src/HOL/Library/Convex.thy
author haftmann
Sat, 28 Jun 2014 09:16:42 +0200
changeset 57418 6ab1c7cb0b8d
parent 56796 9f84219715a7
child 57512 cc97b347b301
permissions -rw-r--r--
fact consolidation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36648
43b66dcd9266 Add Convex to Library build
hoelzl
parents: 36623
diff changeset
     1
(*  Title:      HOL/Library/Convex.thy
43b66dcd9266 Add Convex to Library build
hoelzl
parents: 36623
diff changeset
     2
    Author:     Armin Heller, TU Muenchen
43b66dcd9266 Add Convex to Library build
hoelzl
parents: 36623
diff changeset
     3
    Author:     Johannes Hoelzl, TU Muenchen
43b66dcd9266 Add Convex to Library build
hoelzl
parents: 36623
diff changeset
     4
*)
43b66dcd9266 Add Convex to Library build
hoelzl
parents: 36623
diff changeset
     5
43b66dcd9266 Add Convex to Library build
hoelzl
parents: 36623
diff changeset
     6
header {* Convexity in real vector spaces *}
43b66dcd9266 Add Convex to Library build
hoelzl
parents: 36623
diff changeset
     7
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
     8
theory Convex
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
     9
imports Product_Vector
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    10
begin
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    11
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    12
subsection {* Convexity. *}
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    13
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
    14
definition convex :: "'a::real_vector set \<Rightarrow> bool"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
    15
  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)"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    16
53676
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    17
lemma convexI:
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    18
  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"
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    19
  shows "convex s"
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    20
  using assms unfolding convex_def by fast
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    21
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    22
lemma convexD:
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    23
  assumes "convex s" and "x \<in> s" and "y \<in> s" and "0 \<le> u" and "0 \<le> v" and "u + v = 1"
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    24
  shows "u *\<^sub>R x + v *\<^sub>R y \<in> s"
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    25
  using assms unfolding convex_def by fast
476ef9b468d2 tuned proofs about 'convex'
huffman
parents: 53620
diff changeset
    26
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    27
lemma convex_alt:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    28
  "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)"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    29
  (is "_ \<longleftrightarrow> ?alt")
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    30
proof
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    31
  assume alt[rule_format]: ?alt
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    32
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    33
    fix x y and u v :: real
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    34
    assume mem: "x \<in> s" "y \<in> s"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
    35
    assume "0 \<le> u" "0 \<le> v"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    36
    moreover
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    37
    assume "u + v = 1"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    38
    then have "u = 1 - v" by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    39
    ultimately have "u *\<^sub>R x + v *\<^sub>R y \<in> s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    40
      using alt[OF mem] by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    41
  }
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    42
  then show "convex s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    43
    unfolding convex_def by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    44
qed (auto simp: convex_def)
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    45
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    46
lemma mem_convex:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    47
  assumes "convex s" "a \<in> s" "b \<in> s" "0 \<le> u" "u \<le> 1"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    48
  shows "((1 - u) *\<^sub>R a + u *\<^sub>R b) \<in> s"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    49
  using assms unfolding convex_alt by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    50
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    51
lemma convex_empty[intro]: "convex {}"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    52
  unfolding convex_def by simp
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    53
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    54
lemma convex_singleton[intro]: "convex {a}"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    55
  unfolding convex_def by (auto simp: scaleR_left_distrib[symmetric])
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    56
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    57
lemma convex_UNIV[intro]: "convex UNIV"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    58
  unfolding convex_def by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    59
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    60
lemma convex_Inter: "(\<forall>s\<in>f. convex s) \<Longrightarrow> convex(\<Inter> f)"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    61
  unfolding convex_def by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    62
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    63
lemma convex_Int: "convex s \<Longrightarrow> convex t \<Longrightarrow> convex (s \<inter> t)"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    64
  unfolding convex_def by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    65
53596
d29d63460d84 new lemmas
huffman
parents: 51642
diff changeset
    66
lemma convex_INT: "\<forall>i\<in>A. convex (B i) \<Longrightarrow> convex (\<Inter>i\<in>A. B i)"
d29d63460d84 new lemmas
huffman
parents: 51642
diff changeset
    67
  unfolding convex_def by auto
d29d63460d84 new lemmas
huffman
parents: 51642
diff changeset
    68
d29d63460d84 new lemmas
huffman
parents: 51642
diff changeset
    69
lemma convex_Times: "convex s \<Longrightarrow> convex t \<Longrightarrow> convex (s \<times> t)"
d29d63460d84 new lemmas
huffman
parents: 51642
diff changeset
    70
  unfolding convex_def by auto
d29d63460d84 new lemmas
huffman
parents: 51642
diff changeset
    71
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    72
lemma convex_halfspace_le: "convex {x. inner a x \<le> b}"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    73
  unfolding convex_def
44142
8e27e0177518 avoid warnings about duplicate rules
huffman
parents: 43337
diff changeset
    74
  by (auto simp: inner_add intro!: convex_bound_le)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    75
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    76
lemma convex_halfspace_ge: "convex {x. inner a x \<ge> b}"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    77
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    78
  have *: "{x. inner a x \<ge> b} = {x. inner (-a) x \<le> -b}"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    79
    by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    80
  show ?thesis
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    81
    unfolding * using convex_halfspace_le[of "-a" "-b"] by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    82
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    83
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    84
lemma convex_hyperplane: "convex {x. inner a x = b}"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
    85
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    86
  have *: "{x. inner a x = b} = {x. inner a x \<le> b} \<inter> {x. inner a x \<ge> b}"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
    87
    by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    88
  show ?thesis using convex_halfspace_le convex_halfspace_ge
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    89
    by (auto intro!: convex_Int simp: *)
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    90
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    91
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    92
lemma convex_halfspace_lt: "convex {x. inner a x < b}"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    93
  unfolding convex_def
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    94
  by (auto simp: convex_bound_lt inner_add)
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    95
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    96
lemma convex_halfspace_gt: "convex {x. inner a x > b}"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    97
   using convex_halfspace_lt[of "-a" "-b"] by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    98
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
    99
