author | wenzelm |
Thu, 21 Feb 2002 11:05:20 +0100 | |
changeset 12913 | 5ac498bffb6b |
parent 12905 | bbbae3f359e6 |
child 13343 | 3b2b18c58d80 |
permissions | -rw-r--r-- |
10358 | 1 |
(* Title: HOL/Relation.thy |
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
diff
changeset
|
2 |
ID: $Id$ |
1983 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
4 |
Copyright 1996 University of Cambridge |
|
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
diff
changeset
|
5 |
*) |
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
diff
changeset
|
6 |
|
12905 | 7 |
header {* Relations *} |
8 |
||
9 |
theory Relation = Product_Type: |
|
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset
|
10 |
|
12913 | 11 |
subsection {* Definitions *} |
12 |
||
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset
|
13 |
constdefs |
10358 | 14 |
converse :: "('a * 'b) set => ('b * 'a) set" ("(_^-1)" [1000] 999) |
15 |
"r^-1 == {(y, x). (x, y) : r}" |
|
16 |
syntax (xsymbols) |
|
12905 | 17 |
converse :: "('a * 'b) set => ('b * 'a) set" ("(_\<inverse>)" [1000] 999) |
7912 | 18 |
|
10358 | 19 |
constdefs |
12487 | 20 |
rel_comp :: "[('b * 'c) set, ('a * 'b) set] => ('a * 'c) set" (infixr "O" 60) |
12913 | 21 |
"r O s == {(x,z). EX y. (x, y) : s & (y, z) : r}" |
22 |
||
23 |
fun_rel_comp :: "['a => 'b, ('b * 'c) set] => ('a => 'c) set" |
|
24 |
"fun_rel_comp f R == {g. ALL x. (f x, g x) : R}" |
|
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset
|
25 |
|
11136 | 26 |
Image :: "[('a * 'b) set, 'a set] => 'b set" (infixl "``" 90) |
12913 | 27 |
"r `` s == {y. EX x:s. (x,y):r}" |
7912 | 28 |
|
12905 | 29 |
Id :: "('a * 'a) set" -- {* the identity relation *} |
12913 | 30 |
"Id == {p. EX x. p = (x,x)}" |
7912 | 31 |
|
12905 | 32 |
diag :: "'a set => ('a * 'a) set" -- {* diagonal: identity over a set *} |
12913 | 33 |
"diag A == UN x:A. {(x,x)}" |
34 |
||
11136 | 35 |
Domain :: "('a * 'b) set => 'a set" |
12913 | 36 |
"Domain r == {x. EX y. (x,y):r}" |
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset
|
37 |
|
11136 | 38 |
Range :: "('a * 'b) set => 'b set" |
12913 | 39 |
"Range r == Domain(r^-1)" |
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset
|
40 |
|
11136 | 41 |
Field :: "('a * 'a) set => 'a set" |
12913 | 42 |
"Field r == Domain r Un Range r" |
10786 | 43 |
|
12905 | 44 |
refl :: "['a set, ('a * 'a) set] => bool" -- {* reflexivity over a set *} |
12913 | 45 |
"refl A r == r \<subseteq> A \<times> A & (ALL x: A. (x,x) : r)" |
6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset
|
46 |
|
12905 | 47 |
sym :: "('a * 'a) set => bool" -- {* symmetry predicate *} |
12913 | 48 |
"sym r == ALL x y. (x,y): r --> (y,x): r" |
6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset
|
49 |
|
12905 | 50 |
antisym:: "('a * 'a) set => bool" -- {* antisymmetry predicate *} |
12913 | 51 |
"antisym r == ALL x y. (x,y):r --> (y,x):r --> x=y" |
6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset
|
52 |
|
12905 | 53 |
trans :: "('a * 'a) set => bool" -- {* transitivity predicate *} |
12913 | 54 |
"trans r == (ALL x y z. (x,y):r --> (y,z):r --> (x,z):r)" |
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset
|
55 |
|
11136 | 56 |
single_valued :: "('a * 'b) set => bool" |
12913 | 57 |
"single_valued r == ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z)" |
7014
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6806
diff
changeset
|
58 |
|
11136 | 59 |
inv_image :: "('b * 'b) set => ('a => 'b) => ('a * 'a) set" |
12913 | 60 |
"inv_image r f == {(x, y). (f x, f y) : r}" |
11136 | 61 |
|
6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset
|
62 |
syntax |
12905 | 63 |
reflexive :: "('a * 'a) set => bool" -- {* reflexivity over a type *} |
6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset
|
64 |
translations |
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset
|
65 |
"reflexive" == "refl UNIV" |
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset
|
66 |
|
12905 | 67 |
|
12913 | 68 |
subsection {* The identity relation *} |
12905 | 69 |
|
70 |
lemma IdI [intro]: "(a, a) : Id" |
|
71 |
by (simp add: Id_def) |
|
72 |
||
73 |
lemma IdE [elim!]: "p : Id ==> (!!x. p = (x, x) ==> P) ==> P" |
|
74 |
by (unfold Id_def) (rules elim: CollectE) |
|
75 |
||
76 |
lemma pair_in_Id_conv [iff]: "((a, b) : Id) = (a = b)" |
|
77 |
by (unfold Id_def) blast |
|
78 |
||
79 |
lemma reflexive_Id: "reflexive Id" |
|
80 |
by (simp add: refl_def) |
|
81 |
||
82 |
lemma antisym_Id: "antisym Id" |
|
83 |
-- {* A strange result, since @{text Id} is also symmetric. *} |
|
84 |
by (simp add: antisym_def) |
|
85 |
||
86 |
lemma trans_Id: "trans Id" |
|
87 |
by (simp add: trans_def) |
|
88 |
||
89 |
||
12913 | 90 |
subsection {* Diagonal: identity over a set *} |
12905 | 91 |
|
92 |
lemma diag_eqI: "a = b ==> a : A ==> (a, b) : diag A" |
|
93 |
by (simp add: diag_def) |
|
94 |
||
95 |
lemma diagI [intro!]: "a : A ==> (a, a) : diag A" |
|
96 |
by (rule diag_eqI) (rule refl) |
|
97 |
||
98 |
lemma diagE [elim!]: |
|
99 |
"c : diag A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P" |
|
12913 | 100 |
-- {* The general elimination rule. *} |
12905 | 101 |
by (unfold diag_def) (rules elim!: UN_E singletonE) |
102 |
||
103 |
lemma diag_iff: "((x, y) : diag A) = (x = y & x : A)" |
|
104 |
by blast |
|
105 |
||
12913 | 106 |
lemma diag_subset_Times: "diag A \<subseteq> A \<times> A" |
12905 | 107 |
by blast |
108 |
||
109 |
||
110 |
subsection {* Composition of two relations *} |
|
111 |
||
12913 | 112 |
lemma rel_compI [intro]: |
12905 | 113 |
"(a, b) : s ==> (b, c) : r ==> (a, c) : r O s" |
114 |
by (unfold rel_comp_def) blast |
|
115 |
||
12913 | 116 |
lemma rel_compE [elim!]: "xz : r O s ==> |
12905 | 117 |
(!!x y z. xz = (x, z) ==> (x, y) : s ==> (y, z) : r ==> P) ==> P" |
118 |
by (unfold rel_comp_def) (rules elim!: CollectE splitE exE conjE) |
|
119 |
||
120 |
lemma rel_compEpair: |
|
121 |
"(a, c) : r O s ==> (!!y. (a, y) : s ==> (y, c) : r ==> P) ==> P" |
|
122 |
by (rules elim: rel_compE Pair_inject ssubst) |
|
123 |
||
124 |
lemma R_O_Id [simp]: "R O Id = R" |
|
125 |
by fast |
|
126 |
||
127 |
lemma Id_O_R [simp]: "Id O R = R" |
|
128 |
by fast |
|
129 |
||
130 |
lemma O_assoc: "(R O S) O T = R O (S O T)" |
|
131 |
by blast |
|
132 |
||
12913 | 133 |
lemma trans_O_subset: "trans r ==> r O r \<subseteq> r" |
12905 | 134 |
by (unfold trans_def) blast |
135 |
||
12913 | 136 |
lemma rel_comp_mono: "r' \<subseteq> r ==> s' \<subseteq> s ==> (r' O s') \<subseteq> (r O s)" |
12905 | 137 |
by blast |
138 |
||
139 |
lemma rel_comp_subset_Sigma: |
|
12913 | 140 |
"s \<subseteq> A \<times> B ==> r \<subseteq> B \<times> C ==> (r O s) \<subseteq> A \<times> C" |
12905 | 141 |
by blast |
142 |
||
12913 | 143 |
|
144 |
subsection {* Composition of function and relation *} |
|
145 |
||
146 |
lemma fun_rel_comp_mono: "A \<subseteq> B ==> fun_rel_comp f A \<subseteq> fun_rel_comp f B" |
|
147 |
by (unfold fun_rel_comp_def) fast |
|
12905 | 148 |
|
12913 | 149 |
lemma fun_rel_comp_unique: |
150 |
"ALL x. EX! y. (f x, y) : R ==> EX! g. g : fun_rel_comp f R" |
|
151 |
apply (unfold fun_rel_comp_def) |
|
152 |
apply (rule_tac a = "%x. THE y. (f x, y) : R" in ex1I) |
|
153 |
apply (fast dest!: theI') |
|
154 |
apply (fast intro: ext the1_equality [symmetric]) |
|
155 |
done |
|
156 |
||
157 |
||
158 |
subsection {* Reflexivity *} |
|
159 |
||
160 |
lemma reflI: "r \<subseteq> A \<times> A ==> (!!x. x : A ==> (x, x) : r) ==> refl A r" |
|
12905 | 161 |
by (unfold refl_def) (rules intro!: ballI) |
162 |
||
163 |
lemma reflD: "refl A r ==> a : A ==> (a, a) : r" |
|
164 |
by (unfold refl_def) blast |
|
165 |
||
12913 | 166 |
|
167 |
subsection {* Antisymmetry *} |
|
12905 | 168 |
|
169 |
lemma antisymI: |
|
170 |
"(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r" |
|
171 |
by (unfold antisym_def) rules |
|
172 |
||
173 |
lemma antisymD: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b" |
|
174 |
by (unfold antisym_def) rules |
|
175 |
||
12913 | 176 |
|
177 |
subsection {* Transitivity *} |
|
12905 | 178 |
|
179 |
lemma transI: |
|
180 |
"(!!x y z. (x, y) : r ==> (y, z) : r ==> (x, z) : r) ==> trans r" |
|
181 |
by (unfold trans_def) rules |
|
182 |
||
183 |
lemma transD: "trans r ==> (a, b) : r ==> (b, c) : r ==> (a, c) : r" |
|
184 |
by (unfold trans_def) rules |
|
185 |
||
186 |
||
12913 | 187 |
subsection {* Converse *} |
188 |
||
189 |
lemma converse_iff [iff]: "((a,b): r^-1) = ((b,a) : r)" |
|
12905 | 190 |
by (simp add: converse_def) |
191 |
||
12913 | 192 |
lemma converseI: "(a, b) : r ==> (b, a) : r^-1" |
12905 | 193 |
by (simp add: converse_def) |
194 |
||
12913 | 195 |
lemma converseD: "(a,b) : r^-1 ==> (b, a) : r" |
12905 | 196 |
by (simp add: converse_def) |
197 |
||
198 |
lemma converseE [elim!]: |
|
199 |
"yx : r^-1 ==> (!!x y. yx = (y, x) ==> (x, y) : r ==> P) ==> P" |
|
12913 | 200 |
-- {* More general than @{text converseD}, as it ``splits'' the member of the relation. *} |
12905 | 201 |
by (unfold converse_def) (rules elim!: CollectE splitE bexE) |
202 |
||
203 |
lemma converse_converse [simp]: "(r^-1)^-1 = r" |
|
204 |
by (unfold converse_def) blast |
|
205 |
||
206 |
lemma converse_rel_comp: "(r O s)^-1 = s^-1 O r^-1" |
|
207 |
by blast |
|
208 |
||
209 |
lemma converse_Id [simp]: "Id^-1 = Id" |
|
210 |
by blast |
|
211 |
||
12913 | 212 |
lemma converse_diag [simp]: "(diag A)^-1 = diag A" |
12905 | 213 |
by blast |
214 |
||
215 |
lemma refl_converse: "refl A r ==> refl A (converse r)" |
|
216 |
by (unfold refl_def) blast |
|
217 |
||
218 |
lemma antisym_converse: "antisym (converse r) = antisym r" |
|
219 |
by (unfold antisym_def) blast |
|
220 |
||
221 |
lemma trans_converse: "trans (converse r) = trans r" |
|
222 |
by (unfold trans_def) blast |
|
223 |
||
12913 | 224 |
|
12905 | 225 |
subsection {* Domain *} |
226 |
||
227 |
lemma Domain_iff: "(a : Domain r) = (EX y. (a, y) : r)" |
|
228 |
by (unfold Domain_def) blast |
|
229 |
||
230 |
lemma DomainI [intro]: "(a, b) : r ==> a : Domain r" |
|
231 |
by (rules intro!: iffD2 [OF Domain_iff]) |
|
232 |
||
233 |
lemma DomainE [elim!]: |
|
234 |
"a : Domain r ==> (!!y. (a, y) : r ==> P) ==> P" |
|
235 |
by (rules dest!: iffD1 [OF Domain_iff]) |
|
236 |
||
237 |
lemma Domain_empty [simp]: "Domain {} = {}" |
|
238 |
by blast |
|
239 |
||
240 |
lemma Domain_insert: "Domain (insert (a, b) r) = insert a (Domain r)" |
|
241 |
by blast |
|
242 |
||
243 |
lemma Domain_Id [simp]: "Domain Id = UNIV" |
|
244 |
by blast |
|
245 |
||
246 |
lemma Domain_diag [simp]: "Domain (diag A) = A" |
|
247 |
by blast |
|
248 |
||
249 |
lemma Domain_Un_eq: "Domain(A Un B) = Domain(A) Un Domain(B)" |
|
250 |
by blast |
|
251 |
||
12913 | 252 |
lemma Domain_Int_subset: "Domain(A Int B) \<subseteq> Domain(A) Int Domain(B)" |
12905 | 253 |
by blast |
254 |
||
12913 | 255 |
lemma Domain_Diff_subset: "Domain(A) - Domain(B) \<subseteq> Domain(A - B)" |
12905 | 256 |
by blast |
257 |
||
258 |
lemma Domain_Union: "Domain (Union S) = (UN A:S. Domain A)" |
|
259 |
by blast |
|
260 |
||
12913 | 261 |
lemma Domain_mono: "r \<subseteq> s ==> Domain r \<subseteq> Domain s" |
12905 | 262 |
by blast |
263 |
||
264 |
||
265 |
subsection {* Range *} |
|
266 |
||
267 |
lemma Range_iff: "(a : Range r) = (EX y. (y, a) : r)" |
|
268 |
by (simp add: Domain_def Range_def) |
|
269 |
||
270 |
lemma RangeI [intro]: "(a, b) : r ==> b : Range r" |
|
271 |
by (unfold Range_def) (rules intro!: converseI DomainI) |
|
272 |
||
273 |
lemma RangeE [elim!]: "b : Range r ==> (!!x. (x, b) : r ==> P) ==> P" |
|
274 |
by (unfold Range_def) (rules elim!: DomainE dest!: converseD) |
|
275 |
||
276 |
lemma Range_empty [simp]: "Range {} = {}" |
|
277 |
by blast |
|
278 |
||
279 |
lemma Range_insert: "Range (insert (a, b) r) = insert b (Range r)" |
|
280 |
by blast |
|
281 |
||
282 |
lemma Range_Id [simp]: "Range Id = UNIV" |
|
283 |
by blast |
|
284 |
||
285 |
lemma Range_diag [simp]: "Range (diag A) = A" |
|
286 |
by auto |
|
287 |
||
288 |
lemma Range_Un_eq: "Range(A Un B) = Range(A) Un Range(B)" |
|
289 |
by blast |
|
290 |
||
12913 | 291 |
lemma Range_Int_subset: "Range(A Int B) \<subseteq> Range(A) Int Range(B)" |
12905 | 292 |
by blast |
293 |
||
12913 | 294 |
lemma Range_Diff_subset: "Range(A) - Range(B) \<subseteq> Range(A - B)" |
12905 | 295 |
by blast |
296 |
||
297 |
lemma Range_Union: "Range (Union S) = (UN A:S. Range A)" |
|
298 |
by blast |
|
299 |
||
300 |
||
301 |
subsection {* Image of a set under a relation *} |
|
302 |
||
303 |
ML {* overload_1st_set "Relation.Image" *} |
|
304 |
||
12913 | 305 |
lemma Image_iff: "(b : r``A) = (EX x:A. (x, b) : r)" |
12905 | 306 |
by (simp add: Image_def) |
307 |
||
12913 | 308 |
lemma Image_singleton: "r``{a} = {b. (a, b) : r}" |
12905 | 309 |
by (simp add: Image_def) |
310 |
||
12913 | 311 |
lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a, b) : r)" |
12905 | 312 |
by (rule Image_iff [THEN trans]) simp |
313 |
||
12913 | 314 |
lemma ImageI [intro]: "(a, b) : r ==> a : A ==> b : r``A" |
12905 | 315 |
by (unfold Image_def) blast |
316 |
||
317 |
lemma ImageE [elim!]: |
|
12913 | 318 |
"b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P" |
12905 | 319 |
by (unfold Image_def) (rules elim!: CollectE bexE) |
320 |
||
321 |
lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A" |
|
322 |
-- {* This version's more effective when we already have the required @{text a} *} |
|
323 |
by blast |
|
324 |
||
325 |
lemma Image_empty [simp]: "R``{} = {}" |
|
326 |
by blast |
|
327 |
||
328 |
lemma Image_Id [simp]: "Id `` A = A" |
|
329 |
by blast |
|
330 |
||
331 |
lemma Image_diag [simp]: "diag A `` B = A Int B" |
|
332 |
by blast |
|
333 |
||
12913 | 334 |
lemma Image_Int_subset: "R `` (A Int B) \<subseteq> R `` A Int R `` B" |
12905 | 335 |
by blast |
336 |
||
337 |
lemma Image_Un: "R `` (A Un B) = R `` A Un R `` B" |
|
338 |
by blast |
|
339 |
||
12913 | 340 |
lemma Image_subset: "r \<subseteq> A \<times> B ==> r``C \<subseteq> B" |
12905 | 341 |
by (rules intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2) |
342 |
||
343 |
lemma Image_eq_UN: "r``B = (UN y: B. r``{y})" |
|
344 |
-- {* NOT suitable for rewriting *} |
|
345 |
by blast |
|
346 |
||
12913 | 347 |
lemma Image_mono: "r' \<subseteq> r ==> A' \<subseteq> A ==> (r' `` A') \<subseteq> (r `` A)" |
12905 | 348 |
by blast |
349 |
||
350 |
lemma Image_UN: "(r `` (UNION A B)) = (UN x:A.(r `` (B x)))" |
|
351 |
by blast |
|
352 |
||
12913 | 353 |
lemma Image_INT_subset: "(r `` (INTER A B)) \<subseteq> (INT x:A.(r `` (B x)))" |
12905 | 354 |
-- {* Converse inclusion fails *} |
355 |
by blast |
|
356 |
||
12913 | 357 |
lemma Image_subset_eq: "(r``A \<subseteq> B) = (A \<subseteq> - ((r^-1) `` (-B)))" |
12905 | 358 |
by blast |
359 |
||
360 |
||
12913 | 361 |
subsection {* Single valued relations *} |
362 |
||
363 |
lemma single_valuedI: |
|
12905 | 364 |
"ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r" |
365 |
by (unfold single_valued_def) |
|
366 |
||
367 |
lemma single_valuedD: |
|
368 |
"single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z" |
|
369 |
by (simp add: single_valued_def) |
|
370 |
||
371 |
||
372 |
subsection {* Graphs given by @{text Collect} *} |
|
373 |
||
374 |
lemma Domain_Collect_split [simp]: "Domain{(x,y). P x y} = {x. EX y. P x y}" |
|
375 |
by auto |
|
376 |
||
377 |
lemma Range_Collect_split [simp]: "Range{(x,y). P x y} = {y. EX x. P x y}" |
|
378 |
by auto |
|
379 |
||
380 |
lemma Image_Collect_split [simp]: "{(x,y). P x y} `` A = {y. EX x:A. P x y}" |
|
381 |
by auto |
|
382 |
||
383 |
||
12913 | 384 |
subsection {* Inverse image *} |
12905 | 385 |
|
12913 | 386 |
lemma trans_inv_image: "trans r ==> trans (inv_image r f)" |
12905 | 387 |
apply (unfold trans_def inv_image_def) |
388 |
apply (simp (no_asm)) |
|
389 |
apply blast |
|
390 |
done |
|
391 |
||
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
diff
changeset
|
392 |
end |