Skip to content

Commit 200ca38

Browse files
committed
Make it look nice
1 parent 0552756 commit 200ca38

File tree

2 files changed

+5
-54
lines changed

2 files changed

+5
-54
lines changed

HumanEvalLean/HumanEval15.lean

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,22 @@ module
22
import Std.Data.Iterators.Producers.Range
33
import Std
44

5-
@[inline]
6-
def intercalateIter {α : Type} [Std.Iterator α Id String.Slice] [Std.IteratorLoop α Id Id]
7-
(s : String.Slice) (it : Std.Iter (α := α) String.Slice) : String :=
8-
(it.fold (init := none) (fun | none, sl => some sl.copy | some str, sl => str ++ s ++ sl)).getD ""
9-
105
def stringSequence (n : Nat) : String :=
11-
intercalateIter " " ((0...=n).iter.map (String.toSlice ∘ Nat.repr))
6+
Std.Iter.intercalateString.{0} " " ((0...=n).iter.map (String.toSlice ∘ Nat.repr))
127

138
example : stringSequence 0 = "0" := by native_decide
149
example : stringSequence 3 = "0 1 2 3" := by native_decide
1510
example : stringSequence 10 = "0 1 2 3 4 5 6 7 8 9 10" := by native_decide
1611

17-
theorem String.intercalate_append_of_ne_nil {l m : List String} {s : String} (hl : l ≠ []) (hm : m ≠ []) :
18-
s.intercalate (l ++ m) = s.intercalate l ++ s ++ s.intercalate m := by
19-
induction l with
20-
| nil => simp_all
21-
| cons hd tl ih =>
22-
rw [List.cons_append, String.intercalate_cons_of_ne_nil (by simp_all)]
23-
by_cases ht : tl = []
24-
· simp_all
25-
· simp [ih ht, String.intercalate_cons_of_ne_nil ht, String.append_assoc]
26-
27-
@[simp]
28-
theorem intercalateIter_eq {α : Type} [Std.Iterator α Id String.Slice] [Std.Iterators.Finite α Id]
29-
[Std.IteratorLoop α Id Id] [Std.LawfulIteratorLoop α Id Id] {s : String.Slice} {it : Std.Iter (α := α) String.Slice} :
30-
intercalateIter s it = s.intercalate it.toList := by
31-
simp only [intercalateIter, String.appendSlice_eq, ← Std.Iter.foldl_toList,
32-
String.Slice.intercalate_eq]
33-
generalize s.copy = s
34-
have := congrArg (·.getD "") (List.foldl_map (init := none) (l := it.toList) (f := String.Slice.copy)
35-
(g := (fun | none, t => some t | some str, t => str ++ s ++ t)))
36-
refine Eq.trans ?_ (Eq.trans this.symm ?_)
37-
· congr
38-
grind
39-
· suffices ∀ (l m : List String),
40-
(l.foldl (init := if m = [] then none else some (s.intercalate m)) (fun | none, sl => some sl | some str, sl => str ++ s ++ sl)).getD ""
41-
= s.intercalate (m ++ l) by
42-
simpa using this (it.toList.map String.Slice.copy) []
43-
clear this
44-
intro l m
45-
induction l generalizing m with
46-
| nil => cases m <;> simp
47-
| cons hd tl ih =>
48-
rw [List.append_cons, ← ih, List.foldl_cons]
49-
congr
50-
simp only [List.append_eq_nil_iff, List.cons_ne_self, and_false, ↓reduceIte]
51-
match m with
52-
| [] => simp
53-
| x::xs =>
54-
simp only [reduceCtorEq, ↓reduceIte, List.cons_append, Option.some.injEq]
55-
rw [← List.cons_append, String.intercalate_append_of_ne_nil (by simp) (by simp),
56-
String.intercalate_singleton]
57-
58-
@[simp]
59-
theorem String.Slice.toNat?_comp_copy : String.toNat? ∘ String.Slice.copy = String.Slice.toNat? := by
60-
ext; simp
61-
6212
/-- Calling `stringSequence` and then splitting the result at space characters and attempting to
6313
parse the components into natural numbers yields the sequence `[some 0, some 1, ..., some n]`. -/
6414
theorem map_ofNat?_stringSequence {n : Nat} :
6515
((stringSequence n).split ' ').toList.map String.Slice.toNat? =
6616
(0...=n).toList.map Option.some := by
67-
rw [stringSequence, ← String.Slice.toNat?_comp_copy, ← List.map_map, intercalateIter_eq]
68-
erw [String.Slice.toList_split_intercalate]
17+
rw [stringSequence, ← String.Slice.toNat?_comp_copy, ← List.map_map,
18+
Std.Iter.intercalateString_eq, String.Slice.toStringToString_eq, String.copy_toSlice]
19+
simp +instances only [String.reduceToSingleton]
20+
rw [String.toList_split_intercalate]
6921
· rw [Std.Iter.toList_map]
7022
simp
7123
· rw [Std.Iter.toList_map]

HumanEvalLean/HumanEval6.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,3 @@ def check(candidate):
127127
assert candidate('(()(())((())))') == [4]
128128
```
129129
-/
130-
)

0 commit comments

Comments
 (0)