Skip to content

Commit 342957c

Browse files
committed
Finish
1 parent 55be02a commit 342957c

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

HumanEvalLean/HumanEval17.lean

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import Std.Data.HashMap.Lemmas
44

55
open Std
66

7-
instance : LawfulHashable String.Slice := sorry -- will be in the next nightly
8-
instance : EquivBEq String.Slice := sorry
9-
107
def parseMusic (musicString : String) : List Nat :=
118
let noteMap : HashMap String.Slice Nat := .ofList [("o", 4), ("o|", 2), (".|", 1)]
129
(musicString.split ' ').filterMap (noteMap[·]?) |>.toList
@@ -29,21 +26,6 @@ def noteForValue (value : Nat) (h : value = 1 ∨ value = 2 ∨ value = 4) : Str
2926
def formatMusic (l : List Nat) (hl : ∀ value ∈ l, value = 1 ∨ value = 2 ∨ value = 4) : String :=
3027
" ".intercalate ((l.attachWith _ hl).map (fun p => noteForValue p.1 p.2))
3128

32-
@[simp]
33-
theorem String.copy_comp_toSlice : String.Slice.copy ∘ String.toSlice = id := by
34-
ext; simp
35-
36-
@[simp]
37-
theorem String.Slice.beq_list_iff {l l' : List String.Slice} : l == l' ↔ l.map String.Slice.copy = l'.map String.Slice.copy := by
38-
induction l generalizing l' with
39-
| nil => simp_all
40-
| cons => cases l' <;> simp_all
41-
42-
theorem String.toList_split_intercalate_beq {l : List String} (h : ∀ s ∈ l, ¬c ∈ s.toList) :
43-
(((String.singleton c).intercalate l).split c).toList ==
44-
if l = [] then ["".toSlice] else l.map String.toSlice := by
45-
split <;> simp_all [String.toList_split_intercalate h]
46-
4729
theorem List.filterMap_beq_congr [BEq α] {l l' : List α} {f : α → Option β}
4830
(hf : ∀ a a', a == a' → f a = f a') (hl : l == l') : l.filterMap f = l'.filterMap f := by
4931
induction l generalizing l' with
@@ -57,25 +39,27 @@ theorem List.filterMap_beq_congr [BEq α] {l l' : List α} {f : α → Option β
5739

5840
theorem parseMusic_formatMusic {l : List Nat} {hl} : parseMusic (formatMusic l hl) = l := by
5941
rw [parseMusic, formatMusic, Iter.toList_filterMap]
60-
-- TODO: use simproc from next nightly to avoid `erw`
61-
erw [List.filterMap_beq_congr (fun _ _ => HashMap.getElem?_congr) (String.toList_split_intercalate_beq _)]
62-
· simp
42+
simp +instances only [String.reduceToSingleton]
43+
rw [List.filterMap_beq_congr (fun _ _ => HashMap.getElem?_congr) (String.toList_split_intercalate_beq _)]
44+
· simp only [↓Char.isValue, String.reduceSingleton, List.map_attachWith, List.map_eq_nil_iff,
45+
List.attach_eq_nil_iff, List.map_map]
6346
by_cases hl : l = []
6447
· simp [hl]
6548
· simp [hl]
6649
clear hl
6750
induction l with
6851
| nil => simp
6952
| cons ht tl ih =>
70-
simp
53+
simp only [List.attach_cons]
7154
rw [List.filterMap_cons_some (b := ht)]
7255
· simp only [List.filterMap_map, List.cons.injEq, true_and]
7356
apply ih
7457
refine fun v hv => hl _ (by simp [hv])
7558
· simp
7659
obtain (rfl|rfl|rfl) := hl ht (by simp) <;>
7760
simp [noteForValue, HashMap.ofList_equiv_foldl.getElem_eq, HashMap.getElem_insert]
78-
· simp
61+
· simp only [List.map_attachWith, List.mem_map, List.mem_attach, true_and, Subtype.exists,
62+
↓Char.isValue, forall_exists_index]
7963
rintro _ val hval rfl
8064
obtain (rfl|rfl|rfl) := hl _ hval <;> simp [noteForValue]
8165

0 commit comments

Comments
 (0)