src/HOL/Hyperreal/Lim.thy
author huffman
Thu Apr 12 01:53:02 2007 +0200 (2007-04-12)
changeset 22637 3f158760b68f
parent 22631 7ae5a6ab7bd6
child 22641 a5dc96fad632
permissions -rw-r--r--
new standard proof of lemma LIM_inverse
paulson@10751
     1
(*  Title       : Lim.thy
paulson@14477
     2
    ID          : $Id$
paulson@10751
     3
    Author      : Jacques D. Fleuriot
paulson@10751
     4
    Copyright   : 1998  University of Cambridge
paulson@14477
     5
    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
paulson@10751
     6
*)
paulson@10751
     7
huffman@21165
     8
header{* Limits and Continuity *}
paulson@10751
     9
nipkow@15131
    10
theory Lim
huffman@22631
    11
imports HSEQ
nipkow@15131
    12
begin
paulson@14477
    13
paulson@14477
    14
text{*Standard and Nonstandard Definitions*}
paulson@10751
    15
wenzelm@19765
    16
definition
huffman@20561
    17
  LIM :: "['a::real_normed_vector => 'b::real_normed_vector, 'a, 'b] => bool"
wenzelm@21404
    18
        ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60) where
wenzelm@19765
    19
  "f -- a --> L =
huffman@20563
    20
     (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & norm (x - a) < s
huffman@20563
    21
        --> norm (f x - L) < r)"
paulson@10751
    22
wenzelm@21404
    23
definition
huffman@20561
    24
  NSLIM :: "['a::real_normed_vector => 'b::real_normed_vector, 'a, 'b] => bool"
wenzelm@21404
    25
            ("((_)/ -- (_)/ --NS> (_))" [60, 0, 60] 60) where
huffman@20552
    26
  "f -- a --NS> L =
huffman@20552
    27
    (\<forall>x. (x \<noteq> star_of a & x @= star_of a --> ( *f* f) x @= star_of L))"
paulson@10751
    28
wenzelm@21404
    29
definition
wenzelm@21404
    30
  isCont :: "['a::real_normed_vector => 'b::real_normed_vector, 'a] => bool" where
wenzelm@19765
    31
  "isCont f a = (f -- a --> (f a))"
paulson@10751
    32
wenzelm@21404
    33
definition
wenzelm@21404
    34
  isNSCont :: "['a::real_normed_vector => 'b::real_normed_vector, 'a] => bool" where
paulson@15228
    35
    --{*NS definition dispenses with limit notions*}
huffman@20552
    36
  "isNSCont f a = (\<forall>y. y @= star_of a -->
huffman@20552
    37
         ( *f* f) y @= star_of (f a))"
paulson@10751
    38
wenzelm@21404
    39
definition
wenzelm@21404
    40
  isUCont :: "['a::real_normed_vector => 'b::real_normed_vector] => bool" where
huffman@20752
    41
  "isUCont f = (\<forall>r>0. \<exists>s>0. \<forall>x y. norm (x - y) < s \<longrightarrow> norm (f x - f y) < r)"
paulson@10751
    42
wenzelm@21404
    43
definition
wenzelm@21404
    44
  isNSUCont :: "['a::real_normed_vector => 'b::real_normed_vector] => bool" where
wenzelm@19765
    45
  "isNSUCont f = (\<forall>x y. x @= y --> ( *f* f) x @= ( *f* f) y)"
paulson@10751
    46
paulson@10751
    47
huffman@20755
    48
subsection {* Limits of Functions *}
paulson@14477
    49
huffman@20755
    50
subsubsection {* Purely standard proofs *}
paulson@14477
    51
paulson@14477
    52
lemma LIM_eq:
paulson@14477
    53
     "f -- a --> L =
huffman@20561
    54
     (\<forall>r>0.\<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r)"
paulson@14477
    55
by (simp add: LIM_def diff_minus)
paulson@14477
    56
huffman@20552
    57
lemma LIM_I:
huffman@20561
    58
     "(!!r. 0<r ==> \<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r)
huffman@20552
    59
      ==> f -- a --> L"
huffman@20552
    60
by (simp add: LIM_eq)
huffman@20552
    61
paulson@14477
    62
lemma LIM_D:
paulson@14477
    63
     "[| f -- a --> L; 0<r |]
huffman@20561
    64
      ==> \<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r"
paulson@14477
    65
by (simp add: LIM_eq)
paulson@14477
    66
huffman@21165
    67
lemma LIM_offset: "f -- a --> L \<Longrightarrow> (\<lambda>x. f (x + k)) -- a - k --> L"
huffman@20756
    68
apply (rule LIM_I)
huffman@20756
    69
apply (drule_tac r="r" in LIM_D, safe)
huffman@20756
    70
apply (rule_tac x="s" in exI, safe)
huffman@20756
    71
apply (drule_tac x="x + k" in spec)
huffman@20756
    72
apply (simp add: compare_rls)
huffman@20756
    73
done
huffman@20756
    74
huffman@21239
    75
lemma LIM_offset_zero: "f -- a --> L \<Longrightarrow> (\<lambda>h. f (a + h)) -- 0 --> L"
huffman@21239
    76
by (drule_tac k="a" in LIM_offset, simp add: add_commute)
huffman@21239
    77
huffman@21239
    78
lemma LIM_offset_zero_cancel: "(\<lambda>h. f (a + h)) -- 0 --> L \<Longrightarrow> f -- a --> L"
huffman@21239
    79
by (drule_tac k="- a" in LIM_offset, simp)
huffman@21239
    80
paulson@15228
    81
lemma LIM_const [simp]: "(%x. k) -- x --> k"
paulson@14477
    82
by (simp add: LIM_def)
paulson@14477
    83
paulson@14477
    84
lemma LIM_add:
huffman@20561
    85
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
paulson@14477
    86
  assumes f: "f -- a --> L" and g: "g -- a --> M"
paulson@14477
    87
  shows "(%x. f x + g(x)) -- a --> (L + M)"
huffman@20552
    88
proof (rule LIM_I)
paulson@14477
    89
  fix r :: real
huffman@20409
    90
  assume r: "0 < r"
paulson@14477
    91
  from LIM_D [OF f half_gt_zero [OF r]]
paulson@14477
    92
  obtain fs
paulson@14477
    93
    where fs:    "0 < fs"
huffman@20561
    94
      and fs_lt: "\<forall>x. x \<noteq> a & norm (x-a) < fs --> norm (f x - L) < r/2"
paulson@14477
    95
  by blast
paulson@14477
    96
  from LIM_D [OF g half_gt_zero [OF r]]
paulson@14477
    97
  obtain gs
paulson@14477
    98
    where gs:    "0 < gs"
huffman@20561
    99
      and gs_lt: "\<forall>x. x \<noteq> a & norm (x-a) < gs --> norm (g x - M) < r/2"
paulson@14477
   100
  by blast
huffman@20561
   101
  show "\<exists>s>0.\<forall>x. x \<noteq> a \<and> norm (x-a) < s \<longrightarrow> norm (f x + g x - (L + M)) < r"
paulson@14477
   102
  proof (intro exI conjI strip)
paulson@14477
   103
    show "0 < min fs gs"  by (simp add: fs gs)
huffman@20561
   104
    fix x :: 'a
huffman@20561
   105
    assume "x \<noteq> a \<and> norm (x-a) < min fs gs"
huffman@20561
   106
    hence "x \<noteq> a \<and> norm (x-a) < fs \<and> norm (x-a) < gs" by simp
paulson@14477
   107
    with fs_lt gs_lt
huffman@20552
   108
    have "norm (f x - L) < r/2" and "norm (g x - M) < r/2" by blast+
huffman@20552
   109
    hence "norm (f x - L) + norm (g x - M) < r" by arith
huffman@20552
   110
    thus "norm (f x + g x - (L + M)) < r"
huffman@20552
   111
      by (blast intro: norm_diff_triangle_ineq order_le_less_trans)
paulson@14477
   112
  qed
paulson@14477
   113
qed
paulson@14477
   114
huffman@21257
   115
lemma LIM_add_zero:
huffman@21257
   116
  "\<lbrakk>f -- a --> 0; g -- a --> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. f x + g x) -- a --> 0"
huffman@21257
   117
by (drule (1) LIM_add, simp)
huffman@21257
   118
huffman@20552
   119
lemma minus_diff_minus:
huffman@20552
   120
  fixes a b :: "'a::ab_group_add"
huffman@20552
   121
  shows "(- a) - (- b) = - (a - b)"
huffman@20552
   122
by simp
huffman@20552
   123
paulson@14477
   124
lemma LIM_minus: "f -- a --> L ==> (%x. -f(x)) -- a --> -L"
huffman@20552
   125
