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