13356
|
1 |
(* Title: ZF/Trancl.thy
|
1478
|
2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
0
|
3 |
Copyright 1992 University of Cambridge
|
|
4 |
*)
|
|
5 |
|
13356
|
6 |
header{*Relations: Their General Properties and Transitive Closure*}
|
|
7 |
|
16417
|
8 |
theory Trancl imports Fixedpt Perm begin
|
13239
|
9 |
|
24893
|
10 |
definition
|
|
11 |
refl :: "[i,i]=>o" where
|
13239
|
12 |
"refl(A,r) == (ALL x: A. <x,x> : r)"
|
|
13 |
|
24893
|
14 |
definition
|
|
15 |
irrefl :: "[i,i]=>o" where
|
13239
|
16 |
"irrefl(A,r) == ALL x: A. <x,x> ~: r"
|
|
17 |
|
24893
|
18 |
definition
|
|
19 |
sym :: "i=>o" where
|
13239
|
20 |
"sym(r) == ALL x y. <x,y>: r --> <y,x>: r"
|
|
21 |
|
24893
|
22 |
definition
|
|
23 |
asym :: "i=>o" where
|
13239
|
24 |
"asym(r) == ALL x y. <x,y>:r --> ~ <y,x>:r"
|
|
25 |
|
24893
|
26 |
definition
|
|
27 |
antisym :: "i=>o" where
|
13239
|
28 |
"antisym(r) == ALL x y.<x,y>:r --> <y,x>:r --> x=y"
|
|
29 |
|
24893
|
30 |
definition
|
|
31 |
trans :: "i=>o" where
|
13239
|
32 |
"trans(r) == ALL x y z. <x,y>: r --> <y,z>: r --> <x,z>: r"
|
|
33 |
|
24893
|
34 |
definition
|
|
35 |
trans_on :: "[i,i]=>o" ("trans[_]'(_')") where
|
13239
|
36 |
"trans[A](r) == ALL x:A. ALL y:A. ALL z:A.
|
|
37 |
<x,y>: r --> <y,z>: r --> <x,z>: r"
|
|
38 |
|
24893
|
39 |
definition
|
|
40 |
rtrancl :: "i=>i" ("(_^*)" [100] 100) (*refl/transitive closure*) where
|
13239
|
41 |
"r^* == lfp(field(r)*field(r), %s. id(field(r)) Un (r O s))"
|
|
42 |
|
24893
|
43 |
definition
|
|
44 |
trancl :: "i=>i" ("(_^+)" [100] 100) (*transitive closure*) where
|
13239
|
45 |
"r^+ == r O r^*"
|
|
46 |
|
24893
|
47 |
definition
|
|
48 |
equiv :: "[i,i]=>o" where
|
14653
|
49 |
"equiv(A,r) == r <= A*A & refl(A,r) & sym(r) & trans(r)"
|
|
50 |
|
|
51 |
|
13239
|
52 |
subsection{*General properties of relations*}
|
|
53 |
|
|
54 |
subsubsection{*irreflexivity*}
|
|
55 |
|
|
56 |
lemma irreflI:
|
|
57 |
"[| !!x. x:A ==> <x,x> ~: r |] ==> irrefl(A,r)"
|
13240
|
58 |
by (simp add: irrefl_def)
|
13239
|
59 |
|
13534
|
60 |
lemma irreflE: "[| irrefl(A,r); x:A |] ==> <x,x> ~: r"
|
13240
|
61 |
by (simp add: irrefl_def)
|
13239
|
62 |
|
|
63 |
subsubsection{*symmetry*}
|
|
64 |
|
|
65 |
lemma symI:
|
|
66 |
"[| !!x y.<x,y>: r ==> <y,x>: r |] ==> sym(r)"
|
13356
|
67 |
by (unfold sym_def, blast)
|
13239
|
68 |
|
13534
|
69 |
lemma symE: "[| sym(r); <x,y>: r |] ==> <y,x>: r"
|
13240
|
70 |
by (unfold sym_def, blast)
|
13239
|
71 |
|
|
72 |
subsubsection{*antisymmetry*}
|
|
73 |
|
|
74 |
lemma antisymI:
|
|
75 |
"[| !!x y.[| <x,y>: r; <y,x>: r |] ==> x=y |] ==> antisym(r)"
|
13356
|
76 |
by (simp add: antisym_def, blast)
|
13239
|
77 |
|
|
78 |
lemma antisymE: "[| antisym(r); <x,y>: r; <y,x>: r |] ==> x=y"
|
13240
|
79 |
by (simp add: antisym_def, blast)
|
13239
|
80 |
|
|
81 |
subsubsection{*transitivity*}
|
|
82 |
|
|
83 |
lemma transD: "[| trans(r); <a,b>:r; <b,c>:r |] ==> <a,c>:r"
|
13240
|
84 |
by (unfold trans_def, blast)
|
13239
|
85 |
|
|
86 |
lemma trans_onD:
|
|
87 |
"[| trans[A](r); <a,b>:r; <b,c>:r; a:A; b:A; c:A |] ==> <a,c>:r"
|
13243
|
88 |
by (unfold trans_on_def, blast)
|
|
89 |
|
|
90 |
lemma trans_imp_trans_on: "trans(r) ==> trans[A](r)"
|
|
91 |
by (unfold trans_def trans_on_def, blast)
|
13239
|
92 |
|
13248
|
93 |
lemma trans_on_imp_trans: "[|trans[A](r); r <= A*A|] ==> trans(r)";
|
|
94 |
by (simp add: trans_on_def trans_def, blast)
|
|
95 |
|
|
96 |
|
13239
|
97 |
subsection{*Transitive closure of a relation*}
|
|
98 |
|
|
99 |
lemma rtrancl_bnd_mono:
|
|
100 |
"bnd_mono(field(r)*field(r), %s. id(field(r)) Un (r O s))"
|
13248
|
101 |
by (rule bnd_monoI, blast+)
|
13239
|
102 |
|
|
103 |
lemma rtrancl_mono: "r<=s ==> r^* <= s^*"
|
|
104 |
apply (unfold rtrancl_def)
|
|
105 |
apply (rule lfp_mono)
|
|
106 |
apply (rule rtrancl_bnd_mono)+
|
13240
|
107 |
apply blast
|
13239
|
108 |
done
|
|
109 |
|
|
110 |
(* r^* = id(field(r)) Un ( r O r^* ) *)
|
|
111 |
lemmas rtrancl_unfold =
|
|
112 |
rtrancl_bnd_mono [THEN rtrancl_def [THEN def_lfp_unfold], standard]
|
|
113 |
|
|
114 |
(** The relation rtrancl **)
|
|
115 |
|
|
116 |
(* r^* <= field(r) * field(r) *)
|
|
117 |
lemmas rtrancl_type = rtrancl_def [THEN def_lfp_subset, standard]
|
|
118 |
|
13248
|
119 |
lemma relation_rtrancl: "relation(r^*)"
|
|
120 |
apply (simp add: relation_def)
|
|
121 |
apply (blast dest: rtrancl_type [THEN subsetD])
|
|
122 |
done
|
|
123 |
|
13239
|
124 |
(*Reflexivity of rtrancl*)
|
|
125 |
lemma rtrancl_refl: "[| a: field(r) |] ==> <a,a> : r^*"
|
|
126 |
apply (rule rtrancl_unfold [THEN ssubst])
|
|
127 |
apply (erule idI [THEN UnI1])
|
|
128 |
done
|
|
129 |
|
|
130 |
(*Closure under composition with r *)
|
|
131 |
lemma rtrancl_into_rtrancl: "[| <a,b> : r^*; <b,c> : r |] ==> <a,c> : r^*"
|
|
132 |
apply (rule rtrancl_unfold [THEN ssubst])
|
13269
|
133 |
apply (rule compI [THEN UnI2], assumption, assumption)
|
13239
|
134 |
done
|
|
135 |
|
|
136 |
(*rtrancl of r contains all pairs in r *)
|
|
137 |
lemma r_into_rtrancl: "<a,b> : r ==> <a,b> : r^*"
|
13240
|
138 |
by (rule rtrancl_refl [THEN rtrancl_into_rtrancl], blast+)
|
13239
|
139 |
|
|
140 |
(*The premise ensures that r consists entirely of pairs*)
|
13248
|
141 |
lemma r_subset_rtrancl: "relation(r) ==> r <= r^*"
|
|
142 |
by (simp add: relation_def, blast intro: r_into_rtrancl)
|
13239
|
143 |
|
|
144 |
lemma rtrancl_field: "field(r^*) = field(r)"
|
13240
|
145 |
by (blast intro: r_into_rtrancl dest!: rtrancl_type [THEN subsetD])
|
13239
|
146 |
|
|
147 |
|
|
148 |
(** standard induction rule **)
|
|
149 |
|
13534
|
150 |
lemma rtrancl_full_induct [case_names initial step, consumes 1]:
|
13239
|
151 |
"[| <a,b> : r^*;
|
|
152 |
!!x. x: field(r) ==> P(<x,x>);
|
|
153 |
!!x y z.[| P(<x,y>); <x,y>: r^*; <y,z>: r |] ==> P(<x,z>) |]
|
|
154 |
==> P(<a,b>)"
|
13248
|
155 |
by (erule def_induct [OF rtrancl_def rtrancl_bnd_mono], blast)
|
13239
|
156 |
|
|
157 |
(*nice induction rule.
|
|
158 |
Tried adding the typing hypotheses y,z:field(r), but these
|
|
159 |
caused expensive case splits!*)
|
13534
|
160 |
lemma rtrancl_induct [case_names initial step, induct set: rtrancl]:
|
13239
|
161 |
"[| <a,b> : r^*;
|
|
162 |
P(a);
|
|
163 |
!!y z.[| <a,y> : r^*; <y,z> : r; P(y) |] ==> P(z)
|
|
164 |
|] ==> P(b)"
|
|
165 |
(*by induction on this formula*)
|
|
166 |
apply (subgoal_tac "ALL y. <a,b> = <a,y> --> P (y) ")
|
|
167 |
(*now solve first subgoal: this formula is sufficient*)
|
|
168 |
apply (erule spec [THEN mp], rule refl)
|
|
169 |
(*now do the induction*)
|
13240
|
170 |
apply (erule rtrancl_full_induct, blast+)
|
13239
|
171 |
done
|
|
172 |
|
|
173 |
(*transitivity of transitive closure!! -- by induction.*)
|
|
174 |
lemma trans_rtrancl: "trans(r^*)"
|
|
175 |
apply (unfold trans_def)
|
|
176 |
apply (intro allI impI)
|
13784
|
177 |
apply (erule_tac b = z in rtrancl_induct, assumption)
|
13239
|
178 |
apply (blast intro: rtrancl_into_rtrancl)
|
|
179 |
done
|
|
180 |
|
|
181 |
lemmas rtrancl_trans = trans_rtrancl [THEN transD, standard]
|
|
182 |
|
|
183 |
(*elimination of rtrancl -- by induction on a special formula*)
|
|
184 |
lemma rtranclE:
|
|
185 |
"[| <a,b> : r^*; (a=b) ==> P;
|
|
186 |
!!y.[| <a,y> : r^*; <y,b> : r |] ==> P |]
|
|
187 |
==> P"
|
|
188 |
apply (subgoal_tac "a = b | (EX y. <a,y> : r^* & <y,b> : r) ")
|
|
189 |
(*see HOL/trancl*)
|
13240
|
190 |
apply blast
|
|
191 |
apply (erule rtrancl_induct, blast+)
|
13239
|
192 |
done
|
|
193 |
|
|
194 |
|
|
195 |
(**** The relation trancl ****)
|
|
196 |
|
|
197 |
(*Transitivity of r^+ is proved by transitivity of r^* *)
|
|
198 |
lemma trans_trancl: "trans(r^+)"
|
|
199 |
apply (unfold trans_def trancl_def)
|
|
200 |
apply (blast intro: rtrancl_into_rtrancl
|
|
201 |
trans_rtrancl [THEN transD, THEN compI])
|
|
202 |
done
|
|
203 |
|
13243
|
204 |
lemmas trans_on_trancl = trans_trancl [THEN trans_imp_trans_on]
|
|
205 |
|
13239
|
206 |
lemmas trancl_trans = trans_trancl [THEN transD, standard]
|
|
207 |
|
|
208 |
(** Conversions between trancl and rtrancl **)
|
0
|
209 |
|
13239
|
210 |
lemma trancl_into_rtrancl: "<a,b> : r^+ ==> <a,b> : r^*"
|
|
211 |
apply (unfold trancl_def)
|
|
212 |
apply (blast intro: rtrancl_into_rtrancl)
|
|
213 |
done
|
|
214 |
|
|
215 |
(*r^+ contains all pairs in r *)
|
|
216 |
lemma r_into_trancl: "<a,b> : r ==> <a,b> : r^+"
|
|
217 |
apply (unfold trancl_def)
|
|
218 |
apply (blast intro!: rtrancl_refl)
|
|
219 |
done
|
|
220 |
|
|
221 |
(*The premise ensures that r consists entirely of pairs*)
|
13248
|
222 |
lemma r_subset_trancl: "relation(r) ==> r <= r^+"
|
|
223 |
by (simp add: relation_def, blast intro: r_into_trancl)
|
|
224 |
|
13239
|
225 |
|
|
226 |
(*intro rule by definition: from r^* and r *)
|
|
227 |
lemma rtrancl_into_trancl1: "[| <a,b> : r^*; <b,c> : r |] ==> <a,c> : r^+"
|
13240
|
228 |
by (unfold trancl_def, blast)
|
13239
|
229 |
|
|
230 |
(*intro rule from r and r^* *)
|
|
231 |
lemma rtrancl_into_trancl2:
|
|
232 |
"[| <a,b> : r; <b,c> : r^* |] ==> <a,c> : r^+"
|
|
233 |
apply (erule rtrancl_induct)
|
|
234 |
apply (erule r_into_trancl)
|
|
235 |
apply (blast intro: r_into_trancl trancl_trans)
|
|
236 |
done
|
|
237 |
|
|
238 |
(*Nice induction rule for trancl*)
|
13534
|
239 |
lemma trancl_induct [case_names initial step, induct set: trancl]:
|
13239
|
240 |
"[| <a,b> : r^+;
|
|
241 |
!!y. [| <a,y> : r |] ==> P(y);
|
|
242 |
!!y z.[| <a,y> : r^+; <y,z> : r; P(y) |] ==> P(z)
|
|
243 |
|] ==> P(b)"
|
|
244 |
apply (rule compEpair)
|
|
245 |
apply (unfold trancl_def, assumption)
|
|
246 |
(*by induction on this formula*)
|
|
247 |
apply (subgoal_tac "ALL z. <y,z> : r --> P (z) ")
|
|
248 |
(*now solve first subgoal: this formula is sufficient*)
|
|
249 |
apply blast
|
|
250 |
apply (erule rtrancl_induct)
|
|
251 |
apply (blast intro: rtrancl_into_trancl1)+
|
|
252 |
done
|
|
253 |
|
|
254 |
(*elimination of r^+ -- NOT an induction rule*)
|
|
255 |
lemma tranclE:
|
|
256 |
"[| <a,b> : r^+;
|
|
257 |
<a,b> : r ==> P;
|
|
258 |
!!y.[| <a,y> : r^+; <y,b> : r |] ==> P
|
|
259 |
|] ==> P"
|
|
260 |
apply (subgoal_tac "<a,b> : r | (EX y. <a,y> : r^+ & <y,b> : r) ")
|
13240
|
261 |
apply blast
|
13239
|
262 |
apply (rule compEpair)
|
|
263 |
apply (unfold trancl_def, assumption)
|
|
264 |
apply (erule rtranclE)
|
|
265 |
apply (blast intro: rtrancl_into_trancl1)+
|
|
266 |
done
|
|
267 |
|
|
268 |
lemma trancl_type: "r^+ <= field(r)*field(r)"
|
|
269 |
apply (unfold trancl_def)
|
|
270 |
apply (blast elim: rtrancl_type [THEN subsetD, THEN SigmaE2])
|
|
271 |
done
|
|
272 |
|
13248
|
273 |
lemma relation_trancl: "relation(r^+)"
|
|
274 |
apply (simp add: relation_def)
|
|
275 |
apply (blast dest: trancl_type [THEN subsetD])
|
|
276 |
done
|
|
277 |
|
13243
|
278 |
lemma trancl_subset_times: "r \<subseteq> A * A ==> r^+ \<subseteq> A * A"
|
|
279 |
by (insert trancl_type [of r], blast)
|
|
280 |
|
13239
|
281 |
lemma trancl_mono: "r<=s ==> r^+ <= s^+"
|
|
282 |
by (unfold trancl_def, intro comp_mono rtrancl_mono)
|
|
283 |
|
13248
|
284 |
lemma trancl_eq_r: "[|relation(r); trans(r)|] ==> r^+ = r"
|
|
285 |
apply (rule equalityI)
|
|
286 |
prefer 2 apply (erule r_subset_trancl, clarify)
|
|
287 |
apply (frule trancl_type [THEN subsetD], clarify)
|
|
288 |
apply (erule trancl_induct, assumption)
|
|
289 |
apply (blast dest: transD)
|
|
290 |
done
|
|
291 |
|
13239
|
292 |
|
|
293 |
(** Suggested by Sidi Ould Ehmety **)
|
|
294 |
|
|
295 |
lemma rtrancl_idemp [simp]: "(r^*)^* = r^*"
|
13240
|
296 |
apply (rule equalityI, auto)
|
13239
|
297 |
prefer 2
|
|
298 |
apply (frule rtrancl_type [THEN subsetD])
|
13240
|
299 |
apply (blast intro: r_into_rtrancl )
|
13239
|
300 |
txt{*converse direction*}
|
13240
|
301 |
apply (frule rtrancl_type [THEN subsetD], clarify)
|
13239
|
302 |
apply (erule rtrancl_induct)
|
|
303 |
apply (simp add: rtrancl_refl rtrancl_field)
|
|
304 |
apply (blast intro: rtrancl_trans)
|
|
305 |
done
|
|
306 |
|
|
307 |
lemma rtrancl_subset: "[| R <= S; S <= R^* |] ==> S^* = R^*"
|
|
308 |
apply (drule rtrancl_mono)
|
13269
|
309 |
apply (drule rtrancl_mono, simp_all, blast)
|
13239
|
310 |
done
|
|
311 |
|
|
312 |
lemma rtrancl_Un_rtrancl:
|
13248
|
313 |
"[| relation(r); relation(s) |] ==> (r^* Un s^*)^* = (r Un s)^*"
|
13239
|
314 |
apply (rule rtrancl_subset)
|
|
315 |
apply (blast dest: r_subset_rtrancl)
|
|
316 |
apply (blast intro: rtrancl_mono [THEN subsetD])
|
|
317 |
done
|
|
318 |
|
|
319 |
(*** "converse" laws by Sidi Ould Ehmety ***)
|
|
320 |
|
|
321 |
(** rtrancl **)
|
|
322 |
|
|
323 |
lemma rtrancl_converseD: "<x,y>:converse(r)^* ==> <x,y>:converse(r^*)"
|
|
324 |
apply (rule converseI)
|
|
325 |
apply (frule rtrancl_type [THEN subsetD])
|
|
326 |
apply (erule rtrancl_induct)
|
|
327 |
apply (blast intro: rtrancl_refl)
|
|
328 |
apply (blast intro: r_into_rtrancl rtrancl_trans)
|
|
329 |
done
|
|
330 |
|
|
331 |
lemma rtrancl_converseI: "<x,y>:converse(r^*) ==> <x,y>:converse(r)^*"
|
|
332 |
apply (drule converseD)
|
|
333 |
apply (frule rtrancl_type [THEN subsetD])
|
|
334 |
apply (erule rtrancl_induct)
|
|
335 |
apply (blast intro: rtrancl_refl)
|
|
336 |
apply (blast intro: r_into_rtrancl rtrancl_trans)
|
|
337 |
done
|
|
338 |
|
|
339 |
lemma rtrancl_converse: "converse(r)^* = converse(r^*)"
|
|
340 |
apply (safe intro!: equalityI)
|
|
341 |
apply (frule rtrancl_type [THEN subsetD])
|
|
342 |
apply (safe dest!: rtrancl_converseD intro!: rtrancl_converseI)
|
|
343 |
done
|
|
344 |
|
|
345 |
(** trancl **)
|
|
346 |
|
|
347 |
lemma trancl_converseD: "<a, b>:converse(r)^+ ==> <a, b>:converse(r^+)"
|
|
348 |
apply (erule trancl_induct)
|
|
349 |
apply (auto intro: r_into_trancl trancl_trans)
|
|
350 |
done
|
|
351 |
|
|
352 |
lemma trancl_converseI: "<x,y>:converse(r^+) ==> <x,y>:converse(r)^+"
|
|
353 |
apply (drule converseD)
|
|
354 |
apply (erule trancl_induct)
|
|
355 |
apply (auto intro: r_into_trancl trancl_trans)
|
|
356 |
done
|
|
357 |
|
|
358 |
lemma trancl_converse: "converse(r)^+ = converse(r^+)"
|
|
359 |
apply (safe intro!: equalityI)
|
|
360 |
apply (frule trancl_type [THEN subsetD])
|
|
361 |
apply (safe dest!: trancl_converseD intro!: trancl_converseI)
|
|
362 |
done
|
|
363 |
|
13534
|
364 |
lemma converse_trancl_induct [case_names initial step, consumes 1]:
|
13239
|
365 |
"[| <a, b>:r^+; !!y. <y, b> :r ==> P(y);
|
|
366 |
!!y z. [| <y, z> : r; <z, b> : r^+; P(z) |] ==> P(y) |]
|
|
367 |
==> P(a)"
|
|
368 |
apply (drule converseI)
|
|
369 |
apply (simp (no_asm_use) add: trancl_converse [symmetric])
|
|
370 |
apply (erule trancl_induct)
|
|
371 |
apply (auto simp add: trancl_converse)
|
|
372 |
done
|
|
373 |
|
0
|
374 |
end
|