src/HOL/Analysis/Product_Vector.thy
author immler
Tue Jul 10 09:38:35 2018 +0200 (15 months ago)
changeset 68607 67bb59e49834
parent 68072 493b818e8e10
child 68611 4bc4b5c0ccfc
permissions -rw-r--r--
make theorem, corollary, and proposition %important for HOL-Analysis manual
hoelzl@63971
     1
(*  Title:      HOL/Analysis/Product_Vector.thy
huffman@30019
     2
    Author:     Brian Huffman
huffman@30019
     3
*)
huffman@30019
     4
wenzelm@60500
     5
section \<open>Cartesian Products as Vector Spaces\<close>
huffman@30019
     6
huffman@30019
     7
theory Product_Vector
hoelzl@63971
     8
imports
hoelzl@63971
     9
  Inner_Product
wenzelm@66453
    10
  "HOL-Library.Product_Plus"
huffman@30019
    11
begin
huffman@30019
    12
immler@68072
    13
lemma Times_eq_image_sum:
immler@68072
    14
  fixes S :: "'a :: comm_monoid_add set" and T :: "'b :: comm_monoid_add set"
immler@68072
    15
  shows "S \<times> T = {u + v |u v. u \<in> (\<lambda>x. (x, 0)) ` S \<and> v \<in> Pair 0 ` T}"
immler@68072
    16
  by force
immler@68072
    17
immler@68072
    18
immler@68072
    19
subsection \<open>Product is a module\<close>
immler@68072
    20
immler@68072
    21
locale module_prod = module_pair begin
immler@68072
    22
immler@68072
    23
definition scale :: "'a \<Rightarrow> 'b \<times> 'c \<Rightarrow> 'b \<times> 'c"
immler@68072
    24
  where "scale a v = (s1 a (fst v), s2 a (snd v))"
immler@68072
    25
immler@68072
    26
lemma scale_prod: "scale x (a, b) = (s1 x a, s2 x b)"
immler@68072
    27
  by (auto simp: scale_def)
immler@68072
    28
immler@68072
    29
sublocale p: module scale
immler@68072
    30
proof qed (simp_all add: scale_def
immler@68072
    31
  m1.scale_left_distrib m1.scale_right_distrib m2.scale_left_distrib m2.scale_right_distrib)
immler@68072
    32
immler@68072
    33
lemma subspace_Times: "m1.subspace A \<Longrightarrow> m2.subspace B \<Longrightarrow> p.subspace (A \<times> B)"
immler@68072
    34
  unfolding m1.subspace_def m2.subspace_def p.subspace_def
immler@68072
    35
  by (auto simp: zero_prod_def scale_def)
immler@68072
    36
immler@68072
    37
lemma module_hom_fst: "module_hom scale s1 fst"
immler@68072
    38
  by unfold_locales (auto simp: scale_def)
immler@68072
    39
immler@68072
    40
lemma module_hom_snd: "module_hom scale s2 snd"
immler@68072
    41
  by unfold_locales (auto simp: scale_def)
immler@68072
    42
immler@68072
    43
end
immler@68072
    44
immler@68072
    45
locale vector_space_prod = vector_space_pair begin
immler@68072
    46
immler@68072
    47
sublocale module_prod s1 s2
immler@68072
    48
  rewrites "module_hom = Vector_Spaces.linear"
immler@68072
    49
  by unfold_locales (fact module_hom_eq_linear)
immler@68072
    50
immler@68072
    51
sublocale p: vector_space scale by unfold_locales (auto simp: algebra_simps)
immler@68072
    52
immler@68072
    53
lemmas linear_fst = module_hom_fst
immler@68072
    54
  and linear_snd = module_hom_snd
immler@68072
    55
immler@68072
    56
end
immler@68072
    57
immler@68072
    58
wenzelm@60500
    59
subsection \<open>Product is a real vector space\<close>
huffman@30019
    60
immler@67962
    61
instantiation%important prod :: (real_vector, real_vector) real_vector
huffman@30019
    62
begin
huffman@30019
    63
huffman@30019
    64
definition scaleR_prod_def:
huffman@30019
    65
  "scaleR r A = (scaleR r (fst A), scaleR r (snd A))"
huffman@30019
    66
huffman@30019
    67
lemma fst_scaleR [simp]: "fst (scaleR r A) = scaleR r (fst A)"
huffman@30019
    68
  unfolding scaleR_prod_def by simp
huffman@30019
    69
huffman@30019
    70
lemma snd_scaleR [simp]: "snd (scaleR r A) = scaleR r (snd A)"
huffman@30019
    71
  unfolding scaleR_prod_def by simp
huffman@30019
    72
huffman@30019
    73
lemma scaleR_Pair [simp]: "scaleR r (a, b) = (scaleR r a, scaleR r b)"
huffman@30019
    74
  unfolding scaleR_prod_def by simp
huffman@30019
    75
wenzelm@60679
    76
instance
wenzelm@60679
    77
proof
huffman@30019
    78
  fix a b :: real and x y :: "'a \<times> 'b"
huffman@30019
    79
  show "scaleR a (x + y) = scaleR a x + scaleR a y"
huffman@44066
    80
    by (simp add: prod_eq_iff scaleR_right_distrib)
huffman@30019
    81
  show "scaleR (a + b) x = scaleR a x + scaleR b x"
huffman@44066
    82
    by (simp add: prod_eq_iff scaleR_left_distrib)
huffman@30019
    83
  show "scaleR a (scaleR b x) = scaleR (a * b) x"
huffman@44066
    84
    by (simp add: prod_eq_iff)
huffman@30019
    85
  show "scaleR 1 x = x"
huffman@44066
    86
    by (simp add: prod_eq_iff)
huffman@30019
    87
qed
huffman@30019
    88
huffman@30019
    89
end
huffman@30019
    90
immler@68072
    91
lemma module_prod_scale_eq_scaleR: "module_prod.scale ( *\<^sub>R) ( *\<^sub>R) = scaleR"
immler@68072
    92
  apply (rule ext) apply (rule ext)
immler@68072
    93
  apply (subst module_prod.scale_def)
immler@68072
    94
  subgoal by unfold_locales
immler@68072
    95
  by (simp add: scaleR_prod_def)
immler@68072
    96
immler@68072
    97
interpretation real_vector?: vector_space_prod "scaleR::_\<Rightarrow>_\<Rightarrow>'a::real_vector" "scaleR::_\<Rightarrow>_\<Rightarrow>'b::real_vector"
immler@68072
    98
  rewrites "scale = (( *\<^sub>R)::_\<Rightarrow>_\<Rightarrow>('a \<times> 'b))"
immler@68072
    99
    and "module.dependent ( *\<^sub>R) = dependent"
immler@68072
   100
    and "module.representation ( *\<^sub>R) = representation"
immler@68072
   101
    and "module.subspace ( *\<^sub>R) = subspace"
immler@68072
   102
    and "module.span ( *\<^sub>R) = span"
immler@68072
   103
    and "vector_space.extend_basis ( *\<^sub>R) = extend_basis"
immler@68072
   104
    and "vector_space.dim ( *\<^sub>R) = dim"
immler@68072
   105
    and "Vector_Spaces.linear ( *\<^sub>R) ( *\<^sub>R) = linear"
immler@68072
   106
  subgoal by unfold_locales
immler@68072
   107
  subgoal by (fact module_prod_scale_eq_scaleR)
immler@68072
   108
  unfolding dependent_raw_def representation_raw_def subspace_raw_def span_raw_def
immler@68072
   109
    extend_basis_raw_def dim_raw_def linear_def
immler@68072
   110
  by (rule refl)+
immler@68072
   111
wenzelm@60500
   112
subsection \<open>Product is a metric space\<close>
huffman@31339
   113
hoelzl@62101
   114
(* TODO: Product of uniform spaces and compatibility with metric_spaces! *)
hoelzl@62101
   115
immler@67962
   116
instantiation%important prod :: (metric_space, metric_space) dist
huffman@31339
   117
begin
huffman@31339
   118
immler@67962
   119
definition%important dist_prod_def[code del]:
wenzelm@53015
   120
  "dist x y = sqrt ((dist (fst x) (fst y))\<^sup>2 + (dist (snd x) (snd y))\<^sup>2)"
huffman@31339
   121
hoelzl@62101
   122
instance ..
hoelzl@62101
   123
end
hoelzl@62101
   124
hoelzl@62101
   125
instantiation prod :: (metric_space, metric_space) uniformity_dist
hoelzl@62101
   126
begin
hoelzl@62101
   127
hoelzl@62101
   128
definition [code del]:
hoelzl@62102
   129
  "(uniformity :: (('a \<times> 'b) \<times> ('a \<times> 'b)) filter) =
hoelzl@62101
   130
    (INF e:{0 <..}. principal {(x, y). dist x y < e})"
hoelzl@62101
   131
hoelzl@62102
   132
instance
hoelzl@62101
   133
  by standard (rule uniformity_prod_def)
hoelzl@62101
   134
end
hoelzl@62101
   135
hoelzl@62102
   136
declare uniformity_Abort[where 'a="'a :: metric_space \<times> 'b :: metric_space", code]
hoelzl@62102
   137
immler@67962
   138
instantiation%important prod :: (metric_space, metric_space) metric_space
hoelzl@62101
   139
begin
hoelzl@62101
   140
wenzelm@53015
   141
lemma dist_Pair_Pair: "dist (a, b) (c, d) = sqrt ((dist a c)\<^sup>2 + (dist b d)\<^sup>2)"
huffman@31339
   142
  unfolding dist_prod_def by simp
huffman@31339
   143
huffman@36332
   144
lemma dist_fst_le: "dist (fst x) (fst y) \<le> dist x y"
huffman@53930
   145
  unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge1)
huffman@36332
   146
huffman@36332
   147
lemma dist_snd_le: "dist (snd x) (snd y) \<le> dist x y"
huffman@53930
   148
  unfolding dist_prod_def by (rule real_sqrt_sum_squares_ge2)
huffman@36332
   149
wenzelm@60679
   150
instance
wenzelm@60679
   151
proof
huffman@31339
   152
  fix x y :: "'a \<times> 'b"
huffman@31339
   153
  show "dist x y = 0 \<longleftrightarrow> x = y"
huffman@44066
   154
    unfolding dist_prod_def prod_eq_iff by simp
huffman@31339
   155
next
huffman@31339
   156
  fix x y z :: "'a \<times> 'b"
huffman@31339
   157
  show "dist x y \<le> dist x z + dist y z"
huffman@31339
   158
    unfolding dist_prod_def
huffman@31563
   159
    by (intro order_trans [OF _ real_sqrt_sum_squares_triangle_ineq]
huffman@31563
   160
        real_sqrt_le_mono add_mono power_mono dist_triangle2 zero_le_dist)
huffman@31415
   161
next
huffman@31492
   162
  fix S :: "('a \<times> 'b) set"
hoelzl@62101
   163
  have *: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
huffman@31563
   164
  proof
huffman@36332
   165
    assume "open S" show "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S"
huffman@36332
   166
    proof
huffman@36332
   167
      fix x assume "x \<in> S"
huffman@36332
   168
      obtain A B where "open A" "open B" "x \<in> A \<times> B" "A \<times> B \<subseteq> S"
wenzelm@60500
   169
        using \<open>open S\<close> and \<open>x \<in> S\<close> by (rule open_prod_elim)
huffman@36332
   170
      obtain r where r: "0 < r" "\<forall>y. dist y (fst x) < r \<longrightarrow> y \<in> A"
wenzelm@60500
   171
        using \<open>open A\<close> and \<open>x \<in> A \<times> B\<close> unfolding open_dist by auto
huffman@36332
   172
      obtain s where s: "0 < s" "\<forall>y. dist y (snd x) < s \<longrightarrow> y \<in> B"
wenzelm@60500
   173
        using \<open>open B\<close> and \<open>x \<in> A \<times> B\<close> unfolding open_dist by auto
huffman@36332
   174
      let ?e = "min r s"
huffman@36332
   175
      have "0 < ?e \<and> (\<forall>y. dist y x < ?e \<longrightarrow> y \<in> S)"
huffman@36332
   176
      proof (intro allI impI conjI)
huffman@36332
   177
        show "0 < min r s" by (simp add: r(1) s(1))
huffman@36332
   178
      next
huffman@36332
   179
        fix y assume "dist y x < min r s"
huffman@36332
   180
        hence "dist y x < r" and "dist y x < s"
huffman@36332
   181
          by simp_all
huffman@36332
   182
        hence "dist (fst y) (fst x) < r" and "dist (snd y) (snd x) < s"
huffman@36332
   183
          by (auto intro: le_less_trans dist_fst_le dist_snd_le)
huffman@36332
   184
        hence "fst y \<in> A" and "snd y \<in> B"
huffman@36332
   185
          by (simp_all add: r(2) s(2))
huffman@36332
   186
        hence "y \<in> A \<times> B" by (induct y, simp)
wenzelm@60500
   187
        with \<open>A \<times> B \<subseteq> S\<close> show "y \<in> S" ..
huffman@36332
   188
      qed
huffman@36332
   189
      thus "\<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" ..
huffman@36332
   190
    qed
huffman@31563
   191
  next
huffman@44575
   192
    assume *: "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" show "open S"
huffman@44575
   193
    proof (rule open_prod_intro)
huffman@44575
   194
      fix x assume "x \<in> S"
huffman@44575
   195
      then obtain e where "0 < e" and S: "\<forall>y. dist y x < e \<longrightarrow> y \<in> S"
huffman@44575
   196
        using * by fast
wenzelm@63040
   197
      define r where "r = e / sqrt 2"
wenzelm@63040
   198
      define s where "s = e / sqrt 2"
wenzelm@60500
   199
      from \<open>0 < e\<close> have "0 < r" and "0 < s"
nipkow@56541
   200
        unfolding r_def s_def by simp_all
wenzelm@60500
   201
      from \<open>0 < e\<close> have "e = sqrt (r\<^sup>2 + s\<^sup>2)"
huffman@44575
   202
        unfolding r_def s_def by (simp add: power_divide)
wenzelm@63040
   203
      define A where "A = {y. dist (fst x) y < r}"
wenzelm@63040
   204
      define B where "B = {y. dist (snd x) y < s}"
huffman@44575
   205
      have "open A" and "open B"
huffman@44575
   206
        unfolding A_def B_def by (simp_all add: open_ball)
huffman@44575
   207
      moreover have "x \<in> A \<times> B"
huffman@44575
   208
        unfolding A_def B_def mem_Times_iff
wenzelm@60500
   209
        using \<open>0 < r\<close> and \<open>0 < s\<close> by simp
huffman@44575
   210
      moreover have "A \<times> B \<subseteq> S"
huffman@44575
   211
      proof (clarify)
huffman@44575
   212
        fix a b assume "a \<in> A" and "b \<in> B"
huffman@44575
   213
        hence "dist a (fst x) < r" and "dist b (snd x) < s"
huffman@44575
   214
          unfolding A_def B_def by (simp_all add: dist_commute)
huffman@44575
   215
        hence "dist (a, b) x < e"
wenzelm@60500
   216
          unfolding dist_prod_def \<open>e = sqrt (r\<^sup>2 + s\<^sup>2)\<close>
