merged
authorwenzelm
Wed, 06 Jul 2016 22:52:10 +0200
changeset 63405 920217323147
parent 63401 28cc90b0e9c2 (current diff)
parent 63404 a95e7432d86c (diff)
child 63406 32866eff1843
merged
--- a/src/Doc/Implementation/Local_Theory.thy	Wed Jul 06 13:45:52 2016 +0200
+++ b/src/Doc/Implementation/Local_Theory.thy	Wed Jul 06 22:52:10 2016 +0200
@@ -91,7 +91,8 @@
 text %mlref \<open>
   \begin{mldecls}
   @{index_ML_type local_theory: Proof.context} \\
-  @{index_ML Named_Target.init: "string -> theory -> local_theory"} \\[1ex]
+  @{index_ML Named_Target.init: "(local_theory -> local_theory) option ->
+    string -> theory -> local_theory"} \\[1ex]
   @{index_ML Local_Theory.define: "(binding * mixfix) * (Attrib.binding * term) ->
     local_theory -> (term * (string * thm)) * local_theory"} \\
   @{index_ML Local_Theory.note: "Attrib.binding * thm list ->
--- a/src/HOL/Finite_Set.thy	Wed Jul 06 13:45:52 2016 +0200
+++ b/src/HOL/Finite_Set.thy	Wed Jul 06 22:52:10 2016 +0200
@@ -16,9 +16,9 @@
 begin
 
 inductive finite :: "'a set \<Rightarrow> bool"
-  where
-    emptyI [simp, intro!]: "finite {}"
-  | insertI [simp, intro!]: "finite A \<Longrightarrow> finite (insert a A)"
+where
+  emptyI [simp, intro!]: "finite {}"
+| insertI [simp, intro!]: "finite A \<Longrightarrow> finite (insert a A)"
 
 end
 
@@ -32,14 +32,16 @@
   assumes "P {}"
     and insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)"
   shows "P F"
-using \<open>finite F\<close>
+  using \<open>finite F\<close>
 proof induct
   show "P {}" by fact
-  fix x F assume F: "finite F" and P: "P F"
+next
+  fix x F
+  assume F: "finite F" and P: "P F"
   show "P (insert x F)"
   proof cases
     assume "x \<in> F"
-    hence "insert x F = F" by (rule insert_absorb)
+    then have "insert x F = F" by (rule insert_absorb)
     with P show ?thesis by (simp only:)
   next
     assume "x \<notin> F"
@@ -49,13 +51,15 @@
 
 lemma infinite_finite_induct [case_names infinite empty insert]:
   assumes infinite: "\<And>A. \<not> finite A \<Longrightarrow> P A"
-  assumes empty: "P {}"
-  assumes insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)"
+    and empty: "P {}"
+    and insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)"
   shows "P A"
 proof (cases "finite A")
-  case False with infinite show ?thesis .
+  case False
+  with infinite show ?thesis .
 next
-  case True then show ?thesis by (induct A) (fact empty insert)+
+  case True
+  then show ?thesis by (induct A) (fact empty insert)+
 qed
 
 
@@ -71,16 +75,18 @@
 
 text \<open>A finite choice principle. Does not need the SOME choice operator.\<close>
 
-lemma finite_set_choice:
-  "finite A \<Longrightarrow> \<forall>x\<in>A. \<exists>y. P x y \<Longrightarrow> \<exists>f. \<forall>x\<in>A. P x (f x)"
+lemma finite_set_choice: "finite A \<Longrightarrow> \<forall>x\<in>A. \<exists>y. P x y \<Longrightarrow> \<exists>f. \<forall>x\<in>A. P x (f x)"
 proof (induct rule: finite_induct)
-  case empty then show ?case by simp
+  case empty
+  then show ?case by simp
 next
   case (insert a A)
-  then obtain f b where f: "ALL x:A. P x (f x)" and ab: "P a b" by auto
-  show ?case (is "EX f. ?P f")
+  then obtain f b where f: "\<forall>x\<in>A. P x (f x)" and ab: "P a b"
+    by auto
+  show ?case (is "\<exists>f. ?P f")
   proof
-    show "?P(%x. if x = a then b else f x)" using f ab by auto
+    show "?P (\<lambda>x. if x = a then b else f x)"
+      using f ab by auto
   qed
 qed
 
@@ -88,100 +94,101 @@
 subsubsection \<open>Finite sets are the images of initial segments of natural numbers\<close>
 
 lemma finite_imp_nat_seg_image_inj_on:
-  assumes "finite A" 
+  assumes "finite A"
   shows "\<exists>(n::nat) f. A = f ` {i. i < n} \<and> inj_on f {i. i < n}"
-using assms
+  using assms
 proof induct
   case empty
   show ?case
   proof
-    show "\<exists>f. {} = f ` {i::nat. i < 0} \<and> inj_on f {i. i < 0}" by simp 
+    show "\<exists>f. {} = f ` {i::nat. i < 0} \<and> inj_on f {i. i < 0}"
+      by simp
   qed
 next
   case (insert a A)
   have notinA: "a \<notin> A" by fact
-  from insert.hyps obtain n f
-    where "A = f ` {i::nat. i < n}" "inj_on f {i. i < n}" by blast
-  hence "insert a A = f(n:=a) ` {i. i < Suc n}"
-        "inj_on (f(n:=a)) {i. i < Suc n}" using notinA
-    by (auto simp add: image_def Ball_def inj_on_def less_Suc_eq)
-  thus ?case by blast
+  from insert.hyps obtain n f where "A = f ` {i::nat. i < n}" "inj_on f {i. i < n}"
+    by blast
+  then have "insert a A = f(n:=a) ` {i. i < Suc n}" and "inj_on (f(n:=a)) {i. i < Suc n}"
+    using notinA by (auto simp add: image_def Ball_def inj_on_def less_Suc_eq)
+  then show ?case by blast
 qed
 
-lemma nat_seg_image_imp_finite:
-  "A = f ` {i::nat. i < n} \<Longrightarrow> finite A"
+lemma nat_seg_image_imp_finite: "A = f ` {i::nat. i < n} \<Longrightarrow> finite A"
 proof (induct n arbitrary: A)
-  case 0 thus ?case by simp
+  case 0
+  then show ?case by simp
 next
   case (Suc n)
   let ?B = "f ` {i. i < n}"
-  have finB: "finite ?B" by(rule Suc.hyps[OF refl])
+  have finB: "finite ?B" by (rule Suc.hyps[OF refl])
   show ?case
-  proof cases
-    assume "\<exists>k<n. f n = f k"
-    hence "A = ?B" using Suc.prems by(auto simp:less_Suc_eq)
-    thus ?thesis using finB by simp
+  proof (cases "\<exists>k<n. f n = f k")
+    case True
+    then have "A = ?B"
+      using Suc.prems by (auto simp:less_Suc_eq)
+    then show ?thesis
+      using finB by simp
   next
-    assume "\<not>(\<exists> k<n. f n = f k)"
-    hence "A = insert (f n) ?B" using Suc.prems by(auto simp:less_Suc_eq)
-    thus ?thesis using finB by simp
+    case False
+    then have "A = insert (f n) ?B"
+      using Suc.prems by (auto simp:less_Suc_eq)
+    then show ?thesis using finB by simp
   qed
 qed
 
-lemma finite_conv_nat_seg_image:
-  "finite A \<longleftrightarrow> (\<exists>(n::nat) f. A = f ` {i::nat. i < n})"
+lemma finite_conv_nat_seg_image: "finite A \<longleftrightarrow> (\<exists>(n::nat) f. A = f ` {i::nat. i < n})"
   by (blast intro: nat_seg_image_imp_finite dest: finite_imp_nat_seg_image_inj_on)
 
 lemma finite_imp_inj_to_nat_seg:
   assumes "finite A"
   shows "\<exists>f n::nat. f ` A = {i. i < n} \<and> inj_on f A"
 proof -
-  from finite_imp_nat_seg_image_inj_on[OF \<open>finite A\<close>]
+  from finite_imp_nat_seg_image_inj_on [OF \<open>finite A\<close>]
   obtain f and n::nat where bij: "bij_betw f {i. i<n} A"
-    by (auto simp:bij_betw_def)
+    by (auto simp: bij_betw_def)
   let ?f = "the_inv_into {i. i<n} f"
-  have "inj_on ?f A & ?f ` A = {i. i<n}"
+  have "inj_on ?f A \<and> ?f ` A = {i. i<n}"
     by (fold bij_betw_def) (rule bij_betw_the_inv_into[OF bij])
-  thus ?thesis by blast
+  then show ?thesis by blast
 qed
 
-lemma finite_Collect_less_nat [iff]:
-  "finite {n::nat. n < k}"
+lemma finite_Collect_less_nat [iff]: "finite {n::nat. n < k}"
   by (fastforce simp: finite_conv_nat_seg_image)
 
-lemma finite_Collect_le_nat [iff]:
-  "finite {n::nat. n \<le> k}"
+lemma finite_Collect_le_nat [iff]: "finite {n::nat. n \<le> k}"
   by (simp add: le_eq_less_or_eq Collect_disj_eq)
 
 
 subsubsection \<open>Finiteness and common set operations\<close>
 
-lemma rev_finite_subset:
-  "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> finite A"
+lemma rev_finite_subset: "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> finite A"
 proof (induct arbitrary: A rule: finite_induct)
   case empty
   then show ?case by simp
 next
   case (insert x F A)
-  have A: "A \<subseteq> insert x F" and r: "A - {x} \<subseteq> F \<Longrightarrow> finite (A - {x})" by fact+
+  have A: "A \<subseteq> insert x F" and r: "A - {x} \<subseteq> F \<Longrightarrow> finite (A - {x})"
+    by fact+
   show "finite A"
   proof cases
     assume x: "x \<in> A"
     with A have "A - {x} \<subseteq> F" by (simp add: subset_insert_iff)
     with r have "finite (A - {x})" .
-    hence "finite (insert x (A - {x}))" ..
-    also have "insert x (A - {x}) = A" using x by (rule insert_Diff)
+    then have "finite (insert x (A - {x}))" ..
+    also have "insert x (A - {x}) = A"
+      using x by (rule insert_Diff)
     finally show ?thesis .
   next
     show ?thesis when "A \<subseteq> F"
       using that by fact
     assume "x \<notin> A"
-    with A show "A \<subseteq> F" by (simp add: subset_insert_iff)
+    with A show "A \<subseteq> F"
+      by (simp add: subset_insert_iff)
   qed
 qed
 
-lemma finite_subset:
-  "A \<subseteq> B \<Longrightarrow> finite B \<Longrightarrow> finite A"
+lemma finite_subset: "A \<subseteq> B \<Longrightarrow> finite B \<Longrightarrow> finite A"
   by (rule rev_finite_subset)
 
 lemma finite_UnI:
@@ -189,8 +196,7 @@
   shows "finite (F \<union> G)"
   using assms by induct simp_all
 
-lemma finite_Un [iff]:
-  "finite (F \<union> G) \<longleftrightarrow> finite F \<and> finite G"
+lemma finite_Un [iff]: "finite (F \<union> G) \<longleftrightarrow> finite F \<and> finite G"
   by (blast intro: finite_UnI finite_subset [of _ "F \<union> G"])
 
 lemma finite_insert [simp]: "finite (insert a A) \<longleftrightarrow> finite A"
@@ -200,8 +206,7 @@
   then show ?thesis by simp
 qed
 
-lemma finite_Int [simp, intro]:
-  "finite F \<or> finite G \<Longrightarrow> finite (F \<inter> G)"
+lemma finite_Int [simp, intro]: "finite F \<or> finite G \<Longrightarrow> finite (F \<inter> G)"
   by (blast intro: finite_subset)
 
 lemma finite_Collect_conjI [simp, intro]:
@@ -212,112 +217,110 @@
   "finite {x. P x \<or> Q x} \<longleftrightarrow> finite {x. P x} \<and> finite {x. Q x}"
   by (simp add: Collect_disj_eq)
 
-lemma finite_Diff [simp, intro]:
-  "finite A \<Longrightarrow> finite (A - B)"
+lemma finite_Diff [simp, intro]: "finite A \<Longrightarrow> finite (A - B)"
   by (rule finite_subset, rule Diff_subset)
 
 lemma finite_Diff2 [simp]:
   assumes "finite B"
   shows "finite (A - B) \<longleftrightarrow> finite A"
 proof -
-  have "finite A \<longleftrightarrow> finite((A - B) \<union> (A \<inter> B))" by (simp add: Un_Diff_Int)
-  also have "\<dots> \<longleftrightarrow> finite (A - B)" using \<open>finite B\<close> by simp
+  have "finite A \<longleftrightarrow> finite ((A - B) \<union> (A \<inter> B))"
+    by (simp add: Un_Diff_Int)
+  also have "\<dots> \<longleftrightarrow> finite (A - B)"
+    using \<open>finite B\<close> by simp
   finally show ?thesis ..
 qed
 
-lemma finite_Diff_insert [iff]:
-  "finite (A - insert a B) \<longleftrightarrow> finite (A - B)"
+lemma finite_Diff_insert [iff]: "finite (A - insert a B) \<longleftrightarrow> finite (A - B)"
 proof -
   have "finite (A - B) \<longleftrightarrow> finite (A - B - {a})" by simp
   moreover have "A - insert a B = A - B - {a}" by auto
   ultimately show ?thesis by simp
 qed
 
-lemma finite_compl[simp]:
+lemma finite_compl [simp]:
   "finite (A :: 'a set) \<Longrightarrow> finite (- A) \<longleftrightarrow> finite (UNIV :: 'a set)"
   by (simp add: Compl_eq_Diff_UNIV)
 
-lemma finite_Collect_not[simp]:
+lemma finite_Collect_not [simp]:
   "finite {x :: 'a. P x} \<Longrightarrow> finite {x. \<not> P x} \<longleftrightarrow> finite (UNIV :: 'a set)"
   by (simp add: Collect_neg_eq)
 
 lemma finite_Union [simp, intro]:
-  "finite A \<Longrightarrow> (\<And>M. M \<in> A \<Longrightarrow> finite M) \<Longrightarrow> finite(\<Union>A)"
+  "finite A \<Longrightarrow> (\<And>M. M \<in> A \<Longrightarrow> finite M) \<Longrightarrow> finite (\<Union>A)"
   by (induct rule: finite_induct) simp_all
 
 lemma finite_UN_I [intro]:
   "finite A \<Longrightarrow> (\<And>a. a \<in> A \<Longrightarrow> finite (B a)) \<Longrightarrow> finite (\<Union>a\<in>A. B a)"
   by (induct rule: finite_induct) simp_all
 
-lemma finite_UN [simp]:
-  "finite A \<Longrightarrow> finite (UNION A B) \<longleftrightarrow> (\<forall>x\<in>A. finite (B x))"
+lemma finite_UN [simp]: "finite A \<Longrightarrow> finite (UNION A B) \<longleftrightarrow> (\<forall>x\<in>A. finite (B x))"
   by (blast intro: finite_subset)
 
-lemma finite_Inter [intro]:
-  "\<exists>A\<in>M. finite A \<Longrightarrow> finite (\<Inter>M)"
+lemma finite_Inter [intro]: "\<exists>A\<in>M. finite A \<Longrightarrow> finite (\<Inter>M)"
   by (blast intro: Inter_lower finite_subset)
 
-lemma finite_INT [intro]:
-  "\<exists>x\<in>I. finite (A x) \<Longrightarrow> finite (\<Inter>x\<in>I. A x)"
+lemma finite_INT [intro]: "\<exists>x\<in>I. finite (A x) \<Longrightarrow> finite (\<Inter>x\<in>I. A x)"
   by (blast intro: INT_lower finite_subset)
 
-lemma finite_imageI [simp, intro]:
-  "finite F \<Longrightarrow> finite (h ` F)"
+lemma finite_imageI [simp, intro]: "finite F \<Longrightarrow> finite (h ` F)"
   by (induct rule: finite_induct) simp_all
 
-lemma finite_image_set [simp]:
-  "finite {x. P x} \<Longrightarrow> finite { f x | x. P x }"
+lemma finite_image_set [simp]: "finite {x. P x} \<Longrightarrow> finite {f x |x. P x}"
   by (simp add: image_Collect [symmetric])
 
 lemma finite_image_set2:
-  "finite {x. P x} \<Longrightarrow> finite {y. Q y} \<Longrightarrow> finite {f x y | x y. P x \<and> Q y}"
+  "finite {x. P x} \<Longrightarrow> finite {y. Q y} \<Longrightarrow> finite {f x y |x y. P x \<and> Q y}"
   by (rule finite_subset [where B = "\<Union>x \<in> {x. P x}. \<Union>y \<in> {y. Q y}. {f x y}"]) auto
 
 lemma finite_imageD:
   assumes "finite (f ` A)" and "inj_on f A"
   shows "finite A"
-using assms
+  using assms
 proof (induct "f ` A" arbitrary: A)
-  case empty then show ?case by simp
+  case empty
+  then show ?case by simp
 next
   case (insert x B)
-  then have B_A: "insert x B = f ` A" by simp
-  then obtain y where "x = f y" and "y \<in> A" by blast
-  from B_A \<open>x \<notin> B\<close> have "B = f ` A - {x}" by blast
-  with B_A \<open>x \<notin> B\<close> \<open>x = f y\<close> \<open>inj_on f A\<close> \<open>y \<in> A\<close> have "B = f ` (A - {y})" 
+  then have B_A: "insert x B = f ` A"
+    by simp
+  then obtain y where "x = f y" and "y \<in> A"
+    by blast
+  from B_A \<open>x \<notin> B\<close> have "B = f ` A - {x}"
+    by blast
+  with B_A \<open>x \<notin> B\<close> \<open>x = f y\<close> \<open>inj_on f A\<close> \<open>y \<in> A\<close> have "B = f ` (A - {y})"
     by (simp add: inj_on_image_set_diff Set.Diff_subset)
-  moreover from \<open>inj_on f A\<close> have "inj_on f (A - {y})" by (rule inj_on_diff)
-  ultimately have "finite (A - {y})" by (rule insert.hyps)
-  then show "finite A" by simp
+  moreover from \<open>inj_on f A\<close> have "inj_on f (A - {y})"
+    by (rule inj_on_diff)
+  ultimately have "finite (A - {y})"
+    by (rule insert.hyps)
+  then show "finite A"
+    by simp
 qed
 
-lemma finite_image_iff:
-  assumes "inj_on f A"
-  shows "finite (f ` A) \<longleftrightarrow> finite A"
-using assms finite_imageD by blast
+lemma finite_image_iff: "inj_on f A \<Longrightarrow> finite (f ` A) \<longleftrightarrow> finite A"
+  using finite_imageD by blast
 
-lemma finite_surj:
-  "finite A \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> finite B"
+lemma finite_surj: "finite A \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> finite B"
   by (erule finite_subset) (rule finite_imageI)
 
-lemma finite_range_imageI:
-  "finite (range g) \<Longrightarrow> finite (range (\<lambda>x. f (g x)))"
+lemma finite_range_imageI: "finite (range g) \<Longrightarrow> finite (range (\<lambda>x. f (g x)))"
   by (drule finite_imageI) (simp add: range_composition)
 
 lemma finite_subset_image:
   assumes "finite B"
   shows "B \<subseteq> f ` A \<Longrightarrow> \<exists>C\<subseteq>A. finite C \<and> B = f ` C"
-using assms
+  using assms
 proof induct
-  case empty then show ?case by simp
+  case empty
+  then show ?case by simp
 next
-  case insert then show ?case
-    by (clarsimp simp del: image_insert simp add: image_insert [symmetric])
-       blast
+  case insert
+  then show ?case
+    by (clarsimp simp del: image_insert simp add: image_insert [symmetric]) blast
 qed
 
-lemma finite_vimage_IntI:
-  "finite F \<Longrightarrow> inj_on h A \<Longrightarrow> finite (h -` F \<inter> A)"
+lemma finite_vimage_IntI: "finite F \<Longrightarrow> inj_on h A \<Longrightarrow> finite (h -` F \<inter> A)"
   apply (induct rule: finite_induct)
    apply simp_all
   apply (subst vimage_insert)
@@ -334,15 +337,14 @@
     by (simp only: * assms finite_UN_I)
 qed
 
-lemma finite_vimageI:
-  "finite F \<Longrightarrow> inj h \<Longrightarrow> finite (h -` F)"
+lemma finite_vimageI: "finite F \<Longrightarrow> inj h \<Longrightarrow> finite (h -` F)"
   using finite_vimage_IntI[of F h UNIV] by auto
 
-lemma finite_vimageD': "\<lbrakk> finite (f -` A); A \<subseteq> range f \<rbrakk> \<Longrightarrow> finite A"
-by(auto simp add: subset_image_iff intro: finite_subset[rotated])
+lemma finite_vimageD': "finite (f -` A) \<Longrightarrow> A \<subseteq> range f \<Longrightarrow> finite A"
+  by (auto simp add: subset_image_iff intro: finite_subset[rotated])
 
-lemma finite_vimageD: "\<lbrakk> finite (h -` F); surj h \<rbrakk> \<Longrightarrow> finite F"
-by(auto dest: finite_vimageD')
+lemma finite_vimageD: "finite (h -` F) \<Longrightarrow> surj h \<Longrightarrow> finite F"
+  by (auto dest: finite_vimageD')
 
 lemma finite_vimage_iff: "bij h \<Longrightarrow> finite (h -` F) \<longleftrightarrow> finite F"
   unfolding bij_def by (auto elim: finite_vimageD finite_vimageI)
@@ -359,30 +361,36 @@
   assumes "finite {y. P y}"
   shows "finite {x. \<exists>y. P y \<and> Q x y} \<longleftrightarrow> (\<forall>y. P y \<longrightarrow> finite {x. Q x y})"
 proof -
-  have "{x. EX y. P y & Q x y} = (\<Union>y\<in>{y. P y}. {x. Q x y})" by auto
-  with assms show ?thesis by simp
+  have "{x. \<exists>y. P y \<and> Q x y} = (\<Union>y\<in>{y. P y}. {x. Q x y})"
+    by auto
+  with assms show ?thesis
+    by simp
 qed
 
-lemma finite_Plus:
-  "finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A <+> B)"
+lemma finite_Plus: "finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A <+> B)"
   by (simp add: Plus_def)
 
-lemma finite_PlusD: 
+lemma finite_PlusD:
   fixes A :: "'a set" and B :: "'b set"
   assumes fin: "finite (A <+> B)"
   shows "finite A" "finite B"
 proof -
-  have "Inl ` A \<subseteq> A <+> B" by auto
-  then have "finite (Inl ` A :: ('a + 'b) set)" using fin by (rule finite_subset)
-  then show "finite A" by (rule finite_imageD) (auto intro: inj_onI)
+  have "Inl ` A \<subseteq> A <+> B"
+    by auto
+  then have "finite (Inl ` A :: ('a + 'b) set)"
+    using fin by (rule finite_subset)
+  then show "finite A"
+    by (rule finite_imageD) (auto intro: inj_onI)
 next
-  have "Inr ` B \<subseteq> A <+> B" by auto
-  then have "finite (Inr ` B :: ('a + 'b) set)" using fin by (rule finite_subset)
-  then show "finite B" by (rule finite_imageD) (auto intro: inj_onI)
+  have "Inr ` B \<subseteq> A <+> B"
+    by auto
+  then have "finite (Inr ` B :: ('a + 'b) set)"
+    using fin by (rule finite_subset)
+  then show "finite B"
+    by (rule finite_imageD) (auto intro: inj_onI)
 qed
 
-lemma finite_Plus_iff [simp]:
-  "finite (A <+> B) \<longleftrightarrow> finite A \<and> finite B"
+lemma finite_Plus_iff [simp]: "finite (A <+> B) \<longleftrightarrow> finite A \<and> finite B"
   by (auto intro: finite_PlusD finite_Plus)
 
 lemma finite_Plus_UNIV_iff [simp]:
@@ -390,21 +398,22 @@
   by (subst UNIV_Plus_UNIV [symmetric]) (rule finite_Plus_iff)
 
 lemma finite_SigmaI [simp, intro]:
-  "finite A \<Longrightarrow> (\<And>a. a\<in>A \<Longrightarrow> finite (B a)) ==> finite (SIGMA a:A. B a)"
-  by (unfold Sigma_def) blast
+  "finite A \<Longrightarrow> (\<And>a. a\<in>A \<Longrightarrow> finite (B a)) \<Longrightarrow> finite (SIGMA a:A. B a)"
+  unfolding Sigma_def by blast
 
 lemma finite_SigmaI2:
   assumes "finite {x\<in>A. B x \<noteq> {}}"
   and "\<And>a. a \<in> A \<Longrightarrow> finite (B a)"
   shows "finite (Sigma A B)"
 proof -
-  from assms have "finite (Sigma {x\<in>A. B x \<noteq> {}} B)" by auto
-  also have "Sigma {x:A. B x \<noteq> {}} B = Sigma A B" by auto
+  from assms have "finite (Sigma {x\<in>A. B x \<noteq> {}} B)"
+    by auto
+  also have "Sigma {x:A. B x \<noteq> {}} B = Sigma A B"
+    by auto
   finally show ?thesis .
 qed
 
-lemma finite_cartesian_product:
-  "finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A \<times> B)"
+lemma finite_cartesian_product: "finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A \<times> B)"
   by (rule finite_SigmaI)
 
 lemma finite_Prod_UNIV:
@@ -417,10 +426,12 @@
 proof -
   from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}"
     by (auto simp add: finite_conv_nat_seg_image)
-  then have "fst ` (A \<times> B) = fst ` f ` {i::nat. i < n}" by simp
+  then have "fst ` (A \<times> B) = fst ` f ` {i::nat. i < n}"
+    by simp
   with \<open>B \<noteq> {}\<close> have "A = (fst \<circ> f) ` {i::nat. i < n}"
     by (simp add: image_comp)
-  then have "\<exists>n f. A = f ` {i::nat. i < n}" by blast
+  then have "\<exists>n f. A = f ` {i::nat. i < n}"
+    by blast
   then show ?thesis
     by (auto simp add: finite_conv_nat_seg_image)
 qed
@@ -431,10 +442,12 @@
 proof -
   from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}"
     by (auto simp add: finite_conv_nat_seg_image)
-  then have "snd ` (A \<times> B) = snd ` f ` {i::nat. i < n}" by simp
+  then have "snd ` (A \<times> B) = snd ` f ` {i::nat. i < n}"
+    by simp
   with \<open>A \<noteq> {}\<close> have "B = (snd \<circ> f) ` {i::nat. i < n}"
     by (simp add: image_comp)
-  then have "\<exists>n f. B = f ` {i::nat. i < n}" by blast
+  then have "\<exists>n f. B = f ` {i::nat. i < n}"
+    by blast
   then show ?thesis
     by (auto simp add: finite_conv_nat_seg_image)
 qed
@@ -443,48 +456,52 @@
   "finite (A \<times> B) \<longleftrightarrow> (A = {} \<or> B = {} \<or> (finite A \<and> finite B))"
   by (auto dest: finite_cartesian_productD1 finite_cartesian_productD2 finite_cartesian_product)
 
-lemma finite_prod: 
+lemma finite_prod:
   "finite (UNIV :: ('a \<times> 'b) set) \<longleftrightarrow> finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set)"
   using finite_cartesian_product_iff[of UNIV UNIV] by simp
 
-lemma finite_Pow_iff [iff]:
-  "finite (Pow A) \<longleftrightarrow> finite A"
+lemma finite_Pow_iff [iff]: "finite (Pow A) \<longleftrightarrow> finite A"
 proof
   assume "finite (Pow A)"
-  then have "finite ((%x. {x}) ` A)" by (blast intro: finite_subset)
-  then show "finite A" by (rule finite_imageD [unfolded inj_on_def]) simp
+  then have "finite ((\<lambda>x. {x}) ` A)"
+    by (blast intro: finite_subset)
+  then show "finite A"
+    by (rule finite_imageD [unfolded inj_on_def]) simp
 next
   assume "finite A"
   then show "finite (Pow A)"
     by induct (simp_all add: Pow_insert)
 qed
 
-corollary finite_Collect_subsets [simp, intro]:
-  "finite A \<Longrightarrow> finite {B. B \<subseteq> A}"
+corollary finite_Collect_subsets [simp, intro]: "finite A \<Longrightarrow> finite {B. B \<subseteq> A}"
   by (simp add: Pow_def [symmetric])
 
 lemma finite_set: "finite (UNIV :: 'a set set) \<longleftrightarrow> finite (UNIV :: 'a set)"
-by(simp only: finite_Pow_iff Pow_UNIV[symmetric])
+  by (simp only: finite_Pow_iff Pow_UNIV[symmetric])
 
-lemma finite_UnionD: "finite(\<Union>A) \<Longrightarrow> finite A"
+lemma finite_UnionD: "finite (\<Union>A) \<Longrightarrow> finite A"
   by (blast intro: finite_subset [OF subset_Pow_Union])
 
-lemma finite_set_of_finite_funs: assumes "finite A" "finite B"
-shows "finite{f. \<forall>x. (x \<in> A \<longrightarrow> f x \<in> B) \<and> (x \<notin> A \<longrightarrow> f x = d)}" (is "finite ?S")
-proof-
+lemma finite_set_of_finite_funs:
+  assumes "finite A" "finite B"
+  shows "finite {f. \<forall>x. (x \<in> A \<longrightarrow> f x \<in> B) \<and> (x \<notin> A \<longrightarrow> f x = d)}" (is "finite ?S")
+proof -
   let ?F = "\<lambda>f. {(a,b). a \<in> A \<and> b = f a}"
-  have "?F ` ?S \<subseteq> Pow(A \<times> B)" by auto
-  from finite_subset[OF this] assms have 1: "finite (?F ` ?S)" by simp
+  have "?F ` ?S \<subseteq> Pow(A \<times> B)"
+    by auto
+  from finite_subset[OF this] assms have 1: "finite (?F ` ?S)"
+    by simp
   have 2: "inj_on ?F ?S"
-    by(fastforce simp add: inj_on_def set_eq_iff fun_eq_iff)
-  show ?thesis by(rule finite_imageD[OF 1 2])
+    by (fastforce simp add: inj_on_def set_eq_iff fun_eq_iff)
+  show ?thesis
+    by (rule finite_imageD [OF 1 2])
 qed
 
 lemma not_finite_existsD:
   assumes "\<not> finite {a. P a}"
   shows "\<exists>a. P a"
 proof (rule classical)
-  assume "\<not> (\<exists>a. P a)"
+  assume "\<not> ?thesis"
   with assms show ?thesis by auto
 qed
 
@@ -496,11 +513,13 @@
   assumes "\<And>x. P {x}"
     and "\<And>x F. finite F \<Longrightarrow> F \<noteq> {} \<Longrightarrow> x \<notin> F \<Longrightarrow> P F  \<Longrightarrow> P (insert x F)"
   shows "P F"
-using assms
+  using assms
 proof induct
-  case empty then show ?case by simp
+  case empty
+  then show ?case by simp
 next
-  case (insert x F) then show ?case by cases auto
+  case (insert x F)
+  then show ?case by cases auto
 qed
 
 lemma finite_subset_induct [consumes 2, case_names empty insert]:
@@ -508,13 +527,12 @@
   assumes empty: "P {}"
     and insert: "\<And>a F. finite F \<Longrightarrow> a \<in> A \<Longrightarrow> a \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert a F)"
   shows "P F"
-using \<open>finite F\<close> \<open>F \<subseteq> A\<close>
+  using \<open>finite F\<close> \<open>F \<subseteq> A\<close>
 proof induct
   show "P {}" by fact
 next
   fix x F
-  assume "finite F" and "x \<notin> F" and
-    P: "F \<subseteq> A \<Longrightarrow> P F" and i: "insert x F \<subseteq> A"
+  assume "finite F" and "x \<notin> F" and P: "F \<subseteq> A \<Longrightarrow> P F" and i: "insert x F \<subseteq> A"
   show "P (insert x F)"
   proof (rule insert)
     from i show "x \<in> A" by blast
@@ -531,11 +549,10 @@
     and remove: "\<And>a A. finite A \<Longrightarrow> a \<in> A \<Longrightarrow> P A \<Longrightarrow> P (A - {a})"
   shows "P {}"
 proof -
-  have "\<And>B. B \<subseteq> A \<Longrightarrow> P (A - B)"
+  have "P (A - B)" if "B \<subseteq> A" for B :: "'a set"
   proof -
-    fix B :: "'a set"
-    assume "B \<subseteq> A"
-    with \<open>finite A\<close> have "finite B" by (rule rev_finite_subset)
+    from \<open>finite A\<close> that have "finite B"
+      by (rule rev_finite_subset)
     from this \<open>B \<subseteq> A\<close> show "P (A - B)"
     proof induct
       case empty
@@ -544,11 +561,15 @@
       case (insert b B)
       have "P (A - B - {b})"
       proof (rule remove)
-        from \<open>finite A\<close> show "finite (A - B)" by induct auto
-        from insert show "b \<in> A - B" by simp
-        from insert show "P (A - B)" by simp
+        from \<open>finite A\<close> show "finite (A - B)"
+          by induct auto
+        from insert show "b \<in> A - B"
+          by simp
+        from insert show "P (A - B)"
+          by simp
       qed
