author wenzelm Wed, 10 Jun 2015 22:28:56 +0200 changeset 60423 5035a2af185b parent 60422 be7565a1115b child 60424 c96fff9dcdbc child 60425 a5c68d06cbf0
misc tuning;
```--- a/src/HOL/Library/Convex.thy	Wed Jun 10 21:49:02 2015 +0200
+++ b/src/HOL/Library/Convex.thy	Wed Jun 10 22:28:56 2015 +0200
@@ -3,13 +3,13 @@
Author:     Johannes Hoelzl, TU Muenchen
*)

-section {* Convexity in real vector spaces *}
+section \<open>Convexity in real vector spaces\<close>

theory Convex
imports Product_Vector
begin

-subsection {* Convexity. *}
+subsection \<open>Convexity\<close>

definition convex :: "'a::real_vector set \<Rightarrow> bool"
where "convex s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. \<forall>u\<ge>0. \<forall>v\<ge>0. u + v = 1 \<longrightarrow> u *\<^sub>R x + v *\<^sub>R y \<in> s)"
@@ -57,7 +57,7 @@
lemma convex_UNIV[intro,simp]: "convex UNIV"
unfolding convex_def by auto

-lemma convex_Inter: "(\<forall>s\<in>f. convex s) \<Longrightarrow> convex(\<Inter> f)"
+lemma convex_Inter: "(\<forall>s\<in>f. convex s) \<Longrightarrow> convex(\<Inter>f)"
unfolding convex_def by auto

lemma convex_Int: "convex s \<Longrightarrow> convex t \<Longrightarrow> convex (s \<inter> t)"
@@ -103,28 +103,45 @@
and "convex {a..b}" and "convex {a<..b}"
and "convex {a..<b}" and "convex {a<..<b}"
proof -
-  have "{a..} = {x. a \<le> inner 1 x}" by auto
-  then show 1: "convex {a..}" by (simp only: convex_halfspace_ge)
-  have "{..b} = {x. inner 1 x \<le> b}" by auto
-  then show 2: "convex {..b}" by (simp only: convex_halfspace_le)
-  have "{a<..} = {x. a < inner 1 x}" by auto
-  then show 3: "convex {a<..}" by (simp only: convex_halfspace_gt)
-  have "{..<b} = {x. inner 1 x < b}" by auto
-  then show 4: "convex {..<b}" by (simp only: convex_halfspace_lt)
-  have "{a..b} = {a..} \<inter> {..b}" by auto
-  then show "convex {a..b}" by (simp only: convex_Int 1 2)
-  have "{a<..b} = {a<..} \<inter> {..b}" by auto
-  then show "convex {a<..b}" by (simp only: convex_Int 3 2)
-  have "{a..<b} = {a..} \<inter> {..<b}" by auto
-  then show "convex {a..<b}" by (simp only: convex_Int 1 4)
-  have "{a<..<b} = {a<..} \<inter> {..<b}" by auto
-  then show "convex {a<..<b}" by (simp only: convex_Int 3 4)
+  have "{a..} = {x. a \<le> inner 1 x}"
+    by auto
+  then show 1: "convex {a..}"
+    by (simp only: convex_halfspace_ge)
+  have "{..b} = {x. inner 1 x \<le> b}"
+    by auto
+  then show 2: "convex {..b}"
+    by (simp only: convex_halfspace_le)
+  have "{a<..} = {x. a < inner 1 x}"
+    by auto
+  then show 3: "convex {a<..}"
+    by (simp only: convex_halfspace_gt)
+  have "{..<b} = {x. inner 1 x < b}"
+    by auto
+  then show 4: "convex {..<b}"
+    by (simp only: convex_halfspace_lt)
+  have "{a..b} = {a..} \<inter> {..b}"
+    by auto
+  then show "convex {a..b}"
+    by (simp only: convex_Int 1 2)
+  have "{a<..b} = {a<..} \<inter> {..b}"
+    by auto
+  then show "convex {a<..b}"
+    by (simp only: convex_Int 3 2)
+  have "{a..<b} = {a..} \<inter> {..<b}"
+    by auto
+  then show "convex {a..<b}"
+    by (simp only: convex_Int 1 4)
+  have "{a<..<b} = {a<..} \<inter> {..<b}"
+    by auto
+  then show "convex {a<..<b}"
+    by (simp only: convex_Int 3 4)
qed

lemma convex_Reals: "convex Reals"
by (simp add: convex_def scaleR_conv_of_real)
-
-subsection {* Explicit expressions for convexity in terms of arbitrary sums. *}
+
+
+subsection \<open>Explicit expressions for convexity in terms of arbitrary sums\<close>

lemma convex_setsum:
fixes C :: "'a::real_vector set"
@@ -151,27 +168,27 @@
have "a i *\<^sub>R y i + (\<Sum>j\<in>s. a j *\<^sub>R y j) \<in> C"
proof (cases)
assume z: "setsum a s = 0"
-    with `a i + setsum a s = 1` have "a i = 1"
+    with \<open>a i + setsum a s = 1\<close> have "a i = 1"
by simp
-    from setsum_nonneg_0 [OF `finite s` _ z] `\<forall>j\<in>s. 0 \<le> a j` have "\<forall>j\<in>s. a j = 0"
+    from setsum_nonneg_0 [OF \<open>finite s\<close> _ z] \<open>\<forall>j\<in>s. 0 \<le> a j\<close> have "\<forall>j\<in>s. a j = 0"
by simp
-    show ?thesis using `a i = 1` and `\<forall>j\<in>s. a j = 0` and `y i \<in> C`
+    show ?thesis using \<open>a i = 1\<close> and \<open>\<forall>j\<in>s. a j = 0\<close> and \<open>y i \<in> C\<close>
by simp
next
assume nz: "setsum a s \<noteq> 0"
-    with `0 \<le> setsum a s` have "0 < setsum a s"
+    with \<open>0 \<le> setsum a s\<close> have "0 < setsum a s"
by simp
then have "(\<Sum>j\<in>s. (a j / setsum a s) *\<^sub>R y j) \<in> C"
-      using `\<forall>j\<in>s. 0 \<le> a j` and `\<forall>j\<in>s. y j \<in> C`
+      using \<open>\<forall>j\<in>s. 0 \<le> a j\<close> and \<open>\<forall>j\<in>s. y j \<in> C\<close>
by (simp add: IH setsum_divide_distrib [symmetric])
-    from `convex C` and `y i \<in> C` and this and `0 \<le> a i`
-      and `0 \<le> setsum a s` and `a i + setsum a s = 1`
+    from \<open>convex C\<close> and \<open>y i \<in> C\<close> and this and \<open>0 \<le> a i\<close>
+      and \<open>0 \<le> setsum a s\<close> and \<open>a i + setsum a s = 1\<close>
have "a i *\<^sub>R y i + setsum a s *\<^sub>R (\<Sum>j\<in>s. (a j / setsum a s) *\<^sub>R y j) \<in> C"
by (rule convexD)
then show ?thesis
by (simp add: scaleR_setsum_right nz)
qed
-  then show ?case using `finite s` and `i \<notin> s`
+  then show ?case using \<open>finite s\<close> and \<open>i \<notin> s\<close>
by simp
qed

@@ -185,11 +202,10 @@
assume "convex s"
"\<forall>i. 1 \<le> i \<and> i \<le> k \<longrightarrow> 0 \<le> u i \<and> x i \<in> s"
"setsum u {1..k} = 1"
-  from this convex_setsum[of "{1 .. k}" s]
-  show "(\<Sum>j\<in>{1 .. k}. u j *\<^sub>R x j) \<in> s"
+  with convex_setsum[of "{1 .. k}" s] show "(\<Sum>j\<in>{1 .. k}. u j *\<^sub>R x j) \<in> s"
by auto
next
-  assume asm: "\<forall>k u x. (\<forall> i :: nat. 1 \<le> i \<and> i \<le> k \<longrightarrow> 0 \<le> u i \<and> x i \<in> s) \<and> setsum u {1..k} = 1
+  assume *: "\<forall>k u x. (\<forall> i :: nat. 1 \<le> i \<and> i \<le> k \<longrightarrow> 0 \<le> u i \<and> x i \<in> s) \<and> setsum u {1..k} = 1
\<longrightarrow> (\<Sum>i = 1..k. u i *\<^sub>R (x i :: 'a)) \<in> s"
{
fix \<mu> :: real
@@ -205,7 +221,7 @@
then have "setsum ?u {1 .. 2} = 1"
using setsum.If_cases[of "{(1 :: nat) .. 2}" "\<lambda> x. x = 1" "\<lambda> x. \<mu>" "\<lambda> x. 1 - \<mu>"]
by auto
-    with asm[rule_format, of "2" ?u ?x] have s: "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) \<in> s"
+    with *[rule_format, of "2" ?u ?x] have s: "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) \<in> s"
using mu xy by auto
have grarr: "(\<Sum>j \<in> {Suc (Suc 0)..2}. ?u j *\<^sub>R ?x j) = (1 - \<mu>) *\<^sub>R y"
using setsum_head_Suc[of "Suc (Suc 0)" 2 "\<lambda> j. (1 - \<mu>) *\<^sub>R y"] by auto
@@ -213,7 +229,7 @@
have "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) = \<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y"
by auto
then have "(1 - \<mu>) *\<^sub>R y + \<mu> *\<^sub>R x \<in> s"
-      using s by (auto simp:add.commute)
+      using s by (auto simp: add.commute)
}
then show "convex s"
unfolding convex_alt by auto
@@ -233,29 +249,26 @@
then show "(\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s"
using convex_setsum[of t s u "\<lambda> x. x"] by auto
next
-  assume asm0: "\<forall>t. \<forall> u. finite t \<and> t \<subseteq> s \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and>
+  assume *: "\<forall>t. \<forall> u. finite t \<and> t \<subseteq> s \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and>
setsum u t = 1 \<longrightarrow> (\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s"
show "convex s"
unfolding convex_alt
proof safe
fix x y
fix \<mu> :: real
-    assume asm: "x \<in> s" "y \<in> s" "0 \<le> \<mu>" "\<mu> \<le> 1"
-    {
-      assume "x \<noteq> y"
-      then have "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
-        using asm0[rule_format, of "{x, y}" "\<lambda> z. if z = x then 1 - \<mu> else \<mu>"]
-          asm by auto
-    }
-    moreover
-    {
-      assume "x = y"
-      then have "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
-        using asm0[rule_format, of "{x, y}" "\<lambda> z. 1"]
-          asm by (auto simp: field_simps real_vector.scale_left_diff_distrib)
-    }
-    ultimately show "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
-      by blast
+    assume **: "x \<in> s" "y \<in> s" "0 \<le> \<mu>" "\<mu> \<le> 1"
+    show "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
+    proof (cases "x = y")
+      case False
+      then show ?thesis
+        using *[rule_format, of "{x, y}" "\<lambda> z. if z = x then 1 - \<mu> else \<mu>"] **
+          by auto
+    next
+      case True
+      then show ?thesis
+        using *[rule_format, of "{x, y}" "\<lambda> z. 1"] **
+          by (auto simp: field_simps real_vector.scale_left_diff_distrib)
+    qed
qed
qed

@@ -277,7 +290,7 @@
qed (erule_tac x=s in allE, erule_tac x=u in allE, auto)

-subsection {* Functions that are convex on a set *}
+subsection \<open>Functions that are convex on a set\<close>

definition convex_on :: "'a::real_vector set \<Rightarrow> ('a \<Rightarrow> real) \<Rightarrow> bool"
where "convex_on s f \<longleftrightarrow>
@@ -299,7 +312,7 @@
assume "0 \<le> u" "0 \<le> v" "u + v = 1"
ultimately
have "f (u *\<^sub>R x + v *\<^sub>R y) + g (u *\<^sub>R x + v *\<^sub>R y) \<le> (u * f x + v * f y) + (u * g x + v * g y)"
-      using assms unfolding convex_on_def by (auto simp add: add_mono)
+      using assms unfolding convex_on_def by (auto simp: add_mono)
then have "f (u *\<^sub>R x + v *\<^sub>R y) + g (u *\<^sub>R x + v *\<^sub>R y) \<le> u * (f x + g x) + v * (f y + g y)"
by (simp add: field_simps)
}
@@ -313,7 +326,7 @@
and "convex_on s f"
shows "convex_on s (\<lambda>x. c * f x)"
proof -
-  have *: "\<And>u c fx v fy ::real. u * (c * fx) + v * (c * fy) = c * (u * fx + v * fy)"
+  have *: "\<And>u c fx v fy :: real. u * (c * fx) + v * (c * fy) = c * (u * fx + v * fy)"
by (simp add: field_simps)
show ?thesis using assms(2) and mult_left_mono [OF _ assms(1)]
unfolding convex_on_def and * by auto
@@ -330,9 +343,9 @@
proof -
let ?m = "max (f x) (f y)"
have "u * f x + v * f y \<le> u * max (f x) (f y) + v * max (f x) (f y)"
-    using assms(4,5) by (auto simp add: mult_left_mono add_mono)
+    using assms(4,5) by (auto simp: mult_left_mono add_mono)
also have "\<dots> = max (f x) (f y)"
-    using assms(6) by (simp add: distrib_right [symmetric])
+    using assms(6) by (simp add: distrib_right [symmetric])
finally show ?thesis
using assms unfolding convex_on_def by fastforce
qed
@@ -340,7 +353,7 @@
lemma convex_on_dist [intro]:
fixes s :: "'a::real_normed_vector set"
shows "convex_on s (\<lambda>x. dist a x)"
-proof (auto simp add: convex_on_def dist_norm)
+proof (auto simp: convex_on_def dist_norm)
fix x y
assume "x \<in> s" "y \<in> s"
fix u v :: real
@@ -348,16 +361,16 @@
assume "0 \<le> v"
assume "u + v = 1"
have "a = u *\<^sub>R a + v *\<^sub>R a"
-    unfolding scaleR_left_distrib[symmetric] and `u + v = 1` by simp
+    unfolding scaleR_left_distrib[symmetric] and \<open>u + v = 1\<close> by simp
then have *: "a - (u *\<^sub>R x + v *\<^sub>R y) = (u *\<^sub>R (a - x)) + (v *\<^sub>R (a - y))"
-    by (auto simp add: algebra_simps)
+    by (auto simp: algebra_simps)
show "norm (a - (u *\<^sub>R x + v *\<^sub>R y)) \<le> u * norm (a - x) + v * norm (a - y)"
unfolding * using norm_triangle_ineq[of "u *\<^sub>R (a - x)" "v *\<^sub>R (a - y)"]
-    using `0 \<le> u` `0 \<le> v` by auto
+    using \<open>0 \<le> u\<close> \<open>0 \<le> v\<close> by auto
qed

-subsection {* Arithmetic operations on sets preserve convexity. *}
+subsection \<open>Arithmetic operations on sets preserve convexity\<close>

lemma convex_linear_image:
assumes "linear f"
@@ -365,7 +378,7 @@
shows "convex (f ` s)"
proof -
interpret f: linear f by fact
-  from `convex s` show "convex (f ` s)"
+  from \<open>convex s\<close> show "convex (f ` s)"
by (simp add: convex_def f.scaleR [symmetric] f.add [symmetric])
qed

@@ -375,7 +388,7 @@
shows "convex (f -` s)"
proof -
interpret f: linear f by fact
-  from `convex s` show "convex (f -` s)"
+  from \<open>convex s\<close> show "convex (f -` s)"
by (simp add: convex_def f.add f.scaleR)
qed

@@ -386,7 +399,7 @@
have "linear (\<lambda>x. c *\<^sub>R x)"
by (simp add: linearI scaleR_add_right)
then show ?thesis
-    using `convex s` by (rule convex_linear_image)
+    using \<open>convex s\<close> by (rule convex_linear_image)
qed

lemma convex_scaled:
@@ -396,7 +409,7 @@
have "linear (\<lambda>x. x *\<^sub>R c)"
by (simp add: linearI scaleR_add_left)
then show ?thesis
-    using `convex s` by (rule convex_linear_image)
+    using \<open>convex s\<close> by (rule convex_linear_image)
qed

lemma convex_negations:
@@ -406,7 +419,7 @@
have "linear (\<lambda>x. - x)"
by (simp add: linearI)
then show ?thesis
-    using `convex s` by (rule convex_linear_image)
+    using \<open>convex s\<close> by (rule convex_linear_image)
qed

lemma convex_sums:
@@ -415,7 +428,7 @@
shows "convex {x + y| x y. x \<in> s \<and> y \<in> t}"
proof -
have "linear (\<lambda>(x, y). x + y)"
-    by (auto intro: linearI simp add: scaleR_add_right)
+    by (auto intro: linearI simp: scaleR_add_right)
with assms have "convex ((\<lambda>(x, y). x + y) ` (s \<times> t))"
by (intro convex_linear_image convex_Times)
also have "((\<lambda>(x, y). x + y) ` (s \<times> t)) = {x + y| x y. x \<in> s \<and> y \<in> t}"
@@ -428,7 +441,7 @@
shows "convex {x - y| x y. x \<in> s \<and> y \<in> t}"
proof -
have "{x - y| x y. x \<in> s \<and> y \<in> t} = {x + y |x y. x \<in> s \<and> y \<in> uminus ` t}"
-    by (auto simp add: diff_conv_add_uminus simp del: add_uminus_conv_diff)
+    by (auto simp: diff_conv_add_uminus simp del: add_uminus_conv_diff)
then show ?thesis
using convex_sums[OF assms(1) convex_negations[OF assms(2)]] by auto
qed
@@ -457,23 +470,23 @@
unfolding convex_alt
proof safe
fix y x \<mu> :: real
-  assume asms: "y > 0" "x > 0" "\<mu> \<ge> 0" "\<mu> \<le> 1"
+  assume *: "y > 0" "x > 0" "\<mu> \<ge> 0" "\<mu> \<le> 1"
{
assume "\<mu> = 0"
then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y = y" by simp
-    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using asms by simp
+    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using * by simp
}
moreover
{
assume "\<mu> = 1"
-    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using asms by simp
+    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using * by simp
}
moreover
{
assume "\<mu> \<noteq> 1" "\<mu> \<noteq> 0"
-    then have "\<mu> > 0" "(1 - \<mu>) > 0" using asms by auto
-    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using asms
-      by (auto simp add: add_pos_pos)
+    then have "\<mu> > 0" "(1 - \<mu>) > 0" using * by auto
+    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using *
+      by (auto simp: add_pos_pos)
}
ultimately show "(1 - \<mu>) *\<^sub>R y + \<mu> *\<^sub>R x > 0"
using assms by fastforce
@@ -496,70 +509,75 @@
then have ai: "a i = 1" by auto
then show ?case by auto
next
-  case (insert i s) note asms = this
+  case (insert i s)
then have "convex_on C f" by simp
from this[unfolded convex_on_def, rule_format]
have conv: "\<And>x y \<mu>. x \<in> C \<Longrightarrow> y \<in> C \<Longrightarrow> 0 \<le> \<mu> \<Longrightarrow> \<mu> \<le> 1 \<Longrightarrow>
f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
by simp
-  {
-    assume "a i = 1"
+  show ?case
+  proof (cases "a i = 1")
+    case True
then have "(\<Sum> j \<in> s. a j) = 0"
-      using asms by auto
+      using insert by auto
then have "\<And>j. j \<in> s \<Longrightarrow> a j = 0"
-      using setsum_nonneg_0[where 'b=real] asms by fastforce
-    then have ?case using asms by auto
-  }
-  moreover
-  {
-    assume asm: "a i \<noteq> 1"
-    from asms have yai: "y i \<in> C" "a i \<ge> 0" by auto
-    have fis: "finite (insert i s)" using asms by auto
-    then have ai1: "a i \<le> 1" using setsum_nonneg_leq_bound[of "insert i s" a] asms by simp
-    then have "a i < 1" using asm by auto
-    then have i0: "1 - a i > 0" by auto
+      using setsum_nonneg_0[where 'b=real] insert by fastforce
+    then show ?thesis
+      using insert by auto
+  next
+    case False
+    from insert have yai: "y i \<in> C" "a i \<ge> 0"
+      by auto
+    have fis: "finite (insert i s)"
+      using insert by auto
+    then have ai1: "a i \<le> 1"
+      using setsum_nonneg_leq_bound[of "insert i s" a] insert by simp
+    then have "a i < 1"
+      using False by auto
+    then have i0: "1 - a i > 0"
+      by auto
let ?a = "\<lambda>j. a j / (1 - a i)"
-    {
-      fix j
-      assume "j \<in> s"
-      with i0 asms have "?a j \<ge> 0"
-        by fastforce
-    }
-    note a_nonneg = this
-    have "(\<Sum> j \<in> insert i s. a j) = 1" using asms by auto
-    then have "(\<Sum> j \<in> s. a j) = 1 - a i" using setsum.insert asms by fastforce
-    then have "(\<Sum> j \<in> s. a j) / (1 - a i) = 1" using i0 by auto
-    then have a1: "(\<Sum> j \<in> s. ?a j) = 1" unfolding setsum_divide_distrib by simp
-    have "convex C" using asms by auto
+    have a_nonneg: "?a j \<ge> 0" if "j \<in> s" for j
+      using i0 insert prems by fastforce
+    have "(\<Sum> j \<in> insert i s. a j) = 1"
+      using insert by auto
+    then have "(\<Sum> j \<in> s. a j) = 1 - a i"
+      using setsum.insert insert by fastforce
+    then have "(\<Sum> j \<in> s. a j) / (1 - a i) = 1"
+      using i0 by auto
+    then have a1: "(\<Sum> j \<in> s. ?a j) = 1"
+      unfolding setsum_divide_distrib by simp
+    have "convex C" using insert by auto
then have asum: "(\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<in> C"
-      using asms convex_setsum[OF `finite s`
-        `convex C` a1 a_nonneg] by auto
+      using insert convex_setsum[OF \<open>finite s\<close>
+        \<open>convex C\<close> a1 a_nonneg] by auto
have asum_le: "f (\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<le> (\<Sum> j \<in> s. ?a j * f (y j))"
-      using a_nonneg a1 asms by blast
+      using a_nonneg a1 insert by blast
have "f (\<Sum> j \<in> insert i s. a j *\<^sub>R y j) = f ((\<Sum> j \<in> s. a j *\<^sub>R y j) + a i *\<^sub>R y i)"
-      using setsum.insert[of s i "\<lambda> j. a j *\<^sub>R y j", OF `finite s` `i \<notin> s`] asms
-      by (auto simp only:add.commute)
+      using setsum.insert[of s i "\<lambda> j. a j *\<^sub>R y j", OF \<open>finite s\<close> \<open>i \<notin> s\<close>] insert
+      by (auto simp only: add.commute)
also have "\<dots> = f (((1 - a i) * inverse (1 - a i)) *\<^sub>R (\<Sum> j \<in> s. a j *\<^sub>R y j) + a i *\<^sub>R y i)"
using i0 by auto
also have "\<dots> = f ((1 - a i) *\<^sub>R (\<Sum> j \<in> s. (a j * inverse (1 - a i)) *\<^sub>R y j) + a i *\<^sub>R y i)"
using scaleR_right.setsum[of "inverse (1 - a i)" "\<lambda> j. a j *\<^sub>R y j" s, symmetric]
-      by (auto simp:algebra_simps)
+      by (auto simp: algebra_simps)
also have "\<dots> = f ((1 - a i) *\<^sub>R (\<Sum> j \<in> s. ?a j *\<^sub>R y j) + a i *\<^sub>R y i)"
by (auto simp: divide_inverse)
also have "\<dots> \<le> (1 - a i) *\<^sub>R f ((\<Sum> j \<in> s. ?a j *\<^sub>R y j)) + a i * f (y i)"
using conv[of "y i" "(\<Sum> j \<in> s. ?a j *\<^sub>R y j)" "a i", OF yai(1) asum yai(2) ai1]
-      by (auto simp add:add.commute)
+      by (auto simp: add.commute)
also have "\<dots> \<le> (1 - a i) * (\<Sum> j \<in> s. ?a j * f (y j)) + a i * f (y i)"
using add_right_mono[OF mult_left_mono[of _ _ "1 - a i",
OF asum_le less_imp_le[OF i0]], of "a i * f (y i)"] by simp
also have "\<dots> = (\<Sum> j \<in> s. (1 - a i) * ?a j * f (y j)) + a i * f (y i)"
unfolding setsum_right_distrib[of "1 - a i" "\<lambda> j. ?a j * f (y j)"] using i0 by auto
-    also have "\<dots> = (\<Sum> j \<in> s. a j * f (y j)) + a i * f (y i)" using i0 by auto
-    also have "\<dots> = (\<Sum> j \<in> insert i s. a j * f (y j))" using asms by auto
-    finally have "f (\<Sum> j \<in> insert i s. a j *\<^sub>R y j) \<le> (\<Sum> j \<in> insert i s. a j * f (y j))"
+    also have "\<dots> = (\<Sum> j \<in> s. a j * f (y j)) + a i * f (y i)"
+      using i0 by auto
+    also have "\<dots> = (\<Sum> j \<in> insert i s. a j * f (y j))"
+      using insert by auto
+    finally show ?thesis
by simp
-  }
-  ultimately show ?case by auto
+  qed
qed

lemma convex_on_alt:
@@ -571,24 +589,24 @@
proof safe
fix x y
fix \<mu> :: real
-  assume asms: "convex_on C f" "x \<in> C" "y \<in> C" "0 \<le> \<mu>" "\<mu> \<le> 1"
+  assume *: "convex_on C f" "x \<in> C" "y \<in> C" "0 \<le> \<mu>" "\<mu> \<le> 1"
from this[unfolded convex_on_def, rule_format]
have "\<And>u v. 0 \<le> u \<Longrightarrow> 0 \<le> v \<Longrightarrow> u + v = 1 \<Longrightarrow> f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y"
by auto
-  from this[of "\<mu>" "1 - \<mu>", simplified] asms
+  from this[of "\<mu>" "1 - \<mu>", simplified] *
show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
by auto
next
-  assume asm: "\<forall>x\<in>C. \<forall>y\<in>C. \<forall>\<mu>. 0 \<le> \<mu> \<and> \<mu> \<le> 1 \<longrightarrow>
+  assume *: "\<forall>x\<in>C. \<forall>y\<in>C. \<forall>\<mu>. 0 \<le> \<mu> \<and> \<mu> \<le> 1 \<longrightarrow>
f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
{
fix x y
fix u v :: real
-    assume lasm: "x \<in> C" "y \<in> C" "u \<ge> 0" "v \<ge> 0" "u + v = 1"
+    assume **: "x \<in> C" "y \<in> C" "u \<ge> 0" "v \<ge> 0" "u + v = 1"
then have[simp]: "1 - u = v" by auto
-    from asm[rule_format, of x y u]
+    from *[rule_format, of x y u]
have "f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y"
-      using lasm by auto
+      using ** by auto
}
then show "convex_on C f"
unfolding convex_on_def by auto
@@ -605,12 +623,12 @@
def a \<equiv> "(t - y) / (x - y)"
with t have "0 \<le> a" "0 \<le> 1 - a"
by (auto simp: field_simps)
-  with f `x \<in> I` `y \<in> I` have cvx: "f (a * x + (1 - a) * y) \<le> a * f x + (1 - a) * f y"
+  with f \<open>x \<in> I\<close> \<open>y \<in> I\<close> have cvx: "f (a * x + (1 - a) * y) \<le> a * f x + (1 - a) * f y"
by (auto simp: convex_on_def)
have "a * x + (1 - a) * y = a * (x - y) + y"
by (simp add: field_simps)
also have "\<dots> = t"
-    unfolding a_def using `x < t` `t < y` by simp
+    unfolding a_def using \<open>x < t\<close> \<open>t < y\<close> by simp
finally have "f t \<le> a * f x + (1 - a) * f y"
using cvx by simp
also have "\<dots> = a * (f x - f y) + f y"
@@ -633,17 +651,17 @@
proof safe
fix x y \<mu> :: real
let ?x = "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y"
-  assume asm: "convex C" "x \<in> C" "y \<in> C" "\<mu> \<ge> 0" "\<mu> \<le> 1"
+  assume *: "convex C" "x \<in> C" "y \<in> C" "\<mu> \<ge> 0" "\<mu> \<le> 1"
then have "1 - \<mu> \<ge> 0" by auto
then have xpos: "?x \<in> C"
-    using asm unfolding convex_alt by fastforce
+    using * unfolding convex_alt by fastforce
have geq: "\<mu> * (f x - f ?x) + (1 - \<mu>) * (f y - f ?x) \<ge>
\<mu> * f' ?x * (x - ?x) + (1 - \<mu>) * f' ?x * (y - ?x)"
-    using add_mono[OF mult_left_mono[OF leq[OF xpos asm(2)] `\<mu> \<ge> 0`]
-      mult_left_mono[OF leq[OF xpos asm(3)] `1 - \<mu> \<ge> 0`]]
+    using add_mono[OF mult_left_mono[OF leq[OF xpos *(2)] \<open>\<mu> \<ge> 0\<close>]
+      mult_left_mono[OF leq[OF xpos *(3)] \<open>1 - \<mu> \<ge> 0\<close>]]
by auto
then have "\<mu> * f x + (1 - \<mu>) * f y - f ?x \<ge> 0"
-    by (auto simp add: field_simps)
+    by (auto simp: field_simps)
then show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
using convex_on_alt by auto
qed
@@ -654,26 +672,25 @@
and "x \<in> C" "y \<in> C" "x < y"
shows "{x .. y} \<subseteq> C"
proof safe
-  fix z assume zasm: "z \<in> {x .. y}"
-  {
-    assume asm: "x < z" "z < y"
+  fix z assume z: "z \<in> {x .. y}"
+  have less: "z \<in> C" if *: "x < z" "z < y"
+  proof -
let ?\<mu> = "(y - z) / (y - x)"
have "0 \<le> ?\<mu>" "?\<mu> \<le> 1"
-      using assms asm by (auto simp add: field_simps)
+      using assms * by (auto simp: field_simps)
then have comb: "?\<mu> * x + (1 - ?\<mu>) * y \<in> C"
using assms iffD1[OF convex_alt, rule_format, of C y x ?\<mu>]
by (simp add: algebra_simps)
have "?\<mu> * x + (1 - ?\<mu>) * y = (y - z) * x / (y - x) + (1 - (y - z) / (y - x)) * y"
-      by (auto simp add: field_simps)
+      by (auto simp: field_simps)
also have "\<dots> = ((y - z) * x + (y - x - (y - z)) * y) / (y - x)"
using assms unfolding add_divide_distrib by (auto simp: field_simps)
also have "\<dots> = z"
using assms by (auto simp: field_simps)
-    finally have "z \<in> C"
+    finally show ?thesis
using comb by auto
-  }
-  note less = this
-  show "z \<in> C" using zasm less assms
+  qed
+  show "z \<in> C" using z less assms
unfolding atLeastAtMost_iff le_less by auto
qed

@@ -689,56 +706,77 @@
proof -
{
fix x y :: real
-    assume asm: "x \<in> C" "y \<in> C" "y > x"
-    then have ge: "y - x > 0" "y - x \<ge> 0" by auto
-    from asm have le: "x - y < 0" "x - y \<le> 0" by auto
+    assume *: "x \<in> C" "y \<in> C" "y > x"
+    then have ge: "y - x > 0" "y - x \<ge> 0"
+      by auto
+    from * have le: "x - y < 0" "x - y \<le> 0"
+      by auto
then obtain z1 where z1: "z1 > x" "z1 < y" "f y - f x = (y - x) * f' z1"
-      using subsetD[OF atMostAtLeast_subset_convex[OF `convex C` `x \<in> C` `y \<in> C` `x < y`],
-        THEN f', THEN MVT2[OF `x < y`, rule_format, unfolded atLeastAtMost_iff[symmetric]]]
+      using subsetD[OF atMostAtLeast_subset_convex[OF \<open>convex C\<close> \<open>x \<in> C\<close> \<open>y \<in> C\<close> \<open>x < y\<close>],
+        THEN f', THEN MVT2[OF \<open>x < y\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]]
by auto
-    then have "z1 \<in> C" using atMostAtLeast_subset_convex
-      `convex C` `x \<in> C` `y \<in> C` `x < y` by fastforce
+    then have "z1 \<in> C"
+      using atMostAtLeast_subset_convex \<open>convex C\<close> \<open>x \<in> C\<close> \<open>y \<in> C\<close> \<open>x < y\<close>
+      by fastforce
from z1 have z1': "f x - f y = (x - y) * f' z1"
-      by (simp add:field_simps)
+      by (simp add: field_simps)
obtain z2 where z2: "z2 > x" "z2 < z1" "f' z1 - f' x = (z1 - x) * f'' z2"
-      using subsetD[OF atMostAtLeast_subset_convex[OF `convex C` `x \<in> C` `z1 \<in> C` `x < z1`],
-        THEN f'', THEN MVT2[OF `x < z1`, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
+      using subsetD[OF atMostAtLeast_subset_convex[OF \<open>convex C\<close> \<open>x \<in> C\<close> \<open>z1 \<in> C\<close> \<open>x < z1\<close>],
+        THEN f'', THEN MVT2[OF \<open>x < z1\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
by auto
obtain z3 where z3: "z3 > z1" "z3 < y" "f' y - f' z1 = (y - z1) * f'' z3"
-      using subsetD[OF atMostAtLeast_subset_convex[OF `convex C` `z1 \<in> C` `y \<in> C` `z1 < y`],
-        THEN f'', THEN MVT2[OF `z1 < y`, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
+      using subsetD[OF atMostAtLeast_subset_convex[OF \<open>convex C\<close> \<open>z1 \<in> C\<close> \<open>y \<in> C\<close> \<open>z1 < y\<close>],
+        THEN f'', THEN MVT2[OF \<open>z1 < y\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
by auto
have "f' y - (f x - f y) / (x - y) = f' y - f' z1"
-      using asm z1' by auto
-    also have "\<dots> = (y - z1) * f'' z3" using z3 by auto
-    finally have cool': "f' y - (f x - f y) / (x - y) = (y - z1) * f'' z3" by simp
-    have A': "y - z1 \<ge> 0" using z1 by auto
-    have "z3 \<in> C" using z3 asm atMostAtLeast_subset_convex
-      `convex C` `x \<in> C` `z1 \<in> C` `x < z1` by fastforce
-    then have B': "f'' z3 \<ge> 0" using assms by auto
-    from A' B' have "(y - z1) * f'' z3 \<ge> 0" by auto
-    from cool' this have "f' y - (f x - f y) / (x - y) \<ge> 0" by auto
+      using * z1' by auto
+    also have "\<dots> = (y - z1) * f'' z3"
+      using z3 by auto
+    finally have cool': "f' y - (f x - f y) / (x - y) = (y - z1) * f'' z3"
+      by simp
+    have A': "y - z1 \<ge> 0"
+      using z1 by auto
+    have "z3 \<in> C"
+      using z3 * atMostAtLeast_subset_convex \<open>convex C\<close> \<open>x \<in> C\<close> \<open>z1 \<in> C\<close> \<open>x < z1\<close>
+      by fastforce
+    then have B': "f'' z3 \<ge> 0"
+      using assms by auto
+    from A' B' have "(y - z1) * f'' z3 \<ge> 0"
+      by auto
+    from cool' this have "f' y - (f x - f y) / (x - y) \<ge> 0"
+      by auto
from mult_right_mono_neg[OF this le(2)]
have "f' y * (x - y) - (f x - f y) / (x - y) * (x - y) \<le> 0 * (x - y)"
by (simp add: algebra_simps)
-    then have "f' y * (x - y) - (f x - f y) \<le> 0" using le by auto
-    then have res: "f' y * (x - y) \<le> f x - f y" by auto
+    then have "f' y * (x - y) - (f x - f y) \<le> 0"
+      using le by auto
+    then have res: "f' y * (x - y) \<le> f x - f y"
+      by auto
have "(f y - f x) / (y - x) - f' x = f' z1 - f' x"
-      using asm z1 by auto
-    also have "\<dots> = (z1 - x) * f'' z2" using z2 by auto
-    finally have cool: "(f y - f x) / (y - x) - f' x = (z1 - x) * f'' z2" by simp
-    have A: "z1 - x \<ge> 0" using z1 by auto
-    have "z2 \<in> C" using z2 z1 asm atMostAtLeast_subset_convex
-      `convex C` `z1 \<in> C` `y \<in> C` `z1 < y` by fastforce
-    then have B: "f'' z2 \<ge> 0" using assms by auto
-    from A B have "(z1 - x) * f'' z2 \<ge> 0" by auto
-    from cool this have "(f y - f x) / (y - x) - f' x \<ge> 0" by auto
+      using * z1 by auto
+    also have "\<dots> = (z1 - x) * f'' z2"
+      using z2 by auto
+    finally have cool: "(f y - f x) / (y - x) - f' x = (z1 - x) * f'' z2"
+      by simp
+    have A: "z1 - x \<ge> 0"
+      using z1 by auto
+    have "z2 \<in> C"
+      using z2 z1 * atMostAtLeast_subset_convex \<open>convex C\<close> \<open>z1 \<in> C\<close> \<open>y \<in> C\<close> \<open>z1 < y\<close>
+      by fastforce
+    then have B: "f'' z2 \<ge> 0"
+      using assms by auto
+    from A B have "(z1 - x) * f'' z2 \<ge> 0"
+      by auto
+    with cool have "(f y - f x) / (y - x) - f' x \<ge> 0"
+      by auto
from mult_right_mono[OF this ge(2)]
have "(f y - f x) / (y - x) * (y - x) - f' x * (y - x) \<ge> 0 * (y - x)"
by (simp add: algebra_simps)
-    then have "f y - f x - f' x * (y - x) \<ge> 0" using ge by auto
+    then have "f y - f x - f' x * (y - x) \<ge> 0"
+      using ge by auto
then have "f y - f x \<ge> f' x * (y - x)" "f' y * (x - y) \<le> f x - f y"
-      using res by auto } note less_imp = this
+      using res by auto
+  } note less_imp = this
{
fix x y :: real
assume "x \<in> C" "y \<in> C" "x \<noteq> y"
@@ -748,7 +786,7 @@
moreover
{
fix x y :: real
-    assume asm: "x \<in> C" "y \<in> C" "x = y"
+    assume "x \<in> C" "y \<in> C" "x = y"
then have "f y - f x \<ge> f' x * (y - x)" by auto
}
ultimately show ?thesis using assms by blast
@@ -781,9 +819,9 @@
by auto
then have f''0: "\<And>z::real. z > 0 \<Longrightarrow>
DERIV (\<lambda> z. - 1 / (ln b * z)) z :> 1 / (ln b * z * z)"
-    unfolding inverse_eq_divide by (auto simp add: mult.assoc)
+    unfolding inverse_eq_divide by (auto simp: mult.assoc)
have f''_ge0: "\<And>z::real. z > 0 \<Longrightarrow> 1 / (ln b * z * z) \<ge> 0"
-    using `b > 1` by (auto intro!:less_imp_le)
+    using \<open>b > 1\<close> by (auto intro!: less_imp_le)
from f''_ge0_imp_convex[OF pos_is_convex,
unfolded greaterThan_iff, OF f' f''0 f''_ge0]
show ?thesis by auto```