src/HOL/Analysis/Cartesian_Euclidean_Space.thy
author wenzelm
Sat Jan 05 17:24:33 2019 +0100 (4 months ago)
changeset 69597 ff784d5a5bfb
parent 69508 2a4c8a2a3f8e
child 69663 41ff40bf1530
child 69677 a06b204527e6
permissions -rw-r--r--
isabelle update -u control_cartouches;
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
ak2110@68833
     5
section%important \<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
ak2110@68833
    11
lemma%unimportant subspace_special_hyperplane: "subspace {x. x $ k = 0}"
lp15@63016
    12
  by (simp add: subspace_def)
lp15@63016
    13
ak2110@68833
    14
lemma%important 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]
ak2110@68833
    17
proof%unimportant (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
ak2110@68833
    28
lemma%unimportant 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
ak2110@68833
    31
lemma%unimportant 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
ak2110@68833
    36
lemma%unimportant 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
ak2110@68833
    43
lemma%unimportant 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
ak2110@68833
    48
subsection%important\<open>Closures and interiors of halfspaces\<close>
lp15@62397
    49
ak2110@68833
    50
lemma%important 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}"
ak2110@68833
    53
proof%unimportant -
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
ak2110@68833
    73
lemma%unimportant 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
ak2110@68833
    77
lemma%important 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")
ak2110@68833
    81
proof%unimportant -
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
ak2110@68833
    91
lemma%unimportant 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
ak2110@68833
   102
lemma%unimportant 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
ak2110@68833
   106
lemma%important 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")
ak2110@68833
   110
proof%unimportant -
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
ak2110@68833
   120
lemma%unimportant interior_hyperplane [simp]:
lp15@62397
   121
  assumes "a \<noteq> 0"
lp15@62397
   122
    shows "interior {x. a \<bullet> x = b} = {}"
ak2110@68833
   123
proof%unimportant -
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
ak2110@68833
   130
lemma%unimportant 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
ak2110@68833
   140
lemma%unimportant 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
ak2110@68833
   150
lemma%unimportant 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
ak2110@68833
   160
lemma%important 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}"
ak2110@68833
   163
proof%unimportant (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
ak2110@68833
   170
lemma%important interior_standard_hyperplane:
wenzelm@67731
   171
   "interior {x :: (real^'n). x$k = a} = {}"
ak2110@68833
   172
proof%unimportant -
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
ak2110@68833
   182
lemma%unimportant 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
ak2110@68833
   186
lemma%unimportant 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
ak2110@68833
   192
lemma%important 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
ak2110@68833
   195
lemma%unimportant 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
ak2110@68833
   203
lemma%important matrix_adjoint: assumes lf: "linear (f :: real^'n \<Rightarrow> real ^'m)"
hoelzl@37489
   204
  shows "matrix(adjoint f) = transpose(matrix f)"
ak2110@68833
   205
proof%unimportant -
nipkow@69064
   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
nipkow@69064
   215
lemma%unimportant matrix_vector_mul_bounded_linear[intro, simp]: "bounded_linear ((*v) A)" for A :: "'a::{euclidean_space,real_algebra_1}^'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
ak2110@68833
   219
lemma%unimportant (* FIX ME needs name*)
immler@68073
   220
  fixes A :: "'a::{euclidean_space,real_algebra_1}^'n^'m"
nipkow@69064
   221
  shows matrix_vector_mult_linear_continuous_at [continuous_intros]: "isCont ((*v) A) z"
nipkow@69064
   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
ak2110@68833
   225
lemma%unimportant 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
wenzelm@69272
   232
  with \<open>k \<noteq> 0\<close>
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
ak2110@68833
   239
lemma%unimportant 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
ak2110@68833
   245
lemma%unimportant 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
ak2110@68833
   249
lemma%unimportant 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
ak2110@68833
   253
lemma%unimportant 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
ak2110@68833
   258
lemma%unimportant 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
 
ak2110@68833
   263
lemma%unimportant 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
ak2110@68833
   266
lemma%unimportant 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
ak2110@68833
   269
lemma%unimportant 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
ak2110@68833
   274
lemma%unimportant 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
ak2110@68833
   279
lemma%important 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)"
ak2110@68833
   282
proof%unimportant -
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
ak2110@68833
   292
subsection%important\<open>Some bounds on components etc. relative to operator norm\<close>
lp15@67719
   293
ak2110@68833
   294
lemma%important norm_column_le_onorm:
lp15@67719
   295
  fixes A :: "real^'n^'m"
nipkow@69064
   296
  shows "norm(column i A) \<le> onorm((*v) A)"
ak2110@68833
   297
proof%unimportant -
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)
nipkow@69064
   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
nipkow@69064
   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
ak2110@68833
   307
lemma%important matrix_component_le_onorm:
lp15@67719
   308
  fixes A :: "real^'n^'m"
nipkow@69064
   309
  shows "\<bar>A $ i $ j\<bar> \<le> onorm((*v) A)"
ak2110@68833
   310
proof%unimportant -
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)
nipkow@69064
   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
ak2110@68833
   318
lemma%unimportant 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
ak2110@68833
   323
lemma%important onorm_le_matrix_component_sum:
lp15@67719
   324
  fixes A :: "real^'n^'m"
nipkow@69064
   325
  shows "onorm((*v) A) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar>)"
ak2110@68833
   326
proof%unimportant (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
ak2110@68833
   345
lemma%important 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"
nipkow@69064
   348
  shows "onorm((*v) A) \<le> real (CARD('m)) * real (CARD('n)) * B"
ak2110@68833
   349
proof%unimportant (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
ak2110@68833
   369
subsection%important \<open>lambda skolemization on cartesian products\<close>
hoelzl@37489
   370
ak2110@68833
   371
lemma%important 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")
ak2110@68833
   373
proof%unimportant -
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
ak2110@68833
   390
lemma%unimportant 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
ak2110@68833
   395
lemma%important 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"
ak2110@68833
   399
proof%unimportant -
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
nipkow@69064
   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)
nipkow@69064
   412
    finally show "onorm ((*v) (A - B)) < e" .
lp15@67719
   413
  qed (use B in auto)
lp15@67719
   414
qed
lp15@67719
   415
ak2110@68833
   416
lemma%unimportant 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
immler@68072
   419
wenzelm@60420
   420
text \<open>The same result in terms of square matrices.\<close>
hoelzl@37489
   421
lp15@68041
   422
wenzelm@60420
   423
text \<open>Considering an n-element vector as an n-by-1 or 1-by-n matrix.\<close>
hoelzl@37489
   424
ak2110@68833
   425
definition%unimportant "rowvector v = (\<chi> i j. (v$j))"
hoelzl@37489
   426
ak2110@68833
   427
definition%unimportant "columnvector v = (\<chi> i j. (v$i))"
hoelzl@37489
   428
ak2110@68833
   429
lemma%unimportant transpose_columnvector: "transpose(columnvector v) = rowvector v"
huffman@44136
   430
  by (simp add: transpose_def rowvector_def columnvector_def vec_eq_iff)
hoelzl@37489
   431
ak2110@68833
   432
lemma%unimportant transpose_rowvector: "transpose(rowvector v) = columnvector v"
huffman@44136
   433
  by (simp add: transpose_def columnvector_def rowvector_def vec_eq_iff)
hoelzl@37489
   434
ak2110@68833
   435
lemma%unimportant dot_rowvector_columnvector: "columnvector (A *v v) = A ** columnvector v"
hoelzl@37489
   436
  by (vector columnvector_def matrix_matrix_mult_def matrix_vector_mult_def)
hoelzl@37489
   437
ak2110@68833
   438
lemma%unimportant dot_matrix_product:
wenzelm@49644
   439
  "(x::real^'n) \<bullet> y = (((rowvector x ::real^'n^1) ** (columnvector y :: real^1^'n))$1)$1"
huffman@44136
   440
  by (vector matrix_matrix_mult_def rowvector_def columnvector_def inner_vec_def)
hoelzl@37489
   441
ak2110@68833
   442
lemma%unimportant dot_matrix_vector_mul:
hoelzl@37489
   443
  fixes A B :: "real ^'n ^'n" and x y :: "real ^'n"
hoelzl@37489
   444
  shows "(A *v x) \<bullet> (B *v y) =
hoelzl@37489
   445
      (((rowvector x :: real^'n^1) ** ((transpose A ** B) ** (columnvector y :: real ^1^'n)))$1)$1"
wenzelm@49644
   446
  unfolding dot_matrix_product transpose_columnvector[symmetric]
wenzelm@49644
   447
    dot_rowvector_columnvector matrix_transpose_mul matrix_mul_assoc ..
hoelzl@37489
   448
ak2110@68833
   449
lemma%unimportant infnorm_cart:"infnorm (x::real^'n) = Sup {\<bar>x$i\<bar> |i. i\<in>UNIV}"
hoelzl@50526
   450
  by (simp add: infnorm_def inner_axis Basis_vec_def) (metis (lifting) inner_axis real_inner_1_right)
hoelzl@37489
   451
ak2110@68833
   452
lemma%unimportant component_le_infnorm_cart: "\<bar>x$i\<bar> \<le> infnorm (x::real^'n)"
hoelzl@50526
   453
  using Basis_le_infnorm[of "axis i 1" x]
hoelzl@50526
   454
  by (simp add: Basis_vec_def axis_eq_axis inner_axis)
hoelzl@37489
   455
ak2110@68833
   456
lemma%unimportant continuous_component[continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. f x $ i)"
huffman@44647
   457
  unfolding continuous_def by (rule tendsto_vec_nth)
huffman@44213
   458
ak2110@68833
   459
lemma%unimportant continuous_on_component[continuous_intros]: "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. f x $ i)"
huffman@44647
   460
  unfolding continuous_on_def by (fast intro: tendsto_vec_nth)
huffman@44213
   461
ak2110@68833
   462
lemma%unimportant continuous_on_vec_lambda[continuous_intros]:
hoelzl@63334
   463
  "(\<And>i. continuous_on S (f i)) \<Longrightarrow> continuous_on S (\<lambda>x. \<chi> i. f i x)"
hoelzl@63334
   464
  unfolding continuous_on_def by (auto intro: tendsto_vec_lambda)
hoelzl@63334
   465
ak2110@68833
   466
lemma%unimportant closed_positive_orthant: "closed {x::real^'n. \<forall>i. 0 \<le>x$i}"
hoelzl@63332
   467
  by (simp add: Collect_all_eq closed_INT closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
huffman@44213
   468
ak2110@68833
   469
lemma%unimportant bounded_component_cart: "bounded s \<Longrightarrow> bounded ((\<lambda>x. x $ i) ` s)"
wenzelm@49644
   470
  unfolding bounded_def
wenzelm@49644
   471
  apply clarify
wenzelm@49644
   472
  apply (rule_tac x="x $ i" in exI)
wenzelm@49644
   473
  apply (rule_tac x="e" in exI)
wenzelm@49644
   474
  apply clarify
wenzelm@49644
   475
  apply (rule order_trans [OF dist_vec_nth_le], simp)
wenzelm@49644
   476
  done
hoelzl@37489
   477
ak2110@68833
   478
lemma%important compact_lemma_cart:
hoelzl@37489
   479
  fixes f :: "nat \<Rightarrow> 'a::heine_borel ^ 'n"
hoelzl@50998
   480
  assumes f: "bounded (range f)"
eberlm@66447
   481
  shows "\<exists>l r. strict_mono r \<and>
hoelzl@37489
   482
        (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) $ i) (l $ i) < e) sequentially)"
immler@62127
   483
    (is "?th d")
ak2110@68833
   484
proof%unimportant -
immler@62127
   485
  have "\<forall>d' \<subseteq> d. ?th d'"
immler@62127
   486
    by (rule compact_lemma_general[where unproj=vec_lambda])
immler@62127
   487
      (auto intro!: f bounded_component_cart simp: vec_lambda_eta)
immler@62127
   488
  then show "?th d" by simp
hoelzl@37489
   489
qed
hoelzl@37489
   490
huffman@44136
   491
instance vec :: (heine_borel, finite) heine_borel
hoelzl@37489
   492
proof
hoelzl@50998
   493
  fix f :: "nat \<Rightarrow> 'a ^ 'b"
hoelzl@50998
   494
  assume f: "bounded (range f)"
eberlm@66447
   495
  then obtain l r where r: "strict_mono r"
wenzelm@49644
   496
      and l: "\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>UNIV. dist (f (r n) $ i) (l $ i) < e) sequentially"
hoelzl@50998
   497
    using compact_lemma_cart [OF f] by blast
hoelzl@37489
   498
  let ?d = "UNIV::'b set"
hoelzl@37489
   499
  { fix e::real assume "e>0"
hoelzl@37489
   500
    hence "0 < e / (real_of_nat (card ?d))"
wenzelm@49644
   501
      using zero_less_card_finite divide_pos_pos[of e, of "real_of_nat (card ?d)"] by auto
hoelzl@37489
   502
    with l have "eventually (\<lambda>n. \<forall>i. dist (f (r n) $ i) (l $ i) < e / (real_of_nat (card ?d))) sequentially"
hoelzl@37489
   503
      by simp
hoelzl@37489
   504
    moreover
wenzelm@49644
   505
    { fix n
wenzelm@49644
   506
      assume n: "\<forall>i. dist (f (r n) $ i) (l $ i) < e / (real_of_nat (card ?d))"
hoelzl@37489
   507
      have "dist (f (r n)) l \<le> (\<Sum>i\<in>?d. dist (f (r n) $ i) (l $ i))"
nipkow@67155
   508
        unfolding dist_vec_def using zero_le_dist by (rule L2_set_le_sum)
hoelzl@37489
   509
      also have "\<dots> < (\<Sum>i\<in>?d. e / (real_of_nat (card ?d)))"
nipkow@64267
   510
        by (rule sum_strict_mono) (simp_all add: n)
hoelzl@37489
   511
      finally have "dist (f (r n)) l < e" by simp
hoelzl@37489
   512
    }
hoelzl@37489
   513
    ultimately have "eventually (\<lambda>n. dist (f (r n)) l < e) sequentially"
lp15@61810
   514
      by (rule eventually_mono)
hoelzl@37489
   515
  }
wenzelm@61973
   516
  hence "((f \<circ> r) \<longlongrightarrow> l) sequentially" unfolding o_def tendsto_iff by simp
eberlm@66447
   517
  with r show "\<exists>l r. strict_mono r \<and> ((f \<circ> r) \<longlongrightarrow> l) sequentially" by auto
hoelzl@37489
   518
qed
hoelzl@37489
   519
ak2110@68833
   520
lemma%unimportant interval_cart:
immler@54775
   521
  fixes a :: "real^'n"
immler@54775
   522
  shows "box a b = {x::real^'n. \<forall>i. a$i < x$i \<and> x$i < b$i}"
immler@56188
   523
    and "cbox a b = {x::real^'n. \<forall>i. a$i \<le> x$i \<and> x$i \<le> b$i}"
immler@56188
   524
  by (auto simp add: set_eq_iff less_vec_def less_eq_vec_def mem_box Basis_vec_def inner_axis)
hoelzl@37489
   525
ak2110@68833
   526
lemma%unimportant mem_box_cart:
immler@54775
   527
  fixes a :: "real^'n"
immler@54775
   528
  shows "x \<in> box a b \<longleftrightarrow> (\<forall>i. a$i < x$i \<and> x$i < b$i)"
immler@56188
   529
    and "x \<in> cbox a b \<longleftrightarrow> (\<forall>i. a$i \<le> x$i \<and> x$i \<le> b$i)"
wenzelm@49644
   530
  using interval_cart[of a b] by (auto simp add: set_eq_iff less_vec_def less_eq_vec_def)
hoelzl@37489
   531
ak2110@68833
   532
lemma%unimportant interval_eq_empty_cart:
wenzelm@49644
   533
  fixes a :: "real^'n"
immler@54775
   534
  shows "(box a b = {} \<longleftrightarrow> (\<exists>i. b$i \<le> a$i))" (is ?th1)
immler@56188
   535
    and "(cbox a b = {} \<longleftrightarrow> (\<exists>i. b$i < a$i))" (is ?th2)
wenzelm@49644
   536
proof -
immler@54775
   537
  { fix i x assume as:"b$i \<le> a$i" and x:"x\<in>box a b"
lp15@67673
   538
    hence "a $ i < x $ i \<and> x $ i < b $ i" unfolding mem_box_cart by auto
hoelzl@37489
   539
    hence "a$i < b$i" by auto
wenzelm@49644
   540
    hence False using as by auto }
hoelzl@37489
   541
  moreover
hoelzl@37489
   542
  { assume as:"\<forall>i. \<not> (b$i \<le> a$i)"
hoelzl@37489
   543
    let ?x = "(1/2) *\<^sub>R (a + b)"
hoelzl@37489
   544
    { fix i
hoelzl@37489
   545
      have "a$i < b$i" using as[THEN spec[where x=i]] by auto
hoelzl@37489
   546
      hence "a$i < ((1/2) *\<^sub>R (a+b)) $ i" "((1/2) *\<^sub>R (a+b)) $ i < b$i"
hoelzl@37489
   547
        unfolding vector_smult_component and vector_add_component
wenzelm@49644
   548
        by auto }
lp15@67673
   549
    hence "box a b \<noteq> {}" using mem_box_cart(1)[of "?x" a b] by auto }
hoelzl@37489
   550
  ultimately show ?th1 by blast
hoelzl@37489
   551
immler@56188
   552
  { fix i x assume as:"b$i < a$i" and x:"x\<in>cbox a b"
lp15@67673
   553
    hence "a $ i \<le> x $ i \<and> x $ i \<le> b $ i" unfolding mem_box_cart by auto
hoelzl@37489
   554
    hence "a$i \<le> b$i" by auto
wenzelm@49644
   555
    hence False using as by auto }
hoelzl@37489
   556
  moreover
hoelzl@37489
   557
  { assume as:"\<forall>i. \<not> (b$i < a$i)"
hoelzl@37489
   558
    let ?x = "(1/2) *\<^sub>R (a + b)"
hoelzl@37489
   559
    { fix i
hoelzl@37489
   560
      have "a$i \<le> b$i" using as[THEN spec[where x=i]] by auto
hoelzl@37489
   561
      hence "a$i \<le> ((1/2) *\<^sub>R (a+b)) $ i" "((1/2) *\<^sub>R (a+b)) $ i \<le> b$i"
hoelzl@37489
   562
        unfolding vector_smult_component and vector_add_component
wenzelm@49644
   563
        by auto }
lp15@67673
   564
    hence "cbox a b \<noteq> {}" using mem_box_cart(2)[of "?x" a b] by auto  }
hoelzl@37489
   565
  ultimately show ?th2 by blast
hoelzl@37489
   566
qed
hoelzl@37489
   567
ak2110@68833
   568
lemma%unimportant interval_ne_empty_cart:
wenzelm@49644
   569
  fixes a :: "real^'n"
immler@56188
   570
  shows "cbox a b \<noteq> {} \<longleftrightarrow> (\<forall>i. a$i \<le> b$i)"
immler@54775
   571
    and "box a b \<noteq> {} \<longleftrightarrow> (\<forall>i. a$i < b$i)"
hoelzl@37489
   572
  unfolding interval_eq_empty_cart[of a b] by (auto simp add: not_less not_le)
hoelzl@37489
   573
    (* BH: Why doesn't just "auto" work here? *)
hoelzl@37489
   574
ak2110@68833
   575
lemma%unimportant subset_interval_imp_cart:
wenzelm@49644
   576
  fixes a :: "real^'n"
immler@56188
   577
  shows "(\<forall>i. a$i \<le> c$i \<and> d$i \<le> b$i) \<Longrightarrow> cbox c d \<subseteq> cbox a b"
immler@56188
   578
    and "(\<forall>i. a$i < c$i \<and> d$i < b$i) \<Longrightarrow> cbox c d \<subseteq> box a b"
immler@56188
   579
    and "(\<forall>i. a$i \<le> c$i \<and> d$i \<le> b$i) \<Longrightarrow> box c d \<subseteq> cbox a b"
immler@54775
   580
    and "(\<forall>i. a$i \<le> c$i \<and> d$i \<le> b$i) \<Longrightarrow> box c d \<subseteq> box a b"
lp15@67673
   581
  unfolding subset_eq[unfolded Ball_def] unfolding mem_box_cart
hoelzl@37489
   582
  by (auto intro: order_trans less_le_trans le_less_trans less_imp_le) (* BH: Why doesn't just "auto" work here? *)
hoelzl@37489
   583
ak2110@68833
   584
lemma%unimportant interval_sing:
wenzelm@49644
   585
  fixes a :: "'a::linorder^'n"
wenzelm@49644
   586
  shows "{a .. a} = {a} \<and> {a<..<a} = {}"
wenzelm@49644
   587
  apply (auto simp add: set_eq_iff less_vec_def less_eq_vec_def vec_eq_iff)
wenzelm@49644
   588
  done
hoelzl@37489
   589
ak2110@68833
   590
lemma%unimportant subset_interval_cart:
wenzelm@49644
   591
  fixes a :: "real^'n"
immler@56188
   592
  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
   593
    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
   594
    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
   595
    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
   596
  using subset_box[of c d a b] by (simp_all add: Basis_vec_def inner_axis)
hoelzl@37489
   597
ak2110@68833
   598
lemma%unimportant disjoint_interval_cart:
wenzelm@49644
   599
  fixes a::"real^'n"
immler@56188
   600
  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
   601
    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
   602
    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
   603
    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
   604
  using disjoint_interval[of a b c d] by (simp_all add: Basis_vec_def inner_axis)
hoelzl@37489
   605
ak2110@68833
   606
lemma%unimportant Int_interval_cart:
immler@54775
   607
  fixes a :: "real^'n"
immler@56188
   608
  shows "cbox a b \<inter> cbox c d =  {(\<chi> i. max (a$i) (c$i)) .. (\<chi> i. min (b$i) (d$i))}"
lp15@63945
   609
  unfolding Int_interval
immler@56188
   610
  by (auto simp: mem_box less_eq_vec_def)
immler@56188
   611
    (auto simp: Basis_vec_def inner_axis)
hoelzl@37489
   612
ak2110@68833
   613
lemma%unimportant closed_interval_left_cart:
wenzelm@49644
   614
  fixes b :: "real^'n"
hoelzl@37489
   615
  shows "closed {x::real^'n. \<forall>i. x$i \<le> b$i}"
hoelzl@63332
   616
  by (simp add: Collect_all_eq closed_INT closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   617
ak2110@68833
   618
lemma%unimportant closed_interval_right_cart:
wenzelm@49644
   619
  fixes a::"real^'n"
hoelzl@37489
   620
  shows "closed {x::real^'n. \<forall>i. a$i \<le> x$i}"
hoelzl@63332
   621
  by (simp add: Collect_all_eq closed_INT closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   622
ak2110@68833
   623
lemma%unimportant is_interval_cart:
wenzelm@49644
   624
  "is_interval (s::(real^'n) set) \<longleftrightarrow>
wenzelm@49644
   625
    (\<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
   626
  by (simp add: is_interval_def Ball_def Basis_vec_def inner_axis imp_ex)
hoelzl@37489
   627
ak2110@68833
   628
lemma%unimportant closed_halfspace_component_le_cart: "closed {x::real^'n. x$i \<le> a}"
hoelzl@63332
   629
  by (simp add: closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   630
ak2110@68833
   631
lemma%unimportant closed_halfspace_component_ge_cart: "closed {x::real^'n. x$i \<ge> a}"
hoelzl@63332
   632
  by (simp add: closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   633
ak2110@68833
   634
lemma%unimportant open_halfspace_component_lt_cart: "open {x::real^'n. x$i < a}"
hoelzl@63332
   635
  by (simp add: open_Collect_less continuous_on_const continuous_on_id continuous_on_component)
wenzelm@49644
   636
ak2110@68833
   637
lemma%unimportant open_halfspace_component_gt_cart: "open {x::real^'n. x$i  > a}"
hoelzl@63332
   638
  by (simp add: open_Collect_less continuous_on_const continuous_on_id continuous_on_component)
hoelzl@37489
   639
ak2110@68833
   640
lemma%unimportant Lim_component_le_cart:
wenzelm@49644
   641
  fixes f :: "'a \<Rightarrow> real^'n"
wenzelm@61973
   642
  assumes "(f \<longlongrightarrow> l) net" "\<not> (trivial_limit net)"  "eventually (\<lambda>x. f x $i \<le> b) net"
hoelzl@37489
   643
  shows "l$i \<le> b"
hoelzl@50526
   644
  by (rule tendsto_le[OF assms(2) tendsto_const tendsto_vec_nth, OF assms(1, 3)])
hoelzl@37489
   645
ak2110@68833
   646
lemma%unimportant Lim_component_ge_cart:
wenzelm@49644
   647
  fixes f :: "'a \<Rightarrow> real^'n"
wenzelm@61973
   648
  assumes "(f \<longlongrightarrow> l) net"  "\<not> (trivial_limit net)"  "eventually (\<lambda>x. b \<le> (f x)$i) net"
hoelzl@37489
   649
  shows "b \<le> l$i"
hoelzl@50526
   650
  by (rule tendsto_le[OF assms(2) tendsto_vec_nth tendsto_const, OF assms(1, 3)])
hoelzl@37489
   651
ak2110@68833
   652
lemma%unimportant Lim_component_eq_cart:
wenzelm@49644
   653
  fixes f :: "'a \<Rightarrow> real^'n"
nipkow@69508
   654
  assumes net: "(f \<longlongrightarrow> l) net" "\<not> trivial_limit net" and ev:"eventually (\<lambda>x. f(x)$i = b) net"
hoelzl@37489
   655
  shows "l$i = b"
wenzelm@49644
   656
  using ev[unfolded order_eq_iff eventually_conj_iff] and
wenzelm@49644
   657
    Lim_component_ge_cart[OF net, of b i] and
hoelzl@37489
   658
    Lim_component_le_cart[OF net, of i b] by auto
hoelzl@37489
   659
ak2110@68833
   660
lemma%unimportant connected_ivt_component_cart:
wenzelm@49644
   661
  fixes x :: "real^'n"
wenzelm@49644
   662
  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
   663
  using connected_ivt_hyperplane[of s x y "axis k 1" a]
hoelzl@50526
   664
  by (auto simp add: inner_axis inner_commute)
hoelzl@37489
   665
ak2110@68833
   666
lemma%unimportant subspace_substandard_cart: "vec.subspace {x. (\<forall>i. P i \<longrightarrow> x$i = 0)}"
immler@68072
   667
  unfolding vec.subspace_def by auto
hoelzl@37489
   668
ak2110@68833
   669
lemma%important closed_substandard_cart:
huffman@44213
   670
  "closed {x::'a::real_normed_vector ^ 'n. \<forall>i. P i \<longrightarrow> x$i = 0}"
ak2110@68833
   671
proof%unimportant -
huffman@44213
   672
  { fix i::'n
huffman@44213
   673
    have "closed {x::'a ^ 'n. P i \<longrightarrow> x$i = 0}"
hoelzl@63332
   674
      by (cases "P i") (simp_all add: closed_Collect_eq continuous_on_const continuous_on_id continuous_on_component) }
huffman@44213
   675
  thus ?thesis
huffman@44213
   676
    unfolding Collect_all_eq by (simp add: closed_INT)
hoelzl@37489
   677
qed
hoelzl@37489
   678
ak2110@68833
   679
lemma%important dim_substandard_cart: "vec.dim {x::'a::field^'n. \<forall>i. i \<notin> d \<longrightarrow> x$i = 0} = card d"
immler@68072
   680
  (is "vec.dim ?A = _")
ak2110@68833
   681
proof%unimportant (rule vec.dim_unique)
immler@68072
   682
  let ?B = "((\<lambda>x. axis x 1) ` d)"
immler@68072
   683
  have subset_basis: "?B \<subseteq> cart_basis"
immler@68072
   684
    by (auto simp: cart_basis_def)
immler@68072
   685
  show "?B \<subseteq> ?A"
immler@68072
   686
    by (auto simp: axis_def)
immler@68072
   687
  show "vec.independent ((\<lambda>x. axis x 1) ` d)"
immler@68072
   688
    using subset_basis
immler@68072
   689
    by (rule vec.independent_mono[OF vec.independent_Basis])
immler@68072
   690
  have "x \<in> vec.span ?B" if "\<forall>i. i \<notin> d \<longrightarrow> x $ i = 0" for x::"'a^'n"
immler@68072
   691
  proof -
immler@68072
   692
    have "finite ?B"
immler@68072
   693
      using subset_basis finite_cart_basis
immler@68072
   694
      by (rule finite_subset)
immler@68072
   695
    have "x = (\<Sum>i\<in>UNIV. x $ i *s axis i 1)"
immler@68072
   696
      by (rule basis_expansion[symmetric])
immler@68072
   697
    also have "\<dots> = (\<Sum>i\<in>d. (x $ i) *s axis i 1)"
immler@68072
   698
      by (rule sum.mono_neutral_cong_right) (auto simp: that)
immler@68072
   699
    also have "\<dots> \<in> vec.span ?B"
immler@68072
   700
      by (simp add: vec.span_sum vec.span_clauses)
immler@68072
   701
    finally show "x \<in> vec.span ?B" .
immler@68072
   702
  qed
immler@68072
   703
  then show "?A \<subseteq> vec.span ?B" by auto
immler@68072
   704
qed (simp add: card_image inj_on_def axis_eq_axis)
immler@68072
   705
ak2110@68833
   706
lemma%unimportant dim_subset_UNIV_cart_gen:
immler@68072
   707
  fixes S :: "('a::field^'n) set"
immler@68072
   708
  shows "vec.dim S \<le> CARD('n)"
immler@68072
   709
  by (metis vec.dim_eq_full vec.dim_subset_UNIV vec.span_UNIV vec_dim_card)
hoelzl@37489
   710
ak2110@68833
   711
lemma%unimportant dim_subset_UNIV_cart:
lp15@67719
   712
  fixes S :: "(real^'n) set"
lp15@67719
   713
  shows "dim S \<le> CARD('n)"
immler@68072
   714
  using dim_subset_UNIV_cart_gen[of S] by (simp add: dim_vec_eq)
lp15@67719
   715
ak2110@68833
   716
lemma%unimportant affinity_inverses:
hoelzl@37489
   717
  assumes m0: "m \<noteq> (0::'a::field)"
wenzelm@61736
   718
  shows "(\<lambda>x. m *s x + c) \<circ> (\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) = id"
wenzelm@61736
   719
  "(\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) \<circ> (\<lambda>x. m *s x + c) = id"
hoelzl@37489
   720
  using m0
immler@68072
   721
  by (auto simp add: fun_eq_iff vector_add_ldistrib diff_conv_add_uminus simp del: add_uminus_conv_diff)
hoelzl@37489
   722
ak2110@68833
   723
lemma%important vector_affinity_eq:
hoelzl@37489
   724
  assumes m0: "(m::'a::field) \<noteq> 0"
hoelzl@37489
   725
  shows "m *s x + c = y \<longleftrightarrow> x = inverse m *s y + -(inverse m *s c)"
ak2110@68833
   726
proof%unimportant
hoelzl@37489
   727
  assume h: "m *s x + c = y"
hoelzl@37489
   728
  hence "m *s x = y - c" by (simp add: field_simps)
hoelzl@37489
   729
  hence "inverse m *s (m *s x) = inverse m *s (y - c)" by simp
hoelzl@37489
   730
  then show "x = inverse m *s y + - (inverse m *s c)"
hoelzl@37489
   731
    using m0 by (simp add: vector_smult_assoc vector_ssub_ldistrib)
hoelzl@37489
   732
next
hoelzl@37489
   733
  assume h: "x = inverse m *s y + - (inverse m *s c)"
haftmann@54230
   734
  show "m *s x + c = y" unfolding h
hoelzl@37489
   735
    using m0 by (simp add: vector_smult_assoc vector_ssub_ldistrib)
hoelzl@37489
   736
qed
hoelzl@37489
   737
ak2110@68833
   738
lemma%unimportant vector_eq_affinity:
wenzelm@49644
   739
    "(m::'a::field) \<noteq> 0 ==> (y = m *s x + c \<longleftrightarrow> inverse(m) *s y + -(inverse(m) *s c) = x)"
hoelzl@37489
   740
  using vector_affinity_eq[where m=m and x=x and y=y and c=c]
hoelzl@37489
   741
  by metis
hoelzl@37489
   742
ak2110@68833
   743
lemma%unimportant vector_cart:
hoelzl@50526
   744
  fixes f :: "real^'n \<Rightarrow> real"
hoelzl@50526
   745
  shows "(\<chi> i. f (axis i 1)) = (\<Sum>i\<in>Basis. f i *\<^sub>R i)"
hoelzl@50526
   746
  unfolding euclidean_eq_iff[where 'a="real^'n"]
hoelzl@50526
   747
  by simp (simp add: Basis_vec_def inner_axis)
hoelzl@63332
   748
ak2110@68833
   749
lemma%unimportant const_vector_cart:"((\<chi> i. d)::real^'n) = (\<Sum>i\<in>Basis. d *\<^sub>R i)"
hoelzl@50526
   750
  by (rule vector_cart)
wenzelm@49644
   751
ak2110@68833
   752
subsection%important "Convex Euclidean Space"
hoelzl@37489
   753
ak2110@68833
   754
lemma%unimportant Cart_1:"(1::real^'n) = \<Sum>Basis"
hoelzl@50526
   755
  using const_vector_cart[of 1] by (simp add: one_vec_def)
hoelzl@37489
   756
hoelzl@37489
   757
declare vector_add_ldistrib[simp] vector_ssub_ldistrib[simp] vector_smult_assoc[simp] vector_smult_rneg[simp]
hoelzl@37489
   758
declare vector_sadd_rdistrib[simp] vector_sub_rdistrib[simp]
hoelzl@37489
   759
ak2110@68833
   760
lemmas%unimportant vector_component_simps = vector_minus_component vector_smult_component vector_add_component less_eq_vec_def vec_lambda_beta vector_uminus_component
hoelzl@37489
   761
ak2110@68833
   762
lemma%unimportant convex_box_cart:
hoelzl@37489
   763
  assumes "\<And>i. convex {x. P i x}"
hoelzl@37489
   764
  shows "convex {x. \<forall>i. P i (x$i)}"
hoelzl@37489
   765
  using assms unfolding convex_def by auto
hoelzl@37489
   766
ak2110@68833
   767
lemma%unimportant convex_positive_orthant_cart: "convex {x::real^'n. (\<forall>i. 0 \<le> x$i)}"
hoelzl@63334
   768
  by (rule convex_box_cart) (simp add: atLeast_def[symmetric])
hoelzl@37489
   769
ak2110@68833
   770
lemma%unimportant unit_interval_convex_hull_cart:
immler@56188
   771
  "cbox (0::real^'n) 1 = convex hull {x. \<forall>i. (x$i = 0) \<or> (x$i = 1)}"
immler@56188
   772
  unfolding Cart_1 unit_interval_convex_hull[where 'a="real^'n"] box_real[symmetric]
hoelzl@50526
   773
  by (rule arg_cong[where f="\<lambda>x. convex hull x"]) (simp add: Basis_vec_def inner_axis)
hoelzl@37489
   774
ak2110@68833
   775
lemma%important cube_convex_hull_cart:
wenzelm@49644
   776
  assumes "0 < d"
wenzelm@49644
   777
  obtains s::"(real^'n) set"
immler@56188
   778
    where "finite s" "cbox (x - (\<chi> i. d)) (x + (\<chi> i. d)) = convex hull s"
ak2110@68833
   779
proof%unimportant -
wenzelm@55522
   780
  from assms obtain s where "finite s"
nipkow@69064
   781
    and "cbox (x - sum ((*\<^sub>R) d) Basis) (x + sum ((*\<^sub>R) d) Basis) = convex hull s"
wenzelm@55522
   782
    by (rule cube_convex_hull)
wenzelm@55522
   783
  with that[of s] show thesis
wenzelm@55522
   784
    by (simp add: const_vector_cart)
hoelzl@37489
   785
qed
hoelzl@37489
   786
hoelzl@37489
   787
ak2110@68833
   788
subsection%important "Derivative"
hoelzl@37489
   789
ak2110@68833
   790
definition%important "jacobian f net = matrix(frechet_derivative f net)"
hoelzl@37489
   791
ak2110@68833
   792
lemma%important jacobian_works:
wenzelm@49644
   793
  "(f::(real^'a) \<Rightarrow> (real^'b)) differentiable net \<longleftrightarrow>
lp15@67986
   794
    (f has_derivative (\<lambda>h. (jacobian f net) *v h)) net" (is "?lhs = ?rhs")
ak2110@68833
   795
proof%unimportant
lp15@67986
   796
  assume ?lhs then show ?rhs
lp15@67986
   797
    by (simp add: frechet_derivative_works has_derivative_linear jacobian_def)
lp15@67986
   798
next
lp15@67986
   799
  assume ?rhs then show ?lhs
lp15@67986
   800
    by (rule differentiableI)
lp15@67986
   801
qed
hoelzl@37489
   802
hoelzl@37489
   803
ak2110@68833
   804
subsection%important \<open>Component of the differential must be zero if it exists at a local
nipkow@67968
   805
  maximum or minimum for that corresponding component\<close>
hoelzl@37489
   806
ak2110@68833
   807
lemma%important differential_zero_maxmin_cart:
wenzelm@49644
   808
  fixes f::"real^'a \<Rightarrow> real^'b"
wenzelm@49644
   809
  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
   810
    "f differentiable (at x)"
hoelzl@50526
   811
  shows "jacobian f (at x) $ k = 0"
hoelzl@50526
   812
  using differential_zero_maxmin_component[of "axis k 1" e x f] assms
hoelzl@50526
   813
    vector_cart[of "\<lambda>j. frechet_derivative f (at x) j $ k"]
hoelzl@50526
   814
  by (simp add: Basis_vec_def axis_eq_axis inner_axis jacobian_def matrix_def)
wenzelm@49644
   815
wenzelm@69597
   816
subsection%unimportant \<open>Lemmas for working on \<^typ>\<open>real^1\<close>\<close>
hoelzl@37489
   817
hoelzl@37489
   818
lemma forall_1[simp]: "(\<forall>i::1. P i) \<longleftrightarrow> P 1"
wenzelm@49644
   819
  by (metis (full_types) num1_eq_iff)
hoelzl@37489
   820
hoelzl@37489
   821
lemma ex_1[simp]: "(\<exists>x::1. P x) \<longleftrightarrow> P 1"
wenzelm@49644
   822
  by auto (metis (full_types) num1_eq_iff)
hoelzl@37489
   823
hoelzl@37489
   824
lemma exhaust_2:
wenzelm@49644
   825
  fixes x :: 2
wenzelm@49644
   826
  shows "x = 1 \<or> x = 2"
hoelzl@37489
   827
proof (induct x)
hoelzl@37489
   828
  case (of_int z)
lp15@67979
   829
  then have "0 \<le> z" and "z < 2" by simp_all
hoelzl@37489
   830
  then have "z = 0 | z = 1" by arith
hoelzl@37489
   831
  then show ?case by auto
hoelzl@37489
   832
qed
hoelzl@37489
   833
hoelzl@37489
   834
lemma forall_2: "(\<forall>i::2. P i) \<longleftrightarrow> P 1 \<and> P 2"
hoelzl@37489
   835
  by (metis exhaust_2)
hoelzl@37489
   836
hoelzl@37489
   837
lemma exhaust_3:
wenzelm@49644
   838
  fixes x :: 3
wenzelm@49644
   839
  shows "x = 1 \<or> x = 2 \<or> x = 3"
hoelzl@37489
   840
proof (induct x)
hoelzl@37489
   841
  case (of_int z)
lp15@67979
   842
  then have "0 \<le> z" and "z < 3" by simp_all
hoelzl@37489
   843
  then have "z = 0 \<or> z = 1 \<or> z = 2" by arith
hoelzl@37489
   844
  then show ?case by auto
hoelzl@37489
   845
qed
hoelzl@37489
   846
hoelzl@37489
   847
lemma forall_3: "(\<forall>i::3. P i) \<longleftrightarrow> P 1 \<and> P 2 \<and> P 3"
hoelzl@37489
   848
  by (metis exhaust_3)
hoelzl@37489
   849
hoelzl@37489
   850
lemma UNIV_1 [simp]: "UNIV = {1::1}"
hoelzl@37489
   851
  by (auto simp add: num1_eq_iff)
hoelzl@37489
   852
hoelzl@37489
   853
lemma UNIV_2: "UNIV = {1::2, 2::2}"
hoelzl@37489
   854
  using exhaust_2 by auto
hoelzl@37489
   855
hoelzl@37489
   856
lemma UNIV_3: "UNIV = {1::3, 2::3, 3::3}"
hoelzl@37489
   857
  using exhaust_3 by auto
hoelzl@37489
   858
nipkow@64267
   859
lemma sum_1: "sum f (UNIV::1 set) = f 1"
hoelzl@37489
   860
  unfolding UNIV_1 by simp
hoelzl@37489
   861
nipkow@64267
   862
lemma sum_2: "sum f (UNIV::2 set) = f 1 + f 2"
hoelzl@37489
   863
  unfolding UNIV_2 by simp
hoelzl@37489
   864
nipkow@64267
   865
lemma sum_3: "sum f (UNIV::3 set) = f 1 + f 2 + f 3"
haftmann@57514
   866
  unfolding UNIV_3 by (simp add: ac_simps)
hoelzl@37489
   867
lp15@67979
   868
lemma num1_eqI:
lp15@67979
   869
  fixes a::num1 shows "a = b"
lp15@67979
   870
  by (metis (full_types) UNIV_1 UNIV_I empty_iff insert_iff)
lp15@67979
   871
lp15@67979
   872
lemma num1_eq1 [simp]:
lp15@67979
   873
  fixes a::num1 shows "a = 1"
lp15@67979
   874
  by (rule num1_eqI)
lp15@67979
   875
wenzelm@49644
   876
instantiation num1 :: cart_one
wenzelm@49644
   877
begin
wenzelm@49644
   878
wenzelm@49644
   879
instance
wenzelm@49644
   880
proof
hoelzl@37489
   881
  show "CARD(1) = Suc 0" by auto
wenzelm@49644
   882
qed
wenzelm@49644
   883
wenzelm@49644
   884
end
hoelzl@37489
   885
lp15@67979
   886
instantiation num1 :: linorder begin
lp15@67979
   887
definition "a < b \<longleftrightarrow> Rep_num1 a < Rep_num1 b"
lp15@67979
   888
definition "a \<le> b \<longleftrightarrow> Rep_num1 a \<le> Rep_num1 b"
lp15@67979
   889
instance
lp15@67979
   890
  by intro_classes (auto simp: less_eq_num1_def less_num1_def intro: num1_eqI)
lp15@67979
   891
end
lp15@67979
   892
lp15@67979
   893
instance num1 :: wellorder
lp15@67979
   894
  by intro_classes (auto simp: less_eq_num1_def less_num1_def)
lp15@67979
   895
ak2110@68833
   896
subsection%unimportant\<open>The collapse of the general concepts to dimension one\<close>
hoelzl@37489
   897
hoelzl@37489
   898
lemma vector_one: "(x::'a ^1) = (\<chi> i. (x$1))"
huffman@44136
   899
  by (simp add: vec_eq_iff)
hoelzl@37489
   900
hoelzl@37489
   901
lemma forall_one: "(\<forall>(x::'a ^1). P x) \<longleftrightarrow> (\<forall>x. P(\<chi> i. x))"
hoelzl@37489
   902
  apply auto
hoelzl@37489
   903
  apply (erule_tac x= "x$1" in allE)
hoelzl@37489
   904
  apply (simp only: vector_one[symmetric])
hoelzl@37489
   905
  done
hoelzl@37489
   906
hoelzl@37489
   907
lemma norm_vector_1: "norm (x :: _^1) = norm (x$1)"
huffman@44136
   908
  by (simp add: norm_vec_def)
hoelzl@37489
   909
lp15@67979
   910
lemma dist_vector_1:
lp15@67979
   911
  fixes x :: "'a::real_normed_vector^1"
lp15@67979
   912
  shows "dist x y = dist (x$1) (y$1)"
lp15@67979
   913
  by (simp add: dist_norm norm_vector_1)
lp15@67979
   914
wenzelm@61945
   915
lemma norm_real: "norm(x::real ^ 1) = \<bar>x$1\<bar>"
hoelzl@37489
   916
  by (simp add: norm_vector_1)
hoelzl@37489
   917
wenzelm@61945
   918
lemma dist_real: "dist(x::real ^ 1) y = \<bar>(x$1) - (y$1)\<bar>"
hoelzl@37489
   919
  by (auto simp add: norm_real dist_norm)
hoelzl@37489
   920
ak2110@68833
   921
subsection%important\<open> Rank of a matrix\<close>
lp15@67986
   922
lp15@67986
   923
text\<open>Equivalence of row and column rank is taken from George Mackiw's paper, Mathematics Magazine 1995, p. 285.\<close>
lp15@67986
   924
ak2110@68833
   925
lemma%unimportant matrix_vector_mult_in_columnspace_gen:
immler@68072
   926
  fixes A :: "'a::field^'n^'m"
immler@68072
   927
  shows "(A *v x) \<in> vec.span(columns A)"
immler@68072
   928
  apply (simp add: matrix_vector_column columns_def transpose_def column_def)
immler@68072
   929
  apply (intro vec.span_sum vec.span_scale)
immler@68072
   930
  apply (force intro: vec.span_base)
immler@68072
   931
  done
immler@68072
   932
ak2110@68833
   933
lemma%unimportant matrix_vector_mult_in_columnspace:
lp15@67986
   934
  fixes A :: "real^'n^'m"
lp15@67986
   935
  shows "(A *v x) \<in> span(columns A)"
immler@68072
   936
  using matrix_vector_mult_in_columnspace_gen[of A x] by (simp add: span_vec_eq)
lp15@67986
   937
ak2110@68833
   938
lemma%important orthogonal_nullspace_rowspace:
lp15@67986
   939
  fixes A :: "real^'n^'m"
lp15@67986
   940
  assumes 0: "A *v x = 0" and y: "y \<in> span(rows A)"
lp15@67986
   941
  shows "orthogonal x y"
lp15@68077
   942
  using y
ak2110@68833
   943
proof%unimportant (induction rule: span_induct)
lp15@68077
   944
  case base
lp15@68077
   945
  then show ?case
lp15@67986
   946
    by (simp add: subspace_orthogonal_to_vector)
lp15@67986
   947
next
lp15@68077
   948
  case (step v)
lp15@67986
   949
  then obtain i where "v = row i A"
lp15@67986
   950
    by (auto simp: rows_def)
lp15@68077
   951
  with 0 show ?case
lp15@67986
   952
    unfolding orthogonal_def inner_vec_def matrix_vector_mult_def row_def
lp15@67986
   953
    by (simp add: mult.commute) (metis (no_types) vec_lambda_beta zero_index)
lp15@67986
   954
qed
lp15@67986
   955
ak2110@68833
   956
lemma%unimportant nullspace_inter_rowspace:
lp15@67986
   957
  fixes A :: "real^'n^'m"
lp15@67986
   958
  shows "A *v x = 0 \<and> x \<in> span(rows A) \<longleftrightarrow> x = 0"
immler@68072
   959
  using orthogonal_nullspace_rowspace orthogonal_self span_zero matrix_vector_mult_0_right
immler@68072
   960
  by blast
lp15@67986
   961
ak2110@68833
   962
lemma%unimportant matrix_vector_mul_injective_on_rowspace:
lp15@67986
   963
  fixes A :: "real^'n^'m"
lp15@67986
   964
  shows "\<lbrakk>A *v x = A *v y; x \<in> span(rows A); y \<in> span(rows A)\<rbrakk> \<Longrightarrow> x = y"
lp15@67986
   965
  using nullspace_inter_rowspace [of A "x-y"]
immler@68072
   966
  by (metis diff_eq_diff_eq diff_self matrix_vector_mult_diff_distrib span_diff)
lp15@67986
   967
ak2110@68833
   968
definition%important rank :: "'a::field^'n^'m=>nat"
immler@68072
   969
  where row_rank_def_gen: "rank A \<equiv> vec.dim(rows A)"
immler@68072
   970
ak2110@68833
   971
lemma%important row_rank_def: "rank A = dim (rows A)" for A::"real^'n^'m"
ak2110@68833
   972
  by%unimportant (auto simp: row_rank_def_gen dim_vec_eq)
lp15@67986
   973
ak2110@68833
   974
lemma%important dim_rows_le_dim_columns:
lp15@67986
   975
  fixes A :: "real^'n^'m"
lp15@67986
   976
  shows "dim(rows A) \<le> dim(columns A)"
ak2110@68833
   977
proof%unimportant -
lp15@67986
   978
  have "dim (span (rows A)) \<le> dim (span (columns A))"
lp15@67986
   979
  proof -
lp15@67986
   980
    obtain B where "independent B" "span(rows A) \<subseteq> span B"
lp15@67986
   981
              and B: "B \<subseteq> span(rows A)""card B = dim (span(rows A))"
immler@68074
   982
      using basis_exists [of "span(rows A)"] by metis
lp15@67986
   983
    with span_subspace have eq: "span B = span(rows A)"
lp15@67986
   984
      by auto
nipkow@69064
   985
    then have inj: "inj_on ((*v) A) (span B)"
immler@68072
   986
      by (simp add: inj_on_def matrix_vector_mul_injective_on_rowspace)
nipkow@69064
   987
    then have ind: "independent ((*v) A ` B)"
immler@68072
   988
      by (rule linear_independent_injective_image [OF Finite_Cartesian_Product.matrix_vector_mul_linear \<open>independent B\<close>])
nipkow@69064
   989
    have "dim (span (rows A)) \<le> card ((*v) A ` B)"
immler@68072
   990
      unfolding B(2)[symmetric]
immler@68072
   991
      using inj
immler@68072
   992
      by (auto simp: card_image inj_on_subset span_superset)
immler@68072
   993
    also have "\<dots> \<le> dim (span (columns A))"
immler@68072
   994
      using _ ind
immler@68072
   995
      by (rule independent_card_le_dim) (auto intro!: matrix_vector_mult_in_columnspace)
immler@68072
   996
    finally show ?thesis .
lp15@67986
   997
  qed
lp15@67986
   998
  then show ?thesis
immler@68072
   999
    by (simp add: dim_span)
lp15@67986
  1000
qed
lp15@67986
  1001
ak2110@68833
  1002
lemma%unimportant column_rank_def:
lp15@67986
  1003
  fixes A :: "real^'n^'m"
immler@68072
  1004
  shows "rank A = dim(columns A)"
immler@68072
  1005
  unfolding row_rank_def
immler@68072
  1006
  by (metis columns_transpose dim_rows_le_dim_columns le_antisym rows_transpose)
lp15@67986
  1007
ak2110@68833
  1008
lemma%unimportant rank_transpose:
lp15@67986
  1009
  fixes A :: "real^'n^'m"
lp15@67986
  1010
  shows "rank(transpose A) = rank A"
immler@68072
  1011
  by (metis column_rank_def row_rank_def rows_transpose)
lp15@67986
  1012
ak2110@68833
  1013
lemma%unimportant matrix_vector_mult_basis:
lp15@67986
  1014
  fixes A :: "real^'n^'m"
lp15@67986
  1015
  shows "A *v (axis k 1) = column k A"
lp15@67986
  1016
  by (simp add: cart_eq_inner_axis column_def matrix_mult_dot)
lp15@67986
  1017
ak2110@68833
  1018
lemma%unimportant columns_image_basis:
lp15@67986
  1019
  fixes A :: "real^'n^'m"
nipkow@69064
  1020
  shows "columns A = (*v) A ` (range (\<lambda>i. axis i 1))"
lp15@67986
  1021
  by (force simp: columns_def matrix_vector_mult_basis [symmetric])
lp15@67986
  1022
ak2110@68833
  1023
lemma%important rank_dim_range:
lp15@67986
  1024
  fixes A :: "real^'n^'m"
lp15@67986
  1025
  shows "rank A = dim(range (\<lambda>x. A *v x))"
immler@68072
  1026
  unfolding column_rank_def
ak2110@68833
  1027
proof%unimportant (rule span_eq_dim)
nipkow@69064
  1028
  have "span (columns A) \<subseteq> span (range ((*v) A))" (is "?l \<subseteq> ?r")
immler@68072
  1029
    by (simp add: columns_image_basis image_subsetI span_mono)
immler@68072
  1030
  then show "?l = ?r"
immler@68072
  1031
    by (metis (no_types, lifting) image_subset_iff matrix_vector_mult_in_columnspace
immler@68072
  1032
        span_eq span_span)
lp15@67986
  1033
qed
lp15@67986
  1034
ak2110@68833
  1035
lemma%unimportant rank_bound:
lp15@67986
  1036
  fixes A :: "real^'n^'m"
lp15@67986
  1037
  shows "rank A \<le> min CARD('m) (CARD('n))"
immler@68072
  1038
  by (metis (mono_tags, lifting) dim_subset_UNIV_cart min.bounded_iff
immler@68072
  1039
      column_rank_def row_rank_def)
lp15@67986
  1040
ak2110@68833
  1041
lemma%unimportant full_rank_injective:
lp15@67986
  1042
  fixes A :: "real^'n^'m"
nipkow@69064
  1043
  shows "rank A = CARD('n) \<longleftrightarrow> inj ((*v) A)"
immler@68072
  1044
  by (simp add: matrix_left_invertible_injective [symmetric] matrix_left_invertible_span_rows row_rank_def
immler@68072
  1045
      dim_eq_full [symmetric] card_cart_basis vec.dimension_def)
lp15@67986
  1046
ak2110@68833
  1047
lemma%unimportant full_rank_surjective:
lp15@67986
  1048
  fixes A :: "real^'n^'m"
nipkow@69064
  1049
  shows "rank A = CARD('m) \<longleftrightarrow> surj ((*v) A)"
lp15@67986
  1050
  by (simp add: matrix_right_invertible_surjective [symmetric] left_invertible_transpose [symmetric]
lp15@67986
  1051
                matrix_left_invertible_injective full_rank_injective [symmetric] rank_transpose)
lp15@67986
  1052
ak2110@68833
  1053
lemma%unimportant rank_I: "rank(mat 1::real^'n^'n) = CARD('n)"
lp15@67986
  1054
  by (simp add: full_rank_injective inj_on_def)
lp15@67986
  1055
ak2110@68833
  1056
lemma%unimportant less_rank_noninjective:
lp15@67986
  1057
  fixes A :: "real^'n^'m"
nipkow@69064
  1058
  shows "rank A < CARD('n) \<longleftrightarrow> \<not> inj ((*v) A)"
lp15@67986
  1059
using less_le rank_bound by (auto simp: full_rank_injective [symmetric])
lp15@67986
  1060
ak2110@68833
  1061
lemma%unimportant matrix_nonfull_linear_equations_eq:
lp15@67986
  1062
  fixes A :: "real^'n^'m"
nipkow@69508
  1063
  shows "(\<exists>x. (x \<noteq> 0) \<and> A *v x = 0) \<longleftrightarrow> rank A \<noteq> CARD('n)"
lp15@67986
  1064
  by (meson matrix_left_invertible_injective full_rank_injective matrix_left_invertible_ker)
lp15@67986
  1065
ak2110@68833
  1066
lemma%unimportant rank_eq_0: "rank A = 0 \<longleftrightarrow> A = 0" and rank_0 [simp]: "rank (0::real^'n^'m) = 0"
immler@68072
  1067
  for A :: "real^'n^'m"
lp15@67986
  1068
  by (auto simp: rank_dim_range matrix_eq)
lp15@67986
  1069
ak2110@68833
  1070
lemma%important rank_mul_le_right:
lp15@67986
  1071
  fixes A :: "real^'n^'m" and B :: "real^'p^'n"
lp15@67986
  1072
  shows "rank(A ** B) \<le> rank B"
ak2110@68833
  1073
proof%unimportant -
nipkow@69064
  1074
  have "rank(A ** B) \<le> dim ((*v) A ` range ((*v) B))"
lp15@67986
  1075
    by (auto simp: rank_dim_range image_comp o_def matrix_vector_mul_assoc)
lp15@67986
  1076
  also have "\<dots> \<le> rank B"
immler@68072
  1077
    by (simp add: rank_dim_range dim_image_le)
lp15@67986
  1078
  finally show ?thesis .
lp15@67986
  1079
qed
lp15@67986
  1080
ak2110@68833
  1081
lemma%unimportant rank_mul_le_left:
lp15@67986
  1082
  fixes A :: "real^'n^'m" and B :: "real^'p^'n"
lp15@67986
  1083
  shows "rank(A ** B) \<le> rank A"
lp15@67986
  1084
  by (metis matrix_transpose_mul rank_mul_le_right rank_transpose)
lp15@67986
  1085
wenzelm@69597
  1086
subsection%unimportant\<open>Routine results connecting the types \<^typ>\<open>real^1\<close> and \<^typ>\<open>real\<close>\<close>
lp15@67981
  1087
lp15@67981
  1088
lemma vector_one_nth [simp]:
lp15@67981
  1089
  fixes x :: "'a^1" shows "vec (x $ 1) = x"
lp15@67981
  1090
  by (metis vec_def vector_one)
lp15@67981
  1091
lp15@67981
  1092
lemma vec_cbox_1_eq [simp]:
lp15@67981
  1093
  shows "vec ` cbox u v = cbox (vec u) (vec v ::real^1)"
lp15@67981
  1094
  by (force simp: Basis_vec_def cart_eq_inner_axis [symmetric] mem_box)
lp15@67981
  1095
lp15@67981
  1096
lemma vec_nth_cbox_1_eq [simp]:
lp15@67981
  1097
  fixes u v :: "'a::euclidean_space^1"
lp15@67981
  1098
  shows "(\<lambda>x. x $ 1) ` cbox u v = cbox (u$1) (v$1)"
lp15@67981
  1099
    by (auto simp: Basis_vec_def cart_eq_inner_axis [symmetric] mem_box image_iff Bex_def inner_axis) (metis vec_component)
lp15@67981
  1100
lp15@67981
  1101
lemma vec_nth_1_iff_cbox [simp]:
lp15@67981
  1102
  fixes a b :: "'a::euclidean_space"
lp15@67981
  1103
  shows "(\<lambda>x::'a^1. x $ 1) ` S = cbox a b \<longleftrightarrow> S = cbox (vec a) (vec b)"
lp15@67981
  1104
    (is "?lhs = ?rhs")
lp15@67981
  1105
proof
lp15@67981
  1106
  assume L: ?lhs show ?rhs
lp15@67981
  1107
  proof (intro equalityI subsetI)
lp15@67981
  1108
    fix x 
lp15@67981
  1109
    assume "x \<in> S"
lp15@67981
  1110
    then have "x $ 1 \<in> (\<lambda>v. v $ (1::1)) ` cbox (vec a) (vec b)"
lp15@67981
  1111
      using L by auto
lp15@67981
  1112
    then show "x \<in> cbox (vec a) (vec b)"
lp15@67981
  1113
      by (metis (no_types, lifting) imageE vector_one_nth)
lp15@67981
  1114
  next
lp15@67981
  1115
    fix x :: "'a^1"
lp15@67981
  1116
    assume "x \<in> cbox (vec a) (vec b)"
lp15@67981
  1117
    then show "x \<in> S"
lp15@67981
  1118
      by (metis (no_types, lifting) L imageE imageI vec_component vec_nth_cbox_1_eq vector_one_nth)
lp15@67981
  1119
  qed
lp15@67981
  1120
qed simp
wenzelm@49644
  1121
lp15@67979
  1122
lemma tendsto_at_within_vector_1:
lp15@67979
  1123
  fixes S :: "'a :: metric_space set"
lp15@67979
  1124
  assumes "(f \<longlongrightarrow> fx) (at x within S)"
lp15@67979
  1125
  shows "((\<lambda>y::'a^1. \<chi> i. f (y $ 1)) \<longlongrightarrow> (vec fx::'a^1)) (at (vec x) within vec ` S)"
lp15@67979
  1126
proof (rule topological_tendstoI)
lp15@67979
  1127
  fix T :: "('a^1) set"
lp15@67979
  1128
  assume "open T" "vec fx \<in> T"
lp15@67979
  1129
  have "\<forall>\<^sub>F x in at x within S. f x \<in> (\<lambda>x. x $ 1) ` T"
lp15@67979
  1130
    using \<open>open T\<close> \<open>vec fx \<in> T\<close> assms open_image_vec_nth tendsto_def by fastforce
lp15@67979
  1131
  then show "\<forall>\<^sub>F x::'a^1 in at (vec x) within vec ` S. (\<chi> i. f (x $ 1)) \<in> T"
lp15@67979
  1132
    unfolding eventually_at dist_norm [symmetric]
lp15@67979
  1133
    by (rule ex_forward)
lp15@67979
  1134
       (use \<open>open T\<close> in 
lp15@67979
  1135
         \<open>fastforce simp: dist_norm dist_vec_def L2_set_def image_iff vector_one open_vec_def\<close>)
lp15@67979
  1136
qed
lp15@67979
  1137
lp15@67979
  1138
lemma has_derivative_vector_1:
lp15@67979
  1139
  assumes der_g: "(g has_derivative (\<lambda>x. x * g' a)) (at a within S)"
nipkow@69064
  1140
  shows "((\<lambda>x. vec (g (x $ 1))) has_derivative (*\<^sub>R) (g' a))
lp15@67979
  1141
         (at ((vec a)::real^1) within vec ` S)"
lp15@67979
  1142
    using der_g
lp15@67979
  1143
    apply (auto simp: Deriv.has_derivative_within bounded_linear_scaleR_right norm_vector_1)
lp15@67979
  1144
    apply (drule tendsto_at_within_vector_1, vector)
lp15@67979
  1145
    apply (auto simp: algebra_simps eventually_at tendsto_def)
lp15@67979
  1146
    done
lp15@67979
  1147
lp15@67979
  1148
ak2110@68833
  1149
subsection%unimportant\<open>Explicit vector construction from lists\<close>
hoelzl@37489
  1150
hoelzl@43995
  1151
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
  1152
lp15@68054
  1153
lemma vector_1 [simp]: "(vector[x]) $1 = x"
hoelzl@37489
  1154
  unfolding vector_def by simp
hoelzl@37489
  1155
lp15@68054
  1156
lemma vector_2 [simp]: "(vector[x,y]) $1 = x" "(vector[x,y] :: 'a^2)$2 = (y::'a::zero)"
hoelzl@37489
  1157
  unfolding vector_def by simp_all
hoelzl@37489
  1158
lp15@68054
  1159
lemma vector_3 [simp]:
hoelzl@37489
  1160
 "(vector [x,y,z] ::('a::zero)^3)$1 = x"
hoelzl@37489
  1161
 "(vector [x,y,z] ::('a::zero)^3)$2 = y"
hoelzl@37489
  1162
 "(vector [x,y,z] ::('a::zero)^3)$3 = z"
hoelzl@37489
  1163
  unfolding vector_def by simp_all
hoelzl@37489
  1164
hoelzl@37489
  1165
lemma forall_vector_1: "(\<forall>v::'a::zero^1. P v) \<longleftrightarrow> (\<forall>x. P(vector[x]))"
lp15@67719
  1166
  by (metis vector_1 vector_one)
hoelzl@37489
  1167
hoelzl@37489
  1168
lemma forall_vector_2: "(\<forall>v::'a::zero^2. P v) \<longleftrightarrow> (\<forall>x y. P(vector[x, y]))"
hoelzl@37489
  1169
  apply auto
hoelzl@37489
  1170
  apply (erule_tac x="v$1" in allE)
hoelzl@37489
  1171
  apply (erule_tac x="v$2" in allE)
hoelzl@37489
  1172
  apply (subgoal_tac "vector [v$1, v$2] = v")
hoelzl@37489
  1173
  apply simp
hoelzl@37489
  1174
  apply (vector vector_def)
hoelzl@37489
  1175
  apply (simp add: forall_2)
hoelzl@37489
  1176
  done
hoelzl@37489
  1177
hoelzl@37489
  1178
lemma forall_vector_3: "(\<forall>v::'a::zero^3. P v) \<longleftrightarrow> (\<forall>x y z. P(vector[x, y, z]))"
hoelzl@37489
  1179
  apply auto
hoelzl@37489
  1180
  apply (erule_tac x="v$1" in allE)
hoelzl@37489
  1181
  apply (erule_tac x="v$2" in allE)
hoelzl@37489
  1182
  apply (erule_tac x="v$3" in allE)
hoelzl@37489
  1183
  apply (subgoal_tac "vector [v$1, v$2, v$3] = v")
hoelzl@37489
  1184
  apply simp
hoelzl@37489
  1185
  apply (vector vector_def)
hoelzl@37489
  1186
  apply (simp add: forall_3)
hoelzl@37489
  1187
  done
hoelzl@37489
  1188
hoelzl@37489
  1189
lemma bounded_linear_component_cart[intro]: "bounded_linear (\<lambda>x::real^'n. x $ k)"
lp15@68062
  1190
  apply (rule bounded_linear_intro[where K=1])
hoelzl@37489
  1191
  using component_le_norm_cart[of _ k] unfolding real_norm_def by auto
hoelzl@37489
  1192
hoelzl@37489
  1193
lemma interval_split_cart:
hoelzl@37489
  1194
  "{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
  1195
  "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
  1196
  apply (rule_tac[!] set_eqI)
lp15@67673
  1197
  unfolding Int_iff mem_box_cart mem_Collect_eq interval_cbox_cart
wenzelm@49644
  1198
  unfolding vec_lambda_beta
wenzelm@49644
  1199
  by auto
hoelzl@37489
  1200
immler@67685
  1201
lemmas cartesian_euclidean_space_uniform_limit_intros[uniform_limit_intros] =
immler@67685
  1202
  bounded_linear.uniform_limit[OF blinfun.bounded_linear_right]
immler@67685
  1203
  bounded_linear.uniform_limit[OF bounded_linear_vec_nth]
immler@67685
  1204
  bounded_linear.uniform_limit[OF bounded_linear_component_cart]
immler@67685
  1205
hoelzl@37489
  1206
end