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
14 changes: 7 additions & 7 deletions spherogram_src/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __hash__(self):
def incident_to(self):
return list(self)

def is_loop(self):
def is_loop(self) -> bool:
return self[0] is self[1]


Expand Down Expand Up @@ -374,7 +374,7 @@ def components(self, deleted_vertices=[]):
result.append(frozenset(component))
return result

def is_connected(self, deleted_vertices=[]):
def is_connected(self, deleted_vertices=[]) -> bool:
"""
Determine whether the graph obtained by removing the
deleted_vertices and incident edges is connected.
Expand All @@ -391,7 +391,7 @@ def reduced(self):
R.add_edge(*e)
return R

def is_planar(self):
def is_planar(self) -> bool:
return self.reduced().is_planar()

def merge(self, V1, V2):
Expand Down Expand Up @@ -478,7 +478,7 @@ def multi_valence(self, vertex):
"""
return sum(e.multiplicity for e in self.incidence_dict[vertex])

def is_planar(self):
def is_planar(self) -> bool:
"""
Return the planarity.
"""
Expand Down Expand Up @@ -697,14 +697,14 @@ def components(self):
raise ValueError('Not meaningful for Digraphs.\n'
'Use weak_components() or strong_components()')

def is_weakly_connected(self):
def is_weakly_connected(self) -> bool:
"""
A digraph is weakly connected if the associated undirected graph
is connected.
"""
return len(self.weak_components()) <= 1

def is_connected(self):
def is_connected(self) -> bool:
"""
A digraph is connected if, for every pair of vertices v, w,
there is either a directed path from v to w or a directed path
Expand Down Expand Up @@ -732,7 +732,7 @@ def strong_components(self):
"""
return StrongConnector(self).components

def is_strongly_connected(self):
def is_strongly_connected(self) -> bool:
"""
A digraph is strongly connected if, for every pair of vertices
v, w, there is a directed path from v to w and a directed path
Expand Down
2 changes: 1 addition & 1 deletion spherogram_src/links/bands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def __ge__(self, other):
def __repr__(self):
return f'Band{self._spec}'

def is_nonminimal(self, link=None):
def is_nonminimal(self, link=None) -> bool:
"""
Do various tests to see if self is obviously equivalent to a
band other with other < self.
Expand Down
6 changes: 3 additions & 3 deletions spherogram_src/links/bands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .core import Band, add_one_band, banded_links, normalize_crossing_labels


def linking_nums_all_zero(link):
def linking_nums_all_zero(link) -> bool:
"""
>>> linking_nums_all_zero(Link('L2a1')) # Hopf
False
Expand All @@ -13,7 +13,7 @@ def linking_nums_all_zero(link):
return all(x == 0 for row in link.linking_matrix() for x in row)


def is_unlink_exterior(manifold):
def is_unlink_exterior(manifold) -> bool:
"""
If there is clearly a hyperbolic structure present, we don't even
look at the fundamental group as it takes some time to compute and
Expand All @@ -24,7 +24,7 @@ def is_unlink_exterior(manifold):
return manifold.fundamental_group().num_relators() == 0


def could_be_strongly_slice(link):
def could_be_strongly_slice(link) -> bool:
"""
Checks several obstructions for a link L to be strongly slice,
that is that all components of L simultaneously bound embedded
Expand Down
6 changes: 4 additions & 2 deletions spherogram_src/links/exhaust.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,14 @@ def _check(self):
return sorted(self.int_to_set) == list(range(self.n))


def is_range(L):
def is_range(L) -> bool:
"""
>>> is_range([2, 3, 4]), is_range([2, 3, 5])
(True, False)
"""
return L == list(range(min(L), max(L) + 1))
if not L:
return False
return all(i == Li for i, Li in enumerate(L, start=L[0]))


class Frontier(BiDict):
Expand Down
4 changes: 2 additions & 2 deletions spherogram_src/links/jones.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def add_positive_crossing(self, i):
def add_negative_crossing(self, i):
return self.cap_then_cup(i) + (-q) * self

def is_multiple_of_empty_pairing(self):
return len(self.dict) == 1 and (PerfectMatching([]) in self.dict)
def is_multiple_of_empty_pairing(self) -> bool:
return len(self.dict) == 1 and PerfectMatching([]) in self.dict


def kauffman_bracket(link):
Expand Down
4 changes: 2 additions & 2 deletions spherogram_src/links/jones_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def cut(G, T, e):
return answer


def is_internally_active(G, T, e):
def is_internally_active(G, T, e) -> bool:
"""
Input:
--A graph G.
Expand Down Expand Up @@ -88,7 +88,7 @@ def cyc(G, T, e):
return answer


