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