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