The docs state that "Rationalize[x,dx] yields the rational number with smallest denominator that lies within dx of x." However, testing this out it appears to be false.
Rationalize[Pi, 0.1]
22 / 7
The problem is that 16 / 5 is also within 0.1 of Pi and has a smaller denominator.
N[16 / 5 - Pi]
0.0584073
How does Rationalize actually work?
N[22/7 - Pi] < N[16/5 - Pi], I assume, thatRationalizetries to minimizeAbs[dx]though within reasonable time limits. Also, as the documentation states, it has to be true thatAbs[p/q - x] < c/q^2, wherec = 10^-4. – István Zachar Jul 19 '16 at 10:51Rationalize. There is an interplay between denominator of result, epsilon, and size of residual. If you takedxas replacing the default epsilon then I think the correct claim might be to the effect:ratPi = Rationalize[N[Pi], eps]; Abs[N[Pi] - ratPi] < N[eps]/Denominator[ratPi]^2. – Daniel Lichtblau Jul 19 '16 at 18:57Rationalizeuse for the 2-argument case witheps = 0, i.e.,Rationalize[some_number, 0]? Using a few test numbers (N[Pi], 0.1, 399847593.00000068), I tried applying your criterion to the latter, and they all evaluated toFalse. – theorist Apr 04 '17 at 19:21Rationalizeproduces a rational number exactly equal to the decimal "num" if I evaluateRationalize[num\z, 0]wherez >= 2*(Length@RealDigits[num][[1]] ) + 1(and where "num" is the actual decimal I type in). E.g., Length@RealDigits[0.39984759300000068][[1]] = 16, andRationalize[0.39984759300000068`33, 0]gives a fraction exactly equal to the decimal, butRationalize[0.39984759300000068`32, 0]` does not. I''d like to understand why that's the cutoff. – theorist Apr 05 '17 at 02:56