It has been noted before, here and here, that when you enter a/ba/b
or a-b mathematicaa-b
, Mathematica does not convert these to Subtract[a,b]Subtract[a,b]
or Divide[a,b]Divide[a,b]
. It uses the rather long forms Times[a, Power[b,-1] ]Times[a, Power[b,-1]]
and Plus[a, Times[bPlus[a, Times[b,-1]]
,-1] ]. Which which are slower, since you do 2two operations instead of one. My question is if
Has anyone has found a systematic way around that.? I do mcmcMCMC 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 SubtractSubtract
and DivideDivide
when declaring functions, but right now I am also working on a problem where I have to take several gradients of multivariable functions and calculate the resulting object many times. SoTherefore, implementing SubtractSubtract
and DivideDivide
by hand would be unfeasible, as the gradient calculations themselves are already automatic.