lemma convex_real_interval:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   100
  fixes a b :: "real"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   101
  shows "convex {a..}" and "convex {..b}"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   102
    and "convex {a<..}" and "convex {..<b}"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   103
    and "convex {a..b}" and "convex {a<..b}"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   104
    and "convex {a..<b}" and "convex {a<..<b}"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   105
proof -
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   106
  have "{a..} = {x. a \<le> inner 1 x}" by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   107
  then show 1: "convex {a..}" by (simp only: convex_halfspace_ge)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   108
  have "{..b} = {x. inner 1 x \<le> b}" by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   109
  then show 2: "convex {..b}" by (simp only: convex_halfspace_le)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   110
  have "{a<..} = {x. a < inner 1 x}" by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   111
  then show 3: "convex {a<..}" by (simp only: convex_halfspace_gt)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   112
  have "{..<b} = {x. inner 1 x < b}" by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   113
  then show 4: "convex {..<b}" by (simp only: convex_halfspace_lt)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   114
  have "{a..b} = {a..} \<inter> {..b}" by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   115
  then show "convex {a..b}" by (simp only: convex_Int 1 2)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   116
  have "{a<..b} = {a<..} \<inter> {..b}" by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   117
  then show "convex {a<..b}" by (simp only: convex_Int 3 2)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   118
  have "{a..<b} = {a..} \<inter> {..<b}" by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   119
  then show "convex {a..<b}" by (simp only: convex_Int 1 4)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   120
  have "{a<..<b} = {a<..} \<inter> {..<b}" by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   121
  then show "convex {a<..<b}" by (simp only: convex_Int 3 4)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   122
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   123
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   124
subsection {* Explicit expressions for convexity in terms of arbitrary sums. *}
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   125
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   126
lemma convex_setsum:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   127
  fixes C :: "'a::real_vector set"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   128
  assumes "finite s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   129
    and "convex C"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   130
    and "(\<Sum> i \<in> s. a i) = 1"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   131
  assumes "\<And>i. i \<in> s \<Longrightarrow> a i \<ge> 0"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   132
    and "\<And>i. i \<in> s \<Longrightarrow> y i \<in> C"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   133
  shows "(\<Sum> j \<in> s. a j *\<^sub>R y j) \<in> C"
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   134
  using assms(1,3,4,5)
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   135
proof (induct arbitrary: a set: finite)
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   136
  case empty
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   137
  then show ?case by simp
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   138
next
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   139
  case (insert i s) note IH = this(3)
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   140
  have "a i + setsum a s = 1"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   141
    and "0 \<le> a i"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   142
    and "\<forall>j\<in>s. 0 \<le> a j"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   143
    and "y i \<in> C"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   144
    and "\<forall>j\<in>s. y j \<in> C"
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   145
    using insert.hyps(1,2) insert.prems by simp_all
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   146
  then have "0 \<le> setsum a s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   147
    by (simp add: setsum_nonneg)
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   148
  have "a i *\<^sub>R y i + (\<Sum>j\<in>s. a j *\<^sub>R y j) \<in> C"
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   149
  proof (cases)
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   150
    assume z: "setsum a s = 0"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   151
    with `a i + setsum a s = 1` have "a i = 1"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   152
      by simp
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   153
    from setsum_nonneg_0 [OF `finite s` _ z] `\<forall>j\<in>s. 0 \<le> a j` have "\<forall>j\<in>s. a j = 0"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   154
      by simp
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   155
    show ?thesis using `a i = 1` and `\<forall>j\<in>s. a j = 0` and `y i \<in> C`
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   156
      by simp
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   157
  next
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   158
    assume nz: "setsum a s \<noteq> 0"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   159
    with `0 \<le> setsum a s` have "0 < setsum a s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   160
      by simp
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   161
    then have "(\<Sum>j\<in>s. (a j / setsum a s) *\<^sub>R y j) \<in> C"
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   162
      using `\<forall>j\<in>s. 0 \<le> a j` and `\<forall>j\<in>s. y j \<in> C`
56571
f4635657d66f added divide_nonneg_nonneg and co; made it a simp rule
hoelzl
parents: 56544
diff changeset
   163
      by (simp add: IH setsum_divide_distrib [symmetric])
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   164
    from `convex C` and `y i \<in> C` and this and `0 \<le> a i`
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   165
      and `0 \<le> setsum a s` and `a i + setsum a s = 1`
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   166
    have "a i *\<^sub>R y i + setsum a s *\<^sub>R (\<Sum>j\<in>s. (a j / setsum a s) *\<^sub>R y j) \<in> C"
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   167
      by (rule convexD)
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   168
    then show ?thesis
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   169
      by (simp add: scaleR_setsum_right nz)
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   170
  qed
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   171
  then show ?case using `finite s` and `i \<notin> s`
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   172
    by simp
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   173
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   174
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   175
lemma convex:
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   176
  "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> (setsum u {1..k} = 1)
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   177
      \<longrightarrow> setsum (\<lambda>i. u i *\<^sub>R x i) {1..k} \<in> s)"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   178
proof safe
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   179
  fix k :: nat
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   180
  fix u :: "nat \<Rightarrow> real"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   181
  fix x
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   182
  assume "convex s"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   183
    "\<forall>i. 1 \<le> i \<and> i \<le> k \<longrightarrow> 0 \<le> u i \<and> x i \<in> s"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   184
    "setsum u {1..k} = 1"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   185
  from this convex_setsum[of "{1 .. k}" s]
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   186
  show "(\<Sum>j\<in>{1 .. k}. u j *\<^sub>R x j) \<in> s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   187
    by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   188
