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