Waring's problem for : (Lagrange, 1770)
Provedwaring_g_two_eq_fourWaring's problem for : . Every natural number is the sum of at most four perfect squares, and four is best possible.
and this fails for three squares: requires all four (the only squares are , and no three of these sum to ).
This is the case of Waring's problem, resolved by Lagrange in 1770 (the "four squares theorem"). It is the foundational instance of the general Waring problem: for each , find the smallest such that every natural number is a sum of at most -th powers. The upper bound is proved via Euler's four-square identity (products of sums of four squares are sums of four squares) and Fermat's theorem for primes; the lower bound is a finite check on .
Formalization Note The upper bound is Mathlib's Nat.sum_four_squares. The lower bound uses interval_cases on the 27 combinations of .
import Mathlib
theorem waring_g_two_eq_four :
(∀ n : ℕ, ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n) ∧
¬(∀ n : ℕ, ∃ a b c : ℕ, a ^ 2 + b ^ 2 + c ^ 2 = n) := by sorry