Error, too many levels of recursion
Error, (in ...) too many levels of recursion
Description
Examples
The too many levels of recursion error occurs when a statement or routine calls itself too many times. For example, a procedure may split a problem, then call itself on a subproblem. Those calls may then split the subproblems still further, and so on. This may cause Maple to run out of memory (stack limit exceeded) or to exceed Maple's internal limit for recursive calls.
f ≔ n→n⋅fn−1;
f:=n→n⁢f⁡n−1
f(3);
Error, (in f) too many levels of recursion
Solution 1: Set a base case.
f(0):=1;
f⁡0:=1
6
Solution 2: The base case is given within the procedure definition. Here, procname is used to implement the recursive call.
g ≔ procn if n = 0 then return 1;else return n*procnamen−1; end if; end proc;
g:=procnifn=0thenreturn1elsereturnn*procname⁡n − 1end ifend proc
g(5);
120
See Also
procedure
procname
Download Help Document