Theorem: Nat.sub_mul_div
File: Std/Data/Nat/Lemmas.lean

tactic: match eq_zero_or_pos n with
| .inl h₀ => rw [h₀, Nat.div_zero, Nat.div_zero, Nat.zero_sub]
| .inr h₀ => induction p with
  | zero => rw [Nat.mul_zero, Nat.sub_zero, Nat.sub_zero]
  | succ p IH =>
    have h₂ : n * p ≤ x := Nat.le_trans (Nat.mul_le_mul_left _ (le_succ _)) h₁
    have h₃ : x - n * p ≥ n := by
      apply Nat.le_of_add_le_add_right
      rw [Nat.sub_add_cancel h₂, Nat.add_comm]
      rw [mul_succ] at h₁
      exact h₁
    rw [sub_succ, ← IH h₂, div_eq_sub_div h₀ h₃]
    simp [add_one, Nat.pred_succ, mul_succ, Nat.sub_sub]
state_before: x n p : Nat
h₁ : n * p ≤ x
⊢ (x - n * p) / n = x / n - p

tactic: rw [h₀, Nat.div_zero, Nat.div_zero, Nat.zero_sub]
state_before: x n p : Nat
h₁ : n * p ≤ x
h₀ : n = 0
⊢ (x - n * p) / n = x / n - p

tactic: induction p with
| zero => rw [Nat.mul_zero, Nat.sub_zero, Nat.sub_zero]
| succ p IH =>
have h₂ : n * p ≤ x := Nat.le_trans (Nat.mul_le_mul_left _ (le_succ _)) h₁
have h₃ : x - n * p ≥ n := by
apply Nat.le_of_add_le_add_right
rw [Nat.sub_add_cancel h₂, Nat.add_comm]
rw [mul_succ] at h₁
exact h₁
rw [sub_succ, ← IH h₂, div_eq_sub_div h₀ h₃]
simp [add_one, Nat.pred_succ, mul_succ, Nat.sub_sub]
state_before: x n p : Nat
h₁ : n * p ≤ x
h₀ : n > 0
⊢ (x - n * p) / n = x / n - p

tactic: rw [Nat.mul_zero, Nat.sub_zero, Nat.sub_zero]
state_before: case zero
x n : Nat
h₀ : n > 0
h₁ : n * zero ≤ x
⊢ (x - n * zero) / n = x / n - zero

tactic: have h₂ : n * p ≤ x := Nat.le_trans (Nat.mul_le_mul_left _ (le_succ _)) h₁
state_before: case succ
x n : Nat
h₀ : n > 0
p : Nat
IH : n * p ≤ x → (x - n * p) / n = x / n - p
h₁ : n * succ p ≤ x
⊢ (x - n * succ p) / n = x / n - succ p

tactic: have h₃ : x - n * p ≥ n := by
  apply Nat.le_of_add_le_add_right
  rw [Nat.sub_add_cancel h₂, Nat.add_comm]
  rw [mul_succ] at h₁
  exact h₁
state_before: case succ
x n : Nat
h₀ : n > 0
p : Nat
IH : n * p ≤ x → (x - n * p) / n = x / n - p
h₁ : n * succ p ≤ x
h₂ : n * p ≤ x
⊢ (x - n * succ p) / n = x / n - succ p

tactic: rw [sub_succ, ← IH h₂, div_eq_sub_div h₀ h₃]
state_before: case succ
x n : Nat
h₀ : n > 0
p : Nat
IH : n * p ≤ x → (x - n * p) / n = x / n - p
h₁ : n * succ p ≤ x
h₂ : n * p ≤ x
h₃ : x - n * p ≥ n
⊢ (x - n * succ p) / n = x / n - succ p

tactic: simp [add_one, Nat.pred_succ, mul_succ, Nat.sub_sub]
state_before: case succ
x n : Nat
h₀ : n > 0
p : Nat
IH : n * p ≤ x → (x - n * p) / n = x / n - p
h₁ : n * succ p ≤ x
h₂ : n * p ≤ x
h₃ : x - n * p ≥ n
⊢ (x - n * succ p) / n = pred ((x - n * p - n) / n + 1)

tactic: apply Nat.le_of_add_le_add_right
state_before: x n : Nat
h₀ : n > 0
p : Nat
IH : n * p ≤ x → (x - n * p) / n = x / n - p
h₁ : n * succ p ≤ x
h₂ : n * p ≤ x
⊢ x - n * p ≥ n

tactic: rw [Nat.sub_add_cancel h₂, Nat.add_comm]
state_before: case a
x n : Nat
h₀ : n > 0
p : Nat
IH : n * p ≤ x → (x - n * p) / n = x / n - p
h₁ : n * succ p ≤ x
h₂ : n * p ≤ x
⊢ n + ?b ≤ x - n * p + ?b

case b
x n : Nat
h₀ : n > 0
p : Nat
IH : n * p ≤ x → (x - n * p) / n = x / n - p
h₁ : n * succ p ≤ x
h₂ : n * p ≤ x
⊢ Nat

tactic: rw [mul_succ] at h₁
state_before: case a
x n : Nat
h₀ : n > 0
p : Nat
IH : n * p ≤ x → (x - n * p) / n = x / n - p
h₁ : n * succ p ≤ x
h₂ : n * p ≤ x
⊢ n * p + n ≤ x

tactic: exact h₁
state_before: case a
x n : Nat
h₀ : n > 0
p : Nat
IH : n * p ≤ x → (x - n * p) / n = x / n - p
h₁ : n * p + n ≤ x
h₂ : n * p ≤ x
⊢ n * p + n ≤ x