Skip to main content
added 127 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269
f[x_] := x^2

DownValues[h] = DownValues[f] /. f -> h;
f[x_] := f[x] = h[x]

h is now equal to the original f, and f is a memoized version of it.

Some kinds of definitions would require a more specific replacement rule than /. f -> h, for example recursive functions.

f[x_] := x^2

DownValues[h] = DownValues[f] /. f -> h;
f[x_] := f[x] = h[x]

h is now equal to the original f, and f is a memoized version of it.

f[x_] := x^2

DownValues[h] = DownValues[f] /. f -> h;
f[x_] := f[x] = h[x]

h is now equal to the original f, and f is a memoized version of it.

Some kinds of definitions would require a more specific replacement rule than /. f -> h, for example recursive functions.

Post Undeleted by C. E.
Post Deleted by C. E.
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

f[x_] := x^2

DownValues[h] = DownValues[f] /. f -> h;
f[x_] := f[x] = h[x]

h is now equal to the original f, and f is a memoized version of it.