Re: recursive relation problem ?

*To*: mathgroup at smc.vnet.net*Subject*: [mg13691] Re: recursive relation problem ?*From*: bruck at pacificnet.net (Ronald Bruck)*Date*: Sat, 15 Aug 1998 04:39:22 -0400*Organization*: University of Southern California*References*: <6qp2vd$aiu@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

In article <6qp2vd$aiu at smc.vnet.net>, cplai at geocities.com wrote: > Dear all, > > I am studying data structure, and always encounter recursive relation > equations. How do I use mathematica to give general solution of > recursive relation. > > For example: f(0)=1; f(1)=1; f(x)=x*f(x-1); Write: Clear[f] (* ALWAYS do this, for safety's sake *) f[0] = 1; f[1] = 1; f[x_] := f[x] = x f[x-1] Note the delayed-rule definition followed by the "f[x] ="; this is the way to tell Mathematica to keep the computed values for future reference. (Otherwise your function is going to be rather slow...) Furthermore, if you DON'T use this construction, and ask for f[257], Mathematica will exceed the 256 (default) levels of recursion, and stop. --Ron Bruck