{VERSION 5 0 "IBM INTEL NT" "5.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 "Emphasis" -1 256 "Times" 1 12 128 0 128 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "Maple Input" -1 257 "Courier" 1 12 255 0 0 1 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 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTY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0 }{CSTYLE "" -1 436 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 437 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 438 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 } {CSTYLE "" -1 439 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 440 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 441 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Tim es" 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 "Title" -1 18 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Author" -1 19 1 {CSTYLE "" -1 -1 "Times " 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 8 8 1 0 1 0 2 2 0 1 } {PSTYLE "Title" -1 256 1 {CSTYLE "" -1 -1 "Times" 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 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 "Normal" -1 258 1 {CSTYLE "" -1 -1 "T imes" 1 14 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 "Normal" -1 259 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 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT -1 9 "Lecture 6" }}{PARA 19 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 33 "The General Syntax of a Procedure" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 48 "The general syntax of a procedure is as f ollows:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{PARA 0 "" 0 "" {TEXT 269 4 "name" }{TEXT -1 2 ":=" }{TEXT 270 4 "proc" }{TEXT -1 17 "(P1, P2, . .., Pn)" }}{PARA 0 "" 0 "" {TEXT -1 2 " " }{TEXT 271 5 "local" } {TEXT -1 21 " L1, L2, ..., Lu; \n " }{TEXT 272 6 "global" }{TEXT -1 21 " G1, G2, ..., Gv; \n " }{TEXT 273 7 "options" }{TEXT -1 21 " O1, \+ O2, ..., Ow; \n " }{TEXT 274 11 "description" }{TEXT -1 78 " \"someth ing here to describe the procedure\"; \n S1;\n S2;\n \+ ----" }}{PARA 0 "" 0 "" {TEXT -1 12 " Sm; \n" }{TEXT 275 8 "end \+ proc" }{TEXT -1 1 ";" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 35 "In the above: \n\n" }{TEXT 260 4 "na me" }{TEXT -1 29 " is the name of the procedure" }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 33 "P1, P2, ..., Pn is a seq uence of " }{TEXT 258 9 "arguments" }{TEXT -1 6 " (aka " }{TEXT 259 10 "parameters" }{TEXT -1 71 ") that represent the input to the proced ure. As we shall see later the " }{TEXT 416 19 "type of a parameter" } {TEXT -1 4 " P " }{TEXT 417 69 "may be declared by replacing a parame ter by an expression of the form" }{TEXT -1 19 " \n\n P:: " }{TEXT 268 4 "type" }{TEXT -1 45 ", \n\nfor example, we could have \+ \n\n P1::" }{TEXT 265 7 "integer" }{TEXT -1 6 ", P2::" }{TEXT 266 6 "matrix" }{TEXT -1 6 ", P3::" }{TEXT 267 7 "numeric" }{TEXT -1 9 ", etc...\n" }}{PARA 0 "" 0 "" {TEXT -1 172 "This means that the par ameter P1 must be an integer, if it is not you will get a warning mess age when you attempt to use the procedure. Examples below will make th is clear." }}{PARA 0 "" 0 "" {TEXT -1 41 "\nL1, L2, ..., Lu represent \+ a sequence of " }{TEXT 261 5 "local" }{TEXT -1 53 " variables.\n\nG1, \+ G2, ..., Gv represent a sequence of " }{TEXT 262 6 "global" }{TEXT -1 58 " variables.\n\nO1, O2, . . . , Ow represent options such as " } {TEXT 334 6 "trace " }{TEXT -1 3 "and" }{TEXT 335 10 " remember." } {TEXT -1 32 " We will discuss these below.\n" }}{PARA 0 "" 0 "" {TEXT -1 6 "After " }{TEXT 263 11 "description" }{TEXT -1 150 " you ma y write anything enclosed in \" \". This is to help document what th e purpose of the procedure is. \n\nS1; S2; ... , Sm represents a seque nce of " }{TEXT 264 10 "statements" }{TEXT -1 67 " which tell the proc edure what to do. These may or may not contain " }{TEXT 385 6 "return " }{TEXT -1 57 " statements which provide the output of the procedure. \n\n" }{TEXT 412 68 "Note that the last thing to be computed is retur ned unless previous " }{TEXT 336 6 "return" }{TEXT 413 106 " statement s are executed. So if the output is computed on the last line before e nd; then that is returned." }{TEXT -1 69 "\n\nAs we have seen a proced ure need not contain all of these elements." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 22 "For more details see ?" }{TEXT 337 9 "procedure" }{TEXT -1 4 ", ?" }{TEXT 338 7 "options" }{TEXT -1 4 ", ?" }{TEXT 339 10 "parameters" }{TEXT -1 6 ", etc." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 50 "Example of a Procedure (Member with error warning)" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 48 "We have seen that Maple has a built-in p rogram " }{TEXT 276 7 "member " }{TEXT -1 104 "to test whether or not \+ x is an element of a list or set. Here we construct such a procedure a nd call it " }{TEXT 277 6 "Member" }{TEXT -1 41 " to distinguish it fr om Maple's built-in " }{TEXT 278 6 "member" }{TEXT -1 12 ". Note that \+ " }{TEXT 414 10 "x::integer" }{TEXT -1 41 " declares that x must be an integer, and " }{TEXT 415 7 "L::list" }{TEXT -1 32 " declares that L \+ must be a list." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 247 "Member: =proc(x::integer, L::list)\n local i;\n description \"this procedure returns true if x is an integer, L is a list and x is in L \";\n for i from 1 to nops(L) do\n if x = L[i] then return true; e nd if;\n end do;\n false;\nend proc:\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 26 "Now lets see how it works." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "Member(5,[1,2,3]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "Member(5,5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "Member(5,[1,2,3,4,5]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "Member(5, \{1,2,3,4,5\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "Member(2.2,[2.3,2.2]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 126 "We can correct this by changing Member as follows. This time we \+ leave off the type checking. We do type checking another way:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 319 "Member:=proc(x,Y)\nlocal i;\ndescription \" this procedure returns true if x is anything, Y is a set or list and x is in Y\";\nif not(type(Y, set) or type(Y,list)) then \n error \"the second argument must be a set or a list\";\nend if;\nfor i from 1 to \+ nops(Y) do\n if x = Y[i] then return true; end if;\nend do;\nfalse; \nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "Member(2.2, \+ \{1,2,z,sqrt(2), 2.2\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "A:=matrix([[1,2],[3,4]]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "Member(1,A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 59 "Alternative w e could have written the procedure as follows:" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 235 "Member:=proc(x::anything,Y::\{set,list\})\nlo cal i;\ndescription \"this procedure returns true if x is anything, Y \+ is a set or list and x is in Y\";\nfor i from 1 to nops(Y) do\n if x = Y[i] then return true; end if;\nend do;\nfalse;\nend proc:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "Member(2,\{1,2,3\});" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "Member(2,[1,2,3]);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "Member(2,2*x^3+3);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 106 "Note Well: You don't have to cons truct your own member procedure. You may use the Maple builtin procedu re " }{TEXT 418 7 "member " }{TEXT -1 38 "or for more general uses the procedure" }{TEXT 420 5 " has." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 " " 0 "" {TEXT -1 41 "Recursive Procedures: (Fibonacci Numbers)" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 2 "A \+ " }{TEXT 285 9 "recursive" }{TEXT -1 48 " procedure is a procedure whi ch \"calls itself\". " }{TEXT 340 85 "This means that the name of the \+ procedure is used in the definition of the procedure." }{TEXT -1 21 " \+ Here's an example: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 4 "The " }{TEXT 312 17 "Fibonacci numbers" }{TEXT -1 152 ": The Fibonacci numbers form a sequence 0, 1, 2, 3, 5, 8, 13, ... Th e n-th element is the sum of the (n-2)-nd and (n-1)-st elements in the sequence. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 136 "We will show several ways to produce Fibonacci numbers. Each p rocedure will give the n-th Fibonacci number. We call the first proced ure " }{TEXT 286 4 "fib1" }{TEXT -1 12 ". Note that " }{TEXT 287 4 "fi b1" }{TEXT -1 36 " is used twice in the definition of " }{TEXT 288 4 " fib1" }{TEXT -1 2 ". " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "restart;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 93 "fib1:=proc(n)\nif n = 0 or n = 1 then \n retur n n; \nend if;\nfib1(n-2) + fib1(n-1);\nend proc:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "fib1(2);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "fib1(3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "seq(fib1(i),i=0..20);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 24 "Note fr om n = 2 onward, " }{TEXT 289 4 "fib1" }{TEXT -1 16 "(n) is equal to \+ " }{TEXT 290 4 "fib1" }{TEXT -1 8 "(n-2) + " }{TEXT 292 3 "fib" } {TEXT -1 0 "" }{TEXT 291 1 "1" }{TEXT -1 28 "(n-1). Note that to compu te " }{TEXT 293 4 "fib1" }{TEXT -1 6 "(20), " }{TEXT 294 4 "fib1" } {TEXT -1 20 " must first compute " }{TEXT 295 4 "fib1" }{TEXT -1 9 "(1 9) and " }{TEXT 296 4 "fib1" }{TEXT -1 52 "(18), but to compute each \+ of these it must compute " }{TEXT 297 4 "fib1" }{TEXT -1 9 "(18) and \+ " }{TEXT 298 4 "fib1" }{TEXT -1 9 "(17) and " }{TEXT 299 4 "fib1" } {TEXT -1 9 "(17) and " }{TEXT 300 4 "fib1" }{TEXT -1 57 "(16), and so \+ on. This takes a lot of time and repetition." }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 14 "By putting in \+ " }{TEXT 283 15 "option remember" }{TEXT -1 30 ", as we now do, the pr ocedure " }{TEXT 419 9 "remembers" }{TEXT -1 194 " the values already \+ computed --it puts them in a table-- and does not have to recompute th em. The only problem with this is it sometimes uses a lot of memory to store the computed values in the " }{TEXT 282 15 "remember table." } {TEXT -1 20 " We illustrate with " }{TEXT 301 4 "fib2" }{TEXT -1 2 ": \n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 110 "fib2:=proc(n)\noptio n remember:\nif n = 0 or n = 1 then \n return n; \nend if;\nfib2(n-2 ) + fib2(n-1);\nend proc:\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 284 28 "C omparison of running times." }{TEXT -1 11 " Note that " }{TEXT 279 6 " time()" }{TEXT -1 188 "; gives the total CPU time used since the star t of the Maple session your computer in seconds. So the following meth od gives the time used for the given computation. Note how much faster " }{TEXT 421 4 "fib2" }{TEXT -1 4 " is." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 62 "starttime:=time():\n fib1(25);\nelapsedtime:=time()-starttime;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 62 "starttime:=time():\n fib2(25);\nelapsedtime:=ti me()-starttime;\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 65 " Here's how \+ we find the values stored in the remember table. For " }{TEXT 386 4 "f ib1" }{TEXT -1 31 " there is no remember table: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "op(4,eval(fib1));" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 4 "But " }{TEXT 387 4 "fib2" }{TEXT -1 46 " has a large rem ember table after calculating " }{TEXT 388 8 "fib2(25)" }{TEXT -1 1 ": " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "op(4,eval(fib2)); " }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 31 "Let's try to compute fib2(500);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "starttime:=time():\nfib2( 500);\nelapsedtime:=time()-starttime;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 17 "Now the value of " }{TEXT 389 9 "fib2(500)" }{TEXT -1 95 " is in the remember table so it doesn't have to be recomputed. Thus i t is returned immediately:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "starttime:=time():\nfib2(500);\nelapsedtime:=time()-starttime;" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 60 "Just look at the 500th entry in t he remember table for fib2:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "op(4,eval(fib2))[500];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 10 "Not e that " }{TEXT 302 4 "fib2" }{TEXT -1 35 "(500) takes much fewer seco nds the " }{TEXT 303 6 "second" }{TEXT -1 50 " time you call it since \+ it has already calculated " }{TEXT 304 4 "fib2" }{TEXT -1 34 "(500) an d just looks it up in its " }{TEXT 280 16 "remember table. " }{TEXT -1 88 "Such tables can clog up one's memory so to clear it out when no longer needed using the " }{TEXT 281 6 "forget" }{TEXT -1 20 " comman d as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "forget(fib 2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "See that the remember tabl e for fib2 is really empty now:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "op(4,eval(fib2));\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 271 "R ecursive procedures can be written as non-recursive procedures usually with some more effort. For example, here is a way to generate the Fi bonacci numbers by a procedure which doesn't call itself. It is a litt le harder to understand, but requires much less memory that " }{TEXT 390 6 "fib2. " }{TEXT -1 9 "I call it" }{TEXT 423 7 " fib3. " }{TEXT 422 50 "Read it carefully and try to see what it is doing." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 212 "fib3:=proc(n)\nlocal minus1,minus2 ,temp,i;\nif n = 0 or n = 1 then \n return n; \nend if;\nminus2:=0;\n minus1:=1:\nfor i from 2 to n do\n temp:=minus2 + minus1;\n minus2:= minus1;\n minus1:=temp;\nend do;\ntemp;\nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "seq(fib3(i),i=0..20);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 37 "Compare the time it takes to compute " }{TEXT 424 10 "fib3(1000)" }{TEXT -1 35 " with the time it takes to compute \+ " }{TEXT 425 8 "fib1(20)" }{TEXT -1 5 " and " }{TEXT 426 10 "fib2(1000 )" }{TEXT -1 31 ": Notice which is the fastest. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "starttime:=time():\nfib3(1000);\nelapsedtime: =time() - starttime;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "sta rttime:=time():\nfib1(20);\nelapsedtime:=time() - starttime;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "starttime:=time():\nfib2(100 0);\nelapsedtime:=time() - starttime;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 22 "Remember Ta ble for sin" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 195 "This command will \+ give slightly different output for Maple V and Maple 6 or 7. In partic ular in Maple 6 or 7 it does not contain the value for sin(Pi/12). But it may be obtained with the command " }{TEXT 331 27 "convert(sin(Pi/1 2),radical)" }{TEXT -1 2 "; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "op(4, eval(sin));\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "sin(Pi/3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "sin(Pi/12 );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "convert(%,radical);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 52 "But this doesn't work for all r ational multiples of " }{XPPEDIT 18 0 "pi;" "6#%#piG" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "sin(Pi/17);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "convert(%,radical);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "We could add it to the remember table for sin as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "sin(Pi/ 12) := sqrt(2)/4 *(sqrt(3) -1):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "sin(Pi/12);" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 52 "Note that this is now in the remember table for sin." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "op(4, eval(sin));" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 1 "\n" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 41 "Two More Examples of Recursive Procedures" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 47 "Study car efully the procedures in this section." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 204 "ADD:=proc(f::procedure, n::nonnegi nt)\noption remember;\ndescription `this computes the sum f(0) + f(1) \+ + f(2) +...+f(n)`;\nif n = 0 then \n return f(0); \nelse \n return ADD(f,n-1)+f(n); \nend if;\nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "ADD(cos,4);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "ADD(cos,-4);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 204 "MUL: =proc(f::procedure, n::nonnegint)\noption remember;\ndescription `this computes the product f(0)*f(1)*f(2)*...*f(n)`;\nif n = 0 then \n re turn f(0); \nelse \n return MUL(f,n-1)*f(n); \nend if; \nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "MUL(exp,4);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "MUL(g,5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "ADD(g,5);" }}}{EXCHG {PARA 259 "" 0 "" {TEXT -1 77 "We can make Maple think g is a procedure if we execute the following \+ command:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "g(-1):=2;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "MUL(g,5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "ADD(g,5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 114 "Both procedu res can also be written with a do loop as we have seen before. Actuall y Maple has built-in procedures " }{TEXT 391 3 "sum" }{TEXT -1 2 ", " }{TEXT 392 3 "add" }{TEXT -1 2 ", " }{TEXT 393 7 "product" }{TEXT -1 5 " and " }{TEXT 394 3 "mul" }{TEXT -1 181 " which do more or less wha t these procedures do (and are more efficiently) as we will discuss \+ in the next lecture. These two procedures were just for the purpose o f illustration." }}}{PARA 0 "" 0 "" {TEXT -1 1 "\n" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 25 "Viewing Maple Source Code" }}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 114 "For programmers, a tremendous benefit of Maple is its \"open-arch itecture\". You can access the source code to over " }{TEXT 256 3 "95% " }{TEXT -1 217 " of the math routines available. This allows you to \+ see what's going on and in some cases you may want to change procedure s to make them more suitable for your needs. One way to view the cod e is to use the command " }{TEXT 428 8 "showstat" }{TEXT -1 95 " as fo llows. This is also useful for debugging. Note that it numbers the lin es of the program. " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "showstat(ran d);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "\nAnother way is to use th e " }{TEXT 427 10 "interface " }{TEXT -1 38 "command as follows. First we execute. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "interface( verboseproc=2);" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 96 "Then we can view the code for various procedures. F or example, let's look at isprime. Applying " }{TEXT 305 5 "eval " } {TEXT -1 4 " or " }{TEXT 306 6 "print " }{TEXT -1 25 "returns the sour ce code. " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "print(isprime);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "You may find it difficult to copy \+ and paste from the output above. If so use use the command " }{TEXT 429 22 "lprint(eval(isprime));" }{TEXT -1 88 " as follows. Then you sh ould be able to select, copy and paste into Maple input regions." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "lprint(eval(isprime));" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 156 "Now selecting the first large num ber in the program, we paste it in and factor it using ifactor. We see that it is the product of all primes from 2 to 100. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "ifactor(230556796394551842475310214 7331756070);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 94 "Notice that this \+ procedure used the procedure igcd as well as other procedures. The pro cedure " }{TEXT 307 4 "igcd" }{TEXT -1 120 " is \"builtin\" and not av ailable--as you see if you try the following command. A few of the mor e basic commands are like " }{TEXT 308 4 "igcd" }{TEXT -1 44 " and the code is not available to the user. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "eval(igcd);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "eval(seq);" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 " " 0 "" {TEXT -1 65 "When done looking at the source code it is a good \+ idea to reset " }{TEXT 309 11 "verboseproc" }{TEXT -1 29 " to the def ault output level." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "interface(ver boseproc=1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 12 "Option trace" }}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 310 14 "op tion trace: " }{TEXT -1 165 "This option causes maple to print out mor e details about the behaviour of the procedure and may be useful duri ng debugging. It seems to have the same effect as the " }{TEXT 430 14 "debug, undebug" }{TEXT -1 5 " and " }{TEXT 431 5 "trace" }{TEXT -1 3 ", " }{TEXT 432 7 "untrace" }{TEXT -1 55 " command mentioned previous ly. Here's a simple example." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 116 "test:=proc(n)\nlocal i,S;\noption trace;\nS:=0:\nfor i from 1 t o n do\nif i > 2 then S:=S+i; end if;\nend do;\nS;\nend proc:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "test(4);" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 31 "Remove or comment out the line " }{TEXT 311 12 "op tion trace" }{TEXT -1 55 "; and reinter the procedure to get back in n ormal mode." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 117 "test:=proc( n)\nlocal i,S;\n#option trace;\nS:=0:\nfor i from 1 to n do\nif i > 2 \+ then S:=S+i; end if;\nend do;\nS;\nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "test(4);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 15 " args and nargs" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 55 "The variables used as input for a procedure are ca lled " }{TEXT 319 10 "parameters" }{TEXT -1 4 " or " }{TEXT 320 9 "arg uments" }{TEXT -1 56 ". For example, in the procedure whose definition begins " }{TEXT 313 19 "f:=proc(A,s,t,n), " }{TEXT -1 28 "A, s,t and n are called the " }{TEXT 395 9 "arguments" }{TEXT -1 4 " or " } {TEXT 396 10 "parameters" }{TEXT -1 45 " of the procedure. By using th e special name " }{TEXT 314 5 "args " }{TEXT -1 4 "and " }{TEXT 315 5 "nargs" }{TEXT -1 65 " one need not declare any parameters when defini ng a procedure. " }{TEXT 316 8 "args[1] " }{TEXT -1 23 "is the first \+ argument, " }{TEXT 317 8 "args[2] " }{TEXT -1 57 "is the second argume nt, etc., The number of arguments is " }{TEXT 318 6 "nargs." }{TEXT -1 25 " One advantage in using " }{TEXT 383 4 "args" }{TEXT -1 5 " an d " }{TEXT 384 5 "nargs" }{TEXT -1 88 " is that we don't have to speci fy in advance the number of arguments. Here's an example:" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 53 "In this pr ocedure we use the builtin Maple procedure " }{TEXT 321 3 "add" } {TEXT 397 2 ".\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 256 "Avg:=p roc()\n local i,A,N;\n description \"this computes the average of th e arguments--all assumed to be numbers\";\n if nargs = 0 then \n \+ error \"there are no numbers to average\"; \n end if;\n A:=add(args[ i],i=1..nargs);\n return evalf(A/nargs);\nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "Avg(10.8,2,3,3,4,5,6);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "Avg();" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 123 "Next we show how to create a procedure to find the maximum of \+ a sequence of numbers. Actually Maple has a builtin function " }{TEXT 332 3 "max" }{TEXT -1 94 " to do this, but it is useful to know how it is constructed for other purposes. Our procedure " }{TEXT 399 3 "Max " }{TEXT -1 27 " returns the largest entry " }{TEXT 398 3 "and" } {TEXT -1 95 " the index of the first occurrence of this entry. It does a little more than Maple's procedure " }{TEXT 333 4 "max " }{TEXT -1 28 "does, but it is not as fast." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 315 "Max:=proc()\nlocal M,w,i;\ndescription `this procedu re returns the list [M,w] where M is the largest element in the input \+ sequence and w is the index of the first occurrence of M`;\n M:=args[ 1];\n w:=1;\n for i from 2 to nargs do\n if args[i] > M then\n M :=args[i];\n w:=i;\n end if;\n end do;\n[M,w];\nend proc:\n\n" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "Max(10, 110 , 445, 78, 34) ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 " " 0 "" {TEXT -1 32 "Local and Global Variables Again" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 31 "We first illustrate the use of " }{TEXT 322 16 "global variable s" }{TEXT -1 52 " and some strange things that can happen when using \+ " }{TEXT 323 16 "local variables." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "x:=10;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 66 "f :=proc(s)\nlocal b;\nglobal x;\nx:=s*x;\nb:=x^2;\nreturn b;\nend proc: \n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "f(5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "x;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "b;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "Compare the above procedure with the following procedure:" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "x:=10;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 58 "g:=proc(s) \nlocal b,x;\nx:=s*x;\nb:=x^2;\nreturn b;\nend proc:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "g(5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "x;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "b;" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 18 "Another example: (" }{TEXT 324 32 "\"When local variables leave home" }{TEXT -1 3 ".\")" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "restart;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "w:=x;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "h:=proc()\nlocal x;\nx;\nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "z:=h();" }}}{EXCHG {PARA 259 "" 0 "" {TEXT -1 173 "It \+ appears that both w and z are equal to x. But w is equal to the globa l variable x\nand z is equal to the local variable created inside the \+ procedure h. So maple considers" }}{PARA 259 "" 0 "" {TEXT -1 57 "them to be different even though they both look the same;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "z,w;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "evalb(x=z);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "evalb(x=w);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "2*(z+w) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 60 "But notice that Maple automa tically simplifies 2(x+x) to 4x:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "2*(x+x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 " r:=h();" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "evalb(r=z);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 71 "Now z, w, r are all equal to x, bu t these are different x's, as we see:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "\{z,w,r\};" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "Com pare with the following:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 " \{x,x,x\};" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 48 "We can create yet a 4-th distinct x, as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "s:=h();" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "\{z,w,r,s\} ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "2*(z+w+r+s);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "2*(x+x+x+x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 10 "Iteration " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 " " 0 "" {TEXT -1 32 "Given a function f : X -> Y let " }{XPPEDIT 18 0 " x[0];" "6#&%\"xG6#\"\"!" }{TEXT -1 29 " be any element of X. Define " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {XPPEDIT 18 0 "x[1] \+ := f(x[0]);" "6#>&%\"xG6#\"\"\"-%\"fG6#&F%6#\"\"!" }{TEXT -1 4 ", " }{XPPEDIT 18 0 "x[2] := f(x[1]);" "6#>&%\"xG6#\"\"#-%\"fG6#&F%6#\"\"\" " }{TEXT -1 3 ", " }{XPPEDIT 18 0 "x[3] := f(x[2]);" "6#>&%\"xG6#\"\" $-%\"fG6#&F%6#\"\"#" }{TEXT -1 8 ", . . . " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 16 "and, in general " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {XPPEDIT 18 0 "x[n+1] := f(x[n]); " "6#>&%\"xG6#,&%\"nG\"\"\"F)F)-%\"fG6#&F%6#F(" }{TEXT -1 13 " for n \+ > 0. " }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 13 "The sequence " }{XPPEDIT 18 0 "x[0],x[1],x[2];" "6%&%\"xG6#\"\"!&F$6# \"\"\"&F$6#\"\"#" }{TEXT -1 19 ", . . ., is called " }{TEXT 364 13 "th e orbit of " }{XPPEDIT 365 0 "x[0];" "6#&%\"xG6#\"\"!" }{TEXT 366 35 " under the action of the function f" }{TEXT -1 33 ". This process is also called " }{TEXT 341 40 "iteration of the function f starting at " }{XPPEDIT 18 0 "x[0];" "6#&%\"xG6#\"\"!" }{TEXT -1 23 " and is an e xample of a" }{TEXT 342 19 " dynamical system. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 4 "The " }{TEXT 400 47 "compo sition of a function f with itself n times" }{TEXT -1 25 " is sometime s called the " }{TEXT 343 12 "n-th iterate" }{TEXT -1 33 " of f. In Ma ple it is denoted by " }{TEXT 401 4 "f@@n" }{TEXT -1 92 ". Recall that if f and g are functions, f@g is the composition of r and g. So, for \+ example, " }{TEXT 402 36 "(f@@3 )(x) = (f@f@f)(x) = f(f(f(x)))" } {TEXT -1 12 ". Note that " }{TEXT 403 13 "(f@@0)(x) = x" }{TEXT -1 26 ". The parentheses around " }{TEXT 433 7 "(f@@3) " }{TEXT -1 11 "are \+ needed." }{TEXT 435 1 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 " restart:\n" }}}{PARA 0 "" 0 "" {TEXT -1 155 "Here are some procedures that one may use to investigate the dynamics of a given function. Fi rst we define a function f that we want to experiment with." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "f: =x->(25*x) mod 197; \n\n" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 26 "\nThe following procedure, " }{TEXT 434 3 "it1" }{TEXT -1 38 ", will produce the list of the first " }{TEXT 344 1 "n" } {TEXT -1 28 " iterations of the function " }{TEXT 345 4 "func" }{TEXT -1 25 " starting with the value " }{TEXT 346 5 "start" }{TEXT -1 2 ": \n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 76 "it1:=proc(start,func, n)\nlocal i;\n[seq((func@@i)(start),i=0..n)];\nend proc:\n " }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 54 "We first see what the output is fo r undefined g and x:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "it1 (x,g,5);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 37 "Let's try the functio n defined above." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "it1(1,f ,5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "it1(1,f,100);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 14 "\nNote that in " }{TEXT 436 3 "it1 " }{TEXT -1 22 " each computation of " }{TEXT 404 7 "func@@n" }{TEXT -1 98 " starts from the beginning and requires n steps. A better way t o write the program is as follows:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 142 "it2:=proc(start,func,n)\n local i,x,SEQ;\n x:=start; \n SEQ:=x; \n for i from 1 to n do\n x:=func(x);\n SEQ:= SEQ, x;\n end do;\n [SEQ];\nend proc:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "it1(x,g,5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "it2( x,g,5);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "We can also write a re cursive version of this procedure:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 146 "it3:=proc(start,func,n)\n option remember:\n if n = \+ 0 then return [start]; fi;\n return [op(it3(start,func,n-1)),func(it3( start,func,n-1)[n])];\nend:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "it3(x,g,5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "it1(x, g,5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "it2(x,g,5);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 75 "Here's another way to time a proce dure--without getting the output however:" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 19 "time(it1(1,f,300));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "time(it2(1,f,300));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 17 "For small values " }{TEXT 347 3 "it3" }{TEXT -1 70 " is fast, b ut for really large values it will require too much memory." }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "ti me(it3(1,f,300));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {SECT 1 {PARA 3 "" 0 "" {TEXT -1 25 "The Famous 3x + 1 Problem" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT 356 94 "T his is a famous open problem in mathematics which involves iteration. \n\nConsider the function " }{TEXT -1 1 "f" }{TEXT 353 41 " defined on positive integers by the rule" }{TEXT -1 123 " \n\n \+ f(n) = n/2, if n is even, \n \+ f(n) = 3n+1, if n is odd. \n " }{TEXT 348 73 "\nIt appears that i f one starts with any integer n and repeatedly applies " }{TEXT -1 1 " f" }{TEXT 354 91 ", one always eventually reaches the number 1. This h as been verified for many values of n, " }{TEXT 405 40 "but has not ye t been proved or disproved" }{TEXT 406 22 ". It was verified for " } {TEXT -1 1 "n" }{TEXT 349 24 " up to approximately 2*" }{XPPEDIT 18 0 "10^16;" "6#*$\"#5\"#;" }{TEXT -1 0 "" }{TEXT 350 86 " in 1999 and a pparently the computer is still running. (Search the internet for th e " }{TEXT 407 12 "3x+1 problem" }{TEXT 351 8 " or the " }{TEXT 408 15 "collatz problem" }{TEXT 352 89 " (as it is sometimes called)--if y ou want more up-to-date information about the problem.)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 137 "For example, starti ng with n = 6 we have\n \n f(6)=3, f(3)=10, f(1 0)=5, f(5)=16, f(16)=8, f(8)=4, f(4)=2, f(2)=1. \n\n" }}{PARA 0 "" 0 " " {TEXT 355 47 "Thus in 8 steps we reach 1 if we start from 6. " }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 60 "Let's def ine a procedure to implement the \"3x + 1 function\"." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 91 "f:=proc(n)\n if n mod 2 = 0 then \n return n/2 ; \n else\n return 3*n+1; \n end if;\nend p roc:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 58 "Now let's iterate it star ting with a few different values:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "S:=[seq((f@@n)(3), n=1..40)]; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 116 "We use member as follows to determine whether or no t and if so what the first value of n is for which (f@@n)(3) = 1:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "member(1,S,'n'); \nn;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 198 "This shows that for n = 7 we get \+ 1. So 1 is reached starting from 3 in 7 steps. \n\nLet's write a proce dure that tells us how many steps are required to reach 1 starting wit h any positive integer n: (" }{TEXT 437 36 "We could use the above met hod using " }{TEXT 409 6 "member" }{TEXT 438 5 " and " }{TEXT 410 3 "s eq" }{TEXT 439 102 ", but that's not very efficient and anyhow we don' t know how far we might have to go before getting 1." }{TEXT -1 2 ")\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 155 "steps:=proc(n)\nlocal \+ x,i;\n if n = 1 then return 0; end if;\n x:=n;\n for i from 1 do\n \+ x:=f(x);\n if x = 1 then return i; end if;\n end do;\nend proc: \n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "steps(3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 67 "Let's see which number n <= 1000 takes th e largest number of steps:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "max(seq(steps(n),n=1..1000));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "member(178,[seq(steps(n),n=1..1000)],'n'); n;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 43 "Let's check that in fact steps(871 ) is 178:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "steps(871);" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 66 "Let's see what the largest numbe r reached is if we start with 871:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "L:=seq((f@@n)(871), n=1..178);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 7 "max(L);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 38 "Assignment 6 -- Due \+ Wednesday, March 6" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 " " 0 "" {TEXT 325 11 "Problem 1. " }{TEXT 368 214 "If n people (numbere d 1 to n) stand in a circle and someone starts going around the circle and eliminating every other person till only one person is left, the \+ number J(n) of the person left at the end is given by " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 153 " J(n) = 1 \+ if n = 1\n J(n) = 2*J(n/2) - 1 if n > 1 a nd n is even\n J(n) = 2*J((n-1)/2) + 1 if n > 1 and n is odd" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 12 "(i) Write a " }{TEXT 369 9 "recursive" }{TEXT 370 1 " " }{TEXT 371 9 "procedure " }{TEXT -1 150 " to compute J. [As a check the first 16 values (start ing with 1) of J(n) are 1,1,3,1,3,5,7,1,3,5,7,9,11,13,15,1]. \n(ii)Com pute the value of J(10000). " }}{PARA 0 "" 0 "" {TEXT -1 115 "(iii) Ca n you explain why this is so much faster than our recursive procedure \+ to compute the n-th Fibonacci number?" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 1 "[" }{TEXT 375 6 "Remark" } {TEXT -1 45 ". The problem above is a special case of the " }{TEXT 376 16 "Josephus Problem" }{TEXT -1 170 ". Instead of eliminating ever other person, one could eliminate every 3rd person, every 4th person, etc. For more on the history and generalizations of this problem see " }{TEXT 377 8 "Concrete" }{TEXT -1 1 " " }{TEXT 378 11 "Mathematics " }{TEXT -1 4 " -- " }{TEXT 379 33 "A Foundation for Computer Science " }{TEXT -1 149 ", by Graham, Knuth and Patashnik, Chapter 1. You will also find a number of webpages and mathematics papers devoted to this problem if you search on " }{TEXT 380 16 "Josephus Problem" }{TEXT -1 28 " via a search engine or via " }{TEXT 382 10 "MathSciNet" } {TEXT -1 13 " -- click on " }{TEXT 381 30 "Interesting Mathematical Li nks" }{TEXT -1 92 " at the bottom of the USF Mathematics Department's \+ home page -- from a USF computer--to use " }{TEXT 411 10 "MathSciNet" }{TEXT -1 2 ".]" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 326 11 "Problem 2. " }{TEXT -1 37 "Write a procedure using \+ the variable " }{TEXT 329 4 "args" }{TEXT -1 57 " that will take an un specified finite number of numbers, " }{TEXT 372 35 "delete the smalle st and the largest" }{TEXT -1 2 ", " }{TEXT 373 62 "and return the ave rage of the rest as a floating point number." }{TEXT -1 264 " If there are fewer than 3 arguments have an error message say: \"There are no t enough arguments. There should be at least three.\" \n\nYou should h ave no input parameters in the definition of the procedure. You may wr ite it directly or you may use the Maple command " }{TEXT 327 5 "sort \+ " }{TEXT -1 30 "as a part of your program. Do " }{TEXT 328 6 "?sort " }{TEXT -1 11 "to see how " }{TEXT 330 4 "sort" }{TEXT -1 171 " works. \+ Test your procedure with the each of following argument sequences: \n \n 50,40,40, 40, 40, 10\n\n 1,2\n\n seq(100 - i, i = 1..100)\n\n seq(modp(n,111), n=1..1000);" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT 359 9 "Problem 3" }{TEXT -1 2 ". " }{TEXT 357 8 "Friendly" }{TEXT -1 288 " numbers are positive integers which end up \+ at 1 under iteration of the \"sum of squares of digits map\". That is, if one defines f(x) to be the sum of the squares of the decimal digit s of the positive integer x, then x is friendly if for some positiv e integer n we have (f@@n)(x) = 1. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 13 "For example, " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 12 "f(7) = 49, " }}{PARA 0 "" 0 " " {TEXT -1 21 "f(49) = 4^2+9^2=97, " }}{PARA 0 "" 0 "" {TEXT -1 20 "f (97)=9^2+7^2=130, " }}{PARA 0 "" 0 "" {TEXT -1 26 "f(130) = 1^2+3^2+0 ^2 = 10," }}{PARA 0 "" 0 "" {TEXT -1 21 "f(10) = 1^2+0^2 = 1. " }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 17 "So 7 is f riendly." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 36 "The first few friendly numbers are \n" }}{PARA 0 "" 0 "" {TEXT -1 61 "1,7,10,13,19,23,28,31,32,44,49,68,70,79,82,86,91,94,97,100. \n" }} {PARA 0 "" 0 "" {TEXT -1 89 "Write a procedure that will declare a po sitive integer x to be friendly (i.e., returns " }{TEXT 440 4 "true" }{TEXT -1 50 ") if the n-th iterate of f starting with x gives 1" } {TEXT 358 10 " for some " }{XPPEDIT 18 0 "n <= 20;" "6#1%\"nG\"#?" } {TEXT -1 16 " --else returns " }{TEXT 441 5 "false" }{TEXT -1 67 ". Fi nd the first 50 friendly numbers. Print them out in a sequence." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 363 5 "Hints" } {TEXT -1 1 ":" }{TEXT 361 2 " " }{TEXT -1 23 "A procedure similar to \+ " }{TEXT 362 5 "steps" }{TEXT -1 77 " in the above lecture will be muc h faster than one using (f@@n)(x). Note that" }{TEXT 360 20 " convert( x,base,10) " }{TEXT -1 138 "will give you the decimal digits of x in a list. It should help if you first write a procedure to compute f(x) f or any positive integer x." }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" } {TEXT 367 11 "Problem 4. " }{TEXT -1 165 "Show that if you increase th e upper bound for n in Problem 3 from 20 to a higher value you will n ot obtain any additional friendly numbers in the above list of 50? " } {TEXT 374 4 "Hint" }{TEXT -1 77 ": The 50th friendly number is 320. Sh ow that if n < 320 then in the sequence " }}{PARA 0 "" 0 "" {TEXT -1 49 "\n X[n]:= n, f(n), (f@@2)(n), . . ., (f@@20)(n)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 487 "if 1 does not appea r then the sequence is ultimately periodic, that is, it starts repeati ng itself. An easy way to establish this is to show that nops([X[n]]) \+ > nops(\{X[n]\}), that is there are more elements in the list [X[n]] t han in the set \{X[n]\}. So some element must be repeated. Once an ele ment is repeated the sequence will start repeating and if one hasn't b een reached it will never be reached. [Remark: There are more sophisti cated ways to detect periodicity, but this will do.]" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 3 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 1 "." }}}{EXCHG {PARA 18 "" 0 "" {TEXT -1 0 "" }}{PARA 19 "" 0 "" {TEXT -1 0 "" }}{PARA 19 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{MARK "12 4 8 0" 4 }{VIEWOPTS 0 0 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 1 1 2 33 1 1 }