src/HOL/Relation.thy
 author nipkow Mon Jan 30 21:49:41 2012 +0100 (2012-01-30) changeset 46372 6fa9cdb8b850 parent 46127 af3b95160b59 child 46635 cde737f9c911 permissions -rw-r--r--
```     1 (*  Title:      HOL/Relation.thy
```
```     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
```
```     3     Copyright   1996  University of Cambridge
```
```     4 *)
```
```     5
```
```     6 header {* Relations *}
```
```     7
```
```     8 theory Relation
```
```     9 imports Datatype Finite_Set
```
```    10 begin
```
```    11
```
```    12 subsection {* Definitions *}
```
```    13
```
```    14 type_synonym 'a rel = "('a * 'a) set"
```
```    15
```
```    16 definition
```
```    17   converse :: "('a * 'b) set => ('b * 'a) set"
```
```    18     ("(_^-1)" [1000] 999) where
```
```    19   "r^-1 = {(y, x). (x, y) : r}"
```
```    20
```
```    21 notation (xsymbols)
```
```    22   converse  ("(_\<inverse>)" [1000] 999)
```
```    23
```
```    24 definition
```
```    25   rel_comp  :: "[('a * 'b) set, ('b * 'c) set] => ('a * 'c) set"
```
```    26     (infixr "O" 75) where
```
```    27   "r O s = {(x,z). EX y. (x, y) : r & (y, z) : s}"
```
```    28
```
```    29 definition
```
```    30   Image :: "[('a * 'b) set, 'a set] => 'b set"
```
```    31     (infixl "``" 90) where
```
```    32   "r `` s = {y. EX x:s. (x,y):r}"
```
```    33
```
```    34 definition
```
```    35   Id :: "('a * 'a) set" where -- {* the identity relation *}
```
```    36   "Id = {p. EX x. p = (x,x)}"
```
```    37
```
```    38 definition
```
```    39   Id_on  :: "'a set => ('a * 'a) set" where -- {* diagonal: identity over a set *}
```
```    40   "Id_on A = (\<Union>x\<in>A. {(x,x)})"
```
```    41
```
```    42 definition
```
```    43   Domain :: "('a * 'b) set => 'a set" where
```
```    44   "Domain r = {x. EX y. (x,y):r}"
```
```    45
```
```    46 definition
```
```    47   Range  :: "('a * 'b) set => 'b set" where
```
```    48   "Range r = Domain(r^-1)"
```
```    49
```
```    50 definition
```
```    51   Field :: "('a * 'a) set => 'a set" where
```
```    52   "Field r = Domain r \<union> Range r"
```
```    53
```
```    54 definition
```
```    55   refl_on :: "['a set, ('a * 'a) set] => bool" where -- {* reflexivity over a set *}
```
```    56   "refl_on A r \<longleftrightarrow> r \<subseteq> A \<times> A & (ALL x: A. (x,x) : r)"
```
```    57
```
```    58 abbreviation
```
```    59   refl :: "('a * 'a) set => bool" where -- {* reflexivity over a type *}
```
```    60   "refl \<equiv> refl_on UNIV"
```
```    61
```
```    62 definition
```
```    63   sym :: "('a * 'a) set => bool" where -- {* symmetry predicate *}
```
```    64   "sym r \<longleftrightarrow> (ALL x y. (x,y): r --> (y,x): r)"
```
```    65
```
```    66 definition
```
```    67   antisym :: "('a * 'a) set => bool" where -- {* antisymmetry predicate *}
```
```    68   "antisym r \<longleftrightarrow> (ALL x y. (x,y):r --> (y,x):r --> x=y)"
```
```    69
```
```    70 definition
```
```    71   trans :: "('a * 'a) set => bool" where -- {* transitivity predicate *}
```
```    72   "trans r \<longleftrightarrow> (ALL x y z. (x,y):r --> (y,z):r --> (x,z):r)"
```
```    73
```
```    74 definition
```
```    75   irrefl :: "('a * 'a) set => bool" where
```
```    76   "irrefl r \<longleftrightarrow> (\<forall>x. (x,x) \<notin> r)"
```
```    77
```
```    78 definition
```
```    79   total_on :: "'a set => ('a * 'a) set => bool" where
```
```    80   "total_on A r \<longleftrightarrow> (\<forall>x\<in>A.\<forall>y\<in>A. x\<noteq>y \<longrightarrow> (x,y)\<in>r \<or> (y,x)\<in>r)"
```
```    81
```
```    82 abbreviation "total \<equiv> total_on UNIV"
```
```    83
```
```    84 definition
```
```    85   single_valued :: "('a * 'b) set => bool" where
```
```    86   "single_valued r \<longleftrightarrow> (ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z))"
```
```    87
```
```    88 definition
```
```    89   inv_image :: "('b * 'b) set => ('a => 'b) => ('a * 'a) set" where
```
```    90   "inv_image r f = {(x, y). (f x, f y) : r}"
```
```    91
```
```    92
```
```    93 subsection {* The identity relation *}
```
```    94
```
```    95 lemma IdI [intro]: "(a, a) : Id"
```
```    96 by (simp add: Id_def)
```
```    97
```
```    98 lemma IdE [elim!]: "p : Id ==> (!!x. p = (x, x) ==> P) ==> P"
```
```    99 by (unfold Id_def) (iprover elim: CollectE)
```
```   100
```
```   101 lemma pair_in_Id_conv [iff]: "((a, b) : Id) = (a = b)"
```
```   102 by (unfold Id_def) blast
```
```   103
```
```   104 lemma refl_Id: "refl Id"
```
```   105 by (simp add: refl_on_def)
```
```   106
```
```   107 lemma antisym_Id: "antisym Id"
```
```   108   -- {* A strange result, since @{text Id} is also symmetric. *}
```
```   109 by (simp add: antisym_def)
```
```   110
```
```   111 lemma sym_Id: "sym Id"
```
```   112 by (simp add: sym_def)
```
```   113
```
```   114 lemma trans_Id: "trans Id"
```
```   115 by (simp add: trans_def)
```
```   116
```
```   117
```
```   118 subsection {* Diagonal: identity over a set *}
```
```   119
```
```   120 lemma Id_on_empty [simp]: "Id_on {} = {}"
```
```   121 by (simp add: Id_on_def)
```
```   122
```
```   123 lemma Id_on_eqI: "a = b ==> a : A ==> (a, b) : Id_on A"
```
```   124 by (simp add: Id_on_def)
```
```   125
```
```   126 lemma Id_onI [intro!,no_atp]: "a : A ==> (a, a) : Id_on A"
```
```   127 by (rule Id_on_eqI) (rule refl)
```
```   128
```
```   129 lemma Id_onE [elim!]:
```
```   130   "c : Id_on A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P"
```
```   131   -- {* The general elimination rule. *}
```
```   132 by (unfold Id_on_def) (iprover elim!: UN_E singletonE)
```
```   133
```
```   134 lemma Id_on_iff: "((x, y) : Id_on A) = (x = y & x : A)"
```
```   135 by blast
```
```   136
```
```   137 lemma Id_on_def' [nitpick_unfold]:
```
```   138   "Id_on {x. A x} = Collect (\<lambda>(x, y). x = y \<and> A x)"
```
```   139 by auto
```
```   140
```
```   141 lemma Id_on_subset_Times: "Id_on A \<subseteq> A \<times> A"
```
```   142 by blast
```
```   143
```
```   144
```
```   145 subsection {* Composition of two relations *}
```
```   146
```
```   147 lemma rel_compI [intro]:
```
```   148   "(a, b) : r ==> (b, c) : s ==> (a, c) : r O s"
```
```   149 by (unfold rel_comp_def) blast
```
```   150
```
```   151 lemma rel_compE [elim!]: "xz : r O s ==>
```
```   152   (!!x y z. xz = (x, z) ==> (x, y) : r ==> (y, z) : s  ==> P) ==> P"
```
```   153 by (unfold rel_comp_def) (iprover elim!: CollectE splitE exE conjE)
```
```   154
```
```   155 lemma rel_compEpair:
```
```   156   "(a, c) : r O s ==> (!!y. (a, y) : r ==> (y, c) : s ==> P) ==> P"
```
```   157 by (iprover elim: rel_compE Pair_inject ssubst)
```
```   158
```
```   159 lemma R_O_Id [simp]: "R O Id = R"
```
```   160 by fast
```
```   161
```
```   162 lemma Id_O_R [simp]: "Id O R = R"
```
```   163 by fast
```
```   164
```
```   165 lemma rel_comp_empty1[simp]: "{} O R = {}"
```
```   166 by blast
```
```   167
```
```   168 lemma rel_comp_empty2[simp]: "R O {} = {}"
```
```   169 by blast
```
```   170
```
```   171 lemma O_assoc: "(R O S) O T = R O (S O T)"
```
```   172 by blast
```
```   173
```
```   174 lemma trans_O_subset: "trans r ==> r O r \<subseteq> r"
```
```   175 by (unfold trans_def) blast
```
```   176
```
```   177 lemma rel_comp_mono: "r' \<subseteq> r ==> s' \<subseteq> s ==> (r' O s') \<subseteq> (r O s)"
```
```   178 by blast
```
```   179
```
```   180 lemma rel_comp_subset_Sigma:
```
```   181     "r \<subseteq> A \<times> B ==> s \<subseteq> B \<times> C ==> (r O s) \<subseteq> A \<times> C"
```
```   182 by blast
```
```   183
```
```   184 lemma rel_comp_distrib[simp]: "R O (S \<union> T) = (R O S) \<union> (R O T)"
```
```   185 by auto
```
```   186
```
```   187 lemma rel_comp_distrib2[simp]: "(S \<union> T) O R = (S O R) \<union> (T O R)"
```
```   188 by auto
```
```   189
```
```   190 lemma rel_comp_UNION_distrib: "s O UNION I r = UNION I (%i. s O r i)"
```
```   191 by auto
```
```   192
```
```   193 lemma rel_comp_UNION_distrib2: "UNION I r O s = UNION I (%i. r i O s)"
```
```   194 by auto
```
```   195
```
```   196
```
```   197 subsection {* Reflexivity *}
```
```   198
```
```   199 lemma refl_onI: "r \<subseteq> A \<times> A ==> (!!x. x : A ==> (x, x) : r) ==> refl_on A r"
```
```   200 by (unfold refl_on_def) (iprover intro!: ballI)
```
```   201
```
```   202 lemma refl_onD: "refl_on A r ==> a : A ==> (a, a) : r"
```
```   203 by (unfold refl_on_def) blast
```
```   204
```
```   205 lemma refl_onD1: "refl_on A r ==> (x, y) : r ==> x : A"
```
```   206 by (unfold refl_on_def) blast
```
```   207
```
```   208 lemma refl_onD2: "refl_on A r ==> (x, y) : r ==> y : A"
```
```   209 by (unfold refl_on_def) blast
```
```   210
```
```   211 lemma refl_on_Int: "refl_on A r ==> refl_on B s ==> refl_on (A \<inter> B) (r \<inter> s)"
```
```   212 by (unfold refl_on_def) blast
```
```   213
```
```   214 lemma refl_on_Un: "refl_on A r ==> refl_on B s ==> refl_on (A \<union> B) (r \<union> s)"
```
```   215 by (unfold refl_on_def) blast
```
```   216
```
```   217 lemma refl_on_INTER:
```
```   218   "ALL x:S. refl_on (A x) (r x) ==> refl_on (INTER S A) (INTER S r)"
```
```   219 by (unfold refl_on_def) fast
```
```   220
```
```   221 lemma refl_on_UNION:
```
```   222   "ALL x:S. refl_on (A x) (r x) \<Longrightarrow> refl_on (UNION S A) (UNION S r)"
```
```   223 by (unfold refl_on_def) blast
```
```   224
```
```   225 lemma refl_on_empty[simp]: "refl_on {} {}"
```
```   226 by(simp add:refl_on_def)
```
```   227
```
```   228 lemma refl_on_Id_on: "refl_on A (Id_on A)"
```
```   229 by (rule refl_onI [OF Id_on_subset_Times Id_onI])
```
```   230
```
```   231 lemma refl_on_def' [nitpick_unfold, code]:
```
```   232   "refl_on A r = ((\<forall>(x, y) \<in> r. x : A \<and> y : A) \<and> (\<forall>x \<in> A. (x, x) : r))"
```
```   233 by (auto intro: refl_onI dest: refl_onD refl_onD1 refl_onD2)
```
```   234
```
```   235 subsection {* Antisymmetry *}
```
```   236
```
```   237 lemma antisymI:
```
```   238   "(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r"
```
```   239 by (unfold antisym_def) iprover
```
```   240
```
```   241 lemma antisymD: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b"
```
```   242 by (unfold antisym_def) iprover
```
```   243
```
```   244 lemma antisym_subset: "r \<subseteq> s ==> antisym s ==> antisym r"
```
```   245 by (unfold antisym_def) blast
```
```   246
```
```   247 lemma antisym_empty [simp]: "antisym {}"
```
```   248 by (unfold antisym_def) blast
```
```   249
```
```   250 lemma antisym_Id_on [simp]: "antisym (Id_on A)"
```
```   251 by (unfold antisym_def) blast
```
```   252
```
```   253
```
```   254 subsection {* Symmetry *}
```
```   255
```
```   256 lemma symI: "(!!a b. (a, b) : r ==> (b, a) : r) ==> sym r"
```
```   257 by (unfold sym_def) iprover
```
```   258
```
```   259 lemma symD: "sym r ==> (a, b) : r ==> (b, a) : r"
```
```   260 by (unfold sym_def, blast)
```
```   261
```
```   262 lemma sym_Int: "sym r ==> sym s ==> sym (r \<inter> s)"
```
```   263 by (fast intro: symI dest: symD)
```
```   264
```
```   265 lemma sym_Un: "sym r ==> sym s ==> sym (r \<union> s)"
```
```   266 by (fast intro: symI dest: symD)
```
```   267
```
```   268 lemma sym_INTER: "ALL x:S. sym (r x) ==> sym (INTER S r)"
```
```   269 by (fast intro: symI dest: symD)
```
```   270
```
```   271 lemma sym_UNION: "ALL x:S. sym (r x) ==> sym (UNION S r)"
```
```   272 by (fast intro: symI dest: symD)
```
```   273
```
```   274 lemma sym_Id_on [simp]: "sym (Id_on A)"
```
```   275 by (rule symI) clarify
```
```   276
```
```   277
```
```   278 subsection {* Transitivity *}
```
```   279
```
```   280 lemma trans_join [code]:
```
```   281   "trans r \<longleftrightarrow> (\<forall>(x, y1) \<in> r. \<forall>(y2, z) \<in> r. y1 = y2 \<longrightarrow> (x, z) \<in> r)"
```
```   282   by (auto simp add: trans_def)
```
```   283
```
```   284 lemma transI:
```
```   285   "(!!x y z. (x, y) : r ==> (y, z) : r ==> (x, z) : r) ==> trans r"
```
```   286 by (unfold trans_def) iprover
```
```   287
```
```   288 lemma transD: "trans r ==> (a, b) : r ==> (b, c) : r ==> (a, c) : r"
```
```   289 by (unfold trans_def) iprover
```
```   290
```
```   291 lemma trans_Int: "trans r ==> trans s ==> trans (r \<inter> s)"
```
```   292 by (fast intro: transI elim: transD)
```
```   293
```
```   294 lemma trans_INTER: "ALL x:S. trans (r x) ==> trans (INTER S r)"
```
```   295 by (fast intro: transI elim: transD)
```
```   296
```
```   297 lemma trans_Id_on [simp]: "trans (Id_on A)"
```
```   298 by (fast intro: transI elim: transD)
```
```   299
```
```   300 lemma trans_diff_Id: " trans r \<Longrightarrow> antisym r \<Longrightarrow> trans (r-Id)"
```
```   301 unfolding antisym_def trans_def by blast
```
```   302
```
```   303 subsection {* Irreflexivity *}
```
```   304
```
```   305 lemma irrefl_distinct [code]:
```
```   306   "irrefl r \<longleftrightarrow> (\<forall>(x, y) \<in> r. x \<noteq> y)"
```
```   307   by (auto simp add: irrefl_def)
```
```   308
```
```   309 lemma irrefl_diff_Id[simp]: "irrefl(r-Id)"
```
```   310 by(simp add:irrefl_def)
```
```   311
```
```   312
```
```   313 subsection {* Totality *}
```
```   314
```
```   315 lemma total_on_empty[simp]: "total_on {} r"
```
```   316 by(simp add:total_on_def)
```
```   317
```
```   318 lemma total_on_diff_Id[simp]: "total_on A (r-Id) = total_on A r"
```
```   319 by(simp add: total_on_def)
```
```   320
```
```   321 subsection {* Converse *}
```
```   322
```
```   323 lemma converse_iff [iff]: "((a,b): r^-1) = ((b,a) : r)"
```
```   324 by (simp add: converse_def)
```
```   325
```
```   326 lemma converseI[sym]: "(a, b) : r ==> (b, a) : r^-1"
```
```   327 by (simp add: converse_def)
```
```   328
```
```   329 lemma converseD[sym]: "(a,b) : r^-1 ==> (b, a) : r"
```
```   330 by (simp add: converse_def)
```
```   331
```
```   332 lemma converseE [elim!]:
```
```   333   "yx : r^-1 ==> (!!x y. yx = (y, x) ==> (x, y) : r ==> P) ==> P"
```
```   334     -- {* More general than @{text converseD}, as it ``splits'' the member of the relation. *}
```
```   335 by (unfold converse_def) (iprover elim!: CollectE splitE bexE)
```
```   336
```
```   337 lemma converse_converse [simp]: "(r^-1)^-1 = r"
```
```   338 by (unfold converse_def) blast
```
```   339
```
```   340 lemma converse_rel_comp: "(r O s)^-1 = s^-1 O r^-1"
```
```   341 by blast
```
```   342
```
```   343 lemma converse_Int: "(r \<inter> s)^-1 = r^-1 \<inter> s^-1"
```
```   344 by blast
```
```   345
```
```   346 lemma converse_Un: "(r \<union> s)^-1 = r^-1 \<union> s^-1"
```
```   347 by blast
```
```   348
```
```   349 lemma converse_INTER: "(INTER S r)^-1 = (INT x:S. (r x)^-1)"
```
```   350 by fast
```
```   351
```
```   352 lemma converse_UNION: "(UNION S r)^-1 = (UN x:S. (r x)^-1)"
```
```   353 by blast
```
```   354
```
```   355 lemma converse_Id [simp]: "Id^-1 = Id"
```
```   356 by blast
```
```   357
```
```   358 lemma converse_Id_on [simp]: "(Id_on A)^-1 = Id_on A"
```
```   359 by blast
```
```   360
```
```   361 lemma refl_on_converse [simp]: "refl_on A (converse r) = refl_on A r"
```
```   362 by (unfold refl_on_def) auto
```
```   363
```
```   364 lemma sym_converse [simp]: "sym (converse r) = sym r"
```
```   365 by (unfold sym_def) blast
```
```   366
```
```   367 lemma antisym_converse [simp]: "antisym (converse r) = antisym r"
```
```   368 by (unfold antisym_def) blast
```
```   369
```
```   370 lemma trans_converse [simp]: "trans (converse r) = trans r"
```
```   371 by (unfold trans_def) blast
```
```   372
```
```   373 lemma sym_conv_converse_eq: "sym r = (r^-1 = r)"
```
```   374 by (unfold sym_def) fast
```
```   375
```
```   376 lemma sym_Un_converse: "sym (r \<union> r^-1)"
```
```   377 by (unfold sym_def) blast
```
```   378
```
```   379 lemma sym_Int_converse: "sym (r \<inter> r^-1)"
```
```   380 by (unfold sym_def) blast
```
```   381
```
```   382 lemma total_on_converse[simp]: "total_on A (r^-1) = total_on A r"
```
```   383 by (auto simp: total_on_def)
```
```   384
```
```   385
```
```   386 subsection {* Domain *}
```
```   387
```
```   388 declare Domain_def [no_atp]
```
```   389
```
```   390 lemma Domain_iff: "(a : Domain r) = (EX y. (a, y) : r)"
```
```   391 by (unfold Domain_def) blast
```
```   392
```
```   393 lemma DomainI [intro]: "(a, b) : r ==> a : Domain r"
```
```   394 by (iprover intro!: iffD2 [OF Domain_iff])
```
```   395
```
```   396 lemma DomainE [elim!]:
```
```   397   "a : Domain r ==> (!!y. (a, y) : r ==> P) ==> P"
```
```   398 by (iprover dest!: iffD1 [OF Domain_iff])
```
```   399
```
```   400 lemma Domain_fst [code]:
```
```   401   "Domain r = fst ` r"
```
```   402   by (auto simp add: image_def Bex_def)
```
```   403
```
```   404 lemma Domain_empty [simp]: "Domain {} = {}"
```
```   405 by blast
```
```   406
```
```   407 lemma Domain_empty_iff: "Domain r = {} \<longleftrightarrow> r = {}"
```
```   408   by auto
```
```   409
```
```   410 lemma Domain_insert: "Domain (insert (a, b) r) = insert a (Domain r)"
```
```   411 by blast
```
```   412
```
```   413 lemma Domain_Id [simp]: "Domain Id = UNIV"
```
```   414 by blast
```
```   415
```
```   416 lemma Domain_Id_on [simp]: "Domain (Id_on A) = A"
```
```   417 by blast
```
```   418
```
```   419 lemma Domain_Un_eq: "Domain(A \<union> B) = Domain(A) \<union> Domain(B)"
```
```   420 by blast
```
```   421
```
```   422 lemma Domain_Int_subset: "Domain(A \<inter> B) \<subseteq> Domain(A) \<inter> Domain(B)"
```
```   423 by blast
```
```   424
```
```   425 lemma Domain_Diff_subset: "Domain(A) - Domain(B) \<subseteq> Domain(A - B)"
```
```   426 by blast
```
```   427
```
```   428 lemma Domain_Union: "Domain (Union S) = (\<Union>A\<in>S. Domain A)"
```
```   429 by blast
```
```   430
```
```   431 lemma Domain_converse[simp]: "Domain(r^-1) = Range r"
```
```   432 by(auto simp:Range_def)
```
```   433
```
```   434 lemma Domain_mono: "r \<subseteq> s ==> Domain r \<subseteq> Domain s"
```
```   435 by blast
```
```   436
```
```   437 lemma fst_eq_Domain: "fst ` R = Domain R"
```
```   438   by force
```
```   439
```
```   440 lemma Domain_dprod [simp]: "Domain (dprod r s) = uprod (Domain r) (Domain s)"
```
```   441 by auto
```
```   442
```
```   443 lemma Domain_dsum [simp]: "Domain (dsum r s) = usum (Domain r) (Domain s)"
```
```   444 by auto
```
```   445
```
```   446
```
```   447 subsection {* Range *}
```
```   448
```
```   449 lemma Range_iff: "(a : Range r) = (EX y. (y, a) : r)"
```
```   450 by (simp add: Domain_def Range_def)
```
```   451
```
```   452 lemma RangeI [intro]: "(a, b) : r ==> b : Range r"
```
```   453 by (unfold Range_def) (iprover intro!: converseI DomainI)
```
```   454
```
```   455 lemma RangeE [elim!]: "b : Range r ==> (!!x. (x, b) : r ==> P) ==> P"
```
```   456 by (unfold Range_def) (iprover elim!: DomainE dest!: converseD)
```
```   457
```
```   458 lemma Range_snd [code]:
```
```   459   "Range r = snd ` r"
```
```   460   by (auto simp add: image_def Bex_def)
```
```   461
```
```   462 lemma Range_empty [simp]: "Range {} = {}"
```
```   463 by blast
```
```   464
```
```   465 lemma Range_empty_iff: "Range r = {} \<longleftrightarrow> r = {}"
```
```   466   by auto
```
```   467
```
```   468 lemma Range_insert: "Range (insert (a, b) r) = insert b (Range r)"
```
```   469 by blast
```
```   470
```
```   471 lemma Range_Id [simp]: "Range Id = UNIV"
```
```   472 by blast
```
```   473
```
```   474 lemma Range_Id_on [simp]: "Range (Id_on A) = A"
```
```   475 by auto
```
```   476
```
```   477 lemma Range_Un_eq: "Range(A \<union> B) = Range(A) \<union> Range(B)"
```
```   478 by blast
```
```   479
```
```   480 lemma Range_Int_subset: "Range(A \<inter> B) \<subseteq> Range(A) \<inter> Range(B)"
```
```   481 by blast
```
```   482
```
```   483 lemma Range_Diff_subset: "Range(A) - Range(B) \<subseteq> Range(A - B)"
```
```   484 by blast
```
```   485
```
```   486 lemma Range_Union: "Range (Union S) = (\<Union>A\<in>S. Range A)"
```
```   487 by blast
```
```   488
```
```   489 lemma Range_converse[simp]: "Range(r^-1) = Domain r"
```
```   490 by blast
```
```   491
```
```   492 lemma snd_eq_Range: "snd ` R = Range R"
```
```   493   by force
```
```   494
```
```   495
```
```   496 subsection {* Field *}
```
```   497
```
```   498 lemma mono_Field: "r \<subseteq> s \<Longrightarrow> Field r \<subseteq> Field s"
```
```   499 by(auto simp:Field_def Domain_def Range_def)
```
```   500
```
```   501 lemma Field_empty[simp]: "Field {} = {}"
```
```   502 by(auto simp:Field_def)
```
```   503
```
```   504 lemma Field_insert[simp]: "Field (insert (a,b) r) = {a,b} \<union> Field r"
```
```   505 by(auto simp:Field_def)
```
```   506
```
```   507 lemma Field_Un[simp]: "Field (r \<union> s) = Field r \<union> Field s"
```
```   508 by(auto simp:Field_def)
```
```   509
```
```   510 lemma Field_Union[simp]: "Field (\<Union>R) = \<Union>(Field ` R)"
```
```   511 by(auto simp:Field_def)
```
```   512
```
```   513 lemma Field_converse[simp]: "Field(r^-1) = Field r"
```
```   514 by(auto simp:Field_def)
```
```   515
```
```   516
```
```   517 subsection {* Image of a set under a relation *}
```
```   518
```
```   519 declare Image_def [no_atp]
```
```   520
```
```   521 lemma Image_iff: "(b : r``A) = (EX x:A. (x, b) : r)"
```
```   522 by (simp add: Image_def)
```
```   523
```
```   524 lemma Image_singleton: "r``{a} = {b. (a, b) : r}"
```
```   525 by (simp add: Image_def)
```
```   526
```
```   527 lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a, b) : r)"
```
```   528 by (rule Image_iff [THEN trans]) simp
```
```   529
```
```   530 lemma ImageI [intro,no_atp]: "(a, b) : r ==> a : A ==> b : r``A"
```
```   531 by (unfold Image_def) blast
```
```   532
```
```   533 lemma ImageE [elim!]:
```
```   534     "b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P"
```
```   535 by (unfold Image_def) (iprover elim!: CollectE bexE)
```
```   536
```
```   537 lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A"
```
```   538   -- {* This version's more effective when we already have the required @{text a} *}
```
```   539 by blast
```
```   540
```
```   541 lemma Image_empty [simp]: "R``{} = {}"
```
```   542 by blast
```
```   543
```
```   544 lemma Image_Id [simp]: "Id `` A = A"
```
```   545 by blast
```
```   546
```
```   547 lemma Image_Id_on [simp]: "Id_on A `` B = A \<inter> B"
```
```   548 by blast
```
```   549
```
```   550 lemma Image_Int_subset: "R `` (A \<inter> B) \<subseteq> R `` A \<inter> R `` B"
```
```   551 by blast
```
```   552
```
```   553 lemma Image_Int_eq:
```
```   554      "single_valued (converse R) ==> R `` (A \<inter> B) = R `` A \<inter> R `` B"
```
```   555 by (simp add: single_valued_def, blast)
```
```   556
```
```   557 lemma Image_Un: "R `` (A \<union> B) = R `` A \<union> R `` B"
```
```   558 by blast
```
```   559
```
```   560 lemma Un_Image: "(R \<union> S) `` A = R `` A \<union> S `` A"
```
```   561 by blast
```
```   562
```
```   563 lemma Image_subset: "r \<subseteq> A \<times> B ==> r``C \<subseteq> B"
```
```   564 by (iprover intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2)
```
```   565
```
```   566 lemma Image_eq_UN: "r``B = (\<Union>y\<in> B. r``{y})"
```
```   567   -- {* NOT suitable for rewriting *}
```
```   568 by blast
```
```   569
```
```   570 lemma Image_mono: "r' \<subseteq> r ==> A' \<subseteq> A ==> (r' `` A') \<subseteq> (r `` A)"
```
```   571 by blast
```
```   572
```
```   573 lemma Image_UN: "(r `` (UNION A B)) = (\<Union>x\<in>A. r `` (B x))"
```
```   574 by blast
```
```   575
```
```   576 lemma Image_INT_subset: "(r `` INTER A B) \<subseteq> (\<Inter>x\<in>A. r `` (B x))"
```
```   577 by blast
```
```   578
```
```   579 text{*Converse inclusion requires some assumptions*}
```
```   580 lemma Image_INT_eq:
```
```   581      "[|single_valued (r\<inverse>); A\<noteq>{}|] ==> r `` INTER A B = (\<Inter>x\<in>A. r `` B x)"
```
```   582 apply (rule equalityI)
```
```   583  apply (rule Image_INT_subset)
```
```   584 apply  (simp add: single_valued_def, blast)
```
```   585 done
```
```   586
```
```   587 lemma Image_subset_eq: "(r``A \<subseteq> B) = (A \<subseteq> - ((r^-1) `` (-B)))"
```
```   588 by blast
```
```   589
```
```   590
```
```   591 subsection {* Single valued relations *}
```
```   592
```
```   593 lemma single_valuedI:
```
```   594   "ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r"
```
```   595 by (unfold single_valued_def)
```
```   596
```
```   597 lemma single_valuedD:
```
```   598   "single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z"
```
```   599 by (simp add: single_valued_def)
```
```   600
```
```   601 lemma single_valued_rel_comp:
```
```   602   "single_valued r ==> single_valued s ==> single_valued (r O s)"
```
```   603 by (unfold single_valued_def) blast
```
```   604
```
```   605 lemma single_valued_subset:
```
```   606   "r \<subseteq> s ==> single_valued s ==> single_valued r"
```
```   607 by (unfold single_valued_def) blast
```
```   608
```
```   609 lemma single_valued_Id [simp]: "single_valued Id"
```
```   610 by (unfold single_valued_def) blast
```
```   611
```
```   612 lemma single_valued_Id_on [simp]: "single_valued (Id_on A)"
```
```   613 by (unfold single_valued_def) blast
```
```   614
```
```   615
```
```   616 subsection {* Graphs given by @{text Collect} *}
```
```   617
```
```   618 lemma Domain_Collect_split [simp]: "Domain{(x,y). P x y} = {x. EX y. P x y}"
```
```   619 by auto
```
```   620
```
```   621 lemma Range_Collect_split [simp]: "Range{(x,y). P x y} = {y. EX x. P x y}"
```
```   622 by auto
```
```   623
```
```   624 lemma Image_Collect_split [simp]: "{(x,y). P x y} `` A = {y. EX x:A. P x y}"
```
```   625 by auto
```
```   626
```
```   627
```
```   628 subsection {* Inverse image *}
```
```   629
```
```   630 lemma sym_inv_image: "sym r ==> sym (inv_image r f)"
```
```   631 by (unfold sym_def inv_image_def) blast
```
```   632
```
```   633 lemma trans_inv_image: "trans r ==> trans (inv_image r f)"
```
```   634   apply (unfold trans_def inv_image_def)
```
```   635   apply (simp (no_asm))
```
```   636   apply blast
```
```   637   done
```
```   638
```
```   639 lemma in_inv_image[simp]: "((x,y) : inv_image r f) = ((f x, f y) : r)"
```
```   640   by (auto simp:inv_image_def)
```
```   641
```
```   642 lemma converse_inv_image[simp]: "(inv_image R f)^-1 = inv_image (R^-1) f"
```
```   643 unfolding inv_image_def converse_def by auto
```
```   644
```
```   645
```
```   646 subsection {* Finiteness *}
```
```   647
```
```   648 lemma finite_converse [iff]: "finite (r^-1) = finite r"
```
```   649   apply (subgoal_tac "r^-1 = (%(x,y). (y,x))`r")
```
```   650    apply simp
```
```   651    apply (rule iffI)
```
```   652     apply (erule finite_imageD [unfolded inj_on_def])
```
```   653     apply (simp split add: split_split)
```
```   654    apply (erule finite_imageI)
```
```   655   apply (simp add: converse_def image_def, auto)
```
```   656   apply (rule bexI)
```
```   657    prefer 2 apply assumption
```
```   658   apply simp
```
```   659   done
```
```   660
```
```   661 lemma finite_Domain: "finite r ==> finite (Domain r)"
```
```   662   by (induct set: finite) (auto simp add: Domain_insert)
```
```   663
```
```   664 lemma finite_Range: "finite r ==> finite (Range r)"
```
```   665   by (induct set: finite) (auto simp add: Range_insert)
```
```   666
```
```   667 lemma finite_Field: "finite r ==> finite (Field r)"
```
```   668   -- {* A finite relation has a finite field (@{text "= domain \<union> range"}. *}
```
```   669   apply (induct set: finite)
```
```   670    apply (auto simp add: Field_def Domain_insert Range_insert)
```
```   671   done
```
```   672
```
```   673
```
```   674 subsection {* Miscellaneous *}
```
```   675
```
```   676 text {* Version of @{thm[source] lfp_induct} for binary relations *}
```
```   677
```
```   678 lemmas lfp_induct2 =
```
```   679   lfp_induct_set [of "(a, b)", split_format (complete)]
```
```   680
```
```   681 text {* Version of @{thm[source] subsetI} for binary relations *}
```
```   682
```
```   683 lemma subrelI: "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (x, y) \<in> s) \<Longrightarrow> r \<subseteq> s"
```
```   684 by auto
```
```   685
```
```   686 end
```