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