//making the  simplex code, S_n, and pdsets  for S_n
//value for n
"n =",n;
Dim:=Dimension;
WD:=WeightDistribution;
PG:=PermutationGroup;
//------------------------------------------------------------------
PDSet:=function(n,r,t);
st:=Ceiling((n-t+1)/(r-t+1));
  for j:=1 to t-1 do
   d:=(n-(t-j)+1)/(r-(t-j)+1);
   nt:=Ceiling(d*st);
   st:=nt;
  end for;
return nt;
end function;
//-----------------------------------------------------------------
//makes the square nxn matrix ma into a permutation on vectors 
mataut:=func<aut,pts,ma|aut![Position(pts,pts[i]*ma):i in [1..#pts]]>;
//inverse to the above
autmat:=func<x,pts,n|Matrix(n,&cat[Eltseq(pts[i^x]):i in [1..n]])>;
//--------------------------------------------------------------
//S is a sequence of I_n and matrices in A_n ,all rows distinct
//pts is a sequence of the non-zero vectors in V_n(GF(2))
//get |S| (n+1)x(n+1) matrices, all rows distinct
extmat:=function(S,n,pts); 
gln:=GL(n,GF(2));gln1:=GL(n+1,GF(2));
f:=GF(2);
z:=[f!0:i in [1..n+1]];z[1]:=f!1;
NS:=[Id(gln1)];
   for i:=2 to #S do
    a:=S[i];
    ela:=&cat[[f!0] cat Eltseq(a[j]):j in [1..n]];
    zj:=z;
     for j:=1 to n do
      zj[j+1]:=pts[i-1][j];
     end for;
    nm:=zj cat ela;
    mi:=gln1!Matrix(n+1,nm);
    NS:=Append(NS,mi);
   end for;
return NS;
end function;
//---------------------------------------------------------------
C:=SimplexCode(n);
G:=GeneratorMatrix(C);GT:=Transpose(G);
pts:=[GT[i]:i in [1..2^n-1]];

[1..Dim(C)] eq InformationSet(C),
"that info set for C is first",n,"positions";
k:=Dim(C);
aut:=PG(C);
"Weight distribution",WD(C);
" C corrects",2^(n-2)-1,"errors";
"GBound for ",2^(n-2)-1,"(full) error correction is",
PDSet(2^n-1,2^n-1-n,2^(n-2)-1);

fn:=Floor((2^n-1)/n)-1;
"f_n=",fn;

gln:=GL(n,GF(2));

an:=[Id(gln)];
rows:=&join[{an[i][j]:j in [1..n]}:i in [1..#an]];
  for x in gln do
    ann:=#an; //counter to show size of an
    if Position(an,x) eq 0 then
     rxs:={x[i]:i in [1..n]};
      if rxs meet rows eq {} then
       an:=Append(an,x); 
       rows:=rows join rxs;
      end if;
     end if;
     if  #an  eq ann +1 then #an;
     end if;
     if #an eq fn+1 then break x;
     end if;
  end for;
ian:=[an[i]^-1:i in [1..#an]];
mian:=[mataut(aut,pts,ian[i]):i in [1..#ian]];
#ian,"=size of set to correct", #ian-1,"errors";
//now use the check program for pdsets .. these are nested.
ian,"the",#ian-1,"-PD-set for S_",n;
ean:=extmat(an,n,pts);
eian:=[ean[i]^-1:i in [1..#ean]];
eian,"the",#ian-1,"-PD-set for S_",n+1;
