1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25import human_eval.problem_31
namespace Submission
theorem solution : type_of% @correctness := by
intro x
refine ⟨implementation x, rfl, ?_⟩
simp only [implementation, decide_eq_true_eq]
rw [Nat.prime_def]
constructor
· rintro ⟨hn, hd⟩
refine ⟨hn, ?_⟩
rintro ⟨k, hk, hkn, hm⟩
rcases hd k (Nat.dvd_of_mod_eq_zero hm) with h | h <;> omega
· rintro ⟨hn, hd⟩
refine ⟨hn, ?_⟩
intro k hk
have hkn := Nat.le_of_dvd (by omega : 0 < x) hk
have hk0 : k ≠ 0 := by
intro hz
subst k
simp at hk
omega
by_contra he
push_neg at he
exact hd ⟨k, by omega, by omega, Nat.mod_eq_zero_of_dvd hk⟩
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/07e72bd5-8e88-4660-81cd-a0832baf903c.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_31.olean' 'human_eval/problem_31.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 07e72bd5-8e88-4660-81cd-a0832baf903c.lean proof-key.pem with OpenSSL 3.
Show full file and definitions
import Imports.AllImports
-- start_def problem_details
/--
function_signature: "def is_prime(n)"
docstring: |
Return true if a given number is prime, and false otherwise.
test_cases:
- input: 6
output: False
- input: 101
output: True
- input: 11
output: True
- input: 13441
output: True
- input: 61
output: True
- input: 4
output: False
- input: 1
output: False
-/
-- end_def problem_details-- start_def problem_specdef problem_spec
-- function signature
(implementation: Nat → Bool)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Bool) :=
result ↔ (2 ≤ n ∧ ¬ (∃ k, 2 ≤ k ∧ k < n ∧ n % k = 0));
-- program termination
∃ result,
implementation n = result ∧
spec result
-- end_def problem_spec-- start_def generated_specdef generated_spec
-- function signature
(implementation: Nat → Bool)
-- inputs
(n: Nat) : Prop :=
-- end_def generated_spec-- start_def generated_spec_body
sorry
-- end_def generated_spec_body-- start_def spec_isomorphismtheorem spec_isomorphism:
∀ implementation,
(∀ n, problem_spec implementation n) ↔
(∀ n, generated_spec implementation n) :=
-- end_def spec_isomorphism-- start_def spec_isomorphism_proof
sorry
-- end_def spec_isomorphism_proof-- start_def implementation_signaturedef implementation (n: Nat): Bool :=
-- end_def implementation_signature-- start_def implementation
Nat.Prime n
-- end_def implementation-- Uncomment the following test cases after implementing the function-- start_def test_cases
#test implementation 6 = false
#test implementation 101 = true
#test implementation 11 = true
#test implementation 13441 = true
#test implementation 61 = true
#test implementation 4 = false
#test implementation 1 = false
-- end_def test_cases-- start_def correctness_definitiontheorem correctness
(n: Nat)
: problem_spec implementation n
:=
-- end_def correctness_definition-- start_def correctness_proofby
unfold problem_spec
let result := implementation n
use result
simp [result]
simp [implementation]
sorry
-- end_def correctness_proof