Skip to content
The Lumenary
Grades 6–8Ages 12–14 70 min

The Pythagorean theorem

Why a2+b2=c2a^2 + b^2 = c^2 in every right triangle, how to prove it by moving four triangles around, and how it measures straight-line distance in the plane.

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

Your guides: Chloe, Margaret, Gideon

MotivationH

Three, four, five

A builder in Accra wants the corner of a new wall to be exactly square. She has no protractor, only a tape measure. So she marks a point 3 metres along one wall and a point 4 metres along the other, and measures the distance between the marks. If it is exactly 5 metres, the corner is a right angle. If it is more, the corner is too wide; if less, too narrow.

Why should the numbers 3, 4 and 5 know anything about right angles? And why does the same trick work with 5, 12 and 13, or with 6, 8 and 10 — but not with 4, 5 and 6? The answer is one of the oldest and most famous theorems in mathematics. It was known, in some form, to scribes in ancient Mesopotamia, to the authors of the Indian Śulbasūtras, and to Chinese astronomers, long before it became attached to the name of Pythagoras. It is also the reason a computer can measure the distance between two points on a map.

IntuitionH

Squares on the sides

Draw a right triangle with sides 3, 4 and 5 on squared paper, and build a square outward on each side. The square on the side 3 contains 99 unit squares, the square on the side 4 contains 1616, and the square on the side 5 contains 2525. And 9+16=259 + 16 = 25.

So the theorem is really about areas: the two smaller squares together have exactly the same area as the big one. You can try other right triangles in the explorer further down — for legs 1 and 1, the tilted square has area 22 — and the areas always balance.

Now try a triangle without a right angle, such as an equilateral triangle with all sides 1. The squares on its sides have areas 11, 11 and 11, and 1+1≠11 + 1 \neq 1. The right angle is essential.

DefinitionsH

Definitions

Definition— right triangle

A right triangle (or right-angled triangle) is a triangle with one angle of 90∘90^\circ. The two sides that form the right angle are the legs; the side opposite the right angle is the hypotenuse. The hypotenuse is always the longest side.

Definition— square root

For a number x≥0x \ge 0, the square root x\sqrt{x} is the number r≥0r \ge 0 with r2=xr^2 = x. For example 25=5\sqrt{25} = 5 and 2.25=1.5\sqrt{2.25} = 1.5. Some square roots, such as 2=1.41421…\sqrt{2} = 1.41421\dots, are not whole numbers or even fractions; we can still approximate them as closely as we like.

We will use two facts from earlier lessons: the angles of a triangle add up to 180∘180^\circ, and the area of a right triangle with legs aa and bb is 12ab\tfrac12 ab (half of an a×ba \times b rectangle).

ProofH

The theorem and two proofs

Theorem— Pythagorean theorem

In a right triangle with legs aa, bb and hypotenuse cc:

a2+b2=c2.a^2 + b^2 = c^2.
c²b²a²abba
The rearrangement proof. Both big squares have side a + b. On the left, four copies of the triangle leave a tilted square of area c². On the right, the same four triangles leave two squares of areas a² and b².

Proof

First proof: rearrangement. Take four copies of the right triangle, with legs aa, bb, hypotenuse cc, and acute angles α\alpha and β\beta. Since the angles of a triangle add up to 180∘180^\circ and one of them is 90∘90^\circ, we have α+β=90∘\alpha + \beta = 90^\circ.

Left picture. Place the four triangles in the corners of a square of side a+ba + b, as shown, so that along each side of the big square a leg aa is followed by a leg bb. The shape left in the middle has four sides, each a hypotenuse, so each of length cc. At each of its corners, the angle of the middle shape sits on a straight side of the big square between an angle α\alpha of one triangle and an angle β\beta of the next, so it measures 180∘−(α+β)=180∘−90∘=90∘180^\circ - (\alpha + \beta) = 180^\circ - 90^\circ = 90^\circ. A shape with four equal sides and four right angles is a square: its area is c2c^2.

Right picture. Rearrange the same four triangles into two a×ba \times b rectangles, placed in opposite corners of a second square of side a+ba + b. What is left is a square of side bb and a square of side aa: total area a2+b2a^2 + b^2.

Both big squares have the same area, (a+b)2(a + b)^2, and both contain four triangles of the same total area. So the uncovered areas are equal:

c2=a2+b2.c^2 = a^2 + b^2.

∎

The left picture also gives an algebraic proof. Its total area is

(a+b)2=c2+4⋅12ab,that is,a2+2ab+b2=c2+2ab,(a + b)^2 = c^2 + 4 \cdot \tfrac{1}{2} a b, \quad\text{that is,}\quad a^2 + 2ab + b^2 = c^2 + 2ab,

and subtracting 2ab2ab from both sides leaves a2+b2=c2a^2 + b^2 = c^2.

(b − a)²
The hypotenuse diagram: four copies of the triangle inside the square on the hypotenuse, with a small square of side b − a left in the middle.

Proof

Second proof: the square in the middle. Suppose a≤ba \le b. Arrange the four triangles inside the square on the hypotenuse, each with its hypotenuse along one side, turning a quarter turn from one to the next. Along each side of the middle shape, a long leg bb overlaps a short leg aa, so the middle is a square of side b−ab - a (if a=ba = b it disappears). Adding up areas:

c2=(b−a)2+4⋅12ab=b2−2ab+a2+2ab=a2+b2.c^2 = (b - a)^2 + 4 \cdot \tfrac12 ab = b^2 - 2ab + a^2 + 2ab = a^2 + b^2.

∎

Worked examplesH

Worked examples

Example— Finding the hypotenuse

A right triangle has legs 5 cm and 12 cm. Then c2=52+122=25+144=169c^2 = 5^2 + 12^2 = 25 + 144 = 169, so c=169=13c = \sqrt{169} = 13 cm.

Example— Finding a leg: the ladder

A ladder 2.5 m long leans against a wall with its foot 0.7 m from the wall. How high does it reach? The ladder is the hypotenuse: h2+0.72=2.52h^2 + 0.7^2 = 2.5^2, so h2=6.25−0.49=5.76h^2 = 6.25 - 0.49 = 5.76 and h=5.76=2.4h = \sqrt{5.76} = 2.4 m.

Example— A length that is not a whole number

A square tile has side 1. Its diagonal splits it into two right triangles with legs 1 and 1, so the diagonal dd has d2=1+1=2d^2 = 1 + 1 = 2 and d=2≈1.414d = \sqrt{2} \approx 1.414. No whole number squares to 2 (12=11^2 = 1, 22=42^2 = 4), and in fact 2\sqrt{2} is not a fraction either — a discovery explored in real numbers.

Example— Is it a right triangle?

Sides 6, 8, 10: 62+82=36+64=100=1026^2 + 8^2 = 36 + 64 = 100 = 10^2. By the converse (below), the triangle has a right angle, opposite the side 10. Sides 5, 6, 8: 52+62=615^2 + 6^2 = 61 but 82=648^2 = 64. No right angle — in fact the angle opposite 8 is slightly more than 90∘90^\circ.

Example— Screen sizes

A screen is advertised by its diagonal. A screen 48 cm wide and 27 cm high has a diagonal of 482+272=2304+729=3033≈55.1\sqrt{48^2 + 27^2} = \sqrt{2304 + 729} = \sqrt{3033} \approx 55.1 cm, about 21.7 inches.

ProofH

The converse: a test for right angles

The builder's 3-4-5 trick uses the theorem backwards: from the side lengths she concludes there is a right angle.

Theorem— Converse of the Pythagorean theorem

If the sides of a triangle satisfy a2+b2=c2a^2 + b^2 = c^2, then the triangle has a right angle, opposite the side cc.

Proof

Let the triangle be TT, with sides aa, bb, cc and a2+b2=c2a^2 + b^2 = c^2. Build a second triangle T′T' with a right angle between two legs of lengths aa and bb. By the Pythagorean theorem, its hypotenuse c′c' satisfies c′2=a2+b2=c2c'^2 = a^2 + b^2 = c^2. Since cc and c′c' are both positive, c′=cc' = c. Now TT and T′T' have the same three side lengths, so they are congruent: one can be moved exactly onto the other (a triangle is fixed by its three sides — the SSS rule). Congruent triangles have equal angles, so the angle of TT opposite cc equals the angle of T′T' opposite c′c', which is 90∘90^\circ.

∎

The same comparison tells more. If a2+b2>c2a^2 + b^2 > c^2, the angle opposite cc is acute (less than 90∘90^\circ); if a2+b2<c2a^2 + b^2 \lt c^2, it is obtuse (more than 90∘90^\circ). The computation section checks this on hundreds of triangles; a proof comes later with the law of cosines in trigonometry.

ProofH

Distance in the coordinate plane

In the coordinate plane we could measure distances along horizontal and vertical lines. Now we can measure them in any direction.

Theorem— Distance formula

The distance between P=(x1,y1)P = (x_1, y_1) and Q=(x2,y2)Q = (x_2, y_2) is

PQ=(x2−x1)2+(y2−y1)2.PQ = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}.

Proof

If PP and QQ lie on a horizontal or vertical line, this is the distance ∣x2−x1∣|x_2 - x_1| or ∣y2−y1∣|y_2 - y_1| from before (note that u2=∣u∣\sqrt{u^2} = |u|). Otherwise let R=(x2,y1)R = (x_2, y_1). The segment PRPR is horizontal with length ∣x2−x1∣|x_2 - x_1|, the segment RQRQ is vertical with length ∣y2−y1∣|y_2 - y_1|, and they meet at a right angle at RR. So PQPQ is the hypotenuse of a right triangle, and PQ2=∣x2−x1∣2+∣y2−y1∣2=(x2−x1)2+(y2−y1)2PQ^2 = |x_2 - x_1|^2 + |y_2 - y_1|^2 = (x_2 - x_1)^2 + (y_2 - y_1)^2.

∎

Example— Two distances between the same points

From (1,2)(1, 2) to (4,6)(4, 6): legs 33 and 44, distance 9+16=5\sqrt{9 + 16} = 5. From (−3,2)(-3, 2) to (4,−1)(4, -1): legs 77 and 33, distance 49+9=58≈7.62\sqrt{49 + 9} = \sqrt{58} \approx 7.62 — shorter than the grid distance 7+3=107 + 3 = 10, as a bird is faster than a taxi.

ExplanationH

Pythagorean triples

A Pythagorean triple is a set of three positive whole numbers (a,b,c)(a, b, c) with a2+b2=c2a^2 + b^2 = c^2, such as (3,4,5)(3, 4, 5), (5,12,13)(5, 12, 13) and (8,15,17)(8, 15, 17). Multiplying a triple by any whole number kk gives another, because (ka)2+(kb)2=k2(a2+b2)=k2c2=(kc)2(ka)^2 + (kb)^2 = k^2(a^2 + b^2) = k^2 c^2 = (kc)^2. So (6,8,10)(6, 8, 10), (9,12,15)(9, 12, 15), (12,16,20)(12, 16, 20), … are triples too, and there are infinitely many triples.

