Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 6bcc1e7

Browse files
author
David Lucas
committed
Class for cyclic and two encoders for this class
1 parent f3ca628 commit 6bcc1e7

File tree

5 files changed

+1264
-111
lines changed

5 files changed

+1264
-111
lines changed

src/doc/en/reference/coding/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Linear codes and related constructions
2525
:maxdepth: 1
2626

2727
sage/coding/binary_code
28+
sage/coding/cyclic_code
2829
sage/coding/grs
2930
sage/coding/hamming_code
3031
sage/coding/linear_code

src/sage/coding/code_constructions.py

+8-110
Original file line numberDiff line numberDiff line change
@@ -585,124 +585,22 @@ def BinaryGolayCode():
585585
V = span(B, F)
586586
return LinearCodeFromVectorSpace(V, d=7)
587587

588-
589588
def CyclicCodeFromGeneratingPolynomial(n,g,ignore=True):
590-
r"""
591-
If g is a polynomial over GF(q) which divides `x^n-1` then
592-
this constructs the code "generated by g" (ie, the code associated
593-
with the principle ideal `gR` in the ring
594-
`R = GF(q)[x]/(x^n-1)` in the usual way).
595-
596-
The option "ignore" says to ignore the condition that (a) the
597-
characteristic of the base field does not divide the length (the
598-
usual assumption in the theory of cyclic codes), and (b) `g`
599-
must divide `x^n-1`. If ignore=True, instead of returning
600-
an error, a code generated by `gcd(x^n-1,g)` is created.
601-
602-
EXAMPLES::
603-
604-
sage: P.<x> = PolynomialRing(GF(3),"x")
605-
sage: g = x-1
606-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(4,g); C
607-
Linear code of length 4, dimension 3 over Finite Field of size 3
608-
sage: P.<x> = PolynomialRing(GF(4,"a"),"x")
609-
sage: g = x^3+1
610-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(9,g); C
611-
Linear code of length 9, dimension 6 over Finite Field in a of size 2^2
612-
sage: P.<x> = PolynomialRing(GF(2),"x")
613-
sage: g = x^3+x+1
614-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(7,g); C
615-
Linear code of length 7, dimension 4 over Finite Field of size 2
616-
sage: C.generator_matrix()
617-
[1 1 0 1 0 0 0]
618-
[0 1 1 0 1 0 0]
619-
[0 0 1 1 0 1 0]
620-
[0 0 0 1 1 0 1]
621-
sage: g = x+1
622-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(4,g); C
623-
Linear code of length 4, dimension 3 over Finite Field of size 2
624-
sage: C.generator_matrix()
625-
[1 1 0 0]
626-
[0 1 1 0]
627-
[0 0 1 1]
628-
629-
On the other hand, CyclicCodeFromPolynomial(4,x) will produce a
630-
ValueError including a traceback error message: "`x` must
631-
divide `x^4 - 1`". You will also get a ValueError if you
632-
type
633-
634-
::
635-
636-
sage: P.<x> = PolynomialRing(GF(4,"a"),"x")
637-
sage: g = x^2+1
638-
639-
followed by CyclicCodeFromGeneratingPolynomial(6,g). You will also
640-
get a ValueError if you type
641-
642-
::
643-
644-
sage: P.<x> = PolynomialRing(GF(3),"x")
645-
sage: g = x^2-1
646-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(5,g); C
647-
Linear code of length 5, dimension 4 over Finite Field of size 3
648-
649-
followed by C = CyclicCodeFromGeneratingPolynomial(5,g,False), with
650-
a traceback message including "`x^2 + 2` must divide
651-
`x^5 - 1`".
652-
"""
653-
P = g.parent()
654-
x = P.gen()
589+
from sage.misc.superseded import deprecation
590+
from sage.coding.cyclic_code import CyclicCode
591+
deprecation(20100, "codes.CyclicCodeFromGeneratingPolynomial is now deprecated. Please use codes.CyclicCode instead.")
655592
F = g.base_ring()
656-
p = F.characteristic()
657-
if not(ignore) and p.divides(n):
658-
raise ValueError('The characteristic %s must not divide %s'%(p,n))
659-
if not(ignore) and not(g.divides(x**n-1)):
660-
raise ValueError('%s must divide x^%s - 1'%(g,n))
661-
gn = GCD([g,x**n-1])
662-
d = gn.degree()
663-
coeffs = Sequence(gn.list())
664-
r1 = Sequence(coeffs+[0]*(n - d - 1))
665-
Sn = SymmetricGroup(n)
666-
s = Sn.gens()[0] # assumes 1st gen of S_n is (1,2,...,n)
667-
rows = [permutation_action(s**(-i),r1) for i in range(n-d)]
668-
MS = MatrixSpace(F,n-d,n)
669-
return LinearCode(MS(rows))
670-
671-
CyclicCode = CyclicCodeFromGeneratingPolynomial
593+
return CyclicCode(length = n, generator_pol = g, field = F)
672594

