doc-src/Logics/HOL.tex
author nipkow
Fri, 09 Feb 1996 18:29:01 +0100
changeset 1489 78e1ce42a825
parent 1471 b088c0a1f2bd
child 1490 713256365b92
permissions -rw-r--r--
Small changes.
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
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   212
\tdx{refl}           t = t
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   213
\tdx{subst}          [| s=t; P s |] ==> P t
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   214
\tdx{ext}            (!!x. f x = g x) ==> (\%x.f x) = (\%x.g x)
1113
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)
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   218
\tdx{selectI}        P(x) ==> P(@x.P x)
1113
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
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   236
\tdx{Inv_def}    Inv      == (\%f y. @x. f x = y)
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   237
\tdx{o_def}      op o     == (\%f g x. f(g x))
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   238
\tdx{if_def}     If P x y == (\%P x y.@z.(P=True --> z=x) & (P=False --> z=y))
1113
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
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   298
\tdx{ssubst}      [| t=s; P s |] ==> P t
1113
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  
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   300
\tdx{arg_cong}    x = y ==> f x = f y
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   301
\tdx{fun_cong}    f = g ==> f x = g x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   302
\tdx{cong}        [| f = g; x = y |] ==> f x = g y
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   303
\tdx{not_sym}     t ~= s ==> s ~= t
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   304
\subcaption{Equality}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   305
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   306
\tdx{TrueI}       True 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   307
\tdx{FalseE}      False ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   308
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   309
\tdx{conjI}       [| P; Q |] ==> P&Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   310
\tdx{conjunct1}   [| P&Q |] ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   311
\tdx{conjunct2}   [| P&Q |] ==> Q 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   312
\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
   313
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   314
\tdx{disjI1}      P ==> P|Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   315
\tdx{disjI2}      Q ==> P|Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   316
\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
   317
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   318
\tdx{notI}        (P ==> False) ==> ~ P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   319
\tdx{notE}        [| ~ P;  P |] ==> R
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   320
\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
   321
\subcaption{Propositional logic}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   322
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   323
\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
   324
\tdx{iffD1}       [| P=Q; P |] ==> Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   325
\tdx{iffD2}       [| P=Q; Q |] ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   326
\tdx{iffE}        [| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   327
%
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   328
%\tdx{eqTrueI}     P ==> P=True 
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   329
%\tdx{eqTrueE}     P=True ==> P 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   330
\subcaption{Logical equivalence}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   331
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   332
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   333
\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
   334
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   335
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   336
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   337
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   338
\begin{ttbox}\makeatother
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   339
\tdx{allI}      (!!x. P x) ==> !x. P x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   340
\tdx{spec}      !x.P x ==> P x
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   341
\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
   342
\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
   343
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   344
\tdx{exI}       P x ==> ? x. P x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   345
\tdx{exE}       [| ? x. P x; !!x. P x ==> Q |] ==> Q
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   346
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   347
\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
   348
\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
   349
          |] ==> R
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   350
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   351
\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
   352
\subcaption{Quantifiers and descriptions}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   353
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   354
\tdx{ccontr}          (~P ==> False) ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   355
\tdx{classical}       (~P ==> P) ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   356
\tdx{excluded_middle} ~P | P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   357
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   358
\tdx{disjCI}          (~Q ==> P) ==> P|Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   359
\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
   360
\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
   361
\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
   362
\tdx{notnotD}         ~~P ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   363
\tdx{swap}            ~P ==> (~Q ==> P) ==> Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   364
\subcaption{Classical logic}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   365
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   366
%\tdx{if_True}         (if True then x else y) = x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   367
%\tdx{if_False}        (if False then x else y) = y
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   368
\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
   369
\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
   370
\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
   371
\subcaption{Conditionals}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   372
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   373
\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
   374
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   375
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   376
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   377
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
   378
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
   379
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
   380
conjunctions, implications, and universal quantifiers.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   381
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   382
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
   383
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
   384
