When faced with a expression involving both purely quadratic terms (e.g. ) and linear terms (e.g. ) in one or more variables , translate the variable in order to absorb the linear terms into the quadratic ones. This can create additional constant terms, but all other things being equal, constant terms are preferable to deal with than linear terms.
High school algebra
Example 1: The quadratic formula
This is the classic example of the completing the square trick. Suppose one wants to find all solutions to the quadratic equation
where are parameters. The linear term prevents one from solving this equation directly; however, observe that for any shift . Thus, (assuming ) if one picks , one can absorb the linear factor into the quadratic one, obtaining an equation
which only involves quadratic and constant terms. Now, the rules of high school algebra can solve this equation. Dividing by and rearranging, one gets
taking square roots, we arrive at the famous formula
for the two solutions to the quadratic equation, bearing in mind that the square root may well be imaginary if is negative. (For the , the above formula does not make sense, but in that case the equation degenerates to the linear equation , which has one solution , unless managed to degenerate to zero also, in which case there are no solutions when and an infinite number of solutions when .)
See "how to solve quadratic equations" for more discussion.
A quadratic form is an expression like . That particular example is a quadratic form on , and in general a quadratic form over is a function obtained by taking a symmetric bilinear form on and defining to be . In the example above, the bilinear form is .
It is often convenient to diagonalize a quadratic form, which means writing it as a linear combination of squares of linearly independent linear forms. Let us do this for the example above, by completing the square.
Our aim will be to achieve this by removing from the square of a linear form in such a way that is no longer involved. To do this, we first pick out the terms that involve , which are . We then try to find a linear form such that when you square it the terms involving are precisely these ones. With a bit of experience in completing the square, we know that will do the job. Indeed,
We would now like to finish this process by diagonalizing , which we can make look slightly nicer by writing it as . Completing the square again, we find that
Plugging this in, we deduce that
and the quadratic form has been diagonalized.
Completing the square can be used to compute the Fourier transform of gaussians. In one dimension, this was done in "Use rescaling or translation to normalize parameters"; we do the multi-dimensional case here. Specifically, let us compute the Fourier transform
of the Gaussian , where is a positive definite real symmetric matrix, and . Observe that
for all . Thus, if we pick , we can complete the square and rewrite (1) as
The constant term , being independent of , can be pulled out of the integral and simplified, leaving us with
Making the change of variables to normalize the integrand, we can simplify this as
The standard proof of the Cauchy-Schwarz inequality in a Hilbert space (which we take here to be real, for simplicity) can be viewed as a variant of the completing-the-square trick, but now one converts linear term into quadratic and constant terms rather than vice versa. Indeed, since
for any , we can write
for any ; in particular,
If we then optimize in , we obtain the Cauchy-Schwarz inequality.
Completing the square can also be done in several variables, whenever one is adding a quadratic form to a linear form plus some constant terms, provided that the quadratic form is non-degenerate (this is analogous to the condition in the quadratic formula).
The method also works to some extent for higher degree polynomials, but is significantly weaker. For instance, with cubic equations , one can complete the cube to eliminate the quadratic factor (at the expense of modifying the lower order terms ), but the linear term remains, and further tricks are needed to solve this equation. See "How to solve cubic and quartic equations".