Ejemplo n.º 1
0
def matrix_index1(overstrand_list, color_list, sign_list, p):

    wherelists = i2l.where_lists(color_list, overstrand_list, p)
    horizontalorder = i2l.horizontal_order(color_list, overstrand_list, p)
    verticalorder = i2l.vertical_order(color_list, overstrand_list, p)

    n = len(color_list)
    num_index2 = (p - 1) // 2
    numCol = num_index2 * n + 1
    numRow = num_index2 * n
    coeff_matrix = [[0] * numCol for i in range(numRow)]  # Build zero matrix
    for i in range(n):
        a = horizontalorder[i][0]  # update a,b,c,d at each crossing
        b = horizontalorder[i][1]
        c = verticalorder[i][0]
        d = verticalorder[i][1]

        # Find all epsilons
        epsilon = sign_list[i]
        if color_list[overstrand_list[i]] == wherelists[a - 1][i]:
            epsilon_a_two = 1
        else:
            epsilon_a_two = -1

        if dl5.reflect(wherelists[b - 1][i], color_list[i],
                       p) == color_list[(i + 1) % n]:
            epsilon_b_two = 1
        else:
            epsilon_b_two = -1

        if wherelists[c - 1][overstrand_list[i]] == dl5.reflect(
                color_list[overstrand_list[i]], color_list[i], p):
            epsilon_c_one = 1
        else:
            epsilon_c_one = -1

        if wherelists[d - 1][overstrand_list[i]] == color_list[(i + 1) % n]:
            epsilon_d_one = 1
        else:
            epsilon_d_one = -1

        # Fill rows 0-3 with top equations
        coeff_matrix[i][i + (a - 1) * n] = 1
        coeff_matrix[i][(i + 1) % n + (a - 1) * n] = -1
        coeff_matrix[i][overstrand_list[i] +
                        (c - 1) * n] = epsilon_c_one * epsilon_a_two
        coeff_matrix[i][-1] = epsilon * epsilon_a_two
        # Fill rows 4-7 with bottom equations
        coeff_matrix[i + n][i + (b - 1) * n] = 1
        coeff_matrix[i + n][(i + 1) % n + (b - 1) * n] = -1
        coeff_matrix[i + n][overstrand_list[i] +
                            (c - 1) * n] = epsilon_c_one * epsilon_b_two
        coeff_matrix[i + n][overstrand_list[i] +
                            (d - 1) * n] = epsilon_d_one * epsilon_b_two

    return Matrix(coeff_matrix).rref()
