Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
r""" Golay code
Golay codes are a set of four specific codes (binary Golay code, extended binary Golay code, ternary Golay and extended ternary Golay code), known to have some very interesting properties: for example, binary and ternary Golay codes are perfect codes, while their extended versions are self-dual codes.
REFERENCES:
- [HP2003]_ pp. 31-33 for a definition of Golay codes.
.. [WS] \F. J. MacWilliams, N. J. A. Sloane, *The Theory of Error-Correcting Codes*, North-Holland, Amsterdam, 1977
- :wikipedia:`Golay_code` """
#***************************************************************************** # Copyright (C) 2016 Arpit Merchant <arpitdm@gmail.com> # 2016 David Lucas <david.lucas@inria.fr> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #*****************************************************************************
LinearCodeGeneratorMatrixEncoder)
r""" Representation of a Golay Code.
INPUT:
- ``base_field`` -- The base field over which the code is defined. Can only be ``GF(2)`` or ``GF(3)``.
- ``extended`` -- (default: ``True``) if set to ``True``, creates an extended Golay code.
EXAMPLES::
sage: codes.GolayCode(GF(2)) [24, 12, 8] Extended Golay code over GF(2)
Another example with the perfect binary Golay code::
sage: codes.GolayCode(GF(2), False) [23, 12, 7] Golay code over GF(2)
TESTS:
sage: G = codes.GolayCode(GF(2),False) sage: G0 = codes.GolayCode(GF(2),True) sage: G0prime = G.extended_code() sage: G0.generator_matrix() * G0prime.parity_check_matrix().transpose() == 0 True
sage: G0perp = G0.dual_code() sage: G0.generator_matrix() * G0perp.generator_matrix().transpose() == 0 True
sage: G = codes.GolayCode(GF(3),False) sage: G0 = codes.GolayCode(GF(3),True) sage: G0prime = G.extended_code() sage: G0.generator_matrix() * G0prime.parity_check_matrix().transpose() == 0 True
sage: G0perp = G0.dual_code() sage: G0.generator_matrix() * G0perp.generator_matrix().transpose() == 0 True """
r""" TESTS:
If ``base_field`` is not ``GF(2)`` or ``GF(3)``, an error is raised::
sage: C = codes.GolayCode(ZZ, true) Traceback (most recent call last): ... ValueError: finite_field must be either GF(2) or GF(3) """ raise ValueError("extension must be either True or False")
else:
r""" Test equality between Golay Code objects.
EXAMPLES::
sage: C1 = codes.GolayCode(GF(2)) sage: C2 = codes.GolayCode(GF(2)) sage: C1.__eq__(C2) True """ and self.base_field() == other.base_field() \ and self.length() == other.length() \
r""" Return a string representation of ``self``.
EXAMPLES::
sage: codes.GolayCode(GF(2),extended=True) [24, 12, 8] Extended Golay code over GF(2) """ % (n, self.dimension(), self.minimum_distance(), ext, self.base_field().cardinality())
r""" Return a latex representation of ``self``.
EXAMPLES::
sage: C = codes.GolayCode(GF(2)) sage: latex(C) [24, 12, 8] \textnormal{ Extended Golay Code over } \Bold{F}_{2} """ % (n, self.dimension(), self.minimum_distance(), ext, self.base_field()._latex_())
r""" Return the dual code of ``self``.
If ``self`` is an extended Golay code, ``self`` is returned. Otherwise, it returns the output of :meth:`sage.coding.linear_code.AbstractLinearCode.dual_code`
EXAMPLES::
sage: C = codes.GolayCode(GF(2), extended=True) sage: Cd = C.dual_code(); Cd [24, 12, 8] Extended Golay code over GF(2)
sage: Cd == C True """
r""" Return the minimum distance of ``self``.
The minimum distance of Golay codes is already known, and is thus returned immediately without computing anything.
EXAMPLES::
sage: C = codes.GolayCode(GF(2)) sage: C.minimum_distance() 8 """ elif n == 11: return 5
r""" Return the covering radius of ``self``.
The covering radius of a linear code `C` is the smallest integer `r` s.t. any element of the ambient space of `C` is at most at distance `r` to `C`.
The covering radii of all Golay codes are known, and are thus returned by this method without performing any computation
EXAMPLES::
sage: C = codes.GolayCode(GF(2)) sage: C.covering_radius() 4 sage: C = codes.GolayCode(GF(2),False) sage: C.covering_radius() 3 sage: C = codes.GolayCode(GF(3)) sage: C.covering_radius() 3 sage: C = codes.GolayCode(GF(3),False) sage: C.covering_radius() 2 """
r""" Return the list whose `i`'th entry is the number of words of weight `i` in ``self``.
The weight distribution of all Golay codes are known, and are thus returned by this method without performing any computation MWS (67, 69)
EXAMPLES::
sage: C = codes.GolayCode(GF(3)) sage: C.weight_distribution() [1, 0, 0, 0, 0, 0, 264, 0, 0, 440, 0, 0, 24]
TESTS::
sage: C = codes.GolayCode(GF(2)) sage: C.weight_distribution() == super(codes.GolayCode, C).weight_distribution() True
sage: C = codes.GolayCode(GF(2), extended=False) sage: C.weight_distribution() == super(codes.GolayCode, C).weight_distribution() True
sage: C = codes.GolayCode(GF(3)) sage: C.weight_distribution() == super(codes.GolayCode, C).weight_distribution() True
sage: C = codes.GolayCode(GF(3), extended=False) sage: C.weight_distribution() == super(codes.GolayCode, C).weight_distribution() True """ +[253]+[0]*6+[1])
r""" Return a generator matrix of ``self``
Generator matrices of all Golay codes are known, and are thus returned by this method without performing any computation
EXAMPLES::
sage: C = codes.GolayCode(GF(2), extended=True) sage: C.generator_matrix() [1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 0 0 0 1 1] [0 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 0 0 1 0] [0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0 1 0 1 1] [0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0] [0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1] [0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 1] [0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 1 1 1] [0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 1 0 1 1 1 1 0 0] [0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 1 0 1 1 1 1 0] [0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 0 0 0 1 1 0 1] [0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 0 0 0 1 1 1] """ [[1, 0,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 0, 1, 0, 2, 1, 2, 2, 0, 1], [0, 0, 0, 0, 0, 1, 0, 2, 1, 2, 2, 1]])
r""" Return the parity check matrix of ``self``.
The parity check matrix of a linear code `C` corresponds to the generator matrix of the dual code of `C`.
Parity check matrices of all Golay codes are known, and are thus returned by this method without performing any computation.
EXAMPLES::
sage: C = codes.GolayCode(GF(3), extended=False) sage: C.parity_check_matrix() [1 0 0 0 0 1 2 2 2 1 0] [0 1 0 0 0 0 1 2 2 2 1] [0 0 1 0 0 2 1 2 0 1 2] [0 0 0 1 0 1 1 0 1 1 1] [0 0 0 0 1 2 2 2 1 0 1] """ [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0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