Ask Your Question
2

Declaring symbols in a Field

asked 2019-01-23 08:12:45 -0500

anonymous user

Anonymous

updated 2019-01-25 02:57:33 -0500

Lets define a field F.<t> = GF(2^n) now i want to define a variable points of the form x1+x2t+...+xnt^(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+f2t+f3t^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,2

edit retag flag offensive close merge delete

Comments

Could 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/mcve

slelievre gravatar imageslelievre ( 2019-01-23 09:02:39 -0500 )edit

Which equation in the variables xi do you wat to solve ?

tmonteil gravatar imagetmonteil ( 2019-01-23 10:21:43 -0500 )edit

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

slelievre gravatar imageslelievre ( 2019-01-25 02:09:58 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2019-01-24 06:54:55 -0500

rburing gravatar image

updated 2019-01-26 04:50:13 -0500

You don't have to declare any symbols to solve the problem that you want to solve. (See the 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.

edit flag offensive delete link more

Comments

Thank 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 c1t^20 + b1c1t^18 + a1c1t^16 + b1c1t^12 + b1t^10 + a1b1t^8 + a1c1t^4 + a1b1t^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).

BishwajitC gravatar imageBishwajitC ( 2019-01-25 00:26:22 -0500 )edit

using 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 iterable
BishwajitC gravatar imageBishwajitC ( 2019-01-25 03:16:46 -0500 )edit

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

rburing gravatar imagerburing ( 2019-01-25 04:48:13 -0500 )edit

I 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 need

BishwajitC gravatar imageBishwajitC ( 2019-01-25 21:08:29 -0500 )edit

So 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).

rburing gravatar imagerburing ( 2019-01-26 04:35:50 -0500 )edit
1

answered 2019-01-24 05:55:31 -0500

tmonteil gravatar image

updated 2019-01-24 05:57:14 -0500

There 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]
edit flag offensive delete link more

Comments

See also vector(f).

rburing gravatar imagerburing ( 2019-01-24 06:55:35 -0500 )edit

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

Stats

Asked: 2019-01-23 08:12:45 -0500

Seen: 147 times

Last updated: Jan 26