Ask Your Question
0

Using SageMath Finite Field Extension on Python.

asked 2021-11-10 17:43:18 +0200

klx gravatar image

updated 2021-11-10 17:44:41 +0200

Yes, I want to the reverse, use the SageMath in Python.

I've seen this on ask.sagemath and stackoverflow

I want to use this in Python

k = GF(2)
R.<x> = k[]
k.extension(x^1000 + x^5 + x^4 + x^3 + 1, 'a')

The python code

from sage.all import *

F = GF(2)
R.<x> = k[]
K = F.extension(x^4 + x + 1, 'a')

print(K)

the R.<x> = k[] fails...

Is there a way to do this in python?

My final aim is finding the multiplicative inverse of an element using python with the sagemath import.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-11-10 18:29:57 +0200

There is a minor issue in your code:

F = GF(2)
R.<x> = k[]

Presumably F should be k or vice versa. The major issue with using this in Python is that R.<x> = k[] is not allowable Python syntax. Sage preparses it first. You can find out how it does this as follows:

sage: k = GF(2)
sage: preparse('R.<x> = k[]')
"R = k['x']; (x,) = R._first_ngens(1)"

So you should be able to do

from sage.all import *
k = GF(2)
R = k['x']; (x,) = R._first_ngens(1)
K = F.extension(x^4 + x + 1, 'a')
edit flag offensive delete link more

Comments

This should be the code. You have forgotten the ** instead of ^

from sage.all import *

F = GF(2)
R = F['x']; (x,) = R._first_ngens(1)
K = F.extension(x**4 + x + 1, 'a')

print(K)

So, the preparse is the key to mapping to Python, Great. What about the real import instead of importing all?

klx gravatar imageklx ( 2021-11-10 18:41:21 +0200 )edit
1

In principle, import_statements(GF) will tell you what you need to import in order for GFto work (https://doc.sagemath.org/html/en/refe...). In practice, it is unfortunately more complicated.

John Palmieri gravatar imageJohn Palmieri ( 2021-11-10 20:53:49 +0200 )edit
1

from sage.all import GF is slightly better, but not ideal.

John Palmieri gravatar imageJohn Palmieri ( 2021-11-10 21:00:42 +0200 )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: 2021-11-10 17:43:18 +0200

Seen: 87 times

Last updated: Nov 10 '21