105
|
1 |
%% $Id$
|
|
2 |
\part{Getting started with Isabelle}
|
|
3 |
This Part describes how to perform simple proofs using Isabelle. Although
|
|
4 |
it frequently refers to concepts from the previous Part, a user can get
|
|
5 |
started without understanding them in detail.
|
|
6 |
|
|
7 |
As of this writing, Isabelle's user interface is \ML. Proofs are conducted
|
|
8 |
by applying certain \ML{} functions, which update a stored proof state.
|
|
9 |
Logics are combined and extended by calling \ML{} functions. All syntax
|
|
10 |
must be expressed using {\sc ascii} characters. Menu-driven graphical
|
|
11 |
interfaces are under construction, but Isabelle users will always need to
|
|
12 |
know some \ML, at least to use tacticals.
|
|
13 |
|
|
14 |
Object-logics are built upon Pure Isabelle, which implements the meta-logic
|
|
15 |
and provides certain fundamental data structures: types, terms, signatures,
|
|
16 |
theorems and theories, tactics and tacticals. These data structures have
|
|
17 |
the corresponding \ML{} types {\tt typ}, {\tt term}, {\tt Sign.sg}, {\tt thm},
|
|
18 |
{\tt theory} and {\tt tactic}; tacticals have function types such as {\tt
|
|
19 |
tactic->tactic}. Isabelle users can operate on these data structures by
|
|
20 |
writing \ML{} programs.
|
|
21 |
|
|
22 |
\section{Forward proof}
|
|
23 |
\index{Isabelle!getting started}\index{ML}
|
|
24 |
This section describes the concrete syntax for types, terms and theorems,
|
|
25 |
and demonstrates forward proof.
|
|
26 |
|
|
27 |
\subsection{Lexical matters}
|
|
28 |
\index{identifiers|bold}\index{reserved words|bold}
|
|
29 |
An {\bf identifier} is a string of letters, digits, underscores~(\verb|_|)
|
|
30 |
and single quotes~({\tt'}), beginning with a letter. Single quotes are
|
|
31 |
regarded as primes; for instance {\tt x'} is read as~$x'$. Identifiers are
|
|
32 |
separated by white space and special characters. {\bf Reserved words} are
|
|
33 |
identifiers that appear in Isabelle syntax definitions.
|
|
34 |
|
|
35 |
An Isabelle theory can declare symbols composed of special characters, such
|
|
36 |
as {\tt=}, {\tt==}, {\tt=>} and {\tt==>}. (The latter three are part of
|
|
37 |
the syntax of the meta-logic.) Such symbols may be run together; thus if
|
|
38 |
\verb|}| and \verb|{| are used for set brackets then \verb|{{a},{a,b}}| is
|
|
39 |
valid notation for a set of sets --- but only if \verb|}}| and \verb|{{|
|
|
40 |
have not been declared as symbols! The parser resolves any ambiguity by
|
|
41 |
taking the longest possible symbol that has been declared. Thus the string
|
|
42 |
{\tt==>} is read as a single symbol. But \hbox{\tt= =>} is read as two
|
|
43 |
symbols, as is \verb|}}|, as discussed above.
|
|
44 |
|
|
45 |
Identifiers that are not reserved words may serve as free variables or
|
|
46 |
constants. A type identifier consists of an identifier prefixed by a
|
|
47 |
prime, for example {\tt'a} and \hbox{\tt'hello}. An unknown (or type
|
|
48 |
unknown) consists of a question mark, an identifier (or type identifier),
|
|
49 |
and a subscript. The subscript, a non-negative integer, allows the
|
|
50 |
renaming of unknowns prior to unification.
|
|
51 |
|
|
52 |
The subscript may appear after the identifier, separated by a dot; this
|
|
53 |
prevents ambiguity when the identifier ends with a digit. Thus {\tt?z6.0}
|
|
54 |
has identifier \verb|"z6"| and subscript~0, while {\tt?a0.5} has identifier
|
|
55 |
\verb|"a0"| and subscript~5. If the identifier does not end with a digit,
|
|
56 |
then no dot appears and a subscript of~0 is omitted; for example,
|
|
57 |
{\tt?hello} has identifier \verb|"hello"| and subscript zero, while
|
|
58 |
{\tt?z6} has identifier \verb|"z"| and subscript~6. The same conventions
|
|
59 |
apply to type unknowns. Note that the question mark is {\bf not} part of the
|
|
60 |
identifier!
|
|
61 |
|
|
62 |
|
|
63 |
\subsection{Syntax of types and terms}
|
|
64 |
\index{Isabelle!syntax of}
|
|
65 |
\index{classes!built-in|bold}
|
|
66 |
Classes are denoted by identifiers; the built-in class \ttindex{logic}
|
|
67 |
contains the `logical' types. Sorts are lists of classes enclosed in
|
|
68 |
braces~\{ and \}; singleton sorts may be abbreviated by dropping the braces.
|
|
69 |
|
|
70 |
\index{types!syntax|bold}
|
|
71 |
Types are written with a syntax like \ML's. The built-in type \ttindex{prop}
|
|
72 |
is the type of propositions. Type variables can be constrained to particular
|
|
73 |
classes or sorts, for example {\tt 'a::term} and {\tt ?'b::\{ord,arith\}}.
|
|
74 |
\[\dquotes
|
|
75 |
\begin{array}{lll}
|
|
76 |
\multicolumn{3}{c}{\hbox{ASCII Notation for Types}} \\ \hline
|
|
77 |
t "::" C & t :: C & \hbox{class constraint} \\
|
|
78 |
t "::" "\{" C@1 "," \ldots "," C@n "\}" &
|
|
79 |
t :: \{C@1,\dots,C@n\} & \hbox{sort constraint} \\
|
|
80 |
\sigma"=>"\tau & \sigma\To\tau & \hbox{function type} \\
|
|
81 |
"[" \sigma@1 "," \ldots "," \sigma@n "] => " \tau &
|
|
82 |
[\sigma@1,\ldots,\sigma@n] \To\tau & \hbox{curried function type} \\
|
|
83 |
"(" \tau@1"," \ldots "," \tau@n ")" tycon &
|
|
84 |
(\tau@1, \ldots, \tau@n)tycon & \hbox{type construction}
|
|
85 |
\end{array}
|
|
86 |
\]
|
|
87 |
Terms are those of the typed $\lambda$-calculus.
|
|
88 |
\index{terms!syntax|bold}
|
|
89 |
\[\dquotes
|
|
90 |
\begin{array}{lll}
|
|
91 |
\multicolumn{3}{c}{\hbox{ASCII Notation for Terms}} \\ \hline
|
|
92 |
t "::" \sigma & t :: \sigma & \hbox{type constraint} \\
|
|
93 |
"\%" x "." t & \lambda x.t & \hbox{abstraction} \\
|
|
94 |
"\%" x@1\ldots x@n "." t & \lambda x@1\ldots x@n.t &
|
|
95 |
\hbox{curried abstraction} \\
|
|
96 |
t "(" u@1"," \ldots "," u@n ")" &
|
|
97 |
t (u@1, \ldots, u@n) & \hbox{curried application}
|
|
98 |
\end{array}
|
|
99 |
\]
|
|
100 |
The theorems and rules of an object-logic are represented by theorems in
|
|
101 |
the meta-logic, which are expressed using meta-formulae. Since the
|
|
102 |
meta-logic is higher-order, meta-formulae~$\phi$, $\psi$, $\theta$,~\ldots{}
|
|
103 |
are just terms of type~\ttindex{prop}.
|
|
104 |
\index{meta-formulae!syntax|bold}
|
|
105 |
\[\dquotes
|
|
106 |
\begin{array}{l@{\quad}l@{\quad}l}
|
|
107 |
\multicolumn{3}{c}{\hbox{ASCII Notation for Meta-Formulae}} \\ \hline
|
|
108 |
a " == " b & a\equiv b & \hbox{meta-equality} \\
|
|
109 |
a " =?= " b & a\qeq b & \hbox{flex-flex constraint} \\
|
|
110 |
\phi " ==> " \psi & \phi\Imp \psi & \hbox{meta-implication} \\
|
|
111 |
"[|" \phi@1 ";" \ldots ";" \phi@n "|] ==> " \psi &
|
|
112 |
\List{\phi@1;\ldots;\phi@n} \Imp \psi & \hbox{nested implication} \\
|
|
113 |
"!!" x "." \phi & \Forall x.\phi & \hbox{meta-quantification} \\
|
|
114 |
"!!" x@1\ldots x@n "." \phi &
|
|
115 |
\Forall x@1. \ldots \Forall x@n.\phi & \hbox{nested quantification}
|
|
116 |
\end{array}
|
|
117 |
\]
|
|
118 |
Flex-flex constraints are meta-equalities arising from unification; they
|
|
119 |
require special treatment. See~\S\ref{flexflex}.
|
|
120 |
\index{flex-flex equations}
|
|
121 |
|
|
122 |
Most logics define the implicit coercion $Trueprop$ from object-formulae to
|
|
123 |
propositions.
|
|
124 |
\index{Trueprop@{$Trueprop$}}
|
|
125 |
This could cause an ambiguity: in $P\Imp Q$, do the variables $P$ and $Q$
|
|
126 |
stand for meta-formulae or object-formulae? If the latter, $P\Imp Q$
|
|
127 |
really abbreviates $Trueprop(P)\Imp Trueprop(Q)$. To prevent such
|
|
128 |
ambiguities, Isabelle's syntax does not allow a meta-formula to consist of
|
|
129 |
a variable. Variables of type~\ttindex{prop} are seldom useful, but you
|
|
130 |
can make a variable stand for a meta-formula by prefixing it with the
|
|
131 |
keyword \ttindex{PROP}:
|
|
132 |
\begin{ttbox}
|
|
133 |
PROP ?psi ==> PROP ?theta
|
|
134 |
\end{ttbox}
|
|
135 |
|
|
136 |
Symbols of object-logics also must be rendered into {\sc ascii}, typically
|
|
137 |
as follows:
|
|
138 |
\[ \begin{tabular}{l@{\quad}l@{\quad}l}
|
|
139 |
\tt True & $\top$ & true \\
|
|
140 |
\tt False & $\bot$ & false \\
|
|
141 |
\tt $P$ \& $Q$ & $P\conj Q$ & conjunction \\
|
|
142 |
\tt $P$ | $Q$ & $P\disj Q$ & disjunction \\
|
|
143 |
\verb'~' $P$ & $\neg P$ & negation \\
|
|
144 |
\tt $P$ --> $Q$ & $P\imp Q$ & implication \\
|
|
145 |
\tt $P$ <-> $Q$ & $P\bimp Q$ & bi-implication \\
|
|
146 |
\tt ALL $x\,y\,z$ .\ $P$ & $\forall x\,y\,z.P$ & for all \\
|
|
147 |
\tt EX $x\,y\,z$ .\ $P$ & $\exists x\,y\,z.P$ & there exists
|
|
148 |
\end{tabular}
|
|
149 |
\]
|
|
150 |
To illustrate the notation, consider two axioms for first-order logic:
|
|
151 |
$$ \List{P; Q} \Imp P\conj Q \eqno(\conj I) $$
|
|
152 |
$$ \List{\exists x.P(x); \Forall x. P(x)\imp Q} \Imp Q \eqno(\exists E) $$
|
|
153 |
Using the {\tt [|\ldots|]} shorthand, $({\conj}I)$ translates literally into
|
|
154 |
{\sc ascii} characters as
|
|
155 |
\begin{ttbox}
|
|
156 |
[| ?P; ?Q |] ==> ?P & ?Q
|
|
157 |
\end{ttbox}
|
|
158 |
The schematic variables let unification instantiate the rule. To
|
|
159 |
avoid cluttering rules with question marks, Isabelle converts any free
|
|
160 |
variables in a rule to schematic variables; we normally write $({\conj}I)$ as
|
|
161 |
\begin{ttbox}
|
|
162 |
[| P; Q |] ==> P & Q
|
|
163 |
\end{ttbox}
|
|
164 |
This variables convention agrees with the treatment of variables in goals.
|
|
165 |
Free variables in a goal remain fixed throughout the proof. After the
|
|
166 |
proof is finished, Isabelle converts them to scheme variables in the
|
|
167 |
resulting theorem. Scheme variables in a goal may be replaced by terms
|
|
168 |
during the proof, supporting answer extraction, program synthesis, and so
|
|
169 |
forth.
|
|
170 |
|
|
171 |
For a final example, the rule $(\exists E)$ is rendered in {\sc ascii} as
|
|
172 |
\begin{ttbox}
|
|
173 |
[| EX x.P(x); !!x. P(x) ==> Q |] ==> Q
|
|
174 |
\end{ttbox}
|
|
175 |
|
|
176 |
|
|
177 |
\subsection{Basic operations on theorems}
|
|
178 |
\index{theorems!basic operations on|bold}
|
|
179 |
\index{LCF}
|
|
180 |
Meta-level theorems have type \ttindex{thm} and represent the theorems and
|
|
181 |
inference rules of object-logics. Isabelle's meta-logic is implemented
|
|
182 |
using the {\sc lcf} approach: each meta-level inference rule is represented by
|
|
183 |
a function from theorems to theorems. Object-level rules are taken as
|
|
184 |
axioms.
|
|
185 |
|
|
186 |
The main theorem printing commands are {\tt prth}, {\tt prths} and~{\tt
|
|
187 |
prthq}. Of the other operations on theorems, most useful are {\tt RS}
|
|
188 |
and {\tt RSN}, which perform resolution.
|
|
189 |
|
|
190 |
\index{printing commands|bold}
|
|
191 |
\begin{description}
|
|
192 |
\item[\ttindexbold{prth} {\it thm}] pretty-prints {\it thm\/} at the terminal.
|
|
193 |
|
|
194 |
\item[\ttindexbold{prths} {\it thms}] pretty-prints {\it thms}, a list of
|
|
195 |
theorems.
|
|
196 |
|
|
197 |
\item[\ttindexbold{prthq} {\it thmq}] pretty-prints {\it thmq}, a sequence of
|
|
198 |
theorems; this is useful for inspecting the output of a tactic.
|
|
199 |
|
|
200 |
\item[\tt$thm1$ RS $thm2$] \indexbold{*RS} resolves the conclusion of $thm1$
|
|
201 |
with the first premise of~$thm2$.
|
|
202 |
|
|
203 |
\item[\tt$thm1$ RSN $(i,thm2)$] \indexbold{*RSN} resolves the conclusion of $thm1$
|
|
204 |
with the $i$th premise of~$thm2$.
|
|
205 |
|
|
206 |
\item[\ttindexbold{standard} $thm$] puts $thm$ into a standard
|
|
207 |
format. It also renames schematic variables to have subscript zero,
|
|
208 |
improving readability and reducing subscript growth.
|
|
209 |
\end{description}
|
|
210 |
\index{ML}
|
|
211 |
The rules of a theory are normally bound to \ML\ identifiers. Suppose we
|
|
212 |
are running an Isabelle session containing natural deduction first-order
|
|
213 |
logic. Let us try an example given in~\S\ref{joining}. We first print
|
|
214 |
\ttindex{mp}, which is the rule~$({\imp}E)$, then resolve it with itself.
|
|
215 |
\begin{ttbox}
|
|
216 |
prth mp;
|
|
217 |
{\out [| ?P --> ?Q; ?P |] ==> ?Q}
|
|
218 |
{\out val it = "[| ?P --> ?Q; ?P |] ==> ?Q" : thm}
|
|
219 |
prth (mp RS mp);
|
|
220 |
{\out [| ?P1 --> ?P --> ?Q; ?P1; ?P |] ==> ?Q}
|
|
221 |
{\out val it = "[| ?P1 --> ?P --> ?Q; ?P1; ?P |] ==> ?Q" : thm}
|
|
222 |
\end{ttbox}
|
|
223 |
In the Isabelle documentation, user's input appears in {\tt typewriter
|
|
224 |
characters}, and output appears in {\sltt slanted typewriter characters}.
|
|
225 |
\ML's response {\out val }~\ldots{} is compiler-dependent and will
|
|
226 |
sometimes be suppressed. This session illustrates two formats for the
|
|
227 |
display of theorems. Isabelle's top-level displays theorems as ML values,
|
|
228 |
enclosed in quotes.\footnote{This works under both Poly/ML and Standard ML
|
|
229 |
of New Jersey.} Printing functions like {\tt prth} omit the quotes and
|
|
230 |
the surrounding {\tt val \ldots :\ thm}.
|
|
231 |
|
|
232 |
To contrast {\tt RS} with {\tt RSN}, we resolve
|
|
233 |
\ttindex{conjunct1}, which stands for~$(\conj E1)$, with~\ttindex{mp}.
|
|
234 |
\begin{ttbox}
|
|
235 |
conjunct1 RS mp;
|
|
236 |
{\out val it = "[| (?P --> ?Q) & ?Q1; ?P |] ==> ?Q" : thm}
|
|
237 |
conjunct1 RSN (2,mp);
|
|
238 |
{\out val it = "[| ?P --> ?Q; ?P & ?Q1 |] ==> ?Q" : thm}
|
|
239 |
\end{ttbox}
|
|
240 |
These correspond to the following proofs:
|
|
241 |
\[ \infer[({\imp}E)]{Q}{\infer[({\conj}E1)]{P\imp Q}{(P\imp Q)\conj Q@1} & P}
|
|
242 |
\qquad
|
|
243 |
\infer[({\imp}E)]{Q}{P\imp Q & \infer[({\conj}E1)]{P}{P\conj Q@1}}
|
|
244 |
\]
|
|
245 |
The printing commands return their argument; the \ML{} identifier~{\tt it}
|
|
246 |
denotes the value just printed. You may derive a rule by pasting other
|
|
247 |
rules together. Below, \ttindex{spec} stands for~$(\forall E)$:
|
|
248 |
\begin{ttbox}
|
|
249 |
spec;
|
|
250 |
{\out val it = "ALL x. ?P(x) ==> ?P(?x)" : thm}
|
|
251 |
it RS mp;
|
|
252 |
{\out val it = "[| ALL x. ?P3(x) --> ?Q2(x); ?P3(?x1) |] ==> ?Q2(?x1)" : thm}
|
|
253 |
it RS conjunct1;
|
|
254 |
{\out val it = "[| ALL x. ?P4(x) --> ?P6(x) & ?Q5(x); ?P4(?x2) |] ==> ?P6(?x2)"}
|
|
255 |
standard it;
|
|
256 |
{\out val it = "[| ALL x. ?P(x) --> ?Pa(x) & ?Q(x); ?P(?x) |] ==> ?Pa(?x)"}
|
|
257 |
\end{ttbox}
|
|
258 |
By resolving $(\forall E)$ with (${\imp}E)$ and (${\conj}E1)$, we have
|
|
259 |
derived a destruction rule for formulae of the form $\forall x.
|
|
260 |
P(x)\imp(Q(x)\conj R(x))$. Used with destruct-resolution, such specialized
|
|
261 |
rules provide a way of referring to particular assumptions.
|
|
262 |
|
|
263 |
\subsection{Flex-flex equations} \label{flexflex}
|
|
264 |
\index{flex-flex equations|bold}\index{unknowns!of function type}
|
|
265 |
In higher-order unification, {\bf flex-flex} equations are those where both
|
|
266 |
sides begin with a function unknown, such as $\Var{f}(0)\qeq\Var{g}(0)$.
|
|
267 |
They admit a trivial unifier, here $\Var{f}\equiv \lambda x.\Var{a}$ and
|
|
268 |
$\Var{g}\equiv \lambda y.\Var{a}$, where $\Var{a}$ is a new unknown. They
|
|
269 |
admit many other unifiers, such as $\Var{f} \equiv \lambda x.\Var{g}(0)$
|
|
270 |
and $\{\Var{f} \equiv \lambda x.x,\, \Var{g} \equiv \lambda x.0\}$. Huet's
|
|
271 |
procedure does not enumerate the unifiers; instead, it retains flex-flex
|
|
272 |
equations as constraints on future unifications. Flex-flex constraints
|
|
273 |
occasionally become attached to a proof state; more frequently, they appear
|
|
274 |
during use of {\tt RS} and~{\tt RSN}:
|
|
275 |
\begin{ttbox}
|
|
276 |
refl;
|
|
277 |
{\out val it = "?a = ?a" : thm}
|
|
278 |
exI;
|
|
279 |
{\out val it = "?P(?x) ==> EX x. ?P(x)" : thm}
|
|
280 |
refl RS exI;
|
|
281 |
{\out val it = "?a3(?x) =?= ?a2(?x) ==> EX x. ?a3(x) = ?a2(x)" : thm}
|
|
282 |
\end{ttbox}
|
|
283 |
|
|
284 |
\noindent
|
|
285 |
Renaming variables, this is $\exists x.\Var{f}(x)=\Var{g}(x)$ with
|
|
286 |
the constraint ${\Var{f}(\Var{u})\qeq\Var{g}(\Var{u})}$. Instances
|
|
287 |
satisfying the constraint include $\exists x.\Var{f}(x)=\Var{f}(x)$ and
|
|
288 |
$\exists x.x=\Var{u}$. Calling \ttindex{flexflex_rule} removes all
|
|
289 |
constraints by applying the trivial unifier:\index{*prthq}
|
|
290 |
\begin{ttbox}
|
|
291 |
prthq (flexflex_rule it);
|
|
292 |
{\out EX x. ?a4 = ?a4}
|
|
293 |
\end{ttbox}
|
|
294 |
Isabelle simplifies flex-flex equations to eliminate redundant bound
|
|
295 |
variables. In $\lambda x\,y.\Var{f}(k(y),x) \qeq \lambda x\,y.\Var{g}(y)$,
|
|
296 |
there is no bound occurrence of~$x$ on the right side; thus, there will be
|
|
297 |
none on the left, in a common instance of these terms. Choosing a new
|
|
298 |
variable~$\Var{h}$, Isabelle assigns $\Var{f}\equiv \lambda u\,v.?h(u)$,
|
|
299 |
simplifying the left side to $\lambda x\,y.\Var{h}(k(y))$. Dropping $x$
|
|
300 |
from the equation leaves $\lambda y.\Var{h}(k(y)) \qeq \lambda
|
|
301 |
y.\Var{g}(y)$. By $\eta$-conversion, this simplifies to the assignment
|
|
302 |
$\Var{g}\equiv\lambda y.?h(k(y))$.
|
|
303 |
|
|
304 |
\begin{warn}
|
|
305 |
\ttindex{RS} and \ttindex{RSN} fail (by raising exception {\tt THM}) unless
|
|
306 |
the resolution delivers {\bf exactly one} resolvent. For multiple results,
|
|
307 |
use \ttindex{RL} and \ttindex{RLN}, which operate on theorem lists. The
|
|
308 |
following example uses \ttindex{read_instantiate} to create an instance
|
|
309 |
of \ttindex{refl} containing no schematic variables.
|
|
310 |
\begin{ttbox}
|
|
311 |
val reflk = read_instantiate [("a","k")] refl;
|
|
312 |
{\out val reflk = "k = k" : thm}
|
|
313 |
\end{ttbox}
|
|
314 |
|
|
315 |
\noindent
|
|
316 |
A flex-flex constraint is no longer possible; resolution does not find a
|
|
317 |
unique unifier:
|
|
318 |
\begin{ttbox}
|
|
319 |
reflk RS exI;
|
|
320 |
{\out uncaught exception THM}
|
|
321 |
\end{ttbox}
|
|
322 |
Using \ttindex{RL} this time, we discover that there are four unifiers, and
|
|
323 |
four resolvents:
|
|
324 |
\begin{ttbox}
|
|
325 |
[reflk] RL [exI];
|
|
326 |
{\out val it = ["EX x. x = x", "EX x. k = x",}
|
|
327 |
{\out "EX x. x = k", "EX x. k = k"] : thm list}
|
|
328 |
\end{ttbox}
|
|
329 |
\end{warn}
|
|
330 |
|
|
331 |
|
|
332 |
\section{Backward proof}
|
|
333 |
Although {\tt RS} and {\tt RSN} are fine for simple forward reasoning,
|
|
334 |
large proofs require tactics. Isabelle provides a suite of commands for
|
|
335 |
conducting a backward proof using tactics.
|
|
336 |
|
|
337 |
\subsection{The basic tactics}
|
|
338 |
\index{tactics!basic|bold}
|
|
339 |
The tactics {\tt assume_tac}, {\tt
|
|
340 |
resolve_tac}, {\tt eresolve_tac}, and {\tt dresolve_tac} suffice for most
|
|
341 |
single-step proofs. Although {\tt eresolve_tac} and {\tt dresolve_tac} are
|
|
342 |
not strictly necessary, they simplify proofs involving elimination and
|
|
343 |
destruction rules. All the tactics act on a subgoal designated by a
|
|
344 |
positive integer~$i$, failing if~$i$ is out of range. The resolution
|
|
345 |
tactics try their list of theorems in left-to-right order.
|
|
346 |
|
|
347 |
\begin{description}
|
|
348 |
\item[\ttindexbold{assume_tac} {\it i}] is the tactic that attempts to solve
|
|
349 |
subgoal~$i$ by assumption. Proof by assumption is not a trivial step; it
|
|
350 |
can falsify other subgoals by instantiating shared variables. There may be
|
|
351 |
several ways of solving the subgoal by assumption.
|
|
352 |
|
|
353 |
\item[\ttindexbold{resolve_tac} {\it thms} {\it i}]
|
|
354 |
is the basic resolution tactic, used for most proof steps. The $thms$
|
|
355 |
represent object-rules, which are resolved against subgoal~$i$ of the proof
|
|
356 |
state. For each rule, resolution forms next states by unifying the
|
|
357 |
conclusion with the subgoal and inserting instantiated premises in its
|
|
358 |
place. A rule can admit many higher-order unifiers. The tactic fails if
|
|
359 |
none of the rules generates next states.
|
|
360 |
|
|
361 |
\item[\ttindexbold{eresolve_tac} {\it thms} {\it i}]
|
|
362 |
performs elim-resolution. Like
|
|
363 |
\hbox{\tt resolve_tac {\it thms} {\it i}} followed by \hbox{\tt assume_tac
|
|
364 |
{\it i}}, it applies a rule then solves its first premise by assumption.
|
|
365 |
But {\tt eresolve_tac} additionally deletes that assumption from any
|
|
366 |
subgoals arising from the resolution.
|
|
367 |
|
|
368 |
|
|
369 |
\item[\ttindexbold{dresolve_tac} {\it thms} {\it i}]
|
|
370 |
performs destruct-resolution with the~$thms$, as described
|
|
371 |
in~\S\ref{destruct}. It is useful for forward reasoning from the
|
|
372 |
assumptions.
|
|
373 |
\end{description}
|
|
374 |
|
|
375 |
\subsection{Commands for backward proof}
|
|
376 |
\index{proof!commands for|bold}
|
|
377 |
Tactics are normally applied using the subgoal module, which maintains a
|
|
378 |
proof state and manages the proof construction. It allows interactive
|
|
379 |
backtracking through the proof space, going away to prove lemmas, etc.; of
|
|
380 |
its many commands, most important are the following:
|
|
381 |
\begin{description}
|
|
382 |
\item[\ttindexbold{goal} {\it theory} {\it formula}; ]
|
|
383 |
begins a new proof, where $theory$ is usually an \ML\ identifier
|
|
384 |
and the {\it formula\/} is written as an \ML\ string.
|
|
385 |
|
|
386 |
\item[\ttindexbold{by} {\it tactic}; ]
|
|
387 |
applies the {\it tactic\/} to the current proof
|
|
388 |
state, raising an exception if the tactic fails.
|
|
389 |
|
|
390 |
\item[\ttindexbold{undo}(); ]
|
|
391 |
reverts to the previous proof state. Undo can be repeated but cannot be
|
|
392 |
undone. Do not omit the parentheses; typing {\tt undo;} merely causes \ML\
|
|
393 |
to echo the value of that function.
|
|
394 |
|
|
395 |
\item[\ttindexbold{result}()]
|
|
396 |
returns the theorem just proved, in a standard format. It fails if
|
|
397 |
unproved subgoals are left or if the main goal does not match the one you
|
|
398 |
started with.
|
|
399 |
\end{description}
|
|
400 |
The commands and tactics given above are cumbersome for interactive use.
|
|
401 |
Although our examples will use the full commands, you may prefer Isabelle's
|
|
402 |
shortcuts:
|
|
403 |
\begin{center} \tt
|
|
404 |
\indexbold{*br} \indexbold{*be} \indexbold{*bd} \indexbold{*ba}
|
|
405 |
\begin{tabular}{l@{\qquad\rm abbreviates\qquad}l}
|
|
406 |
ba {\it i}; & by (assume_tac {\it i}); \\
|
|
407 |
|
|
408 |
br {\it thm} {\it i}; & by (resolve_tac [{\it thm}] {\it i}); \\
|
|
409 |
|
|
410 |
be {\it thm} {\it i}; & by (eresolve_tac [{\it thm}] {\it i}); \\
|
|
411 |
|
|
412 |
bd {\it thm} {\it i}; & by (dresolve_tac [{\it thm}] {\it i});
|
|
413 |
\end{tabular}
|
|
414 |
\end{center}
|
|
415 |
|
|
416 |
\subsection{A trivial example in propositional logic}
|
|
417 |
\index{examples!propositional}
|
|
418 |
Directory {\tt FOL} of the Isabelle distribution defines the \ML\
|
|
419 |
identifier~\ttindex{FOL.thy}, which denotes the theory of first-order
|
|
420 |
logic. Let us try the example from~\S\ref{prop-proof}, entering the goal
|
|
421 |
$P\disj P\imp P$ in that theory.\footnote{To run these examples, see the
|
|
422 |
file {\tt FOL/ex/intro.ML}.}
|
|
423 |
\begin{ttbox}
|
|
424 |
goal FOL.thy "P|P --> P";
|
|
425 |
{\out Level 0}
|
|
426 |
{\out P | P --> P}
|
|
427 |
{\out 1. P | P --> P}
|
|
428 |
\end{ttbox}
|
|
429 |
Isabelle responds by printing the initial proof state, which has $P\disj
|
|
430 |
P\imp P$ as the main goal and the only subgoal. The \bfindex{level} of the
|
|
431 |
state is the number of {\tt by} commands that have been applied to reach
|
|
432 |
it. We now use \ttindex{resolve_tac} to apply the rule \ttindex{impI},
|
|
433 |
or~$({\imp}I)$, to subgoal~1:
|
|
434 |
\begin{ttbox}
|
|
435 |
by (resolve_tac [impI] 1);
|
|
436 |
{\out Level 1}
|
|
437 |
{\out P | P --> P}
|
|
438 |
{\out 1. P | P ==> P}
|
|
439 |
\end{ttbox}
|
|
440 |
In the new proof state, subgoal~1 is $P$ under the assumption $P\disj P$.
|
|
441 |
(The meta-implication {\tt==>} indicates assumptions.) We apply
|
|
442 |
\ttindex{disjE}, or~(${\disj}E)$, to that subgoal:
|
|
443 |
\begin{ttbox}
|
|
444 |
by (resolve_tac [disjE] 1);
|
|
445 |
{\out Level 2}
|
|
446 |
{\out P | P --> P}
|
|
447 |
{\out 1. P | P ==> ?P1 | ?Q1}
|
|
448 |
{\out 2. [| P | P; ?P1 |] ==> P}
|
|
449 |
{\out 3. [| P | P; ?Q1 |] ==> P}
|
|
450 |
\end{ttbox}
|
|
451 |
At Level~2 there are three subgoals, each provable by
|
|
452 |
assumption. We deviate from~\S\ref{prop-proof} by tackling subgoal~3
|
|
453 |
first, using \ttindex{assume_tac}. This updates {\tt?Q1} to~{\tt P}.
|
|
454 |
\begin{ttbox}
|
|
455 |
by (assume_tac 3);
|
|
456 |
{\out Level 3}
|
|
457 |
{\out P | P --> P}
|
|
458 |
{\out 1. P | P ==> ?P1 | P}
|
|
459 |
{\out 2. [| P | P; ?P1 |] ==> P}
|
|
460 |
\end{ttbox}
|
|
461 |
Next we tackle subgoal~2, instantiating {\tt?P1} to~{\tt P}.
|
|
462 |
\begin{ttbox}
|
|
463 |
by (assume_tac 2);
|
|
464 |
{\out Level 4}
|
|
465 |
{\out P | P --> P}
|
|
466 |
{\out 1. P | P ==> P | P}
|
|
467 |
\end{ttbox}
|
|
468 |
Lastly we prove the remaining subgoal by assumption:
|
|
469 |
\begin{ttbox}
|
|
470 |
by (assume_tac 1);
|
|
471 |
{\out Level 5}
|
|
472 |
{\out P | P --> P}
|
|
473 |
{\out No subgoals!}
|
|
474 |
\end{ttbox}
|
|
475 |
Isabelle tells us that there are no longer any subgoals: the proof is
|
|
476 |
complete. Calling \ttindex{result} returns the theorem.
|
|
477 |
\begin{ttbox}
|
|
478 |
val mythm = result();
|
|
479 |
{\out val mythm = "?P | ?P --> ?P" : thm}
|
|
480 |
\end{ttbox}
|
|
481 |
Isabelle has replaced the free variable~{\tt P} by the scheme
|
|
482 |
variable~{\tt?P}\@. Free variables in the proof state remain fixed
|
|
483 |
throughout the proof. Isabelle finally converts them to scheme variables
|
|
484 |
so that the resulting theorem can be instantiated with any formula.
|
|
485 |
|
|
486 |
|
|
487 |
\subsection{Proving a distributive law}
|
|
488 |
\index{examples!propositional}
|
|
489 |
To demonstrate the tactics \ttindex{eresolve_tac}, \ttindex{dresolve_tac}
|
|
490 |
and the tactical \ttindex{REPEAT}, we shall prove part of the distributive
|
|
491 |
law $(P\conj Q)\disj R \iff (P\disj R)\conj (Q\disj R)$.
|
|
492 |
|
|
493 |
We begin by stating the goal to Isabelle and applying~$({\imp}I)$ to it:
|
|
494 |
\begin{ttbox}
|
|
495 |
goal FOL.thy "(P & Q) | R --> (P | R)";
|
|
496 |
{\out Level 0}
|
|
497 |
{\out P & Q | R --> P | R}
|
|
498 |
{\out 1. P & Q | R --> P | R}
|
|
499 |
by (resolve_tac [impI] 1);
|
|
500 |
{\out Level 1}
|
|
501 |
{\out P & Q | R --> P | R}
|
|
502 |
{\out 1. P & Q | R ==> P | R}
|
|
503 |
\end{ttbox}
|
|
504 |
Previously we applied~(${\disj}E)$ using {\tt resolve_tac}, but
|
|
505 |
\ttindex{eresolve_tac} deletes the assumption after use. The resulting proof
|
|
506 |
state is simpler.
|
|
507 |
\begin{ttbox}
|
|
508 |
by (eresolve_tac [disjE] 1);
|
|
509 |
{\out Level 2}
|
|
510 |
{\out P & Q | R --> P | R}
|
|
511 |
{\out 1. P & Q ==> P | R}
|
|
512 |
{\out 2. R ==> P | R}
|
|
513 |
\end{ttbox}
|
|
514 |
Using \ttindex{dresolve_tac}, we can apply~(${\conj}E1)$ to subgoal~1,
|
|
515 |
replacing the assumption $P\conj Q$ by~$P$. Normally we should apply the
|
|
516 |
rule~(${\conj}E)$, given in~\S\ref{destruct}. That is an elimination rule
|
|
517 |
and requires {\tt eresolve_tac}; it would replace $P\conj Q$ by the two
|
|
518 |
assumptions~$P$ and~$Q$. The present example does not need~$Q$.
|
|
519 |
\begin{ttbox}
|
|
520 |
by (dresolve_tac [conjunct1] 1);
|
|
521 |
{\out Level 3}
|
|
522 |
{\out P & Q | R --> P | R}
|
|
523 |
{\out 1. P ==> P | R}
|
|
524 |
{\out 2. R ==> P | R}
|
|
525 |
\end{ttbox}
|
|
526 |
The next two steps apply~(${\disj}I1$) and~(${\disj}I2$) in an obvious manner.
|
|
527 |
\begin{ttbox}
|
|
528 |
by (resolve_tac [disjI1] 1);
|
|
529 |
{\out Level 4}
|
|
530 |
{\out P & Q | R --> P | R}
|
|
531 |
{\out 1. P ==> P}
|
|
532 |
{\out 2. R ==> P | R}
|
|
533 |
\ttbreak
|
|
534 |
by (resolve_tac [disjI2] 2);
|
|
535 |
{\out Level 5}
|
|
536 |
{\out P & Q | R --> P | R}
|
|
537 |
{\out 1. P ==> P}
|
|
538 |
{\out 2. R ==> R}
|
|
539 |
\end{ttbox}
|
|
540 |
Two calls of~\ttindex{assume_tac} can finish the proof. The
|
|
541 |
tactical~\ttindex{REPEAT} expresses a tactic that calls {\tt assume_tac~1}
|
|
542 |
as many times as possible. We can restrict attention to subgoal~1 because
|
|
543 |
the other subgoals move up after subgoal~1 disappears.
|
|
544 |
\begin{ttbox}
|
|
545 |
by (REPEAT (assume_tac 1));
|
|
546 |
{\out Level 6}
|
|
547 |
{\out P & Q | R --> P | R}
|
|
548 |
{\out No subgoals!}
|
|
549 |
\end{ttbox}
|
|
550 |
|
|
551 |
|
|
552 |
\section{Quantifier reasoning}
|
|
553 |
\index{quantifiers!reasoning about}\index{parameters}\index{unknowns}
|
|
554 |
This section illustrates how Isabelle enforces quantifier provisos.
|
|
555 |
Quantifier rules create terms such as~$\Var{f}(x,z)$, where~$\Var{f}$ is a
|
|
556 |
function unknown and $x$ and~$z$ are parameters. This may be replaced by
|
|
557 |
any term, possibly containing free occurrences of $x$ and~$z$.
|
|
558 |
|
|
559 |
\subsection{Two quantifier proofs, successful and not}
|
|
560 |
\index{examples!with quantifiers}
|
|
561 |
Let us contrast a proof of the theorem $\forall x.\exists y.x=y$ with an
|
|
562 |
attempted proof of the non-theorem $\exists y.\forall x.x=y$. The former
|
|
563 |
proof succeeds, and the latter fails, because of the scope of quantified
|
|
564 |
variables~\cite{paulson89}. Unification helps even in these trivial
|
|
565 |
proofs. In $\forall x.\exists y.x=y$ the $y$ that `exists' is simply $x$,
|
|
566 |
but we need never say so. This choice is forced by the reflexive law for
|
|
567 |
equality, and happens automatically.
|
|
568 |
|
|
569 |
\subsubsection{The successful proof}
|
|
570 |
The proof of $\forall x.\exists y.x=y$ demonstrates the introduction rules
|
|
571 |
$(\forall I)$ and~$(\exists I)$. We state the goal and apply $(\forall I)$:
|
|
572 |
\begin{ttbox}
|
|
573 |
goal FOL.thy "ALL x. EX y. x=y";
|
|
574 |
{\out Level 0}
|
|
575 |
{\out ALL x. EX y. x = y}
|
|
576 |
{\out 1. ALL x. EX y. x = y}
|
|
577 |
\ttbreak
|
|
578 |
by (resolve_tac [allI] 1);
|
|
579 |
{\out Level 1}
|
|
580 |
{\out ALL x. EX y. x = y}
|
|
581 |
{\out 1. !!x. EX y. x = y}
|
|
582 |
\end{ttbox}
|
|
583 |
The variable~{\tt x} is no longer universally quantified, but is a
|
|
584 |
parameter in the subgoal; thus, it is universally quantified at the
|
|
585 |
meta-level. The subgoal must be proved for all possible values of~{\tt x}.
|
|
586 |
We apply the rule $(\exists I)$:
|
|
587 |
\begin{ttbox}
|
|
588 |
by (resolve_tac [exI] 1);
|
|
589 |
{\out Level 2}
|
|
590 |
{\out ALL x. EX y. x = y}
|
|
591 |
{\out 1. !!x. x = ?y1(x)}
|
|
592 |
\end{ttbox}
|
|
593 |
The bound variable {\tt y} has become {\tt?y1(x)}. This term consists of
|
|
594 |
the function unknown~{\tt?y1} applied to the parameter~{\tt x}.
|
|
595 |
Instances of {\tt?y1(x)} may or may not contain~{\tt x}. We resolve the
|
|
596 |
subgoal with the reflexivity axiom.
|
|
597 |
\begin{ttbox}
|
|
598 |
by (resolve_tac [refl] 1);
|
|
599 |
{\out Level 3}
|
|
600 |
{\out ALL x. EX y. x = y}
|
|
601 |
{\out No subgoals!}
|
|
602 |
\end{ttbox}
|
|
603 |
Let us consider what has happened in detail. The reflexivity axiom is
|
|
604 |
lifted over~$x$ to become $\Forall x.\Var{f}(x)=\Var{f}(x)$, which is
|
|
605 |
unified with $\Forall x.x=\Var{y@1}(x)$. The function unknowns $\Var{f}$
|
|
606 |
and~$\Var{y@1}$ are both instantiated to the identity function, and
|
|
607 |
$x=\Var{y@1}(x)$ collapses to~$x=x$ by $\beta$-reduction.
|
|
608 |
|
|
609 |
\subsubsection{The unsuccessful proof}
|
|
610 |
We state the goal $\exists y.\forall x.x=y$, which is {\bf not} a theorem, and
|
|
611 |
try~$(\exists I)$:
|
|
612 |
\begin{ttbox}
|
|
613 |
goal FOL.thy "EX y. ALL x. x=y";
|
|
614 |
{\out Level 0}
|
|
615 |
{\out EX y. ALL x. x = y}
|
|
616 |
{\out 1. EX y. ALL x. x = y}
|
|
617 |
\ttbreak
|
|
618 |
by (resolve_tac [exI] 1);
|
|
619 |
{\out Level 1}
|
|
620 |
{\out EX y. ALL x. x = y}
|
|
621 |
{\out 1. ALL x. x = ?y}
|
|
622 |
\end{ttbox}
|
|
623 |
The unknown {\tt ?y} may be replaced by any term, but this can never
|
|
624 |
introduce another bound occurrence of~{\tt x}. We now apply~$(\forall I)$:
|
|
625 |
\begin{ttbox}
|
|
626 |
by (resolve_tac [allI] 1);
|
|
627 |
{\out Level 2}
|
|
628 |
{\out EX y. ALL x. x = y}
|
|
629 |
{\out 1. !!x. x = ?y}
|
|
630 |
\end{ttbox}
|
|
631 |
Compare our position with the previous Level~2. Instead of {\tt?y1(x)} we
|
|
632 |
have~{\tt?y}, whose instances may not contain the bound variable~{\tt x}.
|
|
633 |
The reflexivity axiom does not unify with subgoal~1.
|
|
634 |
\begin{ttbox}
|
|
635 |
by (resolve_tac [refl] 1);
|
|
636 |
{\out by: tactic returned no results}
|
|
637 |
\end{ttbox}
|
|
638 |
No other choice of rules seems likely to complete the proof. Of course,
|
|
639 |
this is no guarantee that Isabelle cannot prove $\exists y.\forall x.x=y$
|
|
640 |
or other invalid assertions. We must appeal to the soundness of
|
|
641 |
first-order logic and the faithfulness of its encoding in
|
|
642 |
Isabelle~\cite{paulson89}, and must trust the implementation.
|
|
643 |
|
|
644 |
|
|
645 |
\subsection{Nested quantifiers}
|
|
646 |
\index{examples!with quantifiers}
|
|
647 |
Multiple quantifiers create complex terms. Proving $(\forall x\,y.P(x,y))
|
|
648 |
\imp (\forall z\,w.P(w,z))$, will demonstrate how parameters and
|
|
649 |
unknowns develop. If they appear in the wrong order, the proof will fail.
|
|
650 |
This section concludes with a demonstration of {\tt REPEAT}
|
|
651 |
and~{\tt ORELSE}.
|
|
652 |
|
|
653 |
The start of the proof is routine.
|
|
654 |
\begin{ttbox}
|
|
655 |
goal FOL.thy "(ALL x y.P(x,y)) --> (ALL z w.P(w,z))";
|
|
656 |
{\out Level 0}
|
|
657 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
658 |
{\out 1. (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
659 |
\ttbreak
|
|
660 |
by (resolve_tac [impI] 1);
|
|
661 |
{\out Level 1}
|
|
662 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
663 |
{\out 1. ALL x y. P(x,y) ==> ALL z w. P(w,z)}
|
|
664 |
\end{ttbox}
|
|
665 |
|
|
666 |
\subsubsection{The wrong approach}
|
|
667 |
Using \ttindex{dresolve_tac}, we apply the rule $(\forall E)$, bound to the
|
|
668 |
\ML\ identifier \ttindex{spec}. Then we apply $(\forall I)$.
|
|
669 |
\begin{ttbox}
|
|
670 |
by (dresolve_tac [spec] 1);
|
|
671 |
{\out Level 2}
|
|
672 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
673 |
{\out 1. ALL y. P(?x1,y) ==> ALL z w. P(w,z)}
|
|
674 |
\ttbreak
|
|
675 |
by (resolve_tac [allI] 1);
|
|
676 |
{\out Level 3}
|
|
677 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
678 |
{\out 1. !!z. ALL y. P(?x1,y) ==> ALL w. P(w,z)}
|
|
679 |
\end{ttbox}
|
|
680 |
The unknown {\tt ?u} and the parameter {\tt z} have appeared. We again
|
|
681 |
apply $(\forall I)$ and~$(\forall E)$.
|
|
682 |
\begin{ttbox}
|
|
683 |
by (dresolve_tac [spec] 1);
|
|
684 |
{\out Level 4}
|
|
685 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
686 |
{\out 1. !!z. P(?x1,?y3(z)) ==> ALL w. P(w,z)}
|
|
687 |
\ttbreak
|
|
688 |
by (resolve_tac [allI] 1);
|
|
689 |
{\out Level 5}
|
|
690 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
691 |
{\out 1. !!z w. P(?x1,?y3(z)) ==> P(w,z)}
|
|
692 |
\end{ttbox}
|
|
693 |
The unknown {\tt ?y3} and the parameter {\tt w} have appeared. Each
|
|
694 |
unknown is applied to the parameters existing at the time of its creation;
|
|
695 |
instances of {\tt ?x1} cannot contain~{\tt z} or~{\tt w}, while instances
|
|
696 |
of {\tt?y3(z)} can only contain~{\tt z}. Because of these restrictions,
|
|
697 |
proof by assumption will fail.
|
|
698 |
\begin{ttbox}
|
|
699 |
by (assume_tac 1);
|
|
700 |
{\out by: tactic returned no results}
|
|
701 |
{\out uncaught exception ERROR}
|
|
702 |
\end{ttbox}
|
|
703 |
|
|
704 |
\subsubsection{The right approach}
|
|
705 |
To do this proof, the rules must be applied in the correct order.
|
|
706 |
Eigenvariables should be created before unknowns. The
|
|
707 |
\ttindex{choplev} command returns to an earlier stage of the proof;
|
|
708 |
let us return to the result of applying~$({\imp}I)$:
|
|
709 |
\begin{ttbox}
|
|
710 |
choplev 1;
|
|
711 |
{\out Level 1}
|
|
712 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
713 |
{\out 1. ALL x y. P(x,y) ==> ALL z w. P(w,z)}
|
|
714 |
\end{ttbox}
|
|
715 |
Previously, we made the mistake of applying $(\forall E)$; this time, we
|
|
716 |
apply $(\forall I)$ twice.
|
|
717 |
\begin{ttbox}
|
|
718 |
by (resolve_tac [allI] 1);
|
|
719 |
{\out Level 2}
|
|
720 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
721 |
{\out 1. !!z. ALL x y. P(x,y) ==> ALL w. P(w,z)}
|
|
722 |
\ttbreak
|
|
723 |
by (resolve_tac [allI] 1);
|
|
724 |
{\out Level 3}
|
|
725 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
726 |
{\out 1. !!z w. ALL x y. P(x,y) ==> P(w,z)}
|
|
727 |
\end{ttbox}
|
|
728 |
The parameters {\tt z} and~{\tt w} have appeared. We now create the
|
|
729 |
unknowns:
|
|
730 |
\begin{ttbox}
|
|
731 |
by (dresolve_tac [spec] 1);
|
|
732 |
{\out Level 4}
|
|
733 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
734 |
{\out 1. !!z w. ALL y. P(?x3(z,w),y) ==> P(w,z)}
|
|
735 |
\ttbreak
|
|
736 |
by (dresolve_tac [spec] 1);
|
|
737 |
{\out Level 5}
|
|
738 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
739 |
{\out 1. !!z w. P(?x3(z,w),?y4(z,w)) ==> P(w,z)}
|
|
740 |
\end{ttbox}
|
|
741 |
Both {\tt?x3(z,w)} and~{\tt?y4(z,w)} could become any terms containing {\tt
|
|
742 |
z} and~{\tt w}:
|
|
743 |
\begin{ttbox}
|
|
744 |
by (assume_tac 1);
|
|
745 |
{\out Level 6}
|
|
746 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
747 |
{\out No subgoals!}
|
|
748 |
\end{ttbox}
|
|
749 |
|
|
750 |
\subsubsection{A one-step proof using tacticals}
|
|
751 |
\index{tacticals}
|
|
752 |
\index{examples!of tacticals}
|
|
753 |
Repeated application of rules can be an effective theorem-proving
|
|
754 |
procedure, but the rules should be attempted in an order that delays the
|
|
755 |
creation of unknowns. As we have just seen, \ttindex{allI} should be
|
|
756 |
attempted before~\ttindex{spec}, while \ttindex{assume_tac} generally can
|
|
757 |
be attempted first. Such priorities can easily be expressed
|
|
758 |
using~\ttindex{ORELSE}, and repeated using~\ttindex{REPEAT}. Let us return
|
|
759 |
to the original goal using \ttindex{choplev}:
|
|
760 |
\begin{ttbox}
|
|
761 |
choplev 0;
|
|
762 |
{\out Level 0}
|
|
763 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
764 |
{\out 1. (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
765 |
\end{ttbox}
|
|
766 |
A repetitive procedure proves it:
|
|
767 |
\begin{ttbox}
|
|
768 |
by (REPEAT (assume_tac 1
|
|
769 |
ORELSE resolve_tac [impI,allI] 1
|
|
770 |
ORELSE dresolve_tac [spec] 1));
|
|
771 |
{\out Level 1}
|
|
772 |
{\out (ALL x y. P(x,y)) --> (ALL z w. P(w,z))}
|
|
773 |
{\out No subgoals!}
|
|
774 |
\end{ttbox}
|
|
775 |
|
|
776 |
|
|
777 |
\subsection{A realistic quantifier proof}
|
|
778 |
\index{examples!with quantifiers}
|
|
779 |
A proof of $(\forall x. P(x) \imp Q) \imp (\exists x. P(x)) \imp Q$
|
|
780 |
demonstrates the practical use of parameters and unknowns.
|
|
781 |
Since $\imp$ is nested to the right, $({\imp}I)$ can be applied twice; we
|
|
782 |
use \ttindex{REPEAT}:
|
|
783 |
\begin{ttbox}
|
|
784 |
goal FOL.thy "(ALL x.P(x) --> Q) --> (EX x.P(x)) --> Q";
|
|
785 |
{\out Level 0}
|
|
786 |
{\out (ALL x. P(x) --> Q) --> (EX x. P(x)) --> Q}
|
|
787 |
{\out 1. (ALL x. P(x) --> Q) --> (EX x. P(x)) --> Q}
|
|
788 |
\ttbreak
|
|
789 |
by (REPEAT (resolve_tac [impI] 1));
|
|
790 |
{\out Level 1}
|
|
791 |
{\out (ALL x. P(x) --> Q) --> (EX x. P(x)) --> Q}
|
|
792 |
{\out 1. [| ALL x. P(x) --> Q; EX x. P(x) |] ==> Q}
|
|
793 |
\end{ttbox}
|
|
794 |
We can eliminate the universal or the existential quantifier. The
|
|
795 |
existential quantifier should be eliminated first, since this creates a
|
|
796 |
parameter. The rule~$(\exists E)$ is bound to the
|
|
797 |
identifier~\ttindex{exE}.
|
|
798 |
\begin{ttbox}
|
|
799 |
by (eresolve_tac [exE] 1);
|
|
800 |
{\out Level 2}
|
|
801 |
{\out (ALL x. P(x) --> Q) --> (EX x. P(x)) --> Q}
|
|
802 |
{\out 1. !!x. [| ALL x. P(x) --> Q; P(x) |] ==> Q}
|
|
803 |
\end{ttbox}
|
|
804 |
The only possibility now is $(\forall E)$, a destruction rule. We use
|
|
805 |
\ttindex{dresolve_tac}, which discards the quantified assumption; it is
|
|
806 |
only needed once.
|
|
807 |
\begin{ttbox}
|
|
808 |
by (dresolve_tac [spec] 1);
|
|
809 |
{\out Level 3}
|
|
810 |
{\out (ALL x. P(x) --> Q) --> (EX x. P(x)) --> Q}
|
|
811 |
{\out 1. !!x. [| P(x); P(?x3(x)) --> Q |] ==> Q}
|
|
812 |
\end{ttbox}
|
|
813 |
Because the parameter~{\tt x} appeared first, the unknown
|
|
814 |
term~{\tt?x3(x)} may depend upon it. Had we eliminated the universal
|
|
815 |
quantifier before the existential, this would not be so.
|
|
816 |
|
|
817 |
Although $({\imp}E)$ is a destruction rule, it works with
|
|
818 |
\ttindex{eresolve_tac} to perform backward chaining. This technique is
|
|
819 |
frequently useful.
|
|
820 |
\begin{ttbox}
|
|
821 |
by (eresolve_tac [mp] 1);
|
|
822 |
{\out Level 4}
|
|
823 |
{\out (ALL x. P(x) --> Q) --> (EX x. P(x)) --> Q}
|
|
824 |
{\out 1. !!x. P(x) ==> P(?x3(x))}
|
|
825 |
\end{ttbox}
|
|
826 |
The tactic has reduced~{\tt Q} to~{\tt P(?x3(x))}, deleting the
|
|
827 |
implication. The final step is trivial, thanks to the occurrence of~{\tt x}.
|
|
828 |
\begin{ttbox}
|
|
829 |
by (assume_tac 1);
|
|
830 |
{\out Level 5}
|
|
831 |
{\out (ALL x. P(x) --> Q) --> (EX x. P(x)) --> Q}
|
|
832 |
{\out No subgoals!}
|
|
833 |
\end{ttbox}
|
|
834 |
|
|
835 |
|
|
836 |
\subsection{The classical reasoning package}
|
|
837 |
\index{classical reasoning package}
|
|
838 |
Although Isabelle cannot compete with fully automatic theorem provers, it
|
|
839 |
provides enough automation to tackle substantial examples. The classical
|
|
840 |
reasoning package can be set up for any classical natural deduction logic
|
|
841 |
--- see the {\em Reference Manual}.
|
|
842 |
|
|
843 |
Rules are packaged into bundles called \bfindex{classical sets}. The package
|
|
844 |
provides several tactics, which apply rules using naive algorithms, using
|
|
845 |
unification to handle quantifiers. The most useful tactic
|
|
846 |
is~\ttindex{fast_tac}.
|
|
847 |
|
|
848 |
Let us solve problems~40 and~60 of Pelletier~\cite{pelletier86}. (The
|
|
849 |
backslashes~\hbox{\verb|\|\ldots\verb|\|} are an \ML{} string escape
|
|
850 |
sequence, to break the long string over two lines.)
|
|
851 |
\begin{ttbox}
|
|
852 |
goal FOL.thy "(EX y. ALL x. J(y,x) <-> ~J(x,x)) \ttback
|
|
853 |
\ttback --> ~ (ALL x. EX y. ALL z. J(z,y) <-> ~ J(z,x))";
|
|
854 |
{\out Level 0}
|
|
855 |
{\out (EX y. ALL x. J(y,x) <-> ~J(x,x)) -->}
|
|
856 |
{\out ~(ALL x. EX y. ALL z. J(z,y) <-> ~J(z,x))}
|
|
857 |
{\out 1. (EX y. ALL x. J(y,x) <-> ~J(x,x)) -->}
|
|
858 |
{\out ~(ALL x. EX y. ALL z. J(z,y) <-> ~J(z,x))}
|
|
859 |
\end{ttbox}
|
|
860 |
The rules of classical logic are bundled as {\tt FOL_cs}. We may solve
|
|
861 |
subgoal~1 at a stroke, using~\ttindex{fast_tac}.
|
|
862 |
\begin{ttbox}
|
|
863 |
by (fast_tac FOL_cs 1);
|
|
864 |
{\out Level 1}
|
|
865 |
{\out (EX y. ALL x. J(y,x) <-> ~J(x,x)) -->}
|
|
866 |
{\out ~(ALL x. EX y. ALL z. J(z,y) <-> ~J(z,x))}
|
|
867 |
{\out No subgoals!}
|
|
868 |
\end{ttbox}
|
|
869 |
Sceptics may examine the proof by calling the package's single-step
|
|
870 |
tactics, such as~{\tt step_tac}. This would take up much space, however,
|
|
871 |
so let us proceed to the next example:
|
|
872 |
\begin{ttbox}
|
|
873 |
goal FOL.thy "ALL x. P(x,f(x)) <-> \ttback
|
|
874 |
\ttback (EX y. (ALL z. P(z,y) --> P(z,f(x))) & P(x,y))";
|
|
875 |
{\out Level 0}
|
|
876 |
{\out ALL x. P(x,f(x)) <-> (EX y. (ALL z. P(z,y) --> P(z,f(x))) & P(x,y))}
|
|
877 |
{\out 1. ALL x. P(x,f(x)) <-> (EX y. (ALL z. P(z,y) --> P(z,f(x))) & P(x,y))}
|
|
878 |
\end{ttbox}
|
|
879 |
Again, subgoal~1 succumbs immediately.
|
|
880 |
\begin{ttbox}
|
|
881 |
by (fast_tac FOL_cs 1);
|
|
882 |
{\out Level 1}
|
|
883 |
{\out ALL x. P(x,f(x)) <-> (EX y. (ALL z. P(z,y) --> P(z,f(x))) & P(x,y))}
|
|
884 |
{\out No subgoals!}
|
|
885 |
\end{ttbox}
|
|
886 |
The classical reasoning package is not restricted to the usual logical
|
|
887 |
connectives. The natural deduction rules for unions and intersections in
|
|
888 |
set theory resemble those for disjunction and conjunction, and in the
|
|
889 |
infinitary case, for quantifiers. The package is valuable for reasoning in
|
|
890 |
set theory.
|
|
891 |
|
|
892 |
|
|
893 |
% Local Variables:
|
|
894 |
% mode: latex
|
|
895 |
% TeX-master: t
|
|
896 |
% End:
|