Direct use. This proves an array append operation keeps every original entry unchanged, places the new number last, and grows the length by exactly one. Reliable software.
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62import datasets.verina.verina_basic_72.task
namespace Submission
theorem copy_toList (a : Array Int) : ∀ (n i : Nat) (acc : Array Int), a.size - i = n →
(copy a i acc).toList = acc.toList ++ a.toList.drop i := by
intro n
induction n with
| zero =>
intro i acc hn
have hi : ¬ i < a.size := by omega
rw [copy, if_neg hi]
have hd : a.toList.drop i = [] := by
apply List.drop_eq_nil_of_le
simp only [Array.length_toList]
omega
rw [hd, List.append_nil]
| succ n ih =>
intro i acc hn
have hi : i < a.size := by omega
rw [copy, if_pos hi, ih (i+1) _ (by omega)]
have hl : i < a.toList.length := by simp only [Array.length_toList]; omega
rw [List.drop_eq_getElem_cons hl]
first
| simp [getElem!_pos a i hi]
| simp [hi]
| simp [Array.getElem!_eq_getD, Array.getD, hi]
theorem copy_self (a : Array Int) : copy a 0 Array.empty = a := by
have h1 := copy_toList a (a.size - 0) 0 Array.empty rfl
have h2 : (Array.empty : Array Int).toList = [] := rfl
rw [h2, List.nil_append, List.drop_zero] at h1
first
| exact Array.ext' h1
| exact Array.toList_inj.mp h1
| (cases a; simp_all)
theorem solution : type_of% @append_spec_satisfied := by
intro a b h
simp only [append_postcond, append, copy_self]
refine ⟨?_, ?_, ?_⟩
· rw [List.all_eq_true]
intro x hx
have hx' : x < a.size := by
first
| (simp [List.mem_range'_1] at hx; omega)
| (simp [List.mem_range'] at hx; omega)
| (rw [List.mem_range'] at hx; obtain ⟨j, hj, rfl⟩ := hx; omega)
have h1 : x < (a.push b).size := by simp only [Array.size_push]; omega
have h1' : x < a.size + 1 := by omega
first
| (simp [getElem!_pos, hx', h1, h1', Array.getElem_push_lt]; done)
| (simp [getElem!_pos, hx', h1, h1', Array.getElem_push]; done)
| (rw [getElem!_pos (a.push b) x h1]; simp [getElem!_pos, hx', Array.getElem_push_lt]; done)
| (simp [getElem!_def, Array.getElem?_push, hx', h1, h1']; done)
| (simp [getElem!_def, Array.getElem?_push_lt, hx', h1, h1']; done)
| (simp [Array.getElem!_eq_getD, Array.getD, hx', h1, h1', Array.getElem_push_lt]; done)
· have h2 : a.size < (a.push b).size := by simp only [Array.size_push]; omega
first
| (rw [getElem!_pos (a.push b) a.size h2]; all_goals simp)
| simp
· simp
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 7352fb03-cbd3-4f58-b1f0-377a6fa7ead0.lean proof-key.pem with OpenSSL 3.