| author | wenzelm | 
| Mon, 25 Feb 2002 20:48:14 +0100 | |
| changeset 12937 | 0c4fd7529467 | 
| parent 12823 | 9d3f5056296b | 
| child 13704 | 854501b1e957 | 
| permissions | -rw-r--r-- | 
| 10213 | 1  | 
(* Title: HOL/Transitive_Closure.thy  | 
2  | 
ID: $Id$  | 
|
3  | 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory  | 
|
4  | 
Copyright 1992 University of Cambridge  | 
|
5  | 
*)  | 
|
6  | 
||
| 12691 | 7  | 
header {* Reflexive and Transitive closure of a relation *}
 | 
8  | 
||
9  | 
theory Transitive_Closure = Inductive:  | 
|
10  | 
||
11  | 
text {*
 | 
|
12  | 
  @{text rtrancl} is reflexive/transitive closure,
 | 
|
13  | 
  @{text trancl} is transitive closure,
 | 
|
14  | 
  @{text reflcl} is reflexive closure.
 | 
|
15  | 
||
16  | 
  These postfix operators have \emph{maximum priority}, forcing their
 | 
|
17  | 
operands to be atomic.  | 
|
18  | 
*}  | 
|
| 10213 | 19  | 
|
| 
11327
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
20  | 
consts  | 
| 12691 | 21  | 
  rtrancl :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_^*)" [1000] 999)
 | 
| 
11327
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
22  | 
|
| 
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
23  | 
inductive "r^*"  | 
| 12691 | 24  | 
intros  | 
| 12823 | 25  | 
rtrancl_refl [intro!, CPure.intro!, simp]: "(a, a) : r^*"  | 
26  | 
rtrancl_into_rtrancl [CPure.intro]: "(a, b) : r^* ==> (b, c) : r ==> (a, c) : r^*"  | 
|
| 
11327
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
27  | 
|
| 10213 | 28  | 
constdefs  | 
| 12691 | 29  | 
  trancl :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_^+)" [1000] 999)
 | 
| 10331 | 30  | 
"r^+ == r O rtrancl r"  | 
| 10213 | 31  | 
|
32  | 
syntax  | 
|
| 12691 | 33  | 
  "_reflcl" :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_^=)" [1000] 999)
 | 
| 10213 | 34  | 
translations  | 
| 12691 | 35  | 
"r^=" == "r \<union> Id"  | 
| 10213 | 36  | 
|
| 10827 | 37  | 
syntax (xsymbols)  | 
| 12691 | 38  | 
  rtrancl :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_\\<^sup>*)" [1000] 999)
 | 
39  | 
  trancl :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_\\<^sup>+)" [1000] 999)
 | 
|
40  | 
  "_reflcl" :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_\\<^sup>=)" [1000] 999)
 | 
|
41  | 
||
42  | 
||
43  | 
subsection {* Reflexive-transitive closure *}
 | 
|
44  | 
||
45  | 
lemma r_into_rtrancl [intro]: "!!p. p \<in> r ==> p \<in> r^*"  | 
|
46  | 
  -- {* @{text rtrancl} of @{text r} contains @{text r} *}
 | 
|
47  | 
apply (simp only: split_tupled_all)  | 
|
48  | 
apply (erule rtrancl_refl [THEN rtrancl_into_rtrancl])  | 
|
49  | 
done  | 
|
50  | 
||
51  | 
lemma rtrancl_mono: "r \<subseteq> s ==> r^* \<subseteq> s^*"  | 
|
52  | 
  -- {* monotonicity of @{text rtrancl} *}
 | 
|
53  | 
apply (rule subsetI)  | 
|
54  | 
apply (simp only: split_tupled_all)  | 
|
55  | 
apply (erule rtrancl.induct)  | 
|
56  | 
apply (rule_tac [2] rtrancl_into_rtrancl)  | 
|
57  | 
apply blast+  | 
|
58  | 
done  | 
|
59  | 
||
| 12823 | 60  | 
theorem rtrancl_induct [consumes 1, induct set: rtrancl]:  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
61  | 
assumes a: "(a, b) : r^*"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
62  | 
and cases: "P a" "!!y z. [| (a, y) : r^*; (y, z) : r; P y |] ==> P z"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
63  | 
shows "P b"  | 
| 12691 | 64  | 
proof -  | 
65  | 
from a have "a = a --> P b"  | 
|
| 12823 | 66  | 
by (induct "%x y. x = a --> P y" a b) (rules intro: cases)+  | 
| 12691 | 67  | 
thus ?thesis by rules  | 
68  | 
qed  | 
|
69  | 
||
70  | 
ML_setup {*
 | 
|
71  | 
  bind_thm ("rtrancl_induct2", split_rule
 | 
|
72  | 
    (read_instantiate [("a","(ax,ay)"), ("b","(bx,by)")] (thm "rtrancl_induct")));
 | 
|
73  | 
*}  | 
|
74  | 
||
75  | 
lemma trans_rtrancl: "trans(r^*)"  | 
|
76  | 
  -- {* transitivity of transitive closure!! -- by induction *}
 | 
|
| 12823 | 77  | 
proof (rule transI)  | 
78  | 
fix x y z  | 
|
79  | 
assume "(x, y) \<in> r\<^sup>*"  | 
|
80  | 
assume "(y, z) \<in> r\<^sup>*"  | 
|
81  | 
thus "(x, z) \<in> r\<^sup>*" by induct (rules!)+  | 
|
82  | 
qed  | 
|
| 12691 | 83  | 
|
84  | 
lemmas rtrancl_trans = trans_rtrancl [THEN transD, standard]  | 
|
85  | 
||
86  | 
lemma rtranclE:  | 
|
87  | 
"[| (a::'a,b) : r^*; (a = b) ==> P;  | 
|
88  | 
!!y.[| (a,y) : r^*; (y,b) : r |] ==> P  | 
|
89  | 
|] ==> P"  | 
|
90  | 
  -- {* elimination of @{text rtrancl} -- by induction on a special formula *}
 | 
|
91  | 
proof -  | 
|
92  | 
assume major: "(a::'a,b) : r^*"  | 
|
93  | 
case rule_context  | 
|
94  | 
show ?thesis  | 
|
95  | 
apply (subgoal_tac "(a::'a) = b | (EX y. (a,y) : r^* & (y,b) : r)")  | 
|
96  | 
apply (rule_tac [2] major [THEN rtrancl_induct])  | 
|
97  | 
prefer 2 apply (blast!)  | 
|
98  | 
prefer 2 apply (blast!)  | 
|
99  | 
apply (erule asm_rl exE disjE conjE prems)+  | 
|
100  | 
done  | 
|
101  | 
qed  | 
|
102  | 
||
| 12823 | 103  | 
lemma converse_rtrancl_into_rtrancl:  | 
104  | 
"(a, b) \<in> r \<Longrightarrow> (b, c) \<in> r\<^sup>* \<Longrightarrow> (a, c) \<in> r\<^sup>*"  | 
|
105  | 
by (rule rtrancl_trans) rules+  | 
|
| 12691 | 106  | 
|
107  | 
text {*
 | 
|
108  | 
  \medskip More @{term "r^*"} equations and inclusions.
 | 
|
109  | 
*}  | 
|
110  | 
||
111  | 
lemma rtrancl_idemp [simp]: "(r^*)^* = r^*"  | 
|
112  | 
apply auto  | 
|
113  | 
apply (erule rtrancl_induct)  | 
|
114  | 
apply (rule rtrancl_refl)  | 
|
115  | 
apply (blast intro: rtrancl_trans)  | 
|
116  | 
done  | 
|
117  | 
||
118  | 
lemma rtrancl_idemp_self_comp [simp]: "R^* O R^* = R^*"  | 
|
119  | 
apply (rule set_ext)  | 
|
120  | 
apply (simp only: split_tupled_all)  | 
|
121  | 
apply (blast intro: rtrancl_trans)  | 
|
122  | 
done  | 
|
123  | 
||
124  | 
lemma rtrancl_subset_rtrancl: "r \<subseteq> s^* ==> r^* \<subseteq> s^*"  | 
|
125  | 
apply (drule rtrancl_mono)  | 
|
126  | 
apply simp  | 
|
127  | 
done  | 
|
128  | 
||
129  | 
lemma rtrancl_subset: "R \<subseteq> S ==> S \<subseteq> R^* ==> S^* = R^*"  | 
|
130  | 
apply (drule rtrancl_mono)  | 
|
131  | 
apply (drule rtrancl_mono)  | 
|
132  | 
apply simp  | 
|
133  | 
apply blast  | 
|
134  | 
done  | 
|
135  | 
||
136  | 
lemma rtrancl_Un_rtrancl: "(R^* \<union> S^*)^* = (R \<union> S)^*"  | 
|
137  | 
by (blast intro!: rtrancl_subset intro: r_into_rtrancl rtrancl_mono [THEN subsetD])  | 
|
138  | 
||
139  | 
lemma rtrancl_reflcl [simp]: "(R^=)^* = R^*"  | 
|
140  | 
by (blast intro!: rtrancl_subset intro: r_into_rtrancl)  | 
|
141  | 
||
142  | 
lemma rtrancl_r_diff_Id: "(r - Id)^* = r^*"  | 
|
143  | 
apply (rule sym)  | 
|
144  | 
apply (rule rtrancl_subset)  | 
|
145  | 
apply blast  | 
|
146  | 
apply clarify  | 
|
147  | 
apply (rename_tac a b)  | 
|
148  | 
apply (case_tac "a = b")  | 
|
149  | 
apply blast  | 
|
150  | 
apply (blast intro!: r_into_rtrancl)  | 
|
151  | 
done  | 
|
152  | 
||
| 12823 | 153  | 
theorem rtrancl_converseD:  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
154  | 
assumes r: "(x, y) \<in> (r^-1)^*"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
155  | 
shows "(y, x) \<in> r^*"  | 
| 12823 | 156  | 
proof -  | 
157  | 
from r show ?thesis  | 
|
158  | 
by induct (rules intro: rtrancl_trans dest!: converseD)+  | 
|
159  | 
qed  | 
|
| 12691 | 160  | 
|
| 12823 | 161  | 
theorem rtrancl_converseI:  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
162  | 
assumes r: "(y, x) \<in> r^*"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
163  | 
shows "(x, y) \<in> (r^-1)^*"  | 
| 12823 | 164  | 
proof -  | 
165  | 
from r show ?thesis  | 
|
166  | 
by induct (rules intro: rtrancl_trans converseI)+  | 
|
167  | 
qed  | 
|
| 12691 | 168  | 
|
169  | 
lemma rtrancl_converse: "(r^-1)^* = (r^*)^-1"  | 
|
170  | 
by (fast dest!: rtrancl_converseD intro!: rtrancl_converseI)  | 
|
171  | 
||
| 12823 | 172  | 
theorem converse_rtrancl_induct:  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
173  | 
assumes major: "(a, b) : r^*"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
174  | 
and cases: "P b" "!!y z. [| (y, z) : r; (z, b) : r^*; P z |] ==> P y"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12823 
diff
changeset
 | 
175  | 
shows "P a"  | 
| 12691 | 176  | 
proof -  | 
| 12823 | 177  | 
from rtrancl_converseI [OF major]  | 
| 12691 | 178  | 
show ?thesis  | 
| 12823 | 179  | 
by induct (rules intro: cases dest!: converseD rtrancl_converseD)+  | 
| 12691 | 180  | 
qed  | 
181  | 
||
182  | 
ML_setup {*
 | 
|
183  | 
  bind_thm ("converse_rtrancl_induct2", split_rule
 | 
|
184  | 
    (read_instantiate [("a","(ax,ay)"),("b","(bx,by)")] (thm "converse_rtrancl_induct")));
 | 
|
185  | 
*}  | 
|
186  | 
||
187  | 
lemma converse_rtranclE:  | 
|
188  | 
"[| (x,z):r^*;  | 
|
189  | 
x=z ==> P;  | 
|
190  | 
!!y. [| (x,y):r; (y,z):r^* |] ==> P  | 
|
191  | 
|] ==> P"  | 
|
192  | 
proof -  | 
|
193  | 
assume major: "(x,z):r^*"  | 
|
194  | 
case rule_context  | 
|
195  | 
show ?thesis  | 
|
196  | 
apply (subgoal_tac "x = z | (EX y. (x,y) : r & (y,z) : r^*)")  | 
|
197  | 
apply (rule_tac [2] major [THEN converse_rtrancl_induct])  | 
|
198  | 
prefer 2 apply (blast!)  | 
|
199  | 
prefer 2 apply (blast!)  | 
|
200  | 
apply (erule asm_rl exE disjE conjE prems)+  | 
|
201  | 
done  | 
|
202  | 
qed  | 
|
203  | 
||
204  | 
ML_setup {*
 | 
|
205  | 
  bind_thm ("converse_rtranclE2", split_rule
 | 
|
206  | 
    (read_instantiate [("x","(xa,xb)"), ("z","(za,zb)")] (thm "converse_rtranclE")));
 | 
|
207  | 
*}  | 
|
208  | 
||
209  | 
lemma r_comp_rtrancl_eq: "r O r^* = r^* O r"  | 
|
210  | 
by (blast elim: rtranclE converse_rtranclE  | 
|
211  | 
intro: rtrancl_into_rtrancl converse_rtrancl_into_rtrancl)  | 
|
212  | 
||
213  | 
||
214  | 
subsection {* Transitive closure *}
 | 
|
| 10331 | 215  | 
|
| 12691 | 216  | 
lemma trancl_mono: "p \<in> r^+ ==> r \<subseteq> s ==> p \<in> s^+"  | 
217  | 
apply (unfold trancl_def)  | 
|
218  | 
apply (blast intro: rtrancl_mono [THEN subsetD])  | 
|
219  | 
done  | 
|
220  | 
||
221  | 
text {*
 | 
|
222  | 
  \medskip Conversions between @{text trancl} and @{text rtrancl}.
 | 
|
223  | 
*}  | 
|
224  | 
||
225  | 
lemma trancl_into_rtrancl: "!!p. p \<in> r^+ ==> p \<in> r^*"  | 
|
226  | 
apply (unfold trancl_def)  | 
|
227  | 
apply (simp only: split_tupled_all)  | 
|
228  | 
apply (erule rel_compEpair)  | 
|
229  | 
apply (assumption | rule rtrancl_into_rtrancl)+  | 
|
230  | 
done  | 
|
231  | 
||
232  | 
lemma r_into_trancl [intro]: "!!p. p \<in> r ==> p \<in> r^+"  | 
|
233  | 
  -- {* @{text "r^+"} contains @{text r} *}
 | 
|
234  | 
apply (unfold trancl_def)  | 
|
235  | 
apply (simp only: split_tupled_all)  | 
|
236  | 
apply (assumption | rule rel_compI rtrancl_refl)+  | 
|
237  | 
done  | 
|
238  | 
||
239  | 
lemma rtrancl_into_trancl1: "(a, b) \<in> r^* ==> (b, c) \<in> r ==> (a, c) \<in> r^+"  | 
|
240  | 
  -- {* intro rule by definition: from @{text rtrancl} and @{text r} *}
 | 
|
241  | 
by (auto simp add: trancl_def)  | 
|
242  | 
||
243  | 
lemma rtrancl_into_trancl2: "[| (a,b) : r; (b,c) : r^* |] ==> (a,c) : r^+"  | 
|
244  | 
  -- {* intro rule from @{text r} and @{text rtrancl} *}
 | 
|
245  | 
apply (erule rtranclE)  | 
|
246  | 
apply (blast intro: r_into_trancl)  | 
|
247  | 
apply (rule rtrancl_trans [THEN rtrancl_into_trancl1])  | 
|
248  | 
apply (assumption | rule r_into_rtrancl)+  | 
|
249  | 
done  | 
|
250  | 
||
251  | 
lemma trancl_induct:  | 
|
252  | 
"[| (a,b) : r^+;  | 
|
253  | 
!!y. [| (a,y) : r |] ==> P(y);  | 
|
254  | 
!!y z.[| (a,y) : r^+; (y,z) : r; P(y) |] ==> P(z)  | 
|
255  | 
|] ==> P(b)"  | 
|
256  | 
  -- {* Nice induction rule for @{text trancl} *}
 | 
|
257  | 
proof -  | 
|
258  | 
assume major: "(a, b) : r^+"  | 
|
259  | 
case rule_context  | 
|
260  | 
show ?thesis  | 
|
261  | 
apply (rule major [unfolded trancl_def, THEN rel_compEpair])  | 
|
262  | 
    txt {* by induction on this formula *}
 | 
|
263  | 
apply (subgoal_tac "ALL z. (y,z) : r --> P (z)")  | 
|
264  | 
     txt {* now solve first subgoal: this formula is sufficient *}
 | 
|
265  | 
apply blast  | 
|
266  | 
apply (erule rtrancl_induct)  | 
|
267  | 
apply (blast intro: rtrancl_into_trancl1 prems)+  | 
|
268  | 
done  | 
|
269  | 
qed  | 
|
270  | 
||
271  | 
lemma trancl_trans_induct:  | 
|
272  | 
"[| (x,y) : r^+;  | 
|
273  | 
!!x y. (x,y) : r ==> P x y;  | 
|
274  | 
!!x y z. [| (x,y) : r^+; P x y; (y,z) : r^+; P y z |] ==> P x z  | 
|
275  | 
|] ==> P x y"  | 
|
276  | 
  -- {* Another induction rule for trancl, incorporating transitivity *}
 | 
|
277  | 
proof -  | 
|
278  | 
assume major: "(x,y) : r^+"  | 
|
279  | 
case rule_context  | 
|
280  | 
show ?thesis  | 
|
281  | 
by (blast intro: r_into_trancl major [THEN trancl_induct] prems)  | 
|
282  | 
qed  | 
|
283  | 
||
284  | 
lemma tranclE:  | 
|
285  | 
"[| (a::'a,b) : r^+;  | 
|
286  | 
(a,b) : r ==> P;  | 
|
287  | 
!!y.[| (a,y) : r^+; (y,b) : r |] ==> P  | 
|
288  | 
|] ==> P"  | 
|
289  | 
  -- {* elimination of @{text "r^+"} -- \emph{not} an induction rule *}
 | 
|
290  | 
proof -  | 
|
291  | 
assume major: "(a::'a,b) : r^+"  | 
|
292  | 
case rule_context  | 
|
293  | 
show ?thesis  | 
|
294  | 
apply (subgoal_tac "(a::'a, b) : r | (EX y. (a,y) : r^+ & (y,b) : r)")  | 
|
295  | 
apply (erule asm_rl disjE exE conjE prems)+  | 
|
296  | 
apply (rule major [unfolded trancl_def, THEN rel_compEpair])  | 
|
297  | 
apply (erule rtranclE)  | 
|
298  | 
apply blast  | 
|
299  | 
apply (blast intro!: rtrancl_into_trancl1)  | 
|
300  | 
done  | 
|
301  | 
qed  | 
|
| 10980 | 302  | 
|
| 12691 | 303  | 
lemma trans_trancl: "trans(r^+)"  | 
304  | 
  -- {* Transitivity of @{term "r^+"} *}
 | 
|
305  | 
  -- {* Proved by unfolding since it uses transitivity of @{text rtrancl} *}
 | 
|
306  | 
apply (unfold trancl_def)  | 
|
307  | 
apply (rule transI)  | 
|
308  | 
apply (erule rel_compEpair)+  | 
|
309  | 
apply (rule rtrancl_into_rtrancl [THEN rtrancl_trans [THEN rel_compI]])  | 
|
310  | 
apply assumption+  | 
|
311  | 
done  | 
|
312  | 
||
313  | 
lemmas trancl_trans = trans_trancl [THEN transD, standard]  | 
|
314  | 
||
315  | 
lemma rtrancl_trancl_trancl: "(x, y) \<in> r^* ==> (y, z) \<in> r^+ ==> (x, z) \<in> r^+"  | 
|
316  | 
apply (unfold trancl_def)  | 
|
317  | 
apply (blast intro: rtrancl_trans)  | 
|
318  | 
done  | 
|
319  | 
||
320  | 
lemma trancl_into_trancl2: "(a, b) \<in> r ==> (b, c) \<in> r^+ ==> (a, c) \<in> r^+"  | 
|
321  | 
by (erule transD [OF trans_trancl r_into_trancl])  | 
|
322  | 
||
323  | 
lemma trancl_insert:  | 
|
324  | 
  "(insert (y, x) r)^+ = r^+ \<union> {(a, b). (a, y) \<in> r^* \<and> (x, b) \<in> r^*}"
 | 
|
325  | 
  -- {* primitive recursion for @{text trancl} over finite relations *}
 | 
|
326  | 
apply (rule equalityI)  | 
|
327  | 
apply (rule subsetI)  | 
|
328  | 
apply (simp only: split_tupled_all)  | 
|
329  | 
apply (erule trancl_induct)  | 
|
330  | 
apply blast  | 
|
331  | 
apply (blast intro: rtrancl_into_trancl1 trancl_into_rtrancl r_into_trancl trancl_trans)  | 
|
332  | 
apply (rule subsetI)  | 
|
333  | 
apply (blast intro: trancl_mono rtrancl_mono  | 
|
334  | 
[THEN [2] rev_subsetD] rtrancl_trancl_trancl rtrancl_into_trancl2)  | 
|
335  | 
done  | 
|
336  | 
||
337  | 
lemma trancl_converse: "(r^-1)^+ = (r^+)^-1"  | 
|
338  | 
apply (unfold trancl_def)  | 
|
339  | 
apply (simp add: rtrancl_converse converse_rel_comp)  | 
|
340  | 
apply (simp add: rtrancl_converse [symmetric] r_comp_rtrancl_eq)  | 
|
341  | 
done  | 
|
342  | 
||
343  | 
lemma trancl_converseI: "(x, y) \<in> (r^+)^-1 ==> (x,y) \<in> (r^-1)^+"  | 
|
344  | 
by (simp add: trancl_converse)  | 
|
345  | 
||
346  | 
lemma trancl_converseD: "(x, y) \<in> (r^-1)^+ ==> (x, y) \<in> (r^+)^-1"  | 
|
347  | 
by (simp add: trancl_converse)  | 
|
348  | 
||
349  | 
lemma converse_trancl_induct:  | 
|
350  | 
"[| (a,b) : r^+; !!y. (y,b) : r ==> P(y);  | 
|
351  | 
!!y z.[| (y,z) : r; (z,b) : r^+; P(z) |] ==> P(y) |]  | 
|
352  | 
==> P(a)"  | 
|
353  | 
proof -  | 
|
354  | 
assume major: "(a,b) : r^+"  | 
|
355  | 
case rule_context  | 
|
356  | 
show ?thesis  | 
|
357  | 
apply (rule major [THEN converseI, THEN trancl_converseI [THEN trancl_induct]])  | 
|
358  | 
apply (rule prems)  | 
|
359  | 
apply (erule converseD)  | 
|
360  | 
apply (blast intro: prems dest!: trancl_converseD)  | 
|
361  | 
done  | 
|
362  | 
qed  | 
|
363  | 
||
364  | 
lemma tranclD: "(x, y) \<in> R^+ ==> EX z. (x, z) \<in> R \<and> (z, y) \<in> R^*"  | 
|
365  | 
apply (erule converse_trancl_induct)  | 
|
366  | 
apply auto  | 
|
367  | 
apply (blast intro: rtrancl_trans)  | 
|
368  | 
done  | 
|
369  | 
||
370  | 
lemma irrefl_tranclI: "r^-1 \<inter> r^+ = {} ==> (x, x) \<notin> r^+"
 | 
|
371  | 
apply (subgoal_tac "ALL y. (x, y) : r^+ --> x \<noteq> y")  | 
|
372  | 
apply fast  | 
|
373  | 
apply (intro strip)  | 
|
374  | 
apply (erule trancl_induct)  | 
|
375  | 
apply (auto intro: r_into_trancl)  | 
|
376  | 
done  | 
|
377  | 
||
378  | 
lemma irrefl_trancl_rD: "!!X. ALL x. (x, x) \<notin> r^+ ==> (x, y) \<in> r ==> x \<noteq> y"  | 
|
379  | 
by (blast dest: r_into_trancl)  | 
|
380  | 
||
381  | 
lemma trancl_subset_Sigma_aux:  | 
|
382  | 
"(a, b) \<in> r^* ==> r \<subseteq> A \<times> A ==> a = b \<or> a \<in> A"  | 
|
383  | 
apply (erule rtrancl_induct)  | 
|
384  | 
apply auto  | 
|
385  | 
done  | 
|
386  | 
||
387  | 
lemma trancl_subset_Sigma: "r \<subseteq> A \<times> A ==> r^+ \<subseteq> A \<times> A"  | 
|
388  | 
apply (unfold trancl_def)  | 
|
389  | 
apply (blast dest!: trancl_subset_Sigma_aux)  | 
|
390  | 
done  | 
|
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
391  | 
|
| 11090 | 392  | 
lemma reflcl_trancl [simp]: "(r^+)^= = r^*"  | 
| 11084 | 393  | 
apply safe  | 
| 12691 | 394  | 
apply (erule trancl_into_rtrancl)  | 
| 11084 | 395  | 
apply (blast elim: rtranclE dest: rtrancl_into_trancl1)  | 
396  | 
done  | 
|
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
397  | 
|
| 11090 | 398  | 
lemma trancl_reflcl [simp]: "(r^=)^+ = r^*"  | 
| 11084 | 399  | 
apply safe  | 
400  | 
apply (drule trancl_into_rtrancl)  | 
|
401  | 
apply simp  | 
|
402  | 
apply (erule rtranclE)  | 
|
403  | 
apply safe  | 
|
404  | 
apply (rule r_into_trancl)  | 
|
405  | 
apply simp  | 
|
406  | 
apply (rule rtrancl_into_trancl1)  | 
|
407  | 
apply (erule rtrancl_reflcl [THEN equalityD2, THEN subsetD])  | 
|
408  | 
apply fast  | 
|
409  | 
done  | 
|
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
410  | 
|
| 11090 | 411  | 
lemma trancl_empty [simp]: "{}^+ = {}"
 | 
| 11084 | 412  | 
by (auto elim: trancl_induct)  | 
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
413  | 
|
| 11090 | 414  | 
lemma rtrancl_empty [simp]: "{}^* = Id"
 | 
| 11084 | 415  | 
by (rule subst [OF reflcl_trancl]) simp  | 
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
416  | 
|
| 11090 | 417  | 
lemma rtranclD: "(a, b) \<in> R^* ==> a = b \<or> a \<noteq> b \<and> (a, b) \<in> R^+"  | 
| 11084 | 418  | 
by (force simp add: reflcl_trancl [symmetric] simp del: reflcl_trancl)  | 
419  | 
||
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
420  | 
|
| 12691 | 421  | 
text {* @{text Domain} and @{text Range} *}
 | 
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
422  | 
|
| 11090 | 423  | 
lemma Domain_rtrancl [simp]: "Domain (R^*) = UNIV"  | 
| 11084 | 424  | 
by blast  | 
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
425  | 
|
| 11090 | 426  | 
lemma Range_rtrancl [simp]: "Range (R^*) = UNIV"  | 
| 11084 | 427  | 
by blast  | 
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
428  | 
|
| 11090 | 429  | 
lemma rtrancl_Un_subset: "(R^* \<union> S^*) \<subseteq> (R Un S)^*"  | 
| 11084 | 430  | 
by (rule rtrancl_Un_rtrancl [THEN subst]) fast  | 
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
431  | 
|
| 11090 | 432  | 
lemma in_rtrancl_UnI: "x \<in> R^* \<or> x \<in> S^* ==> x \<in> (R \<union> S)^*"  | 
| 11084 | 433  | 
by (blast intro: subsetD [OF rtrancl_Un_subset])  | 
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
434  | 
|
| 11090 | 435  | 
lemma trancl_domain [simp]: "Domain (r^+) = Domain r"  | 
| 11084 | 436  | 
by (unfold Domain_def) (blast dest: tranclD)  | 
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
437  | 
|
| 11090 | 438  | 
lemma trancl_range [simp]: "Range (r^+) = Range r"  | 
| 11084 | 439  | 
by (simp add: Range_def trancl_converse [symmetric])  | 
| 
10996
 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 
