misc tuning and modernization;
authorwenzelm
Wed, 10 Aug 2016 22:05:00 +0200
changeset 63653 4453cfb745e5
parent 63652 804b80a80016
child 63654 f90e3926e627
misc tuning and modernization;
src/HOL/Equiv_Relations.thy
--- a/src/HOL/Equiv_Relations.thy	Wed Aug 10 22:03:58 2016 +0200
+++ b/src/HOL/Equiv_Relations.thy	Wed Aug 10 22:05:00 2016 +0200
@@ -1,20 +1,19 @@
-(*  Authors:    Lawrence C Paulson, Cambridge University Computer Laboratory
-    Copyright   1996  University of Cambridge
+(*  Title:      HOL/Equiv_Relations.thy
+    Author:     Lawrence C Paulson, 1996 Cambridge University Computer Laboratory
 *)
 
 section \<open>Equivalence Relations in Higher-Order Set Theory\<close>
 
 theory Equiv_Relations
-imports Groups_Big Relation
+  imports Groups_Big Relation
 begin
 
 subsection \<open>Equivalence relations -- set version\<close>
 
-definition equiv :: "'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> bool" where
-  "equiv A r \<longleftrightarrow> refl_on A r \<and> sym r \<and> trans r"
+definition equiv :: "'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> bool"
+  where "equiv A r \<longleftrightarrow> refl_on A r \<and> sym r \<and> trans r"
 
-lemma equivI:
-  "refl_on A r \<Longrightarrow> sym r \<Longrightarrow> trans r \<Longrightarrow> equiv A r"
+lemma equivI: "refl_on A r \<Longrightarrow> sym r \<Longrightarrow> trans r \<Longrightarrow> equiv A r"
   by (simp add: equiv_def)
 
 lemma equivE:
@@ -23,20 +22,18 @@
   using assms by (simp add: equiv_def)
 
 text \<open>
-  Suppes, Theorem 70: \<open>r\<close> is an equiv relation iff \<open>r\<inverse> O
-  r = r\<close>.
+  Suppes, Theorem 70: \<open>r\<close> is an equiv relation iff \<open>r\<inverse> O r = r\<close>.
 
-  First half: \<open>equiv A r ==> r\<inverse> O r = r\<close>.
+  First half: \<open>equiv A r \<Longrightarrow> r\<inverse> O r = r\<close>.
 \<close>
 
-lemma sym_trans_comp_subset:
-    "sym r ==> trans r ==> r\<inverse> O r \<subseteq> r"
-  by (unfold trans_def sym_def converse_unfold) blast
+lemma sym_trans_comp_subset: "sym r \<Longrightarrow> trans r \<Longrightarrow> r\<inverse> O r \<subseteq> r"
+  unfolding trans_def sym_def converse_unfold by blast
 
-lemma refl_on_comp_subset: "refl_on A r ==> r \<subseteq> r\<inverse> O r"
-  by (unfold refl_on_def) blast
+lemma refl_on_comp_subset: "refl_on A r \<Longrightarrow> r \<subseteq> r\<inverse> O r"
+  unfolding refl_on_def by blast
 
-lemma equiv_comp_eq: "equiv A r ==> r\<inverse> O r = r"
+lemma equiv_comp_eq: "equiv A r \<Longrightarrow> r\<inverse> O r = r"
   apply (unfold equiv_def)
   apply clarify
   apply (rule equalityI)
@@ -45,11 +42,10 @@
 
 text \<open>Second half.\<close>
 
-lemma comp_equivI:
-    "r\<inverse> O r = r ==> Domain r = A ==> equiv A r"
+lemma comp_equivI: "r\<inverse> O r = r \<Longrightarrow> Domain r = A \<Longrightarrow> equiv A r"
   apply (unfold equiv_def refl_on_def sym_def trans_def)
   apply (erule equalityE)
-  apply (subgoal_tac "\<forall>x y. (x, y) \<in> r --> (y, x) \<in> r")
+  apply (subgoal_tac "\<forall>x y. (x, y) \<in> r \<longrightarrow> (y, x) \<in> r")
    apply fast
   apply fast
   done
@@ -57,62 +53,54 @@
 
 subsection \<open>Equivalence classes\<close>
 
-lemma equiv_class_subset:
-  "equiv A r ==> (a, b) \<in> r ==> r``{a} \<subseteq> r``{b}"
+lemma equiv_class_subset: "equiv A r \<Longrightarrow> (a, b) \<in> r \<Longrightarrow> r``{a} \<subseteq> r``{b}"
   \<comment> \<open>lemma for the next result\<close>
-  by (unfold equiv_def trans_def sym_def) blast
+  unfolding equiv_def trans_def sym_def by blast
 
-theorem equiv_class_eq: "equiv A r ==> (a, b) \<in> r ==> r``{a} = r``{b}"
+theorem equiv_class_eq: "equiv A r \<Longrightarrow> (a, b) \<in> r \<Longrightarrow> r``{a} = r``{b}"
   apply (assumption | rule equalityI equiv_class_subset)+
   apply (unfold equiv_def sym_def)
   apply blast
   done
 
-lemma equiv_class_self: "equiv A r ==> a \<in> A ==> a \<in> r``{a}"
-  by (unfold equiv_def refl_on_def) blast
+lemma equiv_class_self: "equiv A r \<Longrightarrow> a \<in> A \<Longrightarrow> a \<in> r``{a}"
+  unfolding equiv_def refl_on_def by blast
 
-lemma subset_equiv_class:
-    "equiv A r ==> r``{b} \<subseteq> r``{a} ==> b \<in> A ==> (a,b) \<in> r"
+lemma subset_equiv_class: "equiv A r \<Longrightarrow> r``{b} \<subseteq> r``{a} \<Longrightarrow> b \<in> A \<Longrightarrow> (a, b) \<in> r"
   \<comment> \<open>lemma for the next result\<close>
-  by (unfold equiv_def refl_on_def) blast
+  unfolding equiv_def refl_on_def by blast
 
-lemma eq_equiv_class:
-    "r``{a} = r``{b} ==> equiv A r ==> b \<in> A ==> (a, b) \<in> r"
+lemma eq_equiv_class: "r``{a} = r``{b} \<Longrightarrow> equiv A r \<Longrightarrow> b \<in> A \<Longrightarrow> (a, b) \<in> r"
   by (iprover intro: equalityD2 subset_equiv_class)
 
-lemma equiv_class_nondisjoint:
-    "equiv A r ==> x \<in> (r``{a} \<inter> r``{b}) ==> (a, b) \<in> r"
-  by (unfold equiv_def trans_def sym_def) blast
+lemma equiv_class_nondisjoint: "equiv A r \<Longrightarrow> x \<in> (r``{a} \<inter> r``{b}) \<Longrightarrow> (a, b) \<in> r"
+  unfolding equiv_def trans_def sym_def by blast
 
-lemma equiv_type: "equiv A r ==> r \<subseteq> A \<times> A"
-  by (unfold equiv_def refl_on_def) blast
+lemma equiv_type: "equiv A r \<Longrightarrow> r \<subseteq> A \<times> A"
+  unfolding equiv_def refl_on_def by blast
 
-theorem equiv_class_eq_iff:
-  "equiv A r ==> ((x, y) \<in> r) = (r``{x} = r``{y} & x \<in> A & y \<in> A)"
+lemma equiv_class_eq_iff: "equiv A r \<Longrightarrow> (x, y) \<in> r \<longleftrightarrow> r``{x} = r``{y} \<and> x \<in> A \<and> y \<in> A"
   by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type)
 
-theorem eq_equiv_class_iff:
-  "equiv A r ==> x \<in> A ==> y \<in> A ==> (r``{x} = r``{y}) = ((x, y) \<in> r)"
+lemma eq_equiv_class_iff: "equiv A r \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> r``{x} = r``{y} \<longleftrightarrow> (x, y) \<in> r"
   by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type)
 
 
 subsection \<open>Quotients\<close>
 
-definition quotient :: "'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> 'a set set"  (infixl "'/'/" 90) where
-  "A//r = (\<Union>x \<in> A. {r``{x}})"  \<comment> \<open>set of equiv classes\<close>
+definition quotient :: "'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> 'a set set"  (infixl "'/'/" 90)
+  where "A//r = (\<Union>x \<in> A. {r``{x}})"  \<comment> \<open>set of equiv classes\<close>
 
 lemma quotientI: "x \<in> A ==> r``{x} \<in> A//r"
-  by (unfold quotient_def) blast
+  unfolding quotient_def by blast
 
-lemma quotientE:
-  "X \<in> A//r ==> (!!x. X = r``{x} ==> x \<in> A ==> P) ==> P"
-  by (unfold quotient_def) blast
+lemma quotientE: "X \<in> A//r \<Longrightarrow> (\<And>x. X = r``{x} \<Longrightarrow> x \<in> A \<Longrightarrow> P) \<Longrightarrow> P"
+  unfolding quotient_def by blast
 
-lemma Union_quotient: "equiv A r ==> \<Union>(A//r) = A"
-  by (unfold equiv_def refl_on_def quotient_def) blast
+lemma Union_quotient: "equiv A r \<Longrightarrow> \<Union>(A//r) = A"
+  unfolding equiv_def refl_on_def quotient_def by blast
 
-lemma quotient_disj:
-  "equiv A r ==> X \<in> A//r ==> Y \<in> A//r ==> X = Y | (X \<inter> Y = {})"
+lemma quotient_disj: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> Y \<in> A//r \<Longrightarrow> X = Y \<or> X \<inter> Y = {}"
   apply (unfold quotient_def)
   apply clarify
   apply (rule equiv_class_eq)
@@ -122,108 +110,96 @@
   done
 
 lemma quotient_eqI:
-  "[|equiv A r; X \<in> A//r; Y \<in> A//r; x \<in> X; y \<in> Y; (x,y) \<in> r|] ==> X = Y" 
+  "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> Y \<in> A//r \<Longrightarrow> x \<in> X \<Longrightarrow> y \<in> Y \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> X = Y"
   apply (clarify elim!: quotientE)
