src/HOL/Equiv_Relations.thy
author blanchet
Wed Feb 12 08:35:57 2014 +0100 (2014-02-12)
changeset 55415 05f5fdb8d093
parent 55024 05cc0dbf3a50
child 58889 5b7a9633cfa8
permissions -rw-r--r--
renamed 'nat_{case,rec}' to '{case,rec}_nat'
haftmann@29655
     1
(*  Authors:    Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@15300
     2
    Copyright   1996  University of Cambridge
paulson@15300
     3
*)
paulson@15300
     4
paulson@15300
     5
header {* Equivalence Relations in Higher-Order Set Theory *}
paulson@15300
     6
paulson@15300
     7
theory Equiv_Relations
haftmann@54744
     8
imports Groups_Big Relation
paulson@15300
     9
begin
paulson@15300
    10
haftmann@40812
    11
subsection {* Equivalence relations -- set version *}
paulson@15300
    12
haftmann@40812
    13
definition equiv :: "'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> bool" where
haftmann@40812
    14
  "equiv A r \<longleftrightarrow> refl_on A r \<and> sym r \<and> trans r"
paulson@15300
    15
haftmann@40815
    16
lemma equivI:
haftmann@40815
    17
  "refl_on A r \<Longrightarrow> sym r \<Longrightarrow> trans r \<Longrightarrow> equiv A r"
haftmann@40815
    18
  by (simp add: equiv_def)
haftmann@40815
    19
haftmann@40815
    20
lemma equivE:
haftmann@40815
    21
  assumes "equiv A r"
haftmann@40815
    22
  obtains "refl_on A r" and "sym r" and "trans r"
haftmann@40815
    23
  using assms by (simp add: equiv_def)
haftmann@40815
    24
paulson@15300
    25
text {*
paulson@15300
    26
  Suppes, Theorem 70: @{text r} is an equiv relation iff @{text "r\<inverse> O
paulson@15300
    27
  r = r"}.
paulson@15300
    28
paulson@15300
    29
  First half: @{text "equiv A r ==> r\<inverse> O r = r"}.
paulson@15300
    30
*}
paulson@15300
    31
paulson@15300
    32
lemma sym_trans_comp_subset:
paulson@15300
    33
    "sym r ==> trans r ==> r\<inverse> O r \<subseteq> r"
haftmann@46752
    34
  by (unfold trans_def sym_def converse_unfold) blast
paulson@15300
    35
nipkow@30198
    36
lemma refl_on_comp_subset: "refl_on A r ==> r \<subseteq> r\<inverse> O r"
nipkow@30198
    37
  by (unfold refl_on_def) blast
paulson@15300
    38
paulson@15300
    39
lemma equiv_comp_eq: "equiv A r ==> r\<inverse> O r = r"
paulson@15300
    40
  apply (unfold equiv_def)
paulson@15300
    41
  apply clarify
paulson@15300
    42
  apply (rule equalityI)
nipkow@30198
    43
   apply (iprover intro: sym_trans_comp_subset refl_on_comp_subset)+
paulson@15300
    44
  done
paulson@15300
    45
paulson@15300
    46
text {* Second half. *}
paulson@15300
    47
paulson@15300
    48
lemma comp_equivI:
paulson@15300
    49
    "r\<inverse> O r = r ==> Domain r = A ==> equiv A r"
nipkow@30198
    50
  apply (unfold equiv_def refl_on_def sym_def trans_def)
paulson@15300
    51
  apply (erule equalityE)
paulson@15300
    52
  apply (subgoal_tac "\<forall>x y. (x, y) \<in> r --> (y, x) \<in> r")
paulson@15300
    53
   apply fast
paulson@15300
    54
  apply fast
paulson@15300
    55
  done
paulson@15300
    56
paulson@15300
    57
paulson@15300
    58
subsection {* Equivalence classes *}
paulson@15300
    59
paulson@15300
    60
lemma equiv_class_subset:
paulson@15300
    61
  "equiv A r ==> (a, b) \<in> r ==> r``{a} \<subseteq> r``{b}"
paulson@15300
    62
  -- {* lemma for the next result *}
paulson@15300
    63
  by (unfold equiv_def trans_def sym_def) blast
paulson@15300
    64
paulson@15300
    65
theorem equiv_class_eq: "equiv A r ==> (a, b) \<in> r ==> r``{a} = r``{b}"
paulson@15300
    66
  apply (assumption | rule equalityI equiv_class_subset)+
paulson@15300
    67
  apply (unfold equiv_def sym_def)
paulson@15300
    68
  apply blast
paulson@15300
    69
  done
paulson@15300
    70
paulson@15300
    71
lemma equiv_class_self: "equiv A r ==> a \<in> A ==> a \<in> r``{a}"
nipkow@30198
    72
  by (unfold equiv_def refl_on_def) blast
paulson@15300
    73
paulson@15300
    74
lemma subset_equiv_class:
paulson@15300
    75
    "equiv A r ==> r``{b} \<subseteq> r``{a} ==> b \<in> A ==> (a,b) \<in> r"
paulson@15300
    76
  -- {* lemma for the next result *}
nipkow@30198
    77
  by (unfold equiv_def refl_on_def) blast
paulson@15300
    78
paulson@15300
    79
lemma eq_equiv_class:
paulson@15300
    80
    "r``{a} = r``{b} ==> equiv A r ==> b \<in> A ==> (a, b) \<in> r"
nipkow@17589
    81
  by (iprover intro: equalityD2 subset_equiv_class)
paulson@15300
    82
paulson@15300
    83
lemma equiv_class_nondisjoint:
paulson@15300
    84
    "equiv A r ==> x \<in> (r``{a} \<inter> r``{b}) ==> (a, b) \<in> r"
paulson@15300
    85
  by (unfold equiv_def trans_def sym_def) blast
paulson@15300
    86
paulson@15300
    87
lemma equiv_type: "equiv A r ==> r \<subseteq> A \<times> A"
nipkow@30198
    88
  by (unfold equiv_def refl_on_def) blast
paulson@15300
    89
paulson@15300
    90
theorem equiv_class_eq_iff:
paulson@15300
    91
  "equiv A r ==> ((x, y) \<in> r) = (r``{x} = r``{y} & x \<in> A & y \<in> A)"
paulson@15300
    92
  by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type)
