//First a couple of preliminary functions /*Gives the dimension of the p-ary code of the affine geometry design of points and t-dimensional flats in AG_d(p)*/ grm:=func; //Input p=prime,t and d pgrm:=func; AGrank:=function(m,r,p,t); /*Want rank_p(AG_{m,rr}(F_q)) where q=p^t*/ if t eq 1 then return grm(m,r,p); else q := p^t; n := (q^m)-1; np := n div (q-1); "q = ", q; wts := [qwt(u,q) : u in [1..n]]; rr:=r; k := ( m-rr)*(q-1); we:=&meet[ {i : i in [1..q^m -2] |wts[(p^j)*i mod n] le k }: j in [0..t-1]]; print "dim(R_F_q/F_p(",k,",",m,")=", #(we)+1; print "=", p, "-rank of AG_{", m, ",", rr, "}(F_", q, ")"; return #(we)+1; end if; end function; PGrank:=function(m,r,p,t); /*Want Rank_p(PG_{m,r}(F_q)) where q=p^t*/ if t eq 1 then return pgrm(m,r,p); else m:=m+1;rr:=r+1; q := p^t; n := (q^m)-1; np := n div (q-1); wts := [qwt(u,q) : u in [1..n]]; k := ( m-rr)*(q-1); we:=&meet[ {i : i in [1..q^m -2] |wts[(p^j)*i mod n] le k }: j in [0..t-1]]; wee:={ i: i in we | (i mod (q-1)) eq 0}; "dim(R_F_q/F_p^(q-1)(",k,",",m,")=", #(wee)+1; print "=", p, "-rank of PG_{", m-1, ",", rr-1, "}(F_", q, ")"; end if; return #wee+1; end function;