Pre-Calculus for Programmers

Algebra foundations: the toolkit calculus never reteaches

8 / 397
Contents

Contents

Pre-Calculus for Programmers

0 of 397 complete

10 min read

Multiplying out, and the products worth memorising

Every term times every term, why the middle term exists, and the three patterns that save you from doing it longhand.

Consider a rectangle whose width is 3 metres more than some length xx, and whose height is 5 metres more than the same xx. Its area is (x+3)(x+5)(x+3)(x+5), and somebody wants that written without brackets.

There is a claim to test: that (x+3)(x+5)(x+3)(x+5) and x2+8x+15x^{2}+8x+15 are the same thing for every xx. Two expressions in one letter are equal only if they agree at every value, so test a spread of values.

Are these two the same expression?Python

Change the 8 to a 7 and run it again. Every row disagrees. That is what a wrong expansion looks like, and it is worth seeing once.

The words

The expression just expanded, x2+8x+15x^{2}+8x+15, has three pieces added together, and each piece has a name. A term is a product of numbers and letters with whole-number powers. So x2x^{2}, 8x8x and 1515 are the three terms here, and −7x3-7x^{3} is a term as well.

The number multiplying the letters in a term is its coefficient. In 8x8x the coefficient is 8, and in −7x3-7x^{3} it is −7-7, with the minus sign belonging to the number. A term such as x2x^{2} with no number written has a coefficient of 1, because multiplying by 1 changes nothing and is left out.

The power of the letter in a term is that term's degree: −7x3-7x^{3} has degree 3, 8x8x has degree 1, and the plain number 15 has degree 0, since 15=15x015 = 15x^{0}.

A polynomial is a sum of terms, such as 2x3−5x+12x^{3}-5x+1, and the degree of the whole polynomial is the largest degree among its terms, which here is 3. The coefficient of that highest term is the leading coefficient, and in 2x3−5x+12x^{3}-5x+1 it is the 2.

What are the degree and the leading coefficient of 4−x2+6x54 - x^{2} + 6x^{5}?

The degree is 5 and the leading coefficient is 6. Read the degrees of the three terms: 4 has degree 0, −x2-x^{2} has degree 2, and 6x56x^{5} has degree 5. The largest is 5, so that is the degree of the polynomial, and the coefficient sitting on that term is 6. Answering 4 for the leading coefficient reads the term written first rather than the term of highest degree, and the two need not be the same when the terms are out of order.

Like terms have identical letters raised to identical powers. 4x24x^{2} and −9x2-9x^{2} are like terms and collapse to −5x2-5x^{2}; 4x24x^{2} and 4x34x^{3} are not, and cannot be combined at all. Adding polynomials is nothing but collecting like terms.

Subtracting is the same with one hazard: the minus sign applies to every term in the bracket that follows, not only the first. (5x2−3x+1)−(2x2−7x+4)(5x^{2}-3x+1)-(2x^{2}-7x+4) becomes 5x2−3x+1−2x2+7x−45x^{2}-3x+1-2x^{2}+7x-4, which is 3x2+4x−33x^{2}+4x-3. Two of the three signs changed.

Multiplying: every term by every term

To multiply two polynomials, multiply each term of the first by each term of the second and collect. If the first has 3 terms and the second has 2, you will write down 3×2=63 \times 2 = 6 products before collecting, and if you have fewer than six you have missed one.

The bookkeeping is easy to automate, and doing so shows the shape of it. Store a polynomial as a list of coefficients, lowest power first, so x+3x+3 is stored as [3, 1], meaning 3+1x3 + 1x.

Multiplying polynomials as lists of coefficientsPython

Change b to [5, 1, 2], which is 2x2+x+52x^{2}+x+5, and run it again. How many numbers come back now, and why that many?

The line that matters is prod[i + j] += a[i] * b[j]. Powers add when terms multiply, which is one of the exponent laws, so the product of the iith and jjth terms lands in slot i+ji+j. Two different pairs can land in the same slot, and that is exactly what produces a middle term.

Where the middle term comes from

