Skip to content

Commit 34c4f56

Browse files
committed
Slightly faster proofs
1 parent d9517ea commit 34c4f56

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

Valaig/ForStd.lean

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,23 @@ private def mapMem.step {xs : Array α} (xs' : Array α) (i : Nat)
4444
(h : ∃ h1 h2, xs'[i]'h1 = xs[i]'h2) : Array α :=
4545
have hxs : i < xs.size := by lia
4646
have hxs' : i < xs'.size := by lia
47-
xs'.modifyMem i hxs' <| fun ⟨x, p⟩ => f i hxs x (by lia)
47+
xs'.modifyMem i hxs' fun ⟨x, p⟩ =>
48+
f i hxs x (by simp_all)
4849

4950
private theorem mapMem.step.size_eq : (step xs' i f hstep).size = xs'.size := by
5051
grind only [step, size_modifyMem]
5152

5253
private theorem mapMem.step.eq_above {j : Nat} (h1 : j > i) (h2 : j < xs'.size) :
53-
(step xs' i f hstep)[j]'(by rw [step.size_eq]; omega) = xs'[j] := by
54-
grind only [= getElem_set, step, modifyMem_def]
54+
have h := by grind only [size_eq]
55+
(step xs' i f hstep)[j]'h = xs'[j] := by
56+
grind only [getElem_set, step, modifyMem_def]
57+
58+
private theorem mapMem.step.eq_above' {j : Nat} (h1 : j > i) (h2 : j < xs'.size)
59+
(h3 : xs.size = xs'.size) (_ : xs[j] = xs'[j]) :
60+
have h := by grind only [size_eq]
61+
have h' := by grind only [size_eq]
62+
(step xs' i f hstep)[j]'h = xs[j]'h' := by
63+
grind only [eq_above]
5564

5665
-- TODO: This can be specialized to use usize for the iterator and also made possible to return
5766
-- different type
@@ -99,13 +108,26 @@ private theorem mapMem.go.getElem {j : Nat} (h : j < xs'.size) :
99108
| zero => lia
100109
| succ fuel motive =>
101110
split
102-
· lia
103-
· simp
111+
· omega
112+
· simp only
104113
unfold go
105-
rw [@motive (xs' := step xs' i f (by grind))]
106-
· grind only [step, modifyMem_def, getElem_set]
114+
rw [@motive (xs' := step xs' i f (by grind only))]
115+
· split
116+
· rw [hgo (by omega) (by omega)]; lia
117+
· simp only [step, modifyMem_def]
118+
split
119+
· have : i = j := by omega
120+
subst this
121+
rw [Array.getElem_set_self]
122+
have := @hgo i (by omega) (by omega)
123+
congr
124+
· rw [Array.getElem_set_ne]
125+
omega
107126
· rwa [step.size_eq]
108-
· grind only [mapMem.step.eq_above]
127+
· intros
128+
rw [←hgo (by omega)]
129+
apply mapMem.step.eq_above
130+
omega
109131
· rwa [step.size_eq]
110132
· omega
111133

0 commit comments

Comments
 (0)