src/HOL/Analysis/Cartesian_Euclidean_Space.thy
 author wenzelm Mon Mar 25 17:21:26 2019 +0100 (3 months ago) changeset 69981 3dced198b9ec parent 69723 9b9f203e0ba3 child 70113 c8deb8ba6d05 permissions -rw-r--r--
more strict AFP properties;
```     1 (* Title:      HOL/Analysis/Cartesian_Euclidean_Space.thy
```
```     2    Some material by Jose DivasÃ³n, Tim Makarios and L C Paulson
```
```     3 *)
```
```     4
```
```     5 section \<open>Finite Cartesian Products of Euclidean Spaces\<close>
```
```     6
```
```     7 theory Cartesian_Euclidean_Space
```
```     8 imports Cartesian_Space Derivative
```
```     9 begin
```
```    10
```
```    11 lemma subspace_special_hyperplane: "subspace {x. x \$ k = 0}"
```
```    12   by (simp add: subspace_def)
```
```    13
```
```    14 lemma sum_mult_product:
```
```    15   "sum h {..<A * B :: nat} = (\<Sum>i\<in>{..<A}. \<Sum>j\<in>{..<B}. h (j + i * B))"
```
```    16   unfolding sum_nat_group[of h B A, unfolded atLeast0LessThan, symmetric]
```
```    17 proof (rule sum.cong, simp, rule sum.reindex_cong)
```
```    18   fix i
```
```    19   show "inj_on (\<lambda>j. j + i * B) {..<B}" by (auto intro!: inj_onI)
```
```    20   show "{i * B..<i * B + B} = (\<lambda>j. j + i * B) ` {..<B}"
```
```    21   proof safe
```
```    22     fix j assume "j \<in> {i * B..<i * B + B}"
```
```    23     then show "j \<in> (\<lambda>j. j + i * B) ` {..<B}"
```
```    24       by (auto intro!: image_eqI[of _ _ "j - i * B"])
```
```    25   qed simp
```
```    26 qed simp
```
```    27
```
```    28 lemma interval_cbox_cart: "{a::real^'n..b} = cbox a b"
```
```    29   by (auto simp add: less_eq_vec_def mem_box Basis_vec_def inner_axis)
```
```    30
```
```    31 lemma differentiable_vec:
```
```    32   fixes S :: "'a::euclidean_space set"
```
```    33   shows "vec differentiable_on S"
```
```    34   by (simp add: linear_linear bounded_linear_imp_differentiable_on)
```
```    35
```
```    36 lemma continuous_vec [continuous_intros]:
```
```    37   fixes x :: "'a::euclidean_space"
```
```    38   shows "isCont vec x"
```
```    39   apply (clarsimp simp add: continuous_def LIM_def dist_vec_def L2_set_def)
```
```    40   apply (rule_tac x="r / sqrt (real CARD('b))" in exI)
```
```    41   by (simp add: mult.commute pos_less_divide_eq real_sqrt_mult)
```
```    42
```
```    43 lemma box_vec_eq_empty [simp]:
```
```    44   shows "cbox (vec a) (vec b) = {} \<longleftrightarrow> cbox a b = {}"
```
```    45         "box (vec a) (vec b) = {} \<longleftrightarrow> box a b = {}"
```
```    46   by (auto simp: Basis_vec_def mem_box box_eq_empty inner_axis)
```
```    47
```
```    48 subsection\<open>Closures and interiors of halfspaces\<close>
```
```    49
```
```    50 lemma interior_halfspace_le [simp]:
```
```    51   assumes "a \<noteq> 0"
```
```    52     shows "interior {x. a \<bullet> x \<le> b} = {x. a \<bullet> x < b}"
```
```    53 proof -
```
```    54   have *: "a \<bullet> x < b" if x: "x \<in> S" and S: "S \<subseteq> {x. a \<bullet> x \<le> b}" and "open S" for S x
```
```    55   proof -
```
```    56     obtain e where "e>0" and e: "cball x e \<subseteq> S"
```
```    57       using \<open>open S\<close> open_contains_cball x by blast
```
```    58     then have "x + (e / norm a) *\<^sub>R a \<in> cball x e"
```
```    59       by (simp add: dist_norm)
```
```    60     then have "x + (e / norm a) *\<^sub>R a \<in> S"
```
```    61       using e by blast
```
```    62     then have "x + (e / norm a) *\<^sub>R a \<in> {x. a \<bullet> x \<le> b}"
```
```    63       using S by blast
```
```    64     moreover have "e * (a \<bullet> a) / norm a > 0"
```
```    65       by (simp add: \<open>0 < e\<close> assms)
```
```    66     ultimately show ?thesis
```
```    67       by (simp add: algebra_simps)
```
```    68   qed
```
```    69   show ?thesis
```
```    70     by (rule interior_unique) (auto simp: open_halfspace_lt *)
```
```    71 qed
```
```    72
```
```    73 lemma interior_halfspace_ge [simp]:
```
```    74    "a \<noteq> 0 \<Longrightarrow> interior {x. a \<bullet> x \<ge> b} = {x. a \<bullet> x > b}"
```
```    75 using interior_halfspace_le [of "-a" "-b"] by simp
```
```    76
```
```    77 lemma interior_halfspace_component_le [simp]:
```
```    78      "interior {x. x\$k \<le> a} = {x :: (real^'n). x\$k < a}" (is "?LE")
```
```    79   and interior_halfspace_component_ge [simp]:
```
```    80      "interior {x. x\$k \<ge> a} = {x :: (real^'n). x\$k > a}" (is "?GE")
```
```    81 proof -
```
```    82   have "axis k (1::real) \<noteq> 0"
```
```    83     by (simp add: axis_def vec_eq_iff)
```
```    84   moreover have "axis k (1::real) \<bullet> x = x\$k" for x
```
```    85     by (simp add: cart_eq_inner_axis inner_commute)
```
```    86   ultimately show ?LE ?GE
```
```    87     using interior_halfspace_le [of "axis k (1::real)" a]
```
```    88           interior_halfspace_ge [of "axis k (1::real)" a] by auto
```
```    89 qed
```
```    90
```
```    91 lemma closure_halfspace_lt [simp]:
```
```    92   assumes "a \<noteq> 0"
```
```    93     shows "closure {x. a \<bullet> x < b} = {x. a \<bullet> x \<le> b}"
```
```    94 proof -
```
```    95   have [simp]: "-{x. a \<bullet> x < b} = {x. a \<bullet> x \<ge> b}"
```
```    96     by (force simp:)
```
```    97   then show ?thesis
```
```    98     using interior_halfspace_ge [of a b] assms
```
```    99     by (force simp: closure_interior)
```
```   100 qed
```
```   101
```
```   102 lemma closure_halfspace_gt [simp]:
```
```   103    "a \<noteq> 0 \<Longrightarrow> closure {x. a \<bullet> x > b} = {x. a \<bullet> x \<ge> b}"
```
```   104 using closure_halfspace_lt [of "-a" "-b"] by simp
```
```   105
```
```   106 lemma closure_halfspace_component_lt [simp]:
```
```   107      "closure {x. x\$k < a} = {x :: (real^'n). x\$k \<le> a}" (is "?LE")
```
```   108   and closure_halfspace_component_gt [simp]:
```
```   109      "closure {x. x\$k > a} = {x :: (real^'n). x\$k \<ge> a}" (is "?GE")
```
```   110 proof -
```
```   111   have "axis k (1::real) \<noteq> 0"
```
```   112     by (simp add: axis_def vec_eq_iff)
```
```   113   moreover have "axis k (1::real) \<bullet> x = x\$k" for x
```
```   114     by (simp add: cart_eq_inner_axis inner_commute)
```
```   115   ultimately show ?LE ?GE
```
```   116     using closure_halfspace_lt [of "axis k (1::real)" a]
```
```   117           closure_halfspace_gt [of "axis k (1::real)" a] by auto
```
```   118 qed
```
```   119
```
```   120 lemma interior_hyperplane [simp]:
```
```   121   assumes "a \<noteq> 0"
```
```   122     shows "interior {x. a \<bullet> x = b} = {}"
```
```   123 proof -
```
```   124   have [simp]: "{x. a \<bullet> x = b} = {x. a \<bullet> x \<le> b} \<inter> {x. a \<bullet> x \<ge> b}"
```
```   125     by (force simp:)
```
```   126   then show ?thesis
```
```   127     by (auto simp: assms)
```
```   128 qed
```
```   129
```
```   130 lemma frontier_halfspace_le:
```
```   131   assumes "a \<noteq> 0 \<or> b \<noteq> 0"
```
```   132     shows "frontier {x. a \<bullet> x \<le> b} = {x. a \<bullet> x = b}"
```
```   133 proof (cases "a = 0")
```
```   134   case True with assms show ?thesis by simp
```
```   135 next
```
```   136   case False then show ?thesis
```
```   137     by (force simp: frontier_def closed_halfspace_le)
```
```   138 qed
```
```   139
```
```   140 lemma frontier_halfspace_ge:
```
```   141   assumes "a \<noteq> 0 \<or> b \<noteq> 0"
```
```   142     shows "frontier {x. a \<bullet> x \<ge> b} = {x. a \<bullet> x = b}"
```
```   143 proof (cases "a = 0")
```
```   144   case True with assms show ?thesis by simp
```
```   145 next
```
```   146   case False then show ?thesis
```
```   147     by (force simp: frontier_def closed_halfspace_ge)
```
```   148 qed
```
```   149
```
```   150 lemma frontier_halfspace_lt:
```
```   151   assumes "a \<noteq> 0 \<or> b \<noteq> 0"
```
```   152     shows "frontier {x. a \<bullet> x < b} = {x. a \<bullet> x = b}"
```
```   153 proof (cases "a = 0")
```
```   154   case True with assms show ?thesis by simp
```
```   155 next
```
```   156   case False then show ?thesis
```
```   157     by (force simp: frontier_def interior_open open_halfspace_lt)
```
```   158 qed
```
```   159
```
```   160 lemma frontier_halfspace_gt:
```
```   161   assumes "a \<noteq> 0 \<or> b \<noteq> 0"
```
```   162     shows "frontier {x. a \<bullet> x > b} = {x. a \<bullet> x = b}"
```
```   163 proof (cases "a = 0")
```
```   164   case True with assms show ?thesis by simp
```
```   165 next
```
```   166   case False then show ?thesis
```
```   167     by (force simp: frontier_def interior_open open_halfspace_gt)
```
```   168 qed
```
```   169
```
```   170 lemma interior_standard_hyperplane:
```
```   171    "interior {x :: (real^'n). x\$k = a} = {}"
```
```   172 proof -
```
```   173   have "axis k (1::real) \<noteq> 0"
```
```   174     by (simp add: axis_def vec_eq_iff)
```
```   175   moreover have "axis k (1::real) \<bullet> x = x\$k" for x
```
```   176     by (simp add: cart_eq_inner_axis inner_commute)
```
```   177   ultimately show ?thesis
```
```   178     using interior_hyperplane [of "axis k (1::real)" a]
```
```   179     by force
```
```   180 qed
```
```   181
```
```   182 lemma matrix_vector_mul_bounded_linear[intro, simp]: "bounded_linear ((*v) A)" for A :: "'a::{euclidean_space,real_algebra_1}^'n^'m"
```
```   183   using matrix_vector_mul_linear[of A]
```
```   184   by (simp add: linear_conv_bounded_linear linear_matrix_vector_mul_eq)
```
```   185
```
```   186 lemma
```
```   187   fixes A :: "'a::{euclidean_space,real_algebra_1}^'n^'m"
```
```   188   shows matrix_vector_mult_linear_continuous_at [continuous_intros]: "isCont ((*v) A) z"
```
```   189     and matrix_vector_mult_linear_continuous_on [continuous_intros]: "continuous_on S ((*v) A)"
```
```   190   by (simp_all add: linear_continuous_at linear_continuous_on)
```
```   191
```
```   192
```
```   193 subsection\<open>Bounds on components etc.\ relative to operator norm\<close>
```
```   194
```
```   195 lemma norm_column_le_onorm:
```
```   196   fixes A :: "real^'n^'m"
```
```   197   shows "norm(column i A) \<le> onorm((*v) A)"
```
```   198 proof -
```
```   199   have "norm (\<chi> j. A \$ j \$ i) \<le> norm (A *v axis i 1)"
```
```   200     by (simp add: matrix_mult_dot cart_eq_inner_axis)
```
```   201   also have "\<dots> \<le> onorm ((*v) A)"
```
```   202     using onorm [OF matrix_vector_mul_bounded_linear, of A "axis i 1"] by auto
```
```   203   finally have "norm (\<chi> j. A \$ j \$ i) \<le> onorm ((*v) A)" .
```
```   204   then show ?thesis
```
```   205     unfolding column_def .
```
```   206 qed
```
```   207
```
```   208 lemma matrix_component_le_onorm:
```
```   209   fixes A :: "real^'n^'m"
```
```   210   shows "\<bar>A \$ i \$ j\<bar> \<le> onorm((*v) A)"
```
```   211 proof -
```
```   212   have "\<bar>A \$ i \$ j\<bar> \<le> norm (\<chi> n. (A \$ n \$ j))"
```
```   213     by (metis (full_types, lifting) component_le_norm_cart vec_lambda_beta)
```
```   214   also have "\<dots> \<le> onorm ((*v) A)"
```
```   215     by (metis (no_types) column_def norm_column_le_onorm)
```
```   216   finally show ?thesis .
```
```   217 qed
```
```   218
```
```   219 lemma component_le_onorm:
```
```   220   fixes f :: "real^'m \<Rightarrow> real^'n"
```
```   221   shows "linear f \<Longrightarrow> \<bar>matrix f \$ i \$ j\<bar> \<le> onorm f"
```
```   222   by (metis linear_matrix_vector_mul_eq matrix_component_le_onorm matrix_vector_mul)
```
```   223
```
```   224 lemma onorm_le_matrix_component_sum:
```
```   225   fixes A :: "real^'n^'m"
```
```   226   shows "onorm((*v) A) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A \$ i \$ j\<bar>)"
```
```   227 proof (rule onorm_le)
```
```   228   fix x
```
```   229   have "norm (A *v x) \<le> (\<Sum>i\<in>UNIV. \<bar>(A *v x) \$ i\<bar>)"
```
```   230     by (rule norm_le_l1_cart)
```
```   231   also have "\<dots> \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A \$ i \$ j\<bar> * norm x)"
```
```   232   proof (rule sum_mono)
```
```   233     fix i
```
```   234     have "\<bar>(A *v x) \$ i\<bar> \<le> \<bar>\<Sum>j\<in>UNIV. A \$ i \$ j * x \$ j\<bar>"
```
```   235       by (simp add: matrix_vector_mult_def)
```
```   236     also have "\<dots> \<le> (\<Sum>j\<in>UNIV. \<bar>A \$ i \$ j * x \$ j\<bar>)"
```
```   237       by (rule sum_abs)
```
```   238     also have "\<dots> \<le> (\<Sum>j\<in>UNIV. \<bar>A \$ i \$ j\<bar> * norm x)"
```
```   239       by (rule sum_mono) (simp add: abs_mult component_le_norm_cart mult_left_mono)
```
```   240     finally show "\<bar>(A *v x) \$ i\<bar> \<le> (\<Sum>j\<in>UNIV. \<bar>A \$ i \$ j\<bar> * norm x)" .
```
```   241   qed
```
```   242   finally show "norm (A *v x) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A \$ i \$ j\<bar>) * norm x"
```
```   243     by (simp add: sum_distrib_right)
```
```   244 qed
```
```   245
```
```   246 lemma onorm_le_matrix_component:
```
```   247   fixes A :: "real^'n^'m"
```
```   248   assumes "\<And>i j. abs(A\$i\$j) \<le> B"
```
```   249   shows "onorm((*v) A) \<le> real (CARD('m)) * real (CARD('n)) * B"
```
```   250 proof (rule onorm_le)
```
```   251   fix x :: "real^'n::_"
```
```   252   have "norm (A *v x) \<le> (\<Sum>i\<in>UNIV. \<bar>(A *v x) \$ i\<bar>)"
```
```   253     by (rule norm_le_l1_cart)
```
```   254   also have "\<dots> \<le> (\<Sum>i::'m \<in>UNIV. real (CARD('n)) * B * norm x)"
```
```   255   proof (rule sum_mono)
```
```   256     fix i
```
```   257     have "\<bar>(A *v x) \$ i\<bar> \<le> norm(A \$ i) * norm x"
```
```   258       by (simp add: matrix_mult_dot Cauchy_Schwarz_ineq2)
```
```   259     also have "\<dots> \<le> (\<Sum>j\<in>UNIV. \<bar>A \$ i \$ j\<bar>) * norm x"
```
```   260       by (simp add: mult_right_mono norm_le_l1_cart)
```
```   261     also have "\<dots> \<le> real (CARD('n)) * B * norm x"
```
```   262       by (simp add: assms sum_bounded_above mult_right_mono)
```
```   263     finally show "\<bar>(A *v x) \$ i\<bar> \<le> real (CARD('n)) * B * norm x" .
```
```   264   qed
```
```   265   also have "\<dots> \<le> CARD('m) * real (CARD('n)) * B * norm x"
```
```   266     by simp
```
```   267   finally show "norm (A *v x) \<le> CARD('m) * real (CARD('n)) * B * norm x" .
```
```   268 qed
```
```   269
```
```   270
```
```   271 lemma rational_approximation:
```
```   272   assumes "e > 0"
```
```   273   obtains r::real where "r \<in> \<rat>" "\<bar>r - x\<bar> < e"
```
```   274   using Rats_dense_in_real [of "x - e/2" "x + e/2"] assms by auto
```
```   275
```
```   276 proposition matrix_rational_approximation:
```
```   277   fixes A :: "real^'n^'m"
```
```   278   assumes "e > 0"
```
```   279   obtains B where "\<And>i j. B\$i\$j \<in> \<rat>" "onorm(\<lambda>x. (A - B) *v x) < e"
```
```   280 proof -
```
```   281   have "\<forall>i j. \<exists>q \<in> \<rat>. \<bar>q - A \$ i \$ j\<bar> < e / (2 * CARD('m) * CARD('n))"
```
```   282     using assms by (force intro: rational_approximation [of "e / (2 * CARD('m) * CARD('n))"])
```
```   283   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))"
```
```   284     by (auto simp: lambda_skolem Bex_def)
```
```   285   show ?thesis
```
```   286   proof
```
```   287     have "onorm ((*v) (A - B)) \<le> real CARD('m) * real CARD('n) *
```
```   288     (e / (2 * real CARD('m) * real CARD('n)))"
```
```   289       apply (rule onorm_le_matrix_component)
```
```   290       using Bclo by (simp add: abs_minus_commute less_imp_le)
```
```   291     also have "\<dots> < e"
```
```   292       using \<open>0 < e\<close> by (simp add: divide_simps)
```
```   293     finally show "onorm ((*v) (A - B)) < e" .
```
```   294   qed (use B in auto)
```
```   295 qed
```
```   296
```
```   297 lemma vector_sub_project_orthogonal_cart: "(b::real^'n) \<bullet> (x - ((b \<bullet> x) / (b \<bullet> b)) *s b) = 0"
```
```   298   unfolding inner_simps scalar_mult_eq_scaleR by auto
```
```   299
```
```   300 lemma infnorm_cart:"infnorm (x::real^'n) = Sup {\<bar>x\$i\<bar> |i. i\<in>UNIV}"
```
```   301   by (simp add: infnorm_def inner_axis Basis_vec_def) (metis (lifting) inner_axis real_inner_1_right)
```
```   302
```
```   303 lemma component_le_infnorm_cart: "\<bar>x\$i\<bar> \<le> infnorm (x::real^'n)"
```
```   304   using Basis_le_infnorm[of "axis i 1" x]
```
```   305   by (simp add: Basis_vec_def axis_eq_axis inner_axis)
```
```   306
```
```   307 lemma continuous_component[continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. f x \$ i)"
```
```   308   unfolding continuous_def by (rule tendsto_vec_nth)
```
```   309
```
```   310 lemma continuous_on_component[continuous_intros]: "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. f x \$ i)"
```
```   311   unfolding continuous_on_def by (fast intro: tendsto_vec_nth)
```
```   312
```
```   313 lemma continuous_on_vec_lambda[continuous_intros]:
```
```   314   "(\<And>i. continuous_on S (f i)) \<Longrightarrow> continuous_on S (\<lambda>x. \<chi> i. f i x)"
```
```   315   unfolding continuous_on_def by (auto intro: tendsto_vec_lambda)
```
```   316
```
```   317 lemma closed_positive_orthant: "closed {x::real^'n. \<forall>i. 0 \<le>x\$i}"
```
```   318   by (simp add: Collect_all_eq closed_INT closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
```
```   319
```
```   320 lemma bounded_component_cart: "bounded s \<Longrightarrow> bounded ((\<lambda>x. x \$ i) ` s)"
```
```   321   unfolding bounded_def
```
```   322   apply clarify
```
```   323   apply (rule_tac x="x \$ i" in exI)
```
```   324   apply (rule_tac x="e" in exI)
```
```   325   apply clarify
```
```   326   apply (rule order_trans [OF dist_vec_nth_le], simp)
```
```   327   done
```
```   328
```
```   329 lemma compact_lemma_cart:
```
```   330   fixes f :: "nat \<Rightarrow> 'a::heine_borel ^ 'n"
```
```   331   assumes f: "bounded (range f)"
```
```   332   shows "\<exists>l r. strict_mono r \<and>
```
```   333         (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) \$ i) (l \$ i) < e) sequentially)"
```
```   334     (is "?th d")
```
```   335 proof -
```
```   336   have "\<forall>d' \<subseteq> d. ?th d'"
```
```   337     by (rule compact_lemma_general[where unproj=vec_lambda])
```
```   338       (auto intro!: f bounded_component_cart simp: vec_lambda_eta)
```
```   339   then show "?th d" by simp
```
```   340 qed
```
```   341
```
```   342 instance vec :: (heine_borel, finite) heine_borel
```
```   343 proof
```
```   344   fix f :: "nat \<Rightarrow> 'a ^ 'b"
```
```   345   assume f: "bounded (range f)"
```
```   346   then obtain l r where r: "strict_mono r"
```
```   347       and l: "\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>UNIV. dist (f (r n) \$ i) (l \$ i) < e) sequentially"
```
```   348     using compact_lemma_cart [OF f] by blast
```
```   349   let ?d = "UNIV::'b set"
```
```   350   { fix e::real assume "e>0"
```
```   351     hence "0 < e / (real_of_nat (card ?d))"
```
```   352       using zero_less_card_finite divide_pos_pos[of e, of "real_of_nat (card ?d)"] by auto
```
```   353     with l have "eventually (\<lambda>n. \<forall>i. dist (f (r n) \$ i) (l \$ i) < e / (real_of_nat (card ?d))) sequentially"
```
```   354       by simp
```
```   355     moreover
```
```   356     { fix n
```
```   357       assume n: "\<forall>i. dist (f (r n) \$ i) (l \$ i) < e / (real_of_nat (card ?d))"
```
```   358       have "dist (f (r n)) l \<le> (\<Sum>i\<in>?d. dist (f (r n) \$ i) (l \$ i))"
```
```   359         unfolding dist_vec_def using zero_le_dist by (rule L2_set_le_sum)
```
```   360       also have "\<dots> < (\<Sum>i\<in>?d. e / (real_of_nat (card ?d)))"
```
```   361         by (rule sum_strict_mono) (simp_all add: n)
```
```   362       finally have "dist (f (r n)) l < e" by simp
```
```   363     }
```
```   364     ultimately have "eventually (\<lambda>n. dist (f (r n)) l < e) sequentially"
```
```   365       by (rule eventually_mono)
```
```   366   }
```
```   367   hence "((f \<circ> r) \<longlongrightarrow> l) sequentially" unfolding o_def tendsto_iff by simp
```
```   368   with r show "\<exists>l r. strict_mono r \<and> ((f \<circ> r) \<longlongrightarrow> l) sequentially" by auto
```
```   369 qed
```
```   370
```
```   371 lemma interval_cart:
```
```   372   fixes a :: "real^'n"
```
```   373   shows "box a b = {x::real^'n. \<forall>i. a\$i < x\$i \<and> x\$i < b\$i}"
```
```   374     and "cbox a b = {x::real^'n. \<forall>i. a\$i \<le> x\$i \<and> x\$i \<le> b\$i}"
```
```   375   by (auto simp add: set_eq_iff less_vec_def less_eq_vec_def mem_box Basis_vec_def inner_axis)
```
```   376
```
```   377 lemma mem_box_cart:
```
```   378   fixes a :: "real^'n"
```
```   379   shows "x \<in> box a b \<longleftrightarrow> (\<forall>i. a\$i < x\$i \<and> x\$i < b\$i)"
```
```   380     and "x \<in> cbox a b \<longleftrightarrow> (\<forall>i. a\$i \<le> x\$i \<and> x\$i \<le> b\$i)"
```
```   381   using interval_cart[of a b] by (auto simp add: set_eq_iff less_vec_def less_eq_vec_def)
```
```   382
```
```   383 lemma interval_eq_empty_cart:
```
```   384   fixes a :: "real^'n"
```
```   385   shows "(box a b = {} \<longleftrightarrow> (\<exists>i. b\$i \<le> a\$i))" (is ?th1)
```
```   386     and "(cbox a b = {} \<longleftrightarrow> (\<exists>i. b\$i < a\$i))" (is ?th2)
```
```   387 proof -
```
```   388   { fix i x assume as:"b\$i \<le> a\$i" and x:"x\<in>box a b"
```
```   389     hence "a \$ i < x \$ i \<and> x \$ i < b \$ i" unfolding mem_box_cart by auto
```
```   390     hence "a\$i < b\$i" by auto
```
```   391     hence False using as by auto }
```
```   392   moreover
```
```   393   { assume as:"\<forall>i. \<not> (b\$i \<le> a\$i)"
```
```   394     let ?x = "(1/2) *\<^sub>R (a + b)"
```
```   395     { fix i
```
```   396       have "a\$i < b\$i" using as[THEN spec[where x=i]] by auto
```
```   397       hence "a\$i < ((1/2) *\<^sub>R (a+b)) \$ i" "((1/2) *\<^sub>R (a+b)) \$ i < b\$i"
```
```   398         unfolding vector_smult_component and vector_add_component
```
```   399         by auto }
```
```   400     hence "box a b \<noteq> {}" using mem_box_cart(1)[of "?x" a b] by auto }
```
```   401   ultimately show ?th1 by blast
```
```   402
```
```   403   { fix i x assume as:"b\$i < a\$i" and x:"x\<in>cbox a b"
```
```   404     hence "a \$ i \<le> x \$ i \<and> x \$ i \<le> b \$ i" unfolding mem_box_cart by auto
```
```   405     hence "a\$i \<le> b\$i" by auto
```
```   406     hence False using as by auto }
```
```   407   moreover
```
```   408   { assume as:"\<forall>i. \<not> (b\$i < a\$i)"
```
```   409     let ?x = "(1/2) *\<^sub>R (a + b)"
```
```   410     { fix i
```
```   411       have "a\$i \<le> b\$i" using as[THEN spec[where x=i]] by auto
```
```   412       hence "a\$i \<le> ((1/2) *\<^sub>R (a+b)) \$ i" "((1/2) *\<^sub>R (a+b)) \$ i \<le> b\$i"
```
```   413         unfolding vector_smult_component and vector_add_component
```
```   414         by auto }
```
```   415     hence "cbox a b \<noteq> {}" using mem_box_cart(2)[of "?x" a b] by auto  }
```
```   416   ultimately show ?th2 by blast
```
```   417 qed
```
```   418
```
```   419 lemma interval_ne_empty_cart:
```
```   420   fixes a :: "real^'n"
```
```   421   shows "cbox a b \<noteq> {} \<longleftrightarrow> (\<forall>i. a\$i \<le> b\$i)"
```
```   422     and "box a b \<noteq> {} \<longleftrightarrow> (\<forall>i. a\$i < b\$i)"
```
```   423   unfolding interval_eq_empty_cart[of a b] by (auto simp add: not_less not_le)
```
```   424     (* BH: Why doesn't just "auto" work here? *)
```
```   425
```
```   426 lemma subset_interval_imp_cart:
```
```   427   fixes a :: "real^'n"
```
```   428   shows "(\<forall>i. a\$i \<le> c\$i \<and> d\$i \<le> b\$i) \<Longrightarrow> cbox c d \<subseteq> cbox a b"
```
```   429     and "(\<forall>i. a\$i < c\$i \<and> d\$i < b\$i) \<Longrightarrow> cbox c d \<subseteq> box a b"
```
```   430     and "(\<forall>i. a\$i \<le> c\$i \<and> d\$i \<le> b\$i) \<Longrightarrow> box c d \<subseteq> cbox a b"
```
```   431     and "(\<forall>i. a\$i \<le> c\$i \<and> d\$i \<le> b\$i) \<Longrightarrow> box c d \<subseteq> box a b"
```
```   432   unfolding subset_eq[unfolded Ball_def] unfolding mem_box_cart
```
```   433   by (auto intro: order_trans less_le_trans le_less_trans less_imp_le) (* BH: Why doesn't just "auto" work here? *)
```
```   434
```
```   435 lemma interval_sing:
```
```   436   fixes a :: "'a::linorder^'n"
```
```   437   shows "{a .. a} = {a} \<and> {a<..<a} = {}"
```
```   438   apply (auto simp add: set_eq_iff less_vec_def less_eq_vec_def vec_eq_iff)
```
```   439   done
```
```   440
```
```   441 lemma subset_interval_cart:
```
```   442   fixes a :: "real^'n"
```
```   443   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)
```
```   444     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)
```
```   445     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)
```
```   446     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)
```
```   447   using subset_box[of c d a b] by (simp_all add: Basis_vec_def inner_axis)
```
```   448
```
```   449 lemma disjoint_interval_cart:
```
```   450   fixes a::"real^'n"
```
```   451   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)
```
```   452     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)
```
```   453     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)
```
```   454     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)
```
```   455   using disjoint_interval[of a b c d] by (simp_all add: Basis_vec_def inner_axis)
```
```   456
```
```   457 lemma Int_interval_cart:
```
```   458   fixes a :: "real^'n"
```
```   459   shows "cbox a b \<inter> cbox c d =  {(\<chi> i. max (a\$i) (c\$i)) .. (\<chi> i. min (b\$i) (d\$i))}"
```
```   460   unfolding Int_interval
```
```   461   by (auto simp: mem_box less_eq_vec_def)
```
```   462     (auto simp: Basis_vec_def inner_axis)
```
```   463
```
```   464 lemma closed_interval_left_cart:
```
```   465   fixes b :: "real^'n"
```
```   466   shows "closed {x::real^'n. \<forall>i. x\$i \<le> b\$i}"
```
```   467   by (simp add: Collect_all_eq closed_INT closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
```
```   468
```
```   469 lemma closed_interval_right_cart:
```
```   470   fixes a::"real^'n"
```
```   471   shows "closed {x::real^'n. \<forall>i. a\$i \<le> x\$i}"
```
```   472   by (simp add: Collect_all_eq closed_INT closed_Collect_le continuous_on_const continuous_on_id continuous_on_component)
```
```   473
```
```   474 lemma is_interval_cart:
```
```   475   "is_interval (s::(real^'n) set) \<longleftrightarrow>
```
```   476     (\<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)"
```
```   477   by (simp add: is_interval_def Ball_def Basis_vec_def inner_axis imp_ex)
```
```   478
```
```   479 lemma closed_halfspace_component_le_cart: "closed {x::real^'n. x\$i \<le> a}"
```
```   480   by (simp add: closed_Collect_le continuous_on_component)
```
```   481
```
```   482 lemma closed_halfspace_component_ge_cart: "closed {x::real^'n. x\$i \<ge> a}"
```
```   483   by (simp add: closed_Collect_le continuous_on_component)
```
```   484
```
```   485 lemma open_halfspace_component_lt_cart: "open {x::real^'n. x\$i < a}"
```
```   486   by (simp add: open_Collect_less continuous_on_component)
```
```   487
```
```   488 lemma open_halfspace_component_gt_cart: "open {x::real^'n. x\$i  > a}"
```
```   489   by (simp add: open_Collect_less continuous_on_component)
```
```   490
```
```   491 lemma Lim_component_le_cart:
```
```   492   fixes f :: "'a \<Rightarrow> real^'n"
```
```   493   assumes "(f \<longlongrightarrow> l) net" "\<not> (trivial_limit net)"  "eventually (\<lambda>x. f x \$i \<le> b) net"
```
```   494   shows "l\$i \<le> b"
```
```   495   by (rule tendsto_le[OF assms(2) tendsto_const tendsto_vec_nth, OF assms(1, 3)])
```
```   496
```
```   497 lemma Lim_component_ge_cart:
```
```   498   fixes f :: "'a \<Rightarrow> real^'n"
```
```   499   assumes "(f \<longlongrightarrow> l) net"  "\<not> (trivial_limit net)"  "eventually (\<lambda>x. b \<le> (f x)\$i) net"
```
```   500   shows "b \<le> l\$i"
```
```   501   by (rule tendsto_le[OF assms(2) tendsto_vec_nth tendsto_const, OF assms(1, 3)])
```
```   502
```
```   503 lemma Lim_component_eq_cart:
```
```   504   fixes f :: "'a \<Rightarrow> real^'n"
```
```   505   assumes net: "(f \<longlongrightarrow> l) net" "\<not> trivial_limit net" and ev:"eventually (\<lambda>x. f(x)\$i = b) net"
```
```   506   shows "l\$i = b"
```
```   507   using ev[unfolded order_eq_iff eventually_conj_iff] and
```
```   508     Lim_component_ge_cart[OF net, of b i] and
```
```   509     Lim_component_le_cart[OF net, of i b] by auto
```
```   510
```
```   511 lemma connected_ivt_component_cart:
```
```   512   fixes x :: "real^'n"
```
```   513   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)"
```
```   514   using connected_ivt_hyperplane[of s x y "axis k 1" a]
```
```   515   by (auto simp add: inner_axis inner_commute)
```
```   516
```
```   517 lemma subspace_substandard_cart: "vec.subspace {x. (\<forall>i. P i \<longrightarrow> x\$i = 0)}"
```
```   518   unfolding vec.subspace_def by auto
```
```   519
```
```   520 lemma closed_substandard_cart:
```
```   521   "closed {x::'a::real_normed_vector ^ 'n. \<forall>i. P i \<longrightarrow> x\$i = 0}"
```
```   522 proof -
```
```   523   { fix i::'n
```
```   524     have "closed {x::'a ^ 'n. P i \<longrightarrow> x\$i = 0}"
```
```   525       by (cases "P i") (simp_all add: closed_Collect_eq continuous_on_const continuous_on_id continuous_on_component) }
```
```   526   thus ?thesis
```
```   527     unfolding Collect_all_eq by (simp add: closed_INT)
```
```   528 qed
```
```   529
```
```   530 subsection "Convex Euclidean Space"
```
```   531
```
```   532 lemma Cart_1:"(1::real^'n) = \<Sum>Basis"
```
```   533   using const_vector_cart[of 1] by (simp add: one_vec_def)
```
```   534
```
```   535 declare vector_add_ldistrib[simp] vector_ssub_ldistrib[simp] vector_smult_assoc[simp] vector_smult_rneg[simp]
```
```   536 declare vector_sadd_rdistrib[simp] vector_sub_rdistrib[simp]
```
```   537
```
```   538 lemmas vector_component_simps = vector_minus_component vector_smult_component vector_add_component less_eq_vec_def vec_lambda_beta vector_uminus_component
```
```   539
```
```   540 lemma convex_box_cart:
```
```   541   assumes "\<And>i. convex {x. P i x}"
```
```   542   shows "convex {x. \<forall>i. P i (x\$i)}"
```
```   543   using assms unfolding convex_def by auto
```
```   544
```
```   545 lemma convex_positive_orthant_cart: "convex {x::real^'n. (\<forall>i. 0 \<le> x\$i)}"
```
```   546   by (rule convex_box_cart) (simp add: atLeast_def[symmetric])
```
```   547
```
```   548 lemma unit_interval_convex_hull_cart:
```
```   549   "cbox (0::real^'n) 1 = convex hull {x. \<forall>i. (x\$i = 0) \<or> (x\$i = 1)}"
```
```   550   unfolding Cart_1 unit_interval_convex_hull[where 'a="real^'n"] box_real[symmetric]
```
```   551   by (rule arg_cong[where f="\<lambda>x. convex hull x"]) (simp add: Basis_vec_def inner_axis)
```
```   552
```
```   553 proposition cube_convex_hull_cart:
```
```   554   assumes "0 < d"
```
```   555   obtains s::"(real^'n) set"
```
```   556     where "finite s" "cbox (x - (\<chi> i. d)) (x + (\<chi> i. d)) = convex hull s"
```
```   557 proof -
```
```   558   from assms obtain s where "finite s"
```
```   559     and "cbox (x - sum ((*\<^sub>R) d) Basis) (x + sum ((*\<^sub>R) d) Basis) = convex hull s"
```
```   560     by (rule cube_convex_hull)
```
```   561   with that[of s] show thesis
```
```   562     by (simp add: const_vector_cart)
```
```   563 qed
```
```   564
```
```   565
```
```   566 subsection "Derivative"
```
```   567
```
```   568 definition%important "jacobian f net = matrix(frechet_derivative f net)"
```
```   569
```
```   570 proposition jacobian_works:
```
```   571   "(f::(real^'a) \<Rightarrow> (real^'b)) differentiable net \<longleftrightarrow>
```
```   572     (f has_derivative (\<lambda>h. (jacobian f net) *v h)) net" (is "?lhs = ?rhs")
```
```   573 proof
```
```   574   assume ?lhs then show ?rhs
```
```   575     by (simp add: frechet_derivative_works has_derivative_linear jacobian_def)
```
```   576 next
```
```   577   assume ?rhs then show ?lhs
```
```   578     by (rule differentiableI)
```
```   579 qed
```
```   580
```
```   581
```
```   582 text \<open>Component of the differential must be zero if it exists at a local
```
```   583   maximum or minimum for that corresponding component\<close>
```
```   584
```
```   585 proposition differential_zero_maxmin_cart:
```
```   586   fixes f::"real^'a \<Rightarrow> real^'b"
```
```   587   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))"
```
```   588     "f differentiable (at x)"
```
```   589   shows "jacobian f (at x) \$ k = 0"
```
```   590   using differential_zero_maxmin_component[of "axis k 1" e x f] assms
```
```   591     vector_cart[of "\<lambda>j. frechet_derivative f (at x) j \$ k"]
```
```   592   by (simp add: Basis_vec_def axis_eq_axis inner_axis jacobian_def matrix_def)
```
```   593
```
```   594 subsection%unimportant\<open>Routine results connecting the types \<^typ>\<open>real^1\<close> and \<^typ>\<open>real\<close>\<close>
```
```   595
```
```   596 lemma vec_cbox_1_eq [simp]:
```
```   597   shows "vec ` cbox u v = cbox (vec u) (vec v ::real^1)"
```
```   598   by (force simp: Basis_vec_def cart_eq_inner_axis [symmetric] mem_box)
```
```   599
```
```   600 lemma vec_nth_cbox_1_eq [simp]:
```
```   601   fixes u v :: "'a::euclidean_space^1"
```
```   602   shows "(\<lambda>x. x \$ 1) ` cbox u v = cbox (u\$1) (v\$1)"
```
```   603     by (auto simp: Basis_vec_def cart_eq_inner_axis [symmetric] mem_box image_iff Bex_def inner_axis) (metis vec_component)
```
```   604
```
```   605 lemma vec_nth_1_iff_cbox [simp]:
```
```   606   fixes a b :: "'a::euclidean_space"
```
```   607   shows "(\<lambda>x::'a^1. x \$ 1) ` S = cbox a b \<longleftrightarrow> S = cbox (vec a) (vec b)"
```
```   608     (is "?lhs = ?rhs")
```
```   609 proof
```
```   610   assume L: ?lhs show ?rhs
```
```   611   proof (intro equalityI subsetI)
```
```   612     fix x
```
```   613     assume "x \<in> S"
```
```   614     then have "x \$ 1 \<in> (\<lambda>v. v \$ (1::1)) ` cbox (vec a) (vec b)"
```
```   615       using L by auto
```
```   616     then show "x \<in> cbox (vec a) (vec b)"
```
```   617       by (metis (no_types, lifting) imageE vector_one_nth)
```
```   618   next
```
```   619     fix x :: "'a^1"
```
```   620     assume "x \<in> cbox (vec a) (vec b)"
```
```   621     then show "x \<in> S"
```
```   622       by (metis (no_types, lifting) L imageE imageI vec_component vec_nth_cbox_1_eq vector_one_nth)
```
```   623   qed
```
```   624 qed simp
```
```   625
```
```   626
```
```   627 lemma interval_split_cart:
```
```   628   "{a..b::real^'n} \<inter> {x. x\$k \<le> c} = {a .. (\<chi> i. if i = k then min (b\$k) c else b\$i)}"
```
```   629   "cbox a b \<inter> {x. x\$k \<ge> c} = {(\<chi> i. if i = k then max (a\$k) c else a\$i) .. b}"
```
```   630   apply (rule_tac[!] set_eqI)
```
```   631   unfolding Int_iff mem_box_cart mem_Collect_eq interval_cbox_cart
```
```   632   unfolding vec_lambda_beta
```
```   633   by auto
```
```   634
```
```   635 lemmas cartesian_euclidean_space_uniform_limit_intros[uniform_limit_intros] =
```
```   636   bounded_linear.uniform_limit[OF blinfun.bounded_linear_right]
```
```   637   bounded_linear.uniform_limit[OF bounded_linear_vec_nth]
```
```   638
```
```   639 end
```