huffman@44575
   217
          by (simp add: add_strict_mono power_strict_mono)
huffman@44575
   218
        thus "(a, b) \<in> S"
huffman@44575
   219
          by (simp add: S)
huffman@44575
   220
      qed
huffman@44575
   221
      ultimately show "\<exists>A B. open A \<and> open B \<and> x \<in> A \<times> B \<and> A \<times> B \<subseteq> S" by fast
huffman@44575
   222
    qed
huffman@31563
   223
  qed
hoelzl@62101
   224
  show "open S = (\<forall>x\<in>S. \<forall>\<^sub>F (x', y) in uniformity. x' = x \<longrightarrow> y \<in> S)"
hoelzl@62101
   225
    unfolding * eventually_uniformity_metric
hoelzl@62101
   226
    by (simp del: split_paired_All add: dist_prod_def dist_commute)
huffman@31339
   227
qed
huffman@31339
   228
huffman@31339
   229
end
huffman@31339
   230
haftmann@54890
   231
declare [[code abort: "dist::('a::metric_space*'b::metric_space)\<Rightarrow>('a*'b) \<Rightarrow> real"]]
immler@54779
   232
huffman@31405
   233
lemma Cauchy_fst: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. fst (X n))"
huffman@53930
   234
  unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_fst_le])
huffman@31405
   235
huffman@31405
   236
lemma Cauchy_snd: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. snd (X n))"
huffman@53930
   237
  unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_snd_le])
huffman@31405
   238
huffman@31405
   239
lemma Cauchy_Pair:
huffman@31405
   240
  assumes "Cauchy X" and "Cauchy Y"
huffman@31405
   241
  shows "Cauchy (\<lambda>n. (X n, Y n))"
huffman@31405
   242
proof (rule metric_CauchyI)
huffman@31405
   243
  fix r :: real assume "0 < r"
nipkow@56541
   244
  hence "0 < r / sqrt 2" (is "0 < ?s") by simp
huffman@31405
   245
  obtain M where M: "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < ?s"
wenzelm@60500
   246
    using metric_CauchyD [OF \<open>Cauchy X\<close> \<open>0 < ?s\<close>] ..
huffman@31405
   247
  obtain N where N: "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (Y m) (Y n) < ?s"
wenzelm@60500
   248
    using metric_CauchyD [OF \<open>Cauchy Y\<close> \<open>0 < ?s\<close>] ..
huffman@31405
   249
  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
   250
    using M N by (simp add: real_sqrt_sum_squares_less dist_Pair_Pair)
huffman@31405
   251
  then show "\<exists>n0. \<forall>m\<ge>n0. \<forall>n\<ge>n0. dist (X m, Y m) (X n, Y n) < r" ..
huffman@31405
   252
qed
huffman@31405
   253
wenzelm@60500
   254
subsection \<open>Product is a complete metric space\<close>
huffman@31405
   255
immler@67962
   256
instance%important prod :: (complete_space, complete_space) complete_space
immler@67962
   257
proof%unimportant
huffman@31405
   258
  fix X :: "nat \<Rightarrow> 'a \<times> 'b" assume "Cauchy X"
wenzelm@61969
   259
  have 1: "(\<lambda>n. fst (X n)) \<longlonglongrightarrow> lim (\<lambda>n. fst (X n))"
wenzelm@60500
   260
    using Cauchy_fst [OF \<open>Cauchy X\<close>]
huffman@31405
   261
    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
wenzelm@61969
   262
  have 2: "(\<lambda>n. snd (X n)) \<longlonglongrightarrow> lim (\<lambda>n. snd (X n))"
wenzelm@60500
   263
    using Cauchy_snd [OF \<open>Cauchy X\<close>]
huffman@31405
   264
    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
wenzelm@61969
   265
  have "X \<longlonglongrightarrow> (lim (\<lambda>n. fst (X n)), lim (\<lambda>n. snd (X n)))"
huffman@36660
   266
    using tendsto_Pair [OF 1 2] by simp
huffman@31405
   267
  then show "convergent X"
huffman@31405
   268
    by (rule convergentI)
huffman@31405
   269
qed
huffman@31405
   270
wenzelm@60500
   271
subsection \<open>Product is a normed vector space\<close>
huffman@30019
   272
immler@67962
   273
instantiation%important prod :: (real_normed_vector, real_normed_vector) real_normed_vector
huffman@30019
   274
begin
huffman@30019
   275
immler@54779
   276
definition norm_prod_def[code del]:
wenzelm@53015
   277
  "norm x = sqrt ((norm (fst x))\<^sup>2 + (norm (snd x))\<^sup>2)"
huffman@30019
   278
huffman@30019
   279
definition sgn_prod_def:
huffman@30019
   280
  "sgn (x::'a \<times> 'b) = scaleR (inverse (norm x)) x"
huffman@30019
   281
wenzelm@53015
   282
lemma norm_Pair: "norm (a, b) = sqrt ((norm a)\<^sup>2 + (norm b)\<^sup>2)"
huffman@30019
   283
  unfolding norm_prod_def by simp
huffman@30019
   284
wenzelm@60679
   285
instance
wenzelm@60679
   286
proof
huffman@30019
   287
  fix r :: real and x y :: "'a \<times> 'b"
