Ginac not collecting terms when multiplying powers (bug?)
Hello Consider this short programme: #include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main() { possymbol x("x"); cout << pow(4,x + 1) * pow(4,-1) << endl; } The result produced is: 1/4*4^(1+x), the expected output is 4^x. I can see that the documentation says these types of situations will only be handled if it is "safe", but having specified x as a positive value, I'm confused why this expression is not considered safe? All the best Jonathan
Dear Jonathan,
On Mon, 20 Jul 2015 01:18:59 +0200, Jonathan Mills <jpamills@gmail.com> said: JM> Consider this short programme: JM> #include <iostream> #include <ginac/ginac.h> using namespace JM> std; using namespace GiNaC; JM> int main() { possymbol x("x"); cout << pow(4,x + 1) * pow(4,-1) JM> << endl; } JM> The result produced is: 1/4*4^(1+x), the expected output is 4^x. JM> a positive value, I'm confused why this expression is not JM> considered safe?
I think, that the issue here is not "safety". Making all possible simplifications of this type will require to try all possible simplification rules for each term of an expression. If done automatically on every step this will make the system very slow. Thus, GiNaC may require some assistance from a human. In this particular example you will get the expected answer 4^x from cout << (pow(4,x + 1) * GiNaC::pow(4,-1)).expand() << endl; Best wishes, Vladimir -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/
participants (2)
-
Jonathan Mills
-
Vladimir V. Kisil