src/HOL/Library/Product_Vector.thy
author huffman
Tue Jun 02 23:35:52 2009 -0700 (2009-06-02)
changeset 31405 1f72869f1a2e
parent 31388 e0c05b595d1f
child 31415 80686a815b59
permissions -rw-r--r--
instance * :: complete_space; generalize continuity lemmas for fst, snd, Pair
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
huffman@30019
    13
instantiation "*" :: (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@30019
    31
    by (simp add: expand_prod_eq scaleR_right_distrib)
huffman@30019
    32
  show "scaleR (a + b) x = scaleR a x + scaleR b x"
huffman@30019
    33
    by (simp add: expand_prod_eq scaleR_left_distrib)
huffman@30019
    34
  show "scaleR a (scaleR b x) = scaleR (a * b) x"
huffman@30019
    35
    by (simp add: expand_prod_eq)
huffman@30019
    36
  show "scaleR 1 x = x"
huffman@30019
    37
    by (simp add: expand_prod_eq)
huffman@30019
    38
qed
huffman@30019
    39
huffman@30019
    40
end
huffman@30019
    41
huffman@31339
    42
subsection {* Product is a metric space *}
huffman@31339
    43
huffman@31339
    44
instantiation
huffman@31339
    45
  "*" :: (metric_space, metric_space) metric_space
huffman@31339
    46
begin
huffman@31339
    47
huffman@31339
    48
definition dist_prod_def:
huffman@31339
    49
  "dist (x::'a \<times> 'b) y = sqrt ((dist (fst x) (fst y))\<twosuperior> + (dist (snd x) (snd y))\<twosuperior>)"
huffman@31339
    50
huffman@31339
    51
lemma dist_Pair_Pair: "dist (a, b) (c, d) = sqrt ((dist a c)\<twosuperior> + (dist b d)\<twosuperior>)"
huffman@31339
    52
  unfolding dist_prod_def by simp
huffman@31339
    53
huffman@31339
    54
instance proof
huffman@31339
    55
  fix x y :: "'a \<times> 'b"
huffman@31339
    56
  show "dist x y = 0 \<longleftrightarrow> x = y"
huffman@31339
    57
    unfolding dist_prod_def
huffman@31339
    58
    by (simp add: expand_prod_eq)
huffman@31339
    59
next
huffman@31339
    60
  fix x y z :: "'a \<times> 'b"
huffman@31339
    61
  show "dist x y \<le> dist x z + dist y z"
huffman@31339
    62
    unfolding dist_prod_def
huffman@31339
    63
    apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
huffman@31339
    64
    apply (rule real_sqrt_le_mono)
huffman@31339
    65
    apply (rule order_trans [OF add_mono])
huffman@31339
    66
    apply (rule power_mono [OF dist_triangle2 [of _ _ "fst z"] zero_le_dist])
huffman@31339
    67
    apply (rule power_mono [OF dist_triangle2 [of _ _ "snd z"] zero_le_dist])
huffman@31339
    68
    apply (simp only: real_sum_squared_expand)
huffman@31339
    69
    done
huffman@31339
    70
qed
huffman@31339
    71
huffman@31339
    72
end
huffman@31339
    73
huffman@31405
    74
subsection {* Continuity of operations *}
huffman@31405
    75
huffman@31405
    76
lemma dist_fst_le: "dist (fst x) (fst y) \<le> dist x y"
huffman@31405
    77
unfolding dist_prod_def by simp
huffman@31405
    78
huffman@31405
    79
lemma dist_snd_le: "dist (snd x) (snd y) \<le> dist x y"
huffman@31405
    80
unfolding dist_prod_def by simp
huffman@31405
    81
huffman@31405
    82
lemma tendsto_fst:
huffman@31405
    83
  assumes "tendsto f a net"
huffman@31405
    84
  shows "tendsto (\<lambda>x. fst (f x)) (fst a) net"
huffman@31405
    85
proof (rule tendstoI)
huffman@31405
    86
  fix r :: real assume "0 < r"
huffman@31405
    87
  have "eventually (\<lambda>x. dist (f x) a < r) net"
huffman@31405
    88
    using `tendsto f a net` `0 < r` by (rule tendstoD)
huffman@31405
    89
  thus "eventually (\<lambda>x. dist (fst (f x)) (fst a) < r) net"
huffman@31405
    90
    by (rule eventually_elim1)
huffman@31405
    91
       (rule le_less_trans [OF dist_fst_le])
huffman@31405
    92
qed
huffman@31405
    93
huffman@31405
    94
lemma tendsto_snd:
huffman@31405
    95
  assumes "tendsto f a net"
huffman@31405
    96
  shows "tendsto (\<lambda>x. snd (f x)) (snd a) net"
huffman@31405
    97
proof (rule tendstoI)
huffman@31405
    98
  fix r :: real assume "0 < r"
huffman@31405
    99
  have "eventually (\<lambda>x. dist (f x) a < r) net"
huffman@31405
   100
    using `tendsto f a net` `0 < r` by (rule tendstoD)
huffman@31405
   101
  thus "eventually (\<lambda>x. dist (snd (f x)) (snd a) < r) net"
huffman@31405
   102
    by (rule eventually_elim1)
huffman@31405
   103
       (rule le_less_trans [OF dist_snd_le])
huffman@31405
   104
qed
huffman@31405
   105
huffman@31405
   106
lemma tendsto_Pair:
huffman@31405
   107
  assumes "tendsto X a net" and "tendsto Y b net"
huffman@31405
   108
  shows "tendsto (\<lambda>i. (X i, Y i)) (a, b) net"
huffman@31405
   109
proof (rule tendstoI)
huffman@31405
   110
  fix r :: real assume "0 < r"
huffman@31405
   111
  then have "0 < r / sqrt 2" (is "0 < ?s")
huffman@31405
   112
    by (simp add: divide_pos_pos)
huffman@31405
   113
  have "eventually (\<lambda>i. dist (X i) a < ?s) net"
huffman@31405
   114
    using `tendsto X a net` `0 < ?s` by (rule tendstoD)
huffman@31405
   115
  moreover
huffman@31405
   116
  have "eventually (\<lambda>i. dist (Y i) b < ?s) net"
huffman@31405
   117
    using `tendsto Y b net` `0 < ?s` by (rule tendstoD)
huffman@31405
   118
  ultimately
huffman@31405
   119
  show "eventually (\<lambda>i. dist (X i, Y i) (a, b) < r) net"
huffman@31405
   120
    by (rule eventually_elim2)
huffman@31405
   121
       (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
huffman@31405
   122
qed
huffman@31405
   123
huffman@31405
   124
lemma LIMSEQ_fst: "(X ----> a) \<Longrightarrow> (\<lambda>n. fst (X n)) ----> fst a"
huffman@31405
   125
unfolding LIMSEQ_conv_tendsto by (rule tendsto_fst)
huffman@31405
   126
huffman@31405
   127
lemma LIMSEQ_snd: "(X ----> a) \<Longrightarrow> (\<lambda>n. snd (X n)) ----> snd a"
huffman@31405
   128
unfolding LIMSEQ_conv_tendsto by (rule tendsto_snd)
huffman@31405
   129
huffman@31405
   130
lemma LIMSEQ_Pair:
huffman@31405
   131
  assumes "X ----> a" and "Y ----> b"
huffman@31405
   132
  shows "(\<lambda>n. (X n, Y n)) ----> (a, b)"
huffman@31405
   133
using assms unfolding LIMSEQ_conv_tendsto
huffman@31405
   134
by (rule tendsto_Pair)
huffman@31405
   135
huffman@31405
   136
lemma LIM_fst: "f -- x --> a \<Longrightarrow> (\<lambda>x. fst (f x)) -- x --> fst a"
huffman@31405
   137
unfolding LIM_conv_tendsto by (rule tendsto_fst)
huffman@31405
   138
huffman@31405
   139
lemma LIM_snd: "f -- x --> a \<Longrightarrow> (\<lambda>x. snd (f x)) -- x --> snd a"
huffman@31405
   140
unfolding LIM_conv_tendsto by (rule tendsto_snd)
huffman@31405
   141
huffman@31405
   142
lemma LIM_Pair:
huffman@31405
   143
  assumes "f -- x --> a" and "g -- x --> b"
huffman@31405
   144
  shows "(\<lambda>x. (f x, g x)) -- x --> (a, b)"
huffman@31405
   145
using assms unfolding LIM_conv_tendsto
huffman@31405
   146
by (rule tendsto_Pair)
huffman@31405
   147
huffman@31405
   148
lemma Cauchy_fst: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. fst (X n))"
huffman@31405
   149
unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_fst_le])
huffman@31405
   150
huffman@31405
   151
lemma Cauchy_snd: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. snd (X n))"
huffman@31405
   152
unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_snd_le])
huffman@31405
   153
huffman@31405
   154
lemma Cauchy_Pair:
huffman@31405
   155
  assumes "Cauchy X" and "Cauchy Y"
huffman@31405
   156
  shows "Cauchy (\<lambda>n. (X n, Y n))"
huffman@31405
   157
proof (rule metric_CauchyI)
huffman@31405
   158
  fix r :: real assume "0 < r"
huffman@31405
   159
  then have "0 < r / sqrt 2" (is "0 < ?s")
huffman@31405
   160
    by (simp add: divide_pos_pos)
huffman@31405
   161
  obtain M where M: "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < ?s"
huffman@31405
   162
    using metric_CauchyD [OF `Cauchy X` `0 < ?s`] ..
huffman@31405
   163
  obtain N where N: "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (Y m) (Y n) < ?s"
huffman@31405
   164
    using metric_CauchyD [OF `Cauchy Y` `0 < ?s`] ..
huffman@31405
   165
  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
   166
    using M N by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
huffman@31405
   167
  then show "\<exists>n0. \<forall>m\<ge>n0. \<forall>n\<ge>n0. dist (X m, Y m) (X n, Y n) < r" ..
