Skip to content

Commit 30b5958

Browse files
committed
Ochmanski (i) => (ii) fragments 2
1 parent 58f6629 commit 30b5958

1 file changed

Lines changed: 163 additions & 158 deletions

File tree

TraceTheory/TraceTheory/Ochmanski.lean

Lines changed: 163 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ theorem cRational_of_isStarConnected (X : RegularExpression α) (h : IsStarConne
124124
rw [connectedComponents_of_connected _ hP_conn]
125125
rw [kstar_eq_minusEps_trace]
126126

127-
/-- Hashiguchi's Theorem. -/
128127
theorem recognizable_image_of_regular_finite_rank {X : Language α}
129128
(hX_reg : X.IsRegular)
130129
(hX_rank : HasFiniteRank I X) :
@@ -552,6 +551,37 @@ lemma ccDec_aux_nonempty_head (I : Independence α) (u w : List α) (h : w ≠ [
552551
by_cases hab : dependencyTransClosureInL I u a b
553552
all_goals simp [hab]
554553

554+
--#check List.reverseRecOn
555+
--todo: make this work?
556+
theorem ccDec_cases {motive : List (List α) → Prop} (u w : List α)
557+
(nil : motive [[]])
558+
(char : ∀ (a : α), motive [[a]])
559+
(cons_conn : ∀ (a : α) (v : List α) (_h_conn : ccDec_aux_conn I u (a :: v)), motive (ccDec_aux I u v) → motive (ccDec_aux I u (a :: v)))
560+
(cons_disc : ∀ (a : α) (v : List α) (_h_disc : ¬ ccDec_aux_conn I u (a :: v)), motive (ccDec_aux I u v) → motive (ccDec_aux I u (a :: v))) :
561+
motive (ccDec_aux I u w) := by
562+
induction w with
563+
| nil => simp [ccDec_aux]; exact nil
564+
| cons a w ih =>
565+
let t := ccDec_aux I u w
566+
have ht : ccDec_aux I u w = t := rfl
567+
rcases t
568+
· exfalso
569+
exact (ccDec_aux_nonempty _ _) ht
570+
· rename_i c_head c_tail
571+
by_cases hw : w = []
572+
· simp [hw, ccDec_aux]
573+
exact char a
574+
cases c_head with
575+
| nil =>
576+
have := ccDec_aux_nonempty_head I u w hw
577+
simp [List.getElem_of_eq ht] at this
578+
| cons b c_head =>
579+
by_cases hab : dependencyTransClosureInL I u a b
580+
· apply cons_conn _ _ _ ih
581+
simp [ccDec_aux_conn, ht, hab]
582+
· apply cons_disc _ _ _ ih
583+
simp [ccDec_aux_conn, ht, hab]
584+
555585
lemma ccDec_aux_len_C {u w : List α} {a : α} (h : ccDec_aux_conn I u (a :: w)) :
556586
(ccDec_aux I u (a :: w)).length = (ccDec_aux I u w).length := by
557587
simp [ccDec_aux_conn] at h
@@ -657,33 +687,6 @@ lemma ccDec_aux_tail_D' {u w : List α} {a : α} (h : ¬ ccDec_aux_conn I u (a :
657687
| zero => simp at hiz
658688
| succ i => apply ccDec_aux_tail_D h i
659689

660-
/-
661-
lemma ccDec'_aux_len (u w : List α) (a : α) :
662-
(ccDec_aux' I u (a :: w)).length = (ccDec_aux' I u w).length ∨
663-
(ccDec_aux' I u (a :: w)).length = (ccDec_aux' I u w).length + 1 := by
664-
simp [ccDec_aux']
665-
cases ccDec_aux' I u w
666-
· simp
667-
· rename_i c_head c_tail
668-
simp
669-
cases c_head with
670-
| nil => simp
671-
| cons b c_head =>
672-
simp
673-
by_cases hab : dependencyTransClosureInL I u a b
674-
all_goals simp [hab]
675-
676-
lemma ccDec'_aux_len_le (u w : List α) (a : α) :
677-
(ccDec_aux' I u w).length ≤ (ccDec_aux' I u (a :: w)).length := by
678-
cases ccDec'_aux_len u w a with
679-
| inl h => rw [h]
680-
| inr h => simp [h]
681-
682-
lemma ccDec'_aux_sub_idx (u w : List α) (a : α) (i : Fin (ccDec_aux' I u (a :: w)).length) (hiz : i.1 > 0) :
683-
∃ j : Fin (ccDec_aux' I u w).length, (ccDec_aux' I u (a :: w))[i] = (ccDec_aux' I u w)[j] := by
684-
sorry
685-
-/
686-
687690
lemma ccDec_aux_elem_nonempty (u w : List α) (i : ℕ) (hi : i < (ccDec_aux I u w).length) (hz : w ≠ []) :
688691
(ccDec_aux I u w)[i] ≠ [] := by
689692
induction w generalizing i with
@@ -720,139 +723,87 @@ lemma ccDec_aux_elem_nonempty (u w : List α) (i : ℕ) (hi : i < (ccDec_aux I u
720723
apply ih
721724
exact hw
722725

723-
lemma ccDec_aux_prefix (I : Independence α) (u w : List α) :
724-
List.IsPrefix ((ccDec_aux I u w)[0]'(ccDec_aux_zero_idx)) w := by
726+
lemma ccDec_aux_flatten (I : Independence α) (u w : List α) :
727+
(ccDec_aux I u w).flatten = w := by
725728
induction w with
726729
| nil => simp [ccDec_aux]
727730
| cons a w ih =>
728-
suffices hs_dec : ∃ _1 _2, (ccDec_aux I u (a :: w)) = _1 :: _2 ∧ List.IsPrefix _1 (a :: w) from by
729-
replace ⟨_1, _2, ⟨hs_dec, hs⟩⟩ := hs_dec
730-
simp [List.getElem_of_eq hs_dec, hs]
731731
simp [ccDec_aux]
732732
let t := ccDec_aux I u w
733733
have ht : ccDec_aux I u w = t := rfl
734734
rcases t
735735
· exfalso
736736
exact (ccDec_aux_nonempty _ _) ht
737737
· rename_i c_head c_tail
738-
simp [ht]
738+
simp [ht] at ih ⊢
739739
cases c_head with
740-
| nil => simp
740+
| nil => simp at ih ⊢; exact ih
741741
| cons b c_head =>
742-
simp
743742
by_cases hab : dependencyTransClosureInL I u a b
744-
· simp [hab]
745-
simp [List.getElem_of_eq ht] at ih
746-
exact ih
747-
· simp [hab]
743+
all_goals simp [hab] at ih ⊢; exact ih
744+
745+
lemma List.flatten_prefix (L : List (List α)) (h : L ≠ []) :
746+
List.IsPrefix (L[0]'(List.length_pos_iff.mpr h)) L.flatten := by
747+
cases L with
748+
| nil => simp at h
749+
| cons w L => simp
750+
751+
lemma ccDec_flatten_prefix2 (L : List (List α)) (h : 1 < L.length) :
752+
List.IsPrefix (L[0] ++ L[1]) L.flatten := by
753+
cases L with
754+
| nil => simp at h
755+
| cons w L =>
756+
cases L with
757+
| nil => simp at h
758+
| cons v L => simp
759+
760+
lemma List.flatten_adj_infix (L : List (List α)) (i : ℕ) (hi : i + 1 < L.length) :
761+
List.IsInfix (L[i] ++ L[i + 1]) L.flatten := by
762+
induction L generalizing i with
763+
| nil => simp at hi
764+
| cons w L ih =>
765+
cases i with
766+
| zero =>
767+
cases L with
768+
| nil => simp at hi
769+
| cons v L =>
770+
simp [<- List.append_assoc]
771+
exact List.infix_append_left
772+
| succ i =>
773+
simp
774+
exact List.infix_append_of_infix_right (ih i (Nat.succ_lt_succ_iff.mp hi))
775+
776+
lemma List.flatten_suffix (L : List (List α)) (h : L ≠ []) :
777+
List.IsSuffix (L.getLast h) L.flatten := by
778+
induction L with
779+
| nil => simp at h
780+
| cons w L ih =>
781+
cases L with
782+
| nil => simp
783+
| cons v L =>
784+
simp at ih ⊢
785+
exact List.suffix_append_of_suffix ih
786+
787+
788+
lemma ccDec_aux_prefix (I : Independence α) (u w : List α) :
789+
List.IsPrefix ((ccDec_aux I u w)[0]'(ccDec_aux_zero_idx)) w := by
790+
nth_rw 3 [<- ccDec_aux_flatten I u w]
791+
exact List.flatten_prefix _ (ccDec_aux_nonempty u w)
748792

749793
lemma ccDec_aux_infix (I : Independence α) (u w : List α) (i : ℕ) (hi : i + 1 < (ccDec_aux I u w).length) :
750794
List.IsInfix ((ccDec_aux I u w)[i] ++ (ccDec_aux I u w)[i + 1]) w := by
751-
induction w generalizing i with
752-
| nil => simp [ccDec_aux] at hi
753-
| cons a w ih =>
754-
by_cases hiz : i = 0
755-
· simp [hiz]
756-
by_cases hab : ccDec_aux_conn I u (a :: w)
757-
· sorry
758-
· sorry
759-
· by_cases hab : ccDec_aux_conn I u (a :: w)
760-
· simp [ccDec_aux_len_C hab] at hi
761-
rw [ccDec_aux_tail_C hab i (by omega) (Nat.zero_lt_of_ne_zero hiz)]
762-
rw [ccDec_aux_tail_C hab (i + 1) (by omega) (Nat.zero_lt_succ i)]
763-
apply List.infix_cons
764-
apply ih
765-
· simp [ccDec_aux_len_D hab] at hi
766-
rw [ccDec_aux_tail_D' hab i (by omega) hiz]
767-
rw [ccDec_aux_tail_D' hab (i + 1) (by omega) (Ne.symm (Nat.zero_ne_add_one i))]
768-
simp
769-
apply List.infix_cons
770-
replace ih := ih (i - 1) (by omega)
771-
have : (ccDec_aux I u w)[i - 1 + 1]'(by omega) = (ccDec_aux I u w)[i]'(by omega) := by
772-
simp [getElem_congr _ (show i - 1 + 1 = i from Nat.succ_pred_eq_of_ne_zero hiz)]
773-
rw [this] at ih
774-
exact ih
795+
nth_rw 7 [<- ccDec_aux_flatten I u w]
796+
exact List.flatten_adj_infix (ccDec_aux I u w) i hi
775797

776798
lemma ccDec_aux_prefix2 (I : Independence α) (u w : List α) (h : 1 < (ccDec_aux I u w).length) :
777799
List.IsPrefix ((ccDec_aux I u w)[0] ++ (ccDec_aux I u w)[1]) w := by
778-
induction w with
779-
| nil => simp [ccDec_aux] at h
780-
| cons a w ih =>
781-
suffices hs_dec : ∃ _1 _2 _3, (ccDec_aux I u (a :: w)) = _1 :: _2 :: _3 ∧ List.IsPrefix (_1 ++ _2) (a :: w) from by
782-
replace ⟨_1, _2, _3, ⟨hs_dec, hs⟩⟩ := hs_dec
783-
simp [List.getElem_of_eq hs_dec, hs]
784-
simp [ccDec_aux]
785-
let t := ccDec_aux I u w
786-
have ht : ccDec_aux I u w = t := rfl
787-
rcases t
788-
· exfalso
789-
exact (ccDec_aux_nonempty _ _) ht
790-
· rename_i c_head c_tail
791-
simp [ht]
792-
cases c_head with
793-
| nil =>
794-
simp
795-
sorry
796-
| cons b c_head =>
797-
simp
798-
by_cases hab : dependencyTransClosureInL I u a b
799-
· simp [hab]
800-
simp [List.getElem_of_eq ht] at ih
801-
sorry
802-
--by_cases hct : c_tail = []
803-
--· simp [hct] at ht
804-
--use c_tail[0]
805-
--exact ih
806-
· simp [hab]
807-
have := List.getElem_of_eq ht ccDec_aux_zero_idx
808-
simp at this
809-
rw [<- this]
810-
exact ccDec_aux_prefix I u w
800+
nth_rw 7 [<- ccDec_aux_flatten I u w]
801+
exact ccDec_flatten_prefix2 (ccDec_aux I u w) h
811802

812803
lemma ccDec_aux_suffix (I : Independence α) (u w : List α) :
813804
List.IsSuffix ((ccDec_aux I u w).getLast (ccDec_aux_nonempty u w)) w := by
814-
induction w with
815-
| nil => simp [ccDec_aux]
816-
| cons a w ih =>
817-
let t := ccDec_aux I u w
818-
have ht : ccDec_aux I u w = t := rfl
819-
rcases t
820-
· simp [ccDec_aux, ht] at ih ⊢
821-
exact List.suffix_cons_iff.mpr (Or.inr ih)
822-
· rename_i c_head c_tail
823-
824-
/- by_cases hab : ccDec_aux_conn I u (a :: w)
825-
· rw [List.getLast_eq_getElem]
826-
rw [ccDec_aux_tail_C hab _ (by sorry) (by exact?)]
827-
have : (ccDec_aux I u (a :: w)).length - 1 = (ccDec_aux I u w).length - 1 := by
828-
rw [ccDec_aux_len_C hab]
829-
rw [getElem_congr rfl this]
830-
rw [<- List.getLast_eq_getElem]
831-
apply List.suffix_cons_iff.mpr -/
832-
833-
by_cases hw : w = []
834-
· simp [hw, ccDec_aux]
835-
have hch : c_head ≠ [] := by
836-
by_contra hcon
837-
rw [hcon] at ht
838-
replace ht := List.getElem_of_eq ht ccDec_aux_zero_idx
839-
simp at ht
840-
exact (ccDec_aux_nonempty_head _ _ _ hw) ht
841-
simp [ccDec_aux, ht]
842-
cases c_head with
843-
| nil => simp at hch
844-
| cons b c_head =>
845-
simp
846-
by_cases hab : dependencyTransClosureInL I u a b
847-
· simp [hab]
848-
sorry
849-
/- induction c_tail using List.reverseRecOn with
850-
| nil => simp
851-
| append_singleton c_tail d ih2 =>
852-
simp
853-
rw [List.getLast_congr ht] at ih -/
854-
· simp [hab]
855-
sorry
805+
nth_rw 3 [<- ccDec_aux_flatten I u w]
806+
exact List.flatten_suffix (ccDec_aux I u w) (ccDec_aux_nonempty u w)
856807

857808
lemma ccDec_across_infix (I : Independence α) (w : List α) (h : 1 < (ccDec I w).length) :
858809
List.IsInfix (
@@ -999,25 +950,6 @@ lemma ccDec_aux_adj_indep (u w : List α) (i : ℕ) (hi : i + 1 < (ccDec_aux I u
999950
intro p hp q hq
1000951
sorry
1001952

1002-
lemma ccDec_aux_flatten (u w : List α) :
1003-
(ccDec_aux I u w).flatten = w := by
1004-
induction w with
1005-
| nil => simp [ccDec_aux]
1006-
| cons a w ih =>
1007-
simp [ccDec_aux]
1008-
let t := ccDec_aux I u w
1009-
have ht : ccDec_aux I u w = t := rfl
1010-
rcases t
1011-
· exfalso
1012-
exact (ccDec_aux_nonempty _ _) ht
1013-
· rename_i c_head c_tail
1014-
simp [ht] at ih ⊢
1015-
cases c_head with
1016-
| nil => simp at ih ⊢; exact ih
1017-
| cons b c_head =>
1018-
by_cases hab : dependencyTransClosureInL I u a b
1019-
all_goals simp [hab] at ih ⊢; exact ih
1020-
1021953
lemma ccDec_disconnected_len (w : List α) (h : ¬ IsConnectedL I w) :
1022954
(ccDec I w).length ≥ 2 := by
1023955
by_contra h_len
@@ -1046,6 +978,17 @@ lemma ccDec_disconnected_len (w : List α) (h : ¬ IsConnectedL I w) :
1046978

1047979
variable [Fintype α] [LinearOrder α] [DecidableRel I.rel]
1048980

981+
omit [Fintype α] [DecidableRel I.rel] in
982+
lemma lexNf_infix_is_lexNf {s t : List α} (hst : List.IsInfix s t) (ht : IsLexNf I t) :
983+
IsLexNf I s := by
984+
apply (isLexNf_iff_factorCondition _ _).mp at ht
985+
apply (isLexNf_iff_factorCondition _ _).mpr
986+
replace ⟨s', s'', hst⟩ := hst
987+
intro y u z a b hs
988+
replace ht := ht (s' ++ y) u (z ++ s'') a b
989+
simp [<- hst, hs] at ht
990+
exact ht
991+
1049992
lemma lexNf_sq_is_lexNf {w : List α} (h : w ++ w ∈ LexNfLanguage I) :
1050993
w ∈ LexNfLanguage I := by
1051994
apply (mem_lexNfLanguage_iff_factorCondition _ _).mp at h
@@ -1070,6 +1013,68 @@ lemma connected_of_lexNf_sq {w : List α}
10701013
have hz : w ≠ [] := List.cons_ne_nil a w'
10711014
rw [show a :: w' = w from rfl] at hw hww ⊢
10721015
by_contra h_con
1016+
replace h_con := ccDec_disconnected_len _ h_con
1017+
1018+
have h_lt : ∀ (i : ℕ), ∀ (hi : i + 1 < (ccDec_aux I w w).length),
1019+
(ccDec_aux I w w)[i][0]'(List.length_pos_iff.mpr (ccDec_aux_elem_nonempty w w i (Nat.lt_of_succ_lt hi) hz)) <
1020+
((ccDec_aux I w w)[i + 1][0]'(List.length_pos_iff.mpr (ccDec_aux_elem_nonempty w w (i + 1) hi hz))) := by
1021+
intro i hi
1022+
have h_infix := ccDec_aux_infix I w w i hi
1023+
apply (mem_lexNfLanguage_iff_factorCondition _ _).mp at hw
1024+
apply (isLexNf_iff_factorCondition _ _).mpr at hw
1025+
replace h_infix := lexNf_infix_is_lexNf h_infix hw
1026+
apply (isLexNf_iff_factorCondition _ _).mp at h_infix
1027+
1028+
have h_indep : Independent I (ccDec_aux I w w)[i] (ccDec_aux I w w)[i + 1] := ccDec_aux_adj_indep w w i hi
1029+
1030+
let t₁ := (ccDec_aux I w w)[i]
1031+
have ht₁ : (ccDec_aux I w w)[i] = t₁ := rfl
1032+
rcases t₁
1033+
· exfalso
1034+
exact (ccDec_aux_elem_nonempty _ _ _ _ hz) ht₁
1035+
rename_i a₁ s₁
1036+
1037+
let t₂ := (ccDec_aux I w w)[i + 1]
1038+
have ht₂ : (ccDec_aux I w w)[i + 1] = t₂ := rfl
1039+
rcases t₂
1040+
· exfalso
1041+
exact (ccDec_aux_elem_nonempty _ _ _ _ hz) ht₂
1042+
rename_i a₂ s₂
1043+
1044+
replace h_infix := h_infix [] s₁ s₂ a₂ a₁
1045+
simp [ht₁, ht₂] at h_infix h_indep
1046+
simp [List.getElem_of_eq ht₁, List.getElem_of_eq ht₂]
1047+
replace h_infix := h_infix (I.symm _ _ h_indep.1.1)
1048+
1049+
by_contra h_ge
1050+
have h_ne : a₁ ≠ a₂ := by
1051+
by_contra h_eq
1052+
rw [h_eq] at h_indep
1053+
exact (I.irrefl _) h_indep.1.1
1054+
have h_gt : a₂ < a₁ := by
1055+
simp at h_ge
1056+
exact Std.lt_of_le_of_ne h_ge (Ne.symm h_ne)
1057+
1058+
replace ⟨c, hcs, hac⟩ := h_infix h_gt
1059+
exact hac (I.symm _ _ (h_indep.2 c hcs).1)
1060+
1061+
replace h_lt : ∀ (i : ℕ), ∀ (hi : i + 1 < (ccDec_aux I w w).length),
1062+
(ccDec_aux I w w)[i][0]'(List.length_pos_iff.mpr (ccDec_aux_elem_nonempty w w i (Nat.lt_of_succ_lt hi) hz)) <
1063+
((ccDec_aux I w w)[(ccDec_aux I w w).length - 1][0]'(List.length_pos_iff.mpr (ccDec_aux_elem_nonempty w w ((ccDec_aux I w w).length - 1) (Nat.sub_one_lt_of_lt h_con) hz))) := by
1064+
intro i hi
1065+
replace hi : i < (ccDec_aux I w w).length - 1 := Nat.lt_sub_of_add_lt hi
1066+
replace hi : i ≤ (ccDec_aux I w w).length - 1 := Nat.le_of_succ_le hi
1067+
induction hi using Nat.decreasingInduction with
1068+
| self =>
1069+
replace hi : (ccDec_aux I w w).length = 0 := by
1070+
contrapose hi
1071+
simp
1072+
exact le_tsub_add
1073+
exfalso
1074+
exact (ccDec_aux_nonempty _ _) (List.eq_nil_iff_length_eq_zero.mpr hi)
1075+
| of_succ k h ih =>
1076+
sorry
1077+
10731078
sorry
10741079

10751080
lemma connected_of_lexNf_sq' {w : List α}

0 commit comments

Comments
 (0)