#Isaac Lam, HW#13, March 1 2024 #old code #HD(u,v): The Hamming distance between two words (of the same length) HD:=proc(u,v) local i,co: co:=0: for i from 1 to nops(u) do if u[i]<>v[i] then co:=co+1: fi: od: co: end: #LtoC(q,M): inputs a list of basis vectors for our linear code over GF(q) #outputs all the codewords (the actual subset of GF(q)^n with q^k elements LtoC:=proc(q,M) local n,k,C,c,i,M1: option remember: k:=nops(M): n:=nops(M[1]): if k=1 then RETURN({seq(i*M[1] mod q,i=0..q-1) }): fi: M1:=M[1..k-1]: C:=LtoC(q,M1): {seq(seq(c+i*M[k] mod q,i=0..q-1),c in C)}: end: #MinW(q,M): The minimal weight of the Linear code generated by M over GF(q) MinW:=proc(q,M) local n,C,c: n:=nops(M[1]): C:=LtoC(q,M): min( seq(HD(c,[0$n]), c in C minus {[0$n]} )): end: #start new code for C12.txt: The generator matrix for the cyclic code over R_n (mod x^n-1) CtoL:=proc(n,x,g) local r,L,i: r:=degree(g,x): L:=[seq(coeff(g,x,i),i=0..r)]: [seq([0$i,op(L), 0$(n-r-1-i)],i=0..n-r-1)]: end: with(combinat): #AllFactors(n,q,x): all the factors of x^n-1 mod q (q is a prime) AllFactors:=proc(n,q,x) local S,s: S:=Factor(x^n-1) mod q: S:=powerset({op(S)}) minus {{},{op(S)}}: {seq(expand(convert(s,`*`)) mod q,s in S)}: end: #end of old code CCshopF := proc(N, q, x, K, R, W) local n, C, S, M, g, w; C := {}; for n from 2 to N do S := AllFactors(n, q, x); for g in S do M := CtoL(n, x, g); if q^nops(M) <= K then w := MinW(q, M); if R <= nops(M)/n and W <= w then C := C union {[g, evalf(nops(M)/n), w]}; end if; end if; end do; end do; C; end; #I have to admit I've been looking for a while and can't see how CtoL with a minor change to account for q isn't already a way to implement 12.15` CtoDual:=proc(n,q,x,g) local p,r,L,i: r:=degree(g,x): P:= g mod q: L:=[seq(coeff(p,x,i),I=0..r)]: [seq([0$i,op(L), 0$(n-r-1-i)],i=0..n-r-1)]: end: