src/HOL/Lim.thy
author huffman
Fri May 29 09:22:56 2009 -0700 (2009-05-29)
changeset 31338 d41a8ba25b67
parent 31336 e17f13cd1280
child 31349 2261c8781f73
permissions -rw-r--r--
generalize constants from Lim.thy to class metric_space
paulson@10751
     1
(*  Title       : Lim.thy
paulson@10751
     2
    Author      : Jacques D. Fleuriot
paulson@10751
     3
    Copyright   : 1998  University of Cambridge
paulson@14477
     4
    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
paulson@10751
     5
*)
paulson@10751
     6
huffman@21165
     7
header{* Limits and Continuity *}
paulson@10751
     8
nipkow@15131
     9
theory Lim
haftmann@29197
    10
imports SEQ
nipkow@15131
    11
begin
paulson@14477
    12
huffman@22641
    13
text{*Standard Definitions*}
paulson@10751
    14
wenzelm@19765
    15
definition
huffman@31338
    16
  LIM :: "['a::metric_space \<Rightarrow> 'b::metric_space, 'a, 'b] \<Rightarrow> bool"
wenzelm@21404
    17
        ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60) where
haftmann@28562
    18
  [code del]: "f -- a --> L =
huffman@31338
    19
     (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & dist x a < s
huffman@31338
    20
        --> dist (f x) L < r)"
paulson@10751
    21
wenzelm@21404
    22
definition
huffman@31338
    23
  isCont :: "['a::metric_space \<Rightarrow> 'b::metric_space, 'a] \<Rightarrow> bool" where
wenzelm@19765
    24
  "isCont f a = (f -- a --> (f a))"
paulson@10751
    25
wenzelm@21404
    26
definition
huffman@31338
    27
  isUCont :: "['a::metric_space \<Rightarrow> 'b::metric_space] \<Rightarrow> bool" where
huffman@31338
    28
  [code del]: "isUCont f = (\<forall>r>0. \<exists>s>0. \<forall>x y. dist x y < s \<longrightarrow> dist (f x) (f y) < r)"
paulson@10751
    29
paulson@10751
    30
huffman@20755
    31
subsection {* Limits of Functions *}
paulson@14477
    32
huffman@31338
    33
lemma metric_LIM_I:
huffman@31338
    34
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r)
huffman@31338
    35
    \<Longrightarrow> f -- a --> L"
huffman@31338
    36
by (simp add: LIM_def)
huffman@31338
    37
huffman@31338
    38
lemma metric_LIM_D:
huffman@31338
    39
  "\<lbrakk>f -- a --> L; 0 < r\<rbrakk>
huffman@31338
    40
    \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r"
huffman@31338
    41
by (simp add: LIM_def)
paulson@14477
    42
paulson@14477
    43
lemma LIM_eq:
huffman@31338
    44
  fixes a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
huffman@31338
    45
  shows "f -- a --> L =
huffman@20561
    46
     (\<forall>r>0.\<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r)"
huffman@31338
    47
by (simp add: LIM_def dist_norm)
paulson@14477
    48
huffman@20552
    49
lemma LIM_I:
huffman@31338
    50
  fixes a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
huffman@31338
    51
  shows "(!!r. 0<r ==> \<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r)
huffman@20552
    52
      ==> f -- a --> L"
huffman@20552
    53
by (simp add: LIM_eq)
huffman@20552
    54
paulson@14477
    55
lemma LIM_D:
huffman@31338
    56
  fixes a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
huffman@31338
    57
  shows "[| f -- a --> L; 0<r |]
huffman@20561
    58
      ==> \<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r"
paulson@14477
    59
by (simp add: LIM_eq)
paulson@14477
    60
huffman@31338
    61
lemma LIM_offset:
huffman@31338
    62
  fixes a :: "'a::real_normed_vector" and L :: "'b::metric_space"
huffman@31338
    63
  shows "f -- a --> L \<Longrightarrow> (\<lambda>x. f (x + k)) -- a - k --> L"
huffman@31338
    64
unfolding LIM_def dist_norm
huffman@31338
    65
apply clarify
huffman@31338
    66
apply (drule_tac x="r" in spec, safe)
huffman@20756
    67
apply (rule_tac x="s" in exI, safe)
huffman@20756
    68
apply (drule_tac x="x + k" in spec)
nipkow@29667
    69
apply (simp add: algebra_simps)
huffman@20756
    70
done
huffman@20756
    71
huffman@31338
    72
lemma LIM_offset_zero:
huffman@31338
    73
  fixes a :: "'a::real_normed_vector" and L :: "'b::metric_space"
huffman@31338
    74
  shows "f -- a --> L \<Longrightarrow> (\<lambda>h. f (a + h)) -- 0 --> L"
huffman@21239
    75
by (drule_tac k="a" in LIM_offset, simp add: add_commute)
huffman@21239
    76
huffman@31338
    77
lemma LIM_offset_zero_cancel:
huffman@31338
    78
  fixes a :: "'a::real_normed_vector" and L :: "'b::metric_space"
huffman@31338
    79
  shows "(\<lambda>h. f (a + h)) -- 0 --> L \<Longrightarrow> f -- a --> L"
huffman@21239
    80
by (drule_tac k="- a" in LIM_offset, simp)
huffman@21239
    81
paulson@15228
    82
lemma LIM_const [simp]: "(%x. k) -- x --> k"
paulson@14477
    83
by (simp add: LIM_def)
paulson@14477
    84
paulson@14477
    85
lemma LIM_add:
huffman@31338
    86
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
paulson@14477
    87
  assumes f: "f -- a --> L" and g: "g -- a --> M"
huffman@31338
    88
  shows "(\<lambda>x. f x + g x) -- a --> (L + M)"
huffman@31338
    89
proof (rule metric_LIM_I)
paulson@14477
    90
  fix r :: real
huffman@20409
    91
  assume r: "0 < r"
huffman@31338
    92
  from metric_LIM_D [OF f half_gt_zero [OF r]]
paulson@14477
    93
  obtain fs
paulson@14477
    94
    where fs:    "0 < fs"
huffman@31338
    95
      and fs_lt: "\<forall>x. x \<noteq> a \<and> dist x a < fs \<longrightarrow> dist (f x) L < r/2"
paulson@14477
    96
  by blast
huffman@31338
    97
  from metric_LIM_D [OF g half_gt_zero [OF r]]
paulson@14477
    98
  obtain gs
paulson@14477
    99
    where gs:    "0 < gs"
huffman@31338
   100
      and gs_lt: "\<forall>x. x \<noteq> a \<and> dist x a < gs \<longrightarrow> dist (g x) M < r/2"
paulson@14477
   101
  by blast
huffman@31338
   102
  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x + g x) (L + M) < r"
paulson@14477
   103
  proof (intro exI conjI strip)
paulson@14477
   104
    show "0 < min fs gs"  by (simp add: fs gs)
huffman@20561
   105
    fix x :: 'a
huffman@31338
   106
    assume "x \<noteq> a \<and> dist x a < min fs gs"
huffman@31338
   107
    hence "x \<noteq> a \<and> dist x a < fs \<and> dist x a < gs" by simp
paulson@14477
   108
    with fs_lt gs_lt
huffman@31338
   109
    have "dist (f x) L < r/2" and "dist (g x) M < r/2" by blast+
huffman@31338
   110
    hence "dist (f x) L + dist (g x) M < r" by arith
huffman@31338
   111
    thus "dist (f x + g x) (L + M) < r"
huffman@31338
   112
      unfolding dist_norm
huffman@20552
   113
      by (blast intro: norm_diff_triangle_ineq order_le_less_trans)
paulson@14477
   114
  qed
paulson@14477
   115
qed
paulson@14477
   116
huffman@21257
   117
lemma LIM_add_zero:
huffman@31338
   118
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   119
  shows "\<lbrakk>f -- a --> 0; g -- a --> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. f x + g x) -- a --> 0"
huffman@21257
   120
by (drule (1) LIM_add, simp)
huffman@21257
   121
huffman@20552
   122
lemma minus_diff_minus:
huffman@20552
   123
  fixes a b :: "'a::ab_group_add"
huffman@20552
   124
  shows "(- a) - (- b) = - (a - b)"
huffman@20552
   125
by simp
huffman@20552
   126
huffman@31338
   127
lemma LIM_minus:
huffman@31338
   128
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   129
  shows "f -- a --> L \<Longrightarrow> (\<lambda>x. - f x) -- a --> - L"
huffman@31338
   130
by (simp only: LIM_def dist_norm minus_diff_minus norm_minus_cancel)
paulson@14477
   131
huffman@31338
   132
(* TODO: delete *)
paulson@14477
   133
lemma LIM_add_minus:
huffman@31338
   134
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   135
  shows "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
huffman@20552
   136
by (intro LIM_add LIM_minus)
paulson@14477
   137
paulson@14477
   138
lemma LIM_diff:
huffman@31338
   139
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   140
  shows "\<lbrakk>f -- x --> l; g -- x --> m\<rbrakk> \<Longrightarrow> (\<lambda>x. f x - g x) -- x --> l - m"
huffman@20552
   141
by (simp only: diff_minus LIM_add LIM_minus)
paulson@14477
   142
huffman@31338
   143
lemma LIM_zero:
huffman@31338
   144
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   145
  shows "f -- a --> l \<Longrightarrow> (\<lambda>x. f x - l) -- a --> 0"
huffman@31338
   146
by (simp add: LIM_def dist_norm)
huffman@21239
   147
huffman@31338
   148
lemma LIM_zero_cancel:
huffman@31338
   149
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   150
  shows "(\<lambda>x. f x - l) -- a --> 0 \<Longrightarrow> f -- a --> l"
huffman@31338
   151
by (simp add: LIM_def dist_norm)
huffman@21239
   152
huffman@31338
   153
lemma LIM_zero_iff:
huffman@31338
   154
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   155
  shows "(\<lambda>x. f x - l) -- a --> 0 = f -- a --> l"
huffman@31338
   156
by (simp add: LIM_def dist_norm)
huffman@21399
   157
huffman@31338
   158
lemma metric_LIM_imp_LIM:
huffman@21257
   159
  assumes f: "f -- a --> l"
huffman@31338
   160
  assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> dist (g x) m \<le> dist (f x) l"
huffman@21257
   161
  shows "g -- a --> m"
huffman@31338
   162
apply (rule metric_LIM_I, drule metric_LIM_D [OF f], safe)
huffman@21257
   163
apply (rule_tac x="s" in exI, safe)
huffman@21257
   164
apply (drule_tac x="x" in spec, safe)
huffman@21257
   165
apply (erule (1) order_le_less_trans [OF le])
huffman@21257
   166
done
huffman@21257
   167
huffman@31338
   168
lemma LIM_imp_LIM:
huffman@31338
   169
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   170
  fixes g :: "'a::metric_space \<Rightarrow> 'c::real_normed_vector"
huffman@31338
   171
  assumes f: "f -- a --> l"
huffman@31338
   172
  assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> norm (g x - m) \<le> norm (f x - l)"
huffman@31338
   173
  shows "g -- a --> m"
huffman@31338
   174
apply (rule metric_LIM_imp_LIM [OF f])
huffman@31338
   175
apply (simp add: dist_norm le)
huffman@31338
   176
done
huffman@31338
   177
huffman@31338
   178
lemma LIM_norm:
huffman@31338
   179
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   180
  shows "f -- a --> l \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> norm l"
huffman@21257
   181
by (erule LIM_imp_LIM, simp add: norm_triangle_ineq3)
huffman@21257
   182
huffman@31338
   183
lemma LIM_norm_zero:
huffman@31338
   184
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   185
  shows "f -- a --> 0 \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> 0"
huffman@21257
   186
by (drule LIM_norm, simp)
huffman@21257
   187
huffman@31338
   188
lemma LIM_norm_zero_cancel:
huffman@31338
   189
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   190
  shows "(\<lambda>x. norm (f x)) -- a --> 0 \<Longrightarrow> f -- a --> 0"
huffman@21257
   191
by (erule LIM_imp_LIM, simp)
huffman@21257
   192
huffman@31338
   193
lemma LIM_norm_zero_iff:
huffman@31338
   194
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   195
  shows "(\<lambda>x. norm (f x)) -- a --> 0 = f -- a --> 0"
huffman@21399
   196
by (rule iffI [OF LIM_norm_zero_cancel LIM_norm_zero])
huffman@21399
   197
huffman@22627
   198
lemma LIM_rabs: "f -- a --> (l::real) \<Longrightarrow> (\<lambda>x. \<bar>f x\<bar>) -- a --> \<bar>l\<bar>"
huffman@22627
   199
by (fold real_norm_def, rule LIM_norm)
huffman@22627
   200
huffman@22627
   201
lemma LIM_rabs_zero: "f -- a --> (0::real) \<Longrightarrow> (\<lambda>x. \<bar>f x\<bar>) -- a --> 0"
huffman@22627
   202
by (fold real_norm_def, rule LIM_norm_zero)
huffman@22627
   203
huffman@22627
   204
lemma LIM_rabs_zero_cancel: "(\<lambda>x. \<bar>f x\<bar>) -- a --> (0::real) \<Longrightarrow> f -- a --> 0"
huffman@22627
   205
by (fold real_norm_def, rule LIM_norm_zero_cancel)
huffman@22627
   206
huffman@22627
   207
lemma LIM_rabs_zero_iff: "(\<lambda>x. \<bar>f x\<bar>) -- a --> (0::real) = f -- a --> 0"
huffman@22627
   208
by (fold real_norm_def, rule LIM_norm_zero_iff)
huffman@22627
   209
huffman@20561
   210
lemma LIM_const_not_eq:
huffman@23076
   211
  fixes a :: "'a::real_normed_algebra_1"
huffman@23076
   212
  shows "k \<noteq> L \<Longrightarrow> \<not> (\<lambda>x. k) -- a --> L"
huffman@31338
   213
apply (simp add: LIM_def)
huffman@31338
   214
apply (rule_tac x="dist k L" in exI, simp add: zero_less_dist_iff, safe)
huffman@31338
   215
apply (rule_tac x="a + of_real (s/2)" in exI, simp add: dist_norm)
huffman@20552
   216
done
paulson@14477
   217
huffman@21786
   218
lemmas LIM_not_zero = LIM_const_not_eq [where L = 0]
huffman@21786
   219
huffman@20561
   220
lemma LIM_const_eq:
huffman@23076
   221
  fixes a :: "'a::real_normed_algebra_1"
huffman@23076
   222
  shows "(\<lambda>x. k) -- a --> L \<Longrightarrow> k = L"
paulson@14477
   223
apply (rule ccontr)
kleing@19023
   224
apply (blast dest: LIM_const_not_eq)
paulson@14477
   225
done
paulson@14477
   226
huffman@20561
   227
lemma LIM_unique:
huffman@31338
   228
  fixes a :: "'a::real_normed_algebra_1" -- {* TODO: find a more appropriate class *}
huffman@23076
   229
  shows "\<lbrakk>f -- a --> L; f -- a --> M\<rbrakk> \<Longrightarrow> L = M"
huffman@31338
   230
apply (rule ccontr)
huffman@31338
   231
apply (drule_tac r="dist L M / 2" in metric_LIM_D, simp add: zero_less_dist_iff)
huffman@31338
   232
apply (drule_tac r="dist L M / 2" in metric_LIM_D, simp add: zero_less_dist_iff)
huffman@31338
   233
apply (clarify, rename_tac r s)
huffman@31338
   234
apply (subgoal_tac "min r s \<noteq> 0")
huffman@31338
   235
apply (subgoal_tac "dist L M < dist L M / 2 + dist L M / 2", simp)
huffman@31338
   236
apply (subgoal_tac "dist L M \<le> dist (f (a + of_real (min r s / 2))) L +
huffman@31338
   237
                               dist (f (a + of_real (min r s / 2))) M")
huffman@31338
   238
apply (erule le_less_trans, rule add_strict_mono)
huffman@31338
   239
apply (drule spec, erule mp, simp add: dist_norm)
huffman@31338
   240
apply (drule spec, erule mp, simp add: dist_norm)
huffman@31338
   241
apply (subst dist_commute, rule dist_triangle)
huffman@31338
   242
apply simp
paulson@14477
   243
done
paulson@14477
   244
huffman@23069
   245
lemma LIM_ident [simp]: "(\<lambda>x. x) -- a --> a"
paulson@14477
   246
by (auto simp add: LIM_def)
paulson@14477
   247
paulson@14477
   248
text{*Limits are equal for functions equal except at limit point*}
paulson@14477
   249
lemma LIM_equal:
paulson@14477
   250
     "[| \<forall>x. x \<noteq> a --> (f x = g x) |] ==> (f -- a --> l) = (g -- a --> l)"
paulson@14477
   251
by (simp add: LIM_def)
paulson@14477
   252
huffman@20796
   253
lemma LIM_cong:
huffman@20796
   254
  "\<lbrakk>a = b; \<And>x. x \<noteq> b \<Longrightarrow> f x = g x; l = m\<rbrakk>
huffman@21399
   255
   \<Longrightarrow> ((\<lambda>x. f x) -- a --> l) = ((\<lambda>x. g x) -- b --> m)"
huffman@20796
   256
by (simp add: LIM_def)
huffman@20796
   257
huffman@31338
   258
lemma metric_LIM_equal2:
huffman@21282
   259
  assumes 1: "0 < R"
huffman@31338
   260
  assumes 2: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < R\<rbrakk> \<Longrightarrow> f x = g x"
huffman@21282
   261
  shows "g -- a --> l \<Longrightarrow> f -- a --> l"
huffman@21282
   262
apply (unfold LIM_def, safe)
huffman@21282
   263
apply (drule_tac x="r" in spec, safe)
huffman@21282
   264
apply (rule_tac x="min s R" in exI, safe)
huffman@21282
   265
apply (simp add: 1)
huffman@21282
   266
apply (simp add: 2)
huffman@21282
   267
done
huffman@21282
   268
huffman@31338
   269
lemma LIM_equal2:
huffman@31338
   270
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::metric_space"
huffman@31338
   271
  assumes 1: "0 < R"
huffman@31338
   272
  assumes 2: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < R\<rbrakk> \<Longrightarrow> f x = g x"
huffman@31338
   273
  shows "g -- a --> l \<Longrightarrow> f -- a --> l"
huffman@31338
   274
apply (unfold LIM_def dist_norm, safe)
huffman@31338
   275
apply (drule_tac x="r" in spec, safe)
huffman@31338
   276
apply (rule_tac x="min s R" in exI, safe)
huffman@31338
   277
apply (simp add: 1)
huffman@31338
   278
apply (simp add: 2)
huffman@31338
   279
done
huffman@31338
   280
huffman@31338
   281
text{*Two uses in Transcendental.ML*}
paulson@14477
   282
lemma LIM_trans:
huffman@31338
   283
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   284
  shows "[| (%x. f(x) + -g(x)) -- a --> 0;  g -- a --> l |] ==> f -- a --> l"
paulson@14477
   285
apply (drule LIM_add, assumption)
paulson@14477
   286
apply (auto simp add: add_assoc)
paulson@14477
   287
done
paulson@14477
   288
huffman@21239
   289
lemma LIM_compose:
huffman@21239
   290
  assumes g: "g -- l --> g l"
huffman@21239
   291
  assumes f: "f -- a --> l"
huffman@21239
   292
  shows "(\<lambda>x. g (f x)) -- a --> g l"
huffman@31338
   293
proof (rule metric_LIM_I)
huffman@21239
   294
  fix r::real assume r: "0 < r"
huffman@21239
   295
  obtain s where s: "0 < s"
huffman@31338
   296
    and less_r: "\<And>y. \<lbrakk>y \<noteq> l; dist y l < s\<rbrakk> \<Longrightarrow> dist (g y) (g l) < r"
huffman@31338
   297
    using metric_LIM_D [OF g r] by fast
huffman@21239
   298
  obtain t where t: "0 < t"
huffman@31338
   299
    and less_s: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < t\<rbrakk> \<Longrightarrow> dist (f x) l < s"
huffman@31338
   300
    using metric_LIM_D [OF f s] by fast
huffman@21239
   301
huffman@31338
   302
  show "\<exists>t>0. \<forall>x. x \<noteq> a \<and> dist x a < t \<longrightarrow> dist (g (f x)) (g l) < r"
huffman@21239
   303
  proof (rule exI, safe)
huffman@21239
   304
    show "0 < t" using t .
huffman@21239
   305
  next
huffman@31338
   306
    fix x assume "x \<noteq> a" and "dist x a < t"
huffman@31338
   307
    hence "dist (f x) l < s" by (rule less_s)
huffman@31338
   308
    thus "dist (g (f x)) (g l) < r"
huffman@21239
   309
      using r less_r by (case_tac "f x = l", simp_all)
huffman@21239
   310
  qed
huffman@21239
   311
qed
huffman@21239
   312
huffman@31338
   313
lemma metric_LIM_compose2:
huffman@31338
   314
  assumes f: "f -- a --> b"
huffman@31338
   315
  assumes g: "g -- b --> c"
huffman@31338
   316
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> b"
huffman@31338
   317
  shows "(\<lambda>x. g (f x)) -- a --> c"
huffman@31338
   318
proof (rule metric_LIM_I)
huffman@31338
   319
  fix r :: real
huffman@31338
   320
  assume r: "0 < r"
huffman@31338
   321
  obtain s where s: "0 < s"
huffman@31338
   322
    and less_r: "\<And>y. \<lbrakk>y \<noteq> b; dist y b < s\<rbrakk> \<Longrightarrow> dist (g y) c < r"
huffman@31338
   323
    using metric_LIM_D [OF g r] by fast
huffman@31338
   324
  obtain t where t: "0 < t"
huffman@31338
   325
    and less_s: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < t\<rbrakk> \<Longrightarrow> dist (f x) b < s"
huffman@31338
   326
    using metric_LIM_D [OF f s] by fast
huffman@31338
   327
  obtain d where d: "0 < d"
huffman@31338
   328
    and neq_b: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < d\<rbrakk> \<Longrightarrow> f x \<noteq> b"
huffman@31338
   329
    using inj by fast
huffman@31338
   330
huffman@31338
   331
  show "\<exists>t>0. \<forall>x. x \<noteq> a \<and> dist x a < t \<longrightarrow> dist (g (f x)) c < r"
huffman@31338
   332
  proof (safe intro!: exI)
huffman@31338
   333
    show "0 < min d t" using d t by simp
huffman@31338
   334
  next
huffman@31338
   335
    fix x
huffman@31338
   336
    assume "x \<noteq> a" and "dist x a < min d t"
huffman@31338
   337
    hence "f x \<noteq> b" and "dist (f x) b < s"
huffman@31338
   338
      using neq_b less_s by simp_all
huffman@31338
   339
    thus "dist (g (f x)) c < r"
huffman@31338
   340
      by (rule less_r)
huffman@31338
   341
  qed
huffman@31338
   342
qed
huffman@31338
   343
huffman@23040
   344
lemma LIM_compose2:
huffman@31338
   345
  fixes a :: "'a::real_normed_vector"
huffman@23040
   346
  assumes f: "f -- a --> b"
huffman@23040
   347
  assumes g: "g -- b --> c"
huffman@23040
   348
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < d \<longrightarrow> f x \<noteq> b"
huffman@23040
   349
  shows "(\<lambda>x. g (f x)) -- a --> c"
huffman@31338
   350
by (rule metric_LIM_compose2 [OF f g inj [folded dist_norm]])
huffman@23040
   351
huffman@21239
   352
lemma LIM_o: "\<lbrakk>g -- l --> g l; f -- a --> l\<rbrakk> \<Longrightarrow> (g \<circ> f) -- a --> g l"
huffman@21239
   353
unfolding o_def by (rule LIM_compose)
huffman@21239
   354
huffman@21282
   355
lemma real_LIM_sandwich_zero:
huffman@31338
   356
  fixes f g :: "'a::metric_space \<Rightarrow> real"
huffman@21282
   357
  assumes f: "f -- a --> 0"
huffman@21282
   358
  assumes 1: "\<And>x. x \<noteq> a \<Longrightarrow> 0 \<le> g x"
huffman@21282
   359
  assumes 2: "\<And>x. x \<noteq> a \<Longrightarrow> g x \<le> f x"
huffman@21282
   360
  shows "g -- a --> 0"
huffman@21282
   361
proof (rule LIM_imp_LIM [OF f])
huffman@21282
   362
  fix x assume x: "x \<noteq> a"
huffman@21282
   363
  have "norm (g x - 0) = g x" by (simp add: 1 x)
huffman@21282
   364
  also have "g x \<le> f x" by (rule 2 [OF x])
huffman@21282
   365
  also have "f x \<le> \<bar>f x\<bar>" by (rule abs_ge_self)
huffman@21282
   366
  also have "\<bar>f x\<bar> = norm (f x - 0)" by simp
huffman@21282
   367
  finally show "norm (g x - 0) \<le> norm (f x - 0)" .
huffman@21282
   368
qed
huffman@21282
   369
huffman@22442
   370
text {* Bounded Linear Operators *}
huffman@21282
   371
huffman@21282
   372
lemma (in bounded_linear) cont: "f -- a --> f a"
huffman@21282
   373
proof (rule LIM_I)
huffman@21282
   374
  fix r::real assume r: "0 < r"
huffman@21282
   375
  obtain K where K: "0 < K" and norm_le: "\<And>x. norm (f x) \<le> norm x * K"
huffman@21282
   376
    using pos_bounded by fast
huffman@21282
   377
  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - f a) < r"
huffman@21282
   378
  proof (rule exI, safe)
huffman@21282
   379
    from r K show "0 < r / K" by (rule divide_pos_pos)
huffman@21282
   380
  next
huffman@21282
   381
    fix x assume x: "norm (x - a) < r / K"
huffman@21282
   382
    have "norm (f x - f a) = norm (f (x - a))" by (simp only: diff)
huffman@21282
   383
    also have "\<dots> \<le> norm (x - a) * K" by (rule norm_le)
huffman@21282
   384
    also from K x have "\<dots> < r" by (simp only: pos_less_divide_eq)
huffman@21282
   385
    finally show "norm (f x - f a) < r" .
huffman@21282
   386
  qed
huffman@21282
   387
qed
huffman@21282
   388
huffman@21282
   389
lemma (in bounded_linear) LIM:
huffman@21282
   390
  "g -- a --> l \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> f l"
huffman@21282
   391
by (rule LIM_compose [OF cont])
huffman@21282
   392
huffman@21282
   393
lemma (in bounded_linear) LIM_zero:
huffman@21282
   394
  "g -- a --> 0 \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> 0"
huffman@21282
   395
by (drule LIM, simp only: zero)
huffman@21282
   396
huffman@22442
   397
text {* Bounded Bilinear Operators *}
huffman@21282
   398
huffman@21282
   399
lemma (in bounded_bilinear) LIM_prod_zero:
huffman@31338
   400
  fixes a :: "'d::metric_space"
huffman@21282
   401
  assumes f: "f -- a --> 0"
huffman@21282
   402
  assumes g: "g -- a --> 0"
huffman@21282
   403
  shows "(\<lambda>x. f x ** g x) -- a --> 0"
huffman@31338
   404
proof (rule metric_LIM_I, unfold dist_norm)
huffman@21282
   405
  fix r::real assume r: "0 < r"
huffman@21282
   406
  obtain K where K: "0 < K"
huffman@21282
   407
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@21282
   408
    using pos_bounded by fast
huffman@21282
   409
  from K have K': "0 < inverse K"
huffman@21282
   410
    by (rule positive_imp_inverse_positive)
huffman@21282
   411
  obtain s where s: "0 < s"
huffman@31338
   412
    and norm_f: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < s\<rbrakk> \<Longrightarrow> norm (f x) < r"
huffman@31338
   413
    using metric_LIM_D [OF f r, unfolded dist_norm] by auto
huffman@21282
   414
  obtain t where t: "0 < t"
huffman@31338
   415
    and norm_g: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < t\<rbrakk> \<Longrightarrow> norm (g x) < inverse K"
huffman@31338
   416
    using metric_LIM_D [OF g K', unfolded dist_norm] by auto
huffman@31338
   417
  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> norm (f x ** g x - 0) < r"
huffman@21282
   418
  proof (rule exI, safe)
huffman@21282
   419
    from s t show "0 < min s t" by simp
huffman@21282
   420
  next
huffman@21282
   421
    fix x assume x: "x \<noteq> a"
huffman@31338
   422
    assume "dist x a < min s t"
huffman@31338
   423
    hence xs: "dist x a < s" and xt: "dist x a < t" by simp_all
huffman@21282
   424
    from x xs have 1: "norm (f x) < r" by (rule norm_f)
huffman@21282
   425
    from x xt have 2: "norm (g x) < inverse K" by (rule norm_g)
huffman@21282
   426
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K" by (rule norm_le)
huffman@21282
   427
    also from 1 2 K have "\<dots> < r * inverse K * K"
huffman@21282
   428
      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero)
huffman@21282
   429
    also from K have "r * inverse K * K = r" by simp
huffman@21282
   430
    finally show "norm (f x ** g x - 0) < r" by simp
huffman@21282
   431
  qed
huffman@21282
   432
qed
huffman@21282
   433
huffman@21282
   434
lemma (in bounded_bilinear) LIM_left_zero:
huffman@21282
   435
  "f -- a --> 0 \<Longrightarrow> (\<lambda>x. f x ** c) -- a --> 0"
huffman@21282
   436
by (rule bounded_linear.LIM_zero [OF bounded_linear_left])
huffman@21282
   437
huffman@21282
   438
lemma (in bounded_bilinear) LIM_right_zero:
huffman@21282
   439
  "f -- a --> 0 \<Longrightarrow> (\<lambda>x. c ** f x) -- a --> 0"
huffman@21282
   440
by (rule bounded_linear.LIM_zero [OF bounded_linear_right])
huffman@21282
   441
huffman@21282
   442
lemma (in bounded_bilinear) LIM:
huffman@21282
   443
  "\<lbrakk>f -- a --> L; g -- a --> M\<rbrakk> \<Longrightarrow> (\<lambda>x. f x ** g x) -- a --> L ** M"
huffman@21282
   444
apply (drule LIM_zero)
huffman@21282
   445
apply (drule LIM_zero)
huffman@21282
   446
apply (rule LIM_zero_cancel)
huffman@21282
   447
apply (subst prod_diff_prod)
huffman@21282
   448
apply (rule LIM_add_zero)
huffman@21282
   449
apply (rule LIM_add_zero)
huffman@21282
   450
apply (erule (1) LIM_prod_zero)
huffman@21282
   451
apply (erule LIM_left_zero)
huffman@21282
   452
apply (erule LIM_right_zero)
huffman@21282
   453
done
huffman@21282
   454
huffman@23127
   455
lemmas LIM_mult = mult.LIM
huffman@21282
   456
huffman@23127
   457
lemmas LIM_mult_zero = mult.LIM_prod_zero
huffman@21282
   458
huffman@23127
   459
lemmas LIM_mult_left_zero = mult.LIM_left_zero
huffman@21282
   460
huffman@23127
   461
lemmas LIM_mult_right_zero = mult.LIM_right_zero
huffman@21282
   462
huffman@23127
   463
lemmas LIM_scaleR = scaleR.LIM
huffman@21282
   464
huffman@23127
   465
lemmas LIM_of_real = of_real.LIM
huffman@22627
   466
huffman@22627
   467
lemma LIM_power:
huffman@31338
   468
  fixes f :: "'a::metric_space \<Rightarrow> 'b::{power,real_normed_algebra}"
huffman@22627
   469
  assumes f: "f -- a --> l"
huffman@22627
   470
  shows "(\<lambda>x. f x ^ n) -- a --> l ^ n"
huffman@30273
   471
by (induct n, simp, simp add: LIM_mult f)
huffman@22627
   472
huffman@22641
   473
subsubsection {* Derived theorems about @{term LIM} *}
huffman@22641
   474
huffman@22637
   475
lemma LIM_inverse_lemma:
huffman@22637
   476
  fixes x :: "'a::real_normed_div_algebra"
huffman@22637
   477
  assumes r: "0 < r"
huffman@22637
   478
  assumes x: "norm (x - 1) < min (1/2) (r/2)"
huffman@22637
   479
  shows "norm (inverse x - 1) < r"
huffman@22637
   480
proof -
huffman@22637
   481
  from r have r2: "0 < r/2" by simp
huffman@22637
   482
  from x have 0: "x \<noteq> 0" by clarsimp
huffman@22637
   483
  from x have x': "norm (1 - x) < min (1/2) (r/2)"
huffman@22637
   484
    by (simp only: norm_minus_commute)
huffman@22637
   485
  hence less1: "norm (1 - x) < r/2" by simp
huffman@22637
   486
  have "norm (1::'a) - norm x \<le> norm (1 - x)" by (rule norm_triangle_ineq2)
huffman@22637
   487
  also from x' have "norm (1 - x) < 1/2" by simp
huffman@22637
   488
  finally have "1/2 < norm x" by simp
huffman@22637
   489
  hence "inverse (norm x) < inverse (1/2)"
huffman@22637
   490
    by (rule less_imp_inverse_less, simp)
huffman@22637
   491
  hence less2: "norm (inverse x) < 2"
huffman@22637
   492
    by (simp add: nonzero_norm_inverse 0)
huffman@22637
   493
  from less1 less2 r2 norm_ge_zero
huffman@22637
   494
  have "norm (1 - x) * norm (inverse x) < (r/2) * 2"
huffman@22637
   495
    by (rule mult_strict_mono)
huffman@22637
   496
  thus "norm (inverse x - 1) < r"
huffman@22637
   497
    by (simp only: norm_mult [symmetric] left_diff_distrib, simp add: 0)
huffman@22637
   498
qed
huffman@22637
   499
huffman@22637
   500
lemma LIM_inverse_fun:
huffman@22637
   501
  assumes a: "a \<noteq> (0::'a::real_normed_div_algebra)"
huffman@22637
   502
  shows "inverse -- a --> inverse a"
huffman@22637
   503
proof (rule LIM_equal2)
huffman@22637
   504
  from a show "0 < norm a" by simp
huffman@22637
   505
next
huffman@22637
   506
  fix x assume "norm (x - a) < norm a"
huffman@22637
   507
  hence "x \<noteq> 0" by auto
huffman@22637
   508
  with a show "inverse x = inverse (inverse a * x) * inverse a"
huffman@22637
   509
    by (simp add: nonzero_inverse_mult_distrib
huffman@22637
   510
                  nonzero_imp_inverse_nonzero
huffman@22637
   511
                  nonzero_inverse_inverse_eq mult_assoc)
huffman@22637
   512
next
huffman@22637
   513
  have 1: "inverse -- 1 --> inverse (1::'a)"
huffman@22637
   514
    apply (rule LIM_I)
huffman@22637
   515
    apply (rule_tac x="min (1/2) (r/2)" in exI)
huffman@22637
   516
    apply (simp add: LIM_inverse_lemma)
huffman@22637
   517
    done
huffman@22637
   518
  have "(\<lambda>x. inverse a * x) -- a --> inverse a * a"
huffman@23069
   519
    by (intro LIM_mult LIM_ident LIM_const)
huffman@22637
   520
  hence "(\<lambda>x. inverse a * x) -- a --> 1"
huffman@22637
   521
    by (simp add: a)
huffman@22637
   522
  with 1 have "(\<lambda>x. inverse (inverse a * x)) -- a --> inverse 1"
huffman@22637
   523
    by (rule LIM_compose)
huffman@22637
   524
  hence "(\<lambda>x. inverse (inverse a * x)) -- a --> 1"
huffman@22637
   525
    by simp
huffman@22637
   526
  hence "(\<lambda>x. inverse (inverse a * x) * inverse a) -- a --> 1 * inverse a"
huffman@22637
   527
    by (intro LIM_mult LIM_const)
huffman@22637
   528
  thus "(\<lambda>x. inverse (inverse a * x) * inverse a) -- a --> inverse a"
huffman@22637
   529
    by simp
huffman@22637
   530
qed
huffman@22637
   531
huffman@22637
   532
lemma LIM_inverse:
huffman@22637
   533
  fixes L :: "'a::real_normed_div_algebra"
huffman@22637
   534
  shows "\<lbrakk>f -- a --> L; L \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. inverse (f x)) -- a --> inverse L"
huffman@22637
   535
by (rule LIM_inverse_fun [THEN LIM_compose])
huffman@22637
   536
huffman@29885
   537
lemma LIM_sgn:
huffman@31338
   538
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   539
  shows "\<lbrakk>f -- a --> l; l \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. sgn (f x)) -- a --> sgn l"
huffman@29885
   540
unfolding sgn_div_norm
huffman@29885
   541
by (simp add: LIM_scaleR LIM_inverse LIM_norm)
huffman@29885
   542
paulson@14477
   543
huffman@20755
   544
subsection {* Continuity *}
paulson@14477
   545
huffman@31338
   546
lemma LIM_isCont_iff:
huffman@31338
   547
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::metric_space"
huffman@31338
   548
  shows "(f -- a --> f a) = ((\<lambda>h. f (a + h)) -- 0 --> f a)"
huffman@21239
   549
by (rule iffI [OF LIM_offset_zero LIM_offset_zero_cancel])
huffman@21239
   550
huffman@31338
   551
lemma isCont_iff:
huffman@31338
   552
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::metric_space"
huffman@31338
   553
  shows "isCont f x = (\<lambda>h. f (x + h)) -- 0 --> f x"
huffman@21239
   554
by (simp add: isCont_def LIM_isCont_iff)
huffman@21239
   555
huffman@23069
   556
lemma isCont_ident [simp]: "isCont (\<lambda>x. x) a"
huffman@23069
   557
  unfolding isCont_def by (rule LIM_ident)
huffman@21239
   558
huffman@21786
   559
lemma isCont_const [simp]: "isCont (\<lambda>x. k) a"
huffman@21282
   560
  unfolding isCont_def by (rule LIM_const)
huffman@21239
   561
huffman@31338
   562
lemma isCont_norm:
huffman@31338
   563
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   564
  shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. norm (f x)) a"
huffman@21786
   565
  unfolding isCont_def by (rule LIM_norm)
huffman@21786
   566
huffman@22627
   567
lemma isCont_rabs: "isCont f a \<Longrightarrow> isCont (\<lambda>x. \<bar>f x :: real\<bar>) a"
huffman@22627
   568
  unfolding isCont_def by (rule LIM_rabs)
huffman@22627
   569
huffman@31338
   570
lemma isCont_add:
huffman@31338
   571
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   572
  shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x + g x) a"
huffman@21282
   573
  unfolding isCont_def by (rule LIM_add)
huffman@21239
   574
huffman@31338
   575
lemma isCont_minus:
huffman@31338
   576
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   577
  shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. - f x) a"
huffman@21282
   578
  unfolding isCont_def by (rule LIM_minus)
huffman@21239
   579
huffman@31338
   580
lemma isCont_diff:
huffman@31338
   581
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   582
  shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x - g x) a"
huffman@21282
   583
  unfolding isCont_def by (rule LIM_diff)
huffman@21239
   584
huffman@21239
   585
lemma isCont_mult:
huffman@31338
   586
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_algebra"
huffman@21786
   587
  shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x * g x) a"
huffman@21282
   588
  unfolding isCont_def by (rule LIM_mult)
huffman@21239
   589
huffman@21239
   590
lemma isCont_inverse:
huffman@31338
   591
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_div_algebra"
huffman@21786
   592
  shows "\<lbrakk>isCont f a; f a \<noteq> 0\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. inverse (f x)) a"
huffman@21282
   593
  unfolding isCont_def by (rule LIM_inverse)
huffman@21239
   594
huffman@21239
   595
lemma isCont_LIM_compose:
huffman@21239
   596
  "\<lbrakk>isCont g l; f -- a --> l\<rbrakk> \<Longrightarrow> (\<lambda>x. g (f x)) -- a --> g l"
huffman@21282
   597
  unfolding isCont_def by (rule LIM_compose)
huffman@21239
   598
huffman@31338
   599
lemma metric_isCont_LIM_compose2:
huffman@31338
   600
  assumes f [unfolded isCont_def]: "isCont f a"
huffman@31338
   601
  assumes g: "g -- f a --> l"
huffman@31338
   602
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> f a"
huffman@31338
   603
  shows "(\<lambda>x. g (f x)) -- a --> l"
huffman@31338
   604
by (rule metric_LIM_compose2 [OF f g inj])
huffman@31338
   605
huffman@23040
   606
lemma isCont_LIM_compose2:
huffman@31338
   607
  fixes a :: "'a::real_normed_vector"
huffman@23040
   608
  assumes f [unfolded isCont_def]: "isCont f a"
huffman@23040
   609
  assumes g: "g -- f a --> l"
huffman@23040
   610
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < d \<longrightarrow> f x \<noteq> f a"
huffman@23040
   611
  shows "(\<lambda>x. g (f x)) -- a --> l"
huffman@23040
   612
by (rule LIM_compose2 [OF f g inj])
huffman@23040
   613
huffman@21239
   614
lemma isCont_o2: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. g (f x)) a"
huffman@21282
   615
  unfolding isCont_def by (rule LIM_compose)
huffman@21239
   616
huffman@21239
   617
lemma isCont_o: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (g o f) a"
huffman@21282
   618
  unfolding o_def by (rule isCont_o2)
huffman@21282
   619
huffman@21282
   620
lemma (in bounded_linear) isCont: "isCont f a"
huffman@21282
   621
  unfolding isCont_def by (rule cont)
huffman@21282
   622
huffman@21282
   623
lemma (in bounded_bilinear) isCont:
huffman@21282
   624
  "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x ** g x) a"
huffman@21282
   625
  unfolding isCont_def by (rule LIM)
huffman@21282
   626
huffman@23127
   627
lemmas isCont_scaleR = scaleR.isCont
huffman@21239
   628
huffman@22627
   629
lemma isCont_of_real:
huffman@31338
   630
  "isCont f a \<Longrightarrow> isCont (\<lambda>x. of_real (f x)::'b::real_normed_algebra_1) a"
huffman@22627
   631
  unfolding isCont_def by (rule LIM_of_real)
huffman@22627
   632
huffman@22627
   633
lemma isCont_power:
huffman@31338
   634
  fixes f :: "'a::metric_space \<Rightarrow> 'b::{power,real_normed_algebra}"
huffman@22627
   635
  shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. f x ^ n) a"
huffman@22627
   636
  unfolding isCont_def by (rule LIM_power)
huffman@22627
   637
huffman@29885
   638
lemma isCont_sgn:
huffman@31338
   639
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@31338
   640
  shows "\<lbrakk>isCont f a; f a \<noteq> 0\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. sgn (f x)) a"
huffman@29885
   641
  unfolding isCont_def by (rule LIM_sgn)
huffman@29885
   642
huffman@20561
   643
lemma isCont_abs [simp]: "isCont abs (a::real)"
huffman@23069
   644
by (rule isCont_rabs [OF isCont_ident])
paulson@15228
   645
huffman@31338
   646
lemma isCont_setsum:
huffman@31338
   647
  fixes f :: "'a \<Rightarrow> 'b::metric_space \<Rightarrow> 'c::real_normed_vector"
huffman@31338
   648
  fixes A :: "'a set" assumes "finite A"
hoelzl@29803
   649
  shows "\<forall> i \<in> A. isCont (f i) x \<Longrightarrow> isCont (\<lambda> x. \<Sum> i \<in> A. f i x) x"
hoelzl@29803
   650
  using `finite A`
hoelzl@29803
   651
proof induct
hoelzl@29803
   652
  case (insert a F) show "isCont (\<lambda> x. \<Sum> i \<in> (insert a F). f i x) x" 
hoelzl@29803
   653
    unfolding setsum_insert[OF `finite F` `a \<notin> F`] by (rule isCont_add, auto simp add: insert)
hoelzl@29803
   654
qed auto
hoelzl@29803
   655
hoelzl@29803
   656
lemma LIM_less_bound: fixes f :: "real \<Rightarrow> real" assumes "b < x"
hoelzl@29803
   657
  and all_le: "\<forall> x' \<in> { b <..< x}. 0 \<le> f x'" and isCont: "isCont f x"
hoelzl@29803
   658
  shows "0 \<le> f x"
hoelzl@29803
   659
proof (rule ccontr)
hoelzl@29803
   660
  assume "\<not> 0 \<le> f x" hence "f x < 0" by auto
hoelzl@29803
   661
  hence "0 < - f x / 2" by auto
hoelzl@29803
   662
  from isCont[unfolded isCont_def, THEN LIM_D, OF this]
hoelzl@29803
   663
  obtain s where "s > 0" and s_D: "\<And>x'. \<lbrakk> x' \<noteq> x ; \<bar> x' - x \<bar> < s \<rbrakk> \<Longrightarrow> \<bar> f x' - f x \<bar> < - f x / 2" by auto
hoelzl@29803
   664
hoelzl@29803
   665
  let ?x = "x - min (s / 2) ((x - b) / 2)"
hoelzl@29803
   666
  have "?x < x" and "\<bar> ?x - x \<bar> < s"
hoelzl@29803
   667
    using `b < x` and `0 < s` by auto
hoelzl@29803
   668
  have "b < ?x"
hoelzl@29803
   669
  proof (cases "s < x - b")
hoelzl@29803
   670
    case True thus ?thesis using `0 < s` by auto
hoelzl@29803
   671
  next
hoelzl@29803
   672
    case False hence "s / 2 \<ge> (x - b) / 2" by auto
hoelzl@29803
   673
    from inf_absorb2[OF this, unfolded inf_real_def]
hoelzl@29803
   674
    have "?x = (x + b) / 2" by auto
hoelzl@29803
   675
    thus ?thesis using `b < x` by auto
hoelzl@29803
   676
  qed
hoelzl@29803
   677
  hence "0 \<le> f ?x" using all_le `?x < x` by auto
hoelzl@29803
   678
  moreover have "\<bar>f ?x - f x\<bar> < - f x / 2"
hoelzl@29803
   679
    using s_D[OF _ `\<bar> ?x - x \<bar> < s`] `?x < x` by auto
hoelzl@29803
   680
  hence "f ?x - f x < - f x / 2" by auto
hoelzl@29803
   681
  hence "f ?x < f x / 2" by auto
hoelzl@29803
   682
  hence "f ?x < 0" using `f x < 0` by auto
hoelzl@29803
   683
  thus False using `0 \<le> f ?x` by auto
hoelzl@29803
   684
qed
huffman@31338
   685
paulson@14477
   686
huffman@20755
   687
subsection {* Uniform Continuity *}
huffman@20755
   688
paulson@14477
   689
lemma isUCont_isCont: "isUCont f ==> isCont f x"
huffman@23012
   690
by (simp add: isUCont_def isCont_def LIM_def, force)
paulson@14477
   691
huffman@23118
   692
lemma isUCont_Cauchy:
huffman@23118
   693
  "\<lbrakk>isUCont f; Cauchy X\<rbrakk> \<Longrightarrow> Cauchy (\<lambda>n. f (X n))"
huffman@23118
   694
unfolding isUCont_def
huffman@31338
   695
apply (rule metric_CauchyI)
huffman@23118
   696
apply (drule_tac x=e in spec, safe)
huffman@31338
   697
apply (drule_tac e=s in metric_CauchyD, safe)
huffman@23118
   698
apply (rule_tac x=M in exI, simp)
huffman@23118
   699
done
huffman@23118
   700
huffman@23118
   701
lemma (in bounded_linear) isUCont: "isUCont f"
huffman@31338
   702
unfolding isUCont_def dist_norm
huffman@23118
   703
proof (intro allI impI)
huffman@23118
   704
  fix r::real assume r: "0 < r"
huffman@23118
   705
  obtain K where K: "0 < K" and norm_le: "\<And>x. norm (f x) \<le> norm x * K"
huffman@23118
   706
    using pos_bounded by fast
huffman@23118
   707
  show "\<exists>s>0. \<forall>x y. norm (x - y) < s \<longrightarrow> norm (f x - f y) < r"
huffman@23118
   708
  proof (rule exI, safe)
huffman@23118
   709
    from r K show "0 < r / K" by (rule divide_pos_pos)
huffman@23118
   710
  next
huffman@23118
   711
    fix x y :: 'a
huffman@23118
   712
    assume xy: "norm (x - y) < r / K"
huffman@23118
   713
    have "norm (f x - f y) = norm (f (x - y))" by (simp only: diff)
huffman@23118
   714
    also have "\<dots> \<le> norm (x - y) * K" by (rule norm_le)
huffman@23118
   715
    also from K xy have "\<dots> < r" by (simp only: pos_less_divide_eq)
huffman@23118
   716
    finally show "norm (f x - f y) < r" .
huffman@23118
   717
  qed
huffman@23118
   718
qed
huffman@23118
   719
huffman@23118
   720
lemma (in bounded_linear) Cauchy: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. f (X n))"
huffman@23118
   721
by (rule isUCont [THEN isUCont_Cauchy])
huffman@23118
   722
paulson@14477
   723
huffman@21165
   724
subsection {* Relation of LIM and LIMSEQ *}
kleing@19023
   725
kleing@19023
   726
lemma LIMSEQ_SEQ_conv1:
huffman@31338
   727
  fixes a :: "'a::metric_space"
huffman@21165
   728
  assumes X: "X -- a --> L"
kleing@19023
   729
  shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
huffman@31338
   730
proof (safe intro!: metric_LIMSEQ_I)
huffman@21165
   731
  fix S :: "nat \<Rightarrow> 'a"
huffman@21165
   732
  fix r :: real
huffman@21165
   733
  assume rgz: "0 < r"
huffman@21165
   734
  assume as: "\<forall>n. S n \<noteq> a"
huffman@21165
   735
  assume S: "S ----> a"
huffman@31338
   736
  from metric_LIM_D [OF X rgz] obtain s
huffman@21165
   737
    where sgz: "0 < s"
huffman@31338
   738
    and aux: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < s\<rbrakk> \<Longrightarrow> dist (X x) L < r"
huffman@21165
   739
    by fast
huffman@31338
   740
  from metric_LIMSEQ_D [OF S sgz]
huffman@31338
   741
  obtain no where "\<forall>n\<ge>no. dist (S n) a < s" by blast
huffman@31338
   742
  hence "\<forall>n\<ge>no. dist (X (S n)) L < r" by (simp add: aux as)
huffman@31338
   743
  thus "\<exists>no. \<forall>n\<ge>no. dist (X (S n)) L < r" ..
kleing@19023
   744
qed
kleing@19023
   745
huffman@31338
   746
kleing@19023
   747
lemma LIMSEQ_SEQ_conv2:
huffman@20561
   748
  fixes a :: real
kleing@19023
   749
  assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
kleing@19023
   750
  shows "X -- a --> L"
kleing@19023
   751
proof (rule ccontr)
kleing@19023
   752
  assume "\<not> (X -- a --> L)"
huffman@31338
   753
  hence "\<not> (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & norm (x - a) < s --> dist (X x) L < r)"
huffman@31338
   754
    unfolding LIM_def dist_norm .
huffman@31338
   755
  hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. \<not>(x \<noteq> a \<and> \<bar>x - a\<bar> < s --> dist (X x) L < r)" by simp
huffman@31338
   756
  hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x - a\<bar> < s \<and> dist (X x) L \<ge> r)" by (simp add: not_less)
huffman@31338
   757
  then obtain r where rdef: "r > 0 \<and> (\<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x - a\<bar> < s \<and> dist (X x) L \<ge> r))" by auto
kleing@19023
   758
huffman@31338
   759
  let ?F = "\<lambda>n::nat. SOME x. x\<noteq>a \<and> \<bar>x - a\<bar> < inverse (real (Suc n)) \<and> dist (X x) L \<ge> r"
huffman@31338
   760
  have "\<And>n. \<exists>x. x\<noteq>a \<and> \<bar>x - a\<bar> < inverse (real (Suc n)) \<and> dist (X x) L \<ge> r"
huffman@21165
   761
    using rdef by simp
huffman@31338
   762
  hence F: "\<And>n. ?F n \<noteq> a \<and> \<bar>?F n - a\<bar> < inverse (real (Suc n)) \<and> dist (X (?F n)) L \<ge> r"
huffman@21165
   763
    by (rule someI_ex)
huffman@21165
   764
  hence F1: "\<And>n. ?F n \<noteq> a"
huffman@21165
   765
    and F2: "\<And>n. \<bar>?F n - a\<bar> < inverse (real (Suc n))"
huffman@31338
   766
    and F3: "\<And>n. dist (X (?F n)) L \<ge> r"
huffman@21165
   767
    by fast+
huffman@21165
   768
kleing@19023
   769
  have "?F ----> a"
huffman@21165
   770
  proof (rule LIMSEQ_I, unfold real_norm_def)
kleing@19023
   771
      fix e::real
kleing@19023
   772
      assume "0 < e"
kleing@19023
   773
        (* choose no such that inverse (real (Suc n)) < e *)
huffman@23441
   774
      then have "\<exists>no. inverse (real (Suc no)) < e" by (rule reals_Archimedean)
kleing@19023
   775
      then obtain m where nodef: "inverse (real (Suc m)) < e" by auto
huffman@21165
   776
      show "\<exists>no. \<forall>n. no \<le> n --> \<bar>?F n - a\<bar> < e"
huffman@21165
   777
      proof (intro exI allI impI)
kleing@19023
   778
        fix n
kleing@19023
   779
        assume mlen: "m \<le> n"
huffman@21165
   780
        have "\<bar>?F n - a\<bar> < inverse (real (Suc n))"
huffman@21165
   781
          by (rule F2)
huffman@21165
   782
        also have "inverse (real (Suc n)) \<le> inverse (real (Suc m))"
huffman@23441
   783
          using mlen by auto
huffman@21165
   784
        also from nodef have
kleing@19023
   785
          "inverse (real (Suc m)) < e" .
huffman@21165
   786
        finally show "\<bar>?F n - a\<bar> < e" .
huffman@21165
   787
      qed
kleing@19023
   788
  qed
kleing@19023
   789
  
kleing@19023
   790
  moreover have "\<forall>n. ?F n \<noteq> a"
huffman@21165
   791
    by (rule allI) (rule F1)
huffman@21165
   792
kleing@19023
   793
  moreover from prems have "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L" by simp
kleing@19023
   794
  ultimately have "(\<lambda>n. X (?F n)) ----> L" by simp
kleing@19023
   795
  
kleing@19023
   796
  moreover have "\<not> ((\<lambda>n. X (?F n)) ----> L)"
kleing@19023
   797
  proof -
kleing@19023
   798
    {
kleing@19023
   799
      fix no::nat
kleing@19023
   800
      obtain n where "n = no + 1" by simp
kleing@19023
   801
      then have nolen: "no \<le> n" by simp
kleing@19023
   802
        (* We prove this by showing that for any m there is an n\<ge>m such that |X (?F n) - L| \<ge> r *)
huffman@31338
   803
      have "dist (X (?F n)) L \<ge> r"
huffman@21165
   804
        by (rule F3)
huffman@31338
   805
      with nolen have "\<exists>n. no \<le> n \<and> dist (X (?F n)) L \<ge> r" by fast
kleing@19023
   806
    }
huffman@31338
   807
    then have "(\<forall>no. \<exists>n. no \<le> n \<and> dist (X (?F n)) L \<ge> r)" by simp
huffman@31338
   808
    with rdef have "\<exists>e>0. (\<forall>no. \<exists>n. no \<le> n \<and> dist (X (?F n)) L \<ge> e)" by auto
huffman@31338
   809
    thus ?thesis by (unfold LIMSEQ_def, auto simp add: not_less)
kleing@19023
   810
  qed
kleing@19023
   811
  ultimately show False by simp
kleing@19023
   812
qed
kleing@19023
   813
kleing@19023
   814
lemma LIMSEQ_SEQ_conv:
huffman@20561
   815
  "(\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> (a::real) \<longrightarrow> (\<lambda>n. X (S n)) ----> L) =
huffman@20561
   816
   (X -- a --> L)"
kleing@19023
   817
proof
kleing@19023
   818
  assume "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
huffman@23441
   819
  thus "X -- a --> L" by (rule LIMSEQ_SEQ_conv2)
kleing@19023
   820
next
kleing@19023
   821
  assume "(X -- a --> L)"
huffman@23441
   822
  thus "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L" by (rule LIMSEQ_SEQ_conv1)
kleing@19023
   823
qed
kleing@19023
   824
paulson@10751
   825
end