doc-src/TutorialI/CTL/document/CTL.tex
author nipkow
Wed, 24 Jan 2001 12:29:10 +0100
changeset 10971 6852682eaf16
parent 10950 aa788fcb75a5
child 10983 59961d32b1ae
permissions -rw-r--r--
*** empty log message ***
     1 %
     2 \begin{isabellebody}%
     3 \def\isabellecontext{CTL}%
     4 %
     5 \isamarkupsubsection{Computation Tree Logic --- CTL%
     6 }
     7 %
     8 \begin{isamarkuptext}%
     9 \label{sec:CTL}
    10 The semantics of PDL only needs reflexive transitive closure.
    11 Let us be adventurous and introduce a more expressive temporal operator.
    12 We extend the datatype
    13 \isa{formula} by a new constructor%
    14 \end{isamarkuptext}%
    15 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ AF\ formula%
    16 \begin{isamarkuptext}%
    17 \noindent
    18 which stands for "always in the future":
    19 on all paths, at some point the formula holds. Formalizing the notion of an infinite path is easy
    20 in HOL: it is simply a function from \isa{nat} to \isa{state}.%
    21 \end{isamarkuptext}%
    22 \isacommand{constdefs}\ Paths\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}state\ {\isasymRightarrow}\ {\isacharparenleft}nat\ {\isasymRightarrow}\ state{\isacharparenright}set{\isachardoublequote}\isanewline
    23 \ \ \ \ \ \ \ \ \ {\isachardoublequote}Paths\ s\ {\isasymequiv}\ {\isacharbraceleft}p{\isachardot}\ s\ {\isacharequal}\ p\ {\isadigit{0}}\ {\isasymand}\ {\isacharparenleft}{\isasymforall}i{\isachardot}\ {\isacharparenleft}p\ i{\isacharcomma}\ p{\isacharparenleft}i{\isacharplus}{\isadigit{1}}{\isacharparenright}{\isacharparenright}\ {\isasymin}\ M{\isacharparenright}{\isacharbraceright}{\isachardoublequote}%
    24 \begin{isamarkuptext}%
    25 \noindent
    26 This definition allows a very succinct statement of the semantics of \isa{AF}:
    27 \footnote{Do not be misled: neither datatypes nor recursive functions can be
    28 extended by new constructors or equations. This is just a trick of the
    29 presentation. In reality one has to define a new datatype and a new function.}%
    30 \end{isamarkuptext}%
    31 {\isachardoublequote}s\ {\isasymTurnstile}\ AF\ f\ \ \ \ {\isacharequal}\ {\isacharparenleft}{\isasymforall}p\ {\isasymin}\ Paths\ s{\isachardot}\ {\isasymexists}i{\isachardot}\ p\ i\ {\isasymTurnstile}\ f{\isacharparenright}{\isachardoublequote}%
    32 \begin{isamarkuptext}%
    33 \noindent
    34 Model checking \isa{AF} involves a function which
    35 is just complicated enough to warrant a separate definition:%
    36 \end{isamarkuptext}%
    37 \isacommand{constdefs}\ af\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}state\ set\ {\isasymRightarrow}\ state\ set\ {\isasymRightarrow}\ state\ set{\isachardoublequote}\isanewline
    38 \ \ \ \ \ \ \ \ \ {\isachardoublequote}af\ A\ T\ {\isasymequiv}\ A\ {\isasymunion}\ {\isacharbraceleft}s{\isachardot}\ {\isasymforall}t{\isachardot}\ {\isacharparenleft}s{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M\ {\isasymlongrightarrow}\ t\ {\isasymin}\ T{\isacharbraceright}{\isachardoublequote}%
    39 \begin{isamarkuptext}%
    40 \noindent
    41 Now we define \isa{mc\ {\isacharparenleft}AF\ f{\isacharparenright}} as the least set \isa{T} that includes
    42 \isa{mc\ f} and all states all of whose direct successors are in \isa{T}:%
    43 \end{isamarkuptext}%
    44 {\isachardoublequote}mc{\isacharparenleft}AF\ f{\isacharparenright}\ \ \ \ {\isacharequal}\ lfp{\isacharparenleft}af{\isacharparenleft}mc\ f{\isacharparenright}{\isacharparenright}{\isachardoublequote}%
    45 \begin{isamarkuptext}%
    46 \noindent
    47 Because \isa{af} is monotone in its second argument (and also its first, but
    48 that is irrelevant) \isa{af\ A} has a least fixed point:%
    49 \end{isamarkuptext}%
    50 \isacommand{lemma}\ mono{\isacharunderscore}af{\isacharcolon}\ {\isachardoublequote}mono{\isacharparenleft}af\ A{\isacharparenright}{\isachardoublequote}\isanewline
    51 \isacommand{apply}{\isacharparenleft}simp\ add{\isacharcolon}\ mono{\isacharunderscore}def\ af{\isacharunderscore}def{\isacharparenright}\isanewline
    52 \isacommand{apply}\ blast\isanewline
    53 \isacommand{done}%
    54 \begin{isamarkuptext}%
    55 All we need to prove now is  \isa{mc\ {\isacharparenleft}AF\ f{\isacharparenright}\ {\isacharequal}\ {\isacharbraceleft}s{\isachardot}\ s\ {\isasymTurnstile}\ AF\ f{\isacharbraceright}}, which states
    56 that \isa{mc} and \isa{{\isasymTurnstile}} agree for \isa{AF}\@.
    57 This time we prove the two inclusions separately, starting
    58 with the easy one:%
    59 \end{isamarkuptext}%
    60 \isacommand{theorem}\ AF{\isacharunderscore}lemma{\isadigit{1}}{\isacharcolon}\isanewline
    61 \ \ {\isachardoublequote}lfp{\isacharparenleft}af\ A{\isacharparenright}\ {\isasymsubseteq}\ {\isacharbraceleft}s{\isachardot}\ {\isasymforall}\ p\ {\isasymin}\ Paths\ s{\isachardot}\ {\isasymexists}\ i{\isachardot}\ p\ i\ {\isasymin}\ A{\isacharbraceright}{\isachardoublequote}%
    62 \begin{isamarkuptxt}%
    63 \noindent
    64 In contrast to the analogous property for \isa{EF}, and just
    65 for a change, we do not use fixed point induction but a weaker theorem,
    66 \isa{lfp{\isacharunderscore}lowerbound}:
    67 \begin{isabelle}%
    68 \ \ \ \ \ f\ S\ {\isasymsubseteq}\ S\ {\isasymLongrightarrow}\ lfp\ f\ {\isasymsubseteq}\ S%
    69 \end{isabelle}
    70 The instance of the premise \isa{f\ S\ {\isasymsubseteq}\ S} is proved pointwise,
    71 a decision that clarification takes for us:%
    72 \end{isamarkuptxt}%
    73 \isacommand{apply}{\isacharparenleft}rule\ lfp{\isacharunderscore}lowerbound{\isacharparenright}\isanewline
    74 \isacommand{apply}{\isacharparenleft}clarsimp\ simp\ add{\isacharcolon}\ af{\isacharunderscore}def\ Paths{\isacharunderscore}def{\isacharparenright}%
    75 \begin{isamarkuptxt}%
    76 \begin{isabelle}%
    77 \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ {\isasymlbrakk}p\ {\isadigit{0}}\ {\isasymin}\ A\ {\isasymor}\isanewline
    78 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ {\isasymlbrakk}}{\isacharparenleft}{\isasymforall}t{\isachardot}\ {\isacharparenleft}p\ {\isadigit{0}}{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M\ {\isasymlongrightarrow}\isanewline
    79 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ {\isasymlbrakk}{\isacharparenleft}{\isasymforall}t{\isachardot}\ }{\isacharparenleft}{\isasymforall}p{\isachardot}\ t\ {\isacharequal}\ p\ {\isadigit{0}}\ {\isasymand}\ {\isacharparenleft}{\isasymforall}i{\isachardot}\ {\isacharparenleft}p\ i{\isacharcomma}\ p\ {\isacharparenleft}Suc\ i{\isacharparenright}{\isacharparenright}\ {\isasymin}\ M{\isacharparenright}\ {\isasymlongrightarrow}\isanewline
    80 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ {\isasymlbrakk}{\isacharparenleft}{\isasymforall}t{\isachardot}\ {\isacharparenleft}{\isasymforall}p{\isachardot}\ }{\isacharparenleft}{\isasymexists}i{\isachardot}\ p\ i\ {\isasymin}\ A{\isacharparenright}{\isacharparenright}{\isacharparenright}{\isacharsemicolon}\isanewline
    81 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ \ \ \ }{\isasymforall}i{\isachardot}\ {\isacharparenleft}p\ i{\isacharcomma}\ p\ {\isacharparenleft}Suc\ i{\isacharparenright}{\isacharparenright}\ {\isasymin}\ M{\isasymrbrakk}\isanewline
    82 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ }{\isasymLongrightarrow}\ {\isasymexists}i{\isachardot}\ p\ i\ {\isasymin}\ A%
    83 \end{isabelle}
    84 Now we eliminate the disjunction. The case \isa{p\ {\isadigit{0}}\ {\isasymin}\ A} is trivial:%
    85 \end{isamarkuptxt}%
    86 \isacommand{apply}{\isacharparenleft}erule\ disjE{\isacharparenright}\isanewline
    87 \ \isacommand{apply}{\isacharparenleft}blast{\isacharparenright}%
    88 \begin{isamarkuptxt}%
    89 \noindent
    90 In the other case we set \isa{t} to \isa{p\ {\isadigit{1}}} and simplify matters:%
    91 \end{isamarkuptxt}%
    92 \isacommand{apply}{\isacharparenleft}erule{\isacharunderscore}tac\ x\ {\isacharequal}\ {\isachardoublequote}p\ {\isadigit{1}}{\isachardoublequote}\ \isakeyword{in}\ allE{\isacharparenright}\isanewline
    93 \isacommand{apply}{\isacharparenleft}clarsimp{\isacharparenright}%
    94 \begin{isamarkuptxt}%
    95 \begin{isabelle}%
    96 \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ {\isasymlbrakk}{\isasymforall}i{\isachardot}\ {\isacharparenleft}p\ i{\isacharcomma}\ p\ {\isacharparenleft}Suc\ i{\isacharparenright}{\isacharparenright}\ {\isasymin}\ M{\isacharsemicolon}\isanewline
    97 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ \ \ \ }{\isasymforall}pa{\isachardot}\ p\ {\isadigit{1}}\ {\isacharequal}\ pa\ {\isadigit{0}}\ {\isasymand}\ {\isacharparenleft}{\isasymforall}i{\isachardot}\ {\isacharparenleft}pa\ i{\isacharcomma}\ pa\ {\isacharparenleft}Suc\ i{\isacharparenright}{\isacharparenright}\ {\isasymin}\ M{\isacharparenright}\ {\isasymlongrightarrow}\isanewline
    98 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ \ \ \ {\isasymforall}pa{\isachardot}\ }{\isacharparenleft}{\isasymexists}i{\isachardot}\ pa\ i\ {\isasymin}\ A{\isacharparenright}{\isasymrbrakk}\isanewline
    99 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}p{\isachardot}\ }{\isasymLongrightarrow}\ {\isasymexists}i{\isachardot}\ p\ i\ {\isasymin}\ A%
   100 \end{isabelle}
   101 It merely remains to set \isa{pa} to \isa{{\isasymlambda}i{\isachardot}\ p\ {\isacharparenleft}i\ {\isacharplus}\ {\isadigit{1}}{\isacharparenright}}, i.e.\ \isa{p} without its
   102 first element. The rest is practically automatic:%
   103 \end{isamarkuptxt}%
   104 \isacommand{apply}{\isacharparenleft}erule{\isacharunderscore}tac\ x\ {\isacharequal}\ {\isachardoublequote}{\isasymlambda}i{\isachardot}\ p{\isacharparenleft}i{\isacharplus}{\isadigit{1}}{\isacharparenright}{\isachardoublequote}\ \isakeyword{in}\ allE{\isacharparenright}\isanewline
   105 \isacommand{apply}\ simp\isanewline
   106 \isacommand{apply}\ blast\isanewline
   107 \isacommand{done}%
   108 \begin{isamarkuptext}%
   109 The opposite inclusion is proved by contradiction: if some state
   110 \isa{s} is not in \isa{lfp\ {\isacharparenleft}af\ A{\isacharparenright}}, then we can construct an
   111 infinite \isa{A}-avoiding path starting from \isa{s}. The reason is
   112 that by unfolding \isa{lfp} we find that if \isa{s} is not in
   113 \isa{lfp\ {\isacharparenleft}af\ A{\isacharparenright}}, then \isa{s} is not in \isa{A} and there is a
   114 direct successor of \isa{s} that is again not in \isa{lfp\ {\isacharparenleft}af\ A{\isacharparenright}}. Iterating this argument yields the promised infinite
   115 \isa{A}-avoiding path. Let us formalize this sketch.
   116 
   117 The one-step argument in the sketch above
   118 is proved by a variant of contraposition:%
   119 \end{isamarkuptext}%
   120 \isacommand{lemma}\ not{\isacharunderscore}in{\isacharunderscore}lfp{\isacharunderscore}afD{\isacharcolon}\isanewline
   121 \ {\isachardoublequote}s\ {\isasymnotin}\ lfp{\isacharparenleft}af\ A{\isacharparenright}\ {\isasymLongrightarrow}\ s\ {\isasymnotin}\ A\ {\isasymand}\ {\isacharparenleft}{\isasymexists}\ t{\isachardot}\ {\isacharparenleft}s{\isacharcomma}t{\isacharparenright}{\isasymin}M\ {\isasymand}\ t\ {\isasymnotin}\ lfp{\isacharparenleft}af\ A{\isacharparenright}{\isacharparenright}{\isachardoublequote}\isanewline
   122 \isacommand{apply}{\isacharparenleft}erule\ contrapos{\isacharunderscore}np{\isacharparenright}\isanewline
   123 \isacommand{apply}{\isacharparenleft}rule\ ssubst{\isacharbrackleft}OF\ lfp{\isacharunderscore}unfold{\isacharbrackleft}OF\ mono{\isacharunderscore}af{\isacharbrackright}{\isacharbrackright}{\isacharparenright}\isanewline
   124 \isacommand{apply}{\isacharparenleft}simp\ add{\isacharcolon}af{\isacharunderscore}def{\isacharparenright}\isanewline
   125 \isacommand{done}%
   126 \begin{isamarkuptext}%
   127 \noindent
   128 We assume the negation of the conclusion and prove \isa{s\ {\isasymin}\ lfp\ {\isacharparenleft}af\ A{\isacharparenright}}.
   129 Unfolding \isa{lfp} once and
   130 simplifying with the definition of \isa{af} finishes the proof.
   131 
   132 Now we iterate this process. The following construction of the desired
   133 path is parameterized by a predicate \isa{Q} that should hold along the path:%
   134 \end{isamarkuptext}%
   135 \isacommand{consts}\ path\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}state\ {\isasymRightarrow}\ {\isacharparenleft}state\ {\isasymRightarrow}\ bool{\isacharparenright}\ {\isasymRightarrow}\ {\isacharparenleft}nat\ {\isasymRightarrow}\ state{\isacharparenright}{\isachardoublequote}\isanewline
   136 \isacommand{primrec}\isanewline
   137 {\isachardoublequote}path\ s\ Q\ {\isadigit{0}}\ {\isacharequal}\ s{\isachardoublequote}\isanewline
   138 {\isachardoublequote}path\ s\ Q\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}SOME\ t{\isachardot}\ {\isacharparenleft}path\ s\ Q\ n{\isacharcomma}t{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ t{\isacharparenright}{\isachardoublequote}%
   139 \begin{isamarkuptext}%
   140 \noindent
   141 Element \isa{n\ {\isacharplus}\ {\isadigit{1}}} on this path is some arbitrary successor
   142 \isa{t} of element \isa{n} such that \isa{Q\ t} holds.  Remember that \isa{SOME\ t{\isachardot}\ R\ t}
   143 is some arbitrary but fixed \isa{t} such that \isa{R\ t} holds (see \S\ref{sec:SOME}). Of
   144 course, such a \isa{t} need not exist, but that is of no
   145 concern to us since we will only use \isa{path} when a
   146 suitable \isa{t} does exist.
   147 
   148 Let us show that if each state \isa{s} that satisfies \isa{Q}
   149 has a successor that again satisfies \isa{Q}, then there exists an infinite \isa{Q}-path:%
   150 \end{isamarkuptext}%
   151 \isacommand{lemma}\ infinity{\isacharunderscore}lemma{\isacharcolon}\isanewline
   152 \ \ {\isachardoublequote}{\isasymlbrakk}\ Q\ s{\isacharsemicolon}\ {\isasymforall}s{\isachardot}\ Q\ s\ {\isasymlongrightarrow}\ {\isacharparenleft}{\isasymexists}\ t{\isachardot}\ {\isacharparenleft}s{\isacharcomma}t{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ t{\isacharparenright}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\isanewline
   153 \ \ \ {\isasymexists}p{\isasymin}Paths\ s{\isachardot}\ {\isasymforall}i{\isachardot}\ Q{\isacharparenleft}p\ i{\isacharparenright}{\isachardoublequote}%
   154 \begin{isamarkuptxt}%
   155 \noindent
   156 First we rephrase the conclusion slightly because we need to prove both the path property
   157 and the fact that \isa{Q} holds simultaneously:%
   158 \end{isamarkuptxt}%
   159 \isacommand{apply}{\isacharparenleft}subgoal{\isacharunderscore}tac\ {\isachardoublequote}{\isasymexists}p{\isachardot}\ s\ {\isacharequal}\ p\ {\isadigit{0}}\ {\isasymand}\ {\isacharparenleft}{\isasymforall}i{\isachardot}\ {\isacharparenleft}p\ i{\isacharcomma}p{\isacharparenleft}i{\isacharplus}{\isadigit{1}}{\isacharparenright}{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q{\isacharparenleft}p\ i{\isacharparenright}{\isacharparenright}{\isachardoublequote}{\isacharparenright}%
   160 \begin{isamarkuptxt}%
   161 \noindent
   162 From this proposition the original goal follows easily:%
   163 \end{isamarkuptxt}%
   164 \ \isacommand{apply}{\isacharparenleft}simp\ add{\isacharcolon}Paths{\isacharunderscore}def{\isacharcomma}\ blast{\isacharparenright}%
   165 \begin{isamarkuptxt}%
   166 \noindent
   167 The new subgoal is proved by providing the witness \isa{path\ s\ Q} for \isa{p}:%
   168 \end{isamarkuptxt}%
   169 \isacommand{apply}{\isacharparenleft}rule{\isacharunderscore}tac\ x\ {\isacharequal}\ {\isachardoublequote}path\ s\ Q{\isachardoublequote}\ \isakeyword{in}\ exI{\isacharparenright}\isanewline
   170 \isacommand{apply}{\isacharparenleft}clarsimp{\isacharparenright}%
   171 \begin{isamarkuptxt}%
   172 \noindent
   173 After simplification and clarification the subgoal has the following compact form
   174 \begin{isabelle}%
   175 \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}i{\isachardot}\ {\isasymlbrakk}Q\ s{\isacharsemicolon}\ {\isasymforall}s{\isachardot}\ Q\ s\ {\isasymlongrightarrow}\ {\isacharparenleft}{\isasymexists}t{\isachardot}\ {\isacharparenleft}s{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ t{\isacharparenright}{\isasymrbrakk}\isanewline
   176 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}i{\isachardot}\ }{\isasymLongrightarrow}\ {\isacharparenleft}path\ s\ Q\ i{\isacharcomma}\ SOME\ t{\isachardot}\ {\isacharparenleft}path\ s\ Q\ i{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ t{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\isanewline
   177 \isaindent{\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}i{\isachardot}\ {\isasymLongrightarrow}\ }Q\ {\isacharparenleft}path\ s\ Q\ i{\isacharparenright}%
   178 \end{isabelle}
   179 and invites a proof by induction on \isa{i}:%
   180 \end{isamarkuptxt}%
   181 \isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ i{\isacharparenright}\isanewline
   182 \ \isacommand{apply}{\isacharparenleft}simp{\isacharparenright}%
   183 \begin{isamarkuptxt}%
   184 \noindent
   185 After simplification the base case boils down to
   186 \begin{isabelle}%
   187 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}Q\ s{\isacharsemicolon}\ {\isasymforall}s{\isachardot}\ Q\ s\ {\isasymlongrightarrow}\ {\isacharparenleft}{\isasymexists}t{\isachardot}\ {\isacharparenleft}s{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ t{\isacharparenright}{\isasymrbrakk}\isanewline
   188 \isaindent{\ {\isadigit{1}}{\isachardot}\ }{\isasymLongrightarrow}\ {\isacharparenleft}s{\isacharcomma}\ SOME\ t{\isachardot}\ {\isacharparenleft}s{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ t{\isacharparenright}\ {\isasymin}\ M%
   189 \end{isabelle}
   190 The conclusion looks exceedingly trivial: after all, \isa{t} is chosen such that \isa{{\isacharparenleft}s{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M}
   191 holds. However, we first have to show that such a \isa{t} actually exists! This reasoning
   192 is embodied in the theorem \isa{someI{\isadigit{2}}{\isacharunderscore}ex}:
   193 \begin{isabelle}%
   194 \ \ \ \ \ {\isasymlbrakk}{\isasymexists}a{\isachardot}\ {\isacharquery}P\ a{\isacharsemicolon}\ {\isasymAnd}x{\isachardot}\ {\isacharquery}P\ x\ {\isasymLongrightarrow}\ {\isacharquery}Q\ x{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharquery}Q\ {\isacharparenleft}SOME\ x{\isachardot}\ {\isacharquery}P\ x{\isacharparenright}%
   195 \end{isabelle}
   196 When we apply this theorem as an introduction rule, \isa{{\isacharquery}P\ x} becomes
   197 \isa{{\isacharparenleft}s{\isacharcomma}\ x{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ x} and \isa{{\isacharquery}Q\ x} becomes \isa{{\isacharparenleft}s{\isacharcomma}\ x{\isacharparenright}\ {\isasymin}\ M} and we have to prove
   198 two subgoals: \isa{{\isasymexists}a{\isachardot}\ {\isacharparenleft}s{\isacharcomma}\ a{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ a}, which follows from the assumptions, and
   199 \isa{{\isacharparenleft}s{\isacharcomma}\ x{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ x\ {\isasymLongrightarrow}\ {\isacharparenleft}s{\isacharcomma}\ x{\isacharparenright}\ {\isasymin}\ M}, which is trivial. Thus it is not surprising that
   200 \isa{fast} can prove the base case quickly:%
   201 \end{isamarkuptxt}%
   202 \ \isacommand{apply}{\isacharparenleft}fast\ intro{\isacharcolon}someI{\isadigit{2}}{\isacharunderscore}ex{\isacharparenright}%
   203 \begin{isamarkuptxt}%
   204 \noindent
   205 What is worth noting here is that we have used \isa{fast} rather than
   206 \isa{blast}.  The reason is that \isa{blast} would fail because it cannot
   207 cope with \isa{someI{\isadigit{2}}{\isacharunderscore}ex}: unifying its conclusion with the current
   208 subgoal is nontrivial because of the nested schematic variables. For
   209 efficiency reasons \isa{blast} does not even attempt such unifications.
   210 Although \isa{fast} can in principle cope with complicated unification
   211 problems, in practice the number of unifiers arising is often prohibitive and
   212 the offending rule may need to be applied explicitly rather than
   213 automatically. This is what happens in the step case.
   214 
   215 The induction step is similar, but more involved, because now we face nested
   216 occurrences of \isa{SOME}. As a result, \isa{fast} is no longer able to
   217 solve the subgoal and we apply \isa{someI{\isadigit{2}}{\isacharunderscore}ex} by hand.  We merely
   218 show the proof commands but do not describe the details:%
   219 \end{isamarkuptxt}%
   220 \isacommand{apply}{\isacharparenleft}simp{\isacharparenright}\isanewline
   221 \isacommand{apply}{\isacharparenleft}rule\ someI{\isadigit{2}}{\isacharunderscore}ex{\isacharparenright}\isanewline
   222 \ \isacommand{apply}{\isacharparenleft}blast{\isacharparenright}\isanewline
   223 \isacommand{apply}{\isacharparenleft}rule\ someI{\isadigit{2}}{\isacharunderscore}ex{\isacharparenright}\isanewline
   224 \ \isacommand{apply}{\isacharparenleft}blast{\isacharparenright}\isanewline
   225 \isacommand{apply}{\isacharparenleft}blast{\isacharparenright}\isanewline
   226 \isacommand{done}%
   227 \begin{isamarkuptext}%
   228 Function \isa{path} has fulfilled its purpose now and can be forgotten.
   229 It was merely defined to provide the witness in the proof of the
   230 \isa{infinity{\isacharunderscore}lemma}. Aficionados of minimal proofs might like to know
   231 that we could have given the witness without having to define a new function:
   232 the term
   233 \begin{isabelle}%
   234 \ \ \ \ \ nat{\isacharunderscore}rec\ s\ {\isacharparenleft}{\isasymlambda}n\ t{\isachardot}\ SOME\ u{\isachardot}\ {\isacharparenleft}t{\isacharcomma}\ u{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ Q\ u{\isacharparenright}%
   235 \end{isabelle}
   236 is extensionally equal to \isa{path\ s\ Q},
   237 where \isa{nat{\isacharunderscore}rec} is the predefined primitive recursor on \isa{nat}.%
   238 \end{isamarkuptext}%
   239 %
   240 \begin{isamarkuptext}%
   241 At last we can prove the opposite direction of \isa{AF{\isacharunderscore}lemma{\isadigit{1}}}:%
   242 \end{isamarkuptext}%
   243 \isacommand{theorem}\ AF{\isacharunderscore}lemma{\isadigit{2}}{\isacharcolon}\ {\isachardoublequote}{\isacharbraceleft}s{\isachardot}\ {\isasymforall}\ p\ {\isasymin}\ Paths\ s{\isachardot}\ {\isasymexists}\ i{\isachardot}\ p\ i\ {\isasymin}\ A{\isacharbraceright}\ {\isasymsubseteq}\ lfp{\isacharparenleft}af\ A{\isacharparenright}{\isachardoublequote}%
   244 \begin{isamarkuptxt}%
   245 \noindent
   246 The proof is again pointwise and then by contraposition:%
   247 \end{isamarkuptxt}%
   248 \isacommand{apply}{\isacharparenleft}rule\ subsetI{\isacharparenright}\isanewline
   249 \isacommand{apply}{\isacharparenleft}erule\ contrapos{\isacharunderscore}pp{\isacharparenright}\isanewline
   250 \isacommand{apply}\ simp%
   251 \begin{isamarkuptxt}%
   252 \begin{isabelle}%
   253 \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ x\ {\isasymnotin}\ lfp\ {\isacharparenleft}af\ A{\isacharparenright}\ {\isasymLongrightarrow}\ {\isasymexists}p{\isasymin}Paths\ x{\isachardot}\ {\isasymforall}i{\isachardot}\ p\ i\ {\isasymnotin}\ A%
   254 \end{isabelle}
   255 Applying the \isa{infinity{\isacharunderscore}lemma} as a destruction rule leaves two subgoals, the second
   256 premise of \isa{infinity{\isacharunderscore}lemma} and the original subgoal:%
   257 \end{isamarkuptxt}%
   258 \isacommand{apply}{\isacharparenleft}drule\ infinity{\isacharunderscore}lemma{\isacharparenright}%
   259 \begin{isamarkuptxt}%
   260 \begin{isabelle}%
   261 \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ {\isasymforall}s{\isachardot}\ s\ {\isasymnotin}\ lfp\ {\isacharparenleft}af\ A{\isacharparenright}\ {\isasymlongrightarrow}\ {\isacharparenleft}{\isasymexists}t{\isachardot}\ {\isacharparenleft}s{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ t\ {\isasymnotin}\ lfp\ {\isacharparenleft}af\ A{\isacharparenright}{\isacharparenright}\isanewline
   262 \ {\isadigit{2}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ {\isasymexists}p{\isasymin}Paths\ x{\isachardot}\ {\isasymforall}i{\isachardot}\ p\ i\ {\isasymnotin}\ lfp\ {\isacharparenleft}af\ A{\isacharparenright}\ {\isasymLongrightarrow}\isanewline
   263 \isaindent{\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ }{\isasymexists}p{\isasymin}Paths\ x{\isachardot}\ {\isasymforall}i{\isachardot}\ p\ i\ {\isasymnotin}\ A%
   264 \end{isabelle}
   265 Both are solved automatically:%
   266 \end{isamarkuptxt}%
   267 \ \isacommand{apply}{\isacharparenleft}auto\ dest{\isacharcolon}not{\isacharunderscore}in{\isacharunderscore}lfp{\isacharunderscore}afD{\isacharparenright}\isanewline
   268 \isacommand{done}%
   269 \begin{isamarkuptext}%
   270 If you find these proofs too complicated, we recommend that you read
   271 \S\ref{sec:CTL-revisited}, where we show how inductive definitions lead to
   272 simpler arguments.
   273 
   274 The main theorem is proved as for PDL, except that we also derive the
   275 necessary equality \isa{lfp{\isacharparenleft}af\ A{\isacharparenright}\ {\isacharequal}\ {\isachardot}{\isachardot}{\isachardot}} by combining
   276 \isa{AF{\isacharunderscore}lemma{\isadigit{1}}} and \isa{AF{\isacharunderscore}lemma{\isadigit{2}}} on the spot:%
   277 \end{isamarkuptext}%
   278 \isacommand{theorem}\ {\isachardoublequote}mc\ f\ {\isacharequal}\ {\isacharbraceleft}s{\isachardot}\ s\ {\isasymTurnstile}\ f{\isacharbraceright}{\isachardoublequote}\isanewline
   279 \isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ f{\isacharparenright}\isanewline
   280 \isacommand{apply}{\isacharparenleft}auto\ simp\ add{\isacharcolon}\ EF{\isacharunderscore}lemma\ equalityI{\isacharbrackleft}OF\ AF{\isacharunderscore}lemma{\isadigit{1}}\ AF{\isacharunderscore}lemma{\isadigit{2}}{\isacharbrackright}{\isacharparenright}\isanewline
   281 \isacommand{done}%
   282 \begin{isamarkuptext}%
   283 The language defined above is not quite CTL\@. The latter also includes an
   284 until-operator \isa{EU\ f\ g} with semantics ``there exists a path
   285 where \isa{f} is true until \isa{g} becomes true''. With the help
   286 of an auxiliary function%
   287 \end{isamarkuptext}%
   288 \isacommand{consts}\ until{\isacharcolon}{\isacharcolon}\ {\isachardoublequote}state\ set\ {\isasymRightarrow}\ state\ set\ {\isasymRightarrow}\ state\ {\isasymRightarrow}\ state\ list\ {\isasymRightarrow}\ bool{\isachardoublequote}\isanewline
   289 \isacommand{primrec}\isanewline
   290 {\isachardoublequote}until\ A\ B\ s\ {\isacharbrackleft}{\isacharbrackright}\ \ \ \ {\isacharequal}\ {\isacharparenleft}s\ {\isasymin}\ B{\isacharparenright}{\isachardoublequote}\isanewline
   291 {\isachardoublequote}until\ A\ B\ s\ {\isacharparenleft}t{\isacharhash}p{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}s\ {\isasymin}\ A\ {\isasymand}\ {\isacharparenleft}s{\isacharcomma}t{\isacharparenright}\ {\isasymin}\ M\ {\isasymand}\ until\ A\ B\ t\ p{\isacharparenright}{\isachardoublequote}%
   292 \begin{isamarkuptext}%
   293 \noindent
   294 the semantics of \isa{EU} is straightforward:
   295 \begin{isabelle}%
   296 \ \ \ \ \ s\ {\isasymTurnstile}\ EU\ f\ g\ {\isacharequal}\ {\isacharparenleft}{\isasymexists}p{\isachardot}\ until\ A\ B\ s\ p{\isacharparenright}%
   297 \end{isabelle}
   298 Note that \isa{EU} is not definable in terms of the other operators!
   299 
   300 Model checking \isa{EU} is again a least fixed point construction:
   301 \begin{isabelle}%
   302 \ \ \ \ \ mc{\isacharparenleft}EU\ f\ g{\isacharparenright}\ {\isacharequal}\ lfp{\isacharparenleft}{\isasymlambda}T{\isachardot}\ mc\ g\ {\isasymunion}\ mc\ f\ {\isasyminter}\ {\isacharparenleft}M{\isasyminverse}\ {\isacharbackquote}{\isacharbackquote}\ T{\isacharparenright}{\isacharparenright}%
   303 \end{isabelle}
   304 
   305 \begin{exercise}
   306 Extend the datatype of formulae by the above until operator
   307 and prove the equivalence between semantics and model checking, i.e.\ that
   308 \begin{isabelle}%
   309 \ \ \ \ \ mc\ {\isacharparenleft}EU\ f\ g{\isacharparenright}\ {\isacharequal}\ {\isacharbraceleft}s{\isachardot}\ s\ {\isasymTurnstile}\ EU\ f\ g{\isacharbraceright}%
   310 \end{isabelle}
   311 %For readability you may want to annotate {term EU} with its customary syntax
   312 %{text[display]"| EU formula formula    E[_ U _]"}
   313 %which enables you to read and write {text"E[f U g]"} instead of {term"EU f g"}.
   314 \end{exercise}
   315 For more CTL exercises see, for example, Huth and Ryan \cite{Huth-Ryan-book}.%
   316 \end{isamarkuptext}%
   317 %
   318 \begin{isamarkuptext}%
   319 Let us close this section with a few words about the executability of our model checkers.
   320 It is clear that if all sets are finite, they can be represented as lists and the usual
   321 set operations are easily implemented. Only \isa{lfp} requires a little thought.
   322 Fortunately, the HOL Library%
   323 \footnote{See theory \isa{While_Combinator_Example}.}
   324 provides a theorem stating that 
   325 in the case of finite sets and a monotone function~\isa{F},
   326 the value of \isa{lfp\ F} can be computed by iterated application of \isa{F} to~\isa{{\isacharbraceleft}{\isacharbraceright}} until
   327 a fixed point is reached. It is actually possible to generate executable functional programs
   328 from HOL definitions, but that is beyond the scope of the tutorial.%
   329 \end{isamarkuptext}%
   330 \end{isabellebody}%
   331 %%% Local Variables:
   332 %%% mode: latex
   333 %%% TeX-master: "root"
   334 %%% End: