| author | oheimb |
| Thu, 03 May 2001 18:22:36 +0200 | |
| changeset 11283 | 358f82c4550d |
| parent 11203 | 881222d48777 |
| child 11410 | b3b61ea9632c |
| permissions | -rw-r--r-- |
| 10857 | 1 |
% $Id$ |
| 10303 | 2 |
\chapter{Sets, Functions and Relations}
|
3 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
4 |
This chapter describes the formalization of typed set theory, which is |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
5 |
the basis of much else in HOL\@. For example, an |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
6 |
inductive definition yields a set, and the abstract theories of relations |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
7 |
regard a relation as a set of pairs. The chapter introduces the well-known |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
8 |
constants such as union and intersection, as well as the main operations on relations, such as converse, composition and |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
9 |
transitive closure. Functions are also covered. They are not sets in |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
10 |
HOL, but many of their properties concern sets: the range of a |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
11 |
function is a set, and the inverse image of a function maps sets to sets. |
| 10303 | 12 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
13 |
This chapter will be useful to anybody who plans to develop a substantial |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
14 |
proof. sets are convenient for formalizing computer science concepts such |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
15 |
as grammars, logical calculi and state transition systems. Isabelle can |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
16 |
prove many statements involving sets automatically. |
| 10303 | 17 |
|
18 |
This chapter ends with a case study concerning model checking for the |
|
19 |
temporal logic CTL\@. Most of the other examples are simple. The |
|
20 |
chapter presents a small selection of built-in theorems in order to point |
|
21 |
out some key properties of the various constants and to introduce you to |
|
22 |
the notation. |
|
23 |
||
24 |
Natural deduction rules are provided for the set theory constants, but they |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
25 |
are seldom used directly, so only a few are presented here. |
| 10303 | 26 |
|
27 |
||
28 |
\section{Sets}
|
|
29 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
30 |
\index{sets|(}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
31 |
HOL's set theory should not be confused with traditional, untyped set |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
32 |
theory, in which everything is a set. Our sets are typed. In a given set, |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
33 |
all elements have the same type, say~$\tau$, and the set itself has type |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
34 |
\isa{$\tau$~set}.
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
35 |
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
36 |
We begin with \bfindex{intersection}, \bfindex{union} and
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
37 |
\bfindex{complement}. In addition to the
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
38 |
\bfindex{membership relation}, there is a symbol for its negation. These
|
| 10857 | 39 |
points can be seen below. |
| 10303 | 40 |
|
41 |
Here are the natural deduction rules for intersection. Note the |
|
42 |
resemblance to those for conjunction. |
|
43 |
\begin{isabelle}
|
|
| 10857 | 44 |
\isasymlbrakk c\ \isasymin\ A;\ c\ \isasymin\ B\isasymrbrakk\ |
45 |
\isasymLongrightarrow\ c\ \isasymin\ A\ \isasyminter\ B% |
|
| 10303 | 46 |
\rulename{IntI}\isanewline
|
| 10857 | 47 |
c\ \isasymin\ A\ \isasyminter\ B\ \isasymLongrightarrow\ c\ \isasymin\ A |
| 10303 | 48 |
\rulename{IntD1}\isanewline
|
| 10857 | 49 |
c\ \isasymin\ A\ \isasyminter\ B\ \isasymLongrightarrow\ c\ \isasymin\ B |
50 |
\rulename{IntD2}
|
|
| 10303 | 51 |
\end{isabelle}
|
52 |
||
| 10857 | 53 |
Here are two of the many installed theorems concerning set complement. |
54 |
Note that it is denoted by a minus sign. |
|
| 10303 | 55 |
\begin{isabelle}
|
| 10857 | 56 |
(c\ \isasymin\ -\ A)\ =\ (c\ \isasymnotin\ A) |
| 10303 | 57 |
\rulename{Compl_iff}\isanewline
|
| 10857 | 58 |
-\ (A\ \isasymunion\ B)\ =\ -\ A\ \isasyminter\ -\ B |
| 10303 | 59 |
\rulename{Compl_Un}
|
60 |
\end{isabelle}
|
|
61 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
62 |
Set \textbf{difference}\indexbold{difference!of sets} is the intersection
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
63 |
of a set with the complement of another set. Here we also see the syntax |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
64 |
for the empty set and for the universal set. |
| 10303 | 65 |
\begin{isabelle}
|
| 10857 | 66 |
A\ \isasyminter\ (B\ -\ A)\ =\ \isacharbraceleft\isacharbraceright |
67 |
\rulename{Diff_disjoint}\isanewline
|
|
68 |
A\ \isasymunion\ -\ A\ =\ UNIV% |
|
| 10303 | 69 |
\rulename{Compl_partition}
|
70 |
\end{isabelle}
|
|
71 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
72 |
The \bfindex{subset relation} holds between two sets just if every element
|
| 10303 | 73 |
of one is also an element of the other. This relation is reflexive. These |
74 |
are its natural deduction rules: |
|
75 |
\begin{isabelle}
|
|
76 |
({\isasymAnd}x.\ x\ \isasymin\ A\ \isasymLongrightarrow\ x\ \isasymin\ B)\ \isasymLongrightarrow\ A\ \isasymsubseteq\ B%
|
|
77 |
\rulename{subsetI}%
|
|
78 |
\par\smallskip% \isanewline didn't leave enough space |
|
79 |
\isasymlbrakk A\ \isasymsubseteq\ B;\ c\ \isasymin\ |
|
80 |
A\isasymrbrakk\ \isasymLongrightarrow\ c\ |
|
81 |
\isasymin\ B% |
|
82 |
\rulename{subsetD}
|
|
83 |
\end{isabelle}
|
|
84 |
In harder proofs, you may need to apply \isa{subsetD} giving a specific term
|
|
85 |
for~\isa{c}. However, \isa{blast} can instantly prove facts such as this
|
|
86 |
one: |
|
87 |
\begin{isabelle}
|
|
| 10857 | 88 |
(A\ \isasymunion\ B\ \isasymsubseteq\ C)\ =\ |
89 |
(A\ \isasymsubseteq\ C\ \isasymand\ B\ \isasymsubseteq\ C) |
|
| 10303 | 90 |
\rulename{Un_subset_iff}
|
91 |
\end{isabelle}
|
|
92 |
Here is another example, also proved automatically: |
|
93 |
\begin{isabelle}
|
|
94 |
\isacommand{lemma}\ "(A\
|
|
| 10857 | 95 |
\isasymsubseteq\ -B)\ =\ (B\ \isasymsubseteq\ -A)"\isanewline |
96 |
\isacommand{by}\ blast
|
|
| 10303 | 97 |
\end{isabelle}
|
98 |
% |
|
| 10983 | 99 |
This is the same example using \textsc{ascii} syntax, illustrating a pitfall:
|
| 10303 | 100 |
\begin{isabelle}
|
| 10857 | 101 |
\isacommand{lemma}\ "(A\ <=\ -B)\ =\ (B\ <=\ -A)"
|
| 10303 | 102 |
\end{isabelle}
|
103 |
% |
|
104 |
The proof fails. It is not a statement about sets, due to overloading; |
|
105 |
the relation symbol~\isa{<=} can be any relation, not just
|
|
106 |
subset. |
|
107 |
In this general form, the statement is not valid. Putting |
|
108 |
in a type constraint forces the variables to denote sets, allowing the |
|
109 |
proof to succeed: |
|
110 |
||
111 |
\begin{isabelle}
|
|
| 10857 | 112 |
\isacommand{lemma}\ "((A::\ {\isacharprime}a\ set)\ <=\ -B)\ =\ (B\ <=\
|
| 10303 | 113 |
-A)" |
114 |
\end{isabelle}
|
|
| 10857 | 115 |
Section~\ref{sec:axclass} below describes overloading. Incidentally,
|
116 |
\isa{A~\isasymsubseteq~-B} asserts that the sets \isa{A} and \isa{B} are
|
|
117 |
disjoint. |
|
| 10303 | 118 |
|
119 |
\medskip |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
120 |
Two sets are \textbf{equal}\indexbold{equality!of sets} if they contain the
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
121 |
same elements. This is |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
122 |
the principle of \textbf{extensionality}\indexbold{extensionality!for sets}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
123 |
for sets. |
| 10303 | 124 |
\begin{isabelle}
|
125 |
({\isasymAnd}x.\ (x\ {\isasymin}\ A)\ =\ (x\ {\isasymin}\ B))\
|
|
126 |
{\isasymLongrightarrow}\ A\ =\ B
|
|
127 |
\rulename{set_ext}
|
|
128 |
\end{isabelle}
|
|
129 |
Extensionality is often expressed as |
|
130 |
$A=B\iff A\subseteq B\conj B\subseteq A$. |
|
131 |
The following rules express both |
|
132 |
directions of this equivalence. Proving a set equation using |
|
133 |
\isa{equalityI} allows the two inclusions to be proved independently.
|
|
134 |
\begin{isabelle}
|
|
135 |
\isasymlbrakk A\ \isasymsubseteq\ B;\ B\ \isasymsubseteq\ |
|
| 10857 | 136 |
A\isasymrbrakk\ \isasymLongrightarrow\ A\ =\ B |
| 10303 | 137 |
\rulename{equalityI}
|
138 |
\par\smallskip% \isanewline didn't leave enough space |
|
139 |
\isasymlbrakk A\ =\ B;\ \isasymlbrakk A\ \isasymsubseteq\ B;\ B\ |
|
140 |
\isasymsubseteq\ A\isasymrbrakk\ \isasymLongrightarrow\ P\isasymrbrakk\ |
|
141 |
\isasymLongrightarrow\ P% |
|
142 |
\rulename{equalityE}
|
|
143 |
\end{isabelle}
|
|
144 |
||
145 |
||
| 10857 | 146 |
\subsection{Finite Set Notation}
|
| 10303 | 147 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
148 |
\indexbold{sets!notation for finite}\index{*insert (constant)}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
149 |
Finite sets are expressed using the constant \isa{insert}, which is
|
| 10857 | 150 |
a form of union: |
| 10303 | 151 |
\begin{isabelle}
|
| 10857 | 152 |
insert\ a\ A\ =\ \isacharbraceleft a\isacharbraceright\ \isasymunion\ A |
| 10303 | 153 |
\rulename{insert_is_Un}
|
154 |
\end{isabelle}
|
|
155 |
% |
|
156 |
The finite set expression \isa{\isacharbraceleft
|
|
157 |
a,b\isacharbraceright} abbreviates |
|
158 |
\isa{insert\ a\ (insert\ b\ \isacharbraceleft\isacharbraceright)}.
|
|
| 10857 | 159 |
Many facts about finite sets can be proved automatically: |
| 10303 | 160 |
\begin{isabelle}
|
161 |
\isacommand{lemma}\
|
|
| 10857 | 162 |
"\isacharbraceleft a,b\isacharbraceright\ |
163 |
\isasymunion\ \isacharbraceleft c,d\isacharbraceright\ =\ |
|
164 |
\isacharbraceleft a,b,c,d\isacharbraceright"\isanewline |
|
165 |
\isacommand{by}\ blast
|
|
| 10303 | 166 |
\end{isabelle}
|
167 |
||
168 |
||
169 |
Not everything that we would like to prove is valid. |
|
| 10857 | 170 |
Consider this attempt: |
| 10303 | 171 |
\begin{isabelle}
|
| 10857 | 172 |
\isacommand{lemma}\ "\isacharbraceleft a,b\isacharbraceright\ \isasyminter\ \isacharbraceleft b,c\isacharbraceright\ =\
|
173 |
\isacharbraceleft b\isacharbraceright"\isanewline |
|
174 |
\isacommand{apply}\ auto
|
|
| 10303 | 175 |
\end{isabelle}
|
176 |
% |
|
177 |
The proof fails, leaving the subgoal \isa{b=c}. To see why it
|
|
178 |
fails, consider a correct version: |
|
179 |
\begin{isabelle}
|
|
| 10857 | 180 |
\isacommand{lemma}\ "\isacharbraceleft a,b\isacharbraceright\ \isasyminter\
|
181 |
\isacharbraceleft b,c\isacharbraceright\ =\ (if\ a=c\ then\ |
|
182 |
\isacharbraceleft a,b\isacharbraceright\ else\ \isacharbraceleft |
|
183 |
b\isacharbraceright)"\isanewline |
|
184 |
\isacommand{apply}\ simp\isanewline
|
|
185 |
\isacommand{by}\ blast
|
|
| 10303 | 186 |
\end{isabelle}
|
187 |
||
188 |
Our mistake was to suppose that the various items were distinct. Another |
|
189 |
remark: this proof uses two methods, namely {\isa{simp}} and
|
|
190 |
{\isa{blast}}. Calling {\isa{simp}} eliminates the
|
|
191 |
\isa{if}-\isa{then}-\isa{else} expression, which {\isa{blast}}
|
|
192 |
cannot break down. The combined methods (namely {\isa{force}} and
|
|
| 10857 | 193 |
\isa{auto}) can prove this fact in one step.
|
| 10303 | 194 |
|
195 |
||
| 10857 | 196 |
\subsection{Set Comprehension}
|
| 10303 | 197 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
198 |
\index{set comprehensions|(}%
|
| 10857 | 199 |
The set comprehension \isa{\isacharbraceleft x.\
|
200 |
P\isacharbraceright} expresses the set of all elements that satisfy the |
|
201 |
predicate~\isa{P}. Two laws describe the relationship between set
|
|
202 |
comprehension and the membership relation: |
|
| 10303 | 203 |
\begin{isabelle}
|
204 |
(a\ \isasymin\ |
|
| 10857 | 205 |
\isacharbraceleft x.\ P\ x\isacharbraceright)\ =\ P\ a |
206 |
\rulename{mem_Collect_eq}\isanewline
|
|
207 |
\isacharbraceleft x.\ x\ \isasymin\ A\isacharbraceright\ =\ A |
|
| 10303 | 208 |
\rulename{Collect_mem_eq}
|
209 |
\end{isabelle}
|
|
210 |
||
| 10857 | 211 |
\smallskip |
| 10303 | 212 |
Facts such as these have trivial proofs: |
213 |
\begin{isabelle}
|
|
| 10857 | 214 |
\isacommand{lemma}\ "\isacharbraceleft x.\ P\ x\ \isasymor\
|
| 10303 | 215 |
x\ \isasymin\ A\isacharbraceright\ =\ |
| 10857 | 216 |
\isacharbraceleft x.\ P\ x\isacharbraceright\ \isasymunion\ A" |
| 10303 | 217 |
\par\smallskip |
| 10857 | 218 |
\isacommand{lemma}\ "\isacharbraceleft x.\ P\ x\
|
| 10303 | 219 |
\isasymlongrightarrow\ Q\ x\isacharbraceright\ =\ |
| 10857 | 220 |
-\isacharbraceleft x.\ P\ x\isacharbraceright\ |
221 |
\isasymunion\ \isacharbraceleft x.\ Q\ x\isacharbraceright" |
|
| 10303 | 222 |
\end{isabelle}
|
223 |
||
| 10857 | 224 |
\smallskip |
| 10303 | 225 |
Isabelle has a general syntax for comprehension, which is best |
226 |
described through an example: |
|
227 |
\begin{isabelle}
|
|
| 10857 | 228 |
\isacommand{lemma}\ "\isacharbraceleft p*q\ \isacharbar\ p\ q.\
|
| 10303 | 229 |
p{\isasymin}prime\ \isasymand\ q{\isasymin}prime\isacharbraceright\ =\
|
230 |
\isanewline |
|
| 10857 | 231 |
\ \ \ \ \ \ \ \ \isacharbraceleft z.\ \isasymexists p\ q.\ z\ =\ p*q\ |
| 10303 | 232 |
\isasymand\ p{\isasymin}prime\ \isasymand\
|
233 |
q{\isasymin}prime\isacharbraceright"
|
|
234 |
\end{isabelle}
|
|
235 |
The proof is trivial because the left and right hand side |
|
236 |
of the expression are synonymous. The syntax appearing on the |
|
237 |
left-hand side abbreviates the right-hand side: in this case, all numbers |
|
| 10857 | 238 |
that are the product of two primes. The syntax provides a neat |
| 10303 | 239 |
way of expressing any set given by an expression built up from variables |
| 10857 | 240 |
under specific constraints. The drawback is that it hides the true form of |
241 |
the expression, with its existential quantifiers. |
|
242 |
||
243 |
\smallskip |
|
244 |
\emph{Remark}. We do not need sets at all. They are essentially equivalent
|
|
245 |
to predicate variables, which are allowed in higher-order logic. The main |
|
246 |
benefit of sets is their notation; we can write \isa{x{\isasymin}A}
|
|
247 |
and |
|
248 |
\isa{\isacharbraceleft z.\ P\isacharbraceright} where predicates would
|
|
249 |
require writing |
|
250 |
\isa{A(x)} and
|
|
251 |
\isa{{\isasymlambda}z.\ P}.
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
252 |
\index{set comprehensions|)}
|
| 10303 | 253 |
|
254 |
||
| 10857 | 255 |
\subsection{Binding Operators}
|
| 10303 | 256 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
257 |
\index{quantifiers!for sets|(}%
|
| 10303 | 258 |
Universal and existential quantifications may range over sets, |
259 |
with the obvious meaning. Here are the natural deduction rules for the |
|
260 |
bounded universal quantifier. Occasionally you will need to apply |
|
261 |
\isa{bspec} with an explicit instantiation of the variable~\isa{x}:
|
|
262 |
% |
|
263 |
\begin{isabelle}
|
|
264 |
({\isasymAnd}x.\ x\ \isasymin\ A\ \isasymLongrightarrow\ P\ x)\ \isasymLongrightarrow\ {\isasymforall}x\isasymin
|
|
265 |
A.\ P\ x% |
|
266 |
\rulename{ballI}%
|
|
267 |
\isanewline |
|
268 |
\isasymlbrakk{\isasymforall}x\isasymin A.\
|
|
269 |
P\ x;\ x\ \isasymin\ |
|
270 |
A\isasymrbrakk\ \isasymLongrightarrow\ P\ |
|
271 |
x% |
|
272 |
\rulename{bspec}
|
|
273 |
\end{isabelle}
|
|
274 |
% |
|
275 |
Dually, here are the natural deduction rules for the |
|
276 |
bounded existential quantifier. You may need to apply |
|
277 |
\isa{bexI} with an explicit instantiation:
|
|
278 |
\begin{isabelle}
|
|
279 |
\isasymlbrakk P\ x;\ |
|
280 |
x\ \isasymin\ A\isasymrbrakk\ |
|
281 |
\isasymLongrightarrow\ |
|
| 10857 | 282 |
\isasymexists x\isasymin A.\ P\ |
| 10303 | 283 |
x% |
284 |
\rulename{bexI}%
|
|
285 |
\isanewline |
|
| 10857 | 286 |
\isasymlbrakk\isasymexists x\isasymin A.\ |
| 10303 | 287 |
P\ x;\ {\isasymAnd}x.\
|
288 |
{\isasymlbrakk}x\ \isasymin\ A;\
|
|
289 |
P\ x\isasymrbrakk\ \isasymLongrightarrow\ |
|
290 |
Q\isasymrbrakk\ \isasymLongrightarrow\ Q% |
|
291 |
\rulename{bexE}
|
|
292 |
\end{isabelle}
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
293 |
\index{quantifiers!for sets|)}
|
| 10303 | 294 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
295 |
\index{union!indexed}%
|
| 10303 | 296 |
Unions can be formed over the values of a given set. The syntax is |
| 10983 | 297 |
\mbox{\isa{\isasymUnion x\isasymin A.\ B}} or \isa{UN
|
298 |
x\isasymin A.\ B} in \textsc{ascii}. Indexed union satisfies this basic law:
|
|
| 10303 | 299 |
\begin{isabelle}
|
300 |
(b\ \isasymin\ |
|
| 10857 | 301 |
(\isasymUnion x\isasymin A.\ B\ x))\ =\ (\isasymexists x\isasymin A.\ |
| 10303 | 302 |
b\ \isasymin\ B\ x) |
303 |
\rulename{UN_iff}
|
|
304 |
\end{isabelle}
|
|
305 |
It has two natural deduction rules similar to those for the existential |
|
306 |
quantifier. Sometimes \isa{UN_I} must be applied explicitly:
|
|
307 |
\begin{isabelle}
|
|
308 |
\isasymlbrakk a\ \isasymin\ |
|
309 |
A;\ b\ \isasymin\ |
|
310 |
B\ a\isasymrbrakk\ \isasymLongrightarrow\ |
|
311 |
b\ \isasymin\ |
|
312 |
({\isasymUnion}x\isasymin A.\
|
|
313 |
B\ x) |
|
314 |
\rulename{UN_I}%
|
|
315 |
\isanewline |
|
316 |
\isasymlbrakk b\ \isasymin\ |
|
317 |
({\isasymUnion}x\isasymin A.\
|
|
318 |
B\ x);\ |
|
319 |
{\isasymAnd}x.\ {\isasymlbrakk}x\ \isasymin\
|
|
320 |
A;\ b\ \isasymin\ |
|
321 |
B\ x\isasymrbrakk\ \isasymLongrightarrow\ |
|
322 |
R\isasymrbrakk\ \isasymLongrightarrow\ R% |
|
323 |
\rulename{UN_E}
|
|
324 |
\end{isabelle}
|
|
325 |
% |
|
| 11203 | 326 |
The following built-in syntax translation (see \S\ref{sec:def-translations})
|
327 |
lets us express the union over a \emph{type}:
|
|
| 10303 | 328 |
\begin{isabelle}
|
329 |
\ \ \ \ \ |
|
| 10983 | 330 |
({\isasymUnion}x.\ B\ x)\ {\isasymrightleftharpoons}\
|
| 10303 | 331 |
({\isasymUnion}x{\isasymin}UNIV.\ B\ x)
|
332 |
\end{isabelle}
|
|
| 11203 | 333 |
%Abbreviations work as you might expect. The term on the left-hand side of |
334 |
%the \isasymrightleftharpoons\ symbol is automatically translated to the right-hand side when the |
|
335 |
%term is parsed, the reverse translation being done when the term is |
|
336 |
%displayed. |
|
| 10303 | 337 |
|
338 |
We may also express the union of a set of sets, written \isa{Union\ C} in
|
|
339 |
\textsc{ascii}:
|
|
340 |
\begin{isabelle}
|
|
| 10857 | 341 |
(A\ \isasymin\ \isasymUnion C)\ =\ (\isasymexists X\isasymin C.\ A\ |
| 10303 | 342 |
\isasymin\ X) |
343 |
\rulename{Union_iff}
|
|
344 |
\end{isabelle}
|
|
345 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
346 |
\index{intersection!indexed}%
|
| 10303 | 347 |
Intersections are treated dually, although they seem to be used less often |
348 |
than unions. The syntax below would be \isa{INT
|
|
349 |
x:\ A.\ B} and \isa{Inter\ C} in \textsc{ascii}. Among others, these
|
|
350 |
theorems are available: |
|
351 |
\begin{isabelle}
|
|
352 |
(b\ \isasymin\ |
|
353 |
({\isasymInter}x\isasymin A.\
|
|
354 |
B\ x))\ |
|
355 |
=\ |
|
356 |
({\isasymforall}x\isasymin A.\
|
|
357 |
b\ \isasymin\ B\ x) |
|
358 |
\rulename{INT_iff}%
|
|
359 |
\isanewline |
|
360 |
(A\ \isasymin\ |
|
361 |
\isasymInter C)\ =\ |
|
362 |
({\isasymforall}X\isasymin C.\
|
|
363 |
A\ \isasymin\ X) |
|
364 |
\rulename{Inter_iff}
|
|
365 |
\end{isabelle}
|
|
366 |
||
367 |
Isabelle uses logical equivalences such as those above in automatic proof. |
|
368 |
Unions, intersections and so forth are not simply replaced by their |
|
369 |
definitions. Instead, membership tests are simplified. For example, $x\in |
|
370 |
A\cup B$ is replaced by $x\in A\vee x\in B$. |
|
371 |
||
372 |
The internal form of a comprehension involves the constant |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
373 |
\isa{Collect},\index{*Collect (constant)}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
374 |
which occasionally appears when a goal or theorem |
| 10303 | 375 |
is displayed. For example, \isa{Collect\ P} is the same term as
|
| 11159 | 376 |
\isa{\isacharbraceleft x.\ P\ x\isacharbraceright}. The same thing can
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
377 |
happen with quantifiers: \hbox{\isa{All\ P}}\index{*All (constant)}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
378 |
is |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
379 |
\isa{{\isasymforall}z.\ P\ x} and
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
380 |
\hbox{\isa{Ex\ P}}\index{*Ex (constant)} is \isa{\isasymexists z.\ P\ x};
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
381 |
also \isa{Ball\ A\ P}\index{*Ball (constant)} is
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
382 |
\isa{{\isasymforall}z\isasymin A.\ P\ x} and
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
383 |
\isa{Bex\ A\ P}\index{*Bex (constant)} is
|
| 10857 | 384 |
\isa{\isasymexists z\isasymin A.\ P\ x}. For indexed unions and
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
385 |
intersections, you may see the constants |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
386 |
\isa{UNION}\index{*UNION (constant)} and
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
387 |
\isa{INTER}\index{*INTER (constant)}\@.
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
388 |
The internal constant for $\varepsilon x.P(x)$ is |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
389 |
\isa{Eps}\index{*Eps (constant)}.
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
390 |
|
| 10303 | 391 |
|
392 |
We have only scratched the surface of Isabelle/HOL's set theory. |
|
393 |
One primitive not mentioned here is the powerset operator |
|
394 |
{\isa{Pow}}. Hundreds of theorems are proved in theory \isa{Set} and its
|
|
395 |
descendants. |
|
396 |
||
397 |
||
| 10857 | 398 |
\subsection{Finiteness and Cardinality}
|
| 10303 | 399 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
400 |
\index{sets!finite}%
|
| 10303 | 401 |
The predicate \isa{finite} holds of all finite sets. Isabelle/HOL includes
|
402 |
many familiar theorems about finiteness and cardinality |
|
403 |
(\isa{card}). For example, we have theorems concerning the cardinalities
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
404 |
of unions, intersections and the powerset:\index{cardinality}
|
| 10303 | 405 |
% |
406 |
\begin{isabelle}
|
|
407 |
{\isasymlbrakk}finite\ A;\ finite\ B\isasymrbrakk\isanewline
|
|
408 |
\isasymLongrightarrow\ card\ A\ \isacharplus\ card\ B\ =\ card\ (A\ \isasymunion\ B)\ \isacharplus\ card\ (A\ \isasyminter\ B) |
|
409 |
\rulename{card_Un_Int}%
|
|
410 |
\isanewline |
|
411 |
\isanewline |
|
412 |
finite\ A\ \isasymLongrightarrow\ card\ |
|
413 |
(Pow\ A)\ =\ 2\ \isacharcircum\ card\ A% |
|
414 |
\rulename{card_Pow}%
|
|
415 |
\isanewline |
|
416 |
\isanewline |
|
417 |
finite\ A\ \isasymLongrightarrow\isanewline |
|
| 10857 | 418 |
card\ \isacharbraceleft B.\ B\ \isasymsubseteq\ |
| 10303 | 419 |
A\ \isasymand\ card\ B\ =\ |
420 |
k\isacharbraceright\ =\ card\ A\ choose\ k% |
|
421 |
\rulename{n_subsets}
|
|
422 |
\end{isabelle}
|
|
423 |
Writing $|A|$ as $n$, the last of these theorems says that the number of |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
424 |
$k$-element subsets of~$A$ is \index{binomial coefficients}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
425 |
$\binom{n}{k}$.
|
| 10303 | 426 |
|
| 10857 | 427 |
\begin{warn}
|
| 11203 | 428 |
The term \isa{finite\ A} is defined via a syntax translation as an
|
429 |
abbreviation for \isa{A \isasymin Finites}, where the constant \isa{Finites}
|
|
430 |
denotes the set of all finite sets of a given type. There is no constant |
|
431 |
\isa{finite}.
|
|
| 10857 | 432 |
\end{warn}
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
433 |
\index{sets|)}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
434 |
|
| 10303 | 435 |
|
436 |
\section{Functions}
|
|
437 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
438 |
\index{functions|(}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
439 |
This section describes a few concepts that involve |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
440 |
functions. Some of the more important theorems are given along with the |
| 10303 | 441 |
names. A few sample proofs appear. Unlike with set theory, however, |
| 10857 | 442 |
we cannot simply state lemmas and expect them to be proved using |
443 |
\isa{blast}.
|
|
| 10303 | 444 |
|
| 10857 | 445 |
\subsection{Function Basics}
|
446 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
447 |
Two functions are \textbf{equal}\indexbold{equality!of functions}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
448 |
if they yield equal results given equal |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
449 |
arguments. This is the principle of |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
450 |
\textbf{extensionality}\indexbold{extensionality!for functions} for
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
451 |
functions: |
| 10303 | 452 |
\begin{isabelle}
|
453 |
({\isasymAnd}x.\ f\ x\ =\ g\ x)\ {\isasymLongrightarrow}\ f\ =\ g
|
|
454 |
\rulename{ext}
|
|
455 |
\end{isabelle}
|
|
456 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
457 |
\indexbold{function updates}%
|
| 10303 | 458 |
Function \textbf{update} is useful for modelling machine states. It has
|
459 |
the obvious definition and many useful facts are proved about |
|
460 |
it. In particular, the following equation is installed as a simplification |
|
461 |
rule: |
|
462 |
\begin{isabelle}
|
|
463 |
(f(x:=y))\ z\ =\ (if\ z\ =\ x\ then\ y\ else\ f\ z) |
|
464 |
\rulename{fun_upd_apply}
|
|
465 |
\end{isabelle}
|
|
466 |
Two syntactic points must be noted. In |
|
467 |
\isa{(f(x:=y))\ z} we are applying an updated function to an
|
|
468 |
argument; the outer parentheses are essential. A series of two or more |
|
469 |
updates can be abbreviated as shown on the left-hand side of this theorem: |
|
470 |
\begin{isabelle}
|
|
471 |
f(x:=y,\ x:=z)\ =\ f(x:=z) |
|
472 |
\rulename{fun_upd_upd}
|
|
473 |
\end{isabelle}
|
|
474 |
Note also that we can write \isa{f(x:=z)} with only one pair of parentheses
|
|
475 |
when it is not being applied to an argument. |
|
476 |
||
477 |
\medskip |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
478 |
The \bfindex{identity function} and function
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
479 |
\textbf{composition}\indexbold{composition!of functions} are
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
480 |
defined: |
| 10303 | 481 |
\begin{isabelle}%
|
482 |
id\ \isasymequiv\ {\isasymlambda}x.\ x%
|
|
483 |
\rulename{id_def}\isanewline
|
|
484 |
f\ \isasymcirc\ g\ \isasymequiv\ |
|
485 |
{\isasymlambda}x.\ f\
|
|
486 |
(g\ x)% |
|
487 |
\rulename{o_def}
|
|
488 |
\end{isabelle}
|
|
489 |
% |
|
490 |
Many familiar theorems concerning the identity and composition |
|
491 |
are proved. For example, we have the associativity of composition: |
|
492 |
\begin{isabelle}
|
|
493 |
f\ \isasymcirc\ (g\ \isasymcirc\ h)\ =\ f\ \isasymcirc\ g\ \isasymcirc\ h |
|
494 |
\rulename{o_assoc}
|
|
495 |
\end{isabelle}
|
|
496 |
||
| 10857 | 497 |
\subsection{Injections, Surjections, Bijections}
|
| 10303 | 498 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
499 |
\index{injections}\index{surjections}\index{bijections}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
500 |
A function may be \textbf{injective}, \textbf{surjective} or \textbf{bijective}:
|
| 10303 | 501 |
\begin{isabelle}
|
502 |
inj_on\ f\ A\ \isasymequiv\ {\isasymforall}x\isasymin A.\
|
|
503 |
{\isasymforall}y\isasymin A.\ f\ x\ =\ f\ y\ \isasymlongrightarrow\ x\
|
|
504 |
=\ y% |
|
505 |
\rulename{inj_on_def}\isanewline
|
|
506 |
surj\ f\ \isasymequiv\ {\isasymforall}y.\
|
|
| 10857 | 507 |
\isasymexists x.\ y\ =\ f\ x% |
| 10303 | 508 |
\rulename{surj_def}\isanewline
|
509 |
bij\ f\ \isasymequiv\ inj\ f\ \isasymand\ surj\ f |
|
510 |
\rulename{bij_def}
|
|
511 |
\end{isabelle}
|
|
512 |
The second argument |
|
513 |
of \isa{inj_on} lets us express that a function is injective over a
|
|
514 |
given set. This refinement is useful in higher-order logic, where |
|
515 |
functions are total; in some cases, a function's natural domain is a subset |
|
516 |
of its domain type. Writing \isa{inj\ f} abbreviates \isa{inj_on\ f\
|
|
517 |
UNIV}, for when \isa{f} is injective everywhere.
|
|
518 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
519 |
The operator \isa{inv} expresses the
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
520 |
\textbf{inverse}\indexbold{inverse!of a function}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
521 |
of a function. In |
| 10303 | 522 |
general the inverse may not be well behaved. We have the usual laws, |
523 |
such as these: |
|
524 |
\begin{isabelle}
|
|
525 |
inj\ f\ \ \isasymLongrightarrow\ inv\ f\ (f\ x)\ =\ x% |
|
526 |
\rulename{inv_f_f}\isanewline
|
|
527 |
surj\ f\ \isasymLongrightarrow\ f\ (inv\ f\ y)\ =\ y |
|
528 |
\rulename{surj_f_inv_f}\isanewline
|
|
529 |
bij\ f\ \ \isasymLongrightarrow\ inv\ (inv\ f)\ =\ f |
|
530 |
\rulename{inv_inv_eq}
|
|
531 |
\end{isabelle}
|
|
532 |
% |
|
533 |
%Other useful facts are that the inverse of an injection |
|
534 |
%is a surjection and vice versa; the inverse of a bijection is |
|
535 |
%a bijection. |
|
536 |
%\begin{isabelle}
|
|
537 |
%inj\ f\ \isasymLongrightarrow\ surj\ |
|
538 |
%(inv\ f) |
|
539 |
%\rulename{inj_imp_surj_inv}\isanewline
|
|
540 |
%surj\ f\ \isasymLongrightarrow\ inj\ (inv\ f) |
|
541 |
%\rulename{surj_imp_inj_inv}\isanewline
|
|
542 |
%bij\ f\ \isasymLongrightarrow\ bij\ (inv\ f) |
|
543 |
%\rulename{bij_imp_bij_inv}
|
|
544 |
%\end{isabelle}
|
|
545 |
% |
|
546 |
%The converses of these results fail. Unless a function is |
|
547 |
%well behaved, little can be said about its inverse. Here is another |
|
548 |
%law: |
|
549 |
%\begin{isabelle}
|
|
550 |
%{\isasymlbrakk}bij\ f;\ bij\ g\isasymrbrakk\ \isasymLongrightarrow\ inv\ (f\ \isasymcirc\ g)\ =\ inv\ g\ \isasymcirc\ inv\ f%
|
|
551 |
%\rulename{o_inv_distrib}
|
|
552 |
%\end{isabelle}
|
|
553 |
||
554 |
Theorems involving these concepts can be hard to prove. The following |
|
555 |
example is easy, but it cannot be proved automatically. To begin |
|
| 10983 | 556 |
with, we need a law that relates the equality of functions to |
| 10303 | 557 |
equality over all arguments: |
558 |
\begin{isabelle}
|
|
559 |
(f\ =\ g)\ =\ ({\isasymforall}x.\ f\ x\ =\ g\ x)
|
|
560 |
\rulename{expand_fun_eq}
|
|
561 |
\end{isabelle}
|
|
| 10857 | 562 |
% |
| 10303 | 563 |
This is just a restatement of extensionality. Our lemma states |
564 |
that an injection can be cancelled from the left |
|
565 |
side of function composition: |
|
566 |
\begin{isabelle}
|
|
567 |
\isacommand{lemma}\ "inj\ f\ \isasymLongrightarrow\ (f\ o\ g\ =\ f\ o\ h)\ =\ (g\ =\ h)"\isanewline
|
|
| 10983 | 568 |
\isacommand{apply}\ (simp\ add:\ expand_fun_eq\ inj_on_def)\isanewline
|
| 10857 | 569 |
\isacommand{apply}\ auto\isanewline
|
| 10303 | 570 |
\isacommand{done}
|
571 |
\end{isabelle}
|
|
572 |
||
573 |
The first step of the proof invokes extensionality and the definitions |
|
574 |
of injectiveness and composition. It leaves one subgoal: |
|
575 |
\begin{isabelle}
|
|
| 10857 | 576 |
\ 1.\ {\isasymforall}x\ y.\ f\ x\ =\ f\ y\ \isasymlongrightarrow\ x\ =\ y\
|
577 |
\isasymLongrightarrow\isanewline |
|
| 10303 | 578 |
\ \ \ \ ({\isasymforall}x.\ f\ (g\ x)\ =\ f\ (h\ x))\ =\ ({\isasymforall}x.\ g\ x\ =\ h\ x)
|
579 |
\end{isabelle}
|
|
| 10857 | 580 |
This can be proved using the \isa{auto} method.
|
581 |
||
| 10303 | 582 |
|
| 10857 | 583 |
\subsection{Function Image}
|
| 10303 | 584 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
585 |
The \textbf{image}\indexbold{image!under a function}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
586 |
of a set under a function is a most useful notion. It |
| 10303 | 587 |
has the obvious definition: |
588 |
\begin{isabelle}
|
|
| 10857 | 589 |
f\ `\ A\ \isasymequiv\ \isacharbraceleft y.\ \isasymexists x\isasymin |
| 10303 | 590 |
A.\ y\ =\ f\ x\isacharbraceright |
591 |
\rulename{image_def}
|
|
592 |
\end{isabelle}
|
|
593 |
% |
|
594 |
Here are some of the many facts proved about image: |
|
595 |
\begin{isabelle}
|
|
| 10857 | 596 |
(f\ \isasymcirc\ g)\ `\ r\ =\ f\ `\ g\ `\ r |
| 10303 | 597 |
\rulename{image_compose}\isanewline
|
| 10857 | 598 |
f`(A\ \isasymunion\ B)\ =\ f`A\ \isasymunion\ f`B |
| 10303 | 599 |
\rulename{image_Un}\isanewline
|
| 10857 | 600 |
inj\ f\ \isasymLongrightarrow\ f`(A\ \isasyminter\ |
601 |
B)\ =\ f`A\ \isasyminter\ f`B |
|
| 10303 | 602 |
\rulename{image_Int}
|
603 |
%\isanewline |
|
| 10857 | 604 |
%bij\ f\ \isasymLongrightarrow\ f\ `\ (-\ A)\ =\ -\ f\ `\ A% |
| 10303 | 605 |
%\rulename{bij_image_Compl_eq}
|
606 |
\end{isabelle}
|
|
607 |
||
608 |
||
609 |
Laws involving image can often be proved automatically. Here |
|
610 |
are two examples, illustrating connections with indexed union and with the |
|
611 |
general syntax for comprehension: |
|
612 |
\begin{isabelle}
|
|
| 10857 | 613 |
\isacommand{lemma}\ "f`A\ \isasymunion\ g`A\ =\ ({\isasymUnion}x{\isasymin}A.\ \isacharbraceleft f\ x,\ g\
|
| 10303 | 614 |
x\isacharbraceright) |
615 |
\par\smallskip |
|
| 10857 | 616 |
\isacommand{lemma}\ "f\ `\ \isacharbraceleft(x,y){.}\ P\ x\ y\isacharbraceright\ =\ \isacharbraceleft f(x,y)\ \isacharbar\ x\ y.\ P\ x\
|
| 10303 | 617 |
y\isacharbraceright" |
618 |
\end{isabelle}
|
|
619 |
||
620 |
\medskip |
|
621 |
A function's \textbf{range} is the set of values that the function can
|
|
622 |
take on. It is, in fact, the image of the universal set under |
|
623 |
that function. There is no constant {\isa{range}}. Instead, {\isa{range}}
|
|
624 |
abbreviates an application of image to {\isa{UNIV}}:
|
|
625 |
\begin{isabelle}
|
|
626 |
\ \ \ \ \ range\ f\ |
|
| 10983 | 627 |
{\isasymrightleftharpoons}\ f`UNIV
|
| 10303 | 628 |
\end{isabelle}
|
629 |
% |
|
630 |
Few theorems are proved specifically |
|
631 |
for {\isa{range}}; in most cases, you should look for a more general
|
|
632 |
theorem concerning images. |
|
633 |
||
634 |
\medskip |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
635 |
\textbf{Inverse image}\index{inverse image!of a function} is also useful.
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
636 |
It is defined as follows: |
| 10303 | 637 |
\begin{isabelle}
|
| 10857 | 638 |
f\ -`\ B\ \isasymequiv\ \isacharbraceleft x.\ f\ x\ \isasymin\ B\isacharbraceright |
| 10303 | 639 |
\rulename{vimage_def}
|
640 |
\end{isabelle}
|
|
641 |
% |
|
642 |
This is one of the facts proved about it: |
|
643 |
\begin{isabelle}
|
|
| 10857 | 644 |
f\ -`\ (-\ A)\ =\ -\ f\ -`\ A% |
| 10303 | 645 |
\rulename{vimage_Compl}
|
646 |
\end{isabelle}
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
647 |
\index{functions|)}
|
| 10303 | 648 |
|
649 |
||
650 |
\section{Relations}
|
|
| 10513 | 651 |
\label{sec:Relations}
|
| 10303 | 652 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
653 |
\index{relations|(}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
654 |
A \textbf{relation} is a set of pairs. As such, the set operations apply
|
| 10303 | 655 |
to them. For instance, we may form the union of two relations. Other |
656 |
primitives are defined specifically for relations. |
|
657 |
||
| 10857 | 658 |
\subsection{Relation Basics}
|
659 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
660 |
The \bfindex{identity relation}, also known as equality, has the obvious
|
| 10303 | 661 |
definition: |
662 |
\begin{isabelle}
|
|
| 10857 | 663 |
Id\ \isasymequiv\ \isacharbraceleft p.\ \isasymexists x.\ p\ =\ (x,x){\isacharbraceright}%
|
| 10303 | 664 |
\rulename{Id_def}
|
665 |
\end{isabelle}
|
|
666 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
667 |
\indexbold{composition!of relations}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
668 |
\textbf{Composition} of relations (the infix \isa{O}) is also available:
|
| 10303 | 669 |
\begin{isabelle}
|
| 10857 | 670 |
r\ O\ s\ \isasymequiv\ \isacharbraceleft(x,z).\ \isasymexists y.\ (x,y)\ \isasymin\ s\ \isasymand\ (y,z)\ \isasymin\ r\isacharbraceright |
| 10303 | 671 |
\rulename{comp_def}
|
672 |
\end{isabelle}
|
|
| 10857 | 673 |
% |
| 10303 | 674 |
This is one of the many lemmas proved about these concepts: |
675 |
\begin{isabelle}
|
|
676 |
R\ O\ Id\ =\ R |
|
677 |
\rulename{R_O_Id}
|
|
678 |
\end{isabelle}
|
|
679 |
% |
|
680 |
Composition is monotonic, as are most of the primitives appearing |
|
681 |
in this chapter. We have many theorems similar to the following |
|
682 |
one: |
|
683 |
\begin{isabelle}
|
|
684 |
\isasymlbrakk r\isacharprime\ \isasymsubseteq\ r;\ s\isacharprime\ |
|
685 |
\isasymsubseteq\ s\isasymrbrakk\ \isasymLongrightarrow\ r\isacharprime\ O\ |
|
686 |
s\isacharprime\ \isasymsubseteq\ r\ O\ s% |
|
687 |
\rulename{comp_mono}
|
|
688 |
\end{isabelle}
|
|
689 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
690 |
\indexbold{converse!of a relation}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
691 |
\indexbold{inverse!of a relation}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
692 |
The \textbf{converse} or inverse of a
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
693 |
relation exchanges the roles of the two operands. We use the postfix |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
694 |
notation~\isa{r\isasyminverse} or
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
695 |
\isa{r\isacharcircum-1} in ASCII\@.
|
| 10303 | 696 |
\begin{isabelle}
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
697 |
((a,b)\ \isasymin\ r\isasyminverse)\ =\ |
| 10303 | 698 |
((b,a)\ \isasymin\ r) |
699 |
\rulename{converse_iff}
|
|
700 |
\end{isabelle}
|
|
701 |
% |
|
702 |
Here is a typical law proved about converse and composition: |
|
703 |
\begin{isabelle}
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
704 |
(r\ O\ s)\isasyminverse\ =\ s\isasyminverse\ O\ r\isasyminverse |
| 10303 | 705 |
\rulename{converse_comp}
|
706 |
\end{isabelle}
|
|
707 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
708 |
\indexbold{image!under a relation}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
709 |
The \textbf{image} of a set under a relation is defined
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
710 |
analogously to image under a function: |
| 10303 | 711 |
\begin{isabelle}
|
| 10857 | 712 |
(b\ \isasymin\ r\ ``\ A)\ =\ (\isasymexists x\isasymin |
| 10303 | 713 |
A.\ (x,b)\ \isasymin\ r) |
714 |
\rulename{Image_iff}
|
|
715 |
\end{isabelle}
|
|
716 |
It satisfies many similar laws. |
|
717 |
||
718 |
%Image under relations, like image under functions, distributes over unions: |
|
719 |
%\begin{isabelle}
|
|
| 10857 | 720 |
%r\ ``\ |
| 10303 | 721 |
%({\isasymUnion}x\isasyminA.\
|
722 |
%B\ |
|
723 |
%x)\ =\ |
|
724 |
%({\isasymUnion}x\isasyminA.\
|
|
| 10857 | 725 |
%r\ ``\ B\ |
| 10303 | 726 |
%x) |
727 |
%\rulename{Image_UN}
|
|
728 |
%\end{isabelle}
|
|
729 |
||
730 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
731 |
The \bfindex{domain} and \bfindex{range} of a relation are defined in the
|
| 10303 | 732 |
standard way: |
733 |
\begin{isabelle}
|
|
| 10857 | 734 |
(a\ \isasymin\ Domain\ r)\ =\ (\isasymexists y.\ (a,y)\ \isasymin\ |
| 10303 | 735 |
r) |
736 |
\rulename{Domain_iff}%
|
|
737 |
\isanewline |
|
738 |
(a\ \isasymin\ Range\ r)\ |
|
| 10857 | 739 |
\ =\ (\isasymexists y.\ |
| 10303 | 740 |
(y,a)\ |
741 |
\isasymin\ r) |
|
742 |
\rulename{Range_iff}
|
|
743 |
\end{isabelle}
|
|
744 |
||
745 |
Iterated composition of a relation is available. The notation overloads |
|
746 |
that of exponentiation: |
|
747 |
\begin{isabelle}
|
|
748 |
R\ \isacharcircum\ \isadigit{0}\ =\ Id\isanewline
|
|
749 |
R\ \isacharcircum\ Suc\ n\ =\ R\ O\ R\isacharcircum n |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
750 |
\rulename{relpow.simps}
|
| 10303 | 751 |
\end{isabelle}
|
752 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
753 |
\subsection{The Reflexive and Transitive Closure}
|
| 10857 | 754 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
755 |
\index{closure!reflexive and transitive|(}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
756 |
The \textbf{reflexive and transitive closure} of the
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
757 |
relation~\isa{r} is written with a
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
758 |
postfix syntax. In ASCII we write \isa{r\isacharcircum*} and in
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
759 |
X-symbol notation~\isa{r\isactrlsup *}. It is the least solution of the
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
760 |
equation |
| 10303 | 761 |
\begin{isabelle}
|
| 10857 | 762 |
r\isactrlsup *\ =\ Id\ \isasymunion \ (r\ O\ r\isactrlsup *) |
| 10303 | 763 |
\rulename{rtrancl_unfold}
|
764 |
\end{isabelle}
|
|
765 |
% |
|
766 |
Among its basic properties are three that serve as introduction |
|
767 |
rules: |
|
768 |
\begin{isabelle}
|
|
| 10857 | 769 |
(a,\ a)\ \isasymin \ r\isactrlsup * |
770 |
\rulename{rtrancl_refl}\isanewline
|
|
771 |
p\ \isasymin \ r\ \isasymLongrightarrow \ p\ \isasymin \ r\isactrlsup * |
|
772 |
\rulename{r_into_rtrancl}\isanewline
|
|
773 |
\isasymlbrakk (a,b)\ \isasymin \ r\isactrlsup *;\ |
|
774 |
(b,c)\ \isasymin \ r\isactrlsup *\isasymrbrakk \ \isasymLongrightarrow \ |
|
775 |
(a,c)\ \isasymin \ r\isactrlsup * |
|
| 10303 | 776 |
\rulename{rtrancl_trans}
|
777 |
\end{isabelle}
|
|
778 |
% |
|
779 |
Induction over the reflexive transitive closure is available: |
|
780 |
\begin{isabelle}
|
|
| 10857 | 781 |
\isasymlbrakk (a,\ b)\ \isasymin \ r\isactrlsup *;\ P\ a;\ \isasymAnd y\ z.\ \isasymlbrakk (a,\ y)\ \isasymin \ r\isactrlsup *;\ (y,\ z)\ \isasymin \ r;\ P\ y\isasymrbrakk \ \isasymLongrightarrow \ P\ z\isasymrbrakk \isanewline |
782 |
\isasymLongrightarrow \ P\ b% |
|
| 10303 | 783 |
\rulename{rtrancl_induct}
|
784 |
\end{isabelle}
|
|
785 |
% |
|
| 10857 | 786 |
Idempotence is one of the laws proved about the reflexive transitive |
| 10303 | 787 |
closure: |
788 |
\begin{isabelle}
|
|
| 10857 | 789 |
(r\isactrlsup *)\isactrlsup *\ =\ r\isactrlsup * |
| 10303 | 790 |
\rulename{rtrancl_idemp}
|
791 |
\end{isabelle}
|
|
792 |
||
| 10857 | 793 |
\smallskip |
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
794 |
The transitive closure is similar. The ASCII syntax is |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
795 |
\isa{r\isacharcircum+}. It has two introduction rules:
|
| 10303 | 796 |
\begin{isabelle}
|
| 10857 | 797 |
p\ \isasymin \ r\ \isasymLongrightarrow \ p\ \isasymin \ r\isactrlsup + |
| 10303 | 798 |
\rulename{r_into_trancl}\isanewline
|
| 10857 | 799 |
\isasymlbrakk (a,\ b)\ \isasymin \ r\isactrlsup +;\ (b,\ c)\ \isasymin \ r\isactrlsup +\isasymrbrakk \ \isasymLongrightarrow \ (a,\ c)\ \isasymin \ r\isactrlsup + |
| 10303 | 800 |
\rulename{trancl_trans}
|
801 |
\end{isabelle}
|
|
802 |
% |
|
| 10857 | 803 |
The induction rule resembles the one shown above. |
| 10303 | 804 |
A typical lemma states that transitive closure commutes with the converse |
805 |
operator: |
|
806 |
\begin{isabelle}
|
|
| 10857 | 807 |
(r\isasyminverse )\isactrlsup +\ =\ (r\isactrlsup +)\isasyminverse |
| 10303 | 808 |
\rulename{trancl_converse}
|
809 |
\end{isabelle}
|
|
810 |
||
| 10857 | 811 |
\subsection{A Sample Proof}
|
| 10303 | 812 |
|
813 |
The reflexive transitive closure also commutes with the converse. |
|
814 |
Let us examine the proof. Each direction of the equivalence is |
|
815 |
proved separately. The two proofs are almost identical. Here |
|
816 |
is the first one: |
|
817 |
\begin{isabelle}
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
818 |
\isacommand{lemma}\ rtrancl_converseD:\ "(x,y)\ \isasymin \
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
819 |
(r\isasyminverse)\isactrlsup *\ \isasymLongrightarrow \ (y,x)\ \isasymin |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
820 |
\ r\isactrlsup *"\isanewline |
| 10857 | 821 |
\isacommand{apply}\ (erule\ rtrancl_induct)\isanewline
|
| 10303 | 822 |
\ \isacommand{apply}\ (rule\ rtrancl_refl)\isanewline
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
823 |
\isacommand{apply}\ (blast\ intro:\ rtrancl_trans)\isanewline
|
| 10303 | 824 |
\isacommand{done}
|
825 |
\end{isabelle}
|
|
| 10857 | 826 |
% |
| 10303 | 827 |
The first step of the proof applies induction, leaving these subgoals: |
828 |
\begin{isabelle}
|
|
| 10857 | 829 |
\ 1.\ (x,\ x)\ \isasymin \ r\isactrlsup *\isanewline |
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
830 |
\ 2.\ \isasymAnd y\ z.\ \isasymlbrakk (x,y)\ \isasymin \ |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
831 |
(r\isasyminverse)\isactrlsup *;\ (y,z)\ \isasymin \ r\isasyminverse ;\ |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
832 |
(y,x)\ \isasymin \ r\isactrlsup *\isasymrbrakk \isanewline |
| 10857 | 833 |
\ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ (z,x)\ \isasymin \ r\isactrlsup * |
| 10303 | 834 |
\end{isabelle}
|
| 10857 | 835 |
% |
| 10303 | 836 |
The first subgoal is trivial by reflexivity. The second follows |
837 |
by first eliminating the converse operator, yielding the |
|
838 |
assumption \isa{(z,y)\
|
|
839 |
\isasymin\ r}, and then |
|
840 |
applying the introduction rules shown above. The same proof script handles |
|
841 |
the other direction: |
|
842 |
\begin{isabelle}
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
843 |
\isacommand{lemma}\ rtrancl_converseI:\ "(y,x)\ \isasymin \ r\isactrlsup *\ \isasymLongrightarrow \ (x,y)\ \isasymin \ (r\isasyminverse)\isactrlsup *"\isanewline
|
| 10303 | 844 |
\isacommand{apply}\ (erule\ rtrancl_induct)\isanewline
|
845 |
\ \isacommand{apply}\ (rule\ rtrancl_refl)\isanewline
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
846 |
\isacommand{apply}\ (blast\ intro:\ rtrancl_trans)\isanewline
|
| 10303 | 847 |
\isacommand{done}
|
848 |
\end{isabelle}
|
|
849 |
||
850 |
||
851 |
Finally, we combine the two lemmas to prove the desired equation: |
|
852 |
\begin{isabelle}
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
853 |
\isacommand{lemma}\ rtrancl_converse:\ "(r\isasyminverse)\isactrlsup *\ =\ (r\isactrlsup *)\isasyminverse"\isanewline
|
| 10857 | 854 |
\isacommand{by}\ (auto\ intro:\ rtrancl_converseI\ dest:\
|
855 |
rtrancl_converseD) |
|
| 10303 | 856 |
\end{isabelle}
|
857 |
||
| 10857 | 858 |
\begin{warn}
|
859 |
Note that \isa{blast} cannot prove this theorem. Here is a subgoal that
|
|
860 |
arises internally after the rules \isa{equalityI} and \isa{subsetI} have
|
|
861 |
been applied: |
|
| 10303 | 862 |
\begin{isabelle}
|
| 10857 | 863 |
\ 1.\ \isasymAnd x.\ x\ \isasymin \ (r\isasyminverse )\isactrlsup *\ \isasymLongrightarrow \ x\ \isasymin \ (r\isactrlsup |
864 |
*)\isasyminverse |
|
865 |
%ignore subgoal 2 |
|
866 |
%\ 2.\ \isasymAnd x.\ x\ \isasymin \ (r\isactrlsup *)\isasyminverse \ |
|
867 |
%\isasymLongrightarrow \ x\ \isasymin \ (r\isasyminverse )\isactrlsup * |
|
| 10303 | 868 |
\end{isabelle}
|
| 10857 | 869 |
\par\noindent |
870 |
We cannot use \isa{rtrancl_converseD}\@. It refers to
|
|
871 |
ordered pairs, while \isa{x} is a variable of product type.
|
|
872 |
The \isa{simp} and \isa{blast} methods can do nothing, so let us try
|
|
873 |
\isa{clarify}:
|
|
| 10303 | 874 |
\begin{isabelle}
|
| 10857 | 875 |
\ 1.\ \isasymAnd a\ b.\ (a,b)\ \isasymin \ (r\isasyminverse )\isactrlsup *\ \isasymLongrightarrow \ (b,a)\ \isasymin \ r\isactrlsup |
876 |
* |
|
| 10303 | 877 |
\end{isabelle}
|
| 10857 | 878 |
Now that \isa{x} has been replaced by the pair \isa{(a,b)}, we can
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
879 |
proceed. Other methods that split variables in this way are \isa{force},
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
880 |
\isa{auto}, \isa{fast} and \isa{best}. Section~\ref{sec:products} will discuss proof
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
881 |
techniques for ordered pairs in more detail. |
| 10857 | 882 |
\end{warn}
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
883 |
\index{relations|)}\index{closure!reflexive and transitive|)}
|
| 10303 | 884 |
|
| 10857 | 885 |
|
886 |
\section{Well-Founded Relations and Induction}
|
|
| 10513 | 887 |
\label{sec:Well-founded}
|
| 10303 | 888 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
889 |
\index{relations!well-founded|(}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
890 |
A well-founded relation captures the notion of a terminating process. |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
891 |
Each \isacommand{recdef}\index{recdef@\isacommand{recdef}}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
892 |
declaration must specify a well-founded relation that |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
893 |
justifies the termination of the desired recursive function. Most of the |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
894 |
forms of induction found in mathematics are merely special cases of |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
895 |
induction over a well-founded relation. |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
896 |
|
| 10303 | 897 |
Intuitively, the relation~$\prec$ is \textbf{well-founded} if it admits no
|
898 |
infinite descending chains |
|
899 |
\[ \cdots \prec a@2 \prec a@1 \prec a@0. \] |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
900 |
Well-foundedness can be hard to show. The various |
| 10857 | 901 |
formulations are all complicated. However, often a relation |
902 |
is well-founded by construction. HOL provides |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
903 |
theorems concerning ways of constructing a well-founded relation. The |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
904 |
most familiar way is to specify a \bfindex{measure function}~\isa{f} into
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
905 |
the natural numbers, when $\isa{x}\prec \isa{y}\iff \isa{f x} < \isa{f y}$;
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
906 |
we write this particular relation as |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
907 |
\isa{measure~f}.
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
908 |
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
909 |
\begin{warn}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
910 |
You may want to skip the rest of this section until you need to perform a |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
911 |
complex recursive function definition or induction. The induction rule |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
912 |
returned by |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
913 |
\isacommand{recdef} is good enough for most purposes. We use an explicit
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
914 |
well-founded induction only in \S\ref{sec:CTL-revisited}.
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
915 |
\end{warn}
|
| 10303 | 916 |
|
| 10857 | 917 |
Isabelle/HOL declares \isa{less_than} as a relation object,
|
| 10303 | 918 |
that is, a set of pairs of natural numbers. Two theorems tell us that this |
919 |
relation behaves as expected and that it is well-founded: |
|
920 |
\begin{isabelle}
|
|
921 |
((x,y)\ \isasymin\ less_than)\ =\ (x\ <\ y) |
|
922 |
\rulename{less_than_iff}\isanewline
|
|
923 |
wf\ less_than |
|
924 |
\rulename{wf_less_than}
|
|
925 |
\end{isabelle}
|
|
926 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
927 |
The notion of measure generalizes to the |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
928 |
\index{inverse image!of a relation}\textbf{inverse image} of
|
| 10857 | 929 |
a relation. Given a relation~\isa{r} and a function~\isa{f}, we express a
|
930 |
new relation using \isa{f} as a measure. An infinite descending chain on
|
|
931 |
this new relation would give rise to an infinite descending chain |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
932 |
on~\isa{r}. Isabelle/HOL defines this concept and proves a
|
| 10857 | 933 |
theorem stating that it preserves well-foundedness: |
| 10303 | 934 |
\begin{isabelle}
|
935 |
inv_image\ r\ f\ \isasymequiv\ \isacharbraceleft(x,y).\ (f\ x,\ f\ y)\ |
|
936 |
\isasymin\ r\isacharbraceright |
|
937 |
\rulename{inv_image_def}\isanewline
|
|
938 |
wf\ r\ \isasymLongrightarrow\ wf\ (inv_image\ r\ f) |
|
939 |
\rulename{wf_inv_image}
|
|
940 |
\end{isabelle}
|
|
941 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
942 |
A measure function involves the natural numbers. The relation \isa{measure
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
943 |
size} justifies primitive recursion and structural induction over a |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
944 |
datatype. Isabelle/HOL defines |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
945 |
\isa{measure} as shown:
|
| 10303 | 946 |
\begin{isabelle}
|
947 |
measure\ \isasymequiv\ inv_image\ less_than% |
|
948 |
\rulename{measure_def}\isanewline
|
|
949 |
wf\ (measure\ f) |
|
950 |
\rulename{wf_measure}
|
|
951 |
\end{isabelle}
|
|
952 |
||
953 |
Of the other constructions, the most important is the \textbf{lexicographic
|
|
954 |
product} of two relations. It expresses the standard dictionary |
|
955 |
ordering over pairs. We write \isa{ra\ <*lex*>\ rb}, where \isa{ra}
|
|
956 |
and \isa{rb} are the two operands. The lexicographic product satisfies the
|
|
957 |
usual definition and it preserves well-foundedness: |
|
958 |
\begin{isabelle}
|
|
959 |
ra\ <*lex*>\ rb\ \isasymequiv \isanewline |
|
960 |
\ \ \isacharbraceleft ((a,b),(a',b')).\ (a,a')\ \isasymin \ ra\ |
|
961 |
\isasymor\isanewline |
|
962 |
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \,a=a'\ \isasymand \ (b,b')\ |
|
963 |
\isasymin \ rb\isacharbraceright |
|
964 |
\rulename{lex_prod_def}%
|
|
965 |
\par\smallskip |
|
966 |
\isasymlbrakk wf\ ra;\ wf\ rb\isasymrbrakk \ \isasymLongrightarrow \ wf\ (ra\ <*lex*>\ rb) |
|
967 |
\rulename{wf_lex_prod}
|
|
968 |
\end{isabelle}
|
|
969 |
||
970 |
These constructions can be used in a |
|
971 |
\textbf{recdef} declaration (\S\ref{sec:recdef-simplification}) to define
|
|
972 |
the well-founded relation used to prove termination. |
|
973 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
974 |
The \bfindex{multiset ordering}, useful for hard termination proofs, is
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
975 |
available in the Library. Baader and Nipkow \cite[\S2.5]{Baader-Nipkow}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
976 |
discuss it. |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
977 |
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
978 |
\medskip |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
979 |
Induction comes in many forms, including traditional mathematical |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
980 |
induction, structural induction on lists and induction on size. All are |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
981 |
instances of the following rule, for a suitable well-founded |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
982 |
relation~$\prec$: |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
983 |
\[ \infer{P(a)}{\infer*{P(x)}{[\forall y.\, y\prec x \imp P(y)]}} \]
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
984 |
To show $P(a)$ for a particular term~$a$, it suffices to show $P(x)$ for |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
985 |
arbitrary~$x$ under the assumption that $P(y)$ holds for $y\prec x$. |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
986 |
Intuitively, the well-foundedness of $\prec$ ensures that the chains of |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
987 |
reasoning are finite. |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
988 |
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
989 |
\smallskip |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
990 |
In Isabelle, the induction rule is expressed like this: |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
991 |
\begin{isabelle}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
992 |
{\isasymlbrakk}wf\ r;\
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
993 |
{\isasymAnd}x.\ {\isasymforall}y.\ (y,x)\ \isasymin\ r\
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
994 |
\isasymlongrightarrow\ P\ y\ \isasymLongrightarrow\ P\ x\isasymrbrakk\ |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
995 |
\isasymLongrightarrow\ P\ a |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
996 |
\rulename{wf_induct}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
997 |
\end{isabelle}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
998 |
Here \isa{wf\ r} expresses that the relation~\isa{r} is well-founded.
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
999 |
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1000 |
Many familiar induction principles are instances of this rule. |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1001 |
For example, the predecessor relation on the natural numbers |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1002 |
is well-founded; induction over it is mathematical induction. |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1003 |
The ``tail of'' relation on lists is well-founded; induction over |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1004 |
it is structural induction. |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1005 |
\index{relations!well-founded|)}
|
| 10303 | 1006 |
|
1007 |
||
| 10857 | 1008 |
\section{Fixed Point Operators}
|
| 10303 | 1009 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1010 |
\index{fixed points|(}%
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1011 |
Fixed point operators define sets |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1012 |
recursively. They are invoked implicitly when making an inductive |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1013 |
definition, as discussed in Chap.\ts\ref{chap:inductive} below. However,
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1014 |
they can be used directly, too. The |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1015 |
\emph{least} or \emph{strongest} fixed point yields an inductive
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1016 |
definition; the \emph{greatest} or \emph{weakest} fixed point yields a
|
| 10857 | 1017 |
coinductive definition. Mathematicians may wish to note that the |
1018 |
existence of these fixed points is guaranteed by the Knaster-Tarski |
|
1019 |
theorem. |
|
| 10303 | 1020 |
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1021 |
\begin{warn}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1022 |
Casual readers should skip the rest of this section. We use fixed point |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1023 |
operators only in \S\ref{sec:VMC}.
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1024 |
\end{warn}
|
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1025 |
|
| 10983 | 1026 |
The theory applies only to monotonic functions. Isabelle's |
| 10303 | 1027 |
definition of monotone is overloaded over all orderings: |
1028 |
\begin{isabelle}
|
|
1029 |
mono\ f\ \isasymequiv\ {\isasymforall}A\ B.\ A\ \isasymle\ B\ \isasymlongrightarrow\ f\ A\ \isasymle\ f\ B%
|
|
1030 |
\rulename{mono_def}
|
|
1031 |
\end{isabelle}
|
|
1032 |
% |
|
1033 |
For fixed point operators, the ordering will be the subset relation: if |
|
1034 |
$A\subseteq B$ then we expect $f(A)\subseteq f(B)$. In addition to its |
|
1035 |
definition, monotonicity has the obvious introduction and destruction |
|
1036 |
rules: |
|
1037 |
\begin{isabelle}
|
|
1038 |
({\isasymAnd}A\ B.\ A\ \isasymle\ B\ \isasymLongrightarrow\ f\ A\ \isasymle\ f\ B)\ \isasymLongrightarrow\ mono\ f%
|
|
1039 |
\rulename{monoI}%
|
|
1040 |
\par\smallskip% \isanewline didn't leave enough space |
|
1041 |
{\isasymlbrakk}mono\ f;\ A\ \isasymle\ B\isasymrbrakk\
|
|
1042 |
\isasymLongrightarrow\ f\ A\ \isasymle\ f\ B% |
|
1043 |
\rulename{monoD}
|
|
1044 |
\end{isabelle}
|
|
1045 |
||
1046 |
The most important properties of the least fixed point are that |
|
1047 |
it is a fixed point and that it enjoys an induction rule: |
|
1048 |
\begin{isabelle}
|
|
1049 |
mono\ f\ \isasymLongrightarrow\ lfp\ f\ =\ f\ (lfp\ f) |
|
1050 |
\rulename{lfp_unfold}%
|
|
1051 |
\par\smallskip% \isanewline didn't leave enough space |
|
1052 |
{\isasymlbrakk}a\ \isasymin\ lfp\ f;\ mono\ f;\isanewline
|
|
1053 |
\ {\isasymAnd}x.\ x\
|
|
| 10857 | 1054 |
\isasymin\ f\ (lfp\ f\ \isasyminter\ \isacharbraceleft x.\ P\ |
| 10303 | 1055 |
x\isacharbraceright)\ \isasymLongrightarrow\ P\ x\isasymrbrakk\ |
1056 |
\isasymLongrightarrow\ P\ a% |
|
1057 |
\rulename{lfp_induct}
|
|
1058 |
\end{isabelle}
|
|
1059 |
% |
|
1060 |
The induction rule shown above is more convenient than the basic |
|
1061 |
one derived from the minimality of {\isa{lfp}}. Observe that both theorems
|
|
1062 |
demand \isa{mono\ f} as a premise.
|
|
1063 |
||
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1064 |
The greatest fixed point is similar, but it has a \bfindex{coinduction} rule:
|
| 10303 | 1065 |
\begin{isabelle}
|
1066 |
mono\ f\ \isasymLongrightarrow\ gfp\ f\ =\ f\ (gfp\ f) |
|
1067 |
\rulename{gfp_unfold}%
|
|
1068 |
\isanewline |
|
1069 |
{\isasymlbrakk}mono\ f;\ a\ \isasymin\ X;\ X\ \isasymsubseteq\ f\ (X\
|
|
1070 |
\isasymunion\ gfp\ f)\isasymrbrakk\ \isasymLongrightarrow\ a\ \isasymin\ |
|
1071 |
gfp\ f% |
|
1072 |
\rulename{coinduct}
|
|
1073 |
\end{isabelle}
|
|
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10983
diff
changeset
|
1074 |
A \bfindex{bisimulation} is perhaps the best-known concept defined as a
|
| 10303 | 1075 |
greatest fixed point. Exhibiting a bisimulation to prove the equality of |
1076 |
two agents in a process algebra is an example of coinduction. |
|
1077 |
The coinduction rule can be strengthened in various ways; see |
|
| 10857 | 1078 |
theory \isa{Gfp} for details.
|
| 11203 | 1079 |
\index{fixed points|)}
|