{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 "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 }{C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 }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 "Times" 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 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT -1 9 "Lecture 5" }}{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 167 ") that represent the input to the proce dure. As we shall see later the type of a parameter P may be declared by replacing a parameter by an expression of the form P::" }{TEXT 268 4 "type" }{TEXT -1 33 ", for example, we could have P1::" }{TEXT 265 7 "integer" }{TEXT -1 6 ", P2::" }{TEXT 266 6 "matrix" }{TEXT -1 6 ", P3::" }{TEXT 267 7 "numeric" }{TEXT -1 50 ", etc...\n\nL1, L2, .. ., Lu represent a sequence of " }{TEXT 261 5 "local" }{TEXT -1 53 " va riables.\n\nG1, G2, ..., Gv represent a sequence of " }{TEXT 262 6 "gl obal" }{TEXT -1 58 " variables.\n\nO1, O2, . . . , Ow represent option s such as " }{TEXT 336 6 "trace " }{TEXT -1 3 "and" }{TEXT 337 10 " re member." }{TEXT -1 32 " We will discuss these below.\n" }}{PARA 0 " " 0 "" {TEXT -1 6 "After " }{TEXT 263 11 "description" }{TEXT -1 150 " you may write anything enclosed in \" \". This is to help document \+ what the purpose of the procedure is. \n\nS1; S2; ... , Sm represents \+ a sequence of " }{TEXT 264 10 "statements" }{TEXT -1 67 " which tell t he procedure what to do. These may or may not contain " }{TEXT 387 6 " return" }{TEXT -1 125 " statements which provide the output of the pro cedure. \n\nNote that the last thing to be computed is returned unless previous " }{TEXT 338 6 "return" }{TEXT -1 175 " statements are execu ted. So if the output is computed on the last line before end; then th at is returned.\n\nAs we have seen a procedure need not contain all of these elements." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 22 "For more details see ?" }{TEXT 339 9 "procedure" }{TEXT -1 4 ", ?" }{TEXT 340 7 "options" }{TEXT -1 4 ", ?" }{TEXT 341 10 "p arameters" }{TEXT -1 6 ", etc." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 42 "Example of a Procedure (Member with error)" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 48 "We have se en that Maple has a built-in program " }{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 and call it " }{TEXT 277 6 "Member" } {TEXT -1 41 " to distinguish it from Maple's built-in " }{TEXT 278 6 " member" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 247 " Member:=proc(x::integer, L::list)\n local i;\n description \"this pr ocedure 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; end if;\n end do;\n false;\nend proc:\n" }}}{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 319 "Member:=proc(x,Y)\nloc al i;\ndescription \"this procedure returns true if x is anything, Y i s 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 "" {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 \+ which \"calls itself\". " }{TEXT 342 85 "This means that the name of t he procedure is used in the definition of the procedure." }{TEXT -1 25 " Here's an example: The " }{TEXT 314 17 "Fibonacci numbers" } {TEXT -1 2 ": " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 149 "The Fibonacci numbers form a sequence 0, 1, 2, 3, 5, 8, 13, ... The n-th element is the sum of the (n-2)-nd and (n-1)-st ele ments in the sequence. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 73 "Our procedure will give the n-th Fibonacci number. W e call the procedure " }{TEXT 286 4 "fib1" }{TEXT -1 12 ". Note that \+ " }{TEXT 287 4 "fib1" }{TEXT -1 36 " is used twice in the definition o f " }{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 t hen \n return 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 from 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 compute " }{TEXT 293 4 "fib1" }{TEXT -1 6 "(20), " } {TEXT 294 4 "fib1" }{TEXT -1 20 " must first compute " }{TEXT 295 4 "f ib1" }{TEXT -1 9 "(19) 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 60 "(16), and so forth. 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 190 " the procedure remembers the values already computed and does \+ not have to recompute them. 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)\noption remember:\nif n = 0 or n = 1 then \n re turn n; \nend if;\nfib2(n-2) + fib2(n-1);\nend proc:\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 284 28 "Comparison of running times." }{TEXT -1 11 " Note that " }{TEXT 279 6 "time()" }{TEXT -1 166 "; gives the tot al CPU time used since the start of the Maple session your computer in seconds. So the following method gives the time used for the given co mputation:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 60 "starttime:=time():\nfib1(25);\nelapsedtime:=time()- starttime;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "starttime:= time():\nfib2(25);\nelapsedtime:=time()-starttime;\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 65 " Here's how we find the values stored in the re member table. For " }{TEXT 388 4 "fib1" }{TEXT -1 31 " there is no rem ember table: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "op(4,eva l(fib1));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 4 "But " }{TEXT 389 4 "f ib2" }{TEXT -1 46 " has a large remember table after calculating " } {TEXT 390 8 "fib2(25)" }{TEXT -1 1 ":" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "op(4,eval(fib2)); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "starttime:=time():\nfib2(500);\nelapsedtime:=time()-s tarttime;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 17 "Now the value of " } {TEXT 391 9 "fib2(500)" }{TEXT -1 95 " is in the remember table so it \+ doesn't have to be recomputed. Thus it is returned immediately:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "starttime:=time():\nfib2(500 );\nelapsedtime:=time()-starttime;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "op(4,eval(fib2))[500];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 10 "Note that " }{TEXT 302 4 "fib2" }{TEXT -1 26 "(500) takes 0 seconds 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) and just looks it up in its " }{TEXT 280 16 "remember table. " } {TEXT -1 86 "Such tables can clog up one's memory so to clear it out w hen no longer needed use the " }{TEXT 281 6 "forget" }{TEXT -1 20 " co mmand as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "forget (fib2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "See that the remember \+ table 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 "Recursive procedures can be written as non-recursive procedure s usually with some more effort. For example, here is a way to genera te the Fibonacci numbers by a procedure which doesn't call itself. It \+ is a little harder to understand, but requires much less memory that \+ " }{TEXT 392 4 "fib2" }{TEXT -1 1 ":" }}}{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;\nminus1:=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 "" {MPLTEXT 1 0 63 "starttime:=time():\nfib3(1000);\nelapsedtime:=time() \+ - starttime;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "starttime:= time():\nfib1(20);\nelapsedtime:=time() - starttime;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "starttime:=time():\nfib2(1000);\nelapsedt ime:=time() - starttime;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 " " }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 22 "Remember Table for sin" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 185 "This command will give slightly d ifferent output for Maple V and Maple 6. In particular in Maple 6 it d oes not contain the value for sin(Pi/12). But it may be obtained with \+ the command " }{TEXT 333 27 "convert(sin(Pi/12),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 rational 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 46 "We could add it to the remember table for sin:" }}}{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 i n 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 "" {MPLTEXT 1 0 8 "restart:" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 204 "ADD:=proc(f::procedure, n:: nonnegint)\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;\ndescri ption `this computes the product f(0)*f(1)*f(2)*...*f(n)`;\nif n = 0 t hen \n return f(0); \nelse \n return MUL(f,n-1)*f(n); \nend if; \n end 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 0 "" 0 "" {TEXT -1 77 "We can make Maple think g is a procedure if we execute th e 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 "Bo th procedures can also be written with a do loop as we have seen befor e. Actually Maple has built-in procedures " }{TEXT 393 3 "sum" }{TEXT -1 2 ", " }{TEXT 394 3 "add" }{TEXT -1 2 ", " }{TEXT 395 7 "product" } {TEXT -1 5 " and " }{TEXT 396 3 "mul" }{TEXT -1 181 " which do more or less what these procedures do (and are more efficiently) as we will discuss in the next lecture. These two procedures were just for the \+ purpose of 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-architecture\". You can access the source code to over " }{TEXT 256 3 "95%" }{TEXT -1 173 " of the math routines available. This allo ws you to see what's going on and in some cases you may want to change procedures to make them more suitable for your needs. The " }{TEXT 310 10 "interface " }{TEXT -1 68 "command helps one view code for Mapl e procedures. You first must do:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "interface(verboseproc=2);" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 30 "Now we view the code for the " }{TEXT 307 7 "isprime" }{TEXT -1 70 " command, which tells us when an intege r is probably prime. Applying " }{TEXT 305 5 "eval " }{TEXT -1 4 " or \+ " }{TEXT 306 6 "print " }{TEXT -1 67 "returns the source code (i.e, ho w the given procedure is written). " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "print(isprime);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 104 "To cut an d paste part of the output of eval(isprime) use the command lprint(eva l(isprime)); as follows; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "lprint(eval(isprime));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "ifactor(2305567963945518424753102147331756070);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 94 "Notice that this procedure used the procedure i gcd as well as other procedures. The procedure " }{TEXT 308 4 "igcd" } {TEXT -1 3 " is" }}{PARA 0 "" 0 "" {TEXT -1 97 "\"builtin\" and not av ailable--as you see if you try the following command. A few of the mor e basic" }}{PARA 0 "" 0 "" {TEXT -1 18 "commands are like " }{TEXT 309 4 "igcd" }{TEXT -1 44 " and the code is not available to the user. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "eval(igcd);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "eval(ln);" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 65 "When done looking at the source code it is a good id ea to reset " }{TEXT 311 11 "verboseproc" }{TEXT -1 29 " to the defau lt output level." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "interface(verbo seproc=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 312 14 "opti on trace: " }{TEXT -1 149 "This option causes maple to print out more \+ details about the behaviour of the procedure and may be useful during debugging. 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 to n do\nif i > 2 then S:=S+i; end if;\nend do;\nS;\nend pro c:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "test(4);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 31 "Remove or comment out the line " }{TEXT 313 12 "option trace" }{TEXT -1 55 "; and reinter the procedure to get back in normal mode." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 117 "t est:=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 called " }{TEXT 321 10 "parameters" }{TEXT -1 4 " or " } {TEXT 322 9 "arguments" }{TEXT -1 56 ". For example, in the procedure \+ whose definition begins " }{TEXT 315 19 "f:=proc(A,s,t,n), " }{TEXT -1 28 "A, s,t and n are called the " }{TEXT 397 9 "arguments" }{TEXT -1 4 " or " }{TEXT 398 10 "parameters" }{TEXT -1 45 " of the procedure . By using the special name " }{TEXT 316 5 "args " }{TEXT -1 4 "and " }{TEXT 317 5 "nargs" }{TEXT -1 65 " one need not declare any parameter s when defining a procedure. " }{TEXT 318 8 "args[1] " }{TEXT -1 23 " is the first argument, " }{TEXT 319 8 "args[2] " }{TEXT -1 57 "is the \+ second argument, etc., The number of arguments is " }{TEXT 320 6 "narg s." }{TEXT -1 25 " One advantage in using " }{TEXT 385 4 "args" } {TEXT -1 5 " and " }{TEXT 386 5 "nargs" }{TEXT -1 88 " is that we don' t have to specify in advance the number of arguments. Here's an exampl e:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 53 "In this procedure we use the builtin Maple procedure " }{TEXT 323 3 "add" }{TEXT 399 2 ".\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 242 "Avg:=proc()\nlocal i,A,N;\ndescription \"this computes the aver age of the arguments--all assumed to be numbers\";\nif nargs = 0 then \+ \n error \"there are no numbers to average\"; \nend if;\nA:=add(args [i],i=1..nargs);\nreturn 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 334 3 "max" }{TEXT -1 94 " to do this, but it is useful to know how it is constructed for other purposes. Our procedure " }{TEXT 401 3 "Max " }{TEXT -1 27 " returns the largest entry " }{TEXT 400 3 "and" } {TEXT -1 106 " the index of the first occurrence of this entry. Our pr ocedure does a little more than Maple's procedure " }{TEXT 335 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 pr ocedure returns the list [M,w] where M is the largest element in the i nput 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 23 "Max(10, 110 , 445, 78 );" }}}{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 324 16 "global variable s" }{TEXT -1 52 " and some strange things that can happen when using \+ " }{TEXT 325 16 "local variables." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "x:=10;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 56 "f :=proc(s)\nlocal b;\nglobal x;\nx:=s*x;\nb:=x^2;\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 procedur e 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 48 "g:=proc(s)\nlocal b,x;\nx: =s*x;\nb:=x^2;\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 326 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 0 "" 0 "" {TEXT -1 173 "It appears that both w and z are \+ equal to x. But w is equal to the global variable x\nand z is equal t o the local variable created inside the procedure h. So maple consider s" }}{PARA 0 "" 0 "" {TEXT -1 57 "them to be different even though the y both look the same;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "z;w ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "\{z,w\};" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "\{x,x\};" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 11 "evalb(x=z);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "\{x,w\};" }}}{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 automatically simpl ifies 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 "" {MPLTEXT 1 0 8 "\{z,w,r\};" }}}{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 g eneral " }}{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 ", . . ., i s called " }{TEXT 366 13 "the orbit of " }{XPPEDIT 367 0 "x[0];" "6#&% \"xG6#\"\"!" }{TEXT 368 35 " under the action of the function f" } {TEXT -1 33 ". This process is also called " }{TEXT 343 40 "iterati on of the function f starting at " }{XPPEDIT 18 0 "x[0];" "6#&%\"xG6# \"\"!" }{TEXT -1 23 " and is an example of a" }{TEXT 344 19 " dynamica l system. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 4 "The " }{TEXT 402 47 "composition of a function f with itself n t imes" }{TEXT -1 25 " is sometimes called the " }{TEXT 345 12 "n-th ite rate" }{TEXT -1 33 " of f. In Maple it is denoted by " }{TEXT 403 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 404 36 "(f@@3 )(x) = (f@f@f)(x) = f(f(f(x)))" }{TEXT -1 12 ". Note that " }{TEXT 405 13 "( f@@0)(x) = x" }{TEXT -1 3 ". \n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "restart:\n" }}}{PARA 0 "" 0 "" {TEXT -1 155 "Here are some pro cedures that one may use to investigate the dynamics of a given functi on. First 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 60 "\nThe following procedure will produce the list of t he first " }{TEXT 346 1 "n" }{TEXT -1 28 " iterations of the function \+ " }{TEXT 347 4 "func" }{TEXT -1 25 " starting with the value " }{TEXT 348 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 se e what the output is for 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 function 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 32 "\nNote t hat each computation of " }{TEXT 406 7 "func@@n" }{TEXT -1 98 " start s from the beginning and requires n steps. A better way to write the p rogram 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 recursive vers ion 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 procedure--w ithout 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 349 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 358 94 "T his is a famous open problem in mathematics which involves iteration. \n\nConsider the function " }{TEXT -1 1 "f" }{TEXT 355 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 350 73 "\nIt appears that i f one starts with any integer n and repeatedly applies " }{TEXT -1 1 " f" }{TEXT 356 91 ", one always eventually reaches the number 1. This h as been verified for many values of n, " }{TEXT 407 40 "but has not ye t been proved or disproved" }{TEXT 408 22 ". It was verified for " } {TEXT -1 1 "n" }{TEXT 351 24 " up to approximately 2*" }{XPPEDIT 18 0 "10^16;" "6#*$\"#5\"#;" }{TEXT -1 0 "" }{TEXT 352 86 " in 1999 and a pparently the computer is still running. (Search the internet for th e " }{TEXT 409 12 "3x+1 problem" }{TEXT 353 8 " or the " }{TEXT 410 15 "collatz problem" }{TEXT 354 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 357 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 "" {MPLTEXT 1 0 20 "member(1,S,'k'); \nk;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 234 "This shows that for n = 7 we get 1. So 1 is reached s tarting from 3 in 7 steps. \n\nLet's write a procedure that tells us h ow many steps are required to reach 1 starting with any positive integ er n: (We could use the above method using " }{TEXT 411 6 "member" } {TEXT -1 5 " and " }{TEXT 412 3 "seq" }{TEXT -1 104 ", but that's not \+ very efficient and anyhow we don't know how far we might have to go be fore getting 1.)\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 155 "step s:=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 "step s(3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 67 "Let's see which number n <= 1000 takes the 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)],'k'); k ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "steps(871);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "Let's see the largest number reach ed 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 1 {PARA 3 "" 0 "" {TEXT -1 31 "Assignment 5 -- Due Next Mo nday" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT 327 11 "Problem 1. " }{TEXT 370 213 "If n people (numbered 1 to n) sta nd in a circle and someone starts going around the circle and eliminat ing 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 and 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 8 "Write a " }{TEXT 371 9 " recursive" }{TEXT 372 1 " " }{TEXT 373 9 "procedure" }{TEXT -1 235 " t o compute J. [As a check the first 16 values of J(n) are 1,1,3,1,3,5,7 ,1,3,5,7,9,11,13,15,1]. Compute the value of J(1000). Can 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 377 6 "Remark" }{TEXT -1 45 ". T he problem above is a special case of the " }{TEXT 378 16 "Josephus Pr oblem" }{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 379 8 "Co ncrete" }{TEXT -1 1 " " }{TEXT 380 11 "Mathematics" }{TEXT -1 4 " -- \+ " }{TEXT 381 33 "A Foundation for Computer Science" }{TEXT -1 149 ", b y Graham, Knuth and Patashnik, Chapter 1. You will also find a number \+ of webpages and mathematics papers devoted to this problem if you sear ch on " }{TEXT 382 16 "Josephus Problem" }{TEXT -1 28 " via a search e ngine or via " }{TEXT 384 10 "MathSciNet" }{TEXT -1 13 " -- click on \+ " }{TEXT 383 30 "Interesting Mathematical Links" }{TEXT -1 92 " at the bottom of the USF Mathematics Department's home page -- from a USF co mputer--to use " }{TEXT 413 10 "MathSciNet" }{TEXT -1 2 ".]" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 328 11 "P roblem 2. " }{TEXT -1 37 "Write a procedure using the variable " } {TEXT 331 4 "args" }{TEXT -1 57 " that will take an unspecified finite number of numbers, " }{TEXT 374 35 "delete the smallest and the large st" }{TEXT -1 2 ", " }{TEXT 375 62 "and return the average 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 not enough argumen ts. There should be at least three.\" \n\nYou should have no input par ameters in the definition of the procedure. You may write it directly \+ or you may use the Maple command " }{TEXT 329 5 "sort " }{TEXT -1 30 " as a part of your program. Do " }{TEXT 330 6 "?sort " }{TEXT -1 11 "to see how " }{TEXT 332 4 "sort" }{TEXT -1 138 " works. Test your proced ure with the each of following argument sequences: \n\n 50,40,40, 4 0, 40, 10\n\n 1,2\n\n seq(100 - i, i = 1..100)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 361 9 "Problem 3" }{TEXT -1 2 ". " }{TEXT 359 8 "Friendly" }{TEXT -1 288 " numbers are positive intege rs 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 t he decimal digits of the positive integer x, then x is friendly if \+ for some positive 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 20 "f(4) = 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(13 0) = 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 friendly." }}{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,10 0. \n" }}{PARA 0 "" 0 "" {TEXT -1 142 "Write a procedure that will de clare a positive integer x to be friendly (i.e., return true) if the \+ n-th iterate of f starting with x gives 1" }{TEXT 360 17 " for some n \+ <= 20" }{TEXT -1 87 " --else return false. Find the first 50 friendly \+ numbers. Print them out in a sequence." }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT 365 5 "Hints" }{TEXT -1 1 ":" }{TEXT 363 2 " " }{TEXT -1 23 "A procedure similar to " }{TEXT 364 5 "steps" } {TEXT -1 77 " in the above lecture will be much faster than one using \+ (f@@n)(x). Note that" }{TEXT 362 20 " convert(x,base,10) " }{TEXT -1 138 "will give you the decimal digits of x in a list. It should help i f you first write a procedure to compute f(x) for any positive integer x." }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 369 11 "Problem 4. " } {TEXT -1 165 "Show that if you increase the upper bound for n in Probl em 3 from 20 to a higher value you will not obtain any additional fri endly numbers in the above list of 50? " }{TEXT 376 4 "Hint" }{TEXT -1 77 ": The 50th friendly number is 320. Show 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 469 "if 1 does not appear then the sequence is ulti mately periodic, that is, it starts repeating itself. An easy way to e stablish this is to show that nops([X[n]]) > nops(\{X[n]\}), that is t here are more elements in the list [X[n]] than in the set \{X[n]\}. So some element must be repeated. Once an element is repeated the sequen ce will start repeating and if one hasn't been reached it will never b e reached. [Remark: There are more sophisticated ways to detect period icity.]" }}}{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 "1" 0 } {VIEWOPTS 0 0 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }