wenzelm@3200
|
1 |
|
lcp@104
|
2 |
%% $Id$
|
wenzelm@3108
|
3 |
|
lcp@286
|
4 |
\chapter{Basic Use of Isabelle}\index{sessions|(}
|
wenzelm@3108
|
5 |
The Reference Manual is a comprehensive description of Isabelle
|
wenzelm@3108
|
6 |
proper, including all \ML{} commands, functions and packages. It
|
wenzelm@3108
|
7 |
really is intended for reference, perhaps for browsing, but not for
|
wenzelm@3108
|
8 |
reading through. It is not a tutorial, but assumes familiarity with
|
wenzelm@3108
|
9 |
the basic logical concepts of Isabelle.
|
lcp@104
|
10 |
|
lcp@286
|
11 |
When you are looking for a way of performing some task, scan the Table of
|
lcp@286
|
12 |
Contents for a relevant heading. Functions are organized by their purpose,
|
lcp@286
|
13 |
by their operands (subgoals, tactics, theorems), and by their usefulness.
|
lcp@286
|
14 |
In each section, basic functions appear first, then advanced functions, and
|
lcp@322
|
15 |
finally esoteric functions. Use the Index when you are looking for the
|
lcp@322
|
16 |
definition of a particular Isabelle function.
|
lcp@104
|
17 |
|
lcp@286
|
18 |
A few examples are presented. Many examples files are distributed with
|
lcp@286
|
19 |
Isabelle, however; please experiment interactively.
|
lcp@104
|
20 |
|
lcp@104
|
21 |
|
lcp@104
|
22 |
\section{Basic interaction with Isabelle}
|
paulson@2225
|
23 |
\index{starting up|bold}\nobreak
|
paulson@2225
|
24 |
%
|
wenzelm@3108
|
25 |
We assume that your local Isabelle administrator (this might be you!)
|
wenzelm@3108
|
26 |
has already installed the \Pure\ system and several object-logics
|
wenzelm@3108
|
27 |
properly --- otherwise see the {\tt INSTALL} file in the top-level
|
wenzelm@3108
|
28 |
directory of the distribution on how to build it.
|
paulson@2225
|
29 |
|
wenzelm@3108
|
30 |
\medskip Let $\langle isabellehome \rangle$ denote the location where
|
paulson@3485
|
31 |
the distribution has been installed. To run Isabelle from a the shell
|
wenzelm@4317
|
32 |
prompt within an ordinary text terminal session, simply type
|
wenzelm@3108
|
33 |
\begin{ttbox}
|
wenzelm@3108
|
34 |
\({\langle}isabellehome{\rangle}\)/bin/isabelle
|
wenzelm@3108
|
35 |
\end{ttbox}
|
wenzelm@3108
|
36 |
This should start an interactive \ML{} session with the default
|
wenzelm@4317
|
37 |
object-logic already preloaded.
|
lcp@104
|
38 |
|
wenzelm@3108
|
39 |
Subsequently we assume that {\tt \(\langle isabellehome \rangle\)/bin}
|
wenzelm@3108
|
40 |
has been added to your shell's search path, in order to avoid typing
|
wenzelm@3108
|
41 |
full path specifications of the executable files.
|
lcp@104
|
42 |
|
wenzelm@3108
|
43 |
The object-logic image to load may be also specified explicitly as an
|
wenzelm@4317
|
44 |
argument to the {\tt isabelle} command, e.g.
|
wenzelm@3108
|
45 |
\begin{ttbox}
|
wenzelm@3108
|
46 |
isabelle FOL
|
wenzelm@3108
|
47 |
\end{ttbox}
|
wenzelm@3108
|
48 |
This should put you into the world of polymorphic first-order logic
|
wenzelm@3108
|
49 |
(assuming that {\FOL} has been pre-built).
|
lcp@104
|
50 |
|
wenzelm@3108
|
51 |
\index{saving your work|bold} Isabelle provides no means of storing
|
wenzelm@4317
|
52 |
theorems or internal proof objects on files. Theorems are simply part
|
wenzelm@4317
|
53 |
of the \ML{} state. To save your work between sessions, you must dump
|
wenzelm@4317
|
54 |
the \ML{} system state to a file. This is done automatically when
|
wenzelm@4317
|
55 |
ending the session normally (e.g.\ by typing control-D), provided that
|
wenzelm@4317
|
56 |
the image has been opened \emph{writable} in the first place. The
|
wenzelm@4317
|
57 |
standard object-logic images are usually read-only, so you probably
|
wenzelm@4317
|
58 |
have to create a private working copy first. For example, the
|
wenzelm@4317
|
59 |
following shell command puts you into a writable Isabelle session of
|
wenzelm@4317
|
60 |
name \texttt{Foo} that initially contains just \FOL:
|
wenzelm@3108
|
61 |
\begin{ttbox}
|
wenzelm@3108
|
62 |
isabelle FOL Foo
|
wenzelm@3108
|
63 |
\end{ttbox}
|
wenzelm@3108
|
64 |
Ending the \texttt{Foo} session with control-D will cause the complete
|
wenzelm@3108
|
65 |
\ML{} world to be saved somewhere in your home directory\footnote{The
|
wenzelm@3108
|
66 |
default location is in \texttt{\~\relax/isabelle/heaps}, but this
|
paulson@3485
|
67 |
depends on your local configuration.}. Make sure there is enough
|
wenzelm@3108
|
68 |
space available! Then one may later continue at exactly the same point
|
wenzelm@3108
|
69 |
by running
|
wenzelm@3108
|
70 |
\begin{ttbox}
|
wenzelm@3108
|
71 |
isabelle Foo
|
wenzelm@3108
|
72 |
\end{ttbox}
|
wenzelm@3108
|
73 |
|
wenzelm@4317
|
74 |
More details about the \texttt{isabelle} command may be found in the
|
wenzelm@4317
|
75 |
\emph{System Manual}.
|
wenzelm@3108
|
76 |
|
wenzelm@3108
|
77 |
\medskip Saving the state is not enough. Record, on a file, the
|
wenzelm@3108
|
78 |
top-level commands that generate your theories and proofs. Such a
|
wenzelm@3108
|
79 |
record allows you to replay the proofs whenever required, for instance
|
wenzelm@3108
|
80 |
after making minor changes to the axioms. Ideally, your record will
|
wenzelm@3108
|
81 |
be somewhat intelligible to others as a formal description of your
|
wenzelm@3108
|
82 |
work.
|
wenzelm@3108
|
83 |
|
wenzelm@3108
|
84 |
\medskip There are more comfortable user interfaces than the
|
paulson@3485
|
85 |
bare-bones \ML{} top-level run from a text terminal. The
|
wenzelm@3108
|
86 |
\texttt{Isabelle} executable (note the capital I) runs one such
|
wenzelm@3108
|
87 |
interface, depending on your local configuration. Furthermore there
|
paulson@3485
|
88 |
are a number of external utilities available. These are started
|
wenzelm@4317
|
89 |
uniformly via the \texttt{isatool} wrapper. See the \emph{System
|
wenzelm@4317
|
90 |
Manual} for more information user interfaces and utilities.
|
lcp@104
|
91 |
|
lcp@104
|
92 |
|
lcp@104
|
93 |
\section{Ending a session}
|
lcp@104
|
94 |
\begin{ttbox}
|
wenzelm@3108
|
95 |
quit : unit -> unit
|
wenzelm@3108
|
96 |
exit : int -> unit
|
wenzelm@3108
|
97 |
commit : unit -> unit
|
lcp@104
|
98 |
\end{ttbox}
|
lcp@322
|
99 |
\begin{ttdescription}
|
wenzelm@3108
|
100 |
\item[\ttindexbold{quit}();] ends the Isabelle session, without saving
|
wenzelm@3108
|
101 |
the state.
|
wenzelm@4317
|
102 |
|
wenzelm@4317
|
103 |
\item[\ttindexbold{exit} \(i\);] similar to {\tt quit}, passing return
|
wenzelm@4317
|
104 |
code \(i\) to the operating system.
|
lcp@104
|
105 |
|
wenzelm@3108
|
106 |
\item[\ttindexbold{commit}();] saves the current state without ending
|
wenzelm@3108
|
107 |
the session, provided that the logic image is opened read-write.
|
lcp@322
|
108 |
\end{ttdescription}
|
lcp@104
|
109 |
|
wenzelm@3108
|
110 |
Typing control-D also finishes the session in essentially the same way
|
wenzelm@3108
|
111 |
as the sequence {\tt commit(); quit();} would.
|
lcp@104
|
112 |
|
lcp@104
|
113 |
|
lcp@322
|
114 |
\section{Reading ML files}
|
lcp@322
|
115 |
\index{files!reading}
|
lcp@104
|
116 |
\begin{ttbox}
|
clasohm@138
|
117 |
cd : string -> unit
|
clasohm@884
|
118 |
pwd : unit -> string
|
clasohm@138
|
119 |
use : string -> unit
|
clasohm@138
|
120 |
time_use : string -> unit
|
lcp@104
|
121 |
\end{ttbox}
|
lcp@322
|
122 |
\begin{ttdescription}
|
wenzelm@4317
|
123 |
\item[\ttindexbold{cd} "{\it dir}";] changes the current directory to
|
wenzelm@4317
|
124 |
{\it dir}. This is the default directory for reading files.
|
wenzelm@4317
|
125 |
|
wenzelm@4317
|
126 |
\item[\ttindexbold{pwd}();] returns the full path of the current
|
wenzelm@4317
|
127 |
directory.
|
clasohm@884
|
128 |
|
lcp@322
|
129 |
\item[\ttindexbold{use} "$file$";]
|
lcp@104
|
130 |
reads the given {\it file} as input to the \ML{} session. Reading a file
|
lcp@104
|
131 |
of Isabelle commands is the usual way of replaying a proof.
|
lcp@104
|
132 |
|
lcp@322
|
133 |
\item[\ttindexbold{time_use} "$file$";]
|
lcp@104
|
134 |
performs {\tt use~"$file$"} and prints the total execution time.
|
lcp@322
|
135 |
\end{ttdescription}
|
lcp@104
|
136 |
|
wenzelm@4274
|
137 |
The $dir$ and $file$ specifications of the \texttt{cd} and
|
wenzelm@4274
|
138 |
\texttt{use} commands may contain path variables that are expanded
|
wenzelm@4317
|
139 |
appropriately, e.g.\ \texttt{\$ISABELLE_HOME} or \texttt{\~\relax}
|
wenzelm@4317
|
140 |
(which abbreviates \texttt{\$HOME}). Section~\ref{LoadingTheories}
|
wenzelm@4274
|
141 |
describes commands for loading theory files.
|
wenzelm@4274
|
142 |
|
lcp@104
|
143 |
|
wenzelm@3108
|
144 |
\section{Setting flags}
|
wenzelm@3108
|
145 |
\begin{ttbox}
|
wenzelm@3108
|
146 |
set : bool ref -> bool
|
wenzelm@3108
|
147 |
reset : bool ref -> bool
|
wenzelm@3108
|
148 |
toggle : bool ref -> bool
|
wenzelm@3108
|
149 |
\end{ttbox}\index{*set}\index{*reset}\index{*toggle}
|
paulson@3485
|
150 |
These are some shorthands for manipulating boolean references. The new
|
wenzelm@3108
|
151 |
value is returned.
|
wenzelm@3108
|
152 |
|
wenzelm@3108
|
153 |
|
lcp@508
|
154 |
\section{Printing of terms and theorems}\label{sec:printing-control}
|
lcp@322
|
155 |
\index{printing control|(}
|
lcp@104
|
156 |
Isabelle's pretty printer is controlled by a number of parameters.
|
lcp@104
|
157 |
|
lcp@104
|
158 |
\subsection{Printing limits}
|
lcp@104
|
159 |
\begin{ttbox}
|
lcp@104
|
160 |
Pretty.setdepth : int -> unit
|
lcp@104
|
161 |
Pretty.setmargin : int -> unit
|
lcp@104
|
162 |
print_depth : int -> unit
|
lcp@104
|
163 |
\end{ttbox}
|
wenzelm@4317
|
164 |
These set limits for terminal output. See also {\tt goals_limit},
|
wenzelm@4317
|
165 |
which limits the number of subgoals printed
|
wenzelm@4317
|
166 |
(\S\ref{sec:goals-printing}).
|
lcp@104
|
167 |
|
lcp@322
|
168 |
\begin{ttdescription}
|
lcp@322
|
169 |
\item[\ttindexbold{Pretty.setdepth} \(d\);]
|
lcp@322
|
170 |
tells Isabelle's pretty printer to limit the printing depth to~$d$. This
|
lcp@322
|
171 |
affects Isabelle's display of theorems and terms. The default value
|
lcp@322
|
172 |
is~0, which permits printing to an arbitrary depth. Useful values for
|
lcp@322
|
173 |
$d$ are~10 and~20.
|
lcp@104
|
174 |
|
lcp@322
|
175 |
\item[\ttindexbold{Pretty.setmargin} \(m\);]
|
lcp@322
|
176 |
tells Isabelle's pretty printer to assume a right margin (page width)
|
wenzelm@4317
|
177 |
of~$m$. The initial margin is~76.
|
lcp@104
|
178 |
|
lcp@322
|
179 |
\item[\ttindexbold{print_depth} \(n\);]
|
lcp@322
|
180 |
limits the printing depth of complex \ML{} values, such as theorems and
|
lcp@322
|
181 |
terms. This command affects the \ML{} top level and its effect is
|
lcp@322
|
182 |
compiler-dependent. Typically $n$ should be less than~10.
|
lcp@322
|
183 |
\end{ttdescription}
|
lcp@104
|
184 |
|
lcp@104
|
185 |
|
wenzelm@4317
|
186 |
\subsection{Printing of hypotheses, brackets, types etc.}
|
lcp@322
|
187 |
\index{meta-assumptions!printing of}
|
lcp@322
|
188 |
\index{types!printing of}\index{sorts!printing of}
|
lcp@104
|
189 |
\begin{ttbox}
|
lcp@508
|
190 |
show_hyps : bool ref \hfill{\bf initially true}
|
lcp@508
|
191 |
show_brackets : bool ref \hfill{\bf initially false}
|
lcp@508
|
192 |
show_types : bool ref \hfill{\bf initially false}
|
lcp@508
|
193 |
show_sorts : bool ref \hfill{\bf initially false}
|
wenzelm@4317
|
194 |
show_consts : bool ref \hfill{\bf initially false}
|
lcp@104
|
195 |
\end{ttbox}
|
lcp@322
|
196 |
These flags allow you to control how much information is displayed for
|
wenzelm@4317
|
197 |
types, terms and theorems. The hypotheses of theorems \emph{are}
|
wenzelm@4317
|
198 |
normally shown. Superfluous parentheses of types and terms are not.
|
wenzelm@4317
|
199 |
Types and sorts of variables are normally hidden.
|
wenzelm@4317
|
200 |
|
wenzelm@4317
|
201 |
Note that displaying types and sorts may explain why a polymorphic
|
wenzelm@4317
|
202 |
inference rule fails to resolve with some goal, or why a rewrite rule
|
wenzelm@4317
|
203 |
does not apply as expected.
|
lcp@104
|
204 |
|
lcp@322
|
205 |
\begin{ttdescription}
|
wenzelm@4317
|
206 |
\item[reset \ttindexbold{show_hyps};] makes Isabelle show each
|
wenzelm@4317
|
207 |
meta-level hypothesis as a dot.
|
wenzelm@4317
|
208 |
|
wenzelm@4317
|
209 |
\item[set \ttindexbold{show_brackets};] makes Isabelle show full
|
wenzelm@4317
|
210 |
bracketing. In particular, this reveals the grouping of infix
|
wenzelm@4317
|
211 |
operators.
|
wenzelm@4317
|
212 |
|
wenzelm@4317
|
213 |
\item[set \ttindexbold{show_types};] makes Isabelle show types when
|
wenzelm@4317
|
214 |
printing a term or theorem.
|
wenzelm@4317
|
215 |
|
wenzelm@4317
|
216 |
\item[set \ttindexbold{show_sorts};] makes Isabelle show both types
|
wenzelm@4317
|
217 |
and the sorts of type variables, independently of the value of
|
wenzelm@4317
|
218 |
\texttt{show_types}.
|
wenzelm@4317
|
219 |
|
wenzelm@4317
|
220 |
\item[set \ttindexbold{show_consts};] makes Isabelle show types of
|
wenzelm@4317
|
221 |
constants, provided that showing of types is enabled at all. This
|
wenzelm@4317
|
222 |
is supported for printing of proof states only. Note that the
|
wenzelm@4317
|
223 |
output can be enormous as polymorphic constants often occur at
|
wenzelm@4317
|
224 |
several different type instances.
|
lcp@104
|
225 |
|
lcp@322
|
226 |
\end{ttdescription}
|
lcp@104
|
227 |
|
lcp@104
|
228 |
|
lcp@104
|
229 |
\subsection{$\eta$-contraction before printing}
|
lcp@104
|
230 |
\begin{ttbox}
|
lcp@104
|
231 |
eta_contract: bool ref \hfill{\bf initially false}
|
lcp@104
|
232 |
\end{ttbox}
|
lcp@104
|
233 |
The {\bf $\eta$-contraction law} asserts $(\lambda x.f(x))\equiv f$,
|
lcp@104
|
234 |
provided $x$ is not free in ~$f$. It asserts {\bf extensionality} of
|
lcp@104
|
235 |
functions: $f\equiv g$ if $f(x)\equiv g(x)$ for all~$x$. Higher-order
|
lcp@332
|
236 |
unification frequently puts terms into a fully $\eta$-expanded form. For
|
lcp@158
|
237 |
example, if $F$ has type $(\tau\To\tau)\To\tau$ then its expanded form is
|
lcp@158
|
238 |
$\lambda h.F(\lambda x.h(x))$. By default, the user sees this expanded
|
lcp@158
|
239 |
form.
|
lcp@104
|
240 |
|
lcp@322
|
241 |
\begin{ttdescription}
|
wenzelm@4317
|
242 |
\item[set \ttindexbold{eta_contract};]
|
lcp@104
|
243 |
makes Isabelle perform $\eta$-contractions before printing, so that
|
lcp@104
|
244 |
$\lambda h.F(\lambda x.h(x))$ appears simply as~$F$. The
|
lcp@104
|
245 |
distinction between a term and its $\eta$-expanded form occasionally
|
lcp@104
|
246 |
matters.
|
lcp@322
|
247 |
\end{ttdescription}
|
lcp@322
|
248 |
\index{printing control|)}
|
lcp@104
|
249 |
|
wenzelm@4317
|
250 |
\section{Diagnostic messages}
|
wenzelm@4317
|
251 |
\index{error messages}
|
wenzelm@4317
|
252 |
\index{warnings}
|
wenzelm@4317
|
253 |
|
wenzelm@4317
|
254 |
Isabelle conceptually provides three output channels for different
|
wenzelm@4317
|
255 |
kinds of messages: ordinary text, warnings, errors. Depending on the
|
wenzelm@4317
|
256 |
user interface involved, these messages may appear in different text
|
wenzelm@4317
|
257 |
styles or colours, even within separate windows.
|
wenzelm@4317
|
258 |
|
wenzelm@4317
|
259 |
The default setup of an \texttt{isabelle} terminal session is as
|
wenzelm@4317
|
260 |
follows: plain output of ordinary text, warnings prefixed by
|
wenzelm@4317
|
261 |
\texttt{\#\#\#}'s, errors prefixed by \texttt{***}'s. For example, a
|
wenzelm@4317
|
262 |
typical warning would look like this:
|
wenzelm@4317
|
263 |
\begin{ttbox}
|
wenzelm@4317
|
264 |
\#\#\# Beware the Jabberwock, my son!
|
wenzelm@4317
|
265 |
\#\#\# The jaws that bite, the claws that catch!
|
wenzelm@4317
|
266 |
\#\#\# Beware the Jubjub Bird, and shun
|
wenzelm@4317
|
267 |
\#\#\# The frumious Bandersnatch!
|
wenzelm@4317
|
268 |
\end{ttbox}
|
wenzelm@4317
|
269 |
|
wenzelm@4317
|
270 |
\texttt{ML} programs may output diagnostic messages using the
|
wenzelm@4317
|
271 |
following functions:
|
wenzelm@4317
|
272 |
\begin{ttbox}
|
wenzelm@4317
|
273 |
writeln : string -> unit
|
wenzelm@4317
|
274 |
warning : string -> unit
|
wenzelm@4317
|
275 |
error : string -> 'a
|
wenzelm@4317
|
276 |
\end{ttbox}
|
wenzelm@4317
|
277 |
Note that \ttindex{error} fails by raising exception \ttindex{ERROR}
|
wenzelm@4317
|
278 |
after having output the text, while \ttindex{writeln} and
|
wenzelm@4317
|
279 |
\ttindex{warning} resume normal program execution.
|
wenzelm@4317
|
280 |
|
lcp@104
|
281 |
|
lcp@104
|
282 |
\section{Displaying exceptions as error messages}
|
lcp@322
|
283 |
\index{exceptions!printing of}
|
lcp@104
|
284 |
\begin{ttbox}
|
lcp@104
|
285 |
print_exn: exn -> 'a
|
lcp@104
|
286 |
\end{ttbox}
|
lcp@104
|
287 |
Certain Isabelle primitives, such as the forward proof functions {\tt RS}
|
lcp@104
|
288 |
and {\tt RSN}, are called both interactively and from programs. They
|
lcp@104
|
289 |
indicate errors not by printing messages, but by raising exceptions. For
|
wenzelm@4317
|
290 |
interactive use, \ML's reporting of an uncaught exception may be
|
lcp@322
|
291 |
uninformative. The Poly/ML function {\tt exception_trace} can generate a
|
lcp@322
|
292 |
backtrace.\index{Poly/{\ML} compiler}
|
lcp@104
|
293 |
|
lcp@322
|
294 |
\begin{ttdescription}
|
lcp@104
|
295 |
\item[\ttindexbold{print_exn} $e$]
|
lcp@104
|
296 |
displays the exception~$e$ in a readable manner, and then re-raises~$e$.
|
lcp@322
|
297 |
Typical usage is~\hbox{\tt $EXP$ handle e => print_exn e;}, where
|
lcp@322
|
298 |
$EXP$ is an expression that may raise an exception.
|
lcp@104
|
299 |
|
lcp@104
|
300 |
{\tt print_exn} can display the following common exceptions, which concern
|
lcp@104
|
301 |
types, terms, theorems and theories, respectively. Each carries a message
|
lcp@104
|
302 |
and related information.
|
lcp@104
|
303 |
\begin{ttbox}
|
lcp@104
|
304 |
exception TYPE of string * typ list * term list
|
lcp@104
|
305 |
exception TERM of string * term list
|
lcp@104
|
306 |
exception THM of string * int * thm list
|
lcp@104
|
307 |
exception THEORY of string * theory list
|
lcp@104
|
308 |
\end{ttbox}
|
lcp@322
|
309 |
\end{ttdescription}
|
lcp@322
|
310 |
\begin{warn}
|
lcp@322
|
311 |
{\tt print_exn} prints terms by calling \ttindex{prin}, which obtains
|
lcp@322
|
312 |
pretty printing information from the proof state last stored in the
|
lcp@322
|
313 |
subgoal module. The appearance of the output thus depends upon the
|
lcp@322
|
314 |
theory used in the last interactive proof.
|
lcp@322
|
315 |
\end{warn}
|
lcp@104
|
316 |
|
lcp@104
|
317 |
\index{sessions|)}
|