{VERSION 4 0 "APPLE_PPC_MAC" "4.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 35 "" 0 1 104 64 92 1 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 256 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 257 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 258 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 259 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 260 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 261 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 262 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 263 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 264 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 265 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 266 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 267 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 268 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 269 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 270 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 271 "" 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0 0 0 0 0 0 }{CSTYLE "" -1 374 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 375 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 376 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 377 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 378 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 379 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 380 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 381 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 382 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 383 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 1 " -1 3 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 1" -1 256 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 }{PSTYLE "Normal" -1 257 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Author" -1 258 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 1 1 1 1 }3 1 0 0 8 8 1 0 1 0 2 2 0 1 }{PSTYLE "Title" -1 259 1 {CSTYLE "" -1 -1 "Ti mes" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Normal" -1 260 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "" 0 261 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 1 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 259 "" 0 "" {TEXT -1 9 "Lecture 2" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 50 "if ... then ... elif ... then ... else .. . end if;" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 257 "" 0 "" {TEXT 282 49 "Such statements take one of the following forms:" } {TEXT -1 2 "\n\n" }{TEXT 262 2 "if" }{TEXT -1 1 " " }{TEXT 274 18 "boo lean expression" }{TEXT -1 1 " " }{TEXT 263 4 "then" }{TEXT -1 7 " \n \+ " }{TEXT 275 22 "sequence of statements" }}{PARA 257 "" 0 "" {TEXT 278 7 "end if;" }{TEXT 279 1 "\n" }}{PARA 257 "" 0 "" {TEXT -1 38 "--------------------------------------" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 264 2 "if" }{TEXT -1 21 " boolean expr ession " }{TEXT 265 4 "then" }{TEXT -1 27 " \n sequence of statement s\n" }{TEXT 266 4 "else" }}{PARA 0 "" 0 "" {TEXT -1 24 " sequence of s tatements\n" }{TEXT 280 7 "end if;" }{TEXT -1 1 "\n" }}{PARA 0 "" 0 " " {TEXT -1 38 "--------------------------------------" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 267 2 "if" }{TEXT -1 24 " b oolean expression1 " }{TEXT 268 4 "then" }{TEXT -1 27 " \n sequence \+ of statements\n" }{TEXT 269 4 "elif" }{TEXT -1 21 " boolean expression 2 " }{TEXT 270 4 "then" }}{PARA 0 "" 0 "" {TEXT -1 23 " sequence of st atements" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 4 " " }{TEXT 283 6 ". . . " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT 271 4 "elif" }{TEXT -1 21 " boolean expression3 \+ " }{TEXT 272 4 "then" }{TEXT -1 25 "\n sequence of statements\n" } {TEXT 273 4 "else" }{TEXT -1 26 "\n sequence of statements\n" }{TEXT 281 7 "end if;" }}{PARA 0 "" 0 "" {TEXT -1 38 "----------------------- ---------------" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 8 "Here by " }{TEXT 259 18 "boolean expression" }{TEXT -1 165 " we mean a statement that is either true or false. Such statement s are usually constructed using <, <=, >, >=, <>. or = together possib ly with the logical operators " }{TEXT 258 12 "and, or, not" }{TEXT -1 6 ". \n\nA " }{TEXT 276 10 "statement " }{TEXT -1 80 "is a command \+ followed by a colon or semicolon. The following is an example of a " } {TEXT 277 22 "sequence of statements" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 1 " " }{TEXT 284 35 " y:=i^2;\n z:=i^3; \n print(y,z);" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 1 "[" }{TEXT 261 7 "Remark:" }{TEXT -1 22 " In Maple V one us es " }{TEXT 285 2 "fi" }{TEXT -1 11 " in place " }{TEXT 260 8 "end f i ." }{TEXT -1 24 " In Maple 6 one may use " }{TEXT 286 7 "fi, end" } {TEXT -1 4 " or " }{TEXT 287 6 "end if" }{TEXT -1 87 " interchangeably .]\n\nWe now look at some examples. The first illustrates a common err or." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "if t > 1 then \n x:=3; \nend if;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 34 "The expression t > 1 is called a " }{TEXT 257 18 "boolean expr ession" }{TEXT -1 227 ". The problem here is that Maple does not know the value of t so it cannot tell if t > 1 is true or false. This ca n be fixed by putting in a value of t as we now do. Note that a print \+ statement is not needed if we use end if" }{TEXT 368 1 ";" }{TEXT -1 22 " as opposed to end if" }{TEXT 369 1 ":" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "t:=3:\nif t > 1 t hen \n x:=2;\n print(x);\nend if:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "t:=3:\nif t > 1 then \n x:=2;\nend if;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "t:=0:\nif t > 1 then \n x:=2; \ne nd if; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 44 "t:=0:\nif t > 1 then \n x:=2; \nend if;\nx:=3 ; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 46 "The same thing can be done \+ with the following:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "t:=0 :\nif t > 1 then \n x:=2; \nelse\n x:=3;\nend if;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 23 "Here we illustrate the " }{TEXT 256 52 "if .. t hen .. elif .. then else... fi construction." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 183 "f:=proc(y)\n if y <= 1 then \n return 1;\n el if y <= 2 then \n return 2;\n elif y <= 3 then \n return 3;\n elif y <= 4 then \n return 4;\n else \n return infinity;\n end if;\nen d proc:\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 47 "The same thing can b e accomplished as follows:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 167 "g:=proc(y)\nif y <= 1 then return 1; end if;\nif y <= 2 then re turn 2; end if;\nif y <= 3 then return 3; end if;\nif y <= 4 then retu rn 4; end if; \nreturn infinity; \nend:\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 49 "We check a few values of x to see if f(x) = g(x):" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 108 "for x from 0 to 5 by .5 d o \nprint(`If x= ` , x , ` then, f(x) = ` , f(x) , ` g(x) = `, g(x)); \nod;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 154 "Let's try to pl ot the function f (t) for t from 0 to 5. The first plot fails, howeve r, the second method works. You can see that we have a step function. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 " plot(f(t),t=0..5, 0..5 );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "plot(f,0..5,0..5);" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 14 "More examples:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 106 "test:=proc(a,b,c)\n if (a < b) and (b < \+ c) then \n return true; \n else\n return false;\n end if;\nend pro c:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "test(1,2,3);\ntest(1, 2,1);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 55 "Note that we can get the se on the same line as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "test(1,2,3),test(1,2,1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 115 "composite:=proc(n)\n if isprime(n) = false then \n \+ return true; \n else\n return false; \n end if;\n end proc: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "composite(10);\ncomposi te(11);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 24 "Note that the statemen t " }{MPLTEXT 1 0 19 "isprime(n) = false " }{TEXT -1 34 "may be replac ed by the statement " }{MPLTEXT 1 0 15 "not(isprime(n))" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 53 "for ... while .. do \+ ... by .. end do, next and break" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "In Maple 6 one may replace " }{TEXT 293 8 "end do " }{TEXT 294 4 "by " }{TEXT 295 2 "od" }{TEXT 296 6 " or " }{TEXT 297 3 "end" } {TEXT 298 46 ". In Maple V one can only use the short form " }{TEXT 299 2 "od" }{TEXT 300 1 "." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 26 "We look at some examples: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 66 "for i to 3 \+ do \n y:=i^2;\n z:=i^3;\n sin(y*z);\n evalf(%);\nend do;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 29 "Note that this is the same as" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 73 "for i from 1 to 3 do \n y:= i^2;\n z:=i^3;\n sin(y*z);\n evalf(%);\nend do;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 356 "Note that the value of the index i is 4 after th e above loop for i from 1 to 3 is executed. Each time one goes through t the loop the value of the index is incremented by 1 and then if the \+ value is less that the upper limit 3 the loop is executed and control \+ is passed to the next statement (if there is one). We now see what the value of the variable i is:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "i;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "for q from -10 t o 10 by 5.5 do\n print(q);\nend do:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 121 "for w from 1 to 100 do\n if 2^w > 10^6 then\n pr int(w, 2^w);\n break;\n end if;\nend do;\nprint(`We are finished!` );\nw;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 10 "Note that " }{TEXT 288 5 "break" }{TEXT -1 64 " means to get out of the loop and go to the st atement following " }{TEXT 314 6 "end do" }{TEXT -1 154 ". If break is executed then the value of the index w is the value at the time the l oop is left. Note that the same result is obtained if we leave out the " }{TEXT 338 6 "to 100" }{TEXT -1 19 " on the first line." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 114 "for w from 1 do\n if 2^w > 10^6 t hen\n print(w, 2^w);\n break;\n end if;\nend do;\nprint(`We are finished!`);\nw;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "Let's write \+ a program to find the product of all primes less than 100: Try this pr ogram with a " }{TEXT 339 9 "semicolon" }{TEXT -1 7 " after " }{TEXT 340 6 "end do" }{TEXT -1 15 " rather than a " }{TEXT 341 5 "colon" } {TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 104 "P:=1:\nfo r m from 1 to 100 do\n if isprime(m) = false then \n next; \n end if;\n P:= P * m;\nend do:\nP; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 10 "Note that " }{TEXT 289 5 "next " }{TEXT -1 38 " means to go to the next value of the " }{TEXT 370 5 "index" }{TEXT -1 25 " - in the abov e case the " }{TEXT 371 5 "index" }{TEXT -1 4 " is " }{TEXT 342 1 "m" }{TEXT -1 139 ". \n\nIn the next example we seek the smallest positive integer n such that n! > 1000. When we find it we will call it a. Not e that in maple " }{TEXT 290 12 "factorial(n)" }{TEXT -1 5 " and " } {TEXT 291 2 "n!" }{TEXT -1 26 " are give the same result." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 87 "for n from 1 to 10 do \n if n! > 10 00 then \n print(n,n!);\n break;\n end if;\nend do:\nn;\n" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 35 "Another way to do this is by using " }{TEXT 292 7 "while. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "q:=0:\nfor n from 1 while q < 1000 do\n q:= n!;\nend do:\nn,n-1,q;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 343 59 "Note that the value of n at th e end of the above loop is 8." }{TEXT -1 69 " \n\nSee what happens if \+ we omit the q:=0; statement at the beginning:\n" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 7 "q:='q':" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "for n from 1 while q < 1000 do\n q:= n!;\nend do:" }}}{PARA 0 "" 0 "" {TEXT -1 118 "This is due to the fact that Maple does not kn ow the value of q at the first step, so cannot tell if q < 1000 or no t." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 " " 0 "" {TEXT -1 25 "for x in L do ... end do;" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 118 "Here is another w ay to use do loops. Here we specify exactly which values of the index \+ we want the loop to go through:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 54 "for x in [1,2,X,Y, t^2+t+1] do\n print(x,x^2);\nend do:" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 41 "[1,2,X,Y,t^2 + t + 1] is an example of a " }{TEXT 301 5 "list " }{TEXT -1 119 "--- we will say more about lists later. Y ou may also use set brackets \{ \} instead of [ ] as in the followin g example." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "for z in \{2, 5,7,11, r^3 + sin(w) \} do\n print(z,z^2);\nend do;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 15 "Nested do loops" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 13 "You may hav e " }{TEXT 344 27 "do loops inside of do loops" }{TEXT -1 112 ". Here \+ are some examples. The first allows us to generate all ordered pairs \+ i,j where i and j are in \{1,2,3,4\}:" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 78 "for i from 1 to 4 do\n \+ for j from 1 to 4 do\n print(i,j);\n end do;\nend do;\n" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 86 "The following allows us to generat e all combinations of \{1,2,3,4\} taken two at a time:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 82 "for i from 1 to 4 do\n for j from i+1 to 4 do\n print(i,j);\n end do;\nend do;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 51 "O f course, we may do other things other than just " }{TEXT 372 10 "pri nt(i,j)" }{TEXT -1 271 ". We can take i,j and perform various other op erations. For example, here we form the set of all sums of i and j and put them in a set called S when i + j is a prime number and we count the number of times that i + j is a prime. For this we need a \"count er\". We call it " }{TEXT 302 5 "count" }{TEXT -1 27 ". It could be an y variable." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 349 "S:=\{\}:\nc ount:=0:\nfor i from 1 to 4 do\n for j from i+1 to 4 do\n print( `-----------------`);\n print(i,j);\n n:=i+j;\n if isprime (n) then\n count:=count+1;\n print(`count = `, count); \n \+ S:=S union \{n\};\n print(`S = `, S); \n end if;\n end do;\nend do;\nprint(`----------`);\nprint(`S = `, S, `count = ` ,count);" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 320 "Why is count = 4, yet S only contains three elements?\n\nLater we will show how to get rid of unwanted commas such as the commas in the last output statement S = , \{ 3,5,7\}, count = , 4. \n\nWe can have \+ do loops nested three deep as in the following example where we form t he set of all binary sequences [lists] of length 3:" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 164 "S:=\{\}:\nfor x1 from 0 to 1 do\n for x2 \+ from 0 to 1 do\n for x3 from 0 to 1 do\n #print(x1,x2,x3);\n \+ S:=S union \{ [x1,x2,x3] \};\n end do:\n end do:\nend do:\nS;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 65 "We will learn other more efficient ways to define this set later." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 45 "Local and Global Var iables, and option trace" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT 303 15 "Local variables" }{TEXT -1 29 " are vari ables that are used " }{TEXT 345 6 "inside" }{TEXT -1 99 " a procedure . After the procedure is executed the local variables revert to their \+ original values. " }{TEXT 304 16 "Global variables" }{TEXT -1 121 " ma y be changed inside the procedure and the values will be retained afte r the procedure is over. Here are some examples:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "We first set the value of the four variables x1,x2,y1,y2:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "x1:=1:\nx2:=1:\ny1:=1:\ny2:= 1:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 10 "Note that " }{MPLTEXT 1 0 13 "option trace;" }{TEXT -1 224 " is useful for debugging procedures. When included it shows details of the internal workings of the proced ure. Sometimes this will permit one to find errors. It should be remov ed once the procedure is working correctly. The " }{MPLTEXT 1 0 1 "#" }{TEXT -1 85 " before the line is one way to cause Maple to skip the l ine. Try it with and without " }{MPLTEXT 1 0 1 "#" }{TEXT -1 1 "." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 124 "f:=proc(n)\n global x1,x2; \n local y1,y2;\n option trace:\n x1:=2:\n x2:=3:\n y1:=5:\n y2:=7 :\n return n*x1*x2*y1*y2;\nend proc:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "f(11);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "ifactor(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 45 "Now let's see wha t happened to the variables " }{TEXT 373 14 "x1, x2, y1, y2" }{TEXT -1 1 ":" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "x1,x2, y1,y2;" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 150 "You can see that the global var iables retain the changes made inside the procedure f, but the local v ariables are unchanged by what happened inside f." }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 260 "" 0 "" {TEXT -1 50 "I \+ recommend using global variables very sparingly." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 34 "Var iable names and reserved words." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 11 "In Maple a " }{TEXT 35 4 "name" } {TEXT -1 2 " (" }{TEXT 346 3 "aka" }{TEXT -1 4 ", a " }{TEXT 305 9 "va riable " }{TEXT -1 3 "or " }{TEXT 374 13 "variable name" }{TEXT -1 293 ") is usually a letter followed by zero or more letters, digits, a nd underscores, with lowercase and uppercase letters distinct. The max imum length of a name is system dependent. It may even contain spaces \+ if you enclose it in backquotes ` `. [Note that in output the backquot es are not shown.]" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "`this is the name of a variable`:=2;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "`this is the name of a variable`^2;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "this_is_the_name_of_a_variable:=3;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "this is not the name of a variable: =2;" }}}{PARA 0 "" 0 "" {TEXT -1 111 "Be carefully about using certain words as variables. If in doubt, enclose the word in backquotes. For \+ example, " }{TEXT 375 10 "quit; done" }{TEXT -1 5 ", or " }{TEXT 376 4 "stop" }{TEXT -1 65 "; will cause Maple to terminate the session. Ho wever you may use " }{TEXT 377 24 "`quit`, `done` or `stop`" }{TEXT -1 49 " as variables if you wish: The reserved words are" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 261 "" 0 "" {TEXT -1 342 "and break by catch description \ndo done elif else end \ne rror export fi finally for \nfrom global if in \+ intersect \nlocal minus mod module next \nnot od \+ option options or \nproc quit read return save \+ \nstop then to try union \nuse while " }}{PARA 0 " " 0 "" {TEXT -1 22 " " }}{PARA 0 "" 0 "" {TEXT -1 51 "You may find them at any time by using the command " }{MPLTEXT 1 0 9 "?reserved" }{TEXT -1 19 " . Note that since " }{TEXT 306 2 "in " }{TEXT -1 73 " is reserved it cannot be used as a variable. But `in` can be a variable." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "in:=2; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "`in`:=2;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "`in`^2;" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 36 "Perfect Squares and Sums of Squares." } }{EXCHG {PARA 0 "" 0 "" {TEXT -1 14 "The procedure " }{MPLTEXT 1 0 9 " root(x,n)" }{TEXT -1 184 " (when x is real or complex and n is a posit ive integer) computes the nth root of x. If x is an integer that is a \+ perfect nth power then the nth root is returned; otherwise the power \+ " }{XPPEDIT 18 0 "x^(1/n);" "6#)%\"xG*&\"\"\"F&%\"nG!\"\"" }{TEXT -1 98 " is returned unevaluated. We can tell if x is a positive integer \+ by use of the boolean function " }{MPLTEXT 1 0 14 "type(x,posint)" } {TEXT -1 86 " which is true if x is a positive integer and false other wise. Here are some examples:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "root(4,2);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "root(2, 3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "root(27,3);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 32 "Compare this with the following:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "27^(1/3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "simplify(%);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 22 "type(27^(1/3),posint);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 24 "type(root(27,3),posint);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "root(28,3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "type(%,posint);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "root(28.0,3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "root(1+2.0*I,3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 139 "Our \+ next procedure determines whether or not an integer n is a perfect squ are, that is, whether or not it is the square of another integer:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "is_sqr:=n->type(root(n,2), p osint);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "is_sqr(16);" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "is_sqr(17);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 130 "Now we want to determine whether or not \+ the positive integer n is a sum of two positive squares or not. If it \+ is, we want to find " }{TEXT 347 14 "all solutions " }{TEXT -1 17 "to \+ the equations " }{XPPEDIT 18 0 "n = x^2+y^2;" "6#/%\"nG,&*$%\"xG\"\"# \"\"\"*$%\"yGF(F)" }{TEXT -1 111 " where x and y are positive integers . Note that if x and y are positive integer solutions we may assume t hat " }{XPPEDIT 18 0 "x <= sqrt(n/2);" "6#1%\"xG-%%sqrtG6#*&%\"nG\"\" \"\"\"#!\"\"" }{TEXT -1 0 "" }{TEXT 365 2 " ." }{TEXT -1 75 " [Can yo u see why? What happens if both x and y are strictly greater than " } {XPPEDIT 18 0 "sqrt(n/2);" "6#-%%sqrtG6#*&%\"nG\"\"\"\"\"#!\"\"" } {TEXT -1 4 " ?]" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 209 "sumsqr :=proc(n)\n local x, y, Sols;\n Sols:=\{\};\n for x from 1 to evalf(sq rt(n/2)) do\n y:= root(n-x^2,2);\n if type(y,posint) then \n \+ Sols:=Sols union \{\{x,y\}\}; \n end if;\n end do;\n return Sols;\ne nd proc: " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 34 "\nWhat happens if we leave off the " }{TEXT 366 5 "evalf" }{TEXT -1 21 " in the 4-th line \+ of " }{TEXT 367 6 "sumsqr" }{TEXT -1 66 "? Remove it and try. Next we \+ illustrate the use of this procedure:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "sumsqr(50);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "W e check these two answers." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "1^2+7^2, 5^2 + 5^2;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 73 "What w ould happen in the definition of sumsqr if you replaced the command" } {MPLTEXT 1 0 21 " Sols union \{\{x,y\}\}; " }{TEXT -1 5 " by " } {MPLTEXT 1 0 17 "Sols union \{x,y\};" }{TEXT -1 1 "?" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 46 "The number of elements in a set S is given by \+ " }{MPLTEXT 1 0 7 "nops(S)" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 9 "nops(\{\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "nops(\{a,b,c,d\});" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 75 "We ca n find this to find the number of different solutions to the equation \+ " }{XPPEDIT 18 0 "n = x^2+y^2" "6#/%\"nG,&*$%\"xG\"\"#\"\"\"*$%\"yGF(F )" }{TEXT -1 41 " where x and y are integers. For example:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "nops(sumsqr(50));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 36 "Let's find the smallest n for which " } {XPPEDIT 18 0 "n = x^2+y^2;" "6#/%\"nG,&*$%\"xG\"\"#\"\"\"*$%\"yGF(F) " }{TEXT -1 36 " has at least 2 different solutions:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 98 "for n from 1 do \nif nops(sumsqr(n)) >= 2 then \n print(n,sumsqr(n));\n break; \n end if;\nend do;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 36 "Let's find the smallest n for whic h " }{XPPEDIT 18 0 "n = x^2+y^2;" "6#/%\"nG,&*$%\"xG\"\"#\"\"\"*$%\"yG F(F)" }{TEXT -1 36 " has at least 3 different solutions:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 100 "for n from 1 do \n if nops(sumsqr (n)) >= 3 then \n print(n,sumsqr(n));\n break; \n end if;\nend do ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 " " 0 "" {TEXT -1 30 "Assignment 2 (Due Next Monday)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT 349 429 "Perhaps you have heard the famous story about Ramanujan and Hardy's taxi number: Once when Ramanujan was ill in London, Hardy visited Ramanujan in the hosp ital. When Hardy remarked that he had taken taxi number 1729, a singul arly unexceptional number, Ramanujan immediately responded that this n umber was actually quite remarkable: it is the smallest positive integ er that can be represented in two ways by the sum of two cubes." } {TEXT -1 2 " [" }{TEXT 316 55 "Eric Weisstein's Treasure Trove of Scie ntific Biography" }{TEXT -1 1 "]" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT 315 10 "Problem 1." }{TEXT -1 375 " \n\nVerify \+ (using Maple) Ramanujan's statement that 1729 is the smallest positive integer that can be expressed in two different ways as a sum of two c ubes. You should be able to use the ideas in the section above on perf ect squares and sums of squares. Only here we are talking of cubes ins tead of squares. But there are other ways to do the problem that may \+ occur to you. " }{TEXT 348 85 "[This took about 1 minute on a 500 Mhz \+ Mac G-4. So don't expect an immediate answer.]" }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 1 "\n" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 308 11 "Problem 2. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 328 11 " Definition." }{TEXT 350 25 " A positive integer n is " }{TEXT 327 7 "p erfect" }{TEXT 351 49 " if the sum of its proper positive divisors is \+ n." }{TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 278 "\nFor example, the proper positive divisors of 6 are 1, 2, and 3 and 6 = 1 + 2 + 3. So 6 is perfect. [If you have had number theory you may know about the str ucture of perfect numbers. Do not use that knowledge for this exercis e. Use only the definition to write your programs.]" }}{PARA 0 "" 0 " " {TEXT 326 6 " \n(a) " }{TEXT -1 108 "Write a procedure which takes a s input a positive integer n and returns the sum of all proper divisor s of n." }{TEXT 313 1 " " }{TEXT -1 81 "Show how your procedure works \+ for the following values of n: 2, 3, 4, 6, 30, 900." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 307 4 "(b) " }{TEXT 317 34 "Us ing the procedure you wrote in " }{TEXT 352 3 "(a)" }{TEXT 353 1 " " }{TEXT -1 18 "write a procedure " }{TEXT 354 9 "isperfect" }{TEXT -1 55 " which takes as input a positive integer n and returns " }{TEXT 311 4 "true" }{TEXT -1 21 " if n is perfect and " }{TEXT 312 5 "false " }{TEXT -1 9 " if not. " }{TEXT 309 4 "Note" }{TEXT -1 53 ": proper d ivisors of n can not be greater than n/2. " }{TEXT 329 46 "Use the pr ocedure to find all perfect numbers " }{XPPEDIT 18 0 "n <= 1000;" "6#1 %\"nG\"%+5" }{TEXT 330 2 ". " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 310 17 "Interesting Fact:" }{TEXT 355 293 " It is an open question whether or not there are any odd perfect numbers. So far no one has found one. In number theory you learn the structure of the even perfect numbers. So far only a finite number of even perf ect numbers have been found. But it is suspected that there are infini tely many." }{TEXT -1 1 " " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 318 11 "Problem 3 ." }{TEXT -1 4 " \n\n" }{TEXT 356 10 "Defini tion" }{TEXT -1 6 ". The " }{TEXT 321 5 "order" }{TEXT -1 1 " " } {TEXT 332 13 "of an integer" }{TEXT -1 3 " a " }{TEXT 331 17 "modulo a n integer" }{TEXT -1 59 " m is defined to be the least positive intege r e such that " }{XPPEDIT 18 0 "`mod`(a^e,m) = 1;" "6#/-%$modG6$)%\"aG %\"eG%\"mG\"\"\"" }{TEXT -1 32 ". \n\nWrite a procedure, call it " } {TEXT 319 3 "Ord" }{TEXT -1 12 ", such that " }{TEXT 333 8 "Ord(a,m)" }{TEXT -1 22 " returns the order of " }{TEXT 378 10 "a modulo m" } {TEXT -1 31 " if the it exists and returns " }{TEXT 379 4 "FAIL" } {TEXT -1 32 " if the order does not exist. \n\n" }{TEXT 357 91 "You ma y use the number theoretic result that the order of a modulo m exists \+ if and only if " }{TEXT 334 13 "igcd(a,m) = 1" }{TEXT 358 46 ". Also y ou may use the fact that the order of " }{TEXT 380 10 "a modulo m" } {TEXT 381 23 " is never greater than " }{TEXT 382 5 "m - 1" }{TEXT 383 24 ". [Note that Maple uses " }{TEXT 335 4 "igcd" }{TEXT 359 49 " \+ for the greatest common divisor of integers and " }{TEXT 336 3 "gcd" } {TEXT 360 46 " for greatest common divisor of polynomials.] " }{TEXT -1 25 "\n\nCheck that you obtain: " }{TEXT 320 67 "\n\n Ord(0,1 1) = FAIL, Ord(2,11) = 10, Ord(4,11) = 5.\n\n" }}{PARA 0 "" 0 " " {TEXT 337 11 "Problem 4. " }{TEXT -1 15 "For each prime " }{TEXT 363 1 "p" }{TEXT -1 50 " from 2 to 100 find the smallest positive inte ger " }{TEXT 362 1 "a" }{TEXT -1 11 " such that " }{TEXT 361 14 "Ord(a ,p) = p-1" }{TEXT -1 25 ". Print out a table with " }{TEXT 364 4 "p, a " }{TEXT -1 39 " on each row. \n\n[Such an a is called a " }{TEXT 322 27 "primitive elements modulo p" }{TEXT -1 47 " and plays an important role in number theory.]" }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 " " 0 "" {TEXT 323 5 "Hint:" }{TEXT -1 82 " You might use a loop for p f rom 2 to 100. If p is not prime then use the command " }{TEXT 324 5 "n ext;" }{TEXT -1 195 " to go to the next value of p. If p is prime then go into another loop for a from 2 to p - 1 looking for an a which has order 1 modulo p. When you find one, print it out and then use the co mmand " }{TEXT 325 6 "break;" }{TEXT -1 19 " to leave the loop." }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}}{MARK "7" 0 }{VIEWOPTS 0 0 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }