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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41import datasets.verina.verina_basic_75.task
namespace Submission
privatetheorem scan (a : Array Int) (i : Nat) (c : Int)
(hp : ∀ j, j < i → j < a.size → c ≤ a[j]!)
(hw : ∃ j, j < a.size ∧ c = a[j]!) :
let r := loop a i c
(∀ j, j < a.size → r ≤ a[j]!) ∧ (∃ j, j < a.size ∧ r = a[j]!) := by
dsimp only
rw [loop]
by_cases hi : i < a.size
· rw [if_pos hi]
let next := if c > a[i]! then a[i]! else c
have hb : ∀ j, j < i + 1 → j < a.size → next ≤ a[j]! := by
intro j hj hja
by_cases he : j = i
· subst j
dsimp [next]
split <;> omega
· have hh := hp j (by omega) hja
dsimp [next]
split <;> omega
have he : ∃ j, j < a.size ∧ next = a[j]! := by
dsimp [next]
split
· exact ⟨i, hi, rfl⟩
· exact hw
exact scan a (i + 1) next hb he
· rw [if_neg hi]
exact ⟨fun j hj => hp j (by omega) hj, hw⟩
termination_by a.size - i
decreasing_by omega
theorem solution : type_of% @minArray_spec_satisfied := by
intro a h
have hn : 0 < a.size := h
exact scan a 1 a[0]! (by
intro j hj _
have he : j = 0 := by omega
subst j
exact Int.le_refl _) ⟨0, hn, rfl⟩
end Submission
Check it yourself
Project
verina
Commit
66b3ce5014edafb20cb26b87c681e7f31847249f
Lean
leanprover/lean4:v4.18.0
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.
Download the receipt verifier and public key. Run python3 verify-proof.py certificate.json b63693dc-9aa7-43c1-b900-03cb717251fb.lean proof-key.pem with OpenSSL 3.
Show full file and definitions
-- !benchmark @start import type=solution-- !benchmark @end import-- !benchmark @start solution_aux-- !benchmark @end solution_aux-- !benchmark @start precond_aux-- !benchmark @end precond_aux
@[reducible, simp]
def minArray_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
a.size > 0
-- !benchmark @end precond-- !benchmark @start code_auxdef loop (a : Array Int) (i : Nat) (currentMin : Int) : Int :=
if i < a.size then
let newMin := if currentMin > a[i]! then a[i]! else currentMin
loop a (i + 1) newMin
else
currentMin
-- !benchmark @end code_auxdef minArray (a : Array Int) (h_precond : minArray_precond (a)) : Int :=
-- !benchmark @start code
loop a 1 (a[0]!)
-- !benchmark @end code-- !benchmark @start postcond_aux-- !benchmark @end postcond_aux
@[reducible, simp]
def minArray_postcond (a : Array Int) (result: Int) (h_precond : minArray_precond (a)) :=
-- !benchmark @start postcond
(∀ i : Nat, i < a.size → result <= a[i]!) ∧ (∃ i : Nat, i < a.size ∧ result = a[i]!)
-- !benchmark @end postcond-- !benchmark @start proof_aux-- !benchmark @end proof_auxtheorem minArray_spec_satisfied (a: Array Int) (h_precond : minArray_precond (a)) :
minArray_postcond (a) (minArray (a) h_precond) h_precond := by-- !benchmark @start proof
sorry
-- !benchmark @end proof