-      also have "A - B - {b} = A - insert b B" by (rule Diff_insert [symmetric])
+      also have "A - B - {b} = A - insert b B"
+        by (rule Diff_insert [symmetric])
       finally show ?case .
     qed
   qed
@@ -558,11 +579,13 @@
 
 lemma finite_update_induct [consumes 1, case_names const update]:
   assumes finite: "finite {a. f a \<noteq> c}"
-  assumes const: "P (\<lambda>a. c)"
-  assumes update: "\<And>a b f. finite {a. f a \<noteq> c} \<Longrightarrow> f a = c \<Longrightarrow> b \<noteq> c \<Longrightarrow> P f \<Longrightarrow> P (f(a := b))"
+    and const: "P (\<lambda>a. c)"
+    and update: "\<And>a b f. finite {a. f a \<noteq> c} \<Longrightarrow> f a = c \<Longrightarrow> b \<noteq> c \<Longrightarrow> P f \<Longrightarrow> P (f(a := b))"
   shows "P f"
-using finite proof (induct "{a. f a \<noteq> c}" arbitrary: f)
-  case empty with const show ?case by simp
+  using finite
+proof (induct "{a. f a \<noteq> c}" arbitrary: f)
+  case empty
+  with const show ?case by simp
 next
   case (insert a A)
   then have "A = {a'. (f(a := c)) a' \<noteq> c}" and "f a \<noteq> c"
@@ -573,7 +596,8 @@
     by simp
   from insert \<open>A = {a'. (f(a := c)) a' \<noteq> c}\<close> have "P (f(a := c))"
     by simp
-  with \<open>finite {a'. (f(a := c)) a' \<noteq> c}\<close> \<open>(f(a := c)) a = c\<close> \<open>f a \<noteq> c\<close> have "P ((f(a := c))(a := f a))"
+  with \<open>finite {a'. (f(a := c)) a' \<noteq> c}\<close> \<open>(f(a := c)) a = c\<close> \<open>f a \<noteq> c\<close>
+  have "P ((f(a := c))(a := f a))"
     by (rule update)
   then show ?case by simp
 qed
@@ -581,8 +605,7 @@
 
 subsection \<open>Class \<open>finite\<close>\<close>
 
-class finite =
-  assumes finite_UNIV: "finite (UNIV :: 'a set)"
+class finite = assumes finite_UNIV: "finite (UNIV :: 'a set)"
 begin
 
 lemma finite [simp]: "finite (A :: 'a set)"
@@ -596,20 +619,22 @@
 instance prod :: (finite, finite) finite
   by standard (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product finite)
 
-lemma inj_graph: "inj (%f. {(x, y). y = f x})"
-  by (rule inj_onI, auto simp add: set_eq_iff fun_eq_iff)
+lemma inj_graph: "inj (\<lambda>f. {(x, y). y = f x})"
+  by (rule inj_onI) (auto simp add: set_eq_iff fun_eq_iff)
 
 instance "fun" :: (finite, finite) finite
 proof
-  show "finite (UNIV :: ('a => 'b) set)"
+  show "finite (UNIV :: ('a \<Rightarrow> 'b) set)"
   proof (rule finite_imageD)
-    let ?graph = "%f::'a => 'b. {(x, y). y = f x}"
-    have "range ?graph \<subseteq> Pow UNIV" by simp
+    let ?graph = "\<lambda>f::'a \<Rightarrow> 'b. {(x, y). y = f x}"
+    have "range ?graph \<subseteq> Pow UNIV"
+      by simp
     moreover have "finite (Pow (UNIV :: ('a * 'b) set))"
       by (simp only: finite_Pow_iff finite)
     ultimately show "finite (range ?graph)"
       by (rule finite_subset)
-    show "inj ?graph" by (rule inj_graph)
+    show "inj ?graph"
+      by (rule inj_graph)
   qed
 qed
 
@@ -629,8 +654,8 @@
 subsection \<open>A basic fold functional for finite sets\<close>
 
 text \<open>The intended behaviour is
-\<open>fold f z {x\<^sub>1, ..., x\<^sub>n} = f x\<^sub>1 (\<dots> (f x\<^sub>n z)\<dots>)\<close>
-if \<open>f\<close> is ``left-commutative'':
+  \<open>fold f z {x\<^sub>1, \<dots>, x\<^sub>n} = f x\<^sub>1 (\<dots> (f x\<^sub>n z)\<dots>)\<close>
+  if \<open>f\<close> is ``left-commutative'':
 \<close>
 
 locale comp_fun_commute =
@@ -641,34 +666,35 @@
 lemma fun_left_comm: "f y (f x z) = f x (f y z)"
   using comp_fun_commute by (simp add: fun_eq_iff)
 
-lemma commute_left_comp:
-  "f y \<circ> (f x \<circ> g) = f x \<circ> (f y \<circ> g)"
+lemma commute_left_comp: "f y \<circ> (f x \<circ> g) = f x \<circ> (f y \<circ> g)"
   by (simp add: o_assoc comp_fun_commute)
 
 end
 
 inductive fold_graph :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> bool"
-for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: 'b where
-  emptyI [intro]: "fold_graph f z {} z" |
-  insertI [intro]: "x \<notin> A \<Longrightarrow> fold_graph f z A y
-      \<Longrightarrow> fold_graph f z (insert x A) (f x y)"
+  for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: 'b
+where
+  emptyI [intro]: "fold_graph f z {} z"
+| insertI [intro]: "x \<notin> A \<Longrightarrow> fold_graph f z A y \<Longrightarrow> fold_graph f z (insert x A) (f x y)"
 
 inductive_cases empty_fold_graphE [elim!]: "fold_graph f z {} x"
 
-definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" where
-  "fold f z A = (if finite A then (THE y. fold_graph f z A y) else z)"
+definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b"
+  where "fold f z A = (if finite A then (THE y. fold_graph f z A y) else z)"
 
-text\<open>A tempting alternative for the definiens is
-@{term "if finite A then THE y. fold_graph f z A y else e"}.
-It allows the removal of finiteness assumptions from the theorems
-\<open>fold_comm\<close>, \<open>fold_reindex\<close> and \<open>fold_distrib\<close>.
-The proofs become ugly. It is not worth the effort. (???)\<close>
+text \<open>
+  A tempting alternative for the definiens is
+  @{term "if finite A then THE y. fold_graph f z A y else e"}.
+  It allows the removal of finiteness assumptions from the theorems
+  \<open>fold_comm\<close>, \<open>fold_reindex\<close> and \<open>fold_distrib\<close>.
+  The proofs become ugly. It is not worth the effort. (???)
+\<close>
 
 lemma finite_imp_fold_graph: "finite A \<Longrightarrow> \<exists>x. fold_graph f z A x"
-by (induct rule: finite_induct) auto
+  by (induct rule: finite_induct) auto
 
 
-subsubsection\<open>From @{const fold_graph} to @{term fold}\<close>
+subsubsection \<open>From @{const fold_graph} to @{term fold}\<close>
 
 context comp_fun_commute
 begin
@@ -681,11 +707,16 @@
 lemma fold_graph_insertE_aux:
   "fold_graph f z A y \<Longrightarrow> a \<in> A \<Longrightarrow> \<exists>y'. y = f a y' \<and> fold_graph f z (A - {a}) y'"
 proof (induct set: fold_graph)
-  case (insertI x A y) show ?case
+  case emptyI
+  then show ?case by simp
+next
+  case (insertI x A y)
+  show ?case
   proof (cases "x = a")
-    assume "x = a" with insertI show ?case by auto
+    case True
+    with insertI show ?thesis by auto
   next
-    assume "x \<noteq> a"
+    case False
     then obtain y' where y: "y = f a y'" and y': "fold_graph f z (A - {a}) y'"
       using insertI by auto
     have "f x y = f a (f x y')"
@@ -693,86 +724,96 @@
     moreover have "fold_graph f z (insert x A - {a}) (f x y')"
       using y' and \<open>x \<noteq> a\<close> and \<open>x \<notin> A\<close>
       by (simp add: insert_Diff_if fold_graph.insertI)
-    ultimately show ?case by fast
+    ultimately show ?thesis
+      by fast
   qed
-qed simp
+qed
 
 lemma fold_graph_insertE:
   assumes "fold_graph f z (insert x A) v" and "x \<notin> A"
   obtains y where "v = f x y" and "fold_graph f z A y"
-using assms by (auto dest: fold_graph_insertE_aux [OF _ insertI1])
+  using assms by (auto dest: fold_graph_insertE_aux [OF _ insertI1])
 
-lemma fold_graph_determ:
-  "fold_graph f z A x \<Longrightarrow> fold_graph f z A y \<Longrightarrow> y = x"
+lemma fold_graph_determ: "fold_graph f z A x \<Longrightarrow> fold_graph f z A y \<Longrightarrow> y = x"
 proof (induct arbitrary: y set: fold_graph)
+  case emptyI
+  then show ?case by fast
+next
   case (insertI x A y v)
   from \<open>fold_graph f z (insert x A) v\<close> and \<open>x \<notin> A\<close>
   obtain y' where "v = f x y'" and "fold_graph f z A y'"
     by (rule fold_graph_insertE)
-  from \<open>fold_graph f z A y'\<close> have "y' = y" by (rule insertI)
-  with \<open>v = f x y'\<close> show "v = f x y" by simp
-qed fast
+  from \<open>fold_graph f z A y'\<close> have "y' = y"
+    by (rule insertI)
+  with \<open>v = f x y'\<close> show "v = f x y"
+    by simp
+qed
 
-lemma fold_equality:
-  "fold_graph f z A y \<Longrightarrow> fold f z A = y"
+lemma fold_equality: "fold_graph f z A y \<Longrightarrow> fold f z A = y"
   by (cases "finite A") (auto simp add: fold_def intro: fold_graph_determ dest: fold_graph_finite)
 
 lemma fold_graph_fold:
   assumes "finite A"
   shows "fold_graph f z A (fold f z A)"
 proof -
-  from assms have "\<exists>x. fold_graph f z A x" by (rule finite_imp_fold_graph)
+  from assms have "\<exists>x. fold_graph f z A x"
+    by (rule finite_imp_fold_graph)
   moreover note fold_graph_determ
-  ultimately have "\<exists>!x. fold_graph f z A x" by (rule ex_ex1I)
-  then have "fold_graph f z A (The (fold_graph f z A))" by (rule theI')
-  with assms show ?thesis by (simp add: fold_def)
+  ultimately have "\<exists>!x. fold_graph f z A x"
+    by (rule ex_ex1I)
+  then have "fold_graph f z A (The (fold_graph f z A))"
+    by (rule theI')
+  with assms show ?thesis
+    by (simp add: fold_def)
 qed
 
 text \<open>The base case for \<open>fold\<close>:\<close>
 
-lemma (in -) fold_infinite [simp]:
-  assumes "\<not> finite A"
-  shows "fold f z A = z"
-  using assms by (auto simp add: fold_def)
+lemma (in -) fold_infinite [simp]: "\<not> finite A \<Longrightarrow> fold f z A = z"
+  by (auto simp: fold_def)
 
-lemma (in -) fold_empty [simp]:
-  "fold f z {} = z"
-  by (auto simp add: fold_def)
+lemma (in -) fold_empty [simp]: "fold f z {} = z"
+  by (auto simp: fold_def)
 
-text\<open>The various recursion equations for @{const fold}:\<close>
+text \<open>The various recursion equations for @{const fold}:\<close>
 
 lemma fold_insert [simp]:
   assumes "finite A" and "x \<notin> A"
   shows "fold f z (insert x A) = f x (fold f z A)"
 proof (rule fold_equality)
   fix z
-  from \<open>finite A\<close> have "fold_graph f z A (fold f z A)" by (rule fold_graph_fold)
-  with \<open>x \<notin> A\<close> have "fold_graph f z (insert x A) (f x (fold f z A))" by (rule fold_graph.insertI)
-  then show "fold_graph f z (insert x A) (f x (fold f z A))" by simp
+  from \<open>finite A\<close> have "fold_graph f z A (fold f z A)"
+    by (rule fold_graph_fold)
+  with \<open>x \<notin> A\<close> have "fold_graph f z (insert x A) (f x (fold f z A))"
+    by (rule fold_graph.insertI)
+  then show "fold_graph f z (insert x A) (f x (fold f z A))"
+    by simp
 qed
 
 declare (in -) empty_fold_graphE [rule del] fold_graph.intros [rule del]
   \<comment> \<open>No more proofs involve these.\<close>
 
-lemma fold_fun_left_comm:
-  "finite A \<Longrightarrow> f x (fold f z A) = fold f (f x z) A"
+lemma fold_fun_left_comm: "finite A \<Longrightarrow> f x (fold f z A) = fold f (f x z) A"
 proof (induct rule: finite_induct)
-  case empty then show ?case by simp
+  case empty
+  then show ?case by simp
 next
-  case (insert y A) then show ?case
+  case insert
+  then show ?case
     by (simp add: fun_left_comm [of x])
 qed
 
-lemma fold_insert2:
-  "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> fold f z (insert x A)  = fold f (f x z) A"
+lemma fold_insert2: "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> fold f z (insert x A)  = fold f (f x z) A"
   by (simp add: fold_fun_left_comm)
 
 lemma fold_rec:
   assumes "finite A" and "x \<in> A"
   shows "fold f z A = f x (fold f z (A - {x}))"
 proof -
-  have A: "A = insert x (A - {x})" using \<open>x \<in> A\<close> by blast
-  then have "fold f z A = fold f z (insert x (A - {x}))" by simp
+  have A: "A = insert x (A - {x})"
+    using \<open>x \<in> A\<close> by blast
+  then have "fold f z A = fold f z (insert x (A - {x}))"
+    by simp
   also have "\<dots> = f x (fold f z (A - {x}))"
     by (rule fold_insert) (simp add: \<open>finite A\<close>)+
   finally show ?thesis .
@@ -782,27 +823,32 @@
   assumes "finite A"
   shows "fold f z (insert x A) = f x (fold f z (A - {x}))"
 proof -
-  from \<open>finite A\<close> have "finite (insert x A)" by auto
-  moreover have "x \<in> insert x A" by auto
+  from \<open>finite A\<close> have "finite (insert x A)"
+    by auto
+  moreover have "x \<in> insert x A"
+    by auto
   ultimately have "fold f z (insert x A) = f x (fold f z (insert x A - {x}))"
     by (rule fold_rec)
-  then show ?thesis by simp
+  then show ?thesis
+    by simp
 qed
 
 lemma fold_set_union_disj:
   assumes "finite A" "finite B" "A \<inter> B = {}"
   shows "Finite_Set.fold f z (A \<union> B) = Finite_Set.fold f (Finite_Set.fold f z A) B"
-using assms(2,1,3) by induction simp_all
+  using assms(2,1,3) by induct simp_all
 
 end
 
-text\<open>Other properties of @{const fold}:\<close>
+text \<open>Other properties of @{const fold}:\<close>
 
 lemma fold_image:
   assumes "inj_on g A"
   shows "fold f z (g ` A) = fold (f \<circ> g) z A"
 proof (cases "finite A")
-  case False with assms show ?thesis by (auto dest: finite_imageD simp add: fold_def)
+  case False
+  with assms show ?thesis
+    by (auto dest: finite_imageD simp add: fold_def)
 next
   case True
   have "fold_graph f z (g ` A) = fold_graph (f \<circ> g) z A"
@@ -810,48 +856,63 @@
     fix w
     show "fold_graph f z (g ` A) w \<longleftrightarrow> fold_graph (f \<circ> g) z A w" (is "?P \<longleftrightarrow> ?Q")
     proof
-      assume ?P then show ?Q using assms
+      assume ?P
+      then show ?Q
+        using assms
       proof (induct "g ` A" w arbitrary: A)
-        case emptyI then show ?case by (auto intro: fold_graph.emptyI)
+        case emptyI
+        then show ?case by (auto intro: fold_graph.emptyI)
       next
         case (insertI x A r B)
-        from \<open>inj_on g B\<close> \<open>x \<notin> A\<close> \<open>insert x A = image g B\<close> obtain x' A' where
-          "x' \<notin> A'" and [simp]: "B = insert x' A'" "x = g x'" "A = g ` A'"
+        from \<open>inj_on g B\<close> \<open>x \<notin> A\<close> \<open>insert x A = image g B\<close> obtain x' A'
+          where "x' \<notin> A'" and [simp]: "B = insert x' A'" "x = g x'" "A = g ` A'"
           by (rule inj_img_insertE)
-        from insertI.prems have "fold_graph (f o g) z A' r"
+        from insertI.prems have "fold_graph (f \<circ> g) z A' r"
           by (auto intro: insertI.hyps)
         with \<open>x' \<notin> A'\<close> have "fold_graph (f \<circ> g) z (insert x' A') ((f \<circ> g) x' r)"
           by (rule fold_graph.insertI)
-        then show ?case by simp
+        then show ?case
+          by simp
       qed
     next
-      assume ?Q then show ?P using assms
+      assume ?Q
+      then show ?P
+        using assms
       proof induct
-        case emptyI thus ?case by (auto intro: fold_graph.emptyI)
+        case emptyI
+        then show ?case
+          by (auto intro: fold_graph.emptyI)
       next
         case (insertI x A r)
-        from \<open>x \<notin> A\<close> insertI.prems have "g x \<notin> g ` A" by auto
-        moreover from insertI have "fold_graph f z (g ` A) r" by simp
+        from \<open>x \<notin> A\<close> insertI.prems have "g x \<notin> g ` A"
+          by auto
+        moreover from insertI have "fold_graph f z (g ` A) r"
+          by simp
         ultimately have "fold_graph f z (insert (g x) (g ` A)) (f (g x) r)"
           by (rule fold_graph.insertI)
-        then show ?case by simp
+        then show ?case
+          by simp
       qed
     qed
   qed
-  with True assms show ?thesis by (auto simp add: fold_def)
+  with True assms show ?thesis
+    by (auto simp add: fold_def)
 qed
 
 lemma fold_cong:
   assumes "comp_fun_commute f" "comp_fun_commute g"
-  assumes "finite A" and cong: "\<And>x. x \<in> A \<Longrightarrow> f x = g x"
+    and "finite A"
+    and cong: "\<And>x. x \<in> A \<Longrightarrow> f x = g x"
     and "s = t" and "A = B"
   shows "fold f s A = fold g t B"
 proof -
-  have "fold f s A = fold g s A"  
-  using \<open>finite A\<close> cong proof (induct A)
-    case empty then show ?case by simp
+  have "fold f s A = fold g s A"
+    using \<open>finite A\<close> cong
+  proof (induct A)
+    case empty
+    then show ?case by simp
   next
-    case (insert x A)
+    case insert
     interpret f: comp_fun_commute f by (fact \<open>comp_fun_commute f\<close>)
     interpret g: comp_fun_commute g by (fact \<open>comp_fun_commute g\<close>)
     from insert show ?case by simp
@@ -874,16 +935,19 @@
   shows "fold f z (insert x A)  = f x (fold f z A)"
 proof cases
   assume "x \<in> A"
-  then obtain B where "A = insert x B" and "x \<notin> B" by (rule set_insert)
-  then show ?thesis using assms by (simp add: comp_fun_idem fun_left_idem)
+  then obtain B where "A = insert x B" and "x \<notin> B"
+    by (rule set_insert)
+  then show ?thesis
+    using assms by (simp add: comp_fun_idem fun_left_idem)
 next
-  assume "x \<notin> A" then show ?thesis using assms by simp
+  assume "x \<notin> A"
+  then show ?thesis
+    using assms by simp
 qed
 
 declare fold_insert [simp del] fold_insert_idem [simp]
 
-lemma fold_insert_idem2:
-  "finite A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A"
+lemma fold_insert_idem2: "finite A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A"
   by (simp add: fold_fun_left_comm)
 
 end
@@ -891,50 +955,54 @@
 
 subsubsection \<open>Liftings to \<open>comp_fun_commute\<close> etc.\<close>
 
-lemma (in comp_fun_commute) comp_comp_fun_commute:
-  "comp_fun_commute (f \<circ> g)"
-proof
-qed (simp_all add: comp_fun_commute)
+lemma (in comp_fun_commute) comp_comp_fun_commute: "comp_fun_commute (f \<circ> g)"
+  by standard (simp_all add: comp_fun_commute)
 
-lemma (in comp_fun_idem) comp_comp_fun_idem:
-  "comp_fun_idem (f \<circ> g)"
+lemma (in comp_fun_idem) comp_comp_fun_idem: "comp_fun_idem (f \<circ> g)"
   by (rule comp_fun_idem.intro, rule comp_comp_fun_commute, unfold_locales)
     (simp_all add: comp_fun_idem)
 
-lemma (in comp_fun_commute) comp_fun_commute_funpow:
-  "comp_fun_commute (\<lambda>x. f x ^^ g x)"
+lemma (in comp_fun_commute) comp_fun_commute_funpow: "comp_fun_commute (\<lambda>x. f x ^^ g x)"
 proof
-  fix y x
-  show "f y ^^ g y \<circ> f x ^^ g x = f x ^^ g x \<circ> f y ^^ g y"
+  show "f y ^^ g y \<circ> f x ^^ g x = f x ^^ g x \<circ> f y ^^ g y" for x y
   proof (cases "x = y")
-    case True then show ?thesis by simp
+    case True
+    then show ?thesis by simp
   next
-    case False show ?thesis
+    case False
+    show ?thesis
     proof (induct "g x" arbitrary: g)
-      case 0 then show ?case by simp
+      case 0
+      then show ?case by simp
     next
       case (Suc n g)
       have hyp1: "f y ^^ g y \<circ> f x = f x \<circ> f y ^^ g y"
       proof (induct "g y" arbitrary: g)
-        case 0 then show ?case by simp
+        case 0
+        then show ?case by simp
       next
         case (Suc n g)
         define h where "h z = g z - 1" for z
-        with Suc have "n = h y" by simp
+        with Suc have "n = h y"
+          by simp
         with Suc have hyp: "f y ^^ h y \<circ> f x = f x \<circ> f y ^^ h y"
           by auto
-        from Suc h_def have "g y = Suc (h y)" by simp
-        then show ?case by (simp add: comp_assoc hyp)
-          (simp add: o_assoc comp_fun_commute)
+        from Suc h_def have "g y = Suc (h y)"
+          by simp
+        then show ?case
+          by (simp add: comp_assoc hyp) (simp add: o_assoc comp_fun_commute)
       qed
       define h where "h z = (if z = x then g x - 1 else g z)" for z
-      with Suc have "n = h x" by simp
+      with Suc have "n = h x"
+        by simp
       with Suc have "f y ^^ h y \<circ> f x ^^ h x = f x ^^ h x \<circ> f y ^^ h y"
         by auto
-      with False h_def have hyp2: "f y ^^ g y \<circ> f x ^^ h x = f x ^^ h x \<circ> f y ^^ g y" by simp
-      from Suc h_def have "g x = Suc (h x)" by simp
-      then show ?case by (simp del: funpow.simps add: funpow_Suc_right o_assoc hyp2)
-        (simp add: comp_assoc hyp1)
+      with False h_def have hyp2: "f y ^^ g y \<circ> f x ^^ h x = f x ^^ h x \<circ> f y ^^ g y"
+        by simp
+      from Suc h_def have "g x = Suc (h x)"
+        by simp
+      then show ?case
+        by (simp del: funpow.simps add: funpow_Suc_right o_assoc hyp2) (simp add: comp_assoc hyp1)
     qed
   qed
 qed
@@ -942,51 +1010,45 @@
 
 subsubsection \<open>Expressing set operations via @{const fold}\<close>
 
-lemma comp_fun_commute_const:
-  "comp_fun_commute (\<lambda>_. f)"
-proof
-qed rule
+lemma comp_fun_commute_const: "comp_fun_commute (\<lambda>_. f)"
+  by standard rule
 
-lemma comp_fun_idem_insert:
-  "comp_fun_idem insert"
-proof
-qed auto
+lemma comp_fun_idem_insert: "comp_fun_idem insert"
+  by standard auto
 
-lemma comp_fun_idem_remove:
-  "comp_fun_idem Set.remove"
-proof
-qed auto
+lemma comp_fun_idem_remove: "comp_fun_idem Set.remove"
+  by standard auto
 
-lemma (in semilattice_inf) comp_fun_idem_inf:
-  "comp_fun_idem inf"
-proof
-qed (auto simp add: inf_left_commute)
+lemma (in semilattice_inf) comp_fun_idem_inf: "comp_fun_idem inf"
+  by standard (auto simp add: inf_left_commute)
 
-lemma (in semilattice_sup) comp_fun_idem_sup:
-  "comp_fun_idem sup"
-proof
-qed (auto simp add: sup_left_commute)
+lemma (in semilattice_sup) comp_fun_idem_sup: "comp_fun_idem sup"
+  by standard (auto simp add: sup_left_commute)
 
 lemma union_fold_insert:
   assumes "finite A"
   shows "A \<union> B = fold insert B A"
 proof -
-  interpret comp_fun_idem insert by (fact comp_fun_idem_insert)
-  from \<open>finite A\<close> show ?thesis by (induct A arbitrary: B) simp_all
+  interpret comp_fun_idem insert
+    by (fact comp_fun_idem_insert)
+  from \<open>finite A\<close> show ?thesis
+    by (induct A arbitrary: B) simp_all
 qed
 
 lemma minus_fold_remove:
   assumes "finite A"
   shows "B - A = fold Set.remove B A"
 proof -
-  interpret comp_fun_idem Set.remove by (fact comp_fun_idem_remove)
-  from \<open>finite A\<close> have "fold Set.remove B A = B - A" by (induct A arbitrary: B) auto
+  interpret comp_fun_idem Set.remove
+    by (fact comp_fun_idem_remove)
+  from \<open>finite A\<close> have "fold Set.remove B A = B - A"
+    by (induct A arbitrary: B) auto
   then show ?thesis ..
 qed
 
 lemma comp_fun_commute_filter_fold:
   "comp_fun_commute (\<lambda>x A'. if P x then Set.insert x A' else A')"
-proof - 
+proof -
   interpret comp_fun_idem Set.insert by (fact comp_fun_idem_insert)
   show ?thesis by standard (auto simp: fun_eq_iff)
 qed
@@ -994,77 +1056,79 @@
 lemma Set_filter_fold:
   assumes "finite A"
   shows "Set.filter P A = fold (\<lambda>x A'. if P x then Set.insert x A' else A') {} A"
-using assms
-by (induct A) 
-  (auto simp add: Set.filter_def comp_fun_commute.fold_insert[OF comp_fun_commute_filter_fold])
+  using assms
+  by induct
+    (auto simp add: Set.filter_def comp_fun_commute.fold_insert[OF comp_fun_commute_filter_fold])
 
-lemma inter_Set_filter:     
+lemma inter_Set_filter:
   assumes "finite B"
   shows "A \<inter> B = Set.filter (\<lambda>x. x \<in> A) B"
-using assms 
-by (induct B) (auto simp: Set.filter_def)
+  using assms
+  by induct (auto simp: Set.filter_def)
 
 lemma image_fold_insert:
   assumes "finite A"
   shows "image f A = fold (\<lambda>k A. Set.insert (f k) A) {} A"
-using assms
 proof -
-  interpret comp_fun_commute "\<lambda>k A. Set.insert (f k) A" by standard auto
-  show ?thesis using assms by (induct A) auto
+  interpret comp_fun_commute "\<lambda>k A. Set.insert (f k) A"
+    by standard auto
+  show ?thesis
+    using assms by (induct A) auto
 qed
 
 lemma Ball_fold:
   assumes "finite A"
   shows "Ball A P = fold (\<lambda>k s. s \<and> P k) True A"
-using assms
 proof -
-  interpret comp_fun_commute "\<lambda>k s. s \<and> P k" by standard auto
-  show ?thesis using assms by (induct A) auto
+  interpret comp_fun_commute "\<lambda>k s. s \<and> P k"
+    by standard auto
+  show ?thesis
+    using assms by (induct A) auto
 qed
 
 lemma Bex_fold:
   assumes "finite A"
   shows "Bex A P = fold (\<lambda>k s. s \<or> P k) False A"
-using assms
 proof -
-  interpret comp_fun_commute "\<lambda>k s. s \<or> P k" by standard auto
-  show ?thesis using assms by (induct A) auto
+  interpret comp_fun_commute "\<lambda>k s. s \<or> P k"
+    by standard auto
+  show ?thesis
+    using assms by (induct A) auto
 qed
 
-lemma comp_fun_commute_Pow_fold: 
-  "comp_fun_commute (\<lambda>x A. A \<union> Set.insert x ` A)" 
+lemma comp_fun_commute_Pow_fold: "comp_fun_commute (\<lambda>x A. A \<union> Set.insert x ` A)"
   by (clarsimp simp: fun_eq_iff comp_fun_commute_def) blast
 
 lemma Pow_fold:
   assumes "finite A"
   shows "Pow A = fold (\<lambda>x A. A \<union> Set.insert x ` A) {{}} A"
-using assms
 proof -
-  interpret comp_fun_commute "\<lambda>x A. A \<union> Set.insert x ` A" by (rule comp_fun_commute_Pow_fold)
-  show ?thesis using assms by (induct A) (auto simp: Pow_insert)
+  interpret comp_fun_commute "\<lambda>x A. A \<union> Set.insert x ` A"
+    by (rule comp_fun_commute_Pow_fold)
+  show ?thesis
+    using assms by (induct A) (auto simp: Pow_insert)
 qed
 
 lemma fold_union_pair:
   assumes "finite B"
   shows "(\<Union>y\<in>B. {(x, y)}) \<union> A = fold (\<lambda>y. Set.insert (x, y)) A B"
 proof -
-  interpret comp_fun_commute "\<lambda>y. Set.insert (x, y)" by standard auto
-  show ?thesis using assms  by (induct B arbitrary: A) simp_all
+  interpret comp_fun_commute "\<lambda>y. Set.insert (x, y)"
+    by standard auto
+  show ?thesis
+    using assms by (induct arbitrary: A) simp_all
 qed
 
-lemma comp_fun_commute_product_fold: 
-  assumes "finite B"
-  shows "comp_fun_commute (\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B)" 
-  by standard (auto simp: fold_union_pair[symmetric] assms)
+lemma comp_fun_commute_product_fold:
+  "finite B \<Longrightarrow> comp_fun_commute (\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B)"
+  by standard (auto simp: fold_union_pair [symmetric])
 
 lemma product_fold:
-  assumes "finite A"
-  assumes "finite B"
+  assumes "finite A" "finite B"
   shows "A \<times> B = fold (\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B) {} A"
-using assms unfolding Sigma_def 
-by (induct A) 
-  (simp_all add: comp_fun_commute.fold_insert[OF comp_fun_commute_product_fold] fold_union_pair)
-
+  using assms unfolding Sigma_def
+  by (induct A)
+    (simp_all add: comp_fun_commute.fold_insert[OF comp_fun_commute_product_fold] fold_union_pair)
 
 context complete_lattice
 begin
@@ -1073,61 +1137,55 @@
   assumes "finite A"
   shows "inf (Inf A) B = fold inf B A"
 proof -
-  interpret comp_fun_idem inf by (fact comp_fun_idem_inf)
-  from \<open>finite A\<close> fold_fun_left_comm show ?thesis by (induct A arbitrary: B)
-    (simp_all add: inf_commute fun_eq_iff)
+  interpret comp_fun_idem inf
+    by (fact comp_fun_idem_inf)
+  from \<open>finite A\<close> fold_fun_left_comm show ?thesis
+    by (induct A arbitrary: B) (simp_all add: inf_commute fun_eq_iff)
 qed
 
 lemma sup_Sup_fold_sup:
   assumes "finite A"
   shows "sup (Sup A) B = fold sup B A"
 proof -
-  interpret comp_fun_idem sup by (fact comp_fun_idem_sup)
-  from \<open>finite A\<close> fold_fun_left_comm show ?thesis by (induct A arbitrary: B)
-    (simp_all add: sup_commute fun_eq_iff)
+  interpret comp_fun_idem sup
+    by (fact comp_fun_idem_sup)
+  from \<open>finite A\<close> fold_fun_left_comm show ?thesis
+    by (induct A arbitrary: B) (simp_all add: sup_commute fun_eq_iff)
 qed
 
-lemma Inf_fold_inf:
-  assumes "finite A"
-  shows "Inf A = fold inf top A"
-  using assms inf_Inf_fold_inf [of A top] by (simp add: inf_absorb2)
+lemma Inf_fold_inf: "finite A \<Longrightarrow> Inf A = fold inf top A"
+  using inf_Inf_fold_inf [of A top] by (simp add: inf_absorb2)
 
-lemma Sup_fold_sup:
-  assumes "finite A"
-  shows "Sup A = fold sup bot A"
-  using assms sup_Sup_fold_sup [of A bot] by (simp add: sup_absorb2)
+lemma Sup_fold_sup: "finite A \<Longrightarrow> Sup A = fold sup bot A"
+  using sup_Sup_fold_sup [of A bot] by (simp add: sup_absorb2)
 
 lemma inf_INF_fold_inf:
   assumes "finite A"
-  shows "inf B (INFIMUM A f) = fold (inf \<circ> f) B A" (is "?inf = ?fold") 
-proof (rule sym)
+  shows "inf B (INFIMUM A f) = fold (inf \<circ> f) B A" (is "?inf = ?fold")
+proof -
   interpret comp_fun_idem inf by (fact comp_fun_idem_inf)
   interpret comp_fun_idem "inf \<circ> f" by (fact comp_comp_fun_idem)
-  from \<open>finite A\<close> show "?fold = ?inf"
-    by (induct A arbitrary: B)
-      (simp_all add: inf_left_commute)
+  from \<open>finite A\<close> have "?fold = ?inf"
+    by (induct A arbitrary: B) (simp_all add: inf_left_commute)
+  then show ?thesis ..
 qed
 
 lemma sup_SUP_fold_sup:
   assumes "finite A"
-  shows "sup B (SUPREMUM A f) = fold (sup \<circ> f) B A" (is "?sup = ?fold") 
-proof (rule sym)
+  shows "sup B (SUPREMUM A f) = fold (sup \<circ> f) B A" (is "?sup = ?fold")
+proof -
   interpret comp_fun_idem sup by (fact comp_fun_idem_sup)
   interpret comp_fun_idem "sup \<circ> f" by (fact comp_comp_fun_idem)
-  from \<open>finite A\<close> show "?fold = ?sup"
-    by (induct A arbitrary: B)
-      (simp_all add: sup_left_commute)
+  from \<open>finite A\<close> have "?fold = ?sup"
+    by (induct A arbitrary: B) (simp_all add: sup_left_commute)
+  then show ?thesis ..
 qed
 
-lemma INF_fold_inf:
-  assumes "finite A"
-  shows "INFIMUM A f = fold (inf \<circ> f) top A"
-  using assms inf_INF_fold_inf [of A top] by simp
+lemma INF_fold_inf: "finite A \<Longrightarrow> INFIMUM A f = fold (inf \<circ> f) top A"
+  using inf_INF_fold_inf [of A top] by simp
 
-lemma SUP_fold_sup:
-  assumes "finite A"
-  shows "SUPREMUM A f = fold (sup \<circ> f) bot A"
-  using assms sup_SUP_fold_sup [of A bot] by simp
+lemma SUP_fold_sup: "finite A \<Longrightarrow> SUPREMUM A f = fold (sup \<circ> f) bot A"
+  using sup_SUP_fold_sup [of A bot] by simp
 
 end
 
@@ -1146,15 +1204,14 @@
   by standard (insert comp_fun_commute, simp add: fun_eq_iff)
 
 definition F :: "'a set \<Rightarrow> 'b"
-where
-  eq_fold: "F A = fold f z A"
+  where eq_fold: "F A = fold f z A"
 
 lemma empty [simp]:"F {} = z"
   by (simp add: eq_fold)
 
 lemma infinite [simp]: "\<not> finite A \<Longrightarrow> F A = z"
   by (simp add: eq_fold)
- 
+
 lemma insert [simp]:
   assumes "finite A" and "x \<notin> A"
   shows "F (insert x A) = f x (F A)"
@@ -1163,7 +1220,7 @@
   have "fold f z (insert x A) = f x (fold f z A)" by simp
   with \<open>finite A\<close> show ?thesis by (simp add: eq_fold fun_eq_iff)
 qed
- 
+
 lemma remove:
   assumes "finite A" and "x \<in> A"
   shows "F A = f x (F (A - {x}))"
@@ -1174,10 +1231,8 @@
   ultimately show ?thesis by simp
 qed
 
-lemma insert_remove:
-  assumes "finite A"
-  shows "F (insert x A) = f x (F (A - {x}))"
-  using assms by (cases "x \<in> A") (simp_all add: remove insert_absorb)
+lemma insert_remove: "finite A \<Longrightarrow> F (insert x A) = f x (F (A - {x}))"
+  by (cases "x \<in> A") (simp_all add: remove insert_absorb)
 
 end
 
@@ -1209,7 +1264,7 @@
 
 text \<open>
   The traditional definition
-  @{prop "card A \<equiv> LEAST n. EX f. A = {f i | i. i < n}"}
+  @{prop "card A \<equiv> LEAST n. \<exists>f. A = {f i |i. i < n}"}
   is ugly to work with.
   But now that we have @{const fold} things are easy:
 \<close>
@@ -1218,60 +1273,49 @@
   defines card = "folding.F (\<lambda>_. Suc) 0"
   by standard rule
 
-lemma card_infinite:
-  "\<not> finite A \<Longrightarrow> card A = 0"
+lemma card_infinite: "\<not> finite A \<Longrightarrow> card A = 0"
   by (fact card.infinite)
 
-lemma card_empty:
-  "card {} = 0"
+lemma card_empty: "card {} = 0"
   by (fact card.empty)
 
-lemma card_insert_disjoint:
-  "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> card (insert x A) = Suc (card A)"
+lemma card_insert_disjoint: "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> card (insert x A) = Suc (card A)"
   by (fact card.insert)
 
-lemma card_insert_if:
-  "finite A \<Longrightarrow> card (insert x A) = (if x \<in> A then card A else Suc (card A))"
+lemma card_insert_if: "finite A \<Longrightarrow> card (insert x A) = (if x \<in> A then card A else Suc (card A))"
   by auto (simp add: card.insert_remove card.remove)
 
-lemma card_ge_0_finite:
-  "card A > 0 \<Longrightarrow> finite A"
+lemma card_ge_0_finite: "card A > 0 \<Longrightarrow> finite A"
   by (rule ccontr) simp
 
-lemma card_0_eq [simp]:
-  "finite A \<Longrightarrow> card A = 0 \<longleftrightarrow> A = {}"
+lemma card_0_eq [simp]: "finite A \<Longrightarrow> card A = 0 \<longleftrightarrow> A = {}"
   by (auto dest: mk_disjoint_insert)
 
-lemma finite_UNIV_card_ge_0:
-  "finite (UNIV :: 'a set) \<Longrightarrow> card (UNIV :: 'a set) > 0"
+lemma finite_UNIV_card_ge_0: "finite (UNIV :: 'a set) \<Longrightarrow> card (UNIV :: 'a set) > 0"
   by (rule ccontr) simp
 
-lemma card_eq_0_iff:
-  "card A = 0 \<longleftrightarrow> A = {} \<or> \<not> finite A"
+lemma card_eq_0_iff: "card A = 0 \<longleftrightarrow> A = {} \<or> \<not> finite A"
   by auto
 
-lemma card_range_greater_zero:
-  "finite (range f) \<Longrightarrow> card (range f) > 0"
+lemma card_range_greater_zero: "finite (range f) \<Longrightarrow> card (range f) > 0"
   by (rule ccontr) (simp add: card_eq_0_iff)
 
-lemma card_gt_0_iff:
-  "0 < card A \<longleftrightarrow> A \<noteq> {} \<and> finite A"
-  by (simp add: neq0_conv [symmetric] card_eq_0_iff) 
+lemma card_gt_0_iff: "0 < card A \<longleftrightarrow> A \<noteq> {} \<and> finite A"
+  by (simp add: neq0_conv [symmetric] card_eq_0_iff)
 
-lemma card_Suc_Diff1:
-  "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> Suc (card (A - {x})) = card A"
-apply(rule_tac t = A in insert_Diff [THEN subst], assumption)
-apply(simp del:insert_Diff_single)
-done
+lemma card_Suc_Diff1: "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> Suc (card (A - {x})) = card A"
+  apply (rule insert_Diff [THEN subst, where t = A])
+  apply assumption
+  apply (simp del: insert_Diff_single)
+  done
 
-lemma card_insert_le_m1: "n>0 \<Longrightarrow> card y \<le> n-1 \<Longrightarrow> card (insert x y) \<le> n"
+lemma card_insert_le_m1: "n > 0 \<Longrightarrow> card y \<le> n - 1 \<Longrightarrow> card (insert x y) \<le> n"
   apply (cases "finite y")
   apply (cases "x \<in> y")
   apply (auto simp: insert_absorb)
   done
 
-lemma card_Diff_singleton:
-  "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> card (A - {x}) = card A - 1"
+lemma card_Diff_singleton: "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> card (A - {x}) = card A - 1"
   by (simp add: card_Suc_Diff1 [symmetric])
 
 lemma card_Diff_singleton_if:
@@ -1282,124 +1326,137 @@
   assumes "finite A" and "a \<in> A" and "a \<notin> B"
   shows "card (A - insert a B) = card (A - B) - 1"
 proof -
-  have "A - insert a B = (A - B) - {a}" using assms by blast
-  then show ?thesis using assms by(simp add: card_Diff_singleton)
+  have "A - insert a B = (A - B) - {a}"
+    using assms by blast
+  then show ?thesis
+    using assms by (simp add: card_Diff_singleton)
 qed
 
-lemma card_insert: "finite A ==> card (insert x A) = Suc (card (A - {x}))"
+lemma card_insert: "finite A \<Longrightarrow> card (insert x A) = Suc (card (A - {x}))"
   by (fact card.insert_remove)
 
-lemma card_insert_le: "finite A ==> card A <= card (insert x A)"
-by (simp add: card_insert_if)
+lemma card_insert_le: "finite A \<Longrightarrow> card A \<le> card (insert x A)"
+  by (simp add: card_insert_if)
 
-lemma card_Collect_less_nat[simp]: "card{i::nat. i < n} = n"
-by (induct n) (simp_all add:less_Suc_eq Collect_disj_eq)
+lemma card_Collect_less_nat[simp]: "card {i::nat. i < n} = n"
+  by (induct n) (simp_all add:less_Suc_eq Collect_disj_eq)
 
-lemma card_Collect_le_nat[simp]: "card{i::nat. i <= n} = Suc n"
-using card_Collect_less_nat[of "Suc n"] by(simp add: less_Suc_eq_le)
+lemma card_Collect_le_nat[simp]: "card {i::nat. i \<le> n} = Suc n"
+  using card_Collect_less_nat[of "Suc n"] by (simp add: less_Suc_eq_le)
 
 lemma card_mono:
   assumes "finite B" and "A \<subseteq> B"
   shows "card A \<le> card B"
 proof -
-  from assms have "finite A" by (auto intro: finite_subset)
-  then show ?thesis using assms proof (induct A arbitrary: B)
-    case empty then show ?case by simp
+  from assms have "finite A"
+    by (auto intro: finite_subset)
+  then show ?thesis
+    using assms
+  proof (induct A arbitrary: B)
+    case empty
+    then show ?case by simp
   next
     case (insert x A)
-    then have "x \<in> B" by simp
-    from insert have "A \<subseteq> B - {x}" and "finite (B - {x})" by auto
-    with insert.hyps have "card A \<le> card (B - {x})" by auto
-    with \<open>finite A\<close> \<open>x \<notin> A\<close> \<open>finite B\<close> \<open>x \<in> B\<close> show ?case by simp (simp only: card.remove)
+    then have "x \<in> B"
+      by simp
+    from insert have "A \<subseteq> B - {x}" and "finite (B - {x})"
+      by auto
+    with insert.hyps have "card A \<le> card (B - {x})"
+      by auto
+    with \<open>finite A\<close> \<open>x \<notin> A\<close> \<open>finite B\<close> \<open>x \<in> B\<close> show ?case
+      by simp (simp only: card.remove)
   qed
 qed
 
-lemma card_seteq: "finite B ==> (!!A. A <= B ==> card B <= card A ==> A = B)"
-apply (induct rule: finite_induct)
-apply simp
-apply clarify
-apply (subgoal_tac "finite A & A - {x} <= F")
- prefer 2 apply (blast intro: finite_subset, atomize)
-apply (drule_tac x = "A - {x}" in spec)
-apply (simp add: card_Diff_singleton_if split add: if_split_asm)
-apply (case_tac "card A", auto)
-done
+lemma card_seteq: "finite B \<Longrightarrow> (\<And>A. A \<subseteq> B \<Longrightarrow> card B \<le> card A \<Longrightarrow> A = B)"
+  apply (induct rule: finite_induct)
+  apply simp
+  apply clarify
+  apply (subgoal_tac "finite A \<and> A - {x} \<subseteq> F")
+   prefer 2 apply (blast intro: finite_subset, atomize)
+  apply (drule_tac x = "A - {x}" in spec)
+  apply (simp add: card_Diff_singleton_if split add: if_split_asm)
+  apply (case_tac "card A", auto)
+  done
 
-lemma psubset_card_mono: "finite B ==> A < B ==> card A < card B"
-apply (simp add: psubset_eq linorder_not_le [symmetric])
-apply (blast dest: card_seteq)
-done
+lemma psubset_card_mono: "finite B \<Longrightarrow> A < B \<Longrightarrow> card A < card B"
+  apply (simp add: psubset_eq linorder_not_le [symmetric])
+  apply (blast dest: card_seteq)
+  done
 
 lemma card_Un_Int:
-  assumes "finite A" and "finite B"
+  assumes "finite A" "finite B"
   shows "card A + card B = card (A \<union> B) + card (A \<inter> B)"
-using assms proof (induct A)
-  case empty then show ?case by simp
+  using assms
+proof (induct A)
+  case empty
+  then show ?case by simp
 next
- case (insert x A) then show ?case
+  case insert
+  then show ?case
     by (auto simp add: insert_absorb Int_insert_left)
 qed
 
-lemma card_Un_disjoint:
-  assumes "finite A" and "finite B"
-  assumes "A \<inter> B = {}"
-  shows "card (A \<union> B) = card A + card B"
-using assms card_Un_Int [of A B] by simp
+lemma card_Un_disjoint: "finite A \<Longrightarrow> finite B \<Longrightarrow> A \<inter> B = {} \<Longrightarrow> card (A \<union> B) = card A + card B"
+  using card_Un_Int [of A B] by simp
 
 lemma card_Un_le: "card (A \<union> B) \<le> card A + card B"
-apply(cases "finite A")
- apply(cases "finite B")
-  using le_iff_add card_Un_Int apply blast
- apply simp
-apply simp
-done
+  apply (cases "finite A")
+   apply (cases "finite B")
+    using le_iff_add card_Un_Int apply blast
+   apply simp
+  apply simp
+  done
 
 lemma card_Diff_subset:
-  assumes "finite B" and "B \<subseteq> A"
+  assumes "finite B"
+    and "B \<subseteq> A"
   shows "card (A - B) = card A - card B"
 proof (cases "finite A")
-  case False with assms show ?thesis by simp
+  case False
+  with assms show ?thesis
+    by simp
 next
-  case True with assms show ?thesis by (induct B arbitrary: A) simp_all
+  case True
+  with assms show ?thesis
+    by (induct B arbitrary: A) simp_all
 qed
 
 lemma card_Diff_subset_Int:
-  assumes AB: "finite (A \<inter> B)" shows "card (A - B) = card A - card (A \<inter> B)"
+  assumes "finite (A \<inter> B)"
+  shows "card (A - B) = card A - card (A \<inter> B)"
 proof -
   have "A - B = A - A \<inter> B" by auto
-  thus ?thesis
-    by (simp add: card_Diff_subset AB) 
+  with assms show ?thesis
+    by (simp add: card_Diff_subset)
 qed
 
 lemma diff_card_le_card_Diff:
-assumes "finite B" shows "card A - card B \<le> card(A - B)"
-proof-
+  assumes "finite B"
+  shows "card A - card B \<le> card (A - B)"
+proof -
   have "card A - card B \<le> card A - card (A \<inter> B)"
     using card_mono[OF assms Int_lower2, of A] by arith
-  also have "\<dots> = card(A-B)" using assms by(simp add: card_Diff_subset_Int)
+  also have "\<dots> = card (A - B)"
+    using assms by (simp add: card_Diff_subset_Int)
   finally show ?thesis .
 qed
 
-lemma card_Diff1_less: "finite A ==> x: A ==> card (A - {x}) < card A"
-apply (rule Suc_less_SucD)
-apply (simp add: card_Suc_Diff1 del:card_Diff_insert)
-done
+lemma card_Diff1_less: "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> card (A - {x}) < card A"
+  by (rule Suc_less_SucD) (simp add: card_Suc_Diff1 del: card_Diff_insert)
 
-lemma card_Diff2_less:
-  "finite A ==> x: A ==> y: A ==> card (A - {x} - {y}) < card A"
-apply (case_tac "x = y")
- apply (simp add: card_Diff1_less del:card_Diff_insert)
-apply (rule less_trans)
- prefer 2 apply (auto intro!: card_Diff1_less simp del:card_Diff_insert)
-done
+lemma card_Diff2_less: "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> card (A - {x} - {y}) < card A"
+  apply (cases "x = y")
+   apply (simp add: card_Diff1_less del:card_Diff_insert)
+  apply (rule less_trans)
+   prefer 2 apply (auto intro!: card_Diff1_less simp del: card_Diff_insert)
+  done
 
-lemma card_Diff1_le: "finite A ==> card (A - {x}) <= card A"
-apply (case_tac "x : A")
- apply (simp_all add: card_Diff1_less less_imp_le)
-done
+lemma card_Diff1_le: "finite A \<Longrightarrow> card (A - {x}) \<le> card A"
+  by (cases "x \<in> A") (simp_all add: card_Diff1_less less_imp_le)
 
-lemma card_psubset: "finite B ==> A \<subseteq> B ==> card A < card B ==> A < B"
-by (erule psubsetI, blast)
+lemma card_psubset: "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> card A < card B \<Longrightarrow> A < B"
+  by (erule psubsetI) blast
 
 lemma card_le_inj:
   assumes fA: "finite A"
@@ -1413,7 +1470,7 @@
 next
   case (insert x s t)
   then show ?case
-  proof (induct rule: finite_induct[OF "insert.prems"(1)])
+  proof (induct rule: finite_induct [OF insert.prems(1)])
     case 1
     then show ?case by simp
   next
@@ -1454,41 +1511,43 @@
 qed
 
 lemma insert_partition:
-  "\<lbrakk> x \<notin> F; \<forall>c1 \<in> insert x F. \<forall>c2 \<in> insert x F. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {} \<rbrakk>
-  \<Longrightarrow> x \<inter> \<Union>F = {}"
-by auto
+  "x \<notin> F \<Longrightarrow> \<forall>c1 \<in> insert x F. \<forall>c2 \<in> insert x F. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {} \<Longrightarrow> x \<inter> \<Union>F = {}"
+  by auto
 
-lemma finite_psubset_induct[consumes 1, case_names psubset]:
-  assumes fin: "finite A" 
-  and     major: "\<And>A. finite A \<Longrightarrow> (\<And>B. B \<subset> A \<Longrightarrow> P B) \<Longrightarrow> P A" 
+lemma finite_psubset_induct [consumes 1, case_names psubset]:
+  assumes finite: "finite A"
+    and major: "\<And>A. finite A \<Longrightarrow> (\<And>B. B \<subset> A \<Longrightarrow> P B) \<Longrightarrow> P A"
   shows "P A"
-using fin
+  using finite
 proof (induct A taking: card rule: measure_induct_rule)
   case (less A)
   have fin: "finite A" by fact
-  have ih: "\<And>B. \<lbrakk>card B < card A; finite B\<rbrakk> \<Longrightarrow> P B" by fact
-  { fix B 
-    assume asm: "B \<subset> A"
-    from asm have "card B < card A" using psubset_card_mono fin by blast
+  have ih: "card B < card A \<Longrightarrow> finite B \<Longrightarrow> P B" for B by fact
+  have "P B" if "B \<subset> A" for B
+  proof -
+    from that have "card B < card A"
+      using psubset_card_mono fin by blast
     moreover
-    from asm have "B \<subseteq> A" by auto
-    then have "finite B" using fin finite_subset by blast
-    ultimately 
-    have "P B" using ih by simp
-  }
+    from that have "B \<subseteq> A"
+      by auto
+    then have "finite B"
+      using fin finite_subset by blast
+    ultimately show ?thesis using ih by simp
+  qed
   with fin show "P A" using major by blast
 qed
 
-lemma finite_induct_select[consumes 1, case_names empty select]:
+lemma finite_induct_select [consumes 1, case_names empty select]:
   assumes "finite S"
-  assumes "P {}"
-  assumes select: "\<And>T. T \<subset> S \<Longrightarrow> P T \<Longrightarrow> \<exists>s\<in>S - T. P (insert s T)"
+    and "P {}"
+    and select: "\<And>T. T \<subset> S \<Longrightarrow> P T \<Longrightarrow> \<exists>s\<in>S - T. P (insert s T)"
   shows "P S"
 proof -
   have "0 \<le> card S" by simp
   then have "\<exists>T \<subseteq> S. card T = card S \<and> P T"
   proof (induct rule: dec_induct)
-    case base with \<open>P {}\<close> show ?case
+    case base with \<open>P {}\<close>
+    show ?case
       by (intro exI[of _ "{}"]) auto
   next
     case (step n)
@@ -1506,24 +1565,27 @@
 qed
 
 lemma remove_induct [case_names empty infinite remove]:
-  assumes empty: "P ({} :: 'a set)" and infinite: "\<not>finite B \<Longrightarrow> P B"
-      and remove: "\<And>A. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P (A - {x})) \<Longrightarrow> P A"
+  assumes empty: "P ({} :: 'a set)"
+    and infinite: "\<not> finite B \<Longrightarrow> P B"
+    and remove: "\<And>A. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P (A - {x})) \<Longrightarrow> P A"
   shows "P B"
 proof (cases "finite B")
   assume "\<not>finite B"
-  thus ?thesis by (rule infinite)
+  then show ?thesis by (rule infinite)
 next
   define A where "A = B"
   assume "finite B"
-  hence "finite A" "A \<subseteq> B" by (simp_all add: A_def)
-  thus "P A"
-  proof (induction "card A" arbitrary: A)
+  then have "finite A" "A \<subseteq> B"
+    by (simp_all add: A_def)
+  then show "P A"
+  proof (induct "card A" arbitrary: A)
     case 0
-    hence "A = {}" by auto
+    then have "A = {}" by auto
     with empty show ?case by simp
   next
     case (Suc n A)
-    from \<open>A \<subseteq> B\<close> and \<open>finite B\<close> have "finite A" by (rule finite_subset)
+    from \<open>A \<subseteq> B\<close> and \<open>finite B\<close> have "finite A"
+      by (rule finite_subset)
     moreover from Suc.hyps have "A \<noteq> {}" by auto
     moreover note \<open>A \<subseteq> B\<close>
     moreover have "P (A - {x})" if x: "x \<in> A" for x
@@ -1533,92 +1595,99 @@
 qed
 
 lemma finite_remove_induct [consumes 1, case_names empty remove]:
-  assumes finite: "finite B" and empty: "P ({} :: 'a set)" 
-      and rm: "\<And>A. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P (A - {x})) \<Longrightarrow> P A"
+  fixes P :: "'a set \<Rightarrow> bool"
+  assumes finite: "finite B"
+    and empty: "P {}"
+    and rm: "\<And>A. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P (A - {x})) \<Longrightarrow> P A"
   defines "B' \<equiv> B"
-  shows   "P B'"
-  by (induction B' rule: remove_induct) (simp_all add: assms)
+  shows "P B'"
+  by (induct B' rule: remove_induct) (simp_all add: assms)
 
 
-text\<open>main cardinality theorem\<close>
+text \<open>Main cardinality theorem.\<close>
 lemma card_partition [rule_format]:
-  "finite C ==>
-     finite (\<Union>C) -->
-     (\<forall>c\<in>C. card c = k) -->
-     (\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 --> c1 \<inter> c2 = {}) -->
-     k * card(C) = card (\<Union>C)"
-apply (erule finite_induct, simp)
-apply (simp add: card_Un_disjoint insert_partition 
-       finite_subset [of _ "\<Union>(insert x F)"])
-done
+  "finite C \<Longrightarrow> finite (\<Union>C) \<Longrightarrow> (\<forall>c\<in>C. card c = k) \<Longrightarrow>
+    (\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}) \<Longrightarrow>
+    k * card C = card (\<Union>C)"
+  apply (induct rule: finite_induct)
+  apply simp
+  apply (simp add: card_Un_disjoint insert_partition finite_subset [of _ "\<Union>(insert x F)"])
+  done
 
 lemma card_eq_UNIV_imp_eq_UNIV:
   assumes fin: "finite (UNIV :: 'a set)"
-  and card: "card A = card (UNIV :: 'a set)"
+    and card: "card A = card (UNIV :: 'a set)"
   shows "A = (UNIV :: 'a set)"
 proof
   show "A \<subseteq> UNIV" by simp
   show "UNIV \<subseteq> A"
   proof
-    fix x
-    show "x \<in> A"
+    show "x \<in> A" for x
     proof (rule ccontr)
       assume "x \<notin> A"
       then have "A \<subset> UNIV" by auto
-      with fin have "card A < card (UNIV :: 'a set)" by (fact psubset_card_mono)
+      with fin have "card A < card (UNIV :: 'a set)"
+        by (fact psubset_card_mono)
       with card show False by simp
     qed
   qed
 qed
 
-text\<open>The form of a finite set of given cardinality\<close>
+text \<open>The form of a finite set of given cardinality\<close>
 
 lemma card_eq_SucD:
-assumes "card A = Suc k"
-shows "\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={})"
+  assumes "card A = Suc k"
+  shows "\<exists>b B. A = insert b B \<and> b \<notin> B \<and> card B = k \<and> (k = 0 \<longrightarrow> B = {})"
 proof -
-  have fin: "finite A" using assms by (auto intro: ccontr)
-  moreover have "card A \<noteq> 0" using assms by auto
-  ultimately obtain b where b: "b \<in> A" by auto
+  have fin: "finite A"
+    using assms by (auto intro: ccontr)
+  moreover have "card A \<noteq> 0"
+    using assms by auto
+  ultimately obtain b where b: "b \<in> A"
+    by auto
   show ?thesis
   proof (intro exI conjI)
-    show "A = insert b (A-{b})" using b by blast
-    show "b \<notin> A - {b}" by blast
+    show "A = insert b (A - {b})"
+      using b by blast
+    show "b \<notin> A - {b}"
+      by blast
     show "card (A - {b}) = k" and "k = 0 \<longrightarrow> A - {b} = {}"
       using assms b fin by(fastforce dest:mk_disjoint_insert)+
   qed
 qed
 
 lemma card_Suc_eq:
-  "(card A = Suc k) =
-   (\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={}))"
- apply(auto elim!: card_eq_SucD)
- apply(subst card.insert)
- apply(auto simp add: intro:ccontr)
- done
+  "card A = Suc k \<longleftrightarrow>
+    (\<exists>b B. A = insert b B \<and> b \<notin> B \<and> card B = k \<and> (k = 0 \<longrightarrow> B = {}))"
+  apply (auto elim!: card_eq_SucD)
+  apply (subst card.insert)
+  apply (auto simp add: intro:ccontr)
+  done
 
 lemma card_1_singletonE:
-    assumes "card A = 1" obtains x where "A = {x}"
+  assumes "card A = 1"
+  obtains x where "A = {x}"
   using assms by (auto simp: card_Suc_eq)
 
 lemma is_singleton_altdef: "is_singleton A \<longleftrightarrow> card A = 1"
   unfolding is_singleton_def
   by (auto elim!: card_1_singletonE is_singletonE simp del: One_nat_def)
 
-lemma card_le_Suc_iff: "finite A \<Longrightarrow>
-  Suc n \<le> card A = (\<exists>a B. A = insert a B \<and> a \<notin> B \<and> n \<le> card B \<and> finite B)"
-by (fastforce simp: card_Suc_eq less_eq_nat.simps(2) insert_eq_iff
-  dest: subset_singletonD split: nat.splits if_splits)
+lemma card_le_Suc_iff:
+  "finite A \<Longrightarrow> Suc n \<le> card A = (\<exists>a B. A = insert a B \<and> a \<notin> B \<and> n \<le> card B \<and> finite B)"
+  by (fastforce simp: card_Suc_eq less_eq_nat.simps(2) insert_eq_iff
+    dest: subset_singletonD split: nat.splits if_splits)
 
 lemma finite_fun_UNIVD2:
   assumes fin: "finite (UNIV :: ('a \<Rightarrow> 'b) set)"
   shows "finite (UNIV :: 'b set)"
 proof -
-  from fin have "\<And>arbitrary. finite (range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary))"
+  from fin have "finite (range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary))" for arbitrary
     by (rule finite_imageI)
-  moreover have "\<And>arbitrary. UNIV = range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary)"
+  moreover have "UNIV = range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary)" for arbitrary
     by (rule UNIV_eq_I) auto
-  ultimately show "finite (UNIV :: 'b set)" by simp
+  ultimately show "finite (UNIV :: 'b set)"
+    by simp
 qed
 
 lemma card_UNIV_unit [simp]: "card (UNIV :: unit set) = 1"
@@ -1628,164 +1697,176 @@
   assumes "\<not> finite A"
   shows "\<exists>B. finite B \<and> card B = n \<and> B \<subseteq> A"
 proof (induction n)
-  case 0 show ?case by (intro exI[of _ "{}"]) auto
-next 
+  case 0
+  show ?case by (intro exI[of _ "{}"]) auto
+next
   case (Suc n)
-  then guess B .. note B = this
+  then obtain B where B: "finite B \<and> card B = n \<and> B \<subseteq> A" ..
   with \<open>\<not> finite A\<close> have "A \<noteq> B" by auto
   with B have "B \<subset> A" by auto
-  hence "\<exists>x. x \<in> A - B" by (elim psubset_imp_ex_mem)
-  then guess x .. note x = this
+  then have "\<exists>x. x \<in> A - B"
+    by (elim psubset_imp_ex_mem)
+  then obtain x where x: "x \<in> A - B" ..
   with B have "finite (insert x B) \<and> card (insert x B) = Suc n \<and> insert x B \<subseteq> A"
     by auto
-  thus "\<exists>B. finite B \<and> card B = Suc n \<and> B \<subseteq> A" ..
+  then show "\<exists>B. finite B \<and> card B = Suc n \<and> B \<subseteq> A" ..
 qed
 
+
 subsubsection \<open>Cardinality of image\<close>
 
-lemma card_image_le: "finite A ==> card (f ` A) \<le> card A"
+lemma card_image_le: "finite A \<Longrightarrow> card (f ` A) \<le> card A"
   by (induct rule: finite_induct) (simp_all add: le_SucI card_insert_if)
 
 lemma card_image:
   assumes "inj_on f A"
   shows "card (f ` A) = card A"
 proof (cases "finite A")
-  case True then show ?thesis using assms by (induct A) simp_all
+  case True
+  then show ?thesis
+    using assms by (induct A) simp_all
 next
-  case False then have "\<not> finite (f ` A)" using assms by (auto dest: finite_imageD)
-  with False show ?thesis by simp
+  case False
+  then have "\<not> finite (f ` A)"
+    using assms by (auto dest: finite_imageD)
+  with False show ?thesis
+    by simp
 qed
 
 lemma bij_betw_same_card: "bij_betw f A B \<Longrightarrow> card A = card B"
-by(auto simp: card_image bij_betw_def)
+  by(auto simp: card_image bij_betw_def)
 
-lemma endo_inj_surj: "finite A ==> f ` A \<subseteq> A ==> inj_on f A ==> f ` A = A"
-by (simp add: card_seteq card_image)
+lemma endo_inj_surj: "finite A \<Longrightarrow> f ` A \<subseteq> A \<Longrightarrow> inj_on f A \<Longrightarrow> f ` A = A"
+  by (simp add: card_seteq card_image)
 
 lemma eq_card_imp_inj_on:
-  assumes "finite A" "card(f ` A) = card A" shows "inj_on f A"
-using assms
+  assumes "finite A" "card(f ` A) = card A"
+  shows "inj_on f A"
+  using assms
 proof (induct rule:finite_induct)
-  case empty show ?case by simp
+  case empty
+  show ?case by simp
 next
   case (insert x A)
-  then show ?case using card_image_le [of A f]
-    by (simp add: card_insert_if split: if_splits)
+  then show ?case
+    using card_image_le [of A f] by (simp add: card_insert_if split: if_splits)
 qed
 
-lemma inj_on_iff_eq_card: "finite A \<Longrightarrow> inj_on f A \<longleftrightarrow> card(f ` A) = card A"
+lemma inj_on_iff_eq_card: "finite A \<Longrightarrow> inj_on f A \<longleftrightarrow> card (f ` A) = card A"
   by (blast intro: card_image eq_card_imp_inj_on)
 
 lemma card_inj_on_le:
-  assumes "inj_on f A" "f ` A \<subseteq> B" "finite B" shows "card A \<le> card B"
+  assumes "inj_on f A" "f ` A \<subseteq> B" "finite B"
+  shows "card A \<le> card B"
 proof -
-  have "finite A" using assms
-    by (blast intro: finite_imageD dest: finite_subset)
-  then show ?thesis using assms 
-   by (force intro: card_mono simp: card_image [symmetric])
+  have "finite A"
+    using assms by (blast intro: finite_imageD dest: finite_subset)
+  then show ?thesis
+    using assms by (force intro: card_mono simp: card_image [symmetric])
 qed
 
 lemma surj_card_le: "finite A \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> card B \<le> card A"
   by (blast intro: card_image_le card_mono le_trans)
 
 lemma card_bij_eq:
-  "[|inj_on f A; f ` A \<subseteq> B; inj_on g B; g ` B \<subseteq> A;
-     finite A; finite B |] ==> card A = card B"
-by (auto intro: le_antisym card_inj_on_le)
+  "inj_on f A \<Longrightarrow> f ` A \<subseteq> B \<Longrightarrow> inj_on g B \<Longrightarrow> g ` B \<subseteq> A \<Longrightarrow> finite A \<Longrightarrow> finite B
+    \<Longrightarrow> card A = card B"
+  by (auto intro: le_antisym card_inj_on_le)
+
+lemma bij_betw_finite: "bij_betw f A B \<Longrightarrow> finite A \<longleftrightarrow> finite B"
+  unfolding bij_betw_def using finite_imageD [of f A] by auto
 
-lemma bij_betw_finite:
-  assumes "bij_betw f A B"
-  shows "finite A \<longleftrightarrow> finite B"
-using assms unfolding bij_betw_def
-using finite_imageD[of f A] by auto
+lemma inj_on_finite: "inj_on f A \<Longrightarrow> f ` A \<le> B \<Longrightarrow> finite B \<Longrightarrow> finite A"
+  using finite_imageD finite_subset by blast
 
-lemma inj_on_finite:
-assumes "inj_on f A" "f ` A \<le> B" "finite B"
-shows "finite A"
-using assms finite_imageD finite_subset by blast
+lemma card_vimage_inj: "inj f \<Longrightarrow> A \<subseteq> range f \<Longrightarrow> card (f -` A) = card A"
+  by (auto 4 3 simp: subset_image_iff inj_vimage_image_eq
+      intro: card_image[symmetric, OF subset_inj_on])
 
-lemma card_vimage_inj: "\<lbrakk> inj f; A \<subseteq> range f \<rbrakk> \<Longrightarrow> card (f -` A) = card A"
-by(auto 4 3 simp add: subset_image_iff inj_vimage_image_eq intro: card_image[symmetric, OF subset_inj_on])
 
 subsubsection \<open>Pigeonhole Principles\<close>
 
-lemma pigeonhole: "card A > card(f ` A) \<Longrightarrow> ~ inj_on f A "
-by (auto dest: card_image less_irrefl_nat)
+lemma pigeonhole: "card A > card (f ` A) \<Longrightarrow> \<not> inj_on f A "
+  by (auto dest: card_image less_irrefl_nat)
 
 lemma pigeonhole_infinite:
-assumes  "~ finite A" and "finite(f`A)"
-shows "EX a0:A. ~finite{a:A. f a = f a0}"
-proof -
-  have "finite(f`A) \<Longrightarrow> ~ finite A \<Longrightarrow> EX a0:A. ~finite{a:A. f a = f a0}"
-  proof(induct "f`A" arbitrary: A rule: finite_induct)
-    case empty thus ?case by simp
+  assumes "\<not> finite A" and "finite (f`A)"
+  shows "\<exists>a0\<in>A. \<not> finite {a\<in>A. f a = f a0}"
+  using assms(2,1)
+proof (induct "f`A" arbitrary: A rule: finite_induct)
+  case empty
+  then show ?case by simp
+next
+  case (insert b F)
+  show ?case
+  proof (cases "finite {a\<in>A. f a = b}")
+    case True
+    with \<open>\<not> finite A\<close> have "\<not> finite (A - {a\<in>A. f a = b})"
+      by simp
+    also have "A - {a\<in>A. f a = b} = {a\<in>A. f a \<noteq> b}"
+      by blast
+    finally have "\<not> finite {a\<in>A. f a \<noteq> b}" .
+    from insert(3)[OF _ this] insert(2,4) show ?thesis
+      by simp (blast intro: rev_finite_subset)
   next
-    case (insert b F)
-    show ?case
-    proof cases
-      assume "finite{a:A. f a = b}"
-      hence "~ finite(A - {a:A. f a = b})" using \<open>\<not> finite A\<close> by simp
-      also have "A - {a:A. f a = b} = {a:A. f a \<noteq> b}" by blast
-      finally have "~ finite({a:A. f a \<noteq> b})" .
-      from insert(3)[OF _ this]
-      show ?thesis using insert(2,4) by simp (blast intro: rev_finite_subset)
-    next
-      assume 1: "~finite{a:A. f a = b}"
-      hence "{a \<in> A. f a = b} \<noteq> {}" by force
-      thus ?thesis using 1 by blast
-    qed
+    case False
+    then have "{a \<in> A. f a = b} \<noteq> {}" by force
+    with False show ?thesis by blast
   qed
-  from this[OF assms(2,1)] show ?thesis .
 qed
 
 lemma pigeonhole_infinite_rel:
-assumes "~finite A" and "finite B" and "ALL a:A. EX b:B. R a b"
-shows "EX b:B. ~finite{a:A. R a b}"
+  assumes "\<not> finite A"
+    and "finite B"
+    and "\<forall>a\<in>A. \<exists>b\<in>B. R a b"
+  shows "\<exists>b\<in>B. \<not> finite {a:A. R a b}"
 proof -
-   let ?F = "%a. {b:B. R a b}"
-   from finite_Pow_iff[THEN iffD2, OF \<open>finite B\<close>]
-   have "finite(?F ` A)" by(blast intro: rev_finite_subset)
-   from pigeonhole_infinite[where f = ?F, OF assms(1) this]
-   obtain a0 where "a0\<in>A" and 1: "\<not> finite {a\<in>A. ?F a = ?F a0}" ..
-   obtain b0 where "b0 : B" and "R a0 b0" using \<open>a0:A\<close> assms(3) by blast
-   { assume "finite{a:A. R a b0}"
-     then have "finite {a\<in>A. ?F a = ?F a0}"
-       using \<open>b0 : B\<close> \<open>R a0 b0\<close> by(blast intro: rev_finite_subset)
-   }
-   with 1 \<open>b0 : B\<close> show ?thesis by blast
+  let ?F = "\<lambda>a. {b\<in>B. R a b}"
+  from finite_Pow_iff[THEN iffD2, OF \<open>finite B\<close>] have "finite (?F ` A)"
+    by (blast intro: rev_finite_subset)
+  from pigeonhole_infinite [where f = ?F, OF assms(1) this]
+  obtain a0 where "a0 \<in> A" and 1: "\<not> finite {a\<in>A. ?F a = ?F a0}" ..
+  obtain b0 where "b0 \<in> B" and "R a0 b0"
+    using \<open>a0 \<in> A\<close> assms(3) by blast
+  have "finite {a\<in>A. ?F a = ?F a0}" if "finite{a:A. R a b0}"
+    using \<open>b0 \<in> B\<close> \<open>R a0 b0\<close> that by (blast intro: rev_finite_subset)
+  with 1 \<open>b0 : B\<close> show ?thesis
+    by blast
 qed
 
 
 subsubsection \<open>Cardinality of sums\<close>
 
 lemma card_Plus:
-  assumes "finite A" and "finite B"
+  assumes "finite A" "finite B"
   shows "card (A <+> B) = card A + card B"
 proof -
   have "Inl`A \<inter> Inr`B = {}" by fast
   with assms show ?thesis
-    unfolding Plus_def
-    by (simp add: card_Un_disjoint card_image)
+    by (simp add: Plus_def card_Un_disjoint card_image)
 qed
 
 lemma card_Plus_conv_if:
   "card (A <+> B) = (if finite A \<and> finite B then card A + card B else 0)"
   by (auto simp add: card_Plus)
 
-text \<open>Relates to equivalence classes.  Based on a theorem of F. Kamm\"uller.\<close>
+text \<open>Relates to equivalence classes.  Based on a theorem of F. Kammüller.\<close>
 
 lemma dvd_partition:
-  assumes f: "finite (\<Union>C)" and "\<forall>c\<in>C. k dvd card c" "\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}"
-    shows "k dvd card (\<Union>C)"
+  assumes f: "finite (\<Union>C)"
+    and "\<forall>c\<in>C. k dvd card c" "\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}"
+  shows "k dvd card (\<Union>C)"
 proof -
-  have "finite C" 
+  have "finite C"
     by (rule finite_UnionD [OF f])
-  then show ?thesis using assms
+  then show ?thesis
+    using assms
   proof (induct rule: finite_induct)
-    case empty show ?case by simp
+    case empty
+    show ?case by simp
   next
-    case (insert c C)
-    then show ?case 
+    case insert
+    then show ?case
       apply simp
       apply (subst card_Un_disjoint)
       apply (auto simp add: disjoint_eq_subset_Compl)
@@ -1793,34 +1874,33 @@
   qed
 qed
 
+
 subsubsection \<open>Relating injectivity and surjectivity\<close>
 
-lemma finite_surj_inj: assumes "finite A" "A \<subseteq> f ` A" shows "inj_on f A"
+lemma finite_surj_inj:
+  assumes "finite A" "A \<subseteq> f ` A"
+  shows "inj_on f A"
 proof -
-  have "f ` A = A" 
+  have "f ` A = A"
     by (rule card_seteq [THEN sym]) (auto simp add: assms card_image_le)
   then show ?thesis using assms
     by (simp add: eq_card_imp_inj_on)
 qed
 
-lemma finite_UNIV_surj_inj: fixes f :: "'a \<Rightarrow> 'a"
-shows "finite(UNIV:: 'a set) \<Longrightarrow> surj f \<Longrightarrow> inj f"
-by (blast intro: finite_surj_inj subset_UNIV)
+lemma finite_UNIV_surj_inj: "finite(UNIV:: 'a set) \<Longrightarrow> surj f \<Longrightarrow> inj f" for f :: "'a \<Rightarrow> 'a"
+  by (blast intro: finite_surj_inj subset_UNIV)
 
-lemma finite_UNIV_inj_surj: fixes f :: "'a \<Rightarrow> 'a"
-shows "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f"
-by(fastforce simp:surj_def dest!: endo_inj_surj)
+lemma finite_UNIV_inj_surj: "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f" for f :: "'a \<Rightarrow> 'a"
+  by (fastforce simp:surj_def dest!: endo_inj_surj)
 
-corollary infinite_UNIV_nat [iff]:
-  "\<not> finite (UNIV :: nat set)"
+corollary infinite_UNIV_nat [iff]: "\<not> finite (UNIV :: nat set)"
 proof
   assume "finite (UNIV :: nat set)"
-  with finite_UNIV_inj_surj [of Suc]
-  show False by simp (blast dest: Suc_neq_Zero surjD)
+  with finite_UNIV_inj_surj [of Suc] show False
+    by simp (blast dest: Suc_neq_Zero surjD)
 qed
 
-lemma infinite_UNIV_char_0:
-  "\<not> finite (UNIV :: 'a::semiring_char_0 set)"
+lemma infinite_UNIV_char_0: "\<not> finite (UNIV :: 'a::semiring_char_0 set)"
 proof
   assume "finite (UNIV :: 'a set)"
   with subset_UNIV have "finite (range of_nat :: 'a set)"
@@ -1836,7 +1916,7 @@
 hide_const (open) Finite_Set.fold
 
 
-subsection "Infinite Sets"
+subsection \<open>Infinite Sets\<close>
 
 text \<open>
   Some elementary facts about infinite sets, mostly by Stephan Merz.
@@ -1859,19 +1939,18 @@
   by simp
 
 lemma Diff_infinite_finite:
-  assumes T: "finite T" and S: "infinite S"
+  assumes "finite T" "infinite S"
   shows "infinite (S - T)"
-  using T
+  using \<open>finite T\<close>
 proof induct
-  from S
-  show "infinite (S - {})" by auto
+  from \<open>infinite S\<close> show "infinite (S - {})"
+    by auto
 next
   fix T x
   assume ih: "infinite (S - T)"
   have "S - (insert x T) = (S - T) - {x}"
     by (rule Diff_insert)
-  with ih
-  show "infinite (S - (insert x T))"
+  with ih show "infinite (S - (insert x T))"
     by (simp add: infinite_remove)
 qed
 
@@ -1882,21 +1961,23 @@
   by simp
 
 lemma infinite_super:
-  assumes T: "S \<subseteq> T" and S: "infinite S"
+  assumes "S \<subseteq> T"
+    and "infinite S"
   shows "infinite T"
 proof
   assume "finite T"
-  with T have "finite S" by (simp add: finite_subset)
-  with S show False by simp
+  with \<open>S \<subseteq> T\<close> have "finite S" by (simp add: finite_subset)
+  with \<open>infinite S\<close> show False by simp
 qed
 
 proposition infinite_coinduct [consumes 1, case_names infinite]:
   assumes "X A"
-  and step: "\<And>A. X A \<Longrightarrow> \<exists>x\<in>A. X (A - {x}) \<or> infinite (A - {x})"
+    and step: "\<And>A. X A \<Longrightarrow> \<exists>x\<in>A. X (A - {x}) \<or> infinite (A - {x})"
   shows "infinite A"
 proof
   assume "finite A"
-  then show False using \<open>X A\<close>
+  then show False
+    using \<open>X A\<close>
   proof (induction rule: finite_psubset_induct)
     case (psubset A)
     then obtain x where "x \<in> A" "X (A - {x}) \<or> infinite (A - {x})"
@@ -1906,7 +1987,8 @@
     show False
       apply (rule psubset.IH [where B = "A - {x}"])
       using \<open>x \<in> A\<close> apply blast
-      by (simp add: \<open>X (A - {x})\<close>)
+      apply (simp add: \<open>X (A - {x})\<close>)
+      done
   qed
 qed
 
@@ -1918,14 +2000,14 @@
 \<close>
 
 lemma inf_img_fin_dom':
-  assumes img: "finite (f ` A)" and dom: "infinite A"
+  assumes img: "finite (f ` A)"
+    and dom: "infinite A"
   shows "\<exists>y \<in> f ` A. infinite (f -` {y} \<inter> A)"
 proof (rule ccontr)
   have "A \<subseteq> (\<Union>y\<in>f ` A. f -` {y} \<inter> A)" by auto
-  moreover
-  assume "\<not> ?thesis"
+  moreover assume "\<not> ?thesis"
   with img have "finite (\<Union>y\<in>f ` A. f -` {y} \<inter> A)" by blast
-  ultimately have "finite A" by(rule finite_subset)
+  ultimately have "finite A" by (rule finite_subset)
   with dom show False by contradiction
 qed
 
@@ -1937,16 +2019,15 @@
 lemma inf_img_fin_dom:
   assumes img: "finite (f`A)" and dom: "infinite A"
   shows "\<exists>y \<in> f`A. infinite (f -` {y})"
-using inf_img_fin_dom'[OF assms] by auto
+  using inf_img_fin_dom'[OF assms] by auto
 
 lemma inf_img_fin_domE:
   assumes "finite (f`A)" and "infinite A"
   obtains y where "y \<in> f`A" and "infinite (f -` {y})"
   using assms by (blast dest: inf_img_fin_dom)
 
-proposition finite_image_absD:
-    fixes S :: "'a::linordered_ring set"
-    shows "finite (abs ` S) \<Longrightarrow> finite S"
+proposition finite_image_absD: "finite (abs ` S) \<Longrightarrow> finite S"
+  for S :: "'a::linordered_ring set"
   by (rule ccontr) (auto simp: abs_eq_iff vimage_def dest: inf_img_fin_dom)
 
 end
--- a/src/HOL/Relation.thy	Wed Jul 06 13:45:52 2016 +0200
+++ b/src/HOL/Relation.thy	Wed Jul 06 22:52:10 2016 +0200
@@ -14,7 +14,7 @@
 declare predicate1D [Pure.dest, dest]
 declare predicate2I [Pure.intro!, intro!]
 declare predicate2D [Pure.dest, dest]
-declare bot1E [elim!] 
+declare bot1E [elim!]
 declare bot2E [elim!]
 declare top1I [intro!]
 declare top2I [intro!]
@@ -56,15 +56,16 @@
 
 subsubsection \<open>Relations as sets of pairs\<close>
 
-type_synonym 'a rel = "('a * 'a) set"
+type_synonym 'a rel = "('a \<times> 'a) set"
 
-lemma subrelI: \<comment> \<open>Version of @{thm [source] subsetI} for binary relations\<close>
-  "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (x, y) \<in> s) \<Longrightarrow> r \<subseteq> s"
+lemma subrelI: "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (x, y) \<in> s) \<Longrightarrow> r \<subseteq> s"
+  \<comment> \<open>Version of @{thm [source] subsetI} for binary relations\<close>
   by auto
 
-lemma lfp_induct2: \<comment> \<open>Version of @{thm [source] lfp_induct} for binary relations\<close>
+lemma lfp_induct2:
   "(a, b) \<in> lfp f \<Longrightarrow> mono f \<Longrightarrow>
     (\<And>a b. (a, b) \<in> f (lfp f \<inter> {(x, y). P x y}) \<Longrightarrow> P a b) \<Longrightarrow> P a b"
+  \<comment> \<open>Version of @{thm [source] lfp_induct} for binary relations\<close>
   using lfp_induct_set [of "(a, b)" f "case_prod P"] by auto
 
 
@@ -148,35 +149,30 @@
 subsubsection \<open>Reflexivity\<close>
 
 definition refl_on :: "'a set \<Rightarrow> 'a rel \<Rightarrow> bool"
-where
-  "refl_on A r \<longleftrightarrow> r \<subseteq> A \<times> A \<and> (\<forall>x\<in>A. (x, x) \<in> r)"
+  where "refl_on A r \<longleftrightarrow> r \<subseteq> A \<times> A \<and> (\<forall>x\<in>A. (x, x) \<in> r)"
 
-abbreviation refl :: "'a rel \<Rightarrow> bool"
-where \<comment> \<open>reflexivity over a type\<close>
-  "refl \<equiv> refl_on UNIV"
+abbreviation refl :: "'a rel \<Rightarrow> bool" \<comment> \<open>reflexivity over a type\<close>
+  where "refl \<equiv> refl_on UNIV"
 
 definition reflp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
-where
-  "reflp r \<longleftrightarrow> (\<forall>x. r x x)"
+  where "reflp r \<longleftrightarrow> (\<forall>x. r x x)"
 
-lemma reflp_refl_eq [pred_set_conv]:
-  "reflp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> refl r" 
+lemma reflp_refl_eq [pred_set_conv]: "reflp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> refl r"
   by (simp add: refl_on_def reflp_def)
 
-lemma refl_onI [intro?]: "r \<subseteq> A \<times> A ==> (!!x. x : A ==> (x, x) : r) ==> refl_on A r"
-  by (unfold refl_on_def) (iprover intro!: ballI)
+lemma refl_onI [intro?]: "r \<subseteq> A \<times> A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> (x, x) \<in> r) \<Longrightarrow> refl_on A r"
+  unfolding refl_on_def by (iprover intro!: ballI)
 
-lemma refl_onD: "refl_on A r ==> a : A ==> (a, a) : r"
-  by (unfold refl_on_def) blast
+lemma refl_onD: "refl_on A r \<Longrightarrow> a \<in> A \<Longrightarrow> (a, a) \<in> r"
+  unfolding refl_on_def by blast
 
-lemma refl_onD1: "refl_on A r ==> (x, y) : r ==> x : A"
-  by (unfold refl_on_def) blast
+lemma refl_onD1: "refl_on A r \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> x \<in> A"
+  unfolding refl_on_def by blast
 
-lemma refl_onD2: "refl_on A r ==> (x, y) : r ==> y : A"
-  by (unfold refl_on_def) blast
+lemma refl_onD2: "refl_on A r \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> y \<in> A"
+  unfolding refl_on_def by blast
 
-lemma reflpI [intro?]:
-  "(\<And>x. r x x) \<Longrightarrow> reflp r"
+lemma reflpI [intro?]: "(\<And>x. r x x) \<Longrightarrow> reflp r"
   by (auto intro: refl_onI simp add: reflp_def)
 
 lemma reflpE:
@@ -189,104 +185,86 @@
   shows "r x x"
   using assms by (auto elim: reflpE)
 
-lemma refl_on_Int: "refl_on A r ==> refl_on B s ==> refl_on (A \<inter> B) (r \<inter> s)"
-  by (unfold refl_on_def) blast
+lemma refl_on_Int: "refl_on A r \<Longrightarrow> refl_on B s \<Longrightarrow> refl_on (A \<inter> B) (r \<inter> s)"
+  unfolding refl_on_def by blast
 
-lemma reflp_inf:
-  "reflp r \<Longrightarrow> reflp s \<Longrightarrow> reflp (r \<sqinter> s)"
+lemma reflp_inf: "reflp r \<Longrightarrow> reflp s \<Longrightarrow> reflp (r \<sqinter> s)"
   by (auto intro: reflpI elim: reflpE)
 
-lemma refl_on_Un: "refl_on A r ==> refl_on B s ==> refl_on (A \<union> B) (r \<union> s)"
-  by (unfold refl_on_def) blast
+lemma refl_on_Un: "refl_on A r \<Longrightarrow> refl_on B s \<Longrightarrow> refl_on (A \<union> B) (r \<union> s)"
+  unfolding refl_on_def by blast
 
-lemma reflp_sup:
-  "reflp r \<Longrightarrow> reflp s \<Longrightarrow> reflp (r \<squnion> s)"
+lemma reflp_sup: "reflp r \<Longrightarrow> reflp s \<Longrightarrow> reflp (r \<squnion> s)"
   by (auto intro: reflpI elim: reflpE)
 
-lemma refl_on_INTER:
-  "ALL x:S. refl_on (A x) (r x) ==> refl_on (INTER S A) (INTER S r)"
-  by (unfold refl_on_def) fast
+lemma refl_on_INTER: "\<forall>x\<in>S. refl_on (A x) (r x) \<Longrightarrow> refl_on (INTER S A) (INTER S r)"
+  unfolding refl_on_def by fast
 
-lemma refl_on_UNION:
-  "ALL x:S. refl_on (A x) (r x) \<Longrightarrow> refl_on (UNION S A) (UNION S r)"
-  by (unfold refl_on_def) blast
+lemma refl_on_UNION: "\<forall>x\<in>S. refl_on (A x) (r x) \<Longrightarrow> refl_on (UNION S A) (UNION S r)"
+  unfolding refl_on_def by blast
 
 lemma refl_on_empty [simp]: "refl_on {} {}"
-  by (simp add:refl_on_def)
+  by (simp add: refl_on_def)
 
 lemma refl_on_def' [nitpick_unfold, code]:
   "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)"
   by (auto intro: refl_onI dest: refl_onD refl_onD1 refl_onD2)
 
 lemma reflp_equality [simp]: "reflp op ="
-by(simp add: reflp_def)
+  by (simp add: reflp_def)
 
-lemma reflp_mono: "\<lbrakk> reflp R; \<And>x y. R x y \<longrightarrow> Q x y \<rbrakk> \<Longrightarrow> reflp Q"
-by(auto intro: reflpI dest: reflpD)
+lemma reflp_mono: "reflp R \<Longrightarrow> (\<And>x y. R x y \<longrightarrow> Q x y) \<Longrightarrow> reflp Q"
+  by (auto intro: reflpI dest: reflpD)
 
 
 subsubsection \<open>Irreflexivity\<close>
 
 definition irrefl :: "'a rel \<Rightarrow> bool"
-where
-  "irrefl r \<longleftrightarrow> (\<forall>a. (a, a) \<notin> r)"
+  where "irrefl r \<longleftrightarrow> (\<forall>a. (a, a) \<notin> r)"
 
 definition irreflp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
-where
-  "irreflp R \<longleftrightarrow> (\<forall>a. \<not> R a a)"
+  where "irreflp R \<longleftrightarrow> (\<forall>a. \<not> R a a)"
 
-lemma irreflp_irrefl_eq [pred_set_conv]:
-  "irreflp (\<lambda>a b. (a, b) \<in> R) \<longleftrightarrow> irrefl R" 
+lemma irreflp_irrefl_eq [pred_set_conv]: "irreflp (\<lambda>a b. (a, b) \<in> R) \<longleftrightarrow> irrefl R"
   by (simp add: irrefl_def irreflp_def)
 
-lemma irreflI [intro?]:
-  "(\<And>a. (a, a) \<notin> R) \<Longrightarrow> irrefl R"
+lemma irreflI [intro?]: "(\<And>a. (a, a) \<notin> R) \<Longrightarrow> irrefl R"
   by (simp add: irrefl_def)
 
-lemma irreflpI [intro?]:
-  "(\<And>a. \<not> R a a) \<Longrightarrow> irreflp R"
+lemma irreflpI [intro?]: "(\<And>a. \<not> R a a) \<Longrightarrow> irreflp R"
   by (fact irreflI [to_pred])
 
-lemma irrefl_distinct [code]:
-  "irrefl r \<longleftrightarrow> (\<forall>(a, b) \<in> r. a \<noteq> b)"
+lemma irrefl_distinct [code]: "irrefl r \<longleftrightarrow> (\<forall>(a, b) \<in> r. a \<noteq> b)"
   by (auto simp add: irrefl_def)
 
 
 subsubsection \<open>Asymmetry\<close>
 
 inductive asym :: "'a rel \<Rightarrow> bool"
-where
-  asymI: "irrefl R \<Longrightarrow> (\<And>a b. (a, b) \<in> R \<Longrightarrow> (b, a) \<notin> R) \<Longrightarrow> asym R"
+  where asymI: "irrefl R \<Longrightarrow> (\<And>a b. (a, b) \<in> R \<Longrightarrow> (b, a) \<notin> R) \<Longrightarrow> asym R"
 
 inductive asymp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
-where
-  asympI: "irreflp R \<Longrightarrow> (\<And>a b. R a b \<Longrightarrow> \<not> R b a) \<Longrightarrow> asymp R"
+  where asympI: "irreflp R \<Longrightarrow> (\<And>a b. R a b \<Longrightarrow> \<not> R b a) \<Longrightarrow> asymp R"
 
-lemma asymp_asym_eq [pred_set_conv]:
-  "asymp (\<lambda>a b. (a, b) \<in> R) \<longleftrightarrow> asym R" 
+lemma asymp_asym_eq [pred_set_conv]: "asymp (\<lambda>a b. (a, b) \<in> R) \<longleftrightarrow> asym R"
   by (auto intro!: asymI asympI elim: asym.cases asymp.cases simp add: irreflp_irrefl_eq)
 
 
 subsubsection \<open>Symmetry\<close>
 
 definition sym :: "'a rel \<Rightarrow> bool"
-where
-  "sym r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (y, x) \<in> r)"
+  where "sym r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (y, x) \<in> r)"
 
 definition symp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
-where
-  "symp r \<longleftrightarrow> (\<forall>x y. r x y \<longrightarrow> r y x)"
+  where "symp r \<longleftrightarrow> (\<forall>x y. r x y \<longrightarrow> r y x)"
 
-lemma symp_sym_eq [pred_set_conv]:
-  "symp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> sym r" 
+lemma symp_sym_eq [pred_set_conv]: "symp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> sym r"
   by (simp add: sym_def symp_def)
 
-lemma symI [intro?]:
-  "(\<And>a b. (a, b) \<in> r \<Longrightarrow> (b, a) \<in> r) \<Longrightarrow> sym r"
+lemma symI [intro?]: "(\<And>a b. (a, b) \<in> r \<Longrightarrow> (b, a) \<in> r) \<Longrightarrow> sym r"
   by (unfold sym_def) iprover
 
-lemma sympI [intro?]:
-  "(\<And>a b. r a b \<Longrightarrow> r b a) \<Longrightarrow> symp r"
+lemma sympI [intro?]: "(\<And>a b. r a b \<Longrightarrow> r b a) \<Longrightarrow> symp r"
   by (fact symI [to_pred])
 
 lemma symE:
@@ -309,86 +287,70 @@
   shows "r a b"
   using assms by (rule symD [to_pred])
 
-lemma sym_Int:
-  "sym r \<Longrightarrow> sym s \<Longrightarrow> sym (r \<inter> s)"
+lemma sym_Int: "sym r \<Longrightarrow> sym s \<Longrightarrow> sym (r \<inter> s)"
   by (fast intro: symI elim: symE)
 
-lemma symp_inf:
-  "symp r \<Longrightarrow> symp s \<Longrightarrow> symp (r \<sqinter> s)"
+lemma symp_inf: "symp r \<Longrightarrow> symp s \<Longrightarrow> symp (r \<sqinter> s)"
   by (fact sym_Int [to_pred])
 
-lemma sym_Un:
-  "sym r \<Longrightarrow> sym s \<Longrightarrow> sym (r \<union> s)"
+lemma sym_Un: "sym r \<Longrightarrow> sym s \<Longrightarrow> sym (r \<union> s)"
   by (fast intro: symI elim: symE)
 
-lemma symp_sup:
-  "symp r \<Longrightarrow> symp s \<Longrightarrow> symp (r \<squnion> s)"
+lemma symp_sup: "symp r \<Longrightarrow> symp s \<Longrightarrow> symp (r \<squnion> s)"
   by (fact sym_Un [to_pred])
 
-lemma sym_INTER:
-  "\<forall>x\<in>S. sym (r x) \<Longrightarrow> sym (INTER S r)"
+lemma sym_INTER: "\<forall>x\<in>S. sym (r x) \<Longrightarrow> sym (INTER S r)"
   by (fast intro: symI elim: symE)
 
-lemma symp_INF:
-  "\<forall>x\<in>S. symp (r x) \<Longrightarrow> symp (INFIMUM S r)"
+lemma symp_INF: "\<forall>x\<in>S. symp (r x) \<Longrightarrow> symp (INFIMUM S r)"
   by (fact sym_INTER [to_pred])
 
-lemma sym_UNION:
-  "\<forall>x\<in>S. sym (r x) \<Longrightarrow> sym (UNION S r)"
+lemma sym_UNION: "\<forall>x\<in>S. sym (r x) \<Longrightarrow> sym (UNION S r)"
   by (fast intro: symI elim: symE)
 
-lemma symp_SUP:
-  "\<forall>x\<in>S. symp (r x) \<Longrightarrow> symp (SUPREMUM S r)"
+lemma symp_SUP: "\<forall>x\<in>S. symp (r x) \<Longrightarrow> symp (SUPREMUM S r)"
   by (fact sym_UNION [to_pred])
 
 
 subsubsection \<open>Antisymmetry\<close>
 
 definition antisym :: "'a rel \<Rightarrow> bool"
-where
-  "antisym r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (y, x) \<in> r \<longrightarrow> x = y)"
+  where "antisym r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (y, x) \<in> r \<longrightarrow> x = y)"
 
 abbreviation antisymP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
-where -- \<open>FIXME proper logical operation\<close>
-  "antisymP r \<equiv> antisym {(x, y). r x y}"
+  where "antisymP r \<equiv> antisym {(x, y). r x y}" (* FIXME proper logical operation *)
+
+lemma antisymI [intro?]: "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (y, x) \<in> r \<Longrightarrow> x = y) \<Longrightarrow> antisym r"
+  unfolding antisym_def by iprover
 
-lemma antisymI [intro?]:
-  "(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r"
-  by (unfold antisym_def) iprover
+lemma antisymD [dest?]: "antisym r \<Longrightarrow> (a, b) \<in> r \<Longrightarrow> (b, a) \<in> r \<Longrightarrow> a = b"
+  unfolding antisym_def by iprover
 
-lemma antisymD [dest?]: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b"
-  by (unfold antisym_def) iprover
-
-lemma antisym_subset: "r \<subseteq> s ==> antisym s ==> antisym r"
-  by (unfold antisym_def) blast
+lemma antisym_subset: "r \<subseteq> s \<Longrightarrow> antisym s \<Longrightarrow> antisym r"
+  unfolding antisym_def by blast
 
 lemma antisym_empty [simp]: "antisym {}"
-  by (unfold antisym_def) blast
+  unfolding antisym_def by blast
 
 lemma antisymP_equality [simp]: "antisymP op ="
-by(auto intro: antisymI)
+  by (auto intro: antisymI)
 
 
 subsubsection \<open>Transitivity\<close>
 
 definition trans :: "'a rel \<Rightarrow> bool"
-where
-  "trans r \<longleftrightarrow> (\<forall>x y z. (x, y) \<in> r \<longrightarrow> (y, z) \<in> r \<longrightarrow> (x, z) \<in> r)"
+  where "trans r \<longleftrightarrow> (\<forall>x y z. (x, y) \<in> r \<longrightarrow> (y, z) \<in> r \<longrightarrow> (x, z) \<in> r)"
 
 definition transp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
-where
-  "transp r \<longleftrightarrow> (\<forall>x y z. r x y \<longrightarrow> r y z \<longrightarrow> r x z)"
+  where "transp r \<longleftrightarrow> (\<forall>x y z. r x y \<longrightarrow> r y z \<longrightarrow> r x z)"
 
-lemma transp_trans_eq [pred_set_conv]:
-  "transp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> trans r" 
+lemma transp_trans_eq [pred_set_conv]: "transp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> trans r"
   by (simp add: trans_def transp_def)
 
-lemma transI [intro?]:
-  "(\<And>x y z. (x, y) \<in> r \<Longrightarrow> (y, z) \<in> r \<Longrightarrow> (x, z) \<in> r) \<Longrightarrow> trans r"
+lemma transI [intro?]: "(\<And>x y z. (x, y) \<in> r \<Longrightarrow> (y, z) \<in> r \<Longrightarrow> (x, z) \<in> r) \<Longrightarrow> trans r"
   by (unfold trans_def) iprover
 
-lemma transpI [intro?]:
-  "(\<And>x y z. r x y \<Longrightarrow> r y z \<Longrightarrow> r x z) \<Longrightarrow> transp r"
+lemma transpI [intro?]: "(\<And>x y z. r x y \<Longrightarrow> r y z \<Longrightarrow> r x z) \<Longrightarrow> transp r"
   by (fact transI [to_pred])
 
 lemma transE:
@@ -411,37 +373,31 @@
   shows "r x z"
   using assms by (rule transD [to_pred])
 
-lemma trans_Int:
-  "trans r \<Longrightarrow> trans s \<Longrightarrow> trans (r \<inter> s)"
+lemma trans_Int: "trans r \<Longrightarrow> trans s \<Longrightarrow> trans (r \<inter> s)"
   by (fast intro: transI elim: transE)
 
-lemma transp_inf:
-  "transp r \<Longrightarrow> transp s \<Longrightarrow> transp (r \<sqinter> s)"
+lemma transp_inf: "transp r \<Longrightarrow> transp s \<Longrightarrow> transp (r \<sqinter> s)"
   by (fact trans_Int [to_pred])
 
-lemma trans_INTER:
-  "\<forall>x\<in>S. trans (r x) \<Longrightarrow> trans (INTER S r)"
+lemma trans_INTER: "\<forall>x\<in>S. trans (r x) \<Longrightarrow> trans (INTER S r)"
   by (fast intro: transI elim: transD)
 
 (* FIXME thm trans_INTER [to_pred] *)
 
-lemma trans_join [code]:
-  "trans r \<longleftrightarrow> (\<forall>(x, y1) \<in> r. \<forall>(y2, z) \<in> r. y1 = y2 \<longrightarrow> (x, z) \<in> r)"
+lemma trans_join [code]: "trans r \<longleftrightarrow> (\<forall>(x, y1) \<in> r. \<forall>(y2, z) \<in> r. y1 = y2 \<longrightarrow> (x, z) \<in> r)"
   by (auto simp add: trans_def)
 
-lemma transp_trans:
-  "transp r \<longleftrightarrow> trans {(x, y). r x y}"
+lemma transp_trans: "transp r \<longleftrightarrow> trans {(x, y). r x y}"
   by (simp add: trans_def transp_def)
 
 lemma transp_equality [simp]: "transp op ="
-by(auto intro: transpI)
+  by (auto intro: transpI)
 
 
 subsubsection \<open>Totality\<close>
 
 definition total_on :: "'a set \<Rightarrow> 'a rel \<Rightarrow> bool"
-where
-  "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)"
+  where "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)"
 
 abbreviation "total \<equiv> total_on UNIV"
 
@@ -452,27 +408,22 @@
 subsubsection \<open>Single valued relations\<close>
 
 definition single_valued :: "('a \<times> 'b) set \<Rightarrow> bool"
-where
-  "single_valued r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (\<forall>z. (x, z) \<in> r \<longrightarrow> y = z))"
+  where "single_valued r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (\<forall>z. (x, z) \<in> r \<longrightarrow> y = z))"
 
 abbreviation single_valuedP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
-where -- \<open>FIXME proper logical operation\<close>
-  "single_valuedP r \<equiv> single_valued {(x, y). r x y}"
+  where "single_valuedP r \<equiv> single_valued {(x, y). r x y}" (* FIXME proper logical operation *)
 
-lemma single_valuedI:
-  "ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r"
-  by (unfold single_valued_def)
+lemma single_valuedI: "\<forall>x y. (x, y) \<in> r \<longrightarrow> (\<forall>z. (x, z) \<in> r \<longrightarrow> y = z) \<Longrightarrow> single_valued r"
+  unfolding single_valued_def .
 
-lemma single_valuedD:
-  "single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z"
+lemma single_valuedD: "single_valued r \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> (x, z) \<in> r \<Longrightarrow> y = z"
   by (simp add: single_valued_def)
 
 lemma single_valued_empty[simp]: "single_valued {}"
-by(simp add: single_valued_def)
+  by (simp add: single_valued_def)
 
-lemma single_valued_subset:
-  "r \<subseteq> s ==> single_valued s ==> single_valued r"
-  by (unfold single_valued_def) blast
+lemma single_valued_subset: "r \<subseteq> s \<Longrightarrow> single_valued s \<Longrightarrow> single_valued r"
+  unfolding single_valued_def by blast
 
 
 subsection \<open>Relation operations\<close>
@@ -480,17 +431,16 @@
 subsubsection \<open>The identity relation\<close>
 
 definition Id :: "'a rel"
-where
-  [code del]: "Id = {p. \<exists>x. p = (x, x)}"
+  where [code del]: "Id = {p. \<exists>x. p = (x, x)}"
 
-lemma IdI [intro]: "(a, a) : Id"
+lemma IdI [intro]: "(a, a) \<in> Id"
   by (simp add: Id_def)
 
-lemma IdE [elim!]: "p : Id ==> (!!x. p = (x, x) ==> P) ==> P"
-  by (unfold Id_def) (iprover elim: CollectE)
+lemma IdE [elim!]: "p \<in> Id \<Longrightarrow> (\<And>x. p = (x, x) \<Longrightarrow> P) \<Longrightarrow> P"
+  unfolding Id_def by (iprover elim: CollectE)
 
-lemma pair_in_Id_conv [iff]: "((a, b) : Id) = (a = b)"
-  by (unfold Id_def) blast
+lemma pair_in_Id_conv [iff]: "(a, b) \<in> Id \<longleftrightarrow> a = b"
+  unfolding Id_def by blast
 
 lemma refl_Id: "refl Id"
   by (simp add: refl_on_def)
@@ -509,7 +459,7 @@
   by (unfold single_valued_def) blast
 
 lemma irrefl_diff_Id [simp]: "irrefl (r - Id)"
-  by (simp add:irrefl_def)
+  by (simp add: irrefl_def)
 
 lemma trans_diff_Id: "trans r \<Longrightarrow> antisym r \<Longrightarrow> trans (r - Id)"
   unfolding antisym_def trans_def by blast
@@ -524,28 +474,25 @@
 subsubsection \<open>Diagonal: identity over a set\<close>
 
 definition Id_on  :: "'a set \<Rightarrow> 'a rel"
-where
-  "Id_on A = (\<Union>x\<in>A. {(x, x)})"
+  where "Id_on A = (\<Union>x\<in>A. {(x, x)})"
 
 lemma Id_on_empty [simp]: "Id_on {} = {}"
-  by (simp add: Id_on_def) 
+  by (simp add: Id_on_def)
 
-lemma Id_on_eqI: "a = b ==> a : A ==> (a, b) : Id_on A"
+lemma Id_on_eqI: "a = b \<Longrightarrow> a \<in> A \<Longrightarrow> (a, b) \<in> Id_on A"
   by (simp add: Id_on_def)
 
-lemma Id_onI [intro!]: "a : A ==> (a, a) : Id_on A"
+lemma Id_onI [intro!]: "a \<in> A \<Longrightarrow> (a, a) \<in> Id_on A"
   by (rule Id_on_eqI) (rule refl)
 
-lemma Id_onE [elim!]:
-  "c : Id_on A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P"
+lemma Id_onE [elim!]: "c \<in> Id_on A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> c = (x, x) \<Longrightarrow> P) \<Longrightarrow> P"
   \<comment> \<open>The general elimination rule.\<close>
-  by (unfold Id_on_def) (iprover elim!: UN_E singletonE)
+  unfolding Id_on_def by (iprover elim!: UN_E singletonE)
 
-lemma Id_on_iff: "((x, y) : Id_on A) = (x = y & x : A)"
+lemma Id_on_iff: "(x, y) \<in> Id_on A \<longleftrightarrow> x = y \<and> x \<in> A"
   by blast
 
-lemma Id_on_def' [nitpick_unfold]:
-  "Id_on {x. A x} = Collect (\<lambda>(x, y). x = y \<and> A x)"
+lemma Id_on_def' [nitpick_unfold]: "Id_on {x. A x} = Collect (\<lambda>(x, y). x = y \<and> A x)"
   by auto
 
 lemma Id_on_subset_Times: "Id_on A \<subseteq> A \<times> A"
@@ -555,7 +502,7 @@
   by (rule refl_onI [OF Id_on_subset_Times Id_onI])
 
 lemma antisym_Id_on [simp]: "antisym (Id_on A)"
-  by (unfold antisym_def) blast
+  unfolding antisym_def by blast
 
 lemma sym_Id_on [simp]: "sym (Id_on A)"
   by (rule symI) clarify
@@ -564,15 +511,14 @@
   by (fast intro: transI elim: transD)
 
 lemma single_valued_Id_on [simp]: "single_valued (Id_on A)"
-  by (unfold single_valued_def) blast
+  unfolding single_valued_def by blast
 
 
 subsubsection \<open>Composition\<close>
 
-inductive_set relcomp  :: "('a \<times> 'b) set \<Rightarrow> ('b \<times> 'c) set \<Rightarrow> ('a \<times> 'c) set" (infixr "O" 75)
+inductive_set relcomp  :: "('a \<times> 'b) set \<Rightarrow> ('b \<times> 'c) set \<Rightarrow> ('a \<times> 'c) set"  (infixr "O" 75)
   for r :: "('a \<times> 'b) set" and s :: "('b \<times> 'c) set"
-where
-  relcompI [intro]: "(a, b) \<in> r \<Longrightarrow> (b, c) \<in> s \<Longrightarrow> (a, c) \<in> r O s"
+  where relcompI [intro]: "(a, b) \<in> r \<Longrightarrow> (b, c) \<in> s \<Longrightarrow> (a, c) \<in> r O s"
 
 notation relcompp (infixr "OO" 75)
 
@@ -588,269 +534,239 @@
 
 lemma relcompE [elim!]: "xz \<in> r O s \<Longrightarrow>
   (\<And>x y z. xz = (x, z) \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> (y, z) \<in> s  \<Longrightarrow> P) \<Longrightarrow> P"
-  by (cases xz) (simp, erule relcompEpair, iprover)
+  apply (cases xz)
+  apply simp
+  apply (erule relcompEpair)
+  apply iprover
+  done
 
-lemma R_O_Id [simp]:
-  "R O Id = R"
+lemma R_O_Id [simp]: "R O Id = R"
   by fast
 
-lemma Id_O_R [simp]:
-  "Id O R = R"
+lemma Id_O_R [simp]: "Id O R = R"
   by fast
 
-lemma relcomp_empty1 [simp]:
-  "{} O R = {}"
+lemma relcomp_empty1 [simp]: "{} O R = {}"
   by blast
 
-lemma relcompp_bot1 [simp]:
-  "\<bottom> OO R = \<bottom>"
+lemma relcompp_bot1 [simp]: "\<bottom> OO R = \<bottom>"
   by (fact relcomp_empty1 [to_pred])
 
-lemma relcomp_empty2 [simp]:
-  "R O {} = {}"
+lemma relcomp_empty2 [simp]: "R O {} = {}"
   by blast
 
-lemma relcompp_bot2 [simp]:
-  "R OO \<bottom> = \<bottom>"
+lemma relcompp_bot2 [simp]: "R OO \<bottom> = \<bottom>"
   by (fact relcomp_empty2 [to_pred])
 
-lemma O_assoc:
-  "(R O S) O T = R O (S O T)"
+lemma O_assoc: "(R O S) O T = R O (S O T)"
   by blast
 
-lemma relcompp_assoc:
-  "(r OO s) OO t = r OO (s OO t)"
+lemma relcompp_assoc: "(r OO s) OO t = r OO (s OO t)"
   by (fact O_assoc [to_pred])
 
-lemma trans_O_subset:
-  "trans r \<Longrightarrow> r O r \<subseteq> r"
+lemma trans_O_subset: "trans r \<Longrightarrow> r O r \<subseteq> r"
   by (unfold trans_def) blast
 
-lemma transp_relcompp_less_eq:
-  "transp r \<Longrightarrow> r OO r \<le> r "
+lemma transp_relcompp_less_eq: "transp r \<Longrightarrow> r OO r \<le> r "
   by (fact trans_O_subset [to_pred])
 
-lemma relcomp_mono:
-  "r' \<subseteq> r \<Longrightarrow> s' \<subseteq> s \<Longrightarrow> r' O s' \<subseteq> r O s"
+lemma relcomp_mono: "r' \<subseteq> r \<Longrightarrow> s' \<subseteq> s \<Longrightarrow> r' O s' \<subseteq> r O s"
   by blast
 
-lemma relcompp_mono:
-  "r' \<le> r \<Longrightarrow> s' \<le> s \<Longrightarrow> r' OO s' \<le> r OO s "
+lemma relcompp_mono: "r' \<le> r \<Longrightarrow> s' \<le> s \<Longrightarrow> r' OO s' \<le> r OO s "
   by (fact relcomp_mono [to_pred])
 
-lemma relcomp_subset_Sigma:
-  "r \<subseteq> A \<times> B \<Longrightarrow> s \<subseteq> B \<times> C \<Longrightarrow> r O s \<subseteq> A \<times> C"
+lemma relcomp_subset_Sigma: "r \<subseteq> A \<times> B \<Longrightarrow> s \<subseteq> B \<times> C \<Longrightarrow> r O s \<subseteq> A \<times> C"
   by blast
 
-lemma relcomp_distrib [simp]:
-  "R O (S \<union> T) = (R O S) \<union> (R O T)" 
+lemma relcomp_distrib [simp]: "R O (S \<union> T) = (R O S) \<union> (R O T)"
   by auto
 
-lemma relcompp_distrib [simp]:
-  "R OO (S \<squnion> T) = R OO S \<squnion> R OO T"
+lemma relcompp_distrib [simp]: "R OO (S \<squnion> T) = R OO S \<squnion> R OO T"
   by (fact relcomp_distrib [to_pred])
 
-lemma relcomp_distrib2 [simp]:
-  "(S \<union> T) O R = (S O R) \<union> (T O R)"
+lemma relcomp_distrib2 [simp]: "(S \<union> T) O R = (S O R) \<union> (T O R)"
   by auto
 
-lemma relcompp_distrib2 [simp]:
-  "(S \<squnion> T) OO R = S OO R \<squnion> T OO R"
+lemma relcompp_distrib2 [simp]: "(S \<squnion> T) OO R = S OO R \<squnion> T OO R"
   by (fact relcomp_distrib2 [to_pred])
 
-lemma relcomp_UNION_distrib:
-  "s O UNION I r = (\<Union>i\<in>I. s O r i) "
+lemma relcomp_UNION_distrib: "s O UNION I r = (\<Union>i\<in>I. s O r i) "
   by auto
 
 (* FIXME thm relcomp_UNION_distrib [to_pred] *)
 
-lemma relcomp_UNION_distrib2:
-  "UNION I r O s = (\<Union>i\<in>I. r i O s) "
+lemma relcomp_UNION_distrib2: "UNION I r O s = (\<Union>i\<in>I. r i O s) "
   by auto
 
 (* FIXME thm relcomp_UNION_distrib2 [to_pred] *)
 
-lemma single_valued_relcomp:
-  "single_valued r \<Longrightarrow> single_valued s \<Longrightarrow> single_valued (r O s)"
-  by (unfold single_valued_def) blast
+lemma single_valued_relcomp: "single_valued r \<Longrightarrow> single_valued s \<Longrightarrow> single_valued (r O s)"
+  unfolding single_valued_def by blast
 
-lemma relcomp_unfold:
-  "r O s = {(x, z). \<exists>y. (x, y) \<in> r \<and> (y, z) \<in> s}"
+lemma relcomp_unfold: "r O s = {(x, z). \<exists>y. (x, y) \<in> r \<and> (y, z) \<in> s}"
   by (auto simp add: set_eq_iff)
 
 lemma relcompp_apply: "(R OO S) a c \<longleftrightarrow> (\<exists>b. R a b \<and> S b c)"
   unfolding relcomp_unfold [to_pred] ..
 
 lemma eq_OO: "op= OO R = R"
-by blast
+  by blast
 
 lemma OO_eq: "R OO op = = R"
-by blast
+  by blast
 
 
 subsubsection \<open>Converse\<close>
 
 inductive_set converse :: "('a \<times> 'b) set \<Rightarrow> ('b \<times> 'a) set"  ("(_\<inverse>)" [1000] 999)
   for r :: "('a \<times> 'b) set"
-where
-  "(a, b) \<in> r \<Longrightarrow> (b, a) \<in> r\<inverse>"
+  where "(a, b) \<in> r \<Longrightarrow> (b, a) \<in> r\<inverse>"
 
-notation
-  conversep  ("(_\<inverse>\<inverse>)" [1000] 1000)
+notation conversep  ("(_\<inverse>\<inverse>)" [1000] 1000)
 
 notation (ASCII)
   converse  ("(_^-1)" [1000] 999) and
   conversep ("(_^--1)" [1000] 1000)
 
-lemma converseI [sym]:
-  "(a, b) \<in> r \<Longrightarrow> (b, a) \<in> r\<inverse>"
+lemma converseI [sym]: "(a, b) \<in> r \<Longrightarrow> (b, a) \<in> r\<inverse>"
   by (fact converse.intros)
 
-lemma conversepI (* CANDIDATE [sym] *):
-  "r a b \<Longrightarrow> r\<inverse>\<inverse> b a"
+lemma conversepI (* CANDIDATE [sym] *): "r a b \<Longrightarrow> r\<inverse>\<inverse> b a"
   by (fact conversep.intros)
 
-lemma converseD [sym]:
-  "(a, b) \<in> r\<inverse> \<Longrightarrow> (b, a) \<in> r"
+lemma converseD [sym]: "(a, b) \<in> r\<inverse> \<Longrightarrow> (b, a) \<in> r"
   by (erule converse.cases) iprover
 
-lemma conversepD (* CANDIDATE [sym] *):
-  "r\<inverse>\<inverse> b a \<Longrightarrow> r a b"
+lemma conversepD (* CANDIDATE [sym] *): "r\<inverse>\<inverse> b a \<Longrightarrow> r a b"
   by (fact converseD [to_pred])
 
-lemma converseE [elim!]:
+lemma converseE [elim!]: "yx \<in> r\<inverse> \<Longrightarrow> (\<And>x y. yx = (y, x) \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> P) \<Longrightarrow> P"
   \<comment> \<open>More general than \<open>converseD\<close>, as it ``splits'' the member of the relation.\<close>
-  "yx \<in> r\<inverse> \<Longrightarrow> (\<And>x y. yx = (y, x) \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> P) \<Longrightarrow> P"
-  by (cases yx) (simp, erule converse.cases, iprover)
+  apply (cases yx)
+  apply simp
+  apply (erule converse.cases)
+  apply iprover
+  done
 
 lemmas conversepE [elim!] = conversep.cases
 
-lemma converse_iff [iff]:
-  "(a, b) \<in> r\<inverse> \<longleftrightarrow> (b, a) \<in> r"
+lemma converse_iff [iff]: "(a, b) \<in> r\<inverse> \<longleftrightarrow> (b, a) \<in> r"
   by (auto intro: converseI)
 
-lemma conversep_iff [iff]:
-  "r\<inverse>\<inverse> a b = r b a"
+lemma conversep_iff [iff]: "r\<inverse>\<inverse> a b = r b a"
   by (fact converse_iff [to_pred])
 
-lemma converse_converse [simp]:
-  "(r\<inverse>)\<inverse> = r"
+lemma converse_converse [simp]: "(r\<inverse>)\<inverse> = r"
   by (simp add: set_eq_iff)
 
-lemma conversep_conversep [simp]:
-  "(r\<inverse>\<inverse>)\<inverse>\<inverse> = r"
+lemma conversep_conversep [simp]: "(r\<inverse>\<inverse>)\<inverse>\<inverse> = r"
   by (fact converse_converse [to_pred])
 
 lemma converse_empty[simp]: "{}\<inverse> = {}"
-by auto
+  by auto
 
 lemma converse_UNIV[simp]: "UNIV\<inverse> = UNIV"
-by auto
+  by auto
 
-lemma converse_relcomp: "(r O s)^-1 = s^-1 O r^-1"
+lemma converse_relcomp: "(r O s)\<inverse> = s\<inverse> O r\<inverse>"
   by blast
 
-lemma converse_relcompp: "(r OO s)^--1 = s^--1 OO r^--1"
-  by (iprover intro: order_antisym conversepI relcomppI
-    elim: relcomppE dest: conversepD)
+lemma converse_relcompp: "(r OO s)\<inverse>\<inverse> = s\<inverse>\<inverse> OO r\<inverse>\<inverse>"
+  by (iprover intro: order_antisym conversepI relcomppI elim: relcomppE dest: conversepD)
 
-lemma converse_Int: "(r \<inter> s)^-1 = r^-1 \<inter> s^-1"
+lemma converse_Int: "(r \<inter> s)\<inverse> = r\<inverse> \<inter> s\<inverse>"
   by blast
 
-lemma converse_meet: "(r \<sqinter> s)^--1 = r^--1 \<sqinter> s^--1"
+lemma converse_meet: "(r \<sqinter> s)\<inverse>\<inverse> = r\<inverse>\<inverse> \<sqinter> s\<inverse>\<inverse>"
   by (simp add: inf_fun_def) (iprover intro: conversepI ext dest: conversepD)
 
-lemma converse_Un: "(r \<union> s)^-1 = r^-1 \<union> s^-1"
+lemma converse_Un: "(r \<union> s)\<inverse> = r\<inverse> \<union> s\<inverse>"
   by blast
 
-lemma converse_join: "(r \<squnion> s)^--1 = r^--1 \<squnion> s^--1"
+lemma converse_join: "(r \<squnion> s)\<inverse>\<inverse> = r\<inverse>\<inverse> \<squnion> s\<inverse>\<inverse>"
   by (simp add: sup_fun_def) (iprover intro: conversepI ext dest: conversepD)
 
-lemma converse_INTER: "(INTER S r)^-1 = (INT x:S. (r x)^-1)"
+lemma converse_INTER: "(INTER S r)\<inverse> = (INT x:S. (r x)\<inverse>)"
   by fast
 
-lemma converse_UNION: "(UNION S r)^-1 = (UN x:S. (r x)^-1)"
+lemma converse_UNION: "(UNION S r)\<inverse> = (UN x:S. (r x)\<inverse>)"
   by blast
 
-lemma converse_mono[simp]: "r^-1 \<subseteq> s ^-1 \<longleftrightarrow> r \<subseteq> s"
+lemma converse_mono[simp]: "r\<inverse> \<subseteq> s \<inverse> \<longleftrightarrow> r \<subseteq> s"
   by auto
 
-lemma conversep_mono[simp]: "r^--1 \<le> s ^--1 \<longleftrightarrow> r \<le> s"
+lemma conversep_mono[simp]: "r\<inverse>\<inverse> \<le> s \<inverse>\<inverse> \<longleftrightarrow> r \<le> s"
   by (fact converse_mono[to_pred])
 
-lemma converse_inject[simp]: "r^-1 = s ^-1 \<longleftrightarrow> r = s"
+lemma converse_inject[simp]: "r\<inverse> = s \<inverse> \<longleftrightarrow> r = s"
   by auto
 
-lemma conversep_inject[simp]: "r^--1 = s ^--1 \<longleftrightarrow> r = s"
+lemma conversep_inject[simp]: "r\<inverse>\<inverse> = s \<inverse>\<inverse> \<longleftrightarrow> r = s"
   by (fact converse_inject[to_pred])
 
-lemma converse_subset_swap: "r \<subseteq> s ^-1 = (r ^-1 \<subseteq> s)"
+lemma converse_subset_swap: "r \<subseteq> s \<inverse> = (r \<inverse> \<subseteq> s)"
   by auto
 
-lemma conversep_le_swap: "r \<le> s ^--1 = (r ^--1 \<le> s)"
+lemma conversep_le_swap: "r \<le> s \<inverse>\<inverse> = (r \<inverse>\<inverse> \<le> s)"
   by (fact converse_subset_swap[to_pred])
 
-lemma converse_Id [simp]: "Id^-1 = Id"
+lemma converse_Id [simp]: "Id\<inverse> = Id"
   by blast
 
-lemma converse_Id_on [simp]: "(Id_on A)^-1 = Id_on A"
+lemma converse_Id_on [simp]: "(Id_on A)\<inverse> = Id_on A"
   by blast
 
 lemma refl_on_converse [simp]: "refl_on A (converse r) = refl_on A r"
-  by (unfold refl_on_def) auto
+  by (auto simp: refl_on_def)
 
 lemma sym_converse [simp]: "sym (converse r) = sym r"
-  by (unfold sym_def) blast
+  unfolding sym_def by blast
 
 lemma antisym_converse [simp]: "antisym (converse r) = antisym r"
-  by (unfold antisym_def) blast
+  unfolding antisym_def by blast
 
 lemma trans_converse [simp]: "trans (converse r) = trans r"
-  by (unfold trans_def) blast
+  unfolding trans_def by blast
 
-lemma sym_conv_converse_eq: "sym r = (r^-1 = r)"
-  by (unfold sym_def) fast
+lemma sym_conv_converse_eq: "sym r \<longleftrightarrow> r\<inverse> = r"
+  unfolding sym_def by fast
 
-lemma sym_Un_converse: "sym (r \<union> r^-1)"
-  by (unfold sym_def) blast
+lemma sym_Un_converse: "sym (r \<union> r\<inverse>)"
+  unfolding sym_def by blast
 
-lemma sym_Int_converse: "sym (r \<inter> r^-1)"
-  by (unfold sym_def) blast
+lemma sym_Int_converse: "sym (r \<inter> r\<inverse>)"
+  unfolding sym_def by blast
 
-lemma total_on_converse [simp]: "total_on A (r^-1) = total_on A r"
+lemma total_on_converse [simp]: "total_on A (r\<inverse>) = total_on A r"
   by (auto simp: total_on_def)
 
-lemma finite_converse [iff]: "finite (r^-1) = finite r"  
+lemma finite_converse [iff]: "finite (r\<inverse>) = finite r"
   unfolding converse_def conversep_iff using [[simproc add: finite_Collect]]
   by (auto elim: finite_imageD simp: inj_on_def)
 
-lemma conversep_noteq [simp]: "(op \<noteq>)^--1 = op \<noteq>"
+lemma conversep_noteq [simp]: "(op \<noteq>)\<inverse>\<inverse> = op \<noteq>"
   by (auto simp add: fun_eq_iff)
 
-lemma conversep_eq [simp]: "(op =)^--1 = op ="
+lemma conversep_eq [simp]: "(op =)\<inverse>\<inverse> = op ="
   by (auto simp add: fun_eq_iff)
 
-lemma converse_unfold [code]:
-  "r\<inverse> = {(y, x). (x, y) \<in> r}"
+lemma converse_unfold [code]: "r\<inverse> = {(y, x). (x, y) \<in> r}"
   by (simp add: set_eq_iff)
 
 
 subsubsection \<open>Domain, range and field\<close>
 
-inductive_set Domain :: "('a \<times> 'b) set \<Rightarrow> 'a set"
-  for r :: "('a \<times> 'b) set"
-where
-  DomainI [intro]: "(a, b) \<in> r \<Longrightarrow> a \<in> Domain r"
+inductive_set Domain :: "('a \<times> 'b) set \<Rightarrow> 'a set" for r :: "('a \<times> 'b) set"
+  where DomainI [intro]: "(a, b) \<in> r \<Longrightarrow> a \<in> Domain r"
 
 lemmas DomainPI = Domainp.DomainI
 
 inductive_cases DomainE [elim!]: "a \<in> Domain r"
 inductive_cases DomainpE [elim!]: "Domainp r a"
 
-inductive_set Range :: "('a \<times> 'b) set \<Rightarrow> 'b set"
-  for r :: "('a \<times> 'b) set"
-where
-  RangeI [intro]: "(a, b) \<in> r \<Longrightarrow> b \<in> Range r"
+inductive_set Range :: "('a \<times> 'b) set \<Rightarrow> 'b set" for r :: "('a \<times> 'b) set"
+  where RangeI [intro]: "(a, b) \<in> r \<Longrightarrow> b \<in> Range r"
 
 lemmas RangePI = Rangep.RangeI
 
@@ -858,15 +774,12 @@
 inductive_cases RangepE [elim!]: "Rangep r b"
 
 definition Field :: "'a rel \<Rightarrow> 'a set"
-where
-  "Field r = Domain r \<union> Range r"
+  where "Field r = Domain r \<union> Range r"
 
-lemma Domain_fst [code]:
-  "Domain r = fst ` r"
+lemma Domain_fst [code]: "Domain r = fst ` r"
   by force
 
-lemma Range_snd [code]:
-  "Range r = snd ` r"
+lemma Range_snd [code]: "Range r = snd ` r"
   by force
 
 lemma fst_eq_Domain: "fst ` R = Domain R"
@@ -962,10 +875,10 @@
 lemma Field_converse [simp]: "Field (r\<inverse>) = Field r"
   by (auto simp: Field_def)
 
-lemma Domain_Collect_case_prod [simp]: "Domain {(x, y). P x y} = {x. EX y. P x y}"
+lemma Domain_Collect_case_prod [simp]: "Domain {(x, y). P x y} = {x. \<exists>y. P x y}"
   by auto
 
-lemma Range_Collect_case_prod [simp]: "Range {(x, y). P x y} = {y. EX x. P x y}"
+lemma Range_Collect_case_prod [simp]: "Range {(x, y). P x y} = {y. \<exists>x. P x y}"
   by auto
 
 lemma finite_Domain: "finite r \<Longrightarrow> finite (Domain r)"
@@ -986,34 +899,31 @@
 lemma mono_Field: "r \<subseteq> s \<Longrightarrow> Field r \<subseteq> Field s"
   by (auto simp: Field_def Domain_def Range_def)
 
-lemma Domain_unfold:
-  "Domain r = {x. \<exists>y. (x, y) \<in> r}"
+lemma Domain_unfold: "Domain r = {x. \<exists>y. (x, y) \<in> r}"
   by blast
 
 
 subsubsection \<open>Image of a set under a relation\<close>
 
-definition Image :: "('a \<times> 'b) set \<Rightarrow> 'a set \<Rightarrow> 'b set" (infixr "``" 90)
-where
-  "r `` s = {y. \<exists>x\<in>s. (x, y) \<in> r}"
+definition Image :: "('a \<times> 'b) set \<Rightarrow> 'a set \<Rightarrow> 'b set"  (infixr "``" 90)
+  where "r `` s = {y. \<exists>x\<in>s. (x, y) \<in> r}"
 
-lemma Image_iff: "(b : r``A) = (EX x:A. (x, b) : r)"
+lemma Image_iff: "b \<in> r``A \<longleftrightarrow> (\<exists>x\<in>A. (x, b) \<in> r)"
   by (simp add: Image_def)
 
-lemma Image_singleton: "r``{a} = {b. (a, b) : r}"
+lemma Image_singleton: "r``{a} = {b. (a, b) \<in> r}"
   by (simp add: Image_def)
 
-lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a, b) : r)"
+lemma Image_singleton_iff [iff]: "b \<in> r``{a} \<longleftrightarrow> (a, b) \<in> r"
   by (rule Image_iff [THEN trans]) simp
 
-lemma ImageI [intro]: "(a, b) : r ==> a : A ==> b : r``A"
-  by (unfold Image_def) blast
+lemma ImageI [intro]: "(a, b) \<in> r \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> r``A"
+  unfolding Image_def by blast
 
-lemma ImageE [elim!]:
-  "b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P"
-  by (unfold Image_def) (iprover elim!: CollectE bexE)
+lemma ImageE [elim!]: "b \<in> r `` A \<Longrightarrow> (\<And>x. (x, b) \<in> r \<Longrightarrow> x \<in> A \<Longrightarrow> P) \<Longrightarrow> P"
+  unfolding Image_def by (iprover elim!: CollectE bexE)
 
-lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A"
+lemma rev_ImageI: "a \<in> A \<Longrightarrow> (a, b) \<in> r \<Longrightarrow> b \<in> r `` A"
   \<comment> \<open>This version's more effective when we already have the required \<open>a\<close>\<close>
   by blast
 
@@ -1029,9 +939,8 @@
 lemma Image_Int_subset: "R `` (A \<inter> B) \<subseteq> R `` A \<inter> R `` B"
   by blast
 
-lemma Image_Int_eq:
-  "single_valued (converse R) ==> R `` (A \<inter> B) = R `` A \<inter> R `` B"
-  by (simp add: single_valued_def, blast) 
+lemma Image_Int_eq: "single_valued (converse R) \<Longrightarrow> R `` (A \<inter> B) = R `` A \<inter> R `` B"
+  by (simp add: single_valued_def, blast)
 
 lemma Image_Un: "R `` (A \<union> B) = R `` A \<union> R `` B"
   by blast
