src/HOL/Relation.thy
author haftmann
Thu Feb 23 21:25:59 2012 +0100 (2012-02-23)
changeset 46635 cde737f9c911
parent 46372 6fa9cdb8b850
child 46637 0bd7c16a4200
permissions -rw-r--r--
moved predicate relations and conversion rules between set and predicate relations from Predicate.thy to Relation.thy; moved Predicate.thy upwards in theory hierarchy
wenzelm@10358
     1
(*  Title:      HOL/Relation.thy
haftmann@46635
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory; Stefan Berghofer, TU Muenchen
nipkow@1128
     3
*)
nipkow@1128
     4
haftmann@46635
     5
header {* Relations – as sets of pairs, and binary predicates *}
berghofe@12905
     6
nipkow@15131
     7
theory Relation
haftmann@32850
     8
imports Datatype Finite_Set
nipkow@15131
     9
begin
paulson@5978
    10
haftmann@46635
    11
notation
haftmann@46635
    12
  bot ("\<bottom>") and
haftmann@46635
    13
  top ("\<top>") and
haftmann@46635
    14
  inf (infixl "\<sqinter>" 70) and
haftmann@46635
    15
  sup (infixl "\<squnion>" 65) and
haftmann@46635
    16
  Inf ("\<Sqinter>_" [900] 900) and
haftmann@46635
    17
  Sup ("\<Squnion>_" [900] 900)
haftmann@46635
    18
haftmann@46635
    19
syntax (xsymbols)
haftmann@46635
    20
  "_INF1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Sqinter>_./ _)" [0, 10] 10)
haftmann@46635
    21
  "_INF"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Sqinter>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@46635
    22
  "_SUP1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Squnion>_./ _)" [0, 10] 10)
haftmann@46635
    23
  "_SUP"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Squnion>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@46635
    24
haftmann@46635
    25
haftmann@46635
    26
subsection {* Classical rules for reasoning on predicates *}
haftmann@46635
    27
haftmann@46635
    28
declare predicate1D [Pure.dest?, dest?]
haftmann@46635
    29
declare predicate2I [Pure.intro!, intro!]
haftmann@46635
    30
declare predicate2D [Pure.dest, dest]
haftmann@46635
    31
declare bot1E [elim!]
haftmann@46635
    32
declare bot2E [elim!]
haftmann@46635
    33
declare top1I [intro!]
haftmann@46635
    34
declare top2I [intro!]
haftmann@46635
    35
declare inf1I [intro!]
haftmann@46635
    36
declare inf2I [intro!]
haftmann@46635
    37
declare inf1E [elim!]
haftmann@46635
    38
declare inf2E [elim!]
haftmann@46635
    39
declare sup1I1 [intro?]
haftmann@46635
    40
declare sup2I1 [intro?]
haftmann@46635
    41
declare sup1I2 [intro?]
haftmann@46635
    42
declare sup2I2 [intro?]
haftmann@46635
    43
declare sup1E [elim!]
haftmann@46635
    44
declare sup2E [elim!]
haftmann@46635
    45
declare sup1CI [intro!]
haftmann@46635
    46
declare sup2CI [intro!]
haftmann@46635
    47
declare INF1_I [intro!]
haftmann@46635
    48
declare INF2_I [intro!]
haftmann@46635
    49
declare INF1_D [elim]
haftmann@46635
    50
declare INF2_D [elim]
haftmann@46635
    51
declare INF1_E [elim]
haftmann@46635
    52
declare INF2_E [elim]
haftmann@46635
    53
declare SUP1_I [intro]
haftmann@46635
    54
declare SUP2_I [intro]
haftmann@46635
    55
declare SUP1_E [elim!]
haftmann@46635
    56
declare SUP2_E [elim!]
haftmann@46635
    57
haftmann@46635
    58
haftmann@46635
    59
subsection {* Conversions between set and predicate relations *}
haftmann@46635
    60
haftmann@46635
    61
lemma pred_equals_eq [pred_set_conv]: "((\<lambda>x. x \<in> R) = (\<lambda>x. x \<in> S)) \<longleftrightarrow> (R = S)"
haftmann@46635
    62
  by (simp add: set_eq_iff fun_eq_iff)
haftmann@46635
    63
haftmann@46635
    64
lemma pred_equals_eq2 [pred_set_conv]: "((\<lambda>x y. (x, y) \<in> R) = (\<lambda>x y. (x, y) \<in> S)) \<longleftrightarrow> (R = S)"
haftmann@46635
    65
  by (simp add: set_eq_iff fun_eq_iff)
haftmann@46635
    66
haftmann@46635
    67
lemma pred_subset_eq [pred_set_conv]: "((\<lambda>x. x \<in> R) \<le> (\<lambda>x. x \<in> S)) \<longleftrightarrow> (R \<subseteq> S)"
haftmann@46635
    68
  by (simp add: subset_iff le_fun_def)
haftmann@46635
    69
haftmann@46635
    70
lemma pred_subset_eq2 [pred_set_conv]: "((\<lambda>x y. (x, y) \<in> R) \<le> (\<lambda>x y. (x, y) \<in> S)) \<longleftrightarrow> (R \<subseteq> S)"
haftmann@46635
    71
  by (simp add: subset_iff le_fun_def)
haftmann@46635
    72
haftmann@46635
    73
lemma bot_empty_eq: "\<bottom> = (\<lambda>x. x \<in> {})"
haftmann@46635
    74
  by (auto simp add: fun_eq_iff)
haftmann@46635
    75
haftmann@46635
    76
lemma bot_empty_eq2: "\<bottom> = (\<lambda>x y. (x, y) \<in> {})"
haftmann@46635
    77
  by (auto simp add: fun_eq_iff)
haftmann@46635
    78
haftmann@46635
    79
lemma inf_Int_eq [pred_set_conv]: "(\<lambda>x. x \<in> R) \<sqinter> (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<inter> S)"
haftmann@46635
    80
  by (simp add: inf_fun_def)
haftmann@46635
    81
haftmann@46635
    82
lemma inf_Int_eq2 [pred_set_conv]: "(\<lambda>x y. (x, y) \<in> R) \<sqinter> (\<lambda>x y. (x, y) \<in> S) = (\<lambda>x y. (x, y) \<in> R \<inter> S)"
haftmann@46635
    83
  by (simp add: inf_fun_def)
haftmann@46635
    84
haftmann@46635
    85
lemma sup_Un_eq [pred_set_conv]: "(\<lambda>x. x \<in> R) \<squnion> (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<union> S)"
haftmann@46635
    86
  by (simp add: sup_fun_def)
haftmann@46635
    87
haftmann@46635
    88
lemma sup_Un_eq2 [pred_set_conv]: "(\<lambda>x y. (x, y) \<in> R) \<squnion> (\<lambda>x y. (x, y) \<in> S) = (\<lambda>x y. (x, y) \<in> R \<union> S)"
haftmann@46635
    89
  by (simp add: sup_fun_def)
haftmann@46635
    90
haftmann@46635
    91
lemma INF_INT_eq: "(\<Sqinter>i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (\<Inter>i. r i))"
haftmann@46635
    92
  by (simp add: INF_apply fun_eq_iff)
haftmann@46635
    93
haftmann@46635
    94
lemma INF_INT_eq2: "(\<Sqinter>i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (\<Inter>i. r i))"
haftmann@46635
    95
  by (simp add: INF_apply fun_eq_iff)
haftmann@46635
    96
haftmann@46635
    97
lemma SUP_UN_eq [pred_set_conv]: "(\<Squnion>i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (\<Union>i. r i))"
haftmann@46635
    98
  by (simp add: SUP_apply fun_eq_iff)
