Reputation: 1
I need some help to get the coefficients of Polynomial. If tried
y = var('y')
q = y^3 -2*y + 1
coeff_list = [q(y=0)] + [q.coeff(y^k) for k in range(1, q.degree(y)+1)]
but in GF(q)
S.<y> = PolynomialRing(GF(q),'y')
q = y^3 -2*y + 1
coeff_list = [q(y=0)] + [q.coeff(y^k) for k in range(1, q.degree(y)+1)]
coeff_list
i got this error
Error in lines 1-1
Traceback (most recent call last):
File "/projects/31b0bdd7-734b-4864-bf87-0b7cfafd06e9/.sagemathcloud/sage_server.py", line 733, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "factory.pyx", line 141, in sage.structure.factory.UniqueFactory.__call__ (sage/structure/factory.c:1157)
File "/usr/local/sage/sage-5.12/local/lib/python2.7/site-packages/sage/rings/finite_rings/constructor.py", line 352, in create_key_and_extra_args
order = int(order)
File "expression.pyx", line 889, in sage.symbolic.expression.Expression.__int__ (sage/symbolic/expression.cpp:6157)
ValueError: cannot convert y^3 - 2*y + 1 to int
Has anyone an idea to get the coefficients. Thanks a lot in advance. JohnDoe
Upvotes: 0
Views: 3116
Reputation: 10667
First of all your problem here is not about getting the coefficient but building the ring. I'm assuming you want to work on GF(q)
for a prime q
(say 7). Then, when you have a polynomial on a finite field pol, pol.list()
returns the list of coefficients:
sage: q = 7
sage: S.<y> = PolynomialRing(GF(q),'y')
sage: pol = y^3 -2*y + 1
sage: pol
y^3 + 5*y + 1
sage: pol.list()
[1, 5, 0, 1]
Upvotes: 5