A triple whose three numbers have no common factor, like (3,4,5)(3, 4, 5), is primitive. Here is a recipe that produces them, recorded in Euclid's Elements (Book X).

Theorem— Euclid's formula

For any whole numbers m>n>0m > n > 0, the numbers a=m2−n2a = m^2 - n^2, b=2mnb = 2mn, c=m2+n2c = m^2 + n^2 form a Pythagorean triple.

Proof

Expand both sides:

(m2−n2)2+(2mn)2=m4−2m2n2+n4+4m2n2=m4+2m2n2+n4=(m2+n2)2.(m^2 - n^2)^2 + (2mn)^2 = m^4 - 2m^2n^2 + n^4 + 4m^2n^2 = m^4 + 2m^2n^2 + n^4 = (m^2 + n^2)^2.

∎

m=2,n=1m = 2, n = 1 gives (3,4,5)(3, 4, 5); m=3,n=2m = 3, n = 2 gives (5,12,13)(5, 12, 13); m=4,n=1m = 4, n = 1 gives (15,8,17)(15, 8, 17). In fact, when mm and nn have no common factor and are not both odd, the formula gives a primitive triple, and every primitive triple arises this way (with the two legs possibly swapped). That second statement is a theorem of number theory whose proof we postpone to elementary number theory; the computation below checks it for all triples up to 100.

What about cubes? Are there positive whole numbers with a3+b3=c3a^3 + b^3 = c^3, or an+bn=cna^n + b^n = c^n for some n≥3n \ge 3? Pierre de Fermat claimed around 1637 that there are none. His claim, Fermat's Last Theorem, was proved only in 1995, by Andrew Wiles (with a final step completed together with Richard Taylor), using some of the deepest mathematics of the twentieth century.

Formal mathematicsF

Pythagoras in Lean

First, the algebraic step of each dissection proof. What Lean checks here is the area bookkeeping: if the big square is made of the pieces, then a2+b2=c2a^2 + b^2 = c^2. That the pieces really fit together — the geometric half of the proof — is argued in words above, not formalised.

rearrangement_algebraLean 4Proved here from basic factsFormally verified
/-- **The first rearrangement proof, algebraic step.** If a square of side `a + b` is made up
of a tilted square of side `c` and four right triangles with legs `a`, `b` (area `ab/2` each),
then `a² + b² = c²`.
`(a + b)² = a² + 2ab + b²`, and the four triangles account for `4 · ab/2 = 2ab`. -/
theorem rearrangement_algebra (a b c : Rat) (h : (a + b) ^ 2 = c ^ 2 + 4 * (a * b / 2)) :
    a ^ 2 + b ^ 2 = c ^ 2 := by
  have expand : (a + b) ^ 2 = a ^ 2 + b ^ 2 + 2 * (a * b) := by grind
  have four : 4 * (a * b / 2) = 2 * (a * b) := by grind
  calc a ^ 2 + b ^ 2 = (a + b) ^ 2 - 2 * (a * b) := by rw [expand]; grind
    _ = c ^ 2 + 4 * (a * b / 2) - 2 * (a * b) := by rw [h]
    _ = c ^ 2 := by rw [four]; grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
rearrangement_square_in_middleLean 4Proved here from basic factsFormally verified
/-- **The second dissection proof, algebraic step** (the “hypotenuse diagram”). If a square of
side `c` is made up of four right triangles with legs `a`, `b` and a small square of side
`b - a` in the middle, then `a² + b² = c²`, because `(b - a)² + 2ab = a² + b²`. -/
theorem rearrangement_square_in_middle (a b c : Rat)
    (h : c ^ 2 = (b - a) ^ 2 + 4 * (a * b / 2)) : a ^ 2 + b ^ 2 = c ^ 2 := by
  rw [h]
  grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor

Next, the theorem and its converse in coordinates. To stay with exact fractions we never take square roots: sqDist is the square of the distance. And “the angle at CC is a right angle” is expressed without measuring angles: the step from CC to BB is the step from CC to AA turned through a quarter turn, (p,q)↦(−q,p)(p, q) \mapsto (-q, p), and then stretched by some factor tt.

PointLean 4Formally verified
/-- A point of the coordinate plane with rational coordinates. -/
structure Point where
  x : Rat
  y : Rat
deriving DecidableEq
Axioms used: No axiomsformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
sqDistLean 4Formally verified
/-- The **square** of the distance from `P` to `Q`: `(x₂ - x₁)² + (y₂ - y₁)²`. Comparing
squares of lengths lets us avoid square roots entirely. -/
def sqDist (P Q : Point) : Rat := (Q.x - P.x) ^ 2 + (Q.y - P.y) ^ 2
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
distance_exampleLean 4Proved here from basic factsFormally verified
/-- The distance from `(1, 2)` to `(4, 6)` is `5`: the legs are `3` and `4`, and
`3² + 4² = 25 = 5²`. -/
theorem distance_example : sqDist ⟨1, 2⟩ ⟨4, 6⟩ = 5 ^ 2 := by decide +kernel
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
IsRightAngleAtLean 4Formally verified
/-- The angle `ACB` is a right angle: the step from `C` to `B` is the step from `C` to `A`
turned through a quarter turn (`(p, q) ↦ (-q, p)`) and scaled by some factor `t`. -/
def IsRightAngleAt (A B C : Point) : Prop :=
  ∃ t : Rat, B.x - C.x = -t * (A.y - C.y) ∧ B.y - C.y = t * (A.x - C.x)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
