Isaac Lam, HW26, April 27st 2024 #C26.txt, April 22, 2024 Help:=proc(): print(` FT(SetL), TM(SetL) `):end: read `ENGLISH.txt`: #FT(SetL): The frequency table of all words whose length belobgs to SetL #For example FT({3,4}) returns the randked frequency table for words of #length 3 and 4 FT:=proc(SetL) local ALPH,T1,W,DB,C,B,FL,L,A,FL1,S1: ALPH:=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]: DB:=ENG(): C:=0: for L in ALPH do T1[L]:=0: od: for A in SetL do for W in DB[A] do for B from 1 to nops(W) do T1[W[B]]:=T1[W[B]]+1: C:=C+1: od: od: od: FL:=evalf([seq(T1[ALPH[A]]/C,A=1..nops(ALPH))]): FL1:=sort(FL,`>`): for A from 1 to nops(ALPH) do S1[FL[A]]:=ALPH[A]: od: FL1,[seq(S1[FL1[A] ],A=1..nops(ALPH))], [seq([FL1[A],S1[FL1[A]] ],A=1..nops(ALPH))] : end: #TM(SetL): The frequency table of all words whose length belobgs to SetL #For example FT({3,4}) returns the randked frequency table for words of #length 3 and 4 #AND the Transiton matrix 28x28 the first "letter" is ST and the last is EN #NOT YET FINISHED TM:=proc(SetL) local ALPH,T1,W,DB,C,B,FL,L,A,FL1,S1,T2,L1,L2,ST,EN,T3,ALPH1: print(`Not yet finished`): ALPH:=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]: DB:=ENG(): C:=0: for L in ALPH do T1[L]:=0: od: for L1 from 1 to nops(ALPH) do T2[ST,ALPH[L1]]:=0: T2[ALPH[L1],EN]:=0: for L2 from 1 to nops(ALPH) do T2[ALPH[L1],ALPH[L2]]:=0: od: od: for A in SetL do for W in DB[A] do for B from 1 to nops(W) do T1[W[B]]:=T1[W[B]]+1: C:=C+1: if B`): for A from 1 to nops(ALPH) do S1[FL[A]]:=ALPH[A]: od: for L1 from 1 to nops(ALPH) do T3[ST,ALPH[L1]]:=evalf(T2[ST,ALPH[L1]]/C): T3[ALPH[L1],EN]:=evalf(T2[ALPH[L1],EN]/C): od: for L1 from 1 to nops(ALPH) do for L2 from 1 to nops(ALPH) do T3[ALPH[L1],ALPH[L2]]:=evalf(T2[ALPH[L1],ALPH[L2]]/C): od: od: FL1,[seq(S1[FL1[A] ],A=1..nops(ALPH))], [seq([FL1[A],S1[FL1[A]] ],A=1..nops(ALPH))] , op(T3): end: getPairs:= proc() local pairs, words, i,j,k ,pair: words:=ENG(): pairs:={}: for i from 1 to nops(words) do: for j from 1 to nops(words[i]) do: for k from 1 to nops(words[i][j]) do: if K<>nops(words[i][j]) then pair:=[words[i][j][k], words[i][j][k+1]]: pairs:= pairs union {pair}: end if: end do: end do: end do: return nops(pairs): end: #593 pairs getPairs2:= proc() local alph, pairCounts, words, i,j,k, count: count:=0: words:=ENG(): alph:= [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]: for i from 1 to 26 do for j from 1 to 26 do pairCounts[alph[i],alph[j]] := 0: end do: end do: for i from 1 to nops(words) do: for j from 1 to nops(words[i]) do: for k from 1 to nops(words[i][j]) do: if k<>nops(words[i][j]) then pairCounts[words[i][j][k], words[i][j][k+1]] := pairCounts[words[i][j][k], words[i][j][k+1]] +1: end if: end do: end do: end do: for i from 1 to 26 do for j from 1 to 26 do if pairCounts[alph[i],alph[j]]>10 then count:=count+1: end if: end do: end do: count: end: #497 total TripletCount:=proc() local triples, words, i,j,k , triple: words:=ENG(): triples:={}: for i from 1 to nops(words) do: for j from 1 to nops(words[i]) do: for k from 1 to (nops(words[i][j])-2) do: triple:=[words[i][j][k], words[i][j][k+1], words[i][j][k+2]]: triples:= triples union {triple}: end do: end do: end do: nops(triples): end: #6639 total