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.

On Thu, Aug 6, 2015 at 3:04 PM, Dima Pasechnik <[email protected]> wrote:
> 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',
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to