Skip to content

Commit 6c50f58

Browse files
committed
Cleanup lemmas
1 parent e150e6a commit 6c50f58

1 file changed

Lines changed: 137 additions & 119 deletions

File tree

TraceTheory/TraceTheory/Language.lean

Lines changed: 137 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ lemma indep_of_flatten {u : List α} {vs : List (List α)} (i : Fin vs.length) (
2121
exact ih (indep_of_concat h).right i hi
2222

2323
/-- (i) → (ii) of Corollary (2.3) in `Partial Commutation and Traces`.
24-
Note that t₁, t₂, …, tₙ is expressed as a list [ts], and (t₁ ++ t₂ ++ … ++ tₙ) via [ts.foldl].
24+
Note that t₁, t₂, …, tₙ is expressed as a list [ts], and (t₁ ++ t₂ ++ … ++ tₙ) via [ts.flatten].
2525
Similarly, p₁, …, pₙ is [ps] and q₁, …, qₙ is [qs]. -/
2626
theorem levi_lemma_gen (u v : List α) (ts : List (List α)) [DecidableEq α] (h : TraceEquiv I (u ++ v) ts.flatten) :
2727
∃ (ps qs : List (List α)),
@@ -439,6 +439,36 @@ def inducedDependence {α : Type} (I : Independence α) : Dependence α where
439439
intro a b hab hba
440440
exact hab (I.symm b a hba)
441441

442+
--@[simp]
443+
--lemma mul_canonical {a b : Trace I} : mul a b = a * b := by rfl
444+
445+
--instance : Mul (Trace I) :=
446+
-- ⟨(mul · ·)⟩
447+
448+
@[simp]
449+
lemma left_id (t : Trace I) : ↑(⟦[]⟧) * t = t := by
450+
rcases t
451+
rfl
452+
453+
@[simp]
454+
lemma right_id (t : Trace I) : t * ↑(⟦[]⟧) = t := by
455+
rcases t with ⟨w⟩
456+
simp [show Quot.mk (⇑(traceSetoid I)) w = ⟦w⟧ from rfl, HMul.hMul, Mul.mul]
457+
458+
--lemma mul_def : (⟦u⟧ : Trace I) * ⟦v⟧ = ⟦u ++ v⟧ :=
459+
-- rfl
460+
461+
def traceFlatten (L : List (Trace I)) := List.foldl (fun (u : Trace I) v => u * v) ⟦[]⟧ L
462+
463+
lemma traceFlatten_append {u : Trace I} (L : List (Trace I)) : traceFlatten (u :: L) = u * traceFlatten L := by
464+
unfold traceFlatten
465+
simp
466+
rw [<- right_id u]
467+
rw [List.foldl_assoc]
468+
simp
469+
470+
471+
442472

443473
def dependencyIn' (s : List α) (a b : {a : α // a ∈ s}) := (inducedDependence I).rel a b
444474

@@ -467,36 +497,70 @@ def isIterativeFactor (X : Language α) (t : List α) :=
467497
def toTrace (X : Language α) : Set (Trace I) := (fun s => ⟦s⟧) '' X
468498

469499

470-
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) ⟦[]⟧}
500+
def kstar (T : Set (Trace I)) := {r | ∃ ts : List (Trace I), (∀ t' ∈ ts, t' ∈ T) ∧ r = traceFlatten ts}
471501

472502
def independent' (u v : Trace I) := ∀ a b, a ∈ u → b ∈ v → I.rel a b
473503

474504
def connectedComponents (X : Set (Trace I)) : Set (Trace I) := {u | isConnected u ∧ u ≠ ⟦[]⟧ ∧ ∃ v, u * v ∈ X ∧ independent' u v}
475505

476506

477-
--@[simp]
478-
--lemma mul_canonical {a b : Trace I} : mul a b = a * b := by rfl
479-
480-
@[simp]
481-
lemma left_id (t : Trace I) : mul ⟦[]⟧ t = t := by
482-
rcases t
483-
rfl
484507

485-
@[simp]
486-
lemma right_id (t : Trace I) : mul t ⟦[]⟧ = t := by
487-
rcases t
488-
simp
489-
rfl
490-
491-
@[simp]
492-
lemma left_id' (t : Trace I) : mk' [] * t = t := by
493-
rcases t
494-
rfl
508+
-- open Computability
495509

496-
@[simp]
497-
lemma right_id' (t : Trace I) : t * mk' [] = t := by
498-
rw [show t * (mk' []) = mul t ⟦[]⟧ from rfl]
499-
exact right_id t
510+
lemma kstar_toTrace_commutes (L : Language α) : @toTrace α I (KStar.kstar L) = kstar (toTrace L) := by
511+
simp [Language.kstar_def, Set.image, toTrace]
512+
apply Set.ext
513+
intro t
514+
apply Iff.intro
515+
all_goals simp [kstar]
516+
· intro w ws hw
517+
induction ws generalizing w t with
518+
| nil =>
519+
intro hL ht
520+
use []
521+
simp at hw
522+
rw [hw] at ht
523+
simp [ht, traceFlatten]
524+
| cons u ws ih =>
525+
simp at ih
526+
intro hL ht
527+
replace ih := ih (fun y hy => hL y (List.mem_cons_of_mem u hy))
528+
choose ts hts using ih
529+
use ⟦u⟧ :: ts
530+
apply And.intro
531+
· intro s hs
532+
cases hs with
533+
| head => use u; simp [hL]
534+
| tail s hs => exact hts.left s hs
535+
· simp [<- ht, hw]
536+
-- rw [<- mul_def]
537+
rw [traceFlatten_append, <- hts.right]
538+
rfl
539+
· intro ts hts ht
540+
induction ts generalizing t with
541+
| nil =>
542+
use []
543+
simp [ht, traceFlatten]
544+
use []
545+
simp
546+
| cons s ts ih =>
547+
simp at ih
548+
replace ih := ih (fun y hy => hts y (List.mem_cons_of_mem s hy))
549+
choose w hws hw using ih
550+
rcases s with ⟨u⟩
551+
rw [show Quot.mk (⇑(traceSetoid I)) u = ⟦u⟧ from rfl] at ht hts
552+
replace hts := hts ⟦u⟧
553+
simp at hts
554+
choose u' hu' using hts
555+
use u' ++ w
556+
apply And.intro
557+
· rcases hws with ⟨ws, hws⟩
558+
use u' :: ws
559+
simp [hws.left, hu']
560+
exact hws.right
561+
· simp [ht]
562+
rw [traceFlatten_append, <- hw, <- hu'.right]
563+
rfl
500564

501565
namespace RegularExpression
502566

@@ -597,65 +661,8 @@ theorem matches_toTrace (P : RegularExpression α) : (matches_trace I P) = toTra
597661
rw [<- ht, <- hw]
598662
rfl
599663
| star P ih =>
600-
unfold matches_trace RegularExpression.matches' toTrace
601-
simp [Language.kstar_def, Set.image, ih, toTrace]
602-
apply Set.ext_iff.mpr
603-
intro t
604-
apply Iff.intro
605-
all_goals simp [kstar]
606-
· intro ts hts ht
607-
induction ts generalizing t with
608-
| nil =>
609-
use []
610-
simp at ht
611-
simp [ht]
612-
use []
613-
simp
614-
| cons head ts ih =>
615-
simp at ih
616-
have ih_cond : ∀ t' ∈ ts, ∃ a ∈ P.matches', ⟦a⟧ = t' := by
617-
intro t' ht'
618-
exact hts t' (List.mem_cons_of_mem head ht')
619-
have ⟨a, ⟨⟨ls, ha, hls⟩, hat⟩⟩ := ih ih_cond
620-
rw [show ⟦[]⟧ = mk' [] from rfl] at ht
621-
rw [List.foldl, Trace.left_id', <- Trace.right_id' head, List.foldl_assoc] at ht
622-
rcases head
623-
rename_i w₀
624-
have ⟨w, hw⟩ := hts ⟦w₀⟧ List.mem_cons_self
625-
use w ++ a
626-
apply And.intro
627-
· use w :: ls
628-
simp [ha, hw]
629-
exact hls
630-
· rw [ht, show ⟦w ++ a⟧ = mul ⟦w⟧ ⟦a⟧ from rfl, hat, hw.2]
631-
rfl
632-
· intro w ws hw hws ht
633-
induction ws generalizing w t with
634-
| nil =>
635-
use []
636-
simp at hw ⊢
637-
rw [<- hw, ht]
638-
| cons u us ih =>
639-
simp at ih
640-
have ih_cond : ∀ y ∈ us, y ∈ P.matches' := by
641-
intro y hy
642-
exact hws y (List.mem_cons_of_mem u hy)
643-
have ⟨ts, ⟨hts, h_eqs⟩⟩ := ih ih_cond
644-
use ⟦u⟧ :: ts
645-
simp
646-
repeat apply And.intro
647-
· use u
648-
simp [hws u List.mem_cons_self]
649-
· exact hts
650-
· rw [<- ht, hw]
651-
simp
652-
rw [show ⟦u ++ us.flatten⟧ = mul ⟦u⟧ ⟦us.flatten⟧ from rfl]
653-
rw [show ⟦[]⟧ = mk' [] from rfl]
654-
rw [Trace.left_id']
655-
nth_rw 2 [<- Trace.right_id' ⟦u⟧]
656-
rw [List.foldl_assoc]
657-
rw [h_eqs]
658-
rfl
664+
unfold matches_trace RegularExpression.matches'
665+
rw [kstar_toTrace_commutes, ih]
659666

660667

661668
@[simp]
@@ -846,15 +853,14 @@ lemma connectedComponents_of_connected (T : Set (Trace I)) (h : ∀ t ∈ T, isC
846853
have hvz : v = ⟦[]⟧ := by
847854
by_contra hvz
848855
exact append_indep_is_disconnected t v htv_id htz hvz h
849-
rw [hvz, show ⟦[]⟧ = mk' [] from rfl, right_id'] at htv
856+
rw [hvz, right_id] at htv
850857
exact htv
851858
· intro ⟨ht, htz⟩
852859
use (h t ht), htz, ⟦[]⟧
853-
rw [show ⟦[]⟧ = mk' [] from rfl, Trace.right_id']
860+
rw [right_id]
854861
use ht
855862
unfold independent'
856-
simp [eps_is_empty]
857-
863+
simp [show ⟦[]⟧ = mk' [] from rfl, eps_is_empty]
858864

859865

860866
lemma empty_iff {w : List α} : (⟦w⟧ : Trace I) = ⟦[]⟧ ↔ w = [] := by
@@ -887,23 +893,52 @@ lemma isEmpty_iff {t : Trace I} : t.isEmpty = true ↔ t = ⟦[]⟧ := by
887893
rw [h]
888894
rfl
889895

890-
lemma traceFlatten_filter_not_isEmpty :
891-
∀ {L : List (Trace I)},
892-
List.foldl (fun (u : Trace I) v => u * v) ⟦[]⟧ (List.filter (!·.isEmpty) L)
893-
= List.foldl (fun (u : Trace I) v => u * v) ⟦[]⟧ L
896+
lemma traceFlatten_filter_not_isEmpty :
897+
∀ {L : List (Trace I)}, traceFlatten (List.filter (!·.isEmpty) L) = traceFlatten L
894898
| [] => rfl
895899
| t :: L => by
896900
by_cases ht : t.isEmpty
897901
· apply isEmpty_iff.mp at ht
898902
simp [ht]
899903
simp [show isEmpty ⟦[]⟧ = true from rfl]
900-
rw [show ⟦[]⟧ = mk' [] from rfl, left_id', show mk' [] = ⟦[]⟧ from rfl]
901904
exact traceFlatten_filter_not_isEmpty (L := L)
902905
· simp [ht]
903-
rw [show ⟦[]⟧ = mk' [] from rfl, left_id', <- right_id' t, show mk' [] = ⟦[]⟧ from rfl]
904-
repeat rw [List.foldl_assoc]
906+
repeat rw [traceFlatten_append]
905907
rw [traceFlatten_filter_not_isEmpty (L := L)]
906908

909+
lemma kstar_eq_minusEps (L : Language α) : KStar.kstar (L \ {[]}) = KStar.kstar L := by
910+
apply Set.ext
911+
intro w
912+
apply Iff.intro
913+
· intro ⟨ls, hw, hls⟩
914+
use ls
915+
simp [hw]
916+
exact fun y hy => Set.diff_subset (hls y hy)
917+
· intro ⟨ls, hls, ht⟩
918+
use ls.filter (!·.isEmpty)
919+
simp
920+
apply And.intro
921+
· simp [hls, List.flatten_filter_not_isEmpty]
922+
· intro y hy hyz
923+
exact Set.mem_diff_singleton.mpr ⟨ht y hy, hyz⟩
924+
925+
lemma kstar_eq_minusEps_trace (T : Set (Trace I)) : kstar (T \ {⟦[]⟧}) = kstar T := by
926+
apply Set.ext
927+
intro t
928+
apply Iff.intro
929+
· intro ⟨ls, hls, ht⟩
930+
use ls
931+
simp [ht]
932+
exact fun y hy => Set.diff_subset (hls y hy)
933+
· intro ⟨ls, hls, ht⟩
934+
use ls.filter (!·.isEmpty)
935+
simp
936+
apply And.intro
937+
· intro y hy hyz
938+
exact ⟨hls y hy, Trace.isEmpty_iff.ne.mp (ne_true_of_eq_false hyz)⟩
939+
· simp [traceFlatten_filter_not_isEmpty, ht]
940+
941+
907942
/-- Theorem 4.1 (iii) => (iv) -/
908943
theorem starConnected_is_cRational (X : RegularExpression α) (h : RegularExpression.isStarConnected I X) :
909944
RegularExpression.matches_trace I X = RegularExpression.matches_cstar_trace I X := by
@@ -915,36 +950,19 @@ theorem starConnected_is_cRational (X : RegularExpression α) (h : RegularExpres
915950
| comp P Q ihP ihQ => simp [RegularExpression.matches_trace, RegularExpression.matches_cstar_trace, ihP h.1, ihQ h.2]
916951
| star P ih =>
917952
unfold RegularExpression.matches_trace RegularExpression.matches_cstar_trace
918-
simp [ih h.left]
953+
simp [<- ih h.1]
919954
unfold RegularExpression.isStarConnected at h
920-
have hP_conn : (∀ t ∈ RegularExpression.matches_cstar_trace I P, t.isConnected) := by
955+
have hP_conn : (∀ t ∈ RegularExpression.matches_trace I P, t.isConnected) := by
921956
intro t ht
922-
rw [<- ih h.left, RegularExpression.matches_toTrace] at ht
923957
rcases t with ⟨w₀⟩
924-
have ⟨w, hw, hw₀⟩ := ht
925-
simp at hw₀
926-
rw [<- hw₀, <- isConnected_toTrace]
927-
exact h.right w hw
958+
rw [show Quot.mk (⇑(traceSetoid I)) w₀ = ⟦w₀⟧ from rfl] at ht ⊢
959+
rw [RegularExpression.matches_toTrace] at ht
960+
simp [toTrace] at ht
961+
rcases ht with ⟨w, hw⟩
962+
rw [<- hw.2, <- isConnected_toTrace]
963+
exact h.2 w hw.1
928964
rw [connectedComponents_of_connected _ hP_conn]
929-
apply Set.ext
930-
intro t
931-
apply Iff.intro
932-
· intro ⟨ls, hls, ht⟩
933-
use ls.filter (!·.isEmpty)
934-
simp
935-
apply And.intro
936-
· intro t' ht' htz'
937-
use hls t' ht'
938-
by_contra ht'_con
939-
rw [ht'_con] at htz'
940-
exact (Bool.eq_not_self (isEmpty ⟦[]⟧)).mp htz'
941-
· rw [ht]
942-
exact Eq.symm traceFlatten_filter_not_isEmpty
943-
· intro ⟨ls, hls, ht⟩
944-
use ls
945-
simp [ht]
946-
intro t' ht'
947-
exact Set.mem_of_mem_inter_left (hls t' ht')
965+
rw [kstar_eq_minusEps_trace]
948966

949967

950968
end Trace

0 commit comments

Comments
 (0)