Maybe this is a giacpy tip of the day, or maybe this is a question...
In python it would sometimes be beneficial if you could put some giacpy gen types into a dictionary or a set. As a simple example, consider a polynomial x^2+1. The following code will fail
Code : Tout sélectionner
from giacpy import giac
f=giac("x^2+1")
hash(f) # fails, thus..
s=set()
s.add(f) # also fails... and
d={}
d[f]="some dict value" # also fails
Continuing with the code ...
Code : Tout sélectionner
t = tuple(int(i) for i in f.e2r())
s=set.add(t)
d[t]="some dict value"
I need to convert the values in f.e2r() into int (because they are still gen types which are unhashable)
I cannot use e.g. str(f) instead of f.e2r() because I might have different ordering of the monomials in strings representing the same polynomial.
Do you think this is the best way I am handling this. So far this is my only solution.
Jose