Skip to content

Commit f068c8f

Browse files
committed
Merge remote-tracking branch 'origin/master' into markus/139-grind
2 parents 839defd + 6a72ee7 commit f068c8f

File tree

6 files changed

+118
-14
lines changed

6 files changed

+118
-14
lines changed

HumanEvalLean/HumanEval11.lean

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
def string_xor : Unit :=
2-
()
1+
import Std.Data.Iterators
2+
3+
def stringXor (a b : List Bool) : List Bool :=
4+
((a.iter).zip b.iter)
5+
|>.map (fun p => Bool.xor p.1 p.2)
6+
|>.toList
7+
8+
@[simp, grind]
9+
theorem length_stringXor {a b : List Bool} : (stringXor a b).length = min a.length b.length := by
10+
simp [stringXor]
11+
12+
theorem getElem_stringXor {a b : List Bool} {i : Nat} {hia : i < a.length} {hib : i < b.length} :
13+
(stringXor a b)[i]'(by grind) = Bool.xor a[i] b[i] := by
14+
simp [stringXor]
315

416
/-!
517
## Prompt
@@ -44,4 +56,4 @@ def check(candidate):
4456
assert candidate('1', '1') == '0'
4557
assert candidate('0101', '0000') == '0101'
4658
```
47-
-/
59+
-/

HumanEvalLean/HumanEval24.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ theorem largestDivisorSpec_go {n i : Nat} (hi : 2 ≤ i)
3232
fun_induction largestDivisor.go n i
3333
case case1 i hni =>
3434
have := @Nat.mul_self_lt_mul_self_iff i
35-
grind [LargestDivisorSpec.one]
35+
exact LargestDivisorSpec.one (fun j hj hj' => hi' _ hj (Nat.mul_self_lt_mul_self_iff.1 (by grind)))
3636
case case2 i hni hni' =>
3737
grind [LargestDivisorSpec.div]
3838
case case3 i hni hni' ih =>

HumanEvalLean/HumanEval5.lean

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
1-
def intersperse : Unit :=
2-
()
1+
example : [].intersperse 7 = [] := rfl
2+
example : [5, 6, 3, 2].intersperse 8 = [5, 8, 6, 8, 3, 8, 2] := rfl
3+
example : [2, 2, 2].intersperse 2 = [2, 2, 2, 2, 2] := rfl
4+
5+
open List
6+
7+
/--
8+
info: List.length_intersperse.{u_1} {α : Type u_1} {l : List α} {sep : α} : (intersperse sep l).length = 2 * l.length - 1
9+
-/
10+
#guard_msgs in
11+
#check length_intersperse
12+
13+
/--
14+
info: List.getElem?_intersperse_two_mul.{u_1} {α : Type u_1} {l : List α} {sep : α} {i : Nat} :
15+
(intersperse sep l)[2 * i]? = l[i]?
16+
-/
17+
#guard_msgs in
18+
#check getElem?_intersperse_two_mul
19+
20+
/--
21+
info: List.getElem?_intersperse_two_mul_add_one.{u_1} {α : Type u_1} {l : List α} {sep : α} {i : Nat} (h : i + 1 < l.length) :
22+
(intersperse sep l)[2 * i + 1]? = some sep
23+
-/
24+
#guard_msgs in
25+
#check getElem?_intersperse_two_mul_add_one
26+
27+
/--
28+
info: List.getElem_intersperse_two_mul.{u_1} {α : Type u_1} {l : List α} {sep : α} {i : Nat}
29+
(h : 2 * i < (intersperse sep l).length) : (intersperse sep l)[2 * i] = l[i]
30+
-/
31+
#guard_msgs in
32+
#check getElem_intersperse_two_mul
33+
34+
/--
35+
info: List.getElem_intersperse_two_mul_add_one.{u_1} {α : Type u_1} {l : List α} {sep : α} {i : Nat}
36+
(h : 2 * i + 1 < (intersperse sep l).length) : (intersperse sep l)[2 * i + 1] = sep
37+
-/
38+
#guard_msgs in
39+
#check getElem_intersperse_two_mul_add_one
40+
41+
/--
42+
info: List.getElem_eq_getElem_intersperse_two_mul.{u_1} {α : Type u_1} {l : List α} {sep : α} {i : Nat} (h : i < l.length) :
43+
l[i] = (intersperse sep l)[2 * i]
44+
-/
45+
#guard_msgs in
46+
#check getElem_eq_getElem_intersperse_two_mul
347

448
/-!
549
## Prompt

HumanEvalLean/HumanEval51.lean

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
1-
def remove_vowels : Unit :=
2-
()
1+
def IsSubseq (s₁ : String) (s₂ : String) : Prop :=
2+
List.Sublist s₁.toList s₂.toList
3+
4+
def vowels : List Char := ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
5+
6+
def NoVowels (s : String) : Prop :=
7+
List.all s.toList (· ∉ vowels)
8+
9+
def MaximalFor [LE α] (P : ι → Prop) (f : ι → α) (x : ι) : Prop :=
10+
-- Same as MaximalFor in Mathlib
11+
P x ∧ ∀ y : ι, P y → f x ≤ f y → f y ≤ f x
12+
13+
def RemoveVowelsIff (solution : String → String) : Prop :=
14+
(s x : String) → (solution s = x) → MaximalFor (fun i => NoVowels i ∧ IsSubseq i s) (String.length) x
15+
16+
def removeVowels (s : String) : String :=
17+
String.mk (s.toList.filter (· ∉ vowels))
18+
19+
example : removeVowels "abcdef" = "bcdf" := by native_decide
20+
example : removeVowels "abcdef\nghijklm" = "bcdf\nghjklm" := by native_decide
21+
example : removeVowels "aaaaa" = "" := by native_decide
22+
example : removeVowels "aaBAA" = "B" := by native_decide
23+
example : removeVowels "zbcd" = "zbcd" := by native_decide
24+
25+
theorem IsSubseq.length_le {s t : String} (hst : IsSubseq s t) :
26+
s.length ≤ t.length :=
27+
List.Sublist.length_le hst
28+
29+
theorem IsSubseq.removeVowels {s t : String} (hst : IsSubseq s t) :
30+
IsSubseq (removeVowels s) (removeVowels t) :=
31+
hst.filter _
32+
33+
theorem removeVowels_eq_self {s : String} :
34+
removeVowels s = s ↔ NoVowels s := by
35+
simp [String.ext_iff, NoVowels, removeVowels]
36+
37+
theorem removeVowels_correct : RemoveVowelsIff removeVowels := by
38+
simp [RemoveVowelsIff]
39+
intro s
40+
constructor
41+
· simp [NoVowels, removeVowels, IsSubseq]
42+
· simp only [and_imp]
43+
intro y hnv hss hle
44+
rw [← removeVowels_eq_self.2 hnv]
45+
exact IsSubseq.length_le (IsSubseq.removeVowels hss)
346

447
/-!
548
## Prompt
@@ -49,4 +92,4 @@ def check(candidate):
4992
assert candidate('ybcd') == 'ybcd'
5093
5194
```
52-
-/
95+
-/

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ platform.
1010
## Contributions
1111

