Pre-Calculus for Programmers

Algebra foundations: the toolkit calculus never reteaches

10 / 397
Contents

Contents

Pre-Calculus for Programmers

0 of 397 complete

11 min read

Factoring: expanding, read backwards

Common factors, trinomials, grouping, and the three patterns that come up again and again.

Expanding turns a product into a sum, and it is mechanical. Going the other way, turning a sum into a product, is called factoring, and it is the move that makes cancelling possible. Almost every simplification in calculus is a cancellation waiting for a factorisation.

Before any method, notice that a factorisation leaves a trace you can look for. If x2−5x+6x^{2}-5x+6 equals (x−2)(x−3)(x-2)(x-3), then it must be zero whenever either bracket is zero. Print the values and see whether anything gives itself away.

Looking for the values that make it zeroPython

Change the -5 to -7 and the 6 to 12 and run it again. Two rows are zero. What brackets do those two numbers suggest?

Zeros appear at x=2x = 2 and x=3x = 3, which points at the factors (x−2)(x-2) and (x−3)(x-3). Multiply them back out to confirm: x2−3x−2x+6=x2−5x+6x^{2}-3x-2x+6 = x^{2}-5x+6. Scanning like that is a hint machine, not a method, because most factorisations do not have whole-number zeros. The methods follow.

Step one, always: the greatest common factor

The greatest common factor, or GCF, is the largest thing that divides every term: the largest number, and the lowest power of each letter that appears in all of them. Take it outside a bracket before anything else.

In 12x4−18x3+6x212x^{4}-18x^{3}+6x^{2} the numbers 12, 18 and 6 share a factor 6, and every term has at least x2x^{2}. So the GCF is 6x26x^{2}, and the expression is 6x2(2x2−3x+1)6x^{2}\left(2x^{2}-3x+1\right). Divide each term by 6x26x^{2} to get what stays inside, and check by multiplying back.

Trinomials with a leading coefficient of 1

A trinomial is a three-term polynomial. For x2+bx+cx^{2}+bx+c, expanding (x+p)(x+q)(x+p)(x+q) gives x2+(p+q)x+pqx^{2}+(p+q)x+pq, so the job is to find two numbers whose sum is bb and whose product is cc. Search for them if you like.

Two numbers with a given sum and productPython

Change to b = 1, c = 6 and run it again: nothing is found, and that trinomial genuinely does not factor with whole numbers. Then try b = 7, c = 12.

By hand the search is short, because the product pins it down. For x2−5x+6x^{2}-5x+6: the product 6 is positive and the sum −5-5 is negative, so both numbers are negative. The negative pairs multiplying to 6 are (−1,−6)(-1,-6) and (−2,−3)(-2,-3), and only the second adds to −5-5. So it factors as (x−2)(x−3)(x-2)(x-3).

  • cc positive and bb positive: both numbers positive.
  • cc positive and bb negative: both numbers negative.
  • cc negative: one of each sign, and the larger in size carries the sign of bb.

Trinomials with a leading coefficient that is not 1

For ax2+bx+cax^{2}+bx+c the same idea works with one extra step, usually called the ac method: find two numbers that multiply to a⋅ca \cdot c and add to bb, use them to split the middle term into two, then factor the four terms in pairs.

Work 6x2+7x−36x^{2}+7x-3 all the way through.

  1. There is no common factor, so start on the method. Here a=6a = 6, b=7b = 7, c=−3c = -3.
  2. Compute a⋅c=6⋅(−3)=−18a \cdot c = 6 \cdot (-3) = -18. Look for two numbers multiplying to −18-18 and adding to 7.
  3. The product is negative, so the numbers have opposite signs. Pairs multiplying to −18-18: (1,−18)(1,-18), (2,−9)(2,-9), (3,−6)(3,-6), (−1,18)(-1,18), (−2,9)(-2,9), (−3,6)(-3,6). The sums are −17-17, −7-7, −3-3, 1717, 77, 33.
  4. The pair that adds to 7 is −2-2 and 99.
  5. Split the middle term using them: 6x2−2x+9x−36x^{2}-2x+9x-3. The terms still add to the original, since −2x+9x=7x-2x+9x = 7x.
  6. Group the first two and the last two: (6x2−2x)+(9x−3)(6x^{2}-2x)+(9x-3).
  7. Take the GCF out of each group: 2x(3x−1)+3(3x−1)2x(3x-1) + 3(3x-1).
  8. The bracket (3x−1)(3x-1) is now a common factor of both pieces, so take it out: (3x−1)(2x+3)(3x-1)(2x+3).
  9. Check by expanding: 6x2+9x−2x−3=6x2+7x−36x^{2}+9x-2x-3 = 6x^{2}+7x-3.

Factoring by grouping

The pairing move in that example works on its own whenever there are four terms. x3+2x2−9x−18x^{3}+2x^{2}-9x-18 groups as (x3+2x2)−(9x+18)(x^{3}+2x^{2}) - (9x+18), which is x2(x+2)−9(x+2)x^{2}(x+2) - 9(x+2), and then (x+2)(x2−9)(x+2)(x^{2}-9). Watch the sign: the second group was −9x−18-9x-18, so what comes out is −9-9, leaving x+2x+2 and not −x−2-x-2.

That is not the end of it. The bracket x2−9x^{2}-9 is a difference of two squares, the first pattern in the table below, so it splits again into (x−3)(x+3)(x-3)(x+3), and the complete factorisation is (x+2)(x−3)(x+3)(x+2)(x-3)(x+3). Grouping is a step, not usually the last one: always look at what each bracket still contains.

The three patterns

NamePatternExample
Difference of squaresa2−b2=(a−b)(a+b)a^{2}-b^{2} = (a-b)(a+b)x2−9=(x−3)(x+3)x^{2}-9 = (x-3)(x+3)
Difference of cubesa3−b3=(a−b)(a2+ab+b2)a^{3}-b^{3} = (a-b)(a^{2}+ab+b^{2})x3−8=(x−2)(x2+2x+4)x^{3}-8 = (x-2)(x^{2}+2x+4)
Sum of cubesa3+b3=(a+b)(a2−ab+b2)a^{3}+b^{3} = (a+b)(a^{2}-ab+b^{2})27x3+1=(3x+1)(9x2−3x+1)27x^{3}+1 = (3x+1)(9x^{2}-3x+1)
Patterns worth recognising instantly, in both directions.

The signs in the two cube patterns follow one rhythm. The sign in the small bracket is the same as the original. The sign in front of the middle term of the big bracket is the opposite. The last sign is always positive. Some readers remember it as "same, opposite, always positive".

A sum of squares, a2+b2a^{2}+b^{2}, does not factor at all using real numbers, so x2+9x^{2}+9 is as factored as it gets.

An identity claims equality at every value, so it can be tested at many values at once.

Testing the cube patterns everywhere at oncePython

Change one a * b to 2 * a * b and run it again. The mismatch count jumps, which is what a wrong sign or a wrong coefficient looks like from the outside.

A worked example, every step

Factor 3x3−243x^{3}-24 completely.

  1. Common factor first. Both terms are divisible by 3, so 3x3−24=3(x3−8)3x^{3}-24 = 3(x^{3}-8).
  2. Look at the bracket. x3x^{3} is a cube and 8=238 = 2^{3} is a cube, with a minus between them, so this is a difference of cubes with a=xa = x and b=2b = 2.
  3. Apply the pattern a3−b3=(a−b)(a2+ab+b2)a^{3}-b^{3} = (a-b)(a^{2}+ab+b^{2}): the small bracket is (x−2)(x-2).
  4. The big bracket is x2+x⋅2+22=x2+2x+4x^{2} + x\cdot2 + 2^{2} = x^{2}+2x+4.
  5. So far: 3(x−2)(x2+2x+4)3(x-2)(x^{2}+2x+4).
  6. Can x2+2x+4x^{2}+2x+4 factor further? It would need two numbers multiplying to 4 and adding to 2, and the pairs (1,4)(1,4) and (2,2)(2,2) add to 5 and 4. So no, it is finished.
  7. Check at x=3x = 3: the original is 81−24=5781-24 = 57, and the factorisation gives 3⋅1⋅(9+6+4)=3⋅19=573 \cdot 1 \cdot (9+6+4) = 3 \cdot 19 = 57.
Check yourself

Factor 4x2−364x^{2}-36 completely.

Factor 2x3+2x2−12x2x^{3}+2x^{2}-12x completely.

2x(x+3)(x−2)2x(x+3)(x-2). The GCF is 2x2x, because every term has a 2 and an xx, leaving 2x(x2+x−6)2x(x^{2}+x-6). Then x2+x−6x^{2}+x-6 needs two numbers multiplying to −6-6 and adding to 1: those are 3 and −2-2, giving (x+3)(x−2)(x+3)(x-2). Check at x=1x = 1: the original is 2+2−12=−82+2-12 = -8, and the factorisation gives 2⋅4⋅(−1)=−82 \cdot 4 \cdot (-1) = -8.

All lessons in Pre-Calculus for Programmers