author  nipkow 
Tue, 30 Apr 1996 17:30:54 +0200  
changeset 1706  4e0d5c7f57fa 
parent 1642  21db0cf9a1a4 
child 1746  f0c6aabc6c02 
permissions  rwrr 
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 

1706
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

71 
val prems = goal Trancl.thy 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

72 
"[ ((a,b),(c,d)) : r^*; P a b; \ 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

73 
\ !!x y z u.[ ((a,b),(x,y)) : r^*; ((x,y),(z,u)) : r; P x y ] ==> P z u\ 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

74 
\ ] ==> P c d"; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

75 
by(res_inst_tac[("R","P")]splitD 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

76 
by(res_inst_tac[("P","split P")]rtrancl_induct 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

77 
brs prems 1; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

78 
by(Simp_tac 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

79 
brs prems 1; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

80 
by(split_all_tac 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

81 
by(Asm_full_simp_tac 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

82 
by(REPEAT(ares_tac prems 1)); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

83 
qed "rtrancl_induct2"; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

84 

923  85 
(*transitivity of transitive closure!!  by induction.*) 
1642  86 
goalw Trancl.thy [trans_def] "trans(r^*)"; 
87 
by (safe_tac HOL_cs); 

88 
by (eres_inst_tac [("b","z")] rtrancl_induct 1); 

1552  89 
by (ALLGOALS(fast_tac (HOL_cs addIs [rtrancl_into_rtrancl]))); 
1642  90 
qed "trans_rtrancl"; 
91 

92 
bind_thm ("rtrancl_trans", trans_rtrancl RS transD); 

93 

923  94 

95 
(*elimination of rtrancl  by induction on a special formula*) 

96 
val major::prems = goal Trancl.thy 

1465  97 
"[ (a::'a,b) : r^*; (a = b) ==> P; \ 
98 
\ !!y.[ (a,y) : r^*; (y,b) : r ] ==> P \ 

923  99 
\ ] ==> P"; 
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset

100 
by (subgoal_tac "(a::'a) = b  (? y. (a,y) : r^* & (y,b) : r)" 1); 
923  101 
by (rtac (major RS rtrancl_induct) 2); 
102 
by (fast_tac (set_cs addIs prems) 2); 

103 
by (fast_tac (set_cs addIs prems) 2); 

104 
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1)); 

105 
qed "rtranclE"; 

106 

1642  107 
bind_thm ("rtrancl_into_rtrancl2", r_into_rtrancl RS rtrancl_trans); 
108 

109 

110 
(*** More r^* equations and inclusions ***) 

111 

112 
goal Trancl.thy "(r^*)^* = r^*"; 

113 
by (rtac set_ext 1); 

114 
by (res_inst_tac [("p","x")] PairE 1); 

115 
by (hyp_subst_tac 1); 

116 
by (rtac iffI 1); 

1552  117 
by (etac rtrancl_induct 1); 
1642  118 
by (rtac rtrancl_refl 1); 
119 
by (fast_tac (HOL_cs addEs [rtrancl_trans]) 1); 

120 
by (etac r_into_rtrancl 1); 

121 
qed "rtrancl_idemp"; 

122 
Addsimps [rtrancl_idemp]; 

123 

124 
goal Trancl.thy "!!r s. r <= s^* ==> r^* <= s^*"; 

125 
bd rtrancl_mono 1; 

126 
by (Asm_full_simp_tac 1); 

127 
qed "rtrancl_subset_rtrancl"; 

128 

129 
goal Trancl.thy "!!R. [ R <= S; S <= R^* ] ==> S^* = R^*"; 

130 
by (dtac rtrancl_mono 1); 

131 
by (dtac rtrancl_mono 1); 

132 
by (Asm_full_simp_tac 1); 

133 
by (fast_tac eq_cs 1); 

134 
qed "rtrancl_subset"; 

135 

136 
goal Trancl.thy "!!R. (R^* Un S^*)^* = (R Un S)^*"; 

137 
by (best_tac (set_cs addIs [rtrancl_subset,r_into_rtrancl, 

138 
rtrancl_mono RS subsetD]) 1); 

139 
qed "rtrancl_Un_rtrancl"; 

1496  140 

1642  141 
goal Trancl.thy "(R^=)^* = R^*"; 
142 
by (fast_tac (rel_cs addIs [rtrancl_refl,rtrancl_subset,r_into_rtrancl]) 1); 

143 
qed "rtrancl_reflcl"; 

144 
Addsimps [rtrancl_reflcl]; 

145 

146 
goal Trancl.thy "!!r. (x,y) : (converse r)^* ==> (x,y) : converse(r^*)"; 

147 
by (rtac converseI 1); 

148 
by (etac rtrancl_induct 1); 

149 
by (rtac rtrancl_refl 1); 

150 
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1); 

151 
qed "rtrancl_converseD"; 

152 

153 
goal Trancl.thy "!!r. (x,y) : converse(r^*) ==> (x,y) : (converse r)^*"; 

154 
by (dtac converseD 1); 

155 
by (etac rtrancl_induct 1); 

156 
by (rtac rtrancl_refl 1); 

157 
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1); 

158 
qed "rtrancl_converseI"; 

159 

160 
goal Trancl.thy "(converse r)^* = converse(r^*)"; 

161 
by (safe_tac (rel_eq_cs addSIs [rtrancl_converseI])); 

162 
by (res_inst_tac [("p","x")] PairE 1); 

163 
by (hyp_subst_tac 1); 

164 
by (etac rtrancl_converseD 1); 

165 
qed "rtrancl_converse"; 

166 

1706
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

167 
val major::prems = goal Trancl.thy 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

168 
"[ (a,b) : r^*; P(b); \ 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

169 
\ !!y z.[ (y,z) : r; (z,b) : r^*; P(z) ] ==> P(y) ] \ 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

170 
\ ==> P(a)"; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

171 
br ((major RS converseI RS rtrancl_converseI) RS rtrancl_induct) 1; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

172 
brs prems 1; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

173 
by(fast_tac (HOL_cs addIs prems addSEs[converseD]addSDs[rtrancl_converseD])1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

174 
qed "converse_rtrancl_induct"; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

175 

4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

176 
val prems = goal Trancl.thy 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

177 
"[ ((a,b),(c,d)) : r^*; P c d; \ 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

178 
\ !!x y z u.[ ((x,y),(z,u)) : r; ((z,u),(c,d)) : r^*; P z u ] ==> P x y\ 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

179 
\ ] ==> P a b"; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

180 
by(res_inst_tac[("R","P")]splitD 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

181 
by(res_inst_tac[("P","split P")]converse_rtrancl_induct 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

182 
brs prems 1; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

183 
by(Simp_tac 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

184 
brs prems 1; 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

185 
by(split_all_tac 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

186 
by(Asm_full_simp_tac 1); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

187 
by(REPEAT(ares_tac prems 1)); 
4e0d5c7f57fa
Added backwards rtrancl_induct and special versions for pairs.
nipkow
parents:
1642
diff
changeset

188 
qed "converse_rtrancl_induct2"; 
1496  189 

923  190 

191 
(**** The relation trancl ****) 

192 

193 
(** Conversions between trancl and rtrancl **) 

194 

195 
val [major] = goalw Trancl.thy [trancl_def] 

972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset

196 
"(a,b) : r^+ ==> (a,b) : r^*"; 
923  197 
by (resolve_tac [major RS compEpair] 1); 
198 
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1)); 

199 
qed "trancl_into_rtrancl"; 

200 

201 
(*r^+ contains r*) 

202 
val [prem] = goalw Trancl.thy [trancl_def] 

972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset

203 
"[ (a,b) : r ] ==> (a,b) : r^+"; 
923  204 
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1)); 
205 
qed "r_into_trancl"; 

206 

207 
(*intro rule by definition: from rtrancl and r*) 

208 
val prems = goalw Trancl.thy [trancl_def] 

972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset

209 
"[ (a,b) : r^*; (b,c) : r ] ==> (a,c) : r^+"; 
923  210 
by (REPEAT (resolve_tac ([compI]@prems) 1)); 
211 
qed "rtrancl_into_trancl1"; 

212 

