src/HOL/Analysis/Convex_Euclidean_Space.thy
changeset 68058 69715dfdc286
parent 68052 e98988801fa9
child 68069 36209dfb981e
equal deleted inserted replaced
68056:9e077a905209 68058:69715dfdc286
  2468 lemma convex_hull_Times:
  2468 lemma convex_hull_Times:
  2469   "convex hull (s \<times> t) = (convex hull s) \<times> (convex hull t)"
  2469   "convex hull (s \<times> t) = (convex hull s) \<times> (convex hull t)"
  2470 proof
  2470 proof
  2471   show "convex hull (s \<times> t) \<subseteq> (convex hull s) \<times> (convex hull t)"
  2471   show "convex hull (s \<times> t) \<subseteq> (convex hull s) \<times> (convex hull t)"
  2472     by (intro hull_minimal Sigma_mono hull_subset convex_Times convex_convex_hull)
  2472     by (intro hull_minimal Sigma_mono hull_subset convex_Times convex_convex_hull)
  2473   have "\<forall>x\<in>convex hull s. \<forall>y\<in>convex hull t. (x, y) \<in> convex hull (s \<times> t)"
  2473   have "(x, y) \<in> convex hull (s \<times> t)" if x: "x \<in> convex hull s" and y: "y \<in> convex hull t" for x y
  2474   proof (intro hull_induct)
  2474   proof (rule hull_induct [OF x], rule hull_induct [OF y])
  2475     fix x y assume "x \<in> s" and "y \<in> t"
  2475     fix x y assume "x \<in> s" and "y \<in> t"
  2476     then show "(x, y) \<in> convex hull (s \<times> t)"
  2476     then show "(x, y) \<in> convex hull (s \<times> t)"
  2477       by (simp add: hull_inc)
  2477       by (simp add: hull_inc)
  2478   next
  2478   next
  2479     fix x let ?S = "((\<lambda>y. (0, y)) -` (\<lambda>p. (- x, 0) + p) ` (convex hull s \<times> t))"
  2479     fix x let ?S = "((\<lambda>y. (0, y)) -` (\<lambda>p. (- x, 0) + p) ` (convex hull s \<times> t))"
  2482         simp add: linear_iff)
  2482         simp add: linear_iff)
  2483     also have "?S = {y. (x, y) \<in> convex hull (s \<times> t)}"
  2483     also have "?S = {y. (x, y) \<in> convex hull (s \<times> t)}"
  2484       by (auto simp: image_def Bex_def)
  2484       by (auto simp: image_def Bex_def)
  2485     finally show "convex {y. (x, y) \<in> convex hull (s \<times> t)}" .
  2485     finally show "convex {y. (x, y) \<in> convex hull (s \<times> t)}" .
  2486   next
  2486   next
  2487     show "convex {x. \<forall>y\<in>convex hull t. (x, y) \<in> convex hull (s \<times> t)}"
  2487     show "convex {x. (x, y) \<in> convex hull s \<times> t}"
  2488     proof (unfold Collect_ball_eq, rule convex_INT [rule_format])
  2488     proof -
  2489       fix y let ?S = "((\<lambda>x. (x, 0)) -` (\<lambda>p. (0, - y) + p) ` (convex hull s \<times> t))"
  2489       fix y let ?S = "((\<lambda>x. (x, 0)) -` (\<lambda>p. (0, - y) + p) ` (convex hull s \<times> t))"
  2490       have "convex ?S"
  2490       have "convex ?S"
  2491       by (intro convex_linear_vimage convex_translation convex_convex_hull,
  2491       by (intro convex_linear_vimage convex_translation convex_convex_hull,
  2492         simp add: linear_iff)
  2492         simp add: linear_iff)
  2493       also have "?S = {x. (x, y) \<in> convex hull (s \<times> t)}"
  2493       also have "?S = {x. (x, y) \<in> convex hull (s \<times> t)}"
  2494         by (auto simp: image_def Bex_def)
  2494         by (auto simp: image_def Bex_def)
  2495       finally show "convex {x. (x, y) \<in> convex hull (s \<times> t)}" .
  2495       finally show "convex {x. (x, y) \<in> convex hull (s \<times> t)}" .
  2496     qed
  2496     qed
  2497   qed
  2497   qed
  2498   then show "(convex hull s) \<times> (convex hull t) \<subseteq> convex hull (s \<times> t)"
  2498   then show "(convex hull s) \<times> (convex hull t) \<subseteq> convex hull (s \<times> t)"
  2499     unfolding subset_eq split_paired_Ball_Sigma .
  2499     unfolding subset_eq split_paired_Ball_Sigma by blast
  2500 qed
  2500 qed
  2501 
  2501 
  2502 
  2502 
  2503 subsubsection%unimportant \<open>Stepping theorems for convex hulls of finite sets\<close>
  2503 subsubsection%unimportant \<open>Stepping theorems for convex hulls of finite sets\<close>
  2504 
  2504 
  2510 
  2510 
  2511 lemma convex_hull_insert:
  2511 lemma convex_hull_insert:
  2512   fixes S :: "'a::real_vector set"
  2512   fixes S :: "'a::real_vector set"
  2513   assumes "S \<noteq> {}"
  2513   assumes "S \<noteq> {}"
  2514   shows "convex hull (insert a S) =
  2514   shows "convex hull (insert a S) =
  2515     {x. \<exists>u\<ge>0. \<exists>v\<ge>0. \<exists>b. (u + v = 1) \<and> b \<in> (convex hull S) \<and> (x = u *\<^sub>R a + v *\<^sub>R b)}"
  2515          {x. \<exists>u\<ge>0. \<exists>v\<ge>0. \<exists>b. (u + v = 1) \<and> b \<in> (convex hull S) \<and> (x = u *\<^sub>R a + v *\<^sub>R b)}"
  2516   (is "_ = ?hull")
  2516   (is "_ = ?hull")
  2517   apply (rule, rule hull_minimal, rule)
  2517 proof (intro equalityI hull_minimal subsetI)
       
  2518   fix x
       
  2519   assume "x \<in> insert a S"
       
  2520   then have "\<exists>u\<ge>0. \<exists>v\<ge>0. u + v = 1 \<and> (\<exists>b. b \<in> convex hull S \<and> x = u *\<^sub>R a + v *\<^sub>R b)"
  2518   unfolding insert_iff
  2521   unfolding insert_iff
  2519   prefer 3
       
  2520   apply rule
       
  2521 proof -
       
  2522   fix x
       
  2523   assume x: "x = a \<or> x \<in> S"
       
  2524   then have "\<exists>u\<ge>0. \<exists>v\<ge>0. u + v = 1 \<and> (\<exists>b. b \<in> convex hull S \<and> x = u *\<^sub>R a + v *\<^sub>R b)"
       
  2525   proof
  2522   proof
  2526     assume "x = a"
  2523     assume "x = a"
  2527     then show ?thesis
  2524     then show ?thesis
  2528       by (rule_tac x=1 in exI) (use assms hull_subset in fastforce)
  2525       by (rule_tac x=1 in exI) (use assms hull_subset in fastforce)
  2529   next
  2526   next
  2617   qed
  2614   qed
  2618 qed
  2615 qed
  2619 
  2616 
  2620 lemma convex_hull_insert_alt:
  2617 lemma convex_hull_insert_alt:
  2621    "convex hull (insert a S) =
  2618    "convex hull (insert a S) =
  2622       (if S = {} then {a}
  2619      (if S = {} then {a}
  2623       else {(1 - u) *\<^sub>R a + u *\<^sub>R x |x u. 0 \<le> u \<and> u \<le> 1 \<and> x \<in> convex hull S})"
  2620       else {(1 - u) *\<^sub>R a + u *\<^sub>R x |x u. 0 \<le> u \<and> u \<le> 1 \<and> x \<in> convex hull S})"
  2624   apply (auto simp: convex_hull_insert)
  2621   apply (auto simp: convex_hull_insert)
  2625   using diff_eq_eq apply fastforce
  2622   using diff_eq_eq apply fastforce
  2626   by (metis add.group_left_neutral add_le_imp_le_diff diff_add_cancel)
  2623   by (metis add.group_left_neutral add_le_imp_le_diff diff_add_cancel)
  2627 
  2624 
  4369       using as[unfolded dist_norm] and \<open>e > 0\<close>
  4366       using as[unfolded dist_norm] and \<open>e > 0\<close>
  4370       by (auto simp:pos_divide_less_eq[OF \<open>e > 0\<close>] mult.commute)
  4367       by (auto simp:pos_divide_less_eq[OF \<open>e > 0\<close>] mult.commute)
  4371     finally have "y \<in> S"
  4368     finally have "y \<in> S"
  4372       apply (subst *)
  4369       apply (subst *)
  4373       apply (rule assms(1)[unfolded convex_alt,rule_format])
  4370       apply (rule assms(1)[unfolded convex_alt,rule_format])
  4374       apply (rule d[unfolded subset_eq,rule_format])
  4371       apply (rule d[THEN subsetD])
  4375       unfolding mem_ball
  4372       unfolding mem_ball
  4376       using assms(3-5) **
  4373       using assms(3-5) **
  4377       apply auto
  4374       apply auto
  4378       done
  4375       done
  4379   }
  4376   }
  4749 
  4746 
  4750 
  4747 
  4751 lemma affine_hull_linear_image:
  4748 lemma affine_hull_linear_image:
  4752   assumes "bounded_linear f"
  4749   assumes "bounded_linear f"
  4753   shows "f ` (affine hull s) = affine hull f ` s"
  4750   shows "f ` (affine hull s) = affine hull f ` s"
  4754   apply rule
       
  4755   unfolding subset_eq ball_simps
       
  4756   apply (rule_tac[!] hull_induct, rule hull_inc)
       
  4757   prefer 3
       
  4758   apply (erule imageE)
       
  4759   apply (rule_tac x=xa in image_eqI, assumption)
       
  4760   apply (rule hull_subset[unfolded subset_eq, rule_format], assumption)
       
  4761 proof -
  4751 proof -
  4762   interpret f: bounded_linear f by fact
  4752   interpret f: bounded_linear f by fact
  4763   show "affine {x. f x \<in> affine hull f ` s}"
  4753   have "affine {x. f x \<in> affine hull f ` s}"
  4764     unfolding affine_def
  4754     unfolding affine_def
  4765     by (auto simp: f.scaleR f.add affine_affine_hull[unfolded affine_def, rule_format])
  4755     by (auto simp: f.scaleR f.add affine_affine_hull[unfolded affine_def, rule_format])
  4766   show "affine {x. x \<in> f ` (affine hull s)}"
  4756   moreover have "affine {x. x \<in> f ` (affine hull s)}"
  4767     using affine_affine_hull[unfolded affine_def, of s]
  4757     using affine_affine_hull[unfolded affine_def, of s]
  4768     unfolding affine_def by (auto simp: f.scaleR [symmetric] f.add [symmetric])
  4758     unfolding affine_def by (auto simp: f.scaleR [symmetric] f.add [symmetric])
  4769 qed auto
  4759   ultimately show ?thesis
       
  4760     by (auto simp: hull_inc elim!: hull_induct)
       
  4761 qed 
  4770 
  4762 
  4771 
  4763 
  4772 lemma rel_interior_injective_on_span_linear_image:
  4764 lemma rel_interior_injective_on_span_linear_image:
  4773   fixes f :: "'m::euclidean_space \<Rightarrow> 'n::euclidean_space"
  4765   fixes f :: "'m::euclidean_space \<Rightarrow> 'n::euclidean_space"
  4774     and S :: "'m::euclidean_space set"
  4766     and S :: "'m::euclidean_space set"
  6482 proof (rule hull_unique)
  6474 proof (rule hull_unique)
  6483   show "{x, y} \<subseteq> cbox x y" using \<open>x \<le> y\<close> by auto
  6475   show "{x, y} \<subseteq> cbox x y" using \<open>x \<le> y\<close> by auto
  6484   show "convex (cbox x y)"
  6476   show "convex (cbox x y)"
  6485     by (rule convex_box)
  6477     by (rule convex_box)
  6486 next
  6478 next
  6487   fix s assume "{x, y} \<subseteq> s" and "convex s"
  6479   fix S assume "{x, y} \<subseteq> S" and "convex S"
  6488   then show "cbox x y \<subseteq> s"
  6480   then show "cbox x y \<subseteq> S"
  6489     unfolding is_interval_convex_1 [symmetric] is_interval_def Basis_real_def
  6481     unfolding is_interval_convex_1 [symmetric] is_interval_def Basis_real_def
  6490     by - (clarify, simp (no_asm_use), fast)
  6482     by - (clarify, simp (no_asm_use), fast)
  6491 qed
  6483 qed
  6492 
  6484 
  6493 lemma unit_interval_convex_hull:
  6485 lemma unit_interval_convex_hull:
  6514 qed
  6506 qed
  6515 
  6507 
  6516 text \<open>And this is a finite set of vertices.\<close>
  6508 text \<open>And this is a finite set of vertices.\<close>
  6517 
  6509 
  6518 lemma unit_cube_convex_hull:
  6510 lemma unit_cube_convex_hull:
  6519   obtains s :: "'a::euclidean_space set"
  6511   obtains S :: "'a::euclidean_space set"
  6520     where "finite s" and "cbox 0 (\<Sum>Basis) = convex hull s"
  6512   where "finite S" and "cbox 0 (\<Sum>Basis) = convex hull S"
  6521   apply (rule that[of "{x::'a. \<forall>i\<in>Basis. x\<bullet>i=0 \<or> x\<bullet>i=1}"])
  6513 proof
  6522   apply (rule finite_subset[of _ "(\<lambda>s. (\<Sum>i\<in>Basis. (if i\<in>s then 1 else 0) *\<^sub>R i)::'a) ` Pow Basis"])
  6514   show "finite {x::'a. \<forall>i\<in>Basis. x \<bullet> i = 0 \<or> x \<bullet> i = 1}"
  6523   prefer 3
  6515   proof (rule finite_subset, clarify)
  6524   apply (rule unit_interval_convex_hull, rule)
  6516     show "finite ((\<lambda>S. \<Sum>i\<in>Basis. (if i \<in> S then 1 else 0) *\<^sub>R i) ` Pow Basis)"
  6525   unfolding mem_Collect_eq
  6517       using finite_Basis by blast
  6526 proof -
  6518     fix x :: 'a
  6527   fix x :: 'a
  6519     assume as: "\<forall>i\<in>Basis. x \<bullet> i = 0 \<or> x \<bullet> i = 1"
  6528   assume as: "\<forall>i\<in>Basis. x \<bullet> i = 0 \<or> x \<bullet> i = 1"
  6520     show "x \<in> (\<lambda>S. \<Sum>i\<in>Basis. (if i\<in>S then 1 else 0) *\<^sub>R i) ` Pow Basis"
  6529   show "x \<in> (\<lambda>s. \<Sum>i\<in>Basis. (if i\<in>s then 1 else 0) *\<^sub>R i) ` Pow Basis"
  6521       apply (rule image_eqI[where x="{i. i\<in>Basis \<and> x\<bullet>i = 1}"])
  6530     apply (rule image_eqI[where x="{i. i\<in>Basis \<and> x\<bullet>i = 1}"])
  6522       using as
  6531     using as
  6523        apply (subst euclidean_eq_iff, auto)
  6532     apply (subst euclidean_eq_iff, auto)
  6524       done
  6533     done
  6525   qed
  6534 qed auto
  6526   show "cbox 0 One = convex hull {x. \<forall>i\<in>Basis. x \<bullet> i = 0 \<or> x \<bullet> i = 1}"
       
  6527     using unit_interval_convex_hull by blast
       
  6528 qed 
  6535 
  6529 
  6536 text \<open>Hence any cube (could do any nonempty interval).\<close>
  6530 text \<open>Hence any cube (could do any nonempty interval).\<close>
  6537 
  6531 
  6538 lemma cube_convex_hull:
  6532 lemma cube_convex_hull:
  6539   assumes "d > 0"
  6533   assumes "d > 0"
  6540   obtains s :: "'a::euclidean_space set" where
  6534   obtains S :: "'a::euclidean_space set" where
  6541     "finite s" and "cbox (x - (\<Sum>i\<in>Basis. d*\<^sub>Ri)) (x + (\<Sum>i\<in>Basis. d*\<^sub>Ri)) = convex hull s"
  6535     "finite S" and "cbox (x - (\<Sum>i\<in>Basis. d*\<^sub>Ri)) (x + (\<Sum>i\<in>Basis. d*\<^sub>Ri)) = convex hull S"
  6542 proof -
  6536 proof -
  6543   let ?d = "(\<Sum>i\<in>Basis. d*\<^sub>Ri)::'a"
  6537   let ?d = "(\<Sum>i\<in>Basis. d *\<^sub>R i)::'a"
  6544   have *: "cbox (x - ?d) (x + ?d) = (\<lambda>y. x - ?d + (2 * d) *\<^sub>R y) ` cbox 0 (\<Sum>Basis)"
  6538   have *: "cbox (x - ?d) (x + ?d) = (\<lambda>y. x - ?d + (2 * d) *\<^sub>R y) ` cbox 0 (\<Sum>Basis)"
  6545     apply (rule set_eqI, rule)
  6539   proof (intro set_eqI iffI)
  6546     unfolding image_iff
       
  6547     defer
       
  6548     apply (erule bexE)
       
  6549   proof -
       
  6550     fix y
  6540     fix y
  6551     assume as: "y\<in>cbox (x - ?d) (x + ?d)"
  6541     assume "y \<in> cbox (x - ?d) (x + ?d)"
  6552     then have "inverse (2 * d) *\<^sub>R (y - (x - ?d)) \<in> cbox 0 (\<Sum>Basis)"
  6542     then have "inverse (2 * d) *\<^sub>R (y - (x - ?d)) \<in> cbox 0 (\<Sum>Basis)"
  6553       using assms by (simp add: mem_box field_simps inner_simps)
  6543       using assms by (simp add: mem_box field_simps inner_simps)
  6554     with \<open>0 < d\<close> show "\<exists>z\<in>cbox 0 (\<Sum>Basis). y = x - ?d + (2 * d) *\<^sub>R z"
  6544     with \<open>0 < d\<close> show "y \<in> (\<lambda>y. x - sum (( *\<^sub>R) d) Basis + (2 * d) *\<^sub>R y) ` cbox 0 One"
  6555       by (intro bexI[of _ "inverse (2 * d) *\<^sub>R (y - (x - ?d))"]) auto
  6545       by (auto intro: image_eqI[where x= "inverse (2 * d) *\<^sub>R (y - (x - ?d))"])
  6556   next
  6546   next
  6557     fix y z
  6547     fix y
  6558     assume as: "z\<in>cbox 0 (\<Sum>Basis)" "y = x - ?d + (2*d) *\<^sub>R z"
  6548     assume "y \<in> (\<lambda>y. x - ?d + (2 * d) *\<^sub>R y) ` cbox 0 One"
  6559     have "\<And>i. i\<in>Basis \<Longrightarrow> 0 \<le> d * (z \<bullet> i) \<and> d * (z \<bullet> i) \<le> d"
  6549     then obtain z where z: "z \<in> cbox 0 One" "y = x - ?d + (2*d) *\<^sub>R z"
  6560       using assms as(1)[unfolded mem_box]
       
  6561       by auto
  6550       by auto
  6562     then show "y \<in> cbox (x - ?d) (x + ?d)"
  6551     then show "y \<in> cbox (x - ?d) (x + ?d)"
  6563       unfolding as(2) mem_box
  6552       using z assms by (auto simp: mem_box inner_simps)
  6564       apply -
       
  6565       apply rule
       
  6566       using as(1)[unfolded mem_box]
       
  6567       apply (erule_tac x=i in ballE)
       
  6568       using assms
       
  6569       apply (auto simp: inner_simps)
       
  6570       done
       
  6571   qed
  6553   qed
  6572   obtain s where "finite s" "cbox 0 (\<Sum>Basis::'a) = convex hull s"
  6554   obtain S where "finite S" "cbox 0 (\<Sum>Basis::'a) = convex hull S"
  6573     using unit_cube_convex_hull by auto
  6555     using unit_cube_convex_hull by auto
  6574   then show ?thesis
  6556   then show ?thesis
  6575     apply (rule_tac that[of "(\<lambda>y. x - ?d + (2 * d) *\<^sub>R y)` s"])
  6557     by (rule_tac that[of "(\<lambda>y. x - ?d + (2 * d) *\<^sub>R y)` S"]) (auto simp: convex_hull_affinity *)
  6576     unfolding * and convex_hull_affinity
       
  6577     apply auto
       
  6578     done
       
  6579 qed
  6558 qed
  6580 
  6559 
  6581 subsection%unimportant\<open>Representation of any interval as a finite convex hull\<close>
  6560 subsection%unimportant\<open>Representation of any interval as a finite convex hull\<close>
  6582 
  6561 
  6583 lemma image_stretch_interval:
  6562 lemma image_stretch_interval:
  6633 apply (simp add: min_def max_def algebra_simps sum_subtractf euclidean_representation)
  6612 apply (simp add: min_def max_def algebra_simps sum_subtractf euclidean_representation)
  6634 done
  6613 done
  6635 
  6614 
  6636 lemma closed_interval_as_convex_hull:
  6615 lemma closed_interval_as_convex_hull:
  6637   fixes a :: "'a::euclidean_space"
  6616   fixes a :: "'a::euclidean_space"
  6638   obtains s where "finite s" "cbox a b = convex hull s"
  6617   obtains S where "finite S" "cbox a b = convex hull S"
  6639 proof (cases "cbox a b = {}")
  6618 proof (cases "cbox a b = {}")
  6640   case True with convex_hull_empty that show ?thesis
  6619   case True with convex_hull_empty that show ?thesis
  6641     by blast
  6620     by blast
  6642 next
  6621 next
  6643   case False
  6622   case False
  6644   obtain s::"'a set" where "finite s" and eq: "cbox 0 One = convex hull s"
  6623   obtain S::"'a set" where "finite S" and eq: "cbox 0 One = convex hull S"
  6645     by (blast intro: unit_cube_convex_hull)
  6624     by (blast intro: unit_cube_convex_hull)
  6646   have lin: "linear (\<lambda>x. \<Sum>k\<in>Basis. ((b \<bullet> k - a \<bullet> k) * (x \<bullet> k)) *\<^sub>R k)"
  6625   have lin: "linear (\<lambda>x. \<Sum>k\<in>Basis. ((b \<bullet> k - a \<bullet> k) * (x \<bullet> k)) *\<^sub>R k)"
  6647     by (rule linear_compose_sum) (auto simp: algebra_simps linearI)
  6626     by (rule linear_compose_sum) (auto simp: algebra_simps linearI)
  6648   have "finite ((+) a ` (\<lambda>x. \<Sum>k\<in>Basis. ((b \<bullet> k - a \<bullet> k) * (x \<bullet> k)) *\<^sub>R k) ` s)"
  6627   have "finite ((+) a ` (\<lambda>x. \<Sum>k\<in>Basis. ((b \<bullet> k - a \<bullet> k) * (x \<bullet> k)) *\<^sub>R k) ` S)"
  6649     by (rule finite_imageI \<open>finite s\<close>)+
  6628     by (rule finite_imageI \<open>finite S\<close>)+
  6650   then show ?thesis
  6629   then show ?thesis
  6651     apply (rule that)
  6630     apply (rule that)
  6652     apply (simp add: convex_hull_translation convex_hull_linear_image [OF lin, symmetric])
  6631     apply (simp add: convex_hull_translation convex_hull_linear_image [OF lin, symmetric])
  6653     apply (simp add: eq [symmetric] cbox_image_unit_interval [OF False])
  6632     apply (simp add: eq [symmetric] cbox_image_unit_interval [OF False])
  6654     done
  6633     done
  6656 
  6635 
  6657 
  6636 
  6658 subsection%unimportant \<open>Bounded convex function on open set is continuous\<close>
  6637 subsection%unimportant \<open>Bounded convex function on open set is continuous\<close>
  6659 
  6638 
  6660 lemma convex_on_bounded_continuous:
  6639 lemma convex_on_bounded_continuous:
  6661   fixes s :: "('a::real_normed_vector) set"
  6640   fixes S :: "('a::real_normed_vector) set"
  6662   assumes "open s"
  6641   assumes "open S"
  6663     and "convex_on s f"
  6642     and "convex_on S f"
  6664     and "\<forall>x\<in>s. \<bar>f x\<bar> \<le> b"
  6643     and "\<forall>x\<in>S. \<bar>f x\<bar> \<le> b"
  6665   shows "continuous_on s f"
  6644   shows "continuous_on S f"
  6666   apply (rule continuous_at_imp_continuous_on)
  6645   apply (rule continuous_at_imp_continuous_on)
  6667   unfolding continuous_at_real_range
  6646   unfolding continuous_at_real_range
  6668 proof (rule,rule,rule)
  6647 proof (rule,rule,rule)
  6669   fix x and e :: real
  6648   fix x and e :: real
  6670   assume "x \<in> s" "e > 0"
  6649   assume "x \<in> S" "e > 0"
  6671   define B where "B = \<bar>b\<bar> + 1"
  6650   define B where "B = \<bar>b\<bar> + 1"
  6672   have B: "0 < B" "\<And>x. x\<in>s \<Longrightarrow> \<bar>f x\<bar> \<le> B"
  6651   then have B:  "0 < B""\<And>x. x\<in>S \<Longrightarrow> \<bar>f x\<bar> \<le> B"
  6673     unfolding B_def
  6652     using assms(3) by auto 
  6674     defer
  6653   obtain k where "k > 0" and k: "cball x k \<subseteq> S"
  6675     apply (drule assms(3)[rule_format])
  6654     using \<open>x \<in> S\<close> assms(1) open_contains_cball_eq by blast
  6676     apply auto
       
  6677     done
       
  6678   obtain k where "k > 0" and k: "cball x k \<subseteq> s"
       
  6679     using assms(1)[unfolded open_contains_cball, THEN bspec[where x=x]]
       
  6680     using \<open>x\<in>s\<close> by auto
       
  6681   show "\<exists>d>0. \<forall>x'. norm (x' - x) < d \<longrightarrow> \<bar>f x' - f x\<bar> < e"
  6655   show "\<exists>d>0. \<forall>x'. norm (x' - x) < d \<longrightarrow> \<bar>f x' - f x\<bar> < e"
  6682     apply (rule_tac x="min (k / 2) (e / (2 * B) * k)" in exI)
  6656   proof (intro exI conjI allI impI)
  6683     apply rule
       
  6684     defer
       
  6685   proof (rule, rule)
       
  6686     fix y
  6657     fix y
  6687     assume as: "norm (y - x) < min (k / 2) (e / (2 * B) * k)"
  6658     assume as: "norm (y - x) < min (k / 2) (e / (2 * B) * k)"
  6688     show "\<bar>f y - f x\<bar> < e"
  6659     show "\<bar>f y - f x\<bar> < e"
  6689     proof (cases "y = x")
  6660     proof (cases "y = x")
  6690       case False
  6661       case False
  6691       define t where "t = k / norm (y - x)"
  6662       define t where "t = k / norm (y - x)"
  6692       have "2 < t" "0<t"
  6663       have "2 < t" "0<t"
  6693         unfolding t_def using as False and \<open>k>0\<close>
  6664         unfolding t_def using as False and \<open>k>0\<close>
  6694         by (auto simp:field_simps)
  6665         by (auto simp:field_simps)
  6695       have "y \<in> s"
  6666       have "y \<in> S"
  6696         apply (rule k[unfolded subset_eq,rule_format])
  6667         apply (rule k[THEN subsetD])
  6697         unfolding mem_cball dist_norm
  6668         unfolding mem_cball dist_norm
  6698         apply (rule order_trans[of _ "2 * norm (x - y)"])
  6669         apply (rule order_trans[of _ "2 * norm (x - y)"])
  6699         using as
  6670         using as
  6700         by (auto simp: field_simps norm_minus_commute)
  6671         by (auto simp: field_simps norm_minus_commute)
  6701       {
  6672       {
  6702         define w where "w = x + t *\<^sub>R (y - x)"
  6673         define w where "w = x + t *\<^sub>R (y - x)"
  6703         have "w \<in> s"
  6674         have "w \<in> S"
  6704           unfolding w_def
  6675           using \<open>k>0\<close> by (auto simp: dist_norm t_def w_def k[THEN subsetD])
  6705           apply (rule k[unfolded subset_eq,rule_format])
       
  6706           unfolding mem_cball dist_norm
       
  6707           unfolding t_def
       
  6708           using \<open>k>0\<close>
       
  6709           apply auto
       
  6710           done
       
  6711         have "(1 / t) *\<^sub>R x + - x + ((t - 1) / t) *\<^sub>R x = (1 / t - 1 + (t - 1) / t) *\<^sub>R x"
  6676         have "(1 / t) *\<^sub>R x + - x + ((t - 1) / t) *\<^sub>R x = (1 / t - 1 + (t - 1) / t) *\<^sub>R x"
  6712           by (auto simp: algebra_simps)
  6677           by (auto simp: algebra_simps)
  6713         also have "\<dots> = 0"
  6678         also have "\<dots> = 0"
  6714           using \<open>t > 0\<close> by (auto simp:field_simps)
  6679           using \<open>t > 0\<close> by (auto simp:field_simps)
  6715         finally have w: "(1 / t) *\<^sub>R w + ((t - 1) / t) *\<^sub>R x = y"
  6680         finally have w: "(1 / t) *\<^sub>R w + ((t - 1) / t) *\<^sub>R x = y"
  6718         have 2: "2 * B < e * t"
  6683         have 2: "2 * B < e * t"
  6719           unfolding t_def using \<open>0 < e\<close> \<open>0 < k\<close> \<open>B > 0\<close> and as and False
  6684           unfolding t_def using \<open>0 < e\<close> \<open>0 < k\<close> \<open>B > 0\<close> and as and False
  6720           by (auto simp:field_simps)
  6685           by (auto simp:field_simps)
  6721         have "f y - f x \<le> (f w - f x) / t"
  6686         have "f y - f x \<le> (f w - f x) / t"
  6722           using assms(2)[unfolded convex_on_def,rule_format,of w x "1/t" "(t - 1)/t", unfolded w]
  6687           using assms(2)[unfolded convex_on_def,rule_format,of w x "1/t" "(t - 1)/t", unfolded w]
  6723           using \<open>0 < t\<close> \<open>2 < t\<close> and \<open>x \<in> s\<close> \<open>w \<in> s\<close>
  6688           using \<open>0 < t\<close> \<open>2 < t\<close> and \<open>x \<in> S\<close> \<open>w \<in> S\<close>
  6724           by (auto simp:field_simps)
  6689           by (auto simp:field_simps)
  6725         also have "... < e"
  6690         also have "... < e"
  6726           using B(2)[OF \<open>w\<in>s\<close>] and B(2)[OF \<open>x\<in>s\<close>] 2 \<open>t > 0\<close> by (auto simp: field_simps)
  6691           using B(2)[OF \<open>w\<in>S\<close>] and B(2)[OF \<open>x\<in>S\<close>] 2 \<open>t > 0\<close> by (auto simp: field_simps)
  6727         finally have th1: "f y - f x < e" .
  6692         finally have th1: "f y - f x < e" .
  6728       }
  6693       }
  6729       moreover
  6694       moreover
  6730       {
  6695       {
  6731         define w where "w = x - t *\<^sub>R (y - x)"
  6696         define w where "w = x - t *\<^sub>R (y - x)"
  6732         have "w \<in> s"
  6697         have "w \<in> S"
  6733           unfolding w_def
  6698           using \<open>k > 0\<close> by (auto simp: dist_norm t_def w_def k[THEN subsetD])
  6734           apply (rule k[unfolded subset_eq,rule_format])
       
  6735           unfolding mem_cball dist_norm
       
  6736           unfolding t_def
       
  6737           using \<open>k > 0\<close>
       
  6738           apply auto
       
  6739           done
       
  6740         have "(1 / (1 + t)) *\<^sub>R x + (t / (1 + t)) *\<^sub>R x = (1 / (1 + t) + t / (1 + t)) *\<^sub>R x"
  6699         have "(1 / (1 + t)) *\<^sub>R x + (t / (1 + t)) *\<^sub>R x = (1 / (1 + t) + t / (1 + t)) *\<^sub>R x"
  6741           by (auto simp: algebra_simps)
  6700           by (auto simp: algebra_simps)
  6742         also have "\<dots> = x"
  6701         also have "\<dots> = x"
  6743           using \<open>t > 0\<close> by (auto simp:field_simps)
  6702           using \<open>t > 0\<close> by (auto simp:field_simps)
  6744         finally have w: "(1 / (1+t)) *\<^sub>R w + (t / (1 + t)) *\<^sub>R y = x"
  6703         finally have w: "(1 / (1+t)) *\<^sub>R w + (t / (1 + t)) *\<^sub>R y = x"
  6747         have "2 * B < e * t"
  6706         have "2 * B < e * t"
  6748           unfolding t_def
  6707           unfolding t_def
  6749           using \<open>0 < e\<close> \<open>0 < k\<close> \<open>B > 0\<close> and as and False
  6708           using \<open>0 < e\<close> \<open>0 < k\<close> \<open>B > 0\<close> and as and False
  6750           by (auto simp:field_simps)
  6709           by (auto simp:field_simps)
  6751         then have *: "(f w - f y) / t < e"
  6710         then have *: "(f w - f y) / t < e"
  6752           using B(2)[OF \<open>w\<in>s\<close>] and B(2)[OF \<open>y\<in>s\<close>]
  6711           using B(2)[OF \<open>w\<in>S\<close>] and B(2)[OF \<open>y\<in>S\<close>]
  6753           using \<open>t > 0\<close>
  6712           using \<open>t > 0\<close>
  6754           by (auto simp:field_simps)
  6713           by (auto simp:field_simps)
  6755         have "f x \<le> 1 / (1 + t) * f w + (t / (1 + t)) * f y"
  6714         have "f x \<le> 1 / (1 + t) * f w + (t / (1 + t)) * f y"
  6756           using assms(2)[unfolded convex_on_def,rule_format,of w y "1/(1+t)" "t / (1+t)",unfolded w]
  6715           using assms(2)[unfolded convex_on_def,rule_format,of w y "1/(1+t)" "t / (1+t)",unfolded w]
  6757           using \<open>0 < t\<close> \<open>2 < t\<close> and \<open>y \<in> s\<close> \<open>w \<in> s\<close>
  6716           using \<open>0 < t\<close> \<open>2 < t\<close> and \<open>y \<in> S\<close> \<open>w \<in> S\<close>
  6758           by (auto simp:field_simps)
  6717           by (auto simp:field_simps)
  6759         also have "\<dots> = (f w + t * f y) / (1 + t)"
  6718         also have "\<dots> = (f w + t * f y) / (1 + t)"
  6760           using \<open>t > 0\<close> by (auto simp: divide_simps)
  6719           using \<open>t > 0\<close> by (auto simp: divide_simps)
  6761         also have "\<dots> < e + f y"
  6720         also have "\<dots> < e + f y"
  6762           using \<open>t > 0\<close> * \<open>e > 0\<close> by (auto simp: field_simps)
  6721           using \<open>t > 0\<close> * \<open>e > 0\<close> by (auto simp: field_simps)
  6841       done
  6800       done
  6842     then have 2: "convex hull c = {a. \<forall>i\<in>Basis. a \<bullet> i \<in> cball (x \<bullet> i) d}"
  6801     then have 2: "convex hull c = {a. \<forall>i\<in>Basis. a \<bullet> i \<in> cball (x \<bullet> i) d}"
  6843       by (simp add: dist_norm abs_le_iff algebra_simps)
  6802       by (simp add: dist_norm abs_le_iff algebra_simps)
  6844     show "cball x d \<subseteq> convex hull c"
  6803     show "cball x d \<subseteq> convex hull c"
  6845       unfolding 2
  6804       unfolding 2
  6846       apply clarsimp
  6805       by (clarsimp simp: dist_norm) (metis inner_commute inner_diff_right norm_bound_Basis_le)
  6847       apply (simp only: dist_norm)
       
  6848       apply (subst inner_diff_left [symmetric], simp)
       
  6849       apply (erule (1) order_trans [OF Basis_le_norm])
       
  6850       done
       
  6851     have e': "e = (\<Sum>(i::'a)\<in>Basis. d)"
  6806     have e': "e = (\<Sum>(i::'a)\<in>Basis. d)"
  6852       by (simp add: d_def DIM_positive)
  6807       by (simp add: d_def DIM_positive)
  6853     show "convex hull c \<subseteq> cball x e"
  6808     show "convex hull c \<subseteq> cball x e"
  6854       unfolding 2
  6809       unfolding 2
  6855       apply clarsimp
  6810       apply clarsimp