Monocurl Essays
Series Download

Completing the square and the quadratic formula

Solve x² + 6x = 16 by rearranging a square and a rectangle into a bigger square with one corner missing, then turn that picture into the quadratic formula.

23 min·High school·

AssumesThe distributive law as a picture: FOIL and (a+b)²Why is a negative times a negative positive?

A square of side $x$ and a 6 by $x$ rectangle have total area 16. The rectangle is cut into two 3 by $x$ strips and one is moved to the top, leaving a larger square with a 3 by 3 corner missing. Filling the corner gives $(x+3)^2 = 25$.
Monocurl source
mesh sq = Slab([X0, Y0, 0], XV * G, XV * G, AZURE)
mesh rect = Slab([X0 + XV * G, Y0, 0], B * G, XV * G, EMBER)
mesh sa = []
mesh sb = []
mesh corner = []
mesh labels = [
    Lab([X0 + XV * G / 2, Y0 + XV * G / 2, 0], "x^2", AZURE),
    Lab([X0 + (XV + B / 2) * G, Y0 + XV * G / 2, 0], str_join([to_string(B), "x"]), EMBER)
]
mesh eqs = Lines([eq_start], [INK])

slide "wrap"
    play Wait(0.9)
    labels = []
    rect = []
    sa = Slab([X0 + XV * G, Y0, 0], HB * G, XV * G, EMBER)
    sb = Slab(p: [X0 + (XV + HB) * G + 0.15, Y0, 0], HB * G, XV * G, EMBER, turn: 0)
    play Fade(0.5)
    sb.p = [X0 + XV * G, Y0 + XV * G, 0]
    sb.turn = PI / 2
    play Lerp(1.8, [&sb])
    labels = WrapLabels(0)
    play Fade(0.5, [&labels])
    corner = Corner
    labels = WrapLabels(1)
    eqs = Lines([eq_start, eq_added, eq_square], [INK, LEAF, INK])
    play Fade(0.8)
    play Wait(2.4)

Uses the shared definitions for this lesson's figures.

Try to solve

$$ x^2 + 6x = 16. $$

If the equation were $x^2 = 16$ you would take a square root and be done. If it were $6x = 16$ you would divide by 6. The trouble is that $x$ appears twice, once squared and once not, and no single operation undoes both at the same time. Taking the square root of both sides produces $\sqrt{x^2 + 6x}$, which does not simplify. Dividing by $x$ gives $x + 6 = 16/x$, which still has $x$ on both sides.

This lesson follows a method that is about twelve hundred years old. It rearranges the left side, by cutting and moving areas, until the equation says “something squared equals a number”, which is the kind of equation a square root does solve. The method is called completing the square. Applied once to an equation with letters for coefficients, it produces the quadratic formula.

What goes wrong with guessing

One natural first move is to factor the left side: $x^2 + 6x = x(x + 6)$, so we want two numbers that differ by 6 and multiply to 16. Trying small numbers, $2 \times 8 = 16$, so $x = 2$ works. Check: $2^2 + 6 \times 2 = 4 + 12 = 16$.

Guessing succeeded because the answer was a whole number. Change the right side to 10 and it fails. At $x = 1$ the left side is 7 and at $x = 2$ it is 16, so the solution of $x^2 + 6x = 10$ is somewhere between 1 and 2, and no amount of trying whole numbers will find it.

The graph of x^2 + 6x for positive x. It reaches the value 16 exactly at x = 2, and it reaches the value 10 at a point between 1 and 2 that is not a whole number or a simple fraction.
The graph of $x^2 + 6x$ for positive $x$. It reaches the value 16 exactly at $x = 2$, and it reaches the value 10 at a point between 1 and 2 that is not a whole number or a simple fraction.
Monocurl source
let fg = Frame(0, 3.1, 0, 28, [-0.1, 0.05, 0], 5.6, 3.3)
let f = |x| x * x + 6 * x
let r = sqrt(19) - 3
mesh grid = GridLines(fg, [0.5, 1, 1.5, 2, 2.5, 3], [5, 10, 15, 20, 25])
mesh axes = [
    Axes(fg, "x"),
    XTicks(fg, [1, 3]),
    YTicks(fg, [5, 10, 16, 25]),
    center{[fx(fg, 0) + 0.75, fy(fg, 28) + 0.3, 0]} Math("x^2 + 6x", 0.8, AZURE)
]
mesh levels = [
    Seg(at(fg, 0, 16), at(fg, 2, 16), LEAF, 2.5),
    Seg(at(fg, 2, 16), at(fg, 2, 0), LEAF, 2.5),
    Seg(at(fg, 0, 10), at(fg, r, 10), ROSE, 2.5),
    Seg(at(fg, r, 10), at(fg, r, 0), ROSE, 2.5)
]
mesh curve = Graph(fg, f, 0, 3.05)
mesh marks = [
    Pt(at(fg, 2, 16), LEAF, 0.1),
    Pt(at(fg, r, 10), ROSE, 0.1),
    center{[fx(fg, 2) + 0.05, fy(fg, 0) - 0.33, 0]} Math("2", 0.8, LEAF),
    center{[fx(fg, r) - 0.1, fy(fg, 0) - 0.33, 0]} Math(to_string(r, 3), 0.8, ROSE)
]

Uses the shared definitions for this lesson's figures.

A second tempting move is worse. From $x(x + 6) = 16$ some students conclude that $x = 16$ or $x + 6 = 16$. That reasoning is valid only when the right side is 0, because a product is zero exactly when one factor is zero. Nothing similar holds for 16: at $x = 16$ the product is $16 \times 22 = 352$.

So we need a method that does not depend on the answer being convenient.

An equation we can solve

It helps to look first at an equation of the same family that is easy.

Pause and try

Find every real number $x$ with $(x + 3)^2 = 25$. There is more than one.

Show answerHide answer

