Ask Your Question
1

Error generating finite field

asked 2020-11-20 14:44:23 -0600

Sylvain gravatar image

I have the following error while creating finite fields:

sage: F1.<x> = GF(2**8, modulus=x^8 + x^6 + x^5 + x^4 + x^3 + x + 1)
sage: F2.<x> = GF(2**8, modulus=x^8 + x^4 + x^3 + x^2 + 1)
ValueError                                Traceback (most recent call last)
<ipython-input-2-bb7f80049a89> in <module>
----> 1 F2 = GF(Integer(2)**Integer(8), modulus=x**Integer(8) + x**Integer(4) + x**Integer(3) + x**Integer(2) + Integer(1),   

    names=('x',)); (x,) = F2._first_ngens(1)

~/software/sage/local/lib/python3.8/site-packages/sage/structure/factory.pyx in sage.structure.factory.UniqueFactory.__call__ (build/cythonized/sage/structure/factory.c:2179)()
    365             False
    366         """
--> 367         key, kwds = self.create_key_and_extra_args(*args, **kwds)
    368         version = self.get_version(sage_version)
    369         return self.get_object(version, key, kwds)

~/software/sage/local/lib/python3.8/site-packages/sage/rings/finite_rings/finite_field_constructor.py in create_key_and_extra_args(self, order, name, modulus, names, impl, proof, check_irreducible, prefix, repr, elem_cache, **kwds)
    585 
    586                     if modulus.degree() != n:
--> 587                         raise ValueError("the degree of the modulus does not equal the degree of the field")
    588                     if check_irreducible and not modulus.is_irreducible():
    589                         raise ValueError("finite field modulus must be irreducible but it is not")

ValueError: the degree of the modulus does not equal the degree of the field

This is annoying when you attach a script, the error happens each time you change the file. It does not happen if the variable name is different that the variable used in the modulus expression. For example:

sage: F1.<a> = GF(2**8, modulus=x^8 + x^6 + x^5 + x^4 + x^3 + x + 1)
sage: F2.<b> = GF(2**8, modulus=x^8 + x^4 + x^3 + x^2 + 1)

Is there a reason for this behavior ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-11-20 15:39:57 -0600

rburing gravatar image

The variable x in SageMath is pre-defined to be a symbolic variable. That is why the right-hand side of

F1.<x> = GF(2**8, modulus=x^8 + x^6 + x^5 + x^4 + x^3 + x + 1)

is valid. This assignment statement however re-defines x to be the generator of F1. To be precise, the assignment statement above is equivalent to:

F1 = GF(2**8, modulus=x^8 + x^6 + x^5 + x^4 + x^3 + x + 1, name='x'); x = F1.gen()

Then, any future polynomial expression in x will be an element of F1; its normal form (which is automatically computed) will be written as a polynomial of degree less than 8. Hence, the right-hand side of the next statement

F2.<x> = GF(2**8, modulus=x^8 + x^4 + x^3 + x^2 + 1)

is not valid, because Sage will do its best to convert the given modulus to a polynomial over GF(2), and (because elements of F1 are written in normal form), the degree of that polynomial will be less than 8.

Your second variant works because x is not overwritten.

If you do not need a variable to hold the generator of your field, just write e.g.

 F1 = GF(2**8, modulus=x^8 + x^6 + x^5 + x^4 + x^3 + x + 1, name='a')

as above. But in general, be careful about naming your variables and not accidentally overwriting them. Also, it is better to explicitly define e.g. x = polygen(GF(2)) rather than depending on Sage to have the symbolic x.

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

1 follower

Stats

Asked: 2020-11-20 14:44:23 -0600

Seen: 40 times

Last updated: Nov 20