import Mathlib /-! # Kripke Structures, Bisimulation Invariance, Hennessy–Milner Theorem & LTL/CTL Incomparability This standalone Lean 4 module formalizes Pillars 1 and 2 of our Formal Verification, Temporal Logic, Modal μ-Calculus & Parity Games development: 1. **Labeled Transition Systems (LTS) & Bisimulation:** - Cross-bisimulation (`IsCrossBisim`), self-bisimulation (`IsBisimulation`), and largest bisimulation (`Bisimilar`), proved to be an equivalence relation and exact greatest fixpoint `OrderHom.gfp (bisimF M)` (`bisimilar_eq_gfp`). - Hennessy–Milner / Basic Modal Logic (`HML A P`), exact **Bisimulation Invariance** (`bisimulation_invariance_hml`), the **Hennessy–Milner Theorem** on image-finite LTSs (`hennessy_milner_theorem`), and an explicit **infinite-branching counterexample** proving image-finiteness is strictly necessary (`hennessy_milner_requires_image_finite`). 2. **LTL & CTL Semantics, Fixpoint Characterizations & Exact Expressive Incomparability:** - Infinite-trace **LTL** (`LTL P`) with exact duality/expansion laws (`ltl_duality_and_expansion_laws`) and trace-equivalence invariance (`trace_equiv_implies_ltl_equiv`). - Branching-time **CTL** (`CTL P`) with full bisimulation invariance (`bisimulation_invariance_ctl`) and exact Knaster–Tarski fixpoint characterizations of `EF`, `EG`, `AF`, `AG`, `EU`, `AU` on arbitrary serial Kripke structures (`ctl_fixpoint_characterizations`). - **CTL ⊈ LTL (`ctl_not_subsumed_by_ltl`):** Two explicit finite serial Kripke structures with identical infinite trace sets (`resetKripke` vs. `trapKripke`) separated by `AG (EF p)`, proving no LTL formula is equivalent to `AG (EF p)`. - **LTL ⊈ CTL (`ltl_FG_not_expressible_in_ctl`):** The Clarke–Draghicescu / Emerson–Halpern theorem proving that LTL persistence `◇□ p` (`FG p`) is not expressible in CTL, via an explicit family of finite serial Kripke structures `cdModel k` and `cdModelPrime k` that agree on all CTL formulas of nesting depth `≤ k` (`cd_ctl_depth_equiv`) yet are separated by `FG p` for every `k ≥ 1`. -/ namespace FormalVerification /-! ## Section 1: Labeled Transition Systems & Greatest-Fixpoint Bisimulation -/ /-- A Labeled Transition System (LTS) with state space `S`, action labels `A`, and atomic propositions `P`. Setting `A = Unit` yields a Kripke structure. -/ structure LTS (S A P : Type*) where step : S → A → S → Prop val : S → P → Prop /-- A cross-bisimulation between two LTSs over the same actions `A` and atoms `P`. -/ def IsCrossBisim {S₁ S₂ A P : Type*} (M₁ : LTS S₁ A P) (M₂ : LTS S₂ A P) (R : S₁ → S₂ → Prop) : Prop := ∀ s₁ s₂, R s₁ s₂ → (∀ p, M₁.val s₁ p ↔ M₂.val s₂ p) ∧ (∀ a s₁', M₁.step s₁ a s₁' → ∃ s₂', M₂.step s₂ a s₂' ∧ R s₁' s₂') ∧ (∀ a s₂', M₂.step s₂ a s₂' → ∃ s₁', M₁.step s₁ a s₁' ∧ R s₁' s₂') /-- A bisimulation relation on a single LTS `M`. -/ def IsBisimulation {S A P : Type*} (M : LTS S A P) (R : S → S → Prop) : Prop := IsCrossBisim M M R /-- Largest cross-bisimulation (coinductive union of all cross-bisimulations). -/ def CrossBisimilar {S₁ S₂ A P : Type*} (M₁ : LTS S₁ A P) (M₂ : LTS S₂ A P) (s₁ : S₁) (s₂ : S₂) : Prop := ∃ R, IsCrossBisim M₁ M₂ R ∧ R s₁ s₂ /-- Largest bisimulation on a single LTS `M`. -/ def Bisimilar {S A P : Type*} (M : LTS S A P) (s t : S) : Prop := CrossBisimilar M M s t lemma isCrossBisim_symm {S₁ S₂ A P : Type*} {M₁ : LTS S₁ A P} {M₂ : LTS S₂ A P} {R : S₁ → S₂ → Prop} (hR : IsCrossBisim M₁ M₂ R) : IsCrossBisim M₂ M₁ (fun s₂ s₁ => R s₁ s₂) := by intro s₂ s₁ h rcases hR s₁ s₂ h with ⟨hval, hzig, hzag⟩ refine ⟨fun p => (hval p).symm, ?_, ?_⟩ · intro a s₂' hstep rcases hzag a s₂' hstep with ⟨s₁', hs₁', hR'⟩ exact ⟨s₁', hs₁', hR'⟩ · intro a s₁' hstep rcases hzig a s₁' hstep with ⟨s₂', hs₂', hR'⟩ exact ⟨s₂', hs₂', hR'⟩ lemma isCrossBisim_comp {S₁ S₂ S₃ A P : Type*} {M₁ : LTS S₁ A P} {M₂ : LTS S₂ A P} {M₃ : LTS S₃ A P} {R₁ : S₁ → S₂ → Prop} {R₂ : S₂ → S₃ → Prop} (h₁ : IsCrossBisim M₁ M₂ R₁) (h₂ : IsCrossBisim M₂ M₃ R₂) : IsCrossBisim M₁ M₃ (fun s₁ s₃ => ∃ s₂, R₁ s₁ s₂ ∧ R₂ s₂ s₃) := by intro s₁ s₃ ⟨s₂, hr₁, hr₂⟩ rcases h₁ s₁ s₂ hr₁ with ⟨hv₁, hzig₁, hzag₁⟩ rcases h₂ s₂ s₃ hr₂ with ⟨hv₂, hzig₂, hzag₂⟩ refine ⟨fun p => (hv₁ p).trans (hv₂ p), ?_, ?_⟩ · intro a s₁' hs₁' rcases hzig₁ a s₁' hs₁' with ⟨s₂', hs₂', hr₁'⟩ rcases hzig₂ a s₂' hs₂' with ⟨s₃', hs₃', hr₂'⟩ exact ⟨s₃', hs₃', s₂', hr₁', hr₂'⟩ · intro a s₃' hs₃' rcases hzag₂ a s₃' hs₃' with ⟨s₂', hs₂', hr₂'⟩ rcases hzag₁ a s₂' hs₂' with ⟨s₁', hs₁', hr₁'⟩ exact ⟨s₁', hs₁', s₂', hr₁', hr₂'⟩ lemma bisimilar_refl {S A P : Type*} (M : LTS S A P) (s : S) : Bisimilar M s s := by refine ⟨Eq, ?_, rfl⟩ intro x y hxy subst hxy exact ⟨fun _ => Iff.rfl, fun a s' hs' => ⟨s', hs', rfl⟩, fun a s' hs' => ⟨s', hs', rfl⟩⟩ lemma bisimilar_symm {S A P : Type*} {M : LTS S A P} {s t : S} (h : Bisimilar M s t) : Bisimilar M t s := by rcases h with ⟨R, hR, hst⟩ exact ⟨fun x y => R y x, isCrossBisim_symm hR, hst⟩ lemma bisimilar_trans {S A P : Type*} {M : LTS S A P} {s t u : S} (h₁ : Bisimilar M s t) (h₂ : Bisimilar M t u) : Bisimilar M s u := by rcases h₁ with ⟨R₁, hR₁, hst⟩ rcases h₂ with ⟨R₂, hR₂, htu⟩ exact ⟨fun x z => ∃ y, R₁ x y ∧ R₂ y z, isCrossBisim_comp hR₁ hR₂, t, hst, htu⟩ lemma crossBisimilar_isCrossBisim {S₁ S₂ A P : Type*} (M₁ : LTS S₁ A P) (M₂ : LTS S₂ A P) : IsCrossBisim M₁ M₂ (CrossBisimilar M₁ M₂) := by intro s₁ s₂ ⟨R, hR, hst⟩ rcases hR s₁ s₂ hst with ⟨hval, hzig, hzag⟩ refine ⟨hval, ?_, ?_⟩ · intro a s₁' hs₁' rcases hzig a s₁' hs₁' with ⟨s₂', hs₂', hr'⟩ exact ⟨s₂', hs₂', R, hR, hr'⟩ · intro a s₂' hs₂' rcases hzag a s₂' hs₂' with ⟨s₁', hs₁', hr'⟩ exact ⟨s₁', hs₁', R, hR, hr'⟩ lemma bisimilar_isBisimulation {S A P : Type*} (M : LTS S A P) : IsBisimulation M (Bisimilar M) := crossBisimilar_isCrossBisim M M /-- The monotone bisimulation functional on binary relations `S → S → Prop`. -/ def bisimF {S A P : Type*} (M : LTS S A P) : (S → S → Prop) →o (S → S → Prop) where toFun R s t := (∀ p, M.val s p ↔ M.val t p) ∧ (∀ a s', M.step s a s' → ∃ t', M.step t a t' ∧ R s' t') ∧ (∀ a t', M.step t a t' → ∃ s', M.step s a s' ∧ R s' t') monotone' := by intro R₁ R₂ hle s t ⟨hval, hzig, hzag⟩ refine ⟨hval, ?_, ?_⟩ · intro a s' hs' rcases hzig a s' hs' with ⟨t', ht', hr⟩ exact ⟨t', ht', hle s' t' hr⟩ · intro a t' ht' rcases hzag a t' ht' with ⟨s', hs', hr⟩ exact ⟨s', hs', hle s' t' hr⟩ lemma isBisimulation_iff_le_bisimF {S A P : Type*} (M : LTS S A P) (R : S → S → Prop) : IsBisimulation M R ↔ R ≤ bisimF M R := Iff.rfl /-- **Greatest Fixpoint Characterization of Bisimilarity:** `Bisimilar M` is equal to the Knaster–Tarski greatest fixpoint `OrderHom.gfp (bisimF M)`. -/ theorem bisimilar_eq_gfp {S A P : Type*} (M : LTS S A P) : Bisimilar M = OrderHom.gfp (bisimF M) := by apply le_antisymm · exact OrderHom.le_gfp (bisimF M) (bisimilar_isBisimulation M) · intro s t hst refine ⟨OrderHom.gfp (bisimF M), ?_, hst⟩ change IsBisimulation M (OrderHom.gfp (bisimF M)) rw [isBisimulation_iff_le_bisimF, OrderHom.map_gfp] /-! ## Section 2: Hennessy–Milner Logic, Bisimulation Invariance & Hennessy–Milner Theorem -/ /-- Basic Modal / Hennessy–Milner Logic over actions `A` and atomic propositions `P`. -/ inductive HML (A P : Type*) : Type _ | tt : HML A P | ff : HML A P | atom (p : P) : HML A P | neg (φ : HML A P) : HML A P | and (φ ψ : HML A P) : HML A P | or (φ ψ : HML A P) : HML A P | dia (a : A) (φ : HML A P) : HML A P | box (a : A) (φ : HML A P) : HML A P /-- Satisfaction semantics of Hennessy–Milner Logic on an LTS. -/ def HML.Sat {S A P : Type*} (M : LTS S A P) : S → HML A P → Prop | _, .tt => True | _, .ff => False | s, .atom p => M.val s p | s, .neg φ => ¬ HML.Sat M s φ | s, .and φ ψ => HML.Sat M s φ ∧ HML.Sat M s ψ | s, .or φ ψ => HML.Sat M s φ ∨ HML.Sat M s ψ | s, .dia a φ => ∃ s', M.step s a s' ∧ HML.Sat M s' φ | s, .box a φ => ∀ s', M.step s a s' → HML.Sat M s' φ /-- Modal nesting depth of an HML formula. -/ def HML.depth {A P : Type*} : HML A P → ℕ | .tt | .ff | .atom _ => 0 | .neg φ => φ.depth | .and φ ψ | .or φ ψ => max φ.depth ψ.depth | .dia _ φ | .box _ φ => φ.depth + 1 /-- Finite conjunction of a list of HML formulas. -/ def HML.conj {A P : Type*} : List (HML A P) → HML A P | [] => .tt | φ :: L => .and φ (HML.conj L) lemma HML.sat_conj {S A P : Type*} (M : LTS S A P) (s : S) (L : List (HML A P)) : HML.Sat M s (HML.conj L) ↔ ∀ φ ∈ L, HML.Sat M s φ := by induction L with | nil => simp [HML.conj, HML.Sat] | cons φ L ih => simp [HML.conj, HML.Sat, ih] /-- Modal equivalence: two states satisfy the exact same HML formulas. -/ def HMLEquiv {S A P : Type*} (M : LTS S A P) (s t : S) : Prop := ∀ φ : HML A P, HML.Sat M s φ ↔ HML.Sat M t φ /-- Image-finiteness: every state has only finitely many `a`-successors for each action `a`. -/ def ImageFinite {S A P : Type*} (M : LTS S A P) : Prop := ∀ s a, Set.Finite {s' | M.step s a s'} lemma isCrossBisim_implies_hml_equiv {S₁ S₂ A P : Type*} {M₁ : LTS S₁ A P} {M₂ : LTS S₂ A P} {R : S₁ → S₂ → Prop} (hR : IsCrossBisim M₁ M₂ R) (φ : HML A P) : ∀ s₁ s₂, R s₁ s₂ → (HML.Sat M₁ s₁ φ ↔ HML.Sat M₂ s₂ φ) := by induction φ with | tt => intro _ _ _; exact Iff.rfl | ff => intro _ _ _; exact Iff.rfl | atom p => intro s₁ s₂ h; exact (hR s₁ s₂ h).1 p | neg φ ih => intro s₁ s₂ h; exact not_congr (ih s₁ s₂ h) | and φ ψ ih₁ ih₂ => intro s₁ s₂ h; exact and_congr (ih₁ s₁ s₂ h) (ih₂ s₁ s₂ h) | or φ ψ ih₁ ih₂ => intro s₁ s₂ h; exact or_congr (ih₁ s₁ s₂ h) (ih₂ s₁ s₂ h) | dia a φ ih => intro s₁ s₂ h rcases hR s₁ s₂ h with ⟨_, hzig, hzag⟩ constructor · rintro ⟨s₁', hs₁', hsat⟩ rcases hzig a s₁' hs₁' with ⟨s₂', hs₂', hr'⟩ exact ⟨s₂', hs₂', (ih s₁' s₂' hr').mp hsat⟩ · rintro ⟨s₂', hs₂', hsat⟩ rcases hzag a s₂' hs₂' with ⟨s₁', hs₁', hr'⟩ exact ⟨s₁', hs₁', (ih s₁' s₂' hr').mpr hsat⟩ | box a φ ih => intro s₁ s₂ h rcases hR s₁ s₂ h with ⟨_, hzig, hzag⟩ constructor · intro hbox s₂' hs₂' rcases hzag a s₂' hs₂' with ⟨s₁', hs₁', hr'⟩ exact (ih s₁' s₂' hr').mp (hbox s₁' hs₁') · intro hbox s₁' hs₁' rcases hzig a s₁' hs₁' with ⟨s₂', hs₂', hr'⟩ exact (ih s₁' s₂' hr').mpr (hbox s₂' hs₂') /-- **Bisimulation Invariance of Hennessy–Milner / Basic Modal Logic:** Cross-bisimilar states satisfy the exact same modal formulas. -/ theorem bisimulation_invariance_hml {S₁ S₂ A P : Type*} {M₁ : LTS S₁ A P} {M₂ : LTS S₂ A P} {s₁ : S₁} {s₂ : S₂} (h : CrossBisimilar M₁ M₂ s₁ s₂) (φ : HML A P) : HML.Sat M₁ s₁ φ ↔ HML.Sat M₂ s₂ φ := by rcases h with ⟨R, hR, hr⟩ exact isCrossBisim_implies_hml_equiv hR φ s₁ s₂ hr lemma exists_separating_hml {S A P : Type*} {M : LTS S A P} {s t : S} (hne : ¬ HMLEquiv M s t) : ∃ ψ : HML A P, HML.Sat M s ψ ∧ ¬ HML.Sat M t ψ := by unfold HMLEquiv at hne push Not at hne rcases hne with ⟨φ, ⟨hs, hnt⟩ | ⟨hns, ht⟩⟩ · exact ⟨φ, hs, hnt⟩ · exact ⟨.neg φ, hns, not_not.mpr ht⟩ lemma hmlEquiv_isBisimulation_of_imageFinite {S A P : Type*} {M : LTS S A P} (hFin : ImageFinite M) : IsBisimulation M (HMLEquiv M) := by intro s t heq refine ⟨fun p => heq (.atom p), ?_, ?_⟩ · intro a s' hs' by_contra hno push Not at hno let T : Finset S := (hFin t a).toFinset have hsep : ∀ t' ∈ T, ∃ ψ : HML A P, HML.Sat M s' ψ ∧ ¬ HML.Sat M t' ψ := by intro t' ht' have hstep : M.step t a t' := (Set.Finite.mem_toFinset _).mp ht' exact exists_separating_hml (hno t' hstep) choose sep hsep_s hsep_t using hsep let L : List (HML A P) := T.attach.toList.map (fun x => sep x.1 x.2) have hs_dia : HML.Sat M s (.dia a (HML.conj L)) := by refine ⟨s', hs', (HML.sat_conj M s' L).mpr ?_⟩ intro φ hφ rw [List.mem_map] at hφ rcases hφ with ⟨⟨t', ht'⟩, _, rfl⟩ exact hsep_s t' ht' have ht_dia : HML.Sat M t (.dia a (HML.conj L)) := (heq (.dia a (HML.conj L))).mp hs_dia rcases ht_dia with ⟨t', ht'_step, ht'_conj⟩ have ht'_mem : t' ∈ T := (Set.Finite.mem_toFinset _).mpr ht'_step have hmem_L : sep t' ht'_mem ∈ L := by rw [List.mem_map] exact ⟨⟨t', ht'_mem⟩, Finset.mem_toList.mpr (Finset.mem_attach T ⟨t', ht'_mem⟩), rfl⟩ exact hsep_t t' ht'_mem ((HML.sat_conj M t' L).mp ht'_conj _ hmem_L) · intro a t' ht' by_contra hno push Not at hno let T : Finset S := (hFin s a).toFinset have hsep : ∀ s' ∈ T, ∃ ψ : HML A P, HML.Sat M t' ψ ∧ ¬ HML.Sat M s' ψ := by intro s' hs' have hstep : M.step s a s' := (Set.Finite.mem_toFinset _).mp hs' exact exists_separating_hml (fun h => hno s' hstep (fun φ => (h φ).symm)) choose sep hsep_t hsep_s using hsep let L : List (HML A P) := T.attach.toList.map (fun x => sep x.1 x.2) have ht_dia : HML.Sat M t (.dia a (HML.conj L)) := by refine ⟨t', ht', (HML.sat_conj M t' L).mpr ?_⟩ intro φ hφ rw [List.mem_map] at hφ rcases hφ with ⟨⟨s', hs'⟩, _, rfl⟩ exact hsep_t s' hs' have hs_dia : HML.Sat M s (.dia a (HML.conj L)) := (heq (.dia a (HML.conj L))).mpr ht_dia rcases hs_dia with ⟨s', hs'_step, hs'_conj⟩ have hs'_mem : s' ∈ T := (Set.Finite.mem_toFinset _).mpr hs'_step have hmem_L : sep s' hs'_mem ∈ L := by rw [List.mem_map] exact ⟨⟨s', hs'_mem⟩, Finset.mem_toList.mpr (Finset.mem_attach T ⟨s', hs'_mem⟩), rfl⟩ exact hsep_s s' hs'_mem ((HML.sat_conj M s' L).mp hs'_conj _ hmem_L) /-- **The Hennessy–Milner Theorem:** On any image-finite LTS, HML modal equivalence coincides exactly with bisimilarity. -/ theorem hennessy_milner_theorem {S A P : Type*} {M : LTS S A P} (hFin : ImageFinite M) (s t : S) : HMLEquiv M s t ↔ Bisimilar M s t := by constructor · intro heq exact ⟨HMLEquiv M, hmlEquiv_isBisimulation_of_imageFinite hFin, heq⟩ · intro hbis φ exact bisimulation_invariance_hml hbis φ /-! ### Exact Infinite-Branching Counterexample to Hennessy–Milner without Image-Finiteness -/ /-- State space of the infinite-branching Hennessy–Milner counterexample: `rootA` branches to `finChain n` for all `n : ℕ`; `rootB` branches to `finChain n` for all `n : ℕ` AND to the self-loop `omega`. -/ inductive InfState : Type | rootA : InfState | rootB : InfState | omega : InfState | finChain (n : ℕ) : InfState deriving DecidableEq /-- The infinite-branching LTS separating modal equivalence from bisimilarity. -/ def infBranchLTS : LTS InfState Unit Empty where step s _ t := match s, t with | .rootA, .finChain _ => True | .rootB, .finChain _ => True | .rootB, .omega => True | .omega, .omega => True | .finChain (n + 1), .finChain m => m = n | _, _ => False val _ p := p.elim lemma omega_finChain_depth_equiv (d : ℕ) : ∀ φ : HML Unit Empty, φ.depth ≤ d → (HML.Sat infBranchLTS .omega φ ↔ HML.Sat infBranchLTS (.finChain d) φ) := by induction d with | zero => intro φ hdep induction φ with | tt => exact Iff.rfl | ff => exact Iff.rfl | atom p => exact p.elim | neg φ ih => exact not_congr (ih hdep) | and φ ψ ih₁ ih₂ => simp only [HML.depth, max_le_iff] at hdep exact and_congr (ih₁ hdep.1) (ih₂ hdep.2) | or φ ψ ih₁ ih₂ => simp only [HML.depth, max_le_iff] at hdep exact or_congr (ih₁ hdep.1) (ih₂ hdep.2) | dia _ _ => simp [HML.depth] at hdep | box _ _ => simp [HML.depth] at hdep | succ d ih_d => intro φ hdep induction φ with | tt => exact Iff.rfl | ff => exact Iff.rfl | atom p => exact p.elim | neg φ ih => exact not_congr (ih hdep) | and φ ψ ih₁ ih₂ => simp only [HML.depth, max_le_iff] at hdep exact and_congr (ih₁ hdep.1) (ih₂ hdep.2) | or φ ψ ih₁ ih₂ => simp only [HML.depth, max_le_iff] at hdep exact or_congr (ih₁ hdep.1) (ih₂ hdep.2) | dia a ψ _ => have hψ : ψ.depth ≤ d := Nat.le_of_succ_le_succ hdep constructor · rintro ⟨s', hs', hsat⟩ cases s' with | omega => exact ⟨.finChain d, rfl, (ih_d ψ hψ).mp hsat⟩ | rootA | rootB | finChain _ => cases hs' · rintro ⟨s', hs', hsat⟩ cases s' with | finChain m => change m = d at hs' subst hs' exact ⟨.omega, trivial, (ih_d ψ hψ).mpr hsat⟩ | rootA | rootB | omega => cases hs' | box a ψ _ => have hψ : ψ.depth ≤ d := Nat.le_of_succ_le_succ hdep constructor · intro hbox s' hs' cases s' with | finChain m => change m = d at hs' subst hs' exact (ih_d ψ hψ).mp (hbox .omega trivial) | rootA | rootB | omega => cases hs' · intro hbox s' hs' cases s' with | omega => exact (ih_d ψ hψ).mpr (hbox (.finChain d) rfl) | rootA | rootB | finChain _ => cases hs' lemma rootA_rootB_hmlEquiv : HMLEquiv infBranchLTS .rootA .rootB := by intro φ induction φ with | tt => exact Iff.rfl | ff => exact Iff.rfl | atom p => exact p.elim | neg φ ih => exact not_congr ih | and φ ψ ih₁ ih₂ => exact and_congr ih₁ ih₂ | or φ ψ ih₁ ih₂ => exact or_congr ih₁ ih₂ | dia a ψ _ => constructor · rintro ⟨s', hs', hsat⟩ cases s' with | finChain n => exact ⟨.finChain n, trivial, hsat⟩ | rootA | rootB | omega => cases hs' · rintro ⟨s', hs', hsat⟩ cases s' with | finChain n => exact ⟨.finChain n, trivial, hsat⟩ | omega => exact ⟨.finChain ψ.depth, trivial, (omega_finChain_depth_equiv ψ.depth ψ le_rfl).mp hsat⟩ | rootA | rootB => cases hs' | box a ψ _ => constructor · intro hbox s' hs' cases s' with | finChain n => exact hbox (.finChain n) trivial | omega => exact (omega_finChain_depth_equiv ψ.depth ψ le_rfl).mpr (hbox (.finChain ψ.depth) trivial) | rootA | rootB => cases hs' · intro hbox s' hs' cases s' with | finChain n => exact hbox (.finChain n) trivial | rootA | rootB | omega => cases hs' lemma finChain_not_bisim_omega : ∀ n : ℕ, ¬ Bisimilar infBranchLTS (.finChain n) .omega := by intro n induction n with | zero => rintro ⟨R, hR, hr⟩ rcases (hR (.finChain 0) .omega hr).2.2 () .omega trivial with ⟨s', hs', _⟩ cases s' <;> cases hs' | succ n ih => rintro ⟨R, hR, hr⟩ rcases (hR (.finChain (n + 1)) .omega hr).2.2 () .omega trivial with ⟨s', hs', hr'⟩ cases s' with | finChain m => change m = n at hs' subst hs' exact ih ⟨R, hR, hr'⟩ | rootA | rootB | omega => cases hs' lemma rootA_not_bisim_rootB : ¬ Bisimilar infBranchLTS .rootA .rootB := by rintro ⟨R, hR, hr⟩ rcases (hR .rootA .rootB hr).2.2 () .omega trivial with ⟨s', hs', hr'⟩ cases s' with | finChain n => exact finChain_not_bisim_omega n ⟨R, hR, hr'⟩ | rootA | rootB | omega => cases hs' lemma infBranchLTS_not_imageFinite : ¬ ImageFinite infBranchLTS := by intro hFin have hinf : Set.Infinite {s' | infBranchLTS.step .rootA () s'} := by refine Set.infinite_of_injective_forall_mem (f := InfState.finChain) ?_ ?_ · intro m n h; cases h; rfl · intro n; trivial exact hinf (hFin .rootA ()) /-- **Strict Necessity of Image-Finiteness in Hennessy–Milner:** There exists an infinite-branching LTS (`infBranchLTS`) with states `rootA`, `rootB` that are HML-equivalent yet NOT bisimilar (and the LTS is explicitly non-image-finite). -/ theorem hennessy_milner_requires_image_finite : HMLEquiv infBranchLTS .rootA .rootB ∧ ¬ Bisimilar infBranchLTS .rootA .rootB ∧ ¬ ImageFinite infBranchLTS := ⟨rootA_rootB_hmlEquiv, rootA_not_bisim_rootB, infBranchLTS_not_imageFinite⟩ /-! ## Section 3: Kripke Structures, LTL & CTL Semantics and Fixpoints -/ /-- An unlabeled Kripke structure `(S, step, val)` over atomic propositions `P`. -/ structure Kripke (S P : Type*) where step : S → S → Prop val : S → P → Prop /-- Convert a Kripke structure to a single-action LTS. -/ def Kripke.toLTS {S P : Type*} (K : Kripke S P) : LTS S Unit P where step s _ t := K.step s t val := K.val /-- Seriality (left-totality): every state has at least one successor. -/ def IsSerial {S P : Type*} (K : Kripke S P) : Prop := ∀ s, ∃ t, K.step s t /-- An infinite path in a Kripke structure `K`. -/ def IsPath {S P : Type*} (K : Kripke S P) (π : ℕ → S) : Prop := ∀ n, K.step (π n) (π (n + 1)) /-- The infinite trace (sequence of atomic valuations) induced by path `π`. -/ def trace {S P : Type*} (K : Kripke S P) (π : ℕ → S) : ℕ → P → Prop := fun n p => K.val (π n) p /-- The set of all infinite traces starting from state `s` in `K`. -/ def TraceSet {S P : Type*} (K : Kripke S P) (s : S) : Set (ℕ → P → Prop) := {τ | ∃ π, IsPath K π ∧ π 0 = s ∧ trace K π = τ} /-- Suffix shift of a sequence by `k` steps. -/ def shift {α : Type*} (f : ℕ → α) (k : ℕ) : ℕ → α := fun n => f (n + k) lemma shift_zero {α : Type*} (f : ℕ → α) : shift f 0 = f := by funext n; simp [shift] lemma shift_add {α : Type*} (f : ℕ → α) (k m : ℕ) : shift (shift f k) m = shift f (m + k) := by funext n; simp [shift, Nat.add_assoc] lemma isPath_shift {S P : Type*} {K : Kripke S P} {π : ℕ → S} (hπ : IsPath K π) (k : ℕ) : IsPath K (shift π k) := by intro n simpa [shift, Nat.add_right_comm] using hπ (n + k) lemma trace_shift {S P : Type*} (K : Kripke S P) (π : ℕ → S) (k : ℕ) : trace K (shift π k) = shift (trace K π) k := rfl lemma exists_path_from {S P : Type*} {K : Kripke S P} (hSer : IsSerial K) (s : S) : ∃ π, IsPath K π ∧ π 0 = s := by choose next hnext using hSer refine ⟨fun n => next^[n] s, ?_, rfl⟩ intro n show K.step (next^[n] s) (next^[n + 1] s) rw [Function.iterate_succ_apply'] exact hnext (next^[n] s) /-! ### Linear Temporal Logic (LTL) -/ /-- Syntax of Linear Temporal Logic (LTL) over atomic propositions `P`. -/ inductive LTL (P : Type*) : Type _ | tt : LTL P | atom (p : P) : LTL P | neg (φ : LTL P) : LTL P | and (φ ψ : LTL P) : LTL P | next (φ : LTL P) : LTL P | until (φ ψ : LTL P) : LTL P def LTL.or {P : Type*} (φ ψ : LTL P) : LTL P := .neg (.and (.neg φ) (.neg ψ)) def LTL.F {P : Type*} (φ : LTL P) : LTL P := .until .tt φ def LTL.G {P : Type*} (φ : LTL P) : LTL P := .neg (LTL.F (.neg φ)) def LTL.release {P : Type*} (φ ψ : LTL P) : LTL P := .neg (.until (.neg φ) (.neg ψ)) /-- Infinite-trace satisfaction semantics of LTL. -/ def LTL.SatTrace {P : Type*} : (ℕ → P → Prop) → LTL P → Prop | _, .tt => True | τ, .atom p => τ 0 p | τ, .neg φ => ¬ LTL.SatTrace τ φ | τ, .and φ ψ => LTL.SatTrace τ φ ∧ LTL.SatTrace τ ψ | τ, .next φ => LTL.SatTrace (shift τ 1) φ | τ, .until φ ψ => ∃ i, LTL.SatTrace (shift τ i) ψ ∧ ∀ j < i, LTL.SatTrace (shift τ j) φ /-- Universal state satisfaction semantics of LTL on a Kripke structure. -/ def LTL.SatState {S P : Type*} (K : Kripke S P) (s : S) (φ : LTL P) : Prop := ∀ π, IsPath K π → π 0 = s → LTL.SatTrace (trace K π) φ lemma LTL.satTrace_or {P : Type*} (τ : ℕ → P → Prop) (φ ψ : LTL P) : LTL.SatTrace τ (LTL.or φ ψ) ↔ LTL.SatTrace τ φ ∨ LTL.SatTrace τ ψ := by simp [LTL.or, LTL.SatTrace, or_iff_not_and_not] lemma LTL.satTrace_F {P : Type*} (τ : ℕ → P → Prop) (φ : LTL P) : LTL.SatTrace τ (LTL.F φ) ↔ ∃ i, LTL.SatTrace (shift τ i) φ := by simp [LTL.F, LTL.SatTrace] lemma LTL.satTrace_G {P : Type*} (τ : ℕ → P → Prop) (φ : LTL P) : LTL.SatTrace τ (LTL.G φ) ↔ ∀ i, LTL.SatTrace (shift τ i) φ := by simp [LTL.G, LTL.satTrace_F, LTL.SatTrace] /-- **Exact LTL Duality, Expansion, Persistence (`FG`) & Recurrence (`GF`) Laws.** -/ theorem ltl_duality_and_expansion_laws {P : Type*} (τ : ℕ → P → Prop) (φ ψ : LTL P) : (LTL.SatTrace τ (LTL.G φ) ↔ ¬ LTL.SatTrace τ (LTL.F (.neg φ))) ∧ (LTL.SatTrace τ (LTL.F φ) ↔ ¬ LTL.SatTrace τ (LTL.G (.neg φ))) ∧ (LTL.SatTrace τ (.until φ ψ) ↔ LTL.SatTrace τ ψ ∨ (LTL.SatTrace τ φ ∧ LTL.SatTrace τ (.next (.until φ ψ)))) ∧ (LTL.SatTrace τ (LTL.F φ) ↔ LTL.SatTrace τ φ ∨ LTL.SatTrace τ (.next (LTL.F φ))) ∧ (LTL.SatTrace τ (LTL.G φ) ↔ LTL.SatTrace τ φ ∧ LTL.SatTrace τ (.next (LTL.G φ))) ∧ (LTL.SatTrace τ (LTL.F (LTL.G φ)) ↔ ∃ n, ∀ m ≥ n, LTL.SatTrace (shift τ m) φ) ∧ (LTL.SatTrace τ (LTL.G (LTL.F φ)) ↔ ∀ n, ∃ m ≥ n, LTL.SatTrace (shift τ m) φ) := by refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · simp [LTL.G, LTL.SatTrace] · simp [LTL.satTrace_F, LTL.satTrace_G, LTL.SatTrace] · constructor · rintro ⟨i, hi, hj⟩ cases i with | zero => left; simpa [shift_zero] using hi | succ i => right refine ⟨by simpa [shift_zero] using hj 0 (Nat.zero_lt_succ i), i, ?_, ?_⟩ · simpa [shift_add] using hi · intro j hji simpa [shift_add] using hj (j + 1) (Nat.succ_lt_succ hji) · rintro (hψ | ⟨hφ, i, hi, hj⟩) · exact ⟨0, by simpa [shift_zero] using hψ, fun j hj => by omega⟩ · refine ⟨i + 1, by simpa [shift_add] using hi, ?_⟩ intro j hji cases j with | zero => simpa [shift_zero] using hφ | succ j => simpa [shift_add] using hj j (Nat.lt_of_succ_lt_succ hji) · rw [LTL.satTrace_F] constructor · rintro ⟨i, hi⟩ cases i with | zero => left; simpa [shift_zero] using hi | succ i => right; rw [LTL.SatTrace, LTL.satTrace_F]; exact ⟨i, by simpa [shift_add] using hi⟩ · rintro (h0 | hnext) · exact ⟨0, by simpa [shift_zero] using h0⟩ · rw [LTL.SatTrace, LTL.satTrace_F] at hnext rcases hnext with ⟨i, hi⟩ exact ⟨i + 1, by simpa [shift_add] using hi⟩ · rw [LTL.satTrace_G] constructor · intro h refine ⟨by simpa [shift_zero] using h 0, ?_⟩ rw [LTL.SatTrace, LTL.satTrace_G] intro i simpa [shift_add] using h (i + 1) · rintro ⟨h0, hnext⟩ i rw [LTL.SatTrace, LTL.satTrace_G] at hnext cases i with | zero => simpa [shift_zero] using h0 | succ i => simpa [shift_add] using hnext i · simp only [LTL.satTrace_F, LTL.satTrace_G, shift_add] constructor · rintro ⟨n, hn⟩ refine ⟨n, fun m hm => ?_⟩ have h := hn (m - n) rwa [Nat.sub_add_cancel hm] at h · rintro ⟨n, hn⟩ exact ⟨n, fun k => hn (k + n) (Nat.le_add_left n k)⟩ · simp only [LTL.satTrace_G, LTL.satTrace_F, shift_add] constructor · intro h n rcases h n with ⟨k, hk⟩ exact ⟨k + n, Nat.le_add_left n k, hk⟩ · intro h n rcases h n with ⟨m, hmn, hm⟩ exact ⟨m - n, by rwa [Nat.sub_add_cancel hmn]⟩ /-- **Trace-Equivalence Invariance of LTL:** If two states in two Kripke structures have identical infinite trace sets, they satisfy the exact same LTL formulas. -/ theorem trace_equiv_implies_ltl_equiv {S₁ S₂ P : Type*} {K₁ : Kripke S₁ P} {K₂ : Kripke S₂ P} {s₁ : S₁} {s₂ : S₂} (htr : TraceSet K₁ s₁ = TraceSet K₂ s₂) (φ : LTL P) : LTL.SatState K₁ s₁ φ ↔ LTL.SatState K₂ s₂ φ := by constructor · intro h₁ π₂ hπ₂ h0 have hmem : trace K₂ π₂ ∈ TraceSet K₁ s₁ := by rw [htr]; exact ⟨π₂, hπ₂, h0, rfl⟩ rcases hmem with ⟨π₁, hπ₁, h0₁, heq⟩ rw [← heq] exact h₁ π₁ hπ₁ h0₁ · intro h₂ π₁ hπ₁ h0 have hmem : trace K₁ π₁ ∈ TraceSet K₂ s₂ := by rw [← htr]; exact ⟨π₁, hπ₁, h0, rfl⟩ rcases hmem with ⟨π₂, hπ₂, h0₂, heq⟩ rw [← heq] exact h₂ π₂ hπ₂ h0₂ /-! ### Computation Tree Logic (CTL) -/ /-- Complete syntax basis for Computation Tree Logic (CTL) over atomic propositions `P`. -/ inductive CTL (P : Type*) : Type _ | tt : CTL P | atom (p : P) : CTL P | neg (φ : CTL P) : CTL P | and (φ ψ : CTL P) : CTL P | EX (φ : CTL P) : CTL P | EU (φ ψ : CTL P) : CTL P | AU (φ ψ : CTL P) : CTL P def CTL.or {P : Type*} (φ ψ : CTL P) : CTL P := .neg (.and (.neg φ) (.neg ψ)) def CTL.AX {P : Type*} (φ : CTL P) : CTL P := .neg (.EX (.neg φ)) def CTL.EF {P : Type*} (φ : CTL P) : CTL P := .EU .tt φ def CTL.AF {P : Type*} (φ : CTL P) : CTL P := .AU .tt φ def CTL.EG {P : Type*} (φ : CTL P) : CTL P := .neg (CTL.AF (.neg φ)) def CTL.AG {P : Type*} (φ : CTL P) : CTL P := .neg (CTL.EF (.neg φ)) /-- Temporal operator nesting depth of a CTL formula. -/ def CTL.depth {P : Type*} : CTL P → ℕ | .tt | .atom _ => 0 | .neg φ => φ.depth | .and φ ψ => max φ.depth ψ.depth | .EX φ => φ.depth + 1 | .EU φ ψ | .AU φ ψ => max φ.depth ψ.depth + 1 /-- Branching-time path semantics of CTL on a Kripke structure. -/ def CTL.Sat {S P : Type*} (K : Kripke S P) : S → CTL P → Prop | _, .tt => True | s, .atom p => K.val s p | s, .neg φ => ¬ CTL.Sat K s φ | s, .and φ ψ => CTL.Sat K s φ ∧ CTL.Sat K s ψ | s, .EX φ => ∃ t, K.step s t ∧ CTL.Sat K t φ | s, .EU φ ψ => ∃ π, IsPath K π ∧ π 0 = s ∧ ∃ i, CTL.Sat K (π i) ψ ∧ ∀ j < i, CTL.Sat K (π j) φ | s, .AU φ ψ => ∀ π, IsPath K π → π 0 = s → ∃ i, CTL.Sat K (π i) ψ ∧ ∀ j < i, CTL.Sat K (π j) φ lemma CTL.sat_AX {S P : Type*} (K : Kripke S P) (s : S) (φ : CTL P) : CTL.Sat K s (CTL.AX φ) ↔ ∀ t, K.step s t → CTL.Sat K t φ := by simp [CTL.AX, CTL.Sat] lemma CTL.sat_EF {S P : Type*} (K : Kripke S P) (s : S) (φ : CTL P) : CTL.Sat K s (CTL.EF φ) ↔ ∃ π, IsPath K π ∧ π 0 = s ∧ ∃ i, CTL.Sat K (π i) φ := by simp [CTL.EF, CTL.Sat] lemma CTL.sat_AF {S P : Type*} (K : Kripke S P) (s : S) (φ : CTL P) : CTL.Sat K s (CTL.AF φ) ↔ ∀ π, IsPath K π → π 0 = s → ∃ i, CTL.Sat K (π i) φ := by simp [CTL.AF, CTL.Sat] lemma CTL.sat_EG {S P : Type*} (K : Kripke S P) (s : S) (φ : CTL P) : CTL.Sat K s (CTL.EG φ) ↔ ∃ π, IsPath K π ∧ π 0 = s ∧ ∀ i, CTL.Sat K (π i) φ := by simp [CTL.EG, CTL.sat_AF, CTL.Sat] lemma CTL.sat_AG {S P : Type*} (K : Kripke S P) (s : S) (φ : CTL P) : CTL.Sat K s (CTL.AG φ) ↔ ∀ π, IsPath K π → π 0 = s → ∀ i, CTL.Sat K (π i) φ := by simp [CTL.AG, CTL.sat_EF, CTL.Sat] /-! ### Bisimulation Invariance of CTL -/ lemma lift_path_crossBisim {S₁ S₂ P : Type*} {K₁ : Kripke S₁ P} {K₂ : Kripke S₂ P} {R : S₁ → S₂ → Prop} (hR : IsCrossBisim K₁.toLTS K₂.toLTS R) {π₁ : ℕ → S₁} (hπ₁ : IsPath K₁ π₁) {s₂ : S₂} (hr0 : R (π₁ 0) s₂) : ∃ π₂, IsPath K₂ π₂ ∧ π₂ 0 = s₂ ∧ ∀ n, R (π₁ n) (π₂ n) := by have hstep : ∀ n (x : {s // R (π₁ n) s}), ∃ y : {s // R (π₁ (n + 1)) s}, K₂.step x.1 y.1 := by intro n ⟨x, hx⟩ rcases (hR (π₁ n) x hx).2.1 () (π₁ (n + 1)) (hπ₁ n) with ⟨y, hxy, hy⟩ exact ⟨⟨y, hy⟩, hxy⟩ choose f hf using hstep let seq : ∀ n, {s // R (π₁ n) s} := Nat.rec ⟨s₂, hr0⟩ (fun n prev => f n prev) refine ⟨fun n => (seq n).1, ?_, rfl, fun n => (seq n).2⟩ intro n exact hf n (seq n) lemma isCrossBisim_implies_ctl_equiv {S₁ S₂ P : Type*} {K₁ : Kripke S₁ P} {K₂ : Kripke S₂ P} {R : S₁ → S₂ → Prop} (hR : IsCrossBisim K₁.toLTS K₂.toLTS R) (φ : CTL P) : ∀ s₁ s₂, R s₁ s₂ → (CTL.Sat K₁ s₁ φ ↔ CTL.Sat K₂ s₂ φ) := by induction φ with | tt => intro _ _ _; exact Iff.rfl | atom p => intro s₁ s₂ h; exact (hR s₁ s₂ h).1 p | neg φ ih => intro s₁ s₂ h; exact not_congr (ih s₁ s₂ h) | and φ ψ ih₁ ih₂ => intro s₁ s₂ h; exact and_congr (ih₁ s₁ s₂ h) (ih₂ s₁ s₂ h) | EX φ ih => intro s₁ s₂ h rcases hR s₁ s₂ h with ⟨_, hzig, hzag⟩ constructor · rintro ⟨t₁, ht₁, hsat⟩ rcases hzig () t₁ ht₁ with ⟨t₂, ht₂, hr'⟩ exact ⟨t₂, ht₂, (ih t₁ t₂ hr').mp hsat⟩ · rintro ⟨t₂, ht₂, hsat⟩ rcases hzag () t₂ ht₂ with ⟨t₁, ht₁, hr'⟩ exact ⟨t₁, ht₁, (ih t₁ t₂ hr').mpr hsat⟩ | EU φ ψ ih₁ ih₂ => intro s₁ s₂ h constructor · rintro ⟨π₁, hπ₁, h0, i, hi, hj⟩ subst h0 rcases lift_path_crossBisim hR hπ₁ h with ⟨π₂, hπ₂, h0₂, hrel⟩ exact ⟨π₂, hπ₂, h0₂, i, (ih₂ _ _ (hrel i)).mp hi, fun j hji => (ih₁ _ _ (hrel j)).mp (hj j hji)⟩ · rintro ⟨π₂, hπ₂, h0, i, hi, hj⟩ subst h0 rcases lift_path_crossBisim (isCrossBisim_symm hR) hπ₂ h with ⟨π₁, hπ₁, h0₁, hrel⟩ exact ⟨π₁, hπ₁, h0₁, i, (ih₂ _ _ (hrel i)).mpr hi, fun j hji => (ih₁ _ _ (hrel j)).mpr (hj j hji)⟩ | AU φ ψ ih₁ ih₂ => intro s₁ s₂ h constructor · intro hau π₂ hπ₂ h0 subst h0 rcases lift_path_crossBisim (isCrossBisim_symm hR) hπ₂ h with ⟨π₁, hπ₁, h0₁, hrel⟩ rcases hau π₁ hπ₁ h0₁ with ⟨i, hi, hj⟩ exact ⟨i, (ih₂ _ _ (hrel i)).mp hi, fun j hji => (ih₁ _ _ (hrel j)).mp (hj j hji)⟩ · intro hau π₁ hπ₁ h0 subst h0 rcases lift_path_crossBisim hR hπ₁ h with ⟨π₂, hπ₂, h0₂, hrel⟩ rcases hau π₂ hπ₂ h0₂ with ⟨i, hi, hj⟩ exact ⟨i, (ih₂ _ _ (hrel i)).mpr hi, fun j hji => (ih₁ _ _ (hrel j)).mpr (hj j hji)⟩ /-- **Bisimulation Invariance of CTL:** Cross-bisimilar states satisfy the exact same CTL formulas. -/ theorem bisimulation_invariance_ctl {S₁ S₂ P : Type*} {K₁ : Kripke S₁ P} {K₂ : Kripke S₂ P} {s₁ : S₁} {s₂ : S₂} (h : CrossBisimilar K₁.toLTS K₂.toLTS s₁ s₂) (φ : CTL P) : CTL.Sat K₁ s₁ φ ↔ CTL.Sat K₂ s₂ φ := by rcases h with ⟨R, hR, hr⟩ exact isCrossBisim_implies_ctl_equiv hR φ s₁ s₂ hr /-! ### Exact Knaster–Tarski Fixpoint Characterizations of CTL Operators -/ /-- Existential predecessor operator `Pre_∃(X)`. -/ def preE {S P : Type*} (K : Kripke S P) (X : Set S) : Set S := {s | ∃ t, K.step s t ∧ t ∈ X} /-- Universal predecessor operator `Pre_∀(X)`. -/ def preA {S P : Type*} (K : Kripke S P) (X : Set S) : Set S := {s | ∀ t, K.step s t → t ∈ X} /-- Monotone fixpoint operator for `EU(A, B)`: `X ↦ B ∪ (A ∩ Pre_∃(X))`. -/ def euOp {S P : Type*} (K : Kripke S P) (A B : Set S) : Set S →o Set S where toFun X := B ∪ (A ∩ preE K X) monotone' _ _ hle _ hx := by rcases hx with hb | ⟨ha, t, hst, ht⟩ · exact Or.inl hb · exact Or.inr ⟨ha, t, hst, hle ht⟩ /-- Monotone fixpoint operator for `AU(A, B)`: `X ↦ B ∪ (A ∩ Pre_∀(X))`. -/ def auOp {S P : Type*} (K : Kripke S P) (A B : Set S) : Set S →o Set S where toFun X := B ∪ (A ∩ preA K X) monotone' _ _ hle _ hx := by rcases hx with hb | ⟨ha, hpre⟩ · exact Or.inl hb · exact Or.inr ⟨ha, fun t hst => hle (hpre t hst)⟩ /-- Monotone fixpoint operator for `EG(A)`: `X ↦ A ∩ Pre_∃(X)`. -/ def egOp {S P : Type*} (K : Kripke S P) (A : Set S) : Set S →o Set S where toFun X := A ∩ preE K X monotone' := by intro _ _ hle _ hx rcases hx with ⟨ha, t, hst, ht⟩ exact ⟨ha, t, hst, hle ht⟩ /-- Monotone fixpoint operator for `AG(A)`: `X ↦ A ∩ Pre_∀(X)`. -/ def agOp {S P : Type*} (K : Kripke S P) (A : Set S) : Set S →o Set S where toFun X := A ∩ preA K X monotone' := by intro _ _ hle _ hx rcases hx with ⟨ha, hpre⟩ exact ⟨ha, fun t hst => hle (hpre t hst)⟩ lemma eu_eq_lfp {S P : Type*} {K : Kripke S P} (hSer : IsSerial K) (φ ψ : CTL P) : {s | CTL.Sat K s (.EU φ ψ)} = OrderHom.lfp (euOp K {s | CTL.Sat K s φ} {s | CTL.Sat K s ψ}) := by let A := {s | CTL.Sat K s φ} let B := {s | CTL.Sat K s ψ} ext s constructor · rintro ⟨π, hπ, rfl, i, hi, hj⟩ induction i generalizing π with | zero => rw [← OrderHom.map_lfp] exact Or.inl hi | succ i ih => have htail : π 1 ∈ OrderHom.lfp (euOp K A B) := by apply ih (shift π 1) (isPath_shift hπ 1) · simpa [shift] using hi · intro j hji simpa [shift] using hj (j + 1) (Nat.succ_lt_succ hji) rw [← OrderHom.map_lfp] exact Or.inr ⟨hj 0 (Nat.zero_lt_succ i), π 1, hπ 0, htail⟩ · intro hs have hpre : euOp K A B {x | CTL.Sat K x (.EU φ ψ)} ⊆ {x | CTL.Sat K x (.EU φ ψ)} := by intro x hx rcases hx with hψ | ⟨hφ, t, hxt, ⟨π, hπ, h0, i, hi, hj⟩⟩ · rcases exists_path_from hSer x with ⟨π, hπ, h0⟩ exact ⟨π, hπ, h0, 0, by rwa [h0], fun j hj => by omega⟩ · let π' : ℕ → S := fun n => match n with | 0 => x | k + 1 => π k refine ⟨π', ?_, rfl, i + 1, hi, ?_⟩ · intro n cases n with | zero => simpa [π', h0] using hxt | succ k => exact hπ k · intro j hji cases j with | zero => exact hφ | succ k => exact hj k (Nat.lt_of_succ_lt_succ hji) exact OrderHom.lfp_le (euOp K A B) hpre hs lemma au_eq_lfp {S P : Type*} {K : Kripke S P} (hSer : IsSerial K) (φ ψ : CTL P) : {s | CTL.Sat K s (.AU φ ψ)} = OrderHom.lfp (auOp K {s | CTL.Sat K s φ} {s | CTL.Sat K s ψ}) := by let A := {s | CTL.Sat K s φ} let B := {s | CTL.Sat K s ψ} let Z := OrderHom.lfp (auOp K A B) ext s constructor · intro hau by_contra hs_not have hstep : ∀ x, x ∉ Z → ¬ CTL.Sat K x ψ ∧ (CTL.Sat K x φ → ∃ y, K.step x y ∧ y ∉ Z) := by intro x hx have hx' : x ∉ auOp K A B Z := by rwa [OrderHom.map_lfp] refine ⟨fun hψ => hx' (Or.inl hψ), fun hφ => ?_⟩ by_contra hno push Not at hno exact hx' (Or.inr ⟨hφ, hno⟩) classical choose defNext hdefNext using hSer let nextState : S → S := fun x => if h : x ∉ Z ∧ CTL.Sat K x φ then Classical.choose ((hstep x h.1).2 h.2) else defNext x have hnext_step : ∀ x, K.step x (nextState x) := by intro x dsimp only [nextState] split_ifs with h · exact (Classical.choose_spec ((hstep x h.1).2 h.2)).1 · exact hdefNext x let π : ℕ → S := fun n => nextState^[n] s have hπ : IsPath K π := by intro n show K.step (nextState^[n] s) (nextState^[n + 1] s) rw [Function.iterate_succ_apply'] exact hnext_step _ rcases hau π hπ rfl with ⟨i, hi, hj⟩ have hinv : ∀ k ≤ i, π k ∉ Z := by intro k hk induction k with | zero => exact hs_not | succ k ih => have hk_lt : k < i := Nat.lt_of_succ_le hk have hkz : π k ∉ Z := ih (Nat.le_of_lt hk_lt) have hkφ : CTL.Sat K (π k) φ := hj k hk_lt show nextState^[k + 1] s ∉ Z rw [Function.iterate_succ_apply'] dsimp only [nextState] rw [dif_pos ⟨hkz, hkφ⟩] exact (Classical.choose_spec ((hstep (π k) hkz).2 hkφ)).2 exact (hstep (π i) (hinv i le_rfl)).1 hi · intro hs have hpre : auOp K A B {x | CTL.Sat K x (.AU φ ψ)} ⊆ {x | CTL.Sat K x (.AU φ ψ)} := by intro x hx π hπ h0 rcases hx with hψ | ⟨hφ, hall⟩ · exact ⟨0, by rwa [h0], fun j hj => by omega⟩ · have h1 : K.step x (π 1) := by simpa [h0] using hπ 0 rcases hall (π 1) h1 (shift π 1) (isPath_shift hπ 1) rfl with ⟨i, hi, hj⟩ refine ⟨i + 1, by simpa [shift] using hi, ?_⟩ intro j hji cases j with | zero => rwa [h0] | succ k => simpa [shift] using hj k (Nat.lt_of_succ_lt_succ hji) exact OrderHom.lfp_le (auOp K A B) hpre hs lemma eg_eq_gfp {S P : Type*} (K : Kripke S P) (φ : CTL P) : {s | CTL.Sat K s (CTL.EG φ)} = OrderHom.gfp (egOp K {s | CTL.Sat K s φ}) := by let A := {s | CTL.Sat K s φ} let Z := OrderHom.gfp (egOp K A) ext s constructor · intro h have hpost : {x | CTL.Sat K x (CTL.EG φ)} ⊆ egOp K A {x | CTL.Sat K x (CTL.EG φ)} := by intro x hx rw [Set.mem_ofPred_eq, CTL.sat_EG] at hx rcases hx with ⟨π, hπ, h0, hall⟩ refine ⟨by simpa [A, h0] using hall 0, π 1, by simpa [h0] using hπ 0, ?_⟩ rw [Set.mem_ofPred_eq, CTL.sat_EG] exact ⟨shift π 1, isPath_shift hπ 1, rfl, fun i => hall (i + 1)⟩ exact OrderHom.le_gfp (egOp K A) hpost h · intro hs rw [Set.mem_ofPred_eq, CTL.sat_EG] have hstep : ∀ x : {x // x ∈ Z}, ∃ y : {x // x ∈ Z}, K.step x.1 y.1 := by intro ⟨x, hx⟩ have hx' : x ∈ egOp K A Z := by rwa [OrderHom.map_gfp] rcases hx'.2 with ⟨y, hxy, hy⟩ exact ⟨⟨y, hy⟩, hxy⟩ choose f hf using hstep let seq : ℕ → {x // x ∈ Z} := fun n => f^[n] ⟨s, hs⟩ refine ⟨fun n => (seq n).1, ?_, rfl, ?_⟩ · intro n show K.step (f^[n] ⟨s, hs⟩).1 (f^[n + 1] ⟨s, hs⟩).1 rw [Function.iterate_succ_apply'] exact hf _ · intro n have hmem : (seq n).1 ∈ egOp K A Z := by rw [OrderHom.map_gfp]; exact (seq n).2 exact hmem.1 lemma ag_eq_gfp {S P : Type*} {K : Kripke S P} (hSer : IsSerial K) (φ : CTL P) : {s | CTL.Sat K s (CTL.AG φ)} = OrderHom.gfp (agOp K {s | CTL.Sat K s φ}) := by let A := {s | CTL.Sat K s φ} let Z := OrderHom.gfp (agOp K A) ext s constructor · intro h have hpost : {x | CTL.Sat K x (CTL.AG φ)} ⊆ agOp K A {x | CTL.Sat K x (CTL.AG φ)} := by intro x hx rw [Set.mem_ofPred_eq, CTL.sat_AG] at hx refine ⟨?_, ?_⟩ · rcases exists_path_from hSer x with ⟨π, hπ, h0⟩ simpa [A, h0] using hx π hπ h0 0 · intro t hxt rw [Set.mem_ofPred_eq, CTL.sat_AG] intro π hπ h0 i let π' : ℕ → S := fun n => match n with | 0 => x | k + 1 => π k have hπ' : IsPath K π' := by intro n cases n with | zero => simpa [π', h0] using hxt | succ k => exact hπ k simpa [π'] using hx π' hπ' rfl (i + 1) exact OrderHom.le_gfp (agOp K A) hpost h · intro hs rw [Set.mem_ofPred_eq, CTL.sat_AG] intro π hπ h0 i have hmem : ∀ n, π n ∈ Z := by intro n induction n with | zero => rwa [h0] | succ n ih => have hstep : π n ∈ agOp K A Z := by rwa [OrderHom.map_gfp] exact hstep.2 (π (n + 1)) (hπ n) have hi : π i ∈ agOp K A Z := by rw [OrderHom.map_gfp]; exact hmem i exact hi.1 /-- **Exact Knaster–Tarski Fixpoint Characterizations of All CTL Temporal Operators:** On any serial Kripke structure, `EU`, `AU`, `EF`, `AF`, `EG`, and `AG` coincide with their canonical least (`lfp`) and greatest (`gfp`) fixpoints on `Set S`. -/ theorem ctl_fixpoint_characterizations {S P : Type*} {K : Kripke S P} (hSer : IsSerial K) (φ ψ : CTL P) : ({s | CTL.Sat K s (.EU φ ψ)} = OrderHom.lfp (euOp K {s | CTL.Sat K s φ} {s | CTL.Sat K s ψ})) ∧ ({s | CTL.Sat K s (.AU φ ψ)} = OrderHom.lfp (auOp K {s | CTL.Sat K s φ} {s | CTL.Sat K s ψ})) ∧ ({s | CTL.Sat K s (CTL.EF φ)} = OrderHom.lfp (euOp K Set.univ {s | CTL.Sat K s φ})) ∧ ({s | CTL.Sat K s (CTL.AF φ)} = OrderHom.lfp (auOp K Set.univ {s | CTL.Sat K s φ})) ∧ ({s | CTL.Sat K s (CTL.EG φ)} = OrderHom.gfp (egOp K {s | CTL.Sat K s φ})) ∧ ({s | CTL.Sat K s (CTL.AG φ)} = OrderHom.gfp (agOp K {s | CTL.Sat K s φ})) := by refine ⟨eu_eq_lfp hSer φ ψ, au_eq_lfp hSer φ ψ, ?_, ?_, eg_eq_gfp K φ, ag_eq_gfp hSer φ⟩ · simpa [CTL.EF, CTL.Sat, Set.ofPred_true] using eu_eq_lfp hSer .tt φ · simpa [CTL.AF, CTL.Sat, Set.ofPred_true] using au_eq_lfp hSer .tt φ /-! ## Section 4: Exact LTL vs. CTL Expressive Incomparability -/ /-! ### Part 4A: `CTL ⊈ LTL` — `AG EF p` Is Not Expressible in LTL -/ inductive ResetState : Type | a | b deriving DecidableEq inductive TrapState : Type | a | b | dead deriving DecidableEq /-- 2-state complete Kripke structure where `p` holds at `a` and can always be reset. -/ def resetKripke : Kripke ResetState Unit where step _ _ := True val s _ := s = .a /-- 3-state Kripke structure with identical traces from `a`, plus an absorbing `¬p`-trap `dead`. -/ def trapKripke : Kripke TrapState Unit where step s t := match s, t with | .a, _ => True | .b, .a => True | .b, .b => True | .dead, .dead => True | _, _ => False val s _ := s = .a lemma resetKripke_serial : IsSerial resetKripke := fun _ => ⟨.a, trivial⟩ lemma trapKripke_serial : IsSerial trapKripke := by intro s cases s with | a => exact ⟨.a, trivial⟩ | b => exact ⟨.a, trivial⟩ | dead => exact ⟨.dead, trivial⟩ lemma reset_trap_trace_equiv : TraceSet resetKripke .a = TraceSet trapKripke .a := by ext τ constructor · rintro ⟨π, _, h0, rfl⟩ let π' : ℕ → TrapState := fun n => match π n with | .a => .a | .b => .b refine ⟨π', ?_, ?_, ?_⟩ · intro n dsimp only [π'] cases π n <;> cases π (n + 1) <;> trivial · simp [π', h0] · funext n u dsimp only [trace, resetKripke, trapKripke, π'] cases π n <;> simp · rintro ⟨π, _, h0, rfl⟩ let π' : ℕ → ResetState := fun n => match π n with | .a => .a | .b => .b | .dead => .b refine ⟨π', fun _ => trivial, ?_, ?_⟩ · simp [π', h0] · funext n u dsimp only [trace, resetKripke, trapKripke, π'] cases π n <;> simp lemma resetKripke_sat_AGEFp : CTL.Sat resetKripke .a (CTL.AG (CTL.EF (.atom ()))) := by rw [CTL.sat_AG] intro π _ _ i rw [CTL.sat_EF] let π' : ℕ → ResetState := fun n => match n with | 0 => π i | _ + 1 => .a exact ⟨π', fun _ => trivial, rfl, 1, rfl⟩ lemma trapKripke_not_sat_AGEFp : ¬ CTL.Sat trapKripke .a (CTL.AG (CTL.EF (.atom ()))) := by rw [CTL.sat_AG] push Not let π : ℕ → TrapState := fun n => match n with | 0 => .a | _ + 1 => .dead refine ⟨π, ?_, rfl, 1, ?_⟩ · intro n cases n <;> trivial · rw [CTL.sat_EF] rintro ⟨σ, hσ, h0, j, hj⟩ have hdead : ∀ m, σ m = .dead := by intro m induction m with | zero => exact h0 | succ m ih => have hstep := hσ m rw [ih] at hstep cases hsm : σ (m + 1) with | dead => rfl | a => rw [hsm] at hstep; cases hstep | b => rw [hsm] at hstep; cases hstep have h1 : σ j = .a := hj rw [hdead j] at h1 cases h1 /-- **CTL ⊈ LTL (`AG EF p` Is Not Expressible in LTL):** The trace-equivalent finite serial Kripke structures `resetKripke` and `trapKripke` satisfy the exact same LTL formulas at state `a`, yet `AG (EF p)` holds at `resetKripke.a` and fails at `trapKripke.a`. Hence no LTL formula is equivalent to `AG (EF p)`. -/ theorem ctl_not_subsumed_by_ltl : (∀ ψ : LTL Unit, LTL.SatState resetKripke .a ψ ↔ LTL.SatState trapKripke .a ψ) ∧ CTL.Sat resetKripke .a (CTL.AG (CTL.EF (.atom ()))) ∧ ¬ CTL.Sat trapKripke .a (CTL.AG (CTL.EF (.atom ()))) ∧ ¬ ∃ ψ : LTL Unit, ∀ (S : Type) (K : Kripke S Unit), IsSerial K → ∀ s, LTL.SatState K s ψ ↔ CTL.Sat K s (CTL.AG (CTL.EF (.atom ()))) := by have hltl : ∀ ψ : LTL Unit, LTL.SatState resetKripke .a ψ ↔ LTL.SatState trapKripke .a ψ := trace_equiv_implies_ltl_equiv reset_trap_trace_equiv refine ⟨hltl, resetKripke_sat_AGEFp, trapKripke_not_sat_AGEFp, ?_⟩ rintro ⟨ψ, hψ⟩ have h1 := (hψ ResetState resetKripke resetKripke_serial .a).mpr resetKripke_sat_AGEFp have h2 := (hltl ψ).mp h1 exact trapKripke_not_sat_AGEFp ((hψ TrapState trapKripke trapKripke_serial .a).mp h2) /-! ### Part 4B: `LTL ⊈ CTL` — Clarke–Draghicescu / Emerson–Halpern Theorem (`◇□ p ∉ CTL`) -/ /-- State space of the Clarke–Draghicescu separating models `M_k` and `M'_k` (`2k + 1` states): `a i` (`i = 0, ..., k`) has `p = True`; `b i` (`i = 0, ..., k - 1`) has `p = False`. -/ inductive CDState (k : ℕ) : Type | a (i : Fin (k + 1)) : CDState k | b (i : Fin k) : CDState k deriving DecidableEq /-- `M_k`: acyclic descent through `a_k → b_{k-1} → a_{k-1} → ... → a_0` with self-loops on `a_i`. -/ def cdModel (k : ℕ) : Kripke (CDState k) Unit where step s t := match s, t with | .a i, .a j => i = j | .a i, .b j => i.val = j.val + 1 | .b i, .a j => j.val = i.val | .b _, .b _ => False val s _ := match s with | .a _ => True | .b _ => False /-- `M'_k`: identical to `M_k` except for one additional back-edge `b_{k-1} → a_k`. -/ def cdModelPrime (k : ℕ) : Kripke (CDState k) Unit where step s t := match s, t with | .a i, .a j => i = j | .a i, .b j => i.val = j.val + 1 | .b i, .a j => j.val = i.val ∨ (i.val + 1 = k ∧ j.val = k) | .b _, .b _ => False val s _ := match s with | .a _ => True | .b _ => False /-- Strict rank decreasing along every non-self-loop transition in `cdModel k`. -/ def cdRank {k : ℕ} : CDState k → ℕ | .a i => 2 * i.val | .b i => 2 * i.val + 1 lemma cdModel_serial (k : ℕ) : IsSerial (cdModel k) := by intro s cases s with | a i => exact ⟨.a i, rfl⟩ | b i => exact ⟨.a ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩, rfl⟩ lemma cdModelPrime_serial (k : ℕ) : IsSerial (cdModelPrime k) := by intro s cases s with | a i => exact ⟨.a i, rfl⟩ | b i => exact ⟨.a ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩, Or.inl rfl⟩ lemma cdModel_rank_le {k : ℕ} {s t : CDState k} (h : (cdModel k).step s t) : cdRank t ≤ cdRank s := by cases s <;> cases t <;> simp [cdModel, cdRank] at h ⊢ <;> omega lemma cdModel_b_rank_lt {k : ℕ} {i : Fin k} {t : CDState k} (h : (cdModel k).step (.b i) t) : cdRank t < cdRank (.b i) := by cases t with | a j => simp [cdModel, cdRank] at h ⊢; omega | b _ => cases h /-- Every infinite path in `cdModel k` satisfies LTL persistence `◇□ p` (`FG p`). -/ lemma cdModel_sat_FGp (k : ℕ) (s : CDState k) : LTL.SatState (cdModel k) s (LTL.F (LTL.G (.atom ()))) := by classical intro π hπ _ rw [(ltl_duality_and_expansion_laws (trace (cdModel k) π) (.atom ()) (.atom ())).2.2.2.2.2.1] have hdec : ∀ m n, m ≤ n → cdRank (π n) ≤ cdRank (π m) := by intro m n hmn induction hmn with | refl => exact le_rfl | @step r _ ih => exact le_trans (cdModel_rank_le (hπ r)) ih have hex : ∃ v, ∃ n, cdRank (π n) = v := ⟨cdRank (π 0), 0, rfl⟩ let vmin := Nat.find hex rcases Nat.find_spec hex with ⟨N, hN⟩ refine ⟨N, fun m hm => ?_⟩ have hmin_m : cdRank (π m) = vmin := by apply le_antisymm · exact le_trans (hdec N m hm) (le_of_eq hN) · exact Nat.find_min' hex ⟨m, rfl⟩ have hmin_succ : cdRank (π (m + 1)) = vmin := by apply le_antisymm · exact le_trans (hdec N (m + 1) (Nat.le_succ_of_le hm)) (le_of_eq hN) · exact Nat.find_min' hex ⟨m + 1, rfl⟩ simp only [LTL.SatTrace, shift, trace, Nat.zero_add] cases hpm : π m with | a _ => trivial | b i => have hstep := hπ m rw [hpm] at hstep have hlt := cdModel_b_rank_lt hstep rw [← hpm, hmin_m, hmin_succ] at hlt exact absurd hlt (lt_irrefl _) /-- In `cdModelPrime k` (`k ≥ 1`), the alternating loop `a_k ↔ b_{k-1}` violates `◇□ p`. -/ lemma cdModelPrime_not_sat_FGp {k : ℕ} (hk : 1 ≤ k) : ¬ LTL.SatState (cdModelPrime k) (.a ⟨k, Nat.lt_succ_self k⟩) (LTL.F (LTL.G (.atom ()))) := by intro hsat let ak : CDState k := .a ⟨k, Nat.lt_succ_self k⟩ let bk : CDState k := .b ⟨k - 1, by omega⟩ let π : ℕ → CDState k := fun n => if n % 2 = 0 then ak else bk have hπ : IsPath (cdModelPrime k) π := by intro n by_cases hn : n % 2 = 0 · have hn1 : (n + 1) % 2 ≠ 0 := by omega simp only [π, if_pos hn, if_neg hn1, ak, bk, cdModelPrime] omega · have hn1 : (n + 1) % 2 = 0 := by omega simp only [π, if_neg hn, if_pos hn1, ak, bk, cdModelPrime] right exact ⟨by omega, trivial⟩ have hfg := hsat π hπ (by simp [π, ak]) rw [(ltl_duality_and_expansion_laws (trace (cdModelPrime k) π) (.atom ()) (.atom ())).2.2.2.2.2.1] at hfg rcases hfg with ⟨N, hN⟩ have hodd := hN (2 * N + 1) (by omega) have hmod : (2 * N + 1) % 2 ≠ 0 := by omega simp only [LTL.SatTrace, shift, trace, Nat.zero_add, π, if_neg hmod, bk, cdModelPrime] at hodd /-- On the lower region `cdRank s ≤ 2 * (k - 1)`, `cdModel k` and `cdModelPrime k` are cross-bisimilar via the identity relation, hence satisfy identical CTL formulas. -/ lemma cd_low_crossBisim {k : ℕ} (hk : 1 ≤ k) {s : CDState k} (hs : cdRank s ≤ 2 * (k - 1)) : CrossBisimilar (cdModel k).toLTS (cdModelPrime k).toLTS s s := by refine ⟨fun x y => x = y ∧ cdRank x ≤ 2 * (k - 1), ?_, rfl, hs⟩ intro x y ⟨hxy, hrx⟩ subst hxy refine ⟨fun _ => Iff.rfl, ?_, ?_⟩ · intro _ t hstep refine ⟨t, ?_, rfl, le_trans (cdModel_rank_le hstep) hrx⟩ cases x <;> cases t <;> simp [Kripke.toLTS, cdModel, cdModelPrime] at hstep ⊢ · exact hstep · exact hstep · exact Or.inl hstep · intro _ t hstep have hstep' : (cdModel k).step x t := by cases x with | a i => cases t <;> simpa [Kripke.toLTS, cdModel, cdModelPrime] using hstep | b i => cases t with | a j => simp only [Kripke.toLTS, cdModelPrime] at hstep rcases hstep with h1 | ⟨h2, _⟩ · exact h1 · simp [cdRank] at hrx omega | b _ => exact hstep exact ⟨t, hstep', rfl, le_trans (cdModel_rank_le hstep') hrx⟩ /-- Helper: in any `cdModel` or `cdModelPrime`, every `a i` has a self-loop, so `AU φ₁ φ₂` at `a i` reduces instantaneously to `φ₂`. -/ lemma cd_sat_AU_a_iff {k : ℕ} {M : Kripke (CDState k) Unit} (hloop : ∀ i : Fin (k + 1), M.step (.a i) (.a i)) (i : Fin (k + 1)) (φ₁ φ₂ : CTL Unit) : CTL.Sat M (.a i) (.AU φ₁ φ₂) ↔ CTL.Sat M (.a i) φ₂ := by constructor · intro hau rcases hau (fun _ => .a i) (fun _ => hloop i) rfl with ⟨t, ht, _⟩ exact ht · intro hφ₂ π _ h0 exact ⟨0, by rwa [h0], fun j hj => by omega⟩ /-- Helper: prepend a descending chain `a i → b (i-1) → ... → a d'` in `cdModel k` or `cdModelPrime k`. -/ lemma cd_prepend_descent {k : ℕ} {M : Kripke (CDState k) Unit} (hdown_ab : ∀ (j : Fin k), M.step (.a ⟨j.val + 1, Nat.succ_lt_succ j.isLt⟩) (.b j)) (hdown_ba : ∀ (j : Fin k), M.step (.b j) (.a ⟨j.val, Nat.lt_succ_of_lt j.isLt⟩)) {d' : ℕ} (hd' : d' < k) {φ₁ φ₂ : CTL Unit} (hA1 : ∀ m : Fin (k + 1), d' ≤ m.val → CTL.Sat M (.a m) φ₁) (hB1 : ∀ m : Fin k, d' ≤ m.val → CTL.Sat M (.b m) φ₁) (hBase : CTL.Sat M (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) (.EU φ₁ φ₂)) : ∀ (m : ℕ), d' ≤ m → ∀ (hmk : m ≤ k), CTL.Sat M (.a ⟨m, Nat.lt_succ_of_le hmk⟩) (.EU φ₁ φ₂) := by intro m hm hmk obtain ⟨r, rfl⟩ := Nat.exists_eq_add_of_le hm induction r with | zero => simpa using hBase | succ r ih => have hprev := ih (by omega) (by omega) rcases hprev with ⟨π, hπ, h0, t, ht, hj⟩ let j : Fin k := ⟨d' + r, by omega⟩ let aNext : CDState k := .a ⟨d' + r + 1, Nat.lt_succ_of_le hmk⟩ let π' : ℕ → CDState k := fun n => match n with | 0 => aNext | 1 => .b j | n + 2 => π n refine ⟨π', ?_, rfl, t + 2, ht, ?_⟩ · intro n cases n with | zero => exact hdown_ab j | succ n => cases n with | zero => change M.step (.b j) (π 0) rw [h0] exact hdown_ba j | succ m => exact hπ m · intro idx hidx cases idx with | zero => exact hA1 ⟨d' + r + 1, Nat.lt_succ_of_le hmk⟩ (by omega) | succ idx => cases idx with | zero => exact hB1 j (by simp [j]) | succ m => exact hj m (by omega) /-- Exact closed-form reduction of `EU φ₁ φ₂` on the upper zone of `cdModel k` and `cdModelPrime k`. -/ lemma cd_EU_upper_char {k d' : ℕ} (hd' : d' < k) {φ₁ φ₂ : CTL Unit} {M : Kripke (CDState k) Unit} (hM : M = cdModel k ∨ M = cdModelPrime k) (hA1 : ∀ m : Fin (k + 1), d' ≤ m.val → (CTL.Sat M (.a m) φ₁ ↔ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) φ₁)) (hA2 : ∀ m : Fin (k + 1), d' ≤ m.val → (CTL.Sat M (.a m) φ₂ ↔ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) φ₂)) (hB1 : ∀ m : Fin k, d' ≤ m.val → (CTL.Sat M (.b m) φ₁ ↔ CTL.Sat (cdModel k) (.b ⟨d', hd'⟩) φ₁)) (hB2 : ∀ m : Fin k, d' ≤ m.val → (CTL.Sat M (.b m) φ₂ ↔ CTL.Sat (cdModel k) (.b ⟨d', hd'⟩) φ₂)) (i : Fin (k + 1)) (hi : d' + 1 ≤ i.val) : CTL.Sat M (.a i) (.EU φ₁ φ₂) ↔ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) φ₂ ∨ (CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) φ₁ ∧ CTL.Sat (cdModel k) (.b ⟨d', hd'⟩) φ₂) ∨ (CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) φ₁ ∧ CTL.Sat (cdModel k) (.b ⟨d', hd'⟩) φ₁ ∧ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) (.EU φ₁ φ₂)) := by have hk1 : 1 ≤ k := by omega have hloop : ∀ m : Fin (k + 1), M.step (.a m) (.a m) := by rcases hM with rfl | rfl <;> intro m <;> rfl have hdown_ab : ∀ j : Fin k, M.step (.a ⟨j.val + 1, Nat.succ_lt_succ j.isLt⟩) (.b j) := by rcases hM with rfl | rfl <;> intro j <;> rfl have hdown_ba : ∀ j : Fin k, M.step (.b j) (.a ⟨j.val, Nat.lt_succ_of_lt j.isLt⟩) := by rcases hM with rfl | rfl · intro j; rfl · intro j; exact Or.inl rfl have hlow_equiv : CTL.Sat M (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) (.EU φ₁ φ₂) ↔ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) (.EU φ₁ φ₂) := by rcases hM with rfl | rfl · exact Iff.rfl · exact (bisimulation_invariance_ctl (cd_low_crossBisim hk1 (s := .a ⟨d', Nat.lt_succ_of_lt hd'⟩) (by simp [cdRank]; omega)) (.EU φ₁ φ₂)).symm constructor · rintro ⟨π, hπ, h0, t, ht, hj⟩ by_cases hhit : ∃ s ≤ t, cdRank (π s) ≤ 2 * d' · classical let s₀ := Nat.find hhit have hs₀_spec : s₀ ≤ t ∧ cdRank (π s₀) ≤ 2 * d' := Nat.find_spec hhit have hs₀_pos : 0 < s₀ := by by_contra hzero have hs0 : s₀ = 0 := by omega have hr0 := hs₀_spec.2 rw [hs0, h0] at hr0 simp [cdRank] at hr0 omega let r := s₀ - 1 have hr_succ : r + 1 = s₀ := by omega have hr_gt : 2 * d' < cdRank (π r) := by by_contra hle exact Nat.find_min hhit (show r < s₀ by omega) ⟨by omega, by omega⟩ have hstep_r : M.step (π r) (π (r + 1)) := hπ r have hrank_next : cdRank (π (r + 1)) ≤ 2 * d' := by rw [hr_succ]; exact hs₀_spec.2 have hpr_b : π r = .b ⟨d', hd'⟩ ∧ π (r + 1) = .a ⟨d', Nat.lt_succ_of_lt hd'⟩ := by cases hpr : π r with | a m => rw [hpr] at hr_gt hstep_r cases hpn : π (r + 1) with | a m' => rw [hpn] at hstep_r hrank_next rcases hM with rfl | rfl <;> (simp [cdModel, cdModelPrime, cdRank] at hstep_r hr_gt hrank_next; subst hstep_r; omega) | b m' => rw [hpn] at hstep_r hrank_next rcases hM with rfl | rfl <;> (simp [cdModel, cdModelPrime, cdRank] at hstep_r hr_gt hrank_next; omega) | b m => rw [hpr] at hr_gt hstep_r cases hpn : π (r + 1) with | b m' => rw [hpn] at hstep_r rcases hM with rfl | rfl <;> simp [cdModel, cdModelPrime] at hstep_r | a m' => rw [hpn] at hstep_r hrank_next rcases hM with rfl | rfl · simp [cdModel, cdRank] at hstep_r hr_gt hrank_next exact ⟨by congr 1; apply Fin.ext; dsimp only; omega, by congr 1; apply Fin.ext; dsimp only; omega⟩ · simp [cdModelPrime, cdRank] at hstep_r hr_gt hrank_next rcases hstep_r with h1 | ⟨_, h2⟩ · exact ⟨by congr 1; apply Fin.ext; dsimp only; omega, by congr 1; apply Fin.ext; dsimp only; omega⟩ · omega right; right have h0_lt : 0 < t := by omega have hr_lt : r < t := by omega refine ⟨(hA1 i (by omega)).mp (by rw [← h0]; exact hj 0 h0_lt), (hB1 ⟨d', hd'⟩ le_rfl).mp (by rw [← hpr_b.1]; exact hj r hr_lt), ?_⟩ rw [← hlow_equiv] refine ⟨shift π (r + 1), isPath_shift hπ (r + 1), by simp [shift, hpr_b.2], t - (r + 1), ?_, ?_⟩ · simpa [shift, Nat.sub_add_cancel (show r + 1 ≤ t by omega)] using ht · intro idx hidx simpa [shift] using hj (idx + (r + 1)) (by omega) · push Not at hhit cases t with | zero => left rw [h0] at ht exact (hA2 i (by omega)).mp ht | succ t' => have hgt := hhit (t' + 1) le_rfl have h0_a1 : CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'⟩) φ₁ := (hA1 i (by omega)).mp (by rw [← h0]; exact hj 0 (Nat.zero_lt_succ t')) cases hpt : π (t' + 1) with | a m => rw [hpt] at hgt ht simp [cdRank] at hgt left exact (hA2 m (by omega)).mp ht | b m => rw [hpt] at hgt ht simp [cdRank] at hgt right; left exact ⟨h0_a1, (hB2 m (by omega)).mp ht⟩ · rintro (h2 | ⟨h1, hb2⟩ | ⟨h1, hb1, heu⟩) · exact ⟨fun _ => .a i, fun _ => hloop i, rfl, 0, (hA2 i (by omega)).mpr h2, fun j hj => by omega⟩ · let j : Fin k := ⟨i.val - 1, by omega⟩ let aPrev : Fin (k + 1) := ⟨j.val, Nat.lt_succ_of_lt j.isLt⟩ let π : ℕ → CDState k := fun n => match n with | 0 => .a i | 1 => .b j | _ + 2 => .a aPrev have hi_eq : (⟨j.val + 1, Nat.succ_lt_succ j.isLt⟩ : Fin (k + 1)) = i := by apply Fin.ext; simp [j]; omega refine ⟨π, ?_, rfl, 1, (hB2 j (by simp [j]; omega)).mpr hb2, ?_⟩ · intro n cases n with | zero => simpa [π, hi_eq] using hdown_ab j | succ n => cases n with | zero => exact hdown_ba j | succ _ => exact hloop aPrev · intro idx hidx have hidx0 : idx = 0 := by omega subst hidx0 exact (hA1 i (by omega)).mpr h1 · have hbase := hlow_equiv.mpr heu have hres := cd_prepend_descent hdown_ab hdown_ba hd' (fun m hm => (hA1 m hm).mpr h1) (fun m hm => (hB1 m hm).mpr hb1) hbase i.val (by omega) (Nat.le_of_lt_succ i.isLt) simpa using hres /-- **Exact CTL-$d$-Equivalence of the Clarke–Draghicescu Family `M_k` and `M'_k`:** For every `k ≥ 1`, every CTL formula `φ` with `φ.depth ≤ d ≤ k`, all upper states `a_i` (`i ≥ d`) and `b_i` (`i ≥ d`) agree across `cdModel k` and `cdModelPrime k`. -/ theorem cd_ctl_depth_equiv (k : ℕ) (φ : CTL Unit) : ∀ d ≤ k, φ.depth ≤ d → (∀ i j : Fin (k + 1), d ≤ i.val → d ≤ j.val → (CTL.Sat (cdModel k) (.a i) φ ↔ CTL.Sat (cdModel k) (.a j) φ)) ∧ (∀ i : Fin (k + 1), d ≤ i.val → (CTL.Sat (cdModel k) (.a i) φ ↔ CTL.Sat (cdModelPrime k) (.a i) φ)) ∧ (∀ i j : Fin k, d ≤ i.val → d ≤ j.val → (CTL.Sat (cdModel k) (.b i) φ ↔ CTL.Sat (cdModel k) (.b j) φ)) ∧ (∀ i : Fin k, d ≤ i.val → (CTL.Sat (cdModel k) (.b i) φ ↔ CTL.Sat (cdModelPrime k) (.b i) φ)) := by induction φ with | tt => intro d _ _ exact ⟨fun _ _ _ _ => Iff.rfl, fun _ _ => Iff.rfl, fun _ _ _ _ => Iff.rfl, fun _ _ => Iff.rfl⟩ | atom p => intro d _ _ exact ⟨fun _ _ _ _ => Iff.rfl, fun _ _ => Iff.rfl, fun _ _ _ _ => Iff.rfl, fun _ _ => Iff.rfl⟩ | neg φ ih => intro d hdk hdep rcases ih d hdk hdep with ⟨h1, h2, h3, h4⟩ exact ⟨fun i j hi hj => not_congr (h1 i j hi hj), fun i hi => not_congr (h2 i hi), fun i j hi hj => not_congr (h3 i j hi hj), fun i hi => not_congr (h4 i hi)⟩ | and φ ψ ih₁ ih₂ => intro d hdk hdep simp only [CTL.depth, max_le_iff] at hdep rcases ih₁ d hdk hdep.1 with ⟨a1, a2, a3, a4⟩ rcases ih₂ d hdk hdep.2 with ⟨b1, b2, b3, b4⟩ exact ⟨fun i j hi hj => and_congr (a1 i j hi hj) (b1 i j hi hj), fun i hi => and_congr (a2 i hi) (b2 i hi), fun i j hi hj => and_congr (a3 i j hi hj) (b3 i j hi hj), fun i hi => and_congr (a4 i hi) (b4 i hi)⟩ | EX φ ih => intro d hdk hdep cases d with | zero => simp [CTL.depth] at hdep | succ d' => have hd'k : d' ≤ k := by omega have hd'lt : d' < k := by omega have hφ : φ.depth ≤ d' := Nat.le_of_succ_le_succ hdep rcases ih d' hd'k hφ with ⟨hA_eq, hA_pr, hB_eq, hB_pr⟩ have hEX_a : ∀ (M : Kripke (CDState k) Unit), (M = cdModel k ∨ M = cdModelPrime k) → ∀ i : Fin (k + 1), d' + 1 ≤ i.val → (CTL.Sat M (.a i) (.EX φ) ↔ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'lt⟩) φ ∨ CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) φ) := by intro M hM i hi constructor · rintro ⟨t, hst, hsat⟩ cases t with | a j => have hij : i = j := by rcases hM with rfl | rfl <;> exact hst subst hij left have hsat' : CTL.Sat (cdModel k) (.a i) φ := by rcases hM with rfl | rfl · exact hsat · exact (hA_pr i (by omega)).mpr hsat exact (hA_eq i ⟨d', Nat.lt_succ_of_lt hd'lt⟩ (by omega) le_rfl).mp hsat' | b j => have hij : i.val = j.val + 1 := by rcases hM with rfl | rfl <;> exact hst right have hsat' : CTL.Sat (cdModel k) (.b j) φ := by rcases hM with rfl | rfl · exact hsat · exact (hB_pr j (by omega)).mpr hsat exact (hB_eq j ⟨d', hd'lt⟩ (by omega) le_rfl).mp hsat' · rintro (ha | hb) · refine ⟨.a i, by rcases hM with rfl | rfl <;> rfl, ?_⟩ have h1 := (hA_eq i ⟨d', Nat.lt_succ_of_lt hd'lt⟩ (by omega) le_rfl).mpr ha rcases hM with rfl | rfl · exact h1 · exact (hA_pr i (by omega)).mp h1 · let j : Fin k := ⟨i.val - 1, by omega⟩ refine ⟨.b j, by rcases hM with rfl | rfl <;> (simp [cdModel, cdModelPrime, j]; omega), ?_⟩ have h1 := (hB_eq j ⟨d', hd'lt⟩ (by simp [j]; omega) le_rfl).mpr hb rcases hM with rfl | rfl · exact h1 · exact (hB_pr j (by simp [j]; omega)).mp h1 have hEX_b : ∀ (M : Kripke (CDState k) Unit), (M = cdModel k ∨ M = cdModelPrime k) → ∀ i : Fin k, d' + 1 ≤ i.val → (CTL.Sat M (.b i) (.EX φ) ↔ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'lt⟩) φ) := by intro M hM i hi constructor · rintro ⟨t, hst, hsat⟩ cases t with | b _ => rcases hM with rfl | rfl <;> cases hst | a j => have hj : d' ≤ j.val := by rcases hM with rfl | rfl · simp [cdModel] at hst; omega · simp [cdModelPrime] at hst; rcases hst with h1 | ⟨_, h2⟩ <;> omega have hsat' : CTL.Sat (cdModel k) (.a j) φ := by rcases hM with rfl | rfl · exact hsat · exact (hA_pr j hj).mpr hsat exact (hA_eq j ⟨d', Nat.lt_succ_of_lt hd'lt⟩ hj le_rfl).mp hsat' · intro ha let ai : Fin (k + 1) := ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ refine ⟨.a ai, by rcases hM with rfl | rfl; exact rfl; exact Or.inl rfl, ?_⟩ have h1 := (hA_eq ai ⟨d', Nat.lt_succ_of_lt hd'lt⟩ (by simp [ai]; omega) le_rfl).mpr ha rcases hM with rfl | rfl · exact h1 · exact (hA_pr ai (by simp [ai]; omega)).mp h1 refine ⟨fun i j hi hj => (hEX_a _ (Or.inl rfl) i hi).trans (hEX_a _ (Or.inl rfl) j hj).symm, fun i hi => (hEX_a _ (Or.inl rfl) i hi).trans (hEX_a _ (Or.inr rfl) i hi).symm, fun i j hi hj => (hEX_b _ (Or.inl rfl) i hi).trans (hEX_b _ (Or.inl rfl) j hj).symm, fun i hi => (hEX_b _ (Or.inl rfl) i hi).trans (hEX_b _ (Or.inr rfl) i hi).symm⟩ | EU φ ψ ih₁ ih₂ => intro d hdk hdep cases d with | zero => simp [CTL.depth] at hdep | succ d' => have hd'k : d' ≤ k := by omega have hd'lt : d' < k := by omega have hmax : max φ.depth ψ.depth ≤ d' := Nat.le_of_succ_le_succ hdep simp only [max_le_iff] at hmax rcases ih₁ d' hd'k hmax.1 with ⟨a1_eq, a1_pr, b1_eq, b1_pr⟩ rcases ih₂ d' hd'k hmax.2 with ⟨a2_eq, a2_pr, b2_eq, b2_pr⟩ have hEU_a : ∀ (M : Kripke (CDState k) Unit), (M = cdModel k ∨ M = cdModelPrime k) → ∀ i : Fin (k + 1), d' + 1 ≤ i.val → (CTL.Sat M (.a i) (.EU φ ψ) ↔ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'lt⟩) ψ ∨ (CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'lt⟩) φ ∧ CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) ψ) ∨ (CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'lt⟩) φ ∧ CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) φ ∧ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'lt⟩) (.EU φ ψ))) := by intro M hM i hi apply cd_EU_upper_char hd'lt hM · intro m hm rcases hM with rfl | rfl · exact a1_eq m ⟨d', Nat.lt_succ_of_lt hd'lt⟩ hm le_rfl · exact (a1_pr m hm).symm.trans (a1_eq m ⟨d', Nat.lt_succ_of_lt hd'lt⟩ hm le_rfl) · intro m hm rcases hM with rfl | rfl · exact a2_eq m ⟨d', Nat.lt_succ_of_lt hd'lt⟩ hm le_rfl · exact (a2_pr m hm).symm.trans (a2_eq m ⟨d', Nat.lt_succ_of_lt hd'lt⟩ hm le_rfl) · intro m hm rcases hM with rfl | rfl · exact b1_eq m ⟨d', hd'lt⟩ hm le_rfl · exact (b1_pr m hm).symm.trans (b1_eq m ⟨d', hd'lt⟩ hm le_rfl) · intro m hm rcases hM with rfl | rfl · exact b2_eq m ⟨d', hd'lt⟩ hm le_rfl · exact (b2_pr m hm).symm.trans (b2_eq m ⟨d', hd'lt⟩ hm le_rfl) · exact hi have hEU_b : ∀ (M : Kripke (CDState k) Unit), (M = cdModel k ∨ M = cdModelPrime k) → ∀ i : Fin k, d' + 1 ≤ i.val → (CTL.Sat M (.b i) (.EU φ ψ) ↔ CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) ψ ∨ (CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) φ ∧ CTL.Sat (cdModel k) (.a ⟨k, Nat.lt_succ_self k⟩) (.EU φ ψ))) := by intro M hM i hi have hSerM : IsSerial M := by rcases hM with rfl | rfl · exact cdModel_serial k · exact cdModelPrime_serial k have hunfold : CTL.Sat M (.b i) (.EU φ ψ) ↔ CTL.Sat M (.b i) ψ ∨ (CTL.Sat M (.b i) φ ∧ ∃ t, M.step (.b i) t ∧ CTL.Sat M t (.EU φ ψ)) := by have heq := eu_eq_lfp hSerM φ ψ have hmem : (.b i : CDState k) ∈ {s | CTL.Sat M s (.EU φ ψ)} ↔ (.b i : CDState k) ∈ euOp M {s | CTL.Sat M s φ} {s | CTL.Sat M s ψ} {s | CTL.Sat M s (.EU φ ψ)} := by rw [heq]; nth_rw 1 [← OrderHom.map_lfp] exact hmem rw [hunfold] have hb1_i : CTL.Sat M (.b i) φ ↔ CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) φ := by rcases hM with rfl | rfl · exact b1_eq i ⟨d', hd'lt⟩ (by omega) le_rfl · exact (b1_pr i (by omega)).symm.trans (b1_eq i ⟨d', hd'lt⟩ (by omega) le_rfl) have hb2_i : CTL.Sat M (.b i) ψ ↔ CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) ψ := by rcases hM with rfl | rfl · exact b2_eq i ⟨d', hd'lt⟩ (by omega) le_rfl · exact (b2_pr i (by omega)).symm.trans (b2_eq i ⟨d', hd'lt⟩ (by omega) le_rfl) have hstep_iff : (∃ t, M.step (.b i) t ∧ CTL.Sat M t (.EU φ ψ)) ↔ CTL.Sat (cdModel k) (.a ⟨k, Nat.lt_succ_self k⟩) (.EU φ ψ) := by constructor · rintro ⟨t, hst, hsat⟩ cases t with | b _ => rcases hM with rfl | rfl <;> cases hst | a j => have hj : d' + 1 ≤ j.val := by rcases hM with rfl | rfl · simp [cdModel] at hst; omega · simp [cdModelPrime] at hst; rcases hst with h1 | ⟨_, h2⟩ <;> omega exact (hEU_a (cdModel k) (Or.inl rfl) ⟨k, Nat.lt_succ_self k⟩ (by omega)).mpr ((hEU_a M hM j hj).mp hsat) · intro hsat let ai : Fin (k + 1) := ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ refine ⟨.a ai, by rcases hM with rfl | rfl; exact rfl; exact Or.inl rfl, ?_⟩ exact (hEU_a M hM ai (by simp [ai]; omega)).mpr ((hEU_a (cdModel k) (Or.inl rfl) ⟨k, Nat.lt_succ_self k⟩ (by omega)).mp hsat) rw [hb2_i, hb1_i, hstep_iff] refine ⟨fun i j hi hj => (hEU_a _ (Or.inl rfl) i hi).trans (hEU_a _ (Or.inl rfl) j hj).symm, fun i hi => (hEU_a _ (Or.inl rfl) i hi).trans (hEU_a _ (Or.inr rfl) i hi).symm, fun i j hi hj => (hEU_b _ (Or.inl rfl) i hi).trans (hEU_b _ (Or.inl rfl) j hj).symm, fun i hi => (hEU_b _ (Or.inl rfl) i hi).trans (hEU_b _ (Or.inr rfl) i hi).symm⟩ | AU φ ψ ih₁ ih₂ => intro d hdk hdep cases d with | zero => simp [CTL.depth] at hdep | succ d' => have hd'k : d' ≤ k := by omega have hd'lt : d' < k := by omega have hmax : max φ.depth ψ.depth ≤ d' := Nat.le_of_succ_le_succ hdep simp only [max_le_iff] at hmax rcases ih₁ d' hd'k hmax.1 with ⟨_, _, b1_eq, b1_pr⟩ rcases ih₂ d' hd'k hmax.2 with ⟨a2_eq, a2_pr, b2_eq, b2_pr⟩ have hAU_a : ∀ (M : Kripke (CDState k) Unit), (M = cdModel k ∨ M = cdModelPrime k) → ∀ i : Fin (k + 1), d' + 1 ≤ i.val → (CTL.Sat M (.a i) (.AU φ ψ) ↔ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'lt⟩) ψ) := by intro M hM i hi have hloop : ∀ m : Fin (k + 1), M.step (.a m) (.a m) := by rcases hM with rfl | rfl <;> intro m <;> rfl rw [cd_sat_AU_a_iff hloop i] rcases hM with rfl | rfl · exact a2_eq i ⟨d', Nat.lt_succ_of_lt hd'lt⟩ (by omega) le_rfl · exact (a2_pr i (by omega)).symm.trans (a2_eq i ⟨d', Nat.lt_succ_of_lt hd'lt⟩ (by omega) le_rfl) have hAU_b : ∀ (M : Kripke (CDState k) Unit), (M = cdModel k ∨ M = cdModelPrime k) → ∀ i : Fin k, d' + 1 ≤ i.val → (CTL.Sat M (.b i) (.AU φ ψ) ↔ CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) ψ ∨ (CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) φ ∧ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'lt⟩) ψ)) := by intro M hM i hi have hSerM : IsSerial M := by rcases hM with rfl | rfl · exact cdModel_serial k · exact cdModelPrime_serial k have hunfold : CTL.Sat M (.b i) (.AU φ ψ) ↔ CTL.Sat M (.b i) ψ ∨ (CTL.Sat M (.b i) φ ∧ ∀ t, M.step (.b i) t → CTL.Sat M t (.AU φ ψ)) := by have heq := au_eq_lfp hSerM φ ψ have hmem : (.b i : CDState k) ∈ {s | CTL.Sat M s (.AU φ ψ)} ↔ (.b i : CDState k) ∈ auOp M {s | CTL.Sat M s φ} {s | CTL.Sat M s ψ} {s | CTL.Sat M s (.AU φ ψ)} := by rw [heq]; nth_rw 1 [← OrderHom.map_lfp] exact hmem rw [hunfold] have hb1_i : CTL.Sat M (.b i) φ ↔ CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) φ := by rcases hM with rfl | rfl · exact b1_eq i ⟨d', hd'lt⟩ (by omega) le_rfl · exact (b1_pr i (by omega)).symm.trans (b1_eq i ⟨d', hd'lt⟩ (by omega) le_rfl) have hb2_i : CTL.Sat M (.b i) ψ ↔ CTL.Sat (cdModel k) (.b ⟨d', hd'lt⟩) ψ := by rcases hM with rfl | rfl · exact b2_eq i ⟨d', hd'lt⟩ (by omega) le_rfl · exact (b2_pr i (by omega)).symm.trans (b2_eq i ⟨d', hd'lt⟩ (by omega) le_rfl) have hall_iff : (∀ t, M.step (.b i) t → CTL.Sat M t (.AU φ ψ)) ↔ CTL.Sat (cdModel k) (.a ⟨d', Nat.lt_succ_of_lt hd'lt⟩) ψ := by constructor · intro hall let ai : Fin (k + 1) := ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ have hstep : M.step (.b i) (.a ai) := by rcases hM with rfl | rfl; exact rfl; exact Or.inl rfl exact (hAU_a M hM ai (by simp [ai]; omega)).mp (hall (.a ai) hstep) · intro ha2 t hst cases t with | b _ => rcases hM with rfl | rfl <;> cases hst | a j => have hj : d' + 1 ≤ j.val := by rcases hM with rfl | rfl · simp [cdModel] at hst; omega · simp [cdModelPrime] at hst; rcases hst with h1 | ⟨_, h2⟩ <;> omega exact (hAU_a M hM j hj).mpr ha2 rw [hb2_i, hb1_i, hall_iff] refine ⟨fun i j hi hj => (hAU_a _ (Or.inl rfl) i hi).trans (hAU_a _ (Or.inl rfl) j hj).symm, fun i hi => (hAU_a _ (Or.inl rfl) i hi).trans (hAU_a _ (Or.inr rfl) i hi).symm, fun i j hi hj => (hAU_b _ (Or.inl rfl) i hi).trans (hAU_b _ (Or.inl rfl) j hj).symm, fun i hi => (hAU_b _ (Or.inl rfl) i hi).trans (hAU_b _ (Or.inr rfl) i hi).symm⟩ /-- **LTL ⊈ CTL (Clarke–Draghicescu / Emerson–Halpern Theorem):** The LTL persistence formula `◇□ p` (`FG p`) is NOT expressible in CTL: for every `k ≥ 1`, `cdModel k` and `cdModelPrime k` are finite serial Kripke structures indistinguishable by all CTL formulas of nesting depth `≤ k`, yet separated by `FG p`. -/ theorem ltl_FG_not_expressible_in_ctl : (∀ k ≥ 1, (∀ φ : CTL Unit, φ.depth ≤ k → (CTL.Sat (cdModel k) (.a ⟨k, Nat.lt_succ_self k⟩) φ ↔ CTL.Sat (cdModelPrime k) (.a ⟨k, Nat.lt_succ_self k⟩) φ)) ∧ LTL.SatState (cdModel k) (.a ⟨k, Nat.lt_succ_self k⟩) (LTL.F (LTL.G (.atom ()))) ∧ ¬ LTL.SatState (cdModelPrime k) (.a ⟨k, Nat.lt_succ_self k⟩) (LTL.F (LTL.G (.atom ())))) ∧ ¬ ∃ φ : CTL Unit, ∀ (S : Type) (K : Kripke S Unit), IsSerial K → ∀ s, CTL.Sat K s φ ↔ LTL.SatState K s (LTL.F (LTL.G (.atom ()))) := by have hfam : ∀ k ≥ 1, (∀ φ : CTL Unit, φ.depth ≤ k → (CTL.Sat (cdModel k) (.a ⟨k, Nat.lt_succ_self k⟩) φ ↔ CTL.Sat (cdModelPrime k) (.a ⟨k, Nat.lt_succ_self k⟩) φ)) ∧ LTL.SatState (cdModel k) (.a ⟨k, Nat.lt_succ_self k⟩) (LTL.F (LTL.G (.atom ()))) ∧ ¬ LTL.SatState (cdModelPrime k) (.a ⟨k, Nat.lt_succ_self k⟩) (LTL.F (LTL.G (.atom ()))) := by intro k hk refine ⟨?_, cdModel_sat_FGp k _, cdModelPrime_not_sat_FGp hk⟩ intro φ hdep exact (cd_ctl_depth_equiv k φ k le_rfl hdep).2.1 ⟨k, Nat.lt_succ_self k⟩ le_rfl refine ⟨hfam, ?_⟩ rintro ⟨φ, hφ⟩ let k := max φ.depth 1 have hk1 : 1 ≤ k := le_max_right _ _ have hdep : φ.depth ≤ k := le_max_left _ _ rcases hfam k hk1 with ⟨heq, hsat, hnsat⟩ have h1 := (hφ (CDState k) (cdModel k) (cdModel_serial k) (.a ⟨k, Nat.lt_succ_self k⟩)).mpr hsat have h2 := (heq φ hdep).mp h1 exact hnsat ((hφ (CDState k) (cdModelPrime k) (cdModelPrime_serial k) (.a ⟨k, Nat.lt_succ_self k⟩)).mp h2) /-! ## Axiom Audit -/ #print axioms bisimilar_eq_gfp #print axioms bisimulation_invariance_hml #print axioms hennessy_milner_theorem #print axioms hennessy_milner_requires_image_finite #print axioms ltl_duality_and_expansion_laws #print axioms trace_equiv_implies_ltl_equiv #print axioms bisimulation_invariance_ctl #print axioms ctl_fixpoint_characterizations #print axioms ctl_not_subsumed_by_ltl #print axioms cd_ctl_depth_equiv #print axioms ltl_FG_not_expressible_in_ctl end FormalVerification