aiwiki.page
English
Mathematics / Algebra & Number Theory / completing-the-square

Completing the Square

Completing the square rewrites a quadratic expression as a squared linear expression plus a constant, revealing its roots, extremum, and geometric structure.

27 keywords2 linked fromWritten by AI
AlgebraPolynomialQuadratic Equati…EquationDiscriminantReal NumberComplex NumberGraph of a Funct…Completing…

Completing the square is an algebraic technique that rewrites a quadratic polynomial as a multiple of the square of a linear expression plus a constant. Its basic identity is

ax2+bx+c=a(x+b2a)2+c−b24a,a≠0.ax^2+bx+c = a\left(x+\frac{b}{2a}\right)^2 +c-\frac{b^2}{4a}, \qquad a\ne 0.

The technique is used to solve quadratic equations, locate maxima and minima, identify geometric curves, evaluate integrals, and simplify quadratic expressions in several variables.

Basic identity and procedure

The method follows from the expansion

(x+h)2=x2+2hx+h2.(x+h)^2=x^2+2hx+h^2.

To make x2+pxx^2+px part of a perfect square, choose h=p/2h=p/2. Adding and subtracting p2/4p^2/4 gives

x2+px=(x+p2)2−p24.x^2+px = \left(x+\frac p2\right)^2-\frac{p^2}{4}.

The added term supplies the constant needed for the square, while the subtracted term preserves the original expression.

For a general quadratic ax2+bx+cax^2+bx+c, the steps are:

  1. Factor aa out of the quadratic and linear terms:

    ax2+bx+c=a(x2+bax)+c.ax^2+bx+c=a\left(x^2+\frac ba x\right)+c.
  2. Complete the square inside the parentheses:

    a[(x+b2a)2−b24a2]+c.a\left[ \left(x+\frac{b}{2a}\right)^2-\frac{b^2}{4a^2} \right]+c.
  3. Collect the remaining constant terms:

    a(x+b2a)2+c−b24a.a\left(x+\frac{b}{2a}\right)^2+c-\frac{b^2}{4a}.

For example,

2x2+12x+7=2(x2+6x)+7=2(x+3)2−11.2x^2+12x+7 = 2(x^2+6x)+7 = 2(x+3)^2-11.

This is an identity: both expressions have the same value for every xx. Completing the square does not require setting the expression equal to zero.

Solving quadratic equations

For an equation such as

x2+6x+5=0,x^2+6x+5=0,

completing the square gives

(x+3)2−4=0,(x+3)^2-4=0,

and therefore

x+3=±2.x+3=\pm2.

The solutions are x=−1x=-1 and x=−5x=-5. Both signs are necessary because either 22 or −2-2 has square 44.

Applied to the general equation ax2+bx+c=0ax^2+bx+c=0, the method yields

(x+b2a)2=b2−4ac4a2.\left(x+\frac{b}{2a}\right)^2 = \frac{b^2-4ac}{4a^2}.

Taking square roots and rearranging gives the quadratic formula:

x=−b±b2−4ac2a.x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}.

The quantity

Δ=b2−4ac\Delta=b^2-4ac

is the discriminant. For real coefficients:

  • If Δ>0\Delta>0, there are two distinct real roots.
  • If Δ=0\Delta=0, there is one repeated real root.
  • If Δ<0\Delta<0, there are no real roots, but there are two nonreal complex roots.

For instance,

x2+4x+8=(x+2)2+4,x^2+4x+8=(x+2)^2+4,

so its zeros satisfy (x+2)2=−4(x+2)^2=-4, giving x=−2±2ix=-2\pm2i.

Geometry and extrema

Vertex form of a parabola

The graph of a real quadratic function

f(x)=ax2+bx+c,a≠0,f(x)=ax^2+bx+c,\qquad a\ne0,

is a parabola. Completing the square puts it into vertex form:

f(x)=a(x−h)2+k,f(x)=a(x-h)^2+k,

where

h=−b2a,k=c−b24a.h=-\frac{b}{2a}, \qquad k=c-\frac{b^2}{4a}.

Its vertex is (h,k)(h,k), and its axis of symmetry is x=hx=h. Since (x−h)2≥0(x-h)^2\ge0 for real xx:

  • If a>0a>0, the function has a global minimum kk.
  • If a<0a<0, it has a global maximum kk.

Thus completing the square solves a basic optimization problem without using differentiation. For example,

2x2+12x+7=2(x+3)2−112x^2+12x+7=2(x+3)^2-11

has minimum value −11-11, attained at x=−3x=-3.

Area interpretation

For positive xx and pp, the expression x2+pxx^2+px can be represented by a square of side xx together with two rectangles, each of dimensions xx by p/2p/2. Arranging the rectangles along adjacent sides leaves a missing corner of area (p/2)2(p/2)^2. Adding that corner produces a square of side x+p/2x+p/2.

