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

tactic: rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
state_before: n✝ b m n : ℕ
hb : 0 < b
⊢ b.digits n ++ b.digits m = b.digits (n + b ^ (b.digits n).length * m)
state_after: case inl
n✝ m n : ℕ
hb : 0 < succ 0
⊢ (succ 0).digits n ++ (succ 0).digits m = (succ 0).digits (n + succ 0 ^ ((succ 0).digits n).length * m)

case inr
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
⊢ b.digits n ++ b.digits m = b.digits (n + b ^ (b.digits n).length * m)

tactic: rw [← ofDigits_digits_append_digits]
state_before: case inr
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
⊢ b.digits n ++ b.digits m = b.digits (n + b ^ (b.digits n).length * m)
state_after: case inr
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
⊢ b.digits n ++ b.digits m = b.digits (ofDigits b (b.digits n ++ b.digits m))

tactic: refine (digits_ofDigits b hb _ (fun l hl => ?_) (fun h_append => ?_)).symm
state_before: case inr
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
⊢ b.digits n ++ b.digits m = b.digits (ofDigits b (b.digits n ++ b.digits m))
state_after: case inr.refine_1
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
l : ℕ
hl : l ∈ b.digits n ++ b.digits m
⊢ l < b

case inr.refine_2
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append : b.digits n ++ b.digits m ≠ []
⊢ (b.digits n ++ b.digits m).getLast h_append ≠ 0

tactic: simp
state_before: case inl
n✝ m n : ℕ
hb : 0 < succ 0
⊢ (succ 0).digits n ++ (succ 0).digits m = (succ 0).digits (n + succ 0 ^ ((succ 0).digits n).length * m)
state_after: no goals

tactic: rcases (List.mem_append.mp hl) with (h | h) <;> exact digits_lt_base hb h
state_before: case inr.refine_1
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
l : ℕ
hl : l ∈ b.digits n ++ b.digits m
⊢ l < b
state_after: no goals

tactic: by_cases h : digits b m = []
state_before: case inr.refine_2
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append : b.digits n ++ b.digits m ≠ []
⊢ (b.digits n ++ b.digits m).getLast h_append ≠ 0
state_after: case pos
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append : b.digits n ++ b.digits m ≠ []
h : b.digits m = []
⊢ (b.digits n ++ b.digits m).getLast h_append ≠ 0

case neg
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append : b.digits n ++ b.digits m ≠ []
h : ¬b.digits m = []
⊢ (b.digits n ++ b.digits m).getLast h_append ≠ 0

tactic: simp only [h, List.append_nil] at h_append ⊢
state_before: case pos
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append : b.digits n ++ b.digits m ≠ []
h : b.digits m = []
⊢ (b.digits n ++ b.digits m).getLast h_append ≠ 0
state_after: case pos
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append✝ : b.digits n ++ b.digits m ≠ []
h : b.digits m = []
h_append : b.digits n ≠ []
⊢ (b.digits n).getLast ⋯ ≠ 0

tactic: exact getLast_digit_ne_zero b <| digits_ne_nil_iff_ne_zero.mp h_append
state_before: case pos
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append✝ : b.digits n ++ b.digits m ≠ []
h : b.digits m = []
h_append : b.digits n ≠ []
⊢ (b.digits n).getLast ⋯ ≠ 0
state_after: no goals

tactic: exact (List.getLast_append' _ _ h) ▸
    (getLast_digit_ne_zero _ <| digits_ne_nil_iff_ne_zero.mp h)
state_before: case neg
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append : b.digits n ++ b.digits m ≠ []
h : ¬b.digits m = []
⊢ (b.digits n ++ b.digits m).getLast h_append ≠ 0
state_after: no goals