Exemple #1
0
def wrap_FpGroup(libgap_fpgroup):
    """
    Wrap a GAP finitely presented group.

    This function changes the comparison method of
    ``libgap_free_group`` to comparison by Python ``id``. If you want
    to put the LibGAP free group into a container ``(set, dict)`` then you
    should understand the implications of
    :meth:`~sage.libs.gap.element.GapElement._set_compare_by_id`. To
    be safe, it is recommended that you just work with the resulting
    Sage :class:`FinitelyPresentedGroup`.

    INPUT:

    - ``libgap_fpgroup`` -- a LibGAP finitely presented group

    OUTPUT:

    A Sage :class:`FinitelyPresentedGroup`.

    EXAMPLES:

    First construct a LibGAP finitely presented group::

        sage: F = libgap.FreeGroup(['a', 'b'])
        sage: a_cubed = F.GeneratorsOfGroup()[0] ^ 3
        sage: P = F / libgap([ a_cubed ]);   P
        <fp group of size infinity on the generators [ a, b ]>
        sage: type(P)
        <type 'sage.libs.gap.element.GapElement'>

    Now wrap it::

        sage: from sage.groups.finitely_presented import wrap_FpGroup
        sage: wrap_FpGroup(P)
        Finitely presented group < a, b | a^3 >
    """
    assert libgap_fpgroup.IsFpGroup()
    libgap_fpgroup._set_compare_by_id()
    from sage.groups.free_group import wrap_FreeGroup
    free_group = wrap_FreeGroup(libgap_fpgroup.FreeGroupOfFpGroup())
    relations = tuple(
        free_group(rel.UnderlyingElement())
        for rel in libgap_fpgroup.RelatorsOfFpGroup())
    return FinitelyPresentedGroup(free_group, relations)
def wrap_FpGroup(libgap_fpgroup):
    """
    Wrap a GAP finitely presented group.

    This function changes the comparison method of
    ``libgap_free_group`` to comparison by Python ``id``. If you want
    to put the LibGAP free group into a container (set, dict) then you
    should understand the implications of
    :meth:`~sage.libs.gap.element.GapElement._set_compare_by_id`. To
    be safe, it is recommended that you just work with the resulting
    Sage :class:`FinitelyPresentedGroup`.

    INPUT:

    - ``libgap_fpgroup`` -- a LibGAP finitely presented group

    OUTPUT:

    A Sage :class:`FinitelyPresentedGroup`.

    EXAMPLES:

    First construct a LibGAP finitely presented group::

        sage: F = libgap.FreeGroup(['a', 'b'])
        sage: a_cubed = F.GeneratorsOfGroup()[0] ^ 3
        sage: P = F / libgap([ a_cubed ]);   P
        <fp group of size infinity on the generators [ a, b ]>
        sage: type(P)
        <type 'sage.libs.gap.element.GapElement'>

    Now wrap it::

        sage: from sage.groups.finitely_presented import wrap_FpGroup
        sage: wrap_FpGroup(P)
        Finitely presented group < a, b | a^3 >
    """
    assert libgap_fpgroup.IsFpGroup()
    libgap_fpgroup._set_compare_by_id()
    from sage.groups.free_group import wrap_FreeGroup
    free_group = wrap_FreeGroup(libgap_fpgroup.FreeGroupOfFpGroup())
    relations = tuple( free_group(rel.UnderlyingElement())
                       for rel in libgap_fpgroup.RelatorsOfFpGroup() )
    return FinitelyPresentedGroup(free_group, relations)