is the head used for rational numbers.
Rational
is the head used for rational numbers.
Details
- You can enter a rational number in the form n/m.
- The pattern object _Rational can be used to stand for a rational number. It cannot stand for a single integer.
- You have to use Numerator and Denominator to extract parts of Rational numbers.
Examples
open all close allBasic Examples (1)
Scope (7)
Enter a rational number with very big integers in the numerator and denominator:
1237918739182739817238917127398123 / 12809812308120812038038101Rational numbers are represented with the smallest possible positive denominator:
7 / 49The FullForm of a rational number is Rational[numerator,denominator]:
FullForm[22 / 7]Enter a rational using the FullForm:
Rational[22, 7]You have to use Numerator and Denominator to extract parts of Rational numbers:
r = 22 / 7;{Numerator[r], Denominator[r]}Part does not work:
r[[1]]The pattern object _Rational can be used to stand for a rational number:
MatchQ[22 / 7, _Rational]It cannot stand for a single integer:
MatchQ[6 / 3, _Rational]A rule that replaces all rationals with their reciprocals:
rule = x_Rational :> Denominator[x] / Numerator[x];f[22 / 7, 201 / 64, x / y] /. ruleAn alternate way to write the rule:
f[22 / 7, 201 / 64, x / y] /. Rational[n_, d_] :> d / nApplications (1)
Define a function that only applies to rational numbers:
f[r_Rational] := Module[{x = Numerator[r], y = Denominator[r]}, (x ^ 2 + 2y ^ 2) / (2x y)]Nest[f, 3 / 2, 6]This is a close approximation to
:
Block[{$MaxExtraPrecision = ∞}, N[% - Sqrt[2], 20]]An alternative definition of the function:
g[Rational[x_, y_]] := (x ^ 2 + 2y ^ 2) / (2x y)Nest[g, 3 / 2, 6]Properties & Relations (5)
NumberQ[22 / 7]Rationals are atomic objects with no subexpressions:
AtomQ[22 / 7]ExactNumberQ[22 / 7]Denominator of a rational is positive:
r = -14 / 21Denominator[r]Numerator and Denominator of a rational are relatively prime:
GCD[Numerator[r], Denominator[r]]Use Rationals to indicate assumptions and domain conditions:
Reduce[1 / 2 - 6x + 10x ^ 2 - x ^ 99 / 2 + x ^ 100 == 0, x, Rationals]Possible Issues (1)
Numbers entered in the form n/m only become Rational numbers on evaluation:
SetAttributes[f, HoldAll];
f[x_Rational] := Numerator[x] - Denominator[x]f[22 / 7]f[Evaluate[22 / 7]]The unevaluated form is expressed in terms of Times and Power:
FullForm[HoldForm[22 / 7]]Tech Notes
Related Guides
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), Rational, Wolfram Language function, https://reference.wolfram.com/language/ref/Rational.html.
CMS
Wolfram Language. 1988. "Rational." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Rational.html.
APA
Wolfram Language. (1988). Rational. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Rational.html
BibTeX
@misc{reference.wolfram_2026_rational, author="Wolfram Research", title="{Rational}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/Rational.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_rational, organization={Wolfram Research}, title={Rational}, year={1988}, url={https://reference.wolfram.com/language/ref/Rational.html}, note=[Accessed: 13-June-2026]}