The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V02. Numbers

Mathlib.Data.Nat.Prime.Defs

76 declarations. Mathlib docs · Source

Prime numbers

This file deals with prime numbers: natural numbers p ≥ 2 whose only divisors are p and 1.

Important declarations

  • Nat.Prime: the predicate that expresses that a natural number p is prime
  • Nat.Primes: the subtype of natural numbers that are prime
  • Nat.minFac n: the minimal prime factor of a natural number n ≠ 1
  • Nat.prime_iff: Nat.Prime coincides with the general definition of Prime
  • Nat.irreducible_iff_nat_prime: a non-unit natural number is only divisible by 1 iff it is prime

Specific small primes

It is recommended not to add further lemmas to this list; instead, import Mathlib.Tactic.NormNum.Prime in downstream files and use norm_num for primality proofs.

def Nat.Prime E1 #

ℕ → Prop

Nat.Prime p means that p is a prime number, that is, a natural number at least 2 whose only divisors are p and 1. The theorem Nat.prime_def witnesses this description of a prime number.

theorem Nat.irreducible_iff_nat_prime E1 #

∀ (a : ℕ), Irreducible a ↔ Nat.Prime a

theorem Nat.not_prime_zero E1 #

¬Nat.Prime 0

theorem Nat.prime_zero_false E1 #

Nat.Prime 0 → False

A copy of not_prime_zero stated in a way that works for aesop.

See https://github.com/leanprover-community/aesop/issues/197 for an explanation.

theorem Nat.not_prime_one E1 #

¬Nat.Prime 1

theorem Nat.prime_one_false E1 #

Nat.Prime 1 → False

A copy of not_prime_one stated in a way that works for aesop.

See https://github.com/leanprover-community/aesop/issues/197 for an explanation.

theorem Nat.Prime.ne_zero E1 #

∀ {n : ℕ}, Nat.Prime n → n ≠ 0

theorem Nat.Prime.pos E1 #

∀ {p : ℕ}, Nat.Prime p → 0 < p

theorem Nat.Prime.two_le E1 #

∀ {p : ℕ}, Nat.Prime p → 2 ≤ p

theorem Nat.Prime.one_lt E1 #

∀ {p : ℕ}, Nat.Prime p → 1 < p

theorem Nat.Prime.one_le E1 #

∀ {p : ℕ}, Nat.Prime p → 1 ≤ p

instance Nat.Prime.one_lt' E0 #

∀ (p : ℕ) [hp : Fact (Nat.Prime p)], Fact (1 < p)

theorem Nat.Prime.ne_one E1 #

∀ {p : ℕ}, Nat.Prime p → p ≠ 1

theorem Nat.prime_def E0 #

∀ {p : ℕ}, Nat.Prime p ↔ 2 ≤ p ∧ ∀ (m : ℕ), m ∣ p → m = 1 ∨ m = p

Nat.Prime p means that p is a prime number, that is, a natural number at least 2 whose only divisors are p and 1. The theorem Nat.prime_def witnesses this description of a prime number.

theorem Nat.prime_def_lt E1 #

∀ {p : ℕ}, Nat.Prime p ↔ 2 ≤ p ∧ ∀ m < p, m ∣ p → m = 1

theorem Nat.prime_def_lt' E1 #

∀ {p : ℕ}, Nat.Prime p ↔ 2 ≤ p ∧ ∀ (m : ℕ), 2 ≤ m → m < p → ¬m ∣ p

theorem Nat.prime_def_le_sqrt E1 #

∀ {p : ℕ}, Nat.Prime p ↔ 2 ≤ p ∧ ∀ (m : ℕ), 2 ≤ m → m ≤ p.sqrt → ¬m ∣ p

theorem Nat.prime_iff_not_exists_mul_eq E0 #

∀ {p : ℕ}, Nat.Prime p ↔ 2 ≤ p ∧ ¬∃ m n, m < p ∧ n < p ∧ m * n = p

theorem Nat.prime_of_coprime E1 #

∀ (n : ℕ), 1 < n → (∀ m < n, m ≠ 0 → n.Coprime m) → Nat.Prime n

