# Solve for coefficients of polynomials

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*a+q)*(a*b)-5*b*a # Equation to solve

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


And I get the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-90-e45cccb450b5> in <module>
5 q = K.gens()
6
----> 7 Pol = (q[Integer(1)]*a+q[Integer(0)])*(a*b)-Integer(5)*b*a # Equation to solve
8
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)
1516
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)
1249
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 close merge delete

Sort by » oldest newest most voted

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

more

@tmonteil I changed the names as you suggested, I got another error (my question was updeated) 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*K(a)+q)*(K(a)*K(b))-5*K(b)*K(a) # Equation to solve

I = S.ideal(Pol.coefficients())
I.variety()

more