Adding and Subtracting Algebraic Fractions
To add or subtract fractions you need a common denominator, and algebraic fractions are no different. The least common denominator (LCD) comes from factoring each denominator, just as the least common multiple of numbers comes from their prime factors. This lesson builds the LCD, combines the fractions, and handles the sign trap in subtraction.
Same denominator
Add or subtract the numerators and keep the denominator:
Note: When subtracting, put the whole second numerator in parentheses. (no parentheses) would give , which is wrong. This is the same sign trap as in subtracting polynomials.
Always try to reduce the result at the end, as in the last step above.
Different denominators: the LCD
- Factor each denominator.
- The LCD takes every factor that appears, each to the highest power it appears with.
- Build up each fraction: multiply its top and bottom by the factors of the LCD it is missing.
- Add or subtract the numerators, then simplify.
With numbers, : , , (Adding Fractions). With polynomials:
has no factor in common with the denominator, so this is the final answer (excluded: ).
Tip: Leave the LCD in factored form while you work. Multiplying it out only makes the final "can anything cancel?" check harder.
A subtraction example
does not factor over the integers, so nothing cancels. Compare with : sometimes the final reduction removes everything.
In Python
SymPy's together combines fractions over a common denominator, factor shows the factored form, and apart goes the other way (partial fractions, used heavily in calculus: Partial Fractions):
import sympy as sp
x = sp.symbols("x")
s = 5/(x**2 - 4) + 2/(x**2 + 2*x)
print(sp.factor(sp.together(s)))
d = x/(x - 3) - 6/(x**2 - 9)
print(sp.factor(sp.together(d)))
print(sp.apart((7*x - 4) / (x*(x - 2)*(x + 2))))(7*x - 4)/(x*(x - 2)*(x + 2))
(x**2 + 3*x - 6)/((x - 3)*(x + 3))
-9/(4*(x + 2)) + 5/(4*(x - 2)) + 1/x
apart splits the combined fraction back into one simple fraction per factor of the denominator (in SymPy's own order); adding those pieces gives the combined fraction again. A numeric check with exact fractions confirms the hand result:
from fractions import Fraction as F
for x in [1, 3, -5, 7]:
left = F(5, x**2 - 4) + F(2, x**2 + 2*x)
right = F(7*x - 4, x * (x - 2) * (x + 2))
print(x, left, right, left == right)1 -1 -1 True
3 17/15 17/15 True
-5 13/35 13/35 True
7 1/7 1/7 True
In software
- Parallel resistors and combined rates. Two resistors in parallel have , so : adding two algebraic fractions. The same formula combines two workers' rates, two pipes filling a tank, or two servers sharing requests (Rational Equations).
- Lens and camera formulas. The thin-lens equation is used in rendering depth of field; solving for means combining fractions.
- Average speed. Driving a distance at speed and back at takes , so the average speed is (the harmonic mean), not . The same harmonic mean appears in ML as the F1 score.
def parallel(r1, r2):
return r1 * r2 / (r1 + r2)
def harmonic_mean(u, v):
return 2 * u * v / (u + v)
print("100 Ω ‖ 300 Ω =", parallel(100, 300), "Ω")
print("60 km/h there, 40 km/h back: average", harmonic_mean(60, 40), "km/h")
print("F1 with precision 0.9, recall 0.6:", round(harmonic_mean(0.9, 0.6), 4))100 Ω ‖ 300 Ω = 75.0 Ω
60 km/h there, 40 km/h back: average 48.0 km/h
F1 with precision 0.9, recall 0.6: 0.72
Exercises
Exercise 1: Same denominator
Simplify .
Answer
, with .
Solution
Exercise 2: Monomial denominators
Simplify .
Answer
Solution
Exercise 3: Binomial denominators
Simplify .
Answer
Solution
Exercise 4: Factor first
Simplify .
Answer
Solution
import sympy as sp
x = sp.symbols("x")
print(sp.factor(sp.together(x/(x**2 - x - 2) + 1/(x**2 - 4))))(x**2 + 3*x + 1)/((x - 2)*(x + 1)*(x + 2))
Exercise 5: Three resistors
Write a function for three resistors in parallel () using Fraction, and compute for , and .
Answer
Solution
, so .
from fractions import Fraction as F
def parallel(*rs):
return 1 / sum(F(1, r) for r in rs)
print(parallel(6, 3, 2))
print(parallel(100, 300))1
75
Test yourself
What is the LCD of and ?
Simplify .
A car goes 30 km/h one way and 60 km/h back over the same road. What is its average speed?
- 45 km/h
- 40 km/h
- 50 km/h
- 35 km/h