GAP (guava) - Chapter 5: Generating Codes

Goto Chapter: Top 1 2 3 4 5 6 7 8 9 Bib Ind
[Top of Book] [Contents] [Previous Chapter] [Next Chapter]

5 Generating Codes
5.1 Generating Unrestricted Codes
5.1-1 ElementsCode
5.1-2 HadamardCode
5.1-3 ConferenceCode
5.1-4 MOLSCode
5.1-5 RandomCode
5.1-6 NordstromRobinsonCode
5.1-7 GreedyCode
5.1-8 LexiCode
5.2 Generating Linear Codes
5.2-1 GeneratorMatCode
5.2-2 CheckMatCodeMutable
5.2-3 CheckMatCode
5.2-4 HammingCode
5.2-5 ReedMullerCode
5.2-6 AlternantCode
5.2-7 GoppaCode
5.2-8 GeneralizedSrivastavaCode
5.2-9 SrivastavaCode
5.2-10 CordaroWagnerCode
5.2-11 FerreroDesignCode
5.2-12 RandomLinearCode
5.2-13 OptimalityCode
5.2-14 BestKnownLinearCode
5.3 Gabidulin Codes
5.3-1 GabidulinCode
5.3-2 EnlargedGabidulinCode
5.3-3 DavydovCode
5.3-4 TombakCode
5.3-5 EnlargedTombakCode
5.4 Golay Codes
5.4-1 BinaryGolayCode
5.4-2 ExtendedBinaryGolayCode
5.4-3 TernaryGolayCode
5.4-4 ExtendedTernaryGolayCode
5.5 Generating Cyclic Codes
5.5-1 GeneratorPolCode
5.5-2 CheckPolCode
5.5-3 RootsCode
5.5-4 BCHCode
5.5-5 ReedSolomonCode
5.5-6 ExtendedReedSolomonCode
5.5-7 QRCode
5.5-8 QQRCodeNC
5.5-9 QQRCode
5.5-10 FireCode
5.5-11 WholeSpaceCode
5.5-12 NullCode
5.5-13 RepetitionCode
5.5-14 CyclicCodes
5.5-15 NrCyclicCodes
5.5-16 QuasiCyclicCode
5.5-17 CyclicMDSCode
5.5-18 FourNegacirculantSelfDualCode
5.5-19 FourNegacirculantSelfDualCodeNC
5.6 Evaluation Codes
5.6-1 EvaluationCode
5.6-2 GeneralizedReedSolomonCode
5.6-3 GeneralizedReedMullerCode
5.6-4 ToricPoints
5.6-5 ToricCode
5.7 Algebraic geometric codes
5.7-1 AffineCurve
5.7-2 AffinePointsOnCurve
5.7-3 GenusCurve
5.7-4 GOrbitPoint
5.7-5 DivisorOnAffineCurve
5.7-6 DivisorAddition
5.7-7 DivisorDegree
5.7-8 DivisorNegate
5.7-9 DivisorIsZero
5.7-10 DivisorsEqual
5.7-11 DivisorGCD
5.7-12 DivisorLCM
5.7-13 RiemannRochSpaceBasisFunctionP1
5.7-14 DivisorOfRationalFunctionP1
5.7-15 RiemannRochSpaceBasisP1
5.7-16 MoebiusTransformation
5.7-17 ActionMoebiusTransformationOnFunction
5.7-18 ActionMoebiusTransformationOnDivisorP1
5.7-19 IsActionMoebiusTransformationOnDivisorDefinedP1
5.7-20 DivisorAutomorphismGroupP1
5.7-21 MatrixRepresentationOnRiemannRochSpaceP1
5.7-22 GoppaCodeClassical
5.7-23 EvaluationBivariateCode
5.7-24 EvaluationBivariateCodeNC
5.7-25 OnePointAGCode
5.8 Low-Density Parity-Check Codes
5.8-1 QCLDPCCodeFromGroup

### 5 Generating Codes

In this chapter we describe functions for generating codes.

Section 5.1 describes functions for generating unrestricted codes.

Section 5.2 describes functions for generating linear codes.

Section 5.3 describes functions for constructing certain covering codes, such as the Gabidulin codes.

Section 5.4 describes functions for constructing the Golay codes.

Section 5.5 describes functions for generating cyclic codes.

Section 5.6 describes functions for generating codes as the image of an evaluation map applied to a space of functions. For example, generalized Reed-Solomon codes and toric codes are described there.

Section 5.7 describes functions for generating algebraic geometry codes.

Section 5.8 describes functions for constructing low-density parity-check (LDPC) codes.

#### 5.1 Generating Unrestricted Codes

In this section we start with functions that creating code from user defined matrices or special matrices (see `ElementsCode` (5.1-1), `HadamardCode` (5.1-2), `ConferenceCode` (5.1-3) and `MOLSCode` (5.1-4)). These codes are unrestricted codes; they may later be discovered to be linear or cyclic.

The next functions generate random codes (see `RandomCode` (5.1-5)) and the Nordstrom-Robinson code (see `NordstromRobinsonCode` (5.1-6)), respectively.

Finally, we describe two functions for generating Greedy codes. These are codes that contructed by gathering codewords from a space (see `GreedyCode` (5.1-7) and `LexiCode` (5.1-8)).

##### 5.1-1 ElementsCode

`‣ ElementsCode`( L[, name], F ) | ( function )

`ElementsCode` creates an unrestricted code of the list of elements L, in the field F. L must be a list of vectors, strings, polynomials or codewords. name can contain a short description of the code.

If L contains a codeword more than once, it is removed from the list and a GAP set is returned.

    gap> M := Z(3)^0 * [ [1, 0, 1, 1], [2, 2, 0, 0], [0, 1, 2, 2] ];;
    gap> C := ElementsCode( M, "example code", GF(3) );
    a (4,3,1..4)2 example code over GF(3)
    gap> MinimumDistance( C );
    4
    gap> AsSSortedList( C );
    [ [ 0 1 2 2 ], [ 1 0 1 1 ], [ 2 2 0 0 ] ]

##### 5.1-2 HadamardCode

`‣ HadamardCode`( H[, t] ) | ( function )

The four forms this command can take are `HadamardCode(H,t)`, `HadamardCode(H)`, `HadamardCode(n,t)`, and `HadamardCode(n)`.

In the case when the arguments H and t are both given, `HadamardCode` returns a Hadamard code of the t^th kind from the Hadamard matrix H In case only H is given, t = 3 is used.

By definition, a Hadamard matrix is a square matrix H with H⋅ H^T = -n⋅ I_n, where n is the size of H. The entries of H are either 1 or -1.

The matrix H is first transformed into a binary matrix A_n by replacing the 1's by 0's and the -1's by 1s).

The Hadamard matrix of the first kind (t=1) is created by using the rows of A_n as elements, after deleting the first column. This is a (n-1, n, n/2) code. We use this code for creating the Hadamard code of the second kind (t=2), by adding all the complements of the already existing codewords. This results in a (n-1, 2n, n/2 -1) code. The third kind (t=3) is created by using the rows of A_n (without cutting a column) and their complements as elements. This way, we have an (n, 2n, n/2)-code. The returned code is generally an unrestricted code, but for n = 2^r, the code is linear.

The command `HadamardCode(n,t)` returns a Hadamard code with parameter n of the t^th kind. For the command `HadamardCode(n)`, t=3 is used.

When called in these forms, `HadamardCode` first creates a Hadamard matrix (see `HadamardMat` (7.3-4)), of size n and then follows the same procedure as described above. Therefore the same restrictions with respect to n as for Hadamard matrices hold.

    gap> H4 := [[1,1,1,1],[1,-1,1,-1],[1,1,-1,-1],[1,-1,-1,1]];;
    gap> HadamardCode( H4, 1 );
    a (3,4,2)1 Hadamard code of order 4 over GF(2)
    gap> HadamardCode( H4, 2 );
    a (3,8,1)0 Hadamard code of order 4 over GF(2)
    gap> HadamardCode( H4 );
    a (4,8,2)1 Hadamard code of order 4 over GF(2)
    gap> H4 := [[1,1,1,1],[1,-1,1,-1],[1,1,-1,-1],[1,-1,-1,1]];;
    gap> C := HadamardCode( 4 );
    a (4,8,2)1 Hadamard code of order 4 over GF(2)
    gap> C = HadamardCode( H4 );
    true

##### 5.1-3 ConferenceCode

`‣ ConferenceCode`( H ) | ( function )

`ConferenceCode` returns a code of length n-1 constructed from a symmetric 'conference matrix' H. A conference matrix H is a symmetric matrix of order n, which satisfies H⋅ H^T = ((n-1)⋅ I, with n ≡ 2 mod 4. The rows of frac12(H+I+J), frac12(-H+I+J), plus the zero and all-ones vectors form the elements of a binary non-linear (n-1, 2n, (n-2)/2) code.

GUAVA constructs a symmetric conference matrix of order n+1 (n≡ 1 mod 4) and uses the rows of that matrix, plus the zero and all-ones vectors, to construct a binary non-linear (n, 2(n+1), (n-1)/2)-code.

    gap> H6 := [[0,1,1,1,1,1],[1,0,1,-1,-1,1],[1,1,0,1,-1,-1],
    > [1,-1,1,0,1,-1],[1,-1,-1,1,0,1],[1,1,-1,-1,1,0]];;
    gap> C1 := ConferenceCode( H6 );
    a (5,12,2)1..4 conference code over GF(2)
    gap> IsLinearCode( C1 );
    false
    gap> C2 := ConferenceCode( 5 );
    a (5,12,2)1..4 conference code over GF(2)
    gap> AsSSortedList( C2 );
    [ [ 0 0 0 0 0 ], [ 0 0 1 1 1 ], [ 0 1 0 1 1 ], [ 0 1 1 0 1 ], [ 0 1 1 1 0 ],
      [ 1 0 0 1 1 ], [ 1 0 1 0 1 ], [ 1 0 1 1 0 ], [ 1 1 0 0 1 ], [ 1 1 0 1 0 ],
      [ 1 1 1 0 0 ], [ 1 1 1 1 1 ] ]

##### 5.1-4 MOLSCode

`‣ MOLSCode`( [n, ]q ) | ( function )

`MOLSCode` returns an (n, q^2, n-1) code over GF(q). The code is created from n-2 'Mutually Orthogonal Latin Squares' (MOLS) of size q × q. The default for n is 4. GUAVA can construct a MOLS code for n-2 ≤ q. Here q must be a prime power, q > 2. If there are no n-2 MOLS, an error is signalled.

Since each of the n-2 MOLS is a q× q matrix, we can create a code of size q^2 by listing in each code element the entries that are in the same position in each of the MOLS. We precede each of these lists with the two coordinates that specify this position, making the word length become n.

The MOLS codes are MDS codes (see `IsMDSCode` (4.3-7)).

    gap> C1 := MOLSCode( 6, 5 );
    a (6,25,5)3..4 code generated by 4 MOLS of order 5 over GF(5)
    gap> mols := List( [1 .. WordLength(C1) - 2 ], function( nr )
    >       local ls, el;
    >       ls := NullMat( Size(LeftActingDomain(C1)), Size(LeftActingDomain(C1)) );
    >       for el in VectorCodeword( AsSSortedList( C1 ) ) do
    >          ls[IntFFE(el[1])+1][IntFFE(el[2])+1] := el[nr + 2];
    >       od;
    >       return ls;
    >    end );;
    gap> AreMOLS( mols );
    true
    gap> C2 := MOLSCode( 11 );
    a (4,121,3)2 code generated by 2 MOLS of order 11 over GF(11)

##### 5.1-5 RandomCode

`‣ RandomCode`( n, M, F ) | ( function )

`RandomCode` returns a random unrestricted code of size M with word length n over F. M must be less than or equal to the number of elements in the space GF(q)^n.

The function `RandomLinearCode` returns a random linear code (see `RandomLinearCode` (5.2-12)).

    gap> C1 := RandomCode( 6, 10, GF(8) );
    a (6,10,1..6)4..6 random unrestricted code over GF(8)
    gap> MinimumDistance(C1);
    3
    gap> C2 := RandomCode( 6, 10, GF(8) );
    a (6,10,1..6)4..6 random unrestricted code over GF(8)
    gap> C1 = C2;
    false

##### 5.1-6 NordstromRobinsonCode

`‣ NordstromRobinsonCode`( ) | ( function )

`NordstromRobinsonCode` returns a Nordstrom-Robinson code, the best code with word length n=16 and minimum distance d=6 over GF(2). This is a non-linear (16, 256, 6) code.

    gap> C := NordstromRobinsonCode();
    a (16,256,6)4 Nordstrom-Robinson code over GF(2)
    gap> OptimalityCode( C );
    0

##### 5.1-7 GreedyCode

`‣ GreedyCode`( L, d, F ) | ( function )

`GreedyCode` returns a Greedy code with design distance d over the finite field F. The code is constructed using the greedy algorithm on the list of vectors L. (The greedy algorithm checks each vector in L and adds it to the code if its distance to the current code is greater than or equal to d. It is obvious that the resulting code has a minimum distance of at least d.

Greedy codes are often linear codes.

The function `LexiCode` creates a greedy code from a basis instead of an enumerated list (see `LexiCode` (5.1-8)).

    gap> C1 := GreedyCode( Tuples( AsSSortedList( GF(2) ), 5 ), 3, GF(2) );
    a (5,4,3..5)2 Greedy code, user defined basis over GF(2)
    gap> C2 := GreedyCode( Permuted( Tuples( AsSSortedList( GF(2) ), 5 ),
    >                         (1,4) ), 3, GF(2) );
    a (5,4,3..5)2 Greedy code, user defined basis over GF(2)
    gap> C1 = C2;
    false

##### 5.1-8 LexiCode

`‣ LexiCode`( n, d, F ) | ( function )

In this format, `Lexicode` returns a lexicode with word length n, design distance d over F. The code is constructed using the greedy algorithm on the lexicographically ordered list of all vectors of length n over F. Every time a vector is found that has a distance to the current code of at least d, it is added to the code. This results, obviously, in a code with minimum distance greater than or equal to d.

Another syntax which one can use is `LexiCode( B, d, F )`. When called in this format, `LexiCode` uses the basis B instead of the standard basis. B is a matrix of vectors over F. The code is constructed using the greedy algorithm on the list of vectors spanned by B, ordered lexicographically with respect to B.

Note that binary lexicodes are always linear.

    gap> C := LexiCode( 4, 3, GF(5) );
    a (4,17,3..4)2..4 lexicode over GF(5)
    gap> B := [ [Z(2)^0, 0*Z(2), 0*Z(2)], [Z(2)^0, Z(2)^0, 0*Z(2)] ];;
    gap> C := LexiCode( B, 2, GF(2) );
    a linear [3,1,2]1..2 lexicode over GF(2)

The function `GreedyCode` creates a greedy code that is not restricted to a lexicographical order (see `GreedyCode` (5.1-7)).

#### 5.2 Generating Linear Codes

In this section we describe functions for constructing linear codes. A linear code always has a generator or check matrix.

The first two functions generate linear codes from the generator matrix (`GeneratorMatCode` (5.2-1)) or check matrix (`CheckMatCode` (5.2-3)). All linear codes can be constructed with these functions.

The next functions we describe generate some well-known codes, like Hamming codes (`HammingCode` (5.2-4)), Reed-Muller codes (`ReedMullerCode` (5.2-5)) and the extended Golay codes (`ExtendedBinaryGolayCode` (5.4-2) and `ExtendedTernaryGolayCode` (5.4-4)).

A large and powerful family of codes are alternant codes. They are obtained by a small modification of the parity check matrix of a BCH code (see `AlternantCode` (5.2-6), `GoppaCode` (5.2-7), `GeneralizedSrivastavaCode` (5.2-8) and `SrivastavaCode` (5.2-9)).

Finally, we describe a function for generating random linear codes (see `RandomLinearCode` (5.2-12)).

##### 5.2-1 GeneratorMatCode

`‣ GeneratorMatCode`( G[, name], F ) | ( function )

`GeneratorMatCode` returns a linear code with generator matrix G. G must be a matrix over finite field F. name can contain a short description of the code. The generator matrix is the basis of the elements of the code. The resulting code has word length n, dimension k if G is a k × n-matrix. If GF(q) is the field of the code, the size of the code will be q^k.

If the generator matrix does not have full row rank, the linearly dependent rows are removed. This is done by the GAP function `BaseMat` and results in an equal code. The generator matrix can be retrieved with the function `GeneratorMat` (see `GeneratorMat` (4.7-1)).

    gap> G := Z(3)^0 * [[1,0,1,2,0],[0,1,2,1,1],[0,0,1,2,1]];;
    gap> C1 := GeneratorMatCode( G, GF(3) );
    a linear [5,3,1..2]1..2 code defined by generator matrix over GF(3)
    gap> C2 := GeneratorMatCode( IdentityMat( 5, GF(2) ), GF(2) );
    a linear [5,5,1]0 code defined by generator matrix over GF(2)
    gap> GeneratorMatCode( List( AsSSortedList( NordstromRobinsonCode() ),
    > x -> VectorCodeword( x ) ), GF( 2 ) );
    a linear [16,11,1..4]2 code defined by generator matrix over GF(2)
    # This is the smallest linear code that contains the N-R code

##### 5.2-2 CheckMatCodeMutable

`‣ CheckMatCodeMutable`( H[, name], F ) | ( function )

`CheckMatCodeMutable` is the same as `CheckMatCode` except that the check matrix and generator matrix are mutable.

##### 5.2-3 CheckMatCode

`‣ CheckMatCode`( H[, name], F ) | ( function )

`CheckMatCode` returns a linear code with check matrix H. H must be a matrix over Galois field F. [name. can contain a short description of the code. The parity check matrix is the transposed of the nullmatrix of the generator matrix of the code. Therefore, c⋅ H^T = 0 where c is an element of the code. If H is a r× n-matrix, the code has word length n, redundancy r and dimension n-r.

If the check matrix does not have full row rank, the linearly dependent rows are removed. This is done by the GAP function `BaseMat`. and results in an equal code. The check matrix can be retrieved with the function `CheckMat` (see `CheckMat` (4.7-2)).

    gap> G := Z(3)^0 * [[1,0,1,2,0],[0,1,2,1,1],[0,0,1,2,1]];;
    gap> C1 := CheckMatCode( G, GF(3) );
    a linear [5,2,1..2]2..3 code defined by check matrix over GF(3)
    gap> CheckMat(C1);
    [ [ Z(3)^0, 0*Z(3), Z(3)^0, Z(3), 0*Z(3) ],
      [ 0*Z(3), Z(3)^0, Z(3), Z(3)^0, Z(3)^0 ],
      [ 0*Z(3), 0*Z(3), Z(3)^0, Z(3), Z(3)^0 ] ]
    gap> C2 := CheckMatCode( IdentityMat( 5, GF(2) ), GF(2) );
    a cyclic [5,0,5]5 code defined by check matrix over GF(2)

##### 5.2-4 HammingCode

`‣ HammingCode`( r, F ) | ( function )

`HammingCode` returns a Hamming code with redundancy r over F. A Hamming code is a single-error-correcting code. The parity check matrix of a Hamming code has all nonzero vectors of length r in its columns, except for a multiplication factor. The decoding algorithm of the Hamming code (see `Decode` (4.10-1)) makes use of this property.

If q is the size of its field F, the returned Hamming code is a linear [(q^r-1)/(q-1), (q^r-1)/(q-1) - r, 3] code.

    gap> C1 := HammingCode( 4, GF(2) );
    a linear [15,11,3]1 Hamming (4,2) code over GF(2)
    gap> C2 := HammingCode( 3, GF(9) );
    a linear [91,88,3]1 Hamming (3,9) code over GF(9)

##### 5.2-5 ReedMullerCode

`‣ ReedMullerCode`( r, k ) | ( function )

`ReedMullerCode` returns a binary 'Reed-Muller code' R(r, k) with dimension k and order r. This is a code with length 2^k and minimum distance 2^k-r (see for example, section 1.10 in [HP03]). By definition, the r^th order binary Reed-Muller code of length n=2^m, for 0 ≤ r ≤ m, is the set of all vectors f, where f is a Boolean function which is a polynomial of degree at most r.

    gap> ReedMullerCode( 1, 3 );
    a linear [8,4,4]2 Reed-Muller (1,3) code over GF(2)

See `GeneralizedReedMullerCode` (5.6-3) for a more general construction.

##### 5.2-6 AlternantCode

`‣ AlternantCode`( r, Y[, alpha], F ) | ( function )

`AlternantCode` returns an 'alternant code', with parameters r, Y and alpha (optional). F denotes the (finite) base field. Here, r is the design redundancy of the code. Y and alpha are both vectors of length n from which the parity check matrix is constructed. The check matrix has the form H=([a_i^j y_i]), where 0 ≤ j≤ r-1, 1 ≤ i≤ n, and where [...] is as in `VerticalConversionFieldMat` (7.3-9)). If no alpha is specified, the vector [1, a, a^2, .., a^n-1] is used, where a is a primitive element of a Galois field F.

    gap> Y := [ 1, 1, 1, 1, 1, 1, 1];; a := PrimitiveUnityRoot( 2, 7 );;
    gap> alpha := List( [0..6], i -> a^i );;
    gap> C := AlternantCode( 2, Y, alpha, GF(8) );
    a linear [7,3,3..4]3..4 alternant code over GF(8)

##### 5.2-7 GoppaCode

`‣ GoppaCode`( G, L ) | ( function )

`GoppaCode` returns a Goppa code C from Goppa polynomial g, having coefficients in a Galois Field GF(q). L must be a list of elements in GF(q), that are not roots of g. The word length of the code is equal to the length of L. The parity check matrix has the form H=([a_i^j / G(a_i)])_0 ≤ j ≤ deg(g)-1, a_i ∈ L, where a_i∈ L and [...] is as in `VerticalConversionFieldMat` (7.3-9), so H has entries in GF(q), q=p^m. It is known that d(C)≥ deg(g)+1, with a better bound in the binary case provided g has no multiple roots. See Huffman and Pless [HP03] section 13.2.2, and MacWilliams and Sloane [MS83] section 12.3, for more details.

One can also call `GoppaCode` using the syntax `GoppaCode(g,n)`. When called with parameter n, GUAVA constructs a list L of length n, such that no element of L is a root of g.

This is a special case of an alternant code.

    gap> x:=Indeterminate(GF(8),"x");
    x
    gap> L:=Elements(GF(8));
    [ 0*Z(2), Z(2)^0, Z(2^3), Z(2^3)^2, Z(2^3)^3, Z(2^3)^4, Z(2^3)^5, Z(2^3)^6 ]
    gap> g:=x^2+x+1;
    x^2+x+Z(2)^0
    gap> C:=GoppaCode(g,L);
    a linear [8,2,5]3 Goppa code over GF(2)
    gap> xx := Indeterminate( GF(2), "xx" );;
    gap> gg := xx^2 + xx + 1;; L := AsSSortedList( GF(8) );;
    gap> C1 := GoppaCode( gg, L );
    a linear [8,2,5]3 Goppa code over GF(2)
    gap> y := Indeterminate( GF(2), "y" );;
    gap> h := y^2 + y + 1;;
    gap> C2 := GoppaCode( h, 8 );
    a linear [8,2,5]3 Goppa code over GF(2)
    gap> C1=C2;
    true
    gap> C=C1;
    true

##### 5.2-8 GeneralizedSrivastavaCode

`‣ GeneralizedSrivastavaCode`( a, w, z[, t], F ) | ( function )

`GeneralizedSrivastavaCode` returns a generalized Srivastava code with parameters a, w, z, t. a ={ a_1, ..., a_n} and w ={ w_1, ..., w_s} are lists of n+s distinct elements of F=GF(q^m), z is a list of length n of nonzero elements of GF(q^m). The parameter t determines the designed distance: d ≥ st + 1. The check matrix of this code is the form

H=([\frac{z_i}{(a_i - w_j)^k}]),

1≤ k≤ t, where [...] is as in `VerticalConversionFieldMat` (7.3-9). We use this definition of H to define the code. The default for t is 1. The original Srivastava codes (see `SrivastavaCode` (5.2-9)) are a special case t=1, z_i=a_i^μ, for some μ.

    gap> a := Filtered( AsSSortedList( GF(2^6) ), e -> e in GF(2^3) );;
    gap> w := [ Z(2^6) ];; z := List( [1..8], e -> 1 );;
    gap> C := GeneralizedSrivastavaCode( a, w, z, 1, GF(64) );
    a linear [8,2,2..5]3..4 generalized Srivastava code over GF(2)

##### 5.2-9 SrivastavaCode

`‣ SrivastavaCode`( a, w[, mu], F ) | ( function )

SrivastavaCode returns a Srivastava code with parameters a, w (and optionally mu). a ={ a_1, ..., a_n} and w ={ w_1, ..., w_s} are lists of n+s distinct elements of F=GF(q^m). The default for mu is 1. The Srivastava code is a generalized Srivastava code, in which z_i = a_i^mu for some mu and t=1.

J. N. Srivastava introduced this code in 1967, though his work was not published. See Helgert [Hel72] for more details on the properties of this code. Related reference: G. Roelofsen, On Goppa and Generalized Srivastava Codes PhD thesis, Dept. Math. and Comp. Sci., Eindhoven Univ. of Technology, the Netherlands, 1982.

    gap> a := AsSSortedList( GF(11) ){[2..8]};;
    gap> w := AsSSortedList( GF(11) ){[9..10]};;
    gap> C := SrivastavaCode( a, w, 2, GF(11) );
    a linear [7,5,3]2 Srivastava code over GF(11)
    gap> IsMDSCode( C );
    true    # Always true if F is a prime field

##### 5.2-10 CordaroWagnerCode

`‣ CordaroWagnerCode`( n ) | ( function )

`CordaroWagnerCode` returns a binary Cordaro-Wagner code. This is a code of length n and dimension 2 having the best possible minimum distance d. This code is just a little bit less trivial than `RepetitionCode` (see `RepetitionCode` (5.5-13)).

    gap> C := CordaroWagnerCode( 11 );
    a linear [11,2,7]5 Cordaro-Wagner code over GF(2)
    gap> AsSSortedList(C);
    [ [ 0 0 0 0 0 0 0 0 0 0 0 ], [ 0 0 0 0 1 1 1 1 1 1 1 ],
      [ 1 1 1 1 0 0 0 1 1 1 1 ], [ 1 1 1 1 1 1 1 0 0 0 0 ] ]

##### 5.2-11 FerreroDesignCode

`‣ FerreroDesignCode`( P, m ) | ( function )

Requires the GAP package SONATA

A group K together with a group of automorphism H of K such that the semidirect product KH is a Frobenius group with complement H is called a Ferrero pair (K, H) in SONATA. Take a Frobenius (G,+) group with kernel K and complement H. Consider the design D with point set K and block set { a^H + b | a, b ∈ K, a not= 0 }. Here a^H denotes the orbit of a under conjugation by elements of H. Every planar near-ring design of type "*" can be obtained in this way from groups. These designs (from a Frobenius kernel of order v and a Frobenius complement of order k) have v(v-1)/k distinct blocks and they are all of size k. Moreover each of the v points occurs in exactly v-1 distinct blocks. Hence the rows and the columns of the incidence matrix M of the design are always of constant weight.

`FerreroDesignCode` constructs binary linear code arising from the incdence matrix of a design associated to a "Ferrero pair" arising from a fixed-point-free (fpf) automorphism groups and Frobenius group.

INPUT: P is a list of prime powers describing an abelian group G. m > 0 is an integer such that G admits a cyclic fpf automorphism group of size m. This means that for all q = p^k ∈ P, OrderMod(p, m) must divide q (see the SONATA documentation for `FpfAutomorphismGroupsCyclic`).

OUTPUT: The binary linear code whose generator matrix is the incidence matrix of a design associated to a "Ferrero pair" arising from the fixed-point-free (fpf) automorphism group of G. The pair (H,K) is called a Ferraro pair and the semidirect product KH is a Frobenius group with complement H.

AUTHORS: Peter Mayr and David Joyner

    gap> G:=AbelianGroup([5,5] );
     [ pc group of size 25 with 2 generators ]
    gap> FpfAutomorphismGroupsMaxSize( G );
    [ 24, 2 ]
    gap> L:=FpfAutomorphismGroupsCyclic( [5,5], 3 );
    [ [ [ f1, f2 ] -> [ f1*f2^2, f1*f2^3 ] ],
      [ pc group of size 25 with 2 generators ] ]
    gap> D := DesignFromFerreroPair( L[2], Group(L[1][1]), "*" );
     [ a 2 - ( 25, 3, 2 ) nearring generated design ]
    gap> M:=IncidenceMat( D );; Length(M); Length(TransposedMat(M));
    25
    200
    gap> C1:=GeneratorMatCode(M*Z(2),GF(2));
    a linear [200,25,1..24]62..100 code defined by generator matrix over GF(2)
    gap> MinimumDistance(C1);
    24
    gap> C2:=FerreroDesignCode( [5,5],3);
    a linear [200,25,1..24]62..100 code defined by generator matrix over GF(2)
    gap> C1=C2;
    true

##### 5.2-12 RandomLinearCode

`‣ RandomLinearCode`( n, k, F ) | ( function )

`RandomLinearCode` returns a random linear code with word length n, dimension k over field F. The method used is to first construct a k× n matrix of the block form (I,A), where I is a k× k identity matrix and A is a k× (n-k) matrix constructed using `Random(F)` repeatedly. Then the columns are permuted using a randomly selected element of `SymmetricGroup(n)`.

To create a random unrestricted code, use `RandomCode` (see `RandomCode` (5.1-5)).

    gap> C := RandomLinearCode( 15, 4, GF(3) );
    a  [15,4,?] randomly generated code over GF(3)
    gap> Display(C);
    a linear [15,4,1..6]6..10 random linear code over GF(3)

The method GUAVA chooses to output the result of a `RandomLinearCode` command is different than other codes. For example, the bounds on the minimum distance is not displayed. Howeer, you can use the `Display` command to print this information. This new display method was added in version 1.9 to speed up the command (if n is about 80 and k about 40, for example, the time it took to look up and/or calculate the bounds on the minimum distance was too long).

##### 5.2-13 OptimalityCode

`‣ OptimalityCode`( C ) | ( function )

`OptimalityCode` returns the difference between the smallest known upper bound and the actual size of the code. Note that the value of the function `UpperBound` is not always equal to the actual upper bound A(n,d) thus the result may not be equal to 0 even if the code is optimal!

`OptimalityLinearCode` is similar but applies only to linear codes.

##### 5.2-14 BestKnownLinearCode

`‣ BestKnownLinearCode`( n, k, F ) | ( function )

`BestKnownLinearCode` returns the best known (as of 11 May 2006) linear code of length n, dimension k over field F. The function uses the tables described in section `BoundsMinimumDistance` (7.1-13) to construct this code.

This command can also be called using the syntax `BestKnownLinearCode( rec )`, where rec must be a record containing the fields `lowerBound', `upperBound' and `construction'. It uses the information in this field to construct a code. This form is meant to be used together with the function `BoundsMinimumDistance` (see `BoundsMinimumDistance` (7.1-13)), if the bounds are already calculated.

    gap> C1 := BestKnownLinearCode( 23, 12, GF(2) );
    a linear [23,12,7]3 punctured code
    gap> C1 = BinaryGolayCode();
    false     # it's constructed differently
    gap> C1 := BestKnownLinearCode( 23, 12, GF(2) );
    a linear [23,12,7]3 punctured code
    gap> G1 := MutableCopyMat(GeneratorMat(C1));;
    gap> PutStandardForm(G1);
    ()
    gap> Display(G1);
     1 . . . . . . . . . . . 1 . 1 . 1 1 1 . . . 1
     . 1 . . . . . . . . . . 1 1 1 1 1 . . 1 . . .
     . . 1 . . . . . . . . . 1 1 . 1 . . 1 . 1 . 1
     . . . 1 . . . . . . . . 1 1 . . . 1 1 1 . 1 .
     . . . . 1 . . . . . . . 1 1 . . 1 1 . 1 1 . 1
     . . . . . 1 . . . . . . . 1 1 . . 1 1 . 1 1 1
     . . . . . . 1 . . . . . . . 1 1 . . 1 1 . 1 1
     . . . . . . . 1 . . . . 1 . 1 1 . 1 1 1 1 . .
     . . . . . . . . 1 . . . . 1 . 1 1 . 1 1 1 1 .
     . . . . . . . . . 1 . . . . 1 . 1 1 . 1 1 1 .
     . . . . . . . . . . 1 . 1 . 1 1 1 . . . 1 1 1
     . . . . . . . . . . . 1 . 1 . 1 1 1 . . . 1 1
    gap> C2 := BinaryGolayCode();
    a cyclic [23,12,7]3 binary Golay code over GF(2)
    gap> G2 := MutableCopyMat(GeneratorMat(C2));;
    gap> PutStandardForm(G2);
    ()
    gap> Display(G2);
     1 . . . . . . . . . . . 1 . 1 . 1 1 1 . . . 1
     . 1 . . . . . . . . . . 1 1 1 1 1 . . 1 . . 1
     . . 1 . . . . . . . . . 1 1 . 1 . . 1 . 1 . 1
     . . . 1 . . . . . . . . 1 1 . . . 1 1 1 . 1 1
     . . . . 1 . . . . . . . 1 1 . . 1 1 . 1 1 . .
     . . . . . 1 . . . . . . . 1 1 . . 1 1 . 1 1 .
     . . . . . . 1 . . . . . . . 1 1 . . 1 1 . 1 1
     . . . . . . . 1 . . . . 1 . 1 1 . 1 1 1 1 . .
     . . . . . . . . 1 . . . . 1 . 1 1 . 1 1 1 1 .
     . . . . . . . . . 1 . . . . 1 . 1 1 . 1 1 1 1
     . . . . . . . . . . 1 . 1 . 1 1 1 . . . 1 1 .
     . . . . . . . . . . . 1 . 1 . 1 1 1 . . . 1 1
    ## Despite their generator matrices are different, they are equivalent codes, see below.
    gap> IsEquivalent(C1,C2);
    true
    gap> CodeIsomorphism(C1,C2);
    (4,14,6,12,5)(7,17,18,11,19)(8,22,13,21,16)(10,23,15,20)
    gap> Display( BestKnownLinearCode( 81, 77, GF(4) ) );
    a linear [81,77,3]2..3 shortened code of
    a linear [85,81,3]1 Hamming (4,4) code over GF(4)
    gap> C:=BestKnownLinearCode(174,72);
    a linear [174,72,31..36]26..87 code defined by generator matrix over GF(2)
    gap> bounds := BoundsMinimumDistance( 81, 77, GF(4) );
    rec( n := 81, k := 77, q := 4,
      references := rec( Ham := [ "%T this reference is unknown, for more info",
              "%T contact A.E. Brouwer (aeb@cwi.nl)" ],
          cap := [ "%T this reference is unknown, for more info",
              "%T contact A.E. Brouwer (aeb@cwi.nl)" ] ),
      construction := [ (Operation "ShortenedCode"),
          [ [ (Operation "HammingCode"), [ 4, 4 ] ], [ 1, 2, 3, 4 ] ] ],
      lowerBound := 3,
      lowerBoundExplanation := [ "Lb(81,77)=3, by shortening of:",
          "Lb(85,81)=3, reference: Ham" ], upperBound := 3,
      upperBoundExplanation := [ "Ub(81,77)=3, by considering shortening to:",
          "Ub(18,14)=3, reference: cap" ] )
    gap> C := BestKnownLinearCode( bounds );
    a linear [81,77,3]2..3 shortened code
    gap> C = BestKnownLinearCode(81, 77, GF(4) );
    true

#### 5.3 Gabidulin Codes

These five binary, linear codes are derived from an article by Gabidulin, Davydov and Tombak [GDT91]. All these codes are defined by check matrices. Exact definitions can be found in the article. The Gabidulin code, the enlarged Gabidulin code, the Davydov code, the Tombak code, and the enlarged Tombak code, correspond with theorem 1, 2, 3, 4, and 5, respectively in the article.

Like the Hamming codes, these codes have fixed minimum distance and covering radius, but can be arbitrarily long.

##### 5.3-1 GabidulinCode

`‣ GabidulinCode`( m, w1, w2 ) | ( function )

`GabidulinCode` yields a code of length 5 . 2^m-2-1, redundancy 2m-1, minimum distance 3 and covering radius 2. w1 and w2 should be elements of GF(2^m-2).

##### 5.3-2 EnlargedGabidulinCode

`‣ EnlargedGabidulinCode`( m, w1, w2, e ) | ( function )

`EnlargedGabidulinCode` yields a code of length 7. 2^m-2-2, redundancy 2m, minimum distance 3 and covering radius 2. w1 and w2 are elements of GF(2^m-2). e is an element of GF(2^m).

##### 5.3-3 DavydovCode

`‣ DavydovCode`( r, v, ei, ej ) | ( function )

`DavydovCode` yields a code of length 2^v + 2^r-v - 3, redundancy r, minimum distance 4 and covering radius 2. v is an integer between 2 and r-2. ei and ej are elements of GF(2^v) and GF(2^r-v), respectively.

##### 5.3-4 TombakCode

`‣ TombakCode`( m, e, beta, gamma, w1, w2 ) | ( function )

`TombakCode` yields a code of length 15 ⋅ 2^m-3 - 3, redundancy 2m, minimum distance 4 and covering radius 2. e is an element of GF(2^m). beta and gamma are elements of GF(2^m-1). w1 and w2 are elements of GF(2^m-3).

##### 5.3-5 EnlargedTombakCode

`‣ EnlargedTombakCode`( m, e, beta, gamma, w1, w2, u ) | ( function )

`EnlargedTombakCode` yields a code of length 23 ⋅ 2^m-4 - 3, redundancy 2m-1, minimum distance 4 and covering radius 2. The parameters m, e, beta, gamma, w1 and w2 are defined as in `TombakCode`. u is an element of GF(2^m-1).

    gap> GabidulinCode( 4, Z(4)^0, Z(4)^1 );
    a linear [19,12,3]2 Gabidulin code (m=4) over GF(2)
    gap> EnlargedGabidulinCode( 4, Z(4)^0, Z(4)^1, Z(16)^11 );
    a linear [26,18,3]2 enlarged Gabidulin code (m=4) over GF(2)
    gap> DavydovCode( 6, 3, Z(8)^1, Z(8)^5 );
    a linear [13,7,4]2 Davydov code (r=6, v=3) over GF(2)
    gap> TombakCode( 5, Z(32)^6, Z(16)^14, Z(16)^10, Z(4)^0, Z(4)^1 );
    a linear [57,47,4]2 Tombak code (m=5) over GF(2)
    gap> EnlargedTombakCode( 6, Z(32)^6, Z(16)^14, Z(16)^10,
    > Z(4)^0, Z(4)^0, Z(32)^23 );
    a linear [89,78,4]2 enlarged Tombak code (m=6) over GF(2)

#### 5.4 Golay Codes

" The Golay code is probably the most important of all codes for both practical and theoretical reasons. " ([MS83], pg. 64). Though born in Switzerland, M. J. E. Golay (1902-1989) worked for the US Army Labs for most of his career. For more information on his life, see his obit in the June 1990 IEEE Information Society Newsletter.

##### 5.4-1 BinaryGolayCode

`‣ BinaryGolayCode`( ) | ( function )

`BinaryGolayCode` returns a binary Golay code. This is a perfect [23,12,7] code. It is also cyclic, and has generator polynomial g(x)=1+x^2+x^4+x^5+x^6+x^10+x^11. Extending it results in an extended Golay code (see `ExtendedBinaryGolayCode` (5.4-2)). There's also the ternary Golay code (see `TernaryGolayCode` (5.4-3)).

    gap> C:=BinaryGolayCode();
    a cyclic [23,12,7]3 binary Golay code over GF(2)
    gap> ExtendedBinaryGolayCode() = ExtendedCode(BinaryGolayCode());
    true
    gap> IsPerfectCode(C);
    true
    gap> IsCyclicCode(C);
    true

##### 5.4-2 ExtendedBinaryGolayCode

`‣ ExtendedBinaryGolayCode`( ) | ( function )

`ExtendedBinaryGolayCode` returns an extended binary Golay code. This is a [24,12,8] code. Puncturing in the last position results in a perfect binary Golay code (see `BinaryGolayCode` (5.4-1)). The code is self-dual.

    gap> C := ExtendedBinaryGolayCode();
    a linear [24,12,8]4 extended binary Golay code over GF(2)
    gap> IsSelfDualCode(C);
    true
    gap> P := PuncturedCode(C);
    a linear [23,12,7]3 punctured code
    gap> P = BinaryGolayCode();
    true
    gap> IsCyclicCode(C);
    false

##### 5.4-3 TernaryGolayCode

`‣ TernaryGolayCode`( ) | ( function )

`TernaryGolayCode` returns a ternary Golay code. This is a perfect [11,6,5] code. It is also cyclic, and has generator polynomial g(x)=2+x^2+2x^3+x^4+x^5. Extending it results in an extended Golay code (see `ExtendedTernaryGolayCode` (5.4-4)). There's also the binary Golay code (see `BinaryGolayCode` (5.4-1)).

    gap> C:=TernaryGolayCode();
    a cyclic [11,6,5]2 ternary Golay code over GF(3)
    gap> ExtendedTernaryGolayCode() = ExtendedCode(TernaryGolayCode());
    true
    gap> IsCyclicCode(C);
    true

##### 5.4-4 ExtendedTernaryGolayCode

`‣ ExtendedTernaryGolayCode`( ) | ( function )

`ExtendedTernaryGolayCode` returns an extended ternary Golay code. This is a [12,6,6] code. Puncturing this code results in a perfect ternary Golay code (see `TernaryGolayCode` (5.4-3)). The code is self-dual.

    gap> C := ExtendedTernaryGolayCode();
    a linear [12,6,6]3 extended ternary Golay code over GF(3)
    gap> IsSelfDualCode(C);
    true
    gap> P := PuncturedCode(C);
    a linear [11,6,5]2 punctured code
    gap> P = TernaryGolayCode();
    true
    gap> IsCyclicCode(C);
    false

#### 5.5 Generating Cyclic Codes

The elements of a cyclic code C are all multiples of a ('generator') polynomial g(x), where calculations are carried out modulo x^n-1. Therefore, as polynomials in x, the elements always have degree less than n. A cyclic code is an ideal in the ring F[x]/(x^n-1) of polynomials modulo x^n - 1. The unique monic polynomial of least degree that generates C is called the generator polynomial of C. It is a divisor of the polynomial x^n-1.

The check polynomial is the polynomial h(x) with g(x)h(x)=x^n-1. Therefore it is also a divisor of x^n-1. The check polynomial has the property that

c(x)h(x) \equiv 0 \pmod{x^n-1},

for every codeword c(x)∈ C.

The first two functions described below generate cyclic codes from a given generator or check polynomial. All cyclic codes can be constructed using these functions.

Two of the Golay codes already described are cyclic (see `BinaryGolayCode` (5.4-1) and `TernaryGolayCode` (5.4-3)). For example, the GUAVA record for a binary Golay code contains the generator polynomial:

    gap> C := BinaryGolayCode();
    a cyclic [23,12,7]3 binary Golay code over GF(2)
    gap> NamesOfComponents(C);
    [ "LeftActingDomain", "GeneratorsOfLeftOperatorAdditiveGroup", "WordLength",
      "GeneratorMat", "GeneratorPol", "Dimension", "Redundancy", "Size", "name",
      "lowerBoundMinimumDistance", "upperBoundMinimumDistance", "WeightDistribution",
      "boundsCoveringRadius", "MinimumWeightOfGenerators",
      "UpperBoundOptimalMinimumDistance" ]
    gap> C!.GeneratorPol;
    x_1^11+x_1^10+x_1^6+x_1^5+x_1^4+x_1^2+Z(2)^0

Then functions that generate cyclic codes from a prescribed set of roots of the generator polynomial are described, including the BCH codes (see `RootsCode` (5.5-3), `BCHCode` (5.5-4), `ReedSolomonCode` (5.5-5) and `QRCode` (5.5-7)).

Finally we describe the trivial codes (see `WholeSpaceCode` (5.5-11), `NullCode` (5.5-12), `RepetitionCode` (5.5-13)), and the command `CyclicCodes` which lists all cyclic codes (`CyclicCodes` (5.5-14)).

##### 5.5-1 GeneratorPolCode

`‣ GeneratorPolCode`( g, n[, name], F ) | ( function )

`GeneratorPolCode` creates a cyclic code with a generator polynomial g, word length n, over F. name can contain a short description of the code.

If g is not a divisor of x^n-1, it cannot be a generator polynomial. In that case, a code is created with generator polynomial gcd( g, x^n-1 ), i.e. the greatest common divisor of g and x^n-1. This is a valid generator polynomial that generates the ideal (g). See `Generating Cyclic Codes` (5.5).

    gap> x:= Indeterminate( GF(2) );; P:= x^2+1;
    Z(2)^0+x^2
    gap> C1 := GeneratorPolCode(P, 7, GF(2));
    a cyclic [7,6,1..2]1 code defined by generator polynomial over GF(2)
    gap> GeneratorPol( C1 );
    Z(2)^0+x
    gap> C2 := GeneratorPolCode( x+1, 7, GF(2));
    a cyclic [7,6,1..2]1 code defined by generator polynomial over GF(2)
    gap> GeneratorPol( C2 );
    Z(2)^0+x

##### 5.5-2 CheckPolCode

`‣ CheckPolCode`( h, n[, name], F ) | ( function )

`CheckPolCode` creates a cyclic code with a check polynomial h, word length n, over F. name can contain a short description of the code (as a string).

If h is not a divisor of x^n-1, it cannot be a check polynomial. In that case, a code is created with check polynomial gcd( h, x^n-1 ), i.e. the greatest common divisor of h and x^n-1. This is a valid check polynomial that yields the same elements as the ideal (h). See 5.5.

    gap>  x:= Indeterminate( GF(3) );; P:= x^2+2;
    -Z(3)^0+x_1^2
    gap> H := CheckPolCode(P, 7, GF(3));
    a cyclic [7,1,7]4 code defined by check polynomial over GF(3)
    gap> CheckPol(H);
    -Z(3)^0+x_1
    gap> Gcd(P, X(GF(3))^7-1);
    -Z(3)^0+x_1

##### 5.5-3 RootsCode

`‣ RootsCode`( n, list ) | ( function )

This is the generalization of the BCH, Reed-Solomon and quadratic residue codes (see `BCHCode` (5.5-4), `ReedSolomonCode` (5.5-5) and `QRCode` (5.5-7)). The user can give a length of the code n and a prescribed set of zeros. The argument list must be a valid list of n^th roots of unity in a splitting field GF(q^m). The resulting code will be over the field GF(q). The function will return the largest possible cyclic code for which the list list is a subset of the roots of the code. From this list, GUAVA calculates the entire set of roots.

This command can also be called with the syntax `RootsCode( n, list, q )`. In this second form, the second argument is a list of integers, ranging from 0 to n-1. The resulting code will be over a field GF(q). GUAVA calculates a primitive n^th root of unity, α, in the extension field of GF(q). It uses the set of the powers of α in the list as a prescribed set of zeros.

    gap> a := PrimitiveUnityRoot( 3, 14 );
    Z(3^6)^52
    gap> C1 := RootsCode( 14, [ a^0, a, a^3 ] );
    a cyclic [14,7,3..6]3..7 code defined by roots over GF(3)
    gap> MinimumDistance( C1 );
    4
    gap> b := PrimitiveUnityRoot( 2, 15 );
    Z(2^4)
    gap> C2 := RootsCode( 15, [ b, b^2, b^3, b^4 ] );
    a cyclic [15,7,5]3..5 code defined by roots over GF(2)
    gap> C2 = BCHCode( 15, 5, GF(2) );
    true
    gap> C3 := RootsCode( 4, [ 1, 2 ], 5 );
    a cyclic [4,2,2..3]2 code defined by roots over GF(5)
    gap> RootsOfCode( C3 );
    [ Z(5), Z(5)^2 ]
    gap> C3 = ReedSolomonCode( 4, 3 );
    true

##### 5.5-4 BCHCode

`‣ BCHCode`( n[, b], delta, F ) | ( function )

The function `BCHCode` returns a 'Bose-Chaudhuri-Hockenghem code' (or BCH code for short). This is the largest possible cyclic code of length n over field F, whose generator polynomial has zeros

a^{b},a^{b+1}, ..., a^{b+delta-2},

where a is a primitive n^th root of unity in the splitting field GF(q^m), b is an integer 0≤ b≤ n-delta+1 and m is the multiplicative order of q modulo n. (The integers {b,...,b+delta-2} typically lie in the range {1,...,n-1}.) Default value for b is 1, though the algorithm allows b=0. The length n of the code and the size q of the field must be relatively prime. The generator polynomial is equal to the least common multiple of the minimal polynomials of

a^{b}, a^{b+1}, ..., a^{b+delta-2}.

The set of zeroes of the generator polynomial is equal to the union of the sets

\{a^x\ |\ x \in C_k\},

where C_k is the k^th cyclotomic coset of q modulo n and b≤ k≤ b+delta-2 (see `CyclotomicCosets` (7.5-12)).

Special cases are b=1 (resulting codes are called 'narrow-sense' BCH codes), and n=q^m-1 (known as 'primitive' BCH codes). GUAVA calculates the largest value of d for which the BCH code with designed distance d coincides with the BCH code with designed distance delta. This distance d is called the Bose distance of the code. The true minimum distance of the code is greater than or equal to the Bose distance.

Printed are the designed distance (to be precise, the Bose distance) d, and the starting power b.

The Sugiyama decoding algorithm has been implemented for this code (see `Decode` (4.10-1)).

    gap> C1 := BCHCode( 15, 3, 5, GF(2) );
    a cyclic [15,5,7]5 BCH code, delta=7, b=1 over GF(2)
    gap> DesignedDistance( C1 );
    7
    gap> C2 := BCHCode( 23, 2, GF(2) );
    a cyclic [23,12,5..7]3 BCH code, delta=5, b=1 over GF(2)
    gap> DesignedDistance( C2 );
    5
    gap> MinimumDistance(C2);
    7

See `RootsCode` (5.5-3) for a more general construction.

##### 5.5-5 ReedSolomonCode

`‣ ReedSolomonCode`( n, d ) | ( function )

`ReedSolomonCode` returns a 'Reed-Solomon code' of length n, designed distance d. This code is a primitive narrow-sense BCH code over the field GF(q), where q=n+1. The dimension of an RS code is n-d+1. According to the Singleton bound (see `UpperBoundSingleton` (7.1-1)) the dimension cannot be greater than this, so the true minimum distance of an RS code is equal to d and the code is maximum distance separable (see `IsMDSCode` (4.3-7)).

    gap> C1 := ReedSolomonCode( 3, 2 );
    a cyclic [3,2,2]1 Reed-Solomon code over GF(4)
    gap> IsCyclicCode(C1);
    true
    gap> C2 := ReedSolomonCode( 4, 3 );
    a cyclic [4,2,3]2 Reed-Solomon code over GF(5)
    gap> RootsOfCode( C2 );
    [ Z(5), Z(5)^2 ]
    gap> IsMDSCode(C2);
    true

See `GeneralizedReedSolomonCode` (5.6-2) for a more general construction.

##### 5.5-6 ExtendedReedSolomonCode

`‣ ExtendedReedSolomonCode`( n, d ) | ( function )

`ExtendedReedSolomonCode` creates a Reed-Solomon code of length n-1 with designed distance d-1 and then returns the code which is extended by adding an overall parity-check symbol. The motivation for creating this function is calling `ExtendedCode` (6.1-1) function over a Reed-Solomon code will take considerably long time.

    gap> C := ExtendedReedSolomonCode(17, 13);
    a linear [17,5,13]9..12 extended Reed Solomon code over GF(17)
    gap> IsMDSCode(C);
    true

##### 5.5-7 QRCode

`‣ QRCode`( n, F ) | ( function )

`QRCode` returns a quadratic residue code. If F is a field GF(q), then q must be a quadratic residue modulo n. That is, an x exists with x^2 ≡ q mod n. Both n and q must be primes. Its generator polynomial is the product of the polynomials x-a^i. a is a primitive n^th root of unity, and i is an integer in the set of quadratic residues modulo n.

    gap> C1 := QRCode( 7, GF(2) );
    a cyclic [7,4,3]1 quadratic residue code over GF(2)
    gap> IsEquivalent( C1, HammingCode( 3, GF(2) ) );
    true
    gap> IsCyclicCode(C1);
    true
    gap> IsCyclicCode(HammingCode( 3, GF(2) ));
    false
    gap> C2 := QRCode( 11, GF(3) );
    a cyclic [11,6,4..5]2 quadratic residue code over GF(3)
    gap> C2 = TernaryGolayCode();
    true
    gap> Q1 := QRCode( 7, GF(2));
    a cyclic [7,4,3]1 quadratic residue code over GF(2)
    gap> P1:=AutomorphismGroup(Q1); IdGroup(P1);
    Group([ (1,2)(5,7), (2,3)(4,7), (2,4)(5,6), (3,5)(6,7), (3,7)(5,6) ])
    [ 168, 42 ]

##### 5.5-8 QQRCodeNC

`‣ QQRCodeNC`( p ) | ( function )

`QQRCodeNC` is the same as `QQRCode`, except that it uses `GeneratorMatCodeNC` instead of `GeneratorMatCode`.

##### 5.5-9 QQRCode

`‣ QQRCode`( p ) | ( function )

`QQRCode` returns a quasi-quadratic residue code, as defined by Proposition 2.2 in Bazzi-Mittel [BMd)]. The parameter p must be a prime. Its generator matrix has the block form G=(Q,N). Here Q is a p× circulant matrix whose top row is (0,x_1,...,x_p-1), where x_i=1 if and only if i is a quadratic residue mod p, and N is a p× circulant matrix whose top row is (0,y_1,...,y_p-1), where x_i+y_i=1 for all i. (In fact, this matrix can be recovered as the component `DoublyCirculant` of the code.)

    gap> C1 := QQRCode( 7);
    a linear [14,7,1..4]3..5 code defined by generator matrix over GF(2)
    gap> G1:=GeneratorMat(C1);;
    gap> Display(G1);
     . 1 1 . 1 . . . . . 1 . 1 1
     1 . 1 1 1 . . . . 1 1 1 . 1
     . . . 1 1 . 1 . 1 1 . . . 1
     . . 1 . 1 1 1 1 . 1 . . 1 1
     . . . . . . . 1 . . 1 1 1 .
     . . . . . . . . . 1 1 1 . 1
     . . . . . . . . 1 . . 1 1 1
    gap> Display(C1!.DoublyCirculant);
     . 1 1 . 1 . . . . . 1 . 1 1
     1 1 . 1 . . . . . 1 . 1 1 .
     1 . 1 . . . 1 . 1 . 1 1 . .
     . 1 . . . 1 1 1 . 1 1 . . .
     1 . . . 1 1 . . 1 1 . . . 1
     . . . 1 1 . 1 1 1 . . . 1 .
     . . 1 1 . 1 . 1 . . . 1 . 1
    gap> MinimumDistance(C1);
    4
    gap> C2 := QQRCode( 29); MinimumDistance(C2);
    a linear [58,28,1..14]8..29 code defined by generator matrix over GF(2)
    12
    gap> Aut2:=AutomorphismGroup(C2); IdGroup(Aut2);
    [ permutation group of size 812 with 4 generators ]
    [ 812, 7 ]

##### 5.5-10 FireCode

`‣ FireCode`( g, b ) | ( function )

`FireCode` constructs a (binary) Fire code. g is a primitive polynomial of degree m, and a factor of x^r-1. b an integer 0 ≤ b ≤ m not divisible by r, that determines the burst length of a single error burst that can be corrected. The argument g can be a polynomial with base ring GF(2), or a list of coefficients in GF(2). The generator polynomial of the code is defined as the product of g and x^2b-1+1.

Here is the general definition of 'Fire code', named after P. Fire, who introduced these codes in 1959 in order to correct burst errors. First, a definition. If F=GF(q) and f∈ F[x] then we say f has order e if f(x)|(x^e-1). A Fire code is a cyclic code over F with generator polynomial g(x)= (x^2t-1-1)p(x), where p(x) does not divide x^2t-1-1 and satisfies deg(p(x))≥ t. The length of such a code is the order of g(x). Non-binary Fire codes have not been implemented.

.

    gap> x:= Indeterminate( GF(2) );; G:= x^3+x^2+1;
    Z(2)^0+x^2+x^3
    gap> Factors( G );
    [ Z(2)^0+x^2+x^3 ]
    gap> C := FireCode( G, 3 );
    a cyclic [35,27,1..4]2..6 3 burst error correcting fire code over GF(2)
    gap> MinimumDistance( C );
    4     # Still it can correct bursts of length 3

##### 5.5-11 WholeSpaceCode

`‣ WholeSpaceCode`( n, F ) | ( function )

`WholeSpaceCode` returns the cyclic whole space code of length n over F. This code consists of all polynomials of degree less than n and coefficients in F.

    gap> C := WholeSpaceCode( 5, GF(3) );
    a cyclic [5,5,1]0 whole space code over GF(3)

##### 5.5-12 NullCode

`‣ NullCode`( n, F ) | ( function )

`NullCode` returns the zero-dimensional nullcode with length n over F. This code has only one word: the all zero word. It is cyclic though!

    gap> C := NullCode( 5, GF(3) );
    a cyclic [5,0,5]5 nullcode over GF(3)
    gap> AsSSortedList( C );
    [ [ 0 0 0 0 0 ] ]

##### 5.5-13 RepetitionCode

`‣ RepetitionCode`( n, F ) | ( function )

`RepetitionCode` returns the cyclic repetition code of length n over F. The code has as many elements as F, because each codeword consists of a repetition of one of these elements.

    gap> C := RepetitionCode( 3, GF(5) );
    a cyclic [3,1,3]2 repetition code over GF(5)
    gap> AsSSortedList( C );
    [ [ 0 0 0 ], [ 1 1 1 ], [ 2 2 2 ], [ 4 4 4 ], [ 3 3 3 ] ]
    gap> IsPerfectCode( C );
    false
    gap> IsMDSCode( C );
    true

##### 5.5-14 CyclicCodes

`‣ CyclicCodes`( n, F ) | ( function )

`CyclicCodes` returns a list of all cyclic codes of length n over F. It constructs all possible generator polynomials from the factors of x^n-1. Each combination of these factors yields a generator polynomial after multiplication.

    gap> CyclicCodes(3,GF(3));
    [ a cyclic [3,3,1]0 enumerated code over GF(3),
    a cyclic [3,2,1..2]1 enumerated code over GF(3),
    a cyclic [3,1,3]2 enumerated code over GF(3),
    a cyclic [3,0,3]3 enumerated code over GF(3) ]

##### 5.5-15 NrCyclicCodes

`‣ NrCyclicCodes`( n, F ) | ( function )

The function `NrCyclicCodes` calculates the number of cyclic codes of length n over field F.

    gap> NrCyclicCodes( 23, GF(2) );
    8
    gap> codelist := CyclicCodes( 23, GF(2) );
    [ a cyclic [23,23,1]0 enumerated code over GF(2),
      a cyclic [23,22,1..2]1 enumerated code over GF(2),
      a cyclic [23,11,1..8]4..7 enumerated code over GF(2),
      a cyclic [23,0,23]23 enumerated code over GF(2),
      a cyclic [23,11,1..8]4..7 enumerated code over GF(2),
      a cyclic [23,12,1..7]3 enumerated code over GF(2),
      a cyclic [23,1,23]11 enumerated code over GF(2),
      a cyclic [23,12,1..7]3 enumerated code over GF(2) ]
    gap> BinaryGolayCode() in codelist;
    true
    gap> RepetitionCode( 23, GF(2) ) in codelist;
    true
    gap> CordaroWagnerCode( 23 ) in codelist;
    false    # This code is not cyclic

##### 5.5-16 QuasiCyclicCode

`‣ QuasiCyclicCode`( G, s, F ) | ( function )

`QuasiCyclicCode( G, k, F )` generates a rate 1/m quasi-cyclic code over field F. The input G is a list of univariate polynomials and m is the cardinality of this list. Note that m must be at least 2. The input s is the size of each circulant and it may not necessarily be the same as the code dimension k, i.e. k le s.

There also exists another version, `QuasiCyclicCode( G, s )` which produces quasi-cyclic codes over F_2 only. Here the parameter s holds the same definition and the input G is a list of integers, where each integer is an octal representation of a binary univariate polynomial.

    gap> #
    gap> # This example show the case for k = s
    gap> #
    gap> L1 := PolyCodeword( Codeword("10000000000", GF(4)) );
    Z(2)^0
    gap> L2 := PolyCodeword( Codeword("12223201000", GF(4)) );
    x^7+Z(2^2)*x^5+Z(2^2)^2*x^4+Z(2^2)*x^3+Z(2^2)*x^2+Z(2^2)*x+Z(2)^0
    gap> L3 := PolyCodeword( Codeword("31111220110", GF(4)) );
    x^9+x^8+Z(2^2)*x^6+Z(2^2)*x^5+x^4+x^3+x^2+x+Z(2^2)^2
    gap> L4 := PolyCodeword( Codeword("13320333010", GF(4)) );
    x^9+Z(2^2)^2*x^7+Z(2^2)^2*x^6+Z(2^2)^2*x^5+Z(2^2)*x^3+Z(2^2)^2*x^2+Z(2^2)^2*x+\
    Z(2)^0
    gap> L5 := PolyCodeword( Codeword("20102211100", GF(4)) );
    x^8+x^7+x^6+Z(2^2)*x^5+Z(2^2)*x^4+x^2+Z(2^2)
    gap> C := QuasiCyclicCode( [L1, L2, L3, L4, L5], 11, GF(4) );
    a linear [55,11,1..32]24..41 quasi-cyclic code over GF(4)
    gap> MinimumDistance(C);
    29
    gap> Display(C);
    a linear [55,11,29]24..41 quasi-cyclic code over GF(4)
    gap> #
    gap> # This example show the case for k < s
    gap> #
    gap> L1 := PolyCodeword( Codeword("02212201220120211002000",GF(3)) );
    -x^19+x^16+x^15-x^14-x^12+x^11-x^9-x^8+x^7-x^5-x^4+x^3-x^2-x
    gap> L2 := PolyCodeword( Codeword("00221100200120220001110",GF(3)) );
    x^21+x^20+x^19-x^15-x^14-x^12+x^11-x^8+x^5+x^4-x^3-x^2
    gap> L3 := PolyCodeword( Codeword("22021011202221111020021",GF(3)) );
    x^22-x^21-x^18+x^16+x^15+x^14+x^13-x^12-x^11-x^10-x^8+x^7+x^6+x^4-x^3-x-Z(3)^0
    gap> C := QuasiCyclicCode( [L1, L2, L3], 23, GF(3) );
    a linear [69,12,1..37]27..46 quasi-cyclic code over GF(3)
    gap> MinimumDistance(C);
    34
    gap> Display(C);
    a linear [69,12,34]27..46 quasi-cyclic code over GF(3)
    gap> #
    gap> # This example show the binary case using octal representation
    gap> #
    gap> L1 := 001;;   # 0 000 001
    gap> L2 := 013;;   # 0 001 011
    gap> L3 := 015;;   # 0 001 101
    gap> L4 := 077;;   # 0 111 111
    gap> C := QuasiCyclicCode( [L1, L2, L3, L4], 7 );
    a linear [28,7,1..12]8..14 quasi-cyclic code over GF(2)
    gap> MinimumDistance(C);
    12
    gap> Display(C);
    a linear [28,7,12]8..14 quasi-cyclic code over GF(2)

##### 5.5-17 CyclicMDSCode

`‣ CyclicMDSCode`( q, m, k ) | ( function )

Given the input parameters q, m and k, this function returns a [q^m + 1, k, q^m - k + 2] cyclic MDS code over GF(q^m). If q^m is even, any value of k can be used, otherwise only odd value of k is accepted.

    gap> C:=CyclicMDSCode(2,6,24);
    a cyclic [65,24,42]31..41 MDS code over GF(64)
    gap> IsMDSCode(C);
    true
    gap> C:=CyclicMDSCode(5,3,77);
    a cyclic [126,77,50]35..49 MDS code over GF(125)
    gap> IsMDSCode(C);
    true
    gap> C:=CyclicMDSCode(3,3,25);
    a cyclic [28,25,4]2..3 MDS code over GF(27)
    gap> GeneratorPol(C);
    x^3+Z(3^3)^7*x^2+Z(3^3)^20*x-Z(3)^0
    gap>

##### 5.5-18 FourNegacirculantSelfDualCode

`‣ FourNegacirculantSelfDualCode`( ax, bx, k ) | ( function )

A four-negacirculant self-dual code has a generator matrix G of the the following form

        -                    -
        |        |  A  |  B  |
    G = |  I_2k  |-----+-----|
        |        | -B^T| A^T |
        -                    -

where AA^T + BB^T = -I_k and A, B and their transposed are all k × k negacirculant matrices. The generator matrix G returns a [2k, k, d]_q self-dual code over GF(q). For discussion on four-negacirculant self-dual codes, refer to [HHKK07].

The input parameters ax and bx are the defining polynomials over GF(q) of negacirculant matrices A and B respectively. The last parameter k is the dimension of the code.

    gap> ax:=PolyCodeword(Codeword("1200200", GF(3)));
    -x_1^4-x_1+Z(3)^0
    gap> bx:=PolyCodeword(Codeword("2020221", GF(3)));
    x_1^6-x_1^5-x_1^4-x_1^2-Z(3)^0
    gap> C:=FourNegacirculantSelfDualCode(ax, bx, 14);;
    gap> MinimumDistance(C);;
    gap> CoveringRadius(C);;
    gap> IsSelfDualCode(C);
    true
    gap> Display(C);
    a linear [28,14,9]7 four-negacirculant self-dual code over GF(3)
    gap> Display( GeneratorMat(C) );
     1 . . . . . . . . . . . . . 1 2 . . 2 . . 2 . 2 . 2 2 1
     . 1 . . . . . . . . . . . . . 1 2 . . 2 . 2 2 . 2 . 2 2
     . . 1 . . . . . . . . . . . . . 1 2 . . 2 1 2 2 . 2 . 2
     . . . 1 . . . . . . . . . . 1 . . 1 2 . . 1 1 2 2 . 2 .
     . . . . 1 . . . . . . . . . . 1 . . 1 2 . . 1 1 2 2 . 2
     . . . . . 1 . . . . . . . . . . 1 . . 1 2 1 . 1 1 2 2 .
     . . . . . . 1 . . . . . . . 1 . . 1 . . 1 . 1 . 1 1 2 2
     . . . . . . . 1 . . . . . . 1 1 2 2 . 2 . 1 . . 1 . . 1
     . . . . . . . . 1 . . . . . . 1 1 2 2 . 2 2 1 . . 1 . .
     . . . . . . . . . 1 . . . . 1 . 1 1 2 2 . . 2 1 . . 1 .
     . . . . . . . . . . 1 . . . . 1 . 1 1 2 2 . . 2 1 . . 1
     . . . . . . . . . . . 1 . . 1 . 1 . 1 1 2 2 . . 2 1 . .
     . . . . . . . . . . . . 1 . 1 1 . 1 . 1 1 . 2 . . 2 1 .
     . . . . . . . . . . . . . 1 2 1 1 . 1 . 1 . . 2 . . 2 1
    gap> ax:=PolyCodeword(Codeword("013131000", GF(7)));
    x_1^5+Z(7)*x_1^4+x_1^3+Z(7)*x_1^2+x_1
    gap> bx:=PolyCodeword(Codeword("425435030", GF(7)));
    Z(7)*x_1^7+Z(7)^5*x_1^5+Z(7)*x_1^4+Z(7)^4*x_1^3+Z(7)^5*x_1^2+Z(7)^2*x_1+Z(7)^4
    gap> C:=FourNegacirculantSelfDualCodeNC(ax, bx, 18);
    a linear [36,18,1..13]0..36 four-negacirculant self-dual code over GF(7)
    gap> IsSelfDualCode(C);
    true

##### 5.5-19 FourNegacirculantSelfDualCodeNC

`‣ FourNegacirculantSelfDualCodeNC`( ax, bx, k ) | ( function )

This function is the same as `FourNegacirculantSelfDualCode`, except this version is faster as it does not estimate the minimum distance and covering radius of the code.

#### 5.6 Evaluation Codes

##### 5.6-1 EvaluationCode

`‣ EvaluationCode`( P, L, R ) | ( function )

Input: F is a finite field, L is a list of rational functions in R=F[x_1,...,x_r], P is a list of n points in F^r at which all of the functions in L are defined.
Output: The 'evaluation code' C, which is the image of the evalation map

Eval_P:span(L)\rightarrow F^n,

given by flongmapsto (f(p_1),...,f(p_n)), where P={p_1,...,p_n} and f ∈ L. The generator matrix of C is G=(f_i(p_j))_f_i∈ L,p_j∈ P.

This command returns a "record" object `C` with several extra components (type `NamesOfComponents(C)` to see them all): `C!.EvaluationMat` (not the same as the generator matrix in general), `C!.points` (namely P), `C!.basis` (namely L), and `C!.ring` (namely R).

    gap> F:=GF(11);
    GF(11)
    gap> R := PolynomialRing(F,2);;
    gap> indets := IndeterminatesOfPolynomialRing(R);;
    gap> x:=indets[1];; y:=indets[2];;
    gap> L:=[x^2*y,x*y,x^5,x^4,x^3,x^2,x,x^0];;
    gap> Pts:=[ [ Z(11)^9, Z(11) ], [ Z(11)^8, Z(11) ], [ Z(11)^7, 0*Z(11) ],
       [ Z(11)^6, 0*Z(11) ], [ Z(11)^5, 0*Z(11) ], [ Z(11)^4, 0*Z(11) ],
       [ Z(11)^3, Z(11) ], [ Z(11)^2, 0*Z(11) ], [ Z(11), 0*Z(11) ],
       [ Z(11)^0, 0*Z(11) ], [ 0*Z(11), Z(11) ] ];;
    gap> C:=EvaluationCode(Pts,L,R);
    a linear [11,8,1..3]2..3  evaluation code over GF(11)
    gap> MinimumDistance(C);
    3

##### 5.6-2 GeneralizedReedSolomonCode

`‣ GeneralizedReedSolomonCode`( P, k, R ) | ( function )

Input: R=F[x], where F is a finite field, k is a positive integer, P is a list of n points in F.
Output: The C which is the image of the evaluation map

Eval_P:F[x]_k\rightarrow F^n,

given by flongmapsto (f(p_1),...,f(p_n)), where P={p_1,...,p_n}⊂ F and f ranges over the space F[x]_k of all polynomials of degree less than k.

This command returns a "record" object `C` with several extra components (type `NamesOfComponents(C)` to see them all): `C!.points` (namely P), `C!.degree` (namely k), and `C!.ring` (namely R).

This code can be decoded using `Decodeword`, which applies the special decoder method (the interpolation method), or using `GeneralizedReedSolomonDecoderGao` which applies an algorithm of S. Gao (see `GeneralizedReedSolomonDecoderGao` (4.10-3)). This code has a special decoder record which implements the interpolation algorithm described in section 5.2 of Justesen and Hoholdt [JH04]. See `Decode` (4.10-1) and `Decodeword` (4.10-2) for more details.

The weighted version has implemented with the option `GeneralizedReedSolomonCode(P,k,R,wts)`, where wts = [v_1, ..., v_n] is a sequence of n non-zero elements from the base field F of R. See also the generalized Reed--Solomon code GRS_k(P, V) described in [MS83], p.303.

The list-decoding algorithm of Sudan-Guraswami (described in section 12.1 of [JH04]) has been implemented for generalized Reed-Solomon codes. See `GeneralizedReedSolomonListDecoder` (4.10-4).

    gap> R:=PolynomialRing(GF(11),["t"]);
    GF(11)[t]
    gap> P:=List([1,3,4,5,7],i->Z(11)^i);
    [ Z(11), Z(11)^3, Z(11)^4, Z(11)^5, Z(11)^7 ]
    gap> C:=GeneralizedReedSolomonCode(P,3,R);
    a linear [5,3,1..3]2  generalized Reed-Solomon code over GF(11)
    gap> MinimumDistance(C);
    3
    gap> V:=[Z(11)^0,Z(11)^0,Z(11)^0,Z(11)^0,Z(11)];
    [ Z(11)^0, Z(11)^0, Z(11)^0, Z(11)^0, Z(11) ]
    gap> C:=GeneralizedReedSolomonCode(P,3,R,V);
    a linear [5,3,1..3]2  weighted generalized Reed-Solomon code over GF(11)
    gap> MinimumDistance(C);
    3

See `EvaluationCode` (5.6-1) for a more general construction.

##### 5.6-3 GeneralizedReedMullerCode

`‣ GeneralizedReedMullerCode`( Pts, r, F ) | ( function )

`GeneralizedReedMullerCode` returns a 'Reed-Muller code' C with length |Pts| and order r. One considers (a) a basis of monomials for the vector space over F=GF(q) of all polynomials in F[x_1,...,x_d] of degree at most r, and (b) a set Pts of points in F^d. The generator matrix of the associated Reed-Muller code C is G=(f(p))_f∈ B,p ∈ Pts. This code C is constructed using the command `GeneralizedReedMullerCode(Pts,r,F)`. When Pts is the set of all q^d points in F^d then the command `GeneralizedReedMuller(d,r,F)` yields the code. When Pts is the set of all (q-1)^d points with no coordinate equal to 0 then this is can be constructed using the `ToricCode` command (as a special case).

This command returns a "record" object `C` with several extra components (type `NamesOfComponents(C)` to see them all): `C!.points` (namely Pts) and `C!.degree` (namely r).

    gap> Pts:=ToricPoints(2,GF(5));
    [ [ Z(5)^0, Z(5)^0 ], [ Z(5)^0, Z(5) ], [ Z(5)^0, Z(5)^2 ], [ Z(5)^0, Z(5)^3 ],
      [ Z(5), Z(5)^0 ], [ Z(5), Z(5) ], [ Z(5), Z(5)^2 ], [ Z(5), Z(5)^3 ],
      [ Z(5)^2, Z(5)^0 ], [ Z(5)^2, Z(5) ], [ Z(5)^2, Z(5)^2 ], [ Z(5)^2, Z(5)^3 ],
      [ Z(5)^3, Z(5)^0 ], [ Z(5)^3, Z(5) ], [ Z(5)^3, Z(5)^2 ], [ Z(5)^3, Z(5)^3 ] ]
    gap> C:=GeneralizedReedMullerCode(Pts,2,GF(5));
    a linear [16,6,1..11]6..10  generalized Reed-Muller code over GF(5)

See `EvaluationCode` (5.6-1) for a more general construction.

##### 5.6-4 ToricPoints

`‣ ToricPoints`( n, F ) | ( function )

`ToricPoints(n,F)` returns the points in (F^×)^n.

    gap> ToricPoints(2,GF(5));
    [ [ Z(5)^0, Z(5)^0 ], [ Z(5)^0, Z(5) ], [ Z(5)^0, Z(5)^2 ],
      [ Z(5)^0, Z(5)^3 ], [ Z(5), Z(5)^0 ], [ Z(5), Z(5) ], [ Z(5), Z(5)^2 ],
      [ Z(5), Z(5)^3 ], [ Z(5)^2, Z(5)^0 ], [ Z(5)^2, Z(5) ], [ Z(5)^2, Z(5)^2 ],
      [ Z(5)^2, Z(5)^3 ], [ Z(5)^3, Z(5)^0 ], [ Z(5)^3, Z(5) ],
      [ Z(5)^3, Z(5)^2 ], [ Z(5)^3, Z(5)^3 ] ]

##### 5.6-5 ToricCode

`‣ ToricCode`( L, F ) | ( function )

This function returns the toric codes as in D. Joyner [Joy04] (see also J. P. Hansen [Han99]). This is a truncated (generalized) Reed-Muller code. Here L is a list of integral vectors and F is the finite field. The size of F must be different from 2.

This command returns a record object `C` with an extra component (type `NamesOfComponents(C)` to see them all): `C!.exponents` (namely L).

    gap> C:=ToricCode([[1,0],[3,4]],GF(3));
    a linear [4,1,4]2 toric code over GF(3)
    gap> Display(GeneratorMat(C));
     1 1 2 2
    gap> Elements(C);
    [ [ 0 0 0 0 ], [ 1 1 2 2 ], [ 2 2 1 1 ] ]

See `EvaluationCode` (5.6-1) for a more general construction.

#### 5.7 Algebraic geometric codes

Certain GUAVA functions related to algebraic geometric codes are described in this section.

##### 5.7-1 AffineCurve

`‣ AffineCurve`( poly, ring ) | ( function )

This function simply defines the data structure of an affine plane curve. In GUAVA, an affine curve is a record crv having two components: a polynomial poly, accessed in GUAVA by crv.polynomial, and a polynomial ring over a field F in two variables ring, accessed in GUAVA by crv.ring, containing poly. You use this function to define a curve in GUAVA.

For example, for the ring, one could take Q}[x,y], and for the polynomial one could take f(x,y)=x^2+y^2-1. For the affine line, simply taking Q}[x,y] for the ring and f(x,y)=y for the polynomial.

