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 numberp
is primeNat.Primes
: the subtype of natural numbers that are primeNat.minFac n
: the minimal prime factor of a natural numbern ≠ 1
Nat.exists_infinite_primes
: Euclid's theorem that there exist infinitely many prime numbers. This also appears asNat.not_bddAbove_setOf_prime
andNat.infinite_setOf_prime
(the latter inData.Nat.PrimeFin
).Nat.prime_iff
:Nat.Prime
coincides with the general definition ofPrime
Nat.irreducible_iff_nat_prime
: a non-unit natural number is only divisible by1
iff it is prime
Equations
This instance is slower than the instance decidablePrime
defined below,
but has the advantage that it works in the kernel for small values.
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
Instances For
Returns the smallest prime factor of n ≠ 1
.
Equations
- Nat.minFac n = if 2 ∣ n then 2 else Nat.minFacAux n 3
Instances For
This instance is faster in the virtual machine than decidablePrime1
,
but slower in the kernel.
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
- Nat.decidablePrime p = decidable_of_iff' (2 ≤ p ∧ Nat.minFac p = p) (_ : Nat.Prime p ↔ 2 ≤ p ∧ Nat.minFac p = p)
The square of the smallest prime factor of a composite number n
is at most n
.
A version of Nat.exists_infinite_primes
using the BddAbove
predicate.
Alias of the forward direction of Nat.prime_iff
.
Alias of the reverse direction of Nat.prime_iff
.
Equations
- Nat.Primes.instReprPrimes = { reprPrec := fun p x => repr ↑p }
Equations
- Nat.Primes.inhabitedPrimes = { default := { val := 2, property := Nat.prime_two } }
Equations
- Nat.Primes.coeNat = { coe := Subtype.val }