TExcelTAD
Home › Algebra › Factoring Out a Common Factor

Factoring Out a Common Factor

Factoring is multiplying in reverse: you start with a sum like 6x3+9x26x^3 + 9x^2 and rewrite it as a product, 3x2(2x+3)3x^2(2x + 3). The first thing to try, always, is pulling out the greatest common factor (GCF) of all the terms. This lesson shows how to find it, how to factor by grouping when there is no single common factor, and how SymPy does the same job.

Why factor?

A product tells you things a sum hides. From 3x2(2x+3)3x^2(2x + 3) you can read at once that the expression is zero when x=0x = 0 or x=−32x = -\frac{3}{2}, and that it is a multiple of 3. Factored forms also simplify algebraic fractions and solve quadratic equations.

Finding the GCF of terms

Take the GCF of the coefficients (GCF and LCM) and, for each variable that appears in every term, the lowest power of it.

12x4y2−18x3y+30x2y3coefficients:GCF(12,18,30)=6x:powers 4,3,2→lowest is x2y:powers 2,1,3→lowest is yGCF=6x2y\begin{aligned} &12x^4y^2 - 18x^3y + 30x^2y^3 \\[1ex] \text{coefficients:}\quad &\text{GCF}(12, 18, 30) = 6 \\ x{:}\quad &\text{powers } 4, 3, 2 \to \text{lowest is } x^2 \\ y{:}\quad &\text{powers } 2, 1, 3 \to \text{lowest is } y \\ &\text{GCF} = 6x^2y \end{aligned}

Then divide each term by the GCF to find what stays in the parentheses:

12x4y2÷6x2y=2x2y−18x3y÷6x2y=−3x30x2y3÷6x2y=5y212x4y2−18x3y+30x2y3=6x2y(2x2y−3x+5y2)\begin{aligned} 12x^4y^2 \div 6x^2y &= 2x^2y \\ -18x^3y \div 6x^2y &= -3x \\ 30x^2y^3 \div 6x^2y &= 5y^2 \\[1ex] 12x^4y^2 - 18x^3y + 30x^2y^3 &= 6x^2y(2x^2y - 3x + 5y^2) \end{aligned}

Tip: Check by multiplying back out. Also check that nothing common is left inside the parentheses: 6x(2x3y2−3x2y+5xy3)6x(2x^3y^2 - 3x^2y + 5xy^3) multiplies back correctly but is not fully factored.

When a term equals the GCF itself, a 1 stays behind: 4x2+4x=4x(x+1)4x^2 + 4x = 4x(x + 1), not 4x(x)4x(x).

Factoring out a negative

If the leading coefficient is negative, it is common to factor out the negative GCF, which flips every sign inside:

−5t2+20t=−5t(t−4)-5t^2 + 20t = -5t(t - 4)

This is the form you want for projectile height formulas like h=−5t2+20th = -5t^2 + 20t: the factors show at once that the height is 0 at t=0t = 0 and t=4t = 4.

The common factor can be a binomial

The GCF does not have to be a monomial. In x(a+b)+3(a+b)x(a + b) + 3(a + b) the common factor is the whole group (a+b)(a + b):

x(a+b)+3(a+b)=(a+b)(x+3)x(a + b) + 3(a + b) = (a + b)(x + 3)

Factoring by grouping

A four-term polynomial often has no factor common to all four terms, but splits into two pairs that do share one:

x3−4x2+3x−12=(x3−4x2)+(3x−12)group in pairs=x2(x−4)+3(x−4)GCF of each pair=(x−4)(x2+3)(x−4) is now common\begin{aligned} &x^3 - 4x^2 + 3x - 12 \\ &= (x^3 - 4x^2) + (3x - 12) && \text{group in pairs} \\ &= x^2(x - 4) + 3(x - 4) && \text{GCF of each pair} \\ &= (x - 4)(x^2 + 3) && (x - 4) \text{ is now common} \end{aligned}

If the two brackets do not match, try regrouping or factoring a negative out of the second pair: 2y3+y2−6y−3=y2(2y+1)−3(2y+1)=(2y+1)(y2−3)2y^3 + y^2 - 6y - 3 = y^2(2y + 1) - 3(2y + 1) = (2y + 1)(y^2 - 3). Grouping is also the engine of the AC method for trinomials.

In Python

Finding the GCF of the coefficients is math.gcd; for the variables, take the minimum exponent. With terms stored as (coefficient, exponent) pairs:

python · try it yourself
from math import gcd
from functools import reduce

terms = [(12, 4), (-18, 3), (30, 2)]         # 12x⁴ − 18x³ + 30x²

