In this section we describe several vector space functionsGUAVAuses for constructing codes or per-forming calculations with codes.
In this section, some new miscellaneous functions are described, including weight enumerators, the MacWilliams-transform and affinity and almost affinity of codes.
7.5.1 CodeWeightEnumerator
♦ CodeWeightEnumerator(C) (function)
CodeWeightEnumeratorreturns a polynomial of the following form:
f(x) =
n
∑
i=0
Aixi,
where Aiis the number of codewords in C with weight i.
Example
gap> CodeWeightEnumerator( ElementsCode( [ [ 0,0,0 ], [ 0,0,1 ],
> [ 0,1,1 ], [ 1,1,1 ] ], GF(2) ) );
xˆ3 + xˆ2 + x + 1
gap> CodeWeightEnumerator( HammingCode( 3, GF(2) ) );
xˆ7 + 7*xˆ4 + 7*xˆ3 + 1
7.5.2 CodeDistanceEnumerator
♦ CodeDistanceEnumerator(C, w) (function)
CodeDistanceEnumeratorreturns a polynomial of the following form:
f(x) =
n
∑
i=0
Bixi, where Biis the number of codewords with distance i to w .
If w is a codeword, then CodeDistanceEnumerator returns the same polynomial as CodeWeightEnumerator.
Example
gap> CodeDistanceEnumerator( HammingCode( 3, GF(2) ),[0,0,0,0,0,0,1] );
xˆ6 + 3*xˆ5 + 4*xˆ4 + 4*xˆ3 + 3*xˆ2 + x
gap> CodeDistanceEnumerator( HammingCode( 3, GF(2) ),[1,1,1,1,1,1,1] );
xˆ7 + 7*xˆ4 + 7*xˆ3 + 1 # ‘[1,1,1,1,1,1,1]’ $\in$ ‘HammingCode( 3, GF(2 ) )’
7.5.3 CodeMacWilliamsTransform
♦ CodeMacWilliamsTransform(C) (function)
CodeMacWilliamsTransformreturns a polynomial of the following form:
f(x) =
n
∑
i=0
Cixi,
where Ciis the number of codewords with weight i in the dual code of C.
Example
gap> CodeMacWilliamsTransform( HammingCode( 3, GF(2) ) );
7*xˆ4 + 1
7.5.4 CodeDensity
♦ CodeDensity(C) (function)
CodeDensityreturns the density of C. The density of a code is defined as M·Vq(n,t)
qn ,
where M is the size of the code, Vq(n,t) is the size of a sphere of radius t in GF(qn) (which may be computed using SphereContent), t is the covering radius of the code and n is the length of the code.
Example gap> CodeDensity( HammingCode( 3, GF(2) ) );
1
gap> CodeDensity( ReedMullerCode( 1, 4 ) );
14893/2048
7.5.5 SphereContent
♦ SphereContent(n, t, F) (function)
SphereContent returns the content of a ball of radius t around an arbitrary element of the vectorspace Fn. This is the cardinality of the set of all elements of Fn that are at distance (see DistanceCodeword(3.6.2) less than or equal to t from an element of Fn.
In the context of codes, the function is used to determine if a code is perfect. A code is perfect if spheres of radius t around all codewords partition the whole ambient vector space, where t is the number of errors the code can correct.
Example gap> SphereContent( 15, 0, GF(2) );
1 # Only one word with distance 0, which is the word itself gap> SphereContent( 11, 3, GF(4) );
4984
gap> C := HammingCode(5);
a linear [31,26,3]1 Hamming (5,2) code over GF(2)
#the minimum distance is 3, so the code can correct one error gap> ( SphereContent( 31, 1, GF(2) ) * Size(C) ) = 2 ˆ 31;
true
7.5.6 Krawtchouk
♦ Krawtchouk(k, i, n, q) (function)
Krawtchoukreturns the Krawtchouk number Kk(i). q must be a prime power, n must be a positive integer, k must be a non-negative integer less then or equal to n and i can be any integer. (See KrawtchoukMat(7.3.1)). This number is the value at x = i of the polynomial
Kkn,q(x) =
n
∑
j=0
(−1)j(q − 1)k− jb(x, j)b(n − x, k − j),
where $b(v,u)=u!/(v!(v-u)!)$ is the binomial coefficient if $u,v$ are integers. For more properties of these polynomials, see [MS83].
Example gap> Krawtchouk( 2, 0, 3, 2);
3
7.5.7 PrimitiveUnityRoot
♦ PrimitiveUnityRoot(F, n) (function)
PrimitiveUnityRootreturns a primitive n-th root of unity in an extension field of F. This is a finite field element a with the property an= 1 in F, and n is the smallest integer such that this equality holds.
Example gap> PrimitiveUnityRoot( GF(2), 15 );
Z(2ˆ4)
gap> lastˆ15;
Z(2)ˆ0
gap> PrimitiveUnityRoot( GF(8), 21 );
Z(2ˆ6)ˆ3
7.5.8 PrimitivePolynomialsNr
♦ PrimitivePolynomialsNr(n, F) (function)
PrimitivePolynomialsNrreturns the number of irreducible polynomials over F = GF(q) of degree n with (maximum) period qn− 1. (According to a theorem of S. Golomb, this is φ(pn− 1)/n.) See also the GAP function RandomPrimitivePolynomial, RandomPrimitivePolynomial (2.2.2).
Example gap> PrimitivePolynomialsNr(3,4);
12
7.5.9 IrreduciblePolynomialsNr
♦ IrreduciblePolynomialsNr(n, F) (function)
PrimitivePolynomialsNrreturns the number of irreducible polynomials over F = GF(q) of degree n.
Example gap> IrreduciblePolynomialsNr(3,4);
20
7.5.10 MatrixRepresentationOfElement
♦ MatrixRepresentationOfElement(a, F) (function)
Here F is either a finite extension of the “base field” GF(p) or of the rationals Q, and a ∈ F.
The command MatrixRepresentationOfElement returns a matrix representation of a over the base field.
If the element a is defined over the base field then it returns the corresponding 1 × 1 matrix.
Example gap> a:=Random(GF(4));
0*Z(2)
gap> M:=MatrixRepresentationOfElement(a,GF(4));; Display(M);
.
gap> a:=Random(GF(4));
Z(2ˆ2)
gap> M:=MatrixRepresentationOfElement(a,GF(4));; Display(M);
. 1 1 1 gap>
7.5.11 ReciprocalPolynomial
♦ ReciprocalPolynomial(P) (function)
ReciprocalPolynomialreturns the reciprocal of polynomial P. This is a polynomial with co-efficients of P in the reverse order. So if P = a0+ a1X+ ... + anXn, the reciprocal polynomial is P0= an+ an−1X+ ... + a0Xn.
This command can also be called using the syntax ReciprocalPolynomial( P , n ). In this form, the number of coefficients of P is assumed to be less than or equal to n + 1 (with zero coefficients added in the highest degrees, if necessary). Therefore, the reciprocal polynomial also has degree n+ 1.
Example
gap> P := UnivariatePolynomial( GF(3), Z(3)ˆ0 * [1,0,1,2] );
Z(3)ˆ0+x_1ˆ2-x_1ˆ3
gap> RecP := ReciprocalPolynomial( P );
-Z(3)ˆ0+x_1+x_1ˆ3
gap> ReciprocalPolynomial( RecP ) = P;
true
gap> P := UnivariatePolynomial( GF(3), Z(3)ˆ0 * [1,0,1,2] );
Z(3)ˆ0+x_1ˆ2-x_1ˆ3
gap> ReciprocalPolynomial( P, 6 );
-x_1ˆ3+x_1ˆ4+x_1ˆ6
7.5.12 CyclotomicCosets
♦ CyclotomicCosets(q, n) (function)
CyclotomicCosetsreturns the cyclotomic cosets of q (mod n). q and n must be relatively prime. Each of the elements of the returned list is a list of integers that belong to one cyclotomic coset. A q-cyclotomic coset of s (mod n) is a set of the form {s, sq, sq2, ..., sqr−1}, where r is the smallest positive integer such that sqr− s is 0 (mod n). In other words, each coset contains all multiplications of the coset representative by q (mod n). The coset representative is the smallest integer that isn’t in the previous cosets.
Example gap> CyclotomicCosets( 2, 15 );
[ [ 0 ], [ 1, 2, 4, 8 ], [ 3, 6, 12, 9 ], [ 5, 10 ], [ 7, 14, 13, 11 ] ]
gap> CyclotomicCosets( 7, 6 );
[ [ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ] ]
7.5.13 WeightHistogram
♦ WeightHistogram(C[, h]) (function)
The function WeightHistogram plots a histogram of weights in code C. The maximum length of a column is h. Default value for h is 1/3 of the size of the screen. The number that appears at the top of the histogram is the maximum value of the list of weights.
Example gap> H := HammingCode(2, GF(5));
a linear [6,4,3]1 Hamming (2,5) code over GF(5) gap> WeightDistribution(H);
[ 1, 0, 0, 80, 120, 264, 160 ] gap> WeightHistogram(H);
264---*
*
*
*
* *
* * *
* * * *
* * * * +---+--+--+--+--0 1 2 3 4 5 6
7.5.14 MultiplicityInList
♦ MultiplicityInList(L, a) (function)
This is a very simple list command which returns how many times a occurs in L. It returns 0 if a is not in L. (The GAP command Collected does not quite handle this ”extreme” case.)
Example gap> L:=[1,2,3,4,3,2,1,5,4,3,2,1];;
gap> MultiplicityInList(L,1);
3
gap> MultiplicityInList(L,6);
0
7.5.15 MostCommonInList
♦ MostCommonInList(L) (function)
Input: a list L
Output: an a in L which occurs at least as much as any other in L Example
gap> L:=[1,2,3,4,3,2,1,5,4,3,2,1];;
gap> MostCommonInList(L);
1
7.5.16 RotateList
♦ RotateList(L) (function)
Input: a list L
Output: a list L’ which is the cyclic rotation of L (to the right) Example
gap> L:=[1,2,3,4];;
gap> RotateList(L);
[2,3,4,1]
7.5.17 CirculantMatrix
♦ CirculantMatrix(k, L) (function)
Input: integer k, a list L of length n
Output: kxn matrix whose rows are cyclic rotations of the list L Example
gap> k:=3; L:=[1,2,3,4];;
gap> M:=CirculantMatrix(k,L);;
gap> Display(M);