[GiNaC-list] Term ordering and compiling C++ code

Alexei Sheplyakov alexei.sheplyakov at gmail.com
Mon May 24 20:51:07 CEST 2010


Hello,

On Mon, May 24, 2010 at 02:17:41AM -0400, jros wrote:

> In this example
> 
> e1=a+b
> e2=a+b+c
> 
> I suppose that no sharing is implied like e2=e1+c, that would be
> computationally expensive. But, if instead
> 
> e2=e1+c
> 
> then e1 is referenced by e2?? (I suppose yes).

No. GiNaC tries to keep trees (which what GiNaC::add essentially is) as
flat as possible (see expairseq::construct_from_epvector). This save
*a lot* of memory and makes collecting similar terms more efficient. 
So +( +(a, b), c) gets transformed into +(a, b, c), and nothing is
shared between e1 and e2.

Best regards,
	Alexei



More information about the GiNaC-list mailing list