@@ -1039,14 +948,14 @@
 lemma Un_Image: "(R \<union> S) `` A = R `` A \<union> S `` A"
   by blast
 
-lemma Image_subset: "r \<subseteq> A \<times> B ==> r``C \<subseteq> B"
+lemma Image_subset: "r \<subseteq> A \<times> B \<Longrightarrow> r``C \<subseteq> B"
   by (iprover intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2)
 
 lemma Image_eq_UN: "r``B = (\<Union>y\<in> B. r``{y})"
   \<comment> \<open>NOT suitable for rewriting\<close>
   by blast
 
-lemma Image_mono: "r' \<subseteq> r ==> A' \<subseteq> A ==> (r' `` A') \<subseteq> (r `` A)"
+lemma Image_mono: "r' \<subseteq> r \<Longrightarrow> A' \<subseteq> A \<Longrightarrow> (r' `` A') \<subseteq> (r `` A)"
   by blast
 
 lemma Image_UN: "(r `` (UNION A B)) = (\<Union>x\<in>A. r `` (B x))"
@@ -1058,19 +967,18 @@
 lemma Image_INT_subset: "(r `` INTER A B) \<subseteq> (\<Inter>x\<in>A. r `` (B x))"
   by blast
 
-text\<open>Converse inclusion requires some assumptions\<close>
-lemma Image_INT_eq:
-  "single_valued (r\<inverse>) \<Longrightarrow> A \<noteq> {} \<Longrightarrow> r `` INTER A B = (\<Inter>x\<in>A. r `` B x)"
-apply (rule equalityI)
- apply (rule Image_INT_subset) 
-apply (auto simp add: single_valued_def)
-apply blast
-done
+text \<open>Converse inclusion requires some assumptions\<close>
+lemma Image_INT_eq: "single_valued (r\<inverse>) \<Longrightarrow> A \<noteq> {} \<Longrightarrow> r `` INTER A B = (\<Inter>x\<in>A. r `` B x)"
+  apply (rule equalityI)
+   apply (rule Image_INT_subset)
+  apply (auto simp add: single_valued_def)
+  apply blast
+  done
 
