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

Commit 2161696

Browse files
committed
Merged to latest beta (7.4.beta6).
2 parents c5dadf9 + 0f4fe27 commit 2161696

File tree

7 files changed

+1205
-151
lines changed

7 files changed

+1205
-151
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Linear codes and related constructions
2525
.. toctree::
2626
:maxdepth: 1
2727

28+
sage/coding/binary_code
29+
sage/coding/cyclic_code
2830
sage/coding/linear_code
2931
sage/coding/grs
3032
sage/coding/hamming_code

src/sage/coding/code_constructions.py

+48-146
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from sage.modules.free_module import span
5353
from sage.schemes.projective.projective_space import ProjectiveSpace
5454
from sage.structure.sequence import Sequence, Sequence_generic
55-
from sage.arith.all import GCD, LCM, divisors, quadratic_residues
55+
from sage.arith.all import GCD, LCM, divisors, quadratic_residues, gcd
5656
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
5757
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
5858
from sage.rings.integer import Integer
@@ -153,9 +153,9 @@ def _is_a_splitting(S1, S2, n, return_automorphism=False):
153153
sage: i2_sqrd = (i2^2).quo_rem(x^n-1)[1]
154154
sage: i2_sqrd == i2
155155
True
156-
sage: C1 = codes.CyclicCodeFromGeneratingPolynomial(n,i1)
157-
sage: C2 = codes.CyclicCodeFromGeneratingPolynomial(n,1-i2)
158-
sage: C1.dual_code() == C2
156+
sage: C1 = codes.CyclicCode(length = n, generator_pol = gcd(i1, x^n - 1))
157+
sage: C2 = codes.CyclicCode(length = n, generator_pol = gcd(1-i2, x^n - 1))
158+
sage: C1.dual_code().systematic_generator_matrix() == C2.systematic_generator_matrix()
159159
True
160160
161161
This is a special case of Theorem 6.4.3 in [HP]_.
@@ -414,22 +414,22 @@ def BCHCode(n,delta,F,b=0):
414414
sage: f = x^(8)-1
415415
sage: g.divides(f)
416416
True
417-
sage: C = codes.CyclicCode(8,g); C
418-
Linear code of length 8, dimension 4 over Finite Field of size 3
417+
sage: C = codes.CyclicCode(generator_pol = g, length = 8); C
418+
[8, 4] Cyclic Code over Finite Field of size 3 with x^4 + 2*x^3 + 2*x + 2 as generator polynomial
419419
sage: C.minimum_distance()
420420
4
421421
sage: C = codes.BCHCode(8,3,GF(3),1); C
422-
Linear code of length 8, dimension 4 over Finite Field of size 3
422+
[8, 4] Cyclic Code over Finite Field of size 3 with x^4 + 2*x^3 + 2*x + 2 as generator polynomial
423423
sage: C.minimum_distance()
424424
4
425425
sage: C = codes.BCHCode(8,3,GF(3)); C
426-
Linear code of length 8, dimension 5 over Finite Field of size 3
426+
[8, 5] Cyclic Code over Finite Field of size 3 with x^3 + x^2 + 1 as generator polynomial
427427
sage: C.minimum_distance()
428428
3
429429
sage: C = codes.BCHCode(26, 5, GF(5), b=1); C
430-
Linear code of length 26, dimension 10 over Finite Field of size 5
431-
430+
[26, 10] Cyclic Code over Finite Field of size 5 with x^16 + 4*x^15 + 4*x^14 + x^13 + 4*x^12 + 3*x^10 + 3*x^9 + x^8 + 3*x^7 + 3*x^6 + 4*x^4 + x^3 + 4*x^2 + 4*x + 1 as generator polynomial
432431
"""
432+
from sage.coding.cyclic_code import CyclicCode
433433
q = F.order()
434434
R = IntegerModRing(n)
435435
m = R(q).multiplicative_order()
@@ -446,7 +446,7 @@ def BCHCode(n,delta,F,b=0):
446446

447447
if not(g.divides(x**n-1)):
448448
raise ValueError("BCH codes does not exist with the given input.")
449-
return CyclicCodeFromGeneratingPolynomial(n,g)
449+
return CyclicCode(generator_pol = g, length = n)
450450

451451

452452
def BinaryGolayCode():
@@ -489,124 +489,22 @@ def BinaryGolayCode():
489489
V = span(B, F)
490490
return LinearCode(V, d=7)
491491

492-
493492
def CyclicCodeFromGeneratingPolynomial(n,g,ignore=True):
494-
r"""
495-
If g is a polynomial over GF(q) which divides `x^n-1` then
496-
this constructs the code "generated by g" (ie, the code associated
497-
with the principle ideal `gR` in the ring
498-
`R = GF(q)[x]/(x^n-1)` in the usual way).
499-
500-
The option "ignore" says to ignore the condition that (a) the
501-
characteristic of the base field does not divide the length (the
502-
usual assumption in the theory of cyclic codes), and (b) `g`
503-
must divide `x^n-1`. If ignore=True, instead of returning
504-
an error, a code generated by `gcd(x^n-1,g)` is created.
505-
506-
EXAMPLES::
507-
508-
sage: P.<x> = PolynomialRing(GF(3),"x")
509-
sage: g = x-1
510-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(4,g); C
511-
Linear code of length 4, dimension 3 over Finite Field of size 3
512-
sage: P.<x> = PolynomialRing(GF(4,"a"),"x")
513-
sage: g = x^3+1
514-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(9,g); C
515-
Linear code of length 9, dimension 6 over Finite Field in a of size 2^2
516-
sage: P.<x> = PolynomialRing(GF(2),"x")
517-
sage: g = x^3+x+1
518-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(7,g); C
519-
Linear code of length 7, dimension 4 over Finite Field of size 2
520-
sage: C.generator_matrix()
521-
[1 1 0 1 0 0 0]
522-
[0 1 1 0 1 0 0]
523-
[0 0 1 1 0 1 0]
524-
[0 0 0 1 1 0 1]
525-
sage: g = x+1
526-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(4,g); C
527-
Linear code of length 4, dimension 3 over Finite Field of size 2
528-
sage: C.generator_matrix()
529-
[1 1 0 0]
530-
[0 1 1 0]
531-
[0 0 1 1]
532-
533-
On the other hand, CyclicCodeFromPolynomial(4,x) will produce a
534-
ValueError including a traceback error message: "`x` must
535-
divide `x^4 - 1`". You will also get a ValueError if you
536-
type
537-
538-
::
539-
540-
sage: P.<x> = PolynomialRing(GF(4,"a"),"x")
541-
sage: g = x^2+1
542-
543-
followed by CyclicCodeFromGeneratingPolynomial(6,g). You will also
544-
get a ValueError if you type
545-
546-
::
547-
548-
sage: P.<x> = PolynomialRing(GF(3),"x")
549-
sage: g = x^2-1
550-
sage: C = codes.CyclicCodeFromGeneratingPolynomial(5,g); C
551-
Linear code of length 5, dimension 4 over Finite Field of size 3
552-
553-
followed by C = CyclicCodeFromGeneratingPolynomial(5,g,False), with
554-
a traceback message including "`x^2 + 2` must divide
555-
`x^5 - 1`".
556-
"""
557-
P = g.parent()
558-
x = P.gen()
493+
from sage.misc.superseded import deprecation
494+
from sage.coding.cyclic_code import CyclicCode
495+
deprecation(20100, "codes.CyclicCodeFromGeneratingPolynomial is now deprecated. Please use codes.CyclicCode instead.")
559496
F = g.base_ring()
560-
p = F.characteristic()
561-
if not(ignore) and p.divides(n):
562-
raise ValueError('The characteristic %s must not divide %s'%(p,n))
563-
if not(ignore) and not(g.divides(x**n-1)):
564-
raise ValueError('%s must divide x^%s - 1'%(g,n))
565-
gn = GCD([g,x**n-1])
566-
d = gn.degree()
567-
coeffs = Sequence(gn.list())
568-
r1 = Sequence(coeffs+[0]*(n - d - 1))
569-
Sn = SymmetricGroup(n)
570-
s = Sn.gens()[0] # assumes 1st gen of S_n is (1,2,...,n)
571-
rows = [permutation_action(s**(-i),r1) for i in range(n-d)]
572-
MS = MatrixSpace(F,n-d,n)
573-
return LinearCode(MS(rows))
574-
575-
CyclicCode = CyclicCodeFromGeneratingPolynomial
497+
return CyclicCode(length = n, generator_pol = g, field = F)
576498

577499
def CyclicCodeFromCheckPolynomial(n,h,ignore=True):
578-
r"""
579-
If h is a polynomial over GF(q) which divides `x^n-1` then
580-
this constructs the code "generated by `g = (x^n-1)/h`"
581-
(ie, the code associated with the principle ideal `gR` in
582-
the ring `R = GF(q)[x]/(x^n-1)` in the usual way). The
583-
option "ignore" says to ignore the condition that the
584-
characteristic of the base field does not divide the length (the
585-
usual assumption in the theory of cyclic codes).
586-
587-
EXAMPLES::
588-
589-
sage: P.<x> = PolynomialRing(GF(3),"x")
590-
sage: C = codes.CyclicCodeFromCheckPolynomial(4,x + 1); C
591-
Linear code of length 4, dimension 1 over Finite Field of size 3
592-
sage: C = codes.CyclicCodeFromCheckPolynomial(4,x^3 + x^2 + x + 1); C
593-
Linear code of length 4, dimension 3 over Finite Field of size 3
594-
sage: C.generator_matrix()
595-
[2 1 0 0]
596-
[0 2 1 0]
597-
[0 0 2 1]
598-
"""
500+
from sage.misc.superseded import deprecation
501+
from sage.coding.cyclic_code import CyclicCode
502+
deprecation(20100, "codes.CyclicCodeFromCheckPolynomial is now deprecated. Please use codes.CyclicCode instead.")
599503
P = h.parent()
600504
x = P.gen()
601-
d = h.degree()
602505
F = h.base_ring()
603-
p = F.characteristic()
604-
if not(ignore) and p.divides(n):
605-
raise ValueError('The characteristic %s must not divide %s'%(p,n))
606-
if not(h.divides(x**n-1)):
607-
raise ValueError('%s must divide x^%s - 1'%(h,n))
608506
g = P((x**n-1)/h)
609-
return CyclicCodeFromGeneratingPolynomial(n,g)
507+
return CyclicCode(length = n, generator_pol = g, field = F)
610508

611509
def DuadicCodeEvenPair(F,S1,S2):
612510
r"""
@@ -630,9 +528,10 @@ def DuadicCodeEvenPair(F,S1,S2):
630528
sage: _is_a_splitting(S1,S2,11)
631529
True
632530
sage: codes.DuadicCodeEvenPair(GF(q),S1,S2)
633-
(Linear code of length 11, dimension 5 over Finite Field of size 3,
634-
Linear code of length 11, dimension 5 over Finite Field of size 3)
531+
([11, 5] Cyclic Code over Finite Field of size 3 with x^6 + x^4 + 2*x^3 + 2*x^2 + 2*x + 1 as generator polynomial,
532+
[11, 5] Cyclic Code over Finite Field of size 3 with x^6 + 2*x^5 + 2*x^4 + 2*x^3 + x^2 + 1 as generator polynomial)
635533
"""
534+
from sage.coding.cyclic_code import CyclicCode
636535
n = len(S1) + len(S2) + 1
637536
if not _is_a_splitting(S1,S2,n):
638537
raise TypeError("%s, %s must be a splitting of %s."%(S1,S2,n))
@@ -649,8 +548,8 @@ def DuadicCodeEvenPair(F,S1,S2):
649548
x = P2.gen()
650549
gg1 = P2([_lift2smallest_field(c)[0] for c in g1.coefficients(sparse=False)])
651550
gg2 = P2([_lift2smallest_field(c)[0] for c in g2.coefficients(sparse=False)])
652-
C1 = CyclicCodeFromGeneratingPolynomial(n,gg1)
653-
C2 = CyclicCodeFromGeneratingPolynomial(n,gg2)
551+
C1 = CyclicCode(length = n, generator_pol = gg1)
552+
C2 = CyclicCode(length = n, generator_pol = gg2)
654553
return C1,C2
655554

656555
def DuadicCodeOddPair(F,S1,S2):
@@ -674,11 +573,12 @@ def DuadicCodeOddPair(F,S1,S2):
674573
sage: _is_a_splitting(S1,S2,11)
675574
True
676575
sage: codes.DuadicCodeOddPair(GF(q),S1,S2)
677-
(Linear code of length 11, dimension 6 over Finite Field of size 3,
678-
Linear code of length 11, dimension 6 over Finite Field of size 3)
576+
([11, 6] Cyclic Code over Finite Field of size 3 with x^5 + x^4 + 2*x^3 + x^2 + 2 as generator polynomial,
577+
[11, 6] Cyclic Code over Finite Field of size 3 with x^5 + 2*x^3 + x^2 + 2*x + 2 as generator polynomial)
679578
680579
This is consistent with Theorem 6.1.3 in [HP]_.
681580
"""
581+
from sage.coding.cyclic_code import CyclicCode
682582
n = len(S1) + len(S2) + 1
683583
if not _is_a_splitting(S1,S2,n):
684584
raise TypeError("%s, %s must be a splitting of %s."%(S1,S2,n))
@@ -698,8 +598,10 @@ def DuadicCodeOddPair(F,S1,S2):
698598
coeffs2 = [_lift2smallest_field(c)[0] for c in (g2+j).coefficients(sparse=False)]
699599
gg1 = P2(coeffs1)
700600
gg2 = P2(coeffs2)
701-
C1 = CyclicCodeFromGeneratingPolynomial(n,gg1)
702-
C2 = CyclicCodeFromGeneratingPolynomial(n,gg2)
601+
gg1 = gcd(gg1, x**n - 1)
602+
gg2 = gcd(gg2, x**n - 1)
603+
C1 = CyclicCode(length = n, generator_pol = gg1)
604+
C2 = CyclicCode(length = n, generator_pol = gg2)
703605
return C1,C2
704606

705607

@@ -763,12 +665,12 @@ def ExtendedQuadraticResidueCode(n,F):
763665
sage: C1 = codes.QuadraticResidueCode(7,GF(2))
764666
sage: C2 = C1.extended_code()
765667
sage: C3 = codes.ExtendedQuadraticResidueCode(7,GF(2)); C3
766-
Extended code coming from Linear code of length 7, dimension 4 over Finite Field of size 2
668+
Extended code coming from [7, 4] Cyclic Code over Finite Field of size 2 with x^3 + x + 1 as generator polynomial
767669
sage: C2 == C3
768670
True
769671
sage: C = codes.ExtendedQuadraticResidueCode(17,GF(2))
770672
sage: C
771-
Extended code coming from Linear code of length 17, dimension 9 over Finite Field of size 2
673+
Extended code coming from [17, 9] Cyclic Code over Finite Field of size 2 with x^8 + x^7 + x^6 + x^4 + x^2 + x + 1 as generator polynomial
772674
sage: C3 = codes.QuadraticResidueCodeOddPair(7,GF(2))[0]
773675
sage: C3x = C3.extended_code()
774676
sage: C4 = codes.ExtendedQuadraticResidueCode(7,GF(2))
@@ -864,10 +766,10 @@ def QuadraticResidueCode(n,F):
864766
865767
sage: C = codes.QuadraticResidueCode(7,GF(2))
866768
sage: C
867-
Linear code of length 7, dimension 4 over Finite Field of size 2
769+
[7, 4] Cyclic Code over Finite Field of size 2 with x^3 + x + 1 as generator polynomial
868770
sage: C = codes.QuadraticResidueCode(17,GF(2))
869771
sage: C
870-
Linear code of length 17, dimension 9 over Finite Field of size 2
772+
[17, 9] Cyclic Code over Finite Field of size 2 with x^8 + x^7 + x^6 + x^4 + x^2 + x + 1 as generator polynomial
871773
sage: C1 = codes.QuadraticResidueCodeOddPair(7,GF(2))[0]
872774
sage: C2 = codes.QuadraticResidueCode(7,GF(2))
873775
sage: C1 == C2
@@ -898,22 +800,22 @@ def QuadraticResidueCodeEvenPair(n,F):
898800
EXAMPLES::
899801
900802
sage: codes.QuadraticResidueCodeEvenPair(17,GF(13))
901-
(Linear code of length 17, dimension 8 over Finite Field of size 13,
902-
Linear code of length 17, dimension 8 over Finite Field of size 13)
803+
([17, 8] Cyclic Code over Finite Field of size 13 with x^9 + 7*x^8 + 2*x^7 + x^6 + 6*x^5 + 7*x^4 + 12*x^3 + 11*x^2 + 6*x + 12 as generator polynomial,
804+
[17, 8] Cyclic Code over Finite Field of size 13 with x^9 + 5*x^8 + 2*x^7 + x^6 + 4*x^5 + 9*x^4 + 12*x^3 + 11*x^2 + 8*x + 12 as generator polynomial)
903805
sage: codes.QuadraticResidueCodeEvenPair(17,GF(2))
904-
(Linear code of length 17, dimension 8 over Finite Field of size 2,
905-
Linear code of length 17, dimension 8 over Finite Field of size 2)
806+
([17, 8] Cyclic Code over Finite Field of size 2 with x^9 + x^6 + x^5 + x^4 + x^3 + 1 as generator polynomial,
807+
[17, 8] Cyclic Code over Finite Field of size 2 with x^9 + x^8 + x^6 + x^3 + x + 1 as generator polynomial)
906808
sage: codes.QuadraticResidueCodeEvenPair(13,GF(9,"z"))
907-
(Linear code of length 13, dimension 6 over Finite Field in z of size 3^2,
908-
Linear code of length 13, dimension 6 over Finite Field in z of size 3^2)
809+
([13, 6] Cyclic Code over Finite Field in z of size 3^2 with x^7 + 2*x^6 + 2*x^5 + x^2 + x + 2 as generator polynomial,
810+
[13, 6] Cyclic Code over Finite Field in z of size 3^2 with x^7 + x^5 + x^4 + 2*x^3 + 2*x^2 + 2 as generator polynomial)
909811
sage: C1,C2 = codes.QuadraticResidueCodeEvenPair(7,GF(2))
910812
sage: C1.is_self_orthogonal()
911813
True
912814
sage: C2.is_self_orthogonal()
913815
True
914816
sage: C3 = codes.QuadraticResidueCodeOddPair(17,GF(2))[0]
915817
sage: C4 = codes.QuadraticResidueCodeEvenPair(17,GF(2))[1]
916-
sage: C3 == C4.dual_code()
818+
sage: C3.systematic_generator_matrix() == C4.dual_code().systematic_generator_matrix()
917819
True
918820
919821
This is consistent with Theorem 6.6.9 and Exercise 365 in [HP]_.
@@ -962,14 +864,14 @@ def QuadraticResidueCodeOddPair(n,F):
962864
EXAMPLES::
963865
964866
sage: codes.QuadraticResidueCodeOddPair(17,GF(13))
965-
(Linear code of length 17, dimension 9 over Finite Field of size 13,
966-
Linear code of length 17, dimension 9 over Finite Field of size 13)
867+
([17, 9] Cyclic Code over Finite Field of size 13 with x^8 + 8*x^7 + 10*x^6 + 11*x^5 + 4*x^4 + 11*x^3 + 10*x^2 + 8*x + 1 as generator polynomial,
868+
[17, 9] Cyclic Code over Finite Field of size 13 with x^8 + 6*x^7 + 8*x^6 + 9*x^5 + 9*x^3 + 8*x^2 + 6*x + 1 as generator polynomial)
967869
sage: codes.QuadraticResidueCodeOddPair(17,GF(2))
968-
(Linear code of length 17, dimension 9 over Finite Field of size 2,
969-
Linear code of length 17, dimension 9 over Finite Field of size 2)
870+
([17, 9] Cyclic Code over Finite Field of size 2 with x^8 + x^7 + x^6 + x^4 + x^2 + x + 1 as generator polynomial,
871+
[17, 9] Cyclic Code over Finite Field of size 2 with x^8 + x^5 + x^4 + x^3 + 1 as generator polynomial)
970872
sage: codes.QuadraticResidueCodeOddPair(13,GF(9,"z"))
971-
(Linear code of length 13, dimension 7 over Finite Field in z of size 3^2,
972-
Linear code of length 13, dimension 7 over Finite Field in z of size 3^2)
873+
([13, 7] Cyclic Code over Finite Field in z of size 3^2 with x^6 + 2*x^4 + 2*x^3 + 2*x^2 + 1 as generator polynomial,
874+
[13, 7] Cyclic Code over Finite Field in z of size 3^2 with x^6 + x^5 + 2*x^4 + 2*x^2 + x + 1 as generator polynomial)
973875
sage: C1 = codes.QuadraticResidueCodeOddPair(17,GF(2))[1]
974876
sage: C1x = C1.extended_code()
975877
sage: C2 = codes.QuadraticResidueCodeOddPair(17,GF(2))[0]

src/sage/coding/codes_catalog.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from .linear_code import LinearCode
2525
from .code_constructions import (BCHCode, BinaryGolayCode, CyclicCodeFromGeneratingPolynomial,
26-
CyclicCode, CyclicCodeFromCheckPolynomial, DuadicCodeEvenPair,
26+
CyclicCodeFromCheckPolynomial, DuadicCodeEvenPair,
2727
DuadicCodeOddPair, ExtendedBinaryGolayCode,
2828
ExtendedQuadraticResidueCode, ExtendedTernaryGolayCode,
2929
from_parity_check_matrix,
@@ -42,6 +42,7 @@
4242

4343
from .guava import QuasiQuadraticResidueCode, RandomLinearCodeGuava
4444
_lazy_import('sage.coding.punctured_code', 'PuncturedCode')
45+
from .cyclic_code import CyclicCode
4546
from .hamming_code import HammingCode
4647
from . import decoders_catalog as decoders
4748
from . import encoders_catalog as encoders

0 commit comments

Comments
 (0)