  
  [1m[4m[31m6. Manipulating Codes[0m
  
  In  this  chapter  we  describe  several  functions [1mGUAVA[0m uses to manipulate
  codes.  Some  of  the best codes are obtained by starting with for example a
  BCH code, and manipulating it.
  
  In  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.
  
  Because  [1mGUAVA[0m  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.
  
  In  Section  [1m6.1[0m,  we  describe  functions  that  take  a  code with certain
  parameters,  modify  it  in  some  way  and  return  a  different  code (see
  [1m[34mExtendedCode[0m  ([1m6.1-1[0m),  [1m[34mPuncturedCode[0m  ([1m6.1-2[0m),  [1m[34mEvenWeightSubcode[0m  ([1m6.1-3[0m),
  [1m[34mPermutedCode[0m   ([1m6.1-4[0m),   [1m[34mExpurgatedCode[0m   ([1m6.1-5[0m),  [1m[34mAugmentedCode[0m  ([1m6.1-6[0m),
  [1m[34mRemovedElementsCode[0m   ([1m6.1-7[0m),   [1m[34mAddedElementsCode[0m   ([1m6.1-8[0m),  [1m[34mShortenedCode[0m
  ([1m6.1-9[0m),  [1m[34mLengthenedCode[0m  ([1m6.1-10[0m),  [1m[34mResidueCode[0m ([1m6.1-11[0m), [1m[34mConstructionBCode[0m
  ([1m6.1-12[0m),      [1m[34mDualCode[0m      ([1m6.1-13[0m),     [1m[34mConversionFieldCode[0m     ([1m6.1-14[0m),
  [1m[34mConstantWeightSubcode[0m  ([1m6.1-17[0m),  [1m[34mStandardFormCode[0m  ([1m6.1-18[0m)  and  [1m[34mCosetCode[0m
  ([1m6.1-16[0m)).  In  Section  [1m6.2[0m, we describe functions that generate a new code
  out   of   two   codes   (see   [1m[34mDirectSumCode[0m   ([1m6.2-1[0m),   [1m[34mUUVCode[0m  ([1m6.2-2[0m),
  [1m[34mDirectProductCode[0m ([1m6.2-3[0m), [1m[34mIntersectionCode[0m ([1m6.2-4[0m) and [1m[34mUnionCode[0m ([1m6.2-5[0m)).
  
  
  [1m[4m[31m6.1 Functions that Generate a New Code from a Given Code[0m
  
  [1m[4m[31m6.1-1 ExtendedCode[0m
  
  [1m[34m> ExtendedCode( [0m[22m[34mC[, i][0m[1m[34m ) ___________________________________________[0mfunction
  
  [22m[32mExtendedCode[0m  extends  the code [22m[34mC[0m [22m[34mi[0m times and returns the result. [22m[34mi[0m is equal
  to  1  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.
  
  The  word  length  increases by [22m[34mi[0m. 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.
  
  A cyclic code in general is no longer cyclic after extending.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := HammingCode( 3, GF(2) );[0m
    [22m[35ma linear [7,4,3]1 Hamming (3,2) code over GF(2)[0m
    [22m[35mgap> C2 := ExtendedCode( C1 );[0m
    [22m[35ma linear [8,4,4]2 extended code[0m
    [22m[35mgap> IsEquivalent( C2, ReedMullerCode( 1, 3 ) );[0m
    [22m[35mtrue[0m
    [22m[35mgap> List( AsSSortedList( C2 ), WeightCodeword );[0m
    [22m[35m[ 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8 ][0m
    [22m[35mgap> C3 := EvenWeightSubcode( C1 );[0m
    [22m[35ma linear [7,3,4]2..3 even weight subcode [0m
  [22m[35m------------------------------------------------------------------[0m
  
  To  undo  extending,  call  [22m[32mPuncturedCode[0m  (see  [1m[34mPuncturedCode[0m ([1m6.1-2[0m)). The
  function  [22m[32mEvenWeightSubcode[0m  (see  [1m[34mEvenWeightSubcode[0m ([1m6.1-3[0m)) also returns a
  related code with only even weights, but without changing its word length.
  
  [1m[4m[31m6.1-2 PuncturedCode[0m
  
  [1m[34m> PuncturedCode( [0m[22m[34mC[0m[1m[34m ) _______________________________________________[0mfunction
  
  [22m[32mPuncturedCode[0m  punctures  [22m[34mC[0m  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.
  
  This  command  can  also be called with the syntax [22m[32mPuncturedCode( C, L )[0m. In
  this  case,  [22m[32mPuncturedCode[0m punctures [22m[34mC[0m in the columns specified by [22m[34mL[0m, a list
  of integers. All columns specified by [22m[34mL[0m are omitted from each codeword. If l
  is  the  length  of  [22m[34mL[0m  (so  the number of removed columns), the word length
  decreases by l. The minimum distance can also decrease by l or less.
  
  Puncturing  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.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := BCHCode( 15, 5, GF(2) );[0m
    [22m[35ma cyclic [15,7,5]3..5 BCH code, delta=5, b=1 over GF(2)[0m
    [22m[35mgap> C2 := PuncturedCode( C1 );[0m
    [22m[35ma linear [14,7,4]3..5 punctured code[0m
    [22m[35mgap> ExtendedCode( C2 ) = C1;[0m
    [22m[35mfalse[0m
    [22m[35mgap> PuncturedCode( C1, [1,2,3,4,5,6,7] );[0m
    [22m[35ma linear [8,7,1]1 punctured code[0m
    [22m[35mgap> PuncturedCode( WholeSpaceCode( 4, GF(5) ) );[0m
    [22m[35ma linear [3,3,1]0 punctured code  # The dimension decreased from 4 to 3 [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [22m[32mExtendedCode[0m  extends the code again (see [1m[34mExtendedCode[0m ([1m6.1-1[0m)), although in
  general this does not result in the old code.
  
  [1m[4m[31m6.1-3 EvenWeightSubcode[0m
  
  [1m[34m> EvenWeightSubcode( [0m[22m[34mC[0m[1m[34m ) ___________________________________________[0mfunction
  
  [22m[32mEvenWeightSubcode[0m  returns  the  even weight subcode of [22m[34mC[0m, consisting of all
  codewords of [22m[34mC[0m with even weight. If [22m[34mC[0m 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 [22m[34mC[0m is a binary cyclic
  code,  and  g(x) is its generator polynomial, the even weight subcode either
  has  generator  polynomial g(x) (if g(x) is divisible by x-1) or g(x)* (x-1)
  (if  no factor x-1 was present in g(x)). So the even weight subcode is again
  cyclic.
  
  Of  course,  if  all codewords of [22m[34mC[0m are already of even weight, the returned
  code is equal to [22m[34mC[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := EvenWeightSubcode( BCHCode( 8, 4, GF(3) ) );[0m
    [22m[35man (8,33,4..8)3..8 even weight subcode[0m
    [22m[35mgap> List( AsSSortedList( C1 ), WeightCodeword );[0m
    [22m[35m[ 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, [0m
    [22m[35m  4, 6, 4, 6, 8, 4, 6, 8 ][0m
    [22m[35mgap> EvenWeightSubcode( ReedMullerCode( 1, 3 ) );[0m
    [22m[35ma linear [8,4,4]2 Reed-Muller (1,3) code over GF(2) [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [22m[32mExtendedCode[0m  also  returns a related code of only even weights, but without
  reducing its dimension (see [1m[34mExtendedCode[0m ([1m6.1-1[0m)).
  
  [1m[4m[31m6.1-4 PermutedCode[0m
  
  [1m[34m> PermutedCode( [0m[22m[34mC, L[0m[1m[34m ) _____________________________________________[0mfunction
  
  [22m[32mPermutedCode[0m  returns  [22m[34mC[0m after column permutations. [22m[34mL[0m (in [1mGAP[0m disjoint cycle
  notation)  is  the  permutation  to be executed on the columns of [22m[34mC[0m. If [22m[34mC[0m is
  cyclic,  the result in general is no longer cyclic. If a permutation results
  in the same code as [22m[34mC[0m, this permutation belongs to the automorphism group of
  [22m[34mC[0m  (see  [1m[34mAutomorphismGroup[0m  ([1m4.4-3[0m)).  In  any  case,  the  returned code is
  equivalent to [22m[34mC[0m (see [1m[34mIsEquivalent[0m ([1m4.4-1[0m)).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := PuncturedCode( ReedMullerCode( 1, 4 ) );[0m
    [22m[35ma linear [15,5,7]5 punctured code[0m
    [22m[35mgap> C2 := BCHCode( 15, 7, GF(2) );[0m
    [22m[35ma cyclic [15,5,7]5 BCH code, delta=7, b=1 over GF(2)[0m
    [22m[35mgap> C2 = C1;[0m
    [22m[35mfalse[0m
    [22m[35mgap> p := CodeIsomorphism( C1, C2 );[0m
    [22m[35m( 2, 4,14, 9,13, 7,11,10, 6, 8,12, 5)[0m
    [22m[35mgap> C3 := PermutedCode( C1, p );[0m
    [22m[35ma linear [15,5,7]5 permuted code[0m
    [22m[35mgap> C2 = C3;[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.1-5 ExpurgatedCode[0m
  
  [1m[34m> ExpurgatedCode( [0m[22m[34mC, L[0m[1m[34m ) ___________________________________________[0mfunction
  
  [22m[32mExpurgatedCode[0m  expurgates the code [22m[34mC[0m> by throwing away codewords in list [22m[34mL[0m.
  [22m[34mC[0m  must  be a linear code. [22m[34mL[0m must be a list of codeword input. The generator
  matrix  of  the new code no longer is a basis for the codewords specified by
  [22m[34mL[0m.  Since the returned code is still linear, it is very likely that, besides
  the words of [22m[34mL[0m, more codewords of [22m[34mC[0m are no longer in the new code.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := HammingCode( 4 );; WeightDistribution( C1 );[0m
    [22m[35m[ 1, 0, 0, 35, 105, 168, 280, 435, 435, 280, 168, 105, 35, 0, 0, 1 ][0m
    [22m[35mgap> L := Filtered( AsSSortedList(C1), i -> WeightCodeword(i) = 3 );;[0m
    [22m[35mgap> C2 := ExpurgatedCode( C1, L );[0m
    [22m[35ma linear [15,4,3..4]5..11 code, expurgated with 7 word(s)[0m
    [22m[35mgap> WeightDistribution( C2 );[0m
    [22m[35m[ 1, 0, 0, 0, 14, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ] [0m
  [22m[35m------------------------------------------------------------------[0m
  
  This  function  does not work on non-linear codes. For removing words from a
  non-linear  code, use [22m[32mRemovedElementsCode[0m (see [1m[34mRemovedElementsCode[0m ([1m6.1-7[0m)).
  For  expurgating  a code of all words of odd weight, use `EvenWeightSubcode'
  (see [1m[34mEvenWeightSubcode[0m ([1m6.1-3[0m)).
  
  [1m[4m[31m6.1-6 AugmentedCode[0m
  
  [1m[34m> AugmentedCode( [0m[22m[34mC, L[0m[1m[34m ) ____________________________________________[0mfunction
  
  [22m[32mAugmentedCode[0m returns [22m[34mC[0m after augmenting. [22m[34mC[0m must be a linear code, [22m[34mL[0m must be
  a  list  of codeword inputs. The generator matrix of the new code is a basis
  for  the  codewords specified by [22m[34mL[0m as well as the words that were already in
  code  [22m[34mC[0m.  Note  that the new code in general will consist of more words than
  only  the codewords of [22m[34mC[0m and the words [22m[34mL[0m. The returned code is also a linear
  code.
  
  This  command  can  also  be  called  with the syntax [22m[32mAugmentedCode(C)[0m. When
  called without a list of codewords, [22m[32mAugmentedCode[0m returns [22m[34mC[0m after adding the
  all-ones  vector  to  the  generator matrix. [22m[34mC[0m 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  [22m[34mC[0m  is  a binary code which does not contain the
  all-ones vector, the complement of all codewords is added.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C31 := ReedMullerCode( 1, 3 );[0m
    [22m[35ma linear [8,4,4]2 Reed-Muller (1,3) code over GF(2)[0m
    [22m[35mgap> C32 := AugmentedCode(C31,["00000011","00000101","00010001"]);[0m
    [22m[35ma linear [8,7,1..2]1 code, augmented with 3 word(s)[0m
    [22m[35mgap> C32 = ReedMullerCode( 2, 3 );[0m
    [22m[35mtrue [0m
    [22m[35mgap> C1 := CordaroWagnerCode(6);[0m
    [22m[35ma linear [6,2,4]2..3 Cordaro-Wagner code over GF(2)[0m
    [22m[35mgap> Codeword( [0,0,1,1,1,1] ) in C1;[0m
    [22m[35mtrue[0m
    [22m[35mgap> C2 := AugmentedCode( C1 );[0m
    [22m[35ma linear [6,3,1..2]2..3 code, augmented with 1 word(s)[0m
    [22m[35mgap> Codeword( [1,1,0,0,0,0] ) in C2;[0m
    [22m[35mtrue[0m
  [22m[35m------------------------------------------------------------------[0m
  
  The  function  [22m[32mAddedElementsCode[0m  adds  elements to the codewords instead of
  adding them to the basis (see [1m[34mAddedElementsCode[0m ([1m6.1-8[0m)).
  
  [1m[4m[31m6.1-7 RemovedElementsCode[0m
  
  [1m[34m> RemovedElementsCode( [0m[22m[34mC, L[0m[1m[34m ) ______________________________________[0mfunction
  
  [22m[32mRemovedElementsCode[0m returns code [22m[34mC[0m after removing a list of codewords [22m[34mL[0m from
  its  elements.  [22m[34mL[0m  must  be  a  list  of  codeword  input.  The result is an
  unrestricted code.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := HammingCode( 4 );; WeightDistribution( C1 );[0m
    [22m[35m[ 1, 0, 0, 35, 105, 168, 280, 435, 435, 280, 168, 105, 35, 0, 0, 1 ][0m
    [22m[35mgap> L := Filtered( AsSSortedList(C1), i -> WeightCodeword(i) = 3 );;[0m
    [22m[35mgap> C2 := RemovedElementsCode( C1, L );[0m
    [22m[35ma (15,2013,3..15)2..15 code with 35 word(s) removed[0m
    [22m[35mgap> WeightDistribution( C2 );[0m
    [22m[35m[ 1, 0, 0, 0, 105, 168, 280, 435, 435, 280, 168, 105, 35, 0, 0, 1 ][0m
    [22m[35mgap> MinimumDistance( C2 );[0m
    [22m[35m3        # C2 is not linear, so the minimum weight does not have to[0m
    [22m[35m         # be equal to the minimum distance [0m
  [22m[35m------------------------------------------------------------------[0m
  
  Adding  elements  to  a  code is done by the function [22m[32mAddedElementsCode[0m (see
  [1m[34mAddedElementsCode[0m  ([1m6.1-8[0m)).  To  remove codewords from the base of a linear
  code, use [22m[32mExpurgatedCode[0m (see [1m[34mExpurgatedCode[0m ([1m6.1-5[0m)).
  
  [1m[4m[31m6.1-8 AddedElementsCode[0m
  
  [1m[34m> AddedElementsCode( [0m[22m[34mC, L[0m[1m[34m ) ________________________________________[0mfunction
  
  [22m[32mAddedElementsCode[0m  returns  code [22m[34mC[0m after adding a list of codewords [22m[34mL[0m to its
  elements.  [22m[34mL[0m must be a list of codeword input. The result is an unrestricted
  code.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := NullCode( 6, GF(2) );[0m
    [22m[35ma cyclic [6,0,6]6 nullcode over GF(2)[0m
    [22m[35mgap> C2 := AddedElementsCode( C1, [ "111111" ] );[0m
    [22m[35ma (6,2,1..6)3 code with 1 word(s) added[0m
    [22m[35mgap> IsCyclicCode( C2 );[0m
    [22m[35mtrue[0m
    [22m[35mgap> C3 := AddedElementsCode( C2, [ "101010", "010101" ] );[0m
    [22m[35ma (6,4,1..6)2 code with 2 word(s) added[0m
    [22m[35mgap> IsCyclicCode( C3 );[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  To   remove   elements   from   a   code,   use   [22m[32mRemovedElementsCode[0m   (see
  [1m[34mRemovedElementsCode[0m  ([1m6.1-7[0m)). To add elements to the base of a linear code,
  use [22m[32mAugmentedCode[0m (see [1m[34mAugmentedCode[0m ([1m6.1-6[0m)).
  
  [1m[4m[31m6.1-9 ShortenedCode[0m
  
  [1m[34m> ShortenedCode( [0m[22m[34mC[, L][0m[1m[34m ) __________________________________________[0mfunction
  
  [22m[32mShortenedCode(  C  )[0m returns the code [22m[34mC[0m shortened by taking a cross section.
  If  [22m[34mC[0m  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 [22m[34mC[0m was a
  [n,k,d]  code,  the  shortened  code  generally is a [n-1,k-1,d] code. It is
  possible  that  the dimension remains the same; it is also possible that the
  minimum distance increases.
  
  If  [22m[34mC[0m  is  a  non-linear code, [22m[32mShortenedCode[0m 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 [22m[34mC[0m.
  
  This  command  can  also be called using the syntax [22m[32mShortenedCode(C,L)[0m. When
  called  in this format, [22m[32mShortenedCode[0m repeats the shortening process on each
  of the columns specified by [22m[34mL[0m. [22m[34mL[0m therefore is a list of integers. The column
  numbers in [22m[34mL[0m are the numbers as they are before the shortening process. If [22m[34mL[0m
  has  l  entries,  the returned code has a word length of l positions shorter
  than [22m[34mC[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := HammingCode( 4 );[0m
    [22m[35ma linear [15,11,3]1 Hamming (4,2) code over GF(2)[0m
    [22m[35mgap> C2 := ShortenedCode( C1 );[0m
    [22m[35ma linear [14,10,3]2 shortened code[0m
    [22m[35mgap> C3 := ElementsCode( ["1000", "1101", "0011" ], GF(2) );[0m
    [22m[35ma (4,3,1..4)2 user defined unrestricted code over GF(2)[0m
    [22m[35mgap> MinimumDistance( C3 );[0m
    [22m[35m2[0m
    [22m[35mgap> C4 := ShortenedCode( C3 );[0m
    [22m[35ma (3,2,2..3)1..2 shortened code[0m
    [22m[35mgap> AsSSortedList( C4 );[0m
    [22m[35m[ [ 0 0 0 ], [ 1 0 1 ] ][0m
    [22m[35mgap> C5 := HammingCode( 5, GF(2) );[0m
    [22m[35ma linear [31,26,3]1 Hamming (5,2) code over GF(2)[0m
    [22m[35mgap> C6 := ShortenedCode( C5, [ 1, 2, 3 ] );[0m
    [22m[35ma linear [28,23,3]2 shortened code[0m
    [22m[35mgap> OptimalityLinearCode( C6 );[0m
    [22m[35m0[0m
  [22m[35m------------------------------------------------------------------[0m
  
  The  function  [22m[32mLengthenedCode[0m  lengthens  the  code  again  (only for linear
  codes),  see  [1m[34mLengthenedCode[0m  ([1m6.1-10[0m).  In general, this is not exactly the
  inverse function.
  
  [1m[4m[31m6.1-10 LengthenedCode[0m
  
  [1m[34m> LengthenedCode( [0m[22m[34mC[, i][0m[1m[34m ) _________________________________________[0mfunction
  
  [22m[32mLengthenedCode(  C )[0m returns the code [22m[34mC[0m lengthened. [22m[34mC[0m must be a linear code.
  First,   the   all-ones  vector  is  added  to  the  generator  matrix  (see
  [1m[34mAugmentedCode[0m  ([1m6.1-6[0m)).  If  the  all-ones  vector  was already a codeword,
  nothing  happens  to  the  code.  Then,  the  code  is extended [22m[34mi[0m times (see
  [1m[34mExtendedCode[0m  ([1m6.1-1[0m)).  [22m[34mi[0m is equal to 1 by default. If [22m[34mC[0m was an [n,k] code,
  the new code generally is a [n+i,k+1] code.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := CordaroWagnerCode( 5 );[0m
    [22m[35ma linear [5,2,3]2 Cordaro-Wagner code over GF(2)[0m
    [22m[35mgap> C2 := LengthenedCode( C1 );[0m
    [22m[35ma linear [6,3,2]2..3 code, lengthened with 1 column(s) [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [22m[32mShortenedCode[0m'  shortens  the  code,  see [1m[34mShortenedCode[0m ([1m6.1-9[0m). In general,
  this is not exactly the inverse function.
  
  [1m[4m[31m6.1-11 ResidueCode[0m
  
  [1m[34m> ResidueCode( [0m[22m[34mC[, c][0m[1m[34m ) ____________________________________________[0mfunction
  
  The  function  [22m[32mResidueCode[0m  takes  a  codeword  [22m[34mc[0m  of  [22m[34mC[0m (if [22m[34mc[0m 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  [22m[34mc[0m  is  unequal  to zero. The resulting code is an [n-w, k-1, d-lfloor
  w*(q-1)/q  rfloor ] code. [22m[34mC[0m must be a linear code and [22m[34mc[0m must be non-zero. If
  [22m[34mc[0m is not in [22m[34m[0m then no change is made to [22m[34mC[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := BCHCode( 15, 7 );[0m
    [22m[35ma cyclic [15,5,7]5 BCH code, delta=7, b=1 over GF(2)[0m
    [22m[35mgap> C2 := ResidueCode( C1 );[0m
    [22m[35ma linear [8,4,4]2 residue code[0m
    [22m[35mgap> c := Codeword( [ 0,0,0,1,0,0,1,1,0,1,0,1,1,1,1 ], C1);;[0m
    [22m[35mgap> C3 := ResidueCode( C1, c );[0m
    [22m[35ma linear [7,4,3]1 residue code [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.1-12 ConstructionBCode[0m
  
  [1m[34m> ConstructionBCode( [0m[22m[34mC[0m[1m[34m ) ___________________________________________[0mfunction
  
  The  function  [22m[32mConstructionBCode[0m takes a binary linear code [22m[34mC[0m and calculates
  the  minimum  distance  of  the  dual  of [22m[34mC[0m (see [1m[34mDualCode[0m ([1m6.1-13[0m)). It then
  removes  the columns of the parity check matrix of [22m[34mC[0m 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 [n-dd, k-dd+1, >= d] code, where dd
  is the minimum distance of the dual of [22m[34mC[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := ReedMullerCode( 2, 5 );[0m
    [22m[35ma linear [32,16,8]6 Reed-Muller (2,5) code over GF(2)[0m
    [22m[35mgap> C2 := ConstructionBCode( C1 );[0m
    [22m[35ma linear [24,9,8]5..10 Construction B (8 coordinates)[0m
    [22m[35mgap> BoundsMinimumDistance( 24, 9, GF(2) );[0m
    [22m[35mrec( n := 24, k := 9, q := 2, references := rec(  ), [0m
    [22m[35m  construction := [ [ Operation "UUVCode" ], [0m
    [22m[35m      [ [ [ Operation "UUVCode" ], [ [ [ Operation "DualCode" ], [0m
    [22m[35m                      [ [ [ Operation "RepetitionCode" ], [ 6, 2 ] ] ] ], [0m
    [22m[35m                  [ [ Operation "CordaroWagnerCode" ], [ 6 ] ] ] ], [0m
    [22m[35m          [ [ Operation "CordaroWagnerCode" ], [ 12 ] ] ] ], lowerBound := 8, [0m
    [22m[35m  lowerBoundExplanation := [ "Lb(24,9)=8, u u+v construction of C1 and C2:", [0m
    [22m[35m      "Lb(12,7)=4, u u+v construction of C1 and C2:", [0m
    [22m[35m      "Lb(6,5)=2, dual of the repetition code", [0m
    [22m[35m      "Lb(6,2)=4, Cordaro-Wagner code", "Lb(12,2)=8, Cordaro-Wagner code" ], [0m
    [22m[35m  upperBound := 8, [0m
    [22m[35m  upperBoundExplanation := [ "Ub(24,9)=8, otherwise construction B would [0m
    [22m[35m                             contradict:", "Ub(18,4)=8, Griesmer bound" ] )[0m
    [22m[35m# so C2 is optimal[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.1-13 DualCode[0m
  
  [1m[34m> DualCode( [0m[22m[34mC[0m[1m[34m ) ____________________________________________________[0mfunction
  
  [22m[32mDualCode[0m returns the dual code of [22m[34mC[0m. The dual code consists of all codewords
  that  are  orthogonal  to  the  codewords  of  [22m[34mC[0m. If [22m[34mC[0m is a linear code with
  generator  matrix  G,  the  dual code has parity check matrix G (or if [22m[34mC[0m has
  parity  check  matrix H, the dual code has generator matrix H). So if [22m[34mC[0m is a
  linear  [n, k] code, the dual code of [22m[34mC[0m is a linear [n, n-k] code. If [22m[34mC[0m is a
  cyclic code with generator polynomial g(x), the dual code has the reciprocal
  polynomial of g(x) as check polynomial.
  
  The dual code is always a linear code, even if [22m[34mC[0m is non-linear.
  
  If a code [22m[34mC[0m is equal to its dual code, it is called [22m[36mself-dual[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> RD := DualCode( R );[0m
    [22m[35ma linear [8,4,4]2 Reed-Muller (1,3) code over GF(2)[0m
    [22m[35mgap> R = RD;[0m
    [22m[35mtrue[0m
    [22m[35mgap> N := WholeSpaceCode( 7, GF(4) );[0m
    [22m[35ma cyclic [7,7,1]0 whole space code over GF(4)[0m
    [22m[35mgap> DualCode( N ) = NullCode( 7, GF(4) );[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.1-14 ConversionFieldCode[0m
  
  [1m[34m> ConversionFieldCode( [0m[22m[34mC[0m[1m[34m ) _________________________________________[0mfunction
  
  [22m[32mConversionFieldCode[0m  returns  the  code obtained from [22m[34mC[0m after converting its
  field. If the field of [22m[34mC[0m is GF(q^m), the returned code has field GF(q). Each
  symbol  of  every  codeword is replaced by a concatenation of m symbols from
  GF(q).  If  [22m[34mC[0m  is an (n, M, d_1) code, the returned code is a (n* m, M, d_2)
  code, where d_2 > d_1.
  
  See also [1m[34mHorizontalConversionFieldMat[0m ([1m7.3-10[0m).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> R := RepetitionCode( 4, GF(4) );[0m
    [22m[35ma cyclic [4,1,4]3 repetition code over GF(4)[0m
    [22m[35mgap> R2 := ConversionFieldCode( R );[0m
    [22m[35ma linear [8,2,4]3..4 code, converted to basefield GF(2)[0m
    [22m[35mgap> Size( R ) = Size( R2 );[0m
    [22m[35mtrue[0m
    [22m[35mgap> GeneratorMat( R );[0m
    [22m[35m[ [ Z(2)^0, Z(2)^0, Z(2)^0, Z(2)^0 ] ][0m
    [22m[35mgap> GeneratorMat( R2 );[0m
    [22m[35m[ [ Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2) ],[0m
    [22m[35m  [ 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0, 0*Z(2), Z(2)^0 ] ] [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.1-15 TraceCode[0m
  
  [1m[34m> TraceCode( [0m[22m[34mC[0m[1m[34m ) ___________________________________________________[0mfunction
  
  Input:  [22m[34mC[0m is a linear code defined over an extension E of [22m[34mF[0m ([22m[34mF[0m is the ``base
  field'')
  
  Output: The linear code generated by Tr_E/F(c), for all c in C.
  
  [22m[32mTraceCode[0m  returns the image of the code [22m[34mC[0m under the trace map. If the field
  of [22m[34mC[0m is GF(q^m), the returned code has field GF(q).
  
  Very  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.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C:=RandomLinearCode(10,4,GF(4)); MinimumDistance(C);[0m
    [22m[35ma  [10,4,?] randomly generated code over GF(4)[0m
    [22m[35m5[0m
    [22m[35mgap> trC:=TraceCode(C,GF(2)); MinimumDistance(trC);[0m
    [22m[35ma linear [10,7,1]1..3 user defined unrestricted code over GF(2)[0m
    [22m[35m1[0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.1-16 CosetCode[0m
  
  [1m[34m> CosetCode( [0m[22m[34mC, w[0m[1m[34m ) ________________________________________________[0mfunction
  
  [22m[32mCosetCode[0m returns the coset of a code [22m[34mC[0m with respect to word [22m[34mw[0m. [22m[34mw[0m must be of
  the  codeword  type.  Then,  [22m[34mw[0m  is added to each codeword of [22m[34mC[0m, yielding the
  elements  of  the new code. If [22m[34mC[0m is linear and [22m[34mw[0m is an element of [22m[34mC[0m, the new
  code is equal to [22m[34mC[0m, otherwise the new code is an unrestricted code.
  
  Generating  a  coset  is also possible by simply adding the word [22m[34mw[0m to [22m[34mC[0m. See
  [1m4.2[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> H := HammingCode(3, GF(2));[0m
    [22m[35ma linear [7,4,3]1 Hamming (3,2) code over GF(2)[0m
    [22m[35mgap> c := Codeword("1011011");; c in H;[0m
    [22m[35mfalse[0m
    [22m[35mgap> C := CosetCode(H, c);[0m
    [22m[35ma (7,16,3)1 coset code[0m
    [22m[35mgap> List(AsSSortedList(C), el-> Syndrome(H, el));[0m
    [22m[35m[ [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ],[0m
    [22m[35m  [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ],[0m
    [22m[35m  [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ], [ 1 1 1 ] ][0m
    [22m[35m# All elements of the coset have the same syndrome in H [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.1-17 ConstantWeightSubcode[0m
  
  [1m[34m> ConstantWeightSubcode( [0m[22m[34mC, w[0m[1m[34m ) ____________________________________[0mfunction
  
  [22m[32mConstantWeightSubcode[0m  returns  the  subcode of [22m[34mC[0m that only has codewords of
  weight  [22m[34mw[0m.  The  resulting  code  is  a non-linear code, because it does not
  contain the all-zero vector.
  
  This  command also can be called with the syntax [22m[32mConstantWeightSubcode(C)[0m In
  this  format,  [22m[32mConstantWeightSubcode[0m  returns the subcode of [22m[34mC[0m consisting of
  all minimum weight codewords of [22m[34mC[0m.
  
  [22m[32mConstantWeightSubcode[0m  first  checks  if Leon's binary [22m[32mwtdist[0m 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 [1mGAP[0m
  program  which  checks  each  codeword  in  [22m[34mC[0m to see if it is of the desired
  weight.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> N := NordstromRobinsonCode();; WeightDistribution(N);[0m
    [22m[35m[ 1, 0, 0, 0, 0, 0, 112, 0, 30, 0, 112, 0, 0, 0, 0, 0, 1 ][0m
    [22m[35mgap> C := ConstantWeightSubcode(N, 8);[0m
    [22m[35ma (16,30,6..16)5..8 code with codewords of weight 8[0m
    [22m[35mgap> WeightDistribution(C);[0m
    [22m[35m[ 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0 ] [0m
    [22m[35mgap> eg := ExtendedTernaryGolayCode();; WeightDistribution(eg);[0m
    [22m[35m[ 1, 0, 0, 0, 0, 0, 264, 0, 0, 440, 0, 0, 24 ][0m
    [22m[35mgap> C := ConstantWeightSubcode(eg);[0m
    [22m[35ma (12,264,6..12)3..6 code with codewords of weight 6[0m
    [22m[35mgap> WeightDistribution(C);[0m
    [22m[35m[ 0, 0, 0, 0, 0, 0, 264, 0, 0, 0, 0, 0, 0 ] [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.1-18 StandardFormCode[0m
  
  [1m[34m> StandardFormCode( [0m[22m[34mC[0m[1m[34m ) ____________________________________________[0mfunction
  
  [22m[32mStandardFormCode[0m  returns  [22m[34mC[0m  after  putting  it in standard form. If [22m[34mC[0m is a
  non-linear code, this means the elements are organized using lexicographical
  order. This means they form a legal [1mGAP[0m `Set'.
  
  If  [22m[34mC[0m is a linear code, the generator matrix and parity check matrix are put
  in  standard  form.  The generator matrix then has an identity matrix in its
  left part, the parity check matrix has an identity matrix in its right part.
  Although  [1mGUAVA[0m  always puts both matrices in a standard form using [22m[32mBaseMat[0m,
  this   never   alters   the   code.  [22m[32mStandardFormCode[0m  even  applies  column
  permutations  if  unavoidable,  and  thereby  changes  the  code. The column
  permutations  are  recorded in the construction history of the new code (see
  [1m[34mDisplay[0m ([1m4.6-3[0m)). [22m[34mC[0m and the new code are of course equivalent.
  
  If [22m[34mC[0m is a cyclic code, its generator matrix cannot be put in the usual upper
  triangular  form,  because  then it would be inconsistent with the generator
  polynomial.  The  reason  is that generating the elements from the generator
  matrix  would  result in a different order than generating the elements from
  the  generator  polynomial.  This  is  an  unwanted  effect,  and  therefore
  [22m[32mStandardFormCode[0m just returns a copy of [22m[34mC[0m for cyclic codes.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> G := GeneratorMatCode( Z(2) * [ [0,1,1,0], [0,1,0,1], [0,0,1,1] ], [0m
    [22m[35m          "random form code", GF(2) );[0m
    [22m[35ma linear [4,2,1..2]1..2 random form code over GF(2)[0m
    [22m[35mgap> Codeword( GeneratorMat( G ) );[0m
    [22m[35m[ [ 0 1 0 1 ], [ 0 0 1 1 ] ][0m
    [22m[35mgap> Codeword( GeneratorMat( StandardFormCode( G ) ) );[0m
    [22m[35m[ [ 1 0 0 1 ], [ 0 1 0 1 ] ] [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.1-19 PiecewiseConstantCode[0m
  
  [1m[34m> PiecewiseConstantCode( [0m[22m[34mpart, wts[, F][0m[1m[34m ) __________________________[0mfunction
  
  [22m[32mPiecewiseConstantCode[0m  returns  a code with length n = sum n_i, where [22m[34mpart[0m=[
  n_1,  dots,  n_k  ].  [22m[34mwts[0m  is a list of [22m[34mconstraints[0m w=(w_1,...,w_k), each of
  length k, where 0 <= w_i <= n_i. The default field is GF(2).
  
  A  constraint  is  a  list  of  integers,  and a word c = ( c_1, dots, c_k )
  (according  to  [22m[34mpart[0m,  i.e.,  each c_i is a subword of length n_i) is in the
  resulting code if and only if, for some constraint w in [22m[34mwts[0m, |c_i| = w_i for
  all 1 <= i <= k, where | ...| denotes the Hamming weight.
  
  An example might make things clearer:
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> PiecewiseConstantCode( [ 2, 3 ],[0m
    [22m[35m     [ [ 0, 0 ], [ 0, 3 ], [ 1, 0 ], [ 2, 2 ] ],GF(2) );[0m
    [22m[35mthe C code programs are compiled, so using Leon's binary....[0m
    [22m[35mthe C code programs are compiled, so using Leon's binary....[0m
    [22m[35mthe C code programs are compiled, so using Leon's binary....[0m
    [22m[35mthe C code programs are compiled, so using Leon's binary....[0m
    [22m[35ma (5,7,1..5)1..5 piecewise constant code over GF(2)[0m
    [22m[35mgap> AsSSortedList(last);[0m
    [22m[35m[ [ 0 0 0 0 0 ], [ 0 0 1 1 1 ], [ 0 1 0 0 0 ], [ 1 0 0 0 0 ], [0m
    [22m[35m  [ 1 1 0 1 1 ], [ 1 1 1 0 1 ], [ 1 1 1 1 0 ] ][0m
    [22m[35mgap>[0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  The  first  constraint is satisfied by codeword 1, the second by codeword 2,
  the third by codewords 3 and 4, and the fourth by codewords 5, 6 and 7.
  
  
  [1m[4m[31m6.2 Functions that Generate a New Code from Two Given Codes[0m
  
  [1m[4m[31m6.2-1 DirectSumCode[0m
  
  [1m[34m> DirectSumCode( [0m[22m[34mC1, C2[0m[1m[34m ) __________________________________________[0mfunction
  
  [22m[32mDirectSumCode[0m returns the direct sum of codes [22m[34mC1[0m and [22m[34mC2[0m. The direct sum code
  consists  of  every  codeword  of  [22m[34mC1[0m  concatenated by every codeword of [22m[34mC2[0m.
  Therefore,   if   [22m[34mCi[0m   was   a   (n_i,M_i,d_i)   code,   the   result  is  a
  (n_1+n_2,M_1*M_2,min(d_1,d_2)) code.
  
  If both [22m[34mC1[0m and [22m[34mC2[0m are linear codes, the result is also a linear code. If one
  of  them  is  non-linear,  the  direct  sum is non-linear too. In general, a
  direct sum code is not cyclic.
  
  Performing  a  direct  sum can also be done by adding two codes (see Section
  [1m4.2[0m).  Another  often used method is the `u, u+v'-construction, described in
  [1m[34mUUVCode[0m ([1m6.2-2[0m).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := ElementsCode( [ [1,0], [4,5] ], GF(7) );;[0m
    [22m[35mgap> C2 := ElementsCode( [ [0,0,0], [3,3,3] ], GF(7) );;[0m
    [22m[35mgap> D := DirectSumCode(C1, C2);;[0m
    [22m[35mgap> AsSSortedList(D);[0m
    [22m[35m[ [ 1 0 0 0 0 ], [ 1 0 3 3 3 ], [ 4 5 0 0 0 ], [ 4 5 3 3 3 ] ][0m
    [22m[35mgap> D = C1 + C2;   # addition = direct sum[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.2-2 UUVCode[0m
  
  [1m[34m> UUVCode( [0m[22m[34mC1, C2[0m[1m[34m ) ________________________________________________[0mfunction
  
  [22m[32mUUVCode[0m returns the so-called (u|u+v) construction applied to [22m[34mC1[0m and [22m[34mC2[0m. The
  resulting code consists of every codeword u of [22m[34mC1[0m concatenated by the sum of
  u  and  every  codeword  v  of [22m[34mC2[0m. If [22m[34mC1[0m and [22m[34mC2[0m have different word lengths,
  sufficient zeros are added to the shorter code to make this sum possible. If
  [22m[34mCi[0m  is  a  (n_i,M_i,d_i)  code,  the  result  is  an  (n_1+max(n_1,n_2),M_1*
  M_2,min(2* d_1,d_2)) code.
  
  If both [22m[34mC1[0m and [22m[34mC2[0m are linear codes, the result is also a linear code. If one
  of  them is non-linear, the UUV sum is non-linear too. In general, a UUV sum
  code is not cyclic.
  
  The  function  [22m[32mDirectSumCode[0m returns another sum of codes (see [1m[34mDirectSumCode[0m
  ([1m6.2-1[0m)).
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := EvenWeightSubcode(WholeSpaceCode(4, GF(2)));[0m
    [22m[35ma cyclic [4,3,2]1 even weight subcode[0m
    [22m[35mgap> C2 := RepetitionCode(4, GF(2));[0m
    [22m[35ma cyclic [4,1,4]2 repetition code over GF(2)[0m
    [22m[35mgap> R := UUVCode(C1, C2);[0m
    [22m[35ma linear [8,4,4]2 U U+V construction code[0m
    [22m[35mgap> R = ReedMullerCode(1,3);[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.2-3 DirectProductCode[0m
  
  [1m[34m> DirectProductCode( [0m[22m[34mC1, C2[0m[1m[34m ) ______________________________________[0mfunction
  
  [22m[32mDirectProductCode[0m  returns  the direct product of codes [22m[34mC1[0m and [22m[34mC2[0m. Both must
  be  linear codes. Suppose [22m[34mCi[0m has generator matrix G_i. The direct product of
  [22m[34mC1[0m  and  [22m[34mC2[0m  then  has the Kronecker product of G_1 and G_2 as the generator
  matrix (see the [1mGAP[0m command [22m[32mKroneckerProduct[0m).
  
  If  [22m[34mCi[0m  is  a  [n_i,  k_i,  d_i]  code,  the direct product then is an [n_1*
  n_2,k_1* k_2,d_1* d_2] code.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> L1 := LexiCode(10, 4, GF(2));[0m
    [22m[35ma linear [10,5,4]2..4 lexicode over GF(2)[0m
    [22m[35mgap> L2 := LexiCode(8, 3, GF(2));[0m
    [22m[35ma linear [8,4,3]2..3 lexicode over GF(2)[0m
    [22m[35mgap> D := DirectProductCode(L1, L2);[0m
    [22m[35ma linear [80,20,12]20..45 direct product code [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.2-4 IntersectionCode[0m
  
  [1m[34m> IntersectionCode( [0m[22m[34mC1, C2[0m[1m[34m ) _______________________________________[0mfunction
  
  [22m[32mIntersectionCode[0m  returns  the  intersection  of  codes [22m[34mC1[0m and [22m[34mC2[0m. This code
  consists  of  all  codewords  that  are both in [22m[34mC1[0m and [22m[34mC2[0m. If both codes are
  linear,  the  result  is also linear. If both are cyclic, the result is also
  cyclic.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C := CyclicCodes(7, GF(2));[0m
    [22m[35m[ a cyclic [7,7,1]0 enumerated code over GF(2),[0m
    [22m[35m  a cyclic [7,6,1..2]1 enumerated code over GF(2),[0m
    [22m[35m  a cyclic [7,3,1..4]2..3 enumerated code over GF(2),[0m
    [22m[35m  a cyclic [7,0,7]7 enumerated code over GF(2),[0m
    [22m[35m  a cyclic [7,3,1..4]2..3 enumerated code over GF(2),[0m
    [22m[35m  a cyclic [7,4,1..3]1 enumerated code over GF(2),[0m
    [22m[35m  a cyclic [7,1,7]3 enumerated code over GF(2),[0m
    [22m[35m  a cyclic [7,4,1..3]1 enumerated code over GF(2) ][0m
    [22m[35mgap> IntersectionCode(C[6], C[8]) = C[7];[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  The  [22m[36mhull[0m  of  a  linear  code is the intersection of the code with its dual
  code. In other words, the hull of C is [22m[32mIntersectionCode(C, DualCode(C))[0m.
  
  [1m[4m[31m6.2-5 UnionCode[0m
  
  [1m[34m> UnionCode( [0m[22m[34mC1, C2[0m[1m[34m ) ______________________________________________[0mfunction
  
  [22m[32mUnionCode[0m  returns  the  union of codes [22m[34mC1[0m and [22m[34mC2[0m. This code consists of the
  union  of  all codewords of [22m[34mC1[0m and [22m[34mC2[0m and all linear combinations. Therefore
  this  function  works  only for linear codes. The function [22m[32mAddedElementsCode[0m
  can  be  used  for  non-linear  codes,  or  if the resulting code should not
  include   linear   combinations.  See  [1m[34mAddedElementsCode[0m  ([1m6.1-8[0m).  If  both
  arguments are cyclic, the result is also cyclic.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> G := GeneratorMatCode([[1,0,1],[0,1,1]]*Z(2)^0, GF(2));[0m
    [22m[35ma linear [3,2,1..2]1 code defined by generator matrix over GF(2)[0m
    [22m[35mgap> H := GeneratorMatCode([[1,1,1]]*Z(2)^0, GF(2));[0m
    [22m[35ma linear [3,1,3]1 code defined by generator matrix over GF(2)[0m
    [22m[35mgap> U := UnionCode(G, H);[0m
    [22m[35ma linear [3,3,1]0 union code[0m
    [22m[35mgap> c := Codeword("010");; c in G;[0m
    [22m[35mfalse[0m
    [22m[35mgap> c in H;[0m
    [22m[35mfalse[0m
    [22m[35mgap> c in U;[0m
    [22m[35mtrue [0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.2-6 ExtendedDirectSumCode[0m
  
  [1m[34m> ExtendedDirectSumCode( [0m[22m[34mL, B, m[0m[1m[34m ) _________________________________[0mfunction
  
  The extended direct sum construction is described in section V of Graham and
  Sloane  [GS85].  The  resulting  code consists of [22m[34mm[0m copies of [22m[34mL[0m, extended by
  repeating the codewords of [22m[34mB[0m [22m[34mm[0m times.
  
  Suppose  [22m[34mL[0m  is  an  [n_L,  k_L]r_L  code,  and  [22m[34mB[0m  is  an [n_L, k_B]r_B code
  (non-linear  codes are also permitted). The length of [22m[34mB[0m must be equal to the
  length  of [22m[34mL[0m. The length of the new code is n = m n_L, the dimension (in the
  case  of  linear codes) is k <= m k_L + k_B, and the covering radius is r <=
  lfloor m Psi( L, B ) rfloor, with
  
  \[
       \Psi( L, B ) = \max_{u \in F_2^{n_L}} \frac{1}{2^{k_B}} \sum_{v
       \in B} {\rm d}( L, v + u ).
  \]
  
  However,  this  computation will not be executed, because it may be too time
  consuming for large codes.
  
  If  L  subseteq  B,  and  L  and  B  are linear codes, the last copy of [22m[34mL[0m is
  omitted. In this case the dimension is k = m k_L + (k_B - k_L).
  
  [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> d := WholeSpaceCode( 7, GF(2) );[0m
    [22m[35ma cyclic [7,7,1]0 whole space code over GF(2)[0m
    [22m[35mgap> e := ExtendedDirectSumCode( c, d, 3 );[0m
    [22m[35ma linear [21,15,1..3]2 3-fold extended direct sum code[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.2-7 AmalgamatedDirectSumCode[0m
  
  [1m[34m> AmalgamatedDirectSumCode( [0m[22m[34mc1, c2[, check][0m[1m[34m ) ______________________[0mfunction
  
  [22m[32mAmalgamatedDirectSumCode[0m  returns the amalgamated direct sum of the codes [22m[34mc1[0m
  and  [22m[34mc2[0m.  The  amalgamated  direct sum code consists of all codewords of the
  form (u , | ,0 , | , v) if (u , | , 0) in c_1 and (0 , | , v) in c_2 and all
  codewords of the form (u , | , 1 , | , v) if (u , | , 1) in c_1 and (1 , | ,
  v)  in c_2. The result is a code with length n = n_1 + n_2 - 1 and size M <=
  M_1 * M_2 / 2.
  
  If  both codes are linear, they will first be standardized, with information
  symbols  in  the  last  and  first coordinates of the first and second code,
  respectively.
  
  If  [22m[34mc1[0m  is a normal code (see [1m[34mIsNormalCode[0m ([1m7.4-5[0m)) with the last coordinate
  acceptable  (see  [1m[34mIsCoordinateAcceptable[0m  ([1m7.4-3[0m)),  and [22m[34mc2[0m is a normal code
  with  the  first  coordinate acceptable, then the covering radius of the new
  code is r <= r_1 + r_2. However, checking whether a code is normal or not is
  a  lot of work, and almost all codes seem to be normal. Therefore, an option
  [22m[34mcheck[0m  can be supplied. If [22m[34mcheck[0m is true, then the codes will be checked for
  normality. If [22m[34mcheck[0m is false or omitted, then the codes will not be checked.
  In  this  case it is assumed that they are normal. Acceptability of the last
  and  first  coordinate of the first and second code, respectively, is in the
  last case also assumed to be done by the user.
  
  [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> d := ReedMullerCode( 1, 4 );[0m
    [22m[35ma linear [16,5,8]6 Reed-Muller (1,4) code over GF(2)[0m
    [22m[35mgap> e := DirectSumCode( c, d );[0m
    [22m[35ma linear [23,9,3]7 direct sum code[0m
    [22m[35mgap> f := AmalgamatedDirectSumCode( c, d );;[0m
    [22m[35mgap> MinimumDistance( f );;[0m
    [22m[35mgap> CoveringRadius( f );; [0m
    [22m[35mgap> f;[0m
    [22m[35ma linear [22,8,3]7 amalgamated direct sum code[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m6.2-8 BlockwiseDirectSumCode[0m
  
  [1m[34m> BlockwiseDirectSumCode( [0m[22m[34mC1, L1, C2, L2[0m[1m[34m ) _________________________[0mfunction
  
  [22m[32mBlockwiseDirectSumCode[0m returns a subcode of the direct sum of [22m[34mC1[0m and [22m[34mC2[0m. The
  fields  of  [22m[34mC1[0m and [22m[34mC2[0m must be same. The lists [22m[34mL1[0m and [22m[34mL2[0m are two equally long
  with  elements from the ambient vector spaces of [22m[34mC1[0m and [22m[34mC2[0m, respectively, [22m[36mor[0m
  [22m[34mL1[0m  and  [22m[34mL2[0m  are  two  equally long lists containing codes. The union of the
  codes in [22m[34mL1[0m and [22m[34mL2[0m must be [22m[34mC1[0m and [22m[34mC2[0m, respectively.
  
  In the first case, the blockwise direct sum code is defined as
  
  \[
       bds = \bigcup_{1 \leq i \leq \ell} ( C_1 + (L_1)_i ) \oplus ( C_2
       + (L_2)_i ),
  \]
  
  where ell is the length of [22m[34mL1[0m and [22m[34mL2[0m, and oplus is the direct sum.
  
  In the second case, it is defined as
  
  \[
       bds = \bigcup_{1 \leq i \leq \ell} ( (L_1)_i \oplus (L_2)_i ).
  \]
  
  The length of the new code is n = n_1 + n_2.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35mgap> C1 := HammingCode( 3, GF(2) );;[0m
    [22m[35mgap> C2 := EvenWeightSubcode( WholeSpaceCode( 6, GF(2) ) );;[0m
    [22m[35mgap> BlockwiseDirectSumCode( C1, [[ 0,0,0,0,0,0,0 ],[ 1,0,1,0,1,0,0 ]],[0m
    [22m[35m> C2, [[ 0,0,0,0,0,0 ],[ 1,0,1,0,1,0 ]] );[0m
    [22m[35ma (13,1024,1..13)1..2 blockwise direct sum code[0m
  [22m[35m------------------------------------------------------------------[0m
  
