Groups | Search | Server Info | Login | Register


Groups > comp.soft-sys.math.mathematica > #16896

Re: How to avoid repeated recalculation of the same function

From Joe Gwinn <joegwinn@comcast.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: How to avoid repeated recalculation of the same function
Date 2014-05-03 07:40 +0000
Message-ID <lk26i5$12b$1@smc.vnet.net> (permalink)
References <ljvdcg$bal$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


In article <ljvdcg$bal$1@smc.vnet.net>, <pgeipi10@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?

That bit me a few times as well.

Instead write f[x_]= ..., dropping the colon.

If you write only =, the ... is evaluated once and the result saved
under f[x_].  

If you write :=, the whole ... is saved under f[x_], and evaluated
every time f[x] is invoked.

Joe Gwinn

Back to comp.soft-sys.math.mathematica | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

How to avoid repeated recalculation of the same function pgeipi10@gmail.com - 2014-05-02 06:18 +0000
  Re: How to avoid repeated recalculation of the same function Richard Fateman <fateman@cs.berkeley.edu> - 2014-05-03 07:39 +0000
  Re: How to avoid repeated recalculation of the same function Joe Gwinn <joegwinn@comcast.net> - 2014-05-03 07:40 +0000
  Re: How to avoid repeated recalculation of the same function psycho_dad <s.nesseris@gmail.com> - 2014-05-04 06:27 +0000
  Re: How to avoid repeated recalculation of the same function Roland Franzius <roland.franzius@uos.de> - 2014-05-04 06:28 +0000

csiph-web