-  apply (rule equiv_class_eq, assumption)
-  apply (unfold equiv_def sym_def trans_def, blast)
+  apply (rule equiv_class_eq)
+   apply assumption
+  apply (unfold equiv_def sym_def trans_def)
+  apply blast
   done
 
 lemma quotient_eq_iff:
-  "[|equiv A r; X \<in> A//r; Y \<in> A//r; x \<in> X; y \<in> Y|] ==> (X = Y) = ((x,y) \<in> r)" 
-  apply (rule iffI)  
-   prefer 2 apply (blast del: equalityI intro: quotient_eqI) 
+  "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> Y \<in> A//r \<Longrightarrow> x \<in> X \<Longrightarrow> y \<in> Y \<Longrightarrow> X = Y \<longleftrightarrow> (x, y) \<in> r"
+  apply (rule iffI)
+   prefer 2
+   apply (blast del: equalityI intro: quotient_eqI)
   apply (clarify elim!: quotientE)
-  apply (unfold equiv_def sym_def trans_def, blast)
+  apply (unfold equiv_def sym_def trans_def)
+  apply blast
   done
 
-lemma eq_equiv_class_iff2:
-  "\<lbrakk> equiv A r; x \<in> A; y \<in> A \<rbrakk> \<Longrightarrow> ({x}//r = {y}//r) = ((x,y) : r)"
-by(simp add:quotient_def eq_equiv_class_iff)
-
+lemma eq_equiv_class_iff2: "equiv A r \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> {x}//r = {y}//r \<longleftrightarrow> (x, y) \<in> r"
+  by (simp add: quotient_def eq_equiv_class_iff)
 
 lemma quotient_empty [simp]: "{}//r = {}"
-by(simp add: quotient_def)
+  by (simp add: quotient_def)
 
-lemma quotient_is_empty [iff]: "(A//r = {}) = (A = {})"
-by(simp add: quotient_def)
+lemma quotient_is_empty [iff]: "A//r = {} \<longleftrightarrow> A = {}"
+  by (simp add: quotient_def)
 
-lemma quotient_is_empty2 [iff]: "({} = A//r) = (A = {})"
-by(simp add: quotient_def)
-
+lemma quotient_is_empty2 [iff]: "{} = A//r \<longleftrightarrow> A = {}"
+  by (simp add: quotient_def)
 
 lemma singleton_quotient: "{x}//r = {r `` {x}}"
-by(simp add:quotient_def)
+  by (simp add: quotient_def)
 
-lemma quotient_diff1:
-  "\<lbrakk> inj_on (%a. {a}//r) A; a \<in> A \<rbrakk> \<Longrightarrow> (A - {a})//r = A//r - {a}//r"
-apply(simp add:quotient_def inj_on_def)
-apply blast
-done
+lemma quotient_diff1: "inj_on (\<lambda>a. {a}//r) A \<Longrightarrow> a \<in> A \<Longrightarrow> (A - {a})//r = A//r - {a}//r"
+  unfolding quotient_def inj_on_def by blast
+
 
 subsection \<open>Refinement of one equivalence relation WRT another\<close>
 
-lemma refines_equiv_class_eq:
-   "\<lbrakk>R \<subseteq> S; equiv A R; equiv A S\<rbrakk> \<Longrightarrow> R``(S``{a}) = S``{a}"
+lemma refines_equiv_class_eq: "R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> R``(S``{a}) = S``{a}"
   by (auto simp: equiv_class_eq_iff)
 
-lemma refines_equiv_class_eq2:
-   "\<lbrakk>R \<subseteq> S; equiv A R; equiv A S\<rbrakk> \<Longrightarrow> S``(R``{a}) = S``{a}"
+lemma refines_equiv_class_eq2: "R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> S``(R``{a}) = S``{a}"
   by (auto simp: equiv_class_eq_iff)
 
-lemma refines_equiv_image_eq:
-   "\<lbrakk>R \<subseteq> S; equiv A R; equiv A S\<rbrakk> \<Longrightarrow> (\<lambda>X. S``X) ` (A//R) = A//S"
+lemma refines_equiv_image_eq: "R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> (\<lambda>X. S``X) ` (A//R) = A//S"
    by (auto simp: quotient_def image_UN refines_equiv_class_eq2)
 
 lemma finite_refines_finite:
-   "\<lbrakk>finite (A//R); R \<subseteq> S; equiv A R; equiv A S\<rbrakk> \<Longrightarrow> finite (A//S)"
-    apply (erule finite_surj [where f = "\<lambda>X. S``X"])
-    apply (simp add: refines_equiv_image_eq)
-    done
+  "finite (A//R) \<Longrightarrow> R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> finite (A//S)"
+  by (erule finite_surj [where f = "\<lambda>X. S``X"]) (simp add: refines_equiv_image_eq)
 
 lemma finite_refines_card_le:
-   "\<lbrakk>finite (A//R); R \<subseteq> S; equiv A R; equiv A S\<rbrakk> \<Longrightarrow> card (A//S) \<le> card (A//R)"
-  apply (subst refines_equiv_image_eq [of R S A, symmetric])
-  apply (auto simp: card_image_le [where f = "\<lambda>X. S``X"])
-  done
+  "finite (A//R) \<Longrightarrow> R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> card (A//S) \<le> card (A//R)"
+  by (subst refines_equiv_image_eq [of R S A, symmetric])
+    (auto simp: card_image_le [where f = "\<lambda>X. S``X"])
 
 
 subsection \<open>Defining unary operations upon equivalence classes\<close>
 
-text\<open>A congruence-preserving function\<close>
+text \<open>A congruence-preserving function.\<close>
 
-definition congruent :: "('a \<times> 'a) set \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"  where
-  "congruent r f \<longleftrightarrow> (\<forall>(y, z) \<in> r. f y = f z)"
+definition congruent :: "('a \<times> 'a) set \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
+  where "congruent r f \<longleftrightarrow> (\<forall>(y, z) \<in> r. f y = f z)"
 
-lemma congruentI:
-  "(\<And>y z. (y, z) \<in> r \<Longrightarrow> f y = f z) \<Longrightarrow> congruent r f"
+lemma congruentI: "(\<And>y z. (y, z) \<in> r \<Longrightarrow> f y = f z) \<Longrightarrow> congruent r f"
   by (auto simp add: congruent_def)
 
-lemma congruentD:
-  "congruent r f \<Longrightarrow> (y, z) \<in> r \<Longrightarrow> f y = f z"
+lemma congruentD: "congruent r f \<Longrightarrow> (y, z) \<in> r \<Longrightarrow> f y = f z"
   by (auto simp add: congruent_def)
 
-abbreviation
-  RESPECTS :: "('a => 'b) => ('a * 'a) set => bool"
-    (infixr "respects" 80) where
-  "f respects r == congruent r f"
+abbreviation RESPECTS :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> bool"  (infixr "respects" 80)
+  where "f respects r \<equiv> congruent r f"
 
 
-lemma UN_constant_eq: "a \<in> A ==> \<forall>y \<in> A. f y = c ==> (\<Union>y \<in> A. f(y))=c"
+lemma UN_constant_eq: "a \<in> A \<Longrightarrow> \<forall>y \<in> A. f y = c \<Longrightarrow> (\<Union>y \<in> A. f y) = c"
   \<comment> \<open>lemma required to prove \<open>UN_equiv_class\<close>\<close>
   by auto
 
-lemma UN_equiv_class:
-  "equiv A r ==> f respects r ==> a \<in> A
-    ==> (\<Union>x \<in> r``{a}. f x) = f a"
+lemma UN_equiv_class: "equiv A r \<Longrightarrow> f respects r \<Longrightarrow> a \<in> A \<Longrightarrow> (\<Union>x \<in> r``{a}. f x) = f a"
   \<comment> \<open>Conversion rule\<close>
-  apply (rule equiv_class_self [THEN UN_constant_eq], assumption+)
+  apply (rule equiv_class_self [THEN UN_constant_eq])
+    apply assumption
+   apply assumption
   apply (unfold equiv_def congruent_def sym_def)
   apply (blast del: equalityI)
   done
 
 lemma UN_equiv_class_type:
-  "equiv A r ==> f respects r ==> X \<in> A//r ==>
-    (!!x. x \<in> A ==> f x \<in> B) ==> (\<Union>x \<in> X. f x) \<in> B"
+  "equiv A r \<Longrightarrow> f respects r \<Longrightarrow> X \<in> A//r \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> f x \<in> B) \<Longrightarrow> (\<Union>x \<in> X. f x) \<in> B"
   apply (unfold quotient_def)
   apply clarify
   apply (subst UN_equiv_class)
@@ -232,15 +208,15 @@
 
 text \<open>
   Sufficient conditions for injectiveness.  Could weaken premises!
-  major premise could be an inclusion; bcong could be \<open>!!y. y \<in>
-  A ==> f y \<in> B\<close>.
+  major premise could be an inclusion; \<open>bcong\<close> could be
+  \<open>\<And>y. y \<in> A \<Longrightarrow> f y \<in> B\<close>.
 \<close>
 
 lemma UN_equiv_class_inject:
-  "equiv A r ==> f respects r ==>
-    (\<Union>x \<in> X. f x) = (\<Union>y \<in> Y. f y) ==> X \<in> A//r ==> Y \<in> A//r
-    ==> (!!x y. x \<in> A ==> y \<in> A ==> f x = f y ==> (x, y) \<in> r)
-    ==> X = Y"
+  "equiv A r \<Longrightarrow> f respects r \<Longrightarrow>
+    (\<Union>x \<in> X. f x) = (\<Union>y \<in> Y. f y) \<Longrightarrow> X \<in> A//r ==> Y \<in> A//r
+    \<Longrightarrow> (\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x = f y \<Longrightarrow> (x, y) \<in> r)
+    \<Longrightarrow> X = Y"
   apply (unfold quotient_def)
   apply clarify
   apply (rule equiv_class_eq)
@@ -254,33 +230,30 @@
 
 subsection \<open>Defining binary operations upon equivalence classes\<close>
 
-text\<open>A congruence-preserving function of two arguments\<close>
+text \<open>A congruence-preserving function of two arguments.\<close>
 
