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""" Extended code
Let `C` be a linear code of length `n` over `\mathbb{F}_{q}`. The extended code of `C` is the code
.. MATH::
\hat{C} = \{x_{1}x_{2}\dots x_{n+1} \in \mathbb{F}_{q}^{n+1} \,\vert\, x_{1}x_{2}\dots x_{n} \in C \text{ with } x_{1} + x_{2} + \dots + x_{n+1} = 0 \}.
See [HP2003]_ (pp 15-16) for details. """
#***************************************************************************** # Copyright (C) 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,\ LinearCodeSyndromeDecoder,\ LinearCodeNearestNeighborDecoder)
r""" Representation of an extended code.
INPUT:
- ``C`` -- A linear code
EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 11, 5) sage: Ce = codes.ExtendedCode(C) sage: Ce Extension of [11, 5] linear code over GF(7) """
r""" TESTS:
``C`` must be a linear code::
sage: C = VectorSpace(GF(7), 11) sage: codes.ExtendedCode(C) Traceback (most recent call last): ... ValueError: Provided code must be a linear code """
r""" Tests equality between two extended codes.
EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 11, 5) sage: C1 = codes.ExtendedCode(C) sage: C2 = codes.ExtendedCode(C) sage: C1 == C2 True """ and self.original_code() == other.original_code()
r""" Returns a string representation of ``self``.
EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 11, 5) sage: Ce = codes.ExtendedCode(C) sage: Ce Extension of [11, 5] linear code over GF(7) """
r""" Returns a latex representation of ``self``.
EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 11, 5) sage: Ce = codes.ExtendedCode(C) sage: latex(Ce) \textnormal{Extension of [11, 5] linear code over GF(7)} """
r""" Returns the code which was extended to get ``self``.
EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 11, 5) sage: Ce = codes.ExtendedCode(C) sage: Ce.original_code() [11, 5] linear code over GF(7) """
def parity_check_matrix(self): r""" Returns a parity check matrix of ``self``.
This matrix is computed directly from :func:`original_code`.
EXAMPLES::
sage: C = LinearCode(matrix(GF(2),[[1,0,0,1,1],\ [0,1,0,1,0],\ [0,0,1,1,1]])) sage: C.parity_check_matrix() [1 0 1 0 1] [0 1 0 1 1] sage: Ce = codes.ExtendedCode(C) sage: Ce.parity_check_matrix() [1 1 1 1 1 1] [1 0 1 0 1 0] [0 1 0 1 1 0] """
r""" Returns a random element of ``self``.
This random element is computed directly from the original code, and does not compute a generator matrix of ``self`` in the process.
EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 9, 5) sage: Ce = codes.ExtendedCode(C) sage: c = Ce.random_element() #random sage: c in Ce True """
r""" Encoder using original code's generator matrix to compute the extended code's one.
INPUT:
- ``code`` -- The associated code of ``self``. """
r""" EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 11, 5) sage: Ce = codes.ExtendedCode(C) sage: E = codes.encoders.ExtendedCodeExtendedMatrixEncoder(Ce) sage: E Matrix-based Encoder for Extension of [11, 5] linear code over GF(7) """ raise TypeError("code has to be an instance of ExtendedCode class")
r""" Returns a string representation of ``self``.
EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 11, 5) sage: Ce = codes.ExtendedCode(C) sage: E = codes.encoders.ExtendedCodeExtendedMatrixEncoder(Ce) sage: E Matrix-based Encoder for Extension of [11, 5] linear code over GF(7) """
r""" Returns a latex representation of ``self``.
EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 11, 5) sage: Ce = codes.ExtendedCode(C) sage: E = codes.encoders.ExtendedCodeExtendedMatrixEncoder(Ce) sage: latex(E) \textnormal{Matrix-based Encoder for }\textnormal{Extension of [11, 5] linear code over GF(7)} """
r""" Tests equality between GRSEvaluationVectorEncoder objects.
EXAMPLES::
sage: C = codes.random_linear_code(GF(7), 11, 5) sage: Ce = codes.ExtendedCode(C) sage: D1 = codes.encoders.ExtendedCodeExtendedMatrixEncoder(Ce) sage: D2 = codes.encoders.ExtendedCodeExtendedMatrixEncoder(Ce) sage: D1.__eq__(D2) True sage: D1 is D2 False """ and self.code() == other.code()
def generator_matrix(self): r""" Returns a generator matrix of the associated code of ``self``.
EXAMPLES::
sage: C = LinearCode(matrix(GF(2),[[1,0,0,1,1],\ [0,1,0,1,0],\ [0,0,1,1,1]])) sage: Ce = codes.ExtendedCode(C) sage: E = codes.encoders.ExtendedCodeExtendedMatrixEncoder(Ce) sage: E.generator_matrix() [1 0 0 1 1 1] [0 1 0 1 0 0] [0 0 1 1 1 1] """
r""" Decoder which decodes through a decoder over the original code.
INPUT:
- ``code`` -- The associated code of this decoder
- ``original_decoder`` -- (default: ``None``) the decoder that will be used over the original code. It has to be a decoder object over the original code. If ``original_decoder`` is set to ``None``, it will use the default decoder of the original code.
- ``**kwargs`` -- all extra arguments are forwarded to original code's decoder
EXAMPLES::
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'a').list()[:15], 7) sage: Ce = codes.ExtendedCode(C) sage: D = codes.decoders.ExtendedCodeOriginalCodeDecoder(Ce) sage: D Decoder of Extension of [15, 7, 9] Reed-Solomon Code over GF(16) through Gao decoder for [15, 7, 9] Reed-Solomon Code over GF(16) """
r""" TESTS:
If one tries to use a decoder whose code is not the original code, it returns an error::
sage: C1 = codes.GeneralizedReedSolomonCode(GF(16, 'a').list()[:15], 7) sage: Ce = codes.ExtendedCode(C1) sage: C2 = codes.GeneralizedReedSolomonCode(GF(13).list()[:12], 7) sage: Dc2 = C2.decoder() sage: D = codes.decoders.ExtendedCodeOriginalCodeDecoder(Ce, original_decoder = Dc2) Traceback (most recent call last): ... ValueError: Original decoder must have the original code as associated code """ raise TypeError("code has to be an instance of ExtendedCode class")
else: self._original_decoder.connected_encoder())
r""" Returns a string representation of ``self``.
EXAMPLES::
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'a').list()[:15], 7) sage: Ce = codes.ExtendedCode(C) sage: D = codes.decoders.ExtendedCodeOriginalCodeDecoder(Ce) sage: D Decoder of Extension of [15, 7, 9] Reed-Solomon Code over GF(16) through Gao decoder for [15, 7, 9] Reed-Solomon Code over GF(16) """
r""" Returns a latex representation of ``self``.
EXAMPLES::
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'a').list()[:15], 7) sage: Ce = codes.ExtendedCode(C) sage: D = codes.decoders.ExtendedCodeOriginalCodeDecoder(Ce) sage: latex(D) \textnormal{Decoder of } Extension of [15, 7, 9] Reed-Solomon Code over GF(16) \textnormal{ through } Gao decoder for [15, 7, 9] Reed-Solomon Code over GF(16) """
r""" Returns the decoder over the original code that will be used to decode words of :meth:`sage.coding.decoder.Decoder.code`.
EXAMPLES::
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'a').list()[:15], 7) sage: Ce = codes.ExtendedCode(C) sage: D = codes.decoders.ExtendedCodeOriginalCodeDecoder(Ce) sage: D.original_decoder() Gao decoder for [15, 7, 9] Reed-Solomon Code over GF(16) """
r""" Decodes ``y`` to an element in :meth:`sage.coding.decoder.Decoder.code`.
EXAMPLES::
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'a').list()[:15], 7) sage: Ce = codes.ExtendedCode(C) sage: D = codes.decoders.ExtendedCodeOriginalCodeDecoder(Ce) sage: c = Ce.random_element() sage: Chan = channels.StaticErrorRateChannel(Ce.ambient_space(), D.decoding_radius()) sage: y = Chan(c) sage: y in Ce False sage: D.decode_to_code(y) == c True
Another example, with a list decoder::
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'a').list()[:15], 7) sage: Ce = codes.ExtendedCode(C) sage: Dgrs = C.decoder('GuruswamiSudan', tau = 4) sage: D = codes.decoders.ExtendedCodeOriginalCodeDecoder(Ce, original_decoder = Dgrs) sage: c = Ce.random_element() sage: Chan = channels.StaticErrorRateChannel(Ce.ambient_space(), D.decoding_radius()) sage: y = Chan(c) sage: y in Ce False sage: c in D.decode_to_code(y) True """ else:
r""" Returns maximal number of errors that ``self`` can decode.
INPUT:
- ``*args``, ``**kwargs`` -- arguments and optional arguments are forwarded to original decoder's ``decoding_radius`` method.
EXAMPLES::
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'a').list()[:15], 7) sage: Ce = codes.ExtendedCode(C) sage: D = codes.decoders.ExtendedCodeOriginalCodeDecoder(Ce) sage: D.decoding_radius() 4 """
####################### registration ###############################
|