author  nipkow 
Thu, 22 Sep 2005 23:56:15 +0200  
changeset 17589  58eeffd73be1 
parent 15177  e7616269fdca 
child 19228  30fce6da8cbe 
permissions  rwrr 
10358  1 
(* Title: HOL/Relation.thy 
1128
64b30e3cc6d4
Trancl is now based on Relation which used to be in Integ.
nipkow
parents:
diff
changeset

2 
ID: $Id$ 
1983  3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 
4 
Copyright 1996 University of Cambridge 

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

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

6 

12905  7 
header {* Relations *} 
8 

15131  9 
theory Relation 
15140  10 
imports Product_Type 
15131  11 
begin 
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset

12 

12913  13 
subsection {* Definitions *} 
14 

5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset

15 
constdefs 
10358  16 
converse :: "('a * 'b) set => ('b * 'a) set" ("(_^1)" [1000] 999) 
17 
"r^1 == {(y, x). (x, y) : r}" 

18 
syntax (xsymbols) 

12905  19 
converse :: "('a * 'b) set => ('b * 'a) set" ("(_\<inverse>)" [1000] 999) 
7912  20 

10358  21 
constdefs 
12487  22 
rel_comp :: "[('b * 'c) set, ('a * 'b) set] => ('a * 'c) set" (infixr "O" 60) 
12913  23 
"r O s == {(x,z). EX y. (x, y) : s & (y, z) : r}" 
24 

11136  25 
Image :: "[('a * 'b) set, 'a set] => 'b set" (infixl "``" 90) 
12913  26 
"r `` s == {y. EX x:s. (x,y):r}" 
7912  27 

12905  28 
Id :: "('a * 'a) set"  {* the identity relation *} 
12913  29 
"Id == {p. EX x. p = (x,x)}" 
7912  30 

12905  31 
diag :: "'a set => ('a * 'a) set"  {* diagonal: identity over a set *} 
13830  32 
"diag A == \<Union>x\<in>A. {(x,x)}" 
12913  33 

11136  34 
Domain :: "('a * 'b) set => 'a set" 
12913  35 
"Domain r == {x. EX y. (x,y):r}" 
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset

36 

11136  37 
Range :: "('a * 'b) set => 'b set" 
12913  38 
"Range r == Domain(r^1)" 
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset

39 

11136  40 
Field :: "('a * 'a) set => 'a set" 
13830  41 
"Field r == Domain r \<union> Range r" 
10786  42 

12905  43 
refl :: "['a set, ('a * 'a) set] => bool"  {* reflexivity over a set *} 
12913  44 
"refl A r == r \<subseteq> A \<times> A & (ALL x: A. (x,x) : r)" 
6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset

45 

12905  46 
sym :: "('a * 'a) set => bool"  {* symmetry predicate *} 
12913  47 
"sym r == ALL x y. (x,y): r > (y,x): r" 
6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset

48 

12905  49 
antisym:: "('a * 'a) set => bool"  {* antisymmetry predicate *} 
12913  50 
"antisym r == ALL x y. (x,y):r > (y,x):r > x=y" 
6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset

51 

12905  52 
trans :: "('a * 'a) set => bool"  {* transitivity predicate *} 
12913  53 
"trans r == (ALL x y z. (x,y):r > (y,z):r > (x,z):r)" 
5978
fa2c2dd74f8c
moved diag (diagonal relation) from Univ to Relation
paulson
parents:
5608
diff
changeset

54 

11136  55 
single_valued :: "('a * 'b) set => bool" 
12913  56 
"single_valued r == ALL x y. (x,y):r > (ALL z. (x,z):r > y=z)" 
7014
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6806
diff
changeset

57 

11136  58 
inv_image :: "('b * 'b) set => ('a => 'b) => ('a * 'a) set" 
12913  59 
"inv_image r f == {(x, y). (f x, f y) : r}" 
11136  60 

6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset

61 
syntax 
12905  62 
reflexive :: "('a * 'a) set => bool"  {* reflexivity over a type *} 
6806
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset

63 
translations 
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset

64 
"reflexive" == "refl UNIV" 
43c081a0858d
new preficates refl, sym [from Integ/Equiv], antisym
paulson
parents:
5978
diff
changeset

65 

12905  66 

12913  67 
subsection {* The identity relation *} 
12905  68 

69 
lemma IdI [intro]: "(a, a) : Id" 

70 
by (simp add: Id_def) 

71 

72 
lemma IdE [elim!]: "p : Id ==> (!!x. p = (x, x) ==> P) ==> P" 

17589  73 
by (unfold Id_def) (iprover elim: CollectE) 
12905  74 

75 
lemma pair_in_Id_conv [iff]: "((a, b) : Id) = (a = b)" 

76 
by (unfold Id_def) blast 

77 

78 
lemma reflexive_Id: "reflexive Id" 

79 
by (simp add: refl_def) 

80 

81 
lemma antisym_Id: "antisym Id" 

82 
 {* A strange result, since @{text Id} is also symmetric. *} 

83 
by (simp add: antisym_def) 

84 

85 
lemma trans_Id: "trans Id" 

86 
by (simp add: trans_def) 

87 

88 

12913  89 
subsection {* Diagonal: identity over a set *} 
12905  90 

13812
91713a1915ee
converting HOL/UNITY to use unconditional fairness
paulson
parents:
13639
diff
changeset

91 
lemma diag_empty [simp]: "diag {} = {}" 
91713a1915ee
converting HOL/UNITY to use unconditional fairness
paulson
parents:
13639
diff
changeset

92 
by (simp add: diag_def) 
91713a1915ee
converting HOL/UNITY to use unconditional fairness
paulson
parents:
13639
diff
changeset

93 

12905  94 
lemma diag_eqI: "a = b ==> a : A ==> (a, b) : diag A" 
95 
by (simp add: diag_def) 

96 

97 
lemma diagI [intro!]: "a : A ==> (a, a) : diag A" 

98 
by (rule diag_eqI) (rule refl) 

99 

100 
lemma diagE [elim!]: 

101 
"c : diag A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P" 

12913  102 
 {* The general elimination rule. *} 
17589  103 
by (unfold diag_def) (iprover elim!: UN_E singletonE) 
12905  104 

105 
lemma diag_iff: "((x, y) : diag A) = (x = y & x : A)" 

106 
by blast 

107 

12913  108 
lemma diag_subset_Times: "diag A \<subseteq> A \<times> A" 
12905  109 
by blast 
110 

111 

112 
subsection {* Composition of two relations *} 

113 

12913  114 
lemma rel_compI [intro]: 
12905  115 
"(a, b) : s ==> (b, c) : r ==> (a, c) : r O s" 
116 
by (unfold rel_comp_def) blast 

117 

12913  118 
lemma rel_compE [elim!]: "xz : r O s ==> 
12905  119 
(!!x y z. xz = (x, z) ==> (x, y) : s ==> (y, z) : r ==> P) ==> P" 
17589  120 
by (unfold rel_comp_def) (iprover elim!: CollectE splitE exE conjE) 
12905  121 

122 
lemma rel_compEpair: 

123 
"(a, c) : r O s ==> (!!y. (a, y) : s ==> (y, c) : r ==> P) ==> P" 

17589  124 
by (iprover elim: rel_compE Pair_inject ssubst) 
12905  125 

126 
lemma R_O_Id [simp]: "R O Id = R" 

127 
by fast 

128 

129 
lemma Id_O_R [simp]: "Id O R = R" 

130 
by fast 

131 

132 
lemma O_assoc: "(R O S) O T = R O (S O T)" 

133 
by blast 

134 

12913  135 
lemma trans_O_subset: "trans r ==> r O r \<subseteq> r" 
12905  136 
by (unfold trans_def) blast 
137 

12913  138 
lemma rel_comp_mono: "r' \<subseteq> r ==> s' \<subseteq> s ==> (r' O s') \<subseteq> (r O s)" 
12905  139 
by blast 
140 

141 
lemma rel_comp_subset_Sigma: 

12913  142 
"s \<subseteq> A \<times> B ==> r \<subseteq> B \<times> C ==> (r O s) \<subseteq> A \<times> C" 
12905  143 
by blast 
144 

12913  145 

146 
subsection {* Reflexivity *} 

147 

148 
lemma reflI: "r \<subseteq> A \<times> A ==> (!!x. x : A ==> (x, x) : r) ==> refl A r" 

17589  149 
by (unfold refl_def) (iprover intro!: ballI) 
12905  150 

151 
lemma reflD: "refl A r ==> a : A ==> (a, a) : r" 

152 
by (unfold refl_def) blast 

153 

12913  154 

155 
subsection {* Antisymmetry *} 

12905  156 

157 
lemma antisymI: 

158 
"(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r" 

17589  159 
by (unfold antisym_def) iprover 
12905  160 

161 
lemma antisymD: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b" 

17589  162 
by (unfold antisym_def) iprover 
12905  163 

12913  164 

15177  165 
subsection {* Symmetry and Transitivity *} 
166 

167 
lemma symD: "sym r ==> (a, b) : r ==> (b, a) : r" 

168 
by (unfold sym_def, blast) 

12905  169 

170 
lemma transI: 

171 
"(!!x y z. (x, y) : r ==> (y, z) : r ==> (x, z) : r) ==> trans r" 

17589  172 
by (unfold trans_def) iprover 
12905  173 

174 
lemma transD: "trans r ==> (a, b) : r ==> (b, c) : r ==> (a, c) : r" 

17589  175 
by (unfold trans_def) iprover 
12905  176 

177 

12913  178 
subsection {* Converse *} 
179 

180 
lemma converse_iff [iff]: "((a,b): r^1) = ((b,a) : r)" 

12905  181 
by (simp add: converse_def) 
182 

13343  183 
lemma converseI[sym]: "(a, b) : r ==> (b, a) : r^1" 
12905  184 
by (simp add: converse_def) 
185 

13343  186 
lemma converseD[sym]: "(a,b) : r^1 ==> (b, a) : r" 
12905  187 
by (simp add: converse_def) 
188 

189 
lemma converseE [elim!]: 

190 
"yx : r^1 ==> (!!x y. yx = (y, x) ==> (x, y) : r ==> P) ==> P" 

12913  191 
 {* More general than @{text converseD}, as it ``splits'' the member of the relation. *} 
17589  192 
by (unfold converse_def) (iprover elim!: CollectE splitE bexE) 
12905  193 

194 
lemma converse_converse [simp]: "(r^1)^1 = r" 

195 
by (unfold converse_def) blast 

196 

197 
lemma converse_rel_comp: "(r O s)^1 = s^1 O r^1" 

198 
by blast 

199 

200 
lemma converse_Id [simp]: "Id^1 = Id" 

201 
by blast 

202 

12913  203 
lemma converse_diag [simp]: "(diag A)^1 = diag A" 
12905  204 
by blast 
205 

206 
lemma refl_converse: "refl A r ==> refl A (converse r)" 

207 
by (unfold refl_def) blast 

208 

209 
lemma antisym_converse: "antisym (converse r) = antisym r" 

210 
by (unfold antisym_def) blast 

211 

212 
lemma trans_converse: "trans (converse r) = trans r" 

213 
by (unfold trans_def) blast 

214 

12913  215 

12905  216 
subsection {* Domain *} 
217 

218 
lemma Domain_iff: "(a : Domain r) = (EX y. (a, y) : r)" 

219 
by (unfold Domain_def) blast 

220 

221 
lemma DomainI [intro]: "(a, b) : r ==> a : Domain r" 

17589  222 
by (iprover intro!: iffD2 [OF Domain_iff]) 
12905  223 

224 
lemma DomainE [elim!]: 

225 
"a : Domain r ==> (!!y. (a, y) : r ==> P) ==> P" 

17589  226 
by (iprover dest!: iffD1 [OF Domain_iff]) 
12905  227 

228 
lemma Domain_empty [simp]: "Domain {} = {}" 

229 
by blast 

230 

231 
lemma Domain_insert: "Domain (insert (a, b) r) = insert a (Domain r)" 

232 
by blast 

233 

234 
lemma Domain_Id [simp]: "Domain Id = UNIV" 

235 
by blast 

236 

237 
lemma Domain_diag [simp]: "Domain (diag A) = A" 

238 
by blast 

239 

13830  240 
lemma Domain_Un_eq: "Domain(A \<union> B) = Domain(A) \<union> Domain(B)" 
12905  241 
by blast 
242 

13830  243 
lemma Domain_Int_subset: "Domain(A \<inter> B) \<subseteq> Domain(A) \<inter> Domain(B)" 
12905  244 
by blast 
245 

12913  246 
lemma Domain_Diff_subset: "Domain(A)  Domain(B) \<subseteq> Domain(A  B)" 
12905  247 
by blast 
248 

13830  249 
lemma Domain_Union: "Domain (Union S) = (\<Union>A\<in>S. Domain A)" 
12905  250 
by blast 
251 

12913  252 
lemma Domain_mono: "r \<subseteq> s ==> Domain r \<subseteq> Domain s" 
12905  253 
by blast 
254 

255 

256 
subsection {* Range *} 

257 

258 
lemma Range_iff: "(a : Range r) = (EX y. (y, a) : r)" 

259 
by (simp add: Domain_def Range_def) 

260 

261 
lemma RangeI [intro]: "(a, b) : r ==> b : Range r" 

17589  262 
by (unfold Range_def) (iprover intro!: converseI DomainI) 
12905  263 

264 
lemma RangeE [elim!]: "b : Range r ==> (!!x. (x, b) : r ==> P) ==> P" 

17589  265 
by (unfold Range_def) (iprover elim!: DomainE dest!: converseD) 
12905  266 

267 
lemma Range_empty [simp]: "Range {} = {}" 

268 
by blast 

269 

270 
lemma Range_insert: "Range (insert (a, b) r) = insert b (Range r)" 

271 
by blast 

272 

273 
lemma Range_Id [simp]: "Range Id = UNIV" 

274 
by blast 

275 

276 
lemma Range_diag [simp]: "Range (diag A) = A" 

277 
by auto 

278 

13830  279 
lemma Range_Un_eq: "Range(A \<union> B) = Range(A) \<union> Range(B)" 
12905  280 
by blast 
281 

13830  282 
lemma Range_Int_subset: "Range(A \<inter> B) \<subseteq> Range(A) \<inter> Range(B)" 
12905  283 
by blast 
284 

12913  285 
lemma Range_Diff_subset: "Range(A)  Range(B) \<subseteq> Range(A  B)" 
12905  286 
by blast 
287 

13830  288 
lemma Range_Union: "Range (Union S) = (\<Union>A\<in>S. Range A)" 
12905  289 
by blast 
290 

291 

292 
subsection {* Image of a set under a relation *} 

293 

12913  294 
lemma Image_iff: "(b : r``A) = (EX x:A. (x, b) : r)" 
12905  295 
by (simp add: Image_def) 
296 

12913  297 
lemma Image_singleton: "r``{a} = {b. (a, b) : r}" 
12905  298 
by (simp add: Image_def) 
299 

12913  300 
lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a, b) : r)" 
12905  301 
by (rule Image_iff [THEN trans]) simp 
302 

12913  303 
lemma ImageI [intro]: "(a, b) : r ==> a : A ==> b : r``A" 
12905  304 
by (unfold Image_def) blast 
305 

306 
lemma ImageE [elim!]: 

12913  307 
"b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P" 
17589  308 
by (unfold Image_def) (iprover elim!: CollectE bexE) 
12905  309 

310 
lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A" 

311 
 {* This version's more effective when we already have the required @{text a} *} 

312 
by blast 

313 

314 
lemma Image_empty [simp]: "R``{} = {}" 

315 
by blast 

316 

317 
lemma Image_Id [simp]: "Id `` A = A" 

318 
by blast 

319 

13830  320 
lemma Image_diag [simp]: "diag A `` B = A \<inter> B" 
321 
by blast 

322 

323 
lemma Image_Int_subset: "R `` (A \<inter> B) \<subseteq> R `` A \<inter> R `` B" 

12905  324 
by blast 
325 

13830  326 
lemma Image_Int_eq: 
327 
"single_valued (converse R) ==> R `` (A \<inter> B) = R `` A \<inter> R `` B" 

328 
by (simp add: single_valued_def, blast) 

12905  329 

13830  330 
lemma Image_Un: "R `` (A \<union> B) = R `` A \<union> R `` B" 
12905  331 
by blast 
332 

13812
91713a1915ee
converting HOL/UNITY to use unconditional fairness
paulson
parents:
13639
diff
changeset

333 
lemma Un_Image: "(R \<union> S) `` A = R `` A \<union> S `` A" 
91713a1915ee
converting HOL/UNITY to use unconditional fairness
paulson
parents:
13639
diff
changeset

334 
by blast 
91713a1915ee
converting HOL/UNITY to use unconditional fairness
paulson
parents:
13639
diff
changeset

335 

12913  336 
lemma Image_subset: "r \<subseteq> A \<times> B ==> r``C \<subseteq> B" 
17589  337 
by (iprover intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2) 
12905  338 

13830  339 
lemma Image_eq_UN: "r``B = (\<Union>y\<in> B. r``{y})" 
12905  340 
 {* NOT suitable for rewriting *} 
341 
by blast 

342 

12913  343 
lemma Image_mono: "r' \<subseteq> r ==> A' \<subseteq> A ==> (r' `` A') \<subseteq> (r `` A)" 
12905  344 
by blast 
345 

13830  346 
lemma Image_UN: "(r `` (UNION A B)) = (\<Union>x\<in>A. r `` (B x))" 
347 
by blast 

348 

349 
lemma Image_INT_subset: "(r `` INTER A B) \<subseteq> (\<Inter>x\<in>A. r `` (B x))" 

12905  350 
by blast 
351 

13830  352 
text{*Converse inclusion requires some assumptions*} 
353 
lemma Image_INT_eq: 

354 
"[single_valued (r\<inverse>); A\<noteq>{}] ==> r `` INTER A B = (\<Inter>x\<in>A. r `` B x)" 

355 
apply (rule equalityI) 

356 
apply (rule Image_INT_subset) 

357 
apply (simp add: single_valued_def, blast) 

358 
done 

12905  359 

12913  360 
lemma Image_subset_eq: "(r``A \<subseteq> B) = (A \<subseteq>  ((r^1) `` (B)))" 
12905  361 
by blast 
362 

363 

12913  364 
subsection {* Single valued relations *} 
365 

366 
lemma single_valuedI: 

12905  367 
"ALL x y. (x,y):r > (ALL z. (x,z):r > y=z) ==> single_valued r" 
368 
by (unfold single_valued_def) 

369 

370 
lemma single_valuedD: 

371 
"single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z" 

372 
by (simp add: single_valued_def) 

373 

374 

375 
subsection {* Graphs given by @{text Collect} *} 

376 

377 
lemma Domain_Collect_split [simp]: "Domain{(x,y). P x y} = {x. EX y. P x y}" 

378 
by auto 

379 

380 
lemma Range_Collect_split [simp]: "Range{(x,y). P x y} = {y. EX x. P x y}" 

381 
by auto 

382 

383 
lemma Image_Collect_split [simp]: "{(x,y). P x y} `` A = {y. EX x:A. P x y}" 

384 
by auto 

385 

386 

12913  387 
subsection {* Inverse image *} 
12905  388 

12913  389 
lemma trans_inv_image: "trans r ==> trans (inv_image r f)" 
12905  390 
apply (unfold trans_def inv_image_def) 
391 
apply (simp (no_asm)) 

392 
apply blast 

393 
done 

394 

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

395 
end 