Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

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[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


  • Prev by Date: Re: confusion with triple integral...
  • Next by Date: Re: Translations
  • Previous by thread: a difficult Bessel intergral
  • Next by thread: Re: memoizing function again