doc-src/Logics/Old_HOL.tex
author immler@in.tum.de
Thu, 26 Feb 2009 10:13:43 +0100
changeset 30151 629f3a92863e
parent 9695 ec7d7f877712
permissions -rw-r--r--
removed global ref dfg_format
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     1
%% $Id$
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
     2
\chapter{Higher-Order Logic}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
     3
\index{higher-order logic|(}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
     4
\index{HOL system@{\sc hol} system}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
     5
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
     6
The theory~\thydx{HOL} implements higher-order logic.  It is based on
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
     7
Gordon's~{\sc hol} system~\cite{mgordon-hol}, which itself is based on
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
     8
Church's original paper~\cite{church40}.  Andrews's book~\cite{andrews86} is a
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
     9
full description of higher-order logic.  Experience with the {\sc hol} system
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    10
has demonstrated that higher-order logic is useful for hardware verification;
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    11
beyond this, it is widely applicable in many areas of mathematics.  It is
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    12
weaker than ZF set theory but for most applications this does not matter.  If
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    13
you prefer {\ML} to Lisp, you will probably prefer HOL to~ZF.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    14
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    15
Previous releases of Isabelle included a different version of~HOL, with
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    16
explicit type inference rules~\cite{paulson-COLOG}.  This version no longer
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    17
exists, but \thydx{ZF} supports a similar style of reasoning.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    18
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    19
HOL has a distinct feel, compared with ZF and CTT.  It identifies object-level
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    20
types with meta-level types, taking advantage of Isabelle's built-in type
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    21
checker.  It identifies object-level functions with meta-level functions, so
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    22
it uses Isabelle's operations for abstraction and application.  There is no
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    23
`apply' operator: function applications are written as simply~$f(a)$ rather
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    24
than $f{\tt`}a$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    25
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    26
These identifications allow Isabelle to support HOL particularly nicely, but
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    27
they also mean that HOL requires more sophistication from the user --- in
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    28
particular, an understanding of Isabelle's type system.  Beginners should work
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    29
with {\tt show_types} set to {\tt true}.  Gain experience by working in
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    30
first-order logic before attempting to use higher-order logic.  This chapter
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
    31
