src/HOL/Equiv_Relations.thy
changeset 30198 922f944f03b2
parent 29655 ac31940cfb69
child 35216 7641e8d831d2
equal deleted inserted replaced
30193:391e10b42889 30198:922f944f03b2
    10 
    10 
    11 subsection {* Equivalence relations *}
    11 subsection {* Equivalence relations *}
    12 
    12 
    13 locale equiv =
    13 locale equiv =
    14   fixes A and r
    14   fixes A and r
    15   assumes refl: "refl A r"
    15   assumes refl_on: "refl_on A r"
    16     and sym: "sym r"
    16     and sym: "sym r"
    17     and trans: "trans r"
    17     and trans: "trans r"
    18 
    18 
    19 text {*
    19 text {*
    20   Suppes, Theorem 70: @{text r} is an equiv relation iff @{text "r\<inverse> O
    20   Suppes, Theorem 70: @{text r} is an equiv relation iff @{text "r\<inverse> O
    25 
    25 
    26 lemma sym_trans_comp_subset:
    26 lemma sym_trans_comp_subset:
    27     "sym r ==> trans r ==> r\<inverse> O r \<subseteq> r"
    27     "sym r ==> trans r ==> r\<inverse> O r \<subseteq> r"
    28   by (unfold trans_def sym_def converse_def) blast
    28   by (unfold trans_def sym_def converse_def) blast
    29 
    29 
    30 lemma refl_comp_subset: "refl A r ==> r \<subseteq> r\<inverse> O r"
    30 lemma refl_on_comp_subset: "refl_on A r ==> r \<subseteq> r\<inverse> O r"
    31   by (unfold refl_def) blast
    31   by (unfold refl_on_def) blast
    32 
    32 
    33 lemma equiv_comp_eq: "equiv A r ==> r\<inverse> O r = r"
    33 lemma equiv_comp_eq: "equiv A r ==> r\<inverse> O r = r"
    34   apply (unfold equiv_def)
    34   apply (unfold equiv_def)
    35   apply clarify
    35   apply clarify
    36   apply (rule equalityI)
    36   apply (rule equalityI)
    37    apply (iprover intro: sym_trans_comp_subset refl_comp_subset)+
    37    apply (iprover intro: sym_trans_comp_subset refl_on_comp_subset)+
    38   done
    38   done
    39 
    39 
    40 text {* Second half. *}
    40 text {* Second half. *}
    41 
    41 
    42 lemma comp_equivI:
    42 lemma comp_equivI:
    43     "r\<inverse> O r = r ==> Domain r = A ==> equiv A r"
    43     "r\<inverse> O r = r ==> Domain r = A ==> equiv A r"
    44   apply (unfold equiv_def refl_def sym_def trans_def)
    44   apply (unfold equiv_def refl_on_def sym_def trans_def)
    45   apply (erule equalityE)
    45   apply (erule equalityE)
    46   apply (subgoal_tac "\<forall>x y. (x, y) \<in> r --> (y, x) \<in> r")
    46   apply (subgoal_tac "\<forall>x y. (x, y) \<in> r --> (y, x) \<in> r")
    47    apply fast
    47    apply fast
    48   apply fast
    48   apply fast
    49   done
    49   done
    61   apply (unfold equiv_def sym_def)
    61   apply (unfold equiv_def sym_def)
    62   apply blast
    62   apply blast
    63   done
    63   done
    64 
    64 
    65 lemma equiv_class_self: "equiv A r ==> a \<in> A ==> a \<in> r``{a}"
    65 lemma equiv_class_self: "equiv A r ==> a \<in> A ==> a \<in> r``{a}"
    66   by (unfold equiv_def refl_def) blast
    66   by (unfold equiv_def refl_on_def) blast
    67 
    67 
    68 lemma subset_equiv_class:
    68 lemma subset_equiv_class:
    69     "equiv A r ==> r``{b} \<subseteq> r``{a} ==> b \<in> A ==> (a,b) \<in> r"
    69     "equiv A r ==> r``{b} \<subseteq> r``{a} ==> b \<in> A ==> (a,b) \<in> r"
    70   -- {* lemma for the next result *}
    70   -- {* lemma for the next result *}
    71   by (unfold equiv_def refl_def) blast
    71   by (unfold equiv_def refl_on_def) blast
    72 
    72 
    73 lemma eq_equiv_class:
    73 lemma eq_equiv_class:
    74     "r``{a} = r``{b} ==> equiv A r ==> b \<in> A ==> (a, b) \<in> r"
    74     "r``{a} = r``{b} ==> equiv A r ==> b \<in> A ==> (a, b) \<in> r"
    75   by (iprover intro: equalityD2 subset_equiv_class)
    75   by (iprover intro: equalityD2 subset_equiv_class)
    76 
    76 
    77 lemma equiv_class_nondisjoint:
    77 lemma equiv_class_nondisjoint:
    78     "equiv A r ==> x \<in> (r``{a} \<inter> r``{b}) ==> (a, b) \<in> r"
    78     "equiv A r ==> x \<in> (r``{a} \<inter> r``{b}) ==> (a, b) \<in> r"
    79   by (unfold equiv_def trans_def sym_def) blast
    79   by (unfold equiv_def trans_def sym_def) blast
    80 
    80 
    81 lemma equiv_type: "equiv A r ==> r \<subseteq> A \<times> A"
    81 lemma equiv_type: "equiv A r ==> r \<subseteq> A \<times> A"
    82   by (unfold equiv_def refl_def) blast
    82   by (unfold equiv_def refl_on_def) blast
    83 
    83 
    84 theorem equiv_class_eq_iff:
    84 theorem equiv_class_eq_iff:
    85   "equiv A r ==> ((x, y) \<in> r) = (r``{x} = r``{y} & x \<in> A & y \<in> A)"
    85   "equiv A r ==> ((x, y) \<in> r) = (r``{x} = r``{y} & x \<in> A & y \<in> A)"
    86   by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type)
    86   by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type)
    87 
    87 
   101 lemma quotientE:
   101 lemma quotientE:
   102   "X \<in> A//r ==> (!!x. X = r``{x} ==> x \<in> A ==> P) ==> P"
   102   "X \<in> A//r ==> (!!x. X = r``{x} ==> x \<in> A ==> P) ==> P"
   103   by (unfold quotient_def) blast
   103   by (unfold quotient_def) blast
   104 
   104 
   105 lemma Union_quotient: "equiv A r ==> Union (A//r) = A"
   105 lemma Union_quotient: "equiv A r ==> Union (A//r) = A"
   106   by (unfold equiv_def refl_def quotient_def) blast
   106   by (unfold equiv_def refl_on_def quotient_def) blast
   107 
   107 
   108 lemma quotient_disj:
   108 lemma quotient_disj:
   109   "equiv A r ==> X \<in> A//r ==> Y \<in> A//r ==> X = Y | (X \<inter> Y = {})"
   109   "equiv A r ==> X \<in> A//r ==> Y \<in> A//r ==> X = Y | (X \<inter> Y = {})"
   110   apply (unfold quotient_def)
   110   apply (unfold quotient_def)
   111   apply clarify
   111   apply clarify
   226   "f respects2 r == congruent2 r r f"
   226   "f respects2 r == congruent2 r r f"
   227 
   227 
   228 
   228 
   229 lemma congruent2_implies_congruent:
   229 lemma congruent2_implies_congruent:
   230     "equiv A r1 ==> congruent2 r1 r2 f ==> a \<in> A ==> congruent r2 (f a)"
   230     "equiv A r1 ==> congruent2 r1 r2 f ==> a \<in> A ==> congruent r2 (f a)"
   231   by (unfold congruent_def congruent2_def equiv_def refl_def) blast
   231   by (unfold congruent_def congruent2_def equiv_def refl_on_def) blast
   232 
   232 
   233 lemma congruent2_implies_congruent_UN:
   233 lemma congruent2_implies_congruent_UN:
   234   "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a \<in> A2 ==>
   234   "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a \<in> A2 ==>
   235     congruent r1 (\<lambda>x1. \<Union>x2 \<in> r2``{a}. f x1 x2)"
   235     congruent r1 (\<lambda>x1. \<Union>x2 \<in> r2``{a}. f x1 x2)"
   236   apply (unfold congruent_def)
   236   apply (unfold congruent_def)
   237   apply clarify
   237   apply clarify
   238   apply (rule equiv_type [THEN subsetD, THEN SigmaE2], assumption+)
   238   apply (rule equiv_type [THEN subsetD, THEN SigmaE2], assumption+)
   239   apply (simp add: UN_equiv_class congruent2_implies_congruent)
   239   apply (simp add: UN_equiv_class congruent2_implies_congruent)
   240   apply (unfold congruent2_def equiv_def refl_def)
   240   apply (unfold congruent2_def equiv_def refl_on_def)
   241   apply (blast del: equalityI)
   241   apply (blast del: equalityI)
   242   done
   242   done
   243 
   243 
   244 lemma UN_equiv_class2:
   244 lemma UN_equiv_class2:
   245   "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a1 \<in> A1 ==> a2 \<in> A2
   245   "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a1 \<in> A1 ==> a2 \<in> A2
   270     ==> (!!y z w. w \<in> A2 ==> (y,z) \<in> r1 ==> f y w = f z w)
   270     ==> (!!y z w. w \<in> A2 ==> (y,z) \<in> r1 ==> f y w = f z w)
   271     ==> (!!y z w. w \<in> A1 ==> (y,z) \<in> r2 ==> f w y = f w z)
   271     ==> (!!y z w. w \<in> A1 ==> (y,z) \<in> r2 ==> f w y = f w z)
   272     ==> congruent2 r1 r2 f"
   272     ==> congruent2 r1 r2 f"
   273   -- {* Suggested by John Harrison -- the two subproofs may be *}
   273   -- {* Suggested by John Harrison -- the two subproofs may be *}
   274   -- {* \emph{much} simpler than the direct proof. *}
   274   -- {* \emph{much} simpler than the direct proof. *}
   275   apply (unfold congruent2_def equiv_def refl_def)
   275   apply (unfold congruent2_def equiv_def refl_on_def)
   276   apply clarify
   276   apply clarify
   277   apply (blast intro: trans)
   277   apply (blast intro: trans)
   278   done
   278   done
   279 
   279 
   280 lemma congruent2_commuteI:
   280 lemma congruent2_commuteI: