Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions spherogram_src/codecs/DT.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,8 @@ def marked_arc(self, vertex):
raise ValueError('Marked graph has a dead end at %s.' % V)
if len(edges) > 1:
break
else:
vertices.add(V)
edge = edges.pop()
vertices.add(V)
edge = edges.pop()
left_path.reverse()
return left_path + right_path

Expand Down Expand Up @@ -755,10 +754,9 @@ def find_circle(self, first_edge):
if vertex in seen:
edges.append(edge)
break
else:
seen.add(vertex)
vertices.append(vertex)
edges.append(edge)
seen.add(vertex)
vertices.append(vertex)
edges.append(edge)
n = vertices.index(vertex)
edges = edges[n:]
vertices = vertices[n:]
Expand Down
3 changes: 1 addition & 2 deletions spherogram_src/links/alexander.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def strand_matrix_merge(A, a, b):
A[:, i] = phi + alpha * psi / mu
A[i, i] = gamma + alpha * delta / mu
A = A.delete_rows([j])
A = A.delete_columns([j])
return A
return A.delete_columns([j])


def test_meta_associativity():
Expand Down
13 changes: 6 additions & 7 deletions spherogram_src/links/invariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ def normalize_alex_poly(p, t):
p = p * (ti**(-min_exp))

R = p.parent()
p = R.polynomial_ring()(p)
return p
return R.polynomial_ring()(p)


def sage_braid_as_int_word(braid):
"""
Convert a Sage Braid to a word.
"""
# Could simplify using braid.Tietze().
# TODO : Could simplify using braid.Tietze().

G = braid.parent()
gen_idx = {g: i + 1 for i, g in enumerate(G.gens())}
Expand Down Expand Up @@ -144,10 +143,10 @@ def knot_group(self):

Returns a finitely presented group::

sage: K = Link('3_1')
sage: G = K.knot_group()
sage: type(G)
<class 'sage.groups.finitely_presented.FinitelyPresentedGroup_with_category'>
sage: K = Link('3_1')
sage: G = K.knot_group()
sage: type(G)
<class 'sage.groups.finitely_presented.FinitelyPresentedGroup_with_category'>
"""
n = len(self.crossings)
F = FreeGroup(n)
Expand Down
22 changes: 9 additions & 13 deletions spherogram_src/links/links_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ def other(self):
other = nonzero_entry_point if self.strand_index == 0 else 0
return CrossingEntryPoint(self.crossing, other)

def is_under_crossing(self):
def is_under_crossing(self) -> bool:
return self.strand_index == 0

def is_over_crossing(self):
def is_over_crossing(self) -> bool:
return self.strand_index != 0

def component(self):
Expand All @@ -290,8 +290,7 @@ def component(self):
next = ans[-1].next()
if next == self:
break
else:
ans.append(next)
ans.append(next)

return ans

Expand Down Expand Up @@ -506,16 +505,15 @@ def __init__(self, crossings=None, braid_closure=None, check_planarity=True, bui
# This is a second Strand in the same component
# with the same component_idx, which is OK
break
elif component_perm[idx] is None:
if component_perm[idx] is None:
if i not in unused_comps:
raise ValueError("Two Strand objects in the same component"
" have different component_idx values")
component_perm[idx] = i
unused_comps.remove(i)
break
else:
raise ValueError("Two Strand objects in different components"
" have the same component_idx values")
raise ValueError("Two Strand objects in different components"
" have the same component_idx values")
else:
raise Exception() # This should not happen
for i in range(len(self.link_components)):
Expand Down Expand Up @@ -1008,9 +1006,8 @@ def faces(self):
if next == cs0:
faces.append(face)
break
else:
corners.remove(next)
face.append(next)
corners.remove(next)
face.append(next)

return faces

Expand Down Expand Up @@ -1338,8 +1335,7 @@ def linking_number(self):
for i, m in enumerate(tally):
if m == 1:
n += (self.crossings)[i].sign
n = n / 4
return n
return n / 4 # should it be n // 4 ?

def _pieces(self):
"""
Expand Down
5 changes: 2 additions & 3 deletions spherogram_src/links/orthogonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,14 @@ def __init__(self, graph, edge_and_vertex):
vertex = edge(vertex)
if self[0] == (edge, vertex):
break
else:
self.append((edge, vertex))
self.append((edge, vertex))

self._add_turns()

def _add_turns(self):
self.turns = turns = []
for i, (e0, v0) in enumerate(self):
(e1, v1) = self[i + 1]
e1, v1 = self[i + 1]
if e0.kind == e1.kind:
turns.append(0)
else:
Expand Down
3 changes: 1 addition & 2 deletions spherogram_src/links/random_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ def random_link(crossings,
# Adjust the currently random crossings to match the request

if alternating:
link = link.alternating()
return link
return link.alternating()

if consistent_twist_regions:
twist.make_twist_regions_consistent(link)
Expand Down
6 changes: 3 additions & 3 deletions spherogram_src/links/seifert.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def remove_admissible_move(link):
reverse_type_II(link, cs1, cs2, label1, label2)
link._rebuild(same_components_and_orientations=True)
break
else:
found_move = False

found_move = False
return found_move


Expand All @@ -149,7 +149,7 @@ def isotope_to_braid(link):
pass


def is_chain(tree):
def is_chain(tree) -> bool:
tails = [e[0] for e in tree]
heads = [e[1] for e in tree]
return len(set(tails)) == len(tails) and len(set(heads)) == len(heads)
Expand Down
35 changes: 17 additions & 18 deletions spherogram_src/links/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ def reidemeister_I_and_II(link, A):
eliminated, changed = reidemeister_I(link, B)
if eliminated:
break
else:
W, w = A.adjacent[a + 2]
X, x = A.adjacent[a + 3]
Y, y = B.adjacent[b + 1]
Z, z = B.adjacent[b + 2]
eliminated = {A, B}
if W != B:
W[w] = Z[z]
changed.update({W, Z})
if X != B:
X[x] = Y[y]
changed.update({X, Y})
remove_crossings(link, eliminated)
break

W, w = A.adjacent[a + 2]
X, x = A.adjacent[a + 3]
Y, y = B.adjacent[b + 1]
Z, z = B.adjacent[b + 2]
eliminated = {A, B}
if W != B:
W[w] = Z[z]
changed.update({W, Z})
if X != B:
X[x] = Y[y]
changed.update({X, Y})
remove_crossings(link, eliminated)
break

return eliminated, changed

Expand Down Expand Up @@ -276,10 +276,9 @@ def dual_graph_as_nx(link):
if next == face[0]:
faces.append(Face(face, count))
break
else:
to_face_index[next] = count
corners.remove(next)
face.append(next)
to_face_index[next] = count
corners.remove(next)
face.append(next)

G = nx.Graph()
to_face = {edge: faces[f] for edge, f in to_face_index.items()}
Expand Down
Loading