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