ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 01 Feb 2021 22:10:53 +0100Solve for coefficients of polynomialshttps://ask.sagemath.org/question/55474/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](https://ask.sagemath.org/question/51639/equating-coefficients-of-multivariate-polynomials/) 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())
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)'Wed, 27 Jan 2021 17:33:29 +0100https://ask.sagemath.org/question/55474/solve-for-coefficients-of-polynomials/Answer by tmonteil for <p>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$.</p>
<p>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}$.</p>
<p>I tried to follow <a href="https://ask.sagemath.org/question/51639/equating-coefficients-of-multivariate-polynomials/">this</a> answer and wrote this code that failed-</p>
<pre><code>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())
I.variety()
</code></pre>
<p>And I get the following error:</p>
<pre><code>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)'
</code></pre>
https://ask.sagemath.org/question/55474/solve-for-coefficients-of-polynomials/?answer=55480#post-id-55480First 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.Wed, 27 Jan 2021 19:33:29 +0100https://ask.sagemath.org/question/55474/solve-for-coefficients-of-polynomials/?answer=55480#post-id-55480Comment by ofir_ar for <p>First problem i can see: when you write <code>a= K.gens()</code>, you overwrite the Python name <code>a</code>, hence in further commands, <code>a</code> is a list, it is not the first undeterminate of the ring <code>S</code> anymore, so when you write <code>a[1]*a</code> you try to multipliy an element of <code>K</code> with a list, which Sage is not able to give a meaning.</p>
<p>There might be other issues (like how <code>K</code> and <code>S</code> are related), but you should start with fixing that one.</p>
https://ask.sagemath.org/question/55474/solve-for-coefficients-of-polynomials/?comment=55484#post-id-55484@tmonteil I changed the names as you suggested, I got another error (my question was updeated)Thu, 28 Jan 2021 09:20:12 +0100https://ask.sagemath.org/question/55474/solve-for-coefficients-of-polynomials/?comment=55484#post-id-55484Answer by Max Alekseyev for <p>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$.</p>
<p>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}$.</p>
<p>I tried to follow <a href="https://ask.sagemath.org/question/51639/equating-coefficients-of-multivariate-polynomials/">this</a> answer and wrote this code that failed-</p>
<pre><code>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())
I.variety()
</code></pre>
<p>And I get the following error:</p>
<pre><code>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)'
</code></pre>
https://ask.sagemath.org/question/55474/solve-for-coefficients-of-polynomials/?answer=55541#post-id-55541Try 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())
I.variety()
Mon, 01 Feb 2021 22:10:53 +0100https://ask.sagemath.org/question/55474/solve-for-coefficients-of-polynomials/?answer=55541#post-id-55541