haftmann@46635
    99
haftmann@46635
   100
lemma SUP_UN_eq2 [pred_set_conv]: "(\<Squnion>i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (\<Union>i. r i))"
haftmann@46635
   101
  by (simp add: SUP_apply fun_eq_iff)
haftmann@46635
   102
haftmann@46635
   103
haftmann@46635
   104
subsection {* Relations as sets of pairs *}
wenzelm@12913
   105
nipkow@46372
   106
type_synonym 'a rel = "('a * 'a) set"
nipkow@46372
   107
wenzelm@19656
   108
definition
wenzelm@21404
   109
  converse :: "('a * 'b) set => ('b * 'a) set"
wenzelm@21404
   110
    ("(_^-1)" [1000] 999) where
haftmann@45137
   111
  "r^-1 = {(y, x). (x, y) : r}"
paulson@7912
   112
wenzelm@21210
   113
notation (xsymbols)
wenzelm@19656
   114
  converse  ("(_\<inverse>)" [1000] 999)
wenzelm@19656
   115
wenzelm@19656
   116
definition
krauss@32235
   117
  rel_comp  :: "[('a * 'b) set, ('b * 'c) set] => ('a * 'c) set"
wenzelm@21404
   118
    (infixr "O" 75) where
haftmann@45137
   119
  "r O s = {(x,z). EX y. (x, y) : r & (y, z) : s}"
wenzelm@12913
   120
wenzelm@21404
   121
definition
wenzelm@21404
   122
  Image :: "[('a * 'b) set, 'a set] => 'b set"
wenzelm@21404
   123
    (infixl "``" 90) where
haftmann@45137
   124
  "r `` s = {y. EX x:s. (x,y):r}"
paulson@7912
   125
wenzelm@21404
   126
definition
wenzelm@21404
   127
  Id :: "('a * 'a) set" where -- {* the identity relation *}
haftmann@45137
   128
  "Id = {p. EX x. p = (x,x)}"
paulson@7912
   129
wenzelm@21404
   130
definition
nipkow@30198
   131
  Id_on  :: "'a set => ('a * 'a) set" where -- {* diagonal: identity over a set *}
haftmann@45137
   132
  "Id_on A = (\<Union>x\<in>A. {(x,x)})"
wenzelm@12913
   133
wenzelm@21404
   134
definition
wenzelm@21404
   135
  Domain :: "('a * 'b) set => 'a set" where
haftmann@45137
   136
  "Domain r = {x. EX y. (x,y):r}"
paulson@5978
   137
wenzelm@21404
   138
definition
wenzelm@21404
   139
  Range  :: "('a * 'b) set => 'b set" where
haftmann@45137
   140
  "Range r = Domain(r^-1)"
paulson@5978
   141
wenzelm@21404
   142
definition
wenzelm@21404
   143
  Field :: "('a * 'a) set => 'a set" where
haftmann@45137
   144
  "Field r = Domain r \<union> Range r"
paulson@10786
   145
wenzelm@21404
   146
definition
nipkow@30198
   147
  refl_on :: "['a set, ('a * 'a) set] => bool" where -- {* reflexivity over a set *}
haftmann@45137
   148
  "refl_on A r \<longleftrightarrow> r \<subseteq> A \<times> A & (ALL x: A. (x,x) : r)"
paulson@6806
   149
nipkow@26297
   150
abbreviation
nipkow@30198
   151
  refl :: "('a * 'a) set => bool" where -- {* reflexivity over a type *}
haftmann@45137
   152
  "refl \<equiv> refl_on UNIV"
nipkow@26297
   153
wenzelm@21404
   154
definition
wenzelm@21404
   155
  sym :: "('a * 'a) set => bool" where -- {* symmetry predicate *}
haftmann@45137
   156
  "sym r \<longleftrightarrow> (ALL x y. (x,y): r --> (y,x): r)"
paulson@6806
   157
wenzelm@21404
   158
definition
wenzelm@21404
   159
  antisym :: "('a * 'a) set => bool" where -- {* antisymmetry predicate *}
haftmann@45137
   160
  "antisym r \<longleftrightarrow> (ALL x y. (x,y):r --> (y,x):r --> x=y)"
paulson@6806
   161
wenzelm@21404
   162
definition
wenzelm@21404
   163
  trans :: "('a * 'a) set => bool" where -- {* transitivity predicate *}
haftmann@45137
   164
  "trans r \<longleftrightarrow> (ALL x y z. (x,y):r --> (y,z):r --> (x,z):r)"
paulson@5978
   165
wenzelm@21404
   166
definition
haftmann@45137
   167
  irrefl :: "('a * 'a) set => bool" where
haftmann@45137
   168
  "irrefl r \<longleftrightarrow> (\<forall>x. (x,x) \<notin> r)"
nipkow@29859
   169
nipkow@29859
   170
definition
haftmann@45137
   171
  total_on :: "'a set => ('a * 'a) set => bool" where
haftmann@45137
   172
  "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
   173
nipkow@29859
   174
abbreviation "total \<equiv> total_on UNIV"
nipkow@29859
   175
nipkow@29859
   176
definition
wenzelm@21404
   177
  single_valued :: "('a * 'b) set => bool" where
haftmann@45137
   178
  "single_valued r \<longleftrightarrow> (ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z))"
berghofe@7014
   179
wenzelm@21404
   180
definition
wenzelm@21404
   181
  inv_image :: "('b * 'b) set => ('a => 'b) => ('a * 'a) set" where
haftmann@45137
   182
  "inv_image r f = {(x, y). (f x, f y) : r}"
oheimb@11136
   183
berghofe@12905
   184
haftmann@46635
   185
subsubsection {* The identity relation *}
berghofe@12905
   186
berghofe@12905
   187
lemma IdI [intro]: "(a, a) : Id"
nipkow@26271
   188
by (simp add: Id_def)
berghofe@12905
   189
berghofe@12905
   190
lemma IdE [elim!]: "p : Id ==> (!!x. p = (x, x) ==> P) ==> P"
nipkow@26271
   191
by (unfold Id_def) (iprover elim: CollectE)
berghofe@12905
   192
berghofe@12905
   193
lemma pair_in_Id_conv [iff]: "((a, b) : Id) = (a = b)"
nipkow@26271
   194
by (unfold Id_def) blast
berghofe@12905
   195
nipkow@30198
   196
lemma refl_Id: "refl Id"
nipkow@30198
   197
by (simp add: refl_on_def)
berghofe@12905
   198
berghofe@12905
   199
lemma antisym_Id: "antisym Id"
berghofe@12905
   200
  -- {* A strange result, since @{text Id} is also symmetric. *}
nipkow@26271
   201
by (simp add: antisym_def)
berghofe@12905
   202
huffman@19228
   203
lemma sym_Id: "sym Id"
nipkow@26271
   204
by (simp add: sym_def)
huffman@19228
   205
berghofe@12905
   206
lemma trans_Id: "trans Id"
nipkow@26271
   207
by (simp add: trans_def)
berghofe@12905
   208
berghofe@12905
   209
haftmann@46635
   210
subsubsection {* Diagonal: identity over a set *}
berghofe@12905
   211
nipkow@30198
   212
lemma Id_on_empty [simp]: "Id_on {} = {}"
nipkow@30198
   213
by (simp add: Id_on_def) 
paulson@13812
   214
nipkow@30198
   215
lemma Id_on_eqI: "a = b ==> a : A ==> (a, b) : Id_on A"
nipkow@30198
   216
by (simp add: Id_on_def)
berghofe@12905
   217
blanchet@35828
   218
