The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V12. Number theory

Mathlib.NumberTheory.SmoothNumbers

56 declarations. Mathlib docs · Source

Smooth numbers

For s : Finset ℕ we define the set Nat.factoredNumbers s of "s-factored numbers" consisting of the positive natural numbers all of whose prime factors are in s, and we provide some API for this.

We then define the set Nat.smoothNumbers n consisting of the positive natural numbers all of whose prime factors are strictly less than n. This is the special case s = Finset.range n of the set of s-factored numbers.

The main definition Nat.equivProdNatSmoothNumbers establishes the bijection between ℕ × (smoothNumbers p) and smoothNumbers (p+1) given by sending (e, n) to p^e * n. Here p is a prime number. It is obtained from the more general bijection between ℕ × (factoredNumbers s) and factoredNumbers (s ∪ {p}); see Nat.equivProdNatFactoredNumbers.

Additionally, we define Nat.smoothNumbersUpTo N n as the Finset of n-smooth numbers up to and including N, and similarly Nat.roughNumbersUpTo for its complement in {1, ..., N}, and we provide some API, in particular bounds for their cardinalities; see Nat.smoothNumbersUpTo_card_le and Nat.roughNumbersUpTo_card_le.

s-factored numbers

n-smooth numbers

Smooth and rough numbers up to a bound

We consider the sets of smooth and non-smooth ("rough") positive natural numbers ≤ N and prove bounds for their sizes.

def Nat.factoredNumbers E1 #

Finset ℕ → Set ℕ

factoredNumbers s, for a finite set s of natural numbers, is the set of positive natural numbers all of whose prime factors are in s.

theorem Nat.mem_factoredNumbers E0 #

∀ {s : Finset ℕ} {m : ℕ}, m ∈ Nat.factoredNumbers s ↔ m ≠ 0 ∧ ∀ p ∈ m.primeFactorsList, p ∈ s

instance Nat.instDecidablePredMemSetFactoredNumbers E0 #

(s : Finset ℕ) → DecidablePred fun x ↦ x ∈ Nat.factoredNumbers s

Membership in Nat.factoredNumbers n is decidable.

theorem Nat.mem_factoredNumbers_of_dvd E0 #

∀ {s : Finset ℕ} {m k : ℕ}, m ∈ Nat.factoredNumbers s → k ∣ m → k ∈ Nat.factoredNumbers s

A number that divides an s-factored number is itself s-factored.

theorem Nat.mem_factoredNumbers_iff_forall_le E0 #

∀ {s : Finset ℕ} {m : ℕ}, m ∈ Nat.factoredNumbers s ↔ m ≠ 0 ∧ ∀ p ≤ m, Nat.Prime p → p ∣ m → p ∈ s

m is s-factored if and only if m is nonzero and all prime divisors ≤ m of m are in s.

theorem Nat.mem_factoredNumbers' E0 #

∀ {s : Finset ℕ} {m : ℕ}, m ∈ Nat.factoredNumbers s ↔ ∀ (p : ℕ), Nat.Prime p → p ∣ m → p ∈ s

m is s-factored if and only if all prime divisors of m are in s.

theorem Nat.ne_zero_of_mem_factoredNumbers E1 #

∀ {s : Finset ℕ} {m : ℕ}, m ∈ Nat.factoredNumbers s → m ≠ 0

theorem Nat.primeFactors_subset_of_mem_factoredNumbers E1 #

∀ {s : Finset ℕ} {m : ℕ}, m ∈ Nat.factoredNumbers s → m.primeFactors ⊆ s

The Finset of prime factors of an s-factored number is contained in s.

theorem Nat.mem_factoredNumbers_of_primeFactors_subset E0 #

∀ {s : Finset ℕ} {m : ℕ}, m ≠ 0 → m.primeFactors ⊆ s → m ∈ Nat.factoredNumbers s

If m ≠ 0 and the Finset of prime factors of m is contained in s, then m is s-factored.

theorem Nat.mem_factoredNumbers_iff_primeFactors_subset E0 #

∀ {s : Finset ℕ} {m : ℕ}, m ∈ Nat.factoredNumbers s ↔ m ≠ 0 ∧ m.primeFactors ⊆ s

m is s-factored if and only if m ≠ 0 and its Finset of prime factors is contained in s.

theorem Nat.factoredNumbers_empty E0 #

Nat.factoredNumbers ∅ = {1}

theorem Nat.mul_mem_factoredNumbers E1 #

∀ {s : Finset ℕ} {m n : ℕ}, m ∈ Nat.factoredNumbers s → n ∈ Nat.factoredNumbers s → m * n ∈ Nat.factoredNumbers s

The product of two s-factored numbers is again s-factored.

theorem Nat.prod_mem_factoredNumbers E1 #

∀ (s : Finset ℕ) (n : ℕ), (List.filter (fun x ↦ decide (x ∈ s)) n.primeFactorsList).prod ∈ Nat.factoredNumbers s

The product of the prime factors of n that are in s is an s-factored number.

theorem Nat.factoredNumbers_insert E1 #

∀ (s : Finset ℕ) {N : ℕ}, ¬Nat.Prime N → Nat.factoredNumbers (insert N s) = Nat.factoredNumbers s

The sets of s-factored and of s ∪ {N}-factored numbers are the same when N is not prime. See Nat.equivProdNatFactoredNumbers for when N is prime.

theorem Nat.factoredNumbers_mono E1 #

∀ {s t : Finset ℕ}, s ⊆ t → Nat.factoredNumbers s ⊆ Nat.factoredNumbers t

theorem Nat.factoredNumbers_compl E1 #

∀ {N : ℕ} {s : Finset ℕ}, N.primesBelow ⊆ s → (Nat.factoredNumbers s)ᶜ \ {0} ⊆ {n | N ≤ n}

The non-zero non-s-factored numbers are ≥ N when s contains all primes less than N.

theorem Nat.pow_mul_mem_factoredNumbers E1 #

∀ {s : Finset ℕ} {p n : ℕ},
  Nat.Prime p → ∀ (e : ℕ), n ∈ Nat.factoredNumbers s → p ^ e * n ∈ Nat.factoredNumbers (insert p s)

If p is a prime and n is s-factored, then every product p^e * n is s ∪ {p}-factored.

theorem Nat.Prime.factoredNumbers_coprime E1 #

∀ {s : Finset ℕ} {p n : ℕ}, Nat.Prime p → p ∉ s → n ∈ Nat.factoredNumbers s → p.Coprime n

If p ∉ s is a prime and n is s-factored, then p and n are coprime.

theorem Nat.factoredNumbers.map_prime_pow_mul E0 #

∀ {F : Type u_1} [inst : Mul F] {f : ℕ → F},
  (∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n) →
    ∀ {s : Finset ℕ} {p : ℕ},
      Nat.Prime p → p ∉ s → ∀ (e : ℕ) {m : ↑(Nat.factoredNumbers s)}, f (p ^ e * ↑m) = f (p ^ e) * f ↑m

If f : ℕ → F is multiplicative on coprime arguments, p ∉ s is a prime and m is s-factored, then f (p^e * m) = f (p^e) * f m.

def Nat.equivProdNatFactoredNumbers E1 #

{s : Finset ℕ} → {p : ℕ} → Nat.Prime p → p ∉ s → ℕ × ↑(Nat.factoredNumbers s) ≃ ↑(Nat.factoredNumbers (insert p s))

We establish the bijection from ℕ × factoredNumbers s to factoredNumbers (s ∪ {p}) given by (e, n) ↦ p^e * n when p ∉ s is a prime. See Nat.factoredNumbers_insert for when p is not prime.

theorem Nat.equivProdNatFactoredNumbers_apply E0 #

∀ {s : Finset ℕ} {p e m : ℕ} (hp : Nat.Prime p) (hs : p ∉ s) (hm : m ∈ Nat.factoredNumbers s),
  ↑((Nat.equivProdNatFactoredNumbers hp hs) (e, ⟨m, hm⟩)) = p ^ e * m

theorem Nat.equivProdNatFactoredNumbers_apply' E0 #

∀ {s : Finset ℕ} {p : ℕ} (hp : Nat.Prime p) (hs : p ∉ s) (x : ℕ × ↑(Nat.factoredNumbers s)),
  ↑((Nat.equivProdNatFactoredNumbers hp hs) x) = p ^ x.1 * ↑x.2

def Nat.smoothNumbers E1 #

ℕ → Set ℕ

smoothNumbers n is the set of n-smooth positive natural numbers, i.e., the positive natural numbers all of whose prime factors are less than n.

theorem Nat.mem_smoothNumbers E0 #

∀ {n m : ℕ}, m ∈ n.smoothNumbers ↔ m ≠ 0 ∧ ∀ p ∈ m.primeFactorsList, p < n

theorem Nat.smoothNumbers_eq_factoredNumbers E1 #

