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
31import datasets.verina.verina_basic_105.task
namespace Submission
privatetheorem loop_correct (a b : Array Int) (hab : a.size = b.size)
(i : Nat) (c : Array Int) (hc : c.size = a.size)
(hp : ∀ j, j < i → j < a.size → a[j]! * b[j]! = c[j]!) :
(loop a b a.size i c).size = a.size ∧
∀ j, j < a.size → a[j]! * b[j]! = (loop a b a.size i c)[j]! := by
rw [loop]
by_cases hi : i < a.size
· have hb : i < b.size := by omega
simp only [hi, hb, if_true]
apply loop_correct a b hab
· simpa using hc
· intro j hj hja
have hjc : j < c.size := by omega
by_cases h : j = i
· subst j
simp [getElem!_pos, hjc]
· have hji : j < i := by omega
simpa [getElem!_pos, hjc, h, Ne.symm h] using hp j hji hja
· simp only [hi, if_false]
exact ⟨hc, fun j hj => hp j (by omega) hj⟩
termination_by a.size - i
decreasing_by omega
theorem solution : type_of% @arrayProduct_spec_satisfied := by
intro a b hab
exact loop_correct a b hab 0 (Array.mkArray a.size 0) (by simp)
(fun j hj => False.elim (Nat.not_lt_zero j hj))
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 64e483e4-b75a-41ff-986f-faed6fc14808.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 arrayProduct_precond (a : Array Int) (b : Array Int) : Prop :=
-- !benchmark @start precond
a.size = b.size
-- !benchmark @end precond-- !benchmark @start code_auxdef loop (a b : Array Int) (len : Nat) : Nat → Array Int → Array Int
| i, c =>
if i < len then
let a_val := if i < a.size then a[i]! else 0
let b_val := if i < b.size then b[i]! else 0
let new_c := Array.set! c i (a_val * b_val)
loop a b len (i+1) new_c
else c
-- !benchmark @end code_auxdef arrayProduct (a : Array Int) (b : Array Int) (h_precond : arrayProduct_precond (a) (b)) : Array Int :=
-- !benchmark @start code
let len := a.size
let c := Array.mkArray len 0
loop a b len 0 c
-- !benchmark @end code-- !benchmark @start postcond_aux-- !benchmark @end postcond_aux
@[reducible, simp]
def arrayProduct_postcond (a : Array Int) (b : Array Int) (result: Array Int) (h_precond : arrayProduct_precond (a) (b)) :=
-- !benchmark @start postcond
(result.size = a.size) ∧ (∀ i, i < a.size → a[i]! * b[i]! = result[i]!)
-- !benchmark @end postcond-- !benchmark @start proof_aux-- !benchmark @end proof_auxtheorem arrayProduct_spec_satisfied (a: Array Int) (b: Array Int) (h_precond : arrayProduct_precond (a) (b)) :
arrayProduct_postcond (a) (b) (arrayProduct (a) (b) h_precond) h_precond := by-- !benchmark @start proof
sorry
-- !benchmark @end proof