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