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.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
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.
Instances For
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.
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
- p.decidablePrime = decidable_of_iff' (2 ≤ p ∧ p.minFac = p) ⋯
Alias of the reverse direction of Nat.prime_iff
.
Alias of the forward direction of Nat.prime_iff
.
Equations
- Nat.Primes.instRepr = { reprPrec := fun (p : Nat.Primes) (x : ℕ) => repr ↑p }
Equations
- Nat.Primes.inhabitedPrimes = { default := ⟨2, Nat.prime_two⟩ }
Equations
- Nat.Primes.coeNat = { coe := Subtype.val }
Equations
- Nat.monoid.primePow = { pow := fun (x : α) (p : Nat.Primes) => x ^ ↑p }