[GiNaC-list] Term ordering (Was: Inconsistent output, with integration).

Alexei Sheplyakov alexei.sheplyakov at gmail.com
Tue Apr 13 06:12:32 CEST 2010


Hi,

On Mon, Apr 12, 2010 at 09:40:17PM +0530, Akshay Srinivasan wrote:

> I recently wrote a simple program to generate legendre
> polynomials of a given degree n. Thing though is that although the
> program is working perfectly in principle, the output thrown out by
> the program is not the same everytime I run it.

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!".

> The signs of the coefficient change between executions; it doesn't seem
> to follow any pattern either. I couldn't really figure out why this 
> happens. Can someone throw more light on this ?

This is kind of design decision: we trade deterministic output for speed.
In general, the canonical form of GiNaC expressions is unpredictable, i.e.
it changes from run to run (no matter what is the type of the expression).
The following script demonstrates this:

for i in `seq 1 100`; do
        echo "a = x; b = y; x - y;" | ginsh
done |  sort -n | uniq
x
x-y
y
-y+x

Depending on luck, canonical form of the same expression (x-y) might be
either 'x-y' or '-y+x' (of course it's the same during one run).

If you need (more) predictable term order in the output please write a custom
printing method.

Best regards,
	Alexei



More information about the GiNaC-list mailing list