src/HOL/Library/Product_Vector.thy
author Andreas Lochbihler
Fri Sep 20 10:09:16 2013 +0200 (2013-09-20)
changeset 53745 788730ab7da4
parent 53015 a1119cf551e8
child 53930 896b642f2aab
permissions -rw-r--r--
prefer Code.abort over code_abort
     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 prod :: (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: prod_eq_iff scaleR_right_distrib)
    32   show "scaleR (a + b) x = scaleR a x + scaleR b x"
    33     by (simp add: prod_eq_iff scaleR_left_distrib)
    34   show "scaleR a (scaleR b x) = scaleR (a * b) x"
    35     by (simp add: prod_eq_iff)
    36   show "scaleR 1 x = x"
    37     by (simp add: prod_eq_iff)
    38 qed
    39 
    40 end
    41 
    42 subsection {* Product is a topological space *}
    43 
    44 instantiation prod :: (topological_space, topological_space) topological_space
    45 begin
    46 
    47 definition open_prod_def:
    48   "open (S :: ('a \<times> 'b) set) \<longleftrightarrow>
    49     (\<forall>x\<in>S. \<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S)"
    50 
    51 lemma open_prod_elim:
    52   assumes "open S" and "x \<in> S"
    53   obtains A B where "open A" and "open B" and "x \<in> A \<times> B" and "A \<times> B \<subseteq> S"
    54 using assms unfolding open_prod_def by fast
    55 
    56 lemma open_prod_intro:
    57   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"
    58   shows "open S"
    59 using assms unfolding open_prod_def by fast
    60 
    61 instance proof
    62   show "open (UNIV :: ('a \<times> 'b) set)"
    63     unfolding open_prod_def by auto
    64 next
    65   fix S T :: "('a \<times> 'b) set"
    66   assume "open S" "open T"
    67   show "open (S \<inter> T)"
    68   proof (rule open_prod_intro)
    69     fix x assume x: "x \<in> S \<inter> T"
    70     from x have "x \<in> S" by simp
    71     obtain Sa Sb where A: "open Sa" "open Sb" "x \<in> Sa \<times> Sb" "Sa \<times> Sb \<subseteq> S"
    72       using `open S` and `x \<in> S` by (rule open_prod_elim)
    73     from x have "x \<in> T" by simp
    74     obtain Ta Tb where B: "open Ta" "open Tb" "x \<in> Ta \<times> Tb" "Ta \<times> Tb \<subseteq> T"
    75       using `open T` and `x \<in> T` by (rule open_prod_elim)
    76     let ?A = "Sa \<inter> Ta" and ?B = "Sb \<inter> Tb"
    77     have "open ?A \<and> open ?B \<and> x \<in> ?A \<times> ?B \<and> ?A \<times> ?B \<subseteq> S \<inter> T"
    78       using A B by (auto simp add: open_Int)
    79     thus "\<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S \<inter> T"
    80       by fast
    81   qed
    82 next
    83   fix K :: "('a \<times> 'b) set set"
    84   assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)"
    85     unfolding open_prod_def by fast
    86 qed
    87 
    88 end
    89 
    90 lemma open_Times: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<times> T)"
    91 unfolding open_prod_def by auto
    92 
    93 lemma fst_vimage_eq_Times: "fst -` S = S \<times> UNIV"
    94 by auto
    95 
    96 lemma snd_vimage_eq_Times: "snd -` S = UNIV \<times> S"
    97 by auto
    98 
    99 lemma open_vimage_fst: "open S \<Longrightarrow> open (fst -` S)"
   100 by (simp add: fst_vimage_eq_Times open_Times)
   101 
   102 lemma open_vimage_snd: "open S \<Longrightarrow> open (snd -` S)"
   103 by (simp add: snd_vimage_eq_Times open_Times)
   104 
   105 lemma closed_vimage_fst: "closed S \<Longrightarrow> closed (fst -` S)"
   106 unfolding closed_open vimage_Compl [symmetric]
   107 by (rule open_vimage_fst)
   108 
   109 lemma closed_vimage_snd: "closed S \<Longrightarrow> closed (snd -` S)"
   110 unfolding closed_open vimage_Compl [symmetric]
   111 by (rule open_vimage_snd)
   112 
   113 lemma closed_Times: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<times> T)"
   114 proof -
   115   have "S \<times> T = (fst -` S) \<inter> (snd -` T)" by auto
   116   thus "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<times> T)"
   117     by (simp add: closed_vimage_fst closed_vimage_snd closed_Int)
   118 qed
   119 
   120 lemma subset_fst_imageI: "A \<times> B \<subseteq> S \<Longrightarrow> y \<in> B \<Longrightarrow> A \<subseteq> fst ` S"
   121   unfolding image_def subset_eq by force
   122 
   123 lemma subset_snd_imageI: "A \<times> B \<subseteq> S \<Longrightarrow> x \<in> A \<Longrightarrow> B \<subseteq> snd ` S"
   124   unfolding image_def subset_eq by force
   125 
   126 lemma open_image_fst: assumes "open S" shows "open (fst ` S)"
   127 proof (rule openI)
   128   fix x assume "x \<in> fst ` S"
   129   then obtain y where "(x, y) \<in> S" by auto
   130   then obtain A B where "open A" "open B" "x \<in> A" "y \<in> B" "A \<times> B \<subseteq> S"
   131     using `open S` unfolding open_prod_def by auto
   132   from `A \<times> B \<subseteq> S` `y \<in> B` have "A \<subseteq> fst ` S" by (rule subset_fst_imageI)
   133   with `open A` `x \<in> A` have "open A \<and> x \<in> A \<and> A \<subseteq> fst ` S" by simp
   134   then show "\<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> fst ` S" by - (rule exI)
   135 qed
   136 
   137 lemma open_image_snd: assumes "open S" shows "open (snd ` S)"
   138 proof (rule openI)
   139   fix y assume "y \<in> snd ` S"
   140   then obtain x where "(x, y) \<in> S" by auto
   141   then obtain A B where "open A" "open B" "x \<in> A" "y \<in> B" "A \<times> B \<subseteq> S"
   142     using `open S` unfolding open_prod_def by auto
   143   from `A \<times> B \<subseteq> S` `x \<in> A` have "B \<subseteq> snd ` S" by (rule subset_snd_imageI)
   144   with `open B` `y \<in> B` have "open B \<and> y \<in> B \<and> B \<subseteq> snd ` S" by simp
   145   then show "\<exists>T. open T \<and> y \<in> T \<and> T \<subseteq> snd ` S" by - (rule exI)
   146 qed
   147 
   148 subsubsection {* Continuity of operations *}
   149 
   150 lemma tendsto_fst [tendsto_intros]:
   151   assumes "(f ---> a) F"
   152   shows "((\<lambda>x. fst (f x)) ---> fst a) F"
   153 proof (rule topological_tendstoI)
   154   fix S assume "open S" and "fst a \<in> S"
   155   then have "open (fst -` S)" and "a \<in> fst -` S"
   156     by (simp_all add: open_vimage_fst)
   157   with assms have "eventually (\<lambda>x. f x \<in> fst -` S) F"
   158     by (rule topological_tendstoD)
   159   then show "eventually (\<lambda>x. fst (f x) \<in> S) F"
   160     by simp
   161 qed
   162 
   163 lemma tendsto_snd [tendsto_intros]:
   164   assumes "(f ---> a) F"
   165   shows "((\<lambda>x. snd (f x)) ---> snd a) F"
   166 proof (rule topological_tendstoI)
   167   fix S assume "open S" and "snd a \<in> S"
   168   then have "open (snd -` S)" and "a \<in> snd -` S"
   169     by (simp_all add: open_vimage_snd)
   170   with assms have "eventually (\<lambda>x. f x \<in> snd -` S) F"
   171     by (rule topological_tendstoD)
   172   then show "eventually (\<lambda>x. snd (f x) \<in> S) F"
   173     by simp
   174 qed
   175 
   176 lemma tendsto_Pair [tendsto_intros]:
   177   assumes "(f ---> a) F" and "(g ---> b) F"
   178   shows "((\<lambda>x. (f x, g x)) ---> (a, b)) F"
   179 proof (rule topological_tendstoI)
   180   fix S assume "open S" and "(a, b) \<in> S"
   181   then obtain A B where "open A" "open B" "a \<in> A" "b \<in> B" "A \<times> B \<subseteq> S"
   182     unfolding open_prod_def by fast
   183   have "eventually (\<lambda>x. f x \<in> A) F"
   184     using `(f ---> a) F` `open A` `a \<in> A`
   185     by (rule topological_tendstoD)
   186   moreover
   187   have "eventually (\<lambda>x. g x \<in> B) F"
   188     using `(g ---> b) F` `open B` `b \<in> B`
   189     by (rule topological_tendstoD)
   190   ultimately
   191   show "eventually (\<lambda>x. (f x, g x) \<in> S) F"
   192     by (rule eventually_elim2)
   193        (simp add: subsetD [OF `A \<times> B \<subseteq> S`])
   194 qed
   195 
   196 lemma continuous_fst[continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. fst (f x))"
   197   unfolding continuous_def by (rule tendsto_fst)
   198 
   199 lemma continuous_snd[continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. snd (f x))"
   200   unfolding continuous_def by (rule tendsto_snd)
   201 
   202 lemma continuous_Pair[continuous_intros]: "continuous F f \<Longrightarrow> continuous F g \<Longrightarrow> continuous F (\<lambda>x. (f x, g x))"
   203   unfolding continuous_def by (rule tendsto_Pair)
   204 
   205 lemma continuous_on_fst[continuous_on_intros]: "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. fst (f x))"
   206   unfolding continuous_on_def by (auto intro: tendsto_fst)
   207 
   208 lemma continuous_on_snd[continuous_on_intros]: "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. snd (f x))"
   209   unfolding continuous_on_def by (auto intro: tendsto_snd)
   210 
   211 lemma continuous_on_Pair[continuous_on_intros]: "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. (f x, g x))"
   212   unfolding continuous_on_def by (auto intro: tendsto_Pair)
   213 
   214 lemma isCont_fst [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. fst (f x)) a"
   215   by (fact continuous_fst)
   216 
   217 lemma isCont_snd [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. snd (f x)) a"
   218   by (fact continuous_snd)
   219 
   220 lemma isCont_Pair [simp]: "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. (f x, g x)) a"
   221   by (fact continuous_Pair)
   222 
   223 subsubsection {* Separation axioms *}
   224 
   225 lemma mem_Times_iff: "x \<in> A \<times> B \<longleftrightarrow> fst x \<in> A \<and> snd x \<in> B"
   226   by (induct x) simp (* TODO: move elsewhere *)
   227 
   228 instance prod :: (t0_space, t0_space) t0_space
   229 proof
   230   fix x y :: "'a \<times> 'b" assume "x \<noteq> y"
   231   hence "fst x \<noteq> fst y \<or> snd x \<noteq> snd y"
   232     by (simp add: prod_eq_iff)
   233   thus "\<exists>U. open U \<and> (x \<in> U) \<noteq> (y \<in> U)"
   234     apply (rule disjE)
   235     apply (drule t0_space, erule exE, rule_tac x="U \<times> UNIV" in exI)
   236     apply (simp add: open_Times mem_Times_iff)
   237     apply (drule t0_space, erule exE, rule_tac x="UNIV \<times> U" in exI)
   238     apply (simp add: open_Times mem_Times_iff)
   239     done
   240 qed
   241 
   242 instance prod :: (t1_space, t1_space) t1_space
   243 proof
   244   fix x y :: "'a \<times> 'b" assume "x \<noteq> y"
   245   hence "fst x \<noteq> fst y \<or> snd x \<noteq> snd y"
   246     by (simp add: prod_eq_iff)
   247   thus "\<exists>U. open U \<and> x \<in> U \<and> y \<notin> U"
   248     apply (rule disjE)
   249     apply (drule t1_space, erule exE, rule_tac x="U \<times> UNIV" in exI)
   250     apply (simp add: open_Times mem_Times_iff)
   251     apply (drule t1_space, erule exE, rule_tac x="UNIV \<times> U" in exI)
   252     apply (simp add: open_Times mem_Times_iff)
   253     done
   254 qed
   255 
   256 instance prod :: (t2_space, t2_space) t2_space
   257 proof
   258   fix x y :: "'a \<times> 'b" assume "x \<noteq> y"
   259   hence "fst x \<noteq> fst y \<or> snd x \<noteq> snd y"
   260     by (simp add: prod_eq_iff)
   261   thus "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
   262     apply (rule disjE)
   263     apply (drule hausdorff, clarify)
   264     apply (rule_tac x="U \<times> UNIV" in exI, rule_tac x="V \<times> UNIV" in exI)
   265     apply (simp add: open_Times mem_Times_iff disjoint_iff_not_equal)
   266     apply (drule hausdorff, clarify)
   267     apply (rule_tac x="UNIV \<times> U" in exI, rule_tac x="UNIV \<times> V" in exI)
   268     apply (simp add: open_Times mem_Times_iff disjoint_iff_not_equal)
   269     done
   270 qed
   271 
   272 subsection {* Product is a metric space *}
   273 
   274 instantiation prod :: (metric_space, metric_space) metric_space
   275 begin
   276 
   277 definition dist_prod_def:
   278   "dist x y = sqrt ((dist (fst x) (fst y))\<^sup>2 + (dist (snd x) (snd y))\<^sup>2)"
   279 
   280 lemma dist_Pair_Pair: "dist (a, b) (c, d) = sqrt ((dist a c)\<^sup>2 + (dist b d)\<^sup>2)"
   281   unfolding dist_prod_def by simp
   282 
   283 lemma dist_fst_le: "dist (fst x) (fst y) \<le> dist x y"
   284 unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge1)
   285 
   286 lemma dist_snd_le: "dist (snd x) (snd y) \<le> dist x y"
   287 unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge2)
   288 
   289 instance proof
   290   fix x y :: "'a \<times> 'b"
   291   show "dist x y = 0 \<longleftrightarrow> x = y"
   292     unfolding dist_prod_def prod_eq_iff by simp
   293 next
   294   fix x y z :: "'a \<times> 'b"
   295   show "dist x y \<le> dist x z + dist y z"
   296     unfolding dist_prod_def
   297     by (intro order_trans [OF _ real_sqrt_sum_squares_triangle_ineq]
   298         real_sqrt_le_mono add_mono power_mono dist_triangle2 zero_le_dist)
   299 next
   300   fix S :: "('a \<times> 'b) set"
   301   show "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
   302   proof
   303     assume "open S" show "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S"
   304     proof
   305       fix x assume "x \<in> S"
   306       obtain A B where "open A" "open B" "x \<in> A \<times> B" "A \<times> B \<subseteq> S"
   307         using `open S` and `x \<in> S` by (rule open_prod_elim)
   308       obtain r where r: "0 < r" "\<forall>y. dist y (fst x) < r \<longrightarrow> y \<in> A"
   309         using `open A` and `x \<in> A \<times> B` unfolding open_dist by auto
   310       obtain s where s: "0 < s" "\<forall>y. dist y (snd x) < s \<longrightarrow> y \<in> B"
   311         using `open B` and `x \<in> A \<times> B` unfolding open_dist by auto
   312       let ?e = "min r s"
   313       have "0 < ?e \<and> (\<forall>y. dist y x < ?e \<longrightarrow> y \<in> S)"
   314       proof (intro allI impI conjI)
   315         show "0 < min r s" by (simp add: r(1) s(1))
   316       next
   317         fix y assume "dist y x < min r s"
   318         hence "dist y x < r" and "dist y x < s"
   319           by simp_all
   320         hence "dist (fst y) (fst x) < r" and "dist (snd y) (snd x) < s"
   321           by (auto intro: le_less_trans dist_fst_le dist_snd_le)
   322         hence "fst y \<in> A" and "snd y \<in> B"
   323           by (simp_all add: r(2) s(2))
   324         hence "y \<in> A \<times> B" by (induct y, simp)
   325         with `A \<times> B \<subseteq> S` show "y \<in> S" ..
   326       qed
   327       thus "\<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" ..
   328     qed
   329   next
   330     assume *: "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" show "open S"
   331     proof (rule open_prod_intro)
   332       fix x assume "x \<in> S"
   333       then obtain e where "0 < e" and S: "\<forall>y. dist y x < e \<longrightarrow> y \<in> S"
   334         using * by fast
   335       def r \<equiv> "e / sqrt 2" and s \<equiv> "e / sqrt 2"
   336       from `0 < e` have "0 < r" and "0 < s"
   337         unfolding r_def s_def by (simp_all add: divide_pos_pos)
   338       from `0 < e` have "e = sqrt (r\<^sup>2 + s\<^sup>2)"
   339         unfolding r_def s_def by (simp add: power_divide)
   340       def A \<equiv> "{y. dist (fst x) y < r}" and B \<equiv> "{y. dist (snd x) y < s}"
   341       have "open A" and "open B"
   342         unfolding A_def B_def by (simp_all add: open_ball)
   343       moreover have "x \<in> A \<times> B"
   344         unfolding A_def B_def mem_Times_iff
   345         using `0 < r` and `0 < s` by simp
   346       moreover have "A \<times> B \<subseteq> S"
   347       proof (clarify)
   348         fix a b assume "a \<in> A" and "b \<in> B"
   349         hence "dist a (fst x) < r" and "dist b (snd x) < s"
   350           unfolding A_def B_def by (simp_all add: dist_commute)
   351         hence "dist (a, b) x < e"
   352           unfolding dist_prod_def `e = sqrt (r\<^sup>2 + s\<^sup>2)`
   353           by (simp add: add_strict_mono power_strict_mono)
   354         thus "(a, b) \<in> S"
   355           by (simp add: S)
   356       qed
   357       ultimately show "\<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S" by fast
   358     qed
   359   qed
   360 qed
   361 
   362 end
   363 
   364 lemma Cauchy_fst: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. fst (X n))"
   365 unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_fst_le])
   366 
   367 lemma Cauchy_snd: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. snd (X n))"
   368 unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_snd_le])
   369 
   370 lemma Cauchy_Pair:
   371   assumes "Cauchy X" and "Cauchy Y"
   372   shows "Cauchy (\<lambda>n. (X n, Y n))"
   373 proof (rule metric_CauchyI)
   374   fix r :: real assume "0 < r"
   375   then have "0 < r / sqrt 2" (is "0 < ?s")
   376     by (simp add: divide_pos_pos)
   377   obtain M where M: "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < ?s"
   378     using metric_CauchyD [OF `Cauchy X` `0 < ?s`] ..
   379   obtain N where N: "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (Y m) (Y n) < ?s"
   380     using metric_CauchyD [OF `Cauchy Y` `0 < ?s`] ..
   381   have "\<forall>m\<ge>max M N. \<forall>n\<ge>max M N. dist (X m, Y m) (X n, Y n) < r"
   382     using M N by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
   383   then show "\<exists>n0. \<forall>m\<ge>n0. \<forall>n\<ge>n0. dist (X m, Y m) (X n, Y n) < r" ..
   384 qed
   385 
   386 subsection {* Product is a complete metric space *}
   387 
   388 instance prod :: (complete_space, complete_space) complete_space
   389 proof
   390   fix X :: "nat \<Rightarrow> 'a \<times> 'b" assume "Cauchy X"
   391   have 1: "(\<lambda>n. fst (X n)) ----> lim (\<lambda>n. fst (X n))"
   392     using Cauchy_fst [OF `Cauchy X`]
   393     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   394   have 2: "(\<lambda>n. snd (X n)) ----> lim (\<lambda>n. snd (X n))"
   395     using Cauchy_snd [OF `Cauchy X`]
   396     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   397   have "X ----> (lim (\<lambda>n. fst (X n)), lim (\<lambda>n. snd (X n)))"
   398     using tendsto_Pair [OF 1 2] by simp
   399   then show "convergent X"
   400     by (rule convergentI)
   401 qed
   402 
   403 subsection {* Product is a normed vector space *}
   404 
   405 instantiation prod :: (real_normed_vector, real_normed_vector) real_normed_vector
   406 begin
   407 
   408 definition norm_prod_def:
   409   "norm x = sqrt ((norm (fst x))\<^sup>2 + (norm (snd x))\<^sup>2)"
   410 
   411 definition sgn_prod_def:
   412   "sgn (x::'a \<times> 'b) = scaleR (inverse (norm x)) x"
   413 
   414 lemma norm_Pair: "norm (a, b) = sqrt ((norm a)\<^sup>2 + (norm b)\<^sup>2)"
   415   unfolding norm_prod_def by simp
   416 
   417 instance proof
   418   fix r :: real and x y :: "'a \<times> 'b"
   419   show "norm x = 0 \<longleftrightarrow> x = 0"
   420     unfolding norm_prod_def
   421     by (simp add: prod_eq_iff)
   422   show "norm (x + y) \<le> norm x + norm y"
   423     unfolding norm_prod_def
   424     apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
   425     apply (simp add: add_mono power_mono norm_triangle_ineq)
   426     done
   427   show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
   428     unfolding norm_prod_def
   429     apply (simp add: power_mult_distrib)
   430     apply (simp add: distrib_left [symmetric])
   431     apply (simp add: real_sqrt_mult_distrib)
   432     done
   433   show "sgn x = scaleR (inverse (norm x)) x"
   434     by (rule sgn_prod_def)
   435   show "dist x y = norm (x - y)"
   436     unfolding dist_prod_def norm_prod_def
   437     by (simp add: dist_norm)
   438 qed
   439 
   440 end
   441 
   442 instance prod :: (banach, banach) banach ..
   443 
   444 subsubsection {* Pair operations are linear *}
   445 
   446 lemma bounded_linear_fst: "bounded_linear fst"
   447   using fst_add fst_scaleR
   448   by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
   449 
   450 lemma bounded_linear_snd: "bounded_linear snd"
   451   using snd_add snd_scaleR
   452   by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
   453 
   454 text {* TODO: move to NthRoot *}
   455 lemma sqrt_add_le_add_sqrt:
   456   assumes x: "0 \<le> x" and y: "0 \<le> y"
   457   shows "sqrt (x + y) \<le> sqrt x + sqrt y"
   458 apply (rule power2_le_imp_le)
   459 apply (simp add: power2_sum x y)
   460 apply (simp add: mult_nonneg_nonneg x y)
   461 apply (simp add: x y)
   462 done
   463 
   464 lemma bounded_linear_Pair:
   465   assumes f: "bounded_linear f"
   466   assumes g: "bounded_linear g"
   467   shows "bounded_linear (\<lambda>x. (f x, g x))"
   468 proof
   469   interpret f: bounded_linear f by fact
   470   interpret g: bounded_linear g by fact
   471   fix x y and r :: real
   472   show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
   473     by (simp add: f.add g.add)
   474   show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
   475     by (simp add: f.scaleR g.scaleR)
   476   obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
   477     using f.pos_bounded by fast
   478   obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
   479     using g.pos_bounded by fast
   480   have "\<forall>x. norm (f x, g x) \<le> norm x * (Kf + Kg)"
   481     apply (rule allI)
   482     apply (simp add: norm_Pair)
   483     apply (rule order_trans [OF sqrt_add_le_add_sqrt], simp, simp)
   484     apply (simp add: distrib_left)
   485     apply (rule add_mono [OF norm_f norm_g])
   486     done
   487   then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
   488 qed
   489 
   490 subsubsection {* Frechet derivatives involving pairs *}
   491 
   492 lemma FDERIV_Pair [FDERIV_intros]:
   493   assumes f: "FDERIV f x : s :> f'" and g: "FDERIV g x : s :> g'"
   494   shows "FDERIV (\<lambda>x. (f x, g x)) x : s :> (\<lambda>h. (f' h, g' h))"
   495 proof (rule FDERIV_I_sandwich[of 1])
   496   show "bounded_linear (\<lambda>h. (f' h, g' h))"
   497     using f g by (intro bounded_linear_Pair FDERIV_bounded_linear)
   498   let ?Rf = "\<lambda>y. f y - f x - f' (y - x)"
   499   let ?Rg = "\<lambda>y. g y - g x - g' (y - x)"
   500   let ?R = "\<lambda>y. ((f y, g y) - (f x, g x) - (f' (y - x), g' (y - x)))"
   501 
   502   show "((\<lambda>y. norm (?Rf y) / norm (y - x) + norm (?Rg y) / norm (y - x)) ---> 0) (at x within s)"
   503     using f g by (intro tendsto_add_zero) (auto simp: FDERIV_iff_norm)
   504 
   505   fix y :: 'a assume "y \<noteq> x"
   506   show "norm (?R y) / norm (y - x) \<le> norm (?Rf y) / norm (y - x) + norm (?Rg y) / norm (y - x)"
   507     unfolding add_divide_distrib [symmetric]
   508     by (simp add: norm_Pair divide_right_mono order_trans [OF sqrt_add_le_add_sqrt])
   509 qed simp
   510 
   511 lemmas FDERIV_fst [FDERIV_intros] = bounded_linear.FDERIV [OF bounded_linear_fst]
   512 lemmas FDERIV_snd [FDERIV_intros] = bounded_linear.FDERIV [OF bounded_linear_snd]
   513 
   514 lemma FDERIV_split [FDERIV_intros]:
   515   "((\<lambda>p. f (fst p) (snd p)) has_derivative f') F \<Longrightarrow> ((\<lambda>(a, b). f a b) has_derivative f') F"
   516   unfolding split_beta' .
   517 
   518 subsection {* Product is an inner product space *}
   519 
   520 instantiation prod :: (real_inner, real_inner) real_inner
   521 begin
   522 
   523 definition inner_prod_def:
   524   "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
   525 
   526 lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
   527   unfolding inner_prod_def by simp
   528 
   529 instance proof
   530   fix r :: real
   531   fix x y z :: "'a::real_inner \<times> 'b::real_inner"
   532   show "inner x y = inner y x"
   533     unfolding inner_prod_def
   534     by (simp add: inner_commute)
   535   show "inner (x + y) z = inner x z + inner y z"
   536     unfolding inner_prod_def
   537     by (simp add: inner_add_left)
   538   show "inner (scaleR r x) y = r * inner x y"
   539     unfolding inner_prod_def
   540     by (simp add: distrib_left)
   541   show "0 \<le> inner x x"
   542     unfolding inner_prod_def
   543     by (intro add_nonneg_nonneg inner_ge_zero)
   544   show "inner x x = 0 \<longleftrightarrow> x = 0"
   545     unfolding inner_prod_def prod_eq_iff
   546     by (simp add: add_nonneg_eq_0_iff)
   547   show "norm x = sqrt (inner x x)"
   548     unfolding norm_prod_def inner_prod_def
   549     by (simp add: power2_norm_eq_inner)
   550 qed
   551 
   552 end
   553 
   554 end