Error, (in PatternMatching:-AlgStruct:-Match) 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 PatternMatching:-AlgStruct:-Match) too many levels of recursion

Error, too many levels of recursion

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

 

Description

Examples

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  nnfn1;

f:=n→nfn1

(2.1)

f(3);

Error, (in f) too many levels of recursion

Solution 1: Set a base case.

f(0):=1;

f0:=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  procn if n = 0 then return 1;else return n*procnamen1; end if; end proc;

g:=procnifn=0thenreturn1elsereturnn*procnamen1end ifend proc

(2.4)

g(5);

120

(2.5)

See Also

procedure

procname