# mathlibdocumentation

data.nat.multiplicity

# 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.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.
• nat.multiplicity_factorial_mul: The multiplicity of p in (p * n)! is n more than that of n!.
• nat.multiplicity_choose: The multiplicity of p in n.choose k is the number of carries when k andn - k are added in base p.

## 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 : n < b) :
n = ((finset.filter (λ (i : ), m ^ i n) 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 : nat.prime p) :
1 = 0
theorem nat.prime.multiplicity_mul {p m n : } (hp : nat.prime p) :
(m * n) = m + n
theorem nat.prime.multiplicity_pow {p m n : } (hp : nat.prime p) :
(m ^ n) = n m
theorem nat.prime.multiplicity_self {p : } (hp : nat.prime p) :
p = 1
theorem nat.prime.multiplicity_pow_self {p n : } (hp : nat.prime p) :
(p ^ n) = n
theorem nat.prime.multiplicity_factorial {p : } (hp : nat.prime p) {n b : } :
n < b = ((finset.Ico 1 b).sum (λ (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.multiplicity_factorial_mul_succ {n p : } (hp : nat.prime p) :
(p * (n + 1)).factorial = (p * n).factorial + (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 : nat.prime p) :
(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 : nat.prime p) (hbn : n < b) :
p ^ r n.factorial r b).sum (λ (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 : nat.prime p) (n : ) :
(n / (p - 1))
theorem nat.prime.multiplicity_choose_aux {p n b k : } (hp : nat.prime p) (hkn : k n) :
b).sum (λ (i : ), n / p ^ i) = b).sum (λ (i : ), k / p ^ i) + b).sum (λ (i : ), (n - k) / p ^ i) + (finset.filter (λ (i : ), p ^ i k % p ^ i + (n - k) % p ^ i) b)).card
theorem nat.prime.multiplicity_choose {p n k b : } (hp : nat.prime p) (hkn : k n) (hnb : n < b) :
(n.choose k) = ((finset.filter (λ (i : ), p ^ i k % p ^ i + (n - k) % p ^ i) 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 : nat.prime p) (n k : ) :
n (n.choose k) + k

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

theorem nat.prime.multiplicity_choose_prime_pow {p n k : } (hp : nat.prime p) (hkn : k p ^ n) (hk0 : 0 < k) :
((p ^ n).choose k) + k = n
theorem nat.multiplicity_two_factorial_lt {n : } (h : n 0) :
< n