Skip to content

Commit

Permalink
feat(Data/Nat/Digits): two lemmas (#5778)
Browse files Browse the repository at this point in the history
Co-authored-by: Moritz Firsching <firsching@google.com>
  • Loading branch information
mo271 and mo271 committed Jul 18, 2023
1 parent f287c03 commit 69bb9bc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Mathlib/Data/Nat/Digits.lean
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,22 @@ theorem le_digits_len_le (b n m : ℕ) (h : n ≤ m) : (digits b n).length ≤ (
monotone_nat_of_le_succ (digits_len_le_digits_len_succ b) h
#align nat.le_digits_len_le Nat.le_digits_len_le

@[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]
exact Nat.mul_le_mul h hi

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]
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
rw [← List.dropLast_append_getLast hl]
Expand Down

0 comments on commit 69bb9bc

Please sign in to comment.