by (simp only: LIM_eq minus_diff_minus norm_minus_cancel)
paulson@14477
   126
paulson@14477
   127
lemma LIM_add_minus:
paulson@14477
   128
    "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
huffman@20552
   129
by (intro LIM_add LIM_minus)
paulson@14477
   130
paulson@14477
   131
lemma LIM_diff:
paulson@14477
   132
    "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) - g(x)) -- x --> l-m"
huffman@20552
   133
by (simp only: diff_minus LIM_add LIM_minus)
paulson@14477
   134
huffman@21239
   135
lemma LIM_zero: "f -- a --> l \<Longrightarrow> (\<lambda>x. f x - l) -- a --> 0"
huffman@21239
   136
by (simp add: LIM_def)
huffman@21239
   137
huffman@21239
   138
lemma LIM_zero_cancel: "(\<lambda>x. f x - l) -- a --> 0 \<Longrightarrow> f -- a --> l"
huffman@21239
   139
by (simp add: LIM_def)
huffman@21239
   140
huffman@21399
   141
lemma LIM_zero_iff: "(\<lambda>x. f x - l) -- a --> 0 = f -- a --> l"
huffman@21399
   142
by (simp add: LIM_def)
huffman@21399
   143
huffman@21257
   144
lemma LIM_imp_LIM:
huffman@21257
   145
  assumes f: "f -- a --> l"
huffman@21257
   146
  assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> norm (g x - m) \<le> norm (f x - l)"
huffman@21257
   147
  shows "g -- a --> m"
huffman@21257
   148
apply (rule LIM_I, drule LIM_D [OF f], safe)
huffman@21257
   149
apply (rule_tac x="s" in exI, safe)
huffman@21257
   150
apply (drule_tac x="x" in spec, safe)
huffman@21257
   151
apply (erule (1) order_le_less_trans [OF le])
huffman@21257
   152
done
huffman@21257
   153
huffman@21257
   154
lemma LIM_norm: "f -- a --> l \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> norm l"
huffman@21257
   155
by (erule LIM_imp_LIM, simp add: norm_triangle_ineq3)
huffman@21257
   156
huffman@21257
   157
lemma LIM_norm_zero: "f -- a --> 0 \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> 0"
huffman@21257
   158
by (drule LIM_norm, simp)
huffman@21257
   159
huffman@21257
   160
lemma LIM_norm_zero_cancel: "(\<lambda>x. norm (f x)) -- a --> 0 \<Longrightarrow> f -- a --> 0"
huffman@21257
   161
by (erule LIM_imp_LIM, simp)
huffman@21257
   162
huffman@21399
   163
lemma LIM_norm_zero_iff: "(\<lambda>x. norm (f x)) -- a --> 0 = f -- a --> 0"
huffman@21399
   164
by (rule iffI [OF LIM_norm_zero_cancel LIM_norm_zero])
huffman@21399
   165
huffman@22627
   166
lemma LIM_rabs: "f -- a --> (l::real) \<Longrightarrow> (\<lambda>x. \<bar>f x\<bar>) -- a --> \<bar>l\<bar>"
huffman@22627
   167
by (fold real_norm_def, rule LIM_norm)
huffman@22627
   168
huffman@22627
   169
lemma LIM_rabs_zero: "f -- a --> (0::real) \<Longrightarrow> (\<lambda>x. \<bar>f x\<bar>) -- a --> 0"
huffman@22627
   170
by (fold real_norm_def, rule LIM_norm_zero)
huffman@22627
   171
huffman@22627
   172
lemma LIM_rabs_zero_cancel: "(\<lambda>x. \<bar>f x\<bar>) -- a --> (0::real) \<Longrightarrow> f -- a --> 0"
huffman@22627
   173
by (fold real_norm_def, rule LIM_norm_zero_cancel)
huffman@22627
   174
huffman@22627
   175
lemma LIM_rabs_zero_iff: "(\<lambda>x. \<bar>f x\<bar>) -- a --> (0::real) = f -- a --> 0"
huffman@22627
   176
by (fold real_norm_def, rule LIM_norm_zero_iff)
huffman@22627
   177
huffman@20561
   178
lemma LIM_const_not_eq:
huffman@20561
   179
  fixes a :: "'a::real_normed_div_algebra"
huffman@20561
   180
  shows "k \<noteq> L ==> ~ ((%x. k) -- a --> L)"
huffman@20552
   181
apply (simp add: LIM_eq)
huffman@20552
   182
apply (rule_tac x="norm (k - L)" in exI, simp, safe)
huffman@20561
   183
apply (rule_tac x="a + of_real (s/2)" in exI, simp add: norm_of_real)
huffman@20552
   184
done
paulson@14477
   185
huffman@21786
   186
lemmas LIM_not_zero = LIM_const_not_eq [where L = 0]
huffman@21786
   187
huffman@20561
   188
lemma LIM_const_eq:
huffman@20561
   189
  fixes a :: "'a::real_normed_div_algebra"
huffman@20561
   190
  shows "(%x. k) -- a --> L ==> k = L"
paulson@14477
   191
apply (rule ccontr)
kleing@19023
   192
apply (blast dest: LIM_const_not_eq)
paulson@14477
   193
done
paulson@14477
   194
huffman@20561
   195
lemma LIM_unique:
huffman@20561
   196
  fixes a :: "'a::real_normed_div_algebra"
huffman@20561
   197
  shows "[| f -- a --> L; f -- a --> M |] ==> L = M"
kleing@19023
   198
apply (drule LIM_diff, assumption)
paulson@14477
   199
apply (auto dest!: LIM_const_eq)
paulson@14477
   200
done
paulson@14477
   201
paulson@14477
   202
lemma LIM_self: "(%x. x) -- a --> a"
paulson@14477
   203
by (auto simp add: LIM_def)
paulson@14477
   204
paulson@14477
   205
text{*Limits are equal for functions equal except at limit point*}
paulson@14477
   206
lemma LIM_equal:
paulson@14477
   207
     "[| \<forall>x. x \<noteq> a --> (f x = g x) |] ==> (f -- a --> l) = (g -- a --> l)"
paulson@14477
   208
by (simp add: LIM_def)
paulson@14477
   209
huffman@20796
   210
lemma LIM_cong:
huffman@20796
   211
  "\<lbrakk>a = b; \<And>x. x \<noteq> b \<Longrightarrow> f x = g x; l = m\<rbrakk>
huffman@21399
   212
   \<Longrightarrow> ((\<lambda>x. f x) -- a --> l) = ((\<lambda>x. g x) -- b --> m)"
huffman@20796
   213
by (simp add: LIM_def)
huffman@20796
   214
huffman@21282
   215
lemma LIM_equal2:
huffman@21282
   216
  assumes 1: "0 < R"
huffman@21282
   217
  assumes 2: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < R\<rbrakk> \<Longrightarrow> f x = g x"
huffman@21282
   218
  shows "g -- a --> l \<Longrightarrow> f -- a --> l"
huffman@21282
   219
apply (unfold LIM_def, safe)
huffman@21282
   220
apply (drule_tac x="r" in spec, safe)
huffman@21282
   221
apply (rule_tac x="min s R" in exI, safe)
huffman@21282
   222
apply (simp add: 1)
huffman@21282
   223
apply (simp add: 2)
huffman@21282
   224
done
huffman@21282
   225
paulson@14477
   226
text{*Two uses in Hyperreal/Transcendental.ML*}
paulson@14477
   227
lemma LIM_trans:
paulson@14477
   228
     "[| (%x. f(x) + -g(x)) -- a --> 0;  g -- a --> l |] ==> f -- a --> l"
paulson@14477
   229
apply (drule LIM_add, assumption)
paulson@14477
   230
apply (auto simp add: add_assoc)
paulson@14477
   231
done
paulson@14477
   232
huffman@21239
   233
lemma LIM_compose:
huffman@21239
   234
  assumes g: "g -- l --> g l"
huffman@21239
   235
  assumes f: "f -- a --> l"
huffman@21239
   236
  shows "(\<lambda>x. g (f x)) -- a --> g l"
huffman@21239
   237
proof (rule LIM_I)
huffman@21239
   238
  fix r::real assume r: "0 < r"
huffman@21239
   239
  obtain s where s: "0 < s"
huffman@21239
   240
    and less_r: "\<And>y. \<lbrakk>y \<noteq> l; norm (y - l) < s\<rbrakk> \<Longrightarrow> norm (g y - g l) < r"
huffman@21239
   241
    using LIM_D [OF g r] by fast
huffman@21239
   242
  obtain t where t: "0 < t"
