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