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