  
  [1X6 [33X[0;0YManipulating Codes[133X[101X
  
  [33X[0;0YIn  this  chapter  we  describe  several  functions [5XGUAVA[105X uses to manipulate
  codes.  Some  of  the best codes are obtained by starting with for example a
  BCH code, and manipulating it.[133X
  
  [33X[0;0YIn  some cases, it is faster to perform calculations with a manipulated code
  than  to use the original code. For example, if the dimension of the code is
  larger  than  half  the  word  length, it is generally faster to compute the
  weight distribution by first calculating the weight distribution of the dual
  code  than  by  directly calculating the weight distribution of the original
  code. The size of the dual code is smaller in these cases.[133X
  
  [33X[0;0YBecause  [5XGUAVA[105X  keeps  all  information  in a code record, in some cases the
  information can be preserved after manipulations. Therefore, computations do
  not always have to start from scratch.[133X
  
  [33X[0;0YIn  Section  [14X6.1[114X,  we  describe  functions  that  take  a  code with certain
  parameters,  modify  it  in  some  way  and  return  a  different  code (see
  [2XExtendedCode[102X  ([14X6.1-1[114X),  [2XPuncturedCode[102X  ([14X6.1-2[114X),  [2XEvenWeightSubcode[102X  ([14X6.1-3[114X),
  [2XPermutedCode[102X   ([14X6.1-4[114X),   [2XExpurgatedCode[102X   ([14X6.1-5[114X),  [2XAugmentedCode[102X  ([14X6.1-6[114X),
  [2XRemovedElementsCode[102X   ([14X6.1-7[114X),   [2XAddedElementsCode[102X   ([14X6.1-8[114X),  [2XShortenedCode[102X
  ([14X6.1-9[114X),  [2XLengthenedCode[102X  ([14X6.1-10[114X),  [2XResidueCode[102X ([14X6.1-12[114X), [2XConstructionBCode[102X
  ([14X6.1-13[114X),      [2XDualCode[102X      ([14X6.1-14[114X),     [2XConversionFieldCode[102X     ([14X6.1-15[114X),
  [2XConstantWeightSubcode[102X  ([14X6.1-18[114X),  [2XStandardFormCode[102X  ([14X6.1-19[114X)  and  [2XCosetCode[102X
  ([14X6.1-17[114X)).  In  Section  [14X6.2[114X, we describe functions that generate a new code
  out   of   two   codes   (see   [2XDirectSumCode[102X   ([14X6.2-1[114X),   [2XUUVCode[102X  ([14X6.2-2[114X),
  [2XDirectProductCode[102X ([14X6.2-3[114X), [2XIntersectionCode[102X ([14X6.2-4[114X) and [2XUnionCode[102X ([14X6.2-5[114X)).[133X
  
  
  [1X6.1 [33X[0;0YFunctions that Generate a New Code from a Given Code[133X[101X
  
  [1X6.1-1 ExtendedCode[101X
  
  [33X[1;0Y[29X[2XExtendedCode[102X( [3XC[103X[, [3Xi[103X] ) [32X function[133X
  
  [33X[0;0Y[10XExtendedCode[110X  extends  the code [3XC[103X [3Xi[103X times and returns the result. [3Xi[103X is equal
  to  [22X1[122X  by  default. Extending is done by adding a parity check bit after the
  last coordinate. The coordinates of all codewords now add up to zero. In the
  binary case, each codeword has even weight.[133X
  
  [33X[0;0YThe  word  length  increases by [3Xi[103X. The size of the code remains the same. In
  the  binary  case,  the  minimum distance increases by one if it was odd. In
  other cases, that is not always true.[133X
  
  [33X[0;0YA cyclic code in general is no longer cyclic after extending.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := HammingCode( 3, GF(2) );[127X[104X
    [4X[28Xa linear [7,4,3]1 Hamming (3,2) code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC2 := ExtendedCode( C1 );[127X[104X
    [4X[28Xa linear [8,4,4]2 extended code[128X[104X
    [4X[25Xgap>[125X [27XIsEquivalent( C2, ReedMullerCode( 1, 3 ) );[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XList( AsSSortedList( C2 ), WeightCodeword );[127X[104X
    [4X[28X[ 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8 ][128X[104X
    [4X[25Xgap>[125X [27XC3 := EvenWeightSubcode( C1 );[127X[104X
    [4X[28Xa linear [7,3,4]2..3 even weight subcode [128X[104X
  [4X[32X[104X
  
  [33X[0;0YTo  undo  extending,  call  [10XPuncturedCode[110X  (see  [2XPuncturedCode[102X ([14X6.1-2[114X)). The
  function  [10XEvenWeightSubcode[110X  (see  [2XEvenWeightSubcode[102X ([14X6.1-3[114X)) also returns a
  related code with only even weights, but without changing its word length.[133X
  
  [1X6.1-2 PuncturedCode[101X
  
  [33X[1;0Y[29X[2XPuncturedCode[102X( [3XC[103X ) [32X function[133X
  
  [33X[0;0Y[10XPuncturedCode[110X  punctures  [3XC[103X  in  the  last  column,  and returns the result.
  Puncturing is done simply by cutting off the last column from each codeword.
  This means the word length decreases by one. The minimum distance in general
  also decrease by one.[133X
  
  [33X[0;0YThis  command  can  also be called with the syntax [10XPuncturedCode( C, L )[110X. In
  this  case,  [10XPuncturedCode[110X punctures [3XC[103X in the columns specified by [3XL[103X, a list
  of integers. All columns specified by [3XL[103X are omitted from each codeword. If [22Xl[122X
  is  the  length  of  [3XL[103X  (so  the number of removed columns), the word length
  decreases by [22Xl[122X. The minimum distance can also decrease by [22Xl[122X or less.[133X
  
  [33X[0;0YPuncturing  a  cyclic  code  in general results in a non-cyclic code. If the
  code  is  punctured  in  all  the  columns where a word of minimal weight is
  unequal to zero, the dimension of the resulting code decreases.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := BCHCode( 15, 5, GF(2) );[127X[104X
    [4X[28Xa cyclic [15,7,5]3..5 BCH code, delta=5, b=1 over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC2 := PuncturedCode( C1 );[127X[104X
    [4X[28Xa linear [14,7,4]3..5 punctured code[128X[104X
    [4X[25Xgap>[125X [27XExtendedCode( C2 ) = C1;[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27XPuncturedCode( C1, [1,2,3,4,5,6,7] );[127X[104X
    [4X[28Xa linear [8,7,1]1 punctured code[128X[104X
    [4X[25Xgap>[125X [27XPuncturedCode( WholeSpaceCode( 4, GF(5) ) );[127X[104X
    [4X[28Xa linear [3,3,1]0 punctured code  # The dimension decreased from 4 to 3 [128X[104X
  [4X[32X[104X
  
  [33X[0;0Y[10XExtendedCode[110X  extends the code again (see [2XExtendedCode[102X ([14X6.1-1[114X)), although in
  general this does not result in the old code.[133X
  
  [1X6.1-3 EvenWeightSubcode[101X
  
  [33X[1;0Y[29X[2XEvenWeightSubcode[102X( [3XC[103X ) [32X function[133X
  
  [33X[0;0Y[10XEvenWeightSubcode[110X  returns  the  even weight subcode of [3XC[103X, consisting of all
  codewords of [3XC[103X with even weight. If [3XC[103X is a linear code and contains words of
  odd  weight,  the  resulting  code  has a dimension of one less. The minimum
  distance  always  increases  with one if it was odd. If [3XC[103X is a binary cyclic
  code,  and  [22Xg(x)[122X is its generator polynomial, the even weight subcode either
  has  generator  polynomial [22Xg(x)[122X (if [22Xg(x)[122X is divisible by [22Xx-1[122X) or [22Xg(x)⋅ (x-1)[122X
  (if  no factor [22Xx-1[122X was present in [22Xg(x)[122X). So the even weight subcode is again
  cyclic.[133X
  
  [33X[0;0YOf  course,  if  all codewords of [3XC[103X are already of even weight, the returned
  code is equal to [3XC[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := EvenWeightSubcode( BCHCode( 8, 4, GF(3) ) );[127X[104X
    [4X[28Xan (8,33,4..8)3..8 even weight subcode[128X[104X
    [4X[25Xgap>[125X [27XList( AsSSortedList( C1 ), WeightCodeword );[127X[104X
    [4X[28X[ 0, 4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 4, 6, 4, 4, 6, 4, 4, 8, 6, 4, 6, 8, 4, 4, [128X[104X
    [4X[28X  4, 6, 4, 6, 8, 4, 6, 8 ][128X[104X
    [4X[25Xgap>[125X [27XEvenWeightSubcode( ReedMullerCode( 1, 3 ) );[127X[104X
    [4X[28Xa linear [8,4,4]2 Reed-Muller (1,3) code over GF(2) [128X[104X
  [4X[32X[104X
  
  [33X[0;0Y[10XExtendedCode[110X  also  returns a related code of only even weights, but without
  reducing its dimension (see [2XExtendedCode[102X ([14X6.1-1[114X)).[133X
  
  [1X6.1-4 PermutedCode[101X
  
  [33X[1;0Y[29X[2XPermutedCode[102X( [3XC[103X, [3XL[103X ) [32X function[133X
  
  [33X[0;0Y[10XPermutedCode[110X  returns  [3XC[103X after column permutations. [3XL[103X (in GAP disjoint cycle
  notation)  is  the  permutation  to be executed on the columns of [3XC[103X. If [3XC[103X is
  cyclic,  the result in general is no longer cyclic. If a permutation results
  in the same code as [3XC[103X, this permutation belongs to the automorphism group of
  [3XC[103X  (see  [2XAutomorphismGroup[102X  ([14X4.4-3[114X)).  In  any  case,  the  returned code is
  equivalent to [3XC[103X (see [2XIsEquivalent[102X ([14X4.4-1[114X)).[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := PuncturedCode( ReedMullerCode( 1, 4 ) );[127X[104X
    [4X[28Xa linear [15,5,7]5 punctured code[128X[104X
    [4X[25Xgap>[125X [27XC2 := BCHCode( 15, 7, GF(2) );[127X[104X
    [4X[28Xa cyclic [15,5,7]5 BCH code, delta=7, b=1 over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC2 = C1;[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xp := CodeIsomorphism( C1, C2 );[127X[104X
    [4X[28X( 2, 4,14, 9,13, 7,11,10, 6, 8,12, 5)[128X[104X
    [4X[25Xgap>[125X [27XC3 := PermutedCode( C1, p );[127X[104X
    [4X[28Xa linear [15,5,7]5 permuted code[128X[104X
    [4X[25Xgap>[125X [27XC2 = C3;[127X[104X
    [4X[28Xtrue [128X[104X
  [4X[32X[104X
  
  [1X6.1-5 ExpurgatedCode[101X
  
  [33X[1;0Y[29X[2XExpurgatedCode[102X( [3XC[103X, [3XL[103X ) [32X function[133X
  
  [33X[0;0Y[10XExpurgatedCode[110X  expurgates the code [3XC[103X> by throwing away codewords in list [3XL[103X.
  [3XC[103X  must  be a linear code. [3XL[103X must be a list of codeword input. The generator
  matrix  of  the new code no longer is a basis for the codewords specified by
  [3XL[103X.  Since the returned code is still linear, it is very likely that, besides
  the words of [3XL[103X, more codewords of [3XC[103X are no longer in the new code.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := HammingCode( 4 );; WeightDistribution( C1 );[127X[104X
    [4X[28X[ 1, 0, 0, 35, 105, 168, 280, 435, 435, 280, 168, 105, 35, 0, 0, 1 ][128X[104X
    [4X[25Xgap>[125X [27XL := Filtered( AsSSortedList(C1), i -> WeightCodeword(i) = 3 );;[127X[104X
    [4X[25Xgap>[125X [27XC2 := ExpurgatedCode( C1, L );[127X[104X
    [4X[28Xa linear [15,4,3..4]5..11 code, expurgated with 7 word(s)[128X[104X
    [4X[25Xgap>[125X [27XWeightDistribution( C2 );[127X[104X
    [4X[28X[ 1, 0, 0, 0, 14, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ] [128X[104X
  [4X[32X[104X
  
  [33X[0;0YThis  function  does not work on non-linear codes. For removing words from a
  non-linear  code, use [10XRemovedElementsCode[110X (see [2XRemovedElementsCode[102X ([14X6.1-7[114X)).
  For  expurgating  a code of all words of odd weight, use `EvenWeightSubcode'
  (see [2XEvenWeightSubcode[102X ([14X6.1-3[114X)).[133X
  
  [1X6.1-6 AugmentedCode[101X
  
  [33X[1;0Y[29X[2XAugmentedCode[102X( [3XC[103X, [3XL[103X ) [32X function[133X
  
  [33X[0;0Y[10XAugmentedCode[110X returns [3XC[103X after augmenting. [3XC[103X must be a linear code, [3XL[103X must be
  a  list  of codeword inputs. The generator matrix of the new code is a basis
  for  the  codewords specified by [3XL[103X as well as the words that were already in
  code  [3XC[103X.  Note  that the new code in general will consist of more words than
  only  the codewords of [3XC[103X and the words [3XL[103X. The returned code is also a linear
  code.[133X
  
  [33X[0;0YThis  command  can  also  be  called  with the syntax [10XAugmentedCode(C)[110X. When
  called without a list of codewords, [10XAugmentedCode[110X returns [3XC[103X after adding the
  all-ones  vector  to  the  generator matrix. [3XC[103X must be a linear code. If the
  all-ones  vector  was already in the code, nothing happens and a copy of the
  argument  is  returned.  If  [3XC[103X  is  a binary code which does not contain the
  all-ones vector, the complement of all codewords is added.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC31 := ReedMullerCode( 1, 3 );[127X[104X
    [4X[28Xa linear [8,4,4]2 Reed-Muller (1,3) code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC32 := AugmentedCode(C31,["00000011","00000101","00010001"]);[127X[104X
    [4X[28Xa linear [8,7,1..2]1 code, augmented with 3 word(s)[128X[104X
    [4X[25Xgap>[125X [27XC32 = ReedMullerCode( 2, 3 );[127X[104X
    [4X[28Xtrue [128X[104X
    [4X[25Xgap>[125X [27XC1 := CordaroWagnerCode(6);[127X[104X
    [4X[28Xa linear [6,2,4]2..3 Cordaro-Wagner code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XCodeword( [0,0,1,1,1,1] ) in C1;[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XC2 := AugmentedCode( C1 );[127X[104X
    [4X[28Xa linear [6,3,1..2]2..3 code, augmented with 1 word(s)[128X[104X
    [4X[25Xgap>[125X [27XCodeword( [1,1,0,0,0,0] ) in C2;[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  function  [10XAddedElementsCode[110X  adds  elements to the codewords instead of
  adding them to the basis (see [2XAddedElementsCode[102X ([14X6.1-8[114X)).[133X
  
  [1X6.1-7 RemovedElementsCode[101X
  
  [33X[1;0Y[29X[2XRemovedElementsCode[102X( [3XC[103X, [3XL[103X ) [32X function[133X
  
  [33X[0;0Y[10XRemovedElementsCode[110X returns code [3XC[103X after removing a list of codewords [3XL[103X from
  its  elements.  [3XL[103X  must  be  a  list  of  codeword  input.  The result is an
  unrestricted code.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := HammingCode( 4 );; WeightDistribution( C1 );[127X[104X
    [4X[28X[ 1, 0, 0, 35, 105, 168, 280, 435, 435, 280, 168, 105, 35, 0, 0, 1 ][128X[104X
    [4X[25Xgap>[125X [27XL := Filtered( AsSSortedList(C1), i -> WeightCodeword(i) = 3 );;[127X[104X
    [4X[25Xgap>[125X [27XC2 := RemovedElementsCode( C1, L );[127X[104X
    [4X[28Xa (15,2013,3..15)2..15 code with 35 word(s) removed[128X[104X
    [4X[25Xgap>[125X [27XWeightDistribution( C2 );[127X[104X
    [4X[28X[ 1, 0, 0, 0, 105, 168, 280, 435, 435, 280, 168, 105, 35, 0, 0, 1 ][128X[104X
    [4X[25Xgap>[125X [27XMinimumDistance( C2 );[127X[104X
    [4X[28X3        # C2 is not linear, so the minimum weight does not have to[128X[104X
    [4X[28X         # be equal to the minimum distance [128X[104X
  [4X[32X[104X
  
  [33X[0;0YAdding  elements  to  a  code is done by the function [10XAddedElementsCode[110X (see
  [2XAddedElementsCode[102X  ([14X6.1-8[114X)).  To  remove codewords from the base of a linear
  code, use [10XExpurgatedCode[110X (see [2XExpurgatedCode[102X ([14X6.1-5[114X)).[133X
  
  [1X6.1-8 AddedElementsCode[101X
  
  [33X[1;0Y[29X[2XAddedElementsCode[102X( [3XC[103X, [3XL[103X ) [32X function[133X
  
  [33X[0;0Y[10XAddedElementsCode[110X  returns  code [3XC[103X after adding a list of codewords [3XL[103X to its
  elements.  [3XL[103X must be a list of codeword input. The result is an unrestricted
  code.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := NullCode( 6, GF(2) );[127X[104X
    [4X[28Xa cyclic [6,0,6]6 nullcode over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC2 := AddedElementsCode( C1, [ "111111" ] );[127X[104X
    [4X[28Xa (6,2,1..6)3 code with 1 word(s) added[128X[104X
    [4X[25Xgap>[125X [27XIsCyclicCode( C2 );[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XC3 := AddedElementsCode( C2, [ "101010", "010101" ] );[127X[104X
    [4X[28Xa (6,4,1..6)2 code with 2 word(s) added[128X[104X
    [4X[25Xgap>[125X [27XIsCyclicCode( C3 );[127X[104X
    [4X[28Xtrue [128X[104X
  [4X[32X[104X
  
  [33X[0;0YTo   remove   elements   from   a   code,   use   [10XRemovedElementsCode[110X   (see
  [2XRemovedElementsCode[102X  ([14X6.1-7[114X)). To add elements to the base of a linear code,
  use [10XAugmentedCode[110X (see [2XAugmentedCode[102X ([14X6.1-6[114X)).[133X
  
  [1X6.1-9 ShortenedCode[101X
  
  [33X[1;0Y[29X[2XShortenedCode[102X( [3XC[103X[, [3XL[103X] ) [32X function[133X
  
  [33X[0;0Y[10XShortenedCode(  C  )[110X returns the code [3XC[103X shortened by taking a cross section.
  If  [3XC[103X  is  a  linear code, this is done by removing all codewords that start
  with  a  non-zero entry, after which the first column is cut off. If [3XC[103X was a
  [22X[n,k,d][122X  code,  the  shortened  code  generally is a [22X[n-1,k-1,d][122X code. It is
  possible  that  the dimension remains the same; it is also possible that the
  minimum distance increases.[133X
  
  [33X[0;0YIf  [3XC[103X  is  a  non-linear code, [10XShortenedCode[110X first checks which finite field
  element  occurs  most  often  in  the  first  column  of  the codewords. The
  codewords  not  starting  with this element are removed from the code, after
  which the first column is cut off. The resulting shortened code has at least
  the same minimum distance as [3XC[103X.[133X
  
  [33X[0;0YThis  command  can  also be called using the syntax [10XShortenedCode(C,L)[110X. When
  called  in this format, [10XShortenedCode[110X repeats the shortening process on each
  of the columns specified by [3XL[103X. [3XL[103X therefore is a list of integers. The column
  numbers in [3XL[103X are the numbers as they are before the shortening process. If [3XL[103X
  has  [22Xl[122X  entries,  the returned code has a word length of [22Xl[122X positions shorter
  than [3XC[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := HammingCode( 4 );[127X[104X
    [4X[28Xa linear [15,11,3]1 Hamming (4,2) code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC2 := ShortenedCode( C1 );[127X[104X
    [4X[28Xa linear [14,10,3]2 shortened code[128X[104X
    [4X[25Xgap>[125X [27XC3 := ElementsCode( ["1000", "1101", "0011" ], GF(2) );[127X[104X
    [4X[28Xa (4,3,1..4)2 user defined unrestricted code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XMinimumDistance( C3 );[127X[104X
    [4X[28X2[128X[104X
    [4X[25Xgap>[125X [27XC4 := ShortenedCode( C3 );[127X[104X
    [4X[28Xa (3,2,2..3)1..2 shortened code[128X[104X
    [4X[25Xgap>[125X [27XAsSSortedList( C4 );[127X[104X
    [4X[28X[ [ 0 0 0 ], [ 1 0 1 ] ][128X[104X
    [4X[25Xgap>[125X [27XC5 := HammingCode( 5, GF(2) );[127X[104X
    [4X[28Xa linear [31,26,3]1 Hamming (5,2) code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC6 := ShortenedCode( C5, [ 1, 2, 3 ] );[127X[104X
    [4X[28Xa linear [28,23,3]2 shortened code[128X[104X
    [4X[25Xgap>[125X [27XOptimalityLinearCode( C6 );[127X[104X
    [4X[28X0[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  function  [10XLengthenedCode[110X  lengthens  the  code  again  (only for linear
  codes),  see  [2XLengthenedCode[102X  ([14X6.1-10[114X).  In general, this is not exactly the
  inverse function.[133X
  
  [1X6.1-10 LengthenedCode[101X
  
  [33X[1;0Y[29X[2XLengthenedCode[102X( [3XC[103X[, [3Xi[103X] ) [32X function[133X
  
  [33X[0;0Y[10XLengthenedCode(  C )[110X returns the code [3XC[103X lengthened. [3XC[103X must be a linear code.
  First,   the   all-ones  vector  is  added  to  the  generator  matrix  (see
  [2XAugmentedCode[102X  ([14X6.1-6[114X)).  If  the  all-ones  vector  was already a codeword,
  nothing  happens  to  the  code.  Then,  the  code  is extended [3Xi[103X times (see
  [2XExtendedCode[102X  ([14X6.1-1[114X)).  [3Xi[103X is equal to [22X1[122X by default. If [3XC[103X was an [22X[n,k][122X code,
  the new code generally is a [22X[n+i,k+1][122X code.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := CordaroWagnerCode( 5 );[127X[104X
    [4X[28Xa linear [5,2,3]2 Cordaro-Wagner code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC2 := LengthenedCode( C1 );[127X[104X
    [4X[28Xa linear [6,3,2]2..3 code, lengthened with 1 column(s) [128X[104X
  [4X[32X[104X
  
  [33X[0;0Y[10XShortenedCode[110X'  shortens  the  code,  see [2XShortenedCode[102X ([14X6.1-9[114X). In general,
  this is not exactly the inverse function.[133X
  
  [1X6.1-11 SubCode[101X
  
  [33X[1;0Y[29X[2XSubCode[102X( [3XC[103X[, [3Xs[103X] ) [32X function[133X
  
  [33X[0;0YThis  function [10XSubCode[110X returns a subcode of [3XC[103X by taking the first [22Xk - s[122X rows
  of  the  generator matrix of [3XC[103X, where [22Xk[122X is the dimension of [3XC[103X. The integer [3Xs[103X
  may be omitted and in this case it is assumed as 1.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC := BCHCode(31,11);[127X[104X
    [4X[28Xa cyclic [31,11,11]7..11 BCH code, delta=11, b=1 over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XS1:= SubCode(C);[127X[104X
    [4X[28Xa linear [31,10,11]7..13 subcode[128X[104X
    [4X[25Xgap>[125X [27XWeightDistribution(S1);[127X[104X
    [4X[28X[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 190, 0, 0, 272, 255, 0, 0, 120, 66,[128X[104X
    [4X[28X  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ][128X[104X
    [4X[25Xgap>[125X [27XS2:= SubCode(C, 8);[127X[104X
    [4X[28Xa linear [31,3,11]14..20 subcode[128X[104X
    [4X[25Xgap>[125X [27XHistory(S2);[127X[104X
    [4X[28X[ "a linear [31,3,11]14..20 subcode of",[128X[104X
    [4X[28X  "a cyclic [31,11,11]7..11 BCH code, delta=11, b=1 over GF(2)" ][128X[104X
    [4X[25Xgap>[125X [27XWeightDistribution(S2);[127X[104X
    [4X[28X[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,[128X[104X
    [4X[28X  0, 0, 0, 0, 0, 0, 0 ][128X[104X
  [4X[32X[104X
  
  [1X6.1-12 ResidueCode[101X
  
  [33X[1;0Y[29X[2XResidueCode[102X( [3XC[103X[, [3Xc[103X] ) [32X function[133X
  
  [33X[0;0YThe  function  [10XResidueCode[110X  takes  a  codeword  [3Xc[103X  of  [3XC[103X (if [3Xc[103X is omitted, a
  codeword of minimal weight is used). It removes this word and all its linear
  combinations  from  the  code and then punctures the code in the coordinates
  where  [3Xc[103X  is  unequal  to  zero.  The  resulting  code  is an [22X[n-w, k-1, d-⌊
  w*(q-1)/q  ⌋ ][122X code. [3XC[103X must be a linear code and [3Xc[103X must be non-zero. If [3Xc[103X is
  not in [3X[103X then no change is made to [3XC[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := BCHCode( 15, 7 );[127X[104X
    [4X[28Xa cyclic [15,5,7]5 BCH code, delta=7, b=1 over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC2 := ResidueCode( C1 );[127X[104X
    [4X[28Xa linear [8,4,4]2 residue code[128X[104X
    [4X[25Xgap>[125X [27Xc := Codeword( [ 0,0,0,1,0,0,1,1,0,1,0,1,1,1,1 ], C1);;[127X[104X
    [4X[25Xgap>[125X [27XC3 := ResidueCode( C1, c );[127X[104X
    [4X[28Xa linear [7,4,3]1 residue code [128X[104X
  [4X[32X[104X
  
  [1X6.1-13 ConstructionBCode[101X
  
  [33X[1;0Y[29X[2XConstructionBCode[102X( [3XC[103X ) [32X function[133X
  
  [33X[0;0YThe  function  [10XConstructionBCode[110X takes a binary linear code [3XC[103X and calculates
  the  minimum  distance  of  the  dual  of [3XC[103X (see [2XDualCode[102X ([14X6.1-14[114X)). It then
  removes  the columns of the parity check matrix of [3XC[103X where a codeword of the
  dual  code  of minimal weight has coordinates unequal to zero. The resulting
  matrix is a parity check matrix for an [22X[n-dd, k-dd+1, ≥ d][122X code, where [22Xdd[122X is
  the minimum distance of the dual of [3XC[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC1 := ReedMullerCode( 2, 5 );[127X[104X
    [4X[28Xa linear [32,16,8]6 Reed-Muller (2,5) code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XC2 := ConstructionBCode( C1 );[127X[104X
    [4X[28Xa linear [24,9,8]5..10 Construction B (8 coordinates)[128X[104X
    [4X[25Xgap>[125X [27XBoundsMinimumDistance( 24, 9, GF(2) );[127X[104X
    [4X[28Xrec( n := 24, k := 9, q := 2, references := rec(  ), [128X[104X
    [4X[28X  construction := [ [ Operation "UUVCode" ], [128X[104X
    [4X[28X      [ [ [ Operation "UUVCode" ], [ [ [ Operation "DualCode" ], [128X[104X
    [4X[28X                      [ [ [ Operation "RepetitionCode" ], [ 6, 2 ] ] ] ], [128X[104X
    [4X[28X                  [ [ Operation "CordaroWagnerCode" ], [ 6 ] ] ] ], [128X[104X
    [4X[28X          [ [ Operation "CordaroWagnerCode" ], [ 12 ] ] ] ], lowerBound := 8, [128X[104X
    [4X[28X  lowerBoundExplanation := [ "Lb(24,9)=8, u u+v construction of C1 and C2:", [128X[104X
    [4X[28X      "Lb(12,7)=4, u u+v construction of C1 and C2:", [128X[104X
    [4X[28X      "Lb(6,5)=2, dual of the repetition code", [128X[104X
    [4X[28X      "Lb(6,2)=4, Cordaro-Wagner code", "Lb(12,2)=8, Cordaro-Wagner code" ], [128X[104X
    [4X[28X  upperBound := 8, [128X[104X
    [4X[28X  upperBoundExplanation := [ "Ub(24,9)=8, otherwise construction B would [128X[104X
    [4X[28X                             contradict:", "Ub(18,4)=8, Griesmer bound" ] )[128X[104X
    [4X[28X# so C2 is optimal[128X[104X
  [4X[32X[104X
  
  [1X6.1-14 DualCode[101X
  
  [33X[1;0Y[29X[2XDualCode[102X( [3XC[103X ) [32X function[133X
  
  [33X[0;0Y[10XDualCode[110X returns the dual code of [3XC[103X. The dual code consists of all codewords
  that  are  orthogonal  to  the  codewords  of  [3XC[103X. If [3XC[103X is a linear code with
  generator  matrix  [22XG[122X,  the  dual code has parity check matrix [22XG[122X (or if [3XC[103X has
  parity  check  matrix [22XH[122X, the dual code has generator matrix [22XH[122X). So if [3XC[103X is a
  linear  [22X[n, k][122X code, the dual code of [3XC[103X is a linear [22X[n, n-k][122X code. If [3XC[103X is a
  cyclic code with generator polynomial [22Xg(x)[122X, the dual code has the reciprocal
  polynomial of [22Xg(x)[122X as check polynomial.[133X
  
  [33X[0;0YThe dual code is always a linear code, even if [3XC[103X is non-linear.[133X
  
  [33X[0;0YIf a code [3XC[103X is equal to its dual code, it is called [13Xself-dual[113X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XR := ReedMullerCode( 1, 3 );[127X[104X
    [4X[28Xa linear [8,4,4]2 Reed-Muller (1,3) code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XRD := DualCode( R );[127X[104X
    [4X[28Xa linear [8,4,4]2 Reed-Muller (1,3) code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27XR = RD;[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XN := WholeSpaceCode( 7, GF(4) );[127X[104X
    [4X[28Xa cyclic [7,7,1]0 whole space code over GF(4)[128X[104X
    [4X[25Xgap>[125X [27XDualCode( N ) = NullCode( 7, GF(4) );[127X[104X
    [4X[28Xtrue [128X[104X
  [4X[32X[104X
  
  [1X6.1-15 ConversionFieldCode[101X
  
  [33X[1;0Y[29X[2XConversionFieldCode[102X( [3XC[103X ) [32X function[133X
  
  [33X[0;0Y[10XConversionFieldCode[110X  returns  the  code obtained from [3XC[103X after converting its
  field. If the field of [3XC[103X is [22XGF(q^m)[122X, the returned code has field [22XGF(q)[122X. Each
  symbol  of  every  codeword is replaced by a concatenation of [22Xm[122X symbols from
  [22XGF(q)[122X.  If  [3XC[103X  is an [22X(n, M, d_1)[122X code, the returned code is a [22X(n⋅ m, M, d_2)[122X
  code, where [22Xd_2 > d_1[122X.[133X
  
  [33X[0;0YSee also [2XHorizontalConversionFieldMat[102X ([14X7.3-10[114X).[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XR := RepetitionCode( 4, GF(4) );[127X[104X
    [4X[28Xa cyclic [4,1,4]3 repetition code over GF(4)[128X[104X
    [4X[25Xgap>[125X [27XR2 := ConversionFieldCode( R );[127X[104X
    [4X[28Xa linear [8,2,4]3..4 code, converted to basefield GF(2)[128X[104X
    [4X[25Xgap>[125X [27XSize( R ) = Size( R2 );[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XGeneratorMat( R );[127X[104X
    [4X[28X[ [ Z(2)^0, Z(2)^0, Z(2)^0, Z(2)^0 ] ][128X[104X
    [4X[25Xgap>[125X [27XGeneratorMat( R2 );[127X[104X
    [4X[28X[ [ Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2) ],[128X[104X
    [4X[28X  [ 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0 ] ] [128X[104X
  [4X[32X[104X
  
  [1X6.1-16 TraceCode[101X
  
  [33X[1;0Y[29X[2XTraceCode[102X( [3XC[103X ) [32X function[133X
  
  [33X[0;0YInput:  [3XC[103X is a linear code defined over an extension [22XE[122X of [3XF[103X ([3XF[103X is the ``base
  field'')[133X
  
  [33X[0;0YOutput: The linear code generated by [22XTr_E/F(c)[122X, for all [22Xc ∈ C[122X.[133X
  
  [33X[0;0Y[10XTraceCode[110X  returns the image of the code [3XC[103X under the trace map. If the field
  of [3XC[103X is [22XGF(q^m)[122X, the returned code has field [22XGF(q)[122X.[133X
  
  [33X[0;0YVery  slow.  It  does  not  seem to be easy to related the parameters of the
  trace code to the original except in the ``Galois closed'' case.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XC:=RandomLinearCode(10,4,GF(4)); MinimumDistance(C);[127X[104X
    [4X[28Xa  [10,4,?] randomly generated code over GF(4)[128X[104X
    [4X[28X5[128X[104X
    [4X[25Xgap>[125X [27XtrC:=TraceCode(C,GF(2)); MinimumDistance(trC);[127X[104X
    [4X[28Xa linear [10,7,1]1..3 user defined unrestricted code over GF(2)[128X[104X
    [4X[28X1[128X[104X
    [4X[28X[128X[104X
  [4X[32X[104X
  
  [1X6.1-17 CosetCode[101X
  
  [33X[1;0Y[29X[2XCosetCode[102X( [3XC[103X, [3Xw[103X ) [32X function[133X
  
  [33X[0;0Y[10XCosetCode[110X returns the coset of a code [3XC[103X with respect to word [3Xw[103X. [3Xw[103X must be of
  the  codeword  type.  Then,  [3Xw[103X  is added to each codeword of [3XC[103X, yielding the
  elements  of  the new code. If [3XC[103X is linear and [3Xw[103X is an element of [3XC[103X, the new
  code is equal to [3XC[103X, otherwise the new code is an unrestricted code.[133X
  
  [33X[0;0YGenerating  a  coset  is also possible by simply adding the word [3Xw[103X to [3XC[103X. See
  [14X4.2[114X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XH := HammingCode(3, GF(2));[127X[104X
    [4X[28Xa linear [7,4,3]1 Hamming (3,2) code over GF(2)[128X[104X
    [4X[25Xgap>[125X [27Xc := Codeword("1011011");; c in H;[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27XC := CosetCode(H, c);[127X[104X
    [4X[28Xa (7,16,3)1 coset code[128X[104X
    [4X[25Xgap>[125X [27XList(AsSSortedList(C), el-> Syndrome(H, el));[127X[104X
    [4X[28X[ [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ],[128X[104X
    [4X[28X  [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ],[128X[104X
    [4X[28X  [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ] ][128X[104X
    [4X[28X# All elements of the coset have the same syndrome in H [128X[104X
  [4X[32X[104X
  
  [1X6.1-18 ConstantWeightSubcode[101X
  
  [33X[1;0Y[29X[2XConstantWeightSubcode[102X( [3XC[103X, [3Xw[103X ) [32X function[133X
  
  [33X[0;0Y[10XConstantWeightSubcode[110X  returns  the  subcode of [3XC[103X that only has codewords of
  weight  [3Xw[103X.  The  resulting  code  is  a non-linear code, because it does not
  contain the all-zero vector.[133X
  
  [33X[0;0YThis  command also can be called with the syntax [10XConstantWeightSubcode(C)[110X In
  this  format,  [10XConstantWeightSubcode[110X  returns the subcode of [3XC[103X consisting of
  all minimum weight codewords of [3XC[103X.[133X
  
  [33X[0;0Y[10XConstantWeightSubcode[110X  first  checks  if Leon's binary [10Xwtdist[110X exists on your
  computer  (in  the  default  directory).  If  it  does, then this program is
  called.  Otherwise,  the  constant  weight  subcode  is computed using a GAP
  program  which  checks  each  codeword  in  [3XC[103X to see if it is of the desired
  weight.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XN := NordstromRobinsonCode();; WeightDistribution(N);[127X[104X
    [4X[28X[ 1, 0, 0, 0, 0, 0, 112, 0, 30, 0, 112, 0, 0, 0, 0, 0, 1 ][128X[104X
    [4X[25Xgap>[125X [27XC := ConstantWeightSubcode(N, 8);[127X[104X
    [4X[28Xa (16,30,6..16)5..8 code with codewords of weight 8[128X[104X
    [4X[25Xgap>[125X [27XWeightDistribution(C);[127X[104X
    [4X[28X[ 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0 ] [128X[104X
    [4X[25Xgap>[125X [27Xeg := ExtendedTernaryGolayCode();; WeightDistribution(eg);[127X[104X
    [4X[28X[ 1, 0, 0, 0, 0, 0, 264, 0, 0, 440, 0, 0, 24 ][128X[104X
    [4X[25Xgap>[125X [27XC := ConstantWeightSubcode(eg);[127X[104X
    [4X[28Xa (12,264,6..12)3..6 code with codewords of weight 6[128X[104X
    [4X[25Xgap>[125X [27XWeightDistribution(C);[127X[104X
    [4X[28X[ 0, 0, 0, 0, 0, 0, 264, 0, 0, 0, 0, 0, 0 ] [128X[104X
  [4X[32X[104X
  
  [1X6.1-19 StandardFormCode[101X
  
  [33X[1;0Y[29X[2XStandardFormCode[102X( [3XC[103X ) [32X function[133X
  
  [33X[0;0Y[10XStandardFormCode[110X  returns  [3XC[103X  after  putting  it in standard form. If [3XC[103X is a
  non-linear code, this means the elements are organized using lexicographical
  order. This means they form a legal GAP `Set'.[133X
  
  [33X[0;0YIf  [3XC[103X is a linear code, the generator matrix and parity check matrix are put
  in  standard                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           