nipkow 
parents: 
10980 
diff
changeset
 | 
440  | 
|
| 11115 | 441  | 
lemma Not_Domain_rtrancl:  | 
| 12691 | 442  | 
"x ~: Domain R ==> ((x, y) : R^*) = (x = y)"  | 
443  | 
apply auto  | 
|
444  | 
by (erule rev_mp, erule rtrancl_induct, auto)  | 
|
445  | 
||
| 
11327
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
446  | 
|
| 12691 | 447  | 
text {* More about converse @{text rtrancl} and @{text trancl}, should
 | 
448  | 
be merged with main body. *}  | 
|
| 
12428
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
449  | 
|
| 12691 | 450  | 
lemma r_r_into_trancl: "(a, b) \<in> R ==> (b, c) \<in> R ==> (a, c) \<in> R^+"  | 
| 
12428
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
451  | 
by (fast intro: trancl_trans)  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
452  | 
|
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
453  | 
lemma trancl_into_trancl [rule_format]:  | 
| 12691 | 454  | 
"(a, b) \<in> r\<^sup>+ ==> (b, c) \<in> r --> (a,c) \<in> r\<^sup>+"  | 
455  | 
apply (erule trancl_induct)  | 
|
| 
12428
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
456  | 
apply (fast intro: r_r_into_trancl)  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
457  | 
apply (fast intro: r_r_into_trancl trancl_trans)  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
458  | 
done  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
459  | 
|
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
460  | 
lemma trancl_rtrancl_trancl:  | 
| 12691 | 461  | 
"(a, b) \<in> r\<^sup>+ ==> (b, c) \<in> r\<^sup>* ==> (a, c) \<in> r\<^sup>+"  | 
| 
12428
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
462  | 
apply (drule tranclD)  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
463  | 
apply (erule exE, erule conjE)  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
464  | 
apply (drule rtrancl_trans, assumption)  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
465  | 
apply (drule rtrancl_into_trancl2, assumption)  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
466  | 
apply assumption  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
467  | 
done  | 
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
468  | 
|
| 12691 | 469  | 
lemmas transitive_closure_trans [trans] =  | 
470  | 
r_r_into_trancl trancl_trans rtrancl_trans  | 
|
471  | 
trancl_into_trancl trancl_into_trancl2  | 
|
472  | 
rtrancl_into_rtrancl converse_rtrancl_into_rtrancl  | 
|
473  | 
rtrancl_trancl_trancl trancl_rtrancl_trancl  | 
|
| 
12428
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
474  | 
|
| 
 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 
kleing 
parents: 
11327 
diff
changeset
 | 
475  | 
declare trancl_into_rtrancl [elim]  | 
| 
11327
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
476  | 
|
| 
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
477  | 
declare rtranclE [cases set: rtrancl]  | 
| 
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
478  | 
declare trancl_induct [induct set: trancl]  | 
| 
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
479  | 
declare tranclE [cases set: trancl]  | 
| 
 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 
berghofe 
parents: 
11115 
diff
changeset
 | 
480  | 
|
| 10213 | 481  | 
end  |