673595
def CyclicCodeFromCheckPolynomial(n,h,ignore=True):
674-
r"""
675-
If h is a polynomial over GF(q) which divides `x^n-1` then
676-
this constructs the code "generated by `g = (x^n-1)/h`"
677-
(ie, the code associated with the principle ideal `gR` in
678-
the ring `R = GF(q)[x]/(x^n-1)` in the usual way). The
679-
option "ignore" says to ignore the condition that the
680-
characteristic of the base field does not divide the length (the
681-
usual assumption in the theory of cyclic codes).
682-
683-
EXAMPLES::
684-
685-
sage: P.<x> = PolynomialRing(GF(3),"x")
686-
sage: C = codes.CyclicCodeFromCheckPolynomial(4,x + 1); C
687-
Linear code of length 4, dimension 1 over Finite Field of size 3
688-
sage: C = codes.CyclicCodeFromCheckPolynomial(4,x^3 + x^2 + x + 1); C
689-
Linear code of length 4, dimension 3 over Finite Field of size 3
690-
sage: C.generator_matrix()
691-
[2 1 0 0]
692-
[0 2 1 0]
693-
[0 0 2 1]
694-
"""
596+
from sage.misc.superseded import deprecation
597+
from sage.coding.cyclic_code import CyclicCode
598+
deprecation(20100, "codes.CyclicCodeFromCheckPolynomial is now deprecated. Please use codes.CyclicCode instead.")
695599
P = h.parent()
696600
x = P.gen()
697-
d = h.degree()
698601
F = h.base_ring()
699-
p = F.characteristic()
700-
if not(ignore) and p.divides(n):
701-
raise ValueError('The characteristic %s must not divide %s'%(p,n))
702-
if not(h.divides(x**n-1)):
703-
raise ValueError('%s must divide x^%s - 1'%(h,n))
704602
g = P((x**n-1)/h)
705-
return CyclicCodeFromGeneratingPolynomial(n,g)
603+
return CyclicCode(length = n, generator_pol = g, field = F)
706604

707605
def DuadicCodeEvenPair(F,S1,S2):
708606
r"""

src/sage/coding/codes_catalog.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# in the global namespace.
2020

2121
from code_constructions import (BCHCode, BinaryGolayCode, CyclicCodeFromGeneratingPolynomial,
22-
CyclicCode, CyclicCodeFromCheckPolynomial, DuadicCodeEvenPair,
22+
CyclicCodeFromCheckPolynomial, DuadicCodeEvenPair,
2323
DuadicCodeOddPair, ExtendedBinaryGolayCode,
2424
ExtendedQuadraticResidueCode, ExtendedTernaryGolayCode,
2525
LinearCode, LinearCodeFromCheckMatrix,
@@ -33,6 +33,7 @@
3333

3434
from guava import BinaryReedMullerCode, QuasiQuadraticResidueCode, RandomLinearCodeGuava
3535
from hamming_code import HammingCode
36+
from cyclic_code import CyclicCode
3637

3738
import decoders_catalog as decoders
3839
import encoders_catalog as encoders

0 commit comments

Comments
 (0)