The result contains only input strings that start with the given prefix, includes every matching input string, and preserves its number of occurrences.
1
2
3
4
5
6
7
8
9
10import human_eval.problem_29
namespace Submission
theorem solution : type_of% @correctness := by
intro xs p
refine ⟨implementation xs p, rfl, ?_⟩
simp only [implementation, List.all_eq_true, List.mem_filter, decide_eq_true_eq]
refine ⟨fun s hs => hs.2, fun s hs => hs.1, fun s hs hp => ⟨hs, hp⟩, ?_⟩
intro s hs
exact List.count_filter hs.2
end Submission
Check it yourself
Project
clever
Commit
8348039a7ff7730a126d761e71d0439735eeb3e2
Lean
leanprover/lean4:v4.27.0
Mathlib
a3a10db0e9d66acbebf76c5e6a135066525ac900
With Git and Elan installed, put the download in a fresh working directory and run this there. Use a disposable environment. Lean prints the axioms at the end. The checker allows propext, Classical.choice, and Quot.sound.
(
set -eu
proof="$PWD/d99846f3-8a53-4ae7-9b63-ee5fe8c72c52.lean"
git clone https://github.com/trishullab/clever.git clever
git -C clever checkout --detach 8348039a7ff7730a126d761e71d0439735eeb3e2
cd clever/src/lean4
elan toolchain install leanprover/lean4:v4.27.0
lake +leanprover/lean4:v4.27.0 exe cache get
lake +leanprover/lean4:v4.27.0 build +Imports.AllImports
mkdir -p '.lake/build/lib/lean/human_eval'
lake +leanprover/lean4:v4.27.0 env lean -DautoImplicit=false --root=. -o '.lake/build/lib/lean/human_eval/problem_29.olean' 'human_eval/problem_29.lean'
check_dir="$(mktemp -d)"
trap 'rm -f "$check_dir/Check.lean"; rmdir "$check_dir"' EXIT
printf "%s\n" "import Lean" > "$check_dir/Check.lean"
cat "$proof" >> "$check_dir/Check.lean"
cat >> "$check_dir/Check.lean" <<'SOLVE_CHECK'
example : type_of% @_root_.correctness := @_root_.Submission.solution
#print axioms Submission.solution
SOLVE_CHECK
lake +leanprover/lean4:v4.27.0 env lean "$check_dir/Check.lean"
)
Download the receipt verifier and public key. Run python3 verify-proof.py certificate.json d99846f3-8a53-4ae7-9b63-ee5fe8c72c52.lean proof-key.pem with OpenSSL 3.
Show full file and definitions
import Imports.AllImports
-- start_def problem_details
/--
function_signature: "def filter_by_prefix(strings: List[str], prefix: str) -> List[str]"
docstring: |
Filter an input list of strings only for ones that start with a given prefix.
test_cases:
- input:
- []
- "a"
expected_output: []
- input:
- ["abc", "bcd", "cde", "array"]
- "a"
expected_output: ["abc", "array"]
-/
-- end_def problem_details-- start_def problem_specdef problem_spec
-- function signature
(implementation: List String → String → List String)
-- inputs
(strings: List String)
(pref: String) :=
-- spec
let spec (result: List String) :=
result.all (λ s => s.startsWith pref) ∧
result.all (λ s => s ∈ strings) ∧
strings.all (λ s => s.startsWith pref → s ∈ result) ∧
∀ s : String, s ∈ result → result.count s = strings.count s;
-- program termination
∃ result, implementation strings pref = result ∧
spec result
-- end_def problem_spec-- start_def generated_specdef generated_spec
-- function signature
(implementation: List String → String → List String)
-- inputs
(strings: List String)
(pref: String) : Prop :=
-- end_def generated_spec-- start_def generated_spec_body
sorry
-- end_def generated_spec_body-- start_def spec_isomorphismtheorem spec_isomorphism:
∀ implementation,
(∀ strings pref, problem_spec implementation strings pref) ↔
(∀ strings pref, generated_spec implementation strings pref) :=
-- end_def spec_isomorphism-- start_def spec_isomorphism_proof
sorry
-- end_def spec_isomorphism_proof-- start_def implementation_signaturedef implementation (strings: List String) (pref: String) : List String :=
-- end_def implementation_signature-- start_def implementation
strings.filter (λ s => s.startsWith pref)
-- end_def implementation-- Uncomment the following test cases after implementing the function-- start_def test_cases
#test implementation [] "a" = []
#test implementation ["abc", "bcd", "cde", "array"] "a" = ["abc", "array"]
-- end_def test_cases-- start_def correctness_definitiontheorem correctness
(strings: List String)
(pref: String)
: problem_spec implementation strings pref
:=
-- end_def correctness_definition-- start_def correctness_proofby
unfold problem_spec
let result := implementation strings pref
use result
simp [result]
repeat sorry
-- end_def correctness_proof