doc-src/TutorialI/basics.tex
author nipkow
Tue, 25 Apr 2000 08:09:10 +0200
changeset 8771 026f37a86ea7
parent 8743 3253c6046d57
child 9541 d17c0b34d5c8
permissions -rw-r--r--
*** empty log message ***
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
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    51
(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
    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
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    57
reside in a \bfindex{theory file} named \texttt{T.thy}.
8743
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{Types, terms and formulae}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    78
\label{sec:TypesTermsForms}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    79
\indexbold{type}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    80
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    81
Embedded in a theory are the types, terms and formulae of HOL. HOL is a typed
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    82
logic whose type system resembles that of functional programming languages
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    83
like ML or Haskell. Thus there are
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    84
\begin{description}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    85
\item[base types,] in particular \isaindex{bool}, the type of truth values,
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    86
and \isaindex{nat}, the type of natural numbers.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    87
\item[type constructors,] in particular \isaindex{list}, the type of
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    88
lists, and \isaindex{set}, the type of sets. Type constructors are written
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    89
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
    90
natural numbers. Parentheses around single arguments can be dropped (as in
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    91
\isa{nat list}), multiple arguments are separated by commas (as in
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    92
\isa{(bool,nat)ty}).
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    93
\item[function types,] denoted by \isasymFun\indexbold{$IsaFun@\isasymFun}.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    94
  In HOL \isasymFun\ represents \emph{total} functions only. As is customary,
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    95
  \isa{$\tau@1$ \isasymFun~$\tau@2$ \isasymFun~$\tau@3$} means
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    96
  \isa{$\tau@1$ \isasymFun~($\tau@2$ \isasymFun~$\tau@3$)}. Isabelle also
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    97
  supports the notation \isa{[$\tau@1,\dots,\tau@n$] \isasymFun~$\tau$}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
    98
  which abbreviates \isa{$\tau@1$ \isasymFun~$\cdots$ \isasymFun~$\tau@n$
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
    99
    \isasymFun~$\tau$}.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   100
\item[type variables,]\indexbold{type variable}\indexbold{variable!type}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   101
  denoted by \isaindexbold{'a}, \isa{'b} etc., just like in ML. They give rise
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   102
  to polymorphic types like \isa{'a \isasymFun~'a}, the type of the identity
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   103
  function.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   104
\end{description}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   105
\begin{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   106
  Types are extremely important because they prevent us from writing
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   107
  nonsense.  Isabelle insists that all terms and formulae must be well-typed
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   108
  and will print an error message if a type mismatch is encountered. To
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   109
  reduce the amount of explicit type information that needs to be provided by
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   110
  the user, Isabelle infers the type of all variables automatically (this is
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   111
  called \bfindex{type inference}) and keeps quiet about it. Occasionally
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   112
  this may lead to misunderstandings between you and the system. If anything
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   113
  strange happens, we recommend to set the \rmindex{flag}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   114
  \ttindexbold{show_types} that tells Isabelle to display type information
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   115
  that is usually suppressed: simply type
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   116
\begin{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   117
ML "set show_types"
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   118
\end{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   119
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   120
\noindent
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   121
This can be reversed by \texttt{ML "reset show_types"}. Various other flags
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   122
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
   123
\end{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   124
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   125
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   126
\textbf{Terms}\indexbold{term} are formed as in functional programming by
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   127
applying functions to arguments. If \isa{f} is a function of type
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   128
\isa{$\tau@1$ \isasymFun~$\tau@2$} and \isa{t} is a term of type
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   129
$\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
   130
infix functions like \isa{+} and some basic constructs from functional
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   131
programming:
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   132
\begin{description}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   133
\item[\isa{if $b$ then $t@1$ else $t@2$}]\indexbold{*if}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   134
means what you think it means and requires that
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   135
$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
   136
\item[\isa{let $x$ = $t$ in $u$}]\indexbold{*let}
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   137
is equivalent to $u$ where all occurrences of $x$ have been replaced by
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   138
$t$. For example,
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   139
\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
   140
by semicolons: \isa{let $x@1$ = $t@1$; \dots; $x@n$ = $t@n$ in $u$}.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   141
\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
   142
\indexbold{*case}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   143
evaluates to $e@i$ if $e$ is of the form $c@i$.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   144
\end{description}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   145
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   146
Terms may also contain
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   147
\isasymlambda-abstractions\indexbold{$Isalam@\isasymlambda}. For example,
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   148
\isa{\isasymlambda{}x.~x+1} is the function that takes an argument \isa{x} and
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   149
returns \isa{x+1}. Instead of
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   150
\isa{\isasymlambda{}x.\isasymlambda{}y.\isasymlambda{}z.~$t$} we can write
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   151
\isa{\isasymlambda{}x~y~z.~$t$}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   152
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   153
\textbf{Formulae}\indexbold{formula} are terms of type \isaindexbold{bool}.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   154
There are the basic constants \isaindexbold{True} and \isaindexbold{False} and
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   155
the usual logical connectives (in decreasing order of priority):
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   156
\indexboldpos{\isasymnot}{$HOL0not}, \indexboldpos{\isasymand}{$HOL0and},
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   157
\indexboldpos{\isasymor}{$HOL0or}, and \indexboldpos{\isasymimp}{$HOL0imp},
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   158
all of which (except the unary \isasymnot) associate to the right. In
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   159
particular \isa{A \isasymimp~B \isasymimp~C} means \isa{A \isasymimp~(B
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   160
  \isasymimp~C)} and is thus logically equivalent to \isa{A \isasymand~B
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   161
  \isasymimp~C} (which is \isa{(A \isasymand~B) \isasymimp~C}).
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   162
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   163
Equality is available in the form of the infix function
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   164
\isa{=}\indexbold{$HOL0eq@\texttt{=}} of type \isa{'a \isasymFun~'a
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   165
  \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
   166
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
   167
\isa{bool}, \isa{=} acts as if-and-only-if. The formula
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   168
\isa{$t@1$~\isasymnoteq~$t@2$} is merely an abbreviation for
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   169
\isa{\isasymnot($t@1$ = $t@2$)}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   170
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   171
The syntax for quantifiers is
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   172
\isa{\isasymforall{}x.~$P$}\indexbold{$HOL0All@\isasymforall} and
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   173
\isa{\isasymexists{}x.~$P$}\indexbold{$HOL0Ex@\isasymexists}.  There is
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   174
even \isa{\isasymuniqex{}x.~$P$}\index{$HOL0ExU@\isasymuniqex|bold}, which
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   175
means that there exists exactly one \isa{x} that satisfies \isa{$P$}.  Nested
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   176
quantifications can be abbreviated: \isa{\isasymforall{}x~y~z.~$P$} means
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   177
\isa{\isasymforall{}x.\isasymforall{}y.\isasymforall{}z.~$P$}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   178
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   179
Despite type inference, it is sometimes necessary to attach explicit
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   180
\textbf{type constraints}\indexbold{type constraint} to a term.  The syntax is
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   181
\isa{$t$::$\tau$} as in \isa{x < (y::nat)}. Note that
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   182
\ttindexboldpos{::}{$Isalamtc} binds weakly and should therefore be enclosed
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   183
in parentheses: \isa{x < y::nat} is ill-typed because it is interpreted as
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   184
\isa{(x < y)::nat}. The main reason for type constraints are overloaded
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   185
functions like \isa{+}, \isa{*} and \isa{<}. (See \S\ref{sec:TypeClasses} for
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   186
a full discussion of overloading.)
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   187
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   188
\begin{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   189
In general, HOL's concrete syntax tries to follow the conventions of
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   190
functional programming and mathematics. Below we list the main rules that you
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   191
should be familiar with to avoid certain syntactic traps. A particular
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   192
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
   193
more rather than fewer parentheses. In those cases where Isabelle echoes your
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   194
input, you can see which parentheses are dropped---they were superfluous. If
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   195
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
   196
where the (dropped) parentheses go, set (and possibly reset) the \rmindex{flag}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   197
\ttindexbold{show_brackets}:
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   198
\begin{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   199
ML "set show_brackets"; \(\dots\); ML "reset show_brackets";
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   200
\end{ttbox}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   201
\end{warn}
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{itemize}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   204
\item
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   205
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
   206
\item
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   207
Isabelle allows infix functions like \isa{+}. The prefix form of function
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   208
application binds more strongly than anything else and hence \isa{f~x + y}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   209
means \isa{(f~x)~+~y} and not \isa{f(x+y)}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   210
\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
   211
  equality has a high priority, as befitting a relation, while if-and-only-if
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   212
  typically has the lowest priority.  Thus, \isa{\isasymnot~\isasymnot~P =
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   213
    P} means \isa{\isasymnot\isasymnot(P = P)} and not
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   214
  \isa{(\isasymnot\isasymnot P) = P}. When using \isa{=} to mean
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   215
  logical equivalence, enclose both operands in parentheses, as in \isa{(A
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   216
    \isasymand~B) = (B \isasymand~A)}.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   217
\item
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   218
Constructs with an opening but without a closing delimiter bind very weakly
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   219
and should therefore be enclosed in parentheses if they appear in subterms, as
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   220
in \isa{f = (\isasymlambda{}x.~x)}. This includes \isaindex{if},
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   221
\isaindex{let}, \isaindex{case}, \isa{\isasymlambda}, and quantifiers.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   222
\item
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   223
Never write \isa{\isasymlambda{}x.x} or \isa{\isasymforall{}x.x=x}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   224
because \isa{x.x} is always read as a single qualified identifier that
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   225
refers to an item \isa{x} in theory \isa{x}. Write
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   226
\isa{\isasymlambda{}x.~x} and \isa{\isasymforall{}x.~x=x} instead.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   227
\item Identifiers\indexbold{identifier} may contain \isa{_} and \isa{'}.
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   228
\end{itemize}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   229
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   230
For the sake of readability the usual mathematical symbols are used throughout
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   231
the tutorial. Their ASCII-equivalents are shown in figure~\ref{fig:ascii} in
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   232
the appendix.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   233
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   234
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   235
\section{Variables}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   236
\label{sec:variables}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   237
\indexbold{variable}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   238
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   239
Isabelle distinguishes free and bound variables just as is customary. Bound
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   240
variables are automatically renamed to avoid clashes with free variables. In
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   241
addition, Isabelle has a third kind of variable, called a \bfindex{schematic
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   242
  variable}\indexbold{variable!schematic} or \bfindex{unknown}, which starts
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   243
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
   244
instantiated by another term during the proof process. For example, the
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   245
mathematical theorem $x = x$ is represented in Isabelle as \isa{?x = ?x},
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   246
which means that Isabelle can instantiate it arbitrarily. This is in contrast
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   247
to ordinary variables, which remain fixed. The programming language Prolog
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   248
calls unknowns {\em logical\/} variables.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   249
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   250
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
   251
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
   252
a theorem, Isabelle will turn your free variables into unknowns: it merely
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   253
indicates that Isabelle will automatically instantiate those unknowns
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   254
suitably when the theorem is used in some other proof.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   255
\begin{warn}
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   256
  If you use \isa{?}\index{$HOL0Ex@\texttt{?}} as an existential
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   257
  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
   258
  interpreted as a schematic variable.
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   259
\end{warn}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   260
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   261
\section{Interaction and interfaces}
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   262
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   263
Interaction with Isabelle can either occur at the shell level or through more
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   264
advanced interfaces. To keep the tutorial independent of the interface we
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   265
have phrased the description of the intraction in a neutral language. For
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   266
example, the phrase ``to abandon a proof'' means to type \isacommand{oops} at the
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   267
shell level, which is explained the first time the phrase is used. Other
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   268
interfaces perform the same act by cursor movements and/or mouse clicks.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   269
Although shell-based interaction is quite feasible for the kind of proof
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   270
scripts currently presented in this tutorial, the recommended interface for
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   271
Isabelle/Isar is the Emacs-based \bfindex{Proof
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   272
  General}~\cite{Aspinall:TACAS:2000,proofgeneral}.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   273
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   274
Some interfaces (including the shell level) offer special fonts with
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   275
mathematical symbols. For those that do not, remember that ASCII-equivalents
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   276
are shown in figure~\ref{fig:ascii} in the appendix.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   277
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   278
Finally, a word about semicolons.\indexbold{$Isar@\texttt{;}} Some interfaces,
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   279
for example Proof General, require each command to be terminated by a
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   280
semicolon, whereas others, for example the shell level, do not. But even at
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   281
the shell level it is advisable to use semicolons to enforce that a command
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   282
is executed immediately; otherwise Isabelle may wait for the next keyword
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   283
before it knows that the command is complete. Note that for readibility
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   284
reasons we often drop the final semicolon in the text.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   285
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   286
8743
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   287
\section{Getting started}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   288
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   289
Assuming you have installed Isabelle, you start it by typing \texttt{isabelle
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   290
  -I HOL} in a shell window.\footnote{Simply executing \texttt{isabelle -I}
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   291
  starts the default logic, which usually is already \texttt{HOL}.  This is
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   292
  controlled by the \texttt{ISABELLE_LOGIC} setting, see \emph{The Isabelle
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   293
    System Manual} for more details.} This presents you with Isabelle's most
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   294
basic ASCII interface.  In addition you need to open an editor window to
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   295
create theory files.  While you are developing a theory, we recommend to
3253c6046d57 I wonder if that's all?
nipkow
parents:
diff changeset
   296
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
   297
copy-and-paste, thus ensuring that you have a complete record of your theory.
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8743
diff changeset
   298
As mentioned above, Proof General offers a much superior interface.