  
  [1m[4m[31m4. Codes[0m
  
  A  [22m[36mcode[0m  is  a  set  of  codewords  (recall  a codeword in [1mGUAVA[0m is simply a
  sequence  of elements of a finite field GF(q), where q is a prime power). We
  call  these  the  [22m[36melements[0m  of  the  code.  Depending on the type of code, a
  codeword  can  be  interpreted  as  a  vector  or  as  a polynomial. This is
  explained in more detail in Chapter [1m3.[0m.
  
  In  [1mGUAVA[0m, codes can be a set specified by its elements (this will be called
  an [22m[36munrestricted code[0m), by a generator matrix listing a set of basis elements
  (for a linear code) or by a generator polynomial (for a cyclic code).
  
  Any  code can be defined by its elements. If you like, you can give the code
  a name.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := ElementsCode(["1100", "1010", "0001"], "example code", GF(2) );[0m
    [22m[35ma (4,3,1..4)2..4 example code over GF(2) [0m
  [22m[35m------------------------------------------------------------------[0m
  
  An (n,M,d) code is a code with word [22m[36mlength[0m n, [22m[36msize[0m M and [22m[36mminimum distance[0m d.
  If  the  minimum  distance  has not yet been calculated, the lower bound and
  upper  bound  are  printed  (except  in  the case where the code is a random
  linear codes, where these are not printed for efficiency reasons). So
  
  
  a (4,3,1..4)2..4 code over GF(2)
  means  a  binary  unrestricted  code  of  length  4, with 3 elements and the
  minimum  distance  is greater than or equal to 1 and less than or equal to 4
  and the covering radius is greater than or equal to 2 and less than or equal
  to 4.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := ElementsCode(["1100", "1010", "0001"], "example code", GF(2) );[0m
    [22m[35ma (4,3,1..4)2..4 example code over GF(2) [0m
    [22m[35mgap> MinimumDistance(C);[0m
    [22m[35m2[0m
    [22m[35mgap> C;[0m
    [22m[35ma (4,3,2)2..4 example code over GF(2) [0m
  [22m[35m------------------------------------------------------------------[0m
  
  If  the  set of elements is a linear subspace of GF(q)^n, the code is called
  [22m[36mlinear[0m.  If  a  code is linear, it can be defined by its [22m[36mgenerator matrix[0m or
  [22m[36mparity  check  matrix[0m.  By definition, the rows of the generator matrix is a
  basis  for  the code (as a vector space over GF(q)). By definition, the rows
  of the parity check matrix is a basis for the dual space of the code,
  
  \[
       C^* = \{ v \in GF(q)^n\ |\ v\cdot c = 0,\ for \ all\ c \in C \}.
  \]
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> G := GeneratorMatCode([[1,0,1],[0,1,2]], "demo code", GF(3) );[0m
    [22m[35ma linear [3,2,1..2]1 demo code over GF(3) [0m
  [22m[35m------------------------------------------------------------------[0m
  
  So  a  linear  [n,  k,  d]r  code is a code with word [22m[36mlength[0m n, [22m[36mdimension[0m k,
  [22m[36mminimum distance[0m d and [22m[36mcovering radius[0m r.
  
  If  the  code  is linear and all cyclic shifts of its codewords (regarded as
  n-tuples)  are again codewords, the code is called [22m[36mcyclic[0m. All elements of a
  cyclic  code  are  multiples of the monic polynomial modulo a polynomial x^n
  -1,  where  n  is the word length of the code. Such a polynomial is called a
  [22m[36mgenerator  polynomial[0m  The  generator  polynomial  must divide x^n-1 and its
  quotient  is  called  a [22m[36mcheck polynomial[0m. Multiplying a codeword in a cyclic
  code  by the check polynomial yields zero (modulo the polynomial x^n -1). In
  [1mGUAVA[0m,  a  cyclic  code can be defined by either its generator polynomial or
  check polynomial.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> G := GeneratorPolCode(Indeterminate(GF(2))+Z(2)^0, 7, GF(2) );[0m
    [22m[35ma cyclic [7,6,1..2]1 code defined by generator polynomial over GF(2)[0m
  [22m[35m------------------------------------------------------------------[0m
  
  It is possible that [1mGUAVA[0m does not know that an unrestricted code is in fact
  linear.  This  situation  occurs for example when a code is generated from a
  list  of elements with the function [22m[32mElementsCode[0m (see [1m[34mElementsCode[0m ([1m5.1-1[0m)).
  By calling the function [22m[32mIsLinearCode[0m (see [1m[34mIsLinearCode[0m ([1m4.3-4[0m)), [1mGUAVA[0m tests
  if the code can be represented by a generator matrix. If so, the code record
  and the operations are converted accordingly.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> L := Z(2)*[ [0,0,0], [1,0,0], [0,1,1], [1,1,1] ];;[0m
    [22m[35mgap> C := ElementsCode( L, GF(2) );[0m
    [22m[35ma (3,4,1..3)1 user defined unrestricted code over GF(2)[0m
    [22m[35m# so far, GUAVA does not know what kind of code this is[0m
    [22m[35mgap> IsLinearCode( C );[0m
    [22m[35mtrue                      # it is linear[0m
    [22m[35mgap> C;[0m
    [22m[35ma linear [3,2,1]1 user defined unrestricted code over GF(2) [0m
  [22m[35m------------------------------------------------------------------[0m
  
  Of  course the same holds for unrestricted codes that in fact are cyclic, or
  codes, defined by a generator matrix, that actually are cyclic.
  
  Codes  are printed simply by giving a small description of their parameters,
  the  word  length,  size  or  dimension  and  perhaps  the minimum distance,
  followed by a short description and the base field of the code. The function
  [22m[32mDisplay[0m  gives a more detailed description, showing the construction history
  of the code.
  
  [1mGUAVA[0m  doesn't  place  much  emphasis  on  the  actual encoding and decoding
  processes;  some algorithms have been included though. Encoding works simply
  by  multiplying  an  information vector with a code, decoding is done by the
  functions  [22m[32mDecode[0m  or  [22m[32mDecodeword[0m.  For  more information about encoding and
  decoding, see sections [1m4.2[0m and [1m4.10-1[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> R := ReedMullerCode( 1, 3 );[0m
    [22m[35ma linear [8,4,4]2 Reed-Muller (1,3) code over GF(2)[0m
    [22m[35mgap> w := [ 1, 0, 1, 1 ] * R;[0m
    [22m[35m[ 1 0 0 1 1 0 0 1 ][0m
    [22m[35mgap> Decode( R, w );[0m
    [22m[35m[ 1 0 1 1 ][0m
    [22m[35mgap> Decode( R, w + "10000000" ); # One error at the first position[0m
    [22m[35m[ 1 0 1 1 ]                       # Corrected by Guava [0m
  [22m[35m------------------------------------------------------------------[0m
  
  Sections  [1m4.1[0m  and [1m4.2[0m describe the operations that are available for codes.
  Section  [1m4.3[0m  describe  the functions that tests whether an object is a code
  and  what  kind  of  code  it  is  (see  [22m[32mIsCode[0m,  [1m[34mIsLinearCode[0m  ([1m4.3-4[0m)  and
  [22m[32mIsCyclicCode[0m)  and  various  other  boolean functions for codes. Section [1m4.4[0m
  describe   functions   about  equivalence  and  isomorphism  of  codes  (see
  [1m[34mIsEquivalent[0m   ([1m4.4-1[0m),   [1m[34mCodeIsomorphism[0m   ([1m4.4-2[0m)   and  [1m[34mAutomorphismGroup[0m
  ([1m4.4-3[0m)).  Section [1m4.5[0m describes functions that work on [22m[36mdomains[0m (see Chapter
  "Domains  and  their  Elements"  in  the  [1mGAP[0m Reference Manual). Section [1m4.6[0m
  describes functions for printing and displaying codes. Section [1m4.7[0m describes
  functions  that  return the matrices and polynomials that define a code (see
  [1m[34mGeneratorMat[0m  ([1m4.7-1[0m),  [1m[34mCheckMat[0m  ([1m4.7-2[0m),  [1m[34mGeneratorPol[0m  ([1m4.7-3[0m),  [1m[34mCheckPol[0m
  ([1m4.7-4[0m),  [1m[34mRootsOfCode[0m  ([1m4.7-5[0m)). Section [1m4.8[0m describes functions that return
  the  basic  parameters  of codes (see [1m[34mWordLength[0m ([1m4.8-1[0m), [1m[34mRedundancy[0m ([1m4.8-2[0m)
  and  [1m[34mMinimumDistance[0m  ([1m4.8-3[0m)).  Section [1m4.9[0m describes functions that return
  distance   and   weight   distributions   (see  [1m[34mWeightDistribution[0m  ([1m4.9-2[0m),
  [1m[34mInnerDistribution[0m      ([1m4.9-3[0m),      [1m[34mOuterDistribution[0m      ([1m4.9-5[0m)      and
  [1m[34mDistancesDistribution[0m  ([1m4.9-4[0m)).  Section  [1m4.10[0m describes functions that are
  related  to  decoding  (see  [1m[34mDecode[0m  ([1m4.10-1[0m), [1m[34mDecodeword[0m ([1m4.10-2[0m), [1m[34mSyndrome[0m
  ([1m4.10-8[0m),  [1m[34mSyndromeTable[0m  ([1m4.10-9[0m) and [1m[34mStandardArray[0m ([1m4.10-10[0m)). In Chapters
  [1m5.[0m  and  [1m6.[0m which follow, we describe functions that generate and manipulate
  codes.
  
  
  [1m[4m[31m4.1 Comparisons of Codes[0m
  
  [1m[4m[31m4.1-1 =[0m
  
  [1m[34m> =( [0m[22m[34mC1, C2[0m[1m[34m ) ______________________________________________________[0mfunction
  
  The equality operator [22m[32mC1 = C2[0m evaluates to `true' if the codes [22m[34mC1[0m and [22m[34mC2[0m are
  equal, and to `false' otherwise.
  
  The  equality operator is also denoted [22m[32mEQ[0m, and [22m[32mEq(C1,C2)[0m is the same as [22m[32mC1 =
  C2[0m. There is also an inequality operator, < >, or [22m[32mnot EQ[0m.
  
  Note  that  codes  are equal if and only if their set of elements are equal.
  Codes  can  also be compared with objects of other types. Of course they are
  never equal.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> M := [ [0, 0], [1, 0], [0, 1], [1, 1] ];;[0m
    [22m[35mgap> C1 := ElementsCode( M, GF(2) );[0m
    [22m[35ma (2,4,1..2)0 user defined unrestricted code over GF(2)[0m
    [22m[35mgap> M = C1;[0m
    [22m[35mfalse[0m
    [22m[35mgap> C2 := GeneratorMatCode( [ [1, 0], [0, 1] ], GF(2) );[0m
    [22m[35ma linear [2,2,1]0 code defined by generator matrix over GF(2)[0m
    [22m[35mgap> C1 = C2;[0m
    [22m[35mtrue[0m
    [22m[35mgap> ReedMullerCode( 1, 3 ) = HadamardCode( 8 );[0m
    [22m[35mtrue[0m
    [22m[35mgap> WholeSpaceCode( 5, GF(4) ) = WholeSpaceCode( 5, GF(2) );[0m
    [22m[35mfalse[0m
  [22m[35m------------------------------------------------------------------[0m
  
  Another  way  of  comparing codes is [22m[32mIsEquivalent[0m, which checks if two codes
  are   equivalent  (see  [1m[34mIsEquivalent[0m  ([1m4.4-1[0m)).  By  the  way,  this  called
  [22m[32mCodeIsomorphism[0m.  For  the current version of [1mGUAVA[0m, unless one of the codes
  is  unrestricted,  this  calls Leon's C program (which only works for binary
  linear codes and only on a unix/linux computer).
  
  
  [1m[4m[31m4.2 Operations for Codes[0m
  
  [1m[4m[31m4.2-1 +[0m
  
  [1m[34m> +( [0m[22m[34mC1, C2[0m[1m[34m ) ______________________________________________________[0mfunction
  
  The  operator  `+'  evaluates  to the direct sum of the codes [22m[34mC1[0m and [22m[34mC2[0m. See
  [1m[34mDirectSumCode[0m ([1m6.2-1[0m).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1:=RandomLinearCode(10,5);[0m
    [22m[35ma  [10,5,?] randomly generated code over GF(2)[0m
    [22m[35mgap> C2:=RandomLinearCode(9,4);[0m
    [22m[35ma  [9,4,?] randomly generated code over GF(2)[0m
    [22m[35mgap> C1+C2;[0m
    [22m[35ma linear [10,9,1]0..10 unknown linear code over GF(2)[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.2-2 *[0m
  
  [1m[34m> *( [0m[22m[34mC1, C2[0m[1m[34m ) ______________________________________________________[0mfunction
  
  The operator `*' evaluates to the direct product of the codes [22m[34mC1[0m and [22m[34mC2[0m. See
  [1m[34mDirectProductCode[0m ([1m6.2-3[0m).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := GeneratorMatCode( [ [1, 0,0,0], [0, 1,0,0] ], GF(2) );[0m
    [22m[35ma linear [4,2,1]1 code defined by generator matrix over GF(2)[0m
    [22m[35mgap> C2 := GeneratorMatCode( [ [0,0,1, 1], [0,0,0, 1] ], GF(2) );[0m
    [22m[35ma linear [4,2,1]1 code defined by generator matrix over GF(2)[0m
    [22m[35mgap> C1*C2;[0m
    [22m[35ma linear [16,4,1]4..12 direct product code[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.2-3 *[0m
  
  [1m[34m> *( [0m[22m[34mm, C[0m[1m[34m ) ________________________________________________________[0mfunction
  
  The operator [22m[32mm*C[0m evaluates to the element of [22m[34mC[0m belonging to information word
  ('message')  [22m[34mm[0m.  Here [22m[34mm[0m may be a vector, polynomial, string or codeword or a
  list  of  those.  This is the way to do encoding in [1mGUAVA[0m. [22m[34mC[0m must be linear,
  because  in  [1mGUAVA[0m,  encoding  by  multiplication is only defined for linear
  codes. If [22m[34mC[0m is a cyclic code, this multiplication is the same as multiplying
  an  information  polynomial  [22m[34mm[0m  by  the generator polynomial of [22m[34mC[0m. If [22m[34mC[0m is a
  linear code, it is equal to the multiplication of an information vector [22m[34mm[0m by
  a generator matrix of [22m[34mC[0m.
  
  To  invert  this,  use  the  function  [22m[32mInformationWord[0m  (see [1m[34mInformationWord[0m
  ([1m4.2-4[0m), which simply calls the function [22m[32mDecode[0m).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := GeneratorMatCode( [ [1, 0,0,0], [0, 1,0,0] ], GF(2) );[0m
    [22m[35ma linear [4,2,1]1 code defined by generator matrix over GF(2)[0m
    [22m[35mgap> m:=Codeword("11");[0m
    [22m[35m[ 1 1 ][0m
    [22m[35mgap> m*C;[0m
    [22m[35m[ 1 1 0 0 ][0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.2-4 InformationWord[0m
  
  [1m[34m> InformationWord( [0m[22m[34mc, C[0m[1m[34m ) __________________________________________[0mfunction
  
  Here  [22m[34mC[0m  is  a  linear  code  and  [22m[34mc[0m  is  a  codeword  in  it.  The  command
  [22m[32mInformationWord[0m  returns  the  message  word  (or  'information  digits')  m
  satisfying [22m[32mc=m*C[0m. This command simply calls [22m[32mDecode[0m, provided [22m[32mc in C[0m is true.
  Otherwise, it returns an error.
  
  To invert this, use the encoding function [22m[32m*[0m (see [1m[34m*[0m ([1m4.2-3[0m)).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C:=HammingCode(3);[0m
    [22m[35ma linear [7,4,3]1 Hamming (3,2) code over GF(2)[0m
    [22m[35mgap> c:=Random(C);[0m
    [22m[35m[ 0 0 0 1 1 1 1 ][0m
    [22m[35mgap> InformationWord(C,c);[0m
    [22m[35m[ 0 1 1 1 ][0m
    [22m[35mgap> c:=Codeword("1111100");[0m
    [22m[35m[ 1 1 1 1 1 0 0 ][0m
    [22m[35mgap> InformationWord(C,c);[0m
    [22m[35m"ERROR: codeword must belong to code"[0m
    [22m[35mgap> C:=NordstromRobinsonCode();[0m
    [22m[35ma (16,256,6)4 Nordstrom-Robinson code over GF(2)[0m
    [22m[35mgap> c:=Random(C);[0m
    [22m[35m[ 0 0 0 1 0 0 0 1 0 0 1 0 1 1 0 1 ][0m
    [22m[35mgap> InformationWord(C,c);[0m
    [22m[35m"ERROR: code must be linear"[0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m4.3 Boolean Functions for Codes[0m
  
  [1m[4m[31m4.3-1 in[0m
  
  [1m[34m> in( [0m[22m[34mc, C[0m[1m[34m ) _______________________________________________________[0mfunction
  
  The command [22m[32mc in C[0m evaluates to `true' if [22m[34mC[0m contains the codeword or list of
  codewords specified by [22m[34mc[0m. Of course, [22m[34mc[0m and [22m[34mC[0m must have the same word lengths
  and base fields.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C:= HammingCode( 2 );; eC:= AsSSortedList( C );[0m
    [22m[35m[ [ 0 0 0 ], [ 1 1 1 ] ][0m
    [22m[35mgap> eC[2] in C;[0m
    [22m[35mtrue[0m
    [22m[35mgap> [ 0 ] in C;[0m
    [22m[35mfalse [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-2 IsSubset[0m
  
  [1m[34m> IsSubset( [0m[22m[34mC1, C2[0m[1m[34m ) _______________________________________________[0mfunction
  
  The command [22m[32mIsSubset(C1,C2)[0m returns `true' if [22m[34mC2[0m is a subcode of [22m[34mC1[0m, i.e. if
  [22m[34mC1[0m contains all the elements of [22m[34mC2[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> IsSubset( HammingCode(3), RepetitionCode( 7 ) );[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsSubset( RepetitionCode( 7 ), HammingCode( 3 ) );[0m
    [22m[35mfalse[0m
    [22m[35mgap> IsSubset( WholeSpaceCode( 7 ), HammingCode( 3 ) );[0m
    [22m[35mtrue[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-3 IsCode[0m
  
  [1m[34m> IsCode( [0m[22m[34mobj[0m[1m[34m ) ____________________________________________________[0mfunction
  
  [22m[32mIsCode[0m returns `true' if [22m[34mobj[0m, which can be an object of arbitrary type, is a
  code  and  `false'  otherwise.  Will  cause  an  error  if [22m[34mobj[0m is an unbound
  variable.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> IsCode( 1 );[0m
    [22m[35mfalse[0m
    [22m[35mgap> IsCode( ReedMullerCode( 2,3 ) );[0m
    [22m[35mtrue[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-4 IsLinearCode[0m
  
  [1m[34m> IsLinearCode( [0m[22m[34mobj[0m[1m[34m ) ______________________________________________[0mfunction
  
  [22m[32mIsLinearCode[0m checks if object [22m[34mobj[0m (not necessarily a code) is a linear code.
  If  a  code  has  already  been  marked  as  linear  or cyclic, the function
  automatically returns `true'. Otherwise, the function checks if a basis G of
  the  elements  of [22m[34mobj[0m exists that generates the elements of [22m[34mobj[0m. If so, G is
  recorded  as  a  generator matrix of [22m[34mobj[0m and the function returns `true'. If
  not, the function returns `false'.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := ElementsCode( [ [0,0,0],[1,1,1] ], GF(2) );[0m
    [22m[35ma (3,2,1..3)1 user defined unrestricted code over GF(2)[0m
    [22m[35mgap> IsLinearCode( C );[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsLinearCode( ElementsCode( [ [1,1,1] ], GF(2) ) );[0m
    [22m[35mfalse[0m
    [22m[35mgap> IsLinearCode( 1 );[0m
    [22m[35mfalse [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-5 IsCyclicCode[0m
  
  [1m[34m> IsCyclicCode( [0m[22m[34mobj[0m[1m[34m ) ______________________________________________[0mfunction
  
  [22m[32mIsCyclicCode[0m  checks  if  the  object  [22m[34mobj[0m  is  a cyclic code. If a code has
  already  been  marked  as cyclic, the function automatically returns `true'.
  Otherwise,  the  function checks if a polynomial g exists that generates the
  elements  of  [22m[34mobj[0m. If so, g is recorded as a generator polynomial of [22m[34mobj[0m and
  the function returns `true'. If not, the function returns `false'.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := ElementsCode( [ [0,0,0], [1,1,1] ], GF(2) );[0m
    [22m[35ma (3,2,1..3)1 user defined unrestricted code over GF(2)[0m
    [22m[35mgap> # GUAVA does not know the code is cyclic[0m
    [22m[35mgap> IsCyclicCode( C );      # this command tells GUAVA to find out[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsCyclicCode( HammingCode( 4, GF(2) ) );[0m
    [22m[35mfalse[0m
    [22m[35mgap> IsCyclicCode( 1 );[0m
    [22m[35mfalse [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-6 IsPerfectCode[0m
  
  [1m[34m> IsPerfectCode( [0m[22m[34mC[0m[1m[34m ) _______________________________________________[0mfunction
  
  [22m[32mIsPerfectCode(C)[0m  returns  `true' if [22m[34mC[0m is a perfect code. If Csubset GF(q)^n
  then,  by definition, this means that for some positive integer t, the space
  GF(q)^n is covered by non-overlapping spheres of (Hamming) radius t centered
  at  the  codewords in [22m[34mC[0m. For a code with odd minimum distance d = 2t+1, this
  is  the case when every word of the vector space of [22m[34mC[0m is at distance at most
  t  from exactly one element of [22m[34mC[0m. Codes with even minimum distance are never
  perfect.
  
  In fact, a code that is not "trivially perfect" (the binary repetition codes
  of odd length, the codes consisting of one word, and the codes consisting of
  the  whole  vector  space), and does not have the parameters of a Hamming or
  Golay code, cannot be perfect (see section 1.12 in [HP03]).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> H := HammingCode(2);[0m
    [22m[35ma linear [3,1,3]1 Hamming (2,2) code over GF(2)[0m
    [22m[35mgap> IsPerfectCode( H );[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsPerfectCode( ElementsCode([[1,1,0],[0,0,1]],GF(2)) );[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsPerfectCode( ReedSolomonCode( 6, 3 ) );[0m
    [22m[35mfalse[0m
    [22m[35mgap> IsPerfectCode( BinaryGolayCode() );[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-7 IsMDSCode[0m
  
  [1m[34m> IsMDSCode( [0m[22m[34mC[0m[1m[34m ) ___________________________________________________[0mfunction
  
  [22m[32mIsMDSCode(C)[0m returns true if [22m[34mC[0m is a maximum distance separable (MDS) code. A
  linear  [n, k, d]-code of length n, dimension k and minimum distance d is an
  MDS  code  if  k=n-d+1,  in  other words if [22m[34mC[0m meets the Singleton bound (see
  [1m[34mUpperBoundSingleton[0m  ([1m7.1-1[0m)).  An unrestricted (n, M, d) code is called [22m[36mMDS[0m
  if  k=n-d+1,  with  k equal to the largest integer less than or equal to the
  logarithm of M with base q, the size of the base field of [22m[34mC[0m.
  
  Well-known  MDS  codes  include the repetition codes, the whole space codes,
  the  even  weight  codes  (these  are  the  only  [22m[36mbinary[0m  MDS codes) and the
  Reed-Solomon codes.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := ReedSolomonCode( 6, 3 );[0m
    [22m[35ma cyclic [6,4,3]2 Reed-Solomon code over GF(7)[0m
    [22m[35mgap> IsMDSCode( C1 );[0m
    [22m[35mtrue    # 6-3+1 = 4[0m
    [22m[35mgap> IsMDSCode( QRCode( 23, GF(2) ) );[0m
    [22m[35mfalse [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-8 IsSelfDualCode[0m
  
  [1m[34m> IsSelfDualCode( [0m[22m[34mC[0m[1m[34m ) ______________________________________________[0mfunction
  
  [22m[32mIsSelfDualCode(C)[0m  returns `true' if [22m[34mC[0m is self-dual, i.e. when [22m[34mC[0m is equal to
  its  dual  code  (see  also  [1m[34mDualCode[0m  ([1m6.1-13[0m)).  A code is self-dual if it
  contains  all  vectors  that  its  elements  are orthogonal to. If a code is
  self-dual,  it  automatically  is  self-orthogonal (see [1m[34mIsSelfOrthogonalCode[0m
  ([1m4.3-9[0m)).
  
  If  [22m[34mC[0m  is a non-linear code, it cannot be self-dual (the dual code is always
  linear),  so  `false'  is returned. A linear code can only be self-dual when
  its dimension k is equal to the redundancy r.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> IsSelfDualCode( ExtendedBinaryGolayCode() );[0m
    [22m[35mtrue[0m
    [22m[35mgap> C := ReedMullerCode( 1, 3 );[0m
    [22m[35ma linear [8,4,4]2 Reed-Muller (1,3) code over GF(2)[0m
    [22m[35mgap> DualCode( C ) = C;[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-9 IsSelfOrthogonalCode[0m
  
  [1m[34m> IsSelfOrthogonalCode( [0m[22m[34mC[0m[1m[34m ) ________________________________________[0mfunction
  
  [22m[32mIsSelfOrthogonalCode(C)[0m  returns  `true'  if [22m[34mC[0m is self-orthogonal. A code is
  [22m[36mself-orthogonal[0m  if  every  element of [22m[34mC[0m is orthogonal to all elements of [22m[34mC[0m,
  including  itself. (In the linear case, this simply means that the generator
  matrix of [22m[34mC[0m multiplied with its transpose yields a null matrix.)
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> R := ReedMullerCode(1,4);[0m
    [22m[35ma linear [16,5,8]6 Reed-Muller (1,4) code over GF(2)[0m
    [22m[35mgap> IsSelfOrthogonalCode(R);[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsSelfDualCode(R);[0m
    [22m[35mfalse [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-10 IsSelfComplementaryCode[0m
  
  [1m[34m> IsSelfComplementaryCode( [0m[22m[34mC[0m[1m[34m ) _____________________________________[0mfunction
  
  [22m[32mIsSelfComplementaryCode[0m returns `true' if
  
  \[
       v \in C \Rightarrow 1 - v \in C,
  \]
  
  where 1 is the all-one word of length n.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> IsSelfComplementaryCode( HammingCode( 3, GF(2) ) );[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsSelfComplementaryCode( EvenWeightSubcode([0m
    [22m[35m> HammingCode( 3, GF(2) ) ) );[0m
    [22m[35mfalse [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-11 IsAffineCode[0m
  
  [1m[34m> IsAffineCode( [0m[22m[34mC[0m[1m[34m ) ________________________________________________[0mfunction
  
  [22m[32mIsAffineCode[0m  returns `true' if [22m[34mC[0m is an affine code. A code is called [22m[36maffine[0m
  if  it is an affine space. In other words, a code is affine if it is a coset
  of a linear code.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> IsAffineCode( HammingCode( 3, GF(2) ) );[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsAffineCode( CosetCode( HammingCode( 3, GF(2) ),[0m
    [22m[35m> [ 1, 0, 0, 0, 0, 0, 0 ] ) );[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsAffineCode( NordstromRobinsonCode() );[0m
    [22m[35mfalse [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.3-12 IsAlmostAffineCode[0m
  
  [1m[34m> IsAlmostAffineCode( [0m[22m[34mC[0m[1m[34m ) __________________________________________[0mfunction
  
  [22m[32mIsAlmostAffineCode[0m  returns  `true' if [22m[34mC[0m is an almost affine code. A code is
  called  [22m[36malmost affine[0m if the size of any punctured code of [22m[34mC[0m is q^r for some
  r,  where  q  is  the size of the alphabet of the code. Every affine code is
  also  almost  affine,  and  every  code  over GF(2) and GF(3) that is almost
  affine is also affine.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> code := ElementsCode( [ [0,0,0], [0,1,1], [0,2,2], [0,3,3],[0m
    [22m[35m>                             [1,0,1], [1,1,0], [1,2,3], [1,3,2],[0m
    [22m[35m>                             [2,0,2], [2,1,3], [2,2,0], [2,3,1],[0m
    [22m[35m>                             [3,0,3], [3,1,2], [3,2,1], [3,3,0] ],[0m
    [22m[35m>                             GF(4) );;[0m
    [22m[35mgap> IsAlmostAffineCode( code );[0m
    [22m[35mtrue[0m
    [22m[35mgap> IsAlmostAffineCode( NordstromRobinsonCode() );[0m
    [22m[35mfalse [0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m4.4 Equivalence and Isomorphism of Codes[0m
  
  [1m[4m[31m4.4-1 IsEquivalent[0m
  
  [1m[34m> IsEquivalent( [0m[22m[34mC1, C2[0m[1m[34m ) ___________________________________________[0mfunction
  
  We say that [22m[34mC1[0m is [22m[36mpermutation equivalent[0m to [22m[34mC2[0m if [22m[34mC1[0m can be obtained from [22m[34mC2[0m
  by  carrying out column permutations. [22m[32mIsEquivalent[0m returns true if [22m[34mC1[0m and [22m[34mC2[0m
  are  equivalent codes. At this time, [22m[32mIsEquivalent[0m only handles [22m[36mbinary[0m codes.
  (The  external  unix/linux  program  [1m[46mdesauto[0m  from  J.  S. Leon is called by
  [22m[32mIsEquivalent[0m.) Of course, if [22m[34mC1[0m and [22m[34mC2[0m are equal, they are also equivalent.
  
  Note that the algorithm is [22m[36mvery slow[0m for non-linear codes.
  
  More  generally,  we  say  that [22m[34mC1[0m is [22m[36mequivalent[0m to [22m[34mC2[0m if [22m[34mC1[0m can be obtained
  from  [22m[34mC2[0m  by  carrying  out  column  permutations  and  a permutation of the
  alphabet.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> x:= Indeterminate( GF(2) );; pol:= x^3+x+1; [0m
    [22m[35mZ(2)^0+x_1+x_1^3[0m
    [22m[35mgap> H := GeneratorPolCode( pol, 7, GF(2));          [0m
    [22m[35ma cyclic [7,4,1..3]1 code defined by generator polynomial over GF(2)[0m
    [22m[35mgap> H = HammingCode(3, GF(2));[0m
    [22m[35mfalse[0m
    [22m[35mgap> IsEquivalent(H, HammingCode(3, GF(2)));[0m
    [22m[35mtrue                        # H is equivalent to a Hamming code[0m
    [22m[35mgap> CodeIsomorphism(H, HammingCode(3, GF(2)));[0m
    [22m[35m(3,4)(5,6,7) [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.4-2 CodeIsomorphism[0m
  
  [1m[34m> CodeIsomorphism( [0m[22m[34mC1, C2[0m[1m[34m ) ________________________________________[0mfunction
  
  If   the  two  codes  [22m[34mC1[0m  and  [22m[34mC2[0m  are  permutation  equivalent  codes  (see
  [1m[34mIsEquivalent[0m   ([1m4.4-1[0m)),   [22m[32mCodeIsomorphism[0m   returns  the  permutation  that
  transforms [22m[34mC1[0m into [22m[34mC2[0m. If the codes are not equivalent, it returns `false'.
  
  At  this  time, [22m[32mIsEquivalent[0m only computes isomorphisms between [22m[36mbinary[0m codes
  on a linux/unix computer (since it calls Leon's C program [1m[46mdesauto[0m).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> x:= Indeterminate( GF(2) );; pol:= x^3+x+1; [0m
    [22m[35mZ(2)^0+x_1+x_1^3[0m
    [22m[35mgap> H := GeneratorPolCode( pol, 7, GF(2));          [0m
    [22m[35ma cyclic [7,4,1..3]1 code defined by generator polynomial over GF(2)[0m
    [22m[35mgap> CodeIsomorphism(H, HammingCode(3, GF(2)));[0m
    [22m[35m(3,4)(5,6,7) [0m
    [22m[35mgap> PermutedCode(H, (3,4)(5,6,7)) = HammingCode(3, GF(2));[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.4-3 AutomorphismGroup[0m
  
  [1m[34m> AutomorphismGroup( [0m[22m[34mC[0m[1m[34m ) ___________________________________________[0mfunction
  
  [22m[32mAutomorphismGroup[0m  returns  the automorphism group of a linear code [22m[34mC[0m. For a
  binary  code,  the  automorphism  group  is the largest permutation group of
  degree n such that each permutation applied to the columns of [22m[34mC[0m again yields
  [22m[34mC[0m.  [1mGUAVA[0m  calls  the  external program [1m[46mdesauto[0m written by J. S. Leon, if it
  exists, to compute the automorphism group. If Leon's program is not compiled
  on  the system (and in the default directory) then it calls instead the much
  slower program [22m[32mPermutationAutomorphismGroup[0m.
  
  See  Leon  [L82]  for  a  more  precise  description  of the method, and the
  [1mguava/src/leon/doc[0m subdirectory for for details about Leon's C programs.
  
  The  function  [22m[32mPermutedCode[0m permutes the columns of a code (see [1m[34mPermutedCode[0m
  ([1m6.1-4[0m)).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> R := RepetitionCode(7,GF(2));[0m
    [22m[35ma cyclic [7,1,7]3 repetition code over GF(2)[0m
    [22m[35mgap> AutomorphismGroup(R);[0m
    [22m[35mSym( [ 1 .. 7 ] )[0m
    [22m[35m                        # every permutation keeps R identical[0m
    [22m[35mgap> C := CordaroWagnerCode(7);[0m
    [22m[35ma linear [7,2,4]3 Cordaro-Wagner code over GF(2)[0m
    [22m[35mgap> AsSSortedList(C);[0m
    [22m[35m[ [ 0 0 0 0 0 0 0 ], [ 0 0 1 1 1 1 1 ], [ 1 1 0 0 0 1 1 ], [ 1 1 1 1 1 0 0 ] ][0m
    [22m[35mgap> AutomorphismGroup(C);[0m
    [22m[35mGroup([ (3,4), (4,5), (1,6)(2,7), (1,2), (6,7) ])[0m
    [22m[35mgap> C2 :=  PermutedCode(C, (1,6)(2,7));[0m
    [22m[35ma linear [7,2,4]3 permuted code[0m
    [22m[35mgap> AsSSortedList(C2);[0m
    [22m[35m[ [ 0 0 0 0 0 0 0 ], [ 0 0 1 1 1 1 1 ], [ 1 1 0 0 0 1 1 ], [ 1 1 1 1 1 0 0 ] ][0m
    [22m[35mgap> C2 = C;[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.4-4 PermutationAutomorphismGroup[0m
  
  [1m[34m> PermutationAutomorphismGroup( [0m[22m[34mC[0m[1m[34m ) ________________________________[0mfunction
  
  [22m[32mPermutationAutomorphismGroup[0m returns the permutation automorphism group of a
  linear  code  [22m[34mC[0m. This is the largest permutation group of degree n such that
  each  permutation  applied to the columns of [22m[34mC[0m again yields [22m[34mC[0m. It is written
  in [1mGAP[0m, so is much slower than [22m[32mAutomorphismGroup[0m.
  
  When    [22m[34mC[0m    is    binary   [22m[32mPermutationAutomorphismGroup[0m   does   [22m[36mnot[0m   call
  [22m[32mAutomorphismGroup[0m,  even though they agree mathematically in that case. This
  way  [22m[32mPermutationAutomorphismGroup[0m  can  be called on any platform which runs
  [1mGAP[0m.
  
  The  older  name for this command, [22m[32mPermutationGroup[0m, will become obsolete in
  the next version of [1mGAP[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> R := RepetitionCode(3,GF(3));[0m
    [22m[35ma cyclic [3,1,3]2 repetition code over GF(3)[0m
    [22m[35mgap> G:=PermutationAutomorphismGroup(R);[0m
    [22m[35mGroup([ (), (1,3), (1,2,3), (2,3), (1,3,2), (1,2) ])[0m
    [22m[35mgap> G=SymmetricGroup(3);[0m
    [22m[35mtrue[0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m4.5 Domain Functions for Codes[0m
  
  These  are  some  [1mGAP[0m  functions  that  work  on `Domains' in general. Their
  specific effect on `Codes' is explained here.
  
  [1m[4m[31m4.5-1 IsFinite[0m
  
  [1m[34m> IsFinite( [0m[22m[34mC[0m[1m[34m ) ____________________________________________________[0mfunction
  
  [22m[32mIsFinite[0m  is  an  implementation  of  the  [1mGAP[0m  domain function [22m[32mIsFinite[0m. It
  returns true for a code [22m[34mC[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> IsFinite( RepetitionCode( 1000, GF(11) ) );[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.5-2 Size[0m
  
  [1m[34m> Size( [0m[22m[34mC[0m[1m[34m ) ________________________________________________________[0mfunction
  
  [22m[32mSize[0m  returns the size of [22m[34mC[0m, the number of elements of the code. If the code
  is  linear, the size of the code is equal to q^k, where q is the size of the
  base field of [22m[34mC[0m and k is the dimension.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> Size( RepetitionCode( 1000, GF(11) ) );[0m
    [22m[35m11[0m
    [22m[35mgap> Size( NordstromRobinsonCode() );[0m
    [22m[35m256 [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.5-3 LeftActingDomain[0m
  
  [1m[34m> LeftActingDomain( [0m[22m[34mC[0m[1m[34m ) ____________________________________________[0mfunction
  
  [22m[32mLeftActingDomain[0m  returns  the  base  field  of  a code [22m[34mC[0m. Each element of [22m[34mC[0m
  consists  of  elements  of  this base field. If the base field is F, and the
  word  length  of the code is n, then the codewords are elements of F^n. If [22m[34mC[0m
  is  a  cyclic  code,  its  elements  are  interpreted  as  polynomials  with
  coefficients over F.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := ElementsCode([[0,0,0], [1,0,1], [0,1,0]], GF(4));[0m
    [22m[35ma (3,3,1..3)2..3 user defined unrestricted code over GF(4)[0m
    [22m[35mgap> LeftActingDomain( C1 );[0m
    [22m[35mGF(2^2)[0m
    [22m[35mgap> LeftActingDomain( HammingCode( 3, GF(9) ) );[0m
    [22m[35mGF(3^2) [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.5-4 Dimension[0m
  
  [1m[34m> Dimension( [0m[22m[34mC[0m[1m[34m ) ___________________________________________________[0mfunction
  
  [22m[32mDimension[0m  returns  the  parameter k of [22m[34mC[0m, the dimension of the code, or the
  number of information symbols in each codeword. The dimension is not defined
  for non-linear codes; [22m[32mDimension[0m then returns an error.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> Dimension( NullCode( 5, GF(5) ) );[0m
    [22m[35m0[0m
    [22m[35mgap> C := BCHCode( 15, 4, GF(4) );[0m
    [22m[35ma cyclic [15,9,5]3..4 BCH code, delta=5, b=1 over GF(4)[0m
    [22m[35mgap> Dimension( C );[0m
    [22m[35m9[0m
    [22m[35mgap> Size( C ) = Size( LeftActingDomain( C ) ) ^ Dimension( C );[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.5-5 AsSSortedList[0m
  
  [1m[34m> AsSSortedList( [0m[22m[34mC[0m[1m[34m ) _______________________________________________[0mfunction
  
  [22m[32mAsSSortedList[0m (as strictly sorted list) returns an immutable, duplicate free
  list  of  the elements of [22m[34mC[0m. For a finite field GF(q) generated by powers of
  Z(q), the ordering on
  
  \[
       GF(q)=\{ 0 , Z(q)^0, Z(q), Z(q)^2, ...Z(q)^{q-2} \}
  \]
  
  is  that  determined  by  the  exponents  i.  These elements are of the type
  codeword  (see  [1m[34mCodeword[0m ([1m3.1-1[0m)). Note that for large codes, generating the
  elements  may  be very time- and memory-consuming. For generating a specific
  element  or  a  subset  of  the  elements,  use  [22m[32mCodewordNr[0m  (see [1m[34mCodewordNr[0m
  ([1m3.1-2[0m)).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := ConferenceCode( 5 );[0m
    [22m[35ma (5,12,2)1..4 conference code over GF(2)[0m
    [22m[35mgap> AsSSortedList( C );[0m
    [22m[35m[ [ 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 ], [0m
    [22m[35m  [ 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 ], [0m
    [22m[35m  [ 1 1 1 0 0 ], [ 1 1 1 1 1 ] ][0m
    [22m[35mgap> CodewordNr( C, [ 1, 2 ] );[0m
    [22m[35m[ [ 0 0 0 0 0 ], [ 0 0 1 1 1 ] ][0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m4.6 Printing and Displaying Codes[0m
  
  [1m[4m[31m4.6-1 Print[0m
  
  [1m[34m> Print( [0m[22m[34mC[0m[1m[34m ) _______________________________________________________[0mfunction
  
  [22m[32mPrint[0m  prints information about [22m[34mC[0m. This is the same as typing the identifier
  [22m[34mC[0m at the [1mGAP[0m-prompt.
  
  If the argument is an unrestricted code, information in the form
  
  
  a (n,M,d)r ... code over GF(q)
  is  printed,  where  [22m[34mn[0m  is  the word length, [22m[34mM[0m the number of elements of the
  code, [22m[34md[0m the minimum distance and [22m[34mr[0m the covering radius.
  
  If the argument is a linear code, information in the form
  
  
  a linear [n,k,d]r ... code over GF(q)
  is  printed,  where [22m[34mn[0m is the word length, [22m[34mk[0m the dimension of the code, [22m[34md[0m the
  minimum distance and [22m[34mr[0m the covering radius.
  
  Except  for codes produced by [22m[32mRandomLinearCode[0m, if [22m[34md[0m is not yet known, it is
  displayed in the form
  
  
  lowerbound..upperbound
  and  if  [22m[34mr[0m  is  not  yet known, it is displayed in the same way. For certain
  ranges  of  n,  the  values  of  [22m[34mlowerbound[0m and [22m[34mupperbound[0m are obtained from
  tables.
  
  The function [22m[32mDisplay[0m gives more information. See [1m[34mDisplay[0m ([1m4.6-3[0m).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := ExtendedCode( HammingCode( 3, GF(2) ) );[0m
    [22m[35ma linear [8,4,4]2 extended code[0m
    [22m[35mgap> Print( "This is ", NordstromRobinsonCode(), ". \n");[0m
    [22m[35mThis is a (16,256,6)4 Nordstrom-Robinson code over GF(2). [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.6-2 String[0m
  
  [1m[34m> String( [0m[22m[34mC[0m[1m[34m ) ______________________________________________________[0mfunction
  
  [22m[32mString[0m  returns  information  about  [22m[34mC[0m in a string. This function is used by
  [22m[32mPrint[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> x:= Indeterminate( GF(3) );; pol:= x^2+1;[0m
    [22m[35mx_1^2+Z(3)^0[0m
    [22m[35mgap> Factors(pol);[0m
    [22m[35m[ x_1^2+Z(3)^0 ][0m
    [22m[35mgap> H := GeneratorPolCode( pol, 8, GF(3));[0m
    [22m[35ma cyclic [8,6,1..2]1..2 code defined by generator polynomial over GF(3)[0m
    [22m[35mgap> String(H);[0m
    [22m[35m"a cyclic [8,6,1..2]1..2 code defined by generator polynomial over GF(3)"[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.6-3 Display[0m
  
  [1m[34m> Display( [0m[22m[34mC[0m[1m[34m ) _____________________________________________________[0mfunction
  
  [22m[32mDisplay[0m  prints  the method of construction of code [22m[34mC[0m. With this history, in
  most  cases  an  equal  or  equivalent code can be reconstructed. If [22m[34mC[0m is an
  unmanipulated code, the result is equal to output of the function [22m[32mPrint[0m (see
  [1m[34mPrint[0m ([1m4.6-1[0m)).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> Display( RepetitionCode( 6, GF(3) ) );[0m
    [22m[35ma cyclic [6,1,6]4 repetition code over GF(3)[0m
    [22m[35mgap> C1 := ExtendedCode( HammingCode(2) );;[0m
    [22m[35mgap> C2 := PuncturedCode( ReedMullerCode( 2, 3 ) );;[0m
    [22m[35mgap> Display( LengthenedCode( UUVCode( C1, C2 ) ) );[0m
    [22m[35ma linear [12,8,2]2..4 code, lengthened with 1 column(s) of[0m
    [22m[35ma linear [11,8,1]1..2 U U+V construction code of[0m
    [22m[35mU: a linear [4,1,4]2 extended code of[0m
    [22m[35m   a linear [3,1,3]1 Hamming (2,2) code over GF(2)[0m
    [22m[35mV: a linear [7,7,1]0 punctured code of[0m
    [22m[35m   a cyclic [8,7,2]1 Reed-Muller (2,3) code over GF(2)[0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m4.7 Generating (Check) Matrices and Polynomials[0m
  
  [1m[4m[31m4.7-1 GeneratorMat[0m
  
  [1m[34m> GeneratorMat( [0m[22m[34mC[0m[1m[34m ) ________________________________________________[0mfunction
  
  [22m[32mGeneratorMat[0m  returns  a  generator  matrix  of  [22m[34mC[0m. The code consists of all
  linear combinations of the rows of this matrix.
  
  If  until  now  no generator matrix of [22m[34mC[0m was determined, it is computed from
  either  the  parity  check  matrix,  the  generator  polynomial,  the  check
  polynomial or the elements (if possible), whichever is available.
  
  If [22m[34mC[0m is a non-linear code, the function returns an error.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> GeneratorMat( HammingCode( 3, GF(2) ) );[0m
    [22m[35m[ [ an immutable GF2 vector of length 7], [0m
    [22m[35m  [ an immutable GF2 vector of length 7], [0m
    [22m[35m  [ an immutable GF2 vector of length 7], [0m
    [22m[35m  [ an immutable GF2 vector of length 7] ][0m
    [22m[35mgap> Display(last);[0m
    [22m[35m 1 1 1 . . . .[0m
    [22m[35m 1 . . 1 1 . .[0m
    [22m[35m . 1 . 1 . 1 .[0m
    [22m[35m 1 1 . 1 . . 1[0m
    [22m[35mgap> GeneratorMat( RepetitionCode( 5, GF(25) ) );[0m
    [22m[35m[ [ Z(5)^0, Z(5)^0, Z(5)^0, Z(5)^0, Z(5)^0 ] ][0m
    [22m[35mgap> GeneratorMat( NullCode( 14, GF(4) ) );[0m
    [22m[35m[  ][0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.7-2 CheckMat[0m
  
  [1m[34m> CheckMat( [0m[22m[34mC[0m[1m[34m ) ____________________________________________________[0mfunction
  
  [22m[32mCheckMat[0m  returns a parity check matrix of [22m[34mC[0m. The code consists of all words
  orthogonal  to  each of the rows of this matrix. The transpose of the matrix
  is  a  right  inverse  of  the  generator matrix. The parity check matrix is
  computed  from  either  the  generator matrix, the generator polynomial, the
  check polynomial or the elements of [22m[34mC[0m (if possible), whichever is available.
  
  If [22m[34mC[0m is a non-linear code, the function returns an error.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> CheckMat( HammingCode(3, GF(2) ) );[0m
    [22m[35m[ [ 0*Z(2), 0*Z(2), 0*Z(2), Z(2)^0, Z(2)^0, Z(2)^0, Z(2)^0 ], [0m
    [22m[35m  [ 0*Z(2), Z(2)^0, Z(2)^0, 0*Z(2), 0*Z(2), Z(2)^0, Z(2)^0 ],[0m
    [22m[35m  [ Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0 ] ][0m
    [22m[35mgap> Display(last);[0m
    [22m[35m . . . 1 1 1 1[0m
    [22m[35m . 1 1 . . 1 1[0m
    [22m[35m 1 . 1 . 1 . 1[0m
    [22m[35mgap> CheckMat( RepetitionCode( 5, GF(25) ) );[0m
    [22m[35m[ [ Z(5)^0, Z(5)^2, 0*Z(5), 0*Z(5), 0*Z(5) ],[0m
    [22m[35m  [ 0*Z(5), Z(5)^0, Z(5)^2, 0*Z(5), 0*Z(5) ],[0m
    [22m[35m  [ 0*Z(5), 0*Z(5), Z(5)^0, Z(5)^2, 0*Z(5) ],[0m
    [22m[35m  [ 0*Z(5), 0*Z(5), 0*Z(5), Z(5)^0, Z(5)^2 ] ][0m
    [22m[35mgap> CheckMat( WholeSpaceCode( 12, GF(4) ) );[0m
    [22m[35m[  ] [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.7-3 GeneratorPol[0m
  
  [1m[34m> GeneratorPol( [0m[22m[34mC[0m[1m[34m ) ________________________________________________[0mfunction
  
  [22m[32mGeneratorPol[0m returns the generator polynomial of [22m[34mC[0m. The code consists of all
  multiples  of  the  generator  polynomial  modulo x^n-1, where n is the word
  length  of  [22m[34mC[0m.  The generator polynomial is determined from either the check
  polynomial,  the  generator  or  check  matrix  or  the  elements  of  [22m[34mC[0m (if
  possible), whichever is available.
  
  If [22m[34mC[0m is not a cyclic code, the function returns `false'.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> GeneratorPol(GeneratorMatCode([[1, 1, 0], [0, 1, 1]], GF(2)));[0m
    [22m[35mZ(2)^0+x_1[0m
    [22m[35mgap> GeneratorPol( WholeSpaceCode( 4, GF(2) ) );[0m
    [22m[35mZ(2)^0[0m
    [22m[35mgap> GeneratorPol( NullCode( 7, GF(3) ) );[0m
    [22m[35m-Z(3)^0+x_1^7[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.7-4 CheckPol[0m
  
  [1m[34m> CheckPol( [0m[22m[34mC[0m[1m[34m ) ____________________________________________________[0mfunction
  
  [22m[32mCheckPol[0m  returns  the  check  polynomial  of  [22m[34mC[0m.  The  code consists of all
  polynomials f with
  
  \[
       f\cdot h \equiv 0 \ ({\rm mod}\ x^n-1),
  \]
  
  where  h  is  the check polynomial, and n is the word length of [22m[34mC[0m. The check
  polynomial  is  computed  from  the  generator  polynomial, the generator or
  parity  check  matrix  or  the  elements  of  [22m[34mC[0m  (if possible), whichever is
  available.
  
  If [22m[34mC[0m if not a cyclic code, the function returns an error.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> CheckPol(GeneratorMatCode([[1, 1, 0], [0, 1, 1]], GF(2)));[0m
    [22m[35mZ(2)^0+x_1+x_1^2[0m
    [22m[35mgap> CheckPol(WholeSpaceCode(4, GF(2)));[0m
    [22m[35mZ(2)^0+x_1^4[0m
    [22m[35mgap> CheckPol(NullCode(7,GF(3)));[0m
    [22m[35mZ(3)^0[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.7-5 RootsOfCode[0m
  
  [1m[34m> RootsOfCode( [0m[22m[34mC[0m[1m[34m ) _________________________________________________[0mfunction
  
  [22m[32mRootsOfCode[0m  returns  a  list  of all zeros of the generator polynomial of a
  cyclic code [22m[34mC[0m. These are finite field elements in the splitting field of the
  generator  polynomial, GF(q^m), m is the multiplicative order of the size of
  the base field of the code, modulo the word length.
  
  The reverse process, constructing a code from a set of roots, can be carried
  out by the function [22m[32mRootsCode[0m (see [1m[34mRootsCode[0m ([1m5.5-3[0m)).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := ReedSolomonCode( 16, 5 );[0m
    [22m[35ma cyclic [16,12,5]3..4 Reed-Solomon code over GF(17)[0m
    [22m[35mgap> RootsOfCode( C1 );[0m
    [22m[35m[ Z(17), Z(17)^2, Z(17)^3, Z(17)^4 ][0m
    [22m[35mgap> C2 := RootsCode( 16, last );[0m
    [22m[35ma cyclic [16,12,5]3..4 code defined by roots over GF(17)[0m
    [22m[35mgap> C1 = C2;[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m4.8 Parameters of Codes[0m
  
  [1m[4m[31m4.8-1 WordLength[0m
  
  [1m[34m> WordLength( [0m[22m[34mC[0m[1m[34m ) __________________________________________________[0mfunction
  
  [22m[32mWordLength[0m  returns  the  parameter n of [22m[34mC[0m, the word length of the elements.
  Elements  of  cyclic  codes  are  polynomials  of  maximum  degree  n-1,  as
  calculations are carried out modulo x^n-1.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> WordLength( NordstromRobinsonCode() );[0m
    [22m[35m16[0m
    [22m[35mgap> WordLength( PuncturedCode( WholeSpaceCode(7) ) );[0m
    [22m[35m6[0m
    [22m[35mgap> WordLength( UUVCode( WholeSpaceCode(7), RepetitionCode(7) ) );[0m
    [22m[35m14 [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.8-2 Redundancy[0m
  
  [1m[34m> Redundancy( [0m[22m[34mC[0m[1m[34m ) __________________________________________________[0mfunction
  
  [22m[32mRedundancy[0m  returns  the  redundancy r of [22m[34mC[0m, which is equal to the number of
  check  symbols  in each element. If [22m[34mC[0m is not a linear code the redundancy is
  not defined and [22m[32mRedundancy[0m returns an error.
  
  If  a  linear  code  [22m[34mC[0m  has dimension k and word length n, it has redundancy
  r=n-k.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := TernaryGolayCode();[0m
    [22m[35ma cyclic [11,6,5]2 ternary Golay code over GF(3)[0m
    [22m[35mgap> Redundancy(C);[0m
    [22m[35m5[0m
    [22m[35mgap> Redundancy( DualCode(C) );[0m
    [22m[35m6 [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.8-3 MinimumDistance[0m
  
  [1m[34m> MinimumDistance( [0m[22m[34mC[0m[1m[34m ) _____________________________________________[0mfunction
  
  [22m[32mMinimumDistance[0m  returns  the  minimum  distance of [22m[34mC[0m, the largest integer d
  with  the property that every element of [22m[34mC[0m has at least a Hamming distance d
  (see  [1m[34mDistanceCodeword[0m ([1m3.6-2[0m)) to any other element of [22m[34mC[0m. For linear codes,
  the  minimum  distance  is equal to the minimum weight. This means that d is
  also    the    smallest   positive   value   with   w[d+1]   <>   0,   where
  w=(w[1],w[2],...,w[n])    is    the    weight   distribution   of   [22m[34mC[0m   (see
  [1m[34mWeightDistribution[0m  ([1m4.9-2[0m)).  For  unrestricted  codes,  d  is the smallest
  positive value with w[d+1] <> 0, where w is the inner distribution of [22m[34mC[0m (see
  [1m[34mInnerDistribution[0m ([1m4.9-3[0m)).
  
  For codes with only one element, the minimum distance is defined to be equal
  to the word length.
  
  For  linear  codes [22m[34mC[0m, the algorithm used is the following: After replacing [22m[34mC[0m
  by  a permutation equivalent [22m[34mC'[0m, one may assume the generator matrix has the
  following  form G=(I_k , | , A), for some ktimes (n-k) matrix A. If A=0 then
  return  d(C)=1.  Next,  find the minimum distance of the code spanned by the
  rows  of  A.  Call  this  distance  d(A). Note that d(A) is equal to the the
  Hamming  distance  d(v,0)  where  v  is  some proper linear combination of i
  distinct rows of A. Return d(C)=d(A)+i, where i is as in the previous step.
  
  This  command  may also be called using the syntax [22m[32mMinimumDistance(C, w)[0m. In
  this  form,  [22m[32mMinimumDistance[0m returns the minimum distance of a codeword [22m[34mw[0m to
  the code [22m[34mC[0m, also called the [22m[36mdistance from [22m[34mw[0m to[0m [22m[34mC[0m. This is the smallest value
  d  for which there is an element c of the code [22m[34mC[0m which is at distance d from
  [22m[34mw[0m.  So  d  is  also  the minimum value for which D[d+1] <> 0, where D is the
  distance distribution of [22m[34mw[0m to [22m[34mC[0m (see [1m[34mDistancesDistribution[0m ([1m4.9-4[0m)).
  
  Note  that  [22m[34mw[0m must be an element of the same vector space as the elements of
  [22m[34mC[0m.  [22m[34mw[0m  does  not  necessarily  belong  to  the code (if it does, the minimum
  distance is zero).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := MOLSCode(7);; MinimumDistance(C);[0m
    [22m[35m3[0m
    [22m[35mgap> WeightDistribution(C);[0m
    [22m[35m[ 1, 0, 0, 24, 24 ][0m
    [22m[35mgap> MinimumDistance( WholeSpaceCode( 5, GF(3) ) );[0m
    [22m[35m1[0m
    [22m[35mgap> MinimumDistance( NullCode( 4, GF(2) ) );[0m
    [22m[35m4[0m
    [22m[35mgap> C := ConferenceCode(9);; MinimumDistance(C);[0m
    [22m[35m4[0m
    [22m[35mgap> InnerDistribution(C);[0m
    [22m[35m[ 1, 0, 0, 0, 63/5, 9/5, 18/5, 0, 9/10, 1/10 ] [0m
    [22m[35mgap> C := MOLSCode(7);; w := CodewordNr( C, 17 );[0m
    [22m[35m[ 3 3 6 2 ][0m
    [22m[35mgap> MinimumDistance( C, w );[0m
    [22m[35m0[0m
    [22m[35mgap> C := RemovedElementsCode( C, w );; MinimumDistance( C, w );[0m
    [22m[35m3                           # so w no longer belongs to C [0m
  [22m[35m------------------------------------------------------------------[0m
  
  See  also  the  [1mGUAVA[0m commands relating to bounds on the minimum distance in
  section [1m7.1[0m.
  
  [1m[4m[31m4.8-4 MinimumDistanceLeon[0m
  
  [1m[34m> MinimumDistanceLeon( [0m[22m[34mC[0m[1m[34m ) _________________________________________[0mfunction
  
  [22m[32mMinimumDistanceLeon[0m  returns  the  ``probable'' minimum distance d_Leon of a
  linear  binary  code  [22m[34mC[0m,  using  an  implementation  of Leon's probabilistic
  polynomial  time  algorithm.  Briefly: Let [22m[34mC[0m be a linear code of dimension k
  over  GF(q)  as above. The algorithm has input parameters s and rho, where s
  is an integer between 2 and n-k, and rho is an integer between 2 and k.
  
  --    Find a generator matrix G of C.
  
  --    Randomly permute the columns of G.
  
  --    Perform  Gaussian  elimination  on the permuted matrix to obtain a new
        matrix of the following form:
  
  \[
             G=(I_{k} \, | \, Z \, | \, B)
  \]
  
        with  Z  a  ktimes s matrix. If (Z,B) is the zero matrix then return 1
        for  the minimum distance. If Z=0 but not B then either choose another
        permutation of the rows of [22m[34mC[0m or return `method fails'.
  
  --    Search  Z  for  at most rho rows that lead to codewords of weight less
        than rho.
  
  --    For these codewords, compute the weight of the whole word in [22m[34mC[0m. Return
        this weight.
  
  (See  for  example J. S. Leon, [L88] for more details.) Sometimes (as is the
  case  in  [1mGUAVA[0m)  this probabilistic algorithm is repeated several times and
  the most commonly occurring value is taken.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C:=RandomLinearCode(50,22,GF(2));[0m
    [22m[35ma  [50,22,?] randomly generated code over GF(2)[0m
    [22m[35mgap> MinimumDistanceLeon(C); time;[0m
    [22m[35m6[0m
    [22m[35m211[0m
    [22m[35mgap> MinimumDistance(C); time;[0m
    [22m[35m6[0m
    [22m[35m1204[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.8-5 DecreaseMinimumDistanceUpperBound[0m
  
  [1m[34m> DecreaseMinimumDistanceUpperBound( [0m[22m[34mC, t, m[0m[1m[34m ) _____________________[0mfunction
  
  [22m[32mDecreaseMinimumDistanceUpperBound[0m  is an implementation of the algorithm for
  the minimum distance of a linear binary code [22m[34mC[0m by Leon [L88]. This algorithm
  tries  to  find  codewords with small minimum weights. The parameter [22m[34mt[0m is at
  least  1  and less than the dimension of [22m[34mC[0m. The best results are obtained if
  it  is  close to the dimension of the code. The parameter [22m[34mm[0m gives the number
  of runs that the algorithm will perform.
  
  The  result  returned is a record with two fields; the first, [22m[32mmindist[0m, gives
  the  lowest  weight  found, and [22m[32mword[0m gives the corresponding codeword. (This
  was  implemented  before  [22m[32mMinimumDistanceLeon[0m  but  independently. The older
  manual  had  given  the  command  incorrectly, so the command was only found
  after  reading  all  the  [22m[36m*.gi[0m  files  in  the  [1mGUAVA[0m  library.  Though both
  [22m[32mMinimumDistance[0m   and   [22m[32mMinimumDistanceLeon[0m   often  run  much  faster  than
  [22m[32mDecreaseMinimumDistanceUpperBound[0m, [22m[32mDecreaseMinimumDistanceUpperBound[0m appears
  to be more accurate than [22m[32mMinimumDistanceLeon[0m.)
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C:=RandomLinearCode(5,2,GF(2));[0m
    [22m[35ma  [5,2,?] randomly generated code over GF(2)[0m
    [22m[35mgap> DecreaseMinimumDistanceUpperBound(C,1,4);[0m
    [22m[35mrec( mindist := 3, word := [ 0*Z(2), Z(2)^0, Z(2)^0, 0*Z(2), Z(2)^0 ] )[0m
    [22m[35mgap> MinimumDistance(C);[0m
    [22m[35m3[0m
    [22m[35mgap> C:=RandomLinearCode(8,4,GF(2));[0m
    [22m[35ma  [8,4,?] randomly generated code over GF(2)[0m
    [22m[35mgap> DecreaseMinimumDistanceUpperBound(C,3,4);[0m
    [22m[35mrec( mindist := 2,[0m
    [22m[35m  word := [ Z(2)^0, 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), Z(2)^0 ] )[0m
    [22m[35mgap> MinimumDistance(C);[0m
    [22m[35m2[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.8-6 MinimumDistanceRandom[0m
  
  [1m[34m> MinimumDistanceRandom( [0m[22m[34mC, num, s[0m[1m[34m ) _______________________________[0mfunction
  
  [22m[32mMinimumDistanceRandom[0m  returns  an  upper  bound  for  the  minimum distance
  d_random  of  a  linear binary code [22m[34mC[0m, using a probabilistic polynomial time
  algorithm.  Briefly:  Let  [22m[34mC[0m  be  a linear code of dimension k over GF(q) as
  above.  The  algorithm has input parameters num and s, where s is an integer
  between 2 and n-1, and num is an integer greater than or equal to 1.
  
  --    Find a generator matrix G of C.
  
  --    Randomly permute the columns of G, written G_p..
  
  --
             G=(A, B)
  \]
  
        with  A a ktimes s matrix. If A is the zero matrix then return `method
        fails'.
  
  --    Search  A  for  at most 5 rows that lead to codewords, in the code C_A
        with generator matrix A, of minimum weight.
  
  --    For  these codewords, use the associated linear combination to compute
        the weight of the whole word in [22m[34mC[0m. Return this weight and codeword.
  
  This  probabilistic  algorithm  is repeated [22m[34mnum[0m times (with different random
  permutations  of the rows of G each time) and the weight and codeword of the
  lowest occurring weight is taken.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C:=RandomLinearCode(60,20,GF(2));[0m
    [22m[35ma  [60,20,?] randomly generated code over GF(2)[0m
    [22m[35mgap> #mindist(C);time;[0m
    [22m[35mgap> #mindistleon(C,10,30);time; #doesn't work well[0m
    [22m[35mgap> a:=MinimumDistanceRandom(C,10,30);time; # done 10 times -with fastest time!![0m
    [22m[35m[0m
    [22m[35m This is a probabilistic algorithm which may return the wrong answer.[0m
    [22m[35m[ 12, [ 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 [0m
    [22m[35m        1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 ] ][0m
    [22m[35m130[0m
    [22m[35mgap> a[2] in C;[0m
    [22m[35mtrue[0m
    [22m[35mgap> b:=DecreaseMinimumDistanceUpperBound(C,10,1); time; #only done once![0m
    [22m[35mrec( mindist := 12, word := [ 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), [0m
    [22m[35m      Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), [0m
    [22m[35m      0*Z(2), Z(2)^0, Z(2)^0, 0*Z(2), 0*Z(2), Z(2)^0, 0*Z(2), 0*Z(2), 0*Z(2), [0m
    [22m[35m      Z(2)^0, 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), Z(2)^0, 0*Z(2), [0m
    [22m[35m      0*Z(2), Z(2)^0, 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), [0m
    [22m[35m      0*Z(2), 0*Z(2), Z(2)^0, 0*Z(2), 0*Z(2), 0*Z(2), Z(2)^0, 0*Z(2), 0*Z(2), [0m
    [22m[35m      0*Z(2), 0*Z(2), Z(2)^0, 0*Z(2), 0*Z(2), 0*Z(2), 0*Z(2), Z(2)^0, 0*Z(2) ] )[0m
    [22m[35m649[0m
    [22m[35mgap> Codeword(b!.word) in C;[0m
    [22m[35mtrue[0m
    [22m[35mgap> MinimumDistance(C);time;[0m
    [22m[35m12[0m
    [22m[35m196[0m
    [22m[35mgap> c:=MinimumDistanceLeon(C);time;[0m
    [22m[35m12[0m
    [22m[35m66[0m
    [22m[35mgap> C:=RandomLinearCode(30,10,GF(3));[0m
    [22m[35ma  [30,10,?] randomly generated code over GF(3)[0m
    [22m[35mgap> a:=MinimumDistanceRandom(C,10,10);time;[0m
    [22m[35m[0m
    [22m[35m This is a probabilistic algorithm which may return the wrong answer.[0m
    [22m[35m[ 13, [ 0 0 0 1 0 0 0 0 0 0 1 0 2 2 1 1 0 2 2 0 1 0 2 1 0 0 0 1 0 2 ] ][0m
    [22m[35m229[0m
    [22m[35mgap> a[2] in C;[0m
    [22m[35mtrue[0m
    [22m[35mgap> MinimumDistance(C);time;[0m
    [22m[35m9[0m
    [22m[35m45[0m
    [22m[35mgap> c:=MinimumDistanceLeon(C);[0m
    [22m[35mCode must be binary. Quitting.[0m
    [22m[35m0[0m
    [22m[35mgap> a:=MinimumDistanceRandom(C,1,29);time;[0m
    [22m[35m[0m
    [22m[35m This is a probabilistic algorithm which may return the wrong answer.[0m
    [22m[35m[ 10, [ 0 0 1 0 2 0 2 0 1 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 2 2 2 0 ] ][0m
    [22m[35m53[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.8-7 CoveringRadius[0m
  
  [1m[34m> CoveringRadius( [0m[22m[34mC[0m[1m[34m ) ______________________________________________[0mfunction
  
  [22m[32mCoveringRadius[0m  returns  the [22m[36mcovering radius[0m of a linear code [22m[34mC[0m. This is the
  smallest  number  r  with  the  property  that each element v of the ambient
  vector space of [22m[34mC[0m has at most a distance r to the code [22m[34mC[0m. So for each vector
  v  there  must  be an element c of [22m[34mC[0m with d(v,c) <= r. The smallest covering
  radius  of  any  [n,k] binary linear code is denoted t(n,k). A binary linear
  code with reasonable small covering radius is called a [22m[36mcovering code[0m.
  
  If  [22m[34mC[0m  is a perfect code (see [1m[34mIsPerfectCode[0m ([1m4.3-6[0m)), the covering radius is
  equal  to t, the number of errors the code can correct, where d = 2t+1, with
  d the minimum distance of [22m[34mC[0m (see [1m[34mMinimumDistance[0m ([1m4.8-3[0m)).
  
  If  there exists a function called [22m[32mSpecialCoveringRadius[0m in the `operations'
  field of the code, then this function will be called to compute the covering
  radius   of  the  code.  At  the  moment,  no  code-specific  functions  are
  implemented.
  
  If the length of [22m[32mBoundsCoveringRadius[0m (see [1m[34mBoundsCoveringRadius[0m ([1m7.2-1[0m)), is
  1, then the value in
  
  
  C.boundsCoveringRadius
  is returned. Otherwise, the function
  
  
  C.operations.CoveringRadius
  is  executed,  unless  the redundancy of [22m[34mC[0m is too large. In the last case, a
  warning is issued.
  
  The  algorithm  used to compute the covering radius is the following. First,
  [22m[32mCosetLeadersMatFFE[0m  is  used  to  compute  the  list of coset leaders (which
  returns  a  codeword  in  each  coset  of GF(q)^n/C of minimum weight). Then
  [22m[32mWeightVecFFE[0m  is  used to compute the weight of each of these coset leaders.
  The program returns the maximum of these weights.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> H := RandomLinearCode(10, 5, GF(2));[0m
    [22m[35ma  [10,5,?] randomly generated code over GF(2)[0m
    [22m[35mgap> CoveringRadius(H);[0m
    [22m[35m3[0m
    [22m[35mgap> H := HammingCode(4, GF(2));; IsPerfectCode(H);[0m
    [22m[35mtrue[0m
    [22m[35mgap> CoveringRadius(H);[0m
    [22m[35m1                       # Hamming codes have minimum distance 3[0m
    [22m[35mgap> CoveringRadius(ReedSolomonCode(7,4));[0m
    [22m[35m3 [0m
    [22m[35mgap> CoveringRadius( BCHCode( 17, 3, GF(2) ) );[0m
    [22m[35m3[0m
    [22m[35mgap> CoveringRadius( HammingCode( 5, GF(2) ) );[0m
    [22m[35m1[0m
    [22m[35mgap> C := ReedMullerCode( 1, 9 );;[0m
    [22m[35mgap> CoveringRadius( C );[0m
    [22m[35mCoveringRadius: warning, the covering radius of[0m
    [22m[35mthis code cannot be computed straightforward.[0m
    [22m[35mTry to use IncreaseCoveringRadiusLowerBound( code ).[0m
    [22m[35m(see the manual for more details).[0m
    [22m[35mThe covering radius of code lies in the interval:[0m
    [22m[35m[ 240 .. 248 ][0m
  [22m[35m------------------------------------------------------------------[0m
  
  See  also  the  [1mGUAVA[0m commands relating to bounds on the minimum distance in
  section [1m7.2[0m.
  
  [1m[4m[31m4.8-8 SetCoveringRadius[0m
  
  [1m[34m> SetCoveringRadius( [0m[22m[34mC, intlist[0m[1m[34m ) __________________________________[0mfunction
  
  [22m[32mSetCoveringRadius[0m  enables  the  user  to  set  the covering radius herself,
  instead  of  letting  [1mGUAVA[0m compute it. If [22m[34mintlist[0m is an integer, [1mGUAVA[0m will
  simply  put  it  in  the  `boundsCoveringRadius'  field.  If it is a list of
  integers,    however,    it    will    intersect    this   list   with   the
  `boundsCoveringRadius'  field,  thus  taking the best of both lists. If this
  would  leave  an empty list, the field is set to [22m[34mintlist[0m. Because some other
  computations  use  the covering radius of the code, it is important that the
  entered value is not wrong, otherwise new results may be invalid.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := BCHCode( 17, 3, GF(2) );;[0m
    [22m[35mgap> BoundsCoveringRadius( C );[0m
    [22m[35m[ 3 .. 4 ][0m
    [22m[35mgap> SetCoveringRadius( C, [ 2 .. 3 ] );[0m
    [22m[35mgap> BoundsCoveringRadius( C );[0m
    [22m[35m[ [ 2 .. 3 ] ][0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m4.9 Distributions[0m
  
  [1m[4m[31m4.9-1 MinimumWeightWords[0m
  
  [1m[34m> MinimumWeightWords( [0m[22m[34mC[0m[1m[34m ) __________________________________________[0mfunction
  
  [22m[32mMinimumWeightWords[0m returns the list of minimum weight codewords of [22m[34mC[0m.
  
  This  algorithm  is  written  in  GAP is slow, so is only suitable for small
  codes.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C:=HammingCode(3,GF(2));[0m
    [22m[35ma linear [7,4,3]1 Hamming (3,2) code over GF(2)[0m
    [22m[35mgap> MinimumWeightWords(C);[0m
    [22m[35m[ [ 1 0 0 0 0 1 1 ], [ 0 1 0 1 0 1 0 ], [ 0 1 0 0 1 0 1 ], [ 1 0 0 1 1 0 0 ], [ 0 0 1 0 1 1 0 ],[0m
    [22m[35m  [ 0 0 1 1 0 0 1 ], [ 1 1 1 0 0 0 0 ] ][0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.9-2 WeightDistribution[0m
  
  [1m[34m> WeightDistribution( [0m[22m[34mC[0m[1m[34m ) __________________________________________[0mfunction
  
  [22m[32mWeightDistribution[0m  returns  the  weight distribution of [22m[34mC[0m, as a vector. The
  i^th element of this vector contains the number of elements of [22m[34mC[0m with weight
  i-1.  For  linear  codes,  the  weight  distribution  is  equal to the inner
  distribution   (see   [1m[34mInnerDistribution[0m   ([1m4.9-3[0m)).   If  w  is  the  weight
  distribution of a linear code [22m[34mC[0m, it must have the zero codeword, so w[1] = 1
  (one word of weight 0).
  
  Some   codes,   such   as   the   Hamming  codes,  have  precomputed  weight
  distributions.  For  others,  the  program  WeightDistribution calls the [1mGAP[0m
  program  [22m[32mDistancesDistributionMatFFEVecFFE[0m,  which is written in C. See also
  [22m[32mCodeWeightEnumerator[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> WeightDistribution( ConferenceCode(9) );[0m
    [22m[35m[ 1, 0, 0, 0, 0, 18, 0, 0, 0, 1 ][0m
    [22m[35mgap> WeightDistribution( RepetitionCode( 7, GF(4) ) );[0m
    [22m[35m[ 1, 0, 0, 0, 0, 0, 0, 3 ][0m
    [22m[35mgap> WeightDistribution( WholeSpaceCode( 5, GF(2) ) );[0m
    [22m[35m[ 1, 5, 10, 10, 5, 1 ] [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.9-3 InnerDistribution[0m
  
  [1m[34m> InnerDistribution( [0m[22m[34mC[0m[1m[34m ) ___________________________________________[0mfunction
  
  [22m[32mInnerDistribution[0m  returns  the inner distribution of [22m[34mC[0m. The i^th element of
  the  vector  contains the average number of elements of [22m[34mC[0m at distance i-1 to
  an  element  of  [22m[34mC[0m. For linear codes, the inner distribution is equal to the
  weight distribution (see [1m[34mWeightDistribution[0m ([1m4.9-2[0m)).
  
  Suppose  w  is  the  inner  distribution  of  [22m[34mC[0m. Then w[1] = 1, because each
  element  of [22m[34mC[0m has exactly one element at distance zero (the element itself).
  The  minimum  distance  of  [22m[34mC[0m  is the smallest value d > 0 with w[d+1] <> 0,
  because  a  distance  between  zero  and d never occurs. See [1m[34mMinimumDistance[0m
  ([1m4.8-3[0m).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> InnerDistribution( ConferenceCode(9) );[0m
    [22m[35m[ 1, 0, 0, 0, 63/5, 9/5, 18/5, 0, 9/10, 1/10 ][0m
    [22m[35mgap> InnerDistribution( RepetitionCode( 7, GF(4) ) );[0m
    [22m[35m[ 1, 0, 0, 0, 0, 0, 0, 3 ] [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.9-4 DistancesDistribution[0m
  
  [1m[34m> DistancesDistribution( [0m[22m[34mC, w[0m[1m[34m ) ____________________________________[0mfunction
  
  [22m[32mDistancesDistribution[0m  returns  the  distribution  of  the  distances of all
  elements  of [22m[34mC[0m to a codeword [22m[34mw[0m in the same vector space. The i^th element of
  the distance distribution is the number of codewords of [22m[34mC[0m that have distance
  i-1  to [22m[34mw[0m. The smallest value d with w[d+1] <> 0, is defined as the [22m[36mdistance
  to[0m [22m[34mC[0m (see [1m[34mMinimumDistance[0m ([1m4.8-3[0m)).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> H := HadamardCode(20);[0m
    [22m[35ma (20,40,10)6..8 Hadamard code of order 20 over GF(2)[0m
    [22m[35mgap> c := Codeword("10110101101010010101", H);[0m
    [22m[35m[ 1 0 1 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 ][0m
    [22m[35mgap> DistancesDistribution(H, c);[0m
    [22m[35m[ 0, 0, 0, 0, 0, 1, 0, 7, 0, 12, 0, 12, 0, 7, 0, 1, 0, 0, 0, 0, 0 ][0m
    [22m[35mgap> MinimumDistance(H, c);[0m
    [22m[35m5                           # distance to H [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.9-5 OuterDistribution[0m
  
  [1m[34m> OuterDistribution( [0m[22m[34mC[0m[1m[34m ) ___________________________________________[0mfunction
  
  The  function [22m[32mOuterDistribution[0m returns a list of length q^n, where q is the
  size  of  the  base field of [22m[34mC[0m and n is the word length. The elements of the
  list  consist  of  pairs,  the  first coordinate being an element of GF(q)^n
  (this  is a codeword type) and the second coordinate being a distribution of
  distances  to  the  code (a list of integers). This table is [22m[36mvery[0m large, and
  for  n  >  20  it will not fit in the memory of most computers. The function
  [22m[32mDistancesDistribution[0m  (see  [1m[34mDistancesDistribution[0m  ([1m4.9-4[0m))  can be used to
  calculate one entry of the list.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := RepetitionCode( 3, GF(2) );[0m
    [22m[35ma cyclic [3,1,3]1 repetition code over GF(2)[0m
    [22m[35mgap> OD := OuterDistribution(C);[0m
    [22m[35m[ [ [ 0 0 0 ], [ 1, 0, 0, 1 ] ], [ [ 1 1 1 ], [ 1, 0, 0, 1 ] ],[0m
    [22m[35m  [ [ 0 0 1 ], [ 0, 1, 1, 0 ] ], [ [ 1 1 0 ], [ 0, 1, 1, 0 ] ],[0m
    [22m[35m  [ [ 1 0 0 ], [ 0, 1, 1, 0 ] ], [ [ 0 1 1 ], [ 0, 1, 1, 0 ] ],[0m
    [22m[35m  [ [ 0 1 0 ], [ 0, 1, 1, 0 ] ], [ [ 1 0 1 ], [ 0, 1, 1, 0 ] ] ][0m
    [22m[35mgap> WeightDistribution(C) = OD[1][2];[0m
    [22m[35mtrue[0m
    [22m[35mgap> DistancesDistribution( C, Codeword("110") ) = OD[4][2];[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m4.10 Decoding Functions[0m
  
  [1m[4m[31m4.10-1 Decode[0m
  
  [1m[34m> Decode( [0m[22m[34mC, r[0m[1m[34m ) ___________________________________________________[0mfunction
  
  [22m[32mDecode[0m  decodes [22m[34mr[0m (a 'received word') with respect to code [22m[34mC[0m and returns the
  `message word' (i.e., the information digits associated to the codeword c in
  C  closest  to  [22m[34mr[0m).  Here  [22m[34mr[0m can be a [1mGUAVA[0m codeword or a list of codewords.
  First,  possible  errors in [22m[34mr[0m are corrected, then the codeword is decoded to
  an  [22m[36minformation codeword[0m m (and not an element of [22m[34mC[0m). If the code record has
  a  field  `specialDecoder',  this  special  algorithm  is used to decode the
  vector. Hamming codes, BCH codes, cyclic codes, and generalized Reed-Solomon
  have  such  a  special  algorithm.  (The algorithm used for BCH codes is the
  Sugiyama  algorithm  described,  for  example, in section 5.4.3 of [HP03]. A
  special decoder has also being written for the generalized Reed-Solomon code
  using  the  interpolation  algorithm.  For  cyclic codes, the error-trapping
  algorithm is used.) If [22m[34mC[0m is linear and no special decoder field has been set
  then  syndrome  decoding  is  used.  Otherwise  (when  [22m[34mC[0m is non-linear), the
  nearest neighbor decoding algorithm is used (which is very slow).
  
  A special decoder can be created by defining a function
  
  
  C!.SpecialDecoder := function(C, r) ... end;
  The  function  uses the arguments [22m[34mC[0m (the code record itself) and [22m[34mr[0m (a vector
  of the codeword type) to decode [22m[34mr[0m to an information vector. A normal decoder
  would  take  a  codeword [22m[34mr[0m of the same word length and field as [22m[34mC[0m, and would
  return  an  information  vector of length k, the dimension of [22m[34mC[0m. The user is
  not restricted to these normal demands though, and can for instance define a
  decoder for non-linear codes.
  
  Encoding  is  done  by multiplying the information vector with the code (see
  [1m4.2[0m).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := HammingCode(3);[0m
    [22m[35ma linear [7,4,3]1 Hamming (3,2) code over GF(2)[0m
    [22m[35mgap> c := "1010"*C;                    # encoding[0m
    [22m[35m[ 1 0 1 1 0 1 0 ][0m
    [22m[35mgap> Decode(C, c);                     # decoding[0m
    [22m[35m[ 1 0 1 0 ][0m
    [22m[35mgap> Decode(C, Codeword("0010101"));[0m
    [22m[35m[ 1 1 0 1 ]                            # one error corrected[0m
    [22m[35mgap> C!.SpecialDecoder := function(C, c)[0m
    [22m[35m> return NullWord(Dimension(C));[0m
    [22m[35m> end;[0m
    [22m[35mfunction ( C, c ) ... end[0m
    [22m[35mgap> Decode(C, c);[0m
    [22m[35m[ 0 0 0 0 ]           # new decoder always returns null word [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-2 Decodeword[0m
  
  [1m[34m> Decodeword( [0m[22m[34mC, r[0m[1m[34m ) _______________________________________________[0mfunction
  
  [22m[32mDecodeword[0m  decodes [22m[34mr[0m (a 'received word') with respect to code [22m[34mC[0m and returns
  the  codeword  c in C closest to [22m[34mr[0m. Here [22m[34mr[0m can be a [1mGUAVA[0m codeword or a list
  of  codewords. If the code record has a field `specialDecoder', this special
  algorithm   is  used  to  decode  the  vector.  Hamming  codes,  generalized
  Reed-Solomon  codes,  and  BCH  codes  have  such  a special algorithm. (The
  algorithm  used  for  BCH  codes  is  the  Sugiyama algorithm described, for
  example,  in  section  5.4.3  of  [HP03]. The algorithm used for generalized
  Reed-Solomon  codes is the ``interpolation algorithm'' described for example
  in  chapter  5  of  [JH04].) If [22m[34mC[0m is linear and no special decoder field has
  been  set  then  syndrome decoding is used. Otherwise, when [22m[34mC[0m is non-linear,
  the  nearest  neighbor  algorithm has been implemented (which should only be
  used for small-sized codes).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := HammingCode(3);[0m
    [22m[35ma linear [7,4,3]1 Hamming (3,2) code over GF(2)[0m
    [22m[35mgap> c := "1010"*C;                    # encoding[0m
    [22m[35m[ 1 0 1 1 0 1 0 ][0m
    [22m[35mgap> Decodeword(C, c);                     # decoding[0m
    [22m[35m[ 1 0 1 1 0 1 0 ][0m
    [22m[35mgap>[0m
    [22m[35mgap> R:=PolynomialRing(GF(11),["t"]);[0m
    [22m[35mGF(11)[t][0m
    [22m[35mgap> P:=List([1,3,4,5,7],i->Z(11)^i);[0m
    [22m[35m[ Z(11), Z(11)^3, Z(11)^4, Z(11)^5, Z(11)^7 ][0m
    [22m[35mgap> C:=GeneralizedReedSolomonCode(P,3,R);[0m
    [22m[35ma linear [5,3,1..3]2  generalized Reed-Solomon code over GF(11)[0m
    [22m[35mgap> MinimumDistance(C);[0m
    [22m[35m3[0m
    [22m[35mgap> c:=Random(C);[0m
    [22m[35m[ 0 9 6 2 1 ][0m
    [22m[35mgap> v:=Codeword("09620");[0m
    [22m[35m[ 0 9 6 2 0 ][0m
    [22m[35mgap> GeneralizedReedSolomonDecoderGao(C,v);[0m
    [22m[35m[ 0 9 6 2 1 ][0m
    [22m[35mgap> Decodeword(C,v); # calls the special interpolation decoder[0m
    [22m[35m[ 0 9 6 2 1 ][0m
    [22m[35mgap> G:=GeneratorMat(C);[0m
    [22m[35m[ [ Z(11)^0, 0*Z(11), 0*Z(11), Z(11)^8, Z(11)^9 ],[0m
    [22m[35m  [ 0*Z(11), Z(11)^0, 0*Z(11), Z(11)^0, Z(11)^8 ],[0m
    [22m[35m  [ 0*Z(11), 0*Z(11), Z(11)^0, Z(11)^3, Z(11)^8 ] ][0m
    [22m[35mgap> C1:=GeneratorMatCode(G,GF(11));[0m
    [22m[35ma linear [5,3,1..3]2 code defined by generator matrix over GF(11)[0m
    [22m[35mgap> Decodeword(C,v); # calls syndrome decoding[0m
    [22m[35m[ 0 9 6 2 1 ][0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-3 GeneralizedReedSolomonDecoderGao[0m
  
  [1m[34m> GeneralizedReedSolomonDecoderGao( [0m[22m[34mC, r[0m[1m[34m ) _________________________[0mfunction
  
  [22m[32mGeneralizedReedSolomonDecoderGao[0m decodes [22m[34mr[0m (a 'received word') to a codeword
  c  in C in a generalized Reed-Solomon code [22m[34mC[0m (see [1m[34mGeneralizedReedSolomonCode[0m
  ([1m5.6-2[0m)),  closest to [22m[34mr[0m. Here [22m[34mr[0m must be a [1mGUAVA[0m codeword. If the code record
  does  not  have  name  `generalized  Reed-Solomon  code'  then  an  error is
  returned. Otherwise, the Gao decoder [G03] is used to compute c.
  
  For  long  codes,  this  method is faster in practice than the interpolation
  method used in [22m[32mDecodeword[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> R:=PolynomialRing(GF(11),["t"]);[0m
    [22m[35mGF(11)[t][0m
    [22m[35mgap> P:=List([1,3,4,5,7],i->Z(11)^i);[0m
    [22m[35m[ Z(11), Z(11)^3, Z(11)^4, Z(11)^5, Z(11)^7 ][0m
    [22m[35mgap> C:=GeneralizedReedSolomonCode(P,3,R);[0m
    [22m[35ma linear [5,3,1..3]2  generalized Reed-Solomon code over GF(11)[0m
    [22m[35mgap> MinimumDistance(C);[0m
    [22m[35m3[0m
    [22m[35mgap> c:=Random(C);[0m
    [22m[35m[ 0 9 6 2 1 ][0m
    [22m[35mgap> v:=Codeword("09620");[0m
    [22m[35m[ 0 9 6 2 0 ][0m
    [22m[35mgap> GeneralizedReedSolomonDecoderGao(C,v); [0m
    [22m[35m[ 0 9 6 2 1 ][0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-4 GeneralizedReedSolomonListDecoder[0m
  
  [1m[34m> GeneralizedReedSolomonListDecoder( [0m[22m[34mC, r, tau[0m[1m[34m ) ___________________[0mfunction
  
  [22m[32mGeneralizedReedSolomonListDecoder[0m  implements Sudans list-decoding algorithm
  (see section 12.1 of [JH04]) for ``low rate'' Reed-Solomon codes. It returns
  the list of all codewords in C which are a distance of at most [22m[34mtau[0m from [22m[34mr[0m (a
  'received  word').  [22m[34mC[0m  must  be  a  generalized  Reed-Solomon  code  [22m[34mC[0m  (see
  [1m[34mGeneralizedReedSolomonCode[0m ([1m5.6-2[0m)) and [22m[34mr[0m must be a [1mGUAVA[0m codeword.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> F:=GF(16);[0m
    [22m[35mGF(2^4)[0m
    [22m[35mgap>[0m
    [22m[35mgap> a:=PrimitiveRoot(F);; b:=a^7;; b^4+b^3+1; [0m
    [22m[35m0*Z(2)[0m
    [22m[35mgap> Pts:=List([0..14],i->b^i);[0m
    [22m[35m[ Z(2)^0, Z(2^4)^7, Z(2^4)^14, Z(2^4)^6, Z(2^4)^13, Z(2^2), Z(2^4)^12, Z(2^4)^4,[0m
    [22m[35m  Z(2^4)^11, Z(2^4)^3, Z(2^2)^2, Z(2^4)^2, Z(2^4)^9, Z(2^4), Z(2^4)^8 ][0m
    [22m[35mgap> x:=X(F);;[0m
    [22m[35mgap> R1:=PolynomialRing(F,[x]);;[0m
    [22m[35mgap> vars:=IndeterminatesOfPolynomialRing(R1);;[0m
    [22m[35mgap> y:=X(F,vars);;[0m
    [22m[35mgap> R2:=PolynomialRing(F,[x,y]);;[0m
    [22m[35mgap> C:=GeneralizedReedSolomonCode(Pts,3,R1); [0m
    [22m[35ma linear [15,3,1..13]10..12  generalized Reed-Solomon code over GF(16)[0m
    [22m[35mgap> MinimumDistance(C); ## 6 error correcting[0m
    [22m[35m13[0m
    [22m[35mgap> z:=Zero(F);;[0m
    [22m[35mgap> r:=[z,z,z,z,z,z,z,z,b^6,b^2,b^5,b^14,b,b^7,b^11];; [0m
    [22m[35mgap> r:=Codeword(r);[0m
    [22m[35m[ 0 0 0 0 0 0 0 0 a^12 a^14 a^5 a^8 a^7 a^4 a^2 ][0m
    [22m[35mgap> cs:=GeneralizedReedSolomonListDecoder(C,r,2); time;[0m
    [22m[35m[ [ 0 a^9 a^3 a^13 a^6 a^10 a^11 a a^12 a^14 a^5 a^8 a^7 a^4 a^2 ],[0m
    [22m[35m  [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ] ][0m
    [22m[35m250[0m
    [22m[35mgap> c1:=cs[1]; c1 in C;[0m
    [22m[35m[ 0 a^9 a^3 a^13 a^6 a^10 a^11 a a^12 a^14 a^5 a^8 a^7 a^4 a^2 ][0m
    [22m[35mtrue[0m
    [22m[35mgap> c2:=cs[2]; c2 in C;[0m
    [22m[35m[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ][0m
    [22m[35mtrue[0m
    [22m[35mgap> WeightCodeword(c1-r);[0m
    [22m[35m7[0m
    [22m[35mgap> WeightCodeword(c2-r);[0m
    [22m[35m7[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-5 BitFlipDecoder[0m
  
  [1m[34m> BitFlipDecoder( [0m[22m[34mC, r[0m[1m[34m ) ___________________________________________[0mfunction
  
  The  iterative  decoding  method [22m[32mBitFlipDecoder[0m must only be applied to LDPC
  codes.  These  have not been implemented in GUAVA (but see [22m[32mFerreroDesignCode[0m
  for  a  code  with  similar  properties).  A binary low density parity check
  (LDPC)  code  of  length  $n$  and redundancy $r$ is defined in terms of its
  check matrix $H$:
  
  --    Each row of $H$ has exactly $x$ 1's.
  
  --    Each column has exactly $y$ 1's.
  
  --    The  number  of  1's in common between any two columns is less than or
        equal to one.
  
  --    $x/n$ and $y/r$ are 'small'.
  
  For  these codes, [22m[32mBitFlipDecoder[0m decodes very quickly. (Warning: it can give
  wildly  wrong  results  for arbitrary binary linear codes.) The bit flipping
  algorithm is described for example in chapter 13 of [JH04].
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C:=HammingCode(4,GF(2));[0m
    [22m[35ma linear [15,11,3]1 Hamming (4,2) code over GF(2)[0m
    [22m[35mgap> c:=Random(C);[0m
    [22m[35m[ 0 0 0 1 0 0 1 0 0 1 1 0 1 0 1 ][0m
    [22m[35mgap> v:=List(c);[0m
    [22m[35m[ 0*Z(2), 0*Z(2), 0*Z(2), Z(2)^0, 0*Z(2), 0*Z(2), Z(2)^0, 0*Z(2), 0*Z(2),[0m
    [22m[35m  Z(2)^0, Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0 ][0m
    [22m[35mgap> v[1]:=Z(2)+v[1]; # flip 1st bit of c to create an error[0m
    [22m[35mZ(2)^0[0m
    [22m[35mgap> v:=Codeword(v);[0m
    [22m[35m[ 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 ][0m
    [22m[35mgap> BitFlipDecoder(C,v);[0m
    [22m[35m[ 0 0 0 1 0 0 1 0 0 1 1 0 1 0 1 ][0m
    [22m[35m[0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-6 NearestNeighborGRSDecodewords[0m
  
  [1m[34m> NearestNeighborGRSDecodewords( [0m[22m[34mC, v, dist[0m[1m[34m ) ______________________[0mfunction
  
  [22m[32mNearestNeighborGRSDecodewords[0m  finds  all generalized Reed-Solomon codewords
  within  distance  [22m[34mdist[0m  from  [22m[34mv[0m [22m[36mand[0m the associated polynomial, using ``brute
  force''.  Input: [22m[34mv[0m is a received vector (a [1mGUAVA[0m codeword), [22m[34mC[0m is a GRS code,
  [22m[34mdist[0m  >  0  is  the  distance from [22m[34mv[0m to search in [22m[34mC[0m. Output: a list of pairs
  [c,f(x)], where wt(c-v)<= dist-1 and c = (f(x_1),...,f(x_n)).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> F:=GF(16);[0m
    [22m[35mGF(2^4)[0m
    [22m[35mgap> a:=PrimitiveRoot(F);; b:=a^7; b^4+b^3+1;[0m
    [22m[35mZ(2^4)^7[0m
    [22m[35m0*Z(2)[0m
    [22m[35mgap> Pts:=List([0..14],i->b^i);[0m
    [22m[35m[ Z(2)^0, Z(2^4)^7, Z(2^4)^14, Z(2^4)^6, Z(2^4)^13, Z(2^2), Z(2^4)^12,[0m
    [22m[35m  Z(2^4)^4, Z(2^4)^11, Z(2^4)^3, Z(2^2)^2, Z(2^4)^2, Z(2^4)^9, Z(2^4),[0m
    [22m[35m  Z(2^4)^8 ][0m
    [22m[35mgap> x:=X(F);;[0m
    [22m[35mgap> R1:=PolynomialRing(F,[x]);;[0m
    [22m[35mgap> vars:=IndeterminatesOfPolynomialRing(R1);;[0m
    [22m[35mgap> y:=X(F,vars);;[0m
    [22m[35mgap> R2:=PolynomialRing(F,[x,y]);;[0m
    [22m[35mgap> C:=GeneralizedReedSolomonCode(Pts,3,R1);[0m
    [22m[35ma linear [15,3,1..13]10..12  generalized Reed-Solomon code over GF(16)[0m
    [22m[35mgap> MinimumDistance(C); # 6 error correcting[0m
    [22m[35m13[0m
    [22m[35mgap> z:=Zero(F);[0m
    [22m[35m0*Z(2)[0m
    [22m[35mgap> r:=[z,z,z,z,z,z,z,z,b^6,b^2,b^5,b^14,b,b^7,b^11];; # 7 errors[0m
    [22m[35mgap> r:=Codeword(r);[0m
    [22m[35m[ 0 0 0 0 0 0 0 0 a^12 a^14 a^5 a^8 a^7 a^4 a^2 ][0m
    [22m[35mgap> cs:=NearestNeighborGRSDecodewords(C,r,7);[0m
    [22m[35m[ [ [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ], 0*Z(2) ],[0m
    [22m[35m  [ [ 0 a^9 a^3 a^13 a^6 a^10 a^11 a a^12 a^14 a^5 a^8 a^7 a^4 a^2 ], x_1+Z(2)^0 ] ][0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-7 NearestNeighborDecodewords[0m
  
  [1m[34m> NearestNeighborDecodewords( [0m[22m[34mC, v, dist[0m[1m[34m ) _________________________[0mfunction
  
  [22m[32mNearestNeighborDecodewords[0m  finds  all  codewords  in a linear code [22m[34mC[0m within
  distance  [22m[34mdist[0m  from [22m[34mv[0m, using ``brute force''. Input: [22m[34mv[0m is a received vector
  (a  [1mGUAVA[0m  codeword), [22m[34mC[0m is a linear code, [22m[34mdist[0m > 0 is the distance from [22m[34mv[0m to
  search in [22m[34mC[0m. Output: a list of c in C, where wt(c-v)<= dist-1.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> F:=GF(16);[0m
    [22m[35mGF(2^4)[0m
    [22m[35mgap> a:=PrimitiveRoot(F);; b:=a^7; b^4+b^3+1;[0m
    [22m[35mZ(2^4)^7[0m
    [22m[35m0*Z(2)[0m
    [22m[35mgap> Pts:=List([0..14],i->b^i);[0m
    [22m[35m[ Z(2)^0, Z(2^4)^7, Z(2^4)^14, Z(2^4)^6, Z(2^4)^13, Z(2^2), Z(2^4)^12,[0m
    [22m[35m  Z(2^4)^4, Z(2^4)^11, Z(2^4)^3, Z(2^2)^2, Z(2^4)^2, Z(2^4)^9, Z(2^4),[0m
    [22m[35m  Z(2^4)^8 ][0m
    [22m[35mgap> x:=X(F);;[0m
    [22m[35mgap> R1:=PolynomialRing(F,[x]);;[0m
    [22m[35mgap> vars:=IndeterminatesOfPolynomialRing(R1);;[0m
    [22m[35mgap> y:=X(F,vars);;[0m
    [22m[35mgap> R2:=PolynomialRing(F,[x,y]);;[0m
    [22m[35mgap> C:=GeneralizedReedSolomonCode(Pts,3,R1);[0m
    [22m[35ma linear [15,3,1..13]10..12  generalized Reed-Solomon code over GF(16)[0m
    [22m[35mgap> MinimumDistance(C);[0m
    [22m[35m13[0m
    [22m[35mgap> z:=Zero(F);[0m
    [22m[35m0*Z(2)[0m
    [22m[35mgap> r:=[z,z,z,z,z,z,z,z,b^6,b^2,b^5,b^14,b,b^7,b^11];;[0m
    [22m[35mgap> r:=Codeword(r);[0m
    [22m[35m[ 0 0 0 0 0 0 0 0 a^12 a^14 a^5 a^8 a^7 a^4 a^2 ][0m
    [22m[35mgap> cs:=NearestNeighborDecodewords(C,r,7);[0m
    [22m[35m[ [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ], [0m
    [22m[35m  [ 0 a^9 a^3 a^13 a^6 a^10 a^11 a a^12 a^14 a^5 a^8 a^7 a^4 a^2 ] ][0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-8 Syndrome[0m
  
  [1m[34m> Syndrome( [0m[22m[34mC, v[0m[1m[34m ) _________________________________________________[0mfunction
  
  [22m[32mSyndrome[0m  returns  the syndrome of word [22m[34mv[0m with respect to a linear code [22m[34mC[0m. [22m[34mv[0m
  is a codeword in the ambient vector space of [22m[34mC[0m. If [22m[34mv[0m is an element of [22m[34mC[0m, the
  syndrome  is a zero vector. The syndrome can be used for looking up an error
  vector  in the syndrome table (see [1m[34mSyndromeTable[0m ([1m4.10-9[0m)) that is needed to
  correct an error in v.
  
  A  syndrome  is  not  defined for non-linear codes. [22m[32mSyndrome[0m then returns an
  error.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := HammingCode(4);[0m
    [22m[35ma linear [15,11,3]1 Hamming (4,2) code over GF(2)[0m
    [22m[35mgap> v := CodewordNr( C, 7 );[0m
    [22m[35m[ 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 ][0m
    [22m[35mgap> Syndrome( C, v );[0m
    [22m[35m[ 0 0 0 0 ][0m
    [22m[35mgap> Syndrome( C, Codeword( "000000001100111" ) );[0m
    [22m[35m[ 1 1 1 1 ][0m
    [22m[35mgap> Syndrome( C, Codeword( "000000000000001" ) );[0m
    [22m[35m[ 1 1 1 1 ]    # the same syndrome: both codewords are in the same[0m
    [22m[35m               # coset of C [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-9 SyndromeTable[0m
  
  [1m[34m> SyndromeTable( [0m[22m[34mC[0m[1m[34m ) _______________________________________________[0mfunction
  
  [22m[32mSyndromeTable[0m returns a [22m[36msyndrome table[0m of a linear code [22m[34mC[0m, consisting of two
  columns.  The  first column consists of the error vectors that correspond to
  the  syndrome  vectors  in  the second column. These vectors both are of the
  codeword type. After calculating the syndrome of a word [22m[34mv[0m with [22m[32mSyndrome[0m (see
  [1m[34mSyndrome[0m ([1m4.10-8[0m)), the error vector needed to correct [22m[34mv[0m can be found in the
  syndrome  table.  Subtracting  this vector from [22m[34mv[0m yields an element of [22m[34mC[0m. To
  make  the search for the syndrome as fast as possible, the syndrome table is
  sorted according to the syndrome vectors.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> H := HammingCode(2);[0m
    [22m[35ma linear [3,1,3]1 Hamming (2,2) code over GF(2)[0m
    [22m[35mgap> SyndromeTable(H);[0m
    [22m[35m[ [ [ 0 0 0 ], [ 0 0 ] ], [ [ 1 0 0 ], [ 0 1 ] ],[0m
    [22m[35m  [ [ 0 1 0 ], [ 1 0 ] ], [ [ 0 0 1 ], [ 1 1 ] ] ][0m
    [22m[35mgap> c := Codeword("101");[0m
    [22m[35m[ 1 0 1 ][0m
    [22m[35mgap> c in H;[0m
    [22m[35mfalse          # c is not an element of H[0m
    [22m[35mgap> Syndrome(H,c);[0m
    [22m[35m[ 1 0 ]        # according to the syndrome table,[0m
    [22m[35m               # the error vector [ 0 1 0 ] belongs to this syndrome[0m
    [22m[35mgap> c - Codeword("010") in H;[0m
    [22m[35mtrue           # so the corrected codeword is[0m
    [22m[35m               # [ 1 0 1 ] - [ 0 1 0 ] = [ 1 1 1 ],[0m
    [22m[35m               # this is an element of H [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-10 StandardArray[0m
  
  [1m[34m> StandardArray( [0m[22m[34mC[0m[1m[34m ) _______________________________________________[0mfunction
  
  [22m[32mStandardArray[0m  returns the standard array of a code [22m[34mC[0m. This is a matrix with
  elements  of  the codeword type. It has q^r rows and q^k columns, where q is
  the  size of the base field of [22m[34mC[0m, r=n-k is the redundancy of [22m[34mC[0m, and k is the
  dimension of [22m[34mC[0m. The first row contains all the elements of [22m[34mC[0m. Each other row
  contains  words  that  do  not  belong to the code, with in the first column
  their syndrome vector (see [1m[34mSyndrome[0m ([1m4.10-8[0m)).
  
  A non-linear code does not have a standard array. [22m[32mStandardArray[0m then returns
  an error.
  
  Note  that  calculating  a  standard  array  can  be  very time- and memory-
  consuming.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> StandardArray(RepetitionCode(3)); [0m
    [22m[35m[ [ [ 0 0 0 ], [ 1 1 1 ] ], [ [ 0 0 1 ], [ 1 1 0 ] ], [0m
    [22m[35m  [ [ 0 1 0 ], [ 1 0 1 ] ], [ [ 1 0 0 ], [ 0 1 1 ] ] ][0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-11 PermutationDecode[0m
  
  [1m[34m> PermutationDecode( [0m[22m[34mC, v[0m[1m[34m ) ________________________________________[0mfunction
  
  [22m[32mPermutationDecode[0m  performs  permutation  decoding when possible and returns
  original vector and prints 'fail' when not possible.
  
  This   uses   [22m[32mAutomorphismGroup[0m   in  the  binary  case,  and  (the  slower)
  [22m[32mPermutationAutomorphismGroup[0m   otherwise,   to   compute   the   permutation
  automorphism  group  P  of [22m[34mC[0m. The algorithm runs through the elements p of P
  checking  if  the  weight of H(p* v) is less than (d-1)/2. If it is then the
  vector  p*  v  is  used  to  decode  v:  assuming [22m[34mC[0m is in standard form then
  c=p^-1Em  is  the decoded word, where m is the information digits part of p*
  v.  If no such p exists then ``fail'' is returned. See, for example, section
  10.2 of Huffman and Pless [HP03] for more details.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C0:=HammingCode(3,GF(2));[0m
    [22m[35ma linear [7,4,3]1 Hamming (3,2) code over GF(2)[0m
    [22m[35mgap> G0:=GeneratorMat(C0);;[0m
    [22m[35mgap> G := List(G0, ShallowCopy);;[0m
    [22m[35mgap> PutStandardForm(G);[0m
    [22m[35m()[0m
    [22m[35mgap> Display(G);[0m
    [22m[35m 1 . . . . 1 1[0m
    [22m[35m . 1 . . 1 . 1[0m
    [22m[35m . . 1 . 1 1 .[0m
    [22m[35m . . . 1 1 1 1[0m
    [22m[35mgap> H0:=CheckMat(C0);;[0m
    [22m[35mgap> Display(H0);[0m
    [22m[35m . . . 1 1 1 1[0m
    [22m[35m . 1 1 . . 1 1[0m
    [22m[35m 1 . 1 . 1 . 1[0m
    [22m[35mgap> c0:=Random(C0);[0m
    [22m[35m[ 0 0 0 1 1 1 1 ][0m
    [22m[35mgap> v01:=c0[1]+Z(2)^2;;[0m
    [22m[35mgap> v1:=List(c0, ShallowCopy);;[0m
    [22m[35mgap> v1[1]:=v01;;[0m
    [22m[35mgap> v1:=Codeword(v1);[0m
    [22m[35m[ 1 0 0 1 1 1 1 ][0m
    [22m[35mgap> c1:=PermutationDecode(C0,v1);[0m
    [22m[35m[ 0 0 0 1 1 1 1 ][0m
    [22m[35mgap> c1=c0;[0m
    [22m[35mtrue[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m4.10-12 PermutationDecodeNC[0m
  
  [1m[34m> PermutationDecodeNC( [0m[22m[34mC, v, P[0m[1m[34m ) ___________________________________[0mfunction
  
  Same  as  [22m[32mPermutationDecode[0m  except  that  one  may  enter  the  permutation
  automorphism group [22m[34mP[0m in as an argument, saving time. Here [22m[34mP[0m is a subgroup of
  the symmetric group on n letters, where n is the word length of [22m[34mC[0m.
  