The quantity $x + 3$ is a number whose square is 25, so $x + 3 = 5$ or $x + 3 = -5$. That gives $x = 2$ or $x = -8$. Check the second one: $(-8 + 3)^2 = (-5)^2 = 25$.

This equation also contains $x^2$ and a multiple of $x$, which you can see by expanding: $(x+3)^2 = x^2 + 6x + 9$. They are hidden inside one square, and because of that a square root reaches both at once.

Now compare with our problem. The left side of $x^2 + 6x = 16$ is exactly $(x + 3)^2$ with the 9 left off. So our expression is nine short of a perfect square, and the plan is to supply the nine. The next section shows where the 9 comes from, so that you could find the right number for any equation of this kind.

The two solutions of (x+3)^2 = 25 on a number line. The equation says that x + 3 is 5 or -5, so x lies at distance 5 from -3 on one side or the other: x = 2 or x = -8.
The two solutions of $(x+3)^2 = 25$ on a number line. The equation says that $x + 3$ is $5$ or $-5$, so $x$ lies at distance 5 from $-3$ on one side or the other: $x = 2$ or $x = -8$.
Monocurl source
let U = 0.48
let P = |v| [(v + 3) * U, -0.2, 0]
mesh line = block {
    . Seg(P(-10.4), P(4.4), SLATE, 2.5)
    for (v in range(-10, 5)) {
        . Seg([P(v)[0], -0.28, 0], [P(v)[0], -0.12, 0], SLATE, 2.5)
    }
    for (v in [-10, -6, -4, -2, 0, 4]) {
        . center{[P(v)[0], -0.58, 0]} Math(to_string(v), 0.72, SLATE)
    }
}
mesh spans = [
    Tip([P(-3)[0] - 0.08, 0.35, 0], [P(-8)[0], 0.35, 0], EMBER, 3),
    Tip([P(-3)[0] + 0.08, 0.35, 0], [P(2)[0], 0.35, 0], EMBER, 3),
    Seg([P(-3)[0], -0.2, 0], [P(-3)[0], 0.55, 0], EMBER, 2.5),
    center{[P(-5.5)[0], 0.7, 0]} Math("5", 0.9, EMBER),
    center{[P(-0.5)[0], 0.7, 0]} Math("5", 0.9, EMBER)
]
mesh marks = [
    Pt(P(-3), EMBER, 0.09),
    Pt(P(-8), LEAF, 0.12),
    Pt(P(2), LEAF, 0.12),
    center{[P(-3)[0], -0.6, 0]} Math("-3", 0.85, EMBER),
    center{[P(-8)[0], -0.62, 0]} Math("x = -8", 0.85, LEAF),
    center{[P(2)[0], -0.62, 0]} Math("x = 2", 0.85, LEAF),
    center{[0, 1.6, 0]} Math("(x + 3)^2 = 25", 1.0),
    center{[0, -1.55, 0]} Math("x + 3 = 5 \quad \text{or} \quad x + 3 = -5", 0.9)
]

Uses the shared definitions for this lesson's figures.

The picture: a square with a corner missing

Read $x^2 + 6x$ as an area. The term $x^2$ is a square whose side is the unknown length $x$. The term $6x$ is a rectangle that is 6 wide and $x$ tall. The equation says that these two shapes together cover 16 square units. (The figures are drawn with the true value of $x$ so that they are to scale, but the argument never uses that value.)

If the two shapes could be rearranged into a single square, we could read off its side length with a square root. Step through the attempt.

  1. A square of side x and a 6 by x rectangle together have area 16.
  2. Cut the rectangle into two equal strips, each 3 wide and x tall.
  3. Turn one strip and set it on top of the square. The total area is still 16.
  4. The shape is a square of side x + 3 with a 3 by 3 corner missing. Add those 9 units to both sides.
  5. The completed square has area 25, so its side is 5. The side is also x + 3, so x = 2.
Solving $x^2 + 6x = 16$ by rearranging areas. The 6 by $x$ rectangle is cut into two 3 by $x$ strips, which are placed on two sides of the $x$ by $x$ square. A 3 by 3 corner is missing. Adding it to both sides gives a square of area 25 and side $x + 3 = 5$.
Monocurl source
mesh sq = []
mesh rect = []
mesh sa = []
mesh sb = []
mesh corner = []
mesh labels = []
mesh eqs = []

slide "A square of side x and a 6 by x rectangle together have area 16."
    sq = Slab([X0, Y0, 0], XV * G, XV * G, AZURE)
    rect = Slab([X0 + XV * G, Y0, 0], B * G, XV * G, EMBER)
    labels = [
        Lab([X0 + XV * G / 2, Y0 + XV * G / 2, 0], "x^2", AZURE),
        Lab([X0 + (XV + B / 2) * G, Y0 + XV * G / 2, 0], str_join([to_string(B), "x"]), EMBER),
        Lab([X0 + XV * G / 2, Y0 - 0.3, 0], "x"),
        Lab([X0 + (XV + B / 2) * G, Y0 - 0.3, 0], to_string(B)),
        Lab([X0 - 0.3, Y0 + XV * G / 2, 0], "x")
    ]
    eqs = Lines([eq_start], [INK])
    play Fade(0.8)

