###################################################################### ## EM19Proj2.txt Save this file as EM19Proj2.txt to use it, # # stay in the # ## same directory, get into Maple (by typing: maple ) # ## and then type: read EM19Proj2.txt: # ## Then follow the instructions given there # ## # ## Written by students of Dr. Z.'s Math 640 , Spring 2019, class # ## Coordinated by Yonah Biers-Ariel, yb165@math.rutges.edu # ###################################################################### read `EV3.txt`: read `EV4.txt`: read `EV5.txt`: read `EV6.txt`: read `EV7.txt`: read `EV8.txt`: Help:=proc() if args=NULL then print(` EM19Proj2.txt: A Maple package for creating Word Rectangles and Squares`): print(`The MAIN procedures are: ALLSQ, ALLSQc, CO , CP1, FT, INID, SCORE, STAB, TRA, RANCON, RANCON1, TRM `): print(` `): elif nargs=1 and args[1]=ALLSQ then print(`ALLSQ(VOC): all the Word squares of size K. Try:`): print(`ALLSQ([op(1..100,ENGLISH3)]); `): elif nargs=1 and args[1]=ALLSQc then print(`ALLSQc(VOC,L): all the continuations of L. Try`): print(`ALLSQc([[d,o,r,o,n],op(ENGLISH5)],[[d,o,r,o,n]]);`): elif nargs=1 and args[1]=CO then print(`CO(A): the code table of the alphabet A`): print(`Try: `): print(`CO(ALPH)`): elif nargs=1 and args[1]=CP1 then print(`CP1(VOC,L): inputs a vocabulary VOC of words of the same length and a list of words that is promising`): print(`finds the set of promising extensions. Try:`): print(`CP1(ENGLISH3,[[a,p,e]]);`): elif nargs=1 and args[1]=FT then print(`FT(VOC,A): inputs a vocabulary list VOC (a list of lists) and an alphabet A`): print(`( a list of letters) and outputs the frequenncy table of ALL letters that show up`): print(`Try: `): print(`FT(ENGLISH3,ALPH); `): elif nargs=1 and args[1]=INID then print(`INID(VOC,A): the probability of the distribution of first letters of the vocabulary VOC and alphabet A. Try`): print(`INID(ENGLISH3,ALPH); `): elif nargs=1 and args[1]=MakePuz then print(`MakePuz(VOC,L,K1): makes a set of random word squares using the words in VOC, starting with L. Try:`): print(`by trying K1 times. Try:`): print(`MakePuz([[y,o,n,a,h],op(ENGLISH5)],[[y,o,n,a,h]],10); `): elif nargs=1 and args[1]=RANCON then print(`RANCON(VOC,L): a random contiuation of L until it gets stuck or finishes`): print(`Try: `): print(`RANCON([[y,o,n,a,h],op(ENGLISH5)],[[y,o,n,a,h]]); `): elif nargs=1 and args[1]=RANCON1 then print(`RANCON1(VOC,L): a random ONE contiuation of L`): print(`Try: `): print(`RANCON1([[y,o,n,a,h],op(ENGLISH5)],[[y,o,n,a,h]]); `): elif nargs=1 and args[1]=SCORE then print(`SCORE(W,VOC,A): the score of the word W in the voculbulary A and alphabet A. Try:`): print(`SCORE([d,a,d],ENGLISH3,ALPH);`): elif nargs=1 and args[1]=STAB then print(`STAB(VOC,R): The starting table of the vocubulary list VOC of length R, returns the set of prefixes followed by the table`): print(`Try: `): print(`STAB(ENGLISH3,2);`): elif nargs=1 and args[1]=TRA then print(`TRA(L): the transpose of L. Try:`): print(`TRA([[d,a,d]]);`): elif nargs=1 and args[1]=TRM then print(`TRM(VOC,A,I1,J1): inputs a vocabulary set VOC, an alphabet A, and pos. integers I1, J1`): print(`outuputs the nops(A) by nops(A) matrix whose i,j entry is conditional probability`): print(`Letter[J1]=j|Letter[I1]=i`): print(`Try:`): print(`TRM(ENGLISH3,ALPH,2,1);`): else print(`There is no such thing as`, args): fi: end: #CO(ALPH): the code table of the alphabet ALPH #Added after class, May 1, 2019 CO:=proc(ALPH) local T1,I1: for I1 from 1 to nops(ALPH) do T1[ALPH[I1]]:=I1: od: op(T1): end: #FT(VOC,A): inputs a vocabulary list VOC (a list of lists) and an alphabet A #( a list of letters) and outputs the frequenncy table of ALL letters that show up #Try: #FT(ENGLISH3,ALPH); FT:=proc(VOC,A) local VOC1,X,I1,J: VOC1:=ListTools[Flatten](VOC): J:=add(X[VOC1[I1]],I1=1..nops(VOC1)): J:=[seq(coeff(J,X[A[I1]],1),I1=1..nops(A))]: J/convert(J,`+`): end: #TRM(VOC,A,I1,J1): inputs a vocabulary set VOC, an alphabet A, and pos. integers I1, J1 #outuputs the nops(A) by nops(A) matrix whose i,j entry is conditional probabity #Letter[J1]=j|Letter[I1]=i #Try: #TRM(ENGLISH3,ALPH,2,1); #corrected May 1, 2019 to avoid division by 0 TRM:=proc(VOC,A,I1,J1) local T1,T2,K1,K2,LIS: option remember: for K1 from 1 to nops(A) do T1[A[K1]]:=0: od: for K1 from 1 to nops(A) do for K2 from 1 to nops(A) do T2[A[K1],A[K2]]:=0: od: od: for K1 from 1 to nops(VOC) do T1[VOC[K1][I1]]:= T1[VOC[K1][I1]]+1: T2[VOC[K1][I1],VOC[K1][J1]]:= T2[VOC[K1][I1],VOC[K1][J1]]+1: od: LIS:=[]: for K1 from 1 to nops(A) do if T1[A[K1]]=0 then LIS:=[op(LIS),[(1/nops(A))$nops(A)]]: else LIS:=[op(LIS),[seq( T2[A[K1],A[K2] ]/T1[A[K1]],K2=1..nops(A) )] ]: fi: od: LIS: end: #Added after class #INID(VOC,A): the probability of the distribution of first letters of the vocabulary VOC and alphabet A INID:=proc(VOC,A) local I1,F,X: F:=add(X[ VOC[I1][1] ], I1=1..nops(VOC)): F:=[seq(coeff(F,X[A[I1]],1),I1=1..nops(A))]: \ F/convert(F,`+`): end: #MakeWS(VOC1,VOC2): creates a random K1 by K2 matrix each of whose rows #belongs to VOC1 and each of whose columns belongs to VOC2 #K1=nops(VOC1[1]), K2=nops(VOC2[1]): #belong to VOC #MakeWS:=proc(VOC1,VOC2) local K1,K2: #print(`To be continued in homework `): #end: #SCORE(W,VOC,A): the score of the word W in the voculbulary A and alphabet A. Try: #SCORE([d,a,d],ENGLISH3,ALPH); SCORE:=proc(W,VOC,A) local T1,I1: T1:=CO(A): INID(VOC,A)[T1[W[1]]]*mul(TRM(VOC,A,I1,I1+1)[T1[W[I1]] ] [ T1[W[I1+1]] ],I1=1..nops(W)-1): end: Help26:=proc(): print(` STAB(VOC,R) , TRA(L), CP1(VOC,L), ALLSQ(VOC,K), ALLSQc(VOC,L), RANCON1(VOC1,L), RANCON(VOC1,L) , MakePuz(VOC,L,K1)`): end: #STAB(VOC,R): The starting table of the vocubulary list VOC of length R, returns the set of prefixes followed by the table STAB:=proc(VOC,R) local S,S1,I1,T,W1: option remember: S:={seq([op(1..R,VOC[I1])],I1=1..nops(VOC))}: for S1 in S do T[S1]:={}: od: for I1 from 1 to nops(VOC) do W1:=VOC[I1]: T[[op(1..R,W1)]]:= T[[op(1..R,W1)]] union {W1}: od: S,op(T): end: #TRA(L): the transpose of L. Try: #TRA([[d,a,d]]); TRA:=proc(L) local I1,J1: [seq([seq(L[J1][I1],J1=1..nops(L))],I1=1..nops(L[1]))]: end: #CP1(VOC,L): inputs a vocabulary VOC of words of the same length and a list of words that is promising #finds the set of promising extensions. Try #CP1(ENGLISH3,[[a,p,e]]); CP1:=proc(VOC,L) local I1,M1,L1,ST,CHILD,M: if convert(L,set) minus convert(VOC,set)<>{} then RETURN(FAIL): fi: if L=[] then RETURN({seq([VOC[I1]],I1=1..nops(VOC))}): fi: L1:=TRA(L): ST:=STAB(VOC,nops(L))[1]: if convert(L1,set) minus ST<>{} then RETURN({}): fi: ST:=STAB(VOC,nops(L)+1)[1]: CHILD:={}: for I1 from 1 to nops(VOC) do M:=[op(L),VOC[I1]]: M1:=TRA(M): if convert(M1,set) minus ST={} then CHILD:=CHILD union {M}: fi: od: CHILD: end: #ALLSQ(VOC): all the Word squares of the vocabulary VOC. Try: #AllSQ([op(1..100,ENGLISH3)]); ALLSQ:=proc(VOC) local K,S,I1,N1: K:=nops(VOC[1]): S:={seq([VOC[I1]],I1=1..nops(VOC))}: for N1 from 2 to K do S:={seq(op(CP1(VOC,S[I1])),I1=1..nops(S))}: od: S: end: #ALLSQc(VOC,L): all the continuations of L ALLSQc:=proc(VOC,L) local K,N1,I1,S: K:=nops(L[1]): S:={L}: for N1 from nops(L)+1 to K do S:={seq(op(CP1(VOC,S[I1])),I1=1..nops(S))}: od: S: end: #RANCON1(VOC,L): a random contiuation of L RANCON1:=proc(VOC,L) local NEW1: NEW1:=CP1(VOC,L): if NEW1={} or NEW1=FAIL then RETURN(FAIL): fi: NEW1[rand(1..nops(NEW1))()]: end: RANCON:=proc(VOC,L) local K,L1,L2: K:=nops(VOC[1]): L1:=L: while L1<>FAIL and nops(L1)