我需要一些帮助来获得多项式的系数。 如果试过
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)]
但在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
我收到了这个错误
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
有没有人想要获得系数。非常感谢提前。 JOHNDOE
答案 0 :(得分:5)
首先,你的问题不是获得系数而是建立环。我假设你想要GF(q)
处理一个素数q
(比如7)。然后,当在有限域pol上有多项式时,pol.list()
返回系数列表:
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]