doc-src/Ref/introduction.tex
author Walther Neuper <neuper@ist.tugraz.at>
Thu, 12 Aug 2010 15:03:34 +0200
branchisac-from-Isabelle2009-2
changeset 37913 20e3616b2d9c
parent 37469 1c816f2abb0e
child 40273 b5d688221d1b
permissions -rw-r--r--
prepare reactivation of isac-update-Isa09-2
wenzelm@3108
     1
lcp@286
     2
\chapter{Basic Use of Isabelle}\index{sessions|(} 
lcp@104
     3
lcp@104
     4
\section{Basic interaction with Isabelle}
paulson@2225
     5
\index{starting up|bold}\nobreak
paulson@2225
     6
%
wenzelm@6568
     7
We assume that your local Isabelle administrator (this might be you!) has
wenzelm@37469
     8
already installed the Isabelle system together with appropriate object-logics.
paulson@2225
     9
wenzelm@3108
    10
\medskip Let $\langle isabellehome \rangle$ denote the location where
paulson@3485
    11
the distribution has been installed.  To run Isabelle from a the shell
wenzelm@4317
    12
prompt within an ordinary text terminal session, simply type
wenzelm@3108
    13
\begin{ttbox}
wenzelm@3108
    14
\({\langle}isabellehome{\rangle}\)/bin/isabelle
wenzelm@3108
    15
\end{ttbox}
wenzelm@6568
    16
This should start an interactive \ML{} session with the default object-logic
wenzelm@9695
    17
(usually HOL) already pre-loaded.
lcp@104
    18
wenzelm@6568
    19
Subsequently, we assume that the \texttt{isabelle} executable is determined
wenzelm@6568
    20
automatically by the shell, e.g.\ by adding {\tt \(\langle isabellehome
wenzelm@6568
    21
  \rangle\)/bin} to your search path.\footnote{Depending on your installation,
wenzelm@7990
    22
  there may be stand-alone binaries located in some global directory such as
wenzelm@7990
    23
  \texttt{/usr/bin}.  Do not attempt to copy {\tt \(\langle isabellehome
wenzelm@28504
    24
    \rangle\)/bin/isabelle}, though!  See \texttt{isabelle install} in
wenzelm@7990
    25
  \emph{The Isabelle System Manual} of how to do this properly.}
lcp@104
    26
wenzelm@6571
    27
\medskip
wenzelm@6571
    28
wenzelm@6568
    29
The object-logic image to load may be also specified explicitly as an argument
wenzelm@6568
    30
to the {\tt isabelle} command, e.g.
wenzelm@3108
    31
\begin{ttbox}
wenzelm@3108
    32
isabelle FOL
wenzelm@3108
    33
\end{ttbox}
wenzelm@6568
    34
This should put you into the world of polymorphic first-order logic (assuming
wenzelm@9695
    35
that an image of FOL has been pre-built).
lcp@104
    36
wenzelm@6568
    37
\index{saving your session|bold} Isabelle provides no means of storing
wenzelm@6568
    38
theorems or internal proof objects on files.  Theorems are simply part of the
wenzelm@6568
    39
\ML{} state.  To save your work between sessions, you may dump the \ML{}
wenzelm@6568
    40
system state to a file.  This is done automatically when ending the session
wenzelm@6568
    41
normally (e.g.\ by typing control-D), provided that the image has been opened
wenzelm@6568
    42
\emph{writable} in the first place.  The standard object-logic images are
wenzelm@6568
    43
usually read-only, so you have to create a private working copy first.  For
wenzelm@6568
    44
example, the following shell command puts you into a writable Isabelle session
wenzelm@9695
    45
of name \texttt{Foo} that initially contains just plain HOL:
wenzelm@3108
    46
\begin{ttbox}
wenzelm@6568
    47
isabelle HOL Foo
wenzelm@3108
    48
\end{ttbox}
wenzelm@3108
    49
Ending the \texttt{Foo} session with control-D will cause the complete
wenzelm@6568
    50
\ML-world to be saved somewhere in your home directory\footnote{The default
wenzelm@6568
    51
  location is in \texttt{\~\relax/isabelle/heaps}, but this depends on your
wenzelm@6568
    52
  local configuration.}.  Make sure there is enough space available! Then one
wenzelm@6568
    53
may later continue at exactly the same point by running
wenzelm@3108
    54
\begin{ttbox}
wenzelm@3108
    55
isabelle Foo  
wenzelm@3108
    56
\end{ttbox}
wenzelm@3108
    57
wenzelm@6568
    58
\medskip Saving the {\ML} state is not enough.  Record, on a file, the
wenzelm@6568
    59
top-level commands that generate your theories and proofs.  Such a record
wenzelm@6568
    60
allows you to replay the proofs whenever required, for instance after making
wenzelm@6571
    61
minor changes to the axioms.  Ideally, these sources will be somewhat
wenzelm@6568
    62
intelligible to others as a formal description of your work.
wenzelm@3108
    63
wenzelm@6568
    64
It is good practice to put all source files that constitute a separate
wenzelm@6568
    65
Isabelle session into an individual directory, together with an {\ML} file
wenzelm@6568
    66
called \texttt{ROOT.ML} that contains appropriate commands to load all other
wenzelm@6568
    67
files required.  Running \texttt{isabelle} with option \texttt{-u}
wenzelm@6568
    68
automatically loads \texttt{ROOT.ML} on entering the session.  The
wenzelm@28504
    69
\texttt{isabelle usedir} utility provides some more options to manage Isabelle
wenzelm@6568
    70
sessions, such as automatic generation of theory browsing information.
wenzelm@3108
    71
wenzelm@28504
    72
\medskip More details about the \texttt{isabelle} and \texttt{isabelle}
wenzelm@6568
    73
commands may be found in \emph{The Isabelle System Manual}.
wenzelm@6568
    74
wenzelm@6568
    75
\medskip There are more comfortable user interfaces than the bare-bones \ML{}
wenzelm@6568
    76
top-level run from a text terminal.  The \texttt{Isabelle} executable (note
wenzelm@6568
    77
the capital I) runs one such interface, depending on your local configuration.
wenzelm@6568
    78
Again, see \emph{The Isabelle System Manual} for more information.
lcp@104
    79
lcp@104
    80
lcp@104
    81
\section{Ending a session}
lcp@104
    82
\begin{ttbox} 
wenzelm@3108
    83
quit    : unit -> unit
wenzelm@3108
    84
exit    : int -> unit
wenzelm@6067
    85
commit  : unit -> bool
lcp@104
    86
\end{ttbox}
lcp@322
    87
\begin{ttdescription}
wenzelm@3108
    88
\item[\ttindexbold{quit}();] ends the Isabelle session, without saving
wenzelm@3108
    89
  the state.
wenzelm@4317
    90
  
wenzelm@4317
    91
\item[\ttindexbold{exit} \(i\);] similar to {\tt quit}, passing return
wenzelm@4317
    92
  code \(i\) to the operating system.
lcp@104
    93
wenzelm@3108
    94
\item[\ttindexbold{commit}();] saves the current state without ending
wenzelm@6067
    95
  the session, provided that the logic image is opened read-write;
wenzelm@6067
    96
  return value {\tt false} indicates an error.
lcp@322
    97
\end{ttdescription}
lcp@104
    98
wenzelm@3108
    99
Typing control-D also finishes the session in essentially the same way
wenzelm@3108
   100
as the sequence {\tt commit(); quit();} would.
lcp@104
   101
lcp@104
   102
lcp@322
   103
\section{Reading ML files}
lcp@322
   104
\index{files!reading}
lcp@104
   105
\begin{ttbox} 
clasohm@138
   106
cd              : string -> unit
clasohm@884
   107
pwd             : unit -> string
clasohm@138
   108
use             : string -> unit
clasohm@138
   109
time_use        : string -> unit
lcp@104
   110
\end{ttbox}
lcp@322
   111
\begin{ttdescription}
wenzelm@4317
   112
\item[\ttindexbold{cd} "{\it dir}";] changes the current directory to
wenzelm@4317
   113
  {\it dir}.  This is the default directory for reading files.
wenzelm@4317
   114
  
wenzelm@4317
   115
\item[\ttindexbold{pwd}();] returns the full path of the current
wenzelm@4317
   116
  directory.
clasohm@884
   117
lcp@322
   118
\item[\ttindexbold{use} "$file$";]  
lcp@104
   119
reads the given {\it file} as input to the \ML{} session.  Reading a file
lcp@104
   120
of Isabelle commands is the usual way of replaying a proof.
lcp@104
   121
lcp@322
   122
\item[\ttindexbold{time_use} "$file$";]  
lcp@104
   123
performs {\tt use~"$file$"} and prints the total execution time.
lcp@322
   124
\end{ttdescription}
lcp@104
   125
wenzelm@6343
   126
The $dir$ and $file$ specifications of the \texttt{cd} and \texttt{use}
wenzelm@6343
   127
commands may contain path variables (e.g.\ \texttt{\$ISABELLE_HOME}) that are
wenzelm@6343
   128
expanded appropriately.  Note that \texttt{\~\relax} abbreviates
wenzelm@6343
   129
\texttt{\$HOME}, and \texttt{\~\relax\~\relax} abbreviates
wenzelm@6571
   130
\texttt{\$ISABELLE_HOME}\index{*\$ISABELLE_HOME}.  The syntax for path
wenzelm@6571
   131
specifications follows Unix conventions.
wenzelm@6568
   132
wenzelm@6568
   133
wenzelm@6568
   134
\section{Reading theories}\label{sec:intro-theories}
wenzelm@6568
   135
\index{theories!reading}
wenzelm@6568
   136
wenzelm@6568
   137
In Isabelle, any kind of declarations, definitions, etc.\ are organized around
wenzelm@6568
   138
named \emph{theory} objects.  Logical reasoning always takes place within a
wenzelm@6568
   139
certain theory context, which may be switched at any time.  Theory $name$ is
wenzelm@6568
   140
defined by a theory file $name$\texttt{.thy}, containing declarations of
wenzelm@6568
   141
\texttt{consts}, \texttt{types}, \texttt{defs}, etc.\ (see
wenzelm@6568
   142
\S\ref{sec:ref-defining-theories} for more details on concrete syntax).
wenzelm@6568
   143
Furthermore, there may be an associated {\ML} file $name$\texttt{.ML} with
wenzelm@6568
   144
proof scripts that are to be run in the context of the theory.
wenzelm@6568
   145
wenzelm@6568
   146
\begin{ttbox}
wenzelm@6568
   147
context      : theory -> unit
wenzelm@6568
   148
the_context  : unit -> theory
wenzelm@6568
   149
theory       : string -> theory
wenzelm@6568
   150
use_thy      : string -> unit
wenzelm@6568
   151
time_use_thy : string -> unit
wenzelm@7136
   152
update_thy   : string -> unit
wenzelm@6568
   153
\end{ttbox}
wenzelm@6568
   154
wenzelm@6568
   155
\begin{ttdescription}
wenzelm@6568
   156
  
wenzelm@6568
   157
\item[\ttindexbold{context} $thy$;] switches the current theory context.  Any
wenzelm@6568
   158
  subsequent command with ``implicit theory argument'' (e.g.\ \texttt{Goal})
wenzelm@6568
   159
  will refer to $thy$ as its theory.
wenzelm@6568
   160
  
wenzelm@6568
   161
\item[\ttindexbold{the_context}();] obtains the current theory context, or
wenzelm@6568
   162
  raises an error if absent.
wenzelm@6568
   163
  
wenzelm@6569
   164
\item[\ttindexbold{theory} "$name$";] retrieves the theory called $name$ from
paulson@8136
   165
  the internal data\-base of loaded theories, raising an error if absent.
wenzelm@6568
   166
  
wenzelm@6569
   167
\item[\ttindexbold{use_thy} "$name$";] reads theory $name$ from the file
wenzelm@6571
   168
  system, looking for $name$\texttt{.thy} and $name$\texttt{.ML} (the latter
wenzelm@6571
   169
  being optional).  It also ensures that all parent theories are loaded as
wenzelm@6571
   170
  well.  In case some older versions have already been present,
wenzelm@6571
   171
  \texttt{use_thy} only tries to reload $name$ itself, but is content with any
wenzelm@6571
   172
  version of its ancestors.
wenzelm@6568
   173
  
wenzelm@6569
   174
\item[\ttindexbold{time_use_thy} "$name$";] same as \texttt{use_thy}, but
wenzelm@6568
   175
  reports the time taken to process the actual theory parts and {\ML} files
wenzelm@6568
   176
  separately.
wenzelm@7592
   177
  
wenzelm@7136
   178
\item[\ttindexbold{update_thy} "$name$";] is similar to \texttt{use_thy}, but
wenzelm@7136
   179
  ensures that theory $name$ is fully up-to-date with respect to the file
wenzelm@7592
   180
  system --- apart from theory $name$ itself, any of its ancestors may be
wenzelm@7592
   181
  reloaded as well.
wenzelm@6568
   182
  
wenzelm@6568
   183
\end{ttdescription}
wenzelm@6568
   184
wenzelm@9695
   185
Note that theories of pre-built logic images (e.g.\ HOL) are marked as
wenzelm@7282
   186
\emph{finished} and cannot be updated any more.  See \S\ref{sec:more-theories}
wenzelm@7282
   187
for further information on Isabelle's theory loader.
wenzelm@4274
   188
lcp@104
   189
wenzelm@3108
   190
\section{Setting flags}
wenzelm@3108
   191
\begin{ttbox}
wenzelm@3108
   192
set     : bool ref -> bool
wenzelm@3108
   193
reset   : bool ref -> bool
wenzelm@3108
   194
toggle  : bool ref -> bool
wenzelm@3108
   195
\end{ttbox}\index{*set}\index{*reset}\index{*toggle}
paulson@3485
   196
These are some shorthands for manipulating boolean references.  The new
wenzelm@3108
   197
value is returned.
wenzelm@3108
   198
wenzelm@3108
   199
wenzelm@4317
   200
\section{Diagnostic messages}
wenzelm@4317
   201
\index{error messages}
wenzelm@4317
   202
\index{warnings}
wenzelm@4317
   203
wenzelm@6568
   204
Isabelle conceptually provides three output channels for different kinds of
wenzelm@6568
   205
messages: ordinary text, warnings, errors.  Depending on the user interface
wenzelm@6568
   206
involved, these messages may appear in different text styles or colours.
wenzelm@4317
   207
wenzelm@4317
   208
The default setup of an \texttt{isabelle} terminal session is as
wenzelm@4317
   209
follows: plain output of ordinary text, warnings prefixed by
wenzelm@4317
   210
\texttt{\#\#\#}'s, errors prefixed by \texttt{***}'s.  For example, a
wenzelm@4317
   211
typical warning would look like this:
wenzelm@4317
   212
\begin{ttbox}
wenzelm@4317
   213
\#\#\# Beware the Jabberwock, my son!
wenzelm@4317
   214
\#\#\# The jaws that bite, the claws that catch!
wenzelm@4317
   215
\#\#\# Beware the Jubjub Bird, and shun
wenzelm@4317
   216
\#\#\# The frumious Bandersnatch!
wenzelm@4317
   217
\end{ttbox}
wenzelm@4317
   218
wenzelm@4317
   219
\texttt{ML} programs may output diagnostic messages using the
wenzelm@4317
   220
following functions:
wenzelm@4317
   221
\begin{ttbox}
wenzelm@4317
   222
writeln : string -> unit
wenzelm@4317
   223
warning : string -> unit
wenzelm@4317
   224
error   : string -> 'a
wenzelm@4317
   225
\end{ttbox}
wenzelm@4317
   226
Note that \ttindex{error} fails by raising exception \ttindex{ERROR}
wenzelm@4317
   227
after having output the text, while \ttindex{writeln} and
wenzelm@4317
   228
\ttindex{warning} resume normal program execution.
wenzelm@4317
   229
lcp@104
   230
wenzelm@30184
   231
\section{Timing}
wenzelm@30184
   232
\index{timing statistics}\index{proofs!timing}
lcp@104
   233
\begin{ttbox} 
wenzelm@30184
   234
timing: bool ref \hfill{\bf initially false}
lcp@104
   235
\end{ttbox}
lcp@104
   236
lcp@322
   237
\begin{ttdescription}
wenzelm@30184
   238
\item[set \ttindexbold{timing};] enables global timing in Isabelle.
wenzelm@30184
   239
  This information is compiler-dependent.
lcp@322
   240
\end{ttdescription}
lcp@104
   241
lcp@104
   242
\index{sessions|)}
wenzelm@5371
   243
wenzelm@5371
   244
wenzelm@5371
   245
%%% Local Variables: 
wenzelm@5371
   246
%%% mode: latex
wenzelm@5371
   247
%%% TeX-master: "ref"
wenzelm@5371
   248
%%% End: