The sum of two squares theorem
ProvedFamousTheorems.sum_of_two_squares_theoremThe sum of two squares theorem. A natural number is a sum of two squares of natural numbers if and only if every prime appears in the prime factorization of with even exponent.
This combines Fermat's theorem on primes being sums of two squares with the multiplicativity of sums of two squares (Brahmagupta–Fibonacci identity). It is a model result for the arithmetic of quadratic forms and of the Gaussian integers.
Formalization note. Mathlib's Nat.eq_sq_add_sq_iff. n.primeFactors is the set of primes dividing , and padicValNat q n is the exponent of in . For both sides hold, since and has no prime factors.
Preamble
import Mathlib
Formal statement
namespace FamousTheorems
theorem sum_of_two_squares_theorem {n : ℕ} : (∃ x y : ℕ, n = x ^ 2 + y ^ 2) ↔ ∀ q ∈ n.primeFactors, q % 4 = 3 → Even (padicValNat q n) := by sorry
end FamousTheoremsSource
Listed in Mathlib's curated theorem manifests (docs/1000.yaml); formalized in Mathlib as `Nat.eq_sq_add_sq_iff`. Proof here reduces to that Mathlib result.