doc-src/Logics/HOL.tex
author paulson
Wed, 07 May 1997 17:16:18 +0200
changeset 3132 8e956415412f
parent 3045 4ef28e05781b
child 3152 065c701c7827
permissions -rw-r--r--
Documents directory Induct; stylistic improvements
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
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
     8
Church's original paper~\cite{church40}.  Andrews's book~\cite{andrews86} is
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
     9
a full description of higher-order logic.  Experience with the {\sc hol}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    10
system has demonstrated that higher-order logic is widely applicable in many
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    11
areas of mathematics and computer science, not just hardware verification,
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    12
{\sc hol}'s original {\it raison d'\^etre\/}.  It is weaker than {\ZF} set
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    13
theory but for most applications this does not matter.  If you prefer {\ML}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    14
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
    15
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    16
The syntax of \HOL\footnote{Earlier versions of Isabelle's \HOL\ used a
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    17
different syntax. Ancient releases of Isabelle included still another version
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    18
of~\HOL, with explicit type inference rules~\cite{paulson-COLOG}.  This
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    19
version no longer exists, but \thydx{ZF} supports a similar style of
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    20
reasoning.} follows $\lambda$-calculus and functional programming.  Function
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    21
application is curried.  To apply the function~$f$ of type
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    22
$\tau@1\To\tau@2\To\tau@3$ to the arguments~$a$ and~$b$ in \HOL, you simply
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    23
write $f\,a\,b$. There is no `apply' operator as in \thydx{ZF}. Note that
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    24
$f(a,b)$ means ``$f$ applied to the pair $(a,b)$'' in \HOL.  We write ordered
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    25
pairs as $(a,b)$, not $\langle a,b\rangle$ as in {\ZF}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    26
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
    27
\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
    28
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
    29
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
    30
with meta-level functions, so it uses Isabelle's operations for abstraction
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    31
and application.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    32
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
    33
These identifications allow Isabelle to support \HOL\ particularly nicely,
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
    34
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
    35
--- in particular, an understanding of Isabelle's type system.  Beginners
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    36
should work with {\tt show_types} set to {\tt true}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    37
%  Gain experience by
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    38
%working in first-order logic before attempting to use higher-order logic.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    39
%This chapter assumes familiarity with~{\FOL{}}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    40
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    41
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    42
\begin{figure}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
    43
\begin{constants}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    44
  \it name      &\it meta-type  & \it description \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    45
  \cdx{Trueprop}& $bool\To prop$                & coercion to $prop$\\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    46
  \cdx{Not}     & $bool\To bool$                & negation ($\neg$) \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    47
  \cdx{True}    & $bool$                        & tautology ($\top$) \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    48
  \cdx{False}   & $bool$                        & absurdity ($\bot$) \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    49
  \cdx{If}      & $[bool,\alpha,\alpha]\To\alpha$ & conditional \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    50
  \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
    51
\end{constants}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    52
\subcaption{Constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    53
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
    54
\begin{constants}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    55
\index{"@@{\tt\at} symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    56
\index{*"! symbol}\index{*"? symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    57
\index{*"?"! symbol}\index{*"E"X"! symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    58
  \it symbol &\it name     &\it meta-type & \it description \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    59
  \tt\at & \cdx{Eps}  & $(\alpha\To bool)\To\alpha$ & 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    60
        Hilbert description ($\varepsilon$) \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    61
  {\tt!~} or \sdx{ALL}  & \cdx{All}  & $(\alpha\To bool)\To bool$ & 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    62
        universal quantifier ($\forall$) \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    63
  {\tt?~} or \sdx{EX}   & \cdx{Ex}   & $(\alpha\To bool)\To bool$ & 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    64
        existential quantifier ($\exists$) \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    65
  {\tt?!} or {\tt EX!}  & \cdx{Ex1}  & $(\alpha\To bool)\To bool$ & 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    66
        unique existence ($\exists!$)\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    67
  {\tt LEAST}  & \cdx{Least}  & $(\alpha\To bool)\To\alpha$ & 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    68
        least element
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
    69
\end{constants}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    70
\subcaption{Binders} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    71
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
    72
\begin{constants}
1113
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
\index{&@{\tt\&} symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    75
\index{*"| symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    76
\index{*"-"-"> symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    77
  \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
    78
  \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
    79
        Left 55 & composition ($\circ$) \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    80
  \tt =         & $[\alpha,\alpha]\To bool$ & Left 50 & equality ($=$) \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    81
  \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
    82
  \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
    83
                less than or equals ($\leq$)\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    84
  \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
    85
  \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
    86
  \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
    87
\end{constants}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    88
\subcaption{Infixes}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
    89
\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
    90
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    91
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    92
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    93
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    94
\index{*let symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    95
\index{*in symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    96
\dquotes
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    97
\[\begin{array}{rclcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    98
    term & = & \hbox{expression of class~$term$} \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    99
         & | & "\at~" id " . " formula \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   100
         & | & 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   101
    \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
   102
         & | & 
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   103
    \multicolumn{3}{l}{"if"~formula~"then"~term~"else"~term} \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   104
         & | & "LEAST"~ id " . " formula \\[2ex]
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   105
 formula & = & \hbox{expression of type~$bool$} \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   106
         & | & term " = " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   107
         & | & term " \ttilde= " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   108
         & | & term " < " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   109
         & | & term " <= " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   110
         & | & "\ttilde\ " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   111
         & | & formula " \& " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   112
         & | & formula " | " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   113
         & | & formula " --> " 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
         & | & "ALL~" id~id^* " . " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   116
         & | & "?~~~" id~id^* " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   117
         & | & "EX~~" id~id^* " . " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   118
         & | & "?!~~" id~id^* " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   119
         & | & "EX!~" id~id^* " . " formula
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   120
  \end{array}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   121
\]
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   122
\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
   123
\end{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   124
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   125
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   126
\section{Syntax}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   127
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   128
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
   129
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
   130
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
   131
$\neg(a=b)$.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   132
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   133
\begin{warn}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   134
  \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
   135
  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
   136
  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
   137
  $\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
   138
  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
   139
  parentheses.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   140
\end{warn}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   141
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   142
\subsection{Types and classes}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   143
The type class of higher-order terms is called~\cldx{term}.  By default,
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   144
explicit type variables have class \cldx{term}.  In particular the equality
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   145
symbol and quantifiers are polymorphic over class {\tt term}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   146
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   147
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
   148
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
   149
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
   150
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
   151
over functions.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   152
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   153
HOL offers various methods for introducing new
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   154
types. See~\S\ref{sec:HOL:Types} and~\S\ref{sec:HOL:datatype}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   155
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   156
Theory \thydx{Ord} defines the class \cldx{ord} of all ordered types; the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   157
relations $<$ and $\leq$ are polymorphic over this class, as are the functions
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   158
\cdx{mono}, \cdx{min} and \cdx{max}, and the least element operator
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   159
\cdx{LEAST}. \thydx{Ord} also defines the subclass \cldx{order} of \cldx{ord}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   160
which axiomatizes partially ordered types (w.r.t.\ $\le$). 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   161
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   162
Three other type classes --- \cldx{plus}, \cldx{minus} and \cldx{times} ---
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   163
permit overloading of the operators {\tt+},\index{*"+ symbol}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   164
{\tt-}\index{*"- symbol} and {\tt*}.\index{*"* symbol} In particular, {\tt-}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   165
is overloaded for set difference and subtraction.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   166
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   167
If you state a goal containing overloaded functions, you may need to include
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   168
type constraints.  Type inference may otherwise make the goal more
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   169
polymorphic than you intended, with confusing results. For example, the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   170
variables $i$, $j$ and $k$ in the goal $i \le j \Imp i \le j+k$ have type
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   171
$\alpha::\{ord,plus\}$, although you may have expected them to have some
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   172
numeric type, e.g. $nat$. Instead you should have stated the goal as
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   173
$(i::nat) \le j \Imp i \le j+k$, which causes all three variables to have
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   174
type $nat$.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   175
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   176
\begin{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   177
  If resolution fails for no obvious reason, try setting
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   178
  \ttindex{show_types} to {\tt true}, causing Isabelle to display types of
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   179
  terms.  Possibly set \ttindex{show_sorts} to {\tt true} as well, causing
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   180
  Isabelle to display sorts.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   181
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   182
  \index{unification!incompleteness of}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   183
  Where function types are involved, Isabelle's unification code does not
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   184
  guarantee to find instantiations for type variables automatically.  Be
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   185
  prepared to use \ttindex{res_inst_tac} instead of {\tt resolve_tac},
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   186
  possibly instantiating type variables.  Setting
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   187
  \ttindex{Unify.trace_types} to {\tt true} causes Isabelle to report
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   188
  omitted search paths during unification.\index{tracing!of unification}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   189
\end{warn}
1113
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{Binders}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   193
Hilbert's {\bf description} operator~$\varepsilon x.P$ stands for some~$x$
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   194
satisfying~$P$, 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
   195
something, a description is always meaningful, but we do not know its value
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   196
unless $P$ defines it uniquely.  We may write descriptions as
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   197
\cdx{Eps}($\lambda x.P$) or use the syntax \hbox{\tt \at $x$.$P$}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   198
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   199
Existential quantification is defined by
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   200
\[ \exists x.P~x \;\equiv\; P(\varepsilon x.P~x). \]
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   201
The unique existence quantifier, $\exists!x.P$, is defined in terms
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   202
of~$\exists$ and~$\forall$.  An Isabelle binder, it admits nested
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   203
quantifications.  For instance, $\exists!x\,y.P\,x\,y$ abbreviates
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   204
$\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
   205
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
   206
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   207
\index{*"! symbol}\index{*"? symbol}\index{HOL system@{\sc hol} system}
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   208
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
   209
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
   210
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
   211
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
   212
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
   213
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
   214
\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
   215
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
   216
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
   217
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   218
If $\tau$ is a type of class \cldx{ord}, $P$ a formula and $x$ a variable of
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   219
type $\tau$, then the term \cdx{LEAST}~$x.P~x$ denotes the least (w.r.t.\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   220
$\le$) $x$ such that $P~x$ holds (see Fig.~\ref{hol-defs}). Note that
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   221
unless $\le$ is a linear order, the result is not uniquely defined.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   222
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   223
All these binders have priority 10. 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   224
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   225
\begin{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   226
The low priority of binders means that they need to be enclosed in
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   227
parenthesis when they occur in the context of other operations. For example,
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   228
instead of $P \land \forall x.Q$ you need to write $P \land (\forall x.Q)$.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   229
\end{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   230
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   231
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   232
\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
   233
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
   234
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
   235
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
   236
definition, \tdx{Let_def}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   237
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   238
\HOL\ also defines the basic syntax
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   239
\[\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
   240
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
   241
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
   242
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
   243
{\tt case} construct to denote applications of particular case operators.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   244
This is what happens automatically for each {\tt datatype} declaration
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   245
(see~\S\ref{sec:HOL:datatype}).
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   246
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   247
\begin{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   248
Both {\tt if} and {\tt case} constructs have as low a priority as
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   249
quantifiers, which requires additional enclosing parenthesis in the context
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   250
of most other operations. For example, instead of $f~x = if \dots then \dots
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   251
else \dots$ you need to write $f~x = (if \dots then \dots else
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   252
\dots)$.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   253
\end{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   254
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   255
\section{Rules of inference}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   256
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   257
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   258
\begin{ttbox}\makeatother
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   259
\tdx{refl}           t = t
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   260
\tdx{subst}          [| s=t; P s |] ==> P t
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   261
\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
   262
\tdx{impI}           (P ==> Q) ==> P-->Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   263
\tdx{mp}             [| P-->Q;  P |] ==> Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   264
\tdx{iff}            (P-->Q) --> (Q-->P) --> (P=Q)
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   265
\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
   266
\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
   267
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   268
\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
   269
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   270
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   271
Figure~\ref{hol-rules} shows the inference rules of~\HOL{}, with their~{\ML}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   272
names.  Some of the rules deserve additional comments:
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   273
\begin{ttdescription}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   274
\item[\tdx{ext}] expresses extensionality of functions.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   275
\item[\tdx{iff}] asserts that logically equivalent formulae are
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   276
  equal.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   277
\item[\tdx{selectI}] gives the defining property of the Hilbert
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   278
  $\varepsilon$-operator.  It is a form of the Axiom of Choice.  The derived rule
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   279
  \tdx{select_equality} (see below) is often easier to use.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   280
\item[\tdx{True_or_False}] makes the logic classical.\footnote{In
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   281
    fact, the $\varepsilon$-operator already makes the logic classical, as
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   282
    shown by Diaconescu; see Paulson~\cite{paulson-COLOG} for details.}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   283
\end{ttdescription}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   284
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   285
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   286
\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
   287
\begin{ttbox}\makeatother
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   288
\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
   289
\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
   290
\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
   291
\tdx{False_def}  False    == (!P.P)
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   292
\tdx{not_def}    not      == (\%P. P-->False)
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   293
\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
   294
\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
   295
\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
   296
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   297
\tdx{o_def}      op o     == (\%f g x. f(g x))
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   298
\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
   299
\tdx{Let_def}    Let s f  == f s
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   300
\tdx{Least_def}  Least P  == @x. P(x) & (ALL y. y<x --> ~P(y))
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   301
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   302
\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
   303
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   304
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   305
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   306
\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
   307
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
   308
(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
   309
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
   310
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
   311
higher-order logic may equate formulae and even functions over formulae.
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   312
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
   313
meta-equality~({\tt==}) for definitions.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   314
\begin{warn}
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   315
The definitions above should never be expanded and are shown for completeness
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   316
only. Instead users should reason in terms of the derived rules shown below
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   317
or, better still, using high-level tactics
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   318
(see~\S\ref{sec:HOL:generic-packages}).
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   319
\end{warn}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   320
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   321
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
   322
mentions the type variable~{\tt'a}.  This allows you to instantiate
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   323
type variables explicitly by calling {\tt res_inst_tac}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   324
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   325
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   326
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   327
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   328
\tdx{sym}         s=t ==> t=s
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   329
\tdx{trans}       [| r=s; s=t |] ==> r=t
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   330
\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
   331
\tdx{box_equals}  [| a=b;  a=c;  b=d |] ==> c=d  
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   332
\tdx{arg_cong}    x = y ==> f x = f y
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   333
\tdx{fun_cong}    f = g ==> f x = g x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   334
\tdx{cong}        [| f = g; x = y |] ==> f x = g y
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   335
\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
   336
\subcaption{Equality}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   337
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   338
\tdx{TrueI}       True 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   339
\tdx{FalseE}      False ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   340
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   341
\tdx{conjI}       [| P; Q |] ==> P&Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   342
\tdx{conjunct1}   [| P&Q |] ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   343
\tdx{conjunct2}   [| P&Q |] ==> Q 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   344
\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
   345
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   346
\tdx{disjI1}      P ==> P|Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   347
\tdx{disjI2}      Q ==> P|Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   348
\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
   349
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   350
\tdx{notI}        (P ==> False) ==> ~ P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   351
\tdx{notE}        [| ~ P;  P |] ==> R
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   352
\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
   353
\subcaption{Propositional logic}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   354
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   355
\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
   356
\tdx{iffD1}       [| P=Q; P |] ==> Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   357
\tdx{iffD2}       [| P=Q; Q |] ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   358
\tdx{iffE}        [| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   359
%
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   360
%\tdx{eqTrueI}     P ==> P=True 
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   361
%\tdx{eqTrueE}     P=True ==> P 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   362
\subcaption{Logical equivalence}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   363
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   364
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   365
\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
   366
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   367
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   368
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   369
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   370
\begin{ttbox}\makeatother
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   371
\tdx{allI}      (!!x. P x) ==> !x. P x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   372
\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
   373
\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
   374
\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
   375
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   376
\tdx{exI}       P x ==> ? x. P x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   377
\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
   378
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   379
\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
   380
\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
   381
          |] ==> R
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   382
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   383
\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
   384
\subcaption{Quantifiers and descriptions}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   385
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   386
\tdx{ccontr}          (~P ==> False) ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   387
\tdx{classical}       (~P ==> P) ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   388
\tdx{excluded_middle} ~P | P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   389
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   390
\tdx{disjCI}          (~Q ==> P) ==> P|Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   391
\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
   392
\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
   393
\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
   394
\tdx{notnotD}         ~~P ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   395
\tdx{swap}            ~P ==> (~Q ==> P) ==> Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   396
\subcaption{Classical logic}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   397
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   398
%\tdx{if_True}         (if True then x else y) = x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   399
%\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
   400
\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
   401
\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
   402
\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
   403
\subcaption{Conditionals}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   404
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   405
\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
   406
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   407
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   408
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
   409
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
   410
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
   411
conjunctions, implications, and universal quantifiers.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   412
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   413
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
   414
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
   415
simplifying both sides of an equation.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   416
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   417
The following simple tactics are occasionally useful:
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   418
\begin{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   419
\item[\ttindexbold{strip_tac} $i$] applies {\tt allI} and {\tt impI}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   420
  repeatedly to remove all outermost universal quantifiers and implications
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   421
  from subgoal $i$.
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   422
\item[\ttindexbold{case_tac} {\tt"}$P${\tt"} $i$] performs case distinction
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   423
  on $P$ for subgoal $i$: the latter is replaced by two identical subgoals
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   424
  with the added assumptions $P$ and $\neg P$, respectively.
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   425
\end{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   426
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   427
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   428
\begin{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   429
\begin{center}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   430
\begin{tabular}{rrr}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   431
  \it name      &\it meta-type  & \it description \\ 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   432
\index{{}@\verb'{}' symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   433
  \verb|{}|     & $\alpha\,set$         & the empty set \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   434
  \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
   435
        & insertion of element \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   436
  \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
   437
        & comprehension \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   438
  \cdx{Compl}   & $(\alpha\,set)\To\alpha\,set$
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   439
        & complement \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   440
  \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
   441
        & intersection over a set\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   442
  \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
   443
        & union over a set\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   444
  \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
   445
        &set of sets intersection \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   446
  \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
   447
        &set of sets union \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   448
  \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
   449
        & powerset \\[1ex]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   450
  \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
   451
        & range of a function \\[1ex]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   452
  \cdx{Ball}~~\cdx{Bex} & $[\alpha\,set,\alpha\To bool]\To bool$
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   453
        & bounded quantifiers
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   454
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   455
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   456
\subcaption{Constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   457
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   458
\begin{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   459
\begin{tabular}{llrrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   460
  \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
   461
  \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
   462
        intersection over a type\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   463
  \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
   464
        union over a type
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   465
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   466
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   467
\subcaption{Binders} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   468
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   469
\begin{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   470
\index{*"`"` symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   471
\index{*": symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   472
\index{*"<"= symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   473
\begin{tabular}{rrrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   474
  \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
   475
  \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
   476
        & Left 90 & image \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   477
  \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
   478
        & Left 70 & intersection ($\inter$) \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   479
  \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
   480
        & Left 65 & union ($\union$) \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   481
  \tt:          & $[\alpha ,\alpha\,set]\To bool$       
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   482
        & Left 50 & membership ($\in$) \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   483
  \tt <=        & $[\alpha\,set,\alpha\,set]\To bool$
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   484
        & Left 50 & subset ($\subseteq$) 
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{Infixes}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   488
\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
   489
\end{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   490
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   491
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   492
\begin{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   493
\begin{center} \tt\frenchspacing
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   494
\index{*"! symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   495
\begin{tabular}{rrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   496
  \it external          & \it internal  & \it description \\ 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   497
  $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
   498
  \{$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
   499
  \{$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
   500
        \rm comprehension \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   501
  \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
   502
        \rm intersection \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   503
  \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
   504
        \rm union \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   505
  \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
   506
        Ball $A$ $\lambda x.P[x]$ & 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   507
        \rm bounded $\forall$ \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   508
  \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
   509
        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
   510
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   511
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   512
\subcaption{Translations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   513
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   514
\dquotes
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   515
\[\begin{array}{rclcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   516
    term & = & \hbox{other terms\ldots} \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   517
         & | & "\{\}" \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   518
         & | & "\{ " term\; ("," term)^* " \}" \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   519
         & | & "\{ " id " . " formula " \}" \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   520
         & | & term " `` " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   521
         & | & term " Int " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   522
         & | & term " Un " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   523
         & | & "INT~~"  id ":" term " . " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   524
         & | & "UN~~~"  id ":" term " . " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   525
         & | & "INT~~"  id~id^* " . " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   526
         & | & "UN~~~"  id~id^* " . " term \\[2ex]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   527
 formula & = & \hbox{other formulae\ldots} \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   528
         & | & term " : " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   529
         & | & term " \ttilde: " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   530
         & | & term " <= " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   531
         & | & "!~" id ":" term " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   532
         & | & "ALL " id ":" term " . " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   533
         & | & "?~" id ":" term " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   534
         & | & "EX~~" id ":" term " . " formula
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   535
  \end{array}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   536
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   537
\subcaption{Full Grammar}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   538
\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
   539
\end{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   540
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   541
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   542
\section{A formulation of set theory}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   543
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
   544
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
   545
{\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
   546
theory, and behave more like {\ZF} classes.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   547
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   548
\item
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   549
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
   550
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
   551
\item
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   552
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
   553
may be defined by absolute comprehension.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   554
\item
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   555
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
   556
have a more complex type.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   557
\end{itemize}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   558
Finite unions and intersections have the same behaviour in \HOL\ as they
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   559
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
   560
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
   561
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   562
\subsection{Syntax of set theory}\index{*set type}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   563
\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
   564
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
   565
clarity and to avoid complications involving function types in unification.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   566
The isomorphisms between the two types are declared explicitly.  They are
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   567
very natural: {\tt Collect} maps $\alpha\To bool$ to $\alpha\,set$, while
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   568
\hbox{\tt op :} maps in the other direction (ignoring argument order).
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   569
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   570
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
   571
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
   572
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
   573
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
   574
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
   575
$\neg(a\in b)$.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   576
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   577
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
   578
obvious manner using~{\tt insert} and~$\{\}$:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   579
\begin{eqnarray*}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   580
  \{a@1, \ldots, a@n\}  & \equiv &  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   581
  {\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
   582
\end{eqnarray*}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   583
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   584
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
   585
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
   586
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
   587
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
   588
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
   589
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   590
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
   591
\begin{eqnarray*}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   592
   \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
   593
   \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
   594
\end{eqnarray*}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   595
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
   596
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
   597
write\index{*"! symbol}\index{*"? symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   598
\index{*ALL symbol}\index{*EX symbol} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   599
%
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   600
\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
   601
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
   602
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
   603
\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
   604
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   605
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
   606
$\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
   607
\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
   608
\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
   609
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   610
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
   611
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
   612
\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
   613
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
   614
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   615
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
   616
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
   617
respectively.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   618
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   619
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   620
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   621
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   622
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   623
\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
   624
\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
   625
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   626
\tdx{empty_def}         \{\}          == \{x.False\}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   627
\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
   628
\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
   629
\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
   630
\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
   631
\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
   632
\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
   633
\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
   634
\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
   635
\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
   636
\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
   637
\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
   638
\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
   639
\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
   640
\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
   641
\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
   642
\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
   643
\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
   644
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   645
\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
   646
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   647
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   648
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   649
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   650
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   651
\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
   652
\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
   653
\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
   654
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   655
\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
   656
\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
   657
\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
   658
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   659
\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
   660
\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
   661
\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
   662
\subcaption{Comprehension and Bounded quantifiers}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   663
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   664
\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
   665
\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
   666
\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
   667
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   668
\tdx{subset_refl}     A <= A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   669
\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
   670
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   671
\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
   672
\tdx{equalityD1}      A = B ==> A<=B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   673
\tdx{equalityD2}      A = B ==> B<=A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   674
\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
   675
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   676
\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
   677
                           [| ~ c:A; ~ c:B |] ==> P 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   678
                |]  ==>  P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   679
\subcaption{The subset and equality relations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   680
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   681
\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
   682
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   683
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   684
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   685
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   686
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   687
\tdx{emptyE}   a : \{\} ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   688
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   689
\tdx{insertI1} a : insert a B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   690
\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
   691
\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
   692
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   693
\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
   694
\tdx{ComplD}   [| c : Compl A |] ==> ~ c:A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   695
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   696
\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
   697
\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
   698
\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
   699
\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
   700
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   701
\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
   702
\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
   703
\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
   704
\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
   705
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   706
\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
   707
\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
   708
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   709
\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
   710
\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
   711
\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
   712
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   713
\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
   714
\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
   715
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   716
\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
   717
\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
   718
\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
   719
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   720
\tdx{PowI}     A<=B ==> A: Pow B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   721
\tdx{PowD}     A: Pow B ==> A<=B
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   722
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   723
\tdx{imageI}   [| x:A |] ==> f x : f``A
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   724
\tdx{imageE}   [| b : f``A;  !!x.[| b=f x;  x:A |] ==> P |] ==> P
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   725
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   726
\tdx{rangeI}   f x : range f
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   727
\tdx{rangeE}   [| b : range f;  !!x.[| b=f x |] ==> P |] ==> P
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   728
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   729
\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
   730
\end{figure}
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
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   733
\subsection{Axioms and rules of set theory}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   734
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
   735
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
   736
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
   737
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
   738
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   739
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
   740
quantifiers, unions, intersections, complements and the subset relation.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   741
They also include straightforward constructions on functions: image~({\tt``})
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   742
and {\tt range}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   743
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   744
%The predicate \cdx{inj_onto} is used for simulating type definitions.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   745
%The statement ${\tt inj_onto}~f~A$ asserts that $f$ is injective on the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   746
%set~$A$, which specifies a subset of its domain type.  In a type
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   747
%definition, $f$ is the abstraction function and $A$ is the set of valid
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   748
%representations; we should not expect $f$ to be injective outside of~$A$.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   749
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   750
%\begin{figure} \underscoreon
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   751
%\begin{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   752
%\tdx{Inv_f_f}    inj f ==> Inv f (f x) = x
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   753
%\tdx{f_Inv_f}    y : range f ==> f(Inv f y) = y
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   754
%
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   755
%\tdx{Inv_injective}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   756
%    [| 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
   757
%
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   758
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   759
%\tdx{monoI}      [| !!A B. A <= B ==> f A <= f B |] ==> mono f
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   760
%\tdx{monoD}      [| mono f;  A <= B |] ==> f A <= f B
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   761
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   762
%\tdx{injI}       [| !! x y. f x = f y ==> x=y |] ==> inj f
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   763
%\tdx{inj_inverseI}              (!!x. g(f x) = x) ==> inj f
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   764
%\tdx{injD}       [| inj f; f x = f y |] ==> x=y
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   765
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   766
%\tdx{inj_ontoI}  (!!x y. [| f x=f y; x:A; y:A |] ==> x=y) ==> inj_onto f A
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   767
%\tdx{inj_ontoD}  [| inj_onto f A;  f x=f y;  x:A;  y:A |] ==> x=y
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   768
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   769
%\tdx{inj_onto_inverseI}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   770
%    (!!x. x:A ==> g(f x) = x) ==> inj_onto f A
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   771
%\tdx{inj_onto_contraD}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   772
%    [| inj_onto f A;  x~=y;  x:A;  y:A |] ==> ~ f x=f y
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   773
%\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   774
%\caption{Derived rules involving functions} \label{hol-fun}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   775
%\end{figure}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   776
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   777
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   778
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   779
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   780
\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
   781
\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
   782
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   783
\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
   784
\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
   785
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   786
\tdx{Un_upper1}       A <= A Un B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   787
\tdx{Un_upper2}       B <= A Un B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   788
\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
   789
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   790
\tdx{Int_lower1}      A Int B <= A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   791
\tdx{Int_lower2}      A Int B <= B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   792
\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
   793
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   794
\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
   795
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   796
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   797
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   798
\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
   799
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   800
\tdx{Int_absorb}        A Int A = A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   801
\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
   802
\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
   803
\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
   804
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   805
\tdx{Un_absorb}         A Un A = A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   806
\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
   807
\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
   808
\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
   809
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   810
\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
   811
\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
   812
\tdx{double_complement} Compl(Compl A) = A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   813
\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
   814
\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
   815
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   816
\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
   817
\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
   818
\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
   819
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   820
\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
   821
\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
   822
\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
   823
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   824
\caption{Set equalities} \label{hol-equalities}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   825
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   826
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   827
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   828
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
   829
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
   830
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
   831
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
   832
\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
   833
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
   834
\tdx{equalityCE} supports classical reasoning about extensionality,
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   835
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
   836
proofs pertaining to set theory.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   837
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   838
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
   839
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
   840
bounds.  Reasoning directly about subsets often yields clearer proofs than
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   841
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
   842
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   843
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
   844
include commutative, associative and distributive laws involving unions,
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   845
intersections and complements.  For a complete listing see the file {\tt
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   846
HOL/equalities.ML}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   847
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   848
\begin{warn}
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   849
\texttt{Blast_tac} proves many set-theoretic theorems automatically.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   850
Hence you seldom need to refer to the theorems above.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   851
\end{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   852
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   853
\begin{figure}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   854
\begin{center}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   855
\begin{tabular}{rrr}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   856
  \it name      &\it meta-type  & \it description \\ 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   857
  \cdx{inj}~~\cdx{surj}& $(\alpha\To\beta )\To bool$
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   858
        & injective/surjective \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   859
  \cdx{inj_onto}        & $[\alpha\To\beta ,\alpha\,set]\To bool$
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   860
        & injective over subset\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   861
  \cdx{inv} & $(\alpha\To\beta)\To(\beta\To\alpha)$ & inverse function
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   862
\end{tabular}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   863
\end{center}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   864
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   865
\underscoreon
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   866
\begin{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   867
\tdx{inj_def}           inj f        == ! x y. f x=f y --> x=y
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   868
\tdx{surj_def}          surj f       == ! y. ? x. y=f x
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   869
\tdx{inj_onto_def}      inj_onto f A == !x:A. !y:A. f x=f y --> x=y
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   870
\tdx{inv_def}           inv f        == (\%y. @x. f(x)=y)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   871
\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   872
\caption{Theory \thydx{Fun}} \label{fig:HOL:Fun}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   873
\end{figure}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   874
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   875
\subsection{Properties of functions}\nopagebreak
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   876
Figure~\ref{fig:HOL:Fun} presents a theory of simple properties of functions.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   877
Note that ${\tt inv}~f$ uses Hilbert's $\varepsilon$ to yield an inverse
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   878
of~$f$. See the file {\tt HOL/Fun.ML} for a complete listing of the derived
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   879
rules.  Reasoning about function composition (the operator~\sdx{o}) and the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   880
predicate~\cdx{surj} is done simply by expanding the definitions.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   881
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   882
There is also a large collection of monotonicity theorems for constructions
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   883
on sets in the file {\tt HOL/mono.ML}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   884
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   885
\section{Generic packages}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   886
\label{sec:HOL:generic-packages}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   887
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   888
\HOL\ instantiates most of Isabelle's generic packages, making available the
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   889
simplifier and the classical reasoner.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   890
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   891
\subsection{Substitution and simplification}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   892
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   893
The simplifier is available in \HOL.  Tactics such as {\tt Asm_simp_tac} and
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   894
{\tt 
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
   895
Full_simp_tac} use the default simpset ({\tt!simpset}), which works for most
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
   896
purposes.  A minimal simplification set for higher-order logic
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
   897
is~\ttindexbold{HOL_ss}.  Equality~($=$), which also expresses logical
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
   898
equivalence, may be used for rewriting.  See the file {\tt HOL/simpdata.ML}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   899
for a complete listing of the basic simplification rules.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   900
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   901
See \iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   902
{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
   903
and simplification.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   904
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   905
\begin{warn}\index{simplification!of conjunctions}%
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   906
  Reducing $a=b\conj P(a)$ to $a=b\conj P(b)$ is sometimes advantageous.  The
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   907
  left part of a conjunction helps in simplifying the right part.  This effect
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   908
  is not available by default: it can be slow.  It can be obtained by
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   909
  including \ttindex{conj_cong} in a simpset, \verb$addcongs [conj_cong]$.
1234
56ee5cc35510 updated "o" in HOL: (infixl 55)
nipkow
parents: 1163
diff changeset
   910
\end{warn}
56ee5cc35510 updated "o" in HOL: (infixl 55)
nipkow
parents: 1163
diff changeset
   911
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   912
If the simplifier cannot use a certain rewrite rule---either because of
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   913
nontermination or because its left-hand side is too flexible---then you might
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   914
try {\tt stac}:
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   915
\begin{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   916
\item[\ttindexbold{stac} $thm$ $i,$] where $thm$ is of the form $lhs = rhs$,
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   917
  replaces in subgoal $i$ instances of $lhs$ by corresponding instances of
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   918
  $rhs$. In case of multiple instances of $lhs$ in subgoal $i$, backtracking
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   919
  may be necessary to select the desired ones.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   920
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   921
If $thm$ is a conditional equality, the instantiated condition becomes an
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   922
additional (first) subgoal.
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   923
\end{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   924
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   925
 \HOL{} provides the tactic \ttindex{hyp_subst_tac}, which substitutes
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   926
  for an equality throughout a subgoal and its hypotheses.  This tactic uses
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   927
  \HOL's general substitution rule.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   928
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   929
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   930
\subsection{Classical reasoning}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   931
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   932
\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
   933
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
   934
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
   935
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   936
The classical reasoner is installed.  Tactics such as {\tt Blast_tac} and {\tt
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
   937
Best_tac} use the default claset ({\tt!claset}), which works for most
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
   938
purposes.  Named clasets include \ttindexbold{prop_cs}, which includes the
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   939
propositional rules, and \ttindexbold{HOL_cs}, which also includes quantifier
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   940
rules.  See the file {\tt HOL/cladata.ML} for lists of the classical rules,
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   941
and \iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   942
{Chap.\ts\ref{chap:classical}} for more discussion of classical proof methods.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   943
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   944
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   945
\section{Types}\label{sec:HOL:Types}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   946
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
   947
  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
   948
type construction, the {\tt datatype}, is treated separately in
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   949
\S\ref{sec:HOL:datatype}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   950
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   951
\subsection{Product and sum types}\index{*"* type}\index{*"+ type}
2994
3bb5d1b9c3aa Tuple patterns are allowed now in `case'
nipkow
parents: 2975
diff changeset
   952
\label{subsec:prod-sum}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   953
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   954
\begin{figure}[htbp]
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   955
\begin{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   956
  \it symbol    & \it meta-type &           & \it description \\ 
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   957
  \cdx{Pair}    & $[\alpha,\beta]\To \alpha\times\beta$
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   958
        & & ordered pairs $(a,b)$ \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   959
  \cdx{fst}     & $\alpha\times\beta \To \alpha$        & & first projection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   960
  \cdx{snd}     & $\alpha\times\beta \To \beta$         & & second projection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   961
  \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
   962
        & & generalized projection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   963
  \cdx{Sigma}  & 
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   964
        $[\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
   965
        & general sum of sets
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   966
\end{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   967
\begin{ttbox}\makeatletter
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   968
%\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
   969
%\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
   970
%\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
   971
\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
   972
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   973
\tdx{Pair_eq}      ((a,b) = (a',b')) = (a=a' & b=b')
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   974
\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
   975
\tdx{PairE}        [| !!x y. p = (x,y) ==> Q |] ==> Q
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   976
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   977
\tdx{fst_conv}     fst (a,b) = a
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   978
\tdx{snd_conv}     snd (a,b) = b
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   979
\tdx{surjective_pairing}  p = (fst p,snd p)
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   980
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   981
\tdx{split}        split c (a,b) = c a b
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   982
\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
   983
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   984
\tdx{SigmaI}    [| a:A;  b:B a |] ==> (a,b) : Sigma A B
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   985
\tdx{SigmaE}    [| c:Sigma A B; !!x y.[| x:A; y:B x; c=(x,y) |] ==> P |] ==> P
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   986
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   987
\caption{Type $\alpha\times\beta$}\label{hol-prod}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   988
\end{figure} 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   989
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   990
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
   991
$\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
   992
simulated by pairs nested to the right:
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   993
\begin{center}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   994
\begin{tabular}{|c|c|}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   995
\hline
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   996
external & internal \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   997
\hline
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   998
$\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
   999
\hline
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1000
$(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
  1001
\hline
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1002
\end{tabular}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1003
\end{center}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1004
In addition, it is possible to use tuples
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1005
as patterns in abstractions:
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1006
\begin{center}
1448
77379ae9ff0d Stylistic changes to discussion of pattern-matching
paulson
parents: 1429
diff changeset
  1007
{\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
  1008
\end{center}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1009
Nested patterns are also supported. They are translated stepwise:
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1010
{\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
  1011
{\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
  1012
  $z$.$t$))}. The reverse translation is performed upon printing.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1013
\begin{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1014
  The translation between patterns and {\tt split} is performed automatically
1448
77379ae9ff0d Stylistic changes to discussion of pattern-matching
paulson
parents: 1429
diff changeset
  1015
  by the parser and printer.  Thus the internal and external form of a term
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1016
  may differ, which can affects proofs.  For example the term {\tt
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1017
  (\%(x,y).(y,x))(a,b)} requires the theorem {\tt split} (which is in the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1018
  default simpset) to rewrite to {\tt(b,a)}.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1019
\end{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1020
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
  1021
variable binding construct which is internally described by a
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1022
$\lambda$-abstraction. Some important examples are
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1023
\begin{description}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1024
\item[Let:] {\tt let {\it pattern} = $t$ in $u$}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1025
\item[Quantifiers:] {\tt !~{\it pattern}:$A$.~$P$}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1026
\item[Choice:] {\underscoreon \tt @~{\it pattern}~.~$P$}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1027
\item[Set operations:] {\tt UN~{\it pattern}:$A$.~$B$}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1028
\item[Sets:] {\tt \{~{\it pattern}~.~$P$~\}}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1029
\end{description}
1471
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1030
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1031
There is a simple tactic which supports reasoning about patterns:
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1032
\begin{ttdescription}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1033
\item[\ttindexbold{split_all_tac} $i$] replaces in subgoal $i$ all
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1034
  {\tt!!}-quantified variables of product type by individual variables for
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1035
  each component. A simple example:
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1036
\begin{ttbox}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1037
{\out 1. !!p. (\%(x,y,z). (x, y, z)) p = p}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1038
by(split_all_tac 1);
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1039
{\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
  1040
\end{ttbox}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1041
\end{ttdescription}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1042
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1043
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
  1044
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
  1045
\begin{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1046
\tdx{unit_eq}       u = ()
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1047
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1048
\bigskip
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1049
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1050
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
  1051
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
  1052
\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
  1053
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1054
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
  1055
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
  1056
  thy}-files.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1057
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1058
\begin{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1059
\begin{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1060
  \it symbol    & \it meta-type &           & \it description \\ 
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1061
  \cdx{Inl}     & $\alpha \To \alpha+\beta$    & & first injection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1062
  \cdx{Inr}     & $\beta \To \alpha+\beta$     & & second injection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1063
  \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
  1064
        & & conditional
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1065
\end{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1066
\begin{ttbox}\makeatletter
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1067
%\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
  1068
%                                        (!y. p=Inr y --> z=g y))
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1069
%
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1070
\tdx{Inl_not_Inr}    ~ Inl a=Inr b
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1071
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1072
\tdx{inj_Inl}        inj Inl
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1073
\tdx{inj_Inr}        inj Inr
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1074
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
  1075
\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
  1076
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1077
\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
  1078
\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
  1079
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
  1080
\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
  1081
\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
  1082
                                     (! y. s = Inr(y) --> R(g(y))))
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1083
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1084
\caption{Type $\alpha+\beta$}\label{hol-sum}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1085
\end{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1086
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1087
\begin{figure}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1088
\index{*"< symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1089
\index{*"* symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1090
\index{*div symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1091
\index{*mod symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1092
\index{*"+ symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1093
\index{*"- symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1094
\begin{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1095
  \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
  1096
  \cdx{0}       & $nat$         & & zero \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1097
  \cdx{Suc}     & $nat \To nat$ & & successor function\\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1098
% \cdx{nat_case} & $[\alpha, nat\To\alpha, nat] \To\alpha$ & & conditional\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1099
% \cdx{nat_rec} & $[nat, \alpha, [nat, \alpha]\To\alpha] \To \alpha$
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1100
%        & & primitive recursor\\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1101
  \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
  1102
  \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
  1103
  \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
  1104
  \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
  1105
  \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
  1106
\end{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1107
\subcaption{Constants and infixes}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1108
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1109
\begin{ttbox}\makeatother
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1110
\tdx{nat_induct}     [| P 0; !!n. P n ==> P(Suc n) |]  ==> P n
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1111
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1112
\tdx{Suc_not_Zero}   Suc m ~= 0
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1113
\tdx{inj_Suc}        inj Suc
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1114
\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
  1115
\subcaption{Basic properties}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1116
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1117
\caption{The type of natural numbers, {\tt nat}} \label{hol-nat1}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1118
\end{figure}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1119
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1120
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1121
\begin{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1122
\begin{ttbox}\makeatother
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1123
%\tdx{nat_case_0}     nat_case a f 0 = a
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1124
%\tdx{nat_case_Suc}   nat_case a f (Suc k) = f k
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1125
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1126
%\tdx{nat_rec_0}      nat_rec 0 c h = c
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1127
%\tdx{nat_rec_Suc}    nat_rec (Suc n) c h = h n (nat_rec n c h)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1128
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1129
              0+n           = n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1130
              (Suc m)+n     = Suc(m+n)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1131
              m-0           = m
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1132
              0-n           = n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1133
              Suc(m)-Suc(n) = m-n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1134
              0*n           = 0
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1135
              Suc(m)*n      = n + m*n
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1136
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1137
\tdx{mod_less}      m<n ==> m mod n = m
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1138
\tdx{mod_geq}       [| 0<n;  ~m<n |] ==> m mod n = (m-n) mod n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1139
\tdx{div_less}      m<n ==> m div n = 0
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1140
\tdx{div_geq}       [| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1141
%\subcaption{Recursion equations}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1142
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1143
%\tdx{less_trans}     [| i<j;  j<k |] ==> i<k
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1144
%\tdx{lessI}          n < Suc n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1145
%\tdx{zero_less_Suc}  0 < Suc n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1146
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1147
%\tdx{less_not_sym}   n<m --> ~ m<n 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1148
%\tdx{less_not_refl}  ~ n<n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1149
%\tdx{not_less0}      ~ n<0
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1150
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1151
%\tdx{Suc_less_eq}    (Suc m < Suc n) = (m<n)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1152
%\tdx{less_induct}    [| !!n. [| ! m. m<n --> P m |] ==> P n |]  ==>  P n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1153
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1154
%\tdx{less_linear}    m<n | m=n | n<m
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1155
%\subcaption{The less-than relation}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1156
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1157
\caption{Recursion equations for {\tt nat}} \label{hol-nat2}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1158
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1159
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1160
\subsection{The type of natural numbers, {\tt nat}}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1161
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1162
The theory \thydx{NatDef} defines the natural numbers in a roundabout but
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1163
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
  1164
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
  1165
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
  1166
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
  1167
usual, the isomorphisms between~\tydx{nat} and its representation are made
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1168
explicitly. For details see the file {\tt NatDef.thy}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1169
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1170
%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
  1171
%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
  1172
%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
  1173
%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
  1174
%along arbitrary well-founded relations.  The corresponding theories are
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1175
%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
  1176
%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
  1177
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1178
Type~\tydx{nat} is an instance of class~\cldx{ord}, which makes the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1179
overloaded functions of this class (esp.\ \cdx{<} and \cdx{<=}, but also
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1180
\cdx{min}, \cdx{max} and \cdx{LEAST}) available on {\tt nat}. Theory
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1181
\thydx{Nat} builds on {\tt NatDef} and shows that {\tt<=} is a partial order,
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1182
i.e.\ {\tt nat} is an instance of class {\tt order}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1183
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1184
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
  1185
defines addition, multiplication, subtraction, division, and remainder.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1186
Many of their properties are proved: commutative, associative and
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1187
distributive laws, identity and cancellation laws, etc.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1188
%  The most
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1189
%interesting result is perhaps the theorem $a \bmod b + (a/b)\times b = a$.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1190
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
  1191
well-founded rather than primitive recursion.  See Figs.\ts\ref{hol-nat1}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1192
and~\ref{hol-nat2}. The recursion equations for the operators {\tt +}, {\tt
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1193
-} and {\tt *} are part of the default simpset.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1194
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1195
Functions on {\tt nat} can be defined by primitive recursion, for example
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1196
addition:
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1197
\begin{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1198
\sdx{primrec} "op +" nat 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1199
  "0 + n = n"
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1200
  "Suc m + n = Suc(m + n)"
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1201
\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1202
(Remember that the name of an infix operator $\oplus$ is {\tt op}~$\oplus$.)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1203
The general format for defining primitive recursive functions on {\tt nat}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1204
follows the rules for primitive recursive functions on datatypes
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1205
(see~\S\ref{sec:HOL:primrec}).
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1206
There is also a \sdx{case}-construct of the form
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1207
\begin{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1208
case \(e\) of 0 => \(a\) | Suc \(m\) => \(b\)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1209
\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1210
Note that Isabelle insists on precisely this format; you may not even change
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1211
the order of the two cases.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1212
Both {\tt primrec} and {\tt case} are realized by a recursion operator
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1213
\cdx{nat_rec}, the details of which can be found in theory {\tt NatDef}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1214
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1215
%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
  1216
%Recursion along this relation resembles primitive recursion, but is
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1217
%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
  1218
%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
  1219
%is not primitive recursive \cite[page~104]{thompson91}.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1220
%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
  1221
%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
  1222
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1223
Tactic {\tt\ttindex{induct_tac} "$n$" $i$} performs induction on variable~$n$
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1224
in subgoal~$i$ using theorem {\tt nat_induct}. There is also the derived
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1225
theorem \tdx{less_induct}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1226
\begin{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1227
[| !!n. [| ! m. m<n --> P m |] ==> P n |]  ==>  P n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1228
\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1229
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1230
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1231
Reasoning about arithmetic inequalities can be tedious. A minimal amount of
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1232
automation is provided by the tactic \ttindex{trans_tac} of type {\tt int ->
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1233
tactic} that deals with simple inequalities. Note that it only knows about
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1234
{\tt 0}, {\tt Suc}, {\tt<} and {\tt<=}. The following goals are all solved by
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1235
{\tt trans_tac 1}:
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1236
\begin{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1237
{\out  1. [| \dots |] ==> m <= Suc(Suc m)}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1238
{\out  1. [| \dots i <= j \dots Suc j <= k \dots |] ==> i < k}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1239
{\out  1. [| \dots Suc m <= n \dots ~ m < n \dots |] ==> \dots}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1240
\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1241
For a complete description of the limitations of the tactic and how to avoid
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1242
some of them, see the comments at the start of the file {\tt
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1243
Provers/nat_transitive.ML}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1244
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1245
If {\tt trans_tac} fails you, try to find relevant arithmetic results in the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1246
library. The theory {\tt NatDef} contains theorems about {\tt<} and {\tt<=},
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1247
the theory {\tt Arith} contains theorems about {\tt +}, {\tt -}, {\tt *},
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1248
{\tt div} and {\tt mod}. Since specific results may be hard to find, we
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1249
recommend the {\tt find}-functions (see the {\em Reference Manual\/}).
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1250
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1251
\begin{figure}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1252
\index{#@{\tt[]} symbol}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1253
\index{#@{\tt\#} symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1254
\index{"@@{\tt\at} symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1255
\begin{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1256
  \it symbol & \it meta-type & \it priority & \it description \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1257
  \tt[]    & $\alpha\,list$ & & empty list\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1258
  \tt \#   & $[\alpha,\alpha\,list]\To \alpha\,list$ & Right 65 & 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1259
        list constructor \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1260
  \cdx{null}    & $\alpha\,list \To bool$ & & emptiness test\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1261
  \cdx{hd}      & $\alpha\,list \To \alpha$ & & head \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1262
  \cdx{tl}      & $\alpha\,list \To \alpha\,list$ & & tail \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1263
  \cdx{ttl}     & $\alpha\,list \To \alpha\,list$ & & total tail \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1264
  \tt\at  & $[\alpha\,list,\alpha\,list]\To \alpha\,list$ & Left 65 & append \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1265
  \cdx{map}     & $(\alpha\To\beta) \To (\alpha\,list \To \beta\,list)$
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1266
        & & mapping functional\\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1267
  \cdx{filter}  & $(\alpha \To bool) \To (\alpha\,list \To \alpha\,list)$
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1268
        & & filter functional\\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1269
  \cdx{list_all}& $(\alpha \To bool) \To (\alpha\,list \To bool)$
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1270
        & & forall functional\\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1271
  \cdx{set_of_list}& $\alpha\,list \To \alpha\,set$ & & elements\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1272
  \sdx{mem}  & $[\alpha,\alpha\,list]\To bool$    &  Left 55   & membership\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1273
  \cdx{foldl}   & $(\beta\To\alpha\To\beta) \To \beta \To \alpha\,list \To \beta$ &
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1274
  & iteration \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1275
  \cdx{concat}   & $(\alpha\,list)list\To \alpha\,list$ & & concatenation \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1276
  \cdx{rev}     & $\alpha\,list \To \alpha\,list$ & & reverse \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1277
  \cdx{length}  & $\alpha\,list \To nat$ & & length \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1278
  \cdx{nth}  & $nat \To \alpha\,list \To \alpha$ & & indexing \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1279
  \cdx{take}, \cdx{drop} & $nat \To \alpha\,list \To \alpha\,list$ &&
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1280
    take/drop prefix \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1281
  \cdx{takeWhile},\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1282
  \cdx{dropWhile} &
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1283
    $(\alpha \To bool) \To \alpha\,list \To \alpha\,list$ &&
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1284
    take/drop prefix
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1285
\end{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1286
\subcaption{Constants and infixes}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1287
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1288
\begin{center} \tt\frenchspacing
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1289
\begin{tabular}{rrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1290
  \it external        & \it internal  & \it description \\{}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1291
  [$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
  1292
        \rm finite list \\{}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1293
  [$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
  1294
        \rm list comprehension
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1295
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1296
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1297
\subcaption{Translations}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
  1298
\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
  1299
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1300
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1301
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1302
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1303
\begin{ttbox}\makeatother
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1304
null [] = True
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1305
null (x#xs) = False
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1306
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1307
hd (x#xs) = x
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1308
tl (x#xs) = xs
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1309
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1310
[] @ ys = ys
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1311
(x#xs) @ ys = x # xs @ ys
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1312
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1313
map f [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1314
map f (x#xs) = f x # map f xs
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1315
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1316
filter P [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1317
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
  1318
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1319
set_of_list [] = \{\}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1320
set_of_list (x#xs) = insert x (set_of_list xs)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1321
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1322
x mem [] = False
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1323
x mem (y#ys) = (if y=x then True else x mem ys)
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1324
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1325
foldl f a [] = a
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1326
foldl f a (x#xs) = foldl f (f a x) xs
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1327
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1328
concat([]) = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1329
concat(x#xs) = x @ concat(xs)
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1330
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1331
rev([]) = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1332
rev(x#xs) = rev(xs) @ [x]
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1333
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1334
length([]) = 0
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1335
length(x#xs) = Suc(length(xs))
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1336
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1337
nth 0 xs = hd xs
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1338
nth (Suc n) xs = nth n (tl xs)
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1339
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1340
take n [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1341
take n (x#xs) = (case n of 0 => [] | Suc(m) => x # take m xs)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1342
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1343
drop n [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1344
drop n (x#xs) = (case n of 0 => x#xs | Suc(m) => drop m xs)
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1345
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1346
takeWhile P [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1347
takeWhile P (x#xs) = (if P x then x#takeWhile P xs else [])
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1348
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1349
dropWhile P [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1350
dropWhile P (x#xs) = (if P x then dropWhile P xs else xs)
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1351
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1352
\caption{Recursions equations for list processing functions}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1353
\label{fig:HOL:list-simps}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1354
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1355
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1356
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1357
\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
  1358
\index{*list type}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1359
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1360
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
  1361
operations with their types and syntax. The type constructor {\tt list} is
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1362
defined as a {\tt datatype} with the constructors {\tt[]} and {\tt\#}.  As a
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1363
result the generic induction tactic \ttindex{induct_tac} also performs
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1364
structural induction over lists. A \sdx{case} construct of the form
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1365
\begin{center}\tt
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1366
case $e$ of [] => $a$  |  \(x\)\#\(xs\) => b
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1367
\end{center}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1368
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
  1369
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1370
{\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
  1371
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
  1372
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
  1373
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1374
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1375
\subsection{Introducing new types}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1376
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1377
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
  1378
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
  1379
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
  1380
{\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
  1381
described elsewhere.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1382
\begin{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1383
  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
  1384
  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
  1385
\end{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1386
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
  1387
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
  1388
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
  1389
Thus~$A$ is a non-empty subset of~$\tau$, and the new type denotes this
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1390
subset.  New functions are defined that establish an isomorphism between the
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1391
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
  1392
\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
  1393
$(\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
  1394
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1395
\begin{figure}[htbp]
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1396
\begin{rail}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1397
typedef  : 'typedef' ( () | '(' tname ')') type '=' set witness;
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1398
type    : typevarlist name ( () | '(' infix ')' );
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1399
tname   : name;
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1400
set     : string;
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1401
witness : () | '(' id ')';
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1402
\end{rail}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1403
\caption{Syntax of type definition}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1404
\label{fig:HOL:typedef}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1405
\end{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1406
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1407
The syntax for type definitions is shown in Fig.~\ref{fig:HOL:typedef}. For
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1408
the definition of `typevarlist' and `infix' see
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1409
\iflabelundefined{chap:classical}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1410
{the appendix of the {\em Reference Manual\/}}%
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1411
{Appendix~\ref{app:TheorySyntax}}. The remaining nonterminals have the
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1412
following meaning:
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1413
\begin{description}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1414
\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
  1415
  optional infix annotation.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1416
\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
  1417
  case $ty$ is a symbolic name. Default: $ty$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1418
\item[\it set]: the representing subset $A$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1419
\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
  1420
  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
  1421
  non-emptiness automatically.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1422
\end{description}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1423
If all context conditions are met (no duplicate type variables in
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1424
`typevarlist', no extra type variables in `set', and no free term variables
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1425
in `set'), the following components are added to the theory:
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1426
\begin{itemize}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1427
\item a type $ty :: (term,\dots)term$;
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1428
\item constants
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1429
\begin{eqnarray*}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1430
T &::& (\tau)set \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1431
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
  1432
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
  1433
\end{eqnarray*}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1434
\item a definition and three axioms
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1435
\[
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1436
\begin{array}{ll}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1437
T{\tt_def} & T \equiv A \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1438
{\tt Rep_}T & Rep_T(x) : T \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1439
{\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
  1440
{\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
  1441
\end{array}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1442
\]
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1443
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
  1444
and its inverse $Abs_T$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1445
\end{itemize}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1446
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
  1447
\begin{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1448
typedef unit = "\{True\}"
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1449
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1450
typedef (prod)
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1451
  ('a, 'b) "*"    (infixr 20)
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1452
      = "\{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
  1453
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1454
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1455
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
  1456
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
  1457
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
  1458
\begin{enumerate}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1459
\item Find an appropriate type $\tau$ and subset $A$ which has the desired
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  1460
  properties $P$, and make a type definition based on this representation.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1461
\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
  1462
\end{enumerate}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1463
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
  1464
abstract properties $P$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1465
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1466
\begin{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1467
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
  1468
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
  1469
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
  1470
\par
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1471
\begin{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1472
arities \(ty\): (term,\(\dots\),term)term
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1473
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1474
in your theory file to tell Isabelle that $ty$ is in class {\tt term}, the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1475
class of all HOL types.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1476
\end{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1477
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1478
\section{Datatype declarations}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1479
\label{sec:HOL:datatype}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1480
\index{*datatype|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1481
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1482
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
  1483
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
  1484
rules that describe the new type. The theory definition section {\tt
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1485
datatype} automates this.
1113
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
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1488
\subsection{Foundations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1489
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1490
\underscoreon
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1491
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1492
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
  1493
\[ \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
  1494
      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
  1495
      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
  1496
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1497
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
  1498
$\tau_{ij}$ are one of the following:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1499
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1500
\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
  1501
\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
  1502
  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
  1503
  \{\alpha_1,\dots,\alpha_n\}$,
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1504
\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
  1505
    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
  1506
    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
  1507
    components.}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1508
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1509
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
  1510
$\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
  1511
$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
  1512
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
  1513
  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
  1514
\mbox{\tt datatype}~ t ~=~ C(t~list). \]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1515
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1516
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
  1517
type:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1518
\[ 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
  1519
These functions have certain {\em freeness} properties:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1520
\begin{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1521
\item[\tt distinct] They are distinct:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1522
\[ 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
  1523
   \mbox{for all}~ i \neq j.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1524
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1525
\item[\tt inject] They are injective:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1526
\[ (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
  1527
   (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
  1528
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1529
\end{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1530
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
  1531
constructors, a different method is used if their number exceeds
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1532
a certain value, currently 6. In that case every constructor is mapped to a
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1533
natural number
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1534
\[
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1535
\begin{array}{lcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1536
\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
  1537
& \vdots & \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1538
\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
  1539
\end{array}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1540
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1541
and distinctness of constructors is expressed by:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1542
\[
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1543
\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
  1544
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1545
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
  1546
\[
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1547
\infer{P x}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1548
{\begin{array}{lcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1549
\Forall x_1\dots x_{k_1}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1550
  \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
  1551
  \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
  1552
 & \vdots & \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1553
\Forall x_1\dots x_{k_m}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1554
  \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
  1555
  \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
  1556
\end{array}}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1557
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1558
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
  1559
= (\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
  1560
all arguments of the recursive type.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1561
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1562
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
  1563
\[
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1564
\begin{array}{rrcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1565
\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
  1566
                           \vdots \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1567
                           \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
  1568
\end{array}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1569
\]
2994
3bb5d1b9c3aa Tuple patterns are allowed now in `case'
nipkow
parents: 2975
diff changeset
  1570
where the $x_{ij}$ are either identifiers or nested tuple patterns as in
3bb5d1b9c3aa Tuple patterns are allowed now in `case'
nipkow
parents: 2975
diff changeset
  1571
\S\ref{subsec:prod-sum}.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1572
\begin{warn}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1573
In contrast to \ML, {\em all} constructors must be present, their order is
2994
3bb5d1b9c3aa Tuple patterns are allowed now in `case'
nipkow
parents: 2975
diff changeset
  1574
fixed, and nested patterns are not supported (with the exception of tuples).
3bb5d1b9c3aa Tuple patterns are allowed now in `case'
nipkow
parents: 2975
diff changeset
  1575
Violating this restriction results in strange error messages.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1576
\end{warn}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1577
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1578
\underscoreoff
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1579
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1580
\subsection{Defining datatypes}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1581
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1582
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
  1583
  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
  1584
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
  1585
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
  1586
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
  1587
section.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1588
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1589
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1590
\begin{rail}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1591
typedecl : typevarlist id '=' (cons + '|')
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1592
         ;
1581
a82618a900e5 updated syntax of datatype declaration
clasohm
parents: 1578
diff changeset
  1593
cons     : name (typ *) ( () | mixfix )
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1594
         ;
1581
a82618a900e5 updated syntax of datatype declaration
clasohm
parents: 1578
diff changeset
  1595
typ      : id | tid | ('(' typevarlist id ')')
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1596
         ;
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1597
\end{rail}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1598
\caption{Syntax of datatype declarations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1599
\label{datatype-grammar}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1600
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1601
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1602
\begin{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1603
  If there are 7 or more constructors, the {\it t\_ord} scheme is used for
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1604
  distinctness theorems.  In this case the theory {\tt Arith} must be
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1605
  contained in the current theory, if necessary by including it explicitly.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1606
\end{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1607
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1608
Most of the theorems about the datatype become part of the default simpset
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1609
and you never need to see them again because the simplifier applies them
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1610
automatically. Only induction is invoked by hand:
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1611
\begin{ttdescription}
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1612
\item[\ttindexbold{induct_tac} {\tt"}$x${\tt"} $i$]
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1613
 applies structural induction on variable $x$ to subgoal $i$, provided the
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1614
 type of $x$ is a datatype or type {\tt nat}.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1615
\end{ttdescription}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1616
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1617
For the technically minded, we give a more detailed description.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1618
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
  1619
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
  1620
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
  1621
  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
  1622
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1623
val distinct : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1624
val inject : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1625
val induct : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1626
val cases : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1627
val simps : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1628
val induct_tac : string -> int -> tactic
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1629
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1630
{\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
  1631
above. For convenience {\tt distinct} contains inequalities in both
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1632
directions.  The reduction rules of the {\tt case}-construct are in {\tt
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1633
cases}.  All theorems from {\tt distinct}, {\tt inject} and {\tt cases} are
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1634
combined in {\tt simps}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1635
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1636
\subsection{Examples}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1637
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1638
\subsubsection{The datatype $\alpha~list$}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1639
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1640
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
  1641
  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
  1642
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
  1643
\begin{ttbox}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1644
MyList = HOL +
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1645
  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
  1646
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1647
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1648
After loading the theory (\verb$use_thy "MyList"$), we can prove
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1649
$Cons~x~xs\neq xs$.  
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1650
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1651
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
  1652
{\out Level 0}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1653
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1654
{\out  1. ! x. Cons x xs ~= xs}
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
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
  1657
\begin{ttbox}
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1658
by (induct_tac "xs" 1);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1659
{\out Level 1}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1660
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1661
{\out  1. ! x. Cons x Nil ~= Nil}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1662
{\out  2. !!a list.}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1663
{\out        ! x. Cons x list ~= list ==>}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1664
{\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
  1665
\end{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1666
The first subgoal can be proved using the simplifier.
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1667
Isabelle has already added the freeness properties of lists to the 
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1668
default simplification set.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1669
\begin{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1670
by (Simp_tac 1);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1671
{\out Level 2}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1672
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1673
{\out  1. !!a list.}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1674
{\out        ! x. Cons x list ~= list ==>}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1675
{\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
  1676
\end{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1677
Similarly, we prove the remaining goal.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1678
\begin{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1679
by (Asm_simp_tac 1);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1680
{\out Level 3}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1681
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1682
{\out No subgoals!}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1683
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1684
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
  1685
done that in one step using
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1686
\begin{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1687
by (ALLGOALS Asm_simp_tac);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1688
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1689
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1690
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1691
\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
  1692
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1693
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
  1694
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
  1695
\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
  1696
after the constructor declarations as follows:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1697
\begin{ttbox}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1698
MyList = HOL +
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1699
  datatype 'a list = "[]" ("[]") 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1700
                   | "#" 'a ('a list) (infixr 70)
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1701
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1702
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1703
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
  1704
proof is the same.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1705
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1706
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1707
\subsubsection{A datatype for weekdays}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1708
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1709
This example shows a datatype that consists of more than 6 constructors:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1710
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1711
Days = Arith +
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1712
  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
  1713
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1714
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1715
Because there are more than 6 constructors, the theory must be based on
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1716
{\tt Arith}.  Inequality is defined via a function \verb|days_ord|.  The
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1717
theorem \verb|Mo ~= Tu| is not directly contained among the distinctness
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1718
theorems, but the simplifier can prove it thanks to rewrite rules inherited
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1719
from theory {\tt Arith}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1720
\begin{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1721
goal Days.thy "Mo ~= Tu";
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1722
by (Simp_tac 1);
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1723
\end{ttbox}
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1724
You need not derive such inequalities explicitly: the simplifier will dispose
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1725
of them automatically.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1726
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
\subsection{Primitive recursive functions}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1729
\label{sec:HOL:primrec}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1730
\index{primitive recursion|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1731
\index{*primrec|(}
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
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
  1734
  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
  1735
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
  1736
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1737
Append = MyList +
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1738
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
  1739
rules 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1740
   app_Nil   "app [] ys = ys"
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1741
   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
  1742
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1743
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1744
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
  1745
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
  1746
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
  1747
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1748
Append = MyList +
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1749
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
  1750
primrec app MyList.list
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1751
   "app [] ys = ys"
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1752
   "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
  1753
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1754
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1755
Isabelle will now check that the two rules do indeed form a primitive
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1756
recursive definition, thus ensuring that consistency is maintained. For
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1757
example
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1758
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1759
primrec app MyList.list
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1760
    "app [] ys = us"
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1761
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1762
is rejected:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1763
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1764
Extra variables on rhs
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1765
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1766
\bigskip
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
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
  1769
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1770
primrec {\it function} {\it type}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1771
    {\it reduction rules}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1772
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1773
where
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1774
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1775
\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
  1776
  {\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
  1777
\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
  1778
  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
  1779
  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
  1780
  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
  1781
  different theories.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1782
\item {\it reduction rules} specify one or more equations of the form \[
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1783
  f~x@1~\dots~x@m~(C~y@1~\dots~y@k)~z@1~\dots~z@n = r \] such that $C$ is a
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1784
  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
  1785
  left-hand side, and all recursive calls in $r$ are of the form
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1786
  $f~\dots~y@i~\dots$ for some $i$. There must be exactly one reduction rule
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1787
  for each constructor. The order is immaterial. {\em All reduction rules are
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1788
  added to the default {\tt simpset}.}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1789
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1790
  If you would like to refer to some rule explicitly, you have to prefix each
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1791
  rule with an identifier (like in the {\tt rules} section of the first {\tt
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1792
  Append} theory above) that will serve as the name of the corresponding
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1793
  theorem at the \ML\ level.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1794
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1795
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
  1796
intermixed with other declarations.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1797
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1798
For the consistency-conscious user it may be reassuring to know that {\tt
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1799
  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
  1800
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
  1801
a recursion operator on the datatype.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1802
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1803
The primitive recursive function can have infix or mixfix syntax:
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1804
\begin{ttbox}\underscoreon
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1805
Append = MyList +
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1806
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
  1807
primrec "op @" MyList.list
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1808
   "[] @ ys = ys"
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1809
   "(x#xs) @ ys = x#(xs @ ys)"
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1810
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1811
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1812
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1813
The reduction rules for {\tt\at} become part of the default simpset, which
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1814
leads to short proofs:
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1815
\begin{ttbox}\underscoreon
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1816
goal Append.thy "(xs @ ys) @ zs = xs @ (ys @ zs)";
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1817
by (induct\_tac "xs" 1);
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1818
by (ALLGOALS Asm\_simp\_tac);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1819
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1820
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1821
%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
  1822
%\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1823
%Tl = MyList +
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1824
%consts tl  :: 'a list => 'a list
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1825
%primrec tl MyList.list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1826
%   tl_Cons "tl(x#xs) = xs"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1827
%end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1828
%\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1829
%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
  1830
%\verb$tl([])$ is.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1831
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1832
\index{primitive recursion|)}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1833
\index{*primrec|)}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1834
\index{*datatype|)}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1835
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1836
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1837
\section{Inductive and coinductive definitions}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1838
\index{*inductive|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1839
\index{*coinductive|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1840
2975
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  1841
An {\bf inductive definition} specifies the least set~$R$ closed under given
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  1842
rules.  (Applying a rule to elements of~$R$ yields a result within~$R$.)  For
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  1843
example, a structural operational semantics is an inductive definition of an
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  1844
evaluation relation.  Dually, a {\bf coinductive definition} specifies the
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  1845
greatest set~$R$ consistent with given rules.  (Every element of~$R$ can be
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  1846
seen as arising by applying a rule to elements of~$R$.)  An important example
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  1847
is using bisimulation relations to formalize equivalence of processes and
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  1848
infinite data structures.
1113
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
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
  1851
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
  1852
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
  1853
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
  1854
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1855
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
  1856
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
  1857
substructure of the main theory structure.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1858
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1859
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
  1860
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
  1861
  longer version is distributed with Isabelle.} which you should refer to
2933
f842a75d9624 Updated discussion and references for inductive definitions
paulson
parents: 2926
diff changeset
  1862
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
  1863
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
  1864
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
  1865
rules for type-checking.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1866
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1867
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1868
\subsection{The result structure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1869
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
  1870
others are self-explanatory.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1871
\begin{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1872
\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
  1873
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1874
\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
  1875
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1876
\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
  1877
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1878
\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
  1879
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
  1880
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1881
\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
  1882
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
  1883
names given them in the theory file. 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1884
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1885
\item[\tt elim] is the elimination rule.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1886
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1887
\item[\tt mk_cases] is a function to create simplified instances of {\tt
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1888
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
  1889
\end{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1890
2933
f842a75d9624 Updated discussion and references for inductive definitions
paulson
parents: 2926
diff changeset
  1891
For an inductive definition, the result structure contains two induction
f842a75d9624 Updated discussion and references for inductive definitions
paulson
parents: 2926
diff changeset
  1892
rules, {\tt induct} and \verb|mutual_induct|.  (To save storage, the latter
f842a75d9624 Updated discussion and references for inductive definitions
paulson
parents: 2926
diff changeset
  1893
rule is just {\tt True} unless more than one set is being defined.)  For a
f842a75d9624 Updated discussion and references for inductive definitions
paulson
parents: 2926
diff changeset
  1894
coinductive definition, it contains the rule \verb|coinduct|.
1113
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
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
  1897
specifying the types of all these components.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1898
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1899
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1900
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1901
sig
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1902
val thy          : theory
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1903
val defs         : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1904
val mono         : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1905
val unfold       : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1906
val intrs        : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1907
val elim         : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1908
val mk_cases     : thm list -> string -> thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1909
{\it(Inductive definitions only)} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1910
val induct       : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1911
val mutual_induct: thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1912
{\it(Coinductive definitions only)}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1913
val coinduct    : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1914
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1915
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1916
\hrule
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1917
\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
  1918
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1919
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1920
\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
  1921
An inductive definition has the form
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1922
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1923
inductive    {\it inductive sets}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1924
  intrs      {\it introduction rules}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1925
  monos      {\it monotonicity theorems}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1926
  con_defs   {\it constructor definitions}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1927
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1928
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
  1929
{\tt coinductive}.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1930
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1931
The {\tt monos} and {\tt con_defs} sections are optional.  If present,
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1932
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
  1933
{\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
  1934
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
  1935
file on your directory.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1936
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1937
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1938
\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
  1939
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1940
\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
  1941
  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
  1942
  the rule in the result structure.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1943
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1944
\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
  1945
  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
  1946
  be a theorem of the form $A\subseteq B\Imp M(A)\subseteq M(B)$, for each
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1947
  premise $t\in M(R@i)$ in an introduction rule!
1113
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 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
  1950
  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
  1951
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1952
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1953
The package has a few notable restrictions:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1954
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1955
\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
  1956
  constants.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1957
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1958
\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
  1959
operators.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1960
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1961
\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
  1962
may contain any number of side-conditions.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1963
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1964
\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
  1965
  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
  1966
\end{itemize}
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
\subsection{Example of an inductive definition}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1970
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
  1971
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
  1972
inductively, with two introduction rules:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1973
\begin{ttbox}
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  1974
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
  1975
inductive "Fin A"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1976
  intrs
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1977
    emptyI  "\{\} : Fin A"
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1978
    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
  1979
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1980
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
  1981
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
  1982
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
  1983
rule is {\tt Fin.induct}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1984
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1985
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
  1986
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
  1987
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
  1988
\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
  1989
of this example in more detail.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1990
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1991
Acc = WF + 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1992
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
  1993
       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
  1994
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
  1995
inductive "acc r"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1996
  intrs
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1997
     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
  1998
  monos   "[Pow_mono]"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1999
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2000
\end{ttbox}
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2001
The HOL distribution contains many other inductive definitions.  Simple
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2002
examples are collected on subdirectory \texttt{Induct}.  The theory {\tt
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2003
  HOL/Induct/LList.thy} contains coinductive definitions.  Larger examples may
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2004
be found on other subdirectories, such as {\tt IMP}, {\tt Lambda} and {\tt
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2005
  Auth}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2006
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2007
\index{*coinductive|)} \index{*inductive|)}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2008
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2009
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2010
\section{The examples directories}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2011
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2012
Directory {\tt HOL/Auth} contains theories for proving the correctness of 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2013
cryptographic protocols.  The approach is based upon operational 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2014
semantics~\cite{paulson-security} rather than the more usual belief logics.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2015
On the same directory are proofs for some standard examples, such as the 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2016
Needham-Schroeder public-key authentication protocol~\cite{paulson-ns} 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2017
and the Otway-Rees protocol.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2018
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2019
Directory {\tt HOL/IMP} contains a formalization of various denotational,
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2020
operational and axiomatic semantics of a simple while-language, the necessary
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2021
equivalence proofs, soundness and completeness of the Hoare rules with respect
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2022
to the 
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2023
denotational semantics, and soundness and completeness of a verification
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2024
condition generator. Much of development is taken from
2933
f842a75d9624 Updated discussion and references for inductive definitions
paulson
parents: 2926
diff changeset
  2025
Winskel~\cite{winskel93}. For details see~\cite{nipkow-IMP}.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2026
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2027
Directory {\tt HOL/Hoare} contains a user friendly surface syntax for Hoare
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2028
logic, including a tactic for generating verification-conditions.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2029
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2030
Directory {\tt HOL/MiniML} contains a formalization of the type system of the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2031
core functional language Mini-ML and a correctness proof for its type
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2032
inference algorithm $\cal W$~\cite{milner78,nazareth-nipkow}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2033
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2034
Directory {\tt HOL/Lambda} contains a formalization of untyped
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2035
$\lambda$-calculus in de~Bruijn notation and Church-Rosser proofs for $\beta$
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2036
and $\eta$ reduction~\cite{Nipkow-CR}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2037
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  2038
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
  2039
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
  2040
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
  2041
theory~\cite{mw81}. 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2042
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2043
Directory {\tt HOL/Induct} presents simple examples of (co)inductive
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2044
definitions.  
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2045
\begin{itemize}
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2046
\item Theory {\tt PropLog} proves the soundness and completeness of
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2047
  classical propositional logic, given a truth table semantics.  The only
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2048
  connective is $\imp$.  A Hilbert-style axiom system is specified, and its
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2049
  set of theorems defined inductively.  A similar proof in \ZF{} is
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2050
  described elsewhere~\cite{paulson-set-II}.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2051
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2052
\item Theory {\tt Term} develops an experimental recursive type definition;
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2053
  the recursion goes through the type constructor~\tydx{list}.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2054
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2055
\item Theory {\tt Simult} constructs mutually recursive sets of trees and
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2056
  forests, including induction and recursion rules.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2057
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2058
\item The definition of lazy lists demonstrates methods for handling
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2059
  infinite data structures and coinduction in higher-order
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2060
  logic~\cite{paulson-coind}.%
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2061
\footnote{To be precise, these lists are \emph{potentially infinite} rather
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2062
  than lazy.  Lazy implies a particular operational semantics.}
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2063
  Theory \thydx{LList} defines an operator for
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2064
  corecursion on lazy lists, which is used to define a few simple functions
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2065
  such as map and append.   A coinduction principle is defined
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2066
  for proving equations on lazy lists.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2067
  
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2068
\item Theory \thydx{LFilter} defines the filter functional for lazy lists.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2069
  This functional is notoriously difficult to define because finding the next
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2070
  element meeting the predicate requires possibly unlimited search.  It is not
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2071
  computable, but can be expressed using a combination of induction and
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2072
  corecursion.  
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2073
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2074
\item Theory \thydx{Exp} illustrates the use of iterated inductive definitions
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2075
  to express a programming language semantics that appears to require mutual
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2076
  induction.  Iterated induction allows greater modularity.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2077
\end{itemize}
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2078
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  2079
Directory {\tt HOL/ex} contains other examples and experimental proofs in
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2080
{\HOL}.  
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2081
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2082
\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
  2083
  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
  2084
  moderately difficult problems involving equality and quantifiers.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2085
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2086
\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
  2087
    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
  2088
  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
  2089
  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
  2090
  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
  2091
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2092
\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
  2093
  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
  2094
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2095
\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
  2096
  \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
  2097
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2098
\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
  2099
  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
  2100
  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
  2101
  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
  2102
  environment, which makes a coinductive argument appropriate.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2103
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2104
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2105
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2106
\goodbreak
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
  2107
\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
  2108
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
  2109
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
  2110
it is so easily expressed:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2111
\[  \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
  2112
    \forall x::\alpha. f~x \not= S 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2113
\] 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2114
%
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2115
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
  2116
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
  2117
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
  2118
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  2119
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
  2120
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
  2121
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
  2122
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2123
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
  2124
{\out Level 0}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2125
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2126
{\out  1. ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2127
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2128
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
  2129
$\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
  2130
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2131
by (resolve_tac [notI] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2132
{\out Level 1}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2133
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2134
{\out  1. ?S : range f ==> False}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2135
\ttbreak
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2136
by (eresolve_tac [rangeE] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2137
{\out Level 2}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2138
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2139
{\out  1. !!x. ?S = f x ==> False}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2140
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2141
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
  2142
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
  2143
any~$\Var{c}$.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2144
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2145
by (eresolve_tac [equalityCE] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2146
{\out Level 3}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2147
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2148
{\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
  2149
{\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
  2150
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2151
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
  2152
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
  2153
$\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
  2154
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
  2155
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2156
by (dresolve_tac [CollectD] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2157
{\out Level 4}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2158
{\out ~ \{x. ?P7 x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2159
{\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
  2160
{\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
  2161
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2162
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
  2163
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
  2164
is the standard diagonal construction.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2165
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2166
by (contr_tac 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2167
{\out Level 5}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2168
{\out ~ \{x. ~ x : f x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2169
{\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
  2170
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2171
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
  2172
assumption, we employ \ttindex{swap_res_tac}:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2173
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2174
by (swap_res_tac [CollectI] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2175
{\out Level 6}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2176
{\out ~ \{x. ~ x : f x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2177
{\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
  2178
\ttbreak
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2179
by (assume_tac 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2180
{\out Level 7}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2181
{\out ~ \{x. ~ x : f x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2182
{\out No subgoals!}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2183
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2184
How much creativity is required?  As it happens, Isabelle can prove this
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2185
theorem automatically.  The default classical set {\tt!claset} contains rules
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  2186
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
  2187
\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
  2188
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
  2189
successfully navigates through the large search space.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2190
\index{search!best-first}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2191
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2192
choplev 0;
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2193
{\out Level 0}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2194
{\out ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2195
{\out  1. ~ ?S : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2196
\ttbreak
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2197
by (best_tac (!claset addSEs [equalityCE]) 1);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2198
{\out Level 1}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2199
{\out ~ \{x. ~ x : f x\} : range f}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2200
{\out No subgoals!}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2201
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2202
If you run this example interactively, make sure your current theory contains
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2203
theory {\tt Set}, for example by executing
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2204
\ttindex{set_current_thy}~{\tt"Set"}. Otherwise the default claset may not
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2205
contain the rules for set theory.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2206
\index{higher-order logic|)}