Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
77c7568
Add (partial) solution to HumanEval5
marcusrossel May 1, 2025
7bacf0e
Add solution to HumanEval155
marcusrossel May 1, 2025
38a4528
Use `List.intersperse`
marcusrossel May 5, 2025
3ac961c
Simplify proof
marcusrossel May 5, 2025
6a07760
Add proof for odd case
marcusrossel May 5, 2025
52ffa4d
Gardening
marcusrossel May 5, 2025
c751675
Turn < into =
marcusrossel May 6, 2025
ddadf48
Rename theorem
marcusrossel May 6, 2025
08dc3d3
Use Lean's theorems
marcusrossel May 14, 2025
c33ec7f
Define decomposition theorem
marcusrossel May 14, 2025
871954b
Update to Lean v4.21.0-rc2
marcusrossel Jun 3, 2025
2f4e27f
Merge branch 'master' into master
marcusrossel Jun 3, 2025
f72aa00
Merge branch 'master' into master
TwoFX Jun 5, 2025
c6cd38a
Overhaul definitions
marcusrossel Jun 7, 2025
b27e888
Reduce `count_decompose` to "simple" lemmas
marcusrossel Jun 8, 2025
a30a5f1
Decouple "`Int`-ness"
marcusrossel Jun 8, 2025
2a80c53
Remove redundant lemma
marcusrossel Jun 8, 2025
418be3b
Prove `digits_of_lt_10`
marcusrossel Jun 8, 2025
cd38c4b
Remove redundant lemma
marcusrossel Jun 8, 2025
7faf093
Prove more lemmas
marcusrossel Jun 8, 2025
f8085eb
Update batteries theorems
marcusrossel Jun 9, 2025
43cce56
Remove redundant lemma
marcusrossel Jun 9, 2025
d713664
Fix incorrect lemmas
marcusrossel Jun 9, 2025
b4964e0
Remove redundant lemma
marcusrossel Jun 9, 2025
1d31d93
Complete all proofs
marcusrossel Jun 9, 2025
66bd94a
Merge branch 'master' into 155
marcusrossel Jun 10, 2025
a4a67e6
Sorry-free version
marcusrossel Jun 10, 2025
0ff4924
Undo accidental change
marcusrossel Jun 10, 2025
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
51 changes: 48 additions & 3 deletions HumanEvalLean/HumanEval155.lean
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
def even_odd_count : Unit :=
()
def Int.toDigits (i : Int) : List Char :=
i.natAbs.toDigits (base := 10)

def evenOddCount (num : Int) : Nat × Nat :=
num.toDigits.foldl countDigit (0, 0)
where
countDigit (evenOdd : Nat × Nat) : Char → Nat × Nat
| '0' | '2' | '4' | '6' | '8' => (evenOdd.fst + 1, evenOdd.snd)
| _ => (evenOdd.fst, evenOdd.snd + 1)

example : evenOddCount (-12) = (1, 1) := rfl
example : evenOddCount 123 = (1, 2) := rfl
example : evenOddCount 7 = (0, 1) := rfl
example : evenOddCount (-78) = (1, 1) := rfl
example : evenOddCount 3452 = (2, 2) := rfl
example : evenOddCount 346211 = (3, 3) := rfl
example : evenOddCount (-345821) = (3, 3) := rfl
example : evenOddCount (-2) = (1, 0) := rfl
example : evenOddCount (-45347) = (2, 3) := rfl
example : evenOddCount 0 = (1, 0) := rfl

def Prod.sum : Nat × Nat → Nat
| (n₁, n₂) => n₁ + n₂

-- Applying `evenOddCount.countDigit` increases the total digit count by `1`.
theorem evenOddCount.countDigit_sum (evenOdd : Nat × Nat) (d : Char) :
(evenOddCount.countDigit evenOdd d).sum = evenOdd.sum + 1 := by
unfold evenOddCount.countDigit
split <;> simp +arith [Prod.sum]

-- Folding `evenOddCount.countDigit` over a given digit count `init` produces the same total digit
-- count as folding `evenOddCount.countDigit` over `(0, 0)` and adding that to `init`.
theorem evenOddCount.countDigit_sum_foldl (ds : List Char) (init : Nat × Nat) :
(ds.foldl evenOddCount.countDigit init).sum =
(ds.foldl evenOddCount.countDigit (0, 0)).sum + init.sum := by
induction ds generalizing init
case nil => simp [Prod.sum]
case cons ih => simp +arith only [List.foldl_cons, ih (countDigit _ _), countDigit_sum]; rfl

-- The total digit count produced by `evenOddCount` matches the number of digits in the input.
theorem evenOddCount_sum_eq_length : (evenOddCount i).sum = i.toDigits.length := by
rw [evenOddCount]
generalize i.toDigits = ds
induction ds
case nil => rfl
case cons ih => rw [List.foldl_cons, List.length_cons, evenOddCount.countDigit_sum_foldl, ih,
evenOddCount.countDigit_sum, Prod.sum]

/-!
## Prompt
Expand Down Expand Up @@ -48,4 +93,4 @@ def check(candidate):
assert True

```
-/
-/