(Not sure if F neeeds to be a field in fact ...)

To compute its degree, simply use the `DegreeMultivariatePolynomial` (7.6-2) command.

    gap>
    gap> F:=GF(11);;
    gap> R2:=PolynomialRing(F,2);
    PolynomialRing(..., [ x_1, x_2 ])
    gap> vars:=IndeterminatesOfPolynomialRing(R2);;
    gap> x:=vars[1];; y:=vars[2];;
    gap> poly:=y;; crvP1:=AffineCurve(poly,R2);
    rec( ring := PolynomialRing(..., [ x_1, x_2 ]), polynomial := x_2 )
    gap> degree_crv:=DegreeMultivariatePolynomial(poly,R2);
    1
    gap> poly:=y^2-x*(x^2-1);; ell_crv:=AffineCurve(poly,R2);
    rec( ring := PolynomialRing(..., [ x_1, x_2 ]), polynomial := -x_1^3+x_2^2+x_1 )
    gap> degree_crv:=DegreeMultivariatePolynomial(poly,R2);
    3
    gap> poly:=x^2+y^2-1;; circle:=AffineCurve(poly,R2);
    rec( ring := PolynomialRing(..., [ x_1, x_2 ]), polynomial := x_1^2+x_2^2-Z(11)^0 )
    gap> degree_crv:=DegreeMultivariatePolynomial(poly,R2);
    2
    gap> q:=3;;
    gap> F:=GF(q^2);;
    gap> R:=PolynomialRing(F,2);;
    gap> vars:=IndeterminatesOfPolynomialRing(R);
    [ x_1, x_2 ]
    gap> x:=vars[1];
    x_1
    gap> y:=vars[2];
    x_2
    gap> crv:=AffineCurve(y^q+y-x^(q+1),R);
    rec( ring := PolynomialRing(..., [ x_1, x_2 ]), polynomial := -x_1^4+x_2^3+x_2 )
    gap>

In GAP, a point on a curve defined by f(x,y)=0 is simply a list [a,b] of elements of F satisfying this polynomial equation.

##### 5.7-2 AffinePointsOnCurve

`‣ AffinePointsOnCurve`( f, R, E ) | ( function )

`AffinePointsOnCurve(f,R,E)` returns the points (x,y) ∈ E^2 satisying f(x,y)=0, where f is an element of R=F[x,y].

    gap> F:=GF(11);;
    gap> R := PolynomialRing(F,["x","y"]);
    PolynomialRing(..., [ x, y ])
    gap> indets := IndeterminatesOfPolynomialRing(R);;
    gap> x:=indets[1];; y:=indets[2];;
    gap> P:=AffinePointsOnCurve(y^2-x^11+x,R,F);
    [ [ Z(11)^9, 0*Z(11) ], [ Z(11)^8, 0*Z(11) ], [ Z(11)^7, 0*Z(11) ],
      [ Z(11)^6, 0*Z(11) ], [ Z(11)^5, 0*Z(11) ], [ Z(11)^4, 0*Z(11) ],
      [ Z(11)^3, 0*Z(11) ], [ Z(11)^2, 0*Z(11) ], [ Z(11), 0*Z(11) ],
      [ Z(11)^0, 0*Z(11) ], [ 0*Z(11), 0*Z(11) ] ]

