src/HOL/Library/Product_Vector.thy
 author huffman Fri May 29 09:58:14 2009 -0700 (2009-05-29) changeset 31339 b4660351e8e7 parent 31290 f41c023d90bc child 31388 e0c05b595d1f permissions -rw-r--r--
instance * :: (metric_space, metric_space) metric_space; generalize lemmas to class metric_space
```     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 metric space *}
```
```    43
```
```    44 instantiation
```
```    45   "*" :: (metric_space, metric_space) metric_space
```
```    46 begin
```
```    47
```
```    48 definition dist_prod_def:
```
```    49   "dist (x::'a \<times> 'b) y = sqrt ((dist (fst x) (fst y))\<twosuperior> + (dist (snd x) (snd y))\<twosuperior>)"
```
```    50
```
```    51 lemma dist_Pair_Pair: "dist (a, b) (c, d) = sqrt ((dist a c)\<twosuperior> + (dist b d)\<twosuperior>)"
```
```    52   unfolding dist_prod_def by simp
```
```    53
```
```    54 instance proof
```
```    55   fix x y :: "'a \<times> 'b"
```
```    56   show "dist x y = 0 \<longleftrightarrow> x = y"
```
```    57     unfolding dist_prod_def
```
```    58     by (simp add: expand_prod_eq)
```
```    59 next
```
```    60   fix x y z :: "'a \<times> 'b"
```
```    61   show "dist x y \<le> dist x z + dist y z"
```
```    62     unfolding dist_prod_def
```
```    63     apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
```
```    64     apply (rule real_sqrt_le_mono)
```
```    65     apply (rule order_trans [OF add_mono])
```
```    66     apply (rule power_mono [OF dist_triangle2 [of _ _ "fst z"] zero_le_dist])
```
```    67     apply (rule power_mono [OF dist_triangle2 [of _ _ "snd z"] zero_le_dist])
```
```    68     apply (simp only: real_sum_squared_expand)
```
```    69     done
```
```    70 qed
```
```    71
```
```    72 end
```
```    73
```
```    74 subsection {* Product is a normed vector space *}
```
```    75
```
```    76 instantiation
```
```    77   "*" :: (real_normed_vector, real_normed_vector) real_normed_vector
```
```    78 begin
```
```    79
```
```    80 definition norm_prod_def:
```
```    81   "norm x = sqrt ((norm (fst x))\<twosuperior> + (norm (snd x))\<twosuperior>)"
```
```    82
```
```    83 definition sgn_prod_def:
```
```    84   "sgn (x::'a \<times> 'b) = scaleR (inverse (norm x)) x"
```
```    85
```
```    86 lemma norm_Pair: "norm (a, b) = sqrt ((norm a)\<twosuperior> + (norm b)\<twosuperior>)"
```
```    87   unfolding norm_prod_def by simp
```
```    88
```
```    89 instance proof
```
```    90   fix r :: real and x y :: "'a \<times> 'b"
```
```    91   show "0 \<le> norm x"
```
```    92     unfolding norm_prod_def by simp
```
```    93   show "norm x = 0 \<longleftrightarrow> x = 0"
```
```    94     unfolding norm_prod_def
```
```    95     by (simp add: expand_prod_eq)
```
```    96   show "norm (x + y) \<le> norm x + norm y"
```
```    97     unfolding norm_prod_def
```
```    98     apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
```
```    99     apply (simp add: add_mono power_mono norm_triangle_ineq)
```
```   100     done
```
```   101   show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
```
```   102     unfolding norm_prod_def
```
```   103     apply (simp add: norm_scaleR power_mult_distrib)
```
```   104     apply (simp add: right_distrib [symmetric])
```
```   105     apply (simp add: real_sqrt_mult_distrib)
```
```   106     done
```
```   107   show "sgn x = scaleR (inverse (norm x)) x"
```
```   108     by (rule sgn_prod_def)
```
```   109   show "dist x y = norm (x - y)"
```
```   110     unfolding dist_prod_def norm_prod_def
```
```   111     by (simp add: dist_norm)
```
```   112 qed
```
```   113
```
```   114 end
```
```   115
```
```   116 subsection {* Product is an inner product space *}
```
```   117
```
```   118 instantiation "*" :: (real_inner, real_inner) real_inner
```
```   119 begin
```
```   120
```
```   121 definition inner_prod_def:
```
```   122   "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
```
```   123
```
```   124 lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
```
```   125   unfolding inner_prod_def by simp
```
```   126
```
```   127 instance proof
```
```   128   fix r :: real
```
```   129   fix x y z :: "'a::real_inner * 'b::real_inner"
```
```   130   show "inner x y = inner y x"
```
```   131     unfolding inner_prod_def
```
```   132     by (simp add: inner_commute)
```
```   133   show "inner (x + y) z = inner x z + inner y z"
```
```   134     unfolding inner_prod_def
```
```   135     by (simp add: inner_left_distrib)
```
```   136   show "inner (scaleR r x) y = r * inner x y"
```
```   137     unfolding inner_prod_def
```
```   138     by (simp add: inner_scaleR_left right_distrib)
```
```   139   show "0 \<le> inner x x"
```
```   140     unfolding inner_prod_def
```
```   141     by (intro add_nonneg_nonneg inner_ge_zero)
```
```   142   show "inner x x = 0 \<longleftrightarrow> x = 0"
```
```   143     unfolding inner_prod_def expand_prod_eq
```
```   144     by (simp add: add_nonneg_eq_0_iff)
```
```   145   show "norm x = sqrt (inner x x)"
```
```   146     unfolding norm_prod_def inner_prod_def
```
```   147     by (simp add: power2_norm_eq_inner)
```
```   148 qed
```
```   149
```
```   150 end
```
```   151
```
```   152 subsection {* Pair operations are linear and continuous *}
```
```   153
```
```   154 interpretation fst: bounded_linear fst
```
```   155   apply (unfold_locales)
```
```   156   apply (rule fst_add)
```
```   157   apply (rule fst_scaleR)
```
```   158   apply (rule_tac x="1" in exI, simp add: norm_Pair)
```
```   159   done
```
```   160
```
```   161 interpretation snd: bounded_linear snd
```
```   162   apply (unfold_locales)
```
```   163   apply (rule snd_add)
```
```   164   apply (rule snd_scaleR)
```
```   165   apply (rule_tac x="1" in exI, simp add: norm_Pair)
```
```   166   done
```
```   167
```
```   168 text {* TODO: move to NthRoot *}
```
```   169 lemma sqrt_add_le_add_sqrt:
```
```   170   assumes x: "0 \<le> x" and y: "0 \<le> y"
```
```   171   shows "sqrt (x + y) \<le> sqrt x + sqrt y"
```
```   172 apply (rule power2_le_imp_le)
```
```   173 apply (simp add: real_sum_squared_expand add_nonneg_nonneg x y)
```
```   174 apply (simp add: mult_nonneg_nonneg x y)
```
```   175 apply (simp add: add_nonneg_nonneg x y)
```
```   176 done
```
```   177
```
```   178 lemma bounded_linear_Pair:
```
```   179   assumes f: "bounded_linear f"
```
```   180   assumes g: "bounded_linear g"
```
```   181   shows "bounded_linear (\<lambda>x. (f x, g x))"
```
```   182 proof
```
```   183   interpret f: bounded_linear f by fact
```
```   184   interpret g: bounded_linear g by fact
```
```   185   fix x y and r :: real
```
```   186   show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
```
```   187     by (simp add: f.add g.add)
```
```   188   show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
```
```   189     by (simp add: f.scaleR g.scaleR)
```
```   190   obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
```
```   191     using f.pos_bounded by fast
```
```   192   obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
```
```   193     using g.pos_bounded by fast
```
```   194   have "\<forall>x. norm (f x, g x) \<le> norm x * (Kf + Kg)"
```
```   195     apply (rule allI)
```
```   196     apply (simp add: norm_Pair)
```
```   197     apply (rule order_trans [OF sqrt_add_le_add_sqrt], simp, simp)
```
```   198     apply (simp add: right_distrib)
```
```   199     apply (rule add_mono [OF norm_f norm_g])
```
```   200     done
```
```   201   then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
```
```   202 qed
```
```   203
```
```   204 text {*
```
```   205   TODO: The next three proofs are nearly identical to each other.
```
```   206   Is there a good way to factor out the common parts?
```
```   207 *}
```
```   208
```
```   209 lemma LIMSEQ_Pair:
```
```   210   assumes "X ----> a" and "Y ----> b"
```
```   211   shows "(\<lambda>n. (X n, Y n)) ----> (a, b)"
```
```   212 proof (rule metric_LIMSEQ_I)
```
```   213   fix r :: real assume "0 < r"
```
```   214   then have "0 < r / sqrt 2" (is "0 < ?s")
```
```   215     by (simp add: divide_pos_pos)
```
```   216   obtain M where M: "\<forall>n\<ge>M. dist (X n) a < ?s"
```
```   217     using metric_LIMSEQ_D [OF `X ----> a` `0 < ?s`] ..
```
```   218   obtain N where N: "\<forall>n\<ge>N. dist (Y n) b < ?s"
```
```   219     using metric_LIMSEQ_D [OF `Y ----> b` `0 < ?s`] ..
```
```   220   have "\<forall>n\<ge>max M N. dist (X n, Y n) (a, b) < r"
```
```   221     using M N by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
```
```   222   then show "\<exists>n0. \<forall>n\<ge>n0. dist (X n, Y n) (a, b) < r" ..
```
```   223 qed
```
```   224
```
```   225 lemma Cauchy_Pair:
```
```   226   assumes "Cauchy X" and "Cauchy Y"
```
```   227   shows "Cauchy (\<lambda>n. (X n, Y n))"
```
```   228 proof (rule metric_CauchyI)
```
```   229   fix r :: real assume "0 < r"
```
```   230   then have "0 < r / sqrt 2" (is "0 < ?s")
```
```   231     by (simp add: divide_pos_pos)
```
```   232   obtain M where M: "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < ?s"
```
```   233     using metric_CauchyD [OF `Cauchy X` `0 < ?s`] ..
```
```   234   obtain N where N: "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (Y m) (Y n) < ?s"
```
```   235     using metric_CauchyD [OF `Cauchy Y` `0 < ?s`] ..
```
```   236   have "\<forall>m\<ge>max M N. \<forall>n\<ge>max M N. dist (X m, Y m) (X n, Y n) < r"
```
```   237     using M N by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
```
```   238   then show "\<exists>n0. \<forall>m\<ge>n0. \<forall>n\<ge>n0. dist (X m, Y m) (X n, Y n) < r" ..
```
```   239 qed
```
```   240
```
```   241 lemma LIM_Pair:
```
```   242   assumes "f -- x --> a" and "g -- x --> b"
```
```   243   shows "(\<lambda>x. (f x, g x)) -- x --> (a, b)"
```
```   244 proof (rule metric_LIM_I)
```
```   245   fix r :: real assume "0 < r"
```
```   246   then have "0 < r / sqrt 2" (is "0 < ?e")
```
```   247     by (simp add: divide_pos_pos)
```
```   248   obtain s where s: "0 < s"
```
```   249     "\<forall>z. z \<noteq> x \<and> dist z x < s \<longrightarrow> dist (f z) a < ?e"
```
```   250     using metric_LIM_D [OF `f -- x --> a` `0 < ?e`] by fast
```
```   251   obtain t where t: "0 < t"
```
```   252     "\<forall>z. z \<noteq> x \<and> dist z x < t \<longrightarrow> dist (g z) b < ?e"
```
```   253     using metric_LIM_D [OF `g -- x --> b` `0 < ?e`] by fast
```
```   254   have "0 < min s t \<and>
```
```   255     (\<forall>z. z \<noteq> x \<and> dist z x < min s t \<longrightarrow> dist (f z, g z) (a, b) < r)"
```
```   256     using s t by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
```
```   257   then show
```
```   258     "\<exists>s>0. \<forall>z. z \<noteq> x \<and> dist z x < s \<longrightarrow> dist (f z, g z) (a, b) < r" ..
```
```   259 qed
```
```   260
```
```   261 lemma isCont_Pair [simp]:
```
```   262   "\<lbrakk>isCont f x; isCont g x\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. (f x, g x)) x"
```
```   263   unfolding isCont_def by (rule LIM_Pair)
```
```   264
```
```   265
```
```   266 subsection {* Product is a complete vector space *}
```
```   267
```
```   268 instance "*" :: (banach, banach) banach
```
```   269 proof
```
```   270   fix X :: "nat \<Rightarrow> 'a \<times> 'b" assume "Cauchy X"
```
```   271   have 1: "(\<lambda>n. fst (X n)) ----> lim (\<lambda>n. fst (X n))"
```
```   272     using fst.Cauchy [OF `Cauchy X`]
```
```   273     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
```
```   274   have 2: "(\<lambda>n. snd (X n)) ----> lim (\<lambda>n. snd (X n))"
```
```   275     using snd.Cauchy [OF `Cauchy X`]
```
```   276     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
```
```   277   have "X ----> (lim (\<lambda>n. fst (X n)), lim (\<lambda>n. snd (X n)))"
```
```   278     using LIMSEQ_Pair [OF 1 2] by simp
```
```   279   then show "convergent X"
```
```   280     by (rule convergentI)
```
```   281 qed
```
```   282
```
```   283 subsection {* Frechet derivatives involving pairs *}
```
```   284
```
```   285 lemma FDERIV_Pair:
```
```   286   assumes f: "FDERIV f x :> f'" and g: "FDERIV g x :> g'"
```
```   287   shows "FDERIV (\<lambda>x. (f x, g x)) x :> (\<lambda>h. (f' h, g' h))"
```
```   288 apply (rule FDERIV_I)
```
```   289 apply (rule bounded_linear_Pair)
```
```   290 apply (rule FDERIV_bounded_linear [OF f])
```
```   291 apply (rule FDERIV_bounded_linear [OF g])
```
```   292 apply (simp add: norm_Pair)
```
```   293 apply (rule real_LIM_sandwich_zero)
```
```   294 apply (rule LIM_add_zero)
```
```   295 apply (rule FDERIV_D [OF f])
```
```   296 apply (rule FDERIV_D [OF g])
```
```   297 apply (rename_tac h)
```
```   298 apply (simp add: divide_nonneg_pos)
```
```   299 apply (rename_tac h)
```
```   300 apply (subst add_divide_distrib [symmetric])
```
```   301 apply (rule divide_right_mono [OF _ norm_ge_zero])
```
```   302 apply (rule order_trans [OF sqrt_add_le_add_sqrt])
```
```   303 apply simp
```
```   304 apply simp
```
```   305 apply simp
```
```   306 done
```
```   307
```
```   308 end
```