
diff -r 3869b2400e22 -r 0d25e02759b7 src/HOL/HOLCF/Fix.thy
--- a/src/HOL/HOLCF/Fix.thy	Mon Jan 01 21:17:28 2018 +0100
+++ b/src/HOL/HOLCF/Fix.thy	Mon Jan 01 23:07:24 2018 +0100
@@ -6,51 +6,50 @@
 section \<open>Fixed point operator and admissibility\<close>
 
 theory Fix
-imports Cfun
+  imports Cfun
 begin
 
 default_sort pcpo
 
+
 subsection \<open>Iteration\<close>
 
-primrec iterate :: "nat \<Rightarrow> ('a::cpo \<rightarrow> 'a) \<rightarrow> ('a \<rightarrow> 'a)" where
+primrec iterate :: "nat \<Rightarrow> ('a::cpo \<rightarrow> 'a) \<rightarrow> ('a \<rightarrow> 'a)"
+  where
     "iterate 0 = (\<Lambda> F x. x)"
   | "iterate (Suc n) = (\<Lambda> F x. F\<cdot>(iterate n\<cdot>F\<cdot>x))"
 
 text \<open>Derive inductive properties of iterate from primitive recursion\<close>
 
 lemma iterate_0 [simp]: "iterate 0\<cdot>F\<cdot>x = x"
-by simp
+  by simp
 
 lemma iterate_Suc [simp]: "iterate (Suc n)\<cdot>F\<cdot>x = F\<cdot>(iterate n\<cdot>F\<cdot>x)"
-by simp
+  by simp
 
 declare iterate.simps [simp del]
 
 lemma iterate_Suc2: "iterate (Suc n)\<cdot>F\<cdot>x = iterate n\<cdot>F\<cdot>(F\<cdot>x)"
-by (induct n) simp_all
+  by (induct n) simp_all
 
-lemma iterate_iterate:
-  "iterate m\<cdot>F\<cdot>(iterate n\<cdot>F\<cdot>x) = iterate (m + n)\<cdot>F\<cdot>x"
-by (induct m) simp_all
+lemma iterate_iterate: "iterate m\<cdot>F\<cdot>(iterate n\<cdot>F\<cdot>x) = iterate (m + n)\<cdot>F\<cdot>x"
+  by (induct m) simp_all
 
 text \<open>The sequence of function iterations is a chain.\<close>
 
 lemma chain_iterate [simp]: "chain (\<lambda>i. iterate i\<cdot>F\<cdot>\<bottom>)"
-by (rule chainI, unfold iterate_Suc2, rule monofun_cfun_arg, rule minimal)
+  by (rule chainI, unfold iterate_Suc2, rule monofun_cfun_arg, rule minimal)
 
 
 subsection \<open>Least fixed point operator\<close>
 
-definition
-  "fix" :: "('a \<rightarrow> 'a) \<rightarrow> 'a" where
-  "fix = (\<Lambda> F. \<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>)"
+definition "fix" :: "('a \<rightarrow> 'a) \<rightarrow> 'a"
+  where "fix = (\<Lambda> F. \<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>)"
 
 text \<open>Binder syntax for @{term fix}\<close>
 
-abbreviation
-  fix_syn :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"  (binder "\<mu> " 10) where
-  "fix_syn (\<lambda>x. f x) \<equiv> fix\<cdot>(\<Lambda> x. f x)"
+abbreviation fix_syn :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"  (binder "\<mu> " 10)
+  where "fix_syn (\<lambda>x. f x) \<equiv> fix\<cdot>(\<Lambda> x. f x)"
 
 notation (ASCII)
   fix_syn  (binder "FIX " 10)
@@ -60,7 +59,7 @@
 text \<open>direct connection between @{term fix} and iteration\<close>
 
 lemma fix_def2: "fix\<cdot>F = (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>)"
-unfolding fix_def by simp
+  by (simp add: fix_def)
 
 lemma iterate_below_fix: "iterate n\<cdot>f\<cdot>\<bottom> \<sqsubseteq> fix\<cdot>f"
   unfolding fix_def2
@@ -72,105 +71,103 @@
 \<close>
 
 lemma fix_eq: "fix\<cdot>F = F\<cdot>(fix\<cdot>F)"
-apply (simp add: fix_def2)
-apply (subst lub_range_shift [of _ 1, symmetric])
-apply (rule chain_iterate)
-apply (subst contlub_cfun_arg)
-apply (rule chain_iterate)
-apply simp
-done
+  apply (simp add: fix_def2)
+  apply (subst lub_range_shift [of _ 1, symmetric])
+   apply (rule chain_iterate)
+  apply (subst contlub_cfun_arg)
+   apply (rule chain_iterate)
+  apply simp
+  done
 
 lemma fix_least_below: "F\<cdot>x \<sqsubseteq> x \<Longrightarrow> fix\<cdot>F \<sqsubseteq> x"
-apply (simp add: fix_def2)
-apply (rule lub_below)
-apply (rule chain_iterate)
-apply (induct_tac i)
-apply simp
-apply simp
-apply (erule rev_below_trans)
-apply (erule monofun_cfun_arg)
-done
+  apply (simp add: fix_def2)
+  apply (rule lub_below)
+   apply (rule chain_iterate)
+  apply (induct_tac i)
+   apply simp
+  apply simp
+  apply (erule rev_below_trans)
+  apply (erule monofun_cfun_arg)
+  done
 
 lemma fix_least: "F\<cdot>x = x \<Longrightarrow> fix\<cdot>F \<sqsubseteq> x"
-by (rule fix_least_below, simp)
+  by (rule fix_least_below) simp
 
 lemma fix_eqI:
-  assumes fixed: "F\<cdot>x = x" and least: "\<And>z. F\<cdot>z = z \<Longrightarrow> x \<sqsubseteq> z"
+  assumes fixed: "F\<cdot>x = x"
+    and least: "\<And>z. F\<cdot>z = z \<Longrightarrow> x \<sqsubseteq> z"
   shows "fix\<cdot>F = x"
-apply (rule below_antisym)
-apply (rule fix_least [OF fixed])
-apply (rule least [OF fix_eq [symmetric]])
-done
+  apply (rule below_antisym)
+   apply (rule fix_least [OF fixed])
+  apply (rule least [OF fix_eq [symmetric]])
+  done
 
 lemma fix_eq2: "f \<equiv> fix\<cdot>F \<Longrightarrow> f = F\<cdot>f"
-by (simp add: fix_eq [symmetric])
+  by (simp add: fix_eq [symmetric])
 
 lemma fix_eq3: "f \<equiv> fix\<cdot>F \<Longrightarrow> f\<cdot>x = F\<cdot>f\<cdot>x"
-by (erule fix_eq2 [THEN cfun_fun_cong])
+  by (erule fix_eq2 [THEN cfun_fun_cong])
 
 lemma fix_eq4: "f = fix\<cdot>F \<Longrightarrow> f = F\<cdot>f"
-apply (erule ssubst)
-apply (rule fix_eq)
-done
+  by (erule ssubst) (rule fix_eq)
 
 lemma fix_eq5: "f = fix\<cdot>F \<Longrightarrow> f\<cdot>x = F\<cdot>f\<cdot>x"
-by (erule fix_eq4 [THEN cfun_fun_cong])
+  by (erule fix_eq4 [THEN cfun_fun_cong])
 
 text \<open>strictness of @{term fix}\<close>
 
-lemma fix_bottom_iff: "(fix\<cdot>F = \<bottom>) = (F\<cdot>\<bottom> = \<bottom>)"
-apply (rule iffI)
-apply (erule subst)
-apply (rule fix_eq [symmetric])
-apply (erule fix_least [THEN bottomI])
-done
+lemma fix_bottom_iff: "fix\<cdot>F = \<bottom> \<longleftrightarrow> F\<cdot>\<bottom> = \<bottom>"
+  apply (rule iffI)
+   apply (erule subst)
+   apply (rule fix_eq [symmetric])
+  apply (erule fix_least [THEN bottomI])
+  done
 
 lemma fix_strict: "F\<cdot>\<bottom> = \<bottom> \<Longrightarrow> fix\<cdot>F = \<bottom>"
-by (simp add: fix_bottom_iff)
+  by (simp add: fix_bottom_iff)
 
 lemma fix_defined: "F\<cdot>\<bottom> \<noteq> \<bottom> \<Longrightarrow> fix\<cdot>F \<noteq> \<bottom>"
-by (simp add: fix_bottom_iff)
+  by (simp add: fix_bottom_iff)
 
 text \<open>@{term fix} applied to identity and constant functions\<close>
 
 lemma fix_id: "(\<mu> x. x) = \<bottom>"
-by (simp add: fix_strict)
+  by (simp add: fix_strict)
 
 lemma fix_const: "(\<mu> x. c) = c"
-by (subst fix_eq, simp)
+  by (subst fix_eq) simp
+
 
 subsection \<open>Fixed point induction\<close>
 
-lemma fix_ind: "\<lbrakk>adm P; P \<bottom>; \<And>x. P x \<Longrightarrow> P (F\<cdot>x)\<rbrakk> \<Longrightarrow> P (fix\<cdot>F)"
-unfolding fix_def2
-apply (erule admD)
-apply (rule chain_iterate)
-apply (rule nat_induct, simp_all)
-done
+lemma fix_ind: "adm P \<Longrightarrow> P \<bottom> \<Longrightarrow> (\<And>x. P x \<Longrightarrow> P (F\<cdot>x)) \<Longrightarrow> P (fix\<cdot>F)"
+  unfolding fix_def2
+  apply (erule admD)
+   apply (rule chain_iterate)
+  apply (rule nat_induct, simp_all)
+  done
 
-lemma cont_fix_ind:
-  "\<lbrakk>cont F; adm P; P \<bottom>; \<And>x. P x \<Longrightarrow> P (F x)\<rbrakk> \<Longrightarrow> P (fix\<cdot>(Abs_cfun F))"
-by (simp add: fix_ind)
+lemma cont_fix_ind: "cont F \<Longrightarrow> adm P \<Longrightarrow> P \<bottom> \<Longrightarrow> (\<And>x. P x \<Longrightarrow> P (F x)) \<Longrightarrow> P (fix\<cdot>(Abs_cfun F))"
+  by (simp add: fix_ind)
 
-lemma def_fix_ind:
-  "\<lbrakk>f \<equiv> fix\<cdot>F; adm P; P \<bottom>; \<And>x. P x \<Longrightarrow> P (F\<cdot>x)\<rbrakk> \<Longrightarrow> P f"
-by (simp add: fix_ind)
+lemma def_fix_ind: "\<lbrakk>f \<equiv> fix\<cdot>F; adm P; P \<bottom>; \<And>x. P x \<Longrightarrow> P (F\<cdot>x)\<rbrakk> \<Longrightarrow> P f"
+  by (simp add: fix_ind)
 
 lemma fix_ind2:
   assumes adm: "adm P"
   assumes 0: "P \<bottom>" and 1: "P (F\<cdot>\<bottom>)"
   assumes step: "\<And>x. \<lbrakk>P x; P (F\<cdot>x)\<rbrakk> \<Longrightarrow> P (F\<cdot>(F\<cdot>x))"
   shows "P (fix\<cdot>F)"
-unfolding fix_def2
-apply (rule admD [OF adm chain_iterate])
-apply (rule nat_less_induct)
-apply (case_tac n)
-apply (simp add: 0)
-apply (case_tac nat)
-apply (simp add: 1)
-apply (frule_tac x=nat in spec)
-apply (simp add: step)
-done
+  unfolding fix_def2
+  apply (rule admD [OF adm chain_iterate])
+  apply (rule nat_less_induct)
+  apply (case_tac n)
+   apply (simp add: 0)
+  apply (case_tac nat)
+   apply (simp add: 1)
+  apply (frule_tac x=nat in spec)
+  apply (simp add: step)
+  done
 
 lemma parallel_fix_ind:
   assumes adm: "adm (\<lambda>x. P (fst x) (snd x))"
@@ -180,17 +177,17 @@
 proof -
   from adm have adm': "adm (case_prod P)"
     unfolding split_def .
-  have "\<And>i. P (iterate i\<cdot>F\<cdot>\<bottom>) (iterate i\<cdot>G\<cdot>\<bottom>)"
-    by (induct_tac i, simp add: base, simp add: step)
-  hence "\<And>i. case_prod P (iterate i\<cdot>F\<cdot>\<bottom>, iterate i\<cdot>G\<cdot>\<bottom>)"
+  have "P (iterate i\<cdot>F\<cdot>\<bottom>) (iterate i\<cdot>G\<cdot>\<bottom>)" for i
+    by (induct i) (simp add: base, simp add: step)
+  then have "\<And>i. case_prod P (iterate i\<cdot>F\<cdot>\<bottom>, iterate i\<cdot>G\<cdot>\<bottom>)"
     by simp
-  hence "case_prod P (\<Squnion>i. (iterate i\<cdot>F\<cdot>\<bottom>, iterate i\<cdot>G\<cdot>\<bottom>))"
+  then have "case_prod P (\<Squnion>i. (iterate i\<cdot>F\<cdot>\<bottom>, iterate i\<cdot>G\<cdot>\<bottom>))"
     by - (rule admD [OF adm'], simp, assumption)
-  hence "case_prod P (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>, \<Squnion>i. iterate i\<cdot>G\<cdot>\<bottom>)"
+  then have "case_prod P (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>, \<Squnion>i. iterate i\<cdot>G\<cdot>\<bottom>)"
     by (simp add: lub_Pair)
-  hence "P (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>) (\<Squnion>i. iterate i\<cdot>G\<cdot>\<bottom>)"
+  then have "P (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>) (\<Squnion>i. iterate i\<cdot>G\<cdot>\<bottom>)"
     by simp
-  thus "P (fix\<cdot>F) (fix\<cdot>G)"
+  then show "P (fix\<cdot>F) (fix\<cdot>G)"
     by (simp add: fix_def2)
 qed
 
@@ -200,7 +197,8 @@
   assumes "P \<bottom> \<bottom>"
   assumes "\<And>x y. P x y \<Longrightarrow> P (F x) (G y)"
   shows "P (fix\<cdot>(Abs_cfun F)) (fix\<cdot>(Abs_cfun G))"
-by (rule parallel_fix_ind, simp_all add: assms)
+  by (rule parallel_fix_ind) (simp_all add: assms)
+
 
 subsection \<open>Fixed-points on product types\<close>
 
@@ -215,27 +213,35 @@
     \<mu> y. snd (F\<cdot>(\<mu> x. fst (F\<cdot>(x, \<mu> y. snd (F\<cdot>(x, y)))), y)))"
   (is "fix\<cdot>F = (?x, ?y)")
 proof (rule fix_eqI)
-  have 1: "fst (F\<cdot>(?x, ?y)) = ?x"
+  have *: "fst (F\<cdot>(?x, ?y)) = ?x"
     by (rule trans [symmetric, OF fix_eq], simp)
-  have 2: "snd (F\<cdot>(?x, ?y)) = ?y"
+  have "snd (F\<cdot>(?x, ?y)) = ?y"
     by (rule trans [symmetric, OF fix_eq], simp)
-  from 1 2 show "F\<cdot>(?x, ?y) = (?x, ?y)" by (simp add: prod_eq_iff)
+  with * show "F\<cdot>(?x, ?y) = (?x, ?y)"
+    by (simp add: prod_eq_iff)
 next
-  fix z assume F_z: "F\<cdot>z = z"
-  obtain x y where z: "z = (x,y)" by (rule prod.exhaust)
+  fix z
+  assume F_z: "F\<cdot>z = z"
+  obtain x y where z: "z = (x, y)" by (rule prod.exhaust)
   from F_z z have F_x: "fst (F\<cdot>(x, y)) = x" by simp
   from F_z z have F_y: "snd (F\<cdot>(x, y)) = y" by simp
   let ?y1 = "\<mu> y. snd (F\<cdot>(x, y))"
-  have "?y1 \<sqsubseteq> y" by (rule fix_least, simp add: F_y)
-  hence "fst (F\<cdot>(x, ?y1)) \<sqsubseteq> fst (F\<cdot>(x, y))"
+  have "?y1 \<sqsubseteq> y"
+    by (rule fix_least) (simp add: F_y)
+  then have "fst (F\<cdot>(x, ?y1)) \<sqsubseteq> fst (F\<cdot>(x, y))"
     by (simp add: fst_monofun monofun_cfun)
-  hence "fst (F\<cdot>(x, ?y1)) \<sqsubseteq> x" using F_x by simp
-  hence 1: "?x \<sqsubseteq> x" by (simp add: fix_least_below)
-  hence "snd (F\<cdot>(?x, y)) \<sqsubseteq> snd (F\<cdot>(x, y))"
+  with F_x have "fst (F\<cdot>(x, ?y1)) \<sqsubseteq> x"
+    by simp
+  then have *: "?x \<sqsubseteq> x"
+    by (simp add: fix_least_below)
+  then have "snd (F\<cdot>(?x, y)) \<sqsubseteq> snd (F\<cdot>(x, y))"
     by (simp add: snd_monofun monofun_cfun)
-  hence "snd (F\<cdot>(?x, y)) \<sqsubseteq> y" using F_y by simp
-  hence 2: "?y \<sqsubseteq> y" by (simp add: fix_least_below)
-  show "(?x, ?y) \<sqsubseteq> z" using z 1 2 by simp
+  with F_y have "snd (F\<cdot>(?x, y)) \<sqsubseteq> y"
+    by simp
+  then have "?y \<sqsubseteq> y"
+    by (simp add: fix_least_below)
+  with z * show "(?x, ?y) \<sqsubseteq> z"
+    by simp
 qed
 
 end




