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