Re: Finding length in recursive definition?
- To: mathgroup at smc.vnet.net
- Subject: [mg60984] Re: Finding length in recursive definition?
- From: "Jose Reckoner" <reckoner at gmail.com>
- Date: Thu, 6 Oct 2005 04:08:25 -0400 (EDT)
- References: <email@example.com><firstname.lastname@example.org>
- Sender: owner-wri-mathgroup at wolfram.com
Please explain the blanks in HoldPattern[_[_[f[nn_Integer]], _]]. I don't understand what's going on here. Thanks! Jose albert wrote: > Jose Reckoner wrote: > > > I have something like: > > f = 1 > > f = 3 > > f[n_] := f[n] = f[n - 1] + f[n - 2] > > > > and in the course of work, f[n] gets evaluated an unknown number of > > times resulting in > > > >>> ?f > > f = 1 > > f = 3 > > f = 4 > > f[n_] := f[n] = f[n - 1] + f[n - 2] > > > > I want to figure out the greatest integer n such that f[n] has already > > been computed and is stored. In this case, it is 3. > > > > How can I do this? > > I think this will do what you want: > > Max[Cases[DownValues[f], HoldPattern[_[_[f[nn_Integer]], _]] :> nn]] > > all patterns for f are stored in DownValues[f], the Cases extracts all > patterns where the argument of f is an integer and replaces them by this > integer... > > Albert