src/HOL/Hyperreal/Lim.thy
author huffman
Thu Nov 09 00:19:16 2006 +0100 (2006-11-09)
changeset 21257 b7f090c5057d
parent 21239 d4fbe2c87ef1
child 21282 dd647b4d7952
permissions -rw-r--r--
added LIM_norm and related lemmas
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
nipkow@15360
    11
imports SEQ
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"
kleing@19023
    18
        ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60)
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
huffman@20561
    23
  NSLIM :: "['a::real_normed_vector => 'b::real_normed_vector, 'a, 'b] => bool"
kleing@19023
    24
            ("((_)/ -- (_)/ --NS> (_))" [60, 0, 60] 60)
huffman@20552
    25
  "f -- a --NS> L =
huffman@20552
    26
    (\<forall>x. (x \<noteq> star_of a & x @= star_of a --> ( *f* f) x @= star_of L))"
paulson@10751
    27
huffman@20561
    28
  isCont :: "['a::real_normed_vector => 'b::real_normed_vector, 'a] => bool"
wenzelm@19765
    29
  "isCont f a = (f -- a --> (f a))"
paulson@10751
    30
huffman@20561
    31
  isNSCont :: "['a::real_normed_vector => 'b::real_normed_vector, 'a] => bool"
paulson@15228
    32
    --{*NS definition dispenses with limit notions*}
huffman@20552
    33
  "isNSCont f a = (\<forall>y. y @= star_of a -->
huffman@20552
    34
         ( *f* f) y @= star_of (f a))"
paulson@10751
    35
huffman@20752
    36
  isUCont :: "['a::real_normed_vector => 'b::real_normed_vector] => bool"
huffman@20752
    37
  "isUCont f = (\<forall>r>0. \<exists>s>0. \<forall>x y. norm (x - y) < s \<longrightarrow> norm (f x - f y) < r)"
paulson@10751
    38
huffman@20752
    39
  isNSUCont :: "['a::real_normed_vector => 'b::real_normed_vector] => bool"
wenzelm@19765
    40
  "isNSUCont f = (\<forall>x y. x @= y --> ( *f* f) x @= ( *f* f) y)"
paulson@10751
    41
paulson@10751
    42
huffman@20755
    43
subsection {* Limits of Functions *}
paulson@14477
    44
huffman@20755
    45
subsubsection {* Purely standard proofs *}
paulson@14477
    46
paulson@14477
    47
lemma LIM_eq:
paulson@14477
    48
     "f -- a --> L =
huffman@20561
    49
     (\<forall>r>0.\<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r)"
paulson@14477
    50
by (simp add: LIM_def diff_minus)
paulson@14477
    51
huffman@20552
    52
lemma LIM_I:
huffman@20561
    53
     "(!!r. 0<r ==> \<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r)
huffman@20552
    54
      ==> f -- a --> L"
huffman@20552
    55
by (simp add: LIM_eq)
huffman@20552
    56
paulson@14477
    57
lemma LIM_D:
paulson@14477
    58
     "[| f -- a --> L; 0<r |]
huffman@20561
    59
      ==> \<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r"
paulson@14477
    60
by (simp add: LIM_eq)
paulson@14477
    61
huffman@21165
    62
lemma LIM_offset: "f -- a --> L \<Longrightarrow> (\<lambda>x. f (x + k)) -- a - k --> L"
huffman@20756
    63
apply (rule LIM_I)
huffman@20756
    64
apply (drule_tac r="r" in LIM_D, safe)
huffman@20756
    65
apply (rule_tac x="s" in exI, safe)
huffman@20756
    66
apply (drule_tac x="x + k" in spec)
huffman@20756
    67
apply (simp add: compare_rls)
huffman@20756
    68
done
huffman@20756
    69
huffman@21239
    70
lemma LIM_offset_zero: "f -- a --> L \<Longrightarrow> (\<lambda>h. f (a + h)) -- 0 --> L"
huffman@21239
    71
by (drule_tac k="a" in LIM_offset, simp add: add_commute)
huffman@21239
    72
huffman@21239
    73
lemma LIM_offset_zero_cancel: "(\<lambda>h. f (a + h)) -- 0 --> L \<Longrightarrow> f -- a --> L"
huffman@21239
    74
by (drule_tac k="- a" in LIM_offset, simp)
huffman@21239
    75
paulson@15228
    76
lemma LIM_const [simp]: "(%x. k) -- x --> k"
paulson@14477
    77
by (simp add: LIM_def)
paulson@14477
    78
paulson@14477
    79
lemma LIM_add:
huffman@20561
    80
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
paulson@14477
    81
  assumes f: "f -- a --> L" and g: "g -- a --> M"
paulson@14477
    82
  shows "(%x. f x + g(x)) -- a --> (L + M)"
huffman@20552
    83
proof (rule LIM_I)
paulson@14477
    84
  fix r :: real
huffman@20409
    85
  assume r: "0 < r"
paulson@14477
    86
  from LIM_D [OF f half_gt_zero [OF r]]
paulson@14477
    87
  obtain fs
paulson@14477
    88
    where fs:    "0 < fs"
huffman@20561
    89
      and fs_lt: "\<forall>x. x \<noteq> a & norm (x-a) < fs --> norm (f x - L) < r/2"
paulson@14477
    90
  by blast
paulson@14477
    91
  from LIM_D [OF g half_gt_zero [OF r]]
paulson@14477
    92
  obtain gs
paulson@14477
    93
    where gs:    "0 < gs"
huffman@20561
    94
      and gs_lt: "\<forall>x. x \<noteq> a & norm (x-a) < gs --> norm (g x - M) < r/2"
paulson@14477
    95
  by blast
huffman@20561
    96
  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
    97
  proof (intro exI conjI strip)
paulson@14477
    98
    show "0 < min fs gs"  by (simp add: fs gs)
huffman@20561
    99
    fix x :: 'a
huffman@20561
   100
    assume "x \<noteq> a \<and> norm (x-a) < min fs gs"
huffman@20561
   101
    hence "x \<noteq> a \<and> norm (x-a) < fs \<and> norm (x-a) < gs" by simp
paulson@14477
   102
    with fs_lt gs_lt
huffman@20552
   103
    have "norm (f x - L) < r/2" and "norm (g x - M) < r/2" by blast+
huffman@20552
   104
    hence "norm (f x - L) + norm (g x - M) < r" by arith
huffman@20552
   105
    thus "norm (f x + g x - (L + M)) < r"
huffman@20552
   106
      by (blast intro: norm_diff_triangle_ineq order_le_less_trans)
paulson@14477
   107
  qed
paulson@14477
   108
qed
paulson@14477
   109
huffman@21257
   110
lemma LIM_add_zero:
huffman@21257
   111
  "\<lbrakk>f -- a --> 0; g -- a --> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. f x + g x) -- a --> 0"
huffman@21257
   112
by (drule (1) LIM_add, simp)
huffman@21257
   113
huffman@20552
   114
lemma minus_diff_minus:
huffman@20552
   115
  fixes a b :: "'a::ab_group_add"
huffman@20552
   116
  shows "(- a) - (- b) = - (a - b)"
huffman@20552
   117
by simp
huffman@20552
   118
paulson@14477
   119
lemma LIM_minus: "f -- a --> L ==> (%x. -f(x)) -- a --> -L"
huffman@20552
   120
by (simp only: LIM_eq minus_diff_minus norm_minus_cancel)
paulson@14477
   121
paulson@14477
   122
lemma LIM_add_minus:
paulson@14477
   123
    "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
huffman@20552
   124
by (intro LIM_add LIM_minus)
paulson@14477
   125
paulson@14477
   126
lemma LIM_diff:
paulson@14477
   127
    "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) - g(x)) -- x --> l-m"
huffman@20552
   128
by (simp only: diff_minus LIM_add LIM_minus)
paulson@14477
   129
huffman@21239
   130
lemma LIM_zero: "f -- a --> l \<Longrightarrow> (\<lambda>x. f x - l) -- a --> 0"
huffman@21239
   131
by (simp add: LIM_def)
huffman@21239
   132
huffman@21239
   133
lemma LIM_zero_cancel: "(\<lambda>x. f x - l) -- a --> 0 \<Longrightarrow> f -- a --> l"
huffman@21239
   134
by (simp add: LIM_def)
huffman@21239
   135
huffman@21257
   136
lemma LIM_imp_LIM:
huffman@21257
   137
  assumes f: "f -- a --> l"
huffman@21257
   138
  assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> norm (g x - m) \<le> norm (f x - l)"
huffman@21257
   139
  shows "g -- a --> m"
huffman@21257
   140
apply (rule LIM_I, drule LIM_D [OF f], safe)
huffman@21257
   141
apply (rule_tac x="s" in exI, safe)
huffman@21257
   142
apply (drule_tac x="x" in spec, safe)
huffman@21257
   143
apply (erule (1) order_le_less_trans [OF le])
huffman@21257
   144
done
huffman@21257
   145
huffman@21257
   146
lemma LIM_norm: "f -- a --> l \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> norm l"
huffman@21257
   147
by (erule LIM_imp_LIM, simp add: norm_triangle_ineq3)
huffman@21257
   148
huffman@21257
   149
lemma LIM_norm_zero: "f -- a --> 0 \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> 0"
huffman@21257
   150
by (drule LIM_norm, simp)
huffman@21257
   151
huffman@21257
   152
lemma LIM_norm_zero_cancel: "(\<lambda>x. norm (f x)) -- a --> 0 \<Longrightarrow> f -- a --> 0"
huffman@21257
   153
by (erule LIM_imp_LIM, simp)
huffman@21257
   154
huffman@20561
   155
lemma LIM_const_not_eq:
huffman@20561
   156
  fixes a :: "'a::real_normed_div_algebra"
huffman@20561
   157
  shows "k \<noteq> L ==> ~ ((%x. k) -- a --> L)"
huffman@20552
   158
apply (simp add: LIM_eq)
huffman@20552
   159
apply (rule_tac x="norm (k - L)" in exI, simp, safe)
huffman@20561
   160
apply (rule_tac x="a + of_real (s/2)" in exI, simp add: norm_of_real)
huffman@20552
   161
done
paulson@14477
   162
huffman@20561
   163
lemma LIM_const_eq:
huffman@20561
   164
  fixes a :: "'a::real_normed_div_algebra"
huffman@20561
   165
  shows "(%x. k) -- a --> L ==> k = L"
paulson@14477
   166
apply (rule ccontr)
kleing@19023
   167
apply (blast dest: LIM_const_not_eq)
paulson@14477
   168
done
paulson@14477
   169
huffman@20561
   170
lemma LIM_unique:
huffman@20561
   171
  fixes a :: "'a::real_normed_div_algebra"
huffman@20561
   172
  shows "[| f -- a --> L; f -- a --> M |] ==> L = M"
kleing@19023
   173
apply (drule LIM_diff, assumption)
paulson@14477
   174
apply (auto dest!: LIM_const_eq)
paulson@14477
   175
done
paulson@14477
   176
paulson@14477
   177
lemma LIM_mult_zero:
huffman@20561
   178
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_algebra"
paulson@14477
   179
  assumes f: "f -- a --> 0" and g: "g -- a --> 0"
paulson@14477
   180
  shows "(%x. f(x) * g(x)) -- a --> 0"
huffman@20552
   181
proof (rule LIM_I, simp)
paulson@14477
   182
  fix r :: real
paulson@14477
   183
  assume r: "0<r"
paulson@14477
   184
  from LIM_D [OF f zero_less_one]
paulson@14477
   185
  obtain fs
paulson@14477
   186
    where fs:    "0 < fs"
huffman@20561
   187
      and fs_lt: "\<forall>x. x \<noteq> a & norm (x-a) < fs --> norm (f x) < 1"
paulson@14477
   188
  by auto
paulson@14477
   189
  from LIM_D [OF g r]
paulson@14477
   190
  obtain gs
paulson@14477
   191
    where gs:    "0 < gs"
huffman@20561
   192
      and gs_lt: "\<forall>x. x \<noteq> a & norm (x-a) < gs --> norm (g x) < r"
paulson@14477
   193
  by auto
huffman@20561
   194
  show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> a \<and> norm (x-a) < s \<longrightarrow> norm (f x * g x) < r)"
paulson@14477
   195
  proof (intro exI conjI strip)
paulson@14477
   196
    show "0 < min fs gs"  by (simp add: fs gs)
huffman@20561
   197
    fix x :: 'a
huffman@20561
   198
    assume "x \<noteq> a \<and> norm (x-a) < min fs gs"
huffman@20561
   199
    hence  "x \<noteq> a \<and> norm (x-a) < fs \<and> norm (x-a) < gs" by simp
paulson@14477
   200
    with fs_lt gs_lt
huffman@20552
   201
    have "norm (f x) < 1" and "norm (g x) < r" by blast+
huffman@20552
   202
    hence "norm (f x) * norm (g x) < 1*r"
huffman@20552
   203
      by (rule mult_strict_mono' [OF _ _ norm_ge_zero norm_ge_zero])
huffman@20552
   204
    thus "norm (f x * g x) < r"
huffman@20552
   205
      by (simp add: order_le_less_trans [OF norm_mult_ineq])
paulson@14477
   206
  qed
paulson@14477
   207
qed
paulson@14477
   208
paulson@14477
   209
lemma LIM_self: "(%x. x) -- a --> a"
paulson@14477
   210
by (auto simp add: LIM_def)
paulson@14477
   211
paulson@14477
   212
text{*Limits are equal for functions equal except at limit point*}
paulson@14477
   213
lemma LIM_equal:
paulson@14477
   214
     "[| \<forall>x. x \<noteq> a --> (f x = g x) |] ==> (f -- a --> l) = (g -- a --> l)"
paulson@14477
   215
by (simp add: LIM_def)
paulson@14477
   216
huffman@20796
   217
lemma LIM_cong:
huffman@20796
   218
  "\<lbrakk>a = b; \<And>x. x \<noteq> b \<Longrightarrow> f x = g x; l = m\<rbrakk>
huffman@20796
   219
   \<Longrightarrow> (f -- a --> l) = (g -- b --> m)"
huffman@20796
   220
by (simp add: LIM_def)
huffman@20796
   221
paulson@14477
   222
text{*Two uses in Hyperreal/Transcendental.ML*}
paulson@14477
   223
lemma LIM_trans:
paulson@14477
   224
     "[| (%x. f(x) + -g(x)) -- a --> 0;  g -- a --> l |] ==> f -- a --> l"
paulson@14477
   225
apply (drule LIM_add, assumption)
paulson@14477
   226
apply (auto simp add: add_assoc)
paulson@14477
   227
done
paulson@14477
   228
huffman@21239
   229
lemma LIM_compose:
huffman@21239
   230
  assumes g: "g -- l --> g l"
huffman@21239
   231
  assumes f: "f -- a --> l"
huffman@21239
   232
  shows "(\<lambda>x. g (f x)) -- a --> g l"
huffman@21239
   233
proof (rule LIM_I)
huffman@21239
   234
  fix r::real assume r: "0 < r"
huffman@21239
   235
  obtain s where s: "0 < s"
huffman@21239
   236
    and less_r: "\<And>y. \<lbrakk>y \<noteq> l; norm (y - l) < s\<rbrakk> \<Longrightarrow> norm (g y - g l) < r"
huffman@21239
   237
    using LIM_D [OF g r] by fast
huffman@21239
   238
  obtain t where t: "0 < t"
huffman@21239
   239
    and less_s: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < t\<rbrakk> \<Longrightarrow> norm (f x - l) < s"
huffman@21239
   240
    using LIM_D [OF f s] by fast
huffman@21239
   241
huffman@21239
   242
  show "\<exists>t>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < t \<longrightarrow> norm (g (f x) - g l) < r"
huffman@21239
   243
  proof (rule exI, safe)
huffman@21239
   244
    show "0 < t" using t .
huffman@21239
   245
  next
huffman@21239
   246
    fix x assume "x \<noteq> a" and "norm (x - a) < t"
huffman@21239
   247
    hence "norm (f x - l) < s" by (rule less_s)
huffman@21239
   248
    thus "norm (g (f x) - g l) < r"
huffman@21239
   249
      using r less_r by (case_tac "f x = l", simp_all)
huffman@21239
   250
  qed
huffman@21239
   251
qed
huffman@21239
   252
huffman@21239
   253
lemma LIM_o: "\<lbrakk>g -- l --> g l; f -- a --> l\<rbrakk> \<Longrightarrow> (g \<circ> f) -- a --> g l"
huffman@21239
   254
unfolding o_def by (rule LIM_compose)
huffman@21239
   255
huffman@20755
   256
subsubsection {* Purely nonstandard proofs *}
paulson@14477
   257
huffman@20754
   258
lemma NSLIM_I:
huffman@20754
   259
  "(\<And>x. \<lbrakk>x \<noteq> star_of a; x \<approx> star_of a\<rbrakk> \<Longrightarrow> starfun f x \<approx> star_of L)
huffman@20754
   260
   \<Longrightarrow> f -- a --NS> L"
huffman@20754
   261
by (simp add: NSLIM_def)
paulson@14477
   262
huffman@20754
   263
lemma NSLIM_D:
huffman@20754
   264
  "\<lbrakk>f -- a --NS> L; x \<noteq> star_of a; x \<approx> star_of a\<rbrakk>
huffman@20754
   265
   \<Longrightarrow> starfun f x \<approx> star_of L"
huffman@20754
   266
by (simp add: NSLIM_def)
paulson@14477
   267
huffman@20755
   268
text{*Proving properties of limits using nonstandard definition.
huffman@20755
   269
      The properties hold for standard limits as well!*}
huffman@20755
   270
huffman@20755
   271
lemma NSLIM_mult:
huffman@20755
   272
  fixes l m :: "'a::real_normed_algebra"
huffman@20755
   273
  shows "[| f -- x --NS> l; g -- x --NS> m |]
huffman@20755
   274
      ==> (%x. f(x) * g(x)) -- x --NS> (l * m)"
huffman@20755
   275
by (auto simp add: NSLIM_def intro!: approx_mult_HFinite)
huffman@20755
   276
huffman@20794
   277
lemma starfun_scaleR [simp]:
huffman@20794
   278
  "starfun (\<lambda>x. f x *# g x) = (\<lambda>x. scaleHR (starfun f x) (starfun g x))"
huffman@20794
   279
by transfer (rule refl)
huffman@20794
   280
huffman@20794
   281
lemma NSLIM_scaleR:
huffman@20794
   282
  "[| f -- x --NS> l; g -- x --NS> m |]
huffman@20794
   283
      ==> (%x. f(x) *# g(x)) -- x --NS> (l *# m)"
huffman@20794
   284
by (auto simp add: NSLIM_def intro!: approx_scaleR_HFinite)
huffman@20794
   285
huffman@20755
   286
lemma NSLIM_add:
huffman@20755
   287
     "[| f -- x --NS> l; g -- x --NS> m |]
huffman@20755
   288
      ==> (%x. f(x) + g(x)) -- x --NS> (l + m)"
huffman@20755
   289
by (auto simp add: NSLIM_def intro!: approx_add)
huffman@20755
   290
huffman@20755
   291
lemma NSLIM_const [simp]: "(%x. k) -- x --NS> k"
huffman@20755
   292
by (simp add: NSLIM_def)
huffman@20755
   293
huffman@20755
   294
lemma NSLIM_minus: "f -- a --NS> L ==> (%x. -f(x)) -- a --NS> -L"
huffman@20755
   295
by (simp add: NSLIM_def)
huffman@20755
   296
huffman@20755
   297
lemma NSLIM_add_minus: "[| f -- x --NS> l; g -- x --NS> m |] ==> (%x. f(x) + -g(x)) -- x --NS> (l + -m)"
huffman@20755
   298
by (simp only: NSLIM_add NSLIM_minus)
huffman@20755
   299
huffman@20755
   300
lemma NSLIM_inverse:
huffman@20755
   301
  fixes L :: "'a::real_normed_div_algebra"
huffman@20755
   302
  shows "[| f -- a --NS> L;  L \<noteq> 0 |]
huffman@20755
   303
      ==> (%x. inverse(f(x))) -- a --NS> (inverse L)"
huffman@20755
   304
apply (simp add: NSLIM_def, clarify)
huffman@20755
   305
apply (drule spec)
huffman@20755
   306
apply (auto simp add: star_of_approx_inverse)
huffman@20755
   307
done
huffman@20755
   308
huffman@20755
   309
lemma NSLIM_zero:
huffman@20755
   310
  assumes f: "f -- a --NS> l" shows "(%x. f(x) + -l) -- a --NS> 0"
huffman@20755
   311
proof -
huffman@20755
   312
  have "(\<lambda>x. f x + - l) -- a --NS> l + -l"
huffman@20755
   313
    by (rule NSLIM_add_minus [OF f NSLIM_const])
huffman@20755
   314
  thus ?thesis by simp
huffman@20755
   315
qed
huffman@20755
   316
huffman@20755
   317
lemma NSLIM_zero_cancel: "(%x. f(x) - l) -- x --NS> 0 ==> f -- x --NS> l"
huffman@20755
   318
apply (drule_tac g = "%x. l" and m = l in NSLIM_add)
huffman@20755
   319
apply (auto simp add: diff_minus add_assoc)
huffman@20755
   320
done
huffman@20755
   321
huffman@20755
   322
lemma NSLIM_const_not_eq:
huffman@20755
   323
  fixes a :: real (* TODO: generalize to real_normed_div_algebra *)
huffman@20755
   324
  shows "k \<noteq> L ==> ~ ((%x. k) -- a --NS> L)"
huffman@20755
   325
apply (simp add: NSLIM_def)
huffman@20755
   326
apply (rule_tac x="star_of a + epsilon" in exI)
huffman@20755
   327
apply (auto intro: Infinitesimal_add_approx_self [THEN approx_sym]
huffman@20755
   328
            simp add: hypreal_epsilon_not_zero)
huffman@20755
   329
done
huffman@20755
   330
huffman@20755
   331
lemma NSLIM_not_zero:
huffman@20755
   332
  fixes a :: real
huffman@20755
   333
  shows "k \<noteq> 0 ==> ~ ((%x. k) -- a --NS> 0)"
huffman@20755
   334
by (rule NSLIM_const_not_eq)
huffman@20755
   335
huffman@20755
   336
lemma NSLIM_const_eq:
huffman@20755
   337
  fixes a :: real
huffman@20755
   338
  shows "(%x. k) -- a --NS> L ==> k = L"
huffman@20755
   339
apply (rule ccontr)
huffman@20755
   340
apply (blast dest: NSLIM_const_not_eq)
huffman@20755
   341
done
huffman@20755
   342
huffman@20755
   343
text{* can actually be proved more easily by unfolding the definition!*}
huffman@20755
   344
lemma NSLIM_unique:
huffman@20755
   345
  fixes a :: real
huffman@20755
   346
  shows "[| f -- a --NS> L; f -- a --NS> M |] ==> L = M"
huffman@20755
   347
apply (drule NSLIM_minus)
huffman@20755
   348
apply (drule NSLIM_add, assumption)
huffman@20755
   349
apply (auto dest!: NSLIM_const_eq [symmetric])
huffman@20755
   350
apply (simp add: diff_def [symmetric])
huffman@20755
   351
done
huffman@20755
   352
huffman@20755
   353
lemma NSLIM_mult_zero:
huffman@20755
   354
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_algebra"
huffman@20755
   355
  shows "[| f -- x --NS> 0; g -- x --NS> 0 |] ==> (%x. f(x)*g(x)) -- x --NS> 0"
huffman@20755
   356
by (drule NSLIM_mult, auto)
huffman@20755
   357
huffman@20755
   358
lemma NSLIM_self: "(%x. x) -- a --NS> a"
huffman@20755
   359
by (simp add: NSLIM_def)
huffman@20755
   360
huffman@20755
   361
subsubsection {* Equivalence of @{term LIM} and @{term NSLIM} *}
huffman@20755
   362
huffman@20754
   363
lemma LIM_NSLIM:
huffman@20754
   364
  assumes f: "f -- a --> L" shows "f -- a --NS> L"
huffman@20754
   365
proof (rule NSLIM_I)
huffman@20754
   366
  fix x
huffman@20754
   367
  assume neq: "x \<noteq> star_of a"
huffman@20754
   368
  assume approx: "x \<approx> star_of a"
huffman@20754
   369
  have "starfun f x - star_of L \<in> Infinitesimal"
huffman@20754
   370
  proof (rule InfinitesimalI2)
huffman@20754
   371
    fix r::real assume r: "0 < r"
huffman@20754
   372
    from LIM_D [OF f r]
huffman@20754
   373
    obtain s where s: "0 < s" and
huffman@20754
   374
      less_r: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < s\<rbrakk> \<Longrightarrow> norm (f x - L) < r"
huffman@20754
   375
      by fast
huffman@20754
   376
    from less_r have less_r':
huffman@20754
   377
       "\<And>x. \<lbrakk>x \<noteq> star_of a; hnorm (x - star_of a) < star_of s\<rbrakk>
huffman@20754
   378
        \<Longrightarrow> hnorm (starfun f x - star_of L) < star_of r"
huffman@20754
   379
      by transfer
huffman@20754
   380
    from approx have "x - star_of a \<in> Infinitesimal"
huffman@20754
   381
      by (unfold approx_def)
huffman@20754
   382
    hence "hnorm (x - star_of a) < star_of s"
huffman@20754
   383
      using s by (rule InfinitesimalD2)
huffman@20754
   384
    with neq show "hnorm (starfun f x - star_of L) < star_of r"
huffman@20754
   385
      by (rule less_r')
huffman@20754
   386
  qed
huffman@20754
   387
  thus "starfun f x \<approx> star_of L"
huffman@20754
   388
    by (unfold approx_def)
huffman@20754
   389
qed
huffman@20552
   390
huffman@20754
   391
lemma NSLIM_LIM:
huffman@20754
   392
  assumes f: "f -- a --NS> L" shows "f -- a --> L"
huffman@20754
   393
proof (rule LIM_I)
huffman@20754
   394
  fix r::real assume r: "0 < r"
huffman@20754
   395
  have "\<exists>s>0. \<forall>x. x \<noteq> star_of a \<and> hnorm (x - star_of a) < s
huffman@20754
   396
        \<longrightarrow> hnorm (starfun f x - star_of L) < star_of r"
huffman@20754
   397
  proof (rule exI, safe)
huffman@20754
   398
    show "0 < epsilon" by (rule hypreal_epsilon_gt_zero)
huffman@20754
   399
  next
huffman@20754
   400
    fix x assume neq: "x \<noteq> star_of a"
huffman@20754
   401
    assume "hnorm (x - star_of a) < epsilon"
huffman@20754
   402
    with Infinitesimal_epsilon
huffman@20754
   403
    have "x - star_of a \<in> Infinitesimal"
huffman@20754
   404
      by (rule hnorm_less_Infinitesimal)
huffman@20754
   405
    hence "x \<approx> star_of a"
huffman@20754
   406
      by (unfold approx_def)
huffman@20754
   407
    with f neq have "starfun f x \<approx> star_of L"
huffman@20754
   408
      by (rule NSLIM_D)
huffman@20754
   409
    hence "starfun f x - star_of L \<in> Infinitesimal"
huffman@20754
   410
      by (unfold approx_def)
huffman@20754
   411
    thus "hnorm (starfun f x - star_of L) < star_of r"
huffman@20754
   412
      using r by (rule InfinitesimalD2)
huffman@20754
   413
  qed
huffman@20754
   414
  thus "\<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - L) < r"
huffman@20754
   415
    by transfer
huffman@20754
   416
qed
paulson@14477
   417
paulson@15228
   418
theorem LIM_NSLIM_iff: "(f -- x --> L) = (f -- x --NS> L)"
paulson@14477
   419
by (blast intro: LIM_NSLIM NSLIM_LIM)
paulson@14477
   420
huffman@20755
   421
subsubsection {* Derived theorems about @{term LIM} *}
paulson@14477
   422
paulson@15228
   423
lemma LIM_mult2:
huffman@20552
   424
  fixes l m :: "'a::real_normed_algebra"
huffman@20552
   425
  shows "[| f -- x --> l; g -- x --> m |]
huffman@20552
   426
      ==> (%x. f(x) * g(x)) -- x --> (l * m)"
paulson@14477
   427
by (simp add: LIM_NSLIM_iff NSLIM_mult)
paulson@14477
   428
huffman@20794
   429
lemma LIM_scaleR:
huffman@20794
   430
  "[| f -- x --> l; g -- x --> m |]
huffman@20794
   431
      ==> (%x. f(x) *# g(x)) -- x --> (l *# m)"
huffman@20794
   432
by (simp add: LIM_NSLIM_iff NSLIM_scaleR)
huffman@20794
   433
paulson@15228
   434
lemma LIM_add2:
paulson@15228
   435
     "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + g(x)) -- x --> (l + m)"
paulson@14477
   436
by (simp add: LIM_NSLIM_iff NSLIM_add)
paulson@14477
   437
paulson@14477
   438
lemma LIM_const2: "(%x. k) -- x --> k"
paulson@14477
   439
by (simp add: LIM_NSLIM_iff)
paulson@14477
   440
paulson@14477
   441
lemma LIM_minus2: "f -- a --> L ==> (%x. -f(x)) -- a --> -L"
paulson@14477
   442
by (simp add: LIM_NSLIM_iff NSLIM_minus)
paulson@14477
   443
paulson@14477
   444
lemma LIM_add_minus2: "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
paulson@14477
   445
by (simp add: LIM_NSLIM_iff NSLIM_add_minus)
paulson@14477
   446
huffman@20552
   447
lemma LIM_inverse:
huffman@20653
   448
  fixes L :: "'a::real_normed_div_algebra"
huffman@20552
   449
  shows "[| f -- a --> L; L \<noteq> 0 |]
huffman@20552
   450
      ==> (%x. inverse(f(x))) -- a --> (inverse L)"
paulson@14477
   451
by (simp add: LIM_NSLIM_iff NSLIM_inverse)
paulson@14477
   452
paulson@14477
   453
lemma LIM_zero2: "f -- a --> l ==> (%x. f(x) + -l) -- a --> 0"
paulson@14477
   454
by (simp add: LIM_NSLIM_iff NSLIM_zero)
paulson@14477
   455
huffman@20561
   456
lemma LIM_unique2:
huffman@20561
   457
  fixes a :: real
huffman@20561
   458
  shows "[| f -- a --> L; f -- a --> M |] ==> L = M"
paulson@14477
   459
by (simp add: LIM_NSLIM_iff NSLIM_unique)
paulson@14477
   460
paulson@14477
   461
(* we can use the corresponding thm LIM_mult2 *)
paulson@14477
   462
(* for standard definition of limit           *)
paulson@14477
   463
huffman@20552
   464
lemma LIM_mult_zero2:
huffman@20561
   465
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_algebra"
huffman@20552
   466
  shows "[| f -- x --> 0; g -- x --> 0 |] ==> (%x. f(x)*g(x)) -- x --> 0"
paulson@14477
   467
by (drule LIM_mult2, auto)
paulson@14477
   468
paulson@14477
   469
huffman@20755
   470
subsection {* Continuity *}
paulson@14477
   471
huffman@21239
   472
subsubsection {* Purely standard proofs *}
huffman@21239
   473
huffman@21239
   474
lemma LIM_isCont_iff: "(f -- a --> f a) = ((\<lambda>h. f (a + h)) -- 0 --> f a)"
huffman@21239
   475
by (rule iffI [OF LIM_offset_zero LIM_offset_zero_cancel])
huffman@21239
   476
huffman@21239
   477
lemma isCont_iff: "isCont f x = (\<lambda>h. f (x + h)) -- 0 --> f x"
huffman@21239
   478
by (simp add: isCont_def LIM_isCont_iff)
huffman@21239
   479
huffman@21239
   480
lemma isCont_Id: "isCont (\<lambda>x. x) a"
huffman@21239
   481
unfolding isCont_def by (rule LIM_self)
huffman@21239
   482
huffman@21239
   483
lemma isCont_const [simp]: "isCont (%x. k) a"
huffman@21239
   484
unfolding isCont_def by (rule LIM_const)
huffman@21239
   485
huffman@21239
   486
lemma isCont_add: "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x + g x) a"
huffman@21239
   487
unfolding isCont_def by (rule LIM_add)
huffman@21239
   488
huffman@21239
   489
lemma isCont_minus: "isCont f a \<Longrightarrow> isCont (\<lambda>x. - f x) a"
huffman@21239
   490
unfolding isCont_def by (rule LIM_minus)
huffman@21239
   491
huffman@21239
   492
lemma isCont_diff: "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x - g x) a"
huffman@21239
   493
unfolding isCont_def by (rule LIM_diff)
huffman@21239
   494
huffman@21239
   495
lemma isCont_mult:
huffman@21239
   496
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_algebra"
huffman@21239
   497
  shows "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) * g(x)) a"
huffman@21239
   498
unfolding isCont_def by (rule LIM_mult2)
huffman@21239
   499
huffman@21239
   500
lemma isCont_inverse:
huffman@21239
   501
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_div_algebra"
huffman@21239
   502
  shows "[| isCont f x; f x \<noteq> 0 |] ==> isCont (%x. inverse (f x)) x"
huffman@21239
   503
unfolding isCont_def by (rule LIM_inverse)
huffman@21239
   504
huffman@21239
   505
lemma isCont_LIM_compose:
huffman@21239
   506
  "\<lbrakk>isCont g l; f -- a --> l\<rbrakk> \<Longrightarrow> (\<lambda>x. g (f x)) -- a --> g l"
huffman@21239
   507
unfolding isCont_def by (rule LIM_compose)
huffman@21239
   508
huffman@21239
   509
lemma isCont_o2: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. g (f x)) a"
huffman@21239
   510
unfolding isCont_def by (rule LIM_compose)
huffman@21239
   511
huffman@21239
   512
lemma isCont_o: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (g o f) a"
huffman@21239
   513
unfolding o_def by (rule isCont_o2)
huffman@21239
   514
huffman@21239
   515
subsubsection {* Nonstandard proofs *}
huffman@21239
   516
paulson@14477
   517
lemma isNSContD: "[| isNSCont f a; y \<approx> hypreal_of_real a |] ==> ( *f* f) y \<approx> hypreal_of_real (f a)"
paulson@14477
   518
by (simp add: isNSCont_def)
paulson@14477
   519
paulson@14477
   520
lemma isNSCont_NSLIM: "isNSCont f a ==> f -- a --NS> (f a) "
paulson@14477
   521
by (simp add: isNSCont_def NSLIM_def)
paulson@14477
   522
paulson@14477
   523
lemma NSLIM_isNSCont: "f -- a --NS> (f a) ==> isNSCont f a"
paulson@14477
   524
apply (simp add: isNSCont_def NSLIM_def, auto)
huffman@20561
   525
apply (case_tac "y = star_of a", auto)
paulson@14477
   526
done
paulson@14477
   527
paulson@15228
   528
text{*NS continuity can be defined using NS Limit in
paulson@15228
   529
    similar fashion to standard def of continuity*}
paulson@14477
   530
lemma isNSCont_NSLIM_iff: "(isNSCont f a) = (f -- a --NS> (f a))"
paulson@14477
   531
by (blast intro: isNSCont_NSLIM NSLIM_isNSCont)
paulson@14477
   532
paulson@15228
   533
text{*Hence, NS continuity can be given
paulson@15228
   534
  in terms of standard limit*}
paulson@14477
   535
lemma isNSCont_LIM_iff: "(isNSCont f a) = (f -- a --> (f a))"
paulson@14477
   536
by (simp add: LIM_NSLIM_iff isNSCont_NSLIM_iff)
paulson@14477
   537
paulson@15228
   538
text{*Moreover, it's trivial now that NS continuity
paulson@15228
   539
  is equivalent to standard continuity*}
paulson@14477
   540
lemma isNSCont_isCont_iff: "(isNSCont f a) = (isCont f a)"
paulson@14477
   541
apply (simp add: isCont_def)
paulson@14477
   542
apply (rule isNSCont_LIM_iff)
paulson@14477
   543
done
paulson@14477
   544
paulson@15228
   545
text{*Standard continuity ==> NS continuity*}
paulson@14477
   546
lemma isCont_isNSCont: "isCont f a ==> isNSCont f a"
paulson@14477
   547
by (erule isNSCont_isCont_iff [THEN iffD2])
paulson@14477
   548
paulson@15228
   549
text{*NS continuity ==> Standard continuity*}
paulson@14477
   550
lemma isNSCont_isCont: "isNSCont f a ==> isCont f a"
paulson@14477
   551
by (erule isNSCont_isCont_iff [THEN iffD1])
paulson@14477
   552
paulson@14477
   553
text{*Alternative definition of continuity*}
paulson@14477
   554
(* Prove equivalence between NS limits - *)
paulson@14477
   555
(* seems easier than using standard def  *)
paulson@14477
   556
lemma NSLIM_h_iff: "(f -- a --NS> L) = ((%h. f(a + h)) -- 0 --NS> L)"
paulson@14477
   557
apply (simp add: NSLIM_def, auto)
huffman@20561
   558
apply (drule_tac x = "star_of a + x" in spec)
huffman@20561
   559
apply (drule_tac [2] x = "- star_of a + x" in spec, safe, simp)
huffman@20561
   560
apply (erule mem_infmal_iff [THEN iffD2, THEN Infinitesimal_add_approx_self [THEN approx_sym]])
huffman@20561
   561
apply (erule_tac [3] approx_minus_iff2 [THEN iffD1])
huffman@20561
   562
 prefer 2 apply (simp add: add_commute diff_def [symmetric])
huffman@20561
   563
apply (rule_tac x = x in star_cases)
huffman@17318
   564
apply (rule_tac [2] x = x in star_cases)
huffman@17318
   565
apply (auto simp add: starfun star_of_def star_n_minus star_n_add add_assoc approx_refl star_n_zero_num)
paulson@14477
   566
done
paulson@14477
   567
paulson@14477
   568
lemma NSLIM_isCont_iff: "(f -- a --NS> f a) = ((%h. f(a + h)) -- 0 --NS> f a)"
paulson@14477
   569
by (rule NSLIM_h_iff)
paulson@14477
   570
paulson@14477
   571
lemma isNSCont_minus: "isNSCont f a ==> isNSCont (%x. - f x) a"
paulson@14477
   572
by (simp add: isNSCont_def)
paulson@14477
   573
huffman@20552
   574
lemma isNSCont_inverse:
huffman@20653
   575
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_div_algebra"
huffman@20552
   576
  shows "[| isNSCont f x; f x \<noteq> 0 |] ==> isNSCont (%x. inverse (f x)) x"
paulson@14477
   577
by (auto intro: isCont_inverse simp add: isNSCont_isCont_iff)
paulson@14477
   578
paulson@15228
   579
lemma isNSCont_const [simp]: "isNSCont (%x. k) a"
paulson@14477
   580
by (simp add: isNSCont_def)
paulson@14477
   581
huffman@20561
   582
lemma isNSCont_abs [simp]: "isNSCont abs (a::real)"
paulson@14477
   583
apply (simp add: isNSCont_def)
paulson@14477
   584
apply (auto intro: approx_hrabs simp add: hypreal_of_real_hrabs [symmetric] starfun_rabs_hrabs)
paulson@14477
   585
done
paulson@14477
   586
huffman@20561
   587
lemma isCont_abs [simp]: "isCont abs (a::real)"
paulson@14477
   588
by (auto simp add: isNSCont_isCont_iff [symmetric])
paulson@15228
   589
paulson@14477
   590
paulson@14477
   591
(****************************************************************
paulson@14477
   592
(%* Leave as commented until I add topology theory or remove? *%)
paulson@14477
   593
(%*------------------------------------------------------------
paulson@14477
   594
  Elementary topology proof for a characterisation of
paulson@14477
   595
  continuity now: a function f is continuous if and only
paulson@14477
   596
  if the inverse image, {x. f(x) \<in> A}, of any open set A
paulson@14477
   597
  is always an open set
paulson@14477
   598
 ------------------------------------------------------------*%)
paulson@14477
   599
Goal "[| isNSopen A; \<forall>x. isNSCont f x |]
paulson@14477
   600
               ==> isNSopen {x. f x \<in> A}"
paulson@14477
   601
by (auto_tac (claset(),simpset() addsimps [isNSopen_iff1]));
paulson@14477
   602
by (dtac (mem_monad_approx RS approx_sym);
paulson@14477
   603
by (dres_inst_tac [("x","a")] spec 1);
paulson@14477
   604
by (dtac isNSContD 1 THEN assume_tac 1)
paulson@14477
   605
by (dtac bspec 1 THEN assume_tac 1)
paulson@14477
   606
by (dres_inst_tac [("x","( *f* f) x")] approx_mem_monad2 1);
paulson@14477
   607
by (blast_tac (claset() addIs [starfun_mem_starset]);
paulson@14477
   608
qed "isNSCont_isNSopen";
paulson@14477
   609
paulson@14477
   610
Goalw [isNSCont_def]
paulson@14477
   611
          "\<forall>A. isNSopen A --> isNSopen {x. f x \<in> A} \
paulson@14477
   612
\              ==> isNSCont f x";
paulson@14477
   613
by (auto_tac (claset() addSIs [(mem_infmal_iff RS iffD1) RS
paulson@14477
   614
     (approx_minus_iff RS iffD2)],simpset() addsimps
paulson@14477
   615
      [Infinitesimal_def,SReal_iff]));
paulson@14477
   616
by (dres_inst_tac [("x","{z. abs(z + -f(x)) < ya}")] spec 1);
paulson@14477
   617
by (etac (isNSopen_open_interval RSN (2,impE));
paulson@14477
   618
by (auto_tac (claset(),simpset() addsimps [isNSopen_def,isNSnbhd_def]));
paulson@14477
   619
by (dres_inst_tac [("x","x")] spec 1);
paulson@14477
   620
by (auto_tac (claset() addDs [approx_sym RS approx_mem_monad],
paulson@14477
   621
    simpset() addsimps [hypreal_of_real_zero RS sym,STAR_starfun_rabs_add_minus]));
paulson@14477
   622
qed "isNSopen_isNSCont";
paulson@14477
   623
paulson@14477
   624
Goal "(\<forall>x. isNSCont f x) = \
paulson@14477
   625
\     (\<forall>A. isNSopen A --> isNSopen {x. f(x) \<in> A})";
paulson@14477
   626
by (blast_tac (claset() addIs [isNSCont_isNSopen,
paulson@14477
   627
    isNSopen_isNSCont]);
paulson@14477
   628
qed "isNSCont_isNSopen_iff";
paulson@14477
   629
paulson@14477
   630
(%*------- Standard version of same theorem --------*%)
paulson@14477
   631
Goal "(\<forall>x. isCont f x) = \
paulson@14477
   632
\         (\<forall>A. isopen A --> isopen {x. f(x) \<in> A})";
paulson@14477
   633
by (auto_tac (claset() addSIs [isNSCont_isNSopen_iff],
paulson@14477
   634
              simpset() addsimps [isNSopen_isopen_iff RS sym,
paulson@14477
   635
              isNSCont_isCont_iff RS sym]));
paulson@14477
   636
qed "isCont_isopen_iff";
paulson@14477
   637
*******************************************************************)
paulson@14477
   638
huffman@20755
   639
subsection {* Uniform Continuity *}
huffman@20755
   640
paulson@14477
   641
lemma isNSUContD: "[| isNSUCont f; x \<approx> y|] ==> ( *f* f) x \<approx> ( *f* f) y"
paulson@14477
   642
by (simp add: isNSUCont_def)
paulson@14477
   643
paulson@14477
   644
lemma isUCont_isCont: "isUCont f ==> isCont f x"
paulson@14477
   645
by (simp add: isUCont_def isCont_def LIM_def, meson)
paulson@14477
   646
huffman@20754
   647
lemma isUCont_isNSUCont:
huffman@20754
   648
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
huffman@20754
   649
  assumes f: "isUCont f" shows "isNSUCont f"
huffman@20754
   650
proof (unfold isNSUCont_def, safe)
huffman@20754
   651
  fix x y :: "'a star"
huffman@20754
   652
  assume approx: "x \<approx> y"
huffman@20754
   653
  have "starfun f x - starfun f y \<in> Infinitesimal"
huffman@20754
   654
  proof (rule InfinitesimalI2)
huffman@20754
   655
    fix r::real assume r: "0 < r"
huffman@20754
   656
    with f obtain s where s: "0 < s" and
huffman@20754
   657
      less_r: "\<And>x y. norm (x - y) < s \<Longrightarrow> norm (f x - f y) < r"
huffman@20754
   658
      by (auto simp add: isUCont_def)
huffman@20754
   659
    from less_r have less_r':
huffman@20754
   660
       "\<And>x y. hnorm (x - y) < star_of s
huffman@20754
   661
        \<Longrightarrow> hnorm (starfun f x - starfun f y) < star_of r"
huffman@20754
   662
      by transfer
huffman@20754
   663
    from approx have "x - y \<in> Infinitesimal"
huffman@20754
   664
      by (unfold approx_def)
huffman@20754
   665
    hence "hnorm (x - y) < star_of s"
huffman@20754
   666
      using s by (rule InfinitesimalD2)
huffman@20754
   667
    thus "hnorm (starfun f x - starfun f y) < star_of r"
huffman@20754
   668
      by (rule less_r')
huffman@20754
   669
  qed
huffman@20754
   670
  thus "starfun f x \<approx> starfun f y"
huffman@20754
   671
    by (unfold approx_def)
huffman@20754
   672
qed
paulson@14477
   673
paulson@14477
   674
lemma isNSUCont_isUCont:
huffman@20754
   675
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
huffman@20754
   676
  assumes f: "isNSUCont f" shows "isUCont f"
huffman@20754
   677
proof (unfold isUCont_def, safe)
huffman@20754
   678
  fix r::real assume r: "0 < r"
huffman@20754
   679
  have "\<exists>s>0. \<forall>x y. hnorm (x - y) < s
huffman@20754
   680
        \<longrightarrow> hnorm (starfun f x - starfun f y) < star_of r"
huffman@20754
   681
  proof (rule exI, safe)
huffman@20754
   682
    show "0 < epsilon" by (rule hypreal_epsilon_gt_zero)
huffman@20754
   683
  next
huffman@20754
   684
    fix x y :: "'a star"
huffman@20754
   685
    assume "hnorm (x - y) < epsilon"
huffman@20754
   686
    with Infinitesimal_epsilon
huffman@20754
   687
    have "x - y \<in> Infinitesimal"
huffman@20754
   688
      by (rule hnorm_less_Infinitesimal)
huffman@20754
   689
    hence "x \<approx> y"
huffman@20754
   690
      by (unfold approx_def)
huffman@20754
   691
    with f have "starfun f x \<approx> starfun f y"
huffman@20754
   692
      by (simp add: isNSUCont_def)
huffman@20754
   693
    hence "starfun f x - starfun f y \<in> Infinitesimal"
huffman@20754
   694
      by (unfold approx_def)
huffman@20754
   695
    thus "hnorm (starfun f x - starfun f y) < star_of r"
huffman@20754
   696
      using r by (rule InfinitesimalD2)
huffman@20754
   697
  qed
huffman@20754
   698
  thus "\<exists>s>0. \<forall>x y. norm (x - y) < s \<longrightarrow> norm (f x - f y) < r"
huffman@20754
   699
    by transfer
huffman@20754
   700
qed
paulson@14477
   701
huffman@21165
   702
subsection {* Relation of LIM and LIMSEQ *}
kleing@19023
   703
kleing@19023
   704
lemma LIMSEQ_SEQ_conv1:
huffman@21165
   705
  fixes a :: "'a::real_normed_vector"
huffman@21165
   706
  assumes X: "X -- a --> L"
kleing@19023
   707
  shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
huffman@21165
   708
proof (safe intro!: LIMSEQ_I)
huffman@21165
   709
  fix S :: "nat \<Rightarrow> 'a"
huffman@21165
   710
  fix r :: real
huffman@21165
   711
  assume rgz: "0 < r"
huffman@21165
   712
  assume as: "\<forall>n. S n \<noteq> a"
huffman@21165
   713
  assume S: "S ----> a"
huffman@21165
   714
  from LIM_D [OF X rgz] obtain s
huffman@21165
   715
    where sgz: "0 < s"
huffman@21165
   716
    and aux: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < s\<rbrakk> \<Longrightarrow> norm (X x - L) < r"
huffman@21165
   717
    by fast
huffman@21165
   718
  from LIMSEQ_D [OF S sgz]
huffman@21165
   719
  obtain no where "\<forall>n\<ge>no. norm (S n - a) < s" by fast
huffman@21165
   720
  hence "\<forall>n\<ge>no. norm (X (S n) - L) < r" by (simp add: aux as)
huffman@21165
   721
  thus "\<exists>no. \<forall>n\<ge>no. norm (X (S n) - L) < r" ..
kleing@19023
   722
qed
kleing@19023
   723
kleing@19023
   724
lemma LIMSEQ_SEQ_conv2:
huffman@20561
   725
  fixes a :: real
kleing@19023
   726
  assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
kleing@19023
   727
  shows "X -- a --> L"
kleing@19023
   728
proof (rule ccontr)
kleing@19023
   729
  assume "\<not> (X -- a --> L)"
huffman@20563
   730
  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
   731
  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
   732
  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
   733
  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
   734
huffman@20563
   735
  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
   736
  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
   737
    using rdef by simp
huffman@21165
   738
  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
   739
    by (rule someI_ex)
huffman@21165
   740
  hence F1: "\<And>n. ?F n \<noteq> a"
huffman@21165
   741
    and F2: "\<And>n. \<bar>?F n - a\<bar> < inverse (real (Suc n))"
huffman@21165
   742
    and F3: "\<And>n. norm (X (?F n) - L) \<ge> r"
huffman@21165
   743
    by fast+
huffman@21165
   744
kleing@19023
   745
  have "?F ----> a"
huffman@21165
   746
  proof (rule LIMSEQ_I, unfold real_norm_def)
kleing@19023
   747
      fix e::real
kleing@19023
   748
      assume "0 < e"
kleing@19023
   749
        (* choose no such that inverse (real (Suc n)) < e *)
kleing@19023
   750
      have "\<exists>no. inverse (real (Suc no)) < e" by (rule reals_Archimedean)
kleing@19023
   751
      then obtain m where nodef: "inverse (real (Suc m)) < e" by auto
huffman@21165
   752
      show "\<exists>no. \<forall>n. no \<le> n --> \<bar>?F n - a\<bar> < e"
huffman@21165
   753
      proof (intro exI allI impI)
kleing@19023
   754
        fix n
kleing@19023
   755
        assume mlen: "m \<le> n"
huffman@21165
   756
        have "\<bar>?F n - a\<bar> < inverse (real (Suc n))"
huffman@21165
   757
          by (rule F2)
huffman@21165
   758
        also have "inverse (real (Suc n)) \<le> inverse (real (Suc m))"
kleing@19023
   759
          by auto
huffman@21165
   760
        also from nodef have
kleing@19023
   761
          "inverse (real (Suc m)) < e" .
huffman@21165
   762
        finally show "\<bar>?F n - a\<bar> < e" .
huffman@21165
   763
      qed
kleing@19023
   764
  qed
kleing@19023
   765
  
kleing@19023
   766
  moreover have "\<forall>n. ?F n \<noteq> a"
huffman@21165
   767
    by (rule allI) (rule F1)
huffman@21165
   768
kleing@19023
   769
  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
   770
  ultimately have "(\<lambda>n. X (?F n)) ----> L" by simp
kleing@19023
   771
  
kleing@19023
   772
  moreover have "\<not> ((\<lambda>n. X (?F n)) ----> L)"
kleing@19023
   773
  proof -
kleing@19023
   774
    {
kleing@19023
   775
      fix no::nat
kleing@19023
   776
      obtain n where "n = no + 1" by simp
kleing@19023
   777
      then have nolen: "no \<le> n" by simp
kleing@19023
   778
        (* 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
   779
      have "norm (X (?F n) - L) \<ge> r"
huffman@21165
   780
        by (rule F3)
huffman@21165
   781
      with nolen have "\<exists>n. no \<le> n \<and> norm (X (?F n) - L) \<ge> r" by fast
kleing@19023
   782
    }
huffman@20563
   783
    then have "(\<forall>no. \<exists>n. no \<le> n \<and> norm (X (?F n) - L) \<ge> r)" by simp
huffman@20563
   784
    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
   785
    thus ?thesis by (unfold LIMSEQ_def, auto simp add: linorder_not_less)
kleing@19023
   786
  qed
kleing@19023
   787
  ultimately show False by simp
kleing@19023
   788
qed
kleing@19023
   789
kleing@19023
   790
lemma LIMSEQ_SEQ_conv:
huffman@20561
   791
  "(\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> (a::real) \<longrightarrow> (\<lambda>n. X (S n)) ----> L) =
huffman@20561
   792
   (X -- a --> L)"
kleing@19023
   793
proof
kleing@19023
   794
  assume "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
kleing@19023
   795
  show "X -- a --> L" by (rule LIMSEQ_SEQ_conv2)
kleing@19023
   796
next
kleing@19023
   797
  assume "(X -- a --> L)"
kleing@19023
   798
  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
   799
qed
kleing@19023
   800
paulson@10751
   801
end