Skip to content

Commit 729f051

Browse files
committed
Fix connectedness definition
1 parent f11951f commit 729f051

1 file changed

Lines changed: 165 additions & 6 deletions

File tree

TraceTheory/TraceTheory/Language.lean

Lines changed: 165 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,26 @@ variable {α : Type} {I : Independence α}
408408
def alph_mem (a : α) (t : Trace I) :=
409409
Quotient.lift (fun (s : List α) => a ∈ s) (by intro u v h; simp; exact mem_iff_mem a h) t
410410

411-
infixl:65 " ∈ " => alph_mem
411+
instance : Membership α (Trace I) where
412+
mem l a := alph_mem a l
413+
414+
lemma eps_is_empty (a : α) : a ∉ @Trace.mk' α I [] := by
415+
intro h
416+
rcases h
417+
418+
lemma empty_is_eps (t : Trace I) : t ≠ ⟦[]⟧ → ∃ a, a ∈ t := by
419+
intro h
420+
rcases t
421+
rename_i w
422+
replace h : w ≠ [] := fun a => h (congrArg (Quot.mk ⇑(traceSetoid I)) a)
423+
exact List.exists_mem_of_ne_nil w h
424+
425+
lemma mem_append {a : α} {s t : Trace I} : a ∈ s * t ↔ a ∈ s ∨ a ∈ t := by
426+
rcases s
427+
rcases t
428+
exact List.mem_append
429+
430+
lemma mems_lift (w : List α) : {a : α // a ∈ w} = {a : α // a ∈ @mk' α I w} := rfl
412431

413432
/-- The Dependence relation induced by an Independence `I`. -/
414433
def inducedDependence {α : Type} (I : Independence α) : Dependence α where
@@ -421,15 +440,50 @@ def inducedDependence {α : Type} (I : Independence α) : Dependence α where
421440
exact hab (I.symm b a hba)
422441

423442

424-
def isConnected' (s : List α) := ∀ a ∈ s, ∀ b ∈ s, (Relation.TransGen (inducedDependence I).rel) a b
443+
def dependencyIn' (s : List α) (a b : {a : α // a ∈ s}) := (inducedDependence I).rel a b
444+
445+
def dependencyTransClosureIn' (s : List α) (a b : {a : α // a ∈ s}) := Relation.TransGen (@dependencyIn' α I s) a b
446+
447+
def isConnected' (s : List α) := ∀ a b : {a : α // a ∈ s}, (Relation.TransGen (inducedDependence I).rel) a b
448+
449+
450+
def dependencyIn (t : Trace I) (a b : {a : α // a ∈ t}) := (inducedDependence I).rel a b
425451

426-
def isConnected (t : Trace I) := ∀ a b : α, a ∈ t ∧ b ∈ t → (Relation.TransGen (inducedDependence I).rel) a b
452+
def dependencyTransClosureIn (t : Trace I) (a b : {a : α // a ∈ t}) := Relation.TransGen (dependencyIn t) a b
453+
454+
def isConnected (t : Trace I) := ∀ a b : {a : α // a ∈ t}, dependencyTransClosureIn t a b
455+
456+
457+
-- lemma
458+
459+
-- lemma dependencyIn_toTrace (s : List α) : dependencyIn
460+
461+
lemma isConnected_toTrace (s : List α) : @isConnected' α I s → @isConnected α I ⟦s⟧ := by
462+
intro h a b
463+
replace h := h a b
464+
unfold dependencyTransClosureIn dependencyIn
465+
cases h with
466+
| single h => exact Relation.TransGen.single h
467+
| tail hac hcb =>
468+
rename_i c
469+
-- rw [show ⟦s⟧ = mk' s from rfl, <- mems_lift] at a b
470+
apply Relation.TransGen.tail
471+
all_goals sorry
472+
-- · exact hac
427473

428474
def isIterativeFactor (X : Language α) (t : List α) :=
429475
∃ u v, ∀ (ts : List (List α)), (∀ t' ∈ ts, t' = t) → u ++ ts.flatten ++ v ∈ X
430476

431477
def toTrace (X : Language α) : Set (Trace I) := (fun s => ⟦s⟧) '' X
432478

479+
480+
def kstar (T : Set (Trace I)) := {r | ∃ ts : List (Trace I), (∀ t' ∈ ts, t' ∈ T) ∧ r = ts.foldl (fun (u : Trace I) v => u * v) ⟦[]⟧}
481+
482+
def independent' (u v : Trace I) := ∀ a b, a ∈ u → b ∈ v → I.rel a b
483+
484+
def connectedComponents (X : Set (Trace I)) : Set (Trace I) := {u | isConnected u ∧ u ≠ ⟦[]⟧ ∧ ∃ v, u * v ∈ X ∧ independent' u v}
485+
486+
433487
--@[simp]
434488
--lemma mul_canonical {a b : Trace I} : mul a b = a * b := by rfl
435489

@@ -471,7 +525,24 @@ def matches_trace (I : Independence α) : RegularExpression α → Set (Trace I)
471525
| RegularExpression.char a => {⟦[a]⟧}
472526
| P + Q => (matches_trace I P) ∪ (matches_trace I Q)
473527
| P * Q => {t | ∃ p : (matches_trace I P), ∃ q : (matches_trace I Q), t = p * q}
474-
| 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) ⟦[]⟧}
528+
| RegularExpression.star P => kstar (matches_trace I P)
529+
530+
def isStarConnected_trace (I : Independence α) : RegularExpression α → Prop
531+
| 0 => True
532+
| 1 => True
533+
| RegularExpression.char _ => True
534+
| P + Q => isStarConnected I P ∧ isStarConnected I Q
535+
| P * Q => isStarConnected I P ∧ isStarConnected I Q
536+
| RegularExpression.star P => isStarConnected I P ∧ (∀ t ∈ matches_trace I P, @isConnected α I t)
537+
538+
-- Interpretation of this RegularExpression as operating on trace languages.
539+
def matches_cstar_trace (I : Independence α) : RegularExpression α → Set (Trace I)
540+
| 0 => {}
541+
| 1 => {⟦[]⟧}
542+
| RegularExpression.char a => {⟦[a]⟧}
543+
| P + Q => (matches_trace I P) ∪ (matches_trace I Q)
544+
| P * Q => {t | ∃ p : (matches_trace I P), ∃ q : (matches_trace I Q), t = p * q}
545+
| RegularExpression.star P => kstar (connectedComponents (matches_trace I P))
475546

476547
/-- Interpreting this RegularExpression as operating on Trace Languages gives the same matching set
477548
as interpreting (as usual) on String Languages and then projecting to Traces.
@@ -541,7 +612,7 @@ lemma matches_toTrace (P : RegularExpression α) : (matches_trace I P) = toTrace
541612
apply Set.ext_iff.mpr
542613
intro t
543614
apply Iff.intro
544-
all_goals simp
615+
all_goals simp [kstar]
545616
· intro ts hts ht
546617
induction ts generalizing t with
547618
| nil =>
@@ -613,7 +684,7 @@ end RegularExpression
613684
then X' is star-connected (for some rational expression X' with L(X) = L(X')).
614685
615686
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
687+
Consider X = {a ∪ b}∗ · ∅; where `a` and `b` are not connected. Then L(X) = ∅ so every
617688
iterative factor is connected, but X is not star-connected.
618689
619690
Note that P · ∅ or ∅ · P are the only cases where this patch is needed.
@@ -745,4 +816,92 @@ theorem connectedIterativeFactors_equiv_starConnected (T : Set (Trace I)) (X : R
745816
use P
746817
simp [hP, himg]
747818

819+
lemma append_indep_is_disconnected (u v : Trace I) (h : independent' u v) (hu : u ≠ ⟦[]⟧) (hv : v ≠ ⟦[]⟧) :
820+
¬isConnected (u * v) := by
821+
by_contra h_con
822+
have ⟨a, ha⟩ := empty_is_eps u hu
823+
have ⟨b, hb⟩ := empty_is_eps v hv
824+
have h_ad := h a b ha hb
825+
have := h_con ⟨a, mem_append.mpr (Or.inl ha)⟩ ⟨b, mem_append.mpr (Or.inr hb)⟩
826+
unfold dependencyTransClosureIn dependencyIn at this
827+
-- simp at this
828+
sorry
829+
830+
lemma connectedComponents_of_connected (T : Set (Trace I)) (h : ∀ t ∈ T, isConnected t) :
831+
connectedComponents T = T \ {⟦[]⟧} := by
832+
apply Set.ext
833+
intro t
834+
apply Iff.intro
835+
· intro ⟨ht, htz, v, htv, htv_id⟩
836+
simp [htz]
837+
replace h := h (t * v) htv
838+
have hvz : v = ⟦[]⟧ := by
839+
by_contra hvz
840+
exact append_indep_is_disconnected t v htv_id htz hvz h
841+
rw [hvz, show ⟦[]⟧ = mk' [] from rfl, right_id'] at htv
842+
exact htv
843+
· intro ⟨ht, htz⟩
844+
use (h t ht), htz, ⟦[]⟧
845+
rw [show ⟦[]⟧ = mk' [] from rfl, Trace.right_id']
846+
use ht
847+
unfold independent'
848+
simp [eps_is_empty]
849+
850+
851+
852+
theorem starConnected_is_cRational (X : RegularExpression α) (h : RegularExpression.isStarConnected I X) :
853+
RegularExpression.matches_trace I X = RegularExpression.matches_cstar_trace I X := by
854+
induction X with
855+
| zero => simp [RegularExpression.matches_trace, RegularExpression.matches_cstar_trace]
856+
| epsilon => simp [RegularExpression.matches_trace, RegularExpression.matches_cstar_trace]
857+
| char _ => simp [RegularExpression.matches_trace, RegularExpression.matches_cstar_trace]
858+
| plus _ _ _ _ => simp [RegularExpression.matches_trace, RegularExpression.matches_cstar_trace]
859+
| comp _ _ _ _ => simp [RegularExpression.matches_trace, RegularExpression.matches_cstar_trace]
860+
| star P ih =>
861+
replace ih := ih h.left
862+
unfold RegularExpression.matches_trace RegularExpression.matches_cstar_trace
863+
simp
864+
unfold RegularExpression.isStarConnected at h
865+
have hP_conn : (∀ t ∈ RegularExpression.matches_trace I P, t.isConnected) := by
866+
intro t ht
867+
rw [RegularExpression.matches_toTrace] at ht
868+
rcases t with ⟨w₀⟩
869+
have ⟨w, hw, hw₀⟩ := ht
870+
simp at hw₀
871+
rw [<- hw₀]
872+
exact isConnected_toTrace w (h.right w hw)
873+
rw [connectedComponents_of_connected _ hP_conn]
874+
apply Set.ext
875+
intro t
876+
apply Iff.intro
877+
· intro ⟨ls, hls, ht⟩
878+
have _ : BEq (Trace I) := by sorry
879+
use ls.filter (· != ⟦[]⟧)
880+
simp
881+
apply And.intro
882+
· intro t' ht' htz'
883+
use hls t' ht'
884+
by_contra ht'_con
885+
rw [ht'_con] at htz'
886+
-- simp at htz'
887+
sorry
888+
· induction ls generalizing t with
889+
| nil => simp at ht ⊢; exact ht
890+
| cons l ls ih =>
891+
rw [ht]
892+
replace ih := ih (List.foldl (fun u v => u * v) ⟦[]⟧ ls)
893+
simp at ih
894+
have ih_cond : (∀ t' ∈ ls, t' ∈ RegularExpression.matches_trace I P) := by
895+
intro c hc
896+
exact hls c (List.mem_cons_of_mem l hc)
897+
replace ih := ih ih_cond
898+
sorry
899+
· intro ⟨ls, hls, ht⟩
900+
use ls
901+
simp [ht]
902+
intro t' ht'
903+
exact Set.mem_of_mem_inter_left (hls t' ht')
904+
905+
906+
748907
end Trace

0 commit comments

Comments
 (0)