[GiNaC-list] Simplifying a hierarchy of rational powers on positive symbols

DerManu at WorksLikeClockwork.com DerManu at WorksLikeClockwork.com
Sat Feb 18 22:47:53 CET 2012


Hi GiNaC Gurus,

Consider the following expression:
(2^(2/3)*x^2)^(3/2)
where x is positive.
I'd expect eval() to reduce this to 2*x^3, but it happens only, when calling evalf(). However, I'd like other possible parts of 
the expression to stay exact, so evalf() isn't an option.

Here's the code for the above expression:
    possymbol x("x");
    ex e = power(  power(2,numeric(2)/numeric(3)) * power(x, 2)  ,  numeric(3)/numeric(2)  );
    std::cout << e.eval() << "  " << e.evalf() << std::endl; // I know eval is redundant, but it adds a dramatic element ;)

Note this situation is somewhat related yet much simpler than Topic [1] because we're dealing with purely numeric powers here. 
Still it seems, this kind of simplification is just not wanted. Is that correct? Or is there a trick to make it all work easily?

Would it be a sensible approach to write a map_function functor that grabs all powers that have positive muls as base and apply 
the power to all mul ops individually?

Best regards,
Emanuel

[1] http://www.ginac.de/pipermail/ginac-list/2011-December/001862.html


More information about the GiNaC-list mailing list