Skip to content

Commit f11951f

Browse files
committed
Add Ochmanski Theorem 4.1 (ii) => (iii)
1 parent 2c7a3cd commit f11951f

1 file changed

Lines changed: 102 additions & 169 deletions

File tree

TraceTheory/TraceTheory/Language.lean

Lines changed: 102 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ def isStarConnected (I : Independence α) : RegularExpression α → Prop
464464
| P * Q => isStarConnected I P ∧ isStarConnected I Q
465465
| RegularExpression.star P => isStarConnected I P ∧ (∀ s ∈ P.matches', @isConnected' α I s)
466466

467+
-- Interpretation of this RegularExpression as operating on trace languages.
467468
def matches_trace (I : Independence α) : RegularExpression α → Set (Trace I)
468469
| 0 => {}
469470
| 1 => {⟦[]⟧}
@@ -472,6 +473,9 @@ def matches_trace (I : Independence α) : RegularExpression α → Set (Trace I)
472473
| P * Q => {t | ∃ p : (matches_trace I P), ∃ q : (matches_trace I Q), t = p * q}
473474
| RegularExpression.star P => {r | ∃ ts : List (Trace I), (∀ t' ∈ ts, t' ∈ matches_trace I P) ∧ r = ts.foldl (fun (u : Trace I) v => u * v) ⟦[]⟧}
474475

476+
/-- Interpreting this RegularExpression as operating on Trace Languages gives the same matching set
477+
as interpreting (as usual) on String Languages and then projecting to Traces.
478+
-/
475479
lemma matches_toTrace (P : RegularExpression α) : (matches_trace I P) = toTrace P.matches' := by
476480
induction P with
477481
| zero => simp [toTrace, matches_trace, Language.zero_def]
@@ -603,60 +607,24 @@ lemma matches_toTrace_dist (P Q : RegularExpression α) :
603607

604608
end RegularExpression
605609

606-
lemma empty_is_starConnected (X : RegularExpression α) (h : ¬ ∃s, s ∈ X.matches') :
607-
RegularExpression.isStarConnected I X := by
608-
induction X with
609-
| zero => trivial
610-
| epsilon => trivial
611-
| char a => trivial
612-
| plus P Q ihP ihQ =>
613-
simp [Language.add_def] at h
614-
replace ihP := ihP (by
615-
simp
616-
intro s
617-
exact (not_or.mp (h s)).left)
618-
replace ihQ := ihQ (by
619-
simp
620-
intro s
621-
exact (not_or.mp (h s)).right)
622-
exact ⟨ihP, ihQ⟩
623-
| comp P Q ihP ihQ =>
624-
by_cases hpe : ∃ s, s ∈ P.matches'
625-
· simp [Language.mul_def] at h
626-
replace ihQ := ihQ (by
627-
simp
628-
intro s hcon
629-
apply h s
630-
have ⟨p, hp⟩ := hpe
631-
use p, hp, s, hcon
632-
-- have : s ∈ Set.image2 (fun x1 x2 => x1 ++ x2) P.matches' Q.matches'
633-
use ihP
634-
exact (not_or.mp (h s)).left)
635-
· simp [Language.mul_def] at h
636-
replace ihP := ihP (by
637-
simp
638-
intro s hcon
639-
apply h s
640-
use s, hcon, []
641-
-- have : s ∈ Set.image2 (fun x1 x2 => x1 ++ x2) P.matches' Q.matches'
642-
use ihP
643-
exact (not_or.mp (h s)).left)
644-
unfold RegularExpression.isStarConnected
645-
| star P ih =>
646-
exfalso
647-
apply h
648-
use []
649-
simp [RegularExpression.matches', KStar.kstar]
650-
use []
651-
simp
610+
/-- Main component of Theorem 4.1 (ii) => (iii).
652611
653-
theorem _connectedIterativeFactors_is_starConnected (X : RegularExpression α)
612+
For a rational expression X, if every iterative factor of L(X) is connected,
613+
then X' is star-connected (for some rational expression X' with L(X) = L(X')).
614+
615+
It is strictly necessary that we use an X' not necessarily equal to X.
616+
Consider X = (ab)∗ · ∅; where `a` and `b` are not connected. Then L(X) = ∅ so every
617+
iterative factor is connected, but X is not star-connected.
618+
619+
Note that P · ∅ or ∅ · P are the only cases where this patch is needed.
620+
-/
621+
theorem connectedIterativeFactors_equiv_starConnected' (X : RegularExpression α)
654622
(hconn : ∀ s, isIterativeFactor X.matches' s → @isConnected' α I s) :
655-
RegularExpression.isStarConnected I X := by
623+
∃ Y, RegularExpression.isStarConnected I Y ∧ X.matches' = Y.matches' := by
656624
induction X with
657-
| zero => trivial
658-
| epsilon => trivial
659-
| char a => trivial
625+
| zero => use RegularExpression.zero, trivial
626+
| epsilon => use RegularExpression.epsilon, trivial
627+
| char a => use RegularExpression.char a, trivial
660628
| plus P Q ihP ihQ =>
661629
have ihP_cond : (∀ s, isIterativeFactor P.matches' s → @isConnected' α I s) := by
662630
intro s ⟨u, v, h⟩
@@ -670,7 +638,7 @@ theorem _connectedIterativeFactors_is_starConnected (X : RegularExpression α)
670638
apply (Set.mem_union _ _ _).mpr
671639
simp [hp]
672640
exact h_match_subset _ h
673-
replace ihP := ihP ihP_cond
641+
have ⟨P', hP'⟩ := ihP ihP_cond
674642

675643
have ihQ_cond : (∀ s, isIterativeFactor Q.matches' s → @isConnected' α I s) := by
676644
intro s ⟨u, v, h⟩
@@ -684,132 +652,97 @@ theorem _connectedIterativeFactors_is_starConnected (X : RegularExpression α)
684652
apply (Set.mem_union _ _ _).mpr
685653
simp [hp]
686654
exact h_match_subset _ h
687-
replace ihQ := ihQ ihQ_cond
655+
have ⟨Q', hQ'⟩ := ihQ ihQ_cond
688656

689-
simp [RegularExpression.isStarConnected, ihP, ihQ]
657+
use P' + Q'
658+
simp [RegularExpression.isStarConnected, hP', hQ']
690659
| comp P Q ihP ihQ =>
660+
by_cases hpe : ¬ ∃ p, p ∈ P.matches'
661+
· use RegularExpression.zero
662+
simp [RegularExpression.isStarConnected]
663+
rw [Language.zero_def]
664+
apply Language.ext
665+
intro x
666+
apply Iff.intro
667+
all_goals intro h
668+
· rw [Language.mul_def] at h
669+
replace ⟨u, hu, v, hv, h⟩ := h
670+
exact hpe ⟨u, hu⟩
671+
· exact False.elim h
672+
673+
by_cases hqe : ¬ ∃ q, q ∈ Q.matches'
674+
· use RegularExpression.zero
675+
simp [RegularExpression.isStarConnected]
676+
rw [Language.zero_def]
677+
apply Language.ext
678+
intro x
679+
apply Iff.intro
680+
all_goals intro h
681+
· rw [Language.mul_def] at h
682+
replace ⟨u, hu, v, hv, h⟩ := h
683+
exact hqe ⟨v, hv⟩
684+
· exact False.elim h
685+
686+
simp at hpe hqe
687+
691688
have ihP_cond : (∀ s, isIterativeFactor P.matches' s → @isConnected' α I s) := by
692689
intro s ⟨u, v, h⟩
693690
apply hconn s
694-
by_cases hqe : ∃ q, q ∈ Q.matches'
695-
· have ⟨q, hq⟩ := hqe
696-
use u, v ++ q
697-
intro ts hts
698-
replace h := h ts hts
699-
unfold RegularExpression.matches'
700-
use u ++ ts.flatten ++ v, h, q, hq
701-
simp
702-
· use [], []
703-
intro ts hts
704-
have := h ts hts
705-
use u
706-
intro u v ts ht
707-
have h := hsf u v ts ht
708-
intro
709-
replace ihP := ihP ihP_cond
710-
| star => sorry
711-
712-
713-
714-
715-
theorem connectedIterativeFactors_is_starConnected (T : Set (Trace I)) (X : RegularExpression α) (himg : T = toTrace X.matches')
716-
(hconn : ∀ s ∈ X.matches', isIterativeFactor X.matches' s → @isConnected' α I s) :
717-
∃ P, RegularExpression.isStarConnected I P ∧ T = (RegularExpression.matches_trace I P) := by
718-
simp [RegularExpression.matches_toTrace]
719-
induction X generalizing T with
720-
| zero => use RegularExpression.zero, trivial, himg
721-
| epsilon => use RegularExpression.epsilon, trivial, himg
722-
| char a => use RegularExpression.char a, trivial, himg
723-
| plus P Q ihP ihQ =>
724-
replace ihP := ihP (toTrace P.matches')
725-
simp at ihP
726-
have ihP_cond : (∀ s ∈ P.matches', isIterativeFactor P.matches' s → @isConnected' α I s) := by
727-
intro s hsp hsf
728-
replace hconn := hconn s
729-
have h_match_subset : ∀ p ∈ P.matches', p ∈ P.matches' + Q.matches' := by
730-
simp [Language.add_def]
731-
intro p hp
732-
apply (Set.mem_union _ _ _).mpr
733-
simp [hp]
734-
apply hconn (h_match_subset s hsp)
735-
intro u v ts ht
736-
have h := hsf u v ts ht
737-
exact h_match_subset _ h
691+
have ⟨q, hq⟩ := hqe
692+
use u, v ++ q
693+
intro ts hts
694+
replace h := h ts hts
695+
unfold RegularExpression.matches'
696+
use u ++ ts.flatten ++ v, h, q, hq
697+
simp
738698
have ⟨P', hP'⟩ := ihP ihP_cond
739699

740-
replace ihQ := ihQ (toTrace Q.matches')
741-
simp at ihQ
742-
have ihQ_cond : (∀ s ∈ Q.matches', isIterativeFactor Q.matches' s → @isConnected' α I s) := by
743-
intro s hsq hsf
744-
replace hconn := hconn s
745-
have h_match_subset : ∀ q ∈ Q.matches', q ∈ P.matches' + Q.matches' := by
746-
simp [Language.add_def]
747-
intro p hp
748-
apply (Set.mem_union _ _ _).mpr
749-
simp [hp]
750-
apply hconn (h_match_subset s hsq)
751-
intro u v ts ht
752-
have h := hsf u v ts ht
753-
exact h_match_subset _ h
700+
have ihQ_cond : (∀ s, isIterativeFactor Q.matches' s → @isConnected' α I s) := by
701+
intro s ⟨u, v, h⟩
702+
apply hconn s
703+
have ⟨p, hp⟩ := hpe
704+
use p ++ u, v
705+
intro ts hts
706+
replace h := h ts hts
707+
unfold RegularExpression.matches'
708+
use p, hp, u ++ ts.flatten ++ v, h
709+
simp
754710
have ⟨Q', hQ'⟩ := ihQ ihQ_cond
755711

756-
use P' + Q'
757-
simp [RegularExpression.isStarConnected, himg, hP', hQ']
758-
| comp P Q ihP ihQ =>
759-
replace ihP := ihP (toTrace P.matches')
760-
simp at ihP
761-
have ihP_cond : (∀ s ∈ P.matches', isIterativeFactor P.matches' s → @isConnected' α I s) := by
762-
intro s hsp hsf
763-
replace hconn := hconn s
764-
have h_match_subset : ∀ p ∈ P.matches', p ∈ P.matches' * Q.matches' := by
765-
intro p hp
766-
use p, hp
767-
simp
768-
apply hconn (h_match_subset s hsp)
769-
intro u v ts ht
770-
have h := hsf u v ts ht
771-
exact h_match_subset _ h
772-
have ⟨P', hP'⟩ := ihP ihP_cond
773-
774-
775-
| star => sorry
776-
777-
simp [RegularExpression.matches_toTrace] at himg
778-
induction T generalizing X with
779-
| zero => exact trivial
780-
| epsilon => exact trivial
781-
| char _ => exact trivial
782-
| plus P Q ihP ihQ =>
783-
unfold RegularExpression.isStarConnected
784-
apply And.intro
785-
· apply ihP P
786-
intro s hsp hsf
787-
simp [] at hsp
788-
replace hconn := hconn s
789-
sorry
790-
| comp P Q ih1 ih2 => sorry
791-
| star => sorry
792-
793-
-- !!! --- T : Set (Trace α) ;; ∃ P : T = P.matches_trace
794-
theorem connectedIterativeFactors_is_starConnected' (T : RegularExpression α) (X : RegularExpression α)
795-
(himg : (@RegularExpression.matches_trace α I T) = toTrace X.matches')
796-
(hconn : ∀ s ∈ X.matches', isIterativeFactor X.matches' s → @isConnected' α I s) :
797-
RegularExpression.isStarConnected I T := by
798-
simp [RegularExpression.matches_toTrace] at himg
799-
induction T generalizing X with
800-
| zero => exact trivial
801-
| epsilon => exact trivial
802-
| char _ => exact trivial
803-
| plus P Q ihP ihQ =>
804-
unfold RegularExpression.isStarConnected
805-
apply And.intro
806-
· apply ihP P
807-
intro s hsp hsf
808-
simp [] at hsp
809-
replace hconn := hconn s
810-
sorry
811-
| comp P Q ih1 ih2 => sorry
812-
| star => sorry
712+
use P' * Q'
713+
simp [RegularExpression.isStarConnected, hP', hQ']
714+
| star P ih =>
715+
have ih_cond : ∀ (s : List α), isIterativeFactor P.matches' s → @isConnected' α I s := by
716+
intro s ⟨u, v, h⟩
717+
apply hconn
718+
use u, v
719+
intro ts hts
720+
replace h := h ts hts
721+
simp [Language.kstar_def]
722+
use [u ++ ts.flatten ++ v]
723+
simp [<- List.append_assoc]
724+
exact h
725+
have ⟨P', hP'⟩ := ih ih_cond
726+
use P'.star
727+
simp [RegularExpression.isStarConnected, hP']
728+
intro s hs
729+
apply hconn
730+
use [], []
731+
intro ts hts
732+
simp [Language.kstar_def]
733+
use ts
734+
simp
735+
intro y hy
736+
rw [hts y hy, hP'.right]
737+
exact hs
813738

739+
/-- Theorem 4.1 (ii) => (iii) -/
740+
theorem connectedIterativeFactors_equiv_starConnected (T : Set (Trace I)) (X : RegularExpression α) (himg : T = toTrace X.matches')
741+
(hconn : ∀ s, isIterativeFactor X.matches' s → @isConnected' α I s) :
742+
∃ P, RegularExpression.isStarConnected I P ∧ T = (RegularExpression.matches_trace I P) := by
743+
simp [RegularExpression.matches_toTrace]
744+
have ⟨P, hP⟩ := connectedIterativeFactors_equiv_starConnected' X hconn
745+
use P
746+
simp [hP, himg]
814747

815748
end Trace

0 commit comments

Comments
 (0)