src/HOL/Library/Product_Vector.thy
changeset 30019 a2f19e0a28b2
child 30729 461ee3e49ad3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Library/Product_Vector.thy	Fri Feb 20 08:02:11 2009 -0800
     1.3 @@ -0,0 +1,273 @@
     1.4 +(*  Title:      HOL/Library/Product_Vector.thy
     1.5 +    Author:     Brian Huffman
     1.6 +*)
     1.7 +
     1.8 +header {* Cartesian Products as Vector Spaces *}
     1.9 +
    1.10 +theory Product_Vector
    1.11 +imports Inner_Product Product_plus
    1.12 +begin
    1.13 +
    1.14 +subsection {* Product is a real vector space *}
    1.15 +
    1.16 +instantiation "*" :: (real_vector, real_vector) real_vector
    1.17 +begin
    1.18 +
    1.19 +definition scaleR_prod_def:
    1.20 +  "scaleR r A = (scaleR r (fst A), scaleR r (snd A))"
    1.21 +
    1.22 +lemma fst_scaleR [simp]: "fst (scaleR r A) = scaleR r (fst A)"
    1.23 +  unfolding scaleR_prod_def by simp
    1.24 +
    1.25 +lemma snd_scaleR [simp]: "snd (scaleR r A) = scaleR r (snd A)"
    1.26 +  unfolding scaleR_prod_def by simp
    1.27 +
    1.28 +lemma scaleR_Pair [simp]: "scaleR r (a, b) = (scaleR r a, scaleR r b)"
    1.29 +  unfolding scaleR_prod_def by simp
    1.30 +
    1.31 +instance proof
    1.32 +  fix a b :: real and x y :: "'a \<times> 'b"
    1.33 +  show "scaleR a (x + y) = scaleR a x + scaleR a y"
    1.34 +    by (simp add: expand_prod_eq scaleR_right_distrib)
    1.35 +  show "scaleR (a + b) x = scaleR a x + scaleR b x"
    1.36 +    by (simp add: expand_prod_eq scaleR_left_distrib)
    1.37 +  show "scaleR a (scaleR b x) = scaleR (a * b) x"
    1.38 +    by (simp add: expand_prod_eq)
    1.39 +  show "scaleR 1 x = x"
    1.40 +    by (simp add: expand_prod_eq)
    1.41 +qed
    1.42 +
    1.43 +end
    1.44 +
    1.45 +subsection {* Product is a normed vector space *}
    1.46 +
    1.47 +instantiation
    1.48 +  "*" :: (real_normed_vector, real_normed_vector) real_normed_vector
    1.49 +begin
    1.50 +
    1.51 +definition norm_prod_def:
    1.52 +  "norm x = sqrt ((norm (fst x))\<twosuperior> + (norm (snd x))\<twosuperior>)"
    1.53 +
    1.54 +definition sgn_prod_def:
    1.55 +  "sgn (x::'a \<times> 'b) = scaleR (inverse (norm x)) x"
    1.56 +
    1.57 +lemma norm_Pair: "norm (a, b) = sqrt ((norm a)\<twosuperior> + (norm b)\<twosuperior>)"
    1.58 +  unfolding norm_prod_def by simp
    1.59 +
    1.60 +instance proof
    1.61 +  fix r :: real and x y :: "'a \<times> 'b"
    1.62 +  show "0 \<le> norm x"
    1.63 +    unfolding norm_prod_def by simp
    1.64 +  show "norm x = 0 \<longleftrightarrow> x = 0"
    1.65 +    unfolding norm_prod_def
    1.66 +    by (simp add: expand_prod_eq)
    1.67 +  show "norm (x + y) \<le> norm x + norm y"
    1.68 +    unfolding norm_prod_def
    1.69 +    apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
    1.70 +    apply (simp add: add_mono power_mono norm_triangle_ineq)
    1.71 +    done
    1.72 +  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
    1.73 +    unfolding norm_prod_def
    1.74 +    apply (simp add: norm_scaleR power_mult_distrib)
    1.75 +    apply (simp add: right_distrib [symmetric])
    1.76 +    apply (simp add: real_sqrt_mult_distrib)
    1.77 +    done
    1.78 +  show "sgn x = scaleR (inverse (norm x)) x"
    1.79 +    by (rule sgn_prod_def)
    1.80 +qed
    1.81 +
    1.82 +end
    1.83 +
    1.84 +subsection {* Product is an inner product space *}
    1.85 +
    1.86 +instantiation "*" :: (real_inner, real_inner) real_inner
    1.87 +begin
    1.88 +
    1.89 +definition inner_prod_def:
    1.90 +  "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
    1.91 +
    1.92 +lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
    1.93 +  unfolding inner_prod_def by simp
    1.94 +
    1.95 +instance proof
    1.96 +  fix r :: real
    1.97 +  fix x y z :: "'a::real_inner * 'b::real_inner"
    1.98 +  show "inner x y = inner y x"
    1.99 +    unfolding inner_prod_def
   1.100 +    by (simp add: inner_commute)
   1.101 +  show "inner (x + y) z = inner x z + inner y z"
   1.102 +    unfolding inner_prod_def
   1.103 +    by (simp add: inner_left_distrib)
   1.104 +  show "inner (scaleR r x) y = r * inner x y"
   1.105 +    unfolding inner_prod_def
   1.106 +    by (simp add: inner_scaleR_left right_distrib)
   1.107 +  show "0 \<le> inner x x"
   1.108 +    unfolding inner_prod_def
   1.109 +    by (intro add_nonneg_nonneg inner_ge_zero)
   1.110 +  show "inner x x = 0 \<longleftrightarrow> x = 0"
   1.111 +    unfolding inner_prod_def expand_prod_eq
   1.112 +    by (simp add: add_nonneg_eq_0_iff)
   1.113 +  show "norm x = sqrt (inner x x)"
   1.114 +    unfolding norm_prod_def inner_prod_def
   1.115 +    by (simp add: power2_norm_eq_inner)
   1.116 +qed
   1.117 +
   1.118 +end
   1.119 +
   1.120 +subsection {* Pair operations are linear and continuous *}
   1.121 +
   1.122 +interpretation fst!: bounded_linear fst
   1.123 +  apply (unfold_locales)
   1.124 +  apply (rule fst_add)
   1.125 +  apply (rule fst_scaleR)
   1.126 +  apply (rule_tac x="1" in exI, simp add: norm_Pair)
   1.127 +  done
   1.128 +
   1.129 +interpretation snd!: bounded_linear snd
   1.130 +  apply (unfold_locales)
   1.131 +  apply (rule snd_add)
   1.132 +  apply (rule snd_scaleR)
   1.133 +  apply (rule_tac x="1" in exI, simp add: norm_Pair)
   1.134 +  done
   1.135 +
   1.136 +text {* TODO: move to NthRoot *}
   1.137 +lemma sqrt_add_le_add_sqrt:
   1.138 +  assumes x: "0 \<le> x" and y: "0 \<le> y"
   1.139 +  shows "sqrt (x + y) \<le> sqrt x + sqrt y"
   1.140 +apply (rule power2_le_imp_le)
   1.141 +apply (simp add: real_sum_squared_expand add_nonneg_nonneg x y)
   1.142 +apply (simp add: mult_nonneg_nonneg x y)
   1.143 +apply (simp add: add_nonneg_nonneg x y)
   1.144 +done
   1.145 +
   1.146 +lemma bounded_linear_Pair:
   1.147 +  assumes f: "bounded_linear f"
   1.148 +  assumes g: "bounded_linear g"
   1.149 +  shows "bounded_linear (\<lambda>x. (f x, g x))"
   1.150 +proof
   1.151 +  interpret f: bounded_linear f by fact
   1.152 +  interpret g: bounded_linear g by fact
   1.153 +  fix x y and r :: real
   1.154 +  show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
   1.155 +    by (simp add: f.add g.add)
   1.156 +  show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
   1.157 +    by (simp add: f.scaleR g.scaleR)
   1.158 +  obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
   1.159 +    using f.pos_bounded by fast
   1.160 +  obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
   1.161 +    using g.pos_bounded by fast
   1.162 +  have "\<forall>x. norm (f x, g x) \<le> norm x * (Kf + Kg)"
   1.163 +    apply (rule allI)
   1.164 +    apply (simp add: norm_Pair)
   1.165 +    apply (rule order_trans [OF sqrt_add_le_add_sqrt], simp, simp)
   1.166 +    apply (simp add: right_distrib)
   1.167 +    apply (rule add_mono [OF norm_f norm_g])
   1.168 +    done
   1.169 +  then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
   1.170 +qed
   1.171 +
   1.172 +text {*
   1.173 +  TODO: The next three proofs are nearly identical to each other.
   1.174 +  Is there a good way to factor out the common parts?
   1.175 +*}
   1.176 +
   1.177 +lemma LIMSEQ_Pair:
   1.178 +  assumes "X ----> a" and "Y ----> b"
   1.179 +  shows "(\<lambda>n. (X n, Y n)) ----> (a, b)"
   1.180 +proof (rule LIMSEQ_I)
   1.181 +  fix r :: real assume "0 < r"
   1.182 +  then have "0 < r / sqrt 2" (is "0 < ?s")
   1.183 +    by (simp add: divide_pos_pos)
   1.184 +  obtain M where M: "\<forall>n\<ge>M. norm (X n - a) < ?s"
   1.185 +    using LIMSEQ_D [OF `X ----> a` `0 < ?s`] ..
   1.186 +  obtain N where N: "\<forall>n\<ge>N. norm (Y n - b) < ?s"
   1.187 +    using LIMSEQ_D [OF `Y ----> b` `0 < ?s`] ..
   1.188 +  have "\<forall>n\<ge>max M N. norm ((X n, Y n) - (a, b)) < r"
   1.189 +    using M N by (simp add: real_sqrt_sum_squares_less norm_Pair)
   1.190 +  then show "\<exists>n0. \<forall>n\<ge>n0. norm ((X n, Y n) - (a, b)) < r" ..
   1.191 +qed
   1.192 +
   1.193 +lemma Cauchy_Pair:
   1.194 +  assumes "Cauchy X" and "Cauchy Y"
   1.195 +  shows "Cauchy (\<lambda>n. (X n, Y n))"
   1.196 +proof (rule CauchyI)
   1.197 +  fix r :: real assume "0 < r"
   1.198 +  then have "0 < r / sqrt 2" (is "0 < ?s")
   1.199 +    by (simp add: divide_pos_pos)
   1.200 +  obtain M where M: "\<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < ?s"
   1.201 +    using CauchyD [OF `Cauchy X` `0 < ?s`] ..
   1.202 +  obtain N where N: "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (Y m - Y n) < ?s"
   1.203 +    using CauchyD [OF `Cauchy Y` `0 < ?s`] ..
   1.204 +  have "\<forall>m\<ge>max M N. \<forall>n\<ge>max M N. norm ((X m, Y m) - (X n, Y n)) < r"
   1.205 +    using M N by (simp add: real_sqrt_sum_squares_less norm_Pair)
   1.206 +  then show "\<exists>n0. \<forall>m\<ge>n0. \<forall>n\<ge>n0. norm ((X m, Y m) - (X n, Y n)) < r" ..
   1.207 +qed
   1.208 +
   1.209 +lemma LIM_Pair:
   1.210 +  assumes "f -- x --> a" and "g -- x --> b"
   1.211 +  shows "(\<lambda>x. (f x, g x)) -- x --> (a, b)"
   1.212 +proof (rule LIM_I)
   1.213 +  fix r :: real assume "0 < r"
   1.214 +  then have "0 < r / sqrt 2" (is "0 < ?e")
   1.215 +    by (simp add: divide_pos_pos)
   1.216 +  obtain s where s: "0 < s"
   1.217 +    "\<forall>z. z \<noteq> x \<and> norm (z - x) < s \<longrightarrow> norm (f z - a) < ?e"
   1.218 +    using LIM_D [OF `f -- x --> a` `0 < ?e`] by fast
   1.219 +  obtain t where t: "0 < t"
   1.220 +    "\<forall>z. z \<noteq> x \<and> norm (z - x) < t \<longrightarrow> norm (g z - b) < ?e"
   1.221 +    using LIM_D [OF `g -- x --> b` `0 < ?e`] by fast
   1.222 +  have "0 < min s t \<and>
   1.223 +    (\<forall>z. z \<noteq> x \<and> norm (z - x) < min s t \<longrightarrow> norm ((f z, g z) - (a, b)) < r)"
   1.224 +    using s t by (simp add: real_sqrt_sum_squares_less norm_Pair)
   1.225 +  then show
   1.226 +    "\<exists>s>0. \<forall>z. z \<noteq> x \<and> norm (z - x) < s \<longrightarrow> norm ((f z, g z) - (a, b)) < r" ..
   1.227 +qed
   1.228 +
   1.229 +lemma isCont_Pair [simp]:
   1.230 +  "\<lbrakk>isCont f x; isCont g x\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. (f x, g x)) x"
   1.231 +  unfolding isCont_def by (rule LIM_Pair)
   1.232 +
   1.233 +
   1.234 +subsection {* Product is a complete vector space *}
   1.235 +
   1.236 +instance "*" :: (banach, banach) banach
   1.237 +proof
   1.238 +  fix X :: "nat \<Rightarrow> 'a \<times> 'b" assume "Cauchy X"
   1.239 +  have 1: "(\<lambda>n. fst (X n)) ----> lim (\<lambda>n. fst (X n))"
   1.240 +    using fst.Cauchy [OF `Cauchy X`]
   1.241 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   1.242 +  have 2: "(\<lambda>n. snd (X n)) ----> lim (\<lambda>n. snd (X n))"
   1.243 +    using snd.Cauchy [OF `Cauchy X`]
   1.244 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   1.245 +  have "X ----> (lim (\<lambda>n. fst (X n)), lim (\<lambda>n. snd (X n)))"
   1.246 +    using LIMSEQ_Pair [OF 1 2] by simp
   1.247 +  then show "convergent X"
   1.248 +    by (rule convergentI)
   1.249 +qed
   1.250 +
   1.251 +subsection {* Frechet derivatives involving pairs *}
   1.252 +
   1.253 +lemma FDERIV_Pair:
   1.254 +  assumes f: "FDERIV f x :> f'" and g: "FDERIV g x :> g'"
   1.255 +  shows "FDERIV (\<lambda>x. (f x, g x)) x :> (\<lambda>h. (f' h, g' h))"
   1.256 +apply (rule FDERIV_I)
   1.257 +apply (rule bounded_linear_Pair)
   1.258 +apply (rule FDERIV_bounded_linear [OF f])
   1.259 +apply (rule FDERIV_bounded_linear [OF g])
   1.260 +apply (simp add: norm_Pair)
   1.261 +apply (rule real_LIM_sandwich_zero)
   1.262 +apply (rule LIM_add_zero)
   1.263 +apply (rule FDERIV_D [OF f])
   1.264 +apply (rule FDERIV_D [OF g])
   1.265 +apply (rename_tac h)
   1.266 +apply (simp add: divide_nonneg_pos)
   1.267 +apply (rename_tac h)
   1.268 +apply (subst add_divide_distrib [symmetric])
   1.269 +apply (rule divide_right_mono [OF _ norm_ge_zero])
   1.270 +apply (rule order_trans [OF sqrt_add_le_add_sqrt])
   1.271 +apply simp
   1.272 +apply simp
   1.273 +apply simp
   1.274 +done
   1.275 +
   1.276 +end