forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval45.lean
More file actions
70 lines (47 loc) · 1.28 KB
/
HumanEval45.lean
File metadata and controls
70 lines (47 loc) · 1.28 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
module
/-! ## Implementation -/
def triangleArea (a h : Rat) : Rat :=
a * h / 2.0
/-! ## Tests -/
example : triangleArea 5 3 = 7.5 := by cbv
example : triangleArea 2 2 = 2.0 := by cbv
example : triangleArea 10 8 = 40.0 := by cbv
/-!
## Verification
We won't formalize geometry and therefore cannot close the verification gap.
What follows are lemmas about `triangleArea` proving useful properties.
-/
theorem triangleArea_mul_left :
triangleArea (c * a) h = c * triangleArea a h := by
grind [triangleArea]
theorem triangleArea_mul_right :
triangleArea a (c * h) = c * triangleArea a h := by
grind [triangleArea]
theorem triangleArea_add_left :
triangleArea (a + b) h = triangleArea a h + triangleArea b h := by
grind [triangleArea]
theorem triangleArea_add_right :
triangleArea a (h₁ + h₂) = triangleArea a h₁ + triangleArea a h₂ := by
grind [triangleArea]
/-!
## Prompt
```python3
def triangle_area(a, h):
"""Given length of a side and high return area for a triangle.
>>> triangle_area(5, 3)
7.5
"""
```
## Canonical solution
```python3
return a * h / 2.0
```
## Tests
```python3
METADATA = {}
def check(candidate):
assert candidate(5, 3) == 7.5
assert candidate(2, 2) == 2.0
assert candidate(10, 8) == 40.0
```
-/