src/HOL/Relation.thy
author berghofe
Thu Oct 10 14:23:19 2002 +0200 (2002-10-10)
changeset 13639 8ee6ea6627e1
parent 13550 5a176b8dda84
child 13812 91713a1915ee
permissions -rw-r--r--
Removed obsolete function "fun_rel_comp".
     1 (*  Title:      HOL/Relation.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 *)
     6 
     7 header {* Relations *}
     8 
     9 theory Relation = Product_Type:
    10 
    11 subsection {* Definitions *}
    12 
    13 constdefs
    14   converse :: "('a * 'b) set => ('b * 'a) set"    ("(_^-1)" [1000] 999)
    15   "r^-1 == {(y, x). (x, y) : r}"
    16 syntax (xsymbols)
    17   converse :: "('a * 'b) set => ('b * 'a) set"    ("(_\<inverse>)" [1000] 999)
    18 
    19 constdefs
    20   rel_comp  :: "[('b * 'c) set, ('a * 'b) set] => ('a * 'c) set"  (infixr "O" 60)
    21   "r O s == {(x,z). EX y. (x, y) : s & (y, z) : r}"
    22 
    23   Image :: "[('a * 'b) set, 'a set] => 'b set"                (infixl "``" 90)
    24   "r `` s == {y. EX x:s. (x,y):r}"
    25 
    26   Id    :: "('a * 'a) set"  -- {* the identity relation *}
    27   "Id == {p. EX x. p = (x,x)}"
    28 
    29   diag  :: "'a set => ('a * 'a) set"  -- {* diagonal: identity over a set *}
    30   "diag A == UN x:A. {(x,x)}"
    31 
    32   Domain :: "('a * 'b) set => 'a set"
    33   "Domain r == {x. EX y. (x,y):r}"
    34 
    35   Range  :: "('a * 'b) set => 'b set"
    36   "Range r == Domain(r^-1)"
    37 
    38   Field :: "('a * 'a) set => 'a set"
    39   "Field r == Domain r Un Range r"
    40 
    41   refl   :: "['a set, ('a * 'a) set] => bool"  -- {* reflexivity over a set *}
    42   "refl A r == r \<subseteq> A \<times> A & (ALL x: A. (x,x) : r)"
    43 
    44   sym    :: "('a * 'a) set => bool"  -- {* symmetry predicate *}
    45   "sym r == ALL x y. (x,y): r --> (y,x): r"
    46 
    47   antisym:: "('a * 'a) set => bool"  -- {* antisymmetry predicate *}
    48   "antisym r == ALL x y. (x,y):r --> (y,x):r --> x=y"
    49 
    50   trans  :: "('a * 'a) set => bool"  -- {* transitivity predicate *}
    51   "trans r == (ALL x y z. (x,y):r --> (y,z):r --> (x,z):r)"
    52 
    53   single_valued :: "('a * 'b) set => bool"
    54   "single_valued r == ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z)"
    55 
    56   inv_image :: "('b * 'b) set => ('a => 'b) => ('a * 'a) set"
    57   "inv_image r f == {(x, y). (f x, f y) : r}"
    58 
    59 syntax
    60   reflexive :: "('a * 'a) set => bool"  -- {* reflexivity over a type *}
    61 translations
    62   "reflexive" == "refl UNIV"
    63 
    64 
    65 subsection {* The identity relation *}
    66 
    67 lemma IdI [intro]: "(a, a) : Id"
    68   by (simp add: Id_def)
    69 
    70 lemma IdE [elim!]: "p : Id ==> (!!x. p = (x, x) ==> P) ==> P"
    71   by (unfold Id_def) (rules elim: CollectE)
    72 
    73 lemma pair_in_Id_conv [iff]: "((a, b) : Id) = (a = b)"
    74   by (unfold Id_def) blast
    75 
    76 lemma reflexive_Id: "reflexive Id"
    77   by (simp add: refl_def)
    78 
    79 lemma antisym_Id: "antisym Id"
    80   -- {* A strange result, since @{text Id} is also symmetric. *}
    81   by (simp add: antisym_def)
    82 
    83 lemma trans_Id: "trans Id"
    84   by (simp add: trans_def)
    85 
    86 
    87 subsection {* Diagonal: identity over a set *}
    88 
    89 lemma diag_eqI: "a = b ==> a : A ==> (a, b) : diag A"
    90   by (simp add: diag_def)
    91 
    92 lemma diagI [intro!]: "a : A ==> (a, a) : diag A"
    93   by (rule diag_eqI) (rule refl)
    94 
    95 lemma diagE [elim!]:
    96   "c : diag A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P"
    97   -- {* The general elimination rule. *}
    98   by (unfold diag_def) (rules elim!: UN_E singletonE)
    99 
   100 lemma diag_iff: "((x, y) : diag A) = (x = y & x : A)"
   101   by blast
   102 
   103 lemma diag_subset_Times: "diag A \<subseteq> A \<times> A"
   104   by blast
   105 
   106 
   107 subsection {* Composition of two relations *}
   108 
   109 lemma rel_compI [intro]:
   110   "(a, b) : s ==> (b, c) : r ==> (a, c) : r O s"
   111   by (unfold rel_comp_def) blast
   112 
   113 lemma rel_compE [elim!]: "xz : r O s ==>
   114   (!!x y z. xz = (x, z) ==> (x, y) : s ==> (y, z) : r  ==> P) ==> P"
   115   by (unfold rel_comp_def) (rules elim!: CollectE splitE exE conjE)
   116 
   117 lemma rel_compEpair:
   118   "(a, c) : r O s ==> (!!y. (a, y) : s ==> (y, c) : r ==> P) ==> P"
   119   by (rules elim: rel_compE Pair_inject ssubst)
   120 
   121 lemma R_O_Id [simp]: "R O Id = R"
   122   by fast
   123 
   124 lemma Id_O_R [simp]: "Id O R = R"
   125   by fast
   126 
   127 lemma O_assoc: "(R O S) O T = R O (S O T)"
   128   by blast
   129 
   130 lemma trans_O_subset: "trans r ==> r O r \<subseteq> r"
   131   by (unfold trans_def) blast
   132 
   133 lemma rel_comp_mono: "r' \<subseteq> r ==> s' \<subseteq> s ==> (r' O s') \<subseteq> (r O s)"
   134   by blast
   135 
   136 lemma rel_comp_subset_Sigma:
   137     "s \<subseteq> A \<times> B ==> r \<subseteq> B \<times> C ==> (r O s) \<subseteq> A \<times> C"
   138   by blast
   139 
   140 
   141 subsection {* Reflexivity *}
   142 
   143 lemma reflI: "r \<subseteq> A \<times> A ==> (!!x. x : A ==> (x, x) : r) ==> refl A r"
   144   by (unfold refl_def) (rules intro!: ballI)
   145 
   146 lemma reflD: "refl A r ==> a : A ==> (a, a) : r"
   147   by (unfold refl_def) blast
   148 
   149 
   150 subsection {* Antisymmetry *}
   151 
   152 lemma antisymI:
   153   "(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r"
   154   by (unfold antisym_def) rules
   155 
   156 lemma antisymD: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b"
   157   by (unfold antisym_def) rules
   158 
   159 
   160 subsection {* Transitivity *}
   161 
   162 lemma transI:
   163   "(!!x y z. (x, y) : r ==> (y, z) : r ==> (x, z) : r) ==> trans r"
   164   by (unfold trans_def) rules
   165 
   166 lemma transD: "trans r ==> (a, b) : r ==> (b, c) : r ==> (a, c) : r"
   167   by (unfold trans_def) rules
   168 
   169 
   170 subsection {* Converse *}
   171 
   172 lemma converse_iff [iff]: "((a,b): r^-1) = ((b,a) : r)"
   173   by (simp add: converse_def)
   174 
   175 lemma converseI[sym]: "(a, b) : r ==> (b, a) : r^-1"
   176   by (simp add: converse_def)
   177 
   178 lemma converseD[sym]: "(a,b) : r^-1 ==> (b, a) : r"
   179   by (simp add: converse_def)
   180 
   181 lemma converseE [elim!]:
   182   "yx : r^-1 ==> (!!x y. yx = (y, x) ==> (x, y) : r ==> P) ==> P"
   183     -- {* More general than @{text converseD}, as it ``splits'' the member of the relation. *}
   184   by (unfold converse_def) (rules elim!: CollectE splitE bexE)
   185 
   186 lemma converse_converse [simp]: "(r^-1)^-1 = r"
   187   by (unfold converse_def) blast
   188 
   189 lemma converse_rel_comp: "(r O s)^-1 = s^-1 O r^-1"
   190   by blast
   191 
   192 lemma converse_Id [simp]: "Id^-1 = Id"
   193   by blast
   194 
   195 lemma converse_diag [simp]: "(diag A)^-1 = diag A"
   196   by blast
   197 
   198 lemma refl_converse: "refl A r ==> refl A (converse r)"
   199   by (unfold refl_def) blast
   200 
   201 lemma antisym_converse: "antisym (converse r) = antisym r"
   202   by (unfold antisym_def) blast
   203 
   204 lemma trans_converse: "trans (converse r) = trans r"
   205   by (unfold trans_def) blast
   206 
   207 
   208 subsection {* Domain *}
   209 
   210 lemma Domain_iff: "(a : Domain r) = (EX y. (a, y) : r)"
   211   by (unfold Domain_def) blast
   212 
   213 lemma DomainI [intro]: "(a, b) : r ==> a : Domain r"
   214   by (rules intro!: iffD2 [OF Domain_iff])
   215 
   216 lemma DomainE [elim!]:
   217   "a : Domain r ==> (!!y. (a, y) : r ==> P) ==> P"
   218   by (rules dest!: iffD1 [OF Domain_iff])
   219 
   220 lemma Domain_empty [simp]: "Domain {} = {}"
   221   by blast
   222 
   223 lemma Domain_insert: "Domain (insert (a, b) r) = insert a (Domain r)"
   224   by blast
   225 
   226 lemma Domain_Id [simp]: "Domain Id = UNIV"
   227   by blast
   228 
   229 lemma Domain_diag [simp]: "Domain (diag A) = A"
   230   by blast
   231 
   232 lemma Domain_Un_eq: "Domain(A Un B) = Domain(A) Un Domain(B)"
   233   by blast
   234 
   235 lemma Domain_Int_subset: "Domain(A Int B) \<subseteq> Domain(A) Int Domain(B)"
   236   by blast
   237 
   238 lemma Domain_Diff_subset: "Domain(A) - Domain(B) \<subseteq> Domain(A - B)"
   239   by blast
   240 
   241 lemma Domain_Union: "Domain (Union S) = (UN A:S. Domain A)"
   242   by blast
   243 
   244 lemma Domain_mono: "r \<subseteq> s ==> Domain r \<subseteq> Domain s"
   245   by blast
   246 
   247 
   248 subsection {* Range *}
   249 
   250 lemma Range_iff: "(a : Range r) = (EX y. (y, a) : r)"
   251   by (simp add: Domain_def Range_def)
   252 
   253 lemma RangeI [intro]: "(a, b) : r ==> b : Range r"
   254   by (unfold Range_def) (rules intro!: converseI DomainI)
   255 
   256 lemma RangeE [elim!]: "b : Range r ==> (!!x. (x, b) : r ==> P) ==> P"
   257   by (unfold Range_def) (rules elim!: DomainE dest!: converseD)
   258 
   259 lemma Range_empty [simp]: "Range {} = {}"
   260   by blast
   261 
   262 lemma Range_insert: "Range (insert (a, b) r) = insert b (Range r)"
   263   by blast
   264 
   265 lemma Range_Id [simp]: "Range Id = UNIV"
   266   by blast
   267 
   268 lemma Range_diag [simp]: "Range (diag A) = A"
   269   by auto
   270 
   271 lemma Range_Un_eq: "Range(A Un B) = Range(A) Un Range(B)"
   272   by blast
   273 
   274 lemma Range_Int_subset: "Range(A Int B) \<subseteq> Range(A) Int Range(B)"
   275   by blast
   276 
   277 lemma Range_Diff_subset: "Range(A) - Range(B) \<subseteq> Range(A - B)"
   278   by blast
   279 
   280 lemma Range_Union: "Range (Union S) = (UN A:S. Range A)"
   281   by blast
   282 
   283 
   284 subsection {* Image of a set under a relation *}
   285 
   286 lemma Image_iff: "(b : r``A) = (EX x:A. (x, b) : r)"
   287   by (simp add: Image_def)
   288 
   289 lemma Image_singleton: "r``{a} = {b. (a, b) : r}"
   290   by (simp add: Image_def)
   291 
   292 lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a, b) : r)"
   293   by (rule Image_iff [THEN trans]) simp
   294 
   295 lemma ImageI [intro]: "(a, b) : r ==> a : A ==> b : r``A"
   296   by (unfold Image_def) blast
   297 
   298 lemma ImageE [elim!]:
   299     "b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P"
   300   by (unfold Image_def) (rules elim!: CollectE bexE)
   301 
   302 lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A"
   303   -- {* This version's more effective when we already have the required @{text a} *}
   304   by blast
   305 
   306 lemma Image_empty [simp]: "R``{} = {}"
   307   by blast
   308 
   309 lemma Image_Id [simp]: "Id `` A = A"
   310   by blast
   311 
   312 lemma Image_diag [simp]: "diag A `` B = A Int B"
   313   by blast
   314 
   315 lemma Image_Int_subset: "R `` (A Int B) \<subseteq> R `` A Int R `` B"
   316   by blast
   317 
   318 lemma Image_Un: "R `` (A Un B) = R `` A Un R `` B"
   319   by blast
   320 
   321 lemma Image_subset: "r \<subseteq> A \<times> B ==> r``C \<subseteq> B"
   322   by (rules intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2)
   323 
   324 lemma Image_eq_UN: "r``B = (UN y: B. r``{y})"
   325   -- {* NOT suitable for rewriting *}
   326   by blast
   327 
   328 lemma Image_mono: "r' \<subseteq> r ==> A' \<subseteq> A ==> (r' `` A') \<subseteq> (r `` A)"
   329   by blast
   330 
   331 lemma Image_UN: "(r `` (UNION A B)) = (UN x:A.(r `` (B x)))"
   332   by blast
   333 
   334 lemma Image_INT_subset: "(r `` (INTER A B)) \<subseteq> (INT x:A.(r `` (B x)))"
   335   -- {* Converse inclusion fails *}
   336   by blast
   337 
   338 lemma Image_subset_eq: "(r``A \<subseteq> B) = (A \<subseteq> - ((r^-1) `` (-B)))"
   339   by blast
   340 
   341 
   342 subsection {* Single valued relations *}
   343 
   344 lemma single_valuedI:
   345   "ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r"
   346   by (unfold single_valued_def)
   347 
   348 lemma single_valuedD:
   349   "single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z"
   350   by (simp add: single_valued_def)
   351 
   352 
   353 subsection {* Graphs given by @{text Collect} *}
   354 
   355 lemma Domain_Collect_split [simp]: "Domain{(x,y). P x y} = {x. EX y. P x y}"
   356   by auto
   357 
   358 lemma Range_Collect_split [simp]: "Range{(x,y). P x y} = {y. EX x. P x y}"
   359   by auto
   360 
   361 lemma Image_Collect_split [simp]: "{(x,y). P x y} `` A = {y. EX x:A. P x y}"
   362   by auto
   363 
   364 
   365 subsection {* Inverse image *}
   366 
   367 lemma trans_inv_image: "trans r ==> trans (inv_image r f)"
   368   apply (unfold trans_def inv_image_def)
   369   apply (simp (no_asm))
   370   apply blast
   371   done
   372 
   373 end