Ask Your Question

Revision history [back]

prime field element constructor does not accept lists of size one

Let p be prime. Elements of

field = GF(p)

can be constructed as

field(x)

If n>1, elements of

field = GF(p**n)

can be constructed as

field([x1, x2, ..., xn])

This would suggest that for n=1

field([x1])

should work and return the same as

field(x1)

However Sage replies with the following traceback

>>> GF(5)([3])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9218)
  File "sage/structure/coerce_maps.pyx", line 161, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4556)
  File "sage/structure/coerce_maps.pyx", line 156, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4448)
  File "/usr/lib/python3/dist-packages/sage/rings/finite_rings/integer_mod_ring.py", line 1162, in _element_constructor_
    return integer_mod.IntegerMod(self, x)
  File "sage/rings/finite_rings/integer_mod.pyx", line 199, in sage.rings.finite_rings.integer_mod.IntegerMod (build/cythonized/sage/rings/finite_rings/integer_mod.c:4669)
  File "sage/rings/finite_rings/integer_mod.pyx", line 389, in  sage.rings.finite_rings.integer_mod.IntegerMod_abstract.__init__ (build/cythonized/sage/rings/finite_rings/integer_mod.c:6214)
  File "sage/rings/finite_rings/integer_mod.pyx", line 378, in sage.rings.finite_rings.integer_mod.IntegerMod_abstract.__init__ (build/cythonized/sage/rings/finite_rings/integer_mod.c:5963)
  File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9218)
  File "sage/structure/coerce_maps.pyx", line 161, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4556)
  File "sage/structure/coerce_maps.pyx", line 156, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4448)
  File "sage/rings/integer.pyx", line 742, in sage.rings.integer.Integer.__init__ (build/cythonized/sage/rings/integer.c:6946)
TypeError: unable to coerce <class 'list'> to an integer

Is this intentional or a bug? (tested on SageMath version 9.0, Release Date: 2020-01-01 on Kubuntu 20.04)

prime field element constructor does not accept lists of size one

Let p be prime. Elements of

field = GF(p)

can be constructed as

field(x)

If n>1, elements of

field = GF(p**n)

can be constructed as

field([x1, x2, ..., xn])

This would suggest that for n=1

field([x1])

should work and return the same as

field(x1)

However Sage replies with the following traceback

>>> GF(5)([3])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9218)
  File "sage/structure/coerce_maps.pyx", line 161, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4556)
  File "sage/structure/coerce_maps.pyx", line 156, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4448)
  File "/usr/lib/python3/dist-packages/sage/rings/finite_rings/integer_mod_ring.py", line 1162, in _element_constructor_
    return integer_mod.IntegerMod(self, x)
  File "sage/rings/finite_rings/integer_mod.pyx", line 199, in sage.rings.finite_rings.integer_mod.IntegerMod (build/cythonized/sage/rings/finite_rings/integer_mod.c:4669)
  File "sage/rings/finite_rings/integer_mod.pyx", line 389, in  sage.rings.finite_rings.integer_mod.IntegerMod_abstract.__init__ (build/cythonized/sage/rings/finite_rings/integer_mod.c:6214)
  File "sage/rings/finite_rings/integer_mod.pyx", line 378, in sage.rings.finite_rings.integer_mod.IntegerMod_abstract.__init__ (build/cythonized/sage/rings/finite_rings/integer_mod.c:5963)
  File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9218)
  File "sage/structure/coerce_maps.pyx", line 161, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4556)
  File "sage/structure/coerce_maps.pyx", line 156, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4448)
  File "sage/rings/integer.pyx", line 742, in sage.rings.integer.Integer.__init__ (build/cythonized/sage/rings/integer.c:6946)
TypeError: unable to coerce <class 'list'> to an integer

Is this intentional or a bug? (tested on SageMath version 9.0, Release Date: 2020-01-01 on Kubuntu 20.04)

click to hide/show revision 3
retagged

prime field element constructor does not accept lists of size one

Let p be prime. Elements of

field = GF(p)

can be constructed as

field(x)

If n>1, elements of

field = GF(p**n)

can be constructed as

field([x1, x2, ..., xn])

This would suggest that for n=1

field([x1])

should work and return the same as

field(x1)

However Sage replies with the following traceback

>>> GF(5)([3])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9218)
  File "sage/structure/coerce_maps.pyx", line 161, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4556)
  File "sage/structure/coerce_maps.pyx", line 156, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4448)
  File "/usr/lib/python3/dist-packages/sage/rings/finite_rings/integer_mod_ring.py", line 1162, in _element_constructor_
    return integer_mod.IntegerMod(self, x)
  File "sage/rings/finite_rings/integer_mod.pyx", line 199, in sage.rings.finite_rings.integer_mod.IntegerMod (build/cythonized/sage/rings/finite_rings/integer_mod.c:4669)
  File "sage/rings/finite_rings/integer_mod.pyx", line 389, in  sage.rings.finite_rings.integer_mod.IntegerMod_abstract.__init__ (build/cythonized/sage/rings/finite_rings/integer_mod.c:6214)
  File "sage/rings/finite_rings/integer_mod.pyx", line 378, in sage.rings.finite_rings.integer_mod.IntegerMod_abstract.__init__ (build/cythonized/sage/rings/finite_rings/integer_mod.c:5963)
  File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9218)
  File "sage/structure/coerce_maps.pyx", line 161, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4556)
  File "sage/structure/coerce_maps.pyx", line 156, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4448)
  File "sage/rings/integer.pyx", line 742, in sage.rings.integer.Integer.__init__ (build/cythonized/sage/rings/integer.c:6946)
TypeError: unable to coerce <class 'list'> to an integer

Is this intentional or a bug? (tested on SageMath version 9.0, Release Date: 2020-01-01 on Kubuntu 20.04)