doc-src/TutorialI/basics.tex
author immler@in.tum.de
Thu, 26 Feb 2009 10:13:43 +0100
changeset 30151 629f3a92863e
parent 16523 f8a734dc0fbc
child 38432 439f50a241c1
permissions -rw-r--r--
removed global ref dfg_format
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12668
b839bd6e06c6 \chapter{The Basics};
wenzelm
parents: 12473
diff changeset
     1
\chapter{The Basics}
8743
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}. \]
11456
7eb63f63e6c6 revisions and indexing
paulson
parents: 11450
diff changeset
    11
We do not assume that you are familiar with mathematical logic. 
7eb63f63e6c6 revisions and indexing
paulson
parents: 11450
diff changeset
    12
However, we do assume that
7eb63f63e6c6 revisions and indexing
paulson
parents: 11450
diff changeset
    13
you are used to logical and set theoretic notation, as covered
7eb63f63e6c6 revisions and indexing
paulson
parents: 11450
diff changeset
    14
in a good discrete mathematics course~\cite{Rosen-DMA}, and
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    15
that you are familiar with the basic concepts of functional
11209
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    16
programming~\cite{Bird-Haskell,Hudak-Haskell,paulson-ml2,Thompson-Haskell}.
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    17
Although this tutorial initially concentrates on functional programming, do
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    18
not be misled: HOL can express most mathematical concepts, and functional
a8cb33f6cf9c *** empty log message ***
nipkow
parents: 11205
diff changeset
    19
programming is just one particularly simple and ubiquitous instance.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    20
11205
67cec35dbc58 *** empty log message ***
nipkow
parents: 10983
diff changeset
    21
Isabelle~\cite{paulson-isa-book} is implemented in ML~\cite{SML}.  This has
67cec35dbc58 *** empty log message ***
nipkow
parents: 10983
diff changeset
    22
influenced some of Isabelle/HOL's concrete syntax but is otherwise irrelevant
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    23
for us: this tutorial is based on
11213
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    24
Isabelle/Isar~\cite{isabelle-isar-ref}, an extension of Isabelle which hides
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    25
the implementation language almost completely.  Thus the full name of the
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    26
system should be Isabelle/Isar/HOL, but that is a bit of a mouthful.
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    27
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    28
There are other implementations of HOL, in particular the one by Mike Gordon
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    29
\index{Gordon, Mike}%
11213
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    30
\emph{et al.}, which is usually referred to as ``the HOL system''
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    31
\cite{mgordon-hol}. For us, HOL refers to the logical system, and sometimes
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    32
its incarnation Isabelle/HOL\@.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    33
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    34
A tutorial is by definition incomplete.  Currently the tutorial only
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    35
introduces the rudiments of Isar's proof language. To fully exploit the power
11213
aeb5c72dd72a *** empty log message ***
nipkow
parents: 11209
diff changeset
    36
of Isar, in particular the ability to write readable and structured proofs,
15429
b08a5eaf22e3 new citation
nipkow
parents: 15358
diff changeset
    37
you should start with Nipkow's overview~\cite{Nipkow-TYPES02} and consult
b08a5eaf22e3 new citation
nipkow
parents: 15358
diff changeset
    38
the Isabelle/Isar Reference Manual~\cite{isabelle-isar-ref} and Wenzel's
b08a5eaf22e3 new citation
nipkow
parents: 15358
diff changeset
    39
PhD thesis~\cite{Wenzel-PhD} (which discusses many proof patterns)
b08a5eaf22e3 new citation
nipkow
parents: 15358
diff changeset
    40
for further details. If you want to use Isabelle's ML level
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    41
directly (for example for writing your own proof procedures) see the Isabelle
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    42
Reference Manual~\cite{isabelle-ref}; for details relating to HOL see the
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    43
Isabelle/HOL manual~\cite{isabelle-HOL}. All manuals have a comprehensive
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    44
index.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    45
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    46
\section{Theories}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    47
\label{sec:Basic:Theories}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    48
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
    49
