Error in operations of finite field

28 views
Skip to first unread message

Samanta

unread,
Nov 22, 2019, 2:53:21 AM11/22/19
to sage-support
I did not understand why the error has occurred. For the first time, it returned output but for the second time when I run the same code, I found an error "ValueError: the degree of the modulus does not equal the degree of the field" which is also not true as my irreducible polynomial has degree 6.
I am attaching my code and output for two consecutive times.

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
....:
(1, a^3 + a + 1, a^5 + a^4 + a^3 + a^2 + 1, a^4 + a^3 + a^2, a^5 + a^4 + a^3, a^3 + a^2 + 1, a^4 + a^3 + a^2 + a + 1)

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
....:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-37bf7e6f8848> 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)])

/home/susanta/Desktop/SageMath/local/lib/python2.7/site-packages/sage/structure/factory.pyx in sage.structure.factory.UniqueFactory.__call__ (build/cythonized/sage/structure/factory.c:2162)()
    366             False
    367         """
--> 368         key, kwds = self.create_key_and_extra_args(*args, **kwds)
    369         version = self.get_version(sage_version)
    370         return self.get_object(version, key, kwds)

/home/susanta/Desktop/SageMath/local/lib/python2.7/site-packages/sage/rings/finite_rings/finite_field_constructor.pyc 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

Dima Pasechnik

unread,
Nov 22, 2019, 4:47:59 AM11/22/19
to sage-support
yes, I can confirm this is still giving an error in the latest Sage
beta. (9.0.beta6).
Note that actually it's two identical inputs, the 2nd executed after
the 1st gives the error.

I'll open a ticket.
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/47e0cba1-d1be-40b7-b376-cfa537b68e29%40googlegroups.com.

Dima Pasechnik

unread,
Nov 22, 2019, 4:51:57 AM11/22/19
to sage-support, sage-devel
This is now https://trac.sagemath.org/ticket/28786
Note that it only happens if modulus is explicitly given.

Dima Pasechnik

unread,
Nov 22, 2019, 4:57:09 AM11/22/19
to sage-support, sage-devel
This is a variable name clash. Somehow, using 'x' for modulus creates a problem.
If I instead do

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

then everything works as expected.

SUSANTA SAMANTA

unread,
Nov 22, 2019, 5:34:29 AM11/22/19
to sage-s...@googlegroups.com, sage-devel
Thanks a lot.
T.<xx>=GF(2)[]
K.<a>=GF(2^6, modulus=xx^6 + xx^4 + xx^3 + xx + 1)
is working perfectly.
Also adding T.<x>=GF(2)[] before K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1) works.

David Roe

unread,
Nov 22, 2019, 11:22:39 AM11/22/19
to sage-devel, sage-support
The issue is that you redefined x after defining K.  I wrote more on the ticket.
David

You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/CAAWYfq167j%3DVciCDWp1z9_ws%2Bqgse4aF1AUWdbeu27G6PJc3ag%40mail.gmail.com.

SUSANTA SAMANTA

unread,
Nov 22, 2019, 1:16:48 PM11/22/19
to sage-s...@googlegroups.com
Thanks David for point out the issue. But when I get the error for the code, this error happens for the next code as well as like when I run
K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)
K
But the error goes away if I run (told by Dima )
T.<x>=GF(2)[]

K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)
K
So I think there may be a bug.
I am attaching the code and their corresponding output or error

....: K

....:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-7687ba85abff> 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 K


/home/susanta/Desktop/SageMath/local/lib/python2.7/site-packages/sage/structure/factory.pyx in sage.structure.factory.UniqueFactory.__call__ (build/cythonized/sage/structure/factory.c:2162)()
    366             False
    367         """
--> 368         key, kwds = self.create_key_and_extra_args(*args, **kwds)
    369         version = self.get_version(sage_version)
    370         return self.get_object(version, key, kwds)

/home/susanta/Desktop/SageMath/local/lib/python2.7/site-packages/sage/rings/finite_rings/finite_field_constructor.pyc 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
sage: T.<x>=GF(2)[]
....: K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)
....: K
....:
Finite Field in a of size 2^6





Dima Pasechnik

unread,
Nov 22, 2019, 4:58:06 PM11/22/19
to sage-support
On Fri, Nov 22, 2019 at 6:16 PM SUSANTA SAMANTA
<susantas...@gmail.com> wrote:
>
> Thanks David for point out the issue. But when I get the error for the code, this error happens for the next code as well as like when I run
> K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)
> K
> But the error goes away if I run (told by Dima )
> T.<x>=GF(2)[]
> K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)
> K
> So I think there may be a bug.

no, it's because you are using x for two different purposes. You can
get the same error just by doing

sage: T.<x>=GF(2)[]
....: 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)

it's not really a bug in Sage, it's a bug in your code.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/CAN3kT1KiBWUQd_JtgS7q%3DuWQuytYdnrq%3Dg7MRQAKAnM4DF812g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages