import Imports.AllImports
-- start_def problem_details
/--
function_signature: "def greatest_common_divisor(a: int, b: int) -> int"
docstring: |
Return a greatest common divisor of two integers a and b
test_cases:
- input:
- 25
- 15
expected_output: 5
- input:
- 3
- 5
expected_output: 1
-/
-- end_def problem_details-- start_def problem_specdef problem_spec
-- function signature
(implementation: Int → Int → Int)
-- inputs
(a b: Int) :=
-- spec
let spec (result: Int) :=
(result ∣ a) ∧
(result ∣ b) ∧
(result ≥ 0) ∧
(∀ (d': Int),
(d' ∣ a) → (d' ∣ b) →
d' ∣ result);
-- program termination
∃ result, implementation a b = result ∧
spec result
-- end_def problem_spec-- start_def generated_specdef generated_spec
-- function signature
(implementation: Int → Int → Int)
-- inputs
(a b: Int) : Prop :=
-- end_def generated_spec--start_def generated_spec_body
implementation a b = Int.gcd a b
--end_def generated_spec_body-- start_def spec_isomorphismtheorem spec_isomorphism:
∀ implementation,
(∀ a b, problem_spec implementation a b) ↔
(∀ a b, generated_spec implementation a b) :=
-- end_def spec_isomorphism-- start_def spec_isomorphism_proof
sorry
-- end_def spec_isomorphism_proof-- start_def implementation_signaturedef implementation (a b: Int) : Int :=
-- end_def implementation_signature-- start_def implementation
(Int.gcd a b)
-- end_def implementation-- Uncomment the following test cases after implementing the function-- start_def test_cases
#test implementation 25 15 = 5
#test implementation 3 5 = 1
-- end_def test_cases-- start_def correctness_definitiontheorem correctness
(a b: Int)
: problem_spec implementation a b
:=
-- end_def correctness_definition-- start_def correctness_proofby
unfold problem_spec
let result := implementation a b
use result
simp [result]
sorry
-- end_def correctness_proof
1
2
3
4
5
6
7
8import human_eval.problem_13
namespace Submission
theorem solution : type_of% @correctness := by
intro a b
refine ⟨implementation a b, rfl, ?_⟩
exact ⟨Int.gcd_dvd_left a b, Int.gcd_dvd_right a b, Int.ofNat_nonneg _,
fun _ ha hb => Int.dvd_coe_gcd ha hb⟩
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/e963b2d7-870e-4775-accc-f1b796bb94bc.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_13.olean' 'human_eval/problem_13.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 e963b2d7-870e-4775-accc-f1b796bb94bc.lean proof-key.pem with OpenSSL 3.