| 17914 |      1 | (*<*)theory PDL imports Base begin(*>*)
 | 
| 9958 |      2 | 
 | 
| 10971 |      3 | subsection{*Propositional Dynamic Logic --- PDL*}
 | 
| 9958 |      4 | 
 | 
| 10178 |      5 | text{*\index{PDL|(}
 | 
| 11458 |      6 | The formulae of PDL are built up from atomic propositions via
 | 
|  |      7 | negation and conjunction and the two temporal
 | 
|  |      8 | connectives @{text AX} and @{text EF}\@. Since formulae are essentially
 | 
|  |      9 | syntax trees, they are naturally modelled as a datatype:%
 | 
|  |     10 | \footnote{The customary definition of PDL
 | 
| 11207 |     11 | \cite{HarelKT-DL} looks quite different from ours, but the two are easily
 | 
| 11458 |     12 | shown to be equivalent.}
 | 
| 10133 |     13 | *}
 | 
| 9958 |     14 | 
 | 
| 18724 |     15 | datatype formula = Atom "atom"
 | 
| 10149 |     16 |                   | Neg formula
 | 
|  |     17 |                   | And formula formula
 | 
|  |     18 |                   | AX formula
 | 
|  |     19 |                   | EF formula
 | 
| 10133 |     20 | 
 | 
|  |     21 | text{*\noindent
 | 
| 11458 |     22 | This resembles the boolean expression case study in
 | 
| 10867 |     23 | \S\ref{sec:boolex}.
 | 
| 11458 |     24 | A validity relation between
 | 
|  |     25 | states and formulae specifies the semantics:
 | 
| 10133 |     26 | *}
 | 
|  |     27 | 
 | 
| 10149 |     28 | consts valid :: "state \<Rightarrow> formula \<Rightarrow> bool"   ("(_ \<Turnstile> _)" [80,80] 80)
 | 
|  |     29 | 
 | 
|  |     30 | text{*\noindent
 | 
| 10867 |     31 | The syntax annotation allows us to write @{term"s \<Turnstile> f"} instead of
 | 
|  |     32 | \hbox{@{text"valid s f"}}.
 | 
| 10149 |     33 | The definition of @{text"\<Turnstile>"} is by recursion over the syntax:
 | 
|  |     34 | *}
 | 
| 9958 |     35 | 
 | 
|  |     36 | primrec
 | 
| 10133 |     37 | "s \<Turnstile> Atom a  = (a \<in> L s)"
 | 
| 10149 |     38 | "s \<Turnstile> Neg f   = (\<not>(s \<Turnstile> f))"
 | 
| 9958 |     39 | "s \<Turnstile> And f g = (s \<Turnstile> f \<and> s \<Turnstile> g)"
 | 
|  |     40 | "s \<Turnstile> AX f    = (\<forall>t. (s,t) \<in> M \<longrightarrow> t \<Turnstile> f)"
 | 
| 12631 |     41 | "s \<Turnstile> EF f    = (\<exists>t. (s,t) \<in> M\<^sup>* \<and> t \<Turnstile> f)"
 | 
| 9958 |     42 | 
 | 
| 10149 |     43 | text{*\noindent
 | 
|  |     44 | The first three equations should be self-explanatory. The temporal formula
 | 
| 10983 |     45 | @{term"AX f"} means that @{term f} is true in \emph{A}ll ne\emph{X}t states whereas
 | 
|  |     46 | @{term"EF f"} means that there \emph{E}xists some \emph{F}uture state in which @{term f} is
 | 
| 10867 |     47 | true. The future is expressed via @{text"\<^sup>*"}, the reflexive transitive
 | 
| 10149 |     48 | closure. Because of reflexivity, the future includes the present.
 | 
|  |     49 | 
 | 
| 10133 |     50 | Now we come to the model checker itself. It maps a formula into the set of
 | 
| 11458 |     51 | states where the formula is true.  It too is defined by recursion over the syntax:
 | 
| 10133 |     52 | *}
 | 
|  |     53 | 
 | 
| 12631 |     54 | consts mc :: "formula \<Rightarrow> state set"
 | 
| 9958 |     55 | primrec
 | 
| 10133 |     56 | "mc(Atom a)  = {s. a \<in> L s}"
 | 
| 10149 |     57 | "mc(Neg f)   = -mc f"
 | 
| 10133 |     58 | "mc(And f g) = mc f \<inter> mc g"
 | 
| 9958 |     59 | "mc(AX f)    = {s. \<forall>t. (s,t) \<in> M  \<longrightarrow> t \<in> mc f}"
 | 
| 10867 |     60 | "mc(EF f)    = lfp(\<lambda>T. mc f \<union> (M\<inverse> `` T))"
 | 
| 10133 |     61 | 
 | 
| 10149 |     62 | text{*\noindent
 | 
|  |     63 | Only the equation for @{term EF} deserves some comments. Remember that the
 | 
| 10839 |     64 | postfix @{text"\<inverse>"} and the infix @{text"``"} are predefined and denote the
 | 
| 10867 |     65 | converse of a relation and the image of a set under a relation.  Thus
 | 
| 10839 |     66 | @{term "M\<inverse> `` T"} is the set of all predecessors of @{term T} and the least
 | 
|  |     67 | fixed point (@{term lfp}) of @{term"\<lambda>T. mc f \<union> M\<inverse> `` T"} is the least set
 | 
| 10149 |     68 | @{term T} containing @{term"mc f"} and all predecessors of @{term T}. If you
 | 
|  |     69 | find it hard to see that @{term"mc(EF f)"} contains exactly those states from
 | 
| 10983 |     70 | which there is a path to a state where @{term f} is true, do not worry --- this
 | 
| 10149 |     71 | will be proved in a moment.
 | 
|  |     72 | 
 | 
|  |     73 | First we prove monotonicity of the function inside @{term lfp}
 | 
| 10867 |     74 | in order to make sure it really has a least fixed point.
 | 
| 10133 |     75 | *}
 | 
|  |     76 | 
 | 
| 10867 |     77 | lemma mono_ef: "mono(\<lambda>T. A \<union> (M\<inverse> `` T))"
 | 
| 10149 |     78 | apply(rule monoI)
 | 
| 10159 |     79 | apply blast
 | 
|  |     80 | done
 | 
| 10149 |     81 | 
 | 
|  |     82 | text{*\noindent
 | 
|  |     83 | Now we can relate model checking and semantics. For the @{text EF} case we need
 | 
|  |     84 | a separate lemma:
 | 
|  |     85 | *}
 | 
|  |     86 | 
 | 
|  |     87 | lemma EF_lemma:
 | 
| 10867 |     88 |   "lfp(\<lambda>T. A \<union> (M\<inverse> `` T)) = {s. \<exists>t. (s,t) \<in> M\<^sup>* \<and> t \<in> A}"
 | 
| 10149 |     89 | 
 | 
|  |     90 | txt{*\noindent
 | 
|  |     91 | The equality is proved in the canonical fashion by proving that each set
 | 
| 10867 |     92 | includes the other; the inclusion is shown pointwise:
 | 
| 10149 |     93 | *}
 | 
|  |     94 | 
 | 
| 12631 |     95 | apply(rule equalityI)
 | 
|  |     96 |  apply(rule subsetI)
 | 
| 10524 |     97 |  apply(simp)(*<*)apply(rename_tac s)(*>*)
 | 
| 10363 |     98 | 
 | 
| 10149 |     99 | txt{*\noindent
 | 
|  |    100 | Simplification leaves us with the following first subgoal
 | 
| 10363 |    101 | @{subgoals[display,indent=0,goals_limit=1]}
 | 
| 10149 |    102 | which is proved by @{term lfp}-induction:
 | 
|  |    103 | *}
 | 
|  |    104 | 
 | 
| 21202 |    105 |  apply(erule lfp_induct_set)
 | 
| 10149 |    106 |   apply(rule mono_ef)
 | 
|  |    107 |  apply(simp)
 | 
|  |    108 | (*pr(latex xsymbols symbols);*)
 | 
|  |    109 | txt{*\noindent
 | 
|  |    110 | Having disposed of the monotonicity subgoal,
 | 
| 11458 |    111 | simplification leaves us with the following goal:
 | 
| 10149 |    112 | \begin{isabelle}
 | 
| 10801 |    113 | \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ x\ {\isasymin}\ A\ {\isasymor}\isanewline
 | 
| 10895 |    114 | \ \ \ \ \ \ \ \ \ x\ {\isasymin}\ M{\isasyminverse}\ {\isacharbackquote}{\isacharbackquote}\ {\isacharparenleft}lfp\ {\isacharparenleft}\dots{\isacharparenright}\ {\isasyminter}\ {\isacharbraceleft}x{\isachardot}\ {\isasymexists}t{\isachardot}\ {\isacharparenleft}x{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M\isactrlsup {\isacharasterisk}\ {\isasymand}\ t\ {\isasymin}\ A{\isacharbraceright}{\isacharparenright}\isanewline
 | 
| 10801 |    115 | \ \ \ \ \ \ \ \ {\isasymLongrightarrow}\ {\isasymexists}t{\isachardot}\ {\isacharparenleft}x{\isacharcomma}\ t{\isacharparenright}\ {\isasymin}\ M\isactrlsup {\isacharasterisk}\ {\isasymand}\ t\ {\isasymin}\ A
 | 
| 10149 |    116 | \end{isabelle}
 | 
| 11458 |    117 | It is proved by @{text blast}, using the transitivity of 
 | 
|  |    118 | \isa{M\isactrlsup {\isacharasterisk}}.
 | 
| 10149 |    119 | *}
 | 
|  |    120 | 
 | 
| 12631 |    121 |  apply(blast intro: rtrancl_trans)
 | 
| 10149 |    122 | 
 | 
|  |    123 | txt{*
 | 
| 10867 |    124 | We now return to the second set inclusion subgoal, which is again proved
 | 
| 10149 |    125 | pointwise:
 | 
|  |    126 | *}
 | 
|  |    127 | 
 | 
|  |    128 | apply(rule subsetI)
 | 
|  |    129 | apply(simp, clarify)
 | 
| 10363 |    130 | 
 | 
| 10149 |    131 | txt{*\noindent
 | 
|  |    132 | After simplification and clarification we are left with
 | 
| 10363 |    133 | @{subgoals[display,indent=0,goals_limit=1]}
 | 
| 10801 |    134 | This goal is proved by induction on @{term"(s,t)\<in>M\<^sup>*"}. But since the model
 | 
| 10149 |    135 | checker works backwards (from @{term t} to @{term s}), we cannot use the
 | 
| 11458 |    136 | induction theorem @{thm[source]rtrancl_induct}: it works in the
 | 
| 10149 |    137 | forward direction. Fortunately the converse induction theorem
 | 
|  |    138 | @{thm[source]converse_rtrancl_induct} already exists:
 | 
|  |    139 | @{thm[display,margin=60]converse_rtrancl_induct[no_vars]}
 | 
| 10801 |    140 | It says that if @{prop"(a,b):r\<^sup>*"} and we know @{prop"P b"} then we can infer
 | 
| 10149 |    141 | @{prop"P a"} provided each step backwards from a predecessor @{term z} of
 | 
|  |    142 | @{term b} preserves @{term P}.
 | 
|  |    143 | *}
 | 
|  |    144 | 
 | 
|  |    145 | apply(erule converse_rtrancl_induct)
 | 
| 10363 |    146 | 
 | 
| 10149 |    147 | txt{*\noindent
 | 
|  |    148 | The base case
 | 
| 10363 |    149 | @{subgoals[display,indent=0,goals_limit=1]}
 | 
| 10149 |    150 | is solved by unrolling @{term lfp} once
 | 
|  |    151 | *}
 | 
|  |    152 | 
 | 
| 11231 |    153 |  apply(subst lfp_unfold[OF mono_ef])
 | 
| 10363 |    154 | 
 | 
| 10149 |    155 | txt{*
 | 
| 10363 |    156 | @{subgoals[display,indent=0,goals_limit=1]}
 | 
| 10149 |    157 | and disposing of the resulting trivial subgoal automatically:
 | 
|  |    158 | *}
 | 
|  |    159 | 
 | 
|  |    160 |  apply(blast)
 | 
|  |    161 | 
 | 
|  |    162 | txt{*\noindent
 | 
|  |    163 | The proof of the induction step is identical to the one for the base case:
 | 
|  |    164 | *}
 | 
|  |    165 | 
 | 
| 11231 |    166 | apply(subst lfp_unfold[OF mono_ef])
 | 
| 10159 |    167 | apply(blast)
 | 
|  |    168 | done
 | 
| 10149 |    169 | 
 | 
|  |    170 | text{*
 | 
|  |    171 | The main theorem is proved in the familiar manner: induction followed by
 | 
|  |    172 | @{text auto} augmented with the lemma as a simplification rule.
 | 
|  |    173 | *}
 | 
| 9958 |    174 | 
 | 
| 12631 |    175 | theorem "mc f = {s. s \<Turnstile> f}"
 | 
|  |    176 | apply(induct_tac f)
 | 
| 12815 |    177 | apply(auto simp add: EF_lemma)
 | 
| 12631 |    178 | done
 | 
| 10171 |    179 | 
 | 
|  |    180 | text{*
 | 
|  |    181 | \begin{exercise}
 | 
| 11458 |    182 | @{term AX} has a dual operator @{term EN} 
 | 
|  |    183 | (``there exists a next state such that'')%
 | 
|  |    184 | \footnote{We cannot use the customary @{text EX}: it is reserved
 | 
|  |    185 | as the \textsc{ascii}-equivalent of @{text"\<exists>"}.}
 | 
|  |    186 | with the intended semantics
 | 
| 10171 |    187 | @{prop[display]"(s \<Turnstile> EN f) = (EX t. (s,t) : M & t \<Turnstile> f)"}
 | 
|  |    188 | Fortunately, @{term"EN f"} can already be expressed as a PDL formula. How?
 | 
|  |    189 | 
 | 
|  |    190 | Show that the semantics for @{term EF} satisfies the following recursion equation:
 | 
|  |    191 | @{prop[display]"(s \<Turnstile> EF f) = (s \<Turnstile> f | s \<Turnstile> EN(EF f))"}
 | 
|  |    192 | \end{exercise}
 | 
| 10178 |    193 | \index{PDL|)}
 | 
| 10171 |    194 | *}
 | 
|  |    195 | (*<*)
 | 
| 12631 |    196 | theorem main: "mc f = {s. s \<Turnstile> f}"
 | 
|  |    197 | apply(induct_tac f)
 | 
|  |    198 | apply(auto simp add: EF_lemma)
 | 
|  |    199 | done
 | 
| 10171 |    200 | 
 | 
| 12631 |    201 | lemma aux: "s \<Turnstile> f = (s : mc f)"
 | 
|  |    202 | apply(simp add: main)
 | 
|  |    203 | done
 | 
| 10171 |    204 | 
 | 
| 12631 |    205 | lemma "(s \<Turnstile> EF f) = (s \<Turnstile> f | s \<Turnstile> Neg(AX(Neg(EF f))))"
 | 
|  |    206 | apply(simp only: aux)
 | 
|  |    207 | apply(simp)
 | 
|  |    208 | apply(subst lfp_unfold[OF mono_ef], fast)
 | 
| 10171 |    209 | done
 | 
|  |    210 | 
 | 
|  |    211 | end
 | 
|  |    212 | (*>*)
 |