Theorem: Polynomial.sum_bernoulli
File: Mathlib/NumberTheory/BernoulliPolynomials.lean

tactic: simp_rw [bernoulli_def, Finset.smul_sum, Finset.range_eq_Ico, ← Finset.sum_Ico_Ico_comm,
  Finset.sum_Ico_eq_sum_range]
state_before: n : ℕ
⊢ ∑ k in range (n + 1), ↑(Nat.choose (n + 1) k) • bernoulli k = ↑(monomial n) (↑n + 1)

tactic: simp only [add_tsub_cancel_left, tsub_zero, zero_add, map_add]
state_before: n : ℕ
⊢ ∑ k in range (n + 1 - 0),
      ∑ k_1 in range (n + 1 - (0 + k)),
        ↑(Nat.choose (n + 1) (0 + k + k_1)) •
          ↑(monomial (0 + k)) (_root_.bernoulli (0 + k + k_1 - (0 + k)) * ↑(Nat.choose (0 + k + k_1) (0 + k))) =
    ↑(monomial n) (↑n + 1)

tactic: simp_rw [smul_monomial, mul_comm (_root_.bernoulli _) _, smul_eq_mul, ← mul_assoc]
state_before: n : ℕ
⊢ ∑ x in range (n + 1),
      ∑ x_1 in range (n + 1 - x),
        ↑(Nat.choose (n + 1) (x + x_1)) • ↑(monomial x) (_root_.bernoulli x_1 * ↑(Nat.choose (x + x_1) x)) =
    ↑(monomial n) ↑n + ↑(monomial n) 1

tactic: conv_lhs =>
  apply_congr
  . skip
  . conv =>
    apply_congr
    . skip
    . rw [← Nat.cast_mul, choose_mul ((le_tsub_iff_left <| mem_range_le (by assumption)).1 <|
          mem_range_le (by assumption)) (le.intro rfl),
        Nat.cast_mul, add_tsub_cancel_left, mul_assoc, mul_comm, ← smul_eq_mul, ←
        smul_monomial]
state_before: n : ℕ
⊢ ∑ x in range (n + 1),
      ∑ x_1 in range (n + 1 - x),
        ↑(monomial x) (↑(Nat.choose (n + 1) (x + x_1)) * ↑(Nat.choose (x + x_1) x) * _root_.bernoulli x_1) =
    ↑(monomial n) ↑n + ↑(monomial n) 1

tactic: simp_rw [← sum_smul]
state_before: n : ℕ
⊢ ∑ x in range (n + 1),
      ∑ x_1 in range (n + 1 - x),
        (↑(Nat.choose (n + 1 - x) x_1) * _root_.bernoulli x_1) • ↑(monomial x) ↑(Nat.choose (n + 1) x) =
    ↑(monomial n) ↑n + ↑(monomial n) 1

tactic: rw [sum_range_succ_comm]
state_before: n : ℕ
⊢ ∑ x in range (n + 1),
      (∑ i in range (n + 1 - x), ↑(Nat.choose (n + 1 - x) i) * _root_.bernoulli i) •
        ↑(monomial x) ↑(Nat.choose (n + 1) x) =
    ↑(monomial n) ↑n + ↑(monomial n) 1

tactic: simp only [add_right_eq_self, mul_one, cast_one, cast_add, add_tsub_cancel_left,
  choose_succ_self_right, one_smul, _root_.bernoulli_zero, sum_singleton, zero_add,
  map_add, range_one, bernoulli_zero, mul_one, one_mul, add_zero, choose_self]
state_before: n : ℕ
⊢ (∑ i in range (n + 1 - n), ↑(Nat.choose (n + 1 - n) i) * _root_.bernoulli i) • ↑(monomial n) ↑(Nat.choose (n + 1) n) +
      ∑ x in range n,
        (∑ i in range (n + 1 - x), ↑(Nat.choose (n + 1 - x) i) * _root_.bernoulli i) •
          ↑(monomial x) ↑(Nat.choose (n + 1) x) =
    ↑(monomial n) ↑n + ↑(monomial n) 1

