author | wenzelm |
Thu, 04 Oct 2001 15:29:22 +0200 | |
changeset 11679 | afdbee613f58 |
parent 11327 | cd2c27a23df1 |
child 12486 | 0ed8bdd883e0 |
permissions | -rw-r--r-- |
10980 | 1 |
(* Title: HOL/Transitive_Closure_lemmas.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1992 University of Cambridge |
|
5 |
||
6 |
Theorems about the transitive closure of a relation |
|
7 |
*) |
|
8 |
||
11327
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
9 |
val rtrancl_refl = thm "rtrancl_refl"; |
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
10 |
val rtrancl_into_rtrancl = thm "rtrancl_into_rtrancl"; |
10980 | 11 |
val trancl_def = thm "trancl_def"; |
12 |
||
13 |
||
14 |
(** The relation rtrancl **) |
|
15 |
||
16 |
section "^*"; |
|
17 |
||
18 |
(*rtrancl of r contains r*) |
|
19 |
Goal "!!p. p : r ==> p : r^*"; |
|
20 |
by (split_all_tac 1); |
|
21 |
by (etac (rtrancl_refl RS rtrancl_into_rtrancl) 1); |
|
22 |
qed "r_into_rtrancl"; |
|
23 |
||
24 |
AddIs [r_into_rtrancl]; |
|
25 |
||
26 |
(*monotonicity of rtrancl*) |
|
11327
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
27 |
Goal "r <= s ==> r^* <= s^*"; |
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
28 |
by (rtac subsetI 1); |
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
29 |
by (split_all_tac 1); |
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
30 |
by (etac (thm "rtrancl.induct") 1); |
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
31 |
by (rtac rtrancl_into_rtrancl 2); |
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
32 |
by (ALLGOALS Blast_tac); |
10980 | 33 |
qed "rtrancl_mono"; |
34 |
||
35 |
(*nice induction rule*) |
|
36 |
val major::prems = Goal |
|
37 |
"[| (a::'a,b) : r^*; \ |
|
38 |
\ P(a); \ |
|
39 |
\ !!y z.[| (a,y) : r^*; (y,z) : r; P(y) |] ==> P(z) |] \ |
|
40 |
\ ==> P(b)"; |
|
11327
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
41 |
by (rtac (read_instantiate [("P","%x y. x = a --> P y")] |
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
42 |
(major RS thm "rtrancl.induct") RS mp) 1); |
cd2c27a23df1
Transitive closure is now defined via "inductive".
berghofe
parents:
10996
diff
changeset
|
43 |
by (ALLGOALS (blast_tac (claset() addIs prems))); |
10980 | 44 |
qed "rtrancl_induct"; |
45 |
||
46 |
bind_thm ("rtrancl_induct2", split_rule |
|
47 |
(read_instantiate [("a","(ax,ay)"), ("b","(bx,by)")] rtrancl_induct)); |
|
48 |
||
49 |
(*transitivity of transitive closure!! -- by induction.*) |
|
50 |
Goalw [trans_def] "trans(r^*)"; |
|
51 |
by Safe_tac; |
|
52 |
by (eres_inst_tac [("b","z")] rtrancl_induct 1); |
|
53 |
by (ALLGOALS(blast_tac (claset() addIs [rtrancl_into_rtrancl]))); |
|
54 |
qed "trans_rtrancl"; |
|
55 |
||
56 |
bind_thm ("rtrancl_trans", trans_rtrancl RS transD); |
|
57 |
||
58 |
||
59 |
(*elimination of rtrancl -- by induction on a special formula*) |
|
60 |
val major::prems = Goal |
|
61 |
"[| (a::'a,b) : r^*; (a = b) ==> P; \ |
|
62 |
\ !!y.[| (a,y) : r^*; (y,b) : r |] ==> P \ |
|
63 |
\ |] ==> P"; |
|
64 |
by (subgoal_tac "(a::'a) = b | (? y. (a,y) : r^* & (y,b) : r)" 1); |
|
65 |
by (rtac (major RS rtrancl_induct) 2); |
|
66 |
by (blast_tac (claset() addIs prems) 2); |
|
67 |
by (blast_tac (claset() addIs prems) 2); |
|
68 |
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1)); |
|
69 |
qed "rtranclE"; |
|
70 |
||
71 |
bind_thm ("rtrancl_into_rtrancl2", r_into_rtrancl RS rtrancl_trans); |
|
72 |
||
73 |
(*** More r^* equations and inclusions ***) |
|
74 |
||
75 |
Goal "(r^*)^* = r^*"; |
|
76 |
by Auto_tac; |
|
77 |
by (etac rtrancl_induct 1); |
|
78 |
by (rtac rtrancl_refl 1); |
|
79 |
by (blast_tac (claset() addIs [rtrancl_trans]) 1); |
|
80 |
qed "rtrancl_idemp"; |
|
81 |
Addsimps [rtrancl_idemp]; |
|
82 |
||
83 |
Goal "R^* O R^* = R^*"; |
|
84 |
by (rtac set_ext 1); |
|
85 |
by (split_all_tac 1); |
|
86 |
by (blast_tac (claset() addIs [rtrancl_trans]) 1); |
|
87 |
qed "rtrancl_idemp_self_comp"; |
|
88 |
Addsimps [rtrancl_idemp_self_comp]; |
|
89 |
||
90 |
Goal "r <= s^* ==> r^* <= s^*"; |
|
91 |
by (dtac rtrancl_mono 1); |
|
92 |
by (Asm_full_simp_tac 1); |
|
93 |
qed "rtrancl_subset_rtrancl"; |
|
94 |
||
95 |
Goal "[| R <= S; S <= R^* |] ==> S^* = R^*"; |
|
96 |
by (dtac rtrancl_mono 1); |
|
97 |
by (dtac rtrancl_mono 1); |
|
98 |
by (Asm_full_simp_tac 1); |
|
99 |
by (Blast_tac 1); |
|
100 |
qed "rtrancl_subset"; |
|
101 |
||
102 |
Goal "(R^* Un S^*)^* = (R Un S)^*"; |
|
103 |
by (blast_tac (claset() addSIs [rtrancl_subset] |
|
104 |
addIs [r_into_rtrancl, rtrancl_mono RS subsetD]) 1); |
|
105 |
qed "rtrancl_Un_rtrancl"; |
|
106 |
||
107 |
Goal "(R^=)^* = R^*"; |
|
108 |
by (blast_tac (claset() addSIs [rtrancl_subset] addIs [r_into_rtrancl]) 1); |
|
109 |
qed "rtrancl_reflcl"; |
|
110 |
Addsimps [rtrancl_reflcl]; |
|
111 |
||
112 |
Goal "(r - Id)^* = r^*"; |
|
113 |
by (rtac sym 1); |
|
114 |
by (rtac rtrancl_subset 1); |
|
115 |
by (Blast_tac 1); |
|
116 |
by (Clarify_tac 1); |
|
117 |
by (rename_tac "a b" 1); |
|
118 |
by (case_tac "a=b" 1); |
|
119 |
by (Blast_tac 1); |
|
120 |
by (blast_tac (claset() addSIs [r_into_rtrancl]) 1); |
|
121 |
qed "rtrancl_r_diff_Id"; |
|
122 |
||
123 |
Goal "(x,y) : (r^-1)^* ==> (y,x) : r^*"; |
|
124 |
by (etac rtrancl_induct 1); |
|
125 |
by (rtac rtrancl_refl 1); |
|
126 |
by (blast_tac (claset() addIs [rtrancl_trans]) 1); |
|
127 |
qed "rtrancl_converseD"; |
|
128 |
||
129 |
Goal "(y,x) : r^* ==> (x,y) : (r^-1)^*"; |
|
130 |
by (etac rtrancl_induct 1); |
|
131 |
by (rtac rtrancl_refl 1); |
|
132 |
by (blast_tac (claset() addIs [rtrancl_trans]) 1); |
|
133 |
qed "rtrancl_converseI"; |
|
134 |
||
135 |
Goal "(r^-1)^* = (r^*)^-1"; |
|
136 |
(*blast_tac fails: the split_all_tac wrapper must be called to convert |
|
137 |
the set element to a pair*) |
|
138 |
by (safe_tac (claset() addSDs [rtrancl_converseD] addSIs [rtrancl_converseI])); |
|
139 |
qed "rtrancl_converse"; |
|
140 |
||
141 |
val major::prems = Goal |
|
142 |
"[| (a,b) : r^*; P(b); \ |
|
143 |
\ !!y z.[| (y,z) : r; (z,b) : r^*; P(z) |] ==> P(y) |] \ |
|
144 |
\ ==> P(a)"; |
|
145 |
by (rtac (major RS rtrancl_converseI RS rtrancl_induct) 1); |
|
146 |
by (resolve_tac prems 1); |
|
147 |
by (blast_tac (claset() addIs prems addSDs[rtrancl_converseD])1); |
|
148 |
qed "converse_rtrancl_induct"; |
|
149 |
||
150 |
bind_thm ("converse_rtrancl_induct2", split_rule |
|
151 |
(read_instantiate [("a","(ax,ay)"),("b","(bx,by)")]converse_rtrancl_induct)); |
|
152 |
||
153 |
val major::prems = Goal |
|
154 |
"[| (x,z):r^*; \ |
|
155 |
\ x=z ==> P; \ |
|
156 |
\ !!y. [| (x,y):r; (y,z):r^* |] ==> P \ |
|
157 |
\ |] ==> P"; |
|
158 |
by (subgoal_tac "x = z | (? y. (x,y) : r & (y,z) : r^*)" 1); |
|
159 |
by (rtac (major RS converse_rtrancl_induct) 2); |
|
160 |
by (blast_tac (claset() addIs prems) 2); |
|
161 |
by (blast_tac (claset() addIs prems) 2); |
|
162 |
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1)); |
|
163 |
qed "converse_rtranclE"; |
|
164 |
||
165 |
bind_thm ("converse_rtranclE2", split_rule |
|
166 |
(read_instantiate [("x","(xa,xb)"), ("z","(za,zb)")] converse_rtranclE)); |
|
167 |
||
168 |
Goal "r O r^* = r^* O r"; |
|
169 |
by (blast_tac (claset() addEs [rtranclE, converse_rtranclE] |
|
170 |
addIs [rtrancl_into_rtrancl, rtrancl_into_rtrancl2]) 1); |
|
171 |
qed "r_comp_rtrancl_eq"; |
|
172 |
||
173 |
||
174 |
(**** The relation trancl ****) |
|
175 |
||
176 |
section "^+"; |
|
177 |
||
178 |
Goalw [trancl_def] "[| p:r^+; r <= s |] ==> p:s^+"; |
|
179 |
by (blast_tac (claset() addIs [rtrancl_mono RS subsetD]) 1); |
|
180 |
qed "trancl_mono"; |
|
181 |
||
182 |
(** Conversions between trancl and rtrancl **) |
|
183 |
||
184 |
Goalw [trancl_def] |
|
185 |
"!!p. p : r^+ ==> p : r^*"; |
|
186 |
by (split_all_tac 1); |
|
187 |
by (etac compEpair 1); |
|
188 |
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1)); |
|
189 |
qed "trancl_into_rtrancl"; |
|
190 |
||
191 |
(*r^+ contains r*) |
|
192 |
Goalw [trancl_def] |
|
193 |
"!!p. p : r ==> p : r^+"; |
|
194 |
by (split_all_tac 1); |
|
195 |
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1)); |
|
196 |
qed "r_into_trancl"; |
|
197 |
AddIs [r_into_trancl]; |
|
198 |
||
199 |
(*intro rule by definition: from rtrancl and r*) |
|
200 |
Goalw [trancl_def] "[| (a,b) : r^*; (b,c) : r |] ==> (a,c) : r^+"; |
|
201 |
by Auto_tac; |
|
202 |
qed "rtrancl_into_trancl1"; |
|
203 |
||
204 |
(*intro rule from r and rtrancl*) |
|
205 |
Goal "[| (a,b) : r; (b,c) : r^* |] ==> (a,c) : r^+"; |
|
206 |
by (etac rtranclE 1); |
|
207 |
by (blast_tac (claset() addIs [r_into_trancl]) 1); |
|
208 |
by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1); |
|
209 |
by (REPEAT (ares_tac [r_into_rtrancl] 1)); |
|
210 |
qed "rtrancl_into_trancl2"; |
|
211 |
||
212 |
(*Nice induction rule for trancl*) |
|
213 |
val major::prems = Goal |
|
214 |
"[| (a,b) : r^+; \ |
|
215 |
\ !!y. [| (a,y) : r |] ==> P(y); \ |
|
216 |
\ !!y z.[| (a,y) : r^+; (y,z) : r; P(y) |] ==> P(z) \ |
|
217 |
\ |] ==> P(b)"; |
|
218 |
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1); |
|
219 |
(*by induction on this formula*) |
|
220 |
by (subgoal_tac "ALL z. (y,z) : r --> P(z)" 1); |
|
221 |
(*now solve first subgoal: this formula is sufficient*) |
|
222 |
by (Blast_tac 1); |
|
223 |
by (etac rtrancl_induct 1); |
|
224 |
by (ALLGOALS (blast_tac (claset() addIs (rtrancl_into_trancl1::prems)))); |
|
225 |
qed "trancl_induct"; |
|
226 |
||
227 |
(*Another induction rule for trancl, incorporating transitivity.*) |
|
228 |
val major::prems = Goal |
|
229 |
"[| (x,y) : r^+; \ |
|
230 |
\ !!x y. (x,y) : r ==> P x y; \ |
|
231 |
\ !!x y z. [| (x,y) : r^+; P x y; (y,z) : r^+; P y z |] ==> P x z \ |
|
232 |
\ |] ==> P x y"; |
|
233 |
by (blast_tac (claset() addIs ([r_into_trancl,major RS trancl_induct]@prems))1); |
|
234 |
qed "trancl_trans_induct"; |
|
235 |
||
236 |
(*elimination of r^+ -- NOT an induction rule*) |
|
237 |
val major::prems = Goal |
|
238 |
"[| (a::'a,b) : r^+; \ |
|
239 |
\ (a,b) : r ==> P; \ |
|
240 |
\ !!y.[| (a,y) : r^+; (y,b) : r |] ==> P \ |
|
241 |
\ |] ==> P"; |
|
242 |
by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+ & (y,b) : r)" 1); |
|
243 |
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1)); |
|
244 |
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1); |
|
245 |
by (etac rtranclE 1); |
|
246 |
by (Blast_tac 1); |
|
247 |
by (blast_tac (claset() addSIs [rtrancl_into_trancl1]) 1); |
|
248 |
qed "tranclE"; |
|
249 |
||
250 |
(*Transitivity of r^+. |
|
251 |
Proved by unfolding since it uses transitivity of rtrancl. *) |
|
252 |
Goalw [trancl_def] "trans(r^+)"; |
|
253 |
by (rtac transI 1); |
|
254 |
by (REPEAT (etac compEpair 1)); |
|
255 |
by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1); |
|
256 |
by (REPEAT (assume_tac 1)); |
|
257 |
qed "trans_trancl"; |
|
258 |
||
259 |
bind_thm ("trancl_trans", trans_trancl RS transD); |
|
260 |
||
261 |
Goalw [trancl_def] "[| (x,y):r^*; (y,z):r^+ |] ==> (x,z):r^+"; |
|
262 |
by (blast_tac (claset() addIs [rtrancl_trans]) 1); |
|
263 |
qed "rtrancl_trancl_trancl"; |
|
264 |
||
265 |
(* "[| (a,b) : r; (b,c) : r^+ |] ==> (a,c) : r^+" *) |
|
266 |
bind_thm ("trancl_into_trancl2", [trans_trancl, r_into_trancl] MRS transD); |
|
267 |
||
268 |
(* primitive recursion for trancl over finite relations: *) |
|
269 |
Goal "(insert (y,x) r)^+ = r^+ Un {(a,b). (a,y):r^* & (x,b):r^*}"; |
|
270 |
by (rtac equalityI 1); |
|
271 |
by (rtac subsetI 1); |
|
272 |
by (split_all_tac 1); |
|
273 |
by (etac trancl_induct 1); |
|
274 |
by (blast_tac (claset() addIs [r_into_trancl]) 1); |
|
275 |
by (blast_tac (claset() addIs |
|
276 |
[rtrancl_into_trancl1,trancl_into_rtrancl,r_into_trancl,trancl_trans]) 1); |
|
277 |
by (rtac subsetI 1); |
|
278 |
by (blast_tac (claset() addIs |
|
279 |
[rtrancl_into_trancl2, rtrancl_trancl_trancl, |
|
280 |
impOfSubs rtrancl_mono, trancl_mono]) 1); |
|
281 |
qed "trancl_insert"; |
|
282 |
||
283 |
Goalw [trancl_def] "(r^-1)^+ = (r^+)^-1"; |
|
284 |
by (simp_tac (simpset() addsimps [rtrancl_converse,converse_comp]) 1); |
|
285 |
by (simp_tac (simpset() addsimps [rtrancl_converse RS sym, |
|
286 |
r_comp_rtrancl_eq]) 1); |
|
287 |
qed "trancl_converse"; |
|
288 |
||
289 |
Goal "(x,y) : (r^+)^-1 ==> (x,y) : (r^-1)^+"; |
|
290 |
by (asm_full_simp_tac (simpset() addsimps [trancl_converse]) 1); |
|
291 |
qed "trancl_converseI"; |
|
292 |
||
293 |
Goal "(x,y) : (r^-1)^+ ==> (x,y) : (r^+)^-1"; |
|
294 |
by (asm_full_simp_tac (simpset() addsimps [trancl_converse]) 1); |
|
295 |
qed "trancl_converseD"; |
|
296 |
||
297 |
val major::prems = Goal |
|
298 |
"[| (a,b) : r^+; !!y. (y,b) : r ==> P(y); \ |
|
299 |
\ !!y z.[| (y,z) : r; (z,b) : r^+; P(z) |] ==> P(y) |] \ |
|
300 |
\ ==> P(a)"; |
|
301 |
by (rtac ((major RS converseI RS trancl_converseI) RS trancl_induct) 1); |
|
302 |
by (resolve_tac prems 1); |
|
303 |
by (etac converseD 1); |
|
304 |
by (blast_tac (claset() addIs prems addSDs [trancl_converseD])1); |
|
305 |
qed "converse_trancl_induct"; |
|
306 |
||
307 |
Goal "(x,y):R^+ ==> ? z. (x,z):R & (z,y):R^*"; |
|
308 |
be converse_trancl_induct 1; |
|
309 |
by Auto_tac; |
|
310 |
by (blast_tac (claset() addIs [rtrancl_trans]) 1); |
|
311 |
qed "tranclD"; |
|
312 |
||
313 |
(*Unused*) |
|
314 |
Goal "r^-1 Int r^+ = {} ==> (x, x) ~: r^+"; |
|
315 |
by (subgoal_tac "!y. (x, y) : r^+ --> x~=y" 1); |
|
316 |
by (Fast_tac 1); |
|
317 |
by (strip_tac 1); |
|
318 |
by (etac trancl_induct 1); |
|
319 |
by (auto_tac (claset() addIs [r_into_trancl], simpset())); |
|
320 |
qed "irrefl_tranclI"; |
|
321 |
||
322 |
Goal "!!X. [| !x. (x, x) ~: r^+; (x,y) : r |] ==> x ~= y"; |
|
323 |
by (blast_tac (claset() addDs [r_into_trancl]) 1); |
|
324 |
qed "irrefl_trancl_rD"; |
|
325 |
||
326 |
Goal "[| (a,b) : r^*; r <= A <*> A |] ==> a=b | a:A"; |
|
327 |
by (etac rtrancl_induct 1); |
|
328 |
by Auto_tac; |
|
329 |
val lemma = result(); |
|
330 |
||
331 |
Goalw [trancl_def] "r <= A <*> A ==> r^+ <= A <*> A"; |
|
332 |
by (blast_tac (claset() addSDs [lemma]) 1); |
|
333 |
qed "trancl_subset_Sigma"; |