forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval30.lean
More file actions
72 lines (48 loc) · 1.65 KB
/
HumanEval30.lean
File metadata and controls
72 lines (48 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module
public import Std
open Std
public section
/-! ## Implementation -/
@[grind =]
def getPositive (xs : Array Int): Array Int :=
xs.filter (0 < ·)
/-! ## Tests -/
example : getPositive #[-1, -2, 4, 5, 6] = #[4, 5, 6] := by cbv
example : getPositive #[5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10] = #[5, 3, 2, 3, 3, 9, 123, 1] := by cbv
example : getPositive #[-1, -2] = #[] := by cbv
example : getPositive #[] = #[] := by cbv
/-! ## Verification -/
section Verification
variable {xs ys : Array Int}
theorem getPositive_empty : getPositive #[] = #[] := by grind
theorem getPositive_singleton_of_pos (h : 0 < x) : getPositive #[x] = #[x] := by grind
theorem getPositive_singleton_of_nonpos (h : x ≤ 0) : getPositive #[x] = #[] := by grind
theorem getPositive_push_of_pos (h : 0 < x) : getPositive (xs.push x) = (getPositive xs).push x := by grind
theorem getPositive_push_of_nonpos (h : x ≤ 0) : getPositive (xs.push x) = getPositive xs := by grind
theorem getPositive_append : getPositive (x ++ y) = getPositive x ++ getPositive y := by grind
end Verification
/-!
## Prompt
```python3
def get_positive(l: list):
"""Return only positive numbers in the list.
>>> get_positive([-1, 2, -4, 5, 6])
[2, 5, 6]
>>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
[5, 3, 2, 3, 9, 123, 1]
"""
```
## Canonical solution
```python3
return [e for e in l if e > 0]
```
## Tests
```python3
METADATA = {}
def check(candidate):
assert candidate([-1, -2, 4, 5, 6]) == [4, 5, 6]
assert candidate([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1]
assert candidate([-1, -2]) == []
assert candidate([]) == []
```
-/