-definition congruent2 :: "('a \<times> 'a) set \<Rightarrow> ('b \<times> 'b) set \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> bool" where
-  "congruent2 r1 r2 f \<longleftrightarrow> (\<forall>(y1, z1) \<in> r1. \<forall>(y2, z2) \<in> r2. f y1 y2 = f z1 z2)"
+definition congruent2 :: "('a \<times> 'a) set \<Rightarrow> ('b \<times> 'b) set \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> bool"
+  where "congruent2 r1 r2 f \<longleftrightarrow> (\<forall>(y1, z1) \<in> r1. \<forall>(y2, z2) \<in> r2. f y1 y2 = f z1 z2)"
 
 lemma congruent2I':
   assumes "\<And>y1 z1 y2 z2. (y1, z1) \<in> r1 \<Longrightarrow> (y2, z2) \<in> r2 \<Longrightarrow> f y1 y2 = f z1 z2"
   shows "congruent2 r1 r2 f"
   using assms by (auto simp add: congruent2_def)
 
-lemma congruent2D:
-  "congruent2 r1 r2 f \<Longrightarrow> (y1, z1) \<in> r1 \<Longrightarrow> (y2, z2) \<in> r2 \<Longrightarrow> f y1 y2 = f z1 z2"
+lemma congruent2D: "congruent2 r1 r2 f \<Longrightarrow> (y1, z1) \<in> r1 \<Longrightarrow> (y2, z2) \<in> r2 \<Longrightarrow> f y1 y2 = f z1 z2"
   by (auto simp add: congruent2_def)
 
-text\<open>Abbreviation for the common case where the relations are identical\<close>
-abbreviation
-  RESPECTS2:: "['a => 'a => 'b, ('a * 'a) set] => bool"
-    (infixr "respects2" 80) where
-  "f respects2 r == congruent2 r r f"
+text \<open>Abbreviation for the common case where the relations are identical.\<close>
+abbreviation RESPECTS2:: "('a \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> bool"  (infixr "respects2" 80)
+  where "f respects2 r \<equiv> congruent2 r r f"
 
 
 lemma congruent2_implies_congruent:
-    "equiv A r1 ==> congruent2 r1 r2 f ==> a \<in> A ==> congruent r2 (f a)"
-  by (unfold congruent_def congruent2_def equiv_def refl_on_def) blast
+  "equiv A r1 \<Longrightarrow> congruent2 r1 r2 f \<Longrightarrow> a \<in> A \<Longrightarrow> congruent r2 (f a)"
+  unfolding congruent_def congruent2_def equiv_def refl_on_def by blast
 
 lemma congruent2_implies_congruent_UN:
-  "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a \<in> A2 ==>
+  "equiv A1 r1 \<Longrightarrow> equiv A2 r2 \<Longrightarrow> congruent2 r1 r2 f \<Longrightarrow> a \<in> A2 \<Longrightarrow>
     congruent r1 (\<lambda>x1. \<Union>x2 \<in> r2``{a}. f x1 x2)"
   apply (unfold congruent_def)
   apply clarify
@@ -291,20 +264,19 @@
   done
 
 lemma UN_equiv_class2:
-  "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a1 \<in> A1 ==> a2 \<in> A2
-    ==> (\<Union>x1 \<in> r1``{a1}. \<Union>x2 \<in> r2``{a2}. f x1 x2) = f a1 a2"
-  by (simp add: UN_equiv_class congruent2_implies_congruent
-    congruent2_implies_congruent_UN)
+  "equiv A1 r1 \<Longrightarrow> equiv A2 r2 \<Longrightarrow> congruent2 r1 r2 f \<Longrightarrow> a1 \<in> A1 \<Longrightarrow> a2 \<in> A2 \<Longrightarrow>
+    (\<Union>x1 \<in> r1``{a1}. \<Union>x2 \<in> r2``{a2}. f x1 x2) = f a1 a2"
+  by (simp add: UN_equiv_class congruent2_implies_congruent congruent2_implies_congruent_UN)
 
 lemma UN_equiv_class_type2:
-  "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f
-    ==> X1 \<in> A1//r1 ==> X2 \<in> A2//r2
-    ==> (!!x1 x2. x1 \<in> A1 ==> x2 \<in> A2 ==> f x1 x2 \<in> B)
-    ==> (\<Union>x1 \<in> X1. \<Union>x2 \<in> X2. f x1 x2) \<in> B"
+  "equiv A1 r1 \<Longrightarrow> equiv A2 r2 \<Longrightarrow> congruent2 r1 r2 f
+    \<Longrightarrow> X1 \<in> A1//r1 \<Longrightarrow> X2 \<in> A2//r2
+    \<Longrightarrow> (\<And>x1 x2. x1 \<in> A1 \<Longrightarrow> x2 \<in> A2 \<Longrightarrow> f x1 x2 \<in> B)
+    \<Longrightarrow> (\<Union>x1 \<in> X1. \<Union>x2 \<in> X2. f x1 x2) \<in> B"
   apply (unfold quotient_def)
   apply clarify
   apply (blast intro: UN_equiv_class_type congruent2_implies_congruent_UN
-    congruent2_implies_congruent quotientI)
+      congruent2_implies_congruent quotientI)
   done
 
 lemma UN_UN_split_split_eq:
