Skip to content
The Lumenary
Grades 9–12Ages 14–18 75 min

Quadratic equations and functions

Three ways to solve ax2+bx+c=0ax^2 + bx + c = 0, one number that says how many solutions there are, and the parabola that draws it all.

Formally verified · 13 LeanComputationally tested · 2 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review

Your guides: Chloe, Margaret, Gideon

MotivationH

A garden against a wall

Students at a secondary school in Kisumu are fencing a vegetable garden against the long wall of their classroom block. They have 2020 metres of fencing for the other three sides. If the two sides that stick out from the wall are xx metres long, the side parallel to the wall is 20−2x20 - 2x metres, and the garden's area is

A(x)=x(20−2x)=20x−2x2square metres.A(x) = x(20 - 2x) = 20x - 2x^2 \quad \text{square metres}.

Two questions come up at once. The agriculture teacher wants exactly 48 m248\ \text{m}^2: what should xx be? And what is the largest garden the fencing can enclose?

The first question is an equation, −2x2+20x=48-2x^2 + 20x = 48, in which the unknown appears squared: a quadratic equation. The second is about the highest point of the graph of AA, which turns out to be a parabola. By the end of this lesson you will be able to answer both, and to prove that your answers are right.

IntuitionH

Completing the square: a picture from Baghdad

Around 820 CE, the scholar Muḥammad ibn Mūsā al-Khwārizmī, working in Baghdad, explained how to solve "a square and ten roots equal thirty-nine": in our notation, x2+10x=39x^2 + 10x = 39. His explanation was a picture.

x²5x5x25x5x5side x + 5
Completing the square for x² + 10x = 39. The square x² and two strips of 5x make the L-shaped area 39. The missing corner is a 5 × 5 square of area 25, so the completed square has area 39 + 25 = 64 and side x + 5 = 8.

Split the 10x10x into two strips of 5x5x and lay them along two sides of the square x2x^2. The L-shape has area 3939, and it is a large square with a 5×55 \times 5 corner missing. Add that corner to both sides:

x2+10x+25=64,(x+5)2=64,x+5=8,x=3.x^2 + 10x + 25 = 64, \qquad (x + 5)^2 = 64, \qquad x + 5 = 8, \qquad x = 3.

Every quadratic equation can be solved this way. Doing it once and for all, with letters instead of numbers, produces the quadratic formula.

DefinitionsH

Definitions

Definition— quadratic equation and function

A quadratic equation is an equation ax2+bx+c=0ax^2 + bx + c = 0 where a,b,ca, b, c are real numbers and a≠0a \neq 0. The function f(x)=ax2+bx+cf(x) = ax^2 + bx + c is a quadratic function, and its graph is called a parabola. A solution of the equation is a root of ff (or a zero).

Definition— discriminant

The discriminant of ax2+bx+cax^2 + bx + c is the number Δ=b2−4ac\Delta = b^2 - 4ac.

Definition— vertex and axis of symmetry

The vertex of a parabola is its lowest point (if a>0a > 0) or highest point (if a<0a < 0). The axis of symmetry is the vertical line through the vertex: the parabola is its own mirror image in this line.

We will use one property of the real numbers again and again.

Theorem— Zero-product property

For real numbers uu and vv: if uv=0uv = 0, then u=0u = 0 or v=0v = 0.

Proof

Suppose uv=0uv = 0 and u≠0u \neq 0. Multiplying both sides by 1/u1/u gives v=1u⋅0=0v = \tfrac{1}{u} \cdot 0 = 0.

∎

Worked examplesH

Worked examples

Example— By factorising: the garden

The garden needs 20x−2x2=4820x - 2x^2 = 48. Rearranging and dividing by 22: x2−10x+24=0x^2 - 10x + 24 = 0. We look for two numbers with product 2424 and sum −10-10: −4-4 and −6-6. So

(x−4)(x−6)=0,(x - 4)(x - 6) = 0,

and by the zero-product property x=4x = 4 or x=6x = 6. Both work: a 4×124 \times 12 garden or a 6×86 \times 8 garden. Factorising is quick when the roots are whole numbers, but most quadratics do not factorise so nicely.

Example— By completing the square

Solve x2+6x−7=0x^2 + 6x - 7 = 0. Half of 66 is 33, and (x+3)2=x2+6x+9(x + 3)^2 = x^2 + 6x + 9, so

x2+6x−7=(x+3)2−16=0⟹(x+3)2=16⟹x+3=±4.x^2 + 6x - 7 = (x + 3)^2 - 16 = 0 \quad\Longrightarrow\quad (x + 3)^2 = 16 \quad\Longrightarrow\quad x + 3 = \pm 4.

So x=1x = 1 or x=−7x = -7. Do not forget the ±\pm: both 424^2 and (−4)2(-4)^2 are 1616.

Example— By the formula

Solve 2x2−4x−3=02x^2 - 4x - 3 = 0. Here a=2a = 2, b=−4b = -4, c=−3c = -3 and Δ=16+24=40>0\Delta = 16 + 24 = 40 > 0, so there are two real roots:

x=4±404=1±102≈2.58 or −0.58.x = \frac{4 \pm \sqrt{40}}{4} = 1 \pm \frac{\sqrt{10}}{2} \approx 2.58 \text{ or } -0.58.

Example— What the discriminant says

  • x2−4x+4x^2 - 4x + 4: Δ=16−16=0\Delta = 16 - 16 = 0. One root, x=2x = 2, because x2−4x+4=(x−2)2x^2 - 4x + 4 = (x - 2)^2. The parabola just touches the xx-axis.
  • x2+x+1x^2 + x + 1: Δ=1−4=−3<0\Delta = 1 - 4 = -3 < 0. No real roots: the parabola stays above the axis. In the complex numbers there are two roots, x=−1±i32x = \tfrac{-1 \pm i\sqrt 3}{2}.

