doc-src/Ref/introduction.tex
author wenzelm
Fri Nov 21 15:37:02 1997 +0100 (1997-11-21)
changeset 4274 2048e7a79d09
parent 3485 f27a30a18a17
child 4317 7264fa2ff2ec
permissions -rw-r--r--
cd, use: path variables;
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.
wenzelm@3108
    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@3108
    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
paulson@3485
    37
object-logic already preloaded.  All Isabelle commands are bound to
wenzelm@3108
    38
\ML{} identifiers.
wenzelm@3108
    39
wenzelm@3108
    40
Subsequently we assume that {\tt \(\langle isabellehome \rangle\)/bin}
wenzelm@3108
    41
has been added to your shell's search path, in order to avoid typing
wenzelm@3108
    42
full path specifications of the executable files.
wenzelm@3108
    43
wenzelm@3108
    44
The object-logic image to load may be also specified explicitly as an
wenzelm@3108
    45
argument to the {\tt isabelle} command, e.g.:
wenzelm@3108
    46
\begin{ttbox}
wenzelm@3108
    47
isabelle FOL
wenzelm@3108
    48
\end{ttbox}
wenzelm@3108
    49
This should put you into the world of polymorphic first-order logic
wenzelm@3108
    50
(assuming that {\FOL} has been pre-built).
paulson@2225
    51
wenzelm@3108
    52
\index{saving your work|bold} Isabelle provides no means of storing
wenzelm@3108
    53
theorems or proofs on files.  Theorems are simply part of the \ML{}
wenzelm@3108
    54
state and are named by \ML{} identifiers.  To save your work between
paulson@3485
    55
sessions, you must dump the \ML{} system state to a file.  This is done
wenzelm@3108
    56
automatically when ending the session normally (e.g.\ by typing
wenzelm@3108
    57
control-D), provided that the image has been opened \emph{writable} in
paulson@3485
    58
the first place.  The standard object-logics are usually read-only, so
paulson@3485
    59
you probably have to create a private working copy first.  For example,
wenzelm@3108
    60
the following shell command puts you into a writable Isabelle session
wenzelm@3108
    61
of name \texttt{Foo} that initially contains just \FOL:
wenzelm@3108
    62
\begin{ttbox}
wenzelm@3108
    63
isabelle FOL Foo
wenzelm@3108
    64
\end{ttbox}
wenzelm@3108
    65
Ending the \texttt{Foo} session with control-D will cause the complete
wenzelm@3108
    66
\ML{} world to be saved somewhere in your home directory\footnote{The
wenzelm@3108
    67
  default location is in \texttt{\~\relax/isabelle/heaps}, but this
paulson@3485
    68
  depends on your local configuration.}.  Make sure there is enough
wenzelm@3108
    69
space available! Then one may later continue at exactly the same point
wenzelm@3108
    70
by running
wenzelm@3108
    71
\begin{ttbox}
wenzelm@3108
    72
isabelle Foo  
wenzelm@3108
    73
\end{ttbox}
lcp@104
    74
wenzelm@3200
    75
More details about \texttt{isabelle} may be found in the \emph{System
wenzelm@3200
    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
paulson@3485
    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
paulson@3485
    89
are a number of external utilities available.  These are started
wenzelm@3108
    90
uniformly via the \texttt{isatool} wrapper.
lcp@104
    91
wenzelm@3200
    92
Again, see the \emph{System Manual} for more information user
wenzelm@3200
    93
interfaces and utilities.
lcp@104
    94
lcp@104
    95
lcp@104
    96
\section{Ending a session}
lcp@104
    97
\begin{ttbox} 
wenzelm@3108
    98
quit    : unit -> unit
wenzelm@3108
    99
exit    : int -> unit
wenzelm@3108
   100
commit  : unit -> unit
lcp@104
   101
\end{ttbox}
lcp@322
   102
\begin{ttdescription}
wenzelm@3108
   103
\item[\ttindexbold{quit}();] ends the Isabelle session, without saving
wenzelm@3108
   104
  the state.
lcp@104
   105
wenzelm@3108
   106
\item[\ttindexbold{exit}();] same as {\tt quit}, passing a return code
wenzelm@3108
   107
  to the operating system.
lcp@104
   108
wenzelm@3108
   109
\item[\ttindexbold{commit}();] saves the current state without ending
wenzelm@3108
   110
  the session, provided that the logic image is opened read-write.
lcp@322
   111
\end{ttdescription}
lcp@104
   112
wenzelm@3108
   113
Typing control-D also finishes the session in essentially the same way
wenzelm@3108
   114
as the sequence {\tt commit(); quit();} would.
lcp@104
   115
lcp@104
   116
lcp@322
   117
\section{Reading ML files}
lcp@322
   118
\index{files!reading}
lcp@104
   119
\begin{ttbox} 
clasohm@138
   120
cd              : string -> unit
clasohm@884
   121
pwd             : unit -> string
clasohm@138
   122
use             : string -> unit
clasohm@138
   123
time_use        : string -> unit
lcp@104
   124
\end{ttbox}
lcp@322
   125
\begin{ttdescription}
lcp@322
   126
\item[\ttindexbold{cd} "{\it dir}";]
lcp@322
   127
  changes the current directory to {\it dir}.  This is the default directory
lcp@322
   128
  for reading files and for writing temporary files.
lcp@104
   129
wenzelm@3108
   130
\item[\ttindexbold{pwd}();] returns the path of the current directory.
clasohm@884
   131
lcp@322
   132
\item[\ttindexbold{use} "$file$";]  
lcp@104
   133
reads the given {\it file} as input to the \ML{} session.  Reading a file
lcp@104
   134
of Isabelle commands is the usual way of replaying a proof.
lcp@104
   135
lcp@322
   136
\item[\ttindexbold{time_use} "$file$";]  
lcp@104
   137
performs {\tt use~"$file$"} and prints the total execution time.
lcp@322
   138
\end{ttdescription}
lcp@104
   139
wenzelm@4274
   140
The $dir$ and $file$ specifications of the \texttt{cd} and
wenzelm@4274
   141
\texttt{use} commands may contain path variables that are expanded
wenzelm@4274
   142
accordingly --- e.g.\ \texttt{\$ISABELLE_HOME}, or \texttt{\~\relax}
wenzelm@4274
   143
(abbreviating \texttt{\$HOME}).  Section~\ref{LoadingTheories}
wenzelm@4274
   144
describes commands for loading theory files.
wenzelm@4274
   145
lcp@104
   146
wenzelm@3108
   147
\section{Setting flags}
wenzelm@3108
   148
\begin{ttbox}
wenzelm@3108
   149
set     : bool ref -> bool
wenzelm@3108
   150
reset   : bool ref -> bool
wenzelm@3108
   151
toggle  : bool ref -> bool
wenzelm@3108
   152
\end{ttbox}\index{*set}\index{*reset}\index{*toggle}
paulson@3485
   153
These are some shorthands for manipulating boolean references.  The new
wenzelm@3108
   154
value is returned.
wenzelm@3108
   155
wenzelm@3108
   156
lcp@508
   157
\section{Printing of terms and theorems}\label{sec:printing-control}
lcp@322
   158
\index{printing control|(}
lcp@104
   159
Isabelle's pretty printer is controlled by a number of parameters.
lcp@104
   160
lcp@104
   161
\subsection{Printing limits}
lcp@104
   162
\begin{ttbox} 
lcp@104
   163
Pretty.setdepth  : int -> unit
lcp@104
   164
Pretty.setmargin : int -> unit
lcp@104
   165
print_depth      : int -> unit
lcp@104
   166
\end{ttbox}
lcp@508
   167
These set limits for terminal output.  See also {\tt goals_limit}, which
lcp@508
   168
limits the number of subgoals printed (page~\pageref{sec:goals-printing}).
lcp@104
   169
lcp@322
   170
\begin{ttdescription}
lcp@322
   171
\item[\ttindexbold{Pretty.setdepth} \(d\);]  
lcp@322
   172
  tells Isabelle's pretty printer to limit the printing depth to~$d$.  This
lcp@322
   173
  affects Isabelle's display of theorems and terms.  The default value
lcp@322
   174
  is~0, which permits printing to an arbitrary depth.  Useful values for
lcp@322
   175
  $d$ are~10 and~20.
lcp@104
   176
lcp@322
   177
\item[\ttindexbold{Pretty.setmargin} \(m\);]  
lcp@322
   178
  tells Isabelle's pretty printer to assume a right margin (page width)
lcp@322
   179
  of~$m$.  The initial margin is~80.
lcp@104
   180
lcp@322
   181
\item[\ttindexbold{print_depth} \(n\);]  
lcp@322
   182
  limits the printing depth of complex \ML{} values, such as theorems and
lcp@322
   183
  terms.  This command affects the \ML{} top level and its effect is
lcp@322
   184
  compiler-dependent.  Typically $n$ should be less than~10.
lcp@322
   185
\end{ttdescription}
lcp@104
   186
lcp@104
   187
lcp@508
   188
\subsection{Printing of hypotheses, brackets, types and sorts}
lcp@322
   189
\index{meta-assumptions!printing of}
lcp@322
   190
\index{types!printing of}\index{sorts!printing of}
lcp@104
   191
\begin{ttbox} 
lcp@508
   192
show_hyps     : bool ref \hfill{\bf initially true}
lcp@508
   193
show_brackets : bool ref \hfill{\bf initially false}
lcp@508
   194
show_types    : bool ref \hfill{\bf initially false}
lcp@508
   195
show_sorts    : bool ref \hfill{\bf initially false}
lcp@104
   196
\end{ttbox}
lcp@322
   197
These flags allow you to control how much information is displayed for
lcp@508
   198
terms and theorems.  The hypotheses are normally shown; superfluous
lcp@508
   199
parentheses are not.  Types and sorts are normally hidden.  Displaying
lcp@508
   200
types and sorts may explain why a polymorphic inference rule fails to
lcp@508
   201
resolve with some goal.
lcp@104
   202
lcp@322
   203
\begin{ttdescription}
lcp@322
   204
\item[\ttindexbold{show_hyps} := false;]   
lcp@332
   205
makes Isabelle show each meta-level hypothesis as a dot.
lcp@104
   206
lcp@508
   207
\item[\ttindexbold{show_brackets} := true;] 
lcp@508
   208
  makes Isabelle show full bracketing.  This reveals the
lcp@508
   209
  grouping of infix operators.
lcp@508
   210
lcp@322
   211
\item[\ttindexbold{show_types} := true;]
lcp@104
   212
makes Isabelle show types when printing a term or theorem.
lcp@104
   213
lcp@322
   214
\item[\ttindexbold{show_sorts} := true;]
lcp@1102
   215
makes Isabelle show both types and the sorts of type variables.  It does not
lcp@1102
   216
matter whether {\tt show_types} is also~{\tt true}. 
lcp@322
   217
\end{ttdescription}
lcp@104
   218
lcp@104
   219
lcp@104
   220
\subsection{$\eta$-contraction before printing}
lcp@104
   221
\begin{ttbox} 
lcp@104
   222
eta_contract: bool ref \hfill{\bf initially false}
lcp@104
   223
\end{ttbox}
lcp@104
   224
The {\bf $\eta$-contraction law} asserts $(\lambda x.f(x))\equiv f$,
lcp@104
   225
provided $x$ is not free in ~$f$.  It asserts {\bf extensionality} of
lcp@104
   226
functions: $f\equiv g$ if $f(x)\equiv g(x)$ for all~$x$.  Higher-order
lcp@332
   227
unification frequently puts terms into a fully $\eta$-expanded form.  For
lcp@158
   228
example, if $F$ has type $(\tau\To\tau)\To\tau$ then its expanded form is
lcp@158
   229
$\lambda h.F(\lambda x.h(x))$.  By default, the user sees this expanded
lcp@158
   230
form.
lcp@104
   231
lcp@322
   232
\begin{ttdescription}
lcp@322
   233
\item[\ttindexbold{eta_contract} := true;]
lcp@104
   234
makes Isabelle perform $\eta$-contractions before printing, so that
lcp@104
   235
$\lambda h.F(\lambda x.h(x))$ appears simply as~$F$.  The
lcp@104
   236
distinction between a term and its $\eta$-expanded form occasionally
lcp@104
   237
matters.
lcp@322
   238
\end{ttdescription}
lcp@322
   239
\index{printing control|)}
lcp@104
   240
lcp@104
   241
lcp@104
   242
\section{Displaying exceptions as error messages}
lcp@322
   243
\index{exceptions!printing of}
lcp@104
   244
\begin{ttbox} 
lcp@104
   245
print_exn: exn -> 'a
lcp@104
   246
\end{ttbox}
lcp@104
   247
Certain Isabelle primitives, such as the forward proof functions {\tt RS}
lcp@104
   248
and {\tt RSN}, are called both interactively and from programs.  They
lcp@104
   249
indicate errors not by printing messages, but by raising exceptions.  For
lcp@322
   250
interactive use, \ML's reporting of an uncaught exception is 
lcp@322
   251
uninformative.  The Poly/ML function {\tt exception_trace} can generate a
lcp@322
   252
backtrace.\index{Poly/{\ML} compiler}
lcp@104
   253
lcp@322
   254
\begin{ttdescription}
lcp@104
   255
\item[\ttindexbold{print_exn} $e$] 
lcp@104
   256
displays the exception~$e$ in a readable manner, and then re-raises~$e$.
lcp@322
   257
Typical usage is~\hbox{\tt $EXP$ handle e => print_exn e;}, where
lcp@322
   258
$EXP$ is an expression that may raise an exception.
lcp@104
   259
lcp@104
   260
{\tt print_exn} can display the following common exceptions, which concern
lcp@104
   261
types, terms, theorems and theories, respectively.  Each carries a message
lcp@104
   262
and related information.
lcp@104
   263
\begin{ttbox} 
lcp@104
   264
exception TYPE   of string * typ list * term list
lcp@104
   265
exception TERM   of string * term list
lcp@104
   266
exception THM    of string * int * thm list
lcp@104
   267
exception THEORY of string * theory list
lcp@104
   268
\end{ttbox}
lcp@322
   269
\end{ttdescription}
lcp@322
   270
\begin{warn}
lcp@322
   271
  {\tt print_exn} prints terms by calling \ttindex{prin}, which obtains
lcp@322
   272
  pretty printing information from the proof state last stored in the
lcp@322
   273
  subgoal module.  The appearance of the output thus depends upon the
lcp@322
   274
  theory used in the last interactive proof.
lcp@322
   275
\end{warn}
lcp@104
   276
lcp@104
   277
\index{sessions|)}