doc-src/IsarOverview/Isar/document/intro.tex
author wenzelm
Fri, 04 Nov 2011 17:19:33 +0100
changeset 45340 98ec8b51af9c
parent 25427 8ba39d2d9d0b
child 45813 5edf7a15ff8e
permissions -rw-r--r--
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     1
\section{Introduction}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     2
25427
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
     3
This is a tutorial introduction to structured proofs in Isabelle/HOL.
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
     4
It introduces the core of the proof language Isar by example. Isar is
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
     5
an extension of the \isa{apply}-style proofs introduced in the
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
     6
Isabelle/HOL tutorial~\cite{LNCS2283} with structured proofs in a
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
     7
stylised language of mathematics.  These proofs are readable for both
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
     8
human and machine.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     9
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    10
\subsection{A first glimpse of Isar}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    11
Below you find a simplified grammar for Isar proofs.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    12
Parentheses are used for grouping and $^?$ indicates an optional item:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    13
\begin{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    14
\begin{tabular}{lrl}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    15
\emph{proof} & ::= & \isakeyword{proof} \emph{method}$^?$
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    16
                     \emph{statement}*
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    17
                     \isakeyword{qed} \\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    18
                 &$\mid$& \isakeyword{by} \emph{method}\\[1ex]
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    19
\emph{statement} &::= & \isakeyword{fix} \emph{variables} \\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    20
             &$\mid$& \isakeyword{assume} \emph{propositions} \\
25427
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    21
             &$\mid$& (\isakeyword{from} \emph{fact}*)$^?$ 
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    22
                    (\isakeyword{show} $\mid$ \isakeyword{have})
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    23
                      \emph{propositions} \emph{proof} \\[1ex]
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    24
\emph{proposition} &::=& (\emph{label}{\bf:})$^?$ \emph{string} \\[1ex]
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    25
\emph{fact} &::=& \emph{label}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    26
\end{tabular}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    27
\end{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    28
A proof can be either compound (\isakeyword{proof} --
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    29
\isakeyword{qed}) or atomic (\isakeyword{by}). A \emph{method} is a
25427
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    30
proof method.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    31
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    32
This is a typical proof skeleton:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    33
\begin{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    34
\begin{tabular}{@{}ll}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    35
\isakeyword{proof}\\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    36
\hspace*{3ex}\isakeyword{assume} \isa{"}\emph{the-assm}\isa{"}\\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    37
\hspace*{3ex}\isakeyword{have} \isa{"}\dots\isa{"} & --- intermediate result\\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    38
\hspace*{3ex}\vdots\\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    39
\hspace*{3ex}\isakeyword{have} \isa{"}\dots\isa{"} & --- intermediate result\\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    40
\hspace*{3ex}\isakeyword{show} \isa{"}\emph{the-concl}\isa{"}\\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    41
\isakeyword{qed}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    42
\end{tabular}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    43
\end{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    44
It proves \emph{the-assm}~$\Longrightarrow$~\emph{the-concl}. Text starting with
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    45
``---'' is a comment. The intermediate \isakeyword{have}s are only
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    46
there to bridge the gap between the assumption and the conclusion and
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    47
do not contribute to the theorem being proved. In contrast,
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    48
\isakeyword{show} establishes the conclusion of the theorem.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    49
25427
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    50
\subsection{Background}
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    51
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    52
Interactive theorem proving has been dominated by a model of proof
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    53
that goes back to the LCF system~\cite{LCF}: a proof is a more or less
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    54
structured sequence of commands that manipulate an implicit proof
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    55
state. Thus the proof text is only suitable for the machine; for a
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    56
human, the proof only comes alive when he can see the state changes
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    57
caused by the stepwise execution of the commands. Such proofs are like
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    58
uncommented assembly language programs. Their Isabelle incarnation are
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    59
sequences of \isa{apply}-commands.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    60
25427
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    61
In contrast there is the model of a mathematics-like proof language
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    62
pioneered in the Mizar system~\cite{Rudnicki92} and followed by
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    63
Isar~\cite{WenzelW-JAR}.
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    64
The most important arguments in favour of this style are
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    65
\emph{communication} and \emph{maintainance}: structured proofs are
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    66
immensly more readable and maintainable than \isa{apply}-scripts.
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    67
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    68
For reading this tutorial you should be familiar with natural
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    69
deduction and the basics of Isabelle/HOL~\cite{LNCS2283} although we
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    70
summarize the most important aspects of Isabelle below.  The
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    71
definitive Isar reference is its manual~\cite{Isar-Ref-Man}. For an
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    72
example-based account of Isar's support for reasoning by chains of
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    73
(in)equations see~\cite{BauerW-TPHOLs01}.
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    74
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    75
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
    76
\subsection{Bits of Isabelle}
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    77
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    78
Isabelle's meta-logic comes with a type of \emph{propositions} with
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    79
implication $\Longrightarrow$ and a universal quantifier $\bigwedge$ for expressing
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    80
inference rules and generality.  Iterated implications $A_1 \Longrightarrow \dots
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    81
A_n \Longrightarrow A$ may be abbreviated to $[\![ A_1; \dots; A_n ]\!] \Longrightarrow A$.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    82
Applying a theorem $A \Longrightarrow B$ (named \isa{T}) to a theorem $A$ (named
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    83
\isa{U}) is written \isa{T[OF U]} and yields theorem $B$.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    84
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    85
Isabelle terms are simply typed. Function types are
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    86
written $\tau_1 \Rightarrow \tau_2$.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    87
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    88
Free variables that may be instantiated (``logical variables'' in Prolog
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    89
parlance) are prefixed with a \isa{?}. Typically, theorems are stated with
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    90
ordinary free variables but after the proof those are automatically replaced
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    91
by \isa{?}-variables. Thus the theorem can be used with arbitrary instances
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    92
of its free variables.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    93
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    94
Isabelle/HOL offers all the usual logical symbols like $\longrightarrow$, $\land$,
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    95
$\forall$ etc. HOL formulae are propositions, e.g.\ $\forall$ can appear below
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    96
$\Longrightarrow$, but not the other way around. Beware that $\longrightarrow$ binds more
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    97
tightly than $\Longrightarrow$: in $\forall x. P \longrightarrow Q$ the $\forall x$ covers $P \longrightarrow Q$, whereas
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    98
in $\forall x. P \Longrightarrow Q$ it covers only $P$.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    99
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   100
Proof methods include \isa{rule} (which performs a backwards
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   101
step with a given rule, unifying the conclusion of the rule with the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   102
current subgoal and replacing the subgoal by the premises of the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   103
rule), \isa{simp} (for simplification) and \isa{blast} (for predicate
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   104
calculus reasoning).
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   105
25427
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   106
\subsection{Advice}
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   107
25427
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   108
A word of warning for potential writers of Isar proofs.  It
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   109
is easier to write obscure rather than readable texts.  Similarly,
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   110
\isa{apply}-style proofs are sometimes easier to write than readable
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   111
ones: structure does not emerge automatically but needs to be
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   112
understood and imposed. If the precise structure of the proof is
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   113
unclear at beginning, it can be useful to start with \isa{apply} for
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   114
exploratory purposes until one has found a proof which can be
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   115
converted into a structured text in a second step. Top down conversion
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   116
is possible because Isar allows \isa{apply}-style proofs as components
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   117
of structured ones.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   118
25427
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   119
Finally, do not be mislead by the simplicity of the formulae being proved,
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   120
especially in the beginning. Isar has been used very successfully in
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   121
large applications, for example the formalisation of Java
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   122
dialects~\cite{KleinN-TOPLAS}.
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   123
\medskip
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   124
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   125
The rest of this tutorial is divided into two parts.
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   126
Section~\ref{sec:Logic} introduces proofs in pure logic based on
8ba39d2d9d0b updated
nipkow
parents: 13999
diff changeset
   127
natural deduction. Section~\ref{sec:Induct} is dedicated to induction.