#OK to post homework #GLORIA LIU, Jan 18 2024, Assignment 1 #=====================================# #1. Read and do all the examples, plus make up similar ones, in the first 30 pages of Frank Garvan's awesome Maple booklet. Only record a small sample in hw1YourName.txt. #Chapter 1 105/25; F:=%; G:=-1/5; F+G; #Chapter 2 7 - 11/15; 20^12; sin(Pi/10); evalf(%, 15); evalf(tan(sqrt(1/2))); convert(%,rational); #Chapter 3 P := x^2 + x + 6; factor(P); P := x^2 + 5*x + 6; subs(x=1,p); factor(P); sqrt(x+2)*sqrt(x+3); expand(%); combine(%); #(x + y + 1)*(x - y + 1)*(x - y - 1); #p := expand(%); #collect(p, x); y:=((x-2)^2)^(1/2): assume(x>2); simplify(y); x:='x': y:='y': z:='z': radsimp(((1+x)^(-1/2))^2); P := (x+y-1)*(x+2*y)*(y-x): simplify(expand(P)); coeff(expand(%),x,2); x:='x': a:='a': solve({x^3+a*x=14,a^2-x=7},{a,x}): %[1]; assign(%); a;x; poly1 := Z^5+3*Z^4-12*Z^3-35*Z^2+42+Z+119=0; polyeqn := Z^6+Z^4-15*Z^3+35*Z^2+42*Z+911=0; fsolve(polyeqn, Z); fsolve(poly1, Z); #assign(%); cannot assign solutions in this way ithprime(1000000); x:='x': a:='a': y:='y': z:='z': #=====================================# #2. Done #=====================================# #3. Generalize procedure CC(P,k) call it CCg(P,A,k) that inputs an arbitrary "alphabet" (e.g. [0,1,...,9], [C,A,G,T]) given as a list and encodes it. #CCg(P,[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],k)should give the same output as CC(P,k). In addition it should check that all the members of the plaintext, P, belong to A, and return FAIL if it doesn't. #CCg(P,A,k) implements the Caeser code for a general alphabet. #Inputs a message, and a list of all possible characters, and an integer k, outputs the encrypted message. #For example #CCg([d,o,r,o,n], [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], 2); should output [f,q,t,q,p] #If there are members of P that do not belong to A, return FAIL CCg:=proc(P,A,k1) local T,i1: for i1 from 1 to nops(A) do T[A[i1]]:=A[(i1+k1-1 mod nops(A))+1]: od: # Check if all members of P belong to A for i1 from 1 to nops(P) do if not(member(P[i1], A)) then return FAIL end if; od: [seq(T[P[i1]],i1=1..nops(P))]: end: #=====================================# #4. Creates the lists T[i,j] (3 ≤ i ≤ 10, 1 ≤ j ≤ i) each of length 26, where T[i,j][i1] is the frequency of the i1-th letter of the English alphabet in the j-th place of an i-letter word. Also create s list, call it, F of the total frequency (only using from 3-letter words to 10-letter words) in the whole text. Can you find any differences? read `ENGLISH.txt`: with(StringTools): A3 := Array(1..3, 1..26, []): A4 := Array(1..4, 1..26, []): A5 := Array(1..5, 1..26, []): A6 := Array(1..6, 1..26, []): A7 := Array(1..7, 1..26, []): A8 := Array(1..8, 1..26, []): A9 := Array(1..9, 1..26, []): A10 := Array(1..10, 1..26, []): F := [0 $ 26]: for i1 from 1 to nops(ENG()[3]) do for j1 from 1 to 3 do letter := ENG()[3][i1][j1]: #97 is the ascii of lowercase a A3[j1, Ord(letter) - 96] := A3[j1, Ord(letter) - 96] + 1: F[Ord(letter) - 96] := F[Ord(letter) - 96] + 1: od: od: A3; for i1 from 1 to nops(ENG()[4]) do for j1 from 1 to 4 do letter := ENG()[4][i1][j1]: A4[j1, Ord(letter) - 96] := A4[j1, Ord(letter) - 96] + 1: F[Ord(letter) - 96] := F[Ord(letter) - 96] + 1: od: od: A4; for i1 from 1 to nops(ENG()[5]) do for j1 from 1 to 5 do letter := ENG()[5][i1][j1]: A5[j1, Ord(letter) - 96] := A5[j1, Ord(letter) - 96] + 1: F[Ord(letter) - 96] := F[Ord(letter) - 96] + 1: od: od: A5; for i1 from 1 to nops(ENG()[6]) do for j1 from 1 to 6 do letter := ENG()[6][i1][j1]: A6[j1, Ord(letter) - 96] := A6[j1, Ord(letter) - 96] + 1: F[Ord(letter) - 96] := F[Ord(letter) - 96] + 1: od: od: A6; for i1 from 1 to nops(ENG()[7]) do for j1 from 1 to 7 do letter := ENG()[7][i1][j1]: A7[j1, Ord(letter) - 96] := A7[j1, Ord(letter) - 96] + 1: F[Ord(letter) - 96] := F[Ord(letter) - 96] + 1: od: od: A7; for i1 from 1 to nops(ENG()[8]) do for j1 from 1 to 8 do letter := ENG()[8][i1][j1]: A8[j1, Ord(letter) - 96] := A8[j1, Ord(letter) - 96] + 1: F[Ord(letter) - 96] := F[Ord(letter) - 96] + 1: od: od: A8; for i1 from 1 to nops(ENG()[9]) do for j1 from 1 to 9 do letter := ENG()[9][i1][j1]: A9[j1, Ord(letter) - 96] := A9[j1, Ord(letter) - 96] + 1: F[Ord(letter) - 96] := F[Ord(letter) - 96] + 1: od: od: A9; for i1 from 1 to nops(ENG()[10]) do for j1 from 1 to 10 do letter := ENG()[10][i1][j1]: A10[j1, Ord(letter) - 96] := A10[j1, Ord(letter) - 96] + 1: F[Ord(letter) - 96] := F[Ord(letter) - 96] + 1: od: od: A10; #Convert array to list, so that T_i[j, i1] represents the amount of times that the i1'th letter in the alphabet appears in the j'th spot of i letter words. T3 = convert(A3, list, nested): T4 = convert(A4, list, nested): T5 = convert(A5, list, nested): T6 = convert(A6, list, nested): T7 = convert(A7, list, nested): T8 = convert(A8, list, nested): T9 = convert(A9, list, nested): T10 = convert(A10, list, nested): F;