Fermat's two-square theorem
ProvedFamousTheorems.prime_sq_add_sqmathlibnumber-theory
A prime is a sum of two squares unless it is .
For a prime with ,
The excluded case is forced: squares are or mod , so a sum of two squares is never mod . The content is the converse for (with the remaining case).
Announced by Fermat in 1640 and first proved by Euler after seven years' work. The conceptual proof observes that makes a quadratic residue, so divides in while dividing neither factor; since is a unique factorisation domain, is not prime there, and its factorisation gives . This is the prototype for using algebraic number theory to answer questions about .
Preamble
import Mathlib
Formal statement
namespace FamousTheorems
theorem prime_sq_add_sq : ∀ {p : ℕ} [Fact (Nat.Prime p)], p % 4 ≠ 3 → ∃ a b : ℕ, a ^ 2 + b ^ 2 = p := by sorry
end FamousTheoremsSource
One of Freek Wiedijk's "100 theorems"; formalized in Mathlib. Proof here reduces to the corresponding Mathlib result.