src/HOL/Multivariate_Analysis/Bounded_Continuous_Function.thy
author paulson <lp15@cam.ac.uk>
Sat Apr 11 11:56:40 2015 +0100 (2015-04-11)
changeset 60017 b785d6d06430
parent 59865 8a20dd967385
child 60420 884f54e01427
permissions -rw-r--r--
Overloading of ln and powr, but "approximation" no longer works for powr. Code generation also fails due to type ambiguity in scala.
hoelzl@59453
     1
section {* Bounded Continuous Functions *}
hoelzl@59453
     2
theory Bounded_Continuous_Function
hoelzl@59453
     3
imports Integration
hoelzl@59453
     4
begin
hoelzl@59453
     5
hoelzl@59453
     6
subsection{* Definition *}
hoelzl@59453
     7
hoelzl@59453
     8
definition "bcontfun = {f :: 'a::topological_space \<Rightarrow> 'b::metric_space. continuous_on UNIV f \<and> bounded (range f)}"
hoelzl@59453
     9
hoelzl@59453
    10
typedef ('a, 'b) bcontfun =
hoelzl@59453
    11
    "bcontfun :: ('a::topological_space \<Rightarrow> 'b::metric_space) set"
hoelzl@59453
    12
  by (auto simp: bcontfun_def intro: continuous_intros simp: bounded_def)
hoelzl@59453
    13
hoelzl@59453
    14
lemma bcontfunE:
hoelzl@59453
    15
  assumes "f \<in> bcontfun"
hoelzl@59453
    16
  obtains y where "continuous_on UNIV f" "\<And>x. dist (f x) u \<le> y"
hoelzl@59453
    17
  using assms unfolding bcontfun_def
hoelzl@59453
    18
  by (metis (lifting) bounded_any_center dist_commute mem_Collect_eq rangeI)
hoelzl@59453
    19
hoelzl@59453
    20
lemma bcontfunE':
hoelzl@59453
    21
  assumes "f \<in> bcontfun"
hoelzl@59453
    22
  obtains y where "continuous_on UNIV f" "\<And>x. dist (f x) undefined \<le> y"
hoelzl@59453
    23
  using assms bcontfunE
hoelzl@59453
    24
  by metis
hoelzl@59453
    25
hoelzl@59453
    26
lemma bcontfunI:
hoelzl@59453
    27
  "continuous_on UNIV f \<Longrightarrow> (\<And>x. dist (f x) u \<le> b) \<Longrightarrow> f \<in> bcontfun"
hoelzl@59453
    28
  unfolding bcontfun_def
hoelzl@59453
    29
  by (metis (lifting, no_types) bounded_def dist_commute mem_Collect_eq rangeE)
hoelzl@59453
    30
hoelzl@59453
    31
lemma bcontfunI':
hoelzl@59453
    32
  "continuous_on UNIV f \<Longrightarrow> (\<And>x. dist (f x) undefined \<le> b) \<Longrightarrow> f \<in> bcontfun"
hoelzl@59453
    33
  using bcontfunI by metis
hoelzl@59453
    34
hoelzl@59453
    35
lemma continuous_on_Rep_bcontfun[intro, simp]: "continuous_on T (Rep_bcontfun x)"
hoelzl@59453
    36
  using Rep_bcontfun[of x]
hoelzl@59453
    37
  by (auto simp: bcontfun_def intro: continuous_on_subset)
hoelzl@59453
    38
hoelzl@59453
    39
instantiation bcontfun :: (topological_space, metric_space) metric_space
hoelzl@59453
    40
begin
hoelzl@59453
    41
hoelzl@59453
    42
definition dist_bcontfun::"('a, 'b) bcontfun \<Rightarrow> ('a, 'b) bcontfun \<Rightarrow> real" where
hoelzl@59453
    43
  "dist_bcontfun f g = (SUP x. dist (Rep_bcontfun f x) (Rep_bcontfun g x))"
hoelzl@59453
    44
hoelzl@59453
    45
definition
hoelzl@59453
    46
  open_bcontfun::"('a, 'b) bcontfun set \<Rightarrow> bool" where
hoelzl@59453
    47
  "open_bcontfun S = (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
hoelzl@59453
    48
hoelzl@59453
    49
lemma dist_bounded:
hoelzl@59453
    50
  fixes f ::"('a, 'b) bcontfun"
hoelzl@59453
    51
  shows "dist (Rep_bcontfun f x) (Rep_bcontfun g x) \<le> dist f g"
hoelzl@59453
    52
proof -
hoelzl@59453
    53
  have "Rep_bcontfun f \<in> bcontfun" using Rep_bcontfun .
hoelzl@59453
    54
  from bcontfunE'[OF this] obtain y where y:
hoelzl@59453
    55
    "continuous_on UNIV (Rep_bcontfun f)"
hoelzl@59453
    56
    "\<And>x. dist (Rep_bcontfun f x) undefined \<le> y"
hoelzl@59453
    57
    by auto
hoelzl@59453
    58
  have "Rep_bcontfun g \<in> bcontfun" using Rep_bcontfun .
hoelzl@59453
    59
  from bcontfunE'[OF this] obtain z where z:
hoelzl@59453
    60
    "continuous_on UNIV (Rep_bcontfun g)"
hoelzl@59453
    61
    "\<And>x. dist (Rep_bcontfun g x) undefined \<le> z"
hoelzl@59453
    62
    by auto
hoelzl@59453
    63
  show ?thesis unfolding dist_bcontfun_def
hoelzl@59453
    64
  proof (intro cSUP_upper bdd_aboveI2)
hoelzl@59453
    65
    fix x
hoelzl@59453
    66
    have "dist (Rep_bcontfun f x) (Rep_bcontfun g x) \<le> dist (Rep_bcontfun f x) undefined + dist (Rep_bcontfun g x) undefined"
hoelzl@59453
    67
      by (rule dist_triangle2)
hoelzl@59453
    68
    also have "\<dots> \<le> y + z" using y(2)[of x] z(2)[of x] by (rule add_mono)
hoelzl@59453
    69
    finally show "dist (Rep_bcontfun f x) (Rep_bcontfun g x) \<le> y + z" .
hoelzl@59453
    70
  qed simp
hoelzl@59453
    71
qed
hoelzl@59453
    72
hoelzl@59453
    73
lemma dist_bound:
hoelzl@59453
    74
  fixes f ::"('a, 'b) bcontfun"
hoelzl@59453
    75
  assumes "\<And>x. dist (Rep_bcontfun f x) (Rep_bcontfun g x) \<le> b"
hoelzl@59453
    76
  shows "dist f g \<le> b"
hoelzl@59453
    77
  using assms by (auto simp: dist_bcontfun_def intro: cSUP_least)
hoelzl@59453
    78
hoelzl@59453
    79
lemma dist_bounded_Abs:
hoelzl@59453
    80
  fixes f g ::"'a \<Rightarrow> 'b"
hoelzl@59453
    81
  assumes "f \<in> bcontfun" "g \<in> bcontfun"
hoelzl@59453
    82
  shows "dist (f x) (g x) \<le> dist (Abs_bcontfun f) (Abs_bcontfun g)"
hoelzl@59453
    83
  by (metis Abs_bcontfun_inverse assms dist_bounded)
hoelzl@59453
    84
hoelzl@59453
    85
lemma const_bcontfun: "(\<lambda>x::'a. b::'b) \<in> bcontfun"
hoelzl@59453
    86
  by (auto intro: bcontfunI continuous_on_const)
hoelzl@59453
    87
hoelzl@59453
    88
lemma dist_fun_lt_imp_dist_val_lt:
hoelzl@59453
    89
  assumes "dist f g < e"
hoelzl@59453
    90
  shows "dist (Rep_bcontfun f x) (Rep_bcontfun g x) < e"
hoelzl@59453
    91
  using dist_bounded assms by (rule le_less_trans)
hoelzl@59453
    92
hoelzl@59453
    93
lemma dist_val_lt_imp_dist_fun_le:
hoelzl@59453
    94
  assumes "\<forall>x. dist (Rep_bcontfun f x) (Rep_bcontfun g x) < e"
hoelzl@59453
    95
  shows "dist f g \<le> e"
hoelzl@59453
    96
unfolding dist_bcontfun_def
hoelzl@59453
    97
proof (intro cSUP_least)
hoelzl@59453
    98
  fix x
hoelzl@59453
    99
  show "dist (Rep_bcontfun f x) (Rep_bcontfun g x) \<le> e"
hoelzl@59453
   100
    using assms[THEN spec[where x=x]] by (simp add: dist_norm)
hoelzl@59453
   101
qed (simp)
hoelzl@59453
   102
hoelzl@59453
   103
instance
hoelzl@59453
   104
proof
hoelzl@59453
   105
  fix f g::"('a, 'b) bcontfun"
hoelzl@59453
   106
  show "dist f g = 0 \<longleftrightarrow> f = g"
hoelzl@59453
   107
  proof
hoelzl@59453
   108
    have "\<And>x. dist (Rep_bcontfun f x) (Rep_bcontfun g x) \<le> dist f g" by (rule dist_bounded)
hoelzl@59453
   109
    also assume "dist f g = 0"
hoelzl@59453
   110
    finally  show "f = g" by (auto simp: Rep_bcontfun_inject[symmetric] Abs_bcontfun_inverse)
hoelzl@59453
   111
  qed (auto simp: dist_bcontfun_def SUP_def simp del: Sup_image_eq intro!: cSup_eq)
hoelzl@59453
   112
next
hoelzl@59453
   113
  fix f g h :: "('a, 'b) bcontfun"
hoelzl@59453
   114
  show "dist f g \<le> dist f h + dist g h"
hoelzl@59453
   115
  proof (subst dist_bcontfun_def, safe intro!: cSUP_least)
hoelzl@59453
   116
    fix x
hoelzl@59453
   117
    have "dist (Rep_bcontfun f x) (Rep_bcontfun g x) \<le>
hoelzl@59453
   118
      dist (Rep_bcontfun f x) (Rep_bcontfun h x) + dist (Rep_bcontfun g x) (Rep_bcontfun h x)"
hoelzl@59453
   119
      by (rule dist_triangle2)
hoelzl@59453
   120
    also have "dist (Rep_bcontfun f x) (Rep_bcontfun h x) \<le> dist f h" by (rule dist_bounded)
hoelzl@59453
   121
    also have "dist (Rep_bcontfun g x) (Rep_bcontfun h x) \<le> dist g h" by (rule dist_bounded)
hoelzl@59453
   122
    finally show "dist (Rep_bcontfun f x) (Rep_bcontfun g x) \<le> dist f h + dist g h" by simp
hoelzl@59453
   123
  qed
hoelzl@59453
   124
qed (simp add: open_bcontfun_def)
hoelzl@59453
   125
end
hoelzl@59453
   126
hoelzl@59453
   127
lemma closed_Pi_bcontfun:
hoelzl@59453
   128
  fixes I::"'a::metric_space set" and X::"'a \<Rightarrow> 'b::complete_space set"
hoelzl@59453
   129
  assumes "\<And>i. i \<in> I \<Longrightarrow> closed (X i)"
hoelzl@59453
   130
  shows "closed (Abs_bcontfun ` (Pi I X \<inter> bcontfun))"
hoelzl@59453
   131
  unfolding closed_sequential_limits
hoelzl@59453
   132
proof safe
hoelzl@59453
   133
  fix f l
hoelzl@59453
   134
  assume seq: "\<forall>n. f n \<in> Abs_bcontfun ` (Pi I X \<inter> bcontfun)" and lim: "f ----> l"
hoelzl@59453
   135
  have lim_fun: "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. \<forall>x. dist (Rep_bcontfun (f n) x) (Rep_bcontfun l x) < e"
hoelzl@59453
   136
    using LIMSEQ_imp_Cauchy[OF lim, simplified Cauchy_def] metric_LIMSEQ_D[OF lim]
hoelzl@59453
   137
    by (intro uniformly_cauchy_imp_uniformly_convergent[where P="%_. True", simplified])
hoelzl@59453
   138
      (metis dist_fun_lt_imp_dist_val_lt)+
hoelzl@59453
   139
  show "l \<in> Abs_bcontfun ` (Pi I X \<inter> bcontfun)"
hoelzl@59453
   140
  proof (rule, safe)
hoelzl@59453
   141
    fix x assume "x \<in> I"
hoelzl@59453
   142
    hence "closed (X x)" using assms by simp
hoelzl@59453
   143
    moreover have "eventually (\<lambda>xa. Rep_bcontfun (f xa) x \<in> X x) sequentially"
hoelzl@59453
   144
    proof (rule always_eventually, safe)
hoelzl@59453
   145
      fix i
hoelzl@59453
   146
      from seq[THEN spec, of i] `x \<in> I`
hoelzl@59453
   147
      show "Rep_bcontfun (f i) x \<in> X x"
hoelzl@59453
   148
        by (auto simp: Abs_bcontfun_inverse)
hoelzl@59453
   149
    qed
hoelzl@59453
   150
    moreover note sequentially_bot
hoelzl@59453
   151
    moreover have "(\<lambda>n. Rep_bcontfun (f n) x) ----> Rep_bcontfun l x"
hoelzl@59453
   152
      using lim_fun by (blast intro!: metric_LIMSEQ_I)
hoelzl@59453
   153
    ultimately show "Rep_bcontfun l x \<in> X x"
hoelzl@59453
   154
      by (rule Lim_in_closed_set)
hoelzl@59453
   155
  qed (auto simp: Rep_bcontfun Rep_bcontfun_inverse)
hoelzl@59453
   156
qed
hoelzl@59453
   157
hoelzl@59453
   158
subsection {* Complete Space *}
hoelzl@59453
   159
hoelzl@59453
   160
instance bcontfun :: (metric_space, complete_space) complete_space
hoelzl@59453
   161
proof
hoelzl@59453
   162
  fix f::"nat \<Rightarrow> ('a,'b) bcontfun"
hoelzl@59453
   163
  assume "Cauchy f" --{* Cauchy equals uniform convergence *}
hoelzl@59453
   164
  then obtain g where limit_function:
hoelzl@59453
   165
    "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. \<forall>x. dist (Rep_bcontfun (f n) x) (g x) < e"
hoelzl@59453
   166
    using uniformly_convergent_eq_cauchy[of "\<lambda>_. True"
hoelzl@59453
   167
      "\<lambda>n. Rep_bcontfun (f n)"]
hoelzl@59453
   168
    unfolding Cauchy_def by (metis dist_fun_lt_imp_dist_val_lt)
hoelzl@59453
   169
hoelzl@59453
   170
  then obtain N where fg_dist: --{* for an upper bound on g *}
hoelzl@59453
   171
    "\<forall>n\<ge>N. \<forall>x. dist (g x) ( Rep_bcontfun (f n) x) < 1"
hoelzl@59453
   172
    by (force simp add: dist_commute)
hoelzl@59453
   173
  from bcontfunE'[OF Rep_bcontfun, of "f N"] obtain b where
hoelzl@59453
   174
    f_bound: "\<forall>x. dist (Rep_bcontfun (f N) x) undefined \<le> b" by force
hoelzl@59453
   175
  have "g \<in> bcontfun" --{* The limit function is bounded and continuous *}
hoelzl@59453
   176
  proof (intro bcontfunI)
hoelzl@59453
   177
    show "continuous_on UNIV g"
hoelzl@59453
   178
      using bcontfunE[OF Rep_bcontfun] limit_function
hoelzl@59453
   179
      by (intro continuous_uniform_limit[where
hoelzl@59453
   180
        f="%n. Rep_bcontfun (f n)" and F="sequentially"]) (auto
hoelzl@59453
   181
        simp add: eventually_sequentially trivial_limit_def dist_norm)
hoelzl@59453
   182
  next
hoelzl@59453
   183
    fix x
hoelzl@59453
   184
    from fg_dist have "dist (g x) (Rep_bcontfun (f N) x) < 1"
hoelzl@59453
   185
      by (simp add: dist_norm norm_minus_commute)
hoelzl@59453
   186
    with dist_triangle[of "g x" undefined "Rep_bcontfun (f N) x"]
hoelzl@59453
   187
    show "dist (g x) undefined \<le> 1 + b" using f_bound[THEN spec, of x]
hoelzl@59453
   188
      by simp
hoelzl@59453
   189
  qed
hoelzl@59453
   190
  show "convergent f"
lp15@60017
   191
  proof (rule convergentI, subst lim_sequentially, safe)
hoelzl@59453
   192
    --{* The limit function converges according to its norm *}
hoelzl@59453
   193
    fix e::real
hoelzl@59453
   194
    assume "e > 0" hence "e/2 > 0" by simp
hoelzl@59453
   195
    with limit_function[THEN spec, of"e/2"]
hoelzl@59453
   196
    have "\<exists>N. \<forall>n\<ge>N. \<forall>x. dist (Rep_bcontfun (f n) x) (g x) < e/2"
hoelzl@59453
   197
      by simp
hoelzl@59453
   198
    then obtain N where N: "\<forall>n\<ge>N. \<forall>x. dist (Rep_bcontfun (f n) x) (g x) < e / 2" by auto
hoelzl@59453
   199
    show "\<exists>N. \<forall>n\<ge>N. dist (f n) (Abs_bcontfun g) < e"
hoelzl@59453
   200
    proof (rule, safe)
hoelzl@59453
   201
      fix n
hoelzl@59453
   202
      assume "N \<le> n"
hoelzl@59453
   203
      with N show "dist (f n) (Abs_bcontfun g) < e"
hoelzl@59453
   204
        using dist_val_lt_imp_dist_fun_le[of
hoelzl@59453
   205
          "f n" "Abs_bcontfun g" "e/2"]
hoelzl@59453
   206
          Abs_bcontfun_inverse[OF `g \<in> bcontfun`] `e > 0` by simp
hoelzl@59453
   207
    qed
hoelzl@59453
   208
  qed
hoelzl@59453
   209
qed
hoelzl@59453
   210
hoelzl@59453
   211
subsection{* Supremum norm for a normed vector space *}
hoelzl@59453
   212
hoelzl@59453
   213
instantiation bcontfun :: (topological_space, real_normed_vector) real_vector
hoelzl@59453
   214
begin
hoelzl@59453
   215
hoelzl@59453
   216
definition "-f = Abs_bcontfun (\<lambda>x. -(Rep_bcontfun f x))"
hoelzl@59453
   217
hoelzl@59453
   218
definition "f + g = Abs_bcontfun (\<lambda>x. Rep_bcontfun f x + Rep_bcontfun g x)"
hoelzl@59453
   219
hoelzl@59453
   220
definition "f - g = Abs_bcontfun (\<lambda>x. Rep_bcontfun f x - Rep_bcontfun g x)"
hoelzl@59453
   221
hoelzl@59453
   222
definition "0 = Abs_bcontfun (\<lambda>x. 0)"
hoelzl@59453
   223
hoelzl@59453
   224
definition "scaleR r f = Abs_bcontfun (\<lambda>x. r *\<^sub>R Rep_bcontfun f x)"
hoelzl@59453
   225
hoelzl@59453
   226
lemma plus_cont:
hoelzl@59453
   227
  fixes f g ::"'a \<Rightarrow> 'b"
hoelzl@59453
   228
  assumes f: "f \<in> bcontfun" and g: "g \<in> bcontfun"
hoelzl@59453
   229
  shows "(\<lambda>x. f x + g x) \<in> bcontfun"
hoelzl@59453
   230
proof -
hoelzl@59453
   231
  from bcontfunE'[OF f] obtain y where "continuous_on UNIV f" "\<And>x. dist (f x) undefined \<le> y"
hoelzl@59453
   232
    by auto
hoelzl@59453
   233
  moreover
hoelzl@59453
   234
  from bcontfunE'[OF g] obtain z where "continuous_on UNIV g" "\<And>x. dist (g x) undefined \<le> z"
hoelzl@59453
   235
    by auto
hoelzl@59453
   236
  ultimately show ?thesis
hoelzl@59453
   237
  proof (intro bcontfunI)
hoelzl@59453
   238
    fix x
hoelzl@59453
   239
    have "dist (f x + g x) 0 = dist (f x + g x) (0 + 0)" by simp
hoelzl@59453
   240
    also have "\<dots> \<le> dist (f x) 0 + dist (g x) 0" by (rule dist_triangle_add)
hoelzl@59453
   241
    also have "\<dots> \<le> dist (Abs_bcontfun f) 0 + dist (Abs_bcontfun g) 0"
hoelzl@59453
   242
      unfolding zero_bcontfun_def using assms
hoelzl@59453
   243
      by (auto intro!: add_mono dist_bounded_Abs const_bcontfun)
hoelzl@59453
   244
    finally
hoelzl@59453
   245
    show "dist (f x + g x) 0 <= dist (Abs_bcontfun f) 0 + dist (Abs_bcontfun g) 0" .
hoelzl@59453
   246
  qed (simp add: continuous_on_add)
hoelzl@59453
   247
qed
hoelzl@59453
   248
hoelzl@59453
   249
lemma Rep_bcontfun_plus[simp]: "Rep_bcontfun (f + g) x = Rep_bcontfun f x + Rep_bcontfun g x"
hoelzl@59453
   250
  by (simp add: plus_bcontfun_def Abs_bcontfun_inverse plus_cont Rep_bcontfun)
hoelzl@59453
   251
hoelzl@59453
   252
lemma uminus_cont:
hoelzl@59453
   253
  fixes f ::"'a \<Rightarrow> 'b"
hoelzl@59453
   254
  assumes "f \<in> bcontfun"
hoelzl@59453
   255
  shows "(\<lambda>x. - f x) \<in> bcontfun"
hoelzl@59453
   256
proof -
hoelzl@59453
   257
  from bcontfunE[OF assms, of 0] obtain y where "continuous_on UNIV f" "\<And>x. dist (f x) 0 \<le> y"
hoelzl@59453
   258
    by auto
hoelzl@59453
   259
  thus ?thesis
hoelzl@59453
   260
  proof (intro bcontfunI)
hoelzl@59453
   261
    fix x
hoelzl@59453
   262
    assume "\<And>x. dist (f x) 0 \<le> y"
hoelzl@59453
   263
    thus "dist (- f x) 0 \<le> y" by (subst dist_minus[symmetric]) simp
hoelzl@59453
   264
  qed (simp add: continuous_on_minus)
hoelzl@59453
   265
qed
hoelzl@59453
   266
hoelzl@59453
   267
lemma Rep_bcontfun_uminus[simp]:
hoelzl@59453
   268
  "Rep_bcontfun (- f) x = - Rep_bcontfun f x"
hoelzl@59453
   269
  by (simp add: uminus_bcontfun_def Abs_bcontfun_inverse uminus_cont Rep_bcontfun)
hoelzl@59453
   270
hoelzl@59453
   271
lemma minus_cont:
hoelzl@59453
   272
  fixes f g ::"'a \<Rightarrow> 'b"
hoelzl@59453
   273
  assumes f: "f \<in> bcontfun" and g: "g \<in> bcontfun"
hoelzl@59453
   274
  shows "(\<lambda>x. f x - g x) \<in> bcontfun"
hoelzl@59453
   275
  using plus_cont [of f "- g"] assms by (simp add: uminus_cont fun_Compl_def)
hoelzl@59453
   276
hoelzl@59453
   277
lemma Rep_bcontfun_minus[simp]:
hoelzl@59453
   278
  "Rep_bcontfun (f - g) x = Rep_bcontfun f x - Rep_bcontfun g x"
hoelzl@59453
   279
  by (simp add: minus_bcontfun_def Abs_bcontfun_inverse minus_cont Rep_bcontfun)
hoelzl@59453
   280
hoelzl@59453
   281
lemma scaleR_cont:
hoelzl@59453
   282
  fixes a and f::"'a \<Rightarrow> 'b"
hoelzl@59453
   283
  assumes "f \<in> bcontfun"
hoelzl@59453
   284
  shows " (\<lambda>x. a *\<^sub>R f x) \<in> bcontfun"
hoelzl@59453
   285
proof -
hoelzl@59453
   286
  from bcontfunE[OF assms, of 0] obtain y where "continuous_on UNIV f" "\<And>x. dist (f x) 0 \<le> y"
hoelzl@59453
   287
    by auto
hoelzl@59453
   288
  thus ?thesis
hoelzl@59453
   289
  proof (intro bcontfunI)
hoelzl@59453
   290
    fix x assume "\<And>x. dist (f x) 0 \<le> y"
haftmann@59554
   291
    then show "dist (a *\<^sub>R f x) 0 \<le> abs a * y"
haftmann@59554
   292
      by (metis norm_cmul_rule_thm norm_conv_dist)
hoelzl@59453
   293
  qed (simp add: continuous_intros)
hoelzl@59453
   294
qed
hoelzl@59453
   295
hoelzl@59453
   296
lemma Rep_bcontfun_scaleR[simp]:
hoelzl@59453
   297
   "Rep_bcontfun (a *\<^sub>R g) x = a *\<^sub>R Rep_bcontfun g x"
hoelzl@59453
   298
  by (simp add: scaleR_bcontfun_def Abs_bcontfun_inverse scaleR_cont Rep_bcontfun)
hoelzl@59453
   299
hoelzl@59453
   300
instance
hoelzl@59453
   301
proof
hoelzl@59453
   302
qed (simp_all add: plus_bcontfun_def zero_bcontfun_def minus_bcontfun_def scaleR_bcontfun_def
hoelzl@59453
   303
    Abs_bcontfun_inverse Rep_bcontfun_inverse Rep_bcontfun algebra_simps
hoelzl@59453
   304
    plus_cont const_bcontfun minus_cont scaleR_cont)
hoelzl@59453
   305
end
hoelzl@59453
   306
hoelzl@59453
   307
instantiation bcontfun :: (topological_space, real_normed_vector) real_normed_vector
hoelzl@59453
   308
begin
hoelzl@59453
   309
hoelzl@59453
   310
definition norm_bcontfun::"('a, 'b) bcontfun \<Rightarrow> real" where
hoelzl@59453
   311
  "norm_bcontfun f = dist f 0"
hoelzl@59453
   312
hoelzl@59453
   313
definition "sgn (f::('a,'b) bcontfun) = f /\<^sub>R norm f"
hoelzl@59453
   314
hoelzl@59453
   315
instance
hoelzl@59453
   316
proof
hoelzl@59453
   317
  fix f g::"('a, 'b) bcontfun"
hoelzl@59453
   318
  show "dist f g = norm (f - g)"
hoelzl@59453
   319
    by (simp add: norm_bcontfun_def dist_bcontfun_def zero_bcontfun_def
hoelzl@59453
   320
    Abs_bcontfun_inverse const_bcontfun norm_conv_dist[symmetric] dist_norm)
hoelzl@59453
   321
  show "norm (f + g) \<le> norm f + norm g"
hoelzl@59453
   322
    unfolding norm_bcontfun_def
hoelzl@59453
   323
  proof (subst dist_bcontfun_def, safe intro!: cSUP_least)
hoelzl@59453
   324
    fix x
hoelzl@59453
   325
    have "dist (Rep_bcontfun (f + g) x) (Rep_bcontfun 0 x) \<le>
hoelzl@59453
   326
      dist (Rep_bcontfun f x) 0 + dist (Rep_bcontfun g x) 0"
hoelzl@59453
   327
      by (metis (hide_lams, no_types) Rep_bcontfun_minus Rep_bcontfun_plus diff_0_right dist_norm
hoelzl@59453
   328
        le_less_linear less_irrefl norm_triangle_lt)
hoelzl@59453
   329
    also have "dist (Rep_bcontfun f x) 0 \<le> dist f 0"
hoelzl@59453
   330
      using dist_bounded[of f x 0]
hoelzl@59453
   331
      by (simp add: Abs_bcontfun_inverse const_bcontfun zero_bcontfun_def)
hoelzl@59453
   332
    also have "dist (Rep_bcontfun g x) 0 \<le> dist g 0" using dist_bounded[of g x 0]
hoelzl@59453
   333
      by (simp add: Abs_bcontfun_inverse const_bcontfun zero_bcontfun_def)
hoelzl@59453
   334
    finally show "dist (Rep_bcontfun (f + g) x) (Rep_bcontfun 0 x) \<le> dist f 0 + dist g 0" by simp
hoelzl@59453
   335
  qed
hoelzl@59453
   336
next
hoelzl@59453
   337
  fix a and f g:: "('a, 'b) bcontfun"
hoelzl@59453
   338
  show "norm (a *\<^sub>R f) = \<bar>a\<bar> * norm f"
hoelzl@59453
   339
  proof -
hoelzl@59453
   340
    have "\<bar>a\<bar> * Sup (range (\<lambda>x. dist (Rep_bcontfun f x) 0)) =
hoelzl@59453
   341
      (SUP i:range (\<lambda>x. dist (Rep_bcontfun f x) 0). \<bar>a\<bar> * i)"
hoelzl@59453
   342
    proof (intro continuous_at_Sup_mono bdd_aboveI2)
hoelzl@59453
   343
      fix x
hoelzl@59453
   344
      show "dist (Rep_bcontfun f x) 0 \<le> norm f" using dist_bounded[of f x 0]
hoelzl@59453
   345
        by (simp add: norm_bcontfun_def norm_conv_dist Abs_bcontfun_inverse zero_bcontfun_def
hoelzl@59453
   346
          const_bcontfun)
hoelzl@59453
   347
    qed (auto intro!: monoI mult_left_mono continuous_intros)
hoelzl@59453
   348
    moreover
hoelzl@59453
   349
    have "range (\<lambda>x. dist (Rep_bcontfun (a *\<^sub>R f) x) 0) = 
hoelzl@59453
   350
      (\<lambda>x. \<bar>a\<bar> * x) ` (range (\<lambda>x. dist (Rep_bcontfun f x) 0))"
hoelzl@59453
   351
      by (auto simp: norm_conv_dist[symmetric])
hoelzl@59453
   352
    ultimately
hoelzl@59453
   353
    show "norm (a *\<^sub>R f) = \<bar>a\<bar> * norm f"
hoelzl@59453
   354
      by (simp add: norm_bcontfun_def dist_bcontfun_def norm_conv_dist Abs_bcontfun_inverse
hoelzl@59453
   355
                    zero_bcontfun_def const_bcontfun SUP_def del: Sup_image_eq)
hoelzl@59453
   356
  qed
hoelzl@59453
   357
qed (auto simp: norm_bcontfun_def sgn_bcontfun_def)
hoelzl@59453
   358
hoelzl@59453
   359
end
hoelzl@59453
   360
hoelzl@59453
   361
lemma bcontfun_normI:
hoelzl@59453
   362
  "continuous_on UNIV f \<Longrightarrow> (\<And>x. norm (f x) \<le> b) \<Longrightarrow> f \<in> bcontfun"
hoelzl@59453
   363
  unfolding norm_conv_dist
hoelzl@59453
   364
  by (auto intro: bcontfunI)
hoelzl@59453
   365
hoelzl@59453
   366
lemma norm_bounded:
hoelzl@59453
   367
  fixes f ::"('a::topological_space, 'b::real_normed_vector) bcontfun"
hoelzl@59453
   368
  shows "norm (Rep_bcontfun f x) \<le> norm f"
hoelzl@59453
   369
  using dist_bounded[of f x 0]
hoelzl@59453
   370
  by (simp add: norm_bcontfun_def norm_conv_dist Abs_bcontfun_inverse zero_bcontfun_def
hoelzl@59453
   371
    const_bcontfun)
hoelzl@59453
   372
hoelzl@59453
   373
lemma norm_bound:
hoelzl@59453
   374
  fixes f ::"('a::topological_space, 'b::real_normed_vector) bcontfun"
hoelzl@59453
   375
  assumes "\<And>x. norm (Rep_bcontfun f x) \<le> b"
hoelzl@59453
   376
  shows "norm f \<le> b"
hoelzl@59453
   377
  using dist_bound[of f 0 b] assms
hoelzl@59453
   378
  by (simp add: norm_bcontfun_def norm_conv_dist Abs_bcontfun_inverse zero_bcontfun_def
hoelzl@59453
   379
    const_bcontfun)
hoelzl@59453
   380
hoelzl@59453
   381
subsection{* Continuously Extended Functions *}
hoelzl@59453
   382
hoelzl@59453
   383
definition clamp::"'a::euclidean_space \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a" where
hoelzl@59453
   384
  "clamp a b x = (\<Sum>i\<in>Basis. (if x\<bullet>i < a\<bullet>i then a\<bullet>i else if x\<bullet>i \<le> b\<bullet>i then x\<bullet>i else b\<bullet>i) *\<^sub>R i)"
hoelzl@59453
   385
hoelzl@59453
   386
definition ext_cont::"('a::euclidean_space \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> ('a, 'b) bcontfun"
hoelzl@59453
   387
  where "ext_cont f a b = Abs_bcontfun ((\<lambda>x. f (clamp a b x)))"
hoelzl@59453
   388
hoelzl@59453
   389
lemma ext_cont_def':
hoelzl@59453
   390
  "ext_cont f a b = Abs_bcontfun (\<lambda>x.
hoelzl@59453
   391
    f (\<Sum>i\<in>Basis. (if x\<bullet>i < a\<bullet>i then a\<bullet>i else if x\<bullet>i \<le> b\<bullet>i then x\<bullet>i else b\<bullet>i) *\<^sub>R i))"
hoelzl@59453
   392
unfolding ext_cont_def clamp_def ..
hoelzl@59453
   393
hoelzl@59453
   394
lemma clamp_in_interval:
hoelzl@59453
   395
  assumes "\<And>i. i \<in> Basis \<Longrightarrow> a \<bullet> i \<le> b \<bullet> i"
hoelzl@59453
   396
  shows "clamp a b x \<in> cbox a b"
hoelzl@59453
   397
  unfolding clamp_def
hoelzl@59453
   398
  using box_ne_empty(1)[of a b] assms by (auto simp: cbox_def)
hoelzl@59453
   399
hoelzl@59453
   400
lemma dist_clamps_le_dist_args:
hoelzl@59453
   401
  fixes x::"'a::euclidean_space"
hoelzl@59453
   402
  assumes "\<And>i. i \<in> Basis \<Longrightarrow> a \<bullet> i \<le> b \<bullet> i"
hoelzl@59453
   403
  shows "dist (clamp a b y) (clamp a b x) \<le> dist y x"
hoelzl@59453
   404
proof -
hoelzl@59453
   405
    from box_ne_empty(1)[of a b] assms have "(\<forall>i\<in>Basis. a \<bullet> i \<le> b \<bullet> i)"
hoelzl@59453
   406
      by (simp add: cbox_def)
hoelzl@59453
   407
    hence "(\<Sum>i\<in>Basis. (dist (clamp a b y \<bullet> i) (clamp a b x \<bullet> i))\<^sup>2)
hoelzl@59453
   408
        \<le> (\<Sum>i\<in>Basis. (dist (y \<bullet> i) (x \<bullet> i))\<^sup>2)"
hoelzl@59453
   409
      by (auto intro!: setsum_mono
lp15@59865
   410
        simp add: clamp_def dist_real_def abs_le_square_iff[symmetric])
hoelzl@59453
   411
    thus ?thesis
hoelzl@59453
   412
      by (auto intro: real_sqrt_le_mono
hoelzl@59453
   413
        simp add: euclidean_dist_l2[where y=x] euclidean_dist_l2[where y="clamp a b x"] setL2_def)
hoelzl@59453
   414
qed
hoelzl@59453
   415
hoelzl@59453
   416
lemma clamp_continuous_at:
hoelzl@59453
   417
  fixes f::"'a::euclidean_space \<Rightarrow> 'b::metric_space"
hoelzl@59453
   418
  fixes x
hoelzl@59453
   419
  assumes "\<And>i. i \<in> Basis \<Longrightarrow> a \<bullet> i \<le> b \<bullet> i"
hoelzl@59453
   420
  assumes f_cont: "continuous_on (cbox a b) f"
hoelzl@59453
   421
  shows "continuous (at x) (\<lambda>x. f (clamp a b x))"
hoelzl@59453
   422
unfolding continuous_at_eps_delta
hoelzl@59453
   423
proof (safe)
hoelzl@59453
   424
  fix x::'a and e::real
hoelzl@59453
   425
  assume "0 < e"
hoelzl@59453
   426
  moreover
hoelzl@59453
   427
  have "clamp a b x \<in> cbox a b" by (simp add: clamp_in_interval assms)
hoelzl@59453
   428
  moreover
hoelzl@59453
   429
  note f_cont[simplified continuous_on_iff]
hoelzl@59453
   430
  ultimately
hoelzl@59453
   431
  obtain d where d: "0 < d"
hoelzl@59453
   432
    "\<And>x'. x' \<in> cbox a b \<Longrightarrow> dist x' (clamp a b x) < d \<Longrightarrow> dist (f x') (f (clamp a b x)) < e"
hoelzl@59453
   433
    by force
hoelzl@59453
   434
  show "\<exists>d>0. \<forall>x'. dist x' x < d \<longrightarrow>
hoelzl@59453
   435
    dist (f (clamp a b x')) (f (clamp a b x)) < e"
hoelzl@59453
   436
    by (auto intro!: d clamp_in_interval assms dist_clamps_le_dist_args[THEN le_less_trans])
hoelzl@59453
   437
qed
hoelzl@59453
   438
hoelzl@59453
   439
lemma clamp_continuous_on:
hoelzl@59453
   440
  fixes f::"'a::euclidean_space \<Rightarrow> 'b::metric_space"
hoelzl@59453
   441
  assumes "\<And>i. i \<in> Basis \<Longrightarrow> a \<bullet> i \<le> b \<bullet> i"
hoelzl@59453
   442
  assumes f_cont: "continuous_on (cbox a b) f"
hoelzl@59453
   443
  shows "continuous_on UNIV (\<lambda>x. f (clamp a b x))"
hoelzl@59453
   444
  using assms
hoelzl@59453
   445
  by (auto intro: continuous_at_imp_continuous_on clamp_continuous_at)
hoelzl@59453
   446
hoelzl@59453
   447
lemma clamp_bcontfun:
hoelzl@59453
   448
  fixes f::"'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@59453
   449
  assumes "\<And>i. i \<in> Basis \<Longrightarrow> a \<bullet> i \<le> b \<bullet> i"
hoelzl@59453
   450
  assumes continuous: "continuous_on (cbox a b) f"
hoelzl@59453
   451
  shows "(\<lambda>x. f (clamp a b x)) \<in> bcontfun"
hoelzl@59453
   452
proof -
hoelzl@59453
   453
  from compact_continuous_image[OF continuous compact_cbox[of a b], THEN compact_imp_bounded]
hoelzl@59453
   454
  have "bounded (f ` (cbox a b))" .
hoelzl@59453
   455
  then obtain c where f_bound: "\<forall>x\<in>f ` cbox a b. norm x \<le> c" by (auto simp add: bounded_pos)
hoelzl@59453
   456
  show "(\<lambda>x. f (clamp a b x)) \<in> bcontfun"
hoelzl@59453
   457
  proof (intro bcontfun_normI)
hoelzl@59453
   458
    fix x
hoelzl@59453
   459
    from clamp_in_interval[OF assms(1), of x] f_bound
hoelzl@59453
   460
    show "norm (f (clamp a b x)) \<le> c" by (simp add: ext_cont_def)
hoelzl@59453
   461
  qed (simp add: clamp_continuous_on assms)
hoelzl@59453
   462
qed
hoelzl@59453
   463
hoelzl@59453
   464
lemma integral_clamp:
hoelzl@59453
   465
  "integral {t0::real..clamp t0 t1 x} f =
hoelzl@59453
   466
    (if x < t0 then 0 else if x \<le> t1 then integral {t0..x} f else integral {t0..t1} f)"
hoelzl@59453
   467
  by (auto simp: clamp_def)
hoelzl@59453
   468
hoelzl@59453
   469
hoelzl@59453
   470
declare [[coercion Rep_bcontfun]]
hoelzl@59453
   471
hoelzl@59453
   472
lemma ext_cont_cancel[simp]:
hoelzl@59453
   473
  fixes x a b::"'a::euclidean_space"
hoelzl@59453
   474
  assumes x: "x \<in> cbox a b"
hoelzl@59453
   475
  assumes "continuous_on (cbox a b) f"
hoelzl@59453
   476
  shows "ext_cont f a b x = f x"
hoelzl@59453
   477
  using assms
hoelzl@59453
   478
  unfolding ext_cont_def
hoelzl@59453
   479
proof (subst Abs_bcontfun_inverse[OF clamp_bcontfun])
hoelzl@59453
   480
  show "f (clamp a b x) = f x"
hoelzl@59453
   481
    using x unfolding clamp_def mem_box
hoelzl@59453
   482
    by (intro arg_cong[where f=f] euclidean_eqI[where 'a='a]) (simp add: not_less)
hoelzl@59453
   483
qed (auto simp: cbox_def)
hoelzl@59453
   484
hoelzl@59453
   485
lemma ext_cont_cong:
hoelzl@59453
   486
  assumes "t0 = s0"
hoelzl@59453
   487
  assumes "t1 = s1"
hoelzl@59453
   488
  assumes "\<And>t. t \<in> (cbox t0 t1) \<Longrightarrow> f t = g t"
hoelzl@59453
   489
  assumes "continuous_on (cbox t0 t1) f"
hoelzl@59453
   490
  assumes "continuous_on (cbox s0 s1) g"
hoelzl@59453
   491
  assumes ord: "\<And>i. i \<in> Basis \<Longrightarrow> t0 \<bullet> i \<le> t1 \<bullet> i"
hoelzl@59453
   492
  shows "ext_cont f t0 t1 = ext_cont g s0 s1"
hoelzl@59453
   493
  unfolding assms ext_cont_def
hoelzl@59453
   494
  using assms clamp_in_interval[OF ord]
hoelzl@59453
   495
  by (subst Rep_bcontfun_inject[symmetric]) simp
hoelzl@59453
   496
hoelzl@59453
   497
end