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