src/HOL/Analysis/Convex_Euclidean_Space.thy
changeset 68072 493b818e8e10
parent 67982 7643b005b29a
child 68073 fad29d2a17a5
equal deleted inserted replaced
68001:0a2a1b6507c1 68072:493b818e8e10
    25     apply (rule continuous_on_compose)
    25     apply (rule continuous_on_compose)
    26     apply (simp add: split_def)
    26     apply (simp add: split_def)
    27     apply (rule continuous_intros | simp add: assms)+
    27     apply (rule continuous_intros | simp add: assms)+
    28     done
    28     done
    29 qed
    29 qed
    30 
       
    31 lemma dim_image_eq:
       
    32   fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space"
       
    33   assumes lf: "linear f"
       
    34     and fi: "inj_on f (span S)"
       
    35   shows "dim (f ` S) = dim (S::'n::euclidean_space set)"
       
    36 proof -
       
    37   obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S"
       
    38     using basis_exists[of S] by auto
       
    39   then have "span S = span B"
       
    40     using span_mono[of B S] span_mono[of S "span B"] span_span[of B] by auto
       
    41   then have "independent (f ` B)"
       
    42     using independent_inj_on_image[of B f] B assms by auto
       
    43   moreover have "card (f ` B) = card B"
       
    44     using assms card_image[of f B] subset_inj_on[of f "span S" B] B span_inc by auto
       
    45   moreover have "(f ` B) \<subseteq> (f ` S)"
       
    46     using B by auto
       
    47   ultimately have "dim (f ` S) \<ge> dim S"
       
    48     using independent_card_le_dim[of "f ` B" "f ` S"] B by auto
       
    49   then show ?thesis
       
    50     using dim_image_le[of f S] assms by auto
       
    51 qed
       
    52 
       
    53 lemma linear_injective_on_subspace_0:
       
    54   assumes lf: "linear f"
       
    55     and "subspace S"
       
    56   shows "inj_on f S \<longleftrightarrow> (\<forall>x \<in> S. f x = 0 \<longrightarrow> x = 0)"
       
    57 proof -
       
    58   have "inj_on f S \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y \<in> S. f x = f y \<longrightarrow> x = y)"
       
    59     by (simp add: inj_on_def)
       
    60   also have "\<dots> \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y \<in> S. f x - f y = 0 \<longrightarrow> x - y = 0)"
       
    61     by simp
       
    62   also have "\<dots> \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y \<in> S. f (x - y) = 0 \<longrightarrow> x - y = 0)"
       
    63     by (simp add: linear_diff[OF lf])
       
    64   also have "\<dots> \<longleftrightarrow> (\<forall>x \<in> S. f x = 0 \<longrightarrow> x = 0)"
       
    65     using \<open>subspace S\<close> subspace_def[of S] subspace_diff[of S] by auto
       
    66   finally show ?thesis .
       
    67 qed
       
    68 
       
    69 lemma subspace_Inter: "\<forall>s \<in> f. subspace s \<Longrightarrow> subspace (\<Inter>f)"
       
    70   unfolding subspace_def by auto
       
    71 
       
    72 lemma span_eq[simp]: "span s = s \<longleftrightarrow> subspace s"
       
    73   unfolding span_def by (rule hull_eq) (rule subspace_Inter)
       
    74 
    30 
    75 lemma substdbasis_expansion_unique:
    31 lemma substdbasis_expansion_unique:
    76   assumes d: "d \<subseteq> Basis"
    32   assumes d: "d \<subseteq> Basis"
    77   shows "(\<Sum>i\<in>d. f i *\<^sub>R i) = (x::'a::euclidean_space) \<longleftrightarrow>
    33   shows "(\<Sum>i\<in>d. f i *\<^sub>R i) = (x::'a::euclidean_space) \<longleftrightarrow>
    78     (\<forall>i\<in>Basis. (i \<in> d \<longrightarrow> f i = x \<bullet> i) \<and> (i \<notin> d \<longrightarrow> x \<bullet> i = 0))"
    34     (\<forall>i\<in>Basis. (i \<in> d \<longrightarrow> f i = x \<bullet> i) \<and> (i \<notin> d \<longrightarrow> x \<bullet> i = 0))"
   103     moreover have *: "x = (norm x / e) *\<^sub>R y"
    59     moreover have *: "x = (norm x / e) *\<^sub>R y"
   104       using y_def assms by simp
    60       using y_def assms by simp
   105     moreover from * have "x = (norm x/e) *\<^sub>R y"
    61     moreover from * have "x = (norm x/e) *\<^sub>R y"
   106       by auto
    62       by auto
   107     ultimately have "x \<in> span (cball 0 e)"
    63     ultimately have "x \<in> span (cball 0 e)"
   108       using span_mul[of y "cball 0 e" "norm x/e"] span_inc[of "cball 0 e"]
    64       using span_scale[of y "cball 0 e" "norm x/e"]
   109       by (simp add: span_superset)
    65         span_superset[of "cball 0 e"]
       
    66       by (simp add: span_base)
   110   }
    67   }
   111   then have "span (cball 0 e) = (UNIV :: 'n::euclidean_space set)"
    68   then have "span (cball 0 e) = (UNIV :: 'n::euclidean_space set)"
   112     by auto
    69     by auto
   113   then show ?thesis
    70   then show ?thesis
   114     using dim_span[of "cball (0 :: 'n::euclidean_space) e"] by (auto simp add: dim_UNIV)
    71     using dim_span[of "cball (0 :: 'n::euclidean_space) e"]
   115 qed
    72     by auto
   116 
    73 qed
   117 lemma indep_card_eq_dim_span:
       
   118   fixes B :: "'n::euclidean_space set"
       
   119   assumes "independent B"
       
   120   shows "finite B \<and> card B = dim (span B)"
       
   121   using assms basis_card_eq_dim[of B "span B"] span_inc by auto
       
   122 
    74 
   123 lemma sum_not_0: "sum f A \<noteq> 0 \<Longrightarrow> \<exists>a \<in> A. f a \<noteq> 0"
    75 lemma sum_not_0: "sum f A \<noteq> 0 \<Longrightarrow> \<exists>a \<in> A. f a \<noteq> 0"
   124   by (rule ccontr) auto
    76   by (rule ccontr) auto
   125 
    77 
   126 lemma subset_translation_eq [simp]:
    78 lemma subset_translation_eq [simp]:
  1216 lemma convex_linear_image_eq [simp]:
  1168 lemma convex_linear_image_eq [simp]:
  1217     fixes f :: "'a::real_vector \<Rightarrow> 'b::real_vector"
  1169     fixes f :: "'a::real_vector \<Rightarrow> 'b::real_vector"
  1218     shows "\<lbrakk>linear f; inj f\<rbrakk> \<Longrightarrow> convex (f ` s) \<longleftrightarrow> convex s"
  1170     shows "\<lbrakk>linear f; inj f\<rbrakk> \<Longrightarrow> convex (f ` s) \<longleftrightarrow> convex s"
  1219     by (metis (no_types) convex_linear_image convex_linear_vimage inj_vimage_image_eq)
  1171     by (metis (no_types) convex_linear_image convex_linear_vimage inj_vimage_image_eq)
  1220 
  1172 
  1221 lemma basis_to_basis_subspace_isomorphism:
       
  1222   assumes s: "subspace (S:: ('n::euclidean_space) set)"
       
  1223     and t: "subspace (T :: ('m::euclidean_space) set)"
       
  1224     and d: "dim S = dim T"
       
  1225     and B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S"
       
  1226     and C: "C \<subseteq> T" "independent C" "T \<subseteq> span C" "card C = dim T"
       
  1227   shows "\<exists>f. linear f \<and> f ` B = C \<and> f ` S = T \<and> inj_on f S"
       
  1228 proof -
       
  1229   from B independent_bound have fB: "finite B"
       
  1230     by blast
       
  1231   from C independent_bound have fC: "finite C"
       
  1232     by blast
       
  1233   from B(4) C(4) card_le_inj[of B C] d obtain f where
       
  1234     f: "f ` B \<subseteq> C" "inj_on f B" using \<open>finite B\<close> \<open>finite C\<close> by auto
       
  1235   from linear_independent_extend[OF B(2)] obtain g where
       
  1236     g: "linear g" "\<forall>x \<in> B. g x = f x" by blast
       
  1237   from inj_on_iff_eq_card[OF fB, of f] f(2)
       
  1238   have "card (f ` B) = card B" by simp
       
  1239   with B(4) C(4) have ceq: "card (f ` B) = card C" using d
       
  1240     by simp
       
  1241   have "g ` B = f ` B" using g(2)
       
  1242     by (auto simp add: image_iff)
       
  1243   also have "\<dots> = C" using card_subset_eq[OF fC f(1) ceq] .
       
  1244   finally have gBC: "g ` B = C" .
       
  1245   have gi: "inj_on g B" using f(2) g(2)
       
  1246     by (auto simp add: inj_on_def)
       
  1247   note g0 = linear_indep_image_lemma[OF g(1) fB, unfolded gBC, OF C(2) gi]
       
  1248   {
       
  1249     fix x y
       
  1250     assume x: "x \<in> S" and y: "y \<in> S" and gxy: "g x = g y"
       
  1251     from B(3) x y have x': "x \<in> span B" and y': "y \<in> span B"
       
  1252       by blast+
       
  1253     from gxy have th0: "g (x - y) = 0"
       
  1254       by (simp add: linear_diff[OF g(1)])
       
  1255     have th1: "x - y \<in> span B" using x' y'
       
  1256       by (metis span_diff)
       
  1257     have "x = y" using g0[OF th1 th0] by simp
       
  1258   }
       
  1259   then have giS: "inj_on g S" unfolding inj_on_def by blast
       
  1260   from span_subspace[OF B(1,3) s]
       
  1261   have "g ` S = span (g ` B)"
       
  1262     by (simp add: span_linear_image[OF g(1)])
       
  1263   also have "\<dots> = span C"
       
  1264     unfolding gBC ..
       
  1265   also have "\<dots> = T"
       
  1266     using span_subspace[OF C(1,3) t] .
       
  1267   finally have gS: "g ` S = T" .
       
  1268   from g(1) gS giS gBC show ?thesis
       
  1269     by blast
       
  1270 qed
       
  1271 
       
  1272 lemma closure_bounded_linear_image_subset:
  1173 lemma closure_bounded_linear_image_subset:
  1273   assumes f: "bounded_linear f"
  1174   assumes f: "bounded_linear f"
  1274   shows "f ` closure S \<subseteq> closure (f ` S)"
  1175   shows "f ` closure S \<subseteq> closure (f ` S)"
  1275   using linear_continuous_on [OF f] closed_closure closure_subset
  1176   using linear_continuous_on [OF f] closed_closure closure_subset
  1276   by (rule image_closure_subset)
  1177   by (rule image_closure_subset)
  1818 proof -
  1719 proof -
  1819   fix x t u
  1720   fix x t u
  1820   assume as: "finite t" "t \<noteq> {}" "t \<subseteq> insert a s" "sum u t = 1" "(\<Sum>v\<in>t. u v *\<^sub>R v) = x"
  1721   assume as: "finite t" "t \<noteq> {}" "t \<subseteq> insert a s" "sum u t = 1" "(\<Sum>v\<in>t. u v *\<^sub>R v) = x"
  1821   have "(\<lambda>x. x - a) ` (t - {a}) \<subseteq> {x - a |x. x \<in> s}"
  1722   have "(\<lambda>x. x - a) ` (t - {a}) \<subseteq> {x - a |x. x \<in> s}"
  1822     using as(3) by auto
  1723     using as(3) by auto
  1823   then show "\<exists>v. x = a + v \<and> (\<exists>S u. finite S \<and> S \<subseteq> {x - a |x. x \<in> s} \<and> (\<Sum>v\<in>S. u v *\<^sub>R v) = v)"
  1724   then show "\<exists>v. x = a + v \<and> (\<exists>S u. v = (\<Sum>v\<in>S. u v *\<^sub>R v) \<and> finite S \<and> S \<subseteq> {x - a |x. x \<in> s} )"
  1824     apply (rule_tac x="x - a" in exI)
  1725     apply (rule_tac x="x - a" in exI)
  1825     apply (rule conjI, simp)
  1726     apply (rule conjI, simp)
  1826     apply (rule_tac x="(\<lambda>x. x - a) ` (t - {a})" in exI)
  1727     apply (rule_tac x="(\<lambda>x. x - a) ` (t - {a})" in exI)
  1827     apply (rule_tac x="\<lambda>x. u (x + a)" in exI)
  1728     apply (rule_tac x="\<lambda>x. u (x + a)" in exI)
  1828     apply (rule conjI) using as(1) apply simp
  1729     by (simp_all add: as sum.reindex[unfolded inj_on_def] scaleR_right_diff_distrib
  1829     apply (erule conjI)
  1730         sum_subtractf scaleR_left.sum[symmetric] sum_diff1 scaleR_left_diff_distrib)
  1830     using as(1)
       
  1831     apply (simp add: sum.reindex[unfolded inj_on_def] scaleR_right_diff_distrib
       
  1832       sum_subtractf scaleR_left.sum[symmetric] sum_diff1 scaleR_left_diff_distrib)
       
  1833     unfolding as
       
  1834     apply simp
       
  1835     done
       
  1836 qed
  1731 qed
  1837 
  1732 
  1838 lemma affine_hull_insert_span:
  1733 lemma affine_hull_insert_span:
  1839   assumes "a \<notin> s"
  1734   assumes "a \<notin> s"
  1840   shows "affine hull (insert a s) = {a + v | v . v \<in> span {x - a | x.  x \<in> s}}"
  1735   shows "affine hull (insert a s) = {a + v | v . v \<in> span {x - a | x.  x \<in> s}}"
  2111 
  2006 
  2112 lemma cone_Inter[intro]: "\<forall>s\<in>f. cone s \<Longrightarrow> cone (\<Inter>f)"
  2007 lemma cone_Inter[intro]: "\<forall>s\<in>f. cone s \<Longrightarrow> cone (\<Inter>f)"
  2113   unfolding cone_def by auto
  2008   unfolding cone_def by auto
  2114 
  2009 
  2115 lemma subspace_imp_cone: "subspace S \<Longrightarrow> cone S"
  2010 lemma subspace_imp_cone: "subspace S \<Longrightarrow> cone S"
  2116   by (simp add: cone_def subspace_mul)
  2011   by (simp add: cone_def subspace_scale)
  2117 
  2012 
  2118 
  2013 
  2119 subsubsection \<open>Conic hull\<close>
  2014 subsubsection \<open>Conic hull\<close>
  2120 
  2015 
  2121 lemma cone_cone_hull: "cone (cone hull s)"
  2016 lemma cone_cone_hull: "cone (cone hull s)"
  3151 
  3046 
  3152 lemma subspace_imp_convex: "subspace s \<Longrightarrow> convex s"
  3047 lemma subspace_imp_convex: "subspace s \<Longrightarrow> convex s"
  3153   using subspace_imp_affine affine_imp_convex by auto
  3048   using subspace_imp_affine affine_imp_convex by auto
  3154 
  3049 
  3155 lemma affine_hull_subset_span: "(affine hull s) \<subseteq> (span s)"
  3050 lemma affine_hull_subset_span: "(affine hull s) \<subseteq> (span s)"
  3156   by (metis hull_minimal span_inc subspace_imp_affine subspace_span)
  3051   by (metis hull_minimal span_superset subspace_imp_affine subspace_span)
  3157 
  3052 
  3158 lemma convex_hull_subset_span: "(convex hull s) \<subseteq> (span s)"
  3053 lemma convex_hull_subset_span: "(convex hull s) \<subseteq> (span s)"
  3159   by (metis hull_minimal span_inc subspace_imp_convex subspace_span)
  3054   by (metis hull_minimal span_superset subspace_imp_convex subspace_span)
  3160 
  3055 
  3161 lemma convex_hull_subset_affine_hull: "(convex hull s) \<subseteq> (affine hull s)"
  3056 lemma convex_hull_subset_affine_hull: "(convex hull s) \<subseteq> (affine hull s)"
  3162   by (metis affine_affine_hull affine_imp_convex hull_minimal hull_subset)
  3057   by (metis affine_affine_hull affine_imp_convex hull_minimal hull_subset)
  3163 
  3058 
  3164 lemma affine_dependent_imp_dependent: "affine_dependent s \<Longrightarrow> dependent s"
  3059 lemma affine_dependent_imp_dependent: "affine_dependent s \<Longrightarrow> dependent s"
  3287     done
  3182     done
  3288   have "dim {x - a |x. x \<in> s - {a}} \<le> dim s"
  3183   have "dim {x - a |x. x \<in> s - {a}} \<le> dim s"
  3289     apply (rule subset_le_dim)
  3184     apply (rule subset_le_dim)
  3290     unfolding subset_eq
  3185     unfolding subset_eq
  3291     using \<open>a\<in>s\<close>
  3186     using \<open>a\<in>s\<close>
  3292     apply (auto simp add:span_superset span_diff)
  3187     apply (auto simp add:span_base span_diff)
  3293     done
  3188     done
  3294   also have "\<dots> < dim s + 1" by auto
  3189   also have "\<dots> < dim s + 1" by auto
  3295   also have "\<dots> \<le> card (s - {a})"
  3190   also have "\<dots> \<le> card (s - {a})"
  3296     using assms
  3191     using assms
  3297     using card_Diff_singleton[OF assms(1) \<open>a\<in>s\<close>]
  3192     using card_Diff_singleton[OF assms(1) \<open>a\<in>s\<close>]
  3658       using aff_dim_parallel_subspace_aux assms by auto
  3553       using aff_dim_parallel_subspace_aux assms by auto
  3659   }
  3554   }
  3660   then show ?thesis by auto
  3555   then show ?thesis by auto
  3661 qed
  3556 qed
  3662 
  3557 
  3663 lemma independent_finite:
  3558 lemmas independent_finite = independent_imp_finite
  3664   fixes B :: "'n::euclidean_space set"
       
  3665   assumes "independent B"
       
  3666   shows "finite B"
       
  3667   using affine_dependent_imp_dependent[of B] aff_independent_finite[of B] assms
       
  3668   by auto
       
  3669 
       
  3670 lemma subspace_dim_equal:
       
  3671   assumes "subspace (S :: ('n::euclidean_space) set)"
       
  3672     and "subspace T"
       
  3673     and "S \<subseteq> T"
       
  3674     and "dim S \<ge> dim T"
       
  3675   shows "S = T"
       
  3676 proof -
       
  3677   obtain B where B: "B \<le> S" "independent B \<and> S \<subseteq> span B" "card B = dim S"
       
  3678     using basis_exists[of S] by auto
       
  3679   then have "span B \<subseteq> S"
       
  3680     using span_mono[of B S] span_eq[of S] assms by metis
       
  3681   then have "span B = S"
       
  3682     using B by auto
       
  3683   have "dim S = dim T"
       
  3684     using assms dim_subset[of S T] by auto
       
  3685   then have "T \<subseteq> span B"
       
  3686     using card_eq_dim[of B T] B independent_finite assms by auto
       
  3687   then show ?thesis
       
  3688     using assms \<open>span B = S\<close> by auto
       
  3689 qed
       
  3690 
       
  3691 corollary dim_eq_span:
       
  3692   fixes S :: "'a::euclidean_space set"
       
  3693   shows "\<lbrakk>S \<subseteq> T; dim T \<le> dim S\<rbrakk> \<Longrightarrow> span S = span T"
       
  3694 by (simp add: span_mono subspace_dim_equal subspace_span)
       
  3695 
       
  3696 lemma dim_eq_full:
       
  3697     fixes S :: "'a :: euclidean_space set"
       
  3698     shows "dim S = DIM('a) \<longleftrightarrow> span S = UNIV"
       
  3699 apply (rule iffI)
       
  3700  apply (metis dim_eq_span dim_subset_UNIV span_Basis span_span subset_UNIV)
       
  3701 by (metis dim_UNIV dim_span)
       
  3702 
  3559 
  3703 lemma span_substd_basis:
  3560 lemma span_substd_basis:
  3704   assumes d: "d \<subseteq> Basis"
  3561   assumes d: "d \<subseteq> Basis"
  3705   shows "span d = {x. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x\<bullet>i = 0}"
  3562   shows "span d = {x. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x\<bullet>i = 0}"
  3706   (is "_ = ?B")
  3563   (is "_ = ?B")
  3708   have "d \<subseteq> ?B"
  3565   have "d \<subseteq> ?B"
  3709     using d by (auto simp: inner_Basis)
  3566     using d by (auto simp: inner_Basis)
  3710   moreover have s: "subspace ?B"
  3567   moreover have s: "subspace ?B"
  3711     using subspace_substandard[of "\<lambda>i. i \<notin> d"] .
  3568     using subspace_substandard[of "\<lambda>i. i \<notin> d"] .
  3712   ultimately have "span d \<subseteq> ?B"
  3569   ultimately have "span d \<subseteq> ?B"
  3713     using span_mono[of d "?B"] span_eq[of "?B"] by blast
  3570     using span_mono[of d "?B"] span_eq_iff[of "?B"] by blast
  3714   moreover have *: "card d \<le> dim (span d)"
  3571   moreover have *: "card d \<le> dim (span d)"
  3715     using independent_card_le_dim[of d "span d"] independent_substdbasis[OF assms] span_inc[of d]
  3572     using independent_card_le_dim[of d "span d"] independent_substdbasis[OF assms]
       
  3573       span_superset[of d]
  3716     by auto
  3574     by auto
  3717   moreover from * have "dim ?B \<le> dim (span d)"
  3575   moreover from * have "dim ?B \<le> dim (span d)"
  3718     using dim_substandard[OF assms] by auto
  3576     using dim_substandard[OF assms] by auto
  3719   ultimately show ?thesis
  3577   ultimately show ?thesis
  3720     using s subspace_dim_equal[of "span d" "?B"] subspace_span[of d] by auto
  3578     using s subspace_dim_equal[of "span d" "?B"] subspace_span[of d] by auto
  3725   assumes "independent B"
  3583   assumes "independent B"
  3726   shows "\<exists>f d::'a set. card d = card B \<and> linear f \<and> f ` B = d \<and>
  3584   shows "\<exists>f d::'a set. card d = card B \<and> linear f \<and> f ` B = d \<and>
  3727     f ` span B = {x. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x \<bullet> i = 0} \<and> inj_on f (span B) \<and> d \<subseteq> Basis"
  3585     f ` span B = {x. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x \<bullet> i = 0} \<and> inj_on f (span B) \<and> d \<subseteq> Basis"
  3728 proof -
  3586 proof -
  3729   have B: "card B = dim B"
  3587   have B: "card B = dim B"
  3730     using dim_unique[of B B "card B"] assms span_inc[of B] by auto
  3588     using dim_unique[of B B "card B"] assms span_superset[of B] by auto
  3731   have "dim B \<le> card (Basis :: 'a set)"
  3589   have "dim B \<le> card (Basis :: 'a set)"
  3732     using dim_subset_UNIV[of B] by simp
  3590     using dim_subset_UNIV[of B] by simp
  3733   from ex_card[OF this] obtain d :: "'a set" where d: "d \<subseteq> Basis" and t: "card d = dim B"
  3591   from ex_card[OF this] obtain d :: "'a set" where d: "d \<subseteq> Basis" and t: "card d = dim B"
  3734     by auto
  3592     by auto
  3735   let ?t = "{x::'a::euclidean_space. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x\<bullet>i = 0}"
  3593   let ?t = "{x::'a::euclidean_space. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x\<bullet>i = 0}"
  3736   have "\<exists>f. linear f \<and> f ` B = d \<and> f ` span B = ?t \<and> inj_on f (span B)"
  3594   have "\<exists>f. linear f \<and> f ` B = d \<and> f ` span B = ?t \<and> inj_on f (span B)"
  3737     apply (rule basis_to_basis_subspace_isomorphism[of "span B" ?t B "d"])
  3595     apply (rule basis_to_basis_subspace_isomorphism[of "span B" ?t B "d"])
  3738     apply (rule subspace_span)
  3596     apply (rule subspace_span)
  3739     apply (rule subspace_substandard)
  3597     apply (rule subspace_substandard)
  3740     defer
  3598     defer
  3741     apply (rule span_inc)
  3599     apply (rule span_superset)
  3742     apply (rule assms)
  3600     apply (rule assms)
  3743     defer
  3601     defer
  3744     unfolding dim_span[of B]
  3602     unfolding dim_span[of B]
  3745     apply(rule B)
  3603     apply(rule B)
  3746     unfolding span_substd_basis[OF d, symmetric]
  3604     unfolding span_substd_basis[OF d, symmetric]
  3747     apply (rule span_inc)
  3605     apply (rule span_superset)
  3748     apply (rule independent_substdbasis[OF d])
  3606     apply (rule independent_substdbasis[OF d])
  3749     apply rule
  3607     apply rule
  3750     apply assumption
  3608     apply assumption
  3751     unfolding t[symmetric] span_substd_basis[OF d] dim_substandard[OF d]
  3609     unfolding t[symmetric] span_substd_basis[OF d] dim_substandard[OF d]
  3752     apply auto
  3610     apply auto
  4030     using lowdim_subset_hyperplane by blast
  3888     using lowdim_subset_hyperplane by blast
  4031   moreover
  3889   moreover
  4032   have "a \<bullet> w = a \<bullet> c" if "span ((+) (- c) ` S) \<subseteq> {x. a \<bullet> x = 0}" "w \<in> S" for w
  3890   have "a \<bullet> w = a \<bullet> c" if "span ((+) (- c) ` S) \<subseteq> {x. a \<bullet> x = 0}" "w \<in> S" for w
  4033   proof -
  3891   proof -
  4034     have "w-c \<in> span ((+) (- c) ` S)"
  3892     have "w-c \<in> span ((+) (- c) ` S)"
  4035       by (simp add: span_superset \<open>w \<in> S\<close>)
  3893       by (simp add: span_base \<open>w \<in> S\<close>)
  4036     with that have "w-c \<in> {x. a \<bullet> x = 0}"
  3894     with that have "w-c \<in> {x. a \<bullet> x = 0}"
  4037       by blast
  3895       by blast
  4038     then show ?thesis
  3896     then show ?thesis
  4039       by (auto simp: algebra_simps)
  3897       by (auto simp: algebra_simps)
  4040   qed
  3898   qed
  4050     shows "card S = dim {x - a|x. x \<in> S} + 1"
  3908     shows "card S = dim {x - a|x. x \<in> S} + 1"
  4051 proof -
  3909 proof -
  4052   have 1: "{b - a|b. b \<in> (S - {a})} \<subseteq> {x - a|x. x \<in> S}" by auto
  3910   have 1: "{b - a|b. b \<in> (S - {a})} \<subseteq> {x - a|x. x \<in> S}" by auto
  4053   have 2: "x - a \<in> span {b - a |b. b \<in> S - {a}}" if "x \<in> S" for x
  3911   have 2: "x - a \<in> span {b - a |b. b \<in> S - {a}}" if "x \<in> S" for x
  4054   proof (cases "x = a")
  3912   proof (cases "x = a")
  4055     case True then show ?thesis by simp
  3913     case True then show ?thesis by (simp add: span_clauses)
  4056   next
  3914   next
  4057     case False then show ?thesis
  3915     case False then show ?thesis
  4058       using assms by (blast intro: span_superset that)
  3916       using assms by (blast intro: span_base that)
  4059   qed
  3917   qed
  4060   have "\<not> affine_dependent (insert a S)"
  3918   have "\<not> affine_dependent (insert a S)"
  4061     by (simp add: assms insert_absorb)
  3919     by (simp add: assms insert_absorb)
  4062   then have 3: "independent {b - a |b. b \<in> S - {a}}"
  3920   then have 3: "independent {b - a |b. b \<in> S - {a}}"
  4063       using dependent_imp_affine_dependent by fastforce
  3921       using dependent_imp_affine_dependent by fastforce
  5070       then have "f y \<in> f ` S"
  4928       then have "f y \<in> f ` S"
  5071         using y e2 h1 by auto
  4929         using y e2 h1 by auto
  5072       then have "y \<in> S"
  4930       then have "y \<in> S"
  5073         using assms y hull_subset[of S] affine_hull_subset_span
  4931         using assms y hull_subset[of S] affine_hull_subset_span
  5074           inj_on_image_mem_iff [OF \<open>inj_on f (span S)\<close>]
  4932           inj_on_image_mem_iff [OF \<open>inj_on f (span S)\<close>]
  5075         by (metis Int_iff span_inc subsetCE)
  4933         by (metis Int_iff span_superset subsetCE)
  5076     }
  4934     }
  5077     then have "z \<in> f ` (rel_interior S)"
  4935     then have "z \<in> f ` (rel_interior S)"
  5078       using mem_rel_interior_cball[of x S] \<open>e > 0\<close> x by auto
  4936       using mem_rel_interior_cball[of x S] \<open>e > 0\<close> x by auto
  5079   }
  4937   }
  5080   moreover
  4938   moreover
  5105         using cball_def[of "f x" e] dist_norm[of "f x" y] e_def by auto
  4963         using cball_def[of "f x" e] dist_norm[of "f x" y] e_def by auto
  5106       moreover have "f x - f xy = f (x - xy)"
  4964       moreover have "f x - f xy = f (x - xy)"
  5107         using assms linear_diff[of f x xy] linear_conv_bounded_linear[of f] by auto
  4965         using assms linear_diff[of f x xy] linear_conv_bounded_linear[of f] by auto
  5108       moreover have *: "x - xy \<in> span S"
  4966       moreover have *: "x - xy \<in> span S"
  5109         using subspace_diff[of "span S" x xy] subspace_span \<open>x \<in> S\<close> xy
  4967         using subspace_diff[of "span S" x xy] subspace_span \<open>x \<in> S\<close> xy
  5110           affine_hull_subset_span[of S] span_inc
  4968           affine_hull_subset_span[of S] span_superset
  5111         by auto
  4969         by auto
  5112       moreover from * have "e1 * norm (x - xy) \<le> norm (f (x - xy))"
  4970       moreover from * have "e1 * norm (x - xy) \<le> norm (f (x - xy))"
  5113         using e1 by auto
  4971         using e1 by auto
  5114       ultimately have "e1 * norm (x - xy) \<le> e1 * e2"
  4972       ultimately have "e1 * norm (x - xy) \<le> e1 * e2"
  5115         by auto
  4973         by auto
  6068     and "s \<inter> t = {}"
  5926     and "s \<inter> t = {}"
  6069   shows "\<exists>a b. a \<noteq> 0 \<and> (\<forall>x\<in>s. inner a x \<le> b) \<and> (\<forall>x\<in>t. inner a x \<ge> b)"
  5927   shows "\<exists>a b. a \<noteq> 0 \<and> (\<forall>x\<in>s. inner a x \<le> b) \<and> (\<forall>x\<in>t. inner a x \<ge> b)"
  6070 proof -
  5928 proof -
  6071   from separating_hyperplane_set_0[OF convex_differences[OF assms(2,1)]]
  5929   from separating_hyperplane_set_0[OF convex_differences[OF assms(2,1)]]
  6072   obtain a where "a \<noteq> 0" "\<forall>x\<in>{x - y |x y. x \<in> t \<and> y \<in> s}. 0 \<le> inner a x"
  5930   obtain a where "a \<noteq> 0" "\<forall>x\<in>{x - y |x y. x \<in> t \<and> y \<in> s}. 0 \<le> inner a x"
  6073     using assms(3-5) by fastforce
  5931     using assms(3-5) by force
  6074   then have *: "\<And>x y. x \<in> t \<Longrightarrow> y \<in> s \<Longrightarrow> inner a y \<le> inner a x"
  5932   then have *: "\<And>x y. x \<in> t \<Longrightarrow> y \<in> s \<Longrightarrow> inner a y \<le> inner a x"
  6075     by (force simp add: inner_diff)
  5933     by (force simp add: inner_diff)
  6076   then have bdd: "bdd_above (((\<bullet>) a)`s)"
  5934   then have bdd: "bdd_above (((\<bullet>) a)`s)"
  6077     using \<open>t \<noteq> {}\<close> by (auto intro: bdd_aboveI2[OF *])
  5935     using \<open>t \<noteq> {}\<close> by (auto intro: bdd_aboveI2[OF *])
  6078   show ?thesis
  5936   show ?thesis
  6150   unfolding translation_eq_singleton_plus
  6008   unfolding translation_eq_singleton_plus
  6151   by (simp only: convex_hull_set_plus convex_hull_singleton)
  6009   by (simp only: convex_hull_set_plus convex_hull_singleton)
  6152 
  6010 
  6153 lemma convex_hull_scaling:
  6011 lemma convex_hull_scaling:
  6154   "convex hull ((\<lambda>x. c *\<^sub>R x) ` s) = (\<lambda>x. c *\<^sub>R x) ` (convex hull s)"
  6012   "convex hull ((\<lambda>x. c *\<^sub>R x) ` s) = (\<lambda>x. c *\<^sub>R x) ` (convex hull s)"
  6155   using linear_scaleR by (rule convex_hull_linear_image [symmetric])
  6013   by (simp add: convex_hull_linear_image)
  6156 
  6014 
  6157 lemma convex_hull_affinity:
  6015 lemma convex_hull_affinity:
  6158   "convex hull ((\<lambda>x. a + c *\<^sub>R x) ` s) = (\<lambda>x. a + c *\<^sub>R x) ` (convex hull s)"
  6016   "convex hull ((\<lambda>x. a + c *\<^sub>R x) ` s) = (\<lambda>x. a + c *\<^sub>R x) ` (convex hull s)"
  6159   by(simp only: image_image[symmetric] convex_hull_scaling convex_hull_translation)
  6017   by(simp only: image_image[symmetric] convex_hull_scaling convex_hull_translation)
  6160 
  6018 
  6728   fixes s :: "'a :: euclidean_space set"
  6586   fixes s :: "'a :: euclidean_space set"
  6729   assumes "DIM('a) = 1"
  6587   assumes "DIM('a) = 1"
  6730   shows "connected s \<longleftrightarrow> convex s"
  6588   shows "connected s \<longleftrightarrow> convex s"
  6731 proof -
  6589 proof -
  6732   obtain f:: "'a \<Rightarrow> real" where linf: "linear f" and "inj f"
  6590   obtain f:: "'a \<Rightarrow> real" where linf: "linear f" and "inj f"
  6733     using subspace_isomorphism [where 'a = 'a and 'b = real]
  6591     using subspace_isomorphism[OF subspace_UNIV subspace_UNIV,
  6734     by (metis DIM_real dim_UNIV subspace_UNIV assms)
  6592         where 'a='a and 'b=real]
       
  6593     unfolding Euclidean_Space.dim_UNIV
       
  6594     by (auto simp: assms)
  6735   then have "f -` (f ` s) = s"
  6595   then have "f -` (f ` s) = s"
  6736     by (simp add: inj_vimage_image_eq)
  6596     by (simp add: inj_vimage_image_eq)
  6737   then show ?thesis
  6597   then show ?thesis
  6738     by (metis connected_convex_1 convex_linear_vimage linf convex_connected connected_linear_image)
  6598     by (metis connected_convex_1 convex_linear_vimage linf convex_connected connected_linear_image)
  6739 qed
  6599 qed
  6740 
  6600 
  6741 lemma is_interval_cball_1[intro, simp]: "is_interval (cball a b)" for a b::real
  6601 lemma is_interval_cball_1[intro, simp]: "is_interval (cball a b)" for a b::real
  6742   by (auto simp: is_interval_convex_1 convex_cball)
  6602   by (simp add: is_interval_convex_1)
  6743 
  6603 
  6744 
  6604 
  6745 subsection%unimportant \<open>Another intermediate value theorem formulation\<close>
  6605 subsection%unimportant \<open>Another intermediate value theorem formulation\<close>
  6746 
  6606 
  6747 lemma ivt_increasing_component_on_1:
  6607 lemma ivt_increasing_component_on_1:
  6907   also have "\<dots> = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` cbox 0 1)"
  6767   also have "\<dots> = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` cbox 0 1)"
  6908     by (simp only: box_eq_set_sum_Basis)
  6768     by (simp only: box_eq_set_sum_Basis)
  6909   also have "\<dots> = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` (convex hull {0, 1}))"
  6769   also have "\<dots> = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` (convex hull {0, 1}))"
  6910     by (simp only: convex_hull_eq_real_cbox zero_le_one)
  6770     by (simp only: convex_hull_eq_real_cbox zero_le_one)
  6911   also have "\<dots> = (\<Sum>i\<in>Basis. convex hull ((\<lambda>x. x *\<^sub>R i) ` {0, 1}))"
  6771   also have "\<dots> = (\<Sum>i\<in>Basis. convex hull ((\<lambda>x. x *\<^sub>R i) ` {0, 1}))"
  6912     by (simp only: convex_hull_linear_image linear_scaleR_left)
  6772     by (simp add: convex_hull_linear_image)
  6913   also have "\<dots> = convex hull (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` {0, 1})"
  6773   also have "\<dots> = convex hull (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` {0, 1})"
  6914     by (simp only: convex_hull_set_sum)
  6774     by (simp only: convex_hull_set_sum)
  6915   also have "\<dots> = convex hull {x. \<forall>i\<in>Basis. x\<bullet>i \<in> {0, 1}}"
  6775   also have "\<dots> = convex hull {x. \<forall>i\<in>Basis. x\<bullet>i \<in> {0, 1}}"
  6916     by (simp only: box_eq_set_sum_Basis)
  6776     by (simp only: box_eq_set_sum_Basis)
  6917   also have "convex hull {x. \<forall>i\<in>Basis. x\<bullet>i \<in> {0, 1}} = convex hull ?points"
  6777   also have "convex hull {x. \<forall>i\<in>Basis. x\<bullet>i \<in> {0, 1}} = convex hull ?points"