src/ZF/EquivClass.thy
author wenzelm
Thu Dec 14 11:24:26 2017 +0100 (20 months ago)
changeset 67198 694f29a5433b
parent 61798 27f3c10b0b50
child 67443 3abf6a722518
permissions -rw-r--r--
merged
wenzelm@23146
     1
(*  Title:      ZF/EquivClass.thy
wenzelm@23146
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
wenzelm@23146
     3
    Copyright   1994  University of Cambridge
wenzelm@23146
     4
*)
wenzelm@23146
     5
wenzelm@60770
     6
section\<open>Equivalence Relations\<close>
wenzelm@23146
     7
wenzelm@23146
     8
theory EquivClass imports Trancl Perm begin
wenzelm@23146
     9
wenzelm@24893
    10
definition
wenzelm@24893
    11
  quotient   :: "[i,i]=>i"    (infixl "'/'/" 90)  (*set of equiv classes*)  where
paulson@46953
    12
      "A//r == {r``{x} . x \<in> A}"
wenzelm@23146
    13
wenzelm@24893
    14
definition
wenzelm@24893
    15
  congruent  :: "[i,i=>i]=>o"  where
paulson@46820
    16
      "congruent(r,b) == \<forall>y z. <y,z>:r \<longrightarrow> b(y)=b(z)"
wenzelm@23146
    17
wenzelm@24893
    18
definition
wenzelm@24893
    19
  congruent2 :: "[i,i,[i,i]=>i]=>o"  where
paulson@46820
    20
      "congruent2(r1,r2,b) == \<forall>y1 z1 y2 z2.
paulson@46820
    21
           <y1,z1>:r1 \<longrightarrow> <y2,z2>:r2 \<longrightarrow> b(y1,y2) = b(z1,z2)"
wenzelm@23146
    22
wenzelm@24892
    23
abbreviation
wenzelm@24892
    24
  RESPECTS ::"[i=>i, i] => o"  (infixr "respects" 80) where
wenzelm@24892
    25
  "f respects r == congruent(r,f)"
wenzelm@24892
    26
wenzelm@24892
    27
abbreviation
wenzelm@24892
    28
  RESPECTS2 ::"[i=>i=>i, i] => o"  (infixr "respects2 " 80) where
wenzelm@24892
    29
  "f respects2 r == congruent2(r,r,f)"
wenzelm@61798
    30
    \<comment>\<open>Abbreviation for the common case where the relations are identical\<close>
wenzelm@23146
    31
wenzelm@23146
    32
wenzelm@60770
    33
subsection\<open>Suppes, Theorem 70:
wenzelm@60770
    34
    @{term r} is an equiv relation iff @{term "converse(r) O r = r"}\<close>
wenzelm@23146
    35
wenzelm@23146
    36
(** first half: equiv(A,r) ==> converse(r) O r = r **)
wenzelm@23146
    37
wenzelm@23146
    38
lemma sym_trans_comp_subset:
paulson@46820
    39
    "[| sym(r); trans(r) |] ==> converse(r) O r \<subseteq> r"
wenzelm@23146
    40
by (unfold trans_def sym_def, blast)
wenzelm@23146
    41
wenzelm@23146
    42
lemma refl_comp_subset:
paulson@46820
    43
    "[| refl(A,r); r \<subseteq> A*A |] ==> r \<subseteq> converse(r) O r"
wenzelm@23146
    44
by (unfold refl_def, blast)
wenzelm@23146
    45
wenzelm@23146
    46
lemma equiv_comp_eq:
wenzelm@23146
    47
    "equiv(A,r) ==> converse(r) O r = r"
wenzelm@23146
    48
apply (unfold equiv_def)
wenzelm@23146
    49
apply (blast del: subsetI intro!: sym_trans_comp_subset refl_comp_subset)
wenzelm@23146
    50
done
wenzelm@23146
    51
wenzelm@23146
    52
(*second half*)
wenzelm@23146
    53
lemma comp_equivI:
wenzelm@23146
    54
    "[| converse(r) O r = r;  domain(r) = A |] ==> equiv(A,r)"
wenzelm@23146
    55
apply (unfold equiv_def refl_def sym_def trans_def)
wenzelm@23146
    56
apply (erule equalityE)
paulson@46820
    57
apply (subgoal_tac "\<forall>x y. <x,y> \<in> r \<longrightarrow> <y,x> \<in> r", blast+)
wenzelm@23146
    58
done
wenzelm@23146
    59
wenzelm@23146
    60
(** Equivalence classes **)
wenzelm@23146
    61
wenzelm@23146
    62
(*Lemma for the next result*)
wenzelm@23146
    63
lemma equiv_class_subset:
paulson@46820
    64
    "[| sym(r);  trans(r);  <a,b>: r |] ==> r``{a} \<subseteq> r``{b}"
wenzelm@23146
    65
by (unfold trans_def sym_def, blast)
wenzelm@23146
    66
wenzelm@23146
    67
lemma equiv_class_eq:
wenzelm@23146
    68
    "[| equiv(A,r);  <a,b>: r |] ==> r``{a} = r``{b}"
wenzelm@23146
    69
apply (unfold equiv_def)
wenzelm@23146
    70
apply (safe del: subsetI intro!: equalityI equiv_class_subset)
wenzelm@23146
    71
apply (unfold sym_def, blast)
wenzelm@23146
    72
done
wenzelm@23146
    73
wenzelm@23146
    74
lemma equiv_class_self:
paulson@46953
    75
    "[| equiv(A,r);  a \<in> A |] ==> a \<in> r``{a}"
wenzelm@23146
    76
by (unfold equiv_def refl_def, blast)
wenzelm@23146
    77
wenzelm@23146
    78
(*Lemma for the next result*)
wenzelm@23146
    79
lemma subset_equiv_class:
paulson@46953
    80
    "[| equiv(A,r);  r``{b} \<subseteq> r``{a};  b \<in> A |] ==> <a,b>: r"
wenzelm@23146
    81
by (unfold equiv_def refl_def, blast)
wenzelm@23146
    82
paulson@46953
    83
lemma eq_equiv_class: "[| r``{a} = r``{b};  equiv(A,r);  b \<in> A |] ==> <a,b>: r"
wenzelm@23146
    84
by (assumption | rule equalityD2 subset_equiv_class)+
wenzelm@23146
    85
wenzelm@23146
    86
(*thus r``{a} = r``{b} as well*)
wenzelm@23146
    87
lemma equiv_class_nondisjoint:
paulson@46820
    88
    "[| equiv(A,r);  x: (r``{a} \<inter> r``{b}) |] ==> <a,b>: r"
wenzelm@23146
    89
by (unfold equiv_def trans_def sym_def, blast)
wenzelm@23146
    90
paulson@46820
    91
lemma equiv_type: "equiv(A,r) ==> r \<subseteq> A*A"
wenzelm@23146
    92
by (unfold equiv_def, blast)
wenzelm@23146
    93
wenzelm@23146
    94
lemma equiv_class_eq_iff:
paulson@46953
    95
     "equiv(A,r) ==> <x,y>: r \<longleftrightarrow> r``{x} = r``{y} & x \<in> A & y \<in> A"
wenzelm@23146
    96
by (blast intro: eq_equiv_class equiv_class_eq dest: equiv_type)
wenzelm@23146
    97
wenzelm@23146
    98
lemma eq_equiv_class_iff:
paulson@46953
    99
     "[| equiv(A,r);  x \<in> A;  y \<in> A |] ==> r``{x} = r``{y} \<longleftrightarrow> <x,y>: r"
wenzelm@23146
   100
by (blast intro: eq_equiv_class equiv_class_eq dest: equiv_type)
wenzelm@23146
   101
wenzelm@23146
   102
(*** Quotients ***)
wenzelm@23146
   103
wenzelm@23146
   104
(** Introduction/elimination rules -- needed? **)
wenzelm@23146
   105
paulson@46953
   106
lemma quotientI [TC]: "x \<in> A ==> r``{x}: A//r"
wenzelm@23146
   107
apply (unfold quotient_def)
wenzelm@23146
   108
apply (erule RepFunI)
wenzelm@23146
   109
done
wenzelm@23146
   110
wenzelm@23146
   111
lemma quotientE:
paulson@46953
   112
    "[| X \<in> A//r;  !!x. [| X = r``{x};  x \<in> A |] ==> P |] ==> P"
wenzelm@23146
   113
by (unfold quotient_def, blast)
wenzelm@23146
   114
wenzelm@23146
   115
lemma Union_quotient:
paulson@46820
   116
    "equiv(A,r) ==> \<Union>(A//r) = A"
wenzelm@23146
   117
by (unfold equiv_def refl_def quotient_def, blast)
wenzelm@23146
   118
wenzelm@23146
   119
lemma quotient_disj:
paulson@46953
   120
    "[| equiv(A,r);  X \<in> A//r;  Y \<in> A//r |] ==> X=Y | (X \<inter> Y \<subseteq> 0)"