huffman@30019
   288
  show "norm x = 0 \<longleftrightarrow> x = 0"
huffman@30019
   289
    unfolding norm_prod_def
huffman@44066
   290
    by (simp add: prod_eq_iff)
huffman@30019
   291
  show "norm (x + y) \<le> norm x + norm y"
huffman@30019
   292
    unfolding norm_prod_def
huffman@30019
   293
    apply (rule order_trans [OF _ real_sqrt_sum_squares_triangle_ineq])
huffman@30019
   294
    apply (simp add: add_mono power_mono norm_triangle_ineq)
huffman@30019
   295
    done
huffman@30019
   296
  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
huffman@30019
   297
    unfolding norm_prod_def
huffman@31587
   298
    apply (simp add: power_mult_distrib)
webertj@49962
   299
    apply (simp add: distrib_left [symmetric])
huffman@30019
   300
    apply (simp add: real_sqrt_mult_distrib)
huffman@30019
   301
    done
huffman@30019
   302
  show "sgn x = scaleR (inverse (norm x)) x"
huffman@30019
   303
    by (rule sgn_prod_def)
huffman@31290
   304
  show "dist x y = norm (x - y)"
huffman@31339
   305
    unfolding dist_prod_def norm_prod_def
huffman@31339
   306
    by (simp add: dist_norm)
huffman@30019
   307
qed
huffman@30019
   308
huffman@30019
   309
end
huffman@30019
   310
haftmann@54890
   311
declare [[code abort: "norm::('a::real_normed_vector*'b::real_normed_vector) \<Rightarrow> real"]]
immler@54779
   312
haftmann@37678
   313
instance prod :: (banach, banach) banach ..
huffman@31405
   314
immler@67962
   315
subsubsection%unimportant \<open>Pair operations are linear\<close>
huffman@30019
   316
immler@68607
   317
proposition bounded_linear_fst: "bounded_linear fst"
huffman@44127
   318
  using fst_add fst_scaleR
huffman@44127
   319
  by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
huffman@30019
   320
immler@68607
   321
proposition bounded_linear_snd: "bounded_linear snd"
huffman@44127
   322
  using snd_add snd_scaleR
huffman@44127
   323
  by (rule bounded_linear_intro [where K=1], simp add: norm_prod_def)
huffman@30019
   324
immler@61915
   325
lemmas bounded_linear_fst_comp = bounded_linear_fst[THEN bounded_linear_compose]
immler@61915
   326
immler@61915
   327
lemmas bounded_linear_snd_comp = bounded_linear_snd[THEN bounded_linear_compose]
immler@61915
   328
huffman@30019
   329
lemma bounded_linear_Pair:
huffman@30019
   330
  assumes f: "bounded_linear f"
huffman@30019
   331
  assumes g: "bounded_linear g"
huffman@30019
   332
  shows "bounded_linear (\<lambda>x. (f x, g x))"
huffman@30019
   333
proof
huffman@30019
   334
  interpret f: bounded_linear f by fact
huffman@30019
   335
  interpret g: bounded_linear g by fact
huffman@30019
   336
  fix x y and r :: real
huffman@30019
   337
  show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
huffman@30019
   338
    by (simp add: f.add g.add)
huffman@30019
   339
  show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
immler@68072
   340
    by (simp add: f.scale g.scale)
huffman@30019
   341
  obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
huffman@30019
   342
    using f.pos_bounded by fast
huffman@30019
   343
  obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
huffman@30019
   344
    using g.pos_bounded by fast
huffman@30019
   345
  have "\<forall>x. norm (f x, g x) \<le> norm x * (Kf + Kg)"
huffman@30019
   346
    apply (rule allI)
huffman@30019
   347
    apply (simp add: norm_Pair)
huffman@30019
   348
    apply (rule order_trans [OF sqrt_add_le_add_sqrt], simp, simp)
webertj@49962
   349
    apply (simp add: distrib_left)
huffman@30019
   350
    apply (rule add_mono [OF norm_f norm_g])
huffman@30019
   351
    done
huffman@30019
   352
  then show "\<exists>K. \<forall>x. norm (f x, g x) \<le> norm x * K" ..
huffman@30019
   353
qed
huffman@30019
   354
immler@67962
   355
subsubsection%unimportant \<open>Frechet derivatives involving pairs\<close>
huffman@30019
   356
immler@68607
   357
proposition has_derivative_Pair [derivative_intros]:
hoelzl@56181
   358
  assumes f: "(f has_derivative f') (at x within s)" and g: "(g has_derivative g') (at x within s)"
hoelzl@56181
   359
  shows "((\<lambda>x. (f x, g x)) has_derivative (\<lambda>h. (f' h, g' h))) (at x within s)"
immler@68607
   360
proof (rule has_derivativeI_sandwich[of 1])
huffman@44575
   361
  show "bounded_linear (\<lambda>h. (f' h, g' h))"
hoelzl@56181
   362
    using f g by (intro bounded_linear_Pair has_derivative_bounded_linear)
hoelzl@51642
   363
  let ?Rf = "\<lambda>y. f y - f x - f' (y - x)"
hoelzl@51642
   364
  let ?Rg = "\<lambda>y. g y - g x - g' (y - x)"
hoelzl@51642
   365
  let ?R = "\<lambda>y. ((f y, g y) - (f x, g x) - (f' (y - x), g' (y - x)))"
hoelzl@51642
   366
wenzelm@61973
   367
  show "((\<lambda>y. norm (?Rf y) / norm (y - x) + norm (?Rg y) / norm (y - x)) \<longlongrightarrow> 0) (at x within s)"
hoelzl@56181
   368
    using f g by (intro tendsto_add_zero) (auto simp: has_derivative_iff_norm)
hoelzl@51642
   369
hoelzl@51642
   370
  fix y :: 'a assume "y \<noteq> x"
hoelzl@51642
   371
  show "norm (?R y) / norm (y - x) \<le> norm (?Rf y) / norm (y - x) + norm (?Rg y) / norm (y - x)"
hoelzl@51642
   372
    unfolding add_divide_distrib [symmetric]
hoelzl@51642
   373
    by (simp add: norm_Pair divide_right_mono order_trans [OF sqrt_add_le_add_sqrt])
hoelzl@51642
   374
qed simp
hoelzl@51642
   375
immler@67685
   376
lemma differentiable_Pair [simp, derivative_intros]:
immler@67685
   377
  "f differentiable at x within s \<Longrightarrow> g differentiable at x within s \<Longrightarrow>
immler@67685
   378
    (\<lambda>x. (f x, g x)) differentiable at x within s"
immler@67685
   379
  unfolding differentiable_def by (blast intro: has_derivative_Pair)
immler@67685
   380
hoelzl@56381
   381
lemmas has_derivative_fst [derivative_intros] = bounded_linear.has_derivative [OF bounded_linear_fst]
hoelzl@56381
   382
lemmas has_derivative_snd [derivative_intros] = bounded_linear.has_derivative [OF bounded_linear_snd]
hoelzl@51642
   383
hoelzl@56381
   384
lemma has_derivative_split [derivative_intros]:
hoelzl@51642
   385
  "((\<lambda>p. f (fst p) (snd p)) has_derivative f') F \<Longrightarrow> ((\<lambda>(a, b). f a b) has_derivative f') F"
hoelzl@51642
   386
  unfolding split_beta' .
huffman@44575
   387
immler@67685
   388
immler@67962
   389
subsubsection%unimportant \<open>Vector derivatives involving pairs\<close>
immler@67685
   390
immler@67685
   391
lemma has_vector_derivative_Pair[derivative_intros]:
immler@67685
   392
  assumes "(f has_vector_derivative f') (at x within s)"
immler@67685
   393
    "(g has_vector_derivative g') (at x within s)"
immler@67685
   394
  shows "((\<lambda>x. (f x, g x)) has_vector_derivative (f', g')) (at x within s)"
immler@67685
   395
  using assms
immler@67685
   396
  by (auto simp: has_vector_derivative_def intro!: derivative_eq_intros)
immler@67685
   397
immler@67685
   398
wenzelm@60500
   399
subsection \<open>Product is an inner product space\<close>
huffman@44575
   400
immler@67962
   401
instantiation%important prod :: (real_inner, real_inner) real_inner
huffman@44575
   402
begin
huffman@44575
   403
huffman@44575
   404
definition inner_prod_def:
huffman@44575
   405
  "inner x y = inner (fst x) (fst y) + inner (snd x) (snd y)"
huffman@44575
   406
huffman@44575
   407
lemma inner_Pair [simp]: "inner (a, b) (c, d) = inner a c + inner b d"
huffman@44575
   408
  unfolding inner_prod_def by simp
huffman@44575
   409
wenzelm@60679
   410
instance
wenzelm@60679
   411
proof
huffman@44575
   412
  fix r :: real
huffman@44575
   413
  fix x y z :: "'a::real_inner \<times> 'b::real_inner"
huffman@44575
   414
  show "inner x y = inner y x"
huffman@44575
   415
    unfolding inner_prod_def
huffman@44575
   416
    by (simp add: inner_commute)
huffman@44575
   417
  show "inner (x + y) z = inner x z + inner y z"
huffman@44575
   418
    unfolding inner_prod_def
huffman@44575
   419
    by (simp add: inner_add_left)
huffman@44575
   420
  show "inner (scaleR r x) y = r * inner x y"
huffman@44575
   421
    unfolding inner_prod_def
webertj@49962
   422
    by (simp add: distrib_left)
huffman@44575
   423
  show "0 \<le> inner x x"
huffman@44575
   424
    unfolding inner_prod_def
huffman@44575
   425
    by (intro add_nonneg_nonneg inner_ge_zero)
huffman@44575
   426
  show "inner x x = 0 \<longleftrightarrow> x = 0"
huffman@44575
   427
    unfolding inner_prod_def prod_eq_iff
huffman@44575
   428
    by (simp add: add_nonneg_eq_0_iff)
huffman@44575
   429
  show "norm x = sqrt (inner x x)"
huffman@44575
   430
    unfolding norm_prod_def inner_prod_def
huffman@44575
   431
    by (simp add: power2_norm_eq_inner)
huffman@44575
   432
qed
huffman@30019
   433
huffman@30019
   434
