l3lab/ntp-mathlib huggingface dataset:
/-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/
protected theorem Commute.geom_sum₂_mul_add {x y : α} (h : Commute x y) (n : ℕ) :
    (∑ i in range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := by
  let f :  ℕ → ℕ → α := fun m i : ℕ => (x + y) ^ i * y ^ (m - 1 - i)
  -- porting note: adding `hf` here, because below in two places `dsimp [f]` didn't work
  have hf : ∀ m i : ℕ, f m i = (x + y) ^ i * y ^ (m - 1 - i) := by
    simp only [ge_iff_le, tsub_le_iff_right, forall_const]
  change (∑ i in range n, (f n) i) * x + y ^ n = (x + y) ^ n
  induction' n with n ih
  · rw [range_zero, sum_empty, zero_mul, zero_add, pow_zero, pow_zero]
  · have f_last : f (n + 1) n = (x + y) ^ n := by
      rw [hf, ← tsub_add_eq_tsub_tsub, Nat.add_comm, tsub_self, pow_zero, mul_one]
    have f_succ : ∀ i, i ∈ range n → f (n + 1) i = y * f n i := fun i hi => by
      rw [hf]
      have : Commute y ((x + y) ^ i) := (h.symm.add_right (Commute.refl y)).pow_right i
      rw [← mul_assoc, this.eq, mul_assoc, ← pow_succ y (n - 1 - i)]
      congr 2
      rw [add_tsub_cancel_right, ← tsub_add_eq_tsub_tsub, add_comm 1 i]
      have : i + 1 + (n - (i + 1)) = n := add_tsub_cancel_of_le (mem_range.mp hi)
      rw [add_comm (i + 1)] at this
      rw [← this, add_tsub_cancel_right, add_comm i 1, ← add_assoc, add_tsub_cancel_right]
    rw [pow_succ (x + y), add_mul, sum_range_succ_comm, add_mul, f_last, add_assoc]
    rw [(((Commute.refl x).add_right h).pow_right n).eq]
    

Proof state:
case succ
α : Type u
inst✝ : Semiring α
x y : α
h : Commute x y
f : ℕ → ℕ → α := fun m i => (x + y) ^ i * y ^ (m - 1 - i)
hf : ∀ (m i : ℕ), f m i = (x + y) ^ i * y ^ (m - 1 - i)
n : ℕ
ih : (∑ i in range n, f n i) * x + y ^ n = (x + y) ^ n
f_last : f (n + 1) n = (x + y) ^ n
f_succ : ∀ i ∈ range n, f (n + 1) i = y * f n i
⊢ (x + y) ^ n * x + ((∑ x in range n, f (Nat.succ n) x) * x + y ^ Nat.succ n) = (x + y) ^ n * x + y * (x + y) ^ n

Next tactic:
congr 1
/-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/
protected theorem Commute.geom_sum₂_mul_add {x y : α} (h : Commute x y) (n : ℕ) :
    (∑ i in range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := by
  let f :  ℕ → ℕ → α := fun m i : ℕ => (x + y) ^ i * y ^ (m - 1 - i)
  -- porting note: adding `hf` here, because below in two places `dsimp [f]` didn't work
  have hf : ∀ m i : ℕ, f m i = (x + y) ^ i * y ^ (m - 1 - i) := by
    simp only [ge_iff_le, tsub_le_iff_right, forall_const]
  change (∑ i in range n, (f n) i) * x + y ^ n = (x + y) ^ n
  induction' n with n ih
  · rw [range_zero, sum_empty, zero_mul, zero_add, pow_zero, pow_zero]
  · have f_last : f (n + 1) n = (x + y) ^ n := by
      rw [hf, ← tsub_add_eq_tsub_tsub, Nat.add_comm, tsub_self, pow_zero, mul_one]
    have f_succ : ∀ i, i ∈ range n → f (n + 1) i = y * f n i := fun i hi => by
      rw [hf]
      have : Commute y ((x + y) ^ i) := (h.symm.add_right (Commute.refl y)).pow_right i
      rw [← mul_assoc, this.eq, mul_assoc, ← pow_succ y (n - 1 - i)]
      congr 2
      rw [add_tsub_cancel_right, ← tsub_add_eq_tsub_tsub, add_comm 1 i]
      have : i + 1 + (n - (i + 1)) = n := add_tsub_cancel_of_le (mem_range.mp hi)
      rw [add_comm (i + 1)] at this
      rw [← this, add_tsub_cancel_right, add_comm i 1, ← add_assoc, add_tsub_cancel_right]
    rw [pow_succ (x + y), add_mul, sum_range_succ_comm, add_mul, f_last, add_assoc]
    rw [(((Commute.refl x).add_right h).pow_right n).eq]
    congr 1
    

Proof state:
case succ.e_a
α : Type u
inst✝ : Semiring α
x y : α
h : Commute x y
f : ℕ → ℕ → α := fun m i => (x + y) ^ i * y ^ (m - 1 - i)
hf : ∀ (m i : ℕ), f m i = (x + y) ^ i * y ^ (m - 1 - i)
n : ℕ
ih : (∑ i in range n, f n i) * x + y ^ n = (x + y) ^ n
f_last : f (n + 1) n = (x + y) ^ n
f_succ : ∀ i ∈ range n, f (n + 1) i = y * f n i
⊢ (∑ x in range n, f (Nat.succ n) x) * x + y ^ Nat.succ n = y * (x + y) ^ n

Next tactic:
rw [sum_congr rfl f_succ, ← mul_sum, pow_succ y, mul_assoc, ← mul_add y, ih]
@[simp]
theorem neg_one_geom_sum [Ring α] {n : ℕ} :
    ∑ i in range n, (-1 : α) ^ i = if Even n then 0 else 1 := by
  

Proof state:
α : Type u
inst✝ : Ring α
n : ℕ
⊢ ∑ i in range n, (-1) ^ i = if Even n then 0 else 1

Next tactic:
induction' n with k hk
@[simp]
theorem neg_one_geom_sum [Ring α] {n : ℕ} :
    ∑ i in range n, (-1 : α) ^ i = if Even n then 0 else 1 := by
  induction' n with k hk
  · 

Proof state:
case zero
α : Type u
inst✝ : Ring α
⊢ ∑ i in range Nat.zero, (-1) ^ i = if Even Nat.zero then 0 else 1

Next tactic:
simp
@[simp]
theorem neg_one_geom_sum [Ring α] {n : ℕ} :
    ∑ i in range n, (-1 : α) ^ i = if Even n then 0 else 1 := by
  induction' n with k hk
  · simp
  · 

Proof state:
case succ
α : Type u
inst✝ : Ring α
k : ℕ
hk : ∑ i in range k, (-1) ^ i = if Even k then 0 else 1
⊢ ∑ i in range (Nat.succ k), (-1) ^ i = if Even (Nat.succ k) then 0 else 1

Next tactic:
simp only [geom_sum_succ', Nat.even_add_one, hk]
@[simp]
theorem neg_one_geom_sum [Ring α] {n : ℕ} :
    ∑ i in range n, (-1 : α) ^ i = if Even n then 0 else 1 := by
  induction' n with k hk
  · simp
  · simp only [geom_sum_succ', Nat.even_add_one, hk]
    

Proof state:
case succ
α : Type u
inst✝ : Ring α
k : ℕ
hk : ∑ i in range k, (-1) ^ i = if Even k then 0 else 1
⊢ ((-1) ^ k + if Even k then 0 else 1) = if ¬Even k then 0 else 1

Next tactic:
split_ifs with h
@[simp]
theorem neg_one_geom_sum [Ring α] {n : ℕ} :
    ∑ i in range n, (-1 : α) ^ i = if Even n then 0 else 1 := by
  induction' n with k hk
  · simp
  · simp only [geom_sum_succ', Nat.even_add_one, hk]
    split_ifs with h
    · 

Proof state:
case pos
α : Type u
inst✝ : Ring α
k : ℕ
hk : ∑ i in range k, (-1) ^ i = if Even k then 0 else 1
h : Even k
⊢ (-1) ^ k + 0 = 1

Next tactic:
rw [h.neg_one_pow, add_zero]
@[simp]
theorem neg_one_geom_sum [Ring α] {n : ℕ} :
    ∑ i in range n, (-1 : α) ^ i = if Even n then 0 else 1 := by
  induction' n with k hk
  · simp
  · simp only [geom_sum_succ', Nat.even_add_one, hk]
    split_ifs with h
    · rw [h.neg_one_pow, add_zero]
    · 

Proof state:
case neg
α : Type u
inst✝ : Ring α
k : ℕ
hk : ∑ i in range k, (-1) ^ i = if Even k then 0 else 1
h : ¬Even k
⊢ (-1) ^ k + 1 = 0

Next tactic:
rw [(Nat.odd_iff_not_even.2 h).neg_one_pow, neg_add_self]
theorem geom_sum₂_self {α : Type*} [CommRing α] (x : α) (n : ℕ) :
    ∑ i in range n, x ^ i * x ^ (n - 1 - i) = n * x ^ (n - 1) :=
  calc
    ∑ i in Finset.range n, x ^ i * x ^ (n - 1 - i) =
        ∑ i in Finset.range n, x ^ (i + (n - 1 - i)) :=
      by 

Proof state:
α✝ : Type u
α : Type u_1
inst✝ : CommRing α
x : α
n : ℕ
⊢ ∑ i in range n, x ^ i * x ^ (n - 1 - i) = ∑ i in range n, x ^ (i + (n - 1 - i))

Next tactic:
simp_rw [← pow_add]
theorem geom_sum₂_self {α : Type*} [CommRing α] (x : α) (n : ℕ) :
    ∑ i in range n, x ^ i * x ^ (n - 1 - i) = n * x ^ (n - 1) :=
  calc
    ∑ i in Finset.range n, x ^ i * x ^ (n - 1 - i) =
        ∑ i in Finset.range n, x ^ (i + (n - 1 - i)) :=
      by simp_rw [← pow_add]
    _ = ∑ _i in Finset.range n, x ^ (n - 1) :=
      Finset.sum_congr rfl fun i hi =>
        congr_arg _ <| add_tsub_cancel_of_le <| Nat.le_sub_one_of_lt <| Finset.mem_range.1 hi
    _ = (Finset.range n).card • x ^ (n - 1) := Finset.sum_const _
    _ = n * x ^ (n - 1) := by 

Proof state:
α✝ : Type u
α : Type u_1
inst✝ : CommRing α
x : α
n : ℕ
⊢ card (range n) • x ^ (n - 1) = ↑n * x ^ (n - 1)

Next tactic:
rw [Finset.card_range, nsmul_eq_mul]
theorem geom_sum_mul_add [Semiring α] (x : α) (n : ℕ) :
    (∑ i in range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n := by
  

Proof state:
α : Type u
inst✝ : Semiring α
x : α
n : ℕ
⊢ (∑ i in range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n

Next tactic:
have := (Commute.one_right x).geom_sum₂_mul_add n
theorem geom_sum_mul_add [Semiring α] (x : α) (n : ℕ) :
    (∑ i in range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n := by
  have := (Commute.one_right x).geom_sum₂_mul_add n
  

Proof state:
α : Type u
inst✝ : Semiring α
x : α
n : ℕ
this : (∑ i in range n, (x + 1) ^ i * 1 ^ (n - 1 - i)) * x + 1 ^ n = (x + 1) ^ n
⊢ (∑ i in range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n

Next tactic:
rw [one_pow, geom_sum₂_with_one] at this
theorem geom_sum_mul_add [Semiring α] (x : α) (n : ℕ) :
    (∑ i in range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n := by
  have := (Commute.one_right x).geom_sum₂_mul_add n
  rw [one_pow, geom_sum₂_with_one] at this
  

Proof state:
α : Type u
inst✝ : Semiring α
x : α
n : ℕ
this : (∑ i in range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n
⊢ (∑ i in range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n

Next tactic:
exact this
protected theorem Commute.geom_sum₂_mul [Ring α] {x y : α} (h : Commute x y) (n : ℕ) :
    (∑ i in range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by
  

Proof state:
α : Type u
inst✝ : Ring α
x y : α
h : Commute x y
n : ℕ
⊢ (∑ i in range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n

Next tactic:
have := (h.sub_left (Commute.refl y)).geom_sum₂_mul_add n
protected theorem Commute.geom_sum₂_mul [Ring α] {x y : α} (h : Commute x y) (n : ℕ) :
    (∑ i in range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by
  have := (h.sub_left (Commute.refl y)).geom_sum₂_mul_add n
  

Proof state:
α : Type u
inst✝ : Ring α
x y : α
h : Commute x y
n : ℕ
this : (∑ i in range n, (x - y + y) ^ i * y ^ (n - 1 - i)) * (x - y) + y ^ n = (x - y + y) ^ n
⊢ (∑ i in range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n

Next tactic:
rw [sub_add_cancel] at this
protected theorem Commute.geom_sum₂_mul [Ring α] {x y : α} (h : Commute x y) (n : ℕ) :
    (∑ i in range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by
  have := (h.sub_left (Commute.refl y)).geom_sum₂_mul_add n
  rw [sub_add_cancel] at this
  

Proof state:
α : Type u
inst✝ : Ring α
x y : α
h : Commute x y
n : ℕ
this : (∑ i in range n, x ^ i * y ^ (n - 1 - i)) * (x - y) + y ^ n = x ^ n
⊢ (∑ i in range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n

Next tactic:
rw [← this, add_sub_cancel]
theorem Commute.mul_neg_geom_sum₂ [Ring α] {x y : α} (h : Commute x y) (n : ℕ) :
    ((y - x) * ∑ i in range n, x ^ i * y ^ (n - 1 - i)) = y ^ n - x ^ n := by
  

Proof state:
α : Type u
inst✝ : Ring α
x y : α
h : Commute x y
n : ℕ
⊢ (y - x) * ∑ i in range n, x ^ i * y ^ (n - 1 - i) = y ^ n - x ^ n

Next tactic:
apply op_injective
theorem Commute.mul_neg_geom_sum₂ [Ring α] {x y : α} (h : Commute x y) (n : ℕ) :
    ((y - x) * ∑ i in range n, x ^ i * y ^ (n - 1 - i)) = y ^ n - x ^ n := by
  apply op_injective
  

Proof state:
case a
α : Type u
inst✝ : Ring α
x y : α
h : Commute x y
n : ℕ
⊢ MulOpposite.op ((y - x) * ∑ i in range n, x ^ i * y ^ (n - 1 - i)) = MulOpposite.op (y ^ n - x ^ n)

Next tactic:
simp only [op_mul, op_sub, op_geom_sum₂, op_pow]
theorem Commute.mul_neg_geom_sum₂ [Ring α] {x y : α} (h : Commute x y) (n : ℕ) :
    ((y - x) * ∑ i in range n, x ^ i * y ^ (n - 1 - i)) = y ^ n - x ^ n := by
  apply op_injective
  simp only [op_mul, op_sub, op_geom_sum₂, op_pow]
  

Proof state:
case a
α : Type u
inst✝ : Ring α
x y : α
h : Commute x y
n : ℕ
⊢ MulOpposite.op (∑ i in range n, x ^ i * y ^ (n - 1 - i)) * (MulOpposite.op y - MulOpposite.op x) =
    MulOpposite.op y ^ n - MulOpposite.op x ^ n

Next tactic:
simp [(Commute.op h.symm).geom_sum₂_mul n]
theorem Commute.mul_geom_sum₂ [Ring α] {x y : α} (h : Commute x y) (n : ℕ) :
    ((x - y) * ∑ i in range n, x ^ i * y ^ (n - 1 - i)) = x ^ n - y ^ n := by
  

Proof state:
α : Type u
inst✝ : Ring α
x y : α
h : Commute x y
n : ℕ
⊢ (x - y) * ∑ i in range n, x ^ i * y ^ (n - 1 - i) = x ^ n - y ^ n

Next tactic:
rw [← neg_sub (y ^ n), ← h.mul_neg_geom_sum₂, ← neg_mul, neg_sub]
theorem one_sub_dvd_one_sub_pow [Ring α] (x : α) (n : ℕ) :
    1 - x ∣ 1 - x ^ n := by
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
⊢ 1 - x ∣ 1 - x ^ n

Next tactic:
conv_rhs => rw [← one_pow n]
theorem one_sub_dvd_one_sub_pow [Ring α] (x : α) (n : ℕ) :
    1 - x ∣ 1 - x ^ n := by
  conv_rhs => 

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
| 1 - x ^ n

Next tactic:
rw [← one_pow n]
theorem one_sub_dvd_one_sub_pow [Ring α] (x : α) (n : ℕ) :
    1 - x ∣ 1 - x ^ n := by
  conv_rhs => rw [← one_pow n]
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
⊢ 1 - x ∣ 1 ^ n - x ^ n

Next tactic:
exact (Commute.one_left x).sub_dvd_pow_sub_pow n
theorem sub_one_dvd_pow_sub_one [Ring α] (x : α) (n : ℕ) :
    x - 1 ∣ x ^ n - 1 := by
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
⊢ x - 1 ∣ x ^ n - 1

Next tactic:
conv_rhs => rw [← one_pow n]
theorem sub_one_dvd_pow_sub_one [Ring α] (x : α) (n : ℕ) :
    x - 1 ∣ x ^ n - 1 := by
  conv_rhs => 

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
| x ^ n - 1

Next tactic:
rw [← one_pow n]
theorem sub_one_dvd_pow_sub_one [Ring α] (x : α) (n : ℕ) :
    x - 1 ∣ x ^ n - 1 := by
  conv_rhs => rw [← one_pow n]
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
⊢ x - 1 ∣ x ^ n - 1 ^ n

Next tactic:
exact (Commute.one_right x).sub_dvd_pow_sub_pow n
theorem nat_sub_dvd_pow_sub_pow (x y n : ℕ) : x - y ∣ x ^ n - y ^ n := by
  

Proof state:
α : Type u
x y n : ℕ
⊢ x - y ∣ x ^ n - y ^ n

Next tactic:
rcases le_or_lt y x with h | h
theorem nat_sub_dvd_pow_sub_pow (x y n : ℕ) : x - y ∣ x ^ n - y ^ n := by
  rcases le_or_lt y x with h | h
  · 

Proof state:
case inl
α : Type u
x y n : ℕ
h : y ≤ x
⊢ x - y ∣ x ^ n - y ^ n

Next tactic:
have : y ^ n ≤ x ^ n := Nat.pow_le_pow_left h _
theorem nat_sub_dvd_pow_sub_pow (x y n : ℕ) : x - y ∣ x ^ n - y ^ n := by
  rcases le_or_lt y x with h | h
  · have : y ^ n ≤ x ^ n := Nat.pow_le_pow_left h _
    

Proof state:
case inl
α : Type u
x y n : ℕ
h : y ≤ x
this : y ^ n ≤ x ^ n
⊢ x - y ∣ x ^ n - y ^ n

Next tactic:
exact mod_cast sub_dvd_pow_sub_pow (x : ℤ) (↑y) n
theorem nat_sub_dvd_pow_sub_pow (x y n : ℕ) : x - y ∣ x ^ n - y ^ n := by
  rcases le_or_lt y x with h | h
  · have : y ^ n ≤ x ^ n := Nat.pow_le_pow_left h _
    exact mod_cast sub_dvd_pow_sub_pow (x : ℤ) (↑y) n
  · 

Proof state:
case inr
α : Type u
x y n : ℕ
h : x < y
⊢ x - y ∣ x ^ n - y ^ n

Next tactic:
have : x ^ n ≤ y ^ n := Nat.pow_le_pow_left h.le _
theorem nat_sub_dvd_pow_sub_pow (x y n : ℕ) : x - y ∣ x ^ n - y ^ n := by
  rcases le_or_lt y x with h | h
  · have : y ^ n ≤ x ^ n := Nat.pow_le_pow_left h _
    exact mod_cast sub_dvd_pow_sub_pow (x : ℤ) (↑y) n
  · have : x ^ n ≤ y ^ n := Nat.pow_le_pow_left h.le _
    

Proof state:
case inr
α : Type u
x y n : ℕ
h : x < y
this : x ^ n ≤ y ^ n
⊢ x - y ∣ x ^ n - y ^ n

Next tactic:
exact (Nat.sub_eq_zero_of_le this).symm ▸ dvd_zero (x - y)
theorem Odd.add_dvd_pow_add_pow [CommRing α] (x y : α) {n : ℕ} (h : Odd n) :
    x + y ∣ x ^ n + y ^ n := by
  

Proof state:
α : Type u
inst✝ : CommRing α
x y : α
n : ℕ
h : Odd n
⊢ x + y ∣ x ^ n + y ^ n

Next tactic:
have h₁ := geom_sum₂_mul x (-y) n
theorem Odd.add_dvd_pow_add_pow [CommRing α] (x y : α) {n : ℕ} (h : Odd n) :
    x + y ∣ x ^ n + y ^ n := by
  have h₁ := geom_sum₂_mul x (-y) n
  

Proof state:
α : Type u
inst✝ : CommRing α
x y : α
n : ℕ
h : Odd n
h₁ : (∑ i in range n, x ^ i * (-y) ^ (n - 1 - i)) * (x - -y) = x ^ n - (-y) ^ n
⊢ x + y ∣ x ^ n + y ^ n

Next tactic:
rw [Odd.neg_pow h y, sub_neg_eq_add, sub_neg_eq_add] at h₁
theorem Odd.add_dvd_pow_add_pow [CommRing α] (x y : α) {n : ℕ} (h : Odd n) :
    x + y ∣ x ^ n + y ^ n := by
  have h₁ := geom_sum₂_mul x (-y) n
  rw [Odd.neg_pow h y, sub_neg_eq_add, sub_neg_eq_add] at h₁
  

Proof state:
α : Type u
inst✝ : CommRing α
x y : α
n : ℕ
h : Odd n
h₁ : (∑ i in range n, x ^ i * (-y) ^ (n - 1 - i)) * (x + y) = x ^ n + y ^ n
⊢ x + y ∣ x ^ n + y ^ n

Next tactic:
exact Dvd.intro_left _ h₁
theorem geom_sum_mul [Ring α] (x : α) (n : ℕ) : (∑ i in range n, x ^ i) * (x - 1) = x ^ n - 1 := by
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
⊢ (∑ i in range n, x ^ i) * (x - 1) = x ^ n - 1

Next tactic:
have := (Commute.one_right x).geom_sum₂_mul n
theorem geom_sum_mul [Ring α] (x : α) (n : ℕ) : (∑ i in range n, x ^ i) * (x - 1) = x ^ n - 1 := by
  have := (Commute.one_right x).geom_sum₂_mul n
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
this : (∑ i in range n, x ^ i * 1 ^ (n - 1 - i)) * (x - 1) = x ^ n - 1 ^ n
⊢ (∑ i in range n, x ^ i) * (x - 1) = x ^ n - 1

Next tactic:
rw [one_pow, geom_sum₂_with_one] at this
theorem geom_sum_mul [Ring α] (x : α) (n : ℕ) : (∑ i in range n, x ^ i) * (x - 1) = x ^ n - 1 := by
  have := (Commute.one_right x).geom_sum₂_mul n
  rw [one_pow, geom_sum₂_with_one] at this
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
this : (∑ i in range n, x ^ i) * (x - 1) = x ^ n - 1
⊢ (∑ i in range n, x ^ i) * (x - 1) = x ^ n - 1

Next tactic:
exact this
theorem mul_geom_sum [Ring α] (x : α) (n : ℕ) : ((x - 1) * ∑ i in range n, x ^ i) = x ^ n - 1 :=
  op_injective <| by 

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
⊢ op ((x - 1) * ∑ i in range n, x ^ i) = op (x ^ n - 1)

Next tactic:
simpa using geom_sum_mul (op x) n
theorem geom_sum_mul_neg [Ring α] (x : α) (n : ℕ) :
    (∑ i in range n, x ^ i) * (1 - x) = 1 - x ^ n := by
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
⊢ (∑ i in range n, x ^ i) * (1 - x) = 1 - x ^ n

Next tactic:
have := congr_arg Neg.neg (geom_sum_mul x n)
theorem geom_sum_mul_neg [Ring α] (x : α) (n : ℕ) :
    (∑ i in range n, x ^ i) * (1 - x) = 1 - x ^ n := by
  have := congr_arg Neg.neg (geom_sum_mul x n)
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
this : -((∑ i in range n, x ^ i) * (x - 1)) = -(x ^ n - 1)
⊢ (∑ i in range n, x ^ i) * (1 - x) = 1 - x ^ n

Next tactic:
rw [neg_sub, ← mul_neg, neg_sub] at this
theorem geom_sum_mul_neg [Ring α] (x : α) (n : ℕ) :
    (∑ i in range n, x ^ i) * (1 - x) = 1 - x ^ n := by
  have := congr_arg Neg.neg (geom_sum_mul x n)
  rw [neg_sub, ← mul_neg, neg_sub] at this
  

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
this : (∑ i in range n, x ^ i) * (1 - x) = 1 - x ^ n
⊢ (∑ i in range n, x ^ i) * (1 - x) = 1 - x ^ n

Next tactic:
exact this
theorem mul_neg_geom_sum [Ring α] (x : α) (n : ℕ) : ((1 - x) * ∑ i in range n, x ^ i) = 1 - x ^ n :=
  op_injective <| by 

Proof state:
α : Type u
inst✝ : Ring α
x : α
n : ℕ
⊢ op ((1 - x) * ∑ i in range n, x ^ i) = op (1 - x ^ n)

Next tactic:
simpa using geom_sum_mul_neg (op x) n
protected theorem Commute.geom_sum₂_comm {α : Type u} [Semiring α] {x y : α} (n : ℕ)
    (h : Commute x y) :
    ∑ i in range n, x ^ i * y ^ (n - 1 - i) = ∑ i in range n, y ^ i * x ^ (n - 1 - i) := by
  

Proof state:
α✝ α : Type u
inst✝ : Semiring α
x y : α
n : ℕ
h : Commute x y
⊢ ∑ i in range n, x ^ i * y ^ (n - 1 - i) = ∑ i in range n, y ^ i * x ^ (n - 1 - i)

Next tactic:
cases n
protected theorem Commute.geom_sum₂_comm {α : Type u} [Semiring α] {x y : α} (n : ℕ)
    (h : Commute x y) :
    ∑ i in range n, x ^ i * y ^ (n - 1 - i) = ∑ i in range n, y ^ i * x ^ (n - 1 - i) := by
  cases n; · 

Proof state:
case zero
α✝ α : Type u
inst✝ : Semiring α
x y : α
h : Commute x y
⊢ ∑ i in range Nat.zero, x ^ i * y ^ (Nat.zero - 1 - i) = ∑ i in range Nat.zero, y ^ i * x ^ (Nat.zero - 1 - i)

Next tactic:
simp
protected theorem Commute.geom_sum₂_comm {α : Type u} [Semiring α] {x y : α} (n : ℕ)
    (h : Commute x y) :
    ∑ i in range n, x ^ i * y ^ (n - 1 - i) = ∑ i in range n, y ^ i * x ^ (n - 1 - i) := by
  cases n; · simp
  

Proof state:
case succ
α✝ α : Type u
inst✝ : Semiring α
x y : α
h : Commute x y
n✝ : ℕ
⊢ ∑ i in range (Nat.succ n✝), x ^ i * y ^ (Nat.succ n✝ - 1 - i) =
    ∑ i in range (Nat.succ n✝), y ^ i * x ^ (Nat.succ n✝ - 1 - i)

Next tactic:
simp only [Nat.succ_eq_add_one, Nat.add_sub_cancel]
protected theorem Commute.geom_sum₂_comm {α : Type u} [Semiring α] {x y : α} (n : ℕ)
    (h : Commute x y) :
    ∑ i in range n, x ^ i * y ^ (n - 1 - i) = ∑ i in range n, y ^ i * x ^ (n - 1 - i) := by
  cases n; · simp
  simp only [Nat.succ_eq_add_one, Nat.add_sub_cancel]
  

Proof state:
case succ
α✝ α : Type u
inst✝ : Semiring α
x y : α
h : Commute x y
n✝ : ℕ
⊢ ∑ x_1 in range (n✝ + 1), x ^ x_1 * y ^ (n✝ - x_1) = ∑ x_1 in range (n✝ + 1), y ^ x_1 * x ^ (n✝ - x_1)

Next tactic:
rw [← Finset.sum_flip]
protected theorem Commute.geom_sum₂_comm {α : Type u} [Semiring α] {x y : α} (n : ℕ)
    (h : Commute x y) :
    ∑ i in range n, x ^ i * y ^ (n - 1 - i) = ∑ i in range n, y ^ i * x ^ (n - 1 - i) := by
  cases n; · simp
  simp only [Nat.succ_eq_add_one, Nat.add_sub_cancel]
  rw [← Finset.sum_flip]
  

Proof state:
case succ
α✝ α : Type u
inst✝ : Semiring α
x y : α
h : Commute x y
n✝ : ℕ
⊢ ∑ r in range (n✝ + 1), x ^ (n✝ - r) * y ^ (n✝ - (n✝ - r)) = ∑ x_1 in range (n✝ + 1), y ^ x_1 * x ^ (n✝ - x_1)

Next tactic:
refine' Finset.sum_congr rfl fun i hi => _
protected theorem Commute.geom_sum₂_comm {α : Type u} [Semiring α] {x y : α} (n : ℕ)
    (h : Commute x y) :
    ∑ i in range n, x ^ i * y ^ (n - 1 - i) = ∑ i in range n, y ^ i * x ^ (n - 1 - i) := by
  cases n; · simp
  simp only [Nat.succ_eq_add_one, Nat.add_sub_cancel]
  rw [← Finset.sum_flip]
  refine' Finset.sum_congr rfl fun i hi => _
  

Proof state:
case succ
α✝ α : Type u
inst✝ : Semiring α
x y : α
h : Commute x y
n✝ i : ℕ
hi : i ∈ range (n✝ + 1)
⊢ x ^ (n✝ - i) * y ^ (n✝ - (n✝ - i)) = y ^ i * x ^ (n✝ - i)

Next tactic:
simpa [Nat.sub_sub_self (Nat.succ_le_succ_iff.mp (Finset.mem_range.mp hi))] using h.pow_pow _ _
protected theorem Commute.geom_sum₂ [DivisionRing α] {x y : α} (h' : Commute x y) (h : x ≠ y)
    (n : ℕ) : ∑ i in range n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ n) / (x - y) := by
  

Proof state:
α : Type u
inst✝ : DivisionRing α
x y : α
h' : Commute x y
h : x ≠ y
n : ℕ
⊢ ∑ i in range n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ n) / (x - y)

Next tactic:
have : x - y ≠ 0 := by simp_all [sub_eq_iff_eq_add]
protected theorem Commute.geom_sum₂ [DivisionRing α] {x y : α} (h' : Commute x y) (h : x ≠ y)
    (n : ℕ) : ∑ i in range n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ n) / (x - y) := by
  have : x - y ≠ 0 := by 

Proof state:
α : Type u
inst✝ : DivisionRing α
x y : α
h' : Commute x y
h : x ≠ y
n : ℕ
⊢ x - y ≠ 0

Next tactic:
simp_all [sub_eq_iff_eq_add]
protected theorem Commute.geom_sum₂ [DivisionRing α] {x y : α} (h' : Commute x y) (h : x ≠ y)
    (n : ℕ) : ∑ i in range n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ n) / (x - y) := by
  have : x - y ≠ 0 := by simp_all [sub_eq_iff_eq_add]
  

Proof state:
α : Type u
inst✝ : DivisionRing α
x y : α
h' : Commute x y
h : x ≠ y
n : ℕ
this : x - y ≠ 0
⊢ ∑ i in range n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ n) / (x - y)

Next tactic:
rw [← h'.geom_sum₂_mul, mul_div_cancel _ this]
theorem geom_sum_eq [DivisionRing α] {x : α} (h : x ≠ 1) (n : ℕ) :
    ∑ i in range n, x ^ i = (x ^ n - 1) / (x - 1) := by
  

Proof state:
α : Type u
inst✝ : DivisionRing α
x : α
h : x ≠ 1
n : ℕ
⊢ ∑ i in range n, x ^ i = (x ^ n - 1) / (x - 1)

Next tactic:
have : x - 1 ≠ 0 := by simp_all [sub_eq_iff_eq_add]
theorem geom_sum_eq [DivisionRing α] {x : α} (h : x ≠ 1) (n : ℕ) :
    ∑ i in range n, x ^ i = (x ^ n - 1) / (x - 1) := by
  have : x - 1 ≠ 0 := by 

Proof state:
α : Type u
inst✝ : DivisionRing α
x : α
h : x ≠ 1
n : ℕ
⊢ x - 1 ≠ 0

Next tactic:
simp_all [sub_eq_iff_eq_add]
theorem geom_sum_eq [DivisionRing α] {x : α} (h : x ≠ 1) (n : ℕ) :
    ∑ i in range n, x ^ i = (x ^ n - 1) / (x - 1) := by
  have : x - 1 ≠ 0 := by simp_all [sub_eq_iff_eq_add]
  

Proof state:
α : Type u
inst✝ : DivisionRing α
x : α
h : x ≠ 1
n : ℕ
this : x - 1 ≠ 0
⊢ ∑ i in range n, x ^ i = (x ^ n - 1) / (x - 1)

Next tactic:
rw [← geom_sum_mul, mul_div_cancel _ this]
protected theorem Commute.mul_geom_sum₂_Ico [Ring α] {x y : α} (h : Commute x y) {m n : ℕ}
    (hmn : m ≤ n) :
    ((x - y) * ∑ i in Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = x ^ n - x ^ m * y ^ (n - m) := by
  

Proof state:
α : Type u
inst✝ : Ring α
x y : α
h : Commute x y
m n : ℕ
hmn : m ≤ n
⊢ (x - y) * ∑ i in Ico m n, x ^ i * y ^ (n - 1 - i) = x ^ n - x ^ m * y ^ (n - m)

Next tactic:
rw [sum_Ico_eq_sub _ hmn]