In the open source Mathematica implementation called Mathics, an issue was raised where Mathics computes Rationalize[-11.5, 1]
as -12 rather than Mathematica which is reported to compute this as -11.
Looking at the docs for Rationalize
, -11 seems equally valid.
Is this is purely an implementation choice, or is there more reasons why one answer is preferred over the other?
Rationalize[]
uses the continued fraction expansion to find a rational approximation with least denominator. For negative numbers it proabably returns-Rationalize[-x]
. I don't know how Mathics does it. $\endgroup$Mathics[]
uses the continued fraction expansion as well on the bounds given. Here those values are -11.5 +/- 1 When the continued fraction of both of these differs in a digit that is when it stops. However the value it picks ismin(-13, -11) + 1
which is -12. Of course, applying-Rationalize[-x]
first in Mathics will give the answer reported . $\endgroup$±x
seems a nice feature. $\endgroup$