huffman@31405
   168
qed
huffman@31405
   169
huffman@31405
   170
lemma isCont_Pair [simp]:
huffman@31405
   171
  "\<lbrakk>isCont f x; isCont g x\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. (f x, g x)) x"
huffman@31405
   172
  unfolding isCont_def by (rule LIM_Pair)
huffman@31405
   173
huffman@31405
   174
subsection {* Product is a complete metric space *}
huffman@31405
   175
huffman@31405
   176
instance "*" :: (complete_space, complete_space) complete_space
huffman@31405
   177
proof
huffman@31405
   178
  fix X :: "nat \<Rightarrow> 'a \<times> 'b" assume "Cauchy X"
huffman@31405
   179
  have 1: "(\<lambda>n. fst (X n)) ----> lim (\<lambda>n. fst (X n))"
huffman@31405
   180
    using Cauchy_fst [OF `Cauchy X`]
huffman@31405
   181
    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
huffman@31405
   182
  have 2: "(\<lambda>n. snd (X n)) ----> lim (\<lambda>n. snd (X n))"
huffman@31405
   183
    using Cauchy_snd [OF `Cauchy X`]
huffman@31405
   184
    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
huffman@31405
   185
  have "X ----> (lim (\<lambda>n. fst (X n)), lim (\<lambda>n. snd (X n)))"
huffman@31405
   186
    using LIMSEQ_Pair [OF 1 2] by simp
huffman@31405
   187
  then show "convergent X"
huffman@31405
   188
    by (rule convergentI)
huffman@31405
   189
qed
huffman@31405
   190
huffman@30019
   191
subsection {* Product is a normed vector space *}
huffman@30019
   192
huffman@30019
   193
instantiation
huffman@30019
   194
  "*" :: (real_normed_vector, real_normed_vector) real_normed_vector
huffman@30019
   195
begin
huffman@30019
   196
huffman@30019
   197
definition norm_prod_def:
huffman@30019
   198
  "norm x = sqrt ((norm (fst x))\<twosuperior> + (norm (snd x))\<twosuperior>)"
huffman@30019
   199
huffman@30019
   200
definition sgn_prod_def:
huffman@30019
   201
  "sgn (x::'a \<times> 'b) = scaleR (inverse (norm x)) x"
huffman@30019
   202
huffman@30019
   203
lemma norm_Pair: "norm (a, b) = sqrt ((norm a)\<twosuperior> + (norm b)\<twosuperior>)"
huffman@30019
   204
  unfolding norm_prod_def by simp
huffman@30019
   205
huffman@30019
   206
instance proof
huffman@30019
   207
  fix r :: real and x y :: "'a \<times> 'b"
