Comparing Fractions
Is bigger than ? This lesson gives four reliable ways to compare fractions: same denominators, same numerators, a common denominator, and cross multiplication. It also shows how to sort fractions in Python, and why comparing them as floats can go wrong.
Same denominator: compare the tops
If the parts are the same size, more parts means more: . Only the numerators matter.
Same numerator: compare the bottoms (reversed)
If you have the same number of parts, the parts that are bigger win. Bigger denominator means smaller parts, so . One fifth of a pizza is a bigger slice than one eighth.
Different numerators and denominators
Method 1: a common denominator
Rewrite both fractions with the same denominator, then compare the numerators. The least common multiple of the denominators is the smallest choice:
Method 2: cross multiplication
To compare with (positive denominators), compare with :
This is Method 1 in disguise: using as the common denominator, the new numerators are and .
Method 3: benchmarks
Often you can compare with or 1 in your head. is less than a half (4.5 would be half of 9), and is more than a half, so . No arithmetic needed.
| Pair | Quick reason | Result |
|---|---|---|
| vs | same denominator | |
| vs | same numerator | |
| vs | benchmark | |
| vs | each is 1 minus a piece: | |
| vs | cross: , |
Comparing in Python
Fraction supports <, >, ==, min, max and sorted exactly, and you can mix it with integers:
from fractions import Fraction as F
pairs = [(F(5, 8), F(3, 5)), (F(7, 8), F(8, 9)), (F(11, 12), F(13, 14))]
for a, b in pairs:
sign = "<" if a < b else (">" if a > b else "=")
print(f"{a} {sign} {b}")
def cross_compare(a, b, c, d):
return (a * d > c * b) - (a * d < c * b) # 1, 0 or -1
print(cross_compare(5, 8, 3, 5))
scores = [F(2, 3), F(5, 9), F(7, 10), F(3, 5), F(4, 6)]
print(sorted(scores))
print("largest:", max(scores), " bigger than 1/2?", min(scores) > F(1, 2))5/8 > 3/5
7/8 < 8/9
11/12 < 13/14
1
[Fraction(5, 9), Fraction(3, 5), Fraction(2, 3), Fraction(2, 3), Fraction(7, 10)]
largest: 7/10 bigger than 1/2? True
Note that and sort next to each other: they are equal, and Fraction stored as . Inside a list, Python shows each item with repr, which is why you see Fraction(5, 9) rather than 5/9.
Why not just compare floats?
Converting to decimals works for everyday numbers, but floats have limited precision. Two different fractions that are extremely close can turn into the same float:
from fractions import Fraction as F
a = F(10**17 + 1, 10**17)
b = F(10**17 + 2, 10**17)
print("as floats:", float(a), float(b), float(a) == float(b))
print("exactly: ", a < b)
# cross multiplication with integers never loses precision
print((10**17 + 1) * 10**17 < (10**17 + 2) * 10**17)as floats: 1.0 1.0 True
exactly: True
True
Python integers have no size limit, so cross multiplication is always exact. In languages with fixed-size integers (C, Java, Rust), a * d can overflow, which is a real bug in naive comparison code.
In software
- Ranking by ratio. "Sort products by rating" or "sort players by win rate" compares fractions like . Sorting with cross multiplication (or
Fractionkeys) avoids float ties. - Computational geometry decides "is this point left of that line?" with cross products of integer coordinates for the same reason: exact answers, no rounding.
- Scheduling. Proportional-share schedulers pick the task with the smallest "" ratio next.
Exercises
Exercise 1: Pick the bigger one
Compare and using cross multiplication.
Answer
.
Solution
Check with a common denominator: and .
Exercise 2: Order them
Put , , and in order from smallest to largest.
Answer
.
Solution
The LCM of 3, 5, 8 and 12 is 120. Rewrite each:
Order the numerators: .
Exercise 3: Benchmark only
Without any multiplication, decide which is bigger: or .
Answer
is bigger.
Solution
Each is one piece short of 1: and . Since is a smaller piece than , is closer to 1, so it is bigger.
Exercise 4: Rank players by win rate
Players: Ana won 7 of 12, Bo won 11 of 19, Cy won 4 of 7. Rank them from best to worst win rate with exact fractions in Python.
Answer
Ana (), Bo (), Cy ().
Solution
The rates are very close, so compare exactly. Ana vs Bo: and , so . Bo vs Cy: and , so . In code, use Fraction as the sort key:
from fractions import Fraction
players = {"Ana": (7, 12), "Bo": (11, 19), "Cy": (4, 7)}
ranked = sorted(players, key=lambda p: Fraction(*players[p]), reverse=True)
for p in ranked:
print(p, Fraction(*players[p]), round(float(Fraction(*players[p])), 4))Ana 7/12 0.5833
Bo 11/19 0.5789
Cy 4/7 0.5714
Test yourself
Which is larger: or ?
- They are equal
- Cannot tell
Which of these is smallest?
Using the benchmark , which comparison is correct?
- Benchmarks never work