52
52
from sage .modules .free_module import span
53
53
from sage .schemes .projective .projective_space import ProjectiveSpace
54
54
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
56
56
from sage .rings .finite_rings .integer_mod_ring import IntegerModRing
57
57
from sage .rings .polynomial .polynomial_ring_constructor import PolynomialRing
58
58
from sage .rings .integer import Integer
@@ -153,9 +153,9 @@ def _is_a_splitting(S1, S2, n, return_automorphism=False):
153
153
sage: i2_sqrd = (i2^2).quo_rem(x^n-1)[1]
154
154
sage: i2_sqrd == i2
155
155
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()
159
159
True
160
160
161
161
This is a special case of Theorem 6.4.3 in [HP]_.
@@ -414,22 +414,22 @@ def BCHCode(n,delta,F,b=0):
414
414
sage: f = x^(8)-1
415
415
sage: g.divides(f)
416
416
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
419
419
sage: C.minimum_distance()
420
420
4
421
421
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
423
423
sage: C.minimum_distance()
424
424
4
425
425
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
427
427
sage: C.minimum_distance()
428
428
3
429
429
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
432
431
"""
432
+ from sage .coding .cyclic_code import CyclicCode
433
433
q = F .order ()
434
434
R = IntegerModRing (n )
435
435
m = R (q ).multiplicative_order ()
@@ -446,7 +446,7 @@ def BCHCode(n,delta,F,b=0):
446
446
447
447
if not (g .divides (x ** n - 1 )):
448
448
raise ValueError ("BCH codes does not exist with the given input." )
449
- return CyclicCodeFromGeneratingPolynomial ( n , g )
449
+ return CyclicCode ( generator_pol = g , length = n )
450
450
451
451
452
452
def BinaryGolayCode ():
@@ -489,124 +489,22 @@ def BinaryGolayCode():
489
489
V = span (B , F )
490
490
return LinearCode (V , d = 7 )
491
491
492
-
493
492
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." )
559
496
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 )
576
498
577
499
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." )
599
503
P = h .parent ()
600
504
x = P .gen ()
601
- d = h .degree ()
602
505
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 ))
608
506
g = P ((x ** n - 1 )/ h )
609
- return CyclicCodeFromGeneratingPolynomial ( n , g )
507
+ return CyclicCode ( length = n , generator_pol = g , field = F )
610
508
611
509
def DuadicCodeEvenPair (F ,S1 ,S2 ):
612
510
r"""
@@ -630,9 +528,10 @@ def DuadicCodeEvenPair(F,S1,S2):
630
528
sage: _is_a_splitting(S1,S2,11)
631
529
True
632
530
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 )
635
533
"""
534
+ from sage .coding .cyclic_code import CyclicCode
636
535
n = len (S1 ) + len (S2 ) + 1
637
536
if not _is_a_splitting (S1 ,S2 ,n ):
638
537
raise TypeError ("%s, %s must be a splitting of %s." % (S1 ,S2 ,n ))
@@ -649,8 +548,8 @@ def DuadicCodeEvenPair(F,S1,S2):
649
548
x = P2 .gen ()
650
549
gg1 = P2 ([_lift2smallest_field (c )[0 ] for c in g1 .coefficients (sparse = False )])
651
550
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 )
654
553
return C1 ,C2
655
554
656
555
def DuadicCodeOddPair (F ,S1 ,S2 ):
@@ -674,11 +573,12 @@ def DuadicCodeOddPair(F,S1,S2):
674
573
sage: _is_a_splitting(S1,S2,11)
675
574
True
676
575
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 )
679
578
680
579
This is consistent with Theorem 6.1.3 in [HP]_.
681
580
"""
581
+ from sage .coding .cyclic_code import CyclicCode
682
582
n = len (S1 ) + len (S2 ) + 1
683
583
if not _is_a_splitting (S1 ,S2 ,n ):
684
584
raise TypeError ("%s, %s must be a splitting of %s." % (S1 ,S2 ,n ))
@@ -698,8 +598,10 @@ def DuadicCodeOddPair(F,S1,S2):
698
598
coeffs2 = [_lift2smallest_field (c )[0 ] for c in (g2 + j ).coefficients (sparse = False )]
699
599
gg1 = P2 (coeffs1 )
700
600
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 )
703
605
return C1 ,C2
704
606
705
607
@@ -763,12 +665,12 @@ def ExtendedQuadraticResidueCode(n,F):
763
665
sage: C1 = codes.QuadraticResidueCode(7,GF(2))
764
666
sage: C2 = C1.extended_code()
765
667
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
767
669
sage: C2 == C3
768
670
True
769
671
sage: C = codes.ExtendedQuadraticResidueCode(17,GF(2))
770
672
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
772
674
sage: C3 = codes.QuadraticResidueCodeOddPair(7,GF(2))[0]
773
675
sage: C3x = C3.extended_code()
774
676
sage: C4 = codes.ExtendedQuadraticResidueCode(7,GF(2))
@@ -864,10 +766,10 @@ def QuadraticResidueCode(n,F):
864
766
865
767
sage: C = codes.QuadraticResidueCode(7,GF(2))
866
768
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
868
770
sage: C = codes.QuadraticResidueCode(17,GF(2))
869
771
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
871
773
sage: C1 = codes.QuadraticResidueCodeOddPair(7,GF(2))[0]
872
774
sage: C2 = codes.QuadraticResidueCode(7,GF(2))
873
775
sage: C1 == C2
@@ -898,22 +800,22 @@ def QuadraticResidueCodeEvenPair(n,F):
898
800
EXAMPLES::
899
801
900
802
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 )
903
805
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 )
906
808
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 )
909
811
sage: C1,C2 = codes.QuadraticResidueCodeEvenPair(7,GF(2))
910
812
sage: C1.is_self_orthogonal()
911
813
True
912
814
sage: C2.is_self_orthogonal()
913
815
True
914
816
sage: C3 = codes.QuadraticResidueCodeOddPair(17,GF(2))[0]
915
817
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 ()
917
819
True
918
820
919
821
This is consistent with Theorem 6.6.9 and Exercise 365 in [HP]_.
@@ -962,14 +864,14 @@ def QuadraticResidueCodeOddPair(n,F):
962
864
EXAMPLES::
963
865
964
866
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 )
967
869
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 )
970
872
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 )
973
875
sage: C1 = codes.QuadraticResidueCodeOddPair(17,GF(2))[1]
974
876
sage: C1x = C1.extended_code()
975
877
sage: C2 = codes.QuadraticResidueCodeOddPair(17,GF(2))[0]
0 commit comments