Skip to content

Commit 22e4df4

Browse files
committed
Merge remote-tracking branch 'origin/master' into markus/11
2 parents 3660e31 + 47c5582 commit 22e4df4

File tree

5 files changed

+161
-13
lines changed

5 files changed

+161
-13
lines changed

HumanEvalLean/HumanEval139.lean

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,61 @@
1-
def special_factorial : Unit :=
2-
()
1+
-- from Mathlib
2+
def Nat.factorial : Nat → Nat
3+
| 0 => 1
4+
| .succ n => Nat.succ n * factorial n
5+
6+
notation:10000 n "!" => Nat.factorial n
7+
8+
@[simp] theorem Nat.factorial_zero : 0! = 1 :=
9+
rfl
10+
11+
theorem Nat.factorial_succ (n : Nat) : (n + 1)! = (n + 1) * n ! :=
12+
rfl
13+
14+
def Nat.brazilianFactorial : Nat → Nat
15+
| .zero => 1
16+
| .succ n => (Nat.succ n)! * brazilianFactorial n
17+
18+
@[simp] theorem Nat.brazilianFactorial_zero : brazilianFactorial 0 = 1 :=
19+
rfl
20+
21+
theorem Nat.brazilianFactorial_succ (n : Nat) : brazilianFactorial (n + 1) = (n + 1)! * (brazilianFactorial n) :=
22+
rfl
23+
24+
def special_factorial (n : Nat) : Nat :=
25+
special_factorial.go n 1 1 0
26+
where
27+
go (n fact brazilFact curr : Nat) : Nat :=
28+
if _h: curr >= n
29+
then brazilFact
30+
else
31+
let fact' := (curr + 1) * fact
32+
let brazilFact' := fact' * brazilFact
33+
special_factorial.go n fact' brazilFact' (Nat.succ curr)
34+
termination_by n - curr
35+
36+
theorem special_factorial_func_correct {n : Nat} :
37+
special_factorial n = n.brazilianFactorial := by
38+
simp [special_factorial]
39+
suffices ∀ (curr fact brazilFact : Nat), fact = curr ! → brazilFact = curr.brazilianFactorial →
40+
curr ≤ n → special_factorial.go n fact brazilFact curr = n.brazilianFactorial by
41+
apply this
42+
· simp [Nat.factorial]
43+
· simp [Nat.brazilianFactorial]
44+
· simp
45+
intro curr fact brazil_fact h₁ h₂ h₃
46+
fun_induction special_factorial.go with
47+
| case1 fact brazil_fact curr h =>
48+
rw [h₂, (show curr = n by omega)]
49+
| case2 fact brazilFact curr h fact' brazilFact' ih =>
50+
simp only [ge_iff_le, Nat.not_le] at h
51+
simp only [h₁, Nat.succ_eq_add_one, Nat.factorial_succ, h₂, Nat.brazilianFactorial_succ,
52+
Nat.succ_le_of_lt h, forall_const, fact', brazilFact'] at ih
53+
simp only [← ih, fact', h₁, brazilFact', h₂]
54+
55+
theorem test1 : special_factorial 4 = 288 := by native_decide
56+
theorem test2 : special_factorial 5 = 34560 := by native_decide
57+
theorem test3 : special_factorial 7 = 125411328000 := by native_decide
58+
theorem test4 : special_factorial 1 = 1 := by native_decide
359

460
/-!
561
## Prompt
@@ -45,4 +101,4 @@ def check(candidate):
45101
assert candidate(1) == 1, "Test 1"
46102
47103
```
48-
-/
104+
-/

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-11
1+
leanprover/lean4:nightly-2025-06-11

0 commit comments

Comments
 (0)