Documentation

Mathlib.Data.Nat.Prime.Defs

Prime numbers #

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

Important declarations #

def Nat.Prime (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.

Equations

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.

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 {n : } (h : Prime n) :
n 0
theorem Nat.Prime.pos {p : } (pp : Prime p) :
0 < p
theorem Nat.Prime.two_le {p : } :
Prime p2 p
theorem Nat.Prime.one_lt {p : } :
Prime p1 < p
theorem Nat.Prime.one_le {p : } (hp : Prime p) :
1 p
instance Nat.Prime.one_lt' (p : ) [hp : Fact (Prime p)] :
Fact (1 < p)
theorem Nat.Prime.ne_one {p : } (hp : Prime p) :
p 1
theorem Nat.Prime.eq_one_or_self_of_dvd {p : } (pp : Prime p) (m : ) (hm : m p) :
m = 1 m = p
theorem Nat.prime_def {p : } :
Prime p 2 p ∀ (m : ), m pm = 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.

@[deprecated Nat.prime_def (since := "2024-11-19")]
theorem Nat.prime_def_lt'' {p : } :
Prime p 2 p ∀ (m : ), m pm = 1 m = p

Alias of Nat.prime_def.

theorem Nat.prime_def_lt {p : } :
Prime p 2 p ∀ (m : ), m < pm pm = 1
theorem Nat.prime_def_lt' {p : } :
Prime p 2 p ∀ (m : ), 2 mm < p¬m p
theorem Nat.prime_def_le_sqrt {p : } :
Prime p 2 p ∀ (m : ), 2 mm p.sqrt¬m p
theorem Nat.prime_of_coprime (n : ) (h1 : 1 < n) (h : ∀ (m : ), m < nm 0n.Coprime m) :

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.

Equations
theorem Nat.dvd_prime {p m : } (pp : Prime p) :
m p m = 1 m = p
theorem Nat.dvd_prime_two_le {p m : } (pp : Prime p) (H : 2 m) :
m p m = p
theorem Nat.prime_dvd_prime_iff_eq {p q : } (pp : Prime p) (qp : Prime q) :
p q p = q
theorem Nat.Prime.not_dvd_one {p : } (pp : Prime p) :
¬p 1
theorem Nat.minFac_lemma (n k : ) (h : ¬n < k * k) :
n.sqrt - k < n.sqrt + 2 - k
def Nat.minFacAux (n : ) :

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.

By default this well-founded recursion would be irreducible. This prevents use decide to resolve Nat.prime n for small values of n, so we mark this as @[semireducible].

In future, we may want to remove this annotation and instead use norm_num instead of decide in these situations.

Equations
def Nat.minFac (n : ) :

Returns the smallest prime factor of n ≠ 1.

Equations
@[simp]
theorem Nat.minFac_zero :
minFac 0 = 2
@[simp]
theorem Nat.minFac_one :
minFac 1 = 1
@[simp]
theorem Nat.minFac_two :
minFac 2 = 2
theorem Nat.minFac_eq (n : ) :
@[irreducible]
theorem Nat.minFacAux_has_prop {n : } (n2 : 2 n) (k i : ) :
k = 2 * i + 3(∀ (m : ), 2 mm nk m)Nat.minFacProp✝ n (n.minFacAux k)
theorem Nat.minFac_dvd (n : ) :
theorem Nat.minFac_prime {n : } (n1 : n 1) :
theorem Nat.minFac_le_of_dvd {n m : } :
2 mm nn.minFac m
theorem Nat.minFac_pos (n : ) :
0 < n.minFac
theorem Nat.minFac_le {n : } (H : 0 < n) :
theorem Nat.le_minFac {m n : } :
n = 1 m n.minFac ∀ (p : ), Prime pp nm p
theorem Nat.le_minFac' {m n : } :
n = 1 m n.minFac ∀ (p : ), 2 pp nm p
@[simp]
theorem Nat.Prime.minFac_eq {p : } (hp : Prime p) :
p.minFac = p

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

Equations
theorem Nat.not_prime_iff_minFac_lt {n : } (n2 : 2 n) :
theorem Nat.minFac_le_div {n : } (pos : 0 < n) (np : ¬Prime n) :
theorem Nat.minFac_sq_le_self {n : } (w : 0 < n) (h : ¬Prime n) :
n.minFac ^ 2 n

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

@[simp]
theorem Nat.minFac_eq_one_iff {n : } :
n.minFac = 1 n = 1
@[simp]
theorem Nat.minFac_eq_two_iff (n : ) :
n.minFac = 2 2 n
theorem Nat.factors_lemma {k : } :
(k + 2) / (k + 2).minFac < k + 2
theorem Nat.exists_prime_and_dvd {n : } (hn : n 1) :
theorem Nat.coprime_of_dvd {m n : } (H : ∀ (k : ), Prime kk m¬k n) :
theorem Nat.Prime.coprime_iff_not_dvd {p n : } (pp : Prime p) :
p.Coprime n ¬p n
theorem Nat.Prime.dvd_mul {p m n : } (pp : Prime p) :
p m * n p m p n
theorem Prime.nat_prime {p : } :

Alias of the reverse direction of Nat.prime_iff.

theorem Nat.Prime.prime {p : } :

Alias of the forward direction of Nat.prime_iff.

The type of prime numbers

Equations
Equations
theorem Nat.Primes.coe_nat_inj (p q : Primes) :
p = q p = q
instance Nat.monoid.primePow {α : Type u_1} [Monoid α] :
Equations