Esempio n. 1
0
    def setUp(self):
        # Trefoil
        a = spherogram.Crossing('a')
        b = spherogram.Crossing('b')
        c = spherogram.Crossing('c')
        a[2] = b[1]
        b[3] = c[0]
        c[2] = a[1]
        a[3] = b[0]
        b[2] = c[1]
        c[3] = a[0]
        self.Tref = spherogram.Link([a,b,c])

        self.K3_1 = spherogram.Link('3_1')
        self.K7_2 = spherogram.Link('7_2')
        self.K8_3 = spherogram.Link('8_3')
        self.K8_13 = spherogram.Link('8_13')

        # Hopf Link
        a = spherogram.Crossing('a') 
        b = spherogram.Crossing('b') 
        a[0]=b[1] 
        a[1]=b[0] 
        a[2]=b[3] 
        a[3]=b[2] 
        self.L2a1 = spherogram.Link([a,b])

        #Borromean Link (3) 
        a = spherogram.Crossing('a') 
        b = spherogram.Crossing('b') 
        c = spherogram.Crossing('c') 
        d = spherogram.Crossing('d') 
        e = spherogram.Crossing('e') 
        f = spherogram.Crossing('f') 
        a[2] = f[1]
        a[3] = e[0] 
        b[1] = a[0] 
        b[2] = e[3] 
        c[0] = a[1] 
        c[1] = b[0] 
        d[3] = c[2] 
        d[0] = b[3] 
        e[2] = d[1] 
        e[1] = f[0] 
        f[2] = c[3] 
        f[3] = d[2] 
        self.Borr = spherogram.Link([a,b,c,d,e,f])
        
        self.L6a2 = spherogram.Link('L6a2')
        self.L6a4 = spherogram.Link('L6a4')
        self.L7a3 = spherogram.Link('L7a3')

        self.knots = [self.K3_1, self.K7_2, self.K8_3, self.K8_13]
        self.links = [self.L2a1, self.L6a4, self.L6a2, self.L7a3]
        self.all_links = self.knots + self.links
def from_gauss_code(code):
    """
    This is the basic unsigned/unoriented variant.

    >>> L = from_gauss_code(unknot_28)
    >>> L.simplify('pickup')
    True
    >>> L
    <Link: 0 comp; 0 cross>
    >>> L.unlinked_unknot_components
    1
    """
    n = len(code)
    labels = list(range(1, n + 1))
    code_to_label = dict(zip(code, labels))
    label_to_code = dict(zip(labels, code))
    dt = []
    for i in range(1, n, 2):
        a = label_to_code[i]
        j = code_to_label[-a]
        if a < 0:
            j = -j
        dt.append(j)

    return spherogram.Link(f'DT: {dt}')
Esempio n. 3
0
def link_diagram(G):
    face_list = faces(G)
    #print(face_list)
    crossing_dict = {}

    for edge in G.edges:  #create one crossing per edge
        l = label(edge)
        crossing_dict[l] = spherogram.Crossing(l)

    for face in face_list:  #connect along faces
        for n, direction in enumerate(face):
            edge = direction[0]
            next_edge = face[(n + 1) % len(face)][0]
            c = crossing_dict[label(edge)]
            cnext = crossing_dict[label(next_edge)]
            o = open_overposition(c)
            u = open_underposition(cnext)
            #            print('c,o: ')
            #            print(c,o)
            #            print('cnext,u: ')
            #            print(cnext,u)
            c[o] = cnext[u]

    for edge in G.edges:  #switch twisted edges
        c = crossing_dict[label(edge)]
        if edge.twisted:
            c.rotate_by_90()

    return spherogram.Link(crossing_dict.values())
Esempio n. 4
0
    def spherogram(self):
        """
        Return a spherogram Link object.
        """

        vertices = self.ribbon_graph.vertices()
        edges = self.ribbon_graph.edges()
        PD = []
        for v in vertices:
            needs_rotation = False
            if self.heights[v[0]] == 1:
                needs_rotation = True
            vertex_code = []
            for i in v:
                for j, edge in enumerate(edges):
                    if i in edge:
                        vertex_code.append(j)
                        break

            if needs_rotation:
                new_vertex_code = vertex_code[1:]
                new_vertex_code.append(vertex_code[0])
                vertex_code = new_vertex_code

            PD.append(vertex_code)
        return spherogram.Link(PD)
