import Std /-! Integer identities for the greatest convex minorant of a binomial tail. The functions use only Pascal's recurrence and include every natural n,k. -/ namespace BinomialTail def choose : Nat → Nat → Nat | 0, 0 => 1 | 0, _ + 1 => 0 | _ + 1, 0 => 1 | n + 1, k + 1 => choose n k + choose n (k + 1) def sumThrough (n : Nat) : Nat → Nat | 0 => choose n 0 | k + 1 => sumThrough n k + choose n (k + 1) theorem choose_zero (n : Nat) : choose n 0 = 1 := by cases n <;> rfl /-- After dividing by 2^(n+1), this is f(n) - f(n+1) = C(n,k)/2^(n+1). -/ theorem first_difference (n k : Nat) : 2 * sumThrough n k = sumThrough (n + 1) k + choose n k := by induction k with | zero => simp [sumThrough, choose_zero] | succ k ih => simp only [sumThrough, choose] omega /-- Division by natural factors is avoided, including at the endpoints. -/ theorem successive_binomials (n k : Nat) : (n + 1) * choose n k = (n + 1 - k) * choose (n + 1) k := by induction n generalizing k with | zero => cases k with | zero => decide | succ k => simp [choose] | succ n ih => cases k with | zero => simp [choose_zero] | succ k => by_cases hk : k ≤ n · have h1 := ih k have h2 := ih (k + 1) have hd1 : n + 1 - k = n - k + 1 := by omega have hd2 : n + 1 - (k + 1) = n - k := by omega have hd3 : n + 1 + 1 - (k + 1) = n - k + 1 := by omega rw [hd1] at h1 rw [hd2] at h2 rw [hd3] simp only [choose] at h2 ⊢ grind · have hd : n + 1 + 1 - (k + 1) = 0 := by omega have h2 := ih (k + 1) have hd2 : n + 1 - (k + 1) = 0 := by omega rw [hd2, Nat.zero_mul] at h2 have hz : choose n (k + 1) = 0 := by rcases Nat.mul_eq_zero.mp h2 with h | h · omega · exact h by_cases hkn : k = n + 1 · subst k have h1 := ih (n + 1) simp at h1 have hzero : choose n (n + 1) = 0 := by rcases Nat.mul_eq_zero.mp h1 with h | h · omega · exact h simp [choose, hz, hzero] · have h1 := ih k have hd1 : n + 1 - k = 0 := by omega rw [hd1, Nat.zero_mul] at h1 have hzero : choose n k = 0 := by rcases Nat.mul_eq_zero.mp h1 with h | h · omega · exact h simp [choose, hz, hzero, hd] #print axioms first_difference #print axioms successive_binomials end BinomialTail