doc-src/TutorialI/CTL/CTL.thy
author nipkow
Thu, 14 Sep 2000 17:46:00 +0200
changeset 9958 67f2920862c7
child 9992 4281ccea43f0
permissions -rw-r--r--
*** empty log message ***
     1 theory CTL = Main:
     2 
     3 typedecl atom;
     4 types state = "atom set";
     5 
     6 datatype ctl_form = Atom atom
     7                   | NOT ctl_form
     8                   | And ctl_form ctl_form
     9                   | AX ctl_form
    10                   | EF ctl_form
    11                   | AF ctl_form;
    12 
    13 consts valid :: "state \<Rightarrow> ctl_form \<Rightarrow> bool" ("(_ \<Turnstile> _)" [80,80] 80)
    14        M :: "(state \<times> state)set";
    15 
    16 constdefs Paths :: "state \<Rightarrow> (nat \<Rightarrow> state)set"
    17 "Paths s \<equiv> {p. s = p 0 \<and> (\<forall>i. (p i, p(i+1)) \<in> M)}";
    18 
    19 primrec
    20 "s \<Turnstile> Atom a  =  (a\<in>s)"
    21 "s \<Turnstile> NOT f   = (~(s \<Turnstile> f))"
    22 "s \<Turnstile> And f g = (s \<Turnstile> f \<and> s \<Turnstile> g)"
    23 "s \<Turnstile> AX f    = (\<forall>t. (s,t) \<in> M \<longrightarrow> t \<Turnstile> f)"
    24 "s \<Turnstile> EF f    = (\<exists>t. (s,t) \<in> M^* \<and> t \<Turnstile> f)"
    25 "s \<Turnstile> AF f    = (\<forall>p \<in> Paths s. \<exists>i. p i \<Turnstile> f)";
    26 
    27 constdefs af :: "state set \<Rightarrow> state set \<Rightarrow> state set"
    28 "af A T \<equiv> A \<union> {s. \<forall>t. (s, t) \<in> M \<longrightarrow> t \<in> T}";
    29 
    30 lemma mono_af: "mono(af A)";
    31 by(force simp add: af_def intro:monoI);
    32 
    33 consts mc :: "ctl_form \<Rightarrow> state set";
    34 primrec
    35 "mc(Atom a)  = {s. a\<in>s}"
    36 "mc(NOT f)   = -mc f"
    37 "mc(And f g) = mc f \<inter> mc g"
    38 "mc(AX f)    = {s. \<forall>t. (s,t) \<in> M  \<longrightarrow> t \<in> mc f}"
    39 "mc(EF f)    = lfp(\<lambda>T. mc f \<union> {s. \<exists>t. (s,t)\<in>M \<and> t\<in>T})"
    40 "mc(AF f)    = lfp(af(mc f))";
    41 
    42 lemma mono_ef: "mono(\<lambda>T. A \<union> {s. \<exists>t. (s,t)\<in>M \<and> t\<in>T})";
    43 apply(rule monoI);
    44 by(blast);
    45 
    46 lemma lfp_conv_EF:
    47 "lfp(\<lambda>T. A \<union> {s. \<exists>t. (s,t)\<in>M \<and> t\<in>T}) = {s. \<exists>t. (s,t) \<in> M^* \<and> t \<in> A}";
    48 apply(rule equalityI);
    49  apply(rule subsetI);
    50  apply(simp);
    51  apply(erule Lfp.induct);
    52   apply(rule mono_ef);
    53  apply(simp);
    54  apply(blast intro: r_into_rtrancl rtrancl_trans);
    55 apply(rule subsetI);
    56 apply(simp);
    57 apply(erule exE);
    58 apply(erule conjE);
    59 apply(erule_tac P = "t\<in>A" in rev_mp);
    60 apply(erule converse_rtrancl_induct);
    61  apply(rule ssubst [OF lfp_Tarski[OF mono_ef]]);
    62  apply(blast);
    63 apply(rule ssubst [OF lfp_Tarski[OF mono_ef]]);
    64 by(blast);
    65 
    66 theorem lfp_subset_AF:
    67 "lfp(af A) \<subseteq> {s. \<forall> p \<in> Paths s. \<exists> i. p i \<in> A}";
    68 apply(rule subsetI);
    69 apply(erule Lfp.induct[OF _ mono_af]);
    70 apply(simp add: af_def Paths_def);
    71 apply(erule disjE);
    72  apply(blast);
    73 apply(clarify);
    74 apply(erule_tac x = "p 1" in allE);
    75 apply(clarsimp);
    76 apply(erule_tac x = "\<lambda>i. p(i+1)" in allE);
    77 apply(simp);
    78 by(blast);
    79 
    80 text{*
    81 The opposite direction is proved by contradiction: if some state
    82 {term s} is not in @{term"lfp(af A)"}, then we can construct an
    83 infinite @{term A}-avoiding path starting from @{term s}. The reason is
    84 that by unfolding @{term"lfp"} we find that if @{term s} is not in
    85 @{term"lfp(af A)"}, then @{term s} is not in @{term A} and there is a
    86 direct successor of @{term s} that is again not in @{term"lfp(af
    87 A)"}. Iterating this argument yields the promised infinite
    88 @{term A}-avoiding path. Let us formalize this sketch.
    89 
    90 The one-step argument in the above sketch
    91 *};
    92 
    93 lemma not_in_lfp_afD:
    94  "s \<notin> lfp(af A) \<Longrightarrow> s \<notin> A \<and> (\<exists> t. (s,t)\<in>M \<and> t \<notin> lfp(af A))";
    95 apply(erule swap);
    96 apply(rule ssubst[OF lfp_Tarski[OF mono_af]]);
    97 by(simp add:af_def);
    98 
    99 text{*\noindent
   100 is proved by a variant of contraposition (@{thm[source]swap}:
   101 @{thm swap[no_vars]}), i.e.\ assuming the negation of the conclusion
   102 and proving @{term"s : lfp(af A)"}. Unfolding @{term lfp} once and
   103 simplifying with the definition of @{term af} finishes the proof.
   104 
   105 Now we iterate this process. The following construction of the desired
   106 path is parameterized by a predicate @{term P} that should hold along the path:
   107 *};
   108 
   109 consts path :: "state \<Rightarrow> (state \<Rightarrow> bool) \<Rightarrow> (nat \<Rightarrow> state)";
   110 primrec
   111 "path s P 0 = s"
   112 "path s P (Suc n) = (SOME t. (path s P n,t) \<in> M \<and> P t)";
   113 
   114 text{*\noindent
   115 Element @{term"n+1"} on this path is some arbitrary successor
   116 @{term"t"} of element @{term"n"} such that @{term"P t"} holds.  Of
   117 course, such a @{term"t"} may in general not exist, but that is of no
   118 concern to us since we will only use @{term path} in such cases where a
   119 suitable @{term"t"} does exist.
   120 
   121 Now we prove that if each state @{term"s"} that satisfies @{term"P"}
   122 has a successor that again satisfies @{term"P"}, then there exists an infinite @{term"P"}-path.
   123 *};
   124 
   125 lemma seq_lemma:
   126 "\<lbrakk> P s; \<forall>s. P s \<longrightarrow> (\<exists> t. (s,t)\<in>M \<and> P t) \<rbrakk> \<Longrightarrow> \<exists>p\<in>Paths s. \<forall>i. P(p i)";
   127 
   128 txt{*\noindent
   129 First we rephrase the conclusion slightly because we need to prove both the path property
   130 and the fact that @{term"P"} holds simultaneously:
   131 *};
   132 
   133 apply(subgoal_tac "\<exists> p. s = p 0 \<and> (\<forall> i. (p i,p(i+1)) \<in> M \<and> P(p i))");
   134 
   135 txt{*\noindent
   136 From this proposition the original goal follows easily
   137 *};
   138 
   139  apply(simp add:Paths_def, blast);
   140 apply(rule_tac x = "path s P" in exI);
   141 apply(simp);
   142 apply(intro strip);
   143 apply(induct_tac i);
   144  apply(simp);
   145  apply(fast intro:selectI2EX);
   146 apply(simp);
   147 apply(rule selectI2EX);
   148  apply(blast);
   149 apply(rule selectI2EX);
   150  apply(blast);
   151 by(blast);
   152 
   153 lemma seq_lemma:
   154 "\<lbrakk> P s; \<forall> s. P s \<longrightarrow> (\<exists> t. (s,t)\<in>M \<and> P t) \<rbrakk> \<Longrightarrow>
   155  \<exists> p\<in>Paths s. \<forall> i. P(p i)";
   156 apply(subgoal_tac
   157  "\<exists> p. s = p 0 \<and> (\<forall> i. (p i,p(Suc i))\<in>M \<and> P(p i))");
   158  apply(simp add:Paths_def);
   159  apply(blast);
   160 apply(rule_tac x = "nat_rec s (\<lambda>n t. SOME u. (t,u)\<in>M \<and> P u)" in exI);
   161 apply(simp);
   162 apply(intro strip);
   163 apply(induct_tac i);
   164  apply(simp);
   165  apply(fast intro:selectI2EX);
   166 apply(simp);
   167 apply(rule selectI2EX);
   168  apply(blast);
   169 apply(rule selectI2EX);
   170  apply(blast);
   171 by(blast);
   172 
   173 theorem AF_subset_lfp:
   174 "{s. \<forall> p \<in> Paths s. \<exists> i. p i \<in> A} \<subseteq> lfp(af A)";
   175 apply(rule subsetI);
   176 apply(erule contrapos2);
   177 apply simp;
   178 apply(drule seq_lemma);
   179 by(auto dest:not_in_lfp_afD);
   180 
   181 
   182 (*
   183 Second proof of opposite direction, directly by wellfounded induction
   184 on the initial segment of M that avoids A.
   185 
   186 Avoid s A = the set of successors of s that can be reached by a finite A-avoiding path
   187 *)
   188 
   189 consts Avoid :: "state \<Rightarrow> state set \<Rightarrow> state set";
   190 inductive "Avoid s A"
   191 intros "s \<in> Avoid s A"
   192        "\<lbrakk> t \<in> Avoid s A; t \<notin> A; (t,u) \<in> M \<rbrakk> \<Longrightarrow> u \<in> Avoid s A";
   193 
   194 (* For any infinite A-avoiding path (f) in Avoid s A,
   195    there is some infinite A-avoiding path (p) in Avoid s A that starts with s.
   196 *)
   197 lemma ex_infinite_path[rule_format]:
   198 "t \<in> Avoid s A  \<Longrightarrow>
   199  \<forall>f. t = f 0 \<longrightarrow> (\<forall>i. (f i, f (Suc i)) \<in> M \<and> f i \<in> Avoid s A \<and> f i \<notin> A)
   200                 \<longrightarrow> (\<exists> p\<in>Paths s. \<forall>i. p i \<notin> A)";
   201 apply(simp add:Paths_def);
   202 apply(erule Avoid.induct);
   203  apply(blast);
   204 apply(rule allI);
   205 apply(erule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> t | Suc i \<Rightarrow> f i" in allE);
   206 by(force split:nat.split);
   207 
   208 lemma Avoid_in_lfp[rule_format(no_asm)]:
   209 "\<forall>p\<in>Paths s. \<exists>i. p i \<in> A \<Longrightarrow> t \<in> Avoid s A \<longrightarrow> t \<in> lfp(af A)";
   210 apply(subgoal_tac "wf{(y,x). (x,y)\<in>M \<and> x \<in> Avoid s A \<and> y \<in> Avoid s A \<and> x \<notin> A}");
   211  apply(erule_tac a = t in wf_induct);
   212  apply(clarsimp);
   213  apply(rule ssubst [OF lfp_Tarski[OF mono_af]]);
   214  apply(unfold af_def);
   215  apply(blast intro:Avoid.intros);
   216 apply(erule contrapos2);
   217 apply(simp add:wf_iff_no_infinite_down_chain);
   218 apply(erule exE);
   219 apply(rule ex_infinite_path);
   220 by(auto);
   221 
   222 theorem AF_subset_lfp:
   223 "{s. \<forall>p \<in> Paths s. \<exists> i. p i \<in> A} \<subseteq> lfp(af A)";
   224 apply(rule subsetI);
   225 apply(simp);
   226 apply(erule Avoid_in_lfp);
   227 by(rule Avoid.intros);
   228 
   229 
   230 theorem "mc f = {s. s \<Turnstile> f}";
   231 apply(induct_tac f);
   232 by(auto simp add: lfp_conv_EF equalityI[OF lfp_subset_AF AF_subset_lfp]);
   233 
   234 end;