[GiNaC-list] same expression prints in differs orders

Alexei Sheplyakov alexei.sheplyakov at gmail.com
Tue Sep 21 09:45:41 CEST 2010


Hello,

On Tue, Sep 21, 2010 at 12:01 AM, Jose Antonio Garcia Peiro
<jgpeiro at gmail.com> 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

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


More information about the GiNaC-list mailing list