ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 26 Jan 2019 09:06:11 -0600Declaring symbols in a Fieldhttp://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/Lets define a field F.<t> = GF(2^n)
now i want to define a variable points of the form x1+x2*t+...+xn*t^(n-1) and then solving equation with this by comparing coefficients of t^i.
Now I am defining R= PolynomialRing(ZZ,'x',n)
c=R.gens()
R=R.quotient_ring([c[i]^2-c[i] for i in range(0,n)])
then i get n variables but if
I write x= sum(c[i]*t^i for i in (0,n)) I get the parent of x is R. and I am unable to collect the coefficients of t^i. after defining y and z in the same way. if I do X=x+y+z then I am getting the value as a Ring element with monomials in xi's and coefficients in F as X in a Ring element.
Can anyone suggest any way to get the results as f1+f2*t+f3*t^2+...+fn*t^(n-1) and then collect fi's where fi's are functions in the variables xi's.
suppose I want to solve for X,Y in GF(2^3) with X^2Y^2= X^2+(1+t)Y^2
sage: F.<t>=GF(2^3)
sage: R.<a1,a2,b1,b2,c1,c2>= PolynomialRing(ZZ)
sage: R.<a1,a2,b1,b2,c1,c2>= R.quotient_ring([a1^2-a1,a2^2-a2,b1^2-b1,b2^2-b2,c1^2-c1,c2^2-c2])
sage: X=R(a1)+R(b1)t+R(c1)t^2
sage: Y=R(a2)+R(b2)t+R(c2)t^2
sage: X^2*Y^2
Now i want to store this output as A+Bt+Ct^2(how to do this? )
then I do:
sage: X^2+(1+t)*Y^2
and I want to store this as E+Ft+Gt^2(is it possible to do?)
finally I want to solve for ai's and bi's from the eqns A=E, B=F,C=G,ai^2=ai,bi^2=bi,ci^2=ci for i=1,2Wed, 23 Jan 2019 08:12:45 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/Comment by slelievre for <p>Lets define a field F.<t> = GF(2^n)
now i want to define a variable points of the form x1+x2<em>t+...+xn</em>t^(n-1) and then solving equation with this by comparing coefficients of t^i.</p>
<p>Now I am defining R= PolynomialRing(ZZ,'x',n)
c=R.gens()
R=R.quotient_ring([c[i]^2-c[i] for i in range(0,n)])
then i get n variables but if
I write x= sum(c[i]*t^i for i in (0,n)) I get the parent of x is R. and I am unable to collect the coefficients of t^i. after defining y and z in the same way. if I do X=x+y+z then I am getting the value as a Ring element with monomials in xi's and coefficients in F as X in a Ring element.</p>
<p>Can anyone suggest any way to get the results as f1+f2<em>t+f3</em>t^2+...+fn*t^(n-1) and then collect fi's where fi's are functions in the variables xi's.</p>
<p>suppose I want to solve for X,Y in GF(2^3) with X^2Y^2= X^2+(1+t)Y^2</p>
<pre><code>sage: F.<t>=GF(2^3)
sage: R.<a1,a2,b1,b2,c1,c2>= PolynomialRing(ZZ)
sage: R.<a1,a2,b1,b2,c1,c2>= R.quotient_ring([a1^2-a1,a2^2-a2,b1^2-b1,b2^2-b2,c1^2-c1,c2^2-c2])
sage: X=R(a1)+R(b1)t+R(c1)t^2
sage: Y=R(a2)+R(b2)t+R(c2)t^2
sage: X^2*Y^2
</code></pre>
<p>Now i want to store this output as A+Bt+Ct^2(how to do this? )</p>
<p>then I do:</p>
<pre><code>sage: X^2+(1+t)*Y^2
</code></pre>
<p>and I want to store this as E+Ft+Gt^2(is it possible to do?)</p>
<p>finally I want to solve for ai's and bi's from the eqns A=E, B=F,C=G,ai^2=ai,bi^2=bi,ci^2=ci for i=1,2</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45176#post-id-45176To display blocks of code or error messages, skip a line above and below,
and do one of the following (all give the same result):
- indent all code lines with 4 spaces
- select all code lines and click the "code" button (the icon with '101 010')
- select all code lines and hit ctrl-K
For instance, typing
> If we define `f` by
>
> def f(x, y, z):
> return x * y * z
>
> then `f(2, 3, 5)` returns `30` but `f(2*3*5)` gives:
>
> TypeError: f() takes exactly 3 arguments (1 given)
produces:
> If we define `f` by
>
> def f(x, y, z):
> return x * y * z
>
> then `f(2, 3, 5)` returns `30` but `f(2*3*5)` gives:
>
> TypeError: f() takes exactly 3 arguments (1 given)
Please edit your question to do that.Fri, 25 Jan 2019 02:09:58 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45176#post-id-45176Comment by tmonteil for <p>Lets define a field F.<t> = GF(2^n)
now i want to define a variable points of the form x1+x2<em>t+...+xn</em>t^(n-1) and then solving equation with this by comparing coefficients of t^i.</p>
<p>Now I am defining R= PolynomialRing(ZZ,'x',n)
c=R.gens()
R=R.quotient_ring([c[i]^2-c[i] for i in range(0,n)])
then i get n variables but if
I write x= sum(c[i]*t^i for i in (0,n)) I get the parent of x is R. and I am unable to collect the coefficients of t^i. after defining y and z in the same way. if I do X=x+y+z then I am getting the value as a Ring element with monomials in xi's and coefficients in F as X in a Ring element.</p>
<p>Can anyone suggest any way to get the results as f1+f2<em>t+f3</em>t^2+...+fn*t^(n-1) and then collect fi's where fi's are functions in the variables xi's.</p>
<p>suppose I want to solve for X,Y in GF(2^3) with X^2Y^2= X^2+(1+t)Y^2</p>
<pre><code>sage: F.<t>=GF(2^3)
sage: R.<a1,a2,b1,b2,c1,c2>= PolynomialRing(ZZ)
sage: R.<a1,a2,b1,b2,c1,c2>= R.quotient_ring([a1^2-a1,a2^2-a2,b1^2-b1,b2^2-b2,c1^2-c1,c2^2-c2])
sage: X=R(a1)+R(b1)t+R(c1)t^2
sage: Y=R(a2)+R(b2)t+R(c2)t^2
sage: X^2*Y^2
</code></pre>
<p>Now i want to store this output as A+Bt+Ct^2(how to do this? )</p>
<p>then I do:</p>
<pre><code>sage: X^2+(1+t)*Y^2
</code></pre>
<p>and I want to store this as E+Ft+Gt^2(is it possible to do?)</p>
<p>finally I want to solve for ai's and bi's from the eqns A=E, B=F,C=G,ai^2=ai,bi^2=bi,ci^2=ci for i=1,2</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45153#post-id-45153Which equation in the variables `xi` do you wat to solve ?Wed, 23 Jan 2019 10:21:43 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45153#post-id-45153Comment by slelievre for <p>Lets define a field F.<t> = GF(2^n)
now i want to define a variable points of the form x1+x2<em>t+...+xn</em>t^(n-1) and then solving equation with this by comparing coefficients of t^i.</p>
<p>Now I am defining R= PolynomialRing(ZZ,'x',n)
c=R.gens()
R=R.quotient_ring([c[i]^2-c[i] for i in range(0,n)])
then i get n variables but if
I write x= sum(c[i]*t^i for i in (0,n)) I get the parent of x is R. and I am unable to collect the coefficients of t^i. after defining y and z in the same way. if I do X=x+y+z then I am getting the value as a Ring element with monomials in xi's and coefficients in F as X in a Ring element.</p>
<p>Can anyone suggest any way to get the results as f1+f2<em>t+f3</em>t^2+...+fn*t^(n-1) and then collect fi's where fi's are functions in the variables xi's.</p>
<p>suppose I want to solve for X,Y in GF(2^3) with X^2Y^2= X^2+(1+t)Y^2</p>
<pre><code>sage: F.<t>=GF(2^3)
sage: R.<a1,a2,b1,b2,c1,c2>= PolynomialRing(ZZ)
sage: R.<a1,a2,b1,b2,c1,c2>= R.quotient_ring([a1^2-a1,a2^2-a2,b1^2-b1,b2^2-b2,c1^2-c1,c2^2-c2])
sage: X=R(a1)+R(b1)t+R(c1)t^2
sage: Y=R(a2)+R(b2)t+R(c2)t^2
sage: X^2*Y^2
</code></pre>
<p>Now i want to store this output as A+Bt+Ct^2(how to do this? )</p>
<p>then I do:</p>
<pre><code>sage: X^2+(1+t)*Y^2
</code></pre>
<p>and I want to store this as E+Ft+Gt^2(is it possible to do?)</p>
<p>finally I want to solve for ai's and bi's from the eqns A=E, B=F,C=G,ai^2=ai,bi^2=bi,ci^2=ci for i=1,2</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45151#post-id-45151Could you provide a full reproducible example?
Please provide a sequence of things to input in a fresh Sage session to reproduce the error.
See for instance https://stackoverflow.com/help/mcveWed, 23 Jan 2019 09:02:39 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45151#post-id-45151Answer by rburing for <p>Lets define a field F.<t> = GF(2^n)
now i want to define a variable points of the form x1+x2<em>t+...+xn</em>t^(n-1) and then solving equation with this by comparing coefficients of t^i.</p>
<p>Now I am defining R= PolynomialRing(ZZ,'x',n)
c=R.gens()
R=R.quotient_ring([c[i]^2-c[i] for i in range(0,n)])
then i get n variables but if
I write x= sum(c[i]*t^i for i in (0,n)) I get the parent of x is R. and I am unable to collect the coefficients of t^i. after defining y and z in the same way. if I do X=x+y+z then I am getting the value as a Ring element with monomials in xi's and coefficients in F as X in a Ring element.</p>
<p>Can anyone suggest any way to get the results as f1+f2<em>t+f3</em>t^2+...+fn*t^(n-1) and then collect fi's where fi's are functions in the variables xi's.</p>
<p>suppose I want to solve for X,Y in GF(2^3) with X^2Y^2= X^2+(1+t)Y^2</p>
<pre><code>sage: F.<t>=GF(2^3)
sage: R.<a1,a2,b1,b2,c1,c2>= PolynomialRing(ZZ)
sage: R.<a1,a2,b1,b2,c1,c2>= R.quotient_ring([a1^2-a1,a2^2-a2,b1^2-b1,b2^2-b2,c1^2-c1,c2^2-c2])
sage: X=R(a1)+R(b1)t+R(c1)t^2
sage: Y=R(a2)+R(b2)t+R(c2)t^2
sage: X^2*Y^2
</code></pre>
<p>Now i want to store this output as A+Bt+Ct^2(how to do this? )</p>
<p>then I do:</p>
<pre><code>sage: X^2+(1+t)*Y^2
</code></pre>
<p>and I want to store this as E+Ft+Gt^2(is it possible to do?)</p>
<p>finally I want to solve for ai's and bi's from the eqns A=E, B=F,C=G,ai^2=ai,bi^2=bi,ci^2=ci for i=1,2</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?answer=45165#post-id-45165You don't have to declare any symbols to solve the problem that you want to solve. (See [the XY problem](https://en.wikipedia.org/wiki/XY_problem).)
Instead, proceed as follows:
F.<t>=GF(2^3)
R.<X,Y> = PolynomialRing(F)
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
C = Curve(f)
sols = C.rational_points()
If you want them as pairs of vectors:
sage: [map(vector, sol) for sol in sols]
[[(0, 0, 0), (0, 0, 0)],
[(1, 0, 0), (1, 1, 0)],
[(0, 1, 0), (0, 0, 1)],
[(1, 1, 0), (0, 1, 0)],
[(0, 0, 1), (1, 0, 1)],
[(1, 0, 1), (1, 1, 1)],
[(0, 1, 1), (0, 1, 1)]]
Note that `C.rational_points()` is a "slow" Python implementation, but it works fine when the degree of `F` is not too big.
---
To answer your question about symbols, you can do the following:
R.<a1,b1,c1,a2,b2,c2> = BooleanPolynomialRing()
S.<s> = PolynomialRing(R)
from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic
T = PolynomialQuotientRing_generic(S, S(conway_polynomial(2,3).change_variable_name('s')), 't')
t = T.gen()
X = a1 + b1*t + c1*t^2
Y = a2 + b2*t + c2*t^2
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
Then you have:
sage: R.ideal(list(f)).variety()
[{c2: 0, b2: 0, a2: 0, b1: 0, c1: 0, a1: 0},
{c2: 0, b2: 1, a2: 0, b1: 1, c1: 0, a1: 1},
{c2: 0, b2: 1, a2: 1, b1: 0, c1: 0, a1: 1},
{c2: 1, b2: 0, a2: 0, b1: 1, c1: 0, a1: 0},
{c2: 1, b2: 0, a2: 1, b1: 0, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 0, b1: 1, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 1, b1: 0, c1: 1, a1: 1}]
----
Morally I think it should be possible (and it was in 8.1) to construct `T` by
T.<t> = S.quotient(conway_polynomial(2,3).change_variable_name('s'))
but it seems this is no longer the case. This is a bug, which was reported as [trac ticket #26929](https://trac.sagemath.org/ticket/26929).Thu, 24 Jan 2019 06:54:55 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?answer=45165#post-id-45165Comment by BishwajitC for <p>You don't have to declare any symbols to solve the problem that you want to solve. (See <a href="https://en.wikipedia.org/wiki/XY_problem">the XY problem</a>.)</p>
<p>Instead, proceed as follows:</p>
<pre><code>F.<t>=GF(2^3)
R.<X,Y> = PolynomialRing(F)
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
C = Curve(f)
sols = C.rational_points()
</code></pre>
<p>If you want them as pairs of vectors:</p>
<pre><code>sage: [map(vector, sol) for sol in sols]
[[(0, 0, 0), (0, 0, 0)],
[(1, 0, 0), (1, 1, 0)],
[(0, 1, 0), (0, 0, 1)],
[(1, 1, 0), (0, 1, 0)],
[(0, 0, 1), (1, 0, 1)],
[(1, 0, 1), (1, 1, 1)],
[(0, 1, 1), (0, 1, 1)]]
</code></pre>
<p>Note that <code>C.rational_points()</code> is a "slow" Python implementation, but it works fine when the degree of <code>F</code> is not too big.</p>
<hr>
<p>To answer your question about symbols, you can do the following:</p>
<pre><code>R.<a1,b1,c1,a2,b2,c2> = BooleanPolynomialRing()
S.<s> = PolynomialRing(R)
from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic
T = PolynomialQuotientRing_generic(S, S(conway_polynomial(2,3).change_variable_name('s')), 't')
t = T.gen()
X = a1 + b1*t + c1*t^2
Y = a2 + b2*t + c2*t^2
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
</code></pre>
<p>Then you have:</p>
<pre><code>sage: R.ideal(list(f)).variety()
[{c2: 0, b2: 0, a2: 0, b1: 0, c1: 0, a1: 0},
{c2: 0, b2: 1, a2: 0, b1: 1, c1: 0, a1: 1},
{c2: 0, b2: 1, a2: 1, b1: 0, c1: 0, a1: 1},
{c2: 1, b2: 0, a2: 0, b1: 1, c1: 0, a1: 0},
{c2: 1, b2: 0, a2: 1, b1: 0, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 0, b1: 1, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 1, b1: 0, c1: 1, a1: 1}]
</code></pre>
<hr>
<p>Morally I think it should be possible (and it was in 8.1) to construct <code>T</code> by</p>
<pre><code>T.<t> = S.quotient(conway_polynomial(2,3).change_variable_name('s'))
</code></pre>
<p>but it seems this is no longer the case. This is a bug, which was reported as <a href="https://trac.sagemath.org/ticket/26929">trac ticket #26929</a>.</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45189#post-id-45189thank you very much. Now it's working perfectly.Sat, 26 Jan 2019 09:06:11 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45189#post-id-45189Comment by rburing for <p>You don't have to declare any symbols to solve the problem that you want to solve. (See <a href="https://en.wikipedia.org/wiki/XY_problem">the XY problem</a>.)</p>
<p>Instead, proceed as follows:</p>
<pre><code>F.<t>=GF(2^3)
R.<X,Y> = PolynomialRing(F)
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
C = Curve(f)
sols = C.rational_points()
</code></pre>
<p>If you want them as pairs of vectors:</p>
<pre><code>sage: [map(vector, sol) for sol in sols]
[[(0, 0, 0), (0, 0, 0)],
[(1, 0, 0), (1, 1, 0)],
[(0, 1, 0), (0, 0, 1)],
[(1, 1, 0), (0, 1, 0)],
[(0, 0, 1), (1, 0, 1)],
[(1, 0, 1), (1, 1, 1)],
[(0, 1, 1), (0, 1, 1)]]
</code></pre>
<p>Note that <code>C.rational_points()</code> is a "slow" Python implementation, but it works fine when the degree of <code>F</code> is not too big.</p>
<hr>
<p>To answer your question about symbols, you can do the following:</p>
<pre><code>R.<a1,b1,c1,a2,b2,c2> = BooleanPolynomialRing()
S.<s> = PolynomialRing(R)
from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic
T = PolynomialQuotientRing_generic(S, S(conway_polynomial(2,3).change_variable_name('s')), 't')
t = T.gen()
X = a1 + b1*t + c1*t^2
Y = a2 + b2*t + c2*t^2
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
</code></pre>
<p>Then you have:</p>
<pre><code>sage: R.ideal(list(f)).variety()
[{c2: 0, b2: 0, a2: 0, b1: 0, c1: 0, a1: 0},
{c2: 0, b2: 1, a2: 0, b1: 1, c1: 0, a1: 1},
{c2: 0, b2: 1, a2: 1, b1: 0, c1: 0, a1: 1},
{c2: 1, b2: 0, a2: 0, b1: 1, c1: 0, a1: 0},
{c2: 1, b2: 0, a2: 1, b1: 0, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 0, b1: 1, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 1, b1: 0, c1: 1, a1: 1}]
</code></pre>
<hr>
<p>Morally I think it should be possible (and it was in 8.1) to construct <code>T</code> by</p>
<pre><code>T.<t> = S.quotient(conway_polynomial(2,3).change_variable_name('s'))
</code></pre>
<p>but it seems this is no longer the case. This is a bug, which was reported as <a href="https://trac.sagemath.org/ticket/26929">trac ticket #26929</a>.</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45188#post-id-45188So it turns out I was the one running an old version. But the old behavior can be reproduced in the latest version with some more effort (see the updated answer).Sat, 26 Jan 2019 04:35:50 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45188#post-id-45188Comment by BishwajitC for <p>You don't have to declare any symbols to solve the problem that you want to solve. (See <a href="https://en.wikipedia.org/wiki/XY_problem">the XY problem</a>.)</p>
<p>Instead, proceed as follows:</p>
<pre><code>F.<t>=GF(2^3)
R.<X,Y> = PolynomialRing(F)
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
C = Curve(f)
sols = C.rational_points()
</code></pre>
<p>If you want them as pairs of vectors:</p>
<pre><code>sage: [map(vector, sol) for sol in sols]
[[(0, 0, 0), (0, 0, 0)],
[(1, 0, 0), (1, 1, 0)],
[(0, 1, 0), (0, 0, 1)],
[(1, 1, 0), (0, 1, 0)],
[(0, 0, 1), (1, 0, 1)],
[(1, 0, 1), (1, 1, 1)],
[(0, 1, 1), (0, 1, 1)]]
</code></pre>
<p>Note that <code>C.rational_points()</code> is a "slow" Python implementation, but it works fine when the degree of <code>F</code> is not too big.</p>
<hr>
<p>To answer your question about symbols, you can do the following:</p>
<pre><code>R.<a1,b1,c1,a2,b2,c2> = BooleanPolynomialRing()
S.<s> = PolynomialRing(R)
from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic
T = PolynomialQuotientRing_generic(S, S(conway_polynomial(2,3).change_variable_name('s')), 't')
t = T.gen()
X = a1 + b1*t + c1*t^2
Y = a2 + b2*t + c2*t^2
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
</code></pre>
<p>Then you have:</p>
<pre><code>sage: R.ideal(list(f)).variety()
[{c2: 0, b2: 0, a2: 0, b1: 0, c1: 0, a1: 0},
{c2: 0, b2: 1, a2: 0, b1: 1, c1: 0, a1: 1},
{c2: 0, b2: 1, a2: 1, b1: 0, c1: 0, a1: 1},
{c2: 1, b2: 0, a2: 0, b1: 1, c1: 0, a1: 0},
{c2: 1, b2: 0, a2: 1, b1: 0, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 0, b1: 1, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 1, b1: 0, c1: 1, a1: 1}]
</code></pre>
<hr>
<p>Morally I think it should be possible (and it was in 8.1) to construct <code>T</code> by</p>
<pre><code>T.<t> = S.quotient(conway_polynomial(2,3).change_variable_name('s'))
</code></pre>
<p>but it seems this is no longer the case. This is a bug, which was reported as <a href="https://trac.sagemath.org/ticket/26929">trac ticket #26929</a>.</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45187#post-id-45187I think it is the latest version. i.e. 8.6 in macOs 10.13.6
sage: version()
'SageMath version 8.6, Release Date: 2019-01-15'
in fact I checked in Cocalc and it has the same errors. Now I am really confused. :(
Your code if I can get it to work is exactly what I needFri, 25 Jan 2019 21:08:29 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45187#post-id-45187Comment by rburing for <p>You don't have to declare any symbols to solve the problem that you want to solve. (See <a href="https://en.wikipedia.org/wiki/XY_problem">the XY problem</a>.)</p>
<p>Instead, proceed as follows:</p>
<pre><code>F.<t>=GF(2^3)
R.<X,Y> = PolynomialRing(F)
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
C = Curve(f)
sols = C.rational_points()
</code></pre>
<p>If you want them as pairs of vectors:</p>
<pre><code>sage: [map(vector, sol) for sol in sols]
[[(0, 0, 0), (0, 0, 0)],
[(1, 0, 0), (1, 1, 0)],
[(0, 1, 0), (0, 0, 1)],
[(1, 1, 0), (0, 1, 0)],
[(0, 0, 1), (1, 0, 1)],
[(1, 0, 1), (1, 1, 1)],
[(0, 1, 1), (0, 1, 1)]]
</code></pre>
<p>Note that <code>C.rational_points()</code> is a "slow" Python implementation, but it works fine when the degree of <code>F</code> is not too big.</p>
<hr>
<p>To answer your question about symbols, you can do the following:</p>
<pre><code>R.<a1,b1,c1,a2,b2,c2> = BooleanPolynomialRing()
S.<s> = PolynomialRing(R)
from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic
T = PolynomialQuotientRing_generic(S, S(conway_polynomial(2,3).change_variable_name('s')), 't')
t = T.gen()
X = a1 + b1*t + c1*t^2
Y = a2 + b2*t + c2*t^2
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
</code></pre>
<p>Then you have:</p>
<pre><code>sage: R.ideal(list(f)).variety()
[{c2: 0, b2: 0, a2: 0, b1: 0, c1: 0, a1: 0},
{c2: 0, b2: 1, a2: 0, b1: 1, c1: 0, a1: 1},
{c2: 0, b2: 1, a2: 1, b1: 0, c1: 0, a1: 1},
{c2: 1, b2: 0, a2: 0, b1: 1, c1: 0, a1: 0},
{c2: 1, b2: 0, a2: 1, b1: 0, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 0, b1: 1, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 1, b1: 0, c1: 1, a1: 1}]
</code></pre>
<hr>
<p>Morally I think it should be possible (and it was in 8.1) to construct <code>T</code> by</p>
<pre><code>T.<t> = S.quotient(conway_polynomial(2,3).change_variable_name('s'))
</code></pre>
<p>but it seems this is no longer the case. This is a bug, which was reported as <a href="https://trac.sagemath.org/ticket/26929">trac ticket #26929</a>.</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45178#post-id-45178On my machine the code works as I wrote it, and `X^10` returns a polynomial of degree 2 in `t`. Are you using an old version of Sage maybe? Enter `version()` to check.Fri, 25 Jan 2019 04:48:13 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45178#post-id-45178Comment by BishwajitC for <p>You don't have to declare any symbols to solve the problem that you want to solve. (See <a href="https://en.wikipedia.org/wiki/XY_problem">the XY problem</a>.)</p>
<p>Instead, proceed as follows:</p>
<pre><code>F.<t>=GF(2^3)
R.<X,Y> = PolynomialRing(F)
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
C = Curve(f)
sols = C.rational_points()
</code></pre>
<p>If you want them as pairs of vectors:</p>
<pre><code>sage: [map(vector, sol) for sol in sols]
[[(0, 0, 0), (0, 0, 0)],
[(1, 0, 0), (1, 1, 0)],
[(0, 1, 0), (0, 0, 1)],
[(1, 1, 0), (0, 1, 0)],
[(0, 0, 1), (1, 0, 1)],
[(1, 0, 1), (1, 1, 1)],
[(0, 1, 1), (0, 1, 1)]]
</code></pre>
<p>Note that <code>C.rational_points()</code> is a "slow" Python implementation, but it works fine when the degree of <code>F</code> is not too big.</p>
<hr>
<p>To answer your question about symbols, you can do the following:</p>
<pre><code>R.<a1,b1,c1,a2,b2,c2> = BooleanPolynomialRing()
S.<s> = PolynomialRing(R)
from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic
T = PolynomialQuotientRing_generic(S, S(conway_polynomial(2,3).change_variable_name('s')), 't')
t = T.gen()
X = a1 + b1*t + c1*t^2
Y = a2 + b2*t + c2*t^2
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
</code></pre>
<p>Then you have:</p>
<pre><code>sage: R.ideal(list(f)).variety()
[{c2: 0, b2: 0, a2: 0, b1: 0, c1: 0, a1: 0},
{c2: 0, b2: 1, a2: 0, b1: 1, c1: 0, a1: 1},
{c2: 0, b2: 1, a2: 1, b1: 0, c1: 0, a1: 1},
{c2: 1, b2: 0, a2: 0, b1: 1, c1: 0, a1: 0},
{c2: 1, b2: 0, a2: 1, b1: 0, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 0, b1: 1, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 1, b1: 0, c1: 1, a1: 1}]
</code></pre>
<hr>
<p>Morally I think it should be possible (and it was in 8.1) to construct <code>T</code> by</p>
<pre><code>T.<t> = S.quotient(conway_polynomial(2,3).change_variable_name('s'))
</code></pre>
<p>but it seems this is no longer the case. This is a bug, which was reported as <a href="https://trac.sagemath.org/ticket/26929">trac ticket #26929</a>.</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45177#post-id-45177using your code I am getting this :
sage: R.<a1,b1,c1,a2,b2,c2> = BooleanPolynomialRing()
sage: S.<s> = PolynomialRing(R)
sage: T.<t> = S.quotient(conway_polynomial(2,3).change_variable_name('s'))
sage: X = a1 + b1*t + c1*t^2
sage: Y = a2 + b2*t + c2*t^2
sage: f = X^2*Y^2 - (X^2+(1+t)*Y^2)
sage: R.ideal(list(f)).variety()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-9-9d89a195f359> in <module>()
----> 1 R.ideal(list(f)).variety()
TypeError: 'QuotientRing_generic_with_category.element_class' object is not iterableFri, 25 Jan 2019 03:16:46 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45177#post-id-45177Comment by BishwajitC for <p>You don't have to declare any symbols to solve the problem that you want to solve. (See <a href="https://en.wikipedia.org/wiki/XY_problem">the XY problem</a>.)</p>
<p>Instead, proceed as follows:</p>
<pre><code>F.<t>=GF(2^3)
R.<X,Y> = PolynomialRing(F)
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
C = Curve(f)
sols = C.rational_points()
</code></pre>
<p>If you want them as pairs of vectors:</p>
<pre><code>sage: [map(vector, sol) for sol in sols]
[[(0, 0, 0), (0, 0, 0)],
[(1, 0, 0), (1, 1, 0)],
[(0, 1, 0), (0, 0, 1)],
[(1, 1, 0), (0, 1, 0)],
[(0, 0, 1), (1, 0, 1)],
[(1, 0, 1), (1, 1, 1)],
[(0, 1, 1), (0, 1, 1)]]
</code></pre>
<p>Note that <code>C.rational_points()</code> is a "slow" Python implementation, but it works fine when the degree of <code>F</code> is not too big.</p>
<hr>
<p>To answer your question about symbols, you can do the following:</p>
<pre><code>R.<a1,b1,c1,a2,b2,c2> = BooleanPolynomialRing()
S.<s> = PolynomialRing(R)
from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic
T = PolynomialQuotientRing_generic(S, S(conway_polynomial(2,3).change_variable_name('s')), 't')
t = T.gen()
X = a1 + b1*t + c1*t^2
Y = a2 + b2*t + c2*t^2
f = X^2*Y^2 - (X^2+(1+t)*Y^2)
</code></pre>
<p>Then you have:</p>
<pre><code>sage: R.ideal(list(f)).variety()
[{c2: 0, b2: 0, a2: 0, b1: 0, c1: 0, a1: 0},
{c2: 0, b2: 1, a2: 0, b1: 1, c1: 0, a1: 1},
{c2: 0, b2: 1, a2: 1, b1: 0, c1: 0, a1: 1},
{c2: 1, b2: 0, a2: 0, b1: 1, c1: 0, a1: 0},
{c2: 1, b2: 0, a2: 1, b1: 0, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 0, b1: 1, c1: 1, a1: 0},
{c2: 1, b2: 1, a2: 1, b1: 0, c1: 1, a1: 1}]
</code></pre>
<hr>
<p>Morally I think it should be possible (and it was in 8.1) to construct <code>T</code> by</p>
<pre><code>T.<t> = S.quotient(conway_polynomial(2,3).change_variable_name('s'))
</code></pre>
<p>but it seems this is no longer the case. This is a bug, which was reported as <a href="https://trac.sagemath.org/ticket/26929">trac ticket #26929</a>.</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45175#post-id-45175Thank you for the solution. But I don't understand what the T definition doing actually. if with the same X you compute T(X)^10 the output is c1*t^20 + b1*c1*t^18 + a1*c1*t^16 + b1*c1*t^12 + b1*t^10 + a1*b1*t^8 + a1*c1*t^4 + a1*b1*t^2 + a1, whereas according to my question it should come back to a poly of degree 2 in t as modulo the conway_polynomial (2,3).Fri, 25 Jan 2019 00:26:22 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45175#post-id-45175Answer by tmonteil for <p>Lets define a field F.<t> = GF(2^n)
now i want to define a variable points of the form x1+x2<em>t+...+xn</em>t^(n-1) and then solving equation with this by comparing coefficients of t^i.</p>
<p>Now I am defining R= PolynomialRing(ZZ,'x',n)
c=R.gens()
R=R.quotient_ring([c[i]^2-c[i] for i in range(0,n)])
then i get n variables but if
I write x= sum(c[i]*t^i for i in (0,n)) I get the parent of x is R. and I am unable to collect the coefficients of t^i. after defining y and z in the same way. if I do X=x+y+z then I am getting the value as a Ring element with monomials in xi's and coefficients in F as X in a Ring element.</p>
<p>Can anyone suggest any way to get the results as f1+f2<em>t+f3</em>t^2+...+fn*t^(n-1) and then collect fi's where fi's are functions in the variables xi's.</p>
<p>suppose I want to solve for X,Y in GF(2^3) with X^2Y^2= X^2+(1+t)Y^2</p>
<pre><code>sage: F.<t>=GF(2^3)
sage: R.<a1,a2,b1,b2,c1,c2>= PolynomialRing(ZZ)
sage: R.<a1,a2,b1,b2,c1,c2>= R.quotient_ring([a1^2-a1,a2^2-a2,b1^2-b1,b2^2-b2,c1^2-c1,c2^2-c2])
sage: X=R(a1)+R(b1)t+R(c1)t^2
sage: Y=R(a2)+R(b2)t+R(c2)t^2
sage: X^2*Y^2
</code></pre>
<p>Now i want to store this output as A+Bt+Ct^2(how to do this? )</p>
<p>then I do:</p>
<pre><code>sage: X^2+(1+t)*Y^2
</code></pre>
<p>and I want to store this as E+Ft+Gt^2(is it possible to do?)</p>
<p>finally I want to solve for ai's and bi's from the eqns A=E, B=F,C=G,ai^2=ai,bi^2=bi,ci^2=ci for i=1,2</p>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?answer=45163#post-id-45163There is a method to pass from an element of `GF(2^n)` to a polynomial with coefficients in `GF(2)`:
sage: n = 5
sage: F.<t> = GF(2^n)
sage: f = F.random_element()
sage: f
t^4 + t^3 + t + 1
sage: p = f.polynomial()
sage: p
t^4 + t^3 + t + 1
`f` and `p` look the same, but they are not: the first belong to `GF(2^n)`, the second is a genuine polynomial with coeffs in `GF(2)`:
sage: f.parent()
Finite Field in t of size 2^5
sage: p.parent()
Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X)
Now, you can ask for the coeffs of `p` (in the variable `t`):
sage: p.coefficients(sparse=False)
[1, 1, 0, 1, 1]
Or (even better):
sage: p.dict()
{0: 1, 1: 1, 3: 1, 4: 1}
**Warning**: be careful that without the `sparse` option, `coefficients` will only give the nonzero coefficients:
sage: p.coefficients(sparse=False)
[1, 1, 0, 1, 1]Thu, 24 Jan 2019 05:55:31 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?answer=45163#post-id-45163Comment by rburing for <p>There is a method to pass from an element of <code>GF(2^n)</code> to a polynomial with coefficients in <code>GF(2)</code>:</p>
<pre><code>sage: n = 5
sage: F.<t> = GF(2^n)
sage: f = F.random_element()
sage: f
t^4 + t^3 + t + 1
sage: p = f.polynomial()
sage: p
t^4 + t^3 + t + 1
</code></pre>
<p><code>f</code> and <code>p</code> look the same, but they are not: the first belong to <code>GF(2^n)</code>, the second is a genuine polynomial with coeffs in <code>GF(2)</code>:</p>
<pre><code>sage: f.parent()
Finite Field in t of size 2^5
sage: p.parent()
Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X)
</code></pre>
<p>Now, you can ask for the coeffs of <code>p</code> (in the variable <code>t</code>):</p>
<pre><code>sage: p.coefficients(sparse=False)
[1, 1, 0, 1, 1]
</code></pre>
<p>Or (even better):</p>
<pre><code>sage: p.dict()
{0: 1, 1: 1, 3: 1, 4: 1}
</code></pre>
<p><strong>Warning</strong>: be careful that without the <code>sparse</code> option, <code>coefficients</code> will only give the nonzero coefficients:</p>
<pre><code>sage: p.coefficients(sparse=False)
[1, 1, 0, 1, 1]
</code></pre>
http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45166#post-id-45166See also `vector(f)`.Thu, 24 Jan 2019 06:55:35 -0600http://ask.sagemath.org/question/45146/declaring-symbols-in-a-field/?comment=45166#post-id-45166