|
| 1 | +# Copyright (c) 2025 Eric Sabo |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +############################# |
| 8 | + # constructors |
| 9 | +############################# |
| 10 | + |
| 11 | +function GeneralizedToricCode(f::CTLRPolyElem, g::CTLRPolyElem) |
| 12 | + LR = parent(f) |
| 13 | + LR == parent(g) || throw(ArgumentError("The polynomials must be over the same ring.")) |
| 14 | + length(symbols(LR)) == 2 || throw(ArgumentError("The polynomials must be over a Laurent polynomial ring in two variables.")) |
| 15 | + return GeneralizedToricCode(LR, base_ring(LR), f, g) |
| 16 | +end |
| 17 | + |
| 18 | +function FiniteGeneralizedToricCode(f::CTLRPolyElem, g::CTLRPolyElem, a1::Tuple{Int, Int}, |
| 19 | + a2::Tuple{Int, Int}) |
| 20 | + |
| 21 | + LR = parent(f) |
| 22 | + LR == parent(g) || throw(ArgumentError("The polynomials must be over the same ring.")) |
| 23 | + length(symbols(LR)) == 2 || throw(ArgumentError("The polynomials must be over a Laurent polynomial ring in two variables.")) |
| 24 | + return FiniteGeneralizedToricCode(LR, base_ring(LR), f, g, a1, a2) |
| 25 | +end |
| 26 | + |
| 27 | +############################# |
| 28 | + # getter functions |
| 29 | +############################# |
| 30 | + |
| 31 | +Laurent_polynomial_ring(S::AbstractGeneralizedToricCode) = S.LR |
| 32 | + |
| 33 | +field(S::AbstractGeneralizedToricCode) = S.F |
| 34 | + |
| 35 | +defining_polynomials(S::AbstractGeneralizedToricCode) = S.f, S.g |
| 36 | + |
| 37 | +twist_vectors(S::FiniteGeneralizedToricCode) = S.a1, S.a2 |
| 38 | + |
| 39 | +############################# |
| 40 | + # setter functions |
| 41 | +############################# |
| 42 | + |
| 43 | +############################# |
| 44 | + # general functions |
| 45 | +############################# |
| 46 | + |
| 47 | +function maximum_dimension(S::AbstractGeneralizedToricCode) |
| 48 | + R2 = Oscar._polyringquo(S.LR) |
| 49 | + R = codomain(R2) |
| 50 | + (x, y) = gens(S.LR) |
| 51 | + if isa(S, FiniteGeneralizedToricCode) |
| 52 | + I = ideal(S.LR, [S.f, S.g, x^S.a1[1] * y^S.a1[2] - 1, x^S.a2[1] * y^S.a2[2] - 1]) |
| 53 | + else |
| 54 | + I = ideal(S.LR, [S.f, S.g]) |
| 55 | + end |
| 56 | + II = ideal(R, R2.(gens(I))) |
| 57 | + Q, ϕ = quo(R, II) |
| 58 | + return 2 * vector_space_dimension(Q) |
| 59 | +end |
| 60 | + |
| 61 | +function CSSCode(S::FiniteGeneralizedToricCode) |
| 62 | + R2 = Oscar._polyringquo(S.LR) |
| 63 | + R = codomain(R2) |
| 64 | + (x, y) = gens(S.LR) |
| 65 | + swap = hom(S.LR, S.LR, [x^-1, y^-1]) |
| 66 | + f_anti = swap(S.f) |
| 67 | + g_anti = swap(S.g) |
| 68 | + f_R2 = R2(S.f) |
| 69 | + g_R2 = R2(S.g) |
| 70 | + f_anti_R2 = R2(f_anti) |
| 71 | + g_anti_R2 = R2(g_anti) |
| 72 | + I = ideal(S.LR, [x^S.a1[1] * y^S.a1[2] - 1, x^S.a2[1] * y^S.a2[2] - 1]) |
| 73 | + II = ideal(R, R2.(gens(I))) |
| 74 | + Q, ϕ = quo(R, II) |
| 75 | + |
| 76 | + mono = monomial_basis(Q) |
| 77 | + len_mon = length(mono) |
| 78 | + n = 2 * len_mon |
| 79 | + LR_edge_index = Dict{fpMPolyRingElem, Int}(mono[i] => i for i in 1:len_mon) |
| 80 | + TB_edge_index = Dict{fpMPolyRingElem, Int}(mono[i] => i + len_mon for i in 1:len_mon) |
| 81 | + |
| 82 | + Fone = S.F(1) |
| 83 | + row = 1 |
| 84 | + X_stabs = zero_matrix(S.F, len_mon, n) |
| 85 | + Z_stabs = zero_matrix(S.F, len_mon, n) |
| 86 | + for edge in mono |
| 87 | + f_shift = simplify(ϕ(edge * f_R2)) |
| 88 | + for term in terms(f_shift.f) |
| 89 | + # X_12 |
| 90 | + X_stabs[row, TB_edge_index[term]] = Fone |
| 91 | + end |
| 92 | + g_shift = simplify(ϕ(edge * g_R2)) |
| 93 | + for term in terms(g_shift.f) |
| 94 | + # X_14 |
| 95 | + X_stabs[row, LR_edge_index[term]] = Fone |
| 96 | + end |
| 97 | + |
| 98 | + g_shift = simplify(ϕ(edge * g_anti_R2)) |
| 99 | + for term in terms(g_shift.f) |
| 100 | + # Z_12 |
| 101 | + Z_stabs[row, TB_edge_index[term]] = Fone |
| 102 | + end |
| 103 | + f_shift = simplify(ϕ(edge * f_anti_R2)) |
| 104 | + for term in terms(f_shift.f) |
| 105 | + # Z_14 |
| 106 | + Z_stabs[row, LR_edge_index[term]] = Fone |
| 107 | + end |
| 108 | + row += 1 |
| 109 | + end |
| 110 | + # println("X stabs") |
| 111 | + # display(X_stabs) |
| 112 | + # println("Z stabs") |
| 113 | + # display(Z_stabs) |
| 114 | + |
| 115 | + return CSSCode(X_stabs, Z_stabs) |
| 116 | +end |
| 117 | + |
| 118 | +function show(io::IO, S::AbstractGeneralizedToricCode) |
| 119 | + if isa(S, FiniteGeneralizedToricCode) |
| 120 | + println(io, "Finite Generalized Toric Code:") |
| 121 | + println(io, "\tf: $(S.f)") |
| 122 | + println(io, "\tg: $(S.g)") |
| 123 | + println(io, "\ta1: $(S.a1)") |
| 124 | + println(io, "\ta2: $(S.a2)") |
| 125 | + else |
| 126 | + println(io, "Generalized Toric Code:") |
| 127 | + println(io, "\tf: $(S.f)") |
| 128 | + println(io, "\tg: $(S.g)") |
| 129 | + end |
| 130 | +end |
0 commit comments