The areas / V12. Number theory
Mathlib.NumberTheory.SumTwoSquares
12 declarations. Mathlib docs · Source
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
Relation to sums of two squares
Characterization in terms of the prime factorization
theorem ZMod.chineseRemainder.congr_simp E1 #
∀ {m n : ℕ} (h : m.Coprime n), ZMod.chineseRemainder h = ZMod.chineseRemainder h
theorem Nat.Prime.sq_add_sq E3 #
∀ {p : ℕ} [Fact (Nat.Prime p)], p % 4 ≠ 3 → ∃ a b, a ^ 2 + b ^ 2 = p
Fermat's theorem on the sum of two squares. Every prime not congruent to 3 mod 4 is the sum of two squares. Also known as Fermat's Christmas theorem.
theorem sq_add_sq_mul E1 #
∀ {R : Type u_1} [inst : CommRing R] {a b x y u v : R},
a = x ^ 2 + y ^ 2 → b = u ^ 2 + v ^ 2 → ∃ r s, a * b = r ^ 2 + s ^ 2
The set of sums of two squares is closed under multiplication in any commutative ring.
See also sq_add_sq_mul_sq_add_sq.
theorem Nat.sq_add_sq_mul E1 #
∀ {a b x y u v : ℕ}, a = x ^ 2 + y ^ 2 → b = u ^ 2 + v ^ 2 → ∃ r s, a * b = r ^ 2 + s ^ 2
The set of natural numbers that are sums of two squares is closed under multiplication.
theorem ZMod.isSquare_neg_one_of_dvd E1 #
∀ {m n : ℕ}, m ∣ n → IsSquare (-1) → IsSquare (-1)
If -1 is a square modulo n and m divides n, then -1 is also a square modulo m.
theorem ZMod.isSquare_neg_one_mul E1 #
∀ {m n : ℕ}, m.Coprime n → IsSquare (-1) → IsSquare (-1) → IsSquare (-1)
If -1 is a square modulo coprime natural numbers m and n, then -1 is also
a square modulo m*n.
theorem Nat.mod_four_ne_three_of_mem_primeFactors_of_isSquare_neg_one E1 #
∀ {p n : ℕ}, p ∈ n.primeFactors → IsSquare (-1) → p % 4 ≠ 3
If p is a prime factor of n such that -1 is a square modulo n, then p % 4 ≠ 3.
theorem ZMod.isSquare_neg_one_iff_forall_mem_primeFactors_mod_four_ne_three E1 #
∀ {n : ℕ}, Squarefree n → (IsSquare (-1) ↔ ∀ q ∈ n.primeFactors, q % 4 ≠ 3)
If n is a squarefree natural number, then -1 is a square modulo n if and only if
n does not have a prime factor q such that q % 4 = 3.
theorem ZMod.isSquare_neg_one_iff' E1 #
∀ {n : ℕ}, Squarefree n → (IsSquare (-1) ↔ ∀ {q : ℕ}, q ∣ n → q % 4 ≠ 3)
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.
theorem ZMod.isSquare_neg_one_of_eq_sq_add_sq_of_isCoprime E1 #
∀ {n x y : ℤ}, n = x ^ 2 + y ^ 2 → IsCoprime x y → IsSquare (-1)
If the integer n is a sum of two squares of coprime integers,
then -1 is a square modulo n.
theorem ZMod.isSquare_neg_one_of_eq_sq_add_sq_of_coprime E1 #
∀ {n x y : ℕ}, n = x ^ 2 + y ^ 2 → x.Coprime y → IsSquare (-1)
If the natural number n is a sum of two squares of coprime natural numbers, then
-1 is a square modulo n.
instance instDecidableExistsNatEqHAddHPowOfNat_mathlib E0 #
{n : ℕ} → Decidable (∃ x y, n = x ^ 2 + y ^ 2)