Completing the square

"Completing the square" refers to an intuitive geometric approach to solving a quadratic. The famous quadratic formula is derived from this method. The equation is rewritten into an expression of form a(x+b)2+c=0, and the roots are found by solving for x using plain ol' algebra. The quadratic formula is simply the result of completing the square (as an expression, it is known as vector form) solved for x.

TL;DR

Given a quadratic equation ax2+bx+c=0, this will be a(x+b2a)2+c−b24a.

Derivation

The method of completing the square is best understood graphically. We will begin with an input polynomial of form x2+bx+c=0. Then, taking advantage of a geometric analogue, we will rewrite the equation into a form solvable with basic algebraic manipulations alone.

Fun fact, I'd initially taken a bunch of graphical, pretty notes where I derive the method by hand! Accidentally overwrote the file. Nice! They were fucking great notes, too. Illustrations and all. What follows is a second write-up from scratch. }:(

We start things off by rewriting our equation such that c sits on the right-hand side of the equals sign:

x2+bx+c=0x2+bx=−c.

If we wish to adapt this equation into something solvable with algebra, we must first speak a bit of geometry. Observe the correspondence between rectangles and products: any product A of two real numbers w and h is, from a geometric perspective, a rectangle of area A and side lengths w and h. Within this metaphor, the distribution of multiplication over addition fades to reveal a geometric analogue to the distributive law: juxtaposition of similarly-sided rectangles.

The geometric metaphor we've described is applied to our equation as so: firstly, the terms x2 and bx are translated to rectangles:

Remember that the goal here is to get rid of the x2 term while leaving an x that we can solve for. This is accomplished in two steps: first, we geometrically rearrange the left-hand side into a square, making way for us to take the square root of both sides, finally allowing us to solve for x in terms of ±−c. This rearrangement relies upon the similar side (shared factor) of the blue x2 and red bx terms, and applies the aforementioned distributive law:

The second step to squarehood is to split the red bx term in half, and glue it to an adjacent side of the blue x2 term, as in

This transformation is sane because the expression's area — its value — is preserved.

Our figure finally resemble a square, ignoring the little missing "chunk" in the corner; however, this much is sufficient for our purposes! we can simply identify the total area of the blue and red portions as (x+b2)2 minus the area of the corner chunk, denoted in dashed green (dashed lines because it is not counted in the total value of the expression).

We are finally ready to move back to algebra. To recap, the entire preceding process, in algebra, has been

x2+bx+c=0x2+bx=−cx2+bx2+bx2=−c(x+b2)2−(b2)2=−c.

Now we solve:

(x+b2)2−(b2)2=−c(x+b2)2=(b2)2−cx+b2=±(b2)2−c.

If b and c are known, this is a trivial solve from here. Otherwise, we can proceed to rearrange this equation into a simplified version of the the quadratic formula that does not account for any leading coefficient:

(We neglected the leading coefficient for simplicity's sake).