Ask Your Question

Finite Field Extension

asked 2021-03-18 15:59:04 +0200

cathreya gravatar image

updated 2021-03-18 16:05:34 +0200

slelievre gravatar image

I am using SageMath version 9.2. I was trying the example in the documentation:

sage: k = GF(2)

sage: k.extension(x^1000 + x^5 + x^4 + x^3 + 1, 'a')

However, this gives the error: UnboundLocalError: local variable 'E' referenced before assignment

How do I fix this?

edit retag flag offensive close merge delete


Same behaviour with SageMath 9.3.beta9. This is a bug.

slelievre gravatar imageslelievre ( 2021-03-18 16:05:19 +0200 )edit

Is there any other way I can specify a finite field modulo a particular irreducible polynomial?

cathreya gravatar imagecathreya ( 2021-03-18 16:29:24 +0200 )edit

The code for the extension method of finite fields is at

There are a bunch of if/elif/else branches to decide how to define E.

In this case we are in the first branch of the main "if",

which has a nested if/elif/elif with no final "else", so that E never gets defined.

slelievre gravatar imageslelievre ( 2021-03-18 17:00:47 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-03-18 17:03:46 +0200

slelievre gravatar image

updated 2021-03-24 14:46:07 +0200

The extension method is really designed for towers of finite fields.

To define a finite field as an extension of the prime field, one can use the GF or FiniteField constructor.

It can take an optional modulus argument:

sage: K.<a> = GF(2^1000, modulus=x^1000 + x^5 + x^4 + x^3 + 1)

For more information, read its documentation:

sage: GF?


sage: FiniteField?

Fixing the bug in the extension method reported in the question is tracked at:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2021-03-18 15:59:04 +0200

Seen: 93 times

Last updated: Mar 24