def parity_check_matrix(self): r""" Return a parity check matrix of ``self``. The construction of the parity check matrix in case ``self`` is not a binary code is not really well documented. Regarding the choice of projective geometry, one might check: - the note over section 2.3 in [Rot2006]_, pages 47-48 - the dedicated paragraph in [HP2003]_, page 30 EXAMPLES:: sage: C = codes.HammingCode(GF(3), 3) sage: C.parity_check_matrix() [1 0 1 1 0 1 0 1 1 1 0 1 1] [0 1 1 2 0 0 1 1 2 0 1 1 2] [0 0 0 0 1 1 1 1 1 2 2 2 2] """ n = self.length() F = self.base_field() m = n - self.dimension() MS = MatrixSpace(F, n, m) X = ProjectiveSpace(m - 1, F) PFn = [list(p) for p in X.point_set(F).points()] H = MS(PFn).transpose() H = H[::-1, :] H.set_immutable() return H
def HammingCode(r,F): r""" Implements the Hamming codes. The `r^{th}` Hamming code over `F=GF(q)` is an `[n,k,d]` code with length `n=(q^r-1)/(q-1)`, dimension `k=(q^r-1)/(q-1) - r` and minimum distance `d=3`. The parity check matrix of a Hamming code has rows consisting of all nonzero vectors of length r in its columns, modulo a scalar factor so no parallel columns arise. A Hamming code is a single error-correcting code. INPUT: - ``r`` - an integer 2 - ``F`` - a finite field. OUTPUT: Returns the r-th q-ary Hamming code. EXAMPLES:: sage: codes.HammingCode(3,GF(2)) Linear code of length 7, dimension 4 over Finite Field of size 2 sage: C = codes.HammingCode(3,GF(3)); C Linear code of length 13, dimension 10 over Finite Field of size 3 sage: C.minimum_distance() 3 sage: C.minimum_distance(algorithm='gap') # long time, check d=3 3 sage: C = codes.HammingCode(3,GF(4,'a')); C Linear code of length 21, dimension 18 over Finite Field in a of size 2^2 While the ``codes`` object now gathers all code constructors, ``HammingCode`` is still available in the global namespace:: sage: HammingCode(3,GF(2)) doctest:...: DeprecationWarning: This method soon will not be available in that way anymore. To use it, you can now call it by typing codes.HammingCode See http://trac.sagemath.org/15445 for details. Linear code of length 7, dimension 4 over Finite Field of size 2 """ q = F.order() n = (q**r-1)/(q-1) k = n-r MS = MatrixSpace(F,n,r) X = ProjectiveSpace(r-1,F) PFn = [list(p) for p in X.point_set(F).points(F)] H = MS(PFn).transpose() Cd = LinearCode(H) # Hamming code always has distance 3, so we provide the distance. return LinearCode(Cd.dual_code().gen_mat(), d=3)
def HammingCode(r,F): r""" Implements the Hamming codes. The `r^{th}` Hamming code over `F=GF(q)` is an `[n,k,d]` code with length `n=(q^r-1)/(q-1)`, dimension `k=(q^r-1)/(q-1) - r` and minimum distance `d=3`. The parity check matrix of a Hamming code has rows consisting of all nonzero vectors of length r in its columns, modulo a scalar factor so no parallel columns arise. A Hamming code is a single error-correcting code. INPUT: - ``r`` - an integer 2 - ``F`` - a finite field. OUTPUT: Returns the r-th q-ary Hamming code. EXAMPLES:: sage: codes.HammingCode(3,GF(2)) Linear code of length 7, dimension 4 over Finite Field of size 2 sage: C = codes.HammingCode(3,GF(3)); C Linear code of length 13, dimension 10 over Finite Field of size 3 sage: C.minimum_distance() 3 sage: C.minimum_distance(algorithm='gap') # long time, check d=3 3 sage: C = codes.HammingCode(3,GF(4,'a')); C Linear code of length 21, dimension 18 over Finite Field in a of size 2^2 While the ``codes`` object now gathers all code constructors, ``HammingCode`` is still available in the global namespace:: sage: HammingCode(3,GF(2)) doctest:1: DeprecationWarning: This method soon will not be available in that way anymore. To use it, you can now call it by typing codes.HammingCode See http://trac.sagemath.org/15445 for details. Linear code of length 7, dimension 4 over Finite Field of size 2 """ q = F.order() n = (q**r-1)/(q-1) k = n-r MS = MatrixSpace(F,n,r) X = ProjectiveSpace(r-1,F) PFn = [list(p) for p in X.point_set(F).points(F)] H = MS(PFn).transpose() Cd = LinearCode(H) # Hamming code always has distance 3, so we provide the distance. return LinearCode(Cd.dual_code().gen_mat(), d=3)
def HammingCode(r,F): r""" Implements the Hamming codes. The `r^{th}` Hamming code over `F=GF(q)` is an `[n,k,d]` code with length `n=(q^r-1)/(q-1)`, dimension `k=(q^r-1)/(q-1) - r` and minimum distance `d=3`. The parity check matrix of a Hamming code has rows consisting of all nonzero vectors of length r in its columns, modulo a scalar factor so no parallel columns arise. A Hamming code is a single error-correcting code. INPUT: - ``r`` - an integer 2 - ``F`` - a finite field. OUTPUT: Returns the r-th q-ary Hamming code. EXAMPLES:: sage: codes.HammingCode(3,GF(2)) Linear code of length 7, dimension 4 over Finite Field of size 2 sage: C = codes.HammingCode(3,GF(3)); C Linear code of length 13, dimension 10 over Finite Field of size 3 sage: C.minimum_distance() 3 sage: C.minimum_distance(algorithm='gap') # long time, check d=3 3 sage: C = codes.HammingCode(3,GF(4,'a')); C Linear code of length 21, dimension 18 over Finite Field in a of size 2^2 """ q = F.order() n = (q**r-1)/(q-1) k = n-r MS = MatrixSpace(F,n,r) X = ProjectiveSpace(r-1,F) PFn = [list(p) for p in X.point_set(F).points(F)] H = MS(PFn).transpose() Cd = LinearCode(H) # Hamming code always has distance 3, so we provide the distance. return LinearCode(Cd.dual_code().generator_matrix(), d=3)
def HammingCode(r, F): r""" Implements the Hamming codes. The `r^{th}` Hamming code over `F=GF(q)` is an `[n,k,d]` code with length `n=(q^r-1)/(q-1)`, dimension `k=(q^r-1)/(q-1) - r` and minimum distance `d=3`. The parity check matrix of a Hamming code has rows consisting of all nonzero vectors of length r in its columns, modulo a scalar factor so no parallel columns arise. A Hamming code is a single error-correcting code. INPUT: - ``r`` - an integer 2 - ``F`` - a finite field. OUTPUT: Returns the r-th q-ary Hamming code. EXAMPLES:: sage: codes.HammingCode(3,GF(2)) Linear code of length 7, dimension 4 over Finite Field of size 2 sage: C = codes.HammingCode(3,GF(3)); C Linear code of length 13, dimension 10 over Finite Field of size 3 sage: C.minimum_distance() 3 sage: C.minimum_distance(algorithm='gap') # long time, check d=3 3 sage: C = codes.HammingCode(3,GF(4,'a')); C Linear code of length 21, dimension 18 over Finite Field in a of size 2^2 """ q = F.order() n = (q**r - 1) / (q - 1) k = n - r MS = MatrixSpace(F, n, r) X = ProjectiveSpace(r - 1, F) PFn = [list(p) for p in X.point_set(F).points(F)] H = MS(PFn).transpose() Cd = LinearCode(H) # Hamming code always has distance 3, so we provide the distance. return LinearCode(Cd.dual_code().generator_matrix(), d=3)