l3lab/ntp-mathlib huggingface dataset:
theorem digit_sum_le (p n : ℕ) : List.sum (digits p n) ≤ n := by
  induction' n with n
  · exact digits_zero _ ▸ Nat.le_refl (List.sum [])
  · 

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

Next tactic:
induction' p with p
theorem digit_sum_le (p n : ℕ) : List.sum (digits p n) ≤ n := by
  induction' n with n
  · exact digits_zero _ ▸ Nat.le_refl (List.sum [])
  · induction' p with p
    · 

Proof state:
case succ.zero
n✝ n : ℕ
n_ih✝ : List.sum (digits zero n) ≤ n
⊢ List.sum (digits zero (succ n)) ≤ succ n

Next tactic:
rw [digits_zero_succ, List.sum_cons, List.sum_nil, add_zero]
theorem digit_sum_le (p n : ℕ) : List.sum (digits p n) ≤ n := by
  induction' n with n
  · exact digits_zero _ ▸ Nat.le_refl (List.sum [])
  · induction' p with p
    · rw [digits_zero_succ, List.sum_cons, List.sum_nil, add_zero]
    · 

Proof state:
case succ.succ
n✝ n p : ℕ
n_ih✝¹ : List.sum (digits p n) ≤ n → List.sum (digits p (succ n)) ≤ succ n
n_ih✝ : List.sum (digits (succ p) n) ≤ n
⊢ List.sum (digits (succ p) (succ n)) ≤ succ n

Next tactic:
nth_rw 2 [← ofDigits_digits p.succ n.succ]
theorem digit_sum_le (p n : ℕ) : List.sum (digits p n) ≤ n := by
  induction' n with n
  · exact digits_zero _ ▸ Nat.le_refl (List.sum [])
  · induction' p with p
    · rw [digits_zero_succ, List.sum_cons, List.sum_nil, add_zero]
    · nth_rw 2 [← ofDigits_digits p.succ n.succ]
      

Proof state:
case succ.succ
n✝ n p : ℕ
n_ih✝¹ : List.sum (digits p n) ≤ n → List.sum (digits p (succ n)) ≤ succ n
n_ih✝ : List.sum (digits (succ p) n) ≤ n
⊢ List.sum (digits (succ p) (succ n)) ≤ ofDigits (succ p) (digits (succ p) (succ n))

Next tactic:
rw [← ofDigits_one <| digits p.succ n.succ]
theorem digit_sum_le (p n : ℕ) : List.sum (digits p n) ≤ n := by
  induction' n with n
  · exact digits_zero _ ▸ Nat.le_refl (List.sum [])
  · induction' p with p
    · rw [digits_zero_succ, List.sum_cons, List.sum_nil, add_zero]
    · nth_rw 2 [← ofDigits_digits p.succ n.succ]
      rw [← ofDigits_one <| digits p.succ n.succ]
      

Proof state:
case succ.succ
n✝ n p : ℕ
n_ih✝¹ : List.sum (digits p n) ≤ n → List.sum (digits p (succ n)) ≤ succ n
n_ih✝ : List.sum (digits (succ p) n) ≤ n
⊢ ofDigits 1 (digits (succ p) (succ n)) ≤ ofDigits (succ p) (digits (succ p) (succ n))

Next tactic:
exact ofDigits_monotone (digits p.succ n.succ) <| Nat.succ_pos p
theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) :
    (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by
  

Proof state:
n b : ℕ
l : List ℕ
hl : l ≠ []
hl2 : List.getLast l hl ≠ 0
⊢ (b + 2) ^ List.length l ≤ (b + 2) * ofDigits (b + 2) l

Next tactic:
rw [← List.dropLast_append_getLast hl]
theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) :
    (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by
  rw [← List.dropLast_append_getLast hl]
  

Proof state:
n b : ℕ
l : List ℕ
hl : l ≠ []
hl2 : List.getLast l hl ≠ 0
⊢ (b + 2) ^ List.length (List.dropLast l ++ [List.getLast l hl]) ≤
    (b + 2) * ofDigits (b + 2) (List.dropLast l ++ [List.getLast l hl])

Next tactic:
simp only [List.length_append, List.length, zero_add, List.length_dropLast, ofDigits_append,
    List.length_dropLast, ofDigits_singleton, add_comm (l.length - 1), pow_add, pow_one]
theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) :
    (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by
  rw [← List.dropLast_append_getLast hl]
  simp only [List.length_append, List.length, zero_add, List.length_dropLast, ofDigits_append,
    List.length_dropLast, ofDigits_singleton, add_comm (l.length - 1), pow_add, pow_one]
  

Proof state:
n b : ℕ
l : List ℕ
hl : l ≠ []
hl2 : List.getLast l hl ≠ 0
⊢ (b + 2) * (b + 2) ^ (List.length l - 1) ≤
    (b + 2) * (ofDigits (b + 2) (List.dropLast l) + (b + 2) ^ (List.length l - 1) * List.getLast l hl)

Next tactic:
apply Nat.mul_le_mul_left
theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) :
    (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by
  rw [← List.dropLast_append_getLast hl]
  simp only [List.length_append, List.length, zero_add, List.length_dropLast, ofDigits_append,
    List.length_dropLast, ofDigits_singleton, add_comm (l.length - 1), pow_add, pow_one]
  apply Nat.mul_le_mul_left
  

Proof state:
case h
n b : ℕ
l : List ℕ
hl : l ≠ []
hl2 : List.getLast l hl ≠ 0
⊢ (b + 2) ^ (List.length l - 1) ≤ ofDigits (b + 2) (List.dropLast l) + (b + 2) ^ (List.length l - 1) * List.getLast l hl

Next tactic:
refine' le_trans _ (Nat.le_add_left _ _)
theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) :
    (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by
  rw [← List.dropLast_append_getLast hl]
  simp only [List.length_append, List.length, zero_add, List.length_dropLast, ofDigits_append,
    List.length_dropLast, ofDigits_singleton, add_comm (l.length - 1), pow_add, pow_one]
  apply Nat.mul_le_mul_left
  refine' le_trans _ (Nat.le_add_left _ _)
  

Proof state:
case h
n b : ℕ
l : List ℕ
hl : l ≠ []
hl2 : List.getLast l hl ≠ 0
⊢ (b + 2) ^ (List.length l - 1) ≤ (b + 2) ^ (List.length l - 1) * List.getLast l hl

Next tactic:
have : 0 < l.getLast hl := by rwa [pos_iff_ne_zero]
theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) :
    (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by
  rw [← List.dropLast_append_getLast hl]
  simp only [List.length_append, List.length, zero_add, List.length_dropLast, ofDigits_append,
    List.length_dropLast, ofDigits_singleton, add_comm (l.length - 1), pow_add, pow_one]
  apply Nat.mul_le_mul_left
  refine' le_trans _ (Nat.le_add_left _ _)
  have : 0 < l.getLast hl := by 

Proof state:
n b : ℕ
l : List ℕ
hl : l ≠ []
hl2 : List.getLast l hl ≠ 0
⊢ 0 < List.getLast l hl

Next tactic:
rwa [pos_iff_ne_zero]
theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) :
    (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by
  rw [← List.dropLast_append_getLast hl]
  simp only [List.length_append, List.length, zero_add, List.length_dropLast, ofDigits_append,
    List.length_dropLast, ofDigits_singleton, add_comm (l.length - 1), pow_add, pow_one]
  apply Nat.mul_le_mul_left
  refine' le_trans _ (Nat.le_add_left _ _)
  have : 0 < l.getLast hl := by rwa [pos_iff_ne_zero]
  

Proof state:
case h
n b : ℕ
l : List ℕ
hl : l ≠ []
hl2 : List.getLast l hl ≠ 0
this : 0 < List.getLast l hl
⊢ (b + 2) ^ (List.length l - 1) ≤ (b + 2) ^ (List.length l - 1) * List.getLast l hl

Next tactic:
convert Nat.mul_le_mul_left ((b + 2) ^ (l.length - 1)) this using 1
theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) :
    (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by
  rw [← List.dropLast_append_getLast hl]
  simp only [List.length_append, List.length, zero_add, List.length_dropLast, ofDigits_append,
    List.length_dropLast, ofDigits_singleton, add_comm (l.length - 1), pow_add, pow_one]
  apply Nat.mul_le_mul_left
  refine' le_trans _ (Nat.le_add_left _ _)
  have : 0 < l.getLast hl := by rwa [pos_iff_ne_zero]
  convert Nat.mul_le_mul_left ((b + 2) ^ (l.length - 1)) this using 1
  

Proof state:
case h.e'_3
n b : ℕ
l : List ℕ
hl : l ≠ []
hl2 : List.getLast l hl ≠ 0
this : 0 < List.getLast l hl
⊢ (b + 2) ^ (List.length l - 1) = (b + 2) ^ (List.length l - 1) * succ 0

Next tactic:
rw [Nat.mul_one]
/-- Any non-zero natural number `m` is greater than
(b+2)^((number of digits in the base (b+2) representation of m) - 1)
-/
theorem base_pow_length_digits_le' (b m : ℕ) (hm : m ≠ 0) :
    (b + 2) ^ (digits (b + 2) m).length ≤ (b + 2) * m := by
  

Proof state:
n b m : ℕ
hm : m ≠ 0
⊢ (b + 2) ^ List.length (digits (b + 2) m) ≤ (b + 2) * m

Next tactic:
have : digits (b + 2) m ≠ [] := digits_ne_nil_iff_ne_zero.mpr hm
/-- Any non-zero natural number `m` is greater than
(b+2)^((number of digits in the base (b+2) representation of m) - 1)
-/
theorem base_pow_length_digits_le' (b m : ℕ) (hm : m ≠ 0) :
    (b + 2) ^ (digits (b + 2) m).length ≤ (b + 2) * m := by
  have : digits (b + 2) m ≠ [] := digits_ne_nil_iff_ne_zero.mpr hm
  

Proof state:
n b m : ℕ
hm : m ≠ 0
this : digits (b + 2) m ≠ []
⊢ (b + 2) ^ List.length (digits (b + 2) m) ≤ (b + 2) * m

Next tactic:
convert @pow_length_le_mul_ofDigits b (digits (b+2) m)
    this (getLast_digit_ne_zero _ hm)
/-- Any non-zero natural number `m` is greater than
(b+2)^((number of digits in the base (b+2) representation of m) - 1)
-/
theorem base_pow_length_digits_le' (b m : ℕ) (hm : m ≠ 0) :
    (b + 2) ^ (digits (b + 2) m).length ≤ (b + 2) * m := by
  have : digits (b + 2) m ≠ [] := digits_ne_nil_iff_ne_zero.mpr hm
  convert @pow_length_le_mul_ofDigits b (digits (b+2) m)
    this (getLast_digit_ne_zero _ hm)
  

Proof state:
case h.e'_4.h.e'_6
n b m : ℕ
hm : m ≠ 0
this : digits (b + 2) m ≠ []
⊢ m = ofDigits (b + 2) (digits (b + 2) m)

Next tactic:
rw [ofDigits_digits]
/-- Any non-zero natural number `m` is greater than
b^((number of digits in the base b representation of m) - 1)
-/
theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) :
    m ≠ 0 → b ^ (digits b m).length ≤ b * m := by
  

Proof state:
n b m : ℕ
hb : 1 < b
⊢ m ≠ 0 → b ^ List.length (digits b m) ≤ b * m

Next tactic:
rcases b with (_ | _ | b)
/-- Any non-zero natural number `m` is greater than
b^((number of digits in the base b representation of m) - 1)
-/
theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) :
    m ≠ 0 → b ^ (digits b m).length ≤ b * m := by
  rcases b with (_ | _ | b) <;> 

Proof state:
case zero
n m : ℕ
hb : 1 < zero
⊢ m ≠ 0 → zero ^ List.length (digits zero m) ≤ zero * m

Next tactic:
try simp_all
/-- Any non-zero natural number `m` is greater than
b^((number of digits in the base b representation of m) - 1)
-/
theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) :
    m ≠ 0 → b ^ (digits b m).length ≤ b * m := by
  rcases b with (_ | _ | b) <;> try 

Proof state:
case zero
n m : ℕ
hb : 1 < zero
⊢ m ≠ 0 → zero ^ List.length (digits zero m) ≤ zero * m

Next tactic:
simp_all
/-- Any non-zero natural number `m` is greater than
b^((number of digits in the base b representation of m) - 1)
-/
theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) :
    m ≠ 0 → b ^ (digits b m).length ≤ b * m := by
  rcases b with (_ | _ | b) <;> 

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

Next tactic:
try simp_all
/-- Any non-zero natural number `m` is greater than
b^((number of digits in the base b representation of m) - 1)
-/
theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) :
    m ≠ 0 → b ^ (digits b m).length ≤ b * m := by
  rcases b with (_ | _ | b) <;> try 

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

Next tactic:
simp_all
/-- Any non-zero natural number `m` is greater than
b^((number of digits in the base b representation of m) - 1)
-/
theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) :
    m ≠ 0 → b ^ (digits b m).length ≤ b * m := by
  rcases b with (_ | _ | b) <;> 

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

Next tactic:
try simp_all
/-- Any non-zero natural number `m` is greater than
b^((number of digits in the base b representation of m) - 1)
-/
theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) :
    m ≠ 0 → b ^ (digits b m).length ≤ b * m := by
  rcases b with (_ | _ | b) <;> try 

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

Next tactic:
simp_all
/-- Any non-zero natural number `m` is greater than
b^((number of digits in the base b representation of m) - 1)
-/
theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) :
    m ≠ 0 → b ^ (digits b m).length ≤ b * m := by
  rcases b with (_ | _ | b) <;> try simp_all
  

Proof state:
case succ.succ
n m b : ℕ
⊢ ¬m = 0 → succ (succ b) ^ List.length (digits (succ (succ b)) m) ≤ succ (succ b) * m

Next tactic:
exact base_pow_length_digits_le' b m
/-- Interpreting as a base `p` number and dividing by `p` is the same as interpreting the tail.
-/
lemma ofDigits_div_eq_ofDigits_tail (hpos : 0 < p) (digits : List ℕ)
    (w₁ : ∀ l ∈ digits, l < p) : ofDigits p digits / p = ofDigits p digits.tail := by
  

Proof state:
n p : ℕ
hpos : 0 < p
digits : List ℕ
w₁ : ∀ l ∈ digits, l < p
⊢ ofDigits p digits / p = ofDigits p (List.tail digits)

Next tactic:
induction' digits with hd tl
/-- Interpreting as a base `p` number and dividing by `p` is the same as interpreting the tail.
-/
lemma ofDigits_div_eq_ofDigits_tail (hpos : 0 < p) (digits : List ℕ)
    (w₁ : ∀ l ∈ digits, l < p) : ofDigits p digits / p = ofDigits p digits.tail := by
  induction' digits with hd tl
  · 

Proof state:
case nil
n p : ℕ
hpos : 0 < p
w₁ : ∀ l ∈ [], l < p
⊢ ofDigits p [] / p = ofDigits p (List.tail [])

Next tactic:
simp [ofDigits]
/-- Interpreting as a base `p` number and dividing by `p` is the same as interpreting the tail.
-/
lemma ofDigits_div_eq_ofDigits_tail (hpos : 0 < p) (digits : List ℕ)
    (w₁ : ∀ l ∈ digits, l < p) : ofDigits p digits / p = ofDigits p digits.tail := by
  induction' digits with hd tl
  · simp [ofDigits]
  · 

Proof state:
case cons
n p : ℕ
hpos : 0 < p
hd : ℕ
tl : List ℕ
tail_ih✝ : (∀ l ∈ tl, l < p) → ofDigits p tl / p = ofDigits p (List.tail tl)
w₁ : ∀ l ∈ hd :: tl, l < p
⊢ ofDigits p (hd :: tl) / p = ofDigits p (List.tail (hd :: tl))

Next tactic:
refine' Eq.trans (add_mul_div_left hd _ hpos) _
/-- Interpreting as a base `p` number and dividing by `p` is the same as interpreting the tail.
-/
lemma ofDigits_div_eq_ofDigits_tail (hpos : 0 < p) (digits : List ℕ)
    (w₁ : ∀ l ∈ digits, l < p) : ofDigits p digits / p = ofDigits p digits.tail := by
  induction' digits with hd tl
  · simp [ofDigits]
  · refine' Eq.trans (add_mul_div_left hd _ hpos) _
    

Proof state:
case cons
n p : ℕ
hpos : 0 < p
hd : ℕ
tl : List ℕ
tail_ih✝ : (∀ l ∈ tl, l < p) → ofDigits p tl / p = ofDigits p (List.tail tl)
w₁ : ∀ l ∈ hd :: tl, l < p
⊢ hd / p + ofDigits p tl = ofDigits p (List.tail (hd :: tl))