paulson@15300
    93
paulson@15300
    94
theorem eq_equiv_class_iff:
paulson@15300
    95
  "equiv A r ==> x \<in> A ==> y \<in> A ==> (r``{x} = r``{y}) = ((x, y) \<in> r)"
paulson@15300
    96
  by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type)
paulson@15300
    97
paulson@15300
    98
paulson@15300
    99
subsection {* Quotients *}
paulson@15300
   100
haftmann@28229
   101
definition quotient :: "'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> 'a set set"  (infixl "'/'/" 90) where
haftmann@37767
   102
  "A//r = (\<Union>x \<in> A. {r``{x}})"  -- {* set of equiv classes *}
paulson@15300
   103
paulson@15300
   104
lemma quotientI: "x \<in> A ==> r``{x} \<in> A//r"
paulson@15300
   105
  by (unfold quotient_def) blast
paulson@15300
   106
paulson@15300
   107
lemma quotientE:
paulson@15300
   108
  "X \<in> A//r ==> (!!x. X = r``{x} ==> x \<in> A ==> P) ==> P"
paulson@15300
   109
  by (unfold quotient_def) blast
paulson@15300
   110
paulson@15300
   111
lemma Union_quotient: "equiv A r ==> Union (A//r) = A"
nipkow@30198
   112
  by (unfold equiv_def refl_on_def quotient_def) blast
paulson@15300
   113
paulson@15300
   114
lemma quotient_disj:
paulson@15300
   115
  "equiv A r ==> X \<in> A//r ==> Y \<in> A//r ==> X = Y | (X \<inter> Y = {})"
paulson@15300
   116
  apply (unfold quotient_def)
paulson@15300
   117
  apply clarify
paulson@15300
   118
  apply (rule equiv_class_eq)
paulson@15300
   119
   apply assumption
paulson@15300
   120
  apply (unfold equiv_def trans_def sym_def)
paulson@15300
   121
  apply blast
paulson@15300
   122
  done
paulson@15300
   123
paulson@15300
   124
lemma quotient_eqI:
paulson@15300
   125
  "[|equiv A r; X \<in> A//r; Y \<in> A//r; x \<in> X; y \<in> Y; (x,y) \<in> r|] ==> X = Y" 
paulson@15300
   126
  apply (clarify elim!: quotientE)
paulson@15300
   127
  apply (rule equiv_class_eq, assumption)
paulson@15300
   128
  apply (unfold equiv_def sym_def trans_def, blast)
paulson@15300
   129
  done
paulson@15300
   130
paulson@15300
   131
