3
$\begingroup$

I want to imitate machine-precision, de facto IEEE division on Mathematica. On my quick trials I find this surprisingly hard to accomplish, since Mma rewrites a / b as a (b^-1) and these are not identical on finite-precision math.

For an explicit example, consider the following:

49. / 49. // FullForm

0.9999999999999999`

EDIT: As @J.M. points out, this works:

Divide[49., 49.] // FullForm

1.`

... but if I do the following, for instance, the finite-precision multiplication by inverse is seen again:

Divide[x, 49.] // FullForm

Times[0.02040816326530612`, x]

... which is bad.

How would I implement a "use native (IEEE) division semantics on machine-precision arguments of this division, even later down the evaluation chain" operation instead of Mma being too clever for its' own sake?

EDIT: In this specific case I'm not interested in other IEEE semantics, for instance strict order of operations (a + b + c is not the same as c + b + a!). I just want divisions to stay as divisions, which may be a bit of a half-way goal, but sounds more feasible to implement that the whole shebang.

$\endgroup$
3
  • 3
    $\begingroup$ Divide[49., 49.]? (I think this was discussed before.) $\endgroup$ Mar 13, 2019 at 9:21
  • $\begingroup$ @J.M.isslightlypensive Hmmh... maybe I should rephrase my question somehow. It would seem that the "expected" IEEE behaviour is seen only in the case the computation can be completed with supplied arguments, otherwise it reverts to the a (b^-1) expansion very eagerly... $\endgroup$
    – kirma
    Mar 13, 2019 at 9:29
  • $\begingroup$ The previous question: mathematica.stackexchange.com/questions/161716 $\endgroup$
    – Coolwater
    Mar 13, 2019 at 11:53

1 Answer 1

3
$\begingroup$

You can define your own divide function:

divide[a_Real, b_Real] := Divide[a, b]
MakeBoxes[divide[a_, b_], StandardForm] := MakeBoxes[Divide[a, b], StandardForm]

Then:

divide[49., 49.]

1.

And:

r = divide[x, 49.]
r /. x->49.

x/49.

1.

Some more work is needed to define how divide works with other arithmetical operations.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.