#OK to post #GLORIA LIU, Mar 5 2024, Assignment 14 read `C14.txt`: #=====================================# #1. Generalize procedures Encode113(x), RV113(), and Syl113(x), call them #Enocde113G(x,q), Sy113G(x,q), and Decode113G(y,q) #that generalizes the code of Ex. 11.3 from n=10 to general n, and from q=11 to general prime q. #I am going to use my code from the last homework with(LinearAlgebra): Encode113G:=proc(x,q) local n,m,H,H1,K,i,j,t,result: m:=nops(x): n:=nops(x) + 4: H:=[seq([seq(i^j, i=1..n)], j=0..3)]: #print(H); H1:=[seq([seq(H[i][j], j=m+1..n)], i=1..4)]: #print(H1); K:=[seq(-1*add(H[i][j]*x[j],j=1..m) mod q, i=1..4)]: t:=Linsolve(Matrix(H1),Vector(K)) mod q: [op(x), seq(t[i], i=1..4)]: end: Sy113G:=proc(x,q) local i,r: [seq(add(i^(r-1)*x[i],i=1..nops(x)) mod q,r=1..4)]: end: Decode113G:=proc(y,q) local S,eq,i,j,L,i1,a,b: S:=Sy113G(y,q): if S=[0$4] then RETURN(y): fi: eq:=(S[2]^2-S[1]*S[3])*i^2+(S[1]*S[4]-S[2]*S[3])*i+(S[3]^2-S[2]*S[4]) mod q: if eq=0 then i:=S[2]/S[1] mod q: a:=S[1]: RETURN(y-[0$(i-1), a, 0$(nops(y)-i)] mod q): fi: L:=[]: for i1 from 0 to q-1 do if subs(i=i1, eq) mod q=0 then L:=[op(L), i1]: fi: od: i:=L[1]: j:=L[2]: print(L); b:=(i*S[1]-S[2])/(i-j) mod q: a:=S[1]-b mod q: print([a,b]); [[i,a],[j,b]]: print(nops(y)); print([0$(i-1),a,0$(j-i-1),b,0$(nops(y)-j)]); y-[0$(i-1),a,0$(j-i-1),b,0$(nops(y)-j)] mod q: end: #Testing: inputs prime q and m, the length of the message to encode #That means the codeword will have length m+4 #q>m+4 RV113G:=proc(q,m) local v,x,y,x1,x2: v:=RV(q,m): print(v); x:=Encode113G(v,q): print(x); print(Sy113G(x,q)); y:=Decode113G(x,q): print(y): x2:=x+[1,0$(m+3)]: print(Decode113G(x2, q)); x1:=x+[1, 0$(m+2), 1]: print(Decode113G(x1, q)); end: RV113G(11, 6); #=====================================# #2. Read and understand Chapter 11 of the book and Ramanujan's paper #Done