next
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   189
  assume asm: "\<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> setsum u {1..k} = 1
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   190
    \<longrightarrow> (\<Sum>i = 1..k. u i *\<^sub>R (x i :: 'a)) \<in> s"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   191
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   192
    fix \<mu> :: real
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   193
    fix x y :: 'a
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   194
    assume xy: "x \<in> s" "y \<in> s"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   195
    assume mu: "\<mu> \<ge> 0" "\<mu> \<le> 1"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   196
    let ?u = "\<lambda>i. if (i :: nat) = 1 then \<mu> else 1 - \<mu>"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   197
    let ?x = "\<lambda>i. if (i :: nat) = 1 then x else y"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   198
    have "{1 :: nat .. 2} \<inter> - {x. x = 1} = {2}"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   199
      by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   200
    then have card: "card ({1 :: nat .. 2} \<inter> - {x. x = 1}) = 1"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   201
      by simp
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   202
    then have "setsum ?u {1 .. 2} = 1"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 56796
diff changeset
   203
      using setsum.If_cases[of "{(1 :: nat) .. 2}" "\<lambda> x. x = 1" "\<lambda> x. \<mu>" "\<lambda> x. 1 - \<mu>"]
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   204
      by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   205
    with asm[rule_format, of "2" ?u ?x] have s: "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) \<in> s"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   206
      using mu xy by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   207
    have grarr: "(\<Sum>j \<in> {Suc (Suc 0)..2}. ?u j *\<^sub>R ?x j) = (1 - \<mu>) *\<^sub>R y"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   208
      using setsum_head_Suc[of "Suc (Suc 0)" 2 "\<lambda> j. (1 - \<mu>) *\<^sub>R y"] by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   209
    from setsum_head_Suc[of "Suc 0" 2 "\<lambda> j. ?u j *\<^sub>R ?x j", simplified this]
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   210
    have "(\<Sum>j \<in> {1..2}. ?u j *\<^sub>R ?x j) = \<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   211
      by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   212
    then have "(1 - \<mu>) *\<^sub>R y + \<mu> *\<^sub>R x \<in> s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   213
      using s by (auto simp:add_commute)
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   214
  }
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   215
  then show "convex s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   216
    unfolding convex_alt by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   217
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   218
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   219
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   220
lemma convex_explicit:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   221
  fixes s :: "'a::real_vector set"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   222
  shows "convex s \<longleftrightarrow>
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   223
    (\<forall>t u. finite t \<and> t \<subseteq> s \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and> setsum u t = 1 \<longrightarrow> setsum (\<lambda>x. u x *\<^sub>R x) t \<in> s)"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   224
proof safe
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   225
  fix t
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   226
  fix u :: "'a \<Rightarrow> real"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   227
  assume "convex s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   228
    and "finite t"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   229
    and "t \<subseteq> s" "\<forall>x\<in>t. 0 \<le> u x" "setsum u t = 1"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   230
  then show "(\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   231
    using convex_setsum[of t s u "\<lambda> x. x"] by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   232
next
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   233
  assume asm0: "\<forall>t. \<forall> u. finite t \<and> t \<subseteq> s \<and> (\<forall>x\<in>t. 0 \<le> u x) \<and>
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   234
    setsum u t = 1 \<longrightarrow> (\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   235
  show "convex s"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   236
    unfolding convex_alt
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   237
  proof safe
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   238
    fix x y
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   239
    fix \<mu> :: real
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   240
    assume asm: "x \<in> s" "y \<in> s" "0 \<le> \<mu>" "\<mu> \<le> 1"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   241
    {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   242
      assume "x \<noteq> y"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   243
      then have "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   244
        using asm0[rule_format, of "{x, y}" "\<lambda> z. if z = x then 1 - \<mu> else \<mu>"]
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   245
          asm by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   246
    }
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   247
    moreover
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   248
    {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   249
      assume "x = y"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   250
      then have "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   251
        using asm0[rule_format, of "{x, y}" "\<lambda> z. 1"]
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   252
          asm by (auto simp: field_simps real_vector.scale_left_diff_distrib)
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   253
    }
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   254
    ultimately show "(1 - \<mu>) *\<^sub>R x + \<mu> *\<^sub>R y \<in> s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   255
      by blast
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   256
  qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   257
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   258
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   259
lemma convex_finite:
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   260
  assumes "finite s"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   261
  shows "convex s \<longleftrightarrow> (\<forall>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<longrightarrow> setsum (\<lambda>x. u x *\<^sub>R x) s \<in> s)"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   262
  unfolding convex_explicit
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   263
proof safe
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   264
  fix t u
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   265
  assume sum: "\<forall>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<longrightarrow> (\<Sum>x\<in>s. u x *\<^sub>R x) \<in> s"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   266
    and as: "finite t" "t \<subseteq> s" "\<forall>x\<in>t. 0 \<le> u x" "setsum u t = (1::real)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   267
  have *: "s \<inter> t = t"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   268
    using as(2) by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   269
  have if_distrib_arg: "\<And>P f g x. (if P then f else g) x = (if P then f x else g x)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   270
    by simp
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   271
  show "(\<Sum>x\<in>t. u x *\<^sub>R x) \<in> s"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   272
   using sum[THEN spec[where x="\<lambda>x. if x\<in>t then u x else 0"]] as *
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 56796
diff changeset
   273
   by (auto simp: assms setsum.If_cases if_distrib if_distrib_arg)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   274
qed (erule_tac x=s in allE, erule_tac x=u in allE, auto)
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   275
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   276
55909
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   277
subsection {* Functions that are convex on a set *}
df6133adb63f tuned proof script
huffman
parents: 54230
diff changeset
   278
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   279
definition convex_on :: "'a::real_vector set \<Rightarrow> ('a \<Rightarrow> real) \<Rightarrow> bool"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   280
  where "convex_on s f \<longleftrightarrow>
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   281
    (\<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)"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   282
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   283
lemma convex_on_subset: "convex_on t f \<Longrightarrow> s \<subseteq> t \<Longrightarrow> convex_on s f"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   284
  unfolding convex_on_def by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   285
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   286
lemma convex_on_add [intro]:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   287
  assumes "convex_on s f"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   288
    and "convex_on s g"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   289
  shows "convex_on s (\<lambda>x. f x + g x)"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   290
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   291
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   292
    fix x y
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   293
    assume "x \<in> s" "y \<in> s"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   294
    moreover
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   295
    fix u v :: real
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   296
    assume "0 \<le> u" "0 \<le> v" "u + v = 1"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   297
    ultimately
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   298
    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)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   299
      using assms unfolding convex_on_def by (auto simp add: add_mono)
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   300
    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)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   301
      by (simp add: field_simps)
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   302
  }
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   303
  then show ?thesis
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   304
    unfolding convex_on_def by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   305
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   306
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   307
lemma convex_on_cmul [intro]:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   308
  fixes c :: real
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   309
  assumes "0 \<le> c"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   310
    and "convex_on s f"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   311
  shows "convex_on s (\<lambda>x. c * f x)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   312
proof -
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   313
  have *: "\<And>u c fx v fy ::real. u * (c * fx) + v * (c * fy) = c * (u * fx + v * fy)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   314
    by (simp add: field_simps)
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   315
  show ?thesis using assms(2) and mult_left_mono [OF _ assms(1)]
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   316
    unfolding convex_on_def and * by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   317
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   318
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   319
lemma convex_lower:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   320
  assumes "convex_on s f"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   321
    and "x \<in> s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   322
    and "y \<in> s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   323
    and "0 \<le> u"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   324
    and "0 \<le> v"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   325
    and "u + v = 1"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   326
  shows "f (u *\<^sub>R x + v *\<^sub>R y) \<le> max (f x) (f y)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   327
proof -
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   328
  let ?m = "max (f x) (f y)"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   329
  have "u * f x + v * f y \<le> u * max (f x) (f y) + v * max (f x) (f y)"
38642
8fa437809c67 dropped type classes mult_mono and mult_mono1; tuned names of technical rule duplicates
haftmann
parents: 36778
diff changeset
   330
    using assms(4,5) by (auto simp add: mult_left_mono add_mono)
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   331
  also have "\<dots> = max (f x) (f y)"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   332
    using assms(6) unfolding distrib[symmetric] by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   333
  finally show ?thesis
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44282
diff changeset
   334
    using assms unfolding convex_on_def by fastforce
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   335
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   336
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   337
lemma convex_on_dist [intro]:
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   338
  fixes s :: "'a::real_normed_vector set"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   339
  shows "convex_on s (\<lambda>x. dist a x)"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   340
proof (auto simp add: convex_on_def dist_norm)
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   341
  fix x y
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   342
  assume "x \<in> s" "y \<in> s"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   343
  fix u v :: real
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   344
  assume "0 \<le> u"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   345
  assume "0 \<le> v"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   346
  assume "u + v = 1"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   347
  have "a = u *\<^sub>R a + v *\<^sub>R a"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   348
    unfolding scaleR_left_distrib[symmetric] and `u + v = 1` by simp
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   349
  then have *: "a - (u *\<^sub>R x + v *\<^sub>R y) = (u *\<^sub>R (a - x)) + (v *\<^sub>R (a - y))"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   350
    by (auto simp add: algebra_simps)
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   351
  show "norm (a - (u *\<^sub>R x + v *\<^sub>R y)) \<le> u * norm (a - x) + v * norm (a - y)"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   352
    unfolding * using norm_triangle_ineq[of "u *\<^sub>R (a - x)" "v *\<^sub>R (a - y)"]
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   353
    using `0 \<le> u` `0 \<le> v` by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   354
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   355
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   356
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   357
subsection {* Arithmetic operations on sets preserve convexity. *}
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   358
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   359
lemma convex_linear_image:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   360
  assumes "linear f"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   361
    and "convex s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   362
  shows "convex (f ` s)"
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   363
proof -
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   364
  interpret f: linear f by fact
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   365
  from `convex s` show "convex (f ` s)"
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   366
    by (simp add: convex_def f.scaleR [symmetric] f.add [symmetric])
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   367
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   368
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   369
lemma convex_linear_vimage:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   370
  assumes "linear f"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   371
    and "convex s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   372
  shows "convex (f -` s)"
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   373
proof -
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   374
  interpret f: linear f by fact
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   375
  from `convex s` show "convex (f -` s)"
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   376
    by (simp add: convex_def f.add f.scaleR)
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   377
qed
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   378
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   379
lemma convex_scaling:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   380
  assumes "convex s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   381
  shows "convex ((\<lambda>x. c *\<^sub>R x) ` s)"
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   382
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   383
  have "linear (\<lambda>x. c *\<^sub>R x)"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   384
    by (simp add: linearI scaleR_add_right)
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   385
  then show ?thesis
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   386
    using `convex s` by (rule convex_linear_image)
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   387
qed
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   388
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   389
lemma convex_negations:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   390
  assumes "convex s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   391
  shows "convex ((\<lambda>x. - x) ` s)"
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   392
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   393
  have "linear (\<lambda>x. - x)"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   394
    by (simp add: linearI)
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   395
  then show ?thesis
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   396
    using `convex s` by (rule convex_linear_image)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   397
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   398
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   399
lemma convex_sums:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   400
  assumes "convex s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   401
    and "convex t"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   402
  shows "convex {x + y| x y. x \<in> s \<and> y \<in> t}"
53620
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   403
proof -
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   404
  have "linear (\<lambda>(x, y). x + y)"
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   405
    by (auto intro: linearI simp add: scaleR_add_right)
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   406
  with assms have "convex ((\<lambda>(x, y). x + y) ` (s \<times> t))"
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   407
    by (intro convex_linear_image convex_Times)
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   408
  also have "((\<lambda>(x, y). x + y) ` (s \<times> t)) = {x + y| x y. x \<in> s \<and> y \<in> t}"
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   409
    by auto
3c7f5e7926dc generalized and simplified proofs of several theorems about convex sets
huffman
parents: 53596
diff changeset
   410
  finally show ?thesis .
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   411
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   412
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   413
lemma convex_differences:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   414
  assumes "convex s" "convex t"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   415
  shows "convex {x - y| x y. x \<in> s \<and> y \<in> t}"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   416
proof -
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   417
  have "{x - y| x y. x \<in> s \<and> y \<in> t} = {x + y |x y. x \<in> s \<and> y \<in> uminus ` t}"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53676
diff changeset
   418
    by (auto simp add: diff_conv_add_uminus simp del: add_uminus_conv_diff)
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   419
  then show ?thesis
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   420
    using convex_sums[OF assms(1) convex_negations[OF assms(2)]] by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   421
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   422
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   423
lemma convex_translation:
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   424
  assumes "convex s"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   425
  shows "convex ((\<lambda>x. a + x) ` s)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   426
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   427
  have "{a + y |y. y \<in> s} = (\<lambda>x. a + x) ` s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   428
    by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   429
  then show ?thesis
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   430
    using convex_sums[OF convex_singleton[of a] assms] by auto
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   431
qed
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   432
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   433
lemma convex_affinity:
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   434
  assumes "convex s"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   435
  shows "convex ((\<lambda>x. a + c *\<^sub>R x) ` s)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   436
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   437
  have "(\<lambda>x. a + c *\<^sub>R x) ` s = op + a ` op *\<^sub>R c ` s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   438
    by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   439
  then show ?thesis
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   440
    using convex_translation[OF convex_scaling[OF assms], of a c] by auto
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   441
qed
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   442
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   443
lemma pos_is_convex: "convex {0 :: real <..}"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   444
  unfolding convex_alt
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   445
proof safe
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   446
  fix y x \<mu> :: real
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   447
  assume asms: "y > 0" "x > 0" "\<mu> \<ge> 0" "\<mu> \<le> 1"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   448
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   449
    assume "\<mu> = 0"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   450
    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y = y" by simp
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   451
    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using asms by simp
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   452
  }
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   453
  moreover
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   454
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   455
    assume "\<mu> = 1"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   456
    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using asms by simp
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   457
  }
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   458
  moreover
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   459
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   460
    assume "\<mu> \<noteq> 1" "\<mu> \<noteq> 0"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   461
    then have "\<mu> > 0" "(1 - \<mu>) > 0" using asms by auto
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   462
    then have "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y > 0" using asms
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   463
      by (auto simp add: add_pos_pos)
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   464
  }
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   465
  ultimately show "(1 - \<mu>) *\<^sub>R y + \<mu> *\<^sub>R x > 0"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   466
    using assms by fastforce
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   467
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   468
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   469
lemma convex_on_setsum:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   470
  fixes a :: "'a \<Rightarrow> real"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   471
    and y :: "'a \<Rightarrow> 'b::real_vector"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   472
    and f :: "'b \<Rightarrow> real"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   473
  assumes "finite s" "s \<noteq> {}"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   474
    and "convex_on C f"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   475
    and "convex C"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   476
    and "(\<Sum> i \<in> s. a i) = 1"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   477
    and "\<And>i. i \<in> s \<Longrightarrow> a i \<ge> 0"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   478
    and "\<And>i. i \<in> s \<Longrightarrow> y i \<in> C"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   479
  shows "f (\<Sum> i \<in> s. a i *\<^sub>R y i) \<le> (\<Sum> i \<in> s. a i * f (y i))"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   480
  using assms
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   481
proof (induct s arbitrary: a rule: finite_ne_induct)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   482
  case (singleton i)
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   483
  then have ai: "a i = 1" by auto
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   484
  then show ?case by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   485
next
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   486
  case (insert i s) note asms = this
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   487
  then have "convex_on C f" by simp
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   488
  from this[unfolded convex_on_def, rule_format]
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   489
  have conv: "\<And>x y \<mu>. x \<in> C \<Longrightarrow> y \<in> C \<Longrightarrow> 0 \<le> \<mu> \<Longrightarrow> \<mu> \<le> 1 \<Longrightarrow>
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   490
      f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   491
    by simp
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   492
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   493
    assume "a i = 1"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   494
    then have "(\<Sum> j \<in> s. a j) = 0"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   495
      using asms by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   496
    then have "\<And>j. j \<in> s \<Longrightarrow> a j = 0"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44282
diff changeset
   497
      using setsum_nonneg_0[where 'b=real] asms by fastforce
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   498
    then have ?case using asms by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   499
  }
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   500
  moreover
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   501
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   502
    assume asm: "a i \<noteq> 1"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   503
    from asms have yai: "y i \<in> C" "a i \<ge> 0" by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   504
    have fis: "finite (insert i s)" using asms by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   505
    then have ai1: "a i \<le> 1" using setsum_nonneg_leq_bound[of "insert i s" a] asms by simp
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   506
    then have "a i < 1" using asm by auto
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   507
    then have i0: "1 - a i > 0" by auto
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   508
    let ?a = "\<lambda>j. a j / (1 - a i)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   509
    {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   510
      fix j
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   511
      assume "j \<in> s"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   512
      with i0 asms have "?a j \<ge> 0"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   513
        by fastforce
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   514
    }
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   515
    note a_nonneg = this
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   516
    have "(\<Sum> j \<in> insert i s. a j) = 1" using asms by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   517
    then have "(\<Sum> j \<in> s. a j) = 1 - a i" using setsum.insert asms by fastforce
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   518
    then have "(\<Sum> j \<in> s. a j) / (1 - a i) = 1" using i0 by auto
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   519
    then have a1: "(\<Sum> j \<in> s. ?a j) = 1" unfolding setsum_divide_distrib by simp
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   520
    have "convex C" using asms by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   521
    then have asum: "(\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<in> C"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   522
      using asms convex_setsum[OF `finite s`
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   523
        `convex C` a1 a_nonneg] by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   524
    have asum_le: "f (\<Sum> j \<in> s. ?a j *\<^sub>R y j) \<le> (\<Sum> j \<in> s. ?a j * f (y j))"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   525
      using a_nonneg a1 asms by blast
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   526
    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)"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   527
      using setsum.insert[of s i "\<lambda> j. a j *\<^sub>R y j", OF `finite s` `i \<notin> s`] asms
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   528
      by (auto simp only:add_commute)
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   529
    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)"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   530
      using i0 by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   531
    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)"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   532
      using scaleR_right.setsum[of "inverse (1 - a i)" "\<lambda> j. a j *\<^sub>R y j" s, symmetric]
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   533
      by (auto simp:algebra_simps)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   534
    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)"
36778
739a9379e29b avoid using real-specific versions of generic lemmas
huffman
parents: 36648
diff changeset
   535
      by (auto simp: divide_inverse)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   536
    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)"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   537
      using conv[of "y i" "(\<Sum> j \<in> s. ?a j *\<^sub>R y j)" "a i", OF yai(1) asum yai(2) ai1]
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   538
      by (auto simp add:add_commute)
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   539
    also have "\<dots> \<le> (1 - a i) * (\<Sum> j \<in> s. ?a j * f (y j)) + a i * f (y i)"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   540
      using add_right_mono[OF mult_left_mono[of _ _ "1 - a i",
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   541
        OF asum_le less_imp_le[OF i0]], of "a i * f (y i)"] by simp
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   542
    also have "\<dots> = (\<Sum> j \<in> s. (1 - a i) * ?a j * f (y j)) + a i * f (y i)"
44282
f0de18b62d63 remove bounded_(bi)linear locale interpretations, to avoid duplicating so many lemmas
huffman
parents: 44142
diff changeset
   543
      unfolding setsum_right_distrib[of "1 - a i" "\<lambda> j. ?a j * f (y j)"] using i0 by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   544
    also have "\<dots> = (\<Sum> j \<in> s. a j * f (y j)) + a i * f (y i)" using i0 by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   545
    also have "\<dots> = (\<Sum> j \<in> insert i s. a j * f (y j))" using asms by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   546
    finally have "f (\<Sum> j \<in> insert i s. a j *\<^sub>R y j) \<le> (\<Sum> j \<in> insert i s. a j * f (y j))"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   547
      by simp
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   548
  }
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   549
  ultimately show ?case by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   550
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   551
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   552
lemma convex_on_alt:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   553
  fixes C :: "'a::real_vector set"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   554
  assumes "convex C"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   555
  shows "convex_on C f \<longleftrightarrow>
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   556
    (\<forall>x \<in> C. \<forall> y \<in> C. \<forall> \<mu> :: real. \<mu> \<ge> 0 \<and> \<mu> \<le> 1 \<longrightarrow>
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   557
      f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y)"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   558
proof safe
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   559
  fix x y
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   560
  fix \<mu> :: real
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   561
  assume asms: "convex_on C f" "x \<in> C" "y \<in> C" "0 \<le> \<mu>" "\<mu> \<le> 1"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   562
  from this[unfolded convex_on_def, rule_format]
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   563
  have "\<And>u v. 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"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   564
    by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   565
  from this[of "\<mu>" "1 - \<mu>", simplified] asms
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   566
  show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   567
    by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   568
next
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   569
  assume asm: "\<forall>x\<in>C. \<forall>y\<in>C. \<forall>\<mu>. 0 \<le> \<mu> \<and> \<mu> \<le> 1 \<longrightarrow>
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   570
    f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   571
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   572
    fix x y
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   573
    fix u v :: real
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   574
    assume lasm: "x \<in> C" "y \<in> C" "u \<ge> 0" "v \<ge> 0" "u + v = 1"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   575
    then have[simp]: "1 - u = v" by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   576
    from asm[rule_format, of x y u]
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   577
    have "f (u *\<^sub>R x + v *\<^sub>R y) \<le> u * f x + v * f y"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   578
      using lasm by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   579
  }
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   580
  then show "convex_on C f"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   581
    unfolding convex_on_def by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   582
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   583
43337
57a1c19f8e3b lemma about differences of convex functions
hoelzl
parents: 38642
diff changeset
   584
lemma convex_on_diff:
57a1c19f8e3b lemma about differences of convex functions
hoelzl
parents: 38642
diff changeset
   585
  fixes f :: "real \<Rightarrow> real"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   586
  assumes f: "convex_on I f"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   587
    and I: "x \<in> I" "y \<in> I"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   588
    and t: "x < t" "t < y"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   589
  shows "(f x - f t) / (x - t) \<le> (f x - f y) / (x - y)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   590
    and "(f x - f y) / (x - y) \<le> (f t - f y) / (t - y)"
43337
57a1c19f8e3b lemma about differences of convex functions
hoelzl
parents: 38642
diff changeset
   591
proof -
57a1c19f8e3b lemma about differences of convex functions
hoelzl
parents: 38642
diff changeset
   592
  def a \<equiv> "(t - y) / (x - y)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   593
  with t have "0 \<le> a" "0 \<le> 1 - a"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   594
    by (auto simp: field_simps)
43337
57a1c19f8e3b lemma about differences of convex functions
hoelzl
parents: 38642
diff changeset
   595
  with f `x \<in> I` `y \<in> I` have cvx: "f (a * x + (1 - a) * y) \<le> a * f x + (1 - a) * f y"
57a1c19f8e3b lemma about differences of convex functions
hoelzl
parents: 38642
diff changeset
   596
    by (auto simp: convex_on_def)
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   597
  have "a * x + (1 - a) * y = a * (x - y) + y"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   598
    by (simp add: field_simps)
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   599
  also have "\<dots> = t"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   600
    unfolding a_def using `x < t` `t < y` by simp
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   601
  finally have "f t \<le> a * f x + (1 - a) * f y"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   602
    using cvx by simp
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   603
  also have "\<dots> = a * (f x - f y) + f y"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   604
    by (simp add: field_simps)
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   605
  finally have "f t - f y \<le> a * (f x - f y)"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   606
    by simp
43337
57a1c19f8e3b lemma about differences of convex functions
hoelzl
parents: 38642
diff changeset
   607
  with t show "(f x - f t) / (x - t) \<le> (f x - f y) / (x - y)"
44142
8e27e0177518 avoid warnings about duplicate rules
huffman
parents: 43337
diff changeset
   608
    by (simp add: le_divide_eq divide_le_eq field_simps a_def)
43337
57a1c19f8e3b lemma about differences of convex functions
hoelzl
parents: 38642
diff changeset
   609
  with t show "(f x - f y) / (x - y) \<le> (f t - f y) / (t - y)"
44142
8e27e0177518 avoid warnings about duplicate rules
huffman
parents: 43337
diff changeset
   610
    by (simp add: le_divide_eq divide_le_eq field_simps)
43337
57a1c19f8e3b lemma about differences of convex functions
hoelzl
parents: 38642
diff changeset
   611
