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