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