Opened 8 months ago

Last modified 2 months ago

#28786 new defect

breakage in finite field with explicit modulus

Reported by: dimpase Owned by:
Priority: critical Milestone: sage-9.2
Component: finite rings Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by dimpase)

Run the following fragment twice in the same Sage session.

sage: K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)
....: x=a^9
....: y=a^21
....: z=1/x
....: v=vector([1,y,y^2,y^3,y^4,y^5,y^6])
....: S=matrix([[1,1,1,1,1,1,1],[1,z,z^2,z^3,z^4,z^5,z^6],[1,(z^2),(z^2)^2,(z^2)^3,(z^2)^4,(z^2)^5,(z^2)^6],[1,(z^3),(z^3)^2,(z^3)^3,(z^3)^4,(z^
....: 3)^5,(z^3)^6],[1,(z^4),(z^4)^2,(z^4)^3,(z^4)^4,(z^4)^5,(z^4)^6],[1,(z^5),(z^5)^2,(z^5)^3,(z^5)^4,(z^5)^5,(z^5)^6],[1,(z^6),(z^6)^2,(z^6)^3
....: ,(z^6)^4,(z^6)^5,(z^6)^6]])
....: w=S*v
....: w

The 1st run succeeds, the 2nd and later runs produce

ValueError                                Traceback (most recent call last)
<ipython-input-7-e412ac7787ee> in <module>()
----> 1 K = GF(Integer(2)**Integer(6), modulus=x**Integer(6) + x**Integer(4) + x**Integer(3) + x + Integer(1), names=('a',)); (a,) = K._first_ngens(1)
      2 x=a**Integer(9)
      3 y=a**Integer(21)
      4 z=Integer(1)/x
      5 v=vector([Integer(1),y,y**Integer(2),y**Integer(3),y**Integer(4),y**Integer(5),y**Integer(6)])

/mnt/opt/Sage/sage-dev/local/lib/python3.7/site-packages/sage/structure/factory.pyx in sage.structure.factory.UniqueFactory.__call__ (build/cythonized/sage/structure/factory.c:2162)()
    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)

/mnt/opt/Sage/sage-dev/local/lib/python3.7/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)
    583 
    584                     if modulus.degree() != n:
--> 585                         raise ValueError("the degree of the modulus does not equal the degree of the field")
    586                     if check_irreducible and not modulus.is_irreducible():
    587                         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

Note that this does not happen if modulus is not given.

This is a variable name clash. Somehow, using 'x' for modulus creates a problem. If I instead define K as

T.<xx>=GF(2)[]
K.<a>=GF(2^6, modulus=xx^6 + xx^4 + xx^3 + xx + 1)

then everything works as expected.

Change History (5)

comment:1 Changed 8 months ago by dimpase

  • Description modified (diff)

comment:2 Changed 8 months ago by dimpase

perhaps making it imposible to use a symbolic variable to define modulus will do the trick. Indeed, if I do

T.<x>=GF(2)[]
K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)

then the error goes away.

Strangely, x is the only symbolic variable that is accepted this way. Trying to use a symbolic variable with a different name does not work

sage: var('tt'); K.<a>=GF(2^6, modulus=tt^6 + tt^4 + tt^3 + tt + 1)
...
TypeError: tt is not a variable of Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X)

Does GF2X do something too smart with x?

comment:3 Changed 8 months ago by roed

I don't think this is a bug. On the first run, you're taking advantage of the fact that x is predefined as a symbolic variable (and indeed, it's the only such variable). The constructor for finite fields can take elements of the symbolic ring, though polynomials are better. On the second, you've redefined x.

The error is triggered by just the following lines:

K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)
x = a^9
K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)

Perhaps a better error message in the case that modulus is a finite field element would be appropriate.

Last edited 8 months ago by roed (previous) (diff)

comment:4 Changed 6 months ago by embray

  • Milestone changed from sage-9.0 to sage-9.1

Ticket retargeted after milestone closed

comment:5 Changed 2 months ago by mkoeppe

  • Milestone changed from sage-9.1 to sage-9.2
Note: See TracTickets for help on using tickets.