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 / V02. Numbers

Mathlib.Data.Nat.MaxPrimeFac

17 declarations. Mathlib docs · Source

Greatest prime factor of a natural number

This file defines Nat.maxPrimeFac, the greatest prime factor of a natural number greater than one, with explicit values at zero and one.

Implementation notes

The list n.primeFactorsList is empty exactly when n = 0 or n = 1. We choose the junk values maxPrimeFac 0 = 0 and maxPrimeFac 1 = 1 so that:

  • maxPrimeFac n ≤ n holds for all n. This forces maxPrimeFac 0 = 0.
  • maxPrimeFac n ∣ n holds for all n. This forces maxPrimeFac 1 = 1.

Choosing maxPrimeFac 1 = 0 instead would make IsLUB {p : ℕ | p.Prime ∧ p ∣ n} (maxPrimeFac n) (but not IsGreatest {p : ℕ | p.Prime ∧ p ∣ n} (maxPrimeFac n)) hold for all n ≠ 0 and would make maxPrimeFac_eq_sSup hold unconditionally thanks to the junk value sSup ∅ = 0 on ℕ.

def Nat.maxPrimeFac E1 #

ℕ → ℕ

The greatest prime divisor of a natural number n > 1.

At the exceptional inputs n = 0 and n = 1, it returns the explicit default n because n.primeFactorsList is empty.

theorem Nat.maxPrimeFac_zero E0 #

Nat.maxPrimeFac 0 = 0

theorem Nat.maxPrimeFac_one E0 #

Nat.maxPrimeFac 1 = 1

theorem Nat.prime_maxPrimeFac_of_one_lt E1 #

∀ {n : ℕ}, 1 < n → Nat.Prime n.maxPrimeFac

theorem Nat.maxPrimeFac_dvd E1 #

∀ {n : ℕ}, n.maxPrimeFac ∣ n

The greatest prime factor of a natural number divides it.

theorem Nat.le_maxPrimeFac E1 #

∀ {n p : ℕ}, n ≠ 0 → Nat.Prime p → p ∣ n → p ≤ n.maxPrimeFac

Every prime factor of a nonzero natural number is at most its greatest prime factor.

theorem Nat.isGreatest_maxPrimeFac E1 #

∀ {n : ℕ}, 1 < n → IsGreatest {p | Nat.Prime p ∧ p ∣ n} n.maxPrimeFac

The greatest prime factor of a natural number greater than one is the greatest of its prime factors.

theorem Nat.isLUB_maxPrimeFac E1 #

∀ {n : ℕ}, 1 < n → IsLUB {p | Nat.Prime p ∧ p ∣ n} n.maxPrimeFac

The greatest prime factor of a natural number greater than one is the least upper bound of its prime factors.

theorem Nat.maxPrimeFac_le_iff E0 #

∀ {m n : ℕ}, 1 < n → (n.maxPrimeFac ≤ m ↔ ∀ (p : ℕ), Nat.Prime p → p ∣ n → p ≤ m)

theorem Nat.one_le_maxPrimeFac_iff E0 #

∀ {n : ℕ}, 1 ≤ n.maxPrimeFac ↔ 1 ≤ n

theorem Nat.one_lt_maxPrimeFac_iff E0 #

∀ {n : ℕ}, 1 < n.maxPrimeFac ↔ 1 < n

theorem Nat.maxPrimeFac_mul E1 #

∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → (m * n).maxPrimeFac = max m.maxPrimeFac n.maxPrimeFac

The greatest prime factor of a product of nonzero natural numbers is the maximum of their greatest prime factors.

theorem Nat.maxPrimeFac_pow E0 #

∀ {k : ℕ}, k ≠ 0 → ∀ (n : ℕ), (n ^ k).maxPrimeFac = n.maxPrimeFac

The greatest prime factor of a power with nonzero exponent is the greatest prime factor of its base.

theorem Nat.Prime.maxPrimeFac_eq_self E0 #

∀ {p : ℕ}, Nat.Prime p → p.maxPrimeFac = p

The greatest prime factor of a prime is the prime itself.

theorem Nat.maxPrimeFac_eq_self_iff E0 #

∀ {n : ℕ}, n.maxPrimeFac = n ↔ n ≤ 1 ∨ Nat.Prime n

The fixed points of maxPrimeFac are zero, one, and the primes.

theorem Nat.maxPrimeFac_le E1 #

∀ {n : ℕ}, n.maxPrimeFac ≤ n

The greatest prime factor of a natural number is at most that number.

theorem Nat.maxPrimeFac_eq_sSup E1 #

∀ {n : ℕ}, n ≠ 1 → n.maxPrimeFac = sSup {p | Nat.Prime p ∧ p ∣ n}

Away from n = 1, the computable greatest prime factor agrees with its supremum characterization.