author | nipkow |
Sat, 27 Apr 1996 18:51:42 +0200 | |
changeset 1699 | 0bcc8cab3461 |
parent 1642 | 21db0cf9a1a4 |
child 1706 | 4e0d5c7f57fa |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/trancl |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
923 | 4 |
Copyright 1992 University of Cambridge |
5 |
||
6 |
For trancl.thy. Theorems about the transitive closure of a relation |
|
7 |
*) |
|
8 |
||
9 |
open Trancl; |
|
10 |
||
11 |
(** The relation rtrancl **) |
|
12 |
||
13 |
goal Trancl.thy "mono(%s. id Un (r O s))"; |
|
14 |
by (rtac monoI 1); |
|
15 |
by (REPEAT (ares_tac [monoI, subset_refl, comp_mono, Un_mono] 1)); |
|
16 |
qed "rtrancl_fun_mono"; |
|
17 |
||
18 |
val rtrancl_unfold = rtrancl_fun_mono RS (rtrancl_def RS def_lfp_Tarski); |
|
19 |
||
20 |
(*Reflexivity of rtrancl*) |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
21 |
goal Trancl.thy "(a,a) : r^*"; |
923 | 22 |
by (stac rtrancl_unfold 1); |
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
23 |
by (fast_tac rel_cs 1); |
923 | 24 |
qed "rtrancl_refl"; |
25 |
||
26 |
(*Closure under composition with r*) |
|
27 |
val prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
28 |
"[| (a,b) : r^*; (b,c) : r |] ==> (a,c) : r^*"; |
923 | 29 |
by (stac rtrancl_unfold 1); |
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
30 |
by (fast_tac (rel_cs addIs prems) 1); |
923 | 31 |
qed "rtrancl_into_rtrancl"; |
32 |
||
33 |
(*rtrancl of r contains r*) |
|
1301 | 34 |
goal Trancl.thy "!!p. p : r ==> p : r^*"; |
1552 | 35 |
by (split_all_tac 1); |
1301 | 36 |
by (etac (rtrancl_refl RS rtrancl_into_rtrancl) 1); |
923 | 37 |
qed "r_into_rtrancl"; |
38 |
||
39 |
(*monotonicity of rtrancl*) |
|
40 |
goalw Trancl.thy [rtrancl_def] "!!r s. r <= s ==> r^* <= s^*"; |
|
1552 | 41 |
by (REPEAT(ares_tac [lfp_mono,Un_mono,comp_mono,subset_refl] 1)); |
923 | 42 |
qed "rtrancl_mono"; |
43 |
||
44 |
(** standard induction rule **) |
|
45 |
||
46 |
val major::prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
47 |
"[| (a,b) : r^*; \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
48 |
\ !!x. P((x,x)); \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
49 |
\ !!x y z.[| P((x,y)); (x,y): r^*; (y,z): r |] ==> P((x,z)) |] \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
50 |
\ ==> P((a,b))"; |
923 | 51 |
by (rtac ([rtrancl_def, rtrancl_fun_mono, major] MRS def_induct) 1); |
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
52 |
by (fast_tac (rel_cs addIs prems) 1); |
923 | 53 |
qed "rtrancl_full_induct"; |
54 |
||
55 |
(*nice induction rule*) |
|
56 |
val major::prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
57 |
"[| (a::'a,b) : r^*; \ |
923 | 58 |
\ P(a); \ |
1465 | 59 |
\ !!y z.[| (a,y) : r^*; (y,z) : r; P(y) |] ==> P(z) |] \ |
923 | 60 |
\ ==> P(b)"; |
61 |
(*by induction on this formula*) |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
62 |
by (subgoal_tac "! y. (a::'a,b) = (a,y) --> P(y)" 1); |
923 | 63 |
(*now solve first subgoal: this formula is sufficient*) |
64 |
by (fast_tac HOL_cs 1); |
|
65 |
(*now do the induction*) |
|
66 |
by (resolve_tac [major RS rtrancl_full_induct] 1); |
|
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
67 |
by (fast_tac (rel_cs addIs prems) 1); |
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
68 |
by (fast_tac (rel_cs addIs prems) 1); |
923 | 69 |
qed "rtrancl_induct"; |
70 |
||
71 |
(*transitivity of transitive closure!! -- by induction.*) |
|
1642 | 72 |
goalw Trancl.thy [trans_def] "trans(r^*)"; |
73 |
by (safe_tac HOL_cs); |
|
74 |
by (eres_inst_tac [("b","z")] rtrancl_induct 1); |
|
1552 | 75 |
by (ALLGOALS(fast_tac (HOL_cs addIs [rtrancl_into_rtrancl]))); |
1642 | 76 |
qed "trans_rtrancl"; |
77 |
||
78 |
bind_thm ("rtrancl_trans", trans_rtrancl RS transD); |
|
79 |
||
923 | 80 |
|
81 |
(*elimination of rtrancl -- by induction on a special formula*) |
|
82 |
val major::prems = goal Trancl.thy |
|
1465 | 83 |
"[| (a::'a,b) : r^*; (a = b) ==> P; \ |
84 |
\ !!y.[| (a,y) : r^*; (y,b) : r |] ==> P \ |
|
923 | 85 |
\ |] ==> P"; |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
86 |
by (subgoal_tac "(a::'a) = b | (? y. (a,y) : r^* & (y,b) : r)" 1); |
923 | 87 |
by (rtac (major RS rtrancl_induct) 2); |
88 |
by (fast_tac (set_cs addIs prems) 2); |
|
89 |
by (fast_tac (set_cs addIs prems) 2); |
|
90 |
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1)); |
|
91 |
qed "rtranclE"; |
|
92 |
||
1642 | 93 |
bind_thm ("rtrancl_into_rtrancl2", r_into_rtrancl RS rtrancl_trans); |
94 |
||
95 |
||
96 |
(*** More r^* equations and inclusions ***) |
|
97 |
||
98 |
goal Trancl.thy "(r^*)^* = r^*"; |
|
99 |
by (rtac set_ext 1); |
|
100 |
by (res_inst_tac [("p","x")] PairE 1); |
|
101 |
by (hyp_subst_tac 1); |
|
102 |
by (rtac iffI 1); |
|
1552 | 103 |
by (etac rtrancl_induct 1); |
1642 | 104 |
by (rtac rtrancl_refl 1); |
105 |
by (fast_tac (HOL_cs addEs [rtrancl_trans]) 1); |
|
106 |
by (etac r_into_rtrancl 1); |
|
107 |
qed "rtrancl_idemp"; |
|
108 |
Addsimps [rtrancl_idemp]; |
|
109 |
||
110 |
goal Trancl.thy "!!r s. r <= s^* ==> r^* <= s^*"; |
|
111 |
bd rtrancl_mono 1; |
|
112 |
by (Asm_full_simp_tac 1); |
|
113 |
qed "rtrancl_subset_rtrancl"; |
|
114 |
||
115 |
goal Trancl.thy "!!R. [| R <= S; S <= R^* |] ==> S^* = R^*"; |
|
116 |
by (dtac rtrancl_mono 1); |
|
117 |
by (dtac rtrancl_mono 1); |
|
118 |
by (Asm_full_simp_tac 1); |
|
119 |
by (fast_tac eq_cs 1); |
|
120 |
qed "rtrancl_subset"; |
|
121 |
||
122 |
goal Trancl.thy "!!R. (R^* Un S^*)^* = (R Un S)^*"; |
|
123 |
by (best_tac (set_cs addIs [rtrancl_subset,r_into_rtrancl, |
|
124 |
rtrancl_mono RS subsetD]) 1); |
|
125 |
qed "rtrancl_Un_rtrancl"; |
|
1496 | 126 |
|
1642 | 127 |
goal Trancl.thy "(R^=)^* = R^*"; |
128 |
by (fast_tac (rel_cs addIs [rtrancl_refl,rtrancl_subset,r_into_rtrancl]) 1); |
|
129 |
qed "rtrancl_reflcl"; |
|
130 |
Addsimps [rtrancl_reflcl]; |
|
131 |
||
132 |
goal Trancl.thy "!!r. (x,y) : (converse r)^* ==> (x,y) : converse(r^*)"; |
|
133 |
by (rtac converseI 1); |
|
134 |
by (etac rtrancl_induct 1); |
|
135 |
by (rtac rtrancl_refl 1); |
|
136 |
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1); |
|
137 |
qed "rtrancl_converseD"; |
|
138 |
||
139 |
goal Trancl.thy "!!r. (x,y) : converse(r^*) ==> (x,y) : (converse r)^*"; |
|
140 |
by (dtac converseD 1); |
|
141 |
by (etac rtrancl_induct 1); |
|
142 |
by (rtac rtrancl_refl 1); |
|
143 |
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1); |
|
144 |
qed "rtrancl_converseI"; |
|
145 |
||
146 |
goal Trancl.thy "(converse r)^* = converse(r^*)"; |
|
147 |
by (safe_tac (rel_eq_cs addSIs [rtrancl_converseI])); |
|
148 |
by (res_inst_tac [("p","x")] PairE 1); |
|
149 |
by (hyp_subst_tac 1); |
|
150 |
by (etac rtrancl_converseD 1); |
|
151 |
qed "rtrancl_converse"; |
|
152 |
||
1496 | 153 |
|
923 | 154 |
|
155 |
(**** The relation trancl ****) |
|
156 |
||
157 |
(** Conversions between trancl and rtrancl **) |
|
158 |
||
159 |
val [major] = goalw Trancl.thy [trancl_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
160 |
"(a,b) : r^+ ==> (a,b) : r^*"; |
923 | 161 |
by (resolve_tac [major RS compEpair] 1); |
162 |
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1)); |
|
163 |
qed "trancl_into_rtrancl"; |
|
164 |
||
165 |
(*r^+ contains r*) |
|
166 |
val [prem] = goalw Trancl.thy [trancl_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
167 |
"[| (a,b) : r |] ==> (a,b) : r^+"; |
923 | 168 |
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1)); |
169 |
qed "r_into_trancl"; |
|
170 |
||
171 |
(*intro rule by definition: from rtrancl and r*) |
|
172 |
val prems = goalw Trancl.thy [trancl_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
173 |
"[| (a,b) : r^*; (b,c) : r |] ==> (a,c) : r^+"; |
923 | 174 |
by (REPEAT (resolve_tac ([compI]@prems) 1)); |
175 |
qed "rtrancl_into_trancl1"; |
|
176 |
||
177 |
(*intro rule from r and rtrancl*) |
|
178 |
val prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
179 |
"[| (a,b) : r; (b,c) : r^* |] ==> (a,c) : r^+"; |
923 | 180 |
by (resolve_tac (prems RL [rtranclE]) 1); |
181 |
by (etac subst 1); |
|
182 |
by (resolve_tac (prems RL [r_into_trancl]) 1); |
|
1122
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset
|
183 |
by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1); |
923 | 184 |
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1)); |
185 |
qed "rtrancl_into_trancl2"; |
|
186 |
||
1642 | 187 |
(*Nice induction rule for trancl*) |
188 |
val major::prems = goal Trancl.thy |
|
189 |
"[| (a,b) : r^+; \ |
|
190 |
\ !!y. [| (a,y) : r |] ==> P(y); \ |
|
191 |
\ !!y z.[| (a,y) : r^+; (y,z) : r; P(y) |] ==> P(z) \ |
|
192 |
\ |] ==> P(b)"; |
|
193 |
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1); |
|
194 |
(*by induction on this formula*) |
|
195 |
by (subgoal_tac "ALL z. (y,z) : r --> P(z)" 1); |
|
196 |
(*now solve first subgoal: this formula is sufficient*) |
|
197 |
by (fast_tac HOL_cs 1); |
|
198 |
by (etac rtrancl_induct 1); |
|
199 |
by (ALLGOALS (fast_tac (set_cs addIs (rtrancl_into_trancl1::prems)))); |
|
200 |
qed "trancl_induct"; |
|
201 |
||
923 | 202 |
(*elimination of r^+ -- NOT an induction rule*) |
203 |
val major::prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
204 |
"[| (a::'a,b) : r^+; \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
205 |
\ (a,b) : r ==> P; \ |
1465 | 206 |
\ !!y.[| (a,y) : r^+; (y,b) : r |] ==> P \ |
923 | 207 |
\ |] ==> P"; |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
208 |
by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+ & (y,b) : r)" 1); |
923 | 209 |
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1)); |
210 |
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1); |
|
211 |
by (etac rtranclE 1); |
|
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
212 |
by (fast_tac rel_cs 1); |
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
213 |
by (fast_tac (rel_cs addSIs [rtrancl_into_trancl1]) 1); |
923 | 214 |
qed "tranclE"; |
215 |
||
216 |
(*Transitivity of r^+. |
|
217 |
Proved by unfolding since it uses transitivity of rtrancl. *) |
|
218 |
goalw Trancl.thy [trancl_def] "trans(r^+)"; |
|
219 |
by (rtac transI 1); |
|
220 |
by (REPEAT (etac compEpair 1)); |
|
1122
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset
|
221 |
by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1); |
923 | 222 |
by (REPEAT (assume_tac 1)); |
223 |
qed "trans_trancl"; |
|
224 |
||
1642 | 225 |
bind_thm ("trancl_trans", trans_trancl RS transD); |
226 |
||
923 | 227 |
val prems = goal Trancl.thy |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
228 |
"[| (a,b) : r; (b,c) : r^+ |] ==> (a,c) : r^+"; |
923 | 229 |
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1); |
230 |
by (resolve_tac prems 1); |
|
231 |
by (resolve_tac prems 1); |
|
232 |
qed "trancl_into_trancl2"; |
|
233 |
||
1130 | 234 |
|
923 | 235 |
val major::prems = goal Trancl.thy |
1642 | 236 |
"[| (a,b) : r^*; r <= A Times A |] ==> a=b | a:A"; |
923 | 237 |
by (cut_facts_tac prems 1); |
238 |
by (rtac (major RS rtrancl_induct) 1); |
|
239 |
by (rtac (refl RS disjI1) 1); |
|
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
240 |
by (fast_tac (rel_cs addSEs [SigmaE2]) 1); |
1642 | 241 |
val lemma = result(); |
923 | 242 |
|
243 |
goalw Trancl.thy [trancl_def] |
|
1642 | 244 |
"!!r. r <= A Times A ==> r^+ <= A Times A"; |
245 |
by (fast_tac (rel_cs addSDs [lemma]) 1); |
|
923 | 246 |
qed "trancl_subset_Sigma"; |
1130 | 247 |
|
1301 | 248 |
(* Don't add r_into_rtrancl: it messes up the proofs in Lambda *) |
1130 | 249 |
val trancl_cs = rel_cs addIs [rtrancl_refl]; |
1642 | 250 |
|
251 |