OS: Ubuntu 11.04 Compiled with g++: g++ -o test test.cpp -lcln -lginac GiNaC ver: 1.60 Sample version of program attached. My program is only meant to simplify expressions that resemble this form: (x^n)^(1/n) = x This program is using a particular value of n to demonstrate what I believe to be a bug (n=2). Two similar methods are employed to attempt to simplify the expression, using wildcards, but only the first one 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? ~Jon
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
participants (2)
-
Jens Vollinga
-
Jon Graves