hashing polynomials
Publié : ven. avr. 27, 2018 1:55 pm
Hi,
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
There is a workaround maybe. One could convert the polynomial (for the time being I am assuming univariate, I do not want to know what happens if I have more variables) into a list uniquely represented in giac.
Continuing with the code ...
Notice the following:
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
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