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