       Re: Finding length in recursive definition?

• To: mathgroup at smc.vnet.net
• Subject: [mg60887] Re: [mg60877] Finding length in recursive definition?
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Sun, 2 Oct 2005 01:54:39 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Clear[f]

f=1;
f=3;
f[n_]:=f[n]=f[n-1]+f[n-2];

f

4

Max[Cases[ReleaseHold[(First/@DownValues[f])/.
HoldPattern[f[n_]]:>n],_Integer]]

3

or more simply

Length[DownValues[f]]-1

3

Bob Hanlon

>
> From: "Jose  Reckoner" <reckoner at gmail.com>
To: mathgroup at smc.vnet.net
> Date: 2005/10/01 Sat AM 02:55:52 EDT
> Subject: [mg60887] [mg60877] Finding length in recursive definition?
>
> 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?
>
> Thanks!
>
> Jose
>
>

```

• Prev by Date: Re: Finding length in recursive definition?
• Next by Date: Re: Rounding?
• Previous by thread: Re: Finding length in recursive definition?
• Next by thread: Re: Finding length in recursive definition?