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