def QuadraticResidueCodeOddPair(n, F): """ Quadratic residue codes of a given odd prime length and base ring either don't exist at all or occur as 4-tuples - a pair of "odd-like" codes and a pair of "even-like" codes. If n 2 is prime then (Theorem 6.6.2 in [HP]_) a QR code exists over GF(q) iff q is a quadratic residue mod n. They are constructed as "odd-like" duadic codes associated the splitting (Q,N) mod n, where Q is the set of non-zero quadratic residues and N is the non-residues. EXAMPLES:: sage: QuadraticResidueCodeOddPair(17,GF(13)) (Linear code of length 17, dimension 9 over Finite Field of size 13, Linear code of length 17, dimension 9 over Finite Field of size 13) sage: QuadraticResidueCodeOddPair(17,GF(2)) (Linear code of length 17, dimension 9 over Finite Field of size 2, Linear code of length 17, dimension 9 over Finite Field of size 2) sage: QuadraticResidueCodeOddPair(13,GF(9,"z")) (Linear code of length 13, dimension 7 over Finite Field in z of size 3^2, Linear code of length 13, dimension 7 over Finite Field in z of size 3^2) sage: C1 = QuadraticResidueCodeOddPair(17,GF(2))[1] sage: C1x = C1.extended_code() sage: C2 = QuadraticResidueCodeOddPair(17,GF(2))[0] sage: C2x = C2.extended_code() sage: C2x.spectrum(); C1x.spectrum() [1, 0, 0, 0, 0, 0, 102, 0, 153, 0, 153, 0, 102, 0, 0, 0, 0, 0, 1] [1, 0, 0, 0, 0, 0, 102, 0, 153, 0, 153, 0, 102, 0, 0, 0, 0, 0, 1] sage: C2x == C1x.dual_code() True sage: C3 = QuadraticResidueCodeOddPair(7,GF(2))[0] sage: C3x = C3.extended_code() sage: C3x.spectrum() [1, 0, 0, 0, 14, 0, 0, 0, 1] sage: C3x.is_self_dual() True This is consistent with Theorem 6.6.14 in [HP]_. """ from sage.coding.code_constructions import is_a_splitting q = F.order() Q = quadratic_residues(n) Q.remove(0) # non-zero quad residues N = range(1, n) tmp = [N.remove(x) for x in Q] # non-zero quad non-residues if n.is_prime() and n > 2 and not (q in Q): raise ValueError, "No quadratic residue code exists for these parameters." if not (is_a_splitting(Q, N, n)): raise TypeError, "No quadratic residue code exists for these parameters." return DuadicCodeOddPair(F, Q, N)
def QuadraticResidueCodeOddPair(n, F): """ Quadratic residue codes of a given odd prime length and base ring either don't exist at all or occur as 4-tuples - a pair of "odd-like" codes and a pair of "even-like" codes. If n 2 is prime then (Theorem 6.6.2 in [HP]_) a QR code exists over GF(q) iff q is a quadratic residue mod n. They are constructed as "odd-like" duadic codes associated the splitting (Q,N) mod n, where Q is the set of non-zero quadratic residues and N is the non-residues. EXAMPLES:: sage: QuadraticResidueCodeOddPair(17,GF(13)) (Linear code of length 17, dimension 9 over Finite Field of size 13, Linear code of length 17, dimension 9 over Finite Field of size 13) sage: QuadraticResidueCodeOddPair(17,GF(2)) (Linear code of length 17, dimension 9 over Finite Field of size 2, Linear code of length 17, dimension 9 over Finite Field of size 2) sage: QuadraticResidueCodeOddPair(13,GF(9,"z")) (Linear code of length 13, dimension 7 over Finite Field in z of size 3^2, Linear code of length 13, dimension 7 over Finite Field in z of size 3^2) sage: C1 = QuadraticResidueCodeOddPair(17,GF(2))[1] sage: C1x = C1.extended_code() sage: C2 = QuadraticResidueCodeOddPair(17,GF(2))[0] sage: C2x = C2.extended_code() sage: C2x.spectrum(); C1x.spectrum() [1, 0, 0, 0, 0, 0, 102, 0, 153, 0, 153, 0, 102, 0, 0, 0, 0, 0, 1] [1, 0, 0, 0, 0, 0, 102, 0, 153, 0, 153, 0, 102, 0, 0, 0, 0, 0, 1] sage: C2x == C1x.dual_code() True sage: C3 = QuadraticResidueCodeOddPair(7,GF(2))[0] sage: C3x = C3.extended_code() sage: C3x.spectrum() [1, 0, 0, 0, 14, 0, 0, 0, 1] sage: C3x.is_self_dual() True This is consistent with Theorem 6.6.14 in [HP]_. """ from sage.coding.code_constructions import is_a_splitting q = F.order() Q = quadratic_residues(n) Q.remove(0) # non-zero quad residues N = range(1, n) tmp = [N.remove(x) for x in Q] # non-zero quad non-residues if (n.is_prime() and n > 2 and not (q in Q)): raise ValueError, "No quadratic residue code exists for these parameters." if not (is_a_splitting(Q, N, n)): raise TypeError, "No quadratic residue code exists for these parameters." return DuadicCodeOddPair(F, Q, N)
def QuadraticResidueCodeEvenPair(n, F): """ Quadratic residue codes of a given odd prime length and base ring either don't exist at all or occur as 4-tuples - a pair of "odd-like" codes and a pair of "even-like" codes. If n 2 is prime then (Theorem 6.6.2 in [HP]_) a QR code exists over GF(q) iff q is a quadratic residue mod n. They are constructed as "even-like" duadic codes associated the splitting (Q,N) mod n, where Q is the set of non-zero quadratic residues and N is the non-residues. EXAMPLES:: sage: codes.QuadraticResidueCodeEvenPair(17,GF(13)) (Linear code of length 17, dimension 8 over Finite Field of size 13, Linear code of length 17, dimension 8 over Finite Field of size 13) sage: codes.QuadraticResidueCodeEvenPair(17,GF(2)) (Linear code of length 17, dimension 8 over Finite Field of size 2, Linear code of length 17, dimension 8 over Finite Field of size 2) sage: codes.QuadraticResidueCodeEvenPair(13,GF(9,"z")) (Linear code of length 13, dimension 6 over Finite Field in z of size 3^2, Linear code of length 13, dimension 6 over Finite Field in z of size 3^2) sage: C1 = codes.QuadraticResidueCodeEvenPair(7,GF(2))[0] sage: C1.is_self_orthogonal() True sage: C2 = codes.QuadraticResidueCodeEvenPair(7,GF(2))[1] sage: C2.is_self_orthogonal() True sage: C3 = codes.QuadraticResidueCodeOddPair(17,GF(2))[0] sage: C4 = codes.QuadraticResidueCodeEvenPair(17,GF(2))[1] sage: C3 == C4.dual_code() True This is consistent with Theorem 6.6.9 and Exercise 365 in [HP]_. """ q = F.order() Q = quadratic_residues(n) Q.remove(0) # non-zero quad residues N = range(1, n) tmp = [N.remove(x) for x in Q] # non-zero quad non-residues if n.is_prime() and n > 2 and not (q in Q): raise ValueError, "No quadratic residue code exists for these parameters." if not (is_a_splitting(Q, N, n)): raise TypeError, "No quadratic residue code exists for these parameters." return DuadicCodeEvenPair(F, Q, N)
def QuadraticResidueCodeEvenPair(n,F): """ Quadratic residue codes of a given odd prime length and base ring either don't exist at all or occur as 4-tuples - a pair of "odd-like" codes and a pair of "even-like" codes. If n 2 is prime then (Theorem 6.6.2 in [HP]_) a QR code exists over GF(q) iff q is a quadratic residue mod n. They are constructed as "even-like" duadic codes associated the splitting (Q,N) mod n, where Q is the set of non-zero quadratic residues and N is the non-residues. EXAMPLES:: sage: codes.QuadraticResidueCodeEvenPair(17,GF(13)) (Linear code of length 17, dimension 8 over Finite Field of size 13, Linear code of length 17, dimension 8 over Finite Field of size 13) sage: codes.QuadraticResidueCodeEvenPair(17,GF(2)) (Linear code of length 17, dimension 8 over Finite Field of size 2, Linear code of length 17, dimension 8 over Finite Field of size 2) sage: codes.QuadraticResidueCodeEvenPair(13,GF(9,"z")) (Linear code of length 13, dimension 6 over Finite Field in z of size 3^2, Linear code of length 13, dimension 6 over Finite Field in z of size 3^2) sage: C1 = codes.QuadraticResidueCodeEvenPair(7,GF(2))[0] sage: C1.is_self_orthogonal() True sage: C2 = codes.QuadraticResidueCodeEvenPair(7,GF(2))[1] sage: C2.is_self_orthogonal() True sage: C3 = codes.QuadraticResidueCodeOddPair(17,GF(2))[0] sage: C4 = codes.QuadraticResidueCodeEvenPair(17,GF(2))[1] sage: C3 == C4.dual_code() True This is consistent with Theorem 6.6.9 and Exercise 365 in [HP]_. """ q = F.order() Q = quadratic_residues(n); Q.remove(0) # non-zero quad residues N = range(1,n); tmp = [N.remove(x) for x in Q] # non-zero quad non-residues if (n.is_prime() and n>2 and not(q in Q)): raise ValueError, "No quadratic residue code exists for these parameters." if not(is_a_splitting(Q,N,n)): raise TypeError, "No quadratic residue code exists for these parameters." return DuadicCodeEvenPair(F,Q,N)
def QuadraticResidueCodeOddPair(n,F): """ Quadratic residue codes of a given odd prime length and base ring either don't exist at all or occur as 4-tuples - a pair of "odd-like" codes and a pair of "even-like" codes. If n 2 is prime then (Theorem 6.6.2 in [HP]_) a QR code exists over GF(q) iff q is a quadratic residue mod n. They are constructed as "odd-like" duadic codes associated the splitting (Q,N) mod n, where Q is the set of non-zero quadratic residues and N is the non-residues. EXAMPLES:: sage: codes.QuadraticResidueCodeOddPair(17,GF(13)) (Linear code of length 17, dimension 9 over Finite Field of size 13, Linear code of length 17, dimension 9 over Finite Field of size 13) sage: codes.QuadraticResidueCodeOddPair(17,GF(2)) (Linear code of length 17, dimension 9 over Finite Field of size 2, Linear code of length 17, dimension 9 over Finite Field of size 2) sage: codes.QuadraticResidueCodeOddPair(13,GF(9,"z")) (Linear code of length 13, dimension 7 over Finite Field in z of size 3^2, Linear code of length 13, dimension 7 over Finite Field in z of size 3^2) sage: C1 = codes.QuadraticResidueCodeOddPair(17,GF(2))[1] sage: C1x = C1.extended_code() sage: C2 = codes.QuadraticResidueCodeOddPair(17,GF(2))[0] sage: C2x = C2.extended_code() sage: C2x.spectrum(); C1x.spectrum() [1, 0, 0, 0, 0, 0, 102, 0, 153, 0, 153, 0, 102, 0, 0, 0, 0, 0, 1] [1, 0, 0, 0, 0, 0, 102, 0, 153, 0, 153, 0, 102, 0, 0, 0, 0, 0, 1] sage: C2x == C1x.dual_code() True sage: C3 = codes.QuadraticResidueCodeOddPair(7,GF(2))[0] sage: C3x = C3.extended_code() sage: C3x.spectrum() [1, 0, 0, 0, 14, 0, 0, 0, 1] sage: C3x.is_self_dual() True This is consistent with Theorem 6.6.14 in [HP]_. TESTS:: sage: codes.QuadraticResidueCodeOddPair(9,GF(2)) Traceback (most recent call last): ... ValueError: the argument n must be an odd prime """ from sage.misc.misc import srange from sage.categories.finite_fields import FiniteFields if F not in FiniteFields(): raise ValueError("the argument F must be a finite field") q = F.order() n = Integer(n) if n <= 2 or not n.is_prime(): raise ValueError("the argument n must be an odd prime") Q = quadratic_residues(n); Q.remove(0) # non-zero quad residues N = [x for x in srange(1,n) if x not in Q] # non-zero quad non-residues if q not in Q: raise ValueError("the order of the finite field must be a quadratic residue modulo n") return DuadicCodeOddPair(F,Q,N)
def QuadraticResidueCodeOddPair(n, F): """ Quadratic residue codes of a given odd prime length and base ring either don't exist at all or occur as 4-tuples - a pair of "odd-like" codes and a pair of "even-like" codes. If n 2 is prime then (Theorem 6.6.2 in [HP]_) a QR code exists over GF(q) iff q is a quadratic residue mod n. They are constructed as "odd-like" duadic codes associated the splitting (Q,N) mod n, where Q is the set of non-zero quadratic residues and N is the non-residues. EXAMPLES:: sage: codes.QuadraticResidueCodeOddPair(17,GF(13)) (Linear code of length 17, dimension 9 over Finite Field of size 13, Linear code of length 17, dimension 9 over Finite Field of size 13) sage: codes.QuadraticResidueCodeOddPair(17,GF(2)) (Linear code of length 17, dimension 9 over Finite Field of size 2, Linear code of length 17, dimension 9 over Finite Field of size 2) sage: codes.QuadraticResidueCodeOddPair(13,GF(9,"z")) (Linear code of length 13, dimension 7 over Finite Field in z of size 3^2, Linear code of length 13, dimension 7 over Finite Field in z of size 3^2) sage: C1 = codes.QuadraticResidueCodeOddPair(17,GF(2))[1] sage: C1x = C1.extended_code() sage: C2 = codes.QuadraticResidueCodeOddPair(17,GF(2))[0] sage: C2x = C2.extended_code() sage: C2x.spectrum(); C1x.spectrum() [1, 0, 0, 0, 0, 0, 102, 0, 153, 0, 153, 0, 102, 0, 0, 0, 0, 0, 1] [1, 0, 0, 0, 0, 0, 102, 0, 153, 0, 153, 0, 102, 0, 0, 0, 0, 0, 1] sage: C2x == C1x.dual_code() True sage: C3 = codes.QuadraticResidueCodeOddPair(7,GF(2))[0] sage: C3x = C3.extended_code() sage: C3x.spectrum() [1, 0, 0, 0, 14, 0, 0, 0, 1] sage: C3x.is_self_dual() True This is consistent with Theorem 6.6.14 in [HP]_. TESTS:: sage: codes.QuadraticResidueCodeOddPair(9,GF(2)) Traceback (most recent call last): ... ValueError: the argument n must be an odd prime """ from sage.misc.misc import srange from sage.categories.finite_fields import FiniteFields if F not in FiniteFields(): raise ValueError("the argument F must be a finite field") q = F.order() n = Integer(n) if n <= 2 or not n.is_prime(): raise ValueError("the argument n must be an odd prime") Q = quadratic_residues(n) Q.remove(0) # non-zero quad residues N = [x for x in srange(1, n) if x not in Q] # non-zero quad non-residues if q not in Q: raise ValueError( "the order of the finite field must be a quadratic residue modulo n" ) return DuadicCodeOddPair(F, Q, N)