213 
(*intro rule from r and rtrancl*) 

214 
val prems = goal Trancl.thy 

972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset

215 
"[ (a,b) : r; (b,c) : r^* ] ==> (a,c) : r^+"; 
923  216 
by (resolve_tac (prems RL [rtranclE]) 1); 
217 
by (etac subst 1); 

218 
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

219 
by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1); 
923  220 
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1)); 
221 
qed "rtrancl_into_trancl2"; 

222 

1642  223 
(*Nice induction rule for trancl*) 
224 
val major::prems = goal Trancl.thy 

225 
"[ (a,b) : r^+; \ 

226 
\ !!y. [ (a,y) : r ] ==> P(y); \ 

227 
\ !!y z.[ (a,y) : r^+; (y,z) : r; P(y) ] ==> P(z) \ 

228 
\ ] ==> P(b)"; 

229 
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1); 

230 
(*by induction on this formula*) 

231 
by (subgoal_tac "ALL z. (y,z) : r > P(z)" 1); 

232 
(*now solve first subgoal: this formula is sufficient*) 

233 
by (fast_tac HOL_cs 1); 

234 
by (etac rtrancl_induct 1); 

235 
by (ALLGOALS (fast_tac (set_cs addIs (rtrancl_into_trancl1::prems)))); 

236 
qed "trancl_induct"; 

237 

923  238 
(*elimination of r^+  NOT an induction rule*) 
239 
val major::prems = goal Trancl.thy 

972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset

240 
"[ (a::'a,b) : r^+; \ 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset

241 
\ (a,b) : r ==> P; \ 
1465  242 
\ !!y.[ (a,y) : r^+; (y,b) : r ] ==> P \ 
923  243 
\ ] ==> P"; 
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset

244 
by (subgoal_tac "(a::'a,b) : r  (? y. (a,y) : r^+ & (y,b) : r)" 1); 
923  245 
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1)); 
246 
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1); 

247 
by (etac rtranclE 1); 

1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset

248 
by (fast_tac rel_cs 1); 
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
1122
diff
changeset

249 
by (fast_tac (rel_cs addSIs [rtrancl_into_trancl1]) 1); 
923  250 
qed "tranclE"; 
251 

252 
(*Transitivity of r^+. 

253 
Proved by unfolding since it uses transitivity of rtrancl. *) 

254 
goalw Trancl.thy [trancl_def] "trans(r^+)"; 

255 
by (rtac transI 1); 

256 
by (REPEAT (etac compEpair 1)); 

1122
20b708827030
renamed trans_rtrancl to rtrancl_trans and modified it by expanding trans.
nipkow
parents:
1121
diff
changeset

257 
by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1); 
923  258 
by (REPEAT (assume_tac 1)); 
259 
qed "trans_trancl"; 

260 

1642  261 
bind_thm ("trancl_trans", trans_trancl RS transD); 
262 

923  263 
val prems = goal Trancl.thy 
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset

264 
"[ (a,b) : r; (b,c) : r^+ ] ==> (a,c) : r^+"; 
923  265 
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1); 
266 
by (resolve_tac prems 1); 

267 
by (resolve_tac prems 1); 

268 
qed "trancl_into_trancl2"; 

269 

1130  270 

923  271 
val major::prems = goal Trancl.thy 
1642  272 
"[ (a,b) : r^*; r <= A Times A ] ==> a=b  a:A"; 
923  273 
by (cut_facts_tac prems 1); 
274 
by (rtac (major RS rtrancl_induct) 1); 

275 
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

276 
by (fast_tac (rel_cs addSEs [SigmaE2]) 1); 
1642  277 
val lemma = result(); 
923  278 

279 
goalw Trancl.thy [trancl_def] 

1642  280 
"!!r. r <= A Times A ==> r^+ <= A Times A"; 
281 
by (fast_tac (rel_cs addSDs [lemma]) 1); 

923  282 
qed "trancl_subset_Sigma"; 
1130  283 

1301  284 
(* Don't add r_into_rtrancl: it messes up the proofs in Lambda *) 
1130  285 
val trancl_cs = rel_cs addIs [rtrancl_refl]; 
1642  286 

287 