∀ (n : ℕ), n.smoothNumbers = Nat.factoredNumbers (Finset.range n)

The n-smooth numbers agree with the Finset.range n-factored numbers.

theorem Nat.smoothNumbers_eq_factoredNumbers_primesBelow E1 #

∀ (n : ℕ), n.smoothNumbers = Nat.factoredNumbers n.primesBelow

The n-smooth numbers agree with the primesBelow n-factored numbers.

instance Nat.instDecidablePredMemSetSmoothNumbers E0 #

(n : ℕ) → DecidablePred fun x ↦ x ∈ n.smoothNumbers

Membership in Nat.smoothNumbers n is decidable.

theorem Nat.mem_smoothNumbers_of_dvd E0 #

∀ {n m k : ℕ}, m ∈ n.smoothNumbers → k ∣ m → k ∈ n.smoothNumbers

A number that divides an n-smooth number is itself n-smooth.

theorem Nat.mem_smoothNumbers_iff_forall_le E0 #

∀ {n m : ℕ}, m ∈ n.smoothNumbers ↔ m ≠ 0 ∧ ∀ p ≤ m, Nat.Prime p → p ∣ m → p < n

m is n-smooth if and only if m is nonzero and all prime divisors ≤ m of m are less than n.

theorem Nat.mem_smoothNumbers' E0 #

∀ {n m : ℕ}, m ∈ n.smoothNumbers ↔ ∀ (p : ℕ), Nat.Prime p → p ∣ m → p < n

m is n-smooth if and only if all prime divisors of m are less than n.

theorem Nat.primeFactors_subset_of_mem_smoothNumbers E1 #

∀ {m n : ℕ}, m ∈ n.smoothNumbers → m.primeFactors ⊆ n.primesBelow

The Finset of prime factors of an n-smooth number is contained in the Finset of primes below n.

theorem Nat.mem_smoothNumbers_of_primeFactors_subset E0 #

∀ {m n : ℕ}, m ≠ 0 → m.primeFactors ⊆ Finset.range n → m ∈ n.smoothNumbers

m is an n-smooth number if the Finset of its prime factors consists of numbers < n.

theorem Nat.mem_smoothNumbers_iff_primeFactors_subset E0 #

∀ {m n : ℕ}, m ∈ n.smoothNumbers ↔ m ≠ 0 ∧ m.primeFactors ⊆ n.primesBelow

m is an n-smooth number if and only if m ≠ 0 and the Finset of its prime factors is contained in the Finset of primes below n

theorem Nat.ne_zero_of_mem_smoothNumbers E1 #

∀ {n m : ℕ}, m ∈ n.smoothNumbers → m ≠ 0

Zero is never a smooth number

theorem Nat.smoothNumbers_zero E0 #

Nat.smoothNumbers 0 = {1}

theorem Nat.mul_mem_smoothNumbers E1 #

∀ {m₁ m₂ n : ℕ}, m₁ ∈ n.smoothNumbers → m₂ ∈ n.smoothNumbers → m₁ * m₂ ∈ n.smoothNumbers

The product of two n-smooth numbers is an n-smooth number.

theorem Nat.prod_mem_smoothNumbers E1 #

∀ (n N : ℕ), (List.filter (fun x ↦ decide (x < N)) n.primeFactorsList).prod ∈ N.smoothNumbers

The product of the prime factors of n that are less than N is an N-smooth number.

theorem Nat.smoothNumbers_succ E1 #

∀ {N : ℕ}, ¬Nat.Prime N → (N + 1).smoothNumbers = N.smoothNumbers

The sets of N-smooth and of (N+1)-smooth numbers are the same when N is not prime. See Nat.equivProdNatSmoothNumbers for when N is prime.

theorem Nat.smoothNumbers_one E0 #

Nat.smoothNumbers 1 = {1}

theorem Nat.smoothNumbers_mono E1 #

∀ {N M : ℕ}, N ≤ M → N.smoothNumbers ⊆ M.smoothNumbers

theorem Nat.mem_smoothNumbers_of_lt E0 #

∀ {m n : ℕ}, 0 < m → m < n → m ∈ n.smoothNumbers

All m, 0 < m < n are n-smooth numbers

theorem Nat.smoothNumbers_compl E1 #

∀ (N : ℕ), N.smoothNumbersᶜ \ {0} ⊆ {n | N ≤ n}

The non-zero non-N-smooth numbers are ≥ N.

theorem Nat.pow_mul_mem_smoothNumbers E1 #

∀ {p n : ℕ}, p ≠ 0 → ∀ (e : ℕ), n ∈ p.smoothNumbers → p ^ e * n ∈ p.succ.smoothNumbers

If p is positive and n is p-smooth, then every product p^e * n is (p+1)-smooth.

theorem Nat.Prime.smoothNumbers_coprime E1 #

∀ {p n : ℕ}, Nat.Prime p → n ∈ p.smoothNumbers → p.Coprime n

If p is a prime and n is p-smooth, then p and n are coprime.

theorem Nat.map_prime_pow_mul E0 #

∀ {F : Type u_1} [inst : Mul F] {f : ℕ → F},
  (∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n) →
    ∀ {p : ℕ}, Nat.Prime p → ∀ (e : ℕ) {m : ↑p.smoothNumbers}, f (p ^ e * ↑m) = f (p ^ e) * f ↑m

If f : ℕ → F is multiplicative on coprime arguments, p is a prime and m is p-smooth, then f (p^e * m) = f (p^e) * f m.

def Nat.equivProdNatSmoothNumbers E1 #

{p : ℕ} → Nat.Prime p → ℕ × ↑p.smoothNumbers ≃ ↑(p + 1).smoothNumbers

We establish the bijection from ℕ × smoothNumbers p to smoothNumbers (p+1) given by (e, n) ↦ p^e * n when p is a prime. See Nat.smoothNumbers_succ for when p is not prime.

theorem Nat.equivProdNatSmoothNumbers_apply E0 #

∀ {p e m : ℕ} (hp : Nat.Prime p) (hm : m ∈ p.smoothNumbers),
  ↑((Nat.equivProdNatSmoothNumbers hp) (e, ⟨m, hm⟩)) = p ^ e * m

theorem Nat.equivProdNatSmoothNumbers_apply' E0 #

∀ {p : ℕ} (hp : Nat.Prime p) (x : ℕ × ↑p.smoothNumbers), ↑((Nat.equivProdNatSmoothNumbers hp) x) = p ^ x.1 * ↑x.2

def Nat.smoothNumbersUpTo E1 #

ℕ → ℕ → Finset ℕ

The k-smooth numbers up to and including N as a Finset

theorem Nat.mem_smoothNumbersUpTo E0 #

∀ {N k n : ℕ}, n ∈ N.smoothNumbersUpTo k ↔ n ≤ N ∧ n ∈ k.smoothNumbers

def Nat.roughNumbersUpTo E1 #

ℕ → ℕ → Finset ℕ

The positive non-k-smooth (so "k-rough") numbers up to and including N as a Finset

theorem Nat.smoothNumbersUpTo_card_add_roughNumbersUpTo_card E1 #

∀ (N k : ℕ), (N.smoothNumbersUpTo k).card + (N.roughNumbersUpTo k).card = N

theorem Nat.smoothNumbersUpTo_subset_image E1 #

∀ (N k : ℕ),
  N.smoothNumbersUpTo k ⊆
    Finset.image
      (fun x ↦
        match x with
        | (s, m) => m ^ 2 * s.prod id)
      (k.primesBelow.powerset ×ˢ (Finset.range (N.sqrt + 1)).erase 0)

The set of k-smooth numbers ≤ N is contained in the set of numbers of the form m^2 * P, where m ≤ √N and P is a product of distinct primes < k.

theorem Nat.smoothNumbersUpTo_card_le E1 #

∀ (N k : ℕ), (N.smoothNumbersUpTo k).card ≤ 2 ^ k.primesBelow.card * N.sqrt

The cardinality of the set of k-smooth numbers ≤ N is bounded by 2^π(k-1) * √N.

theorem Nat.roughNumbersUpTo_eq_biUnion E1 #

∀ (N k : ℕ),
  N.roughNumbersUpTo k =
    ((N + 1).primesBelow \ k.primesBelow).biUnion fun p ↦ {m ∈ Finset.range (N + 1) | m ≠ 0 ∧ p ∣ m}

The set of k-rough numbers ≤ N can be written as the union of the sets of multiples ≤ N of primes k ≤ p ≤ N.

theorem Nat.roughNumbersUpTo_card_le E1 #

∀ (N k : ℕ), (N.roughNumbersUpTo k).card ≤ ∑ p ∈ (N + 1).primesBelow \ k.primesBelow, N / p

The cardinality of the set of k-rough numbers ≤ N is bounded by the sum of ⌊N/p⌋ over the primes k ≤ p ≤ N.