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