Skip to content

Commit f2e4121

Browse files
committed
add more automation
1 parent 5938155 commit f2e4121

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

Batteries/Data/Array/Monadic.lean

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ theorem Spec.mapM_array {α β : Type w} [Monad m] [LawfulMonad m] [WPMonad m ps
2828
xs.mapM f
2929
⦃(fun bs => inv.1 (⟨xs.toList, [], by simp⟩, bs), inv.2)⦄ := by
3030
rw [Array.mapM_eq_foldlM]
31-
mvcgen
32-
invariants
31+
mvcgen invariants
3332
· inv
3433
apply step (h := ‹_›)
3534

@@ -87,8 +86,7 @@ theorem size_mapM {α β : Type u} [Monad m] [LawfulMonad m] [WPMonad m ps]
8786
xs.mapM f
8887
⦃⇓ bs => ⌜bs.size = xs.size⌝⦄ := by
8988
rw [Array.mapM_eq_foldlM]
90-
mvcgen
91-
invariants
89+
mvcgen invariants
9290
· ⇓⟨cursor, acc⟩ => ⌜acc.size = cursor.prefix.length⌝
9391
. mspec hf
9492
simp_all

Batteries/Data/List/Monadic.lean

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ private theorem Spec.mapFinIdxM_list_go [Monad m] [LawfulMonad m] [WPMonad m ps]
114114
| nil =>
115115
simp [List.mapFinIdxM.go]
116116
mvcgen
117-
simp only [List.length_nil, Nat.zero_add] at hlen
118-
simp_all
117+
grind
119118
| cons b bs ih =>
120119
simp only [List.mapFinIdxM.go]
121120
have hacc : acc.size < xs.length := by simp [List.length_cons] at hlen; omega
@@ -125,19 +124,9 @@ private theorem Spec.mapFinIdxM_list_go [Monad m] [LawfulMonad m] [WPMonad m ps]
125124
subst hb
126125
mvcgen
127126
mspec (hs acc.size _ hmot)
128-
mframe
129-
rename_i r h
130-
obtain ⟨h_p, h_motive⟩ := h
131-
mspec (ih _ (Array.size_push r ▸ h_motive) _)
132-
. simp only [Array.size_push]
133-
rw [List.drop_eq_getElem_cons hacc] at hsuff
134-
exact List.cons_inj_right _ |>.mp ‹_›
135-
. intro i hi
136-
simp only [Array.size_push] at hi
137-
simp only [Array.getElem_push]
138-
split
139-
. exact hprev i ‹_›
140-
. simp_all [show i = acc.size by omega]
127+
mframe; rename_i h
128+
mspec ih _ (Array.size_push ‹_› ▸ h.2) _ <;>
129+
grind [List.drop_eq_getElem_cons]
141130

142131
@[spec]
143132
theorem Spec.mapFinIdxM_list [Monad m] [LawfulMonad m] [WPMonad m ps]
@@ -151,7 +140,7 @@ theorem Spec.mapFinIdxM_list [Monad m] [LawfulMonad m] [WPMonad m ps]
151140
xs.mapFinIdxM f
152141
⦃(fun bs => ⌜motive xs.length ∧ ∃ eq : bs.length = xs.length, ∀ i h, p i bs[i] h⌝, exc)⦄ := by
153142
unfold List.mapFinIdxM
154-
exact Spec.mapFinIdxM_list_go hs (by simp) (by simp [h0]) (fun i hi => absurd hi (by simp))
143+
apply Spec.mapFinIdxM_list_go <;> grind
155144

156145
end Std.Do
157146

@@ -192,7 +181,7 @@ theorem anyM_iff_exists [Monad m] [LawfulMonad m] [WPMonad m ps]
192181
mframe
193182
rename_i hiff
194183
split <;> mpure_intro
195-
case isTrue => exact ⟨⟨pref, cur :: suff, h.symm⟩, (by simp), hiff.mp ‹_›⟩
184+
case isTrue => grind only
196185
intro c hsuff hlen
197186
simp only [List.length_append, List.length_singleton] at hlen
198187
by_cases hc : c.prefix.length < pref.length

0 commit comments

Comments
 (0)