pythagoras_coordinatesLean 4Proved here from basic factsFormally verified
/-- **The Pythagorean theorem in coordinates.** If the angle at `C` is a right angle, then
`AB² = CA² + CB²`.
Write `A - C = (p, q)`, so `B - C = (-tq, tp)`. Then `CA² = p² + q²`, `CB² = t²(p² + q²)` and
`AB² = (-tq - p)² + (tp - q)² = (1 + t²)(p² + q²)`: the cross terms `±2tpq` cancel. -/
theorem pythagoras_coordinates (A B C : Point) (h : IsRightAngleAt A B C) :
    sqDist A B = sqDist C A + sqDist C B := by
  obtain ⟨t, h1, h2⟩ := h
  unfold sqDist
  have e1 : B.x - A.x = (B.x - C.x) - (A.x - C.x) := by grind
  have e2 : B.y - A.y = (B.y - C.y) - (A.y - C.y) := by grind
  rw [e1, e2, h1, h2]
  grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
right_triangle_exampleLean 4Proved here from basic factsFormally verified
/-- A tilted right triangle: `C = (1, 1)`, `A = (4, 2)`, `B = (0, 4)`. The step `C → A` is
`(3, 1)` and the step `C → B` is `(-1, 3)`, its quarter turn. So `AB² = 10 + 10 = 20`. -/
theorem right_triangle_example :
    IsRightAngleAt ⟨4, 2⟩ ⟨0, 4⟩ ⟨1, 1⟩ ∧ sqDist ⟨4, 2⟩ ⟨0, 4⟩ = 20 := by
  refine ⟨⟨1, by decide +kernel, by decide +kernel⟩, by decide +kernel⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor

For the converse, the key step is that pr+qs=0p r + q s = 0 forces (r,s)(r, s) to be a multiple of (−q,p)(-q, p):

quarter_turn_of_dot_zeroLean 4Proved here from basic factsFormally verified
/-- If `(r, s)` is perpendicular to a non-zero `(p, q)` in the sense `p·r + q·s = 0`, then
`(r, s)` is a multiple of the quarter turn `(-q, p)`. The factor is
`t = (p·s - q·r) / (p² + q²)`. -/
theorem quarter_turn_of_dot_zero (p q r s : Rat) (hpq : p ≠ 0 ∨ q ≠ 0)
    (h : p * r + q * s = 0) : ∃ t : Rat, r = -t * q ∧ s = t * p := by
  have hne : p * p + q * q ≠ 0 := Rat.ne_of_gt (sum_sq_pos p q hpq)
  have ht : (p * s - q * r) / (p * p + q * q) * (p * p + q * q) = p * s - q * r :=
    Rat.div_mul_cancel hne
  generalize (p * s - q * r) / (p * p + q * q) = t at ht
  refine ⟨t, ?_, ?_⟩
  · have hr : r * (p * p + q * q) = (-t * q) * (p * p + q * q) := by grind
    calc r = r * (p * p + q * q) / (p * p + q * q) := (Rat.mul_div_cancel hne).symm
      _ = (-t * q) * (p * p + q * q) / (p * p + q * q) := by rw [hr]
      _ = -t * q := Rat.mul_div_cancel hne
  · have hs : s * (p * p + q * q) = (t * p) * (p * p + q * q) := by grind
    calc s = s * (p * p + q * q) / (p * p + q * q) := (Rat.mul_div_cancel hne).symm
      _ = (t * p) * (p * p + q * q) / (p * p + q * q) := by rw [hs]
      _ = t * p := Rat.mul_div_cancel hne
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
converse_coordinatesLean 4Proved here from basic factsFormally verified
/-- **The converse in coordinates.** If `A ≠ C` and `AB² = CA² + CB²`, then the angle at `C`
is a right angle.
Expanding, `AB² = CA² + CB² - 2(p·r + q·s)` where `(p, q) = A - C` and `(r, s) = B - C`; so the
hypothesis says exactly `p·r + q·s = 0`, and `quarter_turn_of_dot_zero` finishes. -/
theorem converse_coordinates (A B C : Point) (hAC : A ≠ C)
    (h : sqDist A B = sqDist C A + sqDist C B) : IsRightAngleAt A B C := by
  have hpq : A.x - C.x ≠ 0 ∨ A.y - C.y ≠ 0 := by
    by_cases hx : A.x - C.x = 0
    · right
      intro hy
      apply hAC
      cases A
      cases C
      simp only at hx hy
      grind
    · left
      exact hx
  have hdot : (A.x - C.x) * (B.x - C.x) + (A.y - C.y) * (B.y - C.y) = 0 := by
    unfold sqDist at h
    grind
  exact quarter_turn_of_dot_zero _ _ _ _ hpq hdot
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor

Finally, whole-number facts: triples, the non-example 5,6,85, 6, 8, scaling, Euclid's formula (for all integers m,nm, n), infinitely many triples, and two warnings.

triple_examplesLean 4Proved here from basic factsFormally verified
/-- Three Pythagorean triples: `3² + 4² = 5²`, `5² + 12² = 13²`, `8² + 15² = 17²`. -/
theorem triple_examples : 3 ^ 2 + 4 ^ 2 = 5 ^ 2 ∧ 5 ^ 2 + 12 ^ 2 = 13 ^ 2 ∧
    8 ^ 2 + 15 ^ 2 = 17 ^ 2 := by decide
Axioms used: No axiomsformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
not_right_exampleLean 4Proved here from basic factsFormally verified
/-- A triangle with sides `5, 6, 8` has **no** right angle: `5² + 6² = 61`, but `8² = 64`.
(By the converse, a right angle would force `61 = 64`; and the right angle could only be
opposite the longest side.) -/
theorem not_right_example : 5 ^ 2 + 6 ^ 2 ≠ 8 ^ 2 := by decide
Axioms used: No axiomsformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
triple_scaleLean 4Proved here from basic factsFormally verified
/-- Scaling a triple gives a triple: if `a² + b² = c²` then `(ka)² + (kb)² = (kc)²`. -/
theorem triple_scale (a b c k : Nat) (h : a ^ 2 + b ^ 2 = c ^ 2) :
    (k * a) ^ 2 + (k * b) ^ 2 = (k * c) ^ 2 := by
  calc (k * a) ^ 2 + (k * b) ^ 2 = k ^ 2 * (a ^ 2 + b ^ 2) := by grind
    _ = k ^ 2 * c ^ 2 := by rw [h]
    _ = (k * c) ^ 2 := by grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
euclid_formulaLean 4Proved here from basic factsFormally verified
/-- **Euclid's formula.** For all integers `m, n`, the numbers `m² - n²`, `2mn`, `m² + n²`
satisfy `(m² - n²)² + (2mn)² = (m² + n²)²`. With `m = 2, n = 1` this is `3, 4, 5`. -/
theorem euclid_formula (m n : Int) :
    (m ^ 2 - n ^ 2) ^ 2 + (2 * m * n) ^ 2 = (m ^ 2 + n ^ 2) ^ 2 := by
  grind
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
infinitely_many_triplesLean 4Proved here from basic factsFormally verified
/-- **There are infinitely many Pythagorean triples**: beyond any number `N` there is a triple
with all sides positive and the first side bigger than `N`. Take `3k, 4k, 5k` with
`k = N + 1`. -/
theorem infinitely_many_triples (N : Nat) :
    ∃ a b c : Nat, N < a ∧ 0 < b ∧ a ^ 2 + b ^ 2 = c ^ 2 := by
  refine ⟨3 * (N + 1), 4 * (N + 1), 5 * (N + 1), by omega, by omega, ?_⟩
  have h := triple_scale 3 4 5 (N + 1) (by decide)
  rw [Nat.mul_comm 3, Nat.mul_comm 4, Nat.mul_comm 5]
  exact h
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
sum_sq_lt_sq_sumLean 4Proved here from basic factsFormally verified
/-- **`√(a² + b²)` is not `a + b`.** For positive `a, b`, `a² + b² < (a + b)²`: the square of
the sum has the extra `2ab`. So the hypotenuse is always shorter than the two legs together. -/
theorem sum_sq_lt_sq_sum (a b : Nat) (ha : 0 < a) (hb : 0 < b) :
    a ^ 2 + b ^ 2 < (a + b) ^ 2 := by
  have hab : 0 < a * b := Nat.mul_pos ha hb
  have expand : (a + b) ^ 2 = a ^ 2 + b ^ 2 + 2 * (a * b) := by grind
  omega
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor
no_whole_sqrt_twoLean 4Proved here from basic factsFormally verified
/-- The diagonal of a unit square has length `√2`, and `√2` is not a whole number: no whole
number `n` has `n² = 2` (`1² = 1` is too small and `2² = 4` already too big). In fact `√2` is not
even a fraction — see the lesson on real numbers. -/
theorem no_whole_sqrt_two : ¬ ∃ n : Nat, n ^ 2 = 2 := by
  intro ⟨n, h⟩
  match n, h with
  | 0, h => exact absurd h (by decide)
  | 1, h => exact absurd h (by decide)
  | k + 2, h =>
    have : 4 ≤ (k + 2) ^ 2 := by
      have := Nat.mul_le_mul (Nat.le_add_left 2 k) (Nat.le_add_left 2 k)
      rw [Nat.pow_two]
      exact this
    omega
Axioms used: propext, Quot.soundformal/Lumenary/PythagoreanTheorem.leanTry it in the Lean web editor

All of these are proved here, using core Lean only. Mathlib proves the theorem and its converse for real inner product spaces (any dimension), and classifies all integer triples — the statement we postponed above.

ComputationC

Triples and triangles by computer

Pythagorean triples up to 100PythonExact computationExhaustive finite checkComputationally tested
"""Pythagorean triples up to 100: search, count and Euclid's formula.

The experiment finds every triple of whole numbers a < b < c <= 100 with
a^2 + b^2 = c^2 by trying all pairs, picks out the primitive ones (no common
factor), and compares them with the triples produced by Euclid's formula
(m^2 - n^2, 2mn, m^2 + n^2) for m > n > 0 with no common factor and not both
odd. It also checks that every triple is a multiple of a primitive one and
tests a curious pattern: the product abc is always a multiple of 60. All of
this is exact and exhaustive for c <= 100 only.
"""

import math

def triples(limit):
    """All (a, b, c) with a < b < c <= limit and a^2 + b^2 = c^2."""
    found = []
    for c in range(1, limit + 1):
        for b in range(1, c):
            a_sq = c * c - b * b
            a = math.isqrt(a_sq)
            if a < b and a > 0 and a * a == a_sq:
                found.append((a, b, c))
    return sorted(found, key=lambda t: (t[2], t[0]))

def is_primitive(t):
    """No whole number greater than 1 divides all three sides."""
    return math.gcd(math.gcd(t[0], t[1]), t[2]) == 1

def euclid(m, n):
    """Euclid's triple for m > n > 0, with the two legs in increasing order."""
    a, b, c = m * m - n * n, 2 * m * n, m * m + n * n
    return (min(a, b), max(a, b), c)

def euclid_primitives(limit):
    """Triples from Euclid's formula with m > n > 0 coprime, not both odd."""
    out = set()
    m = 2
    while m * m + 1 <= limit:
        for n in range(1, m):
            if math.gcd(m, n) == 1 and (m - n) % 2 == 1:
                t = euclid(m, n)
                if t[2] <= limit:
                    out.add(t)
        m += 1
    return sorted(out, key=lambda t: (t[2], t[0]))

def primitive_root(t):
    """Divide a triple by the common factor of its sides."""
    g = math.gcd(math.gcd(t[0], t[1]), t[2])
    return (t[0] // g, t[1] // g, t[2] // g)

def hypotenuse_counts(found):
    """How many of the triples in ``found`` have each hypotenuse c."""
    counts = {}
    for _, _, c in found:
        counts[c] = counts.get(c, 0) + 1
    return counts

def main():
    all_t = triples(100)
    prim = [t for t in all_t if is_primitive(t)]
    print(f"Triples with c <= 100: {len(all_t)}; primitive: {len(prim)}")
    print("Primitive triples:")
    for i in range(0, len(prim), 4):
        print("  " + "  ".join(f"{t}" for t in prim[i:i + 4]))
    eu = euclid_primitives(100)
    print(f"Euclid's formula (m > n coprime, not both odd): {len(eu)} triples;"
          f" same list: {eu == prim}")
    roots_ok = all(primitive_root(t) in prim for t in all_t)
    print(f"Every triple is k times a primitive triple: {roots_ok}")
    print(f"abc is a multiple of 60 for every triple found: "
          f"{all(a * b * c % 60 == 0 for a, b, c in all_t)}")
    counts = hypotenuse_counts(all_t)
    best = max(counts.values())
    tops = [c for c, k in sorted(counts.items()) if k == best]
    print(f"Hypotenuses in the most triples ({best} each): {tops}")
    print()
    print("Epistemic status: exact, exhaustive search for c <= 100. It is evidence")
    print("for, not proof of, the facts that Euclid's formula gives every primitive")
    print("triple and that 60 always divides abc; both are theorems of number")
    print("theory, proved with divisibility arguments.")

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

The search is exhaustive for c≤100c \le 100: there are exactly 52 triples, 16 of them primitive, and Euclid's formula produces exactly those 16. It also finds a pattern we did not expect: abcabc is always a multiple of 60. A search can find patterns and refute guesses, but it cannot prove a pattern continues for ever; both patterns are in fact theorems of number theory.

Right, acute or obtuse? Every triangle with sides up to 20PythonExact computationNumerical approximationExhaustive finite checkComputationally tested
"""Testing the converse: build every whole-number triangle and measure it.

For every triangle with whole-number sides a <= b <= c <= 20, the experiment
builds it in the coordinate plane: C = (0, 0), B = (a, 0), and A = (x, y)
with CA = b and BA = c. Subtracting the two distance equations gives the exact
value x = (a^2 + b^2 - c^2) / (2a), computed with fractions. The angle at C is
then measured numerically (like a protractor) and compared with the test
"compare a^2 + b^2 with c^2". The sign of x is the whole story: x = 0 means a
right angle at C, x > 0 an acute one, x < 0 an obtuse one.
"""

import math
from fractions import Fraction

def triangles(limit):
    """All (a, b, c) with a <= b <= c <= limit satisfying a + b > c."""
    return [(a, b, c) for c in range(1, limit + 1) for b in range(1, c + 1)
            for a in range(1, b + 1) if a + b > c]

def apex(a, b, c):
    """Exact x and approximate y of A, where C = (0, 0) and B = (a, 0)."""
    x = Fraction(a * a + b * b - c * c, 2 * a)
    y = math.sqrt(b * b - x * x)
    return x, y

def angle_at_c(a, b, c):
    """The angle ACB in degrees, measured from the coordinates."""
    x, y = apex(a, b, c)
    return math.degrees(math.atan2(y, float(x)))

def pythagoras_test(a, b, c):
    """'right', 'acute' or 'obtuse' by comparing a^2 + b^2 with c^2."""
    s, t = a * a + b * b, c * c
    return "right" if s == t else ("acute" if s > t else "obtuse")

def measured_type(a, b, c, tol=1e-9):
    """'right', 'acute' or 'obtuse' from the measured angle at C."""
    ang = angle_at_c(a, b, c)
    if abs(ang - 90) < tol:
        return "right"
    return "acute" if ang < 90 else "obtuse"

def main():
    tris = triangles(20)
    counts = {"right": 0, "acute": 0, "obtuse": 0}
    agree = 0
    for t in tris:
        kind = pythagoras_test(*t)
        counts[kind] += 1
        agree += kind == measured_type(*t)
    print(f"Triangles with whole-number sides a <= b <= c <= 20: {len(tris)}")
    print(f"  by the test a^2 + b^2 vs c^2: {counts['right']} right, "
          f"{counts['acute']} acute, {counts['obtuse']} obtuse")
    print(f"  measured angle at C agrees with the test: {agree} of {len(tris)}")
    rights = [t for t in tris if pythagoras_test(*t) == "right"]
    print("  the right ones:")
    print("    " + ", ".join(str(t) for t in rights))
    print()
    print("Three examples (x is exact, the angle is measured):")
    for t in [(3, 4, 5), (5, 6, 8), (4, 5, 6)]:
        x, _ = apex(*t)
        print(f"  sides {t}: x = {str(x):>6}, angle at C = "
              f"{angle_at_c(*t):7.3f} degrees ({pythagoras_test(*t)})")
    smallest = min((abs(angle_at_c(*t) - 90), t) for t in tris
                   if pythagoras_test(*t) != "right")
    print(f"Closest to 90 degrees without being right: {smallest[1]}, off by "
          f"{smallest[0]:.3f} degrees")
    print()
    print("Epistemic status: exhaustive over these 825 triangles. The x-coordinate")
    print("is exact (x = 0 exactly for the right triangles); the angles are")
    print("floating-point measurements, and an angle within 1e-9 degrees of 90")
    print("counts as right. Evidence for these triangles only: the converse is")
    print("proved in the lesson for every triangle.")

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

All 825 triangles agree with the test: right exactly when a2+b2=c2a^2 + b^2 = c^2, acute when it is bigger, obtuse when it is smaller. Look at the exact xx-coordinate x=a2+b2−c22ax = \frac{a^2 + b^2 - c^2}{2a} of the top vertex: its sign is the sign of a2+b2−c2a^2 + b^2 - c^2. That observation, turned into an argument, is a second proof of the converse.

Explore

Explore: the squares on the sides

Change the legs aa and bb of the right triangle with corner CC at the origin. The picture shows the squares on the two legs, the square on the hypotenuse, and the big square of side a+ba + b from the first proof. Choose whole numbers and count unit squares: for a=3a = 3, b=4b = 4, the big square has area 4949, the four corner triangles 4×6=244 \times 6 = 24, and the tilted square 49−24=25=9+1649 - 24 = 25 = 9 + 16. Try a=b=1a = b = 1 to see 2\sqrt{2}.

Squares on the sides of a right triangle

A point moves along the curve as t changes: x and y are both functions of t.

CBA
  • right triangle, legs a and b
  • square on a: area a²
  • square on b: area b²
  • square on the hypotenuse: area c²
  • big square, side a + b
  • (1.5, 0)
  • (1.5, 0)
  • (0, 2)
  • (5, 1.5)
  • (3.5, 0)
Exercises

Exercises

1. The Pythagorean theorem

Warm-upHuman

A right triangle has legs 88 cm and 1515 cm. How long is the hypotenuse, in cm?

2. The Pythagorean theorem

Warm-upHuman

A right triangle has hypotenuse 1313 and one leg 55. How long is the other leg?

3. The Pythagorean theorem

CoreHuman

What is the straight-line distance between the points (1,5)(1, 5) and (7,−3)(7, -3)?

4. The Pythagorean theorem

CoreHuman

Which of these triangles has a right angle?

Choose one

5. The Pythagorean theorem

CoreHuman

A right triangle has one leg 66 and hypotenuse 1010. Rahul writes 62+102=1366^2 + 10^2 = 136 and says the third side is 136≈11.7\sqrt{136} \approx 11.7. What went wrong?

Choose one

6. The Pythagorean theorem

CoreHuman

In the first rearrangement proof, why is the shape in the middle of the left picture a square?

Choose one

7. The Pythagorean theorem

StretchHuman

Use Euclid's formula (m2−n2, 2mn, m2+n2)(m^2 - n^2,\ 2mn,\ m^2 + n^2) with m=5m = 5 and n=2n = 2. What is the hypotenuse of the triple you get?

8. The Pythagorean theorem

StretchHuman

A triangle has sides 77, 88 and 1111. What kind of angle is opposite the side 1111?

Choose one

9. The Pythagorean theorem

CoreFormal

In the Lean file, sqDist A B is the square of the distance ABAB and IsRightAngleAt A B C says the angle at CC is a right angle. Which statement is the converse of the Pythagorean theorem?

Choose one

10. The Pythagorean theorem

StretchComputational

Write a function is_right(a, b, c) that returns True if a triangle with sides a, b, c (given in any order) has a right angle, and False otherwise. Use whole numbers, so the test is exact.

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

Common misconceptions

Misconception

Using a2+b2=c2a^2 + b^2 = c^2 for triangles without a right angle. The proof used the right angle to show that the middle shape is a square. For an equilateral triangle with sides 1, 12+12=2≠1=121^2 + 1^2 = 2 \neq 1 = 1^2. Before using the theorem, check that there is a right angle — or, if you only know the sides, use the converse.

Misconception

Taking cc to be any side. cc must be the hypotenuse, the side opposite the right angle, which is always the longest side. In the 3-4-5 triangle, 32+52=34≠16=423^2 + 5^2 = 34 \neq 16 = 4^2. When finding a missing leg, subtract: a2=c2−b2a^2 = c^2 - b^2.

Misconception

Thinking a2+b2=a+b\sqrt{a^2 + b^2} = a + b. For legs 3 and 4, 9+16=5\sqrt{9 + 16} = 5, not 77. Squaring a sum gives an extra term: (a+b)2=a2+2ab+b2(a + b)^2 = a^2 + 2ab + b^2, which is bigger than a2+b2a^2 + b^2 whenever a,b>0a, b > 0. Geometrically: the hypotenuse is a short cut, shorter than walking along both legs.

Misconception

“Pythagoras discovered it.” The relation was known and used in Mesopotamia, India and China, in some cases more than a thousand years before Pythagoras (6th century BCE). No writing by Pythagoras survives, and we do not know whether he proved it. The oldest surviving complete proof is in Euclid's Elements (about 300 BCE).

ViewpointsH

Other ways of seeing

Geometry— On a sphere, Pythagoras fails

The proof used the fact that the angles of a triangle add up to 180∘180^\circ — true on a flat plane, false on a curved surface. On a globe, walk from the North Pole down to the equator, turn 90∘90^\circ, walk a quarter of the way round the equator, turn 90∘90^\circ and walk back to the pole. Your path is a triangle with three right angles and three equal sides, so a2+b2=2c2≠c2a^2 + b^2 = 2c^2 \neq c^2. For small triangles on a large sphere, a2+b2=c2a^2 + b^2 = c^2 holds approximately, and the size of the error measures how curved the surface is. Try it below. See non-Euclidean geometry.

A triangle with three right angles

Drag the corners. On a flat plane the angles add up to 180°; on a sphere they add up to more, and in the hyperbolic plane to less.

90.0°90.0°90.0°ABC

Drag a corner to move it; drag anywhere else to turn the sphere. The sides are arcs of great circles — the shortest paths on a sphere.

  • ∠A90.0°
  • ∠B90.0°
  • ∠C90.0°

∠A + ∠B + ∠C = 270.0°

Angle excess (sum − 180°)
90.0° = 1.571 rad
Area, measured numerically
1.571 R²
Share of the whole sphere (area ÷ 4πR²)
12.50 %

∠A + ∠B + ∠C − π = Area / R²On a sphere of radius R, the excess in radians equals the area divided by R². The area is computed separately, by numerical integration, so the match is a check rather than an assumption.

∠A + ∠B + ∠C − π = K · Area

Flat planeK = 0∠A+∠B+∠C = 180°
SphereK = 1/R²∠A+∠B+∠C > 180°
Hyperbolic planeK = −1∠A+∠B+∠C < 180°

This is a first glimpse of the Gauss–Bonnet theorem: for a triangle whose sides are geodesics (shortest paths), the angle sum minus π equals the total curvature inside it. Here the curvature K is the same everywhere; on other surfaces you add up (integrate) K over the area.

Number theory— Whole-number solutions

Asking for whole-number solutions of a2+b2=c2a^2 + b^2 = c^2 turns a geometry theorem into a problem about integers. Euclid's formula answers it completely. Dividing by c2c^2 gives (a/c)2+(b/c)2=1(a/c)^2 + (b/c)^2 = 1: each triple is a point with fraction coordinates on the circle of radius 1, such as (35,45)(\tfrac35, \tfrac45). Drawing lines through (−1,0)(-1, 0) with fraction slopes finds every such point — a geometric derivation of Euclid's formula. Changing the exponent from 2 to 3 or more leads to Fermat's Last Theorem. See elementary number theory.

Algebra— More dimensions

Applying the theorem twice gives distances in space: the diagonal of a box with edges aa, bb, hh has length a2+b2+h2\sqrt{a^2 + b^2 + h^2} (first the diagonal of the floor, then up). In coordinates, the length of a vector (x1,…,xn)(x_1, \dots, x_n) is x12+⋯+xn2\sqrt{x_1^2 + \dots + x_n^2} in any number of dimensions, and “perpendicular” becomes the algebraic condition x1y1+⋯+xnyn=0x_1 y_1 + \dots + x_n y_n = 0 that appeared in our Lean proof of the converse. See vectors.

Wonder Trails

Wonder Trails

History & global context

History and global context

  • Mesopotamia. The Old Babylonian tablet YBC 7289 (about 1800–1600 BCE) shows a square with its diagonals and gives 2\sqrt{2} in base 60 as 1;24,51,10≈1.41421301;24,51,10 \approx 1.4142130, correct to about six decimal places. The tablet Plimpton 322, from the same period, lists numbers closely related to Pythagorean triples such as (119,120,169)(119, 120, 169); its exact purpose is still debated.
  • India. The Baudhāyana Śulbasūtra (dates uncertain, perhaps 800–500 BCE), a manual for building fire altars, states that the diagonal of a rectangle produces both areas that its length and breadth produce separately — the theorem in words — and lists triples.
  • China. The Zhoubi Suanjing (compiled by about the 1st century CE) discusses the gougu rule with the 3-4-5 triangle. In the 3rd century CE, Zhao Shuang's commentary gave the “hypotenuse diagram” used in our second proof, and Liu Hui gave a dissection proof in his commentary on the Nine Chapters.
  • Greece. Euclid's Elements (about 300 BCE) proves the theorem as Book I, Proposition 47, and its converse as Proposition 48. The traditional link with Pythagoras comes from much later writers.
  • The Islamic world and beyond. Thābit ibn Qurra in 9th-century Baghdad generalised the theorem to all triangles. In 12th-century India, Bhāskara II gave a dissection proof with the square-in-the-middle figure. In 1876 James Garfield, later President of the United States, published a proof using a trapezium. Elisha Loomis's The Pythagorean Proposition (1927; 2nd edition 1940) collected 367 proofs.
  • 1995. Andrew Wiles's proof of Fermat's Last Theorem settled the question Fermat asked about higher powers.
Further reading

Further reading

  • Eli Maor, The Pythagorean Theorem: A 4,000-Year History (2007).
  • Euclid, Elements, Book I, Propositions 47–48 (translation by Thomas L. Heath, 1908).
  • Frank J. Swetz and T. I. Kao, Was Pythagoras Chinese? An Examination of Right Triangle Theory in Ancient China (1977).
  • Elisha Scott Loomis, The Pythagorean Proposition (1927; 2nd edition 1940).