def type_da_in_left_grading(etangle: ETangle, i: int) -> TypeDA: out = TypeDA(etangle.ring, etangle.left_algebra, etangle.right_algebra, etangle.left_scalar_action, etangle.right_scalar_action) strands = [ ETangleStrands(etangle, left_strands, right_strands) for left_strands, right_strands in enumerate_gens([ etangle.left_points(), etangle.middle_points(), etangle.right_points() ], i) ] for x in strands: out.add_generator(x.to_generator(out), (x.to_strand_diagram().maslov(), x.to_strand_diagram().twoalexander())) for x in strands: out.add_structure_map(x.to_generator(out), delta1_1(out, x)) for a in etangle.right_algebra.left_gens(list( x.right_strands.values())): out.add_structure_map(x.to_generator(out)**a, delta1_2(out, x, a)) return out
def test_m2(): # Figure 10 from "An introduction..." cap2 = ETangle(ETangle.Type.CAP, (1, -1, -1), 1) cap2_module = empty_da_module(cap2) sd_cap2_1 = ETangleStrands(cap2, {0: 0, 1: 3}, {2: 0}) sd_cap2_1_out = ETangleStrands(cap2, {0: 0, 1: 3}, {2: 1}).to_generator(cap2_module) algebra1 = AMinus((-1,)) elt1 = algebra1.generator({0: 1}) idem = algebra1.generator({0: 0}) assert m2(cap2_module, sd_cap2_1, elt1) == sd_cap2_1_out assert m2(cap2_module, sd_cap2_1, idem) == sd_cap2_1.to_generator(cap2_module) cup1 = ETangle(ETangle.Type.CUP, (1, -1), 1) cup1_module = empty_da_module(cup1) sd_cup1_1 = ETangleStrands(cup1, {}, {2: 1, 0: 0}) algebra2 = AMinus((1, -1)) idem2 = algebra2.generator({0: 0, 1: 1}) elt = algebra2.generator({1: 0, 2: 2}) sd_cup1_2 = ETangleStrands(cup1, {}, {2: 2, 0: 1}) sd_cup1_2_out = cup1_module.ring['U1'] * ETangleStrands(cup1, {}, {2: 2, 0: 0}).to_generator(cup1_module) assert m2(cup1_module, sd_cup1_1, idem2) == sd_cup1_1.to_generator(cup1_module) assert m2(cup1_module, sd_cup1_2, elt) == sd_cup1_2_out cup2 = ETangle(ETangle.Type.CUP, (-1, 1), 1) cup2_module = empty_da_module(cup2) sd_cup2_1 = ETangleStrands(cup2, {}, {0: 0, 2: 1}) elt2 = cup2.right_algebra.generator({0: 0, 1: 2}) sd_cup2_1_out = cup2_module.ring['U1'] * ETangleStrands(cup2, {}, {0: 0, 2: 2}).to_generator(cup2_module) assert m2(cup2_module, sd_cup2_1, elt2) == sd_cup2_1_out
def valid_dictionaries(et: ETangle, ls: Dict, rs: Dict): for key in ls.keys(): if key not in et.left_points(): return False for val in rs.values(): if val not in et.right_points(): return False return set(ls.values()).union(set(rs.keys())) == set(et.middle_points())
def test_isomorphism(): cup = ETangle(ETangle.Type.CUP, (1, -1), 1) cup_da = type_da(cup) cap = ETangle(ETangle.Type.CAP, (1, -1), 1) cap_da = type_da(cap) assert cup_da.is_isomorphic_to(cup_da) assert not cup_da.is_isomorphic_to(cup_da[1, 0]) assert not cup_da.is_isomorphic_to(cap_da)
def test_halve(): cup = ETangle(ETangle.Type.CUP, (1, -1), 1) cup_da = type_da(cup).reduce() cap = ETangle(ETangle.Type.CAP, (1, -1), 1) cap_da = type_da(cap).reduce() unknot_da = (cup_da ** cap_da).reduce() unknot_da = unknot_da.identify_variables('U1b', 'U1c') unknot_da = unknot_da.halve() assert len(unknot_da.graph.nodes()) == 4
def type_da(etangle: ETangle) -> TypeDA: components = [ type_da_in_left_grading(etangle, r) for r in range(0, len(etangle.left_points()) + 1) ] return TypeDA.direct_sum(components)
def test_type_da(): cup = ETangle(ETangle.Type.CUP, (-1, 1), 1) cup_da = type_da(cup) da_list = [cup_da] for da in da_list: assert len(da.graph.nodes) == 12 assert len(da.decomposed()) == 2
def test_d_minus(): under1 = ETangle(ETangle.Type.OVER, (-1, -1, -1, -1), 2) under1_module = empty_da_module(under1) sd_under1_1 = ETangleStrands(under1, {2: 2, 4: 4}, {0: 0, 1: 1, 3: 3}) sd_under1_1_out = under1.ring['U3'] * under1.ring['U4'] * \ ETangleStrands(under1, {2: 4, 4: 2}, {0: 0, 1: 1, 3: 3}).to_generator(under1_module) # Figure 9 from "An introduction..." over3 = ETangle(ETangle.Type.OVER, (1, 1, -1, -1), 2) over3_module = empty_da_module(over3) sd_over3_1 = ETangleStrands(over3, {1: 2, 2: 1, 3: 4}, {0: 1, 3: 2}) sd_over3_1_out = over3.ring['U3'] * \ ETangleStrands(over3, {1: 2, 2: 4, 3: 1}, {0: 1, 3: 2}).to_generator(over3_module) + \ over3.ring['U3'] * \ ETangleStrands(over3, {1: 4, 2: 1, 3: 2}, {0: 1, 3: 2}).to_generator(over3_module) assert d_minus(under1_module, sd_under1_1) == sd_under1_1_out assert d_minus(over3_module, sd_over3_1) == sd_over3_1_out
def test_delta_ell(): over1 = ETangle(ETangle.Type.OVER, (-1, -1, 1), 2) over1_module = empty_da_module(over1) x = ETangleStrands(over1, {1: 0, 2: 1}, {3: 0, 2: 2}) y = ETangleStrands(over1, {0: 0, 2: 1}, {3: 0, 2: 2}) c = over1.ring.one() elt = over1.left_algebra.generator({0: 1, 3: 3}).to_element() out = elt ** (c * y.to_generator(over1_module)) assert delta_ell(over1_module, x) == out
def test_delta_ell_case_4(): over1 = ETangle(ETangle.Type.OVER, (-1, -1), 1) over1_module = empty_da_module(over1) x = ETangleStrands(over1, {0: 1, 1: 0}, {2: 2}) a1 = 0 a2 = 2 y = ETangleStrands(over1, {2: 1, 1: 0}, {2: 2}) out = over1.left_algebra.generator({2: 0}).to_element() ** (over1.ring['U2'] * y.to_generator(over1_module)) assert delta_ell_case_4(over1_module, x, a1, a2) == out
def test_delta_ell_case_1(): over1 = ETangle(ETangle.Type.OVER, (-1, -1), 1) over1_module = empty_da_module(over1) x = ETangleStrands(over1, {0: 2}, {0: 0, 1: 1}) a1 = 1 a2 = 2 y = x out = over1.left_algebra.generator({1: 2, 2: 1}).to_element() ** \ (over1.ring['U2'] * y.to_generator(over1_module)) assert delta_ell_case_1(over1_module, x, a1, a2) == out
def test_delta_ell_case_2(): over1 = ETangle(ETangle.Type.OVER, (1, 1), 1) over1_module = empty_da_module(over1) x = ETangleStrands(over1, {0: 1, 1: 0}, {2: 2}) a1 = 0 a2 = 1 y = ETangleStrands(over1, {0: 0, 1: 1}, {2: 2}) out = (over1.left_algebra.ring['U1'] * over1.left_algebra.generator({2: 2}).to_element()) ** \ y.to_generator(over1_module) assert delta_ell_case_2(over1_module, x, a1, a2) == out
def test_d_mixed(): # Figure 9 from "An introduction..." over3 = ETangle(ETangle.Type.OVER, (1, 1, -1, -1), 2) over3_module = empty_da_module(over3) sd_over3_1 = ETangleStrands(over3, {1: 2, 2: 1, 3: 4}, {0: 1, 3: 2}) sd_over3_1_out = over3.ring['U2'] * \ ETangleStrands(over3, {1: 1, 2: 2, 3: 4}, {0: 1, 3: 2}).to_generator(over3_module) + \ over3.ring['U2'] * over3.ring['U3'] * \ ETangleStrands(over3, {1: 2, 2: 3, 3: 4}, {0: 1, 1: 2}).to_generator(over3_module) + \ over3.ring['U3'] * \ ETangleStrands(over3, {1: 3, 2: 1, 3: 4}, {0: 1, 2: 2}).to_generator(over3_module) + \ over3.ring.one() * \ ETangleStrands(over3, {1: 2, 2: 1, 3: 3}, {0: 1, 4: 2}).to_generator(over3_module) assert d_mixed(over3_module, sd_over3_1) == sd_over3_1_out
def test_d_plus(): under1 = ETangle(ETangle.Type.UNDER, (1, 1, 1, 1), 2) under1_module = empty_da_module(under1) sd_under1_1 = ETangleStrands(under1, {0: 0, 3: 3, 4: 4}, {1: 4, 2: 3}) sd_under1_1_out = ETangleStrands(under1, {0: 0, 3: 3, 4: 4}, {1: 3, 2: 4}).to_generator(under1_module) sd_under1_2 = ETangleStrands(under1, {0: 0, 2: 2, 3: 3}, {1: 3, 4: 0}) sd_under1_2_out = under1.ring['U2'] * under1.ring['U3'] * \ ETangleStrands(under1, {0: 0, 2: 2, 3: 3}, {1: 0, 4: 3}).to_generator(under1_module) under2 = ETangle(ETangle.Type.UNDER, (1, -1, 1, 1), 2) under2_module = empty_da_module(under2) sd_under2_1 = ETangleStrands(under2, {0: 0, 3: 3, 4: 4}, {1: 4, 2: 3}) sd_under2_1_out = ETangleStrands(under2, {0: 0, 3: 3, 4: 4}, {1: 3, 2: 4}).to_generator(under2_module) sd_under2_2 = ETangleStrands(under2, {0: 0, 2: 2, 3: 3}, {1: 3, 4: 0}) sd_under2_2_out = under2_module.zero() over1 = ETangle(ETangle.Type.OVER, (1, 1, 1, 1), 2) over1_module = empty_da_module(over1) sd_over1_1 = ETangleStrands(over1, {4: 4, 1: 1, 3: 3}, {2: 2, 0: 4}) sd_over1_1_out = over1.ring['U2'] * \ ETangleStrands(over1, {4: 4, 1: 1, 3: 3}, {0: 2, 2: 4}).to_generator(over1_module) sd_over1_2 = ETangleStrands(over1, {1: 1, 4: 4, 3: 3}, {2: 1, 0: 4}) sd_over1_2_out = over1.ring['U2'] * \ ETangleStrands(over1, {1: 1, 4: 4, 3: 3}, {0: 1, 2: 4}).to_generator(over1_module) over2 = ETangle(ETangle.Type.OVER, (1, 1, -1, 1), 2) over2_module = empty_da_module(over2) sd_over2_1 = ETangleStrands(over2, {1: 1, 0: 0, 4: 4}, {3: 1, 2: 4}) sd_over2_1_out = over2_module.zero() # Figure 9 from "An introduction..." over3 = ETangle(ETangle.Type.OVER, (1, 1, -1, -1), 2) over3_module = empty_da_module(over3) sd_over3_1 = ETangleStrands(over3, {1: 2, 2: 1, 3: 4}, {0: 1, 3: 2}) sd_over3_1_out = over3_module.zero() cap1 = ETangle(ETangle.Type.CAP, (1, 1, -1, 1), 2) cap1_module = empty_da_module(cap1) sd_cap1_1 = ETangleStrands(cap1, {0: 0, 1: 1}, {4: 1, 3: 2}) sd_cap1_1_out = cap1.ring['U3'] * ETangleStrands(cap1, {0: 0, 1: 1}, {4: 2, 3: 1}).to_generator(cap1_module) sd_cap1_2 = ETangleStrands(cap1, {3: 3, 1: 1}, {4: 0, 0: 2}) sd_cap1_2_out = cap1.ring['U1'] * cap1.ring['U3'] * \ ETangleStrands(cap1, {3: 3, 1: 1}, {4: 2, 0: 0}).to_generator(cap1_module) assert d_plus(under1_module, sd_under1_1) == sd_under1_1_out assert d_plus(under1_module, sd_under1_2) == sd_under1_2_out assert d_plus(under2_module, sd_under2_1) == sd_under2_1_out assert d_plus(under2_module, sd_under2_2) == sd_under2_2_out assert d_plus(over1_module, sd_over1_1) == sd_over1_1_out assert d_plus(over1_module, sd_over1_2) == sd_over1_2_out assert d_plus(over2_module, sd_over2_1) == sd_over2_1_out assert d_plus(over3_module, sd_over3_1) == sd_over3_1_out assert d_plus(cap1_module, sd_cap1_1) == sd_cap1_1_out assert d_plus(cap1_module, sd_cap1_2) == sd_cap1_2_out
def test_comparison(): assert t1 + t2 == t1 + ETangle(ETangle.Type.CUP, (-1, 1, -1, 1), 3)
# some simple examples from Tangles.Tangle import ETangle, Tangle from Tangles.TangleRenderer import TangleRenderer cup = ETangle(ETangle.Type.CUP, (1, -1), 1) over = ETangle(ETangle.Type.OVER, (1, -1), 1) under = ETangle(ETangle.Type.UNDER, (1, -1), 1) cap = ETangle(ETangle.Type.CAP, (1, -1), 1) unknot = Tangle((cup, cap)) unknot2 = Tangle((cup, over, under, cap)) straight = ETangle(ETangle.Type.STRAIGHT, (1, -1)) straight2 = ETangle(ETangle.Type.STRAIGHT, (1, 1)) # some larger examples cup2 = ETangle(ETangle.Type.CUP, (-1, -1, 1, -1), 2) over2 = ETangle(ETangle.Type.OVER, (-1, -1, 1, -1), 2) under2 = ETangle(ETangle.Type.UNDER, (-1, -1, 1, -1), 2) cap2 = ETangle(ETangle.Type.CAP, (-1, -1, 1, -1), 2) # the trefoil from the paper t1 = ETangle(ETangle.Type.CUP, (-1, 1), 1) t2 = ETangle(ETangle.Type.CUP, (-1, 1, -1, 1), 3) t3 = ETangle(ETangle.Type.OVER, (-1, 1, -1, 1), 2) t4 = ETangle(ETangle.Type.UNDER, (-1, -1, 1, 1), 1) t5 = ETangle(ETangle.Type.OVER, (-1, -1, 1, 1), 2) t6 = ETangle(ETangle.Type.CAP, (-1, 1, -1, 1), 1) t7 = ETangle(ETangle.Type.CAP, (-1, 1), 1) trefoil = Tangle((t1, t2, t3, t4, t5, t6, t7)) # more examples b1 = ETangle(ETangle.Type.UNDER, (1, 1, 1), 1)
def test_da_speed(): # cup = ETangle(ETangle.Type.OVER, (-1, 1, -1), 1) cup = ETangle(ETangle.Type.OVER, (-1, 1), 1) for _ in range(1): da = type_da(cup) assert True