l3lab/ntp-mathlib huggingface dataset:
/-- The digits in the base b expansion of n are all less than b, if b ≥ 2 -/
theorem digits_lt_base {b m d : ℕ} (hb : 1 < b) (hd : d ∈ digits b m) : d < b := by
  rcases b with (_ | _ | b) <;> try simp_all
  

Proof state:
case succ.succ
n m d b : ℕ
hd : d ∈ digits (succ (succ b)) m
⊢ d < succ (succ b)

Next tactic:
exact digits_lt_base' hd
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  

Proof state:
n b : ℕ
l : List ℕ
hl : ∀ x ∈ l, x < b + 2
⊢ ofDigits (b + 2) l < (b + 2) ^ List.length l

Next tactic:
induction' l with hd tl IH
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  induction' l with hd tl IH
  · 

Proof state:
case nil
n b : ℕ
hl : ∀ x ∈ [], x < b + 2
⊢ ofDigits (b + 2) [] < (b + 2) ^ List.length []

Next tactic:
simp [ofDigits]
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  induction' l with hd tl IH
  · simp [ofDigits]
  · 

Proof state:
case cons
n b hd : ℕ
tl : List ℕ
IH : (∀ x ∈ tl, x < b + 2) → ofDigits (b + 2) tl < (b + 2) ^ List.length tl
hl : ∀ x ∈ hd :: tl, x < b + 2
⊢ ofDigits (b + 2) (hd :: tl) < (b + 2) ^ List.length (hd :: tl)

Next tactic:
rw [ofDigits, List.length_cons, pow_succ]
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  induction' l with hd tl IH
  · simp [ofDigits]
  · rw [ofDigits, List.length_cons, pow_succ]
    

Proof state:
case cons
n b hd : ℕ
tl : List ℕ
IH : (∀ x ∈ tl, x < b + 2) → ofDigits (b + 2) tl < (b + 2) ^ List.length tl
hl : ∀ x ∈ hd :: tl, x < b + 2
⊢ ↑hd + (b + 2) * ofDigits (b + 2) tl < (b + 2) ^ List.length tl * (b + 2)

Next tactic:
have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) :=
      mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le])
        (Nat.zero_le _)
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  induction' l with hd tl IH
  · simp [ofDigits]
  · rw [ofDigits, List.length_cons, pow_succ]
    have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) :=
      mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by 

Proof state:
n b hd : ℕ
tl : List ℕ
IH : (∀ x ∈ tl, x < b + 2) → ofDigits (b + 2) tl < (b + 2) ^ List.length tl
hl : ∀ x ∈ hd :: tl, x < b + 2
⊢ b + 2 ≤ b + 2

Next tactic:
rfl
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  induction' l with hd tl IH
  · simp [ofDigits]
  · rw [ofDigits, List.length_cons, pow_succ]
    have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) :=
      mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by 

Proof state:
n b hd : ℕ
tl : List ℕ
IH : (∀ x ∈ tl, x < b + 2) → ofDigits (b + 2) tl < (b + 2) ^ List.length tl
hl : ∀ x ∈ hd :: tl, x < b + 2
⊢ 0 ≤ b + 2

Next tactic:
simp only [zero_le]
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  induction' l with hd tl IH
  · simp [ofDigits]
  · rw [ofDigits, List.length_cons, pow_succ]
    have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) :=
      mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le])
        (Nat.zero_le _)
    

Proof state:
case cons
n b hd : ℕ
tl : List ℕ
IH : (∀ x ∈ tl, x < b + 2) → ofDigits (b + 2) tl < (b + 2) ^ List.length tl
hl : ∀ x ∈ hd :: tl, x < b + 2
this : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ List.length tl * (b + 2)
⊢ ↑hd + (b + 2) * ofDigits (b + 2) tl < (b + 2) ^ List.length tl * (b + 2)

Next tactic:
suffices ↑hd < b + 2 by linarith
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  induction' l with hd tl IH
  · simp [ofDigits]
  · rw [ofDigits, List.length_cons, pow_succ]
    have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) :=
      mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le])
        (Nat.zero_le _)
    suffices ↑hd < b + 2 by 

