Changeset 7f3ad4 in git for Singular/LIB/decodegb.lib


Ignore:
Timestamp:
Jan 14, 2009, 5:07:05 PM (15 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'd0474371d8c5d8068ab70bfb42719c97936b18a6')
Children:
0721816437af5ddabc83aa203a12d9b58b42a33c
Parents:
95edd5641377e851d4a1d4e986853687991d0895
Message:
*hannes: format


git-svn-id: file:///usr/local/Singular/svn/trunk@11306 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/decodegb.lib

    r95edd5 r7f3ad4  
    11///////////////////////////////////////////////////////////////////////////////
    2 version="$Id: decodegb.lib,v 1.8 2008-10-22 13:31:48 bulygin Exp $";
     2version="$Id: decodegb.lib,v 1.9 2009-01-14 16:07:03 Singular Exp $";
    33category="Coding theory";
    44info="
    55LIBRARY: decodegb.lib         Decoding and min distance of linear codes with GB
    6 AUTHOR:  Stanislav Bulygin,   bulygin@mathematik.uni-kl.de                     
     6AUTHOR:  Stanislav Bulygin,   bulygin@mathematik.uni-kl.de
    77
    88OVERVIEW:
    99 In this library we generate several systems used for decoding cyclic codes and
    10  finding their minimum distance. Namely, we work with the Cooper's philosophy 
    11  and generalized Newton identities. The original method of quadratic equations 
    12  is worked out here as well. We also (for comparison) enable to work with the 
    13  system of Fitzgerald-Lax. We provide some auxiliary functions for further 
    14  manipulations and decoding. For an overview of the methods mentioned above @ref{Decoding codes with GB} 
    15  For the vanishing ideal computation the algorithm of Farr and Gao is 
     10 finding their minimum distance. Namely, we work with the Cooper's philosophy
     11 and generalized Newton identities. The original method of quadratic equations
     12 is worked out here as well. We also (for comparison) enable to work with the
     13 system of Fitzgerald-Lax. We provide some auxiliary functions for further
     14 manipulations and decoding. For an overview of the methods mentioned above @ref{Decoding codes with GB}
     15 For the vanishing ideal computation the algorithm of Farr and Gao is
    1616 implemented.
    1717
    18 MAIN PROCEDURES: 
     18MAIN PROCEDURES:
    1919 sysCRHT(..);        generates the CRHT-ideal as in Cooper's philosophy
    2020 sysCRHTMindist(..); CRHT-ideal to find the minimum distance in the binary case
     
    2929 genMDSMat(n,a);     generates an MDS (actually an RS) matrix
    3030 mindist(check);     computes the minimum distance of a code
    31  decode(rec);        decoding of a word using the system of quadratic equations 
     31 decode(rec);        decoding of a word using the system of quadratic equations
    3232 decodeRandom(..); a procedure for manipulation with random codes
    3333 decodeCode(..);   a procedure for manipulation with the given code
     
    3535 sysFL(..);          generates the Fitzgerald-Lax system
    3636 decodeRandomFL(..); manipulation with random codes via Fitzgerald-Lax
    37  
    38 
    39 KEYWORDS:  Cyclic code; Linear code; Decoding; 
     37
     38
     39KEYWORDS:  Cyclic code; Linear code; Decoding;
    4040           Minimum distance; Groebner bases
    4141";
     
    7676
    7777///////////////////////////////////////////////////////////////////////////////
    78 // the polynomial for Sala's restrictions 
     78// the polynomial for Sala's restrictions
    7979static proc p_poly(int n, int a, int b)
    8080{
     
    9292"USAGE:   sysCRHT(n,defset,e,q,m,[k]); n,e,q,m,k int, defset list of int's
    9393@format
    94          - n length of the cyclic code, 
     94         - n length of the cyclic code,
    9595         - defset is a list representing the defining set,
    96          - e the error-correcting capacity, 
     96         - e the error-correcting capacity,
    9797         - q field size
    98          - m degree extension of the splitting field, 
    99          - if k>0 additional equations representing the fact that every two 
     98         - m degree extension of the splitting field,
     99         - if k>0 additional equations representing the fact that every two
    100100         error positions are either different or at least one of them is zero
    101101@end format
    102 RETURN: the ring to work with the CRHT-ideal (with Sala's additions), 
     102RETURN: the ring to work with the CRHT-ideal (with Sala's additions),
    103103        containig an ideal with name 'crht'
    104 THEORY:  Based on 'defset' of the given cyclic code, the procedure constructs 
    105          the corresponding Cooper-Reed-Heleseth-Truong ideal 'crht'. With its 
     104THEORY:  Based on 'defset' of the given cyclic code, the procedure constructs
     105         the corresponding Cooper-Reed-Heleseth-Truong ideal 'crht'. With its
    106106         help one can solve the decoding problem. For basics of the method @ref{Cooper philosophy}.
    107107SEE ALSO: sysNewton, sysBin
     
    109109"
    110110{
    111   int r=size(defset); 
     111  int r=size(defset);
    112112  ring @crht=(q,a),(Y(e..1),Z(1..e),X(r..1)),lp;
    113113  ideal crht;
     
    115115  poly sum;
    116116  int k;
    117   if ( size(#) > 0) 
    118   { 
    119     k = #[1]; 
    120   }
    121  
     117  if ( size(#) > 0)
     118  {
     119    k = #[1];
     120  }
     121
    122122  //---------------------- add check equations --------------------------
    123123  for (i=1; i<=r; i++)
     
    130130    crht[i]=sum-X(i);
    131131  }
    132  
     132
    133133  //--------------------- field equations on syndromes ------------------
    134134  for (i=1; i<=r; i++)
     
    136136    crht=crht,X(i)^(q^m)-X(i);
    137137  }
    138  
     138
    139139  //------ restrictions on error-locations: n-th roots of unity ----------
    140140  for (i=1; i<=e; i++)
     
    142142    crht=crht,Z(i)^(n+1)-Z(i);
    143143  }
    144  
     144
    145145  for (i=1; i<=e; i++)
    146146  {
    147147    crht=crht,Y(i)^(q-1)-1;
    148   } 
    149  
     148  }
     149
    150150  //--------- add Sala's additional conditions if necessary --------------
    151151  if ( k > 0 )
    152  
     152
    153153  {
    154154    for (i=1; i<=e; i++)
     
    159159      }
    160160    }
    161   } 
    162   export crht; 
    163   return(@crht);   
    164 } 
     161  }
     162  export crht;
     163  return(@crht);
     164}
    165165example
    166166{ "EXAMPLE:"; echo=2;
     
    168168  intvec v = option(get);
    169169
    170   list defset=1,3;           // defining set 
     170  list defset=1,3;           // defining set
    171171  int n=15;                  // length
    172172  int e=2;                   // error-correcting capacity
     
    174174  int m=4;                   // degree extension of the splitting field
    175175  int sala=1;                // indicator to add additional equations
    176    
    177   def A=sysCRHT(n,defset,e,q,m); 
     176
     177  def A=sysCRHT(n,defset,e,q,m);
    178178  setring A;
    179179  A;                         // shows the ring we are working in
    180   print(crht);               // the CRHT-ideal 
     180  print(crht);               // the CRHT-ideal
    181181  option(redSB);
    182182  ideal red_crht=std(crht);  // reduced Groebner basis
    183183  print(red_crht);
    184  
     184
    185185  //============================
    186   A=sysCRHT(n,defset,e,q,m,sala); 
    187   setring A; 
     186  A=sysCRHT(n,defset,e,q,m,sala);
     187  setring A;
    188188  print(crht);                // CRHT-ideal with additional equations from Sala
    189189  option(redSB);
    190190  ideal red_crht=std(crht);   // reduced Groebner basis
    191   print(red_crht);           
     191  print(red_crht);
    192192  red_crht[5];                // general error-locator polynomial for this code
    193193  option(set,v);
     
    198198
    199199proc sysCRHTMindist (int n, list defset, int w)
    200 "USAGE:  sysCRHTMindist(n,defset,w);  n,w are int, defset is list of int's 
     200"USAGE:  sysCRHTMindist(n,defset,w);  n,w are int, defset is list of int's
    201201@format
    202         - n length of the cyclic code, 
     202        - n length of the cyclic code,
    203203        - defset is a list representing the defining set,
    204204        - w is a candidate for the minimum distance
    205205@end format
    206 RETURN:  the ring to work with the Sala's ideal for the minimum distance 
     206RETURN:  the ring to work with the Sala's ideal for the minimum distance
    207207         containing the ideal with name 'crht_md'
    208 THEORY:  Based on 'defset' of the given cyclic code, the procedure constructs 
    209          the corresponding Cooper-Reed-Heleseth-Truong ideal 'crht_md'. With 
    210          its help one can find minimum distance of the code in the binary 
     208THEORY:  Based on 'defset' of the given cyclic code, the procedure constructs
     209         the corresponding Cooper-Reed-Heleseth-Truong ideal 'crht_md'. With
     210         its help one can find minimum distance of the code in the binary
    211211         case. For basics of the method @ref{Cooper philosophy}.
    212212EXAMPLE: example sysCRHTMindist; shows an example
    213213"
    214214{
    215   int r=size(defset); 
     215  int r=size(defset);
    216216  ring @crht_md=2,Z(1..w),lp;
    217217  ideal crht_md;
    218218  int i,j;
    219219  poly sum;
    220  
     220
    221221  //------------ add check equations --------------
    222222  for (i=1; i<=r; i++)
     
    228228    }
    229229    crht_md[i]=sum;
    230   } 
    231  
    232  
     230  }
     231
     232
    233233  //----------- locations are n-th roots of unity ------------
    234234  for (i=1; i<=w; i++)
    235235  {
    236236    crht_md=crht_md,Z(i)^n-1;
    237   } 
    238  
     237  }
     238
    239239  //------------ adding conditions on locations being different ------------
    240240  for (i=1; i<=w; i++)
     
    245245    }
    246246  }
    247    
    248   export crht_md; 
    249   return(@crht_md);   
    250 } 
     247
     248  export crht_md;
     249  return(@crht_md);
     250}
    251251example
    252252{
     
    254254  intvec v = option(get);
    255255  // binary cyclic [15,7,5] code with defining set (1,3)
    256  
    257   list defset=1,3;             // defining set 
    258   int n=15;                    // length 
    259   int d=5;                     // candidate for the minimum distance 
    260      
    261   def A=sysCRHTMindist(n,defset,d); 
     256
     257  list defset=1,3;             // defining set
     258  int n=15;                    // length
     259  int d=5;                     // candidate for the minimum distance
     260
     261  def A=sysCRHTMindist(n,defset,d);
    262262  setring A;
    263263  A;                           // shows the ring we are working in
    264264  print(crht_md);              // the Sala's ideal for mindist
    265265  option(redSB);
    266   ideal red_crht_md=std(crht_md);     
     266  ideal red_crht_md=std(crht_md);
    267267  print(red_crht_md);          // reduced Groebner basis
    268  
     268
    269269  option(set,v);
    270270}
     
    281281
    282282proc sysNewton (int n, list defset, int t, int q, int m, list #)
    283 "USAGE:   sysNewton (n,defset,t,q,m,[tr]); n,t,q,m,tr int, defset list int's 
     283"USAGE:   sysNewton (n,defset,t,q,m,[tr]); n,t,q,m,tr int, defset list int's
    284284@format
    285          - n is length, 
     285         - n is length,
    286286         - defset is the defining set,
    287          - t is the number of errors, 
    288          - q is basefield size, 
     287         - t is the number of errors,
     288         - q is basefield size,
    289289         - m is degree extension of the splitting field,
    290          - if tr>0 it indicates that Newton identities in triangular 
     290         - if tr>0 it indicates that Newton identities in triangular
    291291           form should be constructed
    292292@end format
    293 RETURN:  the ring to work with the generalized Newton identities (in 
     293RETURN:  the ring to work with the generalized Newton identities (in
    294294         triangular form if applicable) containing the ideal with name 'newton'
    295 THEORY:  Based on 'defset' of the given cyclic code, the procedure constructs 
    296          the corresponding ideal 'newton' with the generalized Newton 
    297          identities. With its help one can solve the decoding problem. For 
     295THEORY:  Based on 'defset' of the given cyclic code, the procedure constructs
     296         the corresponding ideal 'newton' with the generalized Newton
     297         identities. With its help one can solve the decoding problem. For
    298298         basics of the method @ref{Cooper philosophy}.
    299299SEE ALSO: sysCRHT, sysBin
    300300EXAMPLE:  example sysNewton; shows an example
    301301"
    302 { 
     302{
    303303 string s="ring @newton=("+string(q)+",a),(";
    304304 int i,j;
    305305 int flag;
    306306 int tr;
    307  
     307
    308308 if (size(#)>0)
    309309 {
    310310  tr=#[1];
    311311 }
    312  
     312
    313313 for (i=n; i>=1; i--)
    314314 {
     
    319319    {
    320320      flag=0;
    321       break;     
     321      break;
    322322    }
    323323  }
     
    332332  s=s+"S("+string(defset[i])+"),";
    333333 }
    334  s=s+"S("+string(defset[1])+")),lp;"; 
    335  
     334 s=s+"S("+string(defset[1])+")),lp;";
     335
    336336 execute(s);
    337  
    338  ideal newton; 
     337
     338 ideal newton;
    339339 poly sum;
    340  
    341  
     340
     341
    342342 //------------ generate generalized Newton identities ----------
    343343 if (tr)
     
    353353  }
    354354 } else
    355  { 
     355 {
    356356  for (i=1; i<=t; i++)
    357357  {
     
    372372  }
    373373  newton=newton,S(t+i)+sum;
    374  } 
    375  
     374 }
     375
    376376 //----------- add field equations on sigma's --------------
    377377 for (i=1; i<=t; i++)
     
    379379  newton=newton,sigma(i)^(q^m)-sigma(i);
    380380 }
    381  
     381
    382382 //----------- add conjugacy relations ------------------
    383383 for (i=1; i<=n; i++)
     
    387387 newton=simplify(newton,2);
    388388 export newton;
    389  return(@newton); 
    390 } 
    391 example 
     389 return(@newton);
     390}
     391example
    392392{
    393393     "EXAMPLE:";  echo = 2;
    394      // Newton identities for a binary 3-error-correcting cyclic code of 
     394     // Newton identities for a binary 3-error-correcting cyclic code of
    395395     //length 31 with defining set (1,5,7)
    396      
     396
    397397     int n=31;          // length
    398398     list defset=1,5,7; //defining set
     
    401401     int m=5;           // degree extension of the splitting field
    402402     int tr=1;          // indicator of triangular form of Newton identities
    403      
    404      
     403
     404
    405405     def A=sysNewton(n,defset,t,q,m);
    406406     setring A;
    407407     A;                 // shows the ring we are working in
    408408     print(newton);     // generalized Newton identities
    409      
     409
    410410     //===============================
    411411     A=sysNewton(n,defset,t,q,m,tr);
    412      setring A;     
     412     setring A;
    413413     print(newton);     // generalized Newton identities in triangular form
    414414}
    415415
    416416///////////////////////////////////////////////////////////////////////////////
    417 // forms a list of special combinations needed for computation of Waring's 
     417// forms a list of special combinations needed for computation of Waring's
    418418//function
    419419static proc combinations_sum (int m, int n)
     
    438438   count++;
    439439  }
    440   if (flag) 
     440  if (flag)
    441441  {
    442442   for (j=2; j<=m; j++)
     
    444444    interm[i][j]=interm[i][j] div j;
    445445   }
    446    result[size(result)+1]=interm[i]; 
     446   result[size(result)+1]=interm[i];
    447447  }
    448448 }
     
    470470"USAGE:    sysBin (v,Q,n,[odd]);  v,n,odd are int, Q is list of int's
    471471@format
    472           - v a number if errors, 
    473           - Q is a generating set of the code, 
    474           - n the length, 
    475           - odd is an additional parameter: if 
    476            set to 1, then the generating set is enlarged by odd elements, 
     472          - v a number if errors,
     473          - Q is a generating set of the code,
     474          - n the length,
     475          - odd is an additional parameter: if
     476           set to 1, then the generating set is enlarged by odd elements,
    477477           which are 2^(some power)*(some elment in the gen.set) mod n
    478478@end format
    479479RETURN:    the ring with the resulting system called 'bin'
    480 THEORY:  Based on Q of the given cyclic code, the procedure constructs 
    481          the corresponding ideal 'bin' with the use of Waring function. 
    482          With its help one can solve the decoding problem. 
     480THEORY:  Based on Q of the given cyclic code, the procedure constructs
     481         the corresponding ideal 'bin' with the use of Waring function.
     482         With its help one can solve the decoding problem.
    483483         For basics of the method @ref{Generalized Newton identities}.
    484484SEE ALSO: sysNewton, sysCRHT
     
    527527  Q_update=Q;
    528528 }
    529  
    530  //---- form polynomials for the Bin system via Waring's function --------- 
     529
     530 //---- form polynomials for the Bin system via Waring's function ---------
    531531 for (i=1; i<=size(Q_update); i++)
    532532 {
     
    541541   }
    542542   count1=0;
    543    for (j=2; j<=upper-1; j++) 
     543   for (j=2; j<=upper-1; j++)
    544544   {
    545545    count1=count1+exp_count(j,2);
     
    564564   sum_=sum_+coef_*mon;
    565565  }
    566   result=result,S(Q_update[i])-sum_; 
     566  result=result,S(Q_update[i])-sum_;
    567567 }
    568568 ideal bin=simplify(result,2);
    569569 export bin;
    570570 return(r);
    571 } 
    572 example 
     571}
     572example
    573573{
    574574     "EXAMPLE:";  echo = 2;
     
    592592 if (ncols(x)!=nrows(g)) {print("ERRORencode2!");}
    593593 return(x*g);
    594 } 
    595 example 
     594}
     595example
    596596{
    597597     "EXAMPLE:";  echo = 2;
     
    603603                    0,0,0,1,1,1,0;
    604604     //encode x with the generator matrix g
    605      print(encode(x,g)); 
     605     print(encode(x,g));
    606606}
    607607
     
    616616 if (nrows(c)>1) {print("ERRORsyndrome1!");}
    617617 if (ncols(c)!=ncols(h)) {print("ERRORsyndrome2!");}
    618  return(h*transpose(c)); 
    619 } 
    620 example 
     618 return(h*transpose(c));
     619}
     620example
    621621{
    622622     "EXAMPLE:";  echo = 2;
     
    636636     print(syndrome(check,c));
    637637     c[1,3]=1;
    638      //now c is a codeword 
     638     //now c is a codeword
    639639     print(syndrome(check,c));
    640640}
     
    657657"USAGE:   sysQE(check,y,t,[fieldeq,formal]);check,y matrix;t,fieldeq,formal int
    658658@format
    659         - check is the check matrix of the code   
    660         - y is a received word, 
    661         - t the number of errors to be corrected, 
    662         - if fieldeq=1, then field equations are added, 
    663         - if formal=0, field equations on (known) syndrome variables 
    664           are not added, in order to add them (note that the exponent should 
     659        - check is the check matrix of the code
     660        - y is a received word,
     661        - t the number of errors to be corrected,
     662        - if fieldeq=1, then field equations are added,
     663        - if formal=0, field equations on (known) syndrome variables
     664          are not added, in order to add them (note that the exponent should
    665665          be as a number of elements in the INITIAL alphabet) one
    666666          needs to set formal>0 for the exponent
    667667@end format
    668668RETURN:   the ring to work with together with the resulting system called 'qe'
    669 THEORY:  Based on 'check' of the given linear code, the procedure constructs 
     669THEORY:  Based on 'check' of the given linear code, the procedure constructs
    670670         the corresponding ideal that gives an opportunity to compute
    671671         unknown syndrome of the received word y. Further
    672          one is able to solve the decoding problem. 
     672         one is able to solve the decoding problem.
    673673         For basics of the method @ref{Decoding method based on quadratic equations}.
    674674SEE ALSO: sysFL
     
    686686  formal=#[2];
    687687 }
    688  
    689  def br=basering; 
     688
     689 def br=basering;
    690690 list rl=ringlist(br);
    691  
     691
    692692 int red=nrows(check);
    693693 int n=ncols(check);
    694694 int q=rl[1][1];
    695  
     695
    696696 if (formal==0)
    697  { 
     697 {
    698698  ring work=(q,a),(V(1..t),U(1..n)),dp;
    699699 } else
     
    701701  ring work=(q,a),(V(1..t),U(1..n),s(1..red)),(dp(t),lp(n),dp(red));
    702702 }
    703  
     703
    704704 matrix check=imap(br,check);
    705705 matrix y=imap(br,y);
    706  
     706
    707707 matrix h_full=genMDSMat(n,a);
    708708 matrix h=submat(h_full,1..red,1..n);
    709709 if (nrows(y)!=1) {print("ERROR1Pell");}
    710710 if (ncols(y)!=n) {print("ERROR2Pell");}
    711  
     711
    712712 ideal result;
    713  
     713
    714714 list c;
    715715 list a;
     
    722722  c[i]=tmp;
    723723 }
    724  
     724
    725725 int tim=rtimer;
    726726 matrix transf=inverse(transpose(h_full));
    727  
     727
    728728 //------ expression matrix of check vectors w.r.t. the MDS basis -----------
    729729 tim=rtimer;
     
    733733  a[i]=transf*a[i];
    734734 }
    735  
     735
    736736 //----------- compute the structure constants ------------------------
    737737 tim=rtimer;
    738  matrix te[n][1]; 
     738 matrix te[n][1];
    739739 for (i=1; i<=n; i++)
    740740 {
     
    742742  {
    743743   if ((j<i)&&(i<=t+1)) {c[i][j]=c[j][i];}
    744    else 
     744   else
    745745   {
    746     if (i+j<=n+1) 
     746    if (i+j<=n+1)
    747747    {
    748748     c[i][j]=te;
    749      c[i][j][i+j-1,1]=1; 
     749     c[i][j][i+j-1,1]=1;
    750750    }
    751751    else
     
    753753     c[i][j]=star(h_full,i,j);
    754754     c[i][j]=transf*c[i][j];
    755     }   
     755    }
    756756   }
    757757  }
    758758 }
    759  
    760  
    761  tim=rtimer; 
     759
     760
     761 tim=rtimer;
    762762 if (formal==0)
    763763 {
     
    798798     result=result,V(j)^q-V(j);
    799799  }
    800  } 
    801  
     800 }
     801
    802802 //----- form the quadratic equations according to the theory -----------
    803803 for (i=1; i<=n; i++)
     
    819819  }
    820820  result=result,sum1-sum3;
    821  } 
    822  
     821 }
     822
    823823 result=simplify(result,2);
    824  
     824
    825825 ideal qe=result;
    826826 export qe;
    827  return(work); 
    828 } 
    829 example 
     827 return(work);
     828}
     829example
    830830{
    831831     "EXAMPLE:";  echo = 2;
    832832     intvec v = option(get);
    833      
     833
    834834     //correct 2 errors in [7,3] 8-ary code RS code
    835835     int t=2; int q=8; int n=7; int redun=4;
     
    840840     matrix x[1][3]=0,0,1,0;
    841841     matrix y[1][7]=encode(x,g);
    842      
     842
    843843     //disturb with 2 errors
    844      matrix rec[1][7]=errorInsert(y,list(2,4),list(1,a)); 
    845      
     844     matrix rec[1][7]=errorInsert(y,list(2,4),list(1,a));
     845
    846846     //generate the system
    847847     def A=sysQE(h,rec,t);
    848848     setring A;
    849849     print(qe);
    850      
     850
    851851     //let us decode
    852852     option(redSB);
    853853     ideal sys_qe=std(qe);
    854      print(sys_qe);     
    855      
     854     print(sys_qe);
     855
    856856     option(set,v);
    857857}
     
    862862"USAGE:  errorInsert(y,pos,val); y is matrix, pos,val list of int's
    863863@format
    864         - y is a (code) word, 
    865         - pos = positions where errors occured, 
     864        - y is a (code) word,
     865        - pos = positions where errors occured,
    866866        - val = their corresponding values
    867867@end format
     
    877877 }
    878878 return(result);
    879 } 
    880 example 
     879}
     880example
    881881{
    882882     "EXAMPLE:";  echo = 2;
     
    890890     matrix y[1][7]=encode(x,g);
    891891     print(y);
    892      
     892
    893893     //disturb with 2 errors
    894894     matrix rec[1][7]=errorInsert(y,list(2,4),list(1,a));
     
    902902"USAGE:    errorRand(y, num, e); y matrix, num,e int
    903903@format
    904           - y is a (code) word, 
    905           - num is the number of errors, 
     904          - y is a (code) word,
     905          - num is the number of errors,
    906906          - e is an extension degree (if one wants values to be from GF(p^e))
    907907@end format
     
    926926   }
    927927   if (flag) {pos[i]=temp;break;}
    928   } 
    929  }
    930  
     928  }
     929 }
     930
    931931 for (i=1; i<=num; i++)
    932932 {
    933933  flag=1;
    934934  while(flag)
    935   {   
    936    tempnum=randomvector(1,e);   
    937    if (tempnum!=0) {flag=0;}   
    938   }
    939   val[i]=tempnum; 
    940  }
    941  
     935  {
     936   tempnum=randomvector(1,e);
     937   if (tempnum!=0) {flag=0;}
     938  }
     939  val[i]=tempnum;
     940 }
     941
    942942 for (i=1; i<=size(pos); i++)
    943943 {
     
    945945 }
    946946 return(result);
    947 } 
    948 example 
     947}
     948example
    949949{
    950950  "EXAMPLE:";  echo = 2;
     
    957957     matrix x[1][3]=0,0,1,0;
    958958     matrix y[1][7]=encode(x,g);
    959      
     959
    960960     //disturb with 2 random errors
    961961     matrix rec[1][7]=errorRand(y,2,3);
    962962     print(rec);
    963      print(rec-y);     
     963     print(rec-y);
    964964}
    965965
     
    969969"USAGE:    randomCheck(m, n, e); m,n,e are int
    970970@format
    971           - m x n are dimensions of the matrix, 
     971          - m x n are dimensions of the matrix,
    972972          - e is an extension degree (if one wants values to be from GF(p^e))
    973973@end format
     
    986986  {
    987987   rand[i,j]=temp[j,1];
    988   } 
     988  }
    989989 }
    990990 result=concat(rand,unitmat(m));
    991991 return(result);
    992 } 
    993 example 
    994 {
    995   "EXAMPLE:";  echo = 2;     
     992}
     993example
     994{
     995  "EXAMPLE:";  echo = 2;
    996996     int redun=5; int n=15;
    997997     ring r=2,x,dp;
    998      
     998
    999999     //generate random check matrix for a [15,5] binary code
    10001000     matrix h=randomCheck(redun,n,1);
    10011001     print(h);
    1002      
     1002
    10031003     //corresponding generator matrix
    10041004     matrix g=dual_code(h);
    1005      print(g);     
     1005     print(g);
    10061006}
    10071007
     
    10111011"USAGE:   genMDSMat(n, a); n is int, a is number
    10121012@format
    1013         - n x n are dimensions of the MDS matrix, 
     1013        - n x n are dimensions of the MDS matrix,
    10141014        - a is a primitive element of the field.
    1015 @end format   
    1016 NOTE:   An MDS matrix is constructed in the following way. We take a to be a 
    1017         generator of the multiplicative group of the field. Then we construct 
     1015@end format
     1016NOTE:   An MDS matrix is constructed in the following way. We take a to be a
     1017        generator of the multiplicative group of the field. Then we construct
    10181018        the Vandermonde matrix with this a.
    1019 ASSUME:   extension field should already be defined 
     1019ASSUME:   extension field should already be defined
    10201020RETURN:   a matrix with the MDS property
    1021 EXAMPLE:  example genMDSMat; shows an example 
     1021EXAMPLE:  example genMDSMat; shows an example
    10221022"
    10231023{
     
    10291029  {
    10301030   result[j+1,i+1]=(a^i)^j;
    1031   } 
     1031  }
    10321032 }
    10331033 return(result);
    1034 } 
    1035 example 
     1034}
     1035example
    10361036{
    10371037     "EXAMPLE:";  echo = 2;
    10381038     int q=16; int n=15;
    10391039     ring r=(q,a),x,dp;
    1040      
     1040
    10411041     //generate an MDS (Vandermonde) matrix
    10421042     matrix h_full=genMDSMat(n,a);
    1043      print(h_full);     
     1043     print(h_full);
    10441044}
    10451045
     
    10501050"USAGE:  mindist (check, q); check matrix, q int
    10511051@format
    1052         - check is a check matrix, 
     1052        - check is a check matrix,
    10531053        - q is the field size
    10541054@end format
    1055 RETURN:  minimum distance of the code together with the time needed for its 
     1055RETURN:  minimum distance of the code together with the time needed for its
    10561056         calculation
    1057 EXAMPLE: example mindist; shows an example 
     1057EXAMPLE: example mindist; shows an example
    10581058"
    10591059{
     
    10611061
    10621062 int n=ncols(check); int redun=nrows(check); int t=redun+1;
    1063  
    1064  def br=basering; 
    1065  list rl=ringlist(br); 
     1063
     1064 def br=basering;
     1065 list rl=ringlist(br);
    10661066 int q=rl[1][1];
    1067  
    1068  ring work=(q,a),(V(1..t),U(1..n)),dp; 
    1069  matrix check=imap(br,check); 
    1070  
     1067
     1068 ring work=(q,a),(V(1..t),U(1..n)),dp;
     1069 matrix check=imap(br,check);
     1070
    10711071 ideal temp;
    10721072 int count=1;
     
    10741074 int flag2;
    10751075 int i, tim, timsolve;
    1076  matrix z[1][n]; 
     1076 matrix z[1][n];
    10771077 option(redSB);
    10781078 def A=sysQE(check,z,count);
    10791079
    1080  //proceed with solving the system w.r.t zero vector until some solutions 
     1080 //proceed with solving the system w.r.t zero vector until some solutions
    10811081 //are found
    10821082 while (flag)
     
    10871087    tim=rtimer;
    10881088    temp=std(temp);
    1089     timsolve=timsolve+rtimer-tim; 
     1089    timsolve=timsolve+rtimer-tim;
    10901090    flag2=1;
    10911091    setring work;
    1092     temp=imap(A,temp);   
     1092    temp=imap(A,temp);
    10931093    for (i=1; i<=n; i++)
    10941094    {
    1095       if 
    1096         (temp[i]!=U(n-i+1)) 
     1095      if
     1096        (temp[i]!=U(n-i+1))
    10971097        {
    10981098          flag2=0;
    10991099        }
    11001100    }
    1101     if (!flag2) 
     1101    if (!flag2)
    11021102    {
    11031103      flag=0;
    11041104    }
    1105     else 
     1105    else
    11061106    {
    11071107      count++;
    11081108    }
    11091109 }
    1110  list result=list(count,timsolve); 
    1111  
     1110 list result=list(count,timsolve);
     1111
    11121112 option(set,vopt);
    1113  return(result); 
    1114 } 
    1115 example 
     1113 return(result);
     1114}
     1115example
    11161116{
    11171117     "EXAMPLE:";  echo = 2;
    1118      //determine a minimum distance for a [7,3] binary code 
    1119      int q=8; int n=7; int redun=4; int t=redun+1; 
    1120      ring r=(q,a),x,dp;     
    1121                
     1118     //determine a minimum distance for a [7,3] binary code
     1119     int q=8; int n=7; int redun=4; int t=redun+1;
     1120     ring r=(q,a),x,dp;
     1121
    11221122     //generate random check matrix
    11231123     matrix h=randomCheck(redun,n,1);
    11241124     print(h);
    1125      list l=mindist(h);     
    1126      print(l[1]); 
    1127      //time for the comutation in secs   
    1128      print(l[2]);     
     1125     list l=mindist(h);
     1126     print(l[1]);
     1127     //time for the comutation in secs
     1128     print(l[2]);
    11291129}
    11301130
     
    11351135@format
    11361136          - check is the check matrix of the code,
    1137           - rec is a received word, 
     1137          - rec is a received word,
    11381138          - t is an upper bound for the number of errors one wants to correct
    11391139@end format
    1140 ASSUME:   Errors in rec should be correctable, otherwise the output is 
     1140ASSUME:   Errors in rec should be correctable, otherwise the output is
    11411141          unpredictable
    11421142RETURN:   a codeword that is closest to rec
    1143 EXAMPLE:  example decode; shows an example 
     1143EXAMPLE:  example decode; shows an example
    11441144"
    11451145{
    1146  intvec vopt = option(get); 
    1147  
     1146 intvec vopt = option(get);
     1147
    11481148 def br=basering;
    1149  int n=ncols(check); 
    1150  
    1151  int count=1; 
     1149 int n=ncols(check);
     1150
     1151 int count=1;
    11521152 def A=sysQE(check,rec,count);
    11531153 while(1)
    11541154 {
    11551155  A=sysQE(check,rec,count);
    1156   setring A;     
     1156  setring A;
    11571157  matrix h_full=genMDSMat(n,a);
    11581158  matrix rec=imap(br,rec);
    11591159  option(redSB);
    1160   ideal qe_red=std(qe);   
     1160  ideal qe_red=std(qe);
    11611161  if (qe_red[1]!=1)
    11621162  {
    11631163    break;
    11641164  }
    1165   else 
     1165  else
    11661166  {
    11671167    count++;
     
    11691169  setring br;
    11701170 }
    1171  
    1172  setring A; 
    1173      
     1171
     1172 setring A;
     1173
    11741174 //obtain a codeword
    11751175 //this works only if our code is indeed can correct these errors
     
    11781178 {
    11791179  syn[i,1]=-qe_red[n-i+1]+lead(qe_red[n-i+1]);
    1180  }   
    1181  
    1182  matrix real_syn=inverse(h_full)*syn; 
     1180 }
     1181
     1182 matrix real_syn=inverse(h_full)*syn;
    11831183 setring br;
    11841184 matrix real_syn=imap(A,real_syn);
    1185  
     1185
    11861186 option(set,vopt);
    1187  return(rec-transpose(real_syn));     
    1188 } 
    1189 example 
    1190 {
    1191      "EXAMPLE:";  echo = 2;     
    1192      //correct 1 error in [15,7] binary code 
     1187 return(rec-transpose(real_syn));
     1188}
     1189example
     1190{
     1191     "EXAMPLE:";  echo = 2;
     1192     //correct 1 error in [15,7] binary code
    11931193     int t=1; int q=16; int n=15; int redun=10;
    1194      ring r=(q,a),x,dp;     
    1195              
     1194     ring r=(q,a),x,dp;
     1195
    11961196     //generate random check matrix
    1197      matrix h=randomCheck(redun,n,1);     
     1197     matrix h=randomCheck(redun,n,1);
    11981198     matrix g=dual_code(h);
    11991199     matrix x[1][n-redun]=0,0,1,0,1,0,1;
    12001200     matrix y[1][n]=encode(x,g);
    12011201     print(y);
    1202      
     1202
    12031203     // find out the minimum distance of the code
    12041204     list l=mindist(h);
    1205      
     1205
    12061206     //disturb with errors
    12071207     "Correct ",(l[1]-1) div 2," errors";
    12081208     matrix rec[1][n]=errorRand(y,(l[1]-1) div 2,1);
    1209      print(rec);     
    1210      
     1209     print(rec);
     1210
    12111211     //let us decode
    12121212     matrix dec_word=decode(h,rec);
    1213      print(dec_word);     
     1213     print(dec_word);
    12141214}
    12151215
     
    12211221@format
    12221222          - redun is a redundabcy of a (random) code,
    1223           - q is the field size, 
     1223          - q is the field size,
    12241224          - ncodes is the number of random codes to be processed,
    12251225          - ntrials is the number of received vectors per code to be corrected
    1226           - If e is given it sets the correction capacity explicitly. It 
     1226          - If e is given it sets the correction capacity explicitly. It
    12271227          should be used in case one expects some lower bound,
    1228           otherwise the procedure tries to compute the real minimum distance 
     1228          otherwise the procedure tries to compute the real minimum distance
    12291229          to find out the error-correction capacity
    12301230@end format
    1231 RETURN:    nothing; 
    1232 EXAMPLE:   example decodeRandom; shows an example 
     1231RETURN:    nothing;
     1232EXAMPLE:   example decodeRandom; shows an example
    12331233"
    12341234{
     
    12481248 option(redSB);
    12491249 def br=basering;
    1250  matrix h_full=genMDSMat(n,a); 
     1250 matrix h_full=genMDSMat(n,a);
    12511251 matrix z[1][ncols(h_full)];
    12521252
     
    12681268     dist=tmp[1];
    12691269     printf("d= %p",dist);
    1270      t=(dist-1) div 2; 
    1271   }     
    1272   tim2=rtimer; 
     1270     t=(dist-1) div 2;
     1271  }
     1272  tim2=rtimer;
    12731273  tim3=rtimer;
    12741274
     
    12791279  ideal sys2,sys3;
    12801280  matrix h=imap(br,h);
    1281   matrix g=dual_code(h); 
     1281  matrix g=dual_code(h);
    12821282  ideal sys=qe;
    12831283  print("The system is generated");
    1284   timdec3=timdec3+rtimer-tim3; 
     1284  timdec3=timdec3+rtimer-tim3;
    12851285
    12861286  //------ modify the template according to every received word --------------
    12871287  for (j=1; j<=ntrials; j++)
    12881288  {
    1289    word=randomvector(n-redun,1);   
     1289   word=randomvector(n-redun,1);
    12901290   y=encode(transpose(word),g);
    1291    rec=errorRand(y,t,1);   
    1292    sys2=add_synd(rec,h,redun,sys); 
    1293  
     1291   rec=errorRand(y,t,1);
     1292   sys2=add_synd(rec,h,redun,sys);
     1293
    12941294   tim=rtimer;
    1295    sys3=std(sys2);   
    1296    timdec=timdec+rtimer-tim;   
    1297   } 
     1295   sys3=std(sys2);
     1296   timdec=timdec+rtimer-tim;
     1297  }
    12981298  timdec2=timdec2+rtimer-tim2;
    12991299  kill A;
    13001300  option(set,vopt);
    1301  } 
     1301 }
    13021302 printf("Time for mindist: %p", timdist);
    13031303 printf("Time for GB in mindist: %p", timdist);
    13041304 printf("Time for decoding: %p", timdec2);
    13051305 printf("Time for GB in decoding: %p", timdec);
    1306  printf("Time for sysQE in decoding: %p", timdec3); 
    1307 } 
    1308 example 
     1306 printf("Time for sysQE in decoding: %p", timdec3);
     1307}
     1308example
    13091309{
    13101310     "EXAMPLE:";  echo = 2;
    13111311     int q=32; int n=25; int redun=n-11; int t=redun+1;
    13121312     ring r=(q,a),x,dp;
    1313      
     1313
    13141314     // correct 2 errors in 5 random binary codes, 50 trials each
    1315      decodeRandom(n,redun,5,50,2); 
     1315     decodeRandom(n,redun,5,50,2);
    13161316}
    13171317
     
    13201320
    13211321proc decodeCode(matrix check, int ntrials, list #)
    1322 "USAGE:     decodeCode(check, ntrials, [e]); check matrix, ntrials,e int 
    1323 @format           
    1324            - check is a check matrix for the code, 
    1325            - ntrials is the number of received vectors per code to be 
     1322"USAGE:     decodeCode(check, ntrials, [e]); check matrix, ntrials,e int
     1323@format
     1324           - check is a check matrix for the code,
     1325           - ntrials is the number of received vectors per code to be
    13261326           corrected.
    1327            - If e is given it sets the correction capacity explicitly. It 
     1327           - If e is given it sets the correction capacity explicitly. It
    13281328           should be used in case one expects some lower bound,
    1329            otherwise the procedure tries to compute the real minimum distance 
     1329           otherwise the procedure tries to compute the real minimum distance
    13301330           to find out the error-correction capacity
    13311331@end format
    1332 RETURN:     nothing; 
    1333 EXAMPLE:    example decodeCode; shows an example 
     1332RETURN:     nothing;
     1333EXAMPLE:    example decodeCode; shows an example
    13341334"
    13351335{
     
    13511351 option(redSB);
    13521352 def br=basering;
    1353  matrix h_full=genMDSMat(n,a); 
     1353 matrix h_full=genMDSMat(n,a);
    13541354 matrix z[1][ncols(h_full)];
    13551355 setring br;
     
    13691369   dist=tmp[1];
    13701370   printf("d= %p",dist);
    1371    t=(dist-1) div 2; 
    1372  }     
    1373  tim2=rtimer; 
     1371   t=(dist-1) div 2;
     1372 }
     1373 tim2=rtimer;
    13741374 tim3=rtimer;
    13751375
     
    13801380 ideal sys2,sys3;
    13811381 matrix h=imap(br,h);
    1382  matrix g=dual_code(h); 
     1382 matrix g=dual_code(h);
    13831383 ideal sys=qe;
    13841384 print("The system is generated");
    1385  timdec3=timdec3+rtimer-tim3; 
    1386 
    1387  //--- modify the template according to every received word --------------- 
     1385 timdec3=timdec3+rtimer-tim3;
     1386
     1387 //--- modify the template according to every received word ---------------
    13881388 for (j=1; j<=ntrials; j++)
    13891389 {
    1390    word=randomvector(n-redun,1);   
     1390   word=randomvector(n-redun,1);
    13911391   y=encode(transpose(word),g);
    1392    rec=errorRand(y,t,1);   
    1393    sys2=add_synd(rec,h,redun,sys); 
    1394    
     1392   rec=errorRand(y,t,1);
     1393   sys2=add_synd(rec,h,redun,sys);
     1394
    13951395   tim=rtimer;
    1396    sys3=std(sys2);   
    1397    timdec=timdec+rtimer-tim;   
    1398  } 
    1399  timdec2=timdec2+rtimer-tim2; 
    1400  
     1396   sys3=std(sys2);
     1397   timdec=timdec+rtimer-tim;
     1398 }
     1399 timdec2=timdec2+rtimer-tim2;
     1400
    14011401 printf("Time for mindist: %p", timdist);
    14021402 printf("Time for GB in mindist: %p", timdist);
    14031403 printf("Time for decoding: %p", timdec2);
    14041404 printf("Time for GB in decoding: %p", timdec);
    1405  printf("Time for sysQE in decoding: %p", timdec3); 
    1406  
     1405 printf("Time for sysQE in decoding: %p", timdec3);
     1406
    14071407 option(set,vopt);
    1408 } 
    1409 example 
     1408}
     1409example
    14101410{
    14111411     "EXAMPLE:";  echo = 2;
     
    14131413     ring r=(q,a),x,dp;
    14141414     matrix check=randomCheck(redun,n,1);
    1415      
    1416      // correct 2 errors in using the code above, 50 trials 
    1417      decodeCode(check,50,2); 
     1415
     1416     // correct 2 errors in using the code above, 50 trials
     1417     decodeCode(check,50,2);
    14181418}
    14191419
     
    14261426     matrix s[redun][1]=syndrome(check,rec);
    14271427     for (int i=1; i<=redun; i++)
    1428      
    1429      {
    1430           result[i]=result[i]-s[i,1];         
     1428
     1429     {
     1430          result[i]=result[i]-s[i,1];
    14311431     }
    14321432     return(result);
     
    14481448
    14491449///////////////////////////////////////////////////////////////////////////////
    1450 // return index of an element in the ideal where it does not vanish at the 
     1450// return index of an element in the ideal where it does not vanish at the
    14511451//given point
    14521452static proc find_index (ideal G, matrix p)
     
    14881488
    14891489///////////////////////////////////////////////////////////////////////////////
    1490 // check whether given polynomial is divisible by some leading monomial of the 
     1490// check whether given polynomial is divisible by some leading monomial of the
    14911491//ideal
    14921492static proc divisible (poly m, ideal G)
     
    14941494     for (int i=1; i<=size(G); i++)
    14951495     {
    1496           if (m/leadmonom(G[i])!=0) {return(1);}         
     1496          if (m/leadmonom(G[i])!=0) {return(1);}
    14971497     }
    14981498     return(0);
     
    15031503proc vanishId (list points)
    15041504"USAGE:  vanishId (points); point is a list of matrices
    1505         'points' is a list of points for which the vanishing ideal is to be 
    1506         constructed       
     1505        'points' is a list of points for which the vanishing ideal is to be
     1506        constructed
    15071507RETURN:  Vanishing ideal corresponding to the given set of points
    1508 EXAMPLE: example vanishId; shows an example 
     1508EXAMPLE: example vanishId; shows an example
    15091509"
    15101510{
    15111511     int m=size(points[1]);
    15121512     int n=size(points);
    1513      
     1513
    15141514     ideal G=1;
    15151515     int i,k,j;
     
    15191519     //------------- proceed according to Farr-Gao algorithm ----------------
    15201520     for (k=1; k<=n; k++)
    1521      {         
     1521     {
    15221522          i=find_index(G,points[k]);
    1523           cur=G[i];         
     1523          cur=G[i];
    15241524          for(j=i+1; j<=size(G); j++)
    15251525          {
     
    15291529          temp=ideal2list(G);
    15301530          temp=delete(temp,i);
    1531           G=list2ideal(temp);         
     1531          G=list2ideal(temp);
    15321532          for (j=1; j<=m; j++)
    15331533          {
     
    15351535               {
    15361536                    attrib(G,"isSB",1);
    1537                     h=NF((x(j)-points[k][j,1])*cur,G);                   
     1537                    h=NF((x(j)-points[k][j,1])*cur,G);
    15381538                    temp=ideal2list(G);
    15391539                    temp=insert(temp,h);
    15401540                    G=list2ideal(temp);
    1541                     G=sort(G)[1];     
     1541                    G=sort(G)[1];
    15421542               }
    15431543          }
     
    15451545     attrib(G,"isSB",1);
    15461546     return(G);
    1547 } 
    1548 example 
     1547}
     1548example
    15491549{
    15501550     "EXAMPLE:";  echo = 2;
    15511551      ring r=3,(x(1..3)),dp;
    1552      
     1552
    15531553     //generate all 3-vectors over GF(3)
    15541554     list points=pointsGen(3,1);
    1555      
     1555
    15561556     list points2=convPoints(points);
    1557      
     1557
    15581558     //grasps the first 11 points
    15591559     list p=graspList(points2,1,11);
    15601560     print(p);
    1561      
     1561
    15621562     //construct the vanishing ideal
    15631563     ideal id=vanishId(p);
     
    15661566
    15671567///////////////////////////////////////////////////////////////////////////////
    1568 // construct the list of all vectors of length m with elements in p^e, where p 
     1568// construct the list of all vectors of length m with elements in p^e, where p
    15691569//is characteristics
    15701570proc pointsGen (int m, int e)
     
    15881588          count++;
    15891589          for (j=1; j<=charac^(e)-1; j++)
    1590           {               
     1590          {
    15911591               result[count][m]=a^j;
    15921592               count++;
     
    15941594          return(result);
    15951595     }
    1596      list prev=pointsGen(m-1,e);     
     1596     list prev=pointsGen(m-1,e);
    15971597     for (i=1; i<=size(prev); i++)
    15981598     {
     
    16091609     return(result);
    16101610     }
    1611      
     1611
    16121612     if (e==1)
    16131613     {
     
    16161616     int i,j;
    16171617     list l=ringlist(basering);
    1618      int charac=l[1][1];     
     1618     int charac=l[1][1];
    16191619     list tmp;
    16201620     for (i=1; i<=charac^m; i++)
     
    16251625     {
    16261626          for (j=0; j<=charac-1; j++)
    1627           {               
     1627          {
    16281628               result[count][m]=number(j);
    16291629               count++;
     
    16311631          return(result);
    16321632     }
    1633      list prev=pointsGen(m-1,e);     
     1633     list prev=pointsGen(m-1,e);
    16341634     for (i=1; i<=size(prev); i++)
    16351635     {
     
    16431643     return(result);
    16441644     }
    1645      
     1645
    16461646}
    16471647
     
    16881688{
    16891689     poly prod=1;
    1690      list rl=ringlist(basering);     
     1690     list rl=ringlist(basering);
    16911691     int charac=rl[1][1];
    16921692     int l;
     
    17301730"USAGE:    sysFL (check,y,t,e,s); check,y matrix, t,e,s int
    17311731@format
    1732           - check is a check matrix of the code, 
    1733           - y is a received word, 
     1732          - check is a check matrix of the code,
     1733          - y is a received word,
    17341734          - t the number of errors to correct,
    1735           - e is the extension degree, 
     1735          - e is the extension degree,
    17361736          - s is the dimension of the point for the vanishing ideal
    17371737@end format
    17381738RETURN:  the system of Fitzgerald-Lax for the given decoding problem
    1739 THEORY:  Based on 'check' of the given linear code, the procedure constructs 
     1739THEORY:  Based on 'check' of the given linear code, the procedure constructs
    17401740         the corresponding ideal constructed with a generalization of
    17411741         Cooper's philosophy. For basics of the method @ref{Fitzgerald-Lax method}.
     
    17441744"
    17451745{
    1746      list rl=ringlist(basering);       
    1747      int charac=rl[1][1];     
     1746     list rl=ringlist(basering);
     1747     int charac=rl[1][1];
    17481748     int n=ncols(check);
    1749      int m=nrows(check);         
     1749     int m=nrows(check);
    17501750     list points=pointsGen(s,e);
    17511751     list points2=convPoints(points);
    1752      list p=graspList(points2,1,n);     
    1753      ideal id=vanishId(p,e);     
    1754      ideal funcs=gener_funcs(check,p,e,id,s);         
    1755      
     1752     list p=graspList(points2,1,n);
     1753     ideal id=vanishId(p,e);
     1754     ideal funcs=gener_funcs(check,p,e,id,s);
     1755
    17561756     ideal result;
    17571757     poly temp;
    17581758     int i,j,k;
    1759      
     1759
    17601760     //--------------- add vanishing realtions ---------------------
    17611761     for (i=1; i<=t; i++)
    1762      {         
     1762     {
    17631763          for (j=1; j<=size(id); j++)
    17641764          {
    1765                temp=id[j];               
     1765               temp=id[j];
    17661766               for (k=1; k<=s; k++)
    17671767               {
    17681768                    temp=subst(temp,x(k),x_var(i,k,s));
    1769                }               
     1769               }
    17701770               result=result,temp;
    17711771          }
    1772      }         
    1773      
     1772     }
     1773
    17741774     //--------------- add field equations --------------------
    17751775     for (i=1; i<=t; i++)
     
    17841784          result=result,e(i)^(charac^e-1)-1;
    17851785     }
    1786      
     1786
    17871787     result=simplify(result,8);
    1788      
     1788
    17891789     //--------------- add check realtions --------------------
    17901790     poly sum;
    1791      matrix syn[m][1]=syndrome(check,y);         
     1791     matrix syn[m][1]=syndrome(check,y);
    17921792     for (i=1; i<=size(funcs); i++)
    1793      {         
     1793     {
    17941794          sum=0;
    17951795          for (j=1; j<=t; j++)
     
    18001800                    temp=subst(temp,x(k),x_var(j,k,s));
    18011801               }
    1802                sum=sum+temp*e(j);         
     1802               sum=sum+temp*e(j);
    18031803          }
    18041804          result=result,sum-syn[i,1];
    18051805     }
    1806      
     1806
    18071807     result=simplify(result,2);
    1808      
     1808
    18091809     points=points2;
    1810      export points;     
     1810     export points;
    18111811     return(result);
    1812 } 
     1812}
    18131813example
    18141814{
    18151815     "EXAMPLE:";  echo = 2;
    18161816     intvec vopt = option(get);
    1817      
     1817
    18181818     list l=FLpreprocess(3,1,11,2,"");
    18191819     def r=l[1];
    18201820     setring r;
    1821      int s_work=l[2];     
    1822      
     1821     int s_work=l[2];
     1822
    18231823     //the check matrix of [11,6,5] ternary code
    18241824     matrix h[5][11]=1,0,0,0,0,1,1,1,-1,-1,0,
     
    18331833     matrix rec[1][11]=errorInsert(y,list(2,4),list(1,-1));
    18341834
    1835      //the Fitzgerald-Lax system     
     1835     //the Fitzgerald-Lax system
    18361836     ideal sys=sysFL(h,rec,2,1,s_work);
    18371837     print(sys);
    18381838     option(redSB);
    18391839     ideal red_sys=std(sys);
    1840      red_sys; 
     1840     red_sys;
    18411841     // read the solutions from this redGB
    18421842     // the points are (0,0,1) and (0,1,0) with error values 1 and -1 resp.
    18431843     // use list points to find error positions;
    18441844     points;
    1845      
     1845
    18461846     option(set,vopt);
    18471847}
     
    18561856     {
    18571857          s++;
    1858      }     
     1858     }
    18591859     list var_ord;
    18601860     int i,j;
     
    18741874               count++;
    18751875          }
    1876      }     
    1877      
     1876     }
     1877
    18781878     list rl;
    18791879     list tmp;
    1880      
     1880
    18811881     if (e>1)
    18821882     {
     
    18861886          rl[1][2][1]=string("a");
    18871887          rl[1][3]=tmp;
    1888           rl[1][3][1]=tmp;         
     1888          rl[1][3][1]=tmp;
    18891889          rl[1][3][1][1]=string("lp");
    18901890          rl[1][3][1][2]=1;
     
    18931893          rl[1]=p;
    18941894     }
    1895      
     1895
    18961896     rl[2]=var_ord;
    1897      
     1897
    18981898     rl[3]=tmp;
    1899      rl[3][1]=tmp;     
     1899     rl[3][1]=tmp;
    19001900     rl[3][1][1]=string("lp");
    19011901     intvec v=1;
     
    19041904          v=v,1;
    19051905     }
    1906      rl[3][1][2]=v; 
     1906     rl[3][1][2]=v;
    19071907     rl[3][2]=tmp;
    1908      rl[3][2][1]=string("C");   
     1908     rl[3][2][1]=string("C");
    19091909     rl[3][2][2]=intvec(0);
    1910      
    1911      rl[4]=ideal(0);     
    1912      
     1910
     1911     rl[4]=ideal(0);
     1912
    19131913     def r2=ring(rl);
    19141914     setring r2;
    1915      list l=ringlist(r2);     
     1915     list l=ringlist(r2);
    19161916     if (e>1)
    19171917     {
    1918           execute(string("poly f="+minp));     
    1919           ideal id=f;     
     1918          execute(string("poly f="+minp));
     1919          ideal id=f;
    19201920          l[1][4]=id;
    19211921     }
    1922      
     1922
    19231923     def r=ring(l);
    1924      setring r;     
    1925      
     1924     setring r;
     1925
    19261926     return(list(r,s));
    19271927}
     
    19301930// imitating two indeces
    19311931static proc x_var (int i, int j, int s)
    1932 {     
     1932{
    19331933     return(x1(s*(i-1)+j));
    19341934}
     
    19371937// random vector of length n with entries from p^e, p the characteristic
    19381938static proc randomvector(int n, int e)
    1939 {     
     1939{
    19401940    int i;
    19411941    matrix result[n][1];
     
    19441944        result[i,1]=asElement(random_prime_vector(e));
    19451945    }
    1946     return(result);       
    1947 }
    1948 
    1949 ///////////////////////////////////////////////////////////////////////////////
    1950 // "convert" representation of an element from the field extension from vector 
     1946    return(result);
     1947}
     1948
     1949///////////////////////////////////////////////////////////////////////////////
     1950// "convert" representation of an element from the field extension from vector
    19511951//to an elelemnt
    19521952static proc asElement(list l)
     
    19551955  int i;
    19561956  number w=1;
    1957   if (size(l)>1) {w=par(1);} 
     1957  if (size(l)>1) {w=par(1);}
    19581958  for (i=0; i<=size(l)-1; i++)
    19591959  {
     
    19661966// random vector of length n with entries from p, p the characteristic
    19671967static proc random_prime_vector (int n)
    1968 { 
     1968{
    19691969  list rl=ringlist(basering);
    19701970  int i, charac;
     
    19721972  {
    19731973    if (rl[1][1] mod i ==0)
    1974     {     
     1974    {
    19751975      break;
    19761976    }
    19771977  }
    1978   charac=i; 
    1979  
     1978  charac=i;
     1979
    19801980  list l;
    1981  
     1981
    19821982  for (i=1; i<=n; i++)
    19831983  {
     
    19901990
    19911991proc decodeRandomFL(int n, int redun, int p, int e, int t, int ncodes, int ntrials, string minpol)
    1992 "USAGE:    decodeRandomFL(redun,p,e,n,t,ncodes,ntrials,minpol); 
     1992"USAGE:    decodeRandomFL(redun,p,e,n,t,ncodes,ntrials,minpol);
    19931993@format
    1994           - n is length of codes generated, redun = redundancy of codes 
    1995           generated, 
    1996           - p is characteristics, 
    1997           - e is the extension degree, 
    1998           - t is the number of errors to correct, 
     1994          - n is length of codes generated, redun = redundancy of codes
     1995          generated,
     1996          - p is characteristics,
     1997          - e is the extension degree,
     1998          - t is the number of errors to correct,
    19991999          - ncodes is the number of random codes to be processed,
    20002000          - ntrials is the number of received vectors per code to be corrected,
    2001           - minpol: due to some pecularities of SINGULAR one needs to provide 
     2001          - minpol: due to some pecularities of SINGULAR one needs to provide
    20022002          minimal polynomial for the extension explicitly
    20032003@end format
     
    20082008 intvec vopt = option(get);
    20092009
    2010  list l=FLpreprocess(p,e,n,t,minpol); 
    2011  
     2010 list l=FLpreprocess(p,e,n,t,minpol);
     2011
    20122012 def r=l[1];
    2013  int s_work=l[2]; 
     2013 int s_work=l[2];
    20142014 export(s_work);
    20152015 setring r;
    2016  
     2016
    20172017 int i,j;
    20182018 matrix h, g, word, y, rec;
    20192019 int dist, tim, tim2, tim3, timdist, timdec, timdist2, timdec2, timdec3;
    20202020 ideal sys, sys2, sys3;
    2021  list tmp; 
    2022 
    2023  option(redSB); 
    2024  matrix z[1][n]; 
    2025  
     2021 list tmp;
     2022
     2023 option(redSB);
     2024 matrix z[1][n];
     2025
    20262026 for (i=1; i<=ncodes; i++)
    20272027 {
    2028      h=randomCheck(redun,n,e);           
     2028     h=randomCheck(redun,n,e);
    20292029     g=dual_code(h);
    2030      tim2=rtimer;       
     2030     tim2=rtimer;
    20312031     tim3=rtimer;
    20322032
    2033      //---------------- generate the template system ----------------------- 
    2034      sys=sysFL(h,z,t,e,s_work);     
     2033     //---------------- generate the template system -----------------------
     2034     sys=sysFL(h,z,t,e,s_work);
    20352035     timdec3=timdec3+rtimer-tim3;
    2036    
     2036
    20372037     //------ modifying the template according to the received word ---------
    20382038     for (j=1; j<=ntrials; j++)
     
    20412041          y=encode(transpose(word),g);
    20422042          rec=errorRand(y,t,e);
    2043           sys2=LF_add_synd(rec,h,sys);   
     2043          sys2=LF_add_synd(rec,h,sys);
    20442044          tim=rtimer;
    20452045          sys3=std(sys2);
    20462046          timdec=timdec+rtimer-tim;
    2047      }           
     2047     }
    20482048     timdec2=timdec2+rtimer-tim2;
    2049  } 
    2050  
     2049 }
     2050
    20512051 printf("Time for decoding: %p", timdec2);
    20522052 printf("Time for GB in decoding: %p", timdec);
    2053  printf("Time for generating Fitzgerald-Lax system during decoding: %p", timdec3); 
    2054  
     2053 printf("Time for generating Fitzgerald-Lax system during decoding: %p", timdec3);
     2054
    20552055 option(set,vopt);
    2056 } 
     2056}
    20572057example
    20582058{
    20592059     "EXAMPLE:";  echo = 2;
    2060      
    2061      // correcting one error for one random binary code of length 25, 
     2060
     2061     // correcting one error for one random binary code of length 25,
    20622062     //redundancy 14; 300 words are processed
    20632063     decodeRandomFL(25,14,2,1,1,1,300,"");
     
    20842084
    20852085"EXAMPLE:";  echo = 2;
    2086 int q=128; int n=120; int redun=n-30; 
     2086int q=128; int n=120; int redun=n-30;
    20872087ring r=(q,a),x,dp;
    20882088decodeRandom(n,redun,1,1,6);
    20892089
    2090 int q=128; int n=120; int redun=n-20; 
     2090int q=128; int n=120; int redun=n-20;
    20912091ring r=(q,a),x,dp;
    20922092decodeRandom(n,redun,1,1,9);
     
    21062106
    21072107"EXAMPLE:";  echo = 2;
    2108 int q=128; int n=120; int redun=n-40; 
     2108int q=128; int n=120; int redun=n-40;
    21092109ring r=(q,a),x,dp;
    21102110decodeRandom(n,redun,1,1,6);
     
    21192119decodeRandom(n,redun,1,1,24);
    21202120
    2121 int q=256; int n=150; int redun=n-10; 
     2121int q=256; int n=150; int redun=n-10;
    21222122ring r=(q,a),x,dp;
    21232123decodeRandom(n,redun,1,1,26);
     
    21562156setring A;
    21572157print(qe);
    2158 ideal red_qe=stdfglm(qe); 
     2158ideal red_qe=stdfglm(qe);
    21592159
    21602160*/
Note: See TracChangeset for help on using the changeset viewer.