diff -r 65223730d7e1 -r f471e1715fc4 src/HOL/Analysis/Convex.thy --- a/src/HOL/Analysis/Convex.thy Mon Feb 19 08:23:23 2024 +0100 +++ b/src/HOL/Analysis/Convex.thy Mon Feb 19 14:12:20 2024 +0000 @@ -583,7 +583,6 @@ and f :: "'b \ real" assumes "finite S" "S \ {}" and "convex_on C f" - and "convex C" and "(\ i \ S. a i) = 1" and "\i. i \ S \ a i \ 0" and "\i. i \ S \ y i \ C" @@ -624,6 +623,8 @@ using i0 by auto then have a1: "(\ j \ S. ?a j) = 1" unfolding sum_divide_distrib by simp + have "convex C" + using \convex_on C f\ by (simp add: convex_on_def) have asum: "(\ j \ S. ?a j *\<^sub>R y j) \ C" using insert convex_sum [OF \finite S\ \convex C\ a1 a_nonneg] by auto have asum_le: "f (\ j \ S. ?a j *\<^sub>R y j) \ (\ j \ S. ?a j * f (y j))" @@ -648,6 +649,26 @@ qed qed +lemma concave_on_sum: + fixes a :: "'a \ real" + and y :: "'a \ 'b::real_vector" + and f :: "'b \ real" + assumes "finite S" "S \ {}" + and "concave_on C f" + and "(\i \ S. a i) = 1" + and "\i. i \ S \ a i \ 0" + and "\i. i \ S \ y i \ C" + shows "f (\i \ S. a i *\<^sub>R y i) \ (\i \ S. a i * f (y i))" +proof - + have "(uminus \ f) (\i\S. a i *\<^sub>R y i) \ (\i\S. a i * (uminus \ f) (y i))" + proof (intro convex_on_sum) + show "convex_on C (uminus \ f)" + by (simp add: assms convex_on_iff_concave) + qed (use assms in auto) + then show ?thesis + by (simp add: sum_negf o_def) +qed + lemma convex_on_alt: fixes C :: "'a::real_vector set" shows "convex_on C f \ convex C \ @@ -865,6 +886,39 @@ lemma exp_convex: "convex_on UNIV exp" by (intro f''_ge0_imp_convex derivative_eq_intros | simp)+ +text \The AM-GM inequality: the arithmetic mean exceeds the geometric mean.\ +lemma arith_geom_mean: + fixes x :: "'a \ real" + assumes "finite S" "S \ {}" + and x: "\i. i \ S \ x i \ 0" + shows "(\i \ S. x i / card S) \ (\i \ S. x i) powr (1 / card S)" +proof (cases "\i\S. x i = 0") + case True + then have "(\i \ S. x i) = 0" + by (simp add: \finite S\) + moreover have "(\i \ S. x i / card S) \ 0" + by (simp add: sum_nonneg x) + ultimately show ?thesis + by simp +next + case False + have "ln (\i \ S. (1 / card S) *\<^sub>R x i) \ (\i \ S. (1 / card S) * ln (x i))" + proof (intro concave_on_sum) + show "concave_on {0<..} ln" + by (simp add: ln_concave) + show "\i. i\S \ x i \ {0<..}" + using False x by fastforce + qed (use assms False in auto) + moreover have "(\i \ S. (1 / card S) *\<^sub>R x i) > 0" + using False assms by (simp add: card_gt_0_iff less_eq_real_def sum_pos) + ultimately have "(\i \ S. (1 / card S) *\<^sub>R x i) \ exp (\i \ S. (1 / card S) * ln (x i))" + using ln_ge_iff by blast + then have "(\i \ S. x i / card S) \ exp (\i \ S. ln (x i) / card S)" + by (simp add: divide_simps) + then show ?thesis + using assms False + by (smt (verit, ccfv_SIG) divide_inverse exp_ln exp_powr_real exp_sum inverse_eq_divide prod.cong prod_powr_distrib) +qed subsection\<^marker>\tag unimportant\ \Convexity of real functions\