{VERSION 2 3 "SUN SPARC UNIX" "2.3" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 258 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Co urier" 1 10 0 0 255 1 0 0 0 0 0 1 3 0 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Warning" 2 7 1 {CSTYLE "" -1 -1 "" 0 1 0 0 255 1 0 0 0 0 0 0 1 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Output" 0 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 11 12 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 256 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 257 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 258 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 259 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 260 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 261 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT -1 79 "1. Write a Maple program that prints the first 10 squares (i.e. 1^2, 2^2, ...)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "for i from 1 to 10 do print (i^2) o d;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"*" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"#;" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#\"#D" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#O" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#\\" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#k" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#\")" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\" $+\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 19 "Or, as a procedure:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 81 "first_squares := proc ()\n \+ local i:\n\n for i from 1 to 10 do print (i^2) od;\nend;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%.first_squaresG:6\"6#%\"iGF&F&?(8$\"\"\"F+\"# 5%%trueG-%&printG6#*$F*\"\"#F&F&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "first_squares ();" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# \"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"*" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#D" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#O " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#\\" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#k" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#\")" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"$+\"" }}}{EXCHG {PARA 257 "" 0 "" {TEXT -1 78 "2. Write a Maple program that tests whether two integers \+ are relatively prime." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 117 "r el_prime := proc (m, n)\n if gcd(m,n)=1 then print (`Relatively prime `) else print (`Not relatively prime`) fi;\nend;" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%*rel_primeG:6$%\"mG%\"nG6\"F)F)@%/-%$gcdG6$9$9%\"\"\" -%&printG6#%1Relatively~primeG-F36#%5Not~relatively~primeGF)F)" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "rel_prime (5,13);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%1Relatively~primeG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "rel_prime (21, 9);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%5Not~relatively~primeG" }}}{EXCHG {PARA 258 "" 0 "" {TEXT -1 115 "3. Write a Maple program that tests whether a number is prime (do n't use Maple's built in prime testing procedure)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 142 "prime_test := proc (n)\n local i;\n\n fo r i from 2 to trunc(sqrt (n)) do\n if n mod i = 0 then RETURN (fals e) fi;\n od;\n RETURN (true);\nend;" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%+prime_testG:6#%\"nG6#%\"iG6\"F*C$?(8$\"\"#\"\"\"-%&truncG6#-%%sq rtG6#9$%%trueG@$/-%$modG6$F6F-\"\"!-%'RETURNG6#%&falseG-F?6#F7F*F*" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "prime_test(5);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%trueG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "prime_test(6);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%&falseG" }} }{EXCHG {PARA 259 "" 0 "" {TEXT -1 121 "4. Check your program from the previous question by comparing it with Maple's isprime function for t he first 100 numbers." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 143 "c heck := proc ()\n local i;\n\n for i from 2 to 100 do\n if not (i sprime(i)=prime_test(i)) then RETURN (false) fi;\n od;\n RETURN (tru e);\nend;" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&checkG:6\"6#%\"iGF&F&C $?(8$\"\"#\"\"\"\"$+\"%%trueG@$4/-%(isprimeG6#F+-%+prime_testGF5-%'RET URNG6#%&falseG-F96#F/F&F&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "check ();" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%trueG" }}}{EXCHG {PARA 260 "" 0 "" {TEXT -1 84 "5. Write a program which, given a piece of text, returns the text written backwards." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 66 "There are many ways to do this. Here is one way, usin g recursion:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 282 "backwards \+ := proc (text)\n local last_letter, all_except_last;\n\n if length ( text) <= 1 then RETURN (text) fi;\n\n last_letter := substring (text, length(text));\n all_except_last := substring (text, 1..length(text) -1);\n RETURN (cat (last_letter, backwards (all_except_last)));\nend: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "backwards (`Does it wor k? Of course!`);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%9!esruoc~fO~?krow ~ti~seoDG" }}}{EXCHG {PARA 261 "" 0 "" {TEXT -1 230 "6. Write a progra m which, given a piece of text, returns a list of the characters occur ring in the text, along with the number of times they occur, in order \+ of decreasing frequency. (Eg: given ``eep'', would return (e,2), (p,1 ))." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 59 "Again, there are many ways of doing this. Here is one way:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 263 "count := proc (text)\n local counts, nums;\n\n num s := convert(text, 'bytes');\n counts := map ((x,y) -> [convert([x], \+ 'bytes'), numboccur (y,x)], nums, nums);\n counts := convert (convert (counts, set), list);\n op (sort (counts, (x,y) -> evalb(x[2]>y[2])) );\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "count (`How man y roads must a man walk down?`);" }}{PARA 12 "" 1 "" {XPPMATH 20 "627$ %\"~G\"\"(7$%\"aG\"\"&7$%\"nG\"\"$7$%\"mGF+7$%\"wGF+7$%\"oGF+7$%\"sG\" \"#7$%\"dGF47$%\"kG\"\"\"7$%\"lGF97$%\"tGF97$%\"uGF97$%\"rGF97$%\"yGF9 7$%\"HGF97$%\"?GF9" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 258 99 "7. Write a Maple program which, given an RSA public key [n,a], finds the corresp onding private key." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "with (numtheory):" }}{PARA 7 "" 1 "" {TEXT -1 33 "Warning, new definition f or order" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 102 "crack := proc \+ (key)\n local phi_n;\n\n phi_n := phi (key [1]);\n [key[1], modp (1 /key[2], phi_n)];\nend;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%&crackG:6 #%$keyG6#%&phi_nG6\"F*C$>8$-%$phiG6#&9$6#\"\"\"7$F1-%%modpG6$*$&F26#\" \"#!\"\"F-F*F*" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "crack ([5 2824610493623, 751]);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7$\"/BO\\5Y#G &\".RO0?5^)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "time (crack \+ ([25697821673947, 757]));" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#$\"%]r!\" $" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "29 0 0" 0 }{VIEWOPTS 1 1 0 3 2 1804 }