Ask Your Question

Solve for coefficients of polynomials

asked 2021-01-27 17:36:04 +0100

ofir_ar gravatar image

updated 2021-01-28 10:08:01 +0100

I want to solve for the coefficients $\alpha(n, m, k)$ an equation that looks like this: $$ 0 = (1 + x + y + z) \sum_{n, m, k \in \{0, 1, \dots, N\}} \alpha(n, m, k) x^n y^m z^k $$ where $\alpha(n, m, k) \in \{0, 1\}$ and $x^n y^m z^k$ are polynomials over $\mathbb{F}_2$ that satisfy $x^L = y^L = z^L = 1$ for some integer $L$.

Is there a way to do this in Sage? Notice there are three generators $x,y,$ but the number of coefficents $\alpha$ is $2^{3L}$.

I tried to follow this answer and wrote this code that failed-

R = PolynomialRing(GF(2),3,"xyz")
x,y,z = R.gens()
S.<a,b,c> = R.quotient((x^2 + 1,y^2+1,z^2+1))
K = PolynomialRing(GF(2),2,'q') # Coefficients
q = K.gens()

Pol = (q[1]*a+q[0])*(a*b)-5*b*a # Equation to solve

I = K.ideal(Pol.coefficients())

And I get the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-90-e45cccb450b5> in <module>
      5 q = K.gens()
----> 7 Pol = (q[Integer(1)]*a+q[Integer(0)])*(a*b)-Integer(5)*b*a # Equation to solve
      9 K.ideal(Pol.coefficients())

/opt/sagemath-9.2/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__mul__ (build/cythonized/sage/structure/element.c:12199)()
   1513             return (<Element>left)._mul_(right)
   1514         if BOTH_ARE_ELEMENT(cl):
-> 1515             return coercion_model.bin_op(left, right, mul)
   1517         cdef long value

/opt/sagemath-9.2/local/lib/python3.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:11304)()
   1246         # We should really include the underlying error.
   1247         # This causes so much headache.
-> 1248         raise bin_op_exception(op, x, y)
   1250     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for *: 'Multivariate Polynomial Ring in q0, q1 over Finite Field of size 2' and 'Quotient of Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 by the ideal (x^2 + 1, y^2 + 1, z^2 + 1)'
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-01-27 19:33:29 +0100

tmonteil gravatar image

updated 2021-01-27 19:35:30 +0100

First problem i can see: when you write a= K.gens(), you overwrite the Python name a, hence in further commands, a is a list, it is not the first undeterminate of the ring S anymore, so when you write a[1]*a you try to multipliy an element of K with a list, which Sage is not able to give a meaning.

There might be other issues (like how K and S are related), but you should start with fixing that one.

edit flag offensive delete link more


@tmonteil I changed the names as you suggested, I got another error (my question was updeated)

ofir_ar gravatar imageofir_ar ( 2021-01-28 09:20:12 +0100 )edit

answered 2021-02-01 22:10:53 +0100

Max Alekseyev gravatar image

Try this:

R = PolynomialRing(GF(2),3,"xyz")
x,y,z = R.gens()
S.<a,b,c> = R.quotient((x^2 + 1,y^2+1,z^2+1))
K = S[var("u v")]
q = K.gens()

Pol = (q[1]*K(a)+q[0])*(K(a)*K(b))-5*K(b)*K(a) # Equation to solve

I = S.ideal(Pol.coefficients())
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


Asked: 2021-01-27 17:33:29 +0100

Seen: 87 times

Last updated: Feb 01