Theorem: Commute.add_pow
File: Mathlib/Data/Nat/Choose/Sum.lean

tactic: let t : ℕ → ℕ → R := fun n m ↦ x ^ m * y ^ (n - m) * choose n m
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n : ℕ
⊢ (x + y) ^ n = ∑ m in range (n + 1), x ^ m * y ^ (n - m) * ↑(Nat.choose n m)

tactic: change (x + y) ^ n = ∑ m in range (n + 1), t n m
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
⊢ (x + y) ^ n = ∑ m in range (n + 1), x ^ m * y ^ (n - m) * ↑(Nat.choose n m)

tactic: have h_first : ∀ n, t n 0 = y ^ n := fun n ↦ by
  simp only [choose_zero_right, _root_.pow_zero, Nat.cast_one, mul_one, one_mul, tsub_zero]
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
⊢ (x + y) ^ n = ∑ m in range (n + 1), t n m

tactic: have h_last : ∀ n, t n n.succ = 0 := fun n ↦ by
  simp only [ge_iff_le, choose_succ_self, cast_zero, mul_zero]
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
⊢ (x + y) ^ n = ∑ m in range (n + 1), t n m

tactic: induction' n with n ih
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
h_middle : ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)
⊢ (x + y) ^ n = ∑ m in range (n + 1), t n m

tactic: simp only [choose_zero_right, _root_.pow_zero, Nat.cast_one, mul_one, one_mul, tsub_zero]
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
n : ℕ
⊢ t n 0 = y ^ n

tactic: simp only [ge_iff_le, choose_succ_self, cast_zero, mul_zero]
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
n : ℕ
⊢ t n (succ n) = 0

tactic: intro n i h_mem
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
⊢ ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)

tactic: have h_le : i ≤ n := Nat.le_of_lt_succ (mem_range.mp h_mem)
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
⊢ (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)

tactic: dsimp only
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
h_le : i ≤ n
⊢ (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)

tactic: rw [Function.comp_apply, choose_succ_succ, Nat.cast_add, mul_add]
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
h_le : i ≤ n
⊢ ((fun m => x ^ m * y ^ (succ n - m) * ↑(Nat.choose (succ n) m)) ∘ succ) i =
    x * (x ^ i * y ^ (n - i) * ↑(Nat.choose n i)) + y * (x ^ succ i * y ^ (n - succ i) * ↑(Nat.choose n (succ i)))

tactic: congr 1
state_before: R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
h_le : i ≤ n
⊢ x ^ succ i * y ^ (succ n - succ i) * ↑(Nat.choose n i) +
      x ^ succ i * y ^ (succ n - succ i) * ↑(Nat.choose n (succ i)) =
    x * (x ^ i * y ^ (n - i) * ↑(Nat.choose n i)) + y * (x ^ succ i * y ^ (n - succ i) * ↑(Nat.choose n (succ i)))

tactic: rw [pow_succ x, succ_sub_succ, mul_assoc, mul_assoc, mul_assoc]
state_before: case e_a
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
h_le : i ≤ n
⊢ x ^ succ i * y ^ (succ n - succ i) * ↑(Nat.choose n i) = x * (x ^ i * y ^ (n - i) * ↑(Nat.choose n i))

tactic: rw [← mul_assoc y, ← mul_assoc y, (h.symm.pow_right i.succ).eq]
state_before: case e_a
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
h_le : i ≤ n
⊢ x ^ succ i * y ^ (succ n - succ i) * ↑(Nat.choose n (succ i)) =
    y * (x ^ succ i * y ^ (n - succ i) * ↑(Nat.choose n (succ i)))

tactic: by_cases h_eq : i = n
state_before: case e_a
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
h_le : i ≤ n
⊢ x ^ succ i * y ^ (succ n - succ i) * ↑(Nat.choose n (succ i)) =
    x ^ succ i * y * y ^ (n - succ i) * ↑(Nat.choose n (succ i))

tactic: rw [h_eq, choose_succ_self, Nat.cast_zero, mul_zero, mul_zero]
state_before: case pos
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
h_le : i ≤ n
h_eq : i = n
⊢ x ^ succ i * y ^ (succ n - succ i) * ↑(Nat.choose n (succ i)) =
    x ^ succ i * y * y ^ (n - succ i) * ↑(Nat.choose n (succ i))

tactic: rw [succ_sub (lt_of_le_of_ne h_le h_eq)]
state_before: case neg
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
h_le : i ≤ n
h_eq : ¬i = n
⊢ x ^ succ i * y ^ (succ n - succ i) * ↑(Nat.choose n (succ i)) =
    x ^ succ i * y * y ^ (n - succ i) * ↑(Nat.choose n (succ i))

tactic: rw [pow_succ y, mul_assoc, mul_assoc, mul_assoc, mul_assoc]
state_before: case neg
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
n✝ : ℕ
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
n i : ℕ
h_mem : i ∈ range (succ n)
h_le : i ≤ n
h_eq : ¬i = n
⊢ x ^ succ i * y ^ succ (n - succ i) * ↑(Nat.choose n (succ i)) =
    x ^ succ i * y * y ^ (n - succ i) * ↑(Nat.choose n (succ i))

tactic: rw [_root_.pow_zero, sum_range_succ, range_zero, sum_empty, zero_add]
state_before: case zero
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
h_middle : ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)
⊢ (x + y) ^ zero = ∑ m in range (zero + 1), t zero m

tactic: dsimp only
state_before: case zero
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
h_middle : ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)
⊢ 1 = t zero zero

tactic: rw [_root_.pow_zero, _root_.pow_zero, choose_self, Nat.cast_one, mul_one, mul_one]
state_before: case zero
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
h_middle : ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)
⊢ 1 = x ^ zero * y ^ (zero - zero) * ↑(Nat.choose zero zero)

tactic: rw [sum_range_succ', h_first]
state_before: case succ
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
h_middle : ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)
n : ℕ
ih : (x + y) ^ n = ∑ m in range (n + 1), t n m
⊢ (x + y) ^ succ n = ∑ m in range (succ n + 1), t (succ n) m

tactic: erw [sum_congr rfl (h_middle n), sum_add_distrib, add_assoc]
state_before: case succ
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
h_middle : ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)
n : ℕ
ih : (x + y) ^ n = ∑ m in range (n + 1), t n m
⊢ (x + y) ^ succ n = ∑ k in range (n + 1), t (succ n) (k + 1) + y ^ succ n

tactic: rw [pow_succ (x + y), ih, add_mul, mul_sum, mul_sum]
state_before: case succ
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
h_middle : ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)
n : ℕ
ih : (x + y) ^ n = ∑ m in range (n + 1), t n m
⊢ (x + y) ^ succ n = ∑ x_1 in range (succ n), x * t n x_1 + (∑ x in range (succ n), y * t n (succ x) + y ^ succ n)

tactic: congr 1
state_before: case succ
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
h_middle : ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)
n : ℕ
ih : (x + y) ^ n = ∑ m in range (n + 1), t n m
⊢ ∑ x_1 in range (n + 1), x * t n x_1 + ∑ x in range (n + 1), y * t n x =
    ∑ x_1 in range (succ n), x * t n x_1 + (∑ x in range (succ n), y * t n (succ x) + y ^ succ n)

tactic: rw [sum_range_succ', sum_range_succ, h_first, h_last, mul_zero, add_zero, _root_.pow_succ]
state_before: case succ.e_a
R : Type u_1
inst✝ : Semiring R
x y : R
h : Commute x y
t : ℕ → ℕ → R := fun n m => x ^ m * y ^ (n - m) * ↑(Nat.choose n m)
h_first : ∀ (n : ℕ), t n 0 = y ^ n
h_last : ∀ (n : ℕ), t n (succ n) = 0
h_middle : ∀ (n i : ℕ), i ∈ range (succ n) → (t (succ n) ∘ succ) i = x * t n i + y * t n (succ i)
n : ℕ
ih : (x + y) ^ n = ∑ m in range (n + 1), t n m
⊢ ∑ x in range (n + 1), y * t n x = ∑ x in range (succ n), y * t n (succ x) + y ^ succ n