Next tactic:
rw [Nat.div_eq_of_lt <| w₁ _ <| List.mem_cons_self _ _, zero_add]
/-- Interpreting as a base `p` number and dividing by `p` is the same as interpreting the tail.
-/
lemma ofDigits_div_eq_ofDigits_tail (hpos : 0 < p) (digits : List ℕ)
    (w₁ : ∀ l ∈ digits, l < p) : ofDigits p digits / p = ofDigits p digits.tail := by
  induction' digits with hd tl
  · simp [ofDigits]
  · refine' Eq.trans (add_mul_div_left hd _ hpos) _
    rw [Nat.div_eq_of_lt <| w₁ _ <| List.mem_cons_self _ _, zero_add]
    

Proof state:
case cons
n p : ℕ
hpos : 0 < p
hd : ℕ
tl : List ℕ
tail_ih✝ : (∀ l ∈ tl, l < p) → ofDigits p tl / p = ofDigits p (List.tail tl)
w₁ : ∀ l ∈ hd :: tl, l < p
⊢ ofDigits p tl = ofDigits p (List.tail (hd :: tl))

Next tactic:
rfl
/-- Interpreting as a base `p` number and dividing by `p^i` is the same as dropping `i`.
-/
lemma ofDigits_div_pow_eq_ofDigits_drop
    (i : ℕ) (hpos : 0 < p) (digits : List ℕ) (w₁ : ∀ l ∈ digits, l < p) :
    ofDigits p digits / p ^ i = ofDigits p (digits.drop i) := by
  

Proof state:
n p i : ℕ
hpos : 0 < p
digits : List ℕ
w₁ : ∀ l ∈ digits, l < p
⊢ ofDigits p digits / p ^ i = ofDigits p (List.drop i digits)

Next tactic:
induction' i with i hi
/-- Interpreting as a base `p` number and dividing by `p^i` is the same as dropping `i`.
-/
lemma ofDigits_div_pow_eq_ofDigits_drop
    (i : ℕ) (hpos : 0 < p) (digits : List ℕ) (w₁ : ∀ l ∈ digits, l < p) :
    ofDigits p digits / p ^ i = ofDigits p (digits.drop i) := by
  induction' i with i hi
  · 

Proof state:
case zero
n p : ℕ
hpos : 0 < p
digits : List ℕ
w₁ : ∀ l ∈ digits, l < p
⊢ ofDigits p digits / p ^ zero = ofDigits p (List.drop zero digits)

Next tactic:
simp
/-- Interpreting as a base `p` number and dividing by `p^i` is the same as dropping `i`.
-/
lemma ofDigits_div_pow_eq_ofDigits_drop
    (i : ℕ) (hpos : 0 < p) (digits : List ℕ) (w₁ : ∀ l ∈ digits, l < p) :
    ofDigits p digits / p ^ i = ofDigits p (digits.drop i) := by
  induction' i with i hi
  · simp
  · 

Proof state:
case succ
n p : ℕ
hpos : 0 < p
digits : List ℕ
w₁ : ∀ l ∈ digits, l < p
i : ℕ
hi : ofDigits p digits / p ^ i = ofDigits p (List.drop i digits)
⊢ ofDigits p digits / p ^ succ i = ofDigits p (List.drop (succ i) digits)

Next tactic:
rw [Nat.pow_succ, ← Nat.div_div_eq_div_mul, hi, ofDigits_div_eq_ofDigits_tail hpos
      (List.drop i digits) <| fun x hx ↦ w₁ x <| List.mem_of_mem_drop hx, ← List.drop_one,
      List.drop_drop, add_comm]
/-- Dividing `n` by `p^i` is like truncating the first `i` digits of `n` in base `p`.
-/
lemma self_div_pow_eq_ofDigits_drop (i n : ℕ) (h : 2 ≤ p):
    n / p ^ i = ofDigits p ((p.digits n).drop i) := by
  

Proof state:
n✝ p i n : ℕ
h : 2 ≤ p
⊢ n / p ^ i = ofDigits p (List.drop i (digits p n))

Next tactic:
convert ofDigits_div_pow_eq_ofDigits_drop i (zero_lt_of_lt h) (p.digits n)
    (fun l hl ↦ digits_lt_base h hl)
/-- Dividing `n` by `p^i` is like truncating the first `i` digits of `n` in base `p`.
-/
lemma self_div_pow_eq_ofDigits_drop (i n : ℕ) (h : 2 ≤ p):
    n / p ^ i = ofDigits p ((p.digits n).drop i) := by
  convert ofDigits_div_pow_eq_ofDigits_drop i (zero_lt_of_lt h) (p.digits n)
    (fun l hl ↦ digits_lt_base h hl)
  

