Re: memoizing function again
- To: mathgroup at smc.vnet.net
- Subject: [mg32513] Re: memoizing function again
- From: Erich Neuwirth <erich.neuwirth at univie.ac.at>
- Date: Fri, 25 Jan 2002 02:57:41 -0500 (EST)
- References: <a2lkn5$htb$1@smc.vnet.net> <a2ong2$5uo$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
i wanted to use cases because i did not know this clever trick with substituting something empty and i wante to describe the rules i want to keep. Jens-Peer Kuska wrote: > > 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 -- 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