slide "Cut the rectangle into two equal strips, each 3 wide and x tall."
    labels = []
    rect = []
    play Fade(0.3, [&labels, &rect])
    sa = Slab([X0 + XV * G, Y0, 0], HB * G, XV * G, EMBER)
    sb = Slab(p: [X0 + (XV + HB) * G + 0.15, Y0, 0], HB * G, XV * G, EMBER, turn: 0)
    labels = [
        Lab([X0 + XV * G / 2, Y0 + XV * G / 2, 0], "x^2", AZURE),
        Lab([X0 + (XV + HB / 2) * G, Y0 + XV * G / 2, 0], half_tex, EMBER),
        Lab([X0 + (XV + HB + HB / 2) * G + 0.15, Y0 + XV * G / 2, 0], half_tex, EMBER),
        Lab([X0 + XV * G / 2, Y0 - 0.3, 0], "x"),
        Lab([X0 + (XV + HB / 2) * G, Y0 - 0.3, 0], to_string(HB)),
        Lab([X0 + (XV + HB + HB / 2) * G + 0.15, Y0 - 0.3, 0], to_string(HB)),
        Lab([X0 - 0.3, Y0 + XV * G / 2, 0], "x")
    ]
    play Fade(0.6)

slide "Turn one strip and set it on top of the square. The total area is still 16."
    labels = []
    play Fade(0.3, [&labels])
    sb.p = [X0 + XV * G, Y0 + XV * G, 0]
    sb.turn = PI / 2
    play Lerp(1.8, [&sb])
    labels = WrapLabels(0)
    play Fade(0.5, [&labels])

slide "The shape is a square of side x + 3 with a 3 by 3 corner missing. Add those 9 units to both sides."
    corner = Corner
    labels = WrapLabels(1)
    eqs = Lines([eq_start, eq_added], [INK, LEAF])
    play Fade(0.8)

slide "The completed square has area 25, so its side is 5. The side is also x + 3, so x = 2."
    eqs = Lines(
        [eq_start, eq_added, eq_square, str_join(["x + ", to_string(HB), " = 5"]), "x = 2"],
        [INK, LEAF, INK, INK, AZURE])
    play Fade(0.8)

Uses the shared definitions for this lesson's figures.

Three things happened, and each has an exact counterpart in algebra.

Cutting the rectangle in half is the reason the number 3 appears: it is half of the 6. The two strips then line two sides of the square, and the L-shaped figure they make with it has outer side $x + 3$.

The missing corner is bounded by the ends of the two strips, each of which is 3 wide, so it is a 3 by 3 square of area 9. This is where the 9 comes from. It is the square of half of 6.

Finally, filling the corner changes the area, and an equation only stays true if both sides are changed by the same amount. So 9 is added to the right side as well: $16 + 9 = 25$. Written out,

$$ x^2 + 6x + 9 = 16 + 9 \quad\text{which is}\quad (x + 3)^2 = 25. $$

That is the equation from the previous section. Its solutions are $x = 2$ and $x = -8$.

The picture found only $x = 2$, because a length cannot be negative. The algebra does not care, and $x = -8$ is a perfectly good solution of the original equation: $(-8)^2 + 6 \times (-8) = 64 - 48 = 16$.

Completing the square for any coefficient

Nothing in the argument was special to the number 6. With $x^2 + bx$, the rectangle is $b$ wide, each strip is $\frac{b}{2}$ wide, and the missing corner is a square of side $\frac{b}{2}$.

Pause and try

The expression $x^2 + 10x$ is a square of side $x$ with a 10 by $x$ rectangle. How wide are the two strips, what is the area of the missing corner, and what is the side of the completed square? Use this to solve al-Khwarizmi’s equation $x^2 + 10x = 39$.

Show answerHide answer

Each strip is 5 wide, the corner is 5 by 5 with area 25, and the completed square has side $x + 5$. Adding 25 to both sides gives $(x + 5)^2 = 64$, so $x + 5 = 8$ or $x + 5 = -8$, and $x = 3$ or $x = -13$. Check: $9 + 30 = 39$ and $169 - 130 = 39$.

Completing the square for $x^2 + bx$ as $b$ varies from 4 to 6. Each strip has width $b/2$, so the corner needed to complete the square is always a square of side $b/2$ and area $(b/2)^2$.
Monocurl source
let GG = 0.7
let XX = 2
let PX = -3.55
let PY = -1.42
let Wrapped = |b| {
    let x = XX * GG
    let w = b / 2 * GG
    return [
        Slab([PX, PY, 0], x, x, AZURE),
        Slab([PX + x, PY, 0], w, x, EMBER),
        Slab([PX, PY + x, 0], x, w, EMBER),
        Slab([PX + x, PY + x, 0], w, w, LEAF, 0, 0.4),
        Lab([PX + x / 2, PY + x / 2, 0], "x^2", AZURE),
        Lab([PX + x + w / 2, PY + x / 2, 0], "\frac{b}{2}x", EMBER, 0.95),
        Lab([PX + x / 2, PY + x + w / 2, 0], "\frac{b}{2}x", EMBER, 0.95),
        Lab([PX + x + w / 2, PY + x + w / 2, 0], "\left(\frac{b}{2}\right)^2", LEAF, 0.92),
        Lab([PX + x + w / 2, PY - 0.4, 0], "\frac{b}{2}", INK, 0.88),
        center{[2.95, 1.1, 0]} scale{1.2} color{EMBER} Number(b, 1),
        center{[2.95, 0.1, 0]} scale{1.2} color{INK} Number(b / 2, 2),
        center{[2.95, -0.9, 0]} scale{1.2} color{LEAF} Number(b * b / 4, 2)
    ]
}
mesh names = [
    Lab([PX + XX * GG / 2, PY - 0.3, 0], "x"),
    Lab([1.6, 1.1, 0], "b", EMBER, 0.95),
    Lab([1.6, 0.1, 0], "\frac{b}{2}", INK, 0.95),
    Lab([1.6, -0.9, 0], "\left(\frac{b}{2}\right)^2", LEAF, 0.95)
]
mesh fig = Wrapped(b: 4)

slide "vary b"
    play Wait(0.8)
    fig.b = 6
    play Lerp(3, [&fig])
    play Wait(1.2)
    fig.b = 4
    play Lerp(3, [&fig])
    play Wait(1)

Uses the shared definitions for this lesson's figures.

The rule that comes out of the picture is: take half the coefficient of $x$, and square it. That is the number that completes the square.

