MathGroup Archive 2014

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

Search the Archive

Re: How to avoid repeated recalculation of the same function


If g is  calling f with the same arguments all the time, memoize f: f[x_]:=f[x]=<expression>.  Otherwise if the result of f is a simple symbolic expression, evaluate f once for x, then use the result to create another function h which g can call eg. simpleExpression = f[x]; h[y_]:= simpleExpression /. x->y; and call h from g instead of f.

On May 2, 2014, at 2:18 AM, pgeipi10 at gmail.com wrote:

> Hi,
>
> I'm doing a calculaton that's purly symbolic (no graphing, numerical integration, etc.).
>
> Suppose I have a function f[x_]:=... that's very complex to build. In fact, f[x] ends up being a manageable expression (about 30 characters) but it takes Mathematica about 30 min to build that expression.
>
> Another function g[] uses the function f[x] and references it many times. I've discovered that g[] actually builds f[x] every time it's referenced which takes 30 minutes each time. Theoretically, Mathematica could build it once and then use the resulting expression every time it's referenced.
>
> So how do I accomplish that? That is, how do I make it build f[x] once and then use the resulting expression when it's needed?
>
> Thanks,
>
>
> Pavel
>




  • Prev by Date: Re: Copying Text From CDFs
  • Next by Date: Re: How to avoid repeated recalculation of the same function
  • Previous by thread: How to avoid repeated recalculation of the same function
  • Next by thread: Re: How to avoid repeated recalculation of the same function