src/HOL/Relation.thy
changeset 63404 a95e7432d86c
parent 63376 4c0cc2b356f0
child 63561 fba08009ff3e
     1.1 --- a/src/HOL/Relation.thy	Wed Jul 06 14:09:13 2016 +0200
     1.2 +++ b/src/HOL/Relation.thy	Wed Jul 06 20:19:51 2016 +0200
     1.3 @@ -14,7 +14,7 @@
     1.4  declare predicate1D [Pure.dest, dest]
     1.5  declare predicate2I [Pure.intro!, intro!]
     1.6  declare predicate2D [Pure.dest, dest]
     1.7 -declare bot1E [elim!] 
     1.8 +declare bot1E [elim!]
     1.9  declare bot2E [elim!]
    1.10  declare top1I [intro!]
    1.11  declare top2I [intro!]
    1.12 @@ -56,15 +56,16 @@
    1.13  
    1.14  subsubsection \<open>Relations as sets of pairs\<close>
    1.15  
    1.16 -type_synonym 'a rel = "('a * 'a) set"
    1.17 +type_synonym 'a rel = "('a \<times> 'a) set"
    1.18  
    1.19 -lemma subrelI: \<comment> \<open>Version of @{thm [source] subsetI} for binary relations\<close>
    1.20 -  "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (x, y) \<in> s) \<Longrightarrow> r \<subseteq> s"
    1.21 +lemma subrelI: "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (x, y) \<in> s) \<Longrightarrow> r \<subseteq> s"
    1.22 +  \<comment> \<open>Version of @{thm [source] subsetI} for binary relations\<close>
    1.23    by auto
    1.24  
    1.25 -lemma lfp_induct2: \<comment> \<open>Version of @{thm [source] lfp_induct} for binary relations\<close>
    1.26 +lemma lfp_induct2:
    1.27    "(a, b) \<in> lfp f \<Longrightarrow> mono f \<Longrightarrow>
    1.28      (\<And>a b. (a, b) \<in> f (lfp f \<inter> {(x, y). P x y}) \<Longrightarrow> P a b) \<Longrightarrow> P a b"
    1.29 +  \<comment> \<open>Version of @{thm [source] lfp_induct} for binary relations\<close>
    1.30    using lfp_induct_set [of "(a, b)" f "case_prod P"] by auto
    1.31  
    1.32  
    1.33 @@ -148,35 +149,30 @@
    1.34  subsubsection \<open>Reflexivity\<close>
    1.35  
    1.36  definition refl_on :: "'a set \<Rightarrow> 'a rel \<Rightarrow> bool"
    1.37 -where
    1.38 -  "refl_on A r \<longleftrightarrow> r \<subseteq> A \<times> A \<and> (\<forall>x\<in>A. (x, x) \<in> r)"
    1.39 +  where "refl_on A r \<longleftrightarrow> r \<subseteq> A \<times> A \<and> (\<forall>x\<in>A. (x, x) \<in> r)"
    1.40  
    1.41 -abbreviation refl :: "'a rel \<Rightarrow> bool"
    1.42 -where \<comment> \<open>reflexivity over a type\<close>
    1.43 -  "refl \<equiv> refl_on UNIV"
    1.44 +abbreviation refl :: "'a rel \<Rightarrow> bool" \<comment> \<open>reflexivity over a type\<close>
    1.45 +  where "refl \<equiv> refl_on UNIV"
    1.46  
    1.47  definition reflp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
    1.48 -where
    1.49 -  "reflp r \<longleftrightarrow> (\<forall>x. r x x)"
    1.50 +  where "reflp r \<longleftrightarrow> (\<forall>x. r x x)"
    1.51  
    1.52 -lemma reflp_refl_eq [pred_set_conv]:
    1.53 -  "reflp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> refl r" 
    1.54 +lemma reflp_refl_eq [pred_set_conv]: "reflp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> refl r"
    1.55    by (simp add: refl_on_def reflp_def)
    1.56  
    1.57 -lemma refl_onI [intro?]: "r \<subseteq> A \<times> A ==> (!!x. x : A ==> (x, x) : r) ==> refl_on A r"
    1.58 -  by (unfold refl_on_def) (iprover intro!: ballI)
    1.59 +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"
    1.60 +  unfolding refl_on_def by (iprover intro!: ballI)
    1.61  
    1.62 -lemma refl_onD: "refl_on A r ==> a : A ==> (a, a) : r"
    1.63 -  by (unfold refl_on_def) blast
    1.64 +lemma refl_onD: "refl_on A r \<Longrightarrow> a \<in> A \<Longrightarrow> (a, a) \<in> r"
    1.65 +  unfolding refl_on_def by blast
    1.66  
    1.67 -lemma refl_onD1: "refl_on A r ==> (x, y) : r ==> x : A"
    1.68 -  by (unfold refl_on_def) blast
    1.69 +lemma refl_onD1: "refl_on A r \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> x \<in> A"
    1.70 +  unfolding refl_on_def by blast
    1.71  
    1.72 -lemma refl_onD2: "refl_on A r ==> (x, y) : r ==> y : A"
    1.73 -  by (unfold refl_on_def) blast
    1.74 +lemma refl_onD2: "refl_on A r \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> y \<in> A"
    1.75 +  unfolding refl_on_def by blast
    1.76  
    1.77 -lemma reflpI [intro?]:
    1.78 -  "(\<And>x. r x x) \<Longrightarrow> reflp r"
    1.79 +lemma reflpI [intro?]: "(\<And>x. r x x) \<Longrightarrow> reflp r"
    1.80    by (auto intro: refl_onI simp add: reflp_def)
    1.81  
    1.82  lemma reflpE:
    1.83 @@ -189,104 +185,86 @@
    1.84    shows "r x x"
    1.85    using assms by (auto elim: reflpE)
    1.86  
    1.87 -lemma refl_on_Int: "refl_on A r ==> refl_on B s ==> refl_on (A \<inter> B) (r \<inter> s)"
    1.88 -  by (unfold refl_on_def) blast
    1.89 +lemma refl_on_Int: "refl_on A r \<Longrightarrow> refl_on B s \<Longrightarrow> refl_on (A \<inter> B) (r \<inter> s)"
    1.90 +  unfolding refl_on_def by blast
    1.91  
    1.92 -lemma reflp_inf:
    1.93 -  "reflp r \<Longrightarrow> reflp s \<Longrightarrow> reflp (r \<sqinter> s)"
    1.94 +lemma reflp_inf: "reflp r \<Longrightarrow> reflp s \<Longrightarrow> reflp (r \<sqinter> s)"
    1.95    by (auto intro: reflpI elim: reflpE)
    1.96  
    1.97 -lemma refl_on_Un: "refl_on A r ==> refl_on B s ==> refl_on (A \<union> B) (r \<union> s)"
    1.98 -  by (unfold refl_on_def) blast
    1.99 +lemma refl_on_Un: "refl_on A r \<Longrightarrow> refl_on B s \<Longrightarrow> refl_on (A \<union> B) (r \<union> s)"
   1.100 +  unfolding refl_on_def by blast
   1.101  
   1.102 -lemma reflp_sup:
   1.103 -  "reflp r \<Longrightarrow> reflp s \<Longrightarrow> reflp (r \<squnion> s)"
   1.104 +lemma reflp_sup: "reflp r \<Longrightarrow> reflp s \<Longrightarrow> reflp (r \<squnion> s)"
   1.105    by (auto intro: reflpI elim: reflpE)
   1.106  
   1.107 -lemma refl_on_INTER:
   1.108 -  "ALL x:S. refl_on (A x) (r x) ==> refl_on (INTER S A) (INTER S r)"
   1.109 -  by (unfold refl_on_def) fast
   1.110 +lemma refl_on_INTER: "\<forall>x\<in>S. refl_on (A x) (r x) \<Longrightarrow> refl_on (INTER S A) (INTER S r)"
   1.111 +  unfolding refl_on_def by fast
   1.112  
   1.113 -lemma refl_on_UNION:
   1.114 -  "ALL x:S. refl_on (A x) (r x) \<Longrightarrow> refl_on (UNION S A) (UNION S r)"
   1.115 -  by (unfold refl_on_def) blast
   1.116 +lemma refl_on_UNION: "\<forall>x\<in>S. refl_on (A x) (r x) \<Longrightarrow> refl_on (UNION S A) (UNION S r)"
   1.117 +  unfolding refl_on_def by blast
   1.118  
   1.119  lemma refl_on_empty [simp]: "refl_on {} {}"
   1.120 -  by (simp add:refl_on_def)
   1.121 +  by (simp add: refl_on_def)
   1.122  
   1.123  lemma refl_on_def' [nitpick_unfold, code]:
   1.124    "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)"
   1.125    by (auto intro: refl_onI dest: refl_onD refl_onD1 refl_onD2)
   1.126  
   1.127  lemma reflp_equality [simp]: "reflp op ="
   1.128 -by(simp add: reflp_def)
   1.129 +  by (simp add: reflp_def)
   1.130  
   1.131 -lemma reflp_mono: "\<lbrakk> reflp R; \<And>x y. R x y \<longrightarrow> Q x y \<rbrakk> \<Longrightarrow> reflp Q"
   1.132 -by(auto intro: reflpI dest: reflpD)
   1.133 +lemma reflp_mono: "reflp R \<Longrightarrow> (\<And>x y. R x y \<longrightarrow> Q x y) \<Longrightarrow> reflp Q"
   1.134 +  by (auto intro: reflpI dest: reflpD)
   1.135  
   1.136  
   1.137  subsubsection \<open>Irreflexivity\<close>
   1.138  
   1.139  definition irrefl :: "'a rel \<Rightarrow> bool"
   1.140 -where
   1.141 -  "irrefl r \<longleftrightarrow> (\<forall>a. (a, a) \<notin> r)"
   1.142 +  where "irrefl r \<longleftrightarrow> (\<forall>a. (a, a) \<notin> r)"
   1.143  
   1.144  definition irreflp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
   1.145 -where
   1.146 -  "irreflp R \<longleftrightarrow> (\<forall>a. \<not> R a a)"
   1.147 +  where "irreflp R \<longleftrightarrow> (\<forall>a. \<not> R a a)"
   1.148  
   1.149 -lemma irreflp_irrefl_eq [pred_set_conv]:
   1.150 -  "irreflp (\<lambda>a b. (a, b) \<in> R) \<longleftrightarrow> irrefl R" 
   1.151 +lemma irreflp_irrefl_eq [pred_set_conv]: "irreflp (\<lambda>a b. (a, b) \<in> R) \<longleftrightarrow> irrefl R"
   1.152    by (simp add: irrefl_def irreflp_def)
   1.153  
   1.154 -lemma irreflI [intro?]:
   1.155 -  "(\<And>a. (a, a) \<notin> R) \<Longrightarrow> irrefl R"
   1.156 +lemma irreflI [intro?]: "(\<And>a. (a, a) \<notin> R) \<Longrightarrow> irrefl R"
   1.157    by (simp add: irrefl_def)
   1.158  
   1.159 -lemma irreflpI [intro?]:
   1.160 -  "(\<And>a. \<not> R a a) \<Longrightarrow> irreflp R"
   1.161 +lemma irreflpI [intro?]: "(\<And>a. \<not> R a a) \<Longrightarrow> irreflp R"
   1.162    by (fact irreflI [to_pred])
   1.163  
   1.164 -lemma irrefl_distinct [code]:
   1.165 -  "irrefl r \<longleftrightarrow> (\<forall>(a, b) \<in> r. a \<noteq> b)"
   1.166 +lemma irrefl_distinct [code]: "irrefl r \<longleftrightarrow> (\<forall>(a, b) \<in> r. a \<noteq> b)"
   1.167    by (auto simp add: irrefl_def)
   1.168  
   1.169  
   1.170  subsubsection \<open>Asymmetry\<close>
   1.171  
   1.172  inductive asym :: "'a rel \<Rightarrow> bool"
   1.173 -where
   1.174 -  asymI: "irrefl R \<Longrightarrow> (\<And>a b. (a, b) \<in> R \<Longrightarrow> (b, a) \<notin> R) \<Longrightarrow> asym R"
   1.175 +  where asymI: "irrefl R \<Longrightarrow> (\<And>a b. (a, b) \<in> R \<Longrightarrow> (b, a) \<notin> R) \<Longrightarrow> asym R"
   1.176  
   1.177  inductive asymp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
   1.178 -where
   1.179 -  asympI: "irreflp R \<Longrightarrow> (\<And>a b. R a b \<Longrightarrow> \<not> R b a) \<Longrightarrow> asymp R"
   1.180 +  where asympI: "irreflp R \<Longrightarrow> (\<And>a b. R a b \<Longrightarrow> \<not> R b a) \<Longrightarrow> asymp R"
   1.181  
   1.182 -lemma asymp_asym_eq [pred_set_conv]:
   1.183 -  "asymp (\<lambda>a b. (a, b) \<in> R) \<longleftrightarrow> asym R" 
   1.184 +lemma asymp_asym_eq [pred_set_conv]: "asymp (\<lambda>a b. (a, b) \<in> R) \<longleftrightarrow> asym R"
   1.185    by (auto intro!: asymI asympI elim: asym.cases asymp.cases simp add: irreflp_irrefl_eq)
   1.186  
   1.187  
   1.188  subsubsection \<open>Symmetry\<close>
   1.189  
   1.190  definition sym :: "'a rel \<Rightarrow> bool"
   1.191 -where
   1.192 -  "sym r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (y, x) \<in> r)"
   1.193 +  where "sym r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (y, x) \<in> r)"
   1.194  
   1.195  definition symp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
   1.196 -where
   1.197 -  "symp r \<longleftrightarrow> (\<forall>x y. r x y \<longrightarrow> r y x)"
   1.198 +  where "symp r \<longleftrightarrow> (\<forall>x y. r x y \<longrightarrow> r y x)"
   1.199  
   1.200 -lemma symp_sym_eq [pred_set_conv]:
   1.201 -  "symp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> sym r" 
   1.202 +lemma symp_sym_eq [pred_set_conv]: "symp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> sym r"
   1.203    by (simp add: sym_def symp_def)
   1.204  
   1.205 -lemma symI [intro?]:
   1.206 -  "(\<And>a b. (a, b) \<in> r \<Longrightarrow> (b, a) \<in> r) \<Longrightarrow> sym r"
   1.207 +lemma symI [intro?]: "(\<And>a b. (a, b) \<in> r \<Longrightarrow> (b, a) \<in> r) \<Longrightarrow> sym r"
   1.208    by (unfold sym_def) iprover
   1.209  
   1.210 -lemma sympI [intro?]:
   1.211 -  "(\<And>a b. r a b \<Longrightarrow> r b a) \<Longrightarrow> symp r"
   1.212 +lemma sympI [intro?]: "(\<And>a b. r a b \<Longrightarrow> r b a) \<Longrightarrow> symp r"
   1.213    by (fact symI [to_pred])
   1.214  
   1.215  lemma symE:
   1.216 @@ -309,86 +287,70 @@
   1.217    shows "r a b"
   1.218    using assms by (rule symD [to_pred])
   1.219  
   1.220 -lemma sym_Int:
   1.221 -  "sym r \<Longrightarrow> sym s \<Longrightarrow> sym (r \<inter> s)"
   1.222 +lemma sym_Int: "sym r \<Longrightarrow> sym s \<Longrightarrow> sym (r \<inter> s)"
   1.223    by (fast intro: symI elim: symE)
   1.224  
   1.225 -lemma symp_inf:
   1.226 -  "symp r \<Longrightarrow> symp s \<Longrightarrow> symp (r \<sqinter> s)"
   1.227 +lemma symp_inf: "symp r \<Longrightarrow> symp s \<Longrightarrow> symp (r \<sqinter> s)"
   1.228    by (fact sym_Int [to_pred])
   1.229  
   1.230 -lemma sym_Un:
   1.231 -  "sym r \<Longrightarrow> sym s \<Longrightarrow> sym (r \<union> s)"
   1.232 +lemma sym_Un: "sym r \<Longrightarrow> sym s \<Longrightarrow> sym (r \<union> s)"
   1.233    by (fast intro: symI elim: symE)
   1.234  
   1.235 -lemma symp_sup:
   1.236 -  "symp r \<Longrightarrow> symp s \<Longrightarrow> symp (r \<squnion> s)"
   1.237 +lemma symp_sup: "symp r \<Longrightarrow> symp s \<Longrightarrow> symp (r \<squnion> s)"
   1.238    by (fact sym_Un [to_pred])
   1.239  
   1.240 -lemma sym_INTER:
   1.241 -  "\<forall>x\<in>S. sym (r x) \<Longrightarrow> sym (INTER S r)"
   1.242 +lemma sym_INTER: "\<forall>x\<in>S. sym (r x) \<Longrightarrow> sym (INTER S r)"
   1.243    by (fast intro: symI elim: symE)
   1.244  
   1.245 -lemma symp_INF:
   1.246 -  "\<forall>x\<in>S. symp (r x) \<Longrightarrow> symp (INFIMUM S r)"
   1.247 +lemma symp_INF: "\<forall>x\<in>S. symp (r x) \<Longrightarrow> symp (INFIMUM S r)"
   1.248    by (fact sym_INTER [to_pred])
   1.249  
   1.250 -lemma sym_UNION:
   1.251 -  "\<forall>x\<in>S. sym (r x) \<Longrightarrow> sym (UNION S r)"
   1.252 +lemma sym_UNION: "\<forall>x\<in>S. sym (r x) \<Longrightarrow> sym (UNION S r)"
   1.253    by (fast intro: symI elim: symE)
   1.254  
   1.255 -lemma symp_SUP:
   1.256 -  "\<forall>x\<in>S. symp (r x) \<Longrightarrow> symp (SUPREMUM S r)"
   1.257 +lemma symp_SUP: "\<forall>x\<in>S. symp (r x) \<Longrightarrow> symp (SUPREMUM S r)"
   1.258    by (fact sym_UNION [to_pred])
   1.259  
   1.260  
   1.261  subsubsection \<open>Antisymmetry\<close>
   1.262  
   1.263  definition antisym :: "'a rel \<Rightarrow> bool"
   1.264 -where
   1.265 -  "antisym r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (y, x) \<in> r \<longrightarrow> x = y)"
   1.266 +  where "antisym r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (y, x) \<in> r \<longrightarrow> x = y)"
   1.267  
   1.268  abbreviation antisymP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
   1.269 -where -- \<open>FIXME proper logical operation\<close>
   1.270 -  "antisymP r \<equiv> antisym {(x, y). r x y}"
   1.271 +  where "antisymP r \<equiv> antisym {(x, y). r x y}" (* FIXME proper logical operation *)
   1.272 +
   1.273 +lemma antisymI [intro?]: "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (y, x) \<in> r \<Longrightarrow> x = y) \<Longrightarrow> antisym r"
   1.274 +  unfolding antisym_def by iprover
   1.275  
   1.276 -lemma antisymI [intro?]:
   1.277 -  "(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r"
   1.278 -  by (unfold antisym_def) iprover
   1.279 +lemma antisymD [dest?]: "antisym r \<Longrightarrow> (a, b) \<in> r \<Longrightarrow> (b, a) \<in> r \<Longrightarrow> a = b"
   1.280 +  unfolding antisym_def by iprover
   1.281  
   1.282 -lemma antisymD [dest?]: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b"
   1.283 -  by (unfold antisym_def) iprover
   1.284 -
   1.285 -lemma antisym_subset: "r \<subseteq> s ==> antisym s ==> antisym r"
   1.286 -  by (unfold antisym_def) blast
   1.287 +lemma antisym_subset: "r \<subseteq> s \<Longrightarrow> antisym s \<Longrightarrow> antisym r"
   1.288 +  unfolding antisym_def by blast
   1.289  
   1.290  lemma antisym_empty [simp]: "antisym {}"
   1.291 -  by (unfold antisym_def) blast
   1.292 +  unfolding antisym_def by blast
   1.293  
   1.294  lemma antisymP_equality [simp]: "antisymP op ="
   1.295 -by(auto intro: antisymI)
   1.296 +  by (auto intro: antisymI)
   1.297  
   1.298  
   1.299  subsubsection \<open>Transitivity\<close>
   1.300  
   1.301  definition trans :: "'a rel \<Rightarrow> bool"
   1.302 -where
   1.303 -  "trans r \<longleftrightarrow> (\<forall>x y z. (x, y) \<in> r \<longrightarrow> (y, z) \<in> r \<longrightarrow> (x, z) \<in> r)"
   1.304 +  where "trans r \<longleftrightarrow> (\<forall>x y z. (x, y) \<in> r \<longrightarrow> (y, z) \<in> r \<longrightarrow> (x, z) \<in> r)"
   1.305  
   1.306  definition transp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
   1.307 -where
   1.308 -  "transp r \<longleftrightarrow> (\<forall>x y z. r x y \<longrightarrow> r y z \<longrightarrow> r x z)"
   1.309 +  where "transp r \<longleftrightarrow> (\<forall>x y z. r x y \<longrightarrow> r y z \<longrightarrow> r x z)"
   1.310  
   1.311 -lemma transp_trans_eq [pred_set_conv]:
   1.312 -  "transp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> trans r" 
   1.313 +lemma transp_trans_eq [pred_set_conv]: "transp (\<lambda>x y. (x, y) \<in> r) \<longleftrightarrow> trans r"
   1.314    by (simp add: trans_def transp_def)
   1.315  
   1.316 -lemma transI [intro?]:
   1.317 -  "(\<And>x y z. (x, y) \<in> r \<Longrightarrow> (y, z) \<in> r \<Longrightarrow> (x, z) \<in> r) \<Longrightarrow> trans r"
   1.318 +lemma transI [intro?]: "(\<And>x y z. (x, y) \<in> r \<Longrightarrow> (y, z) \<in> r \<Longrightarrow> (x, z) \<in> r) \<Longrightarrow> trans r"
   1.319    by (unfold trans_def) iprover
   1.320  
   1.321 -lemma transpI [intro?]:
   1.322 -  "(\<And>x y z. r x y \<Longrightarrow> r y z \<Longrightarrow> r x z) \<Longrightarrow> transp r"
   1.323 +lemma transpI [intro?]: "(\<And>x y z. r x y \<Longrightarrow> r y z \<Longrightarrow> r x z) \<Longrightarrow> transp r"
   1.324    by (fact transI [to_pred])
   1.325  
   1.326  lemma transE:
   1.327 @@ -411,37 +373,31 @@
   1.328    shows "r x z"
   1.329    using assms by (rule transD [to_pred])
   1.330  
   1.331 -lemma trans_Int:
   1.332 -  "trans r \<Longrightarrow> trans s \<Longrightarrow> trans (r \<inter> s)"
   1.333 +lemma trans_Int: "trans r \<Longrightarrow> trans s \<Longrightarrow> trans (r \<inter> s)"
   1.334    by (fast intro: transI elim: transE)
   1.335  
   1.336 -lemma transp_inf:
   1.337 -  "transp r \<Longrightarrow> transp s \<Longrightarrow> transp (r \<sqinter> s)"
   1.338 +lemma transp_inf: "transp r \<Longrightarrow> transp s \<Longrightarrow> transp (r \<sqinter> s)"
   1.339    by (fact trans_Int [to_pred])
   1.340  
   1.341 -lemma trans_INTER:
   1.342 -  "\<forall>x\<in>S. trans (r x) \<Longrightarrow> trans (INTER S r)"
   1.343 +lemma trans_INTER: "\<forall>x\<in>S. trans (r x) \<Longrightarrow> trans (INTER S r)"
   1.344    by (fast intro: transI elim: transD)
   1.345  
   1.346  (* FIXME thm trans_INTER [to_pred] *)
   1.347  
   1.348 -lemma trans_join [code]:
   1.349 -  "trans r \<longleftrightarrow> (\<forall>(x, y1) \<in> r. \<forall>(y2, z) \<in> r. y1 = y2 \<longrightarrow> (x, z) \<in> r)"
   1.350 +lemma trans_join [code]: "trans r \<longleftrightarrow> (\<forall>(x, y1) \<in> r. \<forall>(y2, z) \<in> r. y1 = y2 \<longrightarrow> (x, z) \<in> r)"
   1.351    by (auto simp add: trans_def)
   1.352  
   1.353 -lemma transp_trans:
   1.354 -  "transp r \<longleftrightarrow> trans {(x, y). r x y}"
   1.355 +lemma transp_trans: "transp r \<longleftrightarrow> trans {(x, y). r x y}"
   1.356    by (simp add: trans_def transp_def)
   1.357  
   1.358  lemma transp_equality [simp]: "transp op ="
   1.359 -by(auto intro: transpI)
   1.360 +  by (auto intro: transpI)
   1.361  
   1.362  
   1.363  subsubsection \<open>Totality\<close>
   1.364  
   1.365  definition total_on :: "'a set \<Rightarrow> 'a rel \<Rightarrow> bool"
   1.366 -where
   1.367 -  "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)"
   1.368 +  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)"
   1.369  
   1.370  abbreviation "total \<equiv> total_on UNIV"
   1.371  
   1.372 @@ -452,27 +408,22 @@
   1.373  subsubsection \<open>Single valued relations\<close>
   1.374  
   1.375  definition single_valued :: "('a \<times> 'b) set \<Rightarrow> bool"
   1.376 -where
   1.377 -  "single_valued r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (\<forall>z. (x, z) \<in> r \<longrightarrow> y = z))"
   1.378 +  where "single_valued r \<longleftrightarrow> (\<forall>x y. (x, y) \<in> r \<longrightarrow> (\<forall>z. (x, z) \<in> r \<longrightarrow> y = z))"
   1.379  
   1.380  abbreviation single_valuedP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
   1.381 -where -- \<open>FIXME proper logical operation\<close>
   1.382 -  "single_valuedP r \<equiv> single_valued {(x, y). r x y}"
   1.383 +  where "single_valuedP r \<equiv> single_valued {(x, y). r x y}" (* FIXME proper logical operation *)
   1.384  
   1.385 -lemma single_valuedI:
   1.386 -  "ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r"
   1.387 -  by (unfold single_valued_def)
   1.388 +lemma single_valuedI: "\<forall>x y. (x, y) \<in> r \<longrightarrow> (\<forall>z. (x, z) \<in> r \<longrightarrow> y = z) \<Longrightarrow> single_valued r"
   1.389 +  unfolding single_valued_def .
   1.390  
   1.391 -lemma single_valuedD:
   1.392 -  "single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z"
   1.393 +lemma single_valuedD: "single_valued r \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> (x, z) \<in> r \<Longrightarrow> y = z"
   1.394    by (simp add: single_valued_def)
   1.395  
   1.396  lemma single_valued_empty[simp]: "single_valued {}"
   1.397 -by(simp add: single_valued_def)
   1.398 +  by (simp add: single_valued_def)
   1.399  
   1.400 -lemma single_valued_subset:
   1.401 -  "r \<subseteq> s ==> single_valued s ==> single_valued r"
   1.402 -  by (unfold single_valued_def) blast
   1.403 +lemma single_valued_subset: "r \<subseteq> s \<Longrightarrow> single_valued s \<Longrightarrow> single_valued r"
   1.404 +  unfolding single_valued_def by blast
   1.405  
   1.406  
   1.407  subsection \<open>Relation operations\<close>
   1.408 @@ -480,17 +431,16 @@
   1.409  subsubsection \<open>The identity relation\<close>
   1.410  
   1.411  definition Id :: "'a rel"
   1.412 -where
   1.413 -  [code del]: "Id = {p. \<exists>x. p = (x, x)}"
   1.414 +  where [code del]: "Id = {p. \<exists>x. p = (x, x)}"
   1.415  
   1.416 -lemma IdI [intro]: "(a, a) : Id"
   1.417 +lemma IdI [intro]: "(a, a) \<in> Id"
   1.418    by (simp add: Id_def)
   1.419  
   1.420 -lemma IdE [elim!]: "p : Id ==> (!!x. p = (x, x) ==> P) ==> P"
   1.421 -  by (unfold Id_def) (iprover elim: CollectE)
   1.422 +lemma IdE [elim!]: "p \<in> Id \<Longrightarrow> (\<And>x. p = (x, x) \<Longrightarrow> P) \<Longrightarrow> P"
   1.423 +  unfolding Id_def by (iprover elim: CollectE)
   1.424  
   1.425 -lemma pair_in_Id_conv [iff]: "((a, b) : Id) = (a = b)"
   1.426 -  by (unfold Id_def) blast
   1.427 +lemma pair_in_Id_conv [iff]: "(a, b) \<in> Id \<longleftrightarrow> a = b"
   1.428 +  unfolding Id_def by blast
   1.429  
   1.430  lemma refl_Id: "refl Id"
   1.431    by (simp add: refl_on_def)
   1.432 @@ -509,7 +459,7 @@
   1.433    by (unfold single_valued_def) blast
   1.434  
   1.435  lemma irrefl_diff_Id [simp]: "irrefl (r - Id)"
   1.436 -  by (simp add:irrefl_def)
   1.437 +  by (simp add: irrefl_def)
   1.438  
   1.439  lemma trans_diff_Id: "trans r \<Longrightarrow> antisym r \<Longrightarrow> trans (r - Id)"
   1.440    unfolding antisym_def trans_def by blast
   1.441 @@ -524,28 +474,25 @@
   1.442  subsubsection \<open>Diagonal: identity over a set\<close>
   1.443  
   1.444  definition Id_on  :: "'a set \<Rightarrow> 'a rel"
   1.445 -where
   1.446 -  "Id_on A = (\<Union>x\<in>A. {(x, x)})"
   1.447 +  where "Id_on A = (\<Union>x\<in>A. {(x, x)})"
   1.448  
   1.449  lemma Id_on_empty [simp]: "Id_on {} = {}"
   1.450 -  by (simp add: Id_on_def) 
   1.451 +  by (simp add: Id_on_def)
   1.452  
   1.453 -lemma Id_on_eqI: "a = b ==> a : A ==> (a, b) : Id_on A"
   1.454 +lemma Id_on_eqI: "a = b \<Longrightarrow> a \<in> A \<Longrightarrow> (a, b) \<in> Id_on A"
   1.455    by (simp add: Id_on_def)
   1.456  
   1.457 -lemma Id_onI [intro!]: "a : A ==> (a, a) : Id_on A"
   1.458 +lemma Id_onI [intro!]: "a \<in> A \<Longrightarrow> (a, a) \<in> Id_on A"
   1.459    by (rule Id_on_eqI) (rule refl)
   1.460  
   1.461 -lemma Id_onE [elim!]:
   1.462 -  "c : Id_on A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P"
   1.463 +lemma Id_onE [elim!]: "c \<in> Id_on A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> c = (x, x) \<Longrightarrow> P) \<Longrightarrow> P"
   1.464    \<comment> \<open>The general elimination rule.\<close>
   1.465 -  by (unfold Id_on_def) (iprover elim!: UN_E singletonE)
   1.466 +  unfolding Id_on_def by (iprover elim!: UN_E singletonE)
   1.467  
   1.468 -lemma Id_on_iff: "((x, y) : Id_on A) = (x = y & x : A)"
   1.469 +lemma Id_on_iff: "(x, y) \<in> Id_on A \<longleftrightarrow> x = y \<and> x \<in> A"
   1.470    by blast
   1.471  
   1.472 -lemma Id_on_def' [nitpick_unfold]:
   1.473 -  "Id_on {x. A x} = Collect (\<lambda>(x, y). x = y \<and> A x)"
   1.474 +lemma Id_on_def' [nitpick_unfold]: "Id_on {x. A x} = Collect (\<lambda>(x, y). x = y \<and> A x)"
   1.475    by auto
   1.476  
   1.477  lemma Id_on_subset_Times: "Id_on A \<subseteq> A \<times> A"
   1.478 @@ -555,7 +502,7 @@
   1.479    by (rule refl_onI [OF Id_on_subset_Times Id_onI])
   1.480  
   1.481  lemma antisym_Id_on [simp]: "antisym (Id_on A)"
   1.482 -  by (unfold antisym_def) blast
   1.483 +  unfolding antisym_def by blast
   1.484  
   1.485  lemma sym_Id_on [simp]: "sym (Id_on A)"
   1.486    by (rule symI) clarify
   1.487 @@ -564,15 +511,14 @@
   1.488    by (fast intro: transI elim: transD)
   1.489  
   1.490  lemma single_valued_Id_on [simp]: "single_valued (Id_on A)"
   1.491 -  by (unfold single_valued_def) blast
   1.492 +  unfolding single_valued_def by blast
   1.493  
   1.494  
   1.495  subsubsection \<open>Composition\<close>
   1.496  
   1.497 -inductive_set relcomp  :: "('a \<times> 'b) set \<Rightarrow> ('b \<times> 'c) set \<Rightarrow> ('a \<times> 'c) set" (infixr "O" 75)
   1.498 +inductive_set relcomp  :: "('a \<times> 'b) set \<Rightarrow> ('b \<times> 'c) set \<Rightarrow> ('a \<times> 'c) set"  (infixr "O" 75)
   1.499    for r :: "('a \<times> 'b) set" and s :: "('b \<times> 'c) set"
   1.500 -where
   1.501 -  relcompI [intro]: "(a, b) \<in> r \<Longrightarrow> (b, c) \<in> s \<Longrightarrow> (a, c) \<in> r O s"
   1.502 +  where relcompI [intro]: "(a, b) \<in> r \<Longrightarrow> (b, c) \<in> s \<Longrightarrow> (a, c) \<in> r O s"
   1.503  
   1.504  notation relcompp (infixr "OO" 75)
   1.505  
   1.506 @@ -588,269 +534,239 @@
   1.507  
   1.508  lemma relcompE [elim!]: "xz \<in> r O s \<Longrightarrow>
   1.509    (\<And>x y z. xz = (x, z) \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> (y, z) \<in> s  \<Longrightarrow> P) \<Longrightarrow> P"
   1.510 -  by (cases xz) (simp, erule relcompEpair, iprover)
   1.511 +  apply (cases xz)
   1.512 +  apply simp
   1.513 +  apply (erule relcompEpair)
   1.514 +  apply iprover
   1.515 +  done
   1.516  
   1.517 -lemma R_O_Id [simp]:
   1.518 -  "R O Id = R"
   1.519 +lemma R_O_Id [simp]: "R O Id = R"
   1.520    by fast
   1.521  
   1.522 -lemma Id_O_R [simp]:
   1.523 -  "Id O R = R"
   1.524 +lemma Id_O_R [simp]: "Id O R = R"
   1.525    by fast
   1.526  
   1.527 -lemma relcomp_empty1 [simp]:
   1.528 -  "{} O R = {}"
   1.529 +lemma relcomp_empty1 [simp]: "{} O R = {}"
   1.530    by blast
   1.531  
   1.532 -lemma relcompp_bot1 [simp]:
   1.533 -  "\<bottom> OO R = \<bottom>"
   1.534 +lemma relcompp_bot1 [simp]: "\<bottom> OO R = \<bottom>"
   1.535    by (fact relcomp_empty1 [to_pred])
   1.536  
   1.537 -lemma relcomp_empty2 [simp]:
   1.538 -  "R O {} = {}"
   1.539 +lemma relcomp_empty2 [simp]: "R O {} = {}"
   1.540    by blast
   1.541  
   1.542 -lemma relcompp_bot2 [simp]:
   1.543 -  "R OO \<bottom> = \<bottom>"
   1.544 +lemma relcompp_bot2 [simp]: "R OO \<bottom> = \<bottom>"
   1.545    by (fact relcomp_empty2 [to_pred])
   1.546  
   1.547 -lemma O_assoc:
   1.548 -  "(R O S) O T = R O (S O T)"
   1.549 +lemma O_assoc: "(R O S) O T = R O (S O T)"
   1.550    by blast
   1.551  
   1.552 -lemma relcompp_assoc:
   1.553 -  "(r OO s) OO t = r OO (s OO t)"
   1.554 +lemma relcompp_assoc: "(r OO s) OO t = r OO (s OO t)"
   1.555    by (fact O_assoc [to_pred])
   1.556  
   1.557 -lemma trans_O_subset:
   1.558 -  "trans r \<Longrightarrow> r O r \<subseteq> r"
   1.559 +lemma trans_O_subset: "trans r \<Longrightarrow> r O r \<subseteq> r"
   1.560    by (unfold trans_def) blast
   1.561  
   1.562 -lemma transp_relcompp_less_eq:
   1.563 -  "transp r \<Longrightarrow> r OO r \<le> r "
   1.564 +lemma transp_relcompp_less_eq: "transp r \<Longrightarrow> r OO r \<le> r "
   1.565    by (fact trans_O_subset [to_pred])
   1.566  
   1.567 -lemma relcomp_mono:
   1.568 -  "r' \<subseteq> r \<Longrightarrow> s' \<subseteq> s \<Longrightarrow> r' O s' \<subseteq> r O s"
   1.569 +lemma relcomp_mono: "r' \<subseteq> r \<Longrightarrow> s' \<subseteq> s \<Longrightarrow> r' O s' \<subseteq> r O s"
   1.570    by blast
   1.571  
   1.572 -lemma relcompp_mono:
   1.573 -  "r' \<le> r \<Longrightarrow> s' \<le> s \<Longrightarrow> r' OO s' \<le> r OO s "
   1.574 +lemma relcompp_mono: "r' \<le> r \<Longrightarrow> s' \<le> s \<Longrightarrow> r' OO s' \<le> r OO s "
   1.575    by (fact relcomp_mono [to_pred])
   1.576  
   1.577 -lemma relcomp_subset_Sigma:
   1.578 -  "r \<subseteq> A \<times> B \<Longrightarrow> s \<subseteq> B \<times> C \<Longrightarrow> r O s \<subseteq> A \<times> C"
   1.579 +lemma relcomp_subset_Sigma: "r \<subseteq> A \<times> B \<Longrightarrow> s \<subseteq> B \<times> C \<Longrightarrow> r O s \<subseteq> A \<times> C"
   1.580    by blast
   1.581  
   1.582 -lemma relcomp_distrib [simp]:
   1.583 -  "R O (S \<union> T) = (R O S) \<union> (R O T)" 
   1.584 +lemma relcomp_distrib [simp]: "R O (S \<union> T) = (R O S) \<union> (R O T)"
   1.585    by auto
   1.586  
   1.587 -lemma relcompp_distrib [simp]:
   1.588 -  "R OO (S \<squnion> T) = R OO S \<squnion> R OO T"
   1.589 +lemma relcompp_distrib [simp]: "R OO (S \<squnion> T) = R OO S \<squnion> R OO T"
   1.590    by (fact relcomp_distrib [to_pred])
   1.591  
   1.592 -lemma relcomp_distrib2 [simp]:
   1.593 -  "(S \<union> T) O R = (S O R) \<union> (T O R)"
   1.594 +lemma relcomp_distrib2 [simp]: "(S \<union> T) O R = (S O R) \<union> (T O R)"
   1.595    by auto
   1.596  
   1.597 -lemma relcompp_distrib2 [simp]:
   1.598 -  "(S \<squnion> T) OO R = S OO R \<squnion> T OO R"
   1.599 +lemma relcompp_distrib2 [simp]: "(S \<squnion> T) OO R = S OO R \<squnion> T OO R"
   1.600    by (fact relcomp_distrib2 [to_pred])
   1.601  
   1.602 -lemma relcomp_UNION_distrib:
   1.603 -  "s O UNION I r = (\<Union>i\<in>I. s O r i) "
   1.604 +lemma relcomp_UNION_distrib: "s O UNION I r = (\<Union>i\<in>I. s O r i) "
   1.605    by auto
   1.606  
   1.607  (* FIXME thm relcomp_UNION_distrib [to_pred] *)
   1.608  
   1.609 -lemma relcomp_UNION_distrib2:
   1.610 -  "UNION I r O s = (\<Union>i\<in>I. r i O s) "
   1.611 +lemma relcomp_UNION_distrib2: "UNION I r O s = (\<Union>i\<in>I. r i O s) "
   1.612    by auto
   1.613  
   1.614  (* FIXME thm relcomp_UNION_distrib2 [to_pred] *)
   1.615  
   1.616 -lemma single_valued_relcomp:
   1.617 -  "single_valued r \<Longrightarrow> single_valued s \<Longrightarrow> single_valued (r O s)"
   1.618 -  by (unfold single_valued_def) blast
   1.619 +lemma single_valued_relcomp: "single_valued r \<Longrightarrow> single_valued s \<Longrightarrow> single_valued (r O s)"
   1.620 +  unfolding single_valued_def by blast
   1.621  
   1.622 -lemma relcomp_unfold:
   1.623 -  "r O s = {(x, z). \<exists>y. (x, y) \<in> r \<and> (y, z) \<in> s}"
   1.624 +lemma relcomp_unfold: "r O s = {(x, z). \<exists>y. (x, y) \<in> r \<and> (y, z) \<in> s}"
   1.625    by (auto simp add: set_eq_iff)
   1.626  
   1.627  lemma relcompp_apply: "(R OO S) a c \<longleftrightarrow> (\<exists>b. R a b \<and> S b c)"
   1.628    unfolding relcomp_unfold [to_pred] ..
   1.629  
   1.630  lemma eq_OO: "op= OO R = R"
   1.631 -by blast
   1.632 +  by blast
   1.633  
   1.634  lemma OO_eq: "R OO op = = R"
   1.635 -by blast
   1.636 +  by blast
   1.637  
   1.638  
   1.639  subsubsection \<open>Converse\<close>
   1.640  
   1.641  inductive_set converse :: "('a \<times> 'b) set \<Rightarrow> ('b \<times> 'a) set"  ("(_\<inverse>)" [1000] 999)
   1.642    for r :: "('a \<times> 'b) set"
   1.643 -where
   1.644 -  "(a, b) \<in> r \<Longrightarrow> (b, a) \<in> r\<inverse>"
   1.645 +  where "(a, b) \<in> r \<Longrightarrow> (b, a) \<in> r\<inverse>"
   1.646  
   1.647 -notation
   1.648 -  conversep  ("(_\<inverse>\<inverse>)" [1000] 1000)
   1.649 +notation conversep  ("(_\<inverse>\<inverse>)" [1000] 1000)
   1.650  
   1.651  notation (ASCII)
   1.652    converse  ("(_^-1)" [1000] 999) and
   1.653    conversep ("(_^--1)" [1000] 1000)
   1.654  
   1.655 -lemma converseI [sym]:
   1.656 -  "(a, b) \<in> r \<Longrightarrow> (b, a) \<in> r\<inverse>"
   1.657 +lemma converseI [sym]: "(a, b) \<in> r \<Longrightarrow> (b, a) \<in> r\<inverse>"
   1.658    by (fact converse.intros)
   1.659  
   1.660 -lemma conversepI (* CANDIDATE [sym] *):
   1.661 -  "r a b \<Longrightarrow> r\<inverse>\<inverse> b a"
   1.662 +lemma conversepI (* CANDIDATE [sym] *): "r a b \<Longrightarrow> r\<inverse>\<inverse> b a"
   1.663    by (fact conversep.intros)
   1.664  
   1.665 -lemma converseD [sym]:
   1.666 -  "(a, b) \<in> r\<inverse> \<Longrightarrow> (b, a) \<in> r"
   1.667 +lemma converseD [sym]: "(a, b) \<in> r\<inverse> \<Longrightarrow> (b, a) \<in> r"
   1.668    by (erule converse.cases) iprover
   1.669  
   1.670 -lemma conversepD (* CANDIDATE [sym] *):
   1.671 -  "r\<inverse>\<inverse> b a \<Longrightarrow> r a b"
   1.672 +lemma conversepD (* CANDIDATE [sym] *): "r\<inverse>\<inverse> b a \<Longrightarrow> r a b"
   1.673    by (fact converseD [to_pred])
   1.674  
   1.675 -lemma converseE [elim!]:
   1.676 +lemma converseE [elim!]: "yx \<in> r\<inverse> \<Longrightarrow> (\<And>x y. yx = (y, x) \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> P) \<Longrightarrow> P"
   1.677    \<comment> \<open>More general than \<open>converseD\<close>, as it ``splits'' the member of the relation.\<close>
   1.678 -  "yx \<in> r\<inverse> \<Longrightarrow> (\<And>x y. yx = (y, x) \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> P) \<Longrightarrow> P"
   1.679 -  by (cases yx) (simp, erule converse.cases, iprover)
   1.680 +  apply (cases yx)
   1.681 +  apply simp
   1.682 +  apply (erule converse.cases)
   1.683 +  apply iprover
   1.684 +  done
   1.685  
   1.686  lemmas conversepE [elim!] = conversep.cases
   1.687  
   1.688 -lemma converse_iff [iff]:
   1.689 -  "(a, b) \<in> r\<inverse> \<longleftrightarrow> (b, a) \<in> r"
   1.690 +lemma converse_iff [iff]: "(a, b) \<in> r\<inverse> \<longleftrightarrow> (b, a) \<in> r"
   1.691    by (auto intro: converseI)
   1.692  
   1.693 -lemma conversep_iff [iff]:
   1.694 -  "r\<inverse>\<inverse> a b = r b a"
   1.695 +lemma conversep_iff [iff]: "r\<inverse>\<inverse> a b = r b a"
   1.696    by (fact converse_iff [to_pred])
   1.697  
   1.698 -lemma converse_converse [simp]:
   1.699 -  "(r\<inverse>)\<inverse> = r"
   1.700 +lemma converse_converse [simp]: "(r\<inverse>)\<inverse> = r"
   1.701    by (simp add: set_eq_iff)
   1.702  
   1.703 -lemma conversep_conversep [simp]:
   1.704 -  "(r\<inverse>\<inverse>)\<inverse>\<inverse> = r"
   1.705 +lemma conversep_conversep [simp]: "(r\<inverse>\<inverse>)\<inverse>\<inverse> = r"
   1.706    by (fact converse_converse [to_pred])
   1.707  
   1.708  lemma converse_empty[simp]: "{}\<inverse> = {}"
   1.709 -by auto
   1.710 +  by auto
   1.711  
   1.712  lemma converse_UNIV[simp]: "UNIV\<inverse> = UNIV"
   1.713 -by auto
   1.714 +  by auto
   1.715  
   1.716 -lemma converse_relcomp: "(r O s)^-1 = s^-1 O r^-1"
   1.717 +lemma converse_relcomp: "(r O s)\<inverse> = s\<inverse> O r\<inverse>"
   1.718    by blast
   1.719  
   1.720 -lemma converse_relcompp: "(r OO s)^--1 = s^--1 OO r^--1"
   1.721 -  by (iprover intro: order_antisym conversepI relcomppI
   1.722 -    elim: relcomppE dest: conversepD)
   1.723 +lemma converse_relcompp: "(r OO s)\<inverse>\<inverse> = s\<inverse>\<inverse> OO r\<inverse>\<inverse>"
   1.724 +  by (iprover intro: order_antisym conversepI relcomppI elim: relcomppE dest: conversepD)
   1.725  
   1.726 -lemma converse_Int: "(r \<inter> s)^-1 = r^-1 \<inter> s^-1"
   1.727 +lemma converse_Int: "(r \<inter> s)\<inverse> = r\<inverse> \<inter> s\<inverse>"
   1.728    by blast
   1.729  
   1.730 -lemma converse_meet: "(r \<sqinter> s)^--1 = r^--1 \<sqinter> s^--1"
   1.731 +lemma converse_meet: "(r \<sqinter> s)\<inverse>\<inverse> = r\<inverse>\<inverse> \<sqinter> s\<inverse>\<inverse>"
   1.732    by (simp add: inf_fun_def) (iprover intro: conversepI ext dest: conversepD)
   1.733  
   1.734 -lemma converse_Un: "(r \<union> s)^-1 = r^-1 \<union> s^-1"
   1.735 +lemma converse_Un: "(r \<union> s)\<inverse> = r\<inverse> \<union> s\<inverse>"
   1.736    by blast
   1.737  
   1.738 -lemma converse_join: "(r \<squnion> s)^--1 = r^--1 \<squnion> s^--1"
   1.739 +lemma converse_join: "(r \<squnion> s)\<inverse>\<inverse> = r\<inverse>\<inverse> \<squnion> s\<inverse>\<inverse>"
   1.740    by (simp add: sup_fun_def) (iprover intro: conversepI ext dest: conversepD)
   1.741  
   1.742 -lemma converse_INTER: "(INTER S r)^-1 = (INT x:S. (r x)^-1)"
   1.743 +lemma converse_INTER: "(INTER S r)\<inverse> = (INT x:S. (r x)\<inverse>)"
   1.744    by fast
   1.745  
   1.746 -lemma converse_UNION: "(UNION S r)^-1 = (UN x:S. (r x)^-1)"
   1.747 +lemma converse_UNION: "(UNION S r)\<inverse> = (UN x:S. (r x)\<inverse>)"
   1.748    by blast
   1.749  
   1.750 -lemma converse_mono[simp]: "r^-1 \<subseteq> s ^-1 \<longleftrightarrow> r \<subseteq> s"
   1.751 +lemma converse_mono[simp]: "r\<inverse> \<subseteq> s \<inverse> \<longleftrightarrow> r \<subseteq> s"
   1.752    by auto
   1.753  
   1.754 -lemma conversep_mono[simp]: "r^--1 \<le> s ^--1 \<longleftrightarrow> r \<le> s"
   1.755 +lemma conversep_mono[simp]: "r\<inverse>\<inverse> \<le> s \<inverse>\<inverse> \<longleftrightarrow> r \<le> s"
   1.756    by (fact converse_mono[to_pred])
   1.757  
   1.758 -lemma converse_inject[simp]: "r^-1 = s ^-1 \<longleftrightarrow> r = s"
   1.759 +lemma converse_inject[simp]: "r\<inverse> = s \<inverse> \<longleftrightarrow> r = s"
   1.760    by auto
   1.761  
   1.762 -lemma conversep_inject[simp]: "r^--1 = s ^--1 \<longleftrightarrow> r = s"
   1.763 +lemma conversep_inject[simp]: "r\<inverse>\<inverse> = s \<inverse>\<inverse> \<longleftrightarrow> r = s"
   1.764    by (fact converse_inject[to_pred])
   1.765  
   1.766 -lemma converse_subset_swap: "r \<subseteq> s ^-1 = (r ^-1 \<subseteq> s)"
   1.767 +lemma converse_subset_swap: "r \<subseteq> s \<inverse> = (r \<inverse> \<subseteq> s)"
   1.768    by auto
   1.769  
   1.770 -lemma conversep_le_swap: "r \<le> s ^--1 = (r ^--1 \<le> s)"
   1.771 +lemma conversep_le_swap: "r \<le> s \<inverse>\<inverse> = (r \<inverse>\<inverse> \<le> s)"
   1.772    by (fact converse_subset_swap[to_pred])
   1.773  
   1.774 -lemma converse_Id [simp]: "Id^-1 = Id"
   1.775 +lemma converse_Id [simp]: "Id\<inverse> = Id"
   1.776    by blast
   1.777  
   1.778 -lemma converse_Id_on [simp]: "(Id_on A)^-1 = Id_on A"
   1.779 +lemma converse_Id_on [simp]: "(Id_on A)\<inverse> = Id_on A"
   1.780    by blast
   1.781  
   1.782  lemma refl_on_converse [simp]: "refl_on A (converse r) = refl_on A r"
   1.783 -  by (unfold refl_on_def) auto
   1.784 +  by (auto simp: refl_on_def)
   1.785  
   1.786  lemma sym_converse [simp]: "sym (converse r) = sym r"
   1.787 -  by (unfold sym_def) blast
   1.788 +  unfolding sym_def by blast
   1.789  
   1.790  lemma antisym_converse [simp]: "antisym (converse r) = antisym r"
   1.791 -  by (unfold antisym_def) blast
   1.792 +  unfolding antisym_def by blast
   1.793  
   1.794  lemma trans_converse [simp]: "trans (converse r) = trans r"
   1.795 -  by (unfold trans_def) blast
   1.796 +  unfolding trans_def by blast
   1.797  
   1.798 -lemma sym_conv_converse_eq: "sym r = (r^-1 = r)"
   1.799 -  by (unfold sym_def) fast
   1.800 +lemma sym_conv_converse_eq: "sym r \<longleftrightarrow> r\<inverse> = r"
   1.801 +  unfolding sym_def by fast
   1.802  
   1.803 -lemma sym_Un_converse: "sym (r \<union> r^-1)"
   1.804 -  by (unfold sym_def) blast
   1.805 +lemma sym_Un_converse: "sym (r \<union> r\<inverse>)"
   1.806 +  unfolding sym_def by blast
   1.807  
   1.808 -lemma sym_Int_converse: "sym (r \<inter> r^-1)"
   1.809 -  by (unfold sym_def) blast
   1.810 +lemma sym_Int_converse: "sym (r \<inter> r\<inverse>)"
   1.811 +  unfolding sym_def by blast
   1.812  
   1.813 -lemma total_on_converse [simp]: "total_on A (r^-1) = total_on A r"
   1.814 +lemma total_on_converse [simp]: "total_on A (r\<inverse>) = total_on A r"
   1.815    by (auto simp: total_on_def)
   1.816  
   1.817 -lemma finite_converse [iff]: "finite (r^-1) = finite r"  
   1.818 +lemma finite_converse [iff]: "finite (r\<inverse>) = finite r"
   1.819    unfolding converse_def conversep_iff using [[simproc add: finite_Collect]]
   1.820    by (auto elim: finite_imageD simp: inj_on_def)
   1.821  
   1.822 -lemma conversep_noteq [simp]: "(op \<noteq>)^--1 = op \<noteq>"
   1.823 +lemma conversep_noteq [simp]: "(op \<noteq>)\<inverse>\<inverse> = op \<noteq>"
   1.824    by (auto simp add: fun_eq_iff)
   1.825  
   1.826 -lemma conversep_eq [simp]: "(op =)^--1 = op ="
   1.827 +lemma conversep_eq [simp]: "(op =)\<inverse>\<inverse> = op ="
   1.828    by (auto simp add: fun_eq_iff)
   1.829  
   1.830 -lemma converse_unfold [code]:
   1.831 -  "r\<inverse> = {(y, x). (x, y) \<in> r}"
   1.832 +lemma converse_unfold [code]: "r\<inverse> = {(y, x). (x, y) \<in> r}"
   1.833    by (simp add: set_eq_iff)
   1.834  
   1.835  
   1.836  subsubsection \<open>Domain, range and field\<close>
   1.837  
   1.838 -inductive_set Domain :: "('a \<times> 'b) set \<Rightarrow> 'a set"
   1.839 -  for r :: "('a \<times> 'b) set"
   1.840 -where
   1.841 -  DomainI [intro]: "(a, b) \<in> r \<Longrightarrow> a \<in> Domain r"
   1.842 +inductive_set Domain :: "('a \<times> 'b) set \<Rightarrow> 'a set" for r :: "('a \<times> 'b) set"
   1.843 +  where DomainI [intro]: "(a, b) \<in> r \<Longrightarrow> a \<in> Domain r"
   1.844  
   1.845  lemmas DomainPI = Domainp.DomainI
   1.846  
   1.847  inductive_cases DomainE [elim!]: "a \<in> Domain r"
   1.848  inductive_cases DomainpE [elim!]: "Domainp r a"
   1.849  
   1.850 -inductive_set Range :: "('a \<times> 'b) set \<Rightarrow> 'b set"
   1.851 -  for r :: "('a \<times> 'b) set"
   1.852 -where
   1.853 -  RangeI [intro]: "(a, b) \<in> r \<Longrightarrow> b \<in> Range r"
   1.854 +inductive_set Range :: "('a \<times> 'b) set \<Rightarrow> 'b set" for r :: "('a \<times> 'b) set"
   1.855 +  where RangeI [intro]: "(a, b) \<in> r \<Longrightarrow> b \<in> Range r"
   1.856  
   1.857  lemmas RangePI = Rangep.RangeI
   1.858  
   1.859 @@ -858,15 +774,12 @@
   1.860  inductive_cases RangepE [elim!]: "Rangep r b"
   1.861  
   1.862  definition Field :: "'a rel \<Rightarrow> 'a set"
   1.863 -where
   1.864 -  "Field r = Domain r \<union> Range r"
   1.865 +  where "Field r = Domain r \<union> Range r"
   1.866  
   1.867 -lemma Domain_fst [code]:
   1.868 -  "Domain r = fst ` r"
   1.869 +lemma Domain_fst [code]: "Domain r = fst ` r"
   1.870    by force
   1.871  
   1.872 -lemma Range_snd [code]:
   1.873 -  "Range r = snd ` r"
   1.874 +lemma Range_snd [code]: "Range r = snd ` r"
   1.875    by force
   1.876  
   1.877  lemma fst_eq_Domain: "fst ` R = Domain R"
   1.878 @@ -962,10 +875,10 @@
   1.879  lemma Field_converse [simp]: "Field (r\<inverse>) = Field r"
   1.880    by (auto simp: Field_def)
   1.881  
   1.882 -lemma Domain_Collect_case_prod [simp]: "Domain {(x, y). P x y} = {x. EX y. P x y}"
   1.883 +lemma Domain_Collect_case_prod [simp]: "Domain {(x, y). P x y} = {x. \<exists>y. P x y}"
   1.884    by auto
   1.885  
   1.886 -lemma Range_Collect_case_prod [simp]: "Range {(x, y). P x y} = {y. EX x. P x y}"
   1.887 +lemma Range_Collect_case_prod [simp]: "Range {(x, y). P x y} = {y. \<exists>x. P x y}"
   1.888    by auto
   1.889  
   1.890  lemma finite_Domain: "finite r \<Longrightarrow> finite (Domain r)"
   1.891 @@ -986,34 +899,31 @@
   1.892  lemma mono_Field: "r \<subseteq> s \<Longrightarrow> Field r \<subseteq> Field s"
   1.893    by (auto simp: Field_def Domain_def Range_def)
   1.894  
   1.895 -lemma Domain_unfold:
   1.896 -  "Domain r = {x. \<exists>y. (x, y) \<in> r}"
   1.897 +lemma Domain_unfold: "Domain r = {x. \<exists>y. (x, y) \<in> r}"
   1.898    by blast
   1.899  
   1.900  
   1.901  subsubsection \<open>Image of a set under a relation\<close>
   1.902  
   1.903 -definition Image :: "('a \<times> 'b) set \<Rightarrow> 'a set \<Rightarrow> 'b set" (infixr "``" 90)
   1.904 -where
   1.905 -  "r `` s = {y. \<exists>x\<in>s. (x, y) \<in> r}"
   1.906 +definition Image :: "('a \<times> 'b) set \<Rightarrow> 'a set \<Rightarrow> 'b set"  (infixr "``" 90)
   1.907 +  where "r `` s = {y. \<exists>x\<in>s. (x, y) \<in> r}"
   1.908  
   1.909 -lemma Image_iff: "(b : r``A) = (EX x:A. (x, b) : r)"
   1.910 +lemma Image_iff: "b \<in> r``A \<longleftrightarrow> (\<exists>x\<in>A. (x, b) \<in> r)"
   1.911    by (simp add: Image_def)
   1.912  
   1.913 -lemma Image_singleton: "r``{a} = {b. (a, b) : r}"
   1.914 +lemma Image_singleton: "r``{a} = {b. (a, b) \<in> r}"
   1.915    by (simp add: Image_def)
   1.916  
   1.917 -lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a, b) : r)"
   1.918 +lemma Image_singleton_iff [iff]: "b \<in> r``{a} \<longleftrightarrow> (a, b) \<in> r"
   1.919    by (rule Image_iff [THEN trans]) simp
   1.920  
   1.921 -lemma ImageI [intro]: "(a, b) : r ==> a : A ==> b : r``A"
   1.922 -  by (unfold Image_def) blast
   1.923 +lemma ImageI [intro]: "(a, b) \<in> r \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> r``A"
   1.924 +  unfolding Image_def by blast
   1.925  
   1.926 -lemma ImageE [elim!]:
   1.927 -  "b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P"
   1.928 -  by (unfold Image_def) (iprover elim!: CollectE bexE)
   1.929 +lemma ImageE [elim!]: "b \<in> r `` A \<Longrightarrow> (\<And>x. (x, b) \<in> r \<Longrightarrow> x \<in> A \<Longrightarrow> P) \<Longrightarrow> P"
   1.930 +  unfolding Image_def by (iprover elim!: CollectE bexE)
   1.931  
   1.932 -lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A"
   1.933 +lemma rev_ImageI: "a \<in> A \<Longrightarrow> (a, b) \<in> r \<Longrightarrow> b \<in> r `` A"
   1.934    \<comment> \<open>This version's more effective when we already have the required \<open>a\<close>\<close>
   1.935    by blast
   1.936  
   1.937 @@ -1029,9 +939,8 @@
   1.938  lemma Image_Int_subset: "R `` (A \<inter> B) \<subseteq> R `` A \<inter> R `` B"
   1.939    by blast
   1.940  
   1.941 -lemma Image_Int_eq:
   1.942 -  "single_valued (converse R) ==> R `` (A \<inter> B) = R `` A \<inter> R `` B"
   1.943 -  by (simp add: single_valued_def, blast) 
   1.944 +lemma Image_Int_eq: "single_valued (converse R) \<Longrightarrow> R `` (A \<inter> B) = R `` A \<inter> R `` B"
   1.945 +  by (simp add: single_valued_def, blast)
   1.946  
   1.947  lemma Image_Un: "R `` (A \<union> B) = R `` A \<union> R `` B"
   1.948    by blast
   1.949 @@ -1039,14 +948,14 @@
   1.950  lemma Un_Image: "(R \<union> S) `` A = R `` A \<union> S `` A"
   1.951    by blast
   1.952  
   1.953 -lemma Image_subset: "r \<subseteq> A \<times> B ==> r``C \<subseteq> B"
   1.954 +lemma Image_subset: "r \<subseteq> A \<times> B \<Longrightarrow> r``C \<subseteq> B"
   1.955    by (iprover intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2)
   1.956  
   1.957  lemma Image_eq_UN: "r``B = (\<Union>y\<in> B. r``{y})"
   1.958    \<comment> \<open>NOT suitable for rewriting\<close>
   1.959    by blast
   1.960  
   1.961 -lemma Image_mono: "r' \<subseteq> r ==> A' \<subseteq> A ==> (r' `` A') \<subseteq> (r `` A)"
   1.962 +lemma Image_mono: "r' \<subseteq> r \<Longrightarrow> A' \<subseteq> A \<Longrightarrow> (r' `` A') \<subseteq> (r `` A)"
   1.963    by blast
   1.964  
   1.965  lemma Image_UN: "(r `` (UNION A B)) = (\<Union>x\<in>A. r `` (B x))"
   1.966 @@ -1058,19 +967,18 @@
   1.967  lemma Image_INT_subset: "(r `` INTER A B) \<subseteq> (\<Inter>x\<in>A. r `` (B x))"
   1.968    by blast
   1.969  
   1.970 -text\<open>Converse inclusion requires some assumptions\<close>
   1.971 -lemma Image_INT_eq:
   1.972 -  "single_valued (r\<inverse>) \<Longrightarrow> A \<noteq> {} \<Longrightarrow> r `` INTER A B = (\<Inter>x\<in>A. r `` B x)"
   1.973 -apply (rule equalityI)
   1.974 - apply (rule Image_INT_subset) 
   1.975 -apply (auto simp add: single_valued_def)
   1.976 -apply blast
   1.977 -done
   1.978 +text \<open>Converse inclusion requires some assumptions\<close>
   1.979 +lemma Image_INT_eq: "single_valued (r\<inverse>) \<Longrightarrow> A \<noteq> {} \<Longrightarrow> r `` INTER A B = (\<Inter>x\<in>A. r `` B x)"
   1.980 +  apply (rule equalityI)
   1.981 +   apply (rule Image_INT_subset)
   1.982 +  apply (auto simp add: single_valued_def)
   1.983 +  apply blast
   1.984 +  done
   1.985  
   1.986 -lemma Image_subset_eq: "(r``A \<subseteq> B) = (A \<subseteq> - ((r^-1) `` (-B)))"
   1.987 +lemma Image_subset_eq: "r``A \<subseteq> B \<longleftrightarrow> A \<subseteq> - ((r\<inverse>) `` (- B))"
   1.988    by blast
   1.989  
   1.990 -lemma Image_Collect_case_prod [simp]: "{(x, y). P x y} `` A = {y. EX x:A. P x y}"
   1.991 +lemma Image_Collect_case_prod [simp]: "{(x, y). P x y} `` A = {y. \<exists>x\<in>A. P x y}"
   1.992    by auto
   1.993  
   1.994  lemma Sigma_Image: "(SIGMA x:A. B x) `` X = (\<Union>x\<in>X \<inter> A. B x)"
   1.995 @@ -1083,29 +991,27 @@
   1.996  subsubsection \<open>Inverse image\<close>
   1.997  
   1.998  definition inv_image :: "'b rel \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a rel"
   1.999 -where
  1.1000 -  "inv_image r f = {(x, y). (f x, f y) \<in> r}"
  1.1001 +  where "inv_image r f = {(x, y). (f x, f y) \<in> r}"
  1.1002  
  1.1003  definition inv_imagep :: "('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool"
  1.1004 -where
  1.1005 -  "inv_imagep r f = (\<lambda>x y. r (f x) (f y))"
  1.1006 +  where "inv_imagep r f = (\<lambda>x y. r (f x) (f y))"
  1.1007  
  1.1008  lemma [pred_set_conv]: "inv_imagep (\<lambda>x y. (x, y) \<in> r) f = (\<lambda>x y. (x, y) \<in> inv_image r f)"
  1.1009    by (simp add: inv_image_def inv_imagep_def)
  1.1010  
  1.1011 -lemma sym_inv_image: "sym r ==> sym (inv_image r f)"
  1.1012 -  by (unfold sym_def inv_image_def) blast
  1.1013 +lemma sym_inv_image: "sym r \<Longrightarrow> sym (inv_image r f)"
  1.1014 +  unfolding sym_def inv_image_def by blast
  1.1015  
  1.1016 -lemma trans_inv_image: "trans r ==> trans (inv_image r f)"
  1.1017 -  apply (unfold trans_def inv_image_def)
  1.1018 +lemma trans_inv_image: "trans r \<Longrightarrow> trans (inv_image r f)"
  1.1019 +  unfolding trans_def inv_image_def
  1.1020    apply (simp (no_asm))
  1.1021    apply blast
  1.1022    done
  1.1023  
  1.1024 -lemma in_inv_image[simp]: "((x,y) : inv_image r f) = ((f x, f y) : r)"
  1.1025 +lemma in_inv_image[simp]: "(x, y) \<in> inv_image r f \<longleftrightarrow> (f x, f y) \<in> r"
  1.1026    by (auto simp:inv_image_def)
  1.1027  
  1.1028 -lemma converse_inv_image[simp]: "(inv_image R f)^-1 = inv_image (R^-1) f"
  1.1029 +lemma converse_inv_image[simp]: "(inv_image R f)\<inverse> = inv_image (R\<inverse>) f"
  1.1030    unfolding inv_image_def converse_unfold by auto
  1.1031  
  1.1032  lemma in_inv_imagep [simp]: "inv_imagep r f x y = r (f x) (f y)"
  1.1033 @@ -1115,8 +1021,7 @@
  1.1034  subsubsection \<open>Powerset\<close>
  1.1035  
  1.1036  definition Powp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool"
  1.1037 -where
  1.1038 -  "Powp A = (\<lambda>B. \<forall>x \<in> B. A x)"
  1.1039 +  where "Powp A = (\<lambda>B. \<forall>x \<in> B. A x)"
  1.1040  
  1.1041  lemma Powp_Pow_eq [pred_set_conv]: "Powp (\<lambda>x. x \<in> A) = (\<lambda>x. x \<in> Pow A)"
  1.1042    by (auto simp add: Powp_def fun_eq_iff)
  1.1043 @@ -1130,28 +1035,31 @@
  1.1044    assumes "finite A"
  1.1045    shows "Id_on A = Finite_Set.fold (\<lambda>x. Set.insert (Pair x x)) {} A"
  1.1046  proof -
  1.1047 -  interpret comp_fun_commute "\<lambda>x. Set.insert (Pair x x)" by standard auto
  1.1048 -  show ?thesis using assms unfolding Id_on_def by (induct A) simp_all
  1.1049 +  interpret comp_fun_commute "\<lambda>x. Set.insert (Pair x x)"
  1.1050 +    by standard auto
  1.1051 +  from assms show ?thesis
  1.1052 +    unfolding Id_on_def by (induct A) simp_all
  1.1053  qed
  1.1054  
  1.1055  lemma comp_fun_commute_Image_fold:
  1.1056    "comp_fun_commute (\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A)"
  1.1057  proof -
  1.1058    interpret comp_fun_idem Set.insert
  1.1059 -      by (fact comp_fun_idem_insert)
  1.1060 -  show ?thesis 
  1.1061 -  by standard (auto simp add: fun_eq_iff comp_fun_commute split:prod.split)
  1.1062 +    by (fact comp_fun_idem_insert)
  1.1063 +  show ?thesis
  1.1064 +    by standard (auto simp add: fun_eq_iff comp_fun_commute split: prod.split)
  1.1065  qed
  1.1066  
  1.1067  lemma Image_fold:
  1.1068    assumes "finite R"
  1.1069    shows "R `` S = Finite_Set.fold (\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A) {} R"
  1.1070  proof -
  1.1071 -  interpret comp_fun_commute "(\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A)" 
  1.1072 +  interpret comp_fun_commute "(\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A)"
  1.1073      by (rule comp_fun_commute_Image_fold)
  1.1074    have *: "\<And>x F. Set.insert x F `` S = (if fst x \<in> S then Set.insert (snd x) (F `` S) else (F `` S))"
  1.1075      by (force intro: rev_ImageI)
  1.1076 -  show ?thesis using assms by (induct R) (auto simp: *)
  1.1077 +  show ?thesis
  1.1078 +    using assms by (induct R) (auto simp: *)
  1.1079  qed
  1.1080  
  1.1081  lemma insert_relcomp_union_fold:
  1.1082 @@ -1159,56 +1067,56 @@
  1.1083    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"
  1.1084  proof -
  1.1085    interpret comp_fun_commute "\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A'"
  1.1086 -  proof - 
  1.1087 -    interpret comp_fun_idem Set.insert by (fact comp_fun_idem_insert)
  1.1088 +  proof -
  1.1089 +    interpret comp_fun_idem Set.insert
  1.1090 +      by (fact comp_fun_idem_insert)
  1.1091      show "comp_fun_commute (\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A')"
  1.1092 -    by standard (auto simp add: fun_eq_iff split:prod.split)
  1.1093 +      by standard (auto simp add: fun_eq_iff split: prod.split)
  1.1094    qed
  1.1095 -  have *: "{x} O S = {(x', z). x' = fst x \<and> (snd x,z) \<in> S}" by (auto simp: relcomp_unfold intro!: exI)
  1.1096 -  show ?thesis unfolding *
  1.1097 -  using \<open>finite S\<close> by (induct S) (auto split: prod.split)
  1.1098 +  have *: "{x} O S = {(x', z). x' = fst x \<and> (snd x, z) \<in> S}"
  1.1099 +    by (auto simp: relcomp_unfold intro!: exI)
  1.1100 +  show ?thesis
  1.1101 +    unfolding * using \<open>finite S\<close> by (induct S) (auto split: prod.split)
  1.1102  qed
  1.1103  
  1.1104  lemma insert_relcomp_fold:
  1.1105    assumes "finite S"
  1.1106 -  shows "Set.insert x R O S = 
  1.1107 +  shows "Set.insert x R O S =
  1.1108      Finite_Set.fold (\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A') (R O S) S"
  1.1109  proof -
  1.1110 -  have "Set.insert x R O S = ({x} O S) \<union> (R O S)" by auto
  1.1111 -  then show ?thesis by (auto simp: insert_relcomp_union_fold[OF assms])
  1.1112 +  have "Set.insert x R O S = ({x} O S) \<union> (R O S)"
  1.1113 +    by auto
  1.1114 +  then show ?thesis
  1.1115 +    by (auto simp: insert_relcomp_union_fold [OF assms])
  1.1116  qed
  1.1117  
  1.1118  lemma comp_fun_commute_relcomp_fold:
  1.1119    assumes "finite S"
  1.1120 -  shows "comp_fun_commute (\<lambda>(x,y) A. 
  1.1121 +  shows "comp_fun_commute (\<lambda>(x,y) A.
  1.1122      Finite_Set.fold (\<lambda>(w,z) A'. if y = w then Set.insert (x,z) A' else A') A S)"
  1.1123  proof -
  1.1124 -  have *: "\<And>a b A. 
  1.1125 +  have *: "\<And>a b A.
  1.1126      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"
  1.1127      by (auto simp: insert_relcomp_union_fold[OF assms] cong: if_cong)
  1.1128 -  show ?thesis by standard (auto simp: *)
  1.1129 +  show ?thesis
  1.1130 +    by standard (auto simp: *)
  1.1131  qed
  1.1132  
  1.1133  lemma relcomp_fold:
  1.1134 -  assumes "finite R"
  1.1135 -  assumes "finite S"
  1.1136 -  shows "R O S = Finite_Set.fold 
  1.1137 +  assumes "finite R" "finite S"
  1.1138 +  shows "R O S = Finite_Set.fold
  1.1139      (\<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"
  1.1140 -  using assms by (induct R)
  1.1141 +  using assms
  1.1142 +  by (induct R)
  1.1143      (auto simp: comp_fun_commute.fold_insert comp_fun_commute_relcomp_fold insert_relcomp_fold
  1.1144        cong: if_cong)
  1.1145  
  1.1146  text \<open>Misc\<close>
  1.1147  
  1.1148  abbreviation (input) transP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
  1.1149 -where \<comment> \<open>FIXME drop\<close>
  1.1150 -  "transP r \<equiv> trans {(x, y). r x y}"
  1.1151 +  where "transP r \<equiv> trans {(x, y). r x y}"  (* FIXME drop *)
  1.1152  
  1.1153 -abbreviation (input)
  1.1154 -  "RangeP \<equiv> Rangep"
  1.1155 -
  1.1156 -abbreviation (input)
  1.1157 -  "DomainP \<equiv> Domainp"
  1.1158 -
  1.1159 +abbreviation (input) "RangeP \<equiv> Rangep"
  1.1160 +abbreviation (input) "DomainP \<equiv> Domainp"
  1.1161  
  1.1162  end