Rationalize[x]
converts an approximate number x to a nearby rational with small denominator.
Rationalize[x,dx]
yields the rational number with smallest denominator that lies within dx of x.
Rationalize
Rationalize[x]
converts an approximate number x to a nearby rational with small denominator.
Rationalize[x,dx]
yields the rational number with smallest denominator that lies within dx of x.
Details
- Rationalize[x,dx] works with exact numbers x.
- Rationalize[x] yields x unchanged if there is no rational number close enough to x to satisfy the condition
, with
chosen to be
. - Rationalize[x,0] converts any inexact number x to rational form. »
Examples
open all close allScope (5)
Find rational approximations to within a given tolerance:
Rationalize[Pi, .01]Rationalize[Pi, .001]Rationalize works with exact numbers:
Rationalize[Exp[Sqrt[2]], 2 ^ -12]Rationalize all numbers in an expression:
Rationalize[1.2 + 6.7x]No rational number is by default considered "close enough" to N[Pi]:
Rationalize[N[Pi]]Force a rational approximation to be found:
Rationalize[N[Pi], 0]Applications (3)
Successive rational approximations to
:
Table[Rationalize[Pi, 10 ^ -n], {n, 1, 10}]Plot the error in progressively better rational approximations to
:
Plot[Log[Abs[Pi - Rationalize[Pi, Exp[-n]]]], {n, 0, 20}]Plot the error in progressively better approximations to
:
Plot[Log[Abs[Sqrt[3] - Rationalize[Sqrt[3], Exp[-n]]]], {n, 0, 20}]Create a polynomial with approximate numerical coefficients:
N[Sum[Exp[n] x ^ n, {n, 6}]]Find a rough approximation involving only rational numbers:
Rationalize[%, 0.1]Factor[%]Properties & Relations (3)
If Rationalize returns a rational number
, then
:
x = 0.202898;r = Rationalize[x]{p, q} = {Numerator[r], Denominator[r]};
Abs[r - x] < 10 ^ -4 / q ^ 2When Rationalize[x] returns x unchanged, there is no rational number satisfying this:
x = N[Pi];Rationalize[x]Get the rational approximations with smallest denominator error dx through machine precision:
rats = Union[Table[Rationalize[x, 2 ^ -k], {k, 53}]]The residual of the inequality is positive for all of these rational approximations:
f[r_, c_] := Abs[r - x] - c / Denominator[r] ^ 2Map[{#, f[#, 10 ^ -4]}&, rats]SetPrecision[x,∞] and Rationalize[x,0] both give rational approximations for real x:
x = N[π]Rationalize[x,0] gives a rational that is equivalent to x up to the precision of x:
r = Rationalize[x, 0]r - xSetPrecision[x,∞] gets a rational directly from the bitwise representation of x:
SetPrecision[x, ∞]% === FromDigits[RealDigits[x, 2], 2]Rationalize and RootApproximant both give exact quantities approximating real x:
x = N[E]RootApproximant[x] gives an algebraic number equivalent to x up to the precision of x:
ra = RootApproximant[x]ra - xRationalize[x,0] gives a rational number equivalent to x up to the precision of x:
q = Rationalize[x, 0]q - xSee Also
N Chop Round ContinuedFraction Convergents RootApproximant LatticeReduce FindSequenceFunction SetPrecision FromDigits RealDigits
Function Repository: RepeatingDecimalToRational SimultaneousRationalize
Tech Notes
Related Guides
History
Introduced in 1988 (1.0) | Updated in 1999 (4.0)
Text
Wolfram Research (1988), Rationalize, Wolfram Language function, https://reference.wolfram.com/language/ref/Rationalize.html (updated 1999).
CMS
Wolfram Language. 1988. "Rationalize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1999. https://reference.wolfram.com/language/ref/Rationalize.html.
APA
Wolfram Language. (1988). Rationalize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Rationalize.html
BibTeX
@misc{reference.wolfram_2026_rationalize, author="Wolfram Research", title="{Rationalize}", year="1999", howpublished="\url{https://reference.wolfram.com/language/ref/Rationalize.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_rationalize, organization={Wolfram Research}, title={Rationalize}, year={1999}, url={https://reference.wolfram.com/language/ref/Rationalize.html}, note=[Accessed: 12-June-2026]}