src/HOL/Analysis/Cartesian_Euclidean_Space.thy
author immler
Thu May 03 15:07:14 2018 +0200 (12 months ago)
changeset 68073 fad29d2a17a5
parent 68072 493b818e8e10
parent 68069 36209dfb981e
child 68074 8d50467f7555
permissions -rw-r--r--
merged; resolved conflicts manually (esp. lemmas that have been moved from Linear_Algebra and Cartesian_Euclidean_Space)
lp15@68038
     1
(* Title:      HOL/Analysis/Cartesian_Euclidean_Space.thy
lp15@68043
     2
   Some material by Jose Divasón, Tim Makarios and L C Paulson
lp15@68038
     3
*)
lp15@68038
     4
nipkow@67968
     5
section \<open>Instantiates the finite Cartesian product of Euclidean spaces as a Euclidean space\<close>
hoelzl@37489
     6
hoelzl@37489
     7
theory Cartesian_Euclidean_Space
immler@68072
     8
imports Cartesian_Space Derivative
hoelzl@37489
     9
begin
hoelzl@37489
    10
lp15@63016
    11
lemma subspace_special_hyperplane: "subspace {x. x $ k = 0}"
lp15@63016
    12
  by (simp add: subspace_def)
lp15@63016
    13
nipkow@64267
    14
lemma sum_mult_product:
nipkow@64267
    15
  "sum h {..<A * B :: nat} = (\<Sum>i\<in>{..<A}. \<Sum>j\<in>{..<B}. h (j + i * B))"
nipkow@64267
    16
  unfolding sum_nat_group[of h B A, unfolded atLeast0LessThan, symmetric]
nipkow@64267
    17
proof (rule sum.cong, simp, rule sum.reindex_cong)
wenzelm@49644
    18
  fix i
wenzelm@49644
    19
  show "inj_on (\<lambda>j. j + i * B) {..<B}" by (auto intro!: inj_onI)
hoelzl@37489
    20
  show "{i * B..<i * B + B} = (\<lambda>j. j + i * B) ` {..<B}"
hoelzl@37489
    21
  proof safe
hoelzl@37489
    22
    fix j assume "j \<in> {i * B..<i * B + B}"
wenzelm@49644
    23
    then show "j \<in> (\<lambda>j. j + i * B) ` {..<B}"
hoelzl@37489
    24
      by (auto intro!: image_eqI[of _ _ "j - i * B"])
hoelzl@37489
    25
  qed simp
hoelzl@37489
    26
qed simp
hoelzl@37489
    27
immler@56188
    28
lemma interval_cbox_cart: "{a::real^'n..b} = cbox a b"
immler@56188
    29
  by (auto simp add: less_eq_vec_def mem_box Basis_vec_def inner_axis)
immler@56188
    30
lp15@67979
    31
lemma differentiable_vec:
lp15@67979
    32
  fixes S :: "'a::euclidean_space set"
lp15@67979
    33
  shows "vec differentiable_on S"
lp15@67979
    34
  by (simp add: linear_linear bounded_linear_imp_differentiable_on)
lp15@67979
    35
lp15@67979
    36
lemma continuous_vec [continuous_intros]:
lp15@67979
    37
  fixes x :: "'a::euclidean_space"
lp15@67979
    38
  shows "isCont vec x"
lp15@67979
    39
  apply (clarsimp simp add: continuous_def LIM_def dist_vec_def L2_set_def)
lp15@67979
    40
  apply (rule_tac x="r / sqrt (real CARD('b))" in exI)
lp15@67979
    41
  by (simp add: mult.commute pos_less_divide_eq real_sqrt_mult)
lp15@67979
    42
lp15@67979
    43
lemma box_vec_eq_empty [simp]:
lp15@67979
    44
  shows "cbox (vec a) (vec b) = {} \<longleftrightarrow> cbox a b = {}"
lp15@67979
    45
        "box (vec a) (vec b) = {} \<longleftrightarrow> box a b = {}"
lp15@67979
    46
  by (auto simp: Basis_vec_def mem_box box_eq_empty inner_axis)
lp15@67979
    47
lp15@62397
    48
subsection\<open>Closures and interiors of halfspaces\<close>
lp15@62397
    49
lp15@62397
    50
lemma interior_halfspace_le [simp]:
lp15@62397
    51
  assumes "a \<noteq> 0"
lp15@62397
    52
    shows "interior {x. a \<bullet> x \<le> b} = {x. a \<bullet> x < b}"
lp15@62397
    53
proof -
lp15@62397
    54
  have *: "a \<bullet> x < b" if x: "x \<in> S" and S: "S \<subseteq> {x. a \<bullet> x \<le> b}" and "open S" for S x
lp15@62397
    55
  proof -
lp15@62397
    56
    obtain e where "e>0" and e: "cball x e \<subseteq> S"
lp15@62397
    57
      using \<open>open S\<close> open_contains_cball x by blast
lp15@62397
    58
    then have "x + (e / norm a) *\<^sub>R a \<in> cball x e"
lp15@62397
    59
      by (simp add: dist_norm)
lp15@62397
    60
    then have "x + (e / norm a) *\<^sub>R a \<in> S"
lp15@62397
    61
      using e by blast
lp15@62397
    62
    then have "x + (e / norm a) *\<^sub>R a \<in> {x. a \<bullet> x \<le> b}"
lp15@62397
    63
      using S by blast
lp15@62397
    64
    moreover have "e * (a \<bullet> a) / norm a > 0"
lp15@62397
    65
      by (simp add: \<open>0 < e\<close> assms)
lp15@62397
    66
    ultimately show ?thesis
lp15@62397
    67
      by (simp add: algebra_simps)
lp15@62397
    68
  qed
lp15@62397
    69
  show ?thesis
lp15@62397
    70
    by (rule interior_unique) (auto simp: open_halfspace_lt *)
lp15@62397
    71
qed
lp15@62397
    72
lp15@62397
    73
lemma interior_halfspace_ge [simp]:
lp15@62397
    74
   "a \<noteq> 0 \<Longrightarrow> interior {x. a \<bullet> x \<ge> b} = {x. a \<bullet> x > b}"
lp15@62397
    75
using interior_halfspace_le [of "-a" "-b"] by simp
lp15@62397
    76
lp15@62397
    77
lemma interior_halfspace_component_le [simp]:
wenzelm@67731
    78
     "interior {x. x$k \<le> a} = {x :: (real^'n). x$k < a}" (is "?LE")
lp15@62397
    79
  and interior_halfspace_component_ge [simp]:
wenzelm@67731
    80
     "interior {x. x$k \<ge> a} = {x :: (real^'n). x$k > a}" (is "?GE")
lp15@62397
    81
proof -
lp15@62397
    82
  have "axis k (1::real) \<noteq> 0"
lp15@62397
    83
    by (simp add: axis_def vec_eq_iff)
lp15@62397
    84
  moreover have "axis k (1::real) \<bullet> x = x$k" for x
lp15@62397
    85
    by (simp add: cart_eq_inner_axis inner_commute)
lp15@62397
    86
  ultimately show ?LE ?GE
lp15@62397
    87
    using interior_halfspace_le [of "axis k (1::real)" a]
lp15@62397
    88
          interior_halfspace_ge [of "axis k (1::real)" a] by auto
lp15@62397
    89
qed
lp15@62397
    90
lp15@62397
    91
lemma closure_halfspace_lt [simp]:
lp15@62397
    92
  assumes "a \<noteq> 0"
lp15@62397
    93
    shows "closure {x. a \<bullet> x < b} = {x. a \<bullet> x \<le> b}"
lp15@62397
    94
proof -
lp15@62397
    95
  have [simp]: "-{x. a \<bullet> x < b} = {x. a \<bullet> x \<ge> b}"
lp15@62397
    96
    by (force simp:)
lp15@62397
    97
  then show ?thesis
lp15@62397
    98
    using interior_halfspace_ge [of a b] assms
lp15@62397
    99
    by (force simp: closure_interior)
lp15@62397
   100
qed
lp15@62397
   101
lp15@62397
   102
lemma closure_halfspace_gt [simp]:
lp15@62397
   103
   "a \<noteq> 0 \<Longrightarrow> closure {x. a \<bullet> x > b} = {x. a \<bullet> x \<ge> b}"
lp15@62397
   104
using closure_halfspace_lt [of "-a" "-b"] by simp
lp15@62397
   105
lp15@62397
   106
lemma closure_halfspace_component_lt [simp]:
wenzelm@67731
   107
     "closure {x. x$k < a} = {x :: (real^'n). x$k \<le> a}" (is "?LE")
lp15@62397
   108
  and closure_halfspace_component_gt [simp]:
wenzelm@67731
   109
     "closure {x. x$k > a} = {x :: (real^'n). x$k \<ge> a}" (is "?GE")
lp15@62397
   110
proof -
lp15@62397
   111
  have "axis k (1::real) \<noteq> 0"
lp15@62397
   112
    by (simp add: axis_def vec_eq_iff)
lp15@62397
   113
  moreover have "axis k (1::real) \<bullet> x = x$k" for x
lp15@62397
   114
    by (simp add: cart_eq_inner_axis inner_commute)
lp15@62397
   115
  ultimately show ?LE ?GE
lp15@62397
   116
    using closure_halfspace_lt [of "axis k (1::real)" a]
lp15@62397
   117
          closure_halfspace_gt [of "axis k (1::real)" a] by auto
lp15@62397
   118
qed
lp15@62397
   119
lp15@62397
   120
lemma interior_hyperplane [simp]:
lp15@62397
   121
  assumes "a \<noteq> 0"
lp15@62397
   122
    shows "interior {x. a \<bullet> x = b} = {}"
lp15@62397
   123
proof -
lp15@62397
   124
  have [simp]: "{x. a \<bullet> x = b} = {x. a \<bullet> x \<le> b} \<inter> {x. a \<bullet> x \<ge> b}"
lp15@62397
   125
    by (force simp:)
lp15@62397
   126
  then show ?thesis
lp15@62397
   127
    by (auto simp: assms)
lp15@62397
   128
qed
lp15@62397
   129
lp15@62397
   130
lemma frontier_halfspace_le:
lp15@62397
   131
  assumes "a \<noteq> 0 \<or> b \<noteq> 0"
lp15@62397
   132
    shows "frontier {x. a \<bullet> x \<le> b} = {x. a \<bullet> x = b}"
lp15@62397
   133
proof (cases "a = 0")
lp15@62397
   134
  case True with assms show ?thesis by simp
lp15@62397
   135
next
lp15@62397
   136
  case False then show ?thesis
lp15@62397
   137
    by (force simp: frontier_def closed_halfspace_le)
lp15@62397
   138
qed
lp15@62397
   139
lp15@62397
   140
lemma frontier_halfspace_ge:
lp15@62397
   141
  assumes "a \<noteq> 0 \<or> b \<noteq> 0"
lp15@62397
   142
    shows "frontier {x. a \<bullet> x \<ge> b} = {x. a \<bullet> x = b}"
lp15@62397
   143
proof (cases "a = 0")
lp15@62397
   144
  case True with assms show ?thesis by simp
lp15@62397
   145
next
lp15@62397
   146
  case False then show ?thesis
lp15@62397
   147
    by (force simp: frontier_def closed_halfspace_ge)
lp15@62397
   148
qed
lp15@62397
   149
lp15@62397
   150
lemma frontier_halfspace_lt:
lp15@62397
   151
  assumes "a \<noteq> 0 \<or> b \<noteq> 0"
lp15@62397
   152
    shows "frontier {x. a \<bullet> x < b} = {x. a \<bullet> x = b}"
lp15@62397
   153
proof (cases "a = 0")
lp15@62397
   154
  case True with assms show ?thesis by simp
lp15@62397
   155
next
lp15@62397
   156
  case False then show ?thesis
lp15@62397
   157
    by (force simp: frontier_def interior_open open_halfspace_lt)
lp15@62397
   158
qed
lp15@62397
   159
lp15@62397
   160
lemma frontier_halfspace_gt:
lp15@62397
   161
  assumes "a \<noteq> 0 \<or> b \<noteq> 0"
lp15@62397
   162
    shows "frontier {x. a \<bullet> x > b} = {x. a \<bullet> x = b}"
lp15@62397
   163
proof (cases "a = 0")
lp15@62397
   164
  case True with assms show ?thesis by simp
lp15@62397
   165
next
lp15@62397
   166
  case False then show ?thesis
lp15@62397
   167
    by (force simp: frontier_def interior_open open_halfspace_gt)
lp15@62397
   168
qed
lp15@62397
   169
lp15@62397
   170
lemma interior_standard_hyperplane:
wenzelm@67731
   171
   "interior {x :: (real^'n). x$k = a} = {}"
lp15@62397
   172
proof -
lp15@62397
   173
  have "axis k (1::real) \<noteq> 0"
lp15@62397
   174
    by (simp add: axis_def vec_eq_iff)
lp15@62397
   175
  moreover have "axis k (1::real) \<bullet> x = x$k" for x
lp15@62397
   176
    by (simp add: cart_eq_inner_axis inner_commute)
lp15@62397
   177
  ultimately show ?thesis
lp15@62397
   178
    using interior_hyperplane [of "axis k (1::real)" a]
lp15@62397
   179
    by force
lp15@62397
   180
qed
lp15@62397
   181
lp15@67673
   182
lemma matrix_mult_transpose_dot_column:
immler@68072
   183
  shows "transpose A ** A = (\<chi> i j. inner (column i A) (column j A))"
lp15@67673
   184
  by (simp add: matrix_matrix_mult_def vec_eq_iff transpose_def column_def inner_vec_def)
lp15@67673
   185
lp15@67673
   186
lemma matrix_mult_transpose_dot_row:
immler@68072
   187
  shows "A ** transpose A = (\<chi> i j. inner (row i A) (row j A))"
lp15@67673
   188
  by (simp add: matrix_matrix_mult_def vec_eq_iff transpose_def row_def inner_vec_def)
lp15@67673
   189
wenzelm@60420
   190
text\<open>Two sometimes fruitful ways of looking at matrix-vector multiplication.\<close>
hoelzl@37489
   191
immler@68072
   192
lemma matrix_mult_dot: "A *v x = (\<chi> i. inner (A$i) x)"
huffman@44136
   193
  by (simp add: matrix_vector_mult_def inner_vec_def)
hoelzl@37489
   194
hoelzl@37489
   195
lemma adjoint_matrix: "adjoint(\<lambda>x. (A::real^'n^'m) *v x) = (\<lambda>x. transpose A *v x)"
hoelzl@37489
   196
  apply (rule adjoint_unique)
wenzelm@49644
   197
  apply (simp add: transpose_def inner_vec_def matrix_vector_mult_def
nipkow@64267
   198
    sum_distrib_right sum_distrib_left)
haftmann@66804
   199
  apply (subst sum.swap)
immler@68072
   200
  apply (simp add:  ac_simps)
hoelzl@37489
   201
  done
hoelzl@37489
   202
hoelzl@37489
   203
lemma matrix_adjoint: assumes lf: "linear (f :: real^'n \<Rightarrow> real ^'m)"
hoelzl@37489
   204
  shows "matrix(adjoint f) = transpose(matrix f)"
immler@68072
   205
proof -
immler@68072
   206
  have "matrix(adjoint f) = matrix(adjoint (( *v) (matrix f)))"
immler@68072
   207
    by (simp add: lf)
immler@68072
   208
  also have "\<dots> = transpose(matrix f)"
immler@68072
   209
    unfolding adjoint_matrix matrix_of_matrix_vector_mul
immler@68072
   210
    apply rule
immler@68072
   211
    done
immler@68072
   212
  finally show ?thesis .
immler@68072
   213
qed
wenzelm@49644
   214
immler@68072
   215
lemma matrix_vector_mul_bounded_linear[intro, simp]: "bounded_linear (( *v) A)" for A :: "real^'n^'m"
immler@68072
   216
  using matrix_vector_mul_linear[of A]
immler@68072
   217
  by (simp add: linear_conv_bounded_linear linear_matrix_vector_mul_eq)
immler@68072
   218
immler@68072
   219
lemma
immler@68073
   220
  fixes A :: "'a::{euclidean_space,real_algebra_1}^'n^'m"
immler@68072
   221
  shows matrix_vector_mult_linear_continuous_at [continuous_intros]: "isCont (( *v) A) z"
immler@68072
   222
    and matrix_vector_mult_linear_continuous_on [continuous_intros]: "continuous_on S (( *v) A)"
immler@68072
   223
  by (simp_all add: linear_continuous_at linear_continuous_on)
lp15@67981
   224
lp15@68038
   225
lemma scalar_invertible:
lp15@68050
   226
  fixes A :: "('a::real_algebra_1)^'m^'n"
lp15@68038
   227
  assumes "k \<noteq> 0" and "invertible A"
lp15@68038
   228
  shows "invertible (k *\<^sub>R A)"
lp15@68038
   229
proof -
lp15@68038
   230
  obtain A' where "A ** A' = mat 1" and "A' ** A = mat 1"
lp15@68038
   231
    using assms unfolding invertible_def by auto
lp15@68038
   232
  with `k \<noteq> 0`
lp15@68038
   233
  have "(k *\<^sub>R A) ** ((1/k) *\<^sub>R A') = mat 1" "((1/k) *\<^sub>R A') ** (k *\<^sub>R A) = mat 1"
lp15@68038
   234
    by (simp_all add: assms matrix_scalar_ac)
lp15@68038
   235
  thus "invertible (k *\<^sub>R A)"
lp15@68038
   236
    unfolding invertible_def by auto
lp15@68038
   237
qed
lp15@68038
   238
lp15@68038
   239
lemma scalar_invertible_iff:
lp15@68050
   240
  fixes A :: "('a::real_algebra_1)^'m^'n"
lp15@68038
   241
  assumes "k \<noteq> 0" and "invertible A"
lp15@68038
   242
  shows "invertible (k *\<^sub>R A) \<longleftrightarrow> k \<noteq> 0 \<and> invertible A"
lp15@68038
   243
  by (simp add: assms scalar_invertible)
lp15@68038
   244
lp15@68038
   245
lemma vector_transpose_matrix [simp]: "x v* transpose A = A *v x"
lp15@68038
   246
  unfolding transpose_def vector_matrix_mult_def matrix_vector_mult_def
lp15@68038
   247
  by simp
lp15@68038
   248
lp15@68038
   249
lemma transpose_matrix_vector [simp]: "transpose A *v x = x v* A"
lp15@68038
   250
  unfolding transpose_def vector_matrix_mult_def matrix_vector_mult_def
lp15@68038
   251
  by simp
lp15@68038
   252
lp15@68043
   253
lemma vector_scalar_commute:
lp15@68043
   254
  fixes A :: "'a::{field}^'m^'n"
lp15@68043
   255
  shows "A *v (c *s x) = c *s (A *v x)"
lp15@68043
   256
  by (simp add: vector_scalar_mult_def matrix_vector_mult_def mult_ac sum_distrib_left)
lp15@68043
   257
lp15@68043
   258
lemma scalar_vector_matrix_assoc:
lp15@68043
   259
  fixes k :: "'a::{field}" and x :: "'a::{field}^'n" and A :: "'a^'m^'n"
lp15@68043
   260
  shows "(k *s x) v* A = k *s (x v* A)"
lp15@68043
   261
  by (metis transpose_matrix_vector vector_scalar_commute)
lp15@68043
   262
 
lp15@68043
   263
lemma vector_matrix_mult_0 [simp]: "0 v* A = 0"
lp15@68043
   264
  unfolding vector_matrix_mult_def by (simp add: zero_vec_def)
lp15@68043
   265
lp15@68043
   266
lemma vector_matrix_mult_0_right [simp]: "x v* 0 = 0"
lp15@68043
   267
  unfolding vector_matrix_mult_def by (simp add: zero_vec_def)
lp15@68043
   268
lp15@68043
   269
lemma vector_matrix_mul_rid [simp]:
lp15@68038
   270
  fixes v :: "('a::semiring_1)^'n"
lp15@68038
   271
  shows "v v* mat 1 = v"
lp15@68038
   272
  by (metis matrix_vector_mul_lid transpose_mat vector_transpose_matrix)
lp15@68038
   273
lp15@68043
   274
lemma scaleR_vector_matrix_assoc:
lp15@68038
   275
  fixes k :: real and x :: "real^'n" and A :: "real^'m^'n"
lp15@68038
   276
  shows "(k *\<^sub>R x) v* A = k *\<^sub>R (x v* A)"
lp15@68038
   277
  by (metis matrix_vector_mult_scaleR transpose_matrix_vector)
lp15@68038
   278
lp15@68043
   279
lemma vector_scaleR_matrix_ac:
lp15@68038
   280
  fixes k :: real and x :: "real^'n" and A :: "real^'m^'n"
lp15@68038
   281
  shows "x v* (k *\<^sub>R A) = k *\<^sub>R (x v* A)"
lp15@68038
   282
proof -
lp15@68038
   283
  have "x v* (k *\<^sub>R A) = (k *\<^sub>R x) v* A"
lp15@68038
   284
    unfolding vector_matrix_mult_def
lp15@68038
   285
    by (simp add: algebra_simps)
lp15@68043
   286
  with scaleR_vector_matrix_assoc
lp15@68038
   287
  show "x v* (k *\<^sub>R A) = k *\<^sub>R (x v* A)"
lp15@68038
   288
    by auto
lp15@68038
   289
qed
lp15@68038
   290
hoelzl@37489
   291
nipkow@67968
   292
subsection\<open>Some bounds on components etc. relative to operator norm\<close>
lp15@67719
   293
lp15@67719
   294
lemma norm_column_le_onorm:
lp15@67719
   295
  fixes A :: "real^'n^'m"
lp15@67719
   296
  shows "norm(column i A) \<le> onorm(( *v) A)"
lp15@67719
   297
proof -
lp15@67719
   298
  have "norm (\<chi> j. A $ j $ i) \<le> norm (A *v axis i 1)"
lp15@67719
   299
    by (simp add: matrix_mult_dot cart_eq_inner_axis)
lp15@67719
   300
  also have "\<dots> \<le> onorm (( *v) A)"
immler@68072
   301
    using onorm [OF matrix_vector_mul_bounded_linear, of A "axis i 1"] by auto
lp15@67719
   302
  finally have "norm (\<chi> j. A $ j $ i) \<le> onorm (( *v) A)" .
lp15@67719
   303
  then show ?thesis
lp15@67719
   304
    unfolding column_def .
lp15@67719
   305
qed
lp15@67719
   306
lp15@67719
   307
lemma matrix_component_le_onorm:
lp15@67719
   308
  fixes A :: "real^'n^'m"
lp15@67719
   309
  shows "\<bar>A $ i $ j\<bar> \<le> onorm(( *v) A)"
lp15@67719
   310
proof -
lp15@67719
   311
  have "\<bar>A $ i $ j\<bar> \<le> norm (\<chi> n. (A $ n $ j))"
lp15@67719
   312
    by (metis (full_types, lifting) component_le_norm_cart vec_lambda_beta)
lp15@67719
   313
  also have "\<dots> \<le> onorm (( *v) A)"
lp15@67719
   314
    by (metis (no_types) column_def norm_column_le_onorm)
lp15@67719
   315
  finally show ?thesis .
lp15@67719
   316
qed
lp15@67719
   317
lp15@67719
   318
lemma component_le_onorm:
lp15@67719
   319
  fixes f :: "real^'m \<Rightarrow> real^'n"
lp15@67719
   320
  shows "linear f \<Longrightarrow> \<bar>matrix f $ i $ j\<bar> \<le> onorm f"
immler@68072
   321
  by (metis linear_matrix_vector_mul_eq matrix_component_le_onorm matrix_vector_mul)
hoelzl@37489
   322
lp15@67719
   323
lemma onorm_le_matrix_component_sum:
lp15@67719
   324
  fixes A :: "real^'n^'m"
lp15@67719
   325
  shows "onorm(( *v) A) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar>)"
lp15@67719
   326
proof (rule onorm_le)
lp15@67719
   327
  fix x
lp15@67719
   328
  have "norm (A *v x) \<le> (\<Sum>i\<in>UNIV. \<bar>(A *v x) $ i\<bar>)"
lp15@67719
   329
    by (rule norm_le_l1_cart)
lp15@67719
   330
  also have "\<dots> \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar> * norm x)"
lp15@67719
   331
  proof (rule sum_mono)
lp15@67719
   332
    fix i
lp15@67719
   333
    have "\<bar>(A *v x) $ i\<bar> \<le> \<bar>\<Sum>j\<in>UNIV. A $ i $ j * x $ j\<bar>"
lp15@67719
   334
      by (simp add: matrix_vector_mult_def)
lp15@67719
   335
    also have "\<dots> \<le> (\<Sum>j\<in>UNIV. \<bar>A $ i $ j * x $ j\<bar>)"
lp15@67719
   336
      by (rule sum_abs)
lp15@67719
   337
    also have "\<dots> \<le> (\<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar> * norm x)"
lp15@67719
   338
      by (rule sum_mono) (simp add: abs_mult component_le_norm_cart mult_left_mono)
lp15@67719
   339
    finally show "\<bar>(A *v x) $ i\<bar> \<le> (\<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar> * norm x)" .
lp15@67719
   340
  qed
lp15@67719
   341
  finally show "norm (A *v x) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar>) * norm x"
lp15@67719
   342
    by (simp add: sum_distrib_right)
lp15@67719
   343
qed
lp15@67719
   344
lp15@67719
   345
lemma onorm_le_matrix_component:
lp15@67719
   346
  fixes A :: "real^'n^'m"
lp15@67719
   347
  assumes "\<And>i j. abs(A$i$j) \<le> B"
lp15@67719
   348
  shows "onorm(( *v) A) \<le> real (CARD('m)) * real (CARD('n)) * B"
lp15@67719
   349
proof (rule onorm_le)
wenzelm@67731
   350
  fix x :: "real^'n::_"
lp15@67719
   351
  have "norm (A *v x) \<le> (\<Sum>i\<in>UNIV. \<bar>(A *v x) $ i\<bar>)"
lp15@67719
   352
    by (rule norm_le_l1_cart)
lp15@67719
   353
  also have "\<dots> \<le> (\<Sum>i::'m \<in>UNIV. real (CARD('n)) * B * norm x)"
lp15@67719
   354
  proof (rule sum_mono)
lp15@67719
   355
    fix i
lp15@67719
   356
    have "\<bar>(A *v x) $ i\<bar> \<le> norm(A $ i) * norm x"
lp15@67719
   357
      by (simp add: matrix_mult_dot Cauchy_Schwarz_ineq2)
lp15@67719
   358
    also have "\<dots> \<le> (\<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar>) * norm x"
lp15@67719
   359
      by (simp add: mult_right_mono norm_le_l1_cart)
lp15@67719
   360
    also have "\<dots> \<le> real (CARD('n)) * B * norm x"
lp15@67719
   361
      by (simp add: assms sum_bounded_above mult_right_mono)
lp15@67719
   362
    finally show "\<bar>(A *v x) $ i\<bar> \<le> real (CARD('n)) * B * norm x" .
lp15@67719
   363
  qed
lp15@67719
   364
  also have "\<dots> \<le> CARD('m) * real (CARD('n)) * B * norm x"
lp15@67719
   365
    by simp
lp15@67719
   366
  finally show "norm (A *v x) \<le> CARD('m) * real (CARD('n)) * B * norm x" .
lp15@67719
   367
qed
lp15@67719
   368
lp15@67719
   369
subsection \<open>lambda skolemization on cartesian products\<close>
hoelzl@37489
   370
hoelzl@37489
   371
lemma lambda_skolem: "(\<forall>i. \<exists>x. P i x) \<longleftrightarrow>
hoelzl@37494
   372
   (\<exists>x::'a ^ 'n. \<forall>i. P i (x $ i))" (is "?lhs \<longleftrightarrow> ?rhs")
wenzelm@49644
   373
proof -
hoelzl@37489
   374
  let ?S = "(UNIV :: 'n set)"
wenzelm@49644
   375
  { assume H: "?rhs"
wenzelm@49644
   376
    then have ?lhs by auto }
hoelzl@37489
   377
  moreover
wenzelm@49644
   378
  { assume H: "?lhs"
hoelzl@37489
   379
    then obtain f where f:"\<forall>i. P i (f i)" unfolding choice_iff by metis
hoelzl@37489
   380
    let ?x = "(\<chi> i. (f i)) :: 'a ^ 'n"
wenzelm@49644
   381
    { fix i
hoelzl@37489
   382
      from f have "P i (f i)" by metis
hoelzl@37494
   383
      then have "P i (?x $ i)" by auto
hoelzl@37489
   384
    }
hoelzl@37489
   385
    hence "\<forall>i. P i (?x$i)" by metis
hoelzl@37489
   386
    hence ?rhs by metis }
hoelzl@37489
   387
  ultimately show ?thesis by metis
hoelzl@37489
   388
qed
hoelzl@37489
   389
lp15@67719
   390
lemma rational_approximation:
lp15@67719
   391
  assumes "e > 0"
lp15@67719
   392
  obtains r::real where "r \<in> \<rat>" "\<bar>r - x\<bar> < e"
lp15@67719
   393
  using Rats_dense_in_real [of "x - e/2" "x + e/2"] assms by auto
lp15@67719
   394
lp15@67719
   395
lemma matrix_rational_approximation:
lp15@67719
   396
  fixes A :: "real^'n^'m"
lp15@67719
   397
  assumes "e > 0"
lp15@67719
   398
  obtains B where "\<And>i j. B$i$j \<in> \<rat>" "onorm(\<lambda>x. (A - B) *v x) < e"
lp15@67719
   399
proof -
lp15@67719
   400
  have "\<forall>i j. \<exists>q \<in> \<rat>. \<bar>q - A $ i $ j\<bar> < e / (2 * CARD('m) * CARD('n))"
lp15@67719
   401
    using assms by (force intro: rational_approximation [of "e / (2 * CARD('m) * CARD('n))"])
lp15@67719
   402
  then obtain B where B: "\<And>i j. B$i$j \<in> \<rat>" and Bclo: "\<And>i j. \<bar>B$i$j - A $ i $ j\<bar> < e / (2 * CARD('m) * CARD('n))"
lp15@67719
   403
    by (auto simp: lambda_skolem Bex_def)
lp15@67719
   404
  show ?thesis
lp15@67719
   405
  proof
lp15@67719
   406
    have "onorm (( *v) (A - B)) \<le> real CARD('m) * real CARD('n) *
lp15@67719
   407
    (e / (2 * real CARD('m) * real CARD('n)))"
lp15@67719
   408
      apply (rule onorm_le_matrix_component)
lp15@67719
   409
      using Bclo by (simp add: abs_minus_commute less_imp_le)
lp15@67719
   410
    also have "\<dots> < e"
lp15@67719
   411
      using \<open>0 < e\<close> by (simp add: divide_simps)
lp15@67719
   412
    finally show "onorm (( *v) (A - B)) < e" .
lp15@67719
   413
  qed (use B in auto)
lp15@67719
   414
qed
lp15@67719
   415
hoelzl@37489
   416
lemma vector_sub_project_orthogonal_cart: "(b::real^'n) \<bullet> (x - ((b \<bullet> x) / (b \<bullet> b)) *s b) = 0"
hoelzl@50526
   417
  unfolding inner_simps scalar_mult_eq_scaleR by auto
hoelzl@37489
   418
hoelzl@37489
   419
lemma matrix_left_invertible_injective:
immler@68072
   420
  fixes A :: "'a::field^'n^'m"
lp15@67986
   421
  shows "(\<exists>B. B ** A = mat 1) \<longleftrightarrow> inj (( *v) A)"
lp15@67986
   422
proof safe
lp15@67986
   423
  fix B
lp15@67986
   424
  assume B: "B ** A = mat 1"
lp15@67986
   425
  show "inj (( *v) A)"
lp15@67986
   426
    unfolding inj_on_def
lp15@67986
   427
      by (metis B matrix_vector_mul_assoc matrix_vector_mul_lid)
lp15@67986
   428
next
lp15@67986
   429
  assume "inj (( *v) A)"
immler@68072
   430
  from vec.linear_injective_left_inverse[OF matrix_vector_mul_linear_gen this]
immler@68072
   431
  obtain g where "Vector_Spaces.linear ( *s) ( *s) g" and g: "g \<circ> ( *v) A = id"
lp15@67986
   432
    by blast
lp15@67986
   433
  have "matrix g ** A = mat 1"
immler@68072
   434
    by (metis matrix_vector_mul_linear_gen \<open>Vector_Spaces.linear ( *s) ( *s) g\<close> g matrix_compose_gen
immler@68072
   435
        matrix_eq matrix_id_mat_1 matrix_vector_mul(1))
lp15@67986
   436
  then show "\<exists>B. B ** A = mat 1"
lp15@67986
   437
    by metis
hoelzl@37489
   438
qed
hoelzl@37489
   439
hoelzl@37489
   440
lemma matrix_right_invertible_surjective:
immler@68072
   441
  "(\<exists>B. (A::'a::field^'n^'m) ** (B::'a::field^'m^'n) = mat 1) \<longleftrightarrow> surj (\<lambda>x. A *v x)"
wenzelm@49644
   442
proof -
immler@68072
   443
  { fix B :: "'a ^'m^'n"
wenzelm@49644
   444
    assume AB: "A ** B = mat 1"
immler@68072
   445
    { fix x :: "'a ^ 'm"
hoelzl@37489
   446
      have "A *v (B *v x) = x"
immler@68072
   447
        by (simp add: matrix_vector_mul_assoc AB) }
nipkow@67399
   448
    hence "surj (( *v) A)" unfolding surj_def by metis }
hoelzl@37489
   449
  moreover
nipkow@67399
   450
  { assume sf: "surj (( *v) A)"
immler@68072
   451
    from vec.linear_surjective_right_inverse[OF _ this]
immler@68072
   452
    obtain g:: "'a ^'m \<Rightarrow> 'a ^'n" where g: "Vector_Spaces.linear ( *s) ( *s) g" "( *v) A \<circ> g = id"
hoelzl@37489
   453
      by blast
hoelzl@37489
   454
hoelzl@37489
   455
    have "A ** (matrix g) = mat 1"
hoelzl@37489
   456
      unfolding matrix_eq  matrix_vector_mul_lid
hoelzl@37489
   457
        matrix_vector_mul_assoc[symmetric] matrix_works[OF g(1)]
huffman@44165
   458
      using g(2) unfolding o_def fun_eq_iff id_def
hoelzl@37489
   459
      .
immler@68072
   460
    hence "\<exists>B. A ** (B::'a^'m^'n) = mat 1" by blast
hoelzl@37489
   461
  }
hoelzl@37489
   462
  ultimately show ?thesis unfolding surj_def by blast
hoelzl@37489
   463
qed
hoelzl@37489
   464
hoelzl@37489
   465
lemma matrix_right_invertible_span_columns:
immler@68072
   466
  "(\<exists>(B::'a::field ^'n^'m). (A::'a ^'m^'n) ** B = mat 1) \<longleftrightarrow>
immler@68072
   467
    vec.span (columns A) = UNIV" (is "?lhs = ?rhs")
wenzelm@49644
   468
proof -
hoelzl@37489
   469
  let ?U = "UNIV :: 'm set"
hoelzl@37489
   470
  have fU: "finite ?U" by simp
immler@68072
   471
  have lhseq: "?lhs \<longleftrightarrow> (\<forall>y. \<exists>(x::'a^'m). sum (\<lambda>i. (x$i) *s column i A) ?U = y)"
lp15@67673
   472
    unfolding matrix_right_invertible_surjective matrix_mult_sum surj_def
lp15@68041
   473
    by (simp add: eq_commute)
immler@68072
   474
  have rhseq: "?rhs \<longleftrightarrow> (\<forall>x. x \<in> vec.span (columns A))" by blast
wenzelm@49644
   475
  { assume h: ?lhs
immler@68072
   476
    { fix x:: "'a ^'n"
immler@68072
   477
      from h[unfolded lhseq, rule_format, of x] obtain y :: "'a ^'m"
nipkow@64267
   478
        where y: "sum (\<lambda>i. (y$i) *s column i A) ?U = x" by blast
immler@68072
   479
      have "x \<in> vec.span (columns A)"
lp15@68041
   480
        unfolding y[symmetric] scalar_mult_eq_scaleR
lp15@68041
   481
      proof (rule span_sum [OF span_mul])
lp15@68041
   482
        show "column i A \<in> span (columns A)" for i
lp15@68041
   483
          using columns_def span_inc by auto
lp15@68041
   484
      qed
wenzelm@49644
   485
    }
wenzelm@49644
   486
    then have ?rhs unfolding rhseq by blast }
hoelzl@37489
   487
  moreover
wenzelm@49644
   488
  { assume h:?rhs
immler@68072
   489
    let ?P = "\<lambda>(y::'a ^'n). \<exists>(x::'a^'m). sum (\<lambda>i. (x$i) *s column i A) ?U = y"
wenzelm@49644
   490
    { fix y
immler@68072
   491
      have "y \<in> vec.span (columns A)"
immler@68072
   492
        unfolding h by blast
lp15@68069
   493
      then have "?P y"
immler@68072
   494
      proof (induction rule: vec.span_induct_alt)
lp15@68069
   495
        case base
lp15@68069
   496
        then show ?case
lp15@68069
   497
          by (metis (full_types) matrix_mult_sum matrix_vector_mult_0_right)
hoelzl@37489
   498
      next
lp15@68069
   499
        case (step c y1 y2)
lp15@68069
   500
        then obtain i where i: "i \<in> ?U" "y1 = column i A"
hoelzl@37489
   501
        from y1 obtain i where i: "i \<in> ?U" "y1 = column i A"
hoelzl@37489
   502
          unfolding columns_def by blast
lp15@68069
   503
        obtain x:: "real ^'m" where x: "sum (\<lambda>i. (x$i) *s column i A) ?U = y2"
lp15@68069
   504
          using step by blast
immler@68072
   505
        let ?x = "(\<chi> j. if j = i then c + (x$i) else (x$j))::'a^'m"
lp15@68069
   506
        show ?case
immler@68072
   507
        proof (rule exI[where x= "?x"], vector, auto simp add: i x[symmetric] if_distrib distrib_left if_distribR cong del: if_weak_cong)
wenzelm@49644
   508
          fix j
wenzelm@49644
   509
          have th: "\<forall>xa \<in> ?U. (if xa = i then (c + (x$i)) * ((column xa A)$j)
wenzelm@49644
   510
              else (x$xa) * ((column xa A$j))) = (if xa = i then c * ((column i A)$j) else 0) + ((x$xa) * ((column xa A)$j))"
wenzelm@49644
   511
            using i(1) by (simp add: field_simps)
nipkow@64267
   512
          have "sum (\<lambda>xa. if xa = i then (c + (x$i)) * ((column xa A)$j)
nipkow@64267
   513
              else (x$xa) * ((column xa A$j))) ?U = sum (\<lambda>xa. (if xa = i then c * ((column i A)$j) else 0) + ((x$xa) * ((column xa A)$j))) ?U"
lp15@68041
   514
            by (rule sum.cong[OF refl]) (use th in blast)
nipkow@64267
   515
          also have "\<dots> = sum (\<lambda>xa. if xa = i then c * ((column i A)$j) else 0) ?U + sum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U"
nipkow@64267
   516
            by (simp add: sum.distrib)
nipkow@64267
   517
          also have "\<dots> = c * ((column i A)$j) + sum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U"
nipkow@64267
   518
            unfolding sum.delta[OF fU]
wenzelm@49644
   519
            using i(1) by simp
nipkow@64267
   520
          finally show "sum (\<lambda>xa. if xa = i then (c + (x$i)) * ((column xa A)$j)
nipkow@64267
   521
            else (x$xa) * ((column xa A$j))) ?U = c * ((column i A)$j) + sum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U" .
wenzelm@49644
   522
        qed
wenzelm@49644
   523
      qed
wenzelm@49644
   524
    }
wenzelm@49644
   525
    then have ?lhs unfolding lhseq ..
wenzelm@49644
   526
  }
hoelzl@37489
   527
  ultimately show ?thesis by blast
hoelzl@37489
   528
qed
hoelzl@37489
   529
immler@68072
   530
lemma matrix_left_invertible_span_rows_gen:
immler@68072
   531
  "(\<exists>(B::'a^'m^'n). B ** (A::'a::field^'n^'m) = mat 1) \<longleftrightarrow> vec.span (rows A) = UNIV"
hoelzl@37489
   532
  unfolding right_invertible_transpose[symmetric]
hoelzl@37489
   533
  unfolding columns_transpose[symmetric]
hoelzl@37489
   534
  unfolding matrix_right_invertible_span_columns
wenzelm@49644
   535
  ..
hoelzl@37489
   536
immler@68072
   537
lemma matrix_left_invertible_span_rows:
immler@68072
   538
  "(\<exists>(B::real^'m^'n). B ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> span (rows A) = UNIV"
immler@68072
   539
  using matrix_left_invertible_span_rows_gen[of A] by (simp add: span_vec_eq)
immler@68072
   540
immler@68072
   541
wenzelm@60420
   542
text \<open>The same result in terms of square matrices.\<close>
hoelzl@37489
   543
lp15@68041
   544
wenzelm@60420
   545
text \<open>Considering an n-element vector as an n-by-1 or 1-by-n matrix.\<close>
hoelzl@37489
   546
hoelzl@37489
   547
definition "rowvector v = (\<chi> i j. (v$j))"
hoelzl@37489
   548
hoelzl@37489
   549
definition "columnvector v = (\<chi> i j. (v$i))"
hoelzl@37489
   550
wenzelm@49644
   551
lemma transpose_columnvector: "transpose(columnvector v) = rowvector v"
huffman@44136
   552
  by (simp add: transpose_def rowvector_def columnvector_def vec_eq_iff)
hoelzl@37489
   553
hoelzl@37489
   554
lemma transpose_rowvector: "transpose(rowvector v) = columnvector v"
huffman@44136
   555
  by (simp add: transpose_def columnvector_def rowvector_def vec_eq_iff)
hoelzl@37489
   556
wenzelm@49644
   557
lemma dot_rowvector_columnvector: "columnvector (A *v v) = A ** columnvector v"
hoelzl@37489
   558
  by (vector columnvector_def matrix_matrix_mult_def matrix_vector_mult_def)
hoelzl@37489
   559
wenzelm@49644
   560
lemma dot_matrix_product:
wenzelm@49644
   561
  "(x::real^'n) \<bullet> y = (((rowvector x ::real^'n^1) ** (columnvector y :: real^1^'n))$1)$1"
huffman@44136
   562
  by (vector matrix_matrix_mult_def rowvector_def columnvector_def inner_vec_def)
hoelzl@37489
   563
hoelzl@37489
   564
lemma dot_matrix_vector_mul:
hoelzl@37489
   565
  fixes A B :: "real ^'n ^'n" and x y :: "real ^'n"
hoelzl@37489
   566
  shows "(A *v x) \<bullet> (B *v y) =
hoelzl@37489
   567
      (((rowvector x :: real^'n^1) ** ((transpose A ** B) ** (columnvector y :: real ^1^'n)))$1)$1"
wenzelm@49644
   568
  unfolding dot_matrix_product transpose_columnvector[symmetric]
wenzelm@49644
   569
    dot_rowvector_columnvector matrix_transpose_mul matrix_mul_assoc ..
hoelzl@37489
   570
wenzelm@61945
   571
lemma infnorm_cart:"infnorm (x::real^'n) = Sup {\<bar>x$i\<bar> |i. i\<in>UNIV}"
hoelzl@50526
   572
  by (simp add: infnorm_def inner_axis Basis_vec_def) (metis (lifting) inner_axis real_inner_1_right)
hoelzl@37489
   573
wenzelm@49644
   574
lemma component_le_infnorm_cart: "\<bar>x$i\<bar> \<le> infnorm (x::real^'n)"
hoelzl@50526
   575
  using Basis_le_infnorm[of "axis i 1" x]
hoelzl@50526
   576
  by (simp add: Basis_vec_def axis_eq_axis inner_axis)
hoelzl@37489
   577
hoelzl@63334
   578
lemma continuous_component[continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. f x $ i)"
huffman@44647
   579
  unfolding continuous_def by (rule tendsto_vec_nth)
huffman@44213
   580
hoelzl@63334
   581
lemma continuous_on_component[continuous_intros]: "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. f x $ i)"
huffman@44647
   582
  unfolding continuous_on_def by (fast intro: tendsto_vec_nth)
huffman@44213
   583
hoelzl@63334
   584
lemma continuous_on_vec_lambda[continuous_intros]:
hoelzl@63334
   585
  "(\<And>i. continuous_on S (f i)) \<Longrightarrow> continuous_on S (\<lambda>x. \<chi> i. f i x)"
hoelzl@63334
   586
  unfolding continuous_on_def by (auto intro: tendsto_vec_lambda)
hoelzl@63334
   587
hoelzl@37489
   588
lemma closed_positive_orthant: "closed {x::real^'n. \<forall>i. 0 \<le>x$i}"
hoelzl@63332
   589
  by (simp add: Collect_all_eq closed_INT closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
huffman@44213
   590
hoelzl@37489
   591
lemma bounded_component_cart: "bounded s \<Longrightarrow> bounded ((\<lambda>x. x $ i) ` s)"
wenzelm@49644
   592
  unfolding bounded_def
wenzelm@49644
   593
  apply clarify
wenzelm@49644
   594
  apply (rule_tac x="x $ i" in exI)
wenzelm@49644
   595
  apply (rule_tac x="e" in exI)
wenzelm@49644
   596
  apply clarify
wenzelm@49644
   597
  apply (rule order_trans [OF dist_vec_nth_le], simp)
wenzelm@49644
   598
  done
hoelzl@37489
   599
hoelzl@37489
   600
lemma compact_lemma_cart:
hoelzl@37489
   601
  fixes f :: "nat \<Rightarrow> 'a::heine_borel ^ 'n"
hoelzl@50998
   602
  assumes f: "bounded (range f)"
eberlm@66447
   603
  shows "\<exists>l r. strict_mono r \<and>
hoelzl@37489
   604
        (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) $ i) (l $ i) < e) sequentially)"
immler@62127
   605
    (is "?th d")
immler@62127
   606
proof -
immler@62127
   607
  have "\<forall>d' \<subseteq> d. ?th d'"
immler@62127
   608
    by (rule compact_lemma_general[where unproj=vec_lambda])
immler@62127
   609
      (auto intro!: f bounded_component_cart simp: vec_lambda_eta)
immler@62127
   610
  then show "?th d" by simp
hoelzl@37489
   611
qed
hoelzl@37489
   612
huffman@44136
   613
instance vec :: (heine_borel, finite) heine_borel
hoelzl@37489
   614
proof
hoelzl@50998
   615
  fix f :: "nat \<Rightarrow> 'a ^ 'b"
hoelzl@50998
   616
  assume f: "bounded (range f)"
eberlm@66447
   617
  then obtain l r where r: "strict_mono r"
wenzelm@49644
   618
      and l: "\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>UNIV. dist (f (r n) $ i) (l $ i) < e) sequentially"
hoelzl@50998
   619
    using compact_lemma_cart [OF f] by blast
hoelzl@37489
   620
  let ?d = "UNIV::'b set"
hoelzl@37489
   621
  { fix e::real assume "e>0"
hoelzl@37489
   622
    hence "0 < e / (real_of_nat (card ?d))"
wenzelm@49644
   623
      using zero_less_card_finite divide_pos_pos[of e, of "real_of_nat (card ?d)"] by auto
hoelzl@37489
   624
    with l have "eventually (\<lambda>n. \<forall>i. dist (f (r n) $ i) (l $ i) < e / (real_of_nat (card ?d))) sequentially"
hoelzl@37489
   625
      by simp
hoelzl@37489
   626
    moreover
wenzelm@49644
   627
    { fix n
wenzelm@49644
   628
      assume n: "\<forall>i. dist (f (r n) $ i) (l $ i) < e / (real_of_nat (card ?d))"
hoelzl@37489
   629
      have "dist (f (r n)) l \<le> (\<Sum>i\<in>?d. dist (f (r n) $ i) (l $ i))"
nipkow@67155
   630
        unfolding dist_vec_def using zero_le_dist by (rule L2_set_le_sum)
hoelzl@37489
   631
      also have "\<dots> < (\<Sum>i\<in>?d. e / (real_of_nat (card ?d)))"
nipkow@64267
   632
        by (rule sum_strict_mono) (simp_all add: n)
hoelzl@37489
   633
      finally have "dist (f (r n)) l < e" by simp
hoelzl@37489
   634
    }
hoelzl@37489
   635
    ultimately have "eventually (\<lambda>n. dist (f (r n)) l < e) sequentially"
lp15@61810
   636
      by (rule eventually_mono)
hoelzl@37489
   637
  }
wenzelm@61973
   638
  hence "((f \<circ> r) \<longlongrightarrow> l) sequentially" unfolding o_def tendsto_iff by simp
eberlm@66447
   639
  with r show "\<exists>l r. strict_mono r \<and> ((f \<circ> r) \<longlongrightarrow> l) sequentially" by auto
hoelzl@37489
   640
qed
hoelzl@37489
   641
wenzelm@49644
   642
lemma interval_cart:
immler@54775
   643
  fixes a :: "real^'n"
immler@54775
   644
  shows "box a b = {x::real^'n. \<forall>i. a$i < x$i \<and> x$i < b$i}"
immler@56188
   645
    and "cbox a b = {x::real^'n. \<forall>i. a$i \<le> x$i \<and> x$i \<le> b$i}"
immler@56188
   646
  by (auto simp add: set_eq_iff less_vec_def less_eq_vec_def mem_box Basis_vec_def inner_axis)
hoelzl@37489
   647
lp15@67673
   648
lemma mem_box_cart:
immler@54775
   649
  fixes a :: "real^'n"
immler@54775
   650
  shows "x \<in> box a b \<longleftrightarrow> (\<forall>i. a$i < x$i \<and> x$i < b$i)"
immler@56188
   651
    and "x \<in> cbox a b \<longleftrightarrow> (\<forall>i. a$i \<le> x$i \<and> x$i \<le> b$i)"
wenzelm@49644
   652
  using interval_cart[of a b] by (auto simp add: set_eq_iff less_vec_def less_eq_vec_def)
hoelzl@37489
   653
wenzelm@49644
   654
lemma interval_eq_empty_cart:
wenzelm@49644
   655
  fixes a :: "real^'n"
immler@54775
   656
  shows "(box a b = {} \<longleftrightarrow> (\<exists>i. b$i \<le> a$i))" (is ?th1)
immler@56188
   657
    and "(cbox a b = {} \<longleftrightarrow> (\<exists>i. b$i < a$i))" (is ?th2)
wenzelm@49644
   658
proof -
immler@54775
   659
  { fix i x assume as:"b$i \<le> a$i" and x:"x\<in>box a b"
lp15@67673
   660
    hence "a $ i < x $ i \<and> x $ i < b $ i" unfolding mem_box_cart by auto
hoelzl@37489
   661
    hence "a$i < b$i" by auto
wenzelm@49644
   662
    hence False using as by auto }
hoelzl@37489
   663
  moreover
hoelzl@37489
   664
  { assume as:"\<forall>i. \<not> (b$i \<le> a$i)"
hoelzl@37489
   665
    let ?x = "(1/2) *\<^sub>R (a + b)"
hoelzl@37489
   666
    { fix i
hoelzl@37489
   667
      have "a$i < b$i" using as[THEN spec[where x=i]] by auto
hoelzl@37489
   668
      hence "a$i < ((1/2) *\<^sub>R (a+b)) $ i" "((1/2) *\<^sub>R (a+b)) $ i < b$i"
hoelzl@37489
   669
        unfolding vector_smult_component and vector_add_component
wenzelm@49644
   670
        by auto }
lp15@67673
   671
    hence "box a b \<noteq> {}" using mem_box_cart(1)[of "?x" a b] by auto }
hoelzl@37489
   672
  ultimately show ?th1 by blast
hoelzl@37489
   673
immler@56188
   674
  { fix i x assume as:"b$i < a$i" and x:"x\<in>cbox a b"
lp15@67673
   675
    hence "a $ i \<le> x $ i \<and> x $ i \<le> b $ i" unfolding mem_box_cart by auto
hoelzl@37489
   676
    hence "a$i \<le> b$i" by auto
wenzelm@49644
   677
    hence False using as by auto }
hoelzl@37489
   678
  moreover
hoelzl@37489
   679
  { assume as:"\<forall>i. \<not> (b$i < a$i)"
hoelzl@37489
   680
    let ?x = "(1/2) *\<^sub>R (a + b)"
hoelzl@37489
   681
    { fix i
hoelzl@37489
   682
      have "a$i \<le> b$i" using as[THEN spec[where x=i]] by auto
hoelzl@37489
   683
      hence "a$i \<le> ((1/2) *\<^sub>R (a+b)) $ i" "((1/2) *\<^sub>R (a+b)) $ i \<le> b$i"
hoelzl@37489
   684
        unfolding vector_smult_component and vector_add_component
wenzelm@49644
   685
        by auto }
lp15@67673
   686
    hence "cbox a b \<noteq> {}" using mem_box_cart(2)[of "?x" a b] by auto  }
hoelzl@37489
   687
  ultimately show ?th2 by blast
hoelzl@37489
   688
qed
hoelzl@37489
   689
wenzelm@49644
   690
lemma interval_ne_empty_cart:
wenzelm@49644
   691
  fixes a :: "real^'n"
immler@56188
   692
  shows "cbox a b \<noteq> {} \<longleftrightarrow> (\<forall>i. a$i \<le> b$i)"
immler@54775
   693
    and "box a b \<noteq> {} \<longleftrightarrow> (\<forall>i. a$i < b$i)"
hoelzl@37489
   694
  unfolding interval_eq_empty_cart[of a b] by (auto simp add: not_less not_le)
hoelzl@37489
   695
    (* BH: Why doesn't just "auto" work here? *)
hoelzl@37489
   696
wenzelm@49644
   697
lemma subset_interval_imp_cart:
wenzelm@49644
   698
  fixes a :: "real^'n"
immler@56188
   699
  shows "(\<forall>i. a$i \<le> c$i \<and> d$i \<le> b$i) \<Longrightarrow> cbox c d \<subseteq> cbox a b"
immler@56188
   700
    and "(\<forall>i. a$i < c$i \<and> d$i < b$i) \<Longrightarrow> cbox c d \<subseteq> box a b"
immler@56188
   701
    and "(\<forall>i. a$i \<le> c$i \<and> d$i \<le> b$i) \<Longrightarrow> box c d \<subseteq> cbox a b"
immler@54775
   702
    and "(\<forall>i. a$i \<le> c$i \<and> d$i \<le> b$i) \<Longrightarrow> box c d \<subseteq> box a b"
lp15@67673
   703
  unfolding subset_eq[unfolded Ball_def] unfolding mem_box_cart
hoelzl@37489
   704
  by (auto intro: order_trans less_le_trans le_less_trans less_imp_le) (* BH: Why doesn't just "auto" work here? *)
hoelzl@37489
   705
wenzelm@49644
   706
lemma interval_sing:
wenzelm@49644
   707
  fixes a :: "'a::linorder^'n"
wenzelm@49644
   708
  shows "{a .. a} = {a} \<and> {a<..<a} = {}"
wenzelm@49644
   709
  apply (auto simp add: set_eq_iff less_vec_def less_eq_vec_def vec_eq_iff)
wenzelm@49644
   710
  done
hoelzl@37489
   711
wenzelm@49644
   712
lemma subset_interval_cart:
wenzelm@49644
   713
  fixes a :: "real^'n"
immler@56188
   714
  shows "cbox c d \<subseteq> cbox a b \<longleftrightarrow> (\<forall>i. c$i \<le> d$i) --> (\<forall>i. a$i \<le> c$i \<and> d$i \<le> b$i)" (is ?th1)
immler@56188
   715
    and "cbox c d \<subseteq> box a b \<longleftrightarrow> (\<forall>i. c$i \<le> d$i) --> (\<forall>i. a$i < c$i \<and> d$i < b$i)" (is ?th2)
immler@56188
   716
    and "box c d \<subseteq> cbox a b \<longleftrightarrow> (\<forall>i. c$i < d$i) --> (\<forall>i. a$i \<le> c$i \<and> d$i \<le> b$i)" (is ?th3)
immler@54775
   717
    and "box c d \<subseteq> box a b \<longleftrightarrow> (\<forall>i. c$i < d$i) --> (\<forall>i. a$i \<le> c$i \<and> d$i \<le> b$i)" (is ?th4)
immler@56188
   718
  using subset_box[of c d a b] by (simp_all add: Basis_vec_def inner_axis)
hoelzl@37489
   719
wenzelm@49644
   720
lemma disjoint_interval_cart:
wenzelm@49644
   721
  fixes a::"real^'n"
immler@56188
   722
  shows "cbox a b \<inter> cbox c d = {} \<longleftrightarrow> (\<exists>i. (b$i < a$i \<or> d$i < c$i \<or> b$i < c$i \<or> d$i < a$i))" (is ?th1)
immler@56188
   723
    and "cbox a b \<inter> box c d = {} \<longleftrightarrow> (\<exists>i. (b$i < a$i \<or> d$i \<le> c$i \<or> b$i \<le> c$i \<or> d$i \<le> a$i))" (is ?th2)
immler@56188
   724
    and "box a b \<inter> cbox c d = {} \<longleftrightarrow> (\<exists>i. (b$i \<le> a$i \<or> d$i < c$i \<or> b$i \<le> c$i \<or> d$i \<le> a$i))" (is ?th3)
immler@54775
   725
    and "box a b \<inter> box c d = {} \<longleftrightarrow> (\<exists>i. (b$i \<le> a$i \<or> d$i \<le> c$i \<or> b$i \<le> c$i \<or> d$i \<le> a$i))" (is ?th4)
hoelzl@50526
   726
  using disjoint_interval[of a b c d] by (simp_all add: Basis_vec_def inner_axis)
hoelzl@37489
   727
lp15@67719
   728
lemma Int_interval_cart:
immler@54775
   729
  fixes a :: "real^'n"
immler@56188
   730
  shows "cbox a b \<inter> cbox c d =  {(\<chi> i. max (a$i) (c$i)) .. (\<chi> i. min (b$i) (d$i))}"
lp15@63945
   731
  unfolding Int_interval
immler@56188
   732
  by (auto simp: mem_box less_eq_vec_def)
immler@56188
   733
    (auto simp: Basis_vec_def inner_axis)
hoelzl@37489
   734
wenzelm@49644
   735
lemma closed_interval_left_cart:
wenzelm@49644
   736
  fixes b :: "real^'n"
hoelzl@37489
   737
  shows "closed {x::real^'n. \<forall>i. x$i \<le> b$i}"
hoelzl@63332
   738
  by (simp add: Collect_all_eq closed_INT closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   739
wenzelm@49644
   740
lemma closed_interval_right_cart:
wenzelm@49644
   741
  fixes a::"real^'n"
hoelzl@37489
   742
  shows "closed {x::real^'n. \<forall>i. a$i \<le> x$i}"
hoelzl@63332
   743
  by (simp add: Collect_all_eq closed_INT closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   744
wenzelm@49644
   745
lemma is_interval_cart:
wenzelm@49644
   746
  "is_interval (s::(real^'n) set) \<longleftrightarrow>
wenzelm@49644
   747
    (\<forall>a\<in>s. \<forall>b\<in>s. \<forall>x. (\<forall>i. ((a$i \<le> x$i \<and> x$i \<le> b$i) \<or> (b$i \<le> x$i \<and> x$i \<le> a$i))) \<longrightarrow> x \<in> s)"
hoelzl@50526
   748
  by (simp add: is_interval_def Ball_def Basis_vec_def inner_axis imp_ex)
hoelzl@37489
   749
wenzelm@49644
   750
lemma closed_halfspace_component_le_cart: "closed {x::real^'n. x$i \<le> a}"
hoelzl@63332
   751
  by (simp add: closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   752
wenzelm@49644
   753
lemma closed_halfspace_component_ge_cart: "closed {x::real^'n. x$i \<ge> a}"
hoelzl@63332
   754
  by (simp add: closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   755
wenzelm@49644
   756
lemma open_halfspace_component_lt_cart: "open {x::real^'n. x$i < a}"
hoelzl@63332
   757
  by (simp add: open_Collect_less continuous_on_const continuous_on_id continuous_on_component)
wenzelm@49644
   758
wenzelm@49644
   759
lemma open_halfspace_component_gt_cart: "open {x::real^'n. x$i  > a}"
hoelzl@63332
   760
  by (simp add: open_Collect_less continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   761
wenzelm@49644
   762
lemma Lim_component_le_cart:
wenzelm@49644
   763
  fixes f :: "'a \<Rightarrow> real^'n"
wenzelm@61973
   764
  assumes "(f \<longlongrightarrow> l) net" "\<not> (trivial_limit net)"  "eventually (\<lambda>x. f x $i \<le> b) net"
hoelzl@37489
   765
  shows "l$i \<le> b"
hoelzl@50526
   766
  by (rule tendsto_le[OF assms(2) tendsto_const tendsto_vec_nth, OF assms(1, 3)])
hoelzl@37489
   767
wenzelm@49644
   768
lemma Lim_component_ge_cart:
wenzelm@49644
   769
  fixes f :: "'a \<Rightarrow> real^'n"
wenzelm@61973
   770
  assumes "(f \<longlongrightarrow> l) net"  "\<not> (trivial_limit net)"  "eventually (\<lambda>x. b \<le> (f x)$i) net"
hoelzl@37489
   771
  shows "b \<le> l$i"
hoelzl@50526
   772
  by (rule tendsto_le[OF assms(2) tendsto_vec_nth tendsto_const, OF assms(1, 3)])
hoelzl@37489
   773
wenzelm@49644
   774
lemma Lim_component_eq_cart:
wenzelm@49644
   775
  fixes f :: "'a \<Rightarrow> real^'n"
wenzelm@61973
   776
  assumes net: "(f \<longlongrightarrow> l) net" "~(trivial_limit net)" and ev:"eventually (\<lambda>x. f(x)$i = b) net"
hoelzl@37489
   777
  shows "l$i = b"
wenzelm@49644
   778
  using ev[unfolded order_eq_iff eventually_conj_iff] and
wenzelm@49644
   779
    Lim_component_ge_cart[OF net, of b i] and
hoelzl@37489
   780
    Lim_component_le_cart[OF net, of i b] by auto
hoelzl@37489
   781
wenzelm@49644
   782
lemma connected_ivt_component_cart:
wenzelm@49644
   783
  fixes x :: "real^'n"
wenzelm@49644
   784
  shows "connected s \<Longrightarrow> x \<in> s \<Longrightarrow> y \<in> s \<Longrightarrow> x$k \<le> a \<Longrightarrow> a \<le> y$k \<Longrightarrow> (\<exists>z\<in>s.  z$k = a)"
hoelzl@50526
   785
  using connected_ivt_hyperplane[of s x y "axis k 1" a]
hoelzl@50526
   786
  by (auto simp add: inner_axis inner_commute)
hoelzl@37489
   787
immler@68072
   788
lemma subspace_substandard_cart: "vec.subspace {x. (\<forall>i. P i \<longrightarrow> x$i = 0)}"
immler@68072
   789
  unfolding vec.subspace_def by auto
hoelzl@37489
   790
hoelzl@37489
   791
lemma closed_substandard_cart:
huffman@44213
   792
  "closed {x::'a::real_normed_vector ^ 'n. \<forall>i. P i \<longrightarrow> x$i = 0}"
wenzelm@49644
   793
proof -
huffman@44213
   794
  { fix i::'n
huffman@44213
   795
    have "closed {x::'a ^ 'n. P i \<longrightarrow> x$i = 0}"
hoelzl@63332
   796
      by (cases "P i") (simp_all add: closed_Collect_eq continuous_on_const continuous_on_id continuous_on_component) }
huffman@44213
   797
  thus ?thesis
huffman@44213
   798
    unfolding Collect_all_eq by (simp add: closed_INT)
hoelzl@37489
   799
qed
hoelzl@37489
   800
immler@68072
   801
lemma dim_substandard_cart: "vec.dim {x::'a::field^'n. \<forall>i. i \<notin> d \<longrightarrow> x$i = 0} = card d"
immler@68072
   802
  (is "vec.dim ?A = _")
immler@68072
   803
proof (rule vec.dim_unique)
immler@68072
   804
  let ?B = "((\<lambda>x. axis x 1) ` d)"
immler@68072
   805
  have subset_basis: "?B \<subseteq> cart_basis"
immler@68072
   806
    by (auto simp: cart_basis_def)
immler@68072
   807
  show "?B \<subseteq> ?A"
immler@68072
   808
    by (auto simp: axis_def)
immler@68072
   809
  show "vec.independent ((\<lambda>x. axis x 1) ` d)"
immler@68072
   810
    using subset_basis
immler@68072
   811
    by (rule vec.independent_mono[OF vec.independent_Basis])
immler@68072
   812
  have "x \<in> vec.span ?B" if "\<forall>i. i \<notin> d \<longrightarrow> x $ i = 0" for x::"'a^'n"
immler@68072
   813
  proof -
immler@68072
   814
    have "finite ?B"
immler@68072
   815
      using subset_basis finite_cart_basis
immler@68072
   816
      by (rule finite_subset)
immler@68072
   817
    have "x = (\<Sum>i\<in>UNIV. x $ i *s axis i 1)"
immler@68072
   818
      by (rule basis_expansion[symmetric])
immler@68072
   819
    also have "\<dots> = (\<Sum>i\<in>d. (x $ i) *s axis i 1)"
immler@68072
   820
      by (rule sum.mono_neutral_cong_right) (auto simp: that)
immler@68072
   821
    also have "\<dots> \<in> vec.span ?B"
immler@68072
   822
      by (simp add: vec.span_sum vec.span_clauses)
immler@68072
   823
    finally show "x \<in> vec.span ?B" .
immler@68072
   824
  qed
immler@68072
   825
  then show "?A \<subseteq> vec.span ?B" by auto
immler@68072
   826
qed (simp add: card_image inj_on_def axis_eq_axis)
immler@68072
   827
immler@68072
   828
lemma dim_subset_UNIV_cart_gen:
immler@68072
   829
  fixes S :: "('a::field^'n) set"
immler@68072
   830
  shows "vec.dim S \<le> CARD('n)"
immler@68072
   831
  by (metis vec.dim_eq_full vec.dim_subset_UNIV vec.span_UNIV vec_dim_card)
hoelzl@37489
   832
lp15@67719
   833
lemma dim_subset_UNIV_cart:
lp15@67719
   834
  fixes S :: "(real^'n) set"
lp15@67719
   835
  shows "dim S \<le> CARD('n)"
immler@68072
   836
  using dim_subset_UNIV_cart_gen[of S] by (simp add: dim_vec_eq)
lp15@67719
   837
hoelzl@37489
   838
lemma affinity_inverses:
hoelzl@37489
   839
  assumes m0: "m \<noteq> (0::'a::field)"
wenzelm@61736
   840
  shows "(\<lambda>x. m *s x + c) \<circ> (\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) = id"
wenzelm@61736
   841
  "(\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) \<circ> (\<lambda>x. m *s x + c) = id"
hoelzl@37489
   842
  using m0
immler@68072
   843
  by (auto simp add: fun_eq_iff vector_add_ldistrib diff_conv_add_uminus simp del: add_uminus_conv_diff)
hoelzl@37489
   844
hoelzl@37489
   845
lemma vector_affinity_eq:
hoelzl@37489
   846
  assumes m0: "(m::'a::field) \<noteq> 0"
hoelzl@37489
   847
  shows "m *s x + c = y \<longleftrightarrow> x = inverse m *s y + -(inverse m *s c)"
hoelzl@37489
   848
proof
hoelzl@37489
   849
  assume h: "m *s x + c = y"
hoelzl@37489
   850
  hence "m *s x = y - c" by (simp add: field_simps)
hoelzl@37489
   851
  hence "inverse m *s (m *s x) = inverse m *s (y - c)" by simp
hoelzl@37489
   852
  then show "x = inverse m *s y + - (inverse m *s c)"
hoelzl@37489
   853
    using m0 by (simp add: vector_smult_assoc vector_ssub_ldistrib)
hoelzl@37489
   854
next
hoelzl@37489
   855
  assume h: "x = inverse m *s y + - (inverse m *s c)"
haftmann@54230
   856
  show "m *s x + c = y" unfolding h
hoelzl@37489
   857
    using m0 by (simp add: vector_smult_assoc vector_ssub_ldistrib)
hoelzl@37489
   858
qed
hoelzl@37489
   859
hoelzl@37489
   860
lemma vector_eq_affinity:
wenzelm@49644
   861
    "(m::'a::field) \<noteq> 0 ==> (y = m *s x + c \<longleftrightarrow> inverse(m) *s y + -(inverse(m) *s c) = x)"
hoelzl@37489
   862
  using vector_affinity_eq[where m=m and x=x and y=y and c=c]
hoelzl@37489
   863
  by metis
hoelzl@37489
   864
hoelzl@50526
   865
lemma vector_cart:
hoelzl@50526
   866
  fixes f :: "real^'n \<Rightarrow> real"
hoelzl@50526
   867
  shows "(\<chi> i. f (axis i 1)) = (\<Sum>i\<in>Basis. f i *\<^sub>R i)"
hoelzl@50526
   868
  unfolding euclidean_eq_iff[where 'a="real^'n"]
hoelzl@50526
   869
  by simp (simp add: Basis_vec_def inner_axis)
hoelzl@63332
   870
hoelzl@50526
   871
lemma const_vector_cart:"((\<chi> i. d)::real^'n) = (\<Sum>i\<in>Basis. d *\<^sub>R i)"
hoelzl@50526
   872
  by (rule vector_cart)
wenzelm@49644
   873
huffman@44360
   874
subsection "Convex Euclidean Space"
hoelzl@37489
   875
hoelzl@50526
   876
lemma Cart_1:"(1::real^'n) = \<Sum>Basis"
hoelzl@50526
   877
  using const_vector_cart[of 1] by (simp add: one_vec_def)
hoelzl@37489
   878
hoelzl@37489
   879
declare vector_add_ldistrib[simp] vector_ssub_ldistrib[simp] vector_smult_assoc[simp] vector_smult_rneg[simp]
hoelzl@37489
   880
declare vector_sadd_rdistrib[simp] vector_sub_rdistrib[simp]
hoelzl@37489
   881
hoelzl@50526
   882
lemmas vector_component_simps = vector_minus_component vector_smult_component vector_add_component less_eq_vec_def vec_lambda_beta vector_uminus_component
hoelzl@37489
   883
hoelzl@37489
   884
lemma convex_box_cart:
hoelzl@37489
   885
  assumes "\<And>i. convex {x. P i x}"
hoelzl@37489
   886
  shows "convex {x. \<forall>i. P i (x$i)}"
hoelzl@37489
   887
  using assms unfolding convex_def by auto
hoelzl@37489
   888
hoelzl@37489
   889
lemma convex_positive_orthant_cart: "convex {x::real^'n. (\<forall>i. 0 \<le> x$i)}"
hoelzl@63334
   890
  by (rule convex_box_cart) (simp add: atLeast_def[symmetric])
hoelzl@37489
   891
hoelzl@37489
   892
lemma unit_interval_convex_hull_cart:
immler@56188
   893
  "cbox (0::real^'n) 1 = convex hull {x. \<forall>i. (x$i = 0) \<or> (x$i = 1)}"
immler@56188
   894
  unfolding Cart_1 unit_interval_convex_hull[where 'a="real^'n"] box_real[symmetric]
hoelzl@50526
   895
  by (rule arg_cong[where f="\<lambda>x. convex hull x"]) (simp add: Basis_vec_def inner_axis)
hoelzl@37489
   896
hoelzl@37489
   897
lemma cube_convex_hull_cart:
wenzelm@49644
   898
  assumes "0 < d"
wenzelm@49644
   899
  obtains s::"(real^'n) set"
immler@56188
   900
    where "finite s" "cbox (x - (\<chi> i. d)) (x + (\<chi> i. d)) = convex hull s"
wenzelm@49644
   901
proof -
wenzelm@55522
   902
  from assms obtain s where "finite s"
nipkow@67399
   903
    and "cbox (x - sum (( *\<^sub>R) d) Basis) (x + sum (( *\<^sub>R) d) Basis) = convex hull s"
wenzelm@55522
   904
    by (rule cube_convex_hull)
wenzelm@55522
   905
  with that[of s] show thesis
wenzelm@55522
   906
    by (simp add: const_vector_cart)
hoelzl@37489
   907
qed
hoelzl@37489
   908
hoelzl@37489
   909
hoelzl@37489
   910
subsection "Derivative"
hoelzl@37489
   911
hoelzl@37489
   912
definition "jacobian f net = matrix(frechet_derivative f net)"
hoelzl@37489
   913
wenzelm@49644
   914
lemma jacobian_works:
wenzelm@49644
   915
  "(f::(real^'a) \<Rightarrow> (real^'b)) differentiable net \<longleftrightarrow>
lp15@67986
   916
    (f has_derivative (\<lambda>h. (jacobian f net) *v h)) net" (is "?lhs = ?rhs")
lp15@67986
   917
proof
lp15@67986
   918
  assume ?lhs then show ?rhs
lp15@67986
   919
    by (simp add: frechet_derivative_works has_derivative_linear jacobian_def)
lp15@67986
   920
next
lp15@67986
   921
  assume ?rhs then show ?lhs
lp15@67986
   922
    by (rule differentiableI)
lp15@67986
   923
qed
hoelzl@37489
   924
hoelzl@37489
   925
wenzelm@60420
   926
subsection \<open>Component of the differential must be zero if it exists at a local
nipkow@67968
   927
  maximum or minimum for that corresponding component\<close>
hoelzl@37489
   928
hoelzl@50526
   929
lemma differential_zero_maxmin_cart:
wenzelm@49644
   930
  fixes f::"real^'a \<Rightarrow> real^'b"
wenzelm@49644
   931
  assumes "0 < e" "((\<forall>y \<in> ball x e. (f y)$k \<le> (f x)$k) \<or> (\<forall>y\<in>ball x e. (f x)$k \<le> (f y)$k))"
hoelzl@50526
   932
    "f differentiable (at x)"
hoelzl@50526
   933
  shows "jacobian f (at x) $ k = 0"
hoelzl@50526
   934
  using differential_zero_maxmin_component[of "axis k 1" e x f] assms
hoelzl@50526
   935
    vector_cart[of "\<lambda>j. frechet_derivative f (at x) j $ k"]
hoelzl@50526
   936
  by (simp add: Basis_vec_def axis_eq_axis inner_axis jacobian_def matrix_def)
wenzelm@49644
   937
wenzelm@60420
   938
subsection \<open>Lemmas for working on @{typ "real^1"}\<close>
hoelzl@37489
   939
hoelzl@37489
   940
lemma forall_1[simp]: "(\<forall>i::1. P i) \<longleftrightarrow> P 1"
wenzelm@49644
   941
  by (metis (full_types) num1_eq_iff)
hoelzl@37489
   942
hoelzl@37489
   943
lemma ex_1[simp]: "(\<exists>x::1. P x) \<longleftrightarrow> P 1"
wenzelm@49644
   944
  by auto (metis (full_types) num1_eq_iff)
hoelzl@37489
   945
hoelzl@37489
   946
lemma exhaust_2:
wenzelm@49644
   947
  fixes x :: 2
wenzelm@49644
   948
  shows "x = 1 \<or> x = 2"
hoelzl@37489
   949
proof (induct x)
hoelzl@37489
   950
  case (of_int z)
lp15@67979
   951
  then have "0 \<le> z" and "z < 2" by simp_all
hoelzl@37489
   952
  then have "z = 0 | z = 1" by arith
hoelzl@37489
   953
  then show ?case by auto
hoelzl@37489
   954
qed
hoelzl@37489
   955
hoelzl@37489
   956
lemma forall_2: "(\<forall>i::2. P i) \<longleftrightarrow> P 1 \<and> P 2"
hoelzl@37489
   957
  by (metis exhaust_2)
hoelzl@37489
   958
hoelzl@37489
   959
lemma exhaust_3:
wenzelm@49644
   960
  fixes x :: 3
wenzelm@49644
   961
  shows "x = 1 \<or> x = 2 \<or> x = 3"
hoelzl@37489
   962
proof (induct x)
hoelzl@37489
   963
  case (of_int z)
lp15@67979
   964
  then have "0 \<le> z" and "z < 3" by simp_all
hoelzl@37489
   965
  then have "z = 0 \<or> z = 1 \<or> z = 2" by arith
hoelzl@37489
   966
  then show ?case by auto
hoelzl@37489
   967
qed
hoelzl@37489
   968
hoelzl@37489
   969
lemma forall_3: "(\<forall>i::3. P i) \<longleftrightarrow> P 1 \<and> P 2 \<and> P 3"
hoelzl@37489
   970
  by (metis exhaust_3)
hoelzl@37489
   971
hoelzl@37489
   972
lemma UNIV_1 [simp]: "UNIV = {1::1}"
hoelzl@37489
   973
  by (auto simp add: num1_eq_iff)
hoelzl@37489
   974
hoelzl@37489
   975
lemma UNIV_2: "UNIV = {1::2, 2::2}"
hoelzl@37489
   976
  using exhaust_2 by auto
hoelzl@37489
   977
hoelzl@37489
   978
lemma UNIV_3: "UNIV = {1::3, 2::3, 3::3}"
hoelzl@37489
   979
  using exhaust_3 by auto
hoelzl@37489
   980
nipkow@64267
   981
lemma sum_1: "sum f (UNIV::1 set) = f 1"
hoelzl@37489
   982
  unfolding UNIV_1 by simp
hoelzl@37489
   983
nipkow@64267
   984
lemma sum_2: "sum f (UNIV::2 set) = f 1 + f 2"
hoelzl@37489
   985
  unfolding UNIV_2 by simp
hoelzl@37489
   986
nipkow@64267
   987
lemma sum_3: "sum f (UNIV::3 set) = f 1 + f 2 + f 3"
haftmann@57514
   988
  unfolding UNIV_3 by (simp add: ac_simps)
hoelzl@37489
   989
lp15@67979
   990
lemma num1_eqI:
lp15@67979
   991
  fixes a::num1 shows "a = b"
lp15@67979
   992
  by (metis (full_types) UNIV_1 UNIV_I empty_iff insert_iff)
lp15@67979
   993
lp15@67979
   994
lemma num1_eq1 [simp]:
lp15@67979
   995
  fixes a::num1 shows "a = 1"
lp15@67979
   996
  by (rule num1_eqI)
lp15@67979
   997
wenzelm@49644
   998
instantiation num1 :: cart_one
wenzelm@49644
   999
begin
wenzelm@49644
  1000
wenzelm@49644
  1001
instance
wenzelm@49644
  1002
proof
hoelzl@37489
  1003
  show "CARD(1) = Suc 0" by auto
wenzelm@49644
  1004
qed
wenzelm@49644
  1005
wenzelm@49644
  1006
end
hoelzl@37489
  1007
lp15@67979
  1008
instantiation num1 :: linorder begin
lp15@67979
  1009
definition "a < b \<longleftrightarrow> Rep_num1 a < Rep_num1 b"
lp15@67979
  1010
definition "a \<le> b \<longleftrightarrow> Rep_num1 a \<le> Rep_num1 b"
lp15@67979
  1011
instance
lp15@67979
  1012
  by intro_classes (auto simp: less_eq_num1_def less_num1_def intro: num1_eqI)
lp15@67979
  1013
end
lp15@67979
  1014
lp15@67979
  1015
instance num1 :: wellorder
lp15@67979
  1016
  by intro_classes (auto simp: less_eq_num1_def less_num1_def)
lp15@67979
  1017
nipkow@67968
  1018
subsection\<open>The collapse of the general concepts to dimension one\<close>
hoelzl@37489
  1019
hoelzl@37489
  1020
lemma vector_one: "(x::'a ^1) = (\<chi> i. (x$1))"
huffman@44136
  1021
  by (simp add: vec_eq_iff)
hoelzl@37489
  1022
hoelzl@37489
  1023
lemma forall_one: "(\<forall>(x::'a ^1). P x) \<longleftrightarrow> (\<forall>x. P(\<chi> i. x))"
hoelzl@37489
  1024
  apply auto
hoelzl@37489
  1025
  apply (erule_tac x= "x$1" in allE)
hoelzl@37489
  1026
  apply (simp only: vector_one[symmetric])
hoelzl@37489
  1027
  done
hoelzl@37489
  1028
hoelzl@37489
  1029
lemma norm_vector_1: "norm (x :: _^1) = norm (x$1)"
huffman@44136
  1030
  by (simp add: norm_vec_def)
hoelzl@37489
  1031
lp15@67979
  1032
lemma dist_vector_1:
lp15@67979
  1033
  fixes x :: "'a::real_normed_vector^1"
lp15@67979
  1034
  shows "dist x y = dist (x$1) (y$1)"
lp15@67979
  1035
  by (simp add: dist_norm norm_vector_1)
lp15@67979
  1036
wenzelm@61945
  1037
lemma norm_real: "norm(x::real ^ 1) = \<bar>x$1\<bar>"
hoelzl@37489
  1038
  by (simp add: norm_vector_1)
hoelzl@37489
  1039
wenzelm@61945
  1040
lemma dist_real: "dist(x::real ^ 1) y = \<bar>(x$1) - (y$1)\<bar>"
hoelzl@37489
  1041
  by (auto simp add: norm_real dist_norm)
hoelzl@37489
  1042
lp15@67986
  1043
subsection\<open> Rank of a matrix\<close>
lp15@67986
  1044
lp15@67986
  1045
text\<open>Equivalence of row and column rank is taken from George Mackiw's paper, Mathematics Magazine 1995, p. 285.\<close>
lp15@67986
  1046
immler@68072
  1047
lemma matrix_vector_mult_in_columnspace_gen:
immler@68072
  1048
  fixes A :: "'a::field^'n^'m"
immler@68072
  1049
  shows "(A *v x) \<in> vec.span(columns A)"
immler@68072
  1050
  apply (simp add: matrix_vector_column columns_def transpose_def column_def)
immler@68072
  1051
  apply (intro vec.span_sum vec.span_scale)
immler@68072
  1052
  apply (force intro: vec.span_base)
immler@68072
  1053
  done
immler@68072
  1054
lp15@67986
  1055
lemma matrix_vector_mult_in_columnspace:
lp15@67986
  1056
  fixes A :: "real^'n^'m"
lp15@67986
  1057
  shows "(A *v x) \<in> span(columns A)"
immler@68072
  1058
  using matrix_vector_mult_in_columnspace_gen[of A x] by (simp add: span_vec_eq)
lp15@67986
  1059
lp15@67986
  1060
lemma orthogonal_nullspace_rowspace:
lp15@67986
  1061
  fixes A :: "real^'n^'m"
lp15@67986
  1062
  assumes 0: "A *v x = 0" and y: "y \<in> span(rows A)"
lp15@67986
  1063
  shows "orthogonal x y"
lp15@67986
  1064
proof (rule span_induct [OF y])
lp15@67986
  1065
  show "subspace {a. orthogonal x a}"
lp15@67986
  1066
    by (simp add: subspace_orthogonal_to_vector)
lp15@67986
  1067
next
lp15@67986
  1068
  fix v
lp15@67986
  1069
  assume "v \<in> rows A"
lp15@67986
  1070
  then obtain i where "v = row i A"
lp15@67986
  1071
    by (auto simp: rows_def)
lp15@67986
  1072
  with 0 show "orthogonal x v"
lp15@67986
  1073
    unfolding orthogonal_def inner_vec_def matrix_vector_mult_def row_def
lp15@67986
  1074
    by (simp add: mult.commute) (metis (no_types) vec_lambda_beta zero_index)
lp15@67986
  1075
qed
lp15@67986
  1076
lp15@67986
  1077
lemma nullspace_inter_rowspace:
lp15@67986
  1078
  fixes A :: "real^'n^'m"
lp15@67986
  1079
  shows "A *v x = 0 \<and> x \<in> span(rows A) \<longleftrightarrow> x = 0"
immler@68072
  1080
  using orthogonal_nullspace_rowspace orthogonal_self span_zero matrix_vector_mult_0_right
immler@68072
  1081
  by blast
lp15@67986
  1082
lp15@67986
  1083
lemma matrix_vector_mul_injective_on_rowspace:
lp15@67986
  1084
  fixes A :: "real^'n^'m"
lp15@67986
  1085
  shows "\<lbrakk>A *v x = A *v y; x \<in> span(rows A); y \<in> span(rows A)\<rbrakk> \<Longrightarrow> x = y"
lp15@67986
  1086
  using nullspace_inter_rowspace [of A "x-y"]
immler@68072
  1087
  by (metis diff_eq_diff_eq diff_self matrix_vector_mult_diff_distrib span_diff)
lp15@67986
  1088
immler@68072
  1089
definition rank :: "'a::field^'n^'m=>nat"
immler@68072
  1090
  where row_rank_def_gen: "rank A \<equiv> vec.dim(rows A)"
immler@68072
  1091
immler@68072
  1092
lemma row_rank_def: "rank A = dim (rows A)" for A::"real^'n^'m"
immler@68072
  1093
  by (auto simp: row_rank_def_gen dim_vec_eq)
lp15@67986
  1094
lp15@67986
  1095
lemma dim_rows_le_dim_columns:
lp15@67986
  1096
  fixes A :: "real^'n^'m"
lp15@67986
  1097
  shows "dim(rows A) \<le> dim(columns A)"
lp15@67986
  1098
proof -
lp15@67986
  1099
  have "dim (span (rows A)) \<le> dim (span (columns A))"
lp15@67986
  1100
  proof -
lp15@67986
  1101
    obtain B where "independent B" "span(rows A) \<subseteq> span B"
lp15@67986
  1102
              and B: "B \<subseteq> span(rows A)""card B = dim (span(rows A))"
lp15@67986
  1103
      using basis_exists [of "span(rows A)"] by blast
lp15@67986
  1104
    with span_subspace have eq: "span B = span(rows A)"
lp15@67986
  1105
      by auto
lp15@67986
  1106
    then have inj: "inj_on (( *v) A) (span B)"
immler@68072
  1107
      by (simp add: inj_on_def matrix_vector_mul_injective_on_rowspace)
lp15@67986
  1108
    then have ind: "independent (( *v) A ` B)"
immler@68072
  1109
      by (rule linear_independent_injective_image [OF Finite_Cartesian_Product.matrix_vector_mul_linear \<open>independent B\<close>])
immler@68072
  1110
    have "dim (span (rows A)) \<le> card (( *v) A ` B)"
immler@68072
  1111
      unfolding B(2)[symmetric]
immler@68072
  1112
      using inj
immler@68072
  1113
      by (auto simp: card_image inj_on_subset span_superset)
immler@68072
  1114
    also have "\<dots> \<le> dim (span (columns A))"
immler@68072
  1115
      using _ ind
immler@68072
  1116
      by (rule independent_card_le_dim) (auto intro!: matrix_vector_mult_in_columnspace)
immler@68072
  1117
    finally show ?thesis .
lp15@67986
  1118
  qed
lp15@67986
  1119
  then show ?thesis
immler@68072
  1120
    by (simp add: dim_span)
lp15@67986
  1121
qed
lp15@67986
  1122
immler@68072
  1123
lemma column_rank_def:
lp15@67986
  1124
  fixes A :: "real^'n^'m"
immler@68072
  1125
  shows "rank A = dim(columns A)"
immler@68072
  1126
  unfolding row_rank_def
immler@68072
  1127
  by (metis columns_transpose dim_rows_le_dim_columns le_antisym rows_transpose)
lp15@67986
  1128
lp15@67986
  1129
lemma rank_transpose:
lp15@67986
  1130
  fixes A :: "real^'n^'m"
lp15@67986
  1131
  shows "rank(transpose A) = rank A"
immler@68072
  1132
  by (metis column_rank_def row_rank_def rows_transpose)
lp15@67986
  1133
lp15@67986
  1134
lemma matrix_vector_mult_basis:
lp15@67986
  1135
  fixes A :: "real^'n^'m"
lp15@67986
  1136
  shows "A *v (axis k 1) = column k A"
lp15@67986
  1137
  by (simp add: cart_eq_inner_axis column_def matrix_mult_dot)
lp15@67986
  1138
lp15@67986
  1139
lemma columns_image_basis:
lp15@67986
  1140
  fixes A :: "real^'n^'m"
lp15@67986
  1141
  shows "columns A = ( *v) A ` (range (\<lambda>i. axis i 1))"
lp15@67986
  1142
  by (force simp: columns_def matrix_vector_mult_basis [symmetric])
lp15@67986
  1143
lp15@67986
  1144
lemma rank_dim_range:
lp15@67986
  1145
  fixes A :: "real^'n^'m"
lp15@67986
  1146
  shows "rank A = dim(range (\<lambda>x. A *v x))"
immler@68072
  1147
  unfolding column_rank_def
lp15@67986
  1148
proof (rule span_eq_dim)
immler@68072
  1149
  have "span (columns A) \<subseteq> span (range (( *v) A))" (is "?l \<subseteq> ?r")
immler@68072
  1150
    by (simp add: columns_image_basis image_subsetI span_mono)
immler@68072
  1151
  then show "?l = ?r"
immler@68072
  1152
    by (metis (no_types, lifting) image_subset_iff matrix_vector_mult_in_columnspace
immler@68072
  1153
        span_eq span_span)
lp15@67986
  1154
qed
lp15@67986
  1155
lp15@67986
  1156
lemma rank_bound:
lp15@67986
  1157
  fixes A :: "real^'n^'m"
lp15@67986
  1158
  shows "rank A \<le> min CARD('m) (CARD('n))"
immler@68072
  1159
  by (metis (mono_tags, lifting) dim_subset_UNIV_cart min.bounded_iff
immler@68072
  1160
      column_rank_def row_rank_def)
lp15@67986
  1161
lp15@67986
  1162
lemma full_rank_injective:
lp15@67986
  1163
  fixes A :: "real^'n^'m"
lp15@67986
  1164
  shows "rank A = CARD('n) \<longleftrightarrow> inj (( *v) A)"
immler@68072
  1165
  by (simp add: matrix_left_invertible_injective [symmetric] matrix_left_invertible_span_rows row_rank_def
immler@68072
  1166
      dim_eq_full [symmetric] card_cart_basis vec.dimension_def)
lp15@67986
  1167
lp15@67986
  1168
lemma full_rank_surjective:
lp15@67986
  1169
  fixes A :: "real^'n^'m"
lp15@67986
  1170
  shows "rank A = CARD('m) \<longleftrightarrow> surj (( *v) A)"
lp15@67986
  1171
  by (simp add: matrix_right_invertible_surjective [symmetric] left_invertible_transpose [symmetric]
lp15@67986
  1172
                matrix_left_invertible_injective full_rank_injective [symmetric] rank_transpose)
lp15@67986
  1173
lp15@67986
  1174
lemma rank_I: "rank(mat 1::real^'n^'n) = CARD('n)"
lp15@67986
  1175
  by (simp add: full_rank_injective inj_on_def)
lp15@67986
  1176
lp15@67986
  1177
lemma less_rank_noninjective:
lp15@67986
  1178
  fixes A :: "real^'n^'m"
lp15@67986
  1179
  shows "rank A < CARD('n) \<longleftrightarrow> \<not> inj (( *v) A)"
lp15@67986
  1180
using less_le rank_bound by (auto simp: full_rank_injective [symmetric])
lp15@67986
  1181
lp15@67986
  1182
lemma matrix_nonfull_linear_equations_eq:
lp15@67986
  1183
  fixes A :: "real^'n^'m"
lp15@67986
  1184
  shows "(\<exists>x. (x \<noteq> 0) \<and> A *v x = 0) \<longleftrightarrow> ~(rank A = CARD('n))"
lp15@67986
  1185
  by (meson matrix_left_invertible_injective full_rank_injective matrix_left_invertible_ker)
lp15@67986
  1186
immler@68072
  1187
lemma rank_eq_0: "rank A = 0 \<longleftrightarrow> A = 0" and rank_0 [simp]: "rank (0::real^'n^'m) = 0"
immler@68072
  1188
  for A :: "real^'n^'m"
lp15@67986
  1189
  by (auto simp: rank_dim_range matrix_eq)
lp15@67986
  1190
lp15@67986
  1191
lemma rank_mul_le_right:
lp15@67986
  1192
  fixes A :: "real^'n^'m" and B :: "real^'p^'n"
lp15@67986
  1193
  shows "rank(A ** B) \<le> rank B"
lp15@67986
  1194
proof -
lp15@67986
  1195
  have "rank(A ** B) \<le> dim (( *v) A ` range (( *v) B))"
lp15@67986
  1196
    by (auto simp: rank_dim_range image_comp o_def matrix_vector_mul_assoc)
lp15@67986
  1197
  also have "\<dots> \<le> rank B"
immler@68072
  1198
    by (simp add: rank_dim_range dim_image_le)
lp15@67986
  1199
  finally show ?thesis .
lp15@67986
  1200
qed
lp15@67986
  1201
lp15@67986
  1202
lemma rank_mul_le_left:
lp15@67986
  1203
  fixes A :: "real^'n^'m" and B :: "real^'p^'n"
lp15@67986
  1204
  shows "rank(A ** B) \<le> rank A"
lp15@67986
  1205
  by (metis matrix_transpose_mul rank_mul_le_right rank_transpose)
lp15@67986
  1206
lp15@67981
  1207
subsection\<open>Routine results connecting the types @{typ "real^1"} and @{typ real}\<close>
lp15@67981
  1208
lp15@67981
  1209
lemma vector_one_nth [simp]:
lp15@67981
  1210
  fixes x :: "'a^1" shows "vec (x $ 1) = x"
lp15@67981
  1211
  by (metis vec_def vector_one)
lp15@67981
  1212
lp15@67981
  1213
lemma vec_cbox_1_eq [simp]:
lp15@67981
  1214
  shows "vec ` cbox u v = cbox (vec u) (vec v ::real^1)"
lp15@67981
  1215
  by (force simp: Basis_vec_def cart_eq_inner_axis [symmetric] mem_box)
lp15@67981
  1216
lp15@67981
  1217
lemma vec_nth_cbox_1_eq [simp]:
lp15@67981
  1218
  fixes u v :: "'a::euclidean_space^1"
lp15@67981
  1219
  shows "(\<lambda>x. x $ 1) ` cbox u v = cbox (u$1) (v$1)"
lp15@67981
  1220
    by (auto simp: Basis_vec_def cart_eq_inner_axis [symmetric] mem_box image_iff Bex_def inner_axis) (metis vec_component)
lp15@67981
  1221
lp15@67981
  1222
lemma vec_nth_1_iff_cbox [simp]:
lp15@67981
  1223
  fixes a b :: "'a::euclidean_space"
lp15@67981
  1224
  shows "(\<lambda>x::'a^1. x $ 1) ` S = cbox a b \<longleftrightarrow> S = cbox (vec a) (vec b)"
lp15@67981
  1225
    (is "?lhs = ?rhs")
lp15@67981
  1226
proof
lp15@67981
  1227
  assume L: ?lhs show ?rhs
lp15@67981
  1228
  proof (intro equalityI subsetI)
lp15@67981
  1229
    fix x 
lp15@67981
  1230
    assume "x \<in> S"
lp15@67981
  1231
    then have "x $ 1 \<in> (\<lambda>v. v $ (1::1)) ` cbox (vec a) (vec b)"
lp15@67981
  1232
      using L by auto
lp15@67981
  1233
    then show "x \<in> cbox (vec a) (vec b)"
lp15@67981
  1234
      by (metis (no_types, lifting) imageE vector_one_nth)
lp15@67981
  1235
  next
lp15@67981
  1236
    fix x :: "'a^1"
lp15@67981
  1237
    assume "x \<in> cbox (vec a) (vec b)"
lp15@67981
  1238
    then show "x \<in> S"
lp15@67981
  1239
      by (metis (no_types, lifting) L imageE imageI vec_component vec_nth_cbox_1_eq vector_one_nth)
lp15@67981
  1240
  qed
lp15@67981
  1241
qed simp
wenzelm@49644
  1242
lp15@67979
  1243
lemma tendsto_at_within_vector_1:
lp15@67979
  1244
  fixes S :: "'a :: metric_space set"
lp15@67979
  1245
  assumes "(f \<longlongrightarrow> fx) (at x within S)"
lp15@67979
  1246
  shows "((\<lambda>y::'a^1. \<chi> i. f (y $ 1)) \<longlongrightarrow> (vec fx::'a^1)) (at (vec x) within vec ` S)"
lp15@67979
  1247
proof (rule topological_tendstoI)
lp15@67979
  1248
  fix T :: "('a^1) set"
lp15@67979
  1249
  assume "open T" "vec fx \<in> T"
lp15@67979
  1250
  have "\<forall>\<^sub>F x in at x within S. f x \<in> (\<lambda>x. x $ 1) ` T"
lp15@67979
  1251
    using \<open>open T\<close> \<open>vec fx \<in> T\<close> assms open_image_vec_nth tendsto_def by fastforce
lp15@67979
  1252
  then show "\<forall>\<^sub>F x::'a^1 in at (vec x) within vec ` S. (\<chi> i. f (x $ 1)) \<in> T"
lp15@67979
  1253
    unfolding eventually_at dist_norm [symmetric]
lp15@67979
  1254
    by (rule ex_forward)
lp15@67979
  1255
       (use \<open>open T\<close> in 
lp15@67979
  1256
         \<open>fastforce simp: dist_norm dist_vec_def L2_set_def image_iff vector_one open_vec_def\<close>)
lp15@67979
  1257
qed
lp15@67979
  1258
lp15@67979
  1259
lemma has_derivative_vector_1:
lp15@67979
  1260
  assumes der_g: "(g has_derivative (\<lambda>x. x * g' a)) (at a within S)"
lp15@67979
  1261
  shows "((\<lambda>x. vec (g (x $ 1))) has_derivative ( *\<^sub>R) (g' a))
lp15@67979
  1262
         (at ((vec a)::real^1) within vec ` S)"
lp15@67979
  1263
    using der_g
lp15@67979
  1264
    apply (auto simp: Deriv.has_derivative_within bounded_linear_scaleR_right norm_vector_1)
lp15@67979
  1265
    apply (drule tendsto_at_within_vector_1, vector)
lp15@67979
  1266
    apply (auto simp: algebra_simps eventually_at tendsto_def)
lp15@67979
  1267
    done
lp15@67979
  1268
lp15@67979
  1269
nipkow@67968
  1270
subsection\<open>Explicit vector construction from lists\<close>
hoelzl@37489
  1271
hoelzl@43995
  1272
definition "vector l = (\<chi> i. foldr (\<lambda>x f n. fun_upd (f (n+1)) n x) l (\<lambda>n x. 0) 1 i)"
hoelzl@37489
  1273
lp15@68054
  1274
lemma vector_1 [simp]: "(vector[x]) $1 = x"
hoelzl@37489
  1275
  unfolding vector_def by simp
hoelzl@37489
  1276
lp15@68054
  1277
lemma vector_2 [simp]: "(vector[x,y]) $1 = x" "(vector[x,y] :: 'a^2)$2 = (y::'a::zero)"
hoelzl@37489
  1278
  unfolding vector_def by simp_all
hoelzl@37489
  1279
lp15@68054
  1280
lemma vector_3 [simp]:
hoelzl@37489
  1281
 "(vector [x,y,z] ::('a::zero)^3)$1 = x"
hoelzl@37489
  1282
 "(vector [x,y,z] ::('a::zero)^3)$2 = y"
hoelzl@37489
  1283
 "(vector [x,y,z] ::('a::zero)^3)$3 = z"
hoelzl@37489
  1284
  unfolding vector_def by simp_all
hoelzl@37489
  1285
hoelzl@37489
  1286
lemma forall_vector_1: "(\<forall>v::'a::zero^1. P v) \<longleftrightarrow> (\<forall>x. P(vector[x]))"
lp15@67719
  1287
  by (metis vector_1 vector_one)
hoelzl@37489
  1288
hoelzl@37489
  1289
lemma forall_vector_2: "(\<forall>v::'a::zero^2. P v) \<longleftrightarrow> (\<forall>x y. P(vector[x, y]))"
hoelzl@37489
  1290
  apply auto
hoelzl@37489
  1291
  apply (erule_tac x="v$1" in allE)
hoelzl@37489
  1292
  apply (erule_tac x="v$2" in allE)
hoelzl@37489
  1293
  apply (subgoal_tac "vector [v$1, v$2] = v")
hoelzl@37489
  1294
  apply simp
hoelzl@37489
  1295
  apply (vector vector_def)
hoelzl@37489
  1296
  apply (simp add: forall_2)
hoelzl@37489
  1297
  done
hoelzl@37489
  1298
hoelzl@37489
  1299
lemma forall_vector_3: "(\<forall>v::'a::zero^3. P v) \<longleftrightarrow> (\<forall>x y z. P(vector[x, y, z]))"
hoelzl@37489
  1300
  apply auto
hoelzl@37489
  1301
  apply (erule_tac x="v$1" in allE)
hoelzl@37489
  1302
  apply (erule_tac x="v$2" in allE)
hoelzl@37489
  1303
  apply (erule_tac x="v$3" in allE)
hoelzl@37489
  1304
  apply (subgoal_tac "vector [v$1, v$2, v$3] = v")
hoelzl@37489
  1305
  apply simp
hoelzl@37489
  1306
  apply (vector vector_def)
hoelzl@37489
  1307
  apply (simp add: forall_3)
hoelzl@37489
  1308
  done
hoelzl@37489
  1309
hoelzl@37489
  1310
lemma bounded_linear_component_cart[intro]: "bounded_linear (\<lambda>x::real^'n. x $ k)"
lp15@68062
  1311
  apply (rule bounded_linear_intro[where K=1])
hoelzl@37489
  1312
  using component_le_norm_cart[of _ k] unfolding real_norm_def by auto
hoelzl@37489
  1313
hoelzl@37489
  1314
lemma interval_split_cart:
hoelzl@37489
  1315
  "{a..b::real^'n} \<inter> {x. x$k \<le> c} = {a .. (\<chi> i. if i = k then min (b$k) c else b$i)}"
immler@56188
  1316
  "cbox a b \<inter> {x. x$k \<ge> c} = {(\<chi> i. if i = k then max (a$k) c else a$i) .. b}"
wenzelm@49644
  1317
  apply (rule_tac[!] set_eqI)
lp15@67673
  1318
  unfolding Int_iff mem_box_cart mem_Collect_eq interval_cbox_cart
wenzelm@49644
  1319
  unfolding vec_lambda_beta
wenzelm@49644
  1320
  by auto
hoelzl@37489
  1321
immler@67685
  1322
lemmas cartesian_euclidean_space_uniform_limit_intros[uniform_limit_intros] =
immler@67685
  1323
  bounded_linear.uniform_limit[OF blinfun.bounded_linear_right]
immler@67685
  1324
  bounded_linear.uniform_limit[OF bounded_linear_vec_nth]
immler@67685
  1325
  bounded_linear.uniform_limit[OF bounded_linear_component_cart]
immler@67685
  1326
hoelzl@37489
  1327
end