Sums of two squares #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Fermat's theorem on the sum of two squares. Every prime p congruent to 1 mod 4 is the
sum of two squares; see nat.prime.sq_add_sq (which has the weaker assumption p % 4 ≠ 3).
We also give the result that characterizes the (positive) natural numbers that are sums
of two squares as those numbers n such that for every prime q congruent to 3 mod 4, the
exponent of the largest power of q dividing n is even; see nat.eq_sq_add_sq_iff.
There is an alternative characterization as the numbers of the form a^2 * b, where b is a
natural number such that -1 is a square modulo b; see nat.eq_sq_add_sq_iff_eq_sq_mul.
Generalities on sums of two squares #
Results on when -1 is a square modulo a natural number #
Relation to sums of two squares #
If the integer n is a sum of two squares of coprime integers,
then -1 is a square modulo n.
Characterization in terms of the prime factorization #
A (positive) natural number n is a sum of two squares if and only if the exponent of
every prime q such that q % 4 = 3 in the prime factorization of n is even.
(The assumption 0 < n is not present, since for n = 0, both sides are satisfied;
the right hand side holds, since padic_val_nat q 0 = 0 by definition.)