Proof state:
n b hd : ℕ
tl : List ℕ
IH : (∀ x ∈ tl, x < b + 2) → ofDigits (b + 2) tl < (b + 2) ^ List.length tl
hl : ∀ x ∈ hd :: tl, x < b + 2
this✝ : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ List.length tl * (b + 2)
this : hd < b + 2
⊢ ↑hd + (b + 2) * ofDigits (b + 2) tl < (b + 2) ^ List.length tl * (b + 2)

Next tactic:
linarith
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  induction' l with hd tl IH
  · simp [ofDigits]
  · rw [ofDigits, List.length_cons, pow_succ]
    have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) :=
      mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le])
        (Nat.zero_le _)
    suffices ↑hd < b + 2 by linarith
    

Proof state:
case cons
n b hd : ℕ
tl : List ℕ
IH : (∀ x ∈ tl, x < b + 2) → ofDigits (b + 2) tl < (b + 2) ^ List.length tl
hl : ∀ x ∈ hd :: tl, x < b + 2
this : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ List.length tl * (b + 2)
⊢ hd < b + 2

Next tactic:
norm_cast
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
    ofDigits (b + 2) l < (b + 2) ^ l.length := by
  induction' l with hd tl IH
  · simp [ofDigits]
  · rw [ofDigits, List.length_cons, pow_succ]
    have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) :=
      mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le])
        (Nat.zero_le _)
    suffices ↑hd < b + 2 by linarith
    norm_cast
    

Proof state:
case cons
n b hd : ℕ
tl : List ℕ
IH : (∀ x ∈ tl, x < b + 2) → ofDigits (b + 2) tl < (b + 2) ^ List.length tl
hl : ∀ x ∈ hd :: tl, x < b + 2
this : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ List.length tl * (b + 2)
⊢ hd < b + 2

Next tactic:
exact hl hd (List.mem_cons_self _ _)
/-- an n-digit number in base b is less than b^n if b > 1 -/
theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) :
    ofDigits b l < b ^ l.length := by
  

Proof state:
n b : ℕ
l : List ℕ
hb : 1 < b
hl : ∀ x ∈ l, x < b
⊢ ofDigits b l < b ^ List.length l

Next tactic:
rcases b with (_ | _ | b)
/-- an n-digit number in base b is less than b^n if b > 1 -/
theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) :
    ofDigits b l < b ^ l.length := by
  rcases b with (_ | _ | b) <;> 

Proof state:
case zero
n : ℕ
l : List ℕ
hb : 1 < zero
hl : ∀ x ∈ l, x < zero
⊢ ofDigits zero l < zero ^ List.length l

Next tactic:
try simp_all
/-- an n-digit number in base b is less than b^n if b > 1 -/
theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) :
    ofDigits b l < b ^ l.length := by
  rcases b with (_ | _ | b) <;> try 

Proof state:
case zero
n : ℕ
l : List ℕ
hb : 1 < zero
hl : ∀ x ∈ l, x < zero
⊢ ofDigits zero l < zero ^ List.length l

Next tactic:
simp_all
/-- an n-digit number in base b is less than b^n if b > 1 -/
theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) :
    ofDigits b l < b ^ l.length := by
  rcases b with (_ | _ | b) <;> 

Proof state:
case succ.zero
n : ℕ
l : List ℕ
hb : 1 < succ zero
hl : ∀ x ∈ l, x < succ zero
⊢ ofDigits (succ zero) l < succ zero ^ List.length l

Next tactic:
try simp_all
/-- an n-digit number in base b is less than b^n if b > 1 -/
theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) :
    ofDigits b l < b ^ l.length := by
  rcases b with (_ | _ | b) <;> try 

Proof state:
case succ.zero
n : ℕ
l : List ℕ
hb : 1 < succ zero
hl : ∀ x ∈ l, x < succ zero
⊢ ofDigits (succ zero) l < succ zero ^ List.length l

