[GiNaC-list] Bug Report

Jens Vollinga jens.vollinga at googlemail.com
Fri Jul 22 22:54:15 CEST 2011


Hi Jon,

On 22.07.2011 01:09, Jon Graves wrote:
> works, while the second doesn't.  The second one is the most general
> one, useful for any situation ... if it worked.  Is this a bug?

no, not really.

It is documented behaviour, but maybe counterintuitive.

In your code

...
   int n = 2;
   ex test = power(power(x,n),power(n,-1));
   cout << test.subs(power(power(wild(1),wild(2)),power(n,-1))==wild(1)) 
<< endl;
   cout << 
test.subs(power(power(wild(1),wild(2)),power(wild(2),-1))==wild(1)) << endl;
...

the term power(n,-1) is simplified/evaluated to a numeric 1/2. Therefore 
the first pattern matches since in its LHS the same simplification takes 
place.

If you want you can look at the data structures with something like

   cout << tree << test << dflt;

The second matching fails because wild(2) is always treated like a 
symbol and a power with a symbol as a base is not simplified. You try to 
match a numeric 1/2 with a power(symbol,-1) which doesn't work, because 
subs() performs purely syntactic substitutions.

Regards,
Jens


More information about the GiNaC-list mailing list