Re: How to avoid repeated recalculation of the same function

• To: mathgroup at smc.vnet.net
• Subject: [mg132674] Re: How to avoid repeated recalculation of the same function
• From: Bob Hanlon <hanlonr357 at gmail.com>
• Date: Sat, 3 May 2014 03:40:15 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-outx@smc.vnet.net
• Delivered-to: mathgroup-newsendx@smc.vnet.net
• References: <20140502061856.7A2216A46@smc.vnet.net>

```If the calculation can be done symbolicly use f[x_] = calc rather than
f[x_] := calc

You may also want to [Full]Simplify the expression, i.e., f[x_] = Simplify[
calc, assumptions ] to speed up subsequent use as well as improve numerical
precision.

Bob Hanlon

On Fri, 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: How to avoid repeated recalculation of the same function
• Next by Date: Re: How to avoid repeated recalculation of the same function
• Previous by thread: Re: How to avoid repeated recalculation of the same function
• Next by thread: Re: How to avoid repeated recalculation of the same function