Skip to content

Commit cb6a504

Browse files
introduce any predicate in Language and proof that or (star any) is universal
1 parent fdb1ba1 commit cb6a504

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

Katydid/Regex/Language.lean

+23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def char {α: Type} (x : α): Lang α :=
2323
def pred {α: Type} (p : α -> Prop): Lang α :=
2424
fun xs => ∃ x, xs = [x] /\ p x
2525

26+
def any {α: Type}: Lang α :=
27+
fun xs => ∃ x, xs = [x]
28+
2629
-- onlyif is used as an and to make derive char not require an if statement
2730
-- (derive (char c) a) w <-> (onlyif (a = c) emptystr)
2831
def onlyif {α: Type} (cond : Prop) (R : Lang α) : Lang α :=
@@ -924,3 +927,23 @@ theorem simp_star_emptyset_is_emptystr {α: Type}:
924927
intro h
925928
rw [h]
926929
exact star.zero
930+
931+
theorem simp_star_any_is_universal {α: Type}:
932+
star (@any α) = @universal α := by
933+
funext xs
934+
simp only [universal, eq_iff_iff]
935+
apply Iff.intro
936+
case mp =>
937+
intro h
938+
exact True.intro
939+
case mpr =>
940+
intro h
941+
induction xs with
942+
| nil =>
943+
exact star.zero
944+
| cons x xs ih =>
945+
apply star.more x [] xs
946+
· simp only [singleton_append]
947+
· unfold any
948+
exists x
949+
· exact ih

Katydid/Regex/SmartRegex.lean

+30
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,36 @@ theorem orToList_is_orFromList (x: Regex α):
346346
rw [orFromList_cons_NonEmptyList_is_or]
347347
rw [ih2]
348348

349+
theorem simp_pred_any_is_any:
350+
denote (Regex.pred (@Predicate.mkAny α o)) = Language.any := by
351+
unfold denote
352+
unfold Predicate.mkAny
353+
unfold Predicate.func
354+
simp only
355+
unfold mkAnyPredFunc
356+
unfold Language.pred
357+
unfold Language.any
358+
funext xs
359+
simp only [and_true]
360+
361+
theorem simp_star_pred_any_is_universal [o: Ord α]:
362+
denote (Regex.star (Regex.pred (@Predicate.mkAny α o))) = Language.universal := by
363+
unfold denote
364+
rw [simp_pred_any_is_any]
365+
exact Language.simp_star_any_is_universal
366+
367+
theorem simp_or_universal_r_is_universal [Ord α] (x: Regex α):
368+
denote (Regex.or x (Regex.star (Regex.pred Predicate.mkAny))) = Language.universal := by
369+
nth_rewrite 1 [denote]
370+
rw [simp_star_pred_any_is_universal]
371+
rw [Language.simp_or_universal_r_is_universal]
372+
373+
theorem simp_or_universal_l_is_universal [Ord α] (x: Regex α):
374+
denote (Regex.or (Regex.star (Regex.pred Predicate.mkAny)) x) = Language.universal := by
375+
nth_rewrite 1 [denote]
376+
rw [simp_star_pred_any_is_universal]
377+
rw [Language.simp_or_universal_l_is_universal]
378+
349379
-- 1. If x or y is emptyset then return the other (Language.simp_or_emptyset_r_is_l and Language.simp_or_emptyset_l_is_r)
350380
-- 2. If x or y is star (any) then return star (any) (Language.simp_or_universal_r_is_universal and Language.simp_or_universal_l_is_universal)
351381
-- 3. Get the lists of ors using orToList (Language.simp_or_assoc)

0 commit comments

Comments
 (0)