doc-src/Logics/Old_HOL.tex
author wenzelm
Thu, 25 Nov 1993 15:32:42 +0100
changeset 154 f8c3715457b8
parent 114 96c627d2815e
child 287 6b62a6ddbe15
permissions -rw-r--r--
corrected obvious errors;
lcp@104
     1
%% $Id$
lcp@104
     2
\chapter{Higher-order logic}
lcp@104
     3
The directory~\ttindexbold{HOL} contains a theory for higher-order logic
lcp@111
     4
based on Gordon's~{\sc hol} system~\cite{mgordon88a}, which itself is based on
lcp@104
     5
Church~\cite{church40}.  Andrews~\cite{andrews86} is a full description of
lcp@104
     6
higher-order logic.  Gordon's work has demonstrated that higher-order logic
lcp@104
     7
is useful for hardware verification; beyond this, it is widely applicable
lcp@104
     8
in many areas of mathematics.  It is weaker than {\ZF} set theory but for
lcp@104
     9
most applications this does not matter.  If you prefer {\ML} to Lisp, you
lcp@104
    10
will probably prefer {\HOL} to~{\ZF}.
lcp@104
    11
lcp@104
    12
Previous releases of Isabelle included a completely different version
lcp@104
    13
of~{\HOL}, with explicit type inference rules~\cite{paulson-COLOG}.  This
lcp@104
    14
version no longer exists, but \ttindex{ZF} supports a similar style of
lcp@104
    15
reasoning.
lcp@104
    16
lcp@104
    17
{\HOL} has a distinct feel, compared with {\ZF} and {\CTT}.  It
lcp@104
    18
identifies object-level types with meta-level types, taking advantage of
lcp@104
    19
Isabelle's built-in type checker.  It identifies object-level functions
lcp@104
    20
with meta-level functions, so it uses Isabelle's operations for abstraction
lcp@104
    21
and application.  There is no ``apply'' operator: function applications are
lcp@104
    22
