diff -r 67d28b35c5d8 -r ca004ccf2352 src/HOL/Analysis/Convex.thy --- a/src/HOL/Analysis/Convex.thy Wed Mar 20 21:12:49 2024 +0100 +++ b/src/HOL/Analysis/Convex.thy Thu Mar 21 14:19:39 2024 +0000 @@ -315,6 +315,12 @@ (\x\S. \y\S. \u\0. \v\0. u + v = 1 \ f (u *\<^sub>R x + v *\<^sub>R y) \ u * f x + v * f y)" by (auto simp: concave_on_def convex_on_def algebra_simps) +lemma concave_onD: + assumes "concave_on A f" + shows "\t x y. t \ 0 \ t \ 1 \ x \ A \ y \ A \ + f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" + using assms by (auto simp: concave_on_iff) + lemma convex_onI [intro?]: assumes "\t x y. t > 0 \ t < 1 \ x \ A \ y \ A \ f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" @@ -323,6 +329,12 @@ unfolding convex_on_def by (smt (verit, del_insts) assms mult_cancel_right1 mult_eq_0_iff scaleR_collapse scaleR_eq_0_iff) +lemma convex_onD: + assumes "convex_on A f" + shows "\t x y. t \ 0 \ t \ 1 \ x \ A \ y \ A \ + f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" + using assms by (auto simp: convex_on_def) + lemma convex_on_linorderI [intro?]: fixes A :: "('a::{linorder,real_vector}) set" assumes "\t x y. t > 0 \ t < 1 \ x \ A \ y \ A \ x < y \ @@ -331,11 +343,13 @@ shows "convex_on A f" by (smt (verit, best) add.commute assms convex_onI distrib_left linorder_cases mult.commute mult_cancel_left2 scaleR_collapse) -lemma convex_onD: - assumes "convex_on A f" - shows "\t x y. t \ 0 \ t \ 1 \ x \ A \ y \ A \ - f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" - using assms by (auto simp: convex_on_def) +lemma concave_on_linorderI [intro?]: + fixes A :: "('a::{linorder,real_vector}) set" + assumes "\t x y. t > 0 \ t < 1 \ x \ A \ y \ A \ x < y \ + f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" + and "convex A" + shows "concave_on A f" + by (smt (verit) assms concave_on_def convex_on_linorderI mult_minus_right) lemma convex_on_imp_convex: "convex_on A f \ convex A" by (auto simp: convex_on_def) @@ -407,27 +421,21 @@ assumes "convex_on S f" "convex_on S g" assumes "mono_on S f" "mono_on S g" assumes fty: "f \ S \ {0..}" and gty: "g \ S \ {0..}" - shows "convex_on S (\x. f x * g x)" + shows "convex_on S (\x. f x*g x)" proof (intro convex_on_linorderI) show "convex S" - using \convex_on S f\ convex_on_imp_convex by blast + using assms convex_on_imp_convex by auto fix t::real and x y - assume t: "0 < t" "t < 1" and xy: "x \ S" "y \ S" - have "f x*g y + f y*g x \ f x*g x + f y*g y" - using \mono_on S f\ \mono_on S g\ - by (smt (verit, ccfv_SIG) mono_onD mult_right_mono right_diff_distrib' xy) - then have "(1-t) * f x * g y + (1-t) * f y * g x \ (1-t) * f x * g x + (1-t) * f y * g y" - using t - by (metis (mono_tags, opaque_lifting) mult.assoc diff_gt_0_iff_gt distrib_left mult_le_cancel_left_pos) - then have *: "t*(1-t) * f x * g y + t*(1-t) * f y * g x \ t*(1-t) * f x * g x + t*(1-t) * f y * g y" - using t - by (metis (mono_tags, opaque_lifting) mult.assoc distrib_left mult_le_cancel_left_pos) + assume t: "0 < t" "t < 1" and xy: "x \ S" "y \ S" "x t*(1-t) * f x * g x + t*(1-t) * f y * g y" + using t \mono_on S f\ \mono_on S g\ xy + by (smt (verit, ccfv_SIG) left_diff_distrib mono_onD mult_left_less_imp_less zero_le_mult_iff) have inS: "(1-t)*x + t*y \ S" using t xy \convex S\ by (simp add: convex_alt) - then have "f ((1-t)*x + t*y) * g ((1-t)*x + t*y) \ ((1-t)*f x + t*f y)*g ((1-t)*x + t*y)" + then have "f ((1-t)*x + t*y) * g ((1-t)*x + t*y) \ ((1-t) * f x + t * f y)*g ((1-t)*x + t*y)" using convex_onD [OF \convex_on S f\, of t x y] t xy fty gty by (intro mult_mono add_nonneg_nonneg) (auto simp: Pi_iff zero_le_mult_iff) - also have "\ \ ((1-t)*f x + t*f y) * ((1-t)*g x + t*g y)" + also have "\ \ ((1-t) * f x + t * f y) * ((1-t)*g x + t*g y)" using convex_onD [OF \convex_on S g\, of t x y] t xy fty gty inS by (intro mult_mono add_nonneg_nonneg) (auto simp: Pi_iff zero_le_mult_iff) also have "\ \ (1-t) * (f x*g x) + t * (f y*g y)" @@ -494,6 +502,50 @@ by (smt (verit, best) \0 \ u\ \0 \ v\ norm_scaleR norm_triangle_ineq) qed (use assms in auto) +lemma concave_on_mul: + fixes S::"real set" + assumes f: "concave_on S f" and g: "concave_on S g" + assumes "mono_on S f" "antimono_on S g" + assumes fty: "f \ S \ {0..}" and gty: "g \ S \ {0..}" + shows "concave_on S (\x. f x * g x)" +proof (intro concave_on_linorderI) + show "convex S" + using concave_on_imp_convex f by blast + fix t::real and x y + assume t: "0 < t" "t < 1" and xy: "x \ S" "y \ S" "x S" + using t xy \convex S\ by (simp add: convex_alt) + have "f x * g y + f y * g x \ f x * g x + f y * g y" + using \mono_on S f\ \antimono_on S g\ + unfolding monotone_on_def by (smt (verit, best) left_diff_distrib mult_left_mono xy) + with t have *: "t*(1-t) * f x * g y + t*(1-t) * f y * g x \ t*(1-t) * f x * g x + t*(1-t) * f y * g y" + by (smt (verit, ccfv_SIG) distrib_left mult_left_mono diff_ge_0_iff_ge mult.assoc) + have "(1 - t) * (f x * g x) + t * (f y * g y) \ ((1-t) * f x + t * f y) * ((1-t) * g x + t * g y)" + using * by (simp add: algebra_simps) + also have "\ \ ((1-t) * f x + t * f y)*g ((1-t)*x + t*y)" + using concave_onD [OF \concave_on S g\, of t x y] t xy fty gty inS + by (intro mult_mono add_nonneg_nonneg) (auto simp: Pi_iff zero_le_mult_iff) + also have "\ \ f ((1-t)*x + t*y) * g ((1-t)*x + t*y)" + using concave_onD [OF \concave_on S f\, of t x y] t xy fty gty inS + by (intro mult_mono add_nonneg_nonneg) (auto simp: Pi_iff zero_le_mult_iff) + finally show "(1 - t) * (f x * g x) + t * (f y * g y) + \ f ((1 - t) *\<^sub>R x + t *\<^sub>R y) * g ((1 - t) *\<^sub>R x + t *\<^sub>R y)" + by simp +qed + +lemma concave_on_cmul [intro]: + fixes c :: real + assumes "0 \ c" and "concave_on S f" + shows "concave_on S (\x. c * f x)" + using assms convex_on_cmul [of c S "\x. - f x"] + by (auto simp: concave_on_def) + +lemma concave_on_cdiv [intro]: + fixes c :: real + assumes "0 \ c" and "concave_on S f" + shows "concave_on S (\x. f x / c)" + unfolding divide_inverse + using concave_on_cmul [of "inverse c" S f] by (simp add: mult.commute assms) subsection\<^marker>\tag unimportant\ \Arithmetic operations on sets preserve convexity\ @@ -1041,6 +1093,66 @@ finally show ?thesis . qed (use assms in auto) +lemma concave_onD_Icc: + assumes "concave_on {x..y} f" "x \ (y :: _ :: {real_vector,preorder})" + shows "\t. t \ 0 \ t \ 1 \ + f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" + using assms(2) by (intro concave_onD [OF assms(1)]) simp_all + +lemma concave_onD_Icc': + assumes "concave_on {x..y} f" "c \ {x..y}" + defines "d \ y - x" + shows "f c \ (f y - f x) / d * (c - x) + f x" +proof - + have "- f c \ (f x - f y) / d * (c - x) - f x" + using assms convex_onD_Icc' [of x y "\x. - f x" c] + by (simp add: concave_on_def) + then show ?thesis + by (smt (verit, best) divide_minus_left mult_minus_left) +qed + +lemma concave_onD_Icc'': + assumes "concave_on {x..y} f" "c \ {x..y}" + defines "d \ y - x" + shows "f c \ (f x - f y) / d * (y - c) + f y" +proof - + have "- f c \ (f y - f x) / d * (y - c) - f y" + using assms convex_onD_Icc'' [of x y "\x. - f x" c] + by (simp add: concave_on_def) + then show ?thesis + by (smt (verit, best) divide_minus_left mult_minus_left) +qed + +lemma convex_on_le_max: + fixes a::real + assumes "convex_on {x..y} f" and a: "a \ {x..y}" + shows "f a \ max (f x) (f y)" +proof - + have *: "(f y - f x) * (a - x) \ (f y - f x) * (y - x)" if "f x \ f y" + using a that by (intro mult_left_mono) auto + have "f a \ (f y - f x) / (y - x) * (a - x) + f x" + using assms convex_onD_Icc' by blast + also have "\ \ max (f x) (f y)" + using a * + by (simp add: divide_le_0_iff mult_le_0_iff zero_le_mult_iff max_def add.commute mult.commute scaling_mono) + finally show ?thesis . +qed + +lemma concave_on_ge_min: + fixes a::real + assumes "concave_on {x..y} f" and a: "a \ {x..y}" + shows "f a \ min (f x) (f y)" +proof - + have *: "(f y - f x) * (a - x) \ (f y - f x) * (y - x)" if "f x \ f y" + using a that by (intro mult_left_mono_neg) auto + have "min (f x) (f y) \ (f y - f x) / (y - x) * (a - x) + f x" + using a * apply (simp add: zero_le_divide_iff mult_le_0_iff zero_le_mult_iff min_def) + by (smt (verit, best) nonzero_eq_divide_eq pos_divide_le_eq) + also have "\ \ f a" + using assms concave_onD_Icc' by blast + finally show ?thesis . +qed + subsection \Some inequalities: Applications of convexity\ lemma Youngs_inequality_0: