doc-src/Tutorial/basics.tex
author paulson
Mon, 08 May 2000 16:59:02 +0200
changeset 8835 56187238220d
parent 6691 8a1b5f9d8420
child 9255 2ceb11a2e190
permissions -rw-r--r--
tidied
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5375
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
     1
\chapter{Basic Concepts}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
     2
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
     3
\section{Introduction}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
     4
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
     5
This is a tutorial on how to use Isabelle/HOL as a specification and
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
     6
verification system. Isabelle is a generic system for implementing logical
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
     7
formalisms, and Isabelle/HOL is the specialization of Isabelle for
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
     8
HOL, which abbreviates Higher-Order Logic. We introduce HOL step by step
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
     9
following the equation
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    10
\[ \mbox{HOL} = \mbox{Functional Programming} + \mbox{Logic}. \]
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    11
We assume that the reader is familiar with the basic concepts of both fields.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    12
For excellent introductions to functional programming consult the textbooks
6606
nipkow
parents: 6584
diff changeset
    13
by Bird and Wadler~\cite{Bird-Wadler} or Paulson~\cite{paulson-ml2}.  Although
5375
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    14
this tutorial initially concentrates on functional programming, do not be
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    15
misled: HOL can express most mathematical concepts, and functional
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    16
programming is just one particularly simple and ubiquitous instance.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    17
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    18
A tutorial is by definition incomplete. To fully exploit the power of the
6606
nipkow
parents: 6584
diff changeset
    19
system you need to consult the Isabelle Reference Manual~\cite{isabelle-ref}
nipkow
parents: 6584
diff changeset
    20
for details about Isabelle and the Isabelle/HOL manual~\cite{isabelle-HOL}
nipkow
parents: 6584
diff changeset
    21
for details relating to HOL. Both manuals have a comprehensive index.
5375
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    22
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    23
\section{Theories, proofs and interaction}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    24
\label{sec:Basic:Theories}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    25
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    26
Working with Isabelle means creating two different kinds of documents:
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    27
theories and proof scripts. Roughly speaking, a \bfindex{theory} is a named
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    28
collection of types and functions, much like a module in a programming
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    29
language or a specification in a specification language. In fact, theories in
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    30
HOL can be either. Theories must reside in files with the suffix
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    31
\texttt{.thy}. The general format of a theory file \texttt{T.thy} is
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    32
\begin{ttbox}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    33
T = B\(@1\) + \(\cdots\) + B\(@n\) +
6584
wenzelm
parents: 6148
diff changeset
    34
\({\langle}declarations{\rangle}\)
5375
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    35
end
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    36
\end{ttbox}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    37
where \texttt{B}$@1$, \dots, \texttt{B}$@n$ are the names of existing
6584
wenzelm
parents: 6148
diff changeset
    38
theories that \texttt{T} is based on and ${\langle}declarations{\rangle}$ stands for the
5375
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    39
newly introduced concepts (types, functions etc). The \texttt{B}$@i$ are the
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    40
direct \textbf{parent theories}\indexbold{parent theory} of \texttt{T}.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    41
Everything defined in the parent theories (and their parents \dots) is
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    42
automatically visible. To avoid name clashes, identifiers can be qualified by
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    43
theory names as in \texttt{T.f} and \texttt{B.f}. HOL's theory library is
6148
d97a944c6ea3 isabelle.in.tum.de;
wenzelm
parents: 5375
diff changeset
    44
available online at
6628
12ed4f748f7c pdf setup;
wenzelm
parents: 6606
diff changeset
    45
12ed4f748f7c pdf setup;
wenzelm
parents: 6606
diff changeset
    46
\begin{center}\small
12ed4f748f7c pdf setup;
wenzelm
parents: 6606
diff changeset
    47
  \begin{tabular}{l}
