doc-src/TutorialI/basics.tex
author paulson
Fri, 13 Jul 2001 18:08:26 +0200
changeset 11420 9529d31f39e0
parent 11405 b6e3ac38397d
child 11428 332347b9b942
permissions -rw-r--r--
added\\protect
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
     1
\chapter{Basic Concepts}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
     2
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
     3
\section{Introduction}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
     4
11405
paulson
parents: 11301
diff changeset
     5
This book is a tutorial on how to use the theorem prover Isabelle/HOL as a
paulson
parents: 11301
diff changeset
     6
specification and verification system. Isabelle is a generic system for
paulson
parents: 11301
diff changeset
     7
implementing logical formalisms, and Isabelle/HOL is the specialization
paulson
parents: 11301
diff changeset
     8
of Isabelle for HOL, which abbreviates Higher-Order Logic. We introduce
paulson
parents: 11301
diff changeset
     9
HOL step by step following the equation
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    10
\[ \mbox{HOL} = \mbox{Functional Programming} + \mbox{Logic}. \]
10983
59961d32b1ae *** empty log message ***
nipkow
parents: 10978
diff changeset
    11
We do not assume that the reader is familiar with mathematical logic but that
11209
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    12
(s)he is used to logical and set theoretic notation, such as covered
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    13
in a good discrete math course~\cite{Rosen-DMA}. In contrast, we do assume
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    14
that the reader is familiar with the basic concepts of functional
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    15
programming~\cite{Bird-Haskell,Hudak-Haskell,paulson-ml2,Thompson-Haskell}.
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    16
Although this tutorial initially concentrates on functional programming, do
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    17
not be misled: HOL can express most mathematical concepts, and functional
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    18
programming is just one particularly simple and ubiquitous instance.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    19
11205
67cec35dbc58 *** empty log message ***
nipkow
parents: 10983
diff changeset
    20
Isabelle~\cite{paulson-isa-book} is implemented in ML~\cite{SML}.  This has
67cec35dbc58 *** empty log message ***
nipkow
parents: 10983
diff changeset
    21
influenced some of Isabelle/HOL's concrete syntax but is otherwise irrelevant
67cec35dbc58 *** empty log message ***
nipkow
parents: 10983
diff changeset
    22
