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