src/HOL/Analysis/Convex.thy
author wenzelm
Mon, 24 Oct 2022 20:37:32 +0200
changeset 76371 1ac2416e8432
parent 74729 64b3d8d9bd10
child 77490 2c86ea8961b5
permissions -rw-r--r--
tuned signature (again, amending f32ac01aef5e), e.g. relevant for Isabelle/DOF;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
70086
72c52a897de2 First tranche of the Homology development: Simplices
paulson <lp15@cam.ac.uk>
parents: 69802
diff changeset
     1
(* Title:      HOL/Analysis/Convex.thy
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
     2
   Author:     L C Paulson, University of Cambridge
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
     3
   Author:     Robert Himmelmann, TU Muenchen
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
     4
   Author:     Bogdan Grechuk, University of Edinburgh
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
     5
   Author:     Armin Heller, TU Muenchen
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
     6
   Author:     Johannes Hoelzl, TU Muenchen
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
     7
*)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
     8
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
     9
section \<open>Convex Sets and Functions\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    10
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    11
theory Convex
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    12
imports
71242
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
    13
  Affine
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    14
  "HOL-Library.Set_Algebras"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    15
begin
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    16
71044
nipkow
parents: 71040
diff changeset
    17
subsection \<open>Convex Sets\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    18
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
    19
definition\<^marker>\<open>tag important\<close> convex :: "'a::real_vector set \<Rightarrow> bool"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    20
  where "convex s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. \<forall>u\<ge>0. \<forall>v\<ge>0. u + v = 1 \<longrightarrow> u *\<^sub>R x + v *\<^sub>R y \<in> s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    21
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    22
lemma convexI:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    23
  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"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    24
  shows "convex s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    25
  using assms unfolding convex_def by fast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    26
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    27
lemma convexD:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    28
  assumes "convex s" and "x \<in> s" and "y \<in> s" and "0 \<le> u" and "0 \<le> v" and "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    29
  shows "u *\<^sub>R x + v *\<^sub>R y \<in> s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    30
  using assms unfolding convex_def by fast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    31
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    32
lemma convex_alt: "convex s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. \<forall>u. 0 \<le> u \<and> u \<le> 1 \<longrightarrow> ((1 - u) *\<^sub>R x + u *\<^sub>R y) \<in> s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    33
  (is "_ \<longleftrightarrow> ?alt")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    34
proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    35
  show "convex s" if alt: ?alt
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    36
  proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    37
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    38
      fix x y and u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    39
      assume mem: "x \<in> s" "y \<in> s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    40
      assume "0 \<le> u" "0 \<le> v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    41
      moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    42
      assume "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    43
      then have "u = 1 - v" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    44
      ultimately have "u *\<^sub>R x + v *\<^sub>R y \<in> s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    45
        using alt [rule_format, OF mem] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    46
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    47
    then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    48
      unfolding convex_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    49
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    50
  show ?alt if "convex s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    51
    using that by (auto simp: convex_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    52
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    53
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    54
lemma convexD_alt:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    55
  assumes "convex s" "a \<in> s" "b \<in> s" "0 \<le> u" "u \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    56
  shows "((1 - u) *\<^sub>R a + u *\<^sub>R b) \<in> s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    57
  using assms unfolding convex_alt by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    58
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    59
lemma mem_convex_alt:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    60
  assumes "convex S" "x \<in> S" "y \<in> S" "u \<ge> 0" "v \<ge> 0" "u + v > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    61
  shows "((u/(u+v)) *\<^sub>R x + (v/(u+v)) *\<^sub>R y) \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    62
  using assms
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
    63
  by (simp add: convex_def zero_le_divide_iff add_divide_distrib [symmetric])
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    64
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    65
lemma convex_empty[intro,simp]: "convex {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    66
  unfolding convex_def by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    67
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    68
lemma convex_singleton[intro,simp]: "convex {a}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    69
  unfolding convex_def by (auto simp: scaleR_left_distrib[symmetric])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    70
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    71
lemma convex_UNIV[intro,simp]: "convex UNIV"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    72
  unfolding convex_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    73
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    74
lemma convex_Inter: "(\<And>s. s\<in>f \<Longrightarrow> convex s) \<Longrightarrow> convex(\<Inter>f)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    75
  unfolding convex_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    76
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    77
lemma convex_Int: "convex s \<Longrightarrow> convex t \<Longrightarrow> convex (s \<inter> t)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    78
  unfolding convex_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    79
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    80
lemma convex_INT: "(\<And>i. i \<in> A \<Longrightarrow> convex (B i)) \<Longrightarrow> convex (\<Inter>i\<in>A. B i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    81
  unfolding convex_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    82
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    83
lemma convex_Times: "convex s \<Longrightarrow> convex t \<Longrightarrow> convex (s \<times> t)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    84
  unfolding convex_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    85
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    86
lemma convex_halfspace_le: "convex {x. inner a x \<le> b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    87
  unfolding convex_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    88
  by (auto simp: inner_add intro!: convex_bound_le)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    89
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    90
lemma convex_halfspace_ge: "convex {x. inner a x \<ge> b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    91
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    92
  have *: "{x. inner a x \<ge> b} = {x. inner (-a) x \<le> -b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    93
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    94
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    95
    unfolding * using convex_halfspace_le[of "-a" "-b"] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    96
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    97
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    98
lemma convex_halfspace_abs_le: "convex {x. \<bar>inner a x\<bar> \<le> b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
    99
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   100
  have *: "{x. \<bar>inner a x\<bar> \<le> b} = {x. inner a x \<le> b} \<inter> {x. -b \<le> inner a x}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   101
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   102
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   103
    unfolding * by (simp add: convex_Int convex_halfspace_ge convex_halfspace_le)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   104
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   105
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   106
lemma convex_hyperplane: "convex {x. inner a x = b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   107
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   108
  have *: "{x. inner a x = b} = {x. inner a x \<le> b} \<inter> {x. inner a x \<ge> b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   109
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   110
  show ?thesis using convex_halfspace_le convex_halfspace_ge
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   111
    by (auto intro!: convex_Int simp: *)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   112
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   113
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   114
lemma convex_halfspace_lt: "convex {x. inner a x < b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   115
  unfolding convex_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   116
  by (auto simp: convex_bound_lt inner_add)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   117
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   118
lemma convex_halfspace_gt: "convex {x. inner a x > b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   119
  using convex_halfspace_lt[of "-a" "-b"] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   120
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   121
lemma convex_halfspace_Re_ge: "convex {x. Re x \<ge> b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   122
  using convex_halfspace_ge[of b "1::complex"] by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   123
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   124
lemma convex_halfspace_Re_le: "convex {x. Re x \<le> b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   125
  using convex_halfspace_le[of "1::complex" b] by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   126
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   127
lemma convex_halfspace_Im_ge: "convex {x. Im x \<ge> b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   128
  using convex_halfspace_ge[of b \<i>] by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   129
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   130
lemma convex_halfspace_Im_le: "convex {x. Im x \<le> b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   131
  using convex_halfspace_le[of \<i> b] by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   132
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   133
lemma convex_halfspace_Re_gt: "convex {x. Re x > b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   134
  using convex_halfspace_gt[of b "1::complex"] by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   135
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   136
lemma convex_halfspace_Re_lt: "convex {x. Re x < b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   137
  using convex_halfspace_lt[of "1::complex" b] by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   138
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   139
lemma convex_halfspace_Im_gt: "convex {x. Im x > b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   140
  using convex_halfspace_gt[of b \<i>] by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   141
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   142
lemma convex_halfspace_Im_lt: "convex {x. Im x < b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   143
  using convex_halfspace_lt[of \<i> b] by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   144
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   145
lemma convex_real_interval [iff]:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   146
  fixes a b :: "real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   147
  shows "convex {a..}" and "convex {..b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   148
    and "convex {a<..}" and "convex {..<b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   149
    and "convex {a..b}" and "convex {a<..b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   150
    and "convex {a..<b}" and "convex {a<..<b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   151
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   152
  have "{a..} = {x. a \<le> inner 1 x}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   153
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   154
  then show 1: "convex {a..}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   155
    by (simp only: convex_halfspace_ge)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   156
  have "{..b} = {x. inner 1 x \<le> b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   157
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   158
  then show 2: "convex {..b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   159
    by (simp only: convex_halfspace_le)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   160
  have "{a<..} = {x. a < inner 1 x}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   161
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   162
  then show 3: "convex {a<..}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   163
    by (simp only: convex_halfspace_gt)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   164
  have "{..<b} = {x. inner 1 x < b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   165
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   166
  then show 4: "convex {..<b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   167
    by (simp only: convex_halfspace_lt)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   168
  have "{a..b} = {a..} \<inter> {..b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   169
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   170
  then show "convex {a..b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   171
    by (simp only: convex_Int 1 2)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   172
  have "{a<..b} = {a<..} \<inter> {..b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   173
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   174
  then show "convex {a<..b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   175
    by (simp only: convex_Int 3 2)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   176
  have "{a..<b} = {a..} \<inter> {..<b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   177
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   178
  then show "convex {a..<b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   179
    by (simp only: convex_Int 1 4)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   180
  have "{a<..<b} = {a<..} \<inter> {..<b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   181
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   182
  then show "convex {a<..<b}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   183
    by (simp only: convex_Int 3 4)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   184
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   185
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   186
lemma convex_Reals: "convex \<real>"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   187
  by (simp add: convex_def scaleR_conv_of_real)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   188
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   189
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
   190
subsection\<^marker>\<open>tag unimportant\<close> \<open>Explicit expressions for convexity in terms of arbitrary sums\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   191
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   192
lemma convex_sum:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   193
  fixes C :: "'a::real_vector set"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   194
  assumes "finite S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   195
    and "convex C"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   196
    and "(\<Sum> i \<in> S. a i) = 1"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   197
  assumes "\<And>i. i \<in> S \<Longrightarrow> a i \<ge> 0"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   198
    and "\<And>i. i \<in> S \<Longrightarrow> y i \<in> C"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   199
  shows "(\<Sum> j \<in> S. a j *\<^sub>R y j) \<in> C"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   200
  using assms(1,3,4,5)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   201
proof (induct arbitrary: a set: finite)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   202
  case empty
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   203
  then show ?case by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   204
next
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   205
  case (insert i S) note IH = this(3)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   206
  have "a i + sum a S = 1"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   207
    and "0 \<le> a i"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   208
    and "\<forall>j\<in>S. 0 \<le> a j"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   209
    and "y i \<in> C"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   210
    and "\<forall>j\<in>S. y j \<in> C"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   211
    using insert.hyps(1,2) insert.prems by simp_all
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   212
  then have "0 \<le> sum a S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   213
    by (simp add: sum_nonneg)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   214
  have "a i *\<^sub>R y i + (\<Sum>j\<in>S. a j *\<^sub>R y j) \<in> C"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   215
  proof (cases "sum a S = 0")
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   216
    case True
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   217
    with \<open>a i + sum a S = 1\<close> have "a i = 1"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   218
      by simp
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   219
    from sum_nonneg_0 [OF \<open>finite S\<close> _ True] \<open>\<forall>j\<in>S. 0 \<le> a j\<close> have "\<forall>j\<in>S. a j = 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   220
      by simp
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   221
    show ?thesis using \<open>a i = 1\<close> and \<open>\<forall>j\<in>S. a j = 0\<close> and \<open>y i \<in> C\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   222
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   223
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   224
    case False
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   225
    with \<open>0 \<le> sum a S\<close> have "0 < sum a S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   226
      by simp
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   227
    then have "(\<Sum>j\<in>S. (a j / sum a S) *\<^sub>R y j) \<in> C"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   228
      using \<open>\<forall>j\<in>S. 0 \<le> a j\<close> and \<open>\<forall>j\<in>S. y j \<in> C\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   229
      by (simp add: IH sum_divide_distrib [symmetric])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   230
    from \<open>convex C\<close> and \<open>y i \<in> C\<close> and this and \<open>0 \<le> a i\<close>
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   231
      and \<open>0 \<le> sum a S\<close> and \<open>a i + sum a S = 1\<close>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   232
    have "a i *\<^sub>R y i + sum a S *\<^sub>R (\<Sum>j\<in>S. (a j / sum a S) *\<^sub>R y j) \<in> C"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   233
      by (rule convexD)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   234
    then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   235
      by (simp add: scaleR_sum_right False)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   236
  qed
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   237
  then show ?case using \<open>finite S\<close> and \<open>i \<notin> S\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   238
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   239
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   240
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   241
lemma convex:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   242
  "convex S \<longleftrightarrow> (\<forall>(k::nat) u x. (\<forall>i. 1\<le>i \<and> i\<le>k \<longrightarrow> 0 \<le> u i \<and> x i \<in>S) \<and> (sum u {1..k} = 1)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   243
      \<longrightarrow> sum (\<lambda>i. u i *\<^sub>R x i) {1..k} \<in> S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   244
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   245
  fix k :: nat
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   246
  fix u :: "nat \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   247
  fix x
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   248
  assume "convex S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   249
    "\<forall>i. 1 \<le> i \<and> i \<le> k \<longrightarrow> 0 \<le> u i \<and> x i \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   250
    "sum u {1..k} = 1"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   251
  with convex_sum[of "{1 .. k}" S] show "(\<Sum>j\<in>{1 .. k}. u j *\<^sub>R x j) \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   252
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   253
next
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   254
  assume *: "\<forall>k u x. (\<forall> i :: nat. 1 \<le> i \<and> i \<le> k \<longrightarrow> 0 \<le> u i \<and> x i \<in> S) \<and> sum u {1..k} = 1
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   255
    \<longrightarrow> (\<Sum>i = 1..k. u i *\<^sub>R (x i :: 'a)) \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   256
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   257
    fix \<mu> :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   258
    fix x y :: 'a
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   259
    assume xy: "x \<in> S" "y \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   260
    assume mu: "\<mu> \<ge> 0" "\<mu> \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   261
    let ?u = "\<lambda>i. if (i :: nat) = 1 then \<mu> else 1 - \<mu>"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   262
    let ?x = "\<lambda>i. if (i :: nat) = 1 then x else y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   263
    have "{1 :: nat .. 2} \<inter> - {x. x = 1} = {2}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   264
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   265
    then have card: "card ({1 :: nat .. 2} \<inter> - {x. x = 1}) = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   266
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   267
    then have "sum ?u {1 .. 2} = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   268
      using sum.If_cases[of "{(1 :: nat) .. 2}" "\<lambda> x. x = 1" "\<lambda> x. \<mu>" "\<lambda> x. 1 - \<mu>"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   269
      by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   270
    with *[rule_format, of "2" ?u ?x] have S: "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   271
      using mu xy by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   272
    have grarr: "(\<Sum>j \<in> {Suc (Suc 0)..2}. ?u j *\<^sub>R ?x j) = (1 - \<mu>) *\<^sub>R y"
70097
4005298550a6 The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
paulson <lp15@cam.ac.uk>
parents: 70086
diff changeset
   273
      using sum.atLeast_Suc_atMost[of "Suc (Suc 0)" 2 "\<lambda> j. (1 - \<mu>) *\<^sub>R y"] by auto
4005298550a6 The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
paulson <lp15@cam.ac.uk>
parents: 70086
diff changeset
   274
    from sum.atLeast_Suc_atMost[of "Suc 0" 2 "\<lambda> j. ?u j *\<^sub>R ?x j", simplified this]
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   275
    have "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) = \<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   276
      by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   277
    then have "(1 - \<mu>) *\<^sub>R y + \<mu> *\<^sub>R x \<in> S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   278
      using S by (auto simp: add.commute)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   279
  }
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   280
  then show "convex S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   281
    unfolding convex_alt by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   282
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   283
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   284
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   285
lemma convex_explicit:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   286
  fixes S :: "'a::real_vector set"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   287
  shows "convex S \<longleftrightarrow>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   288
    (\<forall>t u. finite t \<and> t \<subseteq> S \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and> sum u t = 1 \<longrightarrow> sum (\<lambda>x. u x *\<^sub>R x) t \<in> S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   289
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   290
  fix t
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   291
  fix u :: "'a \<Rightarrow> real"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   292
  assume "convex S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   293
    and "finite t"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   294
    and "t \<subseteq> S" "\<forall>x\<in>t. 0 \<le> u x" "sum u t = 1"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   295
  then show "(\<Sum>x\<in>t. u x *\<^sub>R x) \<in> S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   296
    using convex_sum[of t S u "\<lambda> x. x"] by auto
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   297
next
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   298
  assume *: "\<forall>t. \<forall> u. finite t \<and> t \<subseteq> S \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   299
    sum u t = 1 \<longrightarrow> (\<Sum>x\<in>t. u x *\<^sub>R x) \<in> S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   300
  show "convex S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   301
    unfolding convex_alt
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   302
  proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   303
    fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   304
    fix \<mu> :: real
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   305
    assume **: "x \<in> S" "y \<in> S" "0 \<le> \<mu>" "\<mu> \<le> 1"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   306
    show "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   307
    proof (cases "x = y")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   308
      case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   309
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   310
        using *[rule_format, of "{x, y}" "\<lambda> z. if z = x then 1 - \<mu> else \<mu>"] **
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   311
        by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   312
    next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   313
      case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   314
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   315
        using *[rule_format, of "{x, y}" "\<lambda> z. 1"] **
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   316
        by (auto simp: field_simps real_vector.scale_left_diff_distrib)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   317
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   318
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   319
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   320
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   321
lemma convex_finite:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   322
  assumes "finite S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   323
  shows "convex S \<longleftrightarrow> (\<forall>u. (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<longrightarrow> sum (\<lambda>x. u x *\<^sub>R x) S \<in> S)"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   324
       (is "?lhs = ?rhs")
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   325
proof 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   326
  { have if_distrib_arg: "\<And>P f g x. (if P then f else g) x = (if P then f x else g x)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   327
      by simp
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   328
    fix T :: "'a set" and u :: "'a \<Rightarrow> real"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   329
    assume sum: "\<forall>u. (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<longrightarrow> (\<Sum>x\<in>S. u x *\<^sub>R x) \<in> S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   330
    assume *: "\<forall>x\<in>T. 0 \<le> u x" "sum u T = 1"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   331
    assume "T \<subseteq> S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   332
    then have "S \<inter> T = T" by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   333
    with sum[THEN spec[where x="\<lambda>x. if x\<in>T then u x else 0"]] * have "(\<Sum>x\<in>T. u x *\<^sub>R x) \<in> S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   334
      by (auto simp: assms sum.If_cases if_distrib if_distrib_arg) }
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   335
  moreover assume ?rhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   336
  ultimately show ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   337
    unfolding convex_explicit by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   338
qed (auto simp: convex_explicit assms)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   339
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   340
71044
nipkow
parents: 71040
diff changeset
   341
subsection \<open>Convex Functions on a Set\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   342
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
   343
definition\<^marker>\<open>tag important\<close> convex_on :: "'a::real_vector set \<Rightarrow> ('a \<Rightarrow> real) \<Rightarrow> bool"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   344
  where "convex_on S f \<longleftrightarrow>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   345
    (\<forall>x\<in>S. \<forall>y\<in>S. \<forall>u\<ge>0. \<forall>v\<ge>0. u + v = 1 \<longrightarrow> f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   346
74729
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   347
definition\<^marker>\<open>tag important\<close> concave_on :: "'a::real_vector set \<Rightarrow> ('a \<Rightarrow> real) \<Rightarrow> bool"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   348
  where "concave_on S f \<equiv> convex_on S (\<lambda>x. - f x)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   349
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   350
lemma concave_on_iff:
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   351
  "concave_on S f \<longleftrightarrow>
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   352
    (\<forall>x\<in>S. \<forall>y\<in>S. \<forall>u\<ge>0. \<forall>v\<ge>0. u + v = 1 \<longrightarrow> f (u *\<^sub>R x + v *\<^sub>R y) \<ge> u * f x + v * f y)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   353
  by (auto simp: concave_on_def convex_on_def algebra_simps)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   354
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   355
lemma convex_onI [intro?]:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   356
  assumes "\<And>t x y. t > 0 \<Longrightarrow> t < 1 \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   357
    f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \<le> (1 - t) * f x + t * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   358
  shows "convex_on A f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   359
  unfolding convex_on_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   360
proof clarify
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   361
  fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   362
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   363
  assume A: "x \<in> A" "y \<in> A" "u \<ge> 0" "v \<ge> 0" "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   364
  from A(5) have [simp]: "v = 1 - u"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   365
    by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   366
  from A(1-4) show "f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   367
    using assms[of u y x]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   368
    by (cases "u = 0 \<or> u = 1") (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   369
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   370
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   371
lemma convex_on_linorderI [intro?]:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   372
  fixes A :: "('a::{linorder,real_vector}) set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   373
  assumes "\<And>t x y. t > 0 \<Longrightarrow> t < 1 \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x < y \<Longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   374
    f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \<le> (1 - t) * f x + t * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   375
  shows "convex_on A f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   376
proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   377
  fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   378
  fix t :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   379
  assume A: "x \<in> A" "y \<in> A" "t > 0" "t < 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   380
  with assms [of t x y] assms [of "1 - t" y x]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   381
  show "f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \<le> (1 - t) * f x + t * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   382
    by (cases x y rule: linorder_cases) (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   383
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   384
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   385
lemma convex_onD:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   386
  assumes "convex_on A f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   387
  shows "\<And>t x y. t \<ge> 0 \<Longrightarrow> t \<le> 1 \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   388
    f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \<le> (1 - t) * f x + t * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   389
  using assms by (auto simp: convex_on_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   390
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   391
lemma convex_onD_Icc:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   392
  assumes "convex_on {x..y} f" "x \<le> (y :: _ :: {real_vector,preorder})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   393
  shows "\<And>t. t \<ge> 0 \<Longrightarrow> t \<le> 1 \<Longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   394
    f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \<le> (1 - t) * f x + t * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   395
  using assms(2) by (intro convex_onD [OF assms(1)]) simp_all
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   396
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   397
lemma convex_on_subset: "convex_on t f \<Longrightarrow> S \<subseteq> t \<Longrightarrow> convex_on S f"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   398
  unfolding convex_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   399
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   400
lemma convex_on_add [intro]:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   401
  assumes "convex_on S f"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   402
    and "convex_on S g"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   403
  shows "convex_on S (\<lambda>x. f x + g x)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   404
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   405
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   406
    fix x y
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   407
    assume "x \<in> S" "y \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   408
    moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   409
    fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   410
    assume "0 \<le> u" "0 \<le> v" "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   411
    ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   412
    have "f (u *\<^sub>R x + v *\<^sub>R y) + g (u *\<^sub>R x + v *\<^sub>R y) \<le> (u * f x + v * f y) + (u * g x + v * g y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   413
      using assms unfolding convex_on_def by (auto simp: add_mono)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   414
    then have "f (u *\<^sub>R x + v *\<^sub>R y) + g (u *\<^sub>R x + v *\<^sub>R y) \<le> u * (f x + g x) + v * (f y + g y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   415
      by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   416
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   417
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   418
    unfolding convex_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   419
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   420
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   421
lemma convex_on_cmul [intro]:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   422
  fixes c :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   423
  assumes "0 \<le> c"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   424
    and "convex_on S f"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   425
  shows "convex_on S (\<lambda>x. c * f x)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   426
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   427
  have *: "u * (c * fx) + v * (c * fy) = c * (u * fx + v * fy)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   428
    for u c fx v fy :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   429
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   430
  show ?thesis using assms(2) and mult_left_mono [OF _ assms(1)]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   431
    unfolding convex_on_def and * by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   432
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   433
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   434
lemma convex_lower:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   435
  assumes "convex_on S f"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   436
    and "x \<in> S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   437
    and "y \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   438
    and "0 \<le> u"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   439
    and "0 \<le> v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   440
    and "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   441
  shows "f (u *\<^sub>R x + v *\<^sub>R y) \<le> max (f x) (f y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   442
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   443
  let ?m = "max (f x) (f y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   444
  have "u * f x + v * f y \<le> u * max (f x) (f y) + v * max (f x) (f y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   445
    using assms(4,5) by (auto simp: mult_left_mono add_mono)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   446
  also have "\<dots> = max (f x) (f y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   447
    using assms(6) by (simp add: distrib_right [symmetric])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   448
  finally show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   449
    using assms unfolding convex_on_def by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   450
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   451
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   452
lemma convex_on_dist [intro]:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   453
  fixes S :: "'a::real_normed_vector set"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   454
  shows "convex_on S (\<lambda>x. dist a x)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   455
proof (auto simp: convex_on_def dist_norm)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   456
  fix x y
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   457
  assume "x \<in> S" "y \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   458
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   459
  assume "0 \<le> u"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   460
  assume "0 \<le> v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   461
  assume "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   462
  have "a = u *\<^sub>R a + v *\<^sub>R a"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   463
    unfolding scaleR_left_distrib[symmetric] and \<open>u + v = 1\<close> by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   464
  then have *: "a - (u *\<^sub>R x + v *\<^sub>R y) = (u *\<^sub>R (a - x)) + (v *\<^sub>R (a - y))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   465
    by (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   466
  show "norm (a - (u *\<^sub>R x + v *\<^sub>R y)) \<le> u * norm (a - x) + v * norm (a - y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   467
    unfolding * using norm_triangle_ineq[of "u *\<^sub>R (a - x)" "v *\<^sub>R (a - y)"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   468
    using \<open>0 \<le> u\<close> \<open>0 \<le> v\<close> by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   469
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   470
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   471
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
   472
subsection\<^marker>\<open>tag unimportant\<close> \<open>Arithmetic operations on sets preserve convexity\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   473
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   474
lemma convex_linear_image:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   475
  assumes "linear f"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   476
    and "convex S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   477
  shows "convex (f ` S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   478
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   479
  interpret f: linear f by fact
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   480
  from \<open>convex S\<close> show "convex (f ` S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   481
    by (simp add: convex_def f.scaleR [symmetric] f.add [symmetric])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   482
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   483
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   484
lemma convex_linear_vimage:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   485
  assumes "linear f"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   486
    and "convex S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   487
  shows "convex (f -` S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   488
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   489
  interpret f: linear f by fact
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   490
  from \<open>convex S\<close> show "convex (f -` S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   491
    by (simp add: convex_def f.add f.scaleR)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   492
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   493
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   494
lemma convex_scaling:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   495
  assumes "convex S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   496
  shows "convex ((\<lambda>x. c *\<^sub>R x) ` S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   497
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   498
  have "linear (\<lambda>x. c *\<^sub>R x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   499
    by (simp add: linearI scaleR_add_right)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   500
  then show ?thesis
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   501
    using \<open>convex S\<close> by (rule convex_linear_image)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   502
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   503
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   504
lemma convex_scaled:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   505
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   506
  shows "convex ((\<lambda>x. x *\<^sub>R c) ` S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   507
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   508
  have "linear (\<lambda>x. x *\<^sub>R c)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   509
    by (simp add: linearI scaleR_add_left)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   510
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   511
    using \<open>convex S\<close> by (rule convex_linear_image)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   512
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   513
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   514
lemma convex_negations:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   515
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   516
  shows "convex ((\<lambda>x. - x) ` S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   517
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   518
  have "linear (\<lambda>x. - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   519
    by (simp add: linearI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   520
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   521
    using \<open>convex S\<close> by (rule convex_linear_image)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   522
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   523
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   524
lemma convex_sums:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   525
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   526
    and "convex T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   527
  shows "convex (\<Union>x\<in> S. \<Union>y \<in> T. {x + y})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   528
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   529
  have "linear (\<lambda>(x, y). x + y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   530
    by (auto intro: linearI simp: scaleR_add_right)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   531
  with assms have "convex ((\<lambda>(x, y). x + y) ` (S \<times> T))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   532
    by (intro convex_linear_image convex_Times)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   533
  also have "((\<lambda>(x, y). x + y) ` (S \<times> T)) = (\<Union>x\<in> S. \<Union>y \<in> T. {x + y})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   534
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   535
  finally show ?thesis .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   536
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   537
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   538
lemma convex_differences:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   539
  assumes "convex S" "convex T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   540
  shows "convex (\<Union>x\<in> S. \<Union>y \<in> T. {x - y})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   541
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   542
  have "{x - y| x y. x \<in> S \<and> y \<in> T} = {x + y |x y. x \<in> S \<and> y \<in> uminus ` T}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   543
    by (auto simp: diff_conv_add_uminus simp del: add_uminus_conv_diff)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   544
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   545
    using convex_sums[OF assms(1) convex_negations[OF assms(2)]] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   546
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   547
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   548
lemma convex_translation:
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   549
  "convex ((+) a ` S)" if "convex S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   550
proof -
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   551
  have "(\<Union> x\<in> {a}. \<Union>y \<in> S. {x + y}) = (+) a ` S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   552
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   553
  then show ?thesis
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   554
    using convex_sums [OF convex_singleton [of a] that] by auto
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   555
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   556
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   557
lemma convex_translation_subtract:
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   558
  "convex ((\<lambda>b. b - a) ` S)" if "convex S"
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   559
  using convex_translation [of S "- a"] that by (simp cong: image_cong_simp)
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   560
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   561
lemma convex_affinity:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   562
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   563
  shows "convex ((\<lambda>x. a + c *\<^sub>R x) ` S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   564
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   565
  have "(\<lambda>x. a + c *\<^sub>R x) ` S = (+) a ` (*\<^sub>R) c ` S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   566
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   567
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   568
    using convex_translation[OF convex_scaling[OF assms], of a c] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   569
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   570
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   571
lemma convex_on_sum:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   572
  fixes a :: "'a \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   573
    and y :: "'a \<Rightarrow> 'b::real_vector"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   574
    and f :: "'b \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   575
  assumes "finite s" "s \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   576
    and "convex_on C f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   577
    and "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   578
    and "(\<Sum> i \<in> s. a i) = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   579
    and "\<And>i. i \<in> s \<Longrightarrow> a i \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   580
    and "\<And>i. i \<in> s \<Longrightarrow> y i \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   581
  shows "f (\<Sum> i \<in> s. a i *\<^sub>R y i) \<le> (\<Sum> i \<in> s. a i * f (y i))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   582
  using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   583
proof (induct s arbitrary: a rule: finite_ne_induct)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   584
  case (singleton i)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   585
  then have ai: "a i = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   586
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   587
  then show ?case
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   588
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   589
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   590
  case (insert i s)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   591
  then have "convex_on C f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   592
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   593
  from this[unfolded convex_on_def, rule_format]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   594
  have conv: "\<And>x y \<mu>. x \<in> C \<Longrightarrow> y \<in> C \<Longrightarrow> 0 \<le> \<mu> \<Longrightarrow> \<mu> \<le> 1 \<Longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   595
      f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   596
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   597
  show ?case
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   598
  proof (cases "a i = 1")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   599
    case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   600
    then have "(\<Sum> j \<in> s. a j) = 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   601
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   602
    then have "\<And>j. j \<in> s \<Longrightarrow> a j = 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   603
      using insert by (fastforce simp: sum_nonneg_eq_0_iff)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   604
    then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   605
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   606
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   607
    case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   608
    from insert have yai: "y i \<in> C" "a i \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   609
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   610
    have fis: "finite (insert i s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   611
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   612
    then have ai1: "a i \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   613
      using sum_nonneg_leq_bound[of "insert i s" a] insert by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   614
    then have "a i < 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   615
      using False by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   616
    then have i0: "1 - a i > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   617
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   618
    let ?a = "\<lambda>j. a j / (1 - a i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   619
    have a_nonneg: "?a j \<ge> 0" if "j \<in> s" for j
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   620
      using i0 insert that by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   621
    have "(\<Sum> j \<in> insert i s. a j) = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   622
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   623
    then have "(\<Sum> j \<in> s. a j) = 1 - a i"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   624
      using sum.insert insert by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   625
    then have "(\<Sum> j \<in> s. a j) / (1 - a i) = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   626
      using i0 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   627
    then have a1: "(\<Sum> j \<in> s. ?a j) = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   628
      unfolding sum_divide_distrib by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   629
    have "convex C" using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   630
    then have asum: "(\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   631
      using insert convex_sum [OF \<open>finite s\<close> \<open>convex C\<close> a1 a_nonneg] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   632
    have asum_le: "f (\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<le> (\<Sum> j \<in> s. ?a j * f (y j))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   633
      using a_nonneg a1 insert by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   634
    have "f (\<Sum> j \<in> insert i s. a j *\<^sub>R y j) = f ((\<Sum> j \<in> s. a j *\<^sub>R y j) + a i *\<^sub>R y i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   635
      using sum.insert[of s i "\<lambda> j. a j *\<^sub>R y j", OF \<open>finite s\<close> \<open>i \<notin> s\<close>] insert
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   636
      by (auto simp only: add.commute)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   637
    also have "\<dots> = f (((1 - a i) * inverse (1 - a i)) *\<^sub>R (\<Sum> j \<in> s. a j *\<^sub>R y j) + a i *\<^sub>R y i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   638
      using i0 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   639
    also have "\<dots> = f ((1 - a i) *\<^sub>R (\<Sum> j \<in> s. (a j * inverse (1 - a i)) *\<^sub>R y j) + a i *\<^sub>R y i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   640
      using scaleR_right.sum[of "inverse (1 - a i)" "\<lambda> j. a j *\<^sub>R y j" s, symmetric]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   641
      by (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   642
    also have "\<dots> = f ((1 - a i) *\<^sub>R (\<Sum> j \<in> s. ?a j *\<^sub>R y j) + a i *\<^sub>R y i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   643
      by (auto simp: divide_inverse)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   644
    also have "\<dots> \<le> (1 - a i) *\<^sub>R f ((\<Sum> j \<in> s. ?a j *\<^sub>R y j)) + a i * f (y i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   645
      using conv[of "y i" "(\<Sum> j \<in> s. ?a j *\<^sub>R y j)" "a i", OF yai(1) asum yai(2) ai1]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   646
      by (auto simp: add.commute)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   647
    also have "\<dots> \<le> (1 - a i) * (\<Sum> j \<in> s. ?a j * f (y j)) + a i * f (y i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   648
      using add_right_mono [OF mult_left_mono [of _ _ "1 - a i",
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   649
            OF asum_le less_imp_le[OF i0]], of "a i * f (y i)"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   650
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   651
    also have "\<dots> = (\<Sum> j \<in> s. (1 - a i) * ?a j * f (y j)) + a i * f (y i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   652
      unfolding sum_distrib_left[of "1 - a i" "\<lambda> j. ?a j * f (y j)"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   653
      using i0 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   654
    also have "\<dots> = (\<Sum> j \<in> s. a j * f (y j)) + a i * f (y i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   655
      using i0 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   656
    also have "\<dots> = (\<Sum> j \<in> insert i s. a j * f (y j))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   657
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   658
    finally show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   659
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   660
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   661
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   662
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   663
lemma convex_on_alt:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   664
  fixes C :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   665
  shows "convex_on C f \<longleftrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   666
    (\<forall>x \<in> C. \<forall> y \<in> C. \<forall> \<mu> :: real. \<mu> \<ge> 0 \<and> \<mu> \<le> 1 \<longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   667
      f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   668
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   669
  fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   670
  fix \<mu> :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   671
  assume *: "convex_on C f" "x \<in> C" "y \<in> C" "0 \<le> \<mu>" "\<mu> \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   672
  from this[unfolded convex_on_def, rule_format]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   673
  have "0 \<le> u \<Longrightarrow> 0 \<le> v \<Longrightarrow> u + v = 1 \<Longrightarrow> f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y" for u v
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   674
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   675
  from this [of "\<mu>" "1 - \<mu>", simplified] *
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   676
  show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   677
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   678
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   679
  assume *: "\<forall>x\<in>C. \<forall>y\<in>C. \<forall>\<mu>. 0 \<le> \<mu> \<and> \<mu> \<le> 1 \<longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   680
    f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   681
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   682
    fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   683
    fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   684
    assume **: "x \<in> C" "y \<in> C" "u \<ge> 0" "v \<ge> 0" "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   685
    then have[simp]: "1 - u = v" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   686
    from *[rule_format, of x y u]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   687
    have "f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   688
      using ** by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   689
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   690
  then show "convex_on C f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   691
    unfolding convex_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   692
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   693
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   694
lemma convex_on_diff:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   695
  fixes f :: "real \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   696
  assumes f: "convex_on I f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   697
    and I: "x \<in> I" "y \<in> I"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   698
    and t: "x < t" "t < y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   699
  shows "(f x - f t) / (x - t) \<le> (f x - f y) / (x - y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   700
    and "(f x - f y) / (x - y) \<le> (f t - f y) / (t - y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   701
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   702
  define a where "a \<equiv> (t - y) / (x - y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   703
  with t have "0 \<le> a" "0 \<le> 1 - a"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   704
    by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   705
  with f \<open>x \<in> I\<close> \<open>y \<in> I\<close> have cvx: "f (a * x + (1 - a) * y) \<le> a * f x + (1 - a) * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   706
    by (auto simp: convex_on_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   707
  have "a * x + (1 - a) * y = a * (x - y) + y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   708
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   709
  also have "\<dots> = t"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   710
    unfolding a_def using \<open>x < t\<close> \<open>t < y\<close> by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   711
  finally have "f t \<le> a * f x + (1 - a) * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   712
    using cvx by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   713
  also have "\<dots> = a * (f x - f y) + f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   714
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   715
  finally have "f t - f y \<le> a * (f x - f y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   716
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   717
  with t show "(f x - f t) / (x - t) \<le> (f x - f y) / (x - y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   718
    by (simp add: le_divide_eq divide_le_eq field_simps a_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   719
  with t show "(f x - f y) / (x - y) \<le> (f t - f y) / (t - y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   720
    by (simp add: le_divide_eq divide_le_eq field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   721
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   722
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   723
lemma pos_convex_function:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   724
  fixes f :: "real \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   725
  assumes "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   726
    and leq: "\<And>x y. x \<in> C \<Longrightarrow> y \<in> C \<Longrightarrow> f' x * (y - x) \<le> f y - f x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   727
  shows "convex_on C f"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   728
  unfolding convex_on_alt
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   729
  using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   730
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   731
  fix x y \<mu> :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   732
  let ?x = "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   733
  assume *: "convex C" "x \<in> C" "y \<in> C" "\<mu> \<ge> 0" "\<mu> \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   734
  then have "1 - \<mu> \<ge> 0" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   735
  then have xpos: "?x \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   736
    using * unfolding convex_alt by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   737
  have geq: "\<mu> * (f x - f ?x) + (1 - \<mu>) * (f y - f ?x) \<ge>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   738
      \<mu> * f' ?x * (x - ?x) + (1 - \<mu>) * f' ?x * (y - ?x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   739
    using add_mono [OF mult_left_mono [OF leq [OF xpos *(2)] \<open>\<mu> \<ge> 0\<close>]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   740
        mult_left_mono [OF leq [OF xpos *(3)] \<open>1 - \<mu> \<ge> 0\<close>]]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   741
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   742
  then have "\<mu> * f x + (1 - \<mu>) * f y - f ?x \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   743
    by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   744
  then show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   745
    by auto
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   746
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   747
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   748
lemma atMostAtLeast_subset_convex:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   749
  fixes C :: "real set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   750
  assumes "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   751
    and "x \<in> C" "y \<in> C" "x < y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   752
  shows "{x .. y} \<subseteq> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   753
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   754
  fix z assume z: "z \<in> {x .. y}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   755
  have less: "z \<in> C" if *: "x < z" "z < y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   756
  proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   757
    let ?\<mu> = "(y - z) / (y - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   758
    have "0 \<le> ?\<mu>" "?\<mu> \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   759
      using assms * by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   760
    then have comb: "?\<mu> * x + (1 - ?\<mu>) * y \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   761
      using assms iffD1[OF convex_alt, rule_format, of C y x ?\<mu>]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   762
      by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   763
    have "?\<mu> * x + (1 - ?\<mu>) * y = (y - z) * x / (y - x) + (1 - (y - z) / (y - x)) * y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   764
      by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   765
    also have "\<dots> = ((y - z) * x + (y - x - (y - z)) * y) / (y - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   766
      using assms by (simp only: add_divide_distrib) (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   767
    also have "\<dots> = z"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   768
      using assms by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   769
    finally show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   770
      using comb by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   771
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   772
  show "z \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   773
    using z less assms by (auto simp: le_less)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   774
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   775
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   776
lemma f''_imp_f':
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   777
  fixes f :: "real \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   778
  assumes "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   779
    and f': "\<And>x. x \<in> C \<Longrightarrow> DERIV f x :> (f' x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   780
    and f'': "\<And>x. x \<in> C \<Longrightarrow> DERIV f' x :> (f'' x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   781
    and pos: "\<And>x. x \<in> C \<Longrightarrow> f'' x \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   782
    and x: "x \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   783
    and y: "y \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   784
  shows "f' x * (y - x) \<le> f y - f x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   785
  using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   786
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   787
  have less_imp: "f y - f x \<ge> f' x * (y - x)" "f' y * (x - y) \<le> f x - f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   788
    if *: "x \<in> C" "y \<in> C" "y > x" for x y :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   789
  proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   790
    from * have ge: "y - x > 0" "y - x \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   791
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   792
    from * have le: "x - y < 0" "x - y \<le> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   793
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   794
    then obtain z1 where z1: "z1 > x" "z1 < y" "f y - f x = (y - x) * f' z1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   795
      using subsetD[OF atMostAtLeast_subset_convex[OF \<open>convex C\<close> \<open>x \<in> C\<close> \<open>y \<in> C\<close> \<open>x < y\<close>],
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   796
          THEN f', THEN MVT2[OF \<open>x < y\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   797
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   798
    then have "z1 \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   799
      using atMostAtLeast_subset_convex \<open>convex C\<close> \<open>x \<in> C\<close> \<open>y \<in> C\<close> \<open>x < y\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   800
      by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   801
    from z1 have z1': "f x - f y = (x - y) * f' z1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   802
      by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   803
    obtain z2 where z2: "z2 > x" "z2 < z1" "f' z1 - f' x = (z1 - x) * f'' z2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   804
      using subsetD[OF atMostAtLeast_subset_convex[OF \<open>convex C\<close> \<open>x \<in> C\<close> \<open>z1 \<in> C\<close> \<open>x < z1\<close>],
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   805
          THEN f'', THEN MVT2[OF \<open>x < z1\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   806
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   807
    obtain z3 where z3: "z3 > z1" "z3 < y" "f' y - f' z1 = (y - z1) * f'' z3"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   808
      using subsetD[OF atMostAtLeast_subset_convex[OF \<open>convex C\<close> \<open>z1 \<in> C\<close> \<open>y \<in> C\<close> \<open>z1 < y\<close>],
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   809
          THEN f'', THEN MVT2[OF \<open>z1 < y\<close>, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   810
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   811
    have "f' y - (f x - f y) / (x - y) = f' y - f' z1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   812
      using * z1' by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   813
    also have "\<dots> = (y - z1) * f'' z3"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   814
      using z3 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   815
    finally have cool': "f' y - (f x - f y) / (x - y) = (y - z1) * f'' z3"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   816
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   817
    have A': "y - z1 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   818
      using z1 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   819
    have "z3 \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   820
      using z3 * atMostAtLeast_subset_convex \<open>convex C\<close> \<open>x \<in> C\<close> \<open>z1 \<in> C\<close> \<open>x < z1\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   821
      by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   822
    then have B': "f'' z3 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   823
      using assms by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   824
    from A' B' have "(y - z1) * f'' z3 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   825
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   826
    from cool' this have "f' y - (f x - f y) / (x - y) \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   827
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   828
    from mult_right_mono_neg[OF this le(2)]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   829
    have "f' y * (x - y) - (f x - f y) / (x - y) * (x - y) \<le> 0 * (x - y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   830
      by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   831
    then have "f' y * (x - y) - (f x - f y) \<le> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   832
      using le by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   833
    then have res: "f' y * (x - y) \<le> f x - f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   834
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   835
    have "(f y - f x) / (y - x) - f' x = f' z1 - f' x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   836
      using * z1 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   837
    also have "\<dots> = (z1 - x) * f'' z2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   838
      using z2 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   839
    finally have cool: "(f y - f x) / (y - x) - f' x = (z1 - x) * f'' z2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   840
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   841
    have A: "z1 - x \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   842
      using z1 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   843
    have "z2 \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   844
      using z2 z1 * atMostAtLeast_subset_convex \<open>convex C\<close> \<open>z1 \<in> C\<close> \<open>y \<in> C\<close> \<open>z1 < y\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   845
      by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   846
    then have B: "f'' z2 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   847
      using assms by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   848
    from A B have "(z1 - x) * f'' z2 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   849
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   850
    with cool have "(f y - f x) / (y - x) - f' x \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   851
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   852
    from mult_right_mono[OF this ge(2)]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   853
    have "(f y - f x) / (y - x) * (y - x) - f' x * (y - x) \<ge> 0 * (y - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   854
      by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   855
    then have "f y - f x - f' x * (y - x) \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   856
      using ge by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   857
    then show "f y - f x \<ge> f' x * (y - x)" "f' y * (x - y) \<le> f x - f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   858
      using res by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   859
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   860
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   861
  proof (cases "x = y")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   862
    case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   863
    with x y show ?thesis by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   864
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   865
    case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   866
    with less_imp x y show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   867
      by (auto simp: neq_iff)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   868
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   869
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   870
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   871
lemma f''_ge0_imp_convex:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   872
  fixes f :: "real \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   873
  assumes conv: "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   874
    and f': "\<And>x. x \<in> C \<Longrightarrow> DERIV f x :> (f' x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   875
    and f'': "\<And>x. x \<in> C \<Longrightarrow> DERIV f' x :> (f'' x)"
74729
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   876
    and 0: "\<And>x. x \<in> C \<Longrightarrow> f'' x \<ge> 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   877
  shows "convex_on C f"
74729
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   878
  using f''_imp_f'[OF conv f' f'' 0] assms pos_convex_function
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   879
  by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   880
74729
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   881
lemma f''_le0_imp_concave:
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   882
  fixes f :: "real \<Rightarrow> real"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   883
  assumes "convex C"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   884
    and "\<And>x. x \<in> C \<Longrightarrow> DERIV f x :> (f' x)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   885
    and "\<And>x. x \<in> C \<Longrightarrow> DERIV f' x :> (f'' x)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   886
    and "\<And>x. x \<in> C \<Longrightarrow> f'' x \<le> 0"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   887
  shows "concave_on C f"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   888
  unfolding concave_on_def
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   889
  by (rule assms f''_ge0_imp_convex derivative_eq_intros | simp)+
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   890
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   891
lemma log_concave:
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   892
  fixes b :: real
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   893
  assumes "b > 1"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   894
  shows "concave_on {0<..} (\<lambda> x. log b x)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   895
  using assms
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   896
  by (intro f''_le0_imp_concave derivative_eq_intros | simp)+
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   897
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   898
lemma ln_concave: "concave_on {0<..} ln"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   899
  unfolding log_ln by (simp add: log_concave)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   900
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   901
lemma minus_log_convex:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   902
  fixes b :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   903
  assumes "b > 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   904
  shows "convex_on {0 <..} (\<lambda> x. - log b x)"
74729
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   905
  using assms concave_on_def log_concave by blast
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   906
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   907
lemma powr_convex: 
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   908
  assumes "p \<ge> 1" shows "convex_on {0<..} (\<lambda>x. x powr p)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   909
  using assms
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   910
  by (intro f''_ge0_imp_convex derivative_eq_intros | simp)+
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   911
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   912
lemma exp_convex: "convex_on UNIV exp"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
   913
  by (intro f''_ge0_imp_convex derivative_eq_intros | simp)+
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   914
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   915
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
   916
subsection\<^marker>\<open>tag unimportant\<close> \<open>Convexity of real functions\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   917
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   918
lemma convex_on_realI:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   919
  assumes "connected A"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   920
    and "\<And>x. x \<in> A \<Longrightarrow> (f has_real_derivative f' x) (at x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   921
    and "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x \<le> y \<Longrightarrow> f' x \<le> f' y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   922
  shows "convex_on A f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   923
proof (rule convex_on_linorderI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   924
  fix t x y :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   925
  assume t: "t > 0" "t < 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   926
  assume xy: "x \<in> A" "y \<in> A" "x < y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   927
  define z where "z = (1 - t) * x + t * y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   928
  with \<open>connected A\<close> and xy have ivl: "{x..y} \<subseteq> A"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   929
    using connected_contains_Icc by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   930
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   931
  from xy t have xz: "z > x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   932
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   933
  have "y - z = (1 - t) * (y - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   934
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   935
  also from xy t have "\<dots> > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   936
    by (intro mult_pos_pos) simp_all
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   937
  finally have yz: "z < y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   938
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   939
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   940
  from assms xz yz ivl t have "\<exists>\<xi>. \<xi> > x \<and> \<xi> < z \<and> f z - f x = (z - x) * f' \<xi>"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   941
    by (intro MVT2) (auto intro!: assms(2))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   942
  then obtain \<xi> where \<xi>: "\<xi> > x" "\<xi> < z" "f' \<xi> = (f z - f x) / (z - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   943
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   944
  from assms xz yz ivl t have "\<exists>\<eta>. \<eta> > z \<and> \<eta> < y \<and> f y - f z = (y - z) * f' \<eta>"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   945
    by (intro MVT2) (auto intro!: assms(2))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   946
  then obtain \<eta> where \<eta>: "\<eta> > z" "\<eta> < y" "f' \<eta> = (f y - f z) / (y - z)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   947
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   948
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   949
  from \<eta>(3) have "(f y - f z) / (y - z) = f' \<eta>" ..
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   950
  also from \<xi> \<eta> ivl have "\<xi> \<in> A" "\<eta> \<in> A"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   951
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   952
  with \<xi> \<eta> have "f' \<eta> \<ge> f' \<xi>"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   953
    by (intro assms(3)) auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   954
  also from \<xi>(3) have "f' \<xi> = (f z - f x) / (z - x)" .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   955
  finally have "(f y - f z) * (z - x) \<ge> (f z - f x) * (y - z)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   956
    using xz yz by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   957
  also have "z - x = t * (y - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   958
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   959
  also have "y - z = (1 - t) * (y - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   960
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   961
  finally have "(f y - f z) * t \<ge> (f z - f x) * (1 - t)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   962
    using xy by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   963
  then show "(1 - t) * f x + t * f y \<ge> f ((1 - t) *\<^sub>R x + t *\<^sub>R y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   964
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   965
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   966
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   967
lemma convex_on_inverse:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   968
  assumes "A \<subseteq> {0<..}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   969
  shows "convex_on A (inverse :: real \<Rightarrow> real)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   970
proof (rule convex_on_subset[OF _ assms], intro convex_on_realI[of _ _ "\<lambda>x. -inverse (x^2)"])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   971
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   972
  assume "u \<in> {0<..}" "v \<in> {0<..}" "u \<le> v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   973
  with assms show "-inverse (u^2) \<le> -inverse (v^2)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   974
    by (intro le_imp_neg_le le_imp_inverse_le power_mono) (simp_all)
70817
dd675800469d dedicated fact collections for algebraic simplification rules potentially splitting goals
haftmann
parents: 70136
diff changeset
   975
qed (insert assms, auto intro!: derivative_eq_intros simp: field_split_simps power2_eq_square)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   976
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   977
lemma convex_onD_Icc':
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   978
  assumes "convex_on {x..y} f" "c \<in> {x..y}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   979
  defines "d \<equiv> y - x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   980
  shows "f c \<le> (f y - f x) / d * (c - x) + f x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   981
proof (cases x y rule: linorder_cases)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   982
  case less
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   983
  then have d: "d > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   984
    by (simp add: d_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   985
  from assms(2) less have A: "0 \<le> (c - x) / d" "(c - x) / d \<le> 1"
70817
dd675800469d dedicated fact collections for algebraic simplification rules potentially splitting goals
haftmann
parents: 70136
diff changeset
   986
    by (simp_all add: d_def field_split_simps)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   987
  have "f c = f (x + (c - x) * 1)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   988
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   989
  also from less have "1 = ((y - x) / d)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   990
    by (simp add: d_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   991
  also from d have "x + (c - x) * \<dots> = (1 - (c - x) / d) *\<^sub>R x + ((c - x) / d) *\<^sub>R y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   992
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   993
  also have "f \<dots> \<le> (1 - (c - x) / d) * f x + (c - x) / d * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   994
    using assms less by (intro convex_onD_Icc) simp_all
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   995
  also from d have "\<dots> = (f y - f x) / d * (c - x) + f x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   996
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   997
  finally show ?thesis .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   998
qed (insert assms(2), simp_all)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   999
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1000
lemma convex_onD_Icc'':
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1001
  assumes "convex_on {x..y} f" "c \<in> {x..y}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1002
  defines "d \<equiv> y - x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1003
  shows "f c \<le> (f x - f y) / d * (y - c) + f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1004
proof (cases x y rule: linorder_cases)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1005
  case less
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1006
  then have d: "d > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1007
    by (simp add: d_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1008
  from assms(2) less have A: "0 \<le> (y - c) / d" "(y - c) / d \<le> 1"
70817
dd675800469d dedicated fact collections for algebraic simplification rules potentially splitting goals
haftmann
parents: 70136
diff changeset
  1009
    by (simp_all add: d_def field_split_simps)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1010
  have "f c = f (y - (y - c) * 1)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1011
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1012
  also from less have "1 = ((y - x) / d)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1013
    by (simp add: d_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1014
  also from d have "y - (y - c) * \<dots> = (1 - (1 - (y - c) / d)) *\<^sub>R x + (1 - (y - c) / d) *\<^sub>R y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1015
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1016
  also have "f \<dots> \<le> (1 - (1 - (y - c) / d)) * f x + (1 - (y - c) / d) * f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1017
    using assms less by (intro convex_onD_Icc) (simp_all add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1018
  also from d have "\<dots> = (f x - f y) / d * (y - c) + f y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1019
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1020
  finally show ?thesis .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1021
qed (insert assms(2), simp_all)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1022
74729
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1023
subsection \<open>Some inequalities\<close>
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1024
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1025
lemma Youngs_inequality_0:
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1026
  fixes a::real
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1027
  assumes "0 \<le> \<alpha>" "0 \<le> \<beta>" "\<alpha>+\<beta> = 1" "a>0" "b>0"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1028
  shows "a powr \<alpha> * b powr \<beta> \<le> \<alpha>*a + \<beta>*b"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1029
proof -
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1030
  have "\<alpha> * ln a + \<beta> * ln b \<le> ln (\<alpha> * a + \<beta> * b)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1031
    using assms ln_concave by (simp add: concave_on_iff)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1032
  moreover have "0 < \<alpha> * a + \<beta> * b"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1033
    using assms by (smt (verit) mult_pos_pos split_mult_pos_le)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1034
  ultimately show ?thesis
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1035
    using assms by (simp add: powr_def mult_exp_exp flip: ln_ge_iff)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1036
qed
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1037
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1038
lemma Youngs_inequality:
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1039
  fixes p::real
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1040
  assumes "p>1" "q>1" "1/p + 1/q = 1" "a\<ge>0" "b\<ge>0"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1041
  shows "a * b \<le> a powr p / p + b powr q / q"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1042
proof (cases "a=0 \<or> b=0")
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1043
  case False
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1044
  then show ?thesis 
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1045
  using Youngs_inequality_0 [of "1/p" "1/q" "a powr p" "b powr q"] assms
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1046
  by (simp add: powr_powr)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1047
qed (use assms in auto)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1048
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1049
lemma Cauchy_Schwarz_ineq_sum:
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1050
  fixes a :: "'a \<Rightarrow> 'b::linordered_field"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1051
  shows "(\<Sum>i\<in>I. a i * b i)\<^sup>2 \<le> (\<Sum>i\<in>I. (a i)\<^sup>2) * (\<Sum>i\<in>I. (b i)\<^sup>2)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1052
proof (cases "(\<Sum>i\<in>I. (b i)\<^sup>2) > 0")
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1053
  case False
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1054
  then consider "\<And>i. i\<in>I \<Longrightarrow> b i = 0" | "infinite I"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1055
    by (metis (mono_tags, lifting) sum_pos2 zero_le_power2 zero_less_power2)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1056
  thus ?thesis
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1057
    by fastforce
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1058
next
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1059
  case True
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1060
  define r where "r \<equiv> (\<Sum>i\<in>I. a i * b i) / (\<Sum>i\<in>I. (b i)\<^sup>2)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1061
  with True have *: "(\<Sum>i\<in>I. a i * b i) = r * (\<Sum>i\<in>I. (b i)\<^sup>2)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1062
    by simp
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1063
  have "0 \<le> (\<Sum>i\<in>I. (a i - r * b i)\<^sup>2)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1064
    by (meson sum_nonneg zero_le_power2)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1065
  also have "... = (\<Sum>i\<in>I. (a i)\<^sup>2) - 2 * r * (\<Sum>i\<in>I. a i * b i) + r\<^sup>2 * (\<Sum>i\<in>I. (b i)\<^sup>2)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1066
    by (simp add: algebra_simps power2_eq_square sum_distrib_left flip: sum.distrib)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1067
  also have "\<dots> = (\<Sum>i\<in>I. (a i)\<^sup>2) - (\<Sum>i\<in>I. a i * b i) * r"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1068
    by (simp add: * power2_eq_square)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1069
  also have "\<dots> = (\<Sum>i\<in>I. (a i)\<^sup>2) - ((\<Sum>i\<in>I. a i * b i))\<^sup>2 / (\<Sum>i\<in>I. (b i)\<^sup>2)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1070
    by (simp add: r_def power2_eq_square)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1071
  finally have "0 \<le> (\<Sum>i\<in>I. (a i)\<^sup>2) - ((\<Sum>i\<in>I. a i * b i))\<^sup>2 / (\<Sum>i\<in>I. (b i)\<^sup>2)" .
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1072
  hence "((\<Sum>i\<in>I. a i * b i))\<^sup>2 / (\<Sum>i\<in>I. (b i)\<^sup>2) \<le> (\<Sum>i\<in>I. (a i)\<^sup>2)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1073
    by (simp add: le_diff_eq)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1074
  thus "((\<Sum>i\<in>I. a i * b i))\<^sup>2 \<le> (\<Sum>i\<in>I. (a i)\<^sup>2) * (\<Sum>i\<in>I. (b i)\<^sup>2)"
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1075
    by (simp add: pos_divide_le_eq True)
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1076
qed
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1077
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1078
subsection \<open>Misc related lemmas\<close>
64b3d8d9bd10 new lemmas about convex, concave functions, + tidying
paulson <lp15@cam.ac.uk>
parents: 72385
diff changeset
  1079
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1080
lemma convex_translation_eq [simp]:
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1081
  "convex ((+) a ` s) \<longleftrightarrow> convex s"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1082
  by (metis convex_translation translation_galois)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1083
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1084
lemma convex_translation_subtract_eq [simp]:
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1085
  "convex ((\<lambda>b. b - a) ` s) \<longleftrightarrow> convex s"
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1086
  using convex_translation_eq [of "- a"] by (simp cong: image_cong_simp)
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1087
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1088
lemma convex_linear_image_eq [simp]:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1089
    fixes f :: "'a::real_vector \<Rightarrow> 'b::real_vector"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1090
    shows "\<lbrakk>linear f; inj f\<rbrakk> \<Longrightarrow> convex (f ` s) \<longleftrightarrow> convex s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1091
    by (metis (no_types) convex_linear_image convex_linear_vimage inj_vimage_image_eq)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1092
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1093
lemma vector_choose_size:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1094
  assumes "0 \<le> c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1095
  obtains x :: "'a::{real_normed_vector, perfect_space}" where "norm x = c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1096
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1097
  obtain a::'a where "a \<noteq> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1098
    using UNIV_not_singleton UNIV_eq_I set_zero singletonI by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1099
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1100
    by (rule_tac x="scaleR (c / norm a) a" in that) (simp add: assms)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1101
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1102
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1103
lemma vector_choose_dist:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1104
  assumes "0 \<le> c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1105
  obtains y :: "'a::{real_normed_vector, perfect_space}" where "dist x y = c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1106
by (metis add_diff_cancel_left' assms dist_commute dist_norm vector_choose_size)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1107
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1108
lemma sum_delta'':
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1109
  fixes s::"'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1110
  assumes "finite s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1111
  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)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1112
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1113
  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)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1114
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1115
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1116
    unfolding * using sum.delta[OF assms, of y "\<lambda>x. f x *\<^sub>R x"] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1117
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1118
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1119
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1120
subsection \<open>Cones\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1121
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1122
definition\<^marker>\<open>tag important\<close> cone :: "'a::real_vector set \<Rightarrow> bool"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1123
  where "cone s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>c\<ge>0. c *\<^sub>R x \<in> s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1124
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1125
lemma cone_empty[intro, simp]: "cone {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1126
  unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1127
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1128
lemma cone_univ[intro, simp]: "cone UNIV"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1129
  unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1130
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1131
lemma cone_Inter[intro]: "\<forall>s\<in>f. cone s \<Longrightarrow> cone (\<Inter>f)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1132
  unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1133
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1134
lemma subspace_imp_cone: "subspace S \<Longrightarrow> cone S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1135
  by (simp add: cone_def subspace_scale)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1136
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1137
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1138
subsubsection \<open>Conic hull\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1139
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1140
lemma cone_cone_hull: "cone (cone hull S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1141
  unfolding hull_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1142
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1143
lemma cone_hull_eq: "cone hull S = S \<longleftrightarrow> cone S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1144
  by (metis cone_cone_hull hull_same)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1145
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1146
lemma mem_cone:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1147
  assumes "cone S" "x \<in> S" "c \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1148
  shows "c *\<^sub>R x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1149
  using assms cone_def[of S] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1150
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1151
lemma cone_contains_0:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1152
  assumes "cone S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1153
  shows "S \<noteq> {} \<longleftrightarrow> 0 \<in> S"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1154
  using assms mem_cone by fastforce
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1155
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1156
lemma cone_0: "cone {0}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1157
  unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1158
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1159
lemma cone_Union[intro]: "(\<forall>s\<in>f. cone s) \<longrightarrow> cone (\<Union>f)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1160
  unfolding cone_def by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1161
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1162
lemma cone_iff:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1163
  assumes "S \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1164
  shows "cone S \<longleftrightarrow> 0 \<in> S \<and> (\<forall>c. c > 0 \<longrightarrow> ((*\<^sub>R) c) ` S = S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1165
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1166
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1167
    assume "cone S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1168
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1169
      fix c :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1170
      assume "c > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1171
      {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1172
        fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1173
        assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1174
        then have "x \<in> ((*\<^sub>R) c) ` S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1175
          unfolding image_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1176
          using \<open>cone S\<close> \<open>c>0\<close> mem_cone[of S x "1/c"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1177
            exI[of "(\<lambda>t. t \<in> S \<and> x = c *\<^sub>R t)" "(1 / c) *\<^sub>R x"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1178
          by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1179
      }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1180
      moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1181
      {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1182
        fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1183
        assume "x \<in> ((*\<^sub>R) c) ` S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1184
        then have "x \<in> S"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1185
          using \<open>0 < c\<close> \<open>cone S\<close> mem_cone by fastforce
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1186
      }
69768
7e4966eaf781 proper congruence rule for image operator
haftmann
parents: 69675
diff changeset
  1187
      ultimately have "((*\<^sub>R) c) ` S = S" by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1188
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1189
    then have "0 \<in> S \<and> (\<forall>c. c > 0 \<longrightarrow> ((*\<^sub>R) c) ` S = S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1190
      using \<open>cone S\<close> cone_contains_0[of S] assms by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1191
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1192
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1193
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1194
    assume a: "0 \<in> S \<and> (\<forall>c. c > 0 \<longrightarrow> ((*\<^sub>R) c) ` S = S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1195
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1196
      fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1197
      assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1198
      fix c1 :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1199
      assume "c1 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1200
      then have "c1 = 0 \<or> c1 > 0" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1201
      then have "c1 *\<^sub>R x \<in> S" using a \<open>x \<in> S\<close> by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1202
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1203
    then have "cone S" unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1204
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1205
  ultimately show ?thesis by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1206
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1207
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1208
lemma cone_hull_empty: "cone hull {} = {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1209
  by (metis cone_empty cone_hull_eq)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1210
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1211
lemma cone_hull_empty_iff: "S = {} \<longleftrightarrow> cone hull S = {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1212
  by (metis bot_least cone_hull_empty hull_subset xtrans(5))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1213
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1214
lemma cone_hull_contains_0: "S \<noteq> {} \<longleftrightarrow> 0 \<in> cone hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1215
  using cone_cone_hull[of S] cone_contains_0[of "cone hull S"] cone_hull_empty_iff[of S]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1216
  by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1217
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1218
lemma mem_cone_hull:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1219
  assumes "x \<in> S" "c \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1220
  shows "c *\<^sub>R x \<in> cone hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1221
  by (metis assms cone_cone_hull hull_inc mem_cone)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1222
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1223
proposition cone_hull_expl: "cone hull S = {c *\<^sub>R x | c x. c \<ge> 0 \<and> x \<in> S}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1224
  (is "?lhs = ?rhs")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1225
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1226
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1227
    fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1228
    assume "x \<in> ?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1229
    then obtain cx :: real and xx where x: "x = cx *\<^sub>R xx" "cx \<ge> 0" "xx \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1230
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1231
    fix c :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1232
    assume c: "c \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1233
    then have "c *\<^sub>R x = (c * cx) *\<^sub>R xx"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1234
      using x by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1235
    moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1236
    have "c * cx \<ge> 0" using c x by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1237
    ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1238
    have "c *\<^sub>R x \<in> ?rhs" using x by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1239
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1240
  then have "cone ?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1241
    unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1242
  then have "?rhs \<in> Collect cone"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1243
    unfolding mem_Collect_eq by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1244
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1245
    fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1246
    assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1247
    then have "1 *\<^sub>R x \<in> ?rhs"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1248
      using zero_le_one by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1249
    then have "x \<in> ?rhs" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1250
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1251
  then have "S \<subseteq> ?rhs" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1252
  then have "?lhs \<subseteq> ?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1253
    using \<open>?rhs \<in> Collect cone\<close> hull_minimal[of S "?rhs" "cone"] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1254
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1255
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1256
    fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1257
    assume "x \<in> ?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1258
    then obtain cx :: real and xx where x: "x = cx *\<^sub>R xx" "cx \<ge> 0" "xx \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1259
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1260
    then have "xx \<in> cone hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1261
      using hull_subset[of S] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1262
    then have "x \<in> ?lhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1263
      using x cone_cone_hull[of S] cone_def[of "cone hull S"] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1264
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1265
  ultimately show ?thesis by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1266
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1267
71242
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1268
lemma convex_cone:
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1269
  "convex s \<and> cone s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. (x + y) \<in> s) \<and> (\<forall>x\<in>s. \<forall>c\<ge>0. (c *\<^sub>R x) \<in> s)"
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1270
  (is "?lhs = ?rhs")
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1271
proof -
71242
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1272
  {
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1273
    fix x y
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1274
    assume "x\<in>s" "y\<in>s" and ?lhs
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1275
    then have "2 *\<^sub>R x \<in>s" "2 *\<^sub>R y \<in> s"
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1276
      unfolding cone_def by auto
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1277
    then have "x + y \<in> s"
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1278
      using \<open>?lhs\<close>[unfolded convex_def, THEN conjunct1]
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1279
      apply (erule_tac x="2*\<^sub>R x" in ballE)
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1280
      apply (erule_tac x="2*\<^sub>R y" in ballE)
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1281
      apply (erule_tac x="1/2" in allE, simp)
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1282
      apply (erule_tac x="1/2" in allE, auto)
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1283
      done
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1284
  }
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1285
  then show ?thesis
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1286
    unfolding convex_def cone_def by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1287
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1288
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1289
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1290
subsection\<^marker>\<open>tag unimportant\<close> \<open>Connectedness of convex sets\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1291
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1292
lemma convex_connected:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1293
  fixes S :: "'a::real_normed_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1294
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1295
  shows "connected S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1296
proof (rule connectedI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1297
  fix A B
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1298
  assume "open A" "open B" "A \<inter> B \<inter> S = {}" "S \<subseteq> A \<union> B"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1299
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1300
  assume "A \<inter> S \<noteq> {}" "B \<inter> S \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1301
  then obtain a b where a: "a \<in> A" "a \<in> S" and b: "b \<in> B" "b \<in> S" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1302
  define f where [abs_def]: "f u = u *\<^sub>R a + (1 - u) *\<^sub>R b" for u
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1303
  then have "continuous_on {0 .. 1} f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1304
    by (auto intro!: continuous_intros)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1305
  then have "connected (f ` {0 .. 1})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1306
    by (auto intro!: connected_continuous_image)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1307
  note connectedD[OF this, of A B]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1308
  moreover have "a \<in> A \<inter> f ` {0 .. 1}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1309
    using a by (auto intro!: image_eqI[of _ _ 1] simp: f_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1310
  moreover have "b \<in> B \<inter> f ` {0 .. 1}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1311
    using b by (auto intro!: image_eqI[of _ _ 0] simp: f_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1312
  moreover have "f ` {0 .. 1} \<subseteq> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1313
    using \<open>convex S\<close> a b unfolding convex_def f_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1314
  ultimately show False by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1315
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1316
71136
nipkow
parents: 71044
diff changeset
  1317
corollary%unimportant connected_UNIV[intro]: "connected (UNIV :: 'a::real_normed_vector set)"
nipkow
parents: 71044
diff changeset
  1318
by (simp add: convex_connected)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1319
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1320
lemma convex_prod:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1321
  assumes "\<And>i. i \<in> Basis \<Longrightarrow> convex {x. P i x}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1322
  shows "convex {x. \<forall>i\<in>Basis. P i (x\<bullet>i)}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1323
  using assms unfolding convex_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1324
  by (auto simp: inner_add_left)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1325
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1326
lemma convex_positive_orthant: "convex {x::'a::euclidean_space. (\<forall>i\<in>Basis. 0 \<le> x\<bullet>i)}"
71136
nipkow
parents: 71044
diff changeset
  1327
by (rule convex_prod) (simp flip: atLeast_def)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1328
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1329
subsection \<open>Convex hull\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1330
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1331
lemma convex_convex_hull [iff]: "convex (convex hull s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1332
  unfolding hull_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1333
  using convex_Inter[of "{t. convex t \<and> s \<subseteq> t}"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1334
  by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1335
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1336
lemma convex_hull_subset:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1337
    "s \<subseteq> convex hull t \<Longrightarrow> convex hull s \<subseteq> convex hull t"
71174
nipkow
parents: 71136
diff changeset
  1338
  by (simp add: subset_hull)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1339
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1340
lemma convex_hull_eq: "convex hull s = s \<longleftrightarrow> convex s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1341
  by (metis convex_convex_hull hull_same)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1342
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1343
subsubsection\<^marker>\<open>tag unimportant\<close> \<open>Convex hull is "preserved" by a linear function\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1344
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1345
lemma convex_hull_linear_image:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1346
  assumes f: "linear f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1347
  shows "f ` (convex hull s) = convex hull (f ` s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1348
proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1349
  show "convex hull (f ` s) \<subseteq> f ` (convex hull s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1350
    by (intro hull_minimal image_mono hull_subset convex_linear_image assms convex_convex_hull)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1351
  show "f ` (convex hull s) \<subseteq> convex hull (f ` s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1352
  proof (unfold image_subset_iff_subset_vimage, rule hull_minimal)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1353
    show "s \<subseteq> f -` (convex hull (f ` s))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1354
      by (fast intro: hull_inc)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1355
    show "convex (f -` (convex hull (f ` s)))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1356
      by (intro convex_linear_vimage [OF f] convex_convex_hull)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1357
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1358
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1359
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1360
lemma in_convex_hull_linear_image:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1361
  assumes "linear f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1362
    and "x \<in> convex hull s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1363
  shows "f x \<in> convex hull (f ` s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1364
  using convex_hull_linear_image[OF assms(1)] assms(2) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1365
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1366
lemma convex_hull_Times:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1367
  "convex hull (s \<times> t) = (convex hull s) \<times> (convex hull t)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1368
proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1369
  show "convex hull (s \<times> t) \<subseteq> (convex hull s) \<times> (convex hull t)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1370
    by (intro hull_minimal Sigma_mono hull_subset convex_Times convex_convex_hull)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1371
  have "(x, y) \<in> convex hull (s \<times> t)" if x: "x \<in> convex hull s" and y: "y \<in> convex hull t" for x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1372
  proof (rule hull_induct [OF x], rule hull_induct [OF y])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1373
    fix x y assume "x \<in> s" and "y \<in> t"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1374
    then show "(x, y) \<in> convex hull (s \<times> t)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1375
      by (simp add: hull_inc)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1376
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1377
    fix x let ?S = "((\<lambda>y. (0, y)) -` (\<lambda>p. (- x, 0) + p) ` (convex hull s \<times> t))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1378
    have "convex ?S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1379
      by (intro convex_linear_vimage convex_translation convex_convex_hull,
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1380
        simp add: linear_iff)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1381
    also have "?S = {y. (x, y) \<in> convex hull (s \<times> t)}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1382
      by (auto simp: image_def Bex_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1383
    finally show "convex {y. (x, y) \<in> convex hull (s \<times> t)}" .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1384
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1385
    show "convex {x. (x, y) \<in> convex hull s \<times> t}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1386
    proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1387
      fix y let ?S = "((\<lambda>x. (x, 0)) -` (\<lambda>p. (0, - y) + p) ` (convex hull s \<times> t))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1388
      have "convex ?S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1389
      by (intro convex_linear_vimage convex_translation convex_convex_hull,
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1390
        simp add: linear_iff)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1391
      also have "?S = {x. (x, y) \<in> convex hull (s \<times> t)}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1392
        by (auto simp: image_def Bex_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1393
      finally show "convex {x. (x, y) \<in> convex hull (s \<times> t)}" .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1394
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1395
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1396
  then show "(convex hull s) \<times> (convex hull t) \<subseteq> convex hull (s \<times> t)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1397
    unfolding subset_eq split_paired_Ball_Sigma by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1398
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1399
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1400
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1401
subsubsection\<^marker>\<open>tag unimportant\<close> \<open>Stepping theorems for convex hulls of finite sets\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1402
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1403
lemma convex_hull_empty[simp]: "convex hull {} = {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1404
  by (rule hull_unique) auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1405
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1406
lemma convex_hull_singleton[simp]: "convex hull {a} = {a}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1407
  by (rule hull_unique) auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1408
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1409
lemma convex_hull_insert:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1410
  fixes S :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1411
  assumes "S \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1412
  shows "convex hull (insert a S) =
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1413
         {x. \<exists>u\<ge>0. \<exists>v\<ge>0. \<exists>b. (u + v = 1) \<and> b \<in> (convex hull S) \<and> (x = u *\<^sub>R a + v *\<^sub>R b)}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1414
  (is "_ = ?hull")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1415
proof (intro equalityI hull_minimal subsetI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1416
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1417
  assume "x \<in> insert a S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1418
  then have "\<exists>u\<ge>0. \<exists>v\<ge>0. u + v = 1 \<and> (\<exists>b. b \<in> convex hull S \<and> x = u *\<^sub>R a + v *\<^sub>R b)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1419
  unfolding insert_iff
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1420
  proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1421
    assume "x = a"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1422
    then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1423
      by (rule_tac x=1 in exI) (use assms hull_subset in fastforce)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1424
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1425
    assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1426
    with hull_subset[of S convex] show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1427
      by force
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1428
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1429
  then show "x \<in> ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1430
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1431
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1432
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1433
  assume "x \<in> ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1434
  then obtain u v b where obt: "u\<ge>0" "v\<ge>0" "u + v = 1" "b \<in> convex hull S" "x = u *\<^sub>R a + v *\<^sub>R b"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1435
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1436
  have "a \<in> convex hull insert a S" "b \<in> convex hull insert a S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1437
    using hull_mono[of S "insert a S" convex] hull_mono[of "{a}" "insert a S" convex] and obt(4)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1438
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1439
  then show "x \<in> convex hull insert a S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1440
    unfolding obt(5) using obt(1-3)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1441
    by (rule convexD [OF convex_convex_hull])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1442
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1443
  show "convex ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1444
  proof (rule convexI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1445
    fix x y u v
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1446
    assume as: "(0::real) \<le> u" "0 \<le> v" "u + v = 1" and x: "x \<in> ?hull" and y: "y \<in> ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1447
    from x obtain u1 v1 b1 where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1448
      obt1: "u1\<ge>0" "v1\<ge>0" "u1 + v1 = 1" "b1 \<in> convex hull S" and xeq: "x = u1 *\<^sub>R a + v1 *\<^sub>R b1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1449
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1450
    from y obtain u2 v2 b2 where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1451
      obt2: "u2\<ge>0" "v2\<ge>0" "u2 + v2 = 1" "b2 \<in> convex hull S" and yeq: "y = u2 *\<^sub>R a + v2 *\<^sub>R b2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1452
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1453
    have *: "\<And>(x::'a) s1 s2. x - s1 *\<^sub>R x - s2 *\<^sub>R x = ((1::real) - (s1 + s2)) *\<^sub>R x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1454
      by (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1455
    have "\<exists>b \<in> convex hull S. u *\<^sub>R x + v *\<^sub>R y =
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1456
      (u * u1) *\<^sub>R a + (v * u2) *\<^sub>R a + (b - (u * u1) *\<^sub>R b - (v * u2) *\<^sub>R b)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1457
    proof (cases "u * v1 + v * v2 = 0")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1458
      case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1459
      have *: "\<And>(x::'a) s1 s2. x - s1 *\<^sub>R x - s2 *\<^sub>R x = ((1::real) - (s1 + s2)) *\<^sub>R x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1460
        by (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1461
      have eq0: "u * v1 = 0" "v * v2 = 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1462
        using True mult_nonneg_nonneg[OF \<open>u\<ge>0\<close> \<open>v1\<ge>0\<close>] mult_nonneg_nonneg[OF \<open>v\<ge>0\<close> \<open>v2\<ge>0\<close>]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1463
        by arith+
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1464
      then have "u * u1 + v * u2 = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1465
        using as(3) obt1(3) obt2(3) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1466
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1467
        using "*" eq0 as obt1(4) xeq yeq by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1468
    next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1469
      case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1470
      have "1 - (u * u1 + v * u2) = (u + v) - (u * u1 + v * u2)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1471
        using as(3) obt1(3) obt2(3) by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1472
      also have "\<dots> = u * (v1 + u1 - u1) + v * (v2 + u2 - u2)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1473
        using as(3) obt1(3) obt2(3) by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1474
      also have "\<dots> = u * v1 + v * v2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1475
        by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1476
      finally have **:"1 - (u * u1 + v * u2) = u * v1 + v * v2" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1477
      let ?b = "((u * v1) / (u * v1 + v * v2)) *\<^sub>R b1 + ((v * v2) / (u * v1 + v * v2)) *\<^sub>R b2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1478
      have zeroes: "0 \<le> u * v1 + v * v2" "0 \<le> u * v1" "0 \<le> u * v1 + v * v2" "0 \<le> v * v2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1479
        using as(1,2) obt1(1,2) obt2(1,2) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1480
      show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1481
      proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1482
        show "u *\<^sub>R x + v *\<^sub>R y = (u * u1) *\<^sub>R a + (v * u2) *\<^sub>R a + (?b - (u * u1) *\<^sub>R ?b - (v * u2) *\<^sub>R ?b)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1483
          unfolding xeq yeq * **
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1484
          using False by (auto simp: scaleR_left_distrib scaleR_right_distrib)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1485
        show "?b \<in> convex hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1486
          using False zeroes obt1(4) obt2(4)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1487
          by (auto simp: convexD [OF convex_convex_hull] scaleR_left_distrib scaleR_right_distrib  add_divide_distrib[symmetric]  zero_le_divide_iff)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1488
      qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1489
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1490
    then obtain b where b: "b \<in> convex hull S" 
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1491
       "u *\<^sub>R x + v *\<^sub>R y = (u * u1) *\<^sub>R a + (v * u2) *\<^sub>R a + (b - (u * u1) *\<^sub>R b - (v * u2) *\<^sub>R b)" ..
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1492
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1493
    have u1: "u1 \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1494
      unfolding obt1(3)[symmetric] and not_le using obt1(2) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1495
    have u2: "u2 \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1496
      unfolding obt2(3)[symmetric] and not_le using obt2(2) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1497
    have "u1 * u + u2 * v \<le> max u1 u2 * u + max u1 u2 * v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1498
    proof (rule add_mono)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1499
      show "u1 * u \<le> max u1 u2 * u" "u2 * v \<le> max u1 u2 * v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1500
        by (simp_all add: as mult_right_mono)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1501
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1502
    also have "\<dots> \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1503
      unfolding distrib_left[symmetric] and as(3) using u1 u2 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1504
    finally have le1: "u1 * u + u2 * v \<le> 1" .    
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1505
    show "u *\<^sub>R x + v *\<^sub>R y \<in> ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1506
    proof (intro CollectI exI conjI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1507
      show "0 \<le> u * u1 + v * u2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1508
        by (simp add: as(1) as(2) obt1(1) obt2(1))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1509
      show "0 \<le> 1 - u * u1 - v * u2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1510
        by (simp add: le1 diff_diff_add mult.commute)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1511
    qed (use b in \<open>auto simp: algebra_simps\<close>)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1512
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1513
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1514
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1515
lemma convex_hull_insert_alt:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1516
   "convex hull (insert a S) =
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1517
     (if S = {} then {a}
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1518
      else {(1 - u) *\<^sub>R a + u *\<^sub>R x |x u. 0 \<le> u \<and> u \<le> 1 \<and> x \<in> convex hull S})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1519
  apply (auto simp: convex_hull_insert)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1520
  using diff_eq_eq apply fastforce
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1521
  using diff_add_cancel diff_ge_0_iff_ge by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1522
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1523
subsubsection\<^marker>\<open>tag unimportant\<close> \<open>Explicit expression for convex hull\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1524
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1525
proposition convex_hull_indexed:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1526
  fixes S :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1527
  shows "convex hull S =
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1528
    {y. \<exists>k u x. (\<forall>i\<in>{1::nat .. k}. 0 \<le> u i \<and> x i \<in> S) \<and>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1529
                (sum u {1..k} = 1) \<and> (\<Sum>i = 1..k. u i *\<^sub>R x i) = y}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1530
    (is "?xyz = ?hull")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1531
proof (rule hull_unique [OF _ convexI])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1532
  show "S \<subseteq> ?hull" 
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1533
    by (clarsimp, rule_tac x=1 in exI, rule_tac x="\<lambda>x. 1" in exI, auto)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1534
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1535
  fix T
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1536
  assume "S \<subseteq> T" "convex T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1537
  then show "?hull \<subseteq> T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1538
    by (blast intro: convex_sum)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1539
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1540
  fix x y u v
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1541
  assume uv: "0 \<le> u" "0 \<le> v" "u + v = (1::real)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1542
  assume xy: "x \<in> ?hull" "y \<in> ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1543
  from xy obtain k1 u1 x1 where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1544
    x [rule_format]: "\<forall>i\<in>{1::nat..k1}. 0\<le>u1 i \<and> x1 i \<in> S" 
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1545
                      "sum u1 {Suc 0..k1} = 1" "(\<Sum>i = Suc 0..k1. u1 i *\<^sub>R x1 i) = x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1546
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1547
  from xy obtain k2 u2 x2 where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1548
    y [rule_format]: "\<forall>i\<in>{1::nat..k2}. 0\<le>u2 i \<and> x2 i \<in> S" 
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1549
                     "sum u2 {Suc 0..k2} = 1" "(\<Sum>i = Suc 0..k2. u2 i *\<^sub>R x2 i) = y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1550
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1551
  have *: "\<And>P (x::'a) y s t i. (if P i then s else t) *\<^sub>R (if P i then x else y) = (if P i then s *\<^sub>R x else t *\<^sub>R y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1552
          "{1..k1 + k2} \<inter> {1..k1} = {1..k1}" "{1..k1 + k2} \<inter> - {1..k1} = (\<lambda>i. i + k1) ` {1..k2}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1553
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1554
  have inj: "inj_on (\<lambda>i. i + k1) {1..k2}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1555
    unfolding inj_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1556
  let ?uu = "\<lambda>i. if i \<in> {1..k1} then u * u1 i else v * u2 (i - k1)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1557
  let ?xx = "\<lambda>i. if i \<in> {1..k1} then x1 i else x2 (i - k1)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1558
  show "u *\<^sub>R x + v *\<^sub>R y \<in> ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1559
  proof (intro CollectI exI conjI ballI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1560
    show "0 \<le> ?uu i" "?xx i \<in> S" if "i \<in> {1..k1+k2}" for i
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1561
      using that by (auto simp add: le_diff_conv uv(1) x(1) uv(2) y(1))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1562
    show "(\<Sum>i = 1..k1 + k2. ?uu i) = 1"  "(\<Sum>i = 1..k1 + k2. ?uu i *\<^sub>R ?xx i) = u *\<^sub>R x + v *\<^sub>R y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1563
      unfolding * sum.If_cases[OF finite_atLeastAtMost[of 1 "k1 + k2"]]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1564
        sum.reindex[OF inj] Collect_mem_eq o_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1565
      unfolding scaleR_scaleR[symmetric] scaleR_right.sum [symmetric] sum_distrib_left[symmetric]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1566
      by (simp_all add: sum_distrib_left[symmetric]  x(2,3) y(2,3) uv(3))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1567
  qed 
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1568
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1569
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1570
lemma convex_hull_finite:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1571
  fixes S :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1572
  assumes "finite S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1573
  shows "convex hull S = {y. \<exists>u. (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<and> sum (\<lambda>x. u x *\<^sub>R x) S = y}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1574
  (is "?HULL = _")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1575
proof (rule hull_unique [OF _ convexI]; clarify)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1576
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1577
  assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1578
  then show "\<exists>u. (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<and> (\<Sum>x\<in>S. u x *\<^sub>R x) = x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1579
    by (rule_tac x="\<lambda>y. if x=y then 1 else 0" in exI) (auto simp: sum.delta'[OF assms] sum_delta''[OF assms])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1580
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1581
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1582
  assume uv: "0 \<le> u" "0 \<le> v" "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1583
  fix ux assume ux [rule_format]: "\<forall>x\<in>S. 0 \<le> ux x" "sum ux S = (1::real)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1584
  fix uy assume uy [rule_format]: "\<forall>x\<in>S. 0 \<le> uy x" "sum uy S = (1::real)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1585
  have "0 \<le> u * ux x + v * uy x" if "x\<in>S" for x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1586
    by (simp add: that uv ux(1) uy(1))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1587
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1588
  have "(\<Sum>x\<in>S. u * ux x + v * uy x) = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1589
    unfolding sum.distrib and sum_distrib_left[symmetric] ux(2) uy(2)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1590
    using uv(3) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1591
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1592
  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)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1593
    unfolding scaleR_left_distrib sum.distrib scaleR_scaleR[symmetric] scaleR_right.sum [symmetric]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1594
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1595
  ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1596
  show "\<exists>uc. (\<forall>x\<in>S. 0 \<le> uc x) \<and> sum uc S = 1 \<and>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1597
             (\<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)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1598
    by (rule_tac x="\<lambda>x. u * ux x + v * uy x" in exI, auto)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1599
qed (use assms in \<open>auto simp: convex_explicit\<close>)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1600
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1601
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1602
subsubsection\<^marker>\<open>tag unimportant\<close> \<open>Another formulation\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1603
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1604
text "Formalized by Lars Schewe."
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1605
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1606
lemma convex_hull_explicit:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1607
  fixes p :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1608
  shows "convex hull p =
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1609
    {y. \<exists>S u. finite S \<and> S \<subseteq> p \<and> (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<and> sum (\<lambda>v. u v *\<^sub>R v) S = y}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1610
  (is "?lhs = ?rhs")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1611
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1612
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1613
    fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1614
    assume "x\<in>?lhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1615
    then obtain k u y where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1616
        obt: "\<forall>i\<in>{1::nat..k}. 0 \<le> u i \<and> y i \<in> p" "sum u {1..k} = 1" "(\<Sum>i = 1..k. u i *\<^sub>R y i) = x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1617
      unfolding convex_hull_indexed by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1618
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1619
    have fin: "finite {1..k}" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1620
    have fin': "\<And>v. finite {i \<in> {1..k}. y i = v}" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1621
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1622
      fix j
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1623
      assume "j\<in>{1..k}"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1624
      then have "y j \<in> p \<and> 0 \<le> sum u {i. Suc 0 \<le> i \<and> i \<le> k \<and> y i = y j}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1625
        using obt(1)[THEN bspec[where x=j]] and obt(2)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1626
        by (metis (no_types, lifting) One_nat_def atLeastAtMost_iff mem_Collect_eq obt(1) sum_nonneg)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1627
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1628
    moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1629
    have "(\<Sum>v\<in>y ` {1..k}. sum u {i \<in> {1..k}. y i = v}) = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1630
      unfolding sum.image_gen[OF fin, symmetric] using obt(2) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1631
    moreover have "(\<Sum>v\<in>y ` {1..k}. sum u {i \<in> {1..k}. y i = v} *\<^sub>R v) = x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1632
      using sum.image_gen[OF fin, of "\<lambda>i. u i *\<^sub>R y i" y, symmetric]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1633
      unfolding scaleR_left.sum using obt(3) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1634
    ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1635
    have "\<exists>S u. finite S \<and> S \<subseteq> p \<and> (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<and> (\<Sum>v\<in>S. u v *\<^sub>R v) = x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1636
      apply (rule_tac x="y ` {1..k}" in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1637
      apply (rule_tac x="\<lambda>v. sum u {i\<in>{1..k}. y i = v}" in exI, auto)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1638
      done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1639
    then have "x\<in>?rhs" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1640
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1641
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1642
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1643
    fix y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1644
    assume "y\<in>?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1645
    then obtain S u where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1646
      obt: "finite S" "S \<subseteq> p" "\<forall>x\<in>S. 0 \<le> u x" "sum u S = 1" "(\<Sum>v\<in>S. u v *\<^sub>R v) = y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1647
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1648
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1649
    obtain f where f: "inj_on f {1..card S}" "f ` {1..card S} = S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1650
      using ex_bij_betw_nat_finite_1[OF obt(1)] unfolding bij_betw_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1651
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1652
      fix i :: nat
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1653
      assume "i\<in>{1..card S}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1654
      then have "f i \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1655
        using f(2) by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1656
      then have "0 \<le> u (f i)" "f i \<in> p" using obt(2,3) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1657
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1658
    moreover have *: "finite {1..card S}" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1659
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1660
      fix y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1661
      assume "y\<in>S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1662
      then obtain i where "i\<in>{1..card S}" "f i = y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1663
        using f using image_iff[of y f "{1..card S}"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1664
        by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1665
      then have "{x. Suc 0 \<le> x \<and> x \<le> card S \<and> f x = y} = {i}"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1666
        using f(1) inj_onD by fastforce
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1667
      then have "card {x. Suc 0 \<le> x \<and> x \<le> card S \<and> f x = y} = 1" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1668
      then have "(\<Sum>x\<in>{x \<in> {1..card S}. f x = y}. u (f x)) = u y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1669
          "(\<Sum>x\<in>{x \<in> {1..card S}. f x = y}. u (f x) *\<^sub>R f x) = u y *\<^sub>R y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1670
        by (auto simp: sum_constant_scaleR)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1671
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1672
    then have "(\<Sum>x = 1..card S. u (f x)) = 1" "(\<Sum>i = 1..card S. u (f i) *\<^sub>R f i) = y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1673
      unfolding sum.image_gen[OF *(1), of "\<lambda>x. u (f x) *\<^sub>R f x" f]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1674
        and sum.image_gen[OF *(1), of "\<lambda>x. u (f x)" f]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1675
      unfolding f
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1676
      using sum.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"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1677
      using sum.cong [of S S "\<lambda>y. (\<Sum>x\<in>{x \<in> {1..card S}. f x = y}. u (f x))" u]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1678
      unfolding obt(4,5)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1679
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1680
    ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1681
    have "\<exists>k u x. (\<forall>i\<in>{1..k}. 0 \<le> u i \<and> x i \<in> p) \<and> sum u {1..k} = 1 \<and>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1682
        (\<Sum>i::nat = 1..k. u i *\<^sub>R x i) = y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1683
      apply (rule_tac x="card S" in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1684
      apply (rule_tac x="u \<circ> f" in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1685
      apply (rule_tac x=f in exI, fastforce)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1686
      done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1687
    then have "y \<in> ?lhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1688
      unfolding convex_hull_indexed by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1689
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1690
  ultimately show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1691
    unfolding set_eq_iff by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1692
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1693
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1694
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1695
subsubsection\<^marker>\<open>tag unimportant\<close> \<open>A stepping theorem for that expansion\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1696
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1697
lemma convex_hull_finite_step:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1698
  fixes S :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1699
  assumes "finite S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1700
  shows
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1701
    "(\<exists>u. (\<forall>x\<in>insert a S. 0 \<le> u x) \<and> sum u (insert a S) = w \<and> sum (\<lambda>x. u x *\<^sub>R x) (insert a S) = y)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1702
      \<longleftrightarrow> (\<exists>v\<ge>0. \<exists>u. (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = w - v \<and> sum (\<lambda>x. u x *\<^sub>R x) S = y - v *\<^sub>R a)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1703
  (is "?lhs = ?rhs")
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1704
proof (cases "a \<in> S")
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1705
  case True
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1706
  then have *: "insert a S = S" by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1707
  show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1708
  proof
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1709
    assume ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1710
    then show ?rhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1711
      unfolding * by force
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1712
  next
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1713
    have fin: "finite (insert a S)" using assms by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1714
    assume ?rhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1715
    then obtain v u where uv: "v\<ge>0" "\<forall>x\<in>S. 0 \<le> u x" "sum u S = w - v" "(\<Sum>x\<in>S. u x *\<^sub>R x) = y - v *\<^sub>R a"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1716
      by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1717
    then show ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1718
      using uv True assms
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1719
      apply (rule_tac x = "\<lambda>x. (if a = x then v else 0) + u x" in exI)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1720
      apply (auto simp: sum_clauses scaleR_left_distrib sum.distrib sum_delta''[OF fin])
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1721
      done
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1722
  qed
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1723
next
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1724
  case False
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1725
  show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1726
  proof
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1727
    assume ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1728
    then obtain u where u: "\<forall>x\<in>insert a S. 0 \<le> u x" "sum u (insert a S) = w" "(\<Sum>x\<in>insert a S. u x *\<^sub>R x) = y"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1729
      by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1730
    then show ?rhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1731
      using u \<open>a\<notin>S\<close> by (rule_tac x="u a" in exI) (auto simp: sum_clauses assms)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1732
  next
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1733
    assume ?rhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1734
    then obtain v u where uv: "v\<ge>0" "\<forall>x\<in>S. 0 \<le> u x" "sum u S = w - v" "(\<Sum>x\<in>S. u x *\<^sub>R x) = y - v *\<^sub>R a"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1735
      by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1736
    moreover
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1737
    have "(\<Sum>x\<in>S. if a = x then v else u x) = sum u S"  "(\<Sum>x\<in>S. (if a = x then v else u x) *\<^sub>R x) = (\<Sum>x\<in>S. u x *\<^sub>R x)"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1738
      using False by (auto intro!: sum.cong)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1739
    ultimately show ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1740
      using False by (rule_tac x="\<lambda>x. if a = x then v else u x" in exI) (auto simp: sum_clauses(2)[OF assms])
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1741
  qed
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1742
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1743
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1744
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1745
subsubsection\<^marker>\<open>tag unimportant\<close> \<open>Hence some special cases\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1746
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1747
lemma convex_hull_2: "convex hull {a,b} = {u *\<^sub>R a + v *\<^sub>R b | u v. 0 \<le> u \<and> 0 \<le> v \<and> u + v = 1}"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1748
       (is "?lhs = ?rhs")
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1749
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1750
  have **: "finite {b}" by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1751
  have "\<And>x v u. \<lbrakk>0 \<le> v; v \<le> 1; (1 - v) *\<^sub>R b = x - v *\<^sub>R a\<rbrakk>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1752
                \<Longrightarrow> \<exists>u v. x = u *\<^sub>R a + v *\<^sub>R b \<and> 0 \<le> u \<and> 0 \<le> v \<and> u + v = 1"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1753
    by (metis add.commute diff_add_cancel diff_ge_0_iff_ge)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1754
  moreover
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1755
  have "\<And>u v. \<lbrakk>0 \<le> u; 0 \<le> v; u + v = 1\<rbrakk>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1756
               \<Longrightarrow> \<exists>p\<ge>0. \<exists>q. 0 \<le> q b \<and> q b = 1 - p \<and> q b *\<^sub>R b = u *\<^sub>R a + v *\<^sub>R b - p *\<^sub>R a"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1757
    apply (rule_tac x=u in exI, simp)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1758
    apply (rule_tac x="\<lambda>x. v" in exI, simp)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1759
    done
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1760
  ultimately show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1761
    using convex_hull_finite_step[OF **, of a 1]
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1762
    by (auto simp add: convex_hull_finite)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1763
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1764
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1765
lemma convex_hull_2_alt: "convex hull {a,b} = {a + u *\<^sub>R (b - a) | u.  0 \<le> u \<and> u \<le> 1}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1766
  unfolding convex_hull_2
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1767
proof (rule Collect_cong)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1768
  have *: "\<And>x y ::real. x + y = 1 \<longleftrightarrow> x = 1 - y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1769
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1770
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1771
  show "(\<exists>v u. x = v *\<^sub>R a + u *\<^sub>R b \<and> 0 \<le> v \<and> 0 \<le> u \<and> v + u = 1) \<longleftrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1772
    (\<exists>u. x = a + u *\<^sub>R (b - a) \<and> 0 \<le> u \<and> u \<le> 1)"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1773
    apply (simp add: *)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1774
    by (rule ex_cong1) (auto simp: algebra_simps)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1775
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1776
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1777
lemma convex_hull_3:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1778
  "convex hull {a,b,c} = { u *\<^sub>R a + v *\<^sub>R b + w *\<^sub>R c | u v w. 0 \<le> u \<and> 0 \<le> v \<and> 0 \<le> w \<and> u + v + w = 1}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1779
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1780
  have fin: "finite {a,b,c}" "finite {b,c}" "finite {c}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1781
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1782
  have *: "\<And>x y z ::real. x + y + z = 1 \<longleftrightarrow> x = 1 - y - z"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1783
    by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1784
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1785
    unfolding convex_hull_finite[OF fin(1)] and convex_hull_finite_step[OF fin(2)] and *
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1786
    unfolding convex_hull_finite_step[OF fin(3)]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1787
    apply (rule Collect_cong, simp)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1788
    apply auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1789
    apply (rule_tac x=va in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1790
    apply (rule_tac x="u c" in exI, simp)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1791
    apply (rule_tac x="1 - v - w" in exI, simp)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1792
    apply (rule_tac x=v in exI, simp)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1793
    apply (rule_tac x="\<lambda>x. w" in exI, simp)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1794
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1795
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1796
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1797
lemma convex_hull_3_alt:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1798
  "convex hull {a,b,c} = {a + u *\<^sub>R (b - a) + v *\<^sub>R (c - a) | u v.  0 \<le> u \<and> 0 \<le> v \<and> u + v \<le> 1}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1799
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1800
  have *: "\<And>x y z ::real. x + y + z = 1 \<longleftrightarrow> x = 1 - y - z"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1801
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1802
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1803
    unfolding convex_hull_3
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1804
    apply (auto simp: *)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1805
    apply (rule_tac x=v in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1806
    apply (rule_tac x=w in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1807
    apply (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1808
    apply (rule_tac x=u in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1809
    apply (rule_tac x=v in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1810
    apply (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1811
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1812
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1813
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1814
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1815
subsection\<^marker>\<open>tag unimportant\<close> \<open>Relations among closure notions and corresponding hulls\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1816
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1817
lemma affine_imp_convex: "affine s \<Longrightarrow> convex s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1818
  unfolding affine_def convex_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1819
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1820
lemma convex_affine_hull [simp]: "convex (affine hull S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1821
  by (simp add: affine_imp_convex)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1822
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1823
lemma subspace_imp_convex: "subspace s \<Longrightarrow> convex s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1824
  using subspace_imp_affine affine_imp_convex by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1825
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1826
lemma convex_hull_subset_span: "(convex hull s) \<subseteq> (span s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1827
  by (metis hull_minimal span_superset subspace_imp_convex subspace_span)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1828
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1829
lemma convex_hull_subset_affine_hull: "(convex hull s) \<subseteq> (affine hull s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1830
  by (metis affine_affine_hull affine_imp_convex hull_minimal hull_subset)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1831
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1832
lemma aff_dim_convex_hull:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1833
  fixes S :: "'n::euclidean_space set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1834
  shows "aff_dim (convex hull S) = aff_dim S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1835
  using aff_dim_affine_hull[of S] convex_hull_subset_affine_hull[of S]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1836
    hull_subset[of S "convex"] aff_dim_subset[of S "convex hull S"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1837
    aff_dim_subset[of "convex hull S" "affine hull S"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1838
  by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1839
71242
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1840
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1841
subsection \<open>Caratheodory's theorem\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1842
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1843
lemma convex_hull_caratheodory_aff_dim:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1844
  fixes p :: "('a::euclidean_space) set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1845
  shows "convex hull p =
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1846
    {y. \<exists>S u. finite S \<and> S \<subseteq> p \<and> card S \<le> aff_dim p + 1 \<and>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1847
        (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<and> sum (\<lambda>v. u v *\<^sub>R v) S = y}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1848
  unfolding convex_hull_explicit set_eq_iff mem_Collect_eq
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1849
proof (intro allI iffI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1850
  fix y
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1851
  let ?P = "\<lambda>n. \<exists>S u. finite S \<and> card S = n \<and> S \<subseteq> p \<and> (\<forall>x\<in>S. 0 \<le> u x) \<and>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1852
    sum u S = 1 \<and> (\<Sum>v\<in>S. u v *\<^sub>R v) = y"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1853
  assume "\<exists>S u. finite S \<and> S \<subseteq> p \<and> (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<and> (\<Sum>v\<in>S. u v *\<^sub>R v) = y"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1854
  then obtain N where "?P N" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1855
  then have "\<exists>n\<le>N. (\<forall>k<n. \<not> ?P k) \<and> ?P n"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1856
    by (rule_tac ex_least_nat_le, auto)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1857
  then obtain n where "?P n" and smallest: "\<forall>k<n. \<not> ?P k"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1858
    by blast
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1859
  then obtain S u where obt: "finite S" "card S = n" "S\<subseteq>p" "\<forall>x\<in>S. 0 \<le> u x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1860
    "sum u S = 1"  "(\<Sum>v\<in>S. u v *\<^sub>R v) = y" by auto
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1861
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1862
  have "card S \<le> aff_dim p + 1"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1863
  proof (rule ccontr, simp only: not_le)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1864
    assume "aff_dim p + 1 < card S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1865
    then have "affine_dependent S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1866
      using affine_dependent_biggerset[OF obt(1)] independent_card_le_aff_dim not_less obt(3)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1867
      by blast
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1868
    then obtain w v where wv: "sum w S = 0" "v\<in>S" "w v \<noteq> 0" "(\<Sum>v\<in>S. w v *\<^sub>R v) = 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1869
      using affine_dependent_explicit_finite[OF obt(1)] by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1870
    define i where "i = (\<lambda>v. (u v) / (- w v)) ` {v\<in>S. w v < 0}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1871
    define t where "t = Min i"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1872
    have "\<exists>x\<in>S. w x < 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1873
    proof (rule ccontr, simp add: not_less)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1874
      assume as:"\<forall>x\<in>S. 0 \<le> w x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1875
      then have "sum w (S - {v}) \<ge> 0"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1876
        by (meson Diff_iff sum_nonneg)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1877
      then have "sum w S > 0"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1878
        using as obt(1) sum_nonneg_eq_0_iff wv by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1879
      then show False using wv(1) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1880
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1881
    then have "i \<noteq> {}" unfolding i_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1882
    then have "t \<ge> 0"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1883
      using Min_ge_iff[of i 0] and obt(1)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1884
      unfolding t_def i_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1885
      using obt(4)[unfolded le_less]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1886
      by (auto simp: divide_le_0_iff)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1887
    have t: "\<forall>v\<in>S. u v + t * w v \<ge> 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1888
    proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1889
      fix v
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1890
      assume "v \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1891
      then have v: "0 \<le> u v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1892
        using obt(4)[THEN bspec[where x=v]] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1893
      show "0 \<le> u v + t * w v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1894
      proof (cases "w v < 0")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1895
        case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1896
        thus ?thesis using v \<open>t\<ge>0\<close> by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1897
      next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1898
        case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1899
        then have "t \<le> u v / (- w v)"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1900
          using \<open>v\<in>S\<close> obt unfolding t_def i_def by (auto intro: Min_le)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1901
        then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1902
          unfolding real_0_le_add_iff
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1903
          using True neg_le_minus_divide_eq by auto
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1904
      qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1905
    qed
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1906
    obtain a where "a \<in> S" and "t = (\<lambda>v. (u v) / (- w v)) a" and "w a < 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1907
      using Min_in[OF _ \<open>i\<noteq>{}\<close>] and obt(1) unfolding i_def t_def by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1908
    then have a: "a \<in> S" "u a + t * w a = 0" by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1909
    have *: "\<And>f. sum f (S - {a}) = sum f S - ((f a)::'b::ab_group_add)"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1910
      unfolding sum.remove[OF obt(1) \<open>a\<in>S\<close>] by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1911
    have "(\<Sum>v\<in>S. u v + t * w v) = 1"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1912
      unfolding sum.distrib wv(1) sum_distrib_left[symmetric] obt(5) by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1913
    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"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1914
      unfolding sum.distrib obt(6) scaleR_scaleR[symmetric] scaleR_right.sum [symmetric] wv(4)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1915
      using a(2) [THEN eq_neg_iff_add_eq_0 [THEN iffD2]] by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1916
    ultimately have "?P (n - 1)"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1917
      apply (rule_tac x="(S - {a})" in exI)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1918
      apply (rule_tac x="\<lambda>v. u v + t * w v" in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1919
      using obt(1-3) and t and a
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1920
      apply (auto simp: * scaleR_left_distrib)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1921
      done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1922
    then show False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1923
      using smallest[THEN spec[where x="n - 1"]] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1924
  qed
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1925
  then show "\<exists>S u. finite S \<and> S \<subseteq> p \<and> card S \<le> aff_dim p + 1 \<and>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1926
      (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<and> (\<Sum>v\<in>S. u v *\<^sub>R v) = y"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1927
    using obt by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1928
qed auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1929
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1930
lemma caratheodory_aff_dim:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1931
  fixes p :: "('a::euclidean_space) set"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1932
  shows "convex hull p = {x. \<exists>S. finite S \<and> S \<subseteq> p \<and> card S \<le> aff_dim p + 1 \<and> x \<in> convex hull S}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1933
        (is "?lhs = ?rhs")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1934
proof
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1935
  have "\<And>x S u. \<lbrakk>finite S; S \<subseteq> p; int (card S) \<le> aff_dim p + 1; \<forall>x\<in>S. 0 \<le> u x; sum u S = 1\<rbrakk>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1936
                \<Longrightarrow> (\<Sum>v\<in>S. u v *\<^sub>R v) \<in> convex hull S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1937
    by (simp add: hull_subset convex_explicit [THEN iffD1, OF convex_convex_hull])
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1938
  then show "?lhs \<subseteq> ?rhs"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1939
    by (subst convex_hull_caratheodory_aff_dim, auto)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1940
qed (use hull_mono in auto)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1941
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1942
lemma convex_hull_caratheodory:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1943
  fixes p :: "('a::euclidean_space) set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1944
  shows "convex hull p =
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1945
            {y. \<exists>S u. finite S \<and> S \<subseteq> p \<and> card S \<le> DIM('a) + 1 \<and>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1946
              (\<forall>x\<in>S. 0 \<le> u x) \<and> sum u S = 1 \<and> sum (\<lambda>v. u v *\<^sub>R v) S = y}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1947
        (is "?lhs = ?rhs")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1948
proof (intro set_eqI iffI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1949
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1950
  assume "x \<in> ?lhs" then show "x \<in> ?rhs"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1951
    unfolding convex_hull_caratheodory_aff_dim 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1952
    using aff_dim_le_DIM [of p] by fastforce
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1953
qed (auto simp: convex_hull_explicit)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1954
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1955
theorem caratheodory:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1956
  "convex hull p =
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1957
    {x::'a::euclidean_space. \<exists>S. finite S \<and> S \<subseteq> p \<and> card S \<le> DIM('a) + 1 \<and> x \<in> convex hull S}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1958
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1959
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1960
  assume "x \<in> convex hull p"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1961
  then obtain S u where "finite S" "S \<subseteq> p" "card S \<le> DIM('a) + 1"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1962
    "\<forall>x\<in>S. 0 \<le> u x" "sum u S = 1" "(\<Sum>v\<in>S. u v *\<^sub>R v) = x"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1963
    unfolding convex_hull_caratheodory by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1964
  then show "\<exists>S. finite S \<and> S \<subseteq> p \<and> card S \<le> DIM('a) + 1 \<and> x \<in> convex hull S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1965
    using convex_hull_finite by fastforce
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1966
qed (use hull_mono in force)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1967
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1968
subsection\<^marker>\<open>tag unimportant\<close>\<open>Some Properties of subset of standard basis\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1969
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1970
lemma affine_hull_substd_basis:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1971
  assumes "d \<subseteq> Basis"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1972
  shows "affine hull (insert 0 d) = {x::'a::euclidean_space. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x\<bullet>i = 0}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1973
  (is "affine hull (insert 0 ?A) = ?B")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1974
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1975
  have *: "\<And>A. (+) (0::'a) ` A = A" "\<And>A. (+) (- (0::'a)) ` A = A"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1976
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1977
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1978
    unfolding affine_hull_insert_span_gen span_substd_basis[OF assms,symmetric] * ..
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1979
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1980
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1981
lemma affine_hull_convex_hull [simp]: "affine hull (convex hull S) = affine hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1982
  by (metis Int_absorb1 Int_absorb2 convex_hull_subset_affine_hull hull_hull hull_mono hull_subset)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1983
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1984
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1985
subsection\<^marker>\<open>tag unimportant\<close> \<open>Moving and scaling convex hulls\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1986
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1987
lemma convex_hull_set_plus:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1988
  "convex hull (S + T) = convex hull S + convex hull T"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1989
  unfolding set_plus_image 
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1990
  apply (subst convex_hull_linear_image [symmetric])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1991
  apply (simp add: linear_iff scaleR_right_distrib)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1992
  apply (simp add: convex_hull_Times)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1993
  done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1994
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1995
lemma translation_eq_singleton_plus: "(\<lambda>x. a + x) ` T = {a} + T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1996
  unfolding set_plus_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1997
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1998
lemma convex_hull_translation:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1999
  "convex hull ((\<lambda>x. a + x) ` S) = (\<lambda>x. a + x) ` (convex hull S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2000
  unfolding translation_eq_singleton_plus
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2001
  by (simp only: convex_hull_set_plus convex_hull_singleton)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2002
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2003
lemma convex_hull_scaling:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2004
  "convex hull ((\<lambda>x. c *\<^sub>R x) ` S) = (\<lambda>x. c *\<^sub>R x) ` (convex hull S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2005
  using linear_scaleR by (rule convex_hull_linear_image [symmetric])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2006
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2007
lemma convex_hull_affinity:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2008
  "convex hull ((\<lambda>x. a + c *\<^sub>R x) ` S) = (\<lambda>x. a + c *\<^sub>R x) ` (convex hull S)"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2009
  by (metis convex_hull_scaling convex_hull_translation image_image)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2010
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2011
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  2012
subsection\<^marker>\<open>tag unimportant\<close> \<open>Convexity of cone hulls\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2013
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2014
lemma convex_cone_hull:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2015
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2016
  shows "convex (cone hull S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2017
proof (rule convexI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2018
  fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2019
  assume xy: "x \<in> cone hull S" "y \<in> cone hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2020
  then have "S \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2021
    using cone_hull_empty_iff[of S] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2022
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2023
  assume uv: "u \<ge> 0" "v \<ge> 0" "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2024
  then have *: "u *\<^sub>R x \<in> cone hull S" "v *\<^sub>R y \<in> cone hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2025
    using cone_cone_hull[of S] xy cone_def[of "cone hull S"] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2026
  from * obtain cx :: real and xx where x: "u *\<^sub>R x = cx *\<^sub>R xx" "cx \<ge> 0" "xx \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2027
    using cone_hull_expl[of S] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2028
  from * obtain cy :: real and yy where y: "v *\<^sub>R y = cy *\<^sub>R yy" "cy \<ge> 0" "yy \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2029
    using cone_hull_expl[of S] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2030
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2031
    assume "cx + cy \<le> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2032
    then have "u *\<^sub>R x = 0" and "v *\<^sub>R y = 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2033
      using x y by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2034
    then have "u *\<^sub>R x + v *\<^sub>R y = 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2035
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2036
    then have "u *\<^sub>R x + v *\<^sub>R y \<in> cone hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2037
      using cone_hull_contains_0[of S] \<open>S \<noteq> {}\<close> by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2038
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2039
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2040
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2041
    assume "cx + cy > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2042
    then have "(cx / (cx + cy)) *\<^sub>R xx + (cy / (cx + cy)) *\<^sub>R yy \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2043
      using assms mem_convex_alt[of S xx yy cx cy] x y by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2044
    then have "cx *\<^sub>R xx + cy *\<^sub>R yy \<in> cone hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2045
      using mem_cone_hull[of "(cx/(cx+cy)) *\<^sub>R xx + (cy/(cx+cy)) *\<^sub>R yy" S "cx+cy"] \<open>cx+cy>0\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2046
      by (auto simp: scaleR_right_distrib)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2047
    then have "u *\<^sub>R x + v *\<^sub>R y \<in> cone hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2048
      using x y by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2049
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2050
  moreover have "cx + cy \<le> 0 \<or> cx + cy > 0" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2051
  ultimately show "u *\<^sub>R x + v *\<^sub>R y \<in> cone hull S" by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2052
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2053
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2054
lemma cone_convex_hull:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2055
  assumes "cone S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2056
  shows "cone (convex hull S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2057
proof (cases "S = {}")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2058
  case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2059
  then show ?thesis by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2060
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2061
  case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2062
  then have *: "0 \<in> S \<and> (\<forall>c. c > 0 \<longrightarrow> (*\<^sub>R) c ` S = S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2063
    using cone_iff[of S] assms by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2064
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2065
    fix c :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2066
    assume "c > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2067
    then have "(*\<^sub>R) c ` (convex hull S) = convex hull ((*\<^sub>R) c ` S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2068
      using convex_hull_scaling[of _ S] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2069
    also have "\<dots> = convex hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2070
      using * \<open>c > 0\<close> by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2071
    finally have "(*\<^sub>R) c ` (convex hull S) = convex hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2072
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2073
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2074
  then have "0 \<in> convex hull S" "\<And>c. c > 0 \<Longrightarrow> ((*\<^sub>R) c ` (convex hull S)) = (convex hull S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2075
    using * hull_subset[of S convex] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2076
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2077
    using \<open>S \<noteq> {}\<close> cone_iff[of "convex hull S"] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2078
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2079
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2080
subsection \<open>Radon's theorem\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2081
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2082
text "Formalized by Lars Schewe."
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2083
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2084
lemma Radon_ex_lemma:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2085
  assumes "finite c" "affine_dependent c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2086
  shows "\<exists>u. sum u c = 0 \<and> (\<exists>v\<in>c. u v \<noteq> 0) \<and> sum (\<lambda>v. u v *\<^sub>R v) c = 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2087
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2088
  from assms(2)[unfolded affine_dependent_explicit]
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2089
  obtain S u where
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2090
      "finite S" "S \<subseteq> c" "sum u S = 0" "\<exists>v\<in>S. u v \<noteq> 0" "(\<Sum>v\<in>S. u v *\<^sub>R v) = 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2091
    by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2092
  then show ?thesis
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2093
    apply (rule_tac x="\<lambda>v. if v\<in>S then u v else 0" in exI)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2094
    unfolding if_smult scaleR_zero_left 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2095
    by (auto simp: Int_absorb1 sum.inter_restrict[OF \<open>finite c\<close>, symmetric])
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2096
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2097
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2098
lemma Radon_s_lemma:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2099
  assumes "finite S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2100
    and "sum f S = (0::real)"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2101
  shows "sum f {x\<in>S. 0 < f x} = - sum f {x\<in>S. f x < 0}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2102
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2103
  have *: "\<And>x. (if f x < 0 then f x else 0) + (if 0 < f x then f x else 0) = f x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2104
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2105
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2106
    unfolding add_eq_0_iff[symmetric] and sum.inter_filter[OF assms(1)]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2107
      and sum.distrib[symmetric] and *
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2108
    using assms(2)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2109
    by assumption
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2110
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2111
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2112
lemma Radon_v_lemma:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2113
  assumes "finite S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2114
    and "sum f S = 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2115
    and "\<forall>x. g x = (0::real) \<longrightarrow> f x = (0::'a::euclidean_space)"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2116
  shows "(sum f {x\<in>S. 0 < g x}) = - sum f {x\<in>S. g x < 0}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2117
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2118
  have *: "\<And>x. (if 0 < g x then f x else 0) + (if g x < 0 then f x else 0) = f x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2119
    using assms(3) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2120
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2121
    unfolding eq_neg_iff_add_eq_0 and sum.inter_filter[OF assms(1)]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2122
      and sum.distrib[symmetric] and *
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2123
    using assms(2)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2124
    apply assumption
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2125
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2126
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2127
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2128
lemma Radon_partition:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2129
  assumes "finite C" "affine_dependent C"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2130
  shows "\<exists>m p. m \<inter> p = {} \<and> m \<union> p = C \<and> (convex hull m) \<inter> (convex hull p) \<noteq> {}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2131
proof -
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2132
  obtain u v where uv: "sum u C = 0" "v\<in>C" "u v \<noteq> 0"  "(\<Sum>v\<in>C. u v *\<^sub>R v) = 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2133
    using Radon_ex_lemma[OF assms] by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2134
  have fin: "finite {x \<in> C. 0 < u x}" "finite {x \<in> C. 0 > u x}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2135
    using assms(1) by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2136
  define z  where "z = inverse (sum u {x\<in>C. u x > 0}) *\<^sub>R sum (\<lambda>x. u x *\<^sub>R x) {x\<in>C. u x > 0}"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2137
  have "sum u {x \<in> C. 0 < u x} \<noteq> 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2138
  proof (cases "u v \<ge> 0")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2139
    case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2140
    then have "u v < 0" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2141
    then show ?thesis
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2142
    proof (cases "\<exists>w\<in>{x \<in> C. 0 < u x}. u w > 0")
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2143
      case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2144
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2145
        using sum_nonneg_eq_0_iff[of _ u, OF fin(1)] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2146
    next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2147
      case False
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2148
      then have "sum u C \<le> sum (\<lambda>x. if x=v then u v else 0) C"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2149
        by (rule_tac sum_mono, auto)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2150
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2151
        unfolding sum.delta[OF assms(1)] using uv(2) and \<open>u v < 0\<close> and uv(1) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2152
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2153
  qed (insert sum_nonneg_eq_0_iff[of _ u, OF fin(1)] uv(2-3), auto)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2154
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2155
  then have *: "sum u {x\<in>C. u x > 0} > 0"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2156
    unfolding less_le by (metis (no_types, lifting) mem_Collect_eq sum_nonneg)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2157
  moreover have "sum u ({x \<in> C. 0 < u x} \<union> {x \<in> C. u x < 0}) = sum u C"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2158
    "(\<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)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2159
    using assms(1)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2160
    by (rule_tac[!] sum.mono_neutral_left, auto)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2161
  then have "sum u {x \<in> C. 0 < u x} = - sum u {x \<in> C. 0 > u x}"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2162
    "(\<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)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2163
    unfolding eq_neg_iff_add_eq_0
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2164
    using uv(1,4)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2165
    by (auto simp: sum.union_inter_neutral[OF fin, symmetric])
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2166
  moreover have "\<forall>x\<in>{v \<in> C. u v < 0}. 0 \<le> inverse (sum u {x \<in> C. 0 < u x}) * - u x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2167
    using * by (fastforce intro: mult_nonneg_nonneg)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2168
  ultimately have "z \<in> convex hull {v \<in> C. u v \<le> 0}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2169
    unfolding convex_hull_explicit mem_Collect_eq
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2170
    apply (rule_tac x="{v \<in> C. u v < 0}" in exI)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2171
    apply (rule_tac x="\<lambda>y. inverse (sum u {x\<in>C. u x > 0}) * - u y" in exI)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2172
    using assms(1) unfolding scaleR_scaleR[symmetric] scaleR_right.sum [symmetric] 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2173
    by (auto simp: z_def sum_negf sum_distrib_left[symmetric])
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2174
  moreover have "\<forall>x\<in>{v \<in> C. 0 < u v}. 0 \<le> inverse (sum u {x \<in> C. 0 < u x}) * u x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2175
    using * by (fastforce intro: mult_nonneg_nonneg)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2176
  then have "z \<in> convex hull {v \<in> C. u v > 0}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2177
    unfolding convex_hull_explicit mem_Collect_eq
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2178
    apply (rule_tac x="{v \<in> C. 0 < u v}" in exI)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2179
    apply (rule_tac x="\<lambda>y. inverse (sum u {x\<in>C. u x > 0}) * u y" in exI)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2180
    using assms(1)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2181
    unfolding scaleR_scaleR[symmetric] scaleR_right.sum [symmetric]
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2182
    using * by (auto simp: z_def sum_negf sum_distrib_left[symmetric])
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2183
  ultimately show ?thesis
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2184
    apply (rule_tac x="{v\<in>C. u v \<le> 0}" in exI)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2185
    apply (rule_tac x="{v\<in>C. u v > 0}" in exI, auto)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2186
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2187
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2188
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2189
theorem Radon:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2190
  assumes "affine_dependent c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2191
  obtains m p where "m \<subseteq> c" "p \<subseteq> c" "m \<inter> p = {}" "(convex hull m) \<inter> (convex hull p) \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2192
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2193
  from assms[unfolded affine_dependent_explicit]
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2194
  obtain S u where
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2195
      "finite S" "S \<subseteq> c" "sum u S = 0" "\<exists>v\<in>S. u v \<noteq> 0" "(\<Sum>v\<in>S. u v *\<^sub>R v) = 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2196
    by blast
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2197
  then have *: "finite S" "affine_dependent S" and S: "S \<subseteq> c"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2198
    unfolding affine_dependent_explicit by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2199
  from Radon_partition[OF *]
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2200
  obtain m p where "m \<inter> p = {}" "m \<union> p = S" "convex hull m \<inter> convex hull p \<noteq> {}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2201
    by blast
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2202
  with S show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2203
    by (force intro: that[of p m])
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2204
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2205
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2206
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2207
subsection \<open>Helly's theorem\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2208
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2209
lemma Helly_induct:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2210
  fixes f :: "'a::euclidean_space set set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2211
  assumes "card f = n"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2212
    and "n \<ge> DIM('a) + 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2213
    and "\<forall>s\<in>f. convex s" "\<forall>t\<subseteq>f. card t = DIM('a) + 1 \<longrightarrow> \<Inter>t \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2214
  shows "\<Inter>f \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2215
  using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2216
proof (induction n arbitrary: f)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2217
  case 0
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2218
  then show ?case by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2219
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2220
  case (Suc n)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2221
  have "finite f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2222
    using \<open>card f = Suc n\<close> by (auto intro: card_ge_0_finite)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2223
  show "\<Inter>f \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2224
  proof (cases "n = DIM('a)")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2225
    case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2226
    then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2227
      by (simp add: Suc.prems(1) Suc.prems(4))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2228
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2229
    case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2230
    have "\<Inter>(f - {s}) \<noteq> {}" if "s \<in> f" for s
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2231
    proof (rule Suc.IH[rule_format])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2232
      show "card (f - {s}) = n"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2233
        by (simp add: Suc.prems(1) \<open>finite f\<close> that)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2234
      show "DIM('a) + 1 \<le> n"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2235
        using False Suc.prems(2) by linarith
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2236
      show "\<And>t. \<lbrakk>t \<subseteq> f - {s}; card t = DIM('a) + 1\<rbrakk> \<Longrightarrow> \<Inter>t \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2237
        by (simp add: Suc.prems(4) subset_Diff_insert)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2238
    qed (use Suc in auto)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2239
    then have "\<forall>s\<in>f. \<exists>x. x \<in> \<Inter>(f - {s})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2240
      by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2241
    then obtain X where X: "\<And>s. s\<in>f \<Longrightarrow> X s \<in> \<Inter>(f - {s})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2242
      by metis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2243
    show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2244
    proof (cases "inj_on X f")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2245
      case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2246
      then obtain s t where "s\<noteq>t" and st: "s\<in>f" "t\<in>f" "X s = X t"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2247
        unfolding inj_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2248
      then have *: "\<Inter>f = \<Inter>(f - {s}) \<inter> \<Inter>(f - {t})" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2249
      show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2250
        by (metis "*" X disjoint_iff_not_equal st)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2251
    next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2252
      case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2253
      then obtain m p where mp: "m \<inter> p = {}" "m \<union> p = X ` f" "convex hull m \<inter> convex hull p \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2254
        using Radon_partition[of "X ` f"] and affine_dependent_biggerset[of "X ` f"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2255
        unfolding card_image[OF True] and \<open>card f = Suc n\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2256
        using Suc(3) \<open>finite f\<close> and False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2257
        by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2258
      have "m \<subseteq> X ` f" "p \<subseteq> X ` f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2259
        using mp(2) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2260
      then obtain g h where gh:"m = X ` g" "p = X ` h" "g \<subseteq> f" "h \<subseteq> f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2261
        unfolding subset_image_iff by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2262
      then have "f \<union> (g \<union> h) = f" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2263
      then have f: "f = g \<union> h"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2264
        using inj_on_Un_image_eq_iff[of X f "g \<union> h"] and True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2265
        unfolding mp(2)[unfolded image_Un[symmetric] gh]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2266
        by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2267
      have *: "g \<inter> h = {}"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2268
        using gh(1) gh(2) local.mp(1) by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2269
      have "convex hull (X ` h) \<subseteq> \<Inter>g" "convex hull (X ` g) \<subseteq> \<Inter>h"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2270
        by (rule hull_minimal; use X * f in \<open>auto simp: Suc.prems(3) convex_Inter\<close>)+
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2271
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2272
        unfolding f using mp(3)[unfolded gh] by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2273
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2274
  qed 
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2275
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2276
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2277
theorem Helly:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2278
  fixes f :: "'a::euclidean_space set set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2279
  assumes "card f \<ge> DIM('a) + 1" "\<forall>s\<in>f. convex s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2280
    and "\<And>t. \<lbrakk>t\<subseteq>f; card t = DIM('a) + 1\<rbrakk> \<Longrightarrow> \<Inter>t \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2281
  shows "\<Inter>f \<noteq> {}"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2282
  using Helly_induct assms by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2283
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2284
subsection \<open>Epigraphs of convex functions\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2285
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  2286
definition\<^marker>\<open>tag important\<close> "epigraph S (f :: _ \<Rightarrow> real) = {xy. fst xy \<in> S \<and> f (fst xy) \<le> snd xy}"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2287
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2288
lemma mem_epigraph: "(x, y) \<in> epigraph S f \<longleftrightarrow> x \<in> S \<and> f x \<le> y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2289
  unfolding epigraph_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2290
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2291
lemma convex_epigraph: "convex (epigraph S f) \<longleftrightarrow> convex_on S f \<and> convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2292
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2293
  assume L: "convex (epigraph S f)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2294
  then show "convex_on S f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2295
    by (auto simp: convex_def convex_on_def epigraph_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2296
  show "convex S"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2297
    using L by (fastforce simp: convex_def convex_on_def epigraph_def)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2298
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2299
  assume "convex_on S f" "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2300
  then show "convex (epigraph S f)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2301
    unfolding convex_def convex_on_def epigraph_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2302
    apply safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2303
     apply (rule_tac [2] y="u * f a + v * f aa" in order_trans)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2304
      apply (auto intro!:mult_left_mono add_mono)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2305
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2306
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2307
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2308
lemma convex_epigraphI: "convex_on S f \<Longrightarrow> convex S \<Longrightarrow> convex (epigraph S f)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2309
  unfolding convex_epigraph by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2310
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2311
lemma convex_epigraph_convex: "convex S \<Longrightarrow> convex_on S f \<longleftrightarrow> convex(epigraph S f)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2312
  by (simp add: convex_epigraph)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2313
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2314
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  2315
subsubsection\<^marker>\<open>tag unimportant\<close> \<open>Use this to derive general bound property of convex function\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2316
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2317
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2318
lemma convex_on:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2319
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2320
  shows "convex_on S f \<longleftrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2321
    (\<forall>k u x. (\<forall>i\<in>{1..k::nat}. 0 \<le> u i \<and> x i \<in> S) \<and> sum u {1..k} = 1 \<longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2322
      f (sum (\<lambda>i. u i *\<^sub>R x i) {1..k}) \<le> sum (\<lambda>i. u i * f(x i)) {1..k})"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2323
  (is "?lhs = (\<forall>k u x. ?rhs k u x)")
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2324
proof
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2325
  assume ?lhs 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2326
  then have \<section>: "convex {xy. fst xy \<in> S \<and> f (fst xy) \<le> snd xy}"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2327
    by (metis assms convex_epigraph epigraph_def)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2328
  show "\<forall>k u x. ?rhs k u x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2329
  proof (intro allI)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2330
    fix k u x
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2331
    show "?rhs k u x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2332
      using \<section>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2333
      unfolding  convex mem_Collect_eq fst_sum snd_sum 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2334
      apply safe
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2335
      apply (drule_tac x=k in spec)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2336
      apply (drule_tac x=u in spec)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2337
      apply (drule_tac x="\<lambda>i. (x i, f (x i))" in spec)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2338
      apply simp
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2339
      done
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2340
  qed
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2341
next
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2342
  assume "\<forall>k u x. ?rhs k u x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2343
  then show ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2344
  unfolding convex_epigraph_convex[OF assms] convex epigraph_def Ball_def mem_Collect_eq fst_sum snd_sum
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2345
  using assms[unfolded convex] apply clarsimp
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2346
  apply (rule_tac y="\<Sum>i = 1..k. u i * f (fst (x i))" in order_trans)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2347
  by (auto simp add: mult_left_mono intro: sum_mono)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2348
qed
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2349
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2350
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  2351
subsection\<^marker>\<open>tag unimportant\<close> \<open>A bound within a convex hull\<close>
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2352
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2353
lemma convex_on_convex_hull_bound:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2354
  assumes "convex_on (convex hull S) f"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2355
    and "\<forall>x\<in>S. f x \<le> b"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2356
  shows "\<forall>x\<in> convex hull S. f x \<le> b"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2357
proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2358
  fix x
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2359
  assume "x \<in> convex hull S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2360
  then obtain k u v where
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2361
    u: "\<forall>i\<in>{1..k::nat}. 0 \<le> u i \<and> v i \<in> S" "sum u {1..k} = 1" "(\<Sum>i = 1..k. u i *\<^sub>R v i) = x"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2362
    unfolding convex_hull_indexed mem_Collect_eq by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2363
  have "(\<Sum>i = 1..k. u i * f (v i)) \<le> b"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2364
    using sum_mono[of "{1..k}" "\<lambda>i. u i * f (v i)" "\<lambda>i. u i * b"]
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2365
    unfolding sum_distrib_right[symmetric] u(2) mult_1
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2366
    using assms(2) mult_left_mono u(1) by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2367
  then show "f x \<le> b"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2368
    using assms(1)[unfolded convex_on[OF convex_convex_hull], rule_format, of k u v]
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2369
    using hull_inc u by fastforce
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2370
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2371
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2372
lemma inner_sum_Basis[simp]: "i \<in> Basis \<Longrightarrow> (\<Sum>Basis) \<bullet> i = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2373
  by (simp add: inner_sum_left sum.If_cases inner_Basis)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2374
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2375
lemma convex_set_plus:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2376
  assumes "convex S" and "convex T" shows "convex (S + T)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2377
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2378
  have "convex (\<Union>x\<in> S. \<Union>y \<in> T. {x + y})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2379
    using assms by (rule convex_sums)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2380
  moreover have "(\<Union>x\<in> S. \<Union>y \<in> T. {x + y}) = S + T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2381
    unfolding set_plus_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2382
  finally show "convex (S + T)" .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2383
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2384
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2385
lemma convex_set_sum:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2386
  assumes "\<And>i. i \<in> A \<Longrightarrow> convex (B i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2387
  shows "convex (\<Sum>i\<in>A. B i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2388
proof (cases "finite A")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2389
  case True then show ?thesis using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2390
    by induct (auto simp: convex_set_plus)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2391
qed auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2392
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2393
lemma finite_set_sum:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2394
  assumes "finite A" and "\<forall>i\<in>A. finite (B i)" shows "finite (\<Sum>i\<in>A. B i)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2395
  using assms by (induct set: finite, simp, simp add: finite_set_plus)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2396
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2397
lemma box_eq_set_sum_Basis:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2398
  "{x. \<forall>i\<in>Basis. x\<bullet>i \<in> B i} = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` (B i))" (is "?lhs = ?rhs")
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2399
proof -
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2400
  have "\<And>x. \<forall>i\<in>Basis. x \<bullet> i \<in> B i \<Longrightarrow>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2401
         \<exists>s. x = sum s Basis \<and> (\<forall>i\<in>Basis. s i \<in> (\<lambda>x. x *\<^sub>R i) ` B i)"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2402
    by (metis (mono_tags, lifting) euclidean_representation image_iff)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2403
  moreover
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2404
  have "sum f Basis \<bullet> i \<in> B i" if "i \<in> Basis" and f: "\<forall>i\<in>Basis. f i \<in> (\<lambda>x. x *\<^sub>R i) ` B i" for i f
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2405
  proof -
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2406
    have "(\<Sum>x\<in>Basis - {i}. f x \<bullet> i) = 0"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2407
    proof (rule sum.neutral, intro strip)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2408
      show "f x \<bullet> i = 0" if "x \<in> Basis - {i}" for x
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2409
        using that f \<open>i \<in> Basis\<close> inner_Basis that by fastforce
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2410
    qed
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2411
    then have "(\<Sum>x\<in>Basis. f x \<bullet> i) = f i \<bullet> i"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2412
      by (metis (no_types) \<open>i \<in> Basis\<close> add.right_neutral sum.remove [OF finite_Basis])
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2413
    then have "(\<Sum>x\<in>Basis. f x \<bullet> i) \<in> B i"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2414
      using f that(1) by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2415
    then show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2416
      by (simp add: inner_sum_left)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2417
  qed
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2418
  ultimately show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2419
    by (subst set_sum_alt [OF finite_Basis]) auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2420
qed
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2421
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2422
lemma convex_hull_set_sum:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2423
  "convex hull (\<Sum>i\<in>A. B i) = (\<Sum>i\<in>A. convex hull (B i))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2424
proof (cases "finite A")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2425
  assume "finite A" then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2426
    by (induct set: finite, simp, simp add: convex_hull_set_plus)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2427
qed simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2428
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2429
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2430
end