[GiNaC-list] Ordering of expressions
Luigi Capozza
capozza at kph.uni-mainz.de
Sat Aug 8 19:28:49 CEST 2009
Dear people,
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. As far as I understand, that seems to depend on the
hash value that is assigned to each symbol, which happens to be
different every time I run the program.
Here is an example (example.cxx):
------------------------------------------
#include <iostream>
#include "ginac/ginac.h"
using namespace std;
using namespace GiNaC;
int main()
{
symbol x("x"),y("y"),z("z");
ex Ex1 = 2*(x + y);
ex Ex2 = z*(x + y);
cout<<x.gethash()<<endl
<<y.gethash()<<endl
<<z.gethash()<<endl;
cout<<Ex1<<endl
<<Ex2<<endl;
return 0;
}
------------------------------------------
And here is the output I get (I am running on Ubuntu 8.04.1 with the
GCC 4.2.4 compiler):
--------------------------------------------------
=>g++ -lginac example.cxx -o example
=>example
2178355982
851138097
3818887508
2*y+2*x
(y+x)*z
=>example
3784401678
2457183793
1129965908
2*y+2*x
(y+x)*z
=>example
2632340238
1305122353
4272871764
2*y+2*x
(y+x)*z
=>example
3711329038
2384111153
1056893268
2*y+2*x
z*(y+x)
=>
...
--------------------------------------------------
With more complicated expressions also the run time can vary from
execution to execution up to a factor of 2 or more.
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?
Thanks in advance.
Regards,
Luigi
More information about the GiNaC-list
mailing list