(a+b)2(a+b)^{2} means (a+b)(a+b)(a+b)(a+b), so there are four products: a⋅aa\cdot a, a⋅ba \cdot b, b⋅ab \cdot a and b⋅bb \cdot b. The two mixed ones are equal and both land in the same slot, so they arrive as 2ab2ab. That is the term people lose.

(a+b)2=a2+2ab+b2(a−b)2=a2−2ab+b2(a+b)^{2} = a^{2}+2ab+b^{2} \qquad (a-b)^{2} = a^{2}-2ab+b^{2}
The middle term is twice the product of the two pieces, and it carries the sign between them.

The third pattern is the one from the lesson on simplest form. In (a+b)(a−b)(a+b)(a-b) the mixed products are −ab-ab and +ab+ab, so this time they cancel instead of doubling.

(a+b)(a−b)=a2−b2(a+b)(a-b) = a^{2}-b^{2}
Called the difference of two squares. This is the identity behind every conjugate trick in this section.
PatternExampleResult
(a+b)2(a+b)^{2}(2x+5)2(2x+5)^{2}4x2+20x+254x^{2}+20x+25
(a−b)2(a-b)^{2}(3x−4)2(3x-4)^{2}9x2−24x+169x^{2}-24x+16
(a+b)(a−b)(a+b)(a-b)(2x+5)(2x−5)(2x+5)(2x-5)4x2−254x^{2}-25
(a+b)3(a+b)^{3}(x+2)3(x+2)^{3}x3+6x2+12x+8x^{3}+6x^{2}+12x+8
(a−b)3(a-b)^{3}(x−1)3(x-1)^{3}x3−3x2+3x−1x^{3}-3x^{2}+3x-1
The special products, with one worked instance of each.

A worked example, every step

Expand (3x−4)2(3x-4)^{2} by hand, using the pattern rather than writing out all four products.

  1. Identify the pieces: a=3xa = 3x and b=4b = 4, with a minus between them.
  2. First term, a2a^{2}: (3x)2=32x2=9x2(3x)^{2} = 3^{2}x^{2} = 9x^{2}.
  3. Middle term, −2ab-2ab: −2⋅3x⋅4=−24x-2 \cdot 3x \cdot 4 = -24x.
  4. Last term, b2b^{2}: 42=164^{2} = 16. It is positive, because a negative squared is positive.
  5. So (3x−4)2=9x2−24x+16(3x-4)^{2} = 9x^{2}-24x+16.
  6. Check at x=1x = 1: the bracket gives (−1)2=1(-1)^{2} = 1, and the expansion gives 9−24+16=19-24+16 = 1.

Higher powers, the slow way

(a+b)5(a+b)^{5} can be got by multiplying by (a+b)(a+b) five times over, and for a computer that is a perfectly reasonable plan. Run it on (1+x)n(1+x)^{n} and watch the coefficients that come out.

Expanding by repeated multiplicationPython

Change [1, 1] to [2, 1], which is x+2x+2, and run it again. The numbers are no longer symmetric. Which end grows, and why that end?

The rows that come out are 1 1, then 1 2 1, then 1 3 3 1, then 1 4 6 4 1. Those numbers have a pattern of their own, and finding it means never having to run the multiplication again. That is the next lesson.

Expand (2x+3)(x2−x+4)(2x+3)(x^{2}-x+4).

2x3−2x2+8x+3x2−3x+122x^{3}-2x^{2}+8x+3x^{2}-3x+12, which collects to 2x3+x2+5x+122x^{3}+x^{2}+5x+12. There were 2×3=62 \times 3 = 6 products before collecting: 2x⋅x22x \cdot x^{2}, 2x⋅(−x)2x \cdot (-x), 2x⋅42x \cdot 4, 3⋅x23 \cdot x^{2}, 3⋅(−x)3\cdot(-x) and 3⋅43 \cdot 4. Check at x=1x = 1: the brackets give 5⋅4=205 \cdot 4 = 20, and the answer gives 2+1+5+12=202+1+5+12 = 20.

All lessons in Pre-Calculus for Programmers