| 17914 |      1 | (*<*)theory CTLind imports CTL begin(*>*)
 | 
| 10218 |      2 | 
 | 
| 10885 |      3 | subsection{*CTL Revisited*}
 | 
| 10218 |      4 | 
 | 
|  |      5 | text{*\label{sec:CTL-revisited}
 | 
| 11494 |      6 | \index{CTL|(}%
 | 
|  |      7 | The purpose of this section is twofold: to demonstrate
 | 
|  |      8 | some of the induction principles and heuristics discussed above and to
 | 
| 10281 |      9 | show how inductive definitions can simplify proofs.
 | 
| 10218 |     10 | In \S\ref{sec:CTL} we gave a fairly involved proof of the correctness of a
 | 
| 10795 |     11 | model checker for CTL\@. In particular the proof of the
 | 
| 10218 |     12 | @{thm[source]infinity_lemma} on the way to @{thm[source]AF_lemma2} is not as
 | 
| 11494 |     13 | simple as one might expect, due to the @{text SOME} operator
 | 
| 10281 |     14 | involved. Below we give a simpler proof of @{thm[source]AF_lemma2}
 | 
|  |     15 | based on an auxiliary inductive definition.
 | 
| 10218 |     16 | 
 | 
|  |     17 | Let us call a (finite or infinite) path \emph{@{term A}-avoiding} if it does
 | 
|  |     18 | not touch any node in the set @{term A}. Then @{thm[source]AF_lemma2} says
 | 
|  |     19 | that if no infinite path from some state @{term s} is @{term A}-avoiding,
 | 
|  |     20 | then @{prop"s \<in> lfp(af A)"}. We prove this by inductively defining the set
 | 
|  |     21 | @{term"Avoid s A"} of states reachable from @{term s} by a finite @{term
 | 
|  |     22 | A}-avoiding path:
 | 
| 10241 |     23 | % Second proof of opposite direction, directly by well-founded induction
 | 
| 10218 |     24 | % on the initial segment of M that avoids A.
 | 
|  |     25 | *}
 | 
|  |     26 | 
 | 
|  |     27 | consts Avoid :: "state \<Rightarrow> state set \<Rightarrow> state set";
 | 
|  |     28 | inductive "Avoid s A"
 | 
|  |     29 | intros "s \<in> Avoid s A"
 | 
|  |     30 |        "\<lbrakk> t \<in> Avoid s A; t \<notin> A; (t,u) \<in> M \<rbrakk> \<Longrightarrow> u \<in> Avoid s A";
 | 
|  |     31 | 
 | 
|  |     32 | text{*
 | 
|  |     33 | It is easy to see that for any infinite @{term A}-avoiding path @{term f}
 | 
| 12492 |     34 | with @{prop"f(0::nat) \<in> Avoid s A"} there is an infinite @{term A}-avoiding path
 | 
| 15904 |     35 | starting with @{term s} because (by definition of @{const Avoid}) there is a
 | 
| 12492 |     36 | finite @{term A}-avoiding path from @{term s} to @{term"f(0::nat)"}.
 | 
|  |     37 | The proof is by induction on @{prop"f(0::nat) \<in> Avoid s A"}. However,
 | 
| 10218 |     38 | this requires the following
 | 
|  |     39 | reformulation, as explained in \S\ref{sec:ind-var-in-prems} above;
 | 
|  |     40 | the @{text rule_format} directive undoes the reformulation after the proof.
 | 
|  |     41 | *}
 | 
|  |     42 | 
 | 
|  |     43 | lemma ex_infinite_path[rule_format]:
 | 
|  |     44 |   "t \<in> Avoid s A  \<Longrightarrow>
 | 
|  |     45 |    \<forall>f\<in>Paths t. (\<forall>i. f i \<notin> A) \<longrightarrow> (\<exists>p\<in>Paths s. \<forall>i. p i \<notin> A)";
 | 
|  |     46 | apply(erule Avoid.induct);
 | 
|  |     47 |  apply(blast);
 | 
|  |     48 | apply(clarify);
 | 
|  |     49 | apply(drule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> t | Suc i \<Rightarrow> f i" in bspec);
 | 
| 12815 |     50 | apply(simp_all add: Paths_def split: nat.split);
 | 
| 10218 |     51 | done
 | 
|  |     52 | 
 | 
|  |     53 | text{*\noindent
 | 
| 11494 |     54 | The base case (@{prop"t = s"}) is trivial and proved by @{text blast}.
 | 
| 10218 |     55 | In the induction step, we have an infinite @{term A}-avoiding path @{term f}
 | 
|  |     56 | starting from @{term u}, a successor of @{term t}. Now we simply instantiate
 | 
|  |     57 | the @{text"\<forall>f\<in>Paths t"} in the induction hypothesis by the path starting with
 | 
|  |     58 | @{term t} and continuing with @{term f}. That is what the above $\lambda$-term
 | 
| 10885 |     59 | expresses.  Simplification shows that this is a path starting with @{term t} 
 | 
|  |     60 | and that the instantiated induction hypothesis implies the conclusion.
 | 
| 10218 |     61 | 
 | 
| 11196 |     62 | Now we come to the key lemma. Assuming that no infinite @{term A}-avoiding
 | 
| 11277 |     63 | path starts from @{term s}, we want to show @{prop"s \<in> lfp(af A)"}. For the
 | 
|  |     64 | inductive proof this must be generalized to the statement that every point @{term t}
 | 
| 11494 |     65 | ``between'' @{term s} and @{term A}, in other words all of @{term"Avoid s A"},
 | 
| 11196 |     66 | is contained in @{term"lfp(af A)"}:
 | 
| 10218 |     67 | *}
 | 
|  |     68 | 
 | 
|  |     69 | lemma Avoid_in_lfp[rule_format(no_asm)]:
 | 
|  |     70 |   "\<forall>p\<in>Paths s. \<exists>i. p i \<in> A \<Longrightarrow> t \<in> Avoid s A \<longrightarrow> t \<in> lfp(af A)";
 | 
| 11196 |     71 | 
 | 
| 10218 |     72 | txt{*\noindent
 | 
| 11196 |     73 | The proof is by induction on the ``distance'' between @{term t} and @{term
 | 
|  |     74 | A}. Remember that @{prop"lfp(af A) = A \<union> M\<inverse> `` lfp(af A)"}.
 | 
|  |     75 | If @{term t} is already in @{term A}, then @{prop"t \<in> lfp(af A)"} is
 | 
|  |     76 | trivial. If @{term t} is not in @{term A} but all successors are in
 | 
|  |     77 | @{term"lfp(af A)"} (induction hypothesis), then @{prop"t \<in> lfp(af A)"} is
 | 
|  |     78 | again trivial.
 | 
|  |     79 | 
 | 
|  |     80 | The formal counterpart of this proof sketch is a well-founded induction
 | 
| 11494 |     81 | on~@{term M} restricted to @{term"Avoid s A - A"}, roughly speaking:
 | 
| 11196 |     82 | @{term[display]"{(y,x). (x,y) \<in> M \<and> x \<in> Avoid s A \<and> x \<notin> A}"}
 | 
| 11277 |     83 | As we shall see presently, the absence of infinite @{term A}-avoiding paths
 | 
| 10241 |     84 | starting from @{term s} implies well-foundedness of this relation. For the
 | 
| 10218 |     85 | moment we assume this and proceed with the induction:
 | 
|  |     86 | *}
 | 
|  |     87 | 
 | 
| 11196 |     88 | apply(subgoal_tac "wf{(y,x). (x,y) \<in> M \<and> x \<in> Avoid s A \<and> x \<notin> A}");
 | 
| 10218 |     89 |  apply(erule_tac a = t in wf_induct);
 | 
|  |     90 |  apply(clarsimp);
 | 
| 11196 |     91 | (*<*)apply(rename_tac t)(*>*)
 | 
| 10218 |     92 | 
 | 
|  |     93 | txt{*\noindent
 | 
| 10885 |     94 | @{subgoals[display,indent=0,margin=65]}
 | 
|  |     95 | Now the induction hypothesis states that if @{prop"t \<notin> A"}
 | 
| 10218 |     96 | then all successors of @{term t} that are in @{term"Avoid s A"} are in
 | 
| 11196 |     97 | @{term"lfp (af A)"}. Unfolding @{term lfp} in the conclusion of the first
 | 
|  |     98 | subgoal once, we have to prove that @{term t} is in @{term A} or all successors
 | 
| 11494 |     99 | of @{term t} are in @{term"lfp (af A)"}.  But if @{term t} is not in @{term A},
 | 
| 11196 |    100 | the second 
 | 
| 15904 |    101 | @{const Avoid}-rule implies that all successors of @{term t} are in
 | 
| 11494 |    102 | @{term"Avoid s A"}, because we also assume @{prop"t \<in> Avoid s A"}.
 | 
|  |    103 | Hence, by the induction hypothesis, all successors of @{term t} are indeed in
 | 
| 10218 |    104 | @{term"lfp(af A)"}. Mechanically:
 | 
|  |    105 | *}
 | 
|  |    106 | 
 | 
| 11196 |    107 |  apply(subst lfp_unfold[OF mono_af]);
 | 
|  |    108 |  apply(simp (no_asm) add: af_def);
 | 
| 12815 |    109 |  apply(blast intro: Avoid.intros);
 | 
| 10218 |    110 | 
 | 
|  |    111 | txt{*
 | 
| 11494 |    112 | Having proved the main goal, we return to the proof obligation that the 
 | 
|  |    113 | relation used above is indeed well-founded. This is proved by contradiction: if
 | 
| 10885 |    114 | the relation is not well-founded then there exists an infinite @{term
 | 
| 10218 |    115 | A}-avoiding path all in @{term"Avoid s A"}, by theorem
 | 
|  |    116 | @{thm[source]wf_iff_no_infinite_down_chain}:
 | 
|  |    117 | @{thm[display]wf_iff_no_infinite_down_chain[no_vars]}
 | 
|  |    118 | From lemma @{thm[source]ex_infinite_path} the existence of an infinite
 | 
| 10885 |    119 | @{term A}-avoiding path starting in @{term s} follows, contradiction.
 | 
| 10218 |    120 | *}
 | 
|  |    121 | 
 | 
| 10235 |    122 | apply(erule contrapos_pp);
 | 
| 12815 |    123 | apply(simp add: wf_iff_no_infinite_down_chain);
 | 
| 10218 |    124 | apply(erule exE);
 | 
|  |    125 | apply(rule ex_infinite_path);
 | 
| 12815 |    126 | apply(auto simp add: Paths_def);
 | 
| 10218 |    127 | done
 | 
|  |    128 | 
 | 
|  |    129 | text{*
 | 
| 11196 |    130 | The @{text"(no_asm)"} modifier of the @{text"rule_format"} directive in the
 | 
|  |    131 | statement of the lemma means
 | 
| 11494 |    132 | that the assumption is left unchanged; otherwise the @{text"\<forall>p"} 
 | 
|  |    133 | would be turned
 | 
| 10218 |    134 | into a @{text"\<And>p"}, which would complicate matters below. As it is,
 | 
|  |    135 | @{thm[source]Avoid_in_lfp} is now
 | 
|  |    136 | @{thm[display]Avoid_in_lfp[no_vars]}
 | 
|  |    137 | The main theorem is simply the corollary where @{prop"t = s"},
 | 
| 11494 |    138 | when the assumption @{prop"t \<in> Avoid s A"} is trivially true
 | 
| 15904 |    139 | by the first @{const Avoid}-rule. Isabelle confirms this:%
 | 
| 11494 |    140 | \index{CTL|)}*}
 | 
| 10218 |    141 | 
 | 
| 10855 |    142 | theorem AF_lemma2:  "{s. \<forall>p \<in> Paths s. \<exists> i. p i \<in> A} \<subseteq> lfp(af A)";
 | 
| 12815 |    143 | by(auto elim: Avoid_in_lfp intro: Avoid.intros);
 | 
| 10218 |    144 | 
 | 
|  |    145 | 
 | 
|  |    146 | (*<*)end(*>*)
 |