lemma Id_onI [intro!,no_atp]: "a : A ==> (a, a) : Id_on A"
nipkow@30198
   219
by (rule Id_on_eqI) (rule refl)
berghofe@12905
   220
nipkow@30198
   221
lemma Id_onE [elim!]:
nipkow@30198
   222
  "c : Id_on A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P"
wenzelm@12913
   223
  -- {* The general elimination rule. *}
nipkow@30198
   224
by (unfold Id_on_def) (iprover elim!: UN_E singletonE)
berghofe@12905
   225
nipkow@30198
   226
lemma Id_on_iff: "((x, y) : Id_on A) = (x = y & x : A)"
nipkow@26271
   227
by blast
berghofe@12905
   228
haftmann@45967
   229
lemma Id_on_def' [nitpick_unfold]:
haftmann@44278
   230
  "Id_on {x. A x} = Collect (\<lambda>(x, y). x = y \<and> A x)"
haftmann@44278
   231
by auto
bulwahn@40923
   232
nipkow@30198
   233
lemma Id_on_subset_Times: "Id_on A \<subseteq> A \<times> A"
nipkow@26271
   234
by blast
berghofe@12905
   235
berghofe@12905
   236
haftmann@46635
   237
subsubsection {* Composition of two relations *}
berghofe@12905
   238
wenzelm@12913
   239
lemma rel_compI [intro]:
krauss@32235
   240
  "(a, b) : r ==> (b, c) : s ==> (a, c) : r O s"
nipkow@26271
   241
by (unfold rel_comp_def) blast
berghofe@12905
   242
wenzelm@12913
   243
lemma rel_compE [elim!]: "xz : r O s ==>
krauss@32235
   244
  (!!x y z. xz = (x, z) ==> (x, y) : r ==> (y, z) : s  ==> P) ==> P"
nipkow@26271
   245
by (unfold rel_comp_def) (iprover elim!: CollectE splitE exE conjE)
berghofe@12905
   246
berghofe@12905
   247
lemma rel_compEpair:
krauss@32235
   248
  "(a, c) : r O s ==> (!!y. (a, y) : r ==> (y, c) : s ==> P) ==> P"
nipkow@26271
   249
by (iprover elim: rel_compE Pair_inject ssubst)
berghofe@12905
   250
berghofe@12905
   251
lemma R_O_Id [simp]: "R O Id = R"
nipkow@26271
   252
by fast
berghofe@12905
   253
berghofe@12905
   254
lemma Id_O_R [simp]: "Id O R = R"
nipkow@26271
   255
by fast
berghofe@12905
   256
krauss@23185
   257
lemma rel_comp_empty1[simp]: "{} O R = {}"
nipkow@26271
   258
by blast
krauss@23185
   259
krauss@23185
   260
lemma rel_comp_empty2[simp]: "R O {} = {}"
nipkow@26271
   261
by blast
krauss@23185
   262
berghofe@12905
   263
lemma O_assoc: "(R O S) O T = R O (S O T)"
nipkow@26271
   264
by blast
berghofe@12905
   265
wenzelm@12913
   266
lemma trans_O_subset: "trans r ==> r O r \<subseteq> r"
nipkow@26271
   267
by (unfold trans_def) blast
berghofe@12905
   268
wenzelm@12913
   269
lemma rel_comp_mono: "r' \<subseteq> r ==> s' \<subseteq> s ==> (r' O s') \<subseteq> (r O s)"
nipkow@26271
   270
by blast
berghofe@12905
   271
berghofe@12905
   272
lemma rel_comp_subset_Sigma:
krauss@32235
   273
    "r \<subseteq> A \<times> B ==> s \<subseteq> B \<times> C ==> (r O s) \<subseteq> A \<times> C"
nipkow@26271
   274
by blast
berghofe@12905
   275
krauss@28008
   276
lemma rel_comp_distrib[simp]: "R O (S \<union> T) = (R O S) \<union> (R O T)" 
krauss@28008
   277
by auto
krauss@28008
   278
krauss@28008
   279
lemma rel_comp_distrib2[simp]: "(S \<union> T) O R = (S O R) \<union> (T O R)"
krauss@28008
   280
by auto
krauss@28008
   281
krauss@36772
   282
lemma rel_comp_UNION_distrib: "s O UNION I r = UNION I (%i. s O r i)"
krauss@36772
   283
by auto
krauss@36772
   284
krauss@36772
   285
lemma rel_comp_UNION_distrib2: "UNION I r O s = UNION I (%i. r i O s)"
krauss@36772
   286
by auto
krauss@36772
   287
wenzelm@12913
   288
haftmann@46635
   289
subsubsection {* Reflexivity *}
wenzelm@12913
   290
nipkow@30198
   291
lemma refl_onI: "r \<subseteq> A \<times> A ==> (!!x. x : A ==> (x, x) : r) ==> refl_on A r"
nipkow@30198
   292
by (unfold refl_on_def) (iprover intro!: ballI)
berghofe@12905
   293
nipkow@30198
   294
lemma refl_onD: "refl_on A r ==> a : A ==> (a, a) : r"
nipkow@30198
   295
by (unfold refl_on_def) blast
berghofe@12905
   296
nipkow@30198
   297
lemma refl_onD1: "refl_on A r ==> (x, y) : r ==> x : A"
nipkow@30198
   298
by (unfold refl_on_def) blast
huffman@19228
   299
nipkow@30198
   300
lemma refl_onD2: "refl_on A r ==> (x, y) : r ==> y : A"
nipkow@30198
   301
by (unfold refl_on_def) blast
huffman@19228
   302
nipkow@30198
   303
lemma refl_on_Int: "refl_on A r ==> refl_on B s ==> refl_on (A \<inter> B) (r \<inter> s)"
nipkow@30198
   304
by (unfold refl_on_def) blast
huffman@19228
   305
nipkow@30198
   306
lemma refl_on_Un: "refl_on A r ==> refl_on B s ==> refl_on (A \<union> B) (r \<union> s)"
nipkow@30198
   307
by (unfold refl_on_def) blast
huffman@19228
   308
nipkow@30198
   309
lemma refl_on_INTER:
nipkow@30198
   310
  "ALL x:S. refl_on (A x) (r x) ==> refl_on (INTER S A) (INTER S r)"
nipkow@30198
   311
by (unfold refl_on_def) fast
huffman@19228
   312
nipkow@30198
   313
lemma refl_on_UNION:
nipkow@30198
   314
  "ALL x:S. refl_on (A x) (r x) \<Longrightarrow> refl_on (UNION S A) (UNION S r)"
nipkow@30198
   315
by (unfold refl_on_def) blast
huffman@19228
   316
nipkow@30198
   317
lemma refl_on_empty[simp]: "refl_on {} {}"
nipkow@30198
   318
by(simp add:refl_on_def)
nipkow@26297
   319
nipkow@30198
   320
lemma refl_on_Id_on: "refl_on A (Id_on A)"
nipkow@30198
   321
by (rule refl_onI [OF Id_on_subset_Times Id_onI])
huffman@19228
   322
blanchet@41792
   323
lemma refl_on_def' [nitpick_unfold, code]:
bulwahn@41056
   324
  "refl_on A r = ((\<forall>(x, y) \<in> r. x : A \<and> y : A) \<and> (\<forall>x \<in> A. (x, x) : r))"
bulwahn@41056
   325
by (auto intro: refl_onI dest: refl_onD refl_onD1 refl_onD2)
wenzelm@12913
   326
haftmann@46635
   327
haftmann@46635
   328
subsubsection {* Antisymmetry *}
berghofe@12905
   329
berghofe@12905
   330
lemma antisymI:
berghofe@12905
   331
  "(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r"
nipkow@26271
   332
by (unfold antisym_def) iprover
berghofe@12905
   333
berghofe@12905
   334
lemma antisymD: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b"
nipkow@26271
   335
by (unfold antisym_def) iprover
berghofe@12905
   336
huffman@19228
   337
lemma antisym_subset: "r \<subseteq> s ==> antisym s ==> antisym r"
nipkow@26271
   338
by (unfold antisym_def) blast
wenzelm@12913
   339
huffman@19228
   340
lemma antisym_empty [simp]: "antisym {}"
nipkow@26271
   341
by (unfold antisym_def) blast
huffman@19228
   342
nipkow@30198
   343
lemma antisym_Id_on [simp]: "antisym (Id_on A)"
nipkow@26271
   344
by (unfold antisym_def) blast
huffman@19228
   345
huffman@19228
   346
haftmann@46635
   347
subsubsection {* Symmetry *}
huffman@19228
   348
huffman@19228
   349
lemma symI: "(!!a b. (a, b) : r ==> (b, a) : r) ==> sym r"
nipkow@26271
   350
by (unfold sym_def) iprover
paulson@15177
   351
paulson@15177
   352
lemma symD: "sym r ==> (a, b) : r ==> (b, a) : r"
nipkow@26271
   353
by (unfold sym_def, blast)
berghofe@12905
   354
huffman@19228
   355
lemma sym_Int: "sym r ==> sym s ==> sym (r \<inter> s)"
nipkow@26271
   356
by (fast intro: symI dest: symD)
huffman@19228
   357
huffman@19228
   358
lemma sym_Un: "sym r ==> sym s ==> sym (r \<union> s)"
nipkow@26271
   359
by (fast intro: symI dest: symD)
huffman@19228
   360
huffman@19228
   361
lemma sym_INTER: "ALL x:S. sym (r x) ==> sym (INTER S r)"
nipkow@26271
   362
by (fast intro: symI dest: symD)
huffman@19228
   363
huffman@19228
   364
lemma sym_UNION: "ALL x:S. sym (r x) ==> sym (UNION S r)"
nipkow@26271
   365
by (fast intro: symI dest: symD)
huffman@19228
   366
nipkow@30198
   367
lemma sym_Id_on [simp]: "sym (Id_on A)"
nipkow@26271
   368
by (rule symI) clarify
huffman@19228
   369
huffman@19228
   370
haftmann@46635
   371
subsubsection {* Transitivity *}
huffman@19228
   372
haftmann@46127
   373
lemma trans_join [code]:
haftmann@45012
   374
  "trans r \<longleftrightarrow> (\<forall>(x, y1) \<in> r. \<forall>(y2, z) \<in> r. y1 = y2 \<longrightarrow> (x, z) \<in> r)"
haftmann@45012
   375
  by (auto simp add: trans_def)
haftmann@45012
   376
berghofe@12905
   377
lemma transI:
berghofe@12905
   378
  "(!!x y z. (x, y) : r ==> (y, z) : r ==> (x, z) : r) ==> trans r"
nipkow@26271
   379
by (unfold trans_def) iprover
berghofe@12905
   380
berghofe@12905
   381
lemma transD: "trans r ==> (a, b) : r ==> (b, c) : r ==> (a, c) : r"
nipkow@26271
   382
by (unfold trans_def) iprover
berghofe@12905
   383
huffman@19228
   384
lemma trans_Int: "trans r ==> trans s ==> trans (r \<inter> s)"
nipkow@26271
   385
by (fast intro: transI elim: transD)
huffman@19228
   386
huffman@19228
   387
lemma trans_INTER: "ALL x:S. trans (r x) ==> trans (INTER S r)"
nipkow@26271
   388
by (fast intro: transI elim: transD)
huffman@19228
   389
nipkow@30198
   390
lemma trans_Id_on [simp]: "trans (Id_on A)"
nipkow@26271
   391
by (fast intro: transI elim: transD)
huffman@19228
   392
nipkow@29859
   393
lemma trans_diff_Id: " trans r \<Longrightarrow> antisym r \<Longrightarrow> trans (r-Id)"
nipkow@29859
   394
unfolding antisym_def trans_def by blast
nipkow@29859
   395
haftmann@46635
   396
haftmann@46635
   397
subsubsection {* Irreflexivity *}
nipkow@29859
   398
haftmann@46127
   399
lemma irrefl_distinct [code]:
haftmann@45012
   400
  "irrefl r \<longleftrightarrow> (\<forall>(x, y) \<in> r. x \<noteq> y)"
haftmann@45012
   401
  by (auto simp add: irrefl_def)
haftmann@45012
   402
nipkow@29859
   403
lemma irrefl_diff_Id[simp]: "irrefl(r-Id)"
nipkow@29859
   404
by(simp add:irrefl_def)
nipkow@29859
   405
haftmann@45139
   406
haftmann@46635
   407
subsubsection {* Totality *}
nipkow@29859
   408
nipkow@29859
   409
lemma total_on_empty[simp]: "total_on {} r"
nipkow@29859
   410
by(simp add:total_on_def)
nipkow@29859
   411
nipkow@29859
   412
lemma total_on_diff_Id[simp]: "total_on A (r-Id) = total_on A r"
nipkow@29859
   413
by(simp add: total_on_def)
berghofe@12905
   414
haftmann@46635
   415
haftmann@46635
   416
subsubsection {* Converse *}
wenzelm@12913
   417
wenzelm@12913
   418
lemma converse_iff [iff]: "((a,b): r^-1) = ((b,a) : r)"
nipkow@26271
   419
by (simp add: converse_def)
berghofe@12905
   420
nipkow@13343
   421
lemma converseI[sym]: "(a, b) : r ==> (b, a) : r^-1"
nipkow@26271
   422
by (simp add: converse_def)
berghofe@12905
   423
nipkow@13343
   424
lemma converseD[sym]: "(a,b) : r^-1 ==> (b, a) : r"
nipkow@26271
   425
by (simp add: converse_def)
berghofe@12905
   426
berghofe@12905
   427
lemma converseE [elim!]:
berghofe@12905
   428
  "yx : r^-1 ==> (!!x y. yx = (y, x) ==> (x, y) : r ==> P) ==> P"
wenzelm@12913
   429
    -- {* More general than @{text converseD}, as it ``splits'' the member of the relation. *}
nipkow@26271
   430
by (unfold converse_def) (iprover elim!: CollectE splitE bexE)
berghofe@12905
   431
berghofe@12905
   432
lemma converse_converse [simp]: "(r^-1)^-1 = r"
nipkow@26271
   433
by (unfold converse_def) blast
berghofe@12905
   434
berghofe@12905
   435
lemma converse_rel_comp: "(r O s)^-1 = s^-1 O r^-1"
nipkow@26271
   436
by blast
berghofe@12905
   437
huffman@19228
   438
lemma converse_Int: "(r \<inter> s)^-1 = r^-1 \<inter> s^-1"
nipkow@26271
   439
by blast
huffman@19228
   440
huffman@19228
   441
lemma converse_Un: "(r \<union> s)^-1 = r^-1 \<union> s^-1"
nipkow@26271
   442
by blast
huffman@19228
   443
huffman@19228
   444
lemma converse_INTER: "(INTER S r)^-1 = (INT x:S. (r x)^-1)"
nipkow@26271
   445
by fast
huffman@19228
   446
huffman@19228
   447
lemma converse_UNION: "(UNION S r)^-1 = (UN x:S. (r x)^-1)"
nipkow@26271
   448
by blast
huffman@19228
   449
berghofe@12905
   450
lemma converse_Id [simp]: "Id^-1 = Id"
nipkow@26271
   451
by blast
berghofe@12905
   452
nipkow@30198
   453
lemma converse_Id_on [simp]: "(Id_on A)^-1 = Id_on A"
nipkow@26271
   454
by blast
berghofe@12905
   455
nipkow@30198
   456
lemma refl_on_converse [simp]: "refl_on A (converse r) = refl_on A r"
nipkow@30198
   457
by (unfold refl_on_def) auto
berghofe@12905
   458
huffman@19228
   459
lemma sym_converse [simp]: "sym (converse r) = sym r"
nipkow@26271
   460
by (unfold sym_def) blast
huffman@19228
   461
huffman@19228
   462
lemma antisym_converse [simp]: "antisym (converse r) = antisym r"
nipkow@26271
   463
by (unfold antisym_def) blast
berghofe@12905
   464
huffman@19228
   465
lemma trans_converse [simp]: "trans (converse r) = trans r"
nipkow@26271
   466
by (unfold trans_def) blast
berghofe@12905
   467
huffman@19228
   468
lemma sym_conv_converse_eq: "sym r = (r^-1 = r)"
nipkow@26271
   469
by (unfold sym_def) fast
huffman@19228
   470
huffman@19228
   471
lemma sym_Un_converse: "sym (r \<union> r^-1)"
nipkow@26271
   472
by (unfold sym_def) blast
huffman@19228
   473
huffman@19228
   474
lemma sym_Int_converse: "sym (r \<inter> r^-1)"
nipkow@26271
   475
by (unfold sym_def) blast
huffman@19228
   476
nipkow@29859
   477
lemma total_on_converse[simp]: "total_on A (r^-1) = total_on A r"
nipkow@29859
   478
by (auto simp: total_on_def)
nipkow@29859
   479
wenzelm@12913
   480
haftmann@46635
   481
subsubsection {* Domain *}
berghofe@12905
   482
blanchet@35828
   483
declare Domain_def [no_atp]
paulson@24286
   484
berghofe@12905
   485
lemma Domain_iff: "(a : Domain r) = (EX y. (a, y) : r)"
nipkow@26271
   486
by (unfold Domain_def) blast
berghofe@12905
   487
berghofe@12905
   488
lemma DomainI [intro]: "(a, b) : r ==> a : Domain r"
nipkow@26271
   489
by (iprover intro!: iffD2 [OF Domain_iff])
berghofe@12905
   490
berghofe@12905
   491
lemma DomainE [elim!]:
berghofe@12905
   492
  "a : Domain r ==> (!!y. (a, y) : r ==> P) ==> P"
nipkow@26271
   493
by (iprover dest!: iffD1 [OF Domain_iff])
berghofe@12905
   494
haftmann@46127
   495
lemma Domain_fst [code]:
haftmann@45012
   496
  "Domain r = fst ` r"
haftmann@45012
   497
  by (auto simp add: image_def Bex_def)
haftmann@45012
   498
berghofe@12905
   499
lemma Domain_empty [simp]: "Domain {} = {}"
nipkow@26271
   500
by blast
berghofe@12905
   501
paulson@32876
   502
lemma Domain_empty_iff: "Domain r = {} \<longleftrightarrow> r = {}"
paulson@32876
   503
  by auto
paulson@32876
   504
berghofe@12905
   505
lemma Domain_insert: "Domain (insert (a, b) r) = insert a (Domain r)"
nipkow@26271
   506
by blast
berghofe@12905
   507
berghofe@12905
   508
lemma Domain_Id [simp]: "Domain Id = UNIV"
nipkow@26271
   509
by blast
berghofe@12905
   510
nipkow@30198
   511
lemma Domain_Id_on [simp]: "Domain (Id_on A) = A"
nipkow@26271
   512
by blast
berghofe@12905
   513
paulson@13830
   514
lemma Domain_Un_eq: "Domain(A \<union> B) = Domain(A) \<union> Domain(B)"
nipkow@26271
   515
by blast
berghofe@12905
   516
paulson@13830
   517
lemma Domain_Int_subset: "Domain(A \<inter> B) \<subseteq> Domain(A) \<inter> Domain(B)"
nipkow@26271
   518
by blast
berghofe@12905
   519
wenzelm@12913
   520
lemma Domain_Diff_subset: "Domain(A) - Domain(B) \<subseteq> Domain(A - B)"
nipkow@26271
   521
by blast
berghofe@12905
   522
paulson@13830
   523
lemma Domain_Union: "Domain (Union S) = (\<Union>A\<in>S. Domain A)"
nipkow@26271
   524
by blast
nipkow@26271
   525
nipkow@26271
   526
lemma Domain_converse[simp]: "Domain(r^-1) = Range r"
nipkow@26271
   527
by(auto simp:Range_def)
berghofe@12905
   528
wenzelm@12913
   529
lemma Domain_mono: "r \<subseteq> s ==> Domain r \<subseteq> Domain s"
nipkow@26271
   530
by blast
berghofe@12905
   531
krauss@36729
   532
lemma fst_eq_Domain: "fst ` R = Domain R"
huffman@44921
   533
  by force
paulson@22172
   534
haftmann@29609
   535
lemma Domain_dprod [simp]: "Domain (dprod r s) = uprod (Domain r) (Domain s)"
haftmann@29609
   536
by auto
haftmann@29609
   537
haftmann@29609
   538
lemma Domain_dsum [simp]: "Domain (dsum r s) = usum (Domain r) (Domain s)"
haftmann@29609
   539
by auto
haftmann@29609
   540
berghofe@12905
   541
haftmann@46635
   542
subsubsection {* Range *}
berghofe@12905
   543
berghofe@12905
   544
lemma Range_iff: "(a : Range r) = (EX y. (y, a) : r)"
nipkow@26271
   545
by (simp add: Domain_def Range_def)
berghofe@12905
   546
berghofe@12905
   547
lemma RangeI [intro]: "(a, b) : r ==> b : Range r"
nipkow@26271
   548
by (unfold Range_def) (iprover intro!: converseI DomainI)
berghofe@12905
   549
berghofe@12905
   550
lemma RangeE [elim!]: "b : Range r ==> (!!x. (x, b) : r ==> P) ==> P"
nipkow@26271
   551
by (unfold Range_def) (iprover elim!: DomainE dest!: converseD)
berghofe@12905
   552
haftmann@46127
   553
lemma Range_snd [code]:
haftmann@45012
   554
  "Range r = snd ` r"
haftmann@45012
   555
  by (auto simp add: image_def Bex_def)
haftmann@45012
   556
berghofe@12905
   557
lemma Range_empty [simp]: "Range {} = {}"
nipkow@26271
   558
by blast
berghofe@12905
   559
paulson@32876
   560
lemma Range_empty_iff: "Range r = {} \<longleftrightarrow> r = {}"
paulson@32876
   561
  by auto
paulson@32876
   562
berghofe@12905
   563
lemma Range_insert: "Range (insert (a, b) r) = insert b (Range r)"
nipkow@26271
   564
by blast
berghofe@12905
   565
berghofe@12905
   566
lemma Range_Id [simp]: "Range Id = UNIV"
nipkow@26271
   567
by blast
berghofe@12905
   568
nipkow@30198
   569
lemma Range_Id_on [simp]: "Range (Id_on A) = A"
nipkow@26271
   570
by auto
berghofe@12905
   571
paulson@13830
   572
lemma Range_Un_eq: "Range(A \<union> B) = Range(A) \<union> Range(B)"
nipkow@26271
   573
by blast
berghofe@12905
   574
paulson@13830
   575
lemma Range_Int_subset: "Range(A \<inter> B) \<subseteq> Range(A) \<inter> Range(B)"
nipkow@26271
   576