The picture justifies this when $x$ and $b$ are positive lengths. The statement is true for all real numbers, and the proof is one line of algebra.

Because the theorem holds for every real $b$, it covers cases the picture cannot draw. If $b = -6$, half of it is $-3$ and the square of that is 9, so $x^2 - 6x = (x - 3)^2 - 9$. The corner is still added, because a square is never negative.

Solving a squared equation exactly

Completing the square always ends with an equation of the form $u^2 = k$. We should be precise about its solutions, since forgetting one of them is the most common error in this topic.

The symbol $\pm$ is shorthand for the first case: $u = \pm\sqrt{k}$ means “$u = \sqrt{k}$ or $u = -\sqrt{k}$”.

Worked examples

The quadratic formula

The third example involved more arithmetic than insight. The steps were the same as before, with fractions. That is a sign that the work can be done once, with letters, and the result reused.

A quadratic equation is an equation of the form $ax^2 + bx + c = 0$, where $a$, $b$ and $c$ are given real numbers and $a \ne 0$. (If $a$ were 0 there would be no $x^2$ term and the equation would not be quadratic.)

Pause and try

Before reading the derivation, carry out the first two steps yourself on $ax^2 + bx + c = 0$: divide by $a$ and move the constant to the right. What is the coefficient of $x$ now, and what number must be added to both sides to complete the square?

Show answerHide answer

Dividing by $a$ and moving the constant gives $x^2 + \frac{b}{a}x = -\frac{c}{a}$. The coefficient of $x$ is $\frac{b}{a}$. Half of it is $\frac{b}{2a}$, and its square, $\frac{b^2}{4a^2}$, is the number to add.

The formula is usually written in one line, $x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a}$. Every part of it is something from the picture. The $-\frac{b}{2a}$ is the half-width of the strips, moved to the other side. The quantity under the root is the area of the completed square, up to the positive factor $4a^2$.

Test it on the running example. For $x^2 + 6x - 16 = 0$ we have $a = 1$, $b = 6$, $c = -16$, so $D = 36 + 64 = 100$ and $x = \frac{-6 \pm 10}{2}$, which is $2$ or $-8$, as before.

The discriminant: is the completed square positive?

The number $D = b^2 - 4ac$ is called the discriminant, because it discriminates between the three cases. The proof shows what it measures. After completing the square, the equation says that a square equals $\frac{D}{4a^2}$. A square can equal a positive number in two ways, zero in one way, and a negative number in no way.

Pause and try

Without solving, decide how many real solutions $x^2 + 6x + 10 = 0$ has. Then complete the square to see why.

Show answerHide answer

Here $D = 36 - 40 = -4$, which is negative, so there are no real solutions. Completing the square gives $(x + 3)^2 + 1 = 0$, that is, $(x + 3)^2 = -1$, and no real number has a negative square.

The graph makes the three cases visible. The graph of $y = x^2 + 6x + c$ is a curve called a parabola, and the solutions of $x^2 + 6x + c = 0$ are the places where it meets the $x$ axis. Completing the square rewrites the function as $y = (x + 3)^2 + (c - 9)$. The squared part is smallest, namely zero, at $x = -3$, so the lowest point of the curve is at $x = -3$ and its height there is $c - 9$. Changing $c$ slides the whole curve up or down, since adding a constant to a function shifts its graph vertically.

The parabola $y = x^2 + 6x + c$ as $c$ rises from 5 to 13. Its lowest point is at $x = -3$ with height $c - 9$. While the lowest point is below the axis there are two solutions, at $c = 9$ they merge into one, and above that there are none. The discriminant $36 - 4c$ changes sign at the same moment.
Monocurl source
let fq = Frame(-7, 1, -6, 12, [-1.35, 0.1, 0], 4.2, 3.4)
let Lift = |c| {
    let reach = sqrt(11.5 - c + 9)
    let f = |x| x * x + 6 * x + c
    let disc = 36 - 4 * c
    var count = 0
    if (disc > 0.0001) { count = 2 }
    if (abs(disc) <= 0.0001) { count = 1 }
    var parts = [
        stroke{AZURE, 4} Polyline(map(sample(-3 - reach, -3 + reach, 80), |x| at(fq, x, f(x)))),
        Pt(at(fq, -3, c - 9), EMBER, 0.09)
    ]
    if (disc >= 0) {
        let d = sqrt(disc) / 2
        parts .= Pt(at(fq, -3 - d, 0), LEAF, 0.11)
        parts .= Pt(at(fq, -3 + d, 0), LEAF, 0.11)
    }
    var shown = disc
    if (abs(disc) < 0.05) { shown = 0 }
    parts .= center{[3.1, 1.1, 0]} scale{1.2} color{INK} Number(c, 1)
    parts .= center{[3.1, 0.1, 0]} scale{1.2} color{EMBER} Number(shown, 1)
    parts .= center{[3.1, -0.9, 0]} scale{1.2} color{LEAF} Number(count, 0)
    return parts
}
mesh grid = GridLines(fq, [-6, -5, -4, -3, -2, -1], [-4, 4, 8])
mesh axes = [
    Axes(fq, "x"),
    Lab([fx(fq, 0) + 0.32, fy(fq, 12) + 0.12, 0], "y", SLATE, 0.9),
    Lab([fx(fq, -6) - 0.06, fy(fq, -6) - 0.28, 0], "-6", SLATE, 0.9),
    Lab([fx(fq, -3) - 0.06, fy(fq, -6) - 0.28, 0], "-3", SLATE, 0.9),
    Lab([fx(fq, -1) - 0.06, fy(fq, -6) - 0.28, 0], "-1", SLATE, 0.9),
    Lab([fx(fq, 0) + 0.3, fy(fq, 4), 0], "4", SLATE, 0.9),
    Lab([fx(fq, 0) + 0.3, fy(fq, 8), 0], "8", SLATE, 0.9),
    Lab([fx(fq, 0) + 0.42, fy(fq, -4), 0], "-4", SLATE, 0.9)
]
mesh names = [
    Lab([1.85, 1.1, 0], "c", INK, 0.95),
    Lab([1.85, 0.1, 0], "b^2 - 4ac", EMBER, 0.85),
    center{[1.85, -0.9, 0]} Cap("solutions", 0.8, LEAF)
]
mesh curve = Lift(c: 5)

