@@ -19,9 +19,11 @@ computer science such as the POSIX standard.
19
19
* `attribute [pattern] has_mul.mul` has been added into this file, it could be moved.
20
20
-/
21
21
22
+ open list set
23
+
22
24
universe u
23
25
24
- variables {α : Type u } [dec : decidable_eq α]
26
+ variables {α β γ : Type * } [dec : decidable_eq α]
25
27
26
28
/--
27
29
This is the definition of regular expressions. The names used here is to mirror the definition
@@ -60,7 +62,7 @@ attribute [pattern] has_mul.mul
60
62
@[simp] lemma comp_def (P Q : regular_expression α) : comp P Q = P * Q := rfl
61
63
62
64
/-- `matches P` provides a language which contains all strings that `P` matches -/
63
- def matches : regular_expression α → language α
65
+ @[simp] def matches : regular_expression α → language α
64
66
| 0 := 0
65
67
| 1 := 1
66
68
| (char a) := {[a]}
@@ -313,4 +315,47 @@ begin
313
315
exact eq.decidable _ _
314
316
end
315
317
318
+ omit dec
319
+
320
+ /-- Map the alphabet of a regular expression. -/
321
+ @[simp] def map (f : α → β) : regular_expression α → regular_expression β
322
+ | 0 := 0
323
+ | 1 := 1
324
+ | (char a) := char (f a)
325
+ | (R + S) := map R + map S
326
+ | (R * S) := map R * map S
327
+ | (star R) := star (map R)
328
+
329
+ @[simp] lemma map_id : ∀ (P : regular_expression α), P.map id = P
330
+ | 0 := rfl
331
+ | 1 := rfl
332
+ | (char a) := rfl
333
+ | (R + S) := by simp_rw [map, map_id]
334
+ | (R * S) := by simp_rw [map, map_id]
335
+ | (star R) := by simp_rw [map, map_id]
336
+
337
+ @[simp] lemma map_map (g : β → γ) (f : α → β) :
338
+ ∀ (P : regular_expression α), (P.map f).map g = P.map (g ∘ f)
339
+ | 0 := rfl
340
+ | 1 := rfl
341
+ | (char a) := rfl
342
+ | (R + S) := by simp_rw [map, map_map]
343
+ | (R * S) := by simp_rw [map, map_map]
344
+ | (star R) := by simp_rw [map, map_map]
345
+
346
+ /-- The language of the map is the map of the language. -/
347
+ @[simp] lemma matches_map (f : α → β) :
348
+ ∀ P : regular_expression α, (P.map f).matches = language.map f P.matches
349
+ | 0 := (map_zero _).symm
350
+ | 1 := (map_one _).symm
351
+ | (char a) := by { rw eq_comm, exact image_singleton }
352
+ | (R + S) := by simp only [matches_map, map, matches_add, map_add]
353
+ | (R * S) := by simp only [matches_map, map, matches_mul, map_mul]
354
+ | (star R) := begin
355
+ simp_rw [map, matches, matches_map],
356
+ rw [language.star_eq_supr_pow, language.star_eq_supr_pow],
357
+ simp_rw ←map_pow,
358
+ exact image_Union.symm,
359
+ end
360
+
316
361
end regular_expression
0 commit comments