@@ -315,12 +287,12 @@
   by auto
 
 lemma congruent2I:
-  "equiv A1 r1 ==> equiv A2 r2
-    ==> (!!y z w. w \<in> A2 ==> (y,z) \<in> r1 ==> f y w = f z w)
-    ==> (!!y z w. w \<in> A1 ==> (y,z) \<in> r2 ==> f w y = f w z)
-    ==> congruent2 r1 r2 f"
+  "equiv A1 r1 \<Longrightarrow> equiv A2 r2
+    \<Longrightarrow> (\<And>y z w. w \<in> A2 \<Longrightarrow> (y,z) \<in> r1 \<Longrightarrow> f y w = f z w)
+    \<Longrightarrow> (\<And>y z w. w \<in> A1 \<Longrightarrow> (y,z) \<in> r2 \<Longrightarrow> f w y = f w z)
+    \<Longrightarrow> congruent2 r1 r2 f"
   \<comment> \<open>Suggested by John Harrison -- the two subproofs may be\<close>
-  \<comment> \<open>\emph{much} simpler than the direct proof.\<close>
+  \<comment> \<open>\<^emph>\<open>much\<close> simpler than the direct proof.\<close>
   apply (unfold congruent2_def equiv_def refl_on_def)
   apply clarify
   apply (blast intro: trans)
@@ -328,8 +300,8 @@
 
 lemma congruent2_commuteI:
   assumes equivA: "equiv A r"
-    and commute: "!!y z. y \<in> A ==> z \<in> A ==> f y z = f z y"
-    and congt: "!!y z w. w \<in> A ==> (y,z) \<in> r ==> f w y = f w z"
+    and commute: "\<And>y z. y \<in> A \<Longrightarrow> z \<in> A \<Longrightarrow> f y z = f z y"
+    and congt: "\<And>y z w. w \<in> A \<Longrightarrow> (y,z) \<in> r \<Longrightarrow> f w y = f w z"
   shows "f respects2 r"
   apply (rule congruent2I [OF equivA equivA])
    apply (rule commute [THEN trans])
@@ -344,7 +316,7 @@
 
 text \<open>Suggested by Florian Kammüller\<close>
 
-lemma finite_quotient: "finite A ==> r \<subseteq> A \<times> A ==> finite (A//r)"
+lemma finite_quotient: "finite A \<Longrightarrow> r \<subseteq> A \<times> A \<Longrightarrow> finite (A//r)"
   \<comment> \<open>recall @{thm equiv_type}\<close>
   apply (rule finite_subset)
    apply (erule_tac [2] finite_Pow_iff [THEN iffD2])
@@ -352,93 +324,94 @@
   apply blast
   done
 
-lemma finite_equiv_class:
-  "finite A ==> r \<subseteq> A \<times> A ==> X \<in> A//r ==> finite X"
+lemma finite_equiv_class: "finite A \<Longrightarrow> r \<subseteq> A \<times> A \<Longrightarrow> X \<in> A//r \<Longrightarrow> finite X"
   apply (unfold quotient_def)
   apply (rule finite_subset)
    prefer 2 apply assumption
   apply blast
   done
 
-lemma equiv_imp_dvd_card:
-  "finite A ==> equiv A r ==> \<forall>X \<in> A//r. k dvd card X
-    ==> k dvd card A"
+lemma equiv_imp_dvd_card: "finite A \<Longrightarrow> equiv A r \<Longrightarrow> \<forall>X \<in> A//r. k dvd card X \<Longrightarrow> k dvd card A"
   apply (rule Union_quotient [THEN subst [where P="\<lambda>A. k dvd card A"]])
    apply assumption
   apply (rule dvd_partition)
-     prefer 3 apply (blast dest: quotient_disj)
-    apply (simp_all add: Union_quotient equiv_type)
+    prefer 3 apply (blast dest: quotient_disj)
+   apply (simp_all add: Union_quotient equiv_type)
   done
 
-lemma card_quotient_disjoint:
- "\<lbrakk> finite A; inj_on (\<lambda>x. {x} // r) A \<rbrakk> \<Longrightarrow> card(A//r) = card A"
-apply(simp add:quotient_def)
-apply(subst card_UN_disjoint)
-   apply assumption
+lemma card_quotient_disjoint: "finite A \<Longrightarrow> inj_on (\<lambda>x. {x} // r) A \<Longrightarrow> card (A//r) = card A"
+  apply (simp add:quotient_def)
+  apply (subst card_UN_disjoint)
+     apply assumption
+    apply simp
+   apply (fastforce simp add:inj_on_def)
   apply simp
- apply(fastforce simp add:inj_on_def)
-apply simp
-done
+  done
 
 
 subsection \<open>Projection\<close>
 
-definition proj where "proj r x = r `` {x}"
+definition proj :: "('b \<times> 'a) set \<Rightarrow> 'b \<Rightarrow> 'a set"
+  where "proj r x = r `` {x}"
 
