LibGAP-based Groups
This module provides helper class for wrapping GAP groups via libgap. See free_group for an example how they are used.
The parent class keeps track of the libGAP element object, to use it in your Python parent you have to derive both from the suitable group parent and ParentLibGAP
sage: from sage.groups.libgap_wrapper import ElementLibGAP, ParentLibGAP
sage: from sage.groups.group import Group
sage: class FooElement(ElementLibGAP):
... pass
sage: class FooGroup(Group, ParentLibGAP):
... Element = FooElement
... def __init__(self):
... lg = libgap(libgap.CyclicGroup(3)) # dummy
... ParentLibGAP.__init__(self, lg)
... Group.__init__(self)
Note how we call the constructor of both superclasses to initialize Group and ParentLibGAP separately. The parent class implements its output via LibGAP:
sage: FooGroup()
<pc group of size 3 with 1 generators>
sage: type(FooGroup().gap())
<type 'sage.libs.gap.element.GapElement'>
The element class is a subclass of MultiplicativeGroupElement. To use it, you just inherit from ElementLibGAP
sage: element = FooGroup().an_element()
sage: element
f1
The element class implements group operations and printing via LibGAP:
sage: element._repr_()
'f1'
sage: element * element
f1^2
AUTHORS:
Bases: sage.structure.element.MultiplicativeGroupElement
A class for LibGAP-based Sage group elements
INPUT:
EXAMPLES:
sage: from sage.groups.libgap_wrapper import ElementLibGAP, ParentLibGAP
sage: from sage.groups.group import Group
sage: class FooElement(ElementLibGAP):
... pass
sage: class FooGroup(Group, ParentLibGAP):
... Element = FooElement
... def __init__(self):
... lg = libgap(libgap.CyclicGroup(3)) # dummy
... ParentLibGAP.__init__(self, lg)
... Group.__init__(self)
sage: FooGroup()
<pc group of size 3 with 1 generators>
sage: FooGroup().gens()
(f1,)
Returns a LibGAP representation of the element
OUTPUT:
EXAMPLES:
sage: G.<a,b> = FreeGroup('a, b')
sage: x = G([1, 2, -1, -2])
sage: x
a*b*a^-1*b^-1
sage: xg = x.gap()
sage: xg
a*b*a^-1*b^-1
sage: type(xg)
<type 'sage.libs.gap.element.GapElement'>
Return the inverse of self.
TESTS:
sage: G = FreeGroup('a, b')
sage: x = G([1, 2, -1, -2])
sage: y = G([2, 2, 2, 1, -2, -2, -2])
sage: x.__invert__()
b*a*b^-1*a^-1
sage: y.__invert__()
b^3*a^-1*b^-3
sage: ~x
b*a*b^-1*a^-1
sage: x.inverse()
b*a*b^-1*a^-1
Test whether the group element is the trivial element.
OUTPUT:
Boolean.
EXAMPLES:
sage: G.<a,b> = FreeGroup(‘a, b’) sage: x = G([1, 2, -1, -2]) sage: x.is_one() False sage: (x * ~x).is_one() True
Bases: object
A class for parents to keep track of the GAP parent.
INPUT:
EXAMPLES:
sage: from sage.groups.libgap_wrapper import ElementLibGAP, ParentLibGAP
sage: from sage.groups.group import Group
sage: class FooElement(ElementLibGAP):
... pass
sage: class FooGroup(Group, ParentLibGAP):
... Element = FooElement
... def __init__(self):
... lg = libgap(libgap.CyclicGroup(3)) # dummy
... ParentLibGAP.__init__(self, lg)
... Group.__init__(self)
sage: FooGroup()
<pc group of size 3 with 1 generators>
Returns the gap representation of self
OUTPUT:
EXAMPLES:
sage: G = FreeGroup(3); G
Free Group on generators {x0, x1, x2}
sage: G.gap()
<free group on the generators [ x0, x1, x2 ]>
sage: G.gap().parent()
C library interface to GAP
sage: type(G.gap())
<type 'sage.libs.gap.element.GapElement'>
This can be useful, for example, to call GAP functions that are not wrapped in Sage:
sage: G = FreeGroup(3)
sage: H = G.gap()
sage: H.DirectProduct(H)
<fp group on the generators [ f1, f2, f3, f4, f5, f6 ]>
sage: H.DirectProduct(H).RelatorsOfFpGroup()
[ f1^-1*f4^-1*f1*f4, f1^-1*f5^-1*f1*f5, f1^-1*f6^-1*f1*f6, f2^-1*f4^-1*f2*f4,
f2^-1*f5^-1*f2*f5, f2^-1*f6^-1*f2*f6, f3^-1*f4^-1*f3*f4, f3^-1*f5^-1*f3*f5,
f3^-1*f6^-1*f3*f6 ]
Return the \(i\)-th generator of self.
Warning
Indexing starts at \(0\) as usual in Sage/Python. Not as in GAP, where indexing starts at \(1\).
INPUT:
OUTPUT:
The \(i\)-th generator of the group.
EXAMPLES:
sage: G = FreeGroup('a, b')
sage: G.gen(0)
a
sage: G.gen(1)
b
Returns the generators of the group.
EXAMPLES:
sage: G = FreeGroup(2) sage: G.gens() (x0, x1) sage: H = FreeGroup('a, b, c') sage: H.gens() (a, b, c)generators() is an alias for gens()
sage: G = FreeGroup('a, b') sage: G.generators() (a, b) sage: H = FreeGroup(3, 'x') sage: H.generators() (x0, x1, x2)
Returns the generators of the group.
EXAMPLES:
sage: G = FreeGroup(2) sage: G.gens() (x0, x1) sage: H = FreeGroup('a, b, c') sage: H.gens() (a, b, c)generators() is an alias for gens()
sage: G = FreeGroup('a, b') sage: G.generators() (a, b) sage: H = FreeGroup(3, 'x') sage: H.generators() (x0, x1, x2)
Return the number of generators of self.
OUTPUT:
Integer.
EXAMPLES:
sage: G = FreeGroup(2) sage: G.ngens() 2TESTS:
sage: type(G.ngens()) <type 'sage.rings.integer.Integer'>
Returns the identity element of self
EXAMPLES:
sage: G = FreeGroup(3) sage: G.one() 1 sage: G.one() == G([]) True sage: G.one().Tietze() ()