Skip to content

Commit a874b47

Browse files
committed
fix: correctness subproject after update to lean v4.31.0
1 parent 0d5d2e7 commit a874b47

8 files changed

Lines changed: 97 additions & 52 deletions

File tree

correctness/RegexCorrectness/Data/String.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ theorem String.empty_or_eq_singleton_append (s : String) :
3737
obtain ⟨cs, rfl⟩ := String.exists_eq_ofList s
3838
match cs with
3939
| [] => exact .inl rfl
40-
| c :: cs => exact .inr ⟨c, String.ofList cs, by simp [String.singleton_eq_ofList, ←String.ofList_append]⟩
40+
| c :: cs => exact .inr ⟨c, String.ofList cs, by simp only [String.singleton_eq_ofList, ←String.ofList_append, List.singleton_append]⟩
4141

4242
namespace Regex.Data.String
4343

correctness/RegexCorrectness/Syntax/Ast.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ theorem repeatConcat_go_tags_subset (e : Expr) (accum : Expr) (n : Nat) :
4747
simpa [Expr.tags] using ih (accum.concat e)
4848

4949
theorem repeatConcat_tags (e : Expr) (n : Nat) : (repeatConcat e n).tags = e.tags := by
50+
unfold repeatConcat
5051
refine Finset.Subset.antisymm ?_ ?_
5152
. simpa using repeatConcat_go_tags_subset e e (n - 1)
5253
. exact subset_repeatConcat_go_tags e e (n - 1) (by simp)

correctness/RegexCorrectness/Unicode/CaseFold/Equivalence.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public def CaseFoldEquiv (c₁ c₂ : Char) : Prop :=
4141
def CaseFoldEquiv' (c₁ c₂ : Char) : Prop :=
4242
getCaseFoldEquivChars c₁ = getCaseFoldEquivChars c₂
4343

44-
instance instCaseFoldEquivEquivalence' : Equivalence CaseFoldEquiv' where
44+
theorem instCaseFoldEquivEquivalence' : Equivalence CaseFoldEquiv' where
4545
refl := by grind [CaseFoldEquiv']
4646
symm := by grind [CaseFoldEquiv']
4747
trans := by grind [CaseFoldEquiv']
@@ -98,7 +98,7 @@ theorem caseFoldEquiv'_iff_caseFoldEquiv {c₁ c₂ : Char} : CaseFoldEquiv' c
9898
theorem caseFoldEquiv'_eq_caseFoldEquiv : CaseFoldEquiv' = CaseFoldEquiv := by
9999
grind [caseFoldEquiv'_iff_caseFoldEquiv]
100100

101-
public instance instCaseFoldEquivEquivalence : Equivalence CaseFoldEquiv :=
101+
public theorem instCaseFoldEquivEquivalence : Equivalence CaseFoldEquiv :=
102102
caseFoldEquiv'_eq_caseFoldEquiv ▸ instCaseFoldEquivEquivalence'
103103

104104
end Regex.Unicode

correctness/RegexCorrectness/VM/CharStep/Lemmas.lean

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,26 @@ theorem lower_bound (h : stepChar (HistoryStrategy s) nfa wf pos ne currentUpdat
2828
(lb : εClosure.LowerBound (pos.next ne) next.states) :
2929
εClosure.LowerBound (pos.next ne) next'.states := by
3030
simp only [HistoryStrategy.update_def, stepChar, Fin.getElem_fin] at h
31-
grind [εClosure.lower_bound]
31+
split at h
32+
· expose_names; exact εClosure.lower_bound h lb
33+
· grind only
3234

3335
theorem eq_updates_of_mem_next {i k} (h : stepChar (HistoryStrategy s) nfa wf pos ne currentUpdates next i = (matched', next'))
3436
(mem : k ∈ next.states) :
3537
next'.updates[k] = next.updates[k] := by
3638
simp only [HistoryStrategy.update_def, stepChar, Fin.getElem_fin] at h
37-
grind [εClosure.eq_updates_of_mem_next]
39+
split at h
40+
· · expose_names; exact εClosure.eq_updates_of_mem_next h mem
41+
· grind only
42+
3843

3944
theorem done_of_matched_some (h : stepChar (HistoryStrategy s) nfa wf pos ne currentUpdates next state = (matched', next'))
4045
(isSome' : matched'.isSome) :
4146
∃ state' ∈ next'.states, nfa[state'] = .done ∧ next'.updates[state'] = matched'.get isSome' := by
4247
simp only [HistoryStrategy.update_def, stepChar, Fin.getElem_fin] at h
43-
grind [εClosure.matched_inv]
48+
split at h
49+
· exact εClosure.matched_inv h (fun isSome => Bool.noConfusion isSome) isSome'
50+
· grind only [= Option.isSome_none]
4451

4552
theorem mem_next_of_stepChar {i j k update}
4653
(h : stepChar (HistoryStrategy s) nfa wf pos ne currentUpdates next i = (matched', next'))
@@ -53,14 +60,18 @@ theorem mem_next_of_stepChar {i j k update}
5360
have eqj : j = state' := by
5461
split at hn
5562
next hn' =>
56-
simp at hn
57-
simp [NFA.CharStep.char hn'] at step
58-
simp [Fin.ext_iff, step, ←hn.2]
63+
split at hn
64+
· injection hn with hn
65+
simp [NFA.CharStep.char hn'] at step
66+
simp [Fin.ext_iff, step, ←hn]
67+
· contradiction
5968
next hn' =>
60-
simp at hn
61-
simp [NFA.CharStep.sparse hn'] at step
62-
simp [Fin.ext_iff, step, ←hn.2]
63-
next => simp at hn
69+
split at hn
70+
· injection hn with hn
71+
simp [NFA.CharStep.sparse hn'] at step
72+
simp [Fin.ext_iff, step, ←hn]
73+
· contradiction
74+
next => contradiction
6475
exact εClosure.mem_next h lb (eqj ▸ cls)
6576
next hn =>
6677
split at hn
@@ -88,8 +99,15 @@ theorem write_updates_of_mem_next {i k}
8899
next state' hn =>
89100
match εClosure.write_updates_of_mem_next h mem with
90101
| .inl mem => exact .inl mem
91-
| .inr ⟨update', cls, write⟩ => exact .inr ⟨state', update', (by grind), cls, write⟩
92-
next => grind
102+
| .inr ⟨update', cls, write⟩ =>
103+
have step : nfa.CharStep pos i state' := by
104+
grind only [usr Fin.isLt, = CharStep.fail, = Fin.getElem_fin, => CharStep.char,
105+
=> CharStep.sparse, #6698, #51e9, #8818, #5c18, #c184]
106+
exact .inr ⟨state', update', step, cls, write⟩
107+
next hn =>
108+
injection h with _ hnext
109+
subst hnext
110+
exact .inl mem
93111

94112
theorem inv {pos₀ idx} (hlt : idx < current.states.count)
95113
(h : stepChar (HistoryStrategy s) nfa wf pos ne current.updates next current.states[idx] = (matched', next'))
@@ -126,8 +144,10 @@ theorem go.lower_bound {idx hle} (h : eachStepChar.go (HistoryStrategy s) nfa wf
126144
(lb : εClosure.LowerBound (pos.next ne) next.states) :
127145
εClosure.LowerBound (pos.next ne) next'.states := by
128146
induction idx, hle, next using eachStepChar.go.induct' (HistoryStrategy s) nfa wf pos ne current with
129-
| base next => simp_all [HistoryStrategy.update_def]
130-
| done i hlt next hn => simp_all [HistoryStrategy.update_def]
147+
| base next =>
148+
simp_all [eachStepChar.go_base, HistoryStrategy.update_def]
149+
| done i hlt next hn =>
150+
simp_all [eachStepChar.go_done, HistoryStrategy.update_def]
131151
| found i hlt next hn matched next'' h' found =>
132152
rw [eachStepChar.go_found hlt hn h' found] at h
133153
simp_all
@@ -140,8 +160,12 @@ theorem go.done_of_matched_some {idx hle} (h : eachStepChar.go (HistoryStrategy
140160
(isSome' : matched'.isSome) :
141161
∃ state' ∈ next'.states, nfa[state'] = .done ∧ next'.updates[state'] = matched'.get isSome' := by
142162
induction idx, hle, next using eachStepChar.go.induct' (HistoryStrategy s) nfa wf pos ne current with
143-
| base next => grind
144-
| done i hlt next hn => grind
163+
| base next =>
164+
simp [eachStepChar.go_base] at h
165+
injection h with h1 _; subst h1; contradiction
166+
| done i hlt next hn =>
167+
simp [eachStepChar.go_done hlt hn] at h
168+
injection h with h1 _; subst h1; contradiction
145169
| found i hlt next hn matched next'' h' found =>
146170
rw [eachStepChar.go_found hlt hn h' found] at h
147171
simp [HistoryStrategy.update_def] at h

correctness/RegexCorrectness/VM/Correspondence/Refinement/Refinement.lean

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ theorem εClosure.refines (resultB resultH)
7272
induction matchedH, nextH, stackH using εClosure.induct' (HistoryStrategy s) nfa wf pos generalizing matchedB nextB stackB resultB resultH with
7373
| base matchedH nextH =>
7474
simp [εStack.materialize] at refStack
75-
grind [εClosure.base, materializeResult]
75+
subst stackB
76+
simp [εClosure.base] at h'
77+
subst h'
78+
-- h : εClosure (BufferStrategy...) ... [] = resultB, hbase gives εClosure [] = (matched, next)
79+
have hbase : εClosure (BufferStrategy s bufferSize) nfa wf pos matchedB nextB [] = (matchedB, nextB) := εClosure.base
80+
have hresB : resultB = (matchedB, nextB) := h.symm.trans hbase
81+
subst hresB
82+
simp [materializeResult, refState, refMatched]
7683
| visited matched' next' update state' stack' mem ih =>
7784
simp only [εStack.materialize.cons] at refStack
7885
subst stackB
@@ -94,14 +101,19 @@ theorem εClosure.refines (resultB resultH)
94101
h
95102
rw [εClosure.not_visited (refState ▸ mem)] at h
96103
refine ih resultB resultH h h' ?_ ?_ ?_
97-
. split
98-
next eq => simp +instances [matched'', node, eq, ←refMatched]; grind only
99-
next eq =>
100-
simp at eq
101-
simp [matched'', node, eq, refMatched]
104+
. dsimp [matched'', node]
105+
split
106+
next =>
107+
clear ih h h'
108+
cases matched' <;> simp [←refMatched] <;> rfl
109+
next =>
110+
clear ih h h'
111+
simp [←refMatched]
102112
. simp [SearchState.materialize] at refState
103-
simp [SearchState.materialize, states'', ←refState]
104-
split <;> grind
113+
simp [SearchState.materialize, states'', ← refState, updates'', node]
114+
split
115+
· grind only [HistoryStrategy.update_def, Vector.map_set]
116+
· grind only
105117
. exact pushNext.refines wf rfl rfl
106118

107119
theorem stepChar.refines {currentUpdatesH currentUpdatesB state} (resultB resultH)
@@ -114,11 +126,17 @@ theorem stepChar.refines {currentUpdatesH currentUpdatesB state} (resultB result
114126
split at h'
115127
next state' hn =>
116128
simp [hn] at h
117-
exact εClosure.refines resultB resultH h h' rfl refState (by simp [εStack.materialize, ←refUpdates]; grind)
129+
have refStack : εStack.materialize [(currentUpdatesH[state], state')] = [(currentUpdatesB[state], state')] := by
130+
have h_eq : (currentUpdatesH.map (materializeUpdates bufferSize))[state] = currentUpdatesB[state] :=
131+
congrArg (fun v => v[state]) refUpdates
132+
simp at h_eq
133+
exact congrArg (fun x => [(x, state')]) h_eq
134+
exact εClosure.refines resultB resultH h h' rfl refState refStack
118135
next hn =>
119136
simp [hn] at h
120-
simp [←h', ←h, materializeResult]
121-
grind
137+
rw [←h', ←h]
138+
simp [materializeResult, refState]
139+
rfl
122140

123141
theorem eachStepChar.go.refines {currentH currentB i hleB hleH} (resultB resultH)
124142
(h : eachStepChar.go (BufferStrategy s bufferSize) nfa wf pos ne currentB i hleB nextB = resultB)
@@ -156,7 +174,7 @@ theorem eachStepChar.go.refines {currentH currentB i hleB hleH} (resultB resultH
156174
simp [materializeResult] at refResult
157175

158176
have isSomeB : matchedB.isSome := by
159-
simpa [←refResult.1] using isSomeH
177+
simpa [←refResult.1, HistoryStrategy.update_def] using isSomeH
160178

161179
simp [eachStepChar.go_found hltH hnH hstepH isSomeH] at h'
162180
simp [eachStepChar.go_found hltB hnB hstepB isSomeB] at h
@@ -176,7 +194,7 @@ theorem eachStepChar.go.refines {currentH currentB i hleB hleH} (resultB resultH
176194
simp [materializeResult] at refResult
177195

178196
have isSomeB : ¬matchedB.isSome := by
179-
simpa [←refResult.1] using isSomeH
197+
simpa [←refResult.1, HistoryStrategy.update_def] using isSomeH
180198

181199
simp [eachStepChar.go_not_found hltH hnH hstepH isSomeH] at h'
182200
simp [eachStepChar.go_not_found hltB hnB hstepB isSomeB] at h
@@ -206,7 +224,7 @@ theorem captureNext.go.refines {currentH currentB resultB resultH}
206224
have isEmptyB : currentB.states.isEmpty := by
207225
simpa [←refCurrent] using isEmptyH
208226
have isSomeB : matchedB.isSome := by
209-
simpa [←refMatched] using isSomeH
227+
simpa [←refMatched, HistoryStrategy.update_def] using isSomeH
210228
rw [captureNext.go_found atEnd isEmptyH isSomeH] at h'
211229
rw [captureNext.go_found atEnd isEmptyB isSomeB] at h
212230
simp [←h', ←h, refMatched]
@@ -218,9 +236,9 @@ theorem captureNext.go.refines {currentH currentB resultB resultH}
218236
have refStepped := eachStepChar.refines steppedB steppedH rfl rfl refCurrent refNext
219237
have refExpanded := εClosure.refines expandedB expandedH rfl rfl rfl (by simp [←refStepped, materializeResult]) rfl
220238
have isNoneB₁ : matchedB = .none := by
221-
simpa [←refMatched] using isNoneH₁
239+
simpa [←refMatched, HistoryStrategy.update_def] using isNoneH₁
222240
have isNoneB₂ : steppedB.1 = .none := by
223-
simpa [←refStepped, materializeResult] using isNoneH₂
241+
simpa [←refStepped, materializeResult, HistoryStrategy.update_def] using isNoneH₂
224242

225243
rw [captureNext.go_ind_not_found steppedH expandedH rfl rfl isNoneH₁ isNoneH₂] at h'
226244
rw [captureNext.go_ind_not_found steppedB expandedB rfl rfl isNoneB₁ isNoneB₂] at h
@@ -238,7 +256,7 @@ theorem captureNext.go.refines {currentH currentB resultB resultH}
238256
simp [←refMatched] at h
239257
exact refCurrent ▸ hempH h
240258
have isSomeB : matchedB.isSome ∨ steppedB.1.isSome := by
241-
simpa [←refMatched, ←refStepped, materializeResult] using isSomeH
259+
simpa [←refMatched, ←refStepped, materializeResult, HistoryStrategy.update_def] using isSomeH
242260

243261
rw [captureNext.go_ind_found steppedH rfl hempH isSomeH] at h'
244262
rw [captureNext.go_ind_found steppedB rfl hempB isSomeB] at h

correctness/RegexCorrectness/VM/EpsilonClosure/Lemmas.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ theorem preserves' {stack'} {node} (hn : nfa[entry.2] = node) (nextEntries) (hst
376376
simp [eq]
377377
have ⟨update', equpdate, cls⟩ := inv.mem_stack entry.1 entry.2 (by simp)
378378
refine .inr ⟨update', cls, fun write => ?_⟩
379-
simpa [←hn, write] using equpdate
379+
simp [←hn, write]
380+
exact equpdate
380381
| inr mem =>
381382
match inv.mem_next j mem with
382383
| .inl mem => exact .inl mem

correctness/RegexCorrectness/VM/Path/VMPath.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ theorem Step.εStep_or_charStep {i j : Nat} (wf : nfa.WellFormed) (step : nfa.St
2020
grind
2121

2222
inductive VMPath (nfa : NFA) (wf : nfa.WellFormed) (pos₀ : Pos s) : Pos s → Fin nfa.size → List (Nat × Pos s) → Prop where
23-
| init {pos i update} (le : pos₀ ≤ pos) (cls : nfa.εClosure' pos ⟨nfa.start, wf.start_lt⟩ i update) :
23+
| init {pos : Pos s} {i : Fin nfa.size} {update : List (Nat × Pos s)} (le : pos₀ ≤ pos) (cls : nfa.εClosure' pos ⟨nfa.start, wf.start_lt⟩ i update) :
2424
VMPath nfa wf pos₀ pos i update
25-
| more {i j k pos pos' update₁ update₂ update₃} (prev : VMPath nfa wf pos₀ pos i update₁) (step : nfa.CharStep pos i j) (cls : nfa.εClosure' (pos.next step.ne) j k update₂)
25+
| more {i j k : Fin nfa.size} {pos pos' : Pos s} {update₁ update₂ update₃ : List (Nat × Pos s)} (prev : VMPath nfa wf pos₀ pos i update₁) (step : nfa.CharStep pos i j) (cls : nfa.εClosure' (pos.next step.ne) j k update₂)
2626
(hupdate : update₃ = update₁ ++ update₂) (hpos : pos' = pos.next step.ne) :
2727
VMPath nfa wf pos₀ pos' k update₃
2828

correctness/lake-manifest.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{"version": "1.1.0",
1+
{"version": "1.2.0",
22
"packagesDir": ".lake/packages",
33
"packages":
44
[{"type": "path",
@@ -12,17 +12,17 @@
1212
"type": "git",
1313
"subDir": null,
1414
"scope": "leanprover-community",
15-
"rev": "8a178386ffc0f5fef0b77738bb5449d50efeea95",
15+
"rev": "fabf563a7c95a166b8d7b6efca11c8b4dc9d911f",
1616
"name": "mathlib",
1717
"manifestFile": "lake-manifest.json",
18-
"inputRev": "v4.29.0",
18+
"inputRev": "v4.31.0",
1919
"inherited": false,
2020
"configFile": "lakefile.lean"},
2121
{"url": "https://github.com/leanprover-community/plausible",
2222
"type": "git",
2323
"subDir": null,
2424
"scope": "leanprover-community",
25-
"rev": "83e90935a17ca19ebe4b7893c7f7066e266f50d3",
25+
"rev": "63045536fe95024e6c18fc7b48e03f506701c5bc",
2626
"name": "plausible",
2727
"manifestFile": "lake-manifest.json",
2828
"inputRev": "main",
@@ -42,7 +42,7 @@
4242
"type": "git",
4343
"subDir": null,
4444
"scope": "leanprover-community",
45-
"rev": "48d5698bc464786347c1b0d859b18f938420f060",
45+
"rev": "5c7542ed018c78194f1e2b903eaf6a792b74c03d",
4646
"name": "importGraph",
4747
"manifestFile": "lake-manifest.json",
4848
"inputRev": "main",
@@ -52,17 +52,17 @@
5252
"type": "git",
5353
"subDir": null,
5454
"scope": "leanprover-community",
55-
"rev": "3c52dee17f0cd89c1ec14de78920d1bdaa3d26b3",
55+
"rev": "24b0d9dc081c5423f8eec7e866c441e5184f29d9",
5656
"name": "proofwidgets",
5757
"manifestFile": "lake-manifest.json",
58-
"inputRev": "v0.0.95",
58+
"inputRev": "main",
5959
"inherited": true,
6060
"configFile": "lakefile.lean"},
6161
{"url": "https://github.com/leanprover-community/aesop",
6262
"type": "git",
6363
"subDir": null,
6464
"scope": "leanprover-community",
65-
"rev": "7152850e7b216a0d409701617721b6e469d34bf6",
65+
"rev": "e3cb2f741431ce31bf73549fb52316a57368b06f",
6666
"name": "aesop",
6767
"manifestFile": "lake-manifest.json",
6868
"inputRev": "master",
@@ -72,7 +72,7 @@
7272
"type": "git",
7373
"subDir": null,
7474
"scope": "leanprover-community",
75-
"rev": "707efb56d0696634e9e965523a1bbe9ac6ce141d",
75+
"rev": "f46324995fca5f0483b742e4eb4daec7f4ee50d2",
7676
"name": "Qq",
7777
"manifestFile": "lake-manifest.json",
7878
"inputRev": "master",
@@ -82,7 +82,7 @@
8282
"type": "git",
8383
"subDir": null,
8484
"scope": "leanprover-community",
85-
"rev": "756e3321fd3b02a85ffda19fef789916223e578c",
85+
"rev": "fa08db58b30eb033edcdab331bba000827f9f785",
8686
"name": "batteries",
8787
"manifestFile": "lake-manifest.json",
8888
"inputRev": "main",
@@ -92,11 +92,12 @@
9292
"type": "git",
9393
"subDir": null,
9494
"scope": "leanprover",
95-
"rev": "7802da01beb530bf051ab657443f9cd9bc3e1a29",
95+
"rev": "92564e5770e4d09f2d86dfbf8ada1e9c715b384c",
9696
"name": "Cli",
9797
"manifestFile": "lake-manifest.json",
98-
"inputRev": "v4.29.0",
98+
"inputRev": "v4.31.0",
9999
"inherited": true,
100100
"configFile": "lakefile.toml"}],
101101
"name": "RegexCorrectness",
102-
"lakeDir": ".lake"}
102+
"lakeDir": ".lake",
103+
"fixedToolchain": false}

0 commit comments

Comments
 (0)