src/HOL/Library/Product_Vector.thy
author huffman
Tue May 04 10:06:05 2010 -0700 (2010-05-04)
changeset 36660 1cc4ab4b7ff7
parent 36332 3ddb2bc07784
child 36661 0a5b7b818d65
permissions -rw-r--r--
make (X ----> L) an abbreviation for (X ---> L) sequentially
     1 (*  Title:      HOL/Library/Product_Vector.thy
     2     Author:     Brian Huffman
     3 *)
     4 
     5 header {* Cartesian Products as Vector Spaces *}
     6 
     7 theory Product_Vector
     8 imports Inner_Product Product_plus
     9 begin
    10 
    11 subsection {* Product is a real vector space *}
    12 
    13 instantiation "*" :: (real_vector, real_vector) real_vector
    14 begin
    15 
    16 definition scaleR_prod_def:
    17   "scaleR r A = (scaleR r (fst A), scaleR r (snd A))"
    18 
    19 lemma fst_scaleR [simp]: "fst (scaleR r A) = scaleR r (fst A)"
    20   unfolding scaleR_prod_def by simp
    21 
    22 lemma snd_scaleR [simp]: "snd (scaleR r A) = scaleR r (snd A)"
    23   unfolding scaleR_prod_def by simp
    24 
    25 lemma scaleR_Pair [simp]: "scaleR r (a, b) = (scaleR r a, scaleR r b)"
    26   unfolding scaleR_prod_def by simp
    27 
    28 instance proof
    29   fix a b :: real and x y :: "'a \<times> 'b"
    30   show "scaleR a (x + y) = scaleR a x + scaleR a y"
    31     by (simp add: expand_prod_eq scaleR_right_distrib)
    32   show "scaleR (a + b) x = scaleR a x + scaleR b x"
    33     by (simp add: expand_prod_eq scaleR_left_distrib)
    34   show "scaleR a (scaleR b x) = scaleR (a * b) x"
    35     by (simp add: expand_prod_eq)
    36   show "scaleR 1 x = x"
    37     by (simp add: expand_prod_eq)
    38 qed
    39 
    40 end
    41 
    42 subsection {* Product is a topological space *}
    43 
    44 instantiation
    45   "*" :: (topological_space, topological_space) topological_space
    46 begin
    47 
    48 definition open_prod_def:
    49   "open (S :: ('a \<times> 'b) set) \<longleftrightarrow>
    50     (\<forall>x\<in>S. \<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S)"
    51 
    52 lemma open_prod_elim:
    53   assumes "open S" and "x \<in> S"
    54   obtains A B where "open A" and "open B" and "x \<in> A \<times> B" and "A \<times> B \<subseteq> S"
    55 using assms unfolding open_prod_def by fast
    56 
    57 lemma open_prod_intro:
    58   assumes "\<And>x. x \<in> S \<Longrightarrow> \<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S"
    59   shows "open S"
    60 using assms unfolding open_prod_def by fast
    61 
    62 instance proof
    63   show "open (UNIV :: ('a \<times> 'b) set)"
    64     unfolding open_prod_def by auto
    65 next
    66   fix S T :: "('a \<times> 'b) set"
    67   assume "open S" "open T"
    68   show "open (S \<inter> T)"
    69   proof (rule open_prod_intro)
    70     fix x assume x: "x \<in> S \<inter> T"
    71     from x have "x \<in> S" by simp
    72     obtain Sa Sb where A: "open Sa" "open Sb" "x \<in> Sa \<times> Sb" "Sa \<times> Sb \<subseteq> S"
    73       using `open S` and `x \<in> S` by (rule open_prod_elim)
    74     from x have "x \<in> T" by simp
    75     obtain Ta Tb where B: "open Ta" "open Tb" "x \<in> Ta \<times> Tb" "Ta \<times> Tb \<subseteq> T"
    76       using `open T` and `x \<in> T` by (rule open_prod_elim)
    77     let ?A = "Sa \<inter> Ta" and ?B = "Sb \<inter> Tb"
    78     have "open ?A \<and> open ?B \<and> x \<in> ?A \<times> ?B \<and> ?A \<times> ?B \<subseteq> S \<inter> T"
    79       using A B by (auto simp add: open_Int)
    80     thus "\<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S \<inter> T"
    81       by fast
    82   qed
    83 next
    84   fix K :: "('a \<times> 'b) set set"
    85   assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)"
    86     unfolding open_prod_def by fast
    87 qed
    88 
    89 end
    90 
    91 lemma open_Times: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<times> T)"
    92 unfolding open_prod_def by auto
    93 
    94 lemma fst_vimage_eq_Times: "fst -` S = S \<times> UNIV"
    95 by auto
    96 
    97 lemma snd_vimage_eq_Times: "snd -` S = UNIV \<times> S"
    98 by auto
    99 
   100 lemma open_vimage_fst: "open S \<Longrightarrow> open (fst -` S)"
   101 by (simp add: fst_vimage_eq_Times open_Times)
   102 
   103 lemma open_vimage_snd: "open S \<Longrightarrow> open (snd -` S)"
   104 by (simp add: snd_vimage_eq_Times open_Times)
   105 
   106 lemma closed_vimage_fst: "closed S \<Longrightarrow> closed (fst -` S)"
   107 unfolding closed_open vimage_Compl [symmetric]
   108 by (rule open_vimage_fst)
   109 
   110 lemma closed_vimage_snd: "closed S \<Longrightarrow> closed (snd -` S)"
   111 unfolding closed_open vimage_Compl [symmetric]
   112 by (rule open_vimage_snd)
   113 
   114 lemma closed_Times: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<times> T)"
   115 proof -
   116   have "S \<times> T = (fst -` S) \<inter> (snd -` T)" by auto
   117   thus "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<times> T)"
   118     by (simp add: closed_vimage_fst closed_vimage_snd closed_Int)
   119 qed
   120 
   121 lemma openI: (* TODO: move *)
   122   assumes "\<And>x. x \<in> S \<Longrightarrow> \<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> S"
   123   shows "open S"
   124 proof -
   125   have "open (\<Union>{T. open T \<and> T \<subseteq> S})" by auto
   126   moreover have "\<Union>{T. open T \<and> T \<subseteq> S} = S" by (auto dest!: assms)
   127   ultimately show "open S" by simp
   128 qed
   129 
   130 lemma subset_fst_imageI: "A \<times> B \<subseteq> S \<Longrightarrow> y \<in> B \<Longrightarrow> A \<subseteq> fst ` S"
   131   unfolding image_def subset_eq by force
   132 
   133 lemma subset_snd_imageI: "A \<times> B \<subseteq> S \<Longrightarrow> x \<in> A \<Longrightarrow> B \<subseteq> snd ` S"
   134   unfolding image_def subset_eq by force
   135 
   136 lemma open_image_fst: assumes "open S" shows "open (fst ` S)"
   137 proof (rule openI)
   138   fix x assume "x \<in> fst ` S"
   139   then obtain y where "(x, y) \<in> S" by auto
   140   then obtain A B where "open A" "open B" "x \<in> A" "y \<in> B" "A \<times> B \<subseteq> S"
   141     using `open S` unfolding open_prod_def by auto
   142   from `A \<times> B \<subseteq> S` `y \<in> B` have "A \<subseteq> fst ` S" by (rule subset_fst_imageI)
   143   with `open A` `x \<in> A` have "open A \<and> x \<in> A \<and> A \<subseteq> fst ` S" by simp
   144   then show "\<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> fst ` S" by - (rule exI)
   145 qed
   146 
   147 lemma open_image_snd: assumes "open S" shows "open (snd ` S)"
   148 proof (rule openI)
   149   fix y assume "y \<in> snd ` S"
   150   then obtain x where "(x, y) \<in> S" by auto
   151   then obtain A B where "open A" "open B" "x \<in> A" "y \<in> B" "A \<times> B \<subseteq> S"
   152     using `open S` unfolding open_prod_def by auto
   153   from `A \<times> B \<subseteq> S` `x \<in> A` have "B \<subseteq> snd ` S" by (rule subset_snd_imageI)
   154   with `open B` `y \<in> B` have "open B \<and> y \<in> B \<and> B \<subseteq> snd ` S" by simp
   155   then show "\<exists>T. open T \<and> y \<in> T \<and> T \<subseteq> snd ` S" by - (rule exI)
   156 qed
   157 
   158 subsection {* Product is a metric space *}
   159 
   160 instantiation
   161   "*" :: (metric_space, metric_space) metric_space
   162 begin
   163 
   164 definition dist_prod_def:
   165   "dist (x::'a \<times> 'b) y = sqrt ((dist (fst x) (fst y))\<twosuperior> + (dist (snd x) (snd y))\<twosuperior>)"
   166 
   167 lemma dist_Pair_Pair: "dist (a, b) (c, d) = sqrt ((dist a c)\<twosuperior> + (dist b d)\<twosuperior>)"
   168   unfolding dist_prod_def by simp
   169 
   170 lemma dist_fst_le: "dist (fst x) (fst y) \<le> dist x y"
   171 unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge1)
   172 
   173 lemma dist_snd_le: "dist (snd x) (snd y) \<le> dist x y"
   174 unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge2)
   175 
   176 instance proof
   177   fix x y :: "'a \<times> 'b"
   178   show "dist x y = 0 \<longleftrightarrow> x = y"
   179     unfolding dist_prod_def expand_prod_eq by simp
   180 next
   181   fix x y z :: "'a \<times> 'b"
   182   show "dist x y \<le> dist x z + dist y z"
   183     unfolding dist_prod_def
   184     by (intro order_trans [OF _ real_sqrt_sum_squares_triangle_ineq]
   185         real_sqrt_le_mono add_mono power_mono dist_triangle2 zero_le_dist)
   186 next
   187   (* FIXME: long proof! *)
   188   (* Maybe it would be easier to define topological spaces *)
   189   (* in terms of neighborhoods instead of open sets? *)
   190   fix S :: "('a \<times> 'b) set"
   191   show "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
   192   proof
   193     assume "open S" show "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S"
   194     proof
   195       fix x assume "x \<in> S"
   196       obtain A B where "open A" "open B" "x \<in> A \<times> B" "A \<times> B \<subseteq> S"
   197         using `open S` and `x \<in> S` by (rule open_prod_elim)
   198       obtain r where r: "0 < r" "\<forall>y. dist y (fst x) < r \<longrightarrow> y \<in> A"
   199         using `open A` and `x \<in> A \<times> B` unfolding open_dist by auto
   200       obtain s where s: "0 < s" "\<forall>y. dist y (snd x) < s \<longrightarrow> y \<in> B"
   201         using `open B` and `x \<in> A \<times> B` unfolding open_dist by auto
   202       let ?e = "min r s"
   203       have "0 < ?e \<and> (\<forall>y. dist y x < ?e \<longrightarrow> y \<in> S)"
   204       proof (intro allI impI conjI)
   205         show "0 < min r s" by (simp add: r(1) s(1))
   206       next
   207         fix y assume "dist y x < min r s"
   208         hence "dist y x < r" and "dist y x < s"
   209           by simp_all
   210         hence "dist (fst y) (fst x) < r" and "dist (snd y) (snd x) < s"
   211           by (auto intro: le_less_trans dist_fst_le dist_snd_le)
   212         hence "fst y \<in> A" and "snd y \<in> B"
   213           by (simp_all add: r(2) s(2))
   214         hence "y \<in> A \<times> B" by (induct y, simp)
   215         with `A \<times> B \<subseteq> S` show "y \<in> S" ..
   216       qed
   217       thus "\<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" ..
   218     qed
   219   next
   220     assume "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" thus "open S"
   221     unfolding open_prod_def open_dist
   222     apply safe
   223     apply (drule (1) bspec)
   224     apply clarify
   225     apply (subgoal_tac "\<exists>r>0. \<exists>s>0. e = sqrt (r\<twosuperior> + s\<twosuperior>)")
   226     apply clarify
   227     apply (rule_tac x="{y. dist y a < r}" in exI)
   228     apply (rule_tac x="{y. dist y b < s}" in exI)
   229     apply (rule conjI)
   230     apply clarify
   231     apply (rule_tac x="r - dist x a" in exI, rule conjI, simp)
   232     apply clarify
   233     apply (simp add: less_diff_eq)
   234     apply (erule le_less_trans [OF dist_triangle])
   235     apply (rule conjI)
   236     apply clarify
   237     apply (rule_tac x="s - dist x b" in exI, rule conjI, simp)
   238     apply clarify
   239     apply (simp add: less_diff_eq)
   240     apply (erule le_less_trans [OF dist_triangle])
   241     apply (rule conjI)
   242     apply simp
   243     apply (clarify, rename_tac c d)
   244     apply (drule spec, erule mp)
   245     apply (simp add: dist_Pair_Pair add_strict_mono power_strict_mono)
   246     apply (rule_tac x="e / sqrt 2" in exI, simp add: divide_pos_pos)
   247     apply (rule_tac x="e / sqrt 2" in exI, simp add: divide_pos_pos)
   248     apply (simp add: power_divide)
   249     done
   250   qed
   251 qed
   252 
   253 end
   254 
   255 subsection {* Continuity of operations *}
   256 
   257 lemma tendsto_fst [tendsto_intros]:
   258   assumes "(f ---> a) net"
   259   shows "((\<lambda>x. fst (f x)) ---> fst a) net"
   260 proof (rule topological_tendstoI)
   261   fix S assume "open S" "fst a \<in> S"
   262   then have "open (fst -` S)" "a \<in> fst -` S"
   263     unfolding open_prod_def
   264     apply simp_all
   265     apply clarify
   266     apply (rule exI, erule conjI)
   267     apply (rule exI, rule conjI [OF open_UNIV])
   268     apply auto
   269     done
   270   with assms have "eventually (\<lambda>x. f x \<in> fst -` S) net"
   271     by (rule topological_tendstoD)
   272   then show "eventually (\<lambda>x. fst (f x) \<in> S) net"
   273     by simp
   274 qed
   275 
   276 lemma tendsto_snd [tendsto_intros]:
   277   assumes "(f ---> a) net"
   278   shows "((\<lambda>x. snd (f x)) ---> snd a) net"
   279 proof (rule topological_tendstoI)
   280   fix S assume "open S" "snd a \<in> S"
   281   then have "open (snd -` S)" "a \<in> snd -` S"
   282     unfolding open_prod_def
   283     apply simp_all
   284     apply clarify
   285     apply (rule exI, rule conjI [OF open_UNIV])
   286     apply (rule exI, erule conjI)
   287     apply auto
   288     done
   289   with assms have "eventually (\<lambda>x. f x \<in> snd -` S) net"
   290     by (rule topological_tendstoD)
   291   then show "eventually (\<lambda>x. snd (f x) \<in> S) net"
   292     by simp
   293 qed
   294 
   295 lemma tendsto_Pair [tendsto_intros]:
   296   assumes "(f ---> a) net" and "(g ---> b) net"
   297   shows "((\<lambda>x. (f x, g x)) ---> (a, b)) net"
   298 proof (rule topological_tendstoI)
   299   fix S assume "open S" "(a, b) \<in> S"
   300   then obtain A B where "open A" "open B" "a \<in> A" "b \<in> B" "A \<times> B \<subseteq> S"
   301     unfolding open_prod_def by auto
   302   have "eventually (\<lambda>x. f x \<in> A) net"
   303     using `(f ---> a) net` `open A` `a \<in> A`
   304     by (rule topological_tendstoD)
   305   moreover
   306   have "eventually (\<lambda>x. g x \<in> B) net"
   307     using `(g ---> b) net` `open B` `b \<in> B`
   308     by (rule topological_tendstoD)
   309   ultimately
   310   show "eventually (\<lambda>x. (f x, g x) \<in> S) net"
   311     by (rule eventually_elim2)
   312        (simp add: subsetD [OF `A \<times> B \<subseteq> S`])
   313 qed
   314 
   315 lemma LIM_fst: "f -- x --> a \<Longrightarrow> (\<lambda>x. fst (f x)) -- x --> fst a"
   316 unfolding LIM_conv_tendsto by (rule tendsto_fst)
   317 
   318 lemma LIM_snd: "f -- x --> a \<Longrightarrow> (\<lambda>x. snd (f x)) -- x --> snd a"
   319 unfolding LIM_conv_tendsto by (rule tendsto_snd)
   320 
   321 lemma LIM_Pair:
   322   assumes "f -- x --> a" and "g -- x --> b"
   323   shows "(\<lambda>x. (f x, g x)) -- x --> (a, b)"
   324 using assms unfolding LIM_conv_tendsto
   325 by (rule tendsto_Pair)
   326 
   327 lemma Cauchy_fst: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. fst (X n))"
   328 unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_fst_le])
   329 
   330 lemma Cauchy_snd: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. snd (X n))"
   331 unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_snd_le])
   332 
   333 lemma Cauchy_Pair:
   334   assumes "Cauchy X" and "Cauchy Y"
   335   shows "Cauchy (\<lambda>n. (X n, Y n))"
   336 proof (rule metric_CauchyI)
   337   fix r :: real assume "0 < r"
   338   then have "0 < r / sqrt 2" (is "0 < ?s")
   339     by (simp add: divide_pos_pos)
   340   obtain M where M: "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < ?s"
   341     using metric_CauchyD [OF `Cauchy X` `0 < ?s`] ..
   342   obtain N where N: "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (Y m) (Y n) < ?s"
   343     using metric_CauchyD [OF `Cauchy Y` `0 < ?s`] ..
   344   have "\<forall>m\<ge>max M N. \<forall>n\<ge>max M N. dist (X m, Y m) (X n, Y n) < r"
   345     using M N by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
   346   then show "\<exists>n0. \<forall>m\<ge>n0. \<forall>n\<ge>n0. dist (X m, Y m) (X n, Y n) < r" ..
   347 qed
   348 
   349 lemma isCont_Pair [simp]:
   350   "\<lbrakk>isCont f x; isCont g x\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. (f x, g x)) x"
   351   unfolding isCont_def by (rule LIM_Pair)
   352 
   353 subsection {* Product is a complete metric space *}
   354 
   355 instance "*" :: (complete_space, complete_space) complete_space
   356 proof
   357   fix X :: "nat \<Rightarrow> 'a \<times> 'b" assume "Cauchy X"
   358   have 1: "(\<lambda>n. fst (X n)) ----> lim (\<lambda>n. fst (X n))"
   359     using Cauchy_fst [OF `Cauchy X`]
   360     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   361   have 2: "(\<lambda>n. snd (X n)) ----> lim (\<lambda>n. snd (X n))"
   362     using Cauchy_snd [OF `Cauchy X`]
   363     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   364   have "X ----> (lim (\<lambda>n. fst (X n)), lim (\<lambda>n. snd (X n)))"
   365     using tendsto_Pair [OF 1 2] by simp
   366   then show "convergent X"
   367     by (rule convergentI)
   368 qed
   369 
   370 subsection {* Product is a normed vector space *}
   371 
   372 instantiation
   373   "*" :: (real_normed_vector, real_normed_vector) real_normed_vector
   374 begin
   375 
   376 definition norm_prod_def:
   377   "norm x = sqrt ((norm (fst x))\<twosuperior> + (norm (snd x))\<twosuperior>)"
   378 
   379 definition sgn_prod_def:
   380   "sgn (x::'a \<times> 'b) = scaleR (inverse (norm x)) x"
   381 
   382 lemma norm_Pair: "norm (a, b) = sqrt ((norm a)\<twosuperior> + (norm b)\<twosuperior>)"
   383   unfolding norm_prod_def by simp
   384 
   385 instance proof
   386   fix r :: real and x y :: "'a \<times> 'b"
   387   show "0 \<le> norm x"
   388     unfolding norm_prod_def by simp
   389   show "norm x = 0 \<longleftrightarrow> x = 0"
   390     unfolding norm_prod_def
   391     by (simp add: expand_prod_eq)
   392   show "norm (x + y) \<le> norm x + norm y"
   393     unfolding norm_prod_def
   394     apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
   395     apply (simp add: add_mono power_mono norm_triangle_ineq)
   396     done
   397   show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
   398     unfolding norm_prod_def
   399     apply (simp add: power_mult_distrib)
   400     apply (simp add: right_distrib [symmetric])
   401     apply (simp add: real_sqrt_mult_distrib)
   402     done
   403   show "sgn x = scaleR (inverse (norm x)) x"
   404     by (rule sgn_prod_def)
   405   show "dist x y = norm (x - y)"
   406     unfolding dist_prod_def norm_prod_def
   407     by (simp add: dist_norm)
   408 qed
   409 
   410 end
   411 
   412 instance "*" :: (banach, banach) banach ..
   413 
   414 subsection {* Product is an inner product space *}
   415 
   416 instantiation "*" :: (real_inner, real_inner) real_inner
   417 begin
   418 
   419 definition inner_prod_def:
   420   "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
   421 
   422 lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
   423   unfolding inner_prod_def by simp
   424 
   425 instance proof
   426   fix r :: real
   427   fix x y z :: "'a::real_inner * 'b::real_inner"
   428   show "inner x y = inner y x"
   429     unfolding inner_prod_def
   430     by (simp add: inner_commute)
   431   show "inner (x + y) z = inner x z + inner y z"
   432     unfolding inner_prod_def
   433     by (simp add: inner_add_left)
   434   show "inner (scaleR r x) y = r * inner x y"
   435     unfolding inner_prod_def
   436     by (simp add: right_distrib)
   437   show "0 \<le> inner x x"
   438     unfolding inner_prod_def
   439     by (intro add_nonneg_nonneg inner_ge_zero)
   440   show "inner x x = 0 \<longleftrightarrow> x = 0"
   441     unfolding inner_prod_def expand_prod_eq
   442     by (simp add: add_nonneg_eq_0_iff)
   443   show "norm x = sqrt (inner x x)"
   444     unfolding norm_prod_def inner_prod_def
   445     by (simp add: power2_norm_eq_inner)
   446 qed
   447 
   448 end
   449 
   450 subsection {* Pair operations are linear *}
   451 
   452 interpretation fst: bounded_linear fst
   453   apply (unfold_locales)
   454   apply (rule fst_add)
   455   apply (rule fst_scaleR)
   456   apply (rule_tac x="1" in exI, simp add: norm_Pair)
   457   done
   458 
   459 interpretation snd: bounded_linear snd
   460   apply (unfold_locales)
   461   apply (rule snd_add)
   462   apply (rule snd_scaleR)
   463   apply (rule_tac x="1" in exI, simp add: norm_Pair)
   464   done
   465 
   466 text {* TODO: move to NthRoot *}
   467 lemma sqrt_add_le_add_sqrt:
   468   assumes x: "0 \<le> x" and y: "0 \<le> y"
   469   shows "sqrt (x + y) \<le> sqrt x + sqrt y"
   470 apply (rule power2_le_imp_le)
   471 apply (simp add: real_sum_squared_expand add_nonneg_nonneg x y)
   472 apply (simp add: mult_nonneg_nonneg x y)
   473 apply (simp add: add_nonneg_nonneg x y)
   474 done
   475 
   476 lemma bounded_linear_Pair:
   477   assumes f: "bounded_linear f"
   478   assumes g: "bounded_linear g"
   479   shows "bounded_linear (\<lambda>x. (f x, g x))"
   480 proof
   481   interpret f: bounded_linear f by fact
   482   interpret g: bounded_linear g by fact
   483   fix x y and r :: real
   484   show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
   485     by (simp add: f.add g.add)
   486   show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
   487     by (simp add: f.scaleR g.scaleR)
   488   obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
   489     using f.pos_bounded by fast
   490   obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
   491     using g.pos_bounded by fast
   492   have "\<forall>x. norm (f x, g x) \<le> norm x * (Kf + Kg)"
   493     apply (rule allI)
   494     apply (simp add: norm_Pair)
   495     apply (rule order_trans [OF sqrt_add_le_add_sqrt], simp, simp)
   496     apply (simp add: right_distrib)
   497     apply (rule add_mono [OF norm_f norm_g])
   498     done
   499   then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
   500 qed
   501 
   502 subsection {* Frechet derivatives involving pairs *}
   503 
   504 lemma FDERIV_Pair:
   505   assumes f: "FDERIV f x :> f'" and g: "FDERIV g x :> g'"
   506   shows "FDERIV (\<lambda>x. (f x, g x)) x :> (\<lambda>h. (f' h, g' h))"
   507 apply (rule FDERIV_I)
   508 apply (rule bounded_linear_Pair)
   509 apply (rule FDERIV_bounded_linear [OF f])
   510 apply (rule FDERIV_bounded_linear [OF g])
   511 apply (simp add: norm_Pair)
   512 apply (rule real_LIM_sandwich_zero)
   513 apply (rule LIM_add_zero)
   514 apply (rule FDERIV_D [OF f])
   515 apply (rule FDERIV_D [OF g])
   516 apply (rename_tac h)
   517 apply (simp add: divide_nonneg_pos)
   518 apply (rename_tac h)
   519 apply (subst add_divide_distrib [symmetric])
   520 apply (rule divide_right_mono [OF _ norm_ge_zero])
   521 apply (rule order_trans [OF sqrt_add_le_add_sqrt])
   522 apply simp
   523 apply simp
   524 apply simp
   525 done
   526 
   527 end