src/HOL/Library/Product_Vector.thy
author huffman
Mon Aug 15 14:29:17 2011 -0700 (2011-08-15)
changeset 44214 1e0414bda9af
parent 44127 7b57b9295d98
child 44233 aa74ce315bae
permissions -rw-r--r--
Library/Product_Vector.thy: class instances for t0_space, t1_space, and t2_space
huffman@30019
     1
(*  Title:      HOL/Library/Product_Vector.thy
huffman@30019
     2
    Author:     Brian Huffman
huffman@30019
     3
*)
huffman@30019
     4
huffman@30019
     5
header {* 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
huffman@30019
    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 \<times> '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
huffman@31415
    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
huffman@31492
    47
definition open_prod_def:
huffman@31492
    48
  "open (S :: ('a \<times> 'b) set) \<longleftrightarrow>
huffman@31492
    49
    (\<forall>x\<in>S. \<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S)"
huffman@31415
    50
huffman@36332
    51
lemma open_prod_elim:
huffman@36332
    52
  assumes "open S" and "x \<in> S"
huffman@36332
    53
  obtains A B where "open A" and "open B" and "x \<in> A \<times> B" and "A \<times> B \<subseteq> 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 "\<And>x. x \<in> S \<Longrightarrow> \<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> 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 \<times> 'b) set)"
huffman@31492
    63
    unfolding open_prod_def by auto
huffman@31415
    64
next
huffman@31415
    65
  fix S T :: "('a \<times> 'b) set"
huffman@36332
    66
  assume "open S" "open T"
huffman@36332
    67
  show "open (S \<inter> T)"
huffman@36332
    68
  proof (rule open_prod_intro)
huffman@36332
    69
    fix x assume x: "x \<in> S \<inter> T"
huffman@36332
    70
    from x have "x \<in> S" by simp
huffman@36332
    71
    obtain Sa Sb where A: "open Sa" "open Sb" "x \<in> Sa \<times> Sb" "Sa \<times> Sb \<subseteq> S"
huffman@36332
    72
      using `open S` and `x \<in> S` by (rule open_prod_elim)
huffman@36332
    73
    from x have "x \<in> T" by simp
huffman@36332
    74
    obtain Ta Tb where B: "open Ta" "open Tb" "x \<in> Ta \<times> Tb" "Ta \<times> Tb \<subseteq> T"
huffman@36332
    75
      using `open T` and `x \<in> T` by (rule open_prod_elim)
huffman@36332
    76
    let ?A = "Sa \<inter> Ta" and ?B = "Sb \<inter> Tb"
huffman@36332
    77
    have "open ?A \<and> open ?B \<and> x \<in> ?A \<times> ?B \<and> ?A \<times> ?B \<subseteq> S \<inter> T"
huffman@36332
    78
      using A B by (auto simp add: open_Int)
huffman@36332
    79
    thus "\<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S \<inter> T"
huffman@36332
    80
      by fast
huffman@36332
    81
  qed
huffman@31415
    82
next
huffman@31492
    83
  fix K :: "('a \<times> 'b) set set"
huffman@31492
    84
  assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)"
huffman@31492
    85
    unfolding open_prod_def by fast
huffman@31415
    86
qed
huffman@31415
    87
huffman@31415
    88
end
huffman@31415
    89
huffman@31562
    90
lemma open_Times: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<times> T)"
huffman@31562
    91
unfolding open_prod_def by auto
huffman@31562
    92
huffman@31562
    93
lemma fst_vimage_eq_Times: "fst -` S = S \<times> UNIV"
huffman@31562
    94
by auto
huffman@31562
    95
huffman@31562
    96
lemma snd_vimage_eq_Times: "snd -` S = UNIV \<times> S"
huffman@31562
    97
by auto
huffman@31562
    98
huffman@31562
    99
lemma open_vimage_fst: "open S \<Longrightarrow> open (fst -` S)"
huffman@31562
   100
by (simp add: fst_vimage_eq_Times open_Times)
huffman@31562
   101
huffman@31562
   102
lemma open_vimage_snd: "open S \<Longrightarrow> open (snd -` S)"
huffman@31562
   103
by (simp add: snd_vimage_eq_Times open_Times)
huffman@31562
   104
huffman@31568
   105
lemma closed_vimage_fst: "closed S \<Longrightarrow> closed (fst -` S)"
huffman@31568
   106
