|
1 | | -section Batteries |
| 1 | +section Batteries -- https://github.com/leanprover-community/batteries/pull/1267 |
2 | 2 |
|
3 | | --- https://github.com/leanprover-community/batteries/pull/1267 |
4 | | -@[simp] theorem Nat.isDigit_digitChar : n.digitChar.isDigit = decide (n < 10) := sorry |
5 | | -theorem Nat.mem_toDigits_base_10_isDigit (h : c ∈ toDigits 10 n) : c.isDigit := sorry |
6 | | -theorem Nat.toDigits_10_of_lt_10 (h : n < 10) : toDigits 10 n = [n.digitChar] := sorry |
| 3 | +@[simp] |
| 4 | +theorem Nat.isDigit_digitChar : n.digitChar.isDigit = decide (n < 10) := |
| 5 | + sorry |
| 6 | + |
| 7 | +theorem Nat.isDigit_of_mem_toDigits (hb₁ : 0 < b) (hb₂ : b ≤ 10) (hc : c ∈ toDigits b n) : |
| 8 | + c.isDigit := |
| 9 | + sorry |
7 | 10 |
|
8 | | -theorem Nat.toDigits_10_decompose (h : d < 10) (n : Nat) : |
9 | | - toDigits 10 (10 * n + d) = (toDigits 10 n) ++ (toDigits 10 d) := |
| 11 | +theorem Nat.toDigits_of_lt_base (h : n < b) : toDigits b n = [n.digitChar] := |
| 12 | + sorry |
| 13 | + |
| 14 | +theorem Nat.toDigits_append_toDigits (hb₁ : 1 < b) (hb₂ : b ≤ 10) (hn : 0 < n) (hd : d < b) : |
| 15 | + (toDigits b n) ++ (toDigits b d) = toDigits b (b * n + d) := by |
10 | 16 | sorry |
11 | 17 |
|
12 | 18 | end Batteries |
13 | 19 |
|
| 20 | +-- TODO: If you want to use induction or recursion here, you probably have to state a lemma for |
| 21 | +-- `Nat.toDigitsCore`, too. |
| 22 | +theorem Nat.toDigits_decompose (hb₁ : 1 < b) (hb₂ : b ≤ 10) (hd : d < b) (n : Nat) : |
| 23 | + toDigits b (b * n + d) = (toDigits b n) ++ (toDigits b d) := by |
| 24 | + rw [toDigits, toDigitsCore] |
| 25 | + split |
| 26 | + · sorry |
| 27 | + · sorry |
| 28 | + |
14 | 29 | abbrev Digit := { c : Char // c.isDigit } |
15 | 30 |
|
16 | 31 | namespace Nat |
17 | 32 |
|
18 | 33 | def digits (n : Nat) : List Digit := |
19 | 34 | n.toDigits (base := 10) |
20 | 35 | |>.attach |
21 | | - |>.map fun ⟨j, h⟩ => ⟨j, Nat.mem_toDigits_base_10_isDigit h⟩ |
| 36 | + |>.map fun ⟨j, h⟩ => ⟨j, Nat.isDigit_of_mem_toDigits (by decide) (by decide) h⟩ |
22 | 37 |
|
23 | 38 | theorem digits_of_lt_10 (h : n < 10) : n.digits = [⟨n.digitChar, by simp_all⟩] := by |
24 | 39 | simp only [digits, List.map_eq_singleton_iff, Subtype.mk.injEq, Subtype.exists, exists_and_right, |
25 | 40 | exists_eq_right] |
26 | | - rw [toDigits_10_of_lt_10 h] |
| 41 | + rw [toDigits_of_lt_base h] |
27 | 42 | exists List.mem_singleton_self _ |
28 | 43 |
|
29 | 44 | theorem digits_decompose (h : d < 10) (n : Nat) : (10 * n + d).digits = n.digits ++ d.digits := by |
|
0 commit comments