src/HOL/Analysis/Product_Vector.thy
 author immler Tue Jul 10 09:38:35 2018 +0200 (11 months ago) changeset 68607 67bb59e49834 parent 68072 493b818e8e10 child 68611 4bc4b5c0ccfc permissions -rw-r--r--
make theorem, corollary, and proposition %important for HOL-Analysis manual
```     1 (*  Title:      HOL/Analysis/Product_Vector.thy
```
```     2     Author:     Brian Huffman
```
```     3 *)
```
```     4
```
```     5 section \<open>Cartesian Products as Vector Spaces\<close>
```
```     6
```
```     7 theory Product_Vector
```
```     8 imports
```
```     9   Inner_Product
```
```    10   "HOL-Library.Product_Plus"
```
```    11 begin
```
```    12
```
```    13 lemma Times_eq_image_sum:
```
```    14   fixes S :: "'a :: comm_monoid_add set" and T :: "'b :: comm_monoid_add set"
```
```    15   shows "S \<times> T = {u + v |u v. u \<in> (\<lambda>x. (x, 0)) ` S \<and> v \<in> Pair 0 ` T}"
```
```    16   by force
```
```    17
```
```    18
```
```    19 subsection \<open>Product is a module\<close>
```
```    20
```
```    21 locale module_prod = module_pair begin
```
```    22
```
```    23 definition scale :: "'a \<Rightarrow> 'b \<times> 'c \<Rightarrow> 'b \<times> 'c"
```
```    24   where "scale a v = (s1 a (fst v), s2 a (snd v))"
```
```    25
```
```    26 lemma scale_prod: "scale x (a, b) = (s1 x a, s2 x b)"
```
```    27   by (auto simp: scale_def)
```
```    28
```
```    29 sublocale p: module scale
```
```    30 proof qed (simp_all add: scale_def
```
```    31   m1.scale_left_distrib m1.scale_right_distrib m2.scale_left_distrib m2.scale_right_distrib)
```
```    32
```
```    33 lemma subspace_Times: "m1.subspace A \<Longrightarrow> m2.subspace B \<Longrightarrow> p.subspace (A \<times> B)"
```
```    34   unfolding m1.subspace_def m2.subspace_def p.subspace_def
```
```    35   by (auto simp: zero_prod_def scale_def)
```
```    36
```
```    37 lemma module_hom_fst: "module_hom scale s1 fst"
```
```    38   by unfold_locales (auto simp: scale_def)
```
```    39
```
```    40 lemma module_hom_snd: "module_hom scale s2 snd"
```
```    41   by unfold_locales (auto simp: scale_def)
```
```    42
```
```    43 end
```
```    44
```
```    45 locale vector_space_prod = vector_space_pair begin
```
```    46
```
```    47 sublocale module_prod s1 s2
```
```    48   rewrites "module_hom = Vector_Spaces.linear"
```
```    49   by unfold_locales (fact module_hom_eq_linear)
```
```    50
```
```    51 sublocale p: vector_space scale by unfold_locales (auto simp: algebra_simps)
```
```    52
```
```    53 lemmas linear_fst = module_hom_fst
```
```    54   and linear_snd = module_hom_snd
```
```    55
```
```    56 end
```
```    57
```
```    58
```
```    59 subsection \<open>Product is a real vector space\<close>
```
```    60
```
```    61 instantiation%important prod :: (real_vector, real_vector) real_vector
```
```    62 begin
```
```    63
```
```    64 definition scaleR_prod_def:
```
```    65   "scaleR r A = (scaleR r (fst A), scaleR r (snd A))"
```
```    66
```
```    67 lemma fst_scaleR [simp]: "fst (scaleR r A) = scaleR r (fst A)"
```
```    68   unfolding scaleR_prod_def by simp
```
```    69
```
```    70 lemma snd_scaleR [simp]: "snd (scaleR r A) = scaleR r (snd A)"
```
```    71   unfolding scaleR_prod_def by simp
```
```    72
```
```    73 lemma scaleR_Pair [simp]: "scaleR r (a, b) = (scaleR r a, scaleR r b)"
```
```    74   unfolding scaleR_prod_def by simp
```
```    75
```
```    76 instance
```
```    77 proof
```
```    78   fix a b :: real and x y :: "'a \<times> 'b"
```
```    79   show "scaleR a (x + y) = scaleR a x + scaleR a y"
```
```    80     by (simp add: prod_eq_iff scaleR_right_distrib)
```
```    81   show "scaleR (a + b) x = scaleR a x + scaleR b x"
```
```    82     by (simp add: prod_eq_iff scaleR_left_distrib)
```
```    83   show "scaleR a (scaleR b x) = scaleR (a * b) x"
```
```    84     by (simp add: prod_eq_iff)
```
```    85   show "scaleR 1 x = x"
```
```    86     by (simp add: prod_eq_iff)
```
```    87 qed
```
```    88
```
```    89 end
```
```    90
```
```    91 lemma module_prod_scale_eq_scaleR: "module_prod.scale ( *\<^sub>R) ( *\<^sub>R) = scaleR"
```
```    92   apply (rule ext) apply (rule ext)
```
```    93   apply (subst module_prod.scale_def)
```
```    94   subgoal by unfold_locales
```
```    95   by (simp add: scaleR_prod_def)
```
```    96
```
```    97 interpretation real_vector?: vector_space_prod "scaleR::_\<Rightarrow>_\<Rightarrow>'a::real_vector" "scaleR::_\<Rightarrow>_\<Rightarrow>'b::real_vector"
```
```    98   rewrites "scale = (( *\<^sub>R)::_\<Rightarrow>_\<Rightarrow>('a \<times> 'b))"
```
```    99     and "module.dependent ( *\<^sub>R) = dependent"
```
```   100     and "module.representation ( *\<^sub>R) = representation"
```
```   101     and "module.subspace ( *\<^sub>R) = subspace"
```
```   102     and "module.span ( *\<^sub>R) = span"
```
```   103     and "vector_space.extend_basis ( *\<^sub>R) = extend_basis"
```
```   104     and "vector_space.dim ( *\<^sub>R) = dim"
```
```   105     and "Vector_Spaces.linear ( *\<^sub>R) ( *\<^sub>R) = linear"
```
```   106   subgoal by unfold_locales
```
```   107   subgoal by (fact module_prod_scale_eq_scaleR)
```
```   108   unfolding dependent_raw_def representation_raw_def subspace_raw_def span_raw_def
```
```   109     extend_basis_raw_def dim_raw_def linear_def
```
```   110   by (rule refl)+
```
```   111
```
```   112 subsection \<open>Product is a metric space\<close>
```
```   113
```
```   114 (* TODO: Product of uniform spaces and compatibility with metric_spaces! *)
```
```   115
```
```   116 instantiation%important prod :: (metric_space, metric_space) dist
```
```   117 begin
```
```   118
```
```   119 definition%important dist_prod_def[code del]:
```
```   120   "dist x y = sqrt ((dist (fst x) (fst y))\<^sup>2 + (dist (snd x) (snd y))\<^sup>2)"
```
```   121
```
```   122 instance ..
```
```   123 end
```
```   124
```
```   125 instantiation prod :: (metric_space, metric_space) uniformity_dist
```
```   126 begin
```
```   127
```
```   128 definition [code del]:
```
```   129   "(uniformity :: (('a \<times> 'b) \<times> ('a \<times> 'b)) filter) =
```
```   130     (INF e:{0 <..}. principal {(x, y). dist x y < e})"
```
```   131
```
```   132 instance
```
```   133   by standard (rule uniformity_prod_def)
```
```   134 end
```
```   135
```
```   136 declare uniformity_Abort[where 'a="'a :: metric_space \<times> 'b :: metric_space", code]
```
```   137
```
```   138 instantiation%important prod :: (metric_space, metric_space) metric_space
```
```   139 begin
```
```   140
```
```   141 lemma dist_Pair_Pair: "dist (a, b) (c, d) = sqrt ((dist a c)\<^sup>2 + (dist b d)\<^sup>2)"
```
```   142   unfolding dist_prod_def by simp
```
```   143
```
```   144 lemma dist_fst_le: "dist (fst x) (fst y) \<le> dist x y"
```
```   145   unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge1)
```
```   146
```
```   147 lemma dist_snd_le: "dist (snd x) (snd y) \<le> dist x y"
```
```   148   unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge2)
```
```   149
```
```   150 instance
```
```   151 proof
```
```   152   fix x y :: "'a \<times> 'b"
```
```   153   show "dist x y = 0 \<longleftrightarrow> x = y"
```
```   154     unfolding dist_prod_def prod_eq_iff by simp
```
```   155 next
```
```   156   fix x y z :: "'a \<times> 'b"
```
```   157   show "dist x y \<le> dist x z + dist y z"
```
```   158     unfolding dist_prod_def
```
```   159     by (intro order_trans [OF _ real_sqrt_sum_squares_triangle_ineq]
```
```   160         real_sqrt_le_mono add_mono power_mono dist_triangle2 zero_le_dist)
```
```   161 next
```
```   162   fix S :: "('a \<times> 'b) set"
```
```   163   have *: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
```
```   164   proof
```
```   165     assume "open S" show "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S"
```
```   166     proof
```
```   167       fix x assume "x \<in> S"
```
```   168       obtain A B where "open A" "open B" "x \<in> A \<times> B" "A \<times> B \<subseteq> S"
```
```   169         using \<open>open S\<close> and \<open>x \<in> S\<close> by (rule open_prod_elim)
```
```   170       obtain r where r: "0 < r" "\<forall>y. dist y (fst x) < r \<longrightarrow> y \<in> A"
```
```   171         using \<open>open A\<close> and \<open>x \<in> A \<times> B\<close> unfolding open_dist by auto
```
```   172       obtain s where s: "0 < s" "\<forall>y. dist y (snd x) < s \<longrightarrow> y \<in> B"
```
```   173         using \<open>open B\<close> and \<open>x \<in> A \<times> B\<close> unfolding open_dist by auto
```
```   174       let ?e = "min r s"
```
```   175       have "0 < ?e \<and> (\<forall>y. dist y x < ?e \<longrightarrow> y \<in> S)"
```
```   176       proof (intro allI impI conjI)
```
```   177         show "0 < min r s" by (simp add: r(1) s(1))
```
```   178       next
```
```   179         fix y assume "dist y x < min r s"
```
```   180         hence "dist y x < r" and "dist y x < s"
```
```   181           by simp_all
```
```   182         hence "dist (fst y) (fst x) < r" and "dist (snd y) (snd x) < s"
```
```   183           by (auto intro: le_less_trans dist_fst_le dist_snd_le)
```
```   184         hence "fst y \<in> A" and "snd y \<in> B"
```
```   185           by (simp_all add: r(2) s(2))
```
```   186         hence "y \<in> A \<times> B" by (induct y, simp)
```
```   187         with \<open>A \<times> B \<subseteq> S\<close> show "y \<in> S" ..
```
```   188       qed
```
```   189       thus "\<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" ..
```
```   190     qed
```
```   191   next
```
```   192     assume *: "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" show "open S"
```
```   193     proof (rule open_prod_intro)
```
```   194       fix x assume "x \<in> S"
```
```   195       then obtain e where "0 < e" and S: "\<forall>y. dist y x < e \<longrightarrow> y \<in> S"
```
```   196         using * by fast
```
```   197       define r where "r = e / sqrt 2"
```
```   198       define s where "s = e / sqrt 2"
```
```   199       from \<open>0 < e\<close> have "0 < r" and "0 < s"
```
```   200         unfolding r_def s_def by simp_all
```
```   201       from \<open>0 < e\<close> have "e = sqrt (r\<^sup>2 + s\<^sup>2)"
```
```   202         unfolding r_def s_def by (simp add: power_divide)
```
```   203       define A where "A = {y. dist (fst x) y < r}"
```
```   204       define B where "B = {y. dist (snd x) y < s}"
```
```   205       have "open A" and "open B"
```
```   206         unfolding A_def B_def by (simp_all add: open_ball)
```
```   207       moreover have "x \<in> A \<times> B"
```
```   208         unfolding A_def B_def mem_Times_iff
```
```   209         using \<open>0 < r\<close> and \<open>0 < s\<close> by simp
```
```   210       moreover have "A \<times> B \<subseteq> S"
```
```   211       proof (clarify)
```
```   212         fix a b assume "a \<in> A" and "b \<in> B"
```
```   213         hence "dist a (fst x) < r" and "dist b (snd x) < s"
```
```   214           unfolding A_def B_def by (simp_all add: dist_commute)
```
```   215         hence "dist (a, b) x < e"
```
```   216           unfolding dist_prod_def \<open>e = sqrt (r\<^sup>2 + s\<^sup>2)\<close>
```
```   217           by (simp add: add_strict_mono power_strict_mono)
```
```   218         thus "(a, b) \<in> S"
```
```   219           by (simp add: S)
```
```   220       qed
```
```   221       ultimately show "\<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S" by fast
```
```   222     qed
```
```   223   qed
```
```   224   show "open S = (\<forall>x\<in>S. \<forall>\<^sub>F (x', y) in uniformity. x' = x \<longrightarrow> y \<in> S)"
```
```   225     unfolding * eventually_uniformity_metric
```
```   226     by (simp del: split_paired_All add: dist_prod_def dist_commute)
```
```   227 qed
```
```   228
```
```   229 end
```
```   230
```
```   231 declare [[code abort: "dist::('a::metric_space*'b::metric_space)\<Rightarrow>('a*'b) \<Rightarrow> real"]]
```
```   232
```
```   233 lemma Cauchy_fst: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. fst (X n))"
```
```   234   unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_fst_le])
```
```   235
```
```   236 lemma Cauchy_snd: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. snd (X n))"
```
```   237   unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_snd_le])
```
```   238
```
```   239 lemma Cauchy_Pair:
```
```   240   assumes "Cauchy X" and "Cauchy Y"
```
```   241   shows "Cauchy (\<lambda>n. (X n, Y n))"
```
```   242 proof (rule metric_CauchyI)
```
```   243   fix r :: real assume "0 < r"
```
```   244   hence "0 < r / sqrt 2" (is "0 < ?s") by simp
```
```   245   obtain M where M: "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < ?s"
```
```   246     using metric_CauchyD [OF \<open>Cauchy X\<close> \<open>0 < ?s\<close>] ..
```
```   247   obtain N where N: "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (Y m) (Y n) < ?s"
```
```   248     using metric_CauchyD [OF \<open>Cauchy Y\<close> \<open>0 < ?s\<close>] ..
```
```   249   have "\<forall>m\<ge>max M N. \<forall>n\<ge>max M N. dist (X m, Y m) (X n, Y n) < r"
```
```   250     using M N by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
```
```   251   then show "\<exists>n0. \<forall>m\<ge>n0. \<forall>n\<ge>n0. dist (X m, Y m) (X n, Y n) < r" ..
```
```   252 qed
```
```   253
```
```   254 subsection \<open>Product is a complete metric space\<close>
```
```   255
```
```   256 instance%important prod :: (complete_space, complete_space) complete_space
```
```   257 proof%unimportant
```
```   258   fix X :: "nat \<Rightarrow> 'a \<times> 'b" assume "Cauchy X"
```
```   259   have 1: "(\<lambda>n. fst (X n)) \<longlonglongrightarrow> lim (\<lambda>n. fst (X n))"
```
```   260     using Cauchy_fst [OF \<open>Cauchy X\<close>]
```
```   261     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
```
```   262   have 2: "(\<lambda>n. snd (X n)) \<longlonglongrightarrow> lim (\<lambda>n. snd (X n))"
```
```   263     using Cauchy_snd [OF \<open>Cauchy X\<close>]
```
```   264     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
```
```   265   have "X \<longlonglongrightarrow> (lim (\<lambda>n. fst (X n)), lim (\<lambda>n. snd (X n)))"
```
```   266     using tendsto_Pair [OF 1 2] by simp
```
```   267   then show "convergent X"
```
```   268     by (rule convergentI)
```
```   269 qed
```
```   270
```
```   271 subsection \<open>Product is a normed vector space\<close>
```
```   272
```
```   273 instantiation%important prod :: (real_normed_vector, real_normed_vector) real_normed_vector
```
```   274 begin
```
```   275
```
```   276 definition norm_prod_def[code del]:
```
```   277   "norm x = sqrt ((norm (fst x))\<^sup>2 + (norm (snd x))\<^sup>2)"
```
```   278
```
```   279 definition sgn_prod_def:
```
```   280   "sgn (x::'a \<times> 'b) = scaleR (inverse (norm x)) x"
```
```   281
```
```   282 lemma norm_Pair: "norm (a, b) = sqrt ((norm a)\<^sup>2 + (norm b)\<^sup>2)"
```
```   283   unfolding norm_prod_def by simp
```
```   284
```
```   285 instance
```
```   286 proof
```
```   287   fix r :: real and x y :: "'a \<times> 'b"
```
```   288   show "norm x = 0 \<longleftrightarrow> x = 0"
```
```   289     unfolding norm_prod_def
```
```   290     by (simp add: prod_eq_iff)
```
```   291   show "norm (x + y) \<le> norm x + norm y"
```
```   292     unfolding norm_prod_def
```
```   293     apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
```
```   294     apply (simp add: add_mono power_mono norm_triangle_ineq)
```
```   295     done
```
```   296   show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
```
```   297     unfolding norm_prod_def
```
```   298     apply (simp add: power_mult_distrib)
```
```   299     apply (simp add: distrib_left [symmetric])
```
```   300     apply (simp add: real_sqrt_mult_distrib)
```
```   301     done
```
```   302   show "sgn x = scaleR (inverse (norm x)) x"
```
```   303     by (rule sgn_prod_def)
```
```   304   show "dist x y = norm (x - y)"
```
```   305     unfolding dist_prod_def norm_prod_def
```
```   306     by (simp add: dist_norm)
```
```   307 qed
```
```   308
```
```   309 end
```
```   310
```
```   311 declare [[code abort: "norm::('a::real_normed_vector*'b::real_normed_vector) \<Rightarrow> real"]]
```
```   312
```
```   313 instance prod :: (banach, banach) banach ..
```
```   314
```
```   315 subsubsection%unimportant \<open>Pair operations are linear\<close>
```
```   316
```
```   317 proposition bounded_linear_fst: "bounded_linear fst"
```
```   318   using fst_add fst_scaleR
```
```   319   by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
```
```   320
```
```   321 proposition bounded_linear_snd: "bounded_linear snd"
```
```   322   using snd_add snd_scaleR
```
```   323   by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
```
```   324
```
```   325 lemmas bounded_linear_fst_comp = bounded_linear_fst[THEN bounded_linear_compose]
```
```   326
```
```   327 lemmas bounded_linear_snd_comp = bounded_linear_snd[THEN bounded_linear_compose]
```
```   328
```
```   329 lemma bounded_linear_Pair:
```
```   330   assumes f: "bounded_linear f"
```
```   331   assumes g: "bounded_linear g"
```
```   332   shows "bounded_linear (\<lambda>x. (f x, g x))"
```
```   333 proof
```
```   334   interpret f: bounded_linear f by fact
```
```   335   interpret g: bounded_linear g by fact
```
```   336   fix x y and r :: real
```
```   337   show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
```
```   338     by (simp add: f.add g.add)
```
```   339   show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
```
```   340     by (simp add: f.scale g.scale)
```
```   341   obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
```
```   342     using f.pos_bounded by fast
```
```   343   obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
```
```   344     using g.pos_bounded by fast
```
```   345   have "\<forall>x. norm (f x, g x) \<le> norm x * (Kf + Kg)"
```
```   346     apply (rule allI)
```
```   347     apply (simp add: norm_Pair)
```
```   348     apply (rule order_trans [OF sqrt_add_le_add_sqrt], simp, simp)
```
```   349     apply (simp add: distrib_left)
```
```   350     apply (rule add_mono [OF norm_f norm_g])
```
```   351     done
```
```   352   then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
```
```   353 qed
```
```   354
```
```   355 subsubsection%unimportant \<open>Frechet derivatives involving pairs\<close>
```
```   356
```
```   357 proposition has_derivative_Pair [derivative_intros]:
```
```   358   assumes f: "(f has_derivative f') (at x within s)" and g: "(g has_derivative g') (at x within s)"
```
```   359   shows "((\<lambda>x. (f x, g x)) has_derivative (\<lambda>h. (f' h, g' h))) (at x within s)"
```
```   360 proof (rule has_derivativeI_sandwich[of 1])
```
```   361   show "bounded_linear (\<lambda>h. (f' h, g' h))"
```
```   362     using f g by (intro bounded_linear_Pair has_derivative_bounded_linear)
```
```   363   let ?Rf = "\<lambda>y. f y - f x - f' (y - x)"
```
```   364   let ?Rg = "\<lambda>y. g y - g x - g' (y - x)"
```
```   365   let ?R = "\<lambda>y. ((f y, g y) - (f x, g x) - (f' (y - x), g' (y - x)))"
```
```   366
```
```   367   show "((\<lambda>y. norm (?Rf y) / norm (y - x) + norm (?Rg y) / norm (y - x)) \<longlongrightarrow> 0) (at x within s)"
```
```   368     using f g by (intro tendsto_add_zero) (auto simp: has_derivative_iff_norm)
```
```   369
```
```   370   fix y :: 'a assume "y \<noteq> x"
```
```   371   show "norm (?R y) / norm (y - x) \<le> norm (?Rf y) / norm (y - x) + norm (?Rg y) / norm (y - x)"
```
```   372     unfolding add_divide_distrib [symmetric]
```
```   373     by (simp add: norm_Pair divide_right_mono order_trans [OF sqrt_add_le_add_sqrt])
```
```   374 qed simp
```
```   375
```
```   376 lemma differentiable_Pair [simp, derivative_intros]:
```
```   377   "f differentiable at x within s \<Longrightarrow> g differentiable at x within s \<Longrightarrow>
```
```   378     (\<lambda>x. (f x, g x)) differentiable at x within s"
```
```   379   unfolding differentiable_def by (blast intro: has_derivative_Pair)
```
```   380
```
```   381 lemmas has_derivative_fst [derivative_intros] = bounded_linear.has_derivative [OF bounded_linear_fst]
```
```   382 lemmas has_derivative_snd [derivative_intros] = bounded_linear.has_derivative [OF bounded_linear_snd]
```
```   383
```
```   384 lemma has_derivative_split [derivative_intros]:
```
```   385   "((\<lambda>p. f (fst p) (snd p)) has_derivative f') F \<Longrightarrow> ((\<lambda>(a, b). f a b) has_derivative f') F"
```
```   386   unfolding split_beta' .
```
```   387
```
```   388
```
```   389 subsubsection%unimportant \<open>Vector derivatives involving pairs\<close>
```
```   390
```
```   391 lemma has_vector_derivative_Pair[derivative_intros]:
```
```   392   assumes "(f has_vector_derivative f') (at x within s)"
```
```   393     "(g has_vector_derivative g') (at x within s)"
```
```   394   shows "((\<lambda>x. (f x, g x)) has_vector_derivative (f', g')) (at x within s)"
```
```   395   using assms
```
```   396   by (auto simp: has_vector_derivative_def intro!: derivative_eq_intros)
```
```   397
```
```   398
```
```   399 subsection \<open>Product is an inner product space\<close>
```
```   400
```
```   401 instantiation%important prod :: (real_inner, real_inner) real_inner
```
```   402 begin
```
```   403
```
```   404 definition inner_prod_def:
```
```   405   "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
```
```   406
```
```   407 lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
```
```   408   unfolding inner_prod_def by simp
```
```   409
```
```   410 instance
```
```   411 proof
```
```   412   fix r :: real
```
```   413   fix x y z :: "'a::real_inner \<times> 'b::real_inner"
```
```   414   show "inner x y = inner y x"
```
```   415     unfolding inner_prod_def
```
```   416     by (simp add: inner_commute)
```
```   417   show "inner (x + y) z = inner x z + inner y z"
```
```   418     unfolding inner_prod_def
```
```   419     by (simp add: inner_add_left)
```
```   420   show "inner (scaleR r x) y = r * inner x y"
```
```   421     unfolding inner_prod_def
```
```   422     by (simp add: distrib_left)
```
```   423   show "0 \<le> inner x x"
```
```   424     unfolding inner_prod_def
```
```   425     by (intro add_nonneg_nonneg inner_ge_zero)
```
```   426   show "inner x x = 0 \<longleftrightarrow> x = 0"
```
```   427     unfolding inner_prod_def prod_eq_iff
```
```   428     by (simp add: add_nonneg_eq_0_iff)
```
```   429   show "norm x = sqrt (inner x x)"
```
```   430     unfolding norm_prod_def inner_prod_def
```
```   431     by (simp add: power2_norm_eq_inner)
```
```   432 qed
```
```   433
```
```   434 end
```
```   435
```
```   436 lemma inner_Pair_0: "inner x (0, b) = inner (snd x) b" "inner x (a, 0) = inner (fst x) a"
```
```   437     by (cases x, simp)+
```
```   438
```
```   439 lemma
```
```   440   fixes x :: "'a::real_normed_vector"
```
```   441   shows norm_Pair1 [simp]: "norm (0,x) = norm x"
```
```   442     and norm_Pair2 [simp]: "norm (x,0) = norm x"
```
```   443 by (auto simp: norm_Pair)
```
```   444
```
```   445 lemma norm_commute: "norm (x,y) = norm (y,x)"
```
```   446   by (simp add: norm_Pair)
```
```   447
```
```   448 lemma norm_fst_le: "norm x \<le> norm (x,y)"
```
```   449   by (metis dist_fst_le fst_conv fst_zero norm_conv_dist)
```
```   450
```
```   451 lemma norm_snd_le: "norm y \<le> norm (x,y)"
```
```   452   by (metis dist_snd_le snd_conv snd_zero norm_conv_dist)
```
```   453
```
```   454 lemma norm_Pair_le:
```
```   455   shows "norm (x, y) \<le> norm x + norm y"
```
```   456   unfolding norm_Pair
```
```   457   by (metis norm_ge_zero sqrt_sum_squares_le_sum)
```
```   458
```
```   459 lemma (in vector_space_prod) span_Times_sing1: "p.span ({0} \<times> B) = {0} \<times> vs2.span B"
```
```   460   apply (rule p.span_unique)
```
```   461   subgoal by (auto intro!: vs1.span_base vs2.span_base)
```
```   462   subgoal using vs1.subspace_single_0 vs2.subspace_span by (rule subspace_Times)
```
```   463   subgoal for T
```
```   464   proof safe
```
```   465     fix b
```
```   466     assume subset_T: "{0} \<times> B \<subseteq> T" and subspace: "p.subspace T" and b_span: "b \<in> vs2.span B"
```
```   467     then obtain t r where b: "b = (\<Sum>a\<in>t. r a *b a)" and t: "finite t" "t \<subseteq> B"
```
```   468       by (auto simp: vs2.span_explicit)
```
```   469     have "(0, b) = (\<Sum>b\<in>t. scale (r b) (0, b))"
```
```   470       unfolding b scale_prod sum_prod
```
```   471       by simp
```
```   472     also have "\<dots> \<in> T"
```
```   473       using \<open>t \<subseteq> B\<close> subset_T
```
```   474       by (auto intro!: p.subspace_sum p.subspace_scale subspace)
```
```   475     finally show "(0, b) \<in> T" .
```
```   476   qed
```
```   477   done
```
```   478
```
```   479 lemma (in vector_space_prod) span_Times_sing2: "p.span (A \<times> {0}) = vs1.span A \<times> {0}"
```
```   480   apply (rule p.span_unique)
```
```   481   subgoal by (auto intro!: vs1.span_base vs2.span_base)
```
```   482   subgoal using vs1.subspace_span vs2.subspace_single_0 by (rule subspace_Times)
```
```   483   subgoal for T
```
```   484   proof safe
```
```   485     fix a
```
```   486     assume subset_T: "A \<times> {0} \<subseteq> T" and subspace: "p.subspace T" and a_span: "a \<in> vs1.span A"
```
```   487     then obtain t r where a: "a = (\<Sum>a\<in>t. r a *a a)" and t: "finite t" "t \<subseteq> A"
```
```   488       by (auto simp: vs1.span_explicit)
```
```   489     have "(a, 0) = (\<Sum>a\<in>t. scale (r a) (a, 0))"
```
```   490       unfolding a scale_prod sum_prod
```
```   491       by simp
```
```   492     also have "\<dots> \<in> T"
```
```   493       using \<open>t \<subseteq> A\<close> subset_T
```
```   494       by (auto intro!: p.subspace_sum p.subspace_scale subspace)
```
```   495     finally show "(a, 0) \<in> T" .
```
```   496   qed
```
```   497   done
```
```   498
```
```   499 lemma (in finite_dimensional_vector_space) zero_not_in_Basis[simp]: "0 \<notin> Basis"
```
```   500   using dependent_zero local.independent_Basis by blast
```
```   501
```
```   502 locale finite_dimensional_vector_space_prod = vector_space_prod + finite_dimensional_vector_space_pair begin
```
```   503
```
```   504 definition "Basis_pair = B1 \<times> {0} \<union> {0} \<times> B2"
```
```   505
```
```   506 sublocale p: finite_dimensional_vector_space scale Basis_pair
```
```   507 proof unfold_locales
```
```   508   show "finite Basis_pair"
```
```   509     by (auto intro!: finite_cartesian_product vs1.finite_Basis vs2.finite_Basis simp: Basis_pair_def)
```
```   510   show "p.independent Basis_pair"
```
```   511     unfolding p.dependent_def Basis_pair_def
```
```   512   proof safe
```
```   513     fix a
```
```   514     assume a: "a \<in> B1"
```
```   515     assume "(a, 0) \<in> p.span (B1 \<times> {0} \<union> {0} \<times> B2 - {(a, 0)})"
```
```   516     also have "B1 \<times> {0} \<union> {0} \<times> B2 - {(a, 0)} = (B1 - {a}) \<times> {0} \<union> {0} \<times> B2"
```
```   517       by auto
```
```   518     finally show False
```
```   519       using a vs1.dependent_def vs1.independent_Basis
```
```   520       by (auto simp: p.span_Un span_Times_sing1 span_Times_sing2)
```
```   521   next
```
```   522     fix b
```
```   523     assume b: "b \<in> B2"
```
```   524     assume "(0, b) \<in> p.span (B1 \<times> {0} \<union> {0} \<times> B2 - {(0, b)})"
```
```   525     also have "(B1 \<times> {0} \<union> {0} \<times> B2 - {(0, b)}) = B1 \<times> {0} \<union> {0} \<times> (B2 - {b})"
```
```   526       by auto
```
```   527     finally show False
```
```   528       using b vs2.dependent_def vs2.independent_Basis
```
```   529       by (auto simp: p.span_Un span_Times_sing1 span_Times_sing2)
```
```   530   qed
```
```   531   show "p.span Basis_pair = UNIV"
```
```   532     by (auto simp: p.span_Un span_Times_sing2 span_Times_sing1 vs1.span_Basis vs2.span_Basis
```
```   533         Basis_pair_def)
```
```   534 qed
```
```   535
```
```   536 lemma dim_Times:
```
```   537   assumes "vs1.subspace S" "vs2.subspace T"
```
```   538   shows "p.dim(S \<times> T) = vs1.dim S + vs2.dim T"
```
```   539 proof -
```
```   540   interpret p1: Vector_Spaces.linear s1 scale "(\<lambda>x. (x, 0))"
```
```   541     by unfold_locales (auto simp: scale_def)
```
```   542   interpret pair1: finite_dimensional_vector_space_pair "( *a)" B1 scale Basis_pair
```
```   543     by unfold_locales
```
```   544   interpret p2: Vector_Spaces.linear s2 scale "(\<lambda>x. (0, x))"
```
```   545     by unfold_locales (auto simp: scale_def)
```
```   546   interpret pair2: finite_dimensional_vector_space_pair "( *b)" B2 scale Basis_pair
```
```   547     by unfold_locales
```
```   548   have ss: "p.subspace ((\<lambda>x. (x, 0)) ` S)" "p.subspace (Pair 0 ` T)"
```
```   549     by (rule p1.subspace_image p2.subspace_image assms)+
```
```   550   have "p.dim(S \<times> T) = p.dim({u + v |u v. u \<in> (\<lambda>x. (x, 0)) ` S \<and> v \<in> Pair 0 ` T})"
```
```   551     by (simp add: Times_eq_image_sum)
```
```   552   moreover have "p.dim ((\<lambda>x. (x, 0::'c)) ` S) = vs1.dim S" "p.dim (Pair (0::'b) ` T) = vs2.dim T"
```
```   553      by (simp_all add: inj_on_def p1.linear_axioms pair1.dim_image_eq p2.linear_axioms pair2.dim_image_eq)
```
```   554   moreover have "p.dim ((\<lambda>x. (x, 0)) ` S \<inter> Pair 0 ` T) = 0"
```
```   555     by (subst p.dim_eq_0) auto
```
```   556   ultimately show ?thesis
```
```   557     using p.dim_sums_Int [OF ss] by linarith
```
```   558 qed
```
```   559
```
```   560 lemma dimension_pair: "p.dimension = vs1.dimension + vs2.dimension"
```
```   561   using dim_Times[OF vs1.subspace_UNIV vs2.subspace_UNIV]
```
```   562   by (auto simp: p.dim_UNIV vs1.dim_UNIV vs2.dim_UNIV
```
```   563       p.dimension_def vs1.dimension_def vs2.dimension_def)
```
```   564
```
```   565 end
```
```   566
```
```   567 end
```