assumes familiarity with~FOL.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    32
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    33
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    34
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    35
\begin{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    36
\begin{tabular}{rrr} 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    37
  \it name      &\it meta-type  & \it description \\ 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    38
  \cdx{Trueprop}& $bool\To prop$                & coercion to $prop$\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    39
  \cdx{not}     & $bool\To bool$                & negation ($\neg$) \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    40
  \cdx{True}    & $bool$                        & tautology ($\top$) \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    41
  \cdx{False}   & $bool$                        & absurdity ($\bot$) \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    42
  \cdx{if}      & $[bool,\alpha,\alpha]\To\alpha::term$ & conditional \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    43
  \cdx{Inv}     & $(\alpha\To\beta)\To(\beta\To\alpha)$ & function inversion\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    44
  \cdx{Let}     & $[\alpha,\alpha\To\beta]\To\beta$ & let binder
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    45
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    46
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    47
\subcaption{Constants}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    48
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    49
\begin{center}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    50
\index{"@@{\tt\at} symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    51
\index{*"! symbol}\index{*"? symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    52
\index{*"?"! symbol}\index{*"E"X"! symbol}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    53
\begin{tabular}{llrrr} 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    54
  \it symbol &\it name     &\it meta-type & \it description \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    55
  \tt\at & \cdx{Eps}  & $(\alpha\To bool)\To\alpha::term$ & 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    56
        Hilbert description ($\epsilon$) \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    57
  {\tt!~} or \sdx{ALL}  & \cdx{All}  & $(\alpha::term\To bool)\To bool$ & 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    58
        universal quantifier ($\forall$) \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    59
  {\tt?~} or \sdx{EX}   & \cdx{Ex}   & $(\alpha::term\To bool)\To bool$ & 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    60
        existential quantifier ($\exists$) \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    61
  {\tt?!} or {\tt EX!}  & \cdx{Ex1}  & $(\alpha::term\To bool)\To bool$ & 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    62
        unique existence ($\exists!$)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    63
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    64
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    65
\subcaption{Binders} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    66
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    67
\begin{center}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    68
\index{*"= symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    69
\index{&@{\tt\&} symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    70
\index{*"| symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    71
\index{*"-"-"> symbol}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    72
\begin{tabular}{rrrr} 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    73
  \it symbol    & \it meta-type & \it priority & \it description \\ 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    74
  \sdx{o}       & $[\beta\To\gamma,\alpha\To\beta]\To (\alpha\To\gamma)$ & 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    75
        Right 50 & composition ($\circ$) \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    76
  \tt =         & $[\alpha::term,\alpha]\To bool$ & Left 50 & equality ($=$) \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    77
  \tt <         & $[\alpha::ord,\alpha]\To bool$ & Left 50 & less than ($<$) \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    78
  \tt <=        & $[\alpha::ord,\alpha]\To bool$ & Left 50 & 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    79
                less than or equals ($\leq$)\\
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    80
  \tt \&        & $[bool,bool]\To bool$ & Right 35 & conjunction ($\conj$) \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
    81
  \tt |         & $[bool,bool]\To bool$ & Right 30 & disjunction ($\disj$) \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    82
  \tt -->       & $[bool,bool]\To bool$ & Right 25 & implication ($\imp$)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    83
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    84
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    85
\subcaption{Infixes}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    86
\caption{Syntax of {\tt HOL}} \label{hol-constants}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    87
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    88
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    89
306
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
    90
\begin{figure}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    91
\index{*let symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    92
\index{*in symbol}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    93
\dquotes
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    94
\[\begin{array}{rclcl}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    95
    term & = & \hbox{expression of class~$term$} \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    96
         & | & "\at~" id~id^* " . " formula \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    97
         & | & 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    98
    \multicolumn{3}{l}{"let"~id~"="~term";"\dots";"~id~"="~term~"in"~term}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
    99
               \\[2ex]
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   100
 formula & = & \hbox{expression of type~$bool$} \\
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   101
         & | & term " = " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   102
         & | & term " \ttilde= " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   103
         & | & term " < " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   104
         & | & term " <= " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   105
         & | & "\ttilde\ " formula \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   106
         & | & formula " \& " formula \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   107
         & | & formula " | " formula \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   108
         & | & formula " --> " formula \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   109
         & | & "!~~~" id~id^* " . " formula 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   110
         & | & "ALL~" id~id^* " . " formula \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   111
         & | & "?~~~" id~id^* " . " formula 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   112
         & | & "EX~~" id~id^* " . " formula \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   113
         & | & "?!~~" id~id^* " . " formula 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   114
         & | & "EX!~" id~id^* " . " formula
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   115
  \end{array}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   116
\]
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   117
\caption{Full grammar for HOL} \label{hol-grammar}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   118
\end{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   119
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   120
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   121
\section{Syntax}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   122
The type class of higher-order terms is called~\cldx{term}.  Type variables
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   123
range over this class by default.  The equality symbol and quantifiers are
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   124
polymorphic over class {\tt term}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   125
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   126
Class \cldx{ord} consists of all ordered types; the relations $<$ and
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   127
$\leq$ are polymorphic over this class, as are the functions
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   128
\cdx{mono}, \cdx{min} and \cdx{max}.  Three other
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   129
type classes --- \cldx{plus}, \cldx{minus} and \cldx{times} --- permit
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   130
overloading of the operators {\tt+}, {\tt-} and {\tt*}.  In particular,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   131
{\tt-} is overloaded for set difference and subtraction.
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   132
\index{*"+ symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   133
\index{*"- symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   134
\index{*"* symbol}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   135
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   136
Figure~\ref{hol-constants} lists the constants (including infixes and
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   137
binders), while Fig.\ts\ref{hol-grammar} presents the grammar of
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   138
higher-order logic.  Note that $a$\verb|~=|$b$ is translated to
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   139
$\neg(a=b)$.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   140
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   141
\begin{warn}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   142
  HOL has no if-and-only-if connective; logical equivalence is expressed
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   143
  using equality.  But equality has a high priority, as befitting a
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   144
  relation, while if-and-only-if typically has the lowest priority.  Thus,
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   145
  $\neg\neg P=P$ abbreviates $\neg\neg (P=P)$ and not $(\neg\neg P)=P$.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   146
  When using $=$ to mean logical equivalence, enclose both operands in
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   147
  parentheses.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   148
\end{warn}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   149
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   150
\subsection{Types}\label{HOL-types}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   151
The type of formulae, \tydx{bool}, belongs to class \cldx{term}; thus,
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   152
formulae are terms.  The built-in type~\tydx{fun}, which constructs function
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   153
types, is overloaded with arity {\tt(term,term)term}.  Thus, $\sigma\To\tau$
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   154
belongs to class~{\tt term} if $\sigma$ and~$\tau$ do, allowing quantification
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   155
over functions.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   156
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   157
Types in HOL must be non-empty; otherwise the quantifier rules would be
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   158
unsound.  I have commented on this elsewhere~\cite[\S7]{paulson-COLOG}.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   159
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   160
\index{type definitions}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   161
Gordon's {\sc hol} system supports {\bf type definitions}.  A type is
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   162
defined by exhibiting an existing type~$\sigma$, a predicate~$P::\sigma\To
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   163
bool$, and a theorem of the form $\exists x::\sigma.P(x)$.  Thus~$P$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   164
specifies a non-empty subset of~$\sigma$, and the new type denotes this
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   165
subset.  New function constants are generated to establish an isomorphism
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   166
between the new type and the subset.  If type~$\sigma$ involves type
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   167
variables $\alpha@1$, \ldots, $\alpha@n$, then the type definition creates
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   168
a type constructor $(\alpha@1,\ldots,\alpha@n)ty$ rather than a particular
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   169
type.  Melham~\cite{melham89} discusses type definitions at length, with
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   170
examples. 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   171
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   172
Isabelle does not support type definitions at present.  Instead, they are
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   173
mimicked by explicit definitions of isomorphism functions.  The definitions
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   174
should be supported by theorems of the form $\exists x::\sigma.P(x)$, but
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   175
Isabelle cannot enforce this.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   176
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   177
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   178
\subsection{Binders}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   179
Hilbert's {\bf description} operator~$\epsilon x.P[x]$ stands for some~$a$
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   180
satisfying~$P[a]$, if such exists.  Since all terms in HOL denote something, a
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   181
description is always meaningful, but we do not know its value unless $P[x]$
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   182
defines it uniquely.  We may write descriptions as \cdx{Eps}($P$) or use the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   183
syntax \hbox{\tt \at $x$.$P[x]$}.
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   184
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   185
Existential quantification is defined by
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   186
\[ \exists x.P(x) \;\equiv\; P(\epsilon x.P(x)). \]
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   187
The unique existence quantifier, $\exists!x.P[x]$, is defined in terms
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   188
of~$\exists$ and~$\forall$.  An Isabelle binder, it admits nested
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   189
quantifications.  For instance, $\exists!x y.P(x,y)$ abbreviates
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   190
$\exists!x. \exists!y.P(x,y)$; note that this does not mean that there
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   191
exists a unique pair $(x,y)$ satisfying~$P(x,y)$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   192
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   193
\index{*"! symbol}\index{*"? symbol}\index{HOL system@{\sc hol} system}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   194
Quantifiers have two notations.  As in Gordon's {\sc hol} system, HOL
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   195
uses~{\tt!}\ and~{\tt?}\ to stand for $\forall$ and $\exists$.  The
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   196
existential quantifier must be followed by a space; thus {\tt?x} is an
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   197
unknown, while \verb'? x.f(x)=y' is a quantification.  Isabelle's usual
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   198
notation for quantifiers, \sdx{ALL} and \sdx{EX}, is also available.  Both
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   199
notations are accepted for input.  The {\ML} reference
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   200
\ttindexbold{HOL_quantifiers} governs the output notation.  If set to {\tt
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   201
  true}, then~{\tt!}\ and~{\tt?}\ are displayed; this is the default.  If set
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   202
to {\tt false}, then~{\tt ALL} and~{\tt EX} are displayed.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   203
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   204
All these binders have priority 10. 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   205
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   206
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   207
\subsection{The \sdx{let} and \sdx{case} constructions}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   208
Local abbreviations can be introduced by a {\tt let} construct whose
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   209
syntax appears in Fig.\ts\ref{hol-grammar}.  Internally it is translated into
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   210
the constant~\cdx{Let}.  It can be expanded by rewriting with its
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   211
definition, \tdx{Let_def}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   212
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   213
HOL also defines the basic syntax
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   214
\[\dquotes"case"~e~"of"~c@1~"=>"~e@1~"|" \dots "|"~c@n~"=>"~e@n\] 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   215
as a uniform means of expressing {\tt case} constructs.  Therefore {\tt
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   216
  case} and \sdx{of} are reserved words.  However, so far this is mere
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   217
syntax and has no logical meaning.  By declaring translations, you can
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   218
cause instances of the {\tt case} construct to denote applications of
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   219
particular case operators.  The patterns supplied for $c@1$,~\ldots,~$c@n$
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   220
distinguish among the different case operators.  For an example, see the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   221
case construct for lists on page~\pageref{hol-list} below.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   222
306
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
   223
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   224
\begin{figure}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   225
\begin{ttbox}\makeatother
453
d4e82b3a06c9 added () around some of the ::
nipkow
parents: 349
diff changeset
   226
\tdx{refl}           t = (t::'a)
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   227
\tdx{subst}          [| s=t; P(s) |] ==> P(t::'a)
453
d4e82b3a06c9 added () around some of the ::
nipkow
parents: 349
diff changeset
   228
\tdx{ext}            (!!x::'a. (f(x)::'b) = g(x)) ==> (\%x.f(x)) = (\%x.g(x))
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   229
\tdx{impI}           (P ==> Q) ==> P-->Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   230
\tdx{mp}             [| P-->Q;  P |] ==> Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   231
\tdx{iff}            (P-->Q) --> (Q-->P) --> (P=Q)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   232
\tdx{selectI}        P(x::'a) ==> P(@x.P(x))
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   233
\tdx{True_or_False}  (P=True) | (P=False)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   234
\end{ttbox}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   235
\caption{The {\tt HOL} rules} \label{hol-rules}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   236
\end{figure}
306
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
   237
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
   238
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   239
\begin{figure}\hfuzz=4pt%suppress "Overfull \hbox" message
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   240
\begin{ttbox}\makeatother
453
d4e82b3a06c9 added () around some of the ::
nipkow
parents: 349
diff changeset
   241
\tdx{True_def}   True  == ((\%x::bool.x)=(\%x.x))
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   242
\tdx{All_def}    All   == (\%P. P = (\%x.True))
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   243
\tdx{Ex_def}     Ex    == (\%P. P(@x.P(x)))
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   244
\tdx{False_def}  False == (!P.P)
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   245
\tdx{not_def}    not   == (\%P. P-->False)
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   246
\tdx{and_def}    op &  == (\%P Q. !R. (P-->Q-->R) --> R)
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   247
\tdx{or_def}     op |  == (\%P Q. !R. (P-->R) --> (Q-->R) --> R)
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   248
\tdx{Ex1_def}    Ex1   == (\%P. ? x. P(x) & (! y. P(y) --> y=x))
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   249
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   250
\tdx{Inv_def}    Inv   == (\%(f::'a=>'b) y. @x. f(x)=y)
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   251
\tdx{o_def}      op o  == (\%(f::'b=>'c) g (x::'a). f(g(x)))
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   252
\tdx{if_def}     if    == (\%P x y.@z::'a.(P=True --> z=x) & (P=False --> z=y))
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   253
\tdx{Let_def}    Let(s,f) == f(s)
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   254
\end{ttbox}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   255
\caption{The {\tt HOL} definitions} \label{hol-defs}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   256
\end{figure}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   257
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   258
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   259
\section{Rules of inference}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   260
Figure~\ref{hol-rules} shows the inference rules of~HOL, with their~{\ML}
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   261
names.  Some of the rules deserve additional comments:
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   262
\begin{ttdescription}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   263
\item[\tdx{ext}] expresses extensionality of functions.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   264
\item[\tdx{iff}] asserts that logically equivalent formulae are
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   265
  equal.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   266
\item[\tdx{selectI}] gives the defining property of the Hilbert
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   267
  $\epsilon$-operator.  It is a form of the Axiom of Choice.  The derived rule
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   268
  \tdx{select_equality} (see below) is often easier to use.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   269
\item[\tdx{True_or_False}] makes the logic classical.\footnote{In
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   270
    fact, the $\epsilon$-operator already makes the logic classical, as
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   271
    shown by Diaconescu; see Paulson~\cite{paulson-COLOG} for details.}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   272
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   273
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   274
HOL follows standard practice in higher-order logic: only a few connectives
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   275
are taken as primitive, with the remainder defined obscurely
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   276
(Fig.\ts\ref{hol-defs}).  Gordon's {\sc hol} system expresses the
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   277
corresponding definitions \cite[page~270]{mgordon-hol} using
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   278
object-equality~({\tt=}), which is possible because equality in higher-order
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   279
logic may equate formulae and even functions over formulae.  But theory~HOL,
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   280
like all other Isabelle theories, uses meta-equality~({\tt==}) for
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   281
definitions.
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   282
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   283
Some of the rules mention type variables; for
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   284
example, {\tt refl} mentions the type variable~{\tt'a}.  This allows you to
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   285
instantiate type variables explicitly by calling {\tt res_inst_tac}.  By
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   286
default, explicit type variables have class \cldx{term}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   287
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   288
Include type constraints whenever you state a polymorphic goal.  Type
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   289
inference may otherwise make the goal more polymorphic than you intended,
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   290
with confusing results.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   291
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   292
\begin{warn}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   293
  If resolution fails for no obvious reason, try setting
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   294
  \ttindex{show_types} to {\tt true}, causing Isabelle to display types of
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   295
  terms.  Possibly set \ttindex{show_sorts} to {\tt true} as well, causing
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   296
  Isabelle to display sorts.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   297
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   298
  \index{unification!incompleteness of}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   299
  Where function types are involved, Isabelle's unification code does not
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   300
  guarantee to find instantiations for type variables automatically.  Be
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   301
  prepared to use \ttindex{res_inst_tac} instead of {\tt resolve_tac},
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   302
  possibly instantiating type variables.  Setting
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   303
  \ttindex{Unify.trace_types} to {\tt true} causes Isabelle to report
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   304
  omitted search paths during unification.\index{tracing!of unification}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   305
\end{warn}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   306
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   307
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   308
\begin{figure}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   309
\begin{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   310
\tdx{sym}         s=t ==> t=s
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   311
\tdx{trans}       [| r=s; s=t |] ==> r=t
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   312
\tdx{ssubst}      [| t=s; P(s) |] ==> P(t::'a)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   313
\tdx{box_equals}  [| a=b;  a=c;  b=d |] ==> c=d  
453
d4e82b3a06c9 added () around some of the ::
nipkow
parents: 349
diff changeset
   314
\tdx{arg_cong}    x=y ==> f(x)=f(y)
d4e82b3a06c9 added () around some of the ::
nipkow
parents: 349
diff changeset
   315
\tdx{fun_cong}    f=g ==> f(x)=g(x)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   316
\subcaption{Equality}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   317
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   318
\tdx{TrueI}       True 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   319
\tdx{FalseE}      False ==> P
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   320
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   321
\tdx{conjI}       [| P; Q |] ==> P&Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   322
\tdx{conjunct1}   [| P&Q |] ==> P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   323
\tdx{conjunct2}   [| P&Q |] ==> Q 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   324
\tdx{conjE}       [| P&Q;  [| P; Q |] ==> R |] ==> R
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   325
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   326
\tdx{disjI1}      P ==> P|Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   327
\tdx{disjI2}      Q ==> P|Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   328
\tdx{disjE}       [| P | Q; P ==> R; Q ==> R |] ==> R
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   329
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   330
\tdx{notI}        (P ==> False) ==> ~ P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   331
\tdx{notE}        [| ~ P;  P |] ==> R
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   332
\tdx{impE}        [| P-->Q;  P;  Q ==> R |] ==> R
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   333
\subcaption{Propositional logic}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   334
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   335
\tdx{iffI}        [| P ==> Q;  Q ==> P |] ==> P=Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   336
\tdx{iffD1}       [| P=Q; P |] ==> Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   337
\tdx{iffD2}       [| P=Q; Q |] ==> P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   338
\tdx{iffE}        [| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   339
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   340
\tdx{eqTrueI}     P ==> P=True 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   341
\tdx{eqTrueE}     P=True ==> P 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   342
\subcaption{Logical equivalence}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   343
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   344
\end{ttbox}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   345
\caption{Derived rules for HOL} \label{hol-lemmas1}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   346
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   347
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   348
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   349
\begin{figure}
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   350
\begin{ttbox}\makeatother
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   351
\tdx{allI}      (!!x::'a. P(x)) ==> !x. P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   352
\tdx{spec}      !x::'a.P(x) ==> P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   353
\tdx{allE}      [| !x.P(x);  P(x) ==> R |] ==> R
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   354
\tdx{all_dupE}  [| !x.P(x);  [| P(x); !x.P(x) |] ==> R |] ==> R
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   355
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   356
\tdx{exI}       P(x) ==> ? x::'a.P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   357
\tdx{exE}       [| ? x::'a.P(x); !!x. P(x) ==> Q |] ==> Q
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   358
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   359
\tdx{ex1I}      [| P(a);  !!x. P(x) ==> x=a |] ==> ?! x. P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   360
\tdx{ex1E}      [| ?! x.P(x);  !!x. [| P(x);  ! y. P(y) --> y=x |] ==> R 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   361
          |] ==> R
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   362
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   363
\tdx{select_equality} [| P(a);  !!x. P(x) ==> x=a |] ==> (@x.P(x)) = a
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   364
\subcaption{Quantifiers and descriptions}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   365
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   366
\tdx{ccontr}          (~P ==> False) ==> P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   367
\tdx{classical}       (~P ==> P) ==> P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   368
\tdx{excluded_middle} ~P | P
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   369
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   370
\tdx{disjCI}          (~Q ==> P) ==> P|Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   371
\tdx{exCI}            (! x. ~ P(x) ==> P(a)) ==> ? x.P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   372
\tdx{impCE}           [| P-->Q; ~ P ==> R; Q ==> R |] ==> R
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   373
\tdx{iffCE}           [| P=Q;  [| P;Q |] ==> R;  [| ~P; ~Q |] ==> R |] ==> R
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   374
\tdx{notnotD}         ~~P ==> P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   375
\tdx{swap}            ~P ==> (~Q ==> P) ==> Q
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   376
\subcaption{Classical logic}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   377
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   378
\tdx{if_True}         if(True,x,y) = x
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   379
\tdx{if_False}        if(False,x,y) = y
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   380
\tdx{if_P}            P ==> if(P,x,y) = x
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   381
\tdx{if_not_P}        ~ P ==> if(P,x,y) = y
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   382
\tdx{expand_if}       P(if(Q,x,y)) = ((Q --> P(x)) & (~Q --> P(y)))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   383
\subcaption{Conditionals}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   384
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   385
\caption{More derived rules} \label{hol-lemmas2}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   386
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   387
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   388
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   389
Some derived rules are shown in Figures~\ref{hol-lemmas1}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   390
and~\ref{hol-lemmas2}, with their {\ML} names.  These include natural rules
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   391
for the logical connectives, as well as sequent-style elimination rules for
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   392
conjunctions, implications, and universal quantifiers.  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   393
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   394
Note the equality rules: \tdx{ssubst} performs substitution in
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   395
backward proofs, while \tdx{box_equals} supports reasoning by
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   396
simplifying both sides of an equation.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   397
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   398
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   399
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   400
\begin{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   401
\begin{tabular}{rrr} 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   402
  \it name      &\it meta-type  & \it description \\ 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   403
\index{{}@\verb'{}' symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   404
  \verb|{}|     & $\alpha\,set$         & the empty set \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   405
  \cdx{insert}  & $[\alpha,\alpha\,set]\To \alpha\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   406
        & insertion of element \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   407
  \cdx{Collect} & $(\alpha\To bool)\To\alpha\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   408
        & comprehension \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   409
  \cdx{Compl}   & $(\alpha\,set)\To\alpha\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   410
        & complement \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   411
  \cdx{INTER} & $[\alpha\,set,\alpha\To\beta\,set]\To\beta\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   412
        & intersection over a set\\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   413
  \cdx{UNION} & $[\alpha\,set,\alpha\To\beta\,set]\To\beta\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   414
        & union over a set\\
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
   415
  \cdx{Inter} & $(\alpha\,set)set\To\alpha\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   416
        &set of sets intersection \\
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
   417
  \cdx{Union} & $(\alpha\,set)set\To\alpha\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   418
        &set of sets union \\
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
   419
  \cdx{Pow}   & $\alpha\,set \To (\alpha\,set)set$
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
   420
        & powerset \\[1ex]
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   421
  \cdx{range}   & $(\alpha\To\beta )\To\beta\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   422
        & range of a function \\[1ex]
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   423
  \cdx{Ball}~~\cdx{Bex} & $[\alpha\,set,\alpha\To bool]\To bool$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   424
        & bounded quantifiers \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   425
  \cdx{mono}    & $(\alpha\,set\To\beta\,set)\To bool$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   426
        & monotonicity \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   427
  \cdx{inj}~~\cdx{surj}& $(\alpha\To\beta )\To bool$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   428
        & injective/surjective \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   429
  \cdx{inj_onto}        & $[\alpha\To\beta ,\alpha\,set]\To bool$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   430
        & injective over subset
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   431
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   432
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   433
\subcaption{Constants}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   434
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   435
\begin{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   436
\begin{tabular}{llrrr} 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   437
  \it symbol &\it name     &\it meta-type & \it priority & \it description \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   438
  \sdx{INT}  & \cdx{INTER1}  & $(\alpha\To\beta\,set)\To\beta\,set$ & 10 & 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   439
        intersection over a type\\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   440
  \sdx{UN}  & \cdx{UNION1}  & $(\alpha\To\beta\,set)\To\beta\,set$ & 10 & 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   441
        union over a type
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   442
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   443
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   444
\subcaption{Binders} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   445
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   446
\begin{center}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   447
\index{*"`"` symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   448
\index{*": symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   449
\index{*"<"= symbol}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   450
\begin{tabular}{rrrr} 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   451
  \it symbol    & \it meta-type & \it priority & \it description \\ 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   452
  \tt ``        & $[\alpha\To\beta ,\alpha\,set]\To  (\beta\,set)$
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   453
        & Left 90 & image \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   454
  \sdx{Int}     & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   455
        & Left 70 & intersection ($\inter$) \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   456
  \sdx{Un}      & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   457
        & Left 65 & union ($\union$) \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   458
  \tt:          & $[\alpha ,\alpha\,set]\To bool$       
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   459
        & Left 50 & membership ($\in$) \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   460
  \tt <=        & $[\alpha\,set,\alpha\,set]\To bool$
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   461
        & Left 50 & subset ($\subseteq$) 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   462
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   463
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   464
\subcaption{Infixes}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   465
\caption{Syntax of the theory {\tt Set}} \label{hol-set-syntax}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   466
\end{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   467
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   468
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   469
\begin{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   470
\begin{center} \tt\frenchspacing
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   471
\index{*"! symbol}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   472
\begin{tabular}{rrr} 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   473
  \it external          & \it internal  & \it description \\ 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   474
  $a$ \ttilde: $b$      & \ttilde($a$ : $b$)    & \rm non-membership\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   475
  \{$a@1$, $\ldots$\}  &  insert($a@1$, $\ldots$\{\}) & \rm finite set \\
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   476
  \{$x$.$P[x]$\}        &  Collect($\lambda x.P[x]$) &
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   477
        \rm comprehension \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   478
  \sdx{INT} $x$:$A$.$B[x]$      & INTER($A$,$\lambda x.B[x]$) &
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   479
        \rm intersection \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   480
  \sdx{UN}{\tt\ }  $x$:$A$.$B[x]$      & UNION($A$,$\lambda x.B[x]$) &
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   481
        \rm union \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   482
  \tt ! $x$:$A$.$P[x]$ or \sdx{ALL} $x$:$A$.$P[x]$ & 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   483
        Ball($A$,$\lambda x.P[x]$) & 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   484
        \rm bounded $\forall$ \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   485
  \sdx{?} $x$:$A$.$P[x]$ or \sdx{EX}{\tt\ } $x$:$A$.$P[x]$ & 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   486
        Bex($A$,$\lambda x.P[x]$) & \rm bounded $\exists$
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   487
\end{tabular}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   488
\end{center}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   489
\subcaption{Translations}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   490
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   491
\dquotes
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   492
\[\begin{array}{rclcl}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   493
    term & = & \hbox{other terms\ldots} \\
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   494
         & | & "\{\}" \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   495
         & | & "\{ " term\; ("," term)^* " \}" \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   496
         & | & "\{ " id " . " formula " \}" \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   497
         & | & term " `` " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   498
         & | & term " Int " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   499
         & | & term " Un " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   500
         & | & "INT~~"  id ":" term " . " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   501
         & | & "UN~~~"  id ":" term " . " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   502
         & | & "INT~~"  id~id^* " . " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   503
         & | & "UN~~~"  id~id^* " . " term \\[2ex]
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   504
 formula & = & \hbox{other formulae\ldots} \\
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   505
         & | & term " : " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   506
         & | & term " \ttilde: " term \\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   507
         & | & term " <= " term \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   508
         & | & "!~" id ":" term " . " formula 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   509
         & | & "ALL " id ":" term " . " formula \\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   510
         & | & "?~" id ":" term " . " formula 
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   511
         & | & "EX~~" id ":" term " . " formula
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   512
  \end{array}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   513
\]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   514
\subcaption{Full Grammar}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   515
\caption{Syntax of the theory {\tt Set} (continued)} \label{hol-set-syntax2}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   516
\end{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   517
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   518
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   519
\section{A formulation of set theory}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   520
Historically, higher-order logic gives a foundation for Russell and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   521
Whitehead's theory of classes.  Let us use modern terminology and call them
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   522
{\bf sets}, but note that these sets are distinct from those of ZF set theory,
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   523
and behave more like ZF classes.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   524
\begin{itemize}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   525
\item
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   526
Sets are given by predicates over some type~$\sigma$.  Types serve to
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   527
define universes for sets, but type checking is still significant.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   528
\item
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   529
There is a universal set (for each type).  Thus, sets have complements, and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   530
may be defined by absolute comprehension.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   531
\item
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   532
Although sets may contain other sets as elements, the containing set must
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   533
have a more complex type.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   534
\end{itemize}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   535
Finite unions and intersections have the same behaviour in HOL as they do
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   536
in~ZF.  In HOL the intersection of the empty set is well-defined, denoting the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   537
universal set for the given type.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   538
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   539
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   540
\subsection{Syntax of set theory}\index{*set type}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   541
HOL's set theory is called \thydx{Set}.  The type $\alpha\,set$ is essentially
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   542
the same as $\alpha\To bool$.  The new type is defined for clarity and to
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   543
avoid complications involving function types in unification.  Since Isabelle
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   544
does not support type definitions (as mentioned in \S\ref{HOL-types}), the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   545
isomorphisms between the two types are declared explicitly.  Here they are
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   546
natural: {\tt Collect} maps $\alpha\To bool$ to $\alpha\,set$, while \hbox{\tt
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   547
  op :} maps in the other direction (ignoring argument order).
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   548
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   549
Figure~\ref{hol-set-syntax} lists the constants, infixes, and syntax
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   550
translations.  Figure~\ref{hol-set-syntax2} presents the grammar of the new
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   551
constructs.  Infix operators include union and intersection ($A\union B$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   552
and $A\inter B$), the subset and membership relations, and the image
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   553
operator~{\tt``}\@.  Note that $a$\verb|~:|$b$ is translated to
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   554
$\neg(a\in b)$.  
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   555
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   556
The {\tt\{\ldots\}} notation abbreviates finite sets constructed in the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   557
obvious manner using~{\tt insert} and~$\{\}$:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   558
\begin{eqnarray*}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   559
  \{a@1, \ldots, a@n\}  & \equiv &  
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   560
  {\tt insert}(a@1,\ldots,{\tt insert}(a@n,\{\}))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   561
\end{eqnarray*}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   562
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   563
The set \hbox{\tt\{$x$.$P[x]$\}} consists of all $x$ (of suitable type) that
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   564
satisfy~$P[x]$, where $P[x]$ is a formula that may contain free occurrences
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   565
of~$x$.  This syntax expands to \cdx{Collect}$(\lambda x.P[x])$.  It defines
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   566
sets by absolute comprehension, which is impossible in~ZF; the type of~$x$
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   567
implicitly restricts the comprehension.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   568
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   569
The set theory defines two {\bf bounded quantifiers}:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   570
\begin{eqnarray*}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   571
   \forall x\in A.P[x] &\hbox{abbreviates}& \forall x. x\in A\imp P[x] \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   572
   \exists x\in A.P[x] &\hbox{abbreviates}& \exists x. x\in A\conj P[x]
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   573
\end{eqnarray*}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   574
The constants~\cdx{Ball} and~\cdx{Bex} are defined
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   575
accordingly.  Instead of {\tt Ball($A$,$P$)} and {\tt Bex($A$,$P$)} we may
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   576
write\index{*"! symbol}\index{*"? symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   577
\index{*ALL symbol}\index{*EX symbol} 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   578
%
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   579
\hbox{\tt !~$x$:$A$.$P[x]$} and \hbox{\tt ?~$x$:$A$.$P[x]$}.  Isabelle's
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   580
usual quantifier symbols, \sdx{ALL} and \sdx{EX}, are also accepted
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   581
for input.  As with the primitive quantifiers, the {\ML} reference
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   582
\ttindex{HOL_quantifiers} specifies which notation to use for output.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   583
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   584
Unions and intersections over sets, namely $\bigcup@{x\in A}B[x]$ and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   585
$\bigcap@{x\in A}B[x]$, are written 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   586
\sdx{UN}~\hbox{\tt$x$:$A$.$B[x]$} and
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   587
\sdx{INT}~\hbox{\tt$x$:$A$.$B[x]$}.  
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   588
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   589
Unions and intersections over types, namely $\bigcup@x B[x]$ and $\bigcap@x
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   590
B[x]$, are written \sdx{UN}~\hbox{\tt$x$.$B[x]$} and
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   591
\sdx{INT}~\hbox{\tt$x$.$B[x]$}.  They are equivalent to the previous
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   592
union and intersection operators when $A$ is the universal set.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   593
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   594
The operators $\bigcup A$ and $\bigcap A$ act upon sets of sets.  They are
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   595
not binders, but are equal to $\bigcup@{x\in A}x$ and $\bigcap@{x\in A}x$,
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   596
respectively.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   597
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   598
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   599
\begin{figure} \underscoreon
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   600
\begin{ttbox}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   601
\tdx{mem_Collect_eq}    (a : \{x.P(x)\}) = P(a)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   602
\tdx{Collect_mem_eq}    \{x.x:A\} = A
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   603
841
14b96e3bd4ab fixed minor typos;
wenzelm
parents: 705
diff changeset
   604
\tdx{empty_def}         \{\}          == \{x.False\}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   605
\tdx{insert_def}        insert(a,B) == \{x.x=a\} Un B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   606
\tdx{Ball_def}          Ball(A,P)   == ! x. x:A --> P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   607
\tdx{Bex_def}           Bex(A,P)    == ? x. x:A & P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   608
\tdx{subset_def}        A <= B      == ! x:A. x:B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   609
\tdx{Un_def}            A Un B      == \{x.x:A | x:B\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   610
\tdx{Int_def}           A Int B     == \{x.x:A & x:B\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   611
\tdx{set_diff_def}      A - B       == \{x.x:A & x~:B\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   612
\tdx{Compl_def}         Compl(A)    == \{x. ~ x:A\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   613
\tdx{INTER_def}         INTER(A,B)  == \{y. ! x:A. y: B(x)\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   614
\tdx{UNION_def}         UNION(A,B)  == \{y. ? x:A. y: B(x)\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   615
\tdx{INTER1_def}        INTER1(B)   == INTER(\{x.True\}, B)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   616
\tdx{UNION1_def}        UNION1(B)   == UNION(\{x.True\}, B)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   617
\tdx{Inter_def}         Inter(S)    == (INT x:S. x)
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
   618
\tdx{Union_def}         Union(S)    == (UN  x:S. x)
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
   619
\tdx{Pow_def}           Pow(A)      == \{B. B <= A\}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   620
\tdx{image_def}         f``A        == \{y. ? x:A. y=f(x)\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   621
\tdx{range_def}         range(f)    == \{y. ? x. y=f(x)\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   622
\tdx{mono_def}          mono(f)     == !A B. A <= B --> f(A) <= f(B)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   623
\tdx{inj_def}           inj(f)      == ! x y. f(x)=f(y) --> x=y
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   624
\tdx{surj_def}          surj(f)     == ! y. ? x. y=f(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   625
\tdx{inj_onto_def}      inj_onto(f,A) == !x:A. !y:A. f(x)=f(y) --> x=y
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   626
\end{ttbox}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   627
\caption{Rules of the theory {\tt Set}} \label{hol-set-rules}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   628
\end{figure}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   629
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   630
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   631
\begin{figure} \underscoreon
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   632
\begin{ttbox}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   633
\tdx{CollectI}        [| P(a) |] ==> a : \{x.P(x)\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   634
\tdx{CollectD}        [| a : \{x.P(x)\} |] ==> P(a)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   635
\tdx{CollectE}        [| a : \{x.P(x)\};  P(a) ==> W |] ==> W
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   636
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   637
\tdx{ballI}           [| !!x. x:A ==> P(x) |] ==> ! x:A. P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   638
\tdx{bspec}           [| ! x:A. P(x);  x:A |] ==> P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   639
\tdx{ballE}           [| ! x:A. P(x);  P(x) ==> Q;  ~ x:A ==> Q |] ==> Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   640
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   641
\tdx{bexI}            [| P(x);  x:A |] ==> ? x:A. P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   642
\tdx{bexCI}           [| ! x:A. ~ P(x) ==> P(a);  a:A |] ==> ? x:A.P(x)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   643
\tdx{bexE}            [| ? x:A. P(x);  !!x. [| x:A; P(x) |] ==> Q  |] ==> Q
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   644
\subcaption{Comprehension and Bounded quantifiers}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   645
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   646
\tdx{subsetI}         (!!x.x:A ==> x:B) ==> A <= B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   647
\tdx{subsetD}         [| A <= B;  c:A |] ==> c:B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   648
\tdx{subsetCE}        [| A <= B;  ~ (c:A) ==> P;  c:B ==> P |] ==> P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   649
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   650
\tdx{subset_refl}     A <= A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   651
\tdx{subset_trans}    [| A<=B;  B<=C |] ==> A<=C
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   652
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
   653
\tdx{equalityI}       [| A <= B;  B <= A |] ==> A = B
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   654
\tdx{equalityD1}      A = B ==> A<=B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   655
\tdx{equalityD2}      A = B ==> B<=A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   656
\tdx{equalityE}       [| A = B;  [| A<=B; B<=A |] ==> P |]  ==>  P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   657
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   658
\tdx{equalityCE}      [| A = B;  [| c:A; c:B |] ==> P;  
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   659
                           [| ~ c:A; ~ c:B |] ==> P 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   660
                |]  ==>  P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   661
\subcaption{The subset and equality relations}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   662
\end{ttbox}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   663
\caption{Derived rules for set theory} \label{hol-set1}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   664
\end{figure}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   665
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   666
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   667
\begin{figure} \underscoreon
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   668
\begin{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   669
\tdx{emptyE}   a : \{\} ==> P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   670
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   671
\tdx{insertI1} a : insert(a,B)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   672
\tdx{insertI2} a : B ==> a : insert(b,B)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   673
\tdx{insertE}  [| a : insert(b,A);  a=b ==> P;  a:A ==> P |] ==> P
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   674
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   675
\tdx{ComplI}   [| c:A ==> False |] ==> c : Compl(A)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   676
\tdx{ComplD}   [| c : Compl(A) |] ==> ~ c:A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   677
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   678
\tdx{UnI1}     c:A ==> c : A Un B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   679
\tdx{UnI2}     c:B ==> c : A Un B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   680
\tdx{UnCI}     (~c:B ==> c:A) ==> c : A Un B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   681
\tdx{UnE}      [| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   682
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   683
\tdx{IntI}     [| c:A;  c:B |] ==> c : A Int B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   684
\tdx{IntD1}    c : A Int B ==> c:A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   685
\tdx{IntD2}    c : A Int B ==> c:B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   686
\tdx{IntE}     [| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   687
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   688
\tdx{UN_I}     [| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   689
\tdx{UN_E}     [| b: (UN x:A. B(x));  !!x.[| x:A;  b:B(x) |] ==> R |] ==> R
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   690
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   691
\tdx{INT_I}    (!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   692
\tdx{INT_D}    [| b: (INT x:A. B(x));  a:A |] ==> b: B(a)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   693
\tdx{INT_E}    [| b: (INT x:A. B(x));  b: B(a) ==> R;  ~ a:A ==> R |] ==> R
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   694
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   695
\tdx{UnionI}   [| X:C;  A:X |] ==> A : Union(C)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   696
\tdx{UnionE}   [| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   697
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   698
\tdx{InterI}   [| !!X. X:C ==> A:X |] ==> A : Inter(C)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   699
\tdx{InterD}   [| A : Inter(C);  X:C |] ==> A:X
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   700
\tdx{InterE}   [| A : Inter(C);  A:X ==> R;  ~ X:C ==> R |] ==> R
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
   701
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
   702
\tdx{PowI}     A<=B ==> A: Pow(B)
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
   703
\tdx{PowD}     A: Pow(B) ==> A<=B
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   704
\end{ttbox}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   705
\caption{Further derived rules for set theory} \label{hol-set2}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   706
\end{figure}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   707
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   708
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   709
\subsection{Axioms and rules of set theory}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   710
Figure~\ref{hol-set-rules} presents the rules of theory \thydx{Set}.  The
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   711
axioms \tdx{mem_Collect_eq} and \tdx{Collect_mem_eq} assert
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   712
that the functions {\tt Collect} and \hbox{\tt op :} are isomorphisms.  Of
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   713
course, \hbox{\tt op :} also serves as the membership relation.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   714
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   715
All the other axioms are definitions.  They include the empty set, bounded
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   716
quantifiers, unions, intersections, complements and the subset relation.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   717
They also include straightforward properties of functions: image~({\tt``}) and
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   718
{\tt range}, and predicates concerning monotonicity, injectiveness and
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   719
surjectiveness.  
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   720
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   721
The predicate \cdx{inj_onto} is used for simulating type definitions.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   722
The statement ${\tt inj_onto}(f,A)$ asserts that $f$ is injective on the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   723
set~$A$, which specifies a subset of its domain type.  In a type
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   724
definition, $f$ is the abstraction function and $A$ is the set of valid
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   725
representations; we should not expect $f$ to be injective outside of~$A$.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   726
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   727
\begin{figure} \underscoreon
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   728
\begin{ttbox}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   729
\tdx{Inv_f_f}    inj(f) ==> Inv(f,f(x)) = x
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   730
\tdx{f_Inv_f}    y : range(f) ==> f(Inv(f,y)) = y
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   731
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   732
%\tdx{Inv_injective}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   733
%    [| Inv(f,x)=Inv(f,y); x: range(f);  y: range(f) |] ==> x=y
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   734
%
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   735
\tdx{imageI}     [| x:A |] ==> f(x) : f``A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   736
\tdx{imageE}     [| b : f``A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   737
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   738
\tdx{rangeI}     f(x) : range(f)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   739
\tdx{rangeE}     [| b : range(f);  !!x.[| b=f(x) |] ==> P |] ==> P
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   740
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   741
\tdx{monoI}      [| !!A B. A <= B ==> f(A) <= f(B) |] ==> mono(f)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   742
\tdx{monoD}      [| mono(f);  A <= B |] ==> f(A) <= f(B)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   743
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   744
\tdx{injI}       [| !! x y. f(x) = f(y) ==> x=y |] ==> inj(f)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   745
\tdx{inj_inverseI}              (!!x. g(f(x)) = x) ==> inj(f)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   746
\tdx{injD}       [| inj(f); f(x) = f(y) |] ==> x=y
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   747
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   748
\tdx{inj_ontoI}  (!!x y. [| f(x)=f(y); x:A; y:A |] ==> x=y) ==> inj_onto(f,A)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   749
\tdx{inj_ontoD}  [| inj_onto(f,A);  f(x)=f(y);  x:A;  y:A |] ==> x=y
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   750
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   751
\tdx{inj_onto_inverseI}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   752
    (!!x. x:A ==> g(f(x)) = x) ==> inj_onto(f,A)
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   753
\tdx{inj_onto_contraD}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   754
    [| inj_onto(f,A);  x~=y;  x:A;  y:A |] ==> ~ f(x)=f(y)
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   755
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   756
\caption{Derived rules involving functions} \label{hol-fun}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   757
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   758
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   759
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   760
\begin{figure} \underscoreon
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   761
\begin{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   762
\tdx{Union_upper}     B:A ==> B <= Union(A)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   763
\tdx{Union_least}     [| !!X. X:A ==> X<=C |] ==> Union(A) <= C
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   764
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   765
\tdx{Inter_lower}     B:A ==> Inter(A) <= B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   766
\tdx{Inter_greatest}  [| !!X. X:A ==> C<=X |] ==> C <= Inter(A)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   767
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   768
\tdx{Un_upper1}       A <= A Un B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   769
\tdx{Un_upper2}       B <= A Un B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   770
\tdx{Un_least}        [| A<=C;  B<=C |] ==> A Un B <= C
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   771
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   772
\tdx{Int_lower1}      A Int B <= A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   773
\tdx{Int_lower2}      A Int B <= B
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   774
\tdx{Int_greatest}    [| C<=A;  C<=B |] ==> C <= A Int B
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   775
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   776
\caption{Derived rules involving subsets} \label{hol-subset}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   777
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   778
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   779
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   780
\begin{figure} \underscoreon   \hfuzz=4pt%suppress "Overfull \hbox" message
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   781
\begin{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   782
\tdx{Int_absorb}        A Int A = A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   783
\tdx{Int_commute}       A Int B = B Int A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   784
\tdx{Int_assoc}         (A Int B) Int C  =  A Int (B Int C)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   785
\tdx{Int_Un_distrib}    (A Un B)  Int C  =  (A Int C) Un (B Int C)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   786
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   787
\tdx{Un_absorb}         A Un A = A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   788
\tdx{Un_commute}        A Un B = B Un A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   789
\tdx{Un_assoc}          (A Un B)  Un C  =  A Un (B Un C)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   790
\tdx{Un_Int_distrib}    (A Int B) Un C  =  (A Un C) Int (B Un C)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   791
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   792
\tdx{Compl_disjoint}    A Int Compl(A) = \{x.False\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   793
\tdx{Compl_partition}   A Un  Compl(A) = \{x.True\}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   794
\tdx{double_complement} Compl(Compl(A)) = A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   795
\tdx{Compl_Un}          Compl(A Un B)  = Compl(A) Int Compl(B)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   796
\tdx{Compl_Int}         Compl(A Int B) = Compl(A) Un Compl(B)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   797
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   798
\tdx{Union_Un_distrib}  Union(A Un B) = Union(A) Un Union(B)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   799
\tdx{Int_Union}         A Int Union(B) = (UN C:B. A Int C)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   800
\tdx{Un_Union_image}    (UN x:C. A(x) Un B(x)) = Union(A``C) Un Union(B``C)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   801
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   802
\tdx{Inter_Un_distrib}  Inter(A Un B) = Inter(A) Int Inter(B)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   803
\tdx{Un_Inter}          A Un Inter(B) = (INT C:B. A Un C)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   804
\tdx{Int_Inter_image}   (INT x:C. A(x) Int B(x)) = Inter(A``C) Int Inter(B``C)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   805
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   806
\caption{Set equalities} \label{hol-equalities}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   807
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   808
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   809
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   810
Figures~\ref{hol-set1} and~\ref{hol-set2} present derived rules.  Most are
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   811
obvious and resemble rules of Isabelle's ZF set theory.  Certain rules, such
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   812
as \tdx{subsetCE}, \tdx{bexCI} and \tdx{UnCI}, are designed for classical
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   813
reasoning; the rules \tdx{subsetD}, \tdx{bexI}, \tdx{Un1} and~\tdx{Un2} are
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   814
not strictly necessary but yield more natural proofs.  Similarly,
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   815
\tdx{equalityCE} supports classical reasoning about extensionality, after the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   816
fashion of \tdx{iffCE}.  See the file {\tt HOL/Set.ML} for proofs pertaining
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   817
to set theory.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   818
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   819
Figure~\ref{hol-fun} presents derived inference rules involving functions.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   820
They also include rules for \cdx{Inv}, which is defined in theory~{\tt
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   821
  HOL}; note that ${\tt Inv}(f)$ applies the Axiom of Choice to yield an
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   822
inverse of~$f$.  They also include natural deduction rules for the image
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   823
and range operators, and for the predicates {\tt inj} and {\tt inj_onto}.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   824
Reasoning about function composition (the operator~\sdx{o}) and the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   825
predicate~\cdx{surj} is done simply by expanding the definitions.  See
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   826
the file {\tt HOL/fun.ML} for a complete listing of the derived rules.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   827
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   828
Figure~\ref{hol-subset} presents lattice properties of the subset relation.
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   829
Unions form least upper bounds; non-empty intersections form greatest lower
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   830
bounds.  Reasoning directly about subsets often yields clearer proofs than
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   831
reasoning about the membership relation.  See the file {\tt HOL/subset.ML}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   832
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   833
Figure~\ref{hol-equalities} presents many common set equalities.  They
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   834
include commutative, associative and distributive laws involving unions,
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   835
intersections and complements.  The proofs are mostly trivial, using the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   836
classical reasoner; see file {\tt HOL/equalities.ML}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   837
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   838
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   839
\begin{figure}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   840
\begin{constants}
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   841
  \it symbol    & \it meta-type &           & \it description \\ 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   842
  \cdx{Pair}    & $[\alpha,\beta]\To \alpha\times\beta$
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   843
        & & ordered pairs $\langle a,b\rangle$ \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   844
  \cdx{fst}     & $\alpha\times\beta \To \alpha$        & & first projection\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   845
  \cdx{snd}     & $\alpha\times\beta \To \beta$         & & second projection\\
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   846
  \cdx{split}   & $[[\alpha,\beta]\To\gamma, \alpha\times\beta] \To \gamma$ 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   847
        & & generalized projection\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   848
  \cdx{Sigma}  & 
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   849
        $[\alpha\,set, \alpha\To\beta\,set]\To(\alpha\times\beta)set$ &
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   850
        & general sum of sets
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   851
\end{constants}
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   852
\begin{ttbox}\makeatletter
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   853
\tdx{fst_def}      fst(p)     == @a. ? b. p = <a,b>
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   854
\tdx{snd_def}      snd(p)     == @b. ? a. p = <a,b>
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   855
\tdx{split_def}    split(c,p) == c(fst(p),snd(p))
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   856
\tdx{Sigma_def}    Sigma(A,B) == UN x:A. UN y:B(x). \{<x,y>\}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   857
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   858
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   859
\tdx{Pair_inject}  [| <a, b> = <a',b'>;  [| a=a';  b=b' |] ==> R |] ==> R
349
0ddc495e8b83 post-CRC corrections
lcp
parents: 344
diff changeset
   860
\tdx{fst_conv}     fst(<a,b>) = a
0ddc495e8b83 post-CRC corrections
lcp
parents: 344
diff changeset
   861
\tdx{snd_conv}     snd(<a,b>) = b
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   862
\tdx{split}        split(c, <a,b>) = c(a,b)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   863
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   864
\tdx{surjective_pairing}  p = <fst(p),snd(p)>
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   865
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   866
\tdx{SigmaI}       [| a:A;  b:B(a) |] ==> <a,b> : Sigma(A,B)
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   867
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   868
\tdx{SigmaE}       [| c: Sigma(A,B);  
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   869
                !!x y.[| x:A; y:B(x); c=<x,y> |] ==> P |] ==> P
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   870
\end{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   871
\caption{Type $\alpha\times\beta$}\label{hol-prod}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   872
\end{figure} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   873
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   874
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   875
\begin{figure}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   876
\begin{constants}
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   877
  \it symbol    & \it meta-type &           & \it description \\ 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   878
  \cdx{Inl}     & $\alpha \To \alpha+\beta$    & & first injection\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   879
  \cdx{Inr}     & $\beta \To \alpha+\beta$     & & second injection\\
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   880
  \cdx{sum_case} & $[\alpha\To\gamma, \beta\To\gamma, \alpha+\beta] \To\gamma$
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   881
        & & conditional
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   882
\end{constants}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   883
\begin{ttbox}\makeatletter
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   884
\tdx{sum_case_def}   sum_case == (\%f g p. @z. (!x. p=Inl(x) --> z=f(x)) &
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   885
                                        (!y. p=Inr(y) --> z=g(y)))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   886
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   887
\tdx{Inl_not_Inr}    ~ Inl(a)=Inr(b)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   888
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   889
\tdx{inj_Inl}        inj(Inl)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   890
\tdx{inj_Inr}        inj(Inr)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   891
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   892
\tdx{sumE}           [| !!x::'a. P(Inl(x));  !!y::'b. P(Inr(y)) |] ==> P(s)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   893
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   894
\tdx{sum_case_Inl}   sum_case(f, g, Inl(x)) = f(x)
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   895
\tdx{sum_case_Inr}   sum_case(f, g, Inr(x)) = g(x)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   896
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   897
\tdx{surjective_sum} sum_case(\%x::'a. f(Inl(x)), \%y::'b. f(Inr(y)), s) = f(s)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   898
\end{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   899
\caption{Type $\alpha+\beta$}\label{hol-sum}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   900
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   901
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   902
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   903
\section{Generic packages and classical reasoning}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   904
HOL instantiates most of Isabelle's generic packages; see {\tt HOL/ROOT.ML}
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   905
for details.
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   906
\begin{itemize}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   907
\item Because it includes a general substitution rule, HOL instantiates the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   908
  tactic {\tt hyp_subst_tac}, which substitutes for an equality throughout a
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   909
  subgoal and its hypotheses.
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   910
\item 
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   911
It instantiates the simplifier, defining~\ttindexbold{HOL_ss} as the
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   912
simplification set for higher-order logic.  Equality~($=$), which also
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   913
expresses logical equivalence, may be used for rewriting.  See the file
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   914
{\tt HOL/simpdata.ML} for a complete listing of the simplification
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   915
rules. 
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   916
\item 
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   917
It instantiates the classical reasoner, as described below. 
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   918
\end{itemize}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   919
HOL derives classical introduction rules for $\disj$ and~$\exists$, as well as
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   920
classical elimination rules for~$\imp$ and~$\bimp$, and the swap rule; recall
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   921
Fig.\ts\ref{hol-lemmas2} above.
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   922
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   923
The classical reasoner is set up as the structure {\tt Classical}.  This
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   924
structure is open, so {\ML} identifiers such as {\tt step_tac}, {\tt
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   925
  fast_tac}, {\tt best_tac}, etc., refer to it.  HOL defines the following
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
   926
classical rule sets:
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   927
\begin{ttbox} 
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   928
prop_cs    : claset
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   929
HOL_cs     : claset
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   930
set_cs     : claset
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   931
\end{ttbox}
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   932
\begin{ttdescription}
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   933
\item[\ttindexbold{prop_cs}] contains the propositional rules, namely
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   934
those for~$\top$, $\bot$, $\conj$, $\disj$, $\neg$, $\imp$ and~$\bimp$,
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   935
along with the rule~{\tt refl}.
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   936
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   937
\item[\ttindexbold{HOL_cs}] extends {\tt prop_cs} with the safe rules
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   938
  {\tt allI} and~{\tt exE} and the unsafe rules {\tt allE}
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   939
  and~{\tt exI}, as well as rules for unique existence.  Search using
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   940
  this classical set is incomplete: quantified formulae are used at most
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   941
  once.
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   942
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   943
\item[\ttindexbold{set_cs}] extends {\tt HOL_cs} with rules for the bounded
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   944
  quantifiers, subsets, comprehensions, unions and intersections,
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   945
  complements, finite sets, images and ranges.
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   946
\end{ttdescription}
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   947
\noindent
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   948
See \iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   949
        {Chap.\ts\ref{chap:classical}} 
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   950
for more discussion of classical proof methods.
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   951
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   952
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   953
\section{Types}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   954
The basic higher-order logic is augmented with a tremendous amount of
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   955
material, including support for recursive function and type definitions.  A
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   956
detailed discussion appears elsewhere~\cite{paulson-coind}.  The simpler
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   957
definitions are the same as those used the {\sc hol} system, but my
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   958
treatment of recursive types differs from Melham's~\cite{melham89}.  The
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   959
present section describes product, sum, natural number and list types.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   960
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   961
\subsection{Product and sum types}\index{*"* type}\index{*"+ type}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   962
Theory \thydx{Prod} defines the product type $\alpha\times\beta$, with
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   963
the ordered pair syntax {\tt<$a$,$b$>}.  Theory \thydx{Sum} defines the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   964
sum type $\alpha+\beta$.  These use fairly standard constructions; see
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   965
Figs.\ts\ref{hol-prod} and~\ref{hol-sum}.  Because Isabelle does not
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   966
support abstract type definitions, the isomorphisms between these types and
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   967
their representations are made explicitly.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   968
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   969
Most of the definitions are suppressed, but observe that the projections
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   970
and conditionals are defined as descriptions.  Their properties are easily
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   971
proved using \tdx{select_equality}.  
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   972
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   973
\begin{figure} 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   974
\index{*"< symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   975
\index{*"* symbol}
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   976
\index{*div symbol}
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   977
\index{*mod symbol}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   978
\index{*"+ symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   979
\index{*"- symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   980
\begin{constants}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   981
  \it symbol    & \it meta-type & \it priority & \it description \\ 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   982
  \cdx{0}       & $nat$         & & zero \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   983
  \cdx{Suc}     & $nat \To nat$ & & successor function\\
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   984
  \cdx{nat_case} & $[\alpha, nat\To\alpha, nat] \To\alpha$
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   985
        & & conditional\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   986
  \cdx{nat_rec} & $[nat, \alpha, [nat, \alpha]\To\alpha] \To \alpha$
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   987
        & & primitive recursor\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   988
  \cdx{pred_nat} & $(nat\times nat) set$ & & predecessor relation\\
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   989
  \tt *         & $[nat,nat]\To nat$    &  Left 70      & multiplication \\
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   990
  \tt div       & $[nat,nat]\To nat$    &  Left 70      & division\\
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   991
  \tt mod       & $[nat,nat]\To nat$    &  Left 70      & modulus\\
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   992
  \tt +         & $[nat,nat]\To nat$    &  Left 65      & addition\\
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
   993
  \tt -         & $[nat,nat]\To nat$    &  Left 65      & subtraction
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
   994
\end{constants}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   995
\subcaption{Constants and infixes}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   996
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
   997
\begin{ttbox}\makeatother
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
   998
\tdx{nat_case_def}  nat_case == (\%a f n. @z. (n=0 --> z=a) & 
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
   999
                                       (!x. n=Suc(x) --> z=f(x)))
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1000
\tdx{pred_nat_def}  pred_nat == \{p. ? n. p = <n, Suc(n)>\} 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1001
\tdx{less_def}      m<n      == <m,n>:pred_nat^+
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1002
\tdx{nat_rec_def}   nat_rec(n,c,d) == 
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
  1003
               wfrec(pred_nat, n, nat_case(\%g.c, \%m g. d(m,g(m))))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1004
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1005
\tdx{add_def}   m+n     == nat_rec(m, n, \%u v.Suc(v))
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1006
\tdx{diff_def}  m-n     == nat_rec(n, m, \%u v. nat_rec(v, 0, \%x y.x))
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1007
\tdx{mult_def}  m*n     == nat_rec(m, 0, \%u v. n + v)
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1008
\tdx{mod_def}   m mod n == wfrec(trancl(pred_nat), m, \%j f. if(j<n,j,f(j-n)))
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1009
\tdx{quo_def}   m div n == wfrec(trancl(pred_nat), 
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
  1010
                        m, \%j f. if(j<n,0,Suc(f(j-n))))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1011
\subcaption{Definitions}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1012
\end{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1013
\caption{Defining {\tt nat}, the type of natural numbers} \label{hol-nat1}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1014
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1015
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1016
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
  1017
\begin{figure} \underscoreon
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1018
\begin{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1019
\tdx{nat_induct}     [| P(0); !!k. [| P(k) |] ==> P(Suc(k)) |]  ==> P(n)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1020
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1021
\tdx{Suc_not_Zero}   Suc(m) ~= 0
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1022
\tdx{inj_Suc}        inj(Suc)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1023
\tdx{n_not_Suc_n}    n~=Suc(n)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1024
\subcaption{Basic properties}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1025
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1026
\tdx{pred_natI}      <n, Suc(n)> : pred_nat
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1027
\tdx{pred_natE}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1028
    [| p : pred_nat;  !!x n. [| p = <n, Suc(n)> |] ==> R |] ==> R
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1029
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
  1030
\tdx{nat_case_0}     nat_case(a, f, 0) = a
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
  1031
\tdx{nat_case_Suc}   nat_case(a, f, Suc(k)) = f(k)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1032
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1033
\tdx{wf_pred_nat}    wf(pred_nat)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1034
\tdx{nat_rec_0}      nat_rec(0,c,h) = c
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1035
\tdx{nat_rec_Suc}    nat_rec(Suc(n), c, h) = h(n, nat_rec(n,c,h))
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1036
\subcaption{Case analysis and primitive recursion}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1037
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1038
\tdx{less_trans}     [| i<j;  j<k |] ==> i<k
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1039
\tdx{lessI}          n < Suc(n)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1040
\tdx{zero_less_Suc}  0 < Suc(n)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1041
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1042
\tdx{less_not_sym}   n<m --> ~ m<n 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1043
\tdx{less_not_refl}  ~ n<n
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1044
\tdx{not_less0}      ~ n<0
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1045
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1046
\tdx{Suc_less_eq}    (Suc(m) < Suc(n)) = (m<n)
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1047
\tdx{less_induct}    [| !!n. [| ! m. m<n --> P(m) |] ==> P(n) |]  ==>  P(n)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1048
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1049
\tdx{less_linear}    m<n | m=n | n<m
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1050
\subcaption{The less-than relation}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1051
\end{ttbox}
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1052
\caption{Derived rules for {\tt nat}} \label{hol-nat2}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1053
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1054
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1055
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1056
\subsection{The type of natural numbers, {\tt nat}}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1057
The theory \thydx{Nat} defines the natural numbers in a roundabout but
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1058
traditional way.  The axiom of infinity postulates an type~\tydx{ind} of
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1059
individuals, which is non-empty and closed under an injective operation.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1060
The natural numbers are inductively generated by choosing an arbitrary
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1061
individual for~0 and using the injective operation to take successors.  As
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1062
usual, the isomorphisms between~\tydx{nat} and its representation are made
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1063
explicitly.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1064
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1065
The definition makes use of a least fixed point operator \cdx{lfp},
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1066
defined using the Knaster-Tarski theorem.  This is used to define the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1067
operator \cdx{trancl}, for taking the transitive closure of a relation.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1068
Primitive recursion makes use of \cdx{wfrec}, an operator for recursion
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1069
along arbitrary well-founded relations.  The corresponding theories are
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1070
called {\tt Lfp}, {\tt Trancl} and {\tt WF}\@.  Elsewhere I have described
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1071
similar constructions in the context of set theory~\cite{paulson-set-II}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1072
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1073
Type~\tydx{nat} is postulated to belong to class~\cldx{ord}, which overloads
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1074
$<$ and $\leq$ on the natural numbers.  As of this writing, Isabelle provides
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1075
no means of verifying that such overloading is sensible; there is no means of
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1076
specifying the operators' properties and verifying that instances of the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1077
operators satisfy those properties.  To be safe, the HOL theory includes no
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1078
polymorphic axioms asserting general properties of $<$ and~$\leq$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1079
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1080
Theory \thydx{Arith} develops arithmetic on the natural numbers.  It
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1081
defines addition, multiplication, subtraction, division, and remainder.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1082
Many of their properties are proved: commutative, associative and
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1083
distributive laws, identity and cancellation laws, etc.  The most
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1084
interesting result is perhaps the theorem $a \bmod b + (a/b)\times b = a$.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1085
Division and remainder are defined by repeated subtraction, which requires
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1086
well-founded rather than primitive recursion.  See Figs.\ts\ref{hol-nat1}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1087
and~\ref{hol-nat2}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1088
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1089
The predecessor relation, \cdx{pred_nat}, is shown to be well-founded.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1090
Recursion along this relation resembles primitive recursion, but is
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1091
stronger because we are in higher-order logic; using primitive recursion to
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1092
define a higher-order function, we can easily Ackermann's function, which
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1093
is not primitive recursive \cite[page~104]{thompson91}.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1094
The transitive closure of \cdx{pred_nat} is~$<$.  Many functions on the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1095
natural numbers are most easily expressed using recursion along~$<$.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1096
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1097
The tactic {\tt\ttindex{nat_ind_tac} "$n$" $i$} performs induction over the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1098
variable~$n$ in subgoal~$i$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1099
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
  1100
\begin{figure}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1101
\index{#@{\tt\#} symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1102
\index{"@@{\tt\at} symbol}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1103
\begin{constants}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1104
  \it symbol & \it meta-type & \it priority & \it description \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1105
  \cdx{Nil}     & $\alpha list$ & & empty list\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1106
  \tt \#   & $[\alpha,\alpha list]\To \alpha list$ & Right 65 & 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1107
        list constructor \\
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1108
  \cdx{null}    & $\alpha list \To bool$ & & emptiness test\\
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1109
  \cdx{hd}      & $\alpha list \To \alpha$ & & head \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1110
  \cdx{tl}      & $\alpha list \To \alpha list$ & & tail \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1111
  \cdx{ttl}     & $\alpha list \To \alpha list$ & & total tail \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1112
  \tt\at  & $[\alpha list,\alpha list]\To \alpha list$ & Left 65 & append \\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1113
  \sdx{mem}  & $[\alpha,\alpha list]\To bool$    &  Left 55   & membership\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1114
  \cdx{map}     & $(\alpha\To\beta) \To (\alpha list \To \beta list)$
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1115
        & & mapping functional\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1116
  \cdx{filter}  & $(\alpha \To bool) \To (\alpha list \To \alpha list)$
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1117
        & & filter functional\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1118
  \cdx{list_all}& $(\alpha \To bool) \To (\alpha list \To bool)$
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1119
        & & forall functional\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1120
  \cdx{list_rec}        & $[\alpha list, \beta, [\alpha ,\alpha list,
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1121
\beta]\To\beta] \To \beta$
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1122
        & & list recursor
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1123
\end{constants}
306
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1124
\subcaption{Constants and infixes}
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1125
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1126
\begin{center} \tt\frenchspacing
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1127
\begin{tabular}{rrr} 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1128
  \it external        & \it internal  & \it description \\{}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1129
  \sdx{[]}            & Nil           & \rm empty list \\{}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1130
  [$x@1$, $\dots$, $x@n$]  &  $x@1$ \# $\cdots$ \# $x@n$ \# [] &
306
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1131
        \rm finite list \\{}
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1132
  [$x$:$l$. $P$]  & filter($\lambda x{.}P$, $l$) & 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1133
        \rm list comprehension
306
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1134
\end{tabular}
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1135
\end{center}
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1136
\subcaption{Translations}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1137
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1138
\begin{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1139
\tdx{list_induct}    [| P([]);  !!x xs. [| P(xs) |] ==> P(x#xs)) |]  ==> P(l)
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1140
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1141
\tdx{Cons_not_Nil}   (x # xs) ~= []
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1142
\tdx{Cons_Cons_eq}   ((x # xs) = (y # ys)) = (x=y & xs=ys)
306
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1143
\subcaption{Induction and freeness}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1144
\end{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1145
\caption{The theory \thydx{List}} \label{hol-list}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1146
\end{figure}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1147
306
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1148
\begin{figure}
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1149
\begin{ttbox}\makeatother
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1150
\tdx{list_rec_Nil}    list_rec([],c,h) = c  
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1151
\tdx{list_rec_Cons}   list_rec(a#l, c, h) = h(a, l, list_rec(l,c,h))
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1152
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
  1153
\tdx{list_case_Nil}   list_case(c, h, []) = c 
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
  1154
\tdx{list_case_Cons}  list_case(c, h, x#xs) = h(x, xs)
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1155
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1156
\tdx{map_Nil}         map(f,[]) = []
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1157
\tdx{map_Cons}        map(f, x \# xs) = f(x) \# map(f,xs)
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1158
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1159
\tdx{null_Nil}        null([]) = True
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1160
\tdx{null_Cons}       null(x#xs) = False
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1161
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1162
\tdx{hd_Cons}         hd(x#xs) = x
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1163
\tdx{tl_Cons}         tl(x#xs) = xs
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1164
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1165
\tdx{ttl_Nil}         ttl([]) = []
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1166
\tdx{ttl_Cons}        ttl(x#xs) = xs
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1167
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1168
\tdx{append_Nil}      [] @ ys = ys
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1169
\tdx{append_Cons}     (x#xs) \at ys = x # xs \at ys
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1170
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1171
\tdx{mem_Nil}         x mem [] = False
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1172
\tdx{mem_Cons}        x mem (y#ys) = if(y=x, True, x mem ys)
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1173
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1174
\tdx{filter_Nil}      filter(P, []) = []
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1175
\tdx{filter_Cons}     filter(P,x#xs) = if(P(x), x#filter(P,xs), filter(P,xs))
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1176
471
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1177
\tdx{list_all_Nil}    list_all(P,[]) = True
22325fd7234e indentation and renaming of rules
lcp
parents: 465
diff changeset
  1178
\tdx{list_all_Cons}   list_all(P, x#xs) = (P(x) & list_all(P, xs))
306
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1179
\end{ttbox}
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1180
\caption{Rewrite rules for lists} \label{hol-list-simps}
eee166d4a532 changed lists and added "let" and "case"
nipkow
parents: 287
diff changeset
  1181
\end{figure}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1182
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1183
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1184
\subsection{The type constructor for lists, {\tt list}}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1185
\index{*list type}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1186
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1187
HOL's definition of lists is an example of an experimental method for handling
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1188
recursive data types.  Figure~\ref{hol-list} presents the theory \thydx{List}:
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1189
the basic list operations with their types and properties.
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1190
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1191
The \sdx{case} construct is defined by the following translation:
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1192
{\dquotes
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1193
\begin{eqnarray*}
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1194
  \begin{array}{r@{\;}l@{}l}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1195
  "case " e " of" & "[]"    & " => " a\\
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1196
              "|" & x"\#"xs & " => " b
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1197
  \end{array} 
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1198
  & \equiv &
705
9fb068497df4 removal of HOL_dup_cs
lcp
parents: 629
diff changeset
  1199
  "list_case"(a, \lambda x\;xs.b, e)
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1200
\end{eqnarray*}}%
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1201
The theory includes \cdx{list_rec}, a primitive recursion operator
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1202
for lists.  It is derived from well-founded recursion, a general principle
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1203
that can express arbitrary total recursive functions.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1204
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1205
The simpset \ttindex{list_ss} contains, along with additional useful lemmas,
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1206
the basic rewrite rules that appear in Fig.\ts\ref{hol-list-simps}.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1207
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1208
The tactic {\tt\ttindex{list_ind_tac} "$xs$" $i$} performs induction over the
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1209
variable~$xs$ in subgoal~$i$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1210
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1211
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1212
\section{Datatype declarations}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1213
\index{*datatype|(}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1214
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1215
\underscoreon
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1216
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1217
It is often necessary to extend a theory with \ML-like datatypes.  This
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1218
extension consists of the new type, declarations of its constructors and
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1219
rules that describe the new type. The theory definition section {\tt
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1220
  datatype} represents a compact way of doing this.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1221
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1222
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1223
\subsection{Foundations}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1224
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1225
A datatype declaration has the following general structure:
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1226
\[ \mbox{\tt datatype}~ (\alpha_1,\dots,\alpha_n)t ~=~
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1227
      C_1(\tau_{11},\dots,\tau_{1k_1}) ~\mid~ \dots ~\mid~
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1228
      C_m(\tau_{m1},\dots,\tau_{mk_m}) 
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1229
\]
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1230
where $\alpha_i$ are type variables, $C_i$ are distinct constructor names and
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1231
$\tau_{ij}$ are one of the following:
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1232
\begin{itemize}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1233
\item type variables $\alpha_1,\dots,\alpha_n$,
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1234
\item types $(\beta_1,\dots,\beta_l)s$ where $s$ is a previously declared
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1235
  type or type synonym and $\{\beta_1,\dots,\beta_l\} \subseteq
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1236
  \{\alpha_1,\dots,\alpha_n\}$,
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1237
\item the newly defined type $(\alpha_1,\dots,\alpha_n)t$ \footnote{This
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1238
    makes it a recursive type. To ensure that the new type is not empty at
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1239
    least one constructor must consist of only non-recursive type
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1240
    components.}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1241
\end{itemize}
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1242
If you would like one of the $\tau_{ij}$ to be a complex type expression
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1243
$\tau$ you need to declare a new type synonym $syn = \tau$ first and use
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1244
$syn$ in place of $\tau$. Of course this does not work if $\tau$ mentions the
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1245
recursive type itself, thus ruling out problematic cases like \[ \mbox{\tt
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1246
  datatype}~ t ~=~ C(t \To t) \] together with unproblematic ones like \[
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1247
\mbox{\tt datatype}~ t ~=~ C(t~list). \]
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1248
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1249
The constructors are automatically defined as functions of their respective
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1250
type:
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1251
\[ C_j : [\tau_{j1},\dots,\tau_{jk_j}] \To (\alpha_1,\dots,\alpha_n)t \]
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1252
These functions have certain {\em freeness} properties:
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1253
\begin{description}
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1254
\item[\tt distinct] They are distinct:
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1255
\[ C_i(x_1,\dots,x_{k_i}) \neq C_j(y_1,\dots,y_{k_j}) \qquad
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1256
   \mbox{for all}~ i \neq j.
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1257
\]
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1258
\item[\tt inject] They are injective:
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1259
\[ (C_j(x_1,\dots,x_{k_j}) = C_j(y_1,\dots,y_{k_j})) =
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1260
   (x_1 = y_1 \land \dots \land x_{k_j} = y_{k_j})
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1261
\]
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1262
\end{description}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1263
Because the number of inequalities is quadratic in the number of
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1264
constructors, a different method is used if their number exceeds
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1265
a certain value, currently 4. In that case every constructor is mapped to a
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1266
natural number
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1267
\[
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1268
\begin{array}{lcl}
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1269
\mbox{\it t\_ord}(C_1(x_1,\dots,x_{k_1})) & = & 0 \\
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1270
& \vdots & \\
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1271
\mbox{\it t\_ord}(C_m(x_1,\dots,x_{k_m})) & = & m-1
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1272
\end{array}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1273
\]
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1274
and distinctness of constructors is expressed by:
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1275
\[
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1276
\mbox{\it t\_ord}(x) \neq \mbox{\it t\_ord}(y) \Imp x \neq y.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1277
\]
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1278
In addition a structural induction axiom {\tt induct} is provided: 
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1279
\[
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1280
\infer{P(x)}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1281
{\begin{array}{lcl}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1282
\Forall x_1\dots x_{k_1}.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1283
  \List{P(x_{r_{11}}); \dots; P(x_{r_{1l_1}})} &
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1284
  \Imp  & P(C_1(x_1,\dots,x_{k_1})) \\
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1285
 & \vdots & \\
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1286
\Forall x_1\dots x_{k_m}.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1287
  \List{P(x_{r_{m1}}); \dots; P(x_{r_{ml_m}})} &
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1288
  \Imp & P(C_m(x_1,\dots,x_{k_m}))
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1289
\end{array}}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1290
\]
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1291
where $\{r_{j1},\dots,r_{jl_j}\} = \{i \in \{1,\dots k_j\} ~\mid~ \tau_{ji}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1292
= (\alpha_1,\dots,\alpha_n)t \}$, i.e.\ the property $P$ can be assumed for
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1293
all arguments of the recursive type.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1294
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1295
The type also comes with an \ML-like \sdx{case}-construct:
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1296
\[
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1297
\begin{array}{rrcl}
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1298
\mbox{\tt case}~e~\mbox{\tt of} & C_1(x_{11},\dots,x_{1k_1}) & \To & e_1 \\
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1299
                           \vdots \\
580
909e00299009 Updated datatype documentation with a few hints
nipkow
parents: 471
diff changeset
  1300
                           \mid & C_m(x_{m1},\dots,x_{mk_m}) & \To & e_m
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1301
\end{array}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1302
\]
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1303
In contrast to \ML, {\em all} constructors must be present, their order is
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1304
fixed, and nested patterns are not supported.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1305
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1306
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1307
\subsection{Defining datatypes}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1308
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1309
A datatype is defined in a theory definition file using the keyword {\tt
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1310
  datatype}. The definition following {\tt datatype} must conform to the
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1311
syntax of {\em typedecl} specified in Fig.~\ref{datatype-grammar} and must
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1312
obey the rules in the previous section. As a result the theory is extended
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1313
with the new type, the constructors, and the theorems listed in the previous
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1314
section.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1315
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1316
\begin{figure}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1317
\begin{rail}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1318
typedecl : typevarlist id '=' (cons + '|')
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1319
         ;
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1320
cons     : (id | string) ( () | '(' (typ + ',') ')' ) ( () | mixfix )
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1321
         ;
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1322
typ      : typevarlist id
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1323
           | tid
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1324
         ;
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1325
typevarlist : () | tid | '(' (tid + ',') ')'
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1326
         ;
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1327
\end{rail}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1328
\caption{Syntax of datatype declarations}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1329
\label{datatype-grammar}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1330
\end{figure}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1331
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1332
Reading the theory file produces a structure which, in addition to the usual
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1333
components, contains a structure named $t$ for each datatype $t$ defined in
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1334
the file.\footnote{Otherwise multiple datatypes in the same theory file would
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1335
  lead to name clashes.} Each structure $t$ contains the following elements:
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1336
\begin{ttbox}
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1337
val distinct : thm list
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1338
val inject : thm list
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1339
val induct : thm
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1340
val cases : thm list
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1341
val simps : thm list
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1342
val induct_tac : string -> int -> tactic
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1343
\end{ttbox}
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1344
{\tt distinct}, {\tt inject} and {\tt induct} contain the theorems described
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1345
above. For convenience {\tt distinct} contains inequalities in both
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1346
directions.
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1347
\begin{warn}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1348
  If there are five or more constructors, the {\em t\_ord} scheme is used for
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1349
  {\tt distinct}.  In this case the theory {\tt Arith} must be contained
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1350
  in the current theory, if necessary by including it explicitly.
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1351
\end{warn}
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1352
The reduction rules of the {\tt case}-construct are in {\tt cases}.  All
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1353
theorems from {\tt distinct}, {\tt inject} and {\tt cases} are combined in
1086
46a7b619e62e trivial change
lcp
parents: 861
diff changeset
  1354
{\tt simps} for use with the simplifier. The tactic {\verb$induct_tac$~{\em
46a7b619e62e trivial change
lcp
parents: 861
diff changeset
  1355
    var i}\/} applies structural induction over variable {\em var} to
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1356
subgoal {\em i}.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1357
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1358
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1359
\subsection{Examples}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1360
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1361
\subsubsection{The datatype $\alpha~list$}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1362
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1363
We want to define the type $\alpha~list$.\footnote{Of course there is a list
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1364
  type in HOL already. This is only an example.} To do this we have to build
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1365
a new theory that contains the type definition. We start from {\tt HOL}.
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1366
\begin{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1367
MyList = HOL +
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1368
  datatype 'a list = Nil | Cons ('a, 'a list)
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1369
end
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1370
\end{ttbox}
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1371
After loading the theory (\verb$use_thy "MyList"$), we can prove
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1372
$Cons(x,xs)\neq xs$.  First we build a suitable simpset for the simplifier:
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1373
\begin{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1374
val mylist_ss = HOL_ss addsimps MyList.list.simps;
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1375
goal MyList.thy "!x. Cons(x,xs) ~= xs";
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1376
{\out Level 0}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1377
{\out ! x. Cons(x, xs) ~= xs}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1378
{\out  1. ! x. Cons(x, xs) ~= xs}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1379
\end{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1380
This can be proved by the structural induction tactic:
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1381
\begin{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1382
by (MyList.list.induct_tac "xs" 1);
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1383
{\out Level 1}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1384
{\out ! x. Cons(x, xs) ~= xs}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1385
{\out  1. ! x. Cons(x, Nil) ~= Nil}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1386
{\out  2. !!a list.}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1387
{\out        ! x. Cons(x, list) ~= list ==>}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1388
{\out        ! x. Cons(x, Cons(a, list)) ~= Cons(a, list)}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1389
\end{ttbox}
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1390
The first subgoal can be proved with the simplifier and the distinctness
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1391
axioms which are part of \verb$mylist_ss$.
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1392
\begin{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1393
by (simp_tac mylist_ss 1);
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1394
{\out Level 2}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1395
{\out ! x. Cons(x, xs) ~= xs}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1396
{\out  1. !!a list.}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1397
{\out        ! x. Cons(x, list) ~= list ==>}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1398
{\out        ! x. Cons(x, Cons(a, list)) ~= Cons(a, list)}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1399
\end{ttbox}
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1400
Using the freeness axioms we can quickly prove the remaining goal.
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1401
\begin{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1402
by (asm_simp_tac mylist_ss 1);
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1403
{\out Level 3}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1404
{\out ! x. Cons(x, xs) ~= xs}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1405
{\out No subgoals!}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1406
\end{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1407
Because both subgoals were proved by almost the same tactic we could have
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1408
done that in one step using
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1409
\begin{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1410
by (ALLGOALS (asm_simp_tac mylist_ss));
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1411
\end{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1412
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1413
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1414
\subsubsection{The datatype $\alpha~list$ with mixfix syntax}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1415
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1416
In this example we define the type $\alpha~list$ again but this time we want
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1417
to write {\tt []} instead of {\tt Nil} and we want to use the infix operator
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1418
\verb|#| instead of {\tt Cons}. To do this we simply add mixfix annotations
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1419
after the constructor declarations as follows:
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1420
\begin{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1421
MyList = HOL +
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1422
  datatype 'a list = "[]" ("[]") 
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1423
                   | "#" ('a, 'a list) (infixr 70)
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1424
end
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1425
\end{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1426
Now the theorem in the previous example can be written \verb|x#xs ~= xs|. The
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1427
proof is the same.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1428
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1429
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1430
\subsubsection{A datatype for weekdays}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1431
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1432
This example shows a datatype that consists of more than four constructors:
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1433
\begin{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1434
Days = Arith +
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1435
  datatype days = Mo | Tu | We | Th | Fr | Sa | So
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1436
end
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1437
\end{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1438
Because there are more than four constructors, the theory must be based on
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1439
{\tt Arith}. Inequality is defined via a function \verb|days_ord|. Although
465
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1440
the expression \verb|Mo ~= Tu| is not directly contained in {\tt distinct},
d4bf81734dfe Corrected HOL.tex
nipkow
parents: 464
diff changeset
  1441
it can be proved by the simplifier if \verb$arith_ss$ is used:
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1442
\begin{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1443
val days_ss = arith_ss addsimps Days.days.simps;
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1444
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1445
goal Days.thy "Mo ~= Tu";
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1446
by (simp_tac days_ss 1);
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1447
\end{ttbox}
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1448
Note that usually it is not necessary to derive these inequalities explicitly
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1449
because the simplifier will dispose of them automatically.
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1450
600
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1451
\subsection{Primitive recursive functions}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1452
\index{primitive recursion|(}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1453
\index{*primrec|(}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1454
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1455
Datatypes come with a uniform way of defining functions, {\bf primitive
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1456
  recursion}. Although it is possible to define primitive recursive functions
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1457
by asserting their reduction rules as new axioms, e.g.\
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1458
\begin{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1459
Append = MyList +
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1460
consts app :: "['a list,'a list] => 'a list"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1461
rules 
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1462
   app_Nil   "app([],ys) = ys"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1463
   app_Cons  "app(x#xs, ys) = x#app(xs,ys)"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1464
end
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1465
\end{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1466
this carries with it the danger of accidentally asserting an inconsistency,
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1467
as in \verb$app([],ys) = us$. Therefore primitive recursive functions on
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1468
datatypes can be defined with a special syntax:
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1469
\begin{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1470
Append = MyList +
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1471
consts app :: "['a list,'a list] => 'a list"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1472
primrec app MyList.list
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1473
   app_Nil   "app([],ys) = ys"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1474
   app_Cons  "app(x#xs, ys) = x#app(xs,ys)"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1475
end
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1476
\end{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1477
The system will now check that the two rules \verb$app_Nil$ and
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1478
\verb$app_Cons$ do indeed form a primitive recursive definition, thus
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1479
ensuring that consistency is maintained. For example
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1480
\begin{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1481
primrec app MyList.list
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1482
    app_Nil   "app([],ys) = us"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1483
\end{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1484
is rejected:
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1485
\begin{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1486
Extra variables on rhs
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1487
\end{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1488
\bigskip
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1489
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1490
The general form of a primitive recursive definition is
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1491
\begin{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1492
primrec {\it function} {\it type}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1493
    {\it reduction rules}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1494
\end{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1495
where
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1496
\begin{itemize}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1497
\item {\it function} is the name of the function, either as an {\it id} or a
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1498
  {\it string}. The function must already have been declared.
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1499
\item {\it type} is the name of the datatype, either as an {\it id} or in the
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1500
  long form {\it Thy.t}, where {\it Thy} is the name of the parent theory the
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1501
  datatype was declared in, and $t$ the name of the datatype. The long form
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1502
  is required if the {\tt datatype} and the {\tt primrec} sections are in
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1503
  different theories.
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1504
\item {\it reduction rules} specify one or more named equations of the form
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1505
  {\it id\/}~{\it string}, where the identifier gives the name of the rule in
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1506
  the result structure, and {\it string} is a reduction rule of the form \[
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1507
  f(x_1,\dots,x_m,C(y_1,\dots,y_k),z_1,\dots,z_n) = r \] such that $C$ is a
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1508
  constructor of the datatype, $r$ contains only the free variables on the
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1509
  left-hand side, and all recursive calls in $r$ are of the form
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1510
  $f(\dots,y_i,\dots)$ for some $i$. There must be exactly one reduction
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1511
  rule for each constructor.
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1512
\end{itemize}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1513
A theory file may contain any number of {\tt primrec} sections which may be
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1514
intermixed with other declarations.
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1515
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1516
For the consistency-sensitive user it may be reassuring to know that {\tt
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1517
  primrec} does not assert the reduction rules as new axioms but derives them
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1518
as theorems from an explicit definition of the recursive function in terms of
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1519
a recursion operator on the datatype.
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1520
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1521
The primitive recursive function can also use infix or mixfix syntax:
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1522
\begin{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1523
Append = MyList +
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1524
consts "@"  :: "['a list,'a list] => 'a list"  (infixr 60)
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1525
primrec "op @" MyList.list
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1526
   app_Nil   "[] @ ys = ys"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1527
   app_Cons  "(x#xs) @ ys = x#(xs @ ys)"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1528
end
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1529
\end{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1530
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1531
The reduction rules become part of the ML structure \verb$Append$ and can
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1532
be used to prove theorems about the function:
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1533
\begin{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1534
val append_ss = HOL_ss addsimps [Append.app_Nil,Append.app_Cons];
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1535
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1536
goal Append.thy "(xs @ ys) @ zs = xs @ (ys @ zs)";
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1537
by (MyList.list.induct_tac "xs" 1);
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1538
by (ALLGOALS(asm_simp_tac append_ss));
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1539
\end{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1540
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1541
%Note that underdefined primitive recursive functions are allowed:
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1542
%\begin{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1543
%Tl = MyList +
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1544
%consts tl  :: "'a list => 'a list"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1545
%primrec tl MyList.list
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1546
%   tl_Cons "tl(x#xs) = xs"
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1547
%end
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1548
%\end{ttbox}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1549
%Nevertheless {\tt tl} is total, although we do not know what the result of
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1550
%\verb$tl([])$ is.
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1551
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1552
\index{primitive recursion|)}
d9133e7ed38a Added primrec section.
nipkow
parents: 594
diff changeset
  1553
\index{*primrec|)}
861
28a593f4b600 Corrected indexing of *datatype
lcp
parents: 841
diff changeset
  1554
\index{*datatype|)}
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1555
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1556
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1557
\section{Inductive and coinductive definitions}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1558
\index{*inductive|(}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1559
\index{*coinductive|(}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1560
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1561
An {\bf inductive definition} specifies the least set closed under given
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1562
rules.  For example, a structural operational semantics is an inductive
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1563
definition of an evaluation relation.  Dually, a {\bf coinductive
2975
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 1086
diff changeset
  1564
  definition} specifies the greatest set consistent with given rules.  An
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1565
important example is using bisimulation relations to formalize equivalence
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1566
of processes and infinite data structures.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1567
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1568
A theory file may contain any number of inductive and coinductive
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1569
definitions.  They may be intermixed with other declarations; in
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1570
particular, the (co)inductive sets {\bf must} be declared separately as
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1571
constants, and may have mixfix syntax or be subject to syntax translations.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1572
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1573
Each (co)inductive definition adds definitions to the theory and also
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1574
proves some theorems.  Each definition creates an ML structure, which is a
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1575
substructure of the main theory structure.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1576
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1577
This package is derived from the ZF one, described in a
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1578
separate paper,\footnote{It appeared in CADE~\cite{paulson-CADE} and a
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1579
  longer version is distributed with Isabelle.} which you should refer to
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1580
in case of difficulties.  The package is simpler than ZF's, thanks to HOL's
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1581
automatic type-checking.  The type of the (co)inductive determines the
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1582
domain of the fixedpoint definition, and the package does not use inference
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1583
rules for type-checking.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1584
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1585
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1586
\subsection{The result structure}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1587
Many of the result structure's components have been discussed in the paper;
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1588
others are self-explanatory.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1589
\begin{description}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1590
\item[\tt thy] is the new theory containing the recursive sets.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1591
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1592
\item[\tt defs] is the list of definitions of the recursive sets.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1593
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1594
\item[\tt mono] is a monotonicity theorem for the fixedpoint operator.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1595
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1596
\item[\tt unfold] is a fixedpoint equation for the recursive set (the union of
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1597
the recursive sets, in the case of mutual recursion).
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1598
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1599
\item[\tt intrs] is the list of introduction rules, now proved as theorems, for
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1600
the recursive sets.  The rules are also available individually, using the
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1601
names given them in the theory file. 
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1602
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1603
\item[\tt elim] is the elimination rule.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1604
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1605
\item[\tt mk\_cases] is a function to create simplified instances of {\tt
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1606
elim}, using freeness reasoning on some underlying datatype.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1607
\end{description}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1608
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1609
For an inductive definition, the result structure contains two induction rules,
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1610
{\tt induct} and \verb|mutual_induct|.  For a coinductive definition, it
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1611
contains the rule \verb|coinduct|.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1612
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1613
Figure~\ref{def-result-fig} summarizes the two result signatures,
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1614
specifying the types of all these components.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1615
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1616
\begin{figure}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1617
\begin{ttbox}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1618
sig
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1619
val thy          : theory
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1620
val defs         : thm list
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1621
val mono         : thm
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1622
val unfold       : thm
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1623
val intrs        : thm list
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1624
val elim         : thm
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1625
val mk_cases     : thm list -> string -> thm
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1626
{\it(Inductive definitions only)} 
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1627
val induct       : thm
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1628
val mutual_induct: thm
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1629
{\it(Coinductive definitions only)}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1630
val coinduct    : thm
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1631
end
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1632
\end{ttbox}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1633
\hrule
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1634
\caption{The result of a (co)inductive definition} \label{def-result-fig}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1635
\end{figure}
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1636
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1637
\subsection{The syntax of a (co)inductive definition}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1638
An inductive definition has the form
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1639
\begin{ttbox}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1640
inductive    {\it inductive sets}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1641
  intrs      {\it introduction rules}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1642
  monos      {\it monotonicity theorems}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1643
  con_defs   {\it constructor definitions}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1644
\end{ttbox}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1645
A coinductive definition is identical, except that it starts with the keyword
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1646
{\tt coinductive}.  
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1647
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1648
The {\tt monos} and {\tt con\_defs} sections are optional.  If present,
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1649
each is specified as a string, which must be a valid ML expression of type
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1650
{\tt thm list}.  It is simply inserted into the {\tt .thy.ML} file; if it
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1651
is ill-formed, it will trigger ML error messages.  You can then inspect the
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1652
file on your directory.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1653
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1654
\begin{itemize}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1655
\item The {\it inductive sets} are specified by one or more strings.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1656
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1657
\item The {\it introduction rules} specify one or more introduction rules in
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1658
  the form {\it ident\/}~{\it string}, where the identifier gives the name of
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1659
  the rule in the result structure.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1660
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1661
\item The {\it monotonicity theorems} are required for each operator
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1662
  applied to a recursive set in the introduction rules.  There {\bf must}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1663
  be a theorem of the form $A\subseteq B\Imp M(A)\subseteq M(B)$, for each
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1664
  premise $t\in M(R_i)$ in an introduction rule!
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1665
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1666
\item The {\it constructor definitions} contain definitions of constants
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1667
  appearing in the introduction rules.  In most cases it can be omitted.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1668
\end{itemize}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1669
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1670
The package has a few notable restrictions:
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1671
\begin{itemize}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1672
\item The theory must separately declare the recursive sets as
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1673
  constants.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1674
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1675
\item The names of the recursive sets must be identifiers, not infix
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1676
operators.  
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1677
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1678
\item Side-conditions must not be conjunctions.  However, an introduction rule
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1679
may contain any number of side-conditions.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1680
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1681
\item Side-conditions of the form $x=t$, where the variable~$x$ does not
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1682
  occur in~$t$, will be substituted through the rule \verb|mutual_induct|.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1683
\end{itemize}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1684
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1685
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1686
\subsection{Example of an inductive definition}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1687
Two declarations, included in a theory file, define the finite powerset
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1688
operator.  First we declare the constant~{\tt Fin}.  Then we declare it
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1689
inductively, with two introduction rules:
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1690
\begin{ttbox}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1691
consts Fin :: "'a set => 'a set set"
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1692
inductive "Fin(A)"
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1693
  intrs
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1694
    emptyI  "{} : Fin(A)"
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1695
    insertI "[| a: A;  b: Fin(A) |] ==> insert(a,b) : Fin(A)"
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1696
\end{ttbox}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1697
The resulting theory structure contains a substructure, called~{\tt Fin}.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1698
It contains the {\tt Fin}$(A)$ introduction rules as the list {\tt Fin.intrs},
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1699
and also individually as {\tt Fin.emptyI} and {\tt Fin.consI}.  The induction
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1700
rule is {\tt Fin.induct}.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1701
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1702
For another example, here is a theory file defining the accessible part of a
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1703
relation.  The main thing to note is the use of~{\tt Pow} in the sole
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1704
introduction rule, and the corresponding mention of the rule
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1705
\verb|Pow_mono| in the {\tt monos} list.  The paper discusses a ZF version
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1706
of this example in more detail.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1707
\begin{ttbox}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1708
Acc = WF + 
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1709
consts pred :: "['b, ('a * 'b)set] => 'a set"   (*Set of predecessors*)
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1710
       acc  :: "('a * 'a)set => 'a set"         (*Accessible part*)
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1711
defs   pred_def  "pred(x,r) == {y. <y,x>:r}"
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1712
inductive "acc(r)"
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1713
  intrs
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1714
     pred "pred(a,r): Pow(acc(r)) ==> a: acc(r)"
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1715
  monos   "[Pow_mono]"
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1716
end
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1717
\end{ttbox}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1718
The HOL distribution contains many other inductive definitions, such as the
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1719
theory {\tt HOL/ex/PropLog.thy} and the directory {\tt HOL/IMP}.  The
629
c97f5a7cf763 Moving theory LList to ex directory
lcp
parents: 600
diff changeset
  1720
theory {\tt HOL/ex/LList.thy} contains coinductive definitions.
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1721
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1722
\index{*coinductive|)} \index{*inductive|)} \underscoreoff
464
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1723
552717636da4 added datatype section
nipkow
parents: 453
diff changeset
  1724
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1725
\section{The examples directories}
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1726
Directory {\tt HOL/Subst} contains Martin Coen's mechanisation of a theory of
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1727
substitutions and unifiers.  It is based on Paulson's previous
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1728
mechanisation in {\LCF}~\cite{paulson85} of Manna and Waldinger's
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1729
theory~\cite{mw81}. 
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1730
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1731
Directory {\tt HOL/IMP} contains a mechanised version of a semantic
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1732
equivalence proof taken from Winskel~\cite{winskel93}.  It formalises the
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1733
denotational and operational semantics of a simple while-language, then
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1734
proves the two equivalent.  It contains several datatype and inductive
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1735
definitions, and demonstrates their use.
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1736
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1737
Directory {\tt HOL/ex} contains other examples and experimental proofs in HOL.
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1738
Here is an overview of the more interesting files.
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1739
\begin{itemize}
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1740
\item File {\tt cla.ML} demonstrates the classical reasoner on over sixty
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1741
  predicate calculus theorems, ranging from simple tautologies to
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1742
  moderately difficult problems involving equality and quantifiers.
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1743
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1744
\item File {\tt meson.ML} contains an experimental implementation of the {\sc
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1745
    meson} proof procedure, inspired by Plaisted~\cite{plaisted90}.  It is
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1746
  much more powerful than Isabelle's classical reasoner.  But it is less
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1747
  useful in practice because it works only for pure logic; it does not
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1748
  accept derived rules for the set theory primitives, for example.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1749
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1750
\item File {\tt mesontest.ML} contains test data for the {\sc meson} proof
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1751
  procedure.  These are mostly taken from Pelletier \cite{pelletier86}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1752
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1753
\item File {\tt set.ML} proves Cantor's Theorem, which is presented in
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1754
  \S\ref{sec:hol-cantor} below, and the Schr\"oder-Bernstein Theorem.
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1755
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1756
\item Theories {\tt InSort} and {\tt Qsort} prove correctness properties of
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1757
  insertion sort and quick sort.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1758
629
c97f5a7cf763 Moving theory LList to ex directory
lcp
parents: 600
diff changeset
  1759
\item The definition of lazy lists demonstrates methods for handling
c97f5a7cf763 Moving theory LList to ex directory
lcp
parents: 600
diff changeset
  1760
  infinite data structures and coinduction in higher-order
c97f5a7cf763 Moving theory LList to ex directory
lcp
parents: 600
diff changeset
  1761
  logic~\cite{paulson-coind}.  Theory \thydx{LList} defines an operator for
c97f5a7cf763 Moving theory LList to ex directory
lcp
parents: 600
diff changeset
  1762
  corecursion on lazy lists, which is used to define a few simple functions
c97f5a7cf763 Moving theory LList to ex directory
lcp
parents: 600
diff changeset
  1763
  such as map and append.  Corecursion cannot easily define operations such
c97f5a7cf763 Moving theory LList to ex directory
lcp
parents: 600
diff changeset
  1764
  as filter, which can compute indefinitely before yielding the next
c97f5a7cf763 Moving theory LList to ex directory
lcp
parents: 600
diff changeset
  1765
  element (if any!) of the lazy list.  A coinduction principle is defined
c97f5a7cf763 Moving theory LList to ex directory
lcp
parents: 600
diff changeset
  1766
  for proving equations on lazy lists.
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1767
  
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1768
\item Theory {\tt PropLog} proves the soundness and completeness of classical
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1769
  propositional logic, given a truth table semantics.  The only connective is
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1770
  $\imp$.  A Hilbert-style axiom system is specified, and its set of theorems
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1771
  defined inductively.  A similar proof in ZF is described
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1772
  elsewhere~\cite{paulson-set-II}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1773
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1774
\item Theory {\tt Term} develops an experimental recursive type definition;
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1775
  the recursion goes through the type constructor~\tydx{list}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1776
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1777
\item Theory {\tt Simult} constructs mutually recursive sets of trees and
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1778
  forests, including induction and recursion rules.
111
1b3cddf41b2d Various updates for Isabelle-93
lcp
parents: 104
diff changeset
  1779
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1780
\item Theory {\tt MT} contains Jacob Frost's formalization~\cite{frost93} of
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1781
  Milner and Tofte's coinduction example~\cite{milner-coind}.  This
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1782
  substantial proof concerns the soundness of a type system for a simple
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1783
  functional language.  The semantics of recursion is given by a cyclic
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1784
  environment, which makes a coinductive argument appropriate.
594
33a6bdb62a18 Logics/HOL: Section 3, added Pow and its rule. New sections 6 on the
lcp
parents: 580
diff changeset
  1785
\end{itemize}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1786
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1787
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1788
\goodbreak
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1789
\section{Example: Cantor's Theorem}\label{sec:hol-cantor}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1790
Cantor's Theorem states that every set has more subsets than it has
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1791
elements.  It has become a favourite example in higher-order logic since
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1792
it is so easily expressed:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1793
\[  \forall f::[\alpha,\alpha]\To bool. \exists S::\alpha\To bool.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1794
    \forall x::\alpha. f(x) \not= S 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1795
\] 
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1796
%
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1797
Viewing types as sets, $\alpha\To bool$ represents the powerset
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1798
of~$\alpha$.  This version states that for every function from $\alpha$ to
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1799
its powerset, some subset is outside its range.  
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1800
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1801
The Isabelle proof uses HOL's set theory, with the type $\alpha\,set$ and the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1802
operator \cdx{range}.  The set~$S$ is given as an unknown instead of a
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1803
quantified variable so that we may inspect the subset found by the proof.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1804
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1805
goal Set.thy "~ ?S : range(f :: 'a=>'a set)";
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1806
{\out Level 0}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1807
{\out ~ ?S : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1808
{\out  1. ~ ?S : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1809
\end{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1810
The first two steps are routine.  The rule \tdx{rangeE} replaces
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1811
$\Var{S}\in {\tt range}(f)$ by $\Var{S}=f(x)$ for some~$x$.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1812
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1813
by (resolve_tac [notI] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1814
{\out Level 1}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1815
{\out ~ ?S : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1816
{\out  1. ?S : range(f) ==> False}
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
  1817
\ttbreak
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1818
by (eresolve_tac [rangeE] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1819
{\out Level 2}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1820
{\out ~ ?S : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1821
{\out  1. !!x. ?S = f(x) ==> False}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1822
\end{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1823
Next, we apply \tdx{equalityCE}, reasoning that since $\Var{S}=f(x)$,
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1824
we have $\Var{c}\in \Var{S}$ if and only if $\Var{c}\in f(x)$ for
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1825
any~$\Var{c}$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1826
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1827
by (eresolve_tac [equalityCE] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1828
{\out Level 3}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1829
{\out ~ ?S : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1830
{\out  1. !!x. [| ?c3(x) : ?S; ?c3(x) : f(x) |] ==> False}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1831
{\out  2. !!x. [| ~ ?c3(x) : ?S; ~ ?c3(x) : f(x) |] ==> False}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1832
\end{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1833
Now we use a bit of creativity.  Suppose that~$\Var{S}$ has the form of a
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1834
comprehension.  Then $\Var{c}\in\{x.\Var{P}(x)\}$ implies
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1835
$\Var{P}(\Var{c})$.   Destruct-resolution using \tdx{CollectD}
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1836
instantiates~$\Var{S}$ and creates the new assumption.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1837
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1838
by (dresolve_tac [CollectD] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1839
{\out Level 4}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1840
{\out ~ \{x. ?P7(x)\} : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1841
{\out  1. !!x. [| ?c3(x) : f(x); ?P7(?c3(x)) |] ==> False}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1842
{\out  2. !!x. [| ~ ?c3(x) : \{x. ?P7(x)\}; ~ ?c3(x) : f(x) |] ==> False}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1843
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1844
Forcing a contradiction between the two assumptions of subgoal~1 completes
344
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1845
the instantiation of~$S$.  It is now the set $\{x. x\not\in f(x)\}$, which
753b50b07c46 final Springer copy
lcp
parents: 315
diff changeset
  1846
is the standard diagonal construction.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1847
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1848
by (contr_tac 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1849
{\out Level 5}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1850
{\out ~ \{x. ~ x : f(x)\} : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1851
{\out  1. !!x. [| ~ x : \{x. ~ x : f(x)\}; ~ x : f(x) |] ==> False}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1852
\end{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1853
The rest should be easy.  To apply \tdx{CollectI} to the negated
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1854
assumption, we employ \ttindex{swap_res_tac}:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1855
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1856
by (swap_res_tac [CollectI] 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1857
{\out Level 6}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1858
{\out ~ \{x. ~ x : f(x)\} : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1859
{\out  1. !!x. [| ~ x : f(x); ~ False |] ==> ~ x : f(x)}
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
  1860
\ttbreak
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1861
by (assume_tac 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1862
{\out Level 7}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1863
{\out ~ \{x. ~ x : f(x)\} : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1864
{\out No subgoals!}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1865
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1866
How much creativity is required?  As it happens, Isabelle can prove this
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1867
theorem automatically.  The classical set \ttindex{set_cs} contains rules for
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1868
most of the constructs of HOL's set theory.  We must augment it with
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1869
\tdx{equalityCE} to break up set equalities, and then apply best-first search.
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1870
Depth-first search would diverge, but best-first search successfully navigates
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 2975
diff changeset
  1871
through the large search space.  \index{search!best-first}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1872
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1873
choplev 0;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1874
{\out Level 0}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1875
{\out ~ ?S : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1876
{\out  1. ~ ?S : range(f)}
287
6b62a6ddbe15 first draft of Springer book
lcp
parents: 154
diff changeset
  1877
\ttbreak
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1878
by (best_tac (set_cs addSEs [equalityCE]) 1);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1879
{\out Level 1}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1880
{\out ~ \{x. ~ x : f(x)\} : range(f)}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1881
{\out No subgoals!}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
  1882
\end{ttbox}
315
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1883
ebf62069d889 penultimate Springer draft
lcp
parents: 306
diff changeset
  1884
\index{higher-order logic|)}