forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval133.lean
More file actions
104 lines (79 loc) · 3.23 KB
/
HumanEval133.lean
File metadata and controls
104 lines (79 loc) · 3.23 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
93
94
95
96
97
98
99
100
101
102
103
104
module
def sumSquares (xs : List Rat) : Int :=
xs.map (·.ceil ^ (2 : Nat)) |>.sum
/-! ## Tests -/
example : sumSquares [1, 2, 3] = 14 := by cbv
example : sumSquares [1.0, 2, 3] = 14 := by cbv
example : sumSquares [1, 3, 5, 7] = 84 := by cbv
example : sumSquares [1.4, 4.2, 0] = 29 := by cbv
example : sumSquares [-2.4, 1, 1] = 6 := by cbv
example : sumSquares [100, 1, 15, 2] = 10230 := by cbv
example : sumSquares [10000, 10000] = 200000000 := by cbv
example : sumSquares [-1.4, 4.6, 6.3] = 75 := by cbv
example : sumSquares [-1.4, 17.9, 18.9, 19.9] = 1086 := by cbv
example : sumSquares [0] = 0 := by cbv
example : sumSquares [-1] = 1 := by cbv
example : sumSquares [-1, 1, 0] = 2 := by cbv
/-!
## Verification
We start pointing to lemmas that verify `Rat.ceil` and then express the correctness lemmas in
terms of `Rat.ceil`.
-/
/-- info: Rat.ceil_lt {x : Rat} : ↑x.ceil < x + 1 -/
#guard_msgs in
#check Rat.ceil_lt
/-- info: Rat.le_ceil {x : Rat} : x ≤ ↑x.ceil -/
#guard_msgs in
#check Rat.le_ceil
@[grind =]
theorem sumSquares_nil :
sumSquares [] = 0 := by
grind [sumSquares]
theorem sumSquares_singleton :
sumSquares [x] = x.ceil * x.ceil := by
grind [sumSquares]
theorem sumSquares_append {xs ys : List Rat} :
sumSquares (xs ++ ys) = sumSquares xs + sumSquares ys := by
grind [sumSquares]
/-!
## Prompt
```python3
def sum_squares(lst):
"""You are given a list of numbers.
You need to return the sum of squared numbers in the given list,
round each element in the list to the upper int(Ceiling) first.
Examples:
For lst = [1,2,3] the output should be 14
For lst = [1,4,9] the output should be 98
For lst = [1,3,5,7] the output should be 84
For lst = [1.4,4.2,0] the output should be 29
For lst = [-2.4,1,1] the output should be 6
"""
```
## Canonical solution
```python3
import math
squared = 0
for i in lst:
squared += math.ceil(i)**2
return squared
```
## Tests
```python3
def check(candidate):
# Check some simple cases
assert candidate([1,2,3])==14, "This prints if this assert fails 1 (good for debugging!)"
assert candidate([1.0,2,3])==14, "This prints if this assert fails 1 (good for debugging!)"
assert candidate([1,3,5,7])==84, "This prints if this assert fails 1 (good for debugging!)"
assert candidate([1.4,4.2,0])==29, "This prints if this assert fails 1 (good for debugging!)"
assert candidate([-2.4,1,1])==6, "This prints if this assert fails 1 (good for debugging!)"
assert candidate([100,1,15,2])==10230, "This prints if this assert fails 1 (good for debugging!)"
assert candidate([10000,10000])==200000000, "This prints if this assert fails 1 (good for debugging!)"
assert candidate([-1.4,4.6,6.3])==75, "This prints if this assert fails 1 (good for debugging!)"
assert candidate([-1.4,17.9,18.9,19.9])==1086, "This prints if this assert fails 1 (good for debugging!)"
# Check some edge cases that are easy to work out by hand.
assert candidate([0])==0, "This prints if this assert fails 2 (also good for debugging!)"
assert candidate([-1])==1, "This prints if this assert fails 2 (also good for debugging!)"
assert candidate([-1,1,0])==2, "This prints if this assert fails 2 (also good for debugging!)"
```
-/