Skip to content
Merged

50 #297

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions HumanEvalLean/HumanEval50.lean
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
module

def decode_shift : Unit :=
()
def Char.shiftByFive (c : Char) : Char :=
Char.ofNat ((c.toNat - 'a'.toNat + 5) % 26 + 'a'.toNat)

def Char.unshiftByFive (c : Char) : Char :=
Char.ofNat ((c.toNat - 'a'.toNat + 21) % 26 + 'a'.toNat)

def encodeShift (s : String) : String :=
s.map Char.shiftByFive

def decodeShift (s : String) : String :=
s.map Char.unshiftByFive

@[simp]
theorem Char.toNat_mk {val : UInt32} {h} : (Char.mk val h).toNat = val.toNat := by
simp [← toNat_val]

theorem Char.toNat_ofNat_of_isValidChar {n : Nat} (h : n.isValidChar) : (Char.ofNat n).toNat = n := by
simp [ofNat, h, ofNatAux]

@[simp]
theorem Char.unshiftByFive_shiftByFive {c : Char} (hc : c.isLower) : c.shiftByFive.unshiftByFive = c := by
simp [Char.isLower, Char.shiftByFive, Char.unshiftByFive, UInt32.le_iff_toNat_le,
← Char.toNat_inj] at *
grind [toNat_ofNat_of_isValidChar]

theorem List.map_eq_self {f : α → α} {l : List α} (hf : ∀ a ∈ l, f a = a) : l.map f = l := by
induction l <;> grind

theorem decodeShift_encodeShift (s : String) (hs : ∀ c ∈ s.toList, c.isLower) :
decodeShift (encodeShift s) = s := by
simpa [← String.toList_inj, decodeShift, encodeShift] using
List.map_eq_self (by grind [Char.unshiftByFive_shiftByFive])

/-!
## Prompt
Expand Down Expand Up @@ -48,4 +78,4 @@ def check(candidate):
assert candidate(copy.deepcopy(encoded_str)) == str

```
-/
-/
Loading