huffman@30019
   208
  show "0 \<le> norm x"
huffman@30019
   209
    unfolding norm_prod_def by simp
huffman@30019
   210
  show "norm x = 0 \<longleftrightarrow> x = 0"
huffman@30019
   211
    unfolding norm_prod_def
huffman@30019
   212
    by (simp add: expand_prod_eq)
huffman@30019
   213
  show "norm (x + y) \<le> norm x + norm y"
huffman@30019
   214
    unfolding norm_prod_def
huffman@30019
   215
    apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
huffman@30019
   216
    apply (simp add: add_mono power_mono norm_triangle_ineq)
huffman@30019
   217
    done
huffman@30019
   218
  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
huffman@30019
   219
    unfolding norm_prod_def
huffman@30019
   220
    apply (simp add: norm_scaleR power_mult_distrib)
huffman@30019
   221
    apply (simp add: right_distrib [symmetric])
huffman@30019
   222
    apply (simp add: real_sqrt_mult_distrib)
huffman@30019
   223
    done
huffman@30019
   224
  show "sgn x = scaleR (inverse (norm x)) x"
huffman@30019
   225
    by (rule sgn_prod_def)
huffman@31290
   226
  show "dist x y = norm (x - y)"
huffman@31339
   227
    unfolding dist_prod_def norm_prod_def
huffman@31339
   228
    by (simp add: dist_norm)
huffman@30019
   229
qed
huffman@30019
   230
huffman@30019
   231
end
huffman@30019
   232
huffman@31405
   233
instance "*" :: (banach, banach) banach ..
huffman@31405
   234
huffman@30019
   235
subsection {* Product is an inner product space *}
huffman@30019
   236
huffman@30019
   237
instantiation "*" :: (real_inner, real_inner) real_inner
huffman@30019
   238
begin
huffman@30019
   239
huffman@30019
   240
definition inner_prod_def:
huffman@30019
   241
  "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
huffman@30019
   242
huffman@30019
   243
lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
huffman@30019
   244
  unfolding inner_prod_def by simp
huffman@30019
   245
huffman@30019
   246
instance proof
huffman@30019
   247
  fix r :: real
huffman@30019
   248
  fix x y z :: "'a::real_inner * 'b::real_inner"
huffman@30019
   249
  show "inner x y = inner y x"
huffman@30019
   250
    unfolding inner_prod_def
huffman@30019
   251
    by (simp add: inner_commute)
huffman@30019
   252
  show "inner (x + y) z = inner x z + inner y z"
huffman@30019
   253
    unfolding inner_prod_def
huffman@30019
   254
    by (simp add: inner_left_distrib)
huffman@30019
   255
  show "inner (scaleR r x) y = r * inner x y"
huffman@30019
   256
    unfolding inner_prod_def
huffman@30019
   257
    by (simp add: inner_scaleR_left right_distrib)
huffman@30019
   258
  show "0 \<le> inner x x"
huffman@30019
   259
    unfolding inner_prod_def
huffman@30019
   260
    by (intro add_nonneg_nonneg inner_ge_zero)
huffman@30019
   261
  show "inner x x = 0 \<longleftrightarrow> x = 0"
huffman@30019
   262
    unfolding inner_prod_def expand_prod_eq
huffman@30019
   263
    by (simp add: add_nonneg_eq_0_iff)
huffman@30019
   264
  show "norm x = sqrt (inner x x)"
huffman@30019
   265
    unfolding norm_prod_def inner_prod_def
huffman@30019
   266
    by (simp add: power2_norm_eq_inner)
huffman@30019
   267
qed
huffman@30019
   268
huffman@30019
   269
end
huffman@30019
   270
huffman@31405
   271
subsection {* Pair operations are linear *}
huffman@30019
   272
wenzelm@30729
   273
interpretation fst: bounded_linear fst
huffman@30019
   274
  apply (unfold_locales)
huffman@30019
   275
  apply (rule fst_add)
huffman@30019
   276
  apply (rule fst_scaleR)
huffman@30019
   277
  apply (rule_tac x="1" in exI, simp add: norm_Pair)
huffman@30019
   278
  done
huffman@30019
   279
wenzelm@30729
   280
interpretation snd: bounded_linear snd
huffman@30019
   281
  apply (unfold_locales)
huffman@30019
   282
  apply (rule snd_add)
huffman@30019
   283
  apply (rule snd_scaleR)
huffman@30019
   284
  apply (rule_tac x="1" in exI, simp add: norm_Pair)
huffman@30019
   285
  done
huffman@30019
   286
huffman@30019
   287
text {* TODO: move to NthRoot *}
huffman@30019
   288
lemma sqrt_add_le_add_sqrt:
huffman@30019
   289
  assumes x: "0 \<le> x" and y: "0 \<le> y"
huffman@30019
   290
  shows "sqrt (x + y) \<le> sqrt x + sqrt y"
huffman@30019
   291
apply (rule power2_le_imp_le)
huffman@30019
   292
apply (simp add: real_sum_squared_expand add_nonneg_nonneg x y)
huffman@30019
   293
apply (simp add: mult_nonneg_nonneg x y)
huffman@30019
   294
apply (simp add: add_nonneg_nonneg x y)
huffman@30019
   295
done
huffman@30019
   296
huffman@30019
   297
lemma bounded_linear_Pair:
huffman@30019
   298
  assumes f: "bounded_linear f"
huffman@30019
   299
  assumes g: "bounded_linear g"
huffman@30019
   300
  shows "bounded_linear (\<lambda>x. (f x, g x))"
huffman@30019
   301
proof
huffman@30019
   302
  interpret f: bounded_linear f by fact
huffman@30019
   303
  interpret g: bounded_linear g by fact
huffman@30019
   304
  fix x y and r :: real
huffman@30019
   305
  show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
huffman@30019
   306
    by (simp add: f.add g.add)
huffman@30019
   307
  show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
huffman@30019
   308
    by (simp add: f.scaleR g.scaleR)
huffman@30019
   309
  obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
huffman@30019
   310
    using f.pos_bounded by fast
huffman@30019
   311
  obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
huffman@30019
   312
    using g.pos_bounded by fast
huffman@30019
   313
  have "\<forall>x. norm (f x, g x) \<le> norm x * (Kf + Kg)"
huffman@30019
   314
    apply (rule allI)
huffman@30019
   315
    apply (simp add: norm_Pair)
huffman@30019
   316
    apply (rule order_trans [OF sqrt_add_le_add_sqrt], simp, simp)
huffman@30019
   317
    apply (simp add: right_distrib)
huffman@30019
   318
    apply (rule add_mono [OF norm_f norm_g])
huffman@30019
   319
    done
huffman@30019
   320
  then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
huffman@30019
   321
qed
huffman@30019
   322
huffman@30019
   323
subsection {* Frechet derivatives involving pairs *}
huffman@30019
   324
huffman@30019
   325
lemma FDERIV_Pair:
huffman@30019
   326
  assumes f: "FDERIV f x :> f'" and g: "FDERIV g x :> g'"
huffman@30019
   327
  shows "FDERIV (\<lambda>x. (f x, g x)) x :> (\<lambda>h. (f' h, g' h))"
huffman@30019
   328
apply (rule FDERIV_I)
huffman@30019
   329
apply (rule bounded_linear_Pair)
huffman@30019
   330
apply (rule FDERIV_bounded_linear [OF f])
huffman@30019
   331
apply (rule FDERIV_bounded_linear [OF g])
huffman@30019
   332
apply (simp add: norm_Pair)
huffman@30019
   333
apply (rule real_LIM_sandwich_zero)
huffman@30019
   334
apply (rule LIM_add_zero)
huffman@30019
   335
apply (rule FDERIV_D [OF f])
huffman@30019
   336
apply (rule FDERIV_D [OF g])
huffman@30019
   337
apply (rename_tac h)
huffman@30019
   338
apply (simp add: divide_nonneg_pos)
huffman@30019
   339
apply (rename_tac h)
huffman@30019
   340
apply (subst add_divide_distrib [symmetric])
huffman@30019
   341
apply (rule divide_right_mono [OF _ norm_ge_zero])
huffman@30019
   342
apply (rule order_trans [OF sqrt_add_le_add_sqrt])
huffman@30019
   343
apply simp
huffman@30019
   344
apply simp
huffman@30019
   345
apply simp
huffman@30019
   346
done
huffman@30019
   347
huffman@30019
   348
end