author wenzelm Wed Jun 10 22:28:56 2015 +0200 (2015-06-10) changeset 60423 5035a2af185b parent 60422 be7565a1115b child 60424 c96fff9dcdbc child 60425 a5c68d06cbf0
misc tuning;
```     1.1 --- a/src/HOL/Library/Convex.thy	Wed Jun 10 21:49:02 2015 +0200
1.2 +++ b/src/HOL/Library/Convex.thy	Wed Jun 10 22:28:56 2015 +0200
1.3 @@ -3,13 +3,13 @@
1.4      Author:     Johannes Hoelzl, TU Muenchen
1.5  *)
1.6
1.7 -section {* Convexity in real vector spaces *}
1.8 +section \<open>Convexity in real vector spaces\<close>
1.9
1.10  theory Convex
1.11  imports Product_Vector
1.12  begin
1.13
1.14 -subsection {* Convexity. *}
1.15 +subsection \<open>Convexity\<close>
1.16
1.17  definition convex :: "'a::real_vector set \<Rightarrow> bool"
1.18    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)"
1.19 @@ -57,7 +57,7 @@
1.20  lemma convex_UNIV[intro,simp]: "convex UNIV"
1.21    unfolding convex_def by auto
1.22
1.23 -lemma convex_Inter: "(\<forall>s\<in>f. convex s) \<Longrightarrow> convex(\<Inter> f)"
1.24 +lemma convex_Inter: "(\<forall>s\<in>f. convex s) \<Longrightarrow> convex(\<Inter>f)"
1.25    unfolding convex_def by auto
1.26
1.27  lemma convex_Int: "convex s \<Longrightarrow> convex t \<Longrightarrow> convex (s \<inter> t)"
1.28 @@ -103,28 +103,45 @@
1.29      and "convex {a..b}" and "convex {a<..b}"
1.30      and "convex {a..<b}" and "convex {a<..<b}"
1.31  proof -
1.32 -  have "{a..} = {x. a \<le> inner 1 x}" by auto
1.33 -  then show 1: "convex {a..}" by (simp only: convex_halfspace_ge)
1.34 -  have "{..b} = {x. inner 1 x \<le> b}" by auto
1.35 -  then show 2: "convex {..b}" by (simp only: convex_halfspace_le)
1.36 -  have "{a<..} = {x. a < inner 1 x}" by auto
1.37 -  then show 3: "convex {a<..}" by (simp only: convex_halfspace_gt)
1.38 -  have "{..<b} = {x. inner 1 x < b}" by auto
1.39 -  then show 4: "convex {..<b}" by (simp only: convex_halfspace_lt)
1.40 -  have "{a..b} = {a..} \<inter> {..b}" by auto
1.41 -  then show "convex {a..b}" by (simp only: convex_Int 1 2)
1.42 -  have "{a<..b} = {a<..} \<inter> {..b}" by auto
1.43 -  then show "convex {a<..b}" by (simp only: convex_Int 3 2)
1.44 -  have "{a..<b} = {a..} \<inter> {..<b}" by auto
1.45 -  then show "convex {a..<b}" by (simp only: convex_Int 1 4)
1.46 -  have "{a<..<b} = {a<..} \<inter> {..<b}" by auto
1.47 -  then show "convex {a<..<b}" by (simp only: convex_Int 3 4)
1.48 +  have "{a..} = {x. a \<le> inner 1 x}"
1.49 +    by auto
1.50 +  then show 1: "convex {a..}"
1.51 +    by (simp only: convex_halfspace_ge)
1.52 +  have "{..b} = {x. inner 1 x \<le> b}"
1.53 +    by auto
1.54 +  then show 2: "convex {..b}"
1.55 +    by (simp only: convex_halfspace_le)
1.56 +  have "{a<..} = {x. a < inner 1 x}"
1.57 +    by auto
1.58 +  then show 3: "convex {a<..}"
1.59 +    by (simp only: convex_halfspace_gt)
1.60 +  have "{..<b} = {x. inner 1 x < b}"
1.61 +    by auto
1.62 +  then show 4: "convex {..<b}"
1.63 +    by (simp only: convex_halfspace_lt)
1.64 +  have "{a..b} = {a..} \<inter> {..b}"
1.65 +    by auto
1.66 +  then show "convex {a..b}"
1.67 +    by (simp only: convex_Int 1 2)
1.68 +  have "{a<..b} = {a<..} \<inter> {..b}"
1.69 +    by auto
1.70 +  then show "convex {a<..b}"
1.71 +    by (simp only: convex_Int 3 2)
1.72 +  have "{a..<b} = {a..} \<inter> {..<b}"
1.73 +    by auto
1.74 +  then show "convex {a..<b}"
1.75 +    by (simp only: convex_Int 1 4)
1.76 +  have "{a<..<b} = {a<..} \<inter> {..<b}"
1.77 +    by auto
1.78 +  then show "convex {a<..<b}"
1.79 +    by (simp only: convex_Int 3 4)
1.80  qed
1.81
1.82  lemma convex_Reals: "convex Reals"
1.83    by (simp add: convex_def scaleR_conv_of_real)
1.84 -
1.85 -subsection {* Explicit expressions for convexity in terms of arbitrary sums. *}
1.86 +
1.87 +
1.88 +subsection \<open>Explicit expressions for convexity in terms of arbitrary sums\<close>
1.89
1.90  lemma convex_setsum:
1.91    fixes C :: "'a::real_vector set"
1.92 @@ -151,27 +168,27 @@
1.93    have "a i *\<^sub>R y i + (\<Sum>j\<in>s. a j *\<^sub>R y j) \<in> C"
1.94    proof (cases)
1.95      assume z: "setsum a s = 0"
1.96 -    with `a i + setsum a s = 1` have "a i = 1"
1.97 +    with \<open>a i + setsum a s = 1\<close> have "a i = 1"
1.98        by simp
1.99 -    from setsum_nonneg_0 [OF `finite s` _ z] `\<forall>j\<in>s. 0 \<le> a j` have "\<forall>j\<in>s. a j = 0"
1.100 +    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"
1.101        by simp
1.102 -    show ?thesis using `a i = 1` and `\<forall>j\<in>s. a j = 0` and `y i \<in> C`
1.103 +    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>
1.104        by simp
1.105    next
1.106      assume nz: "setsum a s \<noteq> 0"
1.107 -    with `0 \<le> setsum a s` have "0 < setsum a s"
1.108 +    with \<open>0 \<le> setsum a s\<close> have "0 < setsum a s"
1.109        by simp
1.110      then have "(\<Sum>j\<in>s. (a j / setsum a s) *\<^sub>R y j) \<in> C"
1.111 -      using `\<forall>j\<in>s. 0 \<le> a j` and `\<forall>j\<in>s. y j \<in> C`
1.112 +      using \<open>\<forall>j\<in>s. 0 \<le> a j\<close> and \<open>\<forall>j\<in>s. y j \<in> C\<close>
1.113        by (simp add: IH setsum_divide_distrib [symmetric])
1.114 -    from `convex C` and `y i \<in> C` and this and `0 \<le> a i`
1.115 -      and `0 \<le> setsum a s` and `a i + setsum a s = 1`
1.116 +    from \<open>convex C\<close> and \<open>y i \<in> C\<close> and this and \<open>0 \<le> a i\<close>
1.117 +      and \<open>0 \<le> setsum a s\<close> and \<open>a i + setsum a s = 1\<close>
1.118      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"
1.119        by (rule convexD)
1.120      then show ?thesis
1.121        by (simp add: scaleR_setsum_right nz)
1.122    qed
1.123 -  then show ?case using `finite s` and `i \<notin> s`
1.124 +  then show ?case using \<open>finite s\<close> and \<open>i \<notin> s\<close>
1.125      by simp
1.126  qed
1.127
1.128 @@ -185,11 +202,10 @@
1.129    assume "convex s"
1.130      "\<forall>i. 1 \<le> i \<and> i \<le> k \<longrightarrow> 0 \<le> u i \<and> x i \<in> s"
1.131      "setsum u {1..k} = 1"
1.132 -  from this convex_setsum[of "{1 .. k}" s]
1.133 -  show "(\<Sum>j\<in>{1 .. k}. u j *\<^sub>R x j) \<in> s"
1.134 +  with convex_setsum[of "{1 .. k}" s] show "(\<Sum>j\<in>{1 .. k}. u j *\<^sub>R x j) \<in> s"
1.135      by auto
1.136  next
1.137 -  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
1.138 +  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
1.139      \<longrightarrow> (\<Sum>i = 1..k. u i *\<^sub>R (x i :: 'a)) \<in> s"
1.140    {
1.141      fix \<mu> :: real
1.142 @@ -205,7 +221,7 @@
1.143      then have "setsum ?u {1 .. 2} = 1"
1.144        using setsum.If_cases[of "{(1 :: nat) .. 2}" "\<lambda> x. x = 1" "\<lambda> x. \<mu>" "\<lambda> x. 1 - \<mu>"]
1.145        by auto
1.146 -    with asm[rule_format, of "2" ?u ?x] have s: "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) \<in> s"
1.147 +    with *[rule_format, of "2" ?u ?x] have s: "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) \<in> s"
1.148        using mu xy by auto
1.149      have grarr: "(\<Sum>j \<in> {Suc (Suc 0)..2}. ?u j *\<^sub>R ?x j) = (1 - \<mu>) *\<^sub>R y"
1.150        using setsum_head_Suc[of "Suc (Suc 0)" 2 "\<lambda> j. (1 - \<mu>) *\<^sub>R y"] by auto
1.151 @@ -213,7 +229,7 @@
1.152      have "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) = \<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y"
1.153        by auto
1.154      then have "(1 - \<mu>) *\<^sub>R y + \<mu> *\<^sub>R x \<in> s"
1.155 -      using s by (auto simp:add.commute)
1.156 +      using s by (auto simp: add.commute)
1.157    }
1.158    then show "convex s"
1.159      unfolding convex_alt by auto
1.160 @@ -233,29 +249,26 @@
1.161    then show "(\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s"
1.162      using convex_setsum[of t s u "\<lambda> x. x"] by auto
1.163  next
1.164 -  assume asm0: "\<forall>t. \<forall> u. finite t \<and> t \<subseteq> s \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and>
1.165 +  assume *: "\<forall>t. \<forall> u. finite t \<and> t \<subseteq> s \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and>
1.166      setsum u t = 1 \<longrightarrow> (\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s"
1.167    show "convex s"
1.168      unfolding convex_alt
1.169    proof safe
1.170      fix x y
1.171      fix \<mu> :: real
1.172 -    assume asm: "x \<in> s" "y \<in> s" "0 \<le> \<mu>" "\<mu> \<le> 1"
1.173 -    {
1.174 -      assume "x \<noteq> y"
1.175 -      then have "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
1.176 -        using asm0[rule_format, of "{x, y}" "\<lambda> z. if z = x then 1 - \<mu> else \<mu>"]
1.177 -          asm by auto
1.178 -    }
1.179 -    moreover
1.180 -    {
1.181 -      assume "x = y"
1.182 -      then have "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
1.183 -        using asm0[rule_format, of "{x, y}" "\<lambda> z. 1"]
1.184 -          asm by (auto simp: field_simps real_vector.scale_left_diff_distrib)
1.185 -    }
1.186 -    ultimately show "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
1.187 -      by blast
1.188 +    assume **: "x \<in> s" "y \<in> s" "0 \<le> \<mu>" "\<mu> \<le> 1"
1.189 +    show "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
1.190 +    proof (cases "x = y")
1.191 +      case False
1.192 +      then show ?thesis
1.193 +        using *[rule_format, of "{x, y}" "\<lambda> z. if z = x then 1 - \<mu> else \<mu>"] **
1.194 +          by auto
1.195 +    next
1.196 +      case True
1.197 +      then show ?thesis
1.198 +        using *[rule_format, of "{x, y}" "\<lambda> z. 1"] **
1.199 +          by (auto simp: field_simps real_vector.scale_left_diff_distrib)
1.200 +    qed
1.201    qed
1.202  qed
1.203
1.204 @@ -277,7 +290,7 @@
1.205  qed (erule_tac x=s in allE, erule_tac x=u in allE, auto)
1.206
1.207
1.208 -subsection {* Functions that are convex on a set *}
1.209 +subsection \<open>Functions that are convex on a set\<close>
1.210
1.211  definition convex_on :: "'a::real_vector set \<Rightarrow> ('a \<Rightarrow> real) \<Rightarrow> bool"
1.212    where "convex_on s f \<longleftrightarrow>
1.213 @@ -299,7 +312,7 @@
1.214      assume "0 \<le> u" "0 \<le> v" "u + v = 1"
1.215      ultimately
1.216      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)"
1.218 +      using assms unfolding convex_on_def by (auto simp: add_mono)
1.219      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)"
1.221    }
1.222 @@ -313,7 +326,7 @@
1.223      and "convex_on s f"
1.224    shows "convex_on s (\<lambda>x. c * f x)"
1.225  proof -
1.226 -  have *: "\<And>u c fx v fy ::real. u * (c * fx) + v * (c * fy) = c * (u * fx + v * fy)"
1.227 +  have *: "\<And>u c fx v fy :: real. u * (c * fx) + v * (c * fy) = c * (u * fx + v * fy)"
1.229    show ?thesis using assms(2) and mult_left_mono [OF _ assms(1)]
1.230      unfolding convex_on_def and * by auto
1.231 @@ -330,9 +343,9 @@
1.232  proof -
1.233    let ?m = "max (f x) (f y)"
1.234    have "u * f x + v * f y \<le> u * max (f x) (f y) + v * max (f x) (f y)"
1.236 +    using assms(4,5) by (auto simp: mult_left_mono add_mono)
1.237    also have "\<dots> = max (f x) (f y)"
1.238 -    using assms(6) by (simp add: distrib_right [symmetric])
1.239 +    using assms(6) by (simp add: distrib_right [symmetric])
1.240    finally show ?thesis
1.241      using assms unfolding convex_on_def by fastforce
1.242  qed
1.243 @@ -340,7 +353,7 @@
1.244  lemma convex_on_dist [intro]:
1.245    fixes s :: "'a::real_normed_vector set"
1.246    shows "convex_on s (\<lambda>x. dist a x)"
1.247 -proof (auto simp add: convex_on_def dist_norm)
1.248 +proof (auto simp: convex_on_def dist_norm)
1.249    fix x y
1.250    assume "x \<in> s" "y \<in> s"
1.251    fix u v :: real
1.252 @@ -348,16 +361,16 @@
1.253    assume "0 \<le> v"
1.254    assume "u + v = 1"
1.255    have "a = u *\<^sub>R a + v *\<^sub>R a"
1.256 -    unfolding scaleR_left_distrib[symmetric] and `u + v = 1` by simp
1.257 +    unfolding scaleR_left_distrib[symmetric] and \<open>u + v = 1\<close> by simp
1.258    then have *: "a - (u *\<^sub>R x + v *\<^sub>R y) = (u *\<^sub>R (a - x)) + (v *\<^sub>R (a - y))"
1.259 -    by (auto simp add: algebra_simps)
1.260 +    by (auto simp: algebra_simps)
1.261    show "norm (a - (u *\<^sub>R x + v *\<^sub>R y)) \<le> u * norm (a - x) + v * norm (a - y)"
1.262      unfolding * using norm_triangle_ineq[of "u *\<^sub>R (a - x)" "v *\<^sub>R (a - y)"]
1.263 -    using `0 \<le> u` `0 \<le> v` by auto
1.264 +    using \<open>0 \<le> u\<close> \<open>0 \<le> v\<close> by auto
1.265  qed
1.266
1.267
1.268 -subsection {* Arithmetic operations on sets preserve convexity. *}
1.269 +subsection \<open>Arithmetic operations on sets preserve convexity\<close>
1.270
1.271  lemma convex_linear_image:
1.272    assumes "linear f"
1.273 @@ -365,7 +378,7 @@
1.274    shows "convex (f ` s)"
1.275  proof -
1.276    interpret f: linear f by fact
1.277 -  from `convex s` show "convex (f ` s)"
1.278 +  from \<open>convex s\<close> show "convex (f ` s)"
1.280  qed
1.281
1.282 @@ -375,7 +388,7 @@
1.283    shows "convex (f -` s)"
1.284  proof -
1.285    interpret f: linear f by fact
1.286 -  from `convex s` show "convex (f -` s)"
1.287 +  from \<open>convex s\<close> show "convex (f -` s)"
1.289  qed
1.290
1.291 @@ -386,7 +399,7 @@
1.292    have "linear (\<lambda>x. c *\<^sub>R x)"
1.294    then show ?thesis
1.295 -    using `convex s` by (rule convex_linear_image)
1.296 +    using \<open>convex s\<close> by (rule convex_linear_image)
1.297  qed
1.298
1.299  lemma convex_scaled:
1.300 @@ -396,7 +409,7 @@
1.301    have "linear (\<lambda>x. x *\<^sub>R c)"
1.303    then show ?thesis
1.304 -    using `convex s` by (rule convex_linear_image)
1.305 +    using \<open>convex s\<close> by (rule convex_linear_image)
1.306  qed
1.307
1.308  lemma convex_negations:
1.309 @@ -406,7 +419,7 @@
1.310    have "linear (\<lambda>x. - x)"
1.312    then show ?thesis
1.313 -    using `convex s` by (rule convex_linear_image)
1.314 +    using \<open>convex s\<close> by (rule convex_linear_image)
1.315  qed
1.316
1.317  lemma convex_sums:
1.318 @@ -415,7 +428,7 @@
1.319    shows "convex {x + y| x y. x \<in> s \<and> y \<in> t}"
1.320  proof -
1.321    have "linear (\<lambda>(x, y). x + y)"
1.323 +    by (auto intro: linearI simp: scaleR_add_right)
1.324    with assms have "convex ((\<lambda>(x, y). x + y) ` (s \<times> t))"
1.325      by (intro convex_linear_image convex_Times)
1.326    also have "((\<lambda>(x, y). x + y) ` (s \<times> t)) = {x + y| x y. x \<in> s \<and> y \<in> t}"
1.327 @@ -428,7 +441,7 @@
1.328    shows "convex {x - y| x y. x \<in> s \<and> y \<in> t}"
1.329  proof -
1.330    have "{x - y| x y. x \<in> s \<and> y \<in> t} = {x + y |x y. x \<in> s \<and> y \<in> uminus ` t}"
1.333    then show ?thesis
1.334      using convex_sums[OF assms(1) convex_negations[OF assms(2)]] by auto
1.335  qed
1.336 @@ -457,23 +470,23 @@
1.337    unfolding convex_alt
1.338  proof safe
1.339    fix y x \<mu> :: real
1.340 -  assume asms: "y > 0" "x > 0" "\<mu> \<ge> 0" "\<mu> \<le> 1"
1.341 +  assume *: "y > 0" "x > 0" "\<mu> \<ge> 0" "\<mu> \<le> 1"
1.342    {
1.343      assume "\<mu> = 0"
1.344      then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y = y" by simp
1.345 -    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using asms by simp
1.346 +    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using * by simp
1.347    }
1.348    moreover
1.349    {
1.350      assume "\<mu> = 1"
1.351 -    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using asms by simp
1.352 +    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using * by simp
1.353    }
1.354    moreover
1.355    {
1.356      assume "\<mu> \<noteq> 1" "\<mu> \<noteq> 0"
1.357 -    then have "\<mu> > 0" "(1 - \<mu>) > 0" using asms by auto
1.358 -    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using asms
1.360 +    then have "\<mu> > 0" "(1 - \<mu>) > 0" using * by auto
1.361 +    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using *
1.362 +      by (auto simp: add_pos_pos)
1.363    }
1.364    ultimately show "(1 - \<mu>) *\<^sub>R y + \<mu> *\<^sub>R x > 0"
1.365      using assms by fastforce
1.366 @@ -496,70 +509,75 @@
1.367    then have ai: "a i = 1" by auto
1.368    then show ?case by auto
1.369  next
1.370 -  case (insert i s) note asms = this
1.371 +  case (insert i s)
1.372    then have "convex_on C f" by simp
1.373    from this[unfolded convex_on_def, rule_format]
1.374    have conv: "\<And>x y \<mu>. x \<in> C \<Longrightarrow> y \<in> C \<Longrightarrow> 0 \<le> \<mu> \<Longrightarrow> \<mu> \<le> 1 \<Longrightarrow>
1.375        f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
1.376      by simp
1.377 -  {
1.378 -    assume "a i = 1"
1.379 +  show ?case
1.380 +  proof (cases "a i = 1")
1.381 +    case True
1.382      then have "(\<Sum> j \<in> s. a j) = 0"
1.383 -      using asms by auto
1.384 +      using insert by auto
1.385      then have "\<And>j. j \<in> s \<Longrightarrow> a j = 0"
1.386 -      using setsum_nonneg_0[where 'b=real] asms by fastforce
1.387 -    then have ?case using asms by auto
1.388 -  }
1.389 -  moreover
1.390 -  {
1.391 -    assume asm: "a i \<noteq> 1"
1.392 -    from asms have yai: "y i \<in> C" "a i \<ge> 0" by auto
1.393 -    have fis: "finite (insert i s)" using asms by auto
1.394 -    then have ai1: "a i \<le> 1" using setsum_nonneg_leq_bound[of "insert i s" a] asms by simp
1.395 -    then have "a i < 1" using asm by auto
1.396 -    then have i0: "1 - a i > 0" by auto
1.397 +      using setsum_nonneg_0[where 'b=real] insert by fastforce
1.398 +    then show ?thesis
1.399 +      using insert by auto
1.400 +  next
1.401 +    case False
1.402 +    from insert have yai: "y i \<in> C" "a i \<ge> 0"
1.403 +      by auto
1.404 +    have fis: "finite (insert i s)"
1.405 +      using insert by auto
1.406 +    then have ai1: "a i \<le> 1"
1.407 +      using setsum_nonneg_leq_bound[of "insert i s" a] insert by simp
1.408 +    then have "a i < 1"
1.409 +      using False by auto
1.410 +    then have i0: "1 - a i > 0"
1.411 +      by auto
1.412      let ?a = "\<lambda>j. a j / (1 - a i)"
1.413 -    {
1.414 -      fix j
1.415 -      assume "j \<in> s"
1.416 -      with i0 asms have "?a j \<ge> 0"
1.417 -        by fastforce
1.418 -    }
1.419 -    note a_nonneg = this
1.420 -    have "(\<Sum> j \<in> insert i s. a j) = 1" using asms by auto
1.421 -    then have "(\<Sum> j \<in> s. a j) = 1 - a i" using setsum.insert asms by fastforce
1.422 -    then have "(\<Sum> j \<in> s. a j) / (1 - a i) = 1" using i0 by auto
1.423 -    then have a1: "(\<Sum> j \<in> s. ?a j) = 1" unfolding setsum_divide_distrib by simp
1.424 -    have "convex C" using asms by auto
1.425 +    have a_nonneg: "?a j \<ge> 0" if "j \<in> s" for j
1.426 +      using i0 insert prems by fastforce
1.427 +    have "(\<Sum> j \<in> insert i s. a j) = 1"
1.428 +      using insert by auto
1.429 +    then have "(\<Sum> j \<in> s. a j) = 1 - a i"
1.430 +      using setsum.insert insert by fastforce
1.431 +    then have "(\<Sum> j \<in> s. a j) / (1 - a i) = 1"
1.432 +      using i0 by auto
1.433 +    then have a1: "(\<Sum> j \<in> s. ?a j) = 1"
1.434 +      unfolding setsum_divide_distrib by simp
1.435 +    have "convex C" using insert by auto
1.436      then have asum: "(\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<in> C"
1.437 -      using asms convex_setsum[OF `finite s`
1.438 -        `convex C` a1 a_nonneg] by auto
1.439 +      using insert convex_setsum[OF \<open>finite s\<close>
1.440 +        \<open>convex C\<close> a1 a_nonneg] by auto
1.441      have asum_le: "f (\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<le> (\<Sum> j \<in> s. ?a j * f (y j))"
1.442 -      using a_nonneg a1 asms by blast
1.443 +      using a_nonneg a1 insert by blast
1.444      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)"
1.445 -      using setsum.insert[of s i "\<lambda> j. a j *\<^sub>R y j", OF `finite s` `i \<notin> s`] asms
1.446 -      by (auto simp only:add.commute)
1.447 +      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
1.448 +      by (auto simp only: add.commute)
1.449      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)"
1.450        using i0 by auto
1.451      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)"
1.452        using scaleR_right.setsum[of "inverse (1 - a i)" "\<lambda> j. a j *\<^sub>R y j" s, symmetric]
1.453 -      by (auto simp:algebra_simps)
1.454 +      by (auto simp: algebra_simps)
1.455      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)"
1.456        by (auto simp: divide_inverse)
1.457      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)"
1.458        using conv[of "y i" "(\<Sum> j \<in> s. ?a j *\<^sub>R y j)" "a i", OF yai(1) asum yai(2) ai1]
1.460 +      by (auto simp: add.commute)
1.461      also have "\<dots> \<le> (1 - a i) * (\<Sum> j \<in> s. ?a j * f (y j)) + a i * f (y i)"
1.462        using add_right_mono[OF mult_left_mono[of _ _ "1 - a i",
1.463          OF asum_le less_imp_le[OF i0]], of "a i * f (y i)"] by simp
1.464      also have "\<dots> = (\<Sum> j \<in> s. (1 - a i) * ?a j * f (y j)) + a i * f (y i)"
1.465        unfolding setsum_right_distrib[of "1 - a i" "\<lambda> j. ?a j * f (y j)"] using i0 by auto
1.466 -    also have "\<dots> = (\<Sum> j \<in> s. a j * f (y j)) + a i * f (y i)" using i0 by auto
1.467 -    also have "\<dots> = (\<Sum> j \<in> insert i s. a j * f (y j))" using asms by auto
1.468 -    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))"
1.469 +    also have "\<dots> = (\<Sum> j \<in> s. a j * f (y j)) + a i * f (y i)"
1.470 +      using i0 by auto
1.471 +    also have "\<dots> = (\<Sum> j \<in> insert i s. a j * f (y j))"
1.472 +      using insert by auto
1.473 +    finally show ?thesis
1.474        by simp
1.475 -  }
1.476 -  ultimately show ?case by auto
1.477 +  qed
1.478  qed
1.479
1.480  lemma convex_on_alt:
1.481 @@ -571,24 +589,24 @@
1.482  proof safe
1.483    fix x y
1.484    fix \<mu> :: real
1.485 -  assume asms: "convex_on C f" "x \<in> C" "y \<in> C" "0 \<le> \<mu>" "\<mu> \<le> 1"
1.486 +  assume *: "convex_on C f" "x \<in> C" "y \<in> C" "0 \<le> \<mu>" "\<mu> \<le> 1"
1.487    from this[unfolded convex_on_def, rule_format]
1.488    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"
1.489      by auto
1.490 -  from this[of "\<mu>" "1 - \<mu>", simplified] asms
1.491 +  from this[of "\<mu>" "1 - \<mu>", simplified] *
1.492    show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
1.493      by auto
1.494  next
1.495 -  assume asm: "\<forall>x\<in>C. \<forall>y\<in>C. \<forall>\<mu>. 0 \<le> \<mu> \<and> \<mu> \<le> 1 \<longrightarrow>
1.496 +  assume *: "\<forall>x\<in>C. \<forall>y\<in>C. \<forall>\<mu>. 0 \<le> \<mu> \<and> \<mu> \<le> 1 \<longrightarrow>
1.497      f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
1.498    {
1.499      fix x y
1.500      fix u v :: real
1.501 -    assume lasm: "x \<in> C" "y \<in> C" "u \<ge> 0" "v \<ge> 0" "u + v = 1"
1.502 +    assume **: "x \<in> C" "y \<in> C" "u \<ge> 0" "v \<ge> 0" "u + v = 1"
1.503      then have[simp]: "1 - u = v" by auto
1.504 -    from asm[rule_format, of x y u]
1.505 +    from *[rule_format, of x y u]
1.506      have "f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y"
1.507 -      using lasm by auto
1.508 +      using ** by auto
1.509    }
1.510    then show "convex_on C f"
1.511      unfolding convex_on_def by auto
1.512 @@ -605,12 +623,12 @@
1.513    def a \<equiv> "(t - y) / (x - y)"
1.514    with t have "0 \<le> a" "0 \<le> 1 - a"
1.515      by (auto simp: field_simps)
1.516 -  with f `x \<in> I` `y \<in> I` have cvx: "f (a * x + (1 - a) * y) \<le> a * f x + (1 - a) * f y"
1.517 +  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"
1.518      by (auto simp: convex_on_def)
1.519    have "a * x + (1 - a) * y = a * (x - y) + y"
1.521    also have "\<dots> = t"
1.522 -    unfolding a_def using `x < t` `t < y` by simp
1.523 +    unfolding a_def using \<open>x < t\<close> \<open>t < y\<close> by simp
1.524    finally have "f t \<le> a * f x + (1 - a) * f y"
1.525      using cvx by simp
1.526    also have "\<dots> = a * (f x - f y) + f y"
1.527 @@ -633,17 +651,17 @@
1.528  proof safe
1.529    fix x y \<mu> :: real
1.530    let ?x = "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y"
1.531 -  assume asm: "convex C" "x \<in> C" "y \<in> C" "\<mu> \<ge> 0" "\<mu> \<le> 1"
1.532 +  assume *: "convex C" "x \<in> C" "y \<in> C" "\<mu> \<ge> 0" "\<mu> \<le> 1"
1.533    then have "1 - \<mu> \<ge> 0" by auto
1.534    then have xpos: "?x \<in> C"
1.535 -    using asm unfolding convex_alt by fastforce
1.536 +    using * unfolding convex_alt by fastforce
1.537    have geq: "\<mu> * (f x - f ?x) + (1 - \<mu>) * (f y - f ?x) \<ge>
1.538        \<mu> * f' ?x * (x - ?x) + (1 - \<mu>) * f' ?x * (y - ?x)"
1.539 -    using add_mono[OF mult_left_mono[OF leq[OF xpos asm(2)] `\<mu> \<ge> 0`]
1.540 -      mult_left_mono[OF leq[OF xpos asm(3)] `1 - \<mu> \<ge> 0`]]
1.541 +    using add_mono[OF mult_left_mono[OF leq[OF xpos *(2)] \<open>\<mu> \<ge> 0\<close>]
1.542 +      mult_left_mono[OF leq[OF xpos *(3)] \<open>1 - \<mu> \<ge> 0\<close>]]
1.543      by auto
1.544    then have "\<mu> * f x + (1 - \<mu>) * f y - f ?x \<ge> 0"
1.545 -    by (auto simp add: field_simps)
1.546 +    by (auto simp: field_simps)
1.547    then show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
1.548      using convex_on_alt by auto
1.549  qed
1.550 @@ -654,26 +672,25 @@
1.551      and "x \<in> C" "y \<in> C" "x < y"
1.552    shows "{x .. y} \<subseteq> C"
1.553  proof safe
1.554 -  fix z assume zasm: "z \<in> {x .. y}"
1.555 -  {
1.556 -    assume asm: "x < z" "z < y"
1.557 +  fix z assume z: "z \<in> {x .. y}"
1.558 +  have less: "z \<in> C" if *: "x < z" "z < y"
1.559 +  proof -
1.560      let ?\<mu> = "(y - z) / (y - x)"
1.561      have "0 \<le> ?\<mu>" "?\<mu> \<le> 1"
1.562 -      using assms asm by (auto simp add: field_simps)
1.563 +      using assms * by (auto simp: field_simps)
1.564      then have comb: "?\<mu> * x + (1 - ?\<mu>) * y \<in> C"
1.565        using assms iffD1[OF convex_alt, rule_format, of C y x ?\<mu>]
1.567      have "?\<mu> * x + (1 - ?\<mu>) * y = (y - z) * x / (y - x) + (1 - (y - z) / (y - x)) * y"
1.568 -      by (auto simp add: field_simps)
1.569 +      by (auto simp: field_simps)
1.570      also have "\<dots> = ((y - z) * x + (y - x - (y - z)) * y) / (y - x)"
1.571        using assms unfolding add_divide_distrib by (auto simp: field_simps)
1.572      also have "\<dots> = z"
1.573        using assms by (auto simp: field_simps)
1.574 -    finally have "z \<in> C"
1.575 +    finally show ?thesis
1.576        using comb by auto
1.577 -  }
1.578 -  note less = this
1.579 -  show "z \<in> C" using zasm less assms
1.580 +  qed
1.581 +  show "z \<in> C" using z less assms
1.582      unfolding atLeastAtMost_iff le_less by auto
1.583  qed
1.584
1.585 @@ -689,56 +706,77 @@
1.586  proof -
1.587    {
1.588      fix x y :: real
1.589 -    assume asm: "x \<in> C" "y \<in> C" "y > x"
1.590 -    then have ge: "y - x > 0" "y - x \<ge> 0" by auto
1.591 -    from asm have le: "x - y < 0" "x - y \<le> 0" by auto
1.592 +    assume *: "x \<in> C" "y \<in> C" "y > x"
1.593 +    then have ge: "y - x > 0" "y - x \<ge> 0"
1.594 +      by auto
1.595 +    from * have le: "x - y < 0" "x - y \<le> 0"
1.596 +      by auto
1.597      then obtain z1 where z1: "z1 > x" "z1 < y" "f y - f x = (y - x) * f' z1"
1.598 -      using subsetD[OF atMostAtLeast_subset_convex[OF `convex C` `x \<in> C` `y \<in> C` `x < y`],
1.599 -        THEN f', THEN MVT2[OF `x < y`, rule_format, unfolded atLeastAtMost_iff[symmetric]]]
1.600 +      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>],
1.601 +        THEN f', THEN MVT2[OF \<open>x < y\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]]
1.602        by auto
1.603 -    then have "z1 \<in> C" using atMostAtLeast_subset_convex
1.604 -      `convex C` `x \<in> C` `y \<in> C` `x < y` by fastforce
1.605 +    then have "z1 \<in> C"
1.606 +      using atMostAtLeast_subset_convex \<open>convex C\<close> \<open>x \<in> C\<close> \<open>y \<in> C\<close> \<open>x < y\<close>
1.607 +      by fastforce
1.608      from z1 have z1': "f x - f y = (x - y) * f' z1"
1.610 +      by (simp add: field_simps)
1.611      obtain z2 where z2: "z2 > x" "z2 < z1" "f' z1 - f' x = (z1 - x) * f'' z2"
1.612 -      using subsetD[OF atMostAtLeast_subset_convex[OF `convex C` `x \<in> C` `z1 \<in> C` `x < z1`],
1.613 -        THEN f'', THEN MVT2[OF `x < z1`, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
1.614 +      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>],
1.615 +        THEN f'', THEN MVT2[OF \<open>x < z1\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
1.616        by auto
1.617      obtain z3 where z3: "z3 > z1" "z3 < y" "f' y - f' z1 = (y - z1) * f'' z3"
1.618 -      using subsetD[OF atMostAtLeast_subset_convex[OF `convex C` `z1 \<in> C` `y \<in> C` `z1 < y`],
1.619 -        THEN f'', THEN MVT2[OF `z1 < y`, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
1.620 +      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>],
1.621 +        THEN f'', THEN MVT2[OF \<open>z1 < y\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
1.622        by auto
1.623      have "f' y - (f x - f y) / (x - y) = f' y - f' z1"
1.624 -      using asm z1' by auto
1.625 -    also have "\<dots> = (y - z1) * f'' z3" using z3 by auto
1.626 -    finally have cool': "f' y - (f x - f y) / (x - y) = (y - z1) * f'' z3" by simp
1.627 -    have A': "y - z1 \<ge> 0" using z1 by auto
1.628 -    have "z3 \<in> C" using z3 asm atMostAtLeast_subset_convex
1.629 -      `convex C` `x \<in> C` `z1 \<in> C` `x < z1` by fastforce
1.630 -    then have B': "f'' z3 \<ge> 0" using assms by auto
1.631 -    from A' B' have "(y - z1) * f'' z3 \<ge> 0" by auto
1.632 -    from cool' this have "f' y - (f x - f y) / (x - y) \<ge> 0" by auto
1.633 +      using * z1' by auto
1.634 +    also have "\<dots> = (y - z1) * f'' z3"
1.635 +      using z3 by auto
1.636 +    finally have cool': "f' y - (f x - f y) / (x - y) = (y - z1) * f'' z3"
1.637 +      by simp
1.638 +    have A': "y - z1 \<ge> 0"
1.639 +      using z1 by auto
1.640 +    have "z3 \<in> C"
1.641 +      using z3 * atMostAtLeast_subset_convex \<open>convex C\<close> \<open>x \<in> C\<close> \<open>z1 \<in> C\<close> \<open>x < z1\<close>
1.642 +      by fastforce
1.643 +    then have B': "f'' z3 \<ge> 0"
1.644 +      using assms by auto
1.645 +    from A' B' have "(y - z1) * f'' z3 \<ge> 0"
1.646 +      by auto
1.647 +    from cool' this have "f' y - (f x - f y) / (x - y) \<ge> 0"
1.648 +      by auto
1.649      from mult_right_mono_neg[OF this le(2)]
1.650      have "f' y * (x - y) - (f x - f y) / (x - y) * (x - y) \<le> 0 * (x - y)"
1.652 -    then have "f' y * (x - y) - (f x - f y) \<le> 0" using le by auto
1.653 -    then have res: "f' y * (x - y) \<le> f x - f y" by auto
1.654 +    then have "f' y * (x - y) - (f x - f y) \<le> 0"
1.655 +      using le by auto
1.656 +    then have res: "f' y * (x - y) \<le> f x - f y"
1.657 +      by auto
1.658      have "(f y - f x) / (y - x) - f' x = f' z1 - f' x"
1.659 -      using asm z1 by auto
1.660 -    also have "\<dots> = (z1 - x) * f'' z2" using z2 by auto
1.661 -    finally have cool: "(f y - f x) / (y - x) - f' x = (z1 - x) * f'' z2" by simp
1.662 -    have A: "z1 - x \<ge> 0" using z1 by auto
1.663 -    have "z2 \<in> C" using z2 z1 asm atMostAtLeast_subset_convex
1.664 -      `convex C` `z1 \<in> C` `y \<in> C` `z1 < y` by fastforce
1.665 -    then have B: "f'' z2 \<ge> 0" using assms by auto
1.666 -    from A B have "(z1 - x) * f'' z2 \<ge> 0" by auto
1.667 -    from cool this have "(f y - f x) / (y - x) - f' x \<ge> 0" by auto
1.668 +      using * z1 by auto
1.669 +    also have "\<dots> = (z1 - x) * f'' z2"
1.670 +      using z2 by auto
1.671 +    finally have cool: "(f y - f x) / (y - x) - f' x = (z1 - x) * f'' z2"
1.672 +      by simp
1.673 +    have A: "z1 - x \<ge> 0"
1.674 +      using z1 by auto
1.675 +    have "z2 \<in> C"
1.676 +      using z2 z1 * atMostAtLeast_subset_convex \<open>convex C\<close> \<open>z1 \<in> C\<close> \<open>y \<in> C\<close> \<open>z1 < y\<close>
1.677 +      by fastforce
1.678 +    then have B: "f'' z2 \<ge> 0"
1.679 +      using assms by auto
1.680 +    from A B have "(z1 - x) * f'' z2 \<ge> 0"
1.681 +      by auto
1.682 +    with cool have "(f y - f x) / (y - x) - f' x \<ge> 0"
1.683 +      by auto
1.684      from mult_right_mono[OF this ge(2)]
1.685      have "(f y - f x) / (y - x) * (y - x) - f' x * (y - x) \<ge> 0 * (y - x)"
1.687 -    then have "f y - f x - f' x * (y - x) \<ge> 0" using ge by auto
1.688 +    then have "f y - f x - f' x * (y - x) \<ge> 0"
1.689 +      using ge by auto
1.690      then have "f y - f x \<ge> f' x * (y - x)" "f' y * (x - y) \<le> f x - f y"
1.691 -      using res by auto } note less_imp = this
1.692 +      using res by auto
1.693 +  } note less_imp = this
1.694    {
1.695      fix x y :: real
1.696      assume "x \<in> C" "y \<in> C" "x \<noteq> y"
1.697 @@ -748,7 +786,7 @@
1.698    moreover
1.699    {
1.700      fix x y :: real
1.701 -    assume asm: "x \<in> C" "y \<in> C" "x = y"
1.702 +    assume "x \<in> C" "y \<in> C" "x = y"
1.703      then have "f y - f x \<ge> f' x * (y - x)" by auto
1.704    }
1.705    ultimately show ?thesis using assms by blast
1.706 @@ -781,9 +819,9 @@
1.707      by auto
1.708    then have f''0: "\<And>z::real. z > 0 \<Longrightarrow>
1.709      DERIV (\<lambda> z. - 1 / (ln b * z)) z :> 1 / (ln b * z * z)"
1.710 -    unfolding inverse_eq_divide by (auto simp add: mult.assoc)
1.711 +    unfolding inverse_eq_divide by (auto simp: mult.assoc)
1.712    have f''_ge0: "\<And>z::real. z > 0 \<Longrightarrow> 1 / (ln b * z * z) \<ge> 0"
1.713 -    using `b > 1` by (auto intro!:less_imp_le)
1.714 +    using \<open>b > 1\<close> by (auto intro!: less_imp_le)
1.715    from f''_ge0_imp_convex[OF pos_is_convex,
1.716      unfolded greaterThan_iff, OF f' f''0 f''_ge0]
1.717    show ?thesis by auto
```