Lean / Reader
Lean reader

BinomialTail.lean

83 lines5 declarationsno sorryimports Std
  1. import Std
  2. /-! Integer identities for the greatest convex minorant of a binomial tail.
  3. The functions use only Pascal's recurrence and include every natural n,k. -/
  4. namespace BinomialTail
  5. def choose : Nat → Nat → Nat
  6. | 0, 0 => 1
  7. | 0, _ + 1 => 0
  8. | _ + 1, 0 => 1
  9. | n + 1, k + 1 => choose n k + choose n (k + 1)
  10. def sumThrough (n : Nat) : Nat → Nat
  11. | 0 => choose n 0
  12. | k + 1 => sumThrough n k + choose n (k + 1)
  13. theorem choose_zero (n : Nat) : choose n 0 = 1 := by
  14. cases n <;> rfl
  15. /-- After dividing by 2^(n+1), this is f(n) - f(n+1) = C(n,k)/2^(n+1). -/
  16. theorem first_difference (n k : Nat) :
  17. 2 * sumThrough n k = sumThrough (n + 1) k + choose n k := by
  18. induction k with
  19. | zero => simp [sumThrough, choose_zero]
  20. | succ k ih =>
  21. simp only [sumThrough, choose]
  22. omega
  23. /-- Division by natural factors is avoided, including at the endpoints. -/
  24. theorem successive_binomials (n k : Nat) :
  25. (n + 1) * choose n k = (n + 1 - k) * choose (n + 1) k := by
  26. induction n generalizing k with
  27. | zero =>
  28. cases k with
  29. | zero => decide
  30. | succ k => simp [choose]
  31. | succ n ih =>
  32. cases k with
  33. | zero => simp [choose_zero]
  34. | succ k =>
  35. by_cases hk : k ≤ n
  36. · have h1 := ih k
  37. have h2 := ih (k + 1)
  38. have hd1 : n + 1 - k = n - k + 1 := by omega
  39. have hd2 : n + 1 - (k + 1) = n - k := by omega
  40. have hd3 : n + 1 + 1 - (k + 1) = n - k + 1 := by omega
  41. rw [hd1] at h1
  42. rw [hd2] at h2
  43. rw [hd3]
  44. simp only [choose] at h2 ⊢
  45. grind
  46. · have hd : n + 1 + 1 - (k + 1) = 0 := by omega
  47. have h2 := ih (k + 1)
  48. have hd2 : n + 1 - (k + 1) = 0 := by omega
  49. rw [hd2, Nat.zero_mul] at h2
  50. have hz : choose n (k + 1) = 0 := by
  51. rcases Nat.mul_eq_zero.mp h2 with h | h
  52. · omega
  53. · exact h
  54. by_cases hkn : k = n + 1
  55. · subst k
  56. have h1 := ih (n + 1)
  57. simp at h1
  58. have hzero : choose n (n + 1) = 0 := by
  59. rcases Nat.mul_eq_zero.mp h1 with h | h
  60. · omega
  61. · exact h
  62. simp [choose, hz, hzero]
  63. · have h1 := ih k
  64. have hd1 : n + 1 - k = 0 := by omega
  65. rw [hd1, Nat.zero_mul] at h1
  66. have hzero : choose n k = 0 := by
  67. rcases Nat.mul_eq_zero.mp h1 with h | h
  68. · omega
  69. · exact h
  70. simp [choose, hz, hzero, hd]
  71. #print axioms first_difference
  72. #print axioms successive_binomials
  73. end BinomialTail