g = reduce(gcd, (abs(c) for c, _ in terms))
low = min(e for _, e in terms)
inside = [(c // g, e - low) for c, e in terms]
print(f"GCF = {g}x^{low}")
print("inside:", inside)
print("check:", [(c * g, e + low) for c, e in inside] == terms)
GCF = 6x^2
inside: [(2, 2), (-3, 1), (5, 0)]
check: True

So 12x4−18x3+30x2=6x2(2x2−3x+5)12x^4 - 18x^3 + 30x^2 = 6x^2(2x^2 - 3x + 5). SymPy's factor finds the GCF and much more; factor_terms pulls out only the common factor:

python · try it yourself
import sympy as sp

x, y = sp.symbols("x y")
print(sp.factor_terms(12*x**4*y**2 - 18*x**3*y + 30*x**2*y**3))
print(sp.factor(x**3 - 4*x**2 + 3*x - 12))
print(sp.factor(-5*x**2 + 20*x))
6*x**2*y*(2*x**2*y - 3*x + 5*y**2)
(x - 4)*(x**2 + 3)
-5*x*(x - 4)

In software

  • Fewer operations. a⋅x+a⋅ya \cdot x + a \cdot y costs two multiplications, a⋅(x+y)a \cdot (x + y) one. Compilers apply this rewrite (and its reverse) when optimizing arithmetic, and the same idea, applied over and over, gives Horner's rule: 3x3+5x2+2x=x(x(3x+5)+2)3x^3 + 5x^2 + 2x = x(x(3x + 5) + 2).
  • Refactoring. Pulling the shared part of several functions into one helper is factoring out a common factor in code.
  • Lower precision risk. Computing x2(1+x)x^2(1 + x) instead of x2+x3x^2 + x^3 can save a rounding step in floating point, and grouping terms of similar size is a standard trick in numerical code.

Exercises

Exercise 1: Monomial GCF

Factor 8m3−12m2+20m8m^3 - 12m^2 + 20m.

Answer

4m(2m2−3m+5)4m(2m^2 - 3m + 5)

Solution
GCF(8,12,20)=4;lowest power of m is m18m3÷4m=2m2;−12m2÷4m=−3m;20m÷4m=5\begin{aligned} &\text{GCF}(8, 12, 20) = 4; \quad \text{lowest power of } m \text{ is } m^1 \\ &8m^3 \div 4m = 2m^2; \quad -12m^2 \div 4m = -3m; \quad 20m \div 4m = 5 \end{aligned}

Exercise 2: Two variables

Factor 14a2b3+21a3b2−7a2b214a^2b^3 + 21a^3b^2 - 7a^2b^2.

Answer

7a2b2(2b+3a−1)7a^2b^2(2b + 3a - 1)

Solution
GCF(14,21,7)=7;a: lowest a2;b: lowest b2→7a2b214a2b3÷7a2b2=2b21a3b2÷7a2b2=3a−7a2b2÷7a2b2=−1(the 1 must stay)\begin{aligned} &\text{GCF}(14, 21, 7) = 7; \quad a{:}\ \text{lowest } a^2; \quad b{:}\ \text{lowest } b^2 \quad \to \quad 7a^2b^2 \\ &14a^2b^3 \div 7a^2b^2 = 2b \\ &21a^3b^2 \div 7a^2b^2 = 3a \\ &-7a^2b^2 \div 7a^2b^2 = -1 && \text{(the 1 must stay)} \end{aligned}

Exercise 3: Grouping

Factor 6x3+9x2−4x−66x^3 + 9x^2 - 4x - 6.

Answer

(2x+3)(3x2−2)(2x + 3)(3x^2 - 2)

Solution
(6x3+9x2)+(−4x−6)=3x2(2x+3)−2(2x+3)=(2x+3)(3x2−2)\begin{aligned} &(6x^3 + 9x^2) + (-4x - 6) \\ &= 3x^2(2x + 3) - 2(2x + 3) \\ &= (2x + 3)(3x^2 - 2) \end{aligned}
python · try it yourself
import sympy as sp

x = sp.symbols("x")
print(sp.factor(6*x**3 + 9*x**2 - 4*x - 6))
(2*x + 3)*(3*x**2 - 2)

Exercise 4: Zeros from the factors

The height of a ball is h=−5t2+15th = -5t^2 + 15t metres after tt seconds. Factor the expression and say when the ball is at height 0.

Answer

h=−5t(t−3)h = -5t(t - 3); height 0 at t=0t = 0 s (launch) and t=3t = 3 s (landing).

Solution

The GCF is −5t-5t (negative because the leading coefficient is negative). −5t2÷(−5t)=t-5t^2 \div (-5t) = t, 15t÷(−5t)=−315t \div (-5t) = -3. A product is zero when a factor is zero: t=0t = 0 or t−3=0t - 3 = 0.

Exercise 5: GCF of a whole list

Extend the code above to handle the case where the leading coefficient is negative: make the GCF negative then, so the first term inside is positive. Test on −6x3+9x2−3x-6x^3 + 9x^2 - 3x.

Answer

GCF −3x-3x, inside 2x2−3x+12x^2 - 3x + 1.

Solution
python · try it yourself
from math import gcd
from functools import reduce

def common_factor(terms):
    g = reduce(gcd, (abs(c) for c, _ in terms))
    if terms[0][0] < 0:
        g = -g
    low = min(e for _, e in terms)
    return (g, low), [(c // g, e - low) for c, e in terms]

print(common_factor([(-6, 3), (9, 2), (-3, 1)]))
((-3, 1), [(2, 2), (-3, 1), (1, 0)])

Test yourself

What is the GCF of 10x3y10x^3y and 15x2y415x^2y^4?

  1. 5x3y45x^3y^4
  2. 5x2y5x^2y
  3. 30x2y30x^2y
  4. 5xy5xy

Factor 9x2+3x9x^2 + 3x completely.

  1. 3x(3x)3x(3x)
  2. 3(3x2+x)3(3x^2 + x)
  3. x(9x+3)x(9x + 3)
  4. 3x(3x+1)3x(3x + 1)

Factor by grouping: ab+2a+5b+10ab + 2a + 5b + 10.

  1. (a+5)(b+2)(a + 5)(b + 2)
  2. (a+2)(b+5)(a + 2)(b + 5)
  3. (ab+10)(2a+5b)(ab + 10)(2a + 5b)
  4. (a+b)(2+5)(a + b)(2 + 5)