mathlib documentation

data.​nat.​prime

data.​nat.​prime

Prime numbers

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

Important declarations

All the following declarations exist in the namespace nat.

def nat.​prime  :
→ Prop

prime p means that p is a prime number, that is, a natural number at least 2 whose only divisors are p and 1.

Equations
theorem nat.​prime.​two_le {p : } :
nat.prime p2 p

theorem nat.​prime.​one_lt {p : } :
nat.prime p1 < p

@[instance]
def nat.​prime.​one_lt' (p : ) [hp : fact (nat.prime p)] :
fact (1 < p)

Equations
  • _ = _
theorem nat.​prime.​ne_one {p : } :
nat.prime pp 1

theorem nat.​prime_def_lt {p : } :
nat.prime p 2 p ∀ (m : ), m < pm pm = 1

theorem nat.​prime_def_lt' {p : } :
nat.prime p 2 p ∀ (m : ), 2 mm < p¬m p

theorem nat.​prime_def_le_sqrt {p : } :
nat.prime p 2 p ∀ (m : ), 2 mm nat.sqrt p¬m p

This instance is slower than the instance decidable_prime defined below, but has the advantage that it works in the kernel.

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

Equations
theorem nat.​prime.​ne_zero {n : } :
nat.prime nn 0

theorem nat.​prime.​pos {p : } :
nat.prime p0 < p

theorem nat.​prime.​pred_pos {p : } :
nat.prime p0 < p.pred

theorem nat.​succ_pred_prime {p : } :
nat.prime pp.pred.succ = p

theorem nat.​dvd_prime {p m : } :
nat.prime p(m p m = 1 m = p)

theorem nat.​dvd_prime_two_le {p m : } :
nat.prime p2 m(m p m = p)

theorem nat.​prime_dvd_prime_iff_eq {p q : } :
nat.prime pnat.prime q(p q p = q)

theorem nat.​not_prime_mul {a b : } :
1 < a1 < b¬nat.prime (a * b)

def nat.​min_fac_aux  :

Equations
def nat.​min_fac  :

Returns the smallest prime factor of n ≠ 1.

Equations
@[simp]
theorem nat.​min_fac_zero  :

@[simp]
theorem nat.​min_fac_one  :

theorem nat.​min_fac_eq (n : ) :
n.min_fac = ite (2 n) 2 (n.min_fac_aux 3)

theorem nat.​min_fac_aux_has_prop {n : } (n2 : 2 n) (nd2 : ¬2 n) (k i : ) :
k = 2 * i + 3(∀ (m : ), 2 mm nk m)min_fac_prop n (n.min_fac_aux k)

theorem nat.​min_fac_has_prop {n : } :
n 1min_fac_prop n n.min_fac

theorem nat.​min_fac_dvd (n : ) :

theorem nat.​min_fac_prime {n : } :

theorem nat.​min_fac_le_of_dvd {n m : } :
2 mm nn.min_fac m

theorem nat.​min_fac_pos (n : ) :

theorem nat.​min_fac_le {n : } :
0 < nn.min_fac n

@[instance]

This instance is faster in the virtual machine than decidable_prime_1, but slower in the kernel.

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

Equations
theorem nat.​min_fac_le_div {n : } :
0 < n¬nat.prime nn.min_fac n / n.min_fac

theorem nat.​min_fac_sq_le_self {n : } :
0 < n¬nat.prime nn.min_fac ^ 2 n

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

@[simp]
theorem nat.​min_fac_eq_one_iff {n : } :
n.min_fac = 1 n = 1

@[simp]
theorem nat.​min_fac_eq_two_iff (n : ) :
n.min_fac = 2 2 n

theorem nat.​exists_dvd_of_not_prime {n : } :
2 n¬nat.prime n(∃ (m : ), m n m 1 m n)

theorem nat.​exists_dvd_of_not_prime2 {n : } :
2 n¬nat.prime n(∃ (m : ), m n 2 m m < n)

theorem nat.​exists_prime_and_dvd {n : } :
2 n(∃ (p : ), nat.prime p p n)

theorem nat.​exists_infinite_primes (n : ) :
∃ (p : ), n p nat.prime p

Euclid's theorem. There exist infinitely many prime numbers. Here given in the form: for every n, there exists a prime number p ≥ n.

theorem nat.​prime.​eq_two_or_odd {p : } :
nat.prime pp = 2 p % 2 = 1

theorem nat.​factors_lemma {k : } :
(k + 2) / (k + 2).min_fac < k + 2

def nat.​factors  :

factors n is the prime factorization of n, listed in increasing order.

Equations
theorem nat.​mem_factors {n p : } :

theorem nat.​prod_factors {n : } :
0 < nn.factors.prod = n

theorem nat.​factors_prime {p : } :
nat.prime pp.factors = [p]

theorem nat.​factors_add_two (n : ) :
(n + 2).factors = (n + 2).min_fac :: ((n + 2) / (n + 2).min_fac).factors

factors can be constructed inductively by extracting min_fac, for sufficiently large n.

theorem nat.​prime.​not_coprime_iff_dvd {m n : } :
¬m.coprime n ∃ (p : ), nat.prime p p m p n

theorem nat.​prime.​dvd_mul {p m n : } :
nat.prime p(p m * n p m p n)

theorem nat.​prime.​not_dvd_mul {p m n : } :
nat.prime p¬p m¬p n¬p m * n

theorem nat.​prime.​dvd_of_dvd_pow {p m n : } :
nat.prime pp m ^ np m

theorem nat.​prime.​pow_not_prime {x n : } :
2 n¬nat.prime (x ^ n)

theorem nat.​prime.​mul_eq_prime_pow_two_iff {x y p : } :
nat.prime px 1y 1(x * y = p ^ 2 x = p y = p)

theorem nat.​prime.​dvd_fact {n p : } :
nat.prime p(p n.fact p n)

theorem nat.​prime.​coprime_pow_of_not_dvd {p m a : } :
nat.prime p¬p aa.coprime (p ^ m)

theorem nat.​coprime_primes {p q : } :
nat.prime pnat.prime q(p.coprime q p q)

theorem nat.​coprime_pow_primes {p q : } (n m : ) :
nat.prime pnat.prime qp q(p ^ n).coprime (q ^ m)

theorem nat.​coprime_or_dvd_of_prime {p : } (pp : nat.prime p) (i : ) :
p.coprime i p i

theorem nat.​dvd_prime_pow {p : } (pp : nat.prime p) {m i : } :
i p ^ m ∃ (k : ) (H : k m), i = p ^ k

theorem nat.​eq_prime_pow_of_dvd_least_prime_pow {a p k : } :
nat.prime p¬a p ^ ka p ^ (k + 1)a = p ^ (k + 1)

If p is prime, and a doesn't divide p^k, but a does divide p^(k+1) then a = p^(k+1).

theorem nat.​mem_list_primes_of_dvd_prod {p : } (hp : nat.prime p) {l : list } :
(∀ (p : ), p lnat.prime p)p l.prodp l

theorem nat.​mem_factors_iff_dvd {n p : } :
0 < nnat.prime p(p n.factors p n)

theorem nat.​perm_of_prod_eq_prod {l₁ l₂ : list } :
l₁.prod = l₂.prod(∀ (p : ), p l₁nat.prime p)(∀ (p : ), p l₂nat.prime p)l₁ ~ l₂

theorem nat.​factors_unique {n : } {l : list } :
l.prod = n(∀ (p : ), p lnat.prime p)l ~ n.factors

theorem nat.​succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : } (p_prime : nat.prime p) {m n k l : } :
p ^ k mp ^ l np ^ (k + l + 1) m * np ^ (k + 1) m p ^ (l + 1) n

def nat.​primes  :
Type

The type of prime numbers

Equations
theorem nat.​primes.​coe_nat_inj (p q : nat.primes) :
p = qp = q

@[instance]
def nat.​monoid.​prime_pow {α : Type u_1} [monoid α] :

Equations