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