slide "lift"
    play Wait(0.9)
    curve.c = 9
    play Lerp(2.4, [&curve])
    play Wait(1.1)
    curve.c = 13
    play Lerp(2.4, [&curve])
    play Wait(1.4)

Uses the shared definitions for this lesson's figures.

For the running example, $c = -16$ and the curve is $y = (x + 3)^2 - 25$. Its lowest point is at $(-3, -25)$, and it crosses the axis where $(x + 3)^2 = 25$, which is 5 units to either side of $-3$.

The parabola y = x^2 + 6x - 16 = (x+3)^2 - 25. Its lowest point is at (-3, -25), and its two crossings of the x axis, at -8 and 2, lie 5 units on either side of the line x = -3.
The parabola $y = x^2 + 6x - 16 = (x+3)^2 - 25$. Its lowest point is at $(-3, -25)$, and its two crossings of the $x$ axis, at $-8$ and $2$, lie 5 units on either side of the line $x = -3$.
Monocurl source
let fr = Frame(-10.5, 4.5, -29, 26, [0.1, 0, 0], 6.2, 3.8)
let f = |x| x * x + 6 * x - 16
mesh grid = GridLines(fr, [-10, -8, -6, -4, -2, 2, 4], [-20, -10, 10, 20])
mesh axes = [
    Axes(fr, "x", "y"),
    Lab([fx(fr, 0) + 0.38, fy(fr, 20), 0], "20", SLATE, 0.72),
    Lab([fx(fr, 0) + 0.38, fy(fr, 10), 0], "10", SLATE, 0.72),
    Lab([fx(fr, 0) + 0.45, fy(fr, -20), 0], "-20", SLATE, 0.72)
]
mesh axis = block {
    for (k in range(1, 13)) {
        . Seg(at(fr, -3, -27 + k * 4), at(fr, -3, -24.6 + k * 4), EMBER, 2.5)
    }
    . Lab([fx(fr, -3), fy(fr, 26) + 0.05, 0], "x = -3", EMBER, 0.78)
}
mesh curve = Graph(fr, f, -9.95, 3.95)
mesh spans = [
    Tip([fx(fr, -3) - 0.08, fy(fr, -9), 0], at(fr, -8, -9), EMBER, 3),
    Tip([fx(fr, -3) + 0.08, fy(fr, -9), 0], at(fr, 2, -9), EMBER, 3),
    Lab([fx(fr, -5.5), fy(fr, -9) + 0.28, 0], "5", EMBER, 0.85),
    Lab([fx(fr, -0.9), fy(fr, -9) + 0.28, 0], "5", EMBER, 0.85)
]
mesh marks = [
    Pt(at(fr, -8, 0), LEAF, 0.11),
    Pt(at(fr, 2, 0), LEAF, 0.11),
    Pt(at(fr, -3, -25), EMBER, 0.1),
    Lab([fx(fr, -8) - 0.42, fy(fr, 0) - 0.3, 0], "-8", LEAF, 0.85),
    Lab([fx(fr, 2) + 0.3, fy(fr, 0) - 0.3, 0], "2", LEAF, 0.85),
    Lab([fx(fr, -3), fy(fr, -25) - 0.36, 0], "(-3, -25)", EMBER, 0.8)
]

Uses the shared definitions for this lesson's figures.

The same holds in general. Completing the square in $ax^2 + bx + c$ (factor out $a$, then proceed as in the proof) gives

$$ ax^2 + bx + c = a\left(x + \frac{b}{2a}\right)^2 - \frac{D}{4a}. $$

The squared term vanishes at $x = -\frac{b}{2a}$, so that is where the parabola has its turning point, called the vertex, and the two solutions $-\frac{b}{2a} \pm \frac{\sqrt{D}}{2a}$ sit at equal distances on either side of it. The quadratic formula says “start at the vertex and go the same distance left and right”.

Edge cases

The hypothesis $a \ne 0$ is needed, and you can see where: the first step divides by $a$, and the formula has $2a$ in the denominator. When $a = 0$ the equation is $bx + c = 0$, which is solved by one division and has a single solution when $b \ne 0$.

When $b = 0$ there is nothing to complete. The equation $ax^2 + c = 0$ is already of the form $x^2 = -\frac{c}{a}$, and the formula reduces to $x = \pm\frac{\sqrt{-4ac}}{2a}$, which is the same thing.

When $D < 0$ the formula asks for the square root of a negative number, and the theorem says correctly that no real solution exists. It does not say the equation is meaningless. Later in mathematics the number system is extended so that such square roots exist, and then the same formula gives two solutions that are not real numbers.

Common mistakes

Stepping back

The obstacle was an unknown that appeared in two different forms, $x^2$ and $x$. The idea that removed it was to change the shape of the expression without changing its value until the unknown appeared only once, inside a square. Cutting the rectangle in half and wrapping the halves around the square did this, at the cost of a missing corner whose size we could compute.

That idea is worth more than the formula it produces. Completing the square finds the lowest or highest point of any quadratic, which is how one shows, for example, that among rectangles with a given perimeter the square has the largest area (a problem in the distributive law lesson does this with a difference of squares). It turns the equation of a circle into a form where the center and radius can be read off. And it reappears in calculus and in statistics whenever a quadratic expression has to be simplified. The question of where an expression is zero continues, for higher powers of $x$, in roots, factors and the shape of a polynomial.

