29 lemma linear_add_cmul: |
29 lemma linear_add_cmul: |
30 assumes "linear f" |
30 assumes "linear f" |
31 shows "f (a *\<^sub>R x + b *\<^sub>R y) = a *\<^sub>R f x + b *\<^sub>R f y" |
31 shows "f (a *\<^sub>R x + b *\<^sub>R y) = a *\<^sub>R f x + b *\<^sub>R f y" |
32 using linear_add[of f] linear_cmul[of f] assms by simp |
32 using linear_add[of f] linear_cmul[of f] assms by simp |
33 |
33 |
34 lemma mem_convex_2: |
|
35 assumes "convex S" "x \<in> S" "y \<in> S" "u \<ge> 0" "v \<ge> 0" "u + v = 1" |
|
36 shows "u *\<^sub>R x + v *\<^sub>R y \<in> S" |
|
37 using assms convex_def[of S] by auto |
|
38 |
|
39 lemma mem_convex_alt: |
34 lemma mem_convex_alt: |
40 assumes "convex S" "x \<in> S" "y \<in> S" "u \<ge> 0" "v \<ge> 0" "u + v > 0" |
35 assumes "convex S" "x \<in> S" "y \<in> S" "u \<ge> 0" "v \<ge> 0" "u + v > 0" |
41 shows "((u/(u+v)) *\<^sub>R x + (v/(u+v)) *\<^sub>R y) \<in> S" |
36 shows "((u/(u+v)) *\<^sub>R x + (v/(u+v)) *\<^sub>R y) \<in> S" |
42 apply (subst mem_convex_2) |
37 apply (rule convexD) |
43 using assms |
38 using assms |
44 apply (auto simp add: algebra_simps zero_le_divide_iff) |
39 apply (simp_all add: zero_le_divide_iff add_divide_distrib [symmetric]) |
45 using add_divide_distrib[of u v "u+v"] |
|
46 apply auto |
|
47 done |
40 done |
48 |
41 |
49 lemma inj_on_image_mem_iff: "inj_on f B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> f a \<in> f`A \<Longrightarrow> a \<in> B \<Longrightarrow> a \<in> A" |
42 lemma inj_on_image_mem_iff: "inj_on f B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> f a \<in> f`A \<Longrightarrow> a \<in> B \<Longrightarrow> a \<in> A" |
50 by (blast dest: inj_onD) |
43 by (blast dest: inj_onD) |
51 |
44 |
1346 by(simp add: convex_connected convex_UNIV) |
1339 by(simp add: convex_connected convex_UNIV) |
1347 |
1340 |
1348 text {* Balls, being convex, are connected. *} |
1341 text {* Balls, being convex, are connected. *} |
1349 |
1342 |
1350 lemma convex_box: |
1343 lemma convex_box: |
1351 fixes a::"'a::euclidean_space" |
|
1352 assumes "\<And>i. i \<in> Basis \<Longrightarrow> convex {x. P i x}" |
1344 assumes "\<And>i. i \<in> Basis \<Longrightarrow> convex {x. P i x}" |
1353 shows "convex {x. \<forall>i\<in>Basis. P i (x\<bullet>i)}" |
1345 shows "convex {x. \<forall>i\<in>Basis. P i (x\<bullet>i)}" |
1354 using assms unfolding convex_def |
1346 using assms unfolding convex_def |
1355 by (auto simp: inner_add_left) |
1347 by (auto simp: inner_add_left) |
1356 |
1348 |
1573 by auto |
1565 by auto |
1574 have "a \<in> convex hull insert a s" "b \<in> convex hull insert a s" |
1566 have "a \<in> convex hull insert a s" "b \<in> convex hull insert a s" |
1575 using hull_mono[of s "insert a s" convex] hull_mono[of "{a}" "insert a s" convex] and obt(4) |
1567 using hull_mono[of s "insert a s" convex] hull_mono[of "{a}" "insert a s" convex] and obt(4) |
1576 by auto |
1568 by auto |
1577 then show "x \<in> convex hull insert a s" |
1569 then show "x \<in> convex hull insert a s" |
1578 unfolding obt(5) |
1570 unfolding obt(5) using obt(1-3) |
1579 using convex_convex_hull[of "insert a s", unfolded convex_def] |
1571 by (rule convexD [OF convex_convex_hull]) |
1580 apply (erule_tac x = a in ballE) |
|
1581 apply (erule_tac x = b in ballE) |
|
1582 apply (erule_tac x = u in allE) |
|
1583 using obt |
|
1584 apply auto |
|
1585 done |
|
1586 next |
1572 next |
1587 show "convex ?hull" |
1573 show "convex ?hull" |
1588 unfolding convex_def |
1574 proof (rule convexI) |
1589 apply (rule, rule, rule, rule, rule, rule, rule) |
|
1590 proof - |
|
1591 fix x y u v |
1575 fix x y u v |
1592 assume as: "(0::real) \<le> u" "0 \<le> v" "u + v = 1" "x\<in>?hull" "y\<in>?hull" |
1576 assume as: "(0::real) \<le> u" "0 \<le> v" "u + v = 1" "x\<in>?hull" "y\<in>?hull" |
1593 from as(4) obtain u1 v1 b1 where |
1577 from as(4) obtain u1 v1 b1 where |
1594 obt1: "u1\<ge>0" "v1\<ge>0" "u1 + v1 = 1" "b1 \<in> convex hull s" "x = u1 *\<^sub>R a + v1 *\<^sub>R b1" |
1578 obt1: "u1\<ge>0" "v1\<ge>0" "u1 + v1 = 1" "b1 \<in> convex hull s" "x = u1 *\<^sub>R a + v1 *\<^sub>R b1" |
1595 by auto |
1579 by auto |
1679 (setsum u {1..k} = 1) \<and> (setsum (\<lambda>i. u i *\<^sub>R x i) {1..k} = y)}" |
1663 (setsum u {1..k} = 1) \<and> (setsum (\<lambda>i. u i *\<^sub>R x i) {1..k} = y)}" |
1680 (is "?xyz = ?hull") |
1664 (is "?xyz = ?hull") |
1681 apply (rule hull_unique) |
1665 apply (rule hull_unique) |
1682 apply rule |
1666 apply rule |
1683 defer |
1667 defer |
1684 apply (subst convex_def) |
1668 apply (rule convexI) |
1685 apply (rule, rule, rule, rule, rule, rule, rule) |
|
1686 proof - |
1669 proof - |
1687 fix x |
1670 fix x |
1688 assume "x\<in>s" |
1671 assume "x\<in>s" |
1689 then show "x \<in> ?hull" |
1672 then show "x \<in> ?hull" |
1690 unfolding mem_Collect_eq |
1673 unfolding mem_Collect_eq |
4665 |
4648 |
4666 lemma convex_closure: |
4649 lemma convex_closure: |
4667 fixes s :: "'a::real_normed_vector set" |
4650 fixes s :: "'a::real_normed_vector set" |
4668 assumes "convex s" |
4651 assumes "convex s" |
4669 shows "convex (closure s)" |
4652 shows "convex (closure s)" |
4670 unfolding convex_def Ball_def closure_sequential |
4653 apply (rule convexI) |
4671 apply (rule,rule,rule,rule,rule,rule,rule,rule,rule) |
4654 apply (unfold closure_sequential, elim exE) |
4672 apply (elim exE) |
4655 apply (rule_tac x="\<lambda>n. u *\<^sub>R xa n + v *\<^sub>R xb n" in exI) |
4673 apply (rule_tac x="\<lambda>n. u *\<^sub>R xb n + v *\<^sub>R xc n" in exI) |
|
4674 apply (rule,rule) |
4656 apply (rule,rule) |
4675 apply (rule assms[unfolded convex_def, rule_format]) |
4657 apply (rule convexD [OF assms]) |
4676 prefer 6 |
|
4677 apply (auto del: tendsto_const intro!: tendsto_intros) |
4658 apply (auto del: tendsto_const intro!: tendsto_intros) |
4678 done |
4659 done |
4679 |
4660 |
4680 lemma convex_interior: |
4661 lemma convex_interior: |
4681 fixes s :: "'a::real_normed_vector set" |
4662 fixes s :: "'a::real_normed_vector set" |
4713 using hull_subset[of s convex] convex_hull_empty by auto |
4694 using hull_subset[of s convex] convex_hull_empty by auto |
4714 |
4695 |
4715 |
4696 |
4716 subsection {* Moving and scaling convex hulls. *} |
4697 subsection {* Moving and scaling convex hulls. *} |
4717 |
4698 |
4718 lemma convex_hull_translation_lemma: |
4699 lemma convex_hull_set_plus: |
4719 "convex hull ((\<lambda>x. a + x) ` s) \<subseteq> (\<lambda>x. a + x) ` (convex hull s)" |
4700 "convex hull (s + t) = convex hull s + convex hull t" |
4720 by (metis convex_convex_hull convex_translation hull_minimal hull_subset image_mono) |
4701 unfolding set_plus_image |
4721 |
4702 apply (subst convex_hull_linear_image [symmetric]) |
4722 lemma convex_hull_bilemma: |
4703 apply (simp add: linear_iff scaleR_right_distrib) |
4723 assumes "\<forall>s a. (convex hull (up a s)) \<subseteq> up a (convex hull s)" |
4704 apply (simp add: convex_hull_Times) |
4724 shows "(\<forall>s. up a (up (neg a) s) = s) \<and> (\<forall>s. up (neg a) (up a s) = s) \<and> (\<forall>s t a. s \<subseteq> t \<longrightarrow> up a s \<subseteq> up a t) |
4705 done |
4725 \<Longrightarrow> \<forall>s. (convex hull (up a s)) = up a (convex hull s)" |
4706 |
4726 using assms by (metis subset_antisym) |
4707 lemma translation_eq_singleton_plus: "(\<lambda>x. a + x) ` t = {a} + t" |
|
4708 unfolding set_plus_def by auto |
4727 |
4709 |
4728 lemma convex_hull_translation: |
4710 lemma convex_hull_translation: |
4729 "convex hull ((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (convex hull s)" |
4711 "convex hull ((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (convex hull s)" |
4730 apply (rule convex_hull_bilemma[rule_format, of _ _ "\<lambda>a. -a"]) |
4712 unfolding translation_eq_singleton_plus |
4731 apply (rule convex_hull_translation_lemma) |
4713 by (simp only: convex_hull_set_plus convex_hull_singleton) |
4732 unfolding image_image |
|
4733 apply auto |
|
4734 done |
|
4735 |
|
4736 lemma convex_hull_scaling_lemma: |
|
4737 "convex hull ((\<lambda>x. c *\<^sub>R x) ` s) \<subseteq> (\<lambda>x. c *\<^sub>R x) ` (convex hull s)" |
|
4738 by (metis convex_convex_hull convex_scaling hull_subset subset_hull subset_image_iff) |
|
4739 |
4714 |
4740 lemma convex_hull_scaling: |
4715 lemma convex_hull_scaling: |
4741 "convex hull ((\<lambda>x. c *\<^sub>R x) ` s) = (\<lambda>x. c *\<^sub>R x) ` (convex hull s)" |
4716 "convex hull ((\<lambda>x. c *\<^sub>R x) ` s) = (\<lambda>x. c *\<^sub>R x) ` (convex hull s)" |
4742 apply (cases "c = 0") |
4717 using linear_scaleR by (rule convex_hull_linear_image [symmetric]) |
4743 defer |
|
4744 apply (rule convex_hull_bilemma[rule_format, of _ _ inverse]) |
|
4745 apply (rule convex_hull_scaling_lemma) |
|
4746 unfolding image_image scaleR_scaleR |
|
4747 apply (auto simp add:image_constant_conv) |
|
4748 done |
|
4749 |
4718 |
4750 lemma convex_hull_affinity: |
4719 lemma convex_hull_affinity: |
4751 "convex hull ((\<lambda>x. a + c *\<^sub>R x) ` s) = (\<lambda>x. a + c *\<^sub>R x) ` (convex hull s)" |
4720 "convex hull ((\<lambda>x. a + c *\<^sub>R x) ` s) = (\<lambda>x. a + c *\<^sub>R x) ` (convex hull s)" |
4752 by(simp only: image_image[symmetric] convex_hull_scaling convex_hull_translation) |
4721 by(simp only: image_image[symmetric] convex_hull_scaling convex_hull_translation) |
4753 |
4722 |
4755 subsection {* Convexity of cone hulls *} |
4724 subsection {* Convexity of cone hulls *} |
4756 |
4725 |
4757 lemma convex_cone_hull: |
4726 lemma convex_cone_hull: |
4758 assumes "convex S" |
4727 assumes "convex S" |
4759 shows "convex (cone hull S)" |
4728 shows "convex (cone hull S)" |
4760 proof - |
4729 proof (rule convexI) |
|
4730 fix x y |
|
4731 assume xy: "x \<in> cone hull S" "y \<in> cone hull S" |
|
4732 then have "S \<noteq> {}" |
|
4733 using cone_hull_empty_iff[of S] by auto |
|
4734 fix u v :: real |
|
4735 assume uv: "u \<ge> 0" "v \<ge> 0" "u + v = 1" |
|
4736 then have *: "u *\<^sub>R x \<in> cone hull S" "v *\<^sub>R y \<in> cone hull S" |
|
4737 using cone_cone_hull[of S] xy cone_def[of "cone hull S"] by auto |
|
4738 from * obtain cx :: real and xx where x: "u *\<^sub>R x = cx *\<^sub>R xx" "cx \<ge> 0" "xx \<in> S" |
|
4739 using cone_hull_expl[of S] by auto |
|
4740 from * obtain cy :: real and yy where y: "v *\<^sub>R y = cy *\<^sub>R yy" "cy \<ge> 0" "yy \<in> S" |
|
4741 using cone_hull_expl[of S] by auto |
4761 { |
4742 { |
4762 fix x y |
4743 assume "cx + cy \<le> 0" |
4763 assume xy: "x \<in> cone hull S" "y \<in> cone hull S" |
4744 then have "u *\<^sub>R x = 0" and "v *\<^sub>R y = 0" |
4764 then have "S \<noteq> {}" |
4745 using x y by auto |
4765 using cone_hull_empty_iff[of S] by auto |
4746 then have "u *\<^sub>R x + v *\<^sub>R y = 0" |
4766 fix u v :: real |
4747 by auto |
4767 assume uv: "u \<ge> 0" "v \<ge> 0" "u + v = 1" |
4748 then have "u *\<^sub>R x + v *\<^sub>R y \<in> cone hull S" |
4768 then have *: "u *\<^sub>R x \<in> cone hull S" "v *\<^sub>R y \<in> cone hull S" |
4749 using cone_hull_contains_0[of S] `S \<noteq> {}` by auto |
4769 using cone_cone_hull[of S] xy cone_def[of "cone hull S"] by auto |
|
4770 from * obtain cx :: real and xx where x: "u *\<^sub>R x = cx *\<^sub>R xx" "cx \<ge> 0" "xx \<in> S" |
|
4771 using cone_hull_expl[of S] by auto |
|
4772 from * obtain cy :: real and yy where y: "v *\<^sub>R y = cy *\<^sub>R yy" "cy \<ge> 0" "yy \<in> S" |
|
4773 using cone_hull_expl[of S] by auto |
|
4774 { |
|
4775 assume "cx + cy \<le> 0" |
|
4776 then have "u *\<^sub>R x = 0" and "v *\<^sub>R y = 0" |
|
4777 using x y by auto |
|
4778 then have "u *\<^sub>R x+ v *\<^sub>R y = 0" |
|
4779 by auto |
|
4780 then have "u *\<^sub>R x+ v *\<^sub>R y \<in> cone hull S" |
|
4781 using cone_hull_contains_0[of S] `S \<noteq> {}` by auto |
|
4782 } |
|
4783 moreover |
|
4784 { |
|
4785 assume "cx + cy > 0" |
|
4786 then have "(cx / (cx + cy)) *\<^sub>R xx + (cy / (cx + cy)) *\<^sub>R yy \<in> S" |
|
4787 using assms mem_convex_alt[of S xx yy cx cy] x y by auto |
|
4788 then have "cx *\<^sub>R xx + cy *\<^sub>R yy \<in> cone hull S" |
|
4789 using mem_cone_hull[of "(cx/(cx+cy)) *\<^sub>R xx + (cy/(cx+cy)) *\<^sub>R yy" S "cx+cy"] `cx+cy>0` |
|
4790 by (auto simp add: scaleR_right_distrib) |
|
4791 then have "u *\<^sub>R x+ v *\<^sub>R y \<in> cone hull S" |
|
4792 using x y by auto |
|
4793 } |
|
4794 moreover have "cx + cy \<le> 0 \<or> cx + cy > 0" by auto |
|
4795 ultimately have "u *\<^sub>R x+ v *\<^sub>R y \<in> cone hull S" by blast |
|
4796 } |
4750 } |
4797 then show ?thesis unfolding convex_def by auto |
4751 moreover |
|
4752 { |
|
4753 assume "cx + cy > 0" |
|
4754 then have "(cx / (cx + cy)) *\<^sub>R xx + (cy / (cx + cy)) *\<^sub>R yy \<in> S" |
|
4755 using assms mem_convex_alt[of S xx yy cx cy] x y by auto |
|
4756 then have "cx *\<^sub>R xx + cy *\<^sub>R yy \<in> cone hull S" |
|
4757 using mem_cone_hull[of "(cx/(cx+cy)) *\<^sub>R xx + (cy/(cx+cy)) *\<^sub>R yy" S "cx+cy"] `cx+cy>0` |
|
4758 by (auto simp add: scaleR_right_distrib) |
|
4759 then have "u *\<^sub>R x + v *\<^sub>R y \<in> cone hull S" |
|
4760 using x y by auto |
|
4761 } |
|
4762 moreover have "cx + cy \<le> 0 \<or> cx + cy > 0" by auto |
|
4763 ultimately show "u *\<^sub>R x + v *\<^sub>R y \<in> cone hull S" by blast |
4798 qed |
4764 qed |
4799 |
4765 |
4800 lemma cone_convex_hull: |
4766 lemma cone_convex_hull: |
4801 assumes "cone S" |
4767 assumes "cone S" |
4802 shows "cone (convex hull S)" |
4768 shows "cone (convex hull S)" |
5658 done |
5624 done |
5659 |
5625 |
5660 |
5626 |
5661 subsection {* Convexity of general and special intervals *} |
5627 subsection {* Convexity of general and special intervals *} |
5662 |
5628 |
5663 lemma convexI: (* TODO: move to Library/Convex.thy *) |
|
5664 assumes "\<And>x y u v. x \<in> s \<Longrightarrow> y \<in> s \<Longrightarrow> 0 \<le> u \<Longrightarrow> 0 \<le> v \<Longrightarrow> u + v = 1 \<Longrightarrow> u *\<^sub>R x + v *\<^sub>R y \<in> s" |
|
5665 shows "convex s" |
|
5666 using assms unfolding convex_def by fast |
|
5667 |
|
5668 lemma is_interval_convex: |
5629 lemma is_interval_convex: |
5669 fixes s :: "'a::euclidean_space set" |
5630 fixes s :: "'a::euclidean_space set" |
5670 assumes "is_interval s" |
5631 assumes "is_interval s" |
5671 shows "convex s" |
5632 shows "convex s" |
5672 proof (rule convexI) |
5633 proof (rule convexI) |
5876 apply (drule_tac x=x in bspec, assumption) |
5837 apply (drule_tac x=x in bspec, assumption) |
5877 apply clarsimp |
5838 apply clarsimp |
5878 apply (cut_tac u=x and v=i in inner_Basis, assumption+) |
5839 apply (cut_tac u=x and v=i in inner_Basis, assumption+) |
5879 apply (rule ccontr) |
5840 apply (rule ccontr) |
5880 apply simp |
5841 apply simp |
5881 done |
|
5882 |
|
5883 lemma convex_hull_set_plus: |
|
5884 "convex hull (s + t) = convex hull s + convex hull t" |
|
5885 unfolding set_plus_image |
|
5886 apply (subst convex_hull_linear_image [symmetric]) |
|
5887 apply (simp add: linear_iff scaleR_right_distrib) |
|
5888 apply (simp add: convex_hull_Times) |
|
5889 done |
5842 done |
5890 |
5843 |
5891 lemma convex_hull_set_setsum: |
5844 lemma convex_hull_set_setsum: |
5892 "convex hull (\<Sum>i\<in>A. B i) = (\<Sum>i\<in>A. convex hull (B i))" |
5845 "convex hull (\<Sum>i\<in>A. B i) = (\<Sum>i\<in>A. convex hull (B i))" |
5893 proof (cases "finite A") |
5846 proof (cases "finite A") |