TExcelTAD
Home › Algebra › Factoring ax² + bx + c

Factoring ax2+bx+cax^2 + bx + c

A quadratic trinomial such as x2+7x+12x^2 + 7x + 12 or 6x2+11x−106x^2 + 11x - 10 can often be written as a product of two binomials. This lesson starts with the easy case where the leading coefficient is 1, then teaches the AC method, a step-by-step recipe that works for any leading coefficient, and finally writes that recipe as a small Python function.

Case a=1a = 1: find two numbers

Multiplying out (x+m)(x+n)(x + m)(x + n) gives x2+(m+n)x+mnx^2 + (m + n)x + mn. So to factor x2+bx+cx^2 + bx + c you need two numbers whose

  • product is cc, and
  • sum is bb.
x2+7x+12:product 12, sum 7→ 3 and 4→ (x+3)(x+4)x2−2x−15:product −15, sum −2→ 3 and −5→ (x+3)(x−5)x2−9x+20:product 20, sum −9→ −4 and −5→ (x−4)(x−5)\begin{aligned} x^2 + 7x + 12{:}\quad &\text{product } 12,\ \text{sum } 7 && \to\ 3 \text{ and } 4 && \to\ (x + 3)(x + 4) \\ x^2 - 2x - 15{:}\quad &\text{product } -15,\ \text{sum } -2 && \to\ 3 \text{ and } -5 && \to\ (x + 3)(x - 5) \\ x^2 - 9x + 20{:}\quad &\text{product } 20,\ \text{sum } -9 && \to\ -4 \text{ and } -5 && \to\ (x - 4)(x - 5) \end{aligned}

The signs tell you where to look:

cc bb the two numbers
positive positive both positive
positive negative both negative
negative either opposite signs; the larger one (in size) has the sign of bb

Tip: List the factor pairs of cc in order (1⋅121 \cdot 12, 2⋅62 \cdot 6, 3⋅43 \cdot 4) and stop at the pair with the right sum. If none works, the trinomial does not factor over the integers. That is fine: the quadratic formula still solves the equation.

The AC method for any aa

When a≠1a \ne 1, guessing gets slow. The AC method turns the problem into factoring by grouping:

  1. Multiply a⋅ca \cdot c.
  2. Find two numbers mm and nn with m⋅n=acm \cdot n = ac and m+n=bm + n = b.
  3. Split the middle term: bx=mx+nxbx = mx + nx.
  4. Factor the four terms by grouping.

Example: 6x2+11x−106x^2 + 11x - 10.

1.ac=6⋅(−10)=−602.pairs of −60 with sum 11: 15 and −4(15⋅−4=−60, 15−4=11)3.6x2+15x−4x−104.3x(2x+5)−2(2x+5)4.=(2x+5)(3x−2)check: (2x+5)(3x−2)=6x2−4x+15x−10=6x2+11x−10 ✓\begin{aligned} &\text{1.}\quad ac = 6 \cdot (-10) = -60 \\ &\text{2.}\quad \text{pairs of } -60 \text{ with sum } 11{:}\ 15 \text{ and } -4 && (15 \cdot -4 = -60,\ 15 - 4 = 11) \\ &\text{3.}\quad 6x^2 + 15x - 4x - 10 \\ &\text{4.}\quad 3x(2x + 5) - 2(2x + 5) \\ &\phantom{\text{4.}}\quad = (2x + 5)(3x - 2) \\ &\text{check: } (2x + 5)(3x - 2) = 6x^2 - 4x + 15x - 10 = 6x^2 + 11x - 10\ \checkmark \end{aligned}

Why does it work? If the answer is (px+q)(rx+s)(px + q)(rx + s), then a=pra = pr, c=qsc = qs and b=ps+qrb = ps + qr. The two numbers psps and qrqr add to bb and multiply to pqrs=acpqrs = ac. Step 2 finds exactly those two numbers, and grouping separates them back into the two factors.

Note: Always take out a common factor first. 4x2+10x−6=2(2x2+5x−3)=2(2x−1)(x+3)4x^2 + 10x - 6 = 2(2x^2 + 5x - 3) = 2(2x - 1)(x + 3). Skipping this gives larger numbers in step 2 and an answer that is not fully factored.

The AC method in Python

The search in step 2 is the only hard part, and a computer can just try every divisor of acac:

python · try it yourself
from math import gcd

def ac_factor(a, b, c):
    ac = a * c
    for m in range(-abs(ac), abs(ac) + 1):
        if m != 0 and ac % m == 0 and m + ac // m == b:
            n = ac // m
            # group: (ax² + mx) + (nx + c); each pair's GCF (sign from its first term)
            g1 = gcd(a, m) * (1 if a > 0 else -1)
            g2 = gcd(n, c) * (1 if n > 0 else -1)
            # a x² + m x = g1·x·(a/g1 · x + m/g1);  n x + c = g2·(n/g2 · x + c/g2)
            return (g1, g2), (a // g1, m // g1)
    return None

def show(a, b, c):
    r = ac_factor(a, b, c)
    if r is None:
        print(f"{a}x² + {b}x + {c}: no integer factorization")
    else:
        (g1, g2), (p, q) = r
        print(f"{a}x² + {b}x + {c} = ({g1}x + {g2})({p}x + {q})")

show(6, 11, -10)
show(1, 7, 12)
show(2, -7, 3)
show(1, 1, 1)
6x² + 11x + -10 = (2x + 5)(3x + -2)
1x² + 7x + 12 = (1x + 4)(1x + 3)
2x² + -7x + 3 = (2x + -1)(1x + -3)
1x² + 1x + 1: no integer factorization

The printing is crude (+ -2 means −2-2), but the factors are right: (2x+5)(3x−2)(2x + 5)(3x - 2), (x+4)(x+3)(x + 4)(x + 3) and (2x−1)(x−3)(2x - 1)(x - 3). Because the leftover bracket after grouping is the same for both pairs, the code only needs the first pair's bracket and the two GCFs.

SymPy factors any polynomial with integer coefficients, so it is a convenient checker:

python · try it yourself
import sympy as sp

x = sp.symbols("x")
for expr in [6*x**2 + 11*x - 10, 4*x**2 + 10*x - 6, 12*x**2 - 17*x + 6, x**2 + x + 1]:
    print(expr, " =>  ", sp.factor(expr))
6*x**2 + 11*x - 10  =>   (2*x + 5)*(3*x - 2)
4*x**2 + 10*x - 6  =>   2*(x + 3)*(2*x - 1)
12*x**2 - 17*x + 6  =>   (3*x - 2)*(4*x - 3)
x**2 + x + 1  =>   x**2 + x + 1

x2+x+1x^2 + x + 1 comes back unchanged: it has no factors with rational coefficients (its roots are complex, see The Discriminant and Complex Roots).

In software

  • Root finding with exact numbers. Computer algebra systems factor polynomials over the integers to find exact rational roots before falling back on floating-point methods.
  • Quick test. ax2+bx+cax^2 + bx + c factors over the integers exactly when b2−4acb^2 - 4ac is a perfect square. math.isqrt(d)**2 == d checks that without any floating-point error.
  • Search problems. The AC search ("two numbers with a given product and sum") is a tiny instance of the two-sum problem from two pointers: with the divisors sorted, one pass from both ends finds the pair.

Exercises

Exercise 1: Leading coefficient 1

Factor x2+2x−24x^2 + 2x - 24.

Answer

(x+6)(x−4)(x + 6)(x - 4)

Solution

Product −24, sum 2. Pairs of opposite sign: (−1,24)(-1, 24), (−2,12)(-2, 12), (−3,8)(-3, 8), (−4,6)(-4, 6). Only −4+6=2-4 + 6 = 2.

Exercise 2: Both negative

Factor y2−13y+36y^2 - 13y + 36.

Answer

(y−4)(y−9)(y - 4)(y - 9)

Solution

Product +36, sum −13, so both numbers are negative. −4⋅−9=36-4 \cdot -9 = 36 and −4−9=−13-4 - 9 = -13.

Exercise 3: AC method

Factor 3x2−10x−83x^2 - 10x - 8.

Answer

(3x+2)(x−4)(3x + 2)(x - 4)

Solution
ac=3⋅(−8)=−24;need sum −10: 2 and −123x2+2x−12x−8=x(3x+2)−4(3x+2)=(3x+2)(x−4)\begin{aligned} &ac = 3 \cdot (-8) = -24; \quad \text{need sum } -10{:}\ 2 \text{ and } -12 \\ &3x^2 + 2x - 12x - 8 \\ &= x(3x + 2) - 4(3x + 2) \\ &= (3x + 2)(x - 4) \end{aligned}

Exercise 4: Common factor first

Factor 10x2−5x−1510x^2 - 5x - 15 completely.

Answer

5(2x−3)(x+1)5(2x - 3)(x + 1)

Solution
10x2−5x−15=5(2x2−x−3)ac=−6; sum −1: −3 and 22x2−3x+2x−3=x(2x−3)+(2x−3)=(2x−3)(x+1)\begin{aligned} &10x^2 - 5x - 15 = 5(2x^2 - x - 3) \\ &ac = -6;\ \text{sum } -1{:}\ -3 \text{ and } 2 \\ &2x^2 - 3x + 2x - 3 = x(2x - 3) + (2x - 3) = (2x - 3)(x + 1) \end{aligned}

Exercise 5: Which ones factor?

Use the perfect-square test b2−4acb^2 - 4ac to decide which of 2x2+5x+32x^2 + 5x + 3, x2+3x+1x^2 + 3x + 1 and 6x2−x−156x^2 - x - 15 factor over the integers. Write the check in Python.

Answer

2x2+5x+32x^2 + 5x + 3 (D=1D = 1) and 6x2−x−156x^2 - x - 15 (D=361=192D = 361 = 19^2) factor; x2+3x+1x^2 + 3x + 1 (D=5D = 5) does not.

Solution
python · try it yourself
from math import isqrt

for a, b, c in [(2, 5, 3), (1, 3, 1), (6, -1, -15)]:
    d = b * b - 4 * a * c
    ok = d >= 0 and isqrt(d) ** 2 == d
    print((a, b, c), "D =", d, "factors" if ok else "does not factor")
(2, 5, 3) D = 1 factors
(1, 3, 1) D = 5 does not factor
(6, -1, -15) D = 361 factors

The factorizations are (2x+3)(x+1)(2x + 3)(x + 1) and (2x+3)(3x−5)(2x + 3)(3x - 5).

Test yourself

Factor x2−x−12x^2 - x - 12.

  1. (x−3)(x+4)(x - 3)(x + 4)
  2. (x−4)(x+3)(x - 4)(x + 3)
  3. (x−6)(x+2)(x - 6)(x + 2)
  4. (x−12)(x+1)(x - 12)(x + 1)

In the AC method for 2x2+9x+42x^2 + 9x + 4, which two numbers split the middle term?

  1. 2 and 4
  2. 4 and 5
  3. 1 and 8
  4. 3 and 6

For a trinomial x2+bx+cx^2 + bx + c with c<0c < 0, the two numbers are…

  1. both positive
  2. both negative
  3. of opposite signs
  4. equal