[GiNaC-devel] Simplifying powers

Alexei Sheplyakov alexei.sheplyakov at gmail.com
Mon Jul 29 11:31:28 CEST 2013


Hello, Vladimir,
 
> 	The method power::eval() contains the following rules:
> 
> // ^(*(...,x;c1),c2) -> *(^(*(...,x;1),c2),c1^c2)  (c1, c2 numeric(), c1>0)
> // ^(*(...,x;c1),c2) -> *(^(*(...,x;-1),c2),(-c1)^c2)  (c1, c2 numeric(), c1<0)
> 
>   Is there a good reason why c1 here shall be numeric?

The idea is to pull the numeric factor out (so some cancellation can happen).
Also this transformation is fast enough -- basically one need to replace
the overall_coeff (of the mul object) with 1 (or -1), and multiply the result
by a number (c1^c2, or (-c1)^c2).

> Cannot we simply check the positive/negative info flag for c1 for that simplification?

Because such a check is *much* slower. Say, if x in the above expression is
a sum, one need to check every term (which is possibly recursive). To make
it reasonably efficient we need to cache info_flags::positive. That is,
introduce status_flags::positive and status_flags::negative, and set/reset them
properly in eval(), expand() (and possibly other methods).

>   Shall I prepare a patch for this?

You are welcome.

Best regards,
	Alexei



More information about the GiNaC-devel mailing list