instance Nat.decidablePrime E0 #

(p : ℕ) → Decidable (Nat.Prime p)

This instance is set up to work in the kernel (by decide) for small values.

Below (decidablePrime') we will define a faster variant to be used by the compiler (e.g. in #eval or by native_decide).

If you need to prove that a particular number is prime, in any case you should not use by decide, but rather by norm_num, which is much faster.

theorem Nat.prime_two E1 #

Nat.Prime 2

theorem Nat.prime_three E1 #

Nat.Prime 3

theorem Nat.prime_five E1 #

Nat.Prime 5

theorem Nat.prime_seven E1 #

Nat.Prime 7

theorem Nat.prime_eleven E1 #

Nat.Prime 11

theorem Nat.dvd_prime E1 #

∀ {p m : ℕ}, Nat.Prime p → (m ∣ p ↔ m = 1 ∨ m = p)

theorem Nat.dvd_prime_two_le E1 #

∀ {p m : ℕ}, Nat.Prime p → 2 ≤ m → (m ∣ p ↔ m = p)

theorem Nat.prime_dvd_prime_iff_eq E0 #

∀ {p q : ℕ}, Nat.Prime p → Nat.Prime q → (p ∣ q ↔ p = q)

theorem Nat.Prime.not_dvd_one E1 #

∀ {p : ℕ}, Nat.Prime p → ¬p ∣ 1

theorem Nat.minFac_lemma E1 #

∀ (n k : ℕ), ¬n < k * k → n.sqrt - k < n.sqrt + 2 - k

def Nat.minFacAux E0 #

ℕ → ℕ → ℕ

If n < k * k, then minFacAux n k = n, if k | n, then minFacAux n k = k. Otherwise, minFacAux n k = minFacAux n (k+2) using well-founded recursion. If n is odd and 1 < n, then minFacAux n 3 is the smallest prime factor of n.

This definition is by well-founded recursion, so rfl or decide cannot be used. One can use norm_num to prove Nat.prime n for small n.

def Nat.minFac E1 #

ℕ → ℕ

Returns the smallest prime factor of n ≠ 1.

theorem Nat.minFac_zero E0 #

Nat.minFac 0 = 2

theorem Nat.minFac_one E0 #

Nat.minFac 1 = 1

theorem Nat.minFac_two E0 #

Nat.minFac 2 = 2

theorem Nat.minFac_eq E0 #

∀ (n : ℕ), n.minFac = if 2 ∣ n then 2 else n.minFacAux 3

theorem Nat.minFac_dvd E1 #

∀ (n : ℕ), n.minFac ∣ n

theorem Nat.minFac_prime E1 #

∀ {n : ℕ}, n ≠ 1 → Nat.Prime n.minFac

theorem Nat.minFac_prime_iff E0 #

∀ {n : ℕ}, Nat.Prime n.minFac ↔ n ≠ 1

theorem Nat.minFac_le_of_dvd E1 #

∀ {n m : ℕ}, 2 ≤ m → m ∣ n → n.minFac ≤ m

theorem Nat.minFac_pos E1 #

∀ (n : ℕ), 0 < n.minFac

theorem Nat.minFac_le E1 #

∀ {n : ℕ}, 0 < n → n.minFac ≤ n

theorem Nat.le_minFac E1 #

∀ {m n : ℕ}, n = 1 ∨ m ≤ n.minFac ↔ ∀ (p : ℕ), Nat.Prime p → p ∣ n → m ≤ p

theorem Nat.le_minFac' E1 #

∀ {m n : ℕ}, n = 1 ∨ m ≤ n.minFac ↔ ∀ (p : ℕ), 2 ≤ p → p ∣ n → m ≤ p

theorem Nat.prime_def_minFac E1 #

∀ {p : ℕ}, Nat.Prime p ↔ 2 ≤ p ∧ p.minFac = p

theorem Nat.Prime.minFac_eq E0 #

∀ {p : ℕ}, Nat.Prime p → p.minFac = p

def Nat.decidablePrime' E1 #

(p : ℕ) → Decidable (Nat.Prime p)

This definition is faster in the virtual machine than decidablePrime, but slower in the kernel.

theorem Nat.decidablePrime_csimp E1 #

Nat.decidablePrime = Nat.decidablePrime'

theorem Nat.not_prime_iff_minFac_lt E1 #

∀ {n : ℕ}, 2 ≤ n → (¬Nat.Prime n ↔ n.minFac < n)

theorem Nat.minFac_le_div E1 #

∀ {n : ℕ}, 0 < n → ¬Nat.Prime n → n.minFac ≤ n / n.minFac

theorem Nat.minFac_sq_le_self E1 #

∀ {n : ℕ}, 0 < n → ¬Nat.Prime n → n.minFac ^ 2 ≤ n

The square of the smallest prime factor of a composite number n is at most n.

theorem Nat.minFac_eq_one_iff E0 #

∀ {n : ℕ}, n.minFac = 1 ↔ n = 1

theorem Nat.minFac_eq_two_iff E0 #

∀ (n : ℕ), n.minFac = 2 ↔ 2 ∣ n

theorem Nat.factors_lemma E1 #

∀ {k : ℕ}, (k + 2) / (k + 2).minFac < k + 2

theorem Nat.exists_prime_and_dvd E1 #

∀ {n : ℕ}, n ≠ 1 → ∃ p, Nat.Prime p ∧ p ∣ n

theorem Nat.exists_prime_and_dvd_and_dvd_div E1 #

∀ {m n : ℕ}, m ∣ n → m ≠ n → ∃ p, Nat.Prime p ∧ p ∣ n ∧ m ∣ n / p

theorem Nat.coprime_of_dvd E1 #

∀ {m n : ℕ}, (∀ (k : ℕ), Nat.Prime k → k ∣ m → ¬k ∣ n) → m.Coprime n

theorem Nat.Prime.coprime_iff_not_dvd E1 #

∀ {p n : ℕ}, Nat.Prime p → (p.Coprime n ↔ ¬p ∣ n)

theorem Nat.Prime.dvd_mul E1 #

∀ {p m n : ℕ}, Nat.Prime p → (p ∣ m * n ↔ p ∣ m ∨ p ∣ n)

theorem Nat.Prime.dvd_or_dvd E1 #

∀ {p m n : ℕ}, Nat.Prime p → p ∣ m * n → p ∣ m ∨ p ∣ n

Alias of the forward direction of Nat.Prime.dvd_mul.

theorem Nat.prime_iff E0 #

∀ {p : ℕ}, Nat.Prime p ↔ Prime p

theorem Nat.Prime.prime E1 #

∀ {p : ℕ}, Nat.Prime p → Prime p

Alias of the forward direction of Nat.prime_iff.

theorem Prime.nat_prime E1 #

∀ {p : ℕ}, Prime p → Nat.Prime p

Alias of the reverse direction of Nat.prime_iff.

instance Nat.instDecidablePredPrime E0 #

DecidablePred Prime

theorem Nat.irreducible_iff_prime E1 #

∀ {p : ℕ}, Irreducible p ↔ Prime p

instance Nat.instDecidablePredIrreducible E0 #

DecidablePred Irreducible

def Nat.Primes E1 #

Type

The type of prime numbers

instance Nat.instDecidableEqPrimes E0 #

DecidableEq Nat.Primes

instance Nat.Primes.instRepr E0 #

Repr Nat.Primes

instance Nat.Primes.inhabitedPrimes E0 #

Inhabited Nat.Primes

instance Nat.Primes.coeNat E0 #

Coe Nat.Primes ℕ

theorem Nat.Primes.coe_nat_injective E0 #

Function.Injective Subtype.val

theorem Nat.Primes.coe_nat_inj E0 #

∀ (p q : Nat.Primes), ↑p = ↑q ↔ p = q

instance Nat.monoid.primePow E0 #

{α : Type u_1} → [Monoid α] → Pow α Nat.Primes

instance Nat.fact_prime_two E0 #

Fact (Nat.Prime 2)

instance Nat.fact_prime_three E0 #

Fact (Nat.Prime 3)