Example— A quadratic with given roots

Find a quadratic with roots 2+32 + \sqrt 3 and 2−32 - \sqrt 3. Their sum is 44 and their product is 4−3=14 - 3 = 1. By Vieta's formulas (proved below), x2−4x+1x^2 - 4x + 1 works. Check with the formula: x=4±122=2±3x = \tfrac{4 \pm \sqrt{12}}{2} = 2 \pm \sqrt 3.

Example— The largest garden

A(x)=−2x2+20xA(x) = -2x^2 + 20x has a=−2<0a = -2 < 0, so its vertex is a highest point, at x=−b2a=−20−4=5x = -\tfrac{b}{2a} = -\tfrac{20}{-4} = 5. The largest garden is 55 m by 1010 m, with area A(5)=50 m2A(5) = 50\ \text{m}^2. Completing the square shows it directly: A(x)=50−2(x−5)2A(x) = 50 - 2(x - 5)^2, and 2(x−5)2≥02(x - 5)^2 \ge 0.

Example— A ball kicked upwards

A footballer kicks a ball straight up from a height of 11 m at 1414 m/s. Ignoring air resistance (a modelling assumption), its height after tt seconds is about h(t)=1+14t−4.9t2h(t) = 1 + 14t - 4.9t^2 metres. The vertex is at t=149.8≈1.43t = \tfrac{14}{9.8} \approx 1.43 s, and the maximum height is

hmax⁡=c−b24a=1−1964⋅(−4.9)=1+10=11 m.h_{\max} = c - \frac{b^2}{4a} = 1 - \frac{196}{4 \cdot (-4.9)} = 1 + 10 = 11 \text{ m}.

The ball lands when h(t)=0h(t) = 0: t=14+196+19.69.8≈2.93t = \tfrac{14 + \sqrt{196 + 19.6}}{9.8} \approx 2.93 s. The other root, about −0.07-0.07 s, is a valid solution of the equation but means nothing for the ball. Always ask which roots make sense in the situation.

ProofH

Proofs: the formula, the discriminant and the vertex

Theorem— Completing the square

If a≠0a \neq 0, then for every xx:

ax2+bx+c=a(x+b2a)2−b2−4ac4a.ax^2 + bx + c = a\left(x + \frac{b}{2a}\right)^2 - \frac{b^2 - 4ac}{4a}.

Proof

Expand the right-hand side: a(x2+bax+b24a2)−b24a+4ac4a=ax2+bx+b24a−b24a+c=ax2+bx+ca\left(x^2 + \tfrac{b}{a}x + \tfrac{b^2}{4a^2}\right) - \tfrac{b^2}{4a} + \tfrac{4ac}{4a} = ax^2 + bx + \tfrac{b^2}{4a} - \tfrac{b^2}{4a} + c = ax^2 + bx + c.

∎

Multiplying by 4a4a clears every fraction and gives an identity that holds even when a=0a = 0:

4a (ax2+bx+c)=(2ax+b)2−(b2−4ac).(∗)4a\,(ax^2 + bx + c) = (2ax + b)^2 - (b^2 - 4ac). \tag{$\ast$}

Theorem— Quadratic formula

Let a≠0a \ne 0 and Δ=b2−4ac≥0\Delta = b^2 - 4ac \ge 0. Then ax2+bx+c=0ax^2 + bx + c = 0 if and only if

x=−b+Δ2aorx=−b−Δ2a.x = \frac{-b + \sqrt{\Delta}}{2a} \quad \text{or} \quad x = \frac{-b - \sqrt{\Delta}}{2a}.

Proof

By (∗)(\ast), and because 4a≠04a \neq 0, the equation ax2+bx+c=0ax^2 + bx + c = 0 is equivalent to (2ax+b)2=Δ(2ax + b)^2 = \Delta. Since Δ≥0\Delta \ge 0, it has the square root s=Δ≥0s = \sqrt\Delta \ge 0, and (2ax+b)2=s2(2ax + b)^2 = s^2 means (2ax+b−s)(2ax+b+s)=0(2ax + b - s)(2ax + b + s) = 0. By the zero-product property, 2ax+b=s2ax + b = s or 2ax+b=−s2ax + b = -s, that is, x=−b±s2ax = \tfrac{-b \pm s}{2a}. Every step is reversible, so these two numbers are roots, and there are no others.

∎

Theorem— The discriminant decides

For a≠0a \neq 0, the equation ax2+bx+c=0ax^2 + bx + c = 0 has

  • two different real roots if Δ>0\Delta > 0;
  • exactly one real root, x=−b2ax = -\tfrac{b}{2a}, if Δ=0\Delta = 0;
  • no real roots if Δ<0\Delta < 0.

Proof

If Δ>0\Delta > 0 then Δ>0\sqrt\Delta > 0, and the two roots given by the formula differ by 2Δ2a≠0\tfrac{2\sqrt\Delta}{2a} \ne 0. If Δ=0\Delta = 0 the formula gives −b2a-\tfrac{b}{2a} twice. If Δ<0\Delta < 0, a root xx would satisfy (2ax+b)2=Δ<0(2ax + b)^2 = \Delta < 0 by (∗)(\ast). But the square of a real number is never negative.

∎

Theorem— Vieta's formulas

If rr and ss are the roots of ax2+bx+cax^2 + bx + c (with r=sr = s allowed when Δ=0\Delta = 0), then

