author | clasohm |
Fri, 08 Mar 1996 13:11:09 +0100 | |
changeset 1558 | 9c6ebfab4e05 |
parent 1552 | 6f71b5d46700 |
child 1642 | 21db0cf9a1a4 |
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.*) |
|
1122
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset
|
72 |
goal Trancl.thy "!!r. [| (a,b):r^*; (b,c):r^* |] ==> (a,c):r^*"; |
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset
|
73 |
by (eres_inst_tac [("b","c")] rtrancl_induct 1); |
1552 | 74 |
by (ALLGOALS(fast_tac (HOL_cs addIs [rtrancl_into_rtrancl]))); |
1122
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset
|
75 |
qed "rtrancl_trans"; |
923 | 76 |
|
77 |
(*elimination of rtrancl -- by induction on a special formula*) |
|
78 |
val major::prems = goal Trancl.thy |
|
1465 | 79 |
"[| (a::'a,b) : r^*; (a = b) ==> P; \ |
80 |
\ !!y.[| (a,y) : r^*; (y,b) : r |] ==> P \ |
|
923 | 81 |
\ |] ==> P"; |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
82 |
by (subgoal_tac "(a::'a) = b | (? y. (a,y) : r^* & (y,b) : r)" 1); |
923 | 83 |
by (rtac (major RS rtrancl_induct) 2); |
84 |
by (fast_tac (set_cs addIs prems) 2); |
|
85 |
by (fast_tac (set_cs addIs prems) 2); |
|
86 |
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1)); |
|
87 |
qed "rtranclE"; |
|
88 |
||
1496 | 89 |
goal Trancl.thy "!!R. (y,z):R^* ==> !x. (x,y):R --> (x,z):R^*"; |
1552 | 90 |
by (etac rtrancl_induct 1); |
91 |
by (fast_tac (HOL_cs addIs [r_into_rtrancl]) 1); |
|
92 |
by (fast_tac (HOL_cs addEs [rtrancl_into_rtrancl]) 1); |
|
1496 | 93 |
val lemma = result(); |
94 |
||
95 |
goal Trancl.thy "!!R. [| (x,y) : R; (y,z) : R^* |] ==> (x,z) : R^*"; |
|
1552 | 96 |
by (fast_tac (HOL_cs addDs [lemma]) 1); |
1496 | 97 |
qed "rtrancl_into_rtrancl2"; |
98 |
||
923 | 99 |
|
100 |
(**** The relation trancl ****) |
|
101 |
||
102 |
(** Conversions between trancl and rtrancl **) |
|
103 |
||
104 |
val [major] = goalw Trancl.thy [trancl_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
105 |
"(a,b) : r^+ ==> (a,b) : r^*"; |
923 | 106 |
by (resolve_tac [major RS compEpair] 1); |
107 |
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1)); |
|
108 |
qed "trancl_into_rtrancl"; |
|
109 |
||
110 |
(*r^+ contains r*) |
|
111 |
val [prem] = goalw Trancl.thy [trancl_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
112 |
"[| (a,b) : r |] ==> (a,b) : r^+"; |
923 | 113 |
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1)); |
114 |
qed "r_into_trancl"; |
|
115 |
||
116 |
(*intro rule by definition: from rtrancl and r*) |
|
117 |
val prems = goalw Trancl.thy [trancl_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
118 |
"[| (a,b) : r^*; (b,c) : r |] ==> (a,c) : r^+"; |
923 | 119 |
by (REPEAT (resolve_tac ([compI]@prems) 1)); |
120 |
qed "rtrancl_into_trancl1"; |
|
121 |
||
122 |
(*intro rule from r and rtrancl*) |
|
123 |
val prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
124 |
"[| (a,b) : r; (b,c) : r^* |] ==> (a,c) : r^+"; |
923 | 125 |
by (resolve_tac (prems RL [rtranclE]) 1); |
126 |
by (etac subst 1); |
|
127 |
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
|
128 |
by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1); |
923 | 129 |
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1)); |
130 |
qed "rtrancl_into_trancl2"; |
|
131 |
||
132 |
(*elimination of r^+ -- NOT an induction rule*) |
|
133 |
val major::prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
134 |
"[| (a::'a,b) : r^+; \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
135 |
\ (a,b) : r ==> P; \ |
1465 | 136 |
\ !!y.[| (a,y) : r^+; (y,b) : r |] ==> P \ |
923 | 137 |
\ |] ==> P"; |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
138 |
by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+ & (y,b) : r)" 1); |
923 | 139 |
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1)); |
140 |
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1); |
|
141 |
by (etac rtranclE 1); |
|
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
142 |
by (fast_tac rel_cs 1); |
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
143 |
by (fast_tac (rel_cs addSIs [rtrancl_into_trancl1]) 1); |
923 | 144 |
qed "tranclE"; |
145 |
||
146 |
(*Transitivity of r^+. |
|
147 |
Proved by unfolding since it uses transitivity of rtrancl. *) |
|
148 |
goalw Trancl.thy [trancl_def] "trans(r^+)"; |
|
149 |
by (rtac transI 1); |
|
150 |
by (REPEAT (etac compEpair 1)); |
|
1122
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset
|
151 |
by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1); |
923 | 152 |
by (REPEAT (assume_tac 1)); |
153 |
qed "trans_trancl"; |
|
154 |
||
155 |
val prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
156 |
"[| (a,b) : r; (b,c) : r^+ |] ==> (a,c) : r^+"; |
923 | 157 |
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1); |
158 |
by (resolve_tac prems 1); |
|
159 |
by (resolve_tac prems 1); |
|
160 |
qed "trancl_into_trancl2"; |
|
161 |
||
1130 | 162 |
(** More about r^* **) |
1121 | 163 |
|
164 |
goal Trancl.thy "(r^*)^* = r^*"; |
|
1465 | 165 |
by (rtac set_ext 1); |
1552 | 166 |
by (res_inst_tac [("p","x")] PairE 1); |
167 |
by (hyp_subst_tac 1); |
|
1465 | 168 |
by (rtac iffI 1); |
169 |
by (etac rtrancl_induct 1); |
|
170 |
by (rtac rtrancl_refl 1); |
|
1552 | 171 |
by (fast_tac (HOL_cs addEs [rtrancl_trans]) 1); |
1465 | 172 |
by (etac r_into_rtrancl 1); |
1121 | 173 |
qed "rtrancl_idemp"; |
1301 | 174 |
Addsimps [rtrancl_idemp]; |
923 | 175 |
|
1301 | 176 |
goal Trancl.thy "!!R. [| R <= S; S <= R^* |] ==> S^* = R^*"; |
1465 | 177 |
by (dtac rtrancl_mono 1); |
178 |
by (dtac rtrancl_mono 1); |
|
1552 | 179 |
by (Asm_full_simp_tac 1); |
180 |
by (fast_tac eq_cs 1); |
|
1301 | 181 |
qed "rtrancl_subset"; |
182 |
||
183 |
goal Trancl.thy "!!R. (R^* Un S^*)^* = (R Un S)^*"; |
|
1552 | 184 |
by (best_tac (set_cs addIs [rtrancl_subset,r_into_rtrancl, |
1301 | 185 |
rtrancl_mono RS subsetD]) 1); |
186 |
qed "trancl_Un_trancl"; |
|
187 |
||
188 |
goal Trancl.thy "(R^=)^* = R^*"; |
|
1552 | 189 |
by (fast_tac (rel_cs addIs [rtrancl_refl,rtrancl_subset,r_into_rtrancl]) 1); |
1301 | 190 |
qed "rtrancl_reflcl"; |
191 |
Addsimps [rtrancl_reflcl]; |
|
1130 | 192 |
|
193 |
goal Trancl.thy "!!r. (x,y) : (converse r)^* ==> (x,y) : converse(r^*)"; |
|
1465 | 194 |
by (rtac converseI 1); |
195 |
by (etac rtrancl_induct 1); |
|
196 |
by (rtac rtrancl_refl 1); |
|
1552 | 197 |
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1); |
1130 | 198 |
qed "rtrancl_converseD"; |
199 |
||
200 |
goal Trancl.thy "!!r. (x,y) : converse(r^*) ==> (x,y) : (converse r)^*"; |
|
1465 | 201 |
by (dtac converseD 1); |
202 |
by (etac rtrancl_induct 1); |
|
203 |
by (rtac rtrancl_refl 1); |
|
1552 | 204 |
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1); |
1130 | 205 |
qed "rtrancl_converseI"; |
206 |
||
207 |
goal Trancl.thy "(converse r)^* = converse(r^*)"; |
|
1552 | 208 |
by (safe_tac (rel_eq_cs addSIs [rtrancl_converseI])); |
209 |
by (res_inst_tac [("p","x")] PairE 1); |
|
210 |
by (hyp_subst_tac 1); |
|
1465 | 211 |
by (etac rtrancl_converseD 1); |
1130 | 212 |
qed "rtrancl_converse"; |
213 |
||
214 |
||
923 | 215 |
val major::prems = goal Trancl.thy |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
216 |
"[| (a,b) : r^*; r <= Sigma A (%x.A) |] ==> a=b | a:A"; |
923 | 217 |
by (cut_facts_tac prems 1); |
218 |
by (rtac (major RS rtrancl_induct) 1); |
|
219 |
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
|
220 |
by (fast_tac (rel_cs addSEs [SigmaE2]) 1); |
923 | 221 |
qed "trancl_subset_Sigma_lemma"; |
222 |
||
223 |
goalw Trancl.thy [trancl_def] |
|
224 |
"!!r. r <= Sigma A (%x.A) ==> trancl(r) <= Sigma A (%x.A)"; |
|
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
225 |
by (fast_tac (rel_cs addSDs [trancl_subset_Sigma_lemma]) 1); |
923 | 226 |
qed "trancl_subset_Sigma"; |
1130 | 227 |
|
1301 | 228 |
(* Don't add r_into_rtrancl: it messes up the proofs in Lambda *) |
1130 | 229 |
val trancl_cs = rel_cs addIs [rtrancl_refl]; |