here is the silly question of mine,
if mathematica takes 3 seconds to evaluate the function f[3] then I plug the this value f[3] into a new function g[f[3],f[3]], Let's ignore the evaluation time for the new function g, how long does it take for g[f[3],f[3]], 3 seconds or 6 seconds?
if it is 6 seconds, how can I make mathematica temporarily to remember the value of f[3]
thanks
Answer
Use With to define temporary constants.
With[{a=f[3]}, g[a,a]]
Memoization is also worth mentioning but keep in mind that once a value is remembered, it won't be forgotten (until to explcitly clear it). I.e. when you use memoization, Mathematica will remember permanently (not temporarily).
Comments
Post a Comment