wenzelm@23146
   121
apply (unfold quotient_def)
wenzelm@23146
   122
apply (safe intro!: equiv_class_eq, assumption)
wenzelm@23146
   123
apply (unfold equiv_def trans_def sym_def, blast)
wenzelm@23146
   124
done
wenzelm@23146
   125
wenzelm@60770
   126
subsection\<open>Defining Unary Operations upon Equivalence Classes\<close>
wenzelm@23146
   127
wenzelm@23146
   128
(** Could have a locale with the premises equiv(A,r)  and  congruent(r,b)
wenzelm@23146
   129
**)
wenzelm@23146
   130
wenzelm@23146
   131
(*Conversion rule*)
wenzelm@23146
   132
lemma UN_equiv_class:
paulson@46953
   133
    "[| equiv(A,r);  b respects r;  a \<in> A |] ==> (\<Union>x\<in>r``{a}. b(x)) = b(a)"
paulson@46820
   134
apply (subgoal_tac "\<forall>x \<in> r``{a}. b(x) = b(a)")
wenzelm@23146
   135
 apply simp
paulson@46820
   136
 apply (blast intro: equiv_class_self)
wenzelm@23146
   137
apply (unfold equiv_def sym_def congruent_def, blast)
wenzelm@23146
   138
done
wenzelm@23146
   139
paulson@46820
   140
(*type checking of  @{term"\<Union>x\<in>r``{a}. b(x)"} *)
wenzelm@23146
   141
lemma UN_equiv_class_type:
paulson@46953
   142
    "[| equiv(A,r);  b respects r;  X \<in> A//r;  !!x.  x \<in> A ==> b(x) \<in> B |]
paulson@46820
   143
     ==> (\<Union>x\<in>X. b(x)) \<in> B"
wenzelm@23146
   144
apply (unfold quotient_def, safe)
wenzelm@23146
   145
apply (simp (no_asm_simp) add: UN_equiv_class)
wenzelm@23146
   146
done
wenzelm@23146
   147
wenzelm@23146
   148
(*Sufficient conditions for injectiveness.  Could weaken premises!
paulson@46953
   149
  major premise could be an inclusion; bcong could be !!y. y \<in> A ==> b(y):B
wenzelm@23146
   150
*)
wenzelm@23146
   151
lemma UN_equiv_class_inject:
wenzelm@23146
   152
    "[| equiv(A,r);   b respects r;
paulson@46953
   153
        (\<Union>x\<in>X. b(x))=(\<Union>y\<in>Y. b(y));  X \<in> A//r;  Y \<in> A//r;
paulson@46953
   154
        !!x y. [| x \<in> A; y \<in> A; b(x)=b(y) |] ==> <x,y>:r |]
wenzelm@23146
   155
     ==> X=Y"
wenzelm@23146
   156
apply (unfold quotient_def, safe)
wenzelm@23146
   157
apply (rule equiv_class_eq, assumption)
paulson@46820
   158
apply (simp add: UN_equiv_class [of A r b])
wenzelm@23146
   159
done
wenzelm@23146
   160
wenzelm@23146
   161
wenzelm@60770
   162
subsection\<open>Defining Binary Operations upon Equivalence Classes\<close>
wenzelm@23146
   163
wenzelm@23146
   164
lemma congruent2_implies_congruent:
paulson@46953
   165
    "[| equiv(A,r1);  congruent2(r1,r2,b);  a \<in> A |] ==> congruent(r2,b(a))"
wenzelm@23146
   166
by (unfold congruent_def congruent2_def equiv_def refl_def, blast)
wenzelm@23146
   167
wenzelm@23146
   168
lemma congruent2_implies_congruent_UN:
paulson@46953
   169
    "[| equiv(A1,r1);  equiv(A2,r2);  congruent2(r1,r2,b);  a \<in> A2 |] ==>
wenzelm@23146
   170
     congruent(r1, %x1. \<Union>x2 \<in> r2``{a}. b(x1,x2))"
wenzelm@23146
   171
apply (unfold congruent_def, safe)
wenzelm@23146
   172
apply (frule equiv_type [THEN subsetD], assumption)
paulson@46820
   173
apply clarify
wenzelm@23146
   174
apply (simp add: UN_equiv_class congruent2_implies_congruent)
wenzelm@23146
   175
apply (unfold congruent2_def equiv_def refl_def, blast)
wenzelm@23146
   176
done
wenzelm@23146
   177
wenzelm@23146
   178
lemma UN_equiv_class2:
wenzelm@23146
   179
    "[| equiv(A1,r1);  equiv(A2,r2);  congruent2(r1,r2,b);  a1: A1;  a2: A2 |]
wenzelm@23146
   180
     ==> (\<Union>x1 \<in> r1``{a1}. \<Union>x2 \<in> r2``{a2}. b(x1,x2)) = b(a1,a2)"
wenzelm@23146
   181
by (simp add: UN_equiv_class congruent2_implies_congruent
wenzelm@23146
   182
              congruent2_implies_congruent_UN)
wenzelm@23146
   183
wenzelm@23146
   184
(*type checking*)
wenzelm@23146
   185
lemma UN_equiv_class_type2:
wenzelm@23146
   186
    "[| equiv(A,r);  b respects2 r;
wenzelm@23146
   187
        X1: A//r;  X2: A//r;
paulson@46820
   188
        !!x1 x2.  [| x1: A; x2: A |] ==> b(x1,x2) \<in> B
paulson@46820
   189
     |] ==> (\<Union>x1\<in>X1. \<Union>x2\<in>X2. b(x1,x2)) \<in> B"
wenzelm@23146
   190
apply (unfold quotient_def, safe)
paulson@46820
   191
apply (blast intro: UN_equiv_class_type congruent2_implies_congruent_UN
wenzelm@23146
   192
                    congruent2_implies_congruent quotientI)
wenzelm@23146
   193
done
wenzelm@23146
   194
wenzelm@23146
   195
wenzelm@23146
   196
(*Suggested by John Harrison -- the two subproofs may be MUCH simpler
wenzelm@23146
   197
  than the direct proof*)
wenzelm@23146
   198
lemma congruent2I:
paulson@46820
   199
    "[|  equiv(A1,r1);  equiv(A2,r2);
wenzelm@23146
   200
        !! y z w. [| w \<in> A2;  <y,z> \<in> r1 |] ==> b(y,w) = b(z,w);
wenzelm@23146
   201
        !! y z w. [| w \<in> A1;  <y,z> \<in> r2 |] ==> b(w,y) = b(w,z)
wenzelm@23146
   202
     |] ==> congruent2(r1,r2,b)"
wenzelm@23146
   203
apply (unfold congruent2_def equiv_def refl_def, safe)
paulson@46820
   204
apply (blast intro: trans)
wenzelm@23146
   205
done
wenzelm@23146
   206
wenzelm@23146
   207
lemma congruent2_commuteI:
wenzelm@23146
   208
 assumes equivA: "equiv(A,r)"
paulson@46953
   209
     and commute: "!! y z. [| y \<in> A;  z \<in> A |] ==> b(y,z) = b(z,y)"
paulson@46953
   210
     and congt:   "!! y z w. [| w \<in> A;  <y,z>: r |] ==> b(w,y) = b(w,z)"
wenzelm@23146
   211
 shows "b respects2 r"
paulson@46820
   212
apply (insert equivA [THEN equiv_type, THEN subsetD])
wenzelm@23146
   213
apply (rule congruent2I [OF equivA equivA])
wenzelm@23146
   214
apply (rule commute [THEN trans])
wenzelm@23146
   215
apply (rule_tac [3] commute [THEN trans, symmetric])
paulson@46820
   216
apply (rule_tac [5] sym)
wenzelm@23146
   217
apply (blast intro: congt)+
wenzelm@23146
   218
done
wenzelm@23146
   219
wenzelm@23146
   220
(*Obsolete?*)
wenzelm@23146
   221
lemma congruent_commuteI:
paulson@46953
   222
    "[| equiv(A,r);  Z \<in> A//r;
paulson@46953
   223
        !!w. [| w \<in> A |] ==> congruent(r, %z. b(w,z));
paulson@46953
   224
        !!x y. [| x \<in> A;  y \<in> A |] ==> b(y,x) = b(x,y)
paulson@46820
   225
     |] ==> congruent(r, %w. \<Union>z\<in>Z. b(w,z))"
wenzelm@23146
   226
apply (simp (no_asm) add: congruent_def)
wenzelm@23146
   227
apply (safe elim!: quotientE)
wenzelm@23146
   228
apply (frule equiv_type [THEN subsetD], assumption)
paulson@46820
   229
apply (simp add: UN_equiv_class [of A r])
paulson@46820
   230
apply (simp add: congruent_def)
wenzelm@23146
   231
done
wenzelm@23146
   232
wenzelm@23146
   233
end