\index{theories|(}%
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    50
Working with Isabelle means creating theories. Roughly speaking, a
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
    51
\textbf{theory} is a named collection of types, functions, and theorems,
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    52
much like a module in a programming language or a specification in a
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    53
specification language. In fact, theories in HOL can be either. The general
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    54
format of a theory \texttt{T} is
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    55
\begin{ttbox}
15136
1275417e3930 Adapted text to new theory header syntax.
nipkow
parents: 13814
diff changeset
    56
theory T
15141
a95c2ff210ba import -> imports
nipkow
parents: 15136
diff changeset
    57
imports B\(@1\) \(\ldots\) B\(@n\)
15136
1275417e3930 Adapted text to new theory header syntax.
nipkow
parents: 13814
diff changeset
    58
begin
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    59
{\rmfamily\textit{declarations, definitions, and proofs}}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    60
end
15358
26c501c5024d *** empty log message ***
nipkow
parents: 15141
diff changeset
    61
\end{ttbox}\cmmdx{theory}\cmmdx{imports}
15136
1275417e3930 Adapted text to new theory header syntax.
nipkow
parents: 13814
diff changeset
    62
where \texttt{B}$@1$ \dots\ \texttt{B}$@n$ are the names of existing
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    63
theories that \texttt{T} is based on and \textit{declarations,
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    64
    definitions, and proofs} represents the newly introduced concepts
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    65
(types, functions etc.) and proofs about them. The \texttt{B}$@i$ are the
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    66
direct \textbf{parent theories}\indexbold{parent theories} of~\texttt{T}\@.
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    67
Everything defined in the parent theories (and their parents, recursively) is
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    68
automatically visible. To avoid name clashes, identifiers can be
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    69
\textbf{qualified}\indexbold{identifiers!qualified}
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    70
by theory names as in \texttt{T.f} and~\texttt{B.f}. 
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    71
Each theory \texttt{T} must
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
    72
reside in a \textbf{theory file}\index{theory files} named \texttt{T.thy}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    73
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    74
This tutorial is concerned with introducing you to the different linguistic
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    75
constructs that can fill the \textit{declarations, definitions, and
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
    76
    proofs} above.  A complete grammar of the basic
12327
5a4d78204492 *** empty log message ***
nipkow
parents: 11456
diff changeset
    77
constructs is found in the Isabelle/Isar Reference
5a4d78204492 *** empty log message ***
nipkow
parents: 11456
diff changeset
    78
Manual~\cite{isabelle-isar-ref}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    79
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    80
\begin{warn}
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
    81
  HOL contains a theory \thydx{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.
12332
aea72a834c85 *** empty log message ***
nipkow
parents: 12327
diff changeset
    85
\end{warn}
16306
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    86
HOL's theory collection is available online at
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    87
\begin{center}\small
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    88
    \url{http://isabelle.in.tum.de/library/HOL/}
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    89
\end{center}
16359
nipkow
parents: 16306
diff changeset
    90
and is recommended browsing. In subdirectory \texttt{Library} you find
nipkow
parents: 16306
diff changeset
    91
a growing library of useful theories that are not part of \isa{Main}
nipkow
parents: 16306
diff changeset
    92
but can be included among the parents of a theory and will then be
nipkow
parents: 16306
diff changeset
    93
loaded automatically.
16306
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    94
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    95
For the more adventurous, there is the \emph{Archive of Formal Proofs},
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    96
a journal-like collection of more advanced Isabelle theories:
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    97
\begin{center}\small
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    98
    \url{http://afp.sourceforge.net/}
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
    99
\end{center}
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
   100
We hope that you will contribute to it yourself one day.%
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   101
\index{theories|)}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   102
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   103
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
   104
\section{Types, Terms and Formulae}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   105
\label{sec:TypesTermsForms}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   106
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10695
diff changeset
   107
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
   108
logic whose type system resembles that of functional programming languages
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   109
like ML or Haskell. Thus there are
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   110
\index{types|(}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   111
\begin{description}
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   112
\item[base types,] 
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   113
in particular \tydx{bool}, the type of truth values,
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   114
and \tydx{nat}, the type of natural numbers.
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   115
\item[type constructors,]\index{type constructors}
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   116
 in particular \tydx{list}, the type of
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   117
lists, and \tydx{set}, the type of sets. Type constructors are written
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   118
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
   119
natural numbers. Parentheses around single arguments can be dropped (as in
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   120
\isa{nat list}), multiple arguments are separated by commas (as in
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   121
\isa{(bool,nat)ty}).
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   122
\item[function types,]\index{function types}
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   123
denoted by \isasymFun\indexbold{$IsaFun@\isasymFun}.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   124
  In HOL \isasymFun\ represents \emph{total} functions only. As is customary,
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   125
  \isa{$\tau@1$ \isasymFun~$\tau@2$ \isasymFun~$\tau@3$} means
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   126
  \isa{$\tau@1$ \isasymFun~($\tau@2$ \isasymFun~$\tau@3$)}. Isabelle also
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   127
  supports the notation \isa{[$\tau@1,\dots,\tau@n$] \isasymFun~$\tau$}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   128
  which abbreviates \isa{$\tau@1$ \isasymFun~$\cdots$ \isasymFun~$\tau@n$
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   129
    \isasymFun~$\tau$}.
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   130
\item[type variables,]\index{type variables}\index{variables!type}
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10695
diff changeset
   131
  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
   132
  to polymorphic types like \isa{'a \isasymFun~'a}, the type of the identity
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   133
  function.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   134
\end{description}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   135
\begin{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   136
  Types are extremely important because they prevent us from writing
16359
nipkow
parents: 16306
diff changeset
   137
  nonsense.  Isabelle insists that all terms and formulae must be
nipkow
parents: 16306
diff changeset
   138
  well-typed and will print an error message if a type mismatch is
nipkow
parents: 16306
diff changeset
   139
  encountered. To reduce the amount of explicit type information that
nipkow
parents: 16306
diff changeset
   140
  needs to be provided by the user, Isabelle infers the type of all
nipkow
parents: 16306
diff changeset
   141
  variables automatically (this is called \bfindex{type inference})
nipkow
parents: 16306
diff changeset
   142
  and keeps quiet about it. Occasionally this may lead to
nipkow
parents: 16306
diff changeset
   143
  misunderstandings between you and the system. If anything strange
nipkow
parents: 16306
diff changeset
   144
  happens, we recommend that you ask Isabelle to display all type
16523
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   145
  information via the Proof General menu item \pgmenu{Isabelle} $>$
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   146
  \pgmenu{Settings} $>$ \pgmenu{Show Types} (see \S\ref{sec:interface}
16359
nipkow
parents: 16306
diff changeset
   147
  for details).
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   148
\end{warn}%
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   149
\index{types|)}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   150
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   151
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   152
\index{terms|(}
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   153
\textbf{Terms} are formed as in functional programming by
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   154
applying functions to arguments. If \isa{f} is a function of type
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   155
\isa{$\tau@1$ \isasymFun~$\tau@2$} and \isa{t} is a term of type
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   156
$\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
   157
infix functions like \isa{+} and some basic constructs from functional
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   158
programming, such as conditional expressions:
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   159
\begin{description}
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   160
\item[\isa{if $b$ then $t@1$ else $t@2$}]\index{*if expressions}
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   161
Here $b$ is of type \isa{bool} and $t@1$ and $t@2$ are of the same type.
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   162
\item[\isa{let $x$ = $t$ in $u$}]\index{*let expressions}
13814
5402c2eaf393 *** empty log message ***
nipkow
parents: 13439
diff changeset
   163
is equivalent to $u$ where all free occurrences of $x$ have been replaced by
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   164
$t$. For example,
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   165
\isa{let x = 0 in x+x} is equivalent to \isa{0+0}. Multiple bindings are separated
13814
5402c2eaf393 *** empty log message ***
nipkow
parents: 13439
diff changeset
   166
by semicolons: \isa{let $x@1$ = $t@1$;\dots; $x@n$ = $t@n$ in $u$}.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   167
\item[\isa{case $e$ of $c@1$ \isasymFun~$e@1$ |~\dots~| $c@n$ \isasymFun~$e@n$}]
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   168
\index{*case expressions}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   169
evaluates to $e@i$ if $e$ is of the form $c@i$.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   170
\end{description}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   171
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   172
Terms may also contain
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   173
\isasymlambda-abstractions.\index{lambda@$\lambda$ expressions}
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   174
For example,
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   175
\isa{\isasymlambda{}x.~x+1} is the function that takes an argument \isa{x} and
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   176
returns \isa{x+1}. Instead of
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   177
\isa{\isasymlambda{}x.\isasymlambda{}y.\isasymlambda{}z.~$t$} we can write
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   178
\isa{\isasymlambda{}x~y~z.~$t$}.%
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   179
\index{terms|)}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   180
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   181
\index{formulae|(}%
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   182
\textbf{Formulae} are terms of type \tydx{bool}.
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   183
There are the basic constants \cdx{True} and \cdx{False} and
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   184
the usual logical connectives (in decreasing order of priority):
11420
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   185
\indexboldpos{\protect\isasymnot}{$HOL0not}, \indexboldpos{\protect\isasymand}{$HOL0and},
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   186
\indexboldpos{\protect\isasymor}{$HOL0or}, and \indexboldpos{\protect\isasymimp}{$HOL0imp},
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   187
all of which (except the unary \isasymnot) associate to the right. In
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   188
particular \isa{A \isasymimp~B \isasymimp~C} means \isa{A \isasymimp~(B
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   189
  \isasymimp~C)} and is thus logically equivalent to \isa{A \isasymand~B
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   190
  \isasymimp~C} (which is \isa{(A \isasymand~B) \isasymimp~C}).
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   191
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   192
Equality\index{equality} is available in the form of the infix function
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   193
\isa{=} of type \isa{'a \isasymFun~'a
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   194
  \isasymFun~bool}. Thus \isa{$t@1$ = $t@2$} is a formula provided $t@1$
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   195
and $t@2$ are terms of the same type. If $t@1$ and $t@2$ are of type
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   196
\isa{bool} then \isa{=} acts as \rmindex{if-and-only-if}.
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   197
The formula
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   198
\isa{$t@1$~\isasymnoteq~$t@2$} is merely an abbreviation for
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   199
\isa{\isasymnot($t@1$ = $t@2$)}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   200
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   201
Quantifiers\index{quantifiers} are written as
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   202
\isa{\isasymforall{}x.~$P$} and \isa{\isasymexists{}x.~$P$}. 
11420
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   203
There is even
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   204
\isa{\isasymuniqex{}x.~$P$}, which
11420
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   205
means that there exists exactly one \isa{x} that satisfies \isa{$P$}. 
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   206
Nested quantifications can be abbreviated:
9529d31f39e0 added\\protect
paulson
parents: 11405
diff changeset
   207
\isa{\isasymforall{}x~y~z.~$P$} means
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   208
\isa{\isasymforall{}x.\isasymforall{}y.\isasymforall{}z.~$P$}.%
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   209
\index{formulae|)}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   210
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   211
Despite type inference, it is sometimes necessary to attach explicit
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   212
\bfindex{type constraints} to a term.  The syntax is
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   213
\isa{$t$::$\tau$} as in \isa{x < (y::nat)}. Note that
10538
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10396
diff changeset
   214
\ttindexboldpos{::}{$Isatype} binds weakly and should therefore be enclosed
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   215
in parentheses.  For instance,
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   216
\isa{x < y::nat} is ill-typed because it is interpreted as
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   217
\isa{(x < y)::nat}.  Type constraints may be needed to disambiguate
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   218
expressions
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   219
involving overloaded functions such as~\isa{+}, 
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   220
\isa{*} and~\isa{<}.  Section~\ref{sec:overloading} 
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   221
discusses overloading, while Table~\ref{tab:overloading} presents the most
10695
ffb153ef6366 *** empty log message ***
nipkow
parents: 10538
diff changeset
   222
important overloaded function symbols.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   223
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   224
In general, HOL's concrete \rmindex{syntax} tries to follow the conventions of
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   225
functional programming and mathematics.  Here are the main rules that you
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   226
should be familiar with to avoid certain syntactic traps:
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   227
\begin{itemize}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   228
\item
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   229
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
   230
\item
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   231
Isabelle allows infix functions like \isa{+}. The prefix form of function
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   232
application binds more strongly than anything else and hence \isa{f~x + y}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   233
means \isa{(f~x)~+~y} and not \isa{f(x+y)}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   234
\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
   235
  equality has a high priority, as befitting a relation, while if-and-only-if
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   236
  typically has the lowest priority.  Thus, \isa{\isasymnot~\isasymnot~P =
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   237
    P} means \isa{\isasymnot\isasymnot(P = P)} and not
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   238
  \isa{(\isasymnot\isasymnot P) = P}. When using \isa{=} to mean
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   239
  logical equivalence, enclose both operands in parentheses, as in \isa{(A
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   240
    \isasymand~B) = (B \isasymand~A)}.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   241
\item
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   242
Constructs with an opening but without a closing delimiter bind very weakly
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   243
and should therefore be enclosed in parentheses if they appear in subterms, as
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   244
in \isa{(\isasymlambda{}x.~x) = f}.  This includes 
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   245
\isa{if},\index{*if expressions}
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   246
\isa{let},\index{*let expressions}
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   247
\isa{case},\index{*case expressions}
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   248
\isa{\isasymlambda}, and quantifiers.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   249
\item
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   250
Never write \isa{\isasymlambda{}x.x} or \isa{\isasymforall{}x.x=x}
12327
5a4d78204492 *** empty log message ***
nipkow
parents: 11456
diff changeset
   251
because \isa{x.x} is always taken as a single qualified identifier. Write
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   252
\isa{\isasymlambda{}x.~x} and \isa{\isasymforall{}x.~x=x} instead.
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   253
\item Identifiers\indexbold{identifiers} may contain the characters \isa{_} 
12327
5a4d78204492 *** empty log message ***
nipkow
parents: 11456
diff changeset
   254
and~\isa{'}, except at the beginning.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   255
\end{itemize}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   256
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   257
For the sake of readability, we use the usual mathematical symbols throughout
10983
59961d32b1ae *** empty log message ***
nipkow
parents: 10978
diff changeset
   258
the tutorial. Their \textsc{ascii}-equivalents are shown in table~\ref{tab:ascii} in
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   259
the appendix.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   260
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   261
\begin{warn}
16359
nipkow
parents: 16306
diff changeset
   262
A particular problem for novices can be the priority of operators. If
nipkow
parents: 16306
diff changeset
   263
you are unsure, use additional parentheses. In those cases where
nipkow
parents: 16306
diff changeset
   264
Isabelle echoes your input, you can see which parentheses are dropped
nipkow
parents: 16306
diff changeset
   265
--- they were superfluous. If you are unsure how to interpret
nipkow
parents: 16306
diff changeset
   266
Isabelle's output because you don't know where the (dropped)
16523
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   267
parentheses go, set the Proof General flag \pgmenu{Isabelle} $>$
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   268
\pgmenu{Settings} $>$ \pgmenu{Show Brackets} (see \S\ref{sec:interface}).
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   269
\end{warn}
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   270
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   271
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   272
\section{Variables}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   273
\label{sec:variables}
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   274
\index{variables|(}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   275
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   276
Isabelle distinguishes free and bound variables, as is customary. Bound
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   277
variables are automatically renamed to avoid clashes with free variables. In
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   278
addition, Isabelle has a third kind of variable, called a \textbf{schematic
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   279
  variable}\index{variables!schematic} or \textbf{unknown}\index{unknowns}, 
13439
2f98365f57a8 *** empty log message ***
nipkow
parents: 12668
diff changeset
   280
which must have a~\isa{?} as its first character.  
11428
332347b9b942 tidying the index
paulson
parents: 11420
diff changeset
   281
Logically, an unknown is a free variable. But it may be
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   282
instantiated by another term during the proof process. For example, the
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   283
mathematical theorem $x = x$ is represented in Isabelle as \isa{?x = ?x},
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   284
which means that Isabelle can instantiate it arbitrarily. This is in contrast
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   285
to ordinary variables, which remain fixed. The programming language Prolog
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   286
calls unknowns {\em logical\/} variables.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   287
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   288
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
   289
variables. Just don't be surprised that after you have finished the proof of
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   290
a theorem, Isabelle will turn your free variables into unknowns.  It
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   291
indicates that Isabelle will automatically instantiate those unknowns
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   292
suitably when the theorem is used in some other proof.
9689
751fde5307e4 *** empty log message ***
nipkow
parents: 9541
diff changeset
   293
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
   294
\begin{warn}
11450
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   295
  For historical reasons, Isabelle accepts \isa{?} as an ASCII representation
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   296
  of the \(\exists\) symbol.  However, the \isa{?} character must then be followed
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   297
  by a space, as in \isa{?~x. f(x) = 0}.  Otherwise, \isa{?x} is
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   298
  interpreted as a schematic variable.  The preferred ASCII representation of
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   299
  the \(\exists\) symbol is \isa{EX}\@. 
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   300
\end{warn}%
1b02a6c4032f tweaks and indexing
paulson
parents: 11428
diff changeset
   301
\index{variables|)}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   302
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
   303
\section{Interaction and Interfaces}
16306
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
   304
\label{sec:interface}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   305
16359
nipkow
parents: 16306
diff changeset
   306
The recommended interface for Isabelle/Isar is the (X)Emacs-based
nipkow
parents: 16306
diff changeset
   307
\bfindex{Proof General}~\cite{proofgeneral,Aspinall:TACAS:2000}.
nipkow
parents: 16306
diff changeset
   308
Interaction with Isabelle at the shell level, although possible,
nipkow
parents: 16306
diff changeset
   309
should be avoided. Most of the tutorial is independent of the
nipkow
parents: 16306
diff changeset
   310
interface and is phrased in a neutral language. For example, the
nipkow
parents: 16306
diff changeset
   311
phrase ``to abandon a proof'' corresponds to the obvious
16523
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   312
action of clicking on the \pgmenu{Undo} symbol in Proof General.
16359
nipkow
parents: 16306
diff changeset
   313
Proof General specific information is often displayed in paragraphs
nipkow
parents: 16306
diff changeset
   314
identified by a miniature Proof General icon. Here are two examples:
nipkow
parents: 16306
diff changeset
   315
\begin{pgnote}
nipkow
parents: 16306
diff changeset
   316
Proof General supports a special font with mathematical symbols known
nipkow
parents: 16306
diff changeset
   317
as ``x-symbols''. All symbols have \textsc{ascii}-equivalents: for
nipkow
parents: 16306
diff changeset
   318
example, you can enter either \verb!&!  or \verb!\<and>! to obtain
nipkow
parents: 16306
diff changeset
   319
$\land$. For a list of the most frequent symbols see table~\ref{tab:ascii}
nipkow
parents: 16306
diff changeset
   320
in the appendix.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   321
16359
nipkow
parents: 16306
diff changeset
   322
Note that by default x-symbols are not enabled. You have to switch
16523
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   323
them on via the menu item \pgmenu{Proof-General} $>$ \pgmenu{Options} $>$
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   324
\pgmenu{X-Symbols} (and save the option via the top-level
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   325
\pgmenu{Options} menu).
16306
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
   326
\end{pgnote}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   327
16306
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
   328
\begin{pgnote}
16523
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   329
Proof General offers the \pgmenu{Isabelle} menu for displaying
16359
nipkow
parents: 16306
diff changeset
   330
information and setting flags. A particularly useful flag is
16523
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   331
\pgmenu{Isabelle} $>$ \pgmenu{Settings} $>$ \pgdx{Show Types} which
16359
nipkow
parents: 16306
diff changeset
   332
causes Isabelle to output the type information that is usually
16306
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
   333
suppressed. This is indispensible in case of errors of all kinds
16359
nipkow
parents: 16306
diff changeset
   334
because often the types reveal the source of the problem. Once you
nipkow
parents: 16306
diff changeset
   335
have diagnosed the problem you may no longer want to see the types
nipkow
parents: 16306
diff changeset
   336
because they clutter all output. Simply reset the flag.
16306
8117e2037d3b updating...
nipkow
parents: 15429
diff changeset
   337
\end{pgnote}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   338
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10795
diff changeset
   339
\section{Getting Started}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   340
16359
nipkow
parents: 16306
diff changeset
   341
Assuming you have installed Isabelle and Proof General, you start it by typing
nipkow
parents: 16306
diff changeset
   342
\texttt{Isabelle} in a shell window. This launches a Proof General window.
nipkow
parents: 16306
diff changeset
   343
By default, you are in HOL\footnote{This is controlled by the
nipkow
parents: 16306
diff changeset
   344
\texttt{ISABELLE_LOGIC} setting, see \emph{The Isabelle System Manual}
nipkow
parents: 16306
diff changeset
   345
for more details.}.
nipkow
parents: 16306
diff changeset
   346
nipkow
parents: 16306
diff changeset
   347
\begin{pgnote}
16523
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   348
You can choose a different logic via the \pgmenu{Isabelle} $>$
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16359
diff changeset
   349
\pgmenu{Logics} menu. For example, you may want to work in the real
16359
nipkow
parents: 16306
diff changeset
   350
numbers, an extension of HOL (see \S\ref{sec:real}).
nipkow
parents: 16306
diff changeset
   351
\end{pgnote}