       memoizing function again

• To: mathgroup at smc.vnet.net
• Subject: [mg32495] memoizing function again
• From: Erich Neuwirth <erich.neuwirth at univie.ac.at>
• Date: Wed, 23 Jan 2002 01:00:22 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```i have the following function

f[x_] /; x <= 2 := f[x] = 1
f[x_] /; x > 2 := f[x] = f[x - 1] + f[x - 2]

it remembers what it already calculated
i want to be able to throw away rules with values
between calculations

In=DownValues[f]
produces

Out={HoldPattern[f[x_]/;x\[LessEqual]2]\[RuleDelayed](f[x]=1),
HoldPattern[f[x_]/;x>2]\[RuleDelayed](f[x]=f[x-1]+f[x-2])}

after f

we have

In:=
DownValues[f]

Out=
{HoldPattern[f]\[RuleDelayed]1,HoldPattern[f]\[RuleDelayed]1,
HoldPattern[f]\[RuleDelayed]2,HoldPattern[f]\[RuleDelayed]3,
HoldPattern[f[x_]/;x\[LessEqual]2]\[RuleDelayed](f[x]=1),
HoldPattern[f[x_]/;x>2]\[RuleDelayed](f[x]=f[x-1]+f[x-2])}

\[RuleDelayed] is ascii for :>, i think

so

DownValues[f] = Take[DownValues[f], -2]

removes all the rules giving calculated values
but i would like to throw away the rules following the pattern

HoldPattern[f[x_Integer]:>y_Integer

but i have not been able wo write an expression using Cases and a
pattern
which gets rid of the rules i want to get rid of

--
Erich Neuwirth, Computer Supported Didactics Working Group