12ed4f748f7c pdf setup;
wenzelm
parents: 6606
diff changeset
    48
    \url{http://www.cl.cam.ac.uk/Research/HVG/Isabelle/library/} \\
12ed4f748f7c pdf setup;
wenzelm
parents: 6606
diff changeset
    49
    \url{http://isabelle.in.tum.de/library/} \\
12ed4f748f7c pdf setup;
wenzelm
parents: 6606
diff changeset
    50
  \end{tabular}
12ed4f748f7c pdf setup;
wenzelm
parents: 6606
diff changeset
    51
\end{center}
12ed4f748f7c pdf setup;
wenzelm
parents: 6606
diff changeset
    52
6148
d97a944c6ea3 isabelle.in.tum.de;
wenzelm
parents: 5375
diff changeset
    53
and is recommended browsing.
5375
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    54
\begin{warn}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    55
  HOL contains a theory \ttindexbold{Main}, the union of all the basic
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    56
  predefined theories like arithmetic, lists, sets, etc.\ (see the online
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    57
  library).  Unless you know what you are doing, always include \texttt{Main}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    58
  as a direct or indirect parent theory of all your theories.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    59
\end{warn}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    60
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    61
This tutorial is concerned with introducing you to the different linguistic
6584
wenzelm
parents: 6148
diff changeset
    62
constructs that can fill ${\langle}declarations{\rangle}$ in the above theory template.
5375
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    63
A complete grammar of the basic constructs is found in Appendix~A
6606
nipkow
parents: 6584
diff changeset
    64
of~\cite{isabelle-ref}, for reference in times of doubt.
5375
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    65
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    66
The tutorial is also concerned with showing you how to prove theorems about
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    67
the concepts in a theory. This involves invoking predefined theorem proving
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    68
commands. Because Isabelle is written in the programming language
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    69
ML,\footnote{Many concepts in HOL and ML are similar. Make sure you do not
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    70
  confuse the two levels.} interacting with Isabelle means calling ML
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    71
functions. Hence \bfindex{proof scripts} are sequences of calls to ML
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    72
functions that perform specific theorem proving tasks. Nevertheless,
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    73
familiarity with ML is absolutely not required.  All proof scripts for theory
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    74
\texttt{T} (defined in file \texttt{T.thy}) should be contained in file
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    75
\texttt{T.ML}. Theory and proof scripts are loaded (and checked!) by calling
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    76
the ML function \ttindexbold{use_thy}:
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    77
\begin{ttbox}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    78
use_thy "T";
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    79
\end{ttbox}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    80
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    81
There are more advanced interfaces for Isabelle that hide the ML level from
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    82
you and replace function calls by menu selection. There is even a special
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    83
font with mathematical symbols. For details see the Isabelle home page.  This
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    84
tutorial concentrates on the bare essentials and ignores such niceties.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    85
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    86
\section{Types, terms and formulae}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    87
\label{sec:TypesTermsForms}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    88
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    89
Embedded in the declarations of a theory are the types, terms and formulae of
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    90
HOL. HOL is a typed logic whose type system resembles that of functional
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    91
programming languages like ML or Haskell. Thus there are
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    92
\begin{description}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    93
\item[base types,] in particular \ttindex{bool}, the type of truth values,
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    94
and \ttindex{nat}, the type of natural numbers.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    95
\item[type constructors,] in particular \ttindex{list}, the type of
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    96
lists, and \ttindex{set}, the type of sets. Type constructors are written
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    97
postfix, e.g.\ \texttt{(nat)list} is the type of lists whose elements are
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    98
natural numbers. Parentheses around single arguments can be dropped (as in
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
    99
\texttt{nat list}), multiple arguments are separated by commas (as in
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   100
\texttt{(bool,nat)foo}).
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   101
\item[function types,] denoted by \ttindexbold{=>}. In HOL
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   102
\texttt{=>} represents {\em total} functions only. As is customary,
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   103
\texttt{$\tau@1$ => $\tau@2$ => $\tau@3$} means
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   104
\texttt{$\tau@1$ => ($\tau@2$ => $\tau@3$)}. Isabelle also supports the
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   105
notation \texttt{[$\tau@1,\dots,\tau@n$] => $\tau$} which abbreviates
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   106
\texttt{$\tau@1$ => $\cdots$ => $\tau@n$ => $\tau$}.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   107
\item[type variables,] denoted by \texttt{'a}, \texttt{'b} etc, just like in
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   108
ML. They give rise to polymorphic types like \texttt{'a => 'a}, the type of the
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   109
identity function.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   110
\end{description}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   111
\begin{warn}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   112
  Types are extremely important because they prevent us from writing
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   113
  nonsense.  Isabelle insists that all terms and formulae must be well-typed
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   114
  and will print an error message if a type mismatch is encountered. To
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   115
  reduce the amount of explicit type information that needs to be provided by
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   116
  the user, Isabelle infers the type of all variables automatically (this is
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   117
  called \bfindex{type inference}) and keeps quiet about it. Occasionally
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   118
  this may lead to misunderstandings between you and the system. If anything
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   119
  strange happens, we recommend to set the flag \ttindexbold{show_types} that
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   120
  tells Isabelle to display type information that is usually suppressed:
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   121
  simply type
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   122
\begin{ttbox}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   123
set show_types;
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   124
\end{ttbox}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   125
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   126
\noindent
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   127
at the ML-level. This can be reversed by \texttt{reset show_types;}.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   128
\end{warn}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   129
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   130
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   131
\textbf{Terms}\indexbold{term}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   132
are formed as in functional programming by applying functions to
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   133
arguments. If \texttt{f} is a function of type \texttt{$\tau@1$ => $\tau@2$}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   134
and \texttt{t} is a term of type $\tau@1$ then \texttt{f~t} is a term of type
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   135
$\tau@2$. HOL also supports infix functions like \texttt{+} and some basic
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   136
constructs from functional programming:
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   137
\begin{description}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   138
\item[\texttt{if $b$ then $t@1$ else $t@2$}]\indexbold{*if}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   139
means what you think it means and requires that
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   140
$b$ is of type \texttt{bool} and $t@1$ and $t@2$ are of the same type.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   141
\item[\texttt{let $x$ = $t$ in $u$}]\indexbold{*let}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   142
is equivalent to $u$ where all occurrences of $x$ have been replaced by
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   143
$t$. For example,
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   144
\texttt{let x = 0 in x+x} means \texttt{0+0}. Multiple bindings are separated
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   145
by semicolons: \texttt{let $x@1$ = $t@1$; \dots; $x@n$ = $t@n$ in $u$}.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   146
\item[\texttt{case $e$ of $c@1$ => $e@1$ | \dots | $c@n$ => $e@n$}]
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   147
\indexbold{*case}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   148
evaluates to $e@i$ if $e$ is of the form
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   149
$c@i$. See~\S\ref{sec:case-expressions} for details.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   150
\end{description}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   151
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   152
Terms may also contain $\lambda$-abstractions. For example, $\lambda
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   153
x. x+1$ is the function that takes an argument $x$ and returns $x+1$. In
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   154
Isabelle we write \texttt{\%x.~x+1}.\index{==>@{\tt\%}|bold}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   155
Instead of \texttt{\%x.~\%y.~\%z.~t} we can write \texttt{\%x~y~z.~t}.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   156
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   157
\textbf{Formulae}\indexbold{formula}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   158
are terms of type \texttt{bool}. There are the basic
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   159
constants \ttindexbold{True} and \ttindexbold{False} and the usual logical
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   160
connectives (in decreasing order of priority):
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   161
\verb$~$\index{$HOL1@{\ttnot}|bold} (`not'),
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   162
\texttt{\&}\index{$HOL2@{\tt\&}|bold} (`and'),
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   163
\texttt{|}\index{$HOL2@{\ttor}|bold} (`or') and
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   164
\texttt{-->}\index{$HOL2@{\tt-->}|bold} (`implies'),
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   165
all of which (except the unary \verb$~$) associate to the right. In
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   166
particular \texttt{A --> B --> C} means \texttt{A --> (B --> C)} and is thus
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   167
logically equivalent with \texttt{A \& B --> C}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   168
(which is \texttt{(A \& B) --> C}).
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   169
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   170
Equality is available in the form of the infix function
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   171
\texttt{=} of type \texttt{'a => 'a => bool}. Thus \texttt{$t@1$ = $t@2$} is
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   172
a formula provided $t@1$ and $t@2$ are terms of the same type. In case $t@1$
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   173
and $t@2$ are of type \texttt{bool}, \texttt{=} acts as if-and-only-if.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   174
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   175
The syntax for quantifiers is
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   176
\texttt{!~$x$.$\,P$}\index{$HOLQ@{\ttall}|bold} (`for all $x$') and
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   177
\texttt{?~$x$.$\,P$}\index{$HOLQ@{\tt?}|bold} (`exists $x$').
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   178
There is even \texttt{?!~$x$.$\,P$}\index{$HOLQ@{\ttuniquex}|bold}, which
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   179
means that there exists exactly one $x$ that satisfies $P$. Instead of
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   180
\texttt{!} and \texttt{?} you may also write \texttt{ALL} and \texttt{EX}.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   181
Nested quantifications can be abbreviated:
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   182
\texttt{!$x~y~z$.$\,P$} means \texttt{!$x$.~!$y$.~!$z$.$\,P$}.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   183
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   184
Despite type inference, it is sometimes necessary to attach explicit
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   185
\bfindex{type constraints} to a term.  The syntax is \texttt{$t$::$\tau$} as
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   186
in \texttt{x < (y::nat)}. Note that \texttt{::} binds weakly and should
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   187
therefore be enclosed in parentheses: \texttt{x < y::nat} is ill-typed
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   188
because it is interpreted as \texttt{(x < y)::nat}. The main reason for type
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   189
constraints are overloaded functions like \texttt{+}, \texttt{*} and
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   190
\texttt{<}. (See \S\ref{sec:TypeClasses} for a full discussion of
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   191
overloading.)
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   192
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   193
\begin{warn}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   194
In general, HOL's concrete syntax tries to follow the conventions of
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   195
functional programming and mathematics. Below we list the main rules that you
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   196
should be familiar with to avoid certain syntactic traps. A particular
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   197
problem for novices can be the priority of operators. If you are unsure, use
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   198
more rather than fewer parentheses. In those cases where Isabelle echoes your
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   199
input, you can see which parentheses are dropped---they were superfluous. If
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   200
you are unsure how to interpret Isabelle's output because you don't know
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   201
where the (dropped) parentheses go, set (and possibly reset) the flag
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   202
\ttindexbold{show_brackets}:
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   203
\begin{ttbox}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   204
set show_brackets; \(\dots\); reset show_brackets;
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   205
\end{ttbox}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   206
\end{warn}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   207
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   208
\begin{itemize}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   209
\item
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   210
Remember that \texttt{f t u} means \texttt{(f t) u} and not \texttt{f(t u)}!
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   211
\item
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   212
Isabelle allows infix functions like \texttt{+}. The prefix form of function
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   213
application binds more strongly than anything else and hence \texttt{f~x + y}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   214
means \texttt{(f~x)~+~y} and not \texttt{f(x+y)}.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   215
\item
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   216
Remember that in HOL if-and-only-if is expressed using equality.  But equality
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   217
has a high priority, as befitting a  relation, while if-and-only-if typically
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   218
has the lowest priority.  Thus, \verb$~ ~ P = P$ means \verb$~ ~(P = P)$ and
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   219
not \verb$(~ ~P) = P$. When using \texttt{=} to mean logical equivalence,
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   220
enclose both operands in parentheses, as in \texttt{(A \& B) = (B \& A)}.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   221
\item
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   222
Constructs with an opening but without a closing delimiter bind very weakly
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   223
and should therefore be enclosed in parentheses if they appear in subterms, as
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   224
in \texttt{f = (\%x.~x)}. This includes
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   225
\ttindex{if}, \ttindex{let}, \ttindex{case}, \verb$%$ and quantifiers.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   226
\item
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   227
Never write \texttt{\%x.x} or \texttt{!x.x=x} because \texttt{x.x} is always
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   228
read as a single qualified identifier that refers to an item \texttt{x} in
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   229
theory \texttt{x}. Write \texttt{\%x.~x} and \texttt{!x.~x=x} instead.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   230
\end{itemize}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   231
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   232
\section{Variables}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   233
\label{sec:variables}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   234
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   235
Isabelle distinguishes free and bound variables just as is customary. Bound
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   236
variables are automatically renamed to avoid clashes with free variables. In
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   237
addition, Isabelle has a third kind of variable, called a \bfindex{schematic
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   238
  variable} or \bfindex{unknown}, which starts with a \texttt{?}.  Logically,
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   239
an unknown is a free variable. But it may be instantiated by another term
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   240
during the proof process. For example, the mathematical theorem $x = x$ is
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   241
represented in Isabelle as \texttt{?x = ?x}, which means that Isabelle can
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   242
instantiate it arbitrarily. This is in contrast to ordinary variables, which
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   243
remain fixed. The programming language Prolog calls unknowns {\em logical\/}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   244
variables.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   245
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   246
Most of the time you can and should ignore unknowns and work with ordinary
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   247
variables. Just don't be surprised that after you have finished the
6691
8a1b5f9d8420 qed indexed.
nipkow
parents: 6628
diff changeset
   248
proof of a theorem, Isabelle (i.e.\ \ttindex{qed} at the end of a proof) will
8a1b5f9d8420 qed indexed.
nipkow
parents: 6628
diff changeset
   249
turn your free variables into unknowns: it merely indicates that Isabelle will
8a1b5f9d8420 qed indexed.
nipkow
parents: 6628
diff changeset
   250
automatically instantiate those unknowns suitably when the theorem is used in
8a1b5f9d8420 qed indexed.
nipkow
parents: 6628
diff changeset
   251
some other proof.
5375
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   252
\begin{warn}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   253
  The existential quantifier \texttt{?}\index{$HOLQ@{\tt?}} needs to be
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   254
  followed by a space. Otherwise \texttt{?x} is interpreted as a schematic
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   255
  variable.
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   256
\end{warn}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   257
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   258
\section{Getting started}
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   259
1463e182c533 The HOL tutorial.
nipkow
parents:
diff changeset
   260
Assuming you have installed Isabelle, you start it by typing \texttt{isabelle
6584
wenzelm
parents: 6148
diff changeset
   261
  HOL} in a shell window.\footnote{Simply executing \texttt{isabelle} without
wenzelm
parents: 6148
diff changeset
   262
  an argument starts the default logic, which usually is already \texttt{HOL}.
wenzelm
parents: 6148
diff changeset
   263
  This is controlled by the \texttt{ISABELLE_LOGIC} setting, see \emph{The
wenzelm
parents: 6148
diff changeset
   264
    Isabelle System Manual} for more details.} This presents you with
wenzelm
parents: 6148
diff changeset
   265
Isabelle's most basic ASCII interface.  In addition you need to open an editor
wenzelm
parents: 6148
diff changeset
   266
window to create theories (\texttt{.thy} files) and proof scripts
wenzelm
parents: 6148
diff changeset
   267
(\texttt{.ML} files). While you are developing a proof, we recommend to type
wenzelm
parents: 6148
diff changeset
   268
each proof command into the ML-file first and then enter it into Isabelle by
wenzelm
parents: 6148
diff changeset
   269
copy-and-paste, thus ensuring that you have a complete record of your proof.
wenzelm
parents: 6148
diff changeset
   270