In elementary algebra, **completing the square** is a technique for converting a quadratic polynomial of the form

to the form

for some values of

In other words, completing the square places a perfect square trinomial inside of a quadratic expression.

Completing the square is used in

- solving quadratic equations,
- deriving the quadratic formula,
- graphing quadratic functions,
- evaluating integrals in calculus, such as Gaussian integrals with a linear term in the exponent,
^{[1]} - finding Laplace transforms.
^{[2]}^{[3]}

In mathematics, completing the square is often applied in any computation involving quadratic polynomials.

Further information: Algebra § History |

The technique of completing the square was known in the Old Babylonian Empire.^{[4]}

Muhammad ibn Musa Al-Khwarizmi, a famous polymath who wrote the early algebraic treatise Al-Jabr, used the technique of completing the square to solve quadratic equations.^{[5]}

The formula in elementary algebra for computing the square of a binomial is:

For example:

In any perfect square, the coefficient of *x* is twice the number *p*, and the constant term is equal to *p*^{2}.

Consider the following quadratic polynomial:

This quadratic is not a perfect square, since 28 is not the square of 5:

However, it is possible to write the original quadratic as the sum of this square and a constant:

This is called **completing the square**.

Given any monic quadratic

it is possible to form a square that has the same first two terms:

This square differs from the original quadratic only in the value of the constant term. Therefore, we can write

where . This operation is known as

Given a quadratic polynomial of the form

it is possible to factor out the coefficient

Example:

This process of factoring out the coefficient

Example:

This allows the writing of any quadratic polynomial in the form

The result of completing the square may be written as a formula. In the general case, one has^{[6]}

with

In particular, when *a* = 1, one has

with

By solving the equation in terms of and reorganizing the resulting expression, one gets the quadratic formula for the roots of the quadratic equation:

The matrix case looks very similar:

where and . Note that has to be symmetric.

If is not symmetric the formulae for and have to be generalized to:

In analytic geometry, the graph of any quadratic function is a parabola in the *xy*-plane. Given a quadratic polynomial of the form

the numbers

One way to see this is to note that the graph of the function *f*(*x*) = *x*^{2} is a parabola whose vertex is at the origin (0, 0). Therefore, the graph of the function *f*(*x* − *h*) = (*x* − *h*)^{2} is a parabola shifted to the right by *h* whose vertex is at (*h*, 0), as shown in the top figure. In contrast, the graph of the function *f*(*x*) + *k* = *x*^{2} + *k* is a parabola shifted upward by k whose vertex is at (0, *k*), as shown in the center figure. Combining both horizontal and vertical shifts yields *f*(*x* − *h*) + *k* = (*x* − *h*)^{2} + *k* is a parabola shifted to the right by h and upward by k whose vertex is at (*h*, *k*), as shown in the bottom figure.

Completing the square may be used to solve any quadratic equation. For example:

The first step is to complete the square:

Next we solve for the squared term:

Then either

and therefore

This can be applied to any quadratic equation. When the *x*^{2} has a coefficient other than 1, the first step is to divide out the equation by this coefficient: for an example see the non-monic case below.

Unlike methods involving factoring the equation, which is reliable only if the roots are rational, completing the square will find the roots of a quadratic equation even when those roots are irrational or complex. For example, consider the equation

Completing the square gives

so

Then either

In terser language:

so

Equations with complex roots can be handled in the same way. For example:

For an equation involving a non-monic quadratic, the first step to solving them is to divide through by the coefficient of *x*^{2}. For example:

Applying this procedure to the general form of a quadratic equation leads to the quadratic formula.

Completing the square may be used to evaluate any integral of the form

using the basic integrals

For example, consider the integral

Completing the square in the denominator gives:

This can now be evaluated by using the substitution
*u* = *x* + 3, which yields

Consider the expression

where

which is clearly a real quantity. This is because

As another example, the expression

where

Then

so

A matrix *M* is idempotent when *M*^{2} = *M*. Idempotent matrices generalize the idempotent properties of 0 and 1. The completion of the square method of addressing the equation

shows that some idempotent 2×2 matrices are parametrized by a circle in the (

The matrix will be idempotent provided which, upon completing the square, becomes

In the (

This section does not cite any sources. Please help improve this section by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: "Completing the square" – news · newspapers · books · scholar · JSTOR (October 2022) (Learn how and when to remove this template message)

Consider completing the square for the equation

Since *x*^{2} represents the area of a square with side of length *x*, and *bx* represents the area of a rectangle with sides *b* and *x*, the process of completing the square can be viewed as visual manipulation of rectangles.

Simple attempts to combine the *x*^{2} and the *bx* rectangles into a larger square result in a missing corner. The term (*b*/2)^{2} added to each side of the above equation is precisely the area of the missing corner, whence derives the terminology "completing the square".

As conventionally taught, completing the square consists of adding the third term, *v*^{2} to

to get a square. There are also cases in which one can add the middle term, either 2

to get a square.

By writing

we show that the sum of a positive number

Consider the problem of factoring the polynomial

This is

so the middle term is 2(

(the last line being added merely to follow the convention of decreasing degrees of terms).

The same argument shows that is always factorizable as

(Also known as Sophie Germain's identity).

"Completing the square" consists to remark that the two first terms of a quadratic polynomial are also the first terms of the square of a linear polynomial, and to use this for expressing the quadratic polynomial as the sum of a square and a constant.

**Completing the cube** is a similar technique that allows to transform a cubic polynomial into a cubic polynomial without term of degree two.

More precisely, if

is a polynomial in x such that its two first terms are the two first terms of the expanded form of

So, the change of variable

provides a cubic polynomial in without term of degree two, which is called the depressed form of the original polynomial.

This transformation is generally the first step of the mehods for solving the general cubic equation.

More generally, a similar transformation can be used for removing terms of degree in polynomials of degree