{
  "id": "completing-the-square",
  "title": "Completing the Square",
  "lang": "en",
  "source_lang": "en",
  "summary": "Completing the square rewrites a quadratic expression as a squared linear expression plus a constant, revealing its roots, extremum, and geometric structure.",
  "category": "mathematics",
  "subcategory": "algebra",
  "type": "concept",
  "aliases": [
    "Square completion"
  ],
  "generated_at": "2026-11-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/completing-the-square/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/completing-the-square/",
      "json": "https://aiwiki.page/zh/completing-the-square.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "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\n\n\\[ax^2+bx+c = a\\left(x+\\frac{b}{2a}\\right)^2 +c-\\frac{b^2}{4a}, \\qquad a\\ne 0.\\]\n\nThe technique is used to solve quadratic equations, locate maxima and minima, identify geometric curves, evaluate integrals, and simplify quadratic expressions in several variables."
    },
    {
      "heading": "Basic identity and procedure",
      "text": "The method follows from the expansion\n\n\\[(x+h)^2=x^2+2hx+h^2.\\]\n\nTo make \\(x^2+px\\) part of a perfect square, choose \\(h=p/2\\). Adding and subtracting \\(p^2/4\\) gives\n\n\\[x^2+px = \\left(x+\\frac p2\\right)^2-\\frac{p^2}{4}.\\]\n\nThe added term supplies the constant needed for the square, while the subtracted term preserves the original expression.\n\nFor a general quadratic \\(ax^2+bx+c\\), the steps are:\n\n- Factor \\(a\\) out of the quadratic and linear terms:\n\n\\[ax^2+bx+c=a\\left(x^2+\\frac ba x\\right)+c.\\]\n- Complete the square inside the parentheses:\n\n\\[a\\left[ \\left(x+\\frac{b}{2a}\\right)^2-\\frac{b^2}{4a^2} \\right]+c.\\]\n- Collect the remaining constant terms:\n\n\\[a\\left(x+\\frac{b}{2a}\\right)^2+c-\\frac{b^2}{4a}.\\]\n\nFor example,\n\n\\[2x^2+12x+7 = 2(x^2+6x)+7 = 2(x+3)^2-11.\\]\n\nThis is an identity: both expressions have the same value for every \\(x\\). Completing the square does not require setting the expression equal to zero."
    },
    {
      "heading": "Solving quadratic equations",
      "text": "For an equation such as\n\n\\[x^2+6x+5=0,\\]\n\ncompleting the square gives\n\n\\[(x+3)^2-4=0,\\]\n\nand therefore\n\n\\[x+3=\\pm2.\\]\n\nThe solutions are \\(x=-1\\) and \\(x=-5\\). Both signs are necessary because either \\(2\\) or \\(-2\\) has square \\(4\\).\n\nApplied to the general equation \\(ax^2+bx+c=0\\), the method yields\n\n\\[\\left(x+\\frac{b}{2a}\\right)^2 = \\frac{b^2-4ac}{4a^2}.\\]\n\nTaking square roots and rearranging gives the quadratic formula:\n\n\\[x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}.\\]\n\nThe quantity\n\n\\[\\Delta=b^2-4ac\\]\n\nis the discriminant. For real coefficients:\n\n- If \\(\\Delta>0\\), there are two distinct real roots.\n- If \\(\\Delta=0\\), there is one repeated real root.\n- If \\(\\Delta<0\\), there are no real roots, but there are two nonreal complex roots.\n\nFor instance,\n\n\\[x^2+4x+8=(x+2)^2+4,\\]\n\nso its zeros satisfy \\((x+2)^2=-4\\), giving \\(x=-2\\pm2i\\)."
    },
    {
      "heading": "Geometry and extrema",
      "text": "Vertex form of a parabola\n\nThe graph of a real quadratic function\n\n\\[f(x)=ax^2+bx+c,\\qquad a\\ne0,\\]\n\nis a parabola. Completing the square puts it into vertex form:\n\n\\[f(x)=a(x-h)^2+k,\\]\n\nwhere\n\n\\[h=-\\frac{b}{2a}, \\qquad k=c-\\frac{b^2}{4a}.\\]\n\nIts vertex is \\((h,k)\\), and its axis of symmetry is \\(x=h\\). Since \\((x-h)^2\\ge0\\) for real \\(x\\):\n\n- If \\(a>0\\), the function has a global minimum \\(k\\).\n- If \\(a<0\\), it has a global maximum \\(k\\).\n\nThus completing the square solves a basic optimization problem without using differentiation. For example,\n\n\\[2x^2+12x+7=2(x+3)^2-11\\]\n\nhas minimum value \\(-11\\), attained at \\(x=-3\\).\n\nArea interpretation\n\nFor positive \\(x\\) and \\(p\\), the expression \\(x^2+px\\) can be represented by a square of side \\(x\\) together with two rectangles, each of dimensions \\(x\\) by \\(p/2\\). Arranging the rectangles along adjacent sides leaves a missing corner of area \\((p/2)^2\\). Adding that corner produces a square of side \\(x+p/2\\).\n\nThis 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.\n\nCircles and other conics\n\nIn analytic geometry, completing the square identifies the centers and standard forms of many conic sections. For example,\n\n\\[x^2+y^2-6x+4y-12=0\\]\n\nbecomes\n\n\\[(x-3)^2+(y+2)^2=25.\\]\n\nIt therefore represents a circle with center \\((3,-2)\\) and radius \\(5\\).\n\nCompleting separate squares removes linear terms, but a translation alone does not remove a mixed term such as \\(xy\\). For general conics, a rotation of coordinates may also be needed."
    },
    {
      "heading": "Applications in calculus and probability",
      "text": "Integration\n\nCompleting the square can convert a quadratic denominator into a standard form. For example,\n\n\\[x^2+4x+13=(x+2)^2+9,\\]\n\nso\n\n\\[\\int\\frac{dx}{x^2+4x+13} = \\frac13\\arctan\\left(\\frac{x+2}{3}\\right)+C.\\]\n\nThe 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.\n\nGaussian expressions\n\nFor \\(\\alpha>0\\),\n\n\\[-\\alpha x^2+\\beta x+\\gamma = -\\alpha\\left(x-\\frac{\\beta}{2\\alpha}\\right)^2 +\\gamma+\\frac{\\beta^2}{4\\alpha}.\\]\n\nConsequently,\n\n\\[\\int_{-\\infty}^{\\infty} e^{-\\alpha x^2+\\beta x+\\gamma}\\,dx = \\sqrt{\\frac{\\pi}{\\alpha}}\\, e^{\\gamma+\\beta^2/(4\\alpha)}.\\]\n\nThe same rewriting identifies expressions proportional to the density of a normal distribution. The exponent\n\n\\[-\\alpha(x-\\mu)^2\\]\n\ncorresponds, after normalization, to mean \\(\\mu\\) and variance \\(1/(2\\alpha)\\).\n\nIn 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."
    },
    {
      "heading": "Several variables",
      "text": "The method extends to quadratic forms. Let \\(x\\) and \\(b\\) be real column vectors and let \\(A\\) be an invertible symmetric matrix. Then\n\n\\[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.\\]\n\nHere \\({}^{\\mathsf T}\\) denotes transpose.\n\nIf \\(A\\) is positive definite, the first term on the right is nonnegative and vanishes only when\n\n\\[x=-A^{-1}b.\\]\n\nThe expression therefore has a unique global minimum\n\n\\[c-b^{\\mathsf T}A^{-1}b.\\]\n\nThis is the multivariable counterpart of locating a parabola’s vertex. It is used in quadratic optimization and in calculations involving the multivariate normal distribution.\n\nPositive 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.\n\nIf \\(A\\) is singular, its inverse does not exist. A suitable translation can remove the linear term only when the equation\n\n\\[Ah=-b\\]\n\nhas a solution. For symmetric \\(A\\), this requires \\(b\\) to lie in the image of \\(A\\)."
    },
    {
      "heading": "Historical development",
      "text": "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.\n\nIn 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."
    },
    {
      "heading": "Scope and limitations",
      "text": "The usual formula requires \\(a\\ne0\\); when \\(a=0\\), the expression is not quadratic. It also requires division by \\(2\\). Consequently, over a field of characteristic \\(2\\), the ordinary procedure does not apply: the expansion of \\((x+h)^2\\) has no \\(2hx\\) term with which to match an arbitrary linear coefficient.\n\nCompleting 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-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."
    }
  ],
  "links": [
    "algebra",
    "polynomial",
    "quadratic-equation",
    "equation",
    "discriminant",
    "real-number",
    "complex-number",
    "graph-of-a-function",
    "parabola",
    "mathematical-optimization",
    "analytic-geometry",
    "conic-section",
    "circle",
    "calculus",
    "integral",
    "probability-density-function",
    "normal-distribution",
    "variance",
    "bayesian-inference",
    "quadratic-form",
    "matrix",
    "positive-definite-matrix",
    "multivariate-normal-distribution",
    "al-khwarizmi",
    "field-mathematics",
    "floating-point-arithmetic",
    "numerical-stability"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}