qed
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   612
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   613
lemma pos_convex_function:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   614
  fixes f :: "real \<Rightarrow> real"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   615
  assumes "convex C"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   616
    and leq: "\<And>x y. x \<in> C \<Longrightarrow> y \<in> C \<Longrightarrow> f' x * (y - x) \<le> f y - f x"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   617
  shows "convex_on C f"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   618
  unfolding convex_on_alt[OF assms(1)]
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   619
  using assms
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   620
proof safe
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   621
  fix x y \<mu> :: real
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   622
  let ?x = "\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   623
  assume asm: "convex C" "x \<in> C" "y \<in> C" "\<mu> \<ge> 0" "\<mu> \<le> 1"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   624
  then have "1 - \<mu> \<ge> 0" by auto
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   625
  then have xpos: "?x \<in> C"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   626
    using asm unfolding convex_alt by fastforce
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   627
  have geq: "\<mu> * (f x - f ?x) + (1 - \<mu>) * (f y - f ?x) \<ge>
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   628
      \<mu> * f' ?x * (x - ?x) + (1 - \<mu>) * f' ?x * (y - ?x)"
38642
8fa437809c67 dropped type classes mult_mono and mult_mono1; tuned names of technical rule duplicates
haftmann
parents: 36778
diff changeset
   629
    using add_mono[OF mult_left_mono[OF leq[OF xpos asm(2)] `\<mu> \<ge> 0`]
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   630
      mult_left_mono[OF leq[OF xpos asm(3)] `1 - \<mu> \<ge> 0`]]
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   631
    by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   632
  then have "\<mu> * f x + (1 - \<mu>) * f y - f ?x \<ge> 0"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   633
    by (auto simp add: field_simps)
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   634
  then show "f (\<mu> *\<^sub>R x + (1 - \<mu>) *\<^sub>R y) \<le> \<mu> * f x + (1 - \<mu>) * f y"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   635
    using convex_on_alt by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   636
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   637
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   638
lemma atMostAtLeast_subset_convex:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   639
  fixes C :: "real set"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   640
  assumes "convex C"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   641
    and "x \<in> C" "y \<in> C" "x < y"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   642
  shows "{x .. y} \<subseteq> C"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   643
proof safe
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   644
  fix z assume zasm: "z \<in> {x .. y}"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   645
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   646
    assume asm: "x < z" "z < y"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   647
    let ?\<mu> = "(y - z) / (y - x)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   648
    have "0 \<le> ?\<mu>" "?\<mu> \<le> 1"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   649
      using assms asm by (auto simp add: field_simps)
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   650
    then have comb: "?\<mu> * x + (1 - ?\<mu>) * y \<in> C"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   651
      using assms iffD1[OF convex_alt, rule_format, of C y x ?\<mu>]
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   652
      by (simp add: algebra_simps)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   653
    have "?\<mu> * x + (1 - ?\<mu>) * y = (y - z) * x / (y - x) + (1 - (y - z) / (y - x)) * y"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   654
      by (auto simp add: field_simps)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   655
    also have "\<dots> = ((y - z) * x + (y - x - (y - z)) * y) / (y - x)"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   656
      using assms unfolding add_divide_distrib by (auto simp: field_simps)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   657
    also have "\<dots> = z"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   658
      using assms by (auto simp: field_simps)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   659
    finally have "z \<in> C"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   660
      using comb by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   661
  }
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   662
  note less = this
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   663
  show "z \<in> C" using zasm less assms
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   664
    unfolding atLeastAtMost_iff le_less by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   665
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   666
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   667
lemma f''_imp_f':
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   668
  fixes f :: "real \<Rightarrow> real"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   669
  assumes "convex C"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   670
    and f': "\<And>x. x \<in> C \<Longrightarrow> DERIV f x :> (f' x)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   671
    and f'': "\<And>x. x \<in> C \<Longrightarrow> DERIV f' x :> (f'' x)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   672
    and pos: "\<And>x. x \<in> C \<Longrightarrow> f'' x \<ge> 0"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   673
    and "x \<in> C" "y \<in> C"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   674
  shows "f' x * (y - x) \<le> f y - f x"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   675
  using assms
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   676
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   677
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   678
    fix x y :: real
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   679
    assume asm: "x \<in> C" "y \<in> C" "y > x"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   680
    then have ge: "y - x > 0" "y - x \<ge> 0" by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   681
    from asm have le: "x - y < 0" "x - y \<le> 0" by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   682
    then obtain z1 where z1: "z1 > x" "z1 < y" "f y - f x = (y - x) * f' z1"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   683
      using subsetD[OF atMostAtLeast_subset_convex[OF `convex C` `x \<in> C` `y \<in> C` `x < y`],
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   684
        THEN f', THEN MVT2[OF `x < y`, rule_format, unfolded atLeastAtMost_iff[symmetric]]]
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   685
      by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   686
    then have "z1 \<in> C" using atMostAtLeast_subset_convex
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44282
diff changeset
   687
      `convex C` `x \<in> C` `y \<in> C` `x < y` by fastforce
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   688
    from z1 have z1': "f x - f y = (x - y) * f' z1"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   689
      by (simp add:field_simps)
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   690
    obtain z2 where z2: "z2 > x" "z2 < z1" "f' z1 - f' x = (z1 - x) * f'' z2"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   691
      using subsetD[OF atMostAtLeast_subset_convex[OF `convex C` `x \<in> C` `z1 \<in> C` `x < z1`],
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   692
        THEN f'', THEN MVT2[OF `x < z1`, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   693
      by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   694
    obtain z3 where z3: "z3 > z1" "z3 < y" "f' y - f' z1 = (y - z1) * f'' z3"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   695
      using subsetD[OF atMostAtLeast_subset_convex[OF `convex C` `z1 \<in> C` `y \<in> C` `z1 < y`],
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   696
        THEN f'', THEN MVT2[OF `z1 < y`, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   697
      by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   698
    have "f' y - (f x - f y) / (x - y) = f' y - f' z1"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   699
      using asm z1' by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   700
    also have "\<dots> = (y - z1) * f'' z3" using z3 by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   701
    finally have cool': "f' y - (f x - f y) / (x - y) = (y - z1) * f'' z3" by simp
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   702
    have A': "y - z1 \<ge> 0" using z1 by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   703
    have "z3 \<in> C" using z3 asm atMostAtLeast_subset_convex
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44282
diff changeset
   704
      `convex C` `x \<in> C` `z1 \<in> C` `x < z1` by fastforce
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   705
    then have B': "f'' z3 \<ge> 0" using assms by auto
56536
aefb4a8da31f made mult_nonneg_nonneg a simp rule
nipkow
parents: 56479
diff changeset
   706
    from A' B' have "(y - z1) * f'' z3 \<ge> 0" by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   707
    from cool' this have "f' y - (f x - f y) / (x - y) \<ge> 0" by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   708
    from mult_right_mono_neg[OF this le(2)]
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   709
    have "f' y * (x - y) - (f x - f y) / (x - y) * (x - y) \<le> 0 * (x - y)"
36778
739a9379e29b avoid using real-specific versions of generic lemmas
huffman
parents: 36648
diff changeset
   710
      by (simp add: algebra_simps)
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   711
    then have "f' y * (x - y) - (f x - f y) \<le> 0" using le by auto
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   712
    then have res: "f' y * (x - y) \<le> f x - f y" by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   713
    have "(f y - f x) / (y - x) - f' x = f' z1 - f' x"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   714
      using asm z1 by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   715
    also have "\<dots> = (z1 - x) * f'' z2" using z2 by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   716
    finally have cool: "(f y - f x) / (y - x) - f' x = (z1 - x) * f'' z2" by simp
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   717
    have A: "z1 - x \<ge> 0" using z1 by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   718
    have "z2 \<in> C" using z2 z1 asm atMostAtLeast_subset_convex
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44282
diff changeset
   719
      `convex C` `z1 \<in> C` `y \<in> C` `z1 < y` by fastforce
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   720
    then have B: "f'' z2 \<ge> 0" using assms by auto
56536
aefb4a8da31f made mult_nonneg_nonneg a simp rule
nipkow
parents: 56479
diff changeset
   721
    from A B have "(z1 - x) * f'' z2 \<ge> 0" by auto
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   722
    from cool this have "(f y - f x) / (y - x) - f' x \<ge> 0" by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   723
    from mult_right_mono[OF this ge(2)]
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   724
    have "(f y - f x) / (y - x) * (y - x) - f' x * (y - x) \<ge> 0 * (y - x)"
36778
739a9379e29b avoid using real-specific versions of generic lemmas
huffman
parents: 36648
diff changeset
   725
      by (simp add: algebra_simps)
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   726
    then have "f y - f x - f' x * (y - x) \<ge> 0" using ge by auto
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   727
    then have "f y - f x \<ge> f' x * (y - x)" "f' y * (x - y) \<le> f x - f y"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   728
      using res by auto } note less_imp = this
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   729
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   730
    fix x y :: real
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   731
    assume "x \<in> C" "y \<in> C" "x \<noteq> y"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   732
    then have"f y - f x \<ge> f' x * (y - x)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   733
    unfolding neq_iff using less_imp by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   734
  }
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   735
  moreover
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   736
  {
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   737
    fix x y :: real
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   738
    assume asm: "x \<in> C" "y \<in> C" "x = y"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   739
    then have "f y - f x \<ge> f' x * (y - x)" by auto
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   740
  }
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   741
  ultimately show ?thesis using assms by blast
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   742
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   743
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   744
lemma f''_ge0_imp_convex:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   745
  fixes f :: "real \<Rightarrow> real"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   746
  assumes conv: "convex C"
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   747
    and f': "\<And>x. x \<in> C \<Longrightarrow> DERIV f x :> (f' x)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   748
    and f'': "\<And>x. x \<in> C \<Longrightarrow> DERIV f' x :> (f'' x)"
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   749
    and pos: "\<And>x. x \<in> C \<Longrightarrow> f'' x \<ge> 0"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   750
  shows "convex_on C f"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   751
  using f''_imp_f'[OF conv f' f'' pos] assms pos_convex_function
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   752
  by fastforce
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   753
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   754
lemma minus_log_convex:
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   755
  fixes b :: real
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   756
  assumes "b > 1"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   757
  shows "convex_on {0 <..} (\<lambda> x. - log b x)"
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   758
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   759
  have "\<And>z. z > 0 \<Longrightarrow> DERIV (log b) z :> 1 / (ln b * z)"
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   760
    using DERIV_log by auto
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   761
  then have f': "\<And>z. z > 0 \<Longrightarrow> DERIV (\<lambda> z. - log b z) z :> - 1 / (ln b * z)"
56479
91958d4b30f7 revert c1bbd3e22226, a14831ac3023, and 36489d77c484: divide_minus_left/right are again simp rules
hoelzl
parents: 56409
diff changeset
   762
    by (auto simp: DERIV_minus)
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   763
  have "\<And>z :: real. z > 0 \<Longrightarrow> DERIV inverse z :> - (inverse z ^ Suc (Suc 0))"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   764
    using less_imp_neq[THEN not_sym, THEN DERIV_inverse] by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   765
  from this[THEN DERIV_cmult, of _ "- 1 / ln b"]
49609
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   766
  have "\<And>z :: real. z > 0 \<Longrightarrow>
89e10ed7668b tuned proofs;
wenzelm
parents: 44890
diff changeset
   767
    DERIV (\<lambda> z. (- 1 / ln b) * inverse z) z :> (- 1 / ln b) * (- (inverse z ^ Suc (Suc 0)))"
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   768
    by auto
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   769
  then have f''0: "\<And>z::real. z > 0 \<Longrightarrow>
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   770
    DERIV (\<lambda> z. - 1 / (ln b * z)) z :> 1 / (ln b * z * z)"
56479
91958d4b30f7 revert c1bbd3e22226, a14831ac3023, and 36489d77c484: divide_minus_left/right are again simp rules
hoelzl
parents: 56409
diff changeset
   771
    unfolding inverse_eq_divide by (auto simp add: mult_assoc)
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56571
diff changeset
   772
  have f''_ge0: "\<And>z::real. z > 0 \<Longrightarrow> 1 / (ln b * z * z) \<ge> 0"
56544
b60d5d119489 made mult_pos_pos a simp rule
nipkow
parents: 56541
diff changeset
   773
    using `b > 1` by (auto intro!:less_imp_le)
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   774
  from f''_ge0_imp_convex[OF pos_is_convex,
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   775
    unfolded greaterThan_iff, OF f' f''0 f''_ge0]
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   776
  show ?thesis by auto
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   777
qed
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   778
d26348b667f2 Moved Convex theory to library.
hoelzl
parents:
diff changeset
   779
end