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