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

tactic: obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p
state_before: n✝ p n : ℕ
⊢ (p - 1) * ∑ i ∈ range (log p n).succ, n / p ^ i.succ = n - (p.digits n).sum
state_after: case inl
n✝ p n : ℕ
h : 1 < p
⊢ (p - 1) * ∑ i ∈ range (log p n).succ, n / p ^ i.succ = n - (p.digits n).sum

case inr.inl
n✝ n : ℕ
⊢ (1 - 1) * ∑ i ∈ range (log 1 n).succ, n / 1 ^ i.succ = n - (digits 1 n).sum

case inr.inr
n✝ p n : ℕ
h : p < 1
⊢ (p - 1) * ∑ i ∈ range (log p n).succ, n / p ^ i.succ = n - (p.digits n).sum

tactic: rcases eq_or_ne n 0 with rfl | hn
state_before: case inl
n✝ p n : ℕ
h : 1 < p
⊢ (p - 1) * ∑ i ∈ range (log p n).succ, n / p ^ i.succ = n - (p.digits n).sum
state_after: case inl.inl
n p : ℕ
h : 1 < p
⊢ (p - 1) * ∑ i ∈ range (log p 0).succ, 0 / p ^ i.succ = 0 - (p.digits 0).sum

case inl.inr
n✝ p n : ℕ
h : 1 < p
hn : n ≠ 0
⊢ (p - 1) * ∑ i ∈ range (log p n).succ, n / p ^ i.succ = n - (p.digits n).sum

tactic: simp
state_before: case inl.inl
n p : ℕ
h : 1 < p
⊢ (p - 1) * ∑ i ∈ range (log p 0).succ, 0 / p ^ i.succ = 0 - (p.digits 0).sum
state_after: no goals

tactic: convert sub_one_mul_sum_div_pow_eq_sub_sum_digits (p.digits n) (getLast_digit_ne_zero p hn) <|
    (fun l a ↦ digits_lt_base h a)
state_before: case inl.inr
n✝ p n : ℕ
h : 1 < p
hn : n ≠ 0
⊢ (p - 1) * ∑ i ∈ range (log p n).succ, n / p ^ i.succ = n - (p.digits n).sum
state_after: case h.e'_2.h.e'_6.h.h.e'_1
n✝ p n : ℕ
h : 1 < p
hn : n ≠ 0
⊢ (log p n).succ = (p.digits n).length

case h.e'_2.h.e'_6.a.h.e'_5
n✝ p n : ℕ
h : 1 < p
hn : n ≠ 0
x✝ : ℕ
a✝ : x✝ ∈ range (p.digits n).length
⊢ n = ofDigits p (p.digits n)

case h.e'_3.h.e'_5
n✝ p n : ℕ
h : 1 < p
hn : n ≠ 0
⊢ n = ofDigits p (p.digits n)

tactic: all_goals exact (ofDigits_digits p n).symm
state_before: case h.e'_2.h.e'_6.a.h.e'_5
n✝ p n : ℕ
h : 1 < p
hn : n ≠ 0
x✝ : ℕ
a✝ : x✝ ∈ range (p.digits n).length
⊢ n = ofDigits p (p.digits n)

case h.e'_3.h.e'_5
n✝ p n : ℕ
h : 1 < p
hn : n ≠ 0
⊢ n = ofDigits p (p.digits n)
state_after: no goals

tactic: refine (digits_len p n h hn).symm
state_before: case h.e'_2.h.e'_6.h.h.e'_1
n✝ p n : ℕ
h : 1 < p
hn : n ≠ 0
⊢ (log p n).succ = (p.digits n).length
state_after: no goals

tactic: exact (ofDigits_digits p n).symm
state_before: case h.e'_3.h.e'_5
n✝ p n : ℕ
h : 1 < p
hn : n ≠ 0
⊢ n = ofDigits p (p.digits n)
state_after: no goals

tactic: simp
state_before: case inr.inl
n✝ n : ℕ
⊢ (1 - 1) * ∑ i ∈ range (log 1 n).succ, n / 1 ^ i.succ = n - (digits 1 n).sum
state_after: no goals

tactic: simp [lt_one_iff.mp h]
state_before: case inr.inr
n✝ p n : ℕ
h : p < 1
⊢ (p - 1) * ∑ i ∈ range (log p n).succ, n / p ^ i.succ = n - (p.digits n).sum
state_after: case inr.inr
n✝ p n : ℕ
h : p < 1
⊢ 0 = n - (digits 0 n).sum

tactic: cases n
state_before: case inr.inr
n✝ p n : ℕ
h : p < 1
⊢ 0 = n - (digits 0 n).sum
state_after: case inr.inr.zero
n p : ℕ
h : p < 1
⊢ 0 = 0 - (digits 0 0).sum

case inr.inr.succ
n p : ℕ
h : p < 1
n✝ : ℕ
⊢ 0 = n✝ + 1 - (digits 0 (n✝ + 1)).sum

tactic: all_goals simp
state_before: case inr.inr.zero
n p : ℕ
h : p < 1
⊢ 0 = 0 - (digits 0 0).sum

case inr.inr.succ
n p : ℕ
h : p < 1
n✝ : ℕ
⊢ 0 = n✝ + 1 - (digits 0 (n✝ + 1)).sum
state_after: no goals

tactic: simp
state_before: case inr.inr.succ
n p : ℕ
h : p < 1
n✝ : ℕ
⊢ 0 = n✝ + 1 - (digits 0 (n✝ + 1)).sum
state_after: no goals