Next tactic:
simp_all
/-- an n-digit number in base b is less than b^n if b > 1 -/
theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) :
    ofDigits b l < b ^ l.length := by
  rcases b with (_ | _ | b) <;> 

Proof state:
case succ.succ
n : ℕ
l : List ℕ
b : ℕ
hb : 1 < succ (succ b)
hl : ∀ x ∈ l, x < succ (succ b)
⊢ ofDigits (succ (succ b)) l < succ (succ b) ^ List.length l

Next tactic:
try simp_all
/-- an n-digit number in base b is less than b^n if b > 1 -/
theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) :
    ofDigits b l < b ^ l.length := by
  rcases b with (_ | _ | b) <;> try 

Proof state:
case succ.succ
n : ℕ
l : List ℕ
b : ℕ
hb : 1 < succ (succ b)
hl : ∀ x ∈ l, x < succ (succ b)
⊢ ofDigits (succ (succ b)) l < succ (succ b) ^ List.length l

Next tactic:
simp_all
/-- an n-digit number in base b is less than b^n if b > 1 -/
theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) :
    ofDigits b l < b ^ l.length := by
  rcases b with (_ | _ | b) <;> try simp_all
  

Proof state:
case succ.succ
n : ℕ
l : List ℕ
b : ℕ
hl : ∀ x ∈ l, x < succ (succ b)
⊢ ofDigits (succ (succ b)) l < succ (succ b) ^ List.length l

Next tactic:
exact ofDigits_lt_base_pow_length' hl
/-- Any number m is less than (b+2)^(number of digits in the base b + 2 representation of m) -/
theorem lt_base_pow_length_digits' {b m : ℕ} : m < (b + 2) ^ (digits (b + 2) m).length := by
  

Proof state:
n b m : ℕ
⊢ m < (b + 2) ^ List.length (digits (b + 2) m)

Next tactic:
convert @ofDigits_lt_base_pow_length' b (digits (b + 2) m) fun _ => digits_lt_base'
/-- Any number m is less than (b+2)^(number of digits in the base b + 2 representation of m) -/
theorem lt_base_pow_length_digits' {b m : ℕ} : m < (b + 2) ^ (digits (b + 2) m).length := by
  convert @ofDigits_lt_base_pow_length' b (digits (b + 2) m) fun _ => digits_lt_base'
  

Proof state:
case h.e'_3
n b m : ℕ
⊢ m = ofDigits (b + 2) (digits (b + 2) m)

Next tactic:
rw [ofDigits_digits (b + 2) m]
/-- Any number m is less than b^(number of digits in the base b representation of m) -/
theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by
  

Proof state:
n b m : ℕ
hb : 1 < b
⊢ m < b ^ List.length (digits b m)

Next tactic:
rcases b with (_ | _ | b)
/-- Any number m is less than b^(number of digits in the base b representation of m) -/
theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by
  rcases b with (_ | _ | b) <;> 

Proof state:
case zero
n m : ℕ
hb : 1 < zero
⊢ m < zero ^ List.length (digits zero m)

Next tactic:
try simp_all
/-- Any number m is less than b^(number of digits in the base b representation of m) -/
theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by
  rcases b with (_ | _ | b) <;> try 

Proof state:
case zero
n m : ℕ
hb : 1 < zero
⊢ m < zero ^ List.length (digits zero m)

Next tactic:
simp_all
/-- Any number m is less than b^(number of digits in the base b representation of m) -/
theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by
  rcases b with (_ | _ | b) <;> 

Proof state:
case succ.zero
n m : ℕ
hb : 1 < succ zero
⊢ m < succ zero ^ List.length (digits (succ zero) m)

Next tactic:
try simp_all
/-- Any number m is less than b^(number of digits in the base b representation of m) -/
theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by
  rcases b with (_ | _ | b) <;> try 

Proof state:
case succ.zero
n m : ℕ
hb : 1 < succ zero
⊢ m < succ zero ^ List.length (digits (succ zero) m)

Next tactic:
simp_all
/-- Any number m is less than b^(number of digits in the base b representation of m) -/
theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by
  rcases b with (_ | _ | b) <;> 

