Skip to content

Commit fdf2a4d

Browse files
authored
27 (#289)
1 parent a21db22 commit fdf2a4d

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

HumanEvalLean/HumanEval27.lean

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
module
22

3-
def flip_case : Unit :=
4-
()
3+
def Char.flipCase (c : Char) : Char :=
4+
if c.isLower then
5+
c.toUpper
6+
else if c.isUpper then
7+
c.toLower
8+
else
9+
c
10+
11+
def flipCase (string : String) : String :=
12+
string.map Char.flipCase
13+
14+
example : flipCase "" = "" := by cbv
15+
example : flipCase "Hello!" = "hELLO!" := by cbv
16+
example : flipCase "These violent delights have violent ends" = "tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS" := by cbv
17+
18+
theorem toList_flipCase {string : String} : (flipCase string).toList = string.toList.map Char.flipCase := by
19+
simp [flipCase]
20+
21+
namespace Char
22+
23+
@[simp]
24+
theorem toNat_mk {val : UInt32} {h} : (Char.mk val h).toNat = val.toNat := by
25+
simp [← toNat_val]
26+
27+
theorem isUpper_flipCase {c : Char} : c.flipCase.isUpper ↔ c.isLower := by
28+
grind [flipCase, isUpper, isLower, toUpper, toLower]
29+
30+
theorem isLower_flipCase {c : Char} : c.flipCase.isLower ↔ c.isUpper := by
31+
grind [flipCase, isUpper, isLower, toUpper, toLower]
32+
33+
theorem toLower_flipCase {c : Char} : c.flipCase.toLower = c.toLower := by
34+
-- https://github.com/leanprover/lean4/issues/13089
35+
simp [flipCase, isUpper, isLower, toUpper, toLower, ← toNat_inj, apply_dite Char.toNat,
36+
apply_ite Char.toNat, UInt32.le_iff_toNat_le]
37+
grind
38+
39+
end Char
40+
541

642
/-!
743
## Prompt
@@ -38,4 +74,4 @@ def check(candidate):
3874
assert candidate('Hello!') == 'hELLO!'
3975
assert candidate('These violent delights have violent ends') == 'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS'
4076
```
41-
-/
77+
-/

0 commit comments

Comments
 (0)