vector-space "in" in libgap?

16 views
Skip to first unread message

Dima Pasechnik

unread,
Aug 6, 2015, 9:04:47 AM8/6/15
to sage-support, vbrau...@gmail.com
I have two libgap objects, and I need to check that one is in the other:

        Fq=libgap.GF(4)
        W=libgap.FullRowSpace(Fq,4)
        B=libgap.Elements(libgap.Basis(W))
        L1 = libgap.Subspace(W,[B[0],B[2]])

Namely, given this, how does one do the Sage equivalent of GAP's 'B[0]-B[3] in L1' ?
I ended up doing

        B[0]-B[3] in L1.Elements()

which does the right thing, but is in general dog-slow...
(the only way to fix this I can see is to patch (lib)GAP to provide a function version of 'in'
for vectorspace; it cannot be done at runtime as it has to be registered in src/sage/libs/gap/gap_functions.py)

Am I missing something obvious

the code above needs the trivial patch:

--- a/src/sage/libs/gap/gap_functions.py
+++ b/src/sage/libs/gap/gap_functions.py
@@ -200,6 +200,7 @@ common_gap_functions = [
   'FreeProduct',
   'FreeSemigroup',
   'FrobeniusAutomorphism',
+  'FullRowSpace',
   'GF',
   'GL',
   'GQuotients',

Volker Braun

unread,
Aug 6, 2015, 9:21:19 AM8/6/15
to Dima Pasechnik, sage-support
This is slow because it first converts the list to Sage and then
iterates through the element warppers and compares:

sage: libgap(1) in libgap.List([1,2,3])
True

The GAP "in" operator is also available as a function IN()

gap> IN(1, [2,3]);
false
gap> IN(2, [2,3]);
true

You can use that in Sage as

sage: contains = libgap.function_factory('IN')
sage: contains(libgap(1), libgap.List([1,2,3]))
true
sage: _.sage()
True

We should probably expose that as the __contains__ method in libgap
elements, then the naive "libgap(1) in libgap.List([1,2,3])" would be
fast, too.
Reply all
Reply to author
Forward
0 new messages