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

Re: memoizing functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32529] Re: memoizing functions
  • From: "Robert G. Wilson v" <rgwv at kspaint.com>
  • Date: Fri, 25 Jan 2002 02:58:04 -0500 (EST)
  • Organization: Kansas Paint & Color Co.
  • References: <a2d1fl$ocm$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Erich,

Yes, In the expression Kleber[n_,k_]:= Kleber[n,k]= ... get rid of the
"Kleber[n,k]=". An easy way to test this is the Fibonacci recursion.

Sincerely yours,
Robert G. "Bob" Wilson, V
Ph.D.  ATP  /  CF & GI

Erich Neuwirth wrote:

> 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


  • Prev by Date: Re: Magic Matrices
  • Next by Date: Re: Change of Variables
  • Previous by thread: memoizing functions
  • Next by thread: FrameLabel text rotation problem in LINUX