0

Possible Duplicate:
Mathematica: How to clear the cache for a symbol, i.e. Unset pattern-free DownValues

This link shows a way to speed up recursive definitions in Mathematica.

f[0]=f[1]=1
f[x_] := f[x] = f[x - 1] + f[x - 2]

Now suppose I find f[5] from this definition. Then the following values are stored in memory

?f

Global`f

f[0]=1

f[1]=1

f[2]=2

f[3]=3

f[4]=5

f[5]=8

f[x_]:=f[x]=f[x-1]+f[x-2]

Suppose now that for some later computation I want to remove the cached values of f from memory but not the definition of f. How can this be done neatly.

I have Tried Unset[f[n_]], but this removes the definition and not the cached values. I have tried Clear["_Integer"] but this does nothing.

Does anyone know how to remove the cached values f[2],...,f[5] but not the definition of f? Without writing some type of loop involving Unset[f[k]] Because I dont know the value of k in advance. Thanks for reading

Community
  • 1
  • 1
mark
  • 586
  • 1
  • 5
  • 11
  • 1
    I do not know if this will do what you want (did not test it), but `ClearSystemCache[]` says `clears internal system caches of stored results.` – Nasser Jan 14 '12 at 02:43
  • @Mr.Wizard ... Thats exactly what I was looking for. Thanks ... – mark Jan 14 '12 at 02:52
  • [Dynamic Programming in Mathematica: how to automatically localize and / or clear memoized function's definitions](http://stackoverflow.com/q/7342748/211232) offers several alternatives. – WReach Jan 14 '12 at 04:11
  • I added [another answer](http://stackoverflow.com/a/8860915/695132) on the question this was marked a duplicate of. – Szabolcs Jan 14 '12 at 07:52

0 Answers0