src/HOL/Library/Product_Vector.thy
changeset 44575 c5e42b8590dd
parent 44568 e6f291cb5810
child 44749 5b1e1432c320
     1.1 --- a/src/HOL/Library/Product_Vector.thy	Sun Aug 28 20:56:49 2011 -0700
     1.2 +++ b/src/HOL/Library/Product_Vector.thy	Mon Aug 29 08:31:09 2011 -0700
     1.3 @@ -154,7 +154,65 @@
     1.4    then show "\<exists>T. open T \<and> y \<in> T \<and> T \<subseteq> snd ` S" by - (rule exI)
     1.5  qed
     1.6  
     1.7 -text {* Product preserves separation axioms. *}
     1.8 +subsubsection {* Continuity of operations *}
     1.9 +
    1.10 +lemma tendsto_fst [tendsto_intros]:
    1.11 +  assumes "(f ---> a) F"
    1.12 +  shows "((\<lambda>x. fst (f x)) ---> fst a) F"
    1.13 +proof (rule topological_tendstoI)
    1.14 +  fix S assume "open S" and "fst a \<in> S"
    1.15 +  then have "open (fst -` S)" and "a \<in> fst -` S"
    1.16 +    by (simp_all add: open_vimage_fst)
    1.17 +  with assms have "eventually (\<lambda>x. f x \<in> fst -` S) F"
    1.18 +    by (rule topological_tendstoD)
    1.19 +  then show "eventually (\<lambda>x. fst (f x) \<in> S) F"
    1.20 +    by simp
    1.21 +qed
    1.22 +
    1.23 +lemma tendsto_snd [tendsto_intros]:
    1.24 +  assumes "(f ---> a) F"
    1.25 +  shows "((\<lambda>x. snd (f x)) ---> snd a) F"
    1.26 +proof (rule topological_tendstoI)
    1.27 +  fix S assume "open S" and "snd a \<in> S"
    1.28 +  then have "open (snd -` S)" and "a \<in> snd -` S"
    1.29 +    by (simp_all add: open_vimage_snd)
    1.30 +  with assms have "eventually (\<lambda>x. f x \<in> snd -` S) F"
    1.31 +    by (rule topological_tendstoD)
    1.32 +  then show "eventually (\<lambda>x. snd (f x) \<in> S) F"
    1.33 +    by simp
    1.34 +qed
    1.35 +
    1.36 +lemma tendsto_Pair [tendsto_intros]:
    1.37 +  assumes "(f ---> a) F" and "(g ---> b) F"
    1.38 +  shows "((\<lambda>x. (f x, g x)) ---> (a, b)) F"
    1.39 +proof (rule topological_tendstoI)
    1.40 +  fix S assume "open S" and "(a, b) \<in> S"
    1.41 +  then obtain A B where "open A" "open B" "a \<in> A" "b \<in> B" "A \<times> B \<subseteq> S"
    1.42 +    unfolding open_prod_def by fast
    1.43 +  have "eventually (\<lambda>x. f x \<in> A) F"
    1.44 +    using `(f ---> a) F` `open A` `a \<in> A`
    1.45 +    by (rule topological_tendstoD)
    1.46 +  moreover
    1.47 +  have "eventually (\<lambda>x. g x \<in> B) F"
    1.48 +    using `(g ---> b) F` `open B` `b \<in> B`
    1.49 +    by (rule topological_tendstoD)
    1.50 +  ultimately
    1.51 +  show "eventually (\<lambda>x. (f x, g x) \<in> S) F"
    1.52 +    by (rule eventually_elim2)
    1.53 +       (simp add: subsetD [OF `A \<times> B \<subseteq> S`])
    1.54 +qed
    1.55 +
    1.56 +lemma isCont_fst [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. fst (f x)) a"
    1.57 +  unfolding isCont_def by (rule tendsto_fst)
    1.58 +
    1.59 +lemma isCont_snd [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. snd (f x)) a"
    1.60 +  unfolding isCont_def by (rule tendsto_snd)
    1.61 +
    1.62 +lemma isCont_Pair [simp]:
    1.63 +  "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. (f x, g x)) a"
    1.64 +  unfolding isCont_def by (rule tendsto_Pair)
    1.65 +
    1.66 +subsubsection {* Separation axioms *}
    1.67  
    1.68  lemma mem_Times_iff: "x \<in> A \<times> B \<longleftrightarrow> fst x \<in> A \<and> snd x \<in> B"
    1.69    by (induct x) simp (* TODO: move elsewhere *)
    1.70 @@ -231,9 +289,6 @@
    1.71      by (intro order_trans [OF _ real_sqrt_sum_squares_triangle_ineq]
    1.72          real_sqrt_le_mono add_mono power_mono dist_triangle2 zero_le_dist)
    1.73  next
    1.74 -  (* FIXME: long proof! *)
    1.75 -  (* Maybe it would be easier to define topological spaces *)
    1.76 -  (* in terms of neighborhoods instead of open sets? *)
    1.77    fix S :: "('a \<times> 'b) set"
    1.78    show "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
    1.79    proof
    1.80 @@ -264,111 +319,40 @@
    1.81        thus "\<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" ..
    1.82      qed
    1.83    next
    1.84 -    assume "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" thus "open S"
    1.85 -    unfolding open_prod_def open_dist
    1.86 -    apply safe
    1.87 -    apply (drule (1) bspec)
    1.88 -    apply clarify
    1.89 -    apply (subgoal_tac "\<exists>r>0. \<exists>s>0. e = sqrt (r\<twosuperior> + s\<twosuperior>)")
    1.90 -    apply clarify
    1.91 -    apply (rule_tac x="{y. dist y a < r}" in exI)
    1.92 -    apply (rule_tac x="{y. dist y b < s}" in exI)
    1.93 -    apply (rule conjI)
    1.94 -    apply clarify
    1.95 -    apply (rule_tac x="r - dist x a" in exI, rule conjI, simp)
    1.96 -    apply clarify
    1.97 -    apply (simp add: less_diff_eq)
    1.98 -    apply (erule le_less_trans [OF dist_triangle])
    1.99 -    apply (rule conjI)
   1.100 -    apply clarify
   1.101 -    apply (rule_tac x="s - dist x b" in exI, rule conjI, simp)
   1.102 -    apply clarify
   1.103 -    apply (simp add: less_diff_eq)
   1.104 -    apply (erule le_less_trans [OF dist_triangle])
   1.105 -    apply (rule conjI)
   1.106 -    apply simp
   1.107 -    apply (clarify, rename_tac c d)
   1.108 -    apply (drule spec, erule mp)
   1.109 -    apply (simp add: dist_Pair_Pair add_strict_mono power_strict_mono)
   1.110 -    apply (rule_tac x="e / sqrt 2" in exI, simp add: divide_pos_pos)
   1.111 -    apply (rule_tac x="e / sqrt 2" in exI, simp add: divide_pos_pos)
   1.112 -    apply (simp add: power_divide)
   1.113 -    done
   1.114 +    assume *: "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" show "open S"
   1.115 +    proof (rule open_prod_intro)
   1.116 +      fix x assume "x \<in> S"
   1.117 +      then obtain e where "0 < e" and S: "\<forall>y. dist y x < e \<longrightarrow> y \<in> S"
   1.118 +        using * by fast
   1.119 +      def r \<equiv> "e / sqrt 2" and s \<equiv> "e / sqrt 2"
   1.120 +      from `0 < e` have "0 < r" and "0 < s"
   1.121 +        unfolding r_def s_def by (simp_all add: divide_pos_pos)
   1.122 +      from `0 < e` have "e = sqrt (r\<twosuperior> + s\<twosuperior>)"
   1.123 +        unfolding r_def s_def by (simp add: power_divide)
   1.124 +      def A \<equiv> "{y. dist (fst x) y < r}" and B \<equiv> "{y. dist (snd x) y < s}"
   1.125 +      have "open A" and "open B"
   1.126 +        unfolding A_def B_def by (simp_all add: open_ball)
   1.127 +      moreover have "x \<in> A \<times> B"
   1.128 +        unfolding A_def B_def mem_Times_iff
   1.129 +        using `0 < r` and `0 < s` by simp
   1.130 +      moreover have "A \<times> B \<subseteq> S"
   1.131 +      proof (clarify)
   1.132 +        fix a b assume "a \<in> A" and "b \<in> B"
   1.133 +        hence "dist a (fst x) < r" and "dist b (snd x) < s"
   1.134 +          unfolding A_def B_def by (simp_all add: dist_commute)
   1.135 +        hence "dist (a, b) x < e"
   1.136 +          unfolding dist_prod_def `e = sqrt (r\<twosuperior> + s\<twosuperior>)`
   1.137 +          by (simp add: add_strict_mono power_strict_mono)
   1.138 +        thus "(a, b) \<in> S"
   1.139 +          by (simp add: S)
   1.140 +      qed
   1.141 +      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.142 +    qed
   1.143    qed
   1.144  qed
   1.145  
   1.146  end
   1.147  
   1.148 -subsection {* Continuity of operations *}
   1.149 -
   1.150 -lemma tendsto_fst [tendsto_intros]:
   1.151 -  assumes "(f ---> a) net"
   1.152 -  shows "((\<lambda>x. fst (f x)) ---> fst a) net"
   1.153 -proof (rule topological_tendstoI)
   1.154 -  fix S assume "open S" "fst a \<in> S"
   1.155 -  then have "open (fst -` S)" "a \<in> fst -` S"
   1.156 -    unfolding open_prod_def
   1.157 -    apply simp_all
   1.158 -    apply clarify
   1.159 -    apply (rule exI, erule conjI)
   1.160 -    apply (rule exI, rule conjI [OF open_UNIV])
   1.161 -    apply auto
   1.162 -    done
   1.163 -  with assms have "eventually (\<lambda>x. f x \<in> fst -` S) net"
   1.164 -    by (rule topological_tendstoD)
   1.165 -  then show "eventually (\<lambda>x. fst (f x) \<in> S) net"
   1.166 -    by simp
   1.167 -qed
   1.168 -
   1.169 -lemma tendsto_snd [tendsto_intros]:
   1.170 -  assumes "(f ---> a) net"
   1.171 -  shows "((\<lambda>x. snd (f x)) ---> snd a) net"
   1.172 -proof (rule topological_tendstoI)
   1.173 -  fix S assume "open S" "snd a \<in> S"
   1.174 -  then have "open (snd -` S)" "a \<in> snd -` S"
   1.175 -    unfolding open_prod_def
   1.176 -    apply simp_all
   1.177 -    apply clarify
   1.178 -    apply (rule exI, rule conjI [OF open_UNIV])
   1.179 -    apply (rule exI, erule conjI)
   1.180 -    apply auto
   1.181 -    done
   1.182 -  with assms have "eventually (\<lambda>x. f x \<in> snd -` S) net"
   1.183 -    by (rule topological_tendstoD)
   1.184 -  then show "eventually (\<lambda>x. snd (f x) \<in> S) net"
   1.185 -    by simp
   1.186 -qed
   1.187 -
   1.188 -lemma tendsto_Pair [tendsto_intros]:
   1.189 -  assumes "(f ---> a) net" and "(g ---> b) net"
   1.190 -  shows "((\<lambda>x. (f x, g x)) ---> (a, b)) net"
   1.191 -proof (rule topological_tendstoI)
   1.192 -  fix S assume "open S" "(a, b) \<in> S"
   1.193 -  then obtain A B where "open A" "open B" "a \<in> A" "b \<in> B" "A \<times> B \<subseteq> S"
   1.194 -    unfolding open_prod_def by auto
   1.195 -  have "eventually (\<lambda>x. f x \<in> A) net"
   1.196 -    using `(f ---> a) net` `open A` `a \<in> A`
   1.197 -    by (rule topological_tendstoD)
   1.198 -  moreover
   1.199 -  have "eventually (\<lambda>x. g x \<in> B) net"
   1.200 -    using `(g ---> b) net` `open B` `b \<in> B`
   1.201 -    by (rule topological_tendstoD)
   1.202 -  ultimately
   1.203 -  show "eventually (\<lambda>x. (f x, g x) \<in> S) net"
   1.204 -    by (rule eventually_elim2)
   1.205 -       (simp add: subsetD [OF `A \<times> B \<subseteq> S`])
   1.206 -qed
   1.207 -
   1.208 -lemma isCont_fst [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. fst (f x)) a"
   1.209 -  unfolding isCont_def by (rule tendsto_fst)
   1.210 -
   1.211 -lemma isCont_snd [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. snd (f x)) a"
   1.212 -  unfolding isCont_def by (rule tendsto_snd)
   1.213 -
   1.214 -lemma isCont_Pair [simp]:
   1.215 -  "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. (f x, g x)) a"
   1.216 -  unfolding isCont_def by (rule tendsto_Pair)
   1.217 -
   1.218  lemma Cauchy_fst: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. fst (X n))"
   1.219  unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_fst_le])
   1.220  
   1.221 @@ -451,43 +435,7 @@
   1.222  
   1.223  instance prod :: (banach, banach) banach ..
   1.224  
   1.225 -subsection {* Product is an inner product space *}
   1.226 -
   1.227 -instantiation prod :: (real_inner, real_inner) real_inner
   1.228 -begin
   1.229 -
   1.230 -definition inner_prod_def:
   1.231 -  "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
   1.232 -
   1.233 -lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
   1.234 -  unfolding inner_prod_def by simp
   1.235 -
   1.236 -instance proof
   1.237 -  fix r :: real
   1.238 -  fix x y z :: "'a::real_inner * 'b::real_inner"
   1.239 -  show "inner x y = inner y x"
   1.240 -    unfolding inner_prod_def
   1.241 -    by (simp add: inner_commute)
   1.242 -  show "inner (x + y) z = inner x z + inner y z"
   1.243 -    unfolding inner_prod_def
   1.244 -    by (simp add: inner_add_left)
   1.245 -  show "inner (scaleR r x) y = r * inner x y"
   1.246 -    unfolding inner_prod_def
   1.247 -    by (simp add: right_distrib)
   1.248 -  show "0 \<le> inner x x"
   1.249 -    unfolding inner_prod_def
   1.250 -    by (intro add_nonneg_nonneg inner_ge_zero)
   1.251 -  show "inner x x = 0 \<longleftrightarrow> x = 0"
   1.252 -    unfolding inner_prod_def prod_eq_iff
   1.253 -    by (simp add: add_nonneg_eq_0_iff)
   1.254 -  show "norm x = sqrt (inner x x)"
   1.255 -    unfolding norm_prod_def inner_prod_def
   1.256 -    by (simp add: power2_norm_eq_inner)
   1.257 -qed
   1.258 -
   1.259 -end
   1.260 -
   1.261 -subsection {* Pair operations are linear *}
   1.262 +subsubsection {* Pair operations are linear *}
   1.263  
   1.264  lemma bounded_linear_fst: "bounded_linear fst"
   1.265    using fst_add fst_scaleR
   1.266 @@ -533,29 +481,65 @@
   1.267    then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
   1.268  qed
   1.269  
   1.270 -subsection {* Frechet derivatives involving pairs *}
   1.271 +subsubsection {* Frechet derivatives involving pairs *}
   1.272  
   1.273  lemma FDERIV_Pair:
   1.274    assumes f: "FDERIV f x :> f'" and g: "FDERIV g x :> g'"
   1.275    shows "FDERIV (\<lambda>x. (f x, g x)) x :> (\<lambda>h. (f' h, g' h))"
   1.276 -apply (rule FDERIV_I)
   1.277 -apply (rule bounded_linear_Pair)
   1.278 -apply (rule FDERIV_bounded_linear [OF f])
   1.279 -apply (rule FDERIV_bounded_linear [OF g])
   1.280 -apply (simp add: norm_Pair)
   1.281 -apply (rule real_LIM_sandwich_zero)
   1.282 -apply (rule tendsto_add_zero)
   1.283 -apply (rule FDERIV_D [OF f])
   1.284 -apply (rule FDERIV_D [OF g])
   1.285 -apply (rename_tac h)
   1.286 -apply (simp add: divide_nonneg_pos)
   1.287 -apply (rename_tac h)
   1.288 -apply (subst add_divide_distrib [symmetric])
   1.289 -apply (rule divide_right_mono [OF _ norm_ge_zero])
   1.290 -apply (rule order_trans [OF sqrt_add_le_add_sqrt])
   1.291 -apply simp
   1.292 -apply simp
   1.293 -apply simp
   1.294 -done
   1.295 +proof (rule FDERIV_I)
   1.296 +  show "bounded_linear (\<lambda>h. (f' h, g' h))"
   1.297 +    using f g by (intro bounded_linear_Pair FDERIV_bounded_linear)
   1.298 +  let ?Rf = "\<lambda>h. f (x + h) - f x - f' h"
   1.299 +  let ?Rg = "\<lambda>h. g (x + h) - g x - g' h"
   1.300 +  let ?R = "\<lambda>h. ((f (x + h), g (x + h)) - (f x, g x) - (f' h, g' h))"
   1.301 +  show "(\<lambda>h. norm (?R h) / norm h) -- 0 --> 0"
   1.302 +  proof (rule real_LIM_sandwich_zero)
   1.303 +    show "(\<lambda>h. norm (?Rf h) / norm h + norm (?Rg h) / norm h) -- 0 --> 0"
   1.304 +      using f g by (intro tendsto_add_zero FDERIV_D)
   1.305 +    fix h :: 'a assume "h \<noteq> 0"
   1.306 +    thus "0 \<le> norm (?R h) / norm h"
   1.307 +      by (simp add: divide_nonneg_pos)
   1.308 +    show "norm (?R h) / norm h \<le> norm (?Rf h) / norm h + norm (?Rg h) / norm h"
   1.309 +      unfolding add_divide_distrib [symmetric]
   1.310 +      by (simp add: norm_Pair divide_right_mono
   1.311 +        order_trans [OF sqrt_add_le_add_sqrt])
   1.312 +  qed
   1.313 +qed
   1.314 +
   1.315 +subsection {* Product is an inner product space *}
   1.316 +
   1.317 +instantiation prod :: (real_inner, real_inner) real_inner
   1.318 +begin
   1.319 +
   1.320 +definition inner_prod_def:
   1.321 +  "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
   1.322 +
   1.323 +lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
   1.324 +  unfolding inner_prod_def by simp
   1.325 +
   1.326 +instance proof
   1.327 +  fix r :: real
   1.328 +  fix x y z :: "'a::real_inner \<times> 'b::real_inner"
   1.329 +  show "inner x y = inner y x"
   1.330 +    unfolding inner_prod_def
   1.331 +    by (simp add: inner_commute)
   1.332 +  show "inner (x + y) z = inner x z + inner y z"
   1.333 +    unfolding inner_prod_def
   1.334 +    by (simp add: inner_add_left)
   1.335 +  show "inner (scaleR r x) y = r * inner x y"
   1.336 +    unfolding inner_prod_def
   1.337 +    by (simp add: right_distrib)
   1.338 +  show "0 \<le> inner x x"
   1.339 +    unfolding inner_prod_def
   1.340 +    by (intro add_nonneg_nonneg inner_ge_zero)
   1.341 +  show "inner x x = 0 \<longleftrightarrow> x = 0"
   1.342 +    unfolding inner_prod_def prod_eq_iff
   1.343 +    by (simp add: add_nonneg_eq_0_iff)
   1.344 +  show "norm x = sqrt (inner x x)"
   1.345 +    unfolding norm_prod_def inner_prod_def
   1.346 +    by (simp add: power2_norm_eq_inner)
   1.347 +qed
   1.348  
   1.349  end
   1.350 +
   1.351 +end