Ask Your Question
1

prime field element constructor does not accept lists of size one

asked 2021-04-02 17:42:35 +0100

dragomang87 gravatar image

updated 2024-04-14 08:12:10 +0100

FrédéricC gravatar image

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)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-04-04 20:07:50 +0100

slelievre gravatar image

Prime fields are a very special case of finite fields, so unsurprisingly there are major implementation differences.

Those differences however should, as much as possible, be smoothed out in the user interface, and you are perfectly right in pointing out this inconsistency.

Fixing this is now tracked at

Similar tickets exist to make available methods more consistent for various implementation of finite fields:

Similarly there have been tickets to make some of the number field methods available for QQ too:

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: 2021-04-02 17:42:35 +0100

Seen: 262 times

Last updated: Apr 04 '21