Type Conversion in coefficient method
I have the polynomials of a certain Eisenstein series. Those are given in the following way:
var('q','z');
K.<sqrt5> = QuadraticField(5);
d2 = [(0, 0, 1), (1/10*sqrt5 + 1/2, 0, 30), (1/10*sqrt5 + 1/2, -1/5*sqrt5 - 1, 1), (1/10*sqrt5 + 1/2, 1/5*sqrt5 + 1, 1), (1/10*sqrt5 + 1/2, -3/10*sqrt5 - 1/2, 12), (1/10*sqrt5 + 1/2, 3/10*sqrt5 + 1/2, 12), (1/10*sqrt5 + 1/2, -1/10*sqrt5 - 1/2, 20), (1/10*sqrt5 + 1/2, 1/10*sqrt5 + 1/2, 20), (1/10*sqrt5 + 1/2, 1/5*sqrt5, 12), (1/10*sqrt5 + 1/2, -1/5*sqrt5, 12), (-1/10*sqrt5 + 1/2, 0, 30), (-1/10*sqrt5 + 1/2, -1/10*sqrt5 - 1/2, 12), (-1/10*sqrt5 + 1/2, 1/10*sqrt5 + 1/2, 12), (-1/10*sqrt5 + 1/2, 1/10*sqrt5 - 1/2, 12), (-1/10*sqrt5 + 1/2, -1/10*sqrt5 + 1/2, 12), (-1/10*sqrt5 + 1/2, 2/5*sqrt5, 1), (-1/10*sqrt5 + 1/2, -2/5*sqrt5, 1), (-1/10*sqrt5 + 1/2, 1/5*sqrt5, 20), (-1/10*sqrt5 + 1/2, -1/5*sqrt5, 20), (-1/5*sqrt5 + 1, 0, 60), (-1/5*sqrt5 + 1, -1, 20), (-1/5*sqrt5 + 1, 1, 20), (-1/5*sqrt5 + 1, -3/10*sqrt5 - 1/2, 20), (-1/5*sqrt5 + 1, 3/10*sqrt5 + 1/2, 20), (-1/5*sqrt5 + 1, -1/10*sqrt5 - 1/2, 60), (-1/5*sqrt5 + 1, 1/10*sqrt5 + 1/2, 60), (-1/5*sqrt5 + 1, 1/10*sqrt5 - 1/2, 60), (-1/5*sqrt5 + 1, -1/10*sqrt5 + 1/2, 60), (-1/5*sqrt5 + 1, 3/10*sqrt5 - 1/2, 20), (-1/5*sqrt5 + 1, -3/10*sqrt5 + 1/2, 20), (-1/5*sqrt5 + 1, 2/5*sqrt5, 30), (-1/5*sqrt5 + 1, -2/5*sqrt5, 30), (-1/5*sqrt5 + 1, 1/5*sqrt5, 60), (-1/5*sqrt5 + 1, -1/5*sqrt5, 60), (1/5*sqrt5 + 1, 0, 60), (1/5*sqrt5 + 1, -2/5*sqrt5 - 1, 20), (1/5*sqrt5 + 1, 2/5*sqrt5 + 1, 20), (1/5*sqrt5 + 1, -1/5*sqrt5 - 1, 30), (1/5*sqrt5 + 1, 1/5*sqrt5 + 1, 30), (1/5*sqrt5 + 1, 1/2*sqrt5 + 1/2, 20), (1/5*sqrt5 + 1, -1/2*sqrt5 - 1/2, 20), (1/5*sqrt5 + 1, -3/10*sqrt5 - 1/2, 60), (1/5*sqrt5 + 1, 3/10*sqrt5 + 1/2, 60), (1/5*sqrt5 + 1, -1/10*sqrt5 - 1/2, 60), (1/5*sqrt5 + 1, 1/10*sqrt5 + 1/2, 60), (1/5*sqrt5 + 1, 1/10*sqrt5 - 1/2, 20), (1/5*sqrt5 + 1, -1/10*sqrt5 + 1/2, 20), (1/5*sqrt5 + 1, 1/5*sqrt5, 60), (1/5*sqrt5 + 1, -1/5*sqrt5, 60), (-2/5*sqrt5 + 1, 0, 30), (-2/5*sqrt5 + 1, 1/5*sqrt5 - 1, 1), (-2/5*sqrt5 + 1, -1/5*sqrt5 + 1, 1), (-2/5*sqrt5 + 1, 1/10*sqrt5 - 1/2, 20), (-2/5*sqrt5 + 1, -1/10*sqrt5 + 1/2, 20), (-2/5*sqrt5 + 1, 3/10*sqrt5 - 1/2, 12), (-2/5*sqrt5 + 1, -3/10*sqrt5 + 1/2, 12), (-2/5*sqrt5 + 1, 1/5*sqrt5, 12), (-2/5*sqrt5 + 1, -1/5*sqrt5, 12), (-2/5*sqrt5 + 1, 0, 30), (-2/5*sqrt5 + 1, 1/5*sqrt5 - 1, 1), (-2/5*sqrt5 + 1, -1/5*sqrt5 + 1, 1), (-2/5*sqrt5 + 1, 1/10*sqrt5 - 1/2, 20), (-2/5*sqrt5 + 1, -1/10*sqrt5 + 1/2, 20), (-2/5*sqrt5 + 1, 3/10*sqrt5 - 1/2, 12), (-2/5*sqrt5 + 1, -3/10*sqrt5 + 1/2, 12), (-2/5*sqrt5 + 1, 1/5*sqrt5, 12), (-2/5*sqrt5 + 1, -1/5*sqrt5, 12), (1, 0, 72), (1, -1/5*sqrt5 - 1, 30), (1, 1/5*sqrt5 + 1, 30), (1, -1, 12), (1, 1, 12), (1, 1/2*sqrt5 + 1/2, 12), (1, -1/2*sqrt5 - 1/2, 12), (1, -3/10*sqrt5 - 1/2, 60), (1, 3/10*sqrt5 + 1/2, 60), (1, -1/10*sqrt5 - 1/2, 60), (1, 1/10*sqrt5 + 1/2, 60), (1, 1/10*sqrt5 - 1/2, 60), (1, -1/10*sqrt5 + 1/2, 60), (1, 2/5*sqrt5, 30), (1, -2/5*sqrt5, 30), (1, 1/5*sqrt5, 60), (1, -1/5*sqrt5, 60)]
e2 = sum(factor * q**exponent * z**exp2 for exponent,exp2, factor in d2)
For example, the first entry in the list d2 would give me the entry 1q^0z^0 with the coefficient 1 and the index (0,0). Now I would like to filter these kind of polynomials to find the coefficients of a certain index.
My naive initial idea was to use the method (e2).coefficients() and then search via comparison.The problem that I am having is that I cannot "compare" the values of the index via "==" since the types are not compatible. So, this for example
type(p.coefficients()[1][1])
yields "<class 'sage.symbolic.expression.expression'="">" and I cannot compare this to an expression like "-2*sqrt(1/5) + 1".
Where is my mistake and is there an easy fix to this? Thanks in advance!
Hey Max, thanks. I tried this. But I get the following error message: ... TypeError: Unable to coerce 1/10*sqrt5 + 1/2 to an integer ...
What command produces that error?
This one: e2 = sum(factor * q**exponent * z**exp2 for exponent,exp2, factor in d2). The program tries to fit this into a rational ... TypeError: Unable to coerce 1/10sqrt5 + 1/2 to a rational... and finally shows ...TypeError: 1/10sqrt5 + 1/2 is neither an integer nor a rational...
Ok, I see. Polynomial variables would not work here, at least directly. See my answer for a working approach.
Sorry for the late reply. Yes, this works. Thanks!