Check yourself

What must be added to $x^2 - 14x$ to make it a perfect square, and what square does it become?

Problems

Problem 1

Complete the square in each expression: (a) $x^2 + 8x$, (b) $x^2 - 12x$, (c) $x^2 + 5x$.

Show solutionHide solution

In each case, halve the coefficient of $x$ and square it.

(a) Half of 8 is 4, and $4^2 = 16$: $x^2 + 8x = (x + 4)^2 - 16$.

(b) Half of $-12$ is $-6$, and $(-6)^2 = 36$: $x^2 - 12x = (x - 6)^2 - 36$.

(c) Half of 5 is $\frac52$, and $\left(\frac52\right)^2 = \frac{25}{4}$: $x^2 + 5x = \left(x + \frac52\right)^2 - \frac{25}{4}$.

Each can be checked by expanding the square. For (c): $\left(x + \frac52\right)^2 = x^2 + 5x + \frac{25}{4}$.

Problem 2

Solve $x^2 + 12x = 13$ by completing the square. Draw (or describe) the picture: what are the dimensions of the strips, the corner and the completed square?

Show solutionHide solution

Half of 12 is 6, so the rectangle is cut into two strips each 6 wide and $x$ tall, and the missing corner is 6 by 6 with area 36. Adding 36 to both sides,

$$ (x + 6)^2 = 13 + 36 = 49. $$

The completed square has area 49 and side 7. So $x + 6 = 7$ or $x + 6 = -7$, giving $x = 1$ or $x = -13$.

Check: $1 + 12 = 13$ and $169 - 156 = 13$. Only $x = 1$ appears in the picture, since a side length is positive.

Problem 3

Solve $x^2 - 6x + 2 = 0$ by completing the square. Give exact answers and decimal approximations to three places.

Show solutionHide solution

Move the constant: $x^2 - 6x = -2$. Half of $-6$ is $-3$ and its square is 9. Adding 9 to both sides gives $(x - 3)^2 = 7$.

Since $7 > 0$, $x - 3 = \sqrt7$ or $x - 3 = -\sqrt7$, so $x = 3 + \sqrt7 \approx 5.646$ or $x = 3 - \sqrt7 \approx 0.354$.

Check the exact value: $(3 + \sqrt7)^2 - 6(3 + \sqrt7) + 2 = (9 + 6\sqrt7 + 7) - 18 - 6\sqrt7 + 2 = 0$.

Problem 4

Use the quadratic formula to solve $3x^2 - 5x - 2 = 0$, and check both solutions.

Show solutionHide solution

Here $a = 3$, $b = -5$, $c = -2$. The discriminant is $D = (-5)^2 - 4 \times 3 \times (-2) = 25 + 24 = 49$, which is positive, so there are two solutions:

$$ x = \frac{5 \pm 7}{6}, \quad\text{that is,}\quad x = 2 \ \text{ or } \ x = -\frac13. $$

Check $x = 2$: $12 - 10 - 2 = 0$. Check $x = -\frac13$: $3 \times \frac19 + \frac53 - 2 = \frac13 + \frac53 - 2 = 0$.

Problem 5

Without solving, find the number of real solutions of each equation: (a) $x^2 + 4x + 5 = 0$, (b) $4x^2 - 12x + 9 = 0$, (c) $x^2 - x - 1 = 0$.

Show solutionHide solution

Compute the discriminant $D = b^2 - 4ac$ in each case.

(a) $D = 16 - 20 = -4 < 0$: no real solutions. Indeed $x^2 + 4x + 5 = (x + 2)^2 + 1$, which is at least 1.

(b) $D = 144 - 144 = 0$: exactly one solution, $x = \frac{12}{8} = \frac32$. Indeed $4x^2 - 12x + 9 = (2x - 3)^2$.

(c) $D = 1 + 4 = 5 > 0$: two real solutions, $x = \frac{1 \pm \sqrt5}{2}$.

Problem 6

Find the smallest value taken by $f(x) = x^2 - 10x + 31$ as $x$ ranges over all real numbers, and the value of $x$ at which it occurs. Explain why no smaller value is possible.

Show solutionHide solution

Complete the square: $x^2 - 10x = (x - 5)^2 - 25$, so

$$ f(x) = (x - 5)^2 - 25 + 31 = (x - 5)^2 + 6. $$

A square of a real number is at least 0, and it equals 0 only when the number is 0. So $(x - 5)^2 \ge 0$ for every $x$, with equality only at $x = 5$. Therefore $f(x) \ge 6$ for every $x$, and $f(5) = 6$. The smallest value is 6, at $x = 5$.

This agrees with the vertex formula: $-\frac{b}{2a} = \frac{10}{2} = 5$.

Problem 7

(a) For which values of $c$ does $x^2 + 6x + c = 0$ have exactly one real solution? No real solution? (b) For which values of $k$ does $x^2 + kx + 9 = 0$ have exactly one real solution?

Show solutionHide solution

(a) The discriminant is $36 - 4c$. It is zero when $c = 9$, giving exactly one solution ($x = -3$, since $x^2 + 6x + 9 = (x + 3)^2$). It is negative when $c > 9$, giving no real solution. In the picture, $c = 9$ is the case where the constant term is exactly the corner.

(b) The discriminant is $k^2 - 36$, which is zero when $k^2 = 36$, that is, $k = 6$ or $k = -6$. The two equations are $(x + 3)^2 = 0$ and $(x - 3)^2 = 0$.

Problem 8

A rectangle has perimeter 20. (a) Find its side lengths if its area is 20. (b) Show that its area cannot be 30.

Show solutionHide solution

The two side lengths add to 10. Call one of them $x$, so the other is $10 - x$ and the area is $x(10 - x)$.

