doc-src/Ref/introduction.tex
author wenzelm
Tue May 06 12:50:16 1997 +0200 (1997-05-06)
changeset 3108 335efc3f5632
parent 2225 78a8faae780f
child 3200 ea2310ba01da
permissions -rw-r--r--
misc updates, tuning, cleanup;
lcp@104
     1
%% $Id$
wenzelm@3108
     2
lcp@286
     3
\chapter{Basic Use of Isabelle}\index{sessions|(} 
wenzelm@3108
     4
The Reference Manual is a comprehensive description of Isabelle
wenzelm@3108
     5
proper, including all \ML{} commands, functions and packages.  It
wenzelm@3108
     6
really is intended for reference, perhaps for browsing, but not for
wenzelm@3108
     7
reading through.  It is not a tutorial, but assumes familiarity with
wenzelm@3108
     8
the basic logical concepts of Isabelle.
lcp@104
     9
lcp@286
    10
When you are looking for a way of performing some task, scan the Table of
lcp@286
    11
Contents for a relevant heading.  Functions are organized by their purpose,
lcp@286
    12
by their operands (subgoals, tactics, theorems), and by their usefulness.
lcp@286
    13
In each section, basic functions appear first, then advanced functions, and
lcp@322
    14
finally esoteric functions.  Use the Index when you are looking for the
lcp@322
    15
definition of a particular Isabelle function.
lcp@104
    16
lcp@286
    17
A few examples are presented.  Many examples files are distributed with
lcp@286
    18
Isabelle, however; please experiment interactively.
lcp@104
    19
lcp@104
    20
lcp@104
    21
\section{Basic interaction with Isabelle}
paulson@2225
    22
\index{starting up|bold}\nobreak
paulson@2225
    23
%
wenzelm@3108
    24
We assume that your local Isabelle administrator (this might be you!)
wenzelm@3108
    25
has already installed the \Pure\ system and several object-logics
wenzelm@3108
    26
properly --- otherwise see the {\tt INSTALL} file in the top-level
wenzelm@3108
    27
directory of the distribution on how to build it.
wenzelm@3108
    28
wenzelm@3108
    29
\medskip Let $\langle isabellehome \rangle$ denote the location where
wenzelm@3108
    30
the distribution has been installed. To run Isabelle from a the shell
wenzelm@3108
    31
prompt within an ordinary text terminal session, simply type:
wenzelm@3108
    32
\begin{ttbox}
wenzelm@3108
    33
\({\langle}isabellehome{\rangle}\)/bin/isabelle
wenzelm@3108
    34
\end{ttbox}
wenzelm@3108
    35
This should start an interactive \ML{} session with the default
wenzelm@3108
    36
object-logic already preloaded. All Isabelle commands are bound to
wenzelm@3108
    37
\ML{} identifiers.
wenzelm@3108
    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.
wenzelm@3108
    42
wenzelm@3108
    43
The object-logic image to load may be also specified explicitly as an
wenzelm@3108
    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).
paulson@2225
    50
wenzelm@3108
    51
\index{saving your work|bold} Isabelle provides no means of storing
wenzelm@3108
    52
theorems or proofs on files.  Theorems are simply part of the \ML{}
wenzelm@3108
    53
state and are named by \ML{} identifiers.  To save your work between
wenzelm@3108
    54
sessions, you must dump the \ML{} system state to a file. This is done
wenzelm@3108
    55
automatically when ending the session normally (e.g.\ by typing
wenzelm@3108
    56
control-D), provided that the image has been opened \emph{writable} in
wenzelm@3108
    57
the first place. The standard object-logics are usually read-only, so
wenzelm@3108
    58
you probably have to create a private working copy first. For example,
wenzelm@3108
    59
the following shell command puts you into a writable Isabelle session
wenzelm@3108
    60
of 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
wenzelm@3108
    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}
lcp@104
    73
wenzelm@3108
    74
%FIXME not yet
wenzelm@3108
    75
%More details about \texttt{isabelle} may be found in the \emph{System
wenzelm@3108
    76
%  Manual}.
wenzelm@3108
    77
wenzelm@3108
    78
\medskip Saving the state is not enough.  Record, on a file, the
wenzelm@3108
    79
top-level commands that generate your theories and proofs.  Such a
wenzelm@3108
    80
record allows you to replay the proofs whenever required, for instance
wenzelm@3108
    81
after making minor changes to the axioms.  Ideally, your record will
wenzelm@3108
    82
be somewhat intelligible to others as a formal description of your
wenzelm@3108
    83
work.
lcp@104
    84
wenzelm@3108
    85
\medskip There are more comfortable user interfaces than the
wenzelm@3108
    86
bare-bones \ML{} top-level run from a text terminal. The
wenzelm@3108
    87
