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 ≤ nholds for alln. This forcesmaxPrimeFac 0 = 0.maxPrimeFac n ∣ nholds for alln. This forcesmaxPrimeFac 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 ℕ.
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.
Equations
- n.maxPrimeFac = n.primeFactorsList.getLastD n
Instances For
The greatest prime factor of a natural number divides it.
Every prime factor of a nonzero natural number is at most its greatest prime factor.
The greatest prime factor of a natural number greater than one is the greatest of its prime factors.
The greatest prime factor of a product of nonzero natural numbers is the maximum of their greatest prime factors.
The greatest prime factor of a power with nonzero exponent is the greatest prime factor of its base.
The greatest prime factor of a prime is the prime itself.
The fixed points of maxPrimeFac are zero, one, and the primes.
The greatest prime factor of a natural number is at most that number.