(a) We need $x(10 - x) = 20$, that is, $x^2 - 10x + 20 = 0$. Completing the square: $x^2 - 10x = -20$, so $(x - 5)^2 = 5$ and $x = 5 \pm \sqrt5$. The sides are $5 + \sqrt5 \approx 7.236$ and $5 - \sqrt5 \approx 2.764$. Each choice of sign gives one side, and the other sign gives the other side. Check: their sum is 10 and their product is $(5 + \sqrt5)(5 - \sqrt5) = 25 - 5 = 20$.

(b) Area 30 would need $x^2 - 10x + 30 = 0$, whose discriminant is $100 - 120 = -20 < 0$. There is no real solution, so no such rectangle exists. Completing the square shows why: the area is $x(10 - x) = 25 - (x - 5)^2$, which is at most 25.

Problem 9

Suppose $ax^2 + bx + c = 0$ with $a \ne 0$ has discriminant $D > 0$, and call its two solutions $r$ and $s$. Use the quadratic formula to prove that $r + s = -\dfrac{b}{a}$ and $rs = \dfrac{c}{a}$. Verify both with the equation $x^2 + 6x - 16 = 0$.

Show solutionHide solution

Write $r = \frac{-b + \sqrt D}{2a}$ and $s = \frac{-b - \sqrt D}{2a}$.

Sum. The square roots cancel: $r + s = \frac{-b + \sqrt D - b - \sqrt D}{2a} = \frac{-2b}{2a} = -\frac{b}{a}$.

Product. The numerators are a sum and a difference of the same two numbers, so the difference of two squares applies:

$$ rs = \frac{(-b + \sqrt D)(-b - \sqrt D)}{4a^2} = \frac{(-b)^2 - (\sqrt D)^2}{4a^2} = \frac{b^2 - D}{4a^2}. $$

Since $D = b^2 - 4ac$, the numerator is $b^2 - b^2 + 4ac = 4ac$, and $rs = \frac{4ac}{4a^2} = \frac{c}{a}$.

For $x^2 + 6x - 16 = 0$ the solutions are $2$ and $-8$. Their sum is $-6 = -\frac{b}{a}$ and their product is $-16 = \frac{c}{a}$.

Shared definitions used by this lesson's figures
# house kit: prepended to every essay figure after the std imports

# palette. AZURE and EMBER are the two actors, LEAF marks an answer, ROSE a problem
let PAPER = [1, 1, 1, 1]
let INK = [0.08, 0.09, 0.11, 1]
let SLATE = [0.40, 0.44, 0.50, 1]
let MIST = [0.85, 0.86, 0.88, 1]
let AZURE = [0.13, 0.42, 0.68, 1]
let EMBER = [0.89, 0.42, 0.12, 1]
let LEAF = [0.13, 0.55, 0.36, 1]
let ROSE = [0.78, 0.22, 0.24, 1]
let PLUM = [0.47, 0.30, 0.66, 1]
let GOLD = [0.85, 0.62, 0.08, 1]

background = PAPER

# an opaque pastel of col; use for fills so overlaps do not darken
let tint = |col, amount = 0.18| [
    1 - (1 - col[0]) * amount,
    1 - (1 - col[1]) * amount,
    1 - (1 - col[2]) * amount,
    1
]

# text: Cap for labels, Note for quiet labels, Math for typeset maths
let Cap = |txt, size = 0.75, col = INK| color{col} Text(txt, size, "Charter")
let Note = |txt, size = 0.65| color{SLATE} Text(txt, size, "Charter")
let Math = |tex, size = 0.9, col = INK| color{col} Tex(tex, size)

# a paper rectangle to sit behind text that crosses lines
let Plate = |pos, size| center{pos} fill{PAPER} stroke{alpha{0} PAPER, 0} Rect(size)

# shapes with fill and stroke both set, so no stray black appears
let Pt = |pos, col = INK, r = 0.075| center{pos} fill{col} stroke{col, 1} Circle(r, 48)
let Ring = |pos, col = INK, r = 0.1, w = 3| center{pos} fill{PAPER} stroke{col, w} Circle(r, 48)
let Seg = |a, b, col = INK, w = 3| stroke{col, w} Line(a, b)
let Path = |pts, col = INK, w = 3| stroke{col, w} Polyline(pts)
let Region = |pts, col| fill{col} stroke{alpha{0} col, 0} Polygon(pts)
let Outline = |pts, col = INK, w = 3| fill{alpha{0} PAPER} stroke{col, w} Polygon(pts)
let Shape = |pts, col, amount = 0.18, w = 3| fill{tint(col, amount)} stroke{col, w} Polygon(pts)
let Disc = |pos, r, col, amount = 0.18, w = 3| center{pos} fill{tint(col, amount)} stroke{col, w} Circle(r, 96)
let Box = |pos, size, col, amount = 0.18, w = 3| center{pos} fill{tint(col, amount)} stroke{col, w} Rect(size)
# a line from a to b ending in a small solid arrowhead
let Tip = |a, b, col = INK, w = 3, head = 0.17| {
    let d = normalize([b[0] - a[0], b[1] - a[1], 0])
    let n = [-d[1], d[0], 0]
    let base = [b[0] - d[0] * head, b[1] - d[1] * head, 0]
    return [
        stroke{col, w} Line(a, base),
        fill{col} stroke{col, 1} Polygon([
            b,
            [base[0] + n[0] * head * 0.42, base[1] + n[1] * head * 0.42, 0],
            [base[0] - n[0] * head * 0.42, base[1] - n[1] * head * 0.42, 0]
        ])
    ]
}

