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