I am currently having problems with some floating points.
I have a function, which gives as an intermediate result (for example)
-(10000. - 10000. a) E^(-16.4157 kp^2 x^0.277)/((-1. + a) a x^0.252525 xj^4.47047)
It gets passed through into another function, which will fill in the value a = 1.
Then Mathematica reacts with a 1/Sqrt[0] error.
However, as you can see, the factor (10000. - 10000. a) should cancel with the factor (-1.+ a) in the denominator to give 10000, the result is thus well-defined.
Do you have any idea how to let Mathematica cancel these factors out?
I have tried Simplify and FullSimplify with Assumptions -> a!=1 but it doesn't work.
I cannot change much to the function itself, as it is an intermediate result (and it is just an example for this post; other intermediate results also occur, sometimes with the same problem, sometimes they work fine).
I think there are two options:
- Use the function Rationalize to turn the floating point numbers into rational numbers and then use FullSimplify. (I'm not a big fan of this because it ignores the fact that the numbers of a limited precision)
– Searke Mar 01 '12 at 19:47(1 + $MaxMachineNumber) == $MaxMachineNumberevaluates toTrue– acl Mar 01 '12 at 20:021.*10^16 + 1. - 1.*10^16which returns different answers depending on where1.is, however-10.^16 + (10.^16 + 1.)and-10.^16 + (1. + 10.^16)return the same incorrect answer. This indicates that addition is not associative, but commutative. Also, giveng[a_, b_, c_] := a^2 - 2 a b + b^2 - c^2,g[10.^10, 10.^10, 10.] == 0implying that mma is doing speculative processing as the first three terms simplify to $(a - b)^2$ and should cancel. – rcollyer Mar 01 '12 at 20:431. + (1.1 $MachineEpsilon) === 1.evaluates toTrue. In any case, point taken, thanks everyone. – David Mar 01 '12 at 20:47RationalizeandCancelfor those situations where I cannot keep the calculation symbolic. I couldn't implementLimit, but I'm happy that I know it now. Thanks a lot everyone! – freddieknets Mar 01 '12 at 23:32