Ejemplo n.º 2
0
def where_lists(colourlist, overstrandlist, p):

    universes = universe_lists(colourlist, overstrandlist, p)
    # print(universes)
    where_lists = []

    for i in range((p - 1) // 2):
        # print(i)
        # print(universes[0], i % 2, i)
        if colourlist[0] == colourlist[overstrandlist[0]]:
            # print("homogeneous")
            # print("universes:", universes[0])
            # print("level:", universes[0][i])
            current_universe = universes[0][i][0]
        else:
            # print("inhomogeneous")
            current_universe = universes[0][i % 2][
                i]  # this is where the error is ?
        where_list = [current_universe]

        for j in range(len(colourlist)):

            overstrand = overstrandlist[j]
            over_colour = colourlist[overstrand]

            current_universe = dl5.reflect(current_universe, over_colour, p)
            where_list.append(current_universe)

        where_lists.append(where_list)

    return where_lists
Ejemplo n.º 3
0
def horizontal_order(colourlist, overstrandlist, p):

    universes = universe_lists(colourlist, overstrandlist, p)
    wheres = where_lists(colourlist, overstrandlist, p)

    order_lists = []

    for i in range(len(colourlist)):

        colour_in = colourlist[i]
        colour_over = colourlist[overstrandlist[i]]
        crossing_universes = universes[i]
        order_list = [0 for x in range((p - 1) // 2)]

        if colour_in == colour_over:

            for j in range((p - 1) // 2):
                where = wheres[j][i]
                for k in range((p - 1) // 2):
                    if where in crossing_universes[k]:
                        order_list[k] = j + 1

            order_lists.append(order_list)

        else:
            left_universes = crossing_universes[0]
            right_universes = crossing_universes[1]

            for j in range((p - 1) // 2):

                where = wheres[j][i]
                pair = dl5.reflect(where, colour_in, p)

                if where in left_universes and pair in left_universes:
                    index1 = index(left_universes, where)
                    index2 = index(left_universes, pair)
                else:
                    index1 = index(right_universes, where)
                    index2 = index(right_universes, pair)

                level = min(index1, index2)
                order_list[level] = j + 1

            order_lists.append(order_list)

    return order_lists
Ejemplo n.º 4
0
def universe_lists(colourlist, overstrandlist, p):

    n = len(colourlist)
    universes = []

    for i in range(n):
        overstrand = overstrandlist[i]
        colour_in = colourlist[i]
        colour_out = colourlist[(i + 1) % n]
        colour_over = colourlist[overstrand]

        if colour_in == colour_out:

            universe_pairs = []

            for j in range((p - 1) // 2):

                current_universe = (colour_in + j + 1) % p
                if current_universe == 0:
                    current_universe = p
                universe_pairs.append([
                    current_universe,
                    dl5.reflect(current_universe, colour_in, p)
                ])

            universes.append(universe_pairs)

        else:

            universes_left = [colour_over]
            current_universe = colour_over

            for j in range((p - 1) // 2):

                if j % 2 == 0:
                    next_universe = dl5.reflect(current_universe, colour_in, p)
                else:
                    next_universe = dl5.reflect(current_universe, colour_out,
                                                p)

                current_universe = next_universe
                universes_left.append(current_universe)

            universes_right = [colour_over]

            current_universe = colour_over

            for k in range((p - 1) // 2):

                if k % 2 == 0:
                    next_universe = dl5.reflect(current_universe, colour_out,
                                                p)
                else:
                    next_universe = dl5.reflect(current_universe, colour_in, p)

                current_universe = next_universe
                universes_right.append(current_universe)

            universes.append([universes_left, universes_right])

    return universes
Ejemplo n.º 5
0
def matrix_to_dln(colourlist, overstrandlist, signlist, coeff_dict, p, k):

    universes_list = i2l.universe_lists(colourlist, overstrandlist, p)
    wheres = i2l.where_lists(colourlist, overstrandlist, p)
    vert_order = i2l.vertical_order(colourlist, overstrandlist, p)
    dlns = []

    dln = 0
    # print('K = ', k)
    if coeff_dict == "X":       # No DLN Exists
        for i in range(((p - 1) // 2) + 1):
            dlns.append("x")

    else:
        # Linking number of Index 1 knot with surface
        zero_2chain = rrematrix_to_dict(matrix.create_matrix(overstrandlist, colourlist, signlist, p, 0), p, 0)
        if zero_2chain == "X":
            dln = "x"
        else:
            for i in range(len(colourlist)):
                if colourlist[i] == colourlist[overstrandlist[i]]:
                    # print("homogeneous => no change. DLN = ", dln)
                    dln += 0
                else:
                    over_index = vert_order[i][-1]      # Need bottom overstrand
                    where_over = wheres[over_index - 1][overstrandlist[i]]

                    if where_over == colourlist[i]:
                        epsilon1 = 1
                    else:
                        epsilon1 = -1

                    if signlist[i] * epsilon1 == 1:
                        # Walk through R wall
                        dln += signlist[i] * coeff_dict[(over_index, overstrandlist[i])]

                    else:
                        # Walk through L wall
                        dln -= signlist[i] * coeff_dict[(over_index, overstrandlist[i])]
                        if k == over_index:
                            dln += signlist[i]
        dlns.append(dln)

        # Linking numbers of Index 2 knots with surface
        for j in range(len(wheres)):        # Go through each of the index 2 knots

            where_list = wheres[j]
            dln = 0

            j_2chain = rrematrix_to_dict(matrix.create_matrix(overstrandlist, colourlist, signlist, p, j + 1), p, j + 1)
            if j_2chain == "X":
                dln = "x"
            else:
                for i in range(len(where_list) - 1):        # Go through each crossing
                    where_under = where_list[i]
                    universes = universes_list[i]
                    # print("crossing:", i)

                    if colourlist[i] == colourlist[overstrandlist[i]]:
                        for x in range(len(universes)):     # list of pairs of universes
                            if where_under in universes[x]:
                                over_index = vert_order[i][x]

                    else:
                        if where_under in universes[0] and where_under in universes[1]:
                            # Must be on the top level, so a(j) = 0
                            over_index = 0
                        else:
                            if where_under in universes[0]:
                                level = i2l.index(universes[0], where_under)
                            else:
                                level = i2l.index(universes[1], where_under)

                            over_index = vert_order[i][level - 1]

                    if over_index == 0:
                        where_over = colourlist[overstrandlist[i]]
                        # print("adding index 1 wall")
                        # print("coefficient:", coeff_dict[(0, overstrandlist[i])])
                        dln += signlist[i] * coeff_dict[(0, overstrandlist[i])]
                        # print()
                        # print(dln)
                    else:
                        where_over = wheres[over_index - 1][overstrandlist[i]]

                        # print(where_under, where_over)

                        reflections = [dln5.reflect(where_over, colourlist[i], p),
                                       dln5.reflect(where_over, colourlist[overstrandlist[i]], p)]
                        if where_under in reflections:
                            epsilon1 = 1
                        else:
                            epsilon1 = -1
                        # print("adding wall", (over_index, overstrandlist[i]))
                        # if epsilon1 * signlist[i] == -1:
                        #     print("right")
                        # else:
                        #     print("left")
                        # print("coefficient:", -epsilon1 * signlist[i] * coeff_dict[(over_index, overstrandlist[i])])
                        dln -= epsilon1 * coeff_dict[(over_index, overstrandlist[i])]

                        if k == over_index:
                            # print("since over_index = k, add", (signlist[i] + epsilon1) // 2)
                            dln += (signlist[i] + epsilon1) // 2
                        # print()
                # print("Final DLN:", dln)
                # print()
            dlns.append(dln)

    return dlns
Ejemplo n.º 6
0
def create_matrix(overstrandlist, colorlist, signlist, p, k):
    # k = number of the surface. k = 0 => index 1 surface, k = 1 => 1st index 2, etc.

    wherelists = i2l.where_lists(colorlist, overstrandlist, p)
    horizontalorder = i2l.horizontal_order(colorlist, overstrandlist, p)
    verticalorder = i2l.vertical_order(colorlist, overstrandlist, p)
    # print(verticalorder)

    n = len(colorlist)
    num_index2 = (p - 1) // 2
    numCol = num_index2 * n + 1
    numRow = num_index2 * n
    coeff_matrix = [[0] * numCol for i in range(numRow)]  # Build zero matrix

    for i in range(n):

        for j in range(num_index2):
            # print(j)
            h = horizontalorder[i][j]
            where_under = wherelists[h - 1][i]
            # edit matrix so that x^h_i = 1, x^h_(i+1) = -1
            coeff_matrix[i + j * n][i + (h - 1) * n] = 1
            coeff_matrix[i + j * n][(i + 1) % n + (h - 1) * n] = -1

            # a = index of overstrand above understrand, b = index of overstrand below understrand
            # (for homogeneous crossing, a = b)
            # We have 8 cases in total to consider:
            # 1. if i is inhomogeneous, j = 0 and k = 0
            # 2. if i is inhomogeneous, j = 0 and k = b
            # 3. if i is inhomogeneous, j = 0 and k != 0, b
            # 4. if i is inhomogeneous, j != 0 and k != a, b
            # 5. if i is inhomogeneous, j != 0, k = a
            # 6. if i is inhomogeneous, j != 0, k = b
            # 7. if i is homogeneous, k != a
            # 8. if i is homogeneous, k = a

            if colorlist[i] == colorlist[overstrandlist[i]]:
                # homogeneous crossing
                # find a
                a = verticalorder[i][j]

                # find where of understrand and overstrand
                # look at a^th index 2 when overstrand is the understrand
                where_over = wherelists[a - 1][overstrandlist[i]]
                # find epsilon1
                if where_under == where_over:
                    epsilon1 = -1
                else:
                    epsilon1 = 1

                coeff_matrix[i + j * n][overstrandlist[i] +
                                        (a - 1) * n] += 2 * epsilon1

                if k == a:  # (Case 8)
                    # x^h_i - x^h_{i+1} + 2epsilon4 x^a_{f(i)} = epsilon4
                    coeff_matrix[i + j * n][-1] = epsilon1
            else:
                # inhomogeneous crossing
                b = verticalorder[i][j]
                # epsilon_b = 1 if where functions are next to each other, -1 otherwise
                where_over = wherelists[b - 1][overstrandlist[i]]

                reflections = [
                    dln5.reflect(where_under, colorlist[i], p),
                    dln5.reflect(where_under, colorlist[overstrandlist[i]], p)
                ]

                if where_over in reflections:
                    epsilon1 = 1
                else:
                    epsilon1 = -1

                coeff_matrix[i +
                             j * n][overstrandlist[i] + (b - 1) *
                                    n] = epsilon1  # (Case 1, 2, 3, 4, 5, 6)
                if k == b:
                    if where_over in [
                            where_under,
                            dln5.reflect(where_under, colorlist[i], p)
                    ]:
                        epsilon2 = 1
                    else:
                        epsilon2 = -1
                    if signlist[i] * epsilon2 == -1:
                        coeff_matrix[i +
                                     j * n][-1] = epsilon1  # (Case 2, Case 6)

                if j == 0 and k == 0:  # (Case 1)
                    # find epsilon0 (previously epsilon_a_2)
                    if where_under == colorlist[overstrandlist[i]]:
                        epsilon0 = 1
                    else:
                        epsilon0 = -1
                    # constant in matrix = signlist[i] * epsilon0
                    coeff_matrix[i + j * n][-1] = epsilon0 * signlist[i]

                if j != 0:
                    a = verticalorder[i][j - 1]
                    # epsilon1 = 1 if where functions are next to each other, -1 otherwise
                    where_over = wherelists[a - 1][overstrandlist[i]]

                    reflections = [
                        dln5.reflect(where_under, colorlist[i], p),
                        dln5.reflect(where_under, colorlist[overstrandlist[i]],
                                     p)
                    ]

                    if where_over in reflections:
                        epsilon1 = 1
                    else:
                        epsilon1 = -1

                    coeff_matrix[i + j * n][overstrandlist[i] + (a - 1) *
                                            n] = epsilon1  # (Case 4, 5, 6)

                    if k == a:
                        if where_over in [
                                where_under,
                                dln5.reflect(where_under, colorlist[i], p)
                        ]:
                            epsilon2 = 1
                        else:
                            epsilon2 = -1
                        if signlist[i] * epsilon2 == -1:
                            coeff_matrix[i + j * n][-1] = epsilon1  # (Case 5)

    # print(coeff_matrix)
    return Matrix(coeff_matrix).rref()