@@ -585,7 +585,18 @@ lemma group_split_factors_aux {n : ℕ} {X : Language α} [DecidableEq α]
585585 omega
586586 · simp only [List.zipWith_cons_cons, List.flatten_cons]
587587 unfold traceClosure at h_zip_in ⊢
588- sorry
588+ rw [Set.mem_setOf] at h_zip_in ⊢
589+ rcases h_zip_in with ⟨x, hx, hx_eqv⟩
590+ rw [Language.mem_kstar] at hx
591+ rcases hx with ⟨L, hL, hLX⟩
592+ have hpq_append_in_X := by simpa using hpq_in_X 0 (by omega)
593+ use p ++ q ++ x
594+ constructor
595+ · rw [Language.mem_kstar]
596+ use [p ++ q] ++ L
597+ simp [hL, hpq_append_in_X]
598+ exact hLX
599+ · exact TraceEqv.compat (TraceEqv.refl _) hx_eqv
589600 · simp only [List.flatten_cons]
590601 exact TraceEqv.compat (TraceEqv.refl _) h_ps_eqv
591602 · simp only [List.flatten_cons]
@@ -613,18 +624,143 @@ lemma group_split_factors_aux {n : ℕ} {X : Language α} [DecidableEq α]
613624 simp only [List.getElem_cons_succ]
614625 exact h_xs_indep i' j' (by simpa using hi) (by simpa using hj) (by omega)
615626 · rcases xs' with _ | ⟨x_head, xs_tail⟩
616- · sorry
627+ · have h_ys_nil : ys' = [] := by
628+ cases ys'
629+ · rfl
630+ · contradiction
631+ subst h_ys_nil
632+ use [p], [q]
633+ and_intros
634+ · rfl
635+ · simp only [List.length_singleton]; omega
636+ · simp only [List.zipWith_cons_cons, List.zipWith_self, List.map_nil, List.flatten_cons,
637+ List.flatten_nil, List.append_nil]
638+ unfold traceClosure
639+ rw [Set.mem_setOf]
640+ have hpq_append_in_X := by simpa using hpq_in_X 0 (by omega)
641+ use p ++ q
642+ constructor
643+ · rw [Language.mem_kstar]
644+ use [p ++ q]
645+ simp [hpq_append_in_X]
646+ · exact TraceEqv.refl _
647+ · simp only [List.flatten_cons, List.flatten_nil, List.append_nil]
648+ have h1 : TraceEqv I (p ++ ps'.flatten) (p ++ []) := TraceEqv.compat (TraceEqv.refl _) h_ps_eqv
649+ rw [List.append_nil] at h1
650+ exact h1
651+ · simp only [List.flatten_cons, List.flatten_nil, List.append_nil]
652+ have h1 : TraceEqv I (q ++ qs'.flatten) (q ++ []) := TraceEqv.compat (TraceEqv.refl _) h_qs_eqv
653+ rw [List.append_nil] at h1
654+ exact h1
655+ · intro i j hi hj hlt
656+ simp only [List.length_cons, List.length_nil, zero_add, Nat.lt_one_iff] at hi hj
657+ omega
617658 rcases ys' with _ | ⟨y_head, ys_tail⟩
618- · sorry
619-
620- use ((p ++ x_head) :: xs_tail), ((q ++ y_head) :: ys_tail)
621-
622- -- To prove the zip is in traceClosure I (X*):
623- -- 1. The new zipped head is `p ++ x_head ++ q ++ y_head`.
624- -- 2. Because `q` is independent of `x_head` (from h_indep), this is equivalent to `p ++ q ++ x_head ++ y_head`.
625- -- 3. `p ++ q` is in X, and `x_head ++ y_head` (attached to the tail) is in traceClosure I (X*) from the IH.
626- -- 4. Therefore, the whole sequence belongs to traceClosure I (X*).
627- sorry
659+ · simp at h_len_eq
660+ use (p ++ x_head) :: xs_tail, (q ++ y_head) :: ys_tail
661+ and_intros
662+ · simpa using h_len_eq
663+ · simp only [List.length_cons]
664+ have h_S_eq : Finset.univ.filter (fun (i : Fin (n' + 1 )) => (p :: ps')[i.val] ≠ [] ∧ (q :: qs')[i.val] ≠ []) =
665+ (Finset.univ.filter (fun (i : Fin n') => ps'[i.val] ≠ [] ∧ qs'[i.val] ≠ [])).image Fin.succ := by
666+ ext x
667+ simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_image]
668+ cases x using Fin.cases with
669+ | zero =>
670+ simp only [Fin.val_zero, List.getElem_cons_zero]
671+ apply iff_of_false
672+ · exact h_split
673+ · rintro ⟨y, hy, h_eq⟩
674+ exact Fin.succ_ne_zero y h_eq
675+ | succ x' =>
676+ simp only [Fin.val_succ, List.getElem_cons_succ]
677+ constructor
678+ · intro h
679+ exact ⟨x', h, rfl⟩
680+ · rintro ⟨y, hy, h_eq⟩
681+ injection h_eq with h_eq
682+ simp only [Nat.add_right_cancel_iff] at h_eq
683+ simp_rw [← h_eq]
684+ exact hy
685+ have h_card : (Finset.univ.filter (fun (i : Fin (n' + 1 )) => (p :: ps')[i.val] ≠ [] ∧ (q :: qs')[i.val] ≠ [])).card =
686+ (Finset.univ.filter (fun (i : Fin n') => ps'[i.val] ≠ [] ∧ qs'[i.val] ≠ [])).card := by
687+ rw [h_S_eq, Finset.card_image_of_injective _ (Fin.succ_injective _)]
688+ rw [h_card]
689+ exact h_bound
690+ · simp only [List.zipWith_cons_cons, List.flatten_cons]
691+ unfold traceClosure at h_zip_in ⊢
692+ rw [Set.mem_setOf] at h_zip_in ⊢
693+ rcases h_zip_in with ⟨x, hx, hx_eqv⟩
694+ have hpq_append_in_X := by simpa using hpq_in_X 0 (by omega)
695+ use p ++ q ++ x
696+ constructor
697+ · rw [Language.mem_kstar] at hx ⊢
698+ rcases hx with ⟨L, hL, hLX⟩
699+ use [p ++ q] ++ L
700+ simp [hL, hpq_append_in_X]
701+ exact hLX
702+ · have hq_ps_flat : Independent I q ps'.flatten := by
703+ intro a ha b hb
704+ simp only [List.mem_flatten] at hb
705+ rcases hb with ⟨p_k, hp_k_in, hb_in⟩
706+ rcases List.mem_iff_getElem.mp hp_k_in with ⟨k, hk_lt, rfl⟩
707+ exact h_indep 0 (k + 1 ) (by omega) (by omega) (by omega) a ha b hb_in
708+ have hq_xs_flat := indep_of_indep_of_eqv hq_ps_flat h_ps_eqv
709+ have hq_xhead : Independent I q x_head := by
710+ intro a ha b hb
711+ have hb_flat : b ∈ (x_head :: xs_tail).flatten := by
712+ simp only [List.flatten_cons, List.mem_append]
713+ exact Or.inl hb
714+ exact hq_xs_flat a ha b hb_flat
715+ have h_list_eq1 : (((p ++ x_head) ++ (q ++ y_head)) ++ (List.zipWith (fun x1 x2 => x1 ++ x2) xs_tail ys_tail).flatten) =
716+ (p ++ ((x_head ++ q) ++ y_head) ++ (List.zipWith (fun x1 x2 => x1 ++ x2) xs_tail ys_tail).flatten) := by simp
717+ rw [h_list_eq1]
718+ have h_swap : TraceEqv I (x_head ++ q) (q ++ x_head) := (comm_append_of_indep hq_xhead).symm
719+ have h_swap2 : TraceEqv I ((x_head ++ q) ++ y_head) ((q ++ x_head) ++ y_head) := TraceEqv.compat h_swap (TraceEqv.refl _)
720+ have h_swap3 : TraceEqv I (p ++ ((x_head ++ q) ++ y_head)) (p ++ ((q ++ x_head) ++ y_head)) := TraceEqv.compat (TraceEqv.refl _) h_swap2
721+ have h_swap4 : TraceEqv I ((p ++ ((x_head ++ q) ++ y_head)) ++ (List.zipWith (fun x1 x2 => x1 ++ x2) xs_tail ys_tail).flatten)
722+ ((p ++ ((q ++ x_head) ++ y_head)) ++ (List.zipWith (fun x1 x2 => x1 ++ x2) xs_tail ys_tail).flatten) :=
723+ TraceEqv.compat h_swap3 (TraceEqv.refl _)
724+ have h_list_eq2 : (p ++ ((q ++ x_head) ++ y_head) ++ (List.zipWith (fun x1 x2 => x1 ++ x2) xs_tail ys_tail).flatten) =
725+ ((p ++ q) ++ ((x_head ++ y_head) ++ (List.zipWith (fun x1 x2 => x1 ++ x2) xs_tail ys_tail).flatten)) := by simp
726+ have h_final : TraceEqv I ((p ++ q) ++ ((x_head ++ y_head) ++ (List.zipWith (fun x1 x2 => x1 ++ x2) xs_tail ys_tail).flatten))
727+ ((p ++ q) ++ x) := TraceEqv.compat (TraceEqv.refl _) hx_eqv.symm
728+ rw [h_list_eq2] at h_swap4
729+ exact h_final.symm.trans h_swap4.symm
730+ · simp only [List.flatten_cons]
731+ rw [List.append_assoc]
732+ exact TraceEqv.compat (TraceEqv.refl _) h_ps_eqv
733+ · simp only [List.flatten_cons]
734+ rw [List.append_assoc]
735+ exact TraceEqv.compat (TraceEqv.refl _) h_qs_eqv
736+ · intro i j hi hj hlt
737+ cases i with
738+ | zero =>
739+ cases j with
740+ | zero => contradiction
741+ | succ j' =>
742+ simp only [List.getElem_cons_zero, List.getElem_cons_succ]
743+ intro a ha b hb
744+ simp only [List.mem_append] at ha
745+ rcases ha with ha | ha
746+ · have hq_ps_flat : Independent I q ps'.flatten := by
747+ intro a' ha' b' hb'
748+ simp only [List.mem_flatten] at hb'
749+ rcases hb' with ⟨p_k, hp_k_in, hb_in⟩
750+ rcases List.mem_iff_getElem.mp hp_k_in with ⟨k, hk_lt, rfl⟩
751+ exact h_indep 0 (k + 1 ) (by omega) (by omega) (by omega) a' ha' b' hb_in
752+ have hq_xs_flat : Independent I q (x_head :: xs_tail).flatten :=
753+ indep_of_indep_of_eqv hq_ps_flat h_ps_eqv
754+ have hq_xstail := indep_of_flatten (j' + 1 ) (by simpa using hj) hq_xs_flat
755+ exact hq_xstail a ha b hb
756+ · have hy_indep := h_xs_indep 0 (j' + 1 ) (by simp) (by simpa using hj) (by omega)
757+ exact hy_indep a ha b hb
758+ | succ i' =>
759+ cases j with
760+ | zero => contradiction
761+ | succ j' =>
762+ simp only [List.getElem_cons_succ]
763+ exact h_xs_indep (i' + 1 ) (j' + 1 ) (by simpa using hi) (by simpa using hj) (by omega)
628764
629765lemma group_split_factors
630766 {x y : List α} {X : Language α} {n : ℕ} {ps qs : List (List α)} [Fintype α] [DecidableEq α]
0 commit comments