1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26import human_eval.problem_16
namespace Submission
theorem solution : type_of% @correctness := by
intro string
unfold problem_spec
refine ⟨implementation string, rfl, ?_⟩
dsimp only [implementation]
apply congrArg Finset.card
have hlow : string.toLower.toList = string.toList.map Char.toLower := by
simp [String.toLower]
rw [hlow]
ext c
simp only [List.mem_toFinset, List.mem_map, Finset.mem_image, Set.mem_toFinset, Set.mem_setOf_eq]
have hlen : string.toList.length = string.length := by simp
constructor
· rintro ⟨a, ha, rfl⟩
rw [List.mem_iff_getElem] at ha
rcases ha with ⟨i, hi, rfl⟩
refine ⟨string.toList[i], ⟨i, by omega, getElem!_pos string.toList i hi⟩, rfl⟩
· rintro ⟨a, ⟨i, hi, rfl⟩, rfl⟩
have hi' : i < string.toList.length := by omega
refine ⟨string.toList[i], List.mem_iff_getElem.mpr ⟨i, hi', rfl⟩, ?_⟩
rw [getElem!_pos string.toList i hi']
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/41b1168d-e12c-4fb9-a987-0123314f7e5a.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_16.olean' 'human_eval/problem_16.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 41b1168d-e12c-4fb9-a987-0123314f7e5a.lean proof-key.pem with OpenSSL 3.
Show full file and definitions
import Imports.AllImports
-- start_def problem_details
/--
function_signature: "def count_distinct_characters(string: str) -> int"
docstring: |
Given a string, find out how many distinct characters (regardless of case) does it consist of
test_cases:
- input: "xyzXYZ"
expected_output: 3
- input: "Jerry"
expected_output: 4
-/
-- end_def problem_details-- start_def problem_specdef problem_spec
-- function signature
(implementation: String → Nat)
-- inputs
(string: String) :=
-- spec
let spec (result: Nat) :=
let string_idx := {i: Nat | i < string.length}.toFinset
let characters := string_idx.image (fun i => string.toList[i]!)
let lowercase_characters := characters.image (fun c => c.toLower)
result = lowercase_characters.card;
-- program termination
∃ result, implementation string = result ∧
spec result
-- end_def problem_spec-- start_def generated_specdef generated_spec
-- function signature
(implementation: String → Nat)
-- inputs
(string: String) : Prop :=
-- end_def generated_spec-- start_def generated_spec_body
sorry
-- end_def generated_spec_body-- start_def spec_isomorphismtheorem spec_isomorphism:
∀ implementation,
(∀ string, problem_spec implementation string) ↔
(∀ string, generated_spec implementation string) :=
-- end_def spec_isomorphism-- start_def spec_isomorphism_proof
sorry
-- end_def spec_isomorphism_proof-- start_def implementation_signaturedef implementation (string: String) : Nat :=
-- end_def implementation_signature-- start_def implementation
let char_set := string.toLower.toList.toFinset
char_set.card
-- end_def implementation-- Uncomment the following test cases after implementing the function-- start_def test_cases
#test implementation "xyzXYZ" = 3
#test implementation "Jerry" = 4
-- end_def test_cases-- start_def correctness_definitiontheorem correctness
(string: String)
: problem_spec implementation string
:=
-- end_def correctness_definition-- start_def correctness_proofby
unfold problem_spec
let result := implementation string
use result
simp [result]
simp [implementation]
rcases string with ⟨data⟩
induction data
try simp
have h1: "".toLower = "" := by
unfold String.toLower
unfold Char.toLower
unfold String.map
unfold String.mapAux
simp
sorry
-- end_def correctness_proof
Reduce card equality to Finset extensionality, rewrite String.toLower.toList as a list map, and match characters via List.mem_iff_getElem and getElem!_pos.