Re: Code optimization
- To: mathgroup at smc.vnet.net
- Subject: [mg109773] Re: Code optimization
- From: "M.Roellig" <markus.roellig at googlemail.com>
- Date: Sun, 16 May 2010 08:51:59 -0400 (EDT)
- References: <hsofh5$3if$1@smc.vnet.net>
Hi, Instead of writing foo =(expression 1)/(obscenely complex expression )+ (expression 2)/ (obscenely complex expression ) it pays out to do something like : denominator = obscenely complex expression ; foo=(expression 1)/denominator + (expression 2)/denominator Mathematica will calculate the complex expression once and store the result in denominator and only use that for later occurances of denominator. If you use denominator := obscenely complex expression ; instead, it will recalculate the complex stuff each time denominator is encountered. Markus > > foo =(expression 1)/denominator + (expression 2)/denominator > > where "denominator" is itself a complex expression. Is it worthwhile for > me to compute "denominator" once and use it explicitly in foo, or will > Mathematica cleverly deduce that it needs to be computed only once? > > My guess is that Mathematica is an interpreter so it will not optimize the code. > > Steve Gray