huffman@21239
   243
    and less_s: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < t\<rbrakk> \<Longrightarrow> norm (f x - l) < s"
huffman@21239
   244
    using LIM_D [OF f s] by fast
huffman@21239
   245
huffman@21239
   246
  show "\<exists>t>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < t \<longrightarrow> norm (g (f x) - g l) < r"
huffman@21239
   247
  proof (rule exI, safe)
huffman@21239
   248
    show "0 < t" using t .
huffman@21239
   249
  next
huffman@21239
   250
    fix x assume "x \<noteq> a" and "norm (x - a) < t"
huffman@21239
   251
    hence "norm (f x - l) < s" by (rule less_s)
huffman@21239
   252
    thus "norm (g (f x) - g l) < r"
huffman@21239
   253
      using r less_r by (case_tac "f x = l", simp_all)
huffman@21239
   254
  qed
huffman@21239
   255
qed
huffman@21239
   256
huffman@21239
   257
lemma LIM_o: "\<lbrakk>g -- l --> g l; f -- a --> l\<rbrakk> \<Longrightarrow> (g \<circ> f) -- a --> g l"
huffman@21239
   258
unfolding o_def by (rule LIM_compose)
huffman@21239
   259
huffman@21282
   260
lemma real_LIM_sandwich_zero:
huffman@21282
   261
  fixes f g :: "'a::real_normed_vector \<Rightarrow> real"
huffman@21282
   262
  assumes f: "f -- a --> 0"
huffman@21282
   263
  assumes 1: "\<And>x. x \<noteq> a \<Longrightarrow> 0 \<le> g x"
huffman@21282
   264
  assumes 2: "\<And>x. x \<noteq> a \<Longrightarrow> g x \<le> f x"
huffman@21282
   265
  shows "g -- a --> 0"
huffman@21282
   266
proof (rule LIM_imp_LIM [OF f])
huffman@21282
   267
  fix x assume x: "x \<noteq> a"
huffman@21282
   268
  have "norm (g x - 0) = g x" by (simp add: 1 x)
huffman@21282
   269
  also have "g x \<le> f x" by (rule 2 [OF x])
huffman@21282
   270
  also have "f x \<le> \<bar>f x\<bar>" by (rule abs_ge_self)
huffman@21282
   271
  also have "\<bar>f x\<bar> = norm (f x - 0)" by simp
huffman@21282
   272
  finally show "norm (g x - 0) \<le> norm (f x - 0)" .
huffman@21282
   273
qed
huffman@21282
   274
huffman@22442
   275
text {* Bounded Linear Operators *}
huffman@21282
   276
huffman@21282
   277
lemma (in bounded_linear) cont: "f -- a --> f a"
huffman@21282
   278
proof (rule LIM_I)
huffman@21282
   279
  fix r::real assume r: "0 < r"
huffman@21282
   280
  obtain K where K: "0 < K" and norm_le: "\<And>x. norm (f x) \<le> norm x * K"
huffman@21282
   281
    using pos_bounded by fast
huffman@21282
   282
  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - f a) < r"
huffman@21282
   283
  proof (rule exI, safe)
huffman@21282
   284
    from r K show "0 < r / K" by (rule divide_pos_pos)
huffman@21282
   285
  next
huffman@21282
   286
    fix x assume x: "norm (x - a) < r / K"
huffman@21282
   287
    have "norm (f x - f a) = norm (f (x - a))" by (simp only: diff)
huffman@21282
   288
    also have "\<dots> \<le> norm (x - a) * K" by (rule norm_le)
huffman@21282
   289
    also from K x have "\<dots> < r" by (simp only: pos_less_divide_eq)
huffman@21282
   290
    finally show "norm (f x - f a) < r" .
huffman@21282
   291
  qed
huffman@21282
   292
qed
huffman@21282
   293
huffman@21282
   294
lemma (in bounded_linear) LIM:
huffman@21282
   295
  "g -- a --> l \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> f l"
huffman@21282
   296
by (rule LIM_compose [OF cont])
huffman@21282
   297
huffman@21282
   298
lemma (in bounded_linear) LIM_zero:
huffman@21282
   299
  "g -- a --> 0 \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> 0"
huffman@21282
   300
by (drule LIM, simp only: zero)
huffman@21282
   301
huffman@22442
   302
text {* Bounded Bilinear Operators *}
huffman@21282
   303
huffman@21282
   304
lemma (in bounded_bilinear) LIM_prod_zero:
huffman@21282
   305
  assumes f: "f -- a --> 0"
huffman@21282
   306
  assumes g: "g -- a --> 0"
huffman@21282
   307
  shows "(\<lambda>x. f x ** g x) -- a --> 0"
huffman@21282
   308
proof (rule LIM_I)
huffman@21282
   309
  fix r::real assume r: "0 < r"
huffman@21282
   310
  obtain K where K: "0 < K"
huffman@21282
   311
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@21282
   312
    using pos_bounded by fast
huffman@21282
   313
  from K have K': "0 < inverse K"
huffman@21282
   314
    by (rule positive_imp_inverse_positive)
huffman@21282
   315
  obtain s where s: "0 < s"
huffman@21282
   316
    and norm_f: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < s\<rbrakk> \<Longrightarrow> norm (f x) < r"
huffman@21282
   317
    using LIM_D [OF f r] by auto
huffman@21282
   318
  obtain t where t: "0 < t"
huffman@21282
   319
    and norm_g: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < t\<rbrakk> \<Longrightarrow> norm (g x) < inverse K"
huffman@21282
   320
    using LIM_D [OF g K'] by auto
huffman@21282
   321
  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x ** g x - 0) < r"
huffman@21282
   322
  proof (rule exI, safe)
huffman@21282
   323
    from s t show "0 < min s t" by simp
huffman@21282
   324
  next
huffman@21282
   325
    fix x assume x: "x \<noteq> a"
huffman@21282
   326
    assume "norm (x - a) < min s t"
huffman@21282
   327
    hence xs: "norm (x - a) < s" and xt: "norm (x - a) < t" by simp_all
huffman@21282
   328
    from x xs have 1: "norm (f x) < r" by (rule norm_f)
huffman@21282
   329
    from x xt have 2: "norm (g x) < inverse K" by (rule norm_g)
huffman@21282
   330
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K" by (rule norm_le)
huffman@21282
   331
    also from 1 2 K have "\<dots> < r * inverse K * K"
huffman@21282
   332
      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero)
huffman@21282
   333
    also from K have "r * inverse K * K = r" by simp
huffman@21282
   334
    finally show "norm (f x ** g x - 0) < r" by simp
huffman@21282
   335
  qed
huffman@21282
   336
qed
huffman@21282
   337
huffman@21282
   338
lemma (in bounded_bilinear) LIM_left_zero:
huffman@21282
   339
  "f -- a --> 0 \<Longrightarrow> (\<lambda>x. f x ** c) -- a --> 0"
huffman@21282
   340
by (rule bounded_linear.LIM_zero [OF bounded_linear_left])
huffman@21282
   341
huffman@21282
   342
lemma (in bounded_bilinear) LIM_right_zero:
huffman@21282
   343
  "f -- a --> 0 \<Longrightarrow> (\<lambda>x. c ** f x) -- a --> 0"
huffman@21282
   344
by (rule bounded_linear.LIM_zero [OF bounded_linear_right])
huffman@21282
   345
huffman@21282
   346
lemma (in bounded_bilinear) LIM:
huffman@21282
   347
  "\<lbrakk>f -- a --> L; g -- a --> M\<rbrakk> \<Longrightarrow> (\<lambda>x. f x ** g x) -- a --> L ** M"
huffman@21282
   348
apply (drule LIM_zero)
huffman@21282
   349
apply (drule LIM_zero)
huffman@21282
   350
apply (rule LIM_zero_cancel)
huffman@21282
   351
apply (subst prod_diff_prod)
huffman@21282
   352
apply (rule LIM_add_zero)
huffman@21282
   353
apply (rule LIM_add_zero)
huffman@21282
   354
apply (erule (1) LIM_prod_zero)
huffman@21282
   355
apply (erule LIM_left_zero)
huffman@21282
   356
apply (erule LIM_right_zero)
huffman@21282
   357
done
huffman@21282
   358
huffman@21282
   359
lemmas LIM_mult = bounded_bilinear_mult.LIM
huffman@21282
   360
huffman@21282
   361
lemmas LIM_mult_zero = bounded_bilinear_mult.LIM_prod_zero
huffman@21282
   362
huffman@21282
   363
lemmas LIM_mult_left_zero = bounded_bilinear_mult.LIM_left_zero
huffman@21282
   364
huffman@21282
   365