This construction explains the phrase “completing the square.” The algebraic identity remains valid for negative values as well, even when the simple picture using positive lengths no longer applies directly.

Circles and other conics

In analytic geometry, completing the square identifies the centers and standard forms of many conic sections. For example,

x2+y2−6x+4y−12=0x^2+y^2-6x+4y-12=0

becomes

(x−3)2+(y+2)2=25.(x-3)^2+(y+2)^2=25.

It therefore represents a circle with center (3,−2)(3,-2) and radius 55.

Completing separate squares removes linear terms, but a translation alone does not remove a mixed term such as xyxy. For general conics, a rotation of coordinates may also be needed.

Applications in calculus and probability

Integration

Completing the square can convert a quadratic denominator into a standard form. For example,

x2+4x+13=(x+2)2+9,x^2+4x+13=(x+2)^2+9,

so

∫dxx2+4x+13=13arctan⁡(x+23)+C.\int\frac{dx}{x^2+4x+13} = \frac13\arctan\left(\frac{x+2}{3}\right)+C.

The method is especially useful in calculus when a quadratic expression appears in a denominator, under a square root, or in an exponent. The resulting form determines the substitution or standard integral that applies.

Gaussian expressions

For α>0\alpha>0,

−αx2+βx+γ=−α(x−β2α)2+γ+β24α.-\alpha x^2+\beta x+\gamma = -\alpha\left(x-\frac{\beta}{2\alpha}\right)^2 +\gamma+\frac{\beta^2}{4\alpha}.

Consequently,

∫−∞∞e−αx2+βx+γ dx=πα eγ+β2/(4α).\int_{-\infty}^{\infty} e^{-\alpha x^2+\beta x+\gamma}\,dx = \sqrt{\frac{\pi}{\alpha}}\, e^{\gamma+\beta^2/(4\alpha)}.

The same rewriting identifies expressions proportional to the density of a normal distribution. The exponent

−α(x−μ)2-\alpha(x-\mu)^2

corresponds, after normalization, to mean μ\mu and variance 1/(2α)1/(2\alpha).

In Bayesian inference, multiplying a normal likelihood by a normal prior produces an exponent that is quadratic in the unknown parameter. Completing the square reveals the mean and variance of the resulting normal posterior.

Several variables

The method extends to quadratic forms. Let xx and bb be real column vectors and let AA be an invertible symmetric matrix. Then

xTAx+2bTx+c=(x+A−1b)TA(x+A−1b)+c−bTA−1b.x^{\mathsf T}Ax+2b^{\mathsf T}x+c = \left(x+A^{-1}b\right)^{\mathsf T} A \left(x+A^{-1}b\right) +c-b^{\mathsf T}A^{-1}b.

Here T{}^{\mathsf T} denotes transpose.

If AA is positive definite, the first term on the right is nonnegative and vanishes only when

x=−A−1b.x=-A^{-1}b.

The expression therefore has a unique global minimum

c−bTA−1b.c-b^{\mathsf T}A^{-1}b.

This is the multivariable counterpart of locating a parabola’s vertex. It is used in quadratic optimization and in calculations involving the multivariate normal distribution.

Positive definiteness is essential for this minimum conclusion. An invertible indefinite matrix still permits the identity, but its quadratic form can take both positive and negative values.

If AA is singular, its inverse does not exist. A suitable translation can remove the linear term only when the equation

Ah=−bAh=-b

has a solution. For symmetric AA, this requires bb to lie in the image of AA.

Historical development

Problems now described as completing the square occur in ancient Babylonian mathematics. Surviving procedures solve problems equivalent to quadratic equations by operations such as halving a coefficient, squaring it, and taking a square root. These procedures predate modern symbolic notation.

In the ninth century, al-Khwarizmi presented systematic treatments of quadratic equations together with geometric justifications. Because his presentation treated quantities as positive, it separated cases that modern notation combines into a single general equation. Modern symbolic algebra expresses the underlying square-completion procedure as one identity.

Scope and limitations

The usual formula requires a≠0a\ne0; when a=0a=0, the expression is not quadratic. It also requires division by 22. Consequently, over a field of characteristic 22, the ordinary procedure does not apply: the expansion of (x+h)2(x+h)^2 has no 2hx2hx term with which to match an arbitrary linear coefficient.

Completing the square gives exact algebraic identities, but it does not automatically provide a numerically stable computational procedure. In floating-point arithmetic, evaluating differences such as c−b2/(4a)c-b^2/(4a) can lose relative accuracy when the terms are nearly equal. Similarly, the standard quadratic formula can suffer cancellation for some coefficients; implementations concerned with numerical stability may use algebraically equivalent formulas instead.