Proof state:
case h.e'_2.h.e'_5
n✝ p i n : ℕ
h : 2 ≤ p
⊢ n = ofDigits p (digits p n)

Next tactic:
exact (ofDigits_digits p n).symm
theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits
    (L : List ℕ) {h_nonempty} (h_ne_zero : L.getLast h_nonempty ≠ 0) (h_lt : ∀ l ∈ L, l < p) :
    (p - 1) * ∑ i in range L.length, (ofDigits p L) / p ^ i.succ = (ofDigits p L) - L.sum := by
  

Proof state:
n p : ℕ
L : List ℕ
h_nonempty : L ≠ []
h_ne_zero : List.getLast L h_nonempty ≠ 0
h_lt : ∀ l ∈ L, l < p
⊢ (p - 1) * ∑ i in range (List.length L), ofDigits p L / p ^ succ i = ofDigits p L - List.sum L

Next tactic:
obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p
theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits
    (L : List ℕ) {h_nonempty} (h_ne_zero : L.getLast h_nonempty ≠ 0) (h_lt : ∀ l ∈ L, l < p) :
    (p - 1) * ∑ i in range L.length, (ofDigits p L) / p ^ i.succ = (ofDigits p L) - L.sum := by
  obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p
  · 

Proof state:
case inl
n p : ℕ
L : List ℕ
h_nonempty : L ≠ []
h_ne_zero : List.getLast L h_nonempty ≠ 0
h_lt : ∀ l ∈ L, l < p
h : 1 < p
⊢ (p - 1) * ∑ i in range (List.length L), ofDigits p L / p ^ succ i = ofDigits p L - List.sum L

Next tactic:
induction' L with hd tl ih
theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits
    (L : List ℕ) {h_nonempty} (h_ne_zero : L.getLast h_nonempty ≠ 0) (h_lt : ∀ l ∈ L, l < p) :
    (p - 1) * ∑ i in range L.length, (ofDigits p L) / p ^ i.succ = (ofDigits p L) - L.sum := by
  obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p
  · induction' L with hd tl ih
    · 

Proof state:
case inl.nil
n p : ℕ
h : 1 < p
h_nonempty : [] ≠ []
h_ne_zero : List.getLast [] h_nonempty ≠ 0
h_lt : ∀ l ∈ [], l < p
⊢ (p - 1) * ∑ i in range (List.length []), ofDigits p [] / p ^ succ i = ofDigits p [] - List.sum []

Next tactic:
simp [ofDigits]
theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits
    (L : List ℕ) {h_nonempty} (h_ne_zero : L.getLast h_nonempty ≠ 0) (h_lt : ∀ l ∈ L, l < p) :
    (p - 1) * ∑ i in range L.length, (ofDigits p L) / p ^ i.succ = (ofDigits p L) - L.sum := by
  obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p
  · induction' L with hd tl ih
    · simp [ofDigits]
    · 

Proof state:
case inl.cons
n p : ℕ
h : 1 < p
hd : ℕ
tl : List ℕ
ih :
  ∀ {h_nonempty : tl ≠ []},
    List.getLast tl h_nonempty ≠ 0 →
      (∀ l ∈ tl, l < p) →
        (p - 1) * ∑ i in range (List.length tl), ofDigits p tl / p ^ succ i = ofDigits p tl - List.sum tl
h_nonempty : hd :: tl ≠ []
h_ne_zero : List.getLast (hd :: tl) h_nonempty ≠ 0
h_lt : ∀ l ∈ hd :: tl, l < p
⊢ (p - 1) * ∑ i in range (List.length (hd :: tl)), ofDigits p (hd :: tl) / p ^ succ i =
    ofDigits p (hd :: tl) - List.sum (hd :: tl)

Next tactic:
simp only [List.length_cons, List.sum_cons, self_div_pow_eq_ofDigits_drop _ _ h,
          digits_ofDigits p h (hd :: tl) h_lt (fun _ => h_ne_zero)]
theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits
    (L : List ℕ) {h_nonempty} (h_ne_zero : L.getLast h_nonempty ≠ 0) (h_lt : ∀ l ∈ L, l < p) :
    (p - 1) * ∑ i in range L.length, (ofDigits p L) / p ^ i.succ = (ofDigits p L) - L.sum := by
  obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p
  · induction' L with hd tl ih
    · simp [ofDigits]
    · simp only [List.length_cons, List.sum_cons, self_div_pow_eq_ofDigits_drop _ _ h,
          digits_ofDigits p h (hd :: tl) h_lt (fun _ => h_ne_zero)]
      

