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""" Cyclic Code
Let `F` be a field. A `[n, k]` code `C` over `F` is called cyclic if every cyclic shift of a codeword is also a codeword [R06]_:
.. MATH::
\forall c \in C, c = (c_{0}, c_{1}, \dots , c_{n-1}) \in C \Rightarrow (c_{n-1}, c_{0}, \dots , c_{n-2}) \in C
Let `c = (c_0, c_1, \dots, c_{n-1})` be a codeword of `C`. This codeword can be seen as a polynomial over `F_q[x]` as follows: `\Sigma_{i=0}^{n-1} c_i x^i`. There is a unique monic polynomial `g(x)` such that for every `c(x) \in F_q[x]` of degree less than `n-1`, we have `c(x) \in C \Leftrightarrow g(x) | c(x)`. This polynomial is called the generator polynomial of `C`.
For now, only single-root cyclic codes (i.e. whose length `n` and field order `q` are coprimes) are implemented.
REFERENCES:
.. [R06] Ron Roth, Introduction to Coding Theory, Cambridge University Press, 2006
TESTS:
This class uses the following experimental feature: :class:`sage.coding.relative_finite_field_extension.RelativeFiniteFieldExtension`. This test block is here only to trigger the experimental warning so it does not interferes with doctests::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: RelativeFiniteFieldExtension(Fqm, Fq) doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. See http://trac.sagemath.org/20284 for details. Relative field extension between Finite Field in aa of size 2^4 and Finite Field in a of size 2^2 """
# ***************************************************************************** # Copyright (C) 2015 David Lucas <david.lucas@inria.fr> # 2016 Julien Lavauzelle <julien.lavauzelle@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/ # *****************************************************************************
LinearCodeSyndromeDecoder, LinearCodeNearestNeighborDecoder)
r""" Returns a possible generator polynomial for ``code``.
If the code is cyclic, the generator polynomial is the gcd of all the polynomial forms of the codewords. Conversely, if this gcd exactly generates the code ``code``, then ``code`` is cyclic.
If ``check`` is set to ``True``, then it also checks that the code is indeed cyclic. Otherwise it doesn't.
INPUT:
- ``code`` -- a linear code
- ``check`` -- whether the cyclicity should be checked
OUTPUT:
- the generator polynomial of ``code`` (if the code is cyclic).
EXAMPLES::
sage: from sage.coding.cyclic_code import find_generator_polynomial sage: C = codes.GeneralizedReedSolomonCode(GF(8, 'a').list()[1:], 4) sage: find_generator_polynomial(C) x^3 + (a^2 + 1)*x^2 + a*x + a^2 + 1 """
raise ValueError("The code is not cyclic.")
r""" Returns the vector of length exactly ``length`` corresponding to the coefficients of the provided polynomial. If needed, zeros are added.
INPUT:
- ``poly`` -- a polynomial
- ``length`` -- an integer
OUTPUT:
- the list of coefficients
EXAMPLES::
sage: R = PolynomialRing(GF(2), 'X') sage: X = R.gen() sage: poly = X**4 + X + 1 sage: sage.coding.cyclic_code._to_complete_list(poly, 7) [1, 1, 0, 0, 1, 0, 0] """
r""" Returns the BCH bound obtained for a cyclic code of length ``n`` and defining set ``D``.
Consider a cyclic code `C`, with defining set `D`, length `n`, and minimum distance `d`. We have the following bound, called BCH bound, on `d`: `d \geq \delta + 1`, where `\delta` is the length of the longest arithmetic sequence (modulo `n`) of elements in `D`.
That is, if `\exists c, \gcd(c,n) = 1` such that `\{l, l+c, \dots, l + (\delta - 1) \times c\} \subseteq D`, then `d \geq \delta + 1` [1]
The BCH bound is often known in the particular case `c = 1`. The user can specify by setting ``arithmetic = False``.
.. NOTE::
As this is a specific use case of the BCH bound, it is *not* available in the global namespace. Call it by using ``sage.coding.cyclic_code.bch_bound``. You can also load it into the global namespace by typing ``from sage.coding.cyclic_code import bch_bound``.
INPUT:
- ``n`` -- an integer
- ``D`` -- a list of integers
- ``arithmetic`` -- (default: ``False``), if it is set to ``True``, then it computes the BCH bound using the longest arithmetic sequence definition
OUTPUT:
- ``(delta + 1, (l, c))`` -- such that ``delta + 1`` is the BCH bound, and ``l, c`` are the parameters of the longest arithmetic sequence (see below)
EXAMPLES::
sage: n = 15 sage: D = [14,1,2,11,12] sage: sage.coding.cyclic_code.bch_bound(n, D) (3, (1, 1))
sage: n = 15 sage: D = [14,1,2,11,12] sage: sage.coding.cyclic_code.bch_bound(n, D, True) (4, (2, 12)) """
except IndexError: raise ValueError("%s must contains integers between 0 and %s" % (D, n - 1)) return (n + 1, (1, 0))
else: for step in range(1, n // 2 + 1) if gcd(step, n) == 1]
r""" Representation of a cyclic code.
We propose three different ways to create a new CyclicCode, either by providing:
- the generator polynomial and the length (1) - an existing linear code. In that case, a generator polynomial will be computed from the provided linear code's parameters (2) - (a subset of) the defining set of the cyclic code (3)
For now, only single-root cyclic codes are implemented. That is, only cyclic codes such that its length `n` and field order `q` are coprimes.
Depending on which behaviour you want, you need to specify the names of the arguments to CyclicCode. See EXAMPLES section below for details.
INPUT:
- ``generator_pol`` -- (default: ``None``) the generator polynomial of ``self``. That is, the highest-degree monic polynomial which divides every polynomial representation of a codeword in ``self``.
- ``length`` -- (default: ``None``) the length of ``self``. It has to be bigger than the degree of ``generator_pol``.
- ``code`` -- (default: ``None``) a linear code.
- ``check`` -- (default: ``False``) a boolean representing whether the cyclicity of ``self`` must be checked while finding the generator polynomial. See :meth:`find_generator_polynomial` for details.
- ``D`` -- (default: ``None``) a list of integers between ``0`` and ``length-1``, corresponding to (a subset of) the defining set of the code. Will be modified if it is not cyclotomic-closed.
- ``field`` -- (default: ``None``) the base field of ``self``.
- ``primitive_root`` -- (default: ``None``) the primitive root of the splitting field which contains the roots of the generator polynomial. It has to be of multiplicative order ``length`` over this field. If the splitting field is not ``field``, it also have to be a polynomial in ``zx``, where ``x`` is the degree of the extension over the prime field. For instance, over ``GF(16)``, it must be a polynomial in ``z4``.
EXAMPLES:
We can construct a CyclicCode object using three different methods. First (1), we provide a generator polynomial and a code length::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: C [7, 4] Cyclic Code over GF(2)
We can also provide a code (2). In that case, the program will try to extract a generator polynomial (see :meth:`find_generator_polynomial` for details)::
sage: C = codes.GeneralizedReedSolomonCode(GF(8, 'a').list()[1:], 4) sage: Cc = codes.CyclicCode(code = C) sage: Cc [7, 4] Cyclic Code over GF(8)
Finally, we can give (a subset of) a defining set for the code (3). In this case, the generator polynomial will be computed::
sage: F = GF(16, 'a') sage: n = 15 sage: Cc = codes.CyclicCode(length = n, field = F, D = [1,2]) sage: Cc [15, 13] Cyclic Code over GF(16) """
D=None, field=None, primitive_root=None): r""" TESTS:
If one provides a generator polynomial and a length, we check that the length is bigger than the degree of the polynomial::
sage: F.<x> = GF(2)[] sage: n = 2 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) Traceback (most recent call last): ... ValueError: Only cyclic codes whose length and field order are coprimes are implemented.
We also check that the polynomial is defined over a finite field::
sage: F.<x> = RR[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol=g, length=n) Traceback (most recent call last): ... ValueError: The generator polynomial must be defined over a finite field.
And we check that the generator polynomial divides `x^{n} - 1`, where `n` is provided length::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 2 + x + 1 sage: C = codes.CyclicCode(generator_pol=g, length=n) Traceback (most recent call last): ... ValueError: Provided polynomial must divide x^n - 1, where n is the provided length.
In the case of a code is passed as argument, if it's not possible to extract a generator polynomial, an exception is raised::
sage: G = matrix(GF(2), [[1, 1, 1], [0, 1, 1]]) sage: C = codes.LinearCode(G) sage: Cc = codes.CyclicCode(code=C) Traceback (most recent call last): ... ValueError: The code is not cyclic.
If the `primitive_root` does not lie in an extension of `field`, or is not a primitive `n`-th root of unity, then an exception is raised::
sage: F = GF(2) sage: n = 15 sage: Dset = [1, 2, 4, 8] sage: alpha = GF(3).one() sage: Cc = codes.CyclicCode(D=Dset, field=F, length=n, primitive_root=alpha) Traceback (most recent call last): ... ValueError: primitive_root must belong to an extension of the base field sage: alpha = GF(16).one() sage: Cc = codes.CyclicCode(D=Dset, field=F, length=n, primitive_root=alpha) Traceback (most recent call last): ... ValueError: primitive_root must be a primitive n-th root of unity sage: alpha = GF(32).gen() sage: Cc = codes.CyclicCode(D=Dset, field=F, length=n, primitive_root=alpha) Traceback (most recent call last): ... ValueError: primitive_root must be a primitive n-th root of unity """ # Case (1) : generator polynomial and length are provided. code is None and D is None and field is None and primitive_root is None): "over a finite field.") "order are coprimes are implemented.") "where n is the provided length.") self._generator_polynomial = generator_pol.monic() else:
# Case (2) : a code is provided. generator_pol is None and length is None and D is None and field is None and primitive_root is None): raise ValueError("code must be an AbstractLinearCode") raise ValueError("Only cyclic codes whose length and field " "order are coprimes are implemented.") "Vector", "Syndrome")
# Case (3) : a defining set, a length and a field are provided generator_pol is None and code is None): raise ValueError("You must provide a finite field.") raise ValueError("Only cyclic codes whose length and field " "order are coprimes are implemented.")
"extension of the base field") primitive_root.multiplicative_order() != n): "n-th root of unity") else: embedding=F_to_Fsplit)
# we set class variables
else: raise AttributeError("You must provide either a code, or a list " "of powers and the length and the field, or " "a generator polynomial and the code length")
r""" Returns ``True`` if ``word`` belongs to ``self``, ``False`` otherwise.
INPUT:
- ``word`` -- the word to test
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol=g, length=n) sage: c = vector(GF(2), (1, 1, 1, 0, 0, 1, 0)) sage: c in C True """
r""" Tests equality between CyclicCode objects.
INPUT:
- ``other`` -- the code to test
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C1 = codes.CyclicCode(generator_pol=g, length=n) sage: C2 = codes.CyclicCode(generator_pol=g, length=n) sage: C1 == C2 True """ return False else: self.length() == other.length() and self.generator_polynomial() == R(other.generator_polynomial()))
r""" Returns a string representation of ``self``.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol=g, length=n) sage: C [7, 4] Cyclic Code over GF(2) """ % (self.length(), self.dimension(), self.base_field().cardinality()))
r""" Returns a latex representation of ``self``.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol=g, length=n) sage: latex(C) [7, 4] \textnormal{ Cyclic Code over } \Bold{F}_{2} """ % (self.length(), self.dimension(), self.base_field()._latex_()))
r""" Returns the generator polynomial of ``self``.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol=g, length=n) sage: C.generator_polynomial() x^3 + x + 1 """
r""" Returns the base field embedding into the splitting field.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol=g, length=n) sage: C.field_embedding() Relative field extension between Finite Field in z3 of size 2^3 and Finite Field of size 2 """
r""" Returns the set of exponents of the roots of ``self``'s generator polynomial over the extension field. Of course, it depends on the choice of the primitive root of the splitting field.
INPUT:
- ``primitive_root`` (optional) -- a primitive root of the extension field
EXAMPLES:
We provide a defining set at construction time::
sage: F = GF(16, 'a') sage: n = 15 sage: C = codes.CyclicCode(length=n, field=F, D=[1,2]) sage: C.defining_set() [1, 2]
If the defining set was provided by the user, it might have been expanded at construction time. In this case, the expanded defining set will be returned::
sage: C = codes.CyclicCode(length=13, field=F, D=[1, 2]) sage: C.defining_set() [1, 2, 3, 5, 6, 9]
If a generator polynomial was passed at construction time, the defining set is computed using this polynomial::
sage: R.<x> = F[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol=g, length=n) sage: C.defining_set() [1, 2, 4]
Both operations give the same result::
sage: C1 = codes.CyclicCode(length=n, field=F, D=[1, 2, 4]) sage: C1.generator_polynomial() == g True
Another one, in a reversed order::
sage: n = 13 sage: C1 = codes.CyclicCode(length=n, field=F, D=[1, 2]) sage: g = C1.generator_polynomial() sage: C2 = codes.CyclicCode(generator_pol=g, length=n) sage: C1.defining_set() == C2.defining_set() True """ (primitive_root is None or primitive_root == self._primitive_root)): else:
embedding=F_to_Fsplit) else: try: alpha = primitive_root Fsplit = alpha.parent() FE = RelativeFiniteFieldExtension(Fsplit, F) F_to_Fsplit = FE.embedding() except ValueError: raise ValueError("primitive_root does not belong to the " "right splitting field") if alpha.multiplicative_order() != n: raise ValueError("primitive_root must have multiplicative " "order equal to the code length")
r""" Returns the primitive root of the splitting field that is used to build the defining set of the code.
If it has not been specified by the user, it is set by default with the output of the ``zeta`` method of the splitting field.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol=g, length=n) sage: C.primitive_root() z3
sage: F = GF(16, 'a') sage: n = 15 sage: a = F.gen() sage: Cc = codes.CyclicCode(length = n, field = F, D = [1,2], primitive_root = a^2 + 1) sage: Cc.primitive_root() a^2 + 1 """ else:
def check_polynomial(self): r""" Returns the check polynomial of ``self``.
Let `C` be a cyclic code of length `n` and `g` its generator polynomial. The following: `h = \frac{x^n - 1}{g(x)}` is called `C`'s check polynomial.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: h = C.check_polynomial() sage: h == (x**n - 1)/C.generator_polynomial() True """
def parity_check_matrix(self): r""" Returns 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`.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: C.parity_check_matrix() [1 0 1 1 1 0 0] [0 1 0 1 1 1 0] [0 0 1 0 1 1 1] """
r""" Returns the BCH bound of ``self`` which is a bound on ``self`` minimum distance.
See :meth:`sage.coding.cyclic_code.bch_bound` for details.
INPUT:
- ``arithmetic`` -- (default: ``False``), if it is set to ``True``, then it computes the BCH bound using the longest arithmetic sequence definition
OUTPUT:
- ``(delta + 1, (l, c))`` -- such that ``delta + 1`` is the BCH bound, and ``l, c`` are the parameters of the largest arithmetic sequence
EXAMPLES::
sage: F = GF(16, 'a') sage: n = 15 sage: D = [14,1,2,11,12] sage: C = codes.CyclicCode(field = F, length = n, D = D) sage: C.bch_bound() (3, (1, 1))
sage: F = GF(16, 'a') sage: n = 15 sage: D = [14,1,2,11,12] sage: C = codes.CyclicCode(field = F, length = n, D = D) sage: C.bch_bound(True) (4, (2, 12)) """
r""" Returns the surrounding BCH code of ``self``.
EXAMPLES::
sage: C = codes.CyclicCode(field=GF(2), length=63, D=[1, 7, 17]) sage: C.dimension() 45 sage: CC = C.surrounding_bch_code() sage: CC [63, 51] BCH Code over GF(2) with designed distance 3 sage: all(r in CC for r in C.generator_matrix()) True """ offset=params[1], jump_size=params[0])
r""" An encoder encoding polynomials into codewords.
Let `C` be a cyclic code over some finite field `F`, and let `g` be its generator polynomial.
This encoder encodes any polynomial `p \in F[x]_{<k}` by computing `c = p \times g` and returning the vector of its coefficients.
INPUT:
- ``code`` -- The associated code of this encoder
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodePolynomialEncoder(C) sage: E Polynomial-style encoder for [7, 4] Cyclic Code over GF(2) """
r""" EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodePolynomialEncoder(C) sage: E Polynomial-style encoder for [7, 4] Cyclic Code over GF(2) """ raise ValueError("code has to be a CyclicCode")
r""" Tests equality between CyclicCodePolynomialEncoder objects.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E1 = codes.encoders.CyclicCodePolynomialEncoder(C) sage: E2 = codes.encoders.CyclicCodePolynomialEncoder(C) sage: E1 == E2 True """ self.code() == other.code())
r""" Returns a string representation of ``self``.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodePolynomialEncoder(C) sage: E Polynomial-style encoder for [7, 4] Cyclic Code over GF(2) """
r""" Returns a latex representation of ``self``.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodePolynomialEncoder(C) sage: latex(E) \textnormal{Polynomial-style encoder for }[7, 4] \textnormal{ Cyclic Code over } \Bold{F}_{2} """ self.code()._latex_())
r""" Transforms ``p`` into an element of the associated code of ``self``.
INPUT:
- ``p`` -- A polynomial from ``self`` message space
OUTPUT:
- A codeword in associated code of ``self``
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodePolynomialEncoder(C) sage: m = x ** 2 + 1 sage: E.encode(m) (1, 1, 1, 0, 0, 1, 0) """ raise ValueError("Degree of the message must be at most %s" % k - 1)
r""" Returns the message corresponding to ``c``. Does not check if ``c`` belongs to the code.
INPUT:
- ``c`` -- A vector with the same length as the code
OUTPUT:
- An element of the message space
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodePolynomialEncoder(C) sage: c = vector(GF(2), (1, 1, 1, 0, 0, 1, 0)) sage: E.unencode_nocheck(c) x^2 + 1 """
r""" Returns the message space of ``self``
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodePolynomialEncoder(C) sage: E.message_space() Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) """
r""" An encoder which can encode vectors into codewords.
Let `C` be a cyclic code over some finite field `F`, and let `g` be its generator polynomial.
Let `m = (m_1, m_2, \dots, m_k)` be a vector in `F^{k}`. This codeword can be seen as a polynomial over `F[x]`, as follows: `P_m = \Sigma_{i=0}^{k-1} m_i \times x^i`.
To encode `m`, this encoder does the following multiplication: `P_m \times g`.
INPUT:
- ``code`` -- The associated code of this encoder
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodeVectorEncoder(C) sage: E Vector-style encoder for [7, 4] Cyclic Code over GF(2) """
r"""
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodeVectorEncoder(C) sage: E Vector-style encoder for [7, 4] Cyclic Code over GF(2) """ raise ValueError("code has to be a CyclicCode")
r""" Tests equality between CyclicCodeVectorEncoder objects.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E1 = codes.encoders.CyclicCodeVectorEncoder(C) sage: E2 = codes.encoders.CyclicCodeVectorEncoder(C) sage: E1 == E2 True """ self.code() == other.code())
r""" Returns a string representation of ``self``.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodeVectorEncoder(C) sage: E Vector-style encoder for [7, 4] Cyclic Code over GF(2) """
r""" Returns a latex representation of ``self``.
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodeVectorEncoder(C) sage: latex(E) \textnormal{Vector-style encoder for }[7, 4] \textnormal{ Cyclic Code over } \Bold{F}_{2} """ self.code()._latex_())
r""" Transforms ``m`` into an element of the associated code of ``self``.
INPUT:
- ``m`` -- an element from ``self``'s message space
OUTPUT:
- A codeword in the associated code of ``self``
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodeVectorEncoder(C) sage: m = vector(GF(2), (1, 0, 1, 0)) sage: E.encode(m) (1, 1, 1, 0, 0, 1, 0) """ return super(CyclicCodeVectorEncoder, self).encode(m)
raise ValueError("Degree of the message must be at most %s" % k - 1)
r""" Returns the message corresponding to ``c``. Does not check if ``c`` belongs to the code.
INPUT:
- ``c`` -- A vector with the same length as the code
OUTPUT:
- An element of the message space
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodeVectorEncoder(C) sage: c = vector(GF(2), (1, 1, 1, 0, 0, 1, 0)) sage: E.unencode_nocheck(c) (1, 0, 1, 0) """
def generator_matrix(self): r""" Returns a generator matrix of ``self``
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodeVectorEncoder(C) sage: E.generator_matrix() [1 1 0 1 0 0 0] [0 1 1 0 1 0 0] [0 0 1 1 0 1 0] [0 0 0 1 1 0 1] """
r""" Returns the message space of ``self``
EXAMPLES::
sage: F.<x> = GF(2)[] sage: n = 7 sage: g = x ** 3 + x + 1 sage: C = codes.CyclicCode(generator_pol = g, length = n) sage: E = codes.encoders.CyclicCodeVectorEncoder(C) sage: E.message_space() Vector space of dimension 4 over Finite Field of size 2 """
r""" A decoder which decodes through the surrounding BCH code of the cyclic code.
INPUT:
- ``code`` -- The associated code of this decoder.
- ``**kwargs`` -- All extra arguments are forwarded to the BCH decoder
EXAMPLES::
sage: C = codes.CyclicCode(field=GF(16), length=15, D=[14, 1, 2, 11, 12]) sage: D = codes.decoders.CyclicCodeSurroundingBCHDecoder(C) sage: D Decoder through the surrounding BCH code of the [15, 10] Cyclic Code over GF(16) """ r"""
EXAMPLES::
sage: C = codes.CyclicCode(field=GF(16), length=15, D=[14, 1, 2, 11, 12]) sage: D = codes.decoders.CyclicCodeSurroundingBCHDecoder(C) sage: D Decoder through the surrounding BCH code of the [15, 10] Cyclic Code over GF(16) """ code, code.ambient_space(), "Vector")
r""" Tests equality between CyclicCodeSurroundingBCHDecoder objects.
EXAMPLES::
sage: C = codes.CyclicCode(field=GF(16), length=15, D=[14, 1, 2, 11, 12]) sage: D1 = C.decoder() sage: D2 = C.decoder() sage: D1 == D2 True """ self.code() == other.code() and self.bch_decoder() == other.bch_decoder())
r""" Returns a string representation of ``self``.
EXAMPLES::
sage: C = codes.CyclicCode(field=GF(16), length=15, D=[14, 1, 2, 11, 12]) sage: D = codes.decoders.CyclicCodeSurroundingBCHDecoder(C) sage: D Decoder through the surrounding BCH code of the [15, 10] Cyclic Code over GF(16) """ self.code())
r""" Returns a latex representation of ``self``.
EXAMPLES::
sage: C = codes.CyclicCode(field=GF(16), length=15, D=[14, 1, 2, 11, 12]) sage: D = codes.decoders.CyclicCodeSurroundingBCHDecoder(C) sage: latex(D) \textnormal{Decoder through the surrounding BCH code of the }[15, 10] \textnormal{ Cyclic Code over } \Bold{F}_{2^{4}} """ "the }%s" % self.code()._latex_())
r""" Returns the surrounding BCH code of :meth:`sage.coding.encoder.Encoder.code`.
EXAMPLES::
sage: C = codes.CyclicCode(field=GF(16), length=15, D=[14, 1, 2, 11, 12]) sage: D = codes.decoders.CyclicCodeSurroundingBCHDecoder(C) sage: D.bch_code() [15, 12] BCH Code over GF(16) with designed distance 4 """
r""" Returns the decoder that will be used over the surrounding BCH code.
EXAMPLES::
sage: C = codes.CyclicCode(field=GF(16), length=15, D=[14, 1, 2, 11, 12]) sage: D = codes.decoders.CyclicCodeSurroundingBCHDecoder(C) sage: D.bch_decoder() Decoder through the underlying GRS code of [15, 12] BCH Code over GF(16) with designed distance 4 """
r""" Decodes ``r`` to an element in :meth:`sage.coding.encoder.Encoder.code`.
EXAMPLES::
sage: F = GF(16, 'a') sage: C = codes.CyclicCode(field=F, length=15, D=[14, 1, 2, 11, 12]) sage: a = F.gen() sage: D = codes.decoders.CyclicCodeSurroundingBCHDecoder(C) sage: y = vector(F, [0, a^3, a^3 + a^2 + a, 1, a^2 + 1, a^3 + a^2 + 1, a^3 + a^2 + a, a^3 + a^2 + a, a^2 + a, a^2 + 1, a^2 + a + 1, a^3 + 1, a^2, a^3 + a, a^3 + a]) sage: D.decode_to_code(y) in C True """
r""" Returns maximal number of errors that ``self`` can decode.
EXAMPLES::
sage: C = codes.CyclicCode(field=GF(16), length=15, D=[14, 1, 2, 11, 12]) sage: D = codes.decoders.CyclicCodeSurroundingBCHDecoder(C) sage: D.decoding_radius() 1 """
####################### registration ###############################
|