Error, (in f) too many levels of recursion - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Error, (in f) too many levels of recursion

Error, too many levels of recursion

Error, (in ...) too many levels of recursion

 Description 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.

Examples

 >
 ${f}{:=}{n}{→}{n}{f}\left({n}{-}{1}\right)$ (2.1)
 > $f\mathit{(}\mathit{3}\mathit{)}\mathit{;}$

Solution 1: Set a base case.

 > $\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}f(0)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}:=\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}1;$
 ${f}\left({0}\right){:=}{1}$ (2.2)
 > $f(3);$
 ${6}$ (2.3)

Solution 2: The base case is given within the procedure definition. Here, procname is used to implement the recursive call.

 >
 ${g}{:=}{\mathbf{proc}}\left({n}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{n}{=}{0}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{else}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{n}{*}{\mathrm{procname}}\left({n}{-}{1}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2.4)
 > $g(5);$
 ${120}$ (2.5)
 > 

 See Also