Sums of two squares #
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 #
If -1
is a square modulo coprime natural numbers m
and n
, then -1
is also
a square modulo m*n
.
If n
is a squarefree natural number, then -1
is a square modulo n
if and only if
n
has no divisor q
that is ≡ 3 mod 4
.
Relation to sums of two squares #
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 padicValNat q 0 = 0
by definition.)