1212
Contributions are welcome! You can
13-
[look at the open issues](https://github.com/TwoFX/human-eval-lean/issues) to see
13+
[look at the table](https://github.com/users/TwoFX/projects/2/views/1) to see
1414
which problems do not currently have a solution.
1515

1616
Feel free to add your thoughts about
1717
a problem to the corresponding issue. A rough estimation of the difficulty is already
1818
helpful; I will add the corresponding label to the issue.
1919

20-
PRs contributing new solutions to both unsolved and solved problems are welcome,
21-
as are PRs improving the code of existing solutions. Golfing is welcome as long
22-
as the resulting code can still be considered idiomatic.
20+
We accept
21+
22+
- PRs adding complete solutions to unsolved problems,
23+
- PRs adding additional solutions to problems which are already solved,
24+
- PRs adding partial solutions (for example just the code and the correctness statement, with the correctness proof sorried, or just developing a bit of related theory), and
25+
- PRs improving the code of existing solutions.
26+
27+
Golfing is welcome as long as the resulting code can still be considered idiomatic.
2328

2429
We use the [Lean 4 standard library style guide and naming convention](https://github.com/leanprover/lean4/tree/master/doc/std),
2530
but we won't be very strict about enforcing it.

lean-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
leanprover/lean4:nightly-2025-06-25
1+
leanprover/lean4:nightly-2025-08-18

0 commit comments

Comments
 (0)