@@ -23,46 +23,11 @@ theorem captures_of_path.group {tag} (eq : nfa.pushRegex next (.group tag e) = r
2323 ∃ groups, EquivUpdate groups update ∧ (Expr.group tag e).Captures pos pos' groups := by
2424 open Compile.ProofData Group in
2525 let pd := Group.intro eq
26- simp [pd.eq_result eq] at path
27-
28- cases path with
29- | last step =>
30- have ⟨eqnext, _, _⟩ := step_start_iff.mp step
31- have ge := ge_pushRegex_start (result := nfaExpr) rfl
32- simp [←eqnext, nfaClose] at ge
33- have : next < pd.nfa.size := next_lt
34- omega
35- | @more i pos j posm k pos'' update updates step rest =>
36- have ⟨hj, hpos, hupdate⟩ := step_start_iff.mp step
37- simp [hupdate]
38- simp [hj, hpos] at rest
39-
40- have rest := castToExpr wf next_lt rest
41- have next_lt_close : next < nfaClose.size := by
42- simp [nfaClose]
43- exact Nat.lt_trans next_lt (Nat.lt_add_one _)
44- have ge_expr_start : nfaClose.size ≤ nfaExpr.start := ge_pushRegex_start rfl
45- have ne_next : next ≠ nfaClose.start := by
46- simp [nfaClose]
47- exact Nat.ne_of_lt next_lt
48- have ⟨posm, updateExpr, updateClose, equ, pathExpr, pathClose⟩ :=
49- rest.path_next_of_ne (result := nfaExpr) rfl next_lt_close ge_expr_start ne_next
50-
51- have wfClose := wfClose wf next_lt
52- have ⟨groupExpr, eqv, c⟩ := ih (result := nfaExpr) rfl wfClose wfClose.start_lt pathExpr
53-
54- have : nfaExpr[nfaClose.start]'(by grind) = nfa'[nfaClose.start]'(by grind) := by
55- grind
56- cases pathClose with
57- | last step =>
58- have ⟨_, hpos, hupdate⟩ := step_close_iff.mp (step.cast this )
59- rw [←hpos] at c
60- simp [equ, hupdate, ←hpos]
61- exact ⟨.group tag pos pos' groupExpr, .group eqv, .group c⟩
62- | more step rest =>
63- have ⟨hj, _, _⟩ := step_close_iff.mp (step.cast this )
64- have : nfa.size ≤ next := show nfa.size ≤ pd.next from hj ▸ rest.ge
65- omega
26+ simp only [pd.eq_result eq] at path
27+ obtain ⟨updates, rfl, pathExpr⟩ := (pd.path_start_iff wf next_lt).mp path
28+ have wfClose := pd.wfClose wf next_lt
29+ have ⟨groups, eqv, c⟩ := ih rfl wfClose wfClose.start_lt pathExpr
30+ exact ⟨.group tag pos pos' groups, .group eqv, .group c⟩
6631
6732theorem captures_of_path.alternate {e₁ e₂} (eq : nfa.pushRegex next (.alternate e₁ e₂) = result)
6833 (wf : nfa.WellFormed) (next_lt : next < nfa.size)
@@ -80,39 +45,16 @@ theorem captures_of_path.alternate {e₁ e₂} (eq : nfa.pushRegex next (.altern
8045 ∃ groups, EquivUpdate groups update ∧ (Expr.alternate e₁ e₂).Captures pos pos' groups := by
8146 open Compile.ProofData Alternate in
8247 let pd := Alternate.intro eq
83- simp [pd.eq_result eq] at path
84-
48+ simp only [pd.eq_result eq] at path
49+ obtain path := (pd.path_start_iff wf next_lt).mp path
8550 cases path with
86- | last step =>
87- have := step_start_iff.mp step
88- have : next < nfa₁.start := Nat.lt_of_lt_of_le next_lt (ge_pushRegex_start rfl)
89- have : next < nfa₂.start := Nat.lt_of_lt_of_le (Nat.lt_trans next_lt nfa₁_property) (ge_pushRegex_start rfl)
90- omega
91- | @more i pos j posm k pos'' update updates step rest =>
92- have ⟨hj, hpos, hupdate⟩ := step_start_iff.mp step
93- simp [hupdate]
94- cases hj with
95- | inl hj =>
96- simp [hj, hpos] at rest
97- have rest := castTo₁ wf next_lt rest
98- have ⟨groups, eqv, c⟩ := ih₁ rfl wf next_lt rest
99- exact ⟨groups, eqv, .alternateLeft c⟩
100- | inr hj =>
101- simp [hj, hpos] at rest
102-
103- have rest := castTo₂ wf next_lt rest
104- have rest : nfa₂.Path nfa₁.size nfa₂.start pos next pos' updates := by
105- apply rest.liftBound' (ge_pushRegex_start rfl)
106- intro i pos j pos' update gei gej step
107- cases (step.liftBound' gei).eq_or_ge_of_pushRegex with
108- | inl eq =>
109- have : nfa.size ≤ next := show nfa.size ≤ pd.next from eq ▸ gej
110- omega
111- | inr ge => exact ge
112-
113- have wf₁ := wf₁ wf next_lt
114- have ⟨groups, eqv, c⟩ := ih₂ rfl wf₁ (Nat.lt_trans next_lt nfa₁_property) rest
115- exact ⟨groups, eqv, .alternateRight c⟩
51+ | inl path₁ =>
52+ have ⟨groups, eqv, c⟩ := ih₁ rfl wf next_lt path₁
53+ exact ⟨groups, eqv, .alternateLeft c⟩
54+ | inr path₂ =>
55+ have wf₁ := wf₁ wf next_lt
56+ have ⟨groups, eqv, c⟩ := ih₂ rfl wf₁ (by grind) path₂
57+ exact ⟨groups, eqv, .alternateRight c⟩
11658
11759theorem captures_of_path.concat {e₁ e₂} (eq : nfa.pushRegex next (.concat e₁ e₂) = result)
11860 (wf : nfa.WellFormed) (next_lt : next < nfa.size)
@@ -130,19 +72,15 @@ theorem captures_of_path.concat {e₁ e₂} (eq : nfa.pushRegex next (.concat e
13072 ∃ groups, EquivUpdate groups update ∧ (Expr.concat e₁ e₂).Captures pos pos' groups := by
13173 open Compile.ProofData Concat in
13274 let pd := Concat.intro eq
133- simp [pd.eq_result eq] at path
134- have next_lt₂ : next < nfa₂.size := Nat.lt_trans next_lt nfa₂_property
135- have ge_start : nfa₂.size ≤ nfa'.start := ge_pushRegex_start rfl
136- have ne_next : next ≠ nfa₂.start := Nat.ne_of_lt (Nat.lt_of_lt_of_le next_lt (ge_pushRegex_start rfl))
137- have ⟨itm, update₁, update₂, equ, path₁, path₂⟩ := path.path_next_of_ne rfl next_lt₂ ge_start ne_next
138-
75+ simp only [pd.eq_result eq] at path
76+ obtain ⟨pm, updates₁, updates₂, rfl, path₁, path₂⟩ := (pd.path_start_iff wf next_lt).mp path
13977 have wf₂ := wf₂ wf next_lt
140- have ⟨group ₁, eqv₁, c₁⟩ := ih₁ rfl wf₂ wf₂.start_lt path₁
141- have ⟨group ₂, eqv₂, c₂⟩ := ih₂ rfl wf next_lt (castTo₂ wf next_lt path₂)
142- exact ⟨.concat group₁ group₂, equ ▸ .concat eqv₁ eqv₂, .concat c₁ c₂⟩
78+ have ⟨groups ₁, eqv₁, c₁⟩ := ih₁ rfl wf₂ wf₂.start_lt path₁
79+ have ⟨groups ₂, eqv₂, c₂⟩ := ih₂ rfl wf next_lt path₂
80+ exact ⟨.concat groups₁ groups₂, .concat eqv₁ eqv₂, .concat c₁ c₂⟩
14381
14482open Compile.ProofData Star in
145- theorem captures_of_path.star_of_loop [Star] {greedy} (loop : Loop pos pos' update)
83+ theorem captures_of_path.star_of_loop [Star] {greedy : Bool } (loop : Loop pos pos' update)
14684 (ih : ∀ {pos pos' : Pos s} {update},
14785 nfa'.Path nfaPlaceholder.size nfaExpr.start pos nfaPlaceholder.start pos' update →
14886 ∃ groups, EquivUpdate groups update ∧ e.Captures pos pos' groups) :
@@ -165,23 +103,20 @@ theorem captures_of_path.star {greedy e} (eq : nfa.pushRegex next (.star greedy
165103 ∃ groups, EquivUpdate groups update ∧ (Expr.star greedy e).Captures pos pos' groups := by
166104 open Compile.ProofData Star in
167105 let pd := Star.intro eq
168- simp [pd.eq_result eq] at path
169- cases path with
170- | last step =>
171- obtain ⟨_, rfl, rfl⟩ := step_start_iff.mp step
106+ simp only [pd.eq_result eq] at path
107+ have h := (pd.path_start_iff next_lt).mp path
108+ match h with
109+ | .inl ⟨hp, hupdate⟩ =>
110+ subst pos' update
172111 exact ⟨.empty, .empty, .starEpsilon⟩
173- | @more _ _ i pos'' _ _ _ updates step rest =>
174- obtain ⟨eqi, rfl, rfl⟩ := step_start_iff.mp step
175- cases eqi with
176- | inl eqi =>
177- have loop := Loop.intro wf next_lt (eqi ▸ rest)
178- apply captures_of_path.star_of_loop (greedy := greedy) loop
112+ | .inr path =>
113+ have loop := Loop.intro wf next_lt path
114+ apply captures_of_path.star_of_loop loop
179115
180- intro pos pos' update path
181- have path := castToExpr wf path
182- have wfPlaceholder := wfPlaceholder wf
183- exact ih (by grind) wfPlaceholder wfPlaceholder.start_lt path
184- | inr eqi => grind
116+ intro pos pos' update path
117+ have path := castToExpr wf path
118+ have wfPlaceholder := wfPlaceholder wf
119+ exact ih (by grind) wfPlaceholder wfPlaceholder.start_lt path
185120
186121public theorem captures_of_path (eq : nfa.pushRegex next e = result)
187122 (wf : nfa.WellFormed) (next_lt : next < nfa.size)
@@ -191,27 +126,27 @@ public theorem captures_of_path (eq : nfa.pushRegex next e = result)
191126 induction e generalizing nfa next result pos pos' update with
192127 | empty =>
193128 let pd := Empty.intro eq
194- simp [pd.eq_result eq] at path
129+ simp only [pd.eq_result eq] at path
195130 exact absurd path pd.not_path_start
196131 | epsilon =>
197132 let pd := Epsilon.intro eq
198- simp [pd.eq_result eq] at path
133+ simp only [pd.eq_result eq] at path
199134 have := (pd.path_start_iff next_lt).mp path
200135 simp [this ]
201136 exact ⟨.empty, .empty, .epsilon⟩
202137 | anchor a =>
203138 let pd := Anchor.intro eq
204- simp [pd.eq_result eq] at path
139+ simp only [pd.eq_result eq] at path
205140 obtain ⟨_, rfl, rfl, test⟩:= (pd.path_start_iff next_lt).mp path
206141 exact ⟨.empty, .empty, .anchor test⟩
207142 | char c =>
208143 let pd := Char.intro eq
209- simp [pd.eq_result eq] at path
144+ simp only [pd.eq_result eq] at path
210145 obtain ⟨_, rfl, ne, rfl, rfl⟩ := (pd.path_start_iff next_lt).mp path
211146 exact ⟨.empty, .empty, .char ne rfl⟩
212147 | classes cs =>
213148 let pd := Classes.intro eq
214- simp [pd.eq_result eq] at path
149+ simp only [pd.eq_result eq] at path
215150 obtain ⟨_, rfl, ne, rfl, mem⟩ := (pd.path_start_iff next_lt).mp path
216151 exact ⟨.empty, .empty, .sparse ne mem⟩
217152 | group tag e ih => exact captures_of_path.group eq wf next_lt path ih
0 commit comments