Proof state:
case inl.cons
n p : ℕ
h : 1 < p
hd : ℕ
tl : List ℕ
ih :
  ∀ {h_nonempty : tl ≠ []},
    List.getLast tl h_nonempty ≠ 0 →
      (∀ l ∈ tl, l < p) →
        (p - 1) * ∑ i in range (List.length tl), ofDigits p tl / p ^ succ i = ofDigits p tl - List.sum tl
h_nonempty : hd :: tl ≠ []
h_ne_zero : List.getLast (hd :: tl) h_nonempty ≠ 0
h_lt : ∀ l ∈ hd :: tl, l < p
⊢ (p - 1) * ∑ x in range (succ (List.length tl)), ofDigits p (List.drop (succ x) (hd :: tl)) =
    ofDigits p (hd :: tl) - (hd + List.sum tl)

Next tactic:
simp only [ofDigits]
theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits
    (L : List ℕ) {h_nonempty} (h_ne_zero : L.getLast h_nonempty ≠ 0) (h_lt : ∀ l ∈ L, l < p) :
    (p - 1) * ∑ i in range L.length, (ofDigits p L) / p ^ i.succ = (ofDigits p L) - L.sum := by
  obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p
  · induction' L with hd tl ih
    · simp [ofDigits]
    · simp only [List.length_cons, List.sum_cons, self_div_pow_eq_ofDigits_drop _ _ h,
          digits_ofDigits p h (hd :: tl) h_lt (fun _ => h_ne_zero)]
      simp only [ofDigits]
      

Proof state:
case inl.cons
n p : ℕ
h : 1 < p
hd : ℕ
tl : List ℕ
ih :
  ∀ {h_nonempty : tl ≠ []},
    List.getLast tl h_nonempty ≠ 0 →
      (∀ l ∈ tl, l < p) →
        (p - 1) * ∑ i in range (List.length tl), ofDigits p tl / p ^ succ i = ofDigits p tl - List.sum tl
h_nonempty : hd :: tl ≠ []
h_ne_zero : List.getLast (hd :: tl) h_nonempty ≠ 0
h_lt : ∀ l ∈ hd :: tl, l < p
⊢ (p - 1) * ∑ x in range (succ (List.length tl)), ofDigits p (List.drop (succ x) (hd :: tl)) =
    ↑hd + p * ofDigits p tl - (hd + List.sum tl)

Next tactic:
rw [sum_range_succ, Nat.cast_id]
theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits
    (L : List ℕ) {h_nonempty} (h_ne_zero : L.getLast h_nonempty ≠ 0) (h_lt : ∀ l ∈ L, l < p) :
    (p - 1) * ∑ i in range L.length, (ofDigits p L) / p ^ i.succ = (ofDigits p L) - L.sum := by
  obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p
  · induction' L with hd tl ih
    · simp [ofDigits]
    · simp only [List.length_cons, List.sum_cons, self_div_pow_eq_ofDigits_drop _ _ h,
          digits_ofDigits p h (hd :: tl) h_lt (fun _ => h_ne_zero)]
      simp only [ofDigits]
      rw [sum_range_succ, Nat.cast_id]
      

Proof state:
case inl.cons
n p : ℕ
h : 1 < p
hd : ℕ
tl : List ℕ
ih :
  ∀ {h_nonempty : tl ≠ []},
    List.getLast tl h_nonempty ≠ 0 →
      (∀ l ∈ tl, l < p) →
        (p - 1) * ∑ i in range (List.length tl), ofDigits p tl / p ^ succ i = ofDigits p tl - List.sum tl
h_nonempty : hd :: tl ≠ []
h_ne_zero : List.getLast (hd :: tl) h_nonempty ≠ 0
h_lt : ∀ l ∈ hd :: tl, l < p
⊢ (p - 1) *
      (∑ x in range (List.length tl), ofDigits p (List.drop (succ x) (hd :: tl)) +
        ofDigits p (List.drop (succ (List.length tl)) (hd :: tl))) =
    hd + p * ofDigits p tl - (hd + List.sum tl)

Next tactic:
simp only [List.drop, List.drop_length]