end
huffman@44575
   435
hoelzl@59425
   436
lemma inner_Pair_0: "inner x (0, b) = inner (snd x) b" "inner x (a, 0) = inner (fst x) a"
hoelzl@59425
   437
    by (cases x, simp)+
hoelzl@59425
   438
hoelzl@62102
   439
lemma
lp15@60615
   440
  fixes x :: "'a::real_normed_vector"
hoelzl@62102
   441
  shows norm_Pair1 [simp]: "norm (0,x) = norm x"
lp15@60615
   442
    and norm_Pair2 [simp]: "norm (x,0) = norm x"
lp15@60615
   443
by (auto simp: norm_Pair)
lp15@60615
   444
paulson@62131
   445
lemma norm_commute: "norm (x,y) = norm (y,x)"
paulson@62131
   446
  by (simp add: norm_Pair)
paulson@62131
   447
paulson@62131
   448
lemma norm_fst_le: "norm x \<le> norm (x,y)"
paulson@62131
   449
  by (metis dist_fst_le fst_conv fst_zero norm_conv_dist)
paulson@62131
   450
paulson@62131
   451
lemma norm_snd_le: "norm y \<le> norm (x,y)"
paulson@62131
   452
  by (metis dist_snd_le snd_conv snd_zero norm_conv_dist)
hoelzl@59425
   453
immler@67685
   454
lemma norm_Pair_le:
immler@67685
   455
  shows "norm (x, y) \<le> norm x + norm y"
immler@67685
   456
  unfolding norm_Pair
immler@67685
   457
  by (metis norm_ge_zero sqrt_sum_squares_le_sum)
immler@67685
   458
immler@68072
   459
lemma (in vector_space_prod) span_Times_sing1: "p.span ({0} \<times> B) = {0} \<times> vs2.span B"
immler@68072
   460
  apply (rule p.span_unique)
immler@68072
   461
  subgoal by (auto intro!: vs1.span_base vs2.span_base)
immler@68072
   462
  subgoal using vs1.subspace_single_0 vs2.subspace_span by (rule subspace_Times)
immler@68072
   463
  subgoal for T
immler@68072
   464
  proof safe
immler@68072
   465
    fix b
immler@68072
   466
    assume subset_T: "{0} \<times> B \<subseteq> T" and subspace: "p.subspace T" and b_span: "b \<in> vs2.span B"
immler@68072
   467
    then obtain t r where b: "b = (\<Sum>a\<in>t. r a *b a)" and t: "finite t" "t \<subseteq> B"
immler@68072
   468
      by (auto simp: vs2.span_explicit)
immler@68072
   469
    have "(0, b) = (\<Sum>b\<in>t. scale (r b) (0, b))"
immler@68072
   470
      unfolding b scale_prod sum_prod
immler@68072
   471
      by simp
immler@68072
   472
    also have "\<dots> \<in> T"
immler@68072
   473
      using \<open>t \<subseteq> B\<close> subset_T
immler@68072
   474
      by (auto intro!: p.subspace_sum p.subspace_scale subspace)
immler@68072
   475
    finally show "(0, b) \<in> T" .
immler@68072
   476
  qed
immler@68072
   477
  done
immler@68072
   478
immler@68072
   479
lemma (in vector_space_prod) span_Times_sing2: "p.span (A \<times> {0}) = vs1.span A \<times> {0}"
immler@68072
   480
  apply (rule p.span_unique)
immler@68072
   481
  subgoal by (auto intro!: vs1.span_base vs2.span_base)
immler@68072
   482
  subgoal using vs1.subspace_span vs2.subspace_single_0 by (rule subspace_Times)
immler@68072
   483
  subgoal for T
immler@68072
   484
  proof safe
immler@68072
   485
    fix a
immler@68072
   486
    assume subset_T: "A \<times> {0} \<subseteq> T" and subspace: "p.subspace T" and a_span: "a \<in> vs1.span A"
immler@68072
   487
    then obtain t r where a: "a = (\<Sum>a\<in>t. r a *a a)" and t: "finite t" "t \<subseteq> A"
immler@68072
   488
      by (auto simp: vs1.span_explicit)
immler@68072
   489
    have "(a, 0) = (\<Sum>a\<in>t. scale (r a) (a, 0))"
immler@68072
   490
      unfolding a scale_prod sum_prod
immler@68072
   491
      by simp
immler@68072
   492
    also have "\<dots> \<in> T"
immler@68072
   493
      using \<open>t \<subseteq> A\<close> subset_T
immler@68072
   494
      by (auto intro!: p.subspace_sum p.subspace_scale subspace)
immler@68072
   495
    finally show "(a, 0) \<in> T" .
immler@68072
   496
  qed
immler@68072
   497
  done
immler@68072
   498
immler@68072
   499
lemma (in finite_dimensional_vector_space) zero_not_in_Basis[simp]: "0 \<notin> Basis"
immler@68072
   500
  using dependent_zero local.independent_Basis by blast
immler@68072
   501
immler@68072
   502
locale finite_dimensional_vector_space_prod = vector_space_prod + finite_dimensional_vector_space_pair begin
immler@68072
   503
immler@68072
   504
definition "Basis_pair = B1 \<times> {0} \<union> {0} \<times> B2"
immler@68072
   505
immler@68072
   506
sublocale p: finite_dimensional_vector_space scale Basis_pair
immler@68072
   507
proof unfold_locales
immler@68072
   508
  show "finite Basis_pair"
immler@68072
   509
    by (auto intro!: finite_cartesian_product vs1.finite_Basis vs2.finite_Basis simp: Basis_pair_def)
immler@68072
   510
  show "p.independent Basis_pair"
immler@68072
   511
    unfolding p.dependent_def Basis_pair_def
immler@68072
   512
  proof safe
immler@68072
   513
    fix a
immler@68072
   514
    assume a: "a \<in> B1"
immler@68072
   515
    assume "(a, 0) \<in> p.span (B1 \<times> {0} \<union> {0} \<times> B2 - {(a, 0)})"
immler@68072
   516
    also have "B1 \<times> {0} \<union> {0} \<times> B2 - {(a, 0)} = (B1 - {a}) \<times> {0} \<union> {0} \<times> B2"
immler@68072
   517
      by auto
immler@68072
   518
    finally show False
immler@68072
   519
      using a vs1.dependent_def vs1.independent_Basis
immler@68072
   520
      by (auto simp: p.span_Un span_Times_sing1 span_Times_sing2)
immler@68072
   521
  next
immler@68072
   522
    fix b
immler@68072
   523
    assume b: "b \<in> B2"
immler@68072
   524
    assume "(0, b) \<in> p.span (B1 \<times> {0} \<union> {0} \<times> B2 - {(0, b)})"
immler@68072
   525
    also have "(B1 \<times> {0} \<union> {0} \<times> B2 - {(0, b)}) = B1 \<times> {0} \<union> {0} \<times> (B2 - {b})"
immler@68072
   526
      by auto
immler@68072
   527
    finally show False
immler@68072
   528
      using b vs2.dependent_def vs2.independent_Basis
immler@68072
   529
      by (auto simp: p.span_Un span_Times_sing1 span_Times_sing2)
immler@68072
   530
  qed
immler@68072
   531
  show "p.span Basis_pair = UNIV"
immler@68072
   532
    by (auto simp: p.span_Un span_Times_sing2 span_Times_sing1 vs1.span_Basis vs2.span_Basis
immler@68072
   533
        Basis_pair_def)
immler@68072
   534
qed
immler@68072
   535
immler@68072
   536
lemma dim_Times:
immler@68072
   537
  assumes "vs1.subspace S" "vs2.subspace T"
immler@68072
   538
  shows "p.dim(S \<times> T) = vs1.dim S + vs2.dim T"
immler@68072
   539
proof -
immler@68072
   540
  interpret p1: Vector_Spaces.linear s1 scale "(\<lambda>x. (x, 0))"
immler@68072
   541
    by unfold_locales (auto simp: scale_def)
immler@68072
   542
  interpret pair1: finite_dimensional_vector_space_pair "( *a)" B1 scale Basis_pair
immler@68072
   543
    by unfold_locales
immler@68072
   544
  interpret p2: Vector_Spaces.linear s2 scale "(\<lambda>x. (0, x))"
immler@68072
   545
    by unfold_locales (auto simp: scale_def)
immler@68072
   546
  interpret pair2: finite_dimensional_vector_space_pair "( *b)" B2 scale Basis_pair
immler@68072
   547
    by unfold_locales
immler@68072
   548
  have ss: "p.subspace ((\<lambda>x. (x, 0)) ` S)" "p.subspace (Pair 0 ` T)"
immler@68072
   549
    by (rule p1.subspace_image p2.subspace_image assms)+
immler@68072
   550
  have "p.dim(S \<times> T) = p.dim({u + v |u v. u \<in> (\<lambda>x. (x, 0)) ` S \<and> v \<in> Pair 0 ` T})"
immler@68072
   551
    by (simp add: Times_eq_image_sum)
immler@68072
   552
  moreover have "p.dim ((\<lambda>x. (x, 0::'c)) ` S) = vs1.dim S" "p.dim (Pair (0::'b) ` T) = vs2.dim T"
immler@68072
   553
     by (simp_all add: inj_on_def p1.linear_axioms pair1.dim_image_eq p2.linear_axioms pair2.dim_image_eq)
immler@68072
   554
  moreover have "p.dim ((\<lambda>x. (x, 0)) ` S \<inter> Pair 0 ` T) = 0"
immler@68072
   555
    by (subst p.dim_eq_0) auto
immler@68072
   556
  ultimately show ?thesis
immler@68072
   557
    using p.dim_sums_Int [OF ss] by linarith
immler@68072
   558
qed
immler@68072
   559
immler@68072
   560
lemma dimension_pair: "p.dimension = vs1.dimension + vs2.dimension"
immler@68072
   561
  using dim_Times[OF vs1.subspace_UNIV vs2.subspace_UNIV]
immler@68072
   562
  by (auto simp: p.dim_UNIV vs1.dim_UNIV vs2.dim_UNIV
immler@68072
   563
      p.dimension_def vs1.dimension_def vs2.dimension_def)
immler@68072
   564
huffman@44575
   565
end
immler@68072
   566
immler@68072
   567
end