Skip to content

Commit f647f67

Browse files
committed
fix method fundamental_group in sage/topology/simplicial_complex.py
1 parent 36ac7e4 commit f647f67

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

src/sage/topology/simplicial_complex.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4173,29 +4173,16 @@ def fundamental_group(self, base_point=None, simplify=True):
41734173
from sage.groups.free_group import FreeGroup
41744174
from sage.libs.gap.libgap import libgap as gap
41754175
G = self.graph()
4176-
# If the vertices and edges of G are not sortable, e.g., a mix
4177-
# of str and int, Sage+Python 3 may raise a TypeError when
4178-
# trying to find the spanning tree. So create a graph
4179-
# isomorphic to G but with sortable vertices. Use a copy of G,
4180-
# because self.graph() is cached, and relabeling its vertices
4181-
# would relabel the cached version.
4182-
int_to_v = dict(enumerate(G.vertex_iterator()))
4183-
v_to_int = {v: i for i, v in int_to_v.items()}
4184-
G2 = G.copy(immutable=False)
4185-
G2.relabel(v_to_int)
4186-
spanning_tree = G2.min_spanning_tree()
4187-
gens = [(int_to_v[e[0]], int_to_v[e[1]])
4188-
for e in G2.edges(sort=True)
4189-
if e not in spanning_tree]
4190-
if len(gens) == 0:
4191-
return gap.TrivialGroup()
4192-
41934176
# Edges in the graph may be sorted differently than in the
41944177
# simplicial complex, so convert the edges to frozensets so we
41954178
# don't have to worry about it. Convert spanning_tree to a set
41964179
# to make lookup faster.
4197-
spanning_tree = set(frozenset((int_to_v[e[0]], int_to_v[e[1]]))
4198-
for e in spanning_tree)
4180+
spanning_tree = set(frozenset((u, v)) for u, v, _ in G.min_spanning_tree())
4181+
gens = [e for e in G.edge_iterator(labels=False)
4182+
if frozenset(e) not in spanning_tree]
4183+
if not gens:
4184+
return gap.TrivialGroup()
4185+
41994186
gens_dict = {frozenset(g): i for i, g in enumerate(gens)}
42004187
FG = FreeGroup(len(gens), 'e')
42014188
rels = []
@@ -4204,7 +4191,7 @@ def fundamental_group(self, base_point=None, simplify=True):
42044191
z = dict()
42054192
for i in range(3):
42064193
x = frozenset(bdry[i])
4207-
if (x in spanning_tree):
4194+
if x in spanning_tree:
42084195
z[i] = FG.one()
42094196
else:
42104197
z[i] = FG.gen(gens_dict[x])

0 commit comments

Comments
 (0)