Algebra

Completing the square, by completing a square

The step everybody is taught as an algebraic trick is a literal instruction about a literal square. There is a corner missing, its size is forced, and paying for it is the whole method.
18 min read 8 figures Proof without words

Nearly everyone who has met algebra has been shown this manoeuvre:

x2+6x=16x2+6x+9=25(x+3)2=25x^2 + 6x = 16 \quad\longrightarrow\quad x^2 + 6x + 9 = 25 \quad\longrightarrow\quad (x+3)^2 = 25

Add nine to both sides, and the left one factors. Where the nine came from is usually explained as half the coefficient, squared, which is a correct instruction and no explanation at all.

The instruction is an instruction about a shape.

Two lengths, three tiles

Read x2x^2 as an area: a square of side xx. Read 6x6x as an area too — a rectangle 66 wide and xx tall. Both are regions, so both can be drawn, and the drawing is the whole method.

Completing the square, as a squareAn x by x square with a strip of width 3 along one side. The result is a rectangle and no amount of staring makes it a square.3xx + 3a rectanglex² + 3xis not a squarex = 4, so the total is28
Fig. 1 A square of side xx with a strip of width bb along one side. The total area is x2+bxx^2 + bx, and the total shape is a rectangle. Nothing about it is a square and no amount of looking makes it one.

That is the honest first attempt and it fails. The result is a rectangle xx by x+bx+b, and a rectangle is not what the method wants.

The repair is to put the strip on two sides instead of one. Cut it in half lengthways and lay one half along the bottom.

Completing the square, as a squareAn x by x square with the strip split in half and laid along two sides, leaving a square hole of side 1.5. Filling the hole costs 2.25 and buys a perfect square.1.5x1.5x?x + 1.5a squarex² + 3xis not a squarex = 4, so the total is28
Fig. 2 The same strip, cut into two halves and laid along two sides instead of one. The area is unchanged — the two halves are the strip — and now the shape almost closes into a square. What is missing is a corner, and its size is not a choice.

Now the figure is nearly a square of side x+b/2x + b/2, and exactly one region is absent: the corner where the two half-strips would meet. That corner is b/2b/2 by b/2b/2.

Its area is (b/2)2(b/2)^2. Half the coefficient, squared. There is no choice about it — the corner’s dimensions are set by the widths of the two strips, and the strips are half the original because it was cut in two.

Completing the square, as a squareAn x by x square with the strip split in half and laid along two sides, leaving a square hole of side 1.5. Filling the hole costs 2.25 and buys a perfect square.1.5x1.5x1.5²x + 1.5a squarex² + 3x + 1.5²= (x + 1.5)²x = 4, so the total is30.25
Fig. 3 The corner filled in. The four pieces are a perfect square of side x+b/2x + b/2, so x2+bx+(b/2)2=(x+b/2)2x^2 + bx + (b/2)^2 = (x + b/2)^2 — and the generator checks both that the pieces tile the square and that the identity holds as arithmetic.

Why the halving is the idea

The step that does the work is not the adding. It is the symmetrising.

A strip on one side is lopsided, and the shape it makes has one dimension bigger than the other by exactly bb. Splitting the strip evenly makes the two dimensions equal, and equal dimensions is what a square is. Everything else follows: once the shape has been made symmetric, the gap is forced, and the gap’s size is forced.

Read that back into the algebra and the substitution u=x+b/2u = x + b/2 appears with a reason attached. It is a shift of origin to the axis of symmetry of the parabola y=x2+bxy = x^2 + bx, which sits at x=b/2x = -b/2 precisely because the two roots are equidistant from it. The whole method is find the symmetry and move to it, and completing the square is the algebraic form of that instruction.

That is why the trick has no analogue for a general cubic that is nearly as clean. A cubic can also be shifted to remove its second-highest term — the same move, and it is called a depressed cubic — but the resulting object is not a perfect anything, and solving it took another two thousand years and a fight in sixteenth-century Bologna.

Two lengths, changed

The construction has to work at every xx and every bb, and one of the things a static diagram cannot say is that nothing in it depended on the numbers drawn. Two more at different proportions are the cheapest available substitute.

Completing the square, as a squareAn x by x square with the strip split in half and laid along two sides, leaving a square hole of side 1. Filling the hole costs 1 and buys a perfect square.1x1xx + 1a squarex² + 2x + 1²= (x + 1)²x = 6, so the total is49
Fig. 4 A wider square with a narrower strip. The corner shrinks with the strip — it is (b/2)2(b/2)^2, so halving bb quarters the price of completing — and the total is still a perfect square.
Completing the square, as a squareAn x by x square with the strip split in half and laid along two sides, leaving a square hole of side 2.5. Filling the hole costs 6.25 and buys a perfect square.2.5x2.5x2.5²x + 2.5a squarex² + 5x + 2.5²= (x + 2.5)²x = 2, so the total is20.25
Fig. 5 The other extreme: a small square and a strip wider than it is. The corner is now the largest of the four pieces, and the completed square is dominated by a term the original expression did not contain. The arrangement is unchanged.

The second of those is worth dwelling on, because it is where the method’s arithmetic feels least like its picture. When bb is large relative to xx, the corner added is the biggest piece in the figure — completing the square costs more than the thing being completed. Algebraically that is unremarkable; visually it is a warning that the “small correction” reading of the method is a coincidence of the usual textbook numbers rather than anything structural.

The formula, read off the picture

The picture solves equations rather than merely rearranging them. An equation x2+bx=kx^2 + bx = k says the L-shaped region has area kk; completing it says the square has area k+(b/2)2k + (b/2)^2; and the side of a square of known area is its root.

The same picture, solvedThe equation x² + 6x = 16 drawn as an L-shaped region of area 16. Completing it to a square of area 25 gives a side of 5.000, so x is 2.000.3x3x95.000x² + bx = kx² + 6x = 16add (b/2)² to both sidesx² + 6x + 9 = 25the left side is now a square(x + 3)² = 25so the side is its rootx + 3 = 5.0000and the length isx = 2.0000
Fig. 6 The same construction with the numbers of an actual equation. The L has area 1616, the corner costs 99, the completed square is 2525, its side is 55, and xx is what is left after the corner’s half-width is taken off.

Run that with letters instead of numbers and the quadratic formula appears, with every symbol in it accounted for:

x=b2±(b2)2+kx = -\frac{b}{2} \pm \sqrt{\left(\frac{b}{2}\right)^2 + k}

The b/2-b/2 is the shift to the axis of symmetry. The square root is the side of the completed square. The ±\pm is the second root, which the picture does not contain — and that omission is the essay’s most interesting failure, taken up below.

Written for ax2+bx+c=0ax^2 + bx + c = 0 the same expression is the familiar one, with the 4a4a and the 2a2a appearing because dividing through by aa has to happen first and the halving then applies to b/ab/a. The discriminant b24acb^2 - 4ac is, in the picture, the area of the completed square measured against the corner: positive when the square is genuinely there, zero when the L has shrunk to the corner alone, and negative when the completed square would need a negative area.

The identity underneath

Completing the square is one instance of a family, and the family is worth seeing together because the pieces are the same pieces.

(a + b)², as four tilesA square of side 7 cut into an 5 by 5 square, a 2 by 2 square and two 5 by 2 rectangles — which is why the middle term is doubled.abab(a + b)² = a² + 2ab + b²7² = 25 + 20 + 4 = 49
Fig. 7 (a+b)2(a+b)^2 cut into four tiles: two squares and two identical rectangles. The doubling of the middle term is not an algebraic accident — there are literally two rectangles, one from each way of pairing the two lengths.

That figure answers a question most people stop asking too early: why is the middle term doubled? Because there are two rectangles. One has the aa side horizontal and the bb side vertical; the other is the reverse. They are congruent and they are distinct, and squaring counts both.

The companion identity is the difference of two squares, and its picture is a cut and a slide rather than an assembly.

A square with a square taken outA 5 by 5 square with a 2 by 2 corner removed, cut into two pieces and reassembled as a 7 by 3 rectangle.a² − b² = 21(a + b)(a − b) = 21
Fig. 8 A square with a smaller square removed from a corner, cut into two pieces and reassembled as a rectangle a+ba+b by aba-b. Nothing is added or discarded — the generator checks the areas before and after — which is why the identity is exact rather than approximate.

Both are dissection arguments in the same sense as the rearrangement proof of the Pythagorean theorem: the claim is an equality of areas, and it is established by exhibiting the pieces. What makes them algebra rather than geometry is only that the side lengths are called aa and bb instead of being measured.

What it costs

For solving an actual quadratic, nothing — but the numerical behaviour of the formula is a standing trap and it is a consequence of exactly the symmetry above.

When b2b^2 is much larger than 4ac4ac, the square root is very close to b|b|, and one of the two roots is computed as a difference of two nearly equal numbers. That subtraction destroys most of the significant digits. Solving x2+108x+1=0x^2 + 10^8 x + 1 = 0 in double precision by the formula gives the small root as 00 or as something wildly wrong, when the true value is close to 108-10^{-8}.

The repair uses the other thing the picture makes obvious: the two roots multiply to c/ac/a. Compute the well-conditioned root by the formula, get the other by division, and both come out accurate. This is not a specialist concern — it is in every numerical library, and the naive formula appears in student code constantly.

Worth noticing that the fix comes from a relation between the roots rather than from a better formula for each. The relations x1+x2=b/ax_1 + x_2 = -b/a and x1x2=c/ax_1 x_2 = c/a are Vieta’s, and in the picture they are the axis of symmetry and the completed area respectively. The stable algorithm is the picture used twice.

The same shape of failure and the same shape of repair recur throughout numerical work, and they are worth recognising in the abstract: a formula that is exact in arithmetic can be catastrophic in floating point wherever it subtracts two nearly equal quantities, and the repair is almost always an algebraic identity that avoids the subtraction rather than more precision. It is the counterpart, in a domain with no pictures at all, of choosing where to sample rather than sampling more often.

Where the picture fails

An area cannot be negative, and a length cannot be negative, and both of those bite.

The construction as drawn requires x>0x > 0 and b>0b > 0. The equation x2+6x=16x^2 + 6x = 16 has roots 22 and 8-8, and the figure produces only the 22. The other root is not hiding in the picture; it is not representable in it, because there is no square of side 8-8.

That is not a defect of this particular drawing. It is the reason the algebra outran the geometry. Al-Khwārizmī, whose ninth-century al-Kitāb al-mukhtaṣar fī ḥisāb al-jabr wal-muqābala gave algebra its name and gave this method its canonical treatment, classified quadratics into six types precisely to keep every coefficient positive — because a negative coefficient had no picture, and the picture was the proof. Each of his six cases has its own diagram and its own rule, and the reason there are six rather than one is that the geometric method cannot say 8-8.

The unification into a single equation with signed coefficients took until the sixteenth and seventeenth centuries, and it required accepting numbers that no length has. The same acceptance, pushed one step further, is what admits the case where the discriminant is negative and the roots are complex — which is a genuine solution living in the plane where multiplying is turning and has no area picture at all.

So the trade is explicit and it is the central one in the history of the subject. The picture proves what it shows and can only show what exists as a region. Algebra gives that up and gets, in exchange, negative roots, complex roots, and one formula instead of six.

Where it earns its keep beyond quadratics

The method is not really about solving equations, which is the impression an education in it tends to leave. It is a way of rewriting a quadratic form so its behaviour is obvious, and that use is much more common.

Integrating 1/(x2+6x+13)1/(x^2 + 6x + 13) needs the denominator as (x+3)2+4(x+3)^2 + 4 before it is recognisable as an arctangent. Sketching a parabola needs its vertex, which is what the completed form displays. Deriving the normal distribution’s density from its exponent needs the exponent completed, and that is where the bell curve’s location and width come from. In every case nothing is being solved; a form is being made legible.

The generalisation to several variables is the same idea and is one of the workhorses of linear algebra: any quadratic form can be written as a sum of squares by repeatedly completing, and the number of positive and negative squares that result is independent of how it is done. That is Sylvester’s law of inertia, and it is completing the square applied nn times.

That invariance is the surprising half. Completing a form in several variables involves a long sequence of arbitrary choices — which variable to take first, and in what order — and different choices produce visibly different sums of squares, with different coefficients and different variables inside them. The counts of positive and negative terms do not move. So a quantity that survives every arbitrary choice has been found, which puts it in the same category as an angle that does not depend on where the observer stands and a count that does not depend on how a solid is drawn: the arbitrary parts are the method, and what is left over is the object.

For a form in two variables the three possible signatures are exactly the three non-degenerate conics, which is why completing the square identifies an ellipse, a parabola or a hyperbola from its equation without any drawing.

What the picture cannot show

Three things, and the first is the largest: the negative root. Every figure here draws lengths, so every figure shows one solution and is silent about the other. A reader who took the pictures as the whole method would come away believing a quadratic has one root, which is worse than an incomplete understanding — it is a definite wrong one.

Second, the pictures show one value of xx at a time. The identity x2+bx+(b/2)2=(x+b/2)2x^2 + bx + (b/2)^2 = (x + b/2)^2 is true for every xx, and each figure is drawn at a particular one. The tiling is a proof for the drawn case; the general case needs the observation that nothing in the argument used the value, which is a remark and not a picture.

Third, the complex case. When the discriminant is negative there is no square to complete, and the honest thing a figure can do is not exist. The plane where those roots live is drawable, and the connection between it and this dissection is not.

The ladder from here

Rungs above: the discriminant as a curve, and the three cases as three parabolas against an axis. Vieta’s relations, drawn. The depressed cubic and Cardano’s method, which is completing the cube and needs a genuinely three-dimensional dissection. The resolvent, and why the same move stops working at degree five. Conic sections as quadratic forms in two variables, where completing the square is what identifies which conic is present. Sylvester’s law of inertia. And the Gaussian integral, where the completed exponent is the entire trick.

The instruction was a description

There is a small pedagogical moral and it generalises past this method.

Half the coefficient, squared is a correct rule that has been separated from the thing it describes. Taught as a rule it is arbitrary, forgettable, and impossible to reconstruct when half-remembered. Taught as a description of a corner whose dimensions are forced by a strip that was cut in two, it cannot be misremembered, because the shape does the remembering.

The general point is that a great many algebraic manipulations are descriptions of arrangements, and the arrangement is usually the older half. This one was a diagram before it was a formula, by about a thousand years, and the formula is a compression of the diagram rather than a discovery that replaced it.

The compression is not a loss to be regretted, and the essay would be dishonest if it left that impression. The formula does things the diagram cannot: it handles the negative root, the complex root, and all six of al-Khwārizmī’s cases at once, and it can be applied without thought, which is exactly what a technique should permit. What the diagram supplies is the part that survives forgetting — the reason the number is a square, and the reason it is a half.

Both are worth having, and the order matters. A reader who meets the rule first and the picture afterwards usually experiences the picture as decoration. A reader who meets the picture first experiences the rule as a summary, which is what it is.