lemmas LIM_mult_right_zero = bounded_bilinear_mult.LIM_right_zero
huffman@21282
   366
huffman@21282
   367
lemmas LIM_scaleR = bounded_bilinear_scaleR.LIM
huffman@21282
   368
huffman@22627
   369
lemmas LIM_of_real = bounded_linear_of_real.LIM
huffman@22627
   370
huffman@22627
   371
lemma LIM_power:
huffman@22627
   372
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::{recpower,real_normed_algebra}"
huffman@22627
   373
  assumes f: "f -- a --> l"
huffman@22627
   374
  shows "(\<lambda>x. f x ^ n) -- a --> l ^ n"
huffman@22627
   375
by (induct n, simp, simp add: power_Suc LIM_mult f)
huffman@22627
   376
huffman@22637
   377
lemma LIM_inverse_lemma:
huffman@22637
   378
  fixes x :: "'a::real_normed_div_algebra"
huffman@22637
   379
  assumes r: "0 < r"
huffman@22637
   380
  assumes x: "norm (x - 1) < min (1/2) (r/2)"
huffman@22637
   381
  shows "norm (inverse x - 1) < r"
huffman@22637
   382
proof -
huffman@22637
   383
  from r have r2: "0 < r/2" by simp
huffman@22637
   384
  from x have 0: "x \<noteq> 0" by clarsimp
huffman@22637
   385
  from x have x': "norm (1 - x) < min (1/2) (r/2)"
huffman@22637
   386
    by (simp only: norm_minus_commute)
huffman@22637
   387
  hence less1: "norm (1 - x) < r/2" by simp
huffman@22637
   388
  have "norm (1::'a) - norm x \<le> norm (1 - x)" by (rule norm_triangle_ineq2)
huffman@22637
   389
  also from x' have "norm (1 - x) < 1/2" by simp
huffman@22637
   390
  finally have "1/2 < norm x" by simp
huffman@22637
   391
  hence "inverse (norm x) < inverse (1/2)"
huffman@22637
   392
    by (rule less_imp_inverse_less, simp)
huffman@22637
   393
  hence less2: "norm (inverse x) < 2"
huffman@22637
   394
    by (simp add: nonzero_norm_inverse 0)
huffman@22637
   395
  from less1 less2 r2 norm_ge_zero
huffman@22637
   396
  have "norm (1 - x) * norm (inverse x) < (r/2) * 2"
huffman@22637
   397
    by (rule mult_strict_mono)
huffman@22637
   398
  thus "norm (inverse x - 1) < r"
huffman@22637
   399
    by (simp only: norm_mult [symmetric] left_diff_distrib, simp add: 0)
huffman@22637
   400
qed
huffman@22637
   401
huffman@22637
   402
lemma LIM_inverse_fun:
huffman@22637
   403
  assumes a: "a \<noteq> (0::'a::real_normed_div_algebra)"
huffman@22637
   404
  shows "inverse -- a --> inverse a"
huffman@22637
   405
proof (rule LIM_equal2)
huffman@22637
   406
  from a show "0 < norm a" by simp
huffman@22637
   407
next
huffman@22637
   408
  fix x assume "norm (x - a) < norm a"
huffman@22637
   409
  hence "x \<noteq> 0" by auto
huffman@22637
   410
  with a show "inverse x = inverse (inverse a * x) * inverse a"
huffman@22637
   411
    by (simp add: nonzero_inverse_mult_distrib
huffman@22637
   412
                  nonzero_imp_inverse_nonzero
huffman@22637
   413
                  nonzero_inverse_inverse_eq mult_assoc)
huffman@22637
   414
next
huffman@22637
   415
  have 1: "inverse -- 1 --> inverse (1::'a)"
huffman@22637
   416
    apply (rule LIM_I)
huffman@22637
   417
    apply (rule_tac x="min (1/2) (r/2)" in exI)
huffman@22637
   418
    apply (simp add: LIM_inverse_lemma)
huffman@22637
   419
    done
huffman@22637
   420
  have "(\<lambda>x. inverse a * x) -- a --> inverse a * a"
huffman@22637
   421
    by (intro LIM_mult LIM_self LIM_const)
huffman@22637
   422
  hence "(\<lambda>x. inverse a * x) -- a --> 1"
huffman@22637
   423
    by (simp add: a)
huffman@22637
   424
  with 1 have "(\<lambda>x. inverse (inverse a * x)) -- a --> inverse 1"
huffman@22637
   425
    by (rule LIM_compose)
huffman@22637
   426
  hence "(\<lambda>x. inverse (inverse a * x)) -- a --> 1"
huffman@22637
   427
    by simp
huffman@22637
   428
  hence "(\<lambda>x. inverse (inverse a * x) * inverse a) -- a --> 1 * inverse a"
huffman@22637
   429
    by (intro LIM_mult LIM_const)
huffman@22637
   430
  thus "(\<lambda>x. inverse (inverse a * x) * inverse a) -- a --> inverse a"
huffman@22637
   431
    by simp
huffman@22637
   432
qed
huffman@22637
   433
huffman@22637
   434
lemma LIM_inverse:
huffman@22637
   435
  fixes L :: "'a::real_normed_div_algebra"
huffman@22637
   436
  shows "\<lbrakk>f -- a --> L; L \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. inverse (f x)) -- a --> inverse L"
huffman@22637
   437
by (rule LIM_inverse_fun [THEN LIM_compose])
huffman@22637
   438
huffman@20755
   439
subsubsection {* Purely nonstandard proofs *}
paulson@14477
   440
huffman@20754
   441
lemma NSLIM_I:
huffman@20754
   442
  "(\<And>x. \<lbrakk>x \<noteq> star_of a; x \<approx> star_of a\<rbrakk> \<Longrightarrow> starfun f x \<approx> star_of L)
huffman@20754
   443
   \<Longrightarrow> f -- a --NS> L"
huffman@20754
   444
by (simp add: NSLIM_def)
paulson@14477
   445
huffman@20754
   446
lemma NSLIM_D:
huffman@20754
   447
  "\<lbrakk>f -- a --NS> L; x \<noteq> star_of a; x \<approx> star_of a\<rbrakk>
huffman@20754
   448
   \<Longrightarrow> starfun f x \<approx> star_of L"
huffman@20754
   449
by (simp add: NSLIM_def)
paulson@14477
   450
huffman@20755
   451
text{*Proving properties of limits using nonstandard definition.
huffman@20755
   452
      The properties hold for standard limits as well!*}
huffman@20755
   453
huffman@20755
   454
lemma NSLIM_mult:
huffman@20755
   455
  fixes l m :: "'a::real_normed_algebra"
huffman@20755
   456
  shows "[| f -- x --NS> l; g -- x --NS> m |]
huffman@20755
   457
      ==> (%x. f(x) * g(x)) -- x --NS> (l * m)"
huffman@20755
   458
by (auto simp add: NSLIM_def intro!: approx_mult_HFinite)
huffman@20755
   459
huffman@20794
   460
lemma starfun_scaleR [simp]:
huffman@20794
   461
  "starfun (\<lambda>x. f x *# g x) = (\<lambda>x. scaleHR (starfun f x) (starfun g x))"
huffman@20794
   462
by transfer (rule refl)
huffman@20794
   463
huffman@20794
   464
lemma NSLIM_scaleR:
huffman@20794
   465
  "[| f -- x --NS> l; g -- x --NS> m |]
huffman@20794
   466
      ==> (%x. f(x) *# g(x)) -- x --NS> (l *# m)"
huffman@20794
   467
by (auto simp add: NSLIM_def intro!: approx_scaleR_HFinite)
huffman@20794
   468
huffman@20755
   469
lemma NSLIM_add:
huffman@20755
   470
     "[| f -- x --NS> l; g -- x --NS> m |]
huffman@20755
   471
      ==> (%x. f(x) + g(x)) -- x --NS> (l + m)"
huffman@20755
   472
by (auto simp add: NSLIM_def intro!: approx_add)
huffman@20755
   473
huffman@20755
   474
lemma NSLIM_const [simp]: "(%x. k) -- x --NS> k"
huffman@20755
   475
by (simp add: NSLIM_def)
huffman@20755
   476
huffman@20755
   477
lemma NSLIM_minus: "f -- a --NS> L ==> (%x. -f(x)) -- a --NS> -L"
huffman@20755
   478
by (simp add: NSLIM_def)
huffman@20755
   479
huffman@21786
   480
lemma NSLIM_diff:
huffman@21786
   481
  "\<lbrakk>f -- x --NS> l; g -- x --NS> m\<rbrakk> \<Longrightarrow> (\<lambda>x. f x - g x) -- x --NS> (l - m)"
huffman@21786
   482
by (simp only: diff_def NSLIM_add NSLIM_minus)
huffman@21786
   483
huffman@20755
   484
lemma NSLIM_add_minus: "[| f -- x --NS> l; g -- x --NS> m |] ==> (%x. f(x) + -g(x)) -- x --NS> (l + -m)"
huffman@20755
   485
by (simp only: NSLIM_add NSLIM_minus)
huffman@20755
   486
huffman@20755
   487
lemma NSLIM_inverse:
huffman@20755
   488
  fixes L :: "'a::real_normed_div_algebra"
huffman@20755
   489
  shows "[| f -- a --NS> L;  L \<noteq> 0 |]
huffman@20755
   490
      ==> (%x. inverse(f(x))) -- a --NS> (inverse L)"
huffman@20755
   491
apply (simp add: NSLIM_def, clarify)
huffman@20755
   492
apply (drule spec)
huffman@20755
   493
apply (auto simp add: star_of_approx_inverse)
huffman@20755
   494
done
huffman@20755
   495
huffman@20755
   496
lemma NSLIM_zero:
huffman@21786
   497
  assumes f: "f -- a --NS> l" shows "(%x. f(x) - l) -- a --NS> 0"
huffman@20755
   498
proof -
huffman@21786
   499
  have "(\<lambda>x. f x - l) -- a --NS> l - l"
huffman@21786
   500
    by (rule NSLIM_diff [OF f NSLIM_const])
huffman@20755
   501
  thus ?thesis by simp
huffman@20755
   502
qed
huffman@20755
   503
huffman@20755
   504
lemma NSLIM_zero_cancel: "(%x. f(x) - l) -- x --NS> 0 ==> f -- x --NS> l"
huffman@20755
   505
apply (drule_tac g = "%x. l" and m = l in NSLIM_add)
huffman@20755
   506
apply (auto simp add: diff_minus add_assoc)
huffman@20755
   507
done
huffman@20755
   508
huffman@20755
   509
lemma NSLIM_const_not_eq:
huffman@20755
   510
  fixes a :: real (* TODO: generalize to real_normed_div_algebra *)
huffman@20755
   511
  shows "k \<noteq> L ==> ~ ((%x. k) -- a --NS> L)"
huffman@20755
   512
apply (simp add: NSLIM_def)
huffman@20755
   513
apply (rule_tac x="star_of a + epsilon" in exI)
huffman@20755
   514
apply (auto intro: Infinitesimal_add_approx_self [THEN approx_sym]
huffman@20755
   515
            simp add: hypreal_epsilon_not_zero)
huffman@20755
   516
done
huffman@20755
   517
huffman@20755
   518
lemma NSLIM_not_zero:
huffman@20755
   519
  fixes a :: real
huffman@20755
   520
  shows "k \<noteq> 0 ==> ~ ((%x. k) -- a --NS> 0)"
huffman@20755
   521
by (rule NSLIM_const_not_eq)
huffman@20755
   522
huffman@20755
   523
lemma NSLIM_const_eq:
huffman@20755
   524
  fixes a :: real
huffman@20755
   525
  shows "(%x. k) -- a --NS> L ==> k = L"
huffman@20755
   526
apply (rule ccontr)
huffman@20755
   527
apply (blast dest: NSLIM_const_not_eq)
huffman@20755
   528
done
huffman@20755
   529
huffman@20755
   530
text{* can actually be proved more easily by unfolding the definition!*}
huffman@20755
   531
lemma NSLIM_unique:
huffman@20755
   532
  fixes a :: real
huffman@20755
   533
  shows "[| f -- a --NS> L; f -- a --NS> M |] ==> L = M"
huffman@20755
   534
apply (drule NSLIM_minus)
huffman@20755
   535
apply (drule NSLIM_add, assumption)
huffman@20755
   536
apply (auto dest!: NSLIM_const_eq [symmetric])
huffman@20755
   537
apply (simp add: diff_def [symmetric])
huffman@20755
   538
done
huffman@20755
   539
huffman@20755
   540
lemma NSLIM_mult_zero:
huffman@20755
   541
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_algebra"
huffman@20755
   542
  shows "[| f -- x --NS> 0; g -- x --NS> 0 |] ==> (%x. f(x)*g(x)) -- x --NS> 0"
huffman@20755
   543
by (drule NSLIM_mult, auto)
huffman@20755
   544
huffman@20755
   545
lemma NSLIM_self: "(%x. x) -- a --NS> a"
huffman@20755
   546
by (simp add: NSLIM_def)
huffman@20755
   547
huffman@20755
   548
subsubsection {* Equivalence of @{term LIM} and @{term NSLIM} *}
huffman@20755
   549
huffman@20754
   550
lemma LIM_NSLIM:
huffman@20754
   551
  assumes f: "f -- a --> L" shows "f -- a --NS> L"
huffman@20754
   552
proof (rule NSLIM_I)
huffman@20754
   553
  fix x
huffman@20754
   554
  assume neq: "x \<noteq> star_of a"
huffman@20754
   555
  assume approx: "x \<approx> star_of a"
huffman@20754
   556
  have "starfun f x - star_of L \<in> Infinitesimal"
huffman@20754
   557
  proof (rule InfinitesimalI2)
huffman@20754
   558
    fix r::real assume r: "0 < r"
huffman@20754
   559
    from LIM_D [OF f r]
huffman@20754
   560
    obtain s where s: "0 < s" and
huffman@20754
   561
      less_r: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < s\<rbrakk> \<Longrightarrow> norm (f x - L) < r"
huffman@20754
   562
      by fast
huffman@20754
   563
    from less_r have less_r':
huffman@20754
   564
       "\<And>x. \<lbrakk>x \<noteq> star_of a; hnorm (x - star_of a) < star_of s\<rbrakk>
huffman@20754
   565
        \<Longrightarrow> hnorm (starfun f x - star_of L) < star_of r"
huffman@20754
   566
      by transfer
huffman@20754
   567
    from approx have "x - star_of a \<in> Infinitesimal"
huffman@20754
   568
      by (unfold approx_def)
huffman@20754
   569
    hence "hnorm (x - star_of a) < star_of s"
huffman@20754
   570
      using s by (rule InfinitesimalD2)
huffman@20754
   571
    with neq show "hnorm (starfun f x - star_of L) < star_of r"
huffman@20754
   572
      by (rule less_r')
huffman@20754
   573
  qed
huffman@20754
   574
  thus "starfun f x \<approx> star_of L"
huffman@20754
   575
    by (unfold approx_def)
huffman@20754
   576
qed
huffman@20552
   577
huffman@20754
   578
lemma NSLIM_LIM:
huffman@20754
   579
  assumes f: "f -- a --NS> L" shows "f -- a --> L"
huffman@20754
   580
proof (rule LIM_I)
huffman@20754
   581
  fix r::real assume r: "0 < r"
huffman@20754
   582
  have "\<exists>s>0. \<forall>x. x \<noteq> star_of a \<and> hnorm (x - star_of a) < s
huffman@20754
   583
        \<longrightarrow> hnorm (starfun f x - star_of L) < star_of r"
huffman@20754
   584
  proof (rule exI, safe)
huffman@20754
   585
    show "0 < epsilon" by (rule hypreal_epsilon_gt_zero)
huffman@20754
   586
  next
huffman@20754
   587
    fix x assume neq: "x \<noteq> star_of a"
huffman@20754
   588
    assume "hnorm (x - star_of a) < epsilon"
huffman@20754
   589
    with Infinitesimal_epsilon
huffman@20754
   590
    have "x - star_of a \<in> Infinitesimal"
huffman@20754
   591
      by (rule hnorm_less_Infinitesimal)
huffman@20754
   592
    hence "x \<approx> star_of a"
huffman@20754
   593
      by (unfold approx_def)
huffman@20754
   594
    with f neq have "starfun f x \<approx> star_of L"
huffman@20754
   595
      by (rule NSLIM_D)
huffman@20754
   596
    hence "starfun f x - star_of L \<in> Infinitesimal"
huffman@20754
   597
      by (unfold approx_def)
huffman@20754
   598
    thus "hnorm (starfun f x - star_of L) < star_of r"
huffman@20754
   599
      using r by (rule InfinitesimalD2)
huffman@20754
   600
  qed
huffman@20754
   601
  thus "\<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - L) < r"
huffman@20754
   602
    by transfer
huffman@20754
   603
qed
paulson@14477
   604
paulson@15228
   605
theorem LIM_NSLIM_iff: "(f -- x --> L) = (f -- x --NS> L)"
paulson@14477
   606
by (blast intro: LIM_NSLIM NSLIM_LIM)
paulson@14477
   607
paulson@14477
   608
huffman@20755
   609
subsection {* Continuity *}
paulson@14477
   610
huffman@21239
   611
subsubsection {* Purely standard proofs *}
huffman@21239
   612
huffman@21239
   613
lemma LIM_isCont_iff: "(f -- a --> f a) = ((\<lambda>h. f (a + h)) -- 0 --> f a)"
huffman@21239
   614
by (rule iffI [OF LIM_offset_zero LIM_offset_zero_cancel])
huffman@21239
   615
huffman@21239
   616
lemma isCont_iff: "isCont f x = (\<lambda>h. f (x + h)) -- 0 --> f x"
huffman@21239
   617
by (simp add: isCont_def LIM_isCont_iff)
huffman@21239
   618
huffman@21239
   619
lemma isCont_Id: "isCont (\<lambda>x. x) a"
huffman@21282
   620
  unfolding isCont_def by (rule LIM_self)
huffman@21239
   621
huffman@21786
   622
lemma isCont_const [simp]: "isCont (\<lambda>x. k) a"
huffman@21282
   623
  unfolding isCont_def by (rule LIM_const)
huffman@21239
   624
huffman@21786
   625
lemma isCont_norm: "isCont f a \<Longrightarrow> isCont (\<lambda>x. norm (f x)) a"
huffman@21786
   626
  unfolding isCont_def by (rule LIM_norm)
huffman@21786
   627
huffman@22627
   628
lemma isCont_rabs: "isCont f a \<Longrightarrow> isCont (\<lambda>x. \<bar>f x :: real\<bar>) a"
huffman@22627
   629
  unfolding isCont_def by (rule LIM_rabs)
huffman@22627
   630
huffman@21239
   631
lemma isCont_add: "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x + g x) a"
huffman@21282
   632
  unfolding isCont_def by (rule LIM_add)
huffman@21239
   633
huffman@21239
   634
lemma isCont_minus: "isCont f a \<Longrightarrow> isCont (\<lambda>x. - f x) a"
huffman@21282
   635
  unfolding isCont_def by (rule LIM_minus)
huffman@21239
   636
huffman@21239
   637
lemma isCont_diff: "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x - g x) a"
huffman@21282
   638
  unfolding isCont_def by (rule LIM_diff)
huffman@21239
   639
huffman@21239
   640
lemma isCont_mult:
huffman@21239
   641
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_algebra"
huffman@21786
   642
  shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x * g x) a"
huffman@21282
   643
  unfolding isCont_def by (rule LIM_mult)
huffman@21239
   644
huffman@21239
   645
lemma isCont_inverse:
huffman@21239
   646
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_div_algebra"
huffman@21786
   647
  shows "\<lbrakk>isCont f a; f a \<noteq> 0\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. inverse (f x)) a"
huffman@21282
   648
  unfolding isCont_def by (rule LIM_inverse)
huffman@21239
   649
huffman@21239
   650
lemma isCont_LIM_compose:
huffman@21239
   651
  "\<lbrakk>isCont g l; f -- a --> l\<rbrakk> \<Longrightarrow> (\<lambda>x. g (f x)) -- a --> g l"
huffman@21282
   652
  unfolding isCont_def by (rule LIM_compose)
huffman@21239
   653
huffman@21239
   654
lemma isCont_o2: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. g (f x)) a"
huffman@21282
   655
  unfolding isCont_def by (rule LIM_compose)
