forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval22.lean
More file actions
92 lines (66 loc) · 2.19 KB
/
HumanEval22.lean
File metadata and controls
92 lines (66 loc) · 2.19 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module
public import Std
open Std
public section
/-!
## Implementation
This Problem assumes a language with dynamic typing. We approximate this by defining an inductive
`Any` type.
-/
inductive Any where
| int : Int → Any
| float : Float → Any
| string : String → Any
@[grind =]
def Any.int? (x : Any) : Option Int :=
if let .int a := x then
some a
else
none
@[grind =]
def filterIntegers (xs : Array Any): Array Int :=
xs.filterMap Any.int?
/-! ## Tests -/
example : filterIntegers #[] = #[] := by cbv
example : filterIntegers #[.int 4, .float 23.2, .int 9, .string "adasd"] = #[4, 9] := by cbv
example : filterIntegers #[.int 3, .string "c", .int 3, .int 3, .string "a", .string "b"] = #[3, 3, 3] := by cbv
/-! ## Verification -/
section Verification
variable {xs ys : Array Any}
theorem filterIntegers_empty : filterIntegers #[] = #[] := by grind
theorem filterIntegers_singleton_int : filterIntegers #[.int x] = #[x] := by grind
theorem filterIntegers_singleton_float : filterIntegers #[.float x] = #[] := by grind
theorem filterIntegers_singleton_string : filterIntegers #[.string x] = #[] := by grind
theorem filterIntegers_push_int : filterIntegers (xs.push (.int x)) = (filterIntegers xs).push x := by grind
theorem filterIntegers_push_float : filterIntegers (xs.push (.float x)) = filterIntegers xs := by grind
theorem filterIntegers_push_string : filterIntegers (xs.push (.string x)) = filterIntegers xs := by grind
theorem filterIntegers_append : filterIntegers (x ++ y) = filterIntegers x ++ filterIntegers y := by grind
end Verification
/-!
## Prompt
```python3
from typing import List, Any
def filter_integers(values: List[Any]) -> List[int]:
""" Filter given list of any python values only for integers
>>> filter_integers(['a', 3.14, 5])
[5]
>>> filter_integers([1, 2, 3, 'abc', {}, []])
[1, 2, 3]
"""
```
## Canonical solution
```python3
return [x for x in values if isinstance(x, int)]
```
## Tests
```python3
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([]) == []
assert candidate([4, {}, [], 23.2, 9, 'adasd']) == [4, 9]
assert candidate([3, 'c', 3, 3, 'a', 'b']) == [3, 3, 3]
```
-/