# Documentation

Mathlib.Data.Nat.Choose.Sum

# Sums of binomial coefficients #

This file includes variants of the binomial theorem and other results on sums of binomial coefficients. Theorems whose proofs depend on such sums may also go in this file for import reasons.

theorem Commute.add_pow {R : Type u_1} [] {x : R} {y : R} (h : Commute x y) (n : ) :
(x + y) ^ n = Finset.sum (Finset.range (n + 1)) fun m => x ^ m * y ^ (n - m) * ↑()

A version of the binomial theorem for commuting elements in noncommutative semirings.

theorem Commute.add_pow' {R : Type u_1} [] {x : R} {y : R} (h : Commute x y) (n : ) :
(x + y) ^ n = Finset.sum () fun m => Nat.choose n m.fst (x ^ m.fst * y ^ m.snd)

A version of Commute.add_pow that avoids ℕ-subtraction by summing over the antidiagonal and also with the binomial coefficient applied via scalar action of ℕ.

theorem add_pow {R : Type u_1} [] (x : R) (y : R) (n : ) :
(x + y) ^ n = Finset.sum (Finset.range (n + 1)) fun m => x ^ m * y ^ (n - m) * ↑()

The binomial theorem

theorem Nat.sum_range_choose (n : ) :
(Finset.sum (Finset.range (n + 1)) fun m => ) = 2 ^ n

The sum of entries in a row of Pascal's triangle

theorem Nat.sum_range_choose_halfway (m : ) :
(Finset.sum (Finset.range (m + 1)) fun i => Nat.choose (2 * m + 1) i) = 4 ^ m
theorem Nat.choose_middle_le_pow (n : ) :
Nat.choose (2 * n + 1) n 4 ^ n
theorem Int.alternating_sum_range_choose {n : } :
(Finset.sum (Finset.range (n + 1)) fun m => (-1) ^ m * ↑()) = if n = 0 then 1 else 0
theorem Int.alternating_sum_range_choose_of_ne {n : } (h0 : n 0) :
(Finset.sum (Finset.range (n + 1)) fun m => (-1) ^ m * ↑()) = 0
theorem Finset.sum_powerset_apply_card {α : Type u_2} {β : Type u_3} [] (f : α) {x : } :
(Finset.sum () fun m => f ()) = Finset.sum (Finset.range ( + 1)) fun m => f m
theorem Finset.sum_powerset_neg_one_pow_card {α : Type u_2} [] {x : } :
(Finset.sum () fun m => (-1) ^ ) = if x = then 1 else 0
theorem Finset.sum_powerset_neg_one_pow_card_of_nonempty {α : Type u_2} {x : } (h0 : ) :
(Finset.sum () fun m => (-1) ^ ) = 0
theorem Finset.sum_choose_succ_nsmul {M : Type u_4} [] (f : M) (n : ) :
(Finset.sum (Finset.range (n + 2)) fun i => Nat.choose (n + 1) i f i (n + 1 - i)) = (Finset.sum (Finset.range (n + 1)) fun i => f i (n + 1 - i)) + Finset.sum (Finset.range (n + 1)) fun i => f (i + 1) (n - i)
theorem Finset.prod_pow_choose_succ {M : Type u_4} [] (f : M) (n : ) :
(Finset.prod (Finset.range (n + 2)) fun i => f i (n + 1 - i) ^ Nat.choose (n + 1) i) = (Finset.prod (Finset.range (n + 1)) fun i => f i (n + 1 - i) ^ ) * Finset.prod (Finset.range (n + 1)) fun i => f (i + 1) (n - i) ^
theorem Finset.sum_antidiagonal_choose_succ_nsmul {M : Type u_4} [] (f : M) (n : ) :
(Finset.sum (Finset.Nat.antidiagonal (n + 1)) fun ij => Nat.choose (n + 1) ij.fst f ij.fst ij.snd) = (Finset.sum () fun ij => Nat.choose n ij.fst f ij.fst (ij.snd + 1)) + Finset.sum () fun ij => Nat.choose n ij.snd f (ij.fst + 1) ij.snd
theorem Finset.prod_antidiagonal_pow_choose_succ {M : Type u_4} [] (f : M) (n : ) :
(Finset.prod (Finset.Nat.antidiagonal (n + 1)) fun ij => f ij.fst ij.snd ^ Nat.choose (n + 1) ij.fst) = (Finset.prod () fun ij => f ij.fst (ij.snd + 1) ^ Nat.choose n ij.fst) * Finset.prod () fun ij => f (ij.fst + 1) ij.snd ^ Nat.choose n ij.snd
theorem Finset.sum_choose_succ_mul {R : Type u_3} [] (f : R) (n : ) :
(Finset.sum (Finset.range (n + 2)) fun i => ↑(Nat.choose (n + 1) i) * f i (n + 1 - i)) = (Finset.sum (Finset.range (n + 1)) fun i => ↑() * f i (n + 1 - i)) + Finset.sum (Finset.range (n + 1)) fun i => ↑() * f (i + 1) (n - i)

The sum of (n+1).choose i * f i (n+1-i) can be split into two sums at rank n, respectively of n.choose i * f i (n+1-i) and n.choose i * f (i+1) (n-i).

theorem Finset.sum_antidiagonal_choose_succ_mul {R : Type u_3} [] (f : R) (n : ) :
(Finset.sum (Finset.Nat.antidiagonal (n + 1)) fun ij => ↑(Nat.choose (n + 1) ij.fst) * f ij.fst ij.snd) = (Finset.sum () fun ij => ↑(Nat.choose n ij.fst) * f ij.fst (ij.snd + 1)) + Finset.sum () fun ij => ↑(Nat.choose n ij.snd) * f (ij.fst + 1) ij.snd

The sum along the antidiagonal of (n+1).choose i * f i j can be split into two sums along the antidiagonal at rank n, respectively of n.choose i * f i (j+1) and n.choose j * f (i+1) j.