1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
# Additional initialisation that takes place only when running Regina
# from within Sage:
from . import engine
import sage.all
# -------------------------------------------------------------------------
# Sage-related hacks implemented at the C++ level in Regina
# -------------------------------------------------------------------------
# These hacks include making pybind11 work with Sage's Integer type.
engine._addSageHacks()
# -------------------------------------------------------------------------
# Conversion from Regina objects to Sage objects
# -------------------------------------------------------------------------
from .engine import GroupPresentation
# Additional methods for GroupPresentation
# Follow convention that .sage() yields a representation of
# a mathematical object native to sage
def _convertRel(generators, rel):
return sage.all.prod([
generators[term.generator] ** term.exponent
for term in rel.terms()])
def _convertGroupPresentation(self):
"""
Returns a Sage version of this finitely presented group.
"""
F = sage.all.FreeGroup(self.countGenerators())
gens = F.generators()
rels = [
_convertRel(gens, self.relation(i))
for i in range(self.countRelations())]
return F/rels
GroupPresentation.sage = _convertGroupPresentation
|