# plots. a frame is [x0, x1, y0, y1, centre, width, height]: a data window and the scene box it fills
let Frame = |x0, x1, y0, y1, c = [0, 0, 0], w = 6.4, h = 3.6| [x0, x1, y0, y1, c, w, h]
let fx = |fr, x| fr[4][0] + (x - (fr[0] + fr[1]) / 2) * fr[5] / (fr[1] - fr[0])
let fy = |fr, y| fr[4][1] + (y - (fr[2] + fr[3]) / 2) * fr[6] / (fr[3] - fr[2])
let at = |fr, x, y| [fx(fr, x), fy(fr, y), 0]

# axes through the data origin (or the nearest edge of the window), with optional names
let Axes = |fr, x_name = "", y_name = "", col = SLATE| {
    let ox = clamp(fr[0], 0, fr[1])
    let oy = clamp(fr[2], 0, fr[3])
    var parts = [
        Tip(at(fr, fr[0], oy), [fx(fr, fr[1]) + 0.25, fy(fr, oy), 0], col, 2.5, 0.15),
        Tip(at(fr, ox, fr[2]), [fx(fr, ox), fy(fr, fr[3]) + 0.25, 0], col, 2.5, 0.15)
    ]
    if (x_name != "") {
        parts .= center{[fx(fr, fr[1]) + 0.5, fy(fr, oy), 0]} Math(x_name, 0.8, col)
    }
    if (y_name != "") {
        parts .= center{[fx(fr, ox), fy(fr, fr[3]) + 0.5, 0]} Math(y_name, 0.8, col)
    }
    return parts
}

# tick marks with numbers at the listed data values
let XTicks = |fr, xs, col = SLATE, places = 0| block {
    let oy = fy(fr, clamp(fr[2], 0, fr[3]))
    for (x in xs) {
        . Seg([fx(fr, x), oy - 0.07, 0], [fx(fr, x), oy + 0.07, 0], col, 2)
        . center{[fx(fr, x), oy - 0.33, 0]} Math(to_string(x, places), 0.72, col)
    }
}
let YTicks = |fr, ys, col = SLATE, places = 0| block {
    let ox = fx(fr, clamp(fr[0], 0, fr[1]))
    for (y in ys) {
        . Seg([ox - 0.07, fy(fr, y), 0], [ox + 0.07, fy(fr, y), 0], col, 2)
        . center{[ox - 0.36, fy(fr, y), 0]} Math(to_string(y, places), 0.72, col)
    }
}

# faint grid lines at the listed data values
let GridLines = |fr, xs, ys, col = MIST| block {
    for (x in xs) {
        . Seg(at(fr, x, fr[2]), at(fr, x, fr[3]), col, 1.5)
    }
    for (y in ys) {
        . Seg(at(fr, fr[0], y), at(fr, fr[1], y), col, 1.5)
    }
}

# the graph of f over [a, b], drawn in the frame. values are clamped to the window
let Graph = |fr, f, a, b, col = AZURE, w = 4, n = 160|
    stroke{col, w} Polyline(map(sample(a, b, n), |x| at(fr, x, clamp(fr[2], f(x), fr[3]))))

# the region between the graph of f and the x axis over [a, b]
let AreaUnder = |fr, f, a, b, col = AZURE, amount = 0.2, n = 80| {
    var pts = [at(fr, a, 0)]
    for (x in sample(a, b, n)) {
        pts .= at(fr, x, clamp(fr[2], f(x), fr[3]))
    }
    pts .= at(fr, b, 0)
    return fill{tint(col, amount)} stroke{alpha{0} col, 0} Polygon(pts)
}

# a w by h rectangle with lower left corner p, turned about p by `turn` radians
let Slab = |p, w, h, col, turn = 0, amount = 0.22| {
    let c = cos(turn)
    let s = sin(turn)
    let q = |i, j| [p[0] + i * c - j * s, p[1] + i * s + j * c, 0]
    return Shape([q(0, 0), q(w, 0), q(w, h), q(0, h)], col, amount, 3)
}
let Lab = |pos, tex, col = INK, size = 0.85| center{pos} Math(tex, size, col)

# the running example x^2 + 6x = 16, drawn to scale with its positive solution x = 2
let XV = 2
let B = 6
let HB = B // 2
let C = 16
let G = 0.68
let X0 = -3.35
let Y0 = -1.7
let half_tex = str_join([to_string(HB), "x"])

# labels for the square of side x with one strip on its right and one on top
let WrapLabels = |corner| block {
    . Lab([X0 + XV * G / 2, Y0 + XV * G / 2, 0], "x^2", AZURE)
    . Lab([X0 + (XV + HB / 2) * G, Y0 + XV * G / 2, 0], half_tex, EMBER)
    . Lab([X0 + XV * G / 2, Y0 + (XV + HB / 2) * G, 0], half_tex, EMBER)
    . Lab([X0 + XV * G / 2, Y0 - 0.3, 0], "x")
    . Lab([X0 + (XV + HB / 2) * G, Y0 - 0.3, 0], to_string(HB))
    . Lab([X0 - 0.3, Y0 + XV * G / 2, 0], "x")
    . Lab([X0 - 0.3, Y0 + (XV + HB / 2) * G, 0], to_string(HB))
    if (corner == 1) {
        . Lab([X0 + (XV + HB / 2) * G, Y0 + (XV + HB / 2) * G, 0], to_string(HB * HB), LEAF, 0.95)
    }
}
let Corner = Slab([X0 + XV * G, Y0 + XV * G, 0], HB * G, HB * G, LEAF, 0, 0.4)
let Lines = |rows, cols, tx = 2.1, top = 1.5| block {
    for (i in range(0, len(rows))) {
        . Lab([tx, top - 0.64 * i, 0], rows[i], cols[i], 0.92)
    }
}
let eq_start = str_join(["x^2 + ", to_string(B), "x = ", to_string(C)])
let eq_added = str_join(["x^2 + ", to_string(B), "x + ", to_string(HB * HB), " = ", to_string(C + HB * HB)])
let eq_square = str_join(["(x + ", to_string(HB), ")^2 = ", to_string(C + HB * HB)])