def is_externally_active(G, T, e):
def is_externally_active(G, T, e) -> bool:
"""
Input:
--A graph G.
Expand Down
25 changes: 11 additions & 14 deletions spherogram_src/links/links_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __getitem__(self, n):
# Helper function.


def is_iterable(obj):
def is_iterable(obj) -> bool:
try:
iter(obj)
return True
Expand Down Expand Up @@ -149,13 +149,12 @@ def orient(self):
self.rotate_by_180()
self.sign = 1 if (3, 1) in self.directions else -1

def is_incoming(self, i):
def is_incoming(self, i) -> bool:
if self.sign == 1:
return i in (0, 3)
elif self.sign == -1:
if self.sign == -1:
return i in (0, 1)
else:
raise ValueError('Crossing not oriented')
raise ValueError('Crossing not oriented')

def __getitem__(self, i):
return (self, i % 4)
Expand Down Expand Up @@ -281,10 +280,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 Down Expand Up @@ -362,7 +361,7 @@ def format_adjacent(a):
print("<%s : %s>" %
(self.label, [format_adjacent(a) for a in self.adjacent]))

def is_loop(self):
def is_loop(self) -> bool:
return self == self.adjacent[0][0]


Expand Down Expand Up @@ -947,7 +946,7 @@ def digraph(self):
G.add_edge(cs0.crossing, cs1.crossing)
return G

def is_planar(self):
def is_planar(self) -> bool:
"""
Whether the 4-valent graph underlying the link projection is planar.

Expand Down Expand Up @@ -989,7 +988,7 @@ def is_planar(self):
euler = -v + len(self.faces())
return euler == 2 or v == 0

def is_alternating(self):
def is_alternating(self) -> bool:
"""
Returns whether or not this link diagram is alternating.

Expand Down Expand Up @@ -1225,10 +1224,8 @@ def PD_code(self, KnotTheory=False, min_strand_index=0):
>>> [len(c) for c in L_copy.link_components]
[4, 4, 4, 6, 8]
"""
PD = []

for c in self.crossings:
PD.append([s + min_strand_index for s in c.strand_labels])
PD = [[s + min_strand_index for s in c.strand_labels]
for c in self.crossings]
if KnotTheory:
PD = "PD" + repr(PD).replace('[', 'X[')[1:]
else:
Expand Down
4 changes: 2 additions & 2 deletions spherogram_src/links/morse.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def pack_snakes(self):

self.snakes_at_height = snakes_at_height

def is_bridge(self):
def is_bridge(self) -> bool:
"""
Returns whether the link is in bridge position with respect to this
height function.
Expand Down Expand Up @@ -431,5 +431,5 @@ def HF(self):
import bohua_HF
return bohua_HF.compute_HF(self.bohua_code())

def is_proper(self):
def is_proper(self) -> bool:
return all(abs(a - b) < 2 for a, b in self.crossings)
7 changes: 3 additions & 4 deletions spherogram_src/links/orthogonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def kitty_corner(self):
if not self.exterior:
return kitty_corner(self.turns)

def is_turn_regular(self):
def is_turn_regular(self) -> bool:
return self.kitty_corner() is None

def switches(self, swap_hor_edges):
Expand Down Expand Up @@ -416,11 +416,10 @@ def orient_edges(self, edge, orientation):
dir = (dir + t) % 4
return ans

def is_turn_regular(self):
def is_turn_regular(self) -> bool:
if self.exterior:
return True
else:
return kitty_corner(self.turns) is None
return kitty_corner(self.turns) is None

def __repr__(self):
ext = '*' if self.exterior else ''
Expand Down
2 changes: 1 addition & 1 deletion spherogram_src/links/seifert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading