src/HOL/Analysis/Bounded_Linear_Function.thy
 author hoelzl Mon Aug 08 14:13:14 2016 +0200 (2016-08-08) changeset 63627 6ddb43c6b711 parent 63040 src/HOL/Multivariate_Analysis/Bounded_Linear_Function.thy@eb4ddd18d635 child 63918 6bf55e6e0b75 permissions -rw-r--r--
rename HOL-Multivariate_Analysis to HOL-Analysis.
```     1 (*  Title:      HOL/Analysis/Bounded_Linear_Function.thy
```
```     2     Author:     Fabian Immler, TU München
```
```     3 *)
```
```     4
```
```     5 section \<open>Bounded Linear Function\<close>
```
```     6
```
```     7 theory Bounded_Linear_Function
```
```     8 imports
```
```     9   Topology_Euclidean_Space
```
```    10   Operator_Norm
```
```    11 begin
```
```    12
```
```    13 subsection \<open>Intro rules for @{term bounded_linear}\<close>
```
```    14
```
```    15 named_theorems bounded_linear_intros
```
```    16
```
```    17 lemma onorm_inner_left:
```
```    18   assumes "bounded_linear r"
```
```    19   shows "onorm (\<lambda>x. r x \<bullet> f) \<le> onorm r * norm f"
```
```    20 proof (rule onorm_bound)
```
```    21   fix x
```
```    22   have "norm (r x \<bullet> f) \<le> norm (r x) * norm f"
```
```    23     by (simp add: Cauchy_Schwarz_ineq2)
```
```    24   also have "\<dots> \<le> onorm r * norm x * norm f"
```
```    25     by (intro mult_right_mono onorm assms norm_ge_zero)
```
```    26   finally show "norm (r x \<bullet> f) \<le> onorm r * norm f * norm x"
```
```    27     by (simp add: ac_simps)
```
```    28 qed (intro mult_nonneg_nonneg norm_ge_zero onorm_pos_le assms)
```
```    29
```
```    30 lemma onorm_inner_right:
```
```    31   assumes "bounded_linear r"
```
```    32   shows "onorm (\<lambda>x. f \<bullet> r x) \<le> norm f * onorm r"
```
```    33   apply (subst inner_commute)
```
```    34   apply (rule onorm_inner_left[OF assms, THEN order_trans])
```
```    35   apply simp
```
```    36   done
```
```    37
```
```    38 lemmas [bounded_linear_intros] =
```
```    39   bounded_linear_zero
```
```    40   bounded_linear_add
```
```    41   bounded_linear_const_mult
```
```    42   bounded_linear_mult_const
```
```    43   bounded_linear_scaleR_const
```
```    44   bounded_linear_const_scaleR
```
```    45   bounded_linear_ident
```
```    46   bounded_linear_setsum
```
```    47   bounded_linear_Pair
```
```    48   bounded_linear_sub
```
```    49   bounded_linear_fst_comp
```
```    50   bounded_linear_snd_comp
```
```    51   bounded_linear_inner_left_comp
```
```    52   bounded_linear_inner_right_comp
```
```    53
```
```    54
```
```    55 subsection \<open>declaration of derivative/continuous/tendsto introduction rules for bounded linear functions\<close>
```
```    56
```
```    57 attribute_setup bounded_linear =
```
```    58   \<open>Scan.succeed (Thm.declaration_attribute (fn thm =>
```
```    59     fold (fn (r, s) => Named_Theorems.add_thm s (thm RS r))
```
```    60       [
```
```    61         (@{thm bounded_linear.has_derivative}, @{named_theorems derivative_intros}),
```
```    62         (@{thm bounded_linear.tendsto}, @{named_theorems tendsto_intros}),
```
```    63         (@{thm bounded_linear.continuous}, @{named_theorems continuous_intros}),
```
```    64         (@{thm bounded_linear.continuous_on}, @{named_theorems continuous_intros}),
```
```    65         (@{thm bounded_linear.uniformly_continuous_on}, @{named_theorems continuous_intros}),
```
```    66         (@{thm bounded_linear_compose}, @{named_theorems bounded_linear_intros})
```
```    67       ]))\<close>
```
```    68
```
```    69 attribute_setup bounded_bilinear =
```
```    70   \<open>Scan.succeed (Thm.declaration_attribute (fn thm =>
```
```    71     fold (fn (r, s) => Named_Theorems.add_thm s (thm RS r))
```
```    72       [
```
```    73         (@{thm bounded_bilinear.FDERIV}, @{named_theorems derivative_intros}),
```
```    74         (@{thm bounded_bilinear.tendsto}, @{named_theorems tendsto_intros}),
```
```    75         (@{thm bounded_bilinear.continuous}, @{named_theorems continuous_intros}),
```
```    76         (@{thm bounded_bilinear.continuous_on}, @{named_theorems continuous_intros}),
```
```    77         (@{thm bounded_linear_compose[OF bounded_bilinear.bounded_linear_left]},
```
```    78           @{named_theorems bounded_linear_intros}),
```
```    79         (@{thm bounded_linear_compose[OF bounded_bilinear.bounded_linear_right]},
```
```    80           @{named_theorems bounded_linear_intros}),
```
```    81         (@{thm bounded_linear.uniformly_continuous_on[OF bounded_bilinear.bounded_linear_left]},
```
```    82           @{named_theorems continuous_intros}),
```
```    83         (@{thm bounded_linear.uniformly_continuous_on[OF bounded_bilinear.bounded_linear_right]},
```
```    84           @{named_theorems continuous_intros})
```
```    85       ]))\<close>
```
```    86
```
```    87
```
```    88 subsection \<open>type of bounded linear functions\<close>
```
```    89
```
```    90 typedef (overloaded) ('a, 'b) blinfun ("(_ \<Rightarrow>\<^sub>L /_)" [22, 21] 21) =
```
```    91   "{f::'a::real_normed_vector\<Rightarrow>'b::real_normed_vector. bounded_linear f}"
```
```    92   morphisms blinfun_apply Blinfun
```
```    93   by (blast intro: bounded_linear_intros)
```
```    94
```
```    95 declare [[coercion
```
```    96     "blinfun_apply :: ('a::real_normed_vector \<Rightarrow>\<^sub>L'b::real_normed_vector) \<Rightarrow> 'a \<Rightarrow> 'b"]]
```
```    97
```
```    98 lemma bounded_linear_blinfun_apply[bounded_linear_intros]:
```
```    99   "bounded_linear g \<Longrightarrow> bounded_linear (\<lambda>x. blinfun_apply f (g x))"
```
```   100   by (metis blinfun_apply mem_Collect_eq bounded_linear_compose)
```
```   101
```
```   102 setup_lifting type_definition_blinfun
```
```   103
```
```   104 lemma blinfun_eqI: "(\<And>i. blinfun_apply x i = blinfun_apply y i) \<Longrightarrow> x = y"
```
```   105   by transfer auto
```
```   106
```
```   107 lemma bounded_linear_Blinfun_apply: "bounded_linear f \<Longrightarrow> blinfun_apply (Blinfun f) = f"
```
```   108   by (auto simp: Blinfun_inverse)
```
```   109
```
```   110
```
```   111 subsection \<open>type class instantiations\<close>
```
```   112
```
```   113 instantiation blinfun :: (real_normed_vector, real_normed_vector) real_normed_vector
```
```   114 begin
```
```   115
```
```   116 lift_definition norm_blinfun :: "'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> real" is onorm .
```
```   117
```
```   118 lift_definition minus_blinfun :: "'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b"
```
```   119   is "\<lambda>f g x. f x - g x"
```
```   120   by (rule bounded_linear_sub)
```
```   121
```
```   122 definition dist_blinfun :: "'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> real"
```
```   123   where "dist_blinfun a b = norm (a - b)"
```
```   124
```
```   125 definition [code del]:
```
```   126   "(uniformity :: (('a \<Rightarrow>\<^sub>L 'b) \<times> ('a \<Rightarrow>\<^sub>L 'b)) filter) = (INF e:{0 <..}. principal {(x, y). dist x y < e})"
```
```   127
```
```   128 definition open_blinfun :: "('a \<Rightarrow>\<^sub>L 'b) set \<Rightarrow> bool"
```
```   129   where [code del]: "open_blinfun S = (\<forall>x\<in>S. \<forall>\<^sub>F (x', y) in uniformity. x' = x \<longrightarrow> y \<in> S)"
```
```   130
```
```   131 lift_definition uminus_blinfun :: "'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b" is "\<lambda>f x. - f x"
```
```   132   by (rule bounded_linear_minus)
```
```   133
```
```   134 lift_definition zero_blinfun :: "'a \<Rightarrow>\<^sub>L 'b" is "\<lambda>x. 0"
```
```   135   by (rule bounded_linear_zero)
```
```   136
```
```   137 lift_definition plus_blinfun :: "'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b"
```
```   138   is "\<lambda>f g x. f x + g x"
```
```   139   by (metis bounded_linear_add)
```
```   140
```
```   141 lift_definition scaleR_blinfun::"real \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b" is "\<lambda>r f x. r *\<^sub>R f x"
```
```   142   by (metis bounded_linear_compose bounded_linear_scaleR_right)
```
```   143
```
```   144 definition sgn_blinfun :: "'a \<Rightarrow>\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b"
```
```   145   where "sgn_blinfun x = scaleR (inverse (norm x)) x"
```
```   146
```
```   147 instance
```
```   148   apply standard
```
```   149   unfolding dist_blinfun_def open_blinfun_def sgn_blinfun_def uniformity_blinfun_def
```
```   150   apply (rule refl | (transfer, force simp: onorm_triangle onorm_scaleR onorm_eq_0 algebra_simps))+
```
```   151   done
```
```   152
```
```   153 end
```
```   154
```
```   155 declare uniformity_Abort[where 'a="('a :: real_normed_vector) \<Rightarrow>\<^sub>L ('b :: real_normed_vector)", code]
```
```   156
```
```   157 lemma norm_blinfun_eqI:
```
```   158   assumes "n \<le> norm (blinfun_apply f x) / norm x"
```
```   159   assumes "\<And>x. norm (blinfun_apply f x) \<le> n * norm x"
```
```   160   assumes "0 \<le> n"
```
```   161   shows "norm f = n"
```
```   162   by (auto simp: norm_blinfun_def
```
```   163     intro!: antisym onorm_bound assms order_trans[OF _ le_onorm]
```
```   164     bounded_linear_intros)
```
```   165
```
```   166 lemma norm_blinfun: "norm (blinfun_apply f x) \<le> norm f * norm x"
```
```   167   by transfer (rule onorm)
```
```   168
```
```   169 lemma norm_blinfun_bound: "0 \<le> b \<Longrightarrow> (\<And>x. norm (blinfun_apply f x) \<le> b * norm x) \<Longrightarrow> norm f \<le> b"
```
```   170   by transfer (rule onorm_bound)
```
```   171
```
```   172 lemma bounded_bilinear_blinfun_apply[bounded_bilinear]: "bounded_bilinear blinfun_apply"
```
```   173 proof
```
```   174   fix f g::"'a \<Rightarrow>\<^sub>L 'b" and a b::'a and r::real
```
```   175   show "(f + g) a = f a + g a" "(r *\<^sub>R f) a = r *\<^sub>R f a"
```
```   176     by (transfer, simp)+
```
```   177   interpret bounded_linear f for f::"'a \<Rightarrow>\<^sub>L 'b"
```
```   178     by (auto intro!: bounded_linear_intros)
```
```   179   show "f (a + b) = f a + f b" "f (r *\<^sub>R a) = r *\<^sub>R f a"
```
```   180     by (simp_all add: add scaleR)
```
```   181   show "\<exists>K. \<forall>a b. norm (blinfun_apply a b) \<le> norm a * norm b * K"
```
```   182     by (auto intro!: exI[where x=1] norm_blinfun)
```
```   183 qed
```
```   184
```
```   185 interpretation blinfun: bounded_bilinear blinfun_apply
```
```   186   by (rule bounded_bilinear_blinfun_apply)
```
```   187
```
```   188 lemmas bounded_linear_apply_blinfun[intro, simp] = blinfun.bounded_linear_left
```
```   189
```
```   190
```
```   191 context bounded_bilinear
```
```   192 begin
```
```   193
```
```   194 named_theorems bilinear_simps
```
```   195
```
```   196 lemmas [bilinear_simps] =
```
```   197   add_left
```
```   198   add_right
```
```   199   diff_left
```
```   200   diff_right
```
```   201   minus_left
```
```   202   minus_right
```
```   203   scaleR_left
```
```   204   scaleR_right
```
```   205   zero_left
```
```   206   zero_right
```
```   207   setsum_left
```
```   208   setsum_right
```
```   209
```
```   210 end
```
```   211
```
```   212
```
```   213 instance blinfun :: (banach, banach) banach
```
```   214 proof
```
```   215   fix X::"nat \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b"
```
```   216   assume "Cauchy X"
```
```   217   {
```
```   218     fix x::'a
```
```   219     {
```
```   220       fix x::'a
```
```   221       assume "norm x \<le> 1"
```
```   222       have "Cauchy (\<lambda>n. X n x)"
```
```   223       proof (rule CauchyI)
```
```   224         fix e::real
```
```   225         assume "0 < e"
```
```   226         from CauchyD[OF \<open>Cauchy X\<close> \<open>0 < e\<close>] obtain M
```
```   227           where M: "\<And>m n. m \<ge> M \<Longrightarrow> n \<ge> M \<Longrightarrow> norm (X m - X n) < e"
```
```   228           by auto
```
```   229         show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m x - X n x) < e"
```
```   230         proof (safe intro!: exI[where x=M])
```
```   231           fix m n
```
```   232           assume le: "M \<le> m" "M \<le> n"
```
```   233           have "norm (X m x - X n x) = norm ((X m - X n) x)"
```
```   234             by (simp add: blinfun.bilinear_simps)
```
```   235           also have "\<dots> \<le> norm (X m - X n) * norm x"
```
```   236              by (rule norm_blinfun)
```
```   237           also have "\<dots> \<le> norm (X m - X n) * 1"
```
```   238             using \<open>norm x \<le> 1\<close> norm_ge_zero by (rule mult_left_mono)
```
```   239           also have "\<dots> = norm (X m - X n)" by simp
```
```   240           also have "\<dots> < e" using le by fact
```
```   241           finally show "norm (X m x - X n x) < e" .
```
```   242         qed
```
```   243       qed
```
```   244       hence "convergent (\<lambda>n. X n x)"
```
```   245         by (metis Cauchy_convergent_iff)
```
```   246     } note convergent_norm1 = this
```
```   247     define y where "y = x /\<^sub>R norm x"
```
```   248     have y: "norm y \<le> 1" and xy: "x = norm x *\<^sub>R y"
```
```   249       by (simp_all add: y_def inverse_eq_divide)
```
```   250     have "convergent (\<lambda>n. norm x *\<^sub>R X n y)"
```
```   251       by (intro bounded_bilinear.convergent[OF bounded_bilinear_scaleR] convergent_const
```
```   252         convergent_norm1 y)
```
```   253     also have "(\<lambda>n. norm x *\<^sub>R X n y) = (\<lambda>n. X n x)"
```
```   254       by (subst xy) (simp add: blinfun.bilinear_simps)
```
```   255     finally have "convergent (\<lambda>n. X n x)" .
```
```   256   }
```
```   257   then obtain v where v: "\<And>x. (\<lambda>n. X n x) \<longlonglongrightarrow> v x"
```
```   258     unfolding convergent_def
```
```   259     by metis
```
```   260
```
```   261   have "Cauchy (\<lambda>n. norm (X n))"
```
```   262   proof (rule CauchyI)
```
```   263     fix e::real
```
```   264     assume "e > 0"
```
```   265     from CauchyD[OF \<open>Cauchy X\<close> \<open>0 < e\<close>] obtain M
```
```   266       where M: "\<And>m n. m \<ge> M \<Longrightarrow> n \<ge> M \<Longrightarrow> norm (X m - X n) < e"
```
```   267       by auto
```
```   268     show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (norm (X m) - norm (X n)) < e"
```
```   269     proof (safe intro!: exI[where x=M])
```
```   270       fix m n assume mn: "m \<ge> M" "n \<ge> M"
```
```   271       have "norm (norm (X m) - norm (X n)) \<le> norm (X m - X n)"
```
```   272         by (metis norm_triangle_ineq3 real_norm_def)
```
```   273       also have "\<dots> < e" using mn by fact
```
```   274       finally show "norm (norm (X m) - norm (X n)) < e" .
```
```   275     qed
```
```   276   qed
```
```   277   then obtain K where K: "(\<lambda>n. norm (X n)) \<longlonglongrightarrow> K"
```
```   278     unfolding Cauchy_convergent_iff convergent_def
```
```   279     by metis
```
```   280
```
```   281   have "bounded_linear v"
```
```   282   proof
```
```   283     fix x y and r::real
```
```   284     from tendsto_add[OF v[of x] v [of y]] v[of "x + y", unfolded blinfun.bilinear_simps]
```
```   285       tendsto_scaleR[OF tendsto_const[of r] v[of x]] v[of "r *\<^sub>R x", unfolded blinfun.bilinear_simps]
```
```   286     show "v (x + y) = v x + v y" "v (r *\<^sub>R x) = r *\<^sub>R v x"
```
```   287       by (metis (poly_guards_query) LIMSEQ_unique)+
```
```   288     show "\<exists>K. \<forall>x. norm (v x) \<le> norm x * K"
```
```   289     proof (safe intro!: exI[where x=K])
```
```   290       fix x
```
```   291       have "norm (v x) \<le> K * norm x"
```
```   292         by (rule tendsto_le[OF _ tendsto_mult[OF K tendsto_const] tendsto_norm[OF v]])
```
```   293           (auto simp: norm_blinfun)
```
```   294       thus "norm (v x) \<le> norm x * K"
```
```   295         by (simp add: ac_simps)
```
```   296     qed
```
```   297   qed
```
```   298   hence Bv: "\<And>x. (\<lambda>n. X n x) \<longlonglongrightarrow> Blinfun v x"
```
```   299     by (auto simp: bounded_linear_Blinfun_apply v)
```
```   300
```
```   301   have "X \<longlonglongrightarrow> Blinfun v"
```
```   302   proof (rule LIMSEQ_I)
```
```   303     fix r::real assume "r > 0"
```
```   304     define r' where "r' = r / 2"
```
```   305     have "0 < r'" "r' < r" using \<open>r > 0\<close> by (simp_all add: r'_def)
```
```   306     from CauchyD[OF \<open>Cauchy X\<close> \<open>r' > 0\<close>]
```
```   307     obtain M where M: "\<And>m n. m \<ge> M \<Longrightarrow> n \<ge> M \<Longrightarrow> norm (X m - X n) < r'"
```
```   308       by metis
```
```   309     show "\<exists>no. \<forall>n\<ge>no. norm (X n - Blinfun v) < r"
```
```   310     proof (safe intro!: exI[where x=M])
```
```   311       fix n assume n: "M \<le> n"
```
```   312       have "norm (X n - Blinfun v) \<le> r'"
```
```   313       proof (rule norm_blinfun_bound)
```
```   314         fix x
```
```   315         have "eventually (\<lambda>m. m \<ge> M) sequentially"
```
```   316           by (metis eventually_ge_at_top)
```
```   317         hence ev_le: "eventually (\<lambda>m. norm (X n x - X m x) \<le> r' * norm x) sequentially"
```
```   318         proof eventually_elim
```
```   319           case (elim m)
```
```   320           have "norm (X n x - X m x) = norm ((X n - X m) x)"
```
```   321             by (simp add: blinfun.bilinear_simps)
```
```   322           also have "\<dots> \<le> norm ((X n - X m)) * norm x"
```
```   323             by (rule norm_blinfun)
```
```   324           also have "\<dots> \<le> r' * norm x"
```
```   325             using M[OF n elim] by (simp add: mult_right_mono)
```
```   326           finally show ?case .
```
```   327         qed
```
```   328         have tendsto_v: "(\<lambda>m. norm (X n x - X m x)) \<longlonglongrightarrow> norm (X n x - Blinfun v x)"
```
```   329           by (auto intro!: tendsto_intros Bv)
```
```   330         show "norm ((X n - Blinfun v) x) \<le> r' * norm x"
```
```   331           by (auto intro!: tendsto_ge_const tendsto_v ev_le simp: blinfun.bilinear_simps)
```
```   332       qed (simp add: \<open>0 < r'\<close> less_imp_le)
```
```   333       thus "norm (X n - Blinfun v) < r"
```
```   334         by (metis \<open>r' < r\<close> le_less_trans)
```
```   335     qed
```
```   336   qed
```
```   337   thus "convergent X"
```
```   338     by (rule convergentI)
```
```   339 qed
```
```   340
```
```   341 subsection \<open>On Euclidean Space\<close>
```
```   342
```
```   343 lemma Zfun_setsum:
```
```   344   assumes "finite s"
```
```   345   assumes f: "\<And>i. i \<in> s \<Longrightarrow> Zfun (f i) F"
```
```   346   shows "Zfun (\<lambda>x. setsum (\<lambda>i. f i x) s) F"
```
```   347   using assms by induct (auto intro!: Zfun_zero Zfun_add)
```
```   348
```
```   349 lemma norm_blinfun_euclidean_le:
```
```   350   fixes a::"'a::euclidean_space \<Rightarrow>\<^sub>L 'b::real_normed_vector"
```
```   351   shows "norm a \<le> setsum (\<lambda>x. norm (a x)) Basis"
```
```   352   apply (rule norm_blinfun_bound)
```
```   353    apply (simp add: setsum_nonneg)
```
```   354   apply (subst euclidean_representation[symmetric, where 'a='a])
```
```   355   apply (simp only: blinfun.bilinear_simps setsum_left_distrib)
```
```   356   apply (rule order.trans[OF norm_setsum setsum_mono])
```
```   357   apply (simp add: abs_mult mult_right_mono ac_simps Basis_le_norm)
```
```   358   done
```
```   359
```
```   360 lemma tendsto_componentwise1:
```
```   361   fixes a::"'a::euclidean_space \<Rightarrow>\<^sub>L 'b::real_normed_vector"
```
```   362     and b::"'c \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b"
```
```   363   assumes "(\<And>j. j \<in> Basis \<Longrightarrow> ((\<lambda>n. b n j) \<longlongrightarrow> a j) F)"
```
```   364   shows "(b \<longlongrightarrow> a) F"
```
```   365 proof -
```
```   366   have "\<And>j. j \<in> Basis \<Longrightarrow> Zfun (\<lambda>x. norm (b x j - a j)) F"
```
```   367     using assms unfolding tendsto_Zfun_iff Zfun_norm_iff .
```
```   368   hence "Zfun (\<lambda>x. \<Sum>j\<in>Basis. norm (b x j - a j)) F"
```
```   369     by (auto intro!: Zfun_setsum)
```
```   370   thus ?thesis
```
```   371     unfolding tendsto_Zfun_iff
```
```   372     by (rule Zfun_le)
```
```   373       (auto intro!: order_trans[OF norm_blinfun_euclidean_le] simp: blinfun.bilinear_simps)
```
```   374 qed
```
```   375
```
```   376 lift_definition
```
```   377   blinfun_of_matrix::"('b::euclidean_space \<Rightarrow> 'a::euclidean_space \<Rightarrow> real) \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b"
```
```   378   is "\<lambda>a x. \<Sum>i\<in>Basis. \<Sum>j\<in>Basis. ((x \<bullet> j) * a i j) *\<^sub>R i"
```
```   379   by (intro bounded_linear_intros)
```
```   380
```
```   381 lemma blinfun_of_matrix_works:
```
```   382   fixes f::"'a::euclidean_space \<Rightarrow>\<^sub>L 'b::euclidean_space"
```
```   383   shows "blinfun_of_matrix (\<lambda>i j. (f j) \<bullet> i) = f"
```
```   384 proof (transfer, rule,  rule euclidean_eqI)
```
```   385   fix f::"'a \<Rightarrow> 'b" and x::'a and b::'b assume "bounded_linear f" and b: "b \<in> Basis"
```
```   386   then interpret bounded_linear f by simp
```
```   387   have "(\<Sum>j\<in>Basis. \<Sum>i\<in>Basis. (x \<bullet> i * (f i \<bullet> j)) *\<^sub>R j) \<bullet> b
```
```   388     = (\<Sum>j\<in>Basis. if j = b then (\<Sum>i\<in>Basis. (x \<bullet> i * (f i \<bullet> j))) else 0)"
```
```   389     using b
```
```   390     by (auto simp add: algebra_simps inner_setsum_left inner_Basis split: if_split intro!: setsum.cong)
```
```   391   also have "\<dots> = (\<Sum>i\<in>Basis. (x \<bullet> i * (f i \<bullet> b)))"
```
```   392     using b by (simp add: setsum.delta)
```
```   393   also have "\<dots> = f x \<bullet> b"
```
```   394     by (subst linear_componentwise[symmetric]) (unfold_locales, rule)
```
```   395   finally show "(\<Sum>j\<in>Basis. \<Sum>i\<in>Basis. (x \<bullet> i * (f i \<bullet> j)) *\<^sub>R j) \<bullet> b = f x \<bullet> b" .
```
```   396 qed
```
```   397
```
```   398 lemma blinfun_of_matrix_apply:
```
```   399   "blinfun_of_matrix a x = (\<Sum>i\<in>Basis. \<Sum>j\<in>Basis. ((x \<bullet> j) * a i j) *\<^sub>R i)"
```
```   400   by transfer simp
```
```   401
```
```   402 lemma blinfun_of_matrix_minus: "blinfun_of_matrix x - blinfun_of_matrix y = blinfun_of_matrix (x - y)"
```
```   403   by transfer (auto simp: algebra_simps setsum_subtractf)
```
```   404
```
```   405 lemma norm_blinfun_of_matrix:
```
```   406   "norm (blinfun_of_matrix a) \<le> (\<Sum>i\<in>Basis. \<Sum>j\<in>Basis. \<bar>a i j\<bar>)"
```
```   407   apply (rule norm_blinfun_bound)
```
```   408    apply (simp add: setsum_nonneg)
```
```   409   apply (simp only: blinfun_of_matrix_apply setsum_left_distrib)
```
```   410   apply (rule order_trans[OF norm_setsum setsum_mono])
```
```   411   apply (rule order_trans[OF norm_setsum setsum_mono])
```
```   412   apply (simp add: abs_mult mult_right_mono ac_simps Basis_le_norm)
```
```   413   done
```
```   414
```
```   415 lemma tendsto_blinfun_of_matrix:
```
```   416   assumes "\<And>i j. i \<in> Basis \<Longrightarrow> j \<in> Basis \<Longrightarrow> ((\<lambda>n. b n i j) \<longlongrightarrow> a i j) F"
```
```   417   shows "((\<lambda>n. blinfun_of_matrix (b n)) \<longlongrightarrow> blinfun_of_matrix a) F"
```
```   418 proof -
```
```   419   have "\<And>i j. i \<in> Basis \<Longrightarrow> j \<in> Basis \<Longrightarrow> Zfun (\<lambda>x. norm (b x i j - a i j)) F"
```
```   420     using assms unfolding tendsto_Zfun_iff Zfun_norm_iff .
```
```   421   hence "Zfun (\<lambda>x. (\<Sum>i\<in>Basis. \<Sum>j\<in>Basis. \<bar>b x i j - a i j\<bar>)) F"
```
```   422     by (auto intro!: Zfun_setsum)
```
```   423   thus ?thesis
```
```   424     unfolding tendsto_Zfun_iff blinfun_of_matrix_minus
```
```   425     by (rule Zfun_le) (auto intro!: order_trans[OF norm_blinfun_of_matrix])
```
```   426 qed
```
```   427
```
```   428 lemma tendsto_componentwise:
```
```   429   fixes a::"'a::euclidean_space \<Rightarrow>\<^sub>L 'b::euclidean_space"
```
```   430     and b::"'c \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b"
```
```   431   shows "(\<And>i j. i \<in> Basis \<Longrightarrow> j \<in> Basis \<Longrightarrow> ((\<lambda>n. b n j \<bullet> i) \<longlongrightarrow> a j \<bullet> i) F) \<Longrightarrow> (b \<longlongrightarrow> a) F"
```
```   432   apply (subst blinfun_of_matrix_works[of a, symmetric])
```
```   433   apply (subst blinfun_of_matrix_works[of "b x" for x, symmetric, abs_def])
```
```   434   by (rule tendsto_blinfun_of_matrix)
```
```   435
```
```   436 lemma
```
```   437   continuous_blinfun_componentwiseI:
```
```   438   fixes f:: "'b::t2_space \<Rightarrow> 'a::euclidean_space \<Rightarrow>\<^sub>L 'c::euclidean_space"
```
```   439   assumes "\<And>i j. i \<in> Basis \<Longrightarrow> j \<in> Basis \<Longrightarrow> continuous F (\<lambda>x. (f x) j \<bullet> i)"
```
```   440   shows "continuous F f"
```
```   441   using assms by (auto simp: continuous_def intro!: tendsto_componentwise)
```
```   442
```
```   443 lemma
```
```   444   continuous_blinfun_componentwiseI1:
```
```   445   fixes f:: "'b::t2_space \<Rightarrow> 'a::euclidean_space \<Rightarrow>\<^sub>L 'c::real_normed_vector"
```
```   446   assumes "\<And>i. i \<in> Basis \<Longrightarrow> continuous F (\<lambda>x. f x i)"
```
```   447   shows "continuous F f"
```
```   448   using assms by (auto simp: continuous_def intro!: tendsto_componentwise1)
```
```   449
```
```   450 lemma bounded_linear_blinfun_matrix: "bounded_linear (\<lambda>x. (x::_\<Rightarrow>\<^sub>L _) j \<bullet> i)"
```
```   451   by (auto intro!: bounded_linearI' bounded_linear_intros)
```
```   452
```
```   453 lemma continuous_blinfun_matrix:
```
```   454   fixes f:: "'b::t2_space \<Rightarrow> 'a::real_normed_vector \<Rightarrow>\<^sub>L 'c::real_inner"
```
```   455   assumes "continuous F f"
```
```   456   shows "continuous F (\<lambda>x. (f x) j \<bullet> i)"
```
```   457   by (rule bounded_linear.continuous[OF bounded_linear_blinfun_matrix assms])
```
```   458
```
```   459 lemma continuous_on_blinfun_matrix:
```
```   460   fixes f::"'a::t2_space \<Rightarrow> 'b::real_normed_vector \<Rightarrow>\<^sub>L 'c::real_inner"
```
```   461   assumes "continuous_on S f"
```
```   462   shows "continuous_on S (\<lambda>x. (f x) j \<bullet> i)"
```
```   463   using assms
```
```   464   by (auto simp: continuous_on_eq_continuous_within continuous_blinfun_matrix)
```
```   465
```
```   466 lemma continuous_on_blinfun_of_matrix[continuous_intros]:
```
```   467   assumes "\<And>i j. i \<in> Basis \<Longrightarrow> j \<in> Basis \<Longrightarrow> continuous_on S (\<lambda>s. g s i j)"
```
```   468   shows "continuous_on S (\<lambda>s. blinfun_of_matrix (g s))"
```
```   469   using assms
```
```   470   by (auto simp: continuous_on intro!: tendsto_blinfun_of_matrix)
```
```   471
```
```   472 lemma mult_if_delta:
```
```   473   "(if P then (1::'a::comm_semiring_1) else 0) * q = (if P then q else 0)"
```
```   474   by auto
```
```   475
```
```   476 lemma compact_blinfun_lemma:
```
```   477   fixes f :: "nat \<Rightarrow> 'a::euclidean_space \<Rightarrow>\<^sub>L 'b::euclidean_space"
```
```   478   assumes "bounded (range f)"
```
```   479   shows "\<forall>d\<subseteq>Basis. \<exists>l::'a \<Rightarrow>\<^sub>L 'b. \<exists> r.
```
```   480     subseq r \<and> (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) i) (l i) < e) sequentially)"
```
```   481   by (rule compact_lemma_general[where unproj = "\<lambda>e. blinfun_of_matrix (\<lambda>i j. e j \<bullet> i)"])
```
```   482    (auto intro!: euclidean_eqI[where 'a='b] bounded_linear_image assms
```
```   483     simp: blinfun_of_matrix_works blinfun_of_matrix_apply inner_Basis mult_if_delta setsum.delta'
```
```   484       scaleR_setsum_left[symmetric])
```
```   485
```
```   486 lemma blinfun_euclidean_eqI: "(\<And>i. i \<in> Basis \<Longrightarrow> blinfun_apply x i = blinfun_apply y i) \<Longrightarrow> x = y"
```
```   487   apply (auto intro!: blinfun_eqI)
```
```   488   apply (subst (2) euclidean_representation[symmetric, where 'a='a])
```
```   489   apply (subst (1) euclidean_representation[symmetric, where 'a='a])
```
```   490   apply (simp add: blinfun.bilinear_simps)
```
```   491   done
```
```   492
```
```   493 lemma Blinfun_eq_matrix: "bounded_linear f \<Longrightarrow> Blinfun f = blinfun_of_matrix (\<lambda>i j. f j \<bullet> i)"
```
```   494   by (intro blinfun_euclidean_eqI)
```
```   495      (auto simp: blinfun_of_matrix_apply bounded_linear_Blinfun_apply inner_Basis if_distrib
```
```   496       cond_application_beta setsum.delta' euclidean_representation
```
```   497       cong: if_cong)
```
```   498
```
```   499 text \<open>TODO: generalize (via @{thm compact_cball})?\<close>
```
```   500 instance blinfun :: (euclidean_space, euclidean_space) heine_borel
```
```   501 proof
```
```   502   fix f :: "nat \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'b"
```
```   503   assume f: "bounded (range f)"
```
```   504   then obtain l::"'a \<Rightarrow>\<^sub>L 'b" and r where r: "subseq r"
```
```   505     and l: "\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>Basis. dist (f (r n) i) (l i) < e) sequentially"
```
```   506     using compact_blinfun_lemma [OF f] by blast
```
```   507   {
```
```   508     fix e::real
```
```   509     let ?d = "real_of_nat DIM('a) * real_of_nat DIM('b)"
```
```   510     assume "e > 0"
```
```   511     hence "e / ?d > 0" by (simp add: DIM_positive)
```
```   512     with l have "eventually (\<lambda>n. \<forall>i\<in>Basis. dist (f (r n) i) (l i) < e / ?d) sequentially"
```
```   513       by simp
```
```   514     moreover
```
```   515     {
```
```   516       fix n
```
```   517       assume n: "\<forall>i\<in>Basis. dist (f (r n) i) (l i) < e / ?d"
```
```   518       have "norm (f (r n) - l) = norm (blinfun_of_matrix (\<lambda>i j. (f (r n) - l) j \<bullet> i))"
```
```   519         unfolding blinfun_of_matrix_works ..
```
```   520       also note norm_blinfun_of_matrix
```
```   521       also have "(\<Sum>i\<in>Basis. \<Sum>j\<in>Basis. \<bar>(f (r n) - l) j \<bullet> i\<bar>) <
```
```   522         (\<Sum>i\<in>(Basis::'b set). e / real_of_nat DIM('b))"
```
```   523       proof (rule setsum_strict_mono)
```
```   524         fix i::'b assume i: "i \<in> Basis"
```
```   525         have "(\<Sum>j::'a\<in>Basis. \<bar>(f (r n) - l) j \<bullet> i\<bar>) < (\<Sum>j::'a\<in>Basis. e / ?d)"
```
```   526         proof (rule setsum_strict_mono)
```
```   527           fix j::'a assume j: "j \<in> Basis"
```
```   528           have "\<bar>(f (r n) - l) j \<bullet> i\<bar> \<le> norm ((f (r n) - l) j)"
```
```   529             by (simp add: Basis_le_norm i)
```
```   530           also have "\<dots> < e / ?d"
```
```   531             using n i j by (auto simp: dist_norm blinfun.bilinear_simps)
```
```   532           finally show "\<bar>(f (r n) - l) j \<bullet> i\<bar> < e / ?d" by simp
```
```   533         qed simp_all
```
```   534         also have "\<dots> \<le> e / real_of_nat DIM('b)"
```
```   535           by simp
```
```   536         finally show "(\<Sum>j\<in>Basis. \<bar>(f (r n) - l) j \<bullet> i\<bar>) < e / real_of_nat DIM('b)"
```
```   537           by simp
```
```   538       qed simp_all
```
```   539       also have "\<dots> \<le> e" by simp
```
```   540       finally have "dist (f (r n)) l < e"
```
```   541         by (auto simp: dist_norm)
```
```   542     }
```
```   543     ultimately have "eventually (\<lambda>n. dist (f (r n)) l < e) sequentially"
```
```   544       using eventually_elim2 by force
```
```   545   }
```
```   546   then have *: "((f \<circ> r) \<longlongrightarrow> l) sequentially"
```
```   547     unfolding o_def tendsto_iff by simp
```
```   548   with r show "\<exists>l r. subseq r \<and> ((f \<circ> r) \<longlongrightarrow> l) sequentially"
```
```   549     by auto
```
```   550 qed
```
```   551
```
```   552
```
```   553 subsection \<open>concrete bounded linear functions\<close>
```
```   554
```
```   555 lemma transfer_bounded_bilinear_bounded_linearI:
```
```   556   assumes "g = (\<lambda>i x. (blinfun_apply (f i) x))"
```
```   557   shows "bounded_bilinear g = bounded_linear f"
```
```   558 proof
```
```   559   assume "bounded_bilinear g"
```
```   560   then interpret bounded_bilinear f by (simp add: assms)
```
```   561   show "bounded_linear f"
```
```   562   proof (unfold_locales, safe intro!: blinfun_eqI)
```
```   563     fix i
```
```   564     show "f (x + y) i = (f x + f y) i" "f (r *\<^sub>R x) i = (r *\<^sub>R f x) i" for r x y
```
```   565       by (auto intro!: blinfun_eqI simp: blinfun.bilinear_simps)
```
```   566     from _ nonneg_bounded show "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K"
```
```   567       by (rule ex_reg) (auto intro!: onorm_bound simp: norm_blinfun.rep_eq ac_simps)
```
```   568   qed
```
```   569 qed (auto simp: assms intro!: blinfun.comp)
```
```   570
```
```   571 lemma transfer_bounded_bilinear_bounded_linear[transfer_rule]:
```
```   572   "(rel_fun (rel_fun op = (pcr_blinfun op = op =)) op =) bounded_bilinear bounded_linear"
```
```   573   by (auto simp: pcr_blinfun_def cr_blinfun_def rel_fun_def OO_def
```
```   574     intro!: transfer_bounded_bilinear_bounded_linearI)
```
```   575
```
```   576 context bounded_bilinear
```
```   577 begin
```
```   578
```
```   579 lift_definition prod_left::"'b \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'c" is "(\<lambda>b a. prod a b)"
```
```   580   by (rule bounded_linear_left)
```
```   581 declare prod_left.rep_eq[simp]
```
```   582
```
```   583 lemma bounded_linear_prod_left[bounded_linear]: "bounded_linear prod_left"
```
```   584   by transfer (rule flip)
```
```   585
```
```   586 lift_definition prod_right::"'a \<Rightarrow> 'b \<Rightarrow>\<^sub>L 'c" is "(\<lambda>a b. prod a b)"
```
```   587   by (rule bounded_linear_right)
```
```   588 declare prod_right.rep_eq[simp]
```
```   589
```
```   590 lemma bounded_linear_prod_right[bounded_linear]: "bounded_linear prod_right"
```
```   591   by transfer (rule bounded_bilinear_axioms)
```
```   592
```
```   593 end
```
```   594
```
```   595 lift_definition id_blinfun::"'a::real_normed_vector \<Rightarrow>\<^sub>L 'a" is "\<lambda>x. x"
```
```   596   by (rule bounded_linear_ident)
```
```   597
```
```   598 lemmas blinfun_apply_id_blinfun[simp] = id_blinfun.rep_eq
```
```   599
```
```   600 lemma norm_blinfun_id[simp]:
```
```   601   "norm (id_blinfun::'a::{real_normed_vector, perfect_space} \<Rightarrow>\<^sub>L 'a) = 1"
```
```   602   by transfer (auto simp: onorm_id)
```
```   603
```
```   604 lemma norm_blinfun_id_le:
```
```   605   "norm (id_blinfun::'a::real_normed_vector \<Rightarrow>\<^sub>L 'a) \<le> 1"
```
```   606   by transfer (auto simp: onorm_id_le)
```
```   607
```
```   608
```
```   609 lift_definition fst_blinfun::"('a::real_normed_vector \<times> 'b::real_normed_vector) \<Rightarrow>\<^sub>L 'a" is fst
```
```   610   by (rule bounded_linear_fst)
```
```   611
```
```   612 lemma blinfun_apply_fst_blinfun[simp]: "blinfun_apply fst_blinfun = fst"
```
```   613   by transfer (rule refl)
```
```   614
```
```   615
```
```   616 lift_definition snd_blinfun::"('a::real_normed_vector \<times> 'b::real_normed_vector) \<Rightarrow>\<^sub>L 'b" is snd
```
```   617   by (rule bounded_linear_snd)
```
```   618
```
```   619 lemma blinfun_apply_snd_blinfun[simp]: "blinfun_apply snd_blinfun = snd"
```
```   620   by transfer (rule refl)
```
```   621
```
```   622
```
```   623 lift_definition blinfun_compose::
```
```   624   "'a::real_normed_vector \<Rightarrow>\<^sub>L 'b::real_normed_vector \<Rightarrow>
```
```   625     'c::real_normed_vector \<Rightarrow>\<^sub>L 'a \<Rightarrow>
```
```   626     'c \<Rightarrow>\<^sub>L 'b" (infixl "o\<^sub>L" 55) is "op o"
```
```   627   parametric comp_transfer
```
```   628   unfolding o_def
```
```   629   by (rule bounded_linear_compose)
```
```   630
```
```   631 lemma blinfun_apply_blinfun_compose[simp]: "(a o\<^sub>L b) c = a (b c)"
```
```   632   by (simp add: blinfun_compose.rep_eq)
```
```   633
```
```   634 lemma norm_blinfun_compose:
```
```   635   "norm (f o\<^sub>L g) \<le> norm f * norm g"
```
```   636   by transfer (rule onorm_compose)
```
```   637
```
```   638 lemma bounded_bilinear_blinfun_compose[bounded_bilinear]: "bounded_bilinear op o\<^sub>L"
```
```   639   by unfold_locales
```
```   640     (auto intro!: blinfun_eqI exI[where x=1] simp: blinfun.bilinear_simps norm_blinfun_compose)
```
```   641
```
```   642 lemma blinfun_compose_zero[simp]:
```
```   643   "blinfun_compose 0 = (\<lambda>_. 0)"
```
```   644   "blinfun_compose x 0 = 0"
```
```   645   by (auto simp: blinfun.bilinear_simps intro!: blinfun_eqI)
```
```   646
```
```   647
```
```   648 lift_definition blinfun_inner_right::"'a::real_inner \<Rightarrow> 'a \<Rightarrow>\<^sub>L real" is "op \<bullet>"
```
```   649   by (rule bounded_linear_inner_right)
```
```   650 declare blinfun_inner_right.rep_eq[simp]
```
```   651
```
```   652 lemma bounded_linear_blinfun_inner_right[bounded_linear]: "bounded_linear blinfun_inner_right"
```
```   653   by transfer (rule bounded_bilinear_inner)
```
```   654
```
```   655
```
```   656 lift_definition blinfun_inner_left::"'a::real_inner \<Rightarrow> 'a \<Rightarrow>\<^sub>L real" is "\<lambda>x y. y \<bullet> x"
```
```   657   by (rule bounded_linear_inner_left)
```
```   658 declare blinfun_inner_left.rep_eq[simp]
```
```   659
```
```   660 lemma bounded_linear_blinfun_inner_left[bounded_linear]: "bounded_linear blinfun_inner_left"
```
```   661   by transfer (rule bounded_bilinear.flip[OF bounded_bilinear_inner])
```
```   662
```
```   663
```
```   664 lift_definition blinfun_scaleR_right::"real \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'a::real_normed_vector" is "op *\<^sub>R"
```
```   665   by (rule bounded_linear_scaleR_right)
```
```   666 declare blinfun_scaleR_right.rep_eq[simp]
```
```   667
```
```   668 lemma bounded_linear_blinfun_scaleR_right[bounded_linear]: "bounded_linear blinfun_scaleR_right"
```
```   669   by transfer (rule bounded_bilinear_scaleR)
```
```   670
```
```   671
```
```   672 lift_definition blinfun_scaleR_left::"'a::real_normed_vector \<Rightarrow> real \<Rightarrow>\<^sub>L 'a" is "\<lambda>x y. y *\<^sub>R x"
```
```   673   by (rule bounded_linear_scaleR_left)
```
```   674 lemmas [simp] = blinfun_scaleR_left.rep_eq
```
```   675
```
```   676 lemma bounded_linear_blinfun_scaleR_left[bounded_linear]: "bounded_linear blinfun_scaleR_left"
```
```   677   by transfer (rule bounded_bilinear.flip[OF bounded_bilinear_scaleR])
```
```   678
```
```   679
```
```   680 lift_definition blinfun_mult_right::"'a \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'a::real_normed_algebra" is "op *"
```
```   681   by (rule bounded_linear_mult_right)
```
```   682 declare blinfun_mult_right.rep_eq[simp]
```
```   683
```
```   684 lemma bounded_linear_blinfun_mult_right[bounded_linear]: "bounded_linear blinfun_mult_right"
```
```   685   by transfer (rule bounded_bilinear_mult)
```
```   686
```
```   687
```
```   688 lift_definition blinfun_mult_left::"'a::real_normed_algebra \<Rightarrow> 'a \<Rightarrow>\<^sub>L 'a" is "\<lambda>x y. y * x"
```
```   689   by (rule bounded_linear_mult_left)
```
```   690 lemmas [simp] = blinfun_mult_left.rep_eq
```
```   691
```
```   692 lemma bounded_linear_blinfun_mult_left[bounded_linear]: "bounded_linear blinfun_mult_left"
```
```   693   by transfer (rule bounded_bilinear.flip[OF bounded_bilinear_mult])
```
```   694
```
```   695 end
```