\texttt{Isabelle} executable (note the capital I) runs one such
wenzelm@3108
    88
interface, depending on your local configuration.  Furthermore there
wenzelm@3108
    89
are a number of external utilities available. These are started
wenzelm@3108
    90
uniformly via the \texttt{isatool} wrapper.
lcp@104
    91
wenzelm@3108
    92
%FIXME not yet
wenzelm@3108
    93
%Again, see the \emph{System Manual} for more information user
wenzelm@3108
    94
%interfaces and utilities.
lcp@104
    95
lcp@104
    96
lcp@104
    97
\section{Ending a session}
lcp@104
    98
\begin{ttbox} 
wenzelm@3108
    99
quit    : unit -> unit
wenzelm@3108
   100
exit    : int -> unit
wenzelm@3108
   101
commit  : unit -> unit
lcp@104
   102
\end{ttbox}
lcp@322
   103
\begin{ttdescription}
wenzelm@3108
   104
\item[\ttindexbold{quit}();] ends the Isabelle session, without saving
wenzelm@3108
   105
  the state.
lcp@104
   106
wenzelm@3108
   107
\item[\ttindexbold{exit}();] same as {\tt quit}, passing a return code
wenzelm@3108
   108
  to the operating system.
lcp@104
   109
wenzelm@3108
   110
\item[\ttindexbold{commit}();] saves the current state without ending
wenzelm@3108
   111
  the session, provided that the logic image is opened read-write.
lcp@322
   112
\end{ttdescription}
lcp@104
   113
wenzelm@3108
   114
Typing control-D also finishes the session in essentially the same way
wenzelm@3108
   115
as the sequence {\tt commit(); quit();} would.
lcp@104
   116
lcp@104
   117
lcp@322
   118
\section{Reading ML files}
lcp@322
   119
\index{files!reading}
lcp@104
   120
\begin{ttbox} 
clasohm@138
   121
cd              : string -> unit
clasohm@884
   122
pwd             : unit -> string
clasohm@138
   123
use             : string -> unit
clasohm@138
   124
time_use        : string -> unit
lcp@104
   125
\end{ttbox}
lcp@322
   126
Section~\ref{LoadingTheories} describes commands for loading theory files.
lcp@322
   127
\begin{ttdescription}
lcp@322
   128
\item[\ttindexbold{cd} "{\it dir}";]
lcp@322
   129
  changes the current directory to {\it dir}.  This is the default directory
lcp@322
   130
  for reading files and for writing temporary files.
lcp@104
   131
wenzelm@3108
   132
\item[\ttindexbold{pwd}();] returns the path of the current directory.
clasohm@884
   133
lcp@322
   134
\item[\ttindexbold{use} "$file$";]  
lcp@104
   135
reads the given {\it file} as input to the \ML{} session.  Reading a file
lcp@104
   136
of Isabelle commands is the usual way of replaying a proof.
lcp@104
   137
lcp@322
   138
\item[\ttindexbold{time_use} "$file$";]  
lcp@104
   139
performs {\tt use~"$file$"} and prints the total execution time.
lcp@322
   140
\end{ttdescription}
lcp@104
   141
lcp@104
   142
wenzelm@3108
   143
\section{Setting flags}
wenzelm@3108
   144
\begin{ttbox}
wenzelm@3108
   145
set     : bool ref -> bool
wenzelm@3108
   146
reset   : bool ref -> bool
wenzelm@3108
   147
toggle  : bool ref -> bool
wenzelm@3108
   148
\end{ttbox}\index{*set}\index{*reset}\index{*toggle}
wenzelm@3108
   149
These are some shorthands for manipulating boolean references. The new
wenzelm@3108
   150
value is returned.
wenzelm@3108
   151
wenzelm@3108
   152
lcp@508
   153
\section{Printing of terms and theorems}\label{sec:printing-control}
lcp@322
   154
