memoizing functions
- To: mathgroup at smc.vnet.net
- Subject: [mg32420] memoizing functions
- From: Erich Neuwirth <erich.neuwirth at univie.ac.at>
- Date: Sat, 19 Jan 2002 19:03:15 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
I have the following )recursive) function:
Kleber[0, k_] := Kleber[0, k] = 1
Kleber[n_, 0] /; n > 0 := Kleber[n, 0] = 0
Kleber[n_, k_] /; (n > 0) && (k > 0) && (k <= n) :=
Kleber[n, k] =
Kleber[n, k - 1] - Kleber[n - 1, k] + Kleber[n - 1, 2*k - 1] +
Kleber[n - 1, 2*k]
Kleber[n_, k_] /; (n > 0) && (k > 0) && (k > n) && (k <= 2*n + 2) :=
Kleber[n, k] =
Sum[(-1)^(j - 1)*Binomial[n + 1, j]*Kleber[n, k - j], {j, 1, n + 1}]
it memorizes the values, so next time it is called it will not
unfold the recursion for values it has calculated before.
for benachmarking purposes, i want to introduce "amnesia", i.e. i want
the function to forget its previously calculated values,
but not its definition.
can this be done?
--
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