Re: Combined Set, SetDelayed
- To: mathgroup at smc.vnet.net
- Subject: [mg100805] Re: Combined Set, SetDelayed
- From: Simon <simonjtyler at gmail.com>
- Date: Sun, 14 Jun 2009 05:41:47 -0400 (EDT)
- References: <h0vteh$6v2$1@smc.vnet.net>
Hi Sid, if you check the grouping of the expression it is f[x_,y_] := ( f[x, y] = ... ) thus if f[x,y] is not in the downvalues of f for the particular x and y it will do the calculation. If it is in the downvalues, it simply returns the value it knows. ( NB this is dangerous if you change your definition of f, but do not clear all the previously calculated specific values ) it can be used whenever the calculation of f[x,y] is computationally expensive (and memory isn't too much of a problem)... the famous example (I think given in the documentation centre) is that of the Fibonacci numbers - a naive recursive definition f[0]=f[1]=1; f[n_Integer?Positive]:=f[n-1]+f[n-2] becomes unusable for relatively small values of n. Simon