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