[GiNaC-list] same expression prints in differs orders

Jose Antonio Garcia Peiro jgpeiro at gmail.com
Tue Sep 21 11:25:59 CEST 2010


>Hello,

>On Tue, Sep 21, 2010 at 12:01 AM, Jose Antonio Garcia Peiro
><jgpeiro at gmail.com <https://www.cebix.net/mailman/listinfo/ginac-list>> wrote:

>>* I think that the problem is at internal representation or at internal order. When*>>* I debug the code, same expression prints differ.*>>* ex test = pow(log(x),2)/x;*>>* cout << test;*>>* // sometimes x^(-1)*log(x)^2*>>* // other sometimes log(x)^2*x^(-1)*
>Works as designed. This behavior is documented in the manual
>(section 5.7.2, titled as 'Expanding  and collecting'): "Again,
>since the canonical form in GiNaC is not easy to guess you
>should be prepared to see different orderings of terms in such
>sums!". Also it has been explained on this mailing list several
>(quite a number, actually) times, see e.g.

> http://www.cebix.net/pipermail/ginac-list/2010-April/001598.html

> h <http://www.ginac.de/pipermail/ginac-list/2008-August/001403.html>ttp://www.ginac.de/pipermail/ginac-list/2008-August/001403.html <http://www.ginac.de/pipermail/ginac-list/2008-August/001403.html>

>>* How I can force GiNaC to unique representation?*
>You can't. And there's no need to do so. Instead fix the (buggy)
>code which makes assuptions about term ordering.

>>* I am try to test expressions with "match", but it not works*>>* always with the same expression.*
>Could you please post the actual expression and the pattern,
>so I can make a (more) specific suggestion?

>Best regards,
>        Alexei


>You can't. And there's no need to do so. Instead fix the (buggy)
>code which makes assuptions about term ordering.

*mmm, I write about 50 lines with these assumptions, and i think that is not
easy to correct....:-(*
*
*
*

>Could you please post the actual expression and the pattern,
>so I can make a (more) specific suggestion?

The code try to find the integral of a function. The code include all basic
integration rules, for the function log(x)^2*x^(-1) apply these rule.

ex f = pow(log(x),2)/x; // case a: f = x^(-1)*log(x)^2, case b: log(x)^2*
x^(-1)
*
*ex w0, w1, w2;*
*exmap m;*
*
*
*if( f.match( pow(wild(0),wild(1))*wild(2), m ) || f.match(
pow(wild(0),wild(1)), m ) ){ **// int( f^c*f', x) = f^(c+1)/(c+1) or ln(f)
if c == -1*
* w2 = 1; for( exmap::const_iterator i=m.begin(); i!=m.end(); ++i){ if
(i->first.is_equal(wild(0)) ) w0 = i->second; // f else if
(i->first.is_equal(wild(1)) ) w1 = i->second; // c else if
(i->first.is_equal(wild(2)) ) w2 = i->second; // f' } if( has(w0,x) &&
!has(w1,x) ){ // f depends on x and c is constant ex dw0 = w0.diff(x,1); if(
!dw0.is_equal(0) ){ // prevents division by 0 if( !has(w2/dw0,x) ){ if(
w1.is_equal(-1) ){ //check if c == -1 return log( w0 ) * (w2/dw0); }else{
return pow( w0, w1+1 )/(w1+1) * (w2/dw0); } } } } } *
*
*
*In case a: f = x, c = -1, and f' = log(x)^2, the code cannot compute the
integral because f'/df = w2/dw0 = (log(x)^2)/(-x^-2) has the term 'x' and it
cannot move out of integral.*
*In case b: f = log(x), c = 2, f' = x^(-1), the code can compute integral
because f'/df = w2/dw0 = x^(-1)/x^(-1) do not have the term 'x' and it can
move out of integral.*

The code fails because I assume that the product w2 dont have powers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cebix.net/pipermail/ginac-list/attachments/20100921/c47b1646/attachment.html>


More information about the GiNaC-list mailing list