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