A bug in element display/matrix conversion when using special linear group over a finite field

61 views
Skip to first unread message

Itay Bookstein

unread,
Jun 6, 2017, 5:17:16 PM6/6/17
to sage-devel
Using Sage 7.6 on Ubuntu 16.04.
S = GF(2^4, 'a')
a = S.gen()

G = SL(2, S)

g1 = G([a**2, a**3 + a**2 + a, a + 1, 0])
g2 = G([a, 0, 0, a**3 + 1])

# prints True True
print g1 in G, g2 in G

# Throws a ValueError
print g1 * g2

Here's the exception:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-edd79a6f0ddd> in <module>()
----> 1 print g1 * g2

/usr/local/sagemath/src/sage/structure/sage_object.pyx in sage.structure.sage_object.SageObject.__repr__ (/usr/local/sagemath/src/build/cythonized/sage/structure/sage_object.c:2694)()
    190             return str(type(self))
    191         else:
--> 192             result = repr_func()
    193             if isinstance(result, unicode):
    194                 # Py3 compatibility: allow _repr_ to return unicode

/usr/local/sagemath/src/sage/groups/matrix_gps/group_element.pyx in sage.groups.matrix_gps.group_element.MatrixGroupElement_gap._repr_ (/usr/local/sagemath/src/build/cythonized/sage/groups/matrix_gps/group_element.c:6695)()
    490             '[1 1]\n[0 1]'
    491         """
--> 492         return str(self.matrix())
    493 
    494     def _latex_(self):

/usr/local/sagemath/src/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (/usr/local/sagemath/src/build/cythonized/sage/misc/cachefunc.c:13453)()
   2399         if self.cache is None:
   2400             f = self.f
-> 2401             self.cache = f(self._instance)
   2402         return self.cache
   2403 

/usr/local/sagemath/src/sage/groups/matrix_gps/group_element.pyx in sage.groups.matrix_gps.group_element.MatrixGroupElement_gap.matrix (/usr/local/sagemath/src/build/cythonized/sage/groups/matrix_gps/group_element.c:7755)()
    585         MS = self.parent().matrix_space()
    586         ring = MS.base_ring()
--> 587         m = MS([x.sage(ring=ring) for x in entries])
    588         m.set_immutable()
    589         return m

/usr/local/sagemath/src/sage/libs/gap/element.pyx in sage.libs.gap.element.GapElement_FiniteField.sage (/usr/local/sagemath/src/build/cythonized/sage/libs/gap/element.c:12693)()
   1384             field = self.DefaultField()
   1385             if field.Size().sage() != ring.cardinality():
-> 1386                 raise ValueError('the given finite field has incompatible size')
   1387             root = self.DefaultField().PrimitiveRoot()
   1388             exp = self.LogFFE(root)

ValueError: the given finite field has incompatible size

Has anyone else encountered this?

Dima Pasechnik

unread,
Jun 6, 2017, 6:19:45 PM6/6/17
to sage-devel
This is a bug, for sure (also present in Sage 8.0.beta9)

Itay Bookstein

unread,
Jul 8, 2017, 2:30:09 PM7/8/17
to sage-devel
Seems like the nature of this issue is general to the explicit 'ring' argument to the sage conversion function.
The bug happens whenever GAP reduces an element to a smaller subfield.
You'd expect this to work:
libgap.eval('Z(2^4)^2 + Z(2^4)^1 + Z(2^4)^0').sage(ring=GF(2^4))
But it throws the exact same error because GAP returned a subfield element:
sage: libgap.eval('Z(2^4)^2 + Z(2^4)^1 + Z(2^4)^0')
Z(2^2)^2
A correct fix would involve only the GapElement_FiniteField.sage method as far as I can tell.
I'm considering patching this myself locally in the meantime seeing as there's no progress on the issue so far.

I'm thinking the size check should be modified to verify that log_p(gap_field_size) divides log_p(ring_size), and the multiplicative_generator()'s exponent should be modified accordingly (i.e. multiplied by (p^n - 1) / (p^m - 1)).
Either that, or instead of using DefaultField (which gives the smallest field containing the element), GF(ring.cardinality()) could be used and the discrete logarithm calculated accordingly.
What do you think?
Could submit it afterwards for review, just want to make sure I'm in the right direction/not missing anything.

Itay Bookstein

unread,
Jul 8, 2017, 4:54:53 PM7/8/17
to sage-devel
Might also be more prudent to use GF(ring.characteristic(), ring.modulus()) within GAP to make sure both fields are 'on the same page' modulus-wise.
Reply all
Reply to author
Forward
0 new messages