Re: why do recursive function calculations take so long in Mathematica?
- To: mathgroup at smc.vnet.net
- Subject: [mg43605] Re: why do recursive function calculations take so long in Mathematica?
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Tue, 23 Sep 2003 04:01:53 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <bkhbk7$7lr$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi, dr[0, 0] := 0; dr[n_, n_] := 0; dr[n_, 0] := 1; dr[n_, k_] := dr[n, k] = dr[n, k - 1] + dr[n - 1, k]; should be faster. Regards Jens G Feigin wrote: > > I defined the following simple recursive function: > > dr[0,0] := 0; dr[n_,n_]:= 0; > dr[n_,0]:=1;dr[n_,k_]:=dr[n,k-1]+dr[n-1,k]; > > To evaluate dr[16,15] takes about 5 minutes on a Pentium class > machine, an absurdly long time. Why? And what can I do to speed > things up? By the way, > if I perform the recursion in an Excel spreadsheet on the same > machine, the calculation time is practically instantaneous. > > Please reply by email.