r+s=−ba,rs=ca.r + s = -\frac{b}{a}, \qquad rs = \frac{c}{a}.

Proof

From the formula: r+s=−b+Δ−b−Δ2a=−bar + s = \tfrac{-b + \sqrt\Delta - b - \sqrt\Delta}{2a} = -\tfrac{b}{a} and rs=b2−Δ4a2=4ac4a2=cars = \tfrac{b^2 - \Delta}{4a^2} = \tfrac{4ac}{4a^2} = \tfrac{c}{a}.

Without the formula, for two different roots: subtracting as2+bs+c=0as^2 + bs + c = 0 from ar2+br+c=0ar^2 + br + c = 0 gives (r−s)(a(r+s)+b)=0(r - s)\big(a(r + s) + b\big) = 0. Since r−s≠0r - s \neq 0, r+s=−b/ar + s = -b/a. Then c=−ar2−br=−ar2+a(r+s)r=arsc = -ar^2 - br = -ar^2 + a(r + s)r = ars.

∎

Equivalently, ax2+bx+c=a(x−r)(x−s)ax^2 + bx + c = a(x - r)(x - s). This is the factor theorem of the polynomials lesson at work: each root gives a factor.

Theorem— Vertex and axis of symmetry

Let f(x)=ax2+bx+cf(x) = ax^2 + bx + c with a≠0a \neq 0 and put h=−b2ah = -\tfrac{b}{2a}. Then:

  1. f(h+t)=f(h−t)f(h + t) = f(h - t) for every tt: the line x=hx = h is an axis of symmetry;
  2. f(h)=c−b24a=−Δ4af(h) = c - \tfrac{b^2}{4a} = -\tfrac{\Delta}{4a};
  3. if a>0a > 0 then f(x)≥f(h)f(x) \ge f(h) for all xx (the vertex (h,f(h))(h, f(h)) is the lowest point); if a<0a < 0 then f(x)≤f(h)f(x) \le f(h) (it is the highest point).

Proof

By completing the square, f(x)=a(x−h)2+f(h)f(x) = a(x - h)^2 + f(h) with f(h)=−Δ4af(h) = -\tfrac{\Delta}{4a}. Then f(h+t)=at2+f(h)=f(h−t)f(h + t) = at^2 + f(h) = f(h - t), which proves 1. For 3, f(x)−f(h)=a(x−h)2f(x) - f(h) = a(x - h)^2 has the sign of aa, because (x−h)2≥0(x - h)^2 \ge 0.

∎

Note

There is a pleasant shortcut, popularised by Po-Shen Loh in 2019 (and, as he points out, rooted in very old ideas). Divide by aa to get x2+Bx+C=0x^2 + Bx + C = 0. By Vieta, the roots have average −B/2-B/2, so write them as −B2±u-\tfrac{B}{2} \pm u. Their product is B24−u2=C\tfrac{B^2}{4} - u^2 = C, so u=B24−Cu = \sqrt{\tfrac{B^2}{4} - C} — the quadratic formula again.

Formal mathematicsF

The proofs, checked by Lean

In Lean the real numbers are ℝ and Real.sqrt is the square root. The tactic field_simp clears denominators (it needs to know a≠0a \neq 0), and ring checks polynomial identities. Completing the square, and the fraction-free identity (∗)(\ast):

complete_squareLean 4Proved here from basic factsFormally verified
/-- **Completing the square:** for `a ≠ 0`,
`ax² + bx + c = a(x + b/(2a))² − (b² − 4ac)/(4a)`.
`field_simp` clears the denominators `2a` and `4a`, and `ring` checks the resulting identity. -/
theorem complete_square {a b c : ℝ} (ha : a ≠ 0) (x : ℝ) :
    a * x ^ 2 + b * x + c = a * (x + b / (2 * a)) ^ 2 - (b ^ 2 - 4 * a * c) / (4 * a) := by
  field_simp
  ring
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor
times_four_aLean 4Proved here from basic factsFormally verified
/-- **The identity behind every case:** `4a(ax² + bx + c) = (2ax + b)² − (b² − 4ac)`.
This is completing the square with the fractions cleared, and it holds even when `a = 0`. -/
theorem times_four_a (a b c x : ℝ) :
    4 * a * (a * x ^ 2 + b * x + c) = (2 * a * x + b) ^ 2 - (b ^ 2 - 4 * a * c) := by
  ring
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor

The quadratic formula is an "if and only if": the two numbers are roots, and they are the only roots. The proof factorises the quadratic as a(x−r1)(x−r2)a(x - r_1)(x - r_2) and uses the zero-product property mul_eq_zero:

quadratic_formulaLean 4Proved here from basic factsFormally verified
/-- **The quadratic formula.** If `a ≠ 0` and `Δ = b² − 4ac ≥ 0`, then
`ax² + bx + c = 0` exactly when `x = (−b + √Δ)/(2a)` or `x = (−b − √Δ)/(2a)`.
Proof: with `s = √Δ` (so `s² = Δ`), the quadratic factorises as `a(x − r₁)(x − r₂)` with
`r₁, r₂ = (−b ± s)/(2a)`; then use the zero-product property and `a ≠ 0`. Both directions are
proved: these numbers are roots, and there are no other roots. -/
theorem quadratic_formula {a b c : ℝ} (ha : a ≠ 0) (hΔ : 0 ≤ b ^ 2 - 4 * a * c) (x : ℝ) :
    a * x ^ 2 + b * x + c = 0 ↔
      x = (-b + Real.sqrt (b ^ 2 - 4 * a * c)) / (2 * a) ∨
        x = (-b - Real.sqrt (b ^ 2 - 4 * a * c)) / (2 * a) := by
  set s := Real.sqrt (b ^ 2 - 4 * a * c) with hs
  have hs2 : s ^ 2 = b ^ 2 - 4 * a * c := Real.sq_sqrt hΔ
  -- the factorisation `a(x − r₁)(x − r₂)`
  have expand : a * (x - (-b + s) / (2 * a)) * (x - (-b - s) / (2 * a)) =
      a * x ^ 2 + b * x + (b ^ 2 - s ^ 2) / (4 * a) := by
    field_simp
    ring
  have key : a * x ^ 2 + b * x + c = a * (x - (-b + s) / (2 * a)) * (x - (-b - s) / (2 * a)) := by
    rw [expand, hs2]
    field_simp
    ring
  rw [key]
  constructor
  · intro h
    rcases mul_eq_zero.mp h with h1 | h2
    · rcases mul_eq_zero.mp h1 with h3 | h4
      · exact absurd h3 ha
      · exact Or.inl (sub_eq_zero.mp h4)
    · exact Or.inr (sub_eq_zero.mp h2)
  · rintro (h | h) <;> rw [h] <;> ring
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor

Mathlib proves the formula over any field in which 2≠02 \neq 0, assuming only that the discriminant has some square root ss. That is why the same theorem covers the complex numbers, where every number has a square root:

quadratic_formula_libraryLean 4Applies a library theoremFormally verified
/-- **The quadratic formula, Mathlib's form,** over any field in which `2 ≠ 0` (the rationals,
the reals, the complex numbers, the integers modulo an odd prime, …): if `s * s = b² − 4ac`
then the roots are `(−b ± s)/(2a)`. This applies `quadratic_eq_zero_iff`. Over the complex
numbers a square root `s` always exists, so every quadratic has roots there. -/
theorem quadratic_formula_library {K : Type*} [Field K] [NeZero (2 : K)] {a b c s : K}
    (ha : a ≠ 0) (h : discrim a b c = s * s) (x : K) :
    a * (x * x) + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) :=
  quadratic_eq_zero_iff ha h x
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor

The three cases of the discriminant:

no_real_rootsLean 4Proved here from basic factsFormally verified
/-- **`Δ < 0`: no real roots.** If `ax² + bx + c = 0` then the identity `times_four_a` gives
`(2ax + b)² − Δ = 4a · 0 = 0` (`linear_combination` checks this), so `(2ax + b)² = Δ`. A square of
a real number is never negative, so `Δ ≥ 0`. (No assumption `a ≠ 0` is needed.) -/
theorem no_real_roots {a b c : ℝ} (hΔ : b ^ 2 - 4 * a * c < 0) (x : ℝ) :
    a * x ^ 2 + b * x + c ≠ 0 := by
  intro h
  have hsq : (2 * a * x + b) ^ 2 = b ^ 2 - 4 * a * c := by
    linear_combination 4 * a * h
  nlinarith [sq_nonneg (2 * a * x + b)]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor
one_rootLean 4Proved here from basic factsFormally verified
/-- **`Δ = 0`: exactly one real root,** `x = −b/(2a)` (a "double root").
By `times_four_a`, `4a(ax² + bx + c) = (2ax + b)²`, which is zero exactly when `2ax + b = 0`. -/
theorem one_root {a b c : ℝ} (ha : a ≠ 0) (hΔ : b ^ 2 - 4 * a * c = 0) (x : ℝ) :
    a * x ^ 2 + b * x + c = 0 ↔ x = -b / (2 * a) := by
  have h4 : 4 * a * (a * x ^ 2 + b * x + c) = (2 * a * x + b) ^ 2 := by
    rw [times_four_a, hΔ, sub_zero]
  constructor
  · intro h
    have hsq : (2 * a * x + b) ^ 2 = 0 := by rw [← h4, h, mul_zero]
    have hlin : 2 * a * x + b = 0 := pow_eq_zero_iff (n := 2) (by norm_num) |>.mp hsq
    field_simp
    linarith
  · intro hx
    have hlin : 2 * a * x + b = 0 := by rw [hx]; field_simp; ring
    have h4a : (4 * a) * (a * x ^ 2 + b * x + c) = 0 := by rw [h4, hlin]; ring
    rcases mul_eq_zero.mp h4a with h | h
    · exact absurd (by linarith : a = 0) ha
    · exact h
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor
two_roots_distinctLean 4Proved here from basic factsFormally verified
/-- **`Δ > 0`: the two roots are different.** They differ by `2√Δ/(2a)`, and `√Δ > 0`. -/
theorem two_roots_distinct {a b c : ℝ} (ha : a ≠ 0) (hΔ : 0 < b ^ 2 - 4 * a * c) :
    (-b + Real.sqrt (b ^ 2 - 4 * a * c)) / (2 * a) ≠
      (-b - Real.sqrt (b ^ 2 - 4 * a * c)) / (2 * a) := by
  have hs : 0 < Real.sqrt (b ^ 2 - 4 * a * c) := Real.sqrt_pos.mpr hΔ
  intro h
  have h2a : (2 * a) ≠ 0 := mul_ne_zero two_ne_zero ha
  rw [div_left_inj' h2a] at h
  linarith
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor
discrim_le_zero_libraryLean 4Applies a library theoremFormally verified
/-- **The converse view:** if `ax² + bx + c ≥ 0` for every `x`, then `Δ ≤ 0`.
(A parabola that never dips below the axis cannot cross it twice.) This applies Mathlib's
`discrim_le_zero`. -/
theorem discrim_le_zero_library {a b c : ℝ} (h : ∀ x : ℝ, 0 ≤ a * (x * x) + b * x + c) :
    discrim a b c ≤ 0 :=
  discrim_le_zero h
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor

Vieta's formulas, proved the second way (without the formula):

vietaLean 4Proved here from basic factsFormally verified
/-- **Vieta's formulas.** If `r ≠ s` are both roots of `ax² + bx + c` with `a ≠ 0`, then
`r + s = −b/a` and `rs = c/a`.
Subtracting the two equations gives `(r − s)(a(r + s) + b) = 0`, and `r − s ≠ 0`; then
`c = −ar² − br = ar(r + s) − ar² = ars`. -/
theorem vieta {a b c r s : ℝ} (ha : a ≠ 0) (hrs : r ≠ s)
    (hr : a * r ^ 2 + b * r + c = 0) (hs : a * s ^ 2 + b * s + c = 0) :
    r + s = -b / a ∧ r * s = c / a := by
  have hdiff : (r - s) * (a * (r + s) + b) = 0 := by linear_combination hr - hs
  have hsum : a * (r + s) + b = 0 :=
    (mul_eq_zero.mp hdiff).resolve_left (sub_ne_zero.mpr hrs)
  constructor
  · field_simp
    linarith
  · have hc : c = a * (r * s) := by linear_combination hr - r * hsum
    rw [hc]
    field_simp
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor

The vertex, the axis of symmetry and the optimisation problem. The garden's area is 2x(10−x)2x(10 - x), which is twice x(P/2−x)x(P/2 - x) with P=20P = 20, so rectangle_max shows that it is largest at x=P/4=5x = P/4 = 5:

vertex_minLean 4Proved here from basic factsFormally verified
/-- **The vertex is the lowest point** when `a > 0`. With `h = −b/(2a)`,
`f(x) − f(h) = a(x − h)² ≥ 0` for every `x`. -/
theorem vertex_min {a b c : ℝ} (ha : 0 < a) (x : ℝ) :
    a * (-b / (2 * a)) ^ 2 + b * (-b / (2 * a)) + c ≤ a * x ^ 2 + b * x + c := by
  have hdiff : a * x ^ 2 + b * x + c - (a * (-b / (2 * a)) ^ 2 + b * (-b / (2 * a)) + c) =
      a * (x + b / (2 * a)) ^ 2 := by
    field_simp
    ring
  have hnonneg : 0 ≤ a * (x + b / (2 * a)) ^ 2 := by positivity
  linarith
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor
vertex_valueLean 4Proved here from basic factsFormally verified
/-- **The height of the vertex** is `f(−b/(2a)) = c − b²/(4a) = −Δ/(4a)`. -/
theorem vertex_value {a b c : ℝ} (ha : a ≠ 0) :
    a * (-b / (2 * a)) ^ 2 + b * (-b / (2 * a)) + c = -(b ^ 2 - 4 * a * c) / (4 * a) := by
  field_simp
  ring
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor
axis_of_symmetryLean 4Proved here from basic factsFormally verified
/-- **Axis of symmetry:** the parabola is symmetric about the vertical line `x = −b/(2a)`:
going a distance `t` to the right or to the left of it gives the same height. -/
theorem axis_of_symmetry {a b c : ℝ} (ha : a ≠ 0) (t : ℝ) :
    a * (-b / (2 * a) + t) ^ 2 + b * (-b / (2 * a) + t) + c =
      a * (-b / (2 * a) - t) ^ 2 + b * (-b / (2 * a) - t) + c := by
  field_simp
  ring
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor
rectangle_maxLean 4Proved here from basic factsFormally verified
/-- **Optimisation:** among rectangles with perimeter `P`, the square has the largest area.
A rectangle with one side `x` has other side `P/2 − x`, and
`P²/16 − x(P/2 − x) = (x − P/4)² ≥ 0`, with equality exactly when `x = P/4`. -/
theorem rectangle_max (P x : ℝ) :
    x * (P / 2 - x) ≤ P ^ 2 / 16 ∧ (x * (P / 2 - x) = P ^ 2 / 16 ↔ x = P / 4) := by
  have key : P ^ 2 / 16 - x * (P / 2 - x) = (x - P / 4) ^ 2 := by ring
  refine ⟨by nlinarith [sq_nonneg (x - P / 4)], ?_⟩
  constructor
  · intro h
    have h0 : (x - P / 4) ^ 2 = 0 := by linarith
    have := pow_eq_zero_iff (n := 2) (by norm_num) |>.mp h0
    linarith
  · rintro rfl
    ring
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Quadratics.leanTry it in the Lean web editor
ComputationC

Counting quadratics, and a formula that fails on a computer

How often does a quadratic have real roots?PythonExhaustive finite checkExact computationStatistical evidenceComputationally tested
"""How often does a quadratic have real roots? The discriminant decides.

Part 1 classifies every quadratic ax^2 + bx + c with whole-number
coefficients from -5 to 5 (a != 0) by the sign of b^2 - 4ac, and checks with
exact fractions that the quadratic formula really gives roots whenever the
discriminant is a perfect square. Part 2 picks coefficients at random from the
interval [-1, 1] and compares the proportion with real roots against the
known exact value (41 + 6 ln 2)/72.
"""

import math
import random
from fractions import Fraction

def discriminant(a, b, c):
    """b^2 - 4ac."""
    return b * b - 4 * a * c

def classify(a, b, c):
    """'two', 'one' or 'none': the number of distinct real roots (a != 0)."""
    if a == 0:
        raise ValueError("not a quadratic: a = 0")
    d = discriminant(a, b, c)
    return "two" if d > 0 else ("one" if d == 0 else "none")

def rational_roots(a, b, c):
    """Exact roots by the formula when b^2 - 4ac is a perfect square, else None."""
    d = discriminant(a, b, c)
    if d < 0 or math.isqrt(d) ** 2 != d:
        return None
    s = math.isqrt(d)
    return sorted({Fraction(-b + s, 2 * a), Fraction(-b - s, 2 * a)})

def census(limit=5):
    """Counts of each case over all integer a, b, c in [-limit, limit], a != 0,
    plus how many have rational roots and how many formula checks failed."""
    counts = {"two": 0, "one": 0, "none": 0, "rational": 0, "failures": 0}
    values = range(-limit, limit + 1)
    for a in values:
        if a == 0:
            continue
        for b in values:
            for c in values:
                counts[classify(a, b, c)] += 1
                roots = rational_roots(a, b, c)
                if roots is not None:
                    counts["rational"] += 1
                    counts["failures"] += any(
                        a * x * x + b * x + c != 0 for x in roots)
    return counts

def simulate(trials, seed=2024):
    """Proportion of random quadratics (a, b, c uniform in [-1, 1]) with
    b^2 - 4ac >= 0."""
    rng = random.Random(seed)
    hits = 0
    for _ in range(trials):
        a, b, c = (rng.uniform(-1, 1) for _ in range(3))
        hits += discriminant(a, b, c) >= 0
    return hits / trials

EXACT_PROBABILITY = (41 + 6 * math.log(2)) / 72

def main():
    counts = census()
    total = counts["two"] + counts["one"] + counts["none"]
    print(f"all {total} quadratics with a, b, c in -5..5 and a != 0:")
    print(f"  discriminant > 0 (two real roots): {counts['two']:4d}")
    print(f"  discriminant = 0 (one real root):  {counts['one']:4d}")
    print(f"  discriminant < 0 (no real roots):  {counts['none']:4d}")
    print(f"  perfect-square discriminant (rational roots): {counts['rational']}")
    print(f"  exact checks of the formula's roots that failed: "
          f"{counts['failures']}")
    print()
    trials = 20000
    p = simulate(trials)
    se = math.sqrt(p * (1 - p) / trials)
    print(f"random a, b, c in [-1, 1], {trials} trials:")
    print(f"  proportion with real roots  {p:.4f}  (standard error {se:.4f})")
    print(f"  exact value (41 + 6 ln 2)/72 = {EXACT_PROBABILITY:.4f}")
    print("  Half the time a and c have opposite signs, so -4ac > 0 and the")
    print("  roots are real for sure; that alone gives at least 1/2.")
    print()
    print("Epistemic status: part 1 is an exhaustive, exact check of 1,210")
    print("cases; it illustrates but does not replace the lesson's proof.")
    print("Part 2 is statistical evidence: the simulated proportion should lie")
    print("within about two standard errors of the exact value, which comes from")
    print("an integral we do not compute here.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The census is exact, but it only covers 12101210 quadratics. The simulation is statistical evidence: it estimates a probability and reports its standard error, so we can judge how far to trust the third decimal place.

The quadratic formula is a theorem, so it cannot be wrong. A computer, though, rounds every number to about 1616 significant digits, and that can make the formula give badly wrong answers:

Catastrophic cancellation in the quadratic formulaPythonNumerical approximationComputationally tested
"""When the quadratic formula goes wrong on a computer - and how Vieta saves it.

The roots of x^2 - Bx + 1 = 0 for large B are about B and 1/B. In
floating-point arithmetic the formula (B - sqrt(B^2 - 4))/2 for the small root
subtracts two nearly equal numbers, and most of its digits cancel. Vieta's
formula r1 * r2 = c/a gives the small root as 1/r1 with no cancellation. Exact
reference values come from 60-digit decimal arithmetic.
"""

from decimal import Decimal, localcontext
import math

def naive_small_root(a, b, c):
    """The textbook formula (-b - sqrt(b^2 - 4ac)) / (2a).

    For a > 0 and b < 0 this is the root of smaller size; when 4ac is tiny
    compared with b^2 it subtracts two nearly equal numbers.
    """
    return (-b - math.sqrt(b * b - 4 * a * c)) / (2 * a)

def stable_roots(a, b, c):
    """Both real roots without cancellation (needs b != 0 and D >= 0).

    First the root where -b and the square root have the same sign (no
    cancellation), then the other one from Vieta: r1 * r2 = c / a.
    """
    d = b * b - 4 * a * c
    if d < 0:
        raise ValueError("no real roots")
    big = (-b + math.copysign(math.sqrt(d), -b)) / (2 * a)
    return big, c / (a * big)

def reference_small_root(big_b, digits=60):
    """Small root of x^2 - B x + 1 to ``digits`` significant digits."""
    with localcontext() as ctx:
        ctx.prec = digits
        b = Decimal(big_b)
        return (b - (b * b - 4).sqrt()) / 2

def relative_error(approx, exact):
    """|approx - exact| / |exact|, with exact a Decimal (60-digit arithmetic)."""
    with localcontext() as ctx:
        ctx.prec = 60
        return abs((Decimal(approx) - exact) / exact)

def main():
    print("small root of x^2 - Bx + 1 = 0 (true value is about 1/B)")
    print(f"{'B':>6}  {'textbook formula':>18}  {'rel. error':>10}"
          f"  {'Vieta':>12}  {'rel. error':>10}")
    for k in range(2, 9):
        big_b = 10 ** k
        exact = reference_small_root(big_b)
        naive = naive_small_root(1.0, -float(big_b), 1.0)
        vieta = stable_roots(1.0, -float(big_b), 1.0)[1]
        print(f"  1e{k}  {naive:18.12e}  {float(relative_error(naive, exact)):10.1e}"
              f"  {vieta:12.6e}  {float(relative_error(vieta, exact)):10.1e}")
    print()
    print("For B = 1e8, sqrt(B^2 - 4) agrees with B in about 16 digits, so")
    print("B - sqrt(B^2 - 4) keeps almost none of them: the textbook answer")
    print("is wrong in the first digit. Vieta's 1/r1 keeps full precision.")
    print()
    print("Epistemic status: numerical evidence about IEEE double-precision")
    print("floating point, checked against 60-digit decimal values whose own")
    print("error is far below the digits shown. Algebraically both formulas are")
    print("exactly equal; the difference is entirely rounding error.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Both formulas are algebraically identical. The difference is numerical. Subtracting two nearly equal rounded numbers destroys their agreeing digits, while Vieta's rs=c/ars = c/a involves no subtraction at all. Numerical software computes roots the second way.

Explore

Explore: the parabola and its coefficients

Move aa, bb and cc. The marked point is the vertex (−b2a, c−b24a)\left(-\tfrac{b}{2a},\ c - \tfrac{b^2}{4a}\right). Watch how the number of xx-intercepts changes exactly when the vertex crosses the xx-axis, which is when Δ=b2−4ac\Delta = b^2 - 4ac changes sign. What does cc alone do? What happens to the vertex when you change only bb?

The parabola y = ax² + bx + c

Move the sliders and trace along the curves to read off values.

vertex
  • y = ax² + bx + c
  • y = ax² + bx + c: y = −4

When Δ<0\Delta < 0 the roots are complex. Here is a beautiful case. The two roots of x2+x+1x^2 + x + 1, −1±i32\tfrac{-1 \pm i\sqrt 3}{2}, are two of the three cube roots of 11, because x3−1=(x−1)(x2+x+1)x^3 - 1 = (x - 1)(x^2 + x + 1). In the complex plane they sit with 11 at the corners of an equilateral triangle:

The roots of x² + x + 1 are cube roots of 1

The n-th roots of a number c sit evenly spaced on one circle: the corners of a regular polygon.

Try
120°w₀w₁w₂c

Drag the points, or focus one with Tab and use the arrow keys (hold Shift for small steps).

c =+i

Solutions of wⁿ = c for n = 3:

  • w₀ = 1
  • w₁ = −0.5 + 0.866i
  • w₂ = −0.5 − 0.866i

All roots lie on the circle of radius |c|^(1/n) ≈ 1.

Neighbouring roots are 120° apart: 360° ÷ 3.

w₀ is the principal root, at the angle (arg c)/n; the others follow by equal turns.

Because c = 1, these are the roots of unity of order 3.

The roots add up to 0, so the regular polygon is balanced around the origin.

Exercises

Exercises

1. Quadratic equations and functions

Warm-upHuman

Compute the discriminant of 3x2−5x+23x^2 - 5x + 2.

2. Quadratic equations and functions

Warm-upHuman

Solve x2−x−12=0x^2 - x - 12 = 0. Enter the solutions as a set, for example {1, 2}.

Write elements separated by commas. Order and repeats don’t matter — just like in a set!

3. Quadratic equations and functions

CoreHuman

How many different real roots does 4x2−12x+94x^2 - 12x + 9 have?

4. Quadratic equations and functions

CoreHuman

Kofi solves x2=3xx^2 = 3x by dividing both sides by xx and gets x=3x = 3. What is wrong?

Choose one

5. Quadratic equations and functions

CoreHuman

A goat pen is built against a straight wall using 6060 m of fencing for the other three sides. What is the largest possible area of the pen, in square metres?

6. Quadratic equations and functions

CoreHuman

Without solving, find the sum and the product of the roots of 2x2−7x+3=02x^2 - 7x + 3 = 0.

Choose one

7. Quadratic equations and functions

StretchHuman

Find the positive number kk for which x2+kx+16=0x^2 + kx + 16 = 0 has exactly one real root.

8. Quadratic equations and functions

StretchFormal

In Mathlib, Real.sqrt of a negative number is defined to be 0. The theorem Lumenary.Quadratics.quadratic_formula has the hypothesis hΔ : 0 ≤ b ^ 2 - 4 * a * c. What would happen if we deleted it?

Choose one

9. Quadratic equations and functions

StretchComputational

Write real_roots(a, b, c) that returns the sorted list of the different real roots of ax2+bx+cax^2 + bx + c (with a≠0a \ne 0): two roots if Δ>0\Delta > 0, one if Δ=0\Delta = 0, and the empty list if Δ<0\Delta < 0. Use math.sqrt.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Common misconceptionsH

Common misconceptions

Misconception

Dividing both sides by xx. From x2=5xx^2 = 5x, dividing by xx gives x=5x = 5 and loses the root x=0x = 0. Dividing by xx is only allowed when x≠0x \ne 0. Instead, factorise: x2−5x=x(x−5)=0x^2 - 5x = x(x - 5) = 0, so x=0x = 0 or x=5x = 5.

Misconception

Misusing the zero-product property. From (x−1)(x−2)=6(x - 1)(x - 2) = 6 it does not follow that x−1=6x - 1 = 6 or x−2=6x - 2 = 6. The property only works with 00 on the right: a product can be 66 in infinitely many ways. Expand and rearrange first: x2−3x−4=0x^2 - 3x - 4 = 0, so (x−4)(x+1)=0(x - 4)(x + 1) = 0, and x=4x = 4 or x=−1x = -1.

Misconception

"Δ<0\Delta < 0 means there are no solutions at all." There are no real solutions. In the complex numbers there are always two (equal when Δ=0\Delta = 0): x=−b±i−Δ2ax = \tfrac{-b \pm i\sqrt{-\Delta}}{2a}. Whether an equation "has solutions" depends on which numbers you allow; see complex numbers.

Misconception

"x2=9x^2 = 9 means x=3x = 3." It means x=3x = 3 or x=−3x = -3. The symbol 9\sqrt 9 means only the non-negative root 33, which is why the formula needs ±\pm.

Misconception

"The vertex is at x=b2ax = \tfrac{b}{2a}." It is at x=−b2ax = -\tfrac{b}{2a}, the average of the two roots by Vieta. Check with y=x2−4xy = x^2 - 4x: its roots are 00 and 44, so the vertex is at x=2=−−42x = 2 = -\tfrac{-4}{2}.

ViewpointsH

Many ways of seeing

Geometry— Every parabola has the same shape

A parabola is a conic section: the set of points at equal distance from a point (the focus) and a line (the directrix). The parabola y=ax2y = ax^2 with a>0a > 0 has focus (0,14a)(0, \tfrac{1}{4a}) and directrix y=−14ay = -\tfrac{1}{4a}. Rays parallel to the axis reflect off it through the focus, which is why satellite dishes and solar cookers are parabolic. Surprisingly, all parabolas are similar. Scaling the plane by a factor kk sends y=x2y = x^2 to y=1kx2y = \tfrac{1}{k}x^2, and any parabola can be moved onto some y=ax2y = ax^2. A "steep" parabola is just a zoomed-out view of a "flat" one (see conic sections).

Number theory— Quadratics in clock arithmetic

Completing the square only needs division by 22, so the quadratic formula also works modulo an odd prime pp, provided the discriminant has a square root there. For example, x2+1=0x^2 + 1 = 0 has no real roots, but modulo 55 it has the roots 22 and 33 (4+1=54 + 1 = 5 and 9+1=109 + 1 = 10). Modulo 77 it has none, since the squares modulo 77 are only 0,1,2,40, 1, 2, 4. Which numbers are squares modulo pp is a deep question. A classical theorem, going back to Fermat and Euler, says that −1-1 is a square modulo an odd prime pp exactly when pp leaves remainder 11 on division by 44 (see number theory).

Analysis— The vertex is where the slope is zero

Near its vertex, a parabola is momentarily flat. Calculus makes this precise: the slope of y=ax2+bx+cy = ax^2 + bx + c at xx is 2ax+b2ax + b, which is zero exactly at x=−b2ax = -\tfrac{b}{2a}. For quadratics, completing the square finds maxima and minima without calculus. For other functions the idea "look where the slope is zero" is the starting point of optimisation (see introductory calculus). The garden problem also hides an inequality between means: for positive uu and vv, uv≤(u+v2)2uv \le \left(\tfrac{u + v}{2}\right)^2, because the difference is (u−v2)2≥0\left(\tfrac{u - v}{2}\right)^2 \ge 0.

Physics— Why thrown things trace parabolas

Galileo Galilei found experimentally, and published in Two New Sciences (1638), that a falling body covers distances proportional to the square of the time. With constant downward acceleration gg, the height of a projectile is h(t)=h0+v0t−12gt2h(t) = h_0 + v_0 t - \tfrac12 g t^2, a quadratic in tt. A ball thrown at an angle travels horizontally at constant speed while its height follows this quadratic, so its path is a parabola too. This is a model: it ignores air resistance and assumes gg is constant, which is excellent for a football and poor for a feather or a rocket (see modelling with functions).

History & global context

History and global context

  • Mesopotamia. Old Babylonian clay tablets from around 1800 BCE, such as the tablet known as BM 13901, pose problems like "I added the area and the side of my square: 34\tfrac34", that is, x2+x=34x^2 + x = \tfrac34. They solve them by a cut-and-paste procedure equivalent to completing the square.
  • Egypt. A Middle Kingdom papyrus now in Berlin contains a problem equivalent to finding two squares whose areas add up to 100100 when one side is 34\tfrac34 of the other.
  • India. Brahmagupta's Brāhmasphuṭasiddhānta (628 CE) gave an explicit rule for solving quadratic equations. Śrīdhara (whose dates are uncertain, perhaps the 8th or 9th century) gave the method that multiplies by 4a4a and adds b2b^2, our identity (∗)(\ast). It is known from Bhāskara II's quotation of it in the 12th century.
  • Baghdad. Al-Khwārizmī (around 820 CE) classified quadratic equations into six types, since he used only positive numbers, and justified each solution by a geometric picture like the one above.
  • Europe. Abraham bar Ḥiyya's treatise, translated into Latin in 1145, helped bring these methods to Europe. In his Ars Magna (1545), Gerolamo Cardano met 5±−155 \pm \sqrt{-15} as "solutions" of dividing 1010 into two parts with product 4040, an early appearance of complex numbers. René Descartes (1637) called such numbers "imaginary".
Further reading

Further reading

  • I. M. Gelfand and A. Shen, Algebra (1993) — includes a careful treatment of quadratic equations and their graphs.
  • Jens Høyrup, Lengths, Widths, Surfaces: A Portrait of Old Babylonian Algebra and Its Kin (2002) — how the Babylonian "cut-and-paste" methods worked.
  • Eleanor Robson, Mathematics in Ancient Iraq: A Social History (2008).
  • Paul J. Nahin, An Imaginary Tale: The Story of −1\sqrt{-1} (1998) — how square roots of negative numbers became respectable.