-lemma proj_preserves:
-"x \<in> A \<Longrightarrow> proj r x \<in> A//r"
-unfolding proj_def by (rule quotientI)
+lemma proj_preserves: "x \<in> A \<Longrightarrow> proj r x \<in> A//r"
+  unfolding proj_def by (rule quotientI)
 
 lemma proj_in_iff:
-assumes "equiv A r"
-shows "(proj r x \<in> A//r) = (x \<in> A)"
-apply(rule iffI, auto simp add: proj_preserves)
-unfolding proj_def quotient_def proof clarsimp
-  fix y assume y: "y \<in> A" and "r `` {x} = r `` {y}"
-  moreover have "y \<in> r `` {y}" using assms y unfolding equiv_def refl_on_def by blast
-  ultimately have "(x,y) \<in> r" by blast
-  thus "x \<in> A" using assms unfolding equiv_def refl_on_def by blast
+  assumes "equiv A r"
+  shows "proj r x \<in> A//r \<longleftrightarrow> x \<in> A"
+    (is "?lhs \<longleftrightarrow> ?rhs")
+proof
+  assume ?rhs
+  then show ?lhs by (simp add: proj_preserves)
+next
+  assume ?lhs
+  then show ?rhs
+    unfolding proj_def quotient_def
+  proof clarsimp
+    fix y
+    assume y: "y \<in> A" and "r `` {x} = r `` {y}"
+    moreover have "y \<in> r `` {y}"
+      using assms y unfolding equiv_def refl_on_def by blast
+    ultimately have "(x, y) \<in> r" by blast
+    then show "x \<in> A"
+      using assms unfolding equiv_def refl_on_def by blast
+  qed
 qed
 
-lemma proj_iff:
-"\<lbrakk>equiv A r; {x,y} \<subseteq> A\<rbrakk> \<Longrightarrow> (proj r x = proj r y) = ((x,y) \<in> r)"
-by (simp add: proj_def eq_equiv_class_iff)
+lemma proj_iff: "equiv A r \<Longrightarrow> {x, y} \<subseteq> A \<Longrightarrow> proj r x = proj r y \<longleftrightarrow> (x, y) \<in> r"
+  by (simp add: proj_def eq_equiv_class_iff)
 
 (*
 lemma in_proj: "\<lbrakk>equiv A r; x \<in> A\<rbrakk> \<Longrightarrow> x \<in> proj r x"
 unfolding proj_def equiv_def refl_on_def by blast
 *)
 
-lemma proj_image: "(proj r) ` A = A//r"
-unfolding proj_def[abs_def] quotient_def by blast
+lemma proj_image: "proj r ` A = A//r"
+  unfolding proj_def[abs_def] quotient_def by blast
 
-lemma in_quotient_imp_non_empty:
-"\<lbrakk>equiv A r; X \<in> A//r\<rbrakk> \<Longrightarrow> X \<noteq> {}"
-unfolding quotient_def using equiv_class_self by fast
+lemma in_quotient_imp_non_empty: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> X \<noteq> {}"
+  unfolding quotient_def using equiv_class_self by fast
 
-lemma in_quotient_imp_in_rel:
-"\<lbrakk>equiv A r; X \<in> A//r; {x,y} \<subseteq> X\<rbrakk> \<Longrightarrow> (x,y) \<in> r"
-using quotient_eq_iff[THEN iffD1] by fastforce
+lemma in_quotient_imp_in_rel: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> {x, y} \<subseteq> X \<Longrightarrow> (x, y) \<in> r"
+  using quotient_eq_iff[THEN iffD1] by fastforce
 
-lemma in_quotient_imp_closed:
-"\<lbrakk>equiv A r; X \<in> A//r; x \<in> X; (x,y) \<in> r\<rbrakk> \<Longrightarrow> y \<in> X"
-unfolding quotient_def equiv_def trans_def by blast
+lemma in_quotient_imp_closed: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> x \<in> X \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> y \<in> X"
+  unfolding quotient_def equiv_def trans_def by blast
 
-lemma in_quotient_imp_subset:
-"\<lbrakk>equiv A r; X \<in> A//r\<rbrakk> \<Longrightarrow> X \<subseteq> A"
-using in_quotient_imp_in_rel equiv_type by fastforce
+lemma in_quotient_imp_subset: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> X \<subseteq> A"
+  using in_quotient_imp_in_rel equiv_type by fastforce
 
 
 subsection \<open>Equivalence relations -- predicate version\<close>
 
-text \<open>Partial equivalences\<close>
+text \<open>Partial equivalences.\<close>
 
-definition part_equivp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
-  "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)"
+definition part_equivp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
+  where "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)"
     \<comment> \<open>John-Harrison-style characterization\<close>
 
-lemma part_equivpI:
-  "(\<exists>x. R x x) \<Longrightarrow> symp R \<Longrightarrow> transp R \<Longrightarrow> part_equivp R"
+lemma part_equivpI: "\<exists>x. R x x \<Longrightarrow> symp R \<Longrightarrow> transp R \<Longrightarrow> part_equivp R"
   by (auto simp add: part_equivp_def) (auto elim: sympE transpE)
 
 lemma part_equivpE:
