src/HOL/Multivariate_Analysis/Convex_Euclidean_Space.thy
author huffman
Sun Aug 21 11:03:15 2011 -0700 (2011-08-21)
changeset 44361 75ec83d45303
parent 44349 f057535311c5
child 44365 5daa55003649
permissions -rw-r--r--
remove unnecessary euclidean_space class constraints
wenzelm@41959
     1
(*  Title:      HOL/Multivariate_Analysis/Convex_Euclidean_Space.thy
himmelma@33175
     2
    Author:     Robert Himmelmann, TU Muenchen
hoelzl@40887
     3
    Author:     Bogdan Grechuk, University of Edinburgh
himmelma@33175
     4
*)
himmelma@33175
     5
himmelma@33175
     6
header {* Convex sets, functions and related things. *}
himmelma@33175
     7
himmelma@33175
     8
theory Convex_Euclidean_Space
huffman@44132
     9
imports
huffman@44132
    10
  Topology_Euclidean_Space
huffman@44132
    11
  "~~/src/HOL/Library/Convex"
huffman@44132
    12
  "~~/src/HOL/Library/Set_Algebras"
himmelma@33175
    13
begin
himmelma@33175
    14
himmelma@33175
    15
himmelma@33175
    16
(* ------------------------------------------------------------------------- *)
himmelma@33175
    17
(* To be moved elsewhere                                                     *)
himmelma@33175
    18
(* ------------------------------------------------------------------------- *)
himmelma@33175
    19
huffman@44361
    20
lemma linear_scaleR: "linear (\<lambda>x. scaleR c x)"
huffman@44361
    21
  by (simp add: linear_def scaleR_add_right)
huffman@44361
    22
huffman@44361
    23
lemma injective_scaleR: "c \<noteq> 0 \<Longrightarrow> inj (\<lambda>(x::'a::real_vector). scaleR c x)"
huffman@44361
    24
  by (simp add: inj_on_def)
hoelzl@40377
    25
hoelzl@40377
    26
lemma linear_add_cmul:
hoelzl@40377
    27
assumes "linear f"
hoelzl@40377
    28
shows "f(a *\<^sub>R x + b *\<^sub>R y) = a *\<^sub>R f x +  b *\<^sub>R f y"
hoelzl@40377
    29
using linear_add[of f] linear_cmul[of f] assms by (simp) 
hoelzl@40377
    30
hoelzl@40377
    31
lemma mem_convex_2:
hoelzl@40377
    32
  assumes "convex S" "x : S" "y : S" "u>=0" "v>=0" "u+v=1"
hoelzl@40377
    33
  shows "(u *\<^sub>R x + v *\<^sub>R y) : S"
hoelzl@40377
    34
  using assms convex_def[of S] by auto
hoelzl@40377
    35
hoelzl@40377
    36
lemma mem_convex_alt:
hoelzl@40377
    37
  assumes "convex S" "x : S" "y : S" "u>=0" "v>=0" "u+v>0"
hoelzl@40377
    38
  shows "((u/(u+v)) *\<^sub>R x + (v/(u+v)) *\<^sub>R y) : S"
hoelzl@40377
    39
apply (subst mem_convex_2) 
hoelzl@40377
    40
using assms apply (auto simp add: algebra_simps zero_le_divide_iff)
hoelzl@40377
    41
using add_divide_distrib[of u v "u+v"] by auto
hoelzl@40377
    42
hoelzl@40377
    43
lemma card_ge1: assumes "d ~= {}" "finite d" shows "card d >= 1"
hoelzl@40377
    44
by (metis Suc_eq_plus1 assms(1) assms(2) card_eq_0_iff fact_ge_one_nat fact_num_eq_if_nat one_le_mult_iff plus_nat.add_0)
hoelzl@40377
    45
hoelzl@40377
    46
lemma inj_on_image_mem_iff: "inj_on f B ==> (A <= B) ==> (f a : f`A) ==> (a : B) ==> (a : A)" 
hoelzl@40377
    47
by (blast dest: inj_onD)
hoelzl@40377
    48
hoelzl@40377
    49
lemma independent_injective_on_span_image:
huffman@44361
    50
  assumes iS: "independent S" 
hoelzl@40377
    51
     and lf: "linear f" and fi: "inj_on f (span S)"
hoelzl@40377
    52
  shows "independent (f ` S)"
hoelzl@40377
    53
proof-
hoelzl@40377
    54
  {fix a assume a: "a : S" "f a : span (f ` S - {f a})"
hoelzl@40377
    55
    have eq: "f ` S - {f a} = f ` (S - {a})" using fi a span_inc
hoelzl@40377
    56
      by (auto simp add: inj_on_def)
hoelzl@40377
    57
    from a have "f a : f ` span (S -{a})"
hoelzl@40377
    58
      unfolding eq span_linear_image[OF lf, of "S - {a}"]  by blast
hoelzl@40377
    59
    moreover have "span (S -{a}) <= span S" using span_mono[of "S-{a}" S] by auto
hoelzl@40377
    60
    ultimately have "a : span (S -{a})" using fi a span_inc by (auto simp add: inj_on_def)
hoelzl@40377
    61
    with a(1) iS  have False by (simp add: dependent_def) }
hoelzl@40377
    62
  then show ?thesis unfolding dependent_def by blast
hoelzl@40377
    63
qed
hoelzl@40377
    64
hoelzl@40377
    65
lemma dim_image_eq:
hoelzl@40377
    66
fixes f :: "'n::euclidean_space => 'm::euclidean_space"
hoelzl@40377
    67
assumes lf: "linear f" and fi: "inj_on f (span S)" 
hoelzl@40377
    68
shows "dim (f ` S) = dim (S:: ('n::euclidean_space) set)"
hoelzl@40377
    69
proof-
hoelzl@40377
    70
obtain B where B_def: "B<=S & independent B & S <= span B & card B = dim S" 
hoelzl@40377
    71
  using basis_exists[of S] by auto
hoelzl@40377
    72
hence "span S = span B" using span_mono[of B S] span_mono[of S "span B"] span_span[of B] by auto
hoelzl@40377
    73
hence "independent (f ` B)" using independent_injective_on_span_image[of B f] B_def assms by auto
hoelzl@40377
    74
moreover have "card (f ` B) = card B" using assms card_image[of f B] subset_inj_on[of f "span S" B] 
hoelzl@40377
    75
   B_def span_inc by auto
hoelzl@40377
    76
moreover have "(f ` B) <= (f ` S)" using B_def by auto
hoelzl@40377
    77
ultimately have "dim (f ` S) >= dim S" 
hoelzl@40377
    78
  using independent_card_le_dim[of "f ` B" "f ` S"] B_def by auto
hoelzl@40377
    79
from this show ?thesis using dim_image_le[of f S] assms by auto
hoelzl@40377
    80
qed
hoelzl@40377
    81
hoelzl@40377
    82
lemma linear_injective_on_subspace_0:
hoelzl@40377
    83
assumes lf: "linear f" and "subspace S"
hoelzl@40377
    84
  shows "inj_on f S <-> (!x : S. f x = 0 --> x = 0)"
hoelzl@40377
    85
proof-
hoelzl@40377
    86
  have "inj_on f S <-> (!x : S. !y : S. f x = f y --> x = y)" by (simp add: inj_on_def)
hoelzl@40377
    87
  also have "... <-> (!x : S. !y : S. f x - f y = 0 --> x - y = 0)" by simp
hoelzl@40377
    88
  also have "... <-> (!x : S. !y : S. f (x - y) = 0 --> x - y = 0)"
hoelzl@40377
    89
    by (simp add: linear_sub[OF lf])
hoelzl@40377
    90
  also have "... <-> (! x : S. f x = 0 --> x = 0)" 
hoelzl@40377
    91
    using `subspace S` subspace_def[of S] subspace_sub[of S] by auto
hoelzl@40377
    92
  finally show ?thesis .
hoelzl@40377
    93
qed
hoelzl@40377
    94
hoelzl@40377
    95
lemma subspace_Inter: "(!s : f. subspace s) ==> subspace (Inter f)"
hoelzl@40377
    96
  unfolding subspace_def by auto 
hoelzl@40377
    97
hoelzl@40377
    98
lemma span_eq[simp]: "(span s = s) <-> subspace s"
hoelzl@40377
    99
proof-
huffman@44170
   100
  { fix f assume "Ball f subspace"
huffman@44170
   101
    hence "subspace (Inter f)" using subspace_Inter[of f] unfolding Ball_def by auto  }
huffman@44170
   102
  thus ?thesis using hull_eq[of subspace s] span_def by auto
hoelzl@40377
   103
qed
hoelzl@40377
   104
hoelzl@40377
   105
lemma basis_inj_on: "d \<subseteq> {..<DIM('n)} \<Longrightarrow> inj_on (basis :: nat => 'n::euclidean_space) d"
hoelzl@40377
   106
  by(auto simp add: inj_on_def euclidean_eq[where 'a='n])
hoelzl@40377
   107
  
hoelzl@40377
   108
lemma finite_substdbasis: "finite {basis i ::'n::euclidean_space |i. i : (d:: nat set)}" (is "finite ?S")
hoelzl@40377
   109
proof-
hoelzl@40377
   110
  have eq: "?S = basis ` d" by blast
hoelzl@40377
   111
  show ?thesis unfolding eq apply(rule finite_subset[OF _ range_basis_finite]) by auto
hoelzl@40377
   112
qed
hoelzl@40377
   113
hoelzl@40377
   114
lemma card_substdbasis: assumes "d \<subseteq> {..<DIM('n::euclidean_space)}"
hoelzl@40377
   115
  shows "card {basis i ::'n::euclidean_space | i. i : d} = card d" (is "card ?S = _")
hoelzl@40377
   116
proof-
hoelzl@40377
   117
  have eq: "?S = basis ` d" by blast
hoelzl@40377
   118
  show ?thesis unfolding eq using card_image[OF basis_inj_on[of d]] assms by auto
hoelzl@40377
   119
qed
hoelzl@40377
   120
hoelzl@40377
   121
lemma substdbasis_expansion_unique: assumes "d\<subseteq>{..<DIM('a::euclidean_space)}"
hoelzl@40377
   122
  shows "setsum (%i. f i *\<^sub>R basis i) d = (x::'a::euclidean_space)
hoelzl@40377
   123
      <-> (!i<DIM('a). (i:d --> f i = x$$i) & (i ~: d --> x $$ i = 0))"
hoelzl@40377
   124
proof- have *:"\<And>x a b P. x * (if P then a else b) = (if P then x*a else x*b)" by auto
hoelzl@40377
   125
  have **:"finite d" apply(rule finite_subset[OF assms]) by fastsimp
hoelzl@40377
   126
  have ***:"\<And>i. (setsum (%i. f i *\<^sub>R ((basis i)::'a)) d) $$ i = (\<Sum>x\<in>d. if x = i then f x else 0)"
huffman@44282
   127
    unfolding euclidean_component_setsum euclidean_component_scaleR basis_component *
hoelzl@40377
   128
    apply(rule setsum_cong2) using assms by auto
hoelzl@40377
   129
  show ?thesis unfolding euclidean_eq[where 'a='a] *** setsum_delta[OF **] using assms by auto
hoelzl@40377
   130
qed
hoelzl@40377
   131
hoelzl@40377
   132
lemma independent_substdbasis: assumes "d\<subseteq>{..<DIM('a::euclidean_space)}"
hoelzl@40377
   133
  shows "independent {basis i ::'a::euclidean_space |i. i : (d :: nat set)}" (is "independent ?A")
hoelzl@40377
   134
proof -
hoelzl@40377
   135
  have *: "{basis i |i. i < DIM('a)} = basis ` {..<DIM('a)}" by auto
hoelzl@40377
   136
  show ?thesis
hoelzl@40377
   137
    apply(intro independent_mono[of "{basis i ::'a |i. i : {..<DIM('a::euclidean_space)}}" "?A"] )
hoelzl@40377
   138
    using independent_basis[where 'a='a] assms by (auto simp: *)
hoelzl@40377
   139
qed
hoelzl@40377
   140
hoelzl@40377
   141
lemma dim_cball: 
hoelzl@40377
   142
assumes "0<e"
hoelzl@40377
   143
shows "dim (cball (0 :: 'n::euclidean_space) e) = DIM('n)"
hoelzl@40377
   144
proof-
hoelzl@40377
   145
{ fix x :: "'n::euclidean_space" def y == "(e/norm x) *\<^sub>R x"
hoelzl@40377
   146
  hence "y : cball 0 e" using cball_def dist_norm[of 0 y] assms by auto
hoelzl@40377
   147
  moreover have "x = (norm x/e) *\<^sub>R y" using y_def assms by simp
hoelzl@40377
   148
  moreover hence "x = (norm x/e) *\<^sub>R y"  by auto
hoelzl@40377
   149
  ultimately have "x : span (cball 0 e)"
hoelzl@40377
   150
     using span_mul[of y "cball 0 e" "norm x/e"] span_inc[of "cball 0 e"] by auto
hoelzl@40377
   151
} hence "span (cball 0 e) = (UNIV :: ('n::euclidean_space) set)" by auto 
hoelzl@40377
   152
from this show ?thesis using dim_span[of "cball (0 :: 'n::euclidean_space) e"] by (auto simp add: dim_UNIV)
hoelzl@40377
   153
qed
hoelzl@40377
   154
hoelzl@40377
   155
lemma indep_card_eq_dim_span:
hoelzl@40377
   156
fixes B :: "('n::euclidean_space) set"
hoelzl@40377
   157
assumes "independent B"
hoelzl@40377
   158
shows "finite B & card B = dim (span B)" 
hoelzl@40377
   159
  using assms basis_card_eq_dim[of B "span B"] span_inc by auto
hoelzl@40377
   160
hoelzl@40377
   161
lemma setsum_not_0: "setsum f A ~= 0 ==> EX a:A. f a ~= 0"
hoelzl@40377
   162
  apply(rule ccontr) by auto
hoelzl@40377
   163
hoelzl@40377
   164
lemma translate_inj_on: 
huffman@44361
   165
fixes A :: "('a::ab_group_add) set"
hoelzl@40377
   166
shows "inj_on (%x. a+x) A" unfolding inj_on_def by auto
hoelzl@40377
   167
hoelzl@40377
   168
lemma translation_assoc:
hoelzl@40377
   169
  fixes a b :: "'a::ab_group_add"
hoelzl@40377
   170
  shows "(\<lambda>x. b+x) ` ((\<lambda>x. a+x) ` S) = (\<lambda>x. (a+b)+x) ` S" by auto
hoelzl@40377
   171
hoelzl@40377
   172
lemma translation_invert:
hoelzl@40377
   173
  fixes a :: "'a::ab_group_add"
hoelzl@40377
   174
  assumes "(\<lambda>x. a+x) ` A = (\<lambda>x. a+x) ` B"
hoelzl@40377
   175
  shows "A=B"
hoelzl@40377
   176
proof-
hoelzl@40377
   177
  have "(%x. -a+x) ` ((%x. a+x) ` A) = (%x. -a+x) ` ((%x. a+x) ` B)" using assms by auto
hoelzl@40377
   178
  from this show ?thesis using translation_assoc[of "-a" a A] translation_assoc[of "-a" a B] by auto 
hoelzl@40377
   179
qed
hoelzl@40377
   180
hoelzl@40377
   181
lemma translation_galois:
hoelzl@40377
   182
  fixes a :: "'a::ab_group_add"
hoelzl@40377
   183
  shows "T=((\<lambda>x. a+x) ` S) <-> S=((\<lambda>x. (-a)+x) ` T)"
hoelzl@40377
   184
  using translation_assoc[of "-a" a S] apply auto
hoelzl@40377
   185
  using translation_assoc[of a "-a" T] by auto
hoelzl@40377
   186
hoelzl@40377
   187
lemma translation_inverse_subset:
hoelzl@40377
   188
  assumes "((%x. -a+x) ` V) <= (S :: 'n::ab_group_add set)" 
hoelzl@40377
   189
  shows "V <= ((%x. a+x) ` S)"
hoelzl@40377
   190
proof-
hoelzl@40377
   191
{ fix x assume "x:V" hence "x-a : S" using assms by auto 
hoelzl@40377
   192
  hence "x : {a + v |v. v : S}" apply auto apply (rule exI[of _ "x-a"]) apply simp done 
hoelzl@40377
   193
  hence "x : ((%x. a+x) ` S)" by auto }
hoelzl@40377
   194
  from this show ?thesis by auto
hoelzl@40377
   195
qed
hoelzl@40377
   196
hoelzl@40377
   197
lemma basis_to_basis_subspace_isomorphism:
hoelzl@40377
   198
  assumes s: "subspace (S:: ('n::euclidean_space) set)"
hoelzl@40377
   199
  and t: "subspace (T :: ('m::euclidean_space) set)"
hoelzl@40377
   200
  and d: "dim S = dim T"
hoelzl@40377
   201
  and B: "B <= S" "independent B" "S <= span B" "card B = dim S"
hoelzl@40377
   202
  and C: "C <= T" "independent C" "T <= span C" "card C = dim T"
hoelzl@40377
   203
  shows "EX f. linear f & f ` B = C & f ` S = T & inj_on f S"
hoelzl@40377
   204
proof-
hoelzl@40377
   205
(* Proof is a modified copy of the proof of similar lemma subspace_isomorphism
hoelzl@40377
   206
*)
hoelzl@40377
   207
  from B independent_bound have fB: "finite B" by blast
hoelzl@40377
   208
  from C independent_bound have fC: "finite C" by blast
hoelzl@40377
   209
  from B(4) C(4) card_le_inj[of B C] d obtain f where
hoelzl@40377
   210
    f: "f ` B \<subseteq> C" "inj_on f B" using `finite B` `finite C` by auto
hoelzl@40377
   211
  from linear_independent_extend[OF B(2)] obtain g where
hoelzl@40377
   212
    g: "linear g" "\<forall>x\<in> B. g x = f x" by blast
hoelzl@40377
   213
  from inj_on_iff_eq_card[OF fB, of f] f(2)
hoelzl@40377
   214
  have "card (f ` B) = card B" by simp
hoelzl@40377
   215
  with B(4) C(4) have ceq: "card (f ` B) = card C" using d
hoelzl@40377
   216
    by simp
hoelzl@40377
   217
  have "g ` B = f ` B" using g(2)
hoelzl@40377
   218
    by (auto simp add: image_iff)
hoelzl@40377
   219
  also have "\<dots> = C" using card_subset_eq[OF fC f(1) ceq] .
hoelzl@40377
   220
  finally have gBC: "g ` B = C" .
hoelzl@40377
   221
  have gi: "inj_on g B" using f(2) g(2)
hoelzl@40377
   222
    by (auto simp add: inj_on_def)
hoelzl@40377
   223
  note g0 = linear_indep_image_lemma[OF g(1) fB, unfolded gBC, OF C(2) gi]
hoelzl@40377
   224
  {fix x y assume x: "x \<in> S" and y: "y \<in> S" and gxy:"g x = g y"
hoelzl@40377
   225
    from B(3) x y have x': "x \<in> span B" and y': "y \<in> span B" by blast+
hoelzl@40377
   226
    from gxy have th0: "g (x - y) = 0" by (simp add: linear_sub[OF g(1)])
hoelzl@40377
   227
    have th1: "x - y \<in> span B" using x' y' by (metis span_sub)
hoelzl@40377
   228
    have "x=y" using g0[OF th1 th0] by simp }
hoelzl@40377
   229
  then have giS: "inj_on g S"
hoelzl@40377
   230
    unfolding inj_on_def by blast
hoelzl@40377
   231
  from span_subspace[OF B(1,3) s]
hoelzl@40377
   232
  have "g ` S = span (g ` B)" by (simp add: span_linear_image[OF g(1)])
hoelzl@40377
   233
  also have "\<dots> = span C" unfolding gBC ..
hoelzl@40377
   234
  also have "\<dots> = T" using span_subspace[OF C(1,3) t] .
hoelzl@40377
   235
  finally have gS: "g ` S = T" .
hoelzl@40377
   236
  from g(1) gS giS gBC show ?thesis by blast
hoelzl@40377
   237
qed
hoelzl@40377
   238
hoelzl@40377
   239
lemma closure_linear_image:
huffman@44361
   240
fixes f :: "('m::euclidean_space) => ('n::real_normed_vector)"
hoelzl@40377
   241
assumes "linear f"
hoelzl@40377
   242
shows "f ` (closure S) <= closure (f ` S)"
hoelzl@40377
   243
using image_closure_subset[of S f "closure (f ` S)"] assms linear_conv_bounded_linear[of f] 
hoelzl@40377
   244
linear_continuous_on[of f "closure S"] closed_closure[of "f ` S"] closure_subset[of "f ` S"] by auto
hoelzl@40377
   245
hoelzl@40377
   246
lemma closure_injective_linear_image:
hoelzl@40377
   247
fixes f :: "('n::euclidean_space) => ('n::euclidean_space)"
hoelzl@40377
   248
assumes "linear f" "inj f"
hoelzl@40377
   249
shows "f ` (closure S) = closure (f ` S)"
hoelzl@40377
   250
proof-
hoelzl@40377
   251
obtain f' where f'_def: "linear f' & f o f' = id & f' o f = id" 
hoelzl@40377
   252
   using assms linear_injective_isomorphism[of f] isomorphism_expand by auto
hoelzl@40377
   253
hence "f' ` closure (f ` S) <= closure (S)"
hoelzl@40377
   254
   using closure_linear_image[of f' "f ` S"] image_compose[of f' f] by auto
hoelzl@40377
   255
hence "f ` f' ` closure (f ` S) <= f ` closure (S)" by auto
hoelzl@40377
   256
hence "closure (f ` S) <= f ` closure (S)" using image_compose[of f f' "closure (f ` S)"] f'_def by auto
hoelzl@40377
   257
from this show ?thesis using closure_linear_image[of f S] assms by auto 
hoelzl@40377
   258
qed
hoelzl@40377
   259
hoelzl@40377
   260
lemma closure_direct_sum:
huffman@44361
   261
fixes S :: "('n::real_normed_vector) set"
huffman@44361
   262
fixes T :: "('m::real_normed_vector) set"
hoelzl@40377
   263
shows "closure (S <*> T) = closure S <*> closure T"
hoelzl@40377
   264
proof-
hoelzl@40377
   265
{ fix x assume "x : closure S <*> closure T"
hoelzl@40377
   266
  from this obtain xs xt where xst_def: "xs : closure S & xt : closure T & (xs,xt) = x" by auto
hoelzl@40377
   267
  { fix ee assume ee_def: "(ee :: real) > 0"
hoelzl@40377
   268
    def e == "ee/2" hence e_def: "(e :: real)>0 & 2*e=ee" using ee_def by auto
hoelzl@40377
   269
    from this obtain e where e_def: "(e :: real)>0 & 2*e=ee" by auto
hoelzl@40377
   270
    obtain ys where ys_def: "ys : S & (dist ys xs < e)"
hoelzl@40377
   271
      using e_def xst_def closure_approachable[of xs S] by auto
hoelzl@40377
   272
    obtain yt where yt_def: "yt : T & (dist yt xt < e)"
hoelzl@40377
   273
      using e_def xst_def closure_approachable[of xt T] by auto
hoelzl@40377
   274
    from ys_def yt_def have "dist (ys,yt) (xs,xt) < sqrt (2*e^2)" 
hoelzl@40377
   275
      unfolding dist_norm apply (auto simp add: norm_Pair) 
hoelzl@40377
   276
      using mult_strict_mono'[of "norm (ys - xs)" e "norm (ys - xs)" e] e_def
hoelzl@40377
   277
      mult_strict_mono'[of "norm (yt - xt)" e "norm (yt - xt)" e] by (simp add: power2_eq_square)
hoelzl@40377
   278
    hence "((ys,yt) : S <*> T) & (dist (ys,yt) x < 2*e)"
hoelzl@40377
   279
      using e_def sqrt_add_le_add_sqrt[of "e^2" "e^2"] xst_def ys_def yt_def by auto
hoelzl@40377
   280
    hence "EX y: S <*> T. dist y x < ee" using e_def by auto
hoelzl@40377
   281
  } hence "x : closure (S <*> T)" using closure_approachable[of x "S <*> T"] by auto
hoelzl@40377
   282
}
hoelzl@40377
   283
hence "closure (S <*> T) >= closure S <*> closure T" by auto
hoelzl@40377
   284
moreover have "closed (closure S <*> closure T)" using closed_Times by auto
hoelzl@40377
   285
ultimately show ?thesis using closure_minimal[of "S <*> T" "closure S <*> closure T"]
hoelzl@40377
   286
  closure_subset[of S] closure_subset[of T] by auto
hoelzl@40377
   287
qed
hoelzl@40377
   288
huffman@44361
   289
lemma closure_scaleR:  (* TODO: generalize to real_normed_vector *)
hoelzl@40377
   290
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
   291
shows "(op *\<^sub>R c) ` (closure S) = closure ((op *\<^sub>R c) ` S)"
hoelzl@40377
   292
proof-
hoelzl@40377
   293
{ assume "c ~= 0" hence ?thesis using closure_injective_linear_image[of "(op *\<^sub>R c)" S]
hoelzl@40377
   294
      linear_scaleR injective_scaleR by auto 
hoelzl@40377
   295
}
hoelzl@40377
   296
moreover
hoelzl@40377
   297
{ assume zero: "c=0 & S ~= {}"
hoelzl@40377
   298
  hence "closure S ~= {}" using closure_subset by auto
hoelzl@40377
   299
  hence "op *\<^sub>R c ` (closure S) = {0}" using zero by auto
hoelzl@40377
   300
  moreover have "op *\<^sub>R 0 ` S = {0}" using zero by auto
hoelzl@40377
   301
  ultimately have ?thesis using zero by auto
hoelzl@40377
   302
}
hoelzl@40377
   303
moreover
hoelzl@40377
   304
{ assume "S={}" hence ?thesis by auto }
hoelzl@40377
   305
ultimately show ?thesis by blast
hoelzl@40377
   306
qed
hoelzl@40377
   307
hoelzl@40377
   308
lemma fst_linear: "linear fst" unfolding linear_def by (simp add: algebra_simps)
hoelzl@40377
   309
hoelzl@40377
   310
lemma snd_linear: "linear snd" unfolding linear_def by (simp add: algebra_simps)
hoelzl@40377
   311
hoelzl@40897
   312
lemma fst_snd_linear: "linear (%(x,y). x + y)" unfolding linear_def by (simp add: algebra_simps)
hoelzl@40377
   313
hoelzl@37489
   314
lemma scaleR_2:
hoelzl@37489
   315
  fixes x :: "'a::real_vector"
hoelzl@37489
   316
  shows "scaleR 2 x = x + x"
hoelzl@37489
   317
unfolding one_add_one_is_two [symmetric] scaleR_left_distrib by simp
hoelzl@34964
   318
hoelzl@37489
   319
declare euclidean_simps[simp]
himmelma@33175
   320
hoelzl@37489
   321
lemma vector_choose_size: "0 <= c ==> \<exists>(x::'a::euclidean_space). norm x = c"
hoelzl@37489
   322
  apply (rule exI[where x="c *\<^sub>R basis 0 ::'a"]) using DIM_positive[where 'a='a] by auto
himmelma@33175
   323
himmelma@33175
   324
lemma setsum_delta_notmem: assumes "x\<notin>s"
himmelma@33175
   325
  shows "setsum (\<lambda>y. if (y = x) then P x else Q y) s = setsum Q s"
himmelma@33175
   326
        "setsum (\<lambda>y. if (x = y) then P x else Q y) s = setsum Q s"
himmelma@33175
   327
        "setsum (\<lambda>y. if (y = x) then P y else Q y) s = setsum Q s"
himmelma@33175
   328
        "setsum (\<lambda>y. if (x = y) then P y else Q y) s = setsum Q s"
himmelma@33175
   329
  apply(rule_tac [!] setsum_cong2) using assms by auto
himmelma@33175
   330
himmelma@33175
   331
lemma setsum_delta'':
himmelma@33175
   332
  fixes s::"'a::real_vector set" assumes "finite s"
himmelma@33175
   333
  shows "(\<Sum>x\<in>s. (if y = x then f x else 0) *\<^sub>R x) = (if y\<in>s then (f y) *\<^sub>R y else 0)"
himmelma@33175
   334
proof-
himmelma@33175
   335
  have *:"\<And>x y. (if y = x then f x else (0::real)) *\<^sub>R x = (if x=y then (f x) *\<^sub>R x else 0)" by auto
himmelma@33175
   336
  show ?thesis unfolding * using setsum_delta[OF assms, of y "\<lambda>x. f x *\<^sub>R x"] by auto
himmelma@33175
   337
qed
himmelma@33175
   338
himmelma@33175
   339
lemma if_smult:"(if P then x else (y::real)) *\<^sub>R v = (if P then x *\<^sub>R v else y *\<^sub>R v)" by auto
himmelma@33175
   340
hoelzl@37489
   341
lemma image_smult_interval:"(\<lambda>x. m *\<^sub>R (x::'a::ordered_euclidean_space)) ` {a..b} =
himmelma@33175
   342
  (if {a..b} = {} then {} else if 0 \<le> m then {m *\<^sub>R a..m *\<^sub>R b} else {m *\<^sub>R b..m *\<^sub>R a})"
himmelma@33175
   343
  using image_affinity_interval[of m 0 a b] by auto
himmelma@33175
   344
himmelma@33175
   345
lemma dist_triangle_eq:
huffman@44361
   346
  fixes x y z :: "'a::real_inner"
himmelma@33175
   347
  shows "dist x z = dist x y + dist y z \<longleftrightarrow> norm (x - y) *\<^sub>R (y - z) = norm (y - z) *\<^sub>R (x - y)"
himmelma@33175
   348
proof- have *:"x - y + (y - z) = x - z" by auto
hoelzl@37489
   349
  show ?thesis unfolding dist_norm norm_triangle_eq[of "x - y" "y - z", unfolded *]
himmelma@33175
   350
    by(auto simp add:norm_minus_commute) qed
himmelma@33175
   351
hoelzl@37489
   352
lemma norm_minus_eqI:"x = - y \<Longrightarrow> norm x = norm y" by auto
himmelma@33175
   353
himmelma@33175
   354
lemma Min_grI: assumes "finite A" "A \<noteq> {}" "\<forall>a\<in>A. x < a" shows "x < Min A"
himmelma@33175
   355
  unfolding Min_gr_iff[OF assms(1,2)] using assms(3) by auto
himmelma@33175
   356
hoelzl@37489
   357
lemma norm_lt: "norm x < norm y \<longleftrightarrow> inner x x < inner y y"
hoelzl@37489
   358
  unfolding norm_eq_sqrt_inner by simp
himmelma@33175
   359
hoelzl@37489
   360
lemma norm_le: "norm x \<le> norm y \<longleftrightarrow> inner x x \<le> inner y y"
hoelzl@37489
   361
  unfolding norm_eq_sqrt_inner by simp
hoelzl@37489
   362
hoelzl@37489
   363
himmelma@33175
   364
himmelma@33175
   365
subsection {* Affine set and affine hull.*}
himmelma@33175
   366
himmelma@33175
   367
definition
himmelma@33175
   368
  affine :: "'a::real_vector set \<Rightarrow> bool" where
himmelma@33175
   369
  "affine s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. \<forall>u v. u + v = 1 \<longrightarrow> u *\<^sub>R x + v *\<^sub>R y \<in> s)"
himmelma@33175
   370
himmelma@33175
   371
lemma affine_alt: "affine s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. \<forall>u::real. (1 - u) *\<^sub>R x + u *\<^sub>R y \<in> s)"
nipkow@36071
   372
unfolding affine_def by(metis eq_diff_eq')
himmelma@33175
   373
himmelma@33175
   374
lemma affine_empty[intro]: "affine {}"
himmelma@33175
   375
  unfolding affine_def by auto
himmelma@33175
   376
himmelma@33175
   377
lemma affine_sing[intro]: "affine {x}"
himmelma@33175
   378
  unfolding affine_alt by (auto simp add: scaleR_left_distrib [symmetric])
himmelma@33175
   379
himmelma@33175
   380
lemma affine_UNIV[intro]: "affine UNIV"
himmelma@33175
   381
  unfolding affine_def by auto
himmelma@33175
   382
himmelma@33175
   383
lemma affine_Inter: "(\<forall>s\<in>f. affine s) \<Longrightarrow> affine (\<Inter> f)"
himmelma@33175
   384
  unfolding affine_def by auto 
himmelma@33175
   385
himmelma@33175
   386
lemma affine_Int: "affine s \<Longrightarrow> affine t \<Longrightarrow> affine (s \<inter> t)"
himmelma@33175
   387
  unfolding affine_def by auto
himmelma@33175
   388
himmelma@33175
   389
lemma affine_affine_hull: "affine(affine hull s)"
huffman@44170
   390
  unfolding hull_def using affine_Inter[of "{t. affine t \<and> s \<subseteq> t}"]
huffman@44170
   391
  by auto
himmelma@33175
   392
himmelma@33175
   393
lemma affine_hull_eq[simp]: "(affine hull s = s) \<longleftrightarrow> affine s"
huffman@44170
   394
by (metis affine_affine_hull hull_same)
himmelma@33175
   395
himmelma@33175
   396
subsection {* Some explicit formulations (from Lars Schewe). *}
himmelma@33175
   397
himmelma@33175
   398
lemma affine: fixes V::"'a::real_vector set"
himmelma@33175
   399
  shows "affine V \<longleftrightarrow> (\<forall>s u. finite s \<and> s \<noteq> {} \<and> s \<subseteq> V \<and> setsum u s = 1 \<longrightarrow> (setsum (\<lambda>x. (u x) *\<^sub>R x)) s \<in> V)"
himmelma@33175
   400
unfolding affine_def apply rule apply(rule, rule, rule) apply(erule conjE)+ 
himmelma@33175
   401
defer apply(rule, rule, rule, rule, rule) proof-
himmelma@33175
   402
  fix x y u v assume as:"x \<in> V" "y \<in> V" "u + v = (1::real)"
himmelma@33175
   403
    "\<forall>s u. finite s \<and> s \<noteq> {} \<and> s \<subseteq> V \<and> setsum u s = 1 \<longrightarrow> (\<Sum>x\<in>s. u x *\<^sub>R x) \<in> V"
himmelma@33175
   404
  thus "u *\<^sub>R x + v *\<^sub>R y \<in> V" apply(cases "x=y")
himmelma@33175
   405
    using as(4)[THEN spec[where x="{x,y}"], THEN spec[where x="\<lambda>w. if w = x then u else v"]] and as(1-3) 
himmelma@33175
   406
    by(auto simp add: scaleR_left_distrib[THEN sym])
himmelma@33175
   407
next
himmelma@33175
   408
  fix s u assume as:"\<forall>x\<in>V. \<forall>y\<in>V. \<forall>u v. u + v = 1 \<longrightarrow> u *\<^sub>R x + v *\<^sub>R y \<in> V"
himmelma@33175
   409
    "finite s" "s \<noteq> {}" "s \<subseteq> V" "setsum u s = (1::real)"
himmelma@33175
   410
  def n \<equiv> "card s"
himmelma@33175
   411
  have "card s = 0 \<or> card s = 1 \<or> card s = 2 \<or> card s > 2" by auto
himmelma@33175
   412
  thus "(\<Sum>x\<in>s. u x *\<^sub>R x) \<in> V" proof(auto simp only: disjE)
himmelma@33175
   413
    assume "card s = 2" hence "card s = Suc (Suc 0)" by auto
himmelma@33175
   414
    then obtain a b where "s = {a, b}" unfolding card_Suc_eq by auto
himmelma@33175
   415
    thus ?thesis using as(1)[THEN bspec[where x=a], THEN bspec[where x=b]] using as(4,5)
himmelma@33175
   416
      by(auto simp add: setsum_clauses(2))
himmelma@33175
   417
  next assume "card s > 2" thus ?thesis using as and n_def proof(induct n arbitrary: u s)
himmelma@33175
   418
      case (Suc n) fix s::"'a set" and u::"'a \<Rightarrow> real"
himmelma@33175
   419
      assume IA:"\<And>u s.  \<lbrakk>2 < card s; \<forall>x\<in>V. \<forall>y\<in>V. \<forall>u v. u + v = 1 \<longrightarrow> u *\<^sub>R x + v *\<^sub>R y \<in> V; finite s;
berghofe@34915
   420
               s \<noteq> {}; s \<subseteq> V; setsum u s = 1; n = card s \<rbrakk> \<Longrightarrow> (\<Sum>x\<in>s. u x *\<^sub>R x) \<in> V" and
berghofe@34915
   421
        as:"Suc n = card s" "2 < card s" "\<forall>x\<in>V. \<forall>y\<in>V. \<forall>u v. u + v = 1 \<longrightarrow> u *\<^sub>R x + v *\<^sub>R y \<in> V"
himmelma@33175
   422
           "finite s" "s \<noteq> {}" "s \<subseteq> V" "setsum u s = 1"
himmelma@33175
   423
      have "\<exists>x\<in>s. u x \<noteq> 1" proof(rule_tac ccontr)
himmelma@33175
   424
        assume " \<not> (\<exists>x\<in>s. u x \<noteq> 1)" hence "setsum u s = real_of_nat (card s)" unfolding card_eq_setsum by auto
himmelma@33175
   425
        thus False using as(7) and `card s > 2` by (metis Numeral1_eq1_nat less_0_number_of less_int_code(15)
himmelma@33175
   426
          less_nat_number_of not_less_iff_gr_or_eq of_nat_1 of_nat_eq_iff pos2 rel_simps(4)) qed
himmelma@33175
   427
      then obtain x where x:"x\<in>s" "u x \<noteq> 1" by auto
himmelma@33175
   428
himmelma@33175
   429
      have c:"card (s - {x}) = card s - 1" apply(rule card_Diff_singleton) using `x\<in>s` as(4) by auto
himmelma@33175
   430
      have *:"s = insert x (s - {x})" "finite (s - {x})" using `x\<in>s` and as(4) by auto
himmelma@33175
   431
      have **:"setsum u (s - {x}) = 1 - u x"
himmelma@33175
   432
        using setsum_clauses(2)[OF *(2), of u x, unfolded *(1)[THEN sym] as(7)] by auto
himmelma@33175
   433
      have ***:"inverse (1 - u x) * setsum u (s - {x}) = 1" unfolding ** using `u x \<noteq> 1` by auto
himmelma@33175
   434
      have "(\<Sum>xa\<in>s - {x}. (inverse (1 - u x) * u xa) *\<^sub>R xa) \<in> V" proof(cases "card (s - {x}) > 2")
himmelma@33175
   435
        case True hence "s - {x} \<noteq> {}" "card (s - {x}) = n" unfolding c and as(1)[symmetric] proof(rule_tac ccontr) 
himmelma@33175
   436
          assume "\<not> s - {x} \<noteq> {}" hence "card (s - {x}) = 0" unfolding card_0_eq[OF *(2)] by simp 
himmelma@33175
   437
          thus False using True by auto qed auto
himmelma@33175
   438
        thus ?thesis apply(rule_tac IA[of "s - {x}" "\<lambda>y. (inverse (1 - u x) * u y)"])
himmelma@33175
   439
        unfolding setsum_right_distrib[THEN sym] using as and *** and True by auto
himmelma@33175
   440
      next case False hence "card (s - {x}) = Suc (Suc 0)" using as(2) and c by auto
himmelma@33175
   441
        then obtain a b where "(s - {x}) = {a, b}" "a\<noteq>b" unfolding card_Suc_eq by auto
himmelma@33175
   442
        thus ?thesis using as(3)[THEN bspec[where x=a], THEN bspec[where x=b]]
himmelma@33175
   443
          using *** *(2) and `s \<subseteq> V` unfolding setsum_right_distrib by(auto simp add: setsum_clauses(2)) qed
hoelzl@37489
   444
      hence "u x + (1 - u x) = 1 \<Longrightarrow> u x *\<^sub>R x + (1 - u x) *\<^sub>R ((\<Sum>xa\<in>s - {x}. u xa *\<^sub>R xa) /\<^sub>R (1 - u x)) \<in> V"
hoelzl@37489
   445
        apply-apply(rule as(3)[rule_format]) 
hoelzl@37489
   446
        unfolding  RealVector.scaleR_right.setsum using x(1) as(6) by auto
himmelma@33175
   447
      thus "(\<Sum>x\<in>s. u x *\<^sub>R x) \<in> V" unfolding scaleR_scaleR[THEN sym] and scaleR_right.setsum [symmetric]
himmelma@33175
   448
         apply(subst *) unfolding setsum_clauses(2)[OF *(2)]
hoelzl@37489
   449
         using `u x \<noteq> 1` by auto 
himmelma@33175
   450
    qed auto
himmelma@33175
   451
  next assume "card s = 1" then obtain a where "s={a}" by(auto simp add: card_Suc_eq)
himmelma@33175
   452
    thus ?thesis using as(4,5) by simp
himmelma@33175
   453
  qed(insert `s\<noteq>{}` `finite s`, auto)
himmelma@33175
   454
qed
himmelma@33175
   455
himmelma@33175
   456
lemma affine_hull_explicit:
himmelma@33175
   457
  "affine hull p = {y. \<exists>s u. finite s \<and> s \<noteq> {} \<and> s \<subseteq> p \<and> setsum u s = 1 \<and> setsum (\<lambda>v. (u v) *\<^sub>R v) s = y}"
huffman@44170
   458
  apply(rule hull_unique) apply(subst subset_eq) prefer 3 apply rule unfolding mem_Collect_eq
himmelma@33175
   459
  apply (erule exE)+ apply(erule conjE)+ prefer 2 apply rule proof-
himmelma@33175
   460
  fix x assume "x\<in>p" thus "\<exists>s u. finite s \<and> s \<noteq> {} \<and> s \<subseteq> p \<and> setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = x"
himmelma@33175
   461
    apply(rule_tac x="{x}" in exI, rule_tac x="\<lambda>x. 1" in exI) by auto
himmelma@33175
   462
next
himmelma@33175
   463
  fix t x s u assume as:"p \<subseteq> t" "affine t" "finite s" "s \<noteq> {}" "s \<subseteq> p" "setsum u s = 1" "(\<Sum>v\<in>s. u v *\<^sub>R v) = x" 
himmelma@33175
   464
  thus "x \<in> t" using as(2)[unfolded affine, THEN spec[where x=s], THEN spec[where x=u]] by auto
himmelma@33175
   465
next
himmelma@33175
   466
  show "affine {y. \<exists>s u. finite s \<and> s \<noteq> {} \<and> s \<subseteq> p \<and> setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = y}" unfolding affine_def
himmelma@33175
   467
    apply(rule,rule,rule,rule,rule) unfolding mem_Collect_eq proof-
himmelma@33175
   468
    fix u v ::real assume uv:"u + v = 1"
himmelma@33175
   469
    fix x assume "\<exists>s u. finite s \<and> s \<noteq> {} \<and> s \<subseteq> p \<and> setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = x"
himmelma@33175
   470
    then obtain sx ux where x:"finite sx" "sx \<noteq> {}" "sx \<subseteq> p" "setsum ux sx = 1" "(\<Sum>v\<in>sx. ux v *\<^sub>R v) = x" by auto
himmelma@33175
   471
    fix y assume "\<exists>s u. finite s \<and> s \<noteq> {} \<and> s \<subseteq> p \<and> setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = y"
himmelma@33175
   472
    then obtain sy uy where y:"finite sy" "sy \<noteq> {}" "sy \<subseteq> p" "setsum uy sy = 1" "(\<Sum>v\<in>sy. uy v *\<^sub>R v) = y" by auto
himmelma@33175
   473
    have xy:"finite (sx \<union> sy)" using x(1) y(1) by auto
himmelma@33175
   474
    have **:"(sx \<union> sy) \<inter> sx = sx" "(sx \<union> sy) \<inter> sy = sy" by auto
himmelma@33175
   475
    show "\<exists>s ua. finite s \<and> s \<noteq> {} \<and> s \<subseteq> p \<and> setsum ua s = 1 \<and> (\<Sum>v\<in>s. ua v *\<^sub>R v) = u *\<^sub>R x + v *\<^sub>R y"
himmelma@33175
   476
      apply(rule_tac x="sx \<union> sy" in exI)
himmelma@33175
   477
      apply(rule_tac x="\<lambda>a. (if a\<in>sx then u * ux a else 0) + (if a\<in>sy then v * uy a else 0)" in exI)
himmelma@33175
   478
      unfolding scaleR_left_distrib setsum_addf if_smult scaleR_zero_left  ** setsum_restrict_set[OF xy, THEN sym]
hoelzl@37489
   479
      unfolding scaleR_scaleR[THEN sym] RealVector.scaleR_right.setsum [symmetric] and setsum_right_distrib[THEN sym]
himmelma@33175
   480
      unfolding x y using x(1-3) y(1-3) uv by simp qed qed
himmelma@33175
   481
himmelma@33175
   482
lemma affine_hull_finite:
himmelma@33175
   483
  assumes "finite s"
himmelma@33175
   484
  shows "affine hull s = {y. \<exists>u. setsum u s = 1 \<and> setsum (\<lambda>v. u v *\<^sub>R v) s = y}"
nipkow@39302
   485
  unfolding affine_hull_explicit and set_eq_iff and mem_Collect_eq apply (rule,rule)
himmelma@33175
   486
  apply(erule exE)+ apply(erule conjE)+ defer apply(erule exE) apply(erule conjE) proof-
himmelma@33175
   487
  fix x u assume "setsum u s = 1" "(\<Sum>v\<in>s. u v *\<^sub>R v) = x"
himmelma@33175
   488
  thus "\<exists>sa u. finite sa \<and> \<not> (\<forall>x. (x \<in> sa) = (x \<in> {})) \<and> sa \<subseteq> s \<and> setsum u sa = 1 \<and> (\<Sum>v\<in>sa. u v *\<^sub>R v) = x"
himmelma@33175
   489
    apply(rule_tac x=s in exI, rule_tac x=u in exI) using assms by auto
himmelma@33175
   490
next
himmelma@33175
   491
  fix x t u assume "t \<subseteq> s" hence *:"s \<inter> t = t" by auto
himmelma@33175
   492
  assume "finite t" "\<not> (\<forall>x. (x \<in> t) = (x \<in> {}))" "setsum u t = 1" "(\<Sum>v\<in>t. u v *\<^sub>R v) = x"
himmelma@33175
   493
  thus "\<exists>u. setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = x" apply(rule_tac x="\<lambda>x. if x\<in>t then u x else 0" in exI)
himmelma@33175
   494
    unfolding if_smult scaleR_zero_left and setsum_restrict_set[OF assms, THEN sym] and * by auto qed
himmelma@33175
   495
himmelma@33175
   496
subsection {* Stepping theorems and hence small special cases. *}
himmelma@33175
   497
himmelma@33175
   498
lemma affine_hull_empty[simp]: "affine hull {} = {}"
huffman@44170
   499
  apply(rule hull_unique) by auto
himmelma@33175
   500
himmelma@33175
   501
lemma affine_hull_finite_step:
himmelma@33175
   502
  fixes y :: "'a::real_vector"
himmelma@33175
   503
  shows "(\<exists>u. setsum u {} = w \<and> setsum (\<lambda>x. u x *\<^sub>R x) {} = y) \<longleftrightarrow> w = 0 \<and> y = 0" (is ?th1)
himmelma@33175
   504
  "finite s \<Longrightarrow> (\<exists>u. setsum u (insert a s) = w \<and> setsum (\<lambda>x. u x *\<^sub>R x) (insert a s) = y) \<longleftrightarrow>
himmelma@33175
   505
                (\<exists>v u. setsum u s = w - v \<and> setsum (\<lambda>x. u x *\<^sub>R x) s = y - v *\<^sub>R a)" (is "?as \<Longrightarrow> (?lhs = ?rhs)")
himmelma@33175
   506
proof-
himmelma@33175
   507
  show ?th1 by simp
himmelma@33175
   508
  assume ?as 
himmelma@33175
   509
  { assume ?lhs
himmelma@33175
   510
    then obtain u where u:"setsum u (insert a s) = w \<and> (\<Sum>x\<in>insert a s. u x *\<^sub>R x) = y" by auto
himmelma@33175
   511
    have ?rhs proof(cases "a\<in>s")
himmelma@33175
   512
      case True hence *:"insert a s = s" by auto
himmelma@33175
   513
      show ?thesis using u[unfolded *] apply(rule_tac x=0 in exI) by auto
himmelma@33175
   514
    next
himmelma@33175
   515
      case False thus ?thesis apply(rule_tac x="u a" in exI) using u and `?as` by auto 
himmelma@33175
   516
    qed  } moreover
himmelma@33175
   517
  { assume ?rhs
himmelma@33175
   518
    then obtain v u where vu:"setsum u s = w - v"  "(\<Sum>x\<in>s. u x *\<^sub>R x) = y - v *\<^sub>R a" by auto
himmelma@33175
   519
    have *:"\<And>x M. (if x = a then v else M) *\<^sub>R x = (if x = a then v *\<^sub>R x else M *\<^sub>R x)" by auto
himmelma@33175
   520
    have ?lhs proof(cases "a\<in>s")
himmelma@33175
   521
      case True thus ?thesis
himmelma@33175
   522
        apply(rule_tac x="\<lambda>x. (if x=a then v else 0) + u x" in exI)
himmelma@33175
   523
        unfolding setsum_clauses(2)[OF `?as`]  apply simp
himmelma@33175
   524
        unfolding scaleR_left_distrib and setsum_addf 
himmelma@33175
   525
        unfolding vu and * and scaleR_zero_left
himmelma@33175
   526
        by (auto simp add: setsum_delta[OF `?as`])
himmelma@33175
   527
    next
himmelma@33175
   528
      case False 
himmelma@33175
   529
      hence **:"\<And>x. x \<in> s \<Longrightarrow> u x = (if x = a then v else u x)"
himmelma@33175
   530
               "\<And>x. x \<in> s \<Longrightarrow> u x *\<^sub>R x = (if x = a then v *\<^sub>R x else u x *\<^sub>R x)" by auto
himmelma@33175
   531
      from False show ?thesis
himmelma@33175
   532
        apply(rule_tac x="\<lambda>x. if x=a then v else u x" in exI)
himmelma@33175
   533
        unfolding setsum_clauses(2)[OF `?as`] and * using vu
himmelma@33175
   534
        using setsum_cong2[of s "\<lambda>x. u x *\<^sub>R x" "\<lambda>x. if x = a then v *\<^sub>R x else u x *\<^sub>R x", OF **(2)]
himmelma@33175
   535
        using setsum_cong2[of s u "\<lambda>x. if x = a then v else u x", OF **(1)] by auto  
himmelma@33175
   536
    qed }
himmelma@33175
   537
  ultimately show "?lhs = ?rhs" by blast
himmelma@33175
   538
qed
himmelma@33175
   539
himmelma@33175
   540
lemma affine_hull_2:
himmelma@33175
   541
  fixes a b :: "'a::real_vector"
himmelma@33175
   542
  shows "affine hull {a,b} = {u *\<^sub>R a + v *\<^sub>R b| u v. (u + v = 1)}" (is "?lhs = ?rhs")
himmelma@33175
   543
proof-
himmelma@33175
   544
  have *:"\<And>x y z. z = x - y \<longleftrightarrow> y + z = (x::real)" 
himmelma@33175
   545
         "\<And>x y z. z = x - y \<longleftrightarrow> y + z = (x::'a)" by auto
himmelma@33175
   546
  have "?lhs = {y. \<exists>u. setsum u {a, b} = 1 \<and> (\<Sum>v\<in>{a, b}. u v *\<^sub>R v) = y}"
himmelma@33175
   547
    using affine_hull_finite[of "{a,b}"] by auto
himmelma@33175
   548
  also have "\<dots> = {y. \<exists>v u. u b = 1 - v \<and> u b *\<^sub>R b = y - v *\<^sub>R a}"
himmelma@33175
   549
    by(simp add: affine_hull_finite_step(2)[of "{b}" a]) 
himmelma@33175
   550
  also have "\<dots> = ?rhs" unfolding * by auto
himmelma@33175
   551
  finally show ?thesis by auto
himmelma@33175
   552
qed
himmelma@33175
   553
himmelma@33175
   554
lemma affine_hull_3:
himmelma@33175
   555
  fixes a b c :: "'a::real_vector"
himmelma@33175
   556
  shows "affine hull {a,b,c} = { u *\<^sub>R a + v *\<^sub>R b + w *\<^sub>R c| u v w. u + v + w = 1}" (is "?lhs = ?rhs")
himmelma@33175
   557
proof-
himmelma@33175
   558
  have *:"\<And>x y z. z = x - y \<longleftrightarrow> y + z = (x::real)" 
himmelma@33175
   559
         "\<And>x y z. z = x - y \<longleftrightarrow> y + z = (x::'a)" by auto
himmelma@33175
   560
  show ?thesis apply(simp add: affine_hull_finite affine_hull_finite_step)
himmelma@33175
   561
    unfolding * apply auto
himmelma@33175
   562
    apply(rule_tac x=v in exI) apply(rule_tac x=va in exI) apply auto
himmelma@33175
   563
    apply(rule_tac x=u in exI) by(auto intro!: exI)
himmelma@33175
   564
qed
himmelma@33175
   565
hoelzl@40377
   566
lemma mem_affine:
hoelzl@40377
   567
  assumes "affine S" "x : S" "y : S" "u+v=1"
hoelzl@40377
   568
  shows "(u *\<^sub>R x + v *\<^sub>R y) : S"
hoelzl@40377
   569
  using assms affine_def[of S] by auto
hoelzl@40377
   570
hoelzl@40377
   571
lemma mem_affine_3:
hoelzl@40377
   572
  assumes "affine S" "x : S" "y : S" "z : S" "u+v+w=1"
hoelzl@40377
   573
  shows "(u *\<^sub>R x + v *\<^sub>R y + w *\<^sub>R z) : S"
hoelzl@40377
   574
proof-
hoelzl@40377
   575
have "(u *\<^sub>R x + v *\<^sub>R y + w *\<^sub>R z) : affine hull {x, y, z}"
hoelzl@40377
   576
  using affine_hull_3[of x y z] assms by auto
hoelzl@40377
   577
moreover have " affine hull {x, y, z} <= affine hull S" 
hoelzl@40377
   578
  using hull_mono[of "{x, y, z}" "S"] assms by auto
hoelzl@40377
   579
moreover have "affine hull S = S" 
hoelzl@40377
   580
  using assms affine_hull_eq[of S] by auto
hoelzl@40377
   581
ultimately show ?thesis by auto 
hoelzl@40377
   582
qed
hoelzl@40377
   583
hoelzl@40377
   584
lemma mem_affine_3_minus:
hoelzl@40377
   585
  assumes "affine S" "x : S" "y : S" "z : S"
hoelzl@40377
   586
  shows "x + v *\<^sub>R (y-z) : S"
hoelzl@40377
   587
using mem_affine_3[of S x y z 1 v "-v"] assms by (simp add: algebra_simps)
hoelzl@40377
   588
hoelzl@40377
   589
himmelma@33175
   590
subsection {* Some relations between affine hull and subspaces. *}
himmelma@33175
   591
himmelma@33175
   592
lemma affine_hull_insert_subset_span:
himmelma@33175
   593
  shows "affine hull (insert a s) \<subseteq> {a + v| v . v \<in> span {x - a | x . x \<in> s}}"
hoelzl@37489
   594
  unfolding subset_eq Ball_def unfolding affine_hull_explicit span_explicit mem_Collect_eq
himmelma@33175
   595
  apply(rule,rule) apply(erule exE)+ apply(erule conjE)+ proof-
himmelma@33175
   596
  fix x t u assume as:"finite t" "t \<noteq> {}" "t \<subseteq> insert a s" "setsum u t = 1" "(\<Sum>v\<in>t. u v *\<^sub>R v) = x"
himmelma@33175
   597
  have "(\<lambda>x. x - a) ` (t - {a}) \<subseteq> {x - a |x. x \<in> s}" using as(3) by auto
himmelma@33175
   598
  thus "\<exists>v. x = a + v \<and> (\<exists>S u. finite S \<and> S \<subseteq> {x - a |x. x \<in> s} \<and> (\<Sum>v\<in>S. u v *\<^sub>R v) = v)"
himmelma@33175
   599
    apply(rule_tac x="x - a" in exI)
himmelma@33175
   600
    apply (rule conjI, simp)
himmelma@33175
   601
    apply(rule_tac x="(\<lambda>x. x - a) ` (t - {a})" in exI)
himmelma@33175
   602
    apply(rule_tac x="\<lambda>x. u (x + a)" in exI)
himmelma@33175
   603
    apply (rule conjI) using as(1) apply simp
himmelma@33175
   604
    apply (erule conjI)
himmelma@33175
   605
    using as(1)
himmelma@33175
   606
    apply (simp add: setsum_reindex[unfolded inj_on_def] scaleR_right_diff_distrib setsum_subtractf scaleR_left.setsum[THEN sym] setsum_diff1 scaleR_left_diff_distrib)
himmelma@33175
   607
    unfolding as by simp qed
himmelma@33175
   608
himmelma@33175
   609
lemma affine_hull_insert_span:
himmelma@33175
   610
  assumes "a \<notin> s"
himmelma@33175
   611
  shows "affine hull (insert a s) =
himmelma@33175
   612
            {a + v | v . v \<in> span {x - a | x.  x \<in> s}}"
himmelma@33175
   613
  apply(rule, rule affine_hull_insert_subset_span) unfolding subset_eq Ball_def
himmelma@33175
   614
  unfolding affine_hull_explicit and mem_Collect_eq proof(rule,rule,erule exE,erule conjE)
himmelma@33175
   615
  fix y v assume "y = a + v" "v \<in> span {x - a |x. x \<in> s}"
hoelzl@37489
   616
  then obtain t u where obt:"finite t" "t \<subseteq> {x - a |x. x \<in> s}" "a + (\<Sum>v\<in>t. u v *\<^sub>R v) = y" unfolding span_explicit by auto
himmelma@33175
   617
  def f \<equiv> "(\<lambda>x. x + a) ` t"
himmelma@33175
   618
  have f:"finite f" "f \<subseteq> s" "(\<Sum>v\<in>f. u (v - a) *\<^sub>R (v - a)) = y - a" unfolding f_def using obt 
himmelma@33175
   619
    by(auto simp add: setsum_reindex[unfolded inj_on_def])
himmelma@33175
   620
  have *:"f \<inter> {a} = {}" "f \<inter> - {a} = f" using f(2) assms by auto
himmelma@33175
   621
  show "\<exists>sa u. finite sa \<and> sa \<noteq> {} \<and> sa \<subseteq> insert a s \<and> setsum u sa = 1 \<and> (\<Sum>v\<in>sa. u v *\<^sub>R v) = y"
himmelma@33175
   622
    apply(rule_tac x="insert a f" in exI)
himmelma@33175
   623
    apply(rule_tac x="\<lambda>x. if x=a then 1 - setsum (\<lambda>x. u (x - a)) f else u (x - a)" in exI)
himmelma@33175
   624
    using assms and f unfolding setsum_clauses(2)[OF f(1)] and if_smult
hoelzl@35577
   625
    unfolding setsum_cases[OF f(1), of "\<lambda>x. x = a"]
hoelzl@35577
   626
    by (auto simp add: setsum_subtractf scaleR_left.setsum algebra_simps *) qed
himmelma@33175
   627
himmelma@33175
   628
lemma affine_hull_span:
himmelma@33175
   629
  assumes "a \<in> s"
himmelma@33175
   630
  shows "affine hull s = {a + v | v. v \<in> span {x - a | x. x \<in> s - {a}}}"
himmelma@33175
   631
  using affine_hull_insert_span[of a "s - {a}", unfolded insert_Diff[OF assms]] by auto
himmelma@33175
   632
hoelzl@40377
   633
subsection{* Parallel Affine Sets *}
hoelzl@40377
   634
hoelzl@40377
   635
definition affine_parallel :: "'a::real_vector set => 'a::real_vector set => bool"
hoelzl@40377
   636
where "affine_parallel S T = (? a. T = ((%x. a + x) ` S))"
hoelzl@40377
   637
hoelzl@40377
   638
lemma affine_parallel_expl_aux:
hoelzl@40377
   639
   fixes S T :: "'a::real_vector set"
hoelzl@40377
   640
   assumes "!x. (x : S <-> (a+x) : T)" 
hoelzl@40377
   641
   shows "T = ((%x. a + x) ` S)"
hoelzl@40377
   642
proof-
hoelzl@40377
   643
{ fix x assume "x : T" hence "(-a)+x : S" using assms by auto
hoelzl@40377
   644
  hence " x : ((%x. a + x) ` S)" using imageI[of "-a+x" S "(%x. a+x)"] by auto}
hoelzl@40377
   645
moreover have "T >= ((%x. a + x) ` S)" using assms by auto 
hoelzl@40377
   646
ultimately show ?thesis by auto
hoelzl@40377
   647
qed
hoelzl@40377
   648
hoelzl@40377
   649
lemma affine_parallel_expl: 
hoelzl@40377
   650
   "affine_parallel S T = (? a. !x. (x : S <-> (a+x) : T))" 
hoelzl@40377
   651
   unfolding affine_parallel_def using affine_parallel_expl_aux[of S _ T] by auto
hoelzl@40377
   652
hoelzl@40377
   653
lemma affine_parallel_reflex: "affine_parallel S S" unfolding affine_parallel_def apply (rule exI[of _ "0"]) by auto
hoelzl@40377
   654
hoelzl@40377
   655
lemma affine_parallel_commut:
hoelzl@40377
   656
assumes "affine_parallel A B" shows "affine_parallel B A" 
hoelzl@40377
   657
proof-
hoelzl@40377
   658
from assms obtain a where "B=((%x. a + x) ` A)" unfolding affine_parallel_def by auto 
hoelzl@40377
   659
from this show ?thesis using translation_galois[of B a A] unfolding affine_parallel_def by auto
hoelzl@40377
   660
qed
hoelzl@40377
   661
hoelzl@40377
   662
lemma affine_parallel_assoc:
hoelzl@40377
   663
assumes "affine_parallel A B" "affine_parallel B C"
hoelzl@40377
   664
shows "affine_parallel A C" 
hoelzl@40377
   665
proof-
hoelzl@40377
   666
from assms obtain ab where "B=((%x. ab + x) ` A)" unfolding affine_parallel_def by auto 
hoelzl@40377
   667
moreover 
hoelzl@40377
   668
from assms obtain bc where "C=((%x. bc + x) ` B)" unfolding affine_parallel_def by auto
hoelzl@40377
   669
ultimately show ?thesis using translation_assoc[of bc ab A] unfolding affine_parallel_def by auto 
hoelzl@40377
   670
qed
hoelzl@40377
   671
hoelzl@40377
   672
lemma affine_translation_aux:
hoelzl@40377
   673
  fixes a :: "'a::real_vector"
hoelzl@40377
   674
  assumes "affine ((%x. a + x) ` S)" shows "affine S"
hoelzl@40377
   675
proof-
hoelzl@40377
   676
{ fix x y u v
hoelzl@40377
   677
  assume xy: "x : S" "y : S" "(u :: real)+v=1"
hoelzl@40377
   678
  hence "(a+x):((%x. a + x) ` S)" "(a+y):((%x. a + x) ` S)" by auto
hoelzl@40377
   679
  hence h1: "u *\<^sub>R  (a+x) + v *\<^sub>R (a+y) : ((%x. a + x) ` S)" using xy assms unfolding affine_def by auto
hoelzl@40377
   680
  have "u *\<^sub>R (a+x) + v *\<^sub>R (a+y) = (u+v) *\<^sub>R a + (u *\<^sub>R x + v *\<^sub>R y)" by (simp add:algebra_simps)
hoelzl@40377
   681
  also have "...= a + (u *\<^sub>R x + v *\<^sub>R y)" using `u+v=1` by auto
hoelzl@40377
   682
  ultimately have "a + (u *\<^sub>R x + v *\<^sub>R y) : ((%x. a + x) ` S)" using h1 by auto
hoelzl@40377
   683
  hence "u *\<^sub>R x + v *\<^sub>R y : S" by auto
hoelzl@40377
   684
} from this show ?thesis unfolding affine_def by auto
hoelzl@40377
   685
qed
hoelzl@40377
   686
hoelzl@40377
   687
lemma affine_translation:
hoelzl@40377
   688
  fixes a :: "'a::real_vector"
hoelzl@40377
   689
  shows "affine S <-> affine ((%x. a + x) ` S)"
hoelzl@40377
   690
proof-
hoelzl@40377
   691
have "affine S ==> affine ((%x. a + x) ` S)" using affine_translation_aux[of "-a" "((%x. a + x) ` S)"]  using translation_assoc[of "-a" a S] by auto
hoelzl@40377
   692
from this show ?thesis using affine_translation_aux by auto
hoelzl@40377
   693
qed
hoelzl@40377
   694
hoelzl@40377
   695
lemma parallel_is_affine:
hoelzl@40377
   696
fixes S T :: "'a::real_vector set"
hoelzl@40377
   697
assumes "affine S" "affine_parallel S T"
hoelzl@40377
   698
shows "affine T"
hoelzl@40377
   699
proof-
hoelzl@40377
   700
  from assms obtain a where "T=((%x. a + x) ` S)" unfolding affine_parallel_def by auto 
hoelzl@40377
   701
  from this show ?thesis using affine_translation assms by auto
hoelzl@40377
   702
qed
hoelzl@40377
   703
huffman@44361
   704
lemma subspace_imp_affine: "subspace s \<Longrightarrow> affine s"
hoelzl@40377
   705
  unfolding subspace_def affine_def by auto
hoelzl@40377
   706
hoelzl@40377
   707
subsection{* Subspace Parallel to an Affine Set *}
hoelzl@40377
   708
hoelzl@40377
   709
lemma subspace_affine:
hoelzl@40377
   710
  shows "subspace S <-> (affine S & 0 : S)"
hoelzl@40377
   711
proof-
hoelzl@40377
   712
have h0: "subspace S ==> (affine S & 0 : S)" using subspace_imp_affine[of S] subspace_0 by auto
hoelzl@40377
   713
{ assume assm: "affine S & 0 : S"
hoelzl@40377
   714
  { fix c :: real 
hoelzl@40377
   715
    fix x assume x_def: "x : S"
hoelzl@40377
   716
    have "c *\<^sub>R x = (1-c) *\<^sub>R 0 + c *\<^sub>R x" by auto
hoelzl@40377
   717
    moreover have "(1-c) *\<^sub>R 0 + c *\<^sub>R x : S" using affine_alt[of S] assm x_def by auto
hoelzl@40377
   718
    ultimately have "c *\<^sub>R x : S" by auto
hoelzl@40377
   719
  } hence h1: "!c. !x : S. c *\<^sub>R x : S" by auto
hoelzl@40377
   720
  { fix x y assume xy_def: "x : S" "y : S"
hoelzl@40377
   721
    def u == "(1 :: real)/2"
hoelzl@40377
   722
    have "(1/2) *\<^sub>R (x+y) = (1/2) *\<^sub>R (x+y)" by auto
hoelzl@40377
   723
    moreover have "(1/2) *\<^sub>R (x+y)=(1/2) *\<^sub>R x + (1-(1/2)) *\<^sub>R y" by (simp add: algebra_simps)
hoelzl@40377
   724
    moreover have "(1-u) *\<^sub>R x + u *\<^sub>R y : S" using affine_alt[of S] assm xy_def by auto
hoelzl@40377
   725
    ultimately have "(1/2) *\<^sub>R (x+y) : S" using u_def by auto
hoelzl@40377
   726
    moreover have "(x+y) = 2 *\<^sub>R ((1/2) *\<^sub>R (x+y))" by auto
hoelzl@40377
   727
    ultimately have "(x+y) : S" using h1[rule_format, of "(1/2) *\<^sub>R (x+y)" "2"] by auto
hoelzl@40377
   728
  } hence "!x : S. !y : S. (x+y) : S" by auto 
hoelzl@40377
   729
  hence "subspace S" using h1 assm unfolding subspace_def by auto
hoelzl@40377
   730
} from this show ?thesis using h0 by metis
hoelzl@40377
   731
qed
hoelzl@40377
   732
hoelzl@40377
   733
lemma affine_diffs_subspace:
hoelzl@40377
   734
  assumes "affine S" "a : S"
hoelzl@40377
   735
  shows "subspace ((%x. (-a)+x) ` S)"
hoelzl@40377
   736
proof-
hoelzl@40377
   737
have "affine ((%x. (-a)+x) ` S)" using  affine_translation assms by auto  
hoelzl@40377
   738
moreover have "0 : ((%x. (-a)+x) ` S)" using assms exI[of "(%x. x:S & -a+x=0)" a] by auto
hoelzl@40377
   739
ultimately show ?thesis using subspace_affine by auto 
hoelzl@40377
   740
qed
hoelzl@40377
   741
hoelzl@40377
   742
lemma parallel_subspace_explicit:
hoelzl@40377
   743
assumes "affine S" "a : S"
hoelzl@40377
   744
assumes "L == {y. ? x : S. (-a)+x=y}" 
hoelzl@40377
   745
shows "subspace L & affine_parallel S L" 
hoelzl@40377
   746
proof-
hoelzl@40377
   747
have par: "affine_parallel S L" unfolding affine_parallel_def using assms by auto
hoelzl@40377
   748
hence "affine L" using assms parallel_is_affine by auto  
hoelzl@40377
   749
moreover have "0 : L" using assms apply auto using exI[of "(%x. x:S & -a+x=0)" a] by auto
hoelzl@40377
   750
ultimately show ?thesis using subspace_affine par by auto 
hoelzl@40377
   751
qed
hoelzl@40377
   752
hoelzl@40377
   753
lemma parallel_subspace_aux:
hoelzl@40377
   754
assumes "subspace A" "subspace B" "affine_parallel A B"
hoelzl@40377
   755
shows "A>=B"
hoelzl@40377
   756
proof-
hoelzl@40377
   757
from assms obtain a where a_def: "!x. (x : A <-> (a+x) : B)" using affine_parallel_expl[of A B] by auto
hoelzl@40377
   758
hence "-a : A" using assms subspace_0[of B] by auto
hoelzl@40377
   759
hence "a : A" using assms subspace_neg[of A "-a"] by auto
hoelzl@40377
   760
from this show ?thesis using assms a_def unfolding subspace_def by auto
hoelzl@40377
   761
qed
hoelzl@40377
   762
hoelzl@40377
   763
lemma parallel_subspace:
hoelzl@40377
   764
assumes "subspace A" "subspace B" "affine_parallel A B"
hoelzl@40377
   765
shows "A=B"
hoelzl@40377
   766
proof-
hoelzl@40377
   767
have "A>=B" using assms parallel_subspace_aux by auto
hoelzl@40377
   768
moreover have "A<=B" using assms parallel_subspace_aux[of B A] affine_parallel_commut by auto
hoelzl@40377
   769
ultimately show ?thesis by auto  
hoelzl@40377
   770
qed
hoelzl@40377
   771
hoelzl@40377
   772
lemma affine_parallel_subspace:
hoelzl@40377
   773
assumes "affine S" "S ~= {}"
hoelzl@40377
   774
shows "?!L. subspace L & affine_parallel S L" 
hoelzl@40377
   775
proof-
hoelzl@40377
   776
have ex: "? L. subspace L & affine_parallel S L" using assms  parallel_subspace_explicit by auto 
hoelzl@40377
   777
{ fix L1 L2 assume ass: "subspace L1 & affine_parallel S L1" "subspace L2 & affine_parallel S L2"
hoelzl@40377
   778
  hence "affine_parallel L1 L2" using affine_parallel_commut[of S L1] affine_parallel_assoc[of L1 S L2] by auto
hoelzl@40377
   779
  hence "L1=L2" using ass parallel_subspace by auto
hoelzl@40377
   780
} from this show ?thesis using ex by auto
hoelzl@40377
   781
qed
hoelzl@40377
   782
himmelma@33175
   783
subsection {* Cones. *}
himmelma@33175
   784
himmelma@33175
   785
definition
himmelma@33175
   786
  cone :: "'a::real_vector set \<Rightarrow> bool" where
himmelma@33175
   787
  "cone s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>c\<ge>0. (c *\<^sub>R x) \<in> s)"
himmelma@33175
   788
himmelma@33175
   789
lemma cone_empty[intro, simp]: "cone {}"
himmelma@33175
   790
  unfolding cone_def by auto
himmelma@33175
   791
himmelma@33175
   792
lemma cone_univ[intro, simp]: "cone UNIV"
himmelma@33175
   793
  unfolding cone_def by auto
himmelma@33175
   794
himmelma@33175
   795
lemma cone_Inter[intro]: "(\<forall>s\<in>f. cone s) \<Longrightarrow> cone(\<Inter> f)"
himmelma@33175
   796
  unfolding cone_def by auto
himmelma@33175
   797
himmelma@33175
   798
subsection {* Conic hull. *}
himmelma@33175
   799
himmelma@33175
   800
lemma cone_cone_hull: "cone (cone hull s)"
huffman@44170
   801
  unfolding hull_def by auto
himmelma@33175
   802
himmelma@33175
   803
lemma cone_hull_eq: "(cone hull s = s) \<longleftrightarrow> cone s"
huffman@44170
   804
  apply(rule hull_eq)
huffman@44170
   805
  using cone_Inter unfolding subset_eq by auto
himmelma@33175
   806
hoelzl@40377
   807
lemma mem_cone:
hoelzl@40377
   808
  assumes "cone S" "x : S" "c>=0"
hoelzl@40377
   809
  shows "c *\<^sub>R x : S"
hoelzl@40377
   810
  using assms cone_def[of S] by auto
hoelzl@40377
   811
hoelzl@40377
   812
lemma cone_contains_0:
hoelzl@40377
   813
assumes "cone S"
hoelzl@40377
   814
shows "(S ~= {}) <-> (0 : S)"
hoelzl@40377
   815
proof-
hoelzl@40377
   816
{ assume "S ~= {}" from this obtain a where "a:S" by auto
hoelzl@40377
   817
  hence "0 : S" using assms mem_cone[of S a 0] by auto
hoelzl@40377
   818
} from this show ?thesis by auto
hoelzl@40377
   819
qed
hoelzl@40377
   820
huffman@44361
   821
lemma cone_0: "cone {0}"
hoelzl@40377
   822
unfolding cone_def by auto
hoelzl@40377
   823
hoelzl@40377
   824
lemma cone_Union[intro]: "(!s:f. cone s) --> (cone (Union f))"
hoelzl@40377
   825
  unfolding cone_def by blast
hoelzl@40377
   826
hoelzl@40377
   827
lemma cone_iff:
hoelzl@40377
   828
assumes "S ~= {}"
hoelzl@40377
   829
shows "cone S <-> 0:S & (!c. c>0 --> ((op *\<^sub>R c) ` S) = S)"
hoelzl@40377
   830
proof-
hoelzl@40377
   831
{ assume "cone S"
hoelzl@40377
   832
  { fix c assume "(c :: real)>0"
hoelzl@40377
   833
    { fix x assume "x : S" hence "x : (op *\<^sub>R c) ` S" unfolding image_def
hoelzl@40377
   834
        using `cone S` `c>0` mem_cone[of S x "1/c"]
hoelzl@40377
   835
        exI[of "(%t. t:S & x = c *\<^sub>R t)" "(1 / c) *\<^sub>R x"] by auto
hoelzl@40377
   836
    }
hoelzl@40377
   837
    moreover
hoelzl@40377
   838
    { fix x assume "x : (op *\<^sub>R c) ` S"
hoelzl@40377
   839
      (*from this obtain t where "t:S & x = c *\<^sub>R t" by auto*)
hoelzl@40377
   840
      hence "x:S" using `cone S` `c>0` unfolding cone_def image_def `c>0` by auto
hoelzl@40377
   841
    }
hoelzl@40377
   842
    ultimately have "((op *\<^sub>R c) ` S) = S" by auto
hoelzl@40377
   843
  } hence "0:S & (!c. c>0 --> ((op *\<^sub>R c) ` S) = S)" using `cone S` cone_contains_0[of S] assms by auto
hoelzl@40377
   844
}
hoelzl@40377
   845
moreover
hoelzl@40377
   846
{ assume a: "0:S & (!c. c>0 --> ((op *\<^sub>R c) ` S) = S)"
hoelzl@40377
   847
  { fix x assume "x:S"
hoelzl@40377
   848
    fix c1 assume "(c1 :: real)>=0"
hoelzl@40377
   849
    hence "(c1=0) | (c1>0)" by auto
hoelzl@40377
   850
    hence "c1 *\<^sub>R x : S" using a `x:S` by auto
hoelzl@40377
   851
  }
hoelzl@40377
   852
 hence "cone S" unfolding cone_def by auto
hoelzl@40377
   853
} ultimately show ?thesis by blast
hoelzl@40377
   854
qed
hoelzl@40377
   855
hoelzl@40377
   856
lemma cone_hull_empty:
hoelzl@40377
   857
"cone hull {} = {}"
hoelzl@40377
   858
by (metis cone_empty cone_hull_eq)
hoelzl@40377
   859
hoelzl@40377
   860
lemma cone_hull_empty_iff:
hoelzl@40377
   861
shows "(S = {}) <-> (cone hull S = {})"
hoelzl@40377
   862
by (metis bot_least cone_hull_empty hull_subset xtrans(5))
hoelzl@40377
   863
hoelzl@40377
   864
lemma cone_hull_contains_0: 
hoelzl@40377
   865
shows "(S ~= {}) <-> (0 : cone hull S)"
hoelzl@40377
   866
using cone_cone_hull[of S] cone_contains_0[of "cone hull S"] cone_hull_empty_iff[of S] by auto
hoelzl@40377
   867
hoelzl@40377
   868
lemma mem_cone_hull:
hoelzl@40377
   869
  assumes "x : S" "c>=0"
hoelzl@40377
   870
  shows "c *\<^sub>R x : cone hull S"
huffman@44170
   871
by (metis assms cone_cone_hull hull_inc mem_cone)
hoelzl@40377
   872
hoelzl@40377
   873
lemma cone_hull_expl:
hoelzl@40377
   874
shows "cone hull S = {c *\<^sub>R x | c x. c>=0 & x : S}" (is "?lhs = ?rhs")
hoelzl@40377
   875
proof-
hoelzl@40377
   876
{ fix x assume "x : ?rhs"
hoelzl@40377
   877
  from this obtain cx xx where x_def: "x= cx *\<^sub>R xx & (cx :: real)>=0 & xx : S" by auto
hoelzl@40377
   878
  fix c assume c_def: "(c :: real)>=0"
hoelzl@40377
   879
  hence "c *\<^sub>R x = (c*cx) *\<^sub>R xx" using x_def by (simp add: algebra_simps)
hoelzl@40377
   880
  moreover have "(c*cx) >= 0" using c_def x_def using mult_nonneg_nonneg by auto
hoelzl@40377
   881
  ultimately have "c *\<^sub>R x : ?rhs" using x_def by auto
hoelzl@40377
   882
} hence "cone ?rhs" unfolding cone_def by auto
huffman@44170
   883
  hence "?rhs : Collect cone" unfolding mem_Collect_eq by auto
hoelzl@40377
   884
{ fix x assume "x : S" hence "1 *\<^sub>R x : ?rhs" apply auto apply(rule_tac x="1" in exI) by auto
hoelzl@40377
   885
  hence "x : ?rhs" by auto
hoelzl@40377
   886
} hence "S <= ?rhs" by auto
huffman@44170
   887
hence "?lhs <= ?rhs" using `?rhs : Collect cone` hull_minimal[of S "?rhs" "cone"] by auto
hoelzl@40377
   888
moreover
hoelzl@40377
   889
{ fix x assume "x : ?rhs"
hoelzl@40377
   890
  from this obtain cx xx where x_def: "x= cx *\<^sub>R xx & (cx :: real)>=0 & xx : S" by auto
hoelzl@40377
   891
  hence "xx : cone hull S" using hull_subset[of S] by auto
hoelzl@40377
   892
  hence "x : ?lhs" using x_def cone_cone_hull[of S] cone_def[of "cone hull S"] by auto
hoelzl@40377
   893
} ultimately show ?thesis by auto
hoelzl@40377
   894
qed
hoelzl@40377
   895
hoelzl@40377
   896
lemma cone_closure:
hoelzl@40377
   897
fixes S :: "('m::euclidean_space) set"
hoelzl@40377
   898
assumes "cone S"
hoelzl@40377
   899
shows "cone (closure S)"
hoelzl@40377
   900
proof-
hoelzl@40377
   901
{ assume "S = {}" hence ?thesis by auto }
hoelzl@40377
   902
moreover
hoelzl@40377
   903
{ assume "S ~= {}" hence "0:S & (!c. c>0 --> op *\<^sub>R c ` S = S)" using cone_iff[of S] assms by auto
hoelzl@40377
   904
  hence "0:(closure S) & (!c. c>0 --> op *\<^sub>R c ` (closure S) = (closure S))"
hoelzl@40377
   905
     using closure_subset by (auto simp add: closure_scaleR)
hoelzl@40377
   906
  hence ?thesis using cone_iff[of "closure S"] by auto
hoelzl@40377
   907
}
hoelzl@40377
   908
ultimately show ?thesis by blast
hoelzl@40377
   909
qed
hoelzl@40377
   910
himmelma@33175
   911
subsection {* Affine dependence and consequential theorems (from Lars Schewe). *}
himmelma@33175
   912
himmelma@33175
   913
definition
himmelma@33175
   914
  affine_dependent :: "'a::real_vector set \<Rightarrow> bool" where
himmelma@33175
   915
  "affine_dependent s \<longleftrightarrow> (\<exists>x\<in>s. x \<in> (affine hull (s - {x})))"
himmelma@33175
   916
himmelma@33175
   917
lemma affine_dependent_explicit:
himmelma@33175
   918
  "affine_dependent p \<longleftrightarrow>
himmelma@33175
   919
    (\<exists>s u. finite s \<and> s \<subseteq> p \<and> setsum u s = 0 \<and>
himmelma@33175
   920
    (\<exists>v\<in>s. u v \<noteq> 0) \<and> setsum (\<lambda>v. u v *\<^sub>R v) s = 0)"
himmelma@33175
   921
  unfolding affine_dependent_def affine_hull_explicit mem_Collect_eq apply(rule)
himmelma@33175
   922
  apply(erule bexE,erule exE,erule exE) apply(erule conjE)+ defer apply(erule exE,erule exE) apply(erule conjE)+ apply(erule bexE)
himmelma@33175
   923
proof-
himmelma@33175
   924
  fix x s u assume as:"x \<in> p" "finite s" "s \<noteq> {}" "s \<subseteq> p - {x}" "setsum u s = 1" "(\<Sum>v\<in>s. u v *\<^sub>R v) = x"
himmelma@33175
   925
  have "x\<notin>s" using as(1,4) by auto
himmelma@33175
   926
  show "\<exists>s u. finite s \<and> s \<subseteq> p \<and> setsum u s = 0 \<and> (\<exists>v\<in>s. u v \<noteq> 0) \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = 0"
himmelma@33175
   927
    apply(rule_tac x="insert x s" in exI, rule_tac x="\<lambda>v. if v = x then - 1 else u v" in exI)
himmelma@33175
   928
    unfolding if_smult and setsum_clauses(2)[OF as(2)] and setsum_delta_notmem[OF `x\<notin>s`] and as using as by auto 
himmelma@33175
   929
next
himmelma@33175
   930
  fix s u v assume as:"finite s" "s \<subseteq> p" "setsum u s = 0" "(\<Sum>v\<in>s. u v *\<^sub>R v) = 0" "v \<in> s" "u v \<noteq> 0"
himmelma@33175
   931
  have "s \<noteq> {v}" using as(3,6) by auto
himmelma@33175
   932
  thus "\<exists>x\<in>p. \<exists>s u. finite s \<and> s \<noteq> {} \<and> s \<subseteq> p - {x} \<and> setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = x" 
himmelma@33175
   933
    apply(rule_tac x=v in bexI, rule_tac x="s - {v}" in exI, rule_tac x="\<lambda>x. - (1 / u v) * u x" in exI)
himmelma@33175
   934
    unfolding scaleR_scaleR[THEN sym] and scaleR_right.setsum [symmetric] unfolding setsum_right_distrib[THEN sym] and setsum_diff1[OF as(1)] using as by auto
himmelma@33175
   935
qed
himmelma@33175
   936
himmelma@33175
   937
lemma affine_dependent_explicit_finite:
himmelma@33175
   938
  fixes s :: "'a::real_vector set" assumes "finite s"
himmelma@33175
   939
  shows "affine_dependent s \<longleftrightarrow> (\<exists>u. setsum u s = 0 \<and> (\<exists>v\<in>s. u v \<noteq> 0) \<and> setsum (\<lambda>v. u v *\<^sub>R v) s = 0)"
himmelma@33175
   940
  (is "?lhs = ?rhs")
himmelma@33175
   941
proof
himmelma@33175
   942
  have *:"\<And>vt u v. (if vt then u v else 0) *\<^sub>R v = (if vt then (u v) *\<^sub>R v else (0::'a))" by auto
himmelma@33175
   943
  assume ?lhs
himmelma@33175
   944
  then obtain t u v where "finite t" "t \<subseteq> s" "setsum u t = 0" "v\<in>t" "u v \<noteq> 0"  "(\<Sum>v\<in>t. u v *\<^sub>R v) = 0"
himmelma@33175
   945
    unfolding affine_dependent_explicit by auto
himmelma@33175
   946
  thus ?rhs apply(rule_tac x="\<lambda>x. if x\<in>t then u x else 0" in exI)
himmelma@33175
   947
    apply auto unfolding * and setsum_restrict_set[OF assms, THEN sym]
himmelma@33175
   948
    unfolding Int_absorb1[OF `t\<subseteq>s`] by auto
himmelma@33175
   949
next
himmelma@33175
   950
  assume ?rhs
himmelma@33175
   951
  then obtain u v where "setsum u s = 0"  "v\<in>s" "u v \<noteq> 0" "(\<Sum>v\<in>s. u v *\<^sub>R v) = 0" by auto
himmelma@33175
   952
  thus ?lhs unfolding affine_dependent_explicit using assms by auto
himmelma@33175
   953
qed
himmelma@33175
   954
himmelma@33175
   955
subsection {* A general lemma. *}
himmelma@33175
   956
himmelma@33175
   957
lemma convex_connected:
himmelma@33175
   958
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
   959
  assumes "convex s" shows "connected s"
himmelma@33175
   960
proof-
himmelma@33175
   961
  { fix e1 e2 assume as:"open e1" "open e2" "e1 \<inter> e2 \<inter> s = {}" "s \<subseteq> e1 \<union> e2" 
himmelma@33175
   962
    assume "e1 \<inter> s \<noteq> {}" "e2 \<inter> s \<noteq> {}"
himmelma@33175
   963
    then obtain x1 x2 where x1:"x1\<in>e1" "x1\<in>s" and x2:"x2\<in>e2" "x2\<in>s" by auto
himmelma@33175
   964
    hence n:"norm (x1 - x2) > 0" unfolding zero_less_norm_iff using as(3) by auto
himmelma@33175
   965
himmelma@33175
   966
    { fix x e::real assume as:"0 \<le> x" "x \<le> 1" "0 < e"
himmelma@33175
   967
      { fix y have *:"(1 - x) *\<^sub>R x1 + x *\<^sub>R x2 - ((1 - y) *\<^sub>R x1 + y *\<^sub>R x2) = (y - x) *\<^sub>R x1 - (y - x) *\<^sub>R x2"
himmelma@33175
   968
          by (simp add: algebra_simps)
himmelma@33175
   969
        assume "\<bar>y - x\<bar> < e / norm (x1 - x2)"
himmelma@33175
   970
        hence "norm ((1 - x) *\<^sub>R x1 + x *\<^sub>R x2 - ((1 - y) *\<^sub>R x1 + y *\<^sub>R x2)) < e"
himmelma@33175
   971
          unfolding * and scaleR_right_diff_distrib[THEN sym]
himmelma@33175
   972
          unfolding less_divide_eq using n by auto  }
himmelma@33175
   973
      hence "\<exists>d>0. \<forall>y. \<bar>y - x\<bar> < d \<longrightarrow> norm ((1 - x) *\<^sub>R x1 + x *\<^sub>R x2 - ((1 - y) *\<^sub>R x1 + y *\<^sub>R x2)) < e"
himmelma@33175
   974
        apply(rule_tac x="e / norm (x1 - x2)" in exI) using as
himmelma@33175
   975
        apply auto unfolding zero_less_divide_iff using n by simp  }  note * = this
himmelma@33175
   976
himmelma@33175
   977
    have "\<exists>x\<ge>0. x \<le> 1 \<and> (1 - x) *\<^sub>R x1 + x *\<^sub>R x2 \<notin> e1 \<and> (1 - x) *\<^sub>R x1 + x *\<^sub>R x2 \<notin> e2"
himmelma@33175
   978
      apply(rule connected_real_lemma) apply (simp add: `x1\<in>e1` `x2\<in>e2` dist_commute)+
himmelma@33175
   979
      using * apply(simp add: dist_norm)
himmelma@33175
   980
      using as(1,2)[unfolded open_dist] apply simp
himmelma@33175
   981
      using as(1,2)[unfolded open_dist] apply simp
himmelma@33175
   982
      using assms[unfolded convex_alt, THEN bspec[where x=x1], THEN bspec[where x=x2]] using x1 x2
himmelma@33175
   983
      using as(3) by auto
himmelma@33175
   984
    then obtain x where "x\<ge>0" "x\<le>1" "(1 - x) *\<^sub>R x1 + x *\<^sub>R x2 \<notin> e1"  "(1 - x) *\<^sub>R x1 + x *\<^sub>R x2 \<notin> e2" by auto
himmelma@33175
   985
    hence False using as(4) 
himmelma@33175
   986
      using assms[unfolded convex_alt, THEN bspec[where x=x1], THEN bspec[where x=x2]]
himmelma@33175
   987
      using x1(2) x2(2) by auto  }
himmelma@33175
   988
  thus ?thesis unfolding connected_def by auto
himmelma@33175
   989
qed
himmelma@33175
   990
himmelma@33175
   991
subsection {* One rather trivial consequence. *}
himmelma@33175
   992
hoelzl@34964
   993
lemma connected_UNIV[intro]: "connected (UNIV :: 'a::real_normed_vector set)"
himmelma@33175
   994
  by(simp add: convex_connected convex_UNIV)
himmelma@33175
   995
hoelzl@36623
   996
subsection {* Balls, being convex, are connected. *}
himmelma@33175
   997
hoelzl@37489
   998
lemma convex_box: fixes a::"'a::euclidean_space"
hoelzl@37489
   999
  assumes "\<And>i. i<DIM('a) \<Longrightarrow> convex {x. P i x}"
hoelzl@37489
  1000
  shows "convex {x. \<forall>i<DIM('a). P i (x$$i)}"
hoelzl@37489
  1001
  using assms unfolding convex_def by(auto simp add:euclidean_simps)
himmelma@33175
  1002
hoelzl@37489
  1003
lemma convex_positive_orthant: "convex {x::'a::euclidean_space. (\<forall>i<DIM('a). 0 \<le> x$$i)}"
hoelzl@36623
  1004
  by (rule convex_box) (simp add: atLeast_def[symmetric] convex_real_interval)
himmelma@33175
  1005
himmelma@33175
  1006
lemma convex_local_global_minimum:
himmelma@33175
  1007
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  1008
  assumes "0<e" "convex_on s f" "ball x e \<subseteq> s" "\<forall>y\<in>ball x e. f x \<le> f y"
himmelma@33175
  1009
  shows "\<forall>y\<in>s. f x \<le> f y"
himmelma@33175
  1010
proof(rule ccontr)
himmelma@33175
  1011
  have "x\<in>s" using assms(1,3) by auto
himmelma@33175
  1012
  assume "\<not> (\<forall>y\<in>s. f x \<le> f y)"
himmelma@33175
  1013
  then obtain y where "y\<in>s" and y:"f x > f y" by auto
himmelma@33175
  1014
  hence xy:"0 < dist x y" by (auto simp add: dist_nz[THEN sym])
himmelma@33175
  1015
himmelma@33175
  1016
  then obtain u where "0 < u" "u \<le> 1" and u:"u < e / dist x y"
himmelma@33175
  1017
    using real_lbound_gt_zero[of 1 "e / dist x y"] using xy `e>0` and divide_pos_pos[of e "dist x y"] by auto
himmelma@33175
  1018
  hence "f ((1-u) *\<^sub>R x + u *\<^sub>R y) \<le> (1-u) * f x + u * f y" using `x\<in>s` `y\<in>s`
himmelma@33175
  1019
    using assms(2)[unfolded convex_on_def, THEN bspec[where x=x], THEN bspec[where x=y], THEN spec[where x="1-u"]] by auto
himmelma@33175
  1020
  moreover
himmelma@33175
  1021
  have *:"x - ((1 - u) *\<^sub>R x + u *\<^sub>R y) = u *\<^sub>R (x - y)" by (simp add: algebra_simps)
himmelma@33175
  1022
  have "(1 - u) *\<^sub>R x + u *\<^sub>R y \<in> ball x e" unfolding mem_ball dist_norm unfolding * and norm_scaleR and abs_of_pos[OF `0<u`] unfolding dist_norm[THEN sym]
himmelma@33175
  1023
    using u unfolding pos_less_divide_eq[OF xy] by auto
himmelma@33175
  1024
  hence "f x \<le> f ((1 - u) *\<^sub>R x + u *\<^sub>R y)" using assms(4) by auto
himmelma@33175
  1025
  ultimately show False using mult_strict_left_mono[OF y `u>0`] unfolding left_diff_distrib by auto
himmelma@33175
  1026
qed
himmelma@33175
  1027
himmelma@33175
  1028
lemma convex_ball:
himmelma@33175
  1029
  fixes x :: "'a::real_normed_vector"
himmelma@33175
  1030
  shows "convex (ball x e)" 
himmelma@33175
  1031
proof(auto simp add: convex_def)
himmelma@33175
  1032
  fix y z assume yz:"dist x y < e" "dist x z < e"
himmelma@33175
  1033
  fix u v ::real assume uv:"0 \<le> u" "0 \<le> v" "u + v = 1"
himmelma@33175
  1034
  have "dist x (u *\<^sub>R y + v *\<^sub>R z) \<le> u * dist x y + v * dist x z" using uv yz
himmelma@33175
  1035
    using convex_distance[of "ball x e" x, unfolded convex_on_def, THEN bspec[where x=y], THEN bspec[where x=z]] by auto
hoelzl@36623
  1036
  thus "dist x (u *\<^sub>R y + v *\<^sub>R z) < e" using convex_bound_lt[OF yz uv] by auto
himmelma@33175
  1037
qed
himmelma@33175
  1038
himmelma@33175
  1039
lemma convex_cball:
himmelma@33175
  1040
  fixes x :: "'a::real_normed_vector"
himmelma@33175
  1041
  shows "convex(cball x e)"
huffman@36362
  1042
proof(auto simp add: convex_def Ball_def)
himmelma@33175
  1043
  fix y z assume yz:"dist x y \<le> e" "dist x z \<le> e"
himmelma@33175
  1044
  fix u v ::real assume uv:" 0 \<le> u" "0 \<le> v" "u + v = 1"
himmelma@33175
  1045
  have "dist x (u *\<^sub>R y + v *\<^sub>R z) \<le> u * dist x y + v * dist x z" using uv yz
himmelma@33175
  1046
    using convex_distance[of "cball x e" x, unfolded convex_on_def, THEN bspec[where x=y], THEN bspec[where x=z]] by auto
hoelzl@36623
  1047
  thus "dist x (u *\<^sub>R y + v *\<^sub>R z) \<le> e" using convex_bound_le[OF yz uv] by auto 
himmelma@33175
  1048
qed
himmelma@33175
  1049
himmelma@33175
  1050
lemma connected_ball:
himmelma@33175
  1051
  fixes x :: "'a::real_normed_vector"
himmelma@33175
  1052
  shows "connected (ball x e)"
himmelma@33175
  1053
  using convex_connected convex_ball by auto
himmelma@33175
  1054
himmelma@33175
  1055
lemma connected_cball:
himmelma@33175
  1056
  fixes x :: "'a::real_normed_vector"
himmelma@33175
  1057
  shows "connected(cball x e)"
himmelma@33175
  1058
  using convex_connected convex_cball by auto
himmelma@33175
  1059
himmelma@33175
  1060
subsection {* Convex hull. *}
himmelma@33175
  1061
himmelma@33175
  1062
lemma convex_convex_hull: "convex(convex hull s)"
huffman@44170
  1063
  unfolding hull_def using convex_Inter[of "{t. convex t \<and> s \<subseteq> t}"]
huffman@44170
  1064
  by auto
himmelma@33175
  1065
haftmann@34064
  1066
lemma convex_hull_eq: "convex hull s = s \<longleftrightarrow> convex s"
huffman@44170
  1067
by (metis convex_convex_hull hull_same)
himmelma@33175
  1068
himmelma@33175
  1069
lemma bounded_convex_hull:
himmelma@33175
  1070
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  1071
  assumes "bounded s" shows "bounded(convex hull s)"
himmelma@33175
  1072
proof- from assms obtain B where B:"\<forall>x\<in>s. norm x \<le> B" unfolding bounded_iff by auto
himmelma@33175
  1073
  show ?thesis apply(rule bounded_subset[OF bounded_cball, of _ 0 B])
huffman@44170
  1074
    unfolding subset_hull[of convex, OF convex_cball]
himmelma@33175
  1075
    unfolding subset_eq mem_cball dist_norm using B by auto qed
himmelma@33175
  1076
himmelma@33175
  1077
lemma finite_imp_bounded_convex_hull:
himmelma@33175
  1078
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  1079
  shows "finite s \<Longrightarrow> bounded(convex hull s)"
himmelma@33175
  1080
  using bounded_convex_hull finite_imp_bounded by auto
himmelma@33175
  1081
hoelzl@40377
  1082
subsection {* Convex hull is "preserved" by a linear function. *}
hoelzl@40377
  1083
hoelzl@40377
  1084
lemma convex_hull_linear_image:
hoelzl@40377
  1085
  assumes "bounded_linear f"
hoelzl@40377
  1086
  shows "f ` (convex hull s) = convex hull (f ` s)"
hoelzl@40377
  1087
  apply rule unfolding subset_eq ball_simps apply(rule_tac[!] hull_induct, rule hull_inc) prefer 3  
hoelzl@40377
  1088
  apply(erule imageE)apply(rule_tac x=xa in image_eqI) apply assumption
hoelzl@40377
  1089
  apply(rule hull_subset[unfolded subset_eq, rule_format]) apply assumption
hoelzl@40377
  1090
proof-
hoelzl@40377
  1091
  interpret f: bounded_linear f by fact
hoelzl@40377
  1092
  show "convex {x. f x \<in> convex hull f ` s}" 
hoelzl@40377
  1093
  unfolding convex_def by(auto simp add: f.scaleR f.add convex_convex_hull[unfolded convex_def, rule_format]) next
hoelzl@40377
  1094
  interpret f: bounded_linear f by fact
hoelzl@40377
  1095
  show "convex {x. x \<in> f ` (convex hull s)}" using  convex_convex_hull[unfolded convex_def, of s] 
hoelzl@40377
  1096
    unfolding convex_def by (auto simp add: f.scaleR [symmetric] f.add [symmetric])
hoelzl@40377
  1097
qed auto
hoelzl@40377
  1098
hoelzl@40377
  1099
lemma in_convex_hull_linear_image:
hoelzl@40377
  1100
  assumes "bounded_linear f" "x \<in> convex hull s"
hoelzl@40377
  1101
  shows "(f x) \<in> convex hull (f ` s)"
hoelzl@40377
  1102
using convex_hull_linear_image[OF assms(1)] assms(2) by auto
hoelzl@40377
  1103
himmelma@33175
  1104
subsection {* Stepping theorems for convex hulls of finite sets. *}
himmelma@33175
  1105
himmelma@33175
  1106
lemma convex_hull_empty[simp]: "convex hull {} = {}"
huffman@44170
  1107
  apply(rule hull_unique) by auto
himmelma@33175
  1108
himmelma@33175
  1109
lemma convex_hull_singleton[simp]: "convex hull {a} = {a}"
huffman@44170
  1110
  apply(rule hull_unique) by auto
himmelma@33175
  1111
himmelma@33175
  1112
lemma convex_hull_insert:
himmelma@33175
  1113
  fixes s :: "'a::real_vector set"
himmelma@33175
  1114
  assumes "s \<noteq> {}"
himmelma@33175
  1115
  shows "convex hull (insert a s) = {x. \<exists>u\<ge>0. \<exists>v\<ge>0. \<exists>b. (u + v = 1) \<and>
himmelma@33175
  1116
                                    b \<in> (convex hull s) \<and> (x = u *\<^sub>R a + v *\<^sub>R b)}" (is "?xyz = ?hull")
huffman@44170
  1117
 apply(rule,rule hull_minimal,rule) unfolding insert_iff prefer 3 apply rule proof-
himmelma@33175
  1118
 fix x assume x:"x = a \<or> x \<in> s"
himmelma@33175
  1119
 thus "x\<in>?hull" apply rule unfolding mem_Collect_eq apply(rule_tac x=1 in exI) defer 
himmelma@33175
  1120
   apply(rule_tac x=0 in exI) using assms hull_subset[of s convex] by auto
himmelma@33175
  1121
next
himmelma@33175
  1122
  fix x assume "x\<in>?hull"
himmelma@33175
  1123
  then obtain u v b where obt:"u\<ge>0" "v\<ge>0" "u + v = 1" "b \<in> convex hull s" "x = u *\<^sub>R a + v *\<^sub>R b" by auto
himmelma@33175
  1124
  have "a\<in>convex hull insert a s" "b\<in>convex hull insert a s"
himmelma@33175
  1125
    using hull_mono[of s "insert a s" convex] hull_mono[of "{a}" "insert a s" convex] and obt(4) by auto
himmelma@33175
  1126
  thus "x\<in> convex hull insert a s" unfolding obt(5) using convex_convex_hull[of "insert a s", unfolded convex_def]
himmelma@33175
  1127
    apply(erule_tac x=a in ballE) apply(erule_tac x=b in ballE) apply(erule_tac x=u in allE) using obt by auto
himmelma@33175
  1128
next
himmelma@33175
  1129
  show "convex ?hull" unfolding convex_def apply(rule,rule,rule,rule,rule,rule,rule) proof-
himmelma@33175
  1130
    fix x y u v assume as:"(0::real) \<le> u" "0 \<le> v" "u + v = 1" "x\<in>?hull" "y\<in>?hull"
himmelma@33175
  1131
    from as(4) obtain u1 v1 b1 where obt1:"u1\<ge>0" "v1\<ge>0" "u1 + v1 = 1" "b1 \<in> convex hull s" "x = u1 *\<^sub>R a + v1 *\<^sub>R b1" by auto
himmelma@33175
  1132
    from as(5) obtain u2 v2 b2 where obt2:"u2\<ge>0" "v2\<ge>0" "u2 + v2 = 1" "b2 \<in> convex hull s" "y = u2 *\<^sub>R a + v2 *\<^sub>R b2" by auto
himmelma@33175
  1133
    have *:"\<And>(x::'a) s1 s2. x - s1 *\<^sub>R x - s2 *\<^sub>R x = ((1::real) - (s1 + s2)) *\<^sub>R x" by (auto simp add: algebra_simps)
himmelma@33175
  1134
    have "\<exists>b \<in> convex hull s. u *\<^sub>R x + v *\<^sub>R y = (u * u1) *\<^sub>R a + (v * u2) *\<^sub>R a + (b - (u * u1) *\<^sub>R b - (v * u2) *\<^sub>R b)"
himmelma@33175
  1135
    proof(cases "u * v1 + v * v2 = 0")
himmelma@33175
  1136
      have *:"\<And>(x::'a) s1 s2. x - s1 *\<^sub>R x - s2 *\<^sub>R x = ((1::real) - (s1 + s2)) *\<^sub>R x" by (auto simp add: algebra_simps)
nipkow@36071
  1137
      case True hence **:"u * v1 = 0" "v * v2 = 0"
nipkow@36071
  1138
        using mult_nonneg_nonneg[OF `u\<ge>0` `v1\<ge>0`] mult_nonneg_nonneg[OF `v\<ge>0` `v2\<ge>0`] by arith+
himmelma@33175
  1139
      hence "u * u1 + v * u2 = 1" using as(3) obt1(3) obt2(3) by auto
himmelma@33175
  1140
      thus ?thesis unfolding obt1(5) obt2(5) * using assms hull_subset[of s convex] by(auto simp add: ** scaleR_right_distrib)
himmelma@33175
  1141
    next
himmelma@33175
  1142
      have "1 - (u * u1 + v * u2) = (u + v) - (u * u1 + v * u2)" using as(3) obt1(3) obt2(3) by (auto simp add: field_simps)
himmelma@33175
  1143
      also have "\<dots> = u * (v1 + u1 - u1) + v * (v2 + u2 - u2)" using as(3) obt1(3) obt2(3) by (auto simp add: field_simps) 
himmelma@33175
  1144
      also have "\<dots> = u * v1 + v * v2" by simp finally have **:"1 - (u * u1 + v * u2) = u * v1 + v * v2" by auto
himmelma@33175
  1145
      case False have "0 \<le> u * v1 + v * v2" "0 \<le> u * v1" "0 \<le> u * v1 + v * v2" "0 \<le> v * v2" apply -
himmelma@33175
  1146
        apply(rule add_nonneg_nonneg) prefer 4 apply(rule add_nonneg_nonneg) apply(rule_tac [!] mult_nonneg_nonneg)
himmelma@33175
  1147
        using as(1,2) obt1(1,2) obt2(1,2) by auto 
himmelma@33175
  1148
      thus ?thesis unfolding obt1(5) obt2(5) unfolding * and ** using False
himmelma@33175
  1149
        apply(rule_tac x="((u * v1) / (u * v1 + v * v2)) *\<^sub>R b1 + ((v * v2) / (u * v1 + v * v2)) *\<^sub>R b2" in bexI) defer
himmelma@33175
  1150
        apply(rule convex_convex_hull[of s, unfolded convex_def, rule_format]) using obt1(4) obt2(4)
huffman@44349
  1151
        unfolding add_divide_distrib[THEN sym] and zero_le_divide_iff
himmelma@33175
  1152
        by (auto simp add: scaleR_left_distrib scaleR_right_distrib)
himmelma@33175
  1153
    qed note * = this
nipkow@36071
  1154
    have u1:"u1 \<le> 1" unfolding obt1(3)[THEN sym] and not_le using obt1(2) by auto
nipkow@36071
  1155
    have u2:"u2 \<le> 1" unfolding obt2(3)[THEN sym] and not_le using obt2(2) by auto
himmelma@33175
  1156
    have "u1 * u + u2 * v \<le> (max u1 u2) * u + (max u1 u2) * v" apply(rule add_mono)
himmelma@33175
  1157
      apply(rule_tac [!] mult_right_mono) using as(1,2) obt1(1,2) obt2(1,2) by auto
huffman@44282
  1158
    also have "\<dots> \<le> 1" unfolding right_distrib[THEN sym] and as(3) using u1 u2 by auto
himmelma@33175
  1159
    finally 
himmelma@33175
  1160
    show "u *\<^sub>R x + v *\<^sub>R y \<in> ?hull" unfolding mem_Collect_eq apply(rule_tac x="u * u1 + v * u2" in exI)
himmelma@33175
  1161
      apply(rule conjI) defer apply(rule_tac x="1 - u * u1 - v * u2" in exI) unfolding Bex_def
himmelma@33175
  1162
      using as(1,2) obt1(1,2) obt2(1,2) * by(auto intro!: mult_nonneg_nonneg add_nonneg_nonneg simp add: algebra_simps)
himmelma@33175
  1163
  qed
himmelma@33175
  1164
qed
himmelma@33175
  1165
himmelma@33175
  1166
himmelma@33175
  1167
subsection {* Explicit expression for convex hull. *}
himmelma@33175
  1168
himmelma@33175
  1169
lemma convex_hull_indexed:
himmelma@33175
  1170
  fixes s :: "'a::real_vector set"
himmelma@33175
  1171
  shows "convex hull s = {y. \<exists>k u x. (\<forall>i\<in>{1::nat .. k}. 0 \<le> u i \<and> x i \<in> s) \<and>
himmelma@33175
  1172
                            (setsum u {1..k} = 1) \<and>
himmelma@33175
  1173
                            (setsum (\<lambda>i. u i *\<^sub>R x i) {1..k} = y)}" (is "?xyz = ?hull")
huffman@44170
  1174
  apply(rule hull_unique) apply(rule) defer
himmelma@33175
  1175
  apply(subst convex_def) apply(rule,rule,rule,rule,rule,rule,rule)
himmelma@33175
  1176
proof-
himmelma@33175
  1177
  fix x assume "x\<in>s"
himmelma@33175
  1178
  thus "x \<in> ?hull" unfolding mem_Collect_eq apply(rule_tac x=1 in exI, rule_tac x="\<lambda>x. 1" in exI) by auto
himmelma@33175
  1179
next
himmelma@33175
  1180
  fix t assume as:"s \<subseteq> t" "convex t"
himmelma@33175
  1181
  show "?hull \<subseteq> t" apply(rule) unfolding mem_Collect_eq apply(erule exE | erule conjE)+ proof-
himmelma@33175
  1182
    fix x k u y assume assm:"\<forall>i\<in>{1::nat..k}. 0 \<le> u i \<and> y i \<in> s" "setsum u {1..k} = 1" "(\<Sum>i = 1..k. u i *\<^sub>R y i) = x"
himmelma@33175
  1183
    show "x\<in>t" unfolding assm(3)[THEN sym] apply(rule as(2)[unfolded convex, rule_format])
himmelma@33175
  1184
      using assm(1,2) as(1) by auto qed
himmelma@33175
  1185
next
himmelma@33175
  1186
  fix x y u v assume uv:"0\<le>u" "0\<le>v" "u+v=(1::real)" and xy:"x\<in>?hull" "y\<in>?hull"
himmelma@33175
  1187
  from xy obtain k1 u1 x1 where x:"\<forall>i\<in>{1::nat..k1}. 0\<le>u1 i \<and> x1 i \<in> s" "setsum u1 {Suc 0..k1} = 1" "(\<Sum>i = Suc 0..k1. u1 i *\<^sub>R x1 i) = x" by auto
himmelma@33175
  1188
  from xy obtain k2 u2 x2 where y:"\<forall>i\<in>{1::nat..k2}. 0\<le>u2 i \<and> x2 i \<in> s" "setsum u2 {Suc 0..k2} = 1" "(\<Sum>i = Suc 0..k2. u2 i *\<^sub>R x2 i) = y" by auto
himmelma@33175
  1189
  have *:"\<And>P (x1::'a) x2 s1 s2 i.(if P i then s1 else s2) *\<^sub>R (if P i then x1 else x2) = (if P i then s1 *\<^sub>R x1 else s2 *\<^sub>R x2)"
himmelma@33175
  1190
    "{1..k1 + k2} \<inter> {1..k1} = {1..k1}" "{1..k1 + k2} \<inter> - {1..k1} = (\<lambda>i. i + k1) ` {1..k2}"
himmelma@33175
  1191
    prefer 3 apply(rule,rule) unfolding image_iff apply(rule_tac x="x - k1" in bexI) by(auto simp add: not_le)
himmelma@33175
  1192
  have inj:"inj_on (\<lambda>i. i + k1) {1..k2}" unfolding inj_on_def by auto  
himmelma@33175
  1193
  show "u *\<^sub>R x + v *\<^sub>R y \<in> ?hull" apply(rule)
himmelma@33175
  1194
    apply(rule_tac x="k1 + k2" in exI, rule_tac x="\<lambda>i. if i \<in> {1..k1} then u * u1 i else v * u2 (i - k1)" in exI)
himmelma@33175
  1195
    apply(rule_tac x="\<lambda>i. if i \<in> {1..k1} then x1 i else x2 (i - k1)" in exI) apply(rule,rule) defer apply(rule)
hoelzl@35577
  1196
    unfolding * and setsum_cases[OF finite_atLeastAtMost[of 1 "k1 + k2"]] and setsum_reindex[OF inj] and o_def Collect_mem_eq
himmelma@33175
  1197
    unfolding scaleR_scaleR[THEN sym] scaleR_right.setsum [symmetric] setsum_right_distrib[THEN sym] proof-
himmelma@33175
  1198
    fix i assume i:"i \<in> {1..k1+k2}"
himmelma@33175
  1199
    show "0 \<le> (if i \<in> {1..k1} then u * u1 i else v * u2 (i - k1)) \<and> (if i \<in> {1..k1} then x1 i else x2 (i - k1)) \<in> s"
himmelma@33175
  1200
    proof(cases "i\<in>{1..k1}")
himmelma@33175
  1201
      case True thus ?thesis using mult_nonneg_nonneg[of u "u1 i"] and uv(1) x(1)[THEN bspec[where x=i]] by auto
himmelma@33175
  1202
    next def j \<equiv> "i - k1"
himmelma@33175
  1203
      case False with i have "j \<in> {1..k2}" unfolding j_def by auto
himmelma@33175
  1204
      thus ?thesis unfolding j_def[symmetric] using False
himmelma@33175
  1205
        using mult_nonneg_nonneg[of v "u2 j"] and uv(2) y(1)[THEN bspec[where x=j]] by auto qed
himmelma@33175
  1206
  qed(auto simp add: not_le x(2,3) y(2,3) uv(3))
himmelma@33175
  1207
qed
himmelma@33175
  1208
himmelma@33175
  1209
lemma convex_hull_finite:
himmelma@33175
  1210
  fixes s :: "'a::real_vector set"
himmelma@33175
  1211
  assumes "finite s"
himmelma@33175
  1212
  shows "convex hull s = {y. \<exists>u. (\<forall>x\<in>s. 0 \<le> u x) \<and>
himmelma@33175
  1213
         setsum u s = 1 \<and> setsum (\<lambda>x. u x *\<^sub>R x) s = y}" (is "?HULL = ?set")
huffman@44170
  1214
proof(rule hull_unique, auto simp add: convex_def[of ?set])
himmelma@33175
  1215
  fix x assume "x\<in>s" thus " \<exists>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> (\<Sum>x\<in>s. u x *\<^sub>R x) = x" 
himmelma@33175
  1216
    apply(rule_tac x="\<lambda>y. if x=y then 1 else 0" in exI) apply auto
himmelma@33175
  1217
    unfolding setsum_delta'[OF assms] and setsum_delta''[OF assms] by auto 
himmelma@33175
  1218
next
himmelma@33175
  1219
  fix u v ::real assume uv:"0 \<le> u" "0 \<le> v" "u + v = 1"
himmelma@33175
  1220
  fix ux assume ux:"\<forall>x\<in>s. 0 \<le> ux x" "setsum ux s = (1::real)"
himmelma@33175
  1221
  fix uy assume uy:"\<forall>x\<in>s. 0 \<le> uy x" "setsum uy s = (1::real)"
himmelma@33175
  1222
  { fix x assume "x\<in>s"
himmelma@33175
  1223
    hence "0 \<le> u * ux x + v * uy x" using ux(1)[THEN bspec[where x=x]] uy(1)[THEN bspec[where x=x]] and uv(1,2)
himmelma@33175
  1224
      by (auto, metis add_nonneg_nonneg mult_nonneg_nonneg uv(1) uv(2))  }
himmelma@33175
  1225
  moreover have "(\<Sum>x\<in>s. u * ux x + v * uy x) = 1"
himmelma@33175
  1226
    unfolding setsum_addf and setsum_right_distrib[THEN sym] and ux(2) uy(2) using uv(3) by auto
himmelma@33175
  1227
  moreover have "(\<Sum>x\<in>s. (u * ux x + v * uy x) *\<^sub>R x) = u *\<^sub>R (\<Sum>x\<in>s. ux x *\<^sub>R x) + v *\<^sub>R (\<Sum>x\<in>s. uy x *\<^sub>R x)"
himmelma@33175
  1228
    unfolding scaleR_left_distrib and setsum_addf and scaleR_scaleR[THEN sym] and scaleR_right.setsum [symmetric] by auto
himmelma@33175
  1229
  ultimately show "\<exists>uc. (\<forall>x\<in>s. 0 \<le> uc x) \<and> setsum uc s = 1 \<and> (\<Sum>x\<in>s. uc x *\<^sub>R x) = u *\<^sub>R (\<Sum>x\<in>s. ux x *\<^sub>R x) + v *\<^sub>R (\<Sum>x\<in>s. uy x *\<^sub>R x)"
himmelma@33175
  1230
    apply(rule_tac x="\<lambda>x. u * ux x + v * uy x" in exI) by auto 
himmelma@33175
  1231
next
himmelma@33175
  1232
  fix t assume t:"s \<subseteq> t" "convex t" 
himmelma@33175
  1233
  fix u assume u:"\<forall>x\<in>s. 0 \<le> u x" "setsum u s = (1::real)"
himmelma@33175
  1234
  thus "(\<Sum>x\<in>s. u x *\<^sub>R x) \<in> t" using t(2)[unfolded convex_explicit, THEN spec[where x=s], THEN spec[where x=u]]
himmelma@33175
  1235
    using assms and t(1) by auto
himmelma@33175
  1236
qed
himmelma@33175
  1237
himmelma@33175
  1238
subsection {* Another formulation from Lars Schewe. *}
himmelma@33175
  1239
himmelma@33175
  1240
lemma setsum_constant_scaleR:
himmelma@33175
  1241
  fixes y :: "'a::real_vector"
himmelma@33175
  1242
  shows "(\<Sum>x\<in>A. y) = of_nat (card A) *\<^sub>R y"
himmelma@33175
  1243
apply (cases "finite A")
himmelma@33175
  1244
apply (induct set: finite)
himmelma@33175
  1245
apply (simp_all add: algebra_simps)
himmelma@33175
  1246
done
himmelma@33175
  1247
himmelma@33175
  1248
lemma convex_hull_explicit:
himmelma@33175
  1249
  fixes p :: "'a::real_vector set"
himmelma@33175
  1250
  shows "convex hull p = {y. \<exists>s u. finite s \<and> s \<subseteq> p \<and>
himmelma@33175
  1251
             (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> setsum (\<lambda>v. u v *\<^sub>R v) s = y}" (is "?lhs = ?rhs")
himmelma@33175
  1252
proof-
himmelma@33175
  1253
  { fix x assume "x\<in>?lhs"
himmelma@33175
  1254
    then obtain k u y where obt:"\<forall>i\<in>{1::nat..k}. 0 \<le> u i \<and> y i \<in> p" "setsum u {1..k} = 1" "(\<Sum>i = 1..k. u i *\<^sub>R y i) = x"
himmelma@33175
  1255
      unfolding convex_hull_indexed by auto
himmelma@33175
  1256
himmelma@33175
  1257
    have fin:"finite {1..k}" by auto
himmelma@33175
  1258
    have fin':"\<And>v. finite {i \<in> {1..k}. y i = v}" by auto
himmelma@33175
  1259
    { fix j assume "j\<in>{1..k}"
himmelma@33175
  1260
      hence "y j \<in> p" "0 \<le> setsum u {i. Suc 0 \<le> i \<and> i \<le> k \<and> y i = y j}"
himmelma@33175
  1261
        using obt(1)[THEN bspec[where x=j]] and obt(2) apply simp
himmelma@33175
  1262
        apply(rule setsum_nonneg) using obt(1) by auto } 
himmelma@33175
  1263
    moreover
himmelma@33175
  1264
    have "(\<Sum>v\<in>y ` {1..k}. setsum u {i \<in> {1..k}. y i = v}) = 1"  
himmelma@33175
  1265
      unfolding setsum_image_gen[OF fin, THEN sym] using obt(2) by auto
himmelma@33175
  1266
    moreover have "(\<Sum>v\<in>y ` {1..k}. setsum u {i \<in> {1..k}. y i = v} *\<^sub>R v) = x"
himmelma@33175
  1267
      using setsum_image_gen[OF fin, of "\<lambda>i. u i *\<^sub>R y i" y, THEN sym]
himmelma@33175
  1268
      unfolding scaleR_left.setsum using obt(3) by auto
himmelma@33175
  1269
    ultimately have "\<exists>s u. finite s \<and> s \<subseteq> p \<and> (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = x"
himmelma@33175
  1270
      apply(rule_tac x="y ` {1..k}" in exI)
himmelma@33175
  1271
      apply(rule_tac x="\<lambda>v. setsum u {i\<in>{1..k}. y i = v}" in exI) by auto
himmelma@33175
  1272
    hence "x\<in>?rhs" by auto  }
himmelma@33175
  1273
  moreover
himmelma@33175
  1274
  { fix y assume "y\<in>?rhs"
himmelma@33175
  1275
    then obtain s u where obt:"finite s" "s \<subseteq> p" "\<forall>x\<in>s. 0 \<le> u x" "setsum u s = 1" "(\<Sum>v\<in>s. u v *\<^sub>R v) = y" by auto
himmelma@33175
  1276
himmelma@33175
  1277
    obtain f where f:"inj_on f {1..card s}" "f ` {1..card s} = s" using ex_bij_betw_nat_finite_1[OF obt(1)] unfolding bij_betw_def by auto
himmelma@33175
  1278
    
himmelma@33175
  1279
    { fix i::nat assume "i\<in>{1..card s}"
himmelma@33175
  1280
      hence "f i \<in> s"  apply(subst f(2)[THEN sym]) by auto
himmelma@33175
  1281
      hence "0 \<le> u (f i)" "f i \<in> p" using obt(2,3) by auto  }
himmelma@33175
  1282
    moreover have *:"finite {1..card s}" by auto
himmelma@33175
  1283
    { fix y assume "y\<in>s"
himmelma@33175
  1284
      then obtain i where "i\<in>{1..card s}" "f i = y" using f using image_iff[of y f "{1..card s}"] by auto
himmelma@33175
  1285
      hence "{x. Suc 0 \<le> x \<and> x \<le> card s \<and> f x = y} = {i}" apply auto using f(1)[unfolded inj_on_def] apply(erule_tac x=x in ballE) by auto
himmelma@33175
  1286
      hence "card {x. Suc 0 \<le> x \<and> x \<le> card s \<and> f x = y} = 1" by auto
himmelma@33175
  1287
      hence "(\<Sum>x\<in>{x \<in> {1..card s}. f x = y}. u (f x)) = u y"
himmelma@33175
  1288
            "(\<Sum>x\<in>{x \<in> {1..card s}. f x = y}. u (f x) *\<^sub>R f x) = u y *\<^sub>R y"
himmelma@33175
  1289
        by (auto simp add: setsum_constant_scaleR)   }
himmelma@33175
  1290
himmelma@33175
  1291
    hence "(\<Sum>x = 1..card s. u (f x)) = 1" "(\<Sum>i = 1..card s. u (f i) *\<^sub>R f i) = y"
himmelma@33175
  1292
      unfolding setsum_image_gen[OF *(1), of "\<lambda>x. u (f x) *\<^sub>R f x" f] and setsum_image_gen[OF *(1), of "\<lambda>x. u (f x)" f] 
himmelma@33175
  1293
      unfolding f using setsum_cong2[of s "\<lambda>y. (\<Sum>x\<in>{x \<in> {1..card s}. f x = y}. u (f x) *\<^sub>R f x)" "\<lambda>v. u v *\<^sub>R v"]
himmelma@33175
  1294
      using setsum_cong2 [of s "\<lambda>y. (\<Sum>x\<in>{x \<in> {1..card s}. f x = y}. u (f x))" u] unfolding obt(4,5) by auto
himmelma@33175
  1295
    
himmelma@33175
  1296
    ultimately have "\<exists>k u x. (\<forall>i\<in>{1..k}. 0 \<le> u i \<and> x i \<in> p) \<and> setsum u {1..k} = 1 \<and> (\<Sum>i::nat = 1..k. u i *\<^sub>R x i) = y"
himmelma@33175
  1297
      apply(rule_tac x="card s" in exI) apply(rule_tac x="u \<circ> f" in exI) apply(rule_tac x=f in exI) by fastsimp
himmelma@33175
  1298
    hence "y \<in> ?lhs" unfolding convex_hull_indexed by auto  }
nipkow@39302
  1299
  ultimately show ?thesis unfolding set_eq_iff by blast
himmelma@33175
  1300
qed
himmelma@33175
  1301
himmelma@33175
  1302
subsection {* A stepping theorem for that expansion. *}
himmelma@33175
  1303
himmelma@33175
  1304
lemma convex_hull_finite_step:
himmelma@33175
  1305
  fixes s :: "'a::real_vector set" assumes "finite s"
himmelma@33175
  1306
  shows "(\<exists>u. (\<forall>x\<in>insert a s. 0 \<le> u x) \<and> setsum u (insert a s) = w \<and> setsum (\<lambda>x. u x *\<^sub>R x) (insert a s) = y)
himmelma@33175
  1307
     \<longleftrightarrow> (\<exists>v\<ge>0. \<exists>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = w - v \<and> setsum (\<lambda>x. u x *\<^sub>R x) s = y - v *\<^sub>R a)" (is "?lhs = ?rhs")
himmelma@33175
  1308
proof(rule, case_tac[!] "a\<in>s")
himmelma@33175
  1309
  assume "a\<in>s" hence *:"insert a s = s" by auto
himmelma@33175
  1310
  assume ?lhs thus ?rhs unfolding * apply(rule_tac x=0 in exI) by auto
himmelma@33175
  1311
next
himmelma@33175
  1312
  assume ?lhs then obtain u where u:"\<forall>x\<in>insert a s. 0 \<le> u x" "setsum u (insert a s) = w" "(\<Sum>x\<in>insert a s. u x *\<^sub>R x) = y" by auto
himmelma@33175
  1313
  assume "a\<notin>s" thus ?rhs apply(rule_tac x="u a" in exI) using u(1)[THEN bspec[where x=a]] apply simp
himmelma@33175
  1314
    apply(rule_tac x=u in exI) using u[unfolded setsum_clauses(2)[OF assms]] and `a\<notin>s` by auto
himmelma@33175
  1315
next
himmelma@33175
  1316
  assume "a\<in>s" hence *:"insert a s = s" by auto
himmelma@33175
  1317
  have fin:"finite (insert a s)" using assms by auto
himmelma@33175
  1318
  assume ?rhs then obtain v u where uv:"v\<ge>0" "\<forall>x\<in>s. 0 \<le> u x" "setsum u s = w - v" "(\<Sum>x\<in>s. u x *\<^sub>R x) = y - v *\<^sub>R a" by auto
himmelma@33175
  1319
  show ?lhs apply(rule_tac x="\<lambda>x. (if a = x then v else 0) + u x" in exI) unfolding scaleR_left_distrib and setsum_addf and setsum_delta''[OF fin] and setsum_delta'[OF fin]
himmelma@33175
  1320
    unfolding setsum_clauses(2)[OF assms] using uv and uv(2)[THEN bspec[where x=a]] and `a\<in>s` by auto
himmelma@33175
  1321
next
himmelma@33175
  1322
  assume ?rhs then obtain v u where uv:"v\<ge>0" "\<forall>x\<in>s. 0 \<le> u x" "setsum u s = w - v" "(\<Sum>x\<in>s. u x *\<^sub>R x) = y - v *\<^sub>R a" by auto
himmelma@33175
  1323
  moreover assume "a\<notin>s" moreover have "(\<Sum>x\<in>s. if a = x then v else u x) = setsum u s" "(\<Sum>x\<in>s. (if a = x then v else u x) *\<^sub>R x) = (\<Sum>x\<in>s. u x *\<^sub>R x)"
himmelma@33175
  1324
    apply(rule_tac setsum_cong2) defer apply(rule_tac setsum_cong2) using `a\<notin>s` by auto
himmelma@33175
  1325
  ultimately show ?lhs apply(rule_tac x="\<lambda>x. if a = x then v else u x" in exI)  unfolding setsum_clauses(2)[OF assms] by auto
himmelma@33175
  1326
qed
himmelma@33175
  1327
himmelma@33175
  1328
subsection {* Hence some special cases. *}
himmelma@33175
  1329
himmelma@33175
  1330
lemma convex_hull_2:
himmelma@33175
  1331
  "convex hull {a,b} = {u *\<^sub>R a + v *\<^sub>R b | u v. 0 \<le> u \<and> 0 \<le> v \<and> u + v = 1}"
himmelma@33175
  1332
proof- have *:"\<And>u. (\<forall>x\<in>{a, b}. 0 \<le> u x) \<longleftrightarrow> 0 \<le> u a \<and> 0 \<le> u b" by auto have **:"finite {b}" by auto
himmelma@33175
  1333
show ?thesis apply(simp add: convex_hull_finite) unfolding convex_hull_finite_step[OF **, of a 1, unfolded * conj_assoc]
himmelma@33175
  1334
  apply auto apply(rule_tac x=v in exI) apply(rule_tac x="1 - v" in exI) apply simp
himmelma@33175
  1335
  apply(rule_tac x=u in exI) apply simp apply(rule_tac x="\<lambda>x. v" in exI) by simp qed
himmelma@33175
  1336
himmelma@33175
  1337
lemma convex_hull_2_alt: "convex hull {a,b} = {a + u *\<^sub>R (b - a) | u.  0 \<le> u \<and> u \<le> 1}"
huffman@44170
  1338
  unfolding convex_hull_2
huffman@44170
  1339
proof(rule Collect_cong) have *:"\<And>x y ::real. x + y = 1 \<longleftrightarrow> x = 1 - y" by auto
himmelma@33175
  1340
  fix x show "(\<exists>v u. x = v *\<^sub>R a + u *\<^sub>R b \<and> 0 \<le> v \<and> 0 \<le> u \<and> v + u = 1) = (\<exists>u. x = a + u *\<^sub>R (b - a) \<and> 0 \<le> u \<and> u \<le> 1)"
himmelma@33175
  1341
    unfolding * apply auto apply(rule_tac[!] x=u in exI) by (auto simp add: algebra_simps) qed
himmelma@33175
  1342
himmelma@33175
  1343
lemma convex_hull_3:
himmelma@33175
  1344
  "convex hull {a,b,c} = { u *\<^sub>R a + v *\<^sub>R b + w *\<^sub>R c | u v w. 0 \<le> u \<and> 0 \<le> v \<and> 0 \<le> w \<and> u + v + w = 1}"
himmelma@33175
  1345
proof-
himmelma@33175
  1346
  have fin:"finite {a,b,c}" "finite {b,c}" "finite {c}" by auto
himmelma@33175
  1347
  have *:"\<And>x y z ::real. x + y + z = 1 \<longleftrightarrow> x = 1 - y - z"
huffman@44361
  1348
    by (auto simp add: field_simps)
huffman@44170
  1349
  show ?thesis unfolding convex_hull_finite[OF fin(1)] and convex_hull_finite_step[OF fin(2)] and *
huffman@44170
  1350
    unfolding convex_hull_finite_step[OF fin(3)] apply(rule Collect_cong) apply simp apply auto
himmelma@33175
  1351
    apply(rule_tac x=va in exI) apply (rule_tac x="u c" in exI) apply simp
himmelma@33175
  1352
    apply(rule_tac x="1 - v - w" in exI) apply simp apply(rule_tac x=v in exI) apply simp apply(rule_tac x="\<lambda>x. w" in exI) by simp qed
himmelma@33175
  1353
himmelma@33175
  1354
lemma convex_hull_3_alt:
himmelma@33175
  1355
  "convex hull {a,b,c} = {a + u *\<^sub>R (b - a) + v *\<^sub>R (c - a) | u v.  0 \<le> u \<and> 0 \<le> v \<and> u + v \<le> 1}"
himmelma@33175
  1356
proof- have *:"\<And>x y z ::real. x + y + z = 1 \<longleftrightarrow> x = 1 - y - z" by auto
himmelma@33175
  1357
  show ?thesis unfolding convex_hull_3 apply (auto simp add: *) apply(rule_tac x=v in exI) apply(rule_tac x=w in exI) apply (simp add: algebra_simps)
himmelma@33175
  1358
    apply(rule_tac x=u in exI) apply(rule_tac x=v in exI) by (simp add: algebra_simps) qed
himmelma@33175
  1359
himmelma@33175
  1360
subsection {* Relations among closure notions and corresponding hulls. *}
himmelma@33175
  1361
himmelma@33175
  1362
lemma affine_imp_convex: "affine s \<Longrightarrow> convex s"
himmelma@33175
  1363
  unfolding affine_def convex_def by auto
himmelma@33175
  1364
huffman@44361
  1365
lemma subspace_imp_convex: "subspace s \<Longrightarrow> convex s"
himmelma@33175
  1366
  using subspace_imp_affine affine_imp_convex by auto
himmelma@33175
  1367
huffman@44361
  1368
lemma affine_hull_subset_span: "(affine hull s) \<subseteq> (span s)"
huffman@44170
  1369
by (metis hull_minimal span_inc subspace_imp_affine subspace_span)
himmelma@33175
  1370
huffman@44361
  1371
lemma convex_hull_subset_span: "(convex hull s) \<subseteq> (span s)"
huffman@44170
  1372
by (metis hull_minimal span_inc subspace_imp_convex subspace_span)
himmelma@33175
  1373
himmelma@33175
  1374
lemma convex_hull_subset_affine_hull: "(convex hull s) \<subseteq> (affine hull s)"
huffman@44170
  1375
by (metis affine_affine_hull affine_imp_convex hull_minimal hull_subset)
nipkow@36071
  1376
himmelma@33175
  1377
himmelma@33175
  1378
lemma affine_dependent_imp_dependent:
huffman@44361
  1379
  shows "affine_dependent s \<Longrightarrow> dependent s"
himmelma@33175
  1380
  unfolding affine_dependent_def dependent_def 
himmelma@33175
  1381
  using affine_hull_subset_span by auto
himmelma@33175
  1382
himmelma@33175
  1383
lemma dependent_imp_affine_dependent:
himmelma@33175
  1384
  assumes "dependent {x - a| x . x \<in> s}" "a \<notin> s"
himmelma@33175
  1385
  shows "affine_dependent (insert a s)"
himmelma@33175
  1386
proof-
hoelzl@37489
  1387
  from assms(1)[unfolded dependent_explicit] obtain S u v 
himmelma@33175
  1388
    where obt:"finite S" "S \<subseteq> {x - a |x. x \<in> s}" "v\<in>S" "u v  \<noteq> 0" "(\<Sum>v\<in>S. u v *\<^sub>R v) = 0" by auto
himmelma@33175
  1389
  def t \<equiv> "(\<lambda>x. x + a) ` S"
himmelma@33175
  1390
himmelma@33175
  1391
  have inj:"inj_on (\<lambda>x. x + a) S" unfolding inj_on_def by auto
himmelma@33175
  1392
  have "0\<notin>S" using obt(2) assms(2) unfolding subset_eq by auto
himmelma@33175
  1393
  have fin:"finite t" and  "t\<subseteq>s" unfolding t_def using obt(1,2) by auto 
himmelma@33175
  1394
himmelma@33175
  1395
  hence "finite (insert a t)" and "insert a t \<subseteq> insert a s" by auto 
himmelma@33175
  1396
  moreover have *:"\<And>P Q. (\<Sum>x\<in>t. (if x = a then P x else Q x)) = (\<Sum>x\<in>t. Q x)"
himmelma@33175
  1397
    apply(rule setsum_cong2) using `a\<notin>s` `t\<subseteq>s` by auto
himmelma@33175
  1398
  have "(\<Sum>x\<in>insert a t. if x = a then - (\<Sum>x\<in>t. u (x - a)) else u (x - a)) = 0"
himmelma@33175
  1399
    unfolding setsum_clauses(2)[OF fin] using `a\<notin>s` `t\<subseteq>s` apply auto unfolding * by auto
himmelma@33175
  1400
  moreover have "\<exists>v\<in>insert a t. (if v = a then - (\<Sum>x\<in>t. u (x - a)) else u (v - a)) \<noteq> 0"
himmelma@33175
  1401
    apply(rule_tac x="v + a" in bexI) using obt(3,4) and `0\<notin>S` unfolding t_def by auto
himmelma@33175
  1402
  moreover have *:"\<And>P Q. (\<Sum>x\<in>t. (if x = a then P x else Q x) *\<^sub>R x) = (\<Sum>x\<in>t. Q x *\<^sub>R x)"
himmelma@33175
  1403
    apply(rule setsum_cong2) using `a\<notin>s` `t\<subseteq>s` by auto
himmelma@33175
  1404
  have "(\<Sum>x\<in>t. u (x - a)) *\<^sub>R a = (\<Sum>v\<in>t. u (v - a) *\<^sub>R v)" 
himmelma@33175
  1405
    unfolding scaleR_left.setsum unfolding t_def and setsum_reindex[OF inj] and o_def
himmelma@33175
  1406
    using obt(5) by (auto simp add: setsum_addf scaleR_right_distrib)
himmelma@33175
  1407
  hence "(\<Sum>v\<in>insert a t. (if v = a then - (\<Sum>x\<in>t. u (x - a)) else u (v - a)) *\<^sub>R v) = 0"
hoelzl@37489
  1408
    unfolding setsum_clauses(2)[OF fin] using `a\<notin>s` `t\<subseteq>s` by (auto simp add: *)
himmelma@33175
  1409
  ultimately show ?thesis unfolding affine_dependent_explicit
himmelma@33175
  1410
    apply(rule_tac x="insert a t" in exI) by auto 
himmelma@33175
  1411
qed
himmelma@33175
  1412
himmelma@33175
  1413
lemma convex_cone:
himmelma@33175
  1414
  "convex s \<and> cone s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. (x + y) \<in> s) \<and> (\<forall>x\<in>s. \<forall>c\<ge>0. (c *\<^sub>R x) \<in> s)" (is "?lhs = ?rhs")
himmelma@33175
  1415
proof-
himmelma@33175
  1416
  { fix x y assume "x\<in>s" "y\<in>s" and ?lhs
himmelma@33175
  1417
    hence "2 *\<^sub>R x \<in>s" "2 *\<^sub>R y \<in> s" unfolding cone_def by auto
himmelma@33175
  1418
    hence "x + y \<in> s" using `?lhs`[unfolded convex_def, THEN conjunct1]
himmelma@33175
  1419
      apply(erule_tac x="2*\<^sub>R x" in ballE) apply(erule_tac x="2*\<^sub>R y" in ballE)
himmelma@33175
  1420
      apply(erule_tac x="1/2" in allE) apply simp apply(erule_tac x="1/2" in allE) by auto  }
huffman@36362
  1421
  thus ?thesis unfolding convex_def cone_def by blast
himmelma@33175
  1422
qed
himmelma@33175
  1423
hoelzl@37489
  1424
lemma affine_dependent_biggerset: fixes s::"('a::euclidean_space) set"
hoelzl@37489
  1425
  assumes "finite s" "card s \<ge> DIM('a) + 2"
himmelma@33175
  1426
  shows "affine_dependent s"
himmelma@33175
  1427
proof-
himmelma@33175
  1428
  have "s\<noteq>{}" using assms by auto then obtain a where "a\<in>s" by auto
himmelma@33175
  1429
  have *:"{x - a |x. x \<in> s - {a}} = (\<lambda>x. x - a) ` (s - {a})" by auto
himmelma@33175
  1430
  have "card {x - a |x. x \<in> s - {a}} = card (s - {a})" unfolding * 
himmelma@33175
  1431
    apply(rule card_image) unfolding inj_on_def by auto
hoelzl@37489
  1432
  also have "\<dots> > DIM('a)" using assms(2)
himmelma@33175
  1433
    unfolding card_Diff_singleton[OF assms(1) `a\<in>s`] by auto
himmelma@33175
  1434
  finally show ?thesis apply(subst insert_Diff[OF `a\<in>s`, THEN sym])
himmelma@33175
  1435
    apply(rule dependent_imp_affine_dependent)
himmelma@33175
  1436
    apply(rule dependent_biggerset) by auto qed
himmelma@33175
  1437
himmelma@33175
  1438
lemma affine_dependent_biggerset_general:
hoelzl@37489
  1439
  assumes "finite (s::('a::euclidean_space) set)" "card s \<ge> dim s + 2"
himmelma@33175
  1440
  shows "affine_dependent s"
himmelma@33175
  1441
proof-
himmelma@33175
  1442
  from assms(2) have "s \<noteq> {}" by auto
himmelma@33175
  1443
  then obtain a where "a\<in>s" by auto
himmelma@33175
  1444
  have *:"{x - a |x. x \<in> s - {a}} = (\<lambda>x. x - a) ` (s - {a})" by auto
himmelma@33175
  1445
  have **:"card {x - a |x. x \<in> s - {a}} = card (s - {a})" unfolding * 
himmelma@33175
  1446
    apply(rule card_image) unfolding inj_on_def by auto
himmelma@33175
  1447
  have "dim {x - a |x. x \<in> s - {a}} \<le> dim s"
himmelma@33175
  1448
    apply(rule subset_le_dim) unfolding subset_eq
himmelma@33175
  1449
    using `a\<in>s` by (auto simp add:span_superset span_sub)
himmelma@33175
  1450
  also have "\<dots> < dim s + 1" by auto
himmelma@33175
  1451
  also have "\<dots> \<le> card (s - {a})" using assms
himmelma@33175
  1452
    using card_Diff_singleton[OF assms(1) `a\<in>s`] by auto
himmelma@33175
  1453
  finally show ?thesis apply(subst insert_Diff[OF `a\<in>s`, THEN sym])
himmelma@33175
  1454
    apply(rule dependent_imp_affine_dependent) apply(rule dependent_biggerset_general) unfolding ** by auto qed
himmelma@33175
  1455
himmelma@33175
  1456
subsection {* Caratheodory's theorem. *}
himmelma@33175
  1457
hoelzl@37489
  1458
lemma convex_hull_caratheodory: fixes p::"('a::euclidean_space) set"
hoelzl@37489
  1459
  shows "convex hull p = {y. \<exists>s u. finite s \<and> s \<subseteq> p \<and> card s \<le> DIM('a) + 1 \<and>
himmelma@33175
  1460
  (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> setsum (\<lambda>v. u v *\<^sub>R v) s = y}"
nipkow@39302
  1461
  unfolding convex_hull_explicit set_eq_iff mem_Collect_eq
himmelma@33175
  1462
proof(rule,rule)
himmelma@33175
  1463
  fix y let ?P = "\<lambda>n. \<exists>s u. finite s \<and> card s = n \<and> s \<subseteq> p \<and> (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = y"
himmelma@33175
  1464
  assume "\<exists>s u. finite s \<and> s \<subseteq> p \<and> (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = y"
himmelma@33175
  1465
  then obtain N where "?P N" by auto
himmelma@33175
  1466
  hence "\<exists>n\<le>N. (\<forall>k<n. \<not> ?P k) \<and> ?P n" apply(rule_tac ex_least_nat_le) by auto
himmelma@33175
  1467
  then obtain n where "?P n" and smallest:"\<forall>k<n. \<not> ?P k" by blast
himmelma@33175
  1468
  then obtain s u where obt:"finite s" "card s = n" "s\<subseteq>p" "\<forall>x\<in>s. 0 \<le> u x" "setsum u s = 1"  "(\<Sum>v\<in>s. u v *\<^sub>R v) = y" by auto
himmelma@33175
  1469
hoelzl@37489
  1470
  have "card s \<le> DIM('a) + 1" proof(rule ccontr, simp only: not_le)
hoelzl@37489
  1471
    assume "DIM('a) + 1 < card s"
himmelma@33175
  1472
    hence "affine_dependent s" using affine_dependent_biggerset[OF obt(1)] by auto
himmelma@33175
  1473
    then obtain w v where wv:"setsum w s = 0" "v\<in>s" "w v \<noteq> 0" "(\<Sum>v\<in>s. w v *\<^sub>R v) = 0"
himmelma@33175
  1474
      using affine_dependent_explicit_finite[OF obt(1)] by auto
himmelma@33175
  1475
    def i \<equiv> "(\<lambda>v. (u v) / (- w v)) ` {v\<in>s. w v < 0}"  def t \<equiv> "Min i"
himmelma@33175
  1476
    have "\<exists>x\<in>s. w x < 0" proof(rule ccontr, simp add: not_less)
himmelma@33175
  1477
      assume as:"\<forall>x\<in>s. 0 \<le> w x"
himmelma@33175
  1478
      hence "setsum w (s - {v}) \<ge> 0" apply(rule_tac setsum_nonneg) by auto
himmelma@33175
  1479
      hence "setsum w s > 0" unfolding setsum_diff1'[OF obt(1) `v\<in>s`]
himmelma@33175
  1480
        using as[THEN bspec[where x=v]] and `v\<in>s` using `w v \<noteq> 0` by auto
himmelma@33175
  1481
      thus False using wv(1) by auto
himmelma@33175
  1482
    qed hence "i\<noteq>{}" unfolding i_def by auto
himmelma@33175
  1483
himmelma@33175
  1484
    hence "t \<ge> 0" using Min_ge_iff[of i 0 ] and obt(1) unfolding t_def i_def
himmelma@33175
  1485
      using obt(4)[unfolded le_less] apply auto unfolding divide_le_0_iff by auto 
himmelma@33175
  1486
    have t:"\<forall>v\<in>s. u v + t * w v \<ge> 0" proof
himmelma@33175
  1487
      fix v assume "v\<in>s" hence v:"0\<le>u v" using obt(4)[THEN bspec[where x=v]] by auto
himmelma@33175
  1488
      show"0 \<le> u v + t * w v" proof(cases "w v < 0")
himmelma@33175
  1489
        case False thus ?thesis apply(rule_tac add_nonneg_nonneg) 
himmelma@33175
  1490
          using v apply simp apply(rule mult_nonneg_nonneg) using `t\<ge>0` by auto next
himmelma@33175
  1491
        case True hence "t \<le> u v / (- w v)" using `v\<in>s`
himmelma@33175
  1492
          unfolding t_def i_def apply(rule_tac Min_le) using obt(1) by auto 
himmelma@33175
  1493
        thus ?thesis unfolding real_0_le_add_iff
himmelma@33175
  1494
          using pos_le_divide_eq[OF True[unfolded neg_0_less_iff_less[THEN sym]]] by auto
himmelma@33175
  1495
      qed qed
himmelma@33175
  1496
himmelma@33175
  1497
    obtain a where "a\<in>s" and "t = (\<lambda>v. (u v) / (- w v)) a" and "w a < 0"
himmelma@33175
  1498
      using Min_in[OF _ `i\<noteq>{}`] and obt(1) unfolding i_def t_def by auto
himmelma@33175
  1499
    hence a:"a\<in>s" "u a + t * w a = 0" by auto
hoelzl@37489
  1500
    have *:"\<And>f. setsum f (s - {a}) = setsum f s - ((f a)::'b::ab_group_add)"
hoelzl@37489
  1501
      unfolding setsum_diff1'[OF obt(1) `a\<in>s`] by auto 
himmelma@33175
  1502
    have "(\<Sum>v\<in>s. u v + t * w v) = 1"
himmelma@33175
  1503
      unfolding setsum_addf wv(1) setsum_right_distrib[THEN sym] obt(5) by auto
himmelma@33175
  1504
    moreover have "(\<Sum>v\<in>s. u v *\<^sub>R v + (t * w v) *\<^sub>R v) - (u a *\<^sub>R a + (t * w a) *\<^sub>R a) = y" 
himmelma@33175
  1505
      unfolding setsum_addf obt(6) scaleR_scaleR[THEN sym] scaleR_right.setsum [symmetric] wv(4)
hoelzl@37489
  1506
      using a(2) [THEN eq_neg_iff_add_eq_0 [THEN iffD2]] by simp
himmelma@33175
  1507
    ultimately have "?P (n - 1)" apply(rule_tac x="(s - {a})" in exI)
hoelzl@37489
  1508
      apply(rule_tac x="\<lambda>v. u v + t * w v" in exI) using obt(1-3) and t and a
hoelzl@37489
  1509
      by (auto simp add: * scaleR_left_distrib)
himmelma@33175
  1510
    thus False using smallest[THEN spec[where x="n - 1"]] by auto qed
hoelzl@37489
  1511
  thus "\<exists>s u. finite s \<and> s \<subseteq> p \<and> card s \<le> DIM('a) + 1
himmelma@33175
  1512
    \<and> (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> (\<Sum>v\<in>s. u v *\<^sub>R v) = y" using obt by auto
himmelma@33175
  1513
qed auto
himmelma@33175
  1514
himmelma@33175
  1515
lemma caratheodory:
hoelzl@37489
  1516
 "convex hull p = {x::'a::euclidean_space. \<exists>s. finite s \<and> s \<subseteq> p \<and>
hoelzl@37489
  1517
      card s \<le> DIM('a) + 1 \<and> x \<in> convex hull s}"
nipkow@39302
  1518
  unfolding set_eq_iff apply(rule, rule) unfolding mem_Collect_eq proof-
himmelma@33175
  1519
  fix x assume "x \<in> convex hull p"
hoelzl@37489
  1520
  then obtain s u where "finite s" "s \<subseteq> p" "card s \<le> DIM('a) + 1"
himmelma@33175
  1521
     "\<forall>x\<in>s. 0 \<le> u x" "setsum u s = 1" "(\<Sum>v\<in>s. u v *\<^sub>R v) = x"unfolding convex_hull_caratheodory by auto
hoelzl@37489
  1522
  thus "\<exists>s. finite s \<and> s \<subseteq> p \<and> card s \<le> DIM('a) + 1 \<and> x \<in> convex hull s"
himmelma@33175
  1523
    apply(rule_tac x=s in exI) using hull_subset[of s convex]
himmelma@33175
  1524
  using convex_convex_hull[unfolded convex_explicit, of s, THEN spec[where x=s], THEN spec[where x=u]] by auto
himmelma@33175
  1525
next
hoelzl@37489
  1526
  fix x assume "\<exists>s. finite s \<and> s \<subseteq> p \<and> card s \<le> DIM('a) + 1 \<and> x \<in> convex hull s"
hoelzl@37489
  1527
  then obtain s where "finite s" "s \<subseteq> p" "card s \<le> DIM('a) + 1" "x \<in> convex hull s" by auto
himmelma@33175
  1528
  thus "x \<in> convex hull p" using hull_mono[OF `s\<subseteq>p`] by auto
himmelma@33175
  1529
qed
himmelma@33175
  1530
hoelzl@40377
  1531
hoelzl@40377
  1532
subsection {* Some Properties of Affine Dependent Sets *}
hoelzl@40377
  1533
hoelzl@40377
  1534
lemma affine_independent_empty: "~(affine_dependent {})"
hoelzl@40377
  1535
  by (simp add: affine_dependent_def)
hoelzl@40377
  1536
hoelzl@40377
  1537
lemma affine_independent_sing:
hoelzl@40377
  1538
shows "~(affine_dependent {a})"
hoelzl@40377
  1539
 by (simp add: affine_dependent_def)
hoelzl@40377
  1540
hoelzl@40377
  1541
lemma affine_hull_translation:
hoelzl@40377
  1542
"affine hull ((%x. a + x) `  S) = (%x. a + x) ` (affine hull S)"
hoelzl@40377
  1543
proof-
hoelzl@40377
  1544
have "affine ((%x. a + x) ` (affine hull S))" using affine_translation affine_affine_hull by auto
hoelzl@40377
  1545
moreover have "(%x. a + x) `  S <= (%x. a + x) ` (affine hull S)" using hull_subset[of S] by auto
huffman@44170
  1546
ultimately have h1: "affine hull ((%x. a + x) `  S) <= (%x. a + x) ` (affine hull S)" by (metis hull_minimal)
hoelzl@40377
  1547
have "affine((%x. -a + x) ` (affine hull ((%x. a + x) `  S)))"  using affine_translation affine_affine_hull by auto
hoelzl@40377
  1548
moreover have "(%x. -a + x) ` (%x. a + x) `  S <= (%x. -a + x) ` (affine hull ((%x. a + x) `  S))" using hull_subset[of "(%x. a + x) `  S"] by auto 
hoelzl@40377
  1549
moreover have "S=(%x. -a + x) ` (%x. a + x) `  S" using  translation_assoc[of "-a" a] by auto
huffman@44170
  1550
ultimately have "(%x. -a + x) ` (affine hull ((%x. a + x) `  S)) >= (affine hull S)" by (metis hull_minimal)
hoelzl@40377
  1551
hence "affine hull ((%x. a + x) `  S) >= (%x. a + x) ` (affine hull S)" by auto
hoelzl@40377
  1552
from this show ?thesis using h1 by auto
hoelzl@40377
  1553
qed
hoelzl@40377
  1554
hoelzl@40377
  1555
lemma affine_dependent_translation:
hoelzl@40377
  1556
  assumes "affine_dependent S"
hoelzl@40377
  1557
  shows "affine_dependent ((%x. a + x) ` S)"
hoelzl@40377
  1558
proof-
hoelzl@40377
  1559
obtain x where x_def: "x : S & x : affine hull (S - {x})" using assms affine_dependent_def by auto
hoelzl@40377
  1560
have "op + a ` (S - {x}) = op + a ` S - {a + x}" by auto
hoelzl@40377
  1561
hence "a+x : affine hull ((%x. a + x) ` S - {a+x})" using  affine_hull_translation[of a "S-{x}"] x_def by auto
hoelzl@40377
  1562
moreover have "a+x : (%x. a + x) ` S" using x_def by auto  
hoelzl@40377
  1563
ultimately show ?thesis unfolding affine_dependent_def by auto 
hoelzl@40377
  1564
qed
hoelzl@40377
  1565
hoelzl@40377
  1566
lemma affine_dependent_translation_eq:
hoelzl@40377
  1567
  "affine_dependent S <-> affine_dependent ((%x. a + x) ` S)"
hoelzl@40377
  1568
proof-
hoelzl@40377
  1569
{ assume "affine_dependent ((%x. a + x) ` S)" 
hoelzl@40377
  1570
  hence "affine_dependent S" using affine_dependent_translation[of "((%x. a + x) ` S)" "-a"] translation_assoc[of "-a" a] by auto  
hoelzl@40377
  1571
} from this show ?thesis using affine_dependent_translation by auto
hoelzl@40377
  1572
qed
hoelzl@40377
  1573
hoelzl@40377
  1574
lemma affine_hull_0_dependent:
hoelzl@40377
  1575
  assumes "0 : affine hull S"
hoelzl@40377
  1576
  shows "dependent S"
hoelzl@40377
  1577
proof-
hoelzl@40377
  1578
obtain s u where s_u_def: "finite s & s ~= {} & s <= S & setsum u s = 1 & (SUM v:s. u v *\<^sub>R v) = 0" using assms affine_hull_explicit[of S] by auto
hoelzl@40377
  1579
hence "EX v:s. u v ~= 0" using setsum_not_0[of "u" "s"] by auto 
hoelzl@40377
  1580
hence "finite s & s <= S & (EX v:s. u v ~= 0 & (SUM v:s. u v *\<^sub>R v) = 0)" using s_u_def by auto
hoelzl@40377
  1581
from this show ?thesis unfolding dependent_explicit[of S] by auto
hoelzl@40377
  1582
qed
hoelzl@40377
  1583
hoelzl@40377
  1584
lemma affine_dependent_imp_dependent2:
hoelzl@40377
  1585
  assumes "affine_dependent (insert 0 S)"
hoelzl@40377
  1586
  shows "dependent S"
hoelzl@40377
  1587
proof-
hoelzl@40377
  1588
obtain x where x_def: "x:insert 0 S & x : affine hull (insert 0 S - {x})" using affine_dependent_def[of "(insert 0 S)"] assms by blast
hoelzl@40377
  1589
hence "x : span (insert 0 S - {x})" using affine_hull_subset_span by auto
hoelzl@40377
  1590
moreover have "span (insert 0 S - {x}) = span (S - {x})" using insert_Diff_if[of "0" S "{x}"] span_insert_0[of "S-{x}"] by auto
hoelzl@40377
  1591
ultimately have "x : span (S - {x})" by auto
hoelzl@40377
  1592
hence "(x~=0) ==> dependent S" using x_def dependent_def by auto
hoelzl@40377
  1593
moreover
hoelzl@40377
  1594
{ assume "x=0" hence "0 : affine hull S" using x_def hull_mono[of "S - {0}" S] by auto
hoelzl@40377
  1595
               hence "dependent S" using affine_hull_0_dependent by auto  
hoelzl@40377
  1596
} ultimately show ?thesis by auto
hoelzl@40377
  1597
qed
hoelzl@40377
  1598
hoelzl@40377
  1599
lemma affine_dependent_iff_dependent:
hoelzl@40377
  1600
  assumes "a ~: S"
hoelzl@40377
  1601
  shows "affine_dependent (insert a S) <-> dependent ((%x. -a + x) ` S)" 
hoelzl@40377
  1602
proof-
hoelzl@40377
  1603
have "(op + (- a) ` S)={x - a| x . x : S}" by auto
hoelzl@40377
  1604
from this show ?thesis using affine_dependent_translation_eq[of "(insert a S)" "-a"] 
hoelzl@40377
  1605
      affine_dependent_imp_dependent2 assms 
hoelzl@40377
  1606
      dependent_imp_affine_dependent[of a S] by auto
hoelzl@40377
  1607
qed
hoelzl@40377
  1608
hoelzl@40377
  1609
lemma affine_dependent_iff_dependent2:
hoelzl@40377
  1610
  assumes "a : S"
hoelzl@40377
  1611
  shows "affine_dependent S <-> dependent ((%x. -a + x) ` (S-{a}))"
hoelzl@40377
  1612
proof-
hoelzl@40377
  1613
have "insert a (S - {a})=S" using assms by auto
hoelzl@40377
  1614
from this show ?thesis using assms affine_dependent_iff_dependent[of a "S-{a}"] by auto 
hoelzl@40377
  1615
qed
hoelzl@40377
  1616
hoelzl@40377
  1617
lemma affine_hull_insert_span_gen:
hoelzl@40377
  1618
  shows "affine hull (insert a s) = (%x. a+x) ` span ((%x. -a+x) ` s)" 
hoelzl@40377
  1619
proof-
hoelzl@40377
  1620
have h1: "{x - a |x. x : s}=((%x. -a+x) ` s)" by auto
hoelzl@40377
  1621
{ assume "a ~: s" hence ?thesis using affine_hull_insert_span[of a s] h1 by auto}  
hoelzl@40377
  1622
moreover
hoelzl@40377
  1623
{ assume a1: "a : s"
hoelzl@40377
  1624
  have "EX x. x:s & -a+x=0" apply (rule exI[of _ a]) using a1 by auto
hoelzl@40377
  1625
  hence "insert 0 ((%x. -a+x) ` (s - {a}))=(%x. -a+x) ` s" by auto
hoelzl@40377
  1626
  hence "span ((%x. -a+x) ` (s - {a}))=span ((%x. -a+x) ` s)" 
hoelzl@40377
  1627
    using span_insert_0[of "op + (- a) ` (s - {a})"] by auto
hoelzl@40377
  1628
  moreover have "{x - a |x. x : (s - {a})}=((%x. -a+x) ` (s - {a}))" by auto 
hoelzl@40377
  1629
  moreover have "insert a (s - {a})=(insert a s)" using assms by auto
hoelzl@40377
  1630
  ultimately have ?thesis using assms affine_hull_insert_span[of "a" "s-{a}"] by auto
hoelzl@40377
  1631
} 
hoelzl@40377
  1632
ultimately show ?thesis by auto  
hoelzl@40377
  1633
qed
hoelzl@40377
  1634
hoelzl@40377
  1635
lemma affine_hull_span2:
hoelzl@40377
  1636
  assumes "a : s"
hoelzl@40377
  1637
  shows "affine hull s = (%x. a+x) ` span ((%x. -a+x) ` (s-{a}))"
hoelzl@40377
  1638
  using affine_hull_insert_span_gen[of a "s - {a}", unfolded insert_Diff[OF assms]] by auto
hoelzl@40377
  1639
hoelzl@40377
  1640
lemma affine_hull_span_gen:
hoelzl@40377
  1641
  assumes "a : affine hull s"
hoelzl@40377
  1642
  shows "affine hull s = (%x. a+x) ` span ((%x. -a+x) ` s)"
hoelzl@40377
  1643
proof-
hoelzl@40377
  1644
have "affine hull (insert a s) = affine hull s" using hull_redundant[of a affine s] assms by auto
hoelzl@40377
  1645
from this show ?thesis using affine_hull_insert_span_gen[of a "s"] by auto
hoelzl@40377
  1646
qed
hoelzl@40377
  1647
hoelzl@40377
  1648
lemma affine_hull_span_0:
huffman@44361
  1649
  assumes "0 : affine hull S"
hoelzl@40377
  1650
  shows "affine hull S = span S"
hoelzl@40377
  1651
using affine_hull_span_gen[of "0" S] assms by auto
hoelzl@40377
  1652
hoelzl@40377
  1653
hoelzl@40377
  1654
lemma extend_to_affine_basis:
hoelzl@40377
  1655
fixes S V :: "('n::euclidean_space) set"
hoelzl@40377
  1656
assumes "~(affine_dependent S)" "S <= V" "S~={}"
hoelzl@40377
  1657
shows "? T. ~(affine_dependent T) & S<=T & T<=V & affine hull T = affine hull V"
hoelzl@40377
  1658
proof-
hoelzl@40377
  1659
obtain a where a_def: "a : S" using assms by auto
hoelzl@40377
  1660
hence h0: "independent  ((%x. -a + x) ` (S-{a}))" using affine_dependent_iff_dependent2 assms by auto
hoelzl@40377
  1661
from this obtain B 
hoelzl@40377
  1662
   where B_def: "(%x. -a+x) ` (S - {a}) <= B & B <= (%x. -a+x) ` V & independent B & (%x. -a+x) ` V <= span B" 
hoelzl@40377
  1663
   using maximal_independent_subset_extend[of "(%x. -a+x) ` (S-{a})" "(%x. -a + x) ` V"] assms by blast
hoelzl@40377
  1664
def T == "(%x. a+x) ` (insert 0 B)" hence "T=insert a ((%x. a+x) ` B)" by auto
hoelzl@40377
  1665
hence "affine hull T = (%x. a+x) ` span B" using affine_hull_insert_span_gen[of a "((%x. a+x) ` B)"] translation_assoc[of "-a" a B] by auto
hoelzl@40377
  1666
hence "V <= affine hull T" using B_def assms translation_inverse_subset[of a V "span B"] by auto
hoelzl@40377
  1667
moreover have "T<=V" using T_def B_def a_def assms by auto
hoelzl@40377
  1668
ultimately have "affine hull T = affine hull V" 
hoelzl@40377
  1669
    by (metis Int_absorb1 Int_absorb2 Int_commute Int_lower2 assms hull_hull hull_mono) 
hoelzl@40377
  1670
moreover have "S<=T" using T_def B_def translation_inverse_subset[of a "S-{a}" B] by auto
hoelzl@40377
  1671
moreover have "~(affine_dependent T)" using T_def affine_dependent_translation_eq[of "insert 0 B"] affine_dependent_imp_dependent2 B_def by auto
hoelzl@40377
  1672
ultimately show ?thesis using `T<=V` by auto
hoelzl@40377
  1673
qed
hoelzl@40377
  1674
hoelzl@40377
  1675
lemma affine_basis_exists: 
hoelzl@40377
  1676
fixes V :: "('n::euclidean_space) set"
hoelzl@40377
  1677
shows "? B. B <= V & ~(affine_dependent B) & affine hull V = affine hull B"
hoelzl@40377
  1678
proof-
hoelzl@40377
  1679
{ assume empt: "V={}" have "? B. B <= V & ~(affine_dependent B) & (affine hull V=affine hull B)" using empt affine_independent_empty by auto
hoelzl@40377
  1680
}
hoelzl@40377
  1681
moreover
hoelzl@40377
  1682
{ assume nonempt: "V~={}" obtain x where "x:V" using nonempt by auto
hoelzl@40377
  1683
  hence "? B. B <= V & ~(affine_dependent B) & (affine hull V=affine hull B)"
hoelzl@40377
  1684
  using affine_dependent_def[of "{x}"] extend_to_affine_basis[of "{x}:: ('n::euclidean_space) set" V] by auto
hoelzl@40377
  1685
}
hoelzl@40377
  1686
ultimately show ?thesis by auto
hoelzl@40377
  1687
qed
hoelzl@40377
  1688
hoelzl@40377
  1689
subsection {* Affine Dimension of a Set *}
hoelzl@40377
  1690
hoelzl@40377
  1691
definition "aff_dim V = (SOME d :: int. ? B. (affine hull B=affine hull V) & ~(affine_dependent B) & (of_nat(card B) = d+1))"
hoelzl@40377
  1692
hoelzl@40377
  1693
lemma aff_dim_basis_exists:
hoelzl@40377
  1694
  fixes V :: "('n::euclidean_space) set" 
hoelzl@40377
  1695
  shows "? B. (affine hull B=affine hull V) & ~(affine_dependent B) & (of_nat(card B) = aff_dim V+1)"
hoelzl@40377
  1696
proof-
hoelzl@40377
  1697
obtain B where B_def: "~(affine_dependent B) & (affine hull B=affine hull V)" using affine_basis_exists[of V] by auto
hoelzl@40377
  1698
from this show ?thesis unfolding aff_dim_def some_eq_ex[of "%d. ? (B :: ('n::euclidean_space) set). (affine hull B=affine hull V) & ~(affine_dependent B) & (of_nat(card B) = d+1)"] apply auto apply (rule exI[of _ "int (card B)-(1 :: int)"]) apply (rule exI[of _ "B"]) by auto
hoelzl@40377
  1699
qed
hoelzl@40377
  1700
hoelzl@40377
  1701
lemma affine_hull_nonempty: "(S ~= {}) <-> affine hull S ~= {}"
hoelzl@40377
  1702
proof-
hoelzl@40377
  1703
fix S have "(S = {}) ==> affine hull S = {}"using affine_hull_empty by auto 
hoelzl@40377
  1704
moreover have "affine hull S = {} ==> S = {}" unfolding hull_def by auto
hoelzl@40377
  1705
ultimately show "(S ~= {}) <-> affine hull S ~= {}" by blast
hoelzl@40377
  1706
qed
hoelzl@40377
  1707
hoelzl@40377
  1708
lemma aff_dim_parallel_subspace_aux:
hoelzl@40377
  1709
fixes B :: "('n::euclidean_space) set"
hoelzl@40377
  1710
assumes "~(affine_dependent B)" "a:B"
hoelzl@40377
  1711
shows "finite B & ((card B) - 1 = dim (span ((%x. -a+x) ` (B-{a}))))" 
hoelzl@40377
  1712
proof-
hoelzl@40377
  1713
have "independent ((%x. -a + x) ` (B-{a}))" using affine_dependent_iff_dependent2 assms by auto
hoelzl@40377
  1714
hence fin: "dim (span ((%x. -a+x) ` (B-{a}))) = card ((%x. -a + x) ` (B-{a}))" "finite ((%x. -a + x) ` (B - {a}))"  using indep_card_eq_dim_span[of "(%x. -a+x) ` (B-{a})"] by auto
hoelzl@40377
  1715
{ assume emp: "(%x. -a + x) ` (B - {a}) = {}" 
hoelzl@40377
  1716
  have "B=insert a ((%x. a + x) ` (%x. -a + x) ` (B - {a}))" using translation_assoc[of "a" "-a" "(B - {a})"] assms by auto
hoelzl@40377
  1717
  hence "B={a}" using emp by auto
hoelzl@40377
  1718
  hence ?thesis using assms fin by auto  
hoelzl@40377
  1719
}
hoelzl@40377
  1720
moreover
hoelzl@40377
  1721
{ assume "(%x. -a + x) ` (B - {a}) ~= {}"
hoelzl@40377
  1722
  hence "card ((%x. -a + x) ` (B - {a}))>0" using fin by auto
hoelzl@40377
  1723
  moreover have h1: "card ((%x. -a + x) ` (B-{a})) = card (B-{a})"  
hoelzl@40377
  1724
     apply (rule card_image) using translate_inj_on by auto
hoelzl@40377
  1725
  ultimately have "card (B-{a})>0" by auto
hoelzl@40377
  1726
  hence "finite(B-{a})" using card_gt_0_iff[of "(B - {a})"] by auto
hoelzl@40377
  1727
  moreover hence "(card (B-{a})= (card B) - 1)" using card_Diff_singleton assms by auto
hoelzl@40377
  1728
  ultimately have ?thesis using fin h1 by auto
hoelzl@40377
  1729
} ultimately show ?thesis by auto
hoelzl@40377
  1730
qed
hoelzl@40377
  1731
hoelzl@40377
  1732
lemma aff_dim_parallel_subspace:
hoelzl@40377
  1733
fixes V L :: "('n::euclidean_space) set"
hoelzl@40377
  1734
assumes "V ~= {}"
hoelzl@40377
  1735
assumes "subspace L" "affine_parallel (affine hull V) L"
hoelzl@40377
  1736
shows "aff_dim V=int(dim L)"
hoelzl@40377
  1737
proof-
hoelzl@40377
  1738
obtain B where B_def: "affine hull B = affine hull V & ~ affine_dependent B & int (card B) = aff_dim V + 1" using aff_dim_basis_exists by auto
hoelzl@40377
  1739
hence "B~={}" using assms B_def  affine_hull_nonempty[of V] affine_hull_nonempty[of B] by auto 
hoelzl@40377
  1740
from this obtain a where a_def: "a : B" by auto
hoelzl@40377
  1741
def Lb == "span ((%x. -a+x) ` (B-{a}))"
hoelzl@40377
  1742
  moreover have "affine_parallel (affine hull B) Lb"
hoelzl@40377
  1743
     using Lb_def B_def assms affine_hull_span2[of a B] a_def  affine_parallel_commut[of "Lb" "(affine hull B)"] unfolding affine_parallel_def by auto
hoelzl@40377
  1744
  moreover have "subspace Lb" using Lb_def subspace_span by auto
hoelzl@40377
  1745
  moreover have "affine hull B ~= {}" using assms B_def affine_hull_nonempty[of V] by auto
hoelzl@40377
  1746
  ultimately have "L=Lb" using assms affine_parallel_subspace[of "affine hull B"] affine_affine_hull[of B] B_def by auto 
hoelzl@40377
  1747
  hence "dim L=dim Lb" by auto 
hoelzl@40377
  1748
  moreover have "(card B) - 1 = dim Lb" "finite B" using Lb_def aff_dim_parallel_subspace_aux a_def B_def by auto
hoelzl@40377
  1749
(*  hence "card B=dim Lb+1" using `B~={}` card_gt_0_iff[of B] by auto *)
hoelzl@40377
  1750
  ultimately show ?thesis using B_def `B~={}` card_gt_0_iff[of B] by auto
hoelzl@40377
  1751
qed
hoelzl@40377
  1752
hoelzl@40377
  1753
lemma aff_independent_finite:
hoelzl@40377
  1754
fixes B :: "('n::euclidean_space) set"
hoelzl@40377
  1755
assumes "~(affine_dependent B)"
hoelzl@40377
  1756
shows "finite B"
hoelzl@40377
  1757
proof-
hoelzl@40377
  1758
{ assume "B~={}" from this obtain a where "a:B" by auto 
hoelzl@40377
  1759
  hence ?thesis using aff_dim_parallel_subspace_aux assms by auto 
hoelzl@40377
  1760
} from this show ?thesis by auto
hoelzl@40377
  1761
qed
hoelzl@40377
  1762
hoelzl@40377
  1763
lemma independent_finite:
hoelzl@40377
  1764
fixes B :: "('n::euclidean_space) set"
hoelzl@40377
  1765
assumes "independent B" 
hoelzl@40377
  1766
shows "finite B"
hoelzl@40377
  1767
using affine_dependent_imp_dependent[of B] aff_independent_finite[of B] assms by auto
hoelzl@40377
  1768
hoelzl@40377
  1769
lemma subspace_dim_equal:
hoelzl@40377
  1770
assumes "subspace (S :: ('n::euclidean_space) set)" "subspace T" "S <= T" "dim S >= dim T"
hoelzl@40377
  1771
shows "S=T"
hoelzl@40377
  1772
proof- 
hoelzl@40377
  1773
obtain B where B_def: "B <= S & independent B & S <= span B & (card B = dim S)" using basis_exists[of S] by auto
hoelzl@40377
  1774
hence "span B <= S" using span_mono[of B S] span_eq[of S] assms by metis 
hoelzl@40377
  1775
hence "span B = S" using B_def by auto
hoelzl@40377
  1776
have "dim S = dim T" using assms dim_subset[of S T] by auto
hoelzl@40377
  1777
hence "T <= span B" using card_eq_dim[of B T] B_def independent_finite assms by auto
hoelzl@40377
  1778
from this show ?thesis using assms `span B=S` by auto
hoelzl@40377
  1779
qed
hoelzl@40377
  1780
hoelzl@40377
  1781
lemma span_substd_basis:  assumes "d\<subseteq>{..<DIM('a::euclidean_space)}"
hoelzl@40377
  1782
  shows "(span {basis i | i. i : d}) = {x::'a::euclidean_space. (!i<DIM('a). i ~: d --> x$$i = 0)}"
hoelzl@40377
  1783
  (is "span ?A = ?B")
hoelzl@40377
  1784
proof-
hoelzl@40377
  1785
have "?A <= ?B" by auto
hoelzl@40377
  1786
moreover have s: "subspace ?B" using subspace_substandard[of "%i. i ~: d"] .
hoelzl@40377
  1787
ultimately have "span ?A <= ?B" using span_mono[of "?A" "?B"] span_eq[of "?B"] by blast
hoelzl@40377
  1788
moreover have "card d <= dim (span ?A)" using independent_card_le_dim[of "?A" "span ?A"] 
hoelzl@40377
  1789
   independent_substdbasis[OF assms] card_substdbasis[OF assms] span_inc[of "?A"] by auto
hoelzl@40377
  1790
moreover hence "dim ?B <= dim (span ?A)" using dim_substandard[OF assms] by auto
hoelzl@40377
  1791
ultimately show ?thesis using s subspace_dim_equal[of "span ?A" "?B"] 
hoelzl@40377
  1792
  subspace_span[of "?A"] by auto
hoelzl@40377
  1793
qed
hoelzl@40377
  1794
hoelzl@40377
  1795
lemma basis_to_substdbasis_subspace_isomorphism:
hoelzl@40377
  1796
fixes B :: "('a::euclidean_space) set" 
hoelzl@40377
  1797
assumes "independent B"
hoelzl@40377
  1798
shows "EX f d. card d = card B & linear f & f ` B = {basis i::'a |i. i : (d :: nat set)} & 
hoelzl@40377
  1799
       f ` span B = {x. ALL i<DIM('a). i ~: d --> x $$ i = (0::real)} &  inj_on f (span B) \<and> d\<subseteq>{..<DIM('a)}" 
hoelzl@40377
  1800
proof-
hoelzl@40377
  1801
  have B:"card B=dim B" using dim_unique[of B B "card B"] assms span_inc[of B] by auto
hoelzl@40377
  1802
  def d \<equiv> "{..<dim B}" have t:"card d = dim B" unfolding d_def by auto
hoelzl@40377
  1803
  have "dim B <= DIM('a)" using dim_subset_UNIV[of B] by auto
hoelzl@40377
  1804
  hence d:"d\<subseteq>{..<DIM('a)}" unfolding d_def by auto
hoelzl@40377
  1805
  let ?t = "{x::'a::euclidean_space. !i<DIM('a). i ~: d --> x$$i = 0}"
hoelzl@40377
  1806
  have "EX f. linear f & f ` B = {basis i |i. i : d} &
hoelzl@40377
  1807
    f ` span B = ?t & inj_on f (span B)"
hoelzl@40377
  1808
    apply (rule basis_to_basis_subspace_isomorphism[of "span B" ?t B "{basis i |i. i : d}"])
hoelzl@40377
  1809
    apply(rule subspace_span) apply(rule subspace_substandard) defer
hoelzl@40377
  1810
    apply(rule span_inc) apply(rule assms) defer unfolding dim_span[of B] apply(rule B)
hoelzl@40377
  1811
    unfolding span_substd_basis[OF d,THEN sym] card_substdbasis[OF d] apply(rule span_inc)
hoelzl@40377
  1812
    apply(rule independent_substdbasis[OF d]) apply(rule,assumption)
hoelzl@40377
  1813
    unfolding t[THEN sym] span_substd_basis[OF d] dim_substandard[OF d] by auto
hoelzl@40377
  1814
  from this t `card B=dim B` show ?thesis using d by auto 
hoelzl@40377
  1815
qed
hoelzl@40377
  1816
hoelzl@40377
  1817
lemma aff_dim_empty:
hoelzl@40377
  1818
fixes S :: "('n::euclidean_space) set" 
hoelzl@40377
  1819
shows "S = {} <-> aff_dim S = -1"
hoelzl@40377
  1820
proof-
hoelzl@40377
  1821
obtain B where "affine hull B = affine hull S & ~ affine_dependent B & int (card B) = aff_dim S + 1" using aff_dim_basis_exists by auto
hoelzl@40377
  1822
moreover hence "S={} <-> B={}" using affine_hull_nonempty[of B] affine_hull_nonempty[of S] by auto
hoelzl@40377
  1823
ultimately show ?thesis using aff_independent_finite[of B] card_gt_0_iff[of B] by auto
hoelzl@40377
  1824
qed
hoelzl@40377
  1825
hoelzl@40377
  1826
lemma aff_dim_affine_hull:
hoelzl@40377
  1827
shows "aff_dim (affine hull S)=aff_dim S" 
hoelzl@40377
  1828
unfolding aff_dim_def using hull_hull[of _ S] by auto 
hoelzl@40377
  1829
hoelzl@40377
  1830
lemma aff_dim_affine_hull2:
hoelzl@40377
  1831
assumes "affine hull S=affine hull T"
hoelzl@40377
  1832
shows "aff_dim S=aff_dim T" unfolding aff_dim_def using assms by auto
hoelzl@40377
  1833
hoelzl@40377
  1834
lemma aff_dim_unique: 
hoelzl@40377
  1835
fixes B V :: "('n::euclidean_space) set" 
hoelzl@40377
  1836
assumes "(affine hull B=affine hull V) & ~(affine_dependent B)"
hoelzl@40377
  1837
shows "of_nat(card B) = aff_dim V+1"
hoelzl@40377
  1838
proof-
hoelzl@40377
  1839
{ assume "B={}" hence "V={}" using affine_hull_nonempty[of V] affine_hull_nonempty[of B] assms by auto
hoelzl@40377
  1840
  hence "aff_dim V = (-1::int)"  using aff_dim_empty by auto  
hoelzl@40377
  1841
  hence ?thesis using `B={}` by auto
hoelzl@40377
  1842
}
hoelzl@40377
  1843
moreover
hoelzl@40377
  1844
{ assume "B~={}" from this obtain a where a_def: "a:B" by auto 
hoelzl@40377
  1845
  def Lb == "span ((%x. -a+x) ` (B-{a}))"
hoelzl@40377
  1846
  have "affine_parallel (affine hull B) Lb"
hoelzl@40377
  1847
     using Lb_def affine_hull_span2[of a B] a_def  affine_parallel_commut[of "Lb" "(affine hull B)"] 
hoelzl@40377
  1848
     unfolding affine_parallel_def by auto
hoelzl@40377
  1849
  moreover have "subspace Lb" using Lb_def subspace_span by auto
hoelzl@40377
  1850
  ultimately have "aff_dim B=int(dim Lb)" using aff_dim_parallel_subspace[of B Lb] `B~={}` by auto 
hoelzl@40377
  1851
  moreover have "(card B) - 1 = dim Lb" "finite B" using Lb_def aff_dim_parallel_subspace_aux a_def assms by auto
hoelzl@40377
  1852
  ultimately have "(of_nat(card B) = aff_dim B+1)" using  `B~={}` card_gt_0_iff[of B] by auto
hoelzl@40377
  1853
  hence ?thesis using aff_dim_affine_hull2 assms by auto
hoelzl@40377
  1854
} ultimately show ?thesis by blast
hoelzl@40377
  1855
qed
hoelzl@40377
  1856
hoelzl@40377
  1857
lemma aff_dim_affine_independent: 
hoelzl@40377
  1858
fixes B :: "('n::euclidean_space) set" 
hoelzl@40377
  1859
assumes "~(affine_dependent B)"
hoelzl@40377
  1860
shows "of_nat(card B) = aff_dim B+1"
hoelzl@40377
  1861
  using aff_dim_unique[of B B] assms by auto
hoelzl@40377
  1862
hoelzl@40377
  1863
lemma aff_dim_sing: 
hoelzl@40377
  1864
fixes a :: "'n::euclidean_space" 
hoelzl@40377
  1865
shows "aff_dim {a}=0"
hoelzl@40377
  1866
  using aff_dim_affine_independent[of "{a}"] affine_independent_sing by auto
hoelzl@40377
  1867
hoelzl@40377
  1868
lemma aff_dim_inner_basis_exists:
hoelzl@40377
  1869
  fixes V :: "('n::euclidean_space) set" 
hoelzl@40377
  1870
  shows "? B. B<=V & (affine hull B=affine hull V) & ~(affine_dependent B) & (of_nat(card B) = aff_dim V+1)"
hoelzl@40377
  1871
proof-
hoelzl@40377
  1872
obtain B where B_def: "~(affine_dependent B) & B<=V & (affine hull B=affine hull V)" using affine_basis_exists[of V] by auto
hoelzl@40377
  1873
moreover hence "of_nat(card B) = aff_dim V+1" using aff_dim_unique by auto
hoelzl@40377
  1874
ultimately show ?thesis by auto
hoelzl@40377
  1875
qed
hoelzl@40377
  1876
hoelzl@40377
  1877
lemma aff_dim_le_card:
hoelzl@40377
  1878
fixes V :: "('n::euclidean_space) set" 
hoelzl@40377
  1879
assumes "finite V"
hoelzl@40377
  1880
shows "aff_dim V <= of_nat(card V) - 1"
hoelzl@40377
  1881
 proof-
hoelzl@40377
  1882
 obtain B where B_def: "B<=V & (of_nat(card B) = aff_dim V+1)" using aff_dim_inner_basis_exists[of V] by auto 
hoelzl@40377
  1883
 moreover hence "card B <= card V" using assms card_mono by auto
hoelzl@40377
  1884
 ultimately show ?thesis by auto
hoelzl@40377
  1885
qed
hoelzl@40377
  1886
hoelzl@40377
  1887
lemma aff_dim_parallel_eq:
hoelzl@40377
  1888
fixes S T :: "('n::euclidean_space) set"
hoelzl@40377
  1889
assumes "affine_parallel (affine hull S) (affine hull T)"
hoelzl@40377
  1890
shows "aff_dim S=aff_dim T"
hoelzl@40377
  1891
proof-
hoelzl@40377
  1892
{ assume "T~={}" "S~={}" 
hoelzl@40377
  1893
  from this obtain L where L_def: "subspace L & affine_parallel (affine hull T) L" 
hoelzl@40377
  1894
       using affine_parallel_subspace[of "affine hull T"] affine_affine_hull[of T] affine_hull_nonempty by auto
hoelzl@40377
  1895
  hence "aff_dim T = int(dim L)" using aff_dim_parallel_subspace `T~={}` by auto
hoelzl@40377
  1896
  moreover have "subspace L & affine_parallel (affine hull S) L" 
hoelzl@40377
  1897
     using L_def affine_parallel_assoc[of "affine hull S" "affine hull T" L] assms by auto
hoelzl@40377
  1898
  moreover hence "aff_dim S = int(dim L)" using aff_dim_parallel_subspace `S~={}` by auto 
hoelzl@40377
  1899
  ultimately have ?thesis by auto
hoelzl@40377
  1900
}
hoelzl@40377
  1901
moreover
hoelzl@40377
  1902
{ assume "S={}" hence "S={} & T={}" using assms affine_hull_nonempty unfolding affine_parallel_def by auto
hoelzl@40377
  1903
  hence ?thesis using aff_dim_empty by auto
hoelzl@40377
  1904
}
hoelzl@40377
  1905
moreover
hoelzl@40377
  1906
{ assume "T={}" hence "S={} & T={}" using assms affine_hull_nonempty unfolding affine_parallel_def by auto
hoelzl@40377
  1907
  hence ?thesis using aff_dim_empty by auto
hoelzl@40377
  1908
}
hoelzl@40377
  1909
ultimately show ?thesis by blast
hoelzl@40377
  1910
qed
hoelzl@40377
  1911
hoelzl@40377
  1912
lemma aff_dim_translation_eq:
hoelzl@40377
  1913
fixes a :: "'n::euclidean_space"
hoelzl@40377
  1914
shows "aff_dim ((%x. a + x) ` S)=aff_dim S" 
hoelzl@40377
  1915
proof-
hoelzl@40377
  1916
have "affine_parallel (affine hull S) (affine hull ((%x. a + x) ` S))" unfolding affine_parallel_def apply (rule exI[of _ "a"]) using affine_hull_translation[of a S] by auto
hoelzl@40377
  1917
from this show ?thesis using  aff_dim_parallel_eq[of S "(%x. a + x) ` S"] by auto 
hoelzl@40377
  1918
qed
hoelzl@40377
  1919
hoelzl@40377
  1920
lemma aff_dim_affine:
hoelzl@40377
  1921
fixes S L :: "('n::euclidean_space) set"
hoelzl@40377
  1922
assumes "S ~= {}" "affine S"
hoelzl@40377
  1923
assumes "subspace L" "affine_parallel S L"
hoelzl@40377
  1924
shows "aff_dim S=int(dim L)" 
hoelzl@40377
  1925
proof-
hoelzl@40377
  1926
have 1: "(affine hull S) = S" using assms affine_hull_eq[of S] by auto 
hoelzl@40377
  1927
hence "affine_parallel (affine hull S) L" using assms by (simp add:1)
hoelzl@40377
  1928
from this show ?thesis using assms aff_dim_parallel_subspace[of S L] by blast 
hoelzl@40377
  1929
qed
hoelzl@40377
  1930
hoelzl@40377
  1931
lemma dim_affine_hull:
hoelzl@40377
  1932
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  1933
shows "dim (affine hull S)=dim S"
hoelzl@40377
  1934
proof-
hoelzl@40377
  1935
have "dim (affine hull S)>=dim S" using dim_subset by auto
hoelzl@40377
  1936
moreover have "dim(span S) >= dim (affine hull S)" using dim_subset affine_hull_subset_span by auto
hoelzl@40377
  1937
moreover have "dim(span S)=dim S" using dim_span by auto
hoelzl@40377
  1938
ultimately show ?thesis by auto
hoelzl@40377
  1939
qed
hoelzl@40377
  1940
hoelzl@40377
  1941
lemma aff_dim_subspace:
hoelzl@40377
  1942
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  1943
assumes "S ~= {}" "subspace S"
hoelzl@40377
  1944
shows "aff_dim S=int(dim S)" using aff_dim_affine[of S S] assms subspace_imp_affine[of S] affine_parallel_reflex[of S] by auto 
hoelzl@40377
  1945
hoelzl@40377
  1946
lemma aff_dim_zero:
hoelzl@40377
  1947
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  1948
assumes "0 : affine hull S"
hoelzl@40377
  1949
shows "aff_dim S=int(dim S)"
hoelzl@40377
  1950
proof-
hoelzl@40377
  1951
have "subspace(affine hull S)" using subspace_affine[of "affine hull S"] affine_affine_hull assms by auto
hoelzl@40377
  1952
hence "aff_dim (affine hull S) =int(dim (affine hull S))" using assms aff_dim_subspace[of "affine hull S"] by auto  
hoelzl@40377
  1953
from this show ?thesis using aff_dim_affine_hull[of S] dim_affine_hull[of S] by auto
hoelzl@40377
  1954
qed
hoelzl@40377
  1955
hoelzl@40377
  1956
lemma aff_dim_univ: "aff_dim (UNIV :: ('n::euclidean_space) set) = int(DIM('n))"
hoelzl@40377
  1957
  using aff_dim_subspace[of "(UNIV :: ('n::euclidean_space) set)"]
hoelzl@40377
  1958
    dim_UNIV[where 'a="'n::euclidean_space"] by auto
hoelzl@40377
  1959
hoelzl@40377
  1960
lemma aff_dim_geq:
hoelzl@40377
  1961
  fixes V :: "('n::euclidean_space) set"
hoelzl@40377
  1962
  shows "aff_dim V >= -1"
hoelzl@40377
  1963
proof-
hoelzl@40377
  1964
obtain B where B_def: "affine hull B = affine hull V & ~ affine_dependent B & int (card B) = aff_dim V + 1" using aff_dim_basis_exists by auto
hoelzl@40377
  1965
from this show ?thesis by auto
hoelzl@40377
  1966
qed
hoelzl@40377
  1967
hoelzl@40377
  1968
lemma independent_card_le_aff_dim: 
hoelzl@40377
  1969
  assumes "(B::('n::euclidean_space) set) <= V"
hoelzl@40377
  1970
  assumes "~(affine_dependent B)" 
hoelzl@40377
  1971
  shows "int(card B) <= aff_dim V+1"
hoelzl@40377
  1972
proof-
hoelzl@40377
  1973
{ assume "B~={}" 
hoelzl@40377
  1974
  from this obtain T where T_def: "~(affine_dependent T) & B<=T & T<=V & affine hull T = affine hull V" 
hoelzl@40377
  1975
  using assms extend_to_affine_basis[of B V] by auto
hoelzl@40377
  1976
  hence "of_nat(card T) = aff_dim V+1" using aff_dim_unique by auto
hoelzl@40377
  1977
  hence ?thesis using T_def card_mono[of T B] aff_independent_finite[of T] by auto
hoelzl@40377
  1978
}
hoelzl@40377
  1979
moreover
hoelzl@40377
  1980
{ assume "B={}"
hoelzl@40377
  1981
  moreover have "-1<= aff_dim V" using aff_dim_geq by auto
hoelzl@40377
  1982
  ultimately have ?thesis by auto
hoelzl@40377
  1983
}  ultimately show ?thesis by blast
hoelzl@40377
  1984
qed
hoelzl@40377
  1985
hoelzl@40377
  1986
lemma aff_dim_subset:
hoelzl@40377
  1987
  fixes S T :: "('n::euclidean_space) set"
hoelzl@40377
  1988
  assumes "S <= T"
hoelzl@40377
  1989
  shows "aff_dim S <= aff_dim T"
hoelzl@40377
  1990
proof-
hoelzl@40377
  1991
obtain B where B_def: "~(affine_dependent B) & B<=S & (affine hull B=affine hull S) & of_nat(card B) = aff_dim S+1" using aff_dim_inner_basis_exists[of S] by auto
hoelzl@40377
  1992
moreover hence "int (card B) <= aff_dim T + 1" using assms independent_card_le_aff_dim[of B T] by auto
hoelzl@40377
  1993
ultimately show ?thesis by auto
hoelzl@40377
  1994
qed
hoelzl@40377
  1995
hoelzl@40377
  1996
lemma aff_dim_subset_univ:
hoelzl@40377
  1997
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  1998
shows "aff_dim S <= int(DIM('n))"
hoelzl@40377
  1999
proof - 
hoelzl@40377
  2000
  have "aff_dim (UNIV :: ('n::euclidean_space) set) = int(DIM('n))" using aff_dim_univ by auto
hoelzl@40377
  2001
  from this show "aff_dim (S:: ('n::euclidean_space) set) <= int(DIM('n))" using assms aff_dim_subset[of S "(UNIV :: ('n::euclidean_space) set)"] subset_UNIV by auto
hoelzl@40377
  2002
qed
hoelzl@40377
  2003
hoelzl@40377
  2004
lemma affine_dim_equal:
hoelzl@40377
  2005
assumes "affine (S :: ('n::euclidean_space) set)" "affine T" "S ~= {}" "S <= T" "aff_dim S = aff_dim T"
hoelzl@40377
  2006
shows "S=T"
hoelzl@40377
  2007
proof-
hoelzl@40377
  2008
obtain a where "a : S" using assms by auto 
hoelzl@40377
  2009
hence "a : T" using assms by auto
hoelzl@40377
  2010
def LS == "{y. ? x : S. (-a)+x=y}"
hoelzl@40377
  2011
hence ls: "subspace LS & affine_parallel S LS" using assms parallel_subspace_explicit[of S a LS] `a : S` by auto 
hoelzl@40377
  2012
hence h1: "int(dim LS) = aff_dim S" using assms aff_dim_affine[of S LS] by auto
hoelzl@40377
  2013
have "T ~= {}" using assms by auto
hoelzl@40377
  2014
def LT == "{y. ? x : T. (-a)+x=y}" 
hoelzl@40377
  2015
hence lt: "subspace LT & affine_parallel T LT" using assms parallel_subspace_explicit[of T a LT] `a : T` by auto
hoelzl@40377
  2016
hence "int(dim LT) = aff_dim T" using assms aff_dim_affine[of T LT] `T ~= {}` by auto 
hoelzl@40377
  2017
hence "dim LS = dim LT" using h1 assms by auto
hoelzl@40377
  2018
moreover have "LS <= LT" using LS_def LT_def assms by auto
hoelzl@40377
  2019
ultimately have "LS=LT" using subspace_dim_equal[of LS LT] ls lt by auto
hoelzl@40377
  2020
moreover have "S = {x. ? y : LS. a+y=x}" using LS_def by auto 
hoelzl@40377
  2021
moreover have "T = {x. ? y : LT. a+y=x}" using LT_def by auto
hoelzl@40377
  2022
ultimately show ?thesis by auto 
hoelzl@40377
  2023
qed
hoelzl@40377
  2024
hoelzl@40377
  2025
lemma affine_hull_univ:
hoelzl@40377
  2026
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  2027
assumes "aff_dim S = int(DIM('n))"
hoelzl@40377
  2028
shows "affine hull S = (UNIV :: ('n::euclidean_space) set)"
hoelzl@40377
  2029
proof-
hoelzl@40377
  2030
have "S ~= {}" using assms aff_dim_empty[of S] by auto
hoelzl@40377
  2031
have h0: "S <= affine hull S" using hull_subset[of S _] by auto
hoelzl@40377
  2032
have h1: "aff_dim (UNIV :: ('n::euclidean_space) set) = aff_dim S" using aff_dim_univ assms by auto
hoelzl@40377
  2033
hence h2: "aff_dim (affine hull S) <= aff_dim (UNIV :: ('n::euclidean_space) set)" using aff_dim_subset_univ[of "affine hull S"] assms h0 by auto  
hoelzl@40377
  2034
have h3: "aff_dim S <= aff_dim (affine hull S)" using h0 aff_dim_subset[of S "affine hull S"] assms by auto
hoelzl@40377
  2035
hence h4: "aff_dim (affine hull S) = aff_dim (UNIV :: ('n::euclidean_space) set)" using h0 h1 h2 by auto
hoelzl@40377
  2036
from this show ?thesis using affine_dim_equal[of "affine hull S" "(UNIV :: ('n::euclidean_space) set)"] affine_affine_hull[of S] affine_UNIV assms h4 h0 `S ~= {}` by auto
hoelzl@40377
  2037
qed
hoelzl@40377
  2038
hoelzl@40377
  2039
lemma aff_dim_convex_hull:
hoelzl@40377
  2040
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  2041
shows "aff_dim (convex hull S)=aff_dim S"
hoelzl@40377
  2042
  using aff_dim_affine_hull[of S] convex_hull_subset_affine_hull[of S] 
hoelzl@40377
  2043
  hull_subset[of S "convex"] aff_dim_subset[of S "convex hull S"] 
hoelzl@40377
  2044
  aff_dim_subset[of "convex hull S" "affine hull S"] by auto
hoelzl@40377
  2045
hoelzl@40377
  2046
lemma aff_dim_cball:
hoelzl@40377
  2047
fixes a :: "'n::euclidean_space" 
hoelzl@40377
  2048
assumes "0<e"
hoelzl@40377
  2049
shows "aff_dim (cball a e) = int (DIM('n))"
hoelzl@40377
  2050
proof-
hoelzl@40377
  2051
have "(%x. a + x) ` (cball 0 e)<=cball a e" unfolding cball_def dist_norm by auto
hoelzl@40377
  2052
hence "aff_dim (cball (0 :: 'n::euclidean_space) e) <= aff_dim (cball a e)"
hoelzl@40377
  2053
  using aff_dim_translation_eq[of a "cball 0 e"] 
hoelzl@40377
  2054
        aff_dim_subset[of "op + a ` cball 0 e" "cball a e"] by auto
hoelzl@40377
  2055
moreover have "aff_dim (cball (0 :: 'n::euclidean_space) e) = int (DIM('n))" 
hoelzl@40377
  2056
   using hull_inc[of "(0 :: 'n::euclidean_space)" "cball 0 e"] centre_in_cball[of "(0 :: 'n::euclidean_space)"] assms 
hoelzl@40377
  2057
   by (simp add: dim_cball[of e] aff_dim_zero[of "cball 0 e"])
hoelzl@40377
  2058
ultimately show ?thesis using aff_dim_subset_univ[of "cball a e"] by auto 
hoelzl@40377
  2059
qed
hoelzl@40377
  2060
hoelzl@40377
  2061
lemma aff_dim_open:
hoelzl@40377
  2062
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  2063
assumes "open S" "S ~= {}"
hoelzl@40377
  2064
shows "aff_dim S = int (DIM('n))"
hoelzl@40377
  2065
proof-
hoelzl@40377
  2066
obtain x where "x:S" using assms by auto
hoelzl@40377
  2067
from this obtain e where e_def: "e>0 & cball x e <= S" using open_contains_cball[of S] assms by auto
hoelzl@40377
  2068
from this have "aff_dim (cball x e) <= aff_dim S" using aff_dim_subset by auto
hoelzl@40377
  2069
from this show ?thesis using aff_dim_cball[of e x] aff_dim_subset_univ[of S] e_def by auto     
hoelzl@40377
  2070
qed
hoelzl@40377
  2071
hoelzl@40377
  2072
lemma low_dim_interior:
hoelzl@40377
  2073
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  2074
assumes "~(aff_dim S = int (DIM('n)))"
hoelzl@40377
  2075
shows "interior S = {}"
hoelzl@40377
  2076
proof-
hoelzl@40377
  2077
have "aff_dim(interior S) <= aff_dim S" 
hoelzl@40377
  2078
   using interior_subset aff_dim_subset[of "interior S" S] by auto 
hoelzl@40377
  2079
from this show ?thesis using aff_dim_open[of "interior S"] aff_dim_subset_univ[of S] assms by auto   
hoelzl@40377
  2080
qed
hoelzl@40377
  2081
hoelzl@40377
  2082
subsection{* Relative Interior of a Set *}
hoelzl@40377
  2083
hoelzl@40377
  2084
definition "rel_interior S = {x. ? T. openin (subtopology euclidean (affine hull S)) T & x : T & T <= S}"
hoelzl@40377
  2085
hoelzl@40377
  2086
lemma rel_interior: "rel_interior S = {x : S. ? T. open T & x : T & (T Int (affine hull S)) <= S}"
hoelzl@40377
  2087
  unfolding rel_interior_def[of S] openin_open[of "affine hull S"] apply auto
hoelzl@40377
  2088
proof-
hoelzl@40377
  2089
fix x T assume a: "x:S" "open T" "x : T" "(T Int (affine hull S)) <= S"
hoelzl@40377
  2090
hence h1: "x : T Int affine hull S" using hull_inc by auto
hoelzl@40377
  2091
show "EX Tb. (EX Ta. open Ta & Tb = affine hull S Int Ta) & x : Tb & Tb <= S"
hoelzl@40377
  2092
apply (rule_tac x="T Int (affine hull S)" in exI)
hoelzl@40377
  2093
using a h1 by auto
hoelzl@40377
  2094
qed
hoelzl@40377
  2095
hoelzl@40377
  2096
lemma mem_rel_interior: 
hoelzl@40377
  2097
     "x : rel_interior S <-> (? T. open T & x : (T Int S) & (T Int (affine hull S)) <= S)" 
hoelzl@40377
  2098
     by (auto simp add: rel_interior)
hoelzl@40377
  2099
hoelzl@40377
  2100
lemma mem_rel_interior_ball: "x : rel_interior S <-> x : S & (? e. 0 < e & ((ball x e) Int (affine hull S)) <= S)"
hoelzl@40377
  2101
  apply (simp add: rel_interior, safe)
hoelzl@40377
  2102
  apply (force simp add: open_contains_ball)
hoelzl@40377
  2103
  apply (rule_tac x="ball x e" in exI)
huffman@44142
  2104
  apply (simp add: centre_in_ball)
hoelzl@40377
  2105
  done
hoelzl@40377
  2106
hoelzl@40377
  2107
lemma rel_interior_ball: 
hoelzl@40377
  2108
      "rel_interior S = {x : S. ? e. e>0 & ((ball x e) Int (affine hull S)) <= S}" 
hoelzl@40377
  2109
      using mem_rel_interior_ball [of _ S] by auto 
hoelzl@40377
  2110
hoelzl@40377
  2111
lemma mem_rel_interior_cball: "x : rel_interior S <-> x : S & (? e. 0 < e & ((cball x e) Int (affine hull S)) <= S)"
hoelzl@40377
  2112
  apply (simp add: rel_interior, safe) 
hoelzl@40377
  2113
  apply (force simp add: open_contains_cball)
hoelzl@40377
  2114
  apply (rule_tac x="ball x e" in exI)
hoelzl@40377
  2115
  apply (simp add: open_ball centre_in_ball subset_trans [OF ball_subset_cball])
hoelzl@40377
  2116
  apply auto
hoelzl@40377
  2117
  done
hoelzl@40377
  2118
hoelzl@40377
  2119
lemma rel_interior_cball: "rel_interior S = {x : S. ? e. e>0 & ((cball x e) Int (affine hull S)) <= S}"       using mem_rel_interior_cball [of _ S] by auto
hoelzl@40377
  2120
hoelzl@40377
  2121
lemma rel_interior_empty: "rel_interior {} = {}" 
hoelzl@40377
  2122
   by (auto simp add: rel_interior_def) 
hoelzl@40377
  2123
hoelzl@40377
  2124
lemma affine_hull_sing: "affine hull {a :: 'n::euclidean_space} = {a}"
hoelzl@40377
  2125
by (metis affine_hull_eq affine_sing)
hoelzl@40377
  2126
hoelzl@40377
  2127
lemma rel_interior_sing: "rel_interior {a :: 'n::euclidean_space} = {a}"
hoelzl@40377
  2128
   unfolding rel_interior_ball affine_hull_sing apply auto
hoelzl@40377
  2129
   apply(rule_tac x="1 :: real" in exI) apply simp
hoelzl@40377
  2130
   done
hoelzl@40377
  2131
hoelzl@40377
  2132
lemma subset_rel_interior:
hoelzl@40377
  2133
fixes S T :: "('n::euclidean_space) set"
hoelzl@40377
  2134
assumes "S<=T" "affine hull S=affine hull T"
hoelzl@40377
  2135
shows "rel_interior S <= rel_interior T"
hoelzl@40377
  2136
  using assms by (auto simp add: rel_interior_def)  
hoelzl@40377
  2137
hoelzl@40377
  2138
lemma rel_interior_subset: "rel_interior S <= S" 
hoelzl@40377
  2139
   by (auto simp add: rel_interior_def)
hoelzl@40377
  2140
hoelzl@40377
  2141
lemma rel_interior_subset_closure: "rel_interior S <= closure S" 
hoelzl@40377
  2142
   using rel_interior_subset by (auto simp add: closure_def) 
hoelzl@40377
  2143
hoelzl@40377
  2144
lemma interior_subset_rel_interior: "interior S <= rel_interior S" 
hoelzl@40377
  2145
   by (auto simp add: rel_interior interior_def)
hoelzl@40377
  2146
hoelzl@40377
  2147
lemma interior_rel_interior:
hoelzl@40377
  2148
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  2149
assumes "aff_dim S = int(DIM('n))"
hoelzl@40377
  2150
shows "rel_interior S = interior S"
hoelzl@40377
  2151
proof -
hoelzl@40377
  2152
have "affine hull S = UNIV" using assms affine_hull_univ[of S] by auto 
hoelzl@40377
  2153
from this show ?thesis unfolding rel_interior interior_def by auto
hoelzl@40377
  2154
qed
hoelzl@40377
  2155
hoelzl@40377
  2156
lemma rel_interior_open:
hoelzl@40377
  2157
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  2158
assumes "open S"
hoelzl@40377
  2159
shows "rel_interior S = S"
hoelzl@40377
  2160
by (metis assms interior_eq interior_subset_rel_interior rel_interior_subset set_eq_subset)
hoelzl@40377
  2161
hoelzl@40377
  2162
lemma interior_rel_interior_gen:
hoelzl@40377
  2163
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  2164
shows "interior S = (if aff_dim S = int(DIM('n)) then rel_interior S else {})"
hoelzl@40377
  2165
by (metis interior_rel_interior low_dim_interior)
hoelzl@40377
  2166
hoelzl@40377
  2167
lemma rel_interior_univ: 
hoelzl@40377
  2168
fixes S :: "('n::euclidean_space) set"
hoelzl@40377
  2169
shows "rel_interior (affine hull S) = affine hull S"
hoelzl@40377
  2170
proof-
hoelzl@40377
  2171
have h1: "rel_interior (affine hull S) <= affine hull S" using rel_interior_subset by auto 
hoelzl@40377
  2172
{ fix x assume x_def: "x : affine hull S"
hoelzl@40377
  2173
  obtain e :: real where "e=1" by auto
hoelzl@40377
  2174
  hence "e>0 & ball x e Int affine hull (affine hull S) <= affine hull S" using hull_hull[of _ S] by auto
hoelzl@40377
  2175
  hence "x : rel_interior (affine hull S)" using x_def rel_interior_ball[of "affine hull S"] by auto
hoelzl@40377
  2176
} from this show ?thesis using h1 by auto 
hoelzl@40377
  2177
qed
hoelzl@40377
  2178
hoelzl@40377
  2179
lemma rel_interior_univ2: "rel_interior (UNIV :: ('n::euclidean_space) set) = UNIV"
hoelzl@40377
  2180
by (metis open_UNIV rel_interior_open)
hoelzl@40377
  2181
hoelzl@40377
  2182
lemma rel_interior_convex_shrink:
hoelzl@40377
  2183
  fixes S :: "('a::euclidean_space) set"
hoelzl@40377
  2184
  assumes "convex S" "c : rel_interior S" "x : S" "0 < e" "e <= 1"
hoelzl@40377
  2185
  shows "x - e *\<^sub>R (x - c) : rel_interior S"
hoelzl@40377
  2186
proof- 
hoelzl@40377
  2187
(* Proof is a modified copy of the proof of similar lemma mem_interior_convex_shrink 
hoelzl@40377
  2188
*)
hoelzl@40377
  2189
obtain d where "d>0" and d:"ball c d Int affine hull S <= S" 
hoelzl@40377
  2190
  using assms(2) unfolding  mem_rel_interior_ball by auto
hoelzl@40377
  2191
{   fix y assume as:"dist (x - e *\<^sub>R (x - c)) y < e * d & y : affine hull S"
hoelzl@40377
  2192
    have *:"y = (1 - (1 - e)) *\<^sub>R ((1 / e) *\<^sub>R y - ((1 - e) / e) *\<^sub>R x) + (1 - e) *\<^sub>R x" using `e>0` by (auto simp add: scaleR_left_diff_distrib scaleR_right_diff_distrib)
hoelzl@40377
  2193
    have "x : affine hull S" using assms hull_subset[of S] by auto
hoelzl@40377
  2194
    moreover have "1 / e + - ((1 - e) / e) = 1" 
huffman@44282
  2195
       using `e>0` left_diff_distrib[of "1" "(1-e)" "1/e"] by auto
hoelzl@40377
  2196
    ultimately have **: "(1 / e) *\<^sub>R y - ((1 - e) / e) *\<^sub>R x : affine hull S"
hoelzl@40377
  2197
        using as affine_affine_hull[of S] mem_affine[of "affine hull S" y x "(1 / e)" "-((1 - e) / e)"] by (simp add: algebra_simps)     
hoelzl@40377
  2198
    have "dist c ((1 / e) *\<^sub>R y - ((1 - e) / e) *\<^sub>R x) = abs(1/e) * norm (e *\<^sub>R c - y + (1 - e) *\<^sub>R x)"
hoelzl@40377
  2199
      unfolding dist_norm unfolding norm_scaleR[THEN sym] apply(rule arg_cong[where f=norm]) using `e>0`
hoelzl@40377
  2200
      by(auto simp add:euclidean_eq[where 'a='a] field_simps) 
hoelzl@40377
  2201
    also have "... = abs(1/e) * norm (x - e *\<^sub>R (x - c) - y)" by(auto intro!:arg_cong[where f=norm] simp add: algebra_simps)
hoelzl@40377
  2202
    also have "... < d" using as[unfolded dist_norm] and `e>0`
hoelzl@40377
  2203
      by(auto simp add:pos_divide_less_eq[OF `e>0`] real_mult_commute)
hoelzl@40377
  2204
    finally have "y : S" apply(subst *) 
hoelzl@40377
  2205
apply(rule assms(1)[unfolded convex_alt,rule_format])
hoelzl@40377
  2206
      apply(rule d[unfolded subset_eq,rule_format]) unfolding mem_ball using assms(3-5) ** by auto
hoelzl@40377
  2207
} hence "ball (x - e *\<^sub>R (x - c)) (e*d) Int affine hull S <= S" by auto
hoelzl@40377
  2208
moreover have "0 < e*d" using `0<e` `0<d` using real_mult_order by auto
hoelzl@40377
  2209
moreover have "c : S" using assms rel_interior_subset by auto
hoelzl@40377
  2210
moreover hence "x - e *\<^sub>R (x - c) : S"
hoelzl@40377
  2211
   using mem_convex[of S x c e] apply (simp add: algebra_simps) using assms by auto
hoelzl@40377
  2212
ultimately show ?thesis 
hoelzl@40377
  2213
  using mem_rel_interior_ball[of "x - e *\<^sub>R (x - c)" S] `e>0` by auto
hoelzl@40377
  2214
qed
hoelzl@40377
  2215
hoelzl@40377
  2216
lemma interior_real_semiline:
hoelzl@40377
  2217
fixes a :: real
hoelzl@40377
  2218
shows "interior {a..} = {a<..}"
hoelzl@40377
  2219
proof-
hoelzl@40377
  2220
{ fix y assume "a<y" hence "y : interior {a..}"
hoelzl@40377
  2221
  apply (simp add: mem_interior) apply (rule_tac x="(y-a)" in exI) apply (auto simp add: dist_norm) 
hoelzl@40377
  2222
  done }
hoelzl@40377
  2223
moreover
hoelzl@40377
  2224
{ fix y assume "y : interior {a..}" (*hence "a<=y" using interior_subset by auto*)
hoelzl@40377
  2225
  from this obtain e where e_def: "e>0 & cball y e \<subseteq> {a..}" 
hoelzl@40377
  2226
     using mem_interior_cball[of y "{a..}"] by auto
hoelzl@40377
  2227
  moreover hence "y-e : cball y e" by (auto simp add: cball_def dist_norm) 
hoelzl@40377
  2228
  ultimately have "a<=y-e" by auto
hoelzl@40377
  2229
  hence "a<y" using e_def by auto
hoelzl@40377
  2230
} ultimately show ?thesis by auto
hoelzl@40377
  2231
qed
hoelzl@40377
  2232
hoelzl@40377
  2233
lemma rel_interior_real_interval:
hoelzl@40377
  2234
  fixes a b :: real assumes "a < b" shows "rel_interior {a..b} = {a<..<b}"
hoelzl@40377
  2235
proof-
hoelzl@40377
  2236
  have "{a<..<b} \<noteq> {}" using assms unfolding set_eq_iff by (auto intro!: exI[of _ "(a + b) / 2"])
hoelzl@40377
  2237
  then show ?thesis
hoelzl@40377
  2238
    using interior_rel_interior_gen[of "{a..b}", symmetric]
hoelzl@40377
  2239
    by (simp split: split_if_asm add: interior_closed_interval)
hoelzl@40377
  2240
qed
hoelzl@40377
  2241
hoelzl@40377
  2242
lemma rel_interior_real_semiline:
hoelzl@40377
  2243
  fixes a :: real shows "rel_interior {a..} = {a<..}"
hoelzl@40377
  2244
proof-
hoelzl@40377
  2245
  have *: "{a<..} \<noteq> {}" unfolding set_eq_iff by (auto intro!: exI[of _ "a + 1"])
hoelzl@40377
  2246
  then show ?thesis using interior_real_semiline
hoelzl@40377
  2247
     interior_rel_interior_gen[of "{a..}"]
hoelzl@40377
  2248
     by (auto split: split_if_asm)
hoelzl@40377
  2249
qed
hoelzl@40377
  2250
hoelzl@40377
  2251
subsection "Relative open"
hoelzl@40377
  2252
hoelzl@40377
  2253
definition "rel_open S <-> (rel_interior S) = S"
hoelzl@40377
  2254
hoelzl@40377
  2255
lemma rel_open: "rel_open S <-> openin (subtopology euclidean (affine hull S)) S"
hoelzl@40377
  2256
 unfolding rel_open_def rel_interior_def apply auto
hoelzl@40377
  2257
 using openin_subopen[of "subtopology euclidean (affine hull S)" S] by auto
hoelzl@40377
  2258