src/HOL/Multivariate_Analysis/Convex_Euclidean_Space.thy
changeset 57418 6ab1c7cb0b8d
parent 56889 48a745e1bde7
child 57447 87429bdecad5
equal deleted inserted replaced
57417:29fe9bac501b 57418:6ab1c7cb0b8d
   119     by auto
   119     by auto
   120   have **: "finite d"
   120   have **: "finite d"
   121     by (auto intro: finite_subset[OF assms])
   121     by (auto intro: finite_subset[OF assms])
   122   have ***: "\<And>i. i \<in> Basis \<Longrightarrow> (\<Sum>i\<in>d. f i *\<^sub>R i) \<bullet> i = (\<Sum>x\<in>d. if x = i then f x else 0)"
   122   have ***: "\<And>i. i \<in> Basis \<Longrightarrow> (\<Sum>i\<in>d. f i *\<^sub>R i) \<bullet> i = (\<Sum>x\<in>d. if x = i then f x else 0)"
   123     using d
   123     using d
   124     by (auto intro!: setsum_cong simp: inner_Basis inner_setsum_left)
   124     by (auto intro!: setsum.cong simp: inner_Basis inner_setsum_left)
   125   show ?thesis
   125   show ?thesis
   126     unfolding euclidean_eq_iff[where 'a='a] by (auto simp: setsum_delta[OF **] ***)
   126     unfolding euclidean_eq_iff[where 'a='a] by (auto simp: setsum.delta[OF **] ***)
   127 qed
   127 qed
   128 
   128 
   129 lemma independent_substdbasis: "d \<subseteq> Basis \<Longrightarrow> independent d"
   129 lemma independent_substdbasis: "d \<subseteq> Basis \<Longrightarrow> independent d"
   130   by (rule independent_mono[OF independent_Basis])
   130   by (rule independent_mono[OF independent_Basis])
   131 
   131 
   322   assumes "x \<notin> s"
   322   assumes "x \<notin> s"
   323   shows "setsum (\<lambda>y. if (y = x) then P x else Q y) s = setsum Q s"
   323   shows "setsum (\<lambda>y. if (y = x) then P x else Q y) s = setsum Q s"
   324     and "setsum (\<lambda>y. if (x = y) then P x else Q y) s = setsum Q s"
   324     and "setsum (\<lambda>y. if (x = y) then P x else Q y) s = setsum Q s"
   325     and "setsum (\<lambda>y. if (y = x) then P y else Q y) s = setsum Q s"
   325     and "setsum (\<lambda>y. if (y = x) then P y else Q y) s = setsum Q s"
   326     and "setsum (\<lambda>y. if (x = y) then P y else Q y) s = setsum Q s"
   326     and "setsum (\<lambda>y. if (x = y) then P y else Q y) s = setsum Q s"
   327   apply (rule_tac [!] setsum_cong2)
   327   apply (rule_tac [!] setsum.cong)
   328   using assms
   328   using assms
   329   apply auto
   329   apply auto
   330   done
   330   done
   331 
   331 
   332 lemma setsum_delta'':
   332 lemma setsum_delta'':
   335   shows "(\<Sum>x\<in>s. (if y = x then f x else 0) *\<^sub>R x) = (if y\<in>s then (f y) *\<^sub>R y else 0)"
   335   shows "(\<Sum>x\<in>s. (if y = x then f x else 0) *\<^sub>R x) = (if y\<in>s then (f y) *\<^sub>R y else 0)"
   336 proof -
   336 proof -
   337   have *: "\<And>x y. (if y = x then f x else (0::real)) *\<^sub>R x = (if x=y then (f x) *\<^sub>R x else 0)"
   337   have *: "\<And>x y. (if y = x then f x else (0::real)) *\<^sub>R x = (if x=y then (f x) *\<^sub>R x else 0)"
   338     by auto
   338     by auto
   339   show ?thesis
   339   show ?thesis
   340     unfolding * using setsum_delta[OF assms, of y "\<lambda>x. f x *\<^sub>R x"] by auto
   340     unfolding * using setsum.delta[OF assms, of y "\<lambda>x. f x *\<^sub>R x"] by auto
   341 qed
   341 qed
   342 
   342 
   343 lemma if_smult: "(if P then x else (y::real)) *\<^sub>R v = (if P then x *\<^sub>R v else y *\<^sub>R v)"
   343 lemma if_smult: "(if P then x else (y::real)) *\<^sub>R v = (if P then x *\<^sub>R v else y *\<^sub>R v)"
   344   by auto
   344   by (fact if_distrib)
   345 
   345 
   346 lemma dist_triangle_eq:
   346 lemma dist_triangle_eq:
   347   fixes x y z :: "'a::real_inner"
   347   fixes x y z :: "'a::real_inner"
   348   shows "dist x z = dist x y + dist y z \<longleftrightarrow>
   348   shows "dist x z = dist x y + dist y z \<longleftrightarrow>
   349     norm (x - y) *\<^sub>R (y - z) = norm (y - z) *\<^sub>R (x - y)"
   349     norm (x - y) *\<^sub>R (y - z) = norm (y - z) *\<^sub>R (x - y)"
   576       by auto
   576       by auto
   577     show "\<exists>s ua. finite s \<and> s \<noteq> {} \<and> s \<subseteq> p \<and>
   577     show "\<exists>s ua. finite s \<and> s \<noteq> {} \<and> s \<subseteq> p \<and>
   578         setsum ua s = 1 \<and> (\<Sum>v\<in>s. ua v *\<^sub>R v) = u *\<^sub>R x + v *\<^sub>R y"
   578         setsum ua s = 1 \<and> (\<Sum>v\<in>s. ua v *\<^sub>R v) = u *\<^sub>R x + v *\<^sub>R y"
   579       apply (rule_tac x="sx \<union> sy" in exI)
   579       apply (rule_tac x="sx \<union> sy" in exI)
   580       apply (rule_tac x="\<lambda>a. (if a\<in>sx then u * ux a else 0) + (if a\<in>sy then v * uy a else 0)" in exI)
   580       apply (rule_tac x="\<lambda>a. (if a\<in>sx then u * ux a else 0) + (if a\<in>sy then v * uy a else 0)" in exI)
   581       unfolding scaleR_left_distrib setsum_addf if_smult scaleR_zero_left
   581       unfolding scaleR_left_distrib setsum.distrib if_smult scaleR_zero_left
   582         ** setsum_restrict_set[OF xy, symmetric]
   582         ** setsum.inter_restrict[OF xy, symmetric]
   583       unfolding scaleR_scaleR[symmetric] Real_Vector_Spaces.scaleR_right.setsum [symmetric]
   583       unfolding scaleR_scaleR[symmetric] Real_Vector_Spaces.scaleR_right.setsum [symmetric]
   584         and setsum_right_distrib[symmetric]
   584         and setsum_right_distrib[symmetric]
   585       unfolding x y
   585       unfolding x y
   586       using x(1-3) y(1-3) uv
   586       using x(1-3) y(1-3) uv
   587       apply simp
   587       apply simp
   614   then have *: "s \<inter> t = t"
   614   then have *: "s \<inter> t = t"
   615     by auto
   615     by auto
   616   assume "finite t" "\<not> (\<forall>x. (x \<in> t) = (x \<in> {}))" "setsum u t = 1" "(\<Sum>v\<in>t. u v *\<^sub>R v) = x"
   616   assume "finite t" "\<not> (\<forall>x. (x \<in> t) = (x \<in> {}))" "setsum u t = 1" "(\<Sum>v\<in>t. u v *\<^sub>R v) = x"
   617   then show "\<exists>u. setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = x"
   617   then show "\<exists>u. setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = x"
   618     apply (rule_tac x="\<lambda>x. if x\<in>t then u x else 0" in exI)
   618     apply (rule_tac x="\<lambda>x. if x\<in>t then u x else 0" in exI)
   619     unfolding if_smult scaleR_zero_left and setsum_restrict_set[OF assms, symmetric] and *
   619     unfolding if_smult scaleR_zero_left and setsum.inter_restrict[OF assms, symmetric] and *
   620     apply auto
   620     apply auto
   621     done
   621     done
   622 qed
   622 qed
   623 
   623 
   624 
   624 
   671       case True
   671       case True
   672       then show ?thesis
   672       then show ?thesis
   673         apply (rule_tac x="\<lambda>x. (if x=a then v else 0) + u x" in exI)
   673         apply (rule_tac x="\<lambda>x. (if x=a then v else 0) + u x" in exI)
   674         unfolding setsum_clauses(2)[OF fin]
   674         unfolding setsum_clauses(2)[OF fin]
   675         apply simp
   675         apply simp
   676         unfolding scaleR_left_distrib and setsum_addf
   676         unfolding scaleR_left_distrib and setsum.distrib
   677         unfolding vu and * and scaleR_zero_left
   677         unfolding vu and * and scaleR_zero_left
   678         apply (auto simp add: setsum_delta[OF fin])
   678         apply (auto simp add: setsum.delta[OF fin])
   679         done
   679         done
   680     next
   680     next
   681       case False
   681       case False
   682       then have **:
   682       then have **:
   683         "\<And>x. x \<in> s \<Longrightarrow> u x = (if x = a then v else u x)"
   683         "\<And>x. x \<in> s \<Longrightarrow> u x = (if x = a then v else u x)"
   684         "\<And>x. x \<in> s \<Longrightarrow> u x *\<^sub>R x = (if x = a then v *\<^sub>R x else u x *\<^sub>R x)" by auto
   684         "\<And>x. x \<in> s \<Longrightarrow> u x *\<^sub>R x = (if x = a then v *\<^sub>R x else u x *\<^sub>R x)" by auto
   685       from False show ?thesis
   685       from False show ?thesis
   686         apply (rule_tac x="\<lambda>x. if x=a then v else u x" in exI)
   686         apply (rule_tac x="\<lambda>x. if x=a then v else u x" in exI)
   687         unfolding setsum_clauses(2)[OF fin] and * using vu
   687         unfolding setsum_clauses(2)[OF fin] and * using vu
   688         using setsum_cong2[of s "\<lambda>x. u x *\<^sub>R x" "\<lambda>x. if x = a then v *\<^sub>R x else u x *\<^sub>R x", OF **(2)]
   688         using setsum.cong [of s _ "\<lambda>x. u x *\<^sub>R x" "\<lambda>x. if x = a then v *\<^sub>R x else u x *\<^sub>R x", OF _ **(2)]
   689         using setsum_cong2[of s u "\<lambda>x. if x = a then v else u x", OF **(1)]
   689         using setsum.cong [of s _ u "\<lambda>x. if x = a then v else u x", OF _ **(1)]
   690         apply auto
   690         apply auto
   691         done
   691         done
   692     qed
   692     qed
   693   qed
   693   qed
   694 qed
   694 qed
   775     apply (rule_tac x="(\<lambda>x. x - a) ` (t - {a})" in exI)
   775     apply (rule_tac x="(\<lambda>x. x - a) ` (t - {a})" in exI)
   776     apply (rule_tac x="\<lambda>x. u (x + a)" in exI)
   776     apply (rule_tac x="\<lambda>x. u (x + a)" in exI)
   777     apply (rule conjI) using as(1) apply simp
   777     apply (rule conjI) using as(1) apply simp
   778     apply (erule conjI)
   778     apply (erule conjI)
   779     using as(1)
   779     using as(1)
   780     apply (simp add: setsum_reindex[unfolded inj_on_def] scaleR_right_diff_distrib
   780     apply (simp add: setsum.reindex[unfolded inj_on_def] scaleR_right_diff_distrib
   781       setsum_subtractf scaleR_left.setsum[symmetric] setsum_diff1 scaleR_left_diff_distrib)
   781       setsum_subtractf scaleR_left.setsum[symmetric] setsum_diff1 scaleR_left_diff_distrib)
   782     unfolding as
   782     unfolding as
   783     apply simp
   783     apply simp
   784     done
   784     done
   785 qed
   785 qed
   795   assume "y = a + v" "v \<in> span {x - a |x. x \<in> s}"
   795   assume "y = a + v" "v \<in> span {x - a |x. x \<in> s}"
   796   then obtain t u where obt: "finite t" "t \<subseteq> {x - a |x. x \<in> s}" "a + (\<Sum>v\<in>t. u v *\<^sub>R v) = y"
   796   then obtain t u where obt: "finite t" "t \<subseteq> {x - a |x. x \<in> s}" "a + (\<Sum>v\<in>t. u v *\<^sub>R v) = y"
   797     unfolding span_explicit by auto
   797     unfolding span_explicit by auto
   798   def f \<equiv> "(\<lambda>x. x + a) ` t"
   798   def f \<equiv> "(\<lambda>x. x + a) ` t"
   799   have f: "finite f" "f \<subseteq> s" "(\<Sum>v\<in>f. u (v - a) *\<^sub>R (v - a)) = y - a"
   799   have f: "finite f" "f \<subseteq> s" "(\<Sum>v\<in>f. u (v - a) *\<^sub>R (v - a)) = y - a"
   800     unfolding f_def using obt by (auto simp add: setsum_reindex[unfolded inj_on_def])
   800     unfolding f_def using obt by (auto simp add: setsum.reindex[unfolded inj_on_def])
   801   have *: "f \<inter> {a} = {}" "f \<inter> - {a} = f"
   801   have *: "f \<inter> {a} = {}" "f \<inter> - {a} = f"
   802     using f(2) assms by auto
   802     using f(2) assms by auto
   803   show "\<exists>sa u. finite sa \<and> sa \<noteq> {} \<and> sa \<subseteq> insert a s \<and> setsum u sa = 1 \<and> (\<Sum>v\<in>sa. u v *\<^sub>R v) = y"
   803   show "\<exists>sa u. finite sa \<and> sa \<noteq> {} \<and> sa \<subseteq> insert a s \<and> setsum u sa = 1 \<and> (\<Sum>v\<in>sa. u v *\<^sub>R v) = y"
   804     apply (rule_tac x = "insert a f" in exI)
   804     apply (rule_tac x = "insert a f" in exI)
   805     apply (rule_tac x = "\<lambda>x. if x=a then 1 - setsum (\<lambda>x. u (x - a)) f else u (x - a)" in exI)
   805     apply (rule_tac x = "\<lambda>x. if x=a then 1 - setsum (\<lambda>x. u (x - a)) f else u (x - a)" in exI)
   806     using assms and f
   806     using assms and f
   807     unfolding setsum_clauses(2)[OF f(1)] and if_smult
   807     unfolding setsum_clauses(2)[OF f(1)] and if_smult
   808     unfolding setsum_cases[OF f(1), of "\<lambda>x. x = a"]
   808     unfolding setsum.If_cases[OF f(1), of "\<lambda>x. x = a"]
   809     apply (auto simp add: setsum_subtractf scaleR_left.setsum algebra_simps *)
   809     apply (auto simp add: setsum_subtractf scaleR_left.setsum algebra_simps *)
   810     done
   810     done
   811 qed
   811 qed
   812 
   812 
   813 lemma affine_hull_span:
   813 lemma affine_hull_span:
  1282   then obtain t u v where
  1282   then obtain t u v where
  1283     "finite t" "t \<subseteq> s" "setsum u t = 0" "v\<in>t" "u v \<noteq> 0"  "(\<Sum>v\<in>t. u v *\<^sub>R v) = 0"
  1283     "finite t" "t \<subseteq> s" "setsum u t = 0" "v\<in>t" "u v \<noteq> 0"  "(\<Sum>v\<in>t. u v *\<^sub>R v) = 0"
  1284     unfolding affine_dependent_explicit by auto
  1284     unfolding affine_dependent_explicit by auto
  1285   then show ?rhs
  1285   then show ?rhs
  1286     apply (rule_tac x="\<lambda>x. if x\<in>t then u x else 0" in exI)
  1286     apply (rule_tac x="\<lambda>x. if x\<in>t then u x else 0" in exI)
  1287     apply auto unfolding * and setsum_restrict_set[OF assms, symmetric]
  1287     apply auto unfolding * and setsum.inter_restrict[OF assms, symmetric]
  1288     unfolding Int_absorb1[OF `t\<subseteq>s`]
  1288     unfolding Int_absorb1[OF `t\<subseteq>s`]
  1289     apply auto
  1289     apply auto
  1290     done
  1290     done
  1291 next
  1291 next
  1292   assume ?rhs
  1292   assume ?rhs
  1706     apply (rule_tac x="\<lambda>i. if i \<in> {1..k1} then u * u1 i else v * u2 (i - k1)" in exI)
  1706     apply (rule_tac x="\<lambda>i. if i \<in> {1..k1} then u * u1 i else v * u2 (i - k1)" in exI)
  1707     apply (rule_tac x="\<lambda>i. if i \<in> {1..k1} then x1 i else x2 (i - k1)" in exI)
  1707     apply (rule_tac x="\<lambda>i. if i \<in> {1..k1} then x1 i else x2 (i - k1)" in exI)
  1708     apply (rule, rule)
  1708     apply (rule, rule)
  1709     defer
  1709     defer
  1710     apply rule
  1710     apply rule
  1711     unfolding * and setsum_cases[OF finite_atLeastAtMost[of 1 "k1 + k2"]] and
  1711     unfolding * and setsum.If_cases[OF finite_atLeastAtMost[of 1 "k1 + k2"]] and
  1712       setsum_reindex[OF inj] and o_def Collect_mem_eq
  1712       setsum.reindex[OF inj] and o_def Collect_mem_eq
  1713     unfolding scaleR_scaleR[symmetric] scaleR_right.setsum [symmetric] setsum_right_distrib[symmetric]
  1713     unfolding scaleR_scaleR[symmetric] scaleR_right.setsum [symmetric] setsum_right_distrib[symmetric]
  1714   proof -
  1714   proof -
  1715     fix i
  1715     fix i
  1716     assume i: "i \<in> {1..k1+k2}"
  1716     assume i: "i \<in> {1..k1+k2}"
  1717     show "0 \<le> (if i \<in> {1..k1} then u * u1 i else v * u2 (i - k1)) \<and>
  1717     show "0 \<le> (if i \<in> {1..k1} then u * u1 i else v * u2 (i - k1)) \<and>
  1742   fix x
  1742   fix x
  1743   assume "x \<in> s"
  1743   assume "x \<in> s"
  1744   then show "\<exists>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> (\<Sum>x\<in>s. u x *\<^sub>R x) = x"
  1744   then show "\<exists>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> (\<Sum>x\<in>s. u x *\<^sub>R x) = x"
  1745     apply (rule_tac x="\<lambda>y. if x=y then 1 else 0" in exI)
  1745     apply (rule_tac x="\<lambda>y. if x=y then 1 else 0" in exI)
  1746     apply auto
  1746     apply auto
  1747     unfolding setsum_delta'[OF assms] and setsum_delta''[OF assms]
  1747     unfolding setsum.delta'[OF assms] and setsum_delta''[OF assms]
  1748     apply auto
  1748     apply auto
  1749     done
  1749     done
  1750 next
  1750 next
  1751   fix u v :: real
  1751   fix u v :: real
  1752   assume uv: "0 \<le> u" "0 \<le> v" "u + v = 1"
  1752   assume uv: "0 \<le> u" "0 \<le> v" "u + v = 1"
  1759       using ux(1)[THEN bspec[where x=x]] uy(1)[THEN bspec[where x=x]] and uv(1,2)
  1759       using ux(1)[THEN bspec[where x=x]] uy(1)[THEN bspec[where x=x]] and uv(1,2)
  1760       by auto
  1760       by auto
  1761   }
  1761   }
  1762   moreover
  1762   moreover
  1763   have "(\<Sum>x\<in>s. u * ux x + v * uy x) = 1"
  1763   have "(\<Sum>x\<in>s. u * ux x + v * uy x) = 1"
  1764     unfolding setsum_addf and setsum_right_distrib[symmetric] and ux(2) uy(2)
  1764     unfolding setsum.distrib and setsum_right_distrib[symmetric] and ux(2) uy(2)
  1765     using uv(3) by auto
  1765     using uv(3) by auto
  1766   moreover
  1766   moreover
  1767   have "(\<Sum>x\<in>s. (u * ux x + v * uy x) *\<^sub>R x) = u *\<^sub>R (\<Sum>x\<in>s. ux x *\<^sub>R x) + v *\<^sub>R (\<Sum>x\<in>s. uy x *\<^sub>R x)"
  1767   have "(\<Sum>x\<in>s. (u * ux x + v * uy x) *\<^sub>R x) = u *\<^sub>R (\<Sum>x\<in>s. ux x *\<^sub>R x) + v *\<^sub>R (\<Sum>x\<in>s. uy x *\<^sub>R x)"
  1768     unfolding scaleR_left_distrib and setsum_addf and scaleR_scaleR[symmetric]
  1768     unfolding scaleR_left_distrib and setsum.distrib and scaleR_scaleR[symmetric]
  1769       and scaleR_right.setsum [symmetric]
  1769       and scaleR_right.setsum [symmetric]
  1770     by auto
  1770     by auto
  1771   ultimately
  1771   ultimately
  1772   show "\<exists>uc. (\<forall>x\<in>s. 0 \<le> uc x) \<and> setsum uc s = 1 \<and>
  1772   show "\<exists>uc. (\<forall>x\<in>s. 0 \<le> uc x) \<and> setsum uc s = 1 \<and>
  1773       (\<Sum>x\<in>s. uc x *\<^sub>R x) = u *\<^sub>R (\<Sum>x\<in>s. ux x *\<^sub>R x) + v *\<^sub>R (\<Sum>x\<in>s. uy x *\<^sub>R x)"
  1773       (\<Sum>x\<in>s. uc x *\<^sub>R x) = u *\<^sub>R (\<Sum>x\<in>s. ux x *\<^sub>R x) + v *\<^sub>R (\<Sum>x\<in>s. uy x *\<^sub>R x)"
  1875     }
  1875     }
  1876     then have "(\<Sum>x = 1..card s. u (f x)) = 1" "(\<Sum>i = 1..card s. u (f i) *\<^sub>R f i) = y"
  1876     then have "(\<Sum>x = 1..card s. u (f x)) = 1" "(\<Sum>i = 1..card s. u (f i) *\<^sub>R f i) = y"
  1877       unfolding setsum_image_gen[OF *(1), of "\<lambda>x. u (f x) *\<^sub>R f x" f]
  1877       unfolding setsum_image_gen[OF *(1), of "\<lambda>x. u (f x) *\<^sub>R f x" f]
  1878         and setsum_image_gen[OF *(1), of "\<lambda>x. u (f x)" f]
  1878         and setsum_image_gen[OF *(1), of "\<lambda>x. u (f x)" f]
  1879       unfolding f
  1879       unfolding f
  1880       using setsum_cong2[of s "\<lambda>y. (\<Sum>x\<in>{x \<in> {1..card s}. f x = y}. u (f x) *\<^sub>R f x)" "\<lambda>v. u v *\<^sub>R v"]
  1880       using setsum.cong [of s s "\<lambda>y. (\<Sum>x\<in>{x \<in> {1..card s}. f x = y}. u (f x) *\<^sub>R f x)" "\<lambda>v. u v *\<^sub>R v"]
  1881       using setsum_cong2 [of s "\<lambda>y. (\<Sum>x\<in>{x \<in> {1..card s}. f x = y}. u (f x))" u]
  1881       using setsum.cong [of s s "\<lambda>y. (\<Sum>x\<in>{x \<in> {1..card s}. f x = y}. u (f x))" u]
  1882       unfolding obt(4,5)
  1882       unfolding obt(4,5)
  1883       by auto
  1883       by auto
  1884     ultimately
  1884     ultimately
  1885     have "\<exists>k u x. (\<forall>i\<in>{1..k}. 0 \<le> u i \<and> x i \<in> p) \<and> setsum u {1..k} = 1 \<and>
  1885     have "\<exists>k u x. (\<forall>i\<in>{1..k}. 0 \<le> u i \<and> x i \<in> p) \<and> setsum u {1..k} = 1 \<and>
  1886         (\<Sum>i::nat = 1..k. u i *\<^sub>R x i) = y"
  1886         (\<Sum>i::nat = 1..k. u i *\<^sub>R x i) = y"
  1936   assume ?rhs
  1936   assume ?rhs
  1937   then obtain v u where uv: "v\<ge>0" "\<forall>x\<in>s. 0 \<le> u x" "setsum u s = w - v" "(\<Sum>x\<in>s. u x *\<^sub>R x) = y - v *\<^sub>R a"
  1937   then obtain v u where uv: "v\<ge>0" "\<forall>x\<in>s. 0 \<le> u x" "setsum u s = w - v" "(\<Sum>x\<in>s. u x *\<^sub>R x) = y - v *\<^sub>R a"
  1938     by auto
  1938     by auto
  1939   show ?lhs
  1939   show ?lhs
  1940     apply (rule_tac x = "\<lambda>x. (if a = x then v else 0) + u x" in exI)
  1940     apply (rule_tac x = "\<lambda>x. (if a = x then v else 0) + u x" in exI)
  1941     unfolding scaleR_left_distrib and setsum_addf and setsum_delta''[OF fin] and setsum_delta'[OF fin]
  1941     unfolding scaleR_left_distrib and setsum.distrib and setsum_delta''[OF fin] and setsum.delta'[OF fin]
  1942     unfolding setsum_clauses(2)[OF assms]
  1942     unfolding setsum_clauses(2)[OF assms]
  1943     using uv and uv(2)[THEN bspec[where x=a]] and `a\<in>s`
  1943     using uv and uv(2)[THEN bspec[where x=a]] and `a\<in>s`
  1944     apply auto
  1944     apply auto
  1945     done
  1945     done
  1946 next
  1946 next
  1951   moreover
  1951   moreover
  1952   assume "a \<notin> s"
  1952   assume "a \<notin> s"
  1953   moreover
  1953   moreover
  1954   have "(\<Sum>x\<in>s. if a = x then v else u x) = setsum u s"
  1954   have "(\<Sum>x\<in>s. if a = x then v else u x) = setsum u s"
  1955     and "(\<Sum>x\<in>s. (if a = x then v else u x) *\<^sub>R x) = (\<Sum>x\<in>s. u x *\<^sub>R x)"
  1955     and "(\<Sum>x\<in>s. (if a = x then v else u x) *\<^sub>R x) = (\<Sum>x\<in>s. u x *\<^sub>R x)"
  1956     apply (rule_tac setsum_cong2)
  1956     apply (rule_tac setsum.cong) apply rule
  1957     defer
  1957     defer
  1958     apply (rule_tac setsum_cong2)
  1958     apply (rule_tac setsum.cong) apply rule
  1959     using `a \<notin> s`
  1959     using `a \<notin> s`
  1960     apply auto
  1960     apply auto
  1961     done
  1961     done
  1962   ultimately show ?lhs
  1962   ultimately show ?lhs
  1963     apply (rule_tac x="\<lambda>x. if a = x then v else u x" in exI)
  1963     apply (rule_tac x="\<lambda>x. if a = x then v else u x" in exI)
  2086   have fin: "finite t" and "t \<subseteq> s"
  2086   have fin: "finite t" and "t \<subseteq> s"
  2087     unfolding t_def using obt(1,2) by auto
  2087     unfolding t_def using obt(1,2) by auto
  2088   then have "finite (insert a t)" and "insert a t \<subseteq> insert a s"
  2088   then have "finite (insert a t)" and "insert a t \<subseteq> insert a s"
  2089     by auto
  2089     by auto
  2090   moreover have *: "\<And>P Q. (\<Sum>x\<in>t. (if x = a then P x else Q x)) = (\<Sum>x\<in>t. Q x)"
  2090   moreover have *: "\<And>P Q. (\<Sum>x\<in>t. (if x = a then P x else Q x)) = (\<Sum>x\<in>t. Q x)"
  2091     apply (rule setsum_cong2)
  2091     apply (rule setsum.cong)
  2092     using `a\<notin>s` `t\<subseteq>s`
  2092     using `a\<notin>s` `t\<subseteq>s`
  2093     apply auto
  2093     apply auto
  2094     done
  2094     done
  2095   have "(\<Sum>x\<in>insert a t. if x = a then - (\<Sum>x\<in>t. u (x - a)) else u (x - a)) = 0"
  2095   have "(\<Sum>x\<in>insert a t. if x = a then - (\<Sum>x\<in>t. u (x - a)) else u (x - a)) = 0"
  2096     unfolding setsum_clauses(2)[OF fin]
  2096     unfolding setsum_clauses(2)[OF fin]
  2104     using obt(3,4) and `0\<notin>S`
  2104     using obt(3,4) and `0\<notin>S`
  2105     unfolding t_def
  2105     unfolding t_def
  2106     apply auto
  2106     apply auto
  2107     done
  2107     done
  2108   moreover have *: "\<And>P Q. (\<Sum>x\<in>t. (if x = a then P x else Q x) *\<^sub>R x) = (\<Sum>x\<in>t. Q x *\<^sub>R x)"
  2108   moreover have *: "\<And>P Q. (\<Sum>x\<in>t. (if x = a then P x else Q x) *\<^sub>R x) = (\<Sum>x\<in>t. Q x *\<^sub>R x)"
  2109     apply (rule setsum_cong2)
  2109     apply (rule setsum.cong)
  2110     using `a\<notin>s` `t\<subseteq>s`
  2110     using `a\<notin>s` `t\<subseteq>s`
  2111     apply auto
  2111     apply auto
  2112     done
  2112     done
  2113   have "(\<Sum>x\<in>t. u (x - a)) *\<^sub>R a = (\<Sum>v\<in>t. u (v - a) *\<^sub>R v)"
  2113   have "(\<Sum>x\<in>t. u (x - a)) *\<^sub>R a = (\<Sum>v\<in>t. u (v - a) *\<^sub>R v)"
  2114     unfolding scaleR_left.setsum
  2114     unfolding scaleR_left.setsum
  2115     unfolding t_def and setsum_reindex[OF inj] and o_def
  2115     unfolding t_def and setsum.reindex[OF inj] and o_def
  2116     using obt(5)
  2116     using obt(5)
  2117     by (auto simp add: setsum_addf scaleR_right_distrib)
  2117     by (auto simp add: setsum.distrib scaleR_right_distrib)
  2118   then have "(\<Sum>v\<in>insert a t. (if v = a then - (\<Sum>x\<in>t. u (x - a)) else u (v - a)) *\<^sub>R v) = 0"
  2118   then have "(\<Sum>v\<in>insert a t. (if v = a then - (\<Sum>x\<in>t. u (x - a)) else u (v - a)) *\<^sub>R v) = 0"
  2119     unfolding setsum_clauses(2)[OF fin]
  2119     unfolding setsum_clauses(2)[OF fin]
  2120     using `a\<notin>s` `t\<subseteq>s`
  2120     using `a\<notin>s` `t\<subseteq>s`
  2121     by (auto simp add: *)
  2121     by (auto simp add: *)
  2122   ultimately show ?thesis
  2122   ultimately show ?thesis
  2248       then have "setsum w (s - {v}) \<ge> 0"
  2248       then have "setsum w (s - {v}) \<ge> 0"
  2249         apply (rule_tac setsum_nonneg)
  2249         apply (rule_tac setsum_nonneg)
  2250         apply auto
  2250         apply auto
  2251         done
  2251         done
  2252       then have "setsum w s > 0"
  2252       then have "setsum w s > 0"
  2253         unfolding setsum_diff1'[OF obt(1) `v\<in>s`]
  2253         unfolding setsum.remove[OF obt(1) `v\<in>s`]
  2254         using as[THEN bspec[where x=v]] and `v\<in>s`
  2254         using as[THEN bspec[where x=v]] and `v\<in>s`
  2255         using `w v \<noteq> 0`
  2255         using `w v \<noteq> 0`
  2256         by auto
  2256         by auto
  2257       then show False using wv(1) by auto
  2257       then show False using wv(1) by auto
  2258     qed
  2258     qed
  2291 
  2291 
  2292     obtain a where "a \<in> s" and "t = (\<lambda>v. (u v) / (- w v)) a" and "w a < 0"
  2292     obtain a where "a \<in> s" and "t = (\<lambda>v. (u v) / (- w v)) a" and "w a < 0"
  2293       using Min_in[OF _ `i\<noteq>{}`] and obt(1) unfolding i_def t_def by auto
  2293       using Min_in[OF _ `i\<noteq>{}`] and obt(1) unfolding i_def t_def by auto
  2294     then have a: "a \<in> s" "u a + t * w a = 0" by auto
  2294     then have a: "a \<in> s" "u a + t * w a = 0" by auto
  2295     have *: "\<And>f. setsum f (s - {a}) = setsum f s - ((f a)::'b::ab_group_add)"
  2295     have *: "\<And>f. setsum f (s - {a}) = setsum f s - ((f a)::'b::ab_group_add)"
  2296       unfolding setsum_diff1'[OF obt(1) `a\<in>s`] by auto
  2296       unfolding setsum.remove[OF obt(1) `a\<in>s`] by auto
  2297     have "(\<Sum>v\<in>s. u v + t * w v) = 1"
  2297     have "(\<Sum>v\<in>s. u v + t * w v) = 1"
  2298       unfolding setsum_addf wv(1) setsum_right_distrib[symmetric] obt(5) by auto
  2298       unfolding setsum.distrib wv(1) setsum_right_distrib[symmetric] obt(5) by auto
  2299     moreover have "(\<Sum>v\<in>s. u v *\<^sub>R v + (t * w v) *\<^sub>R v) - (u a *\<^sub>R a + (t * w a) *\<^sub>R a) = y"
  2299     moreover have "(\<Sum>v\<in>s. u v *\<^sub>R v + (t * w v) *\<^sub>R v) - (u a *\<^sub>R a + (t * w a) *\<^sub>R a) = y"
  2300       unfolding setsum_addf obt(6) scaleR_scaleR[symmetric] scaleR_right.setsum [symmetric] wv(4)
  2300       unfolding setsum.distrib obt(6) scaleR_scaleR[symmetric] scaleR_right.setsum [symmetric] wv(4)
  2301       using a(2) [THEN eq_neg_iff_add_eq_0 [THEN iffD2]] by simp
  2301       using a(2) [THEN eq_neg_iff_add_eq_0 [THEN iffD2]] by simp
  2302     ultimately have "?P (n - 1)"
  2302     ultimately have "?P (n - 1)"
  2303       apply (rule_tac x="(s - {a})" in exI)
  2303       apply (rule_tac x="(s - {a})" in exI)
  2304       apply (rule_tac x="\<lambda>v. u v + t * w v" in exI)
  2304       apply (rule_tac x="\<lambda>v. u v + t * w v" in exI)
  2305       using obt(1-3) and t and a
  2305       using obt(1-3) and t and a
  3760     }
  3760     }
  3761     moreover
  3761     moreover
  3762     have *: "inj_on (\<lambda>v. v + (y - a)) t"
  3762     have *: "inj_on (\<lambda>v. v + (y - a)) t"
  3763       unfolding inj_on_def by auto
  3763       unfolding inj_on_def by auto
  3764     have "(\<Sum>v\<in>(\<lambda>v. v + (y - a)) ` t. u (v - (y - a))) = 1"
  3764     have "(\<Sum>v\<in>(\<lambda>v. v + (y - a)) ` t. u (v - (y - a))) = 1"
  3765       unfolding setsum_reindex[OF *] o_def using obt(4) by auto
  3765       unfolding setsum.reindex[OF *] o_def using obt(4) by auto
  3766     moreover have "(\<Sum>v\<in>(\<lambda>v. v + (y - a)) ` t. u (v - (y - a)) *\<^sub>R v) = y"
  3766     moreover have "(\<Sum>v\<in>(\<lambda>v. v + (y - a)) ` t. u (v - (y - a)) *\<^sub>R v) = y"
  3767       unfolding setsum_reindex[OF *] o_def using obt(4,5)
  3767       unfolding setsum.reindex[OF *] o_def using obt(4,5)
  3768       by (simp add: setsum_addf setsum_subtractf scaleR_left.setsum[symmetric] scaleR_right_distrib)
  3768       by (simp add: setsum.distrib setsum_subtractf scaleR_left.setsum[symmetric] scaleR_right_distrib)
  3769     ultimately
  3769     ultimately
  3770     show "\<exists>sa u. finite sa \<and> (\<forall>x\<in>sa. x \<in> s) \<and> (\<forall>x\<in>sa. 0 \<le> u x) \<and> setsum u sa = 1 \<and> (\<Sum>v\<in>sa. u v *\<^sub>R v) = y"
  3770     show "\<exists>sa u. finite sa \<and> (\<forall>x\<in>sa. x \<in> s) \<and> (\<forall>x\<in>sa. 0 \<le> u x) \<and> setsum u sa = 1 \<and> (\<Sum>v\<in>sa. u v *\<^sub>R v) = y"
  3771       apply (rule_tac x="(\<lambda>v. v + (y - a)) ` t" in exI)
  3771       apply (rule_tac x="(\<lambda>v. v + (y - a)) ` t" in exI)
  3772       apply (rule_tac x="\<lambda>v. u (v - (y - a))" in exI)
  3772       apply (rule_tac x="\<lambda>v. u (v - (y - a))" in exI)
  3773       using obt(1, 3)
  3773       using obt(1, 3)
  4774   obtain s u where
  4774   obtain s u where
  4775       "finite s" "s \<subseteq> c" "setsum u s = 0" "\<exists>v\<in>s. u v \<noteq> 0" "(\<Sum>v\<in>s. u v *\<^sub>R v) = 0"
  4775       "finite s" "s \<subseteq> c" "setsum u s = 0" "\<exists>v\<in>s. u v \<noteq> 0" "(\<Sum>v\<in>s. u v *\<^sub>R v) = 0"
  4776     by blast
  4776     by blast
  4777   then show ?thesis
  4777   then show ?thesis
  4778     apply (rule_tac x="\<lambda>v. if v\<in>s then u v else 0" in exI)
  4778     apply (rule_tac x="\<lambda>v. if v\<in>s then u v else 0" in exI)
  4779     unfolding if_smult scaleR_zero_left and setsum_restrict_set[OF assms(1), symmetric]
  4779     unfolding if_smult scaleR_zero_left and setsum.inter_restrict[OF assms(1), symmetric]
  4780     apply (auto simp add: Int_absorb1)
  4780     apply (auto simp add: Int_absorb1)
  4781     done
  4781     done
  4782 qed
  4782 qed
  4783 
  4783 
  4784 lemma radon_s_lemma:
  4784 lemma radon_s_lemma:
  4787   shows "setsum f {x\<in>s. 0 < f x} = - setsum f {x\<in>s. f x < 0}"
  4787   shows "setsum f {x\<in>s. 0 < f x} = - setsum f {x\<in>s. f x < 0}"
  4788 proof -
  4788 proof -
  4789   have *: "\<And>x. (if f x < 0 then f x else 0) + (if 0 < f x then f x else 0) = f x"
  4789   have *: "\<And>x. (if f x < 0 then f x else 0) + (if 0 < f x then f x else 0) = f x"
  4790     by auto
  4790     by auto
  4791   show ?thesis
  4791   show ?thesis
  4792     unfolding real_add_eq_0_iff[symmetric] and setsum_restrict_set''[OF assms(1)]
  4792     unfolding real_add_eq_0_iff[symmetric] and setsum.inter_filter[OF assms(1)]
  4793       and setsum_addf[symmetric] and *
  4793       and setsum.distrib[symmetric] and *
  4794     using assms(2)
  4794     using assms(2)
  4795     apply assumption
  4795     apply assumption
  4796     done
  4796     done
  4797 qed
  4797 qed
  4798 
  4798 
  4803   shows "(setsum f {x\<in>s. 0 < g x}) = - setsum f {x\<in>s. g x < 0}"
  4803   shows "(setsum f {x\<in>s. 0 < g x}) = - setsum f {x\<in>s. g x < 0}"
  4804 proof -
  4804 proof -
  4805   have *: "\<And>x. (if 0 < g x then f x else 0) + (if g x < 0 then f x else 0) = f x"
  4805   have *: "\<And>x. (if 0 < g x then f x else 0) + (if g x < 0 then f x else 0) = f x"
  4806     using assms(3) by auto
  4806     using assms(3) by auto
  4807   show ?thesis
  4807   show ?thesis
  4808     unfolding eq_neg_iff_add_eq_0 and setsum_restrict_set''[OF assms(1)]
  4808     unfolding eq_neg_iff_add_eq_0 and setsum.inter_filter[OF assms(1)]
  4809       and setsum_addf[symmetric] and *
  4809       and setsum.distrib[symmetric] and *
  4810     using assms(2)
  4810     using assms(2)
  4811     apply assumption
  4811     apply assumption
  4812     done
  4812     done
  4813 qed
  4813 qed
  4814 
  4814 
  4835       then have "setsum u c \<le> setsum (\<lambda>x. if x=v then u v else 0) c"
  4835       then have "setsum u c \<le> setsum (\<lambda>x. if x=v then u v else 0) c"
  4836         apply (rule_tac setsum_mono)
  4836         apply (rule_tac setsum_mono)
  4837         apply auto
  4837         apply auto
  4838         done
  4838         done
  4839       then show ?thesis
  4839       then show ?thesis
  4840         unfolding setsum_delta[OF assms(1)] using uv(2) and `u v < 0` and uv(1) by auto
  4840         unfolding setsum.delta[OF assms(1)] using uv(2) and `u v < 0` and uv(1) by auto
  4841     qed
  4841     qed
  4842   qed (insert setsum_nonneg_eq_0_iff[of _ u, OF fin(1)] uv(2-3), auto)
  4842   qed (insert setsum_nonneg_eq_0_iff[of _ u, OF fin(1)] uv(2-3), auto)
  4843 
  4843 
  4844   then have *: "setsum u {x\<in>c. u x > 0} > 0"
  4844   then have *: "setsum u {x\<in>c. u x > 0} > 0"
  4845     unfolding less_le
  4845     unfolding less_le
  4848     apply auto
  4848     apply auto
  4849     done
  4849     done
  4850   moreover have "setsum u ({x \<in> c. 0 < u x} \<union> {x \<in> c. u x < 0}) = setsum u c"
  4850   moreover have "setsum u ({x \<in> c. 0 < u x} \<union> {x \<in> c. u x < 0}) = setsum u c"
  4851     "(\<Sum>x\<in>{x \<in> c. 0 < u x} \<union> {x \<in> c. u x < 0}. u x *\<^sub>R x) = (\<Sum>x\<in>c. u x *\<^sub>R x)"
  4851     "(\<Sum>x\<in>{x \<in> c. 0 < u x} \<union> {x \<in> c. u x < 0}. u x *\<^sub>R x) = (\<Sum>x\<in>c. u x *\<^sub>R x)"
  4852     using assms(1)
  4852     using assms(1)
  4853     apply (rule_tac[!] setsum_mono_zero_left)
  4853     apply (rule_tac[!] setsum.mono_neutral_left)
  4854     apply auto
  4854     apply auto
  4855     done
  4855     done
  4856   then have "setsum u {x \<in> c. 0 < u x} = - setsum u {x \<in> c. 0 > u x}"
  4856   then have "setsum u {x \<in> c. 0 < u x} = - setsum u {x \<in> c. 0 > u x}"
  4857     "(\<Sum>x\<in>{x \<in> c. 0 < u x}. u x *\<^sub>R x) = - (\<Sum>x\<in>{x \<in> c. 0 > u x}. u x *\<^sub>R x)"
  4857     "(\<Sum>x\<in>{x \<in> c. 0 < u x}. u x *\<^sub>R x) = - (\<Sum>x\<in>{x \<in> c. 0 > u x}. u x *\<^sub>R x)"
  4858     unfolding eq_neg_iff_add_eq_0
  4858     unfolding eq_neg_iff_add_eq_0
  4859     using uv(1,4)
  4859     using uv(1,4)
  4860     by (auto simp add: setsum_Un_zero[OF fin, symmetric])
  4860     by (auto simp add: setsum.union_inter_neutral[OF fin, symmetric])
  4861   moreover have "\<forall>x\<in>{v \<in> c. u v < 0}. 0 \<le> inverse (setsum u {x \<in> c. 0 < u x}) * - u x"
  4861   moreover have "\<forall>x\<in>{v \<in> c. u v < 0}. 0 \<le> inverse (setsum u {x \<in> c. 0 < u x}) * - u x"
  4862     apply rule
  4862     apply rule
  4863     apply (rule mult_nonneg_nonneg)
  4863     apply (rule mult_nonneg_nonneg)
  4864     using *
  4864     using *
  4865     apply auto
  4865     apply auto
  5771     using obt(1) and hull_subset[unfolded subset_eq, rule_format, of _ s]
  5771     using obt(1) and hull_subset[unfolded subset_eq, rule_format, of _ s]
  5772     by auto
  5772     by auto
  5773 qed
  5773 qed
  5774 
  5774 
  5775 lemma inner_setsum_Basis[simp]: "i \<in> Basis \<Longrightarrow> (\<Sum>Basis) \<bullet> i = 1"
  5775 lemma inner_setsum_Basis[simp]: "i \<in> Basis \<Longrightarrow> (\<Sum>Basis) \<bullet> i = 1"
  5776   by (simp add: inner_setsum_left setsum_cases inner_Basis)
  5776   by (simp add: inner_setsum_left setsum.If_cases inner_Basis)
  5777 
  5777 
  5778 lemma convex_set_plus:
  5778 lemma convex_set_plus:
  5779   assumes "convex s" and "convex t" shows "convex (s + t)"
  5779   assumes "convex s" and "convex t" shows "convex (s + t)"
  5780 proof -
  5780 proof -
  5781   have "convex {x + y |x y. x \<in> s \<and> y \<in> t}"
  5781   have "convex {x + y |x y. x \<in> s \<and> y \<in> t}"
  5804   apply simp
  5804   apply simp
  5805   apply (safe elim!: set_plus_elim)
  5805   apply (safe elim!: set_plus_elim)
  5806   apply (rule_tac x="fun_upd f x a" in exI)
  5806   apply (rule_tac x="fun_upd f x a" in exI)
  5807   apply simp
  5807   apply simp
  5808   apply (rule_tac f="\<lambda>x. a + x" in arg_cong)
  5808   apply (rule_tac f="\<lambda>x. a + x" in arg_cong)
  5809   apply (rule setsum_cong [OF refl])
  5809   apply (rule setsum.cong [OF refl])
  5810   apply clarsimp
  5810   apply clarsimp
  5811   apply (fast intro: set_plus_intro)
  5811   apply (fast intro: set_plus_intro)
  5812   done
  5812   done
  5813 
  5813 
  5814 lemma box_eq_set_setsum_Basis:
  5814 lemma box_eq_set_setsum_Basis:
  5818   apply (fast intro: euclidean_representation [symmetric])
  5818   apply (fast intro: euclidean_representation [symmetric])
  5819   apply (subst inner_setsum_left)
  5819   apply (subst inner_setsum_left)
  5820   apply (subgoal_tac "(\<Sum>x\<in>Basis. f x \<bullet> i) = f i \<bullet> i")
  5820   apply (subgoal_tac "(\<Sum>x\<in>Basis. f x \<bullet> i) = f i \<bullet> i")
  5821   apply (drule (1) bspec)
  5821   apply (drule (1) bspec)
  5822   apply clarsimp
  5822   apply clarsimp
  5823   apply (frule setsum_diff1' [OF finite_Basis])
  5823   apply (frule setsum.remove [OF finite_Basis])
  5824   apply (erule trans)
  5824   apply (erule trans)
  5825   apply simp
  5825   apply simp
  5826   apply (rule setsum_0')
  5826   apply (rule setsum.neutral)
  5827   apply clarsimp
  5827   apply clarsimp
  5828   apply (frule_tac x=i in bspec, assumption)
  5828   apply (frule_tac x=i in bspec, assumption)
  5829   apply (drule_tac x=x in bspec, assumption)
  5829   apply (drule_tac x=x in bspec, assumption)
  5830   apply clarsimp
  5830   apply clarsimp
  5831   apply (cut_tac u=x and v=i in inner_Basis, assumption+)
  5831   apply (cut_tac u=x and v=i in inner_Basis, assumption+)
  5858   defines "One \<equiv> \<Sum>Basis"
  5858   defines "One \<equiv> \<Sum>Basis"
  5859   shows "cbox (0::'a::euclidean_space) One = convex hull {x. \<forall>i\<in>Basis. (x\<bullet>i = 0) \<or> (x\<bullet>i = 1)}"
  5859   shows "cbox (0::'a::euclidean_space) One = convex hull {x. \<forall>i\<in>Basis. (x\<bullet>i = 0) \<or> (x\<bullet>i = 1)}"
  5860   (is "?int = convex hull ?points")
  5860   (is "?int = convex hull ?points")
  5861 proof -
  5861 proof -
  5862   have One[simp]: "\<And>i. i \<in> Basis \<Longrightarrow> One \<bullet> i = 1"
  5862   have One[simp]: "\<And>i. i \<in> Basis \<Longrightarrow> One \<bullet> i = 1"
  5863     by (simp add: One_def inner_setsum_left setsum_cases inner_Basis)
  5863     by (simp add: One_def inner_setsum_left setsum.If_cases inner_Basis)
  5864   have "?int = {x. \<forall>i\<in>Basis. x \<bullet> i \<in> cbox 0 1}"
  5864   have "?int = {x. \<forall>i\<in>Basis. x \<bullet> i \<in> cbox 0 1}"
  5865     by (auto simp: cbox_def)
  5865     by (auto simp: cbox_def)
  5866   also have "\<dots> = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` cbox 0 1)"
  5866   also have "\<dots> = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` cbox 0 1)"
  5867     by (simp only: box_eq_set_setsum_Basis)
  5867     by (simp only: box_eq_set_setsum_Basis)
  5868   also have "\<dots> = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` (convex hull {0, 1}))"
  5868   also have "\<dots> = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` (convex hull {0, 1}))"
  6152     have 1: "convex hull c = {a. \<forall>i\<in>Basis. a \<bullet> i \<in> cbox (x \<bullet> i - d) (x \<bullet> i + d)}"
  6152     have 1: "convex hull c = {a. \<forall>i\<in>Basis. a \<bullet> i \<in> cbox (x \<bullet> i - d) (x \<bullet> i + d)}"
  6153       unfolding box_eq_set_setsum_Basis
  6153       unfolding box_eq_set_setsum_Basis
  6154       unfolding c_def convex_hull_set_setsum
  6154       unfolding c_def convex_hull_set_setsum
  6155       apply (subst convex_hull_linear_image [symmetric])
  6155       apply (subst convex_hull_linear_image [symmetric])
  6156       apply (simp add: linear_iff scaleR_add_left)
  6156       apply (simp add: linear_iff scaleR_add_left)
  6157       apply (rule setsum_cong [OF refl])
  6157       apply (rule setsum.cong [OF refl])
  6158       apply (rule image_cong [OF _ refl])
  6158       apply (rule image_cong [OF _ refl])
  6159       apply (rule convex_hull_eq_real_cbox)
  6159       apply (rule convex_hull_eq_real_cbox)
  6160       apply (cut_tac `0 < d`, simp)
  6160       apply (cut_tac `0 < d`, simp)
  6161       done
  6161       done
  6162     then have 2: "convex hull c = {a. \<forall>i\<in>Basis. a \<bullet> i \<in> cball (x \<bullet> i) d}"
  6162     then have 2: "convex hull c = {a. \<forall>i\<in>Basis. a \<bullet> i \<in> cball (x \<bullet> i) d}"
  6623       using as(3)
  6623       using as(3)
  6624       unfolding substdbasis_expansion_unique[OF assms]
  6624       unfolding substdbasis_expansion_unique[OF assms]
  6625       by auto
  6625       by auto
  6626     then have **: "setsum u ?D = setsum (op \<bullet> x) ?D"
  6626     then have **: "setsum u ?D = setsum (op \<bullet> x) ?D"
  6627       apply -
  6627       apply -
  6628       apply (rule setsum_cong2)
  6628       apply (rule setsum.cong)
  6629       using assms
  6629       using assms
  6630       apply auto
  6630       apply auto
  6631       done
  6631       done
  6632     have "(\<forall>i\<in>Basis. 0 \<le> x\<bullet>i) \<and> setsum (op \<bullet> x) ?D \<le> 1"
  6632     have "(\<forall>i\<in>Basis. 0 \<le> x\<bullet>i) \<and> setsum (op \<bullet> x) ?D \<le> 1"
  6633     proof (rule,rule)
  6633     proof (rule,rule)
  6692     have "\<And>i. i \<in> Basis \<Longrightarrow> (x + (e / 2) *\<^sub>R (SOME i. i\<in>Basis)) \<bullet> i =
  6692     have "\<And>i. i \<in> Basis \<Longrightarrow> (x + (e / 2) *\<^sub>R (SOME i. i\<in>Basis)) \<bullet> i =
  6693       x\<bullet>i + (if i = (SOME i. i\<in>Basis) then e/2 else 0)"
  6693       x\<bullet>i + (if i = (SOME i. i\<in>Basis) then e/2 else 0)"
  6694       by (auto simp: SOME_Basis inner_Basis inner_simps)
  6694       by (auto simp: SOME_Basis inner_Basis inner_simps)
  6695     then have *: "setsum (op \<bullet> (x + (e / 2) *\<^sub>R (SOME i. i\<in>Basis))) Basis =
  6695     then have *: "setsum (op \<bullet> (x + (e / 2) *\<^sub>R (SOME i. i\<in>Basis))) Basis =
  6696       setsum (\<lambda>i. x\<bullet>i + (if (SOME i. i\<in>Basis) = i then e/2 else 0)) Basis"
  6696       setsum (\<lambda>i. x\<bullet>i + (if (SOME i. i\<in>Basis) = i then e/2 else 0)) Basis"
  6697       apply (rule_tac setsum_cong)
  6697       apply (rule_tac setsum.cong)
  6698       apply auto
  6698       apply auto
  6699       done
  6699       done
  6700     have "setsum (op \<bullet> x) Basis < setsum (op \<bullet> (x + (e / 2) *\<^sub>R (SOME i. i\<in>Basis))) Basis"
  6700     have "setsum (op \<bullet> x) Basis < setsum (op \<bullet> (x + (e / 2) *\<^sub>R (SOME i. i\<in>Basis))) Basis"
  6701       unfolding * setsum_addf
  6701       unfolding * setsum.distrib
  6702       using `e > 0` DIM_positive[where 'a='a]
  6702       using `e > 0` DIM_positive[where 'a='a]
  6703       apply (subst setsum_delta')
  6703       apply (subst setsum.delta')
  6704       apply (auto simp: SOME_Basis)
  6704       apply (auto simp: SOME_Basis)
  6705       done
  6705       done
  6706     also have "\<dots> \<le> 1"
  6706     also have "\<dots> \<le> 1"
  6707       using **
  6707       using **
  6708       apply (drule_tac as[rule_format])
  6708       apply (drule_tac as[rule_format])
  6742         apply (auto simp add: norm_minus_commute inner_diff_left)
  6742         apply (auto simp add: norm_minus_commute inner_diff_left)
  6743         done
  6743         done
  6744       then show "y \<bullet> i \<le> x \<bullet> i + ?d" by auto
  6744       then show "y \<bullet> i \<le> x \<bullet> i + ?d" by auto
  6745     qed
  6745     qed
  6746     also have "\<dots> \<le> 1"
  6746     also have "\<dots> \<le> 1"
  6747       unfolding setsum_addf setsum_constant real_eq_of_nat
  6747       unfolding setsum.distrib setsum_constant real_eq_of_nat
  6748       by (auto simp add: Suc_le_eq)
  6748       by (auto simp add: Suc_le_eq)
  6749     finally show "(\<forall>i\<in>Basis. 0 \<le> y \<bullet> i) \<and> setsum (op \<bullet> y) Basis \<le> 1"
  6749     finally show "(\<forall>i\<in>Basis. 0 \<le> y \<bullet> i) \<and> setsum (op \<bullet> y) Basis \<le> 1"
  6750     proof safe
  6750     proof safe
  6751       fix i :: 'a
  6751       fix i :: 'a
  6752       assume i: "i \<in> Basis"
  6752       assume i: "i \<in> Basis"
  6772   {
  6772   {
  6773     fix i :: 'a
  6773     fix i :: 'a
  6774     assume i: "i \<in> Basis"
  6774     assume i: "i \<in> Basis"
  6775     have "?a \<bullet> i = inverse (2 * real DIM('a))"
  6775     have "?a \<bullet> i = inverse (2 * real DIM('a))"
  6776       by (rule trans[of _ "setsum (\<lambda>j. if i = j then inverse (2 * real DIM('a)) else 0) ?D"])
  6776       by (rule trans[of _ "setsum (\<lambda>j. if i = j then inverse (2 * real DIM('a)) else 0) ?D"])
  6777          (simp_all add: setsum_cases i) }
  6777          (simp_all add: setsum.If_cases i) }
  6778   note ** = this
  6778   note ** = this
  6779   show ?thesis
  6779   show ?thesis
  6780     apply (rule that[of ?a])
  6780     apply (rule that[of ?a])
  6781     unfolding interior_std_simplex mem_Collect_eq
  6781     unfolding interior_std_simplex mem_Collect_eq
  6782   proof safe
  6782   proof safe
  6784     assume i: "i \<in> Basis"
  6784     assume i: "i \<in> Basis"
  6785     show "0 < ?a \<bullet> i"
  6785     show "0 < ?a \<bullet> i"
  6786       unfolding **[OF i] by (auto simp add: Suc_le_eq DIM_positive)
  6786       unfolding **[OF i] by (auto simp add: Suc_le_eq DIM_positive)
  6787   next
  6787   next
  6788     have "setsum (op \<bullet> ?a) ?D = setsum (\<lambda>i. inverse (2 * real DIM('a))) ?D"
  6788     have "setsum (op \<bullet> ?a) ?D = setsum (\<lambda>i. inverse (2 * real DIM('a))) ?D"
  6789       apply (rule setsum_cong2, rule **)
  6789       apply (rule setsum.cong)
       
  6790       apply rule
  6790       apply auto
  6791       apply auto
  6791       done
  6792       done
  6792     also have "\<dots> < 1"
  6793     also have "\<dots> < 1"
  6793       unfolding setsum_constant real_eq_of_nat divide_inverse[symmetric]
  6794       unfolding setsum_constant real_eq_of_nat divide_inverse[symmetric]
  6794       by (auto simp add: field_simps)
  6795       by (auto simp add: field_simps)
  6857           by auto
  6858           by auto
  6858         have "\<And>i. i \<in> Basis \<Longrightarrow> (x + (e / 2) *\<^sub>R a) \<bullet> i = x\<bullet>i + (if i = a then e/2 else 0)"
  6859         have "\<And>i. i \<in> Basis \<Longrightarrow> (x + (e / 2) *\<^sub>R a) \<bullet> i = x\<bullet>i + (if i = a then e/2 else 0)"
  6859           using a d by (auto simp: inner_simps inner_Basis)
  6860           using a d by (auto simp: inner_simps inner_Basis)
  6860         then have *: "setsum (op \<bullet> (x + (e / 2) *\<^sub>R a)) d =
  6861         then have *: "setsum (op \<bullet> (x + (e / 2) *\<^sub>R a)) d =
  6861           setsum (\<lambda>i. x\<bullet>i + (if a = i then e/2 else 0)) d"
  6862           setsum (\<lambda>i. x\<bullet>i + (if a = i then e/2 else 0)) d"
  6862           using d by (intro setsum_cong) auto
  6863           using d by (intro setsum.cong) auto
  6863         have "a \<in> Basis"
  6864         have "a \<in> Basis"
  6864           using `a \<in> d` d by auto
  6865           using `a \<in> d` d by auto
  6865         then have h1: "(\<forall>i\<in>Basis. i \<notin> d \<longrightarrow> (x + (e / 2) *\<^sub>R a) \<bullet> i = 0)"
  6866         then have h1: "(\<forall>i\<in>Basis. i \<notin> d \<longrightarrow> (x + (e / 2) *\<^sub>R a) \<bullet> i = 0)"
  6866           using x0 d `a\<in>d` by (auto simp add: inner_add_left inner_Basis)
  6867           using x0 d `a\<in>d` by (auto simp add: inner_add_left inner_Basis)
  6867         have "setsum (op \<bullet> x) d < setsum (op \<bullet> (x + (e / 2) *\<^sub>R a)) d"
  6868         have "setsum (op \<bullet> x) d < setsum (op \<bullet> (x + (e / 2) *\<^sub>R a)) d"
  6868           unfolding * setsum_addf
  6869           unfolding * setsum.distrib
  6869           using `e > 0` `a \<in> d`
  6870           using `e > 0` `a \<in> d`
  6870           using `finite d`
  6871           using `finite d`
  6871           by (auto simp add: setsum_delta')
  6872           by (auto simp add: setsum.delta')
  6872         also have "\<dots> \<le> 1"
  6873         also have "\<dots> \<le> 1"
  6873           using ** h1 as[rule_format, of "x + (e / 2) *\<^sub>R a"]
  6874           using ** h1 as[rule_format, of "x + (e / 2) *\<^sub>R a"]
  6874           by auto
  6875           by auto
  6875         finally show "setsum (op \<bullet> x) d < 1 \<and> (\<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x\<bullet>i = 0)"
  6876         finally show "setsum (op \<bullet> x) d < 1 \<and> (\<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x\<bullet>i = 0)"
  6876           using x0 by auto
  6877           using x0 by auto
  6925             apply (auto simp add: norm_minus_commute inner_simps)
  6926             apply (auto simp add: norm_minus_commute inner_simps)
  6926             done
  6927             done
  6927           then show "y \<bullet> i \<le> x \<bullet> i + ?d" by auto
  6928           then show "y \<bullet> i \<le> x \<bullet> i + ?d" by auto
  6928         qed
  6929         qed
  6929         also have "\<dots> \<le> 1"
  6930         also have "\<dots> \<le> 1"
  6930           unfolding setsum_addf setsum_constant real_eq_of_nat
  6931           unfolding setsum.distrib setsum_constant real_eq_of_nat
  6931           using `0 < card d`
  6932           using `0 < card d`
  6932           by auto
  6933           by auto
  6933         finally show "setsum (op \<bullet> y) d \<le> 1" .
  6934         finally show "setsum (op \<bullet> y) d \<le> 1" .
  6934 
  6935 
  6935         fix i :: 'a
  6936         fix i :: 'a
  6974     fix i
  6975     fix i
  6975     assume "i \<in> d"
  6976     assume "i \<in> d"
  6976     have "?a \<bullet> i = inverse (2 * real (card d))"
  6977     have "?a \<bullet> i = inverse (2 * real (card d))"
  6977       apply (rule trans[of _ "setsum (\<lambda>j. if i = j then inverse (2 * real (card d)) else 0) ?D"])
  6978       apply (rule trans[of _ "setsum (\<lambda>j. if i = j then inverse (2 * real (card d)) else 0) ?D"])
  6978       unfolding inner_setsum_left
  6979       unfolding inner_setsum_left
  6979       apply (rule setsum_cong2)
  6980       apply (rule setsum.cong)
  6980       using `i \<in> d` `finite d` setsum_delta'[of d i "(\<lambda>k. inverse (2 * real (card d)))"]
  6981       using `i \<in> d` `finite d` setsum.delta'[of d i "(\<lambda>k. inverse (2 * real (card d)))"]
  6981         d1 assms(2)
  6982         d1 assms(2)
  6982       by (auto simp: inner_simps inner_Basis set_rev_mp[OF _ assms(2)])
  6983       by (auto simp: inner_Basis set_rev_mp[OF _ assms(2)])
  6983   }
  6984   }
  6984   note ** = this
  6985   note ** = this
  6985   show ?thesis
  6986   show ?thesis
  6986     apply (rule that[of ?a])
  6987     apply (rule that[of ?a])
  6987     unfolding rel_interior_substd_simplex[OF assms(2)] mem_Collect_eq
  6988     unfolding rel_interior_substd_simplex[OF assms(2)] mem_Collect_eq
  6993     also have "\<dots> = ?a \<bullet> i" using **[of i] `i \<in> d`
  6994     also have "\<dots> = ?a \<bullet> i" using **[of i] `i \<in> d`
  6994       by auto
  6995       by auto
  6995     finally show "0 < ?a \<bullet> i" by auto
  6996     finally show "0 < ?a \<bullet> i" by auto
  6996   next
  6997   next
  6997     have "setsum (op \<bullet> ?a) ?D = setsum (\<lambda>i. inverse (2 * real (card d))) ?D"
  6998     have "setsum (op \<bullet> ?a) ?D = setsum (\<lambda>i. inverse (2 * real (card d))) ?D"
  6998       by (rule setsum_cong2) (rule **)
  6999       by (rule setsum.cong) (rule refl, rule **)
  6999     also have "\<dots> < 1"
  7000     also have "\<dots> < 1"
  7000       unfolding setsum_constant real_eq_of_nat divide_real_def[symmetric]
  7001       unfolding setsum_constant real_eq_of_nat divide_real_def[symmetric]
  7001       by (auto simp add: field_simps)
  7002       by (auto simp add: field_simps)
  7002     finally show "setsum (op \<bullet> ?a) ?D < 1" by auto
  7003     finally show "setsum (op \<bullet> ?a) ?D < 1" by auto
  7003   next
  7004   next
  8393     {
  8394     {
  8394       fix x
  8395       fix x
  8395       assume "x \<in> S i"
  8396       assume "x \<in> S i"
  8396       def c \<equiv> "\<lambda>j. if j = i then 1::real else 0"
  8397       def c \<equiv> "\<lambda>j. if j = i then 1::real else 0"
  8397       then have *: "setsum c I = 1"
  8398       then have *: "setsum c I = 1"
  8398         using `finite I` `i \<in> I` setsum_delta[of I i "\<lambda>j::'a. 1::real"]
  8399         using `finite I` `i \<in> I` setsum.delta[of I i "\<lambda>j::'a. 1::real"]
  8399         by auto
  8400         by auto
  8400       def s \<equiv> "\<lambda>j. if j = i then x else p j"
  8401       def s \<equiv> "\<lambda>j. if j = i then x else p j"
  8401       then have "\<forall>j. c j *\<^sub>R s j = (if j = i then x else 0)"
  8402       then have "\<forall>j. c j *\<^sub>R s j = (if j = i then x else 0)"
  8402         using c_def by (auto simp add: algebra_simps)
  8403         using c_def by (auto simp add: algebra_simps)
  8403       then have "x = setsum (\<lambda>i. c i *\<^sub>R s i) I"
  8404       then have "x = setsum (\<lambda>i. c i *\<^sub>R s i) I"
  8404         using s_def c_def `finite I` `i \<in> I` setsum_delta[of I i "\<lambda>j::'a. x"]
  8405         using s_def c_def `finite I` `i \<in> I` setsum.delta[of I i "\<lambda>j::'a. x"]
  8405         by auto
  8406         by auto
  8406       then have "x \<in> ?rhs"
  8407       then have "x \<in> ?rhs"
  8407         apply auto
  8408         apply auto
  8408         apply (rule_tac x = c in exI)
  8409         apply (rule_tac x = c in exI)
  8409         apply (rule_tac x = s in exI)
  8410         apply (rule_tac x = s in exI)
  8432     have "setsum (\<lambda>i. u * c i) I = u * setsum c I"
  8433     have "setsum (\<lambda>i. u * c i) I = u * setsum c I"
  8433       by (simp add: setsum_right_distrib)
  8434       by (simp add: setsum_right_distrib)
  8434     moreover have "setsum (\<lambda>i. v * d i) I = v * setsum d I"
  8435     moreover have "setsum (\<lambda>i. v * d i) I = v * setsum d I"
  8435       by (simp add: setsum_right_distrib)
  8436       by (simp add: setsum_right_distrib)
  8436     ultimately have sum1: "setsum e I = 1"
  8437     ultimately have sum1: "setsum e I = 1"
  8437       using e_def xc yc uv by (simp add: setsum_addf)
  8438       using e_def xc yc uv by (simp add: setsum.distrib)
  8438     def q \<equiv> "\<lambda>i. if e i = 0 then p i else (u * c i / e i) *\<^sub>R s i + (v * d i / e i) *\<^sub>R t i"
  8439     def q \<equiv> "\<lambda>i. if e i = 0 then p i else (u * c i / e i) *\<^sub>R s i + (v * d i / e i) *\<^sub>R t i"
  8439     {
  8440     {
  8440       fix i
  8441       fix i
  8441       assume i: "i \<in> I"
  8442       assume i: "i \<in> I"
  8442       have "q i \<in> S i"
  8443       have "q i \<in> S i"
  8475       qed
  8476       qed
  8476     }
  8477     }
  8477     then have *: "\<forall>i\<in>I. (u * c i) *\<^sub>R s i + (v * d i) *\<^sub>R t i = e i *\<^sub>R q i"
  8478     then have *: "\<forall>i\<in>I. (u * c i) *\<^sub>R s i + (v * d i) *\<^sub>R t i = e i *\<^sub>R q i"
  8478       by auto
  8479       by auto
  8479     have "u *\<^sub>R x + v *\<^sub>R y = setsum (\<lambda>i. (u * c i) *\<^sub>R s i + (v * d i) *\<^sub>R t i) I"
  8480     have "u *\<^sub>R x + v *\<^sub>R y = setsum (\<lambda>i. (u * c i) *\<^sub>R s i + (v * d i) *\<^sub>R t i) I"
  8480       using xc yc by (simp add: algebra_simps scaleR_right.setsum setsum_addf)
  8481       using xc yc by (simp add: algebra_simps scaleR_right.setsum setsum.distrib)
  8481     also have "\<dots> = setsum (\<lambda>i. e i *\<^sub>R q i) I"
  8482     also have "\<dots> = setsum (\<lambda>i. e i *\<^sub>R q i) I"
  8482       using * by auto
  8483       using * by auto
  8483     finally have "u *\<^sub>R x + v *\<^sub>R y = setsum (\<lambda>i. (e i) *\<^sub>R (q i)) I"
  8484     finally have "u *\<^sub>R x + v *\<^sub>R y = setsum (\<lambda>i. (e i) *\<^sub>R (q i)) I"
  8484       by auto
  8485       by auto
  8485     then have "u *\<^sub>R x + v *\<^sub>R y \<in> ?rhs"
  8486     then have "u *\<^sub>R x + v *\<^sub>R y \<in> ?rhs"