@@ -6,7 +6,7 @@ import RegexCorrectness.Backtracker.Path
66set_option autoImplicit false
77
88open Regex.Data (BitMatrix BVPos)
9- open String (ValidPos )
9+ open String (Pos )
1010open Regex.NFA (Step)
1111
1212namespace Regex.Backtracker.captureNextAux
4646
4747section
4848
49- variable {s : String} {nfa : NFA} {wf : nfa.WellFormed} {startPos : ValidPos s}
49+ variable {s : String} {nfa : NFA} {wf : nfa.WellFormed} {startPos : Pos s}
5050 {visited : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )} {stack : List (StackEntry (HistoryStrategy s) nfa startPos)} {update' visited'}
5151
5252def StackInv (wf : nfa.WellFormed) (bvpos : BVPos startPos) (stack : List (StackEntry (HistoryStrategy s) nfa startPos)) : Prop :=
@@ -156,11 +156,11 @@ end
156156
157157section
158158
159- variable {s : String} {nfa : NFA} {wf : nfa.WellFormed} {startPos : ValidPos s}
159+ variable {s : String} {nfa : NFA} {wf : nfa.WellFormed} {startPos : Pos s}
160160 {bvpos₀ : BVPos startPos} {visited : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )} {stack : List (StackEntry (HistoryStrategy s) nfa startPos)}
161161
162162def ClosureInv (bvpos₀ : BVPos startPos) (visited : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )) (stack : List (StackEntry (HistoryStrategy s) nfa startPos)) : Prop :=
163- ∀ (state : Fin nfa.nodes.size) (bvpos : BVPos startPos) (state' : Fin nfa.nodes.size) (bvpos' : BVPos startPos) (update : Option (Nat × ValidPos s)),
163+ ∀ (state : Fin nfa.nodes.size) (bvpos : BVPos startPos) (state' : Fin nfa.nodes.size) (bvpos' : BVPos startPos) (update : Option (Nat × Pos s)),
164164 bvpos₀ ≤ bvpos →
165165 visited.get state bvpos.index →
166166 nfa.Step 0 state bvpos.current state' bvpos'.current update →
@@ -171,7 +171,7 @@ namespace ClosureInv
171171-- Preservation of the non-visited cases
172172theorem preserves' {entry stack'} (inv : ClosureInv bvpos₀ visited (entry :: stack))
173173 (nextEntries : List (StackEntry (HistoryStrategy s) nfa startPos)) (hstack : stack' = nextEntries ++ stack)
174- (hnext : ∀ (state' : Fin nfa.nodes.size) (bvpos' : BVPos startPos) (update : Option (Nat × ValidPos s)),
174+ (hnext : ∀ (state' : Fin nfa.nodes.size) (bvpos' : BVPos startPos) (update : Option (Nat × Pos s)),
175175 nfa.Step 0 entry.state entry.pos.current state' bvpos'.current update →
176176 ∃ entry' ∈ nextEntries, entry'.state = state' ∧ entry'.pos = bvpos') :
177177 ClosureInv bvpos₀ (visited.set entry.state entry.pos.index) stack' := by
@@ -256,7 +256,7 @@ theorem preserves {stack update state bvpos} (wf : nfa.WellFormed) (inv : Closur
256256 | char_neg stack' update state bvpos c state' hn h =>
257257 rw [pushNext.char_neg hn h]
258258 apply inv.preserves' [] (by simp)
259- have {ne : bvpos.current ≠ s.endValidPos } : bvpos.current.get ne ≠ c := by
259+ have {ne : bvpos.current ≠ s.endPos } : bvpos.current.get ne ≠ c := by
260260 match h with
261261 | .inl eq => simp [eq] at ne
262262 | .inr ⟨ne', hc⟩ => simpa [BVPos.get] using hc
@@ -272,7 +272,7 @@ theorem preserves {stack update state bvpos} (wf : nfa.WellFormed) (inv : Closur
272272 | sparse_neg stack' update state bvpos cs state' hn h =>
273273 rw [pushNext.sparse_neg hn h]
274274 apply inv.preserves' [] (by simp)
275- have {ne : bvpos.current ≠ s.endValidPos } : bvpos.current.get ne ∉ cs := by
275+ have {ne : bvpos.current ≠ s.endPos } : bvpos.current.get ne ∉ cs := by
276276 match h with
277277 | .inl eq => simp [eq] at ne
278278 | .inr ⟨ne', hc⟩ => simpa [BVPos.get] using hc
@@ -311,14 +311,14 @@ theorem step_closure {bvpos₀ bvpos : BVPos startPos} {result} (hres : captureN
311311 exact ih hres (cinv.preserves wf hn) stinv.preserves
312312
313313def StepClosure (bvpos₀ : BVPos startPos) (visited : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )) : Prop :=
314- ∀ (state : Fin nfa.nodes.size) (bvpos : BVPos startPos) (state' : Fin nfa.nodes.size) (bvpos' : BVPos startPos) (update : Option (Nat × ValidPos s)),
314+ ∀ (state : Fin nfa.nodes.size) (bvpos : BVPos startPos) (state' : Fin nfa.nodes.size) (bvpos' : BVPos startPos) (update : Option (Nat × Pos s)),
315315 bvpos₀ ≤ bvpos →
316316 visited.get state bvpos.index →
317317 nfa.Step 0 state bvpos.current state' bvpos'.current update →
318318 visited.get state' bvpos'.index
319319
320320def PathClosure (bvpos₀ : BVPos startPos) (visited : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )) : Prop :=
321- ∀ (state : Fin nfa.nodes.size) (bvpos : BVPos startPos) (state' : Fin nfa.nodes.size) (bvpos' : BVPos startPos) (update : List (Nat × ValidPos s)),
321+ ∀ (state : Fin nfa.nodes.size) (bvpos : BVPos startPos) (state' : Fin nfa.nodes.size) (bvpos' : BVPos startPos) (update : List (Nat × Pos s)),
322322 bvpos₀ ≤ bvpos →
323323 visited.get state bvpos.index →
324324 nfa.Path 0 state bvpos.current state' bvpos'.current update →
@@ -331,12 +331,12 @@ theorem zero : PathClosure bvpos₀ (BitMatrix.zero nfa.nodes.size (startPos.rem
331331 simp at hmem
332332
333333theorem of_step_closure {bvpos₀ : BVPos startPos} (wf : nfa.WellFormed) (h : StepClosure bvpos₀ visited) : PathClosure bvpos₀ visited := by
334- let motive (i : Nat) (pos : ValidPos s) : Prop :=
334+ let motive (i : Nat) (pos : Pos s) : Prop :=
335335 ∃ (isLt : i < nfa.nodes.size) (bvpos : BVPos startPos), bvpos₀ ≤ bvpos ∧ pos = bvpos.current ∧ visited.get ⟨i, isLt⟩ bvpos.index
336336 have cls i pos j pos' update (base : motive i pos) (step : nfa.Step 0 i pos j pos' update) : motive j pos' := by
337337 have ⟨_, bvpos, le, hbvpos, hmem⟩ := base
338338
339- let bvpos' : BVPos startPos := ⟨pos', ValidPos .le_trans (hbvpos ▸ bvpos.le) step.le⟩
339+ let bvpos' : BVPos startPos := ⟨pos', Pos .le_trans (hbvpos ▸ bvpos.le) step.le⟩
340340
341341 have le₀' : bvpos₀ ≤ bvpos' := BVPos.le_trans le (BVPos.le_iff.mpr (hbvpos ▸ step.le))
342342 have visited' := h ⟨i, step.lt⟩ bvpos ⟨j, step.lt_right wf⟩ bvpos' update le hmem (by simp [←hbvpos, bvpos', step])
369369
370370section
371371
372- variable {s : String} {nfa : NFA} {wf : nfa.WellFormed} {startPos : ValidPos s} {bvpos₀ bvpos : BVPos startPos}
372+ variable {s : String} {nfa : NFA} {wf : nfa.WellFormed} {startPos : Pos s} {bvpos₀ bvpos : BVPos startPos}
373373 {visited visited' : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )} {stack : List (StackEntry (HistoryStrategy s) nfa startPos)}
374374
375375def VisitedInv (wf : nfa.WellFormed) (bvpos₀ bvpos : BVPos startPos) (visited visited' : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )) : Prop :=
@@ -386,7 +386,7 @@ theorem rfl (wf : nfa.WellFormed) (bvpos₀ bvpos : BVPos startPos) : VisitedInv
386386
387387theorem preserves {bvpos' : BVPos startPos} {state : Fin nfa.nodes.size}
388388 (inv : VisitedInv wf bvpos₀ bvpos visited visited')
389- (update : List (Nat × ValidPos s)) (path : Path nfa wf bvpos.current bvpos'.current state update) :
389+ (update : List (Nat × Pos s)) (path : Path nfa wf bvpos.current bvpos'.current state update) :
390390 VisitedInv wf bvpos₀ bvpos visited (visited'.set state bvpos'.index) := by
391391 intro state' bvpos'' le' hmem
392392 simp [visited'.get_set] at hmem
423423
424424section
425425
426- variable {s : String} {nfa : NFA} {wf : nfa.WellFormed} {startPos : ValidPos s} {bvpos₀ bvpos : BVPos startPos} {visited : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )} {stack : List (StackEntry (HistoryStrategy s) nfa startPos)}
426+ variable {s : String} {nfa : NFA} {wf : nfa.WellFormed} {startPos : Pos s} {bvpos₀ bvpos : BVPos startPos} {visited : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )} {stack : List (StackEntry (HistoryStrategy s) nfa startPos)}
427427
428428def NotDoneInv (visited : BitMatrix nfa.nodes.size (startPos.remainingBytes + 1 )) : Prop :=
429429 ∀ (state : Fin nfa.nodes.size) (bvpos : BVPos startPos),
0 commit comments