\index{printing control|(}
lcp@104
   155
Isabelle's pretty printer is controlled by a number of parameters.
lcp@104
   156
lcp@104
   157
\subsection{Printing limits}
lcp@104
   158
\begin{ttbox} 
lcp@104
   159
Pretty.setdepth  : int -> unit
lcp@104
   160
Pretty.setmargin : int -> unit
lcp@104
   161
print_depth      : int -> unit
lcp@104
   162
\end{ttbox}
lcp@508
   163
These set limits for terminal output.  See also {\tt goals_limit}, which
lcp@508
   164
limits the number of subgoals printed (page~\pageref{sec:goals-printing}).
lcp@104
   165
lcp@322
   166
\begin{ttdescription}
lcp@322
   167
\item[\ttindexbold{Pretty.setdepth} \(d\);]  
lcp@322
   168
  tells Isabelle's pretty printer to limit the printing depth to~$d$.  This
lcp@322
   169
  affects Isabelle's display of theorems and terms.  The default value
lcp@322
   170
  is~0, which permits printing to an arbitrary depth.  Useful values for
lcp@322
   171
  $d$ are~10 and~20.
lcp@104
   172
lcp@322
   173
\item[\ttindexbold{Pretty.setmargin} \(m\);]  
lcp@322
   174
  tells Isabelle's pretty printer to assume a right margin (page width)
lcp@322
   175
  of~$m$.  The initial margin is~80.
lcp@104
   176
lcp@322
   177
\item[\ttindexbold{print_depth} \(n\);]  
lcp@322
   178
  limits the printing depth of complex \ML{} values, such as theorems and
lcp@322
   179
  terms.  This command affects the \ML{} top level and its effect is
lcp@322
   180
  compiler-dependent.  Typically $n$ should be less than~10.
lcp@322
   181
\end{ttdescription}
lcp@104
   182
lcp@104
   183
lcp@508
   184
\subsection{Printing of hypotheses, brackets, types and sorts}
lcp@322
   185
\index{meta-assumptions!printing of}
lcp@322
   186
\index{types!printing of}\index{sorts!printing of}
lcp@104
   187
\begin{ttbox} 
lcp@508
   188
show_hyps     : bool ref \hfill{\bf initially true}
lcp@508
   189
show_brackets : bool ref \hfill{\bf initially false}
lcp@508
   190
show_types    : bool ref \hfill{\bf initially false}
lcp@508
   191
show_sorts    : bool ref \hfill{\bf initially false}
lcp@104
   192
\end{ttbox}
lcp@322
   193
These flags allow you to control how much information is displayed for
lcp@508
   194
terms and theorems.  The hypotheses are normally shown; superfluous
lcp@508
   195
parentheses are not.  Types and sorts are normally hidden.  Displaying
lcp@508
   196
types and sorts may explain why a polymorphic inference rule fails to
lcp@508
   197
resolve with some goal.
lcp@104
   198
lcp@322
   199
\begin{ttdescription}
lcp@322
   200
\item[\ttindexbold{show_hyps} := false;]   
lcp@332
   201
makes Isabelle show each meta-level hypothesis as a dot.
lcp@104
   202
lcp@508
   203
\item[\ttindexbold{show_brackets} := true;] 
lcp@508
   204
  makes Isabelle show full bracketing.  This reveals the
lcp@508
   205
  grouping of infix operators.
lcp@508
   206
lcp@322
   207
\item[\ttindexbold{show_types} := true;]
lcp@104
   208
makes Isabelle show types when printing a term or theorem.
lcp@104
   209
lcp@322
   210
\item[\ttindexbold{show_sorts} := true;]
lcp@1102
   211
makes Isabelle show both types and the sorts of type variables.  It does not
lcp@1102
   212
matter whether {\tt show_types} is also~{\tt true}. 
lcp@322
   213
\end{ttdescription}
lcp@104
   214
lcp@104
   215
lcp@104
   216
\subsection{$\eta$-contraction before printing}
lcp@104
   217
\begin{ttbox} 
lcp@104
   218
eta_contract: bool ref \hfill{\bf initially false}
lcp@104
   219
\end{ttbox}
lcp@104
   220
The {\bf $\eta$-contraction law} asserts $(\lambda x.f(x))\equiv f$,
lcp@104
   221
provided $x$ is not free in ~$f$.  It asserts {\bf extensionality} of
lcp@104
   222
functions: $f\equiv g$ if $f(x)\equiv g(x)$ for all~$x$.  Higher-order
lcp@332
   223
unification frequently puts terms into a fully $\eta$-expanded form.  For
lcp@158
   224
example, if $F$ has type $(\tau\To\tau)\To\tau$ then its expanded form is
lcp@158
   225
$\lambda h.F(\lambda x.h(x))$.  By default, the user sees this expanded
lcp@158
   226
form.
lcp@104
   227
lcp@322
   228
\begin{ttdescription}
lcp@322
   229
\item[\ttindexbold{eta_contract} := true;]
lcp@104
   230
makes Isabelle perform $\eta$-contractions before printing, so that
lcp@104
   231
$\lambda h.F(\lambda x.h(x))$ appears simply as~$F$.  The
lcp@104
   232
distinction between a term and its $\eta$-expanded form occasionally
lcp@104
   233
matters.
lcp@322
   234
\end{ttdescription}
lcp@322
   235
\index{printing control|)}
lcp@104
   236
lcp@104
   237
lcp@104
   238
\section{Displaying exceptions as error messages}
lcp@322
   239
\index{exceptions!printing of}
lcp@104
   240
\begin{ttbox} 
lcp@104
   241
print_exn: exn -> 'a
lcp@104
   242
\end{ttbox}
lcp@104
   243
Certain Isabelle primitives, such as the forward proof functions {\tt RS}
lcp@104
   244
and {\tt RSN}, are called both interactively and from programs.  They
lcp@104
   245
indicate errors not by printing messages, but by raising exceptions.  For
lcp@322
   246
interactive use, \ML's reporting of an uncaught exception is 
lcp@322
   247
uninformative.  The Poly/ML function {\tt exception_trace} can generate a
lcp@322
   248
backtrace.\index{Poly/{\ML} compiler}
lcp@104
   249
lcp@322
   250
\begin{ttdescription}
lcp@104
   251
\item[\ttindexbold{print_exn} $e$] 
lcp@104
   252
displays the exception~$e$ in a readable manner, and then re-raises~$e$.
lcp@322
   253
Typical usage is~\hbox{\tt $EXP$ handle e => print_exn e;}, where
lcp@322
   254
$EXP$ is an expression that may raise an exception.
lcp@104
   255
lcp@104
   256
{\tt print_exn} can display the following common exceptions, which concern
lcp@104
   257
types, terms, theorems and theories, respectively.  Each carries a message
lcp@104
   258
and related information.
lcp@104
   259
\begin{ttbox} 
lcp@104
   260
exception TYPE   of string * typ list * term list
lcp@104
   261
exception TERM   of string * term list
lcp@104
   262
exception THM    of string * int * thm list
lcp@104
   263
exception THEORY of string * theory list
lcp@104
   264
\end{ttbox}
lcp@322
   265
\end{ttdescription}
lcp@322
   266
\begin{warn}
lcp@322
   267
  {\tt print_exn} prints terms by calling \ttindex{prin}, which obtains
lcp@322
   268
  pretty printing information from the proof state last stored in the
lcp@322
   269
  subgoal module.  The appearance of the output thus depends upon the
lcp@322
   270
  theory used in the last interactive proof.
lcp@322
   271
\end{warn}
lcp@104
   272
wenzelm@3108
   273
%FIXME remove
wenzelm@3108
   274
%\section{Shell scripts}\label{sec:shell-scripts}
wenzelm@3108
   275
%\index{shell scripts|bold} The following files are distributed with
wenzelm@3108
   276
%Isabelle, and work under Unix$^{\rm TM}$.  They can be executed as commands
wenzelm@3108
   277
%to the Unix shell.  Some of them depend upon shell environment variables.
wenzelm@3108
   278
%\begin{ttdescription}
wenzelm@3108
   279
%\item[make-all $switches$] \index{*make-all shell script}
wenzelm@3108
   280
%  compiles the Isabelle system, when executed on the source directory.
wenzelm@3108
   281
%  Environment variables specify which \ML{} compiler to use.  These
wenzelm@3108
   282
%  variables, and the {\it switches}, are documented on the file itself.
wenzelm@3108
   283
%
wenzelm@3108
   284
%\item[teeinput $program$] \index{*teeinput shell script}
wenzelm@3108
   285
%  executes the {\it program}, while piping the standard input to a log file
wenzelm@3108
   286
%  designated by the \verb|$LISTEN| environment variable.  Normally the
wenzelm@3108
   287
%  program is Isabelle, and the log file receives a copy of all the Isabelle
wenzelm@3108
   288
%  commands.
wenzelm@3108
   289
%
wenzelm@3108
   290
%\item[xlisten $program$] \index{*xlisten shell script}
wenzelm@3108
   291
%  is a trivial `user interface' for the X Window System.  It creates two
wenzelm@3108
   292
%  windows using {\tt xterm}.  One executes an interactive session via
wenzelm@3108
   293
%  \hbox{\tt teeinput $program$}, while the other displays the log file.  To
wenzelm@3108
   294
%  make a proof record, simply paste lines from the log file into an editor
wenzelm@3108
   295
%  window.
wenzelm@3108
   296
%
wenzelm@3108
   297
%\item[expandshort $files$]  \index{*expandshort shell script}
wenzelm@3108
   298
%  reads the {\it files\/} and replaces all occurrences of the shorthand
wenzelm@3108
   299
%  commands {\tt br}, {\tt be}, {\tt brs}, {\tt bes}, etc., with the
wenzelm@3108
   300
%  corresponding full commands.  Shorthand commands should appear one
wenzelm@3108
   301
%  per line.  The old versions of the files
wenzelm@3108
   302
%  are renamed to have the suffix~\verb'~~'.
wenzelm@3108
   303
%\end{ttdescription}
lcp@104
   304
lcp@104
   305
\index{sessions|)}