src/HOL/Multivariate_Analysis/Convex_Euclidean_Space.thy
changeset 62381 a6479cb85944
parent 62131 1baed43f453e
child 62393 a620a8756b7c
child 62397 5ae24f33d343
equal deleted inserted replaced
62379:340738057c8c 62381:a6479cb85944
   322   fixes x :: "'a::real_vector"
   322   fixes x :: "'a::real_vector"
   323   shows "scaleR 2 x = x + x"
   323   shows "scaleR 2 x = x + x"
   324   unfolding one_add_one [symmetric] scaleR_left_distrib by simp
   324   unfolding one_add_one [symmetric] scaleR_left_distrib by simp
   325 
   325 
   326 lemma vector_choose_size:
   326 lemma vector_choose_size:
   327   "0 \<le> c \<Longrightarrow> \<exists>x::'a::euclidean_space. norm x = c"
   327   assumes "0 \<le> c"
   328   apply (rule exI [where x="c *\<^sub>R (SOME i. i \<in> Basis)"])
   328   obtains x :: "'a::{real_normed_vector, perfect_space}" where "norm x = c"
   329   apply (auto simp: SOME_Basis)
   329 proof -
   330   done
   330   obtain a::'a where "a \<noteq> 0"
       
   331     using UNIV_not_singleton UNIV_eq_I set_zero singletonI by fastforce
       
   332   then show ?thesis
       
   333     by (rule_tac x="scaleR (c / norm a) a" in that) (simp add: assms)
       
   334 qed
       
   335 
       
   336 lemma vector_choose_dist:
       
   337   assumes "0 \<le> c"
       
   338   obtains y :: "'a::{real_normed_vector, perfect_space}" where "dist x y = c"
       
   339 by (metis add_diff_cancel_left' assms dist_commute dist_norm vector_choose_size)
       
   340 
       
   341 lemma sphere_eq_empty [simp]:
       
   342   fixes a :: "'a::{real_normed_vector, perfect_space}"
       
   343   shows "sphere a r = {} \<longleftrightarrow> r < 0"
       
   344 by (auto simp: sphere_def dist_norm) (metis dist_norm le_less_linear vector_choose_dist)
   331 
   345 
   332 lemma setsum_delta_notmem:
   346 lemma setsum_delta_notmem:
   333   assumes "x \<notin> s"
   347   assumes "x \<notin> s"
   334   shows "setsum (\<lambda>y. if (y = x) then P x else Q y) s = setsum Q s"
   348   shows "setsum (\<lambda>y. if (y = x) then P x else Q y) s = setsum Q s"
   335     and "setsum (\<lambda>y. if (x = y) then P x else Q y) s = setsum Q s"
   349     and "setsum (\<lambda>y. if (x = y) then P x else Q y) s = setsum Q s"
  4298     and "s \<noteq> {}"
  4312     and "s \<noteq> {}"
  4299   shows "closest_point s a \<in> s"
  4313   shows "closest_point s a \<in> s"
  4300     and "\<forall>y\<in>s. dist a (closest_point s a) \<le> dist a y"
  4314     and "\<forall>y\<in>s. dist a (closest_point s a) \<le> dist a y"
  4301   unfolding closest_point_def
  4315   unfolding closest_point_def
  4302   apply(rule_tac[!] someI2_ex)
  4316   apply(rule_tac[!] someI2_ex)
  4303   using distance_attains_inf[OF assms(1,2), of a]
  4317   apply (auto intro: distance_attains_inf[OF assms(1,2), of a])
  4304   apply auto
       
  4305   done
  4318   done
  4306 
  4319 
  4307 lemma closest_point_in_set: "closed s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> closest_point s a \<in> s"
  4320 lemma closest_point_in_set: "closed s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> closest_point s a \<in> s"
  4308   by (meson closest_point_exists)
  4321   by (meson closest_point_exists)
  4309 
  4322 
  4444     and "closed s"
  4457     and "closed s"
  4445     and "s \<noteq> {}"
  4458     and "s \<noteq> {}"
  4446     and "z \<notin> s"
  4459     and "z \<notin> s"
  4447   shows "\<exists>a b. \<exists>y\<in>s. inner a z < b \<and> inner a y = b \<and> (\<forall>x\<in>s. inner a x \<ge> b)"
  4460   shows "\<exists>a b. \<exists>y\<in>s. inner a z < b \<and> inner a y = b \<and> (\<forall>x\<in>s. inner a x \<ge> b)"
  4448 proof -
  4461 proof -
  4449   from distance_attains_inf[OF assms(2-3)]
       
  4450   obtain y where "y \<in> s" and y: "\<forall>x\<in>s. dist z y \<le> dist z x"
  4462   obtain y where "y \<in> s" and y: "\<forall>x\<in>s. dist z y \<le> dist z x"
  4451     by auto
  4463     by (metis distance_attains_inf[OF assms(2-3)]) 
  4452   show ?thesis
  4464   show ?thesis
  4453     apply (rule_tac x="y - z" in exI)
  4465     apply (rule_tac x="y - z" in exI)
  4454     apply (rule_tac x="inner (y - z) y" in exI)
  4466     apply (rule_tac x="inner (y - z) y" in exI)
  4455     apply (rule_tac x=y in bexI)
  4467     apply (rule_tac x=y in bexI)
  4456     apply rule
  4468     apply rule
  4495     apply auto
  4507     apply auto
  4496     done
  4508     done
  4497 next
  4509 next
  4498   case False
  4510   case False
  4499   obtain y where "y \<in> s" and y: "\<forall>x\<in>s. dist z y \<le> dist z x"
  4511   obtain y where "y \<in> s" and y: "\<forall>x\<in>s. dist z y \<le> dist z x"
  4500     using distance_attains_inf[OF assms(2) False] by auto
  4512     by (metis distance_attains_inf[OF assms(2) False])
  4501   show ?thesis
  4513   show ?thesis
  4502     apply (rule_tac x="y - z" in exI)
  4514     apply (rule_tac x="y - z" in exI)
  4503     apply (rule_tac x="inner (y - z) z + (norm (y - z))\<^sup>2 / 2" in exI)
  4515     apply (rule_tac x="inner (y - z) z + (norm (y - z))\<^sup>2 / 2" in exI)
  4504     apply rule
  4516     apply rule
  4505     defer
  4517     defer
  4655 lemma separating_hyperplane_set_0:
  4667 lemma separating_hyperplane_set_0:
  4656   assumes "convex s" "(0::'a::euclidean_space) \<notin> s"
  4668   assumes "convex s" "(0::'a::euclidean_space) \<notin> s"
  4657   shows "\<exists>a. a \<noteq> 0 \<and> (\<forall>x\<in>s. 0 \<le> inner a x)"
  4669   shows "\<exists>a. a \<noteq> 0 \<and> (\<forall>x\<in>s. 0 \<le> inner a x)"
  4658 proof -
  4670 proof -
  4659   let ?k = "\<lambda>c. {x::'a. 0 \<le> inner c x}"
  4671   let ?k = "\<lambda>c. {x::'a. 0 \<le> inner c x}"
  4660   have "frontier (cball 0 1) \<inter> (\<Inter>(?k ` s)) \<noteq> {}"
  4672   have *: "frontier (cball 0 1) \<inter> \<Inter>f \<noteq> {}" if as: "f \<subseteq> ?k ` s" "finite f" for f
  4661     apply (rule compact_imp_fip)
       
  4662     apply (rule compact_frontier[OF compact_cball])
       
  4663     defer
       
  4664     apply rule
       
  4665     apply rule
       
  4666     apply (erule conjE)
       
  4667   proof -
  4673   proof -
  4668     fix f
       
  4669     assume as: "f \<subseteq> ?k ` s" "finite f"
       
  4670     obtain c where c: "f = ?k ` c" "c \<subseteq> s" "finite c"
  4674     obtain c where c: "f = ?k ` c" "c \<subseteq> s" "finite c"
  4671       using finite_subset_image[OF as(2,1)] by auto
  4675       using finite_subset_image[OF as(2,1)] by auto
  4672     then obtain a b where ab: "a \<noteq> 0" "0 < b" "\<forall>x\<in>convex hull c. b < inner a x"
  4676     then obtain a b where ab: "a \<noteq> 0" "0 < b" "\<forall>x\<in>convex hull c. b < inner a x"
  4673       using separating_hyperplane_closed_0[OF convex_convex_hull, of c]
  4677       using separating_hyperplane_closed_0[OF convex_convex_hull, of c]
  4674       using finite_imp_compact_convex_hull[OF c(3), THEN compact_imp_closed] and assms(2)
  4678       using finite_imp_compact_convex_hull[OF c(3), THEN compact_imp_closed] and assms(2)
  4678       apply (rule_tac x = "inverse(norm a) *\<^sub>R a" in exI)
  4682       apply (rule_tac x = "inverse(norm a) *\<^sub>R a" in exI)
  4679       using hull_subset[of c convex]
  4683       using hull_subset[of c convex]
  4680       unfolding subset_eq and inner_scaleR
  4684       unfolding subset_eq and inner_scaleR
  4681       by (auto simp add: inner_commute del: ballE elim!: ballE)
  4685       by (auto simp add: inner_commute del: ballE elim!: ballE)
  4682     then show "frontier (cball 0 1) \<inter> \<Inter>f \<noteq> {}"
  4686     then show "frontier (cball 0 1) \<inter> \<Inter>f \<noteq> {}"
  4683       unfolding c(1) frontier_cball dist_norm by auto
  4687       unfolding c(1) frontier_cball sphere_def dist_norm by auto
  4684   qed (insert closed_halfspace_ge, auto)
  4688   qed
       
  4689   have "frontier (cball 0 1) \<inter> (\<Inter>(?k ` s)) \<noteq> {}"
       
  4690     apply (rule compact_imp_fip)
       
  4691     apply (rule compact_frontier[OF compact_cball])
       
  4692     using * closed_halfspace_ge
       
  4693     by auto
  4685   then obtain x where "norm x = 1" "\<forall>y\<in>s. x\<in>?k y"
  4694   then obtain x where "norm x = 1" "\<forall>y\<in>s. x\<in>?k y"
  4686     unfolding frontier_cball dist_norm by auto
  4695     unfolding frontier_cball dist_norm sphere_def by auto
  4687   then show ?thesis
  4696   then show ?thesis
  4688     apply (rule_tac x=x in exI)
  4697     by (metis inner_commute mem_Collect_eq norm_eq_zero zero_neq_one)
  4689     apply (auto simp add: inner_commute)
       
  4690     done
       
  4691 qed
  4698 qed
  4692 
  4699 
  4693 lemma separating_hyperplane_sets:
  4700 lemma separating_hyperplane_sets:
  4694   fixes s t :: "'a::euclidean_space set"
  4701   fixes s t :: "'a::euclidean_space set"
  4695   assumes "convex s"
  4702   assumes "convex s"
  9926 proof -
  9933 proof -
  9927   have "{x - y |x y. x \<in> s \<and> y \<in> t} \<noteq> {}"
  9934   have "{x - y |x y. x \<in> s \<and> y \<in> t} \<noteq> {}"
  9928     using assms by blast
  9935     using assms by blast
  9929   then
  9936   then
  9930   have "\<exists>x \<in> s. \<exists>y \<in> t. dist x y \<le> setdist s t"
  9937   have "\<exists>x \<in> s. \<exists>y \<in> t. dist x y \<le> setdist s t"
  9931     using  distance_attains_inf [where a=0, OF compact_closed_differences [OF s t]] assms
  9938     apply (rule distance_attains_inf [where a=0, OF compact_closed_differences [OF s t]])
  9932     apply (clarsimp simp: dist_norm le_setdist_iff, blast)
  9939     apply (simp add: dist_norm le_setdist_iff)
       
  9940     apply blast
  9933     done
  9941     done
  9934   then show ?thesis
  9942   then show ?thesis
  9935     by (blast intro!: antisym [OF _ setdist_le_dist] )
  9943     by (blast intro!: antisym [OF _ setdist_le_dist] )
  9936 qed
  9944 qed
  9937 
  9945 
 10007 using closure_subset by force
 10015 using closure_subset by force
 10008 
 10016 
 10009 lemma setdist_le_sing: "x \<in> s ==> setdist s t \<le> setdist {x} t"
 10017 lemma setdist_le_sing: "x \<in> s ==> setdist s t \<le> setdist {x} t"
 10010   using setdist_subset_left by auto
 10018   using setdist_subset_left by auto
 10011 
 10019 
 10012 
       
 10013 end
 10020 end