Skip to content
Merged

58 #266

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
38 changes: 35 additions & 3 deletions HumanEvalLean/HumanEval58.lean
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
module

def common : Unit :=
()
public import Std
open Std

public section

/-! ## Implementation -/

def common (xs ys : List Nat) : List Nat :=
let xsSet : TreeSet Nat := .ofList xs
let ysSet : TreeSet Nat := .ofList ys
ysSet.filter (· ∈ xsSet) |>.toList

/-! ## Tests -/

set_option cbv.warning false

example : common [1, 4, 3, 34, 653, 2, 5] [5, 7, 1, 5, 9, 653, 121] = [1, 5, 653] := by cbv
example : common [5, 3, 2, 8] [3, 2] = [2, 3] := by cbv
example : common [4, 3, 2, 8] [3, 2, 4] = [2, 3, 4] := by cbv
example : common [4, 3, 2, 8] [] = [] := by cbv

/-! ## Verification -/

theorem pairwise_lt_common :
(common xs ys).Pairwise (· < ·) := by
grind [common, TreeSet.ordered_toList, compare_eq_lt]

theorem distinct_common :
(common xs ys).Pairwise (· ≠ ·) := by
grind [common, TreeSet.distinct_toList]

theorem mem_common_iff :
x ∈ common xs ys ↔ x ∈ xs ∧ x ∈ ys := by
grind [common]

/-!
## Prompt
Expand Down Expand Up @@ -45,4 +77,4 @@ def check(candidate):
assert candidate([4, 3, 2, 8], []) == []

```
-/
-/