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.