-lemma Image_subset_eq: "(r``A \<subseteq> B) = (A \<subseteq> - ((r^-1) `` (-B)))"
+lemma Image_subset_eq: "r``A \<subseteq> B \<longleftrightarrow> A \<subseteq> - ((r\<inverse>) `` (- B))"
   by blast
 
-lemma Image_Collect_case_prod [simp]: "{(x, y). P x y} `` A = {y. EX x:A. P x y}"
+lemma Image_Collect_case_prod [simp]: "{(x, y). P x y} `` A = {y. \<exists>x\<in>A. P x y}"
   by auto
 
 lemma Sigma_Image: "(SIGMA x:A. B x) `` X = (\<Union>x\<in>X \<inter> A. B x)"
@@ -1083,29 +991,27 @@
 subsubsection \<open>Inverse image\<close>
 
 definition inv_image :: "'b rel \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a rel"
-where
-  "inv_image r f = {(x, y). (f x, f y) \<in> r}"
+  where "inv_image r f = {(x, y). (f x, f y) \<in> r}"
 
 definition inv_imagep :: "('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool"
-where
-  "inv_imagep r f = (\<lambda>x y. r (f x) (f y))"
+  where "inv_imagep r f = (\<lambda>x y. r (f x) (f y))"
 
 lemma [pred_set_conv]: "inv_imagep (\<lambda>x y. (x, y) \<in> r) f = (\<lambda>x y. (x, y) \<in> inv_image r f)"
   by (simp add: inv_image_def inv_imagep_def)
 
-lemma sym_inv_image: "sym r ==> sym (inv_image r f)"
-  by (unfold sym_def inv_image_def) blast
+lemma sym_inv_image: "sym r \<Longrightarrow> sym (inv_image r f)"
+  unfolding sym_def inv_image_def by blast
 
-lemma trans_inv_image: "trans r ==> trans (inv_image r f)"
-  apply (unfold trans_def inv_image_def)
+lemma trans_inv_image: "trans r \<Longrightarrow> trans (inv_image r f)"
+  unfolding trans_def inv_image_def
   apply (simp (no_asm))
   apply blast
   done
 
-lemma in_inv_image[simp]: "((x,y) : inv_image r f) = ((f x, f y) : r)"
+lemma in_inv_image[simp]: "(x, y) \<in> inv_image r f \<longleftrightarrow> (f x, f y) \<in> r"
   by (auto simp:inv_image_def)
 
-lemma converse_inv_image[simp]: "(inv_image R f)^-1 = inv_image (R^-1) f"
+lemma converse_inv_image[simp]: "(inv_image R f)\<inverse> = inv_image (R\<inverse>) f"
   unfolding inv_image_def converse_unfold by auto
 
 lemma in_inv_imagep [simp]: "inv_imagep r f x y = r (f x) (f y)"
@@ -1115,8 +1021,7 @@
 subsubsection \<open>Powerset\<close>
 
 definition Powp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool"
-where
-  "Powp A = (\<lambda>B. \<forall>x \<in> B. A x)"
+  where "Powp A = (\<lambda>B. \<forall>x \<in> B. A x)"
 
 lemma Powp_Pow_eq [pred_set_conv]: "Powp (\<lambda>x. x \<in> A) = (\<lambda>x. x \<in> Pow A)"
   by (auto simp add: Powp_def fun_eq_iff)
@@ -1130,28 +1035,31 @@
   assumes "finite A"
   shows "Id_on A = Finite_Set.fold (\<lambda>x. Set.insert (Pair x x)) {} A"
 proof -
-  interpret comp_fun_commute "\<lambda>x. Set.insert (Pair x x)" by standard auto
-  show ?thesis using assms unfolding Id_on_def by (induct A) simp_all
+  interpret comp_fun_commute "\<lambda>x. Set.insert (Pair x x)"
+    by standard auto
+  from assms show ?thesis
+    unfolding Id_on_def by (induct A) simp_all
 qed
 
 lemma comp_fun_commute_Image_fold:
   "comp_fun_commute (\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A)"
 proof -
   interpret comp_fun_idem Set.insert
-      by (fact comp_fun_idem_insert)
-  show ?thesis 
-  by standard (auto simp add: fun_eq_iff comp_fun_commute split:prod.split)
+    by (fact comp_fun_idem_insert)
+  show ?thesis
+    by standard (auto simp add: fun_eq_iff comp_fun_commute split: prod.split)
 qed
 
 lemma Image_fold:
   assumes "finite R"
   shows "R `` S = Finite_Set.fold (\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A) {} R"
 proof -
-  interpret comp_fun_commute "(\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A)" 
+  interpret comp_fun_commute "(\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A)"
     by (rule comp_fun_commute_Image_fold)
   have *: "\<And>x F. Set.insert x F `` S = (if fst x \<in> S then Set.insert (snd x) (F `` S) else (F `` S))"
     by (force intro: rev_ImageI)
-  show ?thesis using assms by (induct R) (auto simp: *)
+  show ?thesis
+    using assms by (induct R) (auto simp: *)
 qed
 
 lemma insert_relcomp_union_fold:
@@ -1159,56 +1067,56 @@
   shows "{x} O S \<union> X = Finite_Set.fold (\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A') X S"
 proof -
   interpret comp_fun_commute "\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A'"
-  proof - 
-    interpret comp_fun_idem Set.insert by (fact comp_fun_idem_insert)
+  proof -
+    interpret comp_fun_idem Set.insert
+      by (fact comp_fun_idem_insert)
     show "comp_fun_commute (\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A')"
-    by standard (auto simp add: fun_eq_iff split:prod.split)
+      by standard (auto simp add: fun_eq_iff split: prod.split)
   qed
-  have *: "{x} O S = {(x', z). x' = fst x \<and> (snd x,z) \<in> S}" by (auto simp: relcomp_unfold intro!: exI)
-  show ?thesis unfolding *
-  using \<open>finite S\<close> by (induct S) (auto split: prod.split)
+  have *: "{x} O S = {(x', z). x' = fst x \<and> (snd x, z) \<in> S}"
+    by (auto simp: relcomp_unfold intro!: exI)
+  show ?thesis
+    unfolding * using \<open>finite S\<close> by (induct S) (auto split: prod.split)
 qed
 
 lemma insert_relcomp_fold:
   assumes "finite S"
