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