It has been noted before, here and here, that when you enter a/b or a-b mathematica does not convert these to Subtract[a,b] or Divide[a,b]. It uses the rather long forms Times[a, Power[b,-1] ] and Plus[a, Times[b,-1] ]. Which are actually slower since you do 2 operations instead of one. My question is if anyone has found a systematic way around that. I do mcmc sampling where you calculate a function many times, in which case these effects can accumulate and result in a sizable difference in run time. I could always manually implement Subtract and Divide when declaring functions, but right now I am also working in a problem where I have to take several gradients of multivariable functions and calculate the resulting object many times. So, implementing Subtract and Divide by hand would be unfeasible, the gradient calculations themselves are already automatic.
How to enforce the use of Subtract and Divide
Felipe
- 719
- 10