-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch.lean
39 lines (35 loc) · 948 Bytes
/
Search.lean
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
@[simp]
theorem Subarray.size_popFront (a : Subarray α) : a.popFront.size = a.size.pred := by
cases h : a.size with
| zero =>
have : ¬a.start < a.stop := by
rw [Nat.not_lt_eq, ← Nat.zero_add a.start]
exact Nat.le_add_of_sub_le <| Nat.le_of_eq h
simp [popFront, this]
exact h
| succ =>
rw [← h]
have : a.start < a.stop := by
dsimp [size] at h
have := Nat.le_of_eq h
sorry
simp [popFront, this]
rfl
variable [BEq α] (x : α) (a : Subarray α)
def linsearch (a : Subarray α) : Option Nat :=
if _ : 0 < a.size
then
if a[0] == x
then some 0
else linsearch a.popFront
else none
termination_by _ => a.size
def ilinsearch : Option Nat := Id.run do
for h : i in [:a.size] do
if a[i]'h.2 == x then
return some i
return none
theorem ilinsearch_eq_linsearch : linsearch x a = ilinsearch x q := by
unfold linsearch ilinsearch
dsimp [Id.run]
sorry