# Natural number multiplicity #

This file contains lemmas about the multiplicity function (the maximum prime power dividing a number) when applied to naturals, in particular calculating it for factorials and binomial coefficients.

## Multiplicity calculations #

• Nat.Prime.multiplicity_factorial: Legendre's Theorem. The multiplicity of p in n! is n / p + ... + n / p ^ b for any b such that n / p ^ (b + 1) = 0. See padicValNat_factorial for this result stated in the language of p-adic valuations and sub_one_mul_padicValNat_factorial for a related result.
• Nat.Prime.multiplicity_factorial_mul: The multiplicity of p in (p * n)! is n more than that of n!.
• Nat.Prime.multiplicity_choose: Kummer's Theorem. The multiplicity of p in n.choose k is the number of carries when k and n - k are added in base p. See padicValNat_choose for the same result but stated in the language of p-adic valuations and sub_one_mul_padicValNat_choose_eq_sub_sum_digits for a related result.

## Other declarations #

• Nat.multiplicity_eq_card_pow_dvd: The multiplicity of m in n is the number of positive natural numbers i such that m ^ i divides n.
• Nat.multiplicity_two_factorial_lt: The multiplicity of 2 in n! is strictly less than n.
• Nat.Prime.multiplicity_something: Specialization of multiplicity.something to a prime in the naturals. Avoids having to provide p ≠ 1 and other trivialities, along with translating between Prime and Nat.Prime.

## Tags #

theorem Nat.multiplicity_eq_card_pow_dvd {m : } {n : } {b : } (hm : m 1) (hn : 0 < n) (hb : Nat.log m n < b) :
= (Finset.filter (fun (i : ) => m ^ i n) (Finset.Ico 1 b)).card

The multiplicity of m in n is the number of positive natural numbers i such that m ^ i divides n. This set is expressed by filtering Ico 1 b where b is any bound greater than log m n.

theorem Nat.Prime.multiplicity_one {p : } (hp : ) :
= 0
theorem Nat.Prime.multiplicity_mul {p : } {m : } {n : } (hp : ) :
multiplicity p (m * n) = +
theorem Nat.Prime.multiplicity_pow {p : } {m : } {n : } (hp : ) :
multiplicity p (m ^ n) = n
theorem Nat.Prime.multiplicity_self {p : } (hp : ) :
= 1
theorem Nat.Prime.multiplicity_pow_self {p : } {n : } (hp : ) :
multiplicity p (p ^ n) = n
theorem Nat.Prime.multiplicity_factorial {p : } (hp : ) {n : } {b : } :
Nat.log p n < bmultiplicity p n.factorial = (∑ i, n / p ^ i)

Legendre's Theorem

The multiplicity of a prime in n! is the sum of the quotients n / p ^ i. This sum is expressed over the finset Ico 1 b where b is any bound greater than log p n.

theorem Nat.Prime.sub_one_mul_multiplicity_factorial {n : } {p : } (hp : ) :
(p - 1) * (multiplicity p n.factorial).get = n - (p.digits n).sum

For a prime number p, taking (p - 1) times the multiplicity of p in n! equals n minus the sum of base p digits of n.

theorem Nat.Prime.multiplicity_factorial_mul_succ {n : } {p : } (hp : ) :
multiplicity p (p * (n + 1)).factorial = multiplicity p (p * n).factorial + multiplicity p (n + 1) + 1

The multiplicity of p in (p * (n + 1))! is one more than the sum of the multiplicities of p in (p * n)! and n + 1.

theorem Nat.Prime.multiplicity_factorial_mul {n : } {p : } (hp : ) :
multiplicity p (p * n).factorial = multiplicity p n.factorial + n

The multiplicity of p in (p * n)! is n more than that of n!.

theorem Nat.Prime.pow_dvd_factorial_iff {p : } {n : } {r : } {b : } (hp : ) (hbn : Nat.log p n < b) :
p ^ r n.factorial r i, n / p ^ i

A prime power divides n! iff it is at most the sum of the quotients n / p ^ i. This sum is expressed over the set Ico 1 b where b is any bound greater than log p n

theorem Nat.Prime.multiplicity_factorial_le_div_pred {p : } (hp : ) (n : ) :
multiplicity p n.factorial (n / (p - 1))
theorem Nat.Prime.multiplicity_choose_aux {p : } {n : } {b : } {k : } (hp : ) (hkn : k n) :
i, n / p ^ i = i, k / p ^ i + i, (n - k) / p ^ i + (Finset.filter (fun (i : ) => p ^ i k % p ^ i + (n - k) % p ^ i) (Finset.Ico 1 b)).card
theorem Nat.Prime.multiplicity_choose' {p : } {n : } {k : } {b : } (hp : ) (hnb : Nat.log p (n + k) < b) :
multiplicity p ((n + k).choose k) = (Finset.filter (fun (i : ) => p ^ i k % p ^ i + n % p ^ i) (Finset.Ico 1 b)).card

The multiplicity of p in choose (n + k) k is the number of carries when k and n are added in base p. The set is expressed by filtering Ico 1 b where b is any bound greater than log p (n + k).

theorem Nat.Prime.multiplicity_choose {p : } {n : } {k : } {b : } (hp : ) (hkn : k n) (hnb : Nat.log p n < b) :
multiplicity p (n.choose k) = (Finset.filter (fun (i : ) => p ^ i k % p ^ i + (n - k) % p ^ i) (Finset.Ico 1 b)).card

The multiplicity of p in choose n k is the number of carries when k and n - k are added in base p. The set is expressed by filtering Ico 1 b where b is any bound greater than log p n.

theorem Nat.Prime.multiplicity_le_multiplicity_choose_add {p : } (hp : ) (n : ) (k : ) :
multiplicity p (n.choose k) +

A lower bound on the multiplicity of p in choose n k.

theorem Nat.Prime.multiplicity_choose_prime_pow_add_multiplicity {p : } {n : } {k : } (hp : ) (hkn : k p ^ n) (hk0 : k 0) :
multiplicity p ((p ^ n).choose k) + = n
theorem Nat.Prime.multiplicity_choose_prime_pow {p : } {n : } {k : } (hp : ) (hkn : k p ^ n) (hk0 : k 0) :
multiplicity p ((p ^ n).choose k) = (n - (multiplicity p k).get )
theorem Nat.Prime.dvd_choose_pow {p : } {n : } {k : } (hp : ) (hk : k 0) (hkp : k p ^ n) :
p (p ^ n).choose k
theorem Nat.Prime.dvd_choose_pow_iff {p : } {n : } {k : } (hp : ) :
p (p ^ n).choose k k 0 k p ^ n
theorem Nat.multiplicity_two_factorial_lt {n : } :
n 0multiplicity 2 n.factorial < n