by blast
berghofe@12905
   577
wenzelm@12913
   578
lemma Range_Diff_subset: "Range(A) - Range(B) \<subseteq> Range(A - B)"
nipkow@26271
   579
by blast
berghofe@12905
   580
paulson@13830
   581
lemma Range_Union: "Range (Union S) = (\<Union>A\<in>S. Range A)"
nipkow@26271
   582
by blast
nipkow@26271
   583
nipkow@26271
   584
lemma Range_converse[simp]: "Range(r^-1) = Domain r"
nipkow@26271
   585
by blast
berghofe@12905
   586
krauss@36729
   587
lemma snd_eq_Range: "snd ` R = Range R"
huffman@44921
   588
  by force
nipkow@26271
   589
nipkow@26271
   590
haftmann@46635
   591
subsubsection {* Field *}
nipkow@26271
   592
nipkow@26271
   593
lemma mono_Field: "r \<subseteq> s \<Longrightarrow> Field r \<subseteq> Field s"
nipkow@26271
   594
by(auto simp:Field_def Domain_def Range_def)
nipkow@26271
   595
nipkow@26271
   596
lemma Field_empty[simp]: "Field {} = {}"
nipkow@26271
   597
by(auto simp:Field_def)
nipkow@26271
   598
nipkow@26271
   599
lemma Field_insert[simp]: "Field (insert (a,b) r) = {a,b} \<union> Field r"
nipkow@26271
   600
by(auto simp:Field_def)
nipkow@26271
   601
nipkow@26271
   602
lemma Field_Un[simp]: "Field (r \<union> s) = Field r \<union> Field s"
nipkow@26271
   603
by(auto simp:Field_def)
nipkow@26271
   604
nipkow@26271
   605
lemma Field_Union[simp]: "Field (\<Union>R) = \<Union>(Field ` R)"
nipkow@26271
   606
by(auto simp:Field_def)
nipkow@26271
   607
nipkow@26271
   608
lemma Field_converse[simp]: "Field(r^-1) = Field r"
nipkow@26271
   609
by(auto simp:Field_def)
paulson@22172
   610
berghofe@12905
   611
haftmann@46635
   612
subsubsection {* Image of a set under a relation *}
berghofe@12905
   613
blanchet@35828
   614
declare Image_def [no_atp]
paulson@24286
   615
wenzelm@12913
   616
lemma Image_iff: "(b : r``A) = (EX x:A. (x, b) : r)"
nipkow@26271
   617
by (simp add: Image_def)
berghofe@12905
   618
wenzelm@12913
   619
lemma Image_singleton: "r``{a} = {b. (a, b) : r}"
nipkow@26271
   620
by (simp add: Image_def)
berghofe@12905
   621
wenzelm@12913
   622
lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a, b) : r)"
nipkow@26271
   623
by (rule Image_iff [THEN trans]) simp
berghofe@12905
   624
blanchet@35828
   625
lemma ImageI [intro,no_atp]: "(a, b) : r ==> a : A ==> b : r``A"
nipkow@26271
   626
by (unfold Image_def) blast
berghofe@12905
   627
berghofe@12905
   628
lemma ImageE [elim!]:
wenzelm@12913
   629
    "b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P"
nipkow@26271
   630
by (unfold Image_def) (iprover elim!: CollectE bexE)
berghofe@12905
   631
berghofe@12905
   632
lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A"
berghofe@12905
   633
  -- {* This version's more effective when we already have the required @{text a} *}
nipkow@26271
   634
by blast
berghofe@12905
   635
berghofe@12905
   636
lemma Image_empty [simp]: "R``{} = {}"
nipkow@26271
   637
by blast
berghofe@12905
   638
berghofe@12905
   639
lemma Image_Id [simp]: "Id `` A = A"
nipkow@26271
   640
by blast
berghofe@12905
   641
nipkow@30198
   642
lemma Image_Id_on [simp]: "Id_on A `` B = A \<inter> B"
nipkow@26271
   643
by blast
paulson@13830
   644
paulson@13830
   645
lemma Image_Int_subset: "R `` (A \<inter> B) \<subseteq> R `` A \<inter> R `` B"
nipkow@26271
   646
by blast
berghofe@12905
   647
paulson@13830
   648
lemma Image_Int_eq:
paulson@13830
   649
     "single_valued (converse R) ==> R `` (A \<inter> B) = R `` A \<inter> R `` B"
nipkow@26271
   650
by (simp add: single_valued_def, blast) 
berghofe@12905
   651
paulson@13830
   652
lemma Image_Un: "R `` (A \<union> B) = R `` A \<union> R `` B"
nipkow@26271
   653
by blast
berghofe@12905
   654
paulson@13812
   655
lemma Un_Image: "(R \<union> S) `` A = R `` A \<union> S `` A"
nipkow@26271
   656
by blast
paulson@13812
   657
wenzelm@12913
   658
lemma Image_subset: "r \<subseteq> A \<times> B ==> r``C \<subseteq> B"
nipkow@26271
   659
by (iprover intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2)
berghofe@12905
   660
paulson@13830
   661
lemma Image_eq_UN: "r``B = (\<Union>y\<in> B. r``{y})"
berghofe@12905
   662
  -- {* NOT suitable for rewriting *}
nipkow@26271
   663
by blast
berghofe@12905
   664
wenzelm@12913
   665
lemma Image_mono: "r' \<subseteq> r ==> A' \<subseteq> A ==> (r' `` A') \<subseteq> (r `` A)"
nipkow@26271
   666
by blast
berghofe@12905
   667
paulson@13830
   668
lemma Image_UN: "(r `` (UNION A B)) = (\<Union>x\<in>A. r `` (B x))"
nipkow@26271
   669
by blast
paulson@13830
   670
paulson@13830
   671
lemma Image_INT_subset: "(r `` INTER A B) \<subseteq> (\<Inter>x\<in>A. r `` (B x))"
nipkow@26271
   672
by blast
berghofe@12905
   673
paulson@13830
   674
text{*Converse inclusion requires some assumptions*}
paulson@13830
   675
lemma Image_INT_eq:
paulson@13830
   676
     "[|single_valued (r\<inverse>); A\<noteq>{}|] ==> r `` INTER A B = (\<Inter>x\<in>A. r `` B x)"
paulson@13830
   677
apply (rule equalityI)
paulson@13830
   678
 apply (rule Image_INT_subset) 
paulson@13830
   679
apply  (simp add: single_valued_def, blast)
paulson@13830
   680
done
berghofe@12905
   681
wenzelm@12913
   682
lemma Image_subset_eq: "(r``A \<subseteq> B) = (A \<subseteq> - ((r^-1) `` (-B)))"
nipkow@26271
   683
by blast
berghofe@12905
   684
berghofe@12905
   685
haftmann@46635
   686
subsubsection {* Single valued relations *}
wenzelm@12913
   687
wenzelm@12913
   688
lemma single_valuedI:
berghofe@12905
   689
  "ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r"
nipkow@26271
   690
by (unfold single_valued_def)
berghofe@12905
   691
berghofe@12905
   692
lemma single_valuedD:
berghofe@12905
   693
  "single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z"
nipkow@26271
   694
by (simp add: single_valued_def)
berghofe@12905
   695
huffman@19228
   696
lemma single_valued_rel_comp:
huffman@19228
   697
  "single_valued r ==> single_valued s ==> single_valued (r O s)"
nipkow@26271
   698
by (unfold single_valued_def) blast
huffman@19228
   699
huffman@19228
   700
lemma single_valued_subset:
huffman@19228
   701
  "r \<subseteq> s ==> single_valued s ==> single_valued r"
nipkow@26271
   702
by (unfold single_valued_def) blast
huffman@19228
   703
huffman@19228
   704
lemma single_valued_Id [simp]: "single_valued Id"
nipkow@26271
   705
by (unfold single_valued_def) blast
huffman@19228
   706
nipkow@30198
   707
lemma single_valued_Id_on [simp]: "single_valued (Id_on A)"
nipkow@26271
   708
by (unfold single_valued_def) blast
huffman@19228
   709
berghofe@12905
   710
haftmann@46635
   711
subsubsection {* Graphs given by @{text Collect} *}
berghofe@12905
   712
berghofe@12905
   713
lemma Domain_Collect_split [simp]: "Domain{(x,y). P x y} = {x. EX y. P x y}"
nipkow@26271
   714
by auto
berghofe@12905
   715
berghofe@12905
   716
lemma Range_Collect_split [simp]: "Range{(x,y). P x y} = {y. EX x. P x y}"
nipkow@26271
   717
by auto
berghofe@12905
   718
berghofe@12905
   719
lemma Image_Collect_split [simp]: "{(x,y). P x y} `` A = {y. EX x:A. P x y}"
nipkow@26271
   720
by auto
berghofe@12905
   721
berghofe@12905
   722
haftmann@46635
   723
subsubsection {* Inverse image *}
berghofe@12905
   724
huffman@19228
   725
lemma sym_inv_image: "sym r ==> sym (inv_image r f)"
nipkow@26271
   726
by (unfold sym_def inv_image_def) blast
huffman@19228
   727
wenzelm@12913
   728
lemma trans_inv_image: "trans r ==> trans (inv_image r f)"
berghofe@12905
   729
  apply (unfold trans_def inv_image_def)
berghofe@12905
   730
  apply (simp (no_asm))
berghofe@12905
   731
  apply blast
berghofe@12905
   732
  done
berghofe@12905
   733
krauss@32463
   734
lemma in_inv_image[simp]: "((x,y) : inv_image r f) = ((f x, f y) : r)"
krauss@32463
   735
  by (auto simp:inv_image_def)
krauss@32463
   736
krauss@33218
   737
lemma converse_inv_image[simp]: "(inv_image R f)^-1 = inv_image (R^-1) f"
krauss@33218
   738
unfolding inv_image_def converse_def by auto
krauss@33218
   739
haftmann@23709
   740
haftmann@46635
   741
subsubsection {* Finiteness *}
haftmann@29609
   742
haftmann@29609
   743
lemma finite_converse [iff]: "finite (r^-1) = finite r"
haftmann@29609
   744
  apply (subgoal_tac "r^-1 = (%(x,y). (y,x))`r")
haftmann@29609
   745
   apply simp
haftmann@29609
   746
   apply (rule iffI)
haftmann@29609
   747
    apply (erule finite_imageD [unfolded inj_on_def])
haftmann@29609
   748
    apply (simp split add: split_split)
haftmann@29609
   749
   apply (erule finite_imageI)
haftmann@29609
   750
  apply (simp add: converse_def image_def, auto)
haftmann@29609
   751
  apply (rule bexI)
haftmann@29609
   752
   prefer 2 apply assumption
haftmann@29609
   753
  apply simp
haftmann@29609
   754
  done
haftmann@29609
   755
paulson@32876
   756
lemma finite_Domain: "finite r ==> finite (Domain r)"
paulson@32876
   757
  by (induct set: finite) (auto simp add: Domain_insert)
paulson@32876
   758
paulson@32876
   759
lemma finite_Range: "finite r ==> finite (Range r)"
paulson@32876
   760
  by (induct set: finite) (auto simp add: Range_insert)
haftmann@29609
   761
haftmann@29609
   762
lemma finite_Field: "finite r ==> finite (Field r)"
haftmann@29609
   763
  -- {* A finite relation has a finite field (@{text "= domain \<union> range"}. *}
haftmann@29609
   764
  apply (induct set: finite)
haftmann@29609
   765
   apply (auto simp add: Field_def Domain_insert Range_insert)
haftmann@29609
   766
  done
haftmann@29609
   767
haftmann@29609
   768
haftmann@46635
   769
subsubsection {* Miscellaneous *}
krauss@36728
   770
krauss@36728
   771
text {* Version of @{thm[source] lfp_induct} for binary relations *}
haftmann@23709
   772
haftmann@23709
   773
lemmas lfp_induct2 = 
haftmann@23709
   774
  lfp_induct_set [of "(a, b)", split_format (complete)]
haftmann@23709
   775
krauss@36728
   776
text {* Version of @{thm[source] subsetI} for binary relations *}
krauss@36728
   777
krauss@36728
   778
lemma subrelI: "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (x, y) \<in> s) \<Longrightarrow> r \<subseteq> s"
krauss@36728
   779
by auto
krauss@36728
   780
haftmann@46635
   781
haftmann@46635
   782
subsection {* Relations as binary predicates *}
haftmann@46635
   783
haftmann@46635
   784
subsubsection {* Composition *}
haftmann@46635
   785
haftmann@46635
   786
inductive pred_comp  :: "['a \<Rightarrow> 'b \<Rightarrow> bool, 'b \<Rightarrow> 'c \<Rightarrow> bool] \<Rightarrow> 'a \<Rightarrow> 'c \<Rightarrow> bool" (infixr "OO" 75)
haftmann@46635
   787
  for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" and s :: "'b \<Rightarrow> 'c \<Rightarrow> bool" where
haftmann@46635
   788
  pred_compI [intro]: "r a b \<Longrightarrow> s b c \<Longrightarrow> (r OO s) a c"
haftmann@46635
   789
haftmann@46635
   790
inductive_cases pred_compE [elim!]: "(r OO s) a c"
haftmann@46635
   791
haftmann@46635
   792
lemma pred_comp_rel_comp_eq [pred_set_conv]:
haftmann@46635
   793
  "((\<lambda>x y. (x, y) \<in> r) OO (\<lambda>x y. (x, y) \<in> s)) = (\<lambda>x y. (x, y) \<in> r O s)"
haftmann@46635
   794
  by (auto simp add: fun_eq_iff)
haftmann@46635
   795
haftmann@46635
   796
haftmann@46635
   797
subsubsection {* Converse *}
haftmann@46635
   798
haftmann@46635
   799
inductive conversep :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> bool" ("(_^--1)" [1000] 1000)
haftmann@46635
   800
  for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" where
haftmann@46635
   801
  conversepI: "r a b \<Longrightarrow> r^--1 b a"
haftmann@46635
   802
haftmann@46635
   803
notation (xsymbols)
haftmann@46635
   804
  conversep  ("(_\<inverse>\<inverse>)" [1000] 1000)
haftmann@46635
   805
haftmann@46635
   806
lemma conversepD:
haftmann@46635
   807
  assumes ab: "r^--1 a b"
haftmann@46635
   808
  shows "r b a" using ab
haftmann@46635
   809
  by cases simp
haftmann@46635
   810
haftmann@46635
   811
lemma conversep_iff [iff]: "r^--1 a b = r b a"
haftmann@46635
   812
  by (iprover intro: conversepI dest: conversepD)
haftmann@46635
   813
haftmann@46635
   814
lemma conversep_converse_eq [pred_set_conv]:
haftmann@46635
   815
  "(\<lambda>x y. (x, y) \<in> r)^--1 = (\<lambda>x y. (x, y) \<in> r^-1)"
haftmann@46635
   816
  by (auto simp add: fun_eq_iff)
haftmann@46635
   817
haftmann@46635
   818
lemma conversep_conversep [simp]: "(r^--1)^--1 = r"
haftmann@46635
   819
  by (iprover intro: order_antisym conversepI dest: conversepD)
haftmann@46635
   820
haftmann@46635
   821
lemma converse_pred_comp: "(r OO s)^--1 = s^--1 OO r^--1"
haftmann@46635
   822
  by (iprover intro: order_antisym conversepI pred_compI
haftmann@46635
   823
    elim: pred_compE dest: conversepD)
haftmann@46635
   824
haftmann@46635
   825
lemma converse_meet: "(r \<sqinter> s)^--1 = r^--1 \<sqinter> s^--1"
haftmann@46635
   826
  by (simp add: inf_fun_def) (iprover intro: conversepI ext dest: conversepD)
haftmann@46635
   827
haftmann@46635
   828
lemma converse_join: "(r \<squnion> s)^--1 = r^--1 \<squnion> s^--1"
haftmann@46635
   829
  by (simp add: sup_fun_def) (iprover intro: conversepI ext dest: conversepD)
haftmann@46635
   830
haftmann@46635
   831
lemma conversep_noteq [simp]: "(op \<noteq>)^--1 = op \<noteq>"
haftmann@46635
   832
  by (auto simp add: fun_eq_iff)
haftmann@46635
   833
haftmann@46635
   834
lemma conversep_eq [simp]: "(op =)^--1 = op ="
haftmann@46635
   835
  by (auto simp add: fun_eq_iff)
haftmann@46635
   836
haftmann@46635
   837
haftmann@46635
   838
subsubsection {* Domain *}
haftmann@46635
   839
haftmann@46635
   840
inductive DomainP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@46635
   841
  for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" where
haftmann@46635
   842
  DomainPI [intro]: "r a b \<Longrightarrow> DomainP r a"
haftmann@46635
   843
haftmann@46635
   844
inductive_cases DomainPE [elim!]: "DomainP r a"
haftmann@46635
   845
haftmann@46635
   846
lemma DomainP_Domain_eq [pred_set_conv]: "DomainP (\<lambda>x y. (x, y) \<in> r) = (\<lambda>x. x \<in> Domain r)"
haftmann@46635
   847
  by (blast intro!: Orderings.order_antisym predicate1I)
haftmann@46635
   848
haftmann@46635
   849
haftmann@46635
   850
subsubsection {* Range *}
haftmann@46635
   851
haftmann@46635
   852
inductive RangeP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'b \<Rightarrow> bool"
haftmann@46635
   853
  for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" where
haftmann@46635
   854
  RangePI [intro]: "r a b \<Longrightarrow> RangeP r b"
haftmann@46635
   855
haftmann@46635
   856
inductive_cases RangePE [elim!]: "RangeP r b"
haftmann@46635
   857
haftmann@46635
   858
lemma RangeP_Range_eq [pred_set_conv]: "RangeP (\<lambda>x y. (x, y) \<in> r) = (\<lambda>x. x \<in> Range r)"
haftmann@46635
   859
  by (blast intro!: Orderings.order_antisym predicate1I)
haftmann@46635
   860
haftmann@46635
   861
haftmann@46635
   862
subsubsection {* Inverse image *}
haftmann@46635
   863
haftmann@46635
   864
definition inv_imagep :: "('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" where
haftmann@46635
   865
  "inv_imagep r f = (\<lambda>x y. r (f x) (f y))"
haftmann@46635
   866
haftmann@46635
   867
lemma [pred_set_conv]: "inv_imagep (\<lambda>x y. (x, y) \<in> r) f = (\<lambda>x y. (x, y) \<in> inv_image r f)"
haftmann@46635
   868
  by (simp add: inv_image_def inv_imagep_def)
haftmann@46635
   869
haftmann@46635
   870
lemma in_inv_imagep [simp]: "inv_imagep r f x y = r (f x) (f y)"
haftmann@46635
   871
  by (simp add: inv_imagep_def)
haftmann@46635
   872
haftmann@46635
   873
haftmann@46635
   874
subsubsection {* Powerset *}
haftmann@46635
   875
haftmann@46635
   876
definition Powp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@46635
   877
  "Powp A = (\<lambda>B. \<forall>x \<in> B. A x)"
haftmann@46635
   878
haftmann@46635
   879
lemma Powp_Pow_eq [pred_set_conv]: "Powp (\<lambda>x. x \<in> A) = (\<lambda>x. x \<in> Pow A)"
haftmann@46635
   880
  by (auto simp add: Powp_def fun_eq_iff)
haftmann@46635
   881
haftmann@46635
   882
lemmas Powp_mono [mono] = Pow_mono [to_pred]
haftmann@46635
   883
haftmann@46635
   884
haftmann@46635
   885
subsubsection {* Properties of predicate relations *}
haftmann@46635
   886
haftmann@46635
   887
abbreviation antisymP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46635
   888
  "antisymP r \<equiv> antisym {(x, y). r x y}"
haftmann@46635
   889
haftmann@46635
   890
abbreviation transP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46635
   891
  "transP r \<equiv> trans {(x, y). r x y}"
haftmann@46635
   892
haftmann@46635
   893
abbreviation single_valuedP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46635
   894
  "single_valuedP r \<equiv> single_valued {(x, y). r x y}"
haftmann@46635
   895
haftmann@46635
   896
(*FIXME inconsistencies: abbreviations vs. definitions, suffix `P` vs. suffix `p`*)
haftmann@46635
   897
haftmann@46635
   898
definition reflp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46635
   899
  "reflp r \<longleftrightarrow> refl {(x, y). r x y}"
haftmann@46635
   900
haftmann@46635
   901
definition symp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46635
   902
  "symp r \<longleftrightarrow> sym {(x, y). r x y}"
haftmann@46635
   903
haftmann@46635
   904
definition transp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46635
   905
  "transp r \<longleftrightarrow> trans {(x, y). r x y}"
haftmann@46635
   906
haftmann@46635
   907
lemma reflpI:
haftmann@46635
   908
  "(\<And>x. r x x) \<Longrightarrow> reflp r"
haftmann@46635
   909
  by (auto intro: refl_onI simp add: reflp_def)
haftmann@46635
   910
haftmann@46635
   911
lemma reflpE:
haftmann@46635
   912
  assumes "reflp r"
haftmann@46635
   913
  obtains "r x x"
haftmann@46635
   914
  using assms by (auto dest: refl_onD simp add: reflp_def)
haftmann@46635
   915
haftmann@46635
   916
lemma sympI:
haftmann@46635
   917
  "(\<And>x y. r x y \<Longrightarrow> r y x) \<Longrightarrow> symp r"
haftmann@46635
   918
  by (auto intro: symI simp add: symp_def)
haftmann@46635
   919
haftmann@46635
   920
lemma sympE:
haftmann@46635
   921
  assumes "symp r" and "r x y"
haftmann@46635
   922
  obtains "r y x"
haftmann@46635
   923
  using assms by (auto dest: symD simp add: symp_def)
haftmann@46635
   924
haftmann@46635
   925
lemma transpI:
haftmann@46635
   926
  "(\<And>x y z. r x y \<Longrightarrow> r y z \<Longrightarrow> r x z) \<Longrightarrow> transp r"
haftmann@46635
   927
  by (auto intro: transI simp add: transp_def)
haftmann@46635
   928
  
haftmann@46635
   929
lemma transpE:
haftmann@46635
   930
  assumes "transp r" and "r x y" and "r y z"
haftmann@46635
   931
  obtains "r x z"
haftmann@46635
   932
  using assms by (auto dest: transD simp add: transp_def)
haftmann@46635
   933
nipkow@1128
   934
end