Theorem: Nat.ofDigits_digits
File: Mathlib/Data/Nat/Digits.lean

tactic: cases' b with b
state_before: n✝ b n : ℕ
⊢ ofDigits b (b.digits n) = n
state_after: case zero
n✝ n : ℕ
⊢ ofDigits 0 (digits 0 n) = n

case succ
n✝ n b : ℕ
⊢ ofDigits (b + 1) ((b + 1).digits n) = n

tactic: cases' n with n
state_before: case zero
n✝ n : ℕ
⊢ ofDigits 0 (digits 0 n) = n
state_after: case zero.zero
n : ℕ
⊢ ofDigits 0 (digits 0 0) = 0

case zero.succ
n✝ n : ℕ
⊢ ofDigits 0 (digits 0 (n + 1)) = n + 1

tactic: rfl
state_before: case zero.zero
n : ℕ
⊢ ofDigits 0 (digits 0 0) = 0
state_after: no goals

tactic: change ofDigits 0 [n + 1] = n + 1
state_before: case zero.succ
n✝ n : ℕ
⊢ ofDigits 0 (digits 0 (n + 1)) = n + 1
state_after: case zero.succ
n✝ n : ℕ
⊢ ofDigits 0 [n + 1] = n + 1

tactic: dsimp [ofDigits]
state_before: case zero.succ
n✝ n : ℕ
⊢ ofDigits 0 [n + 1] = n + 1
state_after: no goals

tactic: cases' b with b
state_before: case succ
n✝ n b : ℕ
⊢ ofDigits (b + 1) ((b + 1).digits n) = n
state_after: case succ.zero
n✝ n : ℕ
⊢ ofDigits (0 + 1) ((0 + 1).digits n) = n

case succ.succ
n✝ n b : ℕ
⊢ ofDigits (b + 1 + 1) ((b + 1 + 1).digits n) = n

tactic: induction' n with n ih
state_before: case succ.zero
n✝ n : ℕ
⊢ ofDigits (0 + 1) ((0 + 1).digits n) = n
state_after: case succ.zero.zero
n : ℕ
⊢ ofDigits (0 + 1) ((0 + 1).digits 0) = 0

case succ.zero.succ
n✝ n : ℕ
ih : ofDigits (0 + 1) ((0 + 1).digits n) = n
⊢ ofDigits (0 + 1) ((0 + 1).digits (n + 1)) = n + 1

tactic: rfl
state_before: case succ.zero.zero
n : ℕ
⊢ ofDigits (0 + 1) ((0 + 1).digits 0) = 0
state_after: no goals

tactic: rw [Nat.zero_add] at ih ⊢
state_before: case succ.zero.succ
n✝ n : ℕ
ih : ofDigits (0 + 1) ((0 + 1).digits n) = n
⊢ ofDigits (0 + 1) ((0 + 1).digits (n + 1)) = n + 1
state_after: case succ.zero.succ
n✝ n : ℕ
ih : ofDigits 1 (digits 1 n) = n
⊢ ofDigits 1 (digits 1 (n + 1)) = n + 1

tactic: simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ]
state_before: case succ.zero.succ
n✝ n : ℕ
ih : ofDigits 1 (digits 1 n) = n
⊢ ofDigits 1 (digits 1 (n + 1)) = n + 1
state_after: no goals

tactic: apply Nat.strongInductionOn n _
state_before: case succ.succ
n✝ n b : ℕ
⊢ ofDigits (b + 1 + 1) ((b + 1 + 1).digits n) = n
state_after: n✝ n b : ℕ
⊢ ∀ (n : ℕ),
    (∀ m < n, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m) → ofDigits (b + 1 + 1) ((b + 1 + 1).digits n) = n

tactic: clear n
state_before: n✝ n b : ℕ
⊢ ∀ (n : ℕ),
    (∀ m < n, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m) → ofDigits (b + 1 + 1) ((b + 1 + 1).digits n) = n
state_after: n b : ℕ
⊢ ∀ (n : ℕ),
    (∀ m < n, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m) → ofDigits (b + 1 + 1) ((b + 1 + 1).digits n) = n

tactic: intro n h
state_before: n b : ℕ
⊢ ∀ (n : ℕ),
    (∀ m < n, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m) → ofDigits (b + 1 + 1) ((b + 1 + 1).digits n) = n
state_after: n✝ b n : ℕ
h : ∀ m < n, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) ((b + 1 + 1).digits n) = n

tactic: cases n
state_before: n✝ b n : ℕ
h : ∀ m < n, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) ((b + 1 + 1).digits n) = n
state_after: case zero
n b : ℕ
h : ∀ m < 0, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) ((b + 1 + 1).digits 0) = 0

case succ
n b n✝ : ℕ
h : ∀ m < n✝ + 1, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) ((b + 1 + 1).digits (n✝ + 1)) = n✝ + 1

tactic: rw [digits_zero]
state_before: case zero
n b : ℕ
h : ∀ m < 0, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) ((b + 1 + 1).digits 0) = 0
state_after: case zero
n b : ℕ
h : ∀ m < 0, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) [] = 0

tactic: rfl
state_before: case zero
n b : ℕ
h : ∀ m < 0, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) [] = 0
state_after: no goals

tactic: simp only [Nat.succ_eq_add_one, digits_add_two_add_one]
state_before: case succ
n b n✝ : ℕ
h : ∀ m < n✝ + 1, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) ((b + 1 + 1).digits (n✝ + 1)) = n✝ + 1
state_after: case succ
n b n✝ : ℕ
h : ∀ m < n✝ + 1, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) ((n✝ + 1) % (b + 2) :: (b + 2).digits ((n✝ + 1) / (b + 2))) = n✝ + 1

tactic: dsimp [ofDigits]
state_before: case succ
n b n✝ : ℕ
h : ∀ m < n✝ + 1, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ ofDigits (b + 1 + 1) ((n✝ + 1) % (b + 2) :: (b + 2).digits ((n✝ + 1) / (b + 2))) = n✝ + 1
state_after: case succ
n b n✝ : ℕ
h : ∀ m < n✝ + 1, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ (n✝ + 1) % (b + 2) + (b + 1 + 1) * ofDigits (b + 1 + 1) ((b + 2).digits ((n✝ + 1) / (b + 2))) = n✝ + 1

tactic: rw [h _ (Nat.div_lt_self' _ b)]
state_before: case succ
n b n✝ : ℕ
h : ∀ m < n✝ + 1, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ (n✝ + 1) % (b + 2) + (b + 1 + 1) * ofDigits (b + 1 + 1) ((b + 2).digits ((n✝ + 1) / (b + 2))) = n✝ + 1
state_after: case succ
n b n✝ : ℕ
h : ∀ m < n✝ + 1, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ (n✝ + 1) % (b + 2) + (b + 1 + 1) * ((n✝ + 1) / (b + 2)) = n✝ + 1

tactic: rw [Nat.mod_add_div]
state_before: case succ
n b n✝ : ℕ
h : ∀ m < n✝ + 1, ofDigits (b + 1 + 1) ((b + 1 + 1).digits m) = m
⊢ (n✝ + 1) % (b + 2) + (b + 1 + 1) * ((n✝ + 1) / (b + 2)) = n✝ + 1
state_after: no goals