-  shows "Set.insert x R O S = 
+  shows "Set.insert x R O S =
     Finite_Set.fold (\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A') (R O S) S"
 proof -
-  have "Set.insert x R O S = ({x} O S) \<union> (R O S)" by auto
-  then show ?thesis by (auto simp: insert_relcomp_union_fold[OF assms])
+  have "Set.insert x R O S = ({x} O S) \<union> (R O S)"
+    by auto
+  then show ?thesis
+    by (auto simp: insert_relcomp_union_fold [OF assms])
 qed
 
 lemma comp_fun_commute_relcomp_fold:
   assumes "finite S"
-  shows "comp_fun_commute (\<lambda>(x,y) A. 
+  shows "comp_fun_commute (\<lambda>(x,y) A.
     Finite_Set.fold (\<lambda>(w,z) A'. if y = w then Set.insert (x,z) A' else A') A S)"
 proof -
-  have *: "\<And>a b A. 
+  have *: "\<And>a b A.
     Finite_Set.fold (\<lambda>(w, z) A'. if b = w then Set.insert (a, z) A' else A') A S = {(a,b)} O S \<union> A"
     by (auto simp: insert_relcomp_union_fold[OF assms] cong: if_cong)
-  show ?thesis by standard (auto simp: *)
+  show ?thesis
+    by standard (auto simp: *)
 qed
 
 lemma relcomp_fold:
-  assumes "finite R"
-  assumes "finite S"
-  shows "R O S = Finite_Set.fold 
+  assumes "finite R" "finite S"
+  shows "R O S = Finite_Set.fold
     (\<lambda>(x,y) A. Finite_Set.fold (\<lambda>(w,z) A'. if y = w then Set.insert (x,z) A' else A') A S) {} R"
-  using assms by (induct R)
+  using assms
+  by (induct R)
     (auto simp: comp_fun_commute.fold_insert comp_fun_commute_relcomp_fold insert_relcomp_fold
       cong: if_cong)
 
 text \<open>Misc\<close>
 
 abbreviation (input) transP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
-where \<comment> \<open>FIXME drop\<close>
-  "transP r \<equiv> trans {(x, y). r x y}"
+  where "transP r \<equiv> trans {(x, y). r x y}"  (* FIXME drop *)
 
-abbreviation (input)
-  "RangeP \<equiv> Rangep"
-
-abbreviation (input)
-  "DomainP \<equiv> Domainp"
-
+abbreviation (input) "RangeP \<equiv> Rangep"
+abbreviation (input) "DomainP \<equiv> Domainp"
 
 end
--- a/src/HOL/Statespace/state_space.ML	Wed Jul 06 13:45:52 2016 +0200
+++ b/src/HOL/Statespace/state_space.ML	Wed Jul 06 22:52:10 2016 +0200
@@ -298,7 +298,7 @@
 
 fun add_declaration name decl thy =
   thy
-  |> Named_Target.init name
+  |> Named_Target.init NONE name
   |> (fn lthy => Local_Theory.declaration {syntax = false, pervasive = false} (decl lthy) lthy)
   |> Local_Theory.exit_global;
 
--- a/src/HOL/Transitive_Closure.thy	Wed Jul 06 13:45:52 2016 +0200
+++ b/src/HOL/Transitive_Closure.thy	Wed Jul 06 22:52:10 2016 +0200
@@ -65,67 +65,65 @@
 
 subsection \<open>Reflexive closure\<close>
 
-lemma refl_reflcl[simp]: "refl(r^=)"
-by(simp add:refl_on_def)
+lemma refl_reflcl[simp]: "refl (r\<^sup>=)"
+  by (simp add: refl_on_def)
 
-lemma antisym_reflcl[simp]: "antisym(r^=) = antisym r"
-by(simp add:antisym_def)
+lemma antisym_reflcl[simp]: "antisym (r\<^sup>=) = antisym r"
+  by (simp add: antisym_def)
 
-lemma trans_reflclI[simp]: "trans r \<Longrightarrow> trans(r^=)"
-unfolding trans_def by blast
+lemma trans_reflclI[simp]: "trans r \<Longrightarrow> trans (r\<^sup>=)"
+  unfolding trans_def by blast
 
-lemma reflclp_idemp [simp]: "(P^==)^==  =  P^=="
-by blast
+lemma reflclp_idemp [simp]: "(P\<^sup>=\<^sup>=)\<^sup>=\<^sup>= = P\<^sup>=\<^sup>="
+  by blast
+
 
 subsection \<open>Reflexive-transitive closure\<close>
 
 lemma reflcl_set_eq [pred_set_conv]: "(sup (\<lambda>x y. (x, y) \<in> r) op =) = (\<lambda>x y. (x, y) \<in> r \<union> Id)"
   by (auto simp add: fun_eq_iff)
 
-lemma r_into_rtrancl [intro]: "!!p. p \<in> r ==> p \<in> r^*"
+lemma r_into_rtrancl [intro]: "\<And>p. p \<in> r \<Longrightarrow> p \<in> r\<^sup>*"
   \<comment> \<open>\<open>rtrancl\<close> of \<open>r\<close> contains \<open>r\<close>\<close>
   apply (simp only: split_tupled_all)
   apply (erule rtrancl_refl [THEN rtrancl_into_rtrancl])
   done
 
-lemma r_into_rtranclp [intro]: "r x y ==> r^** x y"
+lemma r_into_rtranclp [intro]: "r x y \<Longrightarrow> r\<^sup>*\<^sup>* x y"
   \<comment> \<open>\<open>rtrancl\<close> of \<open>r\<close> contains \<open>r\<close>\<close>
   by (erule rtranclp.rtrancl_refl [THEN rtranclp.rtrancl_into_rtrancl])
 
-lemma rtranclp_mono: "r \<le> s ==> r^** \<le> s^**"
+lemma rtranclp_mono: "r \<le> s \<Longrightarrow> r\<^sup>*\<^sup>* \<le> s\<^sup>*\<^sup>*"
   \<comment> \<open>monotonicity of \<open>rtrancl\<close>\<close>
   apply (rule predicate2I)
   apply (erule rtranclp.induct)
    apply (rule_tac [2] rtranclp.rtrancl_into_rtrancl, blast+)
   done
 
-lemma mono_rtranclp[mono]:
-   "(\<And>a b. x a b \<longrightarrow> y a b) \<Longrightarrow> x^** a b \<longrightarrow> y^** a b"
+lemma mono_rtranclp[mono]: "(\<And>a b. x a b \<longrightarrow> y a b) \<Longrightarrow> x\<^sup>*\<^sup>* a b \<longrightarrow> y\<^sup>*\<^sup>* a b"
    using rtranclp_mono[of x y] by auto
 
 lemmas rtrancl_mono = rtranclp_mono [to_set]
 
 theorem rtranclp_induct [consumes 1, case_names base step, induct set: rtranclp]:
-  assumes a: "r^** a b"
-    and cases: "P a" "!!y z. [| r^** a y; r y z; P y |] ==> P z"
-  shows "P b" using a
-  by (induct x\<equiv>a b) (rule cases)+
+  assumes a: "r\<^sup>*\<^sup>* a b"
+    and cases: "P a" "\<And>y z. r\<^sup>*\<^sup>* a y \<Longrightarrow> r y z \<Longrightarrow> P y \<Longrightarrow> P z"
+  shows "P b"
+  using a by (induct x\<equiv>a b) (rule cases)+
 
 lemmas rtrancl_induct [induct set: rtrancl] = rtranclp_induct [to_set]
 
 lemmas rtranclp_induct2 =
-  rtranclp_induct[of _ "(ax,ay)" "(bx,by)", split_rule,
-                 consumes 1, case_names refl step]
+  rtranclp_induct[of _ "(ax,ay)" "(bx,by)", split_rule, consumes 1, case_names refl step]
 
 lemmas rtrancl_induct2 =
-  rtrancl_induct[of "(ax,ay)" "(bx,by)", split_format (complete),
-                 consumes 1, case_names refl step]
+  rtrancl_induct[of "(ax,ay)" "(bx,by)", split_format (complete), consumes 1, case_names refl step]
 
-lemma refl_rtrancl: "refl (r^*)"
-by (unfold refl_on_def) fast
+lemma refl_rtrancl: "refl (r\<^sup>*)"
+  unfolding refl_on_def by fast
 
 text \<open>Transitivity of transitive closure.\<close>
-lemma trans_rtrancl: "trans (r^*)"
+lemma trans_rtrancl: "trans (r\<^sup>*)"
 proof (rule transI)
   fix x y z
   assume "(x, y) \<in> r\<^sup>*"
@@ -144,42 +142,40 @@
 lemmas rtrancl_trans = trans_rtrancl [THEN transD]
 
 lemma rtranclp_trans:
-  assumes xy: "r^** x y"
-  and yz: "r^** y z"
-  shows "r^** x z" using yz xy
-  by induct iprover+
+  assumes "r\<^sup>*\<^sup>* x y"
+    and "r\<^sup>*\<^sup>* y z"
+  shows "r\<^sup>*\<^sup>* x z"
+  using assms(2,1) by induct iprover+
 
 lemma rtranclE [cases set: rtrancl]:
-  assumes major: "(a::'a, b) : r^*"
+  fixes a b :: 'a
+  assumes major: "(a, b) \<in> r\<^sup>*"
   obtains
     (base) "a = b"
-  | (step) y where "(a, y) : r^*" and "(y, b) : r"
+  | (step) y where "(a, y) \<in> r\<^sup>*" and "(y, b) \<in> r"
   \<comment> \<open>elimination of \<open>rtrancl\<close> -- by induction on a special formula\<close>
-  apply (subgoal_tac "(a::'a) = b | (EX y. (a,y) : r^* & (y,b) : r)")
+  apply (subgoal_tac "a = b \<or> (\<exists>y. (a, y) \<in> r\<^sup>* \<and> (y, b) \<in> r)")
    apply (rule_tac [2] major [THEN rtrancl_induct])
     prefer 2 apply blast
    prefer 2 apply blast
   apply (erule asm_rl exE disjE conjE base step)+
   done
 
-lemma rtrancl_Int_subset: "[| Id \<subseteq> s; (r^* \<inter> s) O r \<subseteq> s|] ==> r^* \<subseteq> s"
+lemma rtrancl_Int_subset: "Id \<subseteq> s \<Longrightarrow> (r\<^sup>* \<inter> s) O r \<subseteq> s \<Longrightarrow> r\<^sup>* \<subseteq> s"
   apply (rule subsetI)
   apply auto
   apply (erule rtrancl_induct)
   apply auto
   done
 
-lemma converse_rtranclp_into_rtranclp:
-  "r a b \<Longrightarrow> r\<^sup>*\<^sup>* b c \<Longrightarrow> r\<^sup>*\<^sup>* a c"
+lemma converse_rtranclp_into_rtranclp: "r a b \<Longrightarrow> r\<^sup>*\<^sup>* b c \<Longrightarrow> r\<^sup>*\<^sup>* a c"
   by (rule rtranclp_trans) iprover+
 
 lemmas converse_rtrancl_into_rtrancl = converse_rtranclp_into_rtranclp [to_set]
 
-text \<open>
-  \medskip More @{term "r^*"} equations and inclusions.
-\<close>
+text \<open>\<^medskip> More @{term "r\<^sup>*"} equations and inclusions.\<close>
 
-lemma rtranclp_idemp [simp]: "(r^**)^** = r^**"
+lemma rtranclp_idemp [simp]: "(r\<^sup>*\<^sup>*)\<^sup>*\<^sup>* = r\<^sup>*\<^sup>*"
   apply (auto intro!: order_antisym)
   apply (erule rtranclp_induct)
    apply (rule rtranclp.rtrancl_refl)
@@ -188,18 +184,18 @@
 
 lemmas rtrancl_idemp [simp] = rtranclp_idemp [to_set]
 
-lemma rtrancl_idemp_self_comp [simp]: "R^* O R^* = R^*"
+lemma rtrancl_idemp_self_comp [simp]: "R\<^sup>* O R\<^sup>* = R\<^sup>*"
   apply (rule set_eqI)
   apply (simp only: split_tupled_all)
   apply (blast intro: rtrancl_trans)
   done
 
-lemma rtrancl_subset_rtrancl: "r \<subseteq> s^* ==> r^* \<subseteq> s^*"
+lemma rtrancl_subset_rtrancl: "r \<subseteq> s\<^sup>* \<Longrightarrow> r\<^sup>* \<subseteq> s\<^sup>*"
   apply (drule rtrancl_mono)
   apply simp
   done
 
-lemma rtranclp_subset: "R \<le> S ==> S \<le> R^** ==> S^** = R^**"
+lemma rtranclp_subset: "R \<le> S \<Longrightarrow> S \<le> R\<^sup>*\<^sup>* \<Longrightarrow> S\<^sup>*\<^sup>* = R\<^sup>*\<^sup>*"
   apply (drule rtranclp_mono)
   apply (drule rtranclp_mono)
   apply simp
@@ -207,17 +203,17 @@
 
 lemmas rtrancl_subset = rtranclp_subset [to_set]
 
-lemma rtranclp_sup_rtranclp: "(sup (R^**) (S^**))^** = (sup R S)^**"
-by (blast intro!: rtranclp_subset intro: rtranclp_mono [THEN predicate2D])
+lemma rtranclp_sup_rtranclp: "(sup (R\<^sup>*\<^sup>*) (S\<^sup>*\<^sup>*))\<^sup>*\<^sup>* = (sup R S)\<^sup>*\<^sup>*"
+  by (blast intro!: rtranclp_subset intro: rtranclp_mono [THEN predicate2D])
 
 lemmas rtrancl_Un_rtrancl = rtranclp_sup_rtranclp [to_set]
 
-lemma rtranclp_reflclp [simp]: "(R^==)^** = R^**"
-by (blast intro!: rtranclp_subset)
+lemma rtranclp_reflclp [simp]: "(R\<^sup>=\<^sup>=)\<^sup>*\<^sup>* = R\<^sup>*\<^sup>*"
+  by (blast intro!: rtranclp_subset)
 
 lemmas rtrancl_reflcl [simp] = rtranclp_reflclp [to_set]
 
-lemma rtrancl_r_diff_Id: "(r - Id)^* = r^*"
+lemma rtrancl_r_diff_Id: "(r - Id)\<^sup>* = r\<^sup>*"
   apply (rule sym)
   apply (rule rtrancl_subset, blast, clarify)
   apply (rename_tac a b)
@@ -226,39 +222,35 @@
   apply blast
   done
 
-lemma rtranclp_r_diff_Id: "(inf r op ~=)^** = r^**"
+lemma rtranclp_r_diff_Id: "(inf r op \<noteq>)\<^sup>*\<^sup>* = r\<^sup>*\<^sup>*"
   apply (rule sym)
   apply (rule rtranclp_subset)
    apply blast+
   done
 
 theorem rtranclp_converseD:
-  assumes r: "(r^--1)^** x y"
-  shows "r^** y x"
-proof -
-  from r show ?thesis
-    by induct (iprover intro: rtranclp_trans dest!: conversepD)+
-qed
+  assumes "(r\<inverse>\<inverse>)\<^sup>*\<^sup>* x y"
+  shows "r\<^sup>*\<^sup>* y x"
+  using assms by induct (iprover intro: rtranclp_trans dest!: conversepD)+
 
 lemmas rtrancl_converseD = rtranclp_converseD [to_set]
 
 theorem rtranclp_converseI:
-  assumes "r^** y x"
-  shows "(r^--1)^** x y"
-  using assms
-  by induct (iprover intro: rtranclp_trans conversepI)+
+  assumes "r\<^sup>*\<^sup>* y x"
+  shows "(r\<inverse>\<inverse>)\<^sup>*\<^sup>* x y"
+  using assms by induct (iprover intro: rtranclp_trans conversepI)+
 
 lemmas rtrancl_converseI = rtranclp_converseI [to_set]
 
-lemma rtrancl_converse: "(r^-1)^* = (r^*)^-1"
+lemma rtrancl_converse: "(r^-1)\<^sup>* = (r\<^sup>*)^-1"
   by (fast dest!: rtrancl_converseD intro!: rtrancl_converseI)
 
-lemma sym_rtrancl: "sym r ==> sym (r^*)"
+lemma sym_rtrancl: "sym r \<Longrightarrow> sym (r\<^sup>*)"
   by (simp only: sym_conv_converse_eq rtrancl_converse [symmetric])
 
 theorem converse_rtranclp_induct [consumes 1, case_names base step]:
-  assumes major: "r^** a b"
-    and cases: "P b" "!!y z. [| r y z; r^** z b; P z |] ==> P y"
+  assumes major: "r\<^sup>*\<^sup>* a b"
+    and cases: "P b" "\<And>y z. r y z \<Longrightarrow> r\<^sup>*\<^sup>* z b \<Longrightarrow> P z \<Longrightarrow> P y"
   shows "P a"
   using rtranclp_converseI [OF major]
   by induct (iprover intro: cases dest!: conversepD rtranclp_converseD)+
@@ -266,19 +258,17 @@
 lemmas converse_rtrancl_induct = converse_rtranclp_induct [to_set]
 
 lemmas converse_rtranclp_induct2 =
-  converse_rtranclp_induct [of _ "(ax,ay)" "(bx,by)", split_rule,
-                 consumes 1, case_names refl step]
+  converse_rtranclp_induct [of _ "(ax,ay)" "(bx,by)", split_rule, consumes 1, case_names refl step]
 
 lemmas converse_rtrancl_induct2 =
   converse_rtrancl_induct [of "(ax,ay)" "(bx,by)", split_format (complete),
-                 consumes 1, case_names refl step]
+    consumes 1, case_names refl step]
 
 lemma converse_rtranclpE [consumes 1, case_names base step]:
-  assumes major: "r^** x z"
-    and cases: "x=z ==> P"
-      "!!y. [| r x y; r^** y z |] ==> P"
+  assumes major: "r\<^sup>*\<^sup>* x z"
+    and cases: "x = z \<Longrightarrow> P" "\<And>y. r x y \<Longrightarrow> r\<^sup>*\<^sup>* y z \<Longrightarrow> P"
   shows P
-  apply (subgoal_tac "x = z | (EX y. r x y & r^** y z)")
+  apply (subgoal_tac "x = z \<or> (\<exists>y. r x y \<and> r\<^sup>*\<^sup>* y z)")
    apply (rule_tac [2] major [THEN converse_rtranclp_induct])
     prefer 2 apply iprover
    prefer 2 apply iprover
@@ -291,41 +281,42 @@
 
 lemmas converse_rtranclE2 = converse_rtranclE [of "(xa,xb)" "(za,zb)", split_rule]
 
-lemma r_comp_rtrancl_eq: "r O r^* = r^* O r"
+lemma r_comp_rtrancl_eq: "r O r\<^sup>* = r\<^sup>* O r"
   by (blast elim: rtranclE converse_rtranclE
     intro: rtrancl_into_rtrancl converse_rtrancl_into_rtrancl)
 
-lemma rtrancl_unfold: "r^* = Id Un r^* O r"
+lemma rtrancl_unfold: "r\<^sup>* = Id \<union> r\<^sup>* O r"
   by (auto intro: rtrancl_into_rtrancl elim: rtranclE)
 
 lemma rtrancl_Un_separatorE:
-  "(a,b) : (P \<union> Q)^* \<Longrightarrow> \<forall>x y. (a,x) : P^* \<longrightarrow> (x,y) : Q \<longrightarrow> x=y \<Longrightarrow> (a,b) : P^*"
-apply (induct rule:rtrancl.induct)
- apply blast
-apply (blast intro:rtrancl_trans)
-done
+  "(a, b) \<in> (P \<union> Q)\<^sup>* \<Longrightarrow> \<forall>x y. (a, x) \<in> P\<^sup>* \<longrightarrow> (x, y) \<in> Q \<longrightarrow> x = y \<Longrightarrow> (a, b) \<in> P\<^sup>*"
+  apply (induct rule:rtrancl.induct)
+   apply blast
+  apply (blast intro:rtrancl_trans)
+  done
 
 lemma rtrancl_Un_separator_converseE:
-  "(a,b) : (P \<union> Q)^* \<Longrightarrow> \<forall>x y. (x,b) : P^* \<longrightarrow> (y,x) : Q \<longrightarrow> y=x \<Longrightarrow> (a,b) : P^*"
-apply (induct rule:converse_rtrancl_induct)
- apply blast
-apply (blast intro:rtrancl_trans)
-done
+  "(a, b) \<in> (P \<union> Q)\<^sup>* \<Longrightarrow> \<forall>x y. (x, b) \<in> P\<^sup>* \<longrightarrow> (y, x) \<in> Q \<longrightarrow> y = x \<Longrightarrow> (a, b) \<in> P\<^sup>*"
+  apply (induct rule:converse_rtrancl_induct)
+   apply blast
+  apply (blast intro:rtrancl_trans)
+  done
 
 lemma Image_closed_trancl:
-  assumes "r `` X \<subseteq> X" shows "r\<^sup>* `` X = X"
+  assumes "r `` X \<subseteq> X"
+  shows "r\<^sup>* `` X = X"
 proof -
-  from assms have **: "{y. \<exists>x\<in>X. (x, y) \<in> r} \<subseteq> X" by auto
-  have "\<And>x y. (y, x) \<in> r\<^sup>* \<Longrightarrow> y \<in> X \<Longrightarrow> x \<in> X"
+  from assms have **: "{y. \<exists>x\<in>X. (x, y) \<in> r} \<subseteq> X"
+    by auto
+  have "x \<in> X" if 1: "(y, x) \<in> r\<^sup>*" and 2: "y \<in> X" for x y
   proof -
-    fix x y
-    assume *: "y \<in> X"
-    assume "(y, x) \<in> r\<^sup>*"
-    then show "x \<in> X"
+    from 1 show "x \<in> X"
     proof induct
-      case base show ?case by (fact *)
+      case base
+      show ?case by (fact 2)
     next
-      case step with ** show ?case by auto
+      case step
+      with ** show ?case by auto
     qed
   qed
   then show ?thesis by auto
@@ -334,31 +325,30 @@
 
 subsection \<open>Transitive closure\<close>
 
-lemma trancl_mono: "!!p. p \<in> r^+ ==> r \<subseteq> s ==> p \<in> s^+"
+lemma trancl_mono: "\<And>p. p \<in> r\<^sup>+ \<Longrightarrow> r \<subseteq> s \<Longrightarrow> p \<in> s\<^sup>+"
   apply (simp add: split_tupled_all)
   apply (erule trancl.induct)
    apply (iprover dest: subsetD)+
   done
 
-lemma r_into_trancl': "!!p. p : r ==> p : r^+"
+lemma r_into_trancl': "\<And>p. p \<in> r \<Longrightarrow> p \<in> r\<^sup>+"
   by (simp only: split_tupled_all) (erule r_into_trancl)
 
-text \<open>
-  \medskip Conversions between \<open>trancl\<close> and \<open>rtrancl\<close>.
-\<close>
+text \<open>\<^medskip> Conversions between \<open>trancl\<close> and \<open>rtrancl\<close>.\<close>
 
-lemma tranclp_into_rtranclp: "r^++ a b ==> r^** a b"
+lemma tranclp_into_rtranclp: "r\<^sup>+\<^sup>+ a b \<Longrightarrow> r\<^sup>*\<^sup>* a b"
   by (erule tranclp.induct) iprover+
 
 lemmas trancl_into_rtrancl = tranclp_into_rtranclp [to_set]
 
-lemma rtranclp_into_tranclp1: assumes r: "r^** a b"
-  shows "!!c. r b c ==> r^++ a c" using r
-  by induct iprover+
+lemma rtranclp_into_tranclp1:
+  assumes "r\<^sup>*\<^sup>* a b"
+  shows "r b c \<Longrightarrow> r\<^sup>+\<^sup>+ a c"
+  using assms by (induct arbitrary: c) iprover+
 
 lemmas rtrancl_into_trancl1 = rtranclp_into_tranclp1 [to_set]
 
-lemma rtranclp_into_tranclp2: "[| r a b; r^** b c |] ==> r^++ a c"
+lemma rtranclp_into_tranclp2: "r a b \<Longrightarrow> r\<^sup>*\<^sup>* b c \<Longrightarrow> r\<^sup>+\<^sup>+ a c"
   \<comment> \<open>intro rule from \<open>r\<close> and \<open>rtrancl\<close>\<close>
   apply (erule rtranclp.cases)
    apply iprover
@@ -370,26 +360,23 @@
 
 text \<open>Nice induction rule for \<open>trancl\<close>\<close>
 lemma tranclp_induct [consumes 1, case_names base step, induct pred: tranclp]:
-  assumes a: "r^++ a b"
-  and cases: "!!y. r a y ==> P y"
-    "!!y z. r^++ a y ==> r y z ==> P y ==> P z"
-  shows "P b" using a
-  by (induct x\<equiv>a b) (iprover intro: cases)+
+  assumes a: "r\<^sup>+\<^sup>+ a b"
+    and cases: "\<And>y. r a y \<Longrightarrow> P y" "\<And>y z. r\<^sup>+\<^sup>+ a y \<Longrightarrow> r y z \<Longrightarrow> P y \<Longrightarrow> P z"
+  shows "P b"
+  using a by (induct x\<equiv>a b) (iprover intro: cases)+
 
 lemmas trancl_induct [induct set: trancl] = tranclp_induct [to_set]
 
 lemmas tranclp_induct2 =
-  tranclp_induct [of _ "(ax,ay)" "(bx,by)", split_rule,
-    consumes 1, case_names base step]
+  tranclp_induct [of _ "(ax,ay)" "(bx,by)", split_rule, consumes 1, case_names base step]
 
 lemmas trancl_induct2 =
   trancl_induct [of "(ax,ay)" "(bx,by)", split_format (complete),
     consumes 1, case_names base step]
 
 lemma tranclp_trans_induct:
-  assumes major: "r^++ x y"
-    and cases: "!!x y. r x y ==> P x y"
-      "!!x y z. [| r^++ x y; P x y; r^++ y z; P y z |] ==> P x z"
+  assumes major: "r\<^sup>+\<^sup>+ x y"
+    and cases: "\<And>x y. r x y \<Longrightarrow> P x y" "\<And>x y z. r\<^sup>+\<^sup>+ x y \<Longrightarrow> P x y \<Longrightarrow> r\<^sup>+\<^sup>+ y z \<Longrightarrow> P y z \<Longrightarrow> P x z"
   shows "P x y"
   \<comment> \<open>Another induction rule for trancl, incorporating transitivity\<close>
   by (iprover intro: major [THEN tranclp_induct] cases)
@@ -397,49 +384,49 @@
 lemmas trancl_trans_induct = tranclp_trans_induct [to_set]
 
 lemma tranclE [cases set: trancl]:
-  assumes "(a, b) : r^+"
+  assumes "(a, b) \<in> r\<^sup>+"
   obtains
-    (base) "(a, b) : r"
-  | (step) c where "(a, c) : r^+" and "(c, b) : r"
+    (base) "(a, b) \<in> r"
+  | (step) c where "(a, c) \<in> r\<^sup>+" and "(c, b) \<in> r"
   using assms by cases simp_all
 
-lemma trancl_Int_subset: "[| r \<subseteq> s; (r^+ \<inter> s) O r \<subseteq> s|] ==> r^+ \<subseteq> s"
+lemma trancl_Int_subset: "r \<subseteq> s \<Longrightarrow> (r\<^sup>+ \<inter> s) O r \<subseteq> s \<Longrightarrow> r\<^sup>+ \<subseteq> s"
   apply (rule subsetI)
   apply auto
   apply (erule trancl_induct)
   apply auto
   done
 
-lemma trancl_unfold: "r^+ = r Un r^+ O r"
+lemma trancl_unfold: "r\<^sup>+ = r \<union> r\<^sup>+ O r"
   by (auto intro: trancl_into_trancl elim: tranclE)
 
-text \<open>Transitivity of @{term "r^+"}\<close>
-lemma trans_trancl [simp]: "trans (r^+)"
+text \<open>Transitivity of @{term "r\<^sup>+"}\<close>
+lemma trans_trancl [simp]: "trans (r\<^sup>+)"
 proof (rule transI)
   fix x y z
-  assume "(x, y) \<in> r^+"
-  assume "(y, z) \<in> r^+"
-  then show "(x, z) \<in> r^+"
+  assume "(x, y) \<in> r\<^sup>+"
+  assume "(y, z) \<in> r\<^sup>+"
+  then show "(x, z) \<in> r\<^sup>+"
   proof induct
     case (base u)
-    from \<open>(x, y) \<in> r^+\<close> and \<open>(y, u) \<in> r\<close>
-    show "(x, u) \<in> r^+" ..
+    from \<open>(x, y) \<in> r\<^sup>+\<close> and \<open>(y, u) \<in> r\<close>
+    show "(x, u) \<in> r\<^sup>+" ..
   next
     case (step u v)
-    from \<open>(x, u) \<in> r^+\<close> and \<open>(u, v) \<in> r\<close>
-    show "(x, v) \<in> r^+" ..
+    from \<open>(x, u) \<in> r\<^sup>+\<close> and \<open>(u, v) \<in> r\<close>
+    show "(x, v) \<in> r\<^sup>+" ..
   qed
 qed
 
 lemmas trancl_trans = trans_trancl [THEN transD]
 
 lemma tranclp_trans:
-  assumes xy: "r^++ x y"
-  and yz: "r^++ y z"
-  shows "r^++ x z" using yz xy
-  by induct iprover+
+  assumes "r\<^sup>+\<^sup>+ x y"
+    and "r\<^sup>+\<^sup>+ y z"
+  shows "r\<^sup>+\<^sup>+ x z"
+  using assms(2,1) by induct iprover+
 
-lemma trancl_id [simp]: "trans r \<Longrightarrow> r^+ = r"
+lemma trancl_id [simp]: "trans r \<Longrightarrow> r\<^sup>+ = r"
   apply auto
   apply (erule trancl_induct)
    apply assumption
@@ -448,18 +435,18 @@
   done
 
 lemma rtranclp_tranclp_tranclp:
-  assumes "r^** x y"
-  shows "!!z. r^++ y z ==> r^++ x z" using assms
-  by induct (iprover intro: tranclp_trans)+
+  assumes "r\<^sup>*\<^sup>* x y"
+  shows "\<And>z. r\<^sup>+\<^sup>+ y z \<Longrightarrow> r\<^sup>+\<^sup>+ x z"
+  using assms by induct (iprover intro: tranclp_trans)+
 
 lemmas rtrancl_trancl_trancl = rtranclp_tranclp_tranclp [to_set]
 
-lemma tranclp_into_tranclp2: "r a b ==> r^++ b c ==> r^++ a c"
+lemma tranclp_into_tranclp2: "r a b \<Longrightarrow> r\<^sup>+\<^sup>+ b c \<Longrightarrow> r\<^sup>+\<^sup>+ a c"
   by (erule tranclp_trans [OF tranclp.r_into_trancl])
 
 lemmas trancl_into_trancl2 = tranclp_into_tranclp2 [to_set]
 
-lemma tranclp_converseI: "(r^++)^--1 x y ==> (r^--1)^++ x y"
+lemma tranclp_converseI: "(r\<^sup>+\<^sup>+)\<inverse>\<inverse> x y \<Longrightarrow> (r\<inverse>\<inverse>)\<^sup>+\<^sup>+ x y"
   apply (drule conversepD)
   apply (erule tranclp_induct)
   apply (iprover intro: conversepI tranclp_trans)+
@@ -467,7 +454,7 @@
 
 lemmas trancl_converseI = tranclp_converseI [to_set]
 
-lemma tranclp_converseD: "(r^--1)^++ x y ==> (r^++)^--1 x y"
+lemma tranclp_converseD: "(r\<inverse>\<inverse>)\<^sup>+\<^sup>+ x y \<Longrightarrow> (r\<^sup>+\<^sup>+)\<inverse>\<inverse> x y"
   apply (rule conversepI)
   apply (erule tranclp_induct)
   apply (iprover dest: conversepD intro: tranclp_trans)+
@@ -475,19 +462,17 @@
 
 lemmas trancl_converseD = tranclp_converseD [to_set]
 
-lemma tranclp_converse: "(r^--1)^++ = (r^++)^--1"
-  by (fastforce simp add: fun_eq_iff
-    intro!: tranclp_converseI dest!: tranclp_converseD)
+lemma tranclp_converse: "(r\<inverse>\<inverse>)\<^sup>+\<^sup>+ = (r\<^sup>+\<^sup>+)\<inverse>\<inverse>"
+  by (fastforce simp add: fun_eq_iff intro!: tranclp_converseI dest!: tranclp_converseD)
 
 lemmas trancl_converse = tranclp_converse [to_set]
 
-lemma sym_trancl: "sym r ==> sym (r^+)"
+lemma sym_trancl: "sym r \<Longrightarrow> sym (r\<^sup>+)"
   by (simp only: sym_conv_converse_eq trancl_converse [symmetric])
 
 lemma converse_tranclp_induct [consumes 1, case_names base step]:
-  assumes major: "r^++ a b"
-    and cases: "!!y. r y b ==> P(y)"
-      "!!y z.[| r y z;  r^++ z b;  P(z) |] ==> P(y)"
+  assumes major: "r\<^sup>+\<^sup>+ a b"
+    and cases: "\<And>y. r y b \<Longrightarrow> P y" "\<And>y z. r y z \<Longrightarrow> r\<^sup>+\<^sup>+ z b \<Longrightarrow> P z \<Longrightarrow> P y"
   shows "P a"
   apply (rule tranclp_induct [OF tranclp_converseI, OF conversepI, OF major])
    apply (rule cases)
@@ -497,7 +482,7 @@
 
 lemmas converse_trancl_induct = converse_tranclp_induct [to_set]
 
-lemma tranclpD: "R^++ x y ==> EX z. R x z \<and> R^** z y"
+lemma tranclpD: "R\<^sup>+\<^sup>+ x y \<Longrightarrow> \<exists>z. R x z \<and> R\<^sup>*\<^sup>* z y"
   apply (erule converse_tranclp_induct)
    apply auto
   apply (blast intro: rtranclp_trans)
@@ -507,48 +492,48 @@
 
 lemma converse_tranclpE:
   assumes major: "tranclp r x z"
-  assumes base: "r x z ==> P"
-  assumes step: "\<And> y. [| r x y; tranclp r y z |] ==> P"
+    and base: "r x z \<Longrightarrow> P"
+    and step: "\<And> y. r x y \<Longrightarrow> tranclp r y z \<Longrightarrow> P"
   shows P
 proof -
-  from tranclpD[OF major]
-  obtain y where "r x y" and "rtranclp r y z" by iprover
+  from tranclpD [OF major] obtain y where "r x y" and "rtranclp r y z"
+    by iprover
   from this(2) show P
   proof (cases rule: rtranclp.cases)
     case rtrancl_refl
-    with \<open>r x y\<close> base show P by iprover
+    with \<open>r x y\<close> base show P
+      by iprover
   next
     case rtrancl_into_rtrancl
     from this have "tranclp r y z"
       by (iprover intro: rtranclp_into_tranclp1)
-    with \<open>r x y\<close> step show P by iprover
+    with \<open>r x y\<close> step show P
+      by iprover
   qed
 qed
 
 lemmas converse_tranclE = converse_tranclpE [to_set]
 
-lemma tranclD2:
-  "(x, y) \<in> R\<^sup>+ \<Longrightarrow> \<exists>z. (x, z) \<in> R\<^sup>* \<and> (z, y) \<in> R"
+lemma tranclD2: "(x, y) \<in> R\<^sup>+ \<Longrightarrow> \<exists>z. (x, z) \<in> R\<^sup>* \<and> (z, y) \<in> R"
   by (blast elim: tranclE intro: trancl_into_rtrancl)
 
-lemma irrefl_tranclI: "r^-1 \<inter> r^* = {} ==> (x, x) \<notin> r^+"
+lemma irrefl_tranclI: "r\<inverse> \<inter> r\<^sup>* = {} \<Longrightarrow> (x, x) \<notin> r\<^sup>+"
   by (blast elim: tranclE dest: trancl_into_rtrancl)
 
-lemma irrefl_trancl_rD: "\<forall>x. (x, x) \<notin> r^+ \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> x \<noteq> y"
+lemma irrefl_trancl_rD: "\<forall>x. (x, x) \<notin> r\<^sup>+ \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> x \<noteq> y"
   by (blast dest: r_into_trancl)
 
-lemma trancl_subset_Sigma_aux:
-    "(a, b) \<in> r^* ==> r \<subseteq> A \<times> A ==> a = b \<or> a \<in> A"
+lemma trancl_subset_Sigma_aux: "(a, b) \<in> r\<^sup>* \<Longrightarrow> r \<subseteq> A \<times> A \<Longrightarrow> a = b \<or> a \<in> A"
   by (induct rule: rtrancl_induct) auto
 
-lemma trancl_subset_Sigma: "r \<subseteq> A \<times> A ==> r^+ \<subseteq> A \<times> A"
+lemma trancl_subset_Sigma: "r \<subseteq> A \<times> A \<Longrightarrow> r\<^sup>+ \<subseteq> A \<times> A"
   apply (rule subsetI)
   apply (simp only: split_tupled_all)
   apply (erule tranclE)
    apply (blast dest!: trancl_into_rtrancl trancl_subset_Sigma_aux)+
   done
 
-lemma reflclp_tranclp [simp]: "(r^++)^== = r^**"
+lemma reflclp_tranclp [simp]: "(r\<^sup>+\<^sup>+)\<^sup>=\<^sup>= = r\<^sup>*\<^sup>*"
   apply (safe intro!: order_antisym)
    apply (erule tranclp_into_rtranclp)
   apply (blast elim: rtranclp.cases dest: rtranclp_into_tranclp1)
@@ -556,7 +541,7 @@
 
 lemmas reflcl_trancl [simp] = reflclp_tranclp [to_set]
 
-lemma trancl_reflcl [simp]: "(r^=)^+ = r^*"
+lemma trancl_reflcl [simp]: "(r\<^sup>=)\<^sup>+ = r\<^sup>*"
   apply safe
    apply (drule trancl_into_rtrancl, simp)
   apply (erule rtranclE, safe)
@@ -565,32 +550,30 @@
    apply (erule rtrancl_reflcl [THEN equalityD2, THEN subsetD], fast)
   done
 
-lemma rtrancl_trancl_reflcl [code]: "r^* = (r^+)^="
+lemma rtrancl_trancl_reflcl [code]: "r\<^sup>* = (r\<^sup>+)\<^sup>="
   by simp
 
-lemma trancl_empty [simp]: "{}^+ = {}"
+lemma trancl_empty [simp]: "{}\<^sup>+ = {}"
   by (auto elim: trancl_induct)
 
-lemma rtrancl_empty [simp]: "{}^* = Id"
+lemma rtrancl_empty [simp]: "{}\<^sup>* = Id"
   by (rule subst [OF reflcl_trancl]) simp
 
-lemma rtranclpD: "R^** a b ==> a = b \<or> a \<noteq> b \<and> R^++ a b"
-by (force simp add: reflclp_tranclp [symmetric] simp del: reflclp_tranclp)
+lemma rtranclpD: "R\<^sup>*\<^sup>* a b \<Longrightarrow> a = b \<or> a \<noteq> b \<and> R\<^sup>+\<^sup>+ a b"
+  by (force simp add: reflclp_tranclp [symmetric] simp del: reflclp_tranclp)
 
 lemmas rtranclD = rtranclpD [to_set]
 
-lemma rtrancl_eq_or_trancl:
-  "(x,y) \<in> R\<^sup>* = (x=y \<or> x\<noteq>y \<and> (x,y) \<in> R\<^sup>+)"
+lemma rtrancl_eq_or_trancl: "(x,y) \<in> R\<^sup>* \<longleftrightarrow> x = y \<or> x \<noteq> y \<and> (x, y) \<in> R\<^sup>+"
   by (fast elim: trancl_into_rtrancl dest: rtranclD)
 
-lemma trancl_unfold_right: "r^+ = r^* O r"
-by (auto dest: tranclD2 intro: rtrancl_into_trancl1)
+lemma trancl_unfold_right: "r\<^sup>+ = r\<^sup>* O r"
+  by (auto dest: tranclD2 intro: rtrancl_into_trancl1)
 
-lemma trancl_unfold_left: "r^+ = r O r^*"
-by (auto dest: tranclD intro: rtrancl_into_trancl2)
+lemma trancl_unfold_left: "r\<^sup>+ = r O r\<^sup>*"
+  by (auto dest: tranclD intro: rtrancl_into_trancl2)
 
-lemma trancl_insert:
-  "(insert (y, x) r)^+ = r^+ \<union> {(a, b). (a, y) \<in> r^* \<and> (x, b) \<in> r^*}"
+lemma trancl_insert: "(insert (y, x) r)\<^sup>+ = r\<^sup>+ \<union> {(a, b). (a, y) \<in> r\<^sup>* \<and> (x, b) \<in> r\<^sup>*}"
   \<comment> \<open>primitive recursion for \<open>trancl\<close> over finite relations\<close>
   apply (rule equalityI)
    apply (rule subsetI)
@@ -603,62 +586,60 @@
   done
 
 lemma trancl_insert2:
-  "(insert (a,b) r)^+ = r^+ \<union> {(x,y). ((x,a) : r^+ \<or> x=a) \<and> ((b,y) \<in> r^+ \<or> y=b)}"
-by(auto simp add: trancl_insert rtrancl_eq_or_trancl)
+  "(insert (a, b) r)\<^sup>+ = r\<^sup>+ \<union> {(x, y). ((x, a) \<in> r\<^sup>+ \<or> x = a) \<and> ((b, y) \<in> r\<^sup>+ \<or> y = b)}"
+  by (auto simp add: trancl_insert rtrancl_eq_or_trancl)
 
-lemma rtrancl_insert:
-  "(insert (a,b) r)^* = r^* \<union> {(x,y). (x,a) : r^* \<and> (b,y) \<in> r^*}"
-using trancl_insert[of a b r]
-by(simp add: rtrancl_trancl_reflcl del: reflcl_trancl) blast
+lemma rtrancl_insert: "(insert (a,b) r)\<^sup>* = r\<^sup>* \<union> {(x, y). (x, a) \<in> r\<^sup>* \<and> (b, y) \<in> r\<^sup>*}"
+  using trancl_insert[of a b r]
+  by (simp add: rtrancl_trancl_reflcl del: reflcl_trancl) blast
 
 
 text \<open>Simplifying nested closures\<close>
 
-lemma rtrancl_trancl_absorb[simp]: "(R^*)^+ = R^*"
-by (simp add: trans_rtrancl)
+lemma rtrancl_trancl_absorb[simp]: "(R\<^sup>*)\<^sup>+ = R\<^sup>*"
+  by (simp add: trans_rtrancl)
 
-lemma trancl_rtrancl_absorb[simp]: "(R^+)^* = R^*"
-by (subst reflcl_trancl[symmetric]) simp
+lemma trancl_rtrancl_absorb[simp]: "(R\<^sup>+)\<^sup>* = R\<^sup>*"
+  by (subst reflcl_trancl[symmetric]) simp
 
-lemma rtrancl_reflcl_absorb[simp]: "(R^*)^= = R^*"
-by auto
+lemma rtrancl_reflcl_absorb[simp]: "(R\<^sup>*)\<^sup>= = R\<^sup>*"
+  by auto
 
 
 text \<open>\<open>Domain\<close> and \<open>Range\<close>\<close>
 
-lemma Domain_rtrancl [simp]: "Domain (R^*) = UNIV"
+lemma Domain_rtrancl [simp]: "Domain (R\<^sup>*) = UNIV"
   by blast
 
-lemma Range_rtrancl [simp]: "Range (R^*) = UNIV"
+lemma Range_rtrancl [simp]: "Range (R\<^sup>*) = UNIV"
   by blast
 
-lemma rtrancl_Un_subset: "(R^* \<union> S^*) \<subseteq> (R Un S)^*"
+lemma rtrancl_Un_subset: "(R\<^sup>* \<union> S\<^sup>*) \<subseteq> (R \<union> S)\<^sup>*"
   by (rule rtrancl_Un_rtrancl [THEN subst]) fast
 
-lemma in_rtrancl_UnI: "x \<in> R^* \<or> x \<in> S^* ==> x \<in> (R \<union> S)^*"
+lemma in_rtrancl_UnI: "x \<in> R\<^sup>* \<or> x \<in> S\<^sup>* \<Longrightarrow> x \<in> (R \<union> S)\<^sup>*"
   by (blast intro: subsetD [OF rtrancl_Un_subset])
 
-lemma trancl_domain [simp]: "Domain (r^+) = Domain r"
+lemma trancl_domain [simp]: "Domain (r\<^sup>+) = Domain r"
   by (unfold Domain_unfold) (blast dest: tranclD)
 
-lemma trancl_range [simp]: "Range (r^+) = Range r"
+lemma trancl_range [simp]: "Range (r\<^sup>+) = Range r"
   unfolding Domain_converse [symmetric] by (simp add: trancl_converse [symmetric])
 
-lemma Not_Domain_rtrancl:
-    "x ~: Domain R ==> ((x, y) : R^*) = (x = y)"
+lemma Not_Domain_rtrancl: "x \<notin> Domain R \<Longrightarrow> (x, y) \<in> R\<^sup>* \<longleftrightarrow> x = y"
   apply auto
   apply (erule rev_mp)
   apply (erule rtrancl_induct)
    apply auto
   done
 
-lemma trancl_subset_Field2: "r^+ <= Field r \<times> Field r"
+lemma trancl_subset_Field2: "r\<^sup>+ \<subseteq> Field r \<times> Field r"
   apply clarify
   apply (erule trancl_induct)
    apply (auto simp add: Field_def)
   done
 
-lemma finite_trancl[simp]: "finite (r^+) = finite r"
+lemma finite_trancl[simp]: "finite (r\<^sup>+) = finite r"
   apply auto
    prefer 2
    apply (rule trancl_subset_Field2 [THEN finite_subset])
@@ -672,8 +653,7 @@
   be merged with main body.\<close>
 
 lemma single_valued_confluent:
-  "\<lbrakk> single_valued r; (x,y) \<in> r^*; (x,z) \<in> r^* \<rbrakk>
-  \<Longrightarrow> (y,z) \<in> r^* \<or> (z,y) \<in> r^*"
+  "single_valued r \<Longrightarrow> (x, y) \<in> r\<^sup>* \<Longrightarrow> (x, z) \<in> r\<^sup>* \<Longrightarrow> (y, z) \<in> r\<^sup>* \<or> (z, y) \<in> r\<^sup>*"
   apply (erule rtrancl_induct)
   apply simp
   apply (erule disjE)
@@ -681,18 +661,16 @@
   apply(blast intro:rtrancl_trans)
   done
 
-lemma r_r_into_trancl: "(a, b) \<in> R ==> (b, c) \<in> R ==> (a, c) \<in> R^+"
+lemma r_r_into_trancl: "(a, b) \<in> R \<Longrightarrow> (b, c) \<in> R \<Longrightarrow> (a, c) \<in> R\<^sup>+"
   by (fast intro: trancl_trans)
 
-lemma trancl_into_trancl [rule_format]:
-    "(a, b) \<in> r\<^sup>+ ==> (b, c) \<in> r --> (a,c) \<in> r\<^sup>+"
-  apply (erule trancl_induct)
+lemma trancl_into_trancl: "(a, b) \<in> r\<^sup>+ \<Longrightarrow> (b, c) \<in> r \<Longrightarrow> (a, c) \<in> r\<^sup>+"
+  apply (induct rule: trancl_induct)
    apply (fast intro: r_r_into_trancl)
   apply (fast intro: r_r_into_trancl trancl_trans)
   done
 
-lemma tranclp_rtranclp_tranclp:
-    "r\<^sup>+\<^sup>+ a b ==> r\<^sup>*\<^sup>* b c ==> r\<^sup>+\<^sup>+ a c"
+lemma tranclp_rtranclp_tranclp: "r\<^sup>+\<^sup>+ a b \<Longrightarrow> r\<^sup>*\<^sup>* b c \<Longrightarrow> r\<^sup>+\<^sup>+ a c"
   apply (drule tranclpD)
   apply (elim exE conjE)
   apply (drule rtranclp_trans, assumption)
@@ -715,37 +693,39 @@
 
 declare trancl_into_rtrancl [elim]
 
+
 subsection \<open>The power operation on relations\<close>
 
-text \<open>\<open>R ^^ n = R O ... O R\<close>, the n-fold composition of \<open>R\<close>\<close>
+text \<open>\<open>R ^^ n = R O \<dots> O R\<close>, the n-fold composition of \<open>R\<close>\<close>
 
 overloading
-  relpow == "compow :: nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set"
-  relpowp == "compow :: nat \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool)"
+  relpow \<equiv> "compow :: nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set"
+  relpowp \<equiv> "compow :: nat \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool)"
 begin
 
-primrec relpow :: "nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set" where
-    "relpow 0 R = Id"
-  | "relpow (Suc n) R = (R ^^ n) O R"
+primrec relpow :: "nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set"
+where
+  "relpow 0 R = Id"
+| "relpow (Suc n) R = (R ^^ n) O R"
 
-primrec relpowp :: "nat \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool)" where
-    "relpowp 0 R = HOL.eq"
-  | "relpowp (Suc n) R = (R ^^ n) OO R"
+primrec relpowp :: "nat \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool)"
+where
+  "relpowp 0 R = HOL.eq"
+| "relpowp (Suc n) R = (R ^^ n) OO R"
 
 end
 
 lemma relpowp_relpow_eq [pred_set_conv]:
-  fixes R :: "'a rel"
-  shows "(\<lambda>x y. (x, y) \<in> R) ^^ n = (\<lambda>x y. (x, y) \<in> R ^^ n)"
+  "(\<lambda>x y. (x, y) \<in> R) ^^ n = (\<lambda>x y. (x, y) \<in> R ^^ n)" for R :: "'a rel"
   by (induct n) (simp_all add: relcompp_relcomp_eq)
 
-text \<open>for code generation\<close>
+text \<open>For code generation:\<close>
 
-definition relpow :: "nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set" where
-  relpow_code_def [code_abbrev]: "relpow = compow"
+definition relpow :: "nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set"
+  where relpow_code_def [code_abbrev]: "relpow = compow"
 
-definition relpowp :: "nat \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool)" where
-  relpowp_code_def [code_abbrev]: "relpowp = compow"
+definition relpowp :: "nat \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool)"
+  where relpowp_code_def [code_abbrev]: "relpowp = compow"
 
 lemma [code]:
   "relpow (Suc n) R = (relpow n R) O R"
@@ -760,54 +740,40 @@
 hide_const (open) relpow
 hide_const (open) relpowp
 
-lemma relpow_1 [simp]:
-  fixes R :: "('a \<times> 'a) set"
-  shows "R ^^ 1 = R"
+lemma relpow_1 [simp]: "R ^^ 1 = R" for R :: "('a \<times> 'a) set"
   by simp
 
-lemma relpowp_1 [simp]:
-  fixes P :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
-  shows "P ^^ 1 = P"
+lemma relpowp_1 [simp]: "P ^^ 1 = P" for P :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   by (fact relpow_1 [to_pred])
 
-lemma relpow_0_I: 
-  "(x, x) \<in> R ^^ 0"
+lemma relpow_0_I: "(x, x) \<in> R ^^ 0"
   by simp
 
-lemma relpowp_0_I:
-  "(P ^^ 0) x x"
+lemma relpowp_0_I: "(P ^^ 0) x x"
   by (fact relpow_0_I [to_pred])
 
-lemma relpow_Suc_I:
-  "(x, y) \<in>  R ^^ n \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> (x, z) \<in> R ^^ Suc n"
+lemma relpow_Suc_I: "(x, y) \<in>  R ^^ n \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> (x, z) \<in> R ^^ Suc n"
   by auto
 
-lemma relpowp_Suc_I:
-  "(P ^^ n) x y \<Longrightarrow> P y z \<Longrightarrow> (P ^^ Suc n) x z"
+lemma relpowp_Suc_I: "(P ^^ n) x y \<Longrightarrow> P y z \<Longrightarrow> (P ^^ Suc n) x z"
   by (fact relpow_Suc_I [to_pred])
 
-lemma relpow_Suc_I2:
-  "(x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ n \<Longrightarrow> (x, z) \<in> R ^^ Suc n"
+lemma relpow_Suc_I2: "(x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ n \<Longrightarrow> (x, z) \<in> R ^^ Suc n"
   by (induct n arbitrary: z) (simp, fastforce)
 
-lemma relpowp_Suc_I2:
-  "P x y \<Longrightarrow> (P ^^ n) y z \<Longrightarrow> (P ^^ Suc n) x z"
+lemma relpowp_Suc_I2: "P x y \<Longrightarrow> (P ^^ n) y z \<Longrightarrow> (P ^^ Suc n) x z"
   by (fact relpow_Suc_I2 [to_pred])
 
-lemma relpow_0_E:
-  "(x, y) \<in> R ^^ 0 \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> P"
+lemma relpow_0_E: "(x, y) \<in> R ^^ 0 \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> P"
   by simp
 
-lemma relpowp_0_E:
-  "(P ^^ 0) x y \<Longrightarrow> (x = y \<Longrightarrow> Q) \<Longrightarrow> Q"
+lemma relpowp_0_E: "(P ^^ 0) x y \<Longrightarrow> (x = y \<Longrightarrow> Q) \<Longrightarrow> Q"
   by (fact relpow_0_E [to_pred])
 
-lemma relpow_Suc_E:
-  "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<And>y. (x, y) \<in> R ^^ n \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> P) \<Longrightarrow> P"
+lemma relpow_Suc_E: "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<And>y. (x, y) \<in> R ^^ n \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> P) \<Longrightarrow> P"
   by auto
 
-lemma relpowp_Suc_E:
-  "(P ^^ Suc n) x z \<Longrightarrow> (\<And>y. (P ^^ n) x y \<Longrightarrow> P y z \<Longrightarrow> Q) \<Longrightarrow> Q"
+lemma relpowp_Suc_E: "(P ^^ Suc n) x z \<Longrightarrow> (\<And>y. (P ^^ n) x y \<Longrightarrow> P y z \<Longrightarrow> Q) \<Longrightarrow> Q"
   by (fact relpow_Suc_E [to_pred])
 
 lemma relpow_E:
@@ -822,31 +788,25 @@
   \<Longrightarrow> Q"
   by (fact relpow_E [to_pred])
 
-lemma relpow_Suc_D2:
-  "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<exists>y. (x, y) \<in> R \<and> (y, z) \<in> R ^^ n)"
+lemma relpow_Suc_D2: "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<exists>y. (x, y) \<in> R \<and> (y, z) \<in> R ^^ n)"
   apply (induct n arbitrary: x z)
    apply (blast intro: relpow_0_I elim: relpow_0_E relpow_Suc_E)
   apply (blast intro: relpow_Suc_I elim: relpow_0_E relpow_Suc_E)
   done
 
-lemma relpowp_Suc_D2:
-  "(P ^^ Suc n) x z \<Longrightarrow> \<exists>y. P x y \<and> (P ^^ n) y z"
+lemma relpowp_Suc_D2: "(P ^^ Suc n) x z \<Longrightarrow> \<exists>y. P x y \<and> (P ^^ n) y z"
   by (fact relpow_Suc_D2 [to_pred])
 
-lemma relpow_Suc_E2:
-  "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<And>y. (x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ n \<Longrightarrow> P) \<Longrightarrow> P"
+lemma relpow_Suc_E2: "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<And>y. (x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ n \<Longrightarrow> P) \<Longrightarrow> P"
   by (blast dest: relpow_Suc_D2)
 
-lemma relpowp_Suc_E2:
-  "(P ^^ Suc n) x z \<Longrightarrow> (\<And>y. P x y \<Longrightarrow> (P ^^ n) y z \<Longrightarrow> Q) \<Longrightarrow> Q"
+lemma relpowp_Suc_E2: "(P ^^ Suc n) x z \<Longrightarrow> (\<And>y. P x y \<Longrightarrow> (P ^^ n) y z \<Longrightarrow> Q) \<Longrightarrow> Q"
   by (fact relpow_Suc_E2 [to_pred])
 
-lemma relpow_Suc_D2':
-  "\<forall>x y z. (x, y) \<in> R ^^ n \<and> (y, z) \<in> R \<longrightarrow> (\<exists>w. (x, w) \<in> R \<and> (w, z) \<in> R ^^ n)"
+lemma relpow_Suc_D2': "\<forall>x y z. (x, y) \<in> R ^^ n \<and> (y, z) \<in> R \<longrightarrow> (\<exists>w. (x, w) \<in> R \<and> (w, z) \<in> R ^^ n)"
   by (induct n) (simp_all, blast)
 
-lemma relpowp_Suc_D2':
-  "\<forall>x y z. (P ^^ n) x y \<and> P y z \<longrightarrow> (\<exists>w. P x w \<and> (P ^^ n) w z)"
+lemma relpowp_Suc_D2': "\<forall>x y z. (P ^^ n) x y \<and> P y z \<longrightarrow> (\<exists>w. P x w \<and> (P ^^ n) w z)"
   by (fact relpow_Suc_D2' [to_pred])
 
 lemma relpow_E2:
@@ -864,83 +824,78 @@
   \<Longrightarrow> Q"
   by (fact relpow_E2 [to_pred])
 
-lemma relpow_add: "R ^^ (m+n) = R^^m O R^^n"
+lemma relpow_add: "R ^^ (m + n) = R^^m O R^^n"
   by (induct n) auto
 
 lemma relpowp_add: "P ^^ (m + n) = P ^^ m OO P ^^ n"
   by (fact relpow_add [to_pred])
 
 lemma relpow_commute: "R O R ^^ n = R ^^ n O R"
-  by (induct n) (simp, simp add: O_assoc [symmetric])
+  by (induct n) (simp_all add: O_assoc [symmetric])
 
 lemma relpowp_commute: "P OO P ^^ n = P ^^ n OO P"
   by (fact relpow_commute [to_pred])
 
-lemma relpow_empty:
-  "0 < n \<Longrightarrow> ({} :: ('a \<times> 'a) set) ^^ n = {}"
+lemma relpow_empty: "0 < n \<Longrightarrow> ({} :: ('a \<times> 'a) set) ^^ n = {}"
   by (cases n) auto
 
-lemma relpowp_bot:
-  "0 < n \<Longrightarrow> (\<bottom> :: 'a \<Rightarrow> 'a \<Rightarrow> bool) ^^ n = \<bottom>"
+lemma relpowp_bot: "0 < n \<Longrightarrow> (\<bottom> :: 'a \<Rightarrow> 'a \<Rightarrow> bool) ^^ n = \<bottom>"
   by (fact relpow_empty [to_pred])
 
 lemma rtrancl_imp_UN_relpow:
-  assumes "p \<in> R^*"
+  assumes "p \<in> R\<^sup>*"
   shows "p \<in> (\<Union>n. R ^^ n)"
 proof (cases p)
   case (Pair x y)
-  with assms have "(x, y) \<in> R^*" by simp
+  with assms have "(x, y) \<in> R\<^sup>*" by simp
   then have "(x, y) \<in> (\<Union>n. R ^^ n)" proof induct
-    case base show ?case by (blast intro: relpow_0_I)
+    case base
+    show ?case by (blast intro: relpow_0_I)
   next
-    case step then show ?case by (blast intro: relpow_Suc_I)
+    case step
+    then show ?case by (blast intro: relpow_Suc_I)
   qed
   with Pair show ?thesis by simp
 qed
 
 lemma rtranclp_imp_Sup_relpowp:
-  assumes "(P^**) x y"
+  assumes "(P\<^sup>*\<^sup>*) x y"
   shows "(\<Squnion>n. P ^^ n) x y"
   using assms and rtrancl_imp_UN_relpow [of "(x, y)", to_pred] by simp
 
 lemma relpow_imp_rtrancl:
   assumes "p \<in> R ^^ n"
-  shows "p \<in> R^*"
+  shows "p \<in> R\<^sup>*"
 proof (cases p)
   case (Pair x y)
   with assms have "(x, y) \<in> R ^^ n" by simp
-  then have "(x, y) \<in> R^*" proof (induct n arbitrary: x y)
-    case 0 then show ?case by simp
+  then have "(x, y) \<in> R\<^sup>*" proof (induct n arbitrary: x y)
+    case 0
+    then show ?case by simp
   next
-    case Suc then show ?case
+    case Suc
+    then show ?case
       by (blast elim: relpow_Suc_E intro: rtrancl_into_rtrancl)
   qed
   with Pair show ?thesis by simp
 qed
 
-lemma relpowp_imp_rtranclp:
-  assumes "(P ^^ n) x y"
-  shows "(P^**) x y"
-  using assms and relpow_imp_rtrancl [of "(x, y)", to_pred] by simp
+lemma relpowp_imp_rtranclp: "(P ^^ n) x y \<Longrightarrow> (P\<^sup>*\<^sup>*) x y"
+  using relpow_imp_rtrancl [of "(x, y)", to_pred] by simp
 
-lemma rtrancl_is_UN_relpow:
-  "R^* = (\<Union>n. R ^^ n)"
+lemma rtrancl_is_UN_relpow: "R\<^sup>* = (\<Union>n. R ^^ n)"
   by (blast intro: rtrancl_imp_UN_relpow relpow_imp_rtrancl)
 
-lemma rtranclp_is_Sup_relpowp:
-  "P^** = (\<Squnion>n. P ^^ n)"
+lemma rtranclp_is_Sup_relpowp: "P\<^sup>*\<^sup>* = (\<Squnion>n. P ^^ n)"
   using rtrancl_is_UN_relpow [to_pred, of P] by auto
 
-lemma rtrancl_power:
-  "p \<in> R^* \<longleftrightarrow> (\<exists>n. p \<in> R ^^ n)"
+lemma rtrancl_power: "p \<in> R\<^sup>* \<longleftrightarrow> (\<exists>n. p \<in> R ^^ n)"
   by (simp add: rtrancl_is_UN_relpow)
 
-lemma rtranclp_power:
-  "(P^**) x y \<longleftrightarrow> (\<exists>n. (P ^^ n) x y)"
+lemma rtranclp_power: "(P\<^sup>*\<^sup>*) x y \<longleftrightarrow> (\<exists>n. (P ^^ n) x y)"
   by (simp add: rtranclp_is_Sup_relpowp)
 
-lemma trancl_power:
-  "p \<in> R^+ \<longleftrightarrow> (\<exists>n > 0. p \<in> R ^^ n)"
+lemma trancl_power: "p \<in> R\<^sup>+ \<longleftrightarrow> (\<exists>n > 0. p \<in> R ^^ n)"
   apply (cases p)
   apply simp
   apply (rule iffI)
@@ -956,187 +911,204 @@
   apply (drule rtrancl_into_trancl1) apply auto
   done
 
-lemma tranclp_power:
-  "(P^++) x y \<longleftrightarrow> (\<exists>n > 0. (P ^^ n) x y)"
+lemma tranclp_power: "(P\<^sup>+\<^sup>+) x y \<longleftrightarrow> (\<exists>n > 0. (P ^^ n) x y)"
   using trancl_power [to_pred, of P "(x, y)"] by simp
 
-lemma rtrancl_imp_relpow:
-  "p \<in> R^* \<Longrightarrow> \<exists>n. p \<in> R ^^ n"
+lemma rtrancl_imp_relpow: "p \<in> R\<^sup>* \<Longrightarrow> \<exists>n. p \<in> R ^^ n"
   by (auto dest: rtrancl_imp_UN_relpow)
 
-lemma rtranclp_imp_relpowp:
-  "(P^**) x y \<Longrightarrow> \<exists>n. (P ^^ n) x y"
+lemma rtranclp_imp_relpowp: "(P\<^sup>*\<^sup>*) x y \<Longrightarrow> \<exists>n. (P ^^ n) x y"
   by (auto dest: rtranclp_imp_Sup_relpowp)
 
-text\<open>By Sternagel/Thiemann:\<close>
-lemma relpow_fun_conv:
-  "((a,b) \<in> R ^^ n) = (\<exists>f. f 0 = a \<and> f n = b \<and> (\<forall>i<n. (f i, f(Suc i)) \<in> R))"
+text \<open>By Sternagel/Thiemann:\<close>
+lemma relpow_fun_conv: "(a, b) \<in> R ^^ n \<longleftrightarrow> (\<exists>f. f 0 = a \<and> f n = b \<and> (\<forall>i<n. (f i, f (Suc i)) \<in> R))"
 proof (induct n arbitrary: b)
-  case 0 show ?case by auto
+  case 0
+  show ?case by auto
 next
   case (Suc n)
   show ?case
   proof (simp add: relcomp_unfold Suc)
-    show "(\<exists>y. (\<exists>f. f 0 = a \<and> f n = y \<and> (\<forall>i<n. (f i,f(Suc i)) \<in> R)) \<and> (y,b) \<in> R)
-     = (\<exists>f. f 0 = a \<and> f(Suc n) = b \<and> (\<forall>i<Suc n. (f i, f (Suc i)) \<in> R))"
+    show "(\<exists>y. (\<exists>f. f 0 = a \<and> f n = y \<and> (\<forall>i<n. (f i,f(Suc i)) \<in> R)) \<and> (y,b) \<in> R) \<longleftrightarrow>
+      (\<exists>f. f 0 = a \<and> f(Suc n) = b \<and> (\<forall>i<Suc n. (f i, f (Suc i)) \<in> R))"
     (is "?l = ?r")
     proof
       assume ?l
-      then obtain c f where 1: "f 0 = a"  "f n = c"  "\<And>i. i < n \<Longrightarrow> (f i, f (Suc i)) \<in> R"  "(c,b) \<in> R" by auto
+      then obtain c f
+        where 1: "f 0 = a"  "f n = c"  "\<And>i. i < n \<Longrightarrow> (f i, f (Suc i)) \<in> R"  "(c,b) \<in> R"
+        by auto
       let ?g = "\<lambda> m. if m = Suc n then b else f m"
-      show ?r by (rule exI[of _ ?g], simp add: 1)
+      show ?r by (rule exI[of _ ?g]) (simp add: 1)
     next
       assume ?r
-      then obtain f where 1: "f 0 = a"  "b = f (Suc n)"  "\<And>i. i < Suc n \<Longrightarrow> (f i, f (Suc i)) \<in> R" by auto
+      then obtain f where 1: "f 0 = a"  "b = f (Suc n)"  "\<And>i. i < Suc n \<Longrightarrow> (f i, f (Suc i)) \<in> R"
+        by auto
       show ?l by (rule exI[of _ "f n"], rule conjI, rule exI[of _ f], insert 1, auto)
     qed
   qed
 qed
 
-lemma relpowp_fun_conv:
-  "(P ^^ n) x y \<longleftrightarrow> (\<exists>f. f 0 = x \<and> f n = y \<and> (\<forall>i<n. P (f i) (f (Suc i))))"
+lemma relpowp_fun_conv: "(P ^^ n) x y \<longleftrightarrow> (\<exists>f. f 0 = x \<and> f n = y \<and> (\<forall>i<n. P (f i) (f (Suc i))))"
   by (fact relpow_fun_conv [to_pred])
 
 lemma relpow_finite_bounded1:
-assumes "finite(R :: ('a*'a)set)" and "k>0"
-shows "R^^k \<subseteq> (UN n:{n. 0<n & n <= card R}. R^^n)" (is "_ \<subseteq> ?r")
-proof-
-  { fix a b k
-    have "(a,b) : R^^(Suc k) \<Longrightarrow> EX n. 0<n & n <= card R & (a,b) : R^^n"
-    proof(induct k arbitrary: b)
-      case 0
-      hence "R \<noteq> {}" by auto
-      with card_0_eq[OF \<open>finite R\<close>] have "card R >= Suc 0" by auto
-      thus ?case using 0 by force
+  fixes R :: "('a \<times> 'a) set"
+  assumes "finite R" and "k > 0"
+  shows "R^^k \<subseteq> (\<Union>n\<in>{n. 0 < n \<and> n \<le> card R}. R^^n)" (is "_ \<subseteq> ?r")
+proof -
+  have "(a, b) \<in> R^^(Suc k) \<Longrightarrow> \<exists>n. 0 < n \<and> n \<le> card R \<and> (a, b) \<in> R^^n" for a b k
+  proof (induct k arbitrary: b)
+    case 0
+    then have "R \<noteq> {}" by auto
+    with card_0_eq[OF \<open>finite R\<close>] have "card R \<ge> Suc 0" by auto
+    then show ?case using 0 by force
+  next
+    case (Suc k)
+    then obtain a' where "(a, a') \<in> R^^(Suc k)" and "(a', b) \<in> R"
+      by auto
+    from Suc(1)[OF \<open>(a, a') \<in> R^^(Suc k)\<close>] obtain n where "n \<le> card R" and "(a, a') \<in> R ^^ n"
+      by auto
+    have "(a, b) \<in> R^^(Suc n)"
+      using \<open>(a, a') \<in> R^^n\<close> and \<open>(a', b)\<in> R\<close> by auto
+    from \<open>n \<le> card R\<close> consider "n < card R" | "n = card R" by force
+    then show ?case
+    proof cases
+      case 1
+      then show ?thesis
+        using \<open>(a, b) \<in> R^^(Suc n)\<close> Suc_leI[OF \<open>n < card R\<close>] by blast
     next
-      case (Suc k)
-      then obtain a' where "(a,a') : R^^(Suc k)" and "(a',b) : R" by auto
-      from Suc(1)[OF \<open>(a,a') : R^^(Suc k)\<close>]
-      obtain n where "n \<le> card R" and "(a,a') \<in> R ^^ n" by auto
-      have "(a,b) : R^^(Suc n)" using \<open>(a,a') \<in> R^^n\<close> and \<open>(a',b)\<in> R\<close> by auto
-      { assume "n < card R"
-        hence ?case using \<open>(a,b): R^^(Suc n)\<close> Suc_leI[OF \<open>n < card R\<close>] by blast
-      } moreover
-      { assume "n = card R"
-        from \<open>(a,b) \<in> R ^^ (Suc n)\<close>[unfolded relpow_fun_conv]
-        obtain f where "f 0 = a" and "f(Suc n) = b"
-          and steps: "\<And>i. i <= n \<Longrightarrow> (f i, f (Suc i)) \<in> R" by auto
-        let ?p = "%i. (f i, f(Suc i))"
-        let ?N = "{i. i \<le> n}"
-        have "?p ` ?N <= R" using steps by auto
-        from card_mono[OF assms(1) this]
-        have "card(?p ` ?N) <= card R" .
-        also have "\<dots> < card ?N" using \<open>n = card R\<close> by simp
-        finally have "~ inj_on ?p ?N" by(rule pigeonhole)
-        then obtain i j where i: "i <= n" and j: "j <= n" and ij: "i \<noteq> j" and
-          pij: "?p i = ?p j" by(auto simp: inj_on_def)
-        let ?i = "min i j" let ?j = "max i j"
-        have i: "?i <= n" and j: "?j <= n" and pij: "?p ?i = ?p ?j" 
-          and ij: "?i < ?j"
-          using i j ij pij unfolding min_def max_def by auto
-        from i j pij ij obtain i j where i: "i<=n" and j: "j<=n" and ij: "i<j"
-          and pij: "?p i = ?p j" by blast
-        let ?g = "\<lambda> l. if l \<le> i then f l else f (l + (j - i))"
-        let ?n = "Suc(n - (j - i))"
-        have abl: "(a,b) \<in> R ^^ ?n" unfolding relpow_fun_conv
-        proof (rule exI[of _ ?g], intro conjI impI allI)
-          show "?g ?n = b" using \<open>f(Suc n) = b\<close> j ij by auto
+      case 2
+      from \<open>(a, b) \<in> R ^^ (Suc n)\<close> [unfolded relpow_fun_conv]
+      obtain f where "f 0 = a" and "f (Suc n) = b"
+        and steps: "\<And>i. i \<le> n \<Longrightarrow> (f i, f (Suc i)) \<in> R" by auto
+      let ?p = "\<lambda>i. (f i, f(Suc i))"
+      let ?N = "{i. i \<le> n}"
+      have "?p ` ?N \<subseteq> R"
+        using steps by auto
+      from card_mono[OF assms(1) this] have "card (?p ` ?N) \<le> card R" .
+      also have "\<dots> < card ?N"
+        using \<open>n = card R\<close> by simp
+      finally have "\<not> inj_on ?p ?N"
+        by (rule pigeonhole)
+      then obtain i j where i: "i \<le> n" and j: "j \<le> n" and ij: "i \<noteq> j" and pij: "?p i = ?p j"
+        by (auto simp: inj_on_def)
+      let ?i = "min i j"
+      let ?j = "max i j"
+      have i: "?i \<le> n" and j: "?j \<le> n" and pij: "?p ?i = ?p ?j" and ij: "?i < ?j"
+        using i j ij pij unfolding min_def max_def by auto
+      from i j pij ij obtain i j where i: "i \<le> n" and j: "j \<le> n" and ij: "i < j"
+        and pij: "?p i = ?p j"
+        by blast
+      let ?g = "\<lambda>l. if l \<le> i then f l else f (l + (j - i))"
+      let ?n = "Suc (n - (j - i))"
+      have abl: "(a, b) \<in> R ^^ ?n"
+        unfolding relpow_fun_conv
+      proof (rule exI[of _ ?g], intro conjI impI allI)
+        show "?g ?n = b"
+          using \<open>f(Suc n) = b\<close> j ij by auto
+      next
+        fix k
+        assume "k < ?n"
+        show "(?g k, ?g (Suc k)) \<in> R"
+        proof (cases "k < i")
+          case True
+          with i have "k \<le> n"
+            by auto
+          from steps[OF this] show ?thesis
+            using True by simp
         next
-          fix k assume "k < ?n"
-          show "(?g k, ?g (Suc k)) \<in> R"
-          proof (cases "k < i")
+          case False
+          then have "i \<le> k" by auto
+          show ?thesis
+          proof (cases "k = i")
             case True
-            with i have "k <= n" by auto
-            from steps[OF this] show ?thesis using True by simp
+            then show ?thesis
+              using ij pij steps[OF i] by simp
           next
             case False
-            hence "i \<le> k" by auto
+            with \<open>i \<le> k\<close> have "i < k" by auto
+            then have small: "k + (j - i) \<le> n"
+              using \<open>k<?n\<close> by arith
             show ?thesis
-            proof (cases "k = i")
-              case True
-              thus ?thesis using ij pij steps[OF i] by simp
-            next
-              case False
-              with \<open>i \<le> k\<close> have "i < k" by auto
-              hence small: "k + (j - i) <= n" using \<open>k<?n\<close> by arith
-              show ?thesis using steps[OF small] \<open>i<k\<close> by auto
-            qed
+              using steps[OF small] \<open>i<k\<close> by auto
           qed
-        qed (simp add: \<open>f 0 = a\<close>)
-        moreover have "?n <= n" using i j ij by arith
-        ultimately have ?case using \<open>n = card R\<close> by blast
-      }
-      ultimately show ?case using \<open>n \<le> card R\<close> by force
+        qed
+      qed (simp add: \<open>f 0 = a\<close>)
+      moreover have "?n \<le> n"
+        using i j ij by arith
+      ultimately show ?thesis
+        using \<open>n = card R\<close> by blast
     qed
-  }
-  thus ?thesis using gr0_implies_Suc[OF \<open>k>0\<close>] by auto
+  qed
+  then show ?thesis
+    using gr0_implies_Suc[OF \<open>k > 0\<close>] by auto
 qed
 
 lemma relpow_finite_bounded:
-assumes "finite(R :: ('a*'a)set)"
-shows "R^^k \<subseteq> (UN n:{n. n <= card R}. R^^n)"
-apply(cases k)
- apply force
-using relpow_finite_bounded1[OF assms, of k] by auto
+  fixes R :: "('a \<times> 'a) set"
+  assumes "finite R"
+  shows "R^^k \<subseteq> (UN n:{n. n \<le> card R}. R^^n)"
+  apply (cases k)
+   apply force
+  using relpow_finite_bounded1[OF assms, of k]
+  apply auto
+  done
 
-lemma rtrancl_finite_eq_relpow:
-  "finite R \<Longrightarrow> R^* = (UN n : {n. n <= card R}. R^^n)"
-by(fastforce simp: rtrancl_power dest: relpow_finite_bounded)
+lemma rtrancl_finite_eq_relpow: "finite R \<Longrightarrow> R\<^sup>* = (\<Union>n\<in>{n. n \<le> card R}. R^^n)"
+  by (fastforce simp: rtrancl_power dest: relpow_finite_bounded)
 
-lemma trancl_finite_eq_relpow:
-  "finite R \<Longrightarrow> R^+ = (UN n : {n. 0 < n & n <= card R}. R^^n)"
-apply(auto simp add: trancl_power)
-apply(auto dest: relpow_finite_bounded1)
-done
+lemma trancl_finite_eq_relpow: "finite R \<Longrightarrow> R\<^sup>+ = (\<Union>n\<in>{n. 0 < n \<and> n \<le> card R}. R^^n)"
+  apply (auto simp: trancl_power)
+  apply (auto dest: relpow_finite_bounded1)
+  done
 
 lemma finite_relcomp[simp,intro]:
-assumes "finite R" and "finite S"
-shows "finite(R O S)"
+  assumes "finite R" and "finite S"
+  shows "finite (R O S)"
 proof-
   have "R O S = (\<Union>(x, y)\<in>R. \<Union>(u, v)\<in>S. if u = y then {(x, v)} else {})"
     by (force simp add: split_def image_constant_conv split: if_splits)
-  then show ?thesis using assms by clarsimp
+  then show ?thesis
+    using assms by clarsimp
 qed
 
-lemma finite_relpow[simp,intro]:
-  assumes "finite(R :: ('a*'a)set)" shows "n>0 \<Longrightarrow> finite(R^^n)"
-apply(induct n)
- apply simp
-apply(case_tac n)
- apply(simp_all add: assms)
-done
+lemma finite_relpow [simp, intro]:
+  fixes R :: "('a \<times> 'a) set"
+  assumes "finite R"
+  shows "n > 0 \<Longrightarrow> finite (R^^n)"
+  apply (induct n)
+   apply simp
+  apply (case_tac n)
+   apply (simp_all add: assms)
+  done
 
 lemma single_valued_relpow:
-  fixes R :: "('a * 'a) set"
+  fixes R :: "('a \<times> 'a) set"
   shows "single_valued R \<Longrightarrow> single_valued (R ^^ n)"
-apply (induct n arbitrary: R)
-apply simp_all
-apply (rule single_valuedI)
-apply (fast dest: single_valuedD elim: relpow_Suc_E)
-done
+  apply (induct n arbitrary: R)
+  apply simp_all
+  apply (rule single_valuedI)
+  apply (fast dest: single_valuedD elim: relpow_Suc_E)
+  done
 
 
 subsection \<open>Bounded transitive closure\<close>
 
 definition ntrancl :: "nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set"
-where
-  "ntrancl n R = (\<Union>i\<in>{i. 0 < i \<and> i \<le> Suc n}. R ^^ i)"
+  where "ntrancl n R = (\<Union>i\<in>{i. 0 < i \<and> i \<le> Suc n}. R ^^ i)"
 
-lemma ntrancl_Zero [simp, code]:
-  "ntrancl 0 R = R"
+lemma ntrancl_Zero [simp, code]: "ntrancl 0 R = R"
 proof
   show "R \<subseteq> ntrancl 0 R"
     unfolding ntrancl_def by fastforce
 next
-  { 
-    fix i have "0 < i \<and> i \<le> Suc 0 \<longleftrightarrow> i = 1" by auto
-  }
-  from this show "ntrancl 0 R \<le> R"
+  have "0 < i \<and> i \<le> Suc 0 \<longleftrightarrow> i = 1" for i
+    by auto
+  then show "ntrancl 0 R \<le> R"
     unfolding ntrancl_def by auto
 qed
 
-lemma ntrancl_Suc [simp]:
-  "ntrancl (Suc n) R = ntrancl n R O (Id \<union> R)"
+lemma ntrancl_Suc [simp]: "ntrancl (Suc n) R = ntrancl n R O (Id \<union> R)"
 proof
   {
     fix a b
@@ -1159,75 +1131,67 @@
       from this c2 show ?thesis by fastforce
     qed
   }
-  from this show "ntrancl (Suc n) R \<subseteq> ntrancl n R O (Id \<union> R)"
+  then show "ntrancl (Suc n) R \<subseteq> ntrancl n R O (Id \<union> R)"
     by auto
-next
   show "ntrancl n R O (Id \<union> R) \<subseteq> ntrancl (Suc n) R"
     unfolding ntrancl_def by fastforce
 qed
 
-lemma [code]:
-  "ntrancl (Suc n) r = (let r' = ntrancl n r in r' Un r' O r)"
-unfolding Let_def by auto
+lemma [code]: "ntrancl (Suc n) r = (let r' = ntrancl n r in r' \<union> r' O r)"
+  by (auto simp: Let_def)
 
-lemma finite_trancl_ntranl:
-  "finite R \<Longrightarrow> trancl R = ntrancl (card R - 1) R"
+lemma finite_trancl_ntranl: "finite R \<Longrightarrow> trancl R = ntrancl (card R - 1) R"
   by (cases "card R") (auto simp add: trancl_finite_eq_relpow relpow_empty ntrancl_def)
 
 
 subsection \<open>Acyclic relations\<close>
 
-definition acyclic :: "('a * 'a) set => bool" where
-  "acyclic r \<longleftrightarrow> (!x. (x,x) ~: r^+)"
+definition acyclic :: "('a \<times> 'a) set \<Rightarrow> bool"
+  where "acyclic r \<longleftrightarrow> (\<forall>x. (x,x) \<notin> r\<^sup>+)"
 
-abbreviation acyclicP :: "('a => 'a => bool) => bool" where
-  "acyclicP r \<equiv> acyclic {(x, y). r x y}"
+abbreviation acyclicP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
+  where "acyclicP r \<equiv> acyclic {(x, y). r x y}"
 
-lemma acyclic_irrefl [code]:
-  "acyclic r \<longleftrightarrow> irrefl (r^+)"
+lemma acyclic_irrefl [code]: "acyclic r \<longleftrightarrow> irrefl (r\<^sup>+)"
   by (simp add: acyclic_def irrefl_def)
 
-lemma acyclicI: "ALL x. (x, x) ~: r^+ ==> acyclic r"
+lemma acyclicI: "\<forall>x. (x, x) \<notin> r\<^sup>+ \<Longrightarrow> acyclic r"
   by (simp add: acyclic_def)
 
 lemma (in order) acyclicI_order:
   assumes *: "\<And>a b. (a, b) \<in> r \<Longrightarrow> f b < f a"
   shows "acyclic r"
 proof -
-  { fix a b assume "(a, b) \<in> r\<^sup>+"
-    then have "f b < f a"
-      by induct (auto intro: * less_trans) }
+  have "f b < f a" if "(a, b) \<in> r\<^sup>+" for a b
+    using that by induct (auto intro: * less_trans)
   then show ?thesis
     by (auto intro!: acyclicI)
 qed
 
-lemma acyclic_insert [iff]:
-     "acyclic(insert (y,x) r) = (acyclic r & (x,y) ~: r^*)"
-apply (simp add: acyclic_def trancl_insert)
-apply (blast intro: rtrancl_trans)
-done
+lemma acyclic_insert [iff]: "acyclic (insert (y, x) r) \<longleftrightarrow> acyclic r \<and> (x, y) \<notin> r\<^sup>*"
+  apply (simp add: acyclic_def trancl_insert)
+  apply (blast intro: rtrancl_trans)
+  done
 
-lemma acyclic_converse [iff]: "acyclic(r^-1) = acyclic r"
-by (simp add: acyclic_def trancl_converse)
+lemma acyclic_converse [iff]: "acyclic (r\<inverse>) \<longleftrightarrow> acyclic r"
+  by (simp add: acyclic_def trancl_converse)
 
 lemmas acyclicP_converse [iff] = acyclic_converse [to_pred]
 
-lemma acyclic_impl_antisym_rtrancl: "acyclic r ==> antisym(r^*)"
-apply (simp add: acyclic_def antisym_def)
-apply (blast elim: rtranclE intro: rtrancl_into_trancl1 rtrancl_trancl_trancl)
-done
+lemma acyclic_impl_antisym_rtrancl: "acyclic r \<Longrightarrow> antisym (r\<^sup>*)"
+  apply (simp add: acyclic_def antisym_def)
+  apply (blast elim: rtranclE intro: rtrancl_into_trancl1 rtrancl_trancl_trancl)
+  done
 
 (* Other direction:
 acyclic = no loops
 antisym = only self loops
-Goalw [acyclic_def,antisym_def] "antisym( r^* ) ==> acyclic(r - Id)
-==> antisym( r^* ) = acyclic(r - Id)";
+Goalw [acyclic_def,antisym_def] "antisym( r\<^sup>* ) \<Longrightarrow> acyclic(r - Id)
+\<Longrightarrow> antisym( r\<^sup>* ) = acyclic(r - Id)";
 *)
 
-lemma acyclic_subset: "[| acyclic s; r <= s |] ==> acyclic r"
-apply (simp add: acyclic_def)
-apply (blast intro: trancl_mono)
-done
+lemma acyclic_subset: "acyclic s \<Longrightarrow> r \<subseteq> s \<Longrightarrow> acyclic r"
+  unfolding acyclic_def by (blast intro: trancl_mono)
 
 
 subsection \<open>Setup of transitivity reasoner\<close>
@@ -1246,14 +1210,16 @@
   val rtrancl_trans = @{thm rtrancl_trans};
 
   fun decomp (@{const Trueprop} $ t) =
-    let fun dec (Const (@{const_name Set.member}, _) $ (Const (@{const_name Pair}, _) $ a $ b) $ rel ) =
-        let fun decr (Const (@{const_name rtrancl}, _ ) $ r) = (r,"r*")
-              | decr (Const (@{const_name trancl}, _ ) $ r)  = (r,"r+")
-              | decr r = (r,"r");
-            val (rel,r) = decr (Envir.beta_eta_contract rel);
-        in SOME (a,b,rel,r) end
-      | dec _ =  NONE
-    in dec t end
+        let
+          fun dec (Const (@{const_name Set.member}, _) $ (Const (@{const_name Pair}, _) $ a $ b) $ rel) =
+              let
+                fun decr (Const (@{const_name rtrancl}, _ ) $ r) = (r,"r*")
+                  | decr (Const (@{const_name trancl}, _ ) $ r)  = (r,"r+")
+                  | decr r = (r,"r");
+                val (rel,r) = decr (Envir.beta_eta_contract rel);
+              in SOME (a,b,rel,r) end
+          | dec _ =  NONE
+        in dec t end
     | decomp _ = NONE;
 );
 
@@ -1269,14 +1235,16 @@
   val rtrancl_trans = @{thm rtranclp_trans};
 
   fun decomp (@{const Trueprop} $ t) =
-    let fun dec (rel $ a $ b) =
-        let fun decr (Const (@{const_name rtranclp}, _ ) $ r) = (r,"r*")
-              | decr (Const (@{const_name tranclp}, _ ) $ r)  = (r,"r+")
-              | decr r = (r,"r");
-            val (rel,r) = decr rel;
-        in SOME (a, b, rel, r) end
-      | dec _ =  NONE
-    in dec t end
+        let
+          fun dec (rel $ a $ b) =
+            let
+              fun decr (Const (@{const_name rtranclp}, _ ) $ r) = (r,"r*")
+                | decr (Const (@{const_name tranclp}, _ ) $ r)  = (r,"r+")
+                | decr r = (r,"r");
+              val (rel,r) = decr rel;
+            in SOME (a, b, rel, r) end
+          | dec _ =  NONE
+        in dec t end
     | decomp _ = NONE;
 );
 \<close>
--- a/src/Pure/Isar/class_declaration.ML	Wed Jul 06 13:45:52 2016 +0200
+++ b/src/Pure/Isar/class_declaration.ML	Wed Jul 06 22:52:10 2016 +0200
@@ -327,7 +327,7 @@
     #> Class.register class sups params base_sort base_morph export_morph some_axiom some_assm_intro of_class
     #> Global_Theory.store_thm (prefix (Binding.qualified_name (class ^ ".of_class.intro")), of_class)))
     |> snd
-    |> Named_Target.init class
+    |> Named_Target.init NONE class
     |> pair class
   end;
 
--- a/src/Pure/Isar/expression.ML	Wed Jul 06 13:45:52 2016 +0200
+++ b/src/Pure/Isar/expression.ML	Wed Jul 06 22:52:10 2016 +0200
@@ -825,7 +825,7 @@
     val loc_ctxt = thy'
       |> Locale.register_locale binding (extraTs, params)
           (asm, rev defs) (a_intro, b_intro) axioms hyp_spec [] (rev notes) (rev deps')
-      |> Named_Target.init name
+      |> Named_Target.init NONE name
       |> fold (fn (kind, facts) => Local_Theory.notes_kind kind facts #> snd) notes';
 
   in (name, loc_ctxt) end;
--- a/src/Pure/Isar/interpretation.ML	Wed Jul 06 13:45:52 2016 +0200
+++ b/src/Pure/Isar/interpretation.ML	Wed Jul 06 22:52:10 2016 +0200
@@ -220,7 +220,7 @@
 fun gen_global_sublocale prep_loc prep_interpretation
     raw_locale expression raw_defs raw_eqns thy =
   let
-    val lthy = Named_Target.init (prep_loc thy raw_locale) thy;
+    val lthy = Named_Target.init NONE (prep_loc thy raw_locale) thy;
     fun setup_proof after_qed =
       Element.witness_proof_eqs
         (fn wits => fn eqs => after_qed wits eqs #> Local_Theory.exit);
--- a/src/Pure/Isar/named_target.ML	Wed Jul 06 13:45:52 2016 +0200
+++ b/src/Pure/Isar/named_target.ML	Wed Jul 06 22:52:10 2016 +0200
@@ -11,14 +11,13 @@
   val locale_of: local_theory -> string option
   val bottom_locale_of: local_theory -> string option
   val class_of: local_theory -> string option
-  val init: string -> theory -> local_theory
+  val init: (local_theory -> local_theory) option -> string -> theory -> local_theory
   val theory_init: theory -> local_theory
   val theory_map: (local_theory -> local_theory) -> theory -> theory
-  val theory_like_init: (local_theory -> local_theory) -> theory -> local_theory
   val begin: xstring * Position.T -> theory -> local_theory
   val exit: local_theory -> theory
-  val switch: (xstring * Position.T) option -> Context.generic
-    -> (local_theory -> Context.generic) * local_theory
+  val switch: (xstring * Position.T) option -> Context.generic ->
+    (local_theory -> Context.generic) * local_theory
 end;
 
 structure Named_Target: NAMED_TARGET =
@@ -133,7 +132,7 @@
   | init_context (locale, false) = Locale.init locale
   | init_context (class, true) = Class.init class;
 
-fun gen_init before_exit target thy =
+fun init before_exit target thy =
   let
     val name_data = make_name_data thy target;
     val background_naming =
@@ -155,19 +154,14 @@
           #> Local_Theory.target_of #> Sign.change_end_local}
   end;
 
-val init = gen_init NONE
-
-val theory_init = init "";
-
+val theory_init = init NONE "";
 fun theory_map f = theory_init #> f #> Local_Theory.exit_global;
 
-fun theory_like_init before_exit = gen_init (SOME before_exit) "";
-
 
 (* toplevel interaction *)
 
 fun begin ("-", _) thy = theory_init thy
-  | begin target thy = init (Locale.check thy target) thy;
+  | begin target thy = init NONE (Locale.check thy target) thy;
 
 val exit = Local_Theory.assert_bottom true #> Local_Theory.exit_global;
 
@@ -178,7 +172,7 @@
   | switch NONE (Context.Proof lthy) =
       (Context.Proof o Local_Theory.reset, lthy)
   | switch (SOME name) (Context.Proof lthy) =
-      (Context.Proof o init (target_of lthy) o exit,
+      (Context.Proof o init NONE (target_of lthy) o exit,
         (begin name o exit o Local_Theory.assert_nonbrittle) lthy);
 
 end;