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