@@ -6,6 +6,7 @@ import Validator.Regex.Num
66import Validator.Regex.Pair
77import Validator.Regex.Regex
88import Validator.Regex.RegexID
9+ import Validator.Regex.Replace
910
1011-- I want to define a map function over a regular expression:
1112
@@ -36,25 +37,6 @@ import Validator.Regex.RegexID
3637
3738namespace Symbol
3839
39- def replace (r: RegexID n) (xs: Vec σ l) (h: n <= l): Regex σ :=
40- match r with
41- | Regex.emptyset => Regex.emptyset
42- | Regex.emptystr => Regex.emptystr
43- | Regex.symbol s => Regex.symbol (Vec.get xs (Fin.mk s.val (by
44- cases s
45- simp only
46- omega
47- )))
48- | Regex.or r1 r2 =>
49- Regex.or (replace r1 xs h) (replace r2 xs h)
50- | Regex.concat r1 r2 =>
51- Regex.concat (replace r1 xs h) (replace r2 xs h)
52- | Regex.star r1 =>
53- Regex.star (replace r1 xs h)
54-
55- def replaceFrom (r: RegexID n) (xs: Vec σ n): Regex σ :=
56- replace r xs (le_refl n)
57-
5840def derive {σ: Type } {α: Type } (Φ: σ -> α -> Bool) (r: Regex σ) (a: α): Regex σ :=
5941 Regex.Pair.derive
6042 (replaceFrom
@@ -72,9 +54,6 @@ def derive' {σ: Type} {α: Type} (Φ: σ -> α -> Bool) (r: Regex σ) (a: α):
7254 let replaced: Regex (σ × Bool) := replaceFrom r' replaces
7355 Regex.Pair.derive replaced
7456
75- def replacesFrom (rs: Vec (RegexID n) l) (xs: Vec σ n): Vec (Regex σ) l :=
76- Vec.map rs (fun r => replaceFrom r xs)
77-
7857def derives {σ: Type } {α: Type } (Φ: σ -> α -> Bool) (rs: Vec (Regex σ) l) (a: α): Vec (Regex σ) l :=
7958 let (rs', symbols): (Vec (RegexID (Symbol.nums rs)) l × Vec σ (Symbol.nums rs)) := Symbol.extractsFrom rs
8059 let pred_results: Vec Bool (Symbol.nums rs) := Vec.map symbols (fun s => Φ s a)
@@ -137,106 +116,6 @@ def derive_closure' {σ: Type}
137116 )
138117 )
139118
140- theorem replace_cast_both (r: RegexID n) (xs: Vec σ n) (h: n = l):
141- replace r xs (by omega) = replace (RegexID.cast r h) (Vec.cast xs h) (by omega) := by
142- subst h
143- simp only [Vec.cast_rfl]
144- rfl
145-
146- theorem replaceFrom_cast_both (r: RegexID n) (xs: Vec σ n) (h: n = l):
147- replaceFrom r xs = replaceFrom (RegexID.cast r h) (Vec.cast xs h) := by
148- unfold replaceFrom
149- rw [replace_cast_both]
150-
151- theorem replace_cast_symbols (r: RegexID n) (xs: Vec σ n) (h: n = l):
152- replace r xs (by omega) = replace r (Vec.cast xs h) (by omega) := by
153- subst h
154- simp only [Vec.cast_rfl]
155-
156- theorem replace_nil_is_map_id (r: Regex (Fin 0 )):
157- replace r Vec.nil (by simp) = Regex.map r id := by
158- induction r with
159- | emptyset =>
160- simp only [replace, Regex.map]
161- | emptystr =>
162- simp only [replace, Regex.map]
163- | symbol s =>
164- nomatch s
165- | or r1 r2 ih1 ih2 =>
166- simp only [replace, Regex.map, Regex.or.injEq]
167- rw [ih1]
168- rw [ih2]
169- apply And.intro rfl rfl
170- | concat r1 r2 ih1 ih2 =>
171- simp only [replace, Regex.map, Regex.concat.injEq]
172- rw [ih1]
173- rw [ih2]
174- apply And.intro rfl rfl
175- | star r1 ih1 =>
176- simp only [replace, Regex.map]
177- rw [ih1]
178-
179- theorem replace_take (r: RegexID n) (xs: Vec σ (n + l)):
180- replace r (Vec.take n xs) (by omega) = replace r xs (by omega):= by
181- induction r with
182- | emptyset =>
183- simp only [replace]
184- | emptystr =>
185- simp only [replace]
186- | symbol s =>
187- generalize_proofs h1 h2 at *
188- simp only [replace]
189- obtain ⟨s, hs⟩ := s
190- simp only [Regex.symbol.injEq]
191- generalize_proofs h3 h4
192- rw [Vec.take_get]
193- omega
194- | or r1 r2 ih1 ih2 =>
195- simp only [replace, Regex.or.injEq]
196- generalize_proofs h1 h2 at *
197- rw [<- ih1]
198- rw [<- ih2]
199- apply And.intro rfl rfl
200- | concat r1 r2 ih1 ih2 =>
201- simp only [replace, Regex.concat.injEq]
202- generalize_proofs h1 h2 at *
203- rw [<- ih1]
204- rw [<- ih2]
205- apply And.intro rfl rfl
206- | star r1 ih1 =>
207- simp only [replace]
208- generalize_proofs h1 at *
209- rw [<- ih1]
210-
211- theorem replace_regexid_add (r: RegexID n) (xs: Vec σ (n + l)):
212- replace r xs (by omega) = replace (RegexID.add l r) xs (by omega):= by
213- generalize_proofs h1 h2
214- induction r with
215- | emptyset =>
216- simp only [replace, RegexID.add, Regex.map]
217- | emptystr =>
218- simp only [replace, RegexID.add, Regex.map]
219- | symbol s =>
220- generalize_proofs h1 h2 at *
221- simp only [replace, RegexID.add, Regex.map, Fin.coe_castLE]
222- | or r1 r2 ih1 ih2 =>
223- simp only [replace, RegexID.add, Regex.map, Regex.or.injEq]
224- generalize_proofs h1 h2 at *
225- rw [ih1]
226- rw [ih2]
227- apply And.intro rfl rfl
228- | concat r1 r2 ih1 ih2 =>
229- simp only [replace, RegexID.add, Regex.map, Regex.concat.injEq]
230- generalize_proofs h1 h2 at *
231- rw [ih1]
232- rw [ih2]
233- apply And.intro rfl rfl
234- | star r1 ih1 =>
235- simp only [replace, RegexID.add, Regex.map, Regex.star.injEq]
236- generalize_proofs h1 h2 at *
237- rw [ih1]
238- rfl
239-
240119theorem extract_replaceFrom_is_id (r: Regex σ) (acc: Vec σ l):
241120 r = replaceFrom (extract r acc).1 (extract r acc).2 := by
242121 simp only [replaceFrom]
@@ -455,20 +334,6 @@ theorem Symbol_derive_is_Regex_derive
455334 rw [<- extractFrom_replaceFrom_is_fmap]
456335 rw [Regex.Pair.derive_is_pair_derive]
457336
458- theorem replacesFrom_cast_both (rs: Vec (RegexID n) l) (ss: Vec σ n) (h: n = m):
459- replacesFrom rs ss =
460- replacesFrom (RegexID.casts rs h) (Vec.cast ss h) := by
461- subst h
462- simp only [Vec.cast_rfl]
463- simp only [RegexID.casts_rfl]
464-
465- theorem replacesFrom_cons (rs: Vec (RegexID n) l) (xs: Vec σ n):
466- replacesFrom (Vec.cons r rs) xs
467- = Vec.cons (replaceFrom r xs) (replacesFrom rs xs)
468- := by
469- simp only [replacesFrom]
470- simp only [Vec.map]
471-
472337theorem replaceFrom_append {r: Regex α} {xs: Vec α (n + Symbol.num r)} {acc: Vec α n} {ys: Vec α m}:
473338 replaceFrom (RegexID.add m (extract r acc).1 ) (Vec.append xs ys)
474339 = replaceFrom (extract r acc).1 xs := by
0 commit comments