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