diff --git a/dev/DTcodes.py b/dev/DTcodes.py index f6af208..bd98f39 100644 --- a/dev/DTcodes.py +++ b/dev/DTcodes.py @@ -121,7 +121,7 @@ def upper_pair(self): return (0,2) if bool(first % 2) ^ even_over else (1,3) -class DTPath(): +class DTPath: """ An iterator which starts at a FatEdge and walks around the link component containing that edge. A DTPath raises @@ -215,7 +215,7 @@ def clear(self): """ for e in self.edges: e.marked = False - self.marked_valences = dict( (v,0) for v in self.vertices ) + self.marked_valences = { v: 0 for v in self.vertices } def push(self, flips): """ @@ -283,7 +283,7 @@ def marked_arc(self, vertex): left_path, right_path, vertices = [], [], set() vertices.add(vertex) try: - left, right = [e for e in self(vertex) if e.marked] + left, right = (e for e in self(vertex) if e.marked) except ValueError: raise RuntimeError('Vertex must have two marked edges.') for edge, path in (left, left_path), (right, right_path): @@ -533,7 +533,7 @@ def KLP_dict(self, vertex, indices): # This assumes that the diagram has no loops, and that each component # meets the next one (so in particular the diagram is connected. -class DTcodec(): +class DTcodec: """ Codec for DT codes of a link projection. """ @@ -871,7 +871,7 @@ def KLPProjection(self): vertices = list(G.vertices) num_crossings = len(vertices) num_components = len(self.code) - KLP_indices = dict( (v,n) for n, v in enumerate(vertices)) + KLP_indices = { v: n for n, v in enumerate(vertices)} KLP_crossings = [G.KLP_dict(v, KLP_indices) for v in vertices] return len(G.vertices), 0, len(self.code), KLP_crossings diff --git a/dev/dev_jennet/bridge_finding.py b/dev/dev_jennet/bridge_finding.py index 14a66c5..eb46112 100644 --- a/dev/dev_jennet/bridge_finding.py +++ b/dev/dev_jennet/bridge_finding.py @@ -15,8 +15,8 @@ def find_bridges(G): bridges = [] verts = G.vertices() - low = dict([(v,-1) for v in verts]) - preorder = dict([(v,-1) for v in verts]) + low = {v: -1 for v in verts} + preorder = {v: -1 for v in verts} for v in verts: if preorder[v] == -1: diff --git a/dev/dev_malik/fast_jones_patch.py b/dev/dev_malik/fast_jones_patch.py index 3279904..fb1d5a8 100644 --- a/dev/dev_malik/fast_jones_patch.py +++ b/dev/dev_malik/fast_jones_patch.py @@ -106,7 +106,7 @@ def simplify_monomial(monomial): # monomial = remove_squares(monomial) # monomial = remove_loops(monomial) - strand_vars = monomial.free_symbols - set([A]) + strand_vars = monomial.free_symbols - {A} strand_labels = all_labels(strand_vars) return monomial @@ -129,7 +129,7 @@ def combine_strands(v1, v2, common_label): def remove_squares(monomial): A, B = sympy.symbols('A,B') - strand_vars = monomial.free_symbols - set([A,B]) + strand_vars = monomial.free_symbols - {A,B} for v in strand_vars: monomial = monomial.subs(v*v,-A**2-(1/A)**2) return monomial @@ -137,7 +137,7 @@ def remove_squares(monomial): def remove_loops(monomial): A, B = sympy.symbols('A,B') - strand_vars = monomial.free_symbols - set([A,B]) + strand_vars = monomial.free_symbols - {A,B} for v in strand_vars: l1, l2 = var_to_strand_labels(v) if l1 == l2: diff --git a/dev/dev_malik/mutation/tangle_patch.py b/dev/dev_malik/mutation/tangle_patch.py index 3828fcc..97fb2a4 100644 --- a/dev/dev_malik/mutation/tangle_patch.py +++ b/dev/dev_malik/mutation/tangle_patch.py @@ -356,7 +356,7 @@ def all_cross_strands(self): other_ends_seen.append(end) orientations, over_or_under = crossing_orientations(strands) cs_seen = [cs for strand in strands for cs in strand] - seen_once = set(cs[0] for cs in cs_seen) + seen_once = {cs[0] for cs in cs_seen} for crossing in orientations: seen_once.remove(crossing) for strand in strands: @@ -873,7 +873,7 @@ def tangle_cut(link, cycle): def fill_in_crossings(link,sides): crossing_sides = {x[0]:sides[x] for x in sides} crossing_labels = map(lambda c: c.label,link.crossings) - crossings_to_sort = set(crossing_labels)-set(x[0] for x in sides) + crossings_to_sort = set(crossing_labels)-{x[0] for x in sides} while len(crossings_to_sort) > 0: start_crossing = crossings_to_sort.pop() accumulated_crossings = [start_crossing] @@ -1158,7 +1158,7 @@ def close_float_sets(L1, L2, tolerance): print(v,avg_vol) """ -a, b, c, d, e, f, g, h = [spherogram.Crossing(x) for x in 'abcdefgh'] +a, b, c, d, e, f, g, h = (spherogram.Crossing(x) for x in 'abcdefgh') a[0] = e[2] a[1] = b[3] a[3] = e[3] diff --git a/dev/dev_malik/thompson/graphknotter.py b/dev/dev_malik/thompson/graphknotter.py index c1ea2cd..6d4a8fd 100644 --- a/dev/dev_malik/thompson/graphknotter.py +++ b/dev/dev_malik/thompson/graphknotter.py @@ -170,8 +170,8 @@ def edge_to_str_pair(edge): def doubled_edge_to_str_pair(e): - s1 = set([e[0].split()[0].split('\'')[1], e[0].split()[1].split('\'')[1]]) - s2 = set([e[1].split()[0].split('\'')[1], e[1].split()[1].split('\'')[1]]) + s1 = {e[0].split()[0].split('\'')[1], e[0].split()[1].split('\'')[1]} + s2 = {e[1].split()[0].split('\'')[1], e[1].split()[1].split('\'')[1]} return [s1,s2] def simple_cut(link, cs1, cs2): diff --git a/dev/dev_malik/unknotting_number.py b/dev/dev_malik/unknotting_number.py index dce6f38..c883a2c 100644 --- a/dev/dev_malik/unknotting_number.py +++ b/dev/dev_malik/unknotting_number.py @@ -6,7 +6,7 @@ def doubly_connected_crossing(link): doubly_connected = None for c in link.crossings: - num_neighbors = len(set(x[0] for x in c.adjacent)) + num_neighbors = len({x[0] for x in c.adjacent}) if num_neighbors == 2: return c elif num_neighbors == 3: diff --git a/dev/dt_issue.py b/dev/dt_issue.py index fb6ecca..39d48d4 100644 --- a/dev/dt_issue.py +++ b/dev/dt_issue.py @@ -64,4 +64,4 @@ def fill_vols(M): def plink_component_order_test(N): M2 = snappy.Manifold() - return set(test_DT(dt, M2) for dt in asymmetric_link_DTs(N)) + return {test_DT(dt, M2) for dt in asymmetric_link_DTs(N)} diff --git a/dev/dt_tests.py b/dev/dt_tests.py index 197aeff..d7c7bf2 100644 --- a/dev/dt_tests.py +++ b/dev/dt_tests.py @@ -36,7 +36,7 @@ def test1(): def test2(): keys = G.incidence_dict.keys() v = keys[0] - D = dict( (k, (i, range(10*i, 10*(i+10)))) for i, k in enumerate(keys)) + D = { k: (i, range(10*i, 10*(i+10))) for i, k in enumerate(keys)} for i in range(155000): D[v] @@ -44,7 +44,7 @@ def test2(): def test3(): keys = G.incidence_dict.keys() v = keys[0] - D = dict((k, None) for i, k in enumerate(keys)) + D = {k: None for i, k in enumerate(keys)} for i in range(155000): D[v] @@ -58,19 +58,19 @@ def test4(): return v -class TestObject(): +class TestObject: pass def test5(): - D = dict([(TestObject(), i) for i in range(10)]) + D = {TestObject(): i for i in range(10)} k = D.keys()[0] for i in range(10000000): D[k] def test6(): - D = dict([(i, TestObject()) for i in range(10)]) + D = {i: TestObject() for i in range(10)} k = D.keys()[0] for i in range(10000000): D[k] diff --git a/dev/old/fastalex/exhaust.py b/dev/old/fastalex/exhaust.py index edf6027..b38b6a4 100644 --- a/dev/old/fastalex/exhaust.py +++ b/dev/old/fastalex/exhaust.py @@ -38,7 +38,7 @@ def entry_pts_ab(crossing): return [CrossingEntryPoint(crossing, v) for v in verts] -class StrandIndices(): +class StrandIndices: """ A map from the crossings strands of a link L onto range(n). """ @@ -111,7 +111,7 @@ def eval_merges(merges): assert eval_merges(m1) == eval_merges(m2) -class DrorDatum(): +class DrorDatum: """ The (omega, A) pair which is the invariant defined in the first column of http://www.math.toronto.edu/drorbn/Talks/Aarhus-1507/ @@ -192,7 +192,7 @@ def num_overlap(crossing, frontier): return len(neighbor_strands.intersection(frontier)) -class Exhaustion(): +class Exhaustion: """ An exhaustion of a link where crossings are added in one-by-one so that the resulting tangle is connected at every stage. diff --git a/dev/old/seifert_patch.py b/dev/old/seifert_patch.py index 46dd840..1330c69 100644 --- a/dev/old/seifert_patch.py +++ b/dev/old/seifert_patch.py @@ -55,7 +55,7 @@ def seifert_tree(link): circles. """ circles = seifert_circles(link) - edges = [[set([n]),set([n])] for n in range(len(circles))] + edges = [[{n},{n}] for n in range(len(circles))] for c in link.crossings: under, over = c.entry_points() under_circle, over_circle = -1,-1 @@ -92,10 +92,10 @@ def remove_admissible_move(link): found_move = False for e1, e2 in combinations(tree,2): if e1[0] == e2[0]: #edges start at same point - circles = set([tree.index(e1), tree.index(e2)]) + circles = {tree.index(e1), tree.index(e2)} found_move = True elif e1[1] == e2[1]: #edges end at same point - circles = set([tree.index(e1), tree.index(e2)]) + circles = {tree.index(e1), tree.index(e2)} found_move = True if found_move: move_possible = False diff --git a/dev/orthogonal/bridge.py b/dev/orthogonal/bridge.py index 3220e88..ef8f455 100644 --- a/dev/orthogonal/bridge.py +++ b/dev/orthogonal/bridge.py @@ -125,7 +125,7 @@ def __new__(self, crossing_strand, link): return ans -class UpwardLinkDiagram(): +class UpwardLinkDiagram: def __init__(self, link): self.link = link = link.copy() bridge, values = bridge_LP(link) @@ -185,7 +185,7 @@ def strands_below(self, crossing): a = CrossingStrand(crossing, 0) b = a.rotate() while True: - if set([kinds[a], kinds[b]]).issubset(set(['up', 'min'])): + if {kinds[a], kinds[b]}.issubset({'up', 'min'}): return a, b a, b = b, b.rotate() @@ -284,19 +284,19 @@ def bottom_pairing(snake): cs = snake[0] return tuple(sorted([to_index(cs), to_index(cs.opposite())])) - bottom = set(bottom_pairing(snake) for snake in self.snakes) + bottom = {bottom_pairing(snake) for snake in self.snakes} def top_pairing(snake): cs = snake[-1] cn = self.adjacent_upwards(snake.final) return tuple(sorted([to_index(cs), to_index(cn)])) - top = set(top_pairing(snake) for snake in self.snakes) + top = {top_pairing(snake) for snake in self.snakes} return BridgeDiagram(bottom, [cd[1] for cd in cross_data], top) -class BridgeDiagram(): +class BridgeDiagram: def __init__(self, bottom, crossings, top): self.bottom, self.crossings, self.top = bottom, crossings, top self.width = 2 * len(bottom) diff --git a/dev/orthogonal/ogdf/ortho.py b/dev/orthogonal/ogdf/ortho.py index 215bab0..fd3b906 100644 --- a/dev/orthogonal/ogdf/ortho.py +++ b/dev/orthogonal/ogdf/ortho.py @@ -17,7 +17,7 @@ def link_to_gml_file(L, filename='graphs/link.gml'): edges = collections.Counter(tuple(sorted([verts_to_int[e.tail], verts_to_int[e.head]])) for e in L.edges) - assert set(edges.values()).issubset(set([1, 2])) + assert set(edges.values()).issubset({1, 2}) for (a, b), m in edges.items(): if m == 2: c = len(verts) diff --git a/dev/orthogonal/orthogonal.py b/dev/orthogonal/orthogonal.py index bbe59bb..202b9c8 100644 --- a/dev/orthogonal/orthogonal.py +++ b/dev/orthogonal/orthogonal.py @@ -324,7 +324,7 @@ def DAG_from_direction(self, kind): def chain_coordinates(self, kind): D = self.DAG_from_direction(kind) chain_coors = topological_numbering(D) - return dict( (v,chain_coors[D.vertex_to_chain[v]]) for v in self.vertices ) + return { v: chain_coors[D.vertex_to_chain[v]] for v in self.vertices } def basic_grid_embedding(self, rotate=False): """ @@ -332,7 +332,7 @@ def basic_grid_embedding(self, rotate=False): """ V = self.chain_coordinates('horizontal') H = self.chain_coordinates('vertical') - return dict( (v,(H[v], V[v])) for v in self.vertices) + return { v: (H[v], V[v]) for v in self.vertices} def show(self, unit=10, labels=True): pos = self.basic_grid_embedding() @@ -457,8 +457,8 @@ def __init__(self, link): self.bend() self.orient_edges() self.edges = sum([F for F in self], []) - strands = set(e.crossing for e in self.edges - if isinstance(e.crossing, Strand)) + strands = {e.crossing for e in self.edges + if isinstance(e.crossing, Strand)} self.strand_CEPs = [CrossingEntryPoint(s, 0) for s in strands] for i, c in enumerate(link.crossings): c.label = i @@ -504,7 +504,7 @@ def bend(self): flow = networkx.min_cost_flow(N) for a, flows in flow.iteritems(): for b, w_a in flows.iteritems(): - if w_a and set(['s', 't']).isdisjoint(set([a, b])): + if w_a and {'s', 't'}.isdisjoint({a, b}): w_b = flow[b][a] A, B = self[a], self[b] e_a, e_b = A.edge_of_intersection(B) @@ -596,7 +596,7 @@ def plink_data(self, spacing=None, canvas_width=None): b, a = emb[v.crossing] vertex_positions.append( (spacing*(a+1), spacing*(b+1)) ) - vert_indices = dict( (v,i) for i, v in enumerate(self.strand_CEPs)) + vert_indices = { v: i for i, v in enumerate(self.strand_CEPs)} arrows, crossings = self.break_into_arrows() arrows = [ (vert_indices[a[0]], vert_indices[a[-1]]) for a in arrows] @@ -668,7 +668,7 @@ def random_link(): def check_faces(link): faces = link.faces() assert len(link.vertices) - len(link.edges) + len(faces) == 2 - assert set(Counter(sum( faces, [] )).values()) == set([1]) + assert set(Counter(sum( faces, [] )).values()) == {1} assert link.is_planar() diff --git a/dev/tangle_patch.py b/dev/tangle_patch.py index 64741b4..b635f48 100644 --- a/dev/tangle_patch.py +++ b/dev/tangle_patch.py @@ -327,7 +327,7 @@ def tangle_neighborhood(link,crossing,radius,return_gluings=True,hull=False): if hull: comps = list(boundary_components(link,crossing,radius)) largest_comp = max(comps) - sides = dict([(cslabel(cross_strand), cross_strand) for cross_strand in adjacent]) + sides = {cslabel(cross_strand): cross_strand for cross_strand in adjacent} c = largest_comp.pop() cs = choice(c.crossing_strands()) exit_strand = meander(cs,sides)[1] @@ -547,9 +547,9 @@ def fill_in_crossings(link, sides): Returns a dictionary with the side (0 or 1) of each crossing. """ - crossing_sides = dict([(x[0], sides[x]) for x in sides]) + crossing_sides = {x[0]: sides[x] for x in sides} crossing_labels = map(lambda c: c.label,link.crossings) - crossings_to_sort = set(crossing_labels)-set(x[0] for x in sides) + crossings_to_sort = set(crossing_labels)-{x[0] for x in sides} while crossings_to_sort: start_crossing = crossings_to_sort.pop() accumulated_crossings = [start_crossing] diff --git a/spherogram_src/codecs/DT.py b/spherogram_src/codecs/DT.py index 77d1d78..1d641c0 100644 --- a/spherogram_src/codecs/DT.py +++ b/spherogram_src/codecs/DT.py @@ -117,7 +117,7 @@ def upper_pair(self): return (0, 2) if bool(first % 2) ^ even_over else (1, 3) -class DTPath(): +class DTPath: """ An iterator which starts at a FatEdge and walks around the link component containing that edge. A DTPath raises @@ -278,7 +278,7 @@ def marked_arc(self, vertex): left_path, right_path, vertices = [], [], set() vertices.add(vertex) try: - left, right = [e for e in self(vertex) if e.marked] + left, right = (e for e in self(vertex) if e.marked) except ValueError: raise RuntimeError('Vertex must have two marked edges.') for edge, path in (left, left_path), (right, right_path): @@ -533,7 +533,7 @@ def KLP_dict(self, vertex, indices): # meets the next one (so in particular the diagram is connected. -class DTcodec(): +class DTcodec: """ Codec for DT codes of a link projection. """ diff --git a/spherogram_src/graphs.py b/spherogram_src/graphs.py index 6073cb0..61ef05c 100644 --- a/spherogram_src/graphs.py +++ b/spherogram_src/graphs.py @@ -211,7 +211,7 @@ def set_slot(self, vertex, n): raise ValueError('Vertex is not an end of this edge.') -class Graph(): +class Graph: """ A set of vertices and a set of edges joining pairs of vertices. Vertices are arbitrary hashable objects and should not be @@ -255,7 +255,7 @@ def incident(self, vertex): """ Return the set of non-loops incident to the vertex. """ - return set(e for e in self.incidence_dict[vertex] if not e.is_loop()) + return {e for e in self.incidence_dict[vertex] if not e.is_loop()} def edges_between(self, vertex1, vertex2): return self.incident(vertex1).intersection(self.incident(vertex2)) @@ -267,7 +267,7 @@ def children(self, vertex): """ Return the set of distinct adjacent vertices. """ - return set(e(vertex) for e in self.incidence_dict[vertex]) + return {e(vertex) for e in self.incidence_dict[vertex]} def add_edge(self, *args, **kwargs): edge = self.Edge(*args, **kwargs) @@ -440,7 +440,7 @@ def one_min_cut(self, source, sink, capacity=None): for e in self.edges: if e not in residual: residual[e] = float('inf') - full_edges = set(e for e in self.edges if residual[e] == 0) + full_edges = {e for e in self.edges if residual[e] == 0} children = {} for vertex in self.vertices: children[vertex] = set() @@ -448,7 +448,7 @@ def one_min_cut(self, source, sink, capacity=None): path_list = [] while True: # Try to find a new path from source to sink - parents, cut_set, reached_sink = {}, set([source]), False + parents, cut_set, reached_sink = {}, {source}, False generator = self.breadth_first_edges( source=source, forbidden=full_edges, @@ -483,9 +483,9 @@ def one_min_cut(self, source, sink, capacity=None): # Find the cut edges. cut_edges = set() for vertex in cut_set: - cut_edges |= set(edge for edge in self.edges + cut_edges |= {edge for edge in self.edges if vertex in edge - and edge(vertex) not in cut_set) + and edge(vertex) not in cut_set} # Find the unsaturated edges. unsaturated = [e for e in self.edges if residual[e] > 0] flow_dict = dict.fromkeys(self.edges, 0) @@ -525,7 +525,7 @@ def merge(self, V1, V2): new_vertex = V1 | V2 if new_vertex in self.vertices: raise ValueError('Merged vertex already exists!') - self.edges -= set(e for e in self.edges if V1 in e and V2 in e) + self.edges -= {e for e in self.edges if V1 in e and V2 in e} self.vertices.remove(V1) self.vertices.remove(V2) old_vertices = (V1, V2) @@ -775,8 +775,8 @@ def outgoing(self, vertex): """ Return the set of non-loop edges which *begin* at the vertex. """ - return set(e for e in self(vertex) - if e.tail is vertex and e.head is not vertex) + return {e for e in self(vertex) + if e.tail is vertex and e.head is not vertex} # Force flows to go in the direction of the edge. flow_incident = outgoing @@ -785,15 +785,15 @@ def incoming(self, vertex): """ Return the set of non-loop edges which *end* at the vertex. """ - return set(e for e in self(vertex) - if e.head is vertex and e.tail is not vertex) + return {e for e in self(vertex) + if e.head is vertex and e.tail is not vertex} def children(self, vertex): """ Return the set of distinct vertices which are endpoints of outgoing non-loop edges. """ - return set(e(vertex) for e in self.outgoing(vertex)) + return {e(vertex) for e in self.outgoing(vertex)} def indegree(self, vertex): return len([e for e in self.incidence_dict[vertex] if e.head is vertex]) @@ -868,7 +868,7 @@ def component_DAG(self): return StrongConnector(self).DAG() -class StrongConnector(): +class StrongConnector: """ Finds strong components of a digraph using Tarjan's algorithm; see http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm @@ -984,7 +984,7 @@ def incomparable(self, x): >>> sorted(P.incomparable(3)) [1, 2] """ - return self.elements - self.smaller[x] - self.larger[x] - set([x]) + return self.elements - self.smaller[x] - self.larger[x] - {x} def smallest(self): """ @@ -1043,7 +1043,7 @@ def XXclosed_subsets(self, start=None): self.closed.add(start) yield start for element in complement: - extended = self.closure(start | set([element])) + extended = self.closure(start | {element}) yield from self.XXclosed_subsets(extended) def XXXclosed_subsets(self, start=None): @@ -1069,7 +1069,7 @@ def XXXclosed_subsets(self, start=None): for element in start: children.update(self.successors[element] - start) for child in children: - extended = self.closure(start | set([child])) + extended = self.closure(start | {child}) yield from self.XXXclosed_subsets(extended) def closed_subsets(self): @@ -1117,7 +1117,7 @@ def powerset(S): for x in X: break X.remove(x) - singleton = set([x]) + singleton = {x} for Y in powerset(X): yield (singleton | Y) yield X diff --git a/spherogram_src/links/alexander.py b/spherogram_src/links/alexander.py index cc03e09..5d55e3e 100644 --- a/spherogram_src/links/alexander.py +++ b/spherogram_src/links/alexander.py @@ -46,7 +46,7 @@ def entry_pts_ab(crossing): return [CrossingEntryPoint(crossing, v) for v in verts] -class StrandIndices(): +class StrandIndices: """ A map from the crossings strands of a link L onto range(n). """ @@ -118,7 +118,7 @@ def eval_merges(merges): assert eval_merges(m1) == eval_merges(m2) -class DrorDatum(): +class DrorDatum: """ The (omega, A) pair which is the invariant defined in the first column of http://www.math.toronto.edu/drorbn/Talks/Aarhus-1507/ @@ -151,11 +151,11 @@ def merge(self, cs_a, cs_b): def num_overlap(crossing, frontier): - neighbor_strands = set(cs.opposite() for cs in crossing.crossing_strands()) + neighbor_strands = {cs.opposite() for cs in crossing.crossing_strands()} return len(neighbor_strands.intersection(frontier)) -class Exhaustion(): +class Exhaustion: """ An exhaustion of a link where crossings are added in one-by-one so that the resulting tangle is connected at every stage. diff --git a/spherogram_src/links/exhaust.py b/spherogram_src/links/exhaust.py index 1630c40..84b604d 100644 --- a/spherogram_src/links/exhaust.py +++ b/spherogram_src/links/exhaust.py @@ -6,7 +6,7 @@ def insert_space(point_dict, i): """ Insert two new points which will be labeled i and i + 1. - """ + """ ans = {} for a, v in point_dict.items(): if a >= i: @@ -28,7 +28,7 @@ def remove_space(point_dict, i): return ans -class Event(): +class Event: """ There are three kinds of events: @@ -59,7 +59,7 @@ def __repr__(self): return repr(ans) -class MorseEncoding(): +class MorseEncoding: """ A MorseEncoding is a concrete encoding of a Morse diagram of an oriented link in the sprit of: @@ -146,7 +146,7 @@ def __iter__(self): return self.events.__iter__() -class BiDict(): +class BiDict: """ A bijective mapping from range(n) to a set of hashable non-integers. @@ -291,7 +291,7 @@ def biggest_all_consecutive_overlap(self): return random.choice(good_choices) -class MorseExhaustion(): +class MorseExhaustion: """ An exhaustion of a link where crossings are added in one-by-one so that the resulting tangle is connected at every stage. diff --git a/spherogram_src/links/extra_tests.py b/spherogram_src/links/extra_tests.py index e3d0f0f..b82e026 100644 --- a/spherogram_src/links/extra_tests.py +++ b/spherogram_src/links/extra_tests.py @@ -7,7 +7,7 @@ def figure8(): - a, b, c, d = [Crossing(x) for x in 'abcd'] + a, b, c, d = (Crossing(x) for x in 'abcd') a[0] = c[1] a[1] = d[0] a[2] = b[1] @@ -27,7 +27,7 @@ def punct_torus(): def whitehead(): - a, b, c, d, e = crossings = [Crossing(x) for x in 'abcde'] + a, b, c, d, e = crossings = (Crossing(x) for x in 'abcde') a[0] = b[3] a[1] = d[0] a[2] = d[3] @@ -56,7 +56,7 @@ def knot(fractions): if len(fractions) == 1: return RationalTangle(*fractions[0]).denominator_closure() else: - A, B, C = [RationalTangle(*f) for f in fractions] + A, B, C = (RationalTangle(*f) for f in fractions) T = A + B + C return T.numerator_closure() diff --git a/spherogram_src/links/invariants.py b/spherogram_src/links/invariants.py index 96e5858..a0e1909 100644 --- a/spherogram_src/links/invariants.py +++ b/spherogram_src/links/invariants.py @@ -425,7 +425,7 @@ def black_graph(self): b = set(faces[j]) s = a.union(b) for x in range(len(self.crossings)): - total = set(self.crossings[x][i] for i in range(4)) + total = {self.crossings[x][i] for i in range(4)} if total.issubset(s): coords.append((tuple(faces[i]), tuple(faces[j]), self.crossings[x])) # label by the crossing. diff --git a/spherogram_src/links/jones.py b/spherogram_src/links/jones.py index f0d333b..9ebb272 100644 --- a/spherogram_src/links/jones.py +++ b/spherogram_src/links/jones.py @@ -86,7 +86,7 @@ def follow(a): return PerfectMatching(new_match), circle -class VElement(): +class VElement: """ An element of some V_{0, n} which is the free R-module on P_{0, n} diff --git a/spherogram_src/links/jones_old.py b/spherogram_src/links/jones_old.py index 75eaebd..7f1de4b 100644 --- a/spherogram_src/links/jones_old.py +++ b/spherogram_src/links/jones_old.py @@ -107,7 +107,7 @@ def is_externally_active(G, T, e): def _edge_sign(K, edge): "Returns the sign (+/- 1) associated to given edge in the black graph." crossing = edge[2] - if set(((crossing, 0), (crossing, 1))).issubset(set(edge[0])) or set(((crossing, 0), (crossing, 1))).issubset(set(edge[1])): + if {(crossing, 0), (crossing, 1)}.issubset(set(edge[0])) or {(crossing, 0), (crossing, 1)}.issubset(set(edge[1])): return +1 return -1 diff --git a/spherogram_src/links/links_base.py b/spherogram_src/links/links_base.py index faf3751..3469d5b 100644 --- a/spherogram_src/links/links_base.py +++ b/spherogram_src/links/links_base.py @@ -68,7 +68,7 @@ def lookup_DT_code_by_name(name): continue -class Crossing(): +class Crossing: """ See "doc.pdf" for the conventions. The sign of a crossing can be in {0, +1, -1}. In the first case, the strands at the crossings can have @@ -130,8 +130,8 @@ def rotate(v): else: self.adjacent[i] = (self, (j - s) % 4) - self.directions = set((rotate(a), rotate(b)) - for a, b in self.directions) + self.directions = {(rotate(a), rotate(b)) + for a, b in self.directions} def rotate_by_90(self): "Effectively switches the crossing" @@ -320,7 +320,7 @@ def add(self, x): self[x] = len(self) -class Strand(): +class Strand: """ When constructing links, it's convenient to have strands as well as crossings. These are stripped by the Link class when it @@ -371,7 +371,7 @@ def enumerate_lists(lists, n=0, filter=lambda x: True): return ans -class Link(): +class Link: """ Links are made from Crossings. The general model is that of the PD diagrams used in `KnotTheory `_. @@ -591,7 +591,7 @@ def _crossings_from_PD_code(self, code): else: gluings[x] = [(c, i)] - if set(len(v) for v in gluings.values()) != set([2]): + if {len(v) for v in gluings.values()} != {2}: raise ValueError("PD code isn't consistent") component_starts = self._component_starts_from_PD( @@ -629,7 +629,7 @@ def _component_starts_from_PD(self, code, labels, gluings): if c1 == c2: # loop at strand, take next strand to be next smallest label # on crossing - next_label = min(set(code[c1]) - set([m])) + next_label = min(set(code[c1]) - {m}) direction = (c1, code[c1].index(next_label)) starts.append(direction) else: @@ -1527,7 +1527,7 @@ def vertex_to_KLP(c, v): return ['Ybackward', 'Xforward', 'Yforward', 'Xbackward'][i] -class KLPCrossing(): +class KLPCrossing: """ SnapPea uses a convention where the orientation of the strands is fixed in the master picture but diff --git a/spherogram_src/links/morse.py b/spherogram_src/links/morse.py index b41b865..4a91864 100644 --- a/spherogram_src/links/morse.py +++ b/spherogram_src/links/morse.py @@ -151,7 +151,7 @@ def __new__(self, crossing_strand, link): return ans -class MorseLinkDiagram(): +class MorseLinkDiagram: """ A planar link diagram with a height function on R^2 which is Morse on the link. @@ -228,7 +228,7 @@ def strands_below(self, crossing): kinds = self.orientations a = CrossingStrand(crossing, 0) b = a.rotate() - upmin = set(['up', 'min']) + upmin = {'up', 'min'} test_a = kinds[a] in upmin while True: test_b = kinds[b] in upmin @@ -364,19 +364,19 @@ def bottom_pairing(snake): cs = snake[0] return tuple(sorted([to_index(cs), to_index(cs.opposite())])) - bottom = set(bottom_pairing(snake) for snake in self.snakes) + bottom = {bottom_pairing(snake) for snake in self.snakes} def top_pairing(snake): cs = snake[-1] cn = self.adjacent_upwards(snake.final) return tuple(sorted([to_index(cs), to_index(cn)])) - top = set(top_pairing(snake) for snake in self.snakes) + top = {top_pairing(snake) for snake in self.snakes} return BridgeDiagram(bottom, [cd[1] for cd in cross_data], top) -class BridgeDiagram(): +class BridgeDiagram: """ A proper bridge diagram of a link, that is, a height function where all the mins are below all the maxes. diff --git a/spherogram_src/links/ordered_set.py b/spherogram_src/links/ordered_set.py index de622bf..dd31425 100644 --- a/spherogram_src/links/ordered_set.py +++ b/spherogram_src/links/ordered_set.py @@ -1,4 +1,4 @@ -class OrderedSet(): +class OrderedSet: def __init__(self, iterable=None): if iterable is not None: self.elts = {e: None for e in iterable} diff --git a/spherogram_src/links/orthogonal.py b/spherogram_src/links/orthogonal.py index 7590c98..fa9cb74 100644 --- a/spherogram_src/links/orthogonal.py +++ b/spherogram_src/links/orthogonal.py @@ -53,7 +53,7 @@ def basic_topological_numbering(G): """ Finds an optimal weighted topological numbering a directed acyclic graph """ - in_valences = dict((v, G.indegree(v)) for v in G.vertices) + in_valences = {v: G.indegree(v) for v in G.vertices} numbering = {} curr_sources = [v for v, i in in_valences.items() if i == 0] curr_number = 0 @@ -325,7 +325,7 @@ def DAG_from_direction(self, kind): def chain_coordinates(self, kind): D = self.DAG_from_direction(kind) chain_coors = topological_numbering(D) - return dict((v, chain_coors[D.vertex_to_chain[v]]) for v in self.vertices) + return {v: chain_coors[D.vertex_to_chain[v]] for v in self.vertices} def basic_grid_embedding(self, rotate=False): """ @@ -333,7 +333,7 @@ def basic_grid_embedding(self, rotate=False): """ V = self.chain_coordinates('horizontal') H = self.chain_coordinates('vertical') - return dict((v, (H[v], V[v])) for v in self.vertices) + return {v: (H[v], V[v]) for v in self.vertices} def show(self, unit=10, labels=True): from sage.all import circle, text, line, Graphics @@ -362,7 +362,7 @@ def show(self, unit=10, labels=True): class Face(CyclicList): def __init__(self, link, crossing_strands, exterior=False): list.__init__(self, crossing_strands) - self.edges = dict((c.oriented(), c) for c in crossing_strands) + self.edges = {c.oriented(): c for c in crossing_strands} self.exterior = exterior self.turns = [1 for e in self] @@ -502,7 +502,7 @@ def bend(self): flow = networkx.min_cost_flow(N) for a, flows in flow.items(): for b, w_a in flows.items(): - if w_a and set(['s', 't']).isdisjoint(set([a, b])): + if w_a and {'s', 't'}.isdisjoint({a, b}): w_b = flow[b][a] A, B = self[a], self[b] e_a, e_b = A.edge_of_intersection(B) @@ -607,7 +607,7 @@ def plink_data(self): b, a = emb[v.crossing] vertex_positions.append((10 * (a + 1), 10 * (b + 1))) - vert_indices = dict((v, i) for i, v in enumerate(self.strand_CEPs)) + vert_indices = {v: i for i, v in enumerate(self.strand_CEPs)} arrows, crossings = self.break_into_arrows() arrows = [(vert_indices[a[0]], vert_indices[a[-1]]) for a in arrows] diff --git a/spherogram_src/links/planar_isotopy.py b/spherogram_src/links/planar_isotopy.py index ee1356b..8a9d8c0 100644 --- a/spherogram_src/links/planar_isotopy.py +++ b/spherogram_src/links/planar_isotopy.py @@ -188,7 +188,7 @@ def all_cross_strands(tangle): other_ends_seen.append(end) orientations, over_or_under = crossing_orientations(strands) cs_seen = [cs for strand in strands for cs in strand] - seen_once = set(cs[0] for cs in cs_seen) + seen_once = {cs[0] for cs in cs_seen} for crossing in orientations: seen_once.remove(crossing) for strand in strands: diff --git a/spherogram_src/links/seifert.py b/spherogram_src/links/seifert.py index 44ec1fe..366d2be 100644 --- a/spherogram_src/links/seifert.py +++ b/spherogram_src/links/seifert.py @@ -79,7 +79,7 @@ def seifert_tree(link): True """ circles = seifert_circles(link) - edges = [[set([n]), set([n])] for n in range(len(circles))] + edges = [[{n}, {n}] for n in range(len(circles))] for c in link.crossings: under, over = c.entry_points() under_circle, over_circle = -1, -1 @@ -116,10 +116,10 @@ def remove_admissible_move(link): found_move = False for e1, e2 in combinations(tree, 2): if e1[0] == e2[0]: # edges start at same point - circles = set([tree.index(e1), tree.index(e2)]) + circles = {tree.index(e1), tree.index(e2)} found_move = True elif e1[1] == e2[1]: # edges end at same point - circles = set([tree.index(e1), tree.index(e2)]) + circles = {tree.index(e1), tree.index(e2)} found_move = True if found_move: move_possible = False @@ -301,7 +301,7 @@ def seifert_matrix(link, return_matrix_of_types=False): from a braid representation." (2007). """ arrows = braid_arrows(link) - strands = set(x[1] for x in arrows) + strands = {x[1] for x in arrows} grouped_by_strand = [[x for x in arrows if x[1] == strand] for strand in strands] hom_gens = [[(group[i][0], group[i + 1][0], group[i][2], group[i + 1][2]) diff --git a/spherogram_src/links/simplify.py b/spherogram_src/links/simplify.py index e544781..393bd6b 100644 --- a/spherogram_src/links/simplify.py +++ b/spherogram_src/links/simplify.py @@ -52,10 +52,10 @@ def reidemeister_I(link, C): for i in range(4): if C.adjacent[i] == (C, (i + 1) % 4): (A, a), (B, b) = C.adjacent[i + 2], C.adjacent[i + 3] - elim = set([C]) + elim = {C} if C != A: A[a] = B[b] - changed = set([A, B]) + changed = {A, B} remove_crossings(link, elim) return elim, changed @@ -81,13 +81,13 @@ def reidemeister_I_and_II(link, A): X, x = A.adjacent[a + 3] Y, y = B.adjacent[b + 1] Z, z = B.adjacent[b + 2] - eliminated = set([A, B]) + eliminated = {A, B} if W != B: W[w] = Z[z] - changed.update(set([W, Z])) + changed.update({W, Z}) if X != B: X[x] = Y[y] - changed.update(set([X, Y])) + changed.update({X, Y}) remove_crossings(link, eliminated) break @@ -147,7 +147,7 @@ def possible_type_III_moves(link): if sum(ce.strand_index % 2 for ce in face) in [1, 2]: while(face[1][1] % 2 != 0 or face[2][1] % 2 != 1): # renumber face_list face = [face[1], face[2], face[0]] - if len(set(e.crossing for e in face)) == 3: # No repeated crossings + if len({e.crossing for e in face}) == 3: # No repeated crossings ans.append(face) return ans @@ -164,8 +164,8 @@ def reidemeister_III(link, triple): Performs the given type III move. Modifies the given link but doesn't update its lists of link components. """ - A, B, C = [t.crossing for t in triple] - a, b, c = [t.strand_index for t in triple] + A, B, C = (t.crossing for t in triple) + a, b, c = (t.strand_index for t in triple) # We insert Strands around the border of the triple to make the code more # transparent and eliminate some special cases. old_border = [(C, c - 1), (C, c - 2), (A, a - 1), @@ -388,7 +388,7 @@ def pickup_strand(link, dual_graph, kind, strand): # of the rest of the components. remove_strand(link, [startcep] + strand) return len(strand) - crossing_set = set(cep.crossing for cep in strand) + crossing_set = {cep.crossing for cep in strand} endpoint = strand[-1].next() if endpoint.crossing in crossing_set: diff --git a/spherogram_src/links/tangles.py b/spherogram_src/links/tangles.py index 6d327fd..5dc201d 100644 --- a/spherogram_src/links/tangles.py +++ b/spherogram_src/links/tangles.py @@ -77,7 +77,7 @@ def decode_boundary(boundary): return (m, n) -class Tangle(): +class Tangle: def __init__(self, boundary=2, crossings=None, entry_points=None, label=None): """ A tangle is a fragment of a Link with some number of boundary diff --git a/spherogram_src/links/test/old_testing_code.py b/spherogram_src/links/test/old_testing_code.py index e3d0f0f..b82e026 100644 --- a/spherogram_src/links/test/old_testing_code.py +++ b/spherogram_src/links/test/old_testing_code.py @@ -7,7 +7,7 @@ def figure8(): - a, b, c, d = [Crossing(x) for x in 'abcd'] + a, b, c, d = (Crossing(x) for x in 'abcd') a[0] = c[1] a[1] = d[0] a[2] = b[1] @@ -27,7 +27,7 @@ def punct_torus(): def whitehead(): - a, b, c, d, e = crossings = [Crossing(x) for x in 'abcde'] + a, b, c, d, e = crossings = (Crossing(x) for x in 'abcde') a[0] = b[3] a[1] = d[0] a[2] = d[3] @@ -56,7 +56,7 @@ def knot(fractions): if len(fractions) == 1: return RationalTangle(*fractions[0]).denominator_closure() else: - A, B, C = [RationalTangle(*f) for f in fractions] + A, B, C = (RationalTangle(*f) for f in fractions) T = A + B + C return T.numerator_closure() diff --git a/spherogram_src/links/test/test_montesinos.py b/spherogram_src/links/test/test_montesinos.py index 835cc96..fb35cc4 100644 --- a/spherogram_src/links/test/test_montesinos.py +++ b/spherogram_src/links/test/test_montesinos.py @@ -14,7 +14,7 @@ def knot(fractions): if len(fractions) == 1: return RationalTangle(*fractions[0]).denominator_closure() else: - A, B, C = [RationalTangle(*f) for f in fractions] + A, B, C = (RationalTangle(*f) for f in fractions) T = A + B + C return T.numerator_closure() diff --git a/spherogram_src/links/twist.py b/spherogram_src/links/twist.py index 1f7dec2..1504415 100644 --- a/spherogram_src/links/twist.py +++ b/spherogram_src/links/twist.py @@ -69,7 +69,7 @@ def __len__(self): def is_end_of_twist_region(crossing) -> bool: - return len(set(C for (C, i) in crossing.adjacent)) == 3 + return len({C for (C, i) in crossing.adjacent}) == 3 def make_twist_regions_consistent(link): diff --git a/spherogram_src/presentations.py b/spherogram_src/presentations.py index 4023106..6136500 100644 --- a/spherogram_src/presentations.py +++ b/spherogram_src/presentations.py @@ -3,7 +3,7 @@ import operator -class Alphabet(): +class Alphabet: """ An Alphabet translates between integers and strings. Call as a function to go from string to integer; use getitem @@ -255,7 +255,7 @@ def __ge__(self, other): return not self < other -class WhiteheadMove(): +class WhiteheadMove: """ Holds the data describing a Whitehead move. """ @@ -283,7 +283,7 @@ def __repr__(self): return ', '.join(subs) -class Presentation(): +class Presentation: """ A Presentation contains a list of CyclicWords as relators and a list of (integer) letters as generators. The generators are @@ -451,7 +451,7 @@ def level_orbit(self, verbose=False): """ S = self.signature() queue = deque([(None, None, self, S)]) - seen = set([S]) + seen = {S} while queue: parent, move, pres, sig = queue.popleft() for a, A in pres.level_transformations(): @@ -495,7 +495,7 @@ def magma_string(self): return ans + '>' -class CanonizeNode(): +class CanonizeNode: def __init__(self, presentation, remaining, ordering=[]): self.presentation = presentation self.generators = presentation.generators