@@ -447,7 +420,7 @@
 proof -
   from assms have 1: "\<exists>x. R x x"
     and 2: "\<And>x y. R x y \<longleftrightarrow> R x x \<and> R y y \<and> R x = R y"
-    by (unfold part_equivp_def) blast+
+    unfolding part_equivp_def by blast+
   from 1 obtain x where "R x x" ..
   moreover have "symp R"
   proof (rule sympI)
@@ -464,30 +437,25 @@
   ultimately show thesis by (rule that)
 qed
 
-lemma part_equivp_refl_symp_transp:
-  "part_equivp R \<longleftrightarrow> (\<exists>x. R x x) \<and> symp R \<and> transp R"
+lemma part_equivp_refl_symp_transp: "part_equivp R \<longleftrightarrow> (\<exists>x. R x x) \<and> symp R \<and> transp R"
   by (auto intro: part_equivpI elim: part_equivpE)
 
-lemma part_equivp_symp:
-  "part_equivp R \<Longrightarrow> R x y \<Longrightarrow> R y x"
+lemma part_equivp_symp: "part_equivp R \<Longrightarrow> R x y \<Longrightarrow> R y x"
   by (erule part_equivpE, erule sympE)
 
-lemma part_equivp_transp:
-  "part_equivp R \<Longrightarrow> R x y \<Longrightarrow> R y z \<Longrightarrow> R x z"
+lemma part_equivp_transp: "part_equivp R \<Longrightarrow> R x y \<Longrightarrow> R y z \<Longrightarrow> R x z"
   by (erule part_equivpE, erule transpE)
 
-lemma part_equivp_typedef:
-  "part_equivp R \<Longrightarrow> \<exists>d. d \<in> {c. \<exists>x. R x x \<and> c = Collect (R x)}"
+lemma part_equivp_typedef: "part_equivp R \<Longrightarrow> \<exists>d. d \<in> {c. \<exists>x. R x x \<and> c = Collect (R x)}"
   by (auto elim: part_equivpE)
 
 
-text \<open>Total equivalences\<close>
+text \<open>Total equivalences.\<close>
 
-definition equivp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
-  "equivp R \<longleftrightarrow> (\<forall>x y. R x y = (R x = R y))" \<comment> \<open>John-Harrison-style characterization\<close>
+definition equivp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
+  where "equivp R \<longleftrightarrow> (\<forall>x y. R x y = (R x = R y))" \<comment> \<open>John-Harrison-style characterization\<close>
 
-lemma equivpI:
-  "reflp R \<Longrightarrow> symp R \<Longrightarrow> transp R \<Longrightarrow> equivp R"
+lemma equivpI: "reflp R \<Longrightarrow> symp R \<Longrightarrow> transp R \<Longrightarrow> equivp R"
   by (auto elim: reflpE sympE transpE simp add: equivp_def)
 
 lemma equivpE:
@@ -495,32 +463,25 @@
   obtains "reflp R" and "symp R" and "transp R"
   using assms by (auto intro!: that reflpI sympI transpI simp add: equivp_def)
 
-lemma equivp_implies_part_equivp:
-  "equivp R \<Longrightarrow> part_equivp R"
+lemma equivp_implies_part_equivp: "equivp R \<Longrightarrow> part_equivp R"
   by (auto intro: part_equivpI elim: equivpE reflpE)
 
-lemma equivp_equiv:
-  "equiv UNIV A \<longleftrightarrow> equivp (\<lambda>x y. (x, y) \<in> A)"
+lemma equivp_equiv: "equiv UNIV A \<longleftrightarrow> equivp (\<lambda>x y. (x, y) \<in> A)"
   by (auto intro!: equivI equivpI [to_set] elim!: equivE equivpE [to_set])
 
-lemma equivp_reflp_symp_transp:
-  shows "equivp R \<longleftrightarrow> reflp R \<and> symp R \<and> transp R"
+lemma equivp_reflp_symp_transp: "equivp R \<longleftrightarrow> reflp R \<and> symp R \<and> transp R"
   by (auto intro: equivpI elim: equivpE)
 
-lemma identity_equivp:
-  "equivp (op =)"
+lemma identity_equivp: "equivp (op =)"
   by (auto intro: equivpI reflpI sympI transpI)
 
-lemma equivp_reflp:
-  "equivp R \<Longrightarrow> R x x"
+lemma equivp_reflp: "equivp R \<Longrightarrow> R x x"
   by (erule equivpE, erule reflpE)
 
-lemma equivp_symp:
-  "equivp R \<Longrightarrow> R x y \<Longrightarrow> R y x"
+lemma equivp_symp: "equivp R \<Longrightarrow> R x y \<Longrightarrow> R y x"
   by (erule equivpE, erule sympE)
 
-lemma equivp_transp:
-  "equivp R \<Longrightarrow> R x y \<Longrightarrow> R y z \<Longrightarrow> R x z"
+lemma equivp_transp: "equivp R \<Longrightarrow> R x y \<Longrightarrow> R y z \<Longrightarrow> R x z"
   by (erule equivpE, erule transpE)
 
 hide_const (open) proj