Pythagorean Triples

lean4-proofnumber-theoryvisualization
a=m2n2,  b=2mn,  c=m2+n2a = m^2 - n^2,\; b = 2mn,\; c = m^2 + n^2

Statement

A Pythagorean triple is a triple of positive integers (a,b,c)(a, b, c) satisfying

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

Every primitive Pythagorean triple (with gcd(a,b,c)=1\gcd(a,b,c) = 1 and bb even) has the form

a=m2n2,b=2mn,c=m2+n2,a = m^2 - n^2, \qquad b = 2mn, \qquad c = m^2 + n^2,

where m>n>0m > n > 0, gcd(m,n)=1\gcd(m, n) = 1, and m≢n(mod2)m \not\equiv n \pmod{2}.

Every Pythagorean triple is obtained by multiplying a primitive one by a common factor k1k \geq 1.

Visualization

Primitive triples generated by small (m,n)(m, n):

m   n   a = m²-n²   b = 2mn   c = m²+n²   Check
----+---+-----------+---------+-----------+------
2   1       3           4         5        3²+4²=25=5²   ✓
3   2       5          12        13        5²+12²=169=13² ✓
4   1      15           8        17        15²+8²=289=17² ✓
4   3       7          24        25        7²+24²=625=25² ✓
5   2      21          20        29        21²+20²=841=29²✓
5   4       9          40        41        9²+40²=1681=41²✓

The first triple (3,4,5)(3, 4, 5) is the simplest and best known. All others in the table above are primitive because gcd(m,n)=1\gcd(m,n) = 1 and m≢n(mod2)m \not\equiv n \pmod 2.

Proof Sketch

  1. Odd/even structure: In a primitive triple, exactly one of a,ba, b is even. Say b=2sb = 2s is even. Then a2=c2b2=(cb)(c+b)a^2 = c^2 - b^2 = (c-b)(c+b), and one checks gcd(cb,c+b)=2\gcd(c-b, c+b) = 2.

  2. Unique factorization: Write cb=2n2c - b = 2n^2 and c+b=2m2c + b = 2m^2 (using that the product of two coprime numbers each equalling a perfect square forces each factor to be a square). Then c=m2+n2c = m^2 + n^2 and b=2mnb = 2mn.

  3. Complete classification: Conversely, for any m>n>0m > n > 0 with gcd(m,n)=1\gcd(m,n) = 1 and m≢n(mod2)m \not\equiv n \pmod 2, the triple (m2n2,2mn,m2+n2)(m^2 - n^2, 2mn, m^2 + n^2) is primitive.

  4. Every triple: Multiply any primitive triple by kZ>0k \in \mathbb{Z}_{>0} to get (ka,kb,kc)(ka, kb, kc).

Connections

The proof uses unique factorization from the Fundamental Theorem of ArithmeticFundamental Theorem of Arithmeticn=p1a1p2a2pkakn = p_1^{a_1} \cdot p_2^{a_2} \cdots p_k^{a_k}Every integer greater than 1 has a unique prime factorizationRead more →. The structure of Z[i]\mathbb{Z}[i] (Gaussian integers) provides a slick alternative proof — each factor c+ibc + ib or cibc - ib is a product of Gaussian primes, tying this to Sum of Two SquaresSum of Two Squaresp=a2+b2    p=2 or p1(mod4)p = a^2 + b^2 \iff p = 2 \text{ or } p \equiv 1 \pmod{4}A prime is a sum of two perfect squares if and only if it equals 2 or is congruent to 1 mod 4Read more →. Pythagorean triples also connect to Euler's Totient (counting coprime pairs) and to Diophantine equations more broadly, which uses ideas from Chinese Remainder TheoremChinese Remainder TheoremZ/mnZZ/mZ×Z/nZ\mathbb{Z}/mn\mathbb{Z} \cong \mathbb{Z}/m\mathbb{Z} \times \mathbb{Z}/n\mathbb{Z}Simultaneous congruences with coprime moduli have a unique solution mod their productRead more →.

Lean4 Proof

/-- Mathlib defines `PythagoreanTriple x y z` as `x * x + y * y = z * z` (over ℤ).
    The triple (3, 4, 5) satisfies this by a direct numerical check. -/
theorem pyth_345 : PythagoreanTriple 3 4 5 := by
  unfold PythagoreanTriple
  norm_num

/-- Scaling: if (a, b, c) is a Pythagorean triple, so is (k·a, k·b, k·c). -/
theorem pyth_scaled (x y z k : ) (h : PythagoreanTriple x y z) :
    PythagoreanTriple (k * x) (k * y) (k * z) :=
  h.mul k