unfolding closed_open vimage_Compl [symmetric]
huffman@31568
   107
by (rule open_vimage_fst)
huffman@31568
   108
huffman@31568
   109
lemma closed_vimage_snd: "closed S \<Longrightarrow> closed (snd -` S)"
huffman@31568
   110
unfolding closed_open vimage_Compl [symmetric]
huffman@31568
   111
by (rule open_vimage_snd)
huffman@31568
   112
huffman@31568
   113
lemma closed_Times: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<times> T)"
huffman@31568
   114
proof -
huffman@31568
   115
  have "S \<times> T = (fst -` S) \<inter> (snd -` T)" by auto
huffman@31568
   116
  thus "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<times> T)"
huffman@31568
   117
    by (simp add: closed_vimage_fst closed_vimage_snd closed_Int)
huffman@31568
   118
qed
huffman@31568
   119
huffman@34110
   120
lemma openI: (* TODO: move *)
huffman@34110
   121
  assumes "\<And>x. x \<in> S \<Longrightarrow> \<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> S"
huffman@34110
   122
  shows "open S"
huffman@34110
   123
proof -
huffman@34110
   124
  have "open (\<Union>{T. open T \<and> T \<subseteq> S})" by auto
huffman@34110
   125
  moreover have "\<Union>{T. open T \<and> T \<subseteq> S} = S" by (auto dest!: assms)
huffman@34110
   126
  ultimately show "open S" by simp
huffman@34110
   127
qed
huffman@34110
   128
huffman@34110
   129
lemma subset_fst_imageI: "A \<times> B \<subseteq> S \<Longrightarrow> y \<in> B \<Longrightarrow> A \<subseteq> fst ` S"
huffman@34110
   130
  unfolding image_def subset_eq by force
huffman@34110
   131
huffman@34110
   132
lemma subset_snd_imageI: "A \<times> B \<subseteq> S \<Longrightarrow> x \<in> A \<Longrightarrow> B \<subseteq> snd ` S"
huffman@34110
   133
  unfolding image_def subset_eq by force
huffman@34110
   134
huffman@34110
   135
lemma open_image_fst: assumes "open S" shows "open (fst ` S)"
huffman@34110
   136
proof (rule openI)
huffman@34110
   137
  fix x assume "x \<in> fst ` S"
huffman@34110
   138
  then obtain y where "(x, y) \<in> S" by auto
huffman@34110
   139
  then obtain A B where "open A" "open B" "x \<in> A" "y \<in> B" "A \<times> B \<subseteq> S"
huffman@34110
   140
    using `open S` unfolding open_prod_def by auto
huffman@34110
   141
  from `A \<times> B \<subseteq> S` `y \<in> B` have "A \<subseteq> fst ` S" by (rule subset_fst_imageI)
huffman@34110
   142
  with `open A` `x \<in> A` have "open A \<and> x \<in> A \<and> A \<subseteq> fst ` S" by simp
huffman@34110
   143
  then show "\<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> fst ` S" by - (rule exI)
huffman@34110
   144
qed
huffman@34110
   145
huffman@34110
   146
lemma open_image_snd: assumes "open S" shows "open (snd ` S)"
huffman@34110
   147
proof (rule openI)
huffman@34110
   148
  fix y assume "y \<in> snd ` S"
huffman@34110
   149
  then obtain x where "(x, y) \<in> S" by auto
huffman@34110
   150
  then obtain A B where "open A" "open B" "x \<in> A" "y \<in> B" "A \<times> B \<subseteq> S"
huffman@34110
   151
    using `open S` unfolding open_prod_def by auto
huffman@34110
   152
  from `A \<times> B \<subseteq> S` `x \<in> A` have "B \<subseteq> snd ` S" by (rule subset_snd_imageI)
huffman@34110
   153
  with `open B` `y \<in> B` have "open B \<and> y \<in> B \<and> B \<subseteq> snd ` S" by simp
huffman@34110
   154
  then show "\<exists>T. open T \<and> y \<in> T \<and> T \<subseteq> snd ` S" by - (rule exI)
huffman@34110
   155
qed
huffman@31568
   156
huffman@44214
   157
text {* Product preserves separation axioms. *}
huffman@44214
   158
huffman@44214
   159
lemma mem_Times_iff: "x \<in> A \<times> B \<longleftrightarrow> fst x \<in> A \<and> snd x \<in> B"
huffman@44214
   160
  by (induct x) simp (* TODO: move elsewhere *)
huffman@44214
   161
huffman@44214
   162
instance prod :: (t0_space, t0_space) t0_space
huffman@44214
   163
proof
huffman@44214
   164
  fix x y :: "'a \<times> 'b" assume "x \<noteq> y"
huffman@44214
   165
  hence "fst x \<noteq> fst y \<or> snd x \<noteq> snd y"
huffman@44214
   166
    by (simp add: prod_eq_iff)
huffman@44214
   167
  thus "\<exists>U. open U \<and> (x \<in> U) \<noteq> (y \<in> U)"
huffman@44214
   168
    apply (rule disjE)
huffman@44214
   169
    apply (drule t0_space, erule exE, rule_tac x="U \<times> UNIV" in exI)
huffman@44214
   170
    apply (simp add: open_Times mem_Times_iff)
huffman@44214
   171
    apply (drule t0_space, erule exE, rule_tac x="UNIV \<times> U" in exI)
huffman@44214
   172
    apply (simp add: open_Times mem_Times_iff)
huffman@44214
   173
    done
huffman@44214
   174
qed
huffman@44214
   175
huffman@44214
   176
instance prod :: (t1_space, t1_space) t1_space
huffman@44214
   177
proof
huffman@44214
   178
  fix x y :: "'a \<times> 'b" assume "x \<noteq> y"
huffman@44214
   179
  hence "fst x \<noteq> fst y \<or> snd x \<noteq> snd y"
huffman@44214
   180
    by (simp add: prod_eq_iff)
huffman@44214
   181
  thus "\<exists>U. open U \<and> x \<in> U \<and> y \<notin> U"
huffman@44214
   182
    apply (rule disjE)
huffman@44214
   183
    apply (drule t1_space, erule exE, rule_tac x="U \<times> UNIV" in exI)
huffman@44214
   184
    apply (simp add: open_Times mem_Times_iff)
huffman@44214
   185
    apply (drule t1_space, erule exE, rule_tac x="UNIV \<times> U" in exI)
huffman@44214
   186
    apply (simp add: open_Times mem_Times_iff)
huffman@44214
   187
    done
huffman@44214
   188
qed
huffman@44214
   189
huffman@44214
   190
instance prod :: (t2_space, t2_space) t2_space
huffman@44214
   191
proof
huffman@44214
   192
  fix x y :: "'a \<times> 'b" assume "x \<noteq> y"
huffman@44214
   193
  hence "fst x \<noteq> fst y \<or> snd x \<noteq> snd y"
huffman@44214
   194
    by (simp add: prod_eq_iff)
huffman@44214
   195
  thus "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
huffman@44214
   196
    apply (rule disjE)
huffman@44214
   197
    apply (drule hausdorff, clarify)
huffman@44214
   198
    apply (rule_tac x="U \<times> UNIV" in exI, rule_tac x="V \<times> UNIV" in exI)
huffman@44214
   199
    apply (simp add: open_Times mem_Times_iff disjoint_iff_not_equal)
huffman@44214
   200
    apply (drule hausdorff, clarify)
huffman@44214
   201
    apply (rule_tac x="UNIV \<times> U" in exI, rule_tac x="UNIV \<times> V" in exI)
huffman@44214
   202
    apply (simp add: open_Times mem_Times_iff disjoint_iff_not_equal)
huffman@44214
   203
    done
huffman@44214
   204
qed
huffman@44214
   205
huffman@31339
   206
subsection {* Product is a metric space *}
huffman@31339
   207
haftmann@37678
   208
instantiation prod :: (metric_space, metric_space) metric_space
huffman@31339
   209
begin
huffman@31339
   210
huffman@31339
   211
definition dist_prod_def:
huffman@44214
   212
  "dist x y = sqrt ((dist (fst x) (fst y))\<twosuperior> + (dist (snd x) (snd y))\<twosuperior>)"
huffman@31339
   213
huffman@31339
   214
lemma dist_Pair_Pair: "dist (a, b) (c, d) = sqrt ((dist a c)\<twosuperior> + (dist b d)\<twosuperior>)"
huffman@31339
   215
  unfolding dist_prod_def by simp
huffman@31339
   216
huffman@36332
   217
lemma dist_fst_le: "dist (fst x) (fst y) \<le> dist x y"
huffman@36332
   218
unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge1)
huffman@36332
   219
huffman@36332
   220
lemma dist_snd_le: "dist (snd x) (snd y) \<le> dist x y"
huffman@36332
   221
unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge2)
huffman@36332
   222
huffman@31339
   223
instance proof
huffman@31339
   224
  fix x y :: "'a \<times> 'b"
huffman@31339
   225
  show "dist x y = 0 \<longleftrightarrow> x = y"
huffman@44066
   226
    unfolding dist_prod_def prod_eq_iff by simp
huffman@31339
   227
next
huffman@31339
   228
  fix x y z :: "'a \<times> 'b"
huffman@31339
   229
  show "dist x y \<le> dist x z + dist y z"
huffman@31339
   230
    unfolding dist_prod_def
huffman@31563
   231
    by (intro order_trans [OF _ real_sqrt_sum_squares_triangle_ineq]
huffman@31563
   232
        real_sqrt_le_mono add_mono power_mono dist_triangle2 zero_le_dist)
huffman@31415
   233
next
huffman@31415
   234
  (* FIXME: long proof! *)
huffman@31415
   235
  (* Maybe it would be easier to define topological spaces *)
huffman@31415
   236
  (* in terms of neighborhoods instead of open sets? *)
huffman@31492
   237
  fix S :: "('a \<times> 'b) set"
huffman@31492
   238
  show "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
huffman@31563
   239
  proof
huffman@36332
   240
    assume "open S" show "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S"
huffman@36332
   241
    proof
huffman@36332
   242
      fix x assume "x \<in> S"
huffman@36332
   243
      obtain A B where "open A" "open B" "x \<in> A \<times> B" "A \<times> B \<subseteq> S"
huffman@36332
   244
        using `open S` and `x \<in> S` by (rule open_prod_elim)
huffman@36332
   245
      obtain r where r: "0 < r" "\<forall>y. dist y (fst x) < r \<longrightarrow> y \<in> A"
huffman@36332
   246
        using `open A` and `x \<in> A \<times> B` unfolding open_dist by auto
huffman@36332
   247
      obtain s where s: "0 < s" "\<forall>y. dist y (snd x) < s \<longrightarrow> y \<in> B"
huffman@36332
   248
        using `open B` and `x \<in> A \<times> B` unfolding open_dist by auto
huffman@36332
   249
      let ?e = "min r s"
huffman@36332
   250
      have "0 < ?e \<and> (\<forall>y. dist y x < ?e \<longrightarrow> y \<in> S)"
huffman@36332
   251
      proof (intro allI impI conjI)
huffman@36332
   252
        show "0 < min r s" by (simp add: r(1) s(1))
huffman@36332
   253
      next
huffman@36332
   254
        fix y assume "dist y x < min r s"
huffman@36332
   255
        hence "dist y x < r" and "dist y x < s"
huffman@36332
   256
          by simp_all
huffman@36332
   257
        hence "dist (fst y) (fst x) < r" and "dist (snd y) (snd x) < s"
huffman@36332
   258
          by (auto intro: le_less_trans dist_fst_le dist_snd_le)
huffman@36332
   259
        hence "fst y \<in> A" and "snd y \<in> B"
huffman@36332
   260
          by (simp_all add: r(2) s(2))
huffman@36332
   261
        hence "y \<in> A \<times> B" by (induct y, simp)
huffman@36332
   262
        with `A \<times> B \<subseteq> S` show "y \<in> S" ..
huffman@36332
   263
      qed
huffman@36332
   264
      thus "\<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" ..
huffman@36332
   265
    qed
huffman@31563
   266
  next
huffman@31563
   267
    assume "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" thus "open S"
huffman@31563
   268
    unfolding open_prod_def open_dist
huffman@31563
   269
    apply safe
huffman@31415
   270
    apply (drule (1) bspec)
huffman@31415
   271
    apply clarify
huffman@31415
   272
    apply (subgoal_tac "\<exists>r>0. \<exists>s>0. e = sqrt (r\<twosuperior> + s\<twosuperior>)")
huffman@31415
   273
    apply clarify
huffman@31492
   274
    apply (rule_tac x="{y. dist y a < r}" in exI)
huffman@31492
   275
    apply (rule_tac x="{y. dist y b < s}" in exI)
huffman@31492
   276
    apply (rule conjI)
huffman@31415
   277
    apply clarify
huffman@31415
   278
    apply (rule_tac x="r - dist x a" in exI, rule conjI, simp)
huffman@31415
   279
    apply clarify
huffman@31563
   280
    apply (simp add: less_diff_eq)
huffman@31563
   281
    apply (erule le_less_trans [OF dist_triangle])
huffman@31492
   282
    apply (rule conjI)
huffman@31415
   283
    apply clarify
huffman@31415
   284
    apply (rule_tac x="s - dist x b" in exI, rule conjI, simp)
huffman@31415
   285
    apply clarify
huffman@31563
   286
    apply (simp add: less_diff_eq)
huffman@31563
   287
    apply (erule le_less_trans [OF dist_triangle])
huffman@31415
   288
    apply (rule conjI)
huffman@31415
   289
    apply simp
huffman@31415
   290
    apply (clarify, rename_tac c d)
huffman@31415
   291
    apply (drule spec, erule mp)
huffman@31415
   292
    apply (simp add: dist_Pair_Pair add_strict_mono power_strict_mono)
huffman@31415
   293
    apply (rule_tac x="e / sqrt 2" in exI, simp add: divide_pos_pos)
huffman@31415
   294
    apply (rule_tac x="e / sqrt 2" in exI, simp add: divide_pos_pos)
huffman@31415
   295
    apply (simp add: power_divide)
huffman@31415
   296
    done
huffman@31563
   297
  qed
huffman@31339
   298
qed
huffman@31339
   299
huffman@31339
   300
end
huffman@31339
   301
huffman@31405
   302
subsection {* Continuity of operations *}
huffman@31405
   303
huffman@31565
   304
lemma tendsto_fst [tendsto_intros]:
huffman@31491
   305
  assumes "(f ---> a) net"
huffman@31491
   306
  shows "((\<lambda>x. fst (f x)) ---> fst a) net"
huffman@31491
   307
proof (rule topological_tendstoI)
huffman@31492
   308
  fix S assume "open S" "fst a \<in> S"
huffman@31492
   309
  then have "open (fst -` S)" "a \<in> fst -` S"
huffman@31492
   310
    unfolding open_prod_def
huffman@31491
   311
    apply simp_all
huffman@31491
   312
    apply clarify
huffman@31492
   313
    apply (rule exI, erule conjI)
huffman@31492
   314
    apply (rule exI, rule conjI [OF open_UNIV])
huffman@31491
   315
    apply auto
huffman@31491
   316
    done
huffman@31491
   317
  with assms have "eventually (\<lambda>x. f x \<in> fst -` S) net"
huffman@31491
   318
    by (rule topological_tendstoD)
huffman@31491
   319
  then show "eventually (\<lambda>x. fst (f x) \<in> S) net"
huffman@31491
   320
    by simp
huffman@31405
   321
qed
huffman@31405
   322
huffman@31565
   323
lemma tendsto_snd [tendsto_intros]:
huffman@31491
   324
  assumes "(f ---> a) net"
huffman@31491
   325
  shows "((\<lambda>x. snd (f x)) ---> snd a) net"
huffman@31491
   326
proof (rule topological_tendstoI)
huffman@31492
   327
  fix S assume "open S" "snd a \<in> S"
huffman@31492
   328
  then have "open (snd -` S)" "a \<in> snd -` S"
huffman@31492
   329
    unfolding open_prod_def
huffman@31491
   330
    apply simp_all
huffman@31491
   331
    apply clarify
huffman@31492
   332
    apply (rule exI, rule conjI [OF open_UNIV])
huffman@31492
   333
    apply (rule exI, erule conjI)
huffman@31491
   334
    apply auto
huffman@31491
   335
    done
huffman@31491
   336
  with assms have "eventually (\<lambda>x. f x \<in> snd -` S) net"
huffman@31491
   337
    by (rule topological_tendstoD)
huffman@31491
   338
  then show "eventually (\<lambda>x. snd (f x) \<in> S) net"
huffman@31491
   339
    by simp
huffman@31405
   340
qed
huffman@31405
   341
huffman@31565
   342
lemma tendsto_Pair [tendsto_intros]:
huffman@31491
   343
  assumes "(f ---> a) net" and "(g ---> b) net"
huffman@31491
   344
  shows "((\<lambda>x. (f x, g x)) ---> (a, b)) net"
huffman@31491
   345
proof (rule topological_tendstoI)
huffman@31492
   346
  fix S assume "open S" "(a, b) \<in> S"
huffman@31492
   347
  then obtain A B where "open A" "open B" "a \<in> A" "b \<in> B" "A \<times> B \<subseteq> S"
huffman@31492
   348
    unfolding open_prod_def by auto
huffman@31491
   349
  have "eventually (\<lambda>x. f x \<in> A) net"
huffman@31492
   350
    using `(f ---> a) net` `open A` `a \<in> A`
huffman@31491
   351
    by (rule topological_tendstoD)
huffman@31405
   352
  moreover
huffman@31491
   353
  have "eventually (\<lambda>x. g x \<in> B) net"
huffman@31492
   354
    using `(g ---> b) net` `open B` `b \<in> B`
huffman@31491
   355
    by (rule topological_tendstoD)
huffman@31405
   356
  ultimately
huffman@31491
   357
  show "eventually (\<lambda>x. (f x, g x) \<in> S) net"
huffman@31405
   358
    by (rule eventually_elim2)
huffman@31491
   359
       (simp add: subsetD [OF `A \<times> B \<subseteq> S`])
huffman@31405
   360
qed
huffman@31405
   361
huffman@31405
   362
lemma Cauchy_fst: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. fst (X n))"
huffman@31405
   363
unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_fst_le])
huffman@31405
   364
huffman@31405
   365
lemma Cauchy_snd: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. snd (X n))"
huffman@31405
   366
unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_snd_le])
huffman@31405
   367
huffman@31405
   368
lemma Cauchy_Pair:
huffman@31405
   369
  assumes "Cauchy X" and "Cauchy Y"
huffman@31405
   370
  shows "Cauchy (\<lambda>n. (X n, Y n))"
huffman@31405
   371
proof (rule metric_CauchyI)
huffman@31405
   372
  fix r :: real assume "0 < r"
huffman@31405
   373
  then have "0 < r / sqrt 2" (is "0 < ?s")
huffman@31405
   374
    by (simp add: divide_pos_pos)
huffman@31405
   375
  obtain M where M: "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < ?s"
huffman@31405
   376
    using metric_CauchyD [OF `Cauchy X` `0 < ?s`] ..
huffman@31405
   377
  obtain N where N: "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (Y m) (Y n) < ?s"
huffman@31405
   378
    using metric_CauchyD [OF `Cauchy Y` `0 < ?s`] ..
huffman@31405
   379
  have "\<forall>m\<ge>max M N. \<forall>n\<ge>max M N. dist (X m, Y m) (X n, Y n) < r"
huffman@31405
   380
    using M N by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
huffman@31405
   381
  then show "\<exists>n0. \<forall>m\<ge>n0. \<forall>n\<ge>n0. dist (X m, Y m) (X n, Y n) < r" ..
huffman@31405
   382
qed
huffman@31405
   383
huffman@31405
   384
lemma isCont_Pair [simp]:
huffman@31405
   385
  "\<lbrakk>isCont f x; isCont g x\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. (f x, g x)) x"
huffman@36661
   386
  unfolding isCont_def by (rule tendsto_Pair)
huffman@31405
   387
huffman@31405
   388
subsection {* Product is a complete metric space *}
huffman@31405
   389
haftmann@37678
   390
instance prod :: (complete_space, complete_space) complete_space
huffman@31405
   391
proof
huffman@31405
   392
  fix X :: "nat \<Rightarrow> 'a \<times> 'b" assume "Cauchy X"
huffman@31405
   393
  have 1: "(\<lambda>n. fst (X n)) ----> lim (\<lambda>n. fst (X n))"
huffman@31405
   394
    using Cauchy_fst [OF `Cauchy X`]
huffman@31405
   395
    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
huffman@31405
   396
  have 2: "(\<lambda>n. snd (X n)) ----> lim (\<lambda>n. snd (X n))"
huffman@31405
   397
    using Cauchy_snd [OF `Cauchy X`]
huffman@31405
   398
    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
huffman@31405
   399
  have "X ----> (lim (\<lambda>n. fst (X n)), lim (\<lambda>n. snd (X n)))"
huffman@36660
   400
    using tendsto_Pair [OF 1 2] by simp
huffman@31405
   401
  then show "convergent X"
huffman@31405
   402
    by (rule convergentI)
huffman@31405
   403
qed
huffman@31405
   404
huffman@30019
   405
subsection {* Product is a normed vector space *}
huffman@30019
   406
haftmann@37678
   407
instantiation prod :: (real_normed_vector, real_normed_vector) real_normed_vector
huffman@30019
   408
begin
huffman@30019
   409
huffman@30019
   410
definition norm_prod_def:
huffman@30019
   411
  "norm x = sqrt ((norm (fst x))\<twosuperior> + (norm (snd x))\<twosuperior>)"
huffman@30019
   412
huffman@30019
   413
definition sgn_prod_def:
huffman@30019
   414
  "sgn (x::'a \<times> 'b) = scaleR (inverse (norm x)) x"
huffman@30019
   415
huffman@30019
   416
lemma norm_Pair: "norm (a, b) = sqrt ((norm a)\<twosuperior> + (norm b)\<twosuperior>)"
huffman@30019
   417
  unfolding norm_prod_def by simp
huffman@30019
   418
huffman@30019
   419
instance proof
huffman@30019
   420
  fix r :: real and x y :: "'a \<times> 'b"
huffman@30019
   421
  show "0 \<le> norm x"
huffman@30019
   422
    unfolding norm_prod_def by simp
huffman@30019
   423
  show "norm x = 0 \<longleftrightarrow> x = 0"
huffman@30019
   424
    unfolding norm_prod_def
huffman@44066
   425
    by (simp add: prod_eq_iff)
huffman@30019
   426
  show "norm (x + y) \<le> norm x + norm y"
huffman@30019
   427
    unfolding norm_prod_def
huffman@30019
   428
    apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
huffman@30019
   429
    apply (simp add: add_mono power_mono norm_triangle_ineq)
huffman@30019
   430
    done
huffman@30019
   431
  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
huffman@30019
   432
    unfolding norm_prod_def
huffman@31587
   433
    apply (simp add: power_mult_distrib)
huffman@30019
   434
    apply (simp add: right_distrib [symmetric])
huffman@30019
   435
    apply (simp add: real_sqrt_mult_distrib)
huffman@30019
   436
    done
huffman@30019
   437
  show "sgn x = scaleR (inverse (norm x)) x"
huffman@30019
   438
    by (rule sgn_prod_def)
huffman@31290
   439
  show "dist x y = norm (x - y)"
huffman@31339
   440
    unfolding dist_prod_def norm_prod_def
huffman@31339
   441
    by (simp add: dist_norm)
huffman@30019
   442
qed
huffman@30019
   443
huffman@30019
   444
end
huffman@30019
   445
haftmann@37678
   446
instance prod :: (banach, banach) banach ..
huffman@31405
   447
huffman@30019
   448
subsection {* Product is an inner product space *}
huffman@30019
   449
haftmann@37678
   450
instantiation prod :: (real_inner, real_inner) real_inner
huffman@30019
   451
begin
huffman@30019
   452
huffman@30019
   453
definition inner_prod_def:
huffman@30019
   454
  "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
huffman@30019
   455
huffman@30019
   456
lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
huffman@30019
   457
  unfolding inner_prod_def by simp
huffman@30019
   458
huffman@30019
   459
instance proof
huffman@30019
   460
  fix r :: real
huffman@30019
   461
  fix x y z :: "'a::real_inner * 'b::real_inner"
huffman@30019
   462
  show "inner x y = inner y x"
huffman@30019
   463
    unfolding inner_prod_def
huffman@30019
   464
    by (simp add: inner_commute)
huffman@30019
   465
  show "inner (x + y) z = inner x z + inner y z"
huffman@30019
   466
    unfolding inner_prod_def
huffman@31590
   467
    by (simp add: inner_add_left)
huffman@30019
   468
  show "inner (scaleR r x) y = r * inner x y"
huffman@30019
   469
    unfolding inner_prod_def
huffman@31590
   470
    by (simp add: right_distrib)
huffman@30019
   471
  show "0 \<le> inner x x"
huffman@30019
   472
    unfolding inner_prod_def
huffman@30019
   473
    by (intro add_nonneg_nonneg inner_ge_zero)
huffman@30019
   474
  show "inner x x = 0 \<longleftrightarrow> x = 0"
huffman@44066
   475
    unfolding inner_prod_def prod_eq_iff
huffman@30019
   476
    by (simp add: add_nonneg_eq_0_iff)
huffman@30019
   477
  show "norm x = sqrt (inner x x)"
huffman@30019
   478
    unfolding norm_prod_def inner_prod_def
huffman@30019
   479
    by (simp add: power2_norm_eq_inner)
huffman@30019
   480
qed
huffman@30019
   481
huffman@30019
   482
end
huffman@30019
   483
huffman@31405
   484
subsection {* Pair operations are linear *}
huffman@30019
   485
wenzelm@30729
   486
interpretation fst: bounded_linear fst
huffman@44127
   487
  using fst_add fst_scaleR
huffman@44127
   488
  by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
huffman@30019
   489
wenzelm@30729
   490
interpretation snd: bounded_linear snd
huffman@44127
   491
  using snd_add snd_scaleR
huffman@44127
   492
  by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
huffman@30019
   493
huffman@30019
   494
text {* TODO: move to NthRoot *}
huffman@30019
   495
lemma sqrt_add_le_add_sqrt:
huffman@30019
   496
  assumes x: "0 \<le> x" and y: "0 \<le> y"
huffman@30019
   497
  shows "sqrt (x + y) \<le> sqrt x + sqrt y"
huffman@30019
   498
apply (rule power2_le_imp_le)
huffman@44126
   499
apply (simp add: real_sum_squared_expand x y)
huffman@30019
   500
apply (simp add: mult_nonneg_nonneg x y)
huffman@44126
   501
apply (simp add: x y)
huffman@30019
   502
done
huffman@30019
   503
huffman@30019
   504
lemma bounded_linear_Pair:
huffman@30019
   505
  assumes f: "bounded_linear f"
huffman@30019
   506
  assumes g: "bounded_linear g"
huffman@30019
   507
  shows "bounded_linear (\<lambda>x. (f x, g x))"
huffman@30019
   508
proof
huffman@30019
   509
  interpret f: bounded_linear f by fact
huffman@30019
   510
  interpret g: bounded_linear g by fact
huffman@30019
   511
  fix x y and r :: real
huffman@30019
   512
  show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
huffman@30019
   513
    by (simp add: f.add g.add)
huffman@30019
   514
  show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
huffman@30019
   515
    by (simp add: f.scaleR g.scaleR)
huffman@30019
   516
  obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
huffman@30019
   517
    using f.pos_bounded by fast
huffman@30019
   518
  obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
huffman@30019
   519
    using g.pos_bounded by fast
huffman@30019
   520
  have "\<forall>x. norm (f x, g x) \<le> norm x * (Kf + Kg)"
huffman@30019
   521
    apply (rule allI)
huffman@30019
   522
    apply (simp add: norm_Pair)
huffman@30019
   523
    apply (rule order_trans [OF sqrt_add_le_add_sqrt], simp, simp)
huffman@30019
   524
    apply (simp add: right_distrib)
huffman@30019
   525
    apply (rule add_mono [OF norm_f norm_g])
huffman@30019
   526
    done
huffman@30019
   527
  then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
huffman@30019
   528
qed
huffman@30019
   529
huffman@30019
   530
subsection {* Frechet derivatives involving pairs *}
huffman@30019
   531
huffman@30019
   532
lemma FDERIV_Pair:
huffman@30019
   533
  assumes f: "FDERIV f x :> f'" and g: "FDERIV g x :> g'"
huffman@30019
   534
  shows "FDERIV (\<lambda>x. (f x, g x)) x :> (\<lambda>h. (f' h, g' h))"
huffman@30019
   535
apply (rule FDERIV_I)
huffman@30019
   536
apply (rule bounded_linear_Pair)
huffman@30019
   537
apply (rule FDERIV_bounded_linear [OF f])
huffman@30019
   538
apply (rule FDERIV_bounded_linear [OF g])
huffman@30019
   539
apply (simp add: norm_Pair)
huffman@30019
   540
apply (rule real_LIM_sandwich_zero)
huffman@30019
   541
apply (rule LIM_add_zero)
huffman@30019
   542
apply (rule FDERIV_D [OF f])
huffman@30019
   543
apply (rule FDERIV_D [OF g])
huffman@30019
   544
apply (rename_tac h)
huffman@30019
   545
apply (simp add: divide_nonneg_pos)
huffman@30019
   546
apply (rename_tac h)
huffman@30019
   547
apply (subst add_divide_distrib [symmetric])
huffman@30019
   548
apply (rule divide_right_mono [OF _ norm_ge_zero])
huffman@30019
   549
apply (rule order_trans [OF sqrt_add_le_add_sqrt])
huffman@30019
   550
apply simp
huffman@30019
   551
apply simp
huffman@30019
   552
apply simp
huffman@30019
   553
done
huffman@30019
   554
huffman@30019
   555
end