author | nipkow |
Sun, 28 May 1995 17:17:43 +0200 | |
changeset 1130 | 0df0df1685a8 |
parent 1128 | 64b30e3cc6d4 |
child 1301 | 42782316d510 |
permissions | -rw-r--r-- |
923 | 1 |
(* Title: HOL/trancl |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
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*) |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
34 |
val [prem] = goal Trancl.thy "[| (a,b) : r |] ==> (a,b) : r^*"; |
923 | 35 |
by (rtac (rtrancl_refl RS rtrancl_into_rtrancl) 1); |
36 |
by (rtac prem 1); |
|
37 |
qed "r_into_rtrancl"; |
|
38 |
||
39 |
(*monotonicity of rtrancl*) |
|
40 |
goalw Trancl.thy [rtrancl_def] "!!r s. r <= s ==> r^* <= s^*"; |
|
41 |
by(REPEAT(ares_tac [lfp_mono,Un_mono,comp_mono,subset_refl] 1)); |
|
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); \ |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
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); |
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset
|
74 |
by(ALLGOALS(fast_tac (HOL_cs addIs [rtrancl_into_rtrancl]))); |
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 |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
79 |
"[| (a::'a,b) : r^*; (a = b) ==> P; \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
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 |
||
89 |
||
90 |
(**** The relation trancl ****) |
|
91 |
||
92 |
(** Conversions between trancl and rtrancl **) |
|
93 |
||
94 |
val [major] = goalw Trancl.thy [trancl_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
95 |
"(a,b) : r^+ ==> (a,b) : r^*"; |
923 | 96 |
by (resolve_tac [major RS compEpair] 1); |
97 |
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1)); |
|
98 |
qed "trancl_into_rtrancl"; |
|
99 |
||
100 |
(*r^+ contains r*) |
|
101 |
val [prem] = goalw Trancl.thy [trancl_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
102 |
"[| (a,b) : r |] ==> (a,b) : r^+"; |
923 | 103 |
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1)); |
104 |
qed "r_into_trancl"; |
|
105 |
||
106 |
(*intro rule by definition: from rtrancl and r*) |
|
107 |
val prems = goalw Trancl.thy [trancl_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
108 |
"[| (a,b) : r^*; (b,c) : r |] ==> (a,c) : r^+"; |
923 | 109 |
by (REPEAT (resolve_tac ([compI]@prems) 1)); |
110 |
qed "rtrancl_into_trancl1"; |
|
111 |
||
112 |
(*intro rule from r and rtrancl*) |
|
113 |
val prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
114 |
"[| (a,b) : r; (b,c) : r^* |] ==> (a,c) : r^+"; |
923 | 115 |
by (resolve_tac (prems RL [rtranclE]) 1); |
116 |
by (etac subst 1); |
|
117 |
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
|
118 |
by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1); |
923 | 119 |
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1)); |
120 |
qed "rtrancl_into_trancl2"; |
|
121 |
||
122 |
(*elimination of r^+ -- NOT an induction rule*) |
|
123 |
val major::prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
124 |
"[| (a::'a,b) : r^+; \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
125 |
\ (a,b) : r ==> P; \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
126 |
\ !!y.[| (a,y) : r^+; (y,b) : r |] ==> P \ |
923 | 127 |
\ |] ==> P"; |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
128 |
by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+ & (y,b) : r)" 1); |
923 | 129 |
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1)); |
130 |
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1); |
|
131 |
by (etac rtranclE 1); |
|
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
132 |
by (fast_tac rel_cs 1); |
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset
|
133 |
by (fast_tac (rel_cs addSIs [rtrancl_into_trancl1]) 1); |
923 | 134 |
qed "tranclE"; |
135 |
||
136 |
(*Transitivity of r^+. |
|
137 |
Proved by unfolding since it uses transitivity of rtrancl. *) |
|
138 |
goalw Trancl.thy [trancl_def] "trans(r^+)"; |
|
139 |
by (rtac transI 1); |
|
140 |
by (REPEAT (etac compEpair 1)); |
|
1122
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset
|
141 |
by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1); |
923 | 142 |
by (REPEAT (assume_tac 1)); |
143 |
qed "trans_trancl"; |
|
144 |
||
145 |
val prems = goal Trancl.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
146 |
"[| (a,b) : r; (b,c) : r^+ |] ==> (a,c) : r^+"; |
923 | 147 |
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1); |
148 |
by (resolve_tac prems 1); |
|
149 |
by (resolve_tac prems 1); |
|
150 |
qed "trancl_into_trancl2"; |
|
151 |
||
1130 | 152 |
(** More about r^* **) |
1121 | 153 |
|
154 |
goal Trancl.thy "(r^*)^* = r^*"; |
|
155 |
br set_ext 1; |
|
156 |
by(res_inst_tac [("p","x")] PairE 1); |
|
157 |
by(hyp_subst_tac 1); |
|
158 |
br iffI 1; |
|
159 |
be rtrancl_induct 1; |
|
160 |
br rtrancl_refl 1; |
|
1122
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset
|
161 |
by(fast_tac (HOL_cs addEs [rtrancl_trans]) 1); |
1121 | 162 |
be r_into_rtrancl 1; |
163 |
qed "rtrancl_idemp"; |
|
923 | 164 |
|
1130 | 165 |
|
166 |
goal Trancl.thy "!!r. (x,y) : (converse r)^* ==> (x,y) : converse(r^*)"; |
|
167 |
br converseI 1; |
|
168 |
be rtrancl_induct 1; |
|
169 |
br rtrancl_refl 1; |
|
170 |
by(fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1); |
|
171 |
qed "rtrancl_converseD"; |
|
172 |
||
173 |
goal Trancl.thy "!!r. (x,y) : converse(r^*) ==> (x,y) : (converse r)^*"; |
|
174 |
bd converseD 1; |
|
175 |
be rtrancl_induct 1; |
|
176 |
br rtrancl_refl 1; |
|
177 |
by(fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1); |
|
178 |
qed "rtrancl_converseI"; |
|
179 |
||
180 |
goal Trancl.thy "(converse r)^* = converse(r^*)"; |
|
181 |
by(safe_tac (rel_eq_cs addSIs [rtrancl_converseI])); |
|
182 |
by(res_inst_tac [("p","x")] PairE 1); |
|
183 |
by(hyp_subst_tac 1); |
|
184 |
be rtrancl_converseD 1; |
|
185 |
qed "rtrancl_converse"; |
|
186 |
||
187 |
||
923 | 188 |
val major::prems = goal Trancl.thy |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
189 |
"[| (a,b) : r^*; r <= Sigma A (%x.A) |] ==> a=b | a:A"; |
923 | 190 |
by (cut_facts_tac prems 1); |
191 |
by (rtac (major RS rtrancl_induct) 1); |
|
192 |
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
|
193 |
by (fast_tac (rel_cs addSEs [SigmaE2]) 1); |
923 | 194 |
qed "trancl_subset_Sigma_lemma"; |
195 |
||
196 |
goalw Trancl.thy [trancl_def] |
|
197 |
"!!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
|
198 |
by (fast_tac (rel_cs addSDs [trancl_subset_Sigma_lemma]) 1); |
923 | 199 |
qed "trancl_subset_Sigma"; |
1130 | 200 |
|
201 |
val trancl_cs = rel_cs addIs [rtrancl_refl]; |