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