src/Doc/Logics/document/HOL.tex
author wenzelm
Sun, 07 Jul 2013 20:23:09 +0200
changeset 52552 0260bdba4dd7
parent 48985 src/Doc/HOL/document/HOL.tex@5386df44a037
child 55413 a8e96847523c
permissions -rw-r--r--
reduced number of old manuals: chapter HOL is back again to the Logics manual by Larry;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
     1
\chapter{Higher-Order Logic}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
     2
\index{higher-order logic|(}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
     3
\index{HOL system@{\sc hol} system}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
     4
52552
0260bdba4dd7 reduced number of old manuals: chapter HOL is back again to the Logics manual by Larry;
wenzelm
parents: 48985
diff changeset
     5
This chapter describes Isabelle's formalization of Higher-Order Logic, a
0260bdba4dd7 reduced number of old manuals: chapter HOL is back again to the Logics manual by Larry;
wenzelm
parents: 48985
diff changeset
     6
polymorphic version of Church's Simple Theory of Types.  HOL can be best
0260bdba4dd7 reduced number of old manuals: chapter HOL is back again to the Logics manual by Larry;
wenzelm
parents: 48985
diff changeset
     7
understood as a simply-typed version of classical set theory.  The monograph
0260bdba4dd7 reduced number of old manuals: chapter HOL is back again to the Logics manual by Larry;
wenzelm
parents: 48985
diff changeset
     8
\emph{Isabelle/HOL --- A Proof Assistant for Higher-Order Logic} provides a
0260bdba4dd7 reduced number of old manuals: chapter HOL is back again to the Logics manual by Larry;
wenzelm
parents: 48985
diff changeset
     9
gentle introduction on using Isabelle/HOL in practice.
0260bdba4dd7 reduced number of old manuals: chapter HOL is back again to the Logics manual by Larry;
wenzelm
parents: 48985
diff changeset
    10
All of this material is mainly of historical interest!
0260bdba4dd7 reduced number of old manuals: chapter HOL is back again to the Logics manual by Larry;
wenzelm
parents: 48985
diff changeset
    11
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    12
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    13
\begin{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    14
  \it name      &\it meta-type  & \it description \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    15
  \cdx{Trueprop}& $bool\To prop$                & coercion to $prop$\\
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
    16
  \cdx{Not}     & $bool\To bool$                & negation ($\lnot$) \\
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    17
  \cdx{True}    & $bool$                        & tautology ($\top$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    18
  \cdx{False}   & $bool$                        & absurdity ($\bot$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    19
  \cdx{If}      & $[bool,\alpha,\alpha]\To\alpha$ & conditional \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    20
  \cdx{Let}     & $[\alpha,\alpha\To\beta]\To\beta$ & let binder
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    21
\end{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    22
\subcaption{Constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    23
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    24
\begin{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    25
\index{"@@{\tt\at} symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    26
\index{*"! symbol}\index{*"? symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    27
\index{*"?"! symbol}\index{*"E"X"! symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    28
  \it symbol &\it name     &\it meta-type & \it description \\
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    29
  \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
    30
        Hilbert description ($\varepsilon$) \\
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    31
  \sdx{ALL} or {\tt!~} & \cdx{All}  & $(\alpha\To bool)\To bool$ & 
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    32
        universal quantifier ($\forall$) \\
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    33
  \sdx{EX} or {\tt?~}  & \cdx{Ex}   & $(\alpha\To bool)\To bool$ & 
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    34
        existential quantifier ($\exists$) \\
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    35
  \texttt{EX!} or {\tt?!} & \cdx{Ex1}  & $(\alpha\To bool)\To bool$ & 
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    36
        unique existence ($\exists!$)\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    37
  \texttt{LEAST}  & \cdx{Least}  & $(\alpha::ord \To bool)\To\alpha$ & 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    38
        least element
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    39
\end{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    40
\subcaption{Binders} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    41
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    42
\begin{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    43
\index{*"= symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    44
\index{&@{\tt\&} symbol}
43077
7d69154d824b Workaround for bug involving makeindex, hyperref and the | symbol
paulson
parents: 42673
diff changeset
    45
\index{"!@{\tt\char124} symbol} %\char124 is vertical bar. We use ! because | stopped working
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    46
\index{*"-"-"> symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    47
  \it symbol    & \it meta-type & \it priority & \it description \\ 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    48
  \sdx{o}       & $[\beta\To\gamma,\alpha\To\beta]\To (\alpha\To\gamma)$ & 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    49
        Left 55 & composition ($\circ$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    50
  \tt =         & $[\alpha,\alpha]\To bool$ & Left 50 & equality ($=$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    51
  \tt <         & $[\alpha::ord,\alpha]\To bool$ & Left 50 & less than ($<$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    52
  \tt <=        & $[\alpha::ord,\alpha]\To bool$ & Left 50 & 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    53
                less than or equals ($\leq$)\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    54
  \tt \&        & $[bool,bool]\To bool$ & Right 35 & conjunction ($\conj$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    55
  \tt |         & $[bool,bool]\To bool$ & Right 30 & disjunction ($\disj$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    56
  \tt -->       & $[bool,bool]\To bool$ & Right 25 & implication ($\imp$)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    57
\end{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    58
\subcaption{Infixes}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    59
\caption{Syntax of \texttt{HOL}} \label{hol-constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    60
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    61
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    62
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    63
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    64
\index{*let symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    65
\index{*in symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    66
\dquotes
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    67
\[\begin{array}{rclcl}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    68
    term & = & \hbox{expression of class~$term$} \\
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    69
         & | & "SOME~" id " . " formula
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    70
         & | & "\at~" id " . " formula \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    71
         & | & 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    72
    \multicolumn{3}{l}{"let"~id~"="~term";"\dots";"~id~"="~term~"in"~term} \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    73
         & | & 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    74
    \multicolumn{3}{l}{"if"~formula~"then"~term~"else"~term} \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    75
         & | & "LEAST"~ id " . " formula \\[2ex]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    76
 formula & = & \hbox{expression of type~$bool$} \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    77
         & | & term " = " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    78
         & | & term " \ttilde= " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    79
         & | & term " < " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    80
         & | & term " <= " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    81
         & | & "\ttilde\ " formula \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    82
         & | & formula " \& " formula \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    83
         & | & formula " | " formula \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    84
         & | & formula " --> " formula \\
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    85
         & | & "ALL~" id~id^* " . " formula
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    86
         & | & "!~~~" id~id^* " . " formula \\
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    87
         & | & "EX~~" id~id^* " . " formula 
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    88
         & | & "?~~~" id~id^* " . " formula \\
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    89
         & | & "EX!~" id~id^* " . " formula
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
    90
         & | & "?!~~" id~id^* " . " formula \\
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    91
  \end{array}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    92
\]
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
    93
\caption{Full grammar for HOL} \label{hol-grammar}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    94
\end{figure} 
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
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    97
\section{Syntax}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    98
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
    99
Figure~\ref{hol-constants} lists the constants (including infixes and
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   100
binders), while Fig.\ts\ref{hol-grammar} presents the grammar of
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   101
higher-order logic.  Note that $a$\verb|~=|$b$ is translated to
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   102
$\lnot(a=b)$.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   103
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   104
\begin{warn}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   105
  HOL has no if-and-only-if connective; logical equivalence is expressed using
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   106
  equality.  But equality has a high priority, as befitting a relation, while
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   107
  if-and-only-if typically has the lowest priority.  Thus, $\lnot\lnot P=P$
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   108
  abbreviates $\lnot\lnot (P=P)$ and not $(\lnot\lnot P)=P$.  When using $=$
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   109
  to mean logical equivalence, enclose both operands in parentheses.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   110
\end{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   111
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   112
\subsection{Types and overloading}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   113
The universal type class of higher-order terms is called~\cldx{term}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   114
By default, explicit type variables have class \cldx{term}.  In
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   115
particular the equality symbol and quantifiers are polymorphic over
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   116
class \texttt{term}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   117
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   118
The type of formulae, \tydx{bool}, belongs to class \cldx{term}; thus,
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   119
formulae are terms.  The built-in type~\tydx{fun}, which constructs
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   120
function types, is overloaded with arity {\tt(term,\thinspace
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   121
  term)\thinspace term}.  Thus, $\sigma\To\tau$ belongs to class~{\tt
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   122
  term} if $\sigma$ and~$\tau$ do, allowing quantification over
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   123
functions.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   124
42907
dfd4ef8e73f6 updated and re-unified HOL typedef, with some live examples;
wenzelm
parents: 42673
diff changeset
   125
HOL allows new types to be declared as subsets of existing types,
dfd4ef8e73f6 updated and re-unified HOL typedef, with some live examples;
wenzelm
parents: 42673
diff changeset
   126
either using the primitive \texttt{typedef} or the more convenient
dfd4ef8e73f6 updated and re-unified HOL typedef, with some live examples;
wenzelm
parents: 42673
diff changeset
   127
\texttt{datatype} (see~{\S}\ref{sec:HOL:datatype}).
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   128
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   129
Several syntactic type classes --- \cldx{plus}, \cldx{minus},
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   130
\cldx{times} and
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   131
\cldx{power} --- permit overloading of the operators {\tt+},\index{*"+
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   132
  symbol} {\tt-}\index{*"- symbol}, {\tt*}.\index{*"* symbol} 
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   133
and \verb|^|.\index{^@\verb.^. symbol} 
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   134
%
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   135
They are overloaded to denote the obvious arithmetic operations on types
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   136
\tdx{nat}, \tdx{int} and~\tdx{real}. (With the \verb|^| operator, the
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   137
exponent always has type~\tdx{nat}.)  Non-arithmetic overloadings are also
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   138
done: the operator {\tt-} can denote set difference, while \verb|^| can
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   139
denote exponentiation of relations (iterated composition).  Unary minus is
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   140
also written as~{\tt-} and is overloaded like its 2-place counterpart; it even
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   141
can stand for set complement.
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   142
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   143
The constant \cdx{0} is also overloaded.  It serves as the zero element of
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   144
several types, of which the most important is \tdx{nat} (the natural
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   145
numbers).  The type class \cldx{plus_ac0} comprises all types for which 0
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   146
and~+ satisfy the laws $x+y=y+x$, $(x+y)+z = x+(y+z)$ and $0+x = x$.  These
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   147
types include the numeric ones \tdx{nat}, \tdx{int} and~\tdx{real} and also
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   148
multisets.  The summation operator \cdx{setsum} is available for all types in
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   149
this class. 
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   150
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   151
Theory \thydx{Ord} defines the syntactic class \cldx{ord} of order
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   152
signatures.  The relations $<$ and $\leq$ are polymorphic over this
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   153
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
   154
the \cdx{LEAST} operator. \thydx{Ord} also defines a subclass
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   155
\cldx{order} of \cldx{ord} which axiomatizes the types that are partially
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   156
ordered with respect to~$\leq$.  A further subclass \cldx{linorder} of
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   157
\cldx{order} axiomatizes linear orderings.
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   158
For details, see the file \texttt{Ord.thy}.
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   159
                                          
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   160
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
   161
type constraints.  Type inference may otherwise make the goal more
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   162
polymorphic than you intended, with confusing results.  For example, the
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   163
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
   164
$\alpha::\{ord,plus\}$, although you may have expected them to have some
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   165
numeric type, e.g. $nat$.  Instead you should have stated the goal as
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   166
$(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
   167
type $nat$.
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
\begin{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   170
  If resolution fails for no obvious reason, try setting
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   171
  \ttindex{show_types} to \texttt{true}, causing Isabelle to display
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   172
  types of terms.  Possibly set \ttindex{show_sorts} to \texttt{true} as
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   173
  well, causing Isabelle to display type classes and sorts.
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
  \index{unification!incompleteness of}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   176
  Where function types are involved, Isabelle's unification code does not
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   177
  guarantee to find instantiations for type variables automatically.  Be
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   178
  prepared to use \ttindex{res_inst_tac} instead of \texttt{resolve_tac},
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   179
  possibly instantiating type variables.  Setting
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   180
  \ttindex{Unify.trace_types} to \texttt{true} causes Isabelle to report
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   181
  omitted search paths during unification.\index{tracing!of unification}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   182
\end{warn}
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
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   185
\subsection{Binders}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   186
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   187
Hilbert's {\bf description} operator~$\varepsilon x. P[x]$ stands for some~$x$
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   188
satisfying~$P$, if such exists.  Since all terms in HOL denote something, a
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   189
description is always meaningful, but we do not know its value unless $P$
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   190
defines it uniquely.  We may write descriptions as \cdx{Eps}($\lambda x.
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   191
P[x]$) or use the syntax \hbox{\tt SOME~$x$.~$P[x]$}.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   192
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   193
Existential quantification is defined by
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   194
\[ \exists x. P~x \;\equiv\; P(\varepsilon x. P~x). \]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   195
The unique existence quantifier, $\exists!x. P$, is defined in terms
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   196
of~$\exists$ and~$\forall$.  An Isabelle binder, it admits nested
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   197
quantifications.  For instance, $\exists!x\,y. P\,x\,y$ abbreviates
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   198
$\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
   199
exists a unique pair $(x,y)$ satisfying~$P\,x\,y$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   200
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   201
\medskip
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   202
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   203
\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
   204
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
   205
\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
   206
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
   207
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
   208
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
   209
quantification.  Both notations are accepted for input.  The print mode
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   210
``\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
   211
passing option \texttt{-m HOL} to the \texttt{isabelle} executable),
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   212
then~{\tt!}\ and~{\tt?}\ are displayed.
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   213
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   214
\medskip
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   215
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   216
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
   217
variable of type $\tau$, then the term \cdx{LEAST}~$x. P[x]$ is defined
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   218
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
   219
Fig.~\ref{hol-defs}).  The definition uses Hilbert's $\varepsilon$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   220
choice operator, so \texttt{Least} is always meaningful, but may yield
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   221
nothing useful in case there is not a unique least element satisfying
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   222
$P$.\footnote{Class $ord$ does not require much of its instances, so
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   223
  $\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
   224
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   225
\medskip All these binders have priority 10.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   226
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   227
\begin{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   228
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
   229
parenthesis when they occur in the context of other operations.  For example,
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   230
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
   231
\end{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   232
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   233
6620
fc991461c7b9 pdf setup;
wenzelm
parents: 6592
diff changeset
   234
\subsection{The let and case constructions}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   235
Local abbreviations can be introduced by a \texttt{let} construct whose
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   236
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
   237
the constant~\cdx{Let}.  It can be expanded by rewriting with its
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   238
definition, \tdx{Let_def}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   239
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   240
HOL also defines the basic syntax
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   241
\[\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
   242
as a uniform means of expressing \texttt{case} constructs.  Therefore \texttt{case}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   243
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
   244
logical meaning.  By declaring translations, you can cause instances of the
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   245
\texttt{case} construct to denote applications of particular case operators.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   246
This is what happens automatically for each \texttt{datatype} definition
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   247
(see~{\S}\ref{sec:HOL:datatype}).
6580
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
\begin{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   250
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
   251
quantifiers, which requires additional enclosing parentheses in the context
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   252
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
   253
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
   254
else\dots})$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   255
\end{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   256
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   257
\section{Rules of inference}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   258
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   259
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   260
\begin{ttbox}\makeatother
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   261
\tdx{refl}          t = (t::'a)
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   262
\tdx{subst}         [| s = t; P s |] ==> P (t::'a)
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   263
\tdx{ext}           (!!x::'a. (f x :: 'b) = g x) ==> (\%x. f x) = (\%x. g x)
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   264
\tdx{impI}          (P ==> Q) ==> P-->Q
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   265
\tdx{mp}            [| P-->Q;  P |] ==> Q
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   266
\tdx{iff}           (P-->Q) --> (Q-->P) --> (P=Q)
9969
4753185f1dd2 renamed (most of...) the select rules
paulson
parents: 9695
diff changeset
   267
\tdx{someI}         P(x::'a) ==> P(@x. P x)
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   268
\tdx{True_or_False} (P=True) | (P=False)
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   269
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   270
\caption{The \texttt{HOL} rules} \label{hol-rules}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   271
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   272
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   273
Figure~\ref{hol-rules} shows the primitive inference rules of~HOL, with
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   274
their~{\ML} names.  Some of the rules deserve additional comments:
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   275
\begin{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   276
\item[\tdx{ext}] expresses extensionality of functions.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   277
\item[\tdx{iff}] asserts that logically equivalent formulae are
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   278
  equal.
9969
4753185f1dd2 renamed (most of...) the select rules
paulson
parents: 9695
diff changeset
   279
\item[\tdx{someI}] gives the defining property of the Hilbert
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   280
  $\varepsilon$-operator.  It is a form of the Axiom of Choice.  The derived rule
9969
4753185f1dd2 renamed (most of...) the select rules
paulson
parents: 9695
diff changeset
   281
  \tdx{some_equality} (see below) is often easier to use.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   282
\item[\tdx{True_or_False}] makes the logic classical.\footnote{In
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   283
    fact, the $\varepsilon$-operator already makes the logic classical, as
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   284
    shown by Diaconescu; see Paulson~\cite{paulson-COLOG} for details.}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   285
\end{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   286
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   287
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   288
\begin{figure}\hfuzz=4pt%suppress "Overfull \hbox" message
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   289
\begin{ttbox}\makeatother
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   290
\tdx{True_def}   True     == ((\%x::bool. x)=(\%x. x))
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   291
\tdx{All_def}    All      == (\%P. P = (\%x. True))
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   292
\tdx{Ex_def}     Ex       == (\%P. P(@x. P x))
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   293
\tdx{False_def}  False    == (!P. P)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   294
\tdx{not_def}    not      == (\%P. P-->False)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   295
\tdx{and_def}    op &     == (\%P Q. !R. (P-->Q-->R) --> R)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   296
\tdx{or_def}     op |     == (\%P Q. !R. (P-->R) --> (Q-->R) --> R)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   297
\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
   298
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   299
\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
   300
\tdx{if_def}     If P x y ==
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   301
              (\%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
   302
\tdx{Let_def}    Let s f  == f s
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   303
\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
   304
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   305
\caption{The \texttt{HOL} definitions} \label{hol-defs}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   306
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   307
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   308
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   309
HOL follows standard practice in higher-order logic: only a few connectives
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   310
are taken as primitive, with the remainder defined obscurely
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   311
(Fig.\ts\ref{hol-defs}).  Gordon's {\sc hol} system expresses the
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   312
corresponding definitions \cite[page~270]{mgordon-hol} using
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   313
object-equality~({\tt=}), which is possible because equality in higher-order
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   314
logic may equate formulae and even functions over formulae.  But theory~HOL,
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   315
like all other Isabelle theories, uses meta-equality~({\tt==}) for
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   316
definitions.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   317
\begin{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   318
The definitions above should never be expanded and are shown for completeness
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   319
only.  Instead users should reason in terms of the derived rules shown below
42924
bd8d78745a7d removed some old stuff;
wenzelm
parents: 42914
diff changeset
   320
or, better still, using high-level tactics.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   321
\end{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   322
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   323
Some of the rules mention type variables; for example, \texttt{refl}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   324
mentions the type variable~{\tt'a}.  This allows you to instantiate
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   325
type variables explicitly by calling \texttt{res_inst_tac}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   326
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   327
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   328
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   329
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   330
\tdx{sym}         s=t ==> t=s
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   331
\tdx{trans}       [| r=s; s=t |] ==> r=t
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   332
\tdx{ssubst}      [| t=s; P s |] ==> P t
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   333
\tdx{box_equals}  [| a=b;  a=c;  b=d |] ==> c=d  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   334
\tdx{arg_cong}    x = y ==> f x = f y
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   335
\tdx{fun_cong}    f = g ==> f x = g x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   336
\tdx{cong}        [| f = g; x = y |] ==> f x = g y
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   337
\tdx{not_sym}     t ~= s ==> s ~= t
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   338
\subcaption{Equality}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   339
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   340
\tdx{TrueI}       True 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   341
\tdx{FalseE}      False ==> P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   342
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   343
\tdx{conjI}       [| P; Q |] ==> P&Q
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   344
\tdx{conjunct1}   [| P&Q |] ==> P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   345
\tdx{conjunct2}   [| P&Q |] ==> Q 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   346
\tdx{conjE}       [| P&Q;  [| P; Q |] ==> R |] ==> R
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   347
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   348
\tdx{disjI1}      P ==> P|Q
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   349
\tdx{disjI2}      Q ==> P|Q
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   350
\tdx{disjE}       [| P | Q; P ==> R; Q ==> R |] ==> R
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   351
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   352
\tdx{notI}        (P ==> False) ==> ~ P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   353
\tdx{notE}        [| ~ P;  P |] ==> R
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   354
\tdx{impE}        [| P-->Q;  P;  Q ==> R |] ==> R
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   355
\subcaption{Propositional logic}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   356
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   357
\tdx{iffI}        [| P ==> Q;  Q ==> P |] ==> P=Q
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   358
\tdx{iffD1}       [| P=Q; P |] ==> Q
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   359
\tdx{iffD2}       [| P=Q; Q |] ==> P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   360
\tdx{iffE}        [| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   361
\subcaption{Logical equivalence}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   362
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   363
\end{ttbox}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   364
\caption{Derived rules for HOL} \label{hol-lemmas1}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   365
\end{figure}
14013
dd80d4654926 moved % comments out of ttboxes
kleing
parents: 13028
diff changeset
   366
%
dd80d4654926 moved % comments out of ttboxes
kleing
parents: 13028
diff changeset
   367
%\tdx{eqTrueI}     P ==> P=True 
dd80d4654926 moved % comments out of ttboxes
kleing
parents: 13028
diff changeset
   368
%\tdx{eqTrueE}     P=True ==> P 
6580
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
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   371
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   372
\begin{ttbox}\makeatother
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   373
\tdx{allI}      (!!x. P x) ==> !x. P x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   374
\tdx{spec}      !x. P x ==> P x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   375
\tdx{allE}      [| !x. P x;  P x ==> R |] ==> R
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   376
\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
   377
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   378
\tdx{exI}       P x ==> ? x. P x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   379
\tdx{exE}       [| ? x. P x; !!x. P x ==> Q |] ==> Q
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   380
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   381
\tdx{ex1I}      [| P a;  !!x. P x ==> x=a |] ==> ?! x. P x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   382
\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
   383
          |] ==> R
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   384
9969
4753185f1dd2 renamed (most of...) the select rules
paulson
parents: 9695
diff changeset
   385
\tdx{some_equality}   [| P a;  !!x. P x ==> x=a |] ==> (@x. P x) = a
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   386
\subcaption{Quantifiers and descriptions}
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
\tdx{ccontr}          (~P ==> False) ==> P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   389
\tdx{classical}       (~P ==> P) ==> P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   390
\tdx{excluded_middle} ~P | P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   391
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   392
\tdx{disjCI}       (~Q ==> P) ==> P|Q
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   393
\tdx{exCI}         (! x. ~ P x ==> P a) ==> ? x. P x
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   394
\tdx{impCE}        [| P-->Q; ~ P ==> R; Q ==> R |] ==> R
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   395
\tdx{iffCE}        [| P=Q;  [| P;Q |] ==> R;  [| ~P; ~Q |] ==> R |] ==> R
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   396
\tdx{notnotD}      ~~P ==> P
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   397
\tdx{swap}         ~P ==> (~Q ==> P) ==> Q
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   398
\subcaption{Classical logic}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   399
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   400
\tdx{if_P}         P ==> (if P then x else y) = x
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   401
\tdx{if_not_P}     ~ P ==> (if P then x else y) = y
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   402
\tdx{split_if}     P(if Q then x else y) = ((Q --> P x) & (~Q --> P y))
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   403
\subcaption{Conditionals}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   404
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   405
\caption{More derived rules} \label{hol-lemmas2}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   406
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   407
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   408
Some derived rules are shown in Figures~\ref{hol-lemmas1}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   409
and~\ref{hol-lemmas2}, with their {\ML} names.  These include natural rules
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   410
for the logical connectives, as well as sequent-style elimination rules for
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   411
conjunctions, implications, and universal quantifiers.  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   412
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   413
Note the equality rules: \tdx{ssubst} performs substitution in
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   414
backward proofs, while \tdx{box_equals} supports reasoning by
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   415
simplifying both sides of an equation.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   416
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   417
The following simple tactics are occasionally useful:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   418
\begin{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   419
\item[\ttindexbold{strip_tac} $i$] applies \texttt{allI} and \texttt{impI}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   420
  repeatedly to remove all outermost universal quantifiers and implications
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   421
  from subgoal $i$.
8443
0ed4b608ba4b renamed cases_tac to case_tac;
wenzelm
parents: 8424
diff changeset
   422
\item[\ttindexbold{case_tac} {\tt"}$P${\tt"} $i$] performs case distinction on
0ed4b608ba4b renamed cases_tac to case_tac;
wenzelm
parents: 8424
diff changeset
   423
  $P$ for subgoal $i$: the latter is replaced by two identical subgoals with
0ed4b608ba4b renamed cases_tac to case_tac;
wenzelm
parents: 8424
diff changeset
   424
  the added assumptions $P$ and $\lnot P$, respectively.
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   425
\item[\ttindexbold{smp_tac} $j$ $i$] applies $j$ times \texttt{spec} and then
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   426
  \texttt{mp} in subgoal $i$, which is typically useful when forward-chaining 
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   427
  from an induction hypothesis. As a generalization of \texttt{mp_tac}, 
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   428
  if there are assumptions $\forall \vec{x}. P \vec{x} \imp Q \vec{x}$ and 
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   429
  $P \vec{a}$, ($\vec{x}$ being a vector of $j$ variables)
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   430
  then it replaces the universally quantified implication by $Q \vec{a}$. 
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   431
  It may instantiate unknowns. It fails if it can do nothing.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   432
\end{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   433
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   434
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   435
\begin{figure} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   436
\begin{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   437
\begin{tabular}{rrr}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   438
  \it name      &\it meta-type  & \it description \\ 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   439
\index{{}@\verb'{}' symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   440
  \verb|{}|     & $\alpha\,set$         & the empty set \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   441
  \cdx{insert}  & $[\alpha,\alpha\,set]\To \alpha\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   442
        & insertion of element \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   443
  \cdx{Collect} & $(\alpha\To bool)\To\alpha\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   444
        & comprehension \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   445
  \cdx{INTER} & $[\alpha\,set,\alpha\To\beta\,set]\To\beta\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   446
        & intersection over a set\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   447
  \cdx{UNION} & $[\alpha\,set,\alpha\To\beta\,set]\To\beta\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   448
        & union over a set\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   449
  \cdx{Inter} & $(\alpha\,set)set\To\alpha\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   450
        &set of sets intersection \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   451
  \cdx{Union} & $(\alpha\,set)set\To\alpha\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   452
        &set of sets union \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   453
  \cdx{Pow}   & $\alpha\,set \To (\alpha\,set)set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   454
        & powerset \\[1ex]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   455
  \cdx{range}   & $(\alpha\To\beta )\To\beta\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   456
        & range of a function \\[1ex]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   457
  \cdx{Ball}~~\cdx{Bex} & $[\alpha\,set,\alpha\To bool]\To bool$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   458
        & bounded quantifiers
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   459
\end{tabular}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   460
\end{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   461
\subcaption{Constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   462
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   463
\begin{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   464
\begin{tabular}{llrrr} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   465
  \it symbol &\it name     &\it meta-type & \it priority & \it description \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   466
  \sdx{INT}  & \cdx{INTER1}  & $(\alpha\To\beta\,set)\To\beta\,set$ & 10 & 
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   467
        intersection\\
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   468
  \sdx{UN}  & \cdx{UNION1}  & $(\alpha\To\beta\,set)\To\beta\,set$ & 10 & 
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   469
        union 
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   470
\end{tabular}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   471
\end{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   472
\subcaption{Binders} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   473
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   474
\begin{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   475
\index{*"`"` symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   476
\index{*": symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   477
\index{*"<"= symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   478
\begin{tabular}{rrrr} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   479
  \it symbol    & \it meta-type & \it priority & \it description \\ 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   480
  \tt ``        & $[\alpha\To\beta ,\alpha\,set]\To  \beta\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   481
        & Left 90 & image \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   482
  \sdx{Int}     & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   483
        & Left 70 & intersection ($\int$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   484
  \sdx{Un}      & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   485
        & Left 65 & union ($\un$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   486
  \tt:          & $[\alpha ,\alpha\,set]\To bool$       
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   487
        & Left 50 & membership ($\in$) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   488
  \tt <=        & $[\alpha\,set,\alpha\,set]\To bool$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   489
        & Left 50 & subset ($\subseteq$) 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   490
\end{tabular}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   491
\end{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   492
\subcaption{Infixes}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   493
\caption{Syntax of the theory \texttt{Set}} \label{hol-set-syntax}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   494
\end{figure} 
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
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   497
\begin{figure} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   498
\begin{center} \tt\frenchspacing
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}{rrr} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   501
  \it external          & \it internal  & \it description \\ 
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   502
  $a$ \ttilde: $b$      & \ttilde($a$ : $b$)    & \rm not in\\
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   503
  {\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
   504
  {\ttlbrace}$x$. $P[x]${\ttrbrace}        &  Collect($\lambda x. P[x]$) &
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   505
        \rm comprehension \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   506
  \sdx{INT} $x$:$A$. $B[x]$      & INTER $A$ $\lambda x. B[x]$ &
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   507
        \rm intersection \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   508
  \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
   509
        \rm union \\
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   510
  \sdx{ALL} $x$:$A$.\ $P[x]$ or \texttt{!} $x$:$A$.\ $P[x]$ &
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   511
        Ball $A$ $\lambda x.\ P[x]$ & 
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   512
        \rm bounded $\forall$ \\
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   513
  \sdx{EX}{\tt\ } $x$:$A$.\ $P[x]$ or \texttt{?} $x$:$A$.\ $P[x]$ & 
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   514
        Bex $A$ $\lambda x.\ P[x]$ & \rm bounded $\exists$
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   515
\end{tabular}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   516
\end{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   517
\subcaption{Translations}
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
\dquotes
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   520
\[\begin{array}{rclcl}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   521
    term & = & \hbox{other terms\ldots} \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   522
         & | & "{\ttlbrace}{\ttrbrace}" \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   523
         & | & "{\ttlbrace} " term\; ("," term)^* " {\ttrbrace}" \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   524
         & | & "{\ttlbrace} " id " . " formula " {\ttrbrace}" \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   525
         & | & term " `` " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   526
         & | & term " Int " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   527
         & | & term " Un " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   528
         & | & "INT~~"  id ":" term " . " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   529
         & | & "UN~~~"  id ":" term " . " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   530
         & | & "INT~~"  id~id^* " . " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   531
         & | & "UN~~~"  id~id^* " . " term \\[2ex]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   532
 formula & = & \hbox{other formulae\ldots} \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   533
         & | & term " : " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   534
         & | & term " \ttilde: " term \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   535
         & | & term " <= " term \\
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   536
         & | & "ALL " id ":" term " . " formula
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   537
         & | & "!~" id ":" term " . " formula \\
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   538
         & | & "EX~~" id ":" term " . " formula
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   539
         & | & "?~" id ":" term " . " formula \\
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   540
  \end{array}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   541
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   542
\subcaption{Full Grammar}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   543
\caption{Syntax of the theory \texttt{Set} (continued)} \label{hol-set-syntax2}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   544
\end{figure} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   545
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   546
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   547
\section{A formulation of set theory}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   548
Historically, higher-order logic gives a foundation for Russell and
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   549
Whitehead's theory of classes.  Let us use modern terminology and call them
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   550
{\bf sets}, but note that these sets are distinct from those of ZF set theory,
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   551
and behave more like ZF classes.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   552
\begin{itemize}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   553
\item
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   554
Sets are given by predicates over some type~$\sigma$.  Types serve to
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   555
define universes for sets, but type-checking is still significant.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   556
\item
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   557
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
   558
may be defined by absolute comprehension.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   559
\item
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   560
Although sets may contain other sets as elements, the containing set must
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   561
have a more complex type.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   562
\end{itemize}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   563
Finite unions and intersections have the same behaviour in HOL as they do
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   564
in~ZF.  In HOL the intersection of the empty set is well-defined, denoting the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   565
universal set for the given type.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   566
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   567
\subsection{Syntax of set theory}\index{*set type}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   568
HOL's set theory is called \thydx{Set}.  The type $\alpha\,set$ is essentially
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   569
the same as $\alpha\To bool$.  The new type is defined for clarity and to
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   570
avoid complications involving function types in unification.  The isomorphisms
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   571
between the two types are declared explicitly.  They are very natural:
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   572
\texttt{Collect} maps $\alpha\To bool$ to $\alpha\,set$, while \hbox{\tt op :}
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   573
maps in the other direction (ignoring argument order).
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   574
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   575
Figure~\ref{hol-set-syntax} lists the constants, infixes, and syntax
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   576
translations.  Figure~\ref{hol-set-syntax2} presents the grammar of the new
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   577
constructs.  Infix operators include union and intersection ($A\un B$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   578
and $A\int B$), the subset and membership relations, and the image
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   579
operator~{\tt``}\@.  Note that $a$\verb|~:|$b$ is translated to
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   580
$\lnot(a\in b)$.  
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   581
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   582
The $\{a@1,\ldots\}$ notation abbreviates finite sets constructed in
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   583
the obvious manner using~\texttt{insert} and~$\{\}$:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   584
\begin{eqnarray*}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   585
  \{a, b, c\} & \equiv &
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   586
  \texttt{insert} \, a \, ({\tt insert} \, b \, ({\tt insert} \, c \, \{\}))
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   587
\end{eqnarray*}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   588
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   589
The set \hbox{\tt{\ttlbrace}$x$.\ $P[x]${\ttrbrace}} consists of all $x$ (of
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   590
suitable type) that satisfy~$P[x]$, where $P[x]$ is a formula that may contain
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   591
free occurrences of~$x$.  This syntax expands to \cdx{Collect}$(\lambda x.
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   592
P[x])$.  It defines sets by absolute comprehension, which is impossible in~ZF;
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   593
the type of~$x$ implicitly restricts the comprehension.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   594
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   595
The set theory defines two {\bf bounded quantifiers}:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   596
\begin{eqnarray*}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   597
   \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
   598
   \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
   599
\end{eqnarray*}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   600
The constants~\cdx{Ball} and~\cdx{Bex} are defined
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   601
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
   602
write\index{*"! symbol}\index{*"? symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   603
\index{*ALL symbol}\index{*EX symbol} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   604
%
7245
65ccac4e1f3f eliminated HOL_quantifiers (replaced by "HOL" print mode);
wenzelm
parents: 7044
diff changeset
   605
\hbox{\tt ALL~$x$:$A$.\ $P[x]$} and \hbox{\tt EX~$x$:$A$.\ $P[x]$}.  The
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   606
original notation of Gordon's {\sc hol} system is supported as well:
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   607
\texttt{!}\ and \texttt{?}.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   608
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   609
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
   610
$\bigcap@{x\in A}B[x]$, are written 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   611
\sdx{UN}~\hbox{\tt$x$:$A$.\ $B[x]$} and
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   612
\sdx{INT}~\hbox{\tt$x$:$A$.\ $B[x]$}.  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   613
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   614
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
   615
B[x]$, are written \sdx{UN}~\hbox{\tt$x$.\ $B[x]$} and
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   616
\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
   617
union and intersection operators when $A$ is the universal set.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   618
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   619
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
   620
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
   621
respectively.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   622
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   623
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   624
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   625
\begin{figure} \underscoreon
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   626
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   627
\tdx{mem_Collect_eq}    (a : {\ttlbrace}x. P x{\ttrbrace}) = P a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   628
\tdx{Collect_mem_eq}    {\ttlbrace}x. x:A{\ttrbrace} = A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   629
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   630
\tdx{empty_def}         {\ttlbrace}{\ttrbrace}          == {\ttlbrace}x. False{\ttrbrace}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   631
\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
   632
\tdx{Ball_def}          Ball A P    == ! x. x:A --> P x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   633
\tdx{Bex_def}           Bex A P     == ? x. x:A & P x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   634
\tdx{subset_def}        A <= B      == ! x:A. x:B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   635
\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
   636
\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
   637
\tdx{set_diff_def}      A - B       == {\ttlbrace}x. x:A & x~:B{\ttrbrace}
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   638
\tdx{Compl_def}         -A          == {\ttlbrace}x. ~ x:A{\ttrbrace}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   639
\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
   640
\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
   641
\tdx{INTER1_def}        INTER1 B    == INTER {\ttlbrace}x. True{\ttrbrace} B 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   642
\tdx{UNION1_def}        UNION1 B    == UNION {\ttlbrace}x. True{\ttrbrace} B 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   643
\tdx{Inter_def}         Inter S     == (INT x:S. x)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   644
\tdx{Union_def}         Union S     == (UN  x:S. x)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   645
\tdx{Pow_def}           Pow A       == {\ttlbrace}B. B <= A{\ttrbrace}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   646
\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
   647
\tdx{range_def}         range f     == {\ttlbrace}y. ? x. y=f x{\ttrbrace}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   648
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   649
\caption{Rules of the theory \texttt{Set}} \label{hol-set-rules}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   650
\end{figure}
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
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   653
\begin{figure} \underscoreon
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   654
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   655
\tdx{CollectI}        [| P a |] ==> a : {\ttlbrace}x. P x{\ttrbrace}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   656
\tdx{CollectD}        [| a : {\ttlbrace}x. P x{\ttrbrace} |] ==> P a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   657
\tdx{CollectE}        [| a : {\ttlbrace}x. P x{\ttrbrace};  P a ==> W |] ==> W
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   658
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   659
\tdx{ballI}           [| !!x. x:A ==> P x |] ==> ! x:A. P x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   660
\tdx{bspec}           [| ! x:A. P x;  x:A |] ==> P x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   661
\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
   662
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   663
\tdx{bexI}            [| P x;  x:A |] ==> ? x:A. P x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   664
\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
   665
\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
   666
\subcaption{Comprehension and Bounded quantifiers}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   667
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   668
\tdx{subsetI}         (!!x. x:A ==> x:B) ==> A <= B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   669
\tdx{subsetD}         [| A <= B;  c:A |] ==> c:B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   670
\tdx{subsetCE}        [| A <= B;  ~ (c:A) ==> P;  c:B ==> P |] ==> P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   671
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   672
\tdx{subset_refl}     A <= A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   673
\tdx{subset_trans}    [| A<=B;  B<=C |] ==> A<=C
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
\tdx{equalityI}       [| A <= B;  B <= A |] ==> A = B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   676
\tdx{equalityD1}      A = B ==> A<=B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   677
\tdx{equalityD2}      A = B ==> B<=A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   678
\tdx{equalityE}       [| A = B;  [| A<=B; B<=A |] ==> P |]  ==>  P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   679
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   680
\tdx{equalityCE}      [| A = B;  [| c:A; c:B |] ==> P;  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   681
                           [| ~ c:A; ~ c:B |] ==> P 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   682
                |]  ==>  P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   683
\subcaption{The subset and equality relations}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   684
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   685
\caption{Derived rules for set theory} \label{hol-set1}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   686
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   687
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   688
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   689
\begin{figure} \underscoreon
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   690
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   691
\tdx{emptyE}   a : {\ttlbrace}{\ttrbrace} ==> P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   692
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   693
\tdx{insertI1} a : insert a B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   694
\tdx{insertI2} a : B ==> a : insert b B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   695
\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
   696
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   697
\tdx{ComplI}   [| c:A ==> False |] ==> c : -A
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   698
\tdx{ComplD}   [| c : -A |] ==> ~ c:A
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   699
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   700
\tdx{UnI1}     c:A ==> c : A Un B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   701
\tdx{UnI2}     c:B ==> c : A Un B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   702
\tdx{UnCI}     (~c:B ==> c:A) ==> c : A Un B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   703
\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
   704
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   705
\tdx{IntI}     [| c:A;  c:B |] ==> c : A Int B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   706
\tdx{IntD1}    c : A Int B ==> c:A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   707
\tdx{IntD2}    c : A Int B ==> c:B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   708
\tdx{IntE}     [| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P
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
\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
   711
\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
   712
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   713
\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
   714
\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
   715
\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
   716
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   717
\tdx{UnionI}   [| X:C;  A:X |] ==> A : Union C
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   718
\tdx{UnionE}   [| A : Union C;  !!X.[| A:X;  X:C |] ==> R |] ==> R
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   719
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   720
\tdx{InterI}   [| !!X. X:C ==> A:X |] ==> A : Inter C
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   721
\tdx{InterD}   [| A : Inter C;  X:C |] ==> A:X
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   722
\tdx{InterE}   [| A : Inter C;  A:X ==> R;  ~ X:C ==> R |] ==> R
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   723
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   724
\tdx{PowI}     A<=B ==> A: Pow B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   725
\tdx{PowD}     A: Pow B ==> A<=B
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{imageI}   [| x:A |] ==> f x : f``A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   728
\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
   729
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   730
\tdx{rangeI}   f x : range f
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   731
\tdx{rangeE}   [| b : range f;  !!x.[| b=f x |] ==> P |] ==> P
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   732
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   733
\caption{Further derived rules for set theory} \label{hol-set2}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   734
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   735
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   736
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   737
\subsection{Axioms and rules of set theory}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   738
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
   739
axioms \tdx{mem_Collect_eq} and \tdx{Collect_mem_eq} assert
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   740
that the functions \texttt{Collect} and \hbox{\tt op :} are isomorphisms.  Of
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   741
course, \hbox{\tt op :} also serves as the membership relation.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   742
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   743
All the other axioms are definitions.  They include the empty set, bounded
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   744
quantifiers, unions, intersections, complements and the subset relation.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   745
They also include straightforward constructions on functions: image~({\tt``})
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   746
and \texttt{range}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   747
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   748
%The predicate \cdx{inj_on} is used for simulating type definitions.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   749
%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
   750
%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
   751
%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
   752
%representations; we should not expect $f$ to be injective outside of~$A$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   753
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   754
%\begin{figure} \underscoreon
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   755
%\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   756
%\tdx{Inv_f_f}    inj f ==> Inv f (f x) = x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   757
%\tdx{f_Inv_f}    y : range f ==> f(Inv f y) = y
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
%\tdx{Inv_injective}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   760
%    [| 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
   761
%
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   762
%
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   763
%\tdx{monoI}      [| !!A B. A <= B ==> f A <= f B |] ==> mono f
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   764
%\tdx{monoD}      [| mono f;  A <= B |] ==> f A <= f B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   765
%
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   766
%\tdx{injI}       [| !! x y. f x = f y ==> x=y |] ==> inj f
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   767
%\tdx{inj_inverseI}              (!!x. g(f x) = x) ==> inj f
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   768
%\tdx{injD}       [| inj f; f x = f y |] ==> x=y
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
%\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
   771
%\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
   772
%
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   773
%\tdx{inj_on_inverseI}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   774
%    (!!x. x:A ==> g(f x) = x) ==> inj_on f A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   775
%\tdx{inj_on_contraD}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   776
%    [| 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
   777
%\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   778
%\caption{Derived rules involving functions} \label{hol-fun}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   779
%\end{figure}
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
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   782
\begin{figure} \underscoreon
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   783
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   784
\tdx{Union_upper}     B:A ==> B <= Union A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   785
\tdx{Union_least}     [| !!X. X:A ==> X<=C |] ==> Union A <= C
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   786
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   787
\tdx{Inter_lower}     B:A ==> Inter A <= B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   788
\tdx{Inter_greatest}  [| !!X. X:A ==> C<=X |] ==> C <= Inter A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   789
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   790
\tdx{Un_upper1}       A <= A Un B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   791
\tdx{Un_upper2}       B <= A Un B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   792
\tdx{Un_least}        [| A<=C;  B<=C |] ==> A Un B <= C
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   793
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   794
\tdx{Int_lower1}      A Int B <= A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   795
\tdx{Int_lower2}      A Int B <= B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   796
\tdx{Int_greatest}    [| C<=A;  C<=B |] ==> C <= A Int B
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   797
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   798
\caption{Derived rules involving subsets} \label{hol-subset}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   799
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   800
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   801
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   802
\begin{figure} \underscoreon   \hfuzz=4pt%suppress "Overfull \hbox" message
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   803
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   804
\tdx{Int_absorb}        A Int A = A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   805
\tdx{Int_commute}       A Int B = B Int A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   806
\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
   807
\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
   808
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   809
\tdx{Un_absorb}         A Un A = A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   810
\tdx{Un_commute}        A Un B = B Un A
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   811
\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
   812
\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
   813
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   814
\tdx{Compl_disjoint}    A Int (-A) = {\ttlbrace}x. False{\ttrbrace}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   815
\tdx{Compl_partition}   A Un  (-A) = {\ttlbrace}x. True{\ttrbrace}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   816
\tdx{double_complement} -(-A) = A
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   817
\tdx{Compl_Un}          -(A Un B)  = (-A) Int (-B)
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
   818
\tdx{Compl_Int}         -(A Int B) = (-A) Un (-B)
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   819
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   820
\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
   821
\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
   822
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   823
\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
   824
\tdx{Un_Inter}          A Un (Inter B) = (INT C:B. A Un C)
14013
dd80d4654926 moved % comments out of ttboxes
kleing
parents: 13028
diff changeset
   825
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   826
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   827
\caption{Set equalities} \label{hol-equalities}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   828
\end{figure}
14013
dd80d4654926 moved % comments out of ttboxes
kleing
parents: 13028
diff changeset
   829
%\tdx{Un_Union_image}    (UN x:C.(A x) Un (B x)) = Union(A``C) Un Union(B``C)
dd80d4654926 moved % comments out of ttboxes
kleing
parents: 13028
diff changeset
   830
%\tdx{Int_Inter_image}   (INT x:C.(A x) Int (B x)) = Inter(A``C) Int Inter(B``C)
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   831
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   832
Figures~\ref{hol-set1} and~\ref{hol-set2} present derived rules.  Most are
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   833
obvious and resemble rules of Isabelle's ZF set theory.  Certain rules, such
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   834
as \tdx{subsetCE}, \tdx{bexCI} and \tdx{UnCI}, are designed for classical
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   835
reasoning; the rules \tdx{subsetD}, \tdx{bexI}, \tdx{Un1} and~\tdx{Un2} are
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   836
not strictly necessary but yield more natural proofs.  Similarly,
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   837
\tdx{equalityCE} supports classical reasoning about extensionality, after the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   838
fashion of \tdx{iffCE}.  See the file \texttt{HOL/Set.ML} for proofs
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   839
pertaining to set theory.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   840
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   841
Figure~\ref{hol-subset} presents lattice properties of the subset relation.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   842
Unions form least upper bounds; non-empty intersections form greatest lower
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   843
bounds.  Reasoning directly about subsets often yields clearer proofs than
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   844
reasoning about the membership relation.  See the file \texttt{HOL/subset.ML}.
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
Figure~\ref{hol-equalities} presents many common set equalities.  They
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   847
include commutative, associative and distributive laws involving unions,
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   848
intersections and complements.  For a complete listing see the file {\tt
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   849
HOL/equalities.ML}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   850
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   851
\begin{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   852
\texttt{Blast_tac} proves many set-theoretic theorems automatically.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   853
Hence you seldom need to refer to the theorems above.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   854
\end{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   855
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   856
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   857
\begin{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   858
\begin{tabular}{rrr}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   859
  \it name      &\it meta-type  & \it description \\ 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   860
  \cdx{inj}~~\cdx{surj}& $(\alpha\To\beta )\To bool$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   861
        & injective/surjective \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   862
  \cdx{inj_on}        & $[\alpha\To\beta ,\alpha\,set]\To bool$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   863
        & injective over subset\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   864
  \cdx{inv} & $(\alpha\To\beta)\To(\beta\To\alpha)$ & inverse function
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   865
\end{tabular}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   866
\end{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   867
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   868
\underscoreon
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   869
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   870
\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
   871
\tdx{surj_def}        surj f     == ! y. ? x. y=f x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   872
\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
   873
\tdx{inv_def}         inv f      == (\%y. @x. f(x)=y)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   874
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   875
\caption{Theory \thydx{Fun}} \label{fig:HOL:Fun}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   876
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   877
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   878
\subsection{Properties of functions}\nopagebreak
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   879
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
   880
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
   881
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
   882
rules.  Reasoning about function composition (the operator~\sdx{o}) and the
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   883
predicate~\cdx{surj} is done simply by expanding the definitions.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   884
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   885
There is also a large collection of monotonicity theorems for constructions
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   886
on sets in the file \texttt{HOL/mono.ML}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   887
7283
5cfe2944910a documented svc_tac
paulson
parents: 7245
diff changeset
   888
42924
bd8d78745a7d removed some old stuff;
wenzelm
parents: 42914
diff changeset
   889
\section{Simplification and substitution}
6580
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
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
   892
(\texttt{simpset()}), which works for most purposes.  A quite minimal
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   893
simplification set for higher-order logic is~\ttindexbold{HOL_ss};
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   894
even more frugal is \ttindexbold{HOL_basic_ss}.  Equality~($=$), which
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   895
also expresses logical equivalence, may be used for rewriting.  See
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   896
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
   897
simplification rules.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   898
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   899
See \iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   900
{Chaps.\ts\ref{substitution} and~\ref{simp-chap}} for details of substitution
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   901
and simplification.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   902
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   903
\begin{warn}\index{simplification!of conjunctions}%
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   904
  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
   905
  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
   906
  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
   907
  including \ttindex{conj_cong} in a simpset, \verb$addcongs [conj_cong]$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   908
\end{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   909
8604
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
   910
\begin{warn}\index{simplification!of \texttt{if}}\label{if-simp}%
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
   911
  By default only the condition of an \ttindex{if} is simplified but not the
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
   912
  \texttt{then} and \texttt{else} parts. Of course the latter are simplified
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
   913
  once the condition simplifies to \texttt{True} or \texttt{False}. To ensure
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
   914
  full simplification of all parts of a conditional you must remove
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
   915
  \ttindex{if_weak_cong} from the simpset, \verb$delcongs [if_weak_cong]$.
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
   916
\end{warn}
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
   917
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   918
If the simplifier cannot use a certain rewrite rule --- either because
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   919
of nontermination or because its left-hand side is too flexible ---
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   920
then you might try \texttt{stac}:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   921
\begin{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   922
\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
   923
  replaces in subgoal $i$ instances of $lhs$ by corresponding instances of
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   924
  $rhs$.  In case of multiple instances of $lhs$ in subgoal $i$, backtracking
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   925
  may be necessary to select the desired ones.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   926
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   927
If $thm$ is a conditional equality, the instantiated condition becomes an
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   928
additional (first) subgoal.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   929
\end{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   930
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   931
HOL provides the tactic \ttindex{hyp_subst_tac}, which substitutes for an
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   932
equality throughout a subgoal and its hypotheses.  This tactic uses HOL's
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   933
general substitution rule.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   934
42924
bd8d78745a7d removed some old stuff;
wenzelm
parents: 42914
diff changeset
   935
\subsection{Case splitting}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   936
\label{subsec:HOL:case:splitting}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   937
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   938
HOL also provides convenient means for case splitting during rewriting. Goals
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   939
containing a subterm of the form \texttt{if}~$b$~{\tt then\dots else\dots}
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   940
often require a case distinction on $b$. This is expressed by the theorem
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   941
\tdx{split_if}:
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   942
$$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   943
\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
   944
((\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
   945
\eqno{(*)}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   946
$$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   947
For example, a simple instance of $(*)$ is
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   948
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   949
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
   950
((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
   951
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   952
Because $(*)$ is too general as a rewrite rule for the simplifier (the
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   953
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
   954
\iflabelundefined{chap:simplification}{the {\em Reference Manual\/}}%
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   955
{Chap.\ts\ref{chap:simplification}}), there is a special infix function 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   956
\ttindexbold{addsplits} of type \texttt{simpset * thm list -> simpset}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   957
(analogous to \texttt{addsimps}) that adds rules such as $(*)$ to a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   958
simpset, as in
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   959
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   960
by(simp_tac (simpset() addsplits [split_if]) 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   961
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   962
The effect is that after each round of simplification, one occurrence of
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   963
\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
   964
\texttt{if} have been eliminated.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   965
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   966
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
   967
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
   968
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
   969
the inverse of \texttt{addsplits}:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   970
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   971
by(simp_tac (simpset() delsplits [split_if]) 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   972
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   973
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   974
In general, \texttt{addsplits} accepts rules of the form
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   975
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   976
\Var{P}(c~\Var{x@1}~\dots~\Var{x@n})~=~ rhs
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   977
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   978
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
   979
right form because internally the left-hand side is
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   980
$\Var{P}(\mathtt{If}~\Var{b}~\Var{x}~~\Var{y})$. Important further examples
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   981
are splitting rules for \texttt{case} expressions (see~{\S}\ref{subsec:list}
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
   982
and~{\S}\ref{subsec:datatype:basics}).
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   983
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   984
Analogous to \texttt{Addsimps} and \texttt{Delsimps}, there are also
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   985
imperative versions of \texttt{addsplits} and \texttt{delsplits}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   986
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   987
\ttindexbold{Addsplits}: thm list -> unit
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   988
\ttindexbold{Delsplits}: thm list -> unit
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   989
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   990
for adding splitting rules to, and deleting them from the current simpset.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   991
7283
5cfe2944910a documented svc_tac
paulson
parents: 7245
diff changeset
   992
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
   993
\section{Types}\label{sec:HOL:Types}
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   994
This section describes HOL's basic predefined types ($\alpha \times \beta$,
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   995
$\alpha + \beta$, $nat$ and $\alpha \; list$) and ways for introducing new
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   996
types in general.  The most important type construction, the
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
   997
\texttt{datatype}, is treated separately in {\S}\ref{sec:HOL:datatype}.
6580
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
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1000
\subsection{Product and sum types}\index{*"* type}\index{*"+ type}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1001
\label{subsec:prod-sum}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1002
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1003
\begin{figure}[htbp]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1004
\begin{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1005
  \it symbol    & \it meta-type &           & \it description \\ 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1006
  \cdx{Pair}    & $[\alpha,\beta]\To \alpha\times\beta$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1007
        & & ordered pairs $(a,b)$ \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1008
  \cdx{fst}     & $\alpha\times\beta \To \alpha$        & & first projection\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1009
  \cdx{snd}     & $\alpha\times\beta \To \beta$         & & second projection\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1010
  \cdx{split}   & $[[\alpha,\beta]\To\gamma, \alpha\times\beta] \To \gamma$ 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1011
        & & generalized projection\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1012
  \cdx{Sigma}  & 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1013
        $[\alpha\,set, \alpha\To\beta\,set]\To(\alpha\times\beta)set$ &
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1014
        & general sum of sets
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1015
\end{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1016
%\tdx{fst_def}      fst p     == @a. ? b. p = (a,b)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1017
%\tdx{snd_def}      snd p     == @b. ? a. p = (a,b)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1018
%\tdx{split_def}    split c p == c (fst p) (snd p)
14013
dd80d4654926 moved % comments out of ttboxes
kleing
parents: 13028
diff changeset
  1019
\begin{ttbox}\makeatletter
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1020
\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
  1021
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1022
\tdx{Pair_eq}      ((a,b) = (a',b')) = (a=a' & b=b')
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1023
\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
  1024
\tdx{PairE}        [| !!x y. p = (x,y) ==> Q |] ==> Q
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1025
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1026
\tdx{fst_conv}     fst (a,b) = a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1027
\tdx{snd_conv}     snd (a,b) = b
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1028
\tdx{surjective_pairing}  p = (fst p,snd p)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1029
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1030
\tdx{split}        split c (a,b) = c a b
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1031
\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
  1032
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1033
\tdx{SigmaI}    [| a:A;  b:B a |] ==> (a,b) : Sigma A B
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1034
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1035
\tdx{SigmaE}    [| c:Sigma A B; !!x y.[| x:A; y:B x; c=(x,y) |] ==> P 
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1036
          |] ==> P
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1037
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1038
\caption{Type $\alpha\times\beta$}\label{hol-prod}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1039
\end{figure} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1040
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1041
Theory \thydx{Prod} (Fig.\ts\ref{hol-prod}) defines the product type
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1042
$\alpha\times\beta$, with the ordered pair syntax $(a, b)$.  General
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1043
tuples are simulated by pairs nested to the right:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1044
\begin{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1045
\begin{tabular}{c|c}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1046
external & internal \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1047
\hline
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1048
$\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
  1049
\hline
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1050
$(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
  1051
\end{tabular}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1052
\end{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1053
In addition, it is possible to use tuples
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1054
as patterns in abstractions:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1055
\begin{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1056
{\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
  1057
\end{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1058
Nested patterns are also supported.  They are translated stepwise:
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1059
\begin{eqnarray*}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1060
\hbox{\tt\%($x$,$y$,$z$).\ $t$} 
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1061
   & \leadsto & \hbox{\tt\%($x$,($y$,$z$)).\ $t$} \\
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1062
   & \leadsto & \hbox{\tt split(\%$x$.\%($y$,$z$).\ $t$)}\\
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1063
   & \leadsto & \hbox{\tt split(\%$x$.\ split(\%$y$ $z$.\ $t$))}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1064
\end{eqnarray*}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1065
The reverse translation is performed upon printing.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1066
\begin{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1067
  The translation between patterns and \texttt{split} is performed automatically
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1068
  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
  1069
  may differ, which can affects proofs.  For example the term {\tt
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1070
  (\%(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
  1071
  default simpset) to rewrite to {\tt(b,a)}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1072
\end{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1073
In addition to explicit $\lambda$-abstractions, patterns can be used in any
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1074
variable binding construct which is internally described by a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1075
$\lambda$-abstraction.  Some important examples are
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1076
\begin{description}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1077
\item[Let:] \texttt{let {\it pattern} = $t$ in $u$}
10109
dcb72400bc32 record proof tools: t.equality;
wenzelm
parents: 10052
diff changeset
  1078
\item[Quantifiers:] \texttt{ALL~{\it pattern}:$A$.~$P$}
dcb72400bc32 record proof tools: t.equality;
wenzelm
parents: 10052
diff changeset
  1079
\item[Choice:] {\underscoreon \tt SOME~{\it pattern}.~$P$}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1080
\item[Set operations:] \texttt{UN~{\it pattern}:$A$.~$B$}
10109
dcb72400bc32 record proof tools: t.equality;
wenzelm
parents: 10052
diff changeset
  1081
\item[Sets:] \texttt{{\ttlbrace}{\it pattern}.~$P${\ttrbrace}}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1082
\end{description}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1083
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1084
There is a simple tactic which supports reasoning about patterns:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1085
\begin{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1086
\item[\ttindexbold{split_all_tac} $i$] replaces in subgoal $i$ all
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1087
  {\tt!!}-quantified variables of product type by individual variables for
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1088
  each component.  A simple example:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1089
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1090
{\out 1. !!p. (\%(x,y,z). (x, y, z)) p = p}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1091
by(split_all_tac 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1092
{\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
  1093
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1094
\end{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1095
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1096
Theory \texttt{Prod} also introduces the degenerate product type \texttt{unit}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1097
which contains only a single element named {\tt()} with the property
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1098
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1099
\tdx{unit_eq}       u = ()
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1100
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1101
\bigskip
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1102
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1103
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
  1104
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
  1105
\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
  1106
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1107
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
  1108
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
  1109
respective theory files. Although the sum and product types are
01bb8abb5a91 Some changes in sections about Sum and Nat.
berghofe
parents: 7283
diff changeset
  1110
constructed manually for foundational reasons, they are represented as
42909
66b189dc5b83 updated and re-unified HOL rep_datatype;
wenzelm
parents: 42907
diff changeset
  1111
actual datatypes later.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1112
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1113
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1114
\begin{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1115
  \it symbol    & \it meta-type &           & \it description \\ 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1116
  \cdx{Inl}     & $\alpha \To \alpha+\beta$    & & first injection\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1117
  \cdx{Inr}     & $\beta \To \alpha+\beta$     & & second injection\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1118
  \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
  1119
        & & conditional
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1120
\end{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1121
\begin{ttbox}\makeatletter
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1122
\tdx{Inl_not_Inr}    Inl a ~= Inr b
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1123
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1124
\tdx{inj_Inl}        inj Inl
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1125
\tdx{inj_Inr}        inj Inr
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1126
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1127
\tdx{sumE}           [| !!x. P(Inl x);  !!y. P(Inr y) |] ==> P s
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
\tdx{sum_case_Inl}   sum_case f g (Inl x) = f x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1130
\tdx{sum_case_Inr}   sum_case f g (Inr x) = g x
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1131
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1132
\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
  1133
\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
  1134
                                     (! y. s = Inr(y) --> R(g(y))))
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1135
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1136
\caption{Type $\alpha+\beta$}\label{hol-sum}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1137
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1138
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1139
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1140
\index{*"< symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1141
\index{*"* symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1142
\index{*div symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1143
\index{*mod symbol}
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1144
\index{*dvd symbol}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1145
\index{*"+ symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1146
\index{*"- symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1147
\begin{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1148
  \it symbol    & \it meta-type & \it priority & \it description \\ 
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1149
  \cdx{0}       & $\alpha$  & & zero \\
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1150
  \cdx{Suc}     & $nat \To nat$ & & successor function\\
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1151
  \tt *    & $[\alpha,\alpha]\To \alpha$    &  Left 70 & multiplication \\
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1152
  \tt div  & $[\alpha,\alpha]\To \alpha$    &  Left 70 & division\\
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1153
  \tt mod  & $[\alpha,\alpha]\To \alpha$    &  Left 70 & modulus\\
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1154
  \tt dvd  & $[\alpha,\alpha]\To bool$     &  Left 70 & ``divides'' relation\\
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1155
  \tt +    & $[\alpha,\alpha]\To \alpha$    &  Left 65 & addition\\
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1156
  \tt -    & $[\alpha,\alpha]\To \alpha$    &  Left 65 & subtraction
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1157
\end{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1158
\subcaption{Constants and infixes}
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
\begin{ttbox}\makeatother
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1161
\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
  1162
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1163
\tdx{Suc_not_Zero}   Suc m ~= 0
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1164
\tdx{inj_Suc}        inj Suc
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1165
\tdx{n_not_Suc_n}    n~=Suc n
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1166
\subcaption{Basic properties}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1167
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1168
\caption{The type of natural numbers, \tydx{nat}} \label{hol-nat1}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1169
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1170
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1171
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1172
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1173
\begin{ttbox}\makeatother
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1174
              0+n           = n
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1175
              (Suc m)+n     = Suc(m+n)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1176
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1177
              m-0           = m
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1178
              0-n           = n
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1179
              Suc(m)-Suc(n) = m-n
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1180
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1181
              0*n           = 0
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1182
              Suc(m)*n      = n + m*n
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1183
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1184
\tdx{mod_less}      m<n ==> m mod n = m
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1185
\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
  1186
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1187
\tdx{div_less}      m<n ==> m div n = 0
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1188
\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
  1189
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1190
\caption{Recursion equations for the arithmetic operators} \label{hol-nat2}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1191
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1192
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1193
\subsection{The type of natural numbers, \textit{nat}}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1194
\index{nat@{\textit{nat}} type|(}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1195
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1196
The theory \thydx{Nat} defines the natural numbers in a roundabout but
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1197
traditional way.  The axiom of infinity postulates a type~\tydx{ind} of
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1198
individuals, which is non-empty and closed under an injective operation.  The
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1199
natural numbers are inductively generated by choosing an arbitrary individual
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1200
for~0 and using the injective operation to take successors.  This is a least
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1201
fixedpoint construction.  
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1202
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1203
Type~\tydx{nat} is an instance of class~\cldx{ord}, which makes the overloaded
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1204
functions of this class (especially \cdx{<} and \cdx{<=}, but also \cdx{min},
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1205
\cdx{max} and \cdx{LEAST}) available on \tydx{nat}.  Theory \thydx{Nat} 
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1206
also shows that {\tt<=} is a linear order, so \tydx{nat} is
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1207
also an instance of class \cldx{linorder}.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1208
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1209
Theory \thydx{NatArith} develops arithmetic on the natural numbers.  It defines
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1210
addition, multiplication and subtraction.  Theory \thydx{Divides} defines
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1211
division, remainder and the ``divides'' relation.  The numerous theorems
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1212
proved include commutative, associative, distributive, identity and
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1213
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
  1214
recursion equations for the operators \texttt{+}, \texttt{-} and \texttt{*} on
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1215
\texttt{nat} are part of the default simpset.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1216
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1217
Functions on \tydx{nat} can be defined by primitive or well-founded recursion;
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1218
see {\S}\ref{sec:HOL:recursive}.  A simple example is addition.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1219
Here, \texttt{op +} is the name of the infix operator~\texttt{+}, following
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1220
the standard convention.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1221
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1222
\sdx{primrec}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1223
      "0 + n = n"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1224
  "Suc m + n = Suc (m + n)"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1225
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1226
There is also a \sdx{case}-construct
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1227
of the form
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1228
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1229
case \(e\) of 0 => \(a\) | Suc \(m\) => \(b\)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1230
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1231
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
  1232
the order of the two cases.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1233
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
  1234
\cdx{nat_rec}, which is available because \textit{nat} is represented as
42909
66b189dc5b83 updated and re-unified HOL rep_datatype;
wenzelm
parents: 42907
diff changeset
  1235
a datatype.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1236
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1237
%The predecessor relation, \cdx{pred_nat}, is shown to be well-founded.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1238
%Recursion along this relation resembles primitive recursion, but is
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1239
%stronger because we are in higher-order logic; using primitive recursion to
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1240
%define a higher-order function, we can easily Ackermann's function, which
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1241
%is not primitive recursive \cite[page~104]{thompson91}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1242
%The transitive closure of \cdx{pred_nat} is~$<$.  Many functions on the
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1243
%natural numbers are most easily expressed using recursion along~$<$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1244
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1245
Tactic {\tt\ttindex{induct_tac} "$n$" $i$} performs induction on variable~$n$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1246
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
  1247
theorem \tdx{less_induct}:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1248
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1249
[| !!n. [| ! m. m<n --> P m |] ==> P n |]  ==>  P n
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1250
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1251
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1252
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1253
\subsection{Numerical types and numerical reasoning}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1254
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
  1255
The integers (type \tdx{int}) are also available in HOL, and the reals (type
14024
213dcc39358f HOL-Real -> HOL-Complex
kleing
parents: 14013
diff changeset
  1256
\tdx{real}) are available in the logic image \texttt{HOL-Complex}.  They support
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1257
the expected operations of addition (\texttt{+}), subtraction (\texttt{-}) and
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1258
multiplication (\texttt{*}), and much else.  Type \tdx{int} provides the
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1259
\texttt{div} and \texttt{mod} operators, while type \tdx{real} provides real
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1260
division and other operations.  Both types belong to class \cldx{linorder}, so
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1261
they inherit the relational operators and all the usual properties of linear
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1262
orderings.  For full details, please survey the theories in subdirectories
14024
213dcc39358f HOL-Real -> HOL-Complex
kleing
parents: 14013
diff changeset
  1263
\texttt{Integ}, \texttt{Real}, and \texttt{Complex}.
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1264
13012
f8bfc61ee1b5 hide SVC stuff (outdated);
wenzelm
parents: 13008
diff changeset
  1265
All three numeric types admit numerals of the form \texttt{$sd\ldots d$},
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1266
where $s$ is an optional minus sign and $d\ldots d$ is a string of digits.
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1267
Numerals are represented internally by a datatype for binary notation, which
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1268
allows numerical calculations to be performed by rewriting.  For example, the
13012
f8bfc61ee1b5 hide SVC stuff (outdated);
wenzelm
parents: 13008
diff changeset
  1269
integer division of \texttt{54342339} by \texttt{3452} takes about five
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1270
seconds.  By default, the simplifier cancels like terms on the opposite sites
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1271
of relational operators (reducing \texttt{z+x<x+y} to \texttt{z<y}, for
13012
f8bfc61ee1b5 hide SVC stuff (outdated);
wenzelm
parents: 13008
diff changeset
  1272
instance.  The simplifier also collects like terms, replacing \texttt{x+y+x*3}
f8bfc61ee1b5 hide SVC stuff (outdated);
wenzelm
parents: 13008
diff changeset
  1273
by \texttt{4*x+y}.
f8bfc61ee1b5 hide SVC stuff (outdated);
wenzelm
parents: 13008
diff changeset
  1274
f8bfc61ee1b5 hide SVC stuff (outdated);
wenzelm
parents: 13008
diff changeset
  1275
Sometimes numerals are not wanted, because for example \texttt{n+3} does not
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1276
match a pattern of the form \texttt{Suc $k$}.  You can re-arrange the form of
13012
f8bfc61ee1b5 hide SVC stuff (outdated);
wenzelm
parents: 13008
diff changeset
  1277
an arithmetic expression by proving (via \texttt{subgoal_tac}) a lemma such as
f8bfc61ee1b5 hide SVC stuff (outdated);
wenzelm
parents: 13008
diff changeset
  1278
\texttt{n+3 = Suc (Suc (Suc n))}.  As an alternative, you can disable the
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1279
fancier simplifications by using a basic simpset such as \texttt{HOL_ss}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1280
rather than the default one, \texttt{simpset()}.
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1281
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1282
Reasoning about arithmetic inequalities can be tedious.  Fortunately, HOL
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1283
provides a decision procedure for \emph{linear arithmetic}: formulae involving
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1284
addition and subtraction. The simplifier invokes a weak version of this
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1285
decision procedure automatically. If this is not sufficent, you can invoke the
31101
26c7bb764a38 qualified names for Lin_Arith tactics and simprocs
haftmann
parents: 30686
diff changeset
  1286
full procedure \ttindex{Lin_Arith.tac} explicitly.  It copes with arbitrary
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1287
formulae involving {\tt=}, {\tt<}, {\tt<=}, {\tt+}, {\tt-}, {\tt Suc}, {\tt
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1288
  min}, {\tt max} and numerical constants. Other subterms are treated as
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1289
atomic, while subformulae not involving numerical types are ignored. Quantified
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1290
subformulae are ignored unless they are positive universal or negative
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1291
existential. The running time is exponential in the number of
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1292
occurrences of {\tt min}, {\tt max}, and {\tt-} because they require case
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1293
distinctions.
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1294
If {\tt k} is a numeral, then {\tt div k}, {\tt mod k} and
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1295
{\tt k dvd} are also supported. The former two are eliminated
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1296
by case distinctions, again blowing up the running time.
31101
26c7bb764a38 qualified names for Lin_Arith tactics and simprocs
haftmann
parents: 30686
diff changeset
  1297
If the formula involves explicit quantifiers, \texttt{Lin_Arith.tac} may take
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1298
super-exponential time and space.
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1299
31101
26c7bb764a38 qualified names for Lin_Arith tactics and simprocs
haftmann
parents: 30686
diff changeset
  1300
If \texttt{Lin_Arith.tac} fails, try to find relevant arithmetic results in
22921
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 17662
diff changeset
  1301
the library.  The theories \texttt{Nat} and \texttt{NatArith} contain
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 17662
diff changeset
  1302
theorems about {\tt<}, {\tt<=}, \texttt{+}, \texttt{-} and \texttt{*}.
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 17662
diff changeset
  1303
Theory \texttt{Divides} contains theorems about \texttt{div} and
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 17662
diff changeset
  1304
\texttt{mod}.  Use Proof General's \emph{find} button (or other search
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 17662
diff changeset
  1305
facilities) to locate them.
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1306
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1307
\index{nat@{\textit{nat}} type|)}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1308
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1309
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1310
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1311
\index{#@{\tt[]} symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1312
\index{#@{\tt\#} symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1313
\index{"@@{\tt\at} symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1314
\index{*"! symbol}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1315
\begin{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1316
  \it symbol & \it meta-type & \it priority & \it description \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1317
  \tt[]    & $\alpha\,list$ & & empty list\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1318
  \tt \#   & $[\alpha,\alpha\,list]\To \alpha\,list$ & Right 65 & 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1319
        list constructor \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1320
  \cdx{null}    & $\alpha\,list \To bool$ & & emptiness test\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1321
  \cdx{hd}      & $\alpha\,list \To \alpha$ & & head \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1322
  \cdx{tl}      & $\alpha\,list \To \alpha\,list$ & & tail \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1323
  \cdx{last}    & $\alpha\,list \To \alpha$ & & last element \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1324
  \cdx{butlast} & $\alpha\,list \To \alpha\,list$ & & drop last element \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1325
  \tt\at  & $[\alpha\,list,\alpha\,list]\To \alpha\,list$ & Left 65 & append \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1326
  \cdx{map}     & $(\alpha\To\beta) \To (\alpha\,list \To \beta\,list)$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1327
        & & apply to all\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1328
  \cdx{filter}  & $(\alpha \To bool) \To (\alpha\,list \To \alpha\,list)$
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1329
        & & filter functional\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1330
  \cdx{set}& $\alpha\,list \To \alpha\,set$ & & elements\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1331
  \sdx{mem}  & $\alpha \To \alpha\,list \To bool$  &  Left 55   & membership\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1332
  \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
  1333
  & iteration \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1334
  \cdx{concat}   & $(\alpha\,list)list\To \alpha\,list$ & & concatenation \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1335
  \cdx{rev}     & $\alpha\,list \To \alpha\,list$ & & reverse \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1336
  \cdx{length}  & $\alpha\,list \To nat$ & & length \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1337
  \tt! & $\alpha\,list \To nat \To \alpha$ & Left 100 & indexing \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1338
  \cdx{take}, \cdx{drop} & $nat \To \alpha\,list \To \alpha\,list$ &&
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1339
    take/drop a prefix \\
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1340
  \cdx{takeWhile},\\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1341
  \cdx{dropWhile} &
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1342
    $(\alpha \To bool) \To \alpha\,list \To \alpha\,list$ &&
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1343
    take/drop a prefix
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1344
\end{constants}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1345
\subcaption{Constants and infixes}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1346
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1347
\begin{center} \tt\frenchspacing
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1348
\begin{tabular}{rrr} 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1349
  \it external        & \it internal  & \it description \\{}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1350
  [$x@1$, $\dots$, $x@n$]  &  $x@1$ \# $\cdots$ \# $x@n$ \# [] &
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1351
        \rm finite list \\{}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1352
  [$x$:$l$. $P$]  & filter ($\lambda x{.}P$) $l$ & 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1353
        \rm list comprehension
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1354
\end{tabular}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1355
\end{center}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1356
\subcaption{Translations}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1357
\caption{The theory \thydx{List}} \label{hol-list}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1358
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1359
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1360
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1361
\begin{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1362
\begin{ttbox}\makeatother
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1363
null [] = True
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1364
null (x#xs) = False
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1365
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1366
hd (x#xs) = x
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1367
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1368
tl (x#xs) = xs
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1369
tl [] = []
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1370
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1371
[] @ ys = ys
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1372
(x#xs) @ ys = x # xs @ ys
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1373
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1374
set [] = \ttlbrace\ttrbrace
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1375
set (x#xs) = insert x (set xs)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1376
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1377
x mem [] = False
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1378
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
  1379
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1380
concat([]) = []
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1381
concat(x#xs) = x @ concat(xs)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1382
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1383
rev([]) = []
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1384
rev(x#xs) = rev(xs) @ [x]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1385
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1386
length([]) = 0
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1387
length(x#xs) = Suc(length(xs))
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1388
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1389
xs!0 = hd xs
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1390
xs!(Suc n) = (tl xs)!n
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1391
\end{ttbox}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1392
\caption{Simple list processing functions}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1393
\label{fig:HOL:list-simps}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1394
\end{figure}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1395
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1396
\begin{figure}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1397
\begin{ttbox}\makeatother
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1398
map f [] = []
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1399
map f (x#xs) = f x # map f xs
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1400
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1401
filter P [] = []
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1402
filter P (x#xs) = (if P x then x#filter P xs else filter P xs)
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1403
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1404
foldl f a [] = a
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1405
foldl f a (x#xs) = foldl f (f a x) xs
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1406
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1407
take n [] = []
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1408
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
  1409
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1410
drop n [] = []
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1411
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
  1412
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1413
takeWhile P [] = []
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1414
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
  1415
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1416
dropWhile P [] = []
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1417
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
  1418
\end{ttbox}
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1419
\caption{Further list processing functions}
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1420
\label{fig:HOL:list-simps2}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1421
\end{figure}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1422
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1423
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1424
\subsection{The type constructor for lists, \textit{list}}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1425
\label{subsec:list}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1426
\index{list@{\textit{list}} type|(}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1427
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1428
Figure~\ref{hol-list} presents the theory \thydx{List}: the basic list
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1429
operations with their types and syntax.  Type $\alpha \; list$ is
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1430
defined as a \texttt{datatype} with the constructors {\tt[]} and {\tt\#}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1431
As a result the generic structural induction and case analysis tactics
8424
a1a41257f45f exhaust -> cases
nipkow
parents: 7846
diff changeset
  1432
\texttt{induct\_tac} and \texttt{cases\_tac} also become available for
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1433
lists.  A \sdx{case} construct of the form
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1434
\begin{center}\tt
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1435
case $e$ of [] => $a$  |  \(x\)\#\(xs\) => b
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1436
\end{center}
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1437
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
  1438
is also a case splitting rule \tdx{split_list_case}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1439
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1440
\begin{array}{l}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1441
P(\mathtt{case}~e~\mathtt{of}~\texttt{[] =>}~a ~\texttt{|}~
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1442
               x\texttt{\#}xs~\texttt{=>}~f~x~xs) ~= \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1443
((e = \texttt{[]} \to P(a)) \land
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1444
 (\forall x~ xs. e = x\texttt{\#}xs \to P(f~x~xs)))
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1445
\end{array}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1446
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1447
which can be fed to \ttindex{addsplits} just like
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1448
\texttt{split_if} (see~{\S}\ref{subsec:HOL:case:splitting}).
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1449
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1450
\texttt{List} provides a basic library of list processing functions defined by
42912
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1451
primitive recursion.  The recursion equations
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1452
are shown in Figs.\ts\ref{fig:HOL:list-simps} and~\ref{fig:HOL:list-simps2}.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1453
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1454
\index{list@{\textit{list}} type|)}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1455
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1456
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1457
\section{Datatype definitions}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1458
\label{sec:HOL:datatype}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1459
\index{*datatype|(}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1460
6626
wenzelm
parents: 6620
diff changeset
  1461
Inductive datatypes, similar to those of \ML, frequently appear in
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1462
applications of Isabelle/HOL.  In principle, such types could be defined by
42907
dfd4ef8e73f6 updated and re-unified HOL typedef, with some live examples;
wenzelm
parents: 42673
diff changeset
  1463
hand via \texttt{typedef}, but this would be far too
6626
wenzelm
parents: 6620
diff changeset
  1464
tedious.  The \ttindex{datatype} definition package of Isabelle/HOL (cf.\ 
wenzelm
parents: 6620
diff changeset
  1465
\cite{Berghofer-Wenzel:1999:TPHOL}) automates such chores.  It generates an
wenzelm
parents: 6620
diff changeset
  1466
appropriate \texttt{typedef} based on a least fixed-point construction, and
wenzelm
parents: 6620
diff changeset
  1467
proves freeness theorems and induction rules, as well as theorems for
wenzelm
parents: 6620
diff changeset
  1468
recursion and case combinators.  The user just has to give a simple
wenzelm
parents: 6620
diff changeset
  1469
specification of new inductive types using a notation similar to {\ML} or
wenzelm
parents: 6620
diff changeset
  1470
Haskell.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1471
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1472
The current datatype package can handle both mutual and indirect recursion.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1473
It also offers to represent existing types as datatypes giving the advantage
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1474
of a more uniform view on standard theories.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1475
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
\subsection{Basics}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1478
\label{subsec:datatype:basics}
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
A general \texttt{datatype} definition is of the following form:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1481
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1482
\begin{array}{llcl}
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1483
\mathtt{datatype} & (\vec{\alpha})t@1 & = &
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1484
  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
  1485
    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
  1486
 & & \vdots \\
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1487
\mathtt{and} & (\vec{\alpha})t@n & = &
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1488
  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
  1489
    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
  1490
\end{array}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1491
\]
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1492
where $\vec{\alpha} = (\alpha@1,\ldots,\alpha@h)$ is a list of type variables,
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1493
$C^j@i$ are distinct constructor names and $\tau^j@{i,i'}$ are {\em
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1494
  admissible} types containing at most the type variables $\alpha@1, \ldots,
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1495
\alpha@h$. A type $\tau$ occurring in a \texttt{datatype} definition is {\em
9258
2121ff73a37d fixed typos reported by Jeremy Dawson
paulson
parents: 9212
diff changeset
  1496
  admissible} if and only if
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1497
\begin{itemize}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1498
\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
  1499
newly defined type constructors $t@1,\ldots,t@n$, or
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1500
\item $\tau = (\vec{\alpha})t@{j'}$ where $1 \leq j' \leq n$, or
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1501
\item $\tau = (\tau'@1,\ldots,\tau'@{h'})t'$, where $t'$ is
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1502
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
  1503
are admissible types.
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1504
\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
  1505
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
  1506
types are {\em strictly positive})
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1507
\end{itemize}
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1508
If some $(\vec{\alpha})t@{j'}$ occurs in a type $\tau^j@{i,i'}$
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1509
of the form
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1510
\[
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1511
(\ldots,\ldots ~ (\vec{\alpha})t@{j'} ~ \ldots,\ldots)t'
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1512
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1513
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
  1514
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
  1515
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1516
datatype 'a list = Nil
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1517
                 | Cons 'a ('a list)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1518
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1519
Arithmetic expressions \texttt{aexp} and boolean expressions \texttt{bexp} can be modelled
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1520
by the mutually recursive datatype definition
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1521
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1522
datatype 'a aexp = If_then_else ('a bexp) ('a aexp) ('a aexp)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1523
                 | Sum ('a aexp) ('a aexp)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1524
                 | Diff ('a aexp) ('a aexp)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1525
                 | Var 'a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1526
                 | Num nat
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1527
and      'a bexp = Less ('a aexp) ('a aexp)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1528
                 | And ('a bexp) ('a bexp)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1529
                 | Or ('a bexp) ('a bexp)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1530
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1531
The datatype \texttt{term}, which is defined by
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1532
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1533
datatype ('a, 'b) term = Var 'a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1534
                       | App 'b ((('a, 'b) term) list)
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1535
\end{ttbox}
7044
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1536
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
  1537
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
  1538
\begin{ttbox}
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1539
datatype 'a tree = Atom 'a | Branch "nat => 'a tree"
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1540
\end{ttbox}
6580
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
\medskip
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1543
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1544
Types in HOL must be non-empty. Each of the new datatypes
9258
2121ff73a37d fixed typos reported by Jeremy Dawson
paulson
parents: 9212
diff changeset
  1545
$(\vec{\alpha})t@j$ with $1 \leq j \leq n$ is non-empty if and only if it has a
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1546
constructor $C^j@i$ with the following property: for all argument types
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1547
$\tau^j@{i,i'}$ of the form $(\vec{\alpha})t@{j'}$ the datatype
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1548
$(\vec{\alpha})t@{j'}$ is non-empty.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1549
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1550
If there are no nested occurrences of the newly defined datatypes, obviously
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1551
at least one of the newly defined datatypes $(\vec{\alpha})t@j$
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1552
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
  1553
  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
  1554
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
  1555
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
  1556
  list)} is non-empty as well.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1557
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1558
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1559
\subsubsection{Freeness of the constructors}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1560
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1561
The datatype constructors are automatically defined as functions of their
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1562
respective type:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1563
\[ 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
  1564
These functions have certain {\em freeness} properties.  They construct
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1565
distinct values:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1566
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1567
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
  1568
\mbox{for all}~ i \neq i'.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1569
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1570
The constructor functions are injective:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1571
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1572
(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
  1573
(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
  1574
\]
7044
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1575
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
  1576
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
  1577
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
  1578
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
  1579
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
  1580
\texttt{DatatypePackage.distinct_simproc}.}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1581
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1582
\subsubsection{Structural induction}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1583
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1584
The datatype package also provides structural induction rules.  For
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1585
datatypes without nested recursion, this is of the following form:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1586
\[
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1587
\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
  1588
  {\begin{array}{lcl}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1589
     \Forall x@1 \dots x@{m^1@1}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1590
       \List{P@{s^1@{1,1}}~x@{r^1@{1,1}}; \dots;
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1591
         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
  1592
           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
  1593
     & \vdots \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1594
     \Forall x@1 \dots x@{m^1@{k@1}}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1595
       \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
  1596
         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
  1597
           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
  1598
     & \vdots \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1599
     \Forall x@1 \dots x@{m^n@1}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1600
       \List{P@{s^n@{1,1}}~x@{r^n@{1,1}}; \dots;
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1601
         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
  1602
           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
  1603
     & \vdots \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1604
     \Forall x@1 \dots x@{m^n@{k@n}}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1605
       \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
  1606
         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
  1607
           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
  1608
   \end{array}}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1609
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1610
where
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1611
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1612
\begin{array}{rcl}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1613
Rec^j@i & := &
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1614
   \left\{\left(r^j@{i,1},s^j@{i,1}\right),\ldots,
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1615
     \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
  1616
&& \left\{(i',i'')~\left|~
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1617
     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
  1618
       \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
  1619
\end{array}
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
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
  1622
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1623
For datatypes with nested recursion, such as the \texttt{term} example from
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1624
above, things are a bit more complicated.  Conceptually, Isabelle/HOL unfolds
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1625
a definition like
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1626
\begin{ttbox}
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1627
datatype ('a,'b) term = Var 'a
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1628
                      | App 'b ((('a, 'b) term) list)
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1629
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1630
to an equivalent definition without nesting:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1631
\begin{ttbox}
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1632
datatype ('a,'b) term      = Var
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1633
                           | App 'b (('a, 'b) term_list)
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1634
and      ('a,'b) term_list = Nil'
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1635
                           | Cons' (('a,'b) term) (('a,'b) term_list)
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1636
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1637
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
  1638
  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
  1639
the original (isomorphic) type \texttt{(('a, 'b) term) list} and its existing
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1640
constructors \texttt{Nil} and \texttt{Cons}. Thus, the structural induction rule for
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1641
\texttt{term} gets the form
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1642
\[
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1643
\infer{P@1~x@1 \land P@2~x@2}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1644
  {\begin{array}{l}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1645
     \Forall x.~P@1~(\mathtt{Var}~x) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1646
     \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
  1647
     P@2~\mathtt{Nil} \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1648
     \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
  1649
   \end{array}}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1650
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1651
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
  1652
and one for the type \texttt{(('a, 'b) term) list}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1653
7044
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1654
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
  1655
is of the form
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1656
\[
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1657
\infer{P~t}
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1658
  {\Forall a.~P~(\mathtt{Atom}~a) &
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1659
   \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
  1660
\]
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1661
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1662
\medskip In principle, inductive types are already fully determined by
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1663
freeness and structural induction.  For convenience in applications,
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1664
the following derived constructions are automatically provided for any
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1665
datatype.
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
\subsubsection{The \sdx{case} construct}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1668
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1669
The type comes with an \ML-like \texttt{case}-construct:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1670
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1671
\begin{array}{rrcl}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1672
\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
  1673
                           \vdots \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1674
                           \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
  1675
\end{array}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1676
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1677
where the $x@{i,j}$ are either identifiers or nested tuple patterns as in
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1678
{\S}\ref{subsec:prod-sum}.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1679
\begin{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1680
  All constructors must be present, their order is fixed, and nested patterns
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1681
  are not supported (with the exception of tuples).  Violating this
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1682
  restriction results in strange error messages.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1683
\end{warn}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1684
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1685
To perform case distinction on a goal containing a \texttt{case}-construct,
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1686
the theorem $t@j.$\texttt{split} is provided:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1687
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1688
\begin{array}{@{}rcl@{}}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1689
P(t@j_\mathtt{case}~f@1~\dots~f@{k@j}~e) &\!\!\!=&
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1690
\!\!\! ((\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
  1691
                             P(f@1~x@1\dots x@{m^j@1})) \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1692
&&\!\!\! ~\land~ \dots ~\land \\
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1693
&&~\!\!\! (\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
  1694
                             P(f@{k@j}~x@1\dots x@{m^j@{k@j}})))
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1695
\end{array}
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
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
  1698
This theorem can be added to a simpset via \ttindex{addsplits}
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1699
(see~{\S}\ref{subsec:HOL:case:splitting}).
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1700
10109
dcb72400bc32 record proof tools: t.equality;
wenzelm
parents: 10052
diff changeset
  1701
Case splitting on assumption works as well, by using the rule
dcb72400bc32 record proof tools: t.equality;
wenzelm
parents: 10052
diff changeset
  1702
$t@j.$\texttt{split_asm} in the same manner.  Both rules are available under
dcb72400bc32 record proof tools: t.equality;
wenzelm
parents: 10052
diff changeset
  1703
$t@j.$\texttt{splits} (this name is \emph{not} bound in ML, though).
dcb72400bc32 record proof tools: t.equality;
wenzelm
parents: 10052
diff changeset
  1704
8604
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1705
\begin{warn}\index{simplification!of \texttt{case}}%
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1706
  By default only the selector expression ($e$ above) in a
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1707
  \texttt{case}-construct is simplified, in analogy with \texttt{if} (see
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1708
  page~\pageref{if-simp}). Only if that reduces to a constructor is one of
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1709
  the arms of the \texttt{case}-construct exposed and simplified. To ensure
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1710
  full simplification of all parts of a \texttt{case}-construct for datatype
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1711
  $t$, remove $t$\texttt{.}\ttindexbold{case_weak_cong} from the simpset, for
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1712
  example by \texttt{delcongs [thm "$t$.weak_case_cong"]}.
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1713
\end{warn}
c99e0024050c *** empty log message ***
nipkow
parents: 8443
diff changeset
  1714
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1715
\subsubsection{The function \cdx{size}}\label{sec:HOL:size}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1716
15455
735dd4260500 updated description of arith_tac
paulson
parents: 14024
diff changeset
  1717
Theory \texttt{NatArith} declares a generic function \texttt{size} of type
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1718
$\alpha\To nat$.  Each datatype defines a particular instance of \texttt{size}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1719
by overloading according to the following scheme:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1720
%%% FIXME: This formula is too big and is completely unreadable
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1721
\[
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1722
size(C^j@i~x@1~\dots~x@{m^j@i}) = \!
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1723
\left\{
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1724
\begin{array}{ll}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1725
0 & \!\mbox{if $Rec^j@i = \emptyset$} \\
7044
193a8601fabd Documented usage of function types in datatype specifications.
berghofe
parents: 6626
diff changeset
  1726
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
  1727
 \!\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
  1728
  \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
  1729
\end{array}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1730
\right.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1731
\]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1732
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
  1733
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
  1734
subtrees ${}+1$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1735
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1736
\subsection{Defining datatypes}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1737
42628
50f257ea2aba removed obsolete rail diagrams (which were about old-style theory syntax);
wenzelm
parents: 42627
diff changeset
  1738
The theory syntax for datatype definitions is given in the
50f257ea2aba removed obsolete rail diagrams (which were about old-style theory syntax);
wenzelm
parents: 42627
diff changeset
  1739
Isabelle/Isar reference manual.  In order to be well-formed, a
50f257ea2aba removed obsolete rail diagrams (which were about old-style theory syntax);
wenzelm
parents: 42627
diff changeset
  1740
datatype definition has to obey the rules stated in the previous
50f257ea2aba removed obsolete rail diagrams (which were about old-style theory syntax);
wenzelm
parents: 42627
diff changeset
  1741
section.  As a result the theory is extended with the new types, the
50f257ea2aba removed obsolete rail diagrams (which were about old-style theory syntax);
wenzelm
parents: 42627
diff changeset
  1742
constructors, and the theorems listed in the previous section.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1743
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1744
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
  1745
you never need to see them again because the simplifier applies them
8424
a1a41257f45f exhaust -> cases
nipkow
parents: 7846
diff changeset
  1746
automatically.  Only induction or case distinction are usually invoked by hand.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1747
\begin{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1748
\item[\ttindexbold{induct_tac} {\tt"}$x${\tt"} $i$]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1749
 applies structural induction on variable $x$ to subgoal $i$, provided the
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1750
 type of $x$ is a datatype.
7846
adf6b1112bc1 Eliminated mutual_induct_tac.
berghofe
parents: 7830
diff changeset
  1751
\item[\texttt{induct_tac}
adf6b1112bc1 Eliminated mutual_induct_tac.
berghofe
parents: 7830
diff changeset
  1752
  {\tt"}$x@1$ $\ldots$ $x@n${\tt"} $i$] applies simultaneous
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1753
  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
  1754
  is the canonical way to prove properties of mutually recursive datatypes
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1755
  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
  1756
  \texttt{term}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1757
\end{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1758
In some cases, induction is overkill and a case distinction over all
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1759
constructors of the datatype suffices.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1760
\begin{ttdescription}
8443
0ed4b608ba4b renamed cases_tac to case_tac;
wenzelm
parents: 8424
diff changeset
  1761
\item[\ttindexbold{case_tac} {\tt"}$u${\tt"} $i$]
8424
a1a41257f45f exhaust -> cases
nipkow
parents: 7846
diff changeset
  1762
 performs a case analysis for the term $u$ whose type  must be a datatype.
a1a41257f45f exhaust -> cases
nipkow
parents: 7846
diff changeset
  1763
 If the datatype has $k@j$ constructors  $C^j@1$, \dots $C^j@{k@j}$, subgoal
a1a41257f45f exhaust -> cases
nipkow
parents: 7846
diff changeset
  1764
 $i$ is replaced by $k@j$ new subgoals which  contain the additional
a1a41257f45f exhaust -> cases
nipkow
parents: 7846
diff changeset
  1765
 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
  1766
\end{ttdescription}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1767
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1768
Note that induction is only allowed on free variables that should not occur
8424
a1a41257f45f exhaust -> cases
nipkow
parents: 7846
diff changeset
  1769
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
  1770
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1771
\bigskip
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
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1774
For the technically minded, we exhibit some more details.  Processing the
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1775
theory file produces an \ML\ structure which, in addition to the usual
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1776
components, contains a structure named $t$ for each datatype $t$ defined in
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1777
the file.  Each structure $t$ contains the following elements:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1778
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1779
val distinct : thm list
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1780
val inject : thm list
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1781
val induct : thm
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1782
val exhaust : thm
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1783
val cases : thm list
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1784
val split : thm
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1785
val split_asm : thm
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1786
val recs : thm list
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1787
val size : thm list
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1788
val simps : thm list
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1789
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1790
\texttt{distinct}, \texttt{inject}, \texttt{induct}, \texttt{size}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1791
and \texttt{split} contain the theorems
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1792
described above.  For user convenience, \texttt{distinct} contains
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1793
inequalities in both directions.  The reduction rules of the {\tt
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1794
  case}-construct are in \texttt{cases}.  All theorems from {\tt
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1795
  distinct}, \texttt{inject} and \texttt{cases} are combined in \texttt{simps}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1796
In case of mutually recursive datatypes, \texttt{recs}, \texttt{size}, \texttt{induct}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1797
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
  1798
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1799
42912
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1800
\section{Old-style recursive function definitions}\label{sec:HOL:recursive}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1801
\index{recursion!general|(}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1802
\index{*recdef|(}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1803
42912
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1804
Old-style recursive definitions via \texttt{recdef} requires that you
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1805
supply a well-founded relation that governs the recursion.  Recursive
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1806
calls are only allowed if they make the argument decrease under the
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1807
relation.  Complicated recursion forms, such as nested recursion, can
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1808
be dealt with.  Termination can even be proved at a later time, though
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1809
having unsolved termination conditions around can make work
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1810
difficult.%
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1811
\footnote{This facility is based on Konrad Slind's TFL
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1812
  package~\cite{slind-tfl}.  Thanks are due to Konrad for implementing
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1813
  TFL and assisting with its installation.}
a5bbc11474f9 clarified current 'primrec' vs. old 'recdef';
wenzelm
parents: 42910
diff changeset
  1814
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1815
Using \texttt{recdef}, you can declare functions involving nested recursion
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1816
and pattern-matching.  Recursion need not involve datatypes and there are few
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1817
syntactic restrictions.  Termination is proved by showing that each recursive
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1818
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
  1819
supplying a well-founded relation.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1820
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1821
Here is a simple example, the Fibonacci function.  The first line declares
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1822
\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
  1823
the natural numbers).  Pattern-matching is used here: \texttt{1} is a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1824
macro for \texttt{Suc~0}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1825
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1826
consts fib  :: "nat => nat"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1827
recdef fib "less_than"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1828
    "fib 0 = 0"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1829
    "fib 1 = 1"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1830
    "fib (Suc(Suc x)) = (fib x + fib (Suc x))"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1831
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1832
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1833
With \texttt{recdef}, function definitions may be incomplete, and patterns may
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1834
overlap, as in functional programming.  The \texttt{recdef} package
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1835
disambiguates overlapping patterns by taking the order of rules into account.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1836
For missing patterns, the function is defined to return a default value.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1837
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1838
%For example, here is a declaration of the list function \cdx{hd}:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1839
%\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1840
%consts hd :: 'a list => 'a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1841
%recdef hd "\{\}"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1842
%    "hd (x#l) = x"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1843
%\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1844
%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
  1845
%relation, $\{\}$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1846
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1847
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
  1848
argument type.  The relation $\prec$ is \textbf{well-founded} provided it
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1849
admits no infinitely decreasing chains
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1850
\[ \cdots\prec x@n\prec\cdots\prec x@1. \]
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1851
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
  1852
over~$\tau$: it must have type $(\tau\times\tau)set$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1853
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1854
Proving well-foundedness can be tricky, so Isabelle/HOL provides a collection
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1855
of operators for building well-founded relations.  The package recognises
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1856
these operators and automatically proves that the constructed relation is
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1857
well-founded.  Here are those operators, in order of importance:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1858
\begin{itemize}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1859
\item \texttt{less_than} is ``less than'' on the natural numbers.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1860
  (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
  1861
  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1862
\item $\mathop{\mathtt{measure}} f$, where $f$ has type $\tau\To nat$, is the
9258
2121ff73a37d fixed typos reported by Jeremy Dawson
paulson
parents: 9212
diff changeset
  1863
  relation~$\prec$ on type~$\tau$ such that $x\prec y$ if and only if
2121ff73a37d fixed typos reported by Jeremy Dawson
paulson
parents: 9212
diff changeset
  1864
  $f(x)<f(y)$.  
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1865
  Typically, $f$ takes the recursive function's arguments (as a tuple) and
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1866
  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
  1867
  called a \textbf{measure function}.  Recall that \texttt{size} is overloaded
7490
9a74b57740d1 added smp_tac
oheimb
parents: 7328
diff changeset
  1868
  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
  1869
                                                    
9258
2121ff73a37d fixed typos reported by Jeremy Dawson
paulson
parents: 9212
diff changeset
  1870
\item $\mathop{\mathtt{inv_image}} R\;f$ is a generalisation of
2121ff73a37d fixed typos reported by Jeremy Dawson
paulson
parents: 9212
diff changeset
  1871
  \texttt{measure}.  It specifies a relation such that $x\prec y$ if and only
2121ff73a37d fixed typos reported by Jeremy Dawson
paulson
parents: 9212
diff changeset
  1872
  if $f(x)$ 
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1873
  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
  1874
  relation.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1875
11242
81fe09ce5fc9 lexicographic product of two relations: updated HOL.tex
paulson
parents: 10109
diff changeset
  1876
\item $R@1\texttt{<*lex*>}R@2$ is the lexicographic product of two relations.
81fe09ce5fc9 lexicographic product of two relations: updated HOL.tex
paulson
parents: 10109
diff changeset
  1877
  It 
9258
2121ff73a37d fixed typos reported by Jeremy Dawson
paulson
parents: 9212
diff changeset
  1878
  is a relation on pairs and satisfies $(x@1,x@2)\prec(y@1,y@2)$ if and only
2121ff73a37d fixed typos reported by Jeremy Dawson
paulson
parents: 9212
diff changeset
  1879
  if $x@1$ 
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1880
  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
  1881
  is less than $y@2$ according to~$R@2$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1882
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1883
\item \texttt{finite_psubset} is the proper subset relation on finite sets.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1884
\end{itemize}
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
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
  1887
common divisor.  The measure function, $\lambda(m,n). n$, specifies that the
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1888
recursion terminates because argument~$n$ decreases.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1889
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1890
recdef gcd "measure ((\%(m,n). n) ::nat*nat=>nat)"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1891
    "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
  1892
\end{ttbox}
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
The general form of a well-founded recursive definition is
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1895
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1896
recdef {\it function} {\it rel}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1897
    congs   {\it congruence rules}      {\bf(optional)}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1898
    simpset {\it simplification set}      {\bf(optional)}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1899
   {\it reduction rules}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1900
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1901
where
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1902
\begin{itemize}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1903
\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
  1904
  or a \textit{string}.  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1905
  
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
  1906
\item \textit{rel} is a HOL expression for the well-founded termination
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1907
  relation.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1908
  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1909
\item \textit{congruence rules} are required only in highly exceptional
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1910
  circumstances.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1911
  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1912
\item The \textit{simplification set} is used to prove that the supplied
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1913
  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
  1914
    conditions}: assertions that arguments of recursive calls decrease under
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1915
  \textit{rel}.  By default, simplification uses \texttt{simpset()}, which
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1916
  is sufficient to prove well-foundedness for the built-in relations listed
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1917
  above. 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1918
  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1919
\item \textit{reduction rules} specify one or more recursion equations.  Each
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1920
  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
  1921
  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
  1922
  $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
  1923
  is a \texttt{datatype}.  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1924
8628
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1925
  The \ML\ identifier $f$\texttt{.simps} contains the reduction rules as
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1926
  a list of theorems.
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1927
\end{itemize}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1928
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1929
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
  1930
prove one termination condition.  It remains as a precondition of the
8628
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1931
recursion theorems:
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1932
\begin{ttbox}
8628
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1933
gcd.simps;
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1934
{\out ["! m n. n ~= 0 --> m mod n < n}
9212
4afe62073b41 overloading, axclasses, numerals and general tidying
paulson
parents: 8628
diff changeset
  1935
{\out   ==> gcd (?m,?n) = (if ?n=0 then ?m else gcd (?n, ?m mod ?n))"] }
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1936
{\out : thm list}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1937
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1938
The theory \texttt{HOL/ex/Primes} illustrates how to prove termination
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1939
conditions afterwards.  The function \texttt{Tfl.tgoalw} is like the standard
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1940
function \texttt{goalw}, which sets up a goal to prove, but its argument
8628
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1941
should be the identifier $f$\texttt{.simps} and its effect is to set up a
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1942
proof of the termination conditions:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1943
\begin{ttbox}
8628
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1944
Tfl.tgoalw thy [] gcd.simps;
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1945
{\out Level 0}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1946
{\out ! m n. n ~= 0 --> m mod n < n}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1947
{\out  1. ! m n. n ~= 0 --> m mod n < n}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1948
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1949
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
  1950
is proved, it can be used to eliminate the termination conditions from
8628
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1951
elements of \texttt{gcd.simps}.  Theory \texttt{HOL/Subst/Unify} is a much
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1952
more complicated example of this process, where the termination conditions can
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1953
only be proved by complicated reasoning involving the recursive function
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1954
itself.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1955
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1956
Isabelle/HOL can prove the \texttt{gcd} function's termination condition
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1957
automatically if supplied with the right simpset.
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
recdef gcd "measure ((\%(m,n). n) ::nat*nat=>nat)"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1960
  simpset "simpset() addsimps [mod_less_divisor, zero_less_eq]"
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1961
    "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
  1962
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1963
8628
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1964
If all termination conditions were proved automatically, $f$\texttt{.simps}
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1965
is added to the simpset automatically, just as in \texttt{primrec}. 
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1966
The simplification rules corresponding to clause $i$ (where counting starts
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1967
at 0) are called $f$\texttt{.}$i$ and can be accessed as \texttt{thms
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1968
  "$f$.$i$"},
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1969
which returns a list of theorems. Thus you can, for example, remove specific
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1970
clauses from the simpset. Note that a single clause may give rise to a set of
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1971
simplification rules in order to capture the fact that if clauses overlap,
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1972
their order disambiguates them.
b3d9d8446473 updated recdef
nipkow
parents: 8604
diff changeset
  1973
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1974
A \texttt{recdef} definition also returns an induction rule specialised for
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1975
the recursive function.  For the \texttt{gcd} function above, the induction
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1976
rule is
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1977
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1978
gcd.induct;
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1979
{\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
  1980
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1981
This rule should be used to reason inductively about the \texttt{gcd}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1982
function.  It usually makes the induction hypothesis available at all
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1983
recursive calls, leading to very direct proofs.  If any termination conditions
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1984
remain unproved, they will become additional premises of this rule.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1985
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1986
\index{recursion!general|)}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1987
\index{*recdef|)}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1988
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1989
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1990
\section{Example: Cantor's Theorem}\label{sec:hol-cantor}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1991
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
  1992
elements.  It has become a favourite example in higher-order logic since
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1993
it is so easily expressed:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1994
\[  \forall f::\alpha \To \alpha \To bool. \exists S::\alpha\To bool.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1995
    \forall x::\alpha. f~x \not= S 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1996
\] 
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
Viewing types as sets, $\alpha\To bool$ represents the powerset
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  1999
of~$\alpha$.  This version states that for every function from $\alpha$ to
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2000
its powerset, some subset is outside its range.  
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2001
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
  2002
The Isabelle proof uses HOL's set theory, with the type $\alpha\,set$ and
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2003
the operator \cdx{range}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2004
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2005
context Set.thy;
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2006
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2007
The set~$S$ is given as an unknown instead of a
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2008
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
  2009
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2010
Goal "?S ~: range\thinspace(f :: 'a=>'a set)";
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2011
{\out Level 0}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2012
{\out ?S ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2013
{\out  1. ?S ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2014
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2015
The first two steps are routine.  The rule \tdx{rangeE} replaces
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2016
$\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
  2017
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2018
by (resolve_tac [notI] 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2019
{\out Level 1}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2020
{\out ?S ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2021
{\out  1. ?S : range f ==> False}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2022
\ttbreak
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2023
by (eresolve_tac [rangeE] 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2024
{\out Level 2}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2025
{\out ?S ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2026
{\out  1. !!x. ?S = f x ==> False}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2027
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2028
Next, we apply \tdx{equalityCE}, reasoning that since $\Var{S}=f~x$,
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2029
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
  2030
any~$\Var{c}$.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2031
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2032
by (eresolve_tac [equalityCE] 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2033
{\out Level 3}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2034
{\out ?S ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2035
{\out  1. !!x. [| ?c3 x : ?S; ?c3 x : f x |] ==> False}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2036
{\out  2. !!x. [| ?c3 x ~: ?S; ?c3 x ~: f x |] ==> False}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2037
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2038
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
  2039
comprehension.  Then $\Var{c}\in\{x.\Var{P}~x\}$ implies
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2040
$\Var{P}~\Var{c}$.   Destruct-resolution using \tdx{CollectD}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2041
instantiates~$\Var{S}$ and creates the new assumption.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2042
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2043
by (dresolve_tac [CollectD] 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2044
{\out Level 4}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2045
{\out {\ttlbrace}x. ?P7 x{\ttrbrace} ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2046
{\out  1. !!x. [| ?c3 x : f x; ?P7(?c3 x) |] ==> False}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2047
{\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
  2048
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2049
Forcing a contradiction between the two assumptions of subgoal~1
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2050
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
  2051
f~x\}$, which is the standard diagonal construction.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2052
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2053
by (contr_tac 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2054
{\out Level 5}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2055
{\out {\ttlbrace}x. x ~: f x{\ttrbrace} ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2056
{\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
  2057
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2058
The rest should be easy.  To apply \tdx{CollectI} to the negated
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2059
assumption, we employ \ttindex{swap_res_tac}:
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2060
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2061
by (swap_res_tac [CollectI] 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2062
{\out Level 6}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2063
{\out {\ttlbrace}x. x ~: f x{\ttrbrace} ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2064
{\out  1. !!x. [| x ~: f x; ~ False |] ==> x ~: f x}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2065
\ttbreak
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2066
by (assume_tac 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2067
{\out Level 7}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2068
{\out {\ttlbrace}x. x ~: f x{\ttrbrace} ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2069
{\out No subgoals!}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2070
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2071
How much creativity is required?  As it happens, Isabelle can prove this
9695
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
  2072
theorem automatically.  The default classical set \texttt{claset()} contains
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
  2073
rules for most of the constructs of HOL's set theory.  We must augment it with
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
  2074
\tdx{equalityCE} to break up set equalities, and then apply best-first search.
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
  2075
Depth-first search would diverge, but best-first search successfully navigates
ec7d7f877712 proper setup of iman.sty/extra.sty/ttbox.sty;
wenzelm
parents: 9258
diff changeset
  2076
through the large search space.  \index{search!best-first}
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2077
\begin{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2078
choplev 0;
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2079
{\out Level 0}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2080
{\out ?S ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2081
{\out  1. ?S ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2082
\ttbreak
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2083
by (best_tac (claset() addSEs [equalityCE]) 1);
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2084
{\out Level 1}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2085
{\out {\ttlbrace}x. x ~: f x{\ttrbrace} ~: range f}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2086
{\out No subgoals!}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2087
\end{ttbox}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2088
If you run this example interactively, make sure your current theory contains
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2089
theory \texttt{Set}, for example by executing \ttindex{context}~{\tt Set.thy}.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2090
Otherwise the default claset may not contain the rules for set theory.
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2091
\index{higher-order logic|)}
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2092
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2093
%%% Local Variables: 
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2094
%%% mode: latex
10109
dcb72400bc32 record proof tools: t.equality;
wenzelm
parents: 10052
diff changeset
  2095
%%% TeX-master: "logics-HOL"
6580
ff2c3ffd38ee used to be part of 'logics' manual;
wenzelm
parents:
diff changeset
  2096
%%% End: