[GiNaC-list] Ordering of expressions
capozza at kph.uni-mainz.de
Sun Aug 9 17:19:52 CEST 2009
On Sun, 9 Aug 2009, Alexei Sheplyakov wrote:
>> I have the following issue with the canonicalization of
>> expressions. If I run many times the same program without changing
>> anything, I get the output for the same expression ordered in
>> different ways.
> 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
Thanks, I had not interpreted that sentence in the right way.
>> With more complicated expressions also the run time can vary from
>> execution to execution up to a factor of 2 or more.
> What exactly is a `run time'? CPU time? Wall clock time? Something else?
I mean CPU time, sorry.
>> Is this normal or am I doing something wrong? I saw that the hash
>> value is calculated in a fairly sophisticated manner but is it eventually
>> possible to set it by hand?
> No, this is an implementation detail, and users are not supposed to fiddle
> with it (the only exception is implementing calchash() method in user defined
I was considering doing that. For the given simple example I found the
easy solution of implementing a class inheriting from symbol and
setting the hash value already in the constructor. Alas, it does not
seem to scale to more elaborated expressions. As you suggest: I'll just
stop fiddling about with the hash.
More information about the GiNaC-list