huffman@21239
   656
huffman@21239
   657
lemma isCont_o: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (g o f) a"
huffman@21282
   658
  unfolding o_def by (rule isCont_o2)
huffman@21282
   659
huffman@21282
   660
lemma (in bounded_linear) isCont: "isCont f a"
huffman@21282
   661
  unfolding isCont_def by (rule cont)
huffman@21282
   662
huffman@21282
   663
lemma (in bounded_bilinear) isCont:
huffman@21282
   664
  "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x ** g x) a"
huffman@21282
   665
  unfolding isCont_def by (rule LIM)
huffman@21282
   666
huffman@21282
   667
lemmas isCont_scaleR = bounded_bilinear_scaleR.isCont
huffman@21239
   668
huffman@22627
   669
lemma isCont_of_real:
huffman@22627
   670
  "isCont f a \<Longrightarrow> isCont (\<lambda>x. of_real (f x)) a"
huffman@22627
   671
  unfolding isCont_def by (rule LIM_of_real)
huffman@22627
   672
huffman@22627
   673
lemma isCont_power:
huffman@22627
   674
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::{recpower,real_normed_algebra}"
huffman@22627
   675
  shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. f x ^ n) a"
huffman@22627
   676
  unfolding isCont_def by (rule LIM_power)
huffman@22627
   677
huffman@21239
   678
subsubsection {* Nonstandard proofs *}
huffman@21239
   679
huffman@21786
   680
lemma isNSContD:
huffman@21786
   681
  "\<lbrakk>isNSCont f a; y \<approx> star_of a\<rbrakk> \<Longrightarrow> ( *f* f) y \<approx> star_of (f a)"
paulson@14477
   682
by (simp add: isNSCont_def)
paulson@14477
   683
paulson@14477
   684
lemma isNSCont_NSLIM: "isNSCont f a ==> f -- a --NS> (f a) "
paulson@14477
   685
by (simp add: isNSCont_def NSLIM_def)
paulson@14477
   686
paulson@14477
   687
lemma NSLIM_isNSCont: "f -- a --NS> (f a) ==> isNSCont f a"
paulson@14477
   688
apply (simp add: isNSCont_def NSLIM_def, auto)
huffman@20561
   689
apply (case_tac "y = star_of a", auto)
paulson@14477
   690
done
paulson@14477
   691
paulson@15228
   692
text{*NS continuity can be defined using NS Limit in
paulson@15228
   693
    similar fashion to standard def of continuity*}
paulson@14477
   694
lemma isNSCont_NSLIM_iff: "(isNSCont f a) = (f -- a --NS> (f a))"
paulson@14477
   695
by (blast intro: isNSCont_NSLIM NSLIM_isNSCont)
paulson@14477
   696
paulson@15228
   697
text{*Hence, NS continuity can be given
paulson@15228
   698
  in terms of standard limit*}
paulson@14477
   699
lemma isNSCont_LIM_iff: "(isNSCont f a) = (f -- a --> (f a))"
paulson@14477
   700
by (simp add: LIM_NSLIM_iff isNSCont_NSLIM_iff)
paulson@14477
   701
paulson@15228
   702
text{*Moreover, it's trivial now that NS continuity
paulson@15228
   703
  is equivalent to standard continuity*}
paulson@14477
   704
lemma isNSCont_isCont_iff: "(isNSCont f a) = (isCont f a)"
paulson@14477
   705
apply (simp add: isCont_def)
paulson@14477
   706
apply (rule isNSCont_LIM_iff)
paulson@14477
   707
done
paulson@14477
   708
paulson@15228
   709
text{*Standard continuity ==> NS continuity*}
paulson@14477
   710
lemma isCont_isNSCont: "isCont f a ==> isNSCont f a"
paulson@14477
   711
by (erule isNSCont_isCont_iff [THEN iffD2])
paulson@14477
   712
paulson@15228
   713
text{*NS continuity ==> Standard continuity*}
paulson@14477
   714
lemma isNSCont_isCont: "isNSCont f a ==> isCont f a"
paulson@14477
   715
by (erule isNSCont_isCont_iff [THEN iffD1])
paulson@14477
   716
paulson@14477
   717
text{*Alternative definition of continuity*}
paulson@14477
   718
(* Prove equivalence between NS limits - *)
paulson@14477
   719
(* seems easier than using standard def  *)
paulson@14477
   720
lemma NSLIM_h_iff: "(f -- a --NS> L) = ((%h. f(a + h)) -- 0 --NS> L)"
paulson@14477
   721
apply (simp add: NSLIM_def, auto)
huffman@20561
   722
apply (drule_tac x = "star_of a + x" in spec)
huffman@20561
   723
apply (drule_tac [2] x = "- star_of a + x" in spec, safe, simp)
huffman@20561
   724
apply (erule mem_infmal_iff [THEN iffD2, THEN Infinitesimal_add_approx_self [THEN approx_sym]])
huffman@20561
   725
apply (erule_tac [3] approx_minus_iff2 [THEN iffD1])
huffman@20561
   726
 prefer 2 apply (simp add: add_commute diff_def [symmetric])
huffman@20561
   727
apply (rule_tac x = x in star_cases)
huffman@17318
   728
apply (rule_tac [2] x = x in star_cases)
huffman@17318
   729
apply (auto simp add: starfun star_of_def star_n_minus star_n_add add_assoc approx_refl star_n_zero_num)
paulson@14477
   730
done
paulson@14477
   731
paulson@14477
   732
lemma NSLIM_isCont_iff: "(f -- a --NS> f a) = ((%h. f(a + h)) -- 0 --NS> f a)"
paulson@14477
   733
by (rule NSLIM_h_iff)
paulson@14477
   734
paulson@14477
   735
lemma isNSCont_minus: "isNSCont f a ==> isNSCont (%x. - f x) a"
paulson@14477
   736
by (simp add: isNSCont_def)
paulson@14477
   737
huffman@20552
   738
lemma isNSCont_inverse:
huffman@20653
   739
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_div_algebra"
huffman@20552
   740
  shows "[| isNSCont f x; f x \<noteq> 0 |] ==> isNSCont (%x. inverse (f x)) x"
paulson@14477
   741
by (auto intro: isCont_inverse simp add: isNSCont_isCont_iff)
paulson@14477
   742
paulson@15228
   743
lemma isNSCont_const [simp]: "isNSCont (%x. k) a"
paulson@14477
   744
by (simp add: isNSCont_def)
paulson@14477
   745
huffman@20561
   746
lemma isNSCont_abs [simp]: "isNSCont abs (a::real)"
paulson@14477
   747
apply (simp add: isNSCont_def)
huffman@21810
   748
apply (auto intro: approx_hrabs simp add: starfun_rabs_hrabs)
paulson@14477
   749
done
paulson@14477
   750
huffman@20561
   751
lemma isCont_abs [simp]: "isCont abs (a::real)"
paulson@14477
   752
by (auto simp add: isNSCont_isCont_iff [symmetric])
paulson@15228
   753
paulson@14477
   754
paulson@14477
   755