simplifying both sides of an equation.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   385
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   386
The following simple tactics are occasionally useful:
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   387
\begin{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   388
\item[\ttindexbold{strip_tac} $i$] applies {\tt allI} and {\tt impI}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   389
  repeatedly to remove all outermost universal quantifiers and implications
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   390
  from subgoal $i$.
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   391
\item[\ttindexbold{case_tac} {\tt"}$P${\tt"} $i$] performs case distinction
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   392
  on $P$ for subgoal $i$: the latter is replaced by two identical subgoals
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   393
  with the added assumptions $P$ and $\neg P$, respectively.
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   394
\end{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   395
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   396
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   397
\begin{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   398
\begin{center}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   399
\begin{tabular}{rrr}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   400
  \it name      &\it meta-type  & \it description \\ 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   401
\index{{}@\verb'{}' symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   402
  \verb|{}|     & $\alpha\,set$         & the empty set \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   403
  \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
   404
        & insertion of element \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   405
  \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
   406
        & comprehension \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   407
  \cdx{Compl}   & $(\alpha\,set)\To\alpha\,set$
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   408
        & complement \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   409
  \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
   410
        & intersection over a set\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   411
  \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
   412
        & union over a set\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   413
  \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
   414
        &set of sets intersection \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   415
  \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
   416
        &set of sets union \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   417
  \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
   418
        & powerset \\[1ex]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   419
  \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
   420
        & range of a function \\[1ex]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   421
  \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
   422
        & bounded quantifiers \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   423
  \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
   424
        & monotonicity \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   425
  \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
   426
        & injective/surjective \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   427
  \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
   428
        & injective over subset
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   429
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   430
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   431
\subcaption{Constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   432
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   433
\begin{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   434
\begin{tabular}{llrrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   435
  \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
   436
  \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
   437
        intersection over a type\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   438
  \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
   439
        union over a type
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   440
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   441
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   442
\subcaption{Binders} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   443
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   444
\begin{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   445
\index{*"`"` symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   446
\index{*": symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   447
\index{*"<"= symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   448
\begin{tabular}{rrrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   449
  \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
   450
  \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
   451
        & Left 90 & image \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   452
  \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
   453
        & Left 70 & intersection ($\inter$) \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   454
  \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
   455
        & Left 65 & union ($\union$) \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   456
  \tt:          & $[\alpha ,\alpha\,set]\To bool$       
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   457
        & Left 50 & membership ($\in$) \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   458
  \tt <=        & $[\alpha\,set,\alpha\,set]\To bool$
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   459
        & Left 50 & subset ($\subseteq$) 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   460
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   461
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   462
\subcaption{Infixes}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   463
\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
   464
\end{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   465
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   466
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   467
\begin{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   468
\begin{center} \tt\frenchspacing
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   469
\index{*"! symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   470
\begin{tabular}{rrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   471
  \it external          & \it internal  & \it description \\ 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   472
  $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
   473
  \{$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
   474
  \{$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
   475
        \rm comprehension \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   476
  \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
   477
        \rm intersection \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   478
  \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
   479
        \rm union \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   480
  \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
   481
        Ball $A$ $\lambda x.P[x]$ & 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   482
        \rm bounded $\forall$ \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   483
  \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
   484
        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
   485
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   486
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   487
\subcaption{Translations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   488
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   489
\dquotes
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   490
\[\begin{array}{rclcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   491
    term & = & \hbox{other terms\ldots} \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   492
         & | & "\{\}" \\
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 " . " formula " \}" \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   495
         & | & term " `` " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   496
         & | & term " Int " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   497
         & | & term " Un " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   498
         & | & "INT~~"  id ":" term " . " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   499
         & | & "UN~~~"  id ":" term " . " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   500
         & | & "INT~~"  id~id^* " . " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   501
         & | & "UN~~~"  id~id^* " . " term \\[2ex]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   502
 formula & = & \hbox{other formulae\ldots} \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   503
         & | & term " : " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   504
         & | & term " \ttilde: " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   505
         & | & term " <= " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   506
         & | & "!~" id ":" term " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   507
         & | & "ALL " id ":" term " . " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   508
         & | & "?~" id ":" term " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   509
         & | & "EX~~" id ":" term " . " formula
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   510
  \end{array}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   511
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   512
\subcaption{Full Grammar}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   513
\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
   514
\end{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   515
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   516
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   517
\section{A formulation of set theory}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   518
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
   519
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
   520
{\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
   521
theory, and behave more like {\ZF} classes.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   522
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   523
\item
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   524
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
   525
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
   526
\item
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   527
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
   528
may be defined by absolute comprehension.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   529
\item
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   530
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
   531
have a more complex type.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   532
\end{itemize}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   533
Finite unions and intersections have the same behaviour in \HOL\ as they
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   534
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
   535
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
   536
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   537
% FIXME: define set via typedef
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   538
\subsection{Syntax of set theory}\index{*set type}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   539
\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
   540
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
   541
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
   542
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
   543
\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
   544
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
   545
$\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
   546
argument order).
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   547
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   548
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
   549
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
   550
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
   551
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
   552
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
   553
$\neg(a\in b)$.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   554
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   555
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
   556
obvious manner using~{\tt insert} and~$\{\}$:
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
  \{a@1, \ldots, a@n\}  & \equiv &  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   559
  {\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
   560
\end{eqnarray*}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   561
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   562
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
   563
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
   564
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
   565
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
   566
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
   567
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   568
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
   569
\begin{eqnarray*}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   570
   \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
   571
   \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
   572
\end{eqnarray*}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   573
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
   574
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
   575
write\index{*"! symbol}\index{*"? symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   576
\index{*ALL symbol}\index{*EX symbol} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   577
%
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   578
\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
   579
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
   580
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
   581
\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
   582
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   583
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
   584
$\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
   585
\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
   586
\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
   587
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   588
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
   589
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
   590
\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
   591
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
   592
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   593
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
   594
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
   595
respectively.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   596
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   597
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   598
% 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
   599
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   600
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   601
\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
   602
\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
   603
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   604
\tdx{empty_def}         \{\}          == \{x.False\}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   605
\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
   606
\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
   607
\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
   608
\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
   609
\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
   610
\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
   611
\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
   612
\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
   613
\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
   614
\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
   615
\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
   616
\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
   617
\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
   618
\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
   619
\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
   620
\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
   621
\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
   622
\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
   623
\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
   624
\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
   625
\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
   626
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   627
\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
   628
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   629
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   630
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   631
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   632
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   633
\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
   634
\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
   635
\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
   636
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   637
\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
   638
\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
   639
\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
   640
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   641
\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
   642
\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
   643
\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
   644
\subcaption{Comprehension and Bounded quantifiers}
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{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
   647
\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
   648
\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
   649
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   650
\tdx{subset_refl}     A <= A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   651
\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
   652
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   653
\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
   654
\tdx{equalityD1}      A = B ==> A<=B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   655
\tdx{equalityD2}      A = B ==> B<=A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   656
\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
   657
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   658
\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
   659
                           [| ~ c:A; ~ c:B |] ==> P 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   660
                |]  ==>  P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   661
\subcaption{The subset and equality relations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   662
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   663
\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
   664
\end{figure}
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
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   667
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   668
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   669
\tdx{emptyE}   a : \{\} ==> 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{insertI1} a : insert a B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   672
\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
   673
\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
   674
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   675
\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
   676
\tdx{ComplD}   [| c : Compl A |] ==> ~ c:A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   677
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   678
\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
   679
\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
   680
\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
   681
\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
   682
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   683
\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
   684
\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
   685
\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
   686
\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
   687
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   688
\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
   689
\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
   690
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   691
\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
   692
\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
   693
\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
   694
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   695
\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
   696
\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
   697
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   698
\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
   699
\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
   700
\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
   701
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   702
\tdx{PowI}     A<=B ==> A: Pow B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   703
\tdx{PowD}     A: Pow B ==> A<=B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   704
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   705
\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
   706
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   707
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
\subsection{Axioms and rules of set theory}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   710
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
   711
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
   712
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
   713
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
   714
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   715
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
   716
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
   717
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
   718
{\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
   719
surjectiveness.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   720
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   721
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
   722
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
   723
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
   724
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
   725
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
   726
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   727
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   728
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   729
\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
   730
\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
   731
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   732
%\tdx{Inv_injective}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   733
%    [| 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
   734
%
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   735
\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
   736
\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
   737
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   738
\tdx{rangeI}     f x : range f
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   739
\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
   740
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   741
\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
   742
\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
   743
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   744
\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
   745
\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
   746
\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
   747
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   748
\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
   749
\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
   750
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   751
\tdx{inj_onto_inverseI}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   752
    (!!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
   753
\tdx{inj_onto_contraD}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   754
    [| 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
   755
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   756
\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
   757
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   758
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
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   761
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   762
\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
   763
\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
   764
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   765
\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
   766
\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
   767
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   768
\tdx{Un_upper1}       A <= A Un B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   769
\tdx{Un_upper2}       B <= A Un B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   770
\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
   771
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   772
\tdx{Int_lower1}      A Int B <= A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   773
\tdx{Int_lower2}      A Int B <= B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   774
\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
   775
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   776
\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
   777
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   778
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
\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
   781
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   782
\tdx{Int_absorb}        A Int A = A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   783
\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
   784
\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
   785
\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
   786
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   787
\tdx{Un_absorb}         A Un A = A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   788
\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
   789
\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
   790
\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
   791
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   792
\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
   793
\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
   794
\tdx{double_complement} Compl(Compl A) = A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   795
\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
   796
\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
   797
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   798
\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
   799
\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
   800
\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
   801
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   802
\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
   803
\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
   804
\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
   805
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   806
\caption{Set equalities} \label{hol-equalities}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   807
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   808
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   809
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   810
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
   811
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
   812
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
   813
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
   814
\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
   815
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
   816
\tdx{equalityCE} supports classical reasoning about extensionality,
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   817
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
   818
proofs pertaining to set theory.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   819
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   820
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
   821
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
   822
  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
   823
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
   824
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
   825
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
   826
predicate~\cdx{surj} is done simply by expanding the definitions.  See
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   827
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
   828
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   829
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
   830
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
   831
bounds.  Reasoning directly about subsets often yields clearer proofs than
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   832
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
   833
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   834
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
   835
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
   836
intersections and complements.  The proofs are mostly trivial, using the
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   837
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
   838
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   839
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   840
\section{Generic packages}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   841
\HOL\ instantiates most of Isabelle's generic packages;
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   842
see {\tt HOL/ROOT.ML} for details.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   843
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   844
\subsection{Substitution and simplification}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   845
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   846
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
   847
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
   848
subgoal and its hypotheses.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   849
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   850
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
   851
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
   852
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
   853
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
   854
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   855
See \iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   856
{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
   857
and simplification.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   858
1234
56ee5cc35510 updated "o" in HOL: (infixl 55)
nipkow
parents: 1163
diff changeset
   859
\begin{warn}\index{simplification!of conjunctions}
56ee5cc35510 updated "o" in HOL: (infixl 55)
nipkow
parents: 1163
diff changeset
   860
  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
   861
  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
   862
  while simplifying the right part. This can be changed by including
56ee5cc35510 updated "o" in HOL: (infixl 55)
nipkow
parents: 1163
diff changeset
   863
  \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
   864
  down rewriting and is therefore not included by default.
56ee5cc35510 updated "o" in HOL: (infixl 55)
nipkow
parents: 1163
diff changeset
   865
\end{warn}
56ee5cc35510 updated "o" in HOL: (infixl 55)
nipkow
parents: 1163
diff changeset
   866
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   867
In case a rewrite rule cannot be dealt with by the simplifier (either because
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   868
of nontermination or because its left-hand side is too flexible), HOL
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   869
provides {\tt stac}:
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   870
\begin{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   871
\item[\ttindexbold{stac} $thm$ $i,$] where $thm$ is of the form $lhs = rhs$,
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   872
  replaces in subgoal $i$ instances of $lhs$ by corresponding instances of
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   873
  $rhs$. In case of multiple instances of $lhs$ in subgoal $i$, backtracking
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   874
  may be necessary to select the desired ones.
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   875
\end{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   876
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   877
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   878
\subsection{Classical reasoning}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   879
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   880
\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
   881
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
   882
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
   883
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   884
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
   885
{\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
   886
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
   887
\HOL\ defines the following classical rule sets:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   888
\begin{ttbox} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   889
prop_cs    : claset
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   890
HOL_cs     : claset
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   891
set_cs     : claset
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   892
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   893
\begin{ttdescription}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   894
\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
   895
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
   896
along with the rule~{\tt refl}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   897
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   898
\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
   899
  {\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
   900
  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
   901
  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
   902
  once.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   903
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   904
\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
   905
  quantifiers, subsets, comprehensions, unions and intersections,
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   906
  complements, finite sets, images and ranges.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   907
\end{ttdescription}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   908
\noindent
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   909
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
   910
        {Chap.\ts\ref{chap:classical}} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   911
for more discussion of classical proof methods.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   912
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   913
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   914
\section{Types}\label{sec:HOL:Types}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   915
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
   916
  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
   917
type construction, the {\tt datatype}, is treated separately in
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   918
\S\ref{sec:HOL:datatype}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   919
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   920
\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
   921
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   922
\begin{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   923
\begin{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   924
  \it symbol    & \it meta-type &           & \it description \\ 
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   925
  \cdx{Pair}    & $[\alpha,\beta]\To \alpha\times\beta$
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   926
        & & ordered pairs $(a,b)$ \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   927
  \cdx{fst}     & $\alpha\times\beta \To \alpha$        & & first projection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   928
  \cdx{snd}     & $\alpha\times\beta \To \beta$         & & second projection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   929
  \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
   930
        & & generalized projection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   931
  \cdx{Sigma}  & 
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   932
        $[\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
   933
        & general sum of sets
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   934
\end{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   935
\begin{ttbox}\makeatletter
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   936
%\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
   937
%\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
   938
%\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
   939
\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
   940
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   941
\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
   942
\tdx{PairE}        [| !!x y. p = (x,y) ==> Q |] ==> Q
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   943
\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
   944
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   945
\tdx{fst_conv}     fst (a,b) = a
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   946
\tdx{snd_conv}     snd (a,b) = b
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   947
\tdx{surjective_pairing}  p = (fst p,snd p)
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   948
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   949
\tdx{split}        split c (a,b) = c a b
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   950
\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
   951
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   952
\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
   953
\tdx{SigmaE}       [| c: Sigma A B;  
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   954
                !!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
   955
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   956
\caption{Type $\alpha\times\beta$}\label{hol-prod}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   957
\end{figure} 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   958
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   959
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
   960
$\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
   961
simulated by pairs nested to the right:
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   962
\begin{center}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   963
\begin{tabular}{|c|c|}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   964
\hline
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   965
external & internal \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   966
\hline
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   967
$\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
   968
\hline
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   969
$(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
   970
\hline
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   971
\end{tabular}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   972
\end{center}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   973
In addition, it is possible to use tuples
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   974
as patterns in abstractions:
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   975
\begin{center}
1448
77379ae9ff0d Stylistic changes to discussion of pattern-matching
paulson
parents: 1429
diff changeset
   976
{\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
   977
\end{center}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   978
Nested patterns are possible and are translated stepwise:
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   979
{\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
   980
{\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
   981
  $z$.$t$))}. The reverse translation is performed upon printing.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   982
\begin{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   983
  The translation between patterns and {\tt split} is performed automatically
1448
77379ae9ff0d Stylistic changes to discussion of pattern-matching
paulson
parents: 1429
diff changeset
   984
  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
   985
  may differ, whichs affects proofs.  For example the term {\tt
77379ae9ff0d Stylistic changes to discussion of pattern-matching
paulson
parents: 1429
diff changeset
   986
    (\%(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
   987
  {\tt(b,a)}.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   988
\end{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   989
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
   990
variable binding construct which is internally described by a
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   991
$\lambda$-abstraction. Some important examples are
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   992
\begin{description}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   993
\item[Let:] {\tt let {\it pattern} = $t$ in $u$}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   994
\item[Quantifiers:] {\tt !~{\it pattern}:$A$.~$P$}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   995
\item[Choice:] {\underscoreon \tt @~{\it pattern}~.~$P$}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   996
\item[Set operations:] {\tt UN~{\it pattern}:$A$.~$B$}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   997
\item[Sets:] {\tt \{~{\it pattern}~.~$P$~\}}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   998
\end{description}
1471
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
   999
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1000
There is a simple tactic which supports reasoning about patterns:
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1001
\begin{ttdescription}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1002
\item[\ttindexbold{split_all_tac} $i$] replaces in subgoal $i$ all
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1003
  {\tt!!}-quantified variables of product type by individual variables for
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1004
  each component. A simple example:
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1005
\begin{ttbox}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1006
{\out 1. !!p. (\%(x,y,z). (x, y, z)) p = p}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1007
by(split_all_tac 1);
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1008
{\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
  1009
\end{ttbox}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1010
\end{ttdescription}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1011
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1012
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
  1013
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
  1014
\begin{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1015
\tdx{unit_eq}       u = ()
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1016
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1017
\bigskip
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1018
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1019
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
  1020
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
  1021
\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
  1022
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1023
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
  1024
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
  1025
  thy}-files.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1026
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1027
\begin{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1028
\begin{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1029
  \it symbol    & \it meta-type &           & \it description \\ 
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1030
  \cdx{Inl}     & $\alpha \To \alpha+\beta$    & & first injection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1031
  \cdx{Inr}     & $\beta \To \alpha+\beta$     & & second injection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1032
  \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
  1033
        & & conditional
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1034
\end{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1035
\begin{ttbox}\makeatletter
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1036
%\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
  1037
%                                        (!y. p=Inr y --> z=g y))
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1038
%
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1039
\tdx{Inl_not_Inr}    ~ Inl a=Inr b
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1040
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1041
\tdx{inj_Inl}        inj Inl
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1042
\tdx{inj_Inr}        inj Inr
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1043
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
  1044
\tdx{sumE}           [| !!x. P(Inl x);  !!y. P(Inr y) |] ==> P s
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1045
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1046
\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
  1047
\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
  1048
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
  1049
\tdx{surjective_sum} sum_case (\%x. f(Inl x)) (\%y. f(Inr y)) s = f s
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1050
\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
  1051
                                     (! y. s = Inr(y) --> R(g(y))))
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1052
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1053
\caption{Type $\alpha+\beta$}\label{hol-sum}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1054
\end{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1055
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1056
\begin{figure}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1057
\index{*"< symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1058
\index{*"* symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1059
\index{*div symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1060
\index{*mod symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1061
\index{*"+ symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1062
\index{*"- symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1063
\begin{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1064
  \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
  1065
  \cdx{0}       & $nat$         & & zero \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1066
  \cdx{Suc}     & $nat \To nat$ & & successor function\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1067
  \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
  1068
        & & conditional\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1069
  \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
  1070
        & & primitive recursor\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1071
  \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
  1072
  \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
  1073
  \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
  1074
  \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
  1075
  \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
  1076
\end{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1077
\subcaption{Constants and infixes}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1078
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1079
\begin{ttbox}\makeatother
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1080
\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
  1081
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1082
\tdx{Suc_not_Zero}   Suc m ~= 0
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1083
\tdx{inj_Suc}        inj Suc
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1084
\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
  1085
\subcaption{Basic properties}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1086
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1087
\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
  1088
\end{figure}
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
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1091
\begin{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1092
\begin{ttbox}\makeatother
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1093
\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
  1094
\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
  1095
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1096
\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
  1097
\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
  1098
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1099
\tdx{add_0}        0+n           = n
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1100
\tdx{add_Suc}      (Suc m)+n     = Suc(m+n)
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1101
\tdx{diff_0}       m-0           = m
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1102
\tdx{diff_0_eq_0}  0-n           = n
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1103
\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
  1104
\tdx{mult_def}     0*n           = 0
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1105
\tdx{mult_Suc}     Suc(m)*n      = n + m*n
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1106
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1107
\tdx{mod_less}     m<n ==> m mod n = m
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1108
\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
  1109
\tdx{div_less}     m<n ==> m div n = 0
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1110
\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
  1111
\subcaption{Recursion equations}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1112
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1113
\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
  1114
\tdx{lessI}          n < Suc n
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1115
\tdx{zero_less_Suc}  0 < Suc n
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1116
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1117
\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
  1118
\tdx{less_not_refl}  ~ n<n
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1119
\tdx{not_less0}      ~ n<0
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1120
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1121
\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
  1122
\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
  1123
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1124
\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
  1125
\subcaption{The less-than relation}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1126
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
  1127
\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
  1128
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1129
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1130
\subsection{The type of natural numbers, {\tt nat}}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1131
%FIXME: introduce separate type proto_nat
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1132
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1133
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
  1134
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
  1135
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
  1136
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
  1137
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
  1138
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
  1139
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
  1140
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1141
%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
  1142
%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
  1143
%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
  1144
%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
  1145
%along arbitrary well-founded relations.  The corresponding theories are
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1146
%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
  1147
%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
  1148
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1149
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
  1150
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
  1151
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1152
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
  1153
defines addition, multiplication, subtraction, division, and remainder.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1154
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
  1155
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
  1156
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
  1157
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
  1158
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
  1159
and~\ref{hol-nat2}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1160
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1161
%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
  1162
%Recursion along this relation resembles primitive recursion, but is
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1163
%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
  1164
%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
  1165
%is not primitive recursive \cite[page~104]{thompson91}.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1166
%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
  1167
%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
  1168
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1169
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
  1170
variable~$n$ in subgoal~$i$.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1171
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1172
%FIXME add nth
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1173
\begin{figure}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1174
\index{#@{\tt[]} symbol}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1175
\index{#@{\tt\#} symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1176
\index{"@@{\tt\at} symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1177
\begin{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1178
  \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
  1179
  \tt[]    & $\alpha list$ & & empty list\\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1180
  \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
  1181
        list constructor \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1182
  \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
  1183
  \cdx{hd}      & $\alpha list \To \alpha$ & & head \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1184
  \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
  1185
  \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
  1186
  \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
  1187
  \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
  1188
        & & mapping functional\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1189
  \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
  1190
        & & filter functional\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1191
  \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
  1192
        & & forall functional\\
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1193
  \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
  1194
  \cdx{length}  & $\alpha list \To nat$ & & length \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1195
%  \cdx{nth}  & $nat \To \alpha list \To \alpha$ & & indexing \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1196
  \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
  1197
  & iteration \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1198
  \cdx{flat}   & $(\alpha list) list\To \alpha list$ & & flattening \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1199
  \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
  1200
\end{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1201
\subcaption{Constants and infixes}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1202
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1203
\begin{center} \tt\frenchspacing
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1204
\begin{tabular}{rrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1205
  \it external        & \it internal  & \it description \\{}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1206
  [$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
  1207
        \rm finite list \\{}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1208
  [$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
  1209
        \rm list comprehension
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1210
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1211
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1212
\subcaption{Translations}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
  1213
\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
  1214
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1215
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1216
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1217
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1218
\begin{ttbox}\makeatother
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1219
\tdx{null_Nil}        null [] = True
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1220
\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
  1221
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1222
\tdx{hd_Cons}         hd (x#xs) = x
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1223
\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
  1224
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1225
\tdx{ttl_Nil}         ttl [] = []
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1226
\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
  1227
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1228
\tdx{append_Nil}      [] @ ys = ys
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1229
\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
  1230
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1231
\tdx{map_Nil}         map f [] = []
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1232
\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
  1233
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1234
\tdx{filter_Nil}      filter P [] = []
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
  1235
\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
  1236
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1237
\tdx{list_all_Nil}    list_all P [] = True
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1238
\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
  1239
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1240
\tdx{mem_Nil}         x mem [] = False
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1241
\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
  1242
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1243
\tdx{length_Nil}      length([]) = 0
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1244
\tdx{length_Cons}     length(x#xs) = Suc(length(xs))
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1245
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1246
\tdx{foldl_Nil}       foldl f a [] = a
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1247
\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
  1248
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1249
\tdx{flat_Nil}        flat([]) = []
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1250
\tdx{flat_Cons}       flat(x#xs) = x @ flat(xs)
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1251
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1252
\tdx{rev_Nil}         rev([]) = []
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1253
\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
  1254
\end{ttbox}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1255
\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
  1256
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1257
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1258
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1259
\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
  1260
\index{*list type}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1261
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1262
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
  1263
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
  1264
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
  1265
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
  1266
theorems {\tt list.simps}.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1267
A \sdx{case} construct of the form
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1268
\begin{center}\tt
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1269
case $e$ of [] => $a$  |  x\#xs => b
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1270
\end{center}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1271
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
  1272
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1273
{\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
  1274
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
  1275
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
  1276
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1277
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1278
\subsection{Introducing new types}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1279
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1280
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
  1281
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
  1282
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
  1283
{\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
  1284
described elsewhere.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1285
\begin{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1286
  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
  1287
  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
  1288
\end{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1289
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
  1290
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
  1291
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
  1292
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
  1293
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
  1294
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
  1295
\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
  1296
$(\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
  1297
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1298
\begin{figure}[htbp]
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1299
\begin{rail}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1300
typedef  : 'typedef' ( () | '(' tname ')') type '=' set witness;
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1301
type    : typevarlist name ( () | '(' infix ')' );
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1302
tname   : name;
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1303
set     : string;
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1304
witness : () | '(' id ')';
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1305
\end{rail}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1306
\caption{Syntax of type definition}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1307
\label{fig:HOL:typedef}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1308
\end{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1309
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1310
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
  1311
the definition of ``typevarlist'' and ``infix'' see
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1312
\iflabelundefined{chap:classical}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1313
{the appendix of the {\em Reference Manual\/}}%
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1314
{Appendix~\ref{app:TheorySyntax}}. The remaining nonterminals have the
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1315
following meaning:
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1316
\begin{description}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1317
\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
  1318
  optional infix annotation.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1319
\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
  1320
  case $ty$ is a symbolic name. Default: $ty$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1321
\item[\it set]: the representing subset $A$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1322
\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
  1323
  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
  1324
  non-emptiness automatically.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1325
\end{description}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1326
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
  1327
'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
  1328
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
  1329
\begin{itemize}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1330
\item a type $ty :: (term,\dots)term$;
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1331
\item constants
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1332
\begin{eqnarray*}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1333
T &::& (\tau)set \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1334
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
  1335
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
  1336
\end{eqnarray*}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1337
\item a definition and three axioms
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1338
\[
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1339
\begin{array}{ll}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1340
T{\tt_def} & T \equiv A \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1341
{\tt Rep_}T & Rep_T(x) : T \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1342
{\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
  1343
{\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
  1344
\end{array}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1345
\]
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1346
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
  1347
and its inverse $Abs_T$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1348
\end{itemize}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1349
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
  1350
\begin{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1351
typedef unit = "\{False\}"
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1352
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1353
typedef (prod)
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1354
  ('a, 'b) "*"    (infixr 20)
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1355
      = "\{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
  1356
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1357
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1358
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
  1359
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
  1360
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
  1361
\begin{enumerate}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1362
\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
  1363
  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
  1364
  representation.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1365
\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
  1366
\end{enumerate}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1367
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
  1368
abstract properties $P$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1369
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1370
\begin{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1371
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
  1372
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
  1373
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
  1374
\par
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1375
\begin{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1376
arities \(ty\): (term,\(\dots\),term)term
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1377
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1378
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
  1379
{\tt term}, the class of all HOL terms.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1380
\end{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1381
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1382
\section{Datatype declarations}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1383
\label{sec:HOL:datatype}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1384
\index{*datatype|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1385
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1386
\underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1387
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1388
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
  1389
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
  1390
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
  1391
  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
  1392
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1393
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1394
\subsection{Foundations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1395
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1396
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
  1397
\[ \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
  1398
      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
  1399
      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
  1400
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1401
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
  1402
$\tau_{ij}$ are one of the following:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1403
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1404
\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
  1405
\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
  1406
  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
  1407
  \{\alpha_1,\dots,\alpha_n\}$,
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1408
\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
  1409
    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
  1410
    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
  1411
    components.}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1412
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1413
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
  1414
$\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
  1415
$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
  1416
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
  1417
  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
  1418
\mbox{\tt datatype}~ t ~=~ C(t~list). \]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1419
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1420
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
  1421
type:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1422
\[ 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
  1423
These functions have certain {\em freeness} properties:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1424
\begin{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1425
\item[\tt distinct] They are distinct:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1426
\[ 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
  1427
   \mbox{for all}~ i \neq j.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1428
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1429
\item[\tt inject] They are injective:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1430
\[ (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
  1431
   (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
  1432
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1433
\end{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1434
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
  1435
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
  1436
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
  1437
natural number
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1438
\[
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1439
\begin{array}{lcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1440
\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
  1441
& \vdots & \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1442
\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
  1443
\end{array}
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
and distinctness of constructors is expressed by:
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
\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
  1448
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1449
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
  1450
\[
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1451
\infer{P x}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1452
{\begin{array}{lcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1453
\Forall x_1\dots x_{k_1}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1454
  \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
  1455
  \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
  1456
 & \vdots & \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1457
\Forall x_1\dots x_{k_m}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1458
  \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
  1459
  \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
  1460
\end{array}}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1461
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1462
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
  1463
= (\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
  1464
all arguments of the recursive type.
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
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
  1467
\[
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1468
\begin{array}{rrcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1469
\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
  1470
                           \vdots \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1471
                           \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
  1472
\end{array}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1473
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1474
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
  1475
fixed, and nested patterns are not supported.
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
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1478
\subsection{Defining datatypes}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1479
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1480
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
  1481
  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
  1482
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
  1483
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
  1484
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
  1485
section.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1486
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1487
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1488
\begin{rail}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1489
typedecl : typevarlist id '=' (cons + '|')
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1490
         ;
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1491
cons     : (id | string) ( () | '(' (typ + ',') ')' ) ( () | mixfix )
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1492
         ;
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1493
typ      : typevarlist id
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1494
           | tid
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1495
         ;
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1496
typevarlist : () | tid | '(' (tid + ',') ')'
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1497
         ;
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1498
\end{rail}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1499
\caption{Syntax of datatype declarations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1500
\label{datatype-grammar}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1501
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1502
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1503
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
  1504
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
  1505
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
  1506
  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
  1507
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1508
val distinct : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1509
val inject : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1510
val induct : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1511
val cases : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1512
val simps : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1513
val induct_tac : string -> int -> tactic
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1514
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1515
{\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
  1516
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
  1517
directions.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1518
\begin{warn}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1519
  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
  1520
  {\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
  1521
  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
  1522
\end{warn}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1523
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
  1524
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
  1525
{\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
  1526
    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
  1527
subgoal {\em i}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1528
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1529
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1530
\subsection{Examples}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1531
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1532
\subsubsection{The datatype $\alpha~list$}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1533
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1534
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
  1535
  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
  1536
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
  1537
\begin{ttbox}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1538
MyList = HOL +
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1539
  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
  1540
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1541
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1542
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
  1543
$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
  1544
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1545
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
  1546
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
  1547
{\out Level 0}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1548
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1549
{\out  1. ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1550
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1551
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
  1552
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1553
by (MyList.list.induct_tac "xs" 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1554
{\out Level 1}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1555
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1556
{\out  1. ! x. Cons x Nil ~= Nil}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1557
{\out  2. !!a list.}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1558
{\out        ! x. Cons x list ~= list ==>}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1559
{\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
  1560
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1561
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
  1562
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
  1563
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1564
by (simp_tac mylist_ss 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1565
{\out Level 2}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1566
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1567
{\out  1. !!a list.}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1568
{\out        ! x. Cons x list ~= list ==>}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1569
{\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
  1570
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1571
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
  1572
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1573
by (asm_simp_tac mylist_ss 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1574
{\out Level 3}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1575
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1576
{\out No subgoals!}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1577
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1578
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
  1579
done that in one step using
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1580
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1581
by (ALLGOALS (asm_simp_tac mylist_ss));
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1582
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1583
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1584
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1585
\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
  1586
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1587
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
  1588
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
  1589
\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
  1590
after the constructor declarations as follows:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1591
\begin{ttbox}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1592
MyList = HOL +
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1593
  datatype 'a list = "[]" ("[]") 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1594
                   | "#" 'a ('a list) (infixr 70)
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1595
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1596
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1597
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
  1598
proof is the same.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1599
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
\subsubsection{A datatype for weekdays}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1602
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1603
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
  1604
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1605
Days = Arith +
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1606
  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
  1607
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1608
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1609
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
  1610
{\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
  1611
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
  1612
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
  1613
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1614
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
  1615
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1616
goal Days.thy "Mo ~= Tu";
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1617
by (simp_tac days_ss 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1618
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1619
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
  1620
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
  1621
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1622
\subsection{Primitive recursive functions}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1623
\label{sec:HOL:primrec}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1624
\index{primitive recursion|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1625
\index{*primrec|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1626
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1627
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
  1628
  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
  1629
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
  1630
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1631
Append = MyList +
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1632
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
  1633
rules 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1634
   app_Nil   "app [] ys = ys"
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1635
   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
  1636
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1637
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1638
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
  1639
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
  1640
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
  1641
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1642
Append = MyList +
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1643
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
  1644
primrec app MyList.list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1645
   app_Nil   "app [] ys = ys"
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1646
   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
  1647
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1648
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1649
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
  1650
\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
  1651
ensuring that consistency is maintained. For example
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1652
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1653
primrec app MyList.list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1654
    app_Nil   "app [] ys = us"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1655
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1656
is rejected:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1657
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1658
Extra variables on rhs
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1659
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1660
\bigskip
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1661
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1662
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
  1663
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1664
primrec {\it function} {\it type}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1665
    {\it reduction rules}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1666
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1667
where
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1668
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1669
\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
  1670
  {\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
  1671
\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
  1672
  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
  1673
  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
  1674
  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
  1675
  different theories.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1676
\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
  1677
  {\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
  1678
  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
  1679
  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
  1680
  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
  1681
  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
  1682
  $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
  1683
  rule for each constructor.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1684
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1685
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
  1686
intermixed with other declarations.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1687
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1688
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
  1689
  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
  1690
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
  1691
a recursion operator on the datatype.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1692
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1693
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
  1694
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1695
Append = MyList +
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1696
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
  1697
primrec "op @" MyList.list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1698
   app_Nil   "[] @ ys = ys"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1699
   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
  1700
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1701
\end{ttbox}
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
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
  1704
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
  1705
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1706
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
  1707
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1708
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
  1709
by (MyList.list.induct_tac "xs" 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1710
by (ALLGOALS(asm_simp_tac append_ss));
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1711
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1712
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1713
%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
  1714
%\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1715
%Tl = MyList +
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1716
%consts tl  :: 'a list => 'a list
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1717
%primrec tl MyList.list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1718
%   tl_Cons "tl(x#xs) = xs"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1719
%end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1720
%\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1721
%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
  1722
%\verb$tl([])$ is.
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
\index{primitive recursion|)}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1725
\index{*primrec|)}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1726
\index{*datatype|)}
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
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1729
\section{Inductive and coinductive definitions}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1730
\index{*inductive|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1731
\index{*coinductive|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1732
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1733
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
  1734
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
  1735
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
  1736
  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
  1737
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
  1738
of processes and infinite data structures.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1739
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1740
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
  1741
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
  1742
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
  1743
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
  1744
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1745
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
  1746
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
  1747
substructure of the main theory structure.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1748
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1749
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
  1750
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
  1751
  longer version is distributed with Isabelle.} which you should refer to
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1752
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
  1753
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
  1754
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
  1755
rules for type-checking.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1756
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1757
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1758
\subsection{The result structure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1759
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
  1760
others are self-explanatory.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1761
\begin{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1762
\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
  1763
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1764
\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
  1765
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1766
\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
  1767
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1768
\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
  1769
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
  1770
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1771
\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
  1772
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
  1773
names given them in the theory file. 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1774
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1775
\item[\tt elim] is the elimination rule.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1776
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1777
\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
  1778
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
  1779
\end{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1780
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1781
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
  1782
{\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
  1783
contains the rule \verb|coinduct|.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1784
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1785
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
  1786
specifying the types of all these components.
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
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1789
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1790
sig
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1791
val thy          : theory
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1792
val defs         : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1793
val mono         : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1794
val unfold       : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1795
val intrs        : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1796
val elim         : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1797
val mk_cases     : thm list -> string -> thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1798
{\it(Inductive definitions only)} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1799
val induct       : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1800
val mutual_induct: thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1801
{\it(Coinductive definitions only)}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1802
val coinduct    : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1803
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1804
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1805
\hrule
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1806
\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
  1807
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1808
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1809
\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
  1810
An inductive definition has the form
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1811
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1812
inductive    {\it inductive sets}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1813
  intrs      {\it introduction rules}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1814
  monos      {\it monotonicity theorems}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1815
  con_defs   {\it constructor definitions}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1816
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1817
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
  1818
{\tt coinductive}.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1819
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1820
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
  1821
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
  1822
{\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
  1823
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
  1824
file on your directory.
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
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1827
\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
  1828
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1829
\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
  1830
  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
  1831
  the rule in the result structure.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1832
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1833
\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
  1834
  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
  1835
  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
  1836
  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
  1837
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1838
\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
  1839
  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
  1840
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1841
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1842
The package has a few notable restrictions:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1843
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1844
\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
  1845
  constants.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1846
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1847
\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
  1848
operators.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1849
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1850
\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
  1851
may contain any number of side-conditions.
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
\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
  1854
  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
  1855
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1856
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1857
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1858
\subsection{Example of an inductive definition}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1859
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
  1860
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
  1861
inductively, with two introduction rules:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1862
\begin{ttbox}
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1863
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
  1864
inductive "Fin A"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1865
  intrs
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1866
    emptyI  "\{\} : Fin A"
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1867
    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
  1868
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1869
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
  1870
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
  1871
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
  1872
rule is {\tt Fin.induct}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1873
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1874
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
  1875
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
  1876
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
  1877
\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
  1878
of this example in more detail.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1879
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1880
Acc = WF + 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1881
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
  1882
       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
  1883
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
  1884
inductive "acc r"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1885
  intrs
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1886
     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
  1887
  monos   "[Pow_mono]"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1888
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1889
\end{ttbox}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1890
The HOL distribution contains many other inductive definitions, such as the
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1891
theory {\tt HOL/ex/PropLog.thy} and the directory {\tt HOL/IMP}.  The
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1892
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
  1893
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1894
\index{*coinductive|)} \index{*inductive|)} \underscoreoff
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1895
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1896
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1897
\section{The examples directories}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1898
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
  1899
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
  1900
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
  1901
theory~\cite{mw81}. 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1902
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1903
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
  1904
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
  1905
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
  1906
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
  1907
definitions, and demonstrates their use.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1908
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1909
Directory {\tt HOL/ex} contains other examples and experimental proofs in
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1910
{\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
  1911
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1912
\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
  1913
  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
  1914
  moderately difficult problems involving equality and quantifiers.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1915
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1916
\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
  1917
    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
  1918
  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
  1919
  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
  1920
  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
  1921
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1922
\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
  1923
  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
  1924
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1925
\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
  1926
  \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
  1927
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1928
\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
  1929
  insertion sort and quick sort.
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 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
  1932
  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
  1933
  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
  1934
  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
  1935
  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
  1936
  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
  1937
  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
  1938
  for proving equations on lazy lists.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1939
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1940
\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
  1941
  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
  1942
  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
  1943
  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
  1944
  described elsewhere~\cite{paulson-set-II}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1945
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1946
\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
  1947
  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
  1948
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1949
\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
  1950
  forests, including induction and recursion rules.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1951
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1952
\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
  1953
  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
  1954
  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
  1955
  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
  1956
  environment, which makes a coinductive argument appropriate.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1957
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1958
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1959
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1960
\goodbreak
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
  1961
\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
  1962
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
  1963
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
  1964
it is so easily expressed:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1965
\[  \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
  1966
    \forall x::\alpha. f~x \not= S 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1967
\] 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1968
%
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1969
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
  1970
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
  1971
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
  1972
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1973
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
  1974
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
  1975
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
  1976
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1977
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
  1978
{\out Level 0}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1979
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1980
{\out  1. ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1981
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1982
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
  1983
$\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
  1984
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1985
by (resolve_tac [notI] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1986
{\out Level 1}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1987
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1988
{\out  1. ?S : range f ==> False}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1989
\ttbreak
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1990
by (eresolve_tac [rangeE] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1991
{\out Level 2}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1992
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1993
{\out  1. !!x. ?S = 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
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
  1996
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
  1997
any~$\Var{c}$.
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 (eresolve_tac [equalityCE] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2000
{\out Level 3}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2001
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2002
{\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
  2003
{\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
  2004
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2005
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
  2006
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
  2007
$\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
  2008
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
  2009
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2010
by (dresolve_tac [CollectD] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2011
{\out Level 4}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2012
{\out ~ \{x. ?P7 x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2013
{\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
  2014
{\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
  2015
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2016
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
  2017
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
  2018
is the standard diagonal construction.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2019
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2020
by (contr_tac 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2021
{\out Level 5}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2022
{\out ~ \{x. ~ x : f x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2023
{\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
  2024
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2025
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
  2026
assumption, we employ \ttindex{swap_res_tac}:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2027
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2028
by (swap_res_tac [CollectI] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2029
{\out Level 6}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2030
{\out ~ \{x. ~ x : f x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2031
{\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
  2032
\ttbreak
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2033
by (assume_tac 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2034
{\out Level 7}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2035
{\out ~ \{x. ~ x : f x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2036
{\out No subgoals!}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2037
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2038
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
  2039
theorem automatically.  The classical set \ttindex{set_cs} contains rules
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  2040
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
  2041
\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
  2042
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
  2043
successfully navigates through the large search space.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2044
\index{search!best-first}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2045
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2046
choplev 0;
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2047
{\out Level 0}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2048
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2049
{\out  1. ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2050
\ttbreak
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2051
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
  2052
{\out Level 1}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2053
{\out ~ \{x. ~ x : f x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2054
{\out No subgoals!}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2055
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2056
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2057
\index{higher-order logic|)}