Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rationalize[-11.5,1] returns -12/1 #1553

Closed
axkr opened this issue Aug 20, 2021 · 1 comment · Fixed by #1555
Closed

Rationalize[-11.5,1] returns -12/1 #1553

axkr opened this issue Aug 20, 2021 · 1 comment · Fixed by #1555

Comments

@axkr
Copy link

axkr commented Aug 20, 2021

Docker web version: Rationalize[-11.5,1] returns -12/1 MMA returns -11.

@rocky
Copy link
Member

rocky commented Aug 21, 2021

I looked at this a little bit (it was easier than doing the hard work of fixing a major performance bug), and I am at a loss at why this result and not say the one that it.

The Mathematica docs for Rationalize just says:

yields the rational number with smallest denominator that lies within dx of x.

And 1 fits this. That the expression -12/1 is not simplified to -12 is another matter.

So other than running MMA, how can we know whether that this should be -11 insteads of -12?

In terms of what Mathics does, is it take integer digits of the continued fraction for the the two bounds it puts on -11.5 +/- 1 and stops at the first digit that it encounters where the upper and lower bounds differ. Then in the code the computation is: min(-13, -11) + 1.

It is easy to see how to adjust this to get -11, but to do this reliably we'd have to know what principle or rule to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants