lcp@104
|
1 |
%% $Id$
|
lcp@315
|
2 |
\chapter{Higher-Order Logic}
|
lcp@315
|
3 |
\index{higher-order logic|(}
|
lcp@315
|
4 |
\index{HOL system@{\sc hol} system}
|
lcp@315
|
5 |
|
wenzelm@9695
|
6 |
The theory~\thydx{HOL} implements higher-order logic. It is based on
|
wenzelm@9695
|
7 |
Gordon's~{\sc hol} system~\cite{mgordon-hol}, which itself is based on
|
wenzelm@9695
|
8 |
Church's original paper~\cite{church40}. Andrews's book~\cite{andrews86} is a
|
wenzelm@9695
|
9 |
full description of higher-order logic. Experience with the {\sc hol} system
|
wenzelm@9695
|
10 |
has demonstrated that higher-order logic is useful for hardware verification;
|
wenzelm@9695
|
11 |
beyond this, it is widely applicable in many areas of mathematics. It is
|
wenzelm@9695
|
12 |
weaker than ZF set theory but for most applications this does not matter. If
|
wenzelm@9695
|
13 |
you prefer {\ML} to Lisp, you will probably prefer HOL to~ZF.
|
lcp@104
|
14 |
|
wenzelm@9695
|
15 |
Previous releases of Isabelle included a different version of~HOL, with
|
lcp@315
|
16 |
explicit type inference rules~\cite{paulson-COLOG}. This version no longer
|
lcp@315
|
17 |
exists, but \thydx{ZF} supports a similar style of reasoning.
|
lcp@104
|
18 |
|
wenzelm@9695
|
19 |
HOL has a distinct feel, compared with ZF and CTT. It identifies object-level
|
wenzelm@9695
|
20 |
types with meta-level types, taking advantage of Isabelle's built-in type
|
wenzelm@9695
|
21 |
checker. It identifies object-level functions with meta-level functions, so
|
wenzelm@9695
|
22 |
it uses Isabelle's operations for abstraction and application. There is no
|
wenzelm@9695
|
23 |
`apply' operator: function applications are written as simply~$f(a)$ rather
|
wenzelm@9695
|
24 |
than $f{\tt`}a$.
|
lcp@104
|
25 |
|
wenzelm@9695
|
26 |
These identifications allow Isabelle to support HOL particularly nicely, but
|
wenzelm@9695
|
27 |
they also mean that HOL requires more sophistication from the user --- in
|
wenzelm@9695
|
28 |
particular, an understanding of Isabelle's type system. Beginners should work
|
wenzelm@9695
|
29 |
with {\tt show_types} set to {\tt true}. Gain experience by working in
|
wenzelm@9695
|
30 |
first-order logic before attempting to use higher-order logic. This chapter
|
wenzelm@9695
|
31 |
assumes familiarity with~FOL.
|
lcp@104
|
32 |
|
lcp@104
|
33 |
|
lcp@104
|
34 |
\begin{figure}
|
lcp@104
|
35 |
\begin{center}
|
lcp@104
|
36 |
\begin{tabular}{rrr}
|
lcp@111
|
37 |
\it name &\it meta-type & \it description \\
|
lcp@315
|
38 |
\cdx{Trueprop}& $bool\To prop$ & coercion to $prop$\\
|
lcp@315
|
39 |
\cdx{not} & $bool\To bool$ & negation ($\neg$) \\
|
lcp@315
|
40 |
\cdx{True} & $bool$ & tautology ($\top$) \\
|
lcp@315
|
41 |
\cdx{False} & $bool$ & absurdity ($\bot$) \\
|
lcp@315
|
42 |
\cdx{if} & $[bool,\alpha,\alpha]\To\alpha::term$ & conditional \\
|
lcp@315
|
43 |
\cdx{Inv} & $(\alpha\To\beta)\To(\beta\To\alpha)$ & function inversion\\
|
lcp@315
|
44 |
\cdx{Let} & $[\alpha,\alpha\To\beta]\To\beta$ & let binder
|
lcp@104
|
45 |
\end{tabular}
|
lcp@104
|
46 |
\end{center}
|
lcp@104
|
47 |
\subcaption{Constants}
|
lcp@104
|
48 |
|
lcp@104
|
49 |
\begin{center}
|
lcp@315
|
50 |
\index{"@@{\tt\at} symbol}
|
lcp@315
|
51 |
\index{*"! symbol}\index{*"? symbol}
|
lcp@315
|
52 |
\index{*"?"! symbol}\index{*"E"X"! symbol}
|
lcp@104
|
53 |
\begin{tabular}{llrrr}
|
lcp@315
|
54 |
\it symbol &\it name &\it meta-type & \it description \\
|
lcp@315
|
55 |
\tt\at & \cdx{Eps} & $(\alpha\To bool)\To\alpha::term$ &
|
lcp@111
|
56 |
Hilbert description ($\epsilon$) \\
|
lcp@315
|
57 |
{\tt!~} or \sdx{ALL} & \cdx{All} & $(\alpha::term\To bool)\To bool$ &
|
lcp@111
|
58 |
universal quantifier ($\forall$) \\
|
lcp@315
|
59 |
{\tt?~} or \sdx{EX} & \cdx{Ex} & $(\alpha::term\To bool)\To bool$ &
|
lcp@111
|
60 |
existential quantifier ($\exists$) \\
|
lcp@315
|
61 |
{\tt?!} or {\tt EX!} & \cdx{Ex1} & $(\alpha::term\To bool)\To bool$ &
|
lcp@111
|
62 |
unique existence ($\exists!$)
|
lcp@104
|
63 |
\end{tabular}
|
lcp@104
|
64 |
\end{center}
|
lcp@104
|
65 |
\subcaption{Binders}
|
lcp@104
|
66 |
|
lcp@104
|
67 |
\begin{center}
|
lcp@315
|
68 |
\index{*"= symbol}
|
lcp@315
|
69 |
\index{&@{\tt\&} symbol}
|
lcp@315
|
70 |
\index{*"| symbol}
|
lcp@315
|
71 |
\index{*"-"-"> symbol}
|
lcp@104
|
72 |
\begin{tabular}{rrrr}
|
lcp@315
|
73 |
\it symbol & \it meta-type & \it priority & \it description \\
|
lcp@315
|
74 |
\sdx{o} & $[\beta\To\gamma,\alpha\To\beta]\To (\alpha\To\gamma)$ &
|
lcp@111
|
75 |
Right 50 & composition ($\circ$) \\
|
lcp@111
|
76 |
\tt = & $[\alpha::term,\alpha]\To bool$ & Left 50 & equality ($=$) \\
|
lcp@315
|
77 |
\tt < & $[\alpha::ord,\alpha]\To bool$ & Left 50 & less than ($<$) \\
|
lcp@315
|
78 |
\tt <= & $[\alpha::ord,\alpha]\To bool$ & Left 50 &
|
lcp@315
|
79 |
less than or equals ($\leq$)\\
|
lcp@111
|
80 |
\tt \& & $[bool,bool]\To bool$ & Right 35 & conjunction ($\conj$) \\
|
lcp@111
|
81 |
\tt | & $[bool,bool]\To bool$ & Right 30 & disjunction ($\disj$) \\
|
lcp@315
|
82 |
\tt --> & $[bool,bool]\To bool$ & Right 25 & implication ($\imp$)
|
lcp@104
|
83 |
\end{tabular}
|
lcp@104
|
84 |
\end{center}
|
lcp@104
|
85 |
\subcaption{Infixes}
|
lcp@104
|
86 |
\caption{Syntax of {\tt HOL}} \label{hol-constants}
|
lcp@104
|
87 |
\end{figure}
|
lcp@104
|
88 |
|
lcp@104
|
89 |
|
nipkow@306
|
90 |
\begin{figure}
|
lcp@315
|
91 |
\index{*let symbol}
|
lcp@315
|
92 |
\index{*in symbol}
|
lcp@104
|
93 |
\dquotes
|
lcp@315
|
94 |
\[\begin{array}{rclcl}
|
lcp@104
|
95 |
term & = & \hbox{expression of class~$term$} \\
|
lcp@315
|
96 |
& | & "\at~" id~id^* " . " formula \\
|
lcp@315
|
97 |
& | &
|
lcp@315
|
98 |
\multicolumn{3}{l}{"let"~id~"="~term";"\dots";"~id~"="~term~"in"~term}
|
lcp@315
|
99 |
\\[2ex]
|
lcp@104
|
100 |
formula & = & \hbox{expression of type~$bool$} \\
|
lcp@111
|
101 |
& | & term " = " term \\
|
lcp@111
|
102 |
& | & term " \ttilde= " term \\
|
lcp@111
|
103 |
& | & term " < " term \\
|
lcp@111
|
104 |
& | & term " <= " term \\
|
lcp@111
|
105 |
& | & "\ttilde\ " formula \\
|
lcp@111
|
106 |
& | & formula " \& " formula \\
|
lcp@111
|
107 |
& | & formula " | " formula \\
|
lcp@111
|
108 |
& | & formula " --> " formula \\
|
lcp@315
|
109 |
& | & "!~~~" id~id^* " . " formula
|
lcp@111
|
110 |
& | & "ALL~" id~id^* " . " formula \\
|
lcp@315
|
111 |
& | & "?~~~" id~id^* " . " formula
|
lcp@111
|
112 |
& | & "EX~~" id~id^* " . " formula \\
|
lcp@315
|
113 |
& | & "?!~~" id~id^* " . " formula
|
lcp@111
|
114 |
& | & "EX!~" id~id^* " . " formula
|
lcp@104
|
115 |
\end{array}
|
lcp@104
|
116 |
\]
|
wenzelm@9695
|
117 |
\caption{Full grammar for HOL} \label{hol-grammar}
|
lcp@104
|
118 |
\end{figure}
|
lcp@104
|
119 |
|
lcp@104
|
120 |
|
lcp@104
|
121 |
\section{Syntax}
|
lcp@315
|
122 |
The type class of higher-order terms is called~\cldx{term}. Type variables
|
lcp@315
|
123 |
range over this class by default. The equality symbol and quantifiers are
|
lcp@315
|
124 |
polymorphic over class {\tt term}.
|
lcp@104
|
125 |
|
lcp@315
|
126 |
Class \cldx{ord} consists of all ordered types; the relations $<$ and
|
lcp@104
|
127 |
$\leq$ are polymorphic over this class, as are the functions
|
lcp@315
|
128 |
\cdx{mono}, \cdx{min} and \cdx{max}. Three other
|
lcp@315
|
129 |
type classes --- \cldx{plus}, \cldx{minus} and \cldx{times} --- permit
|
lcp@104
|
130 |
overloading of the operators {\tt+}, {\tt-} and {\tt*}. In particular,
|
lcp@104
|
131 |
{\tt-} is overloaded for set difference and subtraction.
|
lcp@315
|
132 |
\index{*"+ symbol}
|
lcp@315
|
133 |
\index{*"- symbol}
|
lcp@315
|
134 |
\index{*"* symbol}
|
lcp@104
|
135 |
|
lcp@104
|
136 |
Figure~\ref{hol-constants} lists the constants (including infixes and
|
lcp@315
|
137 |
binders), while Fig.\ts\ref{hol-grammar} presents the grammar of
|
lcp@287
|
138 |
higher-order logic. Note that $a$\verb|~=|$b$ is translated to
|
lcp@315
|
139 |
$\neg(a=b)$.
|
lcp@315
|
140 |
|
lcp@315
|
141 |
\begin{warn}
|
wenzelm@9695
|
142 |
HOL has no if-and-only-if connective; logical equivalence is expressed
|
lcp@315
|
143 |
using equality. But equality has a high priority, as befitting a
|
lcp@315
|
144 |
relation, while if-and-only-if typically has the lowest priority. Thus,
|
lcp@315
|
145 |
$\neg\neg P=P$ abbreviates $\neg\neg (P=P)$ and not $(\neg\neg P)=P$.
|
lcp@315
|
146 |
When using $=$ to mean logical equivalence, enclose both operands in
|
lcp@315
|
147 |
parentheses.
|
lcp@315
|
148 |
\end{warn}
|
lcp@104
|
149 |
|
lcp@287
|
150 |
\subsection{Types}\label{HOL-types}
|
lcp@315
|
151 |
The type of formulae, \tydx{bool}, belongs to class \cldx{term}; thus,
|
lcp@315
|
152 |
formulae are terms. The built-in type~\tydx{fun}, which constructs function
|
lcp@315
|
153 |
types, is overloaded with arity {\tt(term,term)term}. Thus, $\sigma\To\tau$
|
lcp@315
|
154 |
belongs to class~{\tt term} if $\sigma$ and~$\tau$ do, allowing quantification
|
lcp@315
|
155 |
over functions.
|
lcp@104
|
156 |
|
wenzelm@9695
|
157 |
Types in HOL must be non-empty; otherwise the quantifier rules would be
|
lcp@315
|
158 |
unsound. I have commented on this elsewhere~\cite[\S7]{paulson-COLOG}.
|
lcp@315
|
159 |
|
lcp@315
|
160 |
\index{type definitions}
|
lcp@104
|
161 |
Gordon's {\sc hol} system supports {\bf type definitions}. A type is
|
lcp@104
|
162 |
defined by exhibiting an existing type~$\sigma$, a predicate~$P::\sigma\To
|
lcp@104
|
163 |
bool$, and a theorem of the form $\exists x::\sigma.P(x)$. Thus~$P$
|
lcp@104
|
164 |
specifies a non-empty subset of~$\sigma$, and the new type denotes this
|
lcp@104
|
165 |
subset. New function constants are generated to establish an isomorphism
|
lcp@104
|
166 |
between the new type and the subset. If type~$\sigma$ involves type
|
lcp@104
|
167 |
variables $\alpha@1$, \ldots, $\alpha@n$, then the type definition creates
|
lcp@104
|
168 |
a type constructor $(\alpha@1,\ldots,\alpha@n)ty$ rather than a particular
|
lcp@344
|
169 |
type. Melham~\cite{melham89} discusses type definitions at length, with
|
lcp@344
|
170 |
examples.
|
lcp@104
|
171 |
|
lcp@104
|
172 |
Isabelle does not support type definitions at present. Instead, they are
|
lcp@315
|
173 |
mimicked by explicit definitions of isomorphism functions. The definitions
|
lcp@315
|
174 |
should be supported by theorems of the form $\exists x::\sigma.P(x)$, but
|
lcp@315
|
175 |
Isabelle cannot enforce this.
|
lcp@104
|
176 |
|
lcp@104
|
177 |
|
lcp@104
|
178 |
\subsection{Binders}
|
lcp@104
|
179 |
Hilbert's {\bf description} operator~$\epsilon x.P[x]$ stands for some~$a$
|
wenzelm@9695
|
180 |
satisfying~$P[a]$, if such exists. Since all terms in HOL denote something, a
|
wenzelm@9695
|
181 |
description is always meaningful, but we do not know its value unless $P[x]$
|
wenzelm@9695
|
182 |
defines it uniquely. We may write descriptions as \cdx{Eps}($P$) or use the
|
wenzelm@9695
|
183 |
syntax \hbox{\tt \at $x$.$P[x]$}.
|
lcp@315
|
184 |
|
lcp@315
|
185 |
Existential quantification is defined by
|
lcp@315
|
186 |
\[ \exists x.P(x) \;\equiv\; P(\epsilon x.P(x)). \]
|
lcp@104
|
187 |
The unique existence quantifier, $\exists!x.P[x]$, is defined in terms
|
lcp@104
|
188 |
of~$\exists$ and~$\forall$. An Isabelle binder, it admits nested
|
lcp@104
|
189 |
quantifications. For instance, $\exists!x y.P(x,y)$ abbreviates
|
lcp@104
|
190 |
$\exists!x. \exists!y.P(x,y)$; note that this does not mean that there
|
lcp@104
|
191 |
exists a unique pair $(x,y)$ satisfying~$P(x,y)$.
|
lcp@104
|
192 |
|
lcp@315
|
193 |
\index{*"! symbol}\index{*"? symbol}\index{HOL system@{\sc hol} system}
|
wenzelm@9695
|
194 |
Quantifiers have two notations. As in Gordon's {\sc hol} system, HOL
|
lcp@104
|
195 |
uses~{\tt!}\ and~{\tt?}\ to stand for $\forall$ and $\exists$. The
|
lcp@104
|
196 |
existential quantifier must be followed by a space; thus {\tt?x} is an
|
lcp@104
|
197 |
unknown, while \verb'? x.f(x)=y' is a quantification. Isabelle's usual
|
wenzelm@9695
|
198 |
notation for quantifiers, \sdx{ALL} and \sdx{EX}, is also available. Both
|
wenzelm@9695
|
199 |
notations are accepted for input. The {\ML} reference
|
lcp@104
|
200 |
\ttindexbold{HOL_quantifiers} governs the output notation. If set to {\tt
|
wenzelm@9695
|
201 |
true}, then~{\tt!}\ and~{\tt?}\ are displayed; this is the default. If set
|
lcp@104
|
202 |
to {\tt false}, then~{\tt ALL} and~{\tt EX} are displayed.
|
lcp@104
|
203 |
|
lcp@315
|
204 |
All these binders have priority 10.
|
lcp@104
|
205 |
|
nipkow@306
|
206 |
|
lcp@315
|
207 |
\subsection{The \sdx{let} and \sdx{case} constructions}
|
lcp@315
|
208 |
Local abbreviations can be introduced by a {\tt let} construct whose
|
lcp@315
|
209 |
syntax appears in Fig.\ts\ref{hol-grammar}. Internally it is translated into
|
lcp@315
|
210 |
the constant~\cdx{Let}. It can be expanded by rewriting with its
|
lcp@315
|
211 |
definition, \tdx{Let_def}.
|
lcp@315
|
212 |
|
wenzelm@9695
|
213 |
HOL also defines the basic syntax
|
lcp@315
|
214 |
\[\dquotes"case"~e~"of"~c@1~"=>"~e@1~"|" \dots "|"~c@n~"=>"~e@n\]
|
lcp@315
|
215 |
as a uniform means of expressing {\tt case} constructs. Therefore {\tt
|
lcp@315
|
216 |
case} and \sdx{of} are reserved words. However, so far this is mere
|
lcp@315
|
217 |
syntax and has no logical meaning. By declaring translations, you can
|
lcp@315
|
218 |
cause instances of the {\tt case} construct to denote applications of
|
lcp@315
|
219 |
particular case operators. The patterns supplied for $c@1$,~\ldots,~$c@n$
|
lcp@315
|
220 |
distinguish among the different case operators. For an example, see the
|
lcp@315
|
221 |
case construct for lists on page~\pageref{hol-list} below.
|
nipkow@306
|
222 |
|
nipkow@306
|
223 |
|
nipkow@306
|
224 |
\begin{figure}
|
lcp@287
|
225 |
\begin{ttbox}\makeatother
|
nipkow@453
|
226 |
\tdx{refl} t = (t::'a)
|
lcp@315
|
227 |
\tdx{subst} [| s=t; P(s) |] ==> P(t::'a)
|
nipkow@453
|
228 |
\tdx{ext} (!!x::'a. (f(x)::'b) = g(x)) ==> (\%x.f(x)) = (\%x.g(x))
|
lcp@315
|
229 |
\tdx{impI} (P ==> Q) ==> P-->Q
|
lcp@315
|
230 |
\tdx{mp} [| P-->Q; P |] ==> Q
|
lcp@315
|
231 |
\tdx{iff} (P-->Q) --> (Q-->P) --> (P=Q)
|
lcp@315
|
232 |
\tdx{selectI} P(x::'a) ==> P(@x.P(x))
|
lcp@315
|
233 |
\tdx{True_or_False} (P=True) | (P=False)
|
lcp@315
|
234 |
\end{ttbox}
|
lcp@315
|
235 |
\caption{The {\tt HOL} rules} \label{hol-rules}
|
lcp@315
|
236 |
\end{figure}
|
lcp@104
|
237 |
|
lcp@104
|
238 |
|
lcp@344
|
239 |
\begin{figure}\hfuzz=4pt%suppress "Overfull \hbox" message
|
lcp@315
|
240 |
\begin{ttbox}\makeatother
|
nipkow@453
|
241 |
\tdx{True_def} True == ((\%x::bool.x)=(\%x.x))
|
lcp@344
|
242 |
\tdx{All_def} All == (\%P. P = (\%x.True))
|
lcp@344
|
243 |
\tdx{Ex_def} Ex == (\%P. P(@x.P(x)))
|
lcp@344
|
244 |
\tdx{False_def} False == (!P.P)
|
lcp@344
|
245 |
\tdx{not_def} not == (\%P. P-->False)
|
lcp@344
|
246 |
\tdx{and_def} op & == (\%P Q. !R. (P-->Q-->R) --> R)
|
lcp@344
|
247 |
\tdx{or_def} op | == (\%P Q. !R. (P-->R) --> (Q-->R) --> R)
|
lcp@344
|
248 |
\tdx{Ex1_def} Ex1 == (\%P. ? x. P(x) & (! y. P(y) --> y=x))
|
lcp@315
|
249 |
|
lcp@344
|
250 |
\tdx{Inv_def} Inv == (\%(f::'a=>'b) y. @x. f(x)=y)
|
lcp@344
|
251 |
\tdx{o_def} op o == (\%(f::'b=>'c) g (x::'a). f(g(x)))
|
lcp@344
|
252 |
\tdx{if_def} if == (\%P x y.@z::'a.(P=True --> z=x) & (P=False --> z=y))
|
lcp@344
|
253 |
\tdx{Let_def} Let(s,f) == f(s)
|
lcp@104
|
254 |
\end{ttbox}
|
lcp@315
|
255 |
\caption{The {\tt HOL} definitions} \label{hol-defs}
|
lcp@104
|
256 |
\end{figure}
|
lcp@104
|
257 |
|
lcp@104
|
258 |
|
lcp@315
|
259 |
\section{Rules of inference}
|
wenzelm@9695
|
260 |
Figure~\ref{hol-rules} shows the inference rules of~HOL, with their~{\ML}
|
wenzelm@9695
|
261 |
names. Some of the rules deserve additional comments:
|
lcp@315
|
262 |
\begin{ttdescription}
|
lcp@315
|
263 |
\item[\tdx{ext}] expresses extensionality of functions.
|
lcp@315
|
264 |
\item[\tdx{iff}] asserts that logically equivalent formulae are
|
lcp@315
|
265 |
equal.
|
lcp@315
|
266 |
\item[\tdx{selectI}] gives the defining property of the Hilbert
|
lcp@315
|
267 |
$\epsilon$-operator. It is a form of the Axiom of Choice. The derived rule
|
lcp@315
|
268 |
\tdx{select_equality} (see below) is often easier to use.
|
lcp@315
|
269 |
\item[\tdx{True_or_False}] makes the logic classical.\footnote{In
|
lcp@315
|
270 |
fact, the $\epsilon$-operator already makes the logic classical, as
|
lcp@315
|
271 |
shown by Diaconescu; see Paulson~\cite{paulson-COLOG} for details.}
|
lcp@315
|
272 |
\end{ttdescription}
|
lcp@315
|
273 |
|
wenzelm@9695
|
274 |
HOL follows standard practice in higher-order logic: only a few connectives
|
wenzelm@9695
|
275 |
are taken as primitive, with the remainder defined obscurely
|
lcp@344
|
276 |
(Fig.\ts\ref{hol-defs}). Gordon's {\sc hol} system expresses the
|
lcp@344
|
277 |
corresponding definitions \cite[page~270]{mgordon-hol} using
|
wenzelm@9695
|
278 |
object-equality~({\tt=}), which is possible because equality in higher-order
|
wenzelm@9695
|
279 |
logic may equate formulae and even functions over formulae. But theory~HOL,
|
wenzelm@9695
|
280 |
like all other Isabelle theories, uses meta-equality~({\tt==}) for
|
wenzelm@9695
|
281 |
definitions.
|
lcp@315
|
282 |
|
lcp@344
|
283 |
Some of the rules mention type variables; for
|
lcp@344
|
284 |
example, {\tt refl} mentions the type variable~{\tt'a}. This allows you to
|
lcp@344
|
285 |
instantiate type variables explicitly by calling {\tt res_inst_tac}. By
|
lcp@344
|
286 |
default, explicit type variables have class \cldx{term}.
|
lcp@315
|
287 |
|
lcp@315
|
288 |
Include type constraints whenever you state a polymorphic goal. Type
|
lcp@315
|
289 |
inference may otherwise make the goal more polymorphic than you intended,
|
lcp@315
|
290 |
with confusing results.
|
lcp@315
|
291 |
|
lcp@315
|
292 |
\begin{warn}
|
lcp@315
|
293 |
If resolution fails for no obvious reason, try setting
|
lcp@315
|
294 |
\ttindex{show_types} to {\tt true}, causing Isabelle to display types of
|
lcp@315
|
295 |
terms. Possibly set \ttindex{show_sorts} to {\tt true} as well, causing
|
lcp@315
|
296 |
Isabelle to display sorts.
|
lcp@315
|
297 |
|
lcp@315
|
298 |
\index{unification!incompleteness of}
|
lcp@315
|
299 |
Where function types are involved, Isabelle's unification code does not
|
lcp@315
|
300 |
guarantee to find instantiations for type variables automatically. Be
|
lcp@315
|
301 |
prepared to use \ttindex{res_inst_tac} instead of {\tt resolve_tac},
|
lcp@315
|
302 |
possibly instantiating type variables. Setting
|
lcp@315
|
303 |
\ttindex{Unify.trace_types} to {\tt true} causes Isabelle to report
|
lcp@315
|
304 |
omitted search paths during unification.\index{tracing!of unification}
|
lcp@315
|
305 |
\end{warn}
|
lcp@315
|
306 |
|
lcp@315
|
307 |
|
lcp@287
|
308 |
\begin{figure}
|
lcp@104
|
309 |
\begin{ttbox}
|
lcp@315
|
310 |
\tdx{sym} s=t ==> t=s
|
lcp@315
|
311 |
\tdx{trans} [| r=s; s=t |] ==> r=t
|
lcp@315
|
312 |
\tdx{ssubst} [| t=s; P(s) |] ==> P(t::'a)
|
lcp@315
|
313 |
\tdx{box_equals} [| a=b; a=c; b=d |] ==> c=d
|
nipkow@453
|
314 |
\tdx{arg_cong} x=y ==> f(x)=f(y)
|
nipkow@453
|
315 |
\tdx{fun_cong} f=g ==> f(x)=g(x)
|
lcp@104
|
316 |
\subcaption{Equality}
|
lcp@104
|
317 |
|
lcp@315
|
318 |
\tdx{TrueI} True
|
lcp@315
|
319 |
\tdx{FalseE} False ==> P
|
lcp@104
|
320 |
|
lcp@315
|
321 |
\tdx{conjI} [| P; Q |] ==> P&Q
|
lcp@315
|
322 |
\tdx{conjunct1} [| P&Q |] ==> P
|
lcp@315
|
323 |
\tdx{conjunct2} [| P&Q |] ==> Q
|
lcp@315
|
324 |
\tdx{conjE} [| P&Q; [| P; Q |] ==> R |] ==> R
|
lcp@104
|
325 |
|
lcp@315
|
326 |
\tdx{disjI1} P ==> P|Q
|
lcp@315
|
327 |
\tdx{disjI2} Q ==> P|Q
|
lcp@315
|
328 |
\tdx{disjE} [| P | Q; P ==> R; Q ==> R |] ==> R
|
lcp@104
|
329 |
|
lcp@315
|
330 |
\tdx{notI} (P ==> False) ==> ~ P
|
lcp@315
|
331 |
\tdx{notE} [| ~ P; P |] ==> R
|
lcp@315
|
332 |
\tdx{impE} [| P-->Q; P; Q ==> R |] ==> R
|
lcp@104
|
333 |
\subcaption{Propositional logic}
|
lcp@104
|
334 |
|
lcp@315
|
335 |
\tdx{iffI} [| P ==> Q; Q ==> P |] ==> P=Q
|
lcp@315
|
336 |
\tdx{iffD1} [| P=Q; P |] ==> Q
|
lcp@315
|
337 |
\tdx{iffD2} [| P=Q; Q |] ==> P
|
lcp@315
|
338 |
\tdx{iffE} [| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R
|
lcp@104
|
339 |
|
lcp@315
|
340 |
\tdx{eqTrueI} P ==> P=True
|
lcp@315
|
341 |
\tdx{eqTrueE} P=True ==> P
|
lcp@104
|
342 |
\subcaption{Logical equivalence}
|
lcp@104
|
343 |
|
lcp@104
|
344 |
\end{ttbox}
|
wenzelm@9695
|
345 |
\caption{Derived rules for HOL} \label{hol-lemmas1}
|
lcp@104
|
346 |
\end{figure}
|
lcp@104
|
347 |
|
lcp@104
|
348 |
|
lcp@287
|
349 |
\begin{figure}
|
lcp@287
|
350 |
\begin{ttbox}\makeatother
|
lcp@315
|
351 |
\tdx{allI} (!!x::'a. P(x)) ==> !x. P(x)
|
lcp@315
|
352 |
\tdx{spec} !x::'a.P(x) ==> P(x)
|
lcp@315
|
353 |
\tdx{allE} [| !x.P(x); P(x) ==> R |] ==> R
|
lcp@315
|
354 |
\tdx{all_dupE} [| !x.P(x); [| P(x); !x.P(x) |] ==> R |] ==> R
|
lcp@104
|
355 |
|
lcp@315
|
356 |
\tdx{exI} P(x) ==> ? x::'a.P(x)
|
lcp@315
|
357 |
\tdx{exE} [| ? x::'a.P(x); !!x. P(x) ==> Q |] ==> Q
|
lcp@104
|
358 |
|
lcp@315
|
359 |
\tdx{ex1I} [| P(a); !!x. P(x) ==> x=a |] ==> ?! x. P(x)
|
lcp@315
|
360 |
\tdx{ex1E} [| ?! x.P(x); !!x. [| P(x); ! y. P(y) --> y=x |] ==> R
|
lcp@104
|
361 |
|] ==> R
|
lcp@104
|
362 |
|
lcp@315
|
363 |
\tdx{select_equality} [| P(a); !!x. P(x) ==> x=a |] ==> (@x.P(x)) = a
|
lcp@104
|
364 |
\subcaption{Quantifiers and descriptions}
|
lcp@104
|
365 |
|
lcp@315
|
366 |
\tdx{ccontr} (~P ==> False) ==> P
|
lcp@315
|
367 |
\tdx{classical} (~P ==> P) ==> P
|
lcp@315
|
368 |
\tdx{excluded_middle} ~P | P
|
lcp@104
|
369 |
|
lcp@315
|
370 |
\tdx{disjCI} (~Q ==> P) ==> P|Q
|
lcp@315
|
371 |
\tdx{exCI} (! x. ~ P(x) ==> P(a)) ==> ? x.P(x)
|
lcp@315
|
372 |
\tdx{impCE} [| P-->Q; ~ P ==> R; Q ==> R |] ==> R
|
lcp@315
|
373 |
\tdx{iffCE} [| P=Q; [| P;Q |] ==> R; [| ~P; ~Q |] ==> R |] ==> R
|
lcp@315
|
374 |
\tdx{notnotD} ~~P ==> P
|
lcp@315
|
375 |
\tdx{swap} ~P ==> (~Q ==> P) ==> Q
|
lcp@104
|
376 |
\subcaption{Classical logic}
|
lcp@104
|
377 |
|
lcp@315
|
378 |
\tdx{if_True} if(True,x,y) = x
|
lcp@315
|
379 |
\tdx{if_False} if(False,x,y) = y
|
lcp@315
|
380 |
\tdx{if_P} P ==> if(P,x,y) = x
|
lcp@315
|
381 |
\tdx{if_not_P} ~ P ==> if(P,x,y) = y
|
lcp@315
|
382 |
\tdx{expand_if} P(if(Q,x,y)) = ((Q --> P(x)) & (~Q --> P(y)))
|
lcp@104
|
383 |
\subcaption{Conditionals}
|
lcp@104
|
384 |
\end{ttbox}
|
lcp@104
|
385 |
\caption{More derived rules} \label{hol-lemmas2}
|
lcp@104
|
386 |
\end{figure}
|
lcp@104
|
387 |
|
lcp@104
|
388 |
|
lcp@104
|
389 |
Some derived rules are shown in Figures~\ref{hol-lemmas1}
|
lcp@104
|
390 |
and~\ref{hol-lemmas2}, with their {\ML} names. These include natural rules
|
lcp@104
|
391 |
for the logical connectives, as well as sequent-style elimination rules for
|
lcp@104
|
392 |
conjunctions, implications, and universal quantifiers.
|
lcp@104
|
393 |
|
lcp@315
|
394 |
Note the equality rules: \tdx{ssubst} performs substitution in
|
lcp@315
|
395 |
backward proofs, while \tdx{box_equals} supports reasoning by
|
lcp@104
|
396 |
simplifying both sides of an equation.
|
lcp@104
|
397 |
|
lcp@104
|
398 |
|
lcp@104
|
399 |
\begin{figure}
|
lcp@104
|
400 |
\begin{center}
|
lcp@104
|
401 |
\begin{tabular}{rrr}
|
lcp@111
|
402 |
\it name &\it meta-type & \it description \\
|
lcp@315
|
403 |
\index{{}@\verb'{}' symbol}
|
lcp@315
|
404 |
\verb|{}| & $\alpha\,set$ & the empty set \\
|
lcp@315
|
405 |
\cdx{insert} & $[\alpha,\alpha\,set]\To \alpha\,set$
|
lcp@111
|
406 |
& insertion of element \\
|
lcp@315
|
407 |
\cdx{Collect} & $(\alpha\To bool)\To\alpha\,set$
|
lcp@111
|
408 |
& comprehension \\
|
lcp@315
|
409 |
\cdx{Compl} & $(\alpha\,set)\To\alpha\,set$
|
lcp@111
|
410 |
& complement \\
|
lcp@315
|
411 |
\cdx{INTER} & $[\alpha\,set,\alpha\To\beta\,set]\To\beta\,set$
|
lcp@111
|
412 |
& intersection over a set\\
|
lcp@315
|
413 |
\cdx{UNION} & $[\alpha\,set,\alpha\To\beta\,set]\To\beta\,set$
|
lcp@111
|
414 |
& union over a set\\
|
lcp@594
|
415 |
\cdx{Inter} & $(\alpha\,set)set\To\alpha\,set$
|
lcp@111
|
416 |
&set of sets intersection \\
|
lcp@594
|
417 |
\cdx{Union} & $(\alpha\,set)set\To\alpha\,set$
|
lcp@111
|
418 |
&set of sets union \\
|
lcp@594
|
419 |
\cdx{Pow} & $\alpha\,set \To (\alpha\,set)set$
|
lcp@594
|
420 |
& powerset \\[1ex]
|
lcp@315
|
421 |
\cdx{range} & $(\alpha\To\beta )\To\beta\,set$
|
lcp@111
|
422 |
& range of a function \\[1ex]
|
lcp@315
|
423 |
\cdx{Ball}~~\cdx{Bex} & $[\alpha\,set,\alpha\To bool]\To bool$
|
lcp@111
|
424 |
& bounded quantifiers \\
|
lcp@315
|
425 |
\cdx{mono} & $(\alpha\,set\To\beta\,set)\To bool$
|
lcp@111
|
426 |
& monotonicity \\
|
lcp@315
|
427 |
\cdx{inj}~~\cdx{surj}& $(\alpha\To\beta )\To bool$
|
lcp@111
|
428 |
& injective/surjective \\
|
lcp@315
|
429 |
\cdx{inj_onto} & $[\alpha\To\beta ,\alpha\,set]\To bool$
|
lcp@111
|
430 |
& injective over subset
|
lcp@104
|
431 |
\end{tabular}
|
lcp@104
|
432 |
\end{center}
|
lcp@104
|
433 |
\subcaption{Constants}
|
lcp@104
|
434 |
|
lcp@104
|
435 |
\begin{center}
|
lcp@104
|
436 |
\begin{tabular}{llrrr}
|
lcp@315
|
437 |
\it symbol &\it name &\it meta-type & \it priority & \it description \\
|
lcp@315
|
438 |
\sdx{INT} & \cdx{INTER1} & $(\alpha\To\beta\,set)\To\beta\,set$ & 10 &
|
lcp@111
|
439 |
intersection over a type\\
|
lcp@315
|
440 |
\sdx{UN} & \cdx{UNION1} & $(\alpha\To\beta\,set)\To\beta\,set$ & 10 &
|
lcp@111
|
441 |
union over a type
|
lcp@104
|
442 |
\end{tabular}
|
lcp@104
|
443 |
\end{center}
|
lcp@104
|
444 |
\subcaption{Binders}
|
lcp@104
|
445 |
|
lcp@104
|
446 |
\begin{center}
|
lcp@315
|
447 |
\index{*"`"` symbol}
|
lcp@315
|
448 |
\index{*": symbol}
|
lcp@315
|
449 |
\index{*"<"= symbol}
|
lcp@104
|
450 |
\begin{tabular}{rrrr}
|
lcp@315
|
451 |
\it symbol & \it meta-type & \it priority & \it description \\
|
lcp@111
|
452 |
\tt `` & $[\alpha\To\beta ,\alpha\,set]\To (\beta\,set)$
|
lcp@111
|
453 |
& Left 90 & image \\
|
lcp@315
|
454 |
\sdx{Int} & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
|
lcp@111
|
455 |
& Left 70 & intersection ($\inter$) \\
|
lcp@315
|
456 |
\sdx{Un} & $[\alpha\,set,\alpha\,set]\To\alpha\,set$
|
lcp@111
|
457 |
& Left 65 & union ($\union$) \\
|
lcp@111
|
458 |
\tt: & $[\alpha ,\alpha\,set]\To bool$
|
lcp@111
|
459 |
& Left 50 & membership ($\in$) \\
|
lcp@111
|
460 |
\tt <= & $[\alpha\,set,\alpha\,set]\To bool$
|
lcp@111
|
461 |
& Left 50 & subset ($\subseteq$)
|
lcp@104
|
462 |
\end{tabular}
|
lcp@104
|
463 |
\end{center}
|
lcp@104
|
464 |
\subcaption{Infixes}
|
lcp@315
|
465 |
\caption{Syntax of the theory {\tt Set}} \label{hol-set-syntax}
|
lcp@104
|
466 |
\end{figure}
|
lcp@104
|
467 |
|
lcp@104
|
468 |
|
lcp@104
|
469 |
\begin{figure}
|
lcp@104
|
470 |
\begin{center} \tt\frenchspacing
|
lcp@315
|
471 |
\index{*"! symbol}
|
lcp@104
|
472 |
\begin{tabular}{rrr}
|
lcp@111
|
473 |
\it external & \it internal & \it description \\
|
lcp@315
|
474 |
$a$ \ttilde: $b$ & \ttilde($a$ : $b$) & \rm non-membership\\
|
lcp@315
|
475 |
\{$a@1$, $\ldots$\} & insert($a@1$, $\ldots$\{\}) & \rm finite set \\
|
lcp@111
|
476 |
\{$x$.$P[x]$\} & Collect($\lambda x.P[x]$) &
|
lcp@104
|
477 |
\rm comprehension \\
|
lcp@315
|
478 |
\sdx{INT} $x$:$A$.$B[x]$ & INTER($A$,$\lambda x.B[x]$) &
|
lcp@315
|
479 |
\rm intersection \\
|
lcp@315
|
480 |
\sdx{UN}{\tt\ } $x$:$A$.$B[x]$ & UNION($A$,$\lambda x.B[x]$) &
|
lcp@315
|
481 |
\rm union \\
|
lcp@315
|
482 |
\tt ! $x$:$A$.$P[x]$ or \sdx{ALL} $x$:$A$.$P[x]$ &
|
lcp@315
|
483 |
Ball($A$,$\lambda x.P[x]$) &
|
lcp@111
|
484 |
\rm bounded $\forall$ \\
|
lcp@315
|
485 |
\sdx{?} $x$:$A$.$P[x]$ or \sdx{EX}{\tt\ } $x$:$A$.$P[x]$ &
|
lcp@315
|
486 |
Bex($A$,$\lambda x.P[x]$) & \rm bounded $\exists$
|
lcp@104
|
487 |
\end{tabular}
|
lcp@104
|
488 |
\end{center}
|
lcp@104
|
489 |
\subcaption{Translations}
|
lcp@104
|
490 |
|
lcp@104
|
491 |
\dquotes
|
lcp@315
|
492 |
\[\begin{array}{rclcl}
|
lcp@104
|
493 |
term & = & \hbox{other terms\ldots} \\
|
lcp@111
|
494 |
& | & "\{\}" \\
|
lcp@111
|
495 |
& | & "\{ " term\; ("," term)^* " \}" \\
|
lcp@111
|
496 |
& | & "\{ " id " . " formula " \}" \\
|
lcp@111
|
497 |
& | & term " `` " term \\
|
lcp@111
|
498 |
& | & term " Int " term \\
|
lcp@111
|
499 |
& | & term " Un " term \\
|
lcp@111
|
500 |
& | & "INT~~" id ":" term " . " term \\
|
lcp@111
|
501 |
& | & "UN~~~" id ":" term " . " term \\
|
lcp@111
|
502 |
& | & "INT~~" id~id^* " . " term \\
|
lcp@111
|
503 |
& | & "UN~~~" id~id^* " . " term \\[2ex]
|
lcp@104
|
504 |
formula & = & \hbox{other formulae\ldots} \\
|
lcp@111
|
505 |
& | & term " : " term \\
|
lcp@111
|
506 |
& | & term " \ttilde: " term \\
|
lcp@111
|
507 |
& | & term " <= " term \\
|
lcp@315
|
508 |
& | & "!~" id ":" term " . " formula
|
lcp@111
|
509 |
& | & "ALL " id ":" term " . " formula \\
|
lcp@315
|
510 |
& | & "?~" id ":" term " . " formula
|
lcp@111
|
511 |
& | & "EX~~" id ":" term " . " formula
|
lcp@104
|
512 |
\end{array}
|
lcp@104
|
513 |
\]
|
lcp@104
|
514 |
\subcaption{Full Grammar}
|
lcp@315
|
515 |
\caption{Syntax of the theory {\tt Set} (continued)} \label{hol-set-syntax2}
|
lcp@104
|
516 |
\end{figure}
|
lcp@104
|
517 |
|
lcp@104
|
518 |
|
lcp@104
|
519 |
\section{A formulation of set theory}
|
lcp@104
|
520 |
Historically, higher-order logic gives a foundation for Russell and
|
lcp@104
|
521 |
Whitehead's theory of classes. Let us use modern terminology and call them
|
wenzelm@9695
|
522 |
{\bf sets}, but note that these sets are distinct from those of ZF set theory,
|
wenzelm@9695
|
523 |
and behave more like ZF classes.
|
lcp@104
|
524 |
\begin{itemize}
|
lcp@104
|
525 |
\item
|
lcp@104
|
526 |
Sets are given by predicates over some type~$\sigma$. Types serve to
|
lcp@104
|
527 |
define universes for sets, but type checking is still significant.
|
lcp@104
|
528 |
\item
|
lcp@104
|
529 |
There is a universal set (for each type). Thus, sets have complements, and
|
lcp@104
|
530 |
may be defined by absolute comprehension.
|
lcp@104
|
531 |
\item
|
lcp@104
|
532 |
Although sets may contain other sets as elements, the containing set must
|
lcp@104
|
533 |
have a more complex type.
|
lcp@104
|
534 |
\end{itemize}
|
wenzelm@9695
|
535 |
Finite unions and intersections have the same behaviour in HOL as they do
|
wenzelm@9695
|
536 |
in~ZF. In HOL the intersection of the empty set is well-defined, denoting the
|
wenzelm@9695
|
537 |
universal set for the given type.
|
lcp@104
|
538 |
|
lcp@315
|
539 |
|
lcp@315
|
540 |
\subsection{Syntax of set theory}\index{*set type}
|
wenzelm@9695
|
541 |
HOL's set theory is called \thydx{Set}. The type $\alpha\,set$ is essentially
|
wenzelm@9695
|
542 |
the same as $\alpha\To bool$. The new type is defined for clarity and to
|
wenzelm@9695
|
543 |
avoid complications involving function types in unification. Since Isabelle
|
wenzelm@9695
|
544 |
does not support type definitions (as mentioned in \S\ref{HOL-types}), the
|
wenzelm@9695
|
545 |
isomorphisms between the two types are declared explicitly. Here they are
|
wenzelm@9695
|
546 |
natural: {\tt Collect} maps $\alpha\To bool$ to $\alpha\,set$, while \hbox{\tt
|
wenzelm@9695
|
547 |
op :} maps in the other direction (ignoring argument order).
|
lcp@104
|
548 |
|
lcp@104
|
549 |
Figure~\ref{hol-set-syntax} lists the constants, infixes, and syntax
|
lcp@104
|
550 |
translations. Figure~\ref{hol-set-syntax2} presents the grammar of the new
|
lcp@104
|
551 |
constructs. Infix operators include union and intersection ($A\union B$
|
lcp@104
|
552 |
and $A\inter B$), the subset and membership relations, and the image
|
lcp@315
|
553 |
operator~{\tt``}\@. Note that $a$\verb|~:|$b$ is translated to
|
lcp@315
|
554 |
$\neg(a\in b)$.
|
lcp@315
|
555 |
|
lcp@315
|
556 |
The {\tt\{\ldots\}} notation abbreviates finite sets constructed in the
|
lcp@315
|
557 |
obvious manner using~{\tt insert} and~$\{\}$:
|
lcp@104
|
558 |
\begin{eqnarray*}
|
lcp@315
|
559 |
\{a@1, \ldots, a@n\} & \equiv &
|
lcp@315
|
560 |
{\tt insert}(a@1,\ldots,{\tt insert}(a@n,\{\}))
|
lcp@104
|
561 |
\end{eqnarray*}
|
lcp@104
|
562 |
|
wenzelm@9695
|
563 |
The set \hbox{\tt\{$x$.$P[x]$\}} consists of all $x$ (of suitable type) that
|
wenzelm@9695
|
564 |
satisfy~$P[x]$, where $P[x]$ is a formula that may contain free occurrences
|
wenzelm@9695
|
565 |
of~$x$. This syntax expands to \cdx{Collect}$(\lambda x.P[x])$. It defines
|
wenzelm@9695
|
566 |
sets by absolute comprehension, which is impossible in~ZF; the type of~$x$
|
wenzelm@9695
|
567 |
implicitly restricts the comprehension.
|
lcp@104
|
568 |
|
lcp@104
|
569 |
The set theory defines two {\bf bounded quantifiers}:
|
lcp@104
|
570 |
\begin{eqnarray*}
|
lcp@315
|
571 |
\forall x\in A.P[x] &\hbox{abbreviates}& \forall x. x\in A\imp P[x] \\
|
lcp@315
|
572 |
\exists x\in A.P[x] &\hbox{abbreviates}& \exists x. x\in A\conj P[x]
|
lcp@104
|
573 |
\end{eqnarray*}
|
lcp@315
|
574 |
The constants~\cdx{Ball} and~\cdx{Bex} are defined
|
lcp@104
|
575 |
accordingly. Instead of {\tt Ball($A$,$P$)} and {\tt Bex($A$,$P$)} we may
|
lcp@315
|
576 |
write\index{*"! symbol}\index{*"? symbol}
|
lcp@315
|
577 |
\index{*ALL symbol}\index{*EX symbol}
|
lcp@315
|
578 |
%
|
lcp@315
|
579 |
\hbox{\tt !~$x$:$A$.$P[x]$} and \hbox{\tt ?~$x$:$A$.$P[x]$}. Isabelle's
|
lcp@315
|
580 |
usual quantifier symbols, \sdx{ALL} and \sdx{EX}, are also accepted
|
lcp@315
|
581 |
for input. As with the primitive quantifiers, the {\ML} reference
|
lcp@315
|
582 |
\ttindex{HOL_quantifiers} specifies which notation to use for output.
|
lcp@104
|
583 |
|
lcp@104
|
584 |
Unions and intersections over sets, namely $\bigcup@{x\in A}B[x]$ and
|
lcp@104
|
585 |
$\bigcap@{x\in A}B[x]$, are written
|
lcp@315
|
586 |
\sdx{UN}~\hbox{\tt$x$:$A$.$B[x]$} and
|
lcp@315
|
587 |
\sdx{INT}~\hbox{\tt$x$:$A$.$B[x]$}.
|
lcp@104
|
588 |
|
lcp@315
|
589 |
Unions and intersections over types, namely $\bigcup@x B[x]$ and $\bigcap@x
|
lcp@315
|
590 |
B[x]$, are written \sdx{UN}~\hbox{\tt$x$.$B[x]$} and
|
lcp@315
|
591 |
\sdx{INT}~\hbox{\tt$x$.$B[x]$}. They are equivalent to the previous
|
lcp@315
|
592 |
union and intersection operators when $A$ is the universal set.
|
lcp@104
|
593 |
|
lcp@315
|
594 |
The operators $\bigcup A$ and $\bigcap A$ act upon sets of sets. They are
|
lcp@315
|
595 |
not binders, but are equal to $\bigcup@{x\in A}x$ and $\bigcap@{x\in A}x$,
|
lcp@315
|
596 |
respectively.
|
lcp@315
|
597 |
|
lcp@104
|
598 |
|
lcp@287
|
599 |
\begin{figure} \underscoreon
|
lcp@104
|
600 |
\begin{ttbox}
|
lcp@315
|
601 |
\tdx{mem_Collect_eq} (a : \{x.P(x)\}) = P(a)
|
lcp@315
|
602 |
\tdx{Collect_mem_eq} \{x.x:A\} = A
|
lcp@104
|
603 |
|
wenzelm@841
|
604 |
\tdx{empty_def} \{\} == \{x.False\}
|
lcp@315
|
605 |
\tdx{insert_def} insert(a,B) == \{x.x=a\} Un B
|
lcp@315
|
606 |
\tdx{Ball_def} Ball(A,P) == ! x. x:A --> P(x)
|
lcp@315
|
607 |
\tdx{Bex_def} Bex(A,P) == ? x. x:A & P(x)
|
lcp@315
|
608 |
\tdx{subset_def} A <= B == ! x:A. x:B
|
lcp@315
|
609 |
\tdx{Un_def} A Un B == \{x.x:A | x:B\}
|
lcp@315
|
610 |
\tdx{Int_def} A Int B == \{x.x:A & x:B\}
|
lcp@315
|
611 |
\tdx{set_diff_def} A - B == \{x.x:A & x~:B\}
|
lcp@315
|
612 |
\tdx{Compl_def} Compl(A) == \{x. ~ x:A\}
|
lcp@315
|
613 |
\tdx{INTER_def} INTER(A,B) == \{y. ! x:A. y: B(x)\}
|
lcp@315
|
614 |
\tdx{UNION_def} UNION(A,B) == \{y. ? x:A. y: B(x)\}
|
lcp@315
|
615 |
\tdx{INTER1_def} INTER1(B) == INTER(\{x.True\}, B)
|
lcp@315
|
616 |
\tdx{UNION1_def} UNION1(B) == UNION(\{x.True\}, B)
|
lcp@315
|
617 |
\tdx{Inter_def} Inter(S) == (INT x:S. x)
|
lcp@594
|
618 |
\tdx{Union_def} Union(S) == (UN x:S. x)
|
lcp@594
|
619 |
\tdx{Pow_def} Pow(A) == \{B. B <= A\}
|
lcp@315
|
620 |
\tdx{image_def} f``A == \{y. ? x:A. y=f(x)\}
|
lcp@315
|
621 |
\tdx{range_def} range(f) == \{y. ? x. y=f(x)\}
|
lcp@315
|
622 |
\tdx{mono_def} mono(f) == !A B. A <= B --> f(A) <= f(B)
|
lcp@315
|
623 |
\tdx{inj_def} inj(f) == ! x y. f(x)=f(y) --> x=y
|
lcp@315
|
624 |
\tdx{surj_def} surj(f) == ! y. ? x. y=f(x)
|
lcp@315
|
625 |
\tdx{inj_onto_def} inj_onto(f,A) == !x:A. !y:A. f(x)=f(y) --> x=y
|
lcp@315
|
626 |
\end{ttbox}
|
lcp@315
|
627 |
\caption{Rules of the theory {\tt Set}} \label{hol-set-rules}
|
lcp@315
|
628 |
\end{figure}
|
lcp@104
|
629 |
|
lcp@104
|
630 |
|
lcp@315
|
631 |
\begin{figure} \underscoreon
|
lcp@315
|
632 |
\begin{ttbox}
|
lcp@315
|
633 |
\tdx{CollectI} [| P(a) |] ==> a : \{x.P(x)\}
|
lcp@315
|
634 |
\tdx{CollectD} [| a : \{x.P(x)\} |] ==> P(a)
|
lcp@315
|
635 |
\tdx{CollectE} [| a : \{x.P(x)\}; P(a) ==> W |] ==> W
|
lcp@104
|
636 |
|
lcp@315
|
637 |
\tdx{ballI} [| !!x. x:A ==> P(x) |] ==> ! x:A. P(x)
|
lcp@315
|
638 |
\tdx{bspec} [| ! x:A. P(x); x:A |] ==> P(x)
|
lcp@315
|
639 |
\tdx{ballE} [| ! x:A. P(x); P(x) ==> Q; ~ x:A ==> Q |] ==> Q
|
lcp@104
|
640 |
|
lcp@315
|
641 |
\tdx{bexI} [| P(x); x:A |] ==> ? x:A. P(x)
|
lcp@315
|
642 |
\tdx{bexCI} [| ! x:A. ~ P(x) ==> P(a); a:A |] ==> ? x:A.P(x)
|
lcp@315
|
643 |
\tdx{bexE} [| ? x:A. P(x); !!x. [| x:A; P(x) |] ==> Q |] ==> Q
|
lcp@315
|
644 |
\subcaption{Comprehension and Bounded quantifiers}
|
lcp@104
|
645 |
|
lcp@315
|
646 |
\tdx{subsetI} (!!x.x:A ==> x:B) ==> A <= B
|
lcp@315
|
647 |
\tdx{subsetD} [| A <= B; c:A |] ==> c:B
|
lcp@315
|
648 |
\tdx{subsetCE} [| A <= B; ~ (c:A) ==> P; c:B ==> P |] ==> P
|
lcp@104
|
649 |
|
lcp@315
|
650 |
\tdx{subset_refl} A <= A
|
lcp@315
|
651 |
\tdx{subset_trans} [| A<=B; B<=C |] ==> A<=C
|
lcp@315
|
652 |
|
lcp@471
|
653 |
\tdx{equalityI} [| A <= B; B <= A |] ==> A = B
|
lcp@315
|
654 |
\tdx{equalityD1} A = B ==> A<=B
|
lcp@315
|
655 |
\tdx{equalityD2} A = B ==> B<=A
|
lcp@315
|
656 |
\tdx{equalityE} [| A = B; [| A<=B; B<=A |] ==> P |] ==> P
|
lcp@315
|
657 |
|
lcp@315
|
658 |
\tdx{equalityCE} [| A = B; [| c:A; c:B |] ==> P;
|
lcp@315
|
659 |
[| ~ c:A; ~ c:B |] ==> P
|
lcp@315
|
660 |
|] ==> P
|
lcp@315
|
661 |
\subcaption{The subset and equality relations}
|
lcp@315
|
662 |
\end{ttbox}
|
lcp@315
|
663 |
\caption{Derived rules for set theory} \label{hol-set1}
|
lcp@315
|
664 |
\end{figure}
|
lcp@315
|
665 |
|
lcp@315
|
666 |
|
lcp@315
|
667 |
\begin{figure} \underscoreon
|
lcp@315
|
668 |
\begin{ttbox}
|
lcp@315
|
669 |
\tdx{emptyE} a : \{\} ==> P
|
lcp@315
|
670 |
|
lcp@315
|
671 |
\tdx{insertI1} a : insert(a,B)
|
lcp@315
|
672 |
\tdx{insertI2} a : B ==> a : insert(b,B)
|
lcp@315
|
673 |
\tdx{insertE} [| a : insert(b,A); a=b ==> P; a:A ==> P |] ==> P
|
lcp@315
|
674 |
|
lcp@315
|
675 |
\tdx{ComplI} [| c:A ==> False |] ==> c : Compl(A)
|
lcp@315
|
676 |
\tdx{ComplD} [| c : Compl(A) |] ==> ~ c:A
|
lcp@315
|
677 |
|
lcp@315
|
678 |
\tdx{UnI1} c:A ==> c : A Un B
|
lcp@315
|
679 |
\tdx{UnI2} c:B ==> c : A Un B
|
lcp@315
|
680 |
\tdx{UnCI} (~c:B ==> c:A) ==> c : A Un B
|
lcp@315
|
681 |
\tdx{UnE} [| c : A Un B; c:A ==> P; c:B ==> P |] ==> P
|
lcp@315
|
682 |
|
lcp@315
|
683 |
\tdx{IntI} [| c:A; c:B |] ==> c : A Int B
|
lcp@315
|
684 |
\tdx{IntD1} c : A Int B ==> c:A
|
lcp@315
|
685 |
\tdx{IntD2} c : A Int B ==> c:B
|
lcp@315
|
686 |
\tdx{IntE} [| c : A Int B; [| c:A; c:B |] ==> P |] ==> P
|
lcp@315
|
687 |
|
lcp@315
|
688 |
\tdx{UN_I} [| a:A; b: B(a) |] ==> b: (UN x:A. B(x))
|
lcp@315
|
689 |
\tdx{UN_E} [| b: (UN x:A. B(x)); !!x.[| x:A; b:B(x) |] ==> R |] ==> R
|
lcp@315
|
690 |
|
lcp@315
|
691 |
\tdx{INT_I} (!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))
|
lcp@315
|
692 |
\tdx{INT_D} [| b: (INT x:A. B(x)); a:A |] ==> b: B(a)
|
lcp@315
|
693 |
\tdx{INT_E} [| b: (INT x:A. B(x)); b: B(a) ==> R; ~ a:A ==> R |] ==> R
|
lcp@315
|
694 |
|
lcp@315
|
695 |
\tdx{UnionI} [| X:C; A:X |] ==> A : Union(C)
|
lcp@315
|
696 |
\tdx{UnionE} [| A : Union(C); !!X.[| A:X; X:C |] ==> R |] ==> R
|
lcp@315
|
697 |
|
lcp@315
|
698 |
\tdx{InterI} [| !!X. X:C ==> A:X |] ==> A : Inter(C)
|
lcp@315
|
699 |
\tdx{InterD} [| A : Inter(C); X:C |] ==> A:X
|
lcp@315
|
700 |
\tdx{InterE} [| A : Inter(C); A:X ==> R; ~ X:C ==> R |] ==> R
|
lcp@594
|
701 |
|
lcp@594
|
702 |
\tdx{PowI} A<=B ==> A: Pow(B)
|
lcp@594
|
703 |
\tdx{PowD} A: Pow(B) ==> A<=B
|
lcp@315
|
704 |
\end{ttbox}
|
lcp@315
|
705 |
\caption{Further derived rules for set theory} \label{hol-set2}
|
lcp@315
|
706 |
\end{figure}
|
lcp@315
|
707 |
|
lcp@315
|
708 |
|
lcp@315
|
709 |
\subsection{Axioms and rules of set theory}
|
lcp@315
|
710 |
Figure~\ref{hol-set-rules} presents the rules of theory \thydx{Set}. The
|
lcp@315
|
711 |
axioms \tdx{mem_Collect_eq} and \tdx{Collect_mem_eq} assert
|
lcp@315
|
712 |
that the functions {\tt Collect} and \hbox{\tt op :} are isomorphisms. Of
|
lcp@315
|
713 |
course, \hbox{\tt op :} also serves as the membership relation.
|
lcp@315
|
714 |
|
lcp@315
|
715 |
All the other axioms are definitions. They include the empty set, bounded
|
lcp@315
|
716 |
quantifiers, unions, intersections, complements and the subset relation.
|
lcp@315
|
717 |
They also include straightforward properties of functions: image~({\tt``}) and
|
lcp@315
|
718 |
{\tt range}, and predicates concerning monotonicity, injectiveness and
|
lcp@315
|
719 |
surjectiveness.
|
lcp@315
|
720 |
|
lcp@315
|
721 |
The predicate \cdx{inj_onto} is used for simulating type definitions.
|
lcp@315
|
722 |
The statement ${\tt inj_onto}(f,A)$ asserts that $f$ is injective on the
|
lcp@315
|
723 |
set~$A$, which specifies a subset of its domain type. In a type
|
lcp@315
|
724 |
definition, $f$ is the abstraction function and $A$ is the set of valid
|
lcp@315
|
725 |
representations; we should not expect $f$ to be injective outside of~$A$.
|
lcp@315
|
726 |
|
lcp@315
|
727 |
\begin{figure} \underscoreon
|
lcp@315
|
728 |
\begin{ttbox}
|
lcp@315
|
729 |
\tdx{Inv_f_f} inj(f) ==> Inv(f,f(x)) = x
|
lcp@315
|
730 |
\tdx{f_Inv_f} y : range(f) ==> f(Inv(f,y)) = y
|
lcp@315
|
731 |
|
lcp@315
|
732 |
%\tdx{Inv_injective}
|
lcp@315
|
733 |
% [| Inv(f,x)=Inv(f,y); x: range(f); y: range(f) |] ==> x=y
|
lcp@315
|
734 |
%
|
lcp@315
|
735 |
\tdx{imageI} [| x:A |] ==> f(x) : f``A
|
lcp@315
|
736 |
\tdx{imageE} [| b : f``A; !!x.[| b=f(x); x:A |] ==> P |] ==> P
|
lcp@315
|
737 |
|
lcp@315
|
738 |
\tdx{rangeI} f(x) : range(f)
|
lcp@315
|
739 |
\tdx{rangeE} [| b : range(f); !!x.[| b=f(x) |] ==> P |] ==> P
|
lcp@315
|
740 |
|
lcp@315
|
741 |
\tdx{monoI} [| !!A B. A <= B ==> f(A) <= f(B) |] ==> mono(f)
|
lcp@315
|
742 |
\tdx{monoD} [| mono(f); A <= B |] ==> f(A) <= f(B)
|
lcp@315
|
743 |
|
lcp@315
|
744 |
\tdx{injI} [| !! x y. f(x) = f(y) ==> x=y |] ==> inj(f)
|
lcp@315
|
745 |
\tdx{inj_inverseI} (!!x. g(f(x)) = x) ==> inj(f)
|
lcp@315
|
746 |
\tdx{injD} [| inj(f); f(x) = f(y) |] ==> x=y
|
lcp@315
|
747 |
|
lcp@315
|
748 |
\tdx{inj_ontoI} (!!x y. [| f(x)=f(y); x:A; y:A |] ==> x=y) ==> inj_onto(f,A)
|
lcp@315
|
749 |
\tdx{inj_ontoD} [| inj_onto(f,A); f(x)=f(y); x:A; y:A |] ==> x=y
|
lcp@315
|
750 |
|
lcp@315
|
751 |
\tdx{inj_onto_inverseI}
|
lcp@104
|
752 |
(!!x. x:A ==> g(f(x)) = x) ==> inj_onto(f,A)
|
lcp@315
|
753 |
\tdx{inj_onto_contraD}
|
lcp@104
|
754 |
[| inj_onto(f,A); x~=y; x:A; y:A |] ==> ~ f(x)=f(y)
|
lcp@104
|
755 |
\end{ttbox}
|
lcp@104
|
756 |
\caption{Derived rules involving functions} \label{hol-fun}
|
lcp@104
|
757 |
\end{figure}
|
lcp@104
|
758 |
|
lcp@104
|
759 |
|
lcp@287
|
760 |
\begin{figure} \underscoreon
|
lcp@104
|
761 |
\begin{ttbox}
|
lcp@315
|
762 |
\tdx{Union_upper} B:A ==> B <= Union(A)
|
lcp@315
|
763 |
\tdx{Union_least} [| !!X. X:A ==> X<=C |] ==> Union(A) <= C
|
lcp@104
|
764 |
|
lcp@315
|
765 |
\tdx{Inter_lower} B:A ==> Inter(A) <= B
|
lcp@315
|
766 |
\tdx{Inter_greatest} [| !!X. X:A ==> C<=X |] ==> C <= Inter(A)
|
lcp@104
|
767 |
|
lcp@315
|
768 |
\tdx{Un_upper1} A <= A Un B
|
lcp@315
|
769 |
\tdx{Un_upper2} B <= A Un B
|
lcp@315
|
770 |
\tdx{Un_least} [| A<=C; B<=C |] ==> A Un B <= C
|
lcp@104
|
771 |
|
lcp@315
|
772 |
\tdx{Int_lower1} A Int B <= A
|
lcp@315
|
773 |
\tdx{Int_lower2} A Int B <= B
|
lcp@315
|
774 |
\tdx{Int_greatest} [| C<=A; C<=B |] ==> C <= A Int B
|
lcp@104
|
775 |
\end{ttbox}
|
lcp@104
|
776 |
\caption{Derived rules involving subsets} \label{hol-subset}
|
lcp@104
|
777 |
\end{figure}
|
lcp@104
|
778 |
|
lcp@104
|
779 |
|
lcp@315
|
780 |
\begin{figure} \underscoreon \hfuzz=4pt%suppress "Overfull \hbox" message
|
lcp@104
|
781 |
\begin{ttbox}
|
lcp@315
|
782 |
\tdx{Int_absorb} A Int A = A
|
lcp@315
|
783 |
\tdx{Int_commute} A Int B = B Int A
|
lcp@315
|
784 |
\tdx{Int_assoc} (A Int B) Int C = A Int (B Int C)
|
lcp@315
|
785 |
\tdx{Int_Un_distrib} (A Un B) Int C = (A Int C) Un (B Int C)
|
lcp@104
|
786 |
|
lcp@315
|
787 |
\tdx{Un_absorb} A Un A = A
|
lcp@315
|
788 |
\tdx{Un_commute} A Un B = B Un A
|
lcp@315
|
789 |
\tdx{Un_assoc} (A Un B) Un C = A Un (B Un C)
|
lcp@315
|
790 |
\tdx{Un_Int_distrib} (A Int B) Un C = (A Un C) Int (B Un C)
|
lcp@104
|
791 |
|
lcp@315
|
792 |
\tdx{Compl_disjoint} A Int Compl(A) = \{x.False\}
|
lcp@315
|
793 |
\tdx{Compl_partition} A Un Compl(A) = \{x.True\}
|
lcp@315
|
794 |
\tdx{double_complement} Compl(Compl(A)) = A
|
lcp@315
|
795 |
\tdx{Compl_Un} Compl(A Un B) = Compl(A) Int Compl(B)
|
lcp@315
|
796 |
\tdx{Compl_Int} Compl(A Int B) = Compl(A) Un Compl(B)
|
lcp@104
|
797 |
|
lcp@315
|
798 |
\tdx{Union_Un_distrib} Union(A Un B) = Union(A) Un Union(B)
|
lcp@315
|
799 |
\tdx{Int_Union} A Int Union(B) = (UN C:B. A Int C)
|
lcp@315
|
800 |
\tdx{Un_Union_image} (UN x:C. A(x) Un B(x)) = Union(A``C) Un Union(B``C)
|
lcp@104
|
801 |
|
lcp@315
|
802 |
\tdx{Inter_Un_distrib} Inter(A Un B) = Inter(A) Int Inter(B)
|
lcp@315
|
803 |
\tdx{Un_Inter} A Un Inter(B) = (INT C:B. A Un C)
|
lcp@315
|
804 |
\tdx{Int_Inter_image} (INT x:C. A(x) Int B(x)) = Inter(A``C) Int Inter(B``C)
|
lcp@104
|
805 |
\end{ttbox}
|
lcp@104
|
806 |
\caption{Set equalities} \label{hol-equalities}
|
lcp@104
|
807 |
\end{figure}
|
lcp@104
|
808 |
|
lcp@104
|
809 |
|
lcp@315
|
810 |
Figures~\ref{hol-set1} and~\ref{hol-set2} present derived rules. Most are
|
wenzelm@9695
|
811 |
obvious and resemble rules of Isabelle's ZF set theory. Certain rules, such
|
wenzelm@9695
|
812 |
as \tdx{subsetCE}, \tdx{bexCI} and \tdx{UnCI}, are designed for classical
|
wenzelm@9695
|
813 |
reasoning; the rules \tdx{subsetD}, \tdx{bexI}, \tdx{Un1} and~\tdx{Un2} are
|
wenzelm@9695
|
814 |
not strictly necessary but yield more natural proofs. Similarly,
|
wenzelm@9695
|
815 |
\tdx{equalityCE} supports classical reasoning about extensionality, after the
|
wenzelm@9695
|
816 |
fashion of \tdx{iffCE}. See the file {\tt HOL/Set.ML} for proofs pertaining
|
wenzelm@9695
|
817 |
to set theory.
|
lcp@104
|
818 |
|
lcp@315
|
819 |
Figure~\ref{hol-fun} presents derived inference rules involving functions.
|
lcp@315
|
820 |
They also include rules for \cdx{Inv}, which is defined in theory~{\tt
|
lcp@315
|
821 |
HOL}; note that ${\tt Inv}(f)$ applies the Axiom of Choice to yield an
|
lcp@315
|
822 |
inverse of~$f$. They also include natural deduction rules for the image
|
lcp@315
|
823 |
and range operators, and for the predicates {\tt inj} and {\tt inj_onto}.
|
lcp@315
|
824 |
Reasoning about function composition (the operator~\sdx{o}) and the
|
lcp@315
|
825 |
predicate~\cdx{surj} is done simply by expanding the definitions. See
|
lcp@315
|
826 |
the file {\tt HOL/fun.ML} for a complete listing of the derived rules.
|
lcp@104
|
827 |
|
lcp@104
|
828 |
Figure~\ref{hol-subset} presents lattice properties of the subset relation.
|
lcp@315
|
829 |
Unions form least upper bounds; non-empty intersections form greatest lower
|
lcp@315
|
830 |
bounds. Reasoning directly about subsets often yields clearer proofs than
|
lcp@315
|
831 |
reasoning about the membership relation. See the file {\tt HOL/subset.ML}.
|
lcp@104
|
832 |
|
lcp@315
|
833 |
Figure~\ref{hol-equalities} presents many common set equalities. They
|
lcp@315
|
834 |
include commutative, associative and distributive laws involving unions,
|
lcp@315
|
835 |
intersections and complements. The proofs are mostly trivial, using the
|
lcp@315
|
836 |
classical reasoner; see file {\tt HOL/equalities.ML}.
|
lcp@104
|
837 |
|
lcp@104
|
838 |
|
lcp@287
|
839 |
\begin{figure}
|
lcp@315
|
840 |
\begin{constants}
|
lcp@344
|
841 |
\it symbol & \it meta-type & & \it description \\
|
lcp@315
|
842 |
\cdx{Pair} & $[\alpha,\beta]\To \alpha\times\beta$
|
lcp@315
|
843 |
& & ordered pairs $\langle a,b\rangle$ \\
|
lcp@315
|
844 |
\cdx{fst} & $\alpha\times\beta \To \alpha$ & & first projection\\
|
lcp@315
|
845 |
\cdx{snd} & $\alpha\times\beta \To \beta$ & & second projection\\
|
lcp@705
|
846 |
\cdx{split} & $[[\alpha,\beta]\To\gamma, \alpha\times\beta] \To \gamma$
|
lcp@315
|
847 |
& & generalized projection\\
|
lcp@315
|
848 |
\cdx{Sigma} &
|
lcp@287
|
849 |
$[\alpha\,set, \alpha\To\beta\,set]\To(\alpha\times\beta)set$ &
|
lcp@315
|
850 |
& general sum of sets
|
lcp@315
|
851 |
\end{constants}
|
lcp@315
|
852 |
\begin{ttbox}\makeatletter
|
lcp@315
|
853 |
\tdx{fst_def} fst(p) == @a. ? b. p = <a,b>
|
lcp@315
|
854 |
\tdx{snd_def} snd(p) == @b. ? a. p = <a,b>
|
lcp@705
|
855 |
\tdx{split_def} split(c,p) == c(fst(p),snd(p))
|
lcp@315
|
856 |
\tdx{Sigma_def} Sigma(A,B) == UN x:A. UN y:B(x). \{<x,y>\}
|
lcp@104
|
857 |
|
lcp@104
|
858 |
|
lcp@315
|
859 |
\tdx{Pair_inject} [| <a, b> = <a',b'>; [| a=a'; b=b' |] ==> R |] ==> R
|
lcp@349
|
860 |
\tdx{fst_conv} fst(<a,b>) = a
|
lcp@349
|
861 |
\tdx{snd_conv} snd(<a,b>) = b
|
lcp@705
|
862 |
\tdx{split} split(c, <a,b>) = c(a,b)
|
lcp@104
|
863 |
|
lcp@315
|
864 |
\tdx{surjective_pairing} p = <fst(p),snd(p)>
|
lcp@104
|
865 |
|
lcp@315
|
866 |
\tdx{SigmaI} [| a:A; b:B(a) |] ==> <a,b> : Sigma(A,B)
|
lcp@287
|
867 |
|
lcp@315
|
868 |
\tdx{SigmaE} [| c: Sigma(A,B);
|
lcp@287
|
869 |
!!x y.[| x:A; y:B(x); c=<x,y> |] ==> P |] ==> P
|
lcp@104
|
870 |
\end{ttbox}
|
lcp@315
|
871 |
\caption{Type $\alpha\times\beta$}\label{hol-prod}
|
lcp@104
|
872 |
\end{figure}
|
lcp@104
|
873 |
|
lcp@104
|
874 |
|
lcp@287
|
875 |
\begin{figure}
|
lcp@315
|
876 |
\begin{constants}
|
lcp@344
|
877 |
\it symbol & \it meta-type & & \it description \\
|
lcp@315
|
878 |
\cdx{Inl} & $\alpha \To \alpha+\beta$ & & first injection\\
|
lcp@315
|
879 |
\cdx{Inr} & $\beta \To \alpha+\beta$ & & second injection\\
|
lcp@705
|
880 |
\cdx{sum_case} & $[\alpha\To\gamma, \beta\To\gamma, \alpha+\beta] \To\gamma$
|
lcp@315
|
881 |
& & conditional
|
lcp@315
|
882 |
\end{constants}
|
lcp@315
|
883 |
\begin{ttbox}\makeatletter
|
lcp@705
|
884 |
\tdx{sum_case_def} sum_case == (\%f g p. @z. (!x. p=Inl(x) --> z=f(x)) &
|
lcp@315
|
885 |
(!y. p=Inr(y) --> z=g(y)))
|
lcp@104
|
886 |
|
lcp@315
|
887 |
\tdx{Inl_not_Inr} ~ Inl(a)=Inr(b)
|
lcp@104
|
888 |
|
lcp@315
|
889 |
\tdx{inj_Inl} inj(Inl)
|
lcp@315
|
890 |
\tdx{inj_Inr} inj(Inr)
|
lcp@104
|
891 |
|
lcp@315
|
892 |
\tdx{sumE} [| !!x::'a. P(Inl(x)); !!y::'b. P(Inr(y)) |] ==> P(s)
|
lcp@104
|
893 |
|
lcp@705
|
894 |
\tdx{sum_case_Inl} sum_case(f, g, Inl(x)) = f(x)
|
lcp@705
|
895 |
\tdx{sum_case_Inr} sum_case(f, g, Inr(x)) = g(x)
|
lcp@104
|
896 |
|
lcp@705
|
897 |
\tdx{surjective_sum} sum_case(\%x::'a. f(Inl(x)), \%y::'b. f(Inr(y)), s) = f(s)
|
lcp@104
|
898 |
\end{ttbox}
|
lcp@315
|
899 |
\caption{Type $\alpha+\beta$}\label{hol-sum}
|
lcp@104
|
900 |
\end{figure}
|
lcp@104
|
901 |
|
lcp@104
|
902 |
|
lcp@344
|
903 |
\section{Generic packages and classical reasoning}
|
wenzelm@9695
|
904 |
HOL instantiates most of Isabelle's generic packages; see {\tt HOL/ROOT.ML}
|
wenzelm@9695
|
905 |
for details.
|
lcp@344
|
906 |
\begin{itemize}
|
wenzelm@9695
|
907 |
\item Because it includes a general substitution rule, HOL instantiates the
|
wenzelm@9695
|
908 |
tactic {\tt hyp_subst_tac}, which substitutes for an equality throughout a
|
wenzelm@9695
|
909 |
subgoal and its hypotheses.
|
lcp@344
|
910 |
\item
|
lcp@344
|
911 |
It instantiates the simplifier, defining~\ttindexbold{HOL_ss} as the
|
lcp@344
|
912 |
simplification set for higher-order logic. Equality~($=$), which also
|
lcp@344
|
913 |
expresses logical equivalence, may be used for rewriting. See the file
|
lcp@344
|
914 |
{\tt HOL/simpdata.ML} for a complete listing of the simplification
|
lcp@344
|
915 |
rules.
|
lcp@344
|
916 |
\item
|
lcp@344
|
917 |
It instantiates the classical reasoner, as described below.
|
lcp@344
|
918 |
\end{itemize}
|
wenzelm@9695
|
919 |
HOL derives classical introduction rules for $\disj$ and~$\exists$, as well as
|
wenzelm@9695
|
920 |
classical elimination rules for~$\imp$ and~$\bimp$, and the swap rule; recall
|
wenzelm@9695
|
921 |
Fig.\ts\ref{hol-lemmas2} above.
|
lcp@344
|
922 |
|
wenzelm@9695
|
923 |
The classical reasoner is set up as the structure {\tt Classical}. This
|
wenzelm@9695
|
924 |
structure is open, so {\ML} identifiers such as {\tt step_tac}, {\tt
|
wenzelm@9695
|
925 |
fast_tac}, {\tt best_tac}, etc., refer to it. HOL defines the following
|
wenzelm@9695
|
926 |
classical rule sets:
|
lcp@344
|
927 |
\begin{ttbox}
|
lcp@344
|
928 |
prop_cs : claset
|
lcp@344
|
929 |
HOL_cs : claset
|
lcp@344
|
930 |
set_cs : claset
|
lcp@344
|
931 |
\end{ttbox}
|
lcp@344
|
932 |
\begin{ttdescription}
|
lcp@344
|
933 |
\item[\ttindexbold{prop_cs}] contains the propositional rules, namely
|
lcp@344
|
934 |
those for~$\top$, $\bot$, $\conj$, $\disj$, $\neg$, $\imp$ and~$\bimp$,
|
lcp@344
|
935 |
along with the rule~{\tt refl}.
|
lcp@344
|
936 |
|
lcp@344
|
937 |
\item[\ttindexbold{HOL_cs}] extends {\tt prop_cs} with the safe rules
|
lcp@344
|
938 |
{\tt allI} and~{\tt exE} and the unsafe rules {\tt allE}
|
lcp@344
|
939 |
and~{\tt exI}, as well as rules for unique existence. Search using
|
lcp@344
|
940 |
this classical set is incomplete: quantified formulae are used at most
|
lcp@344
|
941 |
once.
|
lcp@344
|
942 |
|
lcp@344
|
943 |
\item[\ttindexbold{set_cs}] extends {\tt HOL_cs} with rules for the bounded
|
lcp@344
|
944 |
quantifiers, subsets, comprehensions, unions and intersections,
|
lcp@344
|
945 |
complements, finite sets, images and ranges.
|
lcp@344
|
946 |
\end{ttdescription}
|
lcp@344
|
947 |
\noindent
|
lcp@344
|
948 |
See \iflabelundefined{chap:classical}{the {\em Reference Manual\/}}%
|
lcp@344
|
949 |
{Chap.\ts\ref{chap:classical}}
|
lcp@344
|
950 |
for more discussion of classical proof methods.
|
lcp@344
|
951 |
|
lcp@344
|
952 |
|
lcp@104
|
953 |
\section{Types}
|
lcp@104
|
954 |
The basic higher-order logic is augmented with a tremendous amount of
|
lcp@315
|
955 |
material, including support for recursive function and type definitions. A
|
lcp@315
|
956 |
detailed discussion appears elsewhere~\cite{paulson-coind}. The simpler
|
lcp@315
|
957 |
definitions are the same as those used the {\sc hol} system, but my
|
lcp@315
|
958 |
treatment of recursive types differs from Melham's~\cite{melham89}. The
|
lcp@315
|
959 |
present section describes product, sum, natural number and list types.
|
lcp@104
|
960 |
|
lcp@315
|
961 |
\subsection{Product and sum types}\index{*"* type}\index{*"+ type}
|
lcp@315
|
962 |
Theory \thydx{Prod} defines the product type $\alpha\times\beta$, with
|
lcp@315
|
963 |
the ordered pair syntax {\tt<$a$,$b$>}. Theory \thydx{Sum} defines the
|
lcp@315
|
964 |
sum type $\alpha+\beta$. These use fairly standard constructions; see
|
lcp@315
|
965 |
Figs.\ts\ref{hol-prod} and~\ref{hol-sum}. Because Isabelle does not
|
lcp@315
|
966 |
support abstract type definitions, the isomorphisms between these types and
|
lcp@315
|
967 |
their representations are made explicitly.
|
lcp@104
|
968 |
|
lcp@104
|
969 |
Most of the definitions are suppressed, but observe that the projections
|
lcp@104
|
970 |
and conditionals are defined as descriptions. Their properties are easily
|
lcp@344
|
971 |
proved using \tdx{select_equality}.
|
lcp@104
|
972 |
|
lcp@287
|
973 |
\begin{figure}
|
lcp@315
|
974 |
\index{*"< symbol}
|
lcp@315
|
975 |
\index{*"* symbol}
|
lcp@344
|
976 |
\index{*div symbol}
|
lcp@344
|
977 |
\index{*mod symbol}
|
lcp@315
|
978 |
\index{*"+ symbol}
|
lcp@315
|
979 |
\index{*"- symbol}
|
lcp@315
|
980 |
\begin{constants}
|
lcp@315
|
981 |
\it symbol & \it meta-type & \it priority & \it description \\
|
lcp@315
|
982 |
\cdx{0} & $nat$ & & zero \\
|
lcp@315
|
983 |
\cdx{Suc} & $nat \To nat$ & & successor function\\
|
lcp@705
|
984 |
\cdx{nat_case} & $[\alpha, nat\To\alpha, nat] \To\alpha$
|
lcp@315
|
985 |
& & conditional\\
|
lcp@315
|
986 |
\cdx{nat_rec} & $[nat, \alpha, [nat, \alpha]\To\alpha] \To \alpha$
|
lcp@315
|
987 |
& & primitive recursor\\
|
lcp@315
|
988 |
\cdx{pred_nat} & $(nat\times nat) set$ & & predecessor relation\\
|
lcp@111
|
989 |
\tt * & $[nat,nat]\To nat$ & Left 70 & multiplication \\
|
lcp@344
|
990 |
\tt div & $[nat,nat]\To nat$ & Left 70 & division\\
|
lcp@344
|
991 |
\tt mod & $[nat,nat]\To nat$ & Left 70 & modulus\\
|
lcp@111
|
992 |
\tt + & $[nat,nat]\To nat$ & Left 65 & addition\\
|
lcp@111
|
993 |
\tt - & $[nat,nat]\To nat$ & Left 65 & subtraction
|
lcp@315
|
994 |
\end{constants}
|
lcp@104
|
995 |
\subcaption{Constants and infixes}
|
lcp@104
|
996 |
|
lcp@287
|
997 |
\begin{ttbox}\makeatother
|
lcp@705
|
998 |
\tdx{nat_case_def} nat_case == (\%a f n. @z. (n=0 --> z=a) &
|
lcp@344
|
999 |
(!x. n=Suc(x) --> z=f(x)))
|
lcp@315
|
1000 |
\tdx{pred_nat_def} pred_nat == \{p. ? n. p = <n, Suc(n)>\}
|
lcp@315
|
1001 |
\tdx{less_def} m<n == <m,n>:pred_nat^+
|
lcp@315
|
1002 |
\tdx{nat_rec_def} nat_rec(n,c,d) ==
|
lcp@705
|
1003 |
wfrec(pred_nat, n, nat_case(\%g.c, \%m g. d(m,g(m))))
|
lcp@104
|
1004 |
|
lcp@344
|
1005 |
\tdx{add_def} m+n == nat_rec(m, n, \%u v.Suc(v))
|
lcp@344
|
1006 |
\tdx{diff_def} m-n == nat_rec(n, m, \%u v. nat_rec(v, 0, \%x y.x))
|
lcp@344
|
1007 |
\tdx{mult_def} m*n == nat_rec(m, 0, \%u v. n + v)
|
lcp@344
|
1008 |
\tdx{mod_def} m mod n == wfrec(trancl(pred_nat), m, \%j f. if(j<n,j,f(j-n)))
|
lcp@344
|
1009 |
\tdx{quo_def} m div n == wfrec(trancl(pred_nat),
|
lcp@287
|
1010 |
m, \%j f. if(j<n,0,Suc(f(j-n))))
|
lcp@104
|
1011 |
\subcaption{Definitions}
|
lcp@104
|
1012 |
\end{ttbox}
|
lcp@315
|
1013 |
\caption{Defining {\tt nat}, the type of natural numbers} \label{hol-nat1}
|
lcp@104
|
1014 |
\end{figure}
|
lcp@104
|
1015 |
|
lcp@104
|
1016 |
|
lcp@287
|
1017 |
\begin{figure} \underscoreon
|
lcp@104
|
1018 |
\begin{ttbox}
|
lcp@315
|
1019 |
\tdx{nat_induct} [| P(0); !!k. [| P(k) |] ==> P(Suc(k)) |] ==> P(n)
|
lcp@104
|
1020 |
|
lcp@315
|
1021 |
\tdx{Suc_not_Zero} Suc(m) ~= 0
|
lcp@315
|
1022 |
\tdx{inj_Suc} inj(Suc)
|
lcp@315
|
1023 |
\tdx{n_not_Suc_n} n~=Suc(n)
|
lcp@104
|
1024 |
\subcaption{Basic properties}
|
lcp@104
|
1025 |
|
lcp@315
|
1026 |
\tdx{pred_natI} <n, Suc(n)> : pred_nat
|
lcp@315
|
1027 |
\tdx{pred_natE}
|
lcp@104
|
1028 |
[| p : pred_nat; !!x n. [| p = <n, Suc(n)> |] ==> R |] ==> R
|
lcp@104
|
1029 |
|
lcp@705
|
1030 |
\tdx{nat_case_0} nat_case(a, f, 0) = a
|
lcp@705
|
1031 |
\tdx{nat_case_Suc} nat_case(a, f, Suc(k)) = f(k)
|
lcp@104
|
1032 |
|
lcp@315
|
1033 |
\tdx{wf_pred_nat} wf(pred_nat)
|
lcp@315
|
1034 |
\tdx{nat_rec_0} nat_rec(0,c,h) = c
|
lcp@315
|
1035 |
\tdx{nat_rec_Suc} nat_rec(Suc(n), c, h) = h(n, nat_rec(n,c,h))
|
lcp@104
|
1036 |
\subcaption{Case analysis and primitive recursion}
|
lcp@104
|
1037 |
|
lcp@315
|
1038 |
\tdx{less_trans} [| i<j; j<k |] ==> i<k
|
lcp@315
|
1039 |
\tdx{lessI} n < Suc(n)
|
lcp@315
|
1040 |
\tdx{zero_less_Suc} 0 < Suc(n)
|
lcp@104
|
1041 |
|
lcp@315
|
1042 |
\tdx{less_not_sym} n<m --> ~ m<n
|
lcp@315
|
1043 |
\tdx{less_not_refl} ~ n<n
|
lcp@315
|
1044 |
\tdx{not_less0} ~ n<0
|
lcp@104
|
1045 |
|
lcp@315
|
1046 |
\tdx{Suc_less_eq} (Suc(m) < Suc(n)) = (m<n)
|
lcp@315
|
1047 |
\tdx{less_induct} [| !!n. [| ! m. m<n --> P(m) |] ==> P(n) |] ==> P(n)
|
lcp@104
|
1048 |
|
lcp@315
|
1049 |
\tdx{less_linear} m<n | m=n | n<m
|
lcp@104
|
1050 |
\subcaption{The less-than relation}
|
lcp@104
|
1051 |
\end{ttbox}
|
lcp@344
|
1052 |
\caption{Derived rules for {\tt nat}} \label{hol-nat2}
|
lcp@104
|
1053 |
\end{figure}
|
lcp@104
|
1054 |
|
lcp@104
|
1055 |
|
lcp@315
|
1056 |
\subsection{The type of natural numbers, {\tt nat}}
|
lcp@315
|
1057 |
The theory \thydx{Nat} defines the natural numbers in a roundabout but
|
lcp@315
|
1058 |
traditional way. The axiom of infinity postulates an type~\tydx{ind} of
|
lcp@315
|
1059 |
individuals, which is non-empty and closed under an injective operation.
|
lcp@315
|
1060 |
The natural numbers are inductively generated by choosing an arbitrary
|
lcp@315
|
1061 |
individual for~0 and using the injective operation to take successors. As
|
lcp@344
|
1062 |
usual, the isomorphisms between~\tydx{nat} and its representation are made
|
lcp@315
|
1063 |
explicitly.
|
lcp@104
|
1064 |
|
lcp@315
|
1065 |
The definition makes use of a least fixed point operator \cdx{lfp},
|
lcp@315
|
1066 |
defined using the Knaster-Tarski theorem. This is used to define the
|
lcp@315
|
1067 |
operator \cdx{trancl}, for taking the transitive closure of a relation.
|
lcp@315
|
1068 |
Primitive recursion makes use of \cdx{wfrec}, an operator for recursion
|
lcp@315
|
1069 |
along arbitrary well-founded relations. The corresponding theories are
|
lcp@315
|
1070 |
called {\tt Lfp}, {\tt Trancl} and {\tt WF}\@. Elsewhere I have described
|
lcp@315
|
1071 |
similar constructions in the context of set theory~\cite{paulson-set-II}.
|
lcp@104
|
1072 |
|
wenzelm@9695
|
1073 |
Type~\tydx{nat} is postulated to belong to class~\cldx{ord}, which overloads
|
wenzelm@9695
|
1074 |
$<$ and $\leq$ on the natural numbers. As of this writing, Isabelle provides
|
wenzelm@9695
|
1075 |
no means of verifying that such overloading is sensible; there is no means of
|
wenzelm@9695
|
1076 |
specifying the operators' properties and verifying that instances of the
|
wenzelm@9695
|
1077 |
operators satisfy those properties. To be safe, the HOL theory includes no
|
wenzelm@9695
|
1078 |
polymorphic axioms asserting general properties of $<$ and~$\leq$.
|
lcp@104
|
1079 |
|
lcp@315
|
1080 |
Theory \thydx{Arith} develops arithmetic on the natural numbers. It
|
lcp@315
|
1081 |
defines addition, multiplication, subtraction, division, and remainder.
|
lcp@315
|
1082 |
Many of their properties are proved: commutative, associative and
|
lcp@315
|
1083 |
distributive laws, identity and cancellation laws, etc. The most
|
lcp@315
|
1084 |
interesting result is perhaps the theorem $a \bmod b + (a/b)\times b = a$.
|
lcp@315
|
1085 |
Division and remainder are defined by repeated subtraction, which requires
|
lcp@315
|
1086 |
well-founded rather than primitive recursion. See Figs.\ts\ref{hol-nat1}
|
lcp@315
|
1087 |
and~\ref{hol-nat2}.
|
lcp@104
|
1088 |
|
lcp@315
|
1089 |
The predecessor relation, \cdx{pred_nat}, is shown to be well-founded.
|
lcp@315
|
1090 |
Recursion along this relation resembles primitive recursion, but is
|
lcp@315
|
1091 |
stronger because we are in higher-order logic; using primitive recursion to
|
lcp@315
|
1092 |
define a higher-order function, we can easily Ackermann's function, which
|
lcp@315
|
1093 |
is not primitive recursive \cite[page~104]{thompson91}.
|
lcp@315
|
1094 |
The transitive closure of \cdx{pred_nat} is~$<$. Many functions on the
|
lcp@315
|
1095 |
natural numbers are most easily expressed using recursion along~$<$.
|
lcp@315
|
1096 |
|
lcp@315
|
1097 |
The tactic {\tt\ttindex{nat_ind_tac} "$n$" $i$} performs induction over the
|
lcp@315
|
1098 |
variable~$n$ in subgoal~$i$.
|
lcp@104
|
1099 |
|
lcp@287
|
1100 |
\begin{figure}
|
lcp@315
|
1101 |
\index{#@{\tt\#} symbol}
|
lcp@315
|
1102 |
\index{"@@{\tt\at} symbol}
|
lcp@315
|
1103 |
\begin{constants}
|
lcp@315
|
1104 |
\it symbol & \it meta-type & \it priority & \it description \\
|
lcp@315
|
1105 |
\cdx{Nil} & $\alpha list$ & & empty list\\
|
lcp@315
|
1106 |
\tt \# & $[\alpha,\alpha list]\To \alpha list$ & Right 65 &
|
lcp@315
|
1107 |
list constructor \\
|
lcp@344
|
1108 |
\cdx{null} & $\alpha list \To bool$ & & emptiness test\\
|
lcp@315
|
1109 |
\cdx{hd} & $\alpha list \To \alpha$ & & head \\
|
lcp@315
|
1110 |
\cdx{tl} & $\alpha list \To \alpha list$ & & tail \\
|
lcp@315
|
1111 |
\cdx{ttl} & $\alpha list \To \alpha list$ & & total tail \\
|
lcp@315
|
1112 |
\tt\at & $[\alpha list,\alpha list]\To \alpha list$ & Left 65 & append \\
|
lcp@315
|
1113 |
\sdx{mem} & $[\alpha,\alpha list]\To bool$ & Left 55 & membership\\
|
lcp@315
|
1114 |
\cdx{map} & $(\alpha\To\beta) \To (\alpha list \To \beta list)$
|
lcp@315
|
1115 |
& & mapping functional\\
|
lcp@315
|
1116 |
\cdx{filter} & $(\alpha \To bool) \To (\alpha list \To \alpha list)$
|
lcp@315
|
1117 |
& & filter functional\\
|
lcp@315
|
1118 |
\cdx{list_all}& $(\alpha \To bool) \To (\alpha list \To bool)$
|
lcp@315
|
1119 |
& & forall functional\\
|
lcp@315
|
1120 |
\cdx{list_rec} & $[\alpha list, \beta, [\alpha ,\alpha list,
|
lcp@104
|
1121 |
\beta]\To\beta] \To \beta$
|
lcp@315
|
1122 |
& & list recursor
|
lcp@315
|
1123 |
\end{constants}
|
nipkow@306
|
1124 |
\subcaption{Constants and infixes}
|
nipkow@306
|
1125 |
|
nipkow@306
|
1126 |
\begin{center} \tt\frenchspacing
|
nipkow@306
|
1127 |
\begin{tabular}{rrr}
|
lcp@315
|
1128 |
\it external & \it internal & \it description \\{}
|
lcp@315
|
1129 |
\sdx{[]} & Nil & \rm empty list \\{}
|
lcp@315
|
1130 |
[$x@1$, $\dots$, $x@n$] & $x@1$ \# $\cdots$ \# $x@n$ \# [] &
|
nipkow@306
|
1131 |
\rm finite list \\{}
|
lcp@344
|
1132 |
[$x$:$l$. $P$] & filter($\lambda x{.}P$, $l$) &
|
lcp@315
|
1133 |
\rm list comprehension
|
nipkow@306
|
1134 |
\end{tabular}
|
nipkow@306
|
1135 |
\end{center}
|
nipkow@306
|
1136 |
\subcaption{Translations}
|
lcp@104
|
1137 |
|
lcp@104
|
1138 |
\begin{ttbox}
|
lcp@315
|
1139 |
\tdx{list_induct} [| P([]); !!x xs. [| P(xs) |] ==> P(x#xs)) |] ==> P(l)
|
lcp@104
|
1140 |
|
lcp@315
|
1141 |
\tdx{Cons_not_Nil} (x # xs) ~= []
|
lcp@315
|
1142 |
\tdx{Cons_Cons_eq} ((x # xs) = (y # ys)) = (x=y & xs=ys)
|
nipkow@306
|
1143 |
\subcaption{Induction and freeness}
|
lcp@104
|
1144 |
\end{ttbox}
|
lcp@315
|
1145 |
\caption{The theory \thydx{List}} \label{hol-list}
|
lcp@104
|
1146 |
\end{figure}
|
lcp@104
|
1147 |
|
nipkow@306
|
1148 |
\begin{figure}
|
nipkow@306
|
1149 |
\begin{ttbox}\makeatother
|
lcp@471
|
1150 |
\tdx{list_rec_Nil} list_rec([],c,h) = c
|
lcp@471
|
1151 |
\tdx{list_rec_Cons} list_rec(a#l, c, h) = h(a, l, list_rec(l,c,h))
|
lcp@315
|
1152 |
|
lcp@705
|
1153 |
\tdx{list_case_Nil} list_case(c, h, []) = c
|
lcp@705
|
1154 |
\tdx{list_case_Cons} list_case(c, h, x#xs) = h(x, xs)
|
lcp@315
|
1155 |
|
lcp@471
|
1156 |
\tdx{map_Nil} map(f,[]) = []
|
lcp@471
|
1157 |
\tdx{map_Cons} map(f, x \# xs) = f(x) \# map(f,xs)
|
lcp@315
|
1158 |
|
lcp@471
|
1159 |
\tdx{null_Nil} null([]) = True
|
lcp@471
|
1160 |
\tdx{null_Cons} null(x#xs) = False
|
lcp@315
|
1161 |
|
lcp@471
|
1162 |
\tdx{hd_Cons} hd(x#xs) = x
|
lcp@471
|
1163 |
\tdx{tl_Cons} tl(x#xs) = xs
|
lcp@315
|
1164 |
|
lcp@471
|
1165 |
\tdx{ttl_Nil} ttl([]) = []
|
lcp@471
|
1166 |
\tdx{ttl_Cons} ttl(x#xs) = xs
|
lcp@315
|
1167 |
|
lcp@471
|
1168 |
\tdx{append_Nil} [] @ ys = ys
|
lcp@471
|
1169 |
\tdx{append_Cons} (x#xs) \at ys = x # xs \at ys
|
lcp@315
|
1170 |
|
lcp@471
|
1171 |
\tdx{mem_Nil} x mem [] = False
|
lcp@471
|
1172 |
\tdx{mem_Cons} x mem (y#ys) = if(y=x, True, x mem ys)
|
lcp@315
|
1173 |
|
lcp@471
|
1174 |
\tdx{filter_Nil} filter(P, []) = []
|
lcp@471
|
1175 |
\tdx{filter_Cons} filter(P,x#xs) = if(P(x), x#filter(P,xs), filter(P,xs))
|
lcp@315
|
1176 |
|
lcp@471
|
1177 |
\tdx{list_all_Nil} list_all(P,[]) = True
|
lcp@471
|
1178 |
\tdx{list_all_Cons} list_all(P, x#xs) = (P(x) & list_all(P, xs))
|
nipkow@306
|
1179 |
\end{ttbox}
|
nipkow@306
|
1180 |
\caption{Rewrite rules for lists} \label{hol-list-simps}
|
nipkow@306
|
1181 |
\end{figure}
|
lcp@104
|
1182 |
|
lcp@315
|
1183 |
|
lcp@315
|
1184 |
\subsection{The type constructor for lists, {\tt list}}
|
lcp@315
|
1185 |
\index{*list type}
|
lcp@315
|
1186 |
|
wenzelm@9695
|
1187 |
HOL's definition of lists is an example of an experimental method for handling
|
wenzelm@9695
|
1188 |
recursive data types. Figure~\ref{hol-list} presents the theory \thydx{List}:
|
wenzelm@9695
|
1189 |
the basic list operations with their types and properties.
|
lcp@104
|
1190 |
|
lcp@344
|
1191 |
The \sdx{case} construct is defined by the following translation:
|
lcp@315
|
1192 |
{\dquotes
|
lcp@315
|
1193 |
\begin{eqnarray*}
|
lcp@344
|
1194 |
\begin{array}{r@{\;}l@{}l}
|
lcp@315
|
1195 |
"case " e " of" & "[]" & " => " a\\
|
lcp@315
|
1196 |
"|" & x"\#"xs & " => " b
|
lcp@315
|
1197 |
\end{array}
|
lcp@315
|
1198 |
& \equiv &
|
lcp@705
|
1199 |
"list_case"(a, \lambda x\;xs.b, e)
|
lcp@344
|
1200 |
\end{eqnarray*}}%
|
lcp@315
|
1201 |
The theory includes \cdx{list_rec}, a primitive recursion operator
|
lcp@315
|
1202 |
for lists. It is derived from well-founded recursion, a general principle
|
lcp@315
|
1203 |
that can express arbitrary total recursive functions.
|
lcp@104
|
1204 |
|
lcp@315
|
1205 |
The simpset \ttindex{list_ss} contains, along with additional useful lemmas,
|
lcp@315
|
1206 |
the basic rewrite rules that appear in Fig.\ts\ref{hol-list-simps}.
|
lcp@315
|
1207 |
|
lcp@315
|
1208 |
The tactic {\tt\ttindex{list_ind_tac} "$xs$" $i$} performs induction over the
|
lcp@315
|
1209 |
variable~$xs$ in subgoal~$i$.
|
lcp@315
|
1210 |
|
lcp@315
|
1211 |
|
nipkow@464
|
1212 |
\section{Datatype declarations}
|
nipkow@464
|
1213 |
\index{*datatype|(}
|
nipkow@464
|
1214 |
|
nipkow@464
|
1215 |
\underscoreon
|
nipkow@464
|
1216 |
|
nipkow@464
|
1217 |
It is often necessary to extend a theory with \ML-like datatypes. This
|
nipkow@464
|
1218 |
extension consists of the new type, declarations of its constructors and
|
nipkow@464
|
1219 |
rules that describe the new type. The theory definition section {\tt
|
nipkow@464
|
1220 |
datatype} represents a compact way of doing this.
|
nipkow@464
|
1221 |
|
nipkow@464
|
1222 |
|
nipkow@464
|
1223 |
\subsection{Foundations}
|
nipkow@464
|
1224 |
|
nipkow@464
|
1225 |
A datatype declaration has the following general structure:
|
nipkow@464
|
1226 |
\[ \mbox{\tt datatype}~ (\alpha_1,\dots,\alpha_n)t ~=~
|
nipkow@580
|
1227 |
C_1(\tau_{11},\dots,\tau_{1k_1}) ~\mid~ \dots ~\mid~
|
nipkow@580
|
1228 |
C_m(\tau_{m1},\dots,\tau_{mk_m})
|
nipkow@464
|
1229 |
\]
|
nipkow@580
|
1230 |
where $\alpha_i$ are type variables, $C_i$ are distinct constructor names and
|
nipkow@464
|
1231 |
$\tau_{ij}$ are one of the following:
|
nipkow@464
|
1232 |
\begin{itemize}
|
nipkow@464
|
1233 |
\item type variables $\alpha_1,\dots,\alpha_n$,
|
nipkow@464
|
1234 |
\item types $(\beta_1,\dots,\beta_l)s$ where $s$ is a previously declared
|
nipkow@464
|
1235 |
type or type synonym and $\{\beta_1,\dots,\beta_l\} \subseteq
|
nipkow@464
|
1236 |
\{\alpha_1,\dots,\alpha_n\}$,
|
nipkow@464
|
1237 |
\item the newly defined type $(\alpha_1,\dots,\alpha_n)t$ \footnote{This
|
nipkow@464
|
1238 |
makes it a recursive type. To ensure that the new type is not empty at
|
nipkow@464
|
1239 |
least one constructor must consist of only non-recursive type
|
nipkow@464
|
1240 |
components.}
|
nipkow@464
|
1241 |
\end{itemize}
|
nipkow@580
|
1242 |
If you would like one of the $\tau_{ij}$ to be a complex type expression
|
nipkow@580
|
1243 |
$\tau$ you need to declare a new type synonym $syn = \tau$ first and use
|
nipkow@580
|
1244 |
$syn$ in place of $\tau$. Of course this does not work if $\tau$ mentions the
|
nipkow@580
|
1245 |
recursive type itself, thus ruling out problematic cases like \[ \mbox{\tt
|
nipkow@580
|
1246 |
datatype}~ t ~=~ C(t \To t) \] together with unproblematic ones like \[
|
nipkow@580
|
1247 |
\mbox{\tt datatype}~ t ~=~ C(t~list). \]
|
nipkow@580
|
1248 |
|
nipkow@464
|
1249 |
The constructors are automatically defined as functions of their respective
|
nipkow@464
|
1250 |
type:
|
nipkow@580
|
1251 |
\[ C_j : [\tau_{j1},\dots,\tau_{jk_j}] \To (\alpha_1,\dots,\alpha_n)t \]
|
nipkow@464
|
1252 |
These functions have certain {\em freeness} properties:
|
nipkow@464
|
1253 |
\begin{description}
|
nipkow@465
|
1254 |
\item[\tt distinct] They are distinct:
|
nipkow@580
|
1255 |
\[ C_i(x_1,\dots,x_{k_i}) \neq C_j(y_1,\dots,y_{k_j}) \qquad
|
nipkow@465
|
1256 |
\mbox{for all}~ i \neq j.
|
nipkow@465
|
1257 |
\]
|
nipkow@464
|
1258 |
\item[\tt inject] They are injective:
|
nipkow@580
|
1259 |
\[ (C_j(x_1,\dots,x_{k_j}) = C_j(y_1,\dots,y_{k_j})) =
|
nipkow@464
|
1260 |
(x_1 = y_1 \land \dots \land x_{k_j} = y_{k_j})
|
nipkow@464
|
1261 |
\]
|
nipkow@464
|
1262 |
\end{description}
|
nipkow@464
|
1263 |
Because the number of inequalities is quadratic in the number of
|
nipkow@464
|
1264 |
constructors, a different method is used if their number exceeds
|
nipkow@464
|
1265 |
a certain value, currently 4. In that case every constructor is mapped to a
|
nipkow@464
|
1266 |
natural number
|
nipkow@464
|
1267 |
\[
|
nipkow@464
|
1268 |
\begin{array}{lcl}
|
nipkow@580
|
1269 |
\mbox{\it t\_ord}(C_1(x_1,\dots,x_{k_1})) & = & 0 \\
|
nipkow@464
|
1270 |
& \vdots & \\
|
nipkow@580
|
1271 |
\mbox{\it t\_ord}(C_m(x_1,\dots,x_{k_m})) & = & m-1
|
nipkow@464
|
1272 |
\end{array}
|
nipkow@464
|
1273 |
\]
|
nipkow@465
|
1274 |
and distinctness of constructors is expressed by:
|
nipkow@464
|
1275 |
\[
|
nipkow@464
|
1276 |
\mbox{\it t\_ord}(x) \neq \mbox{\it t\_ord}(y) \Imp x \neq y.
|
nipkow@464
|
1277 |
\]
|
nipkow@464
|
1278 |
In addition a structural induction axiom {\tt induct} is provided:
|
nipkow@464
|
1279 |
\[
|
nipkow@464
|
1280 |
\infer{P(x)}
|
nipkow@464
|
1281 |
{\begin{array}{lcl}
|
nipkow@464
|
1282 |
\Forall x_1\dots x_{k_1}.
|
nipkow@464
|
1283 |
\List{P(x_{r_{11}}); \dots; P(x_{r_{1l_1}})} &
|
nipkow@580
|
1284 |
\Imp & P(C_1(x_1,\dots,x_{k_1})) \\
|
nipkow@464
|
1285 |
& \vdots & \\
|
nipkow@464
|
1286 |
\Forall x_1\dots x_{k_m}.
|
nipkow@464
|
1287 |
\List{P(x_{r_{m1}}); \dots; P(x_{r_{ml_m}})} &
|
nipkow@580
|
1288 |
\Imp & P(C_m(x_1,\dots,x_{k_m}))
|
nipkow@464
|
1289 |
\end{array}}
|
nipkow@464
|
1290 |
\]
|
nipkow@464
|
1291 |
where $\{r_{j1},\dots,r_{jl_j}\} = \{i \in \{1,\dots k_j\} ~\mid~ \tau_{ji}
|
nipkow@464
|
1292 |
= (\alpha_1,\dots,\alpha_n)t \}$, i.e.\ the property $P$ can be assumed for
|
nipkow@464
|
1293 |
all arguments of the recursive type.
|
nipkow@464
|
1294 |
|
nipkow@465
|
1295 |
The type also comes with an \ML-like \sdx{case}-construct:
|
nipkow@464
|
1296 |
\[
|
nipkow@464
|
1297 |
\begin{array}{rrcl}
|
nipkow@580
|
1298 |
\mbox{\tt case}~e~\mbox{\tt of} & C_1(x_{11},\dots,x_{1k_1}) & \To & e_1 \\
|
nipkow@464
|
1299 |
\vdots \\
|
nipkow@580
|
1300 |
\mid & C_m(x_{m1},\dots,x_{mk_m}) & \To & e_m
|
nipkow@464
|
1301 |
\end{array}
|
nipkow@464
|
1302 |
\]
|
nipkow@464
|
1303 |
In contrast to \ML, {\em all} constructors must be present, their order is
|
nipkow@464
|
1304 |
fixed, and nested patterns are not supported.
|
nipkow@464
|
1305 |
|
nipkow@464
|
1306 |
|
nipkow@464
|
1307 |
\subsection{Defining datatypes}
|
nipkow@464
|
1308 |
|
nipkow@464
|
1309 |
A datatype is defined in a theory definition file using the keyword {\tt
|
nipkow@464
|
1310 |
datatype}. The definition following {\tt datatype} must conform to the
|
nipkow@464
|
1311 |
syntax of {\em typedecl} specified in Fig.~\ref{datatype-grammar} and must
|
nipkow@464
|
1312 |
obey the rules in the previous section. As a result the theory is extended
|
nipkow@464
|
1313 |
with the new type, the constructors, and the theorems listed in the previous
|
nipkow@464
|
1314 |
section.
|
nipkow@464
|
1315 |
|
nipkow@464
|
1316 |
\begin{figure}
|
nipkow@464
|
1317 |
\begin{rail}
|
nipkow@464
|
1318 |
typedecl : typevarlist id '=' (cons + '|')
|
nipkow@464
|
1319 |
;
|
nipkow@464
|
1320 |
cons : (id | string) ( () | '(' (typ + ',') ')' ) ( () | mixfix )
|
nipkow@464
|
1321 |
;
|
nipkow@464
|
1322 |
typ : typevarlist id
|
nipkow@464
|
1323 |
| tid
|
lcp@594
|
1324 |
;
|
nipkow@464
|
1325 |
typevarlist : () | tid | '(' (tid + ',') ')'
|
nipkow@464
|
1326 |
;
|
nipkow@464
|
1327 |
\end{rail}
|
nipkow@464
|
1328 |
\caption{Syntax of datatype declarations}
|
nipkow@464
|
1329 |
\label{datatype-grammar}
|
nipkow@464
|
1330 |
\end{figure}
|
nipkow@464
|
1331 |
|
nipkow@465
|
1332 |
Reading the theory file produces a structure which, in addition to the usual
|
nipkow@464
|
1333 |
components, contains a structure named $t$ for each datatype $t$ defined in
|
nipkow@465
|
1334 |
the file.\footnote{Otherwise multiple datatypes in the same theory file would
|
nipkow@465
|
1335 |
lead to name clashes.} Each structure $t$ contains the following elements:
|
nipkow@464
|
1336 |
\begin{ttbox}
|
nipkow@465
|
1337 |
val distinct : thm list
|
nipkow@465
|
1338 |
val inject : thm list
|
nipkow@464
|
1339 |
val induct : thm
|
nipkow@464
|
1340 |
val cases : thm list
|
nipkow@464
|
1341 |
val simps : thm list
|
nipkow@464
|
1342 |
val induct_tac : string -> int -> tactic
|
nipkow@464
|
1343 |
\end{ttbox}
|
nipkow@465
|
1344 |
{\tt distinct}, {\tt inject} and {\tt induct} contain the theorems described
|
nipkow@465
|
1345 |
above. For convenience {\tt distinct} contains inequalities in both
|
nipkow@465
|
1346 |
directions.
|
nipkow@464
|
1347 |
\begin{warn}
|
nipkow@464
|
1348 |
If there are five or more constructors, the {\em t\_ord} scheme is used for
|
nipkow@465
|
1349 |
{\tt distinct}. In this case the theory {\tt Arith} must be contained
|
nipkow@465
|
1350 |
in the current theory, if necessary by including it explicitly.
|
nipkow@464
|
1351 |
\end{warn}
|
nipkow@465
|
1352 |
The reduction rules of the {\tt case}-construct are in {\tt cases}. All
|
nipkow@465
|
1353 |
theorems from {\tt distinct}, {\tt inject} and {\tt cases} are combined in
|
lcp@1086
|
1354 |
{\tt simps} for use with the simplifier. The tactic {\verb$induct_tac$~{\em
|
lcp@1086
|
1355 |
var i}\/} applies structural induction over variable {\em var} to
|
nipkow@464
|
1356 |
subgoal {\em i}.
|
nipkow@464
|
1357 |
|
nipkow@464
|
1358 |
|
nipkow@464
|
1359 |
\subsection{Examples}
|
nipkow@464
|
1360 |
|
nipkow@464
|
1361 |
\subsubsection{The datatype $\alpha~list$}
|
nipkow@464
|
1362 |
|
nipkow@465
|
1363 |
We want to define the type $\alpha~list$.\footnote{Of course there is a list
|
nipkow@465
|
1364 |
type in HOL already. This is only an example.} To do this we have to build
|
nipkow@465
|
1365 |
a new theory that contains the type definition. We start from {\tt HOL}.
|
nipkow@464
|
1366 |
\begin{ttbox}
|
nipkow@464
|
1367 |
MyList = HOL +
|
nipkow@464
|
1368 |
datatype 'a list = Nil | Cons ('a, 'a list)
|
nipkow@464
|
1369 |
end
|
nipkow@464
|
1370 |
\end{ttbox}
|
nipkow@465
|
1371 |
After loading the theory (\verb$use_thy "MyList"$), we can prove
|
nipkow@465
|
1372 |
$Cons(x,xs)\neq xs$. First we build a suitable simpset for the simplifier:
|
nipkow@464
|
1373 |
\begin{ttbox}
|
nipkow@464
|
1374 |
val mylist_ss = HOL_ss addsimps MyList.list.simps;
|
nipkow@464
|
1375 |
goal MyList.thy "!x. Cons(x,xs) ~= xs";
|
nipkow@464
|
1376 |
{\out Level 0}
|
nipkow@464
|
1377 |
{\out ! x. Cons(x, xs) ~= xs}
|
nipkow@464
|
1378 |
{\out 1. ! x. Cons(x, xs) ~= xs}
|
nipkow@464
|
1379 |
\end{ttbox}
|
nipkow@464
|
1380 |
This can be proved by the structural induction tactic:
|
nipkow@464
|
1381 |
\begin{ttbox}
|
nipkow@464
|
1382 |
by (MyList.list.induct_tac "xs" 1);
|
nipkow@464
|
1383 |
{\out Level 1}
|
nipkow@464
|
1384 |
{\out ! x. Cons(x, xs) ~= xs}
|
nipkow@464
|
1385 |
{\out 1. ! x. Cons(x, Nil) ~= Nil}
|
nipkow@464
|
1386 |
{\out 2. !!a list.}
|
nipkow@464
|
1387 |
{\out ! x. Cons(x, list) ~= list ==>}
|
nipkow@464
|
1388 |
{\out ! x. Cons(x, Cons(a, list)) ~= Cons(a, list)}
|
nipkow@464
|
1389 |
\end{ttbox}
|
nipkow@465
|
1390 |
The first subgoal can be proved with the simplifier and the distinctness
|
nipkow@465
|
1391 |
axioms which are part of \verb$mylist_ss$.
|
nipkow@464
|
1392 |
\begin{ttbox}
|
nipkow@464
|
1393 |
by (simp_tac mylist_ss 1);
|
nipkow@464
|
1394 |
{\out Level 2}
|
nipkow@464
|
1395 |
{\out ! x. Cons(x, xs) ~= xs}
|
nipkow@464
|
1396 |
{\out 1. !!a list.}
|
nipkow@464
|
1397 |
{\out ! x. Cons(x, list) ~= list ==>}
|
nipkow@464
|
1398 |
{\out ! x. Cons(x, Cons(a, list)) ~= Cons(a, list)}
|
nipkow@464
|
1399 |
\end{ttbox}
|
nipkow@465
|
1400 |
Using the freeness axioms we can quickly prove the remaining goal.
|
nipkow@464
|
1401 |
\begin{ttbox}
|
nipkow@464
|
1402 |
by (asm_simp_tac mylist_ss 1);
|
nipkow@464
|
1403 |
{\out Level 3}
|
nipkow@464
|
1404 |
{\out ! x. Cons(x, xs) ~= xs}
|
nipkow@464
|
1405 |
{\out No subgoals!}
|
nipkow@464
|
1406 |
\end{ttbox}
|
nipkow@464
|
1407 |
Because both subgoals were proved by almost the same tactic we could have
|
nipkow@464
|
1408 |
done that in one step using
|
nipkow@464
|
1409 |
\begin{ttbox}
|
nipkow@464
|
1410 |
by (ALLGOALS (asm_simp_tac mylist_ss));
|
nipkow@464
|
1411 |
\end{ttbox}
|
nipkow@464
|
1412 |
|
nipkow@464
|
1413 |
|
nipkow@464
|
1414 |
\subsubsection{The datatype $\alpha~list$ with mixfix syntax}
|
nipkow@464
|
1415 |
|
nipkow@464
|
1416 |
In this example we define the type $\alpha~list$ again but this time we want
|
nipkow@464
|
1417 |
to write {\tt []} instead of {\tt Nil} and we want to use the infix operator
|
nipkow@464
|
1418 |
\verb|#| instead of {\tt Cons}. To do this we simply add mixfix annotations
|
nipkow@464
|
1419 |
after the constructor declarations as follows:
|
nipkow@464
|
1420 |
\begin{ttbox}
|
nipkow@464
|
1421 |
MyList = HOL +
|
nipkow@464
|
1422 |
datatype 'a list = "[]" ("[]")
|
nipkow@464
|
1423 |
| "#" ('a, 'a list) (infixr 70)
|
nipkow@464
|
1424 |
end
|
nipkow@464
|
1425 |
\end{ttbox}
|
nipkow@464
|
1426 |
Now the theorem in the previous example can be written \verb|x#xs ~= xs|. The
|
nipkow@464
|
1427 |
proof is the same.
|
nipkow@464
|
1428 |
|
nipkow@464
|
1429 |
|
nipkow@464
|
1430 |
\subsubsection{A datatype for weekdays}
|
nipkow@464
|
1431 |
|
nipkow@464
|
1432 |
This example shows a datatype that consists of more than four constructors:
|
nipkow@464
|
1433 |
\begin{ttbox}
|
nipkow@464
|
1434 |
Days = Arith +
|
nipkow@464
|
1435 |
datatype days = Mo | Tu | We | Th | Fr | Sa | So
|
nipkow@464
|
1436 |
end
|
nipkow@464
|
1437 |
\end{ttbox}
|
nipkow@464
|
1438 |
Because there are more than four constructors, the theory must be based on
|
nipkow@464
|
1439 |
{\tt Arith}. Inequality is defined via a function \verb|days_ord|. Although
|
nipkow@465
|
1440 |
the expression \verb|Mo ~= Tu| is not directly contained in {\tt distinct},
|
nipkow@465
|
1441 |
it can be proved by the simplifier if \verb$arith_ss$ is used:
|
nipkow@464
|
1442 |
\begin{ttbox}
|
nipkow@464
|
1443 |
val days_ss = arith_ss addsimps Days.days.simps;
|
nipkow@464
|
1444 |
|
nipkow@464
|
1445 |
goal Days.thy "Mo ~= Tu";
|
nipkow@464
|
1446 |
by (simp_tac days_ss 1);
|
nipkow@464
|
1447 |
\end{ttbox}
|
nipkow@464
|
1448 |
Note that usually it is not necessary to derive these inequalities explicitly
|
nipkow@464
|
1449 |
because the simplifier will dispose of them automatically.
|
nipkow@464
|
1450 |
|
nipkow@600
|
1451 |
\subsection{Primitive recursive functions}
|
nipkow@600
|
1452 |
\index{primitive recursion|(}
|
nipkow@600
|
1453 |
\index{*primrec|(}
|
nipkow@600
|
1454 |
|
nipkow@600
|
1455 |
Datatypes come with a uniform way of defining functions, {\bf primitive
|
nipkow@600
|
1456 |
recursion}. Although it is possible to define primitive recursive functions
|
nipkow@600
|
1457 |
by asserting their reduction rules as new axioms, e.g.\
|
nipkow@600
|
1458 |
\begin{ttbox}
|
nipkow@600
|
1459 |
Append = MyList +
|
nipkow@600
|
1460 |
consts app :: "['a list,'a list] => 'a list"
|
nipkow@600
|
1461 |
rules
|
nipkow@600
|
1462 |
app_Nil "app([],ys) = ys"
|
nipkow@600
|
1463 |
app_Cons "app(x#xs, ys) = x#app(xs,ys)"
|
nipkow@600
|
1464 |
end
|
nipkow@600
|
1465 |
\end{ttbox}
|
nipkow@600
|
1466 |
this carries with it the danger of accidentally asserting an inconsistency,
|
nipkow@600
|
1467 |
as in \verb$app([],ys) = us$. Therefore primitive recursive functions on
|
nipkow@600
|
1468 |
datatypes can be defined with a special syntax:
|
nipkow@600
|
1469 |
\begin{ttbox}
|
nipkow@600
|
1470 |
Append = MyList +
|
nipkow@600
|
1471 |
consts app :: "['a list,'a list] => 'a list"
|
nipkow@600
|
1472 |
primrec app MyList.list
|
nipkow@600
|
1473 |
app_Nil "app([],ys) = ys"
|
nipkow@600
|
1474 |
app_Cons "app(x#xs, ys) = x#app(xs,ys)"
|
nipkow@600
|
1475 |
end
|
nipkow@600
|
1476 |
\end{ttbox}
|
nipkow@600
|
1477 |
The system will now check that the two rules \verb$app_Nil$ and
|
nipkow@600
|
1478 |
\verb$app_Cons$ do indeed form a primitive recursive definition, thus
|
nipkow@600
|
1479 |
ensuring that consistency is maintained. For example
|
nipkow@600
|
1480 |
\begin{ttbox}
|
nipkow@600
|
1481 |
primrec app MyList.list
|
nipkow@600
|
1482 |
app_Nil "app([],ys) = us"
|
nipkow@600
|
1483 |
\end{ttbox}
|
nipkow@600
|
1484 |
is rejected:
|
nipkow@600
|
1485 |
\begin{ttbox}
|
nipkow@600
|
1486 |
Extra variables on rhs
|
nipkow@600
|
1487 |
\end{ttbox}
|
nipkow@600
|
1488 |
\bigskip
|
nipkow@600
|
1489 |
|
nipkow@600
|
1490 |
The general form of a primitive recursive definition is
|
nipkow@600
|
1491 |
\begin{ttbox}
|
nipkow@600
|
1492 |
primrec {\it function} {\it type}
|
nipkow@600
|
1493 |
{\it reduction rules}
|
nipkow@600
|
1494 |
\end{ttbox}
|
nipkow@600
|
1495 |
where
|
nipkow@600
|
1496 |
\begin{itemize}
|
nipkow@600
|
1497 |
\item {\it function} is the name of the function, either as an {\it id} or a
|
nipkow@600
|
1498 |
{\it string}. The function must already have been declared.
|
nipkow@600
|
1499 |
\item {\it type} is the name of the datatype, either as an {\it id} or in the
|
nipkow@600
|
1500 |
long form {\it Thy.t}, where {\it Thy} is the name of the parent theory the
|
nipkow@600
|
1501 |
datatype was declared in, and $t$ the name of the datatype. The long form
|
nipkow@600
|
1502 |
is required if the {\tt datatype} and the {\tt primrec} sections are in
|
nipkow@600
|
1503 |
different theories.
|
nipkow@600
|
1504 |
\item {\it reduction rules} specify one or more named equations of the form
|
nipkow@600
|
1505 |
{\it id\/}~{\it string}, where the identifier gives the name of the rule in
|
nipkow@600
|
1506 |
the result structure, and {\it string} is a reduction rule of the form \[
|
nipkow@600
|
1507 |
f(x_1,\dots,x_m,C(y_1,\dots,y_k),z_1,\dots,z_n) = r \] such that $C$ is a
|
nipkow@600
|
1508 |
constructor of the datatype, $r$ contains only the free variables on the
|
nipkow@600
|
1509 |
left-hand side, and all recursive calls in $r$ are of the form
|
nipkow@600
|
1510 |
$f(\dots,y_i,\dots)$ for some $i$. There must be exactly one reduction
|
nipkow@600
|
1511 |
rule for each constructor.
|
nipkow@600
|
1512 |
\end{itemize}
|
nipkow@600
|
1513 |
A theory file may contain any number of {\tt primrec} sections which may be
|
nipkow@600
|
1514 |
intermixed with other declarations.
|
nipkow@600
|
1515 |
|
nipkow@600
|
1516 |
For the consistency-sensitive user it may be reassuring to know that {\tt
|
nipkow@600
|
1517 |
primrec} does not assert the reduction rules as new axioms but derives them
|
nipkow@600
|
1518 |
as theorems from an explicit definition of the recursive function in terms of
|
nipkow@600
|
1519 |
a recursion operator on the datatype.
|
nipkow@600
|
1520 |
|
nipkow@600
|
1521 |
The primitive recursive function can also use infix or mixfix syntax:
|
nipkow@600
|
1522 |
\begin{ttbox}
|
nipkow@600
|
1523 |
Append = MyList +
|
nipkow@600
|
1524 |
consts "@" :: "['a list,'a list] => 'a list" (infixr 60)
|
nipkow@600
|
1525 |
primrec "op @" MyList.list
|
nipkow@600
|
1526 |
app_Nil "[] @ ys = ys"
|
nipkow@600
|
1527 |
app_Cons "(x#xs) @ ys = x#(xs @ ys)"
|
nipkow@600
|
1528 |
end
|
nipkow@600
|
1529 |
\end{ttbox}
|
nipkow@600
|
1530 |
|
nipkow@600
|
1531 |
The reduction rules become part of the ML structure \verb$Append$ and can
|
nipkow@600
|
1532 |
be used to prove theorems about the function:
|
nipkow@600
|
1533 |
\begin{ttbox}
|
nipkow@600
|
1534 |
val append_ss = HOL_ss addsimps [Append.app_Nil,Append.app_Cons];
|
nipkow@600
|
1535 |
|
nipkow@600
|
1536 |
goal Append.thy "(xs @ ys) @ zs = xs @ (ys @ zs)";
|
nipkow@600
|
1537 |
by (MyList.list.induct_tac "xs" 1);
|
nipkow@600
|
1538 |
by (ALLGOALS(asm_simp_tac append_ss));
|
nipkow@600
|
1539 |
\end{ttbox}
|
nipkow@600
|
1540 |
|
nipkow@600
|
1541 |
%Note that underdefined primitive recursive functions are allowed:
|
nipkow@600
|
1542 |
%\begin{ttbox}
|
nipkow@600
|
1543 |
%Tl = MyList +
|
nipkow@600
|
1544 |
%consts tl :: "'a list => 'a list"
|
nipkow@600
|
1545 |
%primrec tl MyList.list
|
nipkow@600
|
1546 |
% tl_Cons "tl(x#xs) = xs"
|
nipkow@600
|
1547 |
%end
|
nipkow@600
|
1548 |
%\end{ttbox}
|
nipkow@600
|
1549 |
%Nevertheless {\tt tl} is total, although we do not know what the result of
|
nipkow@600
|
1550 |
%\verb$tl([])$ is.
|
nipkow@600
|
1551 |
|
nipkow@600
|
1552 |
\index{primitive recursion|)}
|
nipkow@600
|
1553 |
\index{*primrec|)}
|
lcp@861
|
1554 |
\index{*datatype|)}
|
nipkow@464
|
1555 |
|
nipkow@464
|
1556 |
|
lcp@594
|
1557 |
\section{Inductive and coinductive definitions}
|
lcp@594
|
1558 |
\index{*inductive|(}
|
lcp@594
|
1559 |
\index{*coinductive|(}
|
lcp@594
|
1560 |
|
lcp@594
|
1561 |
An {\bf inductive definition} specifies the least set closed under given
|
lcp@594
|
1562 |
rules. For example, a structural operational semantics is an inductive
|
lcp@594
|
1563 |
definition of an evaluation relation. Dually, a {\bf coinductive
|
paulson@2975
|
1564 |
definition} specifies the greatest set consistent with given rules. An
|
lcp@594
|
1565 |
important example is using bisimulation relations to formalize equivalence
|
lcp@594
|
1566 |
of processes and infinite data structures.
|
lcp@594
|
1567 |
|
lcp@594
|
1568 |
A theory file may contain any number of inductive and coinductive
|
lcp@594
|
1569 |
definitions. They may be intermixed with other declarations; in
|
lcp@594
|
1570 |
particular, the (co)inductive sets {\bf must} be declared separately as
|
lcp@594
|
1571 |
constants, and may have mixfix syntax or be subject to syntax translations.
|
lcp@594
|
1572 |
|
lcp@594
|
1573 |
Each (co)inductive definition adds definitions to the theory and also
|
lcp@594
|
1574 |
proves some theorems. Each definition creates an ML structure, which is a
|
lcp@594
|
1575 |
substructure of the main theory structure.
|
lcp@594
|
1576 |
|
lcp@594
|
1577 |
This package is derived from the ZF one, described in a
|
lcp@594
|
1578 |
separate paper,\footnote{It appeared in CADE~\cite{paulson-CADE} and a
|
lcp@594
|
1579 |
longer version is distributed with Isabelle.} which you should refer to
|
lcp@594
|
1580 |
in case of difficulties. The package is simpler than ZF's, thanks to HOL's
|
lcp@594
|
1581 |
automatic type-checking. The type of the (co)inductive determines the
|
lcp@594
|
1582 |
domain of the fixedpoint definition, and the package does not use inference
|
lcp@594
|
1583 |
rules for type-checking.
|
lcp@594
|
1584 |
|
lcp@594
|
1585 |
|
lcp@594
|
1586 |
\subsection{The result structure}
|
lcp@594
|
1587 |
Many of the result structure's components have been discussed in the paper;
|
lcp@594
|
1588 |
others are self-explanatory.
|
lcp@594
|
1589 |
\begin{description}
|
lcp@594
|
1590 |
\item[\tt thy] is the new theory containing the recursive sets.
|
lcp@594
|
1591 |
|
lcp@594
|
1592 |
\item[\tt defs] is the list of definitions of the recursive sets.
|
lcp@594
|
1593 |
|
lcp@594
|
1594 |
\item[\tt mono] is a monotonicity theorem for the fixedpoint operator.
|
lcp@594
|
1595 |
|
lcp@594
|
1596 |
\item[\tt unfold] is a fixedpoint equation for the recursive set (the union of
|
lcp@594
|
1597 |
the recursive sets, in the case of mutual recursion).
|
lcp@594
|
1598 |
|
lcp@594
|
1599 |
\item[\tt intrs] is the list of introduction rules, now proved as theorems, for
|
lcp@594
|
1600 |
the recursive sets. The rules are also available individually, using the
|
lcp@594
|
1601 |
names given them in the theory file.
|
lcp@594
|
1602 |
|
lcp@594
|
1603 |
\item[\tt elim] is the elimination rule.
|
lcp@594
|
1604 |
|
lcp@594
|
1605 |
\item[\tt mk\_cases] is a function to create simplified instances of {\tt
|
lcp@594
|
1606 |
elim}, using freeness reasoning on some underlying datatype.
|
lcp@594
|
1607 |
\end{description}
|
lcp@594
|
1608 |
|
lcp@594
|
1609 |
For an inductive definition, the result structure contains two induction rules,
|
lcp@594
|
1610 |
{\tt induct} and \verb|mutual_induct|. For a coinductive definition, it
|
lcp@594
|
1611 |
contains the rule \verb|coinduct|.
|
lcp@594
|
1612 |
|
lcp@594
|
1613 |
Figure~\ref{def-result-fig} summarizes the two result signatures,
|
lcp@594
|
1614 |
specifying the types of all these components.
|
lcp@594
|
1615 |
|
lcp@594
|
1616 |
\begin{figure}
|
lcp@594
|
1617 |
\begin{ttbox}
|
lcp@594
|
1618 |
sig
|
lcp@594
|
1619 |
val thy : theory
|
lcp@594
|
1620 |
val defs : thm list
|
lcp@594
|
1621 |
val mono : thm
|
lcp@594
|
1622 |
val unfold : thm
|
lcp@594
|
1623 |
val intrs : thm list
|
lcp@594
|
1624 |
val elim : thm
|
lcp@594
|
1625 |
val mk_cases : thm list -> string -> thm
|
lcp@594
|
1626 |
{\it(Inductive definitions only)}
|
lcp@594
|
1627 |
val induct : thm
|
lcp@594
|
1628 |
val mutual_induct: thm
|
lcp@594
|
1629 |
{\it(Coinductive definitions only)}
|
lcp@594
|
1630 |
val coinduct : thm
|
lcp@594
|
1631 |
end
|
lcp@594
|
1632 |
\end{ttbox}
|
lcp@594
|
1633 |
\hrule
|
lcp@594
|
1634 |
\caption{The result of a (co)inductive definition} \label{def-result-fig}
|
lcp@594
|
1635 |
\end{figure}
|
lcp@594
|
1636 |
|
lcp@594
|
1637 |
\subsection{The syntax of a (co)inductive definition}
|
lcp@594
|
1638 |
An inductive definition has the form
|
lcp@594
|
1639 |
\begin{ttbox}
|
lcp@594
|
1640 |
inductive {\it inductive sets}
|
lcp@594
|
1641 |
intrs {\it introduction rules}
|
lcp@594
|
1642 |
monos {\it monotonicity theorems}
|
lcp@594
|
1643 |
con_defs {\it constructor definitions}
|
lcp@594
|
1644 |
\end{ttbox}
|
lcp@594
|
1645 |
A coinductive definition is identical, except that it starts with the keyword
|
lcp@594
|
1646 |
{\tt coinductive}.
|
lcp@594
|
1647 |
|
lcp@594
|
1648 |
The {\tt monos} and {\tt con\_defs} sections are optional. If present,
|
lcp@594
|
1649 |
each is specified as a string, which must be a valid ML expression of type
|
lcp@594
|
1650 |
{\tt thm list}. It is simply inserted into the {\tt .thy.ML} file; if it
|
lcp@594
|
1651 |
is ill-formed, it will trigger ML error messages. You can then inspect the
|
lcp@594
|
1652 |
file on your directory.
|
lcp@594
|
1653 |
|
lcp@594
|
1654 |
\begin{itemize}
|
lcp@594
|
1655 |
\item The {\it inductive sets} are specified by one or more strings.
|
lcp@594
|
1656 |
|
lcp@594
|
1657 |
\item The {\it introduction rules} specify one or more introduction rules in
|
lcp@594
|
1658 |
the form {\it ident\/}~{\it string}, where the identifier gives the name of
|
lcp@594
|
1659 |
the rule in the result structure.
|
lcp@594
|
1660 |
|
lcp@594
|
1661 |
\item The {\it monotonicity theorems} are required for each operator
|
lcp@594
|
1662 |
applied to a recursive set in the introduction rules. There {\bf must}
|
lcp@594
|
1663 |
be a theorem of the form $A\subseteq B\Imp M(A)\subseteq M(B)$, for each
|
lcp@594
|
1664 |
premise $t\in M(R_i)$ in an introduction rule!
|
lcp@594
|
1665 |
|
lcp@594
|
1666 |
\item The {\it constructor definitions} contain definitions of constants
|
lcp@594
|
1667 |
appearing in the introduction rules. In most cases it can be omitted.
|
lcp@594
|
1668 |
\end{itemize}
|
lcp@594
|
1669 |
|
lcp@594
|
1670 |
The package has a few notable restrictions:
|
lcp@594
|
1671 |
\begin{itemize}
|
lcp@594
|
1672 |
\item The theory must separately declare the recursive sets as
|
lcp@594
|
1673 |
constants.
|
lcp@594
|
1674 |
|
lcp@594
|
1675 |
\item The names of the recursive sets must be identifiers, not infix
|
lcp@594
|
1676 |
operators.
|
lcp@594
|
1677 |
|
lcp@594
|
1678 |
\item Side-conditions must not be conjunctions. However, an introduction rule
|
lcp@594
|
1679 |
may contain any number of side-conditions.
|
lcp@594
|
1680 |
|
lcp@594
|
1681 |
\item Side-conditions of the form $x=t$, where the variable~$x$ does not
|
lcp@594
|
1682 |
occur in~$t$, will be substituted through the rule \verb|mutual_induct|.
|
lcp@594
|
1683 |
\end{itemize}
|
lcp@594
|
1684 |
|
lcp@594
|
1685 |
|
lcp@594
|
1686 |
\subsection{Example of an inductive definition}
|
lcp@594
|
1687 |
Two declarations, included in a theory file, define the finite powerset
|
lcp@594
|
1688 |
operator. First we declare the constant~{\tt Fin}. Then we declare it
|
lcp@594
|
1689 |
inductively, with two introduction rules:
|
lcp@594
|
1690 |
\begin{ttbox}
|
lcp@594
|
1691 |
consts Fin :: "'a set => 'a set set"
|
lcp@594
|
1692 |
inductive "Fin(A)"
|
lcp@594
|
1693 |
intrs
|
lcp@594
|
1694 |
emptyI "{} : Fin(A)"
|
lcp@594
|
1695 |
insertI "[| a: A; b: Fin(A) |] ==> insert(a,b) : Fin(A)"
|
lcp@594
|
1696 |
\end{ttbox}
|
lcp@594
|
1697 |
The resulting theory structure contains a substructure, called~{\tt Fin}.
|
lcp@594
|
1698 |
It contains the {\tt Fin}$(A)$ introduction rules as the list {\tt Fin.intrs},
|
lcp@594
|
1699 |
and also individually as {\tt Fin.emptyI} and {\tt Fin.consI}. The induction
|
lcp@594
|
1700 |
rule is {\tt Fin.induct}.
|
lcp@594
|
1701 |
|
lcp@594
|
1702 |
For another example, here is a theory file defining the accessible part of a
|
lcp@594
|
1703 |
relation. The main thing to note is the use of~{\tt Pow} in the sole
|
lcp@594
|
1704 |
introduction rule, and the corresponding mention of the rule
|
lcp@594
|
1705 |
\verb|Pow_mono| in the {\tt monos} list. The paper discusses a ZF version
|
lcp@594
|
1706 |
of this example in more detail.
|
lcp@594
|
1707 |
\begin{ttbox}
|
lcp@594
|
1708 |
Acc = WF +
|
lcp@594
|
1709 |
consts pred :: "['b, ('a * 'b)set] => 'a set" (*Set of predecessors*)
|
lcp@594
|
1710 |
acc :: "('a * 'a)set => 'a set" (*Accessible part*)
|
lcp@594
|
1711 |
defs pred_def "pred(x,r) == {y. <y,x>:r}"
|
lcp@594
|
1712 |
inductive "acc(r)"
|
lcp@594
|
1713 |
intrs
|
lcp@594
|
1714 |
pred "pred(a,r): Pow(acc(r)) ==> a: acc(r)"
|
lcp@594
|
1715 |
monos "[Pow_mono]"
|
lcp@594
|
1716 |
end
|
lcp@594
|
1717 |
\end{ttbox}
|
lcp@594
|
1718 |
The HOL distribution contains many other inductive definitions, such as the
|
lcp@594
|
1719 |
theory {\tt HOL/ex/PropLog.thy} and the directory {\tt HOL/IMP}. The
|
lcp@629
|
1720 |
theory {\tt HOL/ex/LList.thy} contains coinductive definitions.
|
lcp@594
|
1721 |
|
lcp@594
|
1722 |
\index{*coinductive|)} \index{*inductive|)} \underscoreoff
|
lcp@594
|
1723 |
|
nipkow@464
|
1724 |
|
lcp@111
|
1725 |
\section{The examples directories}
|
lcp@344
|
1726 |
Directory {\tt HOL/Subst} contains Martin Coen's mechanisation of a theory of
|
lcp@111
|
1727 |
substitutions and unifiers. It is based on Paulson's previous
|
lcp@344
|
1728 |
mechanisation in {\LCF}~\cite{paulson85} of Manna and Waldinger's
|
lcp@111
|
1729 |
theory~\cite{mw81}.
|
lcp@111
|
1730 |
|
lcp@594
|
1731 |
Directory {\tt HOL/IMP} contains a mechanised version of a semantic
|
lcp@594
|
1732 |
equivalence proof taken from Winskel~\cite{winskel93}. It formalises the
|
lcp@594
|
1733 |
denotational and operational semantics of a simple while-language, then
|
lcp@594
|
1734 |
proves the two equivalent. It contains several datatype and inductive
|
lcp@594
|
1735 |
definitions, and demonstrates their use.
|
lcp@594
|
1736 |
|
wenzelm@9695
|
1737 |
Directory {\tt HOL/ex} contains other examples and experimental proofs in HOL.
|
wenzelm@9695
|
1738 |
Here is an overview of the more interesting files.
|
lcp@594
|
1739 |
\begin{itemize}
|
lcp@594
|
1740 |
\item File {\tt cla.ML} demonstrates the classical reasoner on over sixty
|
lcp@344
|
1741 |
predicate calculus theorems, ranging from simple tautologies to
|
lcp@344
|
1742 |
moderately difficult problems involving equality and quantifiers.
|
lcp@344
|
1743 |
|
lcp@594
|
1744 |
\item File {\tt meson.ML} contains an experimental implementation of the {\sc
|
lcp@315
|
1745 |
meson} proof procedure, inspired by Plaisted~\cite{plaisted90}. It is
|
lcp@315
|
1746 |
much more powerful than Isabelle's classical reasoner. But it is less
|
lcp@315
|
1747 |
useful in practice because it works only for pure logic; it does not
|
lcp@315
|
1748 |
accept derived rules for the set theory primitives, for example.
|
lcp@104
|
1749 |
|
lcp@594
|
1750 |
\item File {\tt mesontest.ML} contains test data for the {\sc meson} proof
|
lcp@315
|
1751 |
procedure. These are mostly taken from Pelletier \cite{pelletier86}.
|
lcp@104
|
1752 |
|
lcp@594
|
1753 |
\item File {\tt set.ML} proves Cantor's Theorem, which is presented in
|
lcp@315
|
1754 |
\S\ref{sec:hol-cantor} below, and the Schr\"oder-Bernstein Theorem.
|
lcp@104
|
1755 |
|
lcp@594
|
1756 |
\item Theories {\tt InSort} and {\tt Qsort} prove correctness properties of
|
lcp@594
|
1757 |
insertion sort and quick sort.
|
lcp@104
|
1758 |
|
lcp@629
|
1759 |
\item The definition of lazy lists demonstrates methods for handling
|
lcp@629
|
1760 |
infinite data structures and coinduction in higher-order
|
lcp@629
|
1761 |
logic~\cite{paulson-coind}. Theory \thydx{LList} defines an operator for
|
lcp@629
|
1762 |
corecursion on lazy lists, which is used to define a few simple functions
|
lcp@629
|
1763 |
such as map and append. Corecursion cannot easily define operations such
|
lcp@629
|
1764 |
as filter, which can compute indefinitely before yielding the next
|
lcp@629
|
1765 |
element (if any!) of the lazy list. A coinduction principle is defined
|
lcp@629
|
1766 |
for proving equations on lazy lists.
|
wenzelm@9695
|
1767 |
|
wenzelm@9695
|
1768 |
\item Theory {\tt PropLog} proves the soundness and completeness of classical
|
wenzelm@9695
|
1769 |
propositional logic, given a truth table semantics. The only connective is
|
wenzelm@9695
|
1770 |
$\imp$. A Hilbert-style axiom system is specified, and its set of theorems
|
wenzelm@9695
|
1771 |
defined inductively. A similar proof in ZF is described
|
wenzelm@9695
|
1772 |
elsewhere~\cite{paulson-set-II}.
|
lcp@315
|
1773 |
|
lcp@594
|
1774 |
\item Theory {\tt Term} develops an experimental recursive type definition;
|
lcp@315
|
1775 |
the recursion goes through the type constructor~\tydx{list}.
|
lcp@104
|
1776 |
|
lcp@594
|
1777 |
\item Theory {\tt Simult} constructs mutually recursive sets of trees and
|
lcp@594
|
1778 |
forests, including induction and recursion rules.
|
lcp@111
|
1779 |
|
lcp@594
|
1780 |
\item Theory {\tt MT} contains Jacob Frost's formalization~\cite{frost93} of
|
lcp@315
|
1781 |
Milner and Tofte's coinduction example~\cite{milner-coind}. This
|
lcp@315
|
1782 |
substantial proof concerns the soundness of a type system for a simple
|
lcp@315
|
1783 |
functional language. The semantics of recursion is given by a cyclic
|
lcp@315
|
1784 |
environment, which makes a coinductive argument appropriate.
|
lcp@594
|
1785 |
\end{itemize}
|
lcp@104
|
1786 |
|
lcp@104
|
1787 |
|
lcp@344
|
1788 |
\goodbreak
|
lcp@315
|
1789 |
\section{Example: Cantor's Theorem}\label{sec:hol-cantor}
|
lcp@104
|
1790 |
Cantor's Theorem states that every set has more subsets than it has
|
lcp@104
|
1791 |
elements. It has become a favourite example in higher-order logic since
|
lcp@104
|
1792 |
it is so easily expressed:
|
lcp@104
|
1793 |
\[ \forall f::[\alpha,\alpha]\To bool. \exists S::\alpha\To bool.
|
lcp@104
|
1794 |
\forall x::\alpha. f(x) \not= S
|
lcp@104
|
1795 |
\]
|
lcp@315
|
1796 |
%
|
lcp@104
|
1797 |
Viewing types as sets, $\alpha\To bool$ represents the powerset
|
lcp@104
|
1798 |
of~$\alpha$. This version states that for every function from $\alpha$ to
|
lcp@344
|
1799 |
its powerset, some subset is outside its range.
|
lcp@344
|
1800 |
|
wenzelm@9695
|
1801 |
The Isabelle proof uses HOL's set theory, with the type $\alpha\,set$ and the
|
wenzelm@9695
|
1802 |
operator \cdx{range}. The set~$S$ is given as an unknown instead of a
|
lcp@315
|
1803 |
quantified variable so that we may inspect the subset found by the proof.
|
lcp@104
|
1804 |
\begin{ttbox}
|
lcp@104
|
1805 |
goal Set.thy "~ ?S : range(f :: 'a=>'a set)";
|
lcp@104
|
1806 |
{\out Level 0}
|
lcp@104
|
1807 |
{\out ~ ?S : range(f)}
|
lcp@104
|
1808 |
{\out 1. ~ ?S : range(f)}
|
lcp@104
|
1809 |
\end{ttbox}
|
lcp@315
|
1810 |
The first two steps are routine. The rule \tdx{rangeE} replaces
|
lcp@315
|
1811 |
$\Var{S}\in {\tt range}(f)$ by $\Var{S}=f(x)$ for some~$x$.
|
lcp@104
|
1812 |
\begin{ttbox}
|
lcp@104
|
1813 |
by (resolve_tac [notI] 1);
|
lcp@104
|
1814 |
{\out Level 1}
|
lcp@104
|
1815 |
{\out ~ ?S : range(f)}
|
lcp@104
|
1816 |
{\out 1. ?S : range(f) ==> False}
|
lcp@287
|
1817 |
\ttbreak
|
lcp@104
|
1818 |
by (eresolve_tac [rangeE] 1);
|
lcp@104
|
1819 |
{\out Level 2}
|
lcp@104
|
1820 |
{\out ~ ?S : range(f)}
|
lcp@104
|
1821 |
{\out 1. !!x. ?S = f(x) ==> False}
|
lcp@104
|
1822 |
\end{ttbox}
|
lcp@315
|
1823 |
Next, we apply \tdx{equalityCE}, reasoning that since $\Var{S}=f(x)$,
|
lcp@104
|
1824 |
we have $\Var{c}\in \Var{S}$ if and only if $\Var{c}\in f(x)$ for
|
lcp@104
|
1825 |
any~$\Var{c}$.
|
lcp@104
|
1826 |
\begin{ttbox}
|
lcp@104
|
1827 |
by (eresolve_tac [equalityCE] 1);
|
lcp@104
|
1828 |
{\out Level 3}
|
lcp@104
|
1829 |
{\out ~ ?S : range(f)}
|
lcp@104
|
1830 |
{\out 1. !!x. [| ?c3(x) : ?S; ?c3(x) : f(x) |] ==> False}
|
lcp@104
|
1831 |
{\out 2. !!x. [| ~ ?c3(x) : ?S; ~ ?c3(x) : f(x) |] ==> False}
|
lcp@104
|
1832 |
\end{ttbox}
|
lcp@315
|
1833 |
Now we use a bit of creativity. Suppose that~$\Var{S}$ has the form of a
|
lcp@104
|
1834 |
comprehension. Then $\Var{c}\in\{x.\Var{P}(x)\}$ implies
|
lcp@315
|
1835 |
$\Var{P}(\Var{c})$. Destruct-resolution using \tdx{CollectD}
|
lcp@315
|
1836 |
instantiates~$\Var{S}$ and creates the new assumption.
|
lcp@104
|
1837 |
\begin{ttbox}
|
lcp@104
|
1838 |
by (dresolve_tac [CollectD] 1);
|
lcp@104
|
1839 |
{\out Level 4}
|
lcp@104
|
1840 |
{\out ~ \{x. ?P7(x)\} : range(f)}
|
lcp@104
|
1841 |
{\out 1. !!x. [| ?c3(x) : f(x); ?P7(?c3(x)) |] ==> False}
|
lcp@104
|
1842 |
{\out 2. !!x. [| ~ ?c3(x) : \{x. ?P7(x)\}; ~ ?c3(x) : f(x) |] ==> False}
|
lcp@104
|
1843 |
\end{ttbox}
|
lcp@104
|
1844 |
Forcing a contradiction between the two assumptions of subgoal~1 completes
|
lcp@344
|
1845 |
the instantiation of~$S$. It is now the set $\{x. x\not\in f(x)\}$, which
|
lcp@344
|
1846 |
is the standard diagonal construction.
|
lcp@104
|
1847 |
\begin{ttbox}
|
lcp@104
|
1848 |
by (contr_tac 1);
|
lcp@104
|
1849 |
{\out Level 5}
|
lcp@104
|
1850 |
{\out ~ \{x. ~ x : f(x)\} : range(f)}
|
lcp@104
|
1851 |
{\out 1. !!x. [| ~ x : \{x. ~ x : f(x)\}; ~ x : f(x) |] ==> False}
|
lcp@104
|
1852 |
\end{ttbox}
|
lcp@315
|
1853 |
The rest should be easy. To apply \tdx{CollectI} to the negated
|
lcp@104
|
1854 |
assumption, we employ \ttindex{swap_res_tac}:
|
lcp@104
|
1855 |
\begin{ttbox}
|
lcp@104
|
1856 |
by (swap_res_tac [CollectI] 1);
|
lcp@104
|
1857 |
{\out Level 6}
|
lcp@104
|
1858 |
{\out ~ \{x. ~ x : f(x)\} : range(f)}
|
lcp@104
|
1859 |
{\out 1. !!x. [| ~ x : f(x); ~ False |] ==> ~ x : f(x)}
|
lcp@287
|
1860 |
\ttbreak
|
lcp@104
|
1861 |
by (assume_tac 1);
|
lcp@104
|
1862 |
{\out Level 7}
|
lcp@104
|
1863 |
{\out ~ \{x. ~ x : f(x)\} : range(f)}
|
lcp@104
|
1864 |
{\out No subgoals!}
|
lcp@104
|
1865 |
\end{ttbox}
|
lcp@104
|
1866 |
How much creativity is required? As it happens, Isabelle can prove this
|
wenzelm@9695
|
1867 |
theorem automatically. The classical set \ttindex{set_cs} contains rules for
|
wenzelm@9695
|
1868 |
most of the constructs of HOL's set theory. We must augment it with
|
wenzelm@9695
|
1869 |
\tdx{equalityCE} to break up set equalities, and then apply best-first search.
|
wenzelm@9695
|
1870 |
Depth-first search would diverge, but best-first search successfully navigates
|
wenzelm@9695
|
1871 |
through the large search space. \index{search!best-first}
|
lcp@104
|
1872 |
\begin{ttbox}
|
lcp@104
|
1873 |
choplev 0;
|
lcp@104
|
1874 |
{\out Level 0}
|
lcp@104
|
1875 |
{\out ~ ?S : range(f)}
|
lcp@104
|
1876 |
{\out 1. ~ ?S : range(f)}
|
lcp@287
|
1877 |
\ttbreak
|
lcp@104
|
1878 |
by (best_tac (set_cs addSEs [equalityCE]) 1);
|
lcp@104
|
1879 |
{\out Level 1}
|
lcp@104
|
1880 |
{\out ~ \{x. ~ x : f(x)\} : range(f)}
|
lcp@104
|
1881 |
{\out No subgoals!}
|
lcp@104
|
1882 |
\end{ttbox}
|
lcp@315
|
1883 |
|
lcp@315
|
1884 |
\index{higher-order logic|)}
|