src/HOL/Analysis/Product_Vector.thy
 changeset 63971 da89140186e2 parent 63040 eb4ddd18d635 child 63972 c98d1dd7eba1
```     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/HOL/Analysis/Product_Vector.thy	Fri Sep 30 15:35:37 2016 +0200
1.3 @@ -0,0 +1,371 @@
1.4 +(*  Title:      HOL/Analysis/Product_Vector.thy
1.5 +    Author:     Brian Huffman
1.6 +*)
1.7 +
1.8 +section \<open>Cartesian Products as Vector Spaces\<close>
1.9 +
1.10 +theory Product_Vector
1.11 +imports
1.12 +  Inner_Product
1.13 +  "~~/src/HOL/Library/Product_plus"
1.14 +begin
1.15 +
1.16 +subsection \<open>Product is a real vector space\<close>
1.17 +
1.18 +instantiation prod :: (real_vector, real_vector) real_vector
1.19 +begin
1.20 +
1.21 +definition scaleR_prod_def:
1.22 +  "scaleR r A = (scaleR r (fst A), scaleR r (snd A))"
1.23 +
1.24 +lemma fst_scaleR [simp]: "fst (scaleR r A) = scaleR r (fst A)"
1.25 +  unfolding scaleR_prod_def by simp
1.26 +
1.27 +lemma snd_scaleR [simp]: "snd (scaleR r A) = scaleR r (snd A)"
1.28 +  unfolding scaleR_prod_def by simp
1.29 +
1.30 +lemma scaleR_Pair [simp]: "scaleR r (a, b) = (scaleR r a, scaleR r b)"
1.31 +  unfolding scaleR_prod_def by simp
1.32 +
1.33 +instance
1.34 +proof
1.35 +  fix a b :: real and x y :: "'a \<times> 'b"
1.36 +  show "scaleR a (x + y) = scaleR a x + scaleR a y"
1.37 +    by (simp add: prod_eq_iff scaleR_right_distrib)
1.38 +  show "scaleR (a + b) x = scaleR a x + scaleR b x"
1.39 +    by (simp add: prod_eq_iff scaleR_left_distrib)
1.40 +  show "scaleR a (scaleR b x) = scaleR (a * b) x"
1.41 +    by (simp add: prod_eq_iff)
1.42 +  show "scaleR 1 x = x"
1.43 +    by (simp add: prod_eq_iff)
1.44 +qed
1.45 +
1.46 +end
1.47 +
1.48 +subsection \<open>Product is a metric space\<close>
1.49 +
1.50 +(* TODO: Product of uniform spaces and compatibility with metric_spaces! *)
1.51 +
1.52 +instantiation prod :: (metric_space, metric_space) dist
1.53 +begin
1.54 +
1.55 +definition dist_prod_def[code del]:
1.56 +  "dist x y = sqrt ((dist (fst x) (fst y))\<^sup>2 + (dist (snd x) (snd y))\<^sup>2)"
1.57 +
1.58 +instance ..
1.59 +end
1.60 +
1.61 +instantiation prod :: (metric_space, metric_space) uniformity_dist
1.62 +begin
1.63 +
1.64 +definition [code del]:
1.65 +  "(uniformity :: (('a \<times> 'b) \<times> ('a \<times> 'b)) filter) =
1.66 +    (INF e:{0 <..}. principal {(x, y). dist x y < e})"
1.67 +
1.68 +instance
1.69 +  by standard (rule uniformity_prod_def)
1.70 +end
1.71 +
1.72 +declare uniformity_Abort[where 'a="'a :: metric_space \<times> 'b :: metric_space", code]
1.73 +
1.74 +instantiation prod :: (metric_space, metric_space) metric_space
1.75 +begin
1.76 +
1.77 +lemma dist_Pair_Pair: "dist (a, b) (c, d) = sqrt ((dist a c)\<^sup>2 + (dist b d)\<^sup>2)"
1.78 +  unfolding dist_prod_def by simp
1.79 +
1.80 +lemma dist_fst_le: "dist (fst x) (fst y) \<le> dist x y"
1.81 +  unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge1)
1.82 +
1.83 +lemma dist_snd_le: "dist (snd x) (snd y) \<le> dist x y"
1.84 +  unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge2)
1.85 +
1.86 +instance
1.87 +proof
1.88 +  fix x y :: "'a \<times> 'b"
1.89 +  show "dist x y = 0 \<longleftrightarrow> x = y"
1.90 +    unfolding dist_prod_def prod_eq_iff by simp
1.91 +next
1.92 +  fix x y z :: "'a \<times> 'b"
1.93 +  show "dist x y \<le> dist x z + dist y z"
1.94 +    unfolding dist_prod_def
1.95 +    by (intro order_trans [OF _ real_sqrt_sum_squares_triangle_ineq]
1.96 +        real_sqrt_le_mono add_mono power_mono dist_triangle2 zero_le_dist)
1.97 +next
1.98 +  fix S :: "('a \<times> 'b) set"
1.99 +  have *: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
1.100 +  proof
1.101 +    assume "open S" show "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S"
1.102 +    proof
1.103 +      fix x assume "x \<in> S"
1.104 +      obtain A B where "open A" "open B" "x \<in> A \<times> B" "A \<times> B \<subseteq> S"
1.105 +        using \<open>open S\<close> and \<open>x \<in> S\<close> by (rule open_prod_elim)
1.106 +      obtain r where r: "0 < r" "\<forall>y. dist y (fst x) < r \<longrightarrow> y \<in> A"
1.107 +        using \<open>open A\<close> and \<open>x \<in> A \<times> B\<close> unfolding open_dist by auto
1.108 +      obtain s where s: "0 < s" "\<forall>y. dist y (snd x) < s \<longrightarrow> y \<in> B"
1.109 +        using \<open>open B\<close> and \<open>x \<in> A \<times> B\<close> unfolding open_dist by auto
1.110 +      let ?e = "min r s"
1.111 +      have "0 < ?e \<and> (\<forall>y. dist y x < ?e \<longrightarrow> y \<in> S)"
1.112 +      proof (intro allI impI conjI)
1.113 +        show "0 < min r s" by (simp add: r(1) s(1))
1.114 +      next
1.115 +        fix y assume "dist y x < min r s"
1.116 +        hence "dist y x < r" and "dist y x < s"
1.117 +          by simp_all
1.118 +        hence "dist (fst y) (fst x) < r" and "dist (snd y) (snd x) < s"
1.119 +          by (auto intro: le_less_trans dist_fst_le dist_snd_le)
1.120 +        hence "fst y \<in> A" and "snd y \<in> B"
1.121 +          by (simp_all add: r(2) s(2))
1.122 +        hence "y \<in> A \<times> B" by (induct y, simp)
1.123 +        with \<open>A \<times> B \<subseteq> S\<close> show "y \<in> S" ..
1.124 +      qed
1.125 +      thus "\<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" ..
1.126 +    qed
1.127 +  next
1.128 +    assume *: "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" show "open S"
1.129 +    proof (rule open_prod_intro)
1.130 +      fix x assume "x \<in> S"
1.131 +      then obtain e where "0 < e" and S: "\<forall>y. dist y x < e \<longrightarrow> y \<in> S"
1.132 +        using * by fast
1.133 +      define r where "r = e / sqrt 2"
1.134 +      define s where "s = e / sqrt 2"
1.135 +      from \<open>0 < e\<close> have "0 < r" and "0 < s"
1.136 +        unfolding r_def s_def by simp_all
1.137 +      from \<open>0 < e\<close> have "e = sqrt (r\<^sup>2 + s\<^sup>2)"
1.138 +        unfolding r_def s_def by (simp add: power_divide)
1.139 +      define A where "A = {y. dist (fst x) y < r}"
1.140 +      define B where "B = {y. dist (snd x) y < s}"
1.141 +      have "open A" and "open B"
1.142 +        unfolding A_def B_def by (simp_all add: open_ball)
1.143 +      moreover have "x \<in> A \<times> B"
1.144 +        unfolding A_def B_def mem_Times_iff
1.145 +        using \<open>0 < r\<close> and \<open>0 < s\<close> by simp
1.146 +      moreover have "A \<times> B \<subseteq> S"
1.147 +      proof (clarify)
1.148 +        fix a b assume "a \<in> A" and "b \<in> B"
1.149 +        hence "dist a (fst x) < r" and "dist b (snd x) < s"
1.150 +          unfolding A_def B_def by (simp_all add: dist_commute)
1.151 +        hence "dist (a, b) x < e"
1.152 +          unfolding dist_prod_def \<open>e = sqrt (r\<^sup>2 + s\<^sup>2)\<close>
1.154 +        thus "(a, b) \<in> S"
1.155 +          by (simp add: S)
1.156 +      qed
1.157 +      ultimately show "\<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S" by fast
1.158 +    qed
1.159 +  qed
1.160 +  show "open S = (\<forall>x\<in>S. \<forall>\<^sub>F (x', y) in uniformity. x' = x \<longrightarrow> y \<in> S)"
1.161 +    unfolding * eventually_uniformity_metric
1.162 +    by (simp del: split_paired_All add: dist_prod_def dist_commute)
1.163 +qed
1.164 +
1.165 +end
1.166 +
1.167 +declare [[code abort: "dist::('a::metric_space*'b::metric_space)\<Rightarrow>('a*'b) \<Rightarrow> real"]]
1.168 +
1.169 +lemma Cauchy_fst: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. fst (X n))"
1.170 +  unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_fst_le])
1.171 +
1.172 +lemma Cauchy_snd: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. snd (X n))"
1.173 +  unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_snd_le])
1.174 +
1.175 +lemma Cauchy_Pair:
1.176 +  assumes "Cauchy X" and "Cauchy Y"
1.177 +  shows "Cauchy (\<lambda>n. (X n, Y n))"
1.178 +proof (rule metric_CauchyI)
1.179 +  fix r :: real assume "0 < r"
1.180 +  hence "0 < r / sqrt 2" (is "0 < ?s") by simp
1.181 +  obtain M where M: "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < ?s"
1.182 +    using metric_CauchyD [OF \<open>Cauchy X\<close> \<open>0 < ?s\<close>] ..
1.183 +  obtain N where N: "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (Y m) (Y n) < ?s"
1.184 +    using metric_CauchyD [OF \<open>Cauchy Y\<close> \<open>0 < ?s\<close>] ..
1.185 +  have "\<forall>m\<ge>max M N. \<forall>n\<ge>max M N. dist (X m, Y m) (X n, Y n) < r"
1.186 +    using M N by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
1.187 +  then show "\<exists>n0. \<forall>m\<ge>n0. \<forall>n\<ge>n0. dist (X m, Y m) (X n, Y n) < r" ..
1.188 +qed
1.189 +
1.190 +subsection \<open>Product is a complete metric space\<close>
1.191 +
1.192 +instance prod :: (complete_space, complete_space) complete_space
1.193 +proof
1.194 +  fix X :: "nat \<Rightarrow> 'a \<times> 'b" assume "Cauchy X"
1.195 +  have 1: "(\<lambda>n. fst (X n)) \<longlonglongrightarrow> lim (\<lambda>n. fst (X n))"
1.196 +    using Cauchy_fst [OF \<open>Cauchy X\<close>]
1.197 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
1.198 +  have 2: "(\<lambda>n. snd (X n)) \<longlonglongrightarrow> lim (\<lambda>n. snd (X n))"
1.199 +    using Cauchy_snd [OF \<open>Cauchy X\<close>]
1.200 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
1.201 +  have "X \<longlonglongrightarrow> (lim (\<lambda>n. fst (X n)), lim (\<lambda>n. snd (X n)))"
1.202 +    using tendsto_Pair [OF 1 2] by simp
1.203 +  then show "convergent X"
1.204 +    by (rule convergentI)
1.205 +qed
1.206 +
1.207 +subsection \<open>Product is a normed vector space\<close>
1.208 +
1.209 +instantiation prod :: (real_normed_vector, real_normed_vector) real_normed_vector
1.210 +begin
1.211 +
1.212 +definition norm_prod_def[code del]:
1.213 +  "norm x = sqrt ((norm (fst x))\<^sup>2 + (norm (snd x))\<^sup>2)"
1.214 +
1.215 +definition sgn_prod_def:
1.216 +  "sgn (x::'a \<times> 'b) = scaleR (inverse (norm x)) x"
1.217 +
1.218 +lemma norm_Pair: "norm (a, b) = sqrt ((norm a)\<^sup>2 + (norm b)\<^sup>2)"
1.219 +  unfolding norm_prod_def by simp
1.220 +
1.221 +instance
1.222 +proof
1.223 +  fix r :: real and x y :: "'a \<times> 'b"
1.224 +  show "norm x = 0 \<longleftrightarrow> x = 0"
1.225 +    unfolding norm_prod_def
1.226 +    by (simp add: prod_eq_iff)
1.227 +  show "norm (x + y) \<le> norm x + norm y"
1.228 +    unfolding norm_prod_def
1.229 +    apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
1.231 +    done
1.232 +  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
1.233 +    unfolding norm_prod_def
1.234 +    apply (simp add: power_mult_distrib)
1.235 +    apply (simp add: distrib_left [symmetric])
1.236 +    apply (simp add: real_sqrt_mult_distrib)
1.237 +    done
1.238 +  show "sgn x = scaleR (inverse (norm x)) x"
1.239 +    by (rule sgn_prod_def)
1.240 +  show "dist x y = norm (x - y)"
1.241 +    unfolding dist_prod_def norm_prod_def
1.242 +    by (simp add: dist_norm)
1.243 +qed
1.244 +
1.245 +end
1.246 +
1.247 +declare [[code abort: "norm::('a::real_normed_vector*'b::real_normed_vector) \<Rightarrow> real"]]
1.248 +
1.249 +instance prod :: (banach, banach) banach ..
1.250 +
1.251 +subsubsection \<open>Pair operations are linear\<close>
1.252 +
1.253 +lemma bounded_linear_fst: "bounded_linear fst"
1.255 +  by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
1.256 +
1.257 +lemma bounded_linear_snd: "bounded_linear snd"
1.259 +  by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
1.260 +
1.261 +lemmas bounded_linear_fst_comp = bounded_linear_fst[THEN bounded_linear_compose]
1.262 +
1.263 +lemmas bounded_linear_snd_comp = bounded_linear_snd[THEN bounded_linear_compose]
1.264 +
1.265 +lemma bounded_linear_Pair:
1.266 +  assumes f: "bounded_linear f"
1.267 +  assumes g: "bounded_linear g"
1.268 +  shows "bounded_linear (\<lambda>x. (f x, g x))"
1.269 +proof
1.270 +  interpret f: bounded_linear f by fact
1.271 +  interpret g: bounded_linear g by fact
1.272 +  fix x y and r :: real
1.273 +  show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
1.275 +  show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
1.276 +    by (simp add: f.scaleR g.scaleR)
1.277 +  obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
1.278 +    using f.pos_bounded by fast
1.279 +  obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
1.280 +    using g.pos_bounded by fast
1.281 +  have "\<forall>x. norm (f x, g x) \<le> norm x * (Kf + Kg)"
1.282 +    apply (rule allI)
1.283 +    apply (simp add: norm_Pair)
1.285 +    apply (simp add: distrib_left)
1.286 +    apply (rule add_mono [OF norm_f norm_g])
1.287 +    done
1.288 +  then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
1.289 +qed
1.290 +
1.291 +subsubsection \<open>Frechet derivatives involving pairs\<close>
1.292 +
1.293 +lemma has_derivative_Pair [derivative_intros]:
1.294 +  assumes f: "(f has_derivative f') (at x within s)" and g: "(g has_derivative g') (at x within s)"
1.295 +  shows "((\<lambda>x. (f x, g x)) has_derivative (\<lambda>h. (f' h, g' h))) (at x within s)"
1.296 +proof (rule has_derivativeI_sandwich[of 1])
1.297 +  show "bounded_linear (\<lambda>h. (f' h, g' h))"
1.298 +    using f g by (intro bounded_linear_Pair has_derivative_bounded_linear)
1.299 +  let ?Rf = "\<lambda>y. f y - f x - f' (y - x)"
1.300 +  let ?Rg = "\<lambda>y. g y - g x - g' (y - x)"
1.301 +  let ?R = "\<lambda>y. ((f y, g y) - (f x, g x) - (f' (y - x), g' (y - x)))"
1.302 +
1.303 +  show "((\<lambda>y. norm (?Rf y) / norm (y - x) + norm (?Rg y) / norm (y - x)) \<longlongrightarrow> 0) (at x within s)"
1.304 +    using f g by (intro tendsto_add_zero) (auto simp: has_derivative_iff_norm)
1.305 +
1.306 +  fix y :: 'a assume "y \<noteq> x"
1.307 +  show "norm (?R y) / norm (y - x) \<le> norm (?Rf y) / norm (y - x) + norm (?Rg y) / norm (y - x)"
1.310 +qed simp
1.311 +
1.312 +lemmas has_derivative_fst [derivative_intros] = bounded_linear.has_derivative [OF bounded_linear_fst]
1.313 +lemmas has_derivative_snd [derivative_intros] = bounded_linear.has_derivative [OF bounded_linear_snd]
1.314 +
1.315 +lemma has_derivative_split [derivative_intros]:
1.316 +  "((\<lambda>p. f (fst p) (snd p)) has_derivative f') F \<Longrightarrow> ((\<lambda>(a, b). f a b) has_derivative f') F"
1.317 +  unfolding split_beta' .
1.318 +
1.319 +subsection \<open>Product is an inner product space\<close>
1.320 +
1.321 +instantiation prod :: (real_inner, real_inner) real_inner
1.322 +begin
1.323 +
1.324 +definition inner_prod_def:
1.325 +  "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
1.326 +
1.327 +lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
1.328 +  unfolding inner_prod_def by simp
1.329 +
1.330 +instance
1.331 +proof
1.332 +  fix r :: real
1.333 +  fix x y z :: "'a::real_inner \<times> 'b::real_inner"
1.334 +  show "inner x y = inner y x"
1.335 +    unfolding inner_prod_def
1.336 +    by (simp add: inner_commute)
1.337 +  show "inner (x + y) z = inner x z + inner y z"
1.338 +    unfolding inner_prod_def
1.340 +  show "inner (scaleR r x) y = r * inner x y"
1.341 +    unfolding inner_prod_def
1.342 +    by (simp add: distrib_left)
1.343 +  show "0 \<le> inner x x"
1.344 +    unfolding inner_prod_def
1.345 +    by (intro add_nonneg_nonneg inner_ge_zero)
1.346 +  show "inner x x = 0 \<longleftrightarrow> x = 0"
1.347 +    unfolding inner_prod_def prod_eq_iff
1.349 +  show "norm x = sqrt (inner x x)"
1.350 +    unfolding norm_prod_def inner_prod_def
1.351 +    by (simp add: power2_norm_eq_inner)
1.352 +qed
1.353 +
1.354 +end
1.355 +
1.356 +lemma inner_Pair_0: "inner x (0, b) = inner (snd x) b" "inner x (a, 0) = inner (fst x) a"
1.357 +    by (cases x, simp)+
1.358 +
1.359 +lemma
1.360 +  fixes x :: "'a::real_normed_vector"
1.361 +  shows norm_Pair1 [simp]: "norm (0,x) = norm x"
1.362 +    and norm_Pair2 [simp]: "norm (x,0) = norm x"
1.363 +by (auto simp: norm_Pair)
1.364 +
1.365 +lemma norm_commute: "norm (x,y) = norm (y,x)"
1.366 +  by (simp add: norm_Pair)
1.367 +
1.368 +lemma norm_fst_le: "norm x \<le> norm (x,y)"
1.369 +  by (metis dist_fst_le fst_conv fst_zero norm_conv_dist)
1.370 +
1.371 +lemma norm_snd_le: "norm y \<le> norm (x,y)"
1.372 +  by (metis dist_snd_le snd_conv snd_zero norm_conv_dist)
1.373 +
1.374 +end
```