tactic: apply sum_eq_zero fun x hx => _
state_before: n : ℕ
⊢ ∑ x in range n,
      (∑ i in range (n + 1 - x), ↑(Nat.choose (n + 1 - x) i) * _root_.bernoulli i) •
        ↑(monomial x) ↑(Nat.choose (n + 1) x) =
    0

tactic: have f : ∀ x ∈ range n, ¬n + 1 - x = 1 := by
  rintro x H
  rw [mem_range] at H
  rw [eq_comm]
  exact _root_.ne_of_lt (Nat.lt_of_lt_of_le one_lt_two (le_tsub_of_add_le_left (succ_le_succ H)))
state_before: n : ℕ
⊢ ∀ (x : ℕ),
    x ∈ range n →
      (∑ i in range (n + 1 - x), ↑(Nat.choose (n + 1 - x) i) * _root_.bernoulli i) •
          ↑(monomial x) ↑(Nat.choose (n + 1) x) =
        0

tactic: intro x hx
state_before: n : ℕ
f : ∀ (x : ℕ), x ∈ range n → ¬n + 1 - x = 1
⊢ ∀ (x : ℕ),
    x ∈ range n →
      (∑ i in range (n + 1 - x), ↑(Nat.choose (n + 1 - x) i) * _root_.bernoulli i) •
          ↑(monomial x) ↑(Nat.choose (n + 1) x) =
        0

tactic: rw [sum_bernoulli]
state_before: n : ℕ
f : ∀ (x : ℕ), x ∈ range n → ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ (∑ i in range (n + 1 - x), ↑(Nat.choose (n + 1 - x) i) * _root_.bernoulli i) • ↑(monomial x) ↑(Nat.choose (n + 1) x) =
    0

tactic: have g : ite (n + 1 - x = 1) (1 : ℚ) 0 = 0 := by
  simp only [ite_eq_right_iff, one_ne_zero]
  intro h₁
  exact (f x hx) h₁
state_before: n : ℕ
f : ∀ (x : ℕ), x ∈ range n → ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ (if n + 1 - x = 1 then 1 else 0) • ↑(monomial x) ↑(Nat.choose (n + 1) x) = 0

tactic: rw [g, zero_smul]
state_before: n : ℕ
f : ∀ (x : ℕ), x ∈ range n → ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
g : (if n + 1 - x = 1 then 1 else 0) = 0
⊢ (if n + 1 - x = 1 then 1 else 0) • ↑(monomial x) ↑(Nat.choose (n + 1) x) = 0

tactic: assumption
state_before: n x✝¹ : ℕ
a✝¹ : x✝¹ ∈ range (n + 1)
x✝ : ℕ
a✝ : x✝ ∈ range (n + 1 - x✝¹)
⊢ x✝¹ ∈ range (n + 1)

tactic: assumption
state_before: n x✝¹ : ℕ
a✝¹ : x✝¹ ∈ range (n + 1)
x✝ : ℕ
a✝ : x✝ ∈ range (n + 1 - x✝¹)
⊢ x✝ ∈ range (n + 1 - x✝¹)

tactic: rintro x H
state_before: n : ℕ
⊢ ∀ (x : ℕ), x ∈ range n → ¬n + 1 - x = 1

tactic: rw [mem_range] at H
state_before: n x : ℕ
H : x ∈ range n
⊢ ¬n + 1 - x = 1

tactic: rw [eq_comm]
state_before: n x : ℕ
H : x < n
⊢ ¬n + 1 - x = 1

tactic: exact _root_.ne_of_lt (Nat.lt_of_lt_of_le one_lt_two (le_tsub_of_add_le_left (succ_le_succ H)))
state_before: n x : ℕ
H : x < n
⊢ ¬1 = n + 1 - x

tactic: simp only [ite_eq_right_iff, one_ne_zero]
state_before: n : ℕ
f : ∀ (x : ℕ), x ∈ range n → ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ (if n + 1 - x = 1 then 1 else 0) = 0

tactic: intro h₁
state_before: n : ℕ
f : ∀ (x : ℕ), x ∈ range n → ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ n + 1 - x = 1 → False

tactic: exact (f x hx) h₁
state_before: n : ℕ
f : ∀ (x : ℕ), x ∈ range n → ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
h₁ : n + 1 - x = 1
⊢ False