-- Mathlib/NumberTheory/BernoulliPolynomials.lean
theorem sum_bernoulli (n : ℕ) :
    (∑ k ∈ range (n + 1), ((n + 1).choose k : ℚ) • bernoulli k) = monomial n (n + 1 : ℚ)

Proof state:
n x✝¹ : ℕ
a✝¹ : x✝¹ ∈ range (n + 1)
x✝ : ℕ
a✝ : x✝ ∈ range (n + 1 - x✝¹)
⊢ x✝ ∈ range (n + 1 - x✝¹)

Tactic:
assumption

Result:
no goals

Proof state:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose x) = 0

Tactic:
rw [sum_bernoulli]

Result:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ (if n + 1 - x = 1 then 1 else 0) • (monomial x) ↑((n + 1).choose x) = 0

Proof state:
n : ℕ
⊢ ∀ x ∈ range n,
    (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose 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)))

Result:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
⊢ ∀ x ∈ range n,
    (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose x) = 0

Proof state:
n x : ℕ
H : x < n
⊢ ¬n + 1 - x = 1

Tactic:
rw [eq_comm]

Result:
n x : ℕ
H : x < n
⊢ ¬1 = n + 1 - x

Proof state:
n x : ℕ
H : x ∈ range n
⊢ ¬n + 1 - x = 1

Tactic:
rw [mem_range] at H

Result:
n x : ℕ
H : x < n
⊢ ¬n + 1 - x = 1

Proof state:
n : ℕ
⊢ ∑ k ∈ range (n + 1), ↑((n + 1).choose k) • bernoulli k = (monomial n) (↑n + 1)

Tactic:
simp_rw [bernoulli_def, Finset.smul_sum, Finset.range_eq_Ico, ← Finset.sum_Ico_Ico_comm,
  Finset.sum_Ico_eq_sum_range]

Result:
n : ℕ
⊢ ∑ k ∈ range (n + 1 - 0),
      ∑ k_1 ∈ range (n + 1 - (0 + k)),
        ↑((n + 1).choose (0 + k + k_1)) •
          (monomial (0 + k)) (_root_.bernoulli (0 + k + k_1 - (0 + k)) * ↑((0 + k + k_1).choose (0 + k))) =
    (monomial n) (↑n + 1)

Proof state:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
h₁ : n + 1 - x = 1
⊢ False

Tactic:
exact (f x hx) h₁

Result:
no goals

Proof state:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
⊢ ∀ x ∈ range n,
    (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose x) = 0

Tactic:
intro x hx

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

Proof state:
n : ℕ
f : ∀ 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) ↑((n + 1).choose x) = 0

Tactic:
rw [g, zero_smul]

Result:
no goals

Proof state:
n : ℕ
⊢ ∑ k ∈ range (n + 1 - 0),
      ∑ k_1 ∈ range (n + 1 - (0 + k)),
        ↑((n + 1).choose (0 + k + k_1)) •
          (monomial (0 + k)) (_root_.bernoulli (0 + k + k_1 - (0 + k)) * ↑((0 + k + k_1).choose (0 + k))) =
    (monomial n) (↑n + 1)

Tactic:
simp only [add_tsub_cancel_left, tsub_zero, zero_add, map_add]

Result:
n : ℕ
⊢ ∑ x ∈ range (n + 1),
      ∑ x_1 ∈ range (n + 1 - x),
        ↑((n + 1).choose (x + x_1)) • (monomial x) (_root_.bernoulli x_1 * ↑((x + x_1).choose x)) =
    (monomial n) ↑n + (monomial n) 1

Proof state:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ (if n + 1 - x = 1 then 1 else 0) • (monomial x) ↑((n + 1).choose 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₁

Result:
n : ℕ
f : ∀ 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) ↑((n + 1).choose x) = 0

Proof state:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ (if n + 1 - x = 1 then 1 else 0) = 0

Tactic:
simp only [ite_eq_right_iff, one_ne_zero]

Result:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ n + 1 - x = 1 → False

Proof state:
n : ℕ
⊢ ∑ x ∈ range (n + 1),
      ∑ x_1 ∈ range (n + 1 - x),
        ↑((n + 1).choose (x + x_1)) • (monomial x) (_root_.bernoulli x_1 * ↑((x + x_1).choose x)) =
    (monomial n) ↑n + (monomial n) 1

Tactic:
simp_rw [smul_monomial, mul_comm (_root_.bernoulli _) _, smul_eq_mul, ← mul_assoc]

Result:
n : ℕ
⊢ ∑ x ∈ range (n + 1),
      ∑ x_1 ∈ range (n + 1 - x),
        (monomial x) (↑((n + 1).choose (x + x_1)) * ↑((x + x_1).choose x) * _root_.bernoulli x_1) =
    (monomial n) ↑n + (monomial n) 1

Proof state:
n : ℕ
⊢ ∀ x ∈ range n, ¬n + 1 - x = 1

Tactic:
rintro x H

Result:
n x : ℕ
H : x ∈ range n
⊢ ¬n + 1 - x = 1

Proof state:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
⊢ n + 1 - x = 1 → False

Tactic:
intro h₁

Result:
n : ℕ
f : ∀ x ∈ range n, ¬n + 1 - x = 1
x : ℕ
hx : x ∈ range n
h₁ : n + 1 - x = 1
⊢ False

Proof state:
n x✝¹ : ℕ
a✝¹ : x✝¹ ∈ range (n + 1)
x✝ : ℕ
a✝ : x✝ ∈ range (n + 1 - x✝¹)
⊢ x✝¹ ∈ range (n + 1)

Tactic:
assumption

Result:
no goals

Proof state:
n : ℕ
⊢ (∑ i ∈ range (n + 1 - n), ↑((n + 1 - n).choose i) * _root_.bernoulli i) • (monomial n) ↑((n + 1).choose n) +
      ∑ x ∈ range n,
        (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose 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]

Result:
n : ℕ
⊢ ∑ x ∈ range n,
      (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose x) =
    0

Proof state:
n : ℕ
⊢ ∑ x ∈ range n,
      (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose x) =
    0

Tactic:
apply sum_eq_zero fun x hx => _

Result:
n : ℕ
⊢ ∀ x ∈ range n,
    (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose x) = 0

Proof state:
n x : ℕ
H : x < n
⊢ ¬1 = n + 1 - x

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)))

Result:
no goals

Proof state:
n : ℕ
⊢ ∑ x ∈ range (n + 1),
      (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose x) =
    (monomial n) ↑n + (monomial n) 1

Tactic:
rw [sum_range_succ_comm]

Result:
n : ℕ
⊢ (∑ i ∈ range (n + 1 - n), ↑((n + 1 - n).choose i) * _root_.bernoulli i) • (monomial n) ↑((n + 1).choose n) +
      ∑ x ∈ range n,
        (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose x) =
    (monomial n) ↑n + (monomial n) 1

Proof state:
n : ℕ
⊢ ∑ x ∈ range (n + 1),
      ∑ x_1 ∈ range (n + 1 - x), (↑((n + 1 - x).choose x_1) * _root_.bernoulli x_1) • (monomial x) ↑((n + 1).choose x) =
    (monomial n) ↑n + (monomial n) 1

Tactic:
simp_rw [← sum_smul]

Result:
n : ℕ
⊢ ∑ x ∈ range (n + 1),
      (∑ i ∈ range (n + 1 - x), ↑((n + 1 - x).choose i) * _root_.bernoulli i) • (monomial x) ↑((n + 1).choose x) =
    (monomial n) ↑n + (monomial n) 1