Esempio n. 5
0
def petaluma_knot(height_perm):
    size = len(height_perm)
    crossing_dict = {}
    visited_dict = {}
    for i in range(size - 1):
        for j in range(i + 1, size):
            crossing_dict[(i, j)] = sg.Crossing('c' + str(i) + str(j))
            visited_dict[(i, j)] = False
    end_position = 2
    if height_perm[1] < height_perm[0]:
        end_position = 3
    old_crossing = crossing_dict[0, 1]
    visited_dict[0, 1] = True

    for i in range(size):
        for j in strands_to_cross(size, i):
            if (i, j) == (0, 1):
                continue
            a, b = sorted([i, j])  #must be ordered
            next_crossing = crossing_dict[a, b]
            ordered_or_backward = 0
            if i > j:
                ordered_or_backward = 1
            if height_perm[i] < height_perm[
                    j]:  # strand i passes under strand j
                if not visited_dict[a, b]:  #if first time crossing has come up
                    next_crossing[0] = old_crossing[end_position]
                    end_position = 2
                else:  #crossing has been seen before
                    if (
                            b - a
                    ) % 2 == 1:  #strand j should cross strand i right to left
                        next_crossing[2] = old_crossing[end_position]
                        end_position = 0
                    else:  #left to right
                        next_crossing[0] = old_crossing[end_position]
                        end_position = 2
            else:  #strand i passes over strand j
                if not visited_dict[a, b]:
                    next_crossing[1] = old_crossing[end_position]
                    end_position = 3
                else:  #crossing has been seen before
                    if (b - a) % 2 == 1:  #right to left
                        next_crossing[1] = old_crossing[end_position]
                        end_position = 3
                    else:  #left to right
                        next_crossing[3] = old_crossing[end_position]
                        end_position = 1
            visited_dict[a, b] = True
            old_crossing = next_crossing

    first = crossing_dict[0, 1]
    last = crossing_dict[size - 2, size - 1]
    first_open = first.adjacent.index(None)  #last open spot
    last_open = last.adjacent.index(None)
    first[first_open] = last[last_open]
    return sg.Link(crossing_dict.values())
def regina_DT(code):
    """
    >>> L = regina_DT('flmnopHKRQGabcdeJI')
    >>> L
    <Link: 1 comp; 18 cross>
    >>> L = regina_DT('hPONrMjsLfiQGDCBKae')
    >>> L
    <Link: 1 comp; 19 cross>
    """
    cross = len(code)
    l = string.ascii_letters[cross - 1]
    dt_prefix = 'DT: ' + l + 'a' + l
    return spherogram.Link(dt_prefix + code)
Esempio n. 7
0
def unknot_search(num_attempts, backtrack_height, num_mutations):
    c = spherogram.Crossing(0)
    c[0] = c[1]
    c[2] = c[3]
    U = spherogram.Link([c])
    for i in range(num_attempts):
        print(i)
        Uc = U.copy()
        Uc.backtrack(backtrack_height)
        for i in range(num_mutations):
            Uc = random_mutate(Uc)
        Uc.simplify(mode='level')
        if len(Uc) > 0:
            return Uc
    return None
def test_knot(snappy_manifold):
    M = snappy_manifold
    assert M.num_cusps() == 1

    U = M.link()
    T = U.sage_link()

    assert [list(x) for x in U.PD_code(min_strand_index=1)] == T.pd_code()
    assert U.alexander_polynomial() == alexander_poly_of_sage(T)
    assert U.signature() == T.signature()
    assert U.jones_polynomial() == jones_polynomial_of_sage(T)

    T_alt = SageLink(U.braid_word(as_sage_braid=True))
    assert U.signature() == T_alt.signature()
    U_alt = spherogram.Link(T.braid())
    assert U.signature() == U_alt.signature()
Esempio n. 9
0
    and the second list consisting of the values [v_0, ... , v_(n-1)]
    of sigma on the interval (x_i, x_(i+1)).  Currently, the value of
    sigma *at* x_i is not computed.
    """
    V = L.seifert_matrix()
    return signature_function_of_integral_matrix(V)


def basic_knot_test():
    # All passed!
    for M in snappy.HTLinkExteriors(cusps=1):
        print(M.name())
        R = PolynomialRing(ZZ, 't')
        K = M.link()
        V = matrix(K.seifert_matrix())
        p0 = R(M.alexander_polynomial())
        p1 = R(K.alexander_polynomial())
        p2 = alexander_poly_from_seifert(V)
        assert p0 == p1 == p2
        partition, values = signature_function_of_integral_matrix(V)
        n = len(values)
        assert n % 2 == 1
        m = (n - 1) // 2
        assert K.signature() == values[m]


if __name__ == '__main__':
    K = spherogram.Link('K12n123')
    V = matrix(ZZ, K.seifert_matrix())
    basic_knot_test()
Esempio n. 10
0
import spherogram
import random


def test(link):
    for i in range(10):
        L = link.copy()
        L.simplify('global')
        L.PD_code()
        expected = len(link.link_components) + L.unlinked_unknot_components
        print(L, L.unlinked_unknot_components, '\n')


C = spherogram.Link([(9, 17, 10, 16), (5, 18, 6, 19), (17, 4, 18, 5),
                     (2, 15, 3, 16), (14, 8, 15, 7), (6, 14, 7, 13),
                     (1, 13, 2, 12), (28, 22, 29, 21), (19, 11, 20, 10),
                     (8, 4, 9, 3), (24, 27, 25, 0), (26, 23, 27, 24),
                     (22, 25, 23, 26), (11, 21, 12, 20), (29, 0, 28, 1)])

test(C)

B = spherogram.Link([(9, 19, 10, 18), (4, 17, 5, 18), (16, 3, 17, 4),
                     (2, 15, 3, 16), (14, 8, 15, 7), (6, 14, 7, 13),
                     (1, 13, 2, 12), (28, 22, 29, 21), (19, 11, 20, 10),
                     (8, 6, 9, 5), (24, 27, 25, 0), (26, 23, 27, 24),
                     (22, 25, 23, 26), (11, 21, 12, 20), (29, 0, 28, 1)])

test(B)

# component incorrectly updated?
A = spherogram.Link([(21, 31, 22, 30), (16, 29, 17, 30), (28, 15, 29, 16),