src/HOL/Analysis/Convex.thy
author nipkow
Wed, 31 Mar 2021 18:18:03 +0200
changeset 73526 a3cc9fa1295d
parent 72385 4a2c0eb482aa
child 74729 64b3d8d9bd10
permissions -rw-r--r--
new automatic order prover: stateless, complete, verified
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
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   347
lemma convex_onI [intro?]:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   348
  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
   349
    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
   350
  shows "convex_on A f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   351
  unfolding convex_on_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   352
proof clarify
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   353
  fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   354
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   355
  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
   356
  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
   357
    by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   358
  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
   359
    using assms[of u y x]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   360
    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
   361
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   362
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   363
lemma convex_on_linorderI [intro?]:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   364
  fixes A :: "('a::{linorder,real_vector}) set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   365
  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
   366
    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
   367
  shows "convex_on A f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   368
proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   369
  fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   370
  fix t :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   371
  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
   372
  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
   373
  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
   374
    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
   375
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   376
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   377
lemma convex_onD:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   378
  assumes "convex_on A f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   379
  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
   380
    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
   381
  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
   382
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   383
lemma convex_onD_Icc:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   384
  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
   385
  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
   386
    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
   387
  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
   388
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   389
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
   390
  unfolding convex_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   391
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   392
lemma convex_on_add [intro]:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   393
  assumes "convex_on S f"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   394
    and "convex_on S g"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   395
  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
   396
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   397
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   398
    fix x y
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   399
    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
   400
    moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   401
    fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   402
    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
   403
    ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   404
    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
   405
      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
   406
    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
   407
      by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   408
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   409
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   410
    unfolding convex_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   411
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   412
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   413
lemma convex_on_cmul [intro]:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   414
  fixes c :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   415
  assumes "0 \<le> c"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   416
    and "convex_on S f"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   417
  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
   418
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   419
  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
   420
    for u c fx v fy :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   421
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   422
  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
   423
    unfolding convex_on_def and * by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   424
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   425
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   426
lemma convex_lower:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   427
  assumes "convex_on S f"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   428
    and "x \<in> S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   429
    and "y \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   430
    and "0 \<le> u"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   431
    and "0 \<le> v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   432
    and "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   433
  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
   434
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   435
  let ?m = "max (f x) (f y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   436
  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
   437
    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
   438
  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
   439
    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
   440
  finally show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   441
    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
   442
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   443
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   444
lemma convex_on_dist [intro]:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   445
  fixes S :: "'a::real_normed_vector set"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   446
  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
   447
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
   448
  fix x y
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   449
  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
   450
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   451
  assume "0 \<le> u"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   452
  assume "0 \<le> v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   453
  assume "u + v = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   454
  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
   455
    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
   456
  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
   457
    by (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   458
  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
   459
    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
   460
    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
   461
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   462
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   463
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
   464
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
   465
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   466
lemma convex_linear_image:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   467
  assumes "linear f"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   468
    and "convex S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   469
  shows "convex (f ` S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   470
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   471
  interpret f: linear f by fact
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   472
  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
   473
    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
   474
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   475
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   476
lemma convex_linear_vimage:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   477
  assumes "linear f"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   478
    and "convex S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   479
  shows "convex (f -` S)"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   480
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   481
  interpret f: linear f by fact
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   482
  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
   483
    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
   484
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   485
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   486
lemma convex_scaling:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   487
  assumes "convex S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   488
  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
   489
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   490
  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
   491
    by (simp add: linearI scaleR_add_right)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   492
  then show ?thesis
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   493
    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
   494
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   495
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   496
lemma convex_scaled:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   497
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   498
  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
   499
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   500
  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
   501
    by (simp add: linearI scaleR_add_left)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   502
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   503
    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
   504
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   505
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   506
lemma convex_negations:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   507
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   508
  shows "convex ((\<lambda>x. - x) ` S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   509
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   510
  have "linear (\<lambda>x. - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   511
    by (simp add: linearI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   512
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   513
    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
   514
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   515
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   516
lemma convex_sums:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   517
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   518
    and "convex T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   519
  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
   520
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   521
  have "linear (\<lambda>(x, y). x + y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   522
    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
   523
  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
   524
    by (intro convex_linear_image convex_Times)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   525
  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
   526
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   527
  finally show ?thesis .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   528
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   529
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   530
lemma convex_differences:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   531
  assumes "convex S" "convex T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   532
  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
   533
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   534
  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
   535
    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
   536
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   537
    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
   538
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   539
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   540
lemma convex_translation:
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   541
  "convex ((+) a ` S)" if "convex S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   542
proof -
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   543
  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
   544
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   545
  then show ?thesis
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   546
    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
   547
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   548
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   549
lemma convex_translation_subtract:
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   550
  "convex ((\<lambda>b. b - a) ` S)" if "convex S"
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   551
  using convex_translation [of S "- a"] that by (simp cong: image_cong_simp)
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
   552
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   553
lemma convex_affinity:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   554
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   555
  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
   556
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   557
  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
   558
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   559
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   560
    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
   561
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   562
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   563
lemma convex_on_sum:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   564
  fixes a :: "'a \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   565
    and y :: "'a \<Rightarrow> 'b::real_vector"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   566
    and f :: "'b \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   567
  assumes "finite s" "s \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   568
    and "convex_on C f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   569
    and "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   570
    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
   571
    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
   572
    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
   573
  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
   574
  using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   575
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
   576
  case (singleton i)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   577
  then have ai: "a i = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   578
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   579
  then show ?case
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   580
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   581
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   582
  case (insert i s)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   583
  then have "convex_on C f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   584
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   585
  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
   586
  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
   587
      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
   588
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   589
  show ?case
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   590
  proof (cases "a i = 1")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   591
    case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   592
    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
   593
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   594
    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
   595
      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
   596
    then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   597
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   598
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   599
    case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   600
    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
   601
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   602
    have fis: "finite (insert i s)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   603
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   604
    then have ai1: "a i \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   605
      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
   606
    then have "a i < 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   607
      using False by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   608
    then have i0: "1 - a i > 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
    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
   611
    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
   612
      using i0 insert that by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   613
    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
   614
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   615
    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
   616
      using sum.insert insert by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   617
    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
   618
      using i0 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   619
    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
   620
      unfolding sum_divide_distrib by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   621
    have "convex C" using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   622
    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
   623
      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
   624
    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
   625
      using a_nonneg a1 insert by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   626
    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
   627
      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
   628
      by (auto simp only: add.commute)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   629
    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
   630
      using i0 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   631
    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
   632
      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
   633
      by (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   634
    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
   635
      by (auto simp: divide_inverse)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   636
    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
   637
      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
   638
      by (auto simp: add.commute)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   639
    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
   640
      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
   641
            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
   642
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   643
    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
   644
      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
   645
      using i0 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   646
    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
   647
      using i0 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   648
    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
   649
      using insert by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   650
    finally show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   651
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   652
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   653
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   654
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   655
lemma convex_on_alt:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   656
  fixes C :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   657
  shows "convex_on C f \<longleftrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   658
    (\<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
   659
      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
   660
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   661
  fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   662
  fix \<mu> :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   663
  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
   664
  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
   665
  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
   666
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   667
  from this [of "\<mu>" "1 - \<mu>", simplified] *
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   668
  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
   669
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   670
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   671
  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
   672
    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
   673
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   674
    fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   675
    fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   676
    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
   677
    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
   678
    from *[rule_format, of x y u]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   679
    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
   680
      using ** by auto
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
  then show "convex_on C f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   683
    unfolding convex_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   684
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   685
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   686
lemma convex_on_diff:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   687
  fixes f :: "real \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   688
  assumes f: "convex_on I f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   689
    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
   690
    and t: "x < t" "t < y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   691
  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
   692
    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
   693
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   694
  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
   695
  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
   696
    by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   697
  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
   698
    by (auto simp: convex_on_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   699
  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
   700
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   701
  also have "\<dots> = t"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   702
    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
   703
  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
   704
    using cvx by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   705
  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
   706
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   707
  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
   708
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   709
  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
   710
    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
   711
  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
   712
    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
   713
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   714
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   715
lemma pos_convex_function:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   716
  fixes f :: "real \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   717
  assumes "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   718
    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
   719
  shows "convex_on C f"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
   720
  unfolding convex_on_alt
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   721
  using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   722
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   723
  fix x y \<mu> :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   724
  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
   725
  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
   726
  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
   727
  then have xpos: "?x \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   728
    using * unfolding convex_alt by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   729
  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
   730
      \<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
   731
    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
   732
        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
   733
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   734
  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
   735
    by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   736
  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
   737
    by auto
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   738
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   739
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   740
lemma atMostAtLeast_subset_convex:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   741
  fixes C :: "real set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   742
  assumes "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   743
    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
   744
  shows "{x .. y} \<subseteq> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   745
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   746
  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
   747
  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
   748
  proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   749
    let ?\<mu> = "(y - z) / (y - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   750
    have "0 \<le> ?\<mu>" "?\<mu> \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   751
      using assms * by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   752
    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
   753
      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
   754
      by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   755
    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
   756
      by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   757
    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
   758
      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
   759
    also have "\<dots> = z"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   760
      using assms by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   761
    finally show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   762
      using comb by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   763
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   764
  show "z \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   765
    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
   766
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   767
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   768
lemma f''_imp_f':
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   769
  fixes f :: "real \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   770
  assumes "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   771
    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
   772
    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
   773
    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
   774
    and x: "x \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   775
    and y: "y \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   776
  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
   777
  using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   778
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   779
  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
   780
    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
   781
  proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   782
    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
   783
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   784
    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
   785
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   786
    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
   787
      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
   788
          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
   789
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   790
    then have "z1 \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   791
      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
   792
      by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   793
    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
   794
      by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   795
    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
   796
      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
   797
          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
   798
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   799
    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
   800
      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
   801
          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
   802
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   803
    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
   804
      using * z1' by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   805
    also have "\<dots> = (y - z1) * f'' z3"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   806
      using z3 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   807
    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
   808
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   809
    have A': "y - z1 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   810
      using z1 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   811
    have "z3 \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   812
      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
   813
      by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   814
    then have B': "f'' z3 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   815
      using assms by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   816
    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
   817
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   818
    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
   819
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   820
    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
   821
    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
   822
      by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   823
    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
   824
      using le by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   825
    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
   826
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   827
    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
   828
      using * z1 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   829
    also have "\<dots> = (z1 - x) * f'' z2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   830
      using z2 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   831
    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
   832
      by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   833
    have A: "z1 - x \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   834
      using z1 by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   835
    have "z2 \<in> C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   836
      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
   837
      by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   838
    then have B: "f'' z2 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   839
      using assms by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   840
    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
   841
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   842
    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
   843
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   844
    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
   845
    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
   846
      by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   847
    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
   848
      using ge by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   849
    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
   850
      using res by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   851
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   852
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   853
  proof (cases "x = y")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   854
    case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   855
    with x y show ?thesis by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   856
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   857
    case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   858
    with less_imp x y show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   859
      by (auto simp: neq_iff)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   860
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   861
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   862
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   863
lemma f''_ge0_imp_convex:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   864
  fixes f :: "real \<Rightarrow> real"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   865
  assumes conv: "convex C"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   866
    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
   867
    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
   868
    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
   869
  shows "convex_on C f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   870
  using f''_imp_f'[OF conv f' f'' pos] assms pos_convex_function
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   871
  by fastforce
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   872
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   873
lemma minus_log_convex:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   874
  fixes b :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   875
  assumes "b > 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   876
  shows "convex_on {0 <..} (\<lambda> x. - log b x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   877
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   878
  have "\<And>z. z > 0 \<Longrightarrow> DERIV (log b) z :> 1 / (ln b * z)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   879
    using DERIV_log by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   880
  then have f': "\<And>z. z > 0 \<Longrightarrow> DERIV (\<lambda> z. - log b z) z :> - 1 / (ln b * z)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   881
    by (auto simp: DERIV_minus)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   882
  have "\<And>z::real. z > 0 \<Longrightarrow> DERIV inverse z :> - (inverse z ^ Suc (Suc 0))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   883
    using less_imp_neq[THEN not_sym, THEN DERIV_inverse] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   884
  from this[THEN DERIV_cmult, of _ "- 1 / ln b"]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   885
  have "\<And>z::real. z > 0 \<Longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   886
    DERIV (\<lambda> z. (- 1 / ln b) * inverse z) z :> (- 1 / ln b) * (- (inverse z ^ Suc (Suc 0)))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   887
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   888
  then have f''0: "\<And>z::real. z > 0 \<Longrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   889
    DERIV (\<lambda> z. - 1 / (ln b * z)) z :> 1 / (ln b * z * z)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   890
    unfolding inverse_eq_divide by (auto simp: mult.assoc)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   891
  have f''_ge0: "\<And>z::real. z > 0 \<Longrightarrow> 1 / (ln b * z * z) \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   892
    using \<open>b > 1\<close> by (auto intro!: less_imp_le)
71244
38457af660bc cleaning
nipkow
parents: 71242
diff changeset
   893
  from f''_ge0_imp_convex[OF convex_real_interval(3), unfolded greaterThan_iff, OF f' f''0 f''_ge0]
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   894
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   895
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   896
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   897
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   898
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
   899
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
   900
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   901
lemma convex_on_realI:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   902
  assumes "connected A"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   903
    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
   904
    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
   905
  shows "convex_on A f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   906
proof (rule convex_on_linorderI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   907
  fix t x y :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   908
  assume t: "t > 0" "t < 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   909
  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
   910
  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
   911
  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
   912
    using connected_contains_Icc by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   913
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   914
  from xy t have xz: "z > x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   915
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   916
  have "y - z = (1 - t) * (y - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   917
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   918
  also from xy t have "\<dots> > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   919
    by (intro mult_pos_pos) simp_all
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   920
  finally have yz: "z < y"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   921
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   922
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   923
  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
   924
    by (intro MVT2) (auto intro!: assms(2))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   925
  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
   926
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   927
  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
   928
    by (intro MVT2) (auto intro!: assms(2))
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   929
  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
   930
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   931
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   932
  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
   933
  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
   934
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   935
  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
   936
    by (intro assms(3)) auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   937
  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
   938
  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
   939
    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
   940
  also have "z - x = t * (y - x)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   941
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   942
  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
   943
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   944
  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
   945
    using xy by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   946
  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
   947
    by (simp add: z_def algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   948
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   949
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   950
lemma convex_on_inverse:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   951
  assumes "A \<subseteq> {0<..}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   952
  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
   953
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
   954
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   955
  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
   956
  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
   957
    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
   958
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
   959
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   960
lemma convex_onD_Icc':
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   961
  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
   962
  defines "d \<equiv> y - x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   963
  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
   964
proof (cases x y rule: linorder_cases)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   965
  case less
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   966
  then have d: "d > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   967
    by (simp add: d_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   968
  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
   969
    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
   970
  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
   971
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   972
  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
   973
    by (simp add: d_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   974
  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
   975
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   976
  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
   977
    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
   978
  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
   979
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   980
  finally show ?thesis .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   981
qed (insert assms(2), simp_all)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   982
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   983
lemma convex_onD_Icc'':
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   984
  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
   985
  defines "d \<equiv> y - x"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   986
  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
   987
proof (cases x y rule: linorder_cases)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   988
  case less
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   989
  then have d: "d > 0"
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
  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
   992
    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
   993
  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
   994
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   995
  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
   996
    by (simp add: d_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   997
  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
   998
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
   999
  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
  1000
    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
  1001
  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
  1002
    by (simp add: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1003
  finally show ?thesis .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1004
qed (insert assms(2), simp_all)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1005
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1006
lemma convex_translation_eq [simp]:
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1007
  "convex ((+) a ` s) \<longleftrightarrow> convex s"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1008
  by (metis convex_translation translation_galois)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1009
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1010
lemma convex_translation_subtract_eq [simp]:
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1011
  "convex ((\<lambda>b. b - a) ` s) \<longleftrightarrow> convex s"
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1012
  using convex_translation_eq [of "- a"] by (simp cong: image_cong_simp)
a03a63b81f44 tuned proofs
haftmann
parents: 69619
diff changeset
  1013
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1014
lemma convex_linear_image_eq [simp]:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1015
    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
  1016
    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
  1017
    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
  1018
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1019
lemma fst_snd_linear: "linear (\<lambda>(x,y). x + y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1020
  unfolding linear_iff by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1021
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1022
lemma vector_choose_size:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1023
  assumes "0 \<le> c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1024
  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
  1025
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1026
  obtain a::'a where "a \<noteq> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1027
    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
  1028
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1029
    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
  1030
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1031
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1032
lemma vector_choose_dist:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1033
  assumes "0 \<le> c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1034
  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
  1035
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
  1036
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1037
lemma sum_delta'':
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1038
  fixes s::"'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1039
  assumes "finite s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1040
  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
  1041
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1042
  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
  1043
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1044
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1045
    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
  1046
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1047
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1048
lemma dist_triangle_eq:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1049
  fixes x y z :: "'a::real_inner"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1050
  shows "dist x z = dist x y + dist y z \<longleftrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1051
    norm (x - y) *\<^sub>R (y - z) = norm (y - z) *\<^sub>R (x - y)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1052
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1053
  have *: "x - y + (y - z) = x - z" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1054
  show ?thesis unfolding dist_norm norm_triangle_eq[of "x - y" "y - z", unfolded *]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1055
    by (auto simp:norm_minus_commute)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1056
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1057
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1058
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1059
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1060
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1061
subsection \<open>Cones\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1062
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1063
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
  1064
  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
  1065
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1066
lemma cone_empty[intro, simp]: "cone {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1067
  unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1068
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1069
lemma cone_univ[intro, simp]: "cone UNIV"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1070
  unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1071
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1072
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
  1073
  unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1074
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1075
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
  1076
  by (simp add: cone_def subspace_scale)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1077
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1078
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1079
subsubsection \<open>Conic hull\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1080
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1081
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
  1082
  unfolding hull_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1083
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1084
lemma cone_hull_eq: "cone hull S = S \<longleftrightarrow> cone S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1085
  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
  1086
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1087
lemma mem_cone:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1088
  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
  1089
  shows "c *\<^sub>R x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1090
  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
  1091
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1092
lemma cone_contains_0:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1093
  assumes "cone S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1094
  shows "S \<noteq> {} \<longleftrightarrow> 0 \<in> S"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1095
  using assms mem_cone by fastforce
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1096
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1097
lemma cone_0: "cone {0}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1098
  unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1099
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1100
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
  1101
  unfolding cone_def by blast
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 cone_iff:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1104
  assumes "S \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1105
  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
  1106
proof -
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
    assume "cone S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1109
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1110
      fix c :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1111
      assume "c > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1112
      {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1113
        fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1114
        assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1115
        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
  1116
          unfolding image_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1117
          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
  1118
            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
  1119
          by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1120
      }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1121
      moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1122
      {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1123
        fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1124
        assume "x \<in> ((*\<^sub>R) c) ` S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1125
        then have "x \<in> S"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1126
          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
  1127
      }
69768
7e4966eaf781 proper congruence rule for image operator
haftmann
parents: 69675
diff changeset
  1128
      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
  1129
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1130
    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
  1131
      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
  1132
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1133
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1134
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1135
    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
  1136
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1137
      fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1138
      assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1139
      fix c1 :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1140
      assume "c1 \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1141
      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
  1142
      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
  1143
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1144
    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
  1145
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1146
  ultimately show ?thesis by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1147
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1148
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1149
lemma cone_hull_empty: "cone hull {} = {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1150
  by (metis cone_empty cone_hull_eq)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1151
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1152
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
  1153
  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
  1154
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1155
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
  1156
  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
  1157
  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 mem_cone_hull:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1160
  assumes "x \<in> S" "c \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1161
  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
  1162
  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
  1163
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1164
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
  1165
  (is "?lhs = ?rhs")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1166
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1167
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1168
    fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1169
    assume "x \<in> ?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1170
    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
  1171
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1172
    fix c :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1173
    assume c: "c \<ge> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1174
    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
  1175
      using x by (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1176
    moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1177
    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
  1178
    ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1179
    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
  1180
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1181
  then have "cone ?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1182
    unfolding cone_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1183
  then have "?rhs \<in> Collect cone"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1184
    unfolding mem_Collect_eq by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1185
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1186
    fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1187
    assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1188
    then have "1 *\<^sub>R x \<in> ?rhs"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1189
      using zero_le_one by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1190
    then have "x \<in> ?rhs" 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
  then have "S \<subseteq> ?rhs" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1193
  then have "?lhs \<subseteq> ?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1194
    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
  1195
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1196
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1197
    fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1198
    assume "x \<in> ?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1199
    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
  1200
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1201
    then have "xx \<in> cone hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1202
      using hull_subset[of S] by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1203
    then have "x \<in> ?lhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1204
      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
  1205
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1206
  ultimately show ?thesis by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1207
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1208
71242
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1209
lemma convex_cone:
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1210
  "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
  1211
  (is "?lhs = ?rhs")
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1212
proof -
71242
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1213
  {
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1214
    fix x y
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1215
    assume "x\<in>s" "y\<in>s" and ?lhs
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1216
    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
  1217
      unfolding cone_def by auto
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1218
    then have "x + y \<in> s"
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1219
      using \<open>?lhs\<close>[unfolded convex_def, THEN conjunct1]
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1220
      apply (erule_tac x="2*\<^sub>R x" in ballE)
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1221
      apply (erule_tac x="2*\<^sub>R y" in ballE)
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1222
      apply (erule_tac x="1/2" in allE, simp)
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1223
      apply (erule_tac x="1/2" in allE, auto)
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1224
      done
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1225
  }
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1226
  then show ?thesis
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1227
    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
  1228
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1229
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1230
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1231
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
  1232
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1233
lemma convex_connected:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1234
  fixes S :: "'a::real_normed_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1235
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1236
  shows "connected S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1237
proof (rule connectedI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1238
  fix A B
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1239
  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
  1240
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1241
  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
  1242
  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
  1243
  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
  1244
  then have "continuous_on {0 .. 1} f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1245
    by (auto intro!: continuous_intros)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1246
  then have "connected (f ` {0 .. 1})"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1247
    by (auto intro!: connected_continuous_image)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1248
  note connectedD[OF this, of A B]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1249
  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
  1250
    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
  1251
  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
  1252
    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
  1253
  moreover have "f ` {0 .. 1} \<subseteq> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1254
    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
  1255
  ultimately show False by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1256
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1257
71136
nipkow
parents: 71044
diff changeset
  1258
corollary%unimportant connected_UNIV[intro]: "connected (UNIV :: 'a::real_normed_vector set)"
nipkow
parents: 71044
diff changeset
  1259
by (simp add: convex_connected)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1260
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1261
lemma convex_prod:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1262
  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
  1263
  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
  1264
  using assms unfolding convex_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1265
  by (auto simp: inner_add_left)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1266
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1267
lemma convex_positive_orthant: "convex {x::'a::euclidean_space. (\<forall>i\<in>Basis. 0 \<le> x\<bullet>i)}"
71136
nipkow
parents: 71044
diff changeset
  1268
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
  1269
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1270
subsection \<open>Convex hull\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1271
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1272
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
  1273
  unfolding hull_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1274
  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
  1275
  by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1276
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1277
lemma convex_hull_subset:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1278
    "s \<subseteq> convex hull t \<Longrightarrow> convex hull s \<subseteq> convex hull t"
71174
nipkow
parents: 71136
diff changeset
  1279
  by (simp add: subset_hull)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1280
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1281
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
  1282
  by (metis convex_convex_hull hull_same)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1283
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1284
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
  1285
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1286
lemma convex_hull_linear_image:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1287
  assumes f: "linear f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1288
  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
  1289
proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1290
  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
  1291
    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
  1292
  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
  1293
  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
  1294
    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
  1295
      by (fast intro: hull_inc)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1296
    show "convex (f -` (convex hull (f ` s)))"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1297
      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
  1298
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1299
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1300
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1301
lemma in_convex_hull_linear_image:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1302
  assumes "linear f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1303
    and "x \<in> convex hull s"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1304
  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
  1305
  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
  1306
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1307
lemma convex_hull_Times:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1308
  "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
  1309
proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1310
  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
  1311
    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
  1312
  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
  1313
  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
  1314
    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
  1315
    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
  1316
      by (simp add: hull_inc)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1317
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1318
    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
  1319
    have "convex ?S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1320
      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
  1321
        simp add: linear_iff)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1322
    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
  1323
      by (auto simp: image_def Bex_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1324
    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
  1325
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1326
    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
  1327
    proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1328
      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
  1329
      have "convex ?S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1330
      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
  1331
        simp add: linear_iff)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1332
      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
  1333
        by (auto simp: image_def Bex_def)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1334
      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
  1335
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1336
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1337
  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
  1338
    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
  1339
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1340
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1341
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1342
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
  1343
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1344
lemma convex_hull_empty[simp]: "convex hull {} = {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1345
  by (rule hull_unique) auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1346
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1347
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
  1348
  by (rule hull_unique) auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1349
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1350
lemma convex_hull_insert:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1351
  fixes S :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1352
  assumes "S \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1353
  shows "convex hull (insert a S) =
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1354
         {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
  1355
  (is "_ = ?hull")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1356
proof (intro equalityI hull_minimal subsetI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1357
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1358
  assume "x \<in> insert a S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1359
  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
  1360
  unfolding insert_iff
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1361
  proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1362
    assume "x = a"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1363
    then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1364
      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
  1365
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1366
    assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1367
    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
  1368
      by force
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1369
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1370
  then show "x \<in> ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1371
    by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1372
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1373
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1374
  assume "x \<in> ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1375
  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
  1376
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1377
  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
  1378
    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
  1379
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1380
  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
  1381
    unfolding obt(5) using obt(1-3)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1382
    by (rule convexD [OF convex_convex_hull])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1383
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1384
  show "convex ?hull"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1385
  proof (rule convexI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1386
    fix x y u v
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1387
    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
  1388
    from x obtain u1 v1 b1 where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1389
      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
  1390
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1391
    from y obtain u2 v2 b2 where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1392
      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
  1393
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1394
    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
  1395
      by (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1396
    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
  1397
      (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
  1398
    proof (cases "u * v1 + v * v2 = 0")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1399
      case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1400
      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
  1401
        by (auto simp: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1402
      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
  1403
        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
  1404
        by arith+
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1405
      then have "u * u1 + v * u2 = 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1406
        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
  1407
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1408
        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
  1409
    next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1410
      case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1411
      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
  1412
        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
  1413
      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
  1414
        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
  1415
      also have "\<dots> = u * v1 + v * v2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1416
        by simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1417
      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
  1418
      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
  1419
      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
  1420
        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
  1421
      show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1422
      proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1423
        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
  1424
          unfolding xeq yeq * **
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1425
          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
  1426
        show "?b \<in> convex hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1427
          using False zeroes obt1(4) obt2(4)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1428
          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
  1429
      qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1430
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1431
    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
  1432
       "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
  1433
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1434
    have u1: "u1 \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1435
      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
  1436
    have u2: "u2 \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1437
      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
  1438
    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
  1439
    proof (rule add_mono)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1440
      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
  1441
        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
  1442
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1443
    also have "\<dots> \<le> 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1444
      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
  1445
    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
  1446
    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
  1447
    proof (intro CollectI exI conjI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1448
      show "0 \<le> u * u1 + v * u2"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1449
        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
  1450
      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
  1451
        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
  1452
    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
  1453
  qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1454
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1455
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1456
lemma convex_hull_insert_alt:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1457
   "convex hull (insert a S) =
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1458
     (if S = {} then {a}
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1459
      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
  1460
  apply (auto simp: convex_hull_insert)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1461
  using diff_eq_eq apply fastforce
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1462
  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
  1463
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1464
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
  1465
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1466
proposition convex_hull_indexed:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1467
  fixes S :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1468
  shows "convex hull S =
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1469
    {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
  1470
                (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
  1471
    (is "?xyz = ?hull")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1472
proof (rule hull_unique [OF _ convexI])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1473
  show "S \<subseteq> ?hull" 
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1474
    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
  1475
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1476
  fix T
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1477
  assume "S \<subseteq> T" "convex T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1478
  then show "?hull \<subseteq> T"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1479
    by (blast intro: convex_sum)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1480
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1481
  fix x y u v
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1482
  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
  1483
  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
  1484
  from xy obtain k1 u1 x1 where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1485
    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
  1486
                      "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
  1487
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1488
  from xy obtain k2 u2 x2 where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1489
    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
  1490
                     "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
  1491
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1492
  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
  1493
          "{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
  1494
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1495
  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
  1496
    unfolding inj_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1497
  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
  1498
  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
  1499
  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
  1500
  proof (intro CollectI exI conjI ballI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1501
    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
  1502
      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
  1503
    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
  1504
      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
  1505
        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
  1506
      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
  1507
      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
  1508
  qed 
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1509
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1510
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1511
lemma convex_hull_finite:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1512
  fixes S :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1513
  assumes "finite S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1514
  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
  1515
  (is "?HULL = _")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1516
proof (rule hull_unique [OF _ convexI]; clarify)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1517
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1518
  assume "x \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1519
  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
  1520
    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
  1521
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1522
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1523
  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
  1524
  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
  1525
  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
  1526
  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
  1527
    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
  1528
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1529
  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
  1530
    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
  1531
    using uv(3) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1532
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1533
  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
  1534
    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
  1535
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1536
  ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1537
  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
  1538
             (\<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
  1539
    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
  1540
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
  1541
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1542
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1543
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
  1544
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1545
text "Formalized by Lars Schewe."
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1546
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1547
lemma convex_hull_explicit:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1548
  fixes p :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1549
  shows "convex hull p =
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1550
    {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
  1551
  (is "?lhs = ?rhs")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1552
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1553
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1554
    fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1555
    assume "x\<in>?lhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1556
    then obtain k u y where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1557
        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
  1558
      unfolding convex_hull_indexed by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1559
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1560
    have fin: "finite {1..k}" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1561
    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
  1562
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1563
      fix j
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1564
      assume "j\<in>{1..k}"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1565
      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
  1566
        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
  1567
        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
  1568
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1569
    moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1570
    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
  1571
      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
  1572
    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
  1573
      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
  1574
      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
  1575
    ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1576
    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
  1577
      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
  1578
      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
  1579
      done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1580
    then have "x\<in>?rhs" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1581
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1582
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1583
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1584
    fix y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1585
    assume "y\<in>?rhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1586
    then obtain S u where
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1587
      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
  1588
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1589
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1590
    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
  1591
      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
  1592
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1593
      fix i :: nat
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1594
      assume "i\<in>{1..card S}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1595
      then have "f i \<in> S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1596
        using f(2) by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1597
      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
  1598
    }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1599
    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
  1600
    {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1601
      fix y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1602
      assume "y\<in>S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1603
      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
  1604
        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
  1605
        by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1606
      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
  1607
        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
  1608
      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
  1609
      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
  1610
          "(\<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
  1611
        by (auto simp: sum_constant_scaleR)
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
    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
  1614
      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
  1615
        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
  1616
      unfolding f
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1617
      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
  1618
      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
  1619
      unfolding obt(4,5)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1620
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1621
    ultimately
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1622
    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
  1623
        (\<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
  1624
      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
  1625
      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
  1626
      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
  1627
      done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1628
    then have "y \<in> ?lhs"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1629
      unfolding convex_hull_indexed by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1630
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1631
  ultimately show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1632
    unfolding set_eq_iff by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1633
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1634
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1635
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1636
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
  1637
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1638
lemma convex_hull_finite_step:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1639
  fixes S :: "'a::real_vector set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1640
  assumes "finite S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1641
  shows
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1642
    "(\<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
  1643
      \<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
  1644
  (is "?lhs = ?rhs")
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1645
proof (cases "a \<in> S")
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1646
  case True
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1647
  then have *: "insert a S = S" by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1648
  show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1649
  proof
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1650
    assume ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1651
    then show ?rhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1652
      unfolding * by force
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1653
  next
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1654
    have fin: "finite (insert a S)" using assms by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1655
    assume ?rhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1656
    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
  1657
      by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1658
    then show ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1659
      using uv True assms
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1660
      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
  1661
      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
  1662
      done
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1663
  qed
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1664
next
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1665
  case False
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1666
  show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1667
  proof
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1668
    assume ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1669
    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
  1670
      by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1671
    then show ?rhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1672
      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
  1673
  next
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1674
    assume ?rhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1675
    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
  1676
      by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1677
    moreover
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1678
    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
  1679
      using False by (auto intro!: sum.cong)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1680
    ultimately show ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1681
      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
  1682
  qed
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1683
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1684
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1685
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1686
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
  1687
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1688
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
  1689
       (is "?lhs = ?rhs")
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1690
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1691
  have **: "finite {b}" by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1692
  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
  1693
                \<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
  1694
    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
  1695
  moreover
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1696
  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
  1697
               \<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
  1698
    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
  1699
    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
  1700
    done
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1701
  ultimately show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1702
    using convex_hull_finite_step[OF **, of a 1]
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1703
    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
  1704
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1705
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1706
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
  1707
  unfolding convex_hull_2
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1708
proof (rule Collect_cong)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1709
  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
  1710
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1711
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1712
  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
  1713
    (\<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
  1714
    apply (simp add: *)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1715
    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
  1716
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1717
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1718
lemma convex_hull_3:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1719
  "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
  1720
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1721
  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
  1722
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1723
  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
  1724
    by (auto simp: field_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1725
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1726
    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
  1727
    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
  1728
    apply (rule Collect_cong, simp)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1729
    apply auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1730
    apply (rule_tac x=va in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1731
    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
  1732
    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
  1733
    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
  1734
    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
  1735
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1736
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1737
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1738
lemma convex_hull_3_alt:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1739
  "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
  1740
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1741
  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
  1742
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1743
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1744
    unfolding convex_hull_3
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1745
    apply (auto simp: *)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1746
    apply (rule_tac x=v in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1747
    apply (rule_tac x=w in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1748
    apply (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1749
    apply (rule_tac x=u in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1750
    apply (rule_tac x=v in exI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1751
    apply (simp add: algebra_simps)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1752
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1753
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1754
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1755
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1756
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
  1757
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1758
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
  1759
  unfolding affine_def convex_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1760
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1761
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
  1762
  by (simp add: affine_imp_convex)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1763
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1764
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
  1765
  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
  1766
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1767
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
  1768
  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
  1769
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1770
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
  1771
  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
  1772
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1773
lemma aff_dim_convex_hull:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1774
  fixes S :: "'n::euclidean_space set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1775
  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
  1776
  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
  1777
    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
  1778
    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
  1779
  by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1780
71242
ec5090faf541 separated Affine theory from Convex
nipkow
parents: 71240
diff changeset
  1781
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1782
subsection \<open>Caratheodory's theorem\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1783
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1784
lemma convex_hull_caratheodory_aff_dim:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1785
  fixes p :: "('a::euclidean_space) set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1786
  shows "convex hull p =
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1787
    {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
  1788
        (\<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
  1789
  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
  1790
proof (intro allI iffI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1791
  fix y
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1792
  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
  1793
    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
  1794
  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
  1795
  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
  1796
  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
  1797
    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
  1798
  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
  1799
    by blast
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1800
  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
  1801
    "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
  1802
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1803
  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
  1804
  proof (rule ccontr, simp only: not_le)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1805
    assume "aff_dim p + 1 < card S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1806
    then have "affine_dependent S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1807
      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
  1808
      by blast
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1809
    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
  1810
      using affine_dependent_explicit_finite[OF obt(1)] by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1811
    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
  1812
    define t where "t = Min i"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1813
    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
  1814
    proof (rule ccontr, simp add: not_less)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1815
      assume as:"\<forall>x\<in>S. 0 \<le> w x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1816
      then have "sum w (S - {v}) \<ge> 0"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1817
        by (meson Diff_iff sum_nonneg)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1818
      then have "sum w S > 0"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1819
        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
  1820
      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
  1821
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1822
    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
  1823
    then have "t \<ge> 0"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1824
      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
  1825
      unfolding t_def i_def
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1826
      using obt(4)[unfolded le_less]
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1827
      by (auto simp: divide_le_0_iff)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1828
    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
  1829
    proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1830
      fix v
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1831
      assume "v \<in> S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1832
      then have v: "0 \<le> u v"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1833
        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
  1834
      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
  1835
      proof (cases "w v < 0")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1836
        case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1837
        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
  1838
      next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1839
        case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1840
        then have "t \<le> u v / (- w v)"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1841
          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
  1842
        then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1843
          unfolding real_0_le_add_iff
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1844
          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
  1845
      qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1846
    qed
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1847
    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
  1848
      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
  1849
    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
  1850
    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
  1851
      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
  1852
    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
  1853
      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
  1854
    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
  1855
      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
  1856
      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
  1857
    ultimately have "?P (n - 1)"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1858
      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
  1859
      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
  1860
      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
  1861
      apply (auto simp: * scaleR_left_distrib)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1862
      done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1863
    then show False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1864
      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
  1865
  qed
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1866
  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
  1867
      (\<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
  1868
    using obt by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1869
qed auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1870
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1871
lemma caratheodory_aff_dim:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1872
  fixes p :: "('a::euclidean_space) set"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1873
  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
  1874
        (is "?lhs = ?rhs")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1875
proof
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1876
  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
  1877
                \<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
  1878
    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
  1879
  then show "?lhs \<subseteq> ?rhs"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1880
    by (subst convex_hull_caratheodory_aff_dim, auto)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1881
qed (use hull_mono in auto)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1882
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1883
lemma convex_hull_caratheodory:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1884
  fixes p :: "('a::euclidean_space) set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1885
  shows "convex hull p =
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1886
            {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
  1887
              (\<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
  1888
        (is "?lhs = ?rhs")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1889
proof (intro set_eqI iffI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1890
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1891
  assume "x \<in> ?lhs" then show "x \<in> ?rhs"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1892
    unfolding convex_hull_caratheodory_aff_dim 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1893
    using aff_dim_le_DIM [of p] by fastforce
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1894
qed (auto simp: convex_hull_explicit)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1895
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1896
theorem caratheodory:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1897
  "convex hull p =
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1898
    {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
  1899
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1900
  fix x
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1901
  assume "x \<in> convex hull p"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1902
  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
  1903
    "\<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
  1904
    unfolding convex_hull_caratheodory by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1905
  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
  1906
    using convex_hull_finite by fastforce
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1907
qed (use hull_mono in force)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1908
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1909
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
  1910
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1911
lemma affine_hull_substd_basis:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1912
  assumes "d \<subseteq> Basis"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1913
  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
  1914
  (is "affine hull (insert 0 ?A) = ?B")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1915
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1916
  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
  1917
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1918
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1919
    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
  1920
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1921
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1922
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
  1923
  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
  1924
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1925
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1926
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
  1927
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1928
lemma convex_hull_set_plus:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1929
  "convex hull (S + T) = convex hull S + convex hull T"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  1930
  unfolding set_plus_image 
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1931
  apply (subst convex_hull_linear_image [symmetric])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1932
  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
  1933
  apply (simp add: convex_hull_Times)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1934
  done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1935
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1936
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
  1937
  unfolding set_plus_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1938
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1939
lemma convex_hull_translation:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1940
  "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
  1941
  unfolding translation_eq_singleton_plus
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1942
  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
  1943
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1944
lemma convex_hull_scaling:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1945
  "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
  1946
  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
  1947
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1948
lemma convex_hull_affinity:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1949
  "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
  1950
  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
  1951
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1952
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  1953
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
  1954
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1955
lemma convex_cone_hull:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1956
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1957
  shows "convex (cone hull S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1958
proof (rule convexI)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1959
  fix x y
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1960
  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
  1961
  then have "S \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1962
    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
  1963
  fix u v :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1964
  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
  1965
  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
  1966
    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
  1967
  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
  1968
    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
  1969
  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
  1970
    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
  1971
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1972
    assume "cx + cy \<le> 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1973
    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
  1974
      using x y by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1975
    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
  1976
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1977
    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
  1978
      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
  1979
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1980
  moreover
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1981
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1982
    assume "cx + cy > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1983
    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
  1984
      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
  1985
    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
  1986
      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
  1987
      by (auto simp: scaleR_right_distrib)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1988
    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
  1989
      using x y by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1990
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1991
  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
  1992
  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
  1993
qed
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 cone_convex_hull:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1996
  assumes "cone S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1997
  shows "cone (convex hull S)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1998
proof (cases "S = {}")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  1999
  case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2000
  then show ?thesis by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2001
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2002
  case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2003
  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
  2004
    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
  2005
  {
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2006
    fix c :: real
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2007
    assume "c > 0"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2008
    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
  2009
      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
  2010
    also have "\<dots> = convex hull S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2011
      using * \<open>c > 0\<close> by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2012
    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
  2013
      by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2014
  }
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2015
  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
  2016
    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
  2017
  then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2018
    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
  2019
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2020
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2021
subsection \<open>Radon's theorem\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2022
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2023
text "Formalized by Lars Schewe."
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2024
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2025
lemma Radon_ex_lemma:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2026
  assumes "finite c" "affine_dependent c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2027
  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
  2028
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2029
  from assms(2)[unfolded affine_dependent_explicit]
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2030
  obtain S u where
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2031
      "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
  2032
    by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2033
  then show ?thesis
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2034
    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
  2035
    unfolding if_smult scaleR_zero_left 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2036
    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
  2037
qed
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
lemma Radon_s_lemma:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2040
  assumes "finite S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2041
    and "sum f S = (0::real)"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2042
  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
  2043
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2044
  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
  2045
    by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2046
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2047
    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
  2048
      and sum.distrib[symmetric] and *
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2049
    using assms(2)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2050
    by assumption
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2051
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2052
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2053
lemma Radon_v_lemma:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2054
  assumes "finite S"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2055
    and "sum f S = 0"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2056
    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
  2057
  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
  2058
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2059
  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
  2060
    using assms(3) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2061
  show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2062
    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
  2063
      and sum.distrib[symmetric] and *
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2064
    using assms(2)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2065
    apply assumption
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2066
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2067
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2068
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2069
lemma Radon_partition:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2070
  assumes "finite C" "affine_dependent C"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2071
  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
  2072
proof -
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2073
  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
  2074
    using Radon_ex_lemma[OF assms] by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2075
  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
  2076
    using assms(1) by auto
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2077
  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
  2078
  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
  2079
  proof (cases "u v \<ge> 0")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2080
    case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2081
    then have "u v < 0" by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2082
    then show ?thesis
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2083
    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
  2084
      case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2085
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2086
        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
  2087
    next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2088
      case False
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2089
      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
  2090
        by (rule_tac sum_mono, auto)
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2091
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2092
        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
  2093
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2094
  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
  2095
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2096
  then have *: "sum u {x\<in>C. u x > 0} > 0"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2097
    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
  2098
  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
  2099
    "(\<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
  2100
    using assms(1)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2101
    by (rule_tac[!] sum.mono_neutral_left, auto)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2102
  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
  2103
    "(\<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
  2104
    unfolding eq_neg_iff_add_eq_0
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2105
    using uv(1,4)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2106
    by (auto simp: sum.union_inter_neutral[OF fin, symmetric])
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2107
  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
  2108
    using * by (fastforce intro: mult_nonneg_nonneg)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2109
  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
  2110
    unfolding convex_hull_explicit mem_Collect_eq
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2111
    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
  2112
    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
  2113
    using assms(1) unfolding scaleR_scaleR[symmetric] scaleR_right.sum [symmetric] 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2114
    by (auto simp: z_def sum_negf sum_distrib_left[symmetric])
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2115
  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
  2116
    using * by (fastforce intro: mult_nonneg_nonneg)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2117
  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
  2118
    unfolding convex_hull_explicit mem_Collect_eq
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2119
    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
  2120
    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
  2121
    using assms(1)
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2122
    unfolding scaleR_scaleR[symmetric] scaleR_right.sum [symmetric]
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2123
    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
  2124
  ultimately show ?thesis
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2125
    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
  2126
    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
  2127
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2128
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2129
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2130
theorem Radon:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2131
  assumes "affine_dependent c"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2132
  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
  2133
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2134
  from assms[unfolded affine_dependent_explicit]
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2135
  obtain S u where
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2136
      "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
  2137
    by blast
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2138
  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
  2139
    unfolding affine_dependent_explicit by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2140
  from Radon_partition[OF *]
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2141
  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
  2142
    by blast
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2143
  with S show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2144
    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
  2145
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2146
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2147
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2148
subsection \<open>Helly's theorem\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2149
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2150
lemma Helly_induct:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2151
  fixes f :: "'a::euclidean_space set set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2152
  assumes "card f = n"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2153
    and "n \<ge> DIM('a) + 1"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2154
    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
  2155
  shows "\<Inter>f \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2156
  using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2157
proof (induction n arbitrary: f)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2158
  case 0
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2159
  then show ?case by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2160
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2161
  case (Suc n)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2162
  have "finite f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2163
    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
  2164
  show "\<Inter>f \<noteq> {}"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2165
  proof (cases "n = DIM('a)")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2166
    case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2167
    then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2168
      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
  2169
  next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2170
    case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2171
    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
  2172
    proof (rule Suc.IH[rule_format])
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2173
      show "card (f - {s}) = n"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2174
        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
  2175
      show "DIM('a) + 1 \<le> n"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2176
        using False Suc.prems(2) by linarith
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2177
      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
  2178
        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
  2179
    qed (use Suc in auto)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2180
    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
  2181
      by blast
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2182
    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
  2183
      by metis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2184
    show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2185
    proof (cases "inj_on X f")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2186
      case False
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2187
      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
  2188
        unfolding inj_on_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2189
      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
  2190
      show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2191
        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
  2192
    next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2193
      case True
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2194
      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
  2195
        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
  2196
        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
  2197
        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
  2198
        by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2199
      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
  2200
        using mp(2) by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2201
      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
  2202
        unfolding subset_image_iff by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2203
      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
  2204
      then have f: "f = g \<union> h"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2205
        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
  2206
        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
  2207
        by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2208
      have *: "g \<inter> h = {}"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2209
        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
  2210
      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
  2211
        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
  2212
      then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2213
        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
  2214
    qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2215
  qed 
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2216
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2217
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2218
theorem Helly:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2219
  fixes f :: "'a::euclidean_space set set"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2220
  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
  2221
    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
  2222
  shows "\<Inter>f \<noteq> {}"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2223
  using Helly_induct assms by blast
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2224
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2225
subsection \<open>Epigraphs of convex functions\<close>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2226
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  2227
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
  2228
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2229
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
  2230
  unfolding epigraph_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2231
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2232
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
  2233
proof safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2234
  assume L: "convex (epigraph S f)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2235
  then show "convex_on S f"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2236
    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
  2237
  show "convex S"
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2238
    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
  2239
next
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2240
  assume "convex_on S f" "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2241
  then show "convex (epigraph S f)"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2242
    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
  2243
    apply safe
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2244
     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
  2245
      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
  2246
    done
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2247
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2248
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2249
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
  2250
  unfolding convex_epigraph by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2251
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2252
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
  2253
  by (simp add: convex_epigraph)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2254
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2255
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  2256
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
  2257
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2258
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2259
lemma convex_on:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2260
  assumes "convex S"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2261
  shows "convex_on S f \<longleftrightarrow>
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2262
    (\<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
  2263
      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
  2264
  (is "?lhs = (\<forall>k u x. ?rhs k u x)")
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2265
proof
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2266
  assume ?lhs 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2267
  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
  2268
    by (metis assms convex_epigraph epigraph_def)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2269
  show "\<forall>k u x. ?rhs k u x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2270
  proof (intro allI)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2271
    fix k u x
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2272
    show "?rhs k u x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2273
      using \<section>
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2274
      unfolding  convex mem_Collect_eq fst_sum snd_sum 
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2275
      apply safe
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2276
      apply (drule_tac x=k in spec)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2277
      apply (drule_tac x=u in spec)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2278
      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
  2279
      apply simp
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2280
      done
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2281
  qed
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2282
next
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2283
  assume "\<forall>k u x. ?rhs k u x"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2284
  then show ?lhs
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2285
  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
  2286
  using assms[unfolded convex] apply clarsimp
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2287
  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
  2288
  by (auto simp add: mult_left_mono intro: sum_mono)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2289
qed
69619
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
70136
f03a01a18c6e modernized tags: default scope excludes proof;
wenzelm
parents: 70097
diff changeset
  2292
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
  2293
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2294
lemma convex_on_convex_hull_bound:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2295
  assumes "convex_on (convex hull S) f"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2296
    and "\<forall>x\<in>S. f x \<le> b"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2297
  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
  2298
proof
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2299
  fix x
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2300
  assume "x \<in> convex hull S"
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2301
  then obtain k u v where
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2302
    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
  2303
    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
  2304
  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
  2305
    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
  2306
    unfolding sum_distrib_right[symmetric] u(2) mult_1
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2307
    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
  2308
  then show "f x \<le> b"
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2309
    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
  2310
    using hull_inc u by fastforce
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2311
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2312
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2313
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
  2314
  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
  2315
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2316
lemma convex_set_plus:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2317
  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
  2318
proof -
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2319
  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
  2320
    using assms by (rule convex_sums)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2321
  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
  2322
    unfolding set_plus_def by auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2323
  finally show "convex (S + T)" .
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2324
qed
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2325
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2326
lemma convex_set_sum:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2327
  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
  2328
  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
  2329
proof (cases "finite A")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2330
  case True then show ?thesis using assms
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2331
    by induct (auto simp: convex_set_plus)
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2332
qed auto
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2333
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2334
lemma finite_set_sum:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2335
  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
  2336
  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
  2337
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2338
lemma box_eq_set_sum_Basis:
72385
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2339
  "{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
  2340
proof -
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2341
  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
  2342
         \<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
  2343
    by (metis (mono_tags, lifting) euclidean_representation image_iff)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2344
  moreover
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2345
  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
  2346
  proof -
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2347
    have "(\<Sum>x\<in>Basis - {i}. f x \<bullet> i) = 0"
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2348
    proof (rule sum.neutral, intro strip)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2349
      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
  2350
        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
  2351
    qed
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2352
    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
  2353
      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
  2354
    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
  2355
      using f that(1) by auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2356
    then show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2357
      by (simp add: inner_sum_left)
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2358
  qed
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2359
  ultimately show ?thesis
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2360
    by (subst set_sum_alt [OF finite_Basis]) auto
4a2c0eb482aa Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 71244
diff changeset
  2361
qed
69619
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2362
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2363
lemma convex_hull_set_sum:
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2364
  "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
  2365
proof (cases "finite A")
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2366
  assume "finite A" then show ?thesis
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2367
    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
  2368
qed simp
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2369
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2370
3f7d8e05e0f2 split off Convex.thy: material that does not require Topology_Euclidean_Space
immler
parents:
diff changeset
  2371
end