Proof state:
case succ.succ
n m b : ℕ
hb : 1 < succ (succ b)
⊢ m < succ (succ b) ^ List.length (digits (succ (succ b)) m)

Next tactic:
try simp_all
/-- Any number m is less than b^(number of digits in the base b representation of m) -/
theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by
  rcases b with (_ | _ | b) <;> try 

Proof state:
case succ.succ
n m b : ℕ
hb : 1 < succ (succ b)
⊢ m < succ (succ b) ^ List.length (digits (succ (succ b)) m)

Next tactic:
simp_all
/-- Any number m is less than b^(number of digits in the base b representation of m) -/
theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by
  rcases b with (_ | _ | b) <;> try simp_all
  

Proof state:
case succ.succ
n m b : ℕ
⊢ m < succ (succ b) ^ List.length (digits (succ (succ b)) m)

Next tactic:
exact lt_base_pow_length_digits'
theorem ofDigits_digits_append_digits {b m n : ℕ} :
    ofDigits b (digits b n ++ digits b m) = n + b ^ (digits b n).length * m := by
  

Proof state:
n✝ b m n : ℕ
⊢ ofDigits b (digits b n ++ digits b m) = n + b ^ List.length (digits b n) * m

Next tactic:
rw [ofDigits_append, ofDigits_digits, ofDigits_digits]
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  

Proof state:
n✝ b m n : ℕ
hb : 0 < b
⊢ digits b n ++ digits b m = digits b (n + b ^ List.length (digits b n) * m)

Next tactic:
rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · 

Proof state:
case inl
n✝ m n : ℕ
hb : 0 < succ 0
⊢ digits (succ 0) n ++ digits (succ 0) m = digits (succ 0) (n + succ 0 ^ List.length (digits (succ 0) n) * m)

Next tactic:
simp [List.replicate_add]
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · simp [List.replicate_add]
  

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

Next tactic:
rw [← ofDigits_digits_append_digits]
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · simp [List.replicate_add]
  rw [← ofDigits_digits_append_digits]
  

Proof state:
case inr
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
⊢ digits b n ++ digits b m = digits b (ofDigits b (digits b n ++ digits b m))

Next tactic:
refine' (digits_ofDigits b hb _ (fun l hl => _) (fun h_append => _)).symm
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · simp [List.replicate_add]
  rw [← ofDigits_digits_append_digits]
  refine' (digits_ofDigits b hb _ (fun l hl => _) (fun h_append => _)).symm
  · 

Proof state:
case inr.refine'_1
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
l : ℕ
hl : l ∈ digits b n ++ digits b m
⊢ l < b

Next tactic:
rcases (List.mem_append.mp hl) with (h | h)
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · simp [List.replicate_add]
  rw [← ofDigits_digits_append_digits]
  refine' (digits_ofDigits b hb _ (fun l hl => _) (fun h_append => _)).symm
  · rcases (List.mem_append.mp hl) with (h | h) <;> 

Proof state:
case inr.refine'_1.inl
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
l : ℕ
hl : l ∈ digits b n ++ digits b m
h : l ∈ digits b n
⊢ l < b

Next tactic:
exact digits_lt_base hb h
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · simp [List.replicate_add]
  rw [← ofDigits_digits_append_digits]
  refine' (digits_ofDigits b hb _ (fun l hl => _) (fun h_append => _)).symm
  · rcases (List.mem_append.mp hl) with (h | h) <;> 

Proof state:
case inr.refine'_1.inr
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
l : ℕ
hl : l ∈ digits b n ++ digits b m
h : l ∈ digits b m
⊢ l < b

Next tactic:
exact digits_lt_base hb h
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · simp [List.replicate_add]
  rw [← ofDigits_digits_append_digits]
  refine' (digits_ofDigits b hb _ (fun l hl => _) (fun h_append => _)).symm
  · rcases (List.mem_append.mp hl) with (h | h) <;> exact digits_lt_base hb h
  · 

Proof state:
case inr.refine'_2
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append : digits b n ++ digits b m ≠ []
⊢ List.getLast (digits b n ++ digits b m) h_append ≠ 0