(****************************************************************
paulson@14477
   756
(%* Leave as commented until I add topology theory or remove? *%)
paulson@14477
   757
(%*------------------------------------------------------------
paulson@14477
   758
  Elementary topology proof for a characterisation of
paulson@14477
   759
  continuity now: a function f is continuous if and only
paulson@14477
   760
  if the inverse image, {x. f(x) \<in> A}, of any open set A
paulson@14477
   761
  is always an open set
paulson@14477
   762
 ------------------------------------------------------------*%)
paulson@14477
   763
Goal "[| isNSopen A; \<forall>x. isNSCont f x |]
paulson@14477
   764
               ==> isNSopen {x. f x \<in> A}"
paulson@14477
   765
by (auto_tac (claset(),simpset() addsimps [isNSopen_iff1]));
paulson@14477
   766
by (dtac (mem_monad_approx RS approx_sym);
paulson@14477
   767
by (dres_inst_tac [("x","a")] spec 1);
paulson@14477
   768
by (dtac isNSContD 1 THEN assume_tac 1)
paulson@14477
   769
by (dtac bspec 1 THEN assume_tac 1)
paulson@14477
   770
by (dres_inst_tac [("x","( *f* f) x")] approx_mem_monad2 1);
paulson@14477
   771
by (blast_tac (claset() addIs [starfun_mem_starset]);
paulson@14477
   772
qed "isNSCont_isNSopen";
paulson@14477
   773
paulson@14477
   774
Goalw [isNSCont_def]
paulson@14477
   775
          "\<forall>A. isNSopen A --> isNSopen {x. f x \<in> A} \
paulson@14477
   776
\              ==> isNSCont f x";
paulson@14477
   777
by (auto_tac (claset() addSIs [(mem_infmal_iff RS iffD1) RS
paulson@14477
   778
     (approx_minus_iff RS iffD2)],simpset() addsimps
paulson@14477
   779
      [Infinitesimal_def,SReal_iff]));
paulson@14477
   780
by (dres_inst_tac [("x","{z. abs(z + -f(x)) < ya}")] spec 1);
paulson@14477
   781
by (etac (isNSopen_open_interval RSN (2,impE));
paulson@14477
   782
by (auto_tac (claset(),simpset() addsimps [isNSopen_def,isNSnbhd_def]));
paulson@14477
   783
by (dres_inst_tac [("x","x")] spec 1);
paulson@14477
   784
by (auto_tac (claset() addDs [approx_sym RS approx_mem_monad],
paulson@14477
   785
    simpset() addsimps [hypreal_of_real_zero RS sym,STAR_starfun_rabs_add_minus]));
paulson@14477
   786
qed "isNSopen_isNSCont";
paulson@14477
   787
paulson@14477
   788
Goal "(\<forall>x. isNSCont f x) = \
paulson@14477
   789
\     (\<forall>A. isNSopen A --> isNSopen {x. f(x) \<in> A})";
paulson@14477
   790
by (blast_tac (claset() addIs [isNSCont_isNSopen,
paulson@14477
   791
    isNSopen_isNSCont]);
paulson@14477
   792
qed "isNSCont_isNSopen_iff";
paulson@14477
   793
paulson@14477
   794
(%*------- Standard version of same theorem --------*%)
paulson@14477
   795
Goal "(\<forall>x. isCont f x) = \
paulson@14477
   796
\         (\<forall>A. isopen A --> isopen {x. f(x) \<in> A})";
paulson@14477
   797
by (auto_tac (claset() addSIs [isNSCont_isNSopen_iff],
paulson@14477
   798
              simpset() addsimps [isNSopen_isopen_iff RS sym,
paulson@14477
   799
              isNSCont_isCont_iff RS sym]));
paulson@14477
   800
qed "isCont_isopen_iff";
paulson@14477
   801
*******************************************************************)
paulson@14477
   802
huffman@20755
   803
subsection {* Uniform Continuity *}
huffman@20755
   804
paulson@14477
   805
lemma isNSUContD: "[| isNSUCont f; x \<approx> y|] ==> ( *f* f) x \<approx> ( *f* f) y"
paulson@14477
   806
by (simp add: isNSUCont_def)
paulson@14477
   807
paulson@14477
   808
lemma isUCont_isCont: "isUCont f ==> isCont f x"
paulson@14477
   809
by (simp add: isUCont_def isCont_def LIM_def, meson)
paulson@14477
   810
huffman@20754
   811
lemma isUCont_isNSUCont:
huffman@20754
   812
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
huffman@20754
   813
  assumes f: "isUCont f" shows "isNSUCont f"
huffman@20754
   814
proof (unfold isNSUCont_def, safe)
huffman@20754
   815
  fix x y :: "'a star"
huffman@20754
   816
  assume approx: "x \<approx> y"
huffman@20754
   817
  have "starfun f x - starfun f y \<in> Infinitesimal"
huffman@20754
   818
  proof (rule InfinitesimalI2)
huffman@20754
   819
    fix r::real assume r: "0 < r"
huffman@20754
   820
    with f obtain s where s: "0 < s" and
huffman@20754
   821
      less_r: "\<And>x y. norm (x - y) < s \<Longrightarrow> norm (f x - f y) < r"
huffman@20754
   822
      by (auto simp add: isUCont_def)
huffman@20754
   823
    from less_r have less_r':
huffman@20754
   824
       "\<And>x y. hnorm (x - y) < star_of s
huffman@20754
   825
        \<Longrightarrow> hnorm (starfun f x - starfun f y) < star_of r"
huffman@20754
   826
      by transfer
huffman@20754
   827
    from approx have "x - y \<in> Infinitesimal"
huffman@20754
   828
      by (unfold approx_def)
huffman@20754
   829
    hence "hnorm (x - y) < star_of s"
huffman@20754
   830
      using s by (rule InfinitesimalD2)
huffman@20754
   831
    thus "hnorm (starfun f x - starfun f y) < star_of r"
huffman@20754
   832
      by (rule less_r')
huffman@20754
   833
  qed
huffman@20754
   834
  thus "starfun f x \<approx> starfun f y"
huffman@20754
   835
    by (unfold approx_def)
huffman@20754
   836
qed
paulson@14477
   837
paulson@14477
   838
lemma isNSUCont_isUCont:
huffman@20754
   839
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
huffman@20754
   840
  assumes f: "isNSUCont f" shows "isUCont f"
huffman@20754
   841
proof (unfold isUCont_def, safe)
huffman@20754
   842
  fix r::real assume r: "0 < r"
huffman@20754
   843
  have "\<exists>s>0. \<forall>x y. hnorm (x - y) < s
huffman@20754
   844
        \<longrightarrow> hnorm (starfun f x - starfun f y) < star_of r"
huffman@20754
   845
  proof (rule exI, safe)
huffman@20754
   846
    show "0 < epsilon" by (rule hypreal_epsilon_gt_zero)
huffman@20754
   847
  next
huffman@20754
   848
    fix x y :: "'a star"
huffman@20754
   849
    assume "hnorm (x - y) < epsilon"
huffman@20754
   850
    with Infinitesimal_epsilon
huffman@20754
   851
    have "x - y \<in> Infinitesimal"
huffman@20754
   852
      by (rule hnorm_less_Infinitesimal)
huffman@20754
   853
    hence "x \<approx> y"
huffman@20754
   854
      by (unfold approx_def)
huffman@20754
   855
    with f have "starfun f x \<approx> starfun f y"
huffman@20754
   856
      by (simp add: isNSUCont_def)
huffman@20754
   857
    hence "starfun f x - starfun f y \<in> Infinitesimal"
huffman@20754
   858
      by (unfold approx_def)
huffman@20754
   859
    thus "hnorm (starfun f x - starfun f y) < star_of r"
huffman@20754
   860
      using r by (rule InfinitesimalD2)
huffman@20754
   861
  qed
huffman@20754
   862
  thus "\<exists>s>0. \<forall>x y. norm (x - y) < s \<longrightarrow> norm (f x - f y) < r"
huffman@20754
   863
    by transfer
huffman@20754
   864
qed
paulson@14477
   865
huffman@21165
   866
subsection {* Relation of LIM and LIMSEQ *}
kleing@19023
   867
kleing@19023
   868
lemma LIMSEQ_SEQ_conv1:
huffman@21165
   869
  fixes a :: "'a::real_normed_vector"
huffman@21165
   870
  assumes X: "X -- a --> L"
kleing@19023
   871
  shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
huffman@21165
   872
proof (safe intro!: LIMSEQ_I)
huffman@21165
   873
  fix S :: "nat \<Rightarrow> 'a"
huffman@21165
   874
  fix r :: real
huffman@21165
   875
  assume rgz: "0 < r"
huffman@21165
   876
  assume as: "\<forall>n. S n \<noteq> a"
huffman@21165
   877
  assume S: "S ----> a"
huffman@21165
   878
  from LIM_D [OF X rgz] obtain s
huffman@21165
   879
    where sgz: "0 < s"
huffman@21165
   880
    and aux: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < s\<rbrakk> \<Longrightarrow> norm (X x - L) < r"
huffman@21165
   881
    by fast
huffman@21165
   882
  from LIMSEQ_D [OF S sgz]
nipkow@21733
   883
  obtain no where "\<forall>n\<ge>no. norm (S n - a) < s" by blast
huffman@21165
   884
  hence "\<forall>n\<ge>no. norm (X (S n) - L) < r" by (simp add: aux as)
huffman@21165
   885
  thus "\<exists>no. \<forall>n\<ge>no. norm (X (S n) - L) < r" ..
kleing@19023
   886
qed
kleing@19023
   887
kleing@19023
   888
lemma LIMSEQ_SEQ_conv2:
huffman@20561
   889
  fixes a :: real
kleing@19023
   890
  assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
kleing@19023
   891
  shows "X -- a --> L"
kleing@19023
   892
proof (rule ccontr)
kleing@19023
   893
  assume "\<not> (X -- a --> L)"
huffman@20563
   894
  hence "\<not> (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & norm (x - a) < s --> norm (X x - L) < r)" by (unfold LIM_def)
huffman@20563
   895
  hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. \<not>(x \<noteq> a \<and> \<bar>x - a\<bar> < s --> norm (X x - L) < r)" by simp
huffman@20563
   896
  hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x - a\<bar> < s \<and> norm (X x - L) \<ge> r)" by (simp add: linorder_not_less)
huffman@20563
   897
  then obtain r where rdef: "r > 0 \<and> (\<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x - a\<bar> < s \<and> norm (X x - L) \<ge> r))" by auto
kleing@19023
   898
huffman@20563
   899
  let ?F = "\<lambda>n::nat. SOME x. x\<noteq>a \<and> \<bar>x - a\<bar> < inverse (real (Suc n)) \<and> norm (X x - L) \<ge> r"
huffman@21165
   900
  have "\<And>n. \<exists>x. x\<noteq>a \<and> \<bar>x - a\<bar> < inverse (real (Suc n)) \<and> norm (X x - L) \<ge> r"
huffman@21165
   901
    using rdef by simp
huffman@21165
   902
  hence F: "\<And>n. ?F n \<noteq> a \<and> \<bar>?F n - a\<bar> < inverse (real (Suc n)) \<and> norm (X (?F n) - L) \<ge> r"
huffman@21165
   903
    by (rule someI_ex)
huffman@21165
   904
  hence F1: "\<And>n. ?F n \<noteq> a"
huffman@21165
   905
    and F2: "\<And>n. \<bar>?F n - a\<bar> < inverse (real (Suc n))"
huffman@21165
   906
    and F3: "\<And>n. norm (X (?F n) - L) \<ge> r"
huffman@21165
   907
    by fast+
huffman@21165
   908
kleing@19023
   909
  have "?F ----> a"
huffman@21165
   910
  proof (rule LIMSEQ_I, unfold real_norm_def)
kleing@19023
   911
      fix e::real
kleing@19023
   912
      assume "0 < e"
kleing@19023
   913
        (* choose no such that inverse (real (Suc n)) < e *)
kleing@19023
   914
      have "\<exists>no. inverse (real (Suc no)) < e" by (rule reals_Archimedean)
kleing@19023
   915
      then obtain m where nodef: "inverse (real (Suc m)) < e" by auto
huffman@21165
   916
      show "\<exists>no. \<forall>n. no \<le> n --> \<bar>?F n - a\<bar> < e"
huffman@21165
   917
      proof (intro exI allI impI)
kleing@19023
   918
        fix n
kleing@19023
   919
        assume mlen: "m \<le> n"
huffman@21165
   920
        have "\<bar>?F n - a\<bar> < inverse (real (Suc n))"
huffman@21165
   921
          by (rule F2)
huffman@21165
   922
        also have "inverse (real (Suc n)) \<le> inverse (real (Suc m))"
kleing@19023
   923
          by auto
huffman@21165
   924
        also from nodef have
kleing@19023
   925
          "inverse (real (Suc m)) < e" .
huffman@21165
   926
        finally show "\<bar>?F n - a\<bar> < e" .
huffman@21165
   927
      qed
kleing@19023
   928
  qed
kleing@19023
   929
  
kleing@19023
   930
  moreover have "\<forall>n. ?F n \<noteq> a"
huffman@21165
   931
    by (rule allI) (rule F1)
huffman@21165
   932
kleing@19023
   933
  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
   934
  ultimately have "(\<lambda>n. X (?F n)) ----> L" by simp
kleing@19023
   935
  
kleing@19023
   936
  moreover have "\<not> ((\<lambda>n. X (?F n)) ----> L)"
kleing@19023
   937
  proof -
kleing@19023
   938
    {
kleing@19023
   939
      fix no::nat
kleing@19023
   940
      obtain n where "n = no + 1" by simp
kleing@19023
   941
      then have nolen: "no \<le> n" by simp
kleing@19023
   942
        (* We prove this by showing that for any m there is an n\<ge>m such that |X (?F n) - L| \<ge> r *)
huffman@21165
   943
      have "norm (X (?F n) - L) \<ge> r"
huffman@21165
   944
        by (rule F3)
huffman@21165
   945
      with nolen have "\<exists>n. no \<le> n \<and> norm (X (?F n) - L) \<ge> r" by fast
kleing@19023
   946
    }
huffman@20563
   947
    then have "(\<forall>no. \<exists>n. no \<le> n \<and> norm (X (?F n) - L) \<ge> r)" by simp
huffman@20563
   948
    with rdef have "\<exists>e>0. (\<forall>no. \<exists>n. no \<le> n \<and> norm (X (?F n) - L) \<ge> e)" by auto
kleing@19023
   949
    thus ?thesis by (unfold LIMSEQ_def, auto simp add: linorder_not_less)
kleing@19023
   950
  qed
kleing@19023
   951
  ultimately show False by simp
kleing@19023
   952
qed
kleing@19023
   953
kleing@19023
   954
lemma LIMSEQ_SEQ_conv:
huffman@20561
   955
  "(\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> (a::real) \<longrightarrow> (\<lambda>n. X (S n)) ----> L) =
huffman@20561
   956
   (X -- a --> L)"
kleing@19023
   957
proof
kleing@19023
   958
  assume "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
kleing@19023
   959
  show "X -- a --> L" by (rule LIMSEQ_SEQ_conv2)
kleing@19023
   960
next
kleing@19023
   961
  assume "(X -- a --> L)"
kleing@19023
   962
  show "\<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
   963
qed
kleing@19023
   964
paulson@10751
   965
end