lemma quotient_eq_iff:
paulson@15300
   132
  "[|equiv A r; X \<in> A//r; Y \<in> A//r; x \<in> X; y \<in> Y|] ==> (X = Y) = ((x,y) \<in> r)" 
paulson@15300
   133
  apply (rule iffI)  
paulson@15300
   134
   prefer 2 apply (blast del: equalityI intro: quotient_eqI) 
paulson@15300
   135
  apply (clarify elim!: quotientE)
paulson@15300
   136
  apply (unfold equiv_def sym_def trans_def, blast)
paulson@15300
   137
  done
paulson@15300
   138
nipkow@18493
   139
lemma eq_equiv_class_iff2:
nipkow@18493
   140
  "\<lbrakk> equiv A r; x \<in> A; y \<in> A \<rbrakk> \<Longrightarrow> ({x}//r = {y}//r) = ((x,y) : r)"
nipkow@18493
   141
by(simp add:quotient_def eq_equiv_class_iff)
nipkow@18493
   142
paulson@15300
   143
paulson@15300
   144
lemma quotient_empty [simp]: "{}//r = {}"
paulson@15300
   145
by(simp add: quotient_def)
paulson@15300
   146
paulson@15300
   147
lemma quotient_is_empty [iff]: "(A//r = {}) = (A = {})"
paulson@15300
   148
by(simp add: quotient_def)
paulson@15300
   149
paulson@15300
   150
lemma quotient_is_empty2 [iff]: "({} = A//r) = (A = {})"
paulson@15300
   151
by(simp add: quotient_def)
paulson@15300
   152
paulson@15300
   153
nipkow@15302
   154
lemma singleton_quotient: "{x}//r = {r `` {x}}"
nipkow@15302
   155
by(simp add:quotient_def)
nipkow@15302
   156
nipkow@15302
   157
lemma quotient_diff1:
nipkow@15302
   158
  "\<lbrakk> inj_on (%a. {a}//r) A; a \<in> A \<rbrakk> \<Longrightarrow> (A - {a})//r = A//r - {a}//r"
nipkow@15302
   159
apply(simp add:quotient_def inj_on_def)
nipkow@15302
   160
apply blast
nipkow@15302
   161
done
nipkow@15302
   162
blanchet@55022
   163
paulson@15300
   164
subsection {* Defining unary operations upon equivalence classes *}
paulson@15300
   165
paulson@15300
   166
text{*A congruence-preserving function*}
haftmann@40816
   167
haftmann@44278
   168
definition congruent :: "('a \<times> 'a) set \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"  where
haftmann@40817
   169
  "congruent r f \<longleftrightarrow> (\<forall>(y, z) \<in> r. f y = f z)"
haftmann@40816
   170
haftmann@40816
   171
lemma congruentI:
haftmann@40816
   172
  "(\<And>y z. (y, z) \<in> r \<Longrightarrow> f y = f z) \<Longrightarrow> congruent r f"
haftmann@40817
   173
  by (auto simp add: congruent_def)
haftmann@40816
   174
haftmann@40816
   175
lemma congruentD:
haftmann@40816
   176
  "congruent r f \<Longrightarrow> (y, z) \<in> r \<Longrightarrow> f y = f z"
haftmann@40817
   177
  by (auto simp add: congruent_def)
paulson@15300
   178
wenzelm@19363
   179
abbreviation
wenzelm@21404
   180
  RESPECTS :: "('a => 'b) => ('a * 'a) set => bool"
wenzelm@21404
   181
    (infixr "respects" 80) where
wenzelm@19363
   182
  "f respects r == congruent r f"
paulson@15300
   183
paulson@15300
   184
paulson@15300
   185
lemma UN_constant_eq: "a \<in> A ==> \<forall>y \<in> A. f y = c ==> (\<Union>y \<in> A. f(y))=c"
paulson@15300
   186
  -- {* lemma required to prove @{text UN_equiv_class} *}
paulson@15300
   187
  by auto
paulson@15300
   188
paulson@15300
   189
lemma UN_equiv_class:
paulson@15300
   190
  "equiv A r ==> f respects r ==> a \<in> A
paulson@15300
   191
    ==> (\<Union>x \<in> r``{a}. f x) = f a"
paulson@15300
   192
  -- {* Conversion rule *}
paulson@15300
   193
  apply (rule equiv_class_self [THEN UN_constant_eq], assumption+)
paulson@15300
   194
  apply (unfold equiv_def congruent_def sym_def)