Next tactic:
by_cases h : digits b m = []
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · simp [List.replicate_add]
  rw [← ofDigits_digits_append_digits]
  refine' (digits_ofDigits b hb _ (fun l hl => _) (fun h_append => _)).symm
  · rcases (List.mem_append.mp hl) with (h | h) <;> exact digits_lt_base hb h
  · by_cases h : digits b m = []
    · 

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

Next tactic:
simp only [h, List.append_nil] at h_append ⊢
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · simp [List.replicate_add]
  rw [← ofDigits_digits_append_digits]
  refine' (digits_ofDigits b hb _ (fun l hl => _) (fun h_append => _)).symm
  · rcases (List.mem_append.mp hl) with (h | h) <;> exact digits_lt_base hb h
  · by_cases h : digits b m = []
    · simp only [h, List.append_nil] at h_append ⊢
      

Proof state:
case pos
n✝ b m n : ℕ
hb✝ : 0 < b
hb : succ 0 < b
h_append✝ : digits b n ++ digits b m ≠ []
h : digits b m = []
h_append : digits b n ≠ []
⊢ List.getLast (digits b n) (_ : digits b n ≠ []) ≠ 0

Next tactic:
exact getLast_digit_ne_zero b <| digits_ne_nil_iff_ne_zero.mp h_append
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
    digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
  rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
  · simp [List.replicate_add]
  rw [← ofDigits_digits_append_digits]
  refine' (digits_ofDigits b hb _ (fun l hl => _) (fun h_append => _)).symm
  · rcases (List.mem_append.mp hl) with (h | h) <;> exact digits_lt_base hb h
  · by_cases h : digits b m = []
    · simp only [h, List.append_nil] at h_append ⊢
      exact getLast_digit_ne_zero b <| digits_ne_nil_iff_ne_zero.mp h_append
    · 

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