for us because this tutorial is based on
11213
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    23
Isabelle/Isar~\cite{isabelle-isar-ref}, an extension of Isabelle which hides
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    24
the implementation language almost completely.  Thus the full name of the
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    25
system should be Isabelle/Isar/HOL, but that is a bit of a mouthful.
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    26
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    27
There are other implementations of HOL, in particular the one by Mike Gordon
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    28
\emph{et al.}, which is usually referred to as ``the HOL system''
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    29
\cite{mgordon-hol}. For us, HOL refers to the logical system, and sometimes
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    30
its incarnation Isabelle/HOL.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    31
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    32
A tutorial is by definition incomplete.  Currently the tutorial only
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    33
introduces the rudiments of Isar's proof language. To fully exploit the power
11213
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    34
of Isar, in particular the ability to write readable and structured proofs,
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    35
you need to consult the Isabelle/Isar Reference
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    36
Manual~\cite{isabelle-isar-ref}. If you want to use Isabelle's ML level
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    37
directly (for example for writing your own proof procedures) see the Isabelle
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    38
Reference Manual~\cite{isabelle-ref}; for details relating to HOL see the
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    39
Isabelle/HOL manual~\cite{isabelle-HOL}. All manuals have a comprehensive
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    40
index.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    41
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    42
\section{Theories}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    43
\label{sec:Basic:Theories}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    44
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    45
Working with Isabelle means creating theories. Roughly speaking, a
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    46
\bfindex{theory} is a named collection of types, functions, and theorems,
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    47
much like a module in a programming language or a specification in a
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    48
specification language. In fact, theories in HOL can be either. The general
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    49
format of a theory \texttt{T} is
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    50
\begin{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    51
theory T = B\(@1\) + \(\cdots\) + B\(@n\):
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    52
\(\textit{declarations, definitions, and proofs}\)
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    53
end
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    54
\end{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    55
where \texttt{B}$@1$, \dots, \texttt{B}$@n$ are the names of existing
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    56
theories that \texttt{T} is based on and \texttt{\textit{declarations,
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    57
    definitions, and proofs}} represents the newly introduced concepts
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    58
(types, functions etc.) and proofs about them. The \texttt{B}$@i$ are the
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    59
direct \textbf{parent theories}\indexbold{parent theory} of \texttt{T}.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    60
Everything defined in the parent theories (and their parents \dots) is
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    61
automatically visible. To avoid name clashes, identifiers can be
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    62
\textbf{qualified} by theory names as in \texttt{T.f} and
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    63
\texttt{B.f}.\indexbold{identifier!qualified} Each theory \texttt{T} must
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    64
reside in a \bfindex{theory file} named \texttt{T.thy}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    65
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    66
This tutorial is concerned with introducing you to the different linguistic
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    67
constructs that can fill \textit{\texttt{declarations, definitions, and
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    68
    proofs}} in the above theory template.  A complete grammar of the basic
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    69
constructs is found in the Isabelle/Isar Reference Manual.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    70
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
    71
HOL's theory collection is available online at
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    72
\begin{center}\small
10978
5eebea8f359f *** empty log message ***
nipkow
parents: 10971
diff changeset
    73
    \url{http://isabelle.in.tum.de/library/HOL/}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    74
\end{center}
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
    75
and is recommended browsing. Note that most of the theories 
9541
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 8771
diff changeset
    76
are based on classical Isabelle without the Isar extension. This means that
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 8771
diff changeset
    77
they look slightly different than the theories in this tutorial, and that all
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 8771
diff changeset
    78
proofs are in separate ML files.
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 8771
diff changeset
    79
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    80
\begin{warn}
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9689
diff changeset
    81
  HOL contains a theory \isaindexbold{Main}, the union of all the basic
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
    82
  predefined theories like arithmetic, lists, sets, etc.  
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
    83
  Unless you know what you are doing, always include \isa{Main}
10971
6852682eaf16 *** empty log message ***
nipkow
parents: 10885
diff changeset
    84
  as a direct or indirect parent of all your theories.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    85
\end{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    86
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    87
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
    88
\section{Types, Terms and Formulae}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    89
\label{sec:TypesTermsForms}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    90
\indexbold{type}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    91
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10695
diff changeset
    92
Embedded in a theory are the types, terms and formulae of HOL\@. HOL is a typed
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    93
logic whose type system resembles that of functional programming languages
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    94
like ML or Haskell. Thus there are
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    95
\begin{description}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    96
\item[base types,] in particular \isaindex{bool}, the type of truth values,
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    97
and \isaindex{nat}, the type of natural numbers.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    98
\item[type constructors,] in particular \isaindex{list}, the type of
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    99
lists, and \isaindex{set}, the type of sets. Type constructors are written
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   100
postfix, e.g.\ \isa{(nat)list} is the type of lists whose elements are
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   101
natural numbers. Parentheses around single arguments can be dropped (as in
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   102
\isa{nat list}), multiple arguments are separated by commas (as in
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   103
\isa{(bool,nat)ty}).
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   104
\item[function types,] denoted by \isasymFun\indexbold{$IsaFun@\isasymFun}.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   105
  In HOL \isasymFun\ represents \emph{total} functions only. As is customary,
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   106
  \isa{$\tau@1$ \isasymFun~$\tau@2$ \isasymFun~$\tau@3$} means
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   107
  \isa{$\tau@1$ \isasymFun~($\tau@2$ \isasymFun~$\tau@3$)}. Isabelle also
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   108
  supports the notation \isa{[$\tau@1,\dots,\tau@n$] \isasymFun~$\tau$}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   109
  which abbreviates \isa{$\tau@1$ \isasymFun~$\cdots$ \isasymFun~$\tau@n$
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   110
    \isasymFun~$\tau$}.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   111
\item[type variables,]\indexbold{type variable}\indexbold{variable!type}
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10695
diff changeset
   112
  denoted by \ttindexboldpos{'a}{$Isatype}, \isa{'b} etc., just like in ML\@. They give rise
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   113
  to polymorphic types like \isa{'a \isasymFun~'a}, the type of the identity
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   114
  function.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   115
\end{description}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   116
\begin{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   117
  Types are extremely important because they prevent us from writing
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   118
  nonsense.  Isabelle insists that all terms and formulae must be well-typed
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   119
  and will print an error message if a type mismatch is encountered. To
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   120
  reduce the amount of explicit type information that needs to be provided by
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   121
  the user, Isabelle infers the type of all variables automatically (this is
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   122
  called \bfindex{type inference}) and keeps quiet about it. Occasionally
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   123
  this may lead to misunderstandings between you and the system. If anything
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   124
  strange happens, we recommend to set the \rmindex{flag}
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9689
diff changeset
   125
  \isaindexbold{show_types} that tells Isabelle to display type information
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   126
  that is usually suppressed: simply type
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   127
\begin{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   128
ML "set show_types"
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   129
\end{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   130
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   131
\noindent
10971
6852682eaf16 *** empty log message ***
nipkow
parents: 10885
diff changeset
   132
This can be reversed by \texttt{ML "reset show_types"}. Various other flags,
6852682eaf16 *** empty log message ***
nipkow
parents: 10885
diff changeset
   133
which we introduce as we go along,
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   134
can be set and reset in the same manner.\indexbold{flag!(re)setting}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   135
\end{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   136
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   137
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   138
\textbf{Terms}\indexbold{term} are formed as in functional programming by
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   139
applying functions to arguments. If \isa{f} is a function of type
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   140
\isa{$\tau@1$ \isasymFun~$\tau@2$} and \isa{t} is a term of type
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   141
$\tau@1$ then \isa{f~t} is a term of type $\tau@2$. HOL also supports
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   142
infix functions like \isa{+} and some basic constructs from functional
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   143
programming:
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   144
\begin{description}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   145
\item[\isa{if $b$ then $t@1$ else $t@2$}]\indexbold{*if}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   146
means what you think it means and requires that
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   147
$b$ is of type \isa{bool} and $t@1$ and $t@2$ are of the same type.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   148
\item[\isa{let $x$ = $t$ in $u$}]\indexbold{*let}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   149
is equivalent to $u$ where all occurrences of $x$ have been replaced by
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   150
$t$. For example,
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   151
\isa{let x = 0 in x+x} is equivalent to \isa{0+0}. Multiple bindings are separated
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   152
by semicolons: \isa{let $x@1$ = $t@1$; \dots; $x@n$ = $t@n$ in $u$}.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   153
\item[\isa{case $e$ of $c@1$ \isasymFun~$e@1$ |~\dots~| $c@n$ \isasymFun~$e@n$}]
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   154
\indexbold{*case}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   155
evaluates to $e@i$ if $e$ is of the form $c@i$.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   156
\end{description}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   157
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   158
Terms may also contain
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   159
\isasymlambda-abstractions\indexbold{$Isalam@\isasymlambda}. For example,
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   160
\isa{\isasymlambda{}x.~x+1} is the function that takes an argument \isa{x} and
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   161
returns \isa{x+1}. Instead of
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   162
\isa{\isasymlambda{}x.\isasymlambda{}y.\isasymlambda{}z.~$t$} we can write
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   163
\isa{\isasymlambda{}x~y~z.~$t$}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   164
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   165
\textbf{Formulae}\indexbold{formula} are terms of type \isaindexbold{bool}.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   166
There are the basic constants \isaindexbold{True} and \isaindexbold{False} and
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   167
the usual logical connectives (in decreasing order of priority):
11420
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   168
\indexboldpos{\protect\isasymnot}{$HOL0not}, \indexboldpos{\protect\isasymand}{$HOL0and},
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   169
\indexboldpos{\protect\isasymor}{$HOL0or}, and \indexboldpos{\protect\isasymimp}{$HOL0imp},
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   170
all of which (except the unary \isasymnot) associate to the right. In
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   171
particular \isa{A \isasymimp~B \isasymimp~C} means \isa{A \isasymimp~(B
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   172
  \isasymimp~C)} and is thus logically equivalent to \isa{A \isasymand~B
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   173
  \isasymimp~C} (which is \isa{(A \isasymand~B) \isasymimp~C}).
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   174
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   175
Equality is available in the form of the infix function
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   176
\isa{=}\indexbold{$HOL0eq@\texttt{=}} of type \isa{'a \isasymFun~'a
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   177
  \isasymFun~bool}. Thus \isa{$t@1$ = $t@2$} is a formula provided $t@1$
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   178
and $t@2$ are terms of the same type. In case $t@1$ and $t@2$ are of type
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   179
\isa{bool}, \isa{=} acts as if-and-only-if. The formula
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   180
\isa{$t@1$~\isasymnoteq~$t@2$} is merely an abbreviation for
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   181
\isa{\isasymnot($t@1$ = $t@2$)}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   182
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10695
diff changeset
   183
Quantifiers are written as
11420
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   184
\isa{\isasymforall{}x.~$P$}\index{$HOL0All@\isasymforall|bold} and
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   185
\isa{\isasymexists{}x.~$P$}\index{$HOL0Ex@\isasymexists|bold}. 
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   186
There is even
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   187
\isa{\isasymuniqex{}x.~$P$}\index{$HOL0ExU@\isasymuniqex|bold}, which
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   188
means that there exists exactly one \isa{x} that satisfies \isa{$P$}. 
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   189
Nested quantifications can be abbreviated:
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   190
\isa{\isasymforall{}x~y~z.~$P$} means
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   191
\isa{\isasymforall{}x.\isasymforall{}y.\isasymforall{}z.~$P$}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   192
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   193
Despite type inference, it is sometimes necessary to attach explicit
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   194
\textbf{type constraints}\indexbold{type constraint} to a term.  The syntax is
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   195
\isa{$t$::$\tau$} as in \isa{x < (y::nat)}. Note that
10538
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10396
diff changeset
   196
\ttindexboldpos{::}{$Isatype} binds weakly and should therefore be enclosed
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   197
in parentheses: \isa{x < y::nat} is ill-typed because it is interpreted as
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10695
diff changeset
   198
\isa{(x < y)::nat}. The main reason for type constraints is overloading of
10538
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10396
diff changeset
   199
functions like \isa{+}, \isa{*} and \isa{<}. See {\S}\ref{sec:overloading} for
10695
ffb153ef6366 *** empty log message ***
nipkow
parents: 10538
diff changeset
   200
a full discussion of overloading and Table~\ref{tab:overloading} for the most
ffb153ef6366 *** empty log message ***
nipkow
parents: 10538
diff changeset
   201
important overloaded function symbols.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   202
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   203
\begin{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   204
In general, HOL's concrete syntax tries to follow the conventions of
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   205
functional programming and mathematics. Below we list the main rules that you
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   206
should be familiar with to avoid certain syntactic traps. A particular
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   207
problem for novices can be the priority of operators. If you are unsure, use
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10695
diff changeset
   208
additional parentheses. In those cases where Isabelle echoes your
10971
6852682eaf16 *** empty log message ***
nipkow
parents: 10885
diff changeset
   209
input, you can see which parentheses are dropped --- they were superfluous. If
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   210
you are unsure how to interpret Isabelle's output because you don't know
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10695
diff changeset
   211
where the (dropped) parentheses go, set the \rmindex{flag}
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9689
diff changeset
   212
\isaindexbold{show_brackets}:
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   213
\begin{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   214
ML "set show_brackets"; \(\dots\); ML "reset show_brackets";
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   215
\end{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   216
\end{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   217
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   218
\begin{itemize}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   219
\item
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   220
Remember that \isa{f t u} means \isa{(f t) u} and not \isa{f(t u)}!
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   221
\item
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   222
Isabelle allows infix functions like \isa{+}. The prefix form of function
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   223
application binds more strongly than anything else and hence \isa{f~x + y}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   224
means \isa{(f~x)~+~y} and not \isa{f(x+y)}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   225
\item Remember that in HOL if-and-only-if is expressed using equality.  But
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   226
  equality has a high priority, as befitting a relation, while if-and-only-if
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   227
  typically has the lowest priority.  Thus, \isa{\isasymnot~\isasymnot~P =
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   228
    P} means \isa{\isasymnot\isasymnot(P = P)} and not
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   229
  \isa{(\isasymnot\isasymnot P) = P}. When using \isa{=} to mean
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   230
  logical equivalence, enclose both operands in parentheses, as in \isa{(A
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   231
    \isasymand~B) = (B \isasymand~A)}.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   232
\item
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   233
Constructs with an opening but without a closing delimiter bind very weakly
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   234
and should therefore be enclosed in parentheses if they appear in subterms, as
10971
6852682eaf16 *** empty log message ***
nipkow
parents: 10885
diff changeset
   235
in \isa{(\isasymlambda{}x.~x) = f}. This includes \isaindex{if},
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   236
\isaindex{let}, \isaindex{case}, \isa{\isasymlambda}, and quantifiers.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   237
\item
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   238
Never write \isa{\isasymlambda{}x.x} or \isa{\isasymforall{}x.x=x}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   239
because \isa{x.x} is always read as a single qualified identifier that
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   240
refers to an item \isa{x} in theory \isa{x}. Write
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   241
\isa{\isasymlambda{}x.~x} and \isa{\isasymforall{}x.~x=x} instead.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   242
\item Identifiers\indexbold{identifier} may contain \isa{_} and \isa{'}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   243
\end{itemize}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   244
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   245
For the sake of readability the usual mathematical symbols are used throughout
10983
59961d32b1ae *** empty log message ***
nipkow
parents: 10978
diff changeset
   246
the tutorial. Their \textsc{ascii}-equivalents are shown in table~\ref{tab:ascii} in
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   247
the appendix.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   248
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   249
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   250
\section{Variables}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   251
\label{sec:variables}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   252
\indexbold{variable}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   253
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   254
Isabelle distinguishes free and bound variables just as is customary. Bound
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   255
variables are automatically renamed to avoid clashes with free variables. In
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   256
addition, Isabelle has a third kind of variable, called a \bfindex{schematic
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   257
  variable}\indexbold{variable!schematic} or \bfindex{unknown}, which starts
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   258
with a \isa{?}.  Logically, an unknown is a free variable. But it may be
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   259
instantiated by another term during the proof process. For example, the
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   260
mathematical theorem $x = x$ is represented in Isabelle as \isa{?x = ?x},
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   261
which means that Isabelle can instantiate it arbitrarily. This is in contrast
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   262
to ordinary variables, which remain fixed. The programming language Prolog
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   263
calls unknowns {\em logical\/} variables.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   264
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   265
Most of the time you can and should ignore unknowns and work with ordinary
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   266
variables. Just don't be surprised that after you have finished the proof of
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   267
a theorem, Isabelle will turn your free variables into unknowns: it merely
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   268
indicates that Isabelle will automatically instantiate those unknowns
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   269
suitably when the theorem is used in some other proof.
9689
751fde5307e4 *** empty log message ***
nipkow
parents: 9541
diff changeset
   270
Note that for readability we often drop the \isa{?}s when displaying a theorem.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   271
\begin{warn}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   272
  If you use \isa{?}\index{$HOL0Ex@\texttt{?}} as an existential
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   273
  quantifier, it needs to be followed by a space. Otherwise \isa{?x} is
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   274
  interpreted as a schematic variable.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   275
\end{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   276
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
   277
\section{Interaction and Interfaces}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   278
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   279
Interaction with Isabelle can either occur at the shell level or through more
11301
be4163219703 spelling
paulson
parents: 11213
diff changeset
   280
advanced interfaces. To keep the tutorial independent of the interface, we
be4163219703 spelling
paulson
parents: 11213
diff changeset
   281
have phrased the description of the interaction in a neutral language. For
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   282
example, the phrase ``to abandon a proof'' means to type \isacommand{oops} at the
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   283
shell level, which is explained the first time the phrase is used. Other
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   284
interfaces perform the same act by cursor movements and/or mouse clicks.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   285
Although shell-based interaction is quite feasible for the kind of proof
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   286
scripts currently presented in this tutorial, the recommended interface for
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   287
Isabelle/Isar is the Emacs-based \bfindex{Proof
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   288
  General}~\cite{Aspinall:TACAS:2000,proofgeneral}.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   289
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   290
Some interfaces (including the shell level) offer special fonts with
10983
59961d32b1ae *** empty log message ***
nipkow
parents: 10978
diff changeset
   291
mathematical symbols. For those that do not, remember that \textsc{ascii}-equivalents
10978
5eebea8f359f *** empty log message ***
nipkow
parents: 10971
diff changeset
   292
are shown in table~\ref{tab:ascii} in the appendix.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   293
9541
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 8771
diff changeset
   294
Finally, a word about semicolons.\indexbold{$Isar@\texttt{;}} 
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 8771
diff changeset
   295
Commands may but need not be terminated by semicolons.
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 8771
diff changeset
   296
At the shell level it is advisable to use semicolons to enforce that a command
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   297
is executed immediately; otherwise Isabelle may wait for the next keyword
9541
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 8771
diff changeset
   298
before it knows that the command is complete.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   299
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   300
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
   301
\section{Getting Started}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   302
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   303
Assuming you have installed Isabelle, you start it by typing \texttt{isabelle
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   304
  -I HOL} in a shell window.\footnote{Simply executing \texttt{isabelle -I}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   305
  starts the default logic, which usually is already \texttt{HOL}.  This is
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   306
  controlled by the \texttt{ISABELLE_LOGIC} setting, see \emph{The Isabelle
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   307
    System Manual} for more details.} This presents you with Isabelle's most
10983
59961d32b1ae *** empty log message ***
nipkow
parents: 10978
diff changeset
   308
basic \textsc{ascii} interface.  In addition you need to open an editor window to
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   309
create theory files.  While you are developing a theory, we recommend to
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   310
type each command into the file first and then enter it into Isabelle by
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   311
copy-and-paste, thus ensuring that you have a complete record of your theory.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   312
As mentioned above, Proof General offers a much superior interface.
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10695
diff changeset
   313
If you have installed Proof General, you can start it by typing \texttt{Isabelle}.