{VERSION 4 0 "IBM INTEL NT" "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 "Hyperlink" -1 17 "" 0 1 0 128 128 1 0 0 1 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 "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" 0 21 "" 0 1 0 0 0 1 0 0 0 0 2 0 0 0 0 1 }{CSTYLE "Help Head ing" -1 26 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{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 "Error" -1 8 1 {CSTYLE "" -1 -1 "Courier " 1 10 255 0 255 1 2 2 2 2 2 1 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 } {PSTYLE "Maple Output" -1 11 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 3 0 0 0 0 1 0 1 0 2 2 0 1 }} {SECT 0 {SECT 0 {PARA 0 "" 0 "" {TEXT 26 6 "Error:" }{TEXT -1 30 " to o many levels of recursion" }}{PARA 0 "" 0 "" {TEXT -1 515 "It often h appens in Maple that one procedure will call a second procedure, which in turn calls a third, and so on. Each time a procedure calls anothe r, some information must be stored in an area of memory called the sta ck. This is removed when the called procedure returns. The stack has only a finite capacity, and when it is full this error message occurs . The size of the stack may vary depending on the platform, available memory in the computer, and whether or not you are using a student ed ition of Maple." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 101 "In many cases when the error message occurs, it is the r esult of an infinite recursion. For example:" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "f:= n -> f(n-1)^2 + 1 mod(n+2):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "f(2);" }}{PARA 8 "" 1 "" {TEXT -1 43 "Error, (in f) too many levels of recursion\n" }}}{PARA 0 "" 0 "" {TEXT -1 38 "What happens here is that to evaluate " }{MPLTEXT 0 21 4 "f(2)" }{TEXT -1 9 " we need " }{XPPEDIT 18 0 "f(1)" "6#-%\"fG6#\"\"\" " }{TEXT -1 31 ", and to evaluate that we need " }{XPPEDIT 18 0 "f(0) " "6#-%\"fG6#\"\"!" }{TEXT -1 221 ", and so on forever. No matter how much stack space we have, it will all fill up and result in an error \+ message. A cure for this problem, if we will only want to evaluate th e function on positive integers, is to assign " }{MPLTEXT 0 21 4 "f(0) " }{TEXT -1 46 ". Then the chain of evaluations, starting at " } {MPLTEXT 0 21 4 "f(n)" }{TEXT -1 26 " for any positive integer " } {MPLTEXT 0 21 1 "n" }{TEXT -1 15 ", will stop at " }{XPPEDIT 18 0 "f(0 )" "6#-%\"fG6#\"\"!" }{TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "f(0):= 0:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "f(10);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"&" }}}{PARA 0 "" 0 "" {TEXT -1 19 "However, if we try " }{MPLTEXT 0 21 4 "f(n)" }{TEXT -1 26 " for a sufficiently large " }{MPLTEXT 0 21 1 "n" }{TEXT -1 32 " we can still fill up the stack." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "f(10000);" }}{PARA 8 "" 1 "" {TEXT -1 43 "Error, (in f) too many \+ levels of recursion\n" }}}{PARA 0 "" 0 "" {TEXT -1 78 "If you really n eed to perform such a calculation, it may be better to rewrite " } {MPLTEXT 0 21 1 "f" }{TEXT -1 51 " as an iterative, rather than recurs ive, procedure:" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 102 "f:= proc (n)\nlocal i, r;\n r:= 0;\n for i from 1 to n do \n r:= r^2 + 1 m od (i+2)\n od;\n r;\nend: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "f(10000);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%Eg" }}}}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 10 "See also: " }{TEXT -1 1 " " }{HYPERLNK 17 "efficiency" 2 "efficiency" "" }}}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 22 "Maple Advisor Database" }{TEXT -1 18 " R. Israel, 1997" }}} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{MARK "1 0 0" 4 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }