Prime factorizations #
n.factorization
is the finitely supported function ℕ →₀ ℕ
mapping each prime factor of n
to its multiplicity in n
. For example, since 2000 = 2^4 * 5^3,
factorization 2000 2
is 4factorization 2000 5
is 3factorization 2000 k
is 0 for all otherk : ℕ
.
TODO #
-
As discussed in this Zulip thread: https://leanprover.zulipchat.com/#narrow/stream/217875/topic/Multiplicity.20in.20the.20naturals We have lots of disparate ways of talking about the multiplicity of a prime in a natural number, including
factors.count
,padic_val_nat
,multiplicity
, and the material indata/pnat/factors
. Move some of this material to this file, prove results about the relationships between these definitions, and (where appropriate) choose a uniform canonical way of expressing these ideas. -
Moreover, the results here should be generalised to an arbitrary unique factorization monoid with a normalization function, and then deduplicated. The basics of this have been started in
ring_theory/unique_factorization_domain
. -
Extend the inductions to any
normalization_monoid
with unique factorization.
n.factorization
is the finitely supported function ℕ →₀ ℕ
mapping each prime factor of n
to its multiplicity in n
.
Equations
Basic facts about factorization #
We can write both n.factorization p
and n.factors.count p
to represent the power
of p
in the factorization of n
: we declare the former to be the simp-normal form.
However, since factorization
is a finsupp it's noncomputable. This theorem can also
be used in reverse to compute values of factorization n p
when required.
Every nonzero natural number has a unique prime factorization
The support of n.factorization
is exactly n.factors.to_finset
The only numbers with empty prime factorization are 0
and 1
For nonzero a
and b
, the power of p
in a * b
is the sum of the powers in a
and b
For any p
, the power of p
in n^k
is k
times the power in n
The only prime factor of prime p
is p
itself, with multiplicity 1
For prime p
the only prime factor of p^k
is p
with multiplicity k
If the factorization of n
contains just one number p
then n
is a power of p
If a product over n.factorization
doesn't use the multiplicities of the prime factors
then it's equal to the corresponding product over n.factors.to_finset
For any p : ℕ
and any function g : α → ℕ
that's non-zero on S : finset α
,
the power of p
in S.prod g
equals the sum over x ∈ S
of the powers of p
in g x
.
Generalises factorization_mul
, which is the special case where S.card = 2
and g = id
.
Equivalence between ℕ+
and ℕ →₀ ℕ
with support in the primes. #
The equiv between ℕ+
and ℕ →₀ ℕ
with support in the primes.
Equations
- nat.factorization_equiv = {to_fun := λ (_x : ℕ+), nat.factorization_equiv._match_1 _x, inv_fun := λ (_x : ↥{f : ℕ →₀ ℕ | ∀ (p : ℕ), p ∈ f.support → nat.prime p}), nat.factorization_equiv._match_2 _x, left_inv := nat.factorization_equiv._proof_1, right_inv := nat.factorization_equiv._proof_2}
- nat.factorization_equiv._match_1 ⟨n, hn⟩ = ⟨n.factorization, _⟩
- nat.factorization_equiv._match_2 ⟨f, hf⟩ = ⟨f.prod pow, _⟩
Factorization and divisibility #
Factorization and coprimes #
For coprime a
and b
, the power of p
in a * b
is the sum of the powers in a
and b
For coprime a
and b
, the power of p
in a * b
is the sum of the powers in a
and b
If p
is a prime factor of a
then the power of p
in a
is the same that in a * b
,
for any b
coprime to a
.
If p
is a prime factor of b
then the power of p
in b
is the same that in a * b
,
for any a
coprime to b
.
The prime factorizations of coprime a
and b
are disjoint
For coprime a
and b
the prime factorization a * b
is the union of those of a
and b
Induction principles involving factorizations #
Given P 0, P 1
and a way to extend P a
to P (p ^ n * a)
for prime p
not dividing a
,
we can define P
for all natural numbers.
Equations
- nat.rec_on_prime_pow h0 h1 h = λ (a : ℕ), a.strong_rec_on (λ (n : ℕ), nat.rec_on_prime_pow._match_1 h0 h1 h n)
- nat.rec_on_prime_pow._match_1 h0 h1 h (k + 2) = λ (hk : Π (m : ℕ), m < k + 2 → P m), let p : ℕ := (k + 2).min_fac, t : ℕ := list.count p (k + 2).factors in _.mpr (h ((k + 2) / p ^ t) p t _ _ _ (hk ((k + 2) / p ^ t) _))
- nat.rec_on_prime_pow._match_1 h0 h1 h 1 = λ (_x : Π (m : ℕ), m < 1 → P m), h1
- nat.rec_on_prime_pow._match_1 h0 h1 h 0 = λ (_x : Π (m : ℕ), m < 0 → P m), h0
Given P 0
, P 1
, and P (p ^ n)
for positive prime powers, and a way to extend P a
and
P b
to P (a * b)
when a, b
are positive coprime, we can define P
for all natural numbers.
Given P 0
, P (p ^ n)
for all prime powers, and a way to extend P a
and P b
to
P (a * b)
when a, b
are positive coprime, we can define P
for all natural numbers.
Equations
- nat.rec_on_prime_coprime h0 hp h = nat.rec_on_pos_prime_pos_coprime (λ (p n : ℕ) (h : nat.prime p) (_x : 0 < n), hp p n h) h0 (hp 2 0 nat.prime_two) h
Given P 0
, P 1
, P p
for all primes, and a way to extend P a
and P b
to
P (a * b)
, we can define P
for all natural numbers.
Equations
- nat.rec_on_mul h0 h1 hp h = let hp : Π (p n : ℕ), nat.prime p → P (p ^ n) := λ (p n : ℕ) (hp' : nat.prime p), nat.rec_on_mul._match_1 h1 hp h p hp' n in nat.rec_on_prime_coprime h0 hp (λ (a b : ℕ) (_x : 1 < a) (_x : 1 < b) (_x : a.coprime b), h a b)
- nat.rec_on_mul._match_1 h1 hp h p hp' (n + 1) = h p (p ^ n.add 0) (hp p hp') (nat.rec_on_mul._match_1 h1 hp h p hp' n)
- nat.rec_on_mul._match_1 h1 hp h p hp' 0 = h1
For any multiplicative function f
with f 1 = 1
and any n ≠ 0
,
we can evaluate f n
by evaluating f
at p ^ k
over the factorization of n
For any multiplicative function f
with f 1 = 1
and f 0 = 1
,
we can evaluate f n
by evaluating f
at p ^ k
over the factorization of n