Ask Your Question
0

Type Conversion in coefficient method

asked 2024-03-12 12:16:04 +0100

imbluedabedee gravatar image

updated 2024-03-12 12:26:26 +0100

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!

edit retag flag offensive close merge delete

Comments

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 ...

imbluedabedee gravatar imageimbluedabedee ( 2024-03-12 13:14:12 +0100 )edit

What command produces that error?

Max Alekseyev gravatar imageMax Alekseyev ( 2024-03-12 14:54:36 +0100 )edit

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...

imbluedabedee gravatar imageimbluedabedee ( 2024-03-12 15:11:13 +0100 )edit

Ok, I see. Polynomial variables would not work here, at least directly. See my answer for a working approach.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-03-12 16:58:18 +0100 )edit

Sorry for the late reply. Yes, this works. Thanks!

imbluedabedee gravatar imageimbluedabedee ( 2024-03-14 07:14:34 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2024-03-12 16:57:33 +0100

Max Alekseyev gravatar image

Simply convert the coefficient to K - e.g.:

K( p.coefficients()[1][1] )
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-03-12 12:16:04 +0100

Seen: 224 times

Last updated: Mar 12