File: sageSetup.py

package info (click to toggle)
regina-normal 7.4.1-1.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 154,244 kB
  • sloc: cpp: 295,026; xml: 9,992; sh: 1,344; python: 1,225; perl: 616; ansic: 138; makefile: 26
file content (41 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download | duplicates (2)
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