Theorem: Nat.mod_pow_succ
File: Mathlib/Data/Nat/Pow.lean

tactic: by_cases b_h : b = 0
state_before: b w m : ℕ
⊢ m % b ^ succ w = b * (m / b % b ^ w) + m % b

tactic: have b_pos := Nat.pos_of_ne_zero b_h
state_before: case neg
b w m : ℕ
b_h : ¬b = 0
⊢ m % b ^ succ w = b * (m / b % b ^ w) + m % b

tactic: simp [b_h, pow_succ]
state_before: case pos
b w m : ℕ
b_h : b = 0
⊢ m % b ^ succ w = b * (m / b % b ^ w) + m % b

tactic: cases' lt_or_ge p (b ^ succ w) with h₁ h₁
state_before: case neg.h
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
⊢ p % b ^ succ w = b * (p / b % b ^ w) + p % b

tactic: have h₂ : p / b < b ^ w := by
  rw [div_lt_iff_lt_mul b_pos]
  simpa [pow_succ] using h₁
state_before: case neg.h.inl
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₁ : p < b ^ succ w
⊢ p % b ^ succ w = b * (p / b % b ^ w) + p % b

tactic: rw [mod_eq_of_lt h₁, mod_eq_of_lt h₂]
state_before: case neg.h.inl
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₁ : p < b ^ succ w
h₂ : p / b < b ^ w
⊢ p % b ^ succ w = b * (p / b % b ^ w) + p % b

tactic: simp [div_add_mod]
state_before: case neg.h.inl
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₁ : p < b ^ succ w
h₂ : p / b < b ^ w
⊢ p = b * (p / b) + p % b

tactic: rw [div_lt_iff_lt_mul b_pos]
state_before: b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₁ : p < b ^ succ w
⊢ p / b < b ^ w

tactic: simpa [pow_succ] using h₁
state_before: b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₁ : p < b ^ succ w
⊢ p < b ^ w * b

tactic: have h₂ : p - b ^ succ w < p :=
  tsub_lt_self ((pow_pos b_pos _).trans_le h₁) (pow_pos b_pos _)
state_before: case neg.h.inr
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₁ : p ≥ b ^ succ w
⊢ p % b ^ succ w = b * (p / b % b ^ w) + p % b

tactic: rw [mod_eq_sub_mod h₁, IH _ h₂]
state_before: case neg.h.inr
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₁ : p ≥ b ^ succ w
h₂ : p - b ^ succ w < p
⊢ p % b ^ succ w = b * (p / b % b ^ w) + p % b

tactic: simp only [pow_succ']
state_before: case neg.h.inr
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₁ : p ≥ b ^ succ w
h₂ : p - b ^ succ w < p
⊢ b * ((p - b ^ succ w) / b % b ^ w) + (p - b ^ succ w) % b = b * (p / b % b ^ w) + p % b

tactic: simp only [GE.ge, pow_succ'] at h₁
state_before: case neg.h.inr
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₁ : p ≥ b ^ succ w
h₂ : p - b ^ succ w < p
⊢ b * ((p - b * b ^ w) / b % b ^ w) + (p - b * b ^ w) % b = b * (p / b % b ^ w) + p % b

tactic: rw [sub_mul_mod h₁, sub_mul_div _ _ _ h₁]
state_before: case neg.h.inr
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₂ : p - b ^ succ w < p
h₁ : b * b ^ w ≤ p
⊢ b * ((p - b * b ^ w) / b % b ^ w) + (p - b * b ^ w) % b = b * (p / b % b ^ w) + p % b

tactic: have p_b_ge : b ^ w ≤ p / b := by
  rw [le_div_iff_mul_le b_pos, mul_comm]
  exact h₁
state_before: case neg.h.inr
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₂ : p - b ^ succ w < p
h₁ : b * b ^ w ≤ p
⊢ b * ((p / b - b ^ w) % b ^ w) + p % b = b * (p / b % b ^ w) + p % b

tactic: rw [Eq.symm (mod_eq_sub_mod p_b_ge)]
state_before: case neg.h.inr
b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₂ : p - b ^ succ w < p
h₁ : b * b ^ w ≤ p
p_b_ge : b ^ w ≤ p / b
⊢ b * ((p / b - b ^ w) % b ^ w) + p % b = b * (p / b % b ^ w) + p % b

tactic: rw [le_div_iff_mul_le b_pos, mul_comm]
state_before: b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₂ : p - b ^ succ w < p
h₁ : b * b ^ w ≤ p
⊢ b ^ w ≤ p / b

tactic: exact h₁
state_before: b w : ℕ
b_h : ¬b = 0
b_pos : 0 < b
p : ℕ
IH : ∀ (m : ℕ), m < p → m % b ^ succ w = b * (m / b % b ^ w) + m % b
h₂ : p - b ^ succ w < p
h₁ : b * b ^ w ≤ p
⊢ b * b ^ w ≤ p