Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Repeated function evaluation?

  • To: mathgroup at
  • Subject: [mg24233] RE: [mg24240] Repeated function evaluation?
  • From: "David Park" <djmp at>
  • Date: Tue, 4 Jul 2000 15:22:00 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

> -----Original Message-----
> From: AES [mailto:siegman at]
To: mathgroup at
> Suppose I have a function  f[x_,y_] := Module[{ }, . . .]  where the
> module is fairly time-consuming to evaluate.
> If I call this function a second time in a given notebook using
> identical values of the arguments  x  and  y , is Mathematica smart
> enough the second time around to recognize that it's already evaluated
> the function once for those arguments, and use a stored value?
> Or, if I want to use the values of this function for a given range of
> arguments multiple times (e.g., replotting the values in different
> ways), do I need to do something like
>    Do[ ff[x,y] = f[x,y], {x, x1, x2}, {y, y1, y2} ]
> and use the values  ff[x,y]  instead?
> Thanks   AES

Use dynamic programming described in Section 2.4.9, Functions That Remember
Values They Have Found, in the Mathematica Book.

f[x_, y_] := f[x, y] = x + y^2

{f[1, 1], f[1, 2]}
{2, 5}

Now, Mathematica has stored the definitions for those particular values.

f[1, 1] = 2

f[1, 2] = 5

f[x_, y_] := f[x, y] = x + y^2

David Park
djmp at

  • Prev by Date: Re: Repeated function evaluation?
  • Next by Date: Re: Re: Evaluate and HoldAll
  • Previous by thread: Re: Repeated function evaluation?
  • Next by thread: HELP: personal package