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.

Instances For
    theorem Nat.prime_zero_false :
    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.prime_one_false :
    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 {n : β„•} (h : Prime n) :
    n β‰  0
    theorem Nat.Prime.pos {p : β„•} (pp : Prime p) :
    0 < p
    theorem Nat.Prime.two_le {p : β„•} :
    Prime p β†’ 2 ≀ p
    theorem Nat.Prime.one_lt {p : β„•} :
    Prime p β†’ 1 < p
    theorem Nat.Prime.one_le {p : β„•} (hp : Prime 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 ∣ 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 {p : β„•} :
    Prime p ↔ 2 ≀ p ∧ βˆ€ m < p, m ∣ p β†’ m = 1
    theorem Nat.prime_def_lt' {p : β„•} :
    Prime p ↔ 2 ≀ p ∧ βˆ€ (m : β„•), 2 ≀ m β†’ m < p β†’ Β¬m ∣ p
    theorem Nat.prime_def_le_sqrt {p : β„•} :
    Prime p ↔ 2 ≀ p ∧ βˆ€ (m : β„•), 2 ≀ m β†’ m ≀ p.sqrt β†’ Β¬m ∣ p
    theorem Nat.prime_iff_not_exists_mul_eq {p : β„•} :
    Prime p ↔ 2 ≀ p ∧ Β¬βˆƒ (m : β„•) (n : β„•), m < p ∧ n < p ∧ m * n = p
    theorem Nat.prime_of_coprime (n : β„•) (h1 : 1 < n) (h : βˆ€ m < n, m β‰  0 β†’ n.Coprime m) :
    @[implicit_reducible]
    instance Nat.decidablePrime (p : β„•) :
    Decidable (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.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
    @[irreducible]
    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.

    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.

    Instances For
      def Nat.minFac (n : β„•) :
      β„•

      Returns the smallest prime factor of n β‰  1.

      Instances For
        theorem Nat.minFac_eq (n : β„•) :
        n.minFac = if 2 ∣ n then 2 else n.minFacAux 3
        @[irreducible]
        theorem Nat.minFacAux_has_prop {n : β„•} (n2 : 2 ≀ n) (k i : β„•) :
        k = 2 * i + 3 β†’ (βˆ€ (m : β„•), 2 ≀ m β†’ m ∣ n β†’ k ≀ m) β†’ Nat.minFacProp✝ n (n.minFacAux k)
        theorem Nat.minFac_has_prop {n : β„•} (n1 : n β‰  1) :
        theorem Nat.minFac_dvd (n : β„•) :
        n.minFac ∣ n
        theorem Nat.minFac_prime {n : β„•} (n1 : n β‰  1) :
        @[simp]
        theorem Nat.minFac_prime_iff {n : β„•} :
        Prime n.minFac ↔ n β‰  1
        theorem Nat.minFac_le_of_dvd {n m : β„•} :
        2 ≀ m β†’ m ∣ n β†’ n.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 p β†’ p ∣ n β†’ m ≀ p
        theorem Nat.le_minFac' {m n : β„•} :
        n = 1 ∨ m ≀ n.minFac ↔ βˆ€ (p : β„•), 2 ≀ p β†’ p ∣ n β†’ m ≀ p
        theorem Nat.prime_def_minFac {p : β„•} :
        Prime p ↔ 2 ≀ p ∧ p.minFac = p
        @[simp]
        theorem Nat.Prime.minFac_eq {p : β„•} (hp : Prime p) :
        p.minFac = p
        def Nat.decidablePrime' (p : β„•) :
        Decidable (Prime p)

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

        Instances For
          theorem Nat.not_prime_iff_minFac_lt {n : β„•} (n2 : 2 ≀ n) :
          Β¬Prime n ↔ n.minFac < 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) :
          βˆƒ (p : β„•), Prime p ∧ p ∣ n
          theorem Nat.coprime_of_dvd {m n : β„•} (H : βˆ€ (k : β„•), Prime k β†’ k ∣ m β†’ Β¬k ∣ n) :
          m.Coprime 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 Nat.Prime.dvd_or_dvd {p m n : β„•} (pp : Prime p) :
          p ∣ m * n β†’ p ∣ m ∨ p ∣ n

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

          theorem Nat.prime_iff {p : β„•} :
          Prime p ↔ _root_.Prime p
          theorem Prime.nat_prime {p : β„•} :
          Prime p β†’ Nat.Prime p

          Alias of the reverse direction of Nat.prime_iff.

          theorem Nat.Prime.prime {p : β„•} :
          Prime p β†’ _root_.Prime p

          Alias of the forward direction of Nat.prime_iff.

          @[implicit_reducible]
          @[implicit_reducible]

          The type of prime numbers

          Instances For
            @[implicit_reducible]
            instance Nat.instDecidableEqPrimes :
            DecidableEq Primes
            @[implicit_reducible]
            @[implicit_reducible]
            @[implicit_reducible]
            instance Nat.Primes.coeNat :
            Coe Primes β„•
            theorem Nat.Primes.coe_nat_injective :
            Function.Injective Subtype.val
            theorem Nat.Primes.coe_nat_inj (p q : Primes) :
            ↑p = ↑q ↔ p = q
            @[implicit_reducible]
            instance Nat.monoid.primePow {Ξ± : Type u_1} [Monoid Ξ±] :
            Pow Ξ± Primes