##### 5.7-3 GenusCurve

`‣ GenusCurve`( crv ) | ( function )

If crv represents f(x,y)=0, where f is a polynomial of degree d, then this function simply returns (d-1)(d-2)/2. At the present, the function does not check if the curve is singular (in which case the result may be false).

    gap> q:=4;;
    gap> F:=GF(q^2);;
    gap> a:=X(F);;
    gap> R1:=PolynomialRing(F,[a]);;
    gap> var1:=IndeterminatesOfPolynomialRing(R1);;
    gap> b:=X(F);;
    gap> R2:=PolynomialRing(F,[a,b]);;
    gap> var2:=IndeterminatesOfPolynomialRing(R2);;
    gap> crv:=AffineCurve(b^q+b-a^(q+1),R2);;
    gap> crv:=AffineCurve(b^q+b-a^(q+1),R2);
    rec( ring := PolynomialRing(..., [ x_1, x_1 ]), polynomial := x_1^5+x_1^4+x_1 )
    gap> GenusCurve(crv);
    36

##### 5.7-4 GOrbitPoint

`‣ GOrbitPoint` ( G, P ) | ( function )

P must be a point in projective space P^n(F), G must be a finite subgroup of GL(n+1,F), This function returns all (representatives of projective) points in the orbit G⋅ P.

