doc-src/Logics/HOL.tex
author paulson
Wed, 03 Feb 1999 13:23:24 +0100
changeset 6170 9a59cf8ae9b5
parent 6141 a6922171b396
child 6406 0f6076dca737
permissions -rw-r--r--
standard spelling: type-checking
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
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
     8
Church's original paper~\cite{church40}.  Andrews's
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
     9
book~\cite{andrews86} is a full description of the original
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
    10
Church-style higher-order logic.  Experience with the {\sc hol} system
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
    11
has demonstrated that higher-order logic is widely applicable in many
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
    12
areas of mathematics and computer science, not just hardware
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
    13
verification, {\sc hol}'s original \textit{raison d'\^etre\/}.  It is
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
    14
weaker than {\ZF} set theory but for most applications this does not
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
    15
matter.  If you prefer {\ML} to Lisp, you will probably prefer \HOL\ 
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
    16
to~{\ZF}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    17
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    18
The syntax of \HOL\footnote{Earlier versions of Isabelle's \HOL\ used a
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
    19
different syntax.  Ancient releases of Isabelle included still another version
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    20
of~\HOL, with explicit type inference rules~\cite{paulson-COLOG}.  This
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    21
version no longer exists, but \thydx{ZF} supports a similar style of
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    22
reasoning.} follows $\lambda$-calculus and functional programming.  Function
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    23
application is curried.  To apply the function~$f$ of type
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    24
$\tau@1\To\tau@2\To\tau@3$ to the arguments~$a$ and~$b$ in \HOL, you simply
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
    25
write $f\,a\,b$.  There is no `apply' operator as in \thydx{ZF}.  Note that
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    26
$f(a,b)$ means ``$f$ applied to the pair $(a,b)$'' in \HOL.  We write ordered
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    27
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
    28
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
    29
\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
    30
identifies object-level types with meta-level types, taking advantage of
6170
9a59cf8ae9b5 standard spelling: type-checking
paulson
parents: 6141
diff changeset
    31
Isabelle's built-in type-checker.  It identifies object-level functions
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    32
with meta-level functions, so it uses Isabelle's operations for abstraction
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    33
and application.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    34
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
    35
These identifications allow Isabelle to support \HOL\ particularly
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
    36
nicely, but they also mean that \HOL\ requires more sophistication
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
    37
from the user --- in particular, an understanding of Isabelle's type
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
    38
system.  Beginners should work with \texttt{show_types} (or even
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
    39
\texttt{show_sorts}) set to \texttt{true}.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    40
%  Gain experience by
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    41
%working in first-order logic before attempting to use higher-order logic.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    42
%This chapter assumes familiarity with~{\FOL{}}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    43
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    44
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    45
\begin{figure}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
    46
\begin{constants}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    47
  \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
    48
  \cdx{Trueprop}& $bool\To prop$                & coercion to $prop$\\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    49
  \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
    50
  \cdx{True}    & $bool$                        & tautology ($\top$) \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    51
  \cdx{False}   & $bool$                        & absurdity ($\bot$) \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    52
  \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
    53
  \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
    54
\end{constants}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    55
\subcaption{Constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    56
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
    57
\begin{constants}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    58
\index{"@@{\tt\at} symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    59
\index{*"! symbol}\index{*"? symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    60
\index{*"?"! symbol}\index{*"E"X"! symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    61
  \it symbol &\it name     &\it meta-type & \it description \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    62
  \tt\at & \cdx{Eps}  & $(\alpha\To bool)\To\alpha$ & 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    63
        Hilbert description ($\varepsilon$) \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    64
  {\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
    65
        universal quantifier ($\forall$) \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    66
  {\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
    67
        existential quantifier ($\exists$) \\
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
    68
  {\tt?!} or \texttt{EX!}  & \cdx{Ex1}  & $(\alpha\To bool)\To bool$ & 
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    69
        unique existence ($\exists!$)\\
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
    70
  \texttt{LEAST}  & \cdx{Least}  & $(\alpha::ord \To bool)\To\alpha$ & 
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    71
        least element
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
    72
\end{constants}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    73
\subcaption{Binders} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    74
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
    75
\begin{constants}
1113
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
\index{&@{\tt\&} symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    78
\index{*"| symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    79
\index{*"-"-"> symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    80
  \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
    81
  \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
    82
        Left 55 & composition ($\circ$) \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
    83
  \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
    84
  \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
    85
  \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
    86
                less than or equals ($\leq$)\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    87
  \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
    88
  \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
    89
  \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
    90
\end{constants}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    91
\subcaption{Infixes}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
    92
\caption{Syntax of \texttt{HOL}} \label{hol-constants}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    93
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    94
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    95
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    96
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    97
\index{*let symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    98
\index{*in symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
    99
\dquotes
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   100
\[\begin{array}{rclcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   101
    term & = & \hbox{expression of class~$term$} \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   102
         & | & "\at~" id " . " formula \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   103
         & | & 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   104
    \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
   105
         & | & 
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   106
    \multicolumn{3}{l}{"if"~formula~"then"~term~"else"~term} \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   107
         & | & "LEAST"~ id " . " formula \\[2ex]
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   108
 formula & = & \hbox{expression of type~$bool$} \\
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
         & | & term " \ttilde= " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   111
         & | & term " < " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   112
         & | & term " <= " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   113
         & | & "\ttilde\ " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   114
         & | & formula " \& " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   115
         & | & formula " | " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   116
         & | & formula " --> " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   117
         & | & "!~~~" id~id^* " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   118
         & | & "ALL~" id~id^* " . " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   119
         & | & "?~~~" id~id^* " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   120
         & | & "EX~~" id~id^* " . " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   121
         & | & "?!~~" id~id^* " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   122
         & | & "EX!~" id~id^* " . " formula
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   123
  \end{array}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   124
\]
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   125
\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
   126
\end{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   127
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   128
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   129
\section{Syntax}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   130
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   131
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
   132
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
   133
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
   134
$\neg(a=b)$.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   135
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   136
\begin{warn}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   137
  \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
   138
  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
   139
  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
   140
  $\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
   141
  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
   142
  parentheses.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   143
\end{warn}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   144
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   145
\subsection{Types and classes}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   146
The universal type class of higher-order terms is called~\cldx{term}.
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   147
By default, explicit type variables have class \cldx{term}.  In
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   148
particular the equality symbol and quantifiers are polymorphic over
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   149
class \texttt{term}.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   150
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   151
The type of formulae, \tydx{bool}, belongs to class \cldx{term}; thus,
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   152
formulae are terms.  The built-in type~\tydx{fun}, which constructs
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   153
function types, is overloaded with arity {\tt(term,\thinspace
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   154
  term)\thinspace term}.  Thus, $\sigma\To\tau$ belongs to class~{\tt
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   155
  term} if $\sigma$ and~$\tau$ do, allowing quantification over
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   156
functions.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   157
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   158
\HOL\ offers various methods for introducing new types.
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   159
See~\S\ref{sec:HOL:Types} and~\S\ref{sec:HOL:datatype}.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   160
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   161
Theory \thydx{Ord} defines the syntactic class \cldx{ord} of order
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   162
signatures; the relations $<$ and $\leq$ are polymorphic over this
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   163
class, as are the functions \cdx{mono}, \cdx{min} and \cdx{max}, and
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   164
the \cdx{LEAST} operator. \thydx{Ord} also defines a subclass
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   165
\cldx{order} of \cldx{ord} which axiomatizes partially ordered types
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   166
(w.r.t.\ $\le$).
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   167
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   168
Three other syntactic type classes --- \cldx{plus}, \cldx{minus} and
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   169
\cldx{times} --- permit overloading of the operators {\tt+},\index{*"+
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   170
  symbol} {\tt-}\index{*"- symbol} and {\tt*}.\index{*"* symbol} In
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   171
particular, {\tt-} is instantiated for set difference and subtraction
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   172
on natural numbers.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   173
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   174
If you state a goal containing overloaded functions, you may need to include
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   175
type constraints.  Type inference may otherwise make the goal more
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   176
polymorphic than you intended, with confusing results.  For example, the
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   177
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
   178
$\alpha::\{ord,plus\}$, although you may have expected them to have some
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   179
numeric type, e.g. $nat$.  Instead you should have stated the goal as
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   180
$(i::nat) \le j \Imp i \le j+k$, which causes all three variables to have
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   181
type $nat$.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   182
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   183
\begin{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   184
  If resolution fails for no obvious reason, try setting
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   185
  \ttindex{show_types} to \texttt{true}, causing Isabelle to display
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   186
  types of terms.  Possibly set \ttindex{show_sorts} to \texttt{true} as
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   187
  well, causing Isabelle to display type classes and sorts.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   188
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   189
  \index{unification!incompleteness of}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   190
  Where function types are involved, Isabelle's unification code does not
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   191
  guarantee to find instantiations for type variables automatically.  Be
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   192
  prepared to use \ttindex{res_inst_tac} instead of \texttt{resolve_tac},
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   193
  possibly instantiating type variables.  Setting
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   194
  \ttindex{Unify.trace_types} to \texttt{true} causes Isabelle to report
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   195
  omitted search paths during unification.\index{tracing!of unification}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   196
\end{warn}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   197
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
\subsection{Binders}
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   200
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   201
Hilbert's {\bf description} operator~$\varepsilon x. P[x]$ stands for
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   202
some~$x$ satisfying~$P$, if such exists.  Since all terms in \HOL\ 
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   203
denote something, a description is always meaningful, but we do not
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   204
know its value unless $P$ defines it uniquely.  We may write
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   205
descriptions as \cdx{Eps}($\lambda x. P[x]$) or use the syntax
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   206
\hbox{\tt \at $x$.\ $P[x]$}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   207
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   208
Existential quantification is defined by
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   209
\[ \exists x. P~x \;\equiv\; P(\varepsilon x. P~x). \]
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   210
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
   211
of~$\exists$ and~$\forall$.  An Isabelle binder, it admits nested
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   212
quantifications.  For instance, $\exists!x\,y. P\,x\,y$ abbreviates
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   213
$\exists!x. \exists!y. P\,x\,y$; note that this does not mean that there
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   214
exists a unique pair $(x,y)$ satisfying~$P\,x\,y$.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   215
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   216
\index{*"! symbol}\index{*"? symbol}\index{HOL system@{\sc hol} system}
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   217
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
   218
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
   219
existential quantifier must be followed by a space; thus {\tt?x} is an
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   220
unknown, while \verb'? x. f x=y' is a quantification.  Isabelle's usual
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   221
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
   222
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
   223
\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
   224
true}, then~{\tt!}\ and~{\tt?}\ are displayed; this is the default.  If set
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   225
to \texttt{false}, then~\texttt{ALL} and~\texttt{EX} are displayed.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   226
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   227
If $\tau$ is a type of class \cldx{ord}, $P$ a formula and $x$ a
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   228
variable of type $\tau$, then the term \cdx{LEAST}~$x. P[x]$ is defined
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   229
to be the least (w.r.t.\ $\le$) $x$ such that $P~x$ holds (see
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   230
Fig.~\ref{hol-defs}).  The definition uses Hilbert's $\varepsilon$
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   231
choice operator, so \texttt{Least} is always meaningful, but may yield
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   232
nothing useful in case there is not a unique least element satisfying
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   233
$P$.\footnote{Class $ord$ does not require much of its instances, so
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   234
  $\le$ need not be a well-ordering, not even an order at all!}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   235
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   236
\medskip All these binders have priority 10.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   237
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   238
\begin{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   239
The low priority of binders means that they need to be enclosed in
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   240
parenthesis when they occur in the context of other operations.  For example,
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   241
instead of $P \land \forall x. Q$ you need to write $P \land (\forall x. Q)$.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   242
\end{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   243
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   244
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   245
\subsection{The \sdx{let} and \sdx{case} constructions}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   246
Local abbreviations can be introduced by a \texttt{let} construct whose
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   247
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
   248
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
   249
definition, \tdx{Let_def}.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   250
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   251
\HOL\ also defines the basic syntax
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   252
\[\dquotes"case"~e~"of"~c@1~"=>"~e@1~"|" \dots "|"~c@n~"=>"~e@n\] 
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   253
as a uniform means of expressing \texttt{case} constructs.  Therefore \texttt{case}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   254
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
   255
logical meaning.  By declaring translations, you can cause instances of the
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   256
\texttt{case} construct to denote applications of particular case operators.
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   257
This is what happens automatically for each \texttt{datatype} definition
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   258
(see~\S\ref{sec:HOL:datatype}).
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   259
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   260
\begin{warn}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   261
Both \texttt{if} and \texttt{case} constructs have as low a priority as
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   262
quantifiers, which requires additional enclosing parentheses in the context
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   263
of most other operations.  For example, instead of $f~x = {\tt if\dots
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   264
then\dots else}\dots$ you need to write $f~x = ({\tt if\dots then\dots
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   265
else\dots})$.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   266
\end{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   267
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   268
\section{Rules of inference}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   269
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   270
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   271
\begin{ttbox}\makeatother
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   272
\tdx{refl}           t = (t::'a)
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   273
\tdx{subst}          [| s = t; P s |] ==> P (t::'a)
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   274
\tdx{ext}            (!!x::'a. (f x :: 'b) = 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
   275
\tdx{impI}           (P ==> Q) ==> P-->Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   276
\tdx{mp}             [| P-->Q;  P |] ==> Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   277
\tdx{iff}            (P-->Q) --> (Q-->P) --> (P=Q)
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   278
\tdx{selectI}        P(x::'a) ==> P(@x. P x)
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   279
\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
   280
\end{ttbox}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   281
\caption{The \texttt{HOL} rules} \label{hol-rules}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   282
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   283
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   284
Figure~\ref{hol-rules} shows the primitive inference rules of~\HOL{},
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   285
with their~{\ML} names.  Some of the rules deserve additional
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   286
comments:
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   287
\begin{ttdescription}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   288
\item[\tdx{ext}] expresses extensionality of functions.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   289
\item[\tdx{iff}] asserts that logically equivalent formulae are
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   290
  equal.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   291
\item[\tdx{selectI}] gives the defining property of the Hilbert
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   292
  $\varepsilon$-operator.  It is a form of the Axiom of Choice.  The derived rule
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   293
  \tdx{select_equality} (see below) is often easier to use.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   294
\item[\tdx{True_or_False}] makes the logic classical.\footnote{In
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   295
    fact, the $\varepsilon$-operator already makes the logic classical, as
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   296
    shown by Diaconescu; see Paulson~\cite{paulson-COLOG} for details.}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   297
\end{ttdescription}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   298
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   299
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   300
\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
   301
\begin{ttbox}\makeatother
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   302
\tdx{True_def}   True     == ((\%x::bool. x)=(\%x. x))
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   303
\tdx{All_def}    All      == (\%P. P = (\%x. True))
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   304
\tdx{Ex_def}     Ex       == (\%P. P(@x. P x))
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   305
\tdx{False_def}  False    == (!P. P)
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   306
\tdx{not_def}    not      == (\%P. P-->False)
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   307
\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
   308
\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
   309
\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
   310
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   311
\tdx{o_def}      op o     == (\%(f::'b=>'c) g x::'a. f(g x))
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   312
\tdx{if_def}     If P x y ==
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   313
              (\%P x y. @z::'a.(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
   314
\tdx{Let_def}    Let s f  == f s
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   315
\tdx{Least_def}  Least P  == @x. P(x) & (ALL y. P(y) --> x <= y)"
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   316
\end{ttbox}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   317
\caption{The \texttt{HOL} definitions} \label{hol-defs}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   318
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   319
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   320
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   321
\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
   322
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
   323
(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
   324
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
   325
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
   326
higher-order logic may equate formulae and even functions over formulae.
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   327
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
   328
meta-equality~({\tt==}) for definitions.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   329
\begin{warn}
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   330
The definitions above should never be expanded and are shown for completeness
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   331
only.  Instead users should reason in terms of the derived rules shown below
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   332
or, better still, using high-level tactics
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   333
(see~\S\ref{sec:HOL:generic-packages}).
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   334
\end{warn}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   335
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   336
Some of the rules mention type variables; for example, \texttt{refl}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   337
mentions the type variable~{\tt'a}.  This allows you to instantiate
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   338
type variables explicitly by calling \texttt{res_inst_tac}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   339
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
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   342
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   343
\tdx{sym}         s=t ==> t=s
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   344
\tdx{trans}       [| r=s; s=t |] ==> r=t
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   345
\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
   346
\tdx{box_equals}  [| a=b;  a=c;  b=d |] ==> c=d  
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   347
\tdx{arg_cong}    x = y ==> f x = f y
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   348
\tdx{fun_cong}    f = g ==> f x = g x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   349
\tdx{cong}        [| f = g; x = y |] ==> f x = g y
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   350
\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
   351
\subcaption{Equality}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   352
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   353
\tdx{TrueI}       True 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   354
\tdx{FalseE}      False ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   355
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   356
\tdx{conjI}       [| P; Q |] ==> P&Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   357
\tdx{conjunct1}   [| P&Q |] ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   358
\tdx{conjunct2}   [| P&Q |] ==> Q 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   359
\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
   360
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   361
\tdx{disjI1}      P ==> P|Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   362
\tdx{disjI2}      Q ==> P|Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   363
\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
   364
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   365
\tdx{notI}        (P ==> False) ==> ~ P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   366
\tdx{notE}        [| ~ P;  P |] ==> R
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   367
\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
   368
\subcaption{Propositional logic}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   369
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   370
\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
   371
\tdx{iffD1}       [| P=Q; P |] ==> Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   372
\tdx{iffD2}       [| P=Q; Q |] ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   373
\tdx{iffE}        [| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   374
%
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   375
%\tdx{eqTrueI}     P ==> P=True 
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   376
%\tdx{eqTrueE}     P=True ==> P 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   377
\subcaption{Logical equivalence}
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
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   380
\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
   381
\end{figure}
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
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   384
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   385
\begin{ttbox}\makeatother
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   386
\tdx{allI}      (!!x. P x) ==> !x. P x
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   387
\tdx{spec}      !x. P x ==> P x
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   388
\tdx{allE}      [| !x. P x;  P x ==> R |] ==> R
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   389
\tdx{all_dupE}  [| !x. P x;  [| P x; !x. P x |] ==> R |] ==> R
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   390
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   391
\tdx{exI}       P x ==> ? x. P x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   392
\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
   393
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   394
\tdx{ex1I}      [| P a;  !!x. P x ==> x=a |] ==> ?! x. P x
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   395
\tdx{ex1E}      [| ?! x. P x;  !!x. [| P x;  ! y. P y --> y=x |] ==> R 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   396
          |] ==> R
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   397
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   398
\tdx{select_equality} [| P a;  !!x. P x ==> x=a |] ==> (@x. P x) = a
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   399
\subcaption{Quantifiers and descriptions}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   400
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   401
\tdx{ccontr}          (~P ==> False) ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   402
\tdx{classical}       (~P ==> P) ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   403
\tdx{excluded_middle} ~P | P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   404
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   405
\tdx{disjCI}          (~Q ==> P) ==> P|Q
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   406
\tdx{exCI}            (! x. ~ P x ==> P a) ==> ? x. P x
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   407
\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
   408
\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
   409
\tdx{notnotD}         ~~P ==> P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   410
\tdx{swap}            ~P ==> (~Q ==> P) ==> Q
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   411
\subcaption{Classical logic}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   412
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   413
%\tdx{if_True}         (if True then x else y) = x
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   414
%\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
   415
\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
   416
\tdx{if_not_P}        ~ P ==> (if P then x else y) = y
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   417
\tdx{split_if}        P(if Q then x else y) = ((Q --> P x) & (~Q --> P y))
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   418
\subcaption{Conditionals}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   419
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   420
\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
   421
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   422
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   423
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
   424
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
   425
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
   426
conjunctions, implications, and universal quantifiers.  
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
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
   429
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
   430
simplifying both sides of an equation.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   431
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   432
The following simple tactics are occasionally useful:
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   433
\begin{ttdescription}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   434
\item[\ttindexbold{strip_tac} $i$] applies \texttt{allI} and \texttt{impI}
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   435
  repeatedly to remove all outermost universal quantifiers and implications
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   436
  from subgoal $i$.
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   437
\item[\ttindexbold{case_tac} {\tt"}$P${\tt"} $i$] performs case distinction
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   438
  on $P$ for subgoal $i$: the latter is replaced by two identical subgoals
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   439
  with the added assumptions $P$ and $\neg P$, respectively.
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   440
\end{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   441
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   442
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   443
\begin{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   444
\begin{center}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   445
\begin{tabular}{rrr}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   446
  \it name      &\it meta-type  & \it description \\ 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   447
\index{{}@\verb'{}' symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   448
  \verb|{}|     & $\alpha\,set$         & the empty set \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   449
  \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
   450
        & insertion of element \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   451
  \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
   452
        & comprehension \\
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
   453
  \cdx{Compl}   & $\alpha\,set\To\alpha\,set$
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   454
        & complement \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   455
  \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
   456
        & intersection over a set\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   457
  \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
   458
        & union over a set\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   459
  \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
   460
        &set of sets intersection \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   461
  \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
   462
        &set of sets union \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   463
  \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
   464
        & powerset \\[1ex]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   465
  \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
   466
        & range of a function \\[1ex]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   467
  \cdx{Ball}~~\cdx{Bex} & $[\alpha\,set,\alpha\To bool]\To bool$
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   468
        & bounded quantifiers
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   469
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   470
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   471
\subcaption{Constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   472
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   473
\begin{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   474
\begin{tabular}{llrrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   475
  \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
   476
  \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
   477
        intersection over a type\\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   478
  \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
   479
        union over a type
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   480
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   481
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   482
\subcaption{Binders} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   483
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   484
\begin{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   485
\index{*"`"` symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   486
\index{*": symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   487
\index{*"<"= symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   488
\begin{tabular}{rrrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   489
  \it symbol    & \it meta-type & \it priority & \it description \\ 
3161
d2c6f15f38f4 minor tuning;
wenzelm
parents: 3160
diff changeset
   490
  \tt ``        & $[\alpha\To\beta ,\alpha\,set]\To  \beta\,set$
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   491
        & Left 90 & image \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   492
  \sdx{Int}     & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   493
        & Left 70 & intersection ($\int$) \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   494
  \sdx{Un}      & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   495
        & Left 65 & union ($\un$) \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   496
  \tt:          & $[\alpha ,\alpha\,set]\To bool$       
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   497
        & Left 50 & membership ($\in$) \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   498
  \tt <=        & $[\alpha\,set,\alpha\,set]\To bool$
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   499
        & Left 50 & subset ($\subseteq$) 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   500
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   501
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   502
\subcaption{Infixes}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   503
\caption{Syntax of the theory \texttt{Set}} \label{hol-set-syntax}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   504
\end{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   505
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   506
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   507
\begin{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   508
\begin{center} \tt\frenchspacing
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   509
\index{*"! symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   510
\begin{tabular}{rrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   511
  \it external          & \it internal  & \it description \\ 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   512
  $a$ \ttilde: $b$      & \ttilde($a$ : $b$)    & \rm non-membership\\
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   513
  {\ttlbrace}$a@1$, $\ldots${\ttrbrace}  &  insert $a@1$ $\ldots$ {\ttlbrace}{\ttrbrace} & \rm finite set \\
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   514
  {\ttlbrace}$x$. $P[x]${\ttrbrace}        &  Collect($\lambda x. P[x]$) &
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   515
        \rm comprehension \\
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   516
  \sdx{INT} $x$:$A$. $B[x]$      & INTER $A$ $\lambda x. B[x]$ &
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   517
        \rm intersection \\
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   518
  \sdx{UN}{\tt\ }  $x$:$A$. $B[x]$      & UNION $A$ $\lambda x. B[x]$ &
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   519
        \rm union \\
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   520
  \tt ! $x$:$A$. $P[x]$ or \sdx{ALL} $x$:$A$. $P[x]$ & 
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   521
        Ball $A$ $\lambda x. P[x]$ & 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   522
        \rm bounded $\forall$ \\
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   523
  \sdx{?} $x$:$A$. $P[x]$ or \sdx{EX}{\tt\ } $x$:$A$. $P[x]$ & 
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   524
        Bex $A$ $\lambda x. P[x]$ & \rm bounded $\exists$
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   525
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   526
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   527
\subcaption{Translations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   528
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   529
\dquotes
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   530
\[\begin{array}{rclcl}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   531
    term & = & \hbox{other terms\ldots} \\
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   532
         & | & "{\ttlbrace}{\ttrbrace}" \\
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   533
         & | & "{\ttlbrace} " term\; ("," term)^* " {\ttrbrace}" \\
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   534
         & | & "{\ttlbrace} " id " . " formula " {\ttrbrace}" \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   535
         & | & term " `` " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   536
         & | & term " Int " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   537
         & | & term " Un " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   538
         & | & "INT~~"  id ":" term " . " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   539
         & | & "UN~~~"  id ":" term " . " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   540
         & | & "INT~~"  id~id^* " . " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   541
         & | & "UN~~~"  id~id^* " . " term \\[2ex]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   542
 formula & = & \hbox{other formulae\ldots} \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   543
         & | & term " : " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   544
         & | & term " \ttilde: " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   545
         & | & term " <= " term \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   546
         & | & "!~" id ":" term " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   547
         & | & "ALL " id ":" term " . " formula \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   548
         & | & "?~" id ":" term " . " formula 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   549
         & | & "EX~~" id ":" term " . " formula
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   550
  \end{array}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   551
\]
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   552
\subcaption{Full Grammar}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   553
\caption{Syntax of the theory \texttt{Set} (continued)} \label{hol-set-syntax2}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   554
\end{figure} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   555
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   556
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   557
\section{A formulation of set theory}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   558
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
   559
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
   560
{\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
   561
theory, and behave more like {\ZF} classes.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   562
\begin{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   563
\item
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   564
Sets are given by predicates over some type~$\sigma$.  Types serve to
6170
9a59cf8ae9b5 standard spelling: type-checking
paulson
parents: 6141
diff changeset
   565
define universes for sets, but type-checking is still significant.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   566
\item
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   567
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
   568
may be defined by absolute comprehension.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   569
\item
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   570
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
   571
have a more complex type.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   572
\end{itemize}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   573
Finite unions and intersections have the same behaviour in \HOL\ as they
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   574
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
   575
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
   576
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   577
\subsection{Syntax of set theory}\index{*set type}
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
   578
\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
   579
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
   580
clarity and to avoid complications involving function types in unification.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   581
The isomorphisms between the two types are declared explicitly.  They are
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   582
very natural: \texttt{Collect} maps $\alpha\To bool$ to $\alpha\,set$, while
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   583
\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
   584
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   585
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
   586
translations.  Figure~\ref{hol-set-syntax2} presents the grammar of the new
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   587
constructs.  Infix operators include union and intersection ($A\un B$
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   588
and $A\int B$), the subset and membership relations, and the image
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   589
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
   590
$\neg(a\in b)$.  
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   591
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   592
The $\{a@1,\ldots\}$ notation abbreviates finite sets constructed in
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   593
the obvious manner using~\texttt{insert} and~$\{\}$:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   594
\begin{eqnarray*}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   595
  \{a, b, c\} & \equiv &
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   596
  \texttt{insert} \, a \, ({\tt insert} \, b \, ({\tt insert} \, c \, \{\}))
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   597
\end{eqnarray*}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   598
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   599
The set \hbox{\tt{\ttlbrace}$x$.\ $P[x]${\ttrbrace}} consists of all $x$ (of suitable type)
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   600
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
   601
occurrences of~$x$.  This syntax expands to \cdx{Collect}$(\lambda
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   602
x. P[x])$.  It defines sets by absolute comprehension, which is impossible
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   603
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
   604
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   605
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
   606
\begin{eqnarray*}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   607
   \forall x\in A. P[x] &\hbox{abbreviates}& \forall x. x\in A\imp P[x] \\
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   608
   \exists x\in A. P[x] &\hbox{abbreviates}& \exists x. x\in A\conj P[x]
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   609
\end{eqnarray*}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   610
The constants~\cdx{Ball} and~\cdx{Bex} are defined
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   611
accordingly.  Instead of \texttt{Ball $A$ $P$} and \texttt{Bex $A$ $P$} we may
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   612
write\index{*"! symbol}\index{*"? symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   613
\index{*ALL symbol}\index{*EX symbol} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   614
%
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   615
\hbox{\tt !~$x$:$A$.\ $P[x]$} and \hbox{\tt ?~$x$:$A$.\ $P[x]$}.  Isabelle's
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   616
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
   617
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
   618
\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
   619
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   620
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
   621
$\bigcap@{x\in A}B[x]$, are written 
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   622
\sdx{UN}~\hbox{\tt$x$:$A$.\ $B[x]$} and
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   623
\sdx{INT}~\hbox{\tt$x$:$A$.\ $B[x]$}.  
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   624
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   625
Unions and intersections over types, namely $\bigcup@x B[x]$ and $\bigcap@x
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   626
B[x]$, are written \sdx{UN}~\hbox{\tt$x$.\ $B[x]$} and
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   627
\sdx{INT}~\hbox{\tt$x$.\ $B[x]$}.  They are equivalent to the previous
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   628
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
   629
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   630
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
   631
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
   632
respectively.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   633
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   634
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   635
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   636
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   637
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   638
\tdx{mem_Collect_eq}    (a : {\ttlbrace}x. P x{\ttrbrace}) = P a
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   639
\tdx{Collect_mem_eq}    {\ttlbrace}x. x:A{\ttrbrace} = A
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   640
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   641
\tdx{empty_def}         {\ttlbrace}{\ttrbrace}          == {\ttlbrace}x. False{\ttrbrace}
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   642
\tdx{insert_def}        insert a B  == {\ttlbrace}x. x=a{\ttrbrace} Un B
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   643
\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
   644
\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
   645
\tdx{subset_def}        A <= B      == ! x:A. x:B
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   646
\tdx{Un_def}            A Un B      == {\ttlbrace}x. x:A | x:B{\ttrbrace}
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   647
\tdx{Int_def}           A Int B     == {\ttlbrace}x. x:A & x:B{\ttrbrace}
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   648
\tdx{set_diff_def}      A - B       == {\ttlbrace}x. x:A & x~:B{\ttrbrace}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   649
\tdx{Compl_def}         Compl A     == {\ttlbrace}x. ~ x:A{\ttrbrace}
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   650
\tdx{INTER_def}         INTER A B   == {\ttlbrace}y. ! x:A. y: B x{\ttrbrace}
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   651
\tdx{UNION_def}         UNION A B   == {\ttlbrace}y. ? x:A. y: B x{\ttrbrace}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   652
\tdx{INTER1_def}        INTER1 B    == INTER {\ttlbrace}x. True{\ttrbrace} B 
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   653
\tdx{UNION1_def}        UNION1 B    == UNION {\ttlbrace}x. True{\ttrbrace} B 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   654
\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
   655
\tdx{Union_def}         Union S     == (UN  x:S. x)
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   656
\tdx{Pow_def}           Pow A       == {\ttlbrace}B. B <= A{\ttrbrace}
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   657
\tdx{image_def}         f``A        == {\ttlbrace}y. ? x:A. y=f x{\ttrbrace}
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   658
\tdx{range_def}         range f     == {\ttlbrace}y. ? x. y=f x{\ttrbrace}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   659
\end{ttbox}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   660
\caption{Rules of the theory \texttt{Set}} \label{hol-set-rules}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   661
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   662
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   663
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   664
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   665
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   666
\tdx{CollectI}        [| P a |] ==> a : {\ttlbrace}x. P x{\ttrbrace}
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   667
\tdx{CollectD}        [| a : {\ttlbrace}x. P x{\ttrbrace} |] ==> P a
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   668
\tdx{CollectE}        [| a : {\ttlbrace}x. P x{\ttrbrace};  P a ==> W |] ==> W
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   669
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   670
\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
   671
\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
   672
\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
   673
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   674
\tdx{bexI}            [| P x;  x:A |] ==> ? x:A. P x
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   675
\tdx{bexCI}           [| ! x:A. ~ P x ==> P a;  a:A |] ==> ? x:A. P x
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   676
\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
   677
\subcaption{Comprehension and Bounded quantifiers}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   678
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   679
\tdx{subsetI}         (!!x. x:A ==> x:B) ==> A <= B
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   680
\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
   681
\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
   682
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   683
\tdx{subset_refl}     A <= A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   684
\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
   685
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   686
\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
   687
\tdx{equalityD1}      A = B ==> A<=B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   688
\tdx{equalityD2}      A = B ==> B<=A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   689
\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
   690
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   691
\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
   692
                           [| ~ c:A; ~ c:B |] ==> P 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   693
                |]  ==>  P
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   694
\subcaption{The subset and equality relations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   695
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   696
\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
   697
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   698
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   699
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   700
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   701
\begin{ttbox}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   702
\tdx{emptyE}   a : {\ttlbrace}{\ttrbrace} ==> P
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   703
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   704
\tdx{insertI1} a : insert a B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   705
\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
   706
\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
   707
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   708
\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
   709
\tdx{ComplD}   [| c : Compl A |] ==> ~ c:A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   710
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   711
\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
   712
\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
   713
\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
   714
\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
   715
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   716
\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
   717
\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
   718
\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
   719
\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
   720
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   721
\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
   722
\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
   723
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   724
\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
   725
\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
   726
\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
   727
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   728
\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
   729
\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
   730
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   731
\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
   732
\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
   733
\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
   734
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   735
\tdx{PowI}     A<=B ==> A: Pow B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   736
\tdx{PowD}     A: Pow B ==> A<=B
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   737
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   738
\tdx{imageI}   [| x:A |] ==> f x : f``A
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   739
\tdx{imageE}   [| b : f``A;  !!x.[| b=f x;  x:A |] ==> P |] ==> P
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   740
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   741
\tdx{rangeI}   f x : range f
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   742
\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
   743
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   744
\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
   745
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   746
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   747
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   748
\subsection{Axioms and rules of set theory}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   749
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
   750
axioms \tdx{mem_Collect_eq} and \tdx{Collect_mem_eq} assert
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   751
that the functions \texttt{Collect} and \hbox{\tt op :} are isomorphisms.  Of
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   752
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
   753
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   754
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
   755
quantifiers, unions, intersections, complements and the subset relation.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   756
They also include straightforward constructions on functions: image~({\tt``})
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   757
and \texttt{range}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   758
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   759
%The predicate \cdx{inj_on} is used for simulating type definitions.
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   760
%The statement ${\tt inj_on}~f~A$ asserts that $f$ is injective on the
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   761
%set~$A$, which specifies a subset of its domain type.  In a type
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   762
%definition, $f$ is the abstraction function and $A$ is the set of valid
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   763
%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
   764
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   765
%\begin{figure} \underscoreon
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   766
%\begin{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   767
%\tdx{Inv_f_f}    inj f ==> Inv f (f x) = x
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   768
%\tdx{f_Inv_f}    y : range f ==> f(Inv f y) = y
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   769
%
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   770
%\tdx{Inv_injective}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   771
%    [| 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
   772
%
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   773
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   774
%\tdx{monoI}      [| !!A B. A <= B ==> f A <= f B |] ==> mono f
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   775
%\tdx{monoD}      [| mono f;  A <= B |] ==> f A <= f B
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   776
%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   777
%\tdx{injI}       [| !! x y. f x = f y ==> x=y |] ==> inj f
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   778
%\tdx{inj_inverseI}              (!!x. g(f x) = x) ==> inj f
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   779
%\tdx{injD}       [| inj f; f x = f y |] ==> x=y
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   780
%
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   781
%\tdx{inj_onI}  (!!x y. [| f x=f y; x:A; y:A |] ==> x=y) ==> inj_on f A
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   782
%\tdx{inj_onD}  [| inj_on f A;  f x=f y;  x:A;  y:A |] ==> x=y
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   783
%
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   784
%\tdx{inj_on_inverseI}
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   785
%    (!!x. x:A ==> g(f x) = x) ==> inj_on f A
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   786
%\tdx{inj_on_contraD}
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   787
%    [| inj_on f A;  x~=y;  x:A;  y:A |] ==> ~ f x=f y
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   788
%\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   789
%\caption{Derived rules involving functions} \label{hol-fun}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   790
%\end{figure}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   791
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   792
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   793
\begin{figure} \underscoreon
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   794
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   795
\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
   796
\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
   797
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   798
\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
   799
\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
   800
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   801
\tdx{Un_upper1}       A <= A Un B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   802
\tdx{Un_upper2}       B <= A Un B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   803
\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
   804
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   805
\tdx{Int_lower1}      A Int B <= A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   806
\tdx{Int_lower2}      A Int B <= B
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   807
\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
   808
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   809
\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
   810
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   811
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   812
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   813
\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
   814
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   815
\tdx{Int_absorb}        A Int A = A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   816
\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
   817
\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
   818
\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
   819
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   820
\tdx{Un_absorb}         A Un A = A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   821
\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
   822
\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
   823
\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
   824
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   825
\tdx{Compl_disjoint}    A Int (Compl A) = {\ttlbrace}x. False{\ttrbrace}
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
   826
\tdx{Compl_partition}   A Un  (Compl A) = {\ttlbrace}x. True{\ttrbrace}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   827
\tdx{double_complement} Compl(Compl A) = A
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   828
\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
   829
\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
   830
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   831
\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
   832
\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
   833
\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
   834
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   835
\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
   836
\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
   837
\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
   838
\end{ttbox}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   839
\caption{Set equalities} \label{hol-equalities}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   840
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   841
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
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
   844
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
   845
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
   846
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
   847
\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
   848
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
   849
\tdx{equalityCE} supports classical reasoning about extensionality,
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   850
after the fashion of \tdx{iffCE}.  See the file \texttt{HOL/Set.ML} for
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   851
proofs pertaining to set theory.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   852
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   853
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
   854
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
   855
bounds.  Reasoning directly about subsets often yields clearer proofs than
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   856
reasoning about the membership relation.  See the file \texttt{HOL/subset.ML}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   857
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
   858
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
   859
include commutative, associative and distributive laws involving unions,
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   860
intersections and complements.  For a complete listing see the file {\tt
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   861
HOL/equalities.ML}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   862
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   863
\begin{warn}
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   864
\texttt{Blast_tac} proves many set-theoretic theorems automatically.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   865
Hence you seldom need to refer to the theorems above.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   866
\end{warn}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   867
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   868
\begin{figure}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   869
\begin{center}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   870
\begin{tabular}{rrr}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   871
  \it name      &\it meta-type  & \it description \\ 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   872
  \cdx{inj}~~\cdx{surj}& $(\alpha\To\beta )\To bool$
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   873
        & injective/surjective \\
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   874
  \cdx{inj_on}        & $[\alpha\To\beta ,\alpha\,set]\To bool$
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   875
        & injective over subset\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   876
  \cdx{inv} & $(\alpha\To\beta)\To(\beta\To\alpha)$ & inverse function
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   877
\end{tabular}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   878
\end{center}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   879
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   880
\underscoreon
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   881
\begin{ttbox}
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   882
\tdx{inj_def}         inj f      == ! x y. f x=f y --> x=y
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   883
\tdx{surj_def}        surj f     == ! y. ? x. y=f x
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   884
\tdx{inj_on_def}      inj_on f A == !x:A. !y:A. f x=f y --> x=y
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   885
\tdx{inv_def}         inv f      == (\%y. @x. f(x)=y)
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   886
\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   887
\caption{Theory \thydx{Fun}} \label{fig:HOL:Fun}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   888
\end{figure}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   889
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   890
\subsection{Properties of functions}\nopagebreak
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   891
Figure~\ref{fig:HOL:Fun} presents a theory of simple properties of functions.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   892
Note that ${\tt inv}~f$ uses Hilbert's $\varepsilon$ to yield an inverse
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   893
of~$f$.  See the file \texttt{HOL/Fun.ML} for a complete listing of the derived
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   894
rules.  Reasoning about function composition (the operator~\sdx{o}) and the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   895
predicate~\cdx{surj} is done simply by expanding the definitions.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   896
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   897
There is also a large collection of monotonicity theorems for constructions
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   898
on sets in the file \texttt{HOL/mono.ML}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
   899
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   900
\section{Generic packages}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   901
\label{sec:HOL:generic-packages}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   902
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   903
\HOL\ instantiates most of Isabelle's generic packages, making available the
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   904
simplifier and the classical reasoner.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   905
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   906
\subsection{Simplification and substitution}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   907
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   908
Simplification tactics tactics such as \texttt{Asm_simp_tac} and \texttt{Full_simp_tac} use the default simpset
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   909
(\texttt{simpset()}), which works for most purposes.  A quite minimal
6072
5583261db33d removal of FOL, ZF to a separate manual
paulson
parents: 5797
diff changeset
   910
simplification set for higher-order logic is~\ttindexbold{HOL_ss};
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   911
even more frugal is \ttindexbold{HOL_basic_ss}.  Equality~($=$), which
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   912
also expresses logical equivalence, may be used for rewriting.  See
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   913
the file \texttt{HOL/simpdata.ML} for a complete listing of the basic
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   914
simplification rules.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   915
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   916
See \iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   917
{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
   918
and simplification.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
   919
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   920
\begin{warn}\index{simplification!of conjunctions}%
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   921
  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
   922
  left part of a conjunction helps in simplifying the right part.  This effect
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   923
  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
   924
  including \ttindex{conj_cong} in a simpset, \verb$addcongs [conj_cong]$.
1234
56ee5cc35510 updated "o" in HOL: (infixl 55)
nipkow
parents: 1163
diff changeset
   925
\end{warn}
56ee5cc35510 updated "o" in HOL: (infixl 55)
nipkow
parents: 1163
diff changeset
   926
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   927
If the simplifier cannot use a certain rewrite rule --- either because
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
   928
of nontermination or because its left-hand side is too flexible ---
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   929
then you might try \texttt{stac}:
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   930
\begin{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   931
\item[\ttindexbold{stac} $thm$ $i,$] where $thm$ is of the form $lhs = rhs$,
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   932
  replaces in subgoal $i$ instances of $lhs$ by corresponding instances of
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
   933
  $rhs$.  In case of multiple instances of $lhs$ in subgoal $i$, backtracking
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   934
  may be necessary to select the desired ones.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   935
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   936
If $thm$ is a conditional equality, the instantiated condition becomes an
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   937
additional (first) subgoal.
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   938
\end{ttdescription}
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   939
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   940
 \HOL{} provides the tactic \ttindex{hyp_subst_tac}, which substitutes
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   941
  for an equality throughout a subgoal and its hypotheses.  This tactic uses
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
   942
  \HOL's general substitution rule.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
   943
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   944
\subsubsection{Case splitting}
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   945
\label{subsec:HOL:case:splitting}
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   946
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   947
\HOL{} also provides convenient means for case splitting during
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
   948
rewriting. Goals containing a subterm of the form \texttt{if}~$b$~{\tt
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   949
then\dots else\dots} often require a case distinction on $b$. This is
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   950
expressed by the theorem \tdx{split_if}:
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   951
$$
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   952
\Var{P}(\mbox{\tt if}~\Var{b}~{\tt then}~\Var{x}~\mbox{\tt else}~\Var{y})~=~
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   953
((\Var{b} \to \Var{P}(\Var{x})) \land (\neg \Var{b} \to \Var{P}(\Var{y})))
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   954
\eqno{(*)}
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   955
$$
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   956
For example, a simple instance of $(*)$ is
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   957
\[
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   958
x \in (\mbox{\tt if}~x \in A~{\tt then}~A~\mbox{\tt else}~\{x\})~=~
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   959
((x \in A \to x \in A) \land (x \notin A \to x \in \{x\}))
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   960
\]
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   961
Because $(*)$ is too general as a rewrite rule for the simplifier (the
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   962
left-hand side is not a higher-order pattern in the sense of
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   963
\iflabelundefined{chap:simplification}{the {\em Reference Manual\/}}%
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   964
{Chap.\ts\ref{chap:simplification}}), there is a special infix function 
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   965
\ttindexbold{addsplits} of type \texttt{simpset * thm list -> simpset}
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   966
(analogous to \texttt{addsimps}) that adds rules such as $(*)$ to a
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   967
simpset, as in
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   968
\begin{ttbox}
4877
7a046198610e fixed simpset(), claset();
wenzelm
parents: 4834
diff changeset
   969
by(simp_tac (simpset() addsplits [split_if]) 1);
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   970
\end{ttbox}
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   971
The effect is that after each round of simplification, one occurrence of
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   972
\texttt{if} is split acording to \texttt{split_if}, until all occurences of
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   973
\texttt{if} have been eliminated.
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   974
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   975
It turns out that using \texttt{split_if} is almost always the right thing to
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   976
do. Hence \texttt{split_if} is already included in the default simpset. If
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   977
you want to delete it from a simpset, use \ttindexbold{delsplits}, which is
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   978
the inverse of \texttt{addsplits}:
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   979
\begin{ttbox}
4877
7a046198610e fixed simpset(), claset();
wenzelm
parents: 4834
diff changeset
   980
by(simp_tac (simpset() delsplits [split_if]) 1);
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   981
\end{ttbox}
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   982
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   983
In general, \texttt{addsplits} accepts rules of the form
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   984
\[
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   985
\Var{P}(c~\Var{x@1}~\dots~\Var{x@n})~=~ rhs
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   986
\]
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   987
where $c$ is a constant and $rhs$ is arbitrary. Note that $(*)$ is of the
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   988
right form because internally the left-hand side is
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   989
$\Var{P}(\mathtt{If}~\Var{b}~\Var{x}~~\Var{y})$. Important further examples
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   990
are splitting rules for \texttt{case} expressions (see~\S\ref{subsec:list}
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
   991
and~\S\ref{subsec:datatype:basics}).
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
   992
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   993
Analogous to \texttt{Addsimps} and \texttt{Delsimps}, there are also
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   994
imperative versions of \texttt{addsplits} and \texttt{delsplits}
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   995
\begin{ttbox}
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   996
\ttindexbold{Addsplits}: thm list -> unit
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   997
\ttindexbold{Delsplits}: thm list -> unit
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   998
\end{ttbox}
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
   999
for adding splitting rules to, and deleting them from the current simpset.
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
  1000
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1001
\subsection{Classical reasoning}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1002
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  1003
\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
  1004
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
  1005
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
  1006
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1007
The classical reasoner is installed.  Tactics such as \texttt{Blast_tac} and {\tt
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1008
Best_tac} refer to the default claset (\texttt{claset()}), which works for most
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  1009
purposes.  Named clasets include \ttindexbold{prop_cs}, which includes the
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1010
propositional rules, and \ttindexbold{HOL_cs}, which also includes quantifier
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1011
rules.  See the file \texttt{HOL/cladata.ML} for lists of the classical rules,
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1012
and \iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1013
{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
  1014
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1015
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1016
\section{Types}\label{sec:HOL:Types}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1017
This section describes \HOL's basic predefined types ($\alpha \times
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1018
\beta$, $\alpha + \beta$, $nat$ and $\alpha \; list$) and ways for
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1019
introducing new types in general.  The most important type
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1020
construction, the \texttt{datatype}, is treated separately in
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1021
\S\ref{sec:HOL:datatype}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1022
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1023
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1024
\subsection{Product and sum types}\index{*"* type}\index{*"+ type}
2994
3bb5d1b9c3aa Tuple patterns are allowed now in `case'
nipkow
parents: 2975
diff changeset
  1025
\label{subsec:prod-sum}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1026
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1027
\begin{figure}[htbp]
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1028
\begin{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1029
  \it symbol    & \it meta-type &           & \it description \\ 
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1030
  \cdx{Pair}    & $[\alpha,\beta]\To \alpha\times\beta$
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1031
        & & ordered pairs $(a,b)$ \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1032
  \cdx{fst}     & $\alpha\times\beta \To \alpha$        & & first projection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1033
  \cdx{snd}     & $\alpha\times\beta \To \beta$         & & second projection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1034
  \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
  1035
        & & generalized projection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1036
  \cdx{Sigma}  & 
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1037
        $[\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
  1038
        & general sum of sets
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1039
\end{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1040
\begin{ttbox}\makeatletter
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1041
%\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
  1042
%\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
  1043
%\tdx{split_def}    split c p == c (fst p) (snd p)
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1044
\tdx{Sigma_def}    Sigma A B == UN x:A. UN y:B x. {\ttlbrace}(x,y){\ttrbrace}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1045
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1046
\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
  1047
\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
  1048
\tdx{PairE}        [| !!x y. p = (x,y) ==> Q |] ==> Q
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
\tdx{fst_conv}     fst (a,b) = a
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1051
\tdx{snd_conv}     snd (a,b) = b
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1052
\tdx{surjective_pairing}  p = (fst p,snd p)
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
\tdx{split}        split c (a,b) = c a b
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
  1055
\tdx{split_split}  R(split c p) = (! x y. p = (x,y) --> R(c x y))
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1056
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  1057
\tdx{SigmaI}    [| a:A;  b:B a |] ==> (a,b) : Sigma A B
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  1058
\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
  1059
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1060
\caption{Type $\alpha\times\beta$}\label{hol-prod}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1061
\end{figure} 
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1062
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1063
Theory \thydx{Prod} (Fig.\ts\ref{hol-prod}) defines the product type
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1064
$\alpha\times\beta$, with the ordered pair syntax $(a, b)$.  General
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1065
tuples are simulated by pairs nested to the right:
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1066
\begin{center}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1067
\begin{tabular}{c|c}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1068
external & internal \\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1069
\hline
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1070
$\tau@1 \times \dots \times \tau@n$ & $\tau@1 \times (\dots (\tau@{n-1} \times \tau@n)\dots)$ \\
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1071
\hline
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1072
$(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
  1073
\end{tabular}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1074
\end{center}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1075
In addition, it is possible to use tuples
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1076
as patterns in abstractions:
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1077
\begin{center}
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1078
{\tt\%($x$,$y$). $t$} \quad stands for\quad \texttt{split(\%$x$\thinspace$y$.\ $t$)} 
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1079
\end{center}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1080
Nested patterns are also supported.  They are translated stepwise:
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  1081
{\tt\%($x$,$y$,$z$). $t$} $\leadsto$ {\tt\%($x$,($y$,$z$)). $t$} $\leadsto$
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  1082
{\tt split(\%$x$.\%($y$,$z$). $t$)} $\leadsto$ \texttt{split(\%$x$. split(\%$y$
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1083
  $z$.\ $t$))}.  The reverse translation is performed upon printing.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1084
\begin{warn}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1085
  The translation between patterns and \texttt{split} is performed automatically
1448
77379ae9ff0d Stylistic changes to discussion of pattern-matching
paulson
parents: 1429
diff changeset
  1086
  by the parser and printer.  Thus the internal and external form of a term
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1087
  may differ, which can affects proofs.  For example the term {\tt
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1088
  (\%(x,y).(y,x))(a,b)} requires the theorem \texttt{split} (which is in the
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1089
  default simpset) to rewrite to {\tt(b,a)}.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1090
\end{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1091
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
  1092
variable binding construct which is internally described by a
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1093
$\lambda$-abstraction.  Some important examples are
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1094
\begin{description}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1095
\item[Let:] \texttt{let {\it pattern} = $t$ in $u$}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1096
\item[Quantifiers:] \texttt{!~{\it pattern}:$A$.~$P$}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1097
\item[Choice:] {\underscoreon \tt @~{\it pattern}~.~$P$}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1098
\item[Set operations:] \texttt{UN~{\it pattern}:$A$.~$B$}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1099
\item[Sets:] \texttt{{\ttlbrace}~{\it pattern}~.~$P$~{\ttrbrace}}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1100
\end{description}
1471
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1101
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1102
There is a simple tactic which supports reasoning about patterns:
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1103
\begin{ttdescription}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1104
\item[\ttindexbold{split_all_tac} $i$] replaces in subgoal $i$ all
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1105
  {\tt!!}-quantified variables of product type by individual variables for
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1106
  each component.  A simple example:
1471
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1107
\begin{ttbox}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1108
{\out 1. !!p. (\%(x,y,z). (x, y, z)) p = p}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1109
by(split_all_tac 1);
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1110
{\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
  1111
\end{ttbox}
b088c0a1f2bd documented split_all_tac in HOL.
nipkow
parents: 1448
diff changeset
  1112
\end{ttdescription}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1113
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1114
Theory \texttt{Prod} also introduces the degenerate product type \texttt{unit}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1115
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
  1116
\begin{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1117
\tdx{unit_eq}       u = ()
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1118
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1119
\bigskip
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1120
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1121
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
  1122
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
  1123
\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
  1124
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1125
The definition of products and sums in terms of existing types is not
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1126
shown.  The constructions are fairly standard and can be found in the
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1127
respective theory files.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1128
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1129
\begin{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1130
\begin{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1131
  \it symbol    & \it meta-type &           & \it description \\ 
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1132
  \cdx{Inl}     & $\alpha \To \alpha+\beta$    & & first injection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1133
  \cdx{Inr}     & $\beta \To \alpha+\beta$     & & second injection\\
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1134
  \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
  1135
        & & conditional
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1136
\end{constants}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1137
\begin{ttbox}\makeatletter
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1138
%\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
  1139
%                                        (!y. p=Inr y --> z=g y))
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1140
%
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1141
\tdx{Inl_not_Inr}    Inl a ~= Inr b
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1142
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1143
\tdx{inj_Inl}        inj Inl
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1144
\tdx{inj_Inr}        inj Inr
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1145
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
  1146
\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
  1147
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1148
\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
  1149
\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
  1150
1489
78e1ce42a825 Small changes.
nipkow
parents: 1471
diff changeset
  1151
\tdx{surjective_sum} sum_case (\%x. f(Inl x)) (\%y. f(Inr y)) s = f s
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
  1152
\tdx{split_sum_case} R(sum_case f g s) = ((! x. s = Inl(x) --> R(f(x))) &
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1153
                                     (! y. s = Inr(y) --> R(g(y))))
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1154
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1155
\caption{Type $\alpha+\beta$}\label{hol-sum}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1156
\end{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1157
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1158
\begin{figure}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1159
\index{*"< symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1160
\index{*"* symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1161
\index{*div symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1162
\index{*mod symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1163
\index{*"+ symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1164
\index{*"- symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1165
\begin{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1166
  \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
  1167
  \cdx{0}       & $nat$         & & zero \\
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1168
  \cdx{Suc}     & $nat \To nat$ & & successor function\\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1169
% \cdx{nat_case} & $[\alpha, nat\To\alpha, nat] \To\alpha$ & & conditional\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1170
% \cdx{nat_rec} & $[nat, \alpha, [nat, \alpha]\To\alpha] \To \alpha$
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1171
%        & & primitive recursor\\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1172
  \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
  1173
  \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
  1174
  \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
  1175
  \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
  1176
  \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
  1177
\end{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1178
\subcaption{Constants and infixes}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1179
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1180
\begin{ttbox}\makeatother
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1181
\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
  1182
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1183
\tdx{Suc_not_Zero}   Suc m ~= 0
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1184
\tdx{inj_Suc}        inj Suc
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1185
\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
  1186
\subcaption{Basic properties}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1187
\end{ttbox}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1188
\caption{The type of natural numbers, \tydx{nat}} \label{hol-nat1}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1189
\end{figure}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1190
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1191
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1192
\begin{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1193
\begin{ttbox}\makeatother
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1194
              0+n           = n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1195
              (Suc m)+n     = Suc(m+n)
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1196
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1197
              m-0           = m
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1198
              0-n           = n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1199
              Suc(m)-Suc(n) = m-n
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1200
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1201
              0*n           = 0
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1202
              Suc(m)*n      = n + m*n
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1203
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1204
\tdx{mod_less}      m<n ==> m mod n = m
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1205
\tdx{mod_geq}       [| 0<n;  ~m<n |] ==> m mod n = (m-n) mod n
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1206
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1207
\tdx{div_less}      m<n ==> m div n = 0
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1208
\tdx{div_geq}       [| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1209
\end{ttbox}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1210
\caption{Recursion equations for the arithmetic operators} \label{hol-nat2}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1211
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1212
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1213
\subsection{The type of natural numbers, \textit{nat}}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1214
\index{nat@{\textit{nat}} type|(}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1215
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1216
The theory \thydx{NatDef} defines the natural numbers in a roundabout but
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1217
traditional way.  The axiom of infinity postulates a type~\tydx{ind} of
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1218
individuals, which is non-empty and closed under an injective operation.  The
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1219
natural numbers are inductively generated by choosing an arbitrary individual
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1220
for~0 and using the injective operation to take successors.  This is a least
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1221
fixedpoint construction.  For details see the file \texttt{NatDef.thy}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1222
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1223
Type~\tydx{nat} is an instance of class~\cldx{ord}, which makes the
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1224
overloaded functions of this class (esp.\ \cdx{<} and \cdx{<=}, but also
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1225
\cdx{min}, \cdx{max} and \cdx{LEAST}) available on \tydx{nat}.  Theory
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1226
\thydx{Nat} builds on \texttt{NatDef} and shows that {\tt<=} is a partial order,
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1227
so \tydx{nat} is also an instance of class \cldx{order}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1228
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1229
Theory \thydx{Arith} develops arithmetic on the natural numbers.  It defines
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1230
addition, multiplication and subtraction.  Theory \thydx{Divides} defines
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1231
division, remainder and the ``divides'' relation.  The numerous theorems
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1232
proved include commutative, associative, distributive, identity and
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1233
cancellation laws.  See Figs.\ts\ref{hol-nat1} and~\ref{hol-nat2}.  The
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1234
recursion equations for the operators \texttt{+}, \texttt{-} and \texttt{*} on
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1235
\texttt{nat} are part of the default simpset.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1236
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1237
Functions on \tydx{nat} can be defined by primitive or well-founded recursion;
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1238
see \S\ref{sec:HOL:recursive}.  A simple example is addition.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1239
Here, \texttt{op +} is the name of the infix operator~\texttt{+}, following
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1240
the standard convention.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1241
\begin{ttbox}
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1242
\sdx{primrec}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1243
  "    0 + n = n"
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1244
  "Suc m + n = Suc(m + n)"
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1245
\end{ttbox}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1246
There is also a \sdx{case}-construct
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1247
of the form
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1248
\begin{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1249
case \(e\) of 0 => \(a\) | Suc \(m\) => \(b\)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1250
\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1251
Note that Isabelle insists on precisely this format; you may not even change
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1252
the order of the two cases.
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1253
Both \texttt{primrec} and \texttt{case} are realized by a recursion operator
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1254
\cdx{nat_rec}, the details of which can be found in theory \texttt{NatDef}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1255
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1256
%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
  1257
%Recursion along this relation resembles primitive recursion, but is
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1258
%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
  1259
%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
  1260
%is not primitive recursive \cite[page~104]{thompson91}.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1261
%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
  1262
%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
  1263
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  1264
Tactic {\tt\ttindex{induct_tac} "$n$" $i$} performs induction on variable~$n$
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1265
in subgoal~$i$ using theorem \texttt{nat_induct}.  There is also the derived
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1266
theorem \tdx{less_induct}:
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1267
\begin{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1268
[| !!n. [| ! m. m<n --> P m |] ==> P n |]  ==>  P n
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1269
\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1270
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1271
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1272
Reasoning about arithmetic inequalities can be tedious.  A minimal amount of
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1273
automation is provided by the tactic \ttindex{trans_tac} of type \texttt{int ->
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1274
tactic} that deals with simple inequalities.  Note that it only knows about
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1275
\texttt{0}, \texttt{Suc}, {\tt<} and {\tt<=}.  The following goals are all solved by
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1276
\texttt{trans_tac 1}:
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1277
\begin{ttbox}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1278
{\out  1. \dots ==> m <= Suc(Suc m)}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1279
{\out  1. [| \dots i <= j \dots Suc j <= k \dots |] ==> i < k}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1280
{\out  1. [| \dots Suc m <= n \dots ~ m < n \dots |] ==> \dots}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1281
\end{ttbox}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1282
For a complete description of the limitations of the tactic and how to avoid
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1283
some of them, see the comments at the start of the file {\tt
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1284
Provers/nat_transitive.ML}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1285
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1286
If \texttt{trans_tac} fails you, try to find relevant arithmetic results in
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1287
the library.  The theory \texttt{NatDef} contains theorems about {\tt<} and
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1288
{\tt<=}, the theory \texttt{Arith} contains theorems about \texttt{+},
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1289
\texttt{-} and \texttt{*}, and theory \texttt{Divides} contains theorems about
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1290
\texttt{div} and \texttt{mod}.  Use the \texttt{find}-functions to locate them
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1291
(see the {\em Reference Manual\/}).
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1292
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1293
\begin{figure}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1294
\index{#@{\tt[]} symbol}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1295
\index{#@{\tt\#} symbol}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1296
\index{"@@{\tt\at} symbol}
4503
5ed72705c201 nth -> !
nipkow
parents: 4068
diff changeset
  1297
\index{*"! symbol}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1298
\begin{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1299
  \it symbol & \it meta-type & \it priority & \it description \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1300
  \tt[]    & $\alpha\,list$ & & empty list\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1301
  \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
  1302
        list constructor \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1303
  \cdx{null}    & $\alpha\,list \To bool$ & & emptiness test\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1304
  \cdx{hd}      & $\alpha\,list \To \alpha$ & & head \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1305
  \cdx{tl}      & $\alpha\,list \To \alpha\,list$ & & tail \\
3881
73be08b4da3f Added last, butlast, dropped ttl.
nipkow
parents: 3489
diff changeset
  1306
  \cdx{last}    & $\alpha\,list \To \alpha$ & & last element \\
73be08b4da3f Added last, butlast, dropped ttl.
nipkow
parents: 3489
diff changeset
  1307
  \cdx{butlast} & $\alpha\,list \To \alpha\,list$ & & drop last element \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1308
  \tt\at  & $[\alpha\,list,\alpha\,list]\To \alpha\,list$ & Left 65 & append \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1309
  \cdx{map}     & $(\alpha\To\beta) \To (\alpha\,list \To \beta\,list)$
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1310
        & & apply to all\\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1311
  \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
  1312
        & & filter functional\\
3487
62a6a08471e4 set_of_list -> set
nipkow
parents: 3315
diff changeset
  1313
  \cdx{set}& $\alpha\,list \To \alpha\,set$ & & elements\\
4503
5ed72705c201 nth -> !
nipkow
parents: 4068
diff changeset
  1314
  \sdx{mem}  & $\alpha \To \alpha\,list \To bool$  &  Left 55   & membership\\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1315
  \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
  1316
  & iteration \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1317
  \cdx{concat}   & $(\alpha\,list)list\To \alpha\,list$ & & concatenation \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1318
  \cdx{rev}     & $\alpha\,list \To \alpha\,list$ & & reverse \\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1319
  \cdx{length}  & $\alpha\,list \To nat$ & & length \\
4503
5ed72705c201 nth -> !
nipkow
parents: 4068
diff changeset
  1320
  \tt! & $\alpha\,list \To nat \To \alpha$ & Left 100 & indexing \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1321
  \cdx{take}, \cdx{drop} & $nat \To \alpha\,list \To \alpha\,list$ &&
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1322
    take or drop a prefix \\
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1323
  \cdx{takeWhile},\\
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1324
  \cdx{dropWhile} &
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1325
    $(\alpha \To bool) \To \alpha\,list \To \alpha\,list$ &&
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1326
    take or drop a prefix
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1327
\end{constants}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1328
\subcaption{Constants and infixes}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1329
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1330
\begin{center} \tt\frenchspacing
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1331
\begin{tabular}{rrr} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1332
  \it external        & \it internal  & \it description \\{}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1333
  [$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
  1334
        \rm finite list \\{}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1335
  [$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
  1336
        \rm list comprehension
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1337
\end{tabular}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1338
\end{center}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1339
\subcaption{Translations}
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
  1340
\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
  1341
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1342
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1343
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1344
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1345
\begin{ttbox}\makeatother
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1346
null [] = True
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1347
null (x#xs) = False
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1348
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1349
hd (x#xs) = x
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1350
tl (x#xs) = xs
3881
73be08b4da3f Added last, butlast, dropped ttl.
nipkow
parents: 3489
diff changeset
  1351
tl [] = []
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1352
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1353
[] @ ys = ys
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1354
(x#xs) @ ys = x # xs @ ys
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1355
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1356
map f [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1357
map f (x#xs) = f x # map f xs
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1358
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1359
filter P [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1360
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
  1361
3487
62a6a08471e4 set_of_list -> set
nipkow
parents: 3315
diff changeset
  1362
set [] = \ttlbrace\ttrbrace
62a6a08471e4 set_of_list -> set
nipkow
parents: 3315
diff changeset
  1363
set (x#xs) = insert x (set xs)
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1364
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1365
x mem [] = False
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1366
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
  1367
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1368
foldl f a [] = a
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1369
foldl f a (x#xs) = foldl f (f a x) xs
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1370
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1371
concat([]) = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1372
concat(x#xs) = x @ concat(xs)
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1373
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1374
rev([]) = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1375
rev(x#xs) = rev(xs) @ [x]
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1376
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1377
length([]) = 0
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1378
length(x#xs) = Suc(length(xs))
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1379
4503
5ed72705c201 nth -> !
nipkow
parents: 4068
diff changeset
  1380
xs!0 = hd xs
5ed72705c201 nth -> !
nipkow
parents: 4068
diff changeset
  1381
xs!(Suc n) = (tl xs)!n
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1382
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1383
take n [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1384
take n (x#xs) = (case n of 0 => [] | Suc(m) => x # take m xs)
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1385
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1386
drop n [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1387
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
  1388
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1389
takeWhile P [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1390
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
  1391
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1392
dropWhile P [] = []
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1393
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
  1394
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1395
\caption{Recursions equations for list processing functions}
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1396
\label{fig:HOL:list-simps}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1397
\end{figure}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1398
\index{nat@{\textit{nat}} type|)}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1399
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1400
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1401
\subsection{The type constructor for lists, \textit{list}}
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1402
\label{subsec:list}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1403
\index{list@{\textit{list}} type|(}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1404
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1405
Figure~\ref{hol-list} presents the theory \thydx{List}: the basic list
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1406
operations with their types and syntax.  Type $\alpha \; list$ is
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1407
defined as a \texttt{datatype} with the constructors {\tt[]} and {\tt\#}.
3287
078be5581967 Documented exhaust_tac.
nipkow
parents: 3181
diff changeset
  1408
As a result the generic structural induction and case analysis tactics
078be5581967 Documented exhaust_tac.
nipkow
parents: 3181
diff changeset
  1409
\texttt{induct\_tac} and \texttt{exhaust\_tac} also become available for
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1410
lists.  A \sdx{case} construct of the form
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1411
\begin{center}\tt
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1412
case $e$ of [] => $a$  |  \(x\)\#\(xs\) => b
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1413
\end{center}
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1414
is defined by translation.  For details see~\S\ref{sec:HOL:datatype}. There
4067
207a7811faa9 Documented `split_t_case' thm genearted by datatype.
nipkow
parents: 3962
diff changeset
  1415
is also a case splitting rule \tdx{split_list_case}
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1416
\[
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1417
\begin{array}{l}
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1418
P(\mathtt{case}~e~\mathtt{of}~\texttt{[] =>}~a ~\texttt{|}~
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1419
               x\texttt{\#}xs~\texttt{=>}~f~x~xs) ~= \\
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1420
((e = \texttt{[]} \to P(a)) \land
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1421
 (\forall x~ xs. e = x\texttt{\#}xs \to P(f~x~xs)))
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1422
\end{array}
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1423
\]
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1424
which can be fed to \ttindex{addsplits} just like
4834
dd89afb55272 delsplits, Addsplits, Delsplits.
nipkow
parents: 4803
diff changeset
  1425
\texttt{split_if} (see~\S\ref{subsec:HOL:case:splitting}).
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1426
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1427
\texttt{List} provides a basic library of list processing functions defined by
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1428
primitive recursion (see~\S\ref{sec:HOL:primrec}).  The recursion equations
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1429
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
  1430
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1431
\index{list@{\textit{list}} type|)}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1432
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1433
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1434
\subsection{Introducing new types} \label{sec:typedef}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1435
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1436
The \HOL-methodology dictates that all extensions to a theory should
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1437
be \textbf{definitional}.  The type definition mechanism that
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1438
meets this criterion is \ttindex{typedef}.  Note that \emph{type synonyms},
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1439
which are inherited from {\Pure} and described elsewhere, are just
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1440
syntactic abbreviations that have no logical meaning.
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1441
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1442
\begin{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1443
  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
  1444
  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
  1445
\end{warn}
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1446
A \bfindex{type definition} identifies the new type with a subset of
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1447
an existing type.  More precisely, the new type is defined by
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1448
exhibiting an existing type~$\tau$, a set~$A::\tau\,set$, and a
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1449
theorem of the form $x:A$.  Thus~$A$ is a non-empty subset of~$\tau$,
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1450
and the new type denotes this subset.  New functions are defined that
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1451
establish an isomorphism between the new type and the subset.  If
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1452
type~$\tau$ involves type variables $\alpha@1$, \ldots, $\alpha@n$,
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1453
then the type definition creates a type constructor
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1454
$(\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
  1455
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1456
\begin{figure}[htbp]
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1457
\begin{rail}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1458
typedef  : 'typedef' ( () | '(' name ')') type '=' set witness;
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1459
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1460
type    : typevarlist name ( () | '(' infix ')' );
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1461
set     : string;
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1462
witness : () | '(' id ')';
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1463
\end{rail}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1464
\caption{Syntax of type definitions}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1465
\label{fig:HOL:typedef}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1466
\end{figure}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1467
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1468
The syntax for type definitions is shown in Fig.~\ref{fig:HOL:typedef}.  For
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1469
the definition of `typevarlist' and `infix' see
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1470
\iflabelundefined{chap:classical}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1471
{the appendix of the {\em Reference Manual\/}}%
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1472
{Appendix~\ref{app:TheorySyntax}}.  The remaining nonterminals have the
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1473
following meaning:
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1474
\begin{description}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1475
\item[\it type:] the new type constructor $(\alpha@1,\dots,\alpha@n)ty$ with
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1476
  optional infix annotation.
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1477
\item[\it name:] an alphanumeric name $T$ for the type constructor
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1478
  $ty$, in case $ty$ is a symbolic name.  Defaults to $ty$.
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1479
\item[\it set:] the representing subset $A$.
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1480
\item[\it witness:] name of a theorem of the form $a:A$ proving
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1481
  non-emptiness.  It can be omitted in case Isabelle manages to prove
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1482
  non-emptiness automatically.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1483
\end{description}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1484
If all context conditions are met (no duplicate type variables in
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1485
`typevarlist', no extra type variables in `set', and no free term variables
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1486
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
  1487
\begin{itemize}
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1488
\item a type $ty :: (term,\dots,term)term$
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1489
\item constants
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1490
\begin{eqnarray*}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1491
T &::& \tau\;set \\
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1492
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
  1493
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
  1494
\end{eqnarray*}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1495
\item a definition and three axioms
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1496
\[
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1497
\begin{array}{ll}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1498
T{\tt_def} & T \equiv A \\
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1499
{\tt Rep_}T & Rep_T\,x \in T \\
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1500
{\tt Rep_}T{\tt_inverse} & Abs_T\,(Rep_T\,x) = x \\
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1501
{\tt Abs_}T{\tt_inverse} & y \in T \Imp Rep_T\,(Abs_T\,y) = y
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1502
\end{array}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1503
\]
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1504
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
  1505
and its inverse $Abs_T$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1506
\end{itemize}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1507
Below are two simple examples of \HOL\ type definitions.  Non-emptiness
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1508
is proved automatically here.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1509
\begin{ttbox}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1510
typedef unit = "{\ttlbrace}True{\ttrbrace}"
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1511
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1512
typedef (prod)
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1513
  ('a, 'b) "*"    (infixr 20)
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1514
      = "{\ttlbrace}f . EX (a::'a) (b::'b). f = (\%x y. x = a & y = b){\ttrbrace}"
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1515
\end{ttbox}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1516
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1517
Type definitions permit the introduction of abstract data types in a safe
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1518
way, namely by providing models based on already existing types.  Given some
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1519
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
  1520
\begin{enumerate}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1521
\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
  1522
  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
  1523
\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
  1524
\end{enumerate}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1525
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
  1526
abstract properties $P$.
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1527
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1528
\begin{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1529
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
  1530
declaring the type and its operations and by stating the desired axioms, you
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1531
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
  1532
\par
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1533
\begin{ttbox}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1534
arities \(ty\) :: (term,\thinspace\(\dots\),{\thinspace}term){\thinspace}term
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1535
\end{ttbox}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1536
in your theory file to tell Isabelle that $ty$ is in class \texttt{term}, the
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1537
class of all \HOL\ types.
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1538
\end{warn}
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1539
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1540
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1541
\section{Records}
5735
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1542
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1543
At a first approximation, records are just a minor generalisation of tuples,
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1544
where components may be addressed by labels instead of just position (think of
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1545
{\ML}, for example).  The version of records offered by Isabelle/HOL is
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1546
slightly more advanced, though, supporting \emph{extensible record schemes}.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1547
This admits operations that are polymorphic with respect to record extension,
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1548
yielding ``object-oriented'' effects like (single) inheritance.  See also
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1549
\cite{Naraschewski-Wenzel:1998:TPHOL} for more details on object-oriented
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1550
verification and record subtyping in HOL.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1551
5735
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1552
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1553
\subsection{Basics}
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1554
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1555
Isabelle/HOL supports fixed and schematic records both at the level of terms
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1556
and types.  The concrete syntax is as follows:
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1557
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1558
\begin{center}
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1559
\begin{tabular}{l|l|l}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1560
  & record terms & record types \\ \hline
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1561
  fixed & $\record{x = a\fs y = b}$ & $\record{x \ty A\fs y \ty B}$ \\
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1562
  schematic & $\record{x = a\fs y = b\fs \more = m}$ &
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1563
    $\record{x \ty A\fs y \ty B\fs \more \ty M}$ \\
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1564
\end{tabular}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1565
\end{center}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1566
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1567
\noindent The \textsc{ascii} representation of $\record{x = a}$ is \texttt{(| x = a |)}.
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1568
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1569
A fixed record $\record{x = a\fs y = b}$ has field $x$ of value $a$ and field
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1570
$y$ of value $b$.  The corresponding type is $\record{x \ty A\fs y \ty B}$,
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1571
assuming that $a \ty A$ and $b \ty B$.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1572
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1573
A record scheme like $\record{x = a\fs y = b\fs \more = m}$ contains fields
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1574
$x$ and $y$ as before, but also possibly further fields as indicated by the
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1575
``$\more$'' notation (which is actually part of the syntax).  The improper
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1576
field ``$\more$'' of a record scheme is called the \emph{more part}.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1577
Logically it is just a free variable, which is occasionally referred to as
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1578
\emph{row variable} in the literature.  The more part of a record scheme may
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1579
be instantiated by zero or more further components.  For example, above scheme
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1580
might get instantiated to $\record{x = a\fs y = b\fs z = c\fs \more = m'}$,
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1581
where $m'$ refers to a different more part.  Fixed records are special
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1582
instances of record schemes, where ``$\more$'' is properly terminated by the
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1583
$() :: unit$ element.  Actually, $\record{x = a\fs y = b}$ is just an
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1584
abbreviation for $\record{x = a\fs y = b\fs \more = ()}$.
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1585
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1586
\medskip
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1587
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1588
There are two key features that make extensible records in a simply typed
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1589
language like HOL feasible:
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1590
\begin{enumerate}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1591
\item the more part is internalised, as a free term or type variable,
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1592
\item field names are externalised, they cannot be accessed within the logic
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1593
  as first-class values.
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1594
\end{enumerate}
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1595
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1596
\medskip
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1597
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1598
In Isabelle/HOL record types have to be defined explicitly, fixing their field
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1599
names and types, and their (optional) parent record (see
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1600
\S\ref{sec:HOL:record-def}).  Afterwards, records may be formed using above
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1601
syntax, while obeying the canonical order of fields as given by their
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1602
declaration.  The record package also provides several operations like
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1603
selectors and updates (see \S\ref{sec:HOL:record-ops}), together with
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1604
characteristic properties (see \S\ref{sec:HOL:record-thms}).
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1605
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1606
There is an example theory demonstrating most basic aspects of extensible
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1607
records (see theory \texttt{HOL/ex/Points} in the Isabelle sources).
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1608
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1609
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1610
\subsection{Defining records}\label{sec:HOL:record-def}
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1611
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1612
The theory syntax for record type definitions is shown in
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1613
Fig.~\ref{fig:HOL:record}.  For the definition of `typevarlist' and `type' see
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1614
\iflabelundefined{chap:classical}
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1615
{the appendix of the {\em Reference Manual\/}}%
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1616
{Appendix~\ref{app:TheorySyntax}}.
5735
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1617
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1618
\begin{figure}[htbp]
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1619
\begin{rail}
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1620
record  : 'record' typevarlist name '=' parent (field +);
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1621
5735
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1622
parent  : ( () | type '+');
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1623
field   : name '::' type;
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1624
\end{rail}
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1625
\caption{Syntax of record type definitions}
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1626
\label{fig:HOL:record}
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1627
\end{figure}
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1628
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1629
A general \ttindex{record} specification is of the following form:
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1630
\[
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1631
\mathtt{record}~(\alpha@1, \dots, \alpha@n) \, t ~=~
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1632
  (\tau@1, \dots, \tau@m) \, s ~+~ c@1 :: \sigma@1 ~ \dots ~ c@l :: \sigma@l
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1633
\]
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1634
where $\vec\alpha@n$ are distinct type variables, and $\vec\tau@m$,
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1635
$\vec\sigma@l$ are types containing at most variables from $\vec\alpha@n$.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1636
Type constructor $t$ has to be new, while $s$ has to specify an existing
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1637
record type.  Furthermore, the $\vec c@l$ have to be distinct field names.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1638
There has to be at least one field.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1639
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1640
In principle, field names may never be shared with other records.  This is no
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1641
actual restriction in practice, since $\vec c@l$ are internally declared
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1642
within a separate name space qualified by the name $t$ of the record.
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1643
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1644
\medskip
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1645
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1646
Above definition introduces a new record type $(\vec\alpha@n) \, t$ by
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1647
extending an existing one $(\vec\tau@m) \, s$ by new fields $\vec c@l \ty
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1648
\vec\sigma@l$.  The parent record specification is optional, by omitting it
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1649
$t$ becomes a \emph{root record}.  The hierarchy of all records declared
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1650
within a theory forms a forest structure, i.e.\ a set of trees, where any of
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1651
these is rooted by some root record.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1652
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1653
For convenience, $(\vec\alpha@n) \, t$ is made a type abbreviation for the
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1654
fixed record type $\record{\vec c@l \ty \vec\sigma@l}$, and $(\vec\alpha@n,
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1655
\zeta) \, t_scheme$ is made an abbreviation for $\record{\vec c@l \ty
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1656
  \vec\sigma@l\fs \more \ty \zeta}$.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1657
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1658
\medskip
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1659
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1660
The following simple example defines a root record type $point$ with fields $x
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1661
\ty nat$ and $y \ty nat$, and record type $cpoint$ by extending $point$ with
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1662
an additional $colour$ component.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1663
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1664
\begin{ttbox}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1665
  record point =
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1666
    x :: nat
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1667
    y :: nat
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1668
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1669
  record cpoint = point +
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1670
    colour :: string
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1671
\end{ttbox}
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1672
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1673
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1674
\subsection{Record operations}\label{sec:HOL:record-ops}
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1675
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1676
Any record definition of the form presented above produces certain standard
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1677
operations.  Selectors and updates are provided for any field, including the
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1678
improper one ``$more$''.  There are also cumulative record constructor
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1679
functions.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1680
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1681
To simplify the presentation below, we first assume that $(\vec\alpha@n) \, t$
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1682
is a root record with fields $\vec c@l \ty \vec\sigma@l$.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1683
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1684
\medskip
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1685
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1686
\textbf{Selectors} and \textbf{updates} are available for any field (including
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1687
``$more$'') as follows:
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1688
\begin{matharray}{lll}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1689
  c@i & \ty & \record{\vec c@l \ty \vec \sigma@l, \more \ty \zeta} \To \sigma@i \\
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1690
  c@i_update & \ty & \sigma@i \To \record{\vec c@l \ty \vec \sigma@l, \more \ty \zeta} \To
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1691
    \record{\vec c@l \ty \vec \sigma@l, \more \ty \zeta}
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1692
\end{matharray}
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1693
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1694
There is some special syntax for updates: $r \, \record{x \asn a}$ abbreviates
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1695
term $x_update \, a \, r$.  Repeated updates are also supported: $r \,
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1696
\record{x \asn a} \, \record{y \asn b} \, \record{z \asn c}$ may be written as
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1697
$r \, \record{x \asn a\fs y \asn b\fs z \asn c}$.  Note that because of
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1698
postfix notation the order of fields shown here is reverse than in the actual
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1699
term.  This might lead to confusion in conjunction with proof tools like
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1700
ordered rewriting.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1701
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1702
Since repeated updates are just function applications, fields may be freely
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1703
permuted in $\record{x \asn a\fs y \asn b\fs z \asn c}$, as far as the logic
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1704
is concerned.  Thus commutativity of updates can be proven within the logic
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1705
for any two fields, but not as a general theorem: fields are not first-class
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1706
values.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1707
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1708
\medskip
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1709
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1710
\textbf{Make} operations provide cumulative record constructor functions:
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1711
\begin{matharray}{lll}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1712
  make & \ty & \vec\sigma@l \To \record{\vec c@l \ty \vec \sigma@l} \\
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1713
  make_scheme & \ty & \vec\sigma@l \To
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1714
    \zeta \To \record{\vec c@l \ty \vec \sigma@l, \more \ty \zeta} \\
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1715
\end{matharray}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1716
\noindent
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1717
These functions are curried.  The corresponding definitions in terms of actual
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1718
record terms are part of the standard simpset.  Thus $point\dtt make\,a\,b$
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1719
rewrites to $\record{x = a\fs y = b}$.
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1720
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1721
\medskip
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1722
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1723
Any of above selector, update and make operations are declared within a local
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1724
name space prefixed by the name $t$ of the record.  In case that different
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1725
records share base names of fields, one has to qualify names explicitly (e.g.\ 
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1726
$t\dtt c@i_update$).  This is recommended especially for operations like
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1727
$make$ or $update_more$ that always have the same base name.  Just use $t\dtt
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1728
make$ etc.\ to avoid confusion.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1729
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1730
\bigskip
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1731
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1732
We reconsider the case of non-root records, which are derived of some parent
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1733
record.  In general, the latter may depend on another parent as well,
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1734
resulting in a list of \emph{ancestor records}.  Appending the lists of fields
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1735
of all ancestors results in a certain field prefix.  The record package
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1736
automatically takes care of this by lifting operations over this context of
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1737
ancestor fields.  Assuming that $(\vec\alpha@n) \, t$ has ancestor fields
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1738
$\vec d@k \ty \vec\rho@k$, selectors will get the following types:
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1739
\begin{matharray}{lll}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1740
  c@i & \ty & \record{\vec d@k \ty \vec\rho@k, \vec c@l \ty \vec \sigma@l, \more \ty \zeta}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1741
    \To \sigma@i
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1742
\end{matharray}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1743
\noindent
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1744
Update and make operations are analogous.
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1745
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1746
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1747
\subsection{Proof tools}\label{sec:HOL:record-thms}
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1748
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1749
The record package provides the following proof rules for any record type $t$.
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1750
\begin{enumerate}
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1751
  
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1752
\item Standard conversions (selectors or updates applied to record constructor
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1753
  terms, make function definitions) are part of the standard simpset (via
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1754
  \texttt{addsimps}).
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1755
  
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1756
\item Inject equations of a form analogous to $((x, y) = (x', y')) \equiv x=x'
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1757
  \conj y=y'$ are made part of the standard simpset and claset (via
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1758
  \texttt{addIffs}).
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1759
  
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1760
\item A tactic for record field splitting (\ttindex{record_split_tac}) is made
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1761
  part of the standard claset (via \texttt{addSWrapper}).  This tactic is
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1762
  based on rules analogous to $(\All x PROP~P~x) \equiv (\All{a~b} PROP~P(a,
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1763
  b))$ for any field.
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1764
\end{enumerate}
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  1765
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1766
The first two kinds of rules are stored within the theory as $t\dtt simps$ and
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1767
$t\dtt iffs$, respectively.  In some situations it might be appropriate to
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1768
expand the definitions of updates: $t\dtt updates$.  Following a new trend in
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1769
Isabelle system architecture, these names are \emph{not} bound at the {\ML}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1770
level, though.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1771
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1772
\medskip
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1773
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1774
The example theory \texttt{HOL/ex/Points} demonstrates typical proofs
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1775
concerning records.  The basic idea is to make \ttindex{record_split_tac}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1776
expand quantified record variables and then simplify by the conversion rules.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1777
By using a combination of the simplifier and classical prover together with
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1778
the default simpset and claset, record problems should be solved with a single
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1779
stroke of \texttt{Auto_tac} or \texttt{Force_tac}.
5735
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1780
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  1781
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1782
\section{Datatype definitions}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  1783
\label{sec:HOL:datatype}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1784
\index{*datatype|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1785
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1786
Inductive datatypes, similar to those of \ML, frequently appear in 
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1787
applications of Isabelle/HOL.  In principle, such types could be defined by
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1788
hand via \texttt{typedef} (see \S\ref{sec:typedef}), but this would be far too
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1789
tedious.  The \ttindex{datatype} definition package of \HOL\ automates such
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1790
chores.  It generates an appropriate \texttt{typedef} based on a least
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1791
fixed-point construction, and proves freeness theorems and induction rules, as
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1792
well as theorems for recursion and case combinators.  The user just has to
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1793
give a simple specification of new inductive types using a notation similar to
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1794
{\ML} or Haskell.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1795
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1796
The current datatype package can handle both mutual and indirect recursion.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1797
It also offers to represent existing types as datatypes giving the advantage
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1798
of a more uniform view on standard theories.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1799
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1800
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1801
\subsection{Basics}
3959
033633d9a032 Documented `addsplits'
nipkow
parents: 3881
diff changeset
  1802
\label{subsec:datatype:basics}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1803
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1804
A general \texttt{datatype} definition is of the following form:
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1805
\[
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1806
\begin{array}{llcl}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1807
\mathtt{datatype} & (\alpha@1,\ldots,\alpha@h)t@1 & = &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1808
  C^1@1~\tau^1@{1,1}~\ldots~\tau^1@{1,m^1@1} ~\mid~ \ldots ~\mid~
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1809
    C^1@{k@1}~\tau^1@{k@1,1}~\ldots~\tau^1@{k@1,m^1@{k@1}} \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1810
 & & \vdots \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1811
\mathtt{and} & (\alpha@1,\ldots,\alpha@h)t@n & = &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1812
  C^n@1~\tau^n@{1,1}~\ldots~\tau^n@{1,m^n@1} ~\mid~ \ldots ~\mid~
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1813
    C^n@{k@n}~\tau^n@{k@n,1}~\ldots~\tau^n@{k@n,m^n@{k@n}}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1814
\end{array}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1815
\]
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1816
where $\alpha@i$ are type variables, $C^j@i$ are distinct constructor
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1817
names and $\tau^j@{i,i'}$ are {\em admissible} types containing at
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1818
most the type variables $\alpha@1, \ldots, \alpha@h$. A type $\tau$
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1819
occurring in a \texttt{datatype} definition is {\em admissible} iff
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1820
\begin{itemize}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1821
\item $\tau$ is non-recursive, i.e.\ $\tau$ does not contain any of the
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1822
newly defined type constructors $t@1,\ldots,t@n$, or
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1823
\item $\tau = (\alpha@1,\ldots,\alpha@h)t@{j'}$ where $1 \leq j' \leq n$, or
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1824
\item $\tau = (\tau'@1,\ldots,\tau'@{h'})t'$, where $t'$ is
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1825
the type constructor of an already existing datatype and $\tau'@1,\ldots,\tau'@{h'}$
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1826
are admissible types.
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1827
\end{itemize}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1828
If some $(\alpha@1,\ldots,\alpha@h)t@{j'}$ occurs in a type $\tau^j@{i,i'}$
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1829
of the form
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1830
\[
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1831
(\ldots,\ldots ~ (\alpha@1,\ldots,\alpha@h)t@{j'} ~ \ldots,\ldots)t'
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1832
\]
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1833
this is called a {\em nested} (or \emph{indirect}) occurrence. A very simple
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1834
example of a datatype is the type \texttt{list}, which can be defined by
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1835
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1836
datatype 'a list = Nil
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1837
                 | Cons 'a ('a list)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1838
\end{ttbox}
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1839
Arithmetic expressions \texttt{aexp} and boolean expressions \texttt{bexp} can be modelled
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1840
by the mutually recursive datatype definition
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1841
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1842
datatype 'a aexp = If_then_else ('a bexp) ('a aexp) ('a aexp)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1843
                 | Sum ('a aexp) ('a aexp)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1844
                 | Diff ('a aexp) ('a aexp)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1845
                 | Var 'a
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1846
                 | Num nat
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1847
and      'a bexp = Less ('a aexp) ('a aexp)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1848
                 | And ('a bexp) ('a bexp)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1849
                 | Or ('a bexp) ('a bexp)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1850
\end{ttbox}
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1851
The datatype \texttt{term}, which is defined by
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1852
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1853
datatype ('a, 'b) term = Var 'a
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1854
                       | App 'b ((('a, 'b) term) list)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1855
\end{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1856
is an example for a datatype with nested recursion.
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1857
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1858
\medskip
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1859
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1860
Types in HOL must be non-empty. Each of the new datatypes
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1861
$(\alpha@1,\ldots,\alpha@h)t@j$ with $1 \le j \le n$ is non-empty iff it has a
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1862
constructor $C^j@i$ with the following property: for all argument types
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1863
$\tau^j@{i,i'}$ of the form $(\alpha@1,\ldots,\alpha@h)t@{j'}$ the datatype
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1864
$(\alpha@1,\ldots,\alpha@h)t@{j'}$ is non-empty.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1865
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1866
If there are no nested occurrences of the newly defined datatypes, obviously
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1867
at least one of the newly defined datatypes $(\alpha@1,\ldots,\alpha@h)t@j$
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1868
must have a constructor $C^j@i$ without recursive arguments, a \emph{base
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1869
  case}, to ensure that the new types are non-empty. If there are nested
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1870
occurrences, a datatype can even be non-empty without having a base case
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1871
itself. Since \texttt{list} is a non-empty datatype, \texttt{datatype t = C (t
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1872
  list)} is non-empty as well.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1873
6119
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  1874
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  1875
\subsubsection{Freeness of the constructors}
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  1876
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1877
The datatype constructors are automatically defined as functions of their
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1878
respective type:
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1879
\[ C^j@i :: [\tau^j@{i,1},\dots,\tau^j@{i,m^j@i}] \To (\alpha@1,\dots,\alpha@h)t@j \]
6119
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  1880
These functions have certain {\em freeness} properties.  They construct
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  1881
distinct values:
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1882
\[
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1883
C^j@i~x@1~\dots~x@{m^j@i} \neq C^j@{i'}~y@1~\dots~y@{m^j@{i'}} \qquad
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1884
\mbox{for all}~ i \neq i'.
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1885
\]
6119
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  1886
The constructor functions are injective:
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1887
\[
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1888
(C^j@i~x@1~\dots~x@{m^j@i} = C^j@i~y@1~\dots~y@{m^j@i}) =
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1889
(x@1 = y@1 \land \dots \land x@{m^j@i} = y@{m^j@i})
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  1890
\]
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1891
Because the number of distinctness inequalities is quadratic in the number of
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1892
constructors, a different representation is used if there are $7$ or more of
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1893
them.  In that case every constructor term is mapped to a natural number:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1894
\[
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1895
t@j_ord \, (C^j@i \, x@1 \, \dots \, x@{m^j@i}) = i - 1
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1896
\]
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1897
Then distinctness of constructor terms is expressed by:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1898
\[
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1899
t@j_ord \, x \neq t@j_ord \, y \Imp x \neq y.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1900
\]
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  1901
6119
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  1902
\subsubsection{Structural induction}
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  1903
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  1904
The datatype package also provides structural induction rules.  For
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1905
datatypes without nested recursion, this is of the following form:
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1906
\[
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1907
\infer{P@1~x@1 \wedge \dots \wedge P@n~x@n}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1908
  {\begin{array}{lcl}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1909
     \Forall x@1 \dots x@{m^1@1}.
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1910
       \List{P@{s^1@{1,1}}~x@{r^1@{1,1}}; \dots;
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1911
         P@{s^1@{1,l^1@1}}~x@{r^1@{1,l^1@1}}} & \Imp &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1912
           P@1~\left(C^1@1~x@1~\dots~x@{m^1@1}\right) \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1913
     & \vdots \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1914
     \Forall x@1 \dots x@{m^1@{k@1}}.
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1915
       \List{P@{s^1@{k@1,1}}~x@{r^1@{k@1,1}}; \dots;
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1916
         P@{s^1@{k@1,l^1@{k@1}}}~x@{r^1@{k@1,l^1@{k@1}}}} & \Imp &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1917
           P@1~\left(C^1@{k@1}~x@1~\ldots~x@{m^1@{k@1}}\right) \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1918
     & \vdots \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1919
     \Forall x@1 \dots x@{m^n@1}.
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1920
       \List{P@{s^n@{1,1}}~x@{r^n@{1,1}}; \dots;
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1921
         P@{s^n@{1,l^n@1}}~x@{r^n@{1,l^n@1}}} & \Imp &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1922
           P@n~\left(C^n@1~x@1~\ldots~x@{m^n@1}\right) \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1923
     & \vdots \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1924
     \Forall x@1 \dots x@{m^n@{k@n}}.
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1925
       \List{P@{s^n@{k@n,1}}~x@{r^n@{k@n,1}}; \dots
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1926
         P@{s^n@{k@n,l^n@{k@n}}}~x@{r^n@{k@n,l^n@{k@n}}}} & \Imp &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1927
           P@n~\left(C^n@{k@n}~x@1~\ldots~x@{m^n@{k@n}}\right)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1928
   \end{array}}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1929
\]
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1930
where
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1931
\[
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1932
\begin{array}{rcl}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1933
Rec^j@i & := &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1934
   \left\{\left(r^j@{i,1},s^j@{i,1}\right),\ldots,
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1935
     \left(r^j@{i,l^j@i},s^j@{i,l^j@i}\right)\right\} = \\[2ex]
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1936
&& \left\{(i',i'')~\left|~
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1937
     1\leq i' \leq m^j@i \wedge 1 \leq i'' \leq n \wedge
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1938
       \tau^j@{i,i'} = (\alpha@1,\ldots,\alpha@h)t@{i''}\right.\right\}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1939
\end{array}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1940
\]
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1941
i.e.\ the properties $P@j$ can be assumed for all recursive arguments.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1942
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1943
For datatypes with nested recursion, such as the \texttt{term} example from
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1944
above, things are a bit more complicated.  Conceptually, Isabelle/HOL unfolds
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1945
a definition like
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1946
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1947
datatype ('a, 'b) term = Var 'a
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1948
                       | App 'b ((('a, 'b) term) list)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1949
\end{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1950
to an equivalent definition without nesting:
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1951
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1952
datatype ('a, 'b) term      = Var
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1953
                            | App 'b (('a, 'b) term_list)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1954
and      ('a, 'b) term_list = Nil'
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1955
                            | Cons' (('a,'b) term) (('a,'b) term_list)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1956
\end{ttbox}
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1957
Note however, that the type \texttt{('a,'b) term_list} and the constructors {\tt
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1958
  Nil'} and \texttt{Cons'} are not really introduced.  One can directly work with
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1959
the original (isomorphic) type \texttt{(('a, 'b) term) list} and its existing
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1960
constructors \texttt{Nil} and \texttt{Cons}. Thus, the structural induction rule for
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1961
\texttt{term} gets the form
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1962
\[
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1963
\infer{P@1~x@1 \wedge P@2~x@2}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1964
  {\begin{array}{l}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1965
     \Forall x.~P@1~(\mathtt{Var}~x) \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1966
     \Forall x@1~x@2.~P@2~x@2 \Imp P@1~(\mathtt{App}~x@1~x@2) \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1967
     P@2~\mathtt{Nil} \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1968
     \Forall x@1~x@2. \List{P@1~x@1; P@2~x@2} \Imp P@2~(\mathtt{Cons}~x@1~x@2)
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1969
   \end{array}}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1970
\]
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1971
Note that there are two predicates $P@1$ and $P@2$, one for the type \texttt{('a,'b) term}
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1972
and one for the type \texttt{(('a, 'b) term) list}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1973
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1974
\medskip In principle, inductive types are already fully determined by
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  1975
freeness and structural induction.  For convenience in applications,
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1976
the following derived constructions are automatically provided for any
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1977
datatype.
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  1978
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  1979
\subsubsection{The \sdx{case} construct}
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  1980
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  1981
The type comes with an \ML-like \texttt{case}-construct:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1982
\[
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1983
\begin{array}{rrcl}
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1984
\mbox{\tt case}~e~\mbox{\tt of} & C^j@1~x@{1,1}~\dots~x@{1,m^j@1} & \To & e@1 \\
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1985
                           \vdots \\
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1986
                           \mid & C^j@{k@j}~x@{k@j,1}~\dots~x@{k@j,m^j@{k@j}} & \To & e@{k@j}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1987
\end{array}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1988
\]
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1989
where the $x@{i,j}$ are either identifiers or nested tuple patterns as in
2994
3bb5d1b9c3aa Tuple patterns are allowed now in `case'
nipkow
parents: 2975
diff changeset
  1990
\S\ref{subsec:prod-sum}.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1991
\begin{warn}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1992
  All constructors must be present, their order is fixed, and nested patterns
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1993
  are not supported (with the exception of tuples).  Violating this
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  1994
  restriction results in strange error messages.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  1995
\end{warn}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  1996
4067
207a7811faa9 Documented `split_t_case' thm genearted by datatype.
nipkow
parents: 3962
diff changeset
  1997
To perform case distinction on a goal containing a \texttt{case}-construct,
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  1998
the theorem $t@j.$\texttt{split} is provided:
4067
207a7811faa9 Documented `split_t_case' thm genearted by datatype.
nipkow
parents: 3962
diff changeset
  1999
\[
207a7811faa9 Documented `split_t_case' thm genearted by datatype.
nipkow
parents: 3962
diff changeset
  2000
\begin{array}{@{}rcl@{}}
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2001
P(t@j_\mathtt{case}~f@1~\dots~f@{k@j}~e) &\!\!\!=&
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2002
\!\!\! ((\forall x@1 \dots x@{m^j@1}. e = C^j@1~x@1\dots x@{m^j@1} \to
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2003
                             P(f@1~x@1\dots x@{m^j@1})) \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2004
&&\!\!\! ~\land~ \dots ~\land \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2005
&&~\!\!\! (\forall x@1 \dots x@{m^j@{k@j}}. e = C^j@{k@j}~x@1\dots x@{m^j@{k@j}} \to
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2006
                             P(f@{k@j}~x@1\dots x@{m^j@{k@j}})))
4067
207a7811faa9 Documented `split_t_case' thm genearted by datatype.
nipkow
parents: 3962
diff changeset
  2007
\end{array}
207a7811faa9 Documented `split_t_case' thm genearted by datatype.
nipkow
parents: 3962
diff changeset
  2008
\]
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2009
where $t@j$\texttt{_case} is the internal name of the \texttt{case}-construct.
4067
207a7811faa9 Documented `split_t_case' thm genearted by datatype.
nipkow
parents: 3962
diff changeset
  2010
This theorem can be added to a simpset via \ttindex{addsplits}
207a7811faa9 Documented `split_t_case' thm genearted by datatype.
nipkow
parents: 3962
diff changeset
  2011
(see~\S\ref{subsec:HOL:case:splitting}).
207a7811faa9 Documented `split_t_case' thm genearted by datatype.
nipkow
parents: 3962
diff changeset
  2012
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2013
\subsubsection{The function \cdx{size}}\label{sec:HOL:size}
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2014
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2015
Theory \texttt{Arith} declares a generic function \texttt{size} of type
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2016
$\alpha\To nat$.  Each datatype defines a particular instance of \texttt{size}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2017
by overloading according to the following scheme:
6072
5583261db33d removal of FOL, ZF to a separate manual
paulson
parents: 5797
diff changeset
  2018
%%% FIXME: This formula is too big and is completely unreadable
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2019
\[
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2020
size(C^j@i~x@1~\dots~x@{m^j@i}) = \!
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2021
\left\{
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2022
\begin{array}{ll}
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2023
0 & \!\mbox{if $Rec^j@i = \emptyset$} \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2024
\!\!\begin{array}{l}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2025
size~x@{r^j@{i,1}} + \cdots \\
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2026
\cdots + size~x@{r^j@{i,l^j@i}} + 1
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2027
\end{array} &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2028
 \!\mbox{if $Rec^j@i = \left\{\left(r^j@{i,1},s^j@{i,1}\right),\ldots,
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2029
  \left(r^j@{i,l^j@i},s^j@{i,l^j@i}\right)\right\}$}
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2030
\end{array}
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2031
\right.
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2032
\]
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2033
where $Rec^j@i$ is defined above.  Viewing datatypes as generalised trees, the
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2034
size of a leaf is 0 and the size of a node is the sum of the sizes of its
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2035
subtrees ${}+1$.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2036
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2037
\subsection{Defining datatypes}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2038
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2039
The theory syntax for datatype definitions is shown in
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2040
Fig.~\ref{datatype-grammar}.  In order to be well-formed, a datatype
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2041
definition has to obey the rules stated in the previous section.  As a result
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2042
the theory is extended with the new types, the constructors, and the theorems
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2043
listed in the previous section.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2044
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2045
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2046
\begin{rail}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2047
datatype : 'datatype' typedecls;
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2048
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2049
typedecls: ( newtype '=' (cons + '|') ) + 'and'
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2050
         ;
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2051
newtype  : typevarlist id ( () | '(' infix ')' )
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2052
         ;
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2053
cons     : name (argtype *) ( () | ( '(' mixfix ')' ) )
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2054
         ;
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2055
argtype  : id | tid | ('(' typevarlist id ')')
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2056
         ;
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2057
\end{rail}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2058
\caption{Syntax of datatype declarations}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2059
\label{datatype-grammar}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2060
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2061
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2062
Most of the theorems about datatypes become part of the default simpset and
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2063
you never need to see them again because the simplifier applies them
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2064
automatically.  Only induction or exhaustion are usually invoked by hand.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2065
\begin{ttdescription}
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  2066
\item[\ttindexbold{induct_tac} {\tt"}$x${\tt"} $i$]
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  2067
 applies structural induction on variable $x$ to subgoal $i$, provided the
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2068
 type of $x$ is a datatype.
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2069
\item[\ttindexbold{mutual_induct_tac}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2070
  {\tt["}$x@1${\tt",}$\ldots${\tt,"}$x@n${\tt"]} $i$] applies simultaneous
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2071
  structural induction on the variables $x@1,\ldots,x@n$ to subgoal $i$.  This
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2072
  is the canonical way to prove properties of mutually recursive datatypes
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2073
  such as \texttt{aexp} and \texttt{bexp}, or datatypes with nested recursion such as
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2074
  \texttt{term}.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2075
\end{ttdescription}
3287
078be5581967 Documented exhaust_tac.
nipkow
parents: 3181
diff changeset
  2076
In some cases, induction is overkill and a case distinction over all
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2077
constructors of the datatype suffices.
3287
078be5581967 Documented exhaust_tac.
nipkow
parents: 3181
diff changeset
  2078
\begin{ttdescription}
078be5581967 Documented exhaust_tac.
nipkow
parents: 3181
diff changeset
  2079
\item[\ttindexbold{exhaust_tac} {\tt"}$u${\tt"} $i$]
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2080
 performs an exhaustive case analysis for the term $u$ whose type
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2081
 must be a datatype.  If the datatype has $k@j$ constructors
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2082
 $C^j@1$, \dots $C^j@{k@j}$, subgoal $i$ is replaced by $k@j$ new subgoals which
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2083
 contain the additional assumption $u = C^j@{i'}~x@1~\dots~x@{m^j@{i'}}$ for
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2084
 $i'=1$, $\dots$,~$k@j$.
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2085
\end{ttdescription}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2086
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2087
Note that induction is only allowed on free variables that should not occur
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2088
among the premises of the subgoal.  Exhaustion applies to arbitrary terms.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2089
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2090
\bigskip
3287
078be5581967 Documented exhaust_tac.
nipkow
parents: 3181
diff changeset
  2091
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2092
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2093
For the technically minded, we exhibit some more details.  Processing the
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2094
theory file produces an \ML\ structure which, in addition to the usual
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2095
components, contains a structure named $t$ for each datatype $t$ defined in
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2096
the file.  Each structure $t$ contains the following elements:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2097
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2098
val distinct : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2099
val inject : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2100
val induct : thm
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2101
val exhaust : thm
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2102
val cases : thm list
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2103
val split : thm
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2104
val split_asm : thm
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2105
val recs : thm list
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2106
val size : thm list
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2107
val simps : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2108
\end{ttbox}
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2109
\texttt{distinct}, \texttt{inject}, \texttt{induct}, \texttt{size}
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2110
and \texttt{split} contain the theorems
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2111
described above.  For user convenience, \texttt{distinct} contains
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2112
inequalities in both directions.  The reduction rules of the {\tt
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2113
  case}-construct are in \texttt{cases}.  All theorems from {\tt
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2114
  distinct}, \texttt{inject} and \texttt{cases} are combined in \texttt{simps}.
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2115
In case of mutually recursive datatypes, \texttt{recs}, \texttt{size}, \texttt{induct}
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2116
and \texttt{simps} are contained in a separate structure named $t@1_\ldots_t@n$.
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2117
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2118
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2119
\subsection{Representing existing types as datatypes}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2120
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2121
For foundational reasons, some basic types such as \texttt{nat}, \texttt{*}, {\tt
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2122
  +}, \texttt{bool} and \texttt{unit} are not defined in a \texttt{datatype} section,
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2123
but by more primitive means using \texttt{typedef}. To be able to use the
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2124
tactics \texttt{induct_tac} and \texttt{exhaust_tac} and to define functions by
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2125
primitive recursion on these types, such types may be represented as actual
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2126
datatypes.  This is done by specifying an induction rule, as well as theorems
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2127
stating the distinctness and injectivity of constructors in a {\tt
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2128
  rep_datatype} section.  For type \texttt{nat} this works as follows:
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2129
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2130
rep_datatype nat
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2131
  distinct Suc_not_Zero, Zero_not_Suc
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2132
  inject   Suc_Suc_eq
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2133
  induct   nat_induct
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2134
\end{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2135
The datatype package automatically derives additional theorems for recursion
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2136
and case combinators from these rules.  Any of the basic HOL types mentioned
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2137
above are represented as datatypes.  Try an induction on \texttt{bool}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2138
today.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2139
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2140
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2141
\subsection{Examples}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2142
3180
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2143
\subsubsection{The datatype $\alpha~mylist$}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2144
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2145
We want to define a type $\alpha~mylist$. To do this we have to build a new
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2146
theory that contains the type definition.  We start from the theory
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2147
\texttt{Datatype} instead of \texttt{Main} in order to avoid clashes with the
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2148
\texttt{List} theory of Isabelle/HOL.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2149
\begin{ttbox}
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2150
MyList = Datatype +
3180
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2151
  datatype 'a mylist = Nil | Cons 'a ('a mylist)
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2152
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2153
\end{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2154
After loading the theory, we can prove $Cons~x~xs\neq xs$, for example.  To
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2155
ease the induction applied below, we state the goal with $x$ quantified at the
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2156
object-level.  This will be stripped later using \ttindex{qed_spec_mp}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2157
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2158
Goal "!x. Cons x xs ~= xs";
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2159
{\out Level 0}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2160
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2161
{\out  1. ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2162
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2163
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
  2164
\begin{ttbox}
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  2165
by (induct_tac "xs" 1);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2166
{\out Level 1}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2167
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2168
{\out  1. ! x. Cons x Nil ~= Nil}
3180
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2169
{\out  2. !!a mylist.}
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2170
{\out        ! x. Cons x mylist ~= mylist ==>}
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2171
{\out        ! x. Cons x (Cons a mylist) ~= Cons a mylist}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2172
\end{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2173
The first subgoal can be proved using the simplifier.  Isabelle/HOL has
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2174
already added the freeness properties of lists to the default simplification
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2175
set.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2176
\begin{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  2177
by (Simp_tac 1);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2178
{\out Level 2}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2179
{\out ! x. Cons x xs ~= xs}
3180
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2180
{\out  1. !!a mylist.}
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2181
{\out        ! x. Cons x mylist ~= mylist ==>}
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2182
{\out        ! x. Cons x (Cons a mylist) ~= Cons a mylist}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2183
\end{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  2184
Similarly, we prove the remaining goal.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2185
\begin{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  2186
by (Asm_simp_tac 1);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2187
{\out Level 3}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2188
{\out ! x. Cons x xs ~= xs}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2189
{\out No subgoals!}
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  2190
\ttbreak
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  2191
qed_spec_mp "not_Cons_self";
6119
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  2192
{\out val not_Cons_self = "Cons x xs ~= xs" : thm}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2193
\end{ttbox}
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  2194
Because both subgoals could have been proved by \texttt{Asm_simp_tac}
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  2195
we could have done that in one step:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2196
\begin{ttbox}
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  2197
by (ALLGOALS Asm_simp_tac);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2198
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2199
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2200
3180
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2201
\subsubsection{The datatype $\alpha~mylist$ with mixfix syntax}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2202
3181
wenzelm
parents: 3180
diff changeset
  2203
In this example we define the type $\alpha~mylist$ again but this time
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2204
we want to write \texttt{[]} for \texttt{Nil} and we want to use infix
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2205
notation \verb|#| for \texttt{Cons}.  To do this we simply add mixfix
3181
wenzelm
parents: 3180
diff changeset
  2206
annotations after the constructor declarations as follows:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2207
\begin{ttbox}
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2208
MyList = Datatype +
3180
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2209
  datatype 'a mylist =
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2210
    Nil ("[]")  |
3180
3fff6839c616 mylist instead of list in datatype ex;
wenzelm
parents: 3161
diff changeset
  2211
    Cons 'a ('a mylist)  (infixr "#" 70)
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2212
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2213
\end{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2214
Now the theorem in the previous example can be written \verb|x#xs ~= xs|.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2215
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2216
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2217
\subsubsection{A datatype for weekdays}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2218
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2219
This example shows a datatype that consists of 7 constructors:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2220
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2221
Days = Main +
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  2222
  datatype days = Mon | Tue | Wed | Thu | Fri | Sat | Sun
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2223
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2224
\end{ttbox}
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2225
Because there are more than 6 constructors, inequality is expressed via a function
3160
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  2226
\verb|days_ord|.  The theorem \verb|Mon ~= Tue| is not directly
08e364dfe518 minor tuning;
wenzelm
parents: 3152
diff changeset
  2227
contained among the distinctness theorems, but the simplifier can
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2228
prove it thanks to rewrite rules inherited from theory \texttt{Arith}:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2229
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2230
Goal "Mon ~= Tue";
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  2231
by (Simp_tac 1);
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  2232
\end{ttbox}
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  2233
You need not derive such inequalities explicitly: the simplifier will dispose
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  2234
of them automatically.
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2235
\index{*datatype|)}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2236
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2237
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2238
\section{Recursive function definitions}\label{sec:HOL:recursive}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2239
\index{recursive functions|see{recursion}}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2240
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2241
Isabelle/HOL provides two main mechanisms of defining recursive functions.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2242
\begin{enumerate}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2243
\item \textbf{Primitive recursion} is available only for datatypes, and it is
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2244
  somewhat restrictive.  Recursive calls are only allowed on the argument's
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2245
  immediate constituents.  On the other hand, it is the form of recursion most
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2246
  often wanted, and it is easy to use.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2247
  
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2248
\item \textbf{Well-founded recursion} requires that you supply a well-founded
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2249
  relation that governs the recursion.  Recursive calls are only allowed if
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2250
  they make the argument decrease under the relation.  Complicated recursion
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2251
  forms, such as nested recursion, can be dealt with.  Termination can even be
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2252
  proved at a later time, though having unsolved termination conditions around
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2253
  can make work difficult.%
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2254
  \footnote{This facility is based on Konrad Slind's TFL
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2255
    package~\cite{slind-tfl}.  Thanks are due to Konrad for implementing TFL
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2256
    and assisting with its installation.}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2257
\end{enumerate}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2258
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2259
Following good HOL tradition, these declarations do not assert arbitrary
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2260
axioms.  Instead, they define the function using a recursion operator.  Both
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2261
HOL and ZF derive the theory of well-founded recursion from first
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2262
principles~\cite{paulson-set-II}.  Primitive recursion over some datatype
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2263
relies on the recursion operator provided by the datatype package.  With
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2264
either form of function definition, Isabelle proves the desired recursion
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2265
equations as theorems.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2266
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2267
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2268
\subsection{Primitive recursive functions}
1422
bc628f4ef0cb New version of type sections and many small changes.
nipkow
parents: 1389
diff changeset
  2269
\label{sec:HOL:primrec}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2270
\index{recursion!primitive|(}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2271
\index{*primrec|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2272
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2273
Datatypes come with a uniform way of defining functions, {\bf primitive
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2274
  recursion}.  In principle, one could introduce primitive recursive functions
6119
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  2275
by asserting their reduction rules as new axioms, but this is not recommended:
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  2276
\begin{ttbox}\slshape
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2277
Append = Main +
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2278
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
  2279
rules 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2280
   app_Nil   "app [] ys = ys"
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  2281
   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
  2282
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2283
\end{ttbox}
6119
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  2284
Asserting axioms brings the danger of accidentally asserting nonsense, as
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2285
in \verb$app [] ys = us$.
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2286
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2287
The \ttindex{primrec} declaration is a safe means of defining primitive
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2288
recursive functions on datatypes:
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2289
\begin{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2290
Append = Main +
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2291
consts app :: ['a list, 'a list] => 'a list
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2292
primrec
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2293
   "app [] ys = ys"
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2294
   "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
  2295
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2296
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2297
Isabelle will now check that the two rules do indeed form a primitive
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2298
recursive definition.  For example
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2299
\begin{ttbox}
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2300
primrec
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2301
    "app [] ys = us"
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2302
\end{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2303
is rejected with an error message ``\texttt{Extra variables on rhs}''.
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2304
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2305
\bigskip
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2306
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2307
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
  2308
\begin{ttbox}
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2309
primrec
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2310
    {\it reduction rules}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2311
\end{ttbox}
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2312
where \textit{reduction rules} specify one or more equations of the form
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2313
\[ f \, x@1 \, \dots \, x@m \, (C \, y@1 \, \dots \, y@k) \, z@1 \,
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2314
\dots \, z@n = r \] such that $C$ is a constructor of the datatype, $r$
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2315
contains only the free variables on the left-hand side, and all recursive
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2316
calls in $r$ are of the form $f \, \dots \, y@i \, \dots$ for some $i$.  There
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2317
must be at most one reduction rule for each constructor.  The order is
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2318
immaterial.  For missing constructors, the function is defined to return a
6119
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  2319
default value.  
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  2320
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2321
If you would like to refer to some rule by name, then you must prefix
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2322
the rule with an identifier.  These identifiers, like those in the
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2323
\texttt{rules} section of a theory, will be visible at the \ML\ level.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2324
2495
82ec47e0a8d3 New discussion of implicit simpsets & clasets
paulson
parents: 1859
diff changeset
  2325
The primitive recursive function can have infix or mixfix syntax:
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2326
\begin{ttbox}\underscoreon
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2327
consts "@"  :: ['a list, 'a list] => 'a list  (infixr 60)
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2328
primrec
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2329
   "[] @ ys = ys"
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2330
   "(x#xs) @ ys = x#(xs @ ys)"
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2331
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2332
6119
7e3eb9b4df8e minor updates on inductive definitions and datatypes
paulson
parents: 6076
diff changeset
  2333
The reduction rules become part of the default simpset, which
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2334
leads to short proof scripts:
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2335
\begin{ttbox}\underscoreon
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2336
Goal "(xs @ ys) @ zs = xs @ (ys @ zs)";
3045
4ef28e05781b Added 'induct_tac'
nipkow
parents: 2994
diff changeset
  2337
by (induct\_tac "xs" 1);
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2338
by (ALLGOALS Asm\_simp\_tac);
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2339
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2340
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2341
\subsubsection{Example: Evaluation of expressions}
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2342
Using mutual primitive recursion, we can define evaluation functions \texttt{eval_aexp}
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2343
and \texttt{eval_bexp} for the datatypes of arithmetic and boolean expressions mentioned in
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2344
\S\ref{subsec:datatype:basics}:
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2345
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2346
consts
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2347
  eval_aexp :: "['a => nat, 'a aexp] => nat"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2348
  eval_bexp :: "['a => nat, 'a bexp] => bool"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2349
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2350
primrec
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2351
  "eval_aexp env (If_then_else b a1 a2) =
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2352
     (if eval_bexp env b then eval_aexp env a1 else eval_aexp env a2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2353
  "eval_aexp env (Sum a1 a2) = eval_aexp env a1 + eval_aexp env a2"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2354
  "eval_aexp env (Diff a1 a2) = eval_aexp env a1 - eval_aexp env a2"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2355
  "eval_aexp env (Var v) = env v"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2356
  "eval_aexp env (Num n) = n"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2357
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2358
  "eval_bexp env (Less a1 a2) = (eval_aexp env a1 < eval_aexp env a2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2359
  "eval_bexp env (And b1 b2) = (eval_bexp env b1 & eval_bexp env b2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2360
  "eval_bexp env (Or b1 b2) = (eval_bexp env b1 & eval_bexp env b2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2361
\end{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2362
Since the value of an expression depends on the value of its variables,
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2363
the functions \texttt{eval_aexp} and \texttt{eval_bexp} take an additional
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2364
parameter, an {\em environment} of type \texttt{'a => nat}, which maps
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2365
variables to their values.
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2366
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2367
Similarly, we may define substitution functions \texttt{subst_aexp}
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2368
and \texttt{subst_bexp} for expressions: The mapping \texttt{f} of type
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2369
\texttt{'a => 'a aexp} given as a parameter is lifted canonically
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2370
on the types {'a aexp} and {'a bexp}:
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2371
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2372
consts
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2373
  subst_aexp :: "['a => 'b aexp, 'a aexp] => 'b aexp"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2374
  subst_bexp :: "['a => 'b aexp, 'a bexp] => 'b bexp"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2375
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2376
primrec
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2377
  "subst_aexp f (If_then_else b a1 a2) =
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2378
     If_then_else (subst_bexp f b) (subst_aexp f a1) (subst_aexp f a2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2379
  "subst_aexp f (Sum a1 a2) = Sum (subst_aexp f a1) (subst_aexp f a2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2380
  "subst_aexp f (Diff a1 a2) = Diff (subst_aexp f a1) (subst_aexp f a2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2381
  "subst_aexp f (Var v) = f v"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2382
  "subst_aexp f (Num n) = Num n"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2383
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2384
  "subst_bexp f (Less a1 a2) = Less (subst_aexp f a1) (subst_aexp f a2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2385
  "subst_bexp f (And b1 b2) = And (subst_bexp f b1) (subst_bexp f b2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2386
  "subst_bexp f (Or b1 b2) = Or (subst_bexp f b1) (subst_bexp f b2)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2387
\end{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2388
In textbooks about semantics one often finds {\em substitution theorems},
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2389
which express the relationship between substitution and evaluation. For
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2390
\texttt{'a aexp} and \texttt{'a bexp}, we can prove such a theorem by mutual
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2391
induction, followed by simplification:
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2392
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2393
Goal
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2394
  "eval_aexp env (subst_aexp (Var(v := a')) a) =
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2395
     eval_aexp (env(v := eval_aexp env a')) a &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2396
   eval_bexp env (subst_bexp (Var(v := a')) b) =
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2397
     eval_bexp (env(v := eval_aexp env a')) b";
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2398
by (mutual_induct_tac ["a","b"] 1);
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2399
by (ALLGOALS Asm_full_simp_tac);
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2400
\end{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2401
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2402
\subsubsection{Example: A substitution function for terms}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2403
Functions on datatypes with nested recursion, such as the type
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2404
\texttt{term} mentioned in \S\ref{subsec:datatype:basics}, are
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2405
also defined by mutual primitive recursion. A substitution
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2406
function \texttt{subst_term} on type \texttt{term}, similar to the functions
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2407
\texttt{subst_aexp} and \texttt{subst_bexp} described above, can
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2408
be defined as follows:
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2409
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2410
consts
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2411
  subst_term :: "['a => ('a, 'b) term, ('a, 'b) term] => ('a, 'b) term"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2412
  subst_term_list ::
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2413
    "['a => ('a, 'b) term, ('a, 'b) term list] => ('a, 'b) term list"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2414
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2415
primrec
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2416
  "subst_term f (Var a) = f a"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2417
  "subst_term f (App b ts) = App b (subst_term_list f ts)"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2418
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2419
  "subst_term_list f [] = []"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2420
  "subst_term_list f (t # ts) =
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2421
     subst_term f t # subst_term_list f ts"
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2422
\end{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2423
The recursion scheme follows the structure of the unfolded definition of type
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2424
\texttt{term} shown in \S\ref{subsec:datatype:basics}. To prove properties of
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2425
this substitution function, mutual induction is needed:
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2426
\begin{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2427
Goal
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2428
  "(subst_term ((subst_term f1) o f2) t) =
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2429
     (subst_term f1 (subst_term f2 t)) &
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2430
   (subst_term_list ((subst_term f1) o f2) ts) =
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2431
     (subst_term_list f1 (subst_term_list f2 ts))";
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2432
by (mutual_induct_tac ["t", "ts"] 1);
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2433
by (ALLGOALS Asm_full_simp_tac);
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2434
\end{ttbox}
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2435
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2436
\index{recursion!primitive|)}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2437
\index{*primrec|)}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2438
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2439
4803
8428d4699d58 Clearer description of recdef, including use of {}
paulson
parents: 4591
diff changeset
  2440
\subsection{General recursive functions}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2441
\label{sec:HOL:recdef}
3962
69c76eb80273 Fixed the index entries for "recursion, general"
paulson
parents: 3959
diff changeset
  2442
\index{recursion!general|(}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2443
\index{*recdef|(}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2444
4803
8428d4699d58 Clearer description of recdef, including use of {}
paulson
parents: 4591
diff changeset
  2445
Using \texttt{recdef}, you can declare functions involving nested recursion
8428d4699d58 Clearer description of recdef, including use of {}
paulson
parents: 4591
diff changeset
  2446
and pattern-matching.  Recursion need not involve datatypes and there are few
8428d4699d58 Clearer description of recdef, including use of {}
paulson
parents: 4591
diff changeset
  2447
syntactic restrictions.  Termination is proved by showing that each recursive
8428d4699d58 Clearer description of recdef, including use of {}
paulson
parents: 4591
diff changeset
  2448
call makes the argument smaller in a suitable sense, which you specify by
8428d4699d58 Clearer description of recdef, including use of {}
paulson
parents: 4591
diff changeset
  2449
supplying a well-founded relation.
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2450
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2451
Here is a simple example, the Fibonacci function.  The first line declares
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2452
\texttt{fib} to be a constant.  The well-founded relation is simply~$<$ (on
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2453
the natural numbers).  Pattern-matching is used here: \texttt{1} is a
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2454
macro for \texttt{Suc~0}.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2455
\begin{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2456
consts fib  :: "nat => nat"
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2457
recdef fib "less_than"
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2458
    "fib 0 = 0"
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2459
    "fib 1 = 1"
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2460
    "fib (Suc(Suc x)) = (fib x + fib (Suc x))"
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2461
\end{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2462
4591
f88e466c43fa Fixed the description of recdef
paulson
parents: 4503
diff changeset
  2463
With \texttt{recdef}, function definitions may be incomplete, and patterns may
f88e466c43fa Fixed the description of recdef
paulson
parents: 4503
diff changeset
  2464
overlap, as in functional programming.  The \texttt{recdef} package
f88e466c43fa Fixed the description of recdef
paulson
parents: 4503
diff changeset
  2465
disambiguates overlapping patterns by taking the order of rules into account.
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2466
For missing patterns, the function is defined to return a default value.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2467
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2468
%For example, here is a declaration of the list function \cdx{hd}:
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2469
%\begin{ttbox}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2470
%consts hd :: 'a list => 'a
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2471
%recdef hd "\{\}"
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2472
%    "hd (x#l) = x"
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2473
%\end{ttbox}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2474
%Because this function is not recursive, we may supply the empty well-founded
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2475
%relation, $\{\}$.
4591
f88e466c43fa Fixed the description of recdef
paulson
parents: 4503
diff changeset
  2476
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2477
The well-founded relation defines a notion of ``smaller'' for the function's
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2478
argument type.  The relation $\prec$ is \textbf{well-founded} provided it
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2479
admits no infinitely decreasing chains
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2480
\[ \cdots\prec x@n\prec\cdots\prec x@1. \]
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2481
If the function's argument has type~$\tau$, then $\prec$ has to be a relation
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2482
over~$\tau$: it must have type $(\tau\times\tau)set$.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2483
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2484
Proving well-foundedness can be tricky, so Isabelle/HOL provides a collection
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2485
of operators for building well-founded relations.  The package recognises
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2486
these operators and automatically proves that the constructed relation is
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2487
well-founded.  Here are those operators, in order of importance:
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2488
\begin{itemize}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2489
\item \texttt{less_than} is ``less than'' on the natural numbers.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2490
  (It has type $(nat\times nat)set$, while $<$ has type $[nat,nat]\To bool$.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2491
  
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2492
\item $\mathop{\mathtt{measure}} f$, where $f$ has type $\tau\To nat$, is the
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2493
  relation~$\prec$ on type~$\tau$ such that $x\prec y$ iff $f(x)<f(y)$.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2494
  Typically, $f$ takes the recursive function's arguments (as a tuple) and
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2495
  returns a result expressed in terms of the function \texttt{size}.  It is
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2496
  called a \textbf{measure function}.  Recall that \texttt{size} is overloaded
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2497
  and is defined on all datatypes (see \S\ref{sec:HOL:size}).
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2498
                                                    
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2499
\item $\mathop{\mathtt{inv_image}} f\;R$ is a generalisation of
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2500
  \texttt{measure}.  It specifies a relation such that $x\prec y$ iff $f(x)$
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2501
  is less than $f(y)$ according to~$R$, which must itself be a well-founded
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2502
  relation.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2503
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2504
\item $R@1\texttt{**}R@2$ is the lexicographic product of two relations.  It
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2505
  is a relation on pairs and satisfies $(x@1,x@2)\prec(y@1,y@2)$ iff $x@1$
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2506
  is less than $y@1$ according to~$R@1$ or $x@1=y@1$ and $x@2$
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2507
  is less than $y@2$ according to~$R@2$.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2508
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2509
\item \texttt{finite_psubset} is the proper subset relation on finite sets.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2510
\end{itemize}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2511
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2512
We can use \texttt{measure} to declare Euclid's algorithm for the greatest
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2513
common divisor.  The measure function, $\lambda(m,n). n$, specifies that the
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2514
recursion terminates because argument~$n$ decreases.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2515
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2516
recdef gcd "measure ((\%(m,n). n) ::nat*nat=>nat)"
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2517
    "gcd (m, n) = (if n=0 then m else gcd(n, m mod n))"
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2518
\end{ttbox}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2519
4591
f88e466c43fa Fixed the description of recdef
paulson
parents: 4503
diff changeset
  2520
The general form of a well-founded recursive definition is
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2521
\begin{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2522
recdef {\it function} {\it rel}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2523
    congs   {\it congruence rules}      {\bf(optional)}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2524
    simpset {\it simplification set}      {\bf(optional)}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2525
   {\it reduction rules}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2526
\end{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2527
where
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2528
\begin{itemize}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2529
\item \textit{function} is the name of the function, either as an \textit{id}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2530
  or a \textit{string}.  
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2531
  
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2532
\item \textit{rel} is a {\HOL} expression for the well-founded termination
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2533
  relation.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2534
  
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2535
\item \textit{congruence rules} are required only in highly exceptional
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2536
  circumstances.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2537
  
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2538
\item The \textit{simplification set} is used to prove that the supplied
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2539
  relation is well-founded.  It is also used to prove the \textbf{termination
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2540
    conditions}: assertions that arguments of recursive calls decrease under
4877
7a046198610e fixed simpset(), claset();
wenzelm
parents: 4834
diff changeset
  2541
  \textit{rel}.  By default, simplification uses \texttt{simpset()}, which
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2542
  is sufficient to prove well-foundedness for the built-in relations listed
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2543
  above. 
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2544
  
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2545
\item \textit{reduction rules} specify one or more recursion equations.  Each
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2546
  left-hand side must have the form $f\,t$, where $f$ is the function and $t$
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2547
  is a tuple of distinct variables.  If more than one equation is present then
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2548
  $f$ is defined by pattern-matching on components of its argument whose type
4591
f88e466c43fa Fixed the description of recdef
paulson
parents: 4503
diff changeset
  2549
  is a \texttt{datatype}.  
f88e466c43fa Fixed the description of recdef
paulson
parents: 4503
diff changeset
  2550
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2551
  Unlike with \texttt{primrec}, the reduction rules are not added to the
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2552
  default simpset, and individual rules may not be labelled with identifiers.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2553
  However, the identifier $f$\texttt{.rules} is visible at the \ML\ level
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2554
  as a list of theorems.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2555
\end{itemize}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2556
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2557
With the definition of \texttt{gcd} shown above, Isabelle/HOL is unable to
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2558
prove one termination condition.  It remains as a precondition of the
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2559
recursion theorems.
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2560
\begin{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2561
gcd.rules;
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2562
{\out ["! m n. n ~= 0 --> m mod n < n}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2563
{\out   ==> gcd (?m, ?n) = (if ?n = 0 then ?m else gcd (?n, ?m mod ?n))"] }
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2564
{\out : thm list}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2565
\end{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2566
The theory \texttt{HOL/ex/Primes} illustrates how to prove termination
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2567
conditions afterwards.  The function \texttt{Tfl.tgoalw} is like the standard
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2568
function \texttt{goalw}, which sets up a goal to prove, but its argument
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2569
should be the identifier $f$\texttt{.rules} and its effect is to set up a
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2570
proof of the termination conditions:
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2571
\begin{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2572
Tfl.tgoalw thy [] gcd.rules;
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2573
{\out Level 0}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2574
{\out ! m n. n ~= 0 --> m mod n < n}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2575
{\out  1. ! m n. n ~= 0 --> m mod n < n}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2576
\end{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2577
This subgoal has a one-step proof using \texttt{simp_tac}.  Once the theorem
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2578
is proved, it can be used to eliminate the termination conditions from
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2579
elements of \texttt{gcd.rules}.  Theory \texttt{HOL/Subst/Unify} is a much
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2580
more complicated example of this process, where the termination conditions can
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2581
only be proved by complicated reasoning involving the recursive function
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2582
itself.
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2583
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2584
Isabelle/HOL can prove the \texttt{gcd} function's termination condition
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2585
automatically if supplied with the right simpset.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2586
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2587
recdef gcd "measure ((\%(m,n). n) ::nat*nat=>nat)"
4877
7a046198610e fixed simpset(), claset();
wenzelm
parents: 4834
diff changeset
  2588
  simpset "simpset() addsimps [mod_less_divisor, zero_less_eq]"
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2589
    "gcd (m, n) = (if n=0 then m else gcd(n, m mod n))"
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2590
\end{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2591
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2592
A \texttt{recdef} definition also returns an induction rule specialised for
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2593
the recursive function.  For the \texttt{gcd} function above, the induction
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2594
rule is
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2595
\begin{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2596
gcd.induct;
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2597
{\out "(!!m n. n ~= 0 --> ?P n (m mod n) ==> ?P m n) ==> ?P ?u ?v" : thm}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2598
\end{ttbox}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2599
This rule should be used to reason inductively about the \texttt{gcd}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2600
function.  It usually makes the induction hypothesis available at all
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2601
recursive calls, leading to very direct proofs.  If any termination conditions
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2602
remain unproved, they will become additional premises of this rule.
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2603
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2604
\index{recursion!general|)}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2605
\index{*recdef|)}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2606
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2607
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2608
\section{Inductive and coinductive definitions}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2609
\index{*inductive|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2610
\index{*coinductive|(}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2611
2975
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  2612
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
  2613
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
  2614
example, a structural operational semantics is an inductive definition of an
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  2615
evaluation relation.  Dually, a {\bf coinductive definition} specifies the
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  2616
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
  2617
seen as arising by applying a rule to elements of~$R$.)  An important example
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2618
is using bisimulation relations to formalise equivalence of processes and
2975
230f456956a2 Corrected the informal description of coinductive definition
paulson
parents: 2933
diff changeset
  2619
infinite data structures.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2620
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2621
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
  2622
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
  2623
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
  2624
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
  2625
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2626
Each (co)inductive definition adds definitions to the theory and also
3315
16d603a560d8 Documented `size' function for datatypes.
nipkow
parents: 3287
diff changeset
  2627
proves some theorems.  Each definition creates an \ML\ structure, which is a
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2628
substructure of the main theory structure.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2629
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2630
This package is related to the \ZF\ one, described in a separate
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2631
paper,%
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2632
\footnote{It appeared in CADE~\cite{paulson-CADE}; a longer version is
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2633
  distributed with Isabelle.}  %
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2634
which you should refer to in case of difficulties.  The package is simpler
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2635
than \ZF's thanks to \HOL's extra-logical automatic type-checking.  The types
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2636
of the (co)inductive sets determine the domain of the fixedpoint definition,
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2637
and the package does not have to use inference rules for type-checking.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2638
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2639
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2640
\subsection{The result structure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2641
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
  2642
others are self-explanatory.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2643
\begin{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2644
\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
  2645
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2646
\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
  2647
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2648
\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
  2649
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
  2650
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2651
\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
  2652
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
  2653
names given them in the theory file. 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2654
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2655
\item[\tt elims] is the list of elimination rule.
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2656
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2657
\item[\tt elim] is the head of the list \texttt{elims}.
5751
369dca267a3b SYNC: records (draft version);
wenzelm
parents: 5743
diff changeset
  2658
  
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2659
\item[\tt mk_cases] is a function to create simplified instances of {\tt
6141
a6922171b396 removal of the (thm list) argument of mk_cases
paulson
parents: 6119
diff changeset
  2660
elim} using freeness reasoning on underlying datatypes.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2661
\end{description}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2662
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2663
For an inductive definition, the result structure contains the
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2664
rule \texttt{induct}.  For a
2933
f842a75d9624 Updated discussion and references for inductive definitions
paulson
parents: 2926
diff changeset
  2665
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
  2666
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2667
Figure~\ref{def-result-fig} summarises the two result signatures,
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2668
specifying the types of all these components.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2669
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2670
\begin{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2671
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2672
sig
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2673
val defs         : thm list
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2674
val mono         : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2675
val unfold       : thm
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2676
val intrs        : thm list
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2677
val elims        : thm list
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2678
val elim         : thm
6141
a6922171b396 removal of the (thm list) argument of mk_cases
paulson
parents: 6119
diff changeset
  2679
val mk_cases     : string -> thm
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2680
{\it(Inductive definitions only)} 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2681
val induct       : thm
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2682
{\it(coinductive definitions only)}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2683
val coinduct     : thm
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2684
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2685
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2686
\hrule
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2687
\caption{The {\ML} result of a (co)inductive definition} \label{def-result-fig}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2688
\end{figure}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2689
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2690
\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
  2691
An inductive definition has the form
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2692
\begin{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2693
inductive    {\it inductive sets}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2694
  intrs      {\it introduction rules}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2695
  monos      {\it monotonicity theorems}
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2696
  con_defs   {\it constructor definitions}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2697
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2698
A coinductive definition is identical, except that it starts with the keyword
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2699
\texttt{coinductive}.  
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2700
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2701
The \texttt{monos} and \texttt{con_defs} sections are optional.  If present,
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2702
each is specified by a list of identifiers.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2703
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2704
\begin{itemize}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2705
\item The \textit{inductive sets} are specified by one or more strings.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2706
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2707
\item The \textit{introduction rules} specify one or more introduction rules in
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2708
  the form \textit{ident\/}~\textit{string}, where the identifier gives the name of
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2709
  the rule in the result structure.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2710
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2711
\item The \textit{monotonicity theorems} are required for each operator
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2712
  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
  2713
  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
  2714
  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
  2715
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2716
\item The \textit{constructor definitions} contain definitions of constants
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2717
  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
  2718
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2719
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2720
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2721
\subsection{Example of an inductive definition}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2722
Two declarations, included in a theory file, define the finite powerset
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2723
operator.  First we declare the constant~\texttt{Fin}.  Then we declare it
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2724
inductively, with two introduction rules:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2725
\begin{ttbox}
1389
fbe857ddc80d removed quotes from consts and syntax sections
clasohm
parents: 1234
diff changeset
  2726
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
  2727
inductive "Fin A"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2728
  intrs
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2729
    emptyI  "{\ttlbrace}{\ttrbrace} : Fin A"
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2730
    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
  2731
\end{ttbox}
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2732
The resulting theory structure contains a substructure, called~\texttt{Fin}.
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2733
It contains the \texttt{Fin}$~A$ introduction rules as the list \texttt{Fin.intrs},
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2734
and also individually as \texttt{Fin.emptyI} and \texttt{Fin.consI}.  The induction
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2735
rule is \texttt{Fin.induct}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2736
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2737
For another example, here is a theory file defining the accessible
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2738
part of a relation.  The main thing to note is the use of~\texttt{Pow} in
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2739
the sole introduction rule, and the corresponding mention of the rule
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2740
\verb|Pow_mono| in the \texttt{monos} list.  The paper
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2741
\cite{paulson-CADE} discusses a \ZF\ version of this example in more
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2742
detail.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2743
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2744
Acc = WF + 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2745
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
  2746
       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
  2747
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
  2748
inductive "acc r"
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2749
  intrs
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2750
     pred "pred a r: Pow(acc r) ==> a: acc r"
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2751
  monos   Pow_mono
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2752
end
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2753
\end{ttbox}
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2754
The Isabelle distribution contains many other inductive definitions.  Simple
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2755
examples are collected on subdirectory \texttt{HOL/Induct}.  The theory
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2756
\texttt{HOL/Induct/LList} contains coinductive definitions.  Larger examples
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2757
may be found on other subdirectories of \texttt{HOL}, such as \texttt{IMP},
5764
ea464976a00f records;
wenzelm
parents: 5751
diff changeset
  2758
\texttt{Lambda} and \texttt{Auth}.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2759
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2760
\index{*coinductive|)} \index{*inductive|)}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2761
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2762
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2763
\section{The examples directories}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2764
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2765
Directory \texttt{HOL/Auth} contains theories for proving the correctness of 
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2766
cryptographic protocols.  The approach is based upon operational 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2767
semantics~\cite{paulson-security} rather than the more usual belief logics.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2768
On the same directory are proofs for some standard examples, such as the 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2769
Needham-Schroeder public-key authentication protocol~\cite{paulson-ns} 
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2770
and the Otway-Rees protocol.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2771
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2772
Directory \texttt{HOL/IMP} contains a formalization of various denotational,
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2773
operational and axiomatic semantics of a simple while-language, the necessary
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2774
equivalence proofs, soundness and completeness of the Hoare rules with respect
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2775
to the 
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2776
denotational semantics, and soundness and completeness of a verification
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2777
condition generator.  Much of development is taken from
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2778
Winskel~\cite{winskel93}.  For details see~\cite{nipkow-IMP}.
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2779
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2780
Directory \texttt{HOL/Hoare} contains a user friendly surface syntax for Hoare
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2781
logic, including a tactic for generating verification-conditions.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2782
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2783
Directory \texttt{HOL/MiniML} contains a formalization of the type system of the
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2784
core functional language Mini-ML and a correctness proof for its type
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2785
inference algorithm $\cal W$~\cite{milner78,nazareth-nipkow}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2786
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2787
Directory \texttt{HOL/Lambda} contains a formalization of untyped
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2788
$\lambda$-calculus in de~Bruijn notation and Church-Rosser proofs for $\beta$
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2789
and $\eta$ reduction~\cite{Nipkow-CR}.
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2790
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2791
Directory \texttt{HOL/Subst} contains Martin Coen's mechanization of a theory of
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2792
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
  2793
mechanisation in {\LCF}~\cite{paulson85} of Manna and Waldinger's
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2794
theory~\cite{mw81}.  It demonstrates a complicated use of \texttt{recdef},
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2795
with nested recursion.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2796
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2797
Directory \texttt{HOL/Induct} presents simple examples of (co)inductive
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2798
definitions and datatypes.
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2799
\begin{itemize}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2800
\item Theory \texttt{PropLog} proves the soundness and completeness of
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2801
  classical propositional logic, given a truth table semantics.  The only
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2802
  connective is $\imp$.  A Hilbert-style axiom system is specified, and its
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2803
  set of theorems defined inductively.  A similar proof in \ZF{} is
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2804
  described elsewhere~\cite{paulson-set-II}.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2805
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2806
\item Theory \texttt{Term} defines the datatype \texttt{term}.
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2807
5743
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2808
\item Theory \texttt{ABexp} defines arithmetic and boolean expressions
f2cf404a9579 Updated to new datatype package.
berghofe
parents: 5735
diff changeset
  2809
 as mutually recursive datatypes.
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2810
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2811
\item The definition of lazy lists demonstrates methods for handling
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2812
  infinite data structures and coinduction in higher-order
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2813
  logic~\cite{paulson-coind}.%
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2814
\footnote{To be precise, these lists are \emph{potentially infinite} rather
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2815
  than lazy.  Lazy implies a particular operational semantics.}
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2816
  Theory \thydx{LList} defines an operator for
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2817
  corecursion on lazy lists, which is used to define a few simple functions
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2818
  such as map and append.   A coinduction principle is defined
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2819
  for proving equations on lazy lists.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2820
  
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2821
\item Theory \thydx{LFilter} defines the filter functional for lazy lists.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2822
  This functional is notoriously difficult to define because finding the next
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2823
  element meeting the predicate requires possibly unlimited search.  It is not
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2824
  computable, but can be expressed using a combination of induction and
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2825
  corecursion.  
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2826
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2827
\item Theory \thydx{Exp} illustrates the use of iterated inductive definitions
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2828
  to express a programming language semantics that appears to require mutual
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2829
  induction.  Iterated induction allows greater modularity.
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2830
\end{itemize}
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2831
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2832
Directory \texttt{HOL/ex} contains other examples and experimental proofs in
3132
8e956415412f Documents directory Induct; stylistic improvements
paulson
parents: 3045
diff changeset
  2833
{\HOL}.  
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2834
\begin{itemize}
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2835
\item Theory \texttt{Recdef} presents many examples of using \texttt{recdef}
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2836
  to define recursive functions.  Another example is \texttt{Fib}, which
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2837
  defines the Fibonacci function.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2838
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2839
\item Theory \texttt{Primes} defines the Greatest Common Divisor of two
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2840
  natural numbers and proves a key lemma of the Fundamental Theorem of
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2841
  Arithmetic: if $p$ is prime and $p$ divides $m\times n$ then $p$ divides~$m$
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2842
  or $p$ divides~$n$.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2843
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2844
\item Theory \texttt{Primrec} develops some computation theory.  It
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2845
  inductively defines the set of primitive recursive functions and presents a
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2846
  proof that Ackermann's function is not primitive recursive.
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2847
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2848
\item File \texttt{cla.ML} demonstrates the classical reasoner on over sixty
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2849
  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
  2850
  moderately difficult problems involving equality and quantifiers.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2851
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2852
\item File \texttt{meson.ML} contains an experimental implementation of the {\sc
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2853
    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
  2854
  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
  2855
  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
  2856
  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
  2857
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2858
\item File \texttt{mesontest.ML} contains test data for the {\sc meson} proof
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2859
  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
  2860
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2861
\item File \texttt{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
  2862
  \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
  2863
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2864
\item Theory \texttt{MT} contains Jacob Frost's formalization~\cite{frost93} of
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2865
  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
  2866
  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
  2867
  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
  2868
  environment, which makes a coinductive argument appropriate.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2869
\end{itemize}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2870
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2871
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2872
\goodbreak
1163
c080ff36d24e changed 'chol' labels to 'hol'; added a few parentheses
clasohm
parents: 1162
diff changeset
  2873
\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
  2874
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
  2875
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
  2876
it is so easily expressed:
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2877
\[  \forall f::\alpha \To \alpha \To bool. \exists S::\alpha\To bool.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2878
    \forall x::\alpha. f~x \not= S 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2879
\] 
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2880
%
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2881
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
  2882
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
  2883
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
  2884
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  2885
The Isabelle proof uses \HOL's set theory, with the type $\alpha\,set$ and
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2886
the operator \cdx{range}.
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2887
\begin{ttbox}
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2888
context Set.thy;
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2889
\end{ttbox}
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2890
The set~$S$ is given as an unknown instead of a
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2891
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
  2892
\begin{ttbox}
5151
1e944fe5ce96 Got rid of obsolete "goal" commands.
paulson
parents: 4877
diff changeset
  2893
Goal "?S ~: range\thinspace(f :: 'a=>'a set)";
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2894
{\out Level 0}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2895
{\out ?S ~: range f}
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2896
{\out  1. ?S ~: range f}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2897
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2898
The first two steps are routine.  The rule \tdx{rangeE} replaces
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2899
$\Var{S}\in \texttt{range} \, f$ by $\Var{S}=f~x$ for some~$x$.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2900
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2901
by (resolve_tac [notI] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2902
{\out Level 1}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2903
{\out ?S ~: range f}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2904
{\out  1. ?S : range f ==> False}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2905
\ttbreak
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2906
by (eresolve_tac [rangeE] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2907
{\out Level 2}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2908
{\out ?S ~: range f}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2909
{\out  1. !!x. ?S = f x ==> False}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2910
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2911
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
  2912
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
  2913
any~$\Var{c}$.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2914
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2915
by (eresolve_tac [equalityCE] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2916
{\out Level 3}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2917
{\out ?S ~: range f}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2918
{\out  1. !!x. [| ?c3 x : ?S; ?c3 x : f x |] ==> False}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2919
{\out  2. !!x. [| ?c3 x ~: ?S; ?c3 x ~: f x |] ==> False}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2920
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2921
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
  2922
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
  2923
$\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
  2924
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
  2925
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2926
by (dresolve_tac [CollectD] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2927
{\out Level 4}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2928
{\out {\ttlbrace}x. ?P7 x{\ttrbrace} ~: range f}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2929
{\out  1. !!x. [| ?c3 x : f x; ?P7(?c3 x) |] ==> False}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2930
{\out  2. !!x. [| ?c3 x ~: {\ttlbrace}x. ?P7 x{\ttrbrace}; ?c3 x ~: f x |] ==> False}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2931
\end{ttbox}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2932
Forcing a contradiction between the two assumptions of subgoal~1
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2933
completes the instantiation of~$S$.  It is now the set $\{x. x\not\in
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2934
f~x\}$, which is the standard diagonal construction.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2935
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2936
by (contr_tac 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2937
{\out Level 5}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2938
{\out {\ttlbrace}x. x ~: f x{\ttrbrace} ~: range f}
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2939
{\out  1. !!x. [| x ~: {\ttlbrace}x. x ~: f x{\ttrbrace}; x ~: f x |] ==> False}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2940
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2941
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
  2942
assumption, we employ \ttindex{swap_res_tac}:
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2943
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2944
by (swap_res_tac [CollectI] 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2945
{\out Level 6}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2946
{\out {\ttlbrace}x. x ~: f x{\ttrbrace} ~: range f}
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2947
{\out  1. !!x. [| x ~: f x; ~ False |] ==> x ~: f x}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2948
\ttbreak
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2949
by (assume_tac 1);
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2950
{\out Level 7}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2951
{\out {\ttlbrace}x. x ~: f x{\ttrbrace} ~: range f}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2952
{\out No subgoals!}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2953
\end{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2954
How much creativity is required?  As it happens, Isabelle can prove this
6076
560396301672 tidying, e.g. from \\tt to \\texttt
paulson
parents: 6072
diff changeset
  2955
theorem automatically.  The default classical set \texttt{claset()} contains rules
1162
7be0684950a3 changes made by Lawrence Paulson
clasohm
parents: 1113
diff changeset
  2956
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
  2957
\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
  2958
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
  2959
successfully navigates through the large search space.
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2960
\index{search!best-first}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2961
\begin{ttbox}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2962
choplev 0;
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2963
{\out Level 0}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2964
{\out ?S ~: range f}
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2965
{\out  1. ?S ~: range f}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2966
\ttbreak
4877
7a046198610e fixed simpset(), claset();
wenzelm
parents: 4834
diff changeset
  2967
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
  2968
{\out Level 1}
3152
065c701c7827 misc tuning, cleanup, improvements;
wenzelm
parents: 3132
diff changeset
  2969
{\out {\ttlbrace}x. x ~: f x{\ttrbrace} ~: range f}
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2970
{\out No subgoals!}
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2971
\end{ttbox}
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2972
If you run this example interactively, make sure your current theory contains
3489
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2973
theory \texttt{Set}, for example by executing
afa802078173 Added documentation for recdef, and tidied some other material
paulson
parents: 3487
diff changeset
  2974
\ttindex{set_current_thy}~{\tt"Set"}.  Otherwise the default claset may not
2926
15c21c1ad71d Thorough update.
nipkow
parents: 2495
diff changeset
  2975
contain the rules for set theory.
1113
dd7284573601 converted HOL.tex to CHOL.tex; replaced HOL.tex by CHOL.tex
clasohm
parents:
diff changeset
  2976
\index{higher-order logic|)}
5735
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  2977
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  2978
%%% Local Variables: 
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  2979
%%% mode: latex
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  2980
%%% TeX-master: "logics"
6b8bb85c3848 started to add records;
wenzelm
parents: 5151
diff changeset
  2981
%%% End: