src/HOL/Relation.thy
author wenzelm
Fri Dec 17 17:43:54 2010 +0100 (2010-12-17)
changeset 41229 d797baa3d57c
parent 41056 dcec9bc71ee9
child 41792 ff3cb0c418b7
permissions -rw-r--r--
replaced command 'nonterminals' by slightly modernized version 'nonterminal';
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@32850
     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
krauss@32235
    23
  rel_comp  :: "[('a * 'b) set, ('b * 'c) set] => ('a * 'c) set"
wenzelm@21404
    24
    (infixr "O" 75) where
krauss@32235
    25
  "r O s == {(x,z). EX y. (x, y) : r & (y, z) : s}"
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
nipkow@30198
    37
  Id_on  :: "'a set => ('a * 'a) set" where -- {* diagonal: identity over a set *}
nipkow@30198
    38
  "Id_on 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
nipkow@30198
    53
  refl_on :: "['a set, ('a * 'a) set] => bool" where -- {* reflexivity over a set *}
nipkow@30198
    54
  "refl_on A r == r \<subseteq> A \<times> A & (ALL x: A. (x,x) : r)"
paulson@6806
    55
nipkow@26297
    56
abbreviation
nipkow@30198
    57
  refl :: "('a * 'a) set => bool" where -- {* reflexivity over a type *}
nipkow@30198
    58
  "refl == refl_on 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
nipkow@30198
   102
lemma refl_Id: "refl Id"
nipkow@30198
   103
by (simp add: refl_on_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
nipkow@30198
   118
lemma Id_on_empty [simp]: "Id_on {} = {}"
nipkow@30198
   119
by (simp add: Id_on_def) 
paulson@13812
   120
nipkow@30198
   121
lemma Id_on_eqI: "a = b ==> a : A ==> (a, b) : Id_on A"
nipkow@30198
   122
by (simp add: Id_on_def)
berghofe@12905
   123
blanchet@35828
   124
lemma Id_onI [intro!,no_atp]: "a : A ==> (a, a) : Id_on A"
nipkow@30198
   125
by (rule Id_on_eqI) (rule refl)
berghofe@12905
   126
nipkow@30198
   127
lemma Id_onE [elim!]:
nipkow@30198
   128
  "c : Id_on A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P"
wenzelm@12913
   129
  -- {* The general elimination rule. *}
nipkow@30198
   130
by (unfold Id_on_def) (iprover elim!: UN_E singletonE)
berghofe@12905
   131
nipkow@30198
   132
lemma Id_on_iff: "((x, y) : Id_on A) = (x = y & x : A)"
nipkow@26271
   133
by blast
berghofe@12905
   134
bulwahn@40923
   135
lemma Id_on_def'[nitpick_def, code]:
bulwahn@40923
   136
  "(Id_on (A :: 'a => bool)) = (%(x, y). x = y \<and> A x)"
bulwahn@40923
   137
by (auto simp add: fun_eq_iff
bulwahn@40923
   138
  elim: Id_onE[unfolded mem_def] intro: Id_onI[unfolded mem_def])
bulwahn@40923
   139
nipkow@30198
   140
lemma Id_on_subset_Times: "Id_on A \<subseteq> A \<times> A"
nipkow@26271
   141
by blast
berghofe@12905
   142
berghofe@12905
   143
berghofe@12905
   144
subsection {* Composition of two relations *}
berghofe@12905
   145
wenzelm@12913
   146
lemma rel_compI [intro]:
krauss@32235
   147
  "(a, b) : r ==> (b, c) : s ==> (a, c) : r O s"
nipkow@26271
   148
by (unfold rel_comp_def) blast
berghofe@12905
   149
wenzelm@12913
   150
lemma rel_compE [elim!]: "xz : r O s ==>
krauss@32235
   151
  (!!x y z. xz = (x, z) ==> (x, y) : r ==> (y, z) : s  ==> P) ==> P"
nipkow@26271
   152
by (unfold rel_comp_def) (iprover elim!: CollectE splitE exE conjE)
berghofe@12905
   153
berghofe@12905
   154
lemma rel_compEpair:
krauss@32235
   155
  "(a, c) : r O s ==> (!!y. (a, y) : r ==> (y, c) : s ==> P) ==> P"
nipkow@26271
   156
by (iprover elim: rel_compE Pair_inject ssubst)
berghofe@12905
   157
berghofe@12905
   158
lemma R_O_Id [simp]: "R O Id = R"
nipkow@26271
   159
by fast
berghofe@12905
   160
berghofe@12905
   161
lemma Id_O_R [simp]: "Id O R = R"
nipkow@26271
   162
by fast
berghofe@12905
   163
krauss@23185
   164
lemma rel_comp_empty1[simp]: "{} O R = {}"
nipkow@26271
   165
by blast
krauss@23185
   166
krauss@23185
   167
lemma rel_comp_empty2[simp]: "R O {} = {}"
nipkow@26271
   168
by blast
krauss@23185
   169
berghofe@12905
   170
lemma O_assoc: "(R O S) O T = R O (S O T)"
nipkow@26271
   171
by blast
berghofe@12905
   172
wenzelm@12913
   173
lemma trans_O_subset: "trans r ==> r O r \<subseteq> r"
nipkow@26271
   174
by (unfold trans_def) blast
berghofe@12905
   175
wenzelm@12913
   176
lemma rel_comp_mono: "r' \<subseteq> r ==> s' \<subseteq> s ==> (r' O s') \<subseteq> (r O s)"
nipkow@26271
   177
by blast
berghofe@12905
   178
berghofe@12905
   179
lemma rel_comp_subset_Sigma:
krauss@32235
   180
    "r \<subseteq> A \<times> B ==> s \<subseteq> B \<times> C ==> (r O s) \<subseteq> A \<times> C"
nipkow@26271
   181
by blast
berghofe@12905
   182
krauss@28008
   183
lemma rel_comp_distrib[simp]: "R O (S \<union> T) = (R O S) \<union> (R O T)" 
krauss@28008
   184
by auto
krauss@28008
   185
krauss@28008
   186
lemma rel_comp_distrib2[simp]: "(S \<union> T) O R = (S O R) \<union> (T O R)"
krauss@28008
   187
by auto
krauss@28008
   188
krauss@36772
   189
lemma rel_comp_UNION_distrib: "s O UNION I r = UNION I (%i. s O r i)"
krauss@36772
   190
by auto
krauss@36772
   191
krauss@36772
   192
lemma rel_comp_UNION_distrib2: "UNION I r O s = UNION I (%i. r i O s)"
krauss@36772
   193
by auto
krauss@36772
   194
wenzelm@12913
   195
wenzelm@12913
   196
subsection {* Reflexivity *}
wenzelm@12913
   197
nipkow@30198
   198
lemma refl_onI: "r \<subseteq> A \<times> A ==> (!!x. x : A ==> (x, x) : r) ==> refl_on A r"
nipkow@30198
   199
by (unfold refl_on_def) (iprover intro!: ballI)
berghofe@12905
   200
nipkow@30198
   201
lemma refl_onD: "refl_on A r ==> a : A ==> (a, a) : r"
nipkow@30198
   202
by (unfold refl_on_def) blast
berghofe@12905
   203
nipkow@30198
   204
lemma refl_onD1: "refl_on A r ==> (x, y) : r ==> x : A"
nipkow@30198
   205
by (unfold refl_on_def) blast
huffman@19228
   206
nipkow@30198
   207
lemma refl_onD2: "refl_on A r ==> (x, y) : r ==> y : A"
nipkow@30198
   208
by (unfold refl_on_def) blast
huffman@19228
   209
nipkow@30198
   210
lemma refl_on_Int: "refl_on A r ==> refl_on B s ==> refl_on (A \<inter> B) (r \<inter> s)"
nipkow@30198
   211
by (unfold refl_on_def) blast
huffman@19228
   212
nipkow@30198
   213
lemma refl_on_Un: "refl_on A r ==> refl_on B s ==> refl_on (A \<union> B) (r \<union> s)"
nipkow@30198
   214
by (unfold refl_on_def) blast
huffman@19228
   215
nipkow@30198
   216
lemma refl_on_INTER:
nipkow@30198
   217
  "ALL x:S. refl_on (A x) (r x) ==> refl_on (INTER S A) (INTER S r)"
nipkow@30198
   218
by (unfold refl_on_def) fast
huffman@19228
   219
nipkow@30198
   220
lemma refl_on_UNION:
nipkow@30198
   221
  "ALL x:S. refl_on (A x) (r x) \<Longrightarrow> refl_on (UNION S A) (UNION S r)"
nipkow@30198
   222
by (unfold refl_on_def) blast
huffman@19228
   223
nipkow@30198
   224
lemma refl_on_empty[simp]: "refl_on {} {}"
nipkow@30198
   225
by(simp add:refl_on_def)
nipkow@26297
   226
nipkow@30198
   227
lemma refl_on_Id_on: "refl_on A (Id_on A)"
nipkow@30198
   228
by (rule refl_onI [OF Id_on_subset_Times Id_onI])
huffman@19228
   229
bulwahn@41056
   230
lemma refl_on_def'[nitpick_def, code]:
bulwahn@41056
   231
  "refl_on A r = ((\<forall>(x, y) \<in> r. x : A \<and> y : A) \<and> (\<forall>x \<in> A. (x, x) : r))"
bulwahn@41056
   232
by (auto intro: refl_onI dest: refl_onD refl_onD1 refl_onD2)
wenzelm@12913
   233
wenzelm@12913
   234
subsection {* Antisymmetry *}
berghofe@12905
   235
berghofe@12905
   236
lemma antisymI:
berghofe@12905
   237
  "(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r"
nipkow@26271
   238
by (unfold antisym_def) iprover
berghofe@12905
   239
berghofe@12905
   240
lemma antisymD: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b"
nipkow@26271
   241
by (unfold antisym_def) iprover
berghofe@12905
   242
huffman@19228
   243
lemma antisym_subset: "r \<subseteq> s ==> antisym s ==> antisym r"
nipkow@26271
   244
by (unfold antisym_def) blast
wenzelm@12913
   245
huffman@19228
   246
lemma antisym_empty [simp]: "antisym {}"
nipkow@26271
   247
by (unfold antisym_def) blast
huffman@19228
   248
nipkow@30198
   249
lemma antisym_Id_on [simp]: "antisym (Id_on A)"
nipkow@26271
   250
by (unfold antisym_def) blast
huffman@19228
   251
huffman@19228
   252
huffman@19228
   253
subsection {* Symmetry *}
huffman@19228
   254
huffman@19228
   255
lemma symI: "(!!a b. (a, b) : r ==> (b, a) : r) ==> sym r"
nipkow@26271
   256
by (unfold sym_def) iprover
paulson@15177
   257
paulson@15177
   258
lemma symD: "sym r ==> (a, b) : r ==> (b, a) : r"
nipkow@26271
   259
by (unfold sym_def, blast)
berghofe@12905
   260
huffman@19228
   261
lemma sym_Int: "sym r ==> sym s ==> sym (r \<inter> s)"
nipkow@26271
   262
by (fast intro: symI dest: symD)
huffman@19228
   263
huffman@19228
   264
lemma sym_Un: "sym r ==> sym s ==> sym (r \<union> s)"
nipkow@26271
   265
by (fast intro: symI dest: symD)
huffman@19228
   266
huffman@19228
   267
lemma sym_INTER: "ALL x:S. sym (r x) ==> sym (INTER S r)"
nipkow@26271
   268
by (fast intro: symI dest: symD)
huffman@19228
   269
huffman@19228
   270
lemma sym_UNION: "ALL x:S. sym (r x) ==> sym (UNION S r)"
nipkow@26271
   271
by (fast intro: symI dest: symD)
huffman@19228
   272
nipkow@30198
   273
lemma sym_Id_on [simp]: "sym (Id_on A)"
nipkow@26271
   274
by (rule symI) clarify
huffman@19228
   275
huffman@19228
   276
huffman@19228
   277
subsection {* Transitivity *}
huffman@19228
   278
berghofe@12905
   279
lemma transI:
berghofe@12905
   280
  "(!!x y z. (x, y) : r ==> (y, z) : r ==> (x, z) : r) ==> trans r"
nipkow@26271
   281
by (unfold trans_def) iprover
berghofe@12905
   282
berghofe@12905
   283
lemma transD: "trans r ==> (a, b) : r ==> (b, c) : r ==> (a, c) : r"
nipkow@26271
   284
by (unfold trans_def) iprover
berghofe@12905
   285
huffman@19228
   286
lemma trans_Int: "trans r ==> trans s ==> trans (r \<inter> s)"
nipkow@26271
   287
by (fast intro: transI elim: transD)
huffman@19228
   288
huffman@19228
   289
lemma trans_INTER: "ALL x:S. trans (r x) ==> trans (INTER S r)"
nipkow@26271
   290
by (fast intro: transI elim: transD)
huffman@19228
   291
nipkow@30198
   292
lemma trans_Id_on [simp]: "trans (Id_on A)"
nipkow@26271
   293
by (fast intro: transI elim: transD)
huffman@19228
   294
nipkow@29859
   295
lemma trans_diff_Id: " trans r \<Longrightarrow> antisym r \<Longrightarrow> trans (r-Id)"
nipkow@29859
   296
unfolding antisym_def trans_def by blast
nipkow@29859
   297
nipkow@29859
   298
subsection {* Irreflexivity *}
nipkow@29859
   299
nipkow@29859
   300
lemma irrefl_diff_Id[simp]: "irrefl(r-Id)"
nipkow@29859
   301
by(simp add:irrefl_def)
nipkow@29859
   302
nipkow@29859
   303
subsection {* Totality *}
nipkow@29859
   304
nipkow@29859
   305
lemma total_on_empty[simp]: "total_on {} r"
nipkow@29859
   306
by(simp add:total_on_def)
nipkow@29859
   307
nipkow@29859
   308
lemma total_on_diff_Id[simp]: "total_on A (r-Id) = total_on A r"
nipkow@29859
   309
by(simp add: total_on_def)
berghofe@12905
   310
wenzelm@12913
   311
subsection {* Converse *}
wenzelm@12913
   312
wenzelm@12913
   313
lemma converse_iff [iff]: "((a,b): r^-1) = ((b,a) : r)"
nipkow@26271
   314
by (simp add: converse_def)
berghofe@12905
   315
nipkow@13343
   316
lemma converseI[sym]: "(a, b) : r ==> (b, a) : r^-1"
nipkow@26271
   317
by (simp add: converse_def)
berghofe@12905
   318
nipkow@13343
   319
lemma converseD[sym]: "(a,b) : r^-1 ==> (b, a) : r"
nipkow@26271
   320
by (simp add: converse_def)
berghofe@12905
   321
berghofe@12905
   322
lemma converseE [elim!]:
berghofe@12905
   323
  "yx : r^-1 ==> (!!x y. yx = (y, x) ==> (x, y) : r ==> P) ==> P"
wenzelm@12913
   324
    -- {* More general than @{text converseD}, as it ``splits'' the member of the relation. *}
nipkow@26271
   325
by (unfold converse_def) (iprover elim!: CollectE splitE bexE)
berghofe@12905
   326
berghofe@12905
   327
lemma converse_converse [simp]: "(r^-1)^-1 = r"
nipkow@26271
   328
by (unfold converse_def) blast
berghofe@12905
   329
berghofe@12905
   330
lemma converse_rel_comp: "(r O s)^-1 = s^-1 O r^-1"
nipkow@26271
   331
by blast
berghofe@12905
   332
huffman@19228
   333
lemma converse_Int: "(r \<inter> s)^-1 = r^-1 \<inter> s^-1"
nipkow@26271
   334
by blast
huffman@19228
   335
huffman@19228
   336
lemma converse_Un: "(r \<union> s)^-1 = r^-1 \<union> s^-1"
nipkow@26271
   337
by blast
huffman@19228
   338
huffman@19228
   339
lemma converse_INTER: "(INTER S r)^-1 = (INT x:S. (r x)^-1)"
nipkow@26271
   340
by fast
huffman@19228
   341
huffman@19228
   342
lemma converse_UNION: "(UNION S r)^-1 = (UN x:S. (r x)^-1)"
nipkow@26271
   343
by blast
huffman@19228
   344
berghofe@12905
   345
lemma converse_Id [simp]: "Id^-1 = Id"
nipkow@26271
   346
by blast
berghofe@12905
   347
nipkow@30198
   348
lemma converse_Id_on [simp]: "(Id_on A)^-1 = Id_on A"
nipkow@26271
   349
by blast
berghofe@12905
   350
nipkow@30198
   351
lemma refl_on_converse [simp]: "refl_on A (converse r) = refl_on A r"
nipkow@30198
   352
by (unfold refl_on_def) auto
berghofe@12905
   353
huffman@19228
   354
lemma sym_converse [simp]: "sym (converse r) = sym r"
nipkow@26271
   355
by (unfold sym_def) blast
huffman@19228
   356
huffman@19228
   357
lemma antisym_converse [simp]: "antisym (converse r) = antisym r"
nipkow@26271
   358
by (unfold antisym_def) blast
berghofe@12905
   359
huffman@19228
   360
lemma trans_converse [simp]: "trans (converse r) = trans r"
nipkow@26271
   361
by (unfold trans_def) blast
berghofe@12905
   362
huffman@19228
   363
lemma sym_conv_converse_eq: "sym r = (r^-1 = r)"
nipkow@26271
   364
by (unfold sym_def) fast
huffman@19228
   365
huffman@19228
   366
lemma sym_Un_converse: "sym (r \<union> r^-1)"
nipkow@26271
   367
by (unfold sym_def) blast
huffman@19228
   368
huffman@19228
   369
lemma sym_Int_converse: "sym (r \<inter> r^-1)"
nipkow@26271
   370
by (unfold sym_def) blast
huffman@19228
   371
nipkow@29859
   372
lemma total_on_converse[simp]: "total_on A (r^-1) = total_on A r"
nipkow@29859
   373
by (auto simp: total_on_def)
nipkow@29859
   374
wenzelm@12913
   375
berghofe@12905
   376
subsection {* Domain *}
berghofe@12905
   377
blanchet@35828
   378
declare Domain_def [no_atp]
paulson@24286
   379
berghofe@12905
   380
lemma Domain_iff: "(a : Domain r) = (EX y. (a, y) : r)"
nipkow@26271
   381
by (unfold Domain_def) blast
berghofe@12905
   382
berghofe@12905
   383
lemma DomainI [intro]: "(a, b) : r ==> a : Domain r"
nipkow@26271
   384
by (iprover intro!: iffD2 [OF Domain_iff])
berghofe@12905
   385
berghofe@12905
   386
lemma DomainE [elim!]:
berghofe@12905
   387
  "a : Domain r ==> (!!y. (a, y) : r ==> P) ==> P"
nipkow@26271
   388
by (iprover dest!: iffD1 [OF Domain_iff])
berghofe@12905
   389
berghofe@12905
   390
lemma Domain_empty [simp]: "Domain {} = {}"
nipkow@26271
   391
by blast
berghofe@12905
   392
paulson@32876
   393
lemma Domain_empty_iff: "Domain r = {} \<longleftrightarrow> r = {}"
paulson@32876
   394
  by auto
paulson@32876
   395
berghofe@12905
   396
lemma Domain_insert: "Domain (insert (a, b) r) = insert a (Domain r)"
nipkow@26271
   397
by blast
berghofe@12905
   398
berghofe@12905
   399
lemma Domain_Id [simp]: "Domain Id = UNIV"
nipkow@26271
   400
by blast
berghofe@12905
   401
nipkow@30198
   402
lemma Domain_Id_on [simp]: "Domain (Id_on A) = A"
nipkow@26271
   403
by blast
berghofe@12905
   404
paulson@13830
   405
lemma Domain_Un_eq: "Domain(A \<union> B) = Domain(A) \<union> Domain(B)"
nipkow@26271
   406
by blast
berghofe@12905
   407
paulson@13830
   408
lemma Domain_Int_subset: "Domain(A \<inter> B) \<subseteq> Domain(A) \<inter> Domain(B)"
nipkow@26271
   409
by blast
berghofe@12905
   410
wenzelm@12913
   411
lemma Domain_Diff_subset: "Domain(A) - Domain(B) \<subseteq> Domain(A - B)"
nipkow@26271
   412
by blast
berghofe@12905
   413
paulson@13830
   414
lemma Domain_Union: "Domain (Union S) = (\<Union>A\<in>S. Domain A)"
nipkow@26271
   415
by blast
nipkow@26271
   416
nipkow@26271
   417
lemma Domain_converse[simp]: "Domain(r^-1) = Range r"
nipkow@26271
   418
by(auto simp:Range_def)
berghofe@12905
   419
wenzelm@12913
   420
lemma Domain_mono: "r \<subseteq> s ==> Domain r \<subseteq> Domain s"
nipkow@26271
   421
by blast
berghofe@12905
   422
krauss@36729
   423
lemma fst_eq_Domain: "fst ` R = Domain R"
nipkow@26271
   424
by (auto intro!:image_eqI)
paulson@22172
   425
haftmann@29609
   426
lemma Domain_dprod [simp]: "Domain (dprod r s) = uprod (Domain r) (Domain s)"
haftmann@29609
   427
by auto
haftmann@29609
   428
haftmann@29609
   429
lemma Domain_dsum [simp]: "Domain (dsum r s) = usum (Domain r) (Domain s)"
haftmann@29609
   430
by auto
haftmann@29609
   431
berghofe@12905
   432
berghofe@12905
   433
subsection {* Range *}
berghofe@12905
   434
berghofe@12905
   435
lemma Range_iff: "(a : Range r) = (EX y. (y, a) : r)"
nipkow@26271
   436
by (simp add: Domain_def Range_def)
berghofe@12905
   437
berghofe@12905
   438
lemma RangeI [intro]: "(a, b) : r ==> b : Range r"
nipkow@26271
   439
by (unfold Range_def) (iprover intro!: converseI DomainI)
berghofe@12905
   440
berghofe@12905
   441
lemma RangeE [elim!]: "b : Range r ==> (!!x. (x, b) : r ==> P) ==> P"
nipkow@26271
   442
by (unfold Range_def) (iprover elim!: DomainE dest!: converseD)
berghofe@12905
   443
berghofe@12905
   444
lemma Range_empty [simp]: "Range {} = {}"
nipkow@26271
   445
by blast
berghofe@12905
   446
paulson@32876
   447
lemma Range_empty_iff: "Range r = {} \<longleftrightarrow> r = {}"
paulson@32876
   448
  by auto
paulson@32876
   449
berghofe@12905
   450
lemma Range_insert: "Range (insert (a, b) r) = insert b (Range r)"
nipkow@26271
   451
by blast
berghofe@12905
   452
berghofe@12905
   453
lemma Range_Id [simp]: "Range Id = UNIV"
nipkow@26271
   454
by blast
berghofe@12905
   455
nipkow@30198
   456
lemma Range_Id_on [simp]: "Range (Id_on A) = A"
nipkow@26271
   457
by auto
berghofe@12905
   458
paulson@13830
   459
lemma Range_Un_eq: "Range(A \<union> B) = Range(A) \<union> Range(B)"
nipkow@26271
   460
by blast
berghofe@12905
   461
paulson@13830
   462
lemma Range_Int_subset: "Range(A \<inter> B) \<subseteq> Range(A) \<inter> Range(B)"
nipkow@26271
   463
by blast
berghofe@12905
   464
wenzelm@12913
   465
lemma Range_Diff_subset: "Range(A) - Range(B) \<subseteq> Range(A - B)"
nipkow@26271
   466
by blast
berghofe@12905
   467
paulson@13830
   468
lemma Range_Union: "Range (Union S) = (\<Union>A\<in>S. Range A)"
nipkow@26271
   469
by blast
nipkow@26271
   470
nipkow@26271
   471
lemma Range_converse[simp]: "Range(r^-1) = Domain r"
nipkow@26271
   472
by blast
berghofe@12905
   473
krauss@36729
   474
lemma snd_eq_Range: "snd ` R = Range R"
nipkow@26271
   475
by (auto intro!:image_eqI)
nipkow@26271
   476
nipkow@26271
   477
nipkow@26271
   478
subsection {* Field *}
nipkow@26271
   479
nipkow@26271
   480
lemma mono_Field: "r \<subseteq> s \<Longrightarrow> Field r \<subseteq> Field s"
nipkow@26271
   481
by(auto simp:Field_def Domain_def Range_def)
nipkow@26271
   482
nipkow@26271
   483
lemma Field_empty[simp]: "Field {} = {}"
nipkow@26271
   484
by(auto simp:Field_def)
nipkow@26271
   485
nipkow@26271
   486
lemma Field_insert[simp]: "Field (insert (a,b) r) = {a,b} \<union> Field r"
nipkow@26271
   487
by(auto simp:Field_def)
nipkow@26271
   488
nipkow@26271
   489
lemma Field_Un[simp]: "Field (r \<union> s) = Field r \<union> Field s"
nipkow@26271
   490
by(auto simp:Field_def)
nipkow@26271
   491
nipkow@26271
   492
lemma Field_Union[simp]: "Field (\<Union>R) = \<Union>(Field ` R)"
nipkow@26271
   493
by(auto simp:Field_def)
nipkow@26271
   494
nipkow@26271
   495
lemma Field_converse[simp]: "Field(r^-1) = Field r"
nipkow@26271
   496
by(auto simp:Field_def)
paulson@22172
   497
berghofe@12905
   498
berghofe@12905
   499
subsection {* Image of a set under a relation *}
berghofe@12905
   500
blanchet@35828
   501
declare Image_def [no_atp]
paulson@24286
   502
wenzelm@12913
   503
lemma Image_iff: "(b : r``A) = (EX x:A. (x, b) : r)"
nipkow@26271
   504
by (simp add: Image_def)
berghofe@12905
   505
wenzelm@12913
   506
lemma Image_singleton: "r``{a} = {b. (a, b) : r}"
nipkow@26271
   507
by (simp add: Image_def)
berghofe@12905
   508
wenzelm@12913
   509
lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a, b) : r)"
nipkow@26271
   510
by (rule Image_iff [THEN trans]) simp
berghofe@12905
   511
blanchet@35828
   512
lemma ImageI [intro,no_atp]: "(a, b) : r ==> a : A ==> b : r``A"
nipkow@26271
   513
by (unfold Image_def) blast
berghofe@12905
   514
berghofe@12905
   515
lemma ImageE [elim!]:
wenzelm@12913
   516
    "b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P"
nipkow@26271
   517
by (unfold Image_def) (iprover elim!: CollectE bexE)
berghofe@12905
   518
berghofe@12905
   519
lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A"
berghofe@12905
   520
  -- {* This version's more effective when we already have the required @{text a} *}
nipkow@26271
   521
by blast
berghofe@12905
   522
berghofe@12905
   523
lemma Image_empty [simp]: "R``{} = {}"
nipkow@26271
   524
by blast
berghofe@12905
   525
berghofe@12905
   526
lemma Image_Id [simp]: "Id `` A = A"
nipkow@26271
   527
by blast
berghofe@12905
   528
nipkow@30198
   529
lemma Image_Id_on [simp]: "Id_on A `` B = A \<inter> B"
nipkow@26271
   530
by blast
paulson@13830
   531
paulson@13830
   532
lemma Image_Int_subset: "R `` (A \<inter> B) \<subseteq> R `` A \<inter> R `` B"
nipkow@26271
   533
by blast
berghofe@12905
   534
paulson@13830
   535
lemma Image_Int_eq:
paulson@13830
   536
     "single_valued (converse R) ==> R `` (A \<inter> B) = R `` A \<inter> R `` B"
nipkow@26271
   537
by (simp add: single_valued_def, blast) 
berghofe@12905
   538
paulson@13830
   539
lemma Image_Un: "R `` (A \<union> B) = R `` A \<union> R `` B"
nipkow@26271
   540
by blast
berghofe@12905
   541
paulson@13812
   542
lemma Un_Image: "(R \<union> S) `` A = R `` A \<union> S `` A"
nipkow@26271
   543
by blast
paulson@13812
   544
wenzelm@12913
   545
lemma Image_subset: "r \<subseteq> A \<times> B ==> r``C \<subseteq> B"
nipkow@26271
   546
by (iprover intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2)
berghofe@12905
   547
paulson@13830
   548
lemma Image_eq_UN: "r``B = (\<Union>y\<in> B. r``{y})"
berghofe@12905
   549
  -- {* NOT suitable for rewriting *}
nipkow@26271
   550
by blast
berghofe@12905
   551
wenzelm@12913
   552
lemma Image_mono: "r' \<subseteq> r ==> A' \<subseteq> A ==> (r' `` A') \<subseteq> (r `` A)"
nipkow@26271
   553
by blast
berghofe@12905
   554
paulson@13830
   555
lemma Image_UN: "(r `` (UNION A B)) = (\<Union>x\<in>A. r `` (B x))"
nipkow@26271
   556
by blast
paulson@13830
   557
paulson@13830
   558
lemma Image_INT_subset: "(r `` INTER A B) \<subseteq> (\<Inter>x\<in>A. r `` (B x))"
nipkow@26271
   559
by blast
berghofe@12905
   560
paulson@13830
   561
text{*Converse inclusion requires some assumptions*}
paulson@13830
   562
lemma Image_INT_eq:
paulson@13830
   563
     "[|single_valued (r\<inverse>); A\<noteq>{}|] ==> r `` INTER A B = (\<Inter>x\<in>A. r `` B x)"
paulson@13830
   564
apply (rule equalityI)
paulson@13830
   565
 apply (rule Image_INT_subset) 
paulson@13830
   566
apply  (simp add: single_valued_def, blast)
paulson@13830
   567
done
berghofe@12905
   568
wenzelm@12913
   569
lemma Image_subset_eq: "(r``A \<subseteq> B) = (A \<subseteq> - ((r^-1) `` (-B)))"
nipkow@26271
   570
by blast
berghofe@12905
   571
berghofe@12905
   572
wenzelm@12913
   573
subsection {* Single valued relations *}
wenzelm@12913
   574
wenzelm@12913
   575
lemma single_valuedI:
berghofe@12905
   576
  "ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r"
nipkow@26271
   577
by (unfold single_valued_def)
berghofe@12905
   578
berghofe@12905
   579
lemma single_valuedD:
berghofe@12905
   580
  "single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z"
nipkow@26271
   581
by (simp add: single_valued_def)
berghofe@12905
   582
huffman@19228
   583
lemma single_valued_rel_comp:
huffman@19228
   584
  "single_valued r ==> single_valued s ==> single_valued (r O s)"
nipkow@26271
   585
by (unfold single_valued_def) blast
huffman@19228
   586
huffman@19228
   587
lemma single_valued_subset:
huffman@19228
   588
  "r \<subseteq> s ==> single_valued s ==> single_valued r"
nipkow@26271
   589
by (unfold single_valued_def) blast
huffman@19228
   590
huffman@19228
   591
lemma single_valued_Id [simp]: "single_valued Id"
nipkow@26271
   592
by (unfold single_valued_def) blast
huffman@19228
   593
nipkow@30198
   594
lemma single_valued_Id_on [simp]: "single_valued (Id_on A)"
nipkow@26271
   595
by (unfold single_valued_def) blast
huffman@19228
   596
berghofe@12905
   597
berghofe@12905
   598
subsection {* Graphs given by @{text Collect} *}
berghofe@12905
   599
berghofe@12905
   600
lemma Domain_Collect_split [simp]: "Domain{(x,y). P x y} = {x. EX y. P x y}"
nipkow@26271
   601
by auto
berghofe@12905
   602
berghofe@12905
   603
lemma Range_Collect_split [simp]: "Range{(x,y). P x y} = {y. EX x. P x y}"
nipkow@26271
   604
by auto
berghofe@12905
   605
berghofe@12905
   606
lemma Image_Collect_split [simp]: "{(x,y). P x y} `` A = {y. EX x:A. P x y}"
nipkow@26271
   607
by auto
berghofe@12905
   608
berghofe@12905
   609
wenzelm@12913
   610
subsection {* Inverse image *}
berghofe@12905
   611
huffman@19228
   612
lemma sym_inv_image: "sym r ==> sym (inv_image r f)"
nipkow@26271
   613
by (unfold sym_def inv_image_def) blast
huffman@19228
   614
wenzelm@12913
   615
lemma trans_inv_image: "trans r ==> trans (inv_image r f)"
berghofe@12905
   616
  apply (unfold trans_def inv_image_def)
berghofe@12905
   617
  apply (simp (no_asm))
berghofe@12905
   618
  apply blast
berghofe@12905
   619
  done
berghofe@12905
   620
krauss@32463
   621
lemma in_inv_image[simp]: "((x,y) : inv_image r f) = ((f x, f y) : r)"
krauss@32463
   622
  by (auto simp:inv_image_def)
krauss@32463
   623
krauss@33218
   624
lemma converse_inv_image[simp]: "(inv_image R f)^-1 = inv_image (R^-1) f"
krauss@33218
   625
unfolding inv_image_def converse_def by auto
krauss@33218
   626
haftmann@23709
   627
haftmann@29609
   628
subsection {* Finiteness *}
haftmann@29609
   629
haftmann@29609
   630
lemma finite_converse [iff]: "finite (r^-1) = finite r"
haftmann@29609
   631
  apply (subgoal_tac "r^-1 = (%(x,y). (y,x))`r")
haftmann@29609
   632
   apply simp
haftmann@29609
   633
   apply (rule iffI)
haftmann@29609
   634
    apply (erule finite_imageD [unfolded inj_on_def])
haftmann@29609
   635
    apply (simp split add: split_split)
haftmann@29609
   636
   apply (erule finite_imageI)
haftmann@29609
   637
  apply (simp add: converse_def image_def, auto)
haftmann@29609
   638
  apply (rule bexI)
haftmann@29609
   639
   prefer 2 apply assumption
haftmann@29609
   640
  apply simp
haftmann@29609
   641
  done
haftmann@29609
   642
paulson@32876
   643
lemma finite_Domain: "finite r ==> finite (Domain r)"
paulson@32876
   644
  by (induct set: finite) (auto simp add: Domain_insert)
paulson@32876
   645
paulson@32876
   646
lemma finite_Range: "finite r ==> finite (Range r)"
paulson@32876
   647
  by (induct set: finite) (auto simp add: Range_insert)
haftmann@29609
   648
haftmann@29609
   649
lemma finite_Field: "finite r ==> finite (Field r)"
haftmann@29609
   650
  -- {* A finite relation has a finite field (@{text "= domain \<union> range"}. *}
haftmann@29609
   651
  apply (induct set: finite)
haftmann@29609
   652
   apply (auto simp add: Field_def Domain_insert Range_insert)
haftmann@29609
   653
  done
haftmann@29609
   654
haftmann@29609
   655
krauss@36728
   656
subsection {* Miscellaneous *}
krauss@36728
   657
krauss@36728
   658
text {* Version of @{thm[source] lfp_induct} for binary relations *}
haftmann@23709
   659
haftmann@23709
   660
lemmas lfp_induct2 = 
haftmann@23709
   661
  lfp_induct_set [of "(a, b)", split_format (complete)]
haftmann@23709
   662
krauss@36728
   663
text {* Version of @{thm[source] subsetI} for binary relations *}
krauss@36728
   664
krauss@36728
   665
lemma subrelI: "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (x, y) \<in> s) \<Longrightarrow> r \<subseteq> s"
krauss@36728
   666
by auto
krauss@36728
   667
nipkow@1128
   668
end