author | paulson |
Mon, 26 Oct 2015 23:41:27 +0000 | |
changeset 61518 | ff12606337e9 |
parent 61426 | d53db136e8fd |
child 61520 | 8f85bb443d33 |
permissions | -rw-r--r-- |
36648 | 1 |
(* Title: HOL/Library/Convex.thy |
2 |
Author: Armin Heller, TU Muenchen |
|
3 |
Author: Johannes Hoelzl, TU Muenchen |
|
4 |
*) |
|
5 |
||
60423 | 6 |
section \<open>Convexity in real vector spaces\<close> |
36648 | 7 |
|
36623 | 8 |
theory Convex |
9 |
imports Product_Vector |
|
10 |
begin |
|
11 |
||
60423 | 12 |
subsection \<open>Convexity\<close> |
36623 | 13 |
|
49609 | 14 |
definition convex :: "'a::real_vector set \<Rightarrow> bool" |
15 |
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)" |
|
36623 | 16 |
|
53676 | 17 |
lemma convexI: |
18 |
assumes "\<And>x y u v. x \<in> s \<Longrightarrow> y \<in> s \<Longrightarrow> 0 \<le> u \<Longrightarrow> 0 \<le> v \<Longrightarrow> u + v = 1 \<Longrightarrow> u *\<^sub>R x + v *\<^sub>R y \<in> s" |
|
19 |
shows "convex s" |
|
20 |
using assms unfolding convex_def by fast |
|
21 |
||
22 |
lemma convexD: |
|
23 |
assumes "convex s" and "x \<in> s" and "y \<in> s" and "0 \<le> u" and "0 \<le> v" and "u + v = 1" |
|
24 |
shows "u *\<^sub>R x + v *\<^sub>R y \<in> s" |
|
25 |
using assms unfolding convex_def by fast |
|
26 |
||
36623 | 27 |
lemma convex_alt: |
28 |
"convex s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. \<forall>u. 0 \<le> u \<and> u \<le> 1 \<longrightarrow> ((1 - u) *\<^sub>R x + u *\<^sub>R y) \<in> s)" |
|
29 |
(is "_ \<longleftrightarrow> ?alt") |
|
30 |
proof |
|
31 |
assume alt[rule_format]: ?alt |
|
56796 | 32 |
{ |
33 |
fix x y and u v :: real |
|
34 |
assume mem: "x \<in> s" "y \<in> s" |
|
49609 | 35 |
assume "0 \<le> u" "0 \<le> v" |
56796 | 36 |
moreover |
37 |
assume "u + v = 1" |
|
38 |
then have "u = 1 - v" by auto |
|
39 |
ultimately have "u *\<^sub>R x + v *\<^sub>R y \<in> s" |
|
40 |
using alt[OF mem] by auto |
|
41 |
} |
|
42 |
then show "convex s" |
|
43 |
unfolding convex_def by auto |
|
36623 | 44 |
qed (auto simp: convex_def) |
45 |
||
61426
d53db136e8fd
new material on path_component_sets, inside, outside, etc. And more default simprules
paulson <lp15@cam.ac.uk>
parents:
61070
diff
changeset
|
46 |
lemma convexD_alt: |
36623 | 47 |
assumes "convex s" "a \<in> s" "b \<in> s" "0 \<le> u" "u \<le> 1" |
48 |
shows "((1 - u) *\<^sub>R a + u *\<^sub>R b) \<in> s" |
|
49 |
using assms unfolding convex_alt by auto |
|
50 |
||
60303 | 51 |
lemma convex_empty[intro,simp]: "convex {}" |
36623 | 52 |
unfolding convex_def by simp |
53 |
||
60303 | 54 |
lemma convex_singleton[intro,simp]: "convex {a}" |
36623 | 55 |
unfolding convex_def by (auto simp: scaleR_left_distrib[symmetric]) |
56 |
||
60303 | 57 |
lemma convex_UNIV[intro,simp]: "convex UNIV" |
36623 | 58 |
unfolding convex_def by auto |
59 |
||
60423 | 60 |
lemma convex_Inter: "(\<forall>s\<in>f. convex s) \<Longrightarrow> convex(\<Inter>f)" |
36623 | 61 |
unfolding convex_def by auto |
62 |
||
63 |
lemma convex_Int: "convex s \<Longrightarrow> convex t \<Longrightarrow> convex (s \<inter> t)" |
|
64 |
unfolding convex_def by auto |
|
65 |
||
53596 | 66 |
lemma convex_INT: "\<forall>i\<in>A. convex (B i) \<Longrightarrow> convex (\<Inter>i\<in>A. B i)" |
67 |
unfolding convex_def by auto |
|
68 |
||
69 |
lemma convex_Times: "convex s \<Longrightarrow> convex t \<Longrightarrow> convex (s \<times> t)" |
|
70 |
unfolding convex_def by auto |
|
71 |
||
36623 | 72 |
lemma convex_halfspace_le: "convex {x. inner a x \<le> b}" |
73 |
unfolding convex_def |
|
44142 | 74 |
by (auto simp: inner_add intro!: convex_bound_le) |
36623 | 75 |
|
76 |
lemma convex_halfspace_ge: "convex {x. inner a x \<ge> b}" |
|
77 |
proof - |
|
56796 | 78 |
have *: "{x. inner a x \<ge> b} = {x. inner (-a) x \<le> -b}" |
79 |
by auto |
|
80 |
show ?thesis |
|
81 |
unfolding * using convex_halfspace_le[of "-a" "-b"] by auto |
|
36623 | 82 |
qed |
83 |
||
84 |
lemma convex_hyperplane: "convex {x. inner a x = b}" |
|
49609 | 85 |
proof - |
56796 | 86 |
have *: "{x. inner a x = b} = {x. inner a x \<le> b} \<inter> {x. inner a x \<ge> b}" |
87 |
by auto |
|
36623 | 88 |
show ?thesis using convex_halfspace_le convex_halfspace_ge |
89 |
by (auto intro!: convex_Int simp: *) |
|
90 |
qed |
|
91 |
||
92 |
lemma convex_halfspace_lt: "convex {x. inner a x < b}" |
|
93 |
unfolding convex_def |
|
94 |
by (auto simp: convex_bound_lt inner_add) |
|
95 |
||
96 |
lemma convex_halfspace_gt: "convex {x. inner a x > b}" |
|
97 |
using convex_halfspace_lt[of "-a" "-b"] by auto |
|
98 |
||
61518
ff12606337e9
new lemmas about topology, etc., for Cauchy integral formula
paulson
parents:
61426
diff
changeset
|
99 |
lemma convex_real_interval [iff]: |
36623 | 100 |
fixes a b :: "real" |
101 |
shows "convex {a..}" and "convex {..b}" |
|
49609 | 102 |
and "convex {a<..}" and "convex {..<b}" |
103 |
and "convex {a..b}" and "convex {a<..b}" |
|
104 |
and "convex {a..<b}" and "convex {a<..<b}" |
|
36623 | 105 |
proof - |
60423 | 106 |
have "{a..} = {x. a \<le> inner 1 x}" |
107 |
by auto |
|
108 |
then show 1: "convex {a..}" |
|
109 |
by (simp only: convex_halfspace_ge) |
|
110 |
have "{..b} = {x. inner 1 x \<le> b}" |
|
111 |
by auto |
|
112 |
then show 2: "convex {..b}" |
|
113 |
by (simp only: convex_halfspace_le) |
|
114 |
have "{a<..} = {x. a < inner 1 x}" |
|
115 |
by auto |
|
116 |
then show 3: "convex {a<..}" |
|
117 |
by (simp only: convex_halfspace_gt) |
|
118 |
have "{..<b} = {x. inner 1 x < b}" |
|
119 |
by auto |
|
120 |
then show 4: "convex {..<b}" |
|
121 |
by (simp only: convex_halfspace_lt) |
|
122 |
have "{a..b} = {a..} \<inter> {..b}" |
|
123 |
by auto |
|
124 |
then show "convex {a..b}" |
|
125 |
by (simp only: convex_Int 1 2) |
|
126 |
have "{a<..b} = {a<..} \<inter> {..b}" |
|
127 |
by auto |
|
128 |
then show "convex {a<..b}" |
|
129 |
by (simp only: convex_Int 3 2) |
|
130 |
have "{a..<b} = {a..} \<inter> {..<b}" |
|
131 |
by auto |
|
132 |
then show "convex {a..<b}" |
|
133 |
by (simp only: convex_Int 1 4) |
|
134 |
have "{a<..<b} = {a<..} \<inter> {..<b}" |
|
135 |
by auto |
|
136 |
then show "convex {a<..<b}" |
|
137 |
by (simp only: convex_Int 3 4) |
|
36623 | 138 |
qed |
139 |
||
61070 | 140 |
lemma convex_Reals: "convex \<real>" |
59862 | 141 |
by (simp add: convex_def scaleR_conv_of_real) |
60423 | 142 |
|
143 |
||
144 |
subsection \<open>Explicit expressions for convexity in terms of arbitrary sums\<close> |
|
36623 | 145 |
|
146 |
lemma convex_setsum: |
|
147 |
fixes C :: "'a::real_vector set" |
|
56796 | 148 |
assumes "finite s" |
149 |
and "convex C" |
|
150 |
and "(\<Sum> i \<in> s. a i) = 1" |
|
151 |
assumes "\<And>i. i \<in> s \<Longrightarrow> a i \<ge> 0" |
|
152 |
and "\<And>i. i \<in> s \<Longrightarrow> y i \<in> C" |
|
36623 | 153 |
shows "(\<Sum> j \<in> s. a j *\<^sub>R y j) \<in> C" |
55909 | 154 |
using assms(1,3,4,5) |
155 |
proof (induct arbitrary: a set: finite) |
|
49609 | 156 |
case empty |
55909 | 157 |
then show ?case by simp |
36623 | 158 |
next |
55909 | 159 |
case (insert i s) note IH = this(3) |
56796 | 160 |
have "a i + setsum a s = 1" |
161 |
and "0 \<le> a i" |
|
162 |
and "\<forall>j\<in>s. 0 \<le> a j" |
|
163 |
and "y i \<in> C" |
|
164 |
and "\<forall>j\<in>s. y j \<in> C" |
|
55909 | 165 |
using insert.hyps(1,2) insert.prems by simp_all |
56796 | 166 |
then have "0 \<le> setsum a s" |
167 |
by (simp add: setsum_nonneg) |
|
55909 | 168 |
have "a i *\<^sub>R y i + (\<Sum>j\<in>s. a j *\<^sub>R y j) \<in> C" |
169 |
proof (cases) |
|
170 |
assume z: "setsum a s = 0" |
|
60423 | 171 |
with \<open>a i + setsum a s = 1\<close> have "a i = 1" |
56796 | 172 |
by simp |
60423 | 173 |
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" |
56796 | 174 |
by simp |
60423 | 175 |
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> |
56796 | 176 |
by simp |
55909 | 177 |
next |
178 |
assume nz: "setsum a s \<noteq> 0" |
|
60423 | 179 |
with \<open>0 \<le> setsum a s\<close> have "0 < setsum a s" |
56796 | 180 |
by simp |
55909 | 181 |
then have "(\<Sum>j\<in>s. (a j / setsum a s) *\<^sub>R y j) \<in> C" |
60423 | 182 |
using \<open>\<forall>j\<in>s. 0 \<le> a j\<close> and \<open>\<forall>j\<in>s. y j \<in> C\<close> |
56571
f4635657d66f
added divide_nonneg_nonneg and co; made it a simp rule
hoelzl
parents:
56544
diff
changeset
|
183 |
by (simp add: IH setsum_divide_distrib [symmetric]) |
60423 | 184 |
from \<open>convex C\<close> and \<open>y i \<in> C\<close> and this and \<open>0 \<le> a i\<close> |
185 |
and \<open>0 \<le> setsum a s\<close> and \<open>a i + setsum a s = 1\<close> |
|
55909 | 186 |
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" |
187 |
by (rule convexD) |
|
56796 | 188 |
then show ?thesis |
189 |
by (simp add: scaleR_setsum_right nz) |
|
55909 | 190 |
qed |
60423 | 191 |
then show ?case using \<open>finite s\<close> and \<open>i \<notin> s\<close> |
56796 | 192 |
by simp |
36623 | 193 |
qed |
194 |
||
195 |
lemma convex: |
|
49609 | 196 |
"convex s \<longleftrightarrow> (\<forall>(k::nat) u x. (\<forall>i. 1\<le>i \<and> i\<le>k \<longrightarrow> 0 \<le> u i \<and> x i \<in>s) \<and> (setsum u {1..k} = 1) |
197 |
\<longrightarrow> setsum (\<lambda>i. u i *\<^sub>R x i) {1..k} \<in> s)" |
|
36623 | 198 |
proof safe |
49609 | 199 |
fix k :: nat |
200 |
fix u :: "nat \<Rightarrow> real" |
|
201 |
fix x |
|
36623 | 202 |
assume "convex s" |
203 |
"\<forall>i. 1 \<le> i \<and> i \<le> k \<longrightarrow> 0 \<le> u i \<and> x i \<in> s" |
|
204 |
"setsum u {1..k} = 1" |
|
60423 | 205 |
with convex_setsum[of "{1 .. k}" s] show "(\<Sum>j\<in>{1 .. k}. u j *\<^sub>R x j) \<in> s" |
56796 | 206 |
by auto |
36623 | 207 |
next |
60423 | 208 |
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 |
36623 | 209 |
\<longrightarrow> (\<Sum>i = 1..k. u i *\<^sub>R (x i :: 'a)) \<in> s" |
56796 | 210 |
{ |
211 |
fix \<mu> :: real |
|
49609 | 212 |
fix x y :: 'a |
213 |
assume xy: "x \<in> s" "y \<in> s" |
|
214 |
assume mu: "\<mu> \<ge> 0" "\<mu> \<le> 1" |
|
215 |
let ?u = "\<lambda>i. if (i :: nat) = 1 then \<mu> else 1 - \<mu>" |
|
216 |
let ?x = "\<lambda>i. if (i :: nat) = 1 then x else y" |
|
56796 | 217 |
have "{1 :: nat .. 2} \<inter> - {x. x = 1} = {2}" |
218 |
by auto |
|
219 |
then have card: "card ({1 :: nat .. 2} \<inter> - {x. x = 1}) = 1" |
|
220 |
by simp |
|
49609 | 221 |
then have "setsum ?u {1 .. 2} = 1" |
57418 | 222 |
using setsum.If_cases[of "{(1 :: nat) .. 2}" "\<lambda> x. x = 1" "\<lambda> x. \<mu>" "\<lambda> x. 1 - \<mu>"] |
36623 | 223 |
by auto |
60423 | 224 |
with *[rule_format, of "2" ?u ?x] have s: "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) \<in> s" |
36623 | 225 |
using mu xy by auto |
226 |
have grarr: "(\<Sum>j \<in> {Suc (Suc 0)..2}. ?u j *\<^sub>R ?x j) = (1 - \<mu>) *\<^sub>R y" |
|
227 |
using setsum_head_Suc[of "Suc (Suc 0)" 2 "\<lambda> j. (1 - \<mu>) *\<^sub>R y"] by auto |
|
228 |
from setsum_head_Suc[of "Suc 0" 2 "\<lambda> j. ?u j *\<^sub>R ?x j", simplified this] |
|
56796 | 229 |
have "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) = \<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y" |
230 |
by auto |
|
231 |
then have "(1 - \<mu>) *\<^sub>R y + \<mu> *\<^sub>R x \<in> s" |
|
60423 | 232 |
using s by (auto simp: add.commute) |
49609 | 233 |
} |
56796 | 234 |
then show "convex s" |
235 |
unfolding convex_alt by auto |
|
36623 | 236 |
qed |
237 |
||
238 |
||
239 |
lemma convex_explicit: |
|
240 |
fixes s :: "'a::real_vector set" |
|
241 |
shows "convex s \<longleftrightarrow> |
|
49609 | 242 |
(\<forall>t u. finite t \<and> t \<subseteq> s \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and> setsum u t = 1 \<longrightarrow> setsum (\<lambda>x. u x *\<^sub>R x) t \<in> s)" |
36623 | 243 |
proof safe |
49609 | 244 |
fix t |
245 |
fix u :: "'a \<Rightarrow> real" |
|
56796 | 246 |
assume "convex s" |
247 |
and "finite t" |
|
248 |
and "t \<subseteq> s" "\<forall>x\<in>t. 0 \<le> u x" "setsum u t = 1" |
|
49609 | 249 |
then show "(\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s" |
36623 | 250 |
using convex_setsum[of t s u "\<lambda> x. x"] by auto |
251 |
next |
|
60423 | 252 |
assume *: "\<forall>t. \<forall> u. finite t \<and> t \<subseteq> s \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and> |
56796 | 253 |
setsum u t = 1 \<longrightarrow> (\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s" |
36623 | 254 |
show "convex s" |
255 |
unfolding convex_alt |
|
256 |
proof safe |
|
49609 | 257 |
fix x y |
258 |
fix \<mu> :: real |
|
60423 | 259 |
assume **: "x \<in> s" "y \<in> s" "0 \<le> \<mu>" "\<mu> \<le> 1" |
260 |
show "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s" |
|
261 |
proof (cases "x = y") |
|
262 |
case False |
|
263 |
then show ?thesis |
|
264 |
using *[rule_format, of "{x, y}" "\<lambda> z. if z = x then 1 - \<mu> else \<mu>"] ** |
|
265 |
by auto |
|
266 |
next |
|
267 |
case True |
|
268 |
then show ?thesis |
|
269 |
using *[rule_format, of "{x, y}" "\<lambda> z. 1"] ** |
|
270 |
by (auto simp: field_simps real_vector.scale_left_diff_distrib) |
|
271 |
qed |
|
36623 | 272 |
qed |
273 |
qed |
|
274 |
||
49609 | 275 |
lemma convex_finite: |
276 |
assumes "finite s" |
|
56796 | 277 |
shows "convex s \<longleftrightarrow> (\<forall>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<longrightarrow> setsum (\<lambda>x. u x *\<^sub>R x) s \<in> s)" |
36623 | 278 |
unfolding convex_explicit |
49609 | 279 |
proof safe |
280 |
fix t u |
|
281 |
assume sum: "\<forall>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<longrightarrow> (\<Sum>x\<in>s. u x *\<^sub>R x) \<in> s" |
|
36623 | 282 |
and as: "finite t" "t \<subseteq> s" "\<forall>x\<in>t. 0 \<le> u x" "setsum u t = (1::real)" |
56796 | 283 |
have *: "s \<inter> t = t" |
284 |
using as(2) by auto |
|
49609 | 285 |
have if_distrib_arg: "\<And>P f g x. (if P then f else g) x = (if P then f x else g x)" |
286 |
by simp |
|
36623 | 287 |
show "(\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s" |
288 |
using sum[THEN spec[where x="\<lambda>x. if x\<in>t then u x else 0"]] as * |
|
57418 | 289 |
by (auto simp: assms setsum.If_cases if_distrib if_distrib_arg) |
36623 | 290 |
qed (erule_tac x=s in allE, erule_tac x=u in allE, auto) |
291 |
||
56796 | 292 |
|
60423 | 293 |
subsection \<open>Functions that are convex on a set\<close> |
55909 | 294 |
|
49609 | 295 |
definition convex_on :: "'a::real_vector set \<Rightarrow> ('a \<Rightarrow> real) \<Rightarrow> bool" |
296 |
where "convex_on s f \<longleftrightarrow> |
|
297 |
(\<forall>x\<in>s. \<forall>y\<in>s. \<forall>u\<ge>0. \<forall>v\<ge>0. u + v = 1 \<longrightarrow> f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y)" |
|
36623 | 298 |
|
299 |
lemma convex_on_subset: "convex_on t f \<Longrightarrow> s \<subseteq> t \<Longrightarrow> convex_on s f" |
|
300 |
unfolding convex_on_def by auto |
|
301 |
||
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
302 |
lemma convex_on_add [intro]: |
56796 | 303 |
assumes "convex_on s f" |
304 |
and "convex_on s g" |
|
36623 | 305 |
shows "convex_on s (\<lambda>x. f x + g x)" |
49609 | 306 |
proof - |
56796 | 307 |
{ |
308 |
fix x y |
|
309 |
assume "x \<in> s" "y \<in> s" |
|
49609 | 310 |
moreover |
311 |
fix u v :: real |
|
312 |
assume "0 \<le> u" "0 \<le> v" "u + v = 1" |
|
313 |
ultimately |
|
314 |
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)" |
|
60423 | 315 |
using assms unfolding convex_on_def by (auto simp: add_mono) |
49609 | 316 |
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)" |
317 |
by (simp add: field_simps) |
|
318 |
} |
|
56796 | 319 |
then show ?thesis |
320 |
unfolding convex_on_def by auto |
|
36623 | 321 |
qed |
322 |
||
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
323 |
lemma convex_on_cmul [intro]: |
56796 | 324 |
fixes c :: real |
325 |
assumes "0 \<le> c" |
|
326 |
and "convex_on s f" |
|
36623 | 327 |
shows "convex_on s (\<lambda>x. c * f x)" |
56796 | 328 |
proof - |
60423 | 329 |
have *: "\<And>u c fx v fy :: real. u * (c * fx) + v * (c * fy) = c * (u * fx + v * fy)" |
49609 | 330 |
by (simp add: field_simps) |
331 |
show ?thesis using assms(2) and mult_left_mono [OF _ assms(1)] |
|
332 |
unfolding convex_on_def and * by auto |
|
36623 | 333 |
qed |
334 |
||
335 |
lemma convex_lower: |
|
56796 | 336 |
assumes "convex_on s f" |
337 |
and "x \<in> s" |
|
338 |
and "y \<in> s" |
|
339 |
and "0 \<le> u" |
|
340 |
and "0 \<le> v" |
|
341 |
and "u + v = 1" |
|
36623 | 342 |
shows "f (u *\<^sub>R x + v *\<^sub>R y) \<le> max (f x) (f y)" |
56796 | 343 |
proof - |
36623 | 344 |
let ?m = "max (f x) (f y)" |
345 |
have "u * f x + v * f y \<le> u * max (f x) (f y) + v * max (f x) (f y)" |
|
60423 | 346 |
using assms(4,5) by (auto simp: mult_left_mono add_mono) |
56796 | 347 |
also have "\<dots> = max (f x) (f y)" |
60423 | 348 |
using assms(6) by (simp add: distrib_right [symmetric]) |
36623 | 349 |
finally show ?thesis |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44282
diff
changeset
|
350 |
using assms unfolding convex_on_def by fastforce |
36623 | 351 |
qed |
352 |
||
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
353 |
lemma convex_on_dist [intro]: |
36623 | 354 |
fixes s :: "'a::real_normed_vector set" |
355 |
shows "convex_on s (\<lambda>x. dist a x)" |
|
60423 | 356 |
proof (auto simp: convex_on_def dist_norm) |
49609 | 357 |
fix x y |
56796 | 358 |
assume "x \<in> s" "y \<in> s" |
49609 | 359 |
fix u v :: real |
56796 | 360 |
assume "0 \<le> u" |
361 |
assume "0 \<le> v" |
|
362 |
assume "u + v = 1" |
|
49609 | 363 |
have "a = u *\<^sub>R a + v *\<^sub>R a" |
60423 | 364 |
unfolding scaleR_left_distrib[symmetric] and \<open>u + v = 1\<close> by simp |
49609 | 365 |
then have *: "a - (u *\<^sub>R x + v *\<^sub>R y) = (u *\<^sub>R (a - x)) + (v *\<^sub>R (a - y))" |
60423 | 366 |
by (auto simp: algebra_simps) |
36623 | 367 |
show "norm (a - (u *\<^sub>R x + v *\<^sub>R y)) \<le> u * norm (a - x) + v * norm (a - y)" |
368 |
unfolding * using norm_triangle_ineq[of "u *\<^sub>R (a - x)" "v *\<^sub>R (a - y)"] |
|
60423 | 369 |
using \<open>0 \<le> u\<close> \<open>0 \<le> v\<close> by auto |
36623 | 370 |
qed |
371 |
||
49609 | 372 |
|
60423 | 373 |
subsection \<open>Arithmetic operations on sets preserve convexity\<close> |
49609 | 374 |
|
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
375 |
lemma convex_linear_image: |
56796 | 376 |
assumes "linear f" |
377 |
and "convex s" |
|
378 |
shows "convex (f ` s)" |
|
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
379 |
proof - |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
380 |
interpret f: linear f by fact |
60423 | 381 |
from \<open>convex s\<close> show "convex (f ` s)" |
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
382 |
by (simp add: convex_def f.scaleR [symmetric] f.add [symmetric]) |
36623 | 383 |
qed |
384 |
||
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
385 |
lemma convex_linear_vimage: |
56796 | 386 |
assumes "linear f" |
387 |
and "convex s" |
|
388 |
shows "convex (f -` s)" |
|
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
389 |
proof - |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
390 |
interpret f: linear f by fact |
60423 | 391 |
from \<open>convex s\<close> show "convex (f -` s)" |
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
392 |
by (simp add: convex_def f.add f.scaleR) |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
393 |
qed |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
394 |
|
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
395 |
lemma convex_scaling: |
56796 | 396 |
assumes "convex s" |
397 |
shows "convex ((\<lambda>x. c *\<^sub>R x) ` s)" |
|
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
398 |
proof - |
56796 | 399 |
have "linear (\<lambda>x. c *\<^sub>R x)" |
400 |
by (simp add: linearI scaleR_add_right) |
|
401 |
then show ?thesis |
|
60423 | 402 |
using \<open>convex s\<close> by (rule convex_linear_image) |
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
403 |
qed |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
404 |
|
60178
f620c70f9e9b
generalized differentiable_bound; some further variations of differentiable_bound
immler
parents:
59862
diff
changeset
|
405 |
lemma convex_scaled: |
f620c70f9e9b
generalized differentiable_bound; some further variations of differentiable_bound
immler
parents:
59862
diff
changeset
|
406 |
assumes "convex s" |
f620c70f9e9b
generalized differentiable_bound; some further variations of differentiable_bound
immler
parents:
59862
diff
changeset
|
407 |
shows "convex ((\<lambda>x. x *\<^sub>R c) ` s)" |
f620c70f9e9b
generalized differentiable_bound; some further variations of differentiable_bound
immler
parents:
59862
diff
changeset
|
408 |
proof - |
f620c70f9e9b
generalized differentiable_bound; some further variations of differentiable_bound
immler
parents:
59862
diff
changeset
|
409 |
have "linear (\<lambda>x. x *\<^sub>R c)" |
f620c70f9e9b
generalized differentiable_bound; some further variations of differentiable_bound
immler
parents:
59862
diff
changeset
|
410 |
by (simp add: linearI scaleR_add_left) |
f620c70f9e9b
generalized differentiable_bound; some further variations of differentiable_bound
immler
parents:
59862
diff
changeset
|
411 |
then show ?thesis |
60423 | 412 |
using \<open>convex s\<close> by (rule convex_linear_image) |
60178
f620c70f9e9b
generalized differentiable_bound; some further variations of differentiable_bound
immler
parents:
59862
diff
changeset
|
413 |
qed |
f620c70f9e9b
generalized differentiable_bound; some further variations of differentiable_bound
immler
parents:
59862
diff
changeset
|
414 |
|
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
415 |
lemma convex_negations: |
56796 | 416 |
assumes "convex s" |
417 |
shows "convex ((\<lambda>x. - x) ` s)" |
|
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
418 |
proof - |
56796 | 419 |
have "linear (\<lambda>x. - x)" |
420 |
by (simp add: linearI) |
|
421 |
then show ?thesis |
|
60423 | 422 |
using \<open>convex s\<close> by (rule convex_linear_image) |
36623 | 423 |
qed |
424 |
||
425 |
lemma convex_sums: |
|
56796 | 426 |
assumes "convex s" |
427 |
and "convex t" |
|
36623 | 428 |
shows "convex {x + y| x y. x \<in> s \<and> y \<in> t}" |
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
429 |
proof - |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
430 |
have "linear (\<lambda>(x, y). x + y)" |
60423 | 431 |
by (auto intro: linearI simp: scaleR_add_right) |
53620
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
432 |
with assms have "convex ((\<lambda>(x, y). x + y) ` (s \<times> t))" |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
433 |
by (intro convex_linear_image convex_Times) |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
434 |
also have "((\<lambda>(x, y). x + y) ` (s \<times> t)) = {x + y| x y. x \<in> s \<and> y \<in> t}" |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
435 |
by auto |
3c7f5e7926dc
generalized and simplified proofs of several theorems about convex sets
huffman
parents:
53596
diff
changeset
|
436 |
finally show ?thesis . |
36623 | 437 |
qed |
438 |
||
439 |
lemma convex_differences: |
|
440 |
assumes "convex s" "convex t" |
|
441 |
shows "convex {x - y| x y. x \<in> s \<and> y \<in> t}" |
|
442 |
proof - |
|
443 |
have "{x - y| x y. x \<in> s \<and> y \<in> t} = {x + y |x y. x \<in> s \<and> y \<in> uminus ` t}" |
|
60423 | 444 |
by (auto simp: diff_conv_add_uminus simp del: add_uminus_conv_diff) |
49609 | 445 |
then show ?thesis |
446 |
using convex_sums[OF assms(1) convex_negations[OF assms(2)]] by auto |
|
36623 | 447 |
qed |
448 |
||
49609 | 449 |
lemma convex_translation: |
450 |
assumes "convex s" |
|
451 |
shows "convex ((\<lambda>x. a + x) ` s)" |
|
452 |
proof - |
|
56796 | 453 |
have "{a + y |y. y \<in> s} = (\<lambda>x. a + x) ` s" |
454 |
by auto |
|
49609 | 455 |
then show ?thesis |
456 |
using convex_sums[OF convex_singleton[of a] assms] by auto |
|
457 |
qed |
|
36623 | 458 |
|
49609 | 459 |
lemma convex_affinity: |
460 |
assumes "convex s" |
|
461 |
shows "convex ((\<lambda>x. a + c *\<^sub>R x) ` s)" |
|
462 |
proof - |
|
56796 | 463 |
have "(\<lambda>x. a + c *\<^sub>R x) ` s = op + a ` op *\<^sub>R c ` s" |
464 |
by auto |
|
49609 | 465 |
then show ?thesis |
466 |
using convex_translation[OF convex_scaling[OF assms], of a c] by auto |
|
467 |
qed |
|
36623 | 468 |
|
49609 | 469 |
lemma pos_is_convex: "convex {0 :: real <..}" |
470 |
unfolding convex_alt |
|
36623 | 471 |
proof safe |
472 |
fix y x \<mu> :: real |
|
60423 | 473 |
assume *: "y > 0" "x > 0" "\<mu> \<ge> 0" "\<mu> \<le> 1" |
56796 | 474 |
{ |
475 |
assume "\<mu> = 0" |
|
49609 | 476 |
then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y = y" by simp |
60423 | 477 |
then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using * by simp |
56796 | 478 |
} |
36623 | 479 |
moreover |
56796 | 480 |
{ |
481 |
assume "\<mu> = 1" |
|
60423 | 482 |
then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using * by simp |
56796 | 483 |
} |
36623 | 484 |
moreover |
56796 | 485 |
{ |
486 |
assume "\<mu> \<noteq> 1" "\<mu> \<noteq> 0" |
|
60423 | 487 |
then have "\<mu> > 0" "(1 - \<mu>) > 0" using * by auto |
488 |
then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using * |
|
489 |
by (auto simp: add_pos_pos) |
|
56796 | 490 |
} |
491 |
ultimately show "(1 - \<mu>) *\<^sub>R y + \<mu> *\<^sub>R x > 0" |
|
492 |
using assms by fastforce |
|
36623 | 493 |
qed |
494 |
||
495 |
lemma convex_on_setsum: |
|
496 |
fixes a :: "'a \<Rightarrow> real" |
|
49609 | 497 |
and y :: "'a \<Rightarrow> 'b::real_vector" |
498 |
and f :: "'b \<Rightarrow> real" |
|
36623 | 499 |
assumes "finite s" "s \<noteq> {}" |
49609 | 500 |
and "convex_on C f" |
501 |
and "convex C" |
|
502 |
and "(\<Sum> i \<in> s. a i) = 1" |
|
503 |
and "\<And>i. i \<in> s \<Longrightarrow> a i \<ge> 0" |
|
504 |
and "\<And>i. i \<in> s \<Longrightarrow> y i \<in> C" |
|
36623 | 505 |
shows "f (\<Sum> i \<in> s. a i *\<^sub>R y i) \<le> (\<Sum> i \<in> s. a i * f (y i))" |
49609 | 506 |
using assms |
507 |
proof (induct s arbitrary: a rule: finite_ne_induct) |
|
36623 | 508 |
case (singleton i) |
49609 | 509 |
then have ai: "a i = 1" by auto |
510 |
then show ?case by auto |
|
36623 | 511 |
next |
60423 | 512 |
case (insert i s) |
49609 | 513 |
then have "convex_on C f" by simp |
36623 | 514 |
from this[unfolded convex_on_def, rule_format] |
56796 | 515 |
have conv: "\<And>x y \<mu>. x \<in> C \<Longrightarrow> y \<in> C \<Longrightarrow> 0 \<le> \<mu> \<Longrightarrow> \<mu> \<le> 1 \<Longrightarrow> |
516 |
f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y" |
|
36623 | 517 |
by simp |
60423 | 518 |
show ?case |
519 |
proof (cases "a i = 1") |
|
520 |
case True |
|
49609 | 521 |
then have "(\<Sum> j \<in> s. a j) = 0" |
60423 | 522 |
using insert by auto |
49609 | 523 |
then have "\<And>j. j \<in> s \<Longrightarrow> a j = 0" |
60423 | 524 |
using setsum_nonneg_0[where 'b=real] insert by fastforce |
525 |
then show ?thesis |
|
526 |
using insert by auto |
|
527 |
next |
|
528 |
case False |
|
529 |
from insert have yai: "y i \<in> C" "a i \<ge> 0" |
|
530 |
by auto |
|
531 |
have fis: "finite (insert i s)" |
|
532 |
using insert by auto |
|
533 |
then have ai1: "a i \<le> 1" |
|
534 |
using setsum_nonneg_leq_bound[of "insert i s" a] insert by simp |
|
535 |
then have "a i < 1" |
|
536 |
using False by auto |
|
537 |
then have i0: "1 - a i > 0" |
|
538 |
by auto |
|
49609 | 539 |
let ?a = "\<lambda>j. a j / (1 - a i)" |
60423 | 540 |
have a_nonneg: "?a j \<ge> 0" if "j \<in> s" for j |
60449 | 541 |
using i0 insert that by fastforce |
60423 | 542 |
have "(\<Sum> j \<in> insert i s. a j) = 1" |
543 |
using insert by auto |
|
544 |
then have "(\<Sum> j \<in> s. a j) = 1 - a i" |
|
545 |
using setsum.insert insert by fastforce |
|
546 |
then have "(\<Sum> j \<in> s. a j) / (1 - a i) = 1" |
|
547 |
using i0 by auto |
|
548 |
then have a1: "(\<Sum> j \<in> s. ?a j) = 1" |
|
549 |
unfolding setsum_divide_distrib by simp |
|
550 |
have "convex C" using insert by auto |
|
49609 | 551 |
then have asum: "(\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<in> C" |
60423 | 552 |
using insert convex_setsum[OF \<open>finite s\<close> |
553 |
\<open>convex C\<close> a1 a_nonneg] by auto |
|
36623 | 554 |
have asum_le: "f (\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<le> (\<Sum> j \<in> s. ?a j * f (y j))" |
60423 | 555 |
using a_nonneg a1 insert by blast |
36623 | 556 |
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)" |
60423 | 557 |
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 |
558 |
by (auto simp only: add.commute) |
|
36623 | 559 |
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)" |
560 |
using i0 by auto |
|
561 |
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)" |
|
49609 | 562 |
using scaleR_right.setsum[of "inverse (1 - a i)" "\<lambda> j. a j *\<^sub>R y j" s, symmetric] |
60423 | 563 |
by (auto simp: algebra_simps) |
36623 | 564 |
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)" |
36778
739a9379e29b
avoid using real-specific versions of generic lemmas
huffman
parents:
36648
diff
changeset
|
565 |
by (auto simp: divide_inverse) |
36623 | 566 |
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)" |
567 |
using conv[of "y i" "(\<Sum> j \<in> s. ?a j *\<^sub>R y j)" "a i", OF yai(1) asum yai(2) ai1] |
|
60423 | 568 |
by (auto simp: add.commute) |
36623 | 569 |
also have "\<dots> \<le> (1 - a i) * (\<Sum> j \<in> s. ?a j * f (y j)) + a i * f (y i)" |
570 |
using add_right_mono[OF mult_left_mono[of _ _ "1 - a i", |
|
571 |
OF asum_le less_imp_le[OF i0]], of "a i * f (y i)"] by simp |
|
572 |
also have "\<dots> = (\<Sum> j \<in> s. (1 - a i) * ?a j * f (y j)) + a i * f (y i)" |
|
44282
f0de18b62d63
remove bounded_(bi)linear locale interpretations, to avoid duplicating so many lemmas
huffman
parents:
44142
diff
changeset
|
573 |
unfolding setsum_right_distrib[of "1 - a i" "\<lambda> j. ?a j * f (y j)"] using i0 by auto |
60423 | 574 |
also have "\<dots> = (\<Sum> j \<in> s. a j * f (y j)) + a i * f (y i)" |
575 |
using i0 by auto |
|
576 |
also have "\<dots> = (\<Sum> j \<in> insert i s. a j * f (y j))" |
|
577 |
using insert by auto |
|
578 |
finally show ?thesis |
|
56796 | 579 |
by simp |
60423 | 580 |
qed |
36623 | 581 |
qed |
582 |
||
583 |
lemma convex_on_alt: |
|
584 |
fixes C :: "'a::real_vector set" |
|
585 |
assumes "convex C" |
|
56796 | 586 |
shows "convex_on C f \<longleftrightarrow> |
587 |
(\<forall>x \<in> C. \<forall> y \<in> C. \<forall> \<mu> :: real. \<mu> \<ge> 0 \<and> \<mu> \<le> 1 \<longrightarrow> |
|
588 |
f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y)" |
|
36623 | 589 |
proof safe |
49609 | 590 |
fix x y |
591 |
fix \<mu> :: real |
|
60423 | 592 |
assume *: "convex_on C f" "x \<in> C" "y \<in> C" "0 \<le> \<mu>" "\<mu> \<le> 1" |
36623 | 593 |
from this[unfolded convex_on_def, rule_format] |
56796 | 594 |
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" |
595 |
by auto |
|
60423 | 596 |
from this[of "\<mu>" "1 - \<mu>", simplified] * |
56796 | 597 |
show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y" |
598 |
by auto |
|
36623 | 599 |
next |
60423 | 600 |
assume *: "\<forall>x\<in>C. \<forall>y\<in>C. \<forall>\<mu>. 0 \<le> \<mu> \<and> \<mu> \<le> 1 \<longrightarrow> |
56796 | 601 |
f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y" |
602 |
{ |
|
603 |
fix x y |
|
49609 | 604 |
fix u v :: real |
60423 | 605 |
assume **: "x \<in> C" "y \<in> C" "u \<ge> 0" "v \<ge> 0" "u + v = 1" |
49609 | 606 |
then have[simp]: "1 - u = v" by auto |
60423 | 607 |
from *[rule_format, of x y u] |
56796 | 608 |
have "f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y" |
60423 | 609 |
using ** by auto |
49609 | 610 |
} |
56796 | 611 |
then show "convex_on C f" |
612 |
unfolding convex_on_def by auto |
|
36623 | 613 |
qed |
614 |
||
43337 | 615 |
lemma convex_on_diff: |
616 |
fixes f :: "real \<Rightarrow> real" |
|
56796 | 617 |
assumes f: "convex_on I f" |
618 |
and I: "x \<in> I" "y \<in> I" |
|
619 |
and t: "x < t" "t < y" |
|
49609 | 620 |
shows "(f x - f t) / (x - t) \<le> (f x - f y) / (x - y)" |
56796 | 621 |
and "(f x - f y) / (x - y) \<le> (f t - f y) / (t - y)" |
43337 | 622 |
proof - |
623 |
def a \<equiv> "(t - y) / (x - y)" |
|
56796 | 624 |
with t have "0 \<le> a" "0 \<le> 1 - a" |
625 |
by (auto simp: field_simps) |
|
60423 | 626 |
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" |
43337 | 627 |
by (auto simp: convex_on_def) |
56796 | 628 |
have "a * x + (1 - a) * y = a * (x - y) + y" |
629 |
by (simp add: field_simps) |
|
630 |
also have "\<dots> = t" |
|
60423 | 631 |
unfolding a_def using \<open>x < t\<close> \<open>t < y\<close> by simp |
56796 | 632 |
finally have "f t \<le> a * f x + (1 - a) * f y" |
633 |
using cvx by simp |
|
634 |
also have "\<dots> = a * (f x - f y) + f y" |
|
635 |
by (simp add: field_simps) |
|
636 |
finally have "f t - f y \<le> a * (f x - f y)" |
|
637 |
by simp |
|
43337 | 638 |
with t show "(f x - f t) / (x - t) \<le> (f x - f y) / (x - y)" |
44142 | 639 |
by (simp add: le_divide_eq divide_le_eq field_simps a_def) |
43337 | 640 |
with t show "(f x - f y) / (x - y) \<le> (f t - f y) / (t - y)" |
44142 | 641 |
by (simp add: le_divide_eq divide_le_eq field_simps) |
43337 | 642 |
qed |
36623 | 643 |
|
644 |
lemma pos_convex_function: |
|
645 |
fixes f :: "real \<Rightarrow> real" |
|
646 |
assumes "convex C" |
|
56796 | 647 |
and leq: "\<And>x y. x \<in> C \<Longrightarrow> y \<in> C \<Longrightarrow> f' x * (y - x) \<le> f y - f x" |
36623 | 648 |
shows "convex_on C f" |
49609 | 649 |
unfolding convex_on_alt[OF assms(1)] |
650 |
using assms |
|
36623 | 651 |
proof safe |
652 |
fix x y \<mu> :: real |
|
653 |
let ?x = "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y" |
|
60423 | 654 |
assume *: "convex C" "x \<in> C" "y \<in> C" "\<mu> \<ge> 0" "\<mu> \<le> 1" |
49609 | 655 |
then have "1 - \<mu> \<ge> 0" by auto |
56796 | 656 |
then have xpos: "?x \<in> C" |
60423 | 657 |
using * unfolding convex_alt by fastforce |
56796 | 658 |
have geq: "\<mu> * (f x - f ?x) + (1 - \<mu>) * (f y - f ?x) \<ge> |
659 |
\<mu> * f' ?x * (x - ?x) + (1 - \<mu>) * f' ?x * (y - ?x)" |
|
60423 | 660 |
using add_mono[OF mult_left_mono[OF leq[OF xpos *(2)] \<open>\<mu> \<ge> 0\<close>] |
661 |
mult_left_mono[OF leq[OF xpos *(3)] \<open>1 - \<mu> \<ge> 0\<close>]] |
|
56796 | 662 |
by auto |
49609 | 663 |
then have "\<mu> * f x + (1 - \<mu>) * f y - f ?x \<ge> 0" |
60423 | 664 |
by (auto simp: field_simps) |
49609 | 665 |
then show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y" |
36623 | 666 |
using convex_on_alt by auto |
667 |
qed |
|
668 |
||
669 |
lemma atMostAtLeast_subset_convex: |
|
670 |
fixes C :: "real set" |
|
671 |
assumes "convex C" |
|
49609 | 672 |
and "x \<in> C" "y \<in> C" "x < y" |
36623 | 673 |
shows "{x .. y} \<subseteq> C" |
674 |
proof safe |
|
60423 | 675 |
fix z assume z: "z \<in> {x .. y}" |
676 |
have less: "z \<in> C" if *: "x < z" "z < y" |
|
677 |
proof - |
|
49609 | 678 |
let ?\<mu> = "(y - z) / (y - x)" |
56796 | 679 |
have "0 \<le> ?\<mu>" "?\<mu> \<le> 1" |
60423 | 680 |
using assms * by (auto simp: field_simps) |
49609 | 681 |
then have comb: "?\<mu> * x + (1 - ?\<mu>) * y \<in> C" |
682 |
using assms iffD1[OF convex_alt, rule_format, of C y x ?\<mu>] |
|
683 |
by (simp add: algebra_simps) |
|
36623 | 684 |
have "?\<mu> * x + (1 - ?\<mu>) * y = (y - z) * x / (y - x) + (1 - (y - z) / (y - x)) * y" |
60423 | 685 |
by (auto simp: field_simps) |
36623 | 686 |
also have "\<dots> = ((y - z) * x + (y - x - (y - z)) * y) / (y - x)" |
49609 | 687 |
using assms unfolding add_divide_distrib by (auto simp: field_simps) |
36623 | 688 |
also have "\<dots> = z" |
49609 | 689 |
using assms by (auto simp: field_simps) |
60423 | 690 |
finally show ?thesis |
56796 | 691 |
using comb by auto |
60423 | 692 |
qed |
693 |
show "z \<in> C" using z less assms |
|
36623 | 694 |
unfolding atLeastAtMost_iff le_less by auto |
695 |
qed |
|
696 |
||
697 |
lemma f''_imp_f': |
|
698 |
fixes f :: "real \<Rightarrow> real" |
|
699 |
assumes "convex C" |
|
49609 | 700 |
and f': "\<And>x. x \<in> C \<Longrightarrow> DERIV f x :> (f' x)" |
701 |
and f'': "\<And>x. x \<in> C \<Longrightarrow> DERIV f' x :> (f'' x)" |
|
702 |
and pos: "\<And>x. x \<in> C \<Longrightarrow> f'' x \<ge> 0" |
|
703 |
and "x \<in> C" "y \<in> C" |
|
36623 | 704 |
shows "f' x * (y - x) \<le> f y - f x" |
49609 | 705 |
using assms |
36623 | 706 |
proof - |
56796 | 707 |
{ |
708 |
fix x y :: real |
|
60423 | 709 |
assume *: "x \<in> C" "y \<in> C" "y > x" |
710 |
then have ge: "y - x > 0" "y - x \<ge> 0" |
|
711 |
by auto |
|
712 |
from * have le: "x - y < 0" "x - y \<le> 0" |
|
713 |
by auto |
|
36623 | 714 |
then obtain z1 where z1: "z1 > x" "z1 < y" "f y - f x = (y - x) * f' z1" |
60423 | 715 |
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>], |
716 |
THEN f', THEN MVT2[OF \<open>x < y\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]] |
|
36623 | 717 |
by auto |
60423 | 718 |
then have "z1 \<in> C" |
719 |
using atMostAtLeast_subset_convex \<open>convex C\<close> \<open>x \<in> C\<close> \<open>y \<in> C\<close> \<open>x < y\<close> |
|
720 |
by fastforce |
|
36623 | 721 |
from z1 have z1': "f x - f y = (x - y) * f' z1" |
60423 | 722 |
by (simp add: field_simps) |
36623 | 723 |
obtain z2 where z2: "z2 > x" "z2 < z1" "f' z1 - f' x = (z1 - x) * f'' z2" |
60423 | 724 |
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>], |
725 |
THEN f'', THEN MVT2[OF \<open>x < z1\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1 |
|
36623 | 726 |
by auto |
727 |
obtain z3 where z3: "z3 > z1" "z3 < y" "f' y - f' z1 = (y - z1) * f'' z3" |
|
60423 | 728 |
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>], |
729 |
THEN f'', THEN MVT2[OF \<open>z1 < y\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1 |
|
36623 | 730 |
by auto |
731 |
have "f' y - (f x - f y) / (x - y) = f' y - f' z1" |
|
60423 | 732 |
using * z1' by auto |
733 |
also have "\<dots> = (y - z1) * f'' z3" |
|
734 |
using z3 by auto |
|
735 |
finally have cool': "f' y - (f x - f y) / (x - y) = (y - z1) * f'' z3" |
|
736 |
by simp |
|
737 |
have A': "y - z1 \<ge> 0" |
|
738 |
using z1 by auto |
|
739 |
have "z3 \<in> C" |
|
740 |
using z3 * atMostAtLeast_subset_convex \<open>convex C\<close> \<open>x \<in> C\<close> \<open>z1 \<in> C\<close> \<open>x < z1\<close> |
|
741 |
by fastforce |
|
742 |
then have B': "f'' z3 \<ge> 0" |
|
743 |
using assms by auto |
|
744 |
from A' B' have "(y - z1) * f'' z3 \<ge> 0" |
|
745 |
by auto |
|
746 |
from cool' this have "f' y - (f x - f y) / (x - y) \<ge> 0" |
|
747 |
by auto |
|
36623 | 748 |
from mult_right_mono_neg[OF this le(2)] |
749 |
have "f' y * (x - y) - (f x - f y) / (x - y) * (x - y) \<le> 0 * (x - y)" |
|
36778
739a9379e29b
avoid using real-specific versions of generic lemmas
huffman
parents:
36648
diff
changeset
|
750 |
by (simp add: algebra_simps) |
60423 | 751 |
then have "f' y * (x - y) - (f x - f y) \<le> 0" |
752 |
using le by auto |
|
753 |
then have res: "f' y * (x - y) \<le> f x - f y" |
|
754 |
by auto |
|
36623 | 755 |
have "(f y - f x) / (y - x) - f' x = f' z1 - f' x" |
60423 | 756 |
using * z1 by auto |
757 |
also have "\<dots> = (z1 - x) * f'' z2" |
|
758 |
using z2 by auto |
|
759 |
finally have cool: "(f y - f x) / (y - x) - f' x = (z1 - x) * f'' z2" |
|
760 |
by simp |
|
761 |
have A: "z1 - x \<ge> 0" |
|
762 |
using z1 by auto |
|
763 |
have "z2 \<in> C" |
|
764 |
using z2 z1 * atMostAtLeast_subset_convex \<open>convex C\<close> \<open>z1 \<in> C\<close> \<open>y \<in> C\<close> \<open>z1 < y\<close> |
|
765 |
by fastforce |
|
766 |
then have B: "f'' z2 \<ge> 0" |
|
767 |
using assms by auto |
|
768 |
from A B have "(z1 - x) * f'' z2 \<ge> 0" |
|
769 |
by auto |
|
770 |
with cool have "(f y - f x) / (y - x) - f' x \<ge> 0" |
|
771 |
by auto |
|
36623 | 772 |
from mult_right_mono[OF this ge(2)] |
773 |
have "(f y - f x) / (y - x) * (y - x) - f' x * (y - x) \<ge> 0 * (y - x)" |
|
36778
739a9379e29b
avoid using real-specific versions of generic lemmas
huffman
parents:
36648
diff
changeset
|
774 |
by (simp add: algebra_simps) |
60423 | 775 |
then have "f y - f x - f' x * (y - x) \<ge> 0" |
776 |
using ge by auto |
|
49609 | 777 |
then have "f y - f x \<ge> f' x * (y - x)" "f' y * (x - y) \<le> f x - f y" |
60423 | 778 |
using res by auto |
779 |
} note less_imp = this |
|
56796 | 780 |
{ |
781 |
fix x y :: real |
|
49609 | 782 |
assume "x \<in> C" "y \<in> C" "x \<noteq> y" |
783 |
then have"f y - f x \<ge> f' x * (y - x)" |
|
56796 | 784 |
unfolding neq_iff using less_imp by auto |
785 |
} |
|
36623 | 786 |
moreover |
56796 | 787 |
{ |
788 |
fix x y :: real |
|
60423 | 789 |
assume "x \<in> C" "y \<in> C" "x = y" |
56796 | 790 |
then have "f y - f x \<ge> f' x * (y - x)" by auto |
791 |
} |
|
36623 | 792 |
ultimately show ?thesis using assms by blast |
793 |
qed |
|
794 |
||
795 |
lemma f''_ge0_imp_convex: |
|
796 |
fixes f :: "real \<Rightarrow> real" |
|
797 |
assumes conv: "convex C" |
|
49609 | 798 |
and f': "\<And>x. x \<in> C \<Longrightarrow> DERIV f x :> (f' x)" |
799 |
and f'': "\<And>x. x \<in> C \<Longrightarrow> DERIV f' x :> (f'' x)" |
|
800 |
and pos: "\<And>x. x \<in> C \<Longrightarrow> f'' x \<ge> 0" |
|
36623 | 801 |
shows "convex_on C f" |
56796 | 802 |
using f''_imp_f'[OF conv f' f'' pos] assms pos_convex_function |
803 |
by fastforce |
|
36623 | 804 |
|
805 |
lemma minus_log_convex: |
|
806 |
fixes b :: real |
|
807 |
assumes "b > 1" |
|
808 |
shows "convex_on {0 <..} (\<lambda> x. - log b x)" |
|
809 |
proof - |
|
56796 | 810 |
have "\<And>z. z > 0 \<Longrightarrow> DERIV (log b) z :> 1 / (ln b * z)" |
811 |
using DERIV_log by auto |
|
49609 | 812 |
then have f': "\<And>z. z > 0 \<Longrightarrow> DERIV (\<lambda> z. - log b z) z :> - 1 / (ln b * z)" |
56479
91958d4b30f7
revert c1bbd3e22226, a14831ac3023, and 36489d77c484: divide_minus_left/right are again simp rules
hoelzl
parents:
56409
diff
changeset
|
813 |
by (auto simp: DERIV_minus) |
49609 | 814 |
have "\<And>z :: real. z > 0 \<Longrightarrow> DERIV inverse z :> - (inverse z ^ Suc (Suc 0))" |
36623 | 815 |
using less_imp_neq[THEN not_sym, THEN DERIV_inverse] by auto |
816 |
from this[THEN DERIV_cmult, of _ "- 1 / ln b"] |
|
49609 | 817 |
have "\<And>z :: real. z > 0 \<Longrightarrow> |
818 |
DERIV (\<lambda> z. (- 1 / ln b) * inverse z) z :> (- 1 / ln b) * (- (inverse z ^ Suc (Suc 0)))" |
|
36623 | 819 |
by auto |
56796 | 820 |
then have f''0: "\<And>z::real. z > 0 \<Longrightarrow> |
821 |
DERIV (\<lambda> z. - 1 / (ln b * z)) z :> 1 / (ln b * z * z)" |
|
60423 | 822 |
unfolding inverse_eq_divide by (auto simp: mult.assoc) |
56796 | 823 |
have f''_ge0: "\<And>z::real. z > 0 \<Longrightarrow> 1 / (ln b * z * z) \<ge> 0" |
60423 | 824 |
using \<open>b > 1\<close> by (auto intro!: less_imp_le) |
36623 | 825 |
from f''_ge0_imp_convex[OF pos_is_convex, |
826 |
unfolded greaterThan_iff, OF f' f''0 f''_ge0] |
|
827 |
show ?thesis by auto |
|
828 |
qed |
|
829 |
||
830 |
end |