The example below computes the orbit of the automorphism group on the Klein quartic over the field GF(43) on the ``point at infinity''.

    gap> R:= PolynomialRing( GF(43), 3 );;
    gap> vars:= IndeterminatesOfPolynomialRing(R);;
    gap> x:= vars[1];; y:= vars[2];; z:= vars[3];;
    gap> zz:=Z(43)^6;
    Z(43)^6
    gap> zzz:=Z(43);
    Z(43)
    gap> rho1:=zz^0*[[zz^4,0,0],[0,zz^2,0],[0,0,zz]];
    [ [ Z(43)^24, 0*Z(43), 0*Z(43) ],
    [ 0*Z(43), Z(43)^12, 0*Z(43) ],
    [ 0*Z(43), 0*Z(43), Z(43)^6 ] ]
    gap> rho2:=zz^0*[[0,1,0],[0,0,1],[1,0,0]];
    [ [ 0*Z(43), Z(43)^0, 0*Z(43) ],
    [ 0*Z(43), 0*Z(43), Z(43)^0 ],
    [ Z(43)^0, 0*Z(43), 0*Z(43) ] ]
    gap> rho3:=(-1)*[[(zz-zz^6 )/zzz^7,( zz^2-zz^5 )/ zzz^7, ( zz^4-zz^3 )/ zzz^7],
    >             [( zz^2-zz^5 )/ zzz^7, ( zz^4-zz^3 )/ zzz^7, ( zz-zz^6 )/ zzz^7],
    >             [( zz^4-zz^3 )/ zzz^7, ( zz-zz^6 )/ zzz^7, ( zz^2-zz^5 )/ zzz^7]];
    [ [ Z(43)^9, Z(43)^28, Z(43)^12 ],
    [ Z(43)^28, Z(43)^12, Z(43)^9 ],
    [ Z(43)^12, Z(43)^9, Z(43)^28 ] ]
    gap> G:=Group([rho1,rho2,rho3]);; #PSL(2,7)
    gap> Size(G);
    168
    gap> P:=[1,0,0]*zzz^0;
    [ Z(43)^0, 0*Z(43), 0*Z(43) ]
    gap> O:=GOrbitPoint(G,P);
    [ [ Z(43)^0, 0*Z(43), 0*Z(43) ], [ 0*Z(43), Z(43)^0, 0*Z(43) ],
    [ 0*Z(43), 0*Z(43), Z(43)^0 ], [ Z(43)^0, Z(43)^39, Z(43)^16 ],
    [ Z(43)^0, Z(43)^33, Z(43)^28 ], [ Z(43)^0, Z(43)^27, Z(43)^40 ],
    [ Z(43)^0, Z(43)^21, Z(43)^10 ], [ Z(43)^0, Z(43)^15, Z(43)^22 ],
    [ Z(43)^0, Z(43)^9, Z(43)^34 ], [ Z(43)^0, Z(43)^3, Z(43)^4 ],
    [ Z(43)^3, Z(43)^22, Z(43)^6 ], [ Z(43)^3, Z(43)^16, Z(43)^18 ],
    [ Z(43)^3, Z(43)^10, Z(43)^30 ], [ Z(43)^3, Z(43)^4, Z(43)^0 ],
    [ Z(43)^3, Z(43)^40, Z(43)^12 ], [ Z(43)^3, Z(43)^34, Z(43)^24 ],
    [ Z(43)^3, Z(43)^28, Z(43)^36 ], [ Z(43)^4, Z(43)^30, Z(43)^27 ],
    [ Z(43)^4, Z(43)^24, Z(43)^39 ], [ Z(43)^4, Z(43)^18, Z(43)^9 ],
    [ Z(43)^4, Z(43)^12, Z(43)^21 ], [ Z(43)^4, Z(43)^6, Z(43)^33 ],
    [ Z(43)^4, Z(43)^0, Z(43)^3 ], [ Z(43)^4, Z(43)^36, Z(43)^15 ] ]
    gap> Length(O);
    24

Informally, a divisor on a curve is a formal integer linear combination of points on the curve, D=m_1P_1+...+m_kP_k, where the m_i are integers (the ``multiplicity'' of P_i in D) and P_i are (F-rational) points on the affine plane curve. In other words, a divisor is an element of the free abelian group generated by the F-rational affine points on the curve. The support of a divisor D is simply the set of points which occurs in the sum defining D with non-zero ``multiplicity''. The data structure for a divisor on an affine plane curve is a record having the following components:

- the coefficients (the integer weights of the points in the support),

- the support,

- the curve, itself a record which has components: polynomial and polynomial ring.

##### 5.7-5 DivisorOnAffineCurve

`‣ DivisorOnAffineCurve`( cdiv, sdiv, crv ) | ( function )

This is the command you use to define a divisor in GUAVA. Of course, crv is the curve on which the divisor lives, cdiv is the list of coefficients (or ``multiplicities''), sdiv is the list of points on crv in the support.

    gap> q:=5;
    5
    gap> F:=GF(q);
    GF(5)
    gap> R:=PolynomialRing(F,2);;
    gap> vars:=IndeterminatesOfPolynomialRing(R);
    [ x_1, x_2 ]
    gap> x:=vars[1];
    x_1
    gap> y:=vars[2];
    x_2
    gap> crv:=AffineCurve(y^3-x^3-x-1,R);
    rec( ring := PolynomialRing(..., [ x_1, x_2 ]),
         polynomial := -x_1^3+x_2^3-x_1-Z(5)^0 )
    gap> Pts:=AffinePointsOnCurve(crv,R,F);;
    gap> supp:=[Pts[1],Pts[2]];
    [ [ 0*Z(5), Z(5)^0 ], [ Z(5)^0, Z(5) ] ]
    gap> D:=DivisorOnAffineCurve([1,-1],supp,crv);
    rec( coeffs := [ 1, -1 ],
         support := [ [ 0*Z(5), Z(5)^0 ], [ Z(5)^0, Z(5) ] ],
         curve := rec( ring := PolynomialRing(..., [ x_1, x_2 ]),
                       polynomial := -x_1^3+x_2^3-x_1-Z(5)^0 ) )

##### 5.7-6 DivisorAddition

`‣ DivisorAddition` ( D1, D2 ) | ( function )

If D_1=m_1P_1+...+m_kP_k and D_2=n_1P_1+...+n_kP_k are divisors then D_1+D_2=(m_1+n_1)P_1+...+(m_k+n_k)P_k.

##### 5.7-7 DivisorDegree

`‣ DivisorDegree` ( D ) | ( function )

If D=m_1P_1+...+m_kP_k is a divisor then the degree is m_1+...+m_k.

##### 5.7-8 DivisorNegate

`‣ DivisorNegate` ( D ) | ( function )

Self-explanatory.

##### 5.7-9 DivisorIsZero

`‣ DivisorIsZero` ( D ) | ( function )

Self-explanatory.

##### 5.7-10 DivisorsEqual

`‣ DivisorsEqual` ( D1, D2 ) | ( function )

Self-explanatory.

##### 5.7-11 DivisorGCD

`‣ DivisorGCD` ( D1, D2 ) | ( function )

If m=p_1^e_1...p_k^e_k and n=p_1^f_1...p_k^f_k are two integers then their greatest common divisor is GCD(m,n)=p_1^min(e_1,f_1)...p_k^min(e_k,f_k). A similar definition works for two divisors on a curve. If D_1=e_1P_1+...+e_kP_k and D_2n=f_1P_1+...+f_kP_k are two divisors on a curve then their greatest common divisor is GCD(m,n)=min(e_1,f_1)P_1+...+min(e_k,f_k)P_k. This function computes this quantity.

##### 5.7-12 DivisorLCM

`‣ DivisorLCM` ( D1, D2 ) | ( function )

If m=p_1^e_1...p_k^e_k and n=p_1^f_1...p_k^f_k are two integers then their least common multiple is LCM(m,n)=p_1^max(e_1,f_1)...p_k^max(e_k,f_k). A similar definition works for two divisors on a curve. If D_1=e_1P_1+...+e_kP_k and D_2=f_1P_1+...+f_kP_k are two divisors on a curve then their least common multiple is LCM(m,n)=max(e_1,f_1)P_1+...+max(e_k,f_k)P_k. This function computes this quantity.

    gap> F:=GF(11);
    GF(11)
    gap> R1:=PolynomialRing(F,["a"]);;
    gap> var1:=IndeterminatesOfPolynomialRing(R1);; a:=var1[1];;
    gap> b:=X(F,"b",var1);
    b
    gap> var2:=Concatenation(var1,[b]);
    [ a, b ]
    gap> R2:=PolynomialRing(F,var2);
    PolynomialRing(..., [ a, b ])
    gap> crvP1:=AffineCurve(b,R2);
    rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b )
    gap> div1:=DivisorOnAffineCurve([1,2,3,4],[Z(11)^2,Z(11)^3,Z(11)^7,Z(11)],crvP1);
    rec( coeffs := [ 1, 2, 3, 4 ],
         support := [ Z(11)^2, Z(11)^3, Z(11)^7, Z(11) ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> DivisorDegree(div1);
    10
    gap> div2:=DivisorOnAffineCurve([1,2,3,4],[Z(11),Z(11)^2,Z(11)^3,Z(11)^4],crvP1);
    rec( coeffs := [ 1, 2, 3, 4 ],
         support := [ Z(11), Z(11)^2, Z(11)^3, Z(11)^4 ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> DivisorDegree(div2);
    10
    gap> div3:=DivisorAddition(div1,div2);
    rec( coeffs := [ 5, 3, 5, 4, 3 ],
         support := [ Z(11), Z(11)^2, Z(11)^3, Z(11)^4, Z(11)^7 ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> DivisorDegree(div3);
    20
    gap> DivisorIsEffective(div1);
    true
    gap> DivisorIsEffective(div2);
    true
    gap>
    gap> ndiv1:=DivisorNegate(div1);
    rec( coeffs := [ -1, -2, -3, -4 ],
         support := [ Z(11)^2, Z(11)^3, Z(11)^7, Z(11) ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> zdiv:=DivisorAddition(div1,ndiv1);
    rec( coeffs := [ 0, 0, 0, 0 ],
         support := [ Z(11), Z(11)^2, Z(11)^3, Z(11)^7 ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> DivisorIsZero(zdiv);
    true
    gap> div_gcd:=DivisorGCD(div1,div2);
    rec( coeffs := [ 1, 1, 2, 0, 0 ],
         support := [ Z(11), Z(11)^2, Z(11)^3, Z(11)^4, Z(11)^7 ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> div_lcm:=DivisorLCM(div1,div2);
    rec( coeffs := [ 4, 2, 3, 4, 3 ],
         support := [ Z(11), Z(11)^2, Z(11)^3, Z(11)^4, Z(11)^7 ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> DivisorDegree(div_gcd);
    4
    gap> DivisorDegree(div_lcm);
    16
    gap> DivisorEqual(div3,DivisorAddition(div_gcd,div_lcm));
    true

Let G denote a finite subgroup of PGL(2,F) and let D denote a divisor on the projective line P^1(F). If G leaves D unchanged (it may permute the points in the support of D but must preserve their sum in D) then the Riemann-Roch space L(D) is a G-module. The commands in this section help explore the G-module structure of L(D) in the case then the ground field F is finite.

##### 5.7-13 RiemannRochSpaceBasisFunctionP1

`‣ RiemannRochSpaceBasisFunctionP1` ( P, k, R2 ) | ( function )

Input: R2 is a polynomial ring in two variables, say F[x,y]; P is an element of the base field, say F; k is an integer. Output: 1/(x-P)^k

##### 5.7-14 DivisorOfRationalFunctionP1

`‣ DivisorOfRationalFunctionP1` ( f, R ) | ( function )

Here R = F[x,y] is a polynomial ring in the variables x,y and f is a rational function of x. Simply returns the principal divisor on P}^1 associated to f.

    gap> F:=GF(11);
    GF(11)
    gap> R1:=PolynomialRing(F,["a"]);;
    gap> var1:=IndeterminatesOfPolynomialRing(R1);; a:=var1[1];;
    gap> b:=X(F,"b",var1);
    b
    gap> var2:=Concatenation(var1,[b]);
    [ a, b ]
    gap> R2:=PolynomialRing(F,var2);
    PolynomialRing(..., [ a, b ])
    gap> pt:=Z(11);
    Z(11)
    gap> f:=RiemannRochSpaceBasisFunctionP1(pt,2,R2);
    (Z(11)^0)/(a^2+Z(11)^7*a+Z(11)^2)
    gap> Df:=DivisorOfRationalFunctionP1(f,R2);
    rec( coeffs := [ -2 ], support := [ Z(11) ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := a )
       )
    gap> Df.support;
    [ Z(11) ]
    gap> F:=GF(11);;
    gap> R:=PolynomialRing(F,2);;
    gap> vars:=IndeterminatesOfPolynomialRing(R);;
    gap> a:=vars[1];;
    gap> b:=vars[2];;
    gap> f:=(a^4+Z(11)^6*a^3-a^2+Z(11)^7*a+Z(11)^0)/(a^4+Z(11)*a^2+Z(11)^7*a+Z(11));;
    gap> divf:=DivisorOfRationalFunctionP1(f,R);
    rec( coeffs := [ 3, 1 ], support := [ Z(11), Z(11)^7 ],
      curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := a ) )
    gap> denf:=DenominatorOfRationalFunction(f); RootsOfUPol(denf);
    a^4+Z(11)*a^2+Z(11)^7*a+Z(11)
    [  ]
    gap> numf:=NumeratorOfRationalFunction(f); RootsOfUPol(numf);
    a^4+Z(11)^6*a^3-a^2+Z(11)^7*a+Z(11)^0
    [ Z(11)^7, Z(11), Z(11), Z(11) ]

##### 5.7-15 RiemannRochSpaceBasisP1

`‣ RiemannRochSpaceBasisP1` ( D ) | ( function )

This returns the basis of the Riemann-Roch space L(D) associated to the divisor D on the projective line P}^1.

    gap> F:=GF(11);
    GF(11)
    gap> R1:=PolynomialRing(F,["a"]);;
    gap> var1:=IndeterminatesOfPolynomialRing(R1);; a:=var1[1];;
    gap> b:=X(F,"b",var1);
    b
    gap> var2:=Concatenation(var1,[b]);
    [ a, b ]
    gap> R2:=PolynomialRing(F,var2);
    PolynomialRing(..., [ a, b ])
    gap> crvP1:=AffineCurve(b,R2);
    rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b )
    gap> D:=DivisorOnAffineCurve([1,2,3,4],[Z(11)^2,Z(11)^3,Z(11)^7,Z(11)],crvP1);
    rec( coeffs := [ 1, 2, 3, 4 ],
         support := [ Z(11)^2, Z(11)^3, Z(11)^7, Z(11) ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> B:=RiemannRochSpaceBasisP1(D);
    [ Z(11)^0, (Z(11)^0)/(a+Z(11)^7), (Z(11)^0)/(a+Z(11)^8),
    (Z(11)^0)/(a^2+Z(11)^9*a+Z(11)^6), (Z(11)^0)/(a+Z(11)^2),
    (Z(11)^0)/(a^2+Z(11)^3*a+Z(11)^4), (Z(11)^0)/(a^3+a^2+Z(11)^2*a+Z(11)^6),
      (Z(11)^0)/(a+Z(11)^6), (Z(11)^0)/(a^2+Z(11)^7*a+Z(11)^2),
    (Z(11)^0)/(a^3+Z(11)^4*a^2+a+Z(11)^8),
    (Z(11)^0)/(a^4+Z(11)^8*a^3+Z(11)*a^2+a+Z(11)^4) ]
    gap> DivisorOfRationalFunctionP1(B[1],R2).support;
    [  ]
    gap> DivisorOfRationalFunctionP1(B[2],R2).support;
    [ Z(11)^2 ]
    gap> DivisorOfRationalFunctionP1(B[3],R2).support;
    [ Z(11)^3 ]
    gap> DivisorOfRationalFunctionP1(B[4],R2).support;
    [ Z(11)^3 ]
    gap> DivisorOfRationalFunctionP1(B[5],R2).support;
    [ Z(11)^7 ]
    gap> DivisorOfRationalFunctionP1(B[6],R2).support;
    [ Z(11)^7 ]
    gap> DivisorOfRationalFunctionP1(B[7],R2).support;
    [ Z(11)^7 ]
    gap> DivisorOfRationalFunctionP1(B[8],R2).support;
    [ Z(11) ]
    gap> DivisorOfRationalFunctionP1(B[9],R2).support;
    [ Z(11) ]
    gap> DivisorOfRationalFunctionP1(B[10],R2).support;
    [ Z(11) ]
    gap> DivisorOfRationalFunctionP1(B[11],R2).support;
    [ Z(11) ]

##### 5.7-16 MoebiusTransformation

`‣ MoebiusTransformation` ( A, R ) | ( function )

The arguments are a 2× 2 matrix A with entries in a field F and a polynomial ring Rof one variable, say F[x]. This function returns the linear fractional transformatio associated to A. These transformations can be composed with each other using GAP's `Value` command.

##### 5.7-17 ActionMoebiusTransformationOnFunction

`‣ ActionMoebiusTransformationOnFunction` ( A, f, R2 ) | ( function )

The arguments are a 2× 2 matrix A with entries in a field F, a rational function f of one variable, say in F(x), and a polynomial ring R2, say F[x,y]. This function simply returns the composition of the function f with the Möbius transformation of A.

##### 5.7-18 ActionMoebiusTransformationOnDivisorP1

`‣ ActionMoebiusTransformationOnDivisorP1` ( A, D ) | ( function )

A Möbius transformation may be regarded as an automorphism of the projective line P^1. This function simply returns the image of the divisor D under the Möbius transformation defined by A, provided that `IsActionMoebiusTransformationOnDivisorDefinedP1(A,D)` returns true.

##### 5.7-19 IsActionMoebiusTransformationOnDivisorDefinedP1

`‣ IsActionMoebiusTransformationOnDivisorDefinedP1` ( A, D ) | ( function )

Returns true of none of the points in the support of the divisor D is the pole of the Möbius transformation.

    gap> F:=GF(11);
    GF(11)
    gap> R1:=PolynomialRing(F,["a"]);;
    gap> var1:=IndeterminatesOfPolynomialRing(R1);; a:=var1[1];;
    gap> b:=X(F,"b",var1);
    b
    gap> var2:=Concatenation(var1,[b]);
    [ a, b ]
    gap> R2:=PolynomialRing(F,var2);
    PolynomialRing(..., [ a, b ])
    gap> crvP1:=AffineCurve(b,R2);
    rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b )
    gap> D:=DivisorOnAffineCurve([1,2,3,4],[Z(11)^2,Z(11)^3,Z(11)^7,Z(11)],crvP1);
    rec( coeffs := [ 1, 2, 3, 4 ],
         support := [ Z(11)^2, Z(11)^3, Z(11)^7, Z(11) ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> A:=Z(11)^0*[[1,2],[1,4]];
    [ [ Z(11)^0, Z(11) ], [ Z(11)^0, Z(11)^2 ] ]
    gap> ActionMoebiusTransformationOnDivisorDefinedP1(A,D);
    false
    gap> A:=Z(11)^0*[[1,2],[3,4]];
    [ [ Z(11)^0, Z(11) ], [ Z(11)^8, Z(11)^2 ] ]
    gap> ActionMoebiusTransformationOnDivisorDefinedP1(A,D);
    true
    gap> ActionMoebiusTransformationOnDivisorP1(A,D);
    rec( coeffs := [ 1, 2, 3, 4 ],
         support := [ Z(11)^5, Z(11)^6, Z(11)^8, Z(11)^7 ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> f:=MoebiusTransformation(A,R1);
    (a+Z(11))/(Z(11)^8*a+Z(11)^2)
    gap> ActionMoebiusTransformationOnFunction(A,f,R1);
    -Z(11)^0+Z(11)^3*a^-1

##### 5.7-20 DivisorAutomorphismGroupP1

`‣ DivisorAutomorphismGroupP1` ( D ) | ( function )

Input: A divisor D on P^1(F), where F is a finite field. Output: A subgroup Aut(D)⊂ Aut(P^1) preserving D.

Very slow.

    gap> F:=GF(11);
    GF(11)
    gap> R1:=PolynomialRing(F,["a"]);;
    gap> var1:=IndeterminatesOfPolynomialRing(R1);; a:=var1[1];;
    gap> b:=X(F,"b",var1);
    b
    gap> var2:=Concatenation(var1,[b]);
    [ a, b ]
    gap> R2:=PolynomialRing(F,var2);
    PolynomialRing(..., [ a, b ])
    gap> crvP1:=AffineCurve(b,R2);
    rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b )
    gap> D:=DivisorOnAffineCurve([1,2,3,4],[Z(11)^2,Z(11)^3,Z(11)^7,Z(11)],crvP1);
    rec( coeffs := [ 1, 2, 3, 4 ],
         support := [ Z(11)^2, Z(11)^3, Z(11)^7, Z(11) ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> agp:=DivisorAutomorphismGroupP1(D);; time;
    7305
    gap> IdGroup(agp);
    [ 10, 2 ]

##### 5.7-21 MatrixRepresentationOnRiemannRochSpaceP1

`‣ MatrixRepresentationOnRiemannRochSpaceP1` ( g, D ) | ( function )

Input: An element g in G, a subgroup of Aut(D)⊂ Aut(P^1), and a divisor D on P^1(F), where F is a finite field. Output: a d× d matrix, where d = dim L(D), representing the action of g on L(D).

Note: g sends L(D) to r⋅ L(D), where r is a polynomial of degree 1 depending on g and D.

Also very slow.

The GAP command `BrauerCharacterValue` can be used to ``lift'' the eigenvalues of this matrix to the complex numbers.

    gap> F:=GF(11);
    GF(11)
    gap> R1:=PolynomialRing(F,["a"]);;
    gap> var1:=IndeterminatesOfPolynomialRing(R1);; a:=var1[1];;
    gap> b:=X(F,"b",var1);
    b
    gap> var2:=Concatenation(var1,[b]);
    [ a, b ]
    gap> R2:=PolynomialRing(F,var2);
    PolynomialRing(..., [ a, b ])
    gap> crvP1:=AffineCurve(b,R2);
    rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b )
    gap> D:=DivisorOnAffineCurve([1,1,1,4],[Z(11)^2,Z(11)^3,Z(11)^7,Z(11)],crvP1);
    rec( coeffs := [ 1, 1, 1, 4 ],
         support := [ Z(11)^2, Z(11)^3, Z(11)^7, Z(11) ],
         curve := rec( ring := PolynomialRing(..., [ a, b ]), polynomial := b ) )
    gap> agp:=DivisorAutomorphismGroupP1(D);; time;
    7198
    gap> IdGroup(agp);
    [ 20, 5 ]
    gap> g:=Random(agp);
    [ [ Z(11)^4, Z(11)^9 ], [ Z(11)^0, Z(11)^9 ] ]
    gap> rho:=MatrixRepresentationOnRiemannRochSpaceP1(g,D);
    [ [ Z(11)^0, 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11) ],
    [ Z(11)^0, 0*Z(11), 0*Z(11), Z(11), 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11) ],
      [ Z(11)^7, 0*Z(11), Z(11)^5, 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11) ],
    [ Z(11)^4, Z(11)^9, 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11), 0*Z(11) ],
      [ Z(11)^2, 0*Z(11), 0*Z(11), 0*Z(11), Z(11)^5, 0*Z(11), 0*Z(11), 0*Z(11) ],
    [ Z(11)^4, 0*Z(11), 0*Z(11), 0*Z(11), Z(11)^8, Z(11)^0, 0*Z(11), 0*Z(11) ],
      [ Z(11)^6, 0*Z(11), 0*Z(11), 0*Z(11), Z(11)^7, Z(11)^0, Z(11)^5, 0*Z(11) ],
    [ Z(11)^8, 0*Z(11), 0*Z(11), 0*Z(11), Z(11)^3, Z(11)^3, Z(11)^9, Z(11)^0 ] ]
    gap> Display(rho);
      1  .  .  .  .  .  .  .
      1  .  .  2  .  .  .  .
      7  . 10  .  .  .  .  .
      5  6  .  .  .  .  .  .
      4  .  .  . 10  .  .  .
      5  .  .  .  3  1  .  .
      9  .  .  .  7  1 10  .
      3  .  .  .  8  8  6  1

##### 5.7-22 GoppaCodeClassical

`‣ GoppaCodeClassical`( div, pts ) | ( function )

Input: A divisor div on the projective line P}^1(F) over a finite field F and a list pts of points {P_1,...,P_n}⊂ F disjoint from the support of div.
Output: The classical (evaluation) Goppa code associated to this data. This is the code

C=\{(f(P_1),...,f(P_n))\ |\ f\in L(D)_F\}.

    gap> F:=GF(11);;
    gap> R2:=PolynomialRing(F,2);;
    gap> vars:=IndeterminatesOfPolynomialRing(R2);;
    gap> a:=vars[1];;b:=vars[2];;
    gap> cdiv:=[ 1, 2, -1, -2 ];
    [ 1, 2, -1, -2 ]
    gap> sdiv:=[ Z(11)^2, Z(11)^3, Z(11)^6, Z(11)^9 ];
    [ Z(11)^2, Z(11)^3, Z(11)^6, Z(11)^9 ]
    gap> crv:=rec(polynomial:=b,ring:=R2);
    rec( polynomial := x_2, ring := PolynomialRing(..., [ x_1, x_2 ]) )
    gap> div:=DivisorOnAffineCurve(cdiv,sdiv,crv);
    rec( coeffs := [ 1, 2, -1, -2 ], support := [ Z(11)^2, Z(11)^3, Z(11)^6, Z(11)^9 ],
      curve := rec( polynomial := x_2, ring := PolynomialRing(..., [ x_1, x_2 ]) ) )
    gap> pts:=Difference(Elements(GF(11)),div.support);
    [ 0*Z(11), Z(11)^0, Z(11), Z(11)^4, Z(11)^5, Z(11)^7, Z(11)^8 ]
    gap> C:=GoppaCodeClassical(div,pts);
    a linear [7,2,1..6]4..5 code defined by generator matrix over GF(11)
    gap> MinimumDistance(C);
    6

##### 5.7-23 EvaluationBivariateCode

`‣ EvaluationBivariateCode`( pts, L, crv ) | ( function )

Input: `pts` is a set of affine points on `crv`, `L` is a list of rational functions on `crv`.
Output: The evaluation code associated to the points in `pts` and functions in `L`, but specifically for affine plane curves and this function checks if points are "bad" (if so removes them from the list `pts` automatically). A point is ``bad'' if either it does not lie on the set of non-singular F-rational points (places of degree 1) on the curve.

Very similar to `EvaluationCode` (see `EvaluationCode` (5.6-1) for a more general construction).

##### 5.7-24 EvaluationBivariateCodeNC

`‣ EvaluationBivariateCodeNC`( pts, L, crv ) | ( function )

As in `EvaluationBivariateCode` but does not check if the points are ``bad''.

Input: `pts` is a set of affine points on `crv`, `L` is a list of rational functions on `crv`.
Output: The evaluation code associated to the points in `pts` and functions in `L`.

    gap> q:=4;;
    gap> F:=GF(q^2);;
    gap> R:=PolynomialRing(F,2);;
    gap> vars:=IndeterminatesOfPolynomialRing(R);;
    gap> x:=vars[1];;
    gap> y:=vars[2];;
    gap> crv:=AffineCurve(y^q+y-x^(q+1),R);
    rec( ring := PolynomialRing(..., [ x_1, x_2 ]), polynomial := x_1^5+x_2^4+x_2 )
    gap> L:=[ x^0, x, x^2*y^-1 ];
    [ Z(2)^0, x_1, x_1^2/x_2 ]
    gap> Pts:=AffinePointsOnCurve(crv.polynomial,crv.ring,F);;
    gap> C1:=EvaluationBivariateCode(Pts,L,crv); time;

     Automatically removed the following 'bad' points (either a pole or not
     on the curve):
    [ [ 0*Z(2), 0*Z(2) ] ]

    a linear [63,3,1..60]51..59  evaluation code over GF(16)
    52
    gap> P:=Difference(Pts,[[ 0*Z(2^4)^0, 0*Z(2)^0 ]]);;
    gap> C2:=EvaluationBivariateCodeNC(P,L,crv); time;
    a linear [63,3,1..60]51..59  evaluation code over GF(16)
    48
    gap> C3:=EvaluationCode(P,L,R); time;
    a linear [63,3,1..56]51..59  evaluation code over GF(16)
    58
    gap> MinimumDistance(C1);
    56
    gap> MinimumDistance(C2);
    56
    gap> MinimumDistance(C3);
    56
    gap>

##### 5.7-25 OnePointAGCode

`‣ OnePointAGCode`( f, P, m, R ) | ( function )

Input: f is a polynomial in R=F[x,y], where F is a finite field, m is a positive integer (the multiplicity of the `point at infinity' ∞ on the curve f(x,y)=0), P is a list of n points on the curve over F.
Output: The C which is the image of the evaluation map

Eval_P:L(m \cdot \infty)\rightarrow F^n,

given by flongmapsto (f(p_1),...,f(p_n)), where p_i ∈ P. Here L(m ⋅ ∞) denotes the Riemann-Roch space of the divisor m ⋅ ∞ on the curve. This has a basis consisting of monomials x^iy^j, where (i,j) range over a polygon depending on m and f(x,y). For more details on the Riemann-Roch space of the divisor m ⋅ ∞ see Proposition III.10.5 in Stichtenoth [Sti93].

This command returns a "record" object `C` with several extra components (type `NamesOfComponents(C)` to see them all): `C!.points` (namely P), `C!.multiplicity` (namely m), `C!.curve` (namely f) and `C!.ring` (namely R).

    gap> F:=GF(11);
    GF(11)
    gap> R := PolynomialRing(F,["x","y"]);
    PolynomialRing(..., [ x, y ])
    gap> indets := IndeterminatesOfPolynomialRing(R);
    [ x, y ]
    gap> x:=indets[1]; y:=indets[2];
    x
    y
    gap> P:=AffinePointsOnCurve(y^2-x^11+x,R,F);;
    gap> C:=OnePointAGCode(y^2-x^11+x,P,15,R);
    a linear [11,8,1..0]2..3  one-point AG code over GF(11)
    gap> MinimumDistance(C);
    4
    gap> Pts:=List([1,2,4,6,7,8,9,10,11],i->P[i]);;
    gap> C:=OnePointAGCode(y^2-x^11+x,PT,10,R);
    a linear [9,6,1..4]2..3 one-point AG code over GF(11)
    gap> MinimumDistance(C);
    4

See `EvaluationCode` (5.6-1) for a more general construction.

#### 5.8 Low-Density Parity-Check Codes

Low-density parity-check (LDPC) codes form a class of linear block codes whose parity-check matrix--as the name implies, is sparse. LDPC codes were introduced by Robert Gallager in 1962 [Gal62] as his PhD work. Due to the decoding complexity for the technology back then, these codes were forgotten. Not until the late 1990s, these codes were rediscovered and research results have shown that LDPC codes can achieve near Shannon's capacity performance provided that their block length is long enough and soft-decision iterative decoder is employed. Note that the bit-flipping decoder (see `BitFlipDecoder`) is a hard-decision decoder and hence capacity achieving performance cannot be achieved despite having a large block length.

Based on the structure of their parity-check matrix, LDPC codes may be categorised into two classes:

- Regular LDPC codes

  This class of codes has a fixed number of non zeros per column and per row in their parity-check matrix. These codes are usually denoted as (n,j,k) codes where n is the block length, j is the number of non zeros per column in their parity-check matrix and k is the number of non zeros per row in their parity-check matrix.

- Irregular LDPC codes

  The irregular codes, on the other hand, do not have a fixed number of non zeros per column and row in their parity-check matrix. This class of codes are commonly represented by two polynomials which denote the distribution of the number of non zeros in the columns and rows respectively of their parity-check matrix.

##### 5.8-1 QCLDPCCodeFromGroup

`‣ QCLDPCCodeFromGroup`( m, j, k ) | ( function )

`QCLDCCodeFromGroup` produces an (n,j,k) regular quasi-cyclic LDPC code over GF(2) of block length n = mk. The term quasi-cyclic in the context of LDPC codes typically refers to LDPC codes whose parity-check matrix H has the following form

        -                                              -
        |  I_P(0,0)  |  I_P(0,1)  | ... |  I_P(0,k-1)  |
        |  I_P(1,0)  |  I_P(1,1)  | ... |  I_P(1,k-1)  |
    H = |      .     |     .      |  .  |       .      |,
        |      .     |     .      |  .  |       .      |
        | I_P(j-1,0) | I_P(j-1,1) | ... | I_P(j-1,k-1) |
        -                                              -

where I_P(s,t) is an identity matrix of size m × m which has been shifted so that the 1 on the first row starts at position P(s,t).

Let F be a multiplicative group of integers modulo m. If m is a prime, F={0,1,...,m-1}, otherwise F contains a set of integers which are relatively prime to m. In both cases, the order of F is equal to ϕ(m). Let a and b be non zeros of F such that the orders of a and b are k and j respectively. Note that the integers a and b can always be found provided that k and j respectively divide ϕ(m). Having obtain integers a and b, construct the following j × k matrix P so that the element at row s and column t is given by P(s,t) = a^tb^s, i.e.

        -                                             -
        |    1    |     a    | . . . |      a^{k-1}   |
        |    b    |    ab    | . . . |     a^{k-1}b   |
    P = |    .    |    .     |   .   |        .       |.
        |    .    |    .     |   .   |        .       |
        | b^{j-1} | ab^{j-1} | . . . | a^{k-1}b^{j-1} |
        -                                             -

The parity-check matrix H of the LDPC code can be obtained by replacing each element of matrix P, i.e. P(s,t), with an identity matrix I_P(s,t) of size m × m.

The code rate R of the constructed code is given by

R \geq 1 - \frac{j}{k}

where the sign ≥ is due to the possible existence of some non linearly independent rows in H. For more details, refer to the paper by Tanner et al [TSSF}04].

    gap> C := QCLDPCCodeFromGroup(7,2,3);
    a linear [21,8,1..6]5..10 low-density parity-check code over GF(2)
    gap> MinimumWeight(C);
    [21,8] linear code over GF(2) - minimum weight evaluation
    Known lower-bound: 1
    There are 3 generator matrices, ranks : 8 8 5
    The weight of the minimum weight codeword satisfies 0 mod 2 congruence
    Enumerating codewords with information weight 1 (w=1)
        Found new minimum weight 6
    Number of matrices required for codeword enumeration 2
    Completed w= 1, 24 codewords enumerated, lower-bound 4, upper-bound 6
    Termination expected with information weight 2 at matrix 1
    -----------------------------------------------------------------------------
    Enumerating codewords with information weight 2 (w=2) using 1 matrices
    Completed w= 2, 28 codewords enumerated, lower-bound 6, upper-bound 6
    -----------------------------------------------------------------------------
    Minimum weight: 6
    6
    gap> # The quasi-cyclic structure is obvious from the check matrix
    gap> Display( CheckMat(C) );
     1 . . . . . . . 1 . . . . . . . . 1 . . .
     . 1 . . . . . . . 1 . . . . . . . . 1 . .
     . . 1 . . . . . . . 1 . . . . . . . . 1 .
     . . . 1 . . . . . . . 1 . . . . . . . . 1
     . . . . 1 . . . . . . . 1 . 1 . . . . . .
     . . . . . 1 . . . . . . . 1 . 1 . . . . .
     . . . . . . 1 1 . . . . . . . . 1 . . . .
     . . . . . 1 . . . . . 1 . . . . 1 . . . .
     . . . . . . 1 . . . . . 1 . . . . 1 . . .
     1 . . . . . . . . . . . . 1 . . . . 1 . .
     . 1 . . . . . 1 . . . . . . . . . . . 1 .
     . . 1 . . . . . 1 . . . . . . . . . . . 1
     . . . 1 . . . . . 1 . . . . 1 . . . . . .
     . . . . 1 . . . . . 1 . . . . 1 . . . . .
    gap> # This is the famous [155,64,20] quasi-cyclic LDPC codes
    gap> C := QCLDPCCodeFromGroup(31,3,5);
    a linear [155,64,1..24]24..77 low-density parity-check code over GF(2)
    gap> # An example using non prime m, it may take a while to construct this code
    gap> C := QCLDPCCodeFromGroup(356,4,8);
    a linear [2848,1436,1..120]312..1412 low-density parity-check code over GF(2)

[Top of Book] [Contents] [Previous Chapter] [Next Chapter]
Goto Chapter: Top 1 2 3 4 5 6 7 8 9 Bib Ind

generated by GAPDoc2HTML