Next tactic:
exact (List.getLast_append' _ _ h) ▸
          (getLast_digit_ne_zero _ <| digits_ne_nil_iff_ne_zero.mp h)
theorem digits_len_le_digits_len_succ (b n : ℕ) :
    (digits b n).length ≤ (digits b (n + 1)).length := by
  

Proof state:
n✝ b n : ℕ
⊢ List.length (digits b n) ≤ List.length (digits b (n + 1))

Next tactic:
rcases Decidable.eq_or_ne n 0 with (rfl | hn)
theorem digits_len_le_digits_len_succ (b n : ℕ) :
    (digits b n).length ≤ (digits b (n + 1)).length := by
  rcases Decidable.eq_or_ne n 0 with (rfl | hn)
  · 

Proof state:
case inl
n b : ℕ
⊢ List.length (digits b 0) ≤ List.length (digits b (0 + 1))

Next tactic:
simp
theorem digits_len_le_digits_len_succ (b n : ℕ) :
    (digits b n).length ≤ (digits b (n + 1)).length := by
  rcases Decidable.eq_or_ne n 0 with (rfl | hn)
  · simp
  

Proof state:
case inr
n✝ b n : ℕ
hn : n ≠ 0
⊢ List.length (digits b n) ≤ List.length (digits b (n + 1))

Next tactic:
rcases le_or_lt b 1 with hb | hb
theorem digits_len_le_digits_len_succ (b n : ℕ) :
    (digits b n).length ≤ (digits b (n + 1)).length := by
  rcases Decidable.eq_or_ne n 0 with (rfl | hn)
  · simp
  rcases le_or_lt b 1 with hb | hb
  · 

Proof state:
case inr.inl
n✝ b n : ℕ
hn : n ≠ 0
hb : b ≤ 1
⊢ List.length (digits b n) ≤ List.length (digits b (n + 1))

Next tactic:
interval_cases b
theorem digits_len_le_digits_len_succ (b n : ℕ) :
    (digits b n).length ≤ (digits b (n + 1)).length := by
  rcases Decidable.eq_or_ne n 0 with (rfl | hn)
  · simp
  rcases le_or_lt b 1 with hb | hb
  · interval_cases b <;> 

Proof state:
case inr.inl.«0»
n✝ b n : ℕ
hn : n ≠ 0
hb : 0 ≤ 1
⊢ List.length (digits 0 n) ≤ List.length (digits 0 (n + 1))

Next tactic:
simp_arith [digits_zero_succ', hn]
theorem digits_len_le_digits_len_succ (b n : ℕ) :
    (digits b n).length ≤ (digits b (n + 1)).length := by
  rcases Decidable.eq_or_ne n 0 with (rfl | hn)
  · simp
  rcases le_or_lt b 1 with hb | hb
  · interval_cases b <;> 

Proof state:
case inr.inl.«1»
n✝ b n : ℕ
hn : n ≠ 0
hb : 1 ≤ 1
⊢ List.length (digits 1 n) ≤ List.length (digits 1 (n + 1))

Next tactic:
simp_arith [digits_zero_succ', hn]
theorem digits_len_le_digits_len_succ (b n : ℕ) :
    (digits b n).length ≤ (digits b (n + 1)).length := by
  rcases Decidable.eq_or_ne n 0 with (rfl | hn)
  · simp
  rcases le_or_lt b 1 with hb | hb
  · interval_cases b <;> simp_arith [digits_zero_succ', hn]
  

Proof state:
case inr.inr
n✝ b n : ℕ
hn : n ≠ 0
hb : 1 < b
⊢ List.length (digits b n) ≤ List.length (digits b (n + 1))

Next tactic:
simpa [digits_len, hb, hn] using log_mono_right (le_succ _)
@[mono]
theorem ofDigits_monotone {p q : ℕ} (L : List ℕ) (h : p ≤ q) : ofDigits p L ≤ ofDigits q L := by
  

Proof state:
n p q : ℕ
L : List ℕ
h : p ≤ q
⊢ ofDigits p L ≤ ofDigits q L

Next tactic:
induction' L with _ _ hi
@[mono]
theorem ofDigits_monotone {p q : ℕ} (L : List ℕ) (h : p ≤ q) : ofDigits p L ≤ ofDigits q L := by
  induction' L with _ _ hi
  · 

Proof state:
case nil
n p q : ℕ
h : p ≤ q
⊢ ofDigits p [] ≤ ofDigits q []

Next tactic:
rfl
@[mono]
theorem ofDigits_monotone {p q : ℕ} (L : List ℕ) (h : p ≤ q) : ofDigits p L ≤ ofDigits q L := by
  induction' L with _ _ hi
  · rfl
  · 

Proof state:
case cons
n p q : ℕ
h : p ≤ q
head✝ : ℕ
tail✝ : List ℕ
hi : ofDigits p tail✝ ≤ ofDigits q tail✝
⊢ ofDigits p (head✝ :: tail✝) ≤ ofDigits q (head✝ :: tail✝)

Next tactic:
simp only [ofDigits, cast_id, add_le_add_iff_left]
@[mono]
theorem ofDigits_monotone {p q : ℕ} (L : List ℕ) (h : p ≤ q) : ofDigits p L ≤ ofDigits q L := by
  induction' L with _ _ hi
  · rfl
  · simp only [ofDigits, cast_id, add_le_add_iff_left]
    

Proof state:
case cons
n p q : ℕ
h : p ≤ q
head✝ : ℕ
tail✝ : List ℕ
hi : ofDigits p tail✝ ≤ ofDigits q tail✝
⊢ p * ofDigits p tail✝ ≤ q * ofDigits q tail✝

Next tactic:
exact Nat.mul_le_mul h hi
theorem digit_sum_le (p n : ℕ) : List.sum (digits p n) ≤ n := by
  

Proof state:
n✝ p n : ℕ
⊢ List.sum (digits p n) ≤ n

Next tactic:
induction' n with n
theorem digit_sum_le (p n : ℕ) : List.sum (digits p n) ≤ n := by
  induction' n with n
  · 

Proof state:
case zero
n p : ℕ
⊢ List.sum (digits p zero) ≤ zero

Next tactic:
exact digits_zero _ ▸ Nat.le_refl (List.sum [])