Why rearrange?

Richard B. Kreckel kreckel at thep.physik.uni-mainz.de
Tue Dec 4 16:32:01 CET 2001


Hi,

On Tue, 4 Dec 2001 gorb at krasu.ru wrote:
[...]
>         ex e1=a-y+x+z;
>         ex e2=a+x-y+z;
>         cout <<"e1="<< e1 << endl;
> 	// e1=a-y+z+x
>         cout <<"e2="<< e2 << endl;
> 	// e2=a-y+z+x
> 
> What if I want to get the same order of the variables which was in
> expression on creation. How can I do this?

You can't.  This is intentional, in order to establish a canonical
ordering so that ex e3 = e1-e2 immediately simplifies to 0 by syntactic
comparison.

> And how can I even get
> 	ex e3=x+x;
>         cout <<"e3="<< e3 << endl;
> 	// e3=x+x

Again, you can't.  This is intentional for the same reason.  This
anonymous evaluation mechanism drastically reduces the trees representing
the expression.  In the same level of a (polynomial) tree, no two children
are equal.  If this would be allowed, we would also allow three, four or
more identical subexpressions which increses the complexity of any tree
traversing algorithm substantially and would soon become horribly
inefficient.

By the way, all major algebraic engines do this.

Regards
     -richy.
-- 
Richard B. Kreckel
<Richard.Kreckel at Uni-Mainz.DE>
<http://wwwthep.physik.uni-mainz.de/~kreckel/>





More information about the GiNaC-list mailing list