Factoring and Reducing Algebraic Fractions
An algebraic fraction (a rational expression) is one polynomial divided by another, such as . Reducing it works exactly like reducing to : factor top and bottom, then cancel the factors they share. The new part is keeping track of the values of that would make a denominator zero.
Rational expressions and their domain
A rational expression is undefined wherever its denominator is 0. Those values are excluded from its domain, and you should state them, because reducing can hide them.
Reducing: factor, then cancel factors
The rule is the same as for numbers (Equivalent Fractions): a factor common to the whole numerator and the whole denominator can be divided out, because for .
So for all . The reduced form is defined at , but the original is not; that point is a "hole" in the graph of the original.
Note: Only factors cancel, never terms. In the 6 in the numerator is a term of a sum, not a factor of the whole numerator, so . Test with : , but .
Opposites: and
and are not equal, but they are opposites: . So they cancel to :
Checking numerically
A good habit: pick a value of that is not excluded, evaluate the original and the reduced form, and compare. Fraction gives exact results:
from fractions import Fraction
def original(x):
return Fraction(x**2 - 9, x**2 + x - 6)
def reduced(x):
return Fraction(x - 3, x - 2)
for x in [0, 1, 5, -7]:
print(x, original(x), reduced(x), original(x) == reduced(x))
for x in [-3, 2]:
try:
print(x, original(x))
except ZeroDivisionError:
print(x, "original is undefined (division by zero)")0 3/2 3/2 True
1 2 2 True
5 2/3 2/3 True
-7 10/9 10/9 True
-3 original is undefined (division by zero)
2 original is undefined (division by zero)
Notice that Fraction itself reduces: Fraction(-9, -6) becomes 3/2 because it divides out . That is the same idea, done with numbers.
SymPy's cancel reduces a rational expression, and factor shows the factored form:
import sympy as sp
x = sp.symbols("x")
expr = (x**2 - 9) / (x**2 + x - 6)
print(sp.cancel(expr))
print(sp.factor(expr))
print(sp.cancel((4 - x) / (x**2 - 16)))
print(sp.cancel((2*x**2 + 5*x - 3) / (4*x**2 - 1)))
print(sp.solve(sp.denom(sp.together(expr)), x)) # excluded values(x - 3)/(x - 2)
(x - 3)/(x - 2)
-1/(x + 4)
(x + 3)/(2*x + 1)
[-3, 2]
Tip: SymPy's
cancelsilently drops the excluded values. When you report a reduced answer, find them from the original denominator yourself, as the last line does.
In software
- Avoiding . evaluated at in floating point gives a division by zero, though the reduced form gives 2. Graphics and physics code often reduces formulas by hand first so that a special input does not crash or produce
nan. - Fewer operations, less rounding. A reduced expression has smaller degree, so evaluating it costs less and accumulates less rounding error.
- Exact rationals.
fractions.Fraction, SymPy'sRationaland big-number libraries keep every fraction reduced with a GCD after each operation, so numbers do not grow without bound (Euclid's algorithm).
Exercises
Exercise 1: Excluded values
State the excluded values of .
Answer
and
Solution
, which is 0 at and .
Exercise 2: Reduce a monomial fraction
Reduce .
Answer
, with .
Solution
Exercise 3: Factor and reduce
Reduce .
Answer
, with .
Solution
Exercise 4: Opposite factors
Reduce .
Answer
, with .
Solution
import sympy as sp
x = sp.symbols("x")
print(sp.cancel((6 - 2*x) / (x**2 - 9)))-2/(x + 3)
Exercise 5: Spot the illegal cancellation
A student writes . Show with one value that this is wrong, and explain the mistake.
Answer
It is false: at the left side is and the right side is . (At both sides happen to equal 2.)
Solution
is a sum of squares and does not factor into (that is ). The student treated it as a difference of squares. A single test value may agree by chance, so test more than one.
from fractions import Fraction
for x in [0, 1, 2]:
print(x, Fraction(x**2 + 4, x + 2), x + 2)0 2 2
1 5/3 3
2 2 4
Test yourself
Reduce .
- 1/4
Which values are excluded from ?
- only 3
- 3 and −2
- −3 and 2
- none
What does simplify to?
- 1
- 0
- −1
- It cannot be simplified