Re: memoizing function again
- To: mathgroup at smc.vnet.net
- Subject: [mg32505] Re: memoizing function again
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 24 Jan 2002 05:20:58 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <a2lkn5$htb$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
ClearConstantArg[f_Symbol] :=
DownValues[f] =
DownValues[f] /. (Verbatim[HoldPattern][f[_Integer]] :> _) :>
Sequence[]
will do it. For what do wish to use Cases[] ?
Regards
Jens
Erich Neuwirth wrote:
>
> 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[3]=DownValues[f]
> produces
>
> Out[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])}
>
> after f[4]
>
> we have
>
> In[5]:=
> DownValues[f]
>
> Out[5]=
> {HoldPattern[f[1]]\[RuleDelayed]1,HoldPattern[f[2]]\[RuleDelayed]1,
> HoldPattern[f[3]]\[RuleDelayed]2,HoldPattern[f[4]]\[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
> Visit our SunSITE at http://sunsite.univie.ac.at
> Phone: +43-1-4277-38624 Fax: +43-1-4277-9386