paulson@15300
   195
  apply (blast del: equalityI)
paulson@15300
   196
  done
paulson@15300
   197
paulson@15300
   198
lemma UN_equiv_class_type:
paulson@15300
   199
  "equiv A r ==> f respects r ==> X \<in> A//r ==>
paulson@15300
   200
    (!!x. x \<in> A ==> f x \<in> B) ==> (\<Union>x \<in> X. f x) \<in> B"
paulson@15300
   201
  apply (unfold quotient_def)
paulson@15300
   202
  apply clarify
paulson@15300
   203
  apply (subst UN_equiv_class)
paulson@15300
   204
     apply auto
paulson@15300
   205
  done
paulson@15300
   206
paulson@15300
   207
text {*
paulson@15300
   208
  Sufficient conditions for injectiveness.  Could weaken premises!
paulson@15300
   209
  major premise could be an inclusion; bcong could be @{text "!!y. y \<in>
paulson@15300
   210
  A ==> f y \<in> B"}.
paulson@15300
   211
*}
paulson@15300
   212
paulson@15300
   213
lemma UN_equiv_class_inject:
paulson@15300
   214
  "equiv A r ==> f respects r ==>
paulson@15300
   215
    (\<Union>x \<in> X. f x) = (\<Union>y \<in> Y. f y) ==> X \<in> A//r ==> Y \<in> A//r
paulson@15300
   216
    ==> (!!x y. x \<in> A ==> y \<in> A ==> f x = f y ==> (x, y) \<in> r)
paulson@15300
   217
    ==> X = Y"
paulson@15300
   218
  apply (unfold quotient_def)
paulson@15300
   219
  apply clarify
paulson@15300
   220
  apply (rule equiv_class_eq)
paulson@15300
   221
   apply assumption
paulson@15300
   222
  apply (subgoal_tac "f x = f xa")
paulson@15300
   223
   apply blast
paulson@15300
   224
  apply (erule box_equals)
paulson@15300
   225
   apply (assumption | rule UN_equiv_class)+
paulson@15300
   226
  done
paulson@15300
   227
paulson@15300
   228
paulson@15300
   229
subsection {* Defining binary operations upon equivalence classes *}
paulson@15300
   230
paulson@15300
   231
text{*A congruence-preserving function of two arguments*}
haftmann@40817
   232
haftmann@44278
   233
definition congruent2 :: "('a \<times> 'a) set \<Rightarrow> ('b \<times> 'b) set \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> bool" where
haftmann@40817
   234
  "congruent2 r1 r2 f \<longleftrightarrow> (\<forall>(y1, z1) \<in> r1. \<forall>(y2, z2) \<in> r2. f y1 y2 = f z1 z2)"
haftmann@40817
   235
haftmann@40817
   236
lemma congruent2I':
haftmann@40817
   237
  assumes "\<And>y1 z1 y2 z2. (y1, z1) \<in> r1 \<Longrightarrow> (y2, z2) \<in> r2 \<Longrightarrow> f y1 y2 = f z1 z2"
haftmann@40817
   238
  shows "congruent2 r1 r2 f"
haftmann@40817
   239
  using assms by (auto simp add: congruent2_def)
haftmann@40817
   240
haftmann@40817
   241
lemma congruent2D:
haftmann@40817
   242
  "congruent2 r1 r2 f \<Longrightarrow> (y1, z1) \<in> r1 \<Longrightarrow> (y2, z2) \<in> r2 \<Longrightarrow> f y1 y2 = f z1 z2"
haftmann@40817
   243
  using assms by (auto simp add: congruent2_def)
paulson@15300
   244
paulson@15300
   245
text{*Abbreviation for the common case where the relations are identical*}
nipkow@19979
   246
abbreviation
wenzelm@21404
   247
  RESPECTS2:: "['a => 'a => 'b, ('a * 'a) set] => bool"
wenzelm@21749
   248
    (infixr "respects2" 80) where
nipkow@19979
   249
  "f respects2 r == congruent2 r r f"
nipkow@19979
   250
paulson@15300
   251
paulson@15300
   252
lemma congruent2_implies_congruent:
paulson@15300
   253
    "equiv A r1 ==> congruent2 r1 r2 f ==> a \<in> A ==> congruent r2 (f a)"
nipkow@30198
   254
  by (unfold congruent_def congruent2_def equiv_def refl_on_def) blast
paulson@15300
   255
paulson@15300
   256
lemma congruent2_implies_congruent_UN:
paulson@15300
   257
  "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a \<in> A2 ==>
paulson@15300
   258
    congruent r1 (\<lambda>x1. \<Union>x2 \<in> r2``{a}. f x1 x2)"
paulson@15300
   259
  apply (unfold congruent_def)
paulson@15300
   260
  apply clarify
paulson@15300
   261
  apply (rule equiv_type [THEN subsetD, THEN SigmaE2], assumption+)
paulson@15300
   262
  apply (simp add: UN_equiv_class congruent2_implies_congruent)
nipkow@30198
   263
  apply (unfold congruent2_def equiv_def refl_on_def)
paulson@15300
   264
  apply (blast del: equalityI)
paulson@15300
   265
  done
paulson@15300
   266
paulson@15300
   267
lemma UN_equiv_class2:
paulson@15300
   268
  "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a1 \<in> A1 ==> a2 \<in> A2
paulson@15300
   269
    ==> (\<Union>x1 \<in> r1``{a1}. \<Union>x2 \<in> r2``{a2}. f x1 x2) = f a1 a2"
paulson@15300
   270
  by (simp add: UN_equiv_class congruent2_implies_congruent
paulson@15300
   271
    congruent2_implies_congruent_UN)
paulson@15300
   272
paulson@15300
   273
lemma UN_equiv_class_type2:
paulson@15300
   274
  "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f
paulson@15300
   275
    ==> X1 \<in> A1//r1 ==> X2 \<in> A2//r2
paulson@15300
   276
    ==> (!!x1 x2. x1 \<in> A1 ==> x2 \<in> A2 ==> f x1 x2 \<in> B)
paulson@15300
   277
    ==> (\<Union>x1 \<in> X1. \<Union>x2 \<in> X2. f x1 x2) \<in> B"
paulson@15300
   278
  apply (unfold quotient_def)
paulson@15300
   279
  apply clarify
paulson@15300
   280
  apply (blast intro: UN_equiv_class_type congruent2_implies_congruent_UN
paulson@15300
   281
    congruent2_implies_congruent quotientI)
paulson@15300
   282
  done
paulson@15300
   283
paulson@15300
   284
lemma UN_UN_split_split_eq:
paulson@15300
   285
  "(\<Union>(x1, x2) \<in> X. \<Union>(y1, y2) \<in> Y. A x1 x2 y1 y2) =
paulson@15300
   286
    (\<Union>x \<in> X. \<Union>y \<in> Y. (\<lambda>(x1, x2). (\<lambda>(y1, y2). A x1 x2 y1 y2) y) x)"
paulson@15300
   287
  -- {* Allows a natural expression of binary operators, *}
paulson@15300
   288
  -- {* without explicit calls to @{text split} *}
paulson@15300
   289
  by auto
paulson@15300
   290
paulson@15300
   291
lemma congruent2I:
paulson@15300
   292
  "equiv A1 r1 ==> equiv A2 r2
paulson@15300
   293
    ==> (!!y z w. w \<in> A2 ==> (y,z) \<in> r1 ==> f y w = f z w)
paulson@15300
   294
    ==> (!!y z w. w \<in> A1 ==> (y,z) \<in> r2 ==> f w y = f w z)
paulson@15300
   295
    ==> congruent2 r1 r2 f"
paulson@15300
   296
  -- {* Suggested by John Harrison -- the two subproofs may be *}
paulson@15300
   297
  -- {* \emph{much} simpler than the direct proof. *}
nipkow@30198
   298
  apply (unfold congruent2_def equiv_def refl_on_def)
paulson@15300
   299
  apply clarify
paulson@15300
   300
  apply (blast intro: trans)
paulson@15300
   301
  done
paulson@15300
   302
paulson@15300
   303
lemma congruent2_commuteI:
paulson@15300
   304
  assumes equivA: "equiv A r"
paulson@15300
   305
    and commute: "!!y z. y \<in> A ==> z \<in> A ==> f y z = f z y"
paulson@15300
   306
    and congt: "!!y z w. w \<in> A ==> (y,z) \<in> r ==> f w y = f w z"
paulson@15300
   307
  shows "f respects2 r"
paulson@15300
   308
  apply (rule congruent2I [OF equivA equivA])
paulson@15300
   309
   apply (rule commute [THEN trans])
paulson@15300
   310
     apply (rule_tac [3] commute [THEN trans, symmetric])
paulson@15300
   311
       apply (rule_tac [5] sym)
haftmann@25482
   312
       apply (rule congt | assumption |
paulson@15300
   313
         erule equivA [THEN equiv_type, THEN subsetD, THEN SigmaE2])+
paulson@15300
   314
  done
paulson@15300
   315
haftmann@24728
   316
haftmann@24728
   317
subsection {* Quotients and finiteness *}
haftmann@24728
   318
wenzelm@40945
   319
text {*Suggested by Florian Kammüller*}
haftmann@24728
   320
haftmann@24728
   321
lemma finite_quotient: "finite A ==> r \<subseteq> A \<times> A ==> finite (A//r)"
haftmann@24728
   322
  -- {* recall @{thm equiv_type} *}
haftmann@24728
   323
  apply (rule finite_subset)
haftmann@24728
   324
   apply (erule_tac [2] finite_Pow_iff [THEN iffD2])
haftmann@24728
   325
  apply (unfold quotient_def)
haftmann@24728
   326
  apply blast
haftmann@24728
   327
  done
haftmann@24728
   328
haftmann@24728
   329
lemma finite_equiv_class:
haftmann@24728
   330
  "finite A ==> r \<subseteq> A \<times> A ==> X \<in> A//r ==> finite X"
haftmann@24728
   331
  apply (unfold quotient_def)
haftmann@24728
   332
  apply (rule finite_subset)
haftmann@24728
   333
   prefer 2 apply assumption
haftmann@24728
   334
  apply blast
haftmann@24728
   335
  done
haftmann@24728
   336
haftmann@24728
   337
lemma equiv_imp_dvd_card:
haftmann@24728
   338
  "finite A ==> equiv A r ==> \<forall>X \<in> A//r. k dvd card X
haftmann@24728
   339
    ==> k dvd card A"
berghofe@26791
   340
  apply (rule Union_quotient [THEN subst [where P="\<lambda>A. k dvd card A"]])
haftmann@24728
   341
   apply assumption
haftmann@24728
   342
  apply (rule dvd_partition)
haftmann@24728
   343
     prefer 3 apply (blast dest: quotient_disj)
haftmann@24728
   344
    apply (simp_all add: Union_quotient equiv_type)
haftmann@24728
   345
  done
haftmann@24728
   346
haftmann@24728
   347
lemma card_quotient_disjoint:
haftmann@24728
   348
 "\<lbrakk> finite A; inj_on (\<lambda>x. {x} // r) A \<rbrakk> \<Longrightarrow> card(A//r) = card A"
haftmann@24728
   349
apply(simp add:quotient_def)
haftmann@24728
   350
apply(subst card_UN_disjoint)
haftmann@24728
   351
   apply assumption
haftmann@24728
   352
  apply simp
nipkow@44890
   353
 apply(fastforce simp add:inj_on_def)
huffman@35216
   354
apply simp
haftmann@24728
   355
done
haftmann@24728
   356
haftmann@40812
   357
blanchet@55022
   358
subsection {* Projection *}
blanchet@55022
   359
blanchet@55022
   360
definition proj where "proj r x = r `` {x}"
blanchet@55022
   361
blanchet@55022
   362
lemma proj_preserves:
blanchet@55022
   363
"x \<in> A \<Longrightarrow> proj r x \<in> A//r"
blanchet@55022
   364
unfolding proj_def by (rule quotientI)
blanchet@55022
   365
blanchet@55022
   366
lemma proj_in_iff:
blanchet@55022
   367
assumes "equiv A r"
blanchet@55022
   368
shows "(proj r x \<in> A//r) = (x \<in> A)"
blanchet@55022
   369
apply(rule iffI, auto simp add: proj_preserves)
blanchet@55022
   370
unfolding proj_def quotient_def proof clarsimp
blanchet@55022
   371
  fix y assume y: "y \<in> A" and "r `` {x} = r `` {y}"
blanchet@55022
   372
  moreover have "y \<in> r `` {y}" using assms y unfolding equiv_def refl_on_def by blast
blanchet@55022
   373
  ultimately have "(x,y) \<in> r" by blast
blanchet@55022
   374
  thus "x \<in> A" using assms unfolding equiv_def refl_on_def by blast
blanchet@55022
   375
qed
blanchet@55022
   376
blanchet@55022
   377
lemma proj_iff:
blanchet@55022
   378
"\<lbrakk>equiv A r; {x,y} \<subseteq> A\<rbrakk> \<Longrightarrow> (proj r x = proj r y) = ((x,y) \<in> r)"
blanchet@55022
   379
by (simp add: proj_def eq_equiv_class_iff)
blanchet@55022
   380
blanchet@55022
   381
(*
blanchet@55022
   382
lemma in_proj: "\<lbrakk>equiv A r; x \<in> A\<rbrakk> \<Longrightarrow> x \<in> proj r x"
blanchet@55022
   383
unfolding proj_def equiv_def refl_on_def by blast
blanchet@55022
   384
*)
blanchet@55022
   385
blanchet@55022
   386
lemma proj_image: "(proj r) ` A = A//r"
blanchet@55022
   387
unfolding proj_def[abs_def] quotient_def by blast
blanchet@55022
   388
blanchet@55022
   389
lemma in_quotient_imp_non_empty:
blanchet@55022
   390
"\<lbrakk>equiv A r; X \<in> A//r\<rbrakk> \<Longrightarrow> X \<noteq> {}"
blanchet@55022
   391
unfolding quotient_def using equiv_class_self by fast
blanchet@55022
   392
blanchet@55022
   393
lemma in_quotient_imp_in_rel:
blanchet@55022
   394
"\<lbrakk>equiv A r; X \<in> A//r; {x,y} \<subseteq> X\<rbrakk> \<Longrightarrow> (x,y) \<in> r"
blanchet@55022
   395
using quotient_eq_iff[THEN iffD1] by fastforce
blanchet@55022
   396
blanchet@55022
   397
lemma in_quotient_imp_closed:
blanchet@55022
   398
"\<lbrakk>equiv A r; X \<in> A//r; x \<in> X; (x,y) \<in> r\<rbrakk> \<Longrightarrow> y \<in> X"
blanchet@55022
   399
unfolding quotient_def equiv_def trans_def by blast
blanchet@55022
   400
blanchet@55022
   401
lemma in_quotient_imp_subset:
blanchet@55022
   402
"\<lbrakk>equiv A r; X \<in> A//r\<rbrakk> \<Longrightarrow> X \<subseteq> A"
blanchet@55022
   403
using assms in_quotient_imp_in_rel equiv_type by fastforce
blanchet@55022
   404
blanchet@55022
   405
haftmann@40812
   406
subsection {* Equivalence relations -- predicate version *}
haftmann@40812
   407
haftmann@40812
   408
text {* Partial equivalences *}
haftmann@40812
   409
haftmann@40812
   410
definition part_equivp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@40812
   411
  "part_equivp R \<longleftrightarrow> (\<exists>x. R x x) \<and> (\<forall>x y. R x y \<longleftrightarrow> R x x \<and> R y y \<and> R x = R y)"
haftmann@40812
   412
    -- {* John-Harrison-style characterization *}
haftmann@40812
   413
haftmann@40812
   414
lemma part_equivpI:
haftmann@40812
   415
  "(\<exists>x. R x x) \<Longrightarrow> symp R \<Longrightarrow> transp R \<Longrightarrow> part_equivp R"
haftmann@45969
   416
  by (auto simp add: part_equivp_def) (auto elim: sympE transpE)
haftmann@40812
   417
haftmann@40812
   418
lemma part_equivpE:
haftmann@40812
   419
  assumes "part_equivp R"
haftmann@40812
   420
  obtains x where "R x x" and "symp R" and "transp R"
haftmann@40812
   421
proof -
haftmann@40812
   422
  from assms have 1: "\<exists>x. R x x"
haftmann@40812
   423
    and 2: "\<And>x y. R x y \<longleftrightarrow> R x x \<and> R y y \<and> R x = R y"
haftmann@40812
   424
    by (unfold part_equivp_def) blast+
haftmann@40812
   425
  from 1 obtain x where "R x x" ..
haftmann@40812
   426
  moreover have "symp R"
haftmann@40812
   427
  proof (rule sympI)
haftmann@40812
   428
    fix x y
haftmann@40812
   429
    assume "R x y"
haftmann@40812
   430
    with 2 [of x y] show "R y x" by auto
haftmann@40812
   431
  qed
haftmann@40812
   432
  moreover have "transp R"
haftmann@40812
   433
  proof (rule transpI)
haftmann@40812
   434
    fix x y z
haftmann@40812
   435
    assume "R x y" and "R y z"
haftmann@40812
   436
    with 2 [of x y] 2 [of y z] show "R x z" by auto
haftmann@40812
   437
  qed
haftmann@40812
   438
  ultimately show thesis by (rule that)
haftmann@40812
   439
qed
haftmann@40812
   440
haftmann@40812
   441
lemma part_equivp_refl_symp_transp:
haftmann@40812
   442
  "part_equivp R \<longleftrightarrow> (\<exists>x. R x x) \<and> symp R \<and> transp R"
haftmann@40812
   443
  by (auto intro: part_equivpI elim: part_equivpE)
haftmann@40812
   444
haftmann@40812
   445
lemma part_equivp_symp:
haftmann@40812
   446
  "part_equivp R \<Longrightarrow> R x y \<Longrightarrow> R y x"
haftmann@40812
   447
  by (erule part_equivpE, erule sympE)
haftmann@40812
   448
haftmann@40812
   449
lemma part_equivp_transp:
haftmann@40812
   450
  "part_equivp R \<Longrightarrow> R x y \<Longrightarrow> R y z \<Longrightarrow> R x z"
haftmann@40812
   451
  by (erule part_equivpE, erule transpE)
haftmann@40812
   452
haftmann@40812
   453
lemma part_equivp_typedef:
kaliszyk@44204
   454
  "part_equivp R \<Longrightarrow> \<exists>d. d \<in> {c. \<exists>x. R x x \<and> c = Collect (R x)}"
kaliszyk@44204
   455
  by (auto elim: part_equivpE)
haftmann@40812
   456
haftmann@40812
   457
haftmann@40812
   458
text {* Total equivalences *}
haftmann@40812
   459
haftmann@40812
   460
definition equivp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@40812
   461
  "equivp R \<longleftrightarrow> (\<forall>x y. R x y = (R x = R y))" -- {* John-Harrison-style characterization *}
haftmann@40812
   462
haftmann@40812
   463
lemma equivpI:
haftmann@40812
   464
  "reflp R \<Longrightarrow> symp R \<Longrightarrow> transp R \<Longrightarrow> equivp R"
haftmann@45969
   465
  by (auto elim: reflpE sympE transpE simp add: equivp_def)
haftmann@40812
   466
haftmann@40812
   467
lemma equivpE:
haftmann@40812
   468
  assumes "equivp R"
haftmann@40812
   469
  obtains "reflp R" and "symp R" and "transp R"
haftmann@40812
   470
  using assms by (auto intro!: that reflpI sympI transpI simp add: equivp_def)
haftmann@40812
   471
haftmann@40812
   472
lemma equivp_implies_part_equivp:
haftmann@40812
   473
  "equivp R \<Longrightarrow> part_equivp R"
haftmann@40812
   474
  by (auto intro: part_equivpI elim: equivpE reflpE)
haftmann@40812
   475
haftmann@40812
   476
lemma equivp_equiv:
haftmann@40812
   477
  "equiv UNIV A \<longleftrightarrow> equivp (\<lambda>x y. (x, y) \<in> A)"
haftmann@46752
   478
  by (auto intro!: equivI equivpI [to_set] elim!: equivE equivpE [to_set])
haftmann@40812
   479
haftmann@40812
   480
lemma equivp_reflp_symp_transp:
haftmann@40812
   481
  shows "equivp R \<longleftrightarrow> reflp R \<and> symp R \<and> transp R"
haftmann@40812
   482
  by (auto intro: equivpI elim: equivpE)
haftmann@40812
   483
haftmann@40812
   484
lemma identity_equivp:
haftmann@40812
   485
  "equivp (op =)"
haftmann@40812
   486
  by (auto intro: equivpI reflpI sympI transpI)
haftmann@40812
   487
haftmann@40812
   488
lemma equivp_reflp:
haftmann@40812
   489
  "equivp R \<Longrightarrow> R x x"
haftmann@40812
   490
  by (erule equivpE, erule reflpE)
haftmann@40812
   491
haftmann@40812
   492
lemma equivp_symp:
haftmann@40812
   493
  "equivp R \<Longrightarrow> R x y \<Longrightarrow> R y x"
haftmann@40812
   494
  by (erule equivpE, erule sympE)
haftmann@40812
   495
haftmann@40812
   496
lemma equivp_transp:
haftmann@40812
   497
  "equivp R \<Longrightarrow> R x y \<Longrightarrow> R y z \<Longrightarrow> R x z"
haftmann@40812
   498
  by (erule equivpE, erule transpE)
haftmann@40812
   499
blanchet@55024
   500
hide_const (open) proj
blanchet@55024
   501
paulson@15300
   502
end