#George Spahn #2/25/2024 #OK TO POST #Alphabet {0,1,...q-1}, Fqn(q,n): {0,1,...,q-1}^n Fqn:=proc(q,n) local S,a,v: option remember: if n=0 then RETURN({[]}): fi: S:=Fqn(q,n-1): {seq(seq([op(v),a],a=0..q-1), v in S)}: end: #TRA(M): inputs a matrix M as a list of lists outputs the transpose matrix #also as a list of lists TRA:=proc(M) local i,j:[seq([seq(M[j][i],j=1..nops(M))],i=1..nops(M[1]))]:end: isg := proc(v) local i: for i in v do if i = 1 then return(true): fi: if i > 1 then return(false): fi: od: end: Hampcm := proc(r,q) local M,N,i: M:=Fqn(q,r) minus {[0$r], seq([0$(i-1),1,0$(r-i)],i=1..r)}: N:=[]: for i in M do if isg(i) then N:=[op(N),i]: fi: od: TRA([op(N),seq([0$(i-1),1,0$(r-i)],i=1..r)]): end: Ham := proc(r,q) antiPCM(q,Hampcm(r,q)): end: #start code by Pablo Blanco # input q, the modulus and a parity check matrix H in standard form. H:= [-A^T | I_{n-k}] has k rows and n columns. # outputs M, the corresponding generating matrix. M := [ I_k | A] has n-k rows and n columns. A has k rows and n-k columns. antiPCM:=proc(q,H) local A,B,M,n,rows,k,co,tempCol: rows:=nops(H): # this is n-k n:=nops(H[1]): # number of H columns k:= n-rows: B:=extractMCols(1,k,H): # this is -A^T, we wish to return [I_k | A]. tempCol := extractMCols(1,1,B): # take the first column, negate it A:= [[seq(op(tempCol[k]), k=1..nops(tempCol))]]: # make the first column into a row for co from 2 to k do: tempCol := extractMCols(co,co,B): # take the (co)-th column A:= [op(A), [seq(op(tempCol[k]), k=1..nops(tempCol))]]: # add the co-th column as a row od: A:= -A mod q: # we took the transpose, now we negate. co:=1: M:=A: for co from 1 to k do: #we will append the identity matrix row by row M[co] := [0$(co-1), 1, 0$(k-co),op(A[co])]: od: M: end: # a few helper functions: # extracts rows i through j of matrix M, returns a matrix with those rows extractMRows := proc(i,j,M) local colN,k: colN:=nops(M[1]): # number of columns of M [seq(M[k][1..colN] ,k=i..j)] end: # extracts columns i through j of matrix M, returns a matrix with those columns extractMCols := proc(i,j,M) local rowN,k: rowN:= nops(M): # number of rows of M [seq( M[k][i..j] , k=1..rowN)]: end: # DecodeLT(q,M). DecodeLT := proc(q,M) local T,n,V,S,v,syn,H: option remember: n:=nops(M[1]): T:= SynT(q,M)[1]: V:= Fqn(q,n): S:=table(): H:=PCM(q,M): for v in V do: syn:= Syn(q,H,v): S[v]:= v-T[syn] mod q: od: op(S): end: #End code by Pablo Blanco