written as simply~$f(a)$ rather than $f{\tt`}a$.
lcp@104
    23
lcp@104
    24
These identifications allow Isabelle to support {\HOL} particularly nicely,
lcp@104
    25
but they also mean that {\HOL} requires more sophistication from the user
lcp@104
    26
--- in particular, an understanding of Isabelle's type system.  Beginners
lcp@104
    27
should gain experience by working in first-order logic, before attempting
lcp@104
    28
to use higher-order logic.  This chapter assumes familiarity with~{\FOL{}}.
lcp@104
    29
lcp@104
    30
lcp@104
    31
\begin{figure} 
lcp@104
    32
\begin{center}
lcp@104
    33
\begin{tabular}{rrr} 
lcp@111
    34
  \it name      &\it meta-type  & \it description \\ 
lcp@111
    35
  \idx{Trueprop}& $bool\To prop$                & coercion to $prop$\\
lcp@111
    36
  \idx{not}     & $bool\To bool$                & negation ($\neg$) \\
lcp@111
    37
  \idx{True}    & $bool$                        & tautology ($\top$) \\
lcp@111
    38
  \idx{False}   & $bool$                        & absurdity ($\bot$) \\
lcp@111
    39
  \idx{if}      & $[bool,\alpha,\alpha]\To\alpha::term$ & conditional \\
lcp@111
    40
  \idx{Inv}     & $(\alpha\To\beta)\To(\beta\To\alpha)$ & function inversion
lcp@104
    41
\end{tabular}
lcp@104
    42
\end{center}
lcp@104
    43
\subcaption{Constants}
lcp@104
    44
lcp@104
    45
\index{"@@{\tt\at}}
lcp@104
    46
\begin{center}
lcp@104
    47
\begin{tabular}{llrrr} 
lcp@111
    48
  \it symbol &\it name     &\it meta-type & \it prec & \it description \\
lcp@104
    49
  \tt\at   & \idx{Eps}  & $(\alpha\To bool)\To\alpha::term$ & 10 & 
lcp@111
    50
        Hilbert description ($\epsilon$) \\
lcp@104
    51
  \idx{!}  & \idx{All}  & $(\alpha::term\To bool)\To bool$ & 10 & 
lcp@111
    52
        universal quantifier ($\forall$) \\
lcp@104
    53
  \idx{?}  & \idx{Ex}   & $(\alpha::term\To bool)\To bool$ & 10 & 
lcp@111
    54
        existential quantifier ($\exists$) \\
lcp@104
    55
  \idx{?!} & \idx{Ex1}  & $(\alpha::term\To bool)\To bool$ & 10 & 
lcp@111
    56
        unique existence ($\exists!$)
lcp@104
    57
\end{tabular}
lcp@104
    58
\end{center}
lcp@104
    59
\subcaption{Binders} 
lcp@104
    60
lcp@104
    61
\begin{center}
lcp@104
    62
\begin{tabular}{llrrr} 
lcp@111
    63
  \it symbol &\it name     &\it meta-type & \it prec & \it description \\
lcp@104
    64
  \idx{ALL}  & \idx{All}  & $(\alpha::term\To bool)\To bool$ & 10 & 
lcp@111
    65
        universal quantifier ($\forall$) \\
lcp@104
    66
  \idx{EX}   & \idx{Ex}   & $(\alpha::term\To bool)\To bool$ & 10 & 
lcp@111
    67
        existential quantifier ($\exists$) \\
lcp@104
    68
  \idx{EX!}  & \idx{Ex1}  & $(\alpha::term\To bool)\To bool$ & 10 & 
lcp@111
    69
        unique existence ($\exists!$)
lcp@104
    70
\end{tabular}
lcp@104
    71
\end{center}
lcp@104
    72
\subcaption{Alternative quantifiers} 
lcp@104
    73
lcp@104
    74
\begin{center}
lcp@104
    75
\indexbold{*"=}
lcp@104
    76
\indexbold{&@{\tt\&}}
lcp@104
    77
\indexbold{*"|}
lcp@104
    78
\indexbold{*"-"-">}
lcp@104
    79
\begin{tabular}{rrrr} 
lcp@111
    80
  \it symbol    & \it meta-type & \it precedence & \it description \\ 
lcp@111
    81
  \idx{o}       & $[\beta\To\gamma,\alpha\To\beta]\To (\alpha\To\gamma)$ & 
lcp@111
    82
        Right 50 & composition ($\circ$) \\
lcp@111
    83
  \tt =         & $[\alpha::term,\alpha]\To bool$ & Left 50 & equality ($=$) \\
lcp@111
    84
  \tt \&        & $[bool,bool]\To bool$ & Right 35 & conjunction ($\conj$) \\
lcp@111
    85
  \tt |         & $[bool,bool]\To bool$ & Right 30 & disjunction ($\disj$) \\
lcp@111
    86
  \tt -->       & $[bool,bool]\To bool$ & Right 25 & implication ($\imp$) \\
lcp@111
    87
  \tt <         & $[\alpha::ord,\alpha]\To bool$ & Left 50 & less than ($<$) \\
lcp@111
    88
  \tt <=        & $[\alpha::ord,\alpha]\To bool$ & Left 50 & 
lcp@111
    89
                less than or equals ($\leq$)
lcp@104
    90
\end{tabular}
lcp@104
    91
\end{center}
lcp@104
    92
\subcaption{Infixes}
lcp@104
    93
\caption{Syntax of {\tt HOL}} \label{hol-constants}
lcp@104
    94
\end{figure}
lcp@104
    95
lcp@104
    96
lcp@104
    97
\begin{figure} 
lcp@104
    98
\dquotes
lcp@104
    99
\[\begin{array}{rcl}
lcp@104
   100
    term & = & \hbox{expression of class~$term$} \\
lcp@111
   101
         & | & "\at~~" id~id^* " . " formula \\[2ex]
lcp@104
   102
 formula & = & \hbox{expression of type~$bool$} \\
lcp@111
   103
         & | & term " = " term \\
lcp@111
   104
         & | & term " \ttilde= " term \\
lcp@111
   105
         & | & term " < " term \\
lcp@111
   106
         & | & term " <= " term \\
lcp@111
   107
         & | & "\ttilde\ " formula \\
lcp@111
   108
         & | & formula " \& " formula \\
lcp@111
   109
         & | & formula " | " formula \\
lcp@111
   110
         & | & formula " --> " formula \\
lcp@111
   111
         & | & "!~~~" id~id^* " . " formula \\
lcp@111
   112
         & | & "?~~~" id~id^* " . " formula \\
lcp@111
   113
         & | & "?!~~" id~id^* " . " formula \\
lcp@111
   114
         & | & "ALL~" id~id^* " . " formula \\
lcp@111
   115
         & | & "EX~~" id~id^* " . " formula \\
lcp@111
   116
         & | & "EX!~" id~id^* " . " formula
lcp@104
   117
  \end{array}
lcp@104
   118
\]
lcp@104
   119
\subcaption{Grammar}
lcp@104
   120
\caption{Full grammar for {\HOL}} \label{hol-grammar}
lcp@104
   121
\end{figure} 
lcp@104
   122
lcp@104
   123
lcp@104
   124
\section{Syntax}
lcp@104
   125
Type inference is automatic, exploiting Isabelle's type classes.  The class
lcp@104
   126
of higher-order terms is called {\it term\/}; type variables range over
lcp@104
   127
this class by default.  The equality symbol and quantifiers are polymorphic
lcp@104
   128
over class {\it term}.  
lcp@104
   129
lcp@104
   130
Class {\it ord\/} consists of all ordered types; the relations $<$ and
lcp@104
   131
$\leq$ are polymorphic over this class, as are the functions
lcp@104
   132
\ttindex{mono}, \ttindex{min} and \ttindex{max}.  Three other
lcp@104
   133
type classes --- {\it plus}, {\it minus\/} and {\it times} --- permit
lcp@104
   134
overloading of the operators {\tt+}, {\tt-} and {\tt*}.  In particular,
lcp@104
   135
{\tt-} is overloaded for set difference and subtraction.
lcp@104
   136
\index{*"+}\index{-@{\tt-}}\index{*@{\tt*}}
lcp@104
   137
lcp@104
   138
Figure~\ref{hol-constants} lists the constants (including infixes and
lcp@104
   139
binders), while Figure~\ref{hol-grammar} presents the grammar.  Note that
lcp@104
   140
$a$\verb|~=|$b$ is translated to \verb|~(|$a$=$b$\verb|)|.
lcp@104
   141
lcp@104
   142
\subsection{Types}
lcp@104
   143
The type of formulae, {\it bool} belongs to class {\it term}; thus,
lcp@104
   144
formulae are terms.  The built-in type~$fun$, which constructs function
lcp@104
   145
types, is overloaded such that $\sigma\To\tau$ belongs to class~$term$ if
lcp@104
   146
$\sigma$ and~$\tau$ do; this allows quantification over functions.  Types
lcp@104
   147
in {\HOL} must be non-empty because of the form of quantifier
lcp@104
   148
rules~\cite[\S7]{paulson-COLOG}.
lcp@104
   149
lcp@104
   150
Gordon's {\sc hol} system supports {\bf type definitions}.  A type is
lcp@104
   151
defined by exhibiting an existing type~$\sigma$, a predicate~$P::\sigma\To
lcp@104
   152
bool$, and a theorem of the form $\exists x::\sigma.P(x)$.  Thus~$P$
lcp@104
   153
specifies a non-empty subset of~$\sigma$, and the new type denotes this
lcp@104
   154
subset.  New function constants are generated to establish an isomorphism
lcp@104
   155
between the new type and the subset.  If type~$\sigma$ involves type
lcp@104
   156
variables $\alpha@1$, \ldots, $\alpha@n$, then the type definition creates
lcp@104
   157
a type constructor $(\alpha@1,\ldots,\alpha@n)ty$ rather than a particular
lcp@104
   158
type.
lcp@104
   159
lcp@104
   160
Isabelle does not support type definitions at present.  Instead, they are
lcp@104
   161
mimicked by explicit definitions of isomorphism functions.  These should be
lcp@104
   162
accompanied by theorems of the form $\exists x::\sigma.P(x)$, but this is
lcp@104
   163
not checked.
lcp@104
   164
lcp@104
   165
lcp@104
   166
\subsection{Binders}
lcp@104
   167
Hilbert's {\bf description} operator~$\epsilon x.P[x]$ stands for some~$a$
lcp@104
   168
satisfying~$P[a]$, if such exists.  Since all terms in {\HOL} denote
lcp@104
   169
something, a description is always meaningful, but we do not know its value
lcp@104
   170
unless $P[x]$ defines it uniquely.  We may write descriptions as
lcp@104
   171
\ttindexbold{Eps}($P$) or use the syntax
lcp@104
   172
\hbox{\tt \at $x$.$P[x]$}.  Existential quantification is defined
lcp@104
   173
by
lcp@104
   174
\[ \exists x.P(x) \equiv P(\epsilon x.P(x)) \]
lcp@104
   175
The unique existence quantifier, $\exists!x.P[x]$, is defined in terms
lcp@104
   176
of~$\exists$ and~$\forall$.  An Isabelle binder, it admits nested
lcp@104
   177
quantifications.  For instance, $\exists!x y.P(x,y)$ abbreviates
lcp@104
   178
$\exists!x. \exists!y.P(x,y)$; note that this does not mean that there
lcp@104
   179
exists a unique pair $(x,y)$ satisfying~$P(x,y)$.
lcp@104
   180
lcp@104
   181
\index{*"!}\index{*"?}
lcp@104
   182
Quantifiers have two notations.  As in Gordon's {\sc hol} system, {\HOL}
lcp@104
   183
uses~{\tt!}\ and~{\tt?}\ to stand for $\forall$ and $\exists$.  The
lcp@104
   184
existential quantifier must be followed by a space; thus {\tt?x} is an
lcp@104
   185
unknown, while \verb'? x.f(x)=y' is a quantification.  Isabelle's usual
lcp@104
   186
notation for quantifiers, \ttindex{ALL} and \ttindex{EX}, is also
lcp@104
   187
available.  Both notations are accepted for input.  The {\ML} reference
lcp@104
   188
\ttindexbold{HOL_quantifiers} governs the output notation.  If set to {\tt
lcp@104
   189
true}, then~{\tt!}\ and~{\tt?}\ are displayed; this is the default.  If set
lcp@104
   190
to {\tt false}, then~{\tt ALL} and~{\tt EX} are displayed.
lcp@104
   191
lcp@104
   192
\begin{warn}
lcp@104
   193
Although the description operator does not usually allow iteration of the
lcp@104
   194
form \hbox{\tt \at $x@1 \dots x@n$.$P[x@1,\dots,x@n]$}, there are cases where
lcp@104
   195
this is legal.  If \hbox{\tt \at $y$.$P[x,y]$} is of type~{\it bool},
lcp@104
   196
then \hbox{\tt \at $x\,y$.$P[x,y]$} is legal.  The pretty printer will
lcp@104
   197
display \hbox{\tt \at $x$.\at $y$.$P[x,y]$} as
lcp@104
   198
\hbox{\tt \at $x\,y$.$P[x,y]$}.
lcp@104
   199
\end{warn}
lcp@104
   200
lcp@104
   201
\begin{figure} \makeatother
lcp@104
   202
\begin{ttbox}
lcp@104
   203
\idx{refl}           t = t::'a
lcp@104
   204
\idx{subst}          [| s=t; P(s) |] ==> P(t::'a)
lcp@104
   205
\idx{ext}            (!!x::'a. f(x)::'b = g(x)) ==> (%x.f(x)) = (%x.g(x))
lcp@104
   206
\idx{impI}           (P ==> Q) ==> P-->Q
lcp@104
   207
\idx{mp}             [| P-->Q;  P |] ==> Q
lcp@104
   208
\idx{iff}            (P-->Q) --> (Q-->P) --> (P=Q)
lcp@104
   209
\idx{selectI}        P(x::'a) ==> P(@x.P(x))
lcp@104
   210
\idx{True_or_False}  (P=True) | (P=False)
lcp@104
   211
\subcaption{basic rules}
lcp@104
   212
lcp@104
   213
\idx{True_def}       True  = ((%x.x)=(%x.x))
lcp@104
   214
\idx{All_def}        All   = (%P. P = (%x.True))
lcp@104
   215
\idx{Ex_def}         Ex    = (%P. P(@x.P(x)))
lcp@104
   216
\idx{False_def}      False = (!P.P)
lcp@104
   217
\idx{not_def}        not   = (%P. P-->False)
lcp@104
   218
\idx{and_def}        op &  = (%P Q. !R. (P-->Q-->R) --> R)
lcp@104
   219
\idx{or_def}         op |  = (%P Q. !R. (P-->R) --> (Q-->R) --> R)
lcp@104
   220
\idx{Ex1_def}        Ex1   = (%P. ? x. P(x) & (! y. P(y) --> y=x))
lcp@104
   221
\subcaption{Definitions of the logical constants}
lcp@104
   222
lcp@104
   223
\idx{Inv_def}   Inv  = (%(f::'a=>'b) y. @x. f(x)=y)
lcp@104
   224
\idx{o_def}     op o = (%(f::'b=>'c) g (x::'a). f(g(x)))
lcp@104
   225
\idx{if_def}    if   = (%P x y.@z::'a.(P=True --> z=x) & (P=False --> z=y))
lcp@104
   226
\subcaption{Further definitions}
lcp@104
   227
\end{ttbox}
lcp@104
   228
\caption{Rules of {\tt HOL}} \label{hol-rules}
lcp@104
   229
\end{figure}
lcp@104
   230
lcp@104
   231
lcp@104
   232
\begin{figure} \makeatother
lcp@104
   233
\begin{ttbox}
lcp@104
   234
\idx{sym}         s=t ==> t=s
lcp@104
   235
\idx{trans}       [| r=s; s=t |] ==> r=t
lcp@104
   236
\idx{ssubst}      [| t=s; P(s) |] ==> P(t::'a)
lcp@104
   237
\idx{box_equals}  [| a=b;  a=c;  b=d |] ==> c=d  
lcp@104
   238
\idx{arg_cong}    s=t ==> f(s)=f(t)
lcp@104
   239
\idx{fun_cong}    s::'a=>'b = t ==> s(x)=t(x)
lcp@104
   240
\subcaption{Equality}
lcp@104
   241
lcp@104
   242
\idx{TrueI}       True 
lcp@104
   243
\idx{FalseE}      False ==> P
lcp@104
   244
lcp@104
   245
\idx{conjI}       [| P; Q |] ==> P&Q
lcp@104
   246
\idx{conjunct1}   [| P&Q |] ==> P
lcp@104
   247
\idx{conjunct2}   [| P&Q |] ==> Q 
lcp@104
   248
\idx{conjE}       [| P&Q;  [| P; Q |] ==> R |] ==> R
lcp@104
   249
lcp@104
   250
\idx{disjI1}      P ==> P|Q
lcp@104
   251
\idx{disjI2}      Q ==> P|Q
lcp@104
   252
\idx{disjE}       [| P | Q; P ==> R; Q ==> R |] ==> R
lcp@104
   253
lcp@104
   254
\idx{notI}        (P ==> False) ==> ~ P
lcp@104
   255
\idx{notE}        [| ~ P;  P |] ==> R
lcp@104
   256
\idx{impE}        [| P-->Q;  P;  Q ==> R |] ==> R
lcp@104
   257
\subcaption{Propositional logic}
lcp@104
   258
lcp@104
   259
\idx{iffI}        [| P ==> Q;  Q ==> P |] ==> P=Q
lcp@104
   260
\idx{iffD1}       [| P=Q; P |] ==> Q
lcp@104
   261
\idx{iffD2}       [| P=Q; Q |] ==> P
lcp@104
   262
\idx{iffE}        [| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R
lcp@104
   263
lcp@104
   264
\idx{eqTrueI}     P ==> P=True 
lcp@104
   265
\idx{eqTrueE}     P=True ==> P 
lcp@104
   266
\subcaption{Logical equivalence}
lcp@104
   267
lcp@104
   268
\end{ttbox}
lcp@104
   269
\caption{Derived rules for {\HOL}} \label{hol-lemmas1}
lcp@104
   270
\end{figure}
lcp@104
   271
lcp@104
   272
lcp@104
   273
\begin{figure} \makeatother
lcp@104
   274
\begin{ttbox}
lcp@104
   275
\idx{allI}      (!!x::'a. P(x)) ==> !x. P(x)
lcp@104
   276
\idx{spec}      !x::'a.P(x) ==> P(x)
lcp@104
   277
\idx{allE}      [| !x.P(x);  P(x) ==> R |] ==> R
lcp@104
   278
\idx{all_dupE}  [| !x.P(x);  [| P(x); !x.P(x) |] ==> R |] ==> R
lcp@104
   279
lcp@104
   280
\idx{exI}       P(x) ==> ? x::'a.P(x)
lcp@104
   281
\idx{exE}       [| ? x::'a.P(x); !!x. P(x) ==> Q |] ==> Q
lcp@104
   282
lcp@104
   283
\idx{ex1I}      [| P(a);  !!x. P(x) ==> x=a |] ==> ?! x. P(x)
lcp@104
   284
\idx{ex1E}      [| ?! x.P(x);  !!x. [| P(x);  ! y. P(y) --> y=x |] ==> R 
lcp@104
   285
          |] ==> R
lcp@104
   286
lcp@104
   287
\idx{select_equality}  [| P(a);  !!x. P(x) ==> x=a |] ==> (@x.P(x)) = a
lcp@104
   288
\subcaption{Quantifiers and descriptions}
lcp@104
   289
lcp@104
   290
\idx{ccontr}             (~P ==> False) ==> P
lcp@104
   291
\idx{classical}          (~P ==> P) ==> P
lcp@104
   292
\idx{excluded_middle}    ~P | P
lcp@104
   293
lcp@104
   294
\idx{disjCI}    (~Q ==> P) ==> P|Q
lcp@104
   295
\idx{exCI}      (! x. ~ P(x) ==> P(a)) ==> ? x.P(x)
lcp@104
   296
\idx{impCE}     [| P-->Q; ~ P ==> R; Q ==> R |] ==> R
lcp@104
   297
\idx{iffCE}     [| P<->Q;  [| P; Q |] ==> R;  [| ~P; ~Q |] ==> R |] ==> R
lcp@104
   298
\idx{notnotD}   ~~P ==> P
lcp@104
   299
\idx{swap}      ~P ==> (~Q ==> P) ==> Q
lcp@104
   300
\subcaption{Classical logic}
lcp@104
   301
lcp@104
   302
\idx{if_True}    if(True,x,y) = x
lcp@104
   303
\idx{if_False}   if(False,x,y) = y
lcp@104
   304
\idx{if_P}       P ==> if(P,x,y) = x
lcp@104
   305
\idx{if_not_P}   ~ P ==> if(P,x,y) = y
lcp@104
   306
\idx{expand_if}  P(if(Q,x,y)) = ((Q --> P(x)) & (~Q --> P(y)))
lcp@104
   307
\subcaption{Conditionals}
lcp@104
   308
\end{ttbox}
lcp@104
   309
\caption{More derived rules} \label{hol-lemmas2}
lcp@104
   310
\end{figure}
lcp@104
   311
lcp@104
   312
lcp@104
   313
\section{Rules of inference}
lcp@104
   314
The basic theory has the {\ML} identifier \ttindexbold{HOL.thy}.  However,
lcp@104
   315
many further theories are defined, introducing product and sum types, the
lcp@104
   316
natural numbers, etc.
lcp@104
   317
lcp@104
   318
Figure~\ref{hol-rules} shows the inference rules with their~{\ML} names.
lcp@104
   319
They follow standard practice in higher-order logic: only a few connectives
lcp@104
   320
are taken as primitive, with the remainder defined obscurely.  
lcp@104
   321
lcp@104
   322
Unusually, the definitions use object-equality~({\tt=}) rather than
lcp@104
   323
meta-equality~({\tt==}).  This is possible because equality in higher-order
lcp@104
   324
logic may equate formulae and even functions over formulae.  On the other
lcp@104
   325
hand, meta-equality is Isabelle's usual symbol for making definitions.
lcp@104
   326
Take care to note which form of equality is used before attempting a proof.
lcp@104
   327
lcp@104
   328
Some of the rules mention type variables; for example, {\tt refl} mentions
lcp@104
   329
the type variable~{\tt'a}.  This facilitates explicit instantiation of the
lcp@104
   330
type variables.  By default, such variables range over class {\it term}.  
lcp@104
   331
lcp@104
   332
\begin{warn}
lcp@104
   333
Where function types are involved, Isabelle's unification code does not
lcp@104
   334
guarantee to find instantiations for type variables automatically.  If
lcp@104
   335
resolution fails for no obvious reason, try setting \ttindex{show_types} to
lcp@104
   336
{\tt true}, causing Isabelle to display types of terms.  (Possibly, set
lcp@104
   337
\ttindex{show_sorts} to {\tt true} also, causing Isabelle to display sorts.)
lcp@104
   338
Be prepared to use \ttindex{res_inst_tac} instead of {\tt resolve_tac}.
lcp@104
   339
Setting \ttindex{Unify.trace_types} to {\tt true} causes Isabelle to
lcp@104
   340
report omitted search paths during unification.
lcp@104
   341
\end{warn}
lcp@104
   342
lcp@104
   343
Here are further comments on the rules:
lcp@104
   344
\begin{description}
lcp@104
   345
\item[\ttindexbold{ext}] 
lcp@104
   346
expresses extensionality of functions.
lcp@104
   347
\item[\ttindexbold{iff}] 
lcp@104
   348
asserts that logically equivalent formulae are equal.
lcp@104
   349
\item[\ttindexbold{selectI}] 
lcp@104
   350
gives the defining property of the Hilbert $\epsilon$-operator.  The
lcp@104
   351
derived rule \ttindexbold{select_equality} (see below) is often easier to use.
lcp@104
   352
\item[\ttindexbold{True_or_False}] 
lcp@104
   353
makes the logic classical.\footnote{In fact, the $\epsilon$-operator
lcp@104
   354
already makes the logic classical, as shown by Diaconescu;
lcp@104
   355
see Paulson~\cite{paulson-COLOG} for details.}
lcp@104
   356
\end{description}
lcp@104
   357
lcp@104
   358
\begin{warn}
lcp@104
   359
{\HOL} has no if-and-only-if connective; logical equivalence is expressed
lcp@104
   360
using equality.  But equality has a high precedence, as befitting a
lcp@104
   361
relation, while if-and-only-if typically has the lowest precedence.  Thus,
lcp@104
   362
$\neg\neg P=P$ abbreviates $\neg\neg (P=P)$ and not $(\neg\neg P)=P$.  When
lcp@104
   363
using $=$ to mean logical equivalence, enclose both operands in
lcp@104
   364
parentheses.
lcp@104
   365
\end{warn}
lcp@104
   366
lcp@104
   367
Some derived rules are shown in Figures~\ref{hol-lemmas1}
lcp@104
   368
and~\ref{hol-lemmas2}, with their {\ML} names.  These include natural rules
lcp@104
   369
for the logical connectives, as well as sequent-style elimination rules for
lcp@104
   370
conjunctions, implications, and universal quantifiers.  
lcp@104
   371
lcp@104
   372
Note the equality rules: \ttindexbold{ssubst} performs substitution in
lcp@104
   373
backward proofs, while \ttindexbold{box_equals} supports reasoning by
lcp@104
   374
simplifying both sides of an equation.
lcp@104
   375
lcp@104
   376
See the files \ttindexbold{HOL/hol.thy} and
lcp@104
   377
\ttindexbold{HOL/hol.ML} for complete listings of the rules and
lcp@104
   378
derived rules.
lcp@104
   379
lcp@104
   380
lcp@104
   381
\section{Generic packages}
lcp@104
   382
{\HOL} instantiates most of Isabelle's generic packages;
lcp@104
   383
see \ttindexbold{HOL/ROOT.ML} for details.
lcp@104
   384
\begin{itemize}
lcp@104
   385
\item 
lcp@104
   386
Because it includes a general substitution rule, {\HOL} instantiates the
lcp@104
   387
tactic \ttindex{hyp_subst_tac}, which substitutes for an equality
lcp@104
   388
throughout a subgoal and its hypotheses.
lcp@104
   389
\item 
lcp@104
   390
It instantiates the simplifier, defining~\ttindexbold{HOL_ss} as the
lcp@104
   391
simplification set for higher-order logic.  Equality~($=$), which also
lcp@104
   392
expresses logical equivalence, may be used for rewriting.  See the file
lcp@104
   393
\ttindexbold{HOL/simpdata.ML} for a complete listing of the simplification
lcp@104
   394
rules. 
lcp@104
   395
\item 
lcp@104
   396
It instantiates the classical reasoning module.  See~\S\ref{hol-cla-prover}
lcp@104
   397
for details. 
lcp@104
   398
\end{itemize}
lcp@104
   399
lcp@104
   400
lcp@104
   401
\begin{figure} 
lcp@104
   402
\begin{center}
lcp@104
   403
\begin{tabular}{rrr} 
lcp@111
   404
  \it name      &\it meta-type  & \it description \\ 
lcp@104
   405
\index{"{"}@{\tt\{\}}}
lcp@111
   406
  {\tt\{\}}     & $\alpha\,set$         & the empty set \\
lcp@111
   407
  \idx{insert}  & $[\alpha,\alpha\,set]\To \alpha\,set$
lcp@111
   408
        & insertion of element \\
lcp@111
   409
  \idx{Collect} & $(\alpha\To bool)\To\alpha\,set$
lcp@111
   410
        & comprehension \\
lcp@111
   411
  \idx{Compl}   & $(\alpha\,set)\To\alpha\,set$
lcp@111
   412
        & complement \\
lcp@104
   413
  \idx{INTER} & $[\alpha\,set,\alpha\To\beta\,set]\To\beta\,set$
lcp@111
   414
        & intersection over a set\\
lcp@104
   415
  \idx{UNION} & $[\alpha\,set,\alpha\To\beta\,set]\To\beta\,set$
lcp@111
   416
        & union over a set\\
lcp@104
   417
  \idx{Inter} & $((\alpha\,set)set)\To\alpha\,set$
lcp@111
   418
        &set of sets intersection \\
lcp@104
   419
  \idx{Union} & $((\alpha\,set)set)\To\alpha\,set$
lcp@111
   420
        &set of sets union \\
lcp@111
   421
  \idx{range}   & $(\alpha\To\beta )\To\beta\,set$
lcp@111
   422
        & range of a function \\[1ex]
lcp@111
   423
  \idx{Ball}~~\idx{Bex} & $[\alpha\,set,\alpha\To bool]\To bool$
lcp@111
   424
        & bounded quantifiers \\
lcp@111
   425
  \idx{mono}    & $(\alpha\,set\To\beta\,set)\To bool$
lcp@111
   426
        & monotonicity \\
lcp@104
   427
  \idx{inj}~~\idx{surj}& $(\alpha\To\beta )\To bool$
lcp@111
   428
        & injective/surjective \\
lcp@111
   429
  \idx{inj_onto}        & $[\alpha\To\beta ,\alpha\,set]\To bool$
lcp@111
   430
        & injective over subset
lcp@104
   431
\end{tabular}
lcp@104
   432
\end{center}
lcp@104
   433
\subcaption{Constants}
lcp@104
   434
lcp@104
   435
\begin{center}
lcp@104
   436
\begin{tabular}{llrrr} 
lcp@111
   437
  \it symbol &\it name     &\it meta-type & \it prec & \it description \\
lcp@104
   438
  \idx{INT}  & \idx{INTER1}  & $(\alpha\To\beta\,set)\To\beta\,set$ & 10 & 
lcp@111
   439
        intersection over a type\\
lcp@104
   440
  \idx{UN}  & \idx{UNION1}  & $(\alpha\To\beta\,set)\To\beta\,set$ & 10 & 
lcp@111
   441
        union over a type
lcp@104
   442
\end{tabular}
lcp@104
   443
\end{center}
lcp@104
   444
\subcaption{Binders} 
lcp@104
   445
lcp@104
   446
\begin{center}
lcp@104
   447
\indexbold{*"`"`}
lcp@104
   448
\indexbold{*":}
lcp@104
   449
\indexbold{*"<"=}
lcp@104
   450
\begin{tabular}{rrrr} 
lcp@111
   451
  \it symbol    & \it meta-type & \it precedence & \it description \\ 
lcp@111
   452
  \tt ``        & $[\alpha\To\beta ,\alpha\,set]\To  (\beta\,set)$
lcp@111
   453
        & Left 90 & image \\
lcp@111
   454
  \idx{Int}     & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
lcp@111
   455
        & Left 70 & intersection ($\inter$) \\
lcp@111
   456
  \idx{Un}      & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
lcp@111
   457
        & Left 65 & union ($\union$) \\
lcp@111
   458
  \tt:          & $[\alpha ,\alpha\,set]\To bool$       
lcp@111
   459
        & Left 50 & membership ($\in$) \\
lcp@111
   460
  \tt <=        & $[\alpha\,set,\alpha\,set]\To bool$
lcp@111
   461
        & Left 50 & subset ($\subseteq$) 
lcp@104
   462
\end{tabular}
lcp@104
   463
\end{center}
lcp@104
   464
\subcaption{Infixes}
lcp@104
   465
\caption{Syntax of {\HOL}'s set theory} \label{hol-set-syntax}
lcp@104
   466
\end{figure} 
lcp@104
   467
lcp@104
   468
lcp@104
   469
\begin{figure} 
lcp@104
   470
\begin{center} \tt\frenchspacing
lcp@104
   471
\begin{tabular}{rrr} 
lcp@111
   472
  \it external          & \it internal  & \it description \\ 
lcp@104
   473
  $a$ \ttilde: $b$      & \ttilde($a$ : $b$)    & \rm negated membership\\
wenzelm@154
   474
  \{$a@1$, $\ldots$, $a@n$\}  &  insert($a@1$,$\cdots$,insert($a@n$,\{\})) &
lcp@104
   475
        \rm finite set \\
lcp@111
   476
  \{$x$.$P[x]$\}        &  Collect($\lambda x.P[x]$) &
lcp@104
   477
        \rm comprehension \\
lcp@111
   478
  \idx{INT} $x$:$A$.$B[x]$      & INTER($A$,$\lambda x.B[x]$) &
lcp@111
   479
        \rm intersection over a set \\
lcp@111
   480
  \idx{UN}  $x$:$A$.$B[x]$      & UNION($A$,$\lambda x.B[x]$) &
lcp@111
   481
        \rm union over a set \\
lcp@111
   482
  \idx{!} $x$:$A$.$P[x]$        & Ball($A$,$\lambda x.P[x]$) & 
lcp@111
   483
        \rm bounded $\forall$ \\
lcp@111
   484
  \idx{?} $x$:$A$.$P[x]$        & Bex($A$,$\lambda x.P[x]$) & 
lcp@111
   485
        \rm bounded $\exists$ \\[1ex]
lcp@111
   486
  \idx{ALL} $x$:$A$.$P[x]$      & Ball($A$,$\lambda x.P[x]$) & 
lcp@111
   487
        \rm bounded $\forall$ \\
lcp@111
   488
  \idx{EX} $x$:$A$.$P[x]$       & Bex($A$,$\lambda x.P[x]$) & 
lcp@111
   489
        \rm bounded $\exists$
lcp@104
   490
\end{tabular}
lcp@104
   491
\end{center}
lcp@104
   492
\subcaption{Translations}
lcp@104
   493
lcp@104
   494
\dquotes
lcp@104
   495
\[\begin{array}{rcl}
lcp@104
   496
    term & = & \hbox{other terms\ldots} \\
lcp@111
   497
         & | & "\{\}" \\
lcp@111
   498
         & | & "\{ " term\; ("," term)^* " \}" \\
lcp@111
   499
         & | & "\{ " id " . " formula " \}" \\
lcp@111
   500
         & | & term " `` " term \\
lcp@111
   501
         & | & term " Int " term \\
lcp@111
   502
         & | & term " Un " term \\
lcp@111
   503
         & | & "INT~~"  id ":" term " . " term \\
lcp@111
   504
         & | & "UN~~~"  id ":" term " . " term \\
lcp@111
   505
         & | & "INT~~"  id~id^* " . " term \\
lcp@111
   506
         & | & "UN~~~"  id~id^* " . " term \\[2ex]
lcp@104
   507
 formula & = & \hbox{other formulae\ldots} \\
lcp@111
   508
         & | & term " : " term \\
lcp@111
   509
         & | & term " \ttilde: " term \\
lcp@111
   510
         & | & term " <= " term \\
lcp@111
   511
         & | & "!~~~" id ":" term " . " formula \\
lcp@111
   512
         & | & "?~~~" id ":" term " . " formula \\
lcp@111
   513
         & | & "ALL " id ":" term " . " formula \\
lcp@111
   514
         & | & "EX~~" id ":" term " . " formula
lcp@104
   515
  \end{array}
lcp@104
   516
\]
lcp@104
   517
\subcaption{Full Grammar}
lcp@104
   518
\caption{Syntax of {\HOL}'s set theory (continued)} \label{hol-set-syntax2}
lcp@104
   519
\end{figure} 
lcp@104
   520
lcp@104
   521
lcp@104
   522
\begin{figure} \makeatother
lcp@104
   523
\begin{ttbox}
lcp@104
   524
\idx{mem_Collect_eq}    (a : \{x.P(x)\}) = P(a)
lcp@104
   525
\idx{Collect_mem_eq}    \{x.x:A\} = A
lcp@104
   526
\subcaption{Isomorphisms between predicates and sets}
lcp@104
   527
wenzelm@154
   528
\idx{empty_def}         \{\}          == \{x.x=False\}
lcp@104
   529
\idx{insert_def}        insert(a,B) == \{x.x=a\} Un B
lcp@104
   530
\idx{Ball_def}          Ball(A,P)   == ! x. x:A --> P(x)
lcp@104
   531
\idx{Bex_def}           Bex(A,P)    == ? x. x:A & P(x)
lcp@104
   532
\idx{subset_def}        A <= B      == ! x:A. x:B
lcp@104
   533
\idx{Un_def}            A Un B      == \{x.x:A | x:B\}
lcp@104
   534
\idx{Int_def}           A Int B     == \{x.x:A & x:B\}
lcp@104
   535
\idx{set_diff_def}      A - B       == \{x.x:A & x~:B\}
lcp@104
   536
\idx{Compl_def}         Compl(A)    == \{x. ~ x:A\}
lcp@104
   537
\idx{INTER_def}         INTER(A,B)  == \{y. ! x:A. y: B(x)\}
lcp@104
   538
\idx{UNION_def}         UNION(A,B)  == \{y. ? x:A. y: B(x)\}
lcp@104
   539
\idx{INTER1_def}        INTER1(B)   == INTER(\{x.True\}, B)
lcp@104
   540
\idx{UNION1_def}        UNION1(B)   == UNION(\{x.True\}, B)
lcp@104
   541
\idx{Inter_def}         Inter(S)    == (INT x:S. x)
lcp@104
   542
\idx{Union_def}         Union(S)    ==  (UN x:S. x)
lcp@104
   543
\idx{image_def}         f``A        == \{y. ? x:A. y=f(x)\}
lcp@104
   544
\idx{range_def}         range(f)    == \{y. ? x. y=f(x)\}
lcp@104
   545
\idx{mono_def}          mono(f)     == !A B. A <= B --> f(A) <= f(B)
lcp@104
   546
\idx{inj_def}           inj(f)      == ! x y. f(x)=f(y) --> x=y
lcp@104
   547
\idx{surj_def}          surj(f)     == ! y. ? x. y=f(x)
lcp@104
   548
\idx{inj_onto_def}      inj_onto(f,A) == !x:A. !y:A. f(x)=f(y) --> x=y
lcp@104
   549
\subcaption{Definitions}
lcp@104
   550
\end{ttbox}
lcp@104
   551
\caption{Rules of {\HOL}'s set theory} \label{hol-set-rules}
lcp@104
   552
\end{figure}
lcp@104
   553
lcp@104
   554
lcp@104
   555
\begin{figure} \makeatother
lcp@104
   556
\begin{ttbox}
lcp@104
   557
\idx{CollectI}      [| P(a) |] ==> a : \{x.P(x)\}
lcp@104
   558
\idx{CollectD}      [| a : \{x.P(x)\} |] ==> P(a)
lcp@104
   559
\idx{CollectE}      [| a : \{x.P(x)\};  P(a) ==> W |] ==> W
lcp@104
   560
\idx{Collect_cong}  [| !!x. P(x)=Q(x) |] ==> \{x. P(x)\} = \{x. Q(x)\}
lcp@104
   561
\subcaption{Comprehension}
lcp@104
   562
lcp@104
   563
\idx{ballI}         [| !!x. x:A ==> P(x) |] ==> ! x:A. P(x)
lcp@104
   564
\idx{bspec}         [| ! x:A. P(x);  x:A |] ==> P(x)
lcp@104
   565
\idx{ballE}         [| ! x:A. P(x);  P(x) ==> Q;  ~ x:A ==> Q |] ==> Q
lcp@104
   566
\idx{ball_cong}     [| A=A';  !!x. x:A' ==> P(x) = P'(x) |] ==>
lcp@104
   567
              (! x:A. P(x)) = (! x:A'. P'(x))
lcp@104
   568
lcp@104
   569
\idx{bexI}          [| P(x);  x:A |] ==> ? x:A. P(x)
lcp@104
   570
\idx{bexCI}         [| ! x:A. ~ P(x) ==> P(a);  a:A |] ==> ? x:A.P(x)
lcp@104
   571
\idx{bexE}          [| ? x:A. P(x);  !!x. [| x:A; P(x) |] ==> Q  |] ==> Q
lcp@104
   572
\subcaption{Bounded quantifiers}
lcp@104
   573
lcp@104
   574
\idx{subsetI}         (!!x.x:A ==> x:B) ==> A <= B
lcp@104
   575
\idx{subsetD}         [| A <= B;  c:A |] ==> c:B
lcp@104
   576
\idx{subsetCE}        [| A <= B;  ~ (c:A) ==> P;  c:B ==> P |] ==> P
lcp@104
   577
lcp@104
   578
\idx{subset_refl}     A <= A
lcp@104
   579
\idx{subset_antisym}  [| A <= B;  B <= A |] ==> A = B
lcp@104
   580
\idx{subset_trans}    [| A<=B;  B<=C |] ==> A<=C
lcp@104
   581
lcp@104
   582
\idx{set_ext}         [| !!x. (x:A) = (x:B) |] ==> A = B
lcp@104
   583
\idx{equalityD1}      A = B ==> A<=B
lcp@104
   584
\idx{equalityD2}      A = B ==> B<=A
lcp@104
   585
\idx{equalityE}       [| A = B;  [| A<=B; B<=A |] ==> P |]  ==>  P
lcp@104
   586
lcp@104
   587
\idx{equalityCE}      [| A = B;  [| c:A; c:B |] ==> P;  
lcp@104
   588
                           [| ~ c:A; ~ c:B |] ==> P 
lcp@104
   589
                |]  ==>  P
lcp@104
   590
\subcaption{The subset and equality relations}
lcp@104
   591
\end{ttbox}
lcp@104
   592
\caption{Derived rules for set theory} \label{hol-set1}
lcp@104
   593
\end{figure}
lcp@104
   594
lcp@104
   595
lcp@104
   596
\begin{figure} \makeatother
lcp@104
   597
\begin{ttbox}
lcp@104
   598
\idx{emptyE}   a : \{\} ==> P
lcp@104
   599
lcp@104
   600
\idx{insertI1} a : insert(a,B)
lcp@104
   601
\idx{insertI2} a : B ==> a : insert(b,B)
lcp@114
   602
\idx{insertE}  [| a : insert(b,A);  a=b ==> P;  a:A ==> P |] ==> P
lcp@104
   603
lcp@104
   604
\idx{ComplI}   [| c:A ==> False |] ==> c : Compl(A)
lcp@104
   605
\idx{ComplD}   [| c : Compl(A) |] ==> ~ c:A
lcp@104
   606
lcp@104
   607
\idx{UnI1}     c:A ==> c : A Un B
lcp@104
   608
\idx{UnI2}     c:B ==> c : A Un B
lcp@104
   609
\idx{UnCI}     (~c:B ==> c:A) ==> c : A Un B
lcp@104
   610
\idx{UnE}      [| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P
lcp@104
   611
lcp@104
   612
\idx{IntI}     [| c:A;  c:B |] ==> c : A Int B
lcp@104
   613
\idx{IntD1}    c : A Int B ==> c:A
lcp@104
   614
\idx{IntD2}    c : A Int B ==> c:B
lcp@104
   615
\idx{IntE}     [| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P
lcp@104
   616
lcp@104
   617
\idx{UN_I}     [| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))
lcp@104
   618
\idx{UN_E}     [| b: (UN x:A. B(x));  !!x.[| x:A;  b:B(x) |] ==> R |] ==> R
lcp@104
   619
lcp@104
   620
\idx{INT_I}    (!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))
lcp@104
   621
\idx{INT_D}    [| b: (INT x:A. B(x));  a:A |] ==> b: B(a)
lcp@104
   622
\idx{INT_E}    [| b: (INT x:A. B(x));  b: B(a) ==> R;  ~ a:A ==> R |] ==> R
lcp@104
   623
lcp@104
   624
\idx{UnionI}   [| X:C;  A:X |] ==> A : Union(C)
lcp@104
   625
\idx{UnionE}   [| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R
lcp@104
   626
lcp@104
   627
\idx{InterI}   [| !!X. X:C ==> A:X |] ==> A : Inter(C)
lcp@104
   628
\idx{InterD}   [| A : Inter(C);  X:C |] ==> A:X
lcp@104
   629
\idx{InterE}   [| A : Inter(C);  A:X ==> R;  ~ X:C ==> R |] ==> R
lcp@104
   630
\end{ttbox}
lcp@104
   631
\caption{Further derived rules for set theory} \label{hol-set2}
lcp@104
   632
\end{figure}
lcp@104
   633
lcp@104
   634
lcp@104
   635
\section{A formulation of set theory}
lcp@104
   636
Historically, higher-order logic gives a foundation for Russell and
lcp@104
   637
Whitehead's theory of classes.  Let us use modern terminology and call them
lcp@104
   638
{\bf sets}, but note that these sets are distinct from those of {\ZF} set
lcp@104
   639
theory, and behave more like {\ZF} classes.
lcp@104
   640
\begin{itemize}
lcp@104
   641
\item
lcp@104
   642
Sets are given by predicates over some type~$\sigma$.  Types serve to
lcp@104
   643
define universes for sets, but type checking is still significant.
lcp@104
   644
\item
lcp@104
   645
There is a universal set (for each type).  Thus, sets have complements, and
lcp@104
   646
may be defined by absolute comprehension.
lcp@104
   647
\item
lcp@104
   648
Although sets may contain other sets as elements, the containing set must
lcp@104
   649
have a more complex type.
lcp@104
   650
\end{itemize}
lcp@104
   651
Finite unions and intersections have the same behaviour in {\HOL} as they
lcp@104
   652
do in~{\ZF}.  In {\HOL} the intersection of the empty set is well-defined,
lcp@104
   653
denoting the universal set for the given type.
lcp@104
   654
lcp@104
   655
\subsection{Syntax of set theory}
lcp@104
   656
The type $\alpha\,set$ is essentially the same as $\alpha\To bool$.  The new
lcp@104
   657
type is defined for clarity and to avoid complications involving function
lcp@104
   658
types in unification.  Since Isabelle does not support type definitions (as
lcp@104
   659
discussed above), the isomorphisms between the two types are declared
lcp@104
   660
explicitly.  Here they are natural: {\tt Collect} maps $\alpha\To bool$ to
lcp@104
   661
$\alpha\,set$, while \hbox{\tt op :} maps in the other direction (ignoring
lcp@104
   662
argument order).  
lcp@104
   663
lcp@104
   664
Figure~\ref{hol-set-syntax} lists the constants, infixes, and syntax
lcp@104
   665
translations.  Figure~\ref{hol-set-syntax2} presents the grammar of the new
lcp@104
   666
constructs.  Infix operators include union and intersection ($A\union B$
lcp@104
   667
and $A\inter B$), the subset and membership relations, and the image
lcp@104
   668
operator~{\tt``}.  Note that $a$\verb|~:|$b$ is translated to
lcp@104
   669
\verb|~(|$a$:$b$\verb|)|.  The {\tt\{\ldots\}} notation abbreviates finite
lcp@104
   670
sets constructed in the obvious manner using~{\tt insert} and~$\{\}$ (the
lcp@104
   671
empty set):
lcp@104
   672
\begin{eqnarray*}
wenzelm@154
   673
 \{a,b,c\} & \equiv & {\tt insert}(a,{\tt insert}(b,{\tt insert}(c,\{\})))
lcp@104
   674
\end{eqnarray*}
lcp@104
   675
lcp@104
   676
The set \hbox{\tt\{$x$.$P[x]$\}} consists of all $x$ (of suitable type)
lcp@104
   677
that satisfy~$P[x]$, where $P[x]$ is a formula that may contain free
lcp@104
   678
occurrences of~$x$.  This syntax expands to \ttindexbold{Collect}$(\lambda
lcp@104
   679
x.P[x])$. 
lcp@104
   680
lcp@104
   681
The set theory defines two {\bf bounded quantifiers}:
lcp@104
   682
\begin{eqnarray*}
lcp@104
   683
   \forall x\in A.P[x] &\hbox{which abbreviates}& \forall x. x\in A\imp P[x] \\
lcp@104
   684
   \exists x\in A.P[x] &\hbox{which abbreviates}& \exists x. x\in A\conj P[x]
lcp@104
   685
\end{eqnarray*}
lcp@104
   686
The constants~\ttindexbold{Ball} and~\ttindexbold{Bex} are defined
lcp@104
   687
accordingly.  Instead of {\tt Ball($A$,$P$)} and {\tt Bex($A$,$P$)} we may
lcp@104
   688
write\index{*"!}\index{*"?}\index{*ALL}\index{*EX}
lcp@104
   689
\hbox{\tt !~$x$:$A$.$P[x]$} and \hbox{\tt ?~$x$:$A$.$P[x]$}. 
lcp@104
   690
Isabelle's usual notation, \ttindex{ALL} and \ttindex{EX}, is also
lcp@104
   691
available.  As with
lcp@104
   692
ordinary quantifiers, the contents of \ttindexbold{HOL_quantifiers} specifies
lcp@104
   693
which notation should be used for output.
lcp@104
   694
lcp@104
   695
Unions and intersections over sets, namely $\bigcup@{x\in A}B[x]$ and
lcp@104
   696
$\bigcap@{x\in A}B[x]$, are written 
lcp@104
   697
\ttindexbold{UN}~\hbox{\tt$x$:$A$.$B[x]$} and
lcp@104
   698
\ttindexbold{INT}~\hbox{\tt$x$:$A$.$B[x]$}.  
lcp@104
   699
Unions and intersections over types, namely $\bigcup@x B[x]$ and
lcp@104
   700
$\bigcap@x B[x]$, are written 
lcp@104
   701
\ttindexbold{UN}~\hbox{\tt$x$.$B[x]$} and
lcp@104
   702
\ttindexbold{INT}~\hbox{\tt$x$.$B[x]$}; they are equivalent to the previous
lcp@104
   703
union/intersection operators when $A$ is the universal set.
lcp@104
   704
The set of set union and intersection operators ($\bigcup A$ and $\bigcap
lcp@104
   705
A$) are not binders, but equals $\bigcup@{x\in A}x$ and $\bigcap@{x\in
lcp@104
   706
  A}x$, respectively.
lcp@104
   707
lcp@104
   708
\subsection{Axioms and rules of set theory}
lcp@104
   709
The axioms \ttindexbold{mem_Collect_eq} and
lcp@104
   710
\ttindexbold{Collect_mem_eq} assert that the functions {\tt Collect} and
lcp@104
   711
\hbox{\tt op :} are isomorphisms. 
lcp@104
   712
All the other axioms are definitions; see Figure~\ref{hol-set-rules}.
lcp@104
   713
These include straightforward properties of functions: image~({\tt``}) and
lcp@104
   714
{\tt range}, and predicates concerning monotonicity, injectiveness, etc.
lcp@104
   715
lcp@104
   716
{\HOL}'s set theory has the {\ML} identifier \ttindexbold{Set.thy}.
lcp@104
   717
lcp@104
   718
\begin{figure} \makeatother
lcp@104
   719
\begin{ttbox}
lcp@104
   720
\idx{imageI}     [| x:A |] ==> f(x) : f``A
lcp@104
   721
\idx{imageE}     [| b : f``A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P
lcp@104
   722
lcp@104
   723
\idx{rangeI}     f(x) : range(f)
lcp@104
   724
\idx{rangeE}     [| b : range(f);  !!x.[| b=f(x) |] ==> P |] ==> P
lcp@104
   725
lcp@104
   726
\idx{monoI}      [| !!A B. A <= B ==> f(A) <= f(B) |] ==> mono(f)
lcp@104
   727
\idx{monoD}      [| mono(f);  A <= B |] ==> f(A) <= f(B)
lcp@104
   728
lcp@104
   729
\idx{injI}       [| !! x y. f(x) = f(y) ==> x=y |] ==> inj(f)
lcp@104
   730
\idx{inj_inverseI}              (!!x. g(f(x)) = x) ==> inj(f)
lcp@104
   731
\idx{injD}       [| inj(f); f(x) = f(y) |] ==> x=y
lcp@104
   732
lcp@104
   733
\idx{Inv_f_f}    inj(f) ==> Inv(f,f(x)) = x
lcp@104
   734
\idx{f_Inv_f}    y : range(f) ==> f(Inv(f,y)) = y
lcp@104
   735
lcp@104
   736
\idx{Inv_injective}
lcp@104
   737
    [| Inv(f,x)=Inv(f,y); x: range(f);  y: range(f) |] ==> x=y
lcp@104
   738
lcp@104
   739
\idx{inj_ontoI}
lcp@104
   740
    (!! x y. [| f(x) = f(y); x:A; y:A |] ==> x=y) ==> inj_onto(f,A)
lcp@104
   741
lcp@104
   742
\idx{inj_onto_inverseI}
lcp@104
   743
    (!!x. x:A ==> g(f(x)) = x) ==> inj_onto(f,A)
lcp@104
   744
lcp@104
   745
\idx{inj_ontoD}
lcp@104
   746
    [| inj_onto(f,A);  f(x)=f(y);  x:A;  y:A |] ==> x=y
lcp@104
   747
lcp@104
   748
\idx{inj_onto_contraD}
lcp@104
   749
    [| inj_onto(f,A);  x~=y;  x:A;  y:A |] ==> ~ f(x)=f(y)
lcp@104
   750
\end{ttbox}
lcp@104
   751
\caption{Derived rules involving functions} \label{hol-fun}
lcp@104
   752
\end{figure}
lcp@104
   753
lcp@104
   754
lcp@104
   755
\begin{figure} \makeatother
lcp@104
   756
\begin{ttbox}
lcp@104
   757
\idx{Union_upper}     B:A ==> B <= Union(A)
lcp@104
   758
\idx{Union_least}     [| !!X. X:A ==> X<=C |] ==> Union(A) <= C
lcp@104
   759
lcp@104
   760
\idx{Inter_lower}     B:A ==> Inter(A) <= B
lcp@104
   761
\idx{Inter_greatest}  [| !!X. X:A ==> C<=X |] ==> C <= Inter(A)
lcp@104
   762
lcp@104
   763
\idx{Un_upper1}       A <= A Un B
lcp@104
   764
\idx{Un_upper2}       B <= A Un B
lcp@104
   765
\idx{Un_least}        [| A<=C;  B<=C |] ==> A Un B <= C
lcp@104
   766
lcp@104
   767
\idx{Int_lower1}      A Int B <= A
lcp@104
   768
\idx{Int_lower2}      A Int B <= B
lcp@104
   769
\idx{Int_greatest}    [| C<=A;  C<=B |] ==> C <= A Int B
lcp@104
   770
\end{ttbox}
lcp@104
   771
\caption{Derived rules involving subsets} \label{hol-subset}
lcp@104
   772
\end{figure}
lcp@104
   773
lcp@104
   774
lcp@104
   775
\begin{figure} \makeatother
lcp@104
   776
\begin{ttbox}
lcp@104
   777
\idx{Int_absorb}         A Int A = A
lcp@104
   778
\idx{Int_commute}        A Int B = B Int A
lcp@104
   779
\idx{Int_assoc}          (A Int B) Int C  =  A Int (B Int C)
lcp@104
   780
\idx{Int_Un_distrib}     (A Un B)  Int C  =  (A Int C) Un (B Int C)
lcp@104
   781
lcp@104
   782
\idx{Un_absorb}          A Un A = A
lcp@104
   783
\idx{Un_commute}         A Un B = B Un A
lcp@104
   784
\idx{Un_assoc}           (A Un B)  Un C  =  A Un (B Un C)
lcp@104
   785
\idx{Un_Int_distrib}     (A Int B) Un C  =  (A Un C) Int (B Un C)
lcp@104
   786
lcp@104
   787
\idx{Compl_disjoint}     A Int Compl(A) = \{x.False\} 
lcp@104
   788
\idx{Compl_partition}    A Un  Compl(A) = \{x.True\}
lcp@104
   789
\idx{double_complement}  Compl(Compl(A)) = A
lcp@104
   790
\idx{Compl_Un}           Compl(A Un B)  = Compl(A) Int Compl(B)
lcp@104
   791
\idx{Compl_Int}          Compl(A Int B) = Compl(A) Un Compl(B)
lcp@104
   792
lcp@104
   793
\idx{Union_Un_distrib}   Union(A Un B) = Union(A) Un Union(B)
lcp@104
   794
\idx{Int_Union_image}    A Int Union(B) = (UN C:B. A Int C)
lcp@104
   795
\idx{Un_Union_image} 
lcp@104
   796
    (UN x:C. A(x) Un B(x)) = Union(A``C)  Un  Union(B``C)
lcp@104
   797
lcp@104
   798
\idx{Inter_Un_distrib}   Inter(A Un B) = Inter(A) Int Inter(B)
lcp@104
   799
\idx{Un_Inter_image}     A Un Inter(B) = (INT C:B. A Un C)
lcp@104
   800
\idx{Int_Inter_image}
lcp@104
   801
   (INT x:C. A(x) Int B(x)) = Inter(A``C) Int Inter(B``C)
lcp@104
   802
\end{ttbox}
lcp@104
   803
\caption{Set equalities} \label{hol-equalities}
lcp@104
   804
\end{figure}
lcp@104
   805
lcp@104
   806
lcp@104
   807
\subsection{Derived rules for sets}
lcp@104
   808
Figures~\ref{hol-set1} and~\ref{hol-set2} present derived rules.  Most
lcp@104
   809
are obvious and resemble rules of Isabelle's {\ZF} set theory.  The
lcp@104
   810
rules named $XXX${\tt_cong} break down equalities.  Certain rules, such as
lcp@104
   811
\ttindexbold{subsetCE}, \ttindexbold{bexCI} and \ttindexbold{UnCI}, are
lcp@104
   812
designed for classical reasoning; the more natural rules \ttindexbold{subsetD},
lcp@104
   813
\ttindexbold{bexI}, \ttindexbold{Un1} and~\ttindexbold{Un2} are not
lcp@104
   814
strictly necessary.  Similarly, \ttindexbold{equalityCE} supports classical
lcp@104
   815
reasoning about extensionality, after the fashion of \ttindex{iffCE}.  See
lcp@104
   816
the file \ttindexbold{HOL/set.ML} for proofs pertaining to set theory.
lcp@104
   817
lcp@104
   818
Figure~\ref{hol-fun} presents derived rules involving functions.  See
lcp@104
   819
the file \ttindexbold{HOL/fun.ML} for a complete listing.
lcp@104
   820
lcp@104
   821
Figure~\ref{hol-subset} presents lattice properties of the subset relation.
lcp@104
   822
See \ttindexbold{HOL/subset.ML}.
lcp@104
   823
lcp@104
   824
Figure~\ref{hol-equalities} presents set equalities.  See
lcp@104
   825
\ttindexbold{HOL/equalities.ML}.
lcp@104
   826
lcp@104
   827
lcp@104
   828
\begin{figure} \makeatother
lcp@104
   829
\begin{center}
lcp@104
   830
\begin{tabular}{rrr} 
lcp@111
   831
  \it name      &\it meta-type  & \it description \\ 
lcp@111
   832
  \idx{Pair}    & $[\alpha,\beta]\To \alpha\times\beta$
lcp@111
   833
        & ordered pairs $\langle a,b\rangle$ \\
lcp@111
   834
  \idx{fst}     & $\alpha\times\beta \To \alpha$                & first projection\\
lcp@111
   835
  \idx{snd}     & $\alpha\times\beta \To \beta$         & second projection\\
lcp@111
   836
  \idx{split}   & $[\alpha\times\beta, [\alpha,\beta]\To\gamma] \To \gamma$ 
lcp@111
   837
        & generalized projection
lcp@104
   838
\end{tabular}
lcp@104
   839
\end{center}
lcp@104
   840
\subcaption{Constants}
lcp@104
   841
lcp@104
   842
\begin{ttbox}
lcp@104
   843
\idx{fst_def}      fst(p)     == @a. ? b. p = <a,b>
lcp@104
   844
\idx{snd_def}      snd(p)     == @b. ? a. p = <a,b>
lcp@104
   845
\idx{split_def}    split(p,c) == c(fst(p),snd(p))
lcp@104
   846
\subcaption{Definitions}
lcp@104
   847
lcp@104
   848
\idx{Pair_inject}  [| <a, b> = <a',b'>;  [| a=a';  b=b' |] ==> R |] ==> R
lcp@104
   849
lcp@104
   850
\idx{fst}          fst(<a,b>) = a
lcp@104
   851
\idx{snd}          snd(<a,b>) = b
lcp@104
   852
\idx{split}        split(<a,b>, c) = c(a,b)
lcp@104
   853
lcp@104
   854
\idx{surjective_pairing}  p = <fst(p),snd(p)>
lcp@104
   855
\subcaption{Derived rules}
lcp@104
   856
\end{ttbox}
lcp@104
   857
\caption{Type $\alpha\times\beta$} 
lcp@104
   858
\label{hol-prod}
lcp@104
   859
\end{figure} 
lcp@104
   860
lcp@104
   861
lcp@104
   862
\begin{figure} \makeatother
lcp@104
   863
\begin{center}
lcp@104
   864
\begin{tabular}{rrr} 
lcp@111
   865
  \it name      &\it meta-type  & \it description \\ 
lcp@111
   866
  \idx{Inl}     & $\alpha \To \alpha+\beta$                     & first injection\\
lcp@111
   867
  \idx{Inr}     & $\beta \To \alpha+\beta$                      & second injection\\
lcp@111
   868
  \idx{case}    & $[\alpha+\beta, \alpha\To\gamma, \beta\To\gamma] \To\gamma$
lcp@111
   869
        & conditional
lcp@104
   870
\end{tabular}
lcp@104
   871
\end{center}
lcp@104
   872
\subcaption{Constants}
lcp@104
   873
lcp@104
   874
\begin{ttbox}
lcp@104
   875
\idx{case_def}     case == (%p f g. @z. (!x. p=Inl(x) --> z=f(x)) &
lcp@104
   876
                                  (!y. p=Inr(y) --> z=g(y)))
lcp@104
   877
\subcaption{Definition}
lcp@104
   878
lcp@104
   879
\idx{Inl_not_Inr}    ~ Inl(a)=Inr(b)
lcp@104
   880
lcp@104
   881
\idx{inj_Inl}        inj(Inl)
lcp@104
   882
\idx{inj_Inr}        inj(Inr)
lcp@104
   883
lcp@104
   884
\idx{sumE}           [| !!x::'a. P(Inl(x));  !!y::'b. P(Inr(y)) |] ==> P(s)
lcp@104
   885
lcp@104
   886
\idx{case_Inl}       case(Inl(x), f, g) = f(x)
lcp@104
   887
\idx{case_Inr}       case(Inr(x), f, g) = g(x)
lcp@104
   888
lcp@104
   889
\idx{surjective_sum} case(s, %x::'a. f(Inl(x)), %y::'b. f(Inr(y))) = f(s)
lcp@104
   890
\subcaption{Derived rules}
lcp@104
   891
\end{ttbox}
lcp@104
   892
\caption{Rules for type $\alpha+\beta$} 
lcp@104
   893
\label{hol-sum}
lcp@104
   894
\end{figure}
lcp@104
   895
lcp@104
   896
lcp@104
   897
\section{Types}
lcp@104
   898
The basic higher-order logic is augmented with a tremendous amount of
lcp@104
   899
material, including support for recursive function and type definitions.
lcp@104
   900
Space does not permit a detailed discussion.  The present section describes
lcp@104
   901
product, sum, natural number and list types.
lcp@104
   902
lcp@104
   903
\subsection{Product and sum types}
lcp@104
   904
{\HOL} defines the product type $\alpha\times\beta$ and the sum type
lcp@104
   905
$\alpha+\beta$, with the ordered pair syntax {\tt<$a$,$b$>}, using fairly
lcp@104
   906
standard constructions (Figures~\ref{hol-prod} and~\ref{hol-sum}).  Because
lcp@104
   907
Isabelle does not support type definitions, the isomorphisms between these
lcp@104
   908
types and their representations are made explicitly.
lcp@104
   909
lcp@104
   910
Most of the definitions are suppressed, but observe that the projections
lcp@104
   911
and conditionals are defined as descriptions.  Their properties are easily
lcp@104
   912
proved using \ttindex{select_equality}.  See \ttindexbold{HOL/prod.thy} and
lcp@104
   913
\ttindexbold{HOL/sum.thy} for details.
lcp@104
   914
lcp@104
   915
\begin{figure} \makeatother
lcp@104
   916
\indexbold{*"<}
lcp@104
   917
\begin{center}
lcp@104
   918
\begin{tabular}{rrr} 
lcp@111
   919
  \it symbol    & \it meta-type & \it description \\ 
lcp@111
   920
  \idx{0}       & $nat$         & zero \\
lcp@111
   921
  \idx{Suc}     & $nat \To nat$ & successor function\\
lcp@104
   922
  \idx{nat_case} & $[nat, \alpha, nat\To\alpha] \To\alpha$
lcp@111
   923
        & conditional\\
lcp@104
   924
  \idx{nat_rec} & $[nat, \alpha, [nat, \alpha]\To\alpha] \To \alpha$
lcp@111
   925
        & primitive recursor\\
lcp@104
   926
  \idx{pred_nat} & $(nat\times nat) set$ & predecessor relation
lcp@104
   927
\end{tabular}
lcp@104
   928
\end{center}
lcp@104
   929
lcp@104
   930
\begin{center}
lcp@104
   931
\indexbold{*"+}
lcp@104
   932
\index{*@{\tt*}|bold}
lcp@104
   933
\index{/@{\tt/}|bold}
lcp@104
   934
\index{//@{\tt//}|bold}
lcp@104
   935
\index{+@{\tt+}|bold}
lcp@104
   936
\index{-@{\tt-}|bold}
lcp@104
   937
\begin{tabular}{rrrr} 
lcp@111
   938
  \it symbol    & \it meta-type & \it precedence & \it description \\ 
lcp@111
   939
  \tt *         & $[nat,nat]\To nat$    &  Left 70      & multiplication \\
lcp@111
   940
  \tt /         & $[nat,nat]\To nat$    &  Left 70      & division\\
lcp@111
   941
  \tt //        & $[nat,nat]\To nat$    &  Left 70      & modulus\\
lcp@111
   942
  \tt +         & $[nat,nat]\To nat$    &  Left 65      & addition\\
lcp@111
   943
  \tt -         & $[nat,nat]\To nat$    &  Left 65      & subtraction
lcp@104
   944
\end{tabular}
lcp@104
   945
\end{center}
lcp@104
   946
\subcaption{Constants and infixes}
lcp@104
   947
lcp@104
   948
\begin{ttbox}
lcp@104
   949
\idx{nat_case_def}  nat_case == (%n a f. @z. (n=0 --> z=a) & 
lcp@104
   950
                                        (!x. n=Suc(x) --> z=f(x)))
lcp@104
   951
\idx{pred_nat_def}  pred_nat == \{p. ? n. p = <n, Suc(n)>\} 
lcp@104
   952
\idx{less_def}      m<n      == <m,n>:pred_nat^+
lcp@104
   953
\idx{nat_rec_def}   nat_rec(n,c,d) == 
lcp@104
   954
               wfrec(pred_nat, n, %l g.nat_case(l, c, %m.d(m,g(m))))
lcp@104
   955
lcp@104
   956
\idx{add_def}   m+n  == nat_rec(m, n, %u v.Suc(v))
lcp@104
   957
\idx{diff_def}  m-n  == nat_rec(n, m, %u v. nat_rec(v, 0, %x y.x))
lcp@104
   958
\idx{mult_def}  m*n  == nat_rec(m, 0, %u v. n + v)
lcp@104
   959
\idx{mod_def}   m//n == wfrec(trancl(pred_nat), m, %j f. if(j<n,j,f(j-n)))
lcp@104
   960
\idx{quo_def}   m/n  == wfrec(trancl(pred_nat), 
lcp@104
   961
                        m, %j f. if(j<n,0,Suc(f(j-n))))
lcp@104
   962
\subcaption{Definitions}
lcp@104
   963
\end{ttbox}
lcp@104
   964
\caption{Defining $nat$, the type of natural numbers} \label{hol-nat1}
lcp@104
   965
\end{figure}
lcp@104
   966
lcp@104
   967
lcp@104
   968
\begin{figure} \makeatother
lcp@104
   969
\begin{ttbox}
lcp@104
   970
\idx{nat_induct}     [| P(0); !!k. [| P(k) |] ==> P(Suc(k)) |]  ==> P(n)
lcp@104
   971
lcp@104
   972
\idx{Suc_not_Zero}   Suc(m) ~= 0
lcp@104
   973
\idx{inj_Suc}        inj(Suc)
lcp@104
   974
\idx{n_not_Suc_n}    n~=Suc(n)
lcp@104
   975
\subcaption{Basic properties}
lcp@104
   976
lcp@104
   977
\idx{pred_natI}      <n, Suc(n)> : pred_nat
lcp@104
   978
\idx{pred_natE}
lcp@104
   979
    [| p : pred_nat;  !!x n. [| p = <n, Suc(n)> |] ==> R |] ==> R
lcp@104
   980
lcp@104
   981
\idx{nat_case_0}     nat_case(0, a, f) = a
lcp@104
   982
\idx{nat_case_Suc}   nat_case(Suc(k), a, f) = f(k)
lcp@104
   983
lcp@104
   984
\idx{wf_pred_nat}    wf(pred_nat)
lcp@104
   985
\idx{nat_rec_0}      nat_rec(0,c,h) = c
lcp@104
   986
\idx{nat_rec_Suc}    nat_rec(Suc(n), c, h) = h(n, nat_rec(n,c,h))
lcp@104
   987
\subcaption{Case analysis and primitive recursion}
lcp@104
   988
lcp@104
   989
\idx{less_trans}     [| i<j;  j<k |] ==> i<k
lcp@104
   990
\idx{lessI}          n < Suc(n)
lcp@104
   991
\idx{zero_less_Suc}  0 < Suc(n)
lcp@104
   992
lcp@104
   993
\idx{less_not_sym}   n<m --> ~ m<n 
lcp@104
   994
\idx{less_not_refl}  ~ n<n
lcp@104
   995
\idx{not_less0}      ~ n<0
lcp@104
   996
lcp@104
   997
\idx{Suc_less_eq}    (Suc(m) < Suc(n)) = (m<n)
lcp@104
   998
\idx{less_induct}    [| !!n. [| ! m. m<n --> P(m) |] ==> P(n) |]  ==>  P(n)
lcp@104
   999
lcp@104
  1000
\idx{less_linear}    m<n | m=n | n<m
lcp@104
  1001
\subcaption{The less-than relation}
lcp@104
  1002
\end{ttbox}
lcp@104
  1003
\caption{Derived rules for~$nat$} \label{hol-nat2}
lcp@104
  1004
\end{figure}
lcp@104
  1005
lcp@104
  1006
lcp@104
  1007
\subsection{The type of natural numbers, $nat$}
lcp@104
  1008
{\HOL} defines the natural numbers in a roundabout but traditional way.
lcp@104
  1009
The axiom of infinity postulates an type~$ind$ of individuals, which is
lcp@104
  1010
non-empty and closed under an injective operation.  The natural numbers are
lcp@104
  1011
inductively generated by choosing an arbitrary individual for~0 and using
lcp@104
  1012
the injective operation to take successors.  As usual, the isomorphisms
lcp@104
  1013
between~$nat$ and its representation are made explicitly.
lcp@104
  1014
lcp@104
  1015
The definition makes use of a least fixed point operator \ttindex{lfp},
lcp@104
  1016
defined using the Knaster-Tarski theorem.  This in turn defines an operator
lcp@104
  1017
\ttindex{trancl} for taking the transitive closure of a relation.  See
lcp@104
  1018
files \ttindexbold{HOL/lfp.thy} and \ttindexbold{HOL/trancl.thy} for
lcp@104
  1019
details.  The definition of~$nat$ resides on \ttindexbold{HOL/nat.thy}.  
lcp@104
  1020
lcp@104
  1021
Type $nat$ is postulated to belong to class~$ord$, which overloads $<$ and
lcp@104
  1022
$\leq$ on the natural numbers.  As of this writing, Isabelle provides no
lcp@104
  1023
means of verifying that such overloading is sensible.  On the other hand,
lcp@104
  1024
the {\HOL} theory includes no polymorphic axioms stating general properties
lcp@104
  1025
of $<$ and $\leq$.
lcp@104
  1026
lcp@104
  1027
File \ttindexbold{HOL/arith.ML} develops arithmetic on the natural numbers.
lcp@104
  1028
It defines addition, multiplication, subtraction, division, and remainder,
lcp@104
  1029
proving the theorem $a \bmod b + (a/b)\times b = a$.  Division and
lcp@104
  1030
remainder are defined by repeated subtraction, which requires well-founded
lcp@104
  1031
rather than primitive recursion.
lcp@104
  1032
lcp@104
  1033
Primitive recursion makes use of \ttindex{wfrec}, an operator for recursion
lcp@104
  1034
along arbitrary well-founded relations; see \ttindexbold{HOL/wf.ML} for the
lcp@104
  1035
development.  The predecessor relation, \ttindexbold{pred_nat}, is shown to
lcp@104
  1036
be well-founded; recursion along this relation is primitive recursion,
lcp@104
  1037
while its transitive closure is~$<$.
lcp@104
  1038
lcp@104
  1039
lcp@104
  1040
\begin{figure} \makeatother
lcp@104
  1041
\begin{center}
lcp@104
  1042
\begin{tabular}{rrr} 
lcp@111
  1043
  \it symbol    & \it meta-type & \it description \\ 
lcp@111
  1044
  \idx{Nil}     & $\alpha list$ & the empty list\\
lcp@111
  1045
  \idx{Cons}    & $[\alpha, \alpha list] \To \alpha list$
lcp@111
  1046
        & list constructor\\
lcp@111
  1047
  \idx{list_rec}        & $[\alpha list, \beta, [\alpha ,\alpha list,
lcp@104
  1048
\beta]\To\beta] \To \beta$
lcp@111
  1049
        & list recursor\\
lcp@111
  1050
  \idx{map}     & $(\alpha\To\beta) \To (\alpha list \To \beta list)$
lcp@111
  1051
        & mapping functional
lcp@104
  1052
\end{tabular}
lcp@104
  1053
\end{center}
lcp@104
  1054
\subcaption{Constants}
lcp@104
  1055
lcp@104
  1056
\begin{ttbox}
lcp@104
  1057
\idx{map_def}     map(f,xs) == list_rec(xs, Nil, %x l r. Cons(f(x), r))
lcp@104
  1058
\subcaption{Definition}
lcp@104
  1059
lcp@104
  1060
\idx{list_induct}
lcp@104
  1061
    [| P(Nil);  !!x xs. [| P(xs) |] ==> P(Cons(x,xs)) |]  ==> P(l)
lcp@104
  1062
lcp@104
  1063
\idx{Cons_not_Nil}   ~ Cons(x,xs) = Nil
lcp@104
  1064
\idx{Cons_Cons_eq}   (Cons(x,xs)=Cons(y,ys)) = (x=y & xs=ys)
lcp@104
  1065
lcp@104
  1066
\idx{list_rec_Nil}   list_rec(Nil,c,h) = c
lcp@104
  1067
\idx{list_rec_Cons}  list_rec(Cons(a,l), c, h) = h(a, l, list_rec(l,c,h))
lcp@104
  1068
lcp@104
  1069
\idx{map_Nil}        map(f,Nil) = Nil
lcp@104
  1070
\idx{map_Cons}       map(f, Cons(x,xs)) = Cons(f(x), map(f,xs))
lcp@104
  1071
\end{ttbox}
lcp@104
  1072
\caption{The type of lists and its operations} \label{hol-list}
lcp@104
  1073
\end{figure}
lcp@104
  1074
lcp@104
  1075
lcp@104
  1076
\subsection{The type constructor for lists, $\alpha\,list$}
lcp@104
  1077
{\HOL}'s definition of lists is an example of an experimental method for
lcp@104
  1078
handling recursive data types.  The details need not concern us here; see
lcp@104
  1079
the file \ttindexbold{HOL/list.ML}.  Figure~\ref{hol-list} presents the
lcp@104
  1080
basic list operations, with their types and properties.  In particular,
lcp@104
  1081
\ttindexbold{list_rec} is a primitive recursion operator for lists, in the
lcp@104
  1082
style of Martin-L\"of type theory.  It is derived from well-founded
lcp@104
  1083
recursion, a general principle that can express arbitrary total recursive
lcp@104
  1084
functions. 
lcp@104
  1085
lcp@104
  1086
lcp@104
  1087
\subsection{The type constructor for lazy lists, $\alpha\,llist$}
lcp@104
  1088
The definition of lazy lists demonstrates methods for handling infinite
lcp@104
  1089
data structures and co-induction in higher-order logic.  It defines an
lcp@104
  1090
operator for co-recursion on lazy lists, which is used to define a few
lcp@104
  1091
simple functions such as map and append.  Co-recursion cannot easily define
lcp@104
  1092
operations such as filter, which can compute indefinitely before yielding
lcp@104
  1093
the next element (if any!) of the lazy list.  A co-induction principle is
lcp@104
  1094
defined for proving equations on lazy lists.  See the files
lcp@104
  1095
\ttindexbold{HOL/llist.thy} and \ttindexbold{HOL/llist.ML} for the formal
lcp@104
  1096
derivations.  I have written a report discussing the treatment of lazy
lcp@104
  1097
lists, and finite lists also~\cite{paulson-coind}.
lcp@104
  1098
lcp@104
  1099
lcp@104
  1100
\section{Classical proof procedures} \label{hol-cla-prover}
lcp@104
  1101
{\HOL} derives classical introduction rules for $\disj$ and~$\exists$, as
lcp@104
  1102
well as classical elimination rules for~$\imp$ and~$\bimp$, and the swap
lcp@104
  1103
rule (Figure~\ref{hol-lemmas2}).
lcp@104
  1104
lcp@104
  1105
The classical reasoning module is set up for \HOL, as the structure 
lcp@104
  1106
\ttindexbold{Classical}.  This structure is open, so {\ML} identifiers such
lcp@104
  1107
as {\tt step_tac}, {\tt fast_tac}, {\tt best_tac}, etc., refer to it.
lcp@104
  1108
lcp@104
  1109
{\HOL} defines the following classical rule sets:
lcp@104
  1110
\begin{ttbox} 
lcp@104
  1111
prop_cs    : claset
lcp@104
  1112
HOL_cs     : claset
lcp@104
  1113
HOL_dup_cs : claset
lcp@104
  1114
set_cs     : claset
lcp@104
  1115
\end{ttbox}
lcp@104
  1116
\begin{description}
lcp@104
  1117
\item[\ttindexbold{prop_cs}] contains the propositional rules, namely
lcp@104
  1118
those for~$\top$, $\bot$, $\conj$, $\disj$, $\neg$, $\imp$ and~$\bimp$,
lcp@104
  1119
along with the rule~\ttindex{refl}.
lcp@104
  1120
lcp@104
  1121
\item[\ttindexbold{HOL_cs}] 
lcp@104
  1122
extends {\tt prop_cs} with the safe rules \ttindex{allI} and~\ttindex{exE}
lcp@104
  1123
and the unsafe rules \ttindex{allE} and~\ttindex{exI}, as well as rules for
lcp@104
  1124
unique existence.  Search using this is incomplete since quantified
lcp@104
  1125
formulae are used at most once.
lcp@104
  1126
lcp@104
  1127
\item[\ttindexbold{HOL_dup_cs}] 
lcp@104
  1128
extends {\tt prop_cs} with the safe rules \ttindex{allI} and~\ttindex{exE}
lcp@104
  1129
and the unsafe rules \ttindex{all_dupE} and~\ttindex{exCI}, as well as
lcp@104
  1130
rules for unique existence.  Search using this is complete --- quantified
lcp@104
  1131
formulae may be duplicated --- but frequently fails to terminate.  It is
lcp@104
  1132
generally unsuitable for depth-first search.
lcp@104
  1133
lcp@104
  1134
\item[\ttindexbold{set_cs}] 
lcp@104
  1135
extends {\tt HOL_cs} with rules for the bounded quantifiers, subsets,
lcp@104
  1136
comprehensions, unions/intersections, complements, finite setes, images and
lcp@104
  1137
ranges.
lcp@104
  1138
\end{description}
lcp@104
  1139
\noindent
lcp@104
  1140
See the {\em Reference Manual} for more discussion of classical proof
lcp@104
  1141
methods.
lcp@104
  1142
lcp@104
  1143
lcp@111
  1144
\section{The examples directories}
lcp@111
  1145
Directory {\tt Subst} contains Martin Coen's mechanization of a theory of
lcp@111
  1146
substitutions and unifiers.  It is based on Paulson's previous
lcp@114
  1147
mechanization in {\LCF}~\cite{paulson85} of Manna and Waldinger's
lcp@111
  1148
theory~\cite{mw81}. 
lcp@111
  1149
lcp@111
  1150
Directory {\tt ex} contains other examples and experimental proofs in
lcp@111
  1151
{\HOL}.  Here is an overview of the more interesting files.
lcp@104
  1152
\begin{description}
lcp@104
  1153
\item[\ttindexbold{HOL/ex/meson.ML}]
lcp@104
  1154
contains an experimental implementation of the MESON proof procedure,
lcp@104
  1155
inspired by Plaisted~\cite{plaisted90}.  It is much more powerful than
lcp@104
  1156
Isabelle's classical module.  
lcp@104
  1157
lcp@111
  1158
\item[\ttindexbold{HOL/ex/mesontest.ML}]
lcp@104
  1159
contains test data for the MESON proof procedure.
lcp@104
  1160
lcp@104
  1161
\item[\ttindexbold{HOL/ex/set.ML}]
lcp@104
  1162
proves Cantor's Theorem (see below) and the Schr\"oder-Bernstein Theorem.
lcp@104
  1163
lcp@111
  1164
\item[\ttindexbold{HOL/ex/pl.ML}]
lcp@104
  1165
proves the soundness and completeness of classical propositional logic,
lcp@104
  1166
given a truth table semantics.  The only connective is $\imp$.  A
lcp@104
  1167
Hilbert-style axiom system is specified, and its set of theorems defined
lcp@104
  1168
inductively.
lcp@104
  1169
lcp@111
  1170
\item[\ttindexbold{HOL/ex/term.ML}] 
lcp@111
  1171
  contains proofs about an experimental recursive type definition;
lcp@111
  1172
  the recursion goes through the type constructor~$list$.
lcp@104
  1173
lcp@104
  1174
\item[\ttindexbold{HOL/ex/simult.ML}]
lcp@104
  1175
defines primitives for solving mutually recursive equations over sets.
lcp@104
  1176
It constructs sets of trees and forests as an example, including induction
lcp@104
  1177
and recursion rules that handle the mutual recursion.
lcp@111
  1178
lcp@111
  1179
\item[\ttindexbold{HOL/ex/mt.ML}]
lcp@111
  1180
contains Jacob Frost's formalization~\cite{frost93} of a co-induction
lcp@111
  1181
example by Milner and Tofte~\cite{milner-coind}.
lcp@104
  1182
\end{description}
lcp@104
  1183
lcp@104
  1184
lcp@104
  1185
\section{Example: deriving the conjunction rules}
lcp@104
  1186
{\HOL} comes with a body of derived rules, ranging from simple properties
lcp@104
  1187
of the logical constants and set theory to well-founded recursion.  Many of
lcp@104
  1188
them are worth studying.
lcp@104
  1189
lcp@104
  1190
Deriving natural deduction rules for the logical constants from their
lcp@104
  1191
definitions is an archetypal example of higher-order reasoning.  Let us
lcp@104
  1192
verify two conjunction rules:
lcp@104
  1193
\[ \infer[({\conj}I)]{P\conj Q}{P & Q} \qquad\qquad
lcp@104
  1194
   \infer[({\conj}E1)]{P}{P\conj Q}  
lcp@104
  1195
\]
lcp@104
  1196
lcp@104
  1197
\subsection{The introduction rule}
lcp@104
  1198
We begin by stating the rule as the goal.  The list of premises $[P,Q]$ is
lcp@104
  1199
bound to the {\ML} variable~{\tt prems}.
lcp@104
  1200
\begin{ttbox}
lcp@104
  1201
val prems = goal HOL.thy "[| P; Q |] ==> P&Q";
lcp@104
  1202
{\out Level 0}
lcp@104
  1203
{\out P & Q}
lcp@104
  1204
{\out  1. P & Q}
lcp@111
  1205
{\out val prems = ["P [P]",  "Q [Q]"] : thm list}
lcp@104
  1206
\end{ttbox}
lcp@104
  1207
The next step is to unfold the definition of conjunction.  But
lcp@104
  1208
\ttindex{and_def} uses {\HOL}'s internal equality, so
lcp@104
  1209
\ttindex{rewrite_goals_tac} is unsuitable.
lcp@104
  1210
Instead, we perform substitution using the rule \ttindex{ssubst}:
lcp@104
  1211
\begin{ttbox}
lcp@104
  1212
by (resolve_tac [and_def RS ssubst] 1);
lcp@104
  1213
{\out Level 1}
lcp@104
  1214
{\out P & Q}
lcp@104
  1215
{\out  1. ! R. (P --> Q --> R) --> R}
lcp@104
  1216
\end{ttbox}
lcp@104
  1217
We now apply $(\forall I)$ and $({\imp}I)$:
lcp@104
  1218
\begin{ttbox}
lcp@104
  1219
by (resolve_tac [allI] 1);
lcp@104
  1220
{\out Level 2}
lcp@104
  1221
{\out P & Q}
lcp@104
  1222
{\out  1. !!R. (P --> Q --> R) --> R}
lcp@104
  1223
by (resolve_tac [impI] 1);
lcp@104
  1224
{\out Level 3}
lcp@104
  1225
{\out P & Q}
lcp@104
  1226
{\out  1. !!R. P --> Q --> R ==> R}
lcp@104
  1227
\end{ttbox}
lcp@104
  1228
The assumption is a nested implication, which may be eliminated
lcp@104
  1229
using~\ttindex{mp} resolved with itself.  Elim-resolution, here, performs
lcp@104
  1230
backwards chaining.  More straightforward would be to use~\ttindex{impE}
lcp@104
  1231
twice.
lcp@104
  1232
\index{*RS}
lcp@104
  1233
\begin{ttbox}
lcp@104
  1234
by (eresolve_tac [mp RS mp] 1);
lcp@104
  1235
{\out Level 4}
lcp@104
  1236
{\out P & Q}
lcp@104
  1237
{\out  1. !!R. P}
lcp@104
  1238
{\out  2. !!R. Q}
lcp@104
  1239
\end{ttbox}
lcp@104
  1240
These two subgoals are simply the premises:
lcp@104
  1241
\begin{ttbox}
lcp@104
  1242
by (REPEAT (resolve_tac prems 1));
lcp@104
  1243
{\out Level 5}
lcp@104
  1244
{\out P & Q}
lcp@104
  1245
{\out No subgoals!}
lcp@104
  1246
\end{ttbox}
lcp@104
  1247
lcp@104
  1248
lcp@104
  1249
\subsection{The elimination rule}
lcp@104
  1250
Again, we bind the list of premises (in this case $[P\conj Q]$)
lcp@104
  1251
to~{\tt prems}.
lcp@104
  1252
\begin{ttbox}
lcp@104
  1253
val prems = goal HOL.thy "[| P & Q |] ==> P";
lcp@104
  1254
{\out Level 0}
lcp@104
  1255
{\out P}
lcp@104
  1256
{\out  1. P}
lcp@111
  1257
{\out val prems = ["P & Q  [P & Q]"] : thm list}
lcp@104
  1258
\end{ttbox}
lcp@104
  1259
Working with premises that involve defined constants can be tricky.  We
lcp@104
  1260
must expand the definition of conjunction in the meta-assumption $P\conj
lcp@104
  1261
Q$.  The rule \ttindex{subst} performs substitution in forward proofs.
lcp@104
  1262
We get two resolvents, since the vacuous substitution is valid:
lcp@104
  1263
\begin{ttbox}
lcp@104
  1264
prems RL [and_def RS subst];
lcp@104
  1265
{\out val it = ["! R. (P --> Q --> R) --> R  [P & Q]",}
lcp@104
  1266
{\out           "P & Q  [P & Q]"] : thm list}
lcp@104
  1267
\end{ttbox}
lcp@104
  1268
By applying $(\forall E)$ and $({\imp}E)$ to the resolvents, we dispose of
lcp@111
  1269
the vacuous one and put the other into a convenient form:\footnote
lcp@111
  1270
{In higher-order logic, {\tt spec RS mp} fails because the resolution yields
lcp@114
  1271
two results, namely ${\List{\forall x.x; P}\Imp Q}$ and ${\List{\forall
lcp@114
  1272
  x.P(x)\imp Q(x); P(x)}\Imp Q(x)}$.  In first-order logic, the resolution
lcp@111
  1273
yields only the latter result.}
lcp@104
  1274
\index{*RL}
lcp@104
  1275
\begin{ttbox}
lcp@104
  1276
prems RL [and_def RS subst] RL [spec] RL [mp];
lcp@104
  1277
{\out val it = ["P --> Q --> ?Q ==> ?Q  [P & Q]"] : thm list}
lcp@104
  1278
\end{ttbox}
lcp@104
  1279
This is a list containing a single rule, which is directly applicable to
lcp@104
  1280
our goal:
lcp@104
  1281
\begin{ttbox}
lcp@104
  1282
by (resolve_tac it 1);
lcp@104
  1283
{\out Level 1}
lcp@104
  1284
{\out P}
lcp@104
  1285
{\out  1. P --> Q --> P}
lcp@104
  1286
\end{ttbox}
lcp@104
  1287
The subgoal is a trivial implication.  Recall that \ttindex{ares_tac} is a
lcp@104
  1288
combination of \ttindex{assume_tac} and \ttindex{resolve_tac}.
lcp@104
  1289
\begin{ttbox}
lcp@104
  1290
by (REPEAT (ares_tac [impI] 1));
lcp@104
  1291
{\out Level 2}
lcp@104
  1292
{\out P}
lcp@104
  1293
{\out No subgoals!}
lcp@104
  1294
\end{ttbox}
lcp@104
  1295
lcp@104
  1296
lcp@104
  1297
\section{Example: Cantor's Theorem}
lcp@104
  1298
Cantor's Theorem states that every set has more subsets than it has
lcp@104
  1299
elements.  It has become a favourite example in higher-order logic since
lcp@104
  1300
it is so easily expressed:
lcp@104
  1301
\[  \forall f::[\alpha,\alpha]\To bool. \exists S::\alpha\To bool.
lcp@104
  1302
    \forall x::\alpha. f(x) \not= S 
lcp@104
  1303
\] 
lcp@104
  1304
Viewing types as sets, $\alpha\To bool$ represents the powerset
lcp@104
  1305
of~$\alpha$.  This version states that for every function from $\alpha$ to
lcp@104
  1306
its powerset, some subset is outside its range.
lcp@104
  1307
lcp@104
  1308
The Isabelle proof uses {\HOL}'s set theory, with the type $\alpha\,set$ and
lcp@104
  1309
the operator \ttindex{range}.  Since it avoids quantification, we may
lcp@104
  1310
inspect the subset found by the proof.
lcp@104
  1311
\begin{ttbox}
lcp@104
  1312
goal Set.thy "~ ?S : range(f :: 'a=>'a set)";
lcp@104
  1313
{\out Level 0}
lcp@104
  1314
{\out ~ ?S : range(f)}
lcp@104
  1315
{\out  1. ~ ?S : range(f)}
lcp@104
  1316
\end{ttbox}
lcp@104
  1317
The first two steps are routine.  The rule \ttindex{rangeE} reasons that,
lcp@104
  1318
since $\Var{S}\in range(f)$, we have $\Var{S}=f(x)$ for some~$x$.
lcp@104
  1319
\begin{ttbox}
lcp@104
  1320
by (resolve_tac [notI] 1);
lcp@104
  1321
{\out Level 1}
lcp@104
  1322
{\out ~ ?S : range(f)}
lcp@104
  1323
{\out  1. ?S : range(f) ==> False}
lcp@104
  1324
by (eresolve_tac [rangeE] 1);
lcp@104
  1325
{\out Level 2}
lcp@104
  1326
{\out ~ ?S : range(f)}
lcp@104
  1327
{\out  1. !!x. ?S = f(x) ==> False}
lcp@104
  1328
\end{ttbox}
lcp@104
  1329
Next, we apply \ttindex{equalityCE}, reasoning that since $\Var{S}=f(x)$,
lcp@104
  1330
we have $\Var{c}\in \Var{S}$ if and only if $\Var{c}\in f(x)$ for
lcp@104
  1331
any~$\Var{c}$.
lcp@104
  1332
\begin{ttbox}
lcp@104
  1333
by (eresolve_tac [equalityCE] 1);
lcp@104
  1334
{\out Level 3}
lcp@104
  1335
{\out ~ ?S : range(f)}
lcp@104
  1336
{\out  1. !!x. [| ?c3(x) : ?S; ?c3(x) : f(x) |] ==> False}
lcp@104
  1337
{\out  2. !!x. [| ~ ?c3(x) : ?S; ~ ?c3(x) : f(x) |] ==> False}
lcp@104
  1338
\end{ttbox}
lcp@104
  1339
Now we use a bit of creativity.  Suppose that $\Var{S}$ has the form of a
lcp@104
  1340
comprehension.  Then $\Var{c}\in\{x.\Var{P}(x)\}$ implies
lcp@104
  1341
$\Var{P}(\Var{c})\}$.\index{*CollectD}
lcp@104
  1342
\begin{ttbox}
lcp@104
  1343
by (dresolve_tac [CollectD] 1);
lcp@104
  1344
{\out Level 4}
lcp@104
  1345
{\out ~ \{x. ?P7(x)\} : range(f)}
lcp@104
  1346
{\out  1. !!x. [| ?c3(x) : f(x); ?P7(?c3(x)) |] ==> False}
lcp@104
  1347
{\out  2. !!x. [| ~ ?c3(x) : \{x. ?P7(x)\}; ~ ?c3(x) : f(x) |] ==> False}
lcp@104
  1348
\end{ttbox}
lcp@104
  1349
Forcing a contradiction between the two assumptions of subgoal~1 completes
lcp@104
  1350
the instantiation of~$S$.  It is now $\{x. x\not\in f(x)\}$, the standard
lcp@104
  1351
diagonal construction.
lcp@104
  1352
\begin{ttbox}
lcp@104
  1353
by (contr_tac 1);
lcp@104
  1354
{\out Level 5}
lcp@104
  1355
{\out ~ \{x. ~ x : f(x)\} : range(f)}
lcp@104
  1356
{\out  1. !!x. [| ~ x : \{x. ~ x : f(x)\}; ~ x : f(x) |] ==> False}
lcp@104
  1357
\end{ttbox}
lcp@104
  1358
The rest should be easy.  To apply \ttindex{CollectI} to the negated
lcp@104
  1359
assumption, we employ \ttindex{swap_res_tac}:
lcp@104
  1360
\begin{ttbox}
lcp@104
  1361
by (swap_res_tac [CollectI] 1);
lcp@104
  1362
{\out Level 6}
lcp@104
  1363
{\out ~ \{x. ~ x : f(x)\} : range(f)}
lcp@104
  1364
{\out  1. !!x. [| ~ x : f(x); ~ False |] ==> ~ x : f(x)}
lcp@104
  1365
by (assume_tac 1);
lcp@104
  1366
{\out Level 7}
lcp@104
  1367
{\out ~ \{x. ~ x : f(x)\} : range(f)}
lcp@104
  1368
{\out No subgoals!}
lcp@104
  1369
\end{ttbox}
lcp@104
  1370
How much creativity is required?  As it happens, Isabelle can prove this
lcp@104
  1371
theorem automatically.  The classical set \ttindex{set_cs} contains rules
lcp@104
  1372
for most of the constructs of {\HOL}'s set theory.  We augment it with
lcp@104
  1373
\ttindex{equalityCE} --- set equalities are not broken up by default ---
lcp@104
  1374
and apply best-first search.  Depth-first search would diverge, but
lcp@104
  1375
best-first search successfully navigates through the large search space.
lcp@104
  1376
\begin{ttbox}
lcp@104
  1377
choplev 0;
lcp@104
  1378
{\out Level 0}
lcp@104
  1379
{\out ~ ?S : range(f)}
lcp@104
  1380
{\out  1. ~ ?S : range(f)}
lcp@104
  1381
by (best_tac (set_cs addSEs [equalityCE]) 1);
lcp@104
  1382
{\out Level 1}
lcp@104
  1383
{\out ~ \{x. ~ x : f(x)\} : range(f)}
lcp@104
  1384
{\out No subgoals!}
lcp@104
  1385
\end{ttbox}