# HG changeset patch # User paulson # Date 1707233350 0 # Node ID 7822b55b26ce2ba640bc985c62cfc273d1deb664 # Parent 163b554af747a650da03082d57e8e5b1d845507d Correct the definition of a convex function, and updated the proofs diff -r 163b554af747 -r 7822b55b26ce src/HOL/Analysis/Convex.thy --- a/src/HOL/Analysis/Convex.thy Mon Feb 05 22:03:43 2024 +0100 +++ b/src/HOL/Analysis/Convex.thy Tue Feb 06 15:29:10 2024 +0000 @@ -302,20 +302,21 @@ subsection \Convex Functions on a Set\ definition\<^marker>\tag important\ convex_on :: "'a::real_vector set \ ('a \ real) \ bool" - where "convex_on S f \ + where "convex_on S f \ convex S \ (\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)" definition\<^marker>\tag important\ concave_on :: "'a::real_vector set \ ('a \ real) \ bool" where "concave_on S f \ convex_on S (\x. - f x)" lemma concave_on_iff: - "concave_on S f \ + "concave_on S f \ convex S \ (\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 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" + and "convex A" shows "convex_on A f" unfolding convex_on_def by (smt (verit, del_insts) assms mult_cancel_right1 mult_eq_0_iff scaleR_collapse scaleR_eq_0_iff) @@ -324,6 +325,7 @@ 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 "convex_on A f" by (smt (verit, best) add.commute assms convex_onI distrib_left linorder_cases mult.commute mult_cancel_left2 scaleR_collapse) @@ -333,14 +335,20 @@ 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_imp_convex: "convex_on A f \ convex A" + by (auto simp: convex_on_def) + +lemma concave_on_imp_convex: "concave_on A f \ convex A" + by (simp add: concave_on_def convex_on_imp_convex) + lemma convex_onD_Icc: assumes "convex_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 convex_onD [OF assms(1)]) simp_all -lemma convex_on_subset: "convex_on t f \ S \ t \ convex_on S f" - unfolding convex_on_def by auto +lemma convex_on_subset: "\convex_on T f; S \ T; convex S\ \ convex_on S f" + by (simp add: convex_on_def subset_iff) lemma convex_on_add [intro]: assumes "convex_on S f" @@ -359,7 +367,7 @@ then have "f (u *\<^sub>R x + v *\<^sub>R y) + g (u *\<^sub>R x + v *\<^sub>R y) \ u * (f x + g x) + v * (f y + g y)" by (simp add: field_simps) } - then show ?thesis + with assms show ?thesis unfolding convex_on_def by auto qed @@ -396,8 +404,10 @@ lemma convex_on_dist [intro]: fixes S :: "'a::real_normed_vector set" + assumes "convex S" shows "convex_on S (\x. dist a x)" -proof (clarsimp simp: convex_on_def dist_norm) +unfolding convex_on_def dist_norm +proof (intro conjI strip) fix x y assume "x \ S" "y \ S" fix u v :: real @@ -410,7 +420,7 @@ by (auto simp: algebra_simps) then show "norm (a - (u *\<^sub>R x + v *\<^sub>R y)) \ u * norm (a - x) + v * norm (a - y)" by (smt (verit, best) \0 \ u\ \0 \ v\ norm_scaleR norm_triangle_ineq) -qed +qed (use assms in auto) subsection\<^marker>\tag unimportant\ \Arithmetic operations on sets preserve convexity\ @@ -568,7 +578,7 @@ lemma convex_on_alt: fixes C :: "'a::real_vector set" - shows "convex_on C f \ + shows "convex_on C f \ convex C \ (\x \ C. \y \ C. \ \ :: real. \ \ 0 \ \ \ 1 \ f (\ *\<^sub>R x + (1 - \) *\<^sub>R y) \ \ * f x + (1 - \) * f y)" by (smt (verit) convex_on_def) @@ -765,6 +775,11 @@ and "\x y. x \ A \ y \ A \ x \ y \ f' x \ f' y" shows "convex_on A f" proof (rule convex_on_linorderI) + show "convex A" + using \connected A\ convex_real_interval interval_cases + by (smt (verit, ccfv_SIG) connectedD_interval convex_UNIV convex_empty) + \ \the equivalence of "connected" and "convex" for real intervals is proved later\ +next fix t x y :: real assume t: "t > 0" "t < 1" assume xy: "x \ A" "y \ A" "x < y" @@ -810,7 +825,7 @@ lemma convex_on_inverse: fixes A :: "real set" - assumes "A \ {0<..}" + assumes "A \ {0<..}" "convex A" shows "convex_on A inverse" proof - have "convex_on {0::real<..} inverse" @@ -2307,15 +2322,13 @@ lemma mem_epigraph: "(x, y) \ epigraph S f \ x \ S \ f x \ y" unfolding epigraph_def by auto -lemma convex_epigraph: "convex (epigraph S f) \ convex_on S f \ convex S" +lemma convex_epigraph: "convex (epigraph S f) \ convex_on S f" proof safe assume L: "convex (epigraph S f)" then show "convex_on S f" - by (auto simp: convex_def convex_on_def epigraph_def) - show "convex S" - using L by (fastforce simp: convex_def convex_on_def epigraph_def) + by (fastforce simp: convex_def convex_on_def epigraph_def) next - assume "convex_on S f" "convex S" + assume "convex_on S f" then show "convex (epigraph S f)" unfolding convex_def convex_on_def epigraph_def apply safe @@ -2324,16 +2337,15 @@ done qed -lemma convex_epigraphI: "convex_on S f \ convex S \ convex (epigraph S f)" +lemma convex_epigraphI: "convex_on S f \ convex (epigraph S f)" unfolding convex_epigraph by auto -lemma convex_epigraph_convex: "convex S \ convex_on S f \ convex(epigraph S f)" +lemma convex_epigraph_convex: "convex_on S f \ convex(epigraph S f)" by (simp add: convex_epigraph) subsubsection\<^marker>\tag unimportant\ \Use this to derive general bound property of convex function\ - lemma convex_on: assumes "convex S" shows "convex_on S f \ @@ -2360,7 +2372,7 @@ next assume "\k u x. ?rhs k u x" then show ?lhs - unfolding convex_epigraph_convex[OF assms] convex epigraph_def Ball_def mem_Collect_eq fst_sum snd_sum + unfolding convex_epigraph_convex convex epigraph_def Ball_def mem_Collect_eq fst_sum snd_sum using assms[unfolded convex] apply clarsimp apply (rule_tac y="\i = 1..k. u i * f (fst (x i))" in order_trans) by (auto simp add: mult_left_mono intro: sum_mono) diff -r 163b554af747 -r 7822b55b26ce src/HOL/Analysis/Convex_Euclidean_Space.thy --- a/src/HOL/Analysis/Convex_Euclidean_Space.thy Mon Feb 05 22:03:43 2024 +0100 +++ b/src/HOL/Analysis/Convex_Euclidean_Space.thy Tue Feb 06 15:29:10 2024 +0000 @@ -10,8 +10,7 @@ theory Convex_Euclidean_Space imports - Convex - Topology_Euclidean_Space + Convex Topology_Euclidean_Space Line_Segment begin subsection\<^marker>\tag unimportant\ \Topological Properties of Convex Sets and Functions\ @@ -1959,7 +1958,7 @@ lemma convex_on_bounded_continuous: fixes S :: "('a::real_normed_vector) set" assumes "open S" - and "convex_on S f" + and f: "convex_on S f" and "\x\S. \f x\ \ b" shows "continuous_on S f" proof - @@ -2002,9 +2001,8 @@ unfolding t_def using \0 < e\ \0 < k\ \B > 0\ and as and False by (auto simp:field_simps) have "f y - f x \ (f w - f x) / t" - using assms(2)[unfolded convex_on_def,rule_format,of w x "1/t" "(t - 1)/t", unfolded w] - using \0 < t\ \2 < t\ and \x \ S\ \w \ S\ - by (auto simp:field_simps) + using convex_onD [OF f, of "(t - 1)/t" w x] \0 < t\ \2 < t\ \x \ S\ \w \ S\ + by (simp add: w field_simps) also have "... < e" using B(2)[OF \w\S\] and B(2)[OF \x\S\] 2 \t > 0\ by (auto simp: field_simps) finally have th1: "f y - f x < e" . @@ -2030,9 +2028,8 @@ using \t > 0\ by (auto simp:field_simps) have "f x \ 1 / (1 + t) * f w + (t / (1 + t)) * f y" - using assms(2)[unfolded convex_on_def,rule_format,of w y "1/(1+t)" "t / (1+t)",unfolded w] - using \0 < t\ \2 < t\ and \y \ S\ \w \ S\ - by (auto simp:field_simps) + using convex_onD [OF f, of "t / (1+t)" w y] \0 < t\ \2 < t\ \y \ S\ \w \ S\ + by (simp add: w field_simps) also have "\ = (f w + t * f y) / (1 + t)" using \t > 0\ by (simp add: add_divide_distrib) also have "\ < e + f y" @@ -2051,8 +2048,8 @@ lemma convex_bounds_lemma: fixes x :: "'a::real_normed_vector" - assumes "convex_on (cball x e) f" - and "\y \ cball x e. f y \ b" and y: "y \ cball x e" + assumes f: "convex_on (cball x e) f" + and b: "\y. y \ cball x e \ f y \ b" and y: "y \ cball x e" shows "\f y\ \ b + 2 * \f x\" proof (cases "0 \ e") case True @@ -2064,9 +2061,8 @@ have "(1 / 2) *\<^sub>R y + (1 / 2) *\<^sub>R z = x" unfolding z_def by (auto simp: algebra_simps) then show "\f y\ \ b + 2 * \f x\" - using assms(1)[unfolded convex_on_def,rule_format, OF y z, of "1/2" "1/2"] - using assms(2)[rule_format,OF y] assms(2)[rule_format,OF z] - by (auto simp:field_simps) + using convex_onD [OF f, of "1/2" y z] b[OF y] b y z + by (fastforce simp add: field_simps) next case False have "dist x y < 0" @@ -2082,23 +2078,22 @@ by auto lemma convex_on_continuous: - assumes "open (s::('a::euclidean_space) set)" "convex_on s f" - shows "continuous_on s f" - unfolding continuous_on_eq_continuous_at[OF assms(1)] + fixes S :: "'a::euclidean_space set" + assumes "open S" "convex_on S f" + shows "continuous_on S f" + unfolding continuous_on_eq_continuous_at[OF \open S\] proof note dimge1 = DIM_positive[where 'a='a] fix x - assume "x \ s" - then obtain e where e: "cball x e \ s" "e > 0" + assume "x \ S" + then obtain e where e: "cball x e \ S" "e > 0" using assms(1) unfolding open_contains_cball by auto define d where "d = e / real DIM('a)" have "0 < d" unfolding d_def using \e > 0\ dimge1 by auto let ?d = "(\i\Basis. d *\<^sub>R i)::'a" obtain c - where c: "finite c" - and c1: "convex hull c \ cball x e" - and c2: "cball x d \ convex hull c" + where c: "finite c" and c1: "convex hull c \ cball x e" and c2: "cball x d \ convex hull c" proof define c where "c = (\i\Basis. (\a. a *\<^sub>R i) ` {x\i - d, x\i + d})" show "finite c" @@ -2145,9 +2140,11 @@ using \convex_on (convex hull c) f\ c2 convex_on_subset by blast then have "\y. y\cball x d \ \f y\ \ k + 2 * \f x\" by (rule convex_bounds_lemma) (use c2 k in blast) - then have "continuous_on (ball x d) f" - by (meson Elementary_Metric_Spaces.open_ball ball_subset_cball conv convex_on_bounded_continuous - convex_on_subset mem_ball_imp_mem_cball) + moreover have "convex_on (ball x d) f" + using conv convex_on_subset by fastforce + ultimately + have "continuous_on (ball x d) f" + by (metis convex_on_bounded_continuous Elementary_Metric_Spaces.open_ball mem_ball_imp_mem_cball) then show "continuous (at x) f" unfolding continuous_on_eq_continuous_at[OF open_ball] using \d > 0\ by auto diff -r 163b554af747 -r 7822b55b26ce src/HOL/Analysis/Line_Segment.thy --- a/src/HOL/Analysis/Line_Segment.thy Mon Feb 05 22:03:43 2024 +0100 +++ b/src/HOL/Analysis/Line_Segment.thy Tue Feb 06 15:29:10 2024 +0000 @@ -109,10 +109,7 @@ fix u v :: real assume uv: "0 \ u" "0 \ v" "u + v = 1" have "dist x (u *\<^sub>R y + v *\<^sub>R z) \ u * dist x y + v * dist x z" - using uv yz - using convex_on_dist [of "ball x e" x, unfolded convex_on_def, - THEN bspec[where x=y], THEN bspec[where x=z]] - by auto + using uv yz by (meson UNIV_I convex_def convex_on_def convex_on_dist) then show "dist x (u *\<^sub>R y + v *\<^sub>R z) < e" using convex_bound_lt[OF yz uv] by auto qed @@ -127,10 +124,7 @@ fix u v :: real assume uv: "0 \ u" "0 \ v" "u + v = 1" have "dist x (u *\<^sub>R y + v *\<^sub>R z) \ u * dist x y + v * dist x z" - using uv yz - using convex_on_dist [of "cball x e" x, unfolded convex_on_def, - THEN bspec[where x=y], THEN bspec[where x=z]] - by auto + using uv yz by (meson UNIV_I convex_def convex_on_def convex_on_dist) then have "dist x (u *\<^sub>R y + v *\<^sub>R z) \ e" using convex_bound_le[OF yz uv] by auto } diff -r 163b554af747 -r 7822b55b26ce src/HOL/Fun.thy --- a/src/HOL/Fun.thy Mon Feb 05 22:03:43 2024 +0100 +++ b/src/HOL/Fun.thy Tue Feb 06 15:29:10 2024 +0000 @@ -1024,7 +1024,6 @@ using mono_f[THEN monotone_onD] by simp qed - subsubsection \Specializations For @{class ord} Type Class And More\ context ord begin @@ -1158,6 +1157,20 @@ qed qed +lemma mono_on_ident: "mono_on S (\x. x)" + by (simp add: monotone_on_def) + +lemma strict_mono_on_ident: "strict_mono_on S (\x. x)" + by (simp add: monotone_on_def) + +lemma mono_on_const: + fixes a :: "'b::order" shows "mono_on S (\x. a)" + by (simp add: mono_on_def) + +lemma antimono_on_const: + fixes a :: "'b::order" shows "antimono_on S (\x. a)" + by (simp add: monotone_on_def) + end context linorder begin