src/HOL/Hyperreal/SEQ.thy
author huffman
Mon Oct 02 21:30:05 2006 +0200 (2006-10-02)
changeset 20830 65ba80cae6df
parent 20829 863b187780bb
child 21139 c957e02e7a36
permissions -rw-r--r--
add axclass banach for complete normed vector spaces
paulson@10751
     1
(*  Title       : SEQ.thy
paulson@10751
     2
    Author      : Jacques D. Fleuriot
paulson@10751
     3
    Copyright   : 1998  University of Cambridge
paulson@10751
     4
    Description : Convergence of sequences and series
paulson@15082
     5
    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
avigad@16819
     6
    Additional contributions by Jeremy Avigad
paulson@15082
     7
*)
paulson@10751
     8
huffman@17439
     9
header {* Sequences and Series *}
huffman@17439
    10
nipkow@15131
    11
theory SEQ
nipkow@15236
    12
imports NatStar
nipkow@15131
    13
begin
paulson@10751
    14
wenzelm@19765
    15
definition
paulson@10751
    16
huffman@20552
    17
  LIMSEQ :: "[nat => 'a::real_normed_vector, 'a] => bool"
huffman@20552
    18
    ("((_)/ ----> (_))" [60, 60] 60)
paulson@15082
    19
    --{*Standard definition of convergence of sequence*}
huffman@20563
    20
  "X ----> L = (\<forall>r. 0 < r --> (\<exists>no. \<forall>n. no \<le> n --> norm (X n - L) < r))"
paulson@10751
    21
huffman@20552
    22
  NSLIMSEQ :: "[nat => 'a::real_normed_vector, 'a] => bool"
huffman@20552
    23
    ("((_)/ ----NS> (_))" [60, 60] 60)
paulson@15082
    24
    --{*Nonstandard definition of convergence of sequence*}
huffman@20552
    25
  "X ----NS> L = (\<forall>N \<in> HNatInfinite. ( *f* X) N \<approx> star_of L)"
paulson@15082
    26
huffman@20693
    27
  lim :: "(nat => 'a::real_normed_vector) => 'a"
paulson@15082
    28
    --{*Standard definition of limit using choice operator*}
huffman@20682
    29
  "lim X = (THE L. X ----> L)"
paulson@10751
    30
huffman@20693
    31
  nslim :: "(nat => 'a::real_normed_vector) => 'a"
paulson@15082
    32
    --{*Nonstandard definition of limit using choice operator*}
huffman@20682
    33
  "nslim X = (THE L. X ----NS> L)"
paulson@10751
    34
huffman@20552
    35
  convergent :: "(nat => 'a::real_normed_vector) => bool"
paulson@15082
    36
    --{*Standard definition of convergence*}
huffman@20682
    37
  "convergent X = (\<exists>L. X ----> L)"
paulson@10751
    38
huffman@20552
    39
  NSconvergent :: "(nat => 'a::real_normed_vector) => bool"
paulson@15082
    40
    --{*Nonstandard definition of convergence*}
huffman@20682
    41
  "NSconvergent X = (\<exists>L. X ----NS> L)"
paulson@15082
    42
huffman@20552
    43
  Bseq :: "(nat => 'a::real_normed_vector) => bool"
paulson@15082
    44
    --{*Standard definition for bounded sequence*}
huffman@20552
    45
  "Bseq X = (\<exists>K>0.\<forall>n. norm (X n) \<le> K)"
paulson@10751
    46
huffman@20552
    47
  NSBseq :: "(nat => 'a::real_normed_vector) => bool"
paulson@15082
    48
    --{*Nonstandard definition for bounded sequence*}
wenzelm@19765
    49
  "NSBseq X = (\<forall>N \<in> HNatInfinite. ( *f* X) N : HFinite)"
paulson@15082
    50
paulson@15082
    51
  monoseq :: "(nat=>real)=>bool"
paulson@15082
    52
    --{*Definition for monotonicity*}
wenzelm@19765
    53
  "monoseq X = ((\<forall>m. \<forall>n\<ge>m. X m \<le> X n) | (\<forall>m. \<forall>n\<ge>m. X n \<le> X m))"
paulson@10751
    54
paulson@15082
    55
  subseq :: "(nat => nat) => bool"
paulson@15082
    56
    --{*Definition of subsequence*}
wenzelm@19765
    57
  "subseq f = (\<forall>m. \<forall>n>m. (f m) < (f n))"
paulson@10751
    58
huffman@20552
    59
  Cauchy :: "(nat => 'a::real_normed_vector) => bool"
paulson@15082
    60
    --{*Standard definition of the Cauchy condition*}
huffman@20563
    61
  "Cauchy X = (\<forall>e>0. \<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. norm (X m - X n) < e)"
paulson@10751
    62
huffman@20552
    63
  NSCauchy :: "(nat => 'a::real_normed_vector) => bool"
paulson@15082
    64
    --{*Nonstandard definition*}
wenzelm@19765
    65
  "NSCauchy X = (\<forall>M \<in> HNatInfinite. \<forall>N \<in> HNatInfinite. ( *f* X) M \<approx> ( *f* X) N)"
paulson@15082
    66
paulson@15082
    67
huffman@20696
    68
subsection {* Limits of Sequences *}
huffman@20696
    69
huffman@20696
    70
subsubsection {* Purely standard proofs *}
paulson@15082
    71
paulson@15082
    72
lemma LIMSEQ_iff:
huffman@20563
    73
      "(X ----> L) = (\<forall>r>0. \<exists>no. \<forall>n \<ge> no. norm (X n - L) < r)"
paulson@15082
    74
by (simp add: LIMSEQ_def)
paulson@15082
    75
huffman@20751
    76
lemma LIMSEQ_I:
huffman@20751
    77
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n - L) < r) \<Longrightarrow> X ----> L"
huffman@20751
    78
by (simp add: LIMSEQ_def)
huffman@20751
    79
huffman@20751
    80
lemma LIMSEQ_D:
huffman@20751
    81
  "\<lbrakk>X ----> L; 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n - L) < r"
huffman@20751
    82
by (simp add: LIMSEQ_def)
huffman@20751
    83
huffman@20696
    84
lemma LIMSEQ_const: "(%n. k) ----> k"
huffman@20696
    85
by (simp add: LIMSEQ_def)
huffman@20696
    86
huffman@20696
    87
lemma LIMSEQ_norm: "X ----> a \<Longrightarrow> (\<lambda>n. norm (X n)) ----> norm a"
huffman@20696
    88
apply (simp add: LIMSEQ_def, safe)
huffman@20696
    89
apply (drule_tac x="r" in spec, safe)
huffman@20696
    90
apply (rule_tac x="no" in exI, safe)
huffman@20696
    91
apply (drule_tac x="n" in spec, safe)
huffman@20696
    92
apply (erule order_le_less_trans [OF norm_triangle_ineq3])
huffman@20696
    93
done
huffman@20696
    94
huffman@20696
    95
lemma LIMSEQ_ignore_initial_segment: "f ----> a 
huffman@20696
    96
  ==> (%n. f(n + k)) ----> a"
huffman@20696
    97
  apply (unfold LIMSEQ_def) 
huffman@20696
    98
  apply (clarify)
huffman@20696
    99
  apply (drule_tac x = r in spec)
huffman@20696
   100
  apply (clarify)
huffman@20696
   101
  apply (rule_tac x = "no + k" in exI)
huffman@20696
   102
  by auto
huffman@20696
   103
huffman@20696
   104
lemma LIMSEQ_offset: "(%x. f (x + k)) ----> a ==>
huffman@20696
   105
    f ----> a"
huffman@20696
   106
  apply (unfold LIMSEQ_def)
huffman@20696
   107
  apply clarsimp
huffman@20696
   108
  apply (drule_tac x = r in spec)
huffman@20696
   109
  apply clarsimp
huffman@20696
   110
  apply (rule_tac x = "no + k" in exI)
huffman@20696
   111
  apply clarsimp
huffman@20696
   112
  apply (drule_tac x = "n - k" in spec)
huffman@20696
   113
  apply (frule mp)
huffman@20696
   114
  apply arith
huffman@20696
   115
  apply simp
huffman@20696
   116
done
huffman@20696
   117
huffman@20696
   118
subsubsection {* Purely nonstandard proofs *}
huffman@20696
   119
paulson@15082
   120
lemma NSLIMSEQ_iff:
huffman@20552
   121
    "(X ----NS> L) = (\<forall>N \<in> HNatInfinite. ( *f* X) N \<approx> star_of L)"
paulson@15082
   122
by (simp add: NSLIMSEQ_def)
paulson@15082
   123
huffman@20751
   124
lemma NSLIMSEQ_I:
huffman@20751
   125
  "(\<And>N. N \<in> HNatInfinite \<Longrightarrow> starfun X N \<approx> star_of L) \<Longrightarrow> X ----NS> L"
huffman@20751
   126
by (simp add: NSLIMSEQ_def)
huffman@20751
   127
huffman@20751
   128
lemma NSLIMSEQ_D:
huffman@20751
   129
  "\<lbrakk>X ----NS> L; N \<in> HNatInfinite\<rbrakk> \<Longrightarrow> starfun X N \<approx> star_of L"
huffman@20751
   130
by (simp add: NSLIMSEQ_def)
huffman@20751
   131
huffman@20696
   132
lemma NSLIMSEQ_const: "(%n. k) ----NS> k"
huffman@20696
   133
by (simp add: NSLIMSEQ_def)
huffman@20696
   134
huffman@20696
   135
lemma NSLIMSEQ_add:
huffman@20696
   136
      "[| X ----NS> a; Y ----NS> b |] ==> (%n. X n + Y n) ----NS> a + b"
huffman@20696
   137
by (auto intro: approx_add simp add: NSLIMSEQ_def starfun_add [symmetric])
huffman@20696
   138
huffman@20696
   139
lemma NSLIMSEQ_add_const: "f ----NS> a ==> (%n.(f n + b)) ----NS> a + b"
huffman@20696
   140
by (simp only: NSLIMSEQ_add NSLIMSEQ_const)
huffman@20696
   141
huffman@20696
   142
lemma NSLIMSEQ_mult:
huffman@20696
   143
  fixes a b :: "'a::real_normed_algebra"
huffman@20696
   144
  shows "[| X ----NS> a; Y ----NS> b |] ==> (%n. X n * Y n) ----NS> a * b"
huffman@20696
   145
by (auto intro!: approx_mult_HFinite simp add: NSLIMSEQ_def)
huffman@20696
   146
huffman@20696
   147
lemma NSLIMSEQ_minus: "X ----NS> a ==> (%n. -(X n)) ----NS> -a"
huffman@20696
   148
by (auto simp add: NSLIMSEQ_def)
huffman@20696
   149
huffman@20696
   150
lemma NSLIMSEQ_minus_cancel: "(%n. -(X n)) ----NS> -a ==> X ----NS> a"
huffman@20696
   151
by (drule NSLIMSEQ_minus, simp)
huffman@20696
   152
huffman@20696
   153
(* FIXME: delete *)
huffman@20696
   154
lemma NSLIMSEQ_add_minus:
huffman@20696
   155
     "[| X ----NS> a; Y ----NS> b |] ==> (%n. X n + -Y n) ----NS> a + -b"
huffman@20696
   156
by (simp add: NSLIMSEQ_add NSLIMSEQ_minus)
huffman@20696
   157
huffman@20696
   158
lemma NSLIMSEQ_diff:
huffman@20696
   159
     "[| X ----NS> a; Y ----NS> b |] ==> (%n. X n - Y n) ----NS> a - b"
huffman@20696
   160
by (simp add: diff_minus NSLIMSEQ_add NSLIMSEQ_minus)
huffman@20696
   161
huffman@20696
   162
lemma NSLIMSEQ_diff_const: "f ----NS> a ==> (%n.(f n - b)) ----NS> a - b"
huffman@20696
   163
by (simp add: NSLIMSEQ_diff NSLIMSEQ_const)
huffman@20696
   164
huffman@20696
   165
lemma NSLIMSEQ_inverse:
huffman@20696
   166
  fixes a :: "'a::real_normed_div_algebra"
huffman@20696
   167
  shows "[| X ----NS> a;  a ~= 0 |] ==> (%n. inverse(X n)) ----NS> inverse(a)"
huffman@20696
   168
by (simp add: NSLIMSEQ_def star_of_approx_inverse)
huffman@20696
   169
huffman@20696
   170
lemma NSLIMSEQ_mult_inverse:
huffman@20696
   171
  fixes a b :: "'a::real_normed_field"
huffman@20696
   172
  shows
huffman@20696
   173
     "[| X ----NS> a;  Y ----NS> b;  b ~= 0 |] ==> (%n. X n / Y n) ----NS> a/b"
huffman@20696
   174
by (simp add: NSLIMSEQ_mult NSLIMSEQ_inverse divide_inverse)
huffman@20696
   175
huffman@20696
   176
lemma starfun_hnorm: "\<And>x. hnorm (( *f* f) x) = ( *f* (\<lambda>x. norm (f x))) x"
huffman@20696
   177
by transfer simp
huffman@20696
   178
huffman@20696
   179
lemma NSLIMSEQ_norm: "X ----NS> a \<Longrightarrow> (\<lambda>n. norm (X n)) ----NS> norm a"
huffman@20696
   180
by (simp add: NSLIMSEQ_def starfun_hnorm [symmetric] approx_hnorm)
huffman@20696
   181
huffman@20696
   182
text{*Uniqueness of limit*}
huffman@20696
   183
lemma NSLIMSEQ_unique: "[| X ----NS> a; X ----NS> b |] ==> a = b"
huffman@20696
   184
apply (simp add: NSLIMSEQ_def)
huffman@20696
   185
apply (drule HNatInfinite_whn [THEN [2] bspec])+
huffman@20696
   186
apply (auto dest: approx_trans3)
huffman@20696
   187
done
huffman@20696
   188
huffman@20696
   189
lemma NSLIMSEQ_pow [rule_format]:
huffman@20696
   190
  fixes a :: "'a::{real_normed_algebra,recpower}"
huffman@20696
   191
  shows "(X ----NS> a) --> ((%n. (X n) ^ m) ----NS> a ^ m)"
huffman@20696
   192
apply (induct "m")
huffman@20696
   193
apply (auto simp add: power_Suc intro: NSLIMSEQ_mult NSLIMSEQ_const)
huffman@20696
   194
done
huffman@20696
   195
huffman@20696
   196
subsubsection {* Equivalence of @{term LIMSEQ} and @{term NSLIMSEQ} *}
paulson@15082
   197
paulson@15082
   198
lemma LIMSEQ_NSLIMSEQ:
huffman@20751
   199
  assumes X: "X ----> L" shows "X ----NS> L"
huffman@20751
   200
proof (rule NSLIMSEQ_I)
huffman@20751
   201
  fix N assume N: "N \<in> HNatInfinite"
huffman@20751
   202
  have "starfun X N - star_of L \<in> Infinitesimal"
huffman@20751
   203
  proof (rule InfinitesimalI2)
huffman@20751
   204
    fix r::real assume r: "0 < r"
huffman@20751
   205
    from LIMSEQ_D [OF X r]
huffman@20751
   206
    obtain no where "\<forall>n\<ge>no. norm (X n - L) < r" ..
huffman@20751
   207
    hence "\<forall>n\<ge>star_of no. hnorm (starfun X n - star_of L) < star_of r"
huffman@20751
   208
      by transfer
huffman@20751
   209
    thus "hnorm (starfun X N - star_of L) < star_of r"
huffman@20751
   210
      using N by (simp add: star_of_le_HNatInfinite)
huffman@20751
   211
  qed
huffman@20751
   212
  thus "starfun X N \<approx> star_of L"
huffman@20751
   213
    by (unfold approx_def)
huffman@20751
   214
qed
paulson@15082
   215
huffman@20751
   216
lemma NSLIMSEQ_LIMSEQ:
huffman@20751
   217
  assumes X: "X ----NS> L" shows "X ----> L"
huffman@20751
   218
proof (rule LIMSEQ_I)
huffman@20751
   219
  fix r::real assume r: "0 < r"
huffman@20751
   220
  have "\<exists>no. \<forall>n\<ge>no. hnorm (starfun X n - star_of L) < star_of r"
huffman@20751
   221
  proof (intro exI allI impI)
huffman@20751
   222
    fix n assume "whn \<le> n"
huffman@20751
   223
    with HNatInfinite_whn have "n \<in> HNatInfinite"
huffman@20751
   224
      by (rule HNatInfinite_upward_closed)
huffman@20751
   225
    with X have "starfun X n \<approx> star_of L"
huffman@20751
   226
      by (rule NSLIMSEQ_D)
huffman@20751
   227
    hence "starfun X n - star_of L \<in> Infinitesimal"
huffman@20751
   228
      by (unfold approx_def)
huffman@20751
   229
    thus "hnorm (starfun X n - star_of L) < star_of r"
huffman@20751
   230
      using r by (rule InfinitesimalD2)
huffman@20751
   231
  qed
huffman@20751
   232
  thus "\<exists>no. \<forall>n\<ge>no. norm (X n - L) < r"
huffman@20751
   233
    by transfer
huffman@20751
   234
qed
paulson@15082
   235
huffman@20751
   236
theorem LIMSEQ_NSLIMSEQ_iff: "(f ----> L) = (f ----NS> L)"
huffman@20751
   237
by (blast intro: LIMSEQ_NSLIMSEQ NSLIMSEQ_LIMSEQ)
paulson@15082
   238
huffman@20751
   239
(* Used once by Integration/Rats.thy in AFP *)
paulson@15082
   240
lemma NSLIMSEQ_finite_set:
paulson@15082
   241
     "!!(f::nat=>nat). \<forall>n. n \<le> f n ==> finite {n. f n \<le> u}"
huffman@20751
   242
by (rule_tac B="{..u}" in finite_subset, auto intro: order_trans)
paulson@15082
   243
huffman@20696
   244
subsubsection {* Derived theorems about @{term LIMSEQ} *}
paulson@15082
   245
paulson@15082
   246
lemma LIMSEQ_add: "[| X ----> a; Y ----> b |] ==> (%n. X n + Y n) ----> a + b"
paulson@15082
   247
by (simp add: LIMSEQ_NSLIMSEQ_iff NSLIMSEQ_add)
paulson@15082
   248
avigad@16819
   249
lemma LIMSEQ_add_const: "f ----> a ==> (%n.(f n + b)) ----> a + b"
huffman@20685
   250
by (simp add: LIMSEQ_add LIMSEQ_const)
avigad@16819
   251
huffman@20552
   252
lemma LIMSEQ_mult:
huffman@20552
   253
  fixes a b :: "'a::real_normed_algebra"
huffman@20552
   254
  shows "[| X ----> a; Y ----> b |] ==> (%n. X n * Y n) ----> a * b"
paulson@15082
   255
by (simp add: LIMSEQ_NSLIMSEQ_iff NSLIMSEQ_mult)
paulson@15082
   256
paulson@15082
   257
lemma LIMSEQ_minus: "X ----> a ==> (%n. -(X n)) ----> -a"
paulson@15082
   258
by (simp add: LIMSEQ_NSLIMSEQ_iff NSLIMSEQ_minus)
paulson@15082
   259
paulson@15082
   260
lemma LIMSEQ_minus_cancel: "(%n. -(X n)) ----> -a ==> X ----> a"
paulson@15082
   261
by (drule LIMSEQ_minus, simp)
paulson@15082
   262
huffman@20685
   263
(* FIXME: delete *)
paulson@15082
   264
lemma LIMSEQ_add_minus:
paulson@15082
   265
     "[| X ----> a; Y ----> b |] ==> (%n. X n + -Y n) ----> a + -b"
paulson@15082
   266
by (simp add: LIMSEQ_NSLIMSEQ_iff NSLIMSEQ_add_minus)
paulson@15082
   267
paulson@15082
   268
lemma LIMSEQ_diff: "[| X ----> a; Y ----> b |] ==> (%n. X n - Y n) ----> a - b"
huffman@20685
   269
by (simp add: diff_minus LIMSEQ_add LIMSEQ_minus)
paulson@15082
   270
avigad@16819
   271
lemma LIMSEQ_diff_const: "f ----> a ==> (%n.(f n  - b)) ----> a - b"
huffman@20685
   272
by (simp add: LIMSEQ_diff LIMSEQ_const)
avigad@16819
   273
paulson@15082
   274
lemma LIMSEQ_inverse:
huffman@20653
   275
  fixes a :: "'a::real_normed_div_algebra"
huffman@20552
   276
  shows "[| X ----> a; a ~= 0 |] ==> (%n. inverse(X n)) ----> inverse(a)"
paulson@15082
   277
by (simp add: NSLIMSEQ_inverse LIMSEQ_NSLIMSEQ_iff)
paulson@15082
   278
paulson@15082
   279
lemma LIMSEQ_divide:
huffman@20696
   280
  fixes a b :: "'a::real_normed_field"
huffman@20552
   281
  shows "[| X ----> a;  Y ----> b;  b ~= 0 |] ==> (%n. X n / Y n) ----> a/b"
paulson@15082
   282
by (simp add: LIMSEQ_mult LIMSEQ_inverse divide_inverse)
paulson@15082
   283
paulson@15082
   284
lemma LIMSEQ_unique: "[| X ----> a; X ----> b |] ==> a = b"
paulson@15082
   285
by (simp add: LIMSEQ_NSLIMSEQ_iff NSLIMSEQ_unique)
paulson@15082
   286
huffman@20696
   287
lemma LIMSEQ_pow:
huffman@20696
   288
  fixes a :: "'a::{real_normed_algebra,recpower}"
huffman@20696
   289
  shows "X ----> a ==> (%n. (X n) ^ m) ----> a ^ m"
huffman@20696
   290
by (simp add: LIMSEQ_NSLIMSEQ_iff NSLIMSEQ_pow)
huffman@20696
   291
nipkow@15312
   292
lemma LIMSEQ_setsum:
nipkow@15312
   293
  assumes n: "\<And>n. n \<in> S \<Longrightarrow> X n ----> L n"
nipkow@15312
   294
  shows "(\<lambda>m. \<Sum>n\<in>S. X n m) ----> (\<Sum>n\<in>S. L n)"
nipkow@15312
   295
proof (cases "finite S")
nipkow@15312
   296
  case True
nipkow@15312
   297
  thus ?thesis using n
nipkow@15312
   298
  proof (induct)
nipkow@15312
   299
    case empty
nipkow@15312
   300
    show ?case
nipkow@15312
   301
      by (simp add: LIMSEQ_const)
nipkow@15312
   302
  next
nipkow@15312
   303
    case insert
nipkow@15312
   304
    thus ?case
nipkow@15312
   305
      by (simp add: LIMSEQ_add)
nipkow@15312
   306
  qed
nipkow@15312
   307
next
nipkow@15312
   308
  case False
nipkow@15312
   309
  thus ?thesis
nipkow@15312
   310
    by (simp add: setsum_def LIMSEQ_const)
nipkow@15312
   311
qed
nipkow@15312
   312
avigad@16819
   313
lemma LIMSEQ_setprod:
huffman@20552
   314
  fixes L :: "'a \<Rightarrow> 'b::{real_normed_algebra,comm_ring_1}"
avigad@16819
   315
  assumes n: "\<And>n. n \<in> S \<Longrightarrow> X n ----> L n"
avigad@16819
   316
  shows "(\<lambda>m. \<Prod>n\<in>S. X n m) ----> (\<Prod>n\<in>S. L n)"
avigad@16819
   317
proof (cases "finite S")
avigad@16819
   318
  case True
avigad@16819
   319
  thus ?thesis using n
avigad@16819
   320
  proof (induct)
avigad@16819
   321
    case empty
avigad@16819
   322
    show ?case
avigad@16819
   323
      by (simp add: LIMSEQ_const)
avigad@16819
   324
  next
avigad@16819
   325
    case insert
avigad@16819
   326
    thus ?case
avigad@16819
   327
      by (simp add: LIMSEQ_mult)
avigad@16819
   328
  qed
avigad@16819
   329
next
avigad@16819
   330
  case False
avigad@16819
   331
  thus ?thesis
avigad@16819
   332
    by (simp add: setprod_def LIMSEQ_const)
avigad@16819
   333
qed
avigad@16819
   334
avigad@16819
   335
lemma LIMSEQ_diff_approach_zero: 
avigad@16819
   336
  "g ----> L ==> (%x. f x - g x) ----> 0  ==>
avigad@16819
   337
     f ----> L"
avigad@16819
   338
  apply (drule LIMSEQ_add)
avigad@16819
   339
  apply assumption
avigad@16819
   340
  apply simp
avigad@16819
   341
done
avigad@16819
   342
avigad@16819
   343
lemma LIMSEQ_diff_approach_zero2: 
avigad@16819
   344
  "f ----> L ==> (%x. f x - g x) ----> 0  ==>
avigad@16819
   345
     g ----> L";
avigad@16819
   346
  apply (drule LIMSEQ_diff)
avigad@16819
   347
  apply assumption
avigad@16819
   348
  apply simp
avigad@16819
   349
done
avigad@16819
   350
paulson@15082
   351
huffman@20696
   352
subsection {* Convergence *}
paulson@15082
   353
paulson@15082
   354
lemma limI: "X ----> L ==> lim X = L"
paulson@15082
   355
apply (simp add: lim_def)
paulson@15082
   356
apply (blast intro: LIMSEQ_unique)
paulson@15082
   357
done
paulson@15082
   358
paulson@15082
   359
lemma nslimI: "X ----NS> L ==> nslim X = L"
paulson@15082
   360
apply (simp add: nslim_def)
paulson@15082
   361
apply (blast intro: NSLIMSEQ_unique)
paulson@15082
   362
done
paulson@15082
   363
paulson@15082
   364
lemma lim_nslim_iff: "lim X = nslim X"
paulson@15082
   365
by (simp add: lim_def nslim_def LIMSEQ_NSLIMSEQ_iff)
paulson@15082
   366
paulson@15082
   367
lemma convergentD: "convergent X ==> \<exists>L. (X ----> L)"
paulson@15082
   368
by (simp add: convergent_def)
paulson@15082
   369
paulson@15082
   370
lemma convergentI: "(X ----> L) ==> convergent X"
paulson@15082
   371
by (auto simp add: convergent_def)
paulson@15082
   372
paulson@15082
   373
lemma NSconvergentD: "NSconvergent X ==> \<exists>L. (X ----NS> L)"
paulson@15082
   374
by (simp add: NSconvergent_def)
paulson@15082
   375
paulson@15082
   376
lemma NSconvergentI: "(X ----NS> L) ==> NSconvergent X"
paulson@15082
   377
by (auto simp add: NSconvergent_def)
paulson@15082
   378
paulson@15082
   379
lemma convergent_NSconvergent_iff: "convergent X = NSconvergent X"
paulson@15082
   380
by (simp add: convergent_def NSconvergent_def LIMSEQ_NSLIMSEQ_iff)
paulson@15082
   381
paulson@15082
   382
lemma NSconvergent_NSLIMSEQ_iff: "NSconvergent X = (X ----NS> nslim X)"
huffman@20682
   383
by (auto intro: theI NSLIMSEQ_unique simp add: NSconvergent_def nslim_def)
paulson@15082
   384
paulson@15082
   385
lemma convergent_LIMSEQ_iff: "convergent X = (X ----> lim X)"
huffman@20682
   386
by (auto intro: theI LIMSEQ_unique simp add: convergent_def lim_def)
paulson@15082
   387
huffman@20696
   388
lemma convergent_minus_iff: "(convergent X) = (convergent (%n. -(X n)))"
huffman@20696
   389
apply (simp add: convergent_def)
huffman@20696
   390
apply (auto dest: LIMSEQ_minus)
huffman@20696
   391
apply (drule LIMSEQ_minus, auto)
huffman@20696
   392
done
huffman@20696
   393
huffman@20696
   394
huffman@20696
   395
subsection {* Bounded Monotonic Sequences *}
huffman@20696
   396
paulson@15082
   397
text{*Subsequence (alternative definition, (e.g. Hoskins)*}
paulson@15082
   398
paulson@15082
   399
lemma subseq_Suc_iff: "subseq f = (\<forall>n. (f n) < (f (Suc n)))"
paulson@15082
   400
apply (simp add: subseq_def)
paulson@15082
   401
apply (auto dest!: less_imp_Suc_add)
paulson@15082
   402
apply (induct_tac k)
paulson@15082
   403
apply (auto intro: less_trans)
paulson@15082
   404
done
paulson@15082
   405
paulson@15082
   406
lemma monoseq_Suc:
paulson@15082
   407
   "monoseq X = ((\<forall>n. X n \<le> X (Suc n))
paulson@15082
   408
                 | (\<forall>n. X (Suc n) \<le> X n))"
paulson@15082
   409
apply (simp add: monoseq_def)
paulson@15082
   410
apply (auto dest!: le_imp_less_or_eq)
paulson@15082
   411
apply (auto intro!: lessI [THEN less_imp_le] dest!: less_imp_Suc_add)
paulson@15082
   412
apply (induct_tac "ka")
paulson@15082
   413
apply (auto intro: order_trans)
wenzelm@18585
   414
apply (erule contrapos_np)
paulson@15082
   415
apply (induct_tac "k")
paulson@15082
   416
apply (auto intro: order_trans)
paulson@15082
   417
done
paulson@15082
   418
nipkow@15360
   419
lemma monoI1: "\<forall>m. \<forall> n \<ge> m. X m \<le> X n ==> monoseq X"
paulson@15082
   420
by (simp add: monoseq_def)
paulson@15082
   421
nipkow@15360
   422
lemma monoI2: "\<forall>m. \<forall> n \<ge> m. X n \<le> X m ==> monoseq X"
paulson@15082
   423
by (simp add: monoseq_def)
paulson@15082
   424
paulson@15082
   425
lemma mono_SucI1: "\<forall>n. X n \<le> X (Suc n) ==> monoseq X"
paulson@15082
   426
by (simp add: monoseq_Suc)
paulson@15082
   427
paulson@15082
   428
lemma mono_SucI2: "\<forall>n. X (Suc n) \<le> X n ==> monoseq X"
paulson@15082
   429
by (simp add: monoseq_Suc)
paulson@15082
   430
huffman@20696
   431
text{*Bounded Sequence*}
paulson@15082
   432
huffman@20552
   433
lemma BseqD: "Bseq X ==> \<exists>K. 0 < K & (\<forall>n. norm (X n) \<le> K)"
paulson@15082
   434
by (simp add: Bseq_def)
paulson@15082
   435
huffman@20552
   436
lemma BseqI: "[| 0 < K; \<forall>n. norm (X n) \<le> K |] ==> Bseq X"
paulson@15082
   437
by (auto simp add: Bseq_def)
paulson@15082
   438
paulson@15082
   439
lemma lemma_NBseq_def:
huffman@20552
   440
     "(\<exists>K > 0. \<forall>n. norm (X n) \<le> K) =
huffman@20552
   441
      (\<exists>N. \<forall>n. norm (X n) \<le> real(Suc N))"
paulson@15082
   442
apply auto
paulson@15082
   443
 prefer 2 apply force
paulson@15082
   444
apply (cut_tac x = K in reals_Archimedean2, clarify)
paulson@15082
   445
apply (rule_tac x = n in exI, clarify)
paulson@15082
   446
apply (drule_tac x = na in spec)
paulson@15082
   447
apply (auto simp add: real_of_nat_Suc)
paulson@15082
   448
done
paulson@15082
   449
paulson@15082
   450
text{* alternative definition for Bseq *}
huffman@20552
   451
lemma Bseq_iff: "Bseq X = (\<exists>N. \<forall>n. norm (X n) \<le> real(Suc N))"
paulson@15082
   452
apply (simp add: Bseq_def)
paulson@15082
   453
apply (simp (no_asm) add: lemma_NBseq_def)
paulson@15082
   454
done
paulson@15082
   455
paulson@15082
   456
lemma lemma_NBseq_def2:
huffman@20552
   457
     "(\<exists>K > 0. \<forall>n. norm (X n) \<le> K) = (\<exists>N. \<forall>n. norm (X n) < real(Suc N))"
paulson@15082
   458
apply (subst lemma_NBseq_def, auto)
paulson@15082
   459
apply (rule_tac x = "Suc N" in exI)
paulson@15082
   460
apply (rule_tac [2] x = N in exI)
paulson@15082
   461
apply (auto simp add: real_of_nat_Suc)
paulson@15082
   462
 prefer 2 apply (blast intro: order_less_imp_le)
paulson@15082
   463
apply (drule_tac x = n in spec, simp)
paulson@15082
   464
done
paulson@15082
   465
paulson@15082
   466
(* yet another definition for Bseq *)
huffman@20552
   467
lemma Bseq_iff1a: "Bseq X = (\<exists>N. \<forall>n. norm (X n) < real(Suc N))"
paulson@15082
   468
by (simp add: Bseq_def lemma_NBseq_def2)
paulson@15082
   469
huffman@17318
   470
lemma NSBseqD: "[| NSBseq X;  N: HNatInfinite |] ==> ( *f* X) N : HFinite"
paulson@15082
   471
by (simp add: NSBseq_def)
paulson@15082
   472
huffman@17318
   473
lemma NSBseqI: "\<forall>N \<in> HNatInfinite. ( *f* X) N : HFinite ==> NSBseq X"
paulson@15082
   474
by (simp add: NSBseq_def)
paulson@15082
   475
paulson@15082
   476
text{*The standard definition implies the nonstandard definition*}
paulson@15082
   477
huffman@20552
   478
lemma lemma_Bseq: "\<forall>n. norm (X n) \<le> K ==> \<forall>n. norm(X((f::nat=>nat) n)) \<le> K"
paulson@15082
   479
by auto
paulson@15082
   480
paulson@15082
   481
lemma Bseq_NSBseq: "Bseq X ==> NSBseq X"
paulson@15082
   482
apply (simp add: Bseq_def NSBseq_def, safe)
huffman@17318
   483
apply (rule_tac x = N in star_cases)
huffman@17318
   484
apply (auto simp add: starfun HFinite_FreeUltrafilterNat_iff 
paulson@15082
   485
                      HNatInfinite_FreeUltrafilterNat_iff)
paulson@15082
   486
apply (drule_tac f = Xa in lemma_Bseq)
paulson@15082
   487
apply (rule_tac x = "K+1" in exI)
paulson@15082
   488
apply (drule_tac P="%n. ?f n \<le> K" in FreeUltrafilterNat_all, ultra)
paulson@15082
   489
done
paulson@15082
   490
paulson@15082
   491
text{*The nonstandard definition implies the standard definition*}
paulson@15082
   492
paulson@15082
   493
(* similar to NSLIM proof in REALTOPOS *)
paulson@15082
   494
paulson@15082
   495
text{* We need to get rid of the real variable and do so by proving the
paulson@15082
   496
   following, which relies on the Archimedean property of the reals.
paulson@15082
   497
   When we skolemize we then get the required function @{term "f::nat=>nat"}.
paulson@15082
   498
   Otherwise, we would be stuck with a skolem function @{term "f::real=>nat"}
paulson@15082
   499
   which woulid be useless.*}
paulson@15082
   500
paulson@15082
   501
lemma lemmaNSBseq:
huffman@20552
   502
     "\<forall>K > 0. \<exists>n. K < norm (X n)
huffman@20552
   503
      ==> \<forall>N. \<exists>n. real(Suc N) < norm (X n)"
paulson@15082
   504
apply safe
paulson@15082
   505
apply (cut_tac n = N in real_of_nat_Suc_gt_zero, blast)
paulson@15082
   506
done
paulson@15082
   507
huffman@20552
   508
lemma lemmaNSBseq2: "\<forall>K > 0. \<exists>n::nat. K < norm (X n)
huffman@20552
   509
                     ==> \<exists>f. \<forall>N. real(Suc N) < norm (X (f N))"
paulson@15082
   510
apply (drule lemmaNSBseq)
huffman@20552
   511
apply (drule no_choice, blast)
paulson@15082
   512
done
paulson@15082
   513
paulson@15082
   514
lemma real_seq_to_hypreal_HInfinite:
huffman@20552
   515
     "\<forall>N. real(Suc N) < norm (X (f N))
huffman@17318
   516
      ==>  star_n (X o f) : HInfinite"
paulson@15082
   517
apply (auto simp add: HInfinite_FreeUltrafilterNat_iff o_def)
paulson@15082
   518
apply (cut_tac u = u in FreeUltrafilterNat_nat_gt_real)
paulson@15082
   519
apply (drule FreeUltrafilterNat_all)
paulson@15082
   520
apply (erule FreeUltrafilterNat_Int [THEN FreeUltrafilterNat_subset])
paulson@15082
   521
apply (auto simp add: real_of_nat_Suc)
paulson@15082
   522
done
paulson@15082
   523
paulson@15082
   524
text{* Now prove that we can get out an infinite hypernatural as well
paulson@15082
   525
     defined using the skolem function  @{term "f::nat=>nat"} above*}
paulson@15082
   526
paulson@15082
   527
lemma lemma_finite_NSBseq:
huffman@20552
   528
     "{n. f n \<le> Suc u & real(Suc n) < norm (X (f n))} \<le>
huffman@20552
   529
      {n. f n \<le> u & real(Suc n) < norm (X (f n))} Un
huffman@20552
   530
      {n. real(Suc n) < norm (X (Suc u))}"
paulson@15082
   531
by (auto dest!: le_imp_less_or_eq)
paulson@15082
   532
paulson@15082
   533
lemma lemma_finite_NSBseq2:
huffman@20552
   534
     "finite {n. f n \<le> (u::nat) &  real(Suc n) < norm (X(f n))}"
paulson@15251
   535
apply (induct "u")
paulson@15082
   536
apply (rule_tac [2] lemma_finite_NSBseq [THEN finite_subset])
huffman@20552
   537
apply (rule_tac B = "{n. real (Suc n) < norm (X 0) }" in finite_subset)
paulson@15082
   538
apply (auto intro: finite_real_of_nat_less_real 
paulson@15082
   539
            simp add: real_of_nat_Suc less_diff_eq [symmetric])
paulson@15082
   540
done
paulson@15082
   541
paulson@15082
   542
lemma HNatInfinite_skolem_f:
huffman@20552
   543
     "\<forall>N. real(Suc N) < norm (X (f N))
huffman@17318
   544
      ==> star_n f : HNatInfinite"
paulson@15082
   545
apply (auto simp add: HNatInfinite_FreeUltrafilterNat_iff)
paulson@15082
   546
apply (rule ccontr, drule FreeUltrafilterNat_Compl_mem)
paulson@15082
   547
apply (rule lemma_finite_NSBseq2 [THEN FreeUltrafilterNat_finite, THEN notE]) 
huffman@20552
   548
apply (subgoal_tac "{n. f n \<le> u & real (Suc n) < norm (X (f n))} =
huffman@20552
   549
                    {n. f n \<le> u} \<inter> {N. real (Suc N) < norm (X (f N))}")
paulson@15082
   550
apply (erule ssubst) 
paulson@15082
   551
 apply (auto simp add: linorder_not_less Compl_def)
paulson@15082
   552
done
paulson@15082
   553
paulson@15082
   554
lemma NSBseq_Bseq: "NSBseq X ==> Bseq X"
paulson@15082
   555
apply (simp add: Bseq_def NSBseq_def)
paulson@15082
   556
apply (rule ccontr)
paulson@15082
   557
apply (auto simp add: linorder_not_less [symmetric])
paulson@15082
   558
apply (drule lemmaNSBseq2, safe)
paulson@15082
   559
apply (frule_tac X = X and f = f in real_seq_to_hypreal_HInfinite)
paulson@15082
   560
apply (drule HNatInfinite_skolem_f [THEN [2] bspec])
huffman@17318
   561
apply (auto simp add: starfun o_def HFinite_HInfinite_iff)
paulson@15082
   562
done
paulson@15082
   563
paulson@15082
   564
text{* Equivalence of nonstandard and standard definitions
paulson@15082
   565
  for a bounded sequence*}
paulson@15082
   566
lemma Bseq_NSBseq_iff: "(Bseq X) = (NSBseq X)"
paulson@15082
   567
by (blast intro!: NSBseq_Bseq Bseq_NSBseq)
paulson@15082
   568
paulson@15082
   569
text{*A convergent sequence is bounded: 
paulson@15082
   570
 Boundedness as a necessary condition for convergence. 
paulson@15082
   571
 The nonstandard version has no existential, as usual *}
paulson@15082
   572
paulson@15082
   573
lemma NSconvergent_NSBseq: "NSconvergent X ==> NSBseq X"
paulson@15082
   574
apply (simp add: NSconvergent_def NSBseq_def NSLIMSEQ_def)
huffman@20552
   575
apply (blast intro: HFinite_star_of approx_sym approx_HFinite)
paulson@15082
   576
done
paulson@15082
   577
paulson@15082
   578
text{*Standard Version: easily now proved using equivalence of NS and
paulson@15082
   579
 standard definitions *}
paulson@15082
   580
lemma convergent_Bseq: "convergent X ==> Bseq X"
paulson@15082
   581
by (simp add: NSconvergent_NSBseq convergent_NSconvergent_iff Bseq_NSBseq_iff)
paulson@15082
   582
huffman@20696
   583
subsubsection{*Upper Bounds and Lubs of Bounded Sequences*}
paulson@15082
   584
paulson@15082
   585
lemma Bseq_isUb:
paulson@15082
   586
  "!!(X::nat=>real). Bseq X ==> \<exists>U. isUb (UNIV::real set) {x. \<exists>n. X n = x} U"
paulson@15082
   587
by (auto intro: isUbI setleI simp add: Bseq_def abs_le_interval_iff)
paulson@15082
   588
paulson@15082
   589
paulson@15082
   590
text{* Use completeness of reals (supremum property)
paulson@15082
   591
   to show that any bounded sequence has a least upper bound*}
paulson@15082
   592
paulson@15082
   593
lemma Bseq_isLub:
paulson@15082
   594
  "!!(X::nat=>real). Bseq X ==>
paulson@15082
   595
   \<exists>U. isLub (UNIV::real set) {x. \<exists>n. X n = x} U"
paulson@15082
   596
by (blast intro: reals_complete Bseq_isUb)
paulson@15082
   597
huffman@20552
   598
lemma NSBseq_isUb: "NSBseq X ==> \<exists>U::real. isUb UNIV {x. \<exists>n. X n = x} U"
paulson@15082
   599
by (simp add: Bseq_NSBseq_iff [symmetric] Bseq_isUb)
paulson@15082
   600
huffman@20552
   601
lemma NSBseq_isLub: "NSBseq X ==> \<exists>U::real. isLub UNIV {x. \<exists>n. X n = x} U"
paulson@15082
   602
by (simp add: Bseq_NSBseq_iff [symmetric] Bseq_isLub)
paulson@15082
   603
paulson@15082
   604
huffman@20696
   605
subsubsection{*A Bounded and Monotonic Sequence Converges*}
paulson@15082
   606
paulson@15082
   607
lemma lemma_converg1:
nipkow@15360
   608
     "!!(X::nat=>real). [| \<forall>m. \<forall> n \<ge> m. X m \<le> X n;
paulson@15082
   609
                  isLub (UNIV::real set) {x. \<exists>n. X n = x} (X ma)
nipkow@15360
   610
               |] ==> \<forall>n \<ge> ma. X n = X ma"
paulson@15082
   611
apply safe
paulson@15082
   612
apply (drule_tac y = "X n" in isLubD2)
paulson@15082
   613
apply (blast dest: order_antisym)+
paulson@15082
   614
done
paulson@15082
   615
paulson@15082
   616
text{* The best of both worlds: Easier to prove this result as a standard
paulson@15082
   617
   theorem and then use equivalence to "transfer" it into the
paulson@15082
   618
   equivalent nonstandard form if needed!*}
paulson@15082
   619
paulson@15082
   620
lemma Bmonoseq_LIMSEQ: "\<forall>n. m \<le> n --> X n = X m ==> \<exists>L. (X ----> L)"
paulson@15082
   621
apply (simp add: LIMSEQ_def)
paulson@15082
   622
apply (rule_tac x = "X m" in exI, safe)
paulson@15082
   623
apply (rule_tac x = m in exI, safe)
paulson@15082
   624
apply (drule spec, erule impE, auto)
paulson@15082
   625
done
paulson@15082
   626
paulson@15082
   627
text{*Now, the same theorem in terms of NS limit *}
nipkow@15360
   628
lemma Bmonoseq_NSLIMSEQ: "\<forall>n \<ge> m. X n = X m ==> \<exists>L. (X ----NS> L)"
paulson@15082
   629
by (auto dest!: Bmonoseq_LIMSEQ simp add: LIMSEQ_NSLIMSEQ_iff)
paulson@15082
   630
paulson@15082
   631
lemma lemma_converg2:
paulson@15082
   632
   "!!(X::nat=>real).
paulson@15082
   633
    [| \<forall>m. X m ~= U;  isLub UNIV {x. \<exists>n. X n = x} U |] ==> \<forall>m. X m < U"
paulson@15082
   634
apply safe
paulson@15082
   635
apply (drule_tac y = "X m" in isLubD2)
paulson@15082
   636
apply (auto dest!: order_le_imp_less_or_eq)
paulson@15082
   637
done
paulson@15082
   638
paulson@15082
   639
lemma lemma_converg3: "!!(X ::nat=>real). \<forall>m. X m \<le> U ==> isUb UNIV {x. \<exists>n. X n = x} U"
paulson@15082
   640
by (rule setleI [THEN isUbI], auto)
paulson@15082
   641
paulson@15082
   642
text{* FIXME: @{term "U - T < U"} is redundant *}
paulson@15082
   643
lemma lemma_converg4: "!!(X::nat=> real).
paulson@15082
   644
               [| \<forall>m. X m ~= U;
paulson@15082
   645
                  isLub UNIV {x. \<exists>n. X n = x} U;
paulson@15082
   646
                  0 < T;
paulson@15082
   647
                  U + - T < U
paulson@15082
   648
               |] ==> \<exists>m. U + -T < X m & X m < U"
paulson@15082
   649
apply (drule lemma_converg2, assumption)
paulson@15082
   650
apply (rule ccontr, simp)
paulson@15082
   651
apply (simp add: linorder_not_less)
paulson@15082
   652
apply (drule lemma_converg3)
paulson@15082
   653
apply (drule isLub_le_isUb, assumption)
paulson@15082
   654
apply (auto dest: order_less_le_trans)
paulson@15082
   655
done
paulson@15082
   656
paulson@15082
   657
text{*A standard proof of the theorem for monotone increasing sequence*}
paulson@15082
   658
paulson@15082
   659
lemma Bseq_mono_convergent:
huffman@20552
   660
     "[| Bseq X; \<forall>m. \<forall>n \<ge> m. X m \<le> X n |] ==> convergent (X::nat=>real)"
paulson@15082
   661
apply (simp add: convergent_def)
paulson@15082
   662
apply (frule Bseq_isLub, safe)
paulson@15082
   663
apply (case_tac "\<exists>m. X m = U", auto)
paulson@15082
   664
apply (blast dest: lemma_converg1 Bmonoseq_LIMSEQ)
paulson@15082
   665
(* second case *)
paulson@15082
   666
apply (rule_tac x = U in exI)
paulson@15082
   667
apply (subst LIMSEQ_iff, safe)
paulson@15082
   668
apply (frule lemma_converg2, assumption)
paulson@15082
   669
apply (drule lemma_converg4, auto)
paulson@15082
   670
apply (rule_tac x = m in exI, safe)
paulson@15082
   671
apply (subgoal_tac "X m \<le> X n")
paulson@15082
   672
 prefer 2 apply blast
paulson@15082
   673
apply (drule_tac x=n and P="%m. X m < U" in spec, arith)
paulson@15082
   674
done
paulson@15082
   675
paulson@15082
   676
text{*Nonstandard version of the theorem*}
paulson@15082
   677
paulson@15082
   678
lemma NSBseq_mono_NSconvergent:
huffman@20552
   679
     "[| NSBseq X; \<forall>m. \<forall>n \<ge> m. X m \<le> X n |] ==> NSconvergent (X::nat=>real)"
paulson@15082
   680
by (auto intro: Bseq_mono_convergent 
paulson@15082
   681
         simp add: convergent_NSconvergent_iff [symmetric] 
paulson@15082
   682
                   Bseq_NSBseq_iff [symmetric])
paulson@15082
   683
paulson@15082
   684
lemma Bseq_minus_iff: "Bseq (%n. -(X n)) = Bseq X"
paulson@15082
   685
by (simp add: Bseq_def)
paulson@15082
   686
paulson@15082
   687
text{*Main monotonicity theorem*}
paulson@15082
   688
lemma Bseq_monoseq_convergent: "[| Bseq X; monoseq X |] ==> convergent X"
paulson@15082
   689
apply (simp add: monoseq_def, safe)
paulson@15082
   690
apply (rule_tac [2] convergent_minus_iff [THEN ssubst])
paulson@15082
   691
apply (drule_tac [2] Bseq_minus_iff [THEN ssubst])
paulson@15082
   692
apply (auto intro!: Bseq_mono_convergent)
paulson@15082
   693
done
paulson@15082
   694
huffman@20696
   695
subsubsection{*A Few More Equivalence Theorems for Boundedness*}
paulson@15082
   696
paulson@15082
   697
text{*alternative formulation for boundedness*}
huffman@20552
   698
lemma Bseq_iff2: "Bseq X = (\<exists>k > 0. \<exists>x. \<forall>n. norm (X(n) + -x) \<le> k)"
paulson@15082
   699
apply (unfold Bseq_def, safe)
huffman@20552
   700
apply (rule_tac [2] x = "k + norm x" in exI)
nipkow@15360
   701
apply (rule_tac x = K in exI, simp)
paulson@15221
   702
apply (rule exI [where x = 0], auto)
huffman@20552
   703
apply (erule order_less_le_trans, simp)
huffman@20552
   704
apply (drule_tac x=n in spec, fold diff_def)
huffman@20552
   705
apply (drule order_trans [OF norm_triangle_ineq2])
huffman@20552
   706
apply simp
paulson@15082
   707
done
paulson@15082
   708
paulson@15082
   709
text{*alternative formulation for boundedness*}
huffman@20552
   710
lemma Bseq_iff3: "Bseq X = (\<exists>k > 0. \<exists>N. \<forall>n. norm(X(n) + -X(N)) \<le> k)"
paulson@15082
   711
apply safe
paulson@15082
   712
apply (simp add: Bseq_def, safe)
huffman@20552
   713
apply (rule_tac x = "K + norm (X N)" in exI)
paulson@15082
   714
apply auto
huffman@20552
   715
apply (erule order_less_le_trans, simp)
paulson@15082
   716
apply (rule_tac x = N in exI, safe)
huffman@20552
   717
apply (drule_tac x = n in spec)
huffman@20552
   718
apply (rule order_trans [OF norm_triangle_ineq], simp)
paulson@15082
   719
apply (auto simp add: Bseq_iff2)
paulson@15082
   720
done
paulson@15082
   721
huffman@20552
   722
lemma BseqI2: "(\<forall>n. k \<le> f n & f n \<le> (K::real)) ==> Bseq f"
paulson@15082
   723
apply (simp add: Bseq_def)
paulson@15221
   724
apply (rule_tac x = " (\<bar>k\<bar> + \<bar>K\<bar>) + 1" in exI, auto)
webertj@20217
   725
apply (drule_tac x = n in spec, arith)
paulson@15082
   726
done
paulson@15082
   727
paulson@15082
   728
huffman@20696
   729
subsection {* Cauchy Sequences *}
paulson@15082
   730
huffman@20751
   731
lemma CauchyI:
huffman@20751
   732
  "(\<And>e. 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e) \<Longrightarrow> Cauchy X"
huffman@20751
   733
by (simp add: Cauchy_def)
huffman@20751
   734
huffman@20751
   735
lemma CauchyD:
huffman@20751
   736
  "\<lbrakk>Cauchy X; 0 < e\<rbrakk> \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e"
huffman@20751
   737
by (simp add: Cauchy_def)
huffman@20751
   738
huffman@20751
   739
lemma NSCauchyI:
huffman@20751
   740
  "(\<And>M N. \<lbrakk>M \<in> HNatInfinite; N \<in> HNatInfinite\<rbrakk> \<Longrightarrow> starfun X M \<approx> starfun X N)
huffman@20751
   741
   \<Longrightarrow> NSCauchy X"
huffman@20751
   742
by (simp add: NSCauchy_def)
huffman@20751
   743
huffman@20751
   744
lemma NSCauchyD:
huffman@20751
   745
  "\<lbrakk>NSCauchy X; M \<in> HNatInfinite; N \<in> HNatInfinite\<rbrakk>
huffman@20751
   746
   \<Longrightarrow> starfun X M \<approx> starfun X N"
huffman@20751
   747
by (simp add: NSCauchy_def)
huffman@20751
   748
huffman@20696
   749
subsubsection{*Equivalence Between NS and Standard*}
huffman@20696
   750
huffman@20751
   751
lemma Cauchy_NSCauchy:
huffman@20751
   752
  assumes X: "Cauchy X" shows "NSCauchy X"
huffman@20751
   753
proof (rule NSCauchyI)
huffman@20751
   754
  fix M assume M: "M \<in> HNatInfinite"
huffman@20751
   755
  fix N assume N: "N \<in> HNatInfinite"
huffman@20751
   756
  have "starfun X M - starfun X N \<in> Infinitesimal"
huffman@20751
   757
  proof (rule InfinitesimalI2)
huffman@20751
   758
    fix r :: real assume r: "0 < r"
huffman@20751
   759
    from CauchyD [OF X r]
huffman@20751
   760
    obtain k where "\<forall>m\<ge>k. \<forall>n\<ge>k. norm (X m - X n) < r" ..
huffman@20751
   761
    hence "\<forall>m\<ge>star_of k. \<forall>n\<ge>star_of k.
huffman@20751
   762
           hnorm (starfun X m - starfun X n) < star_of r"
huffman@20751
   763
      by transfer
huffman@20751
   764
    thus "hnorm (starfun X M - starfun X N) < star_of r"
huffman@20751
   765
      using M N by (simp add: star_of_le_HNatInfinite)
huffman@20751
   766
  qed
huffman@20751
   767
  thus "starfun X M \<approx> starfun X N"
huffman@20751
   768
    by (unfold approx_def)
huffman@20751
   769
qed
paulson@15082
   770
huffman@20751
   771
lemma NSCauchy_Cauchy:
huffman@20751
   772
  assumes X: "NSCauchy X" shows "Cauchy X"
huffman@20751
   773
proof (rule CauchyI)
huffman@20751
   774
  fix r::real assume r: "0 < r"
huffman@20751
   775
  have "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. hnorm (starfun X m - starfun X n) < star_of r"
huffman@20751
   776
  proof (intro exI allI impI)
huffman@20751
   777
    fix M assume "whn \<le> M"
huffman@20751
   778
    with HNatInfinite_whn have M: "M \<in> HNatInfinite"
huffman@20751
   779
      by (rule HNatInfinite_upward_closed)
huffman@20751
   780
    fix N assume "whn \<le> N"
huffman@20751
   781
    with HNatInfinite_whn have N: "N \<in> HNatInfinite"
huffman@20751
   782
      by (rule HNatInfinite_upward_closed)
huffman@20751
   783
    from X M N have "starfun X M \<approx> starfun X N"
huffman@20751
   784
      by (rule NSCauchyD)
huffman@20751
   785
    hence "starfun X M - starfun X N \<in> Infinitesimal"
huffman@20751
   786
      by (unfold approx_def)
huffman@20751
   787
    thus "hnorm (starfun X M - starfun X N) < star_of r"
huffman@20751
   788
      using r by (rule InfinitesimalD2)
huffman@20751
   789
  qed
huffman@20751
   790
  thus "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. norm (X m - X n) < r"
huffman@20751
   791
    by transfer
huffman@20751
   792
qed
paulson@15082
   793
paulson@15082
   794
theorem NSCauchy_Cauchy_iff: "NSCauchy X = Cauchy X"
paulson@15082
   795
by (blast intro!: NSCauchy_Cauchy Cauchy_NSCauchy)
paulson@15082
   796
huffman@20696
   797
subsubsection {* Cauchy Sequences are Bounded *}
huffman@20696
   798
paulson@15082
   799
text{*A Cauchy sequence is bounded -- this is the standard
paulson@15082
   800
  proof mechanization rather than the nonstandard proof*}
paulson@15082
   801
huffman@20563
   802
lemma lemmaCauchy: "\<forall>n \<ge> M. norm (X M - X n) < (1::real)
huffman@20552
   803
          ==>  \<forall>n \<ge> M. norm (X n :: 'a::real_normed_vector) < 1 + norm (X M)"
huffman@20552
   804
apply (clarify, drule spec, drule (1) mp)
huffman@20563
   805
apply (simp only: norm_minus_commute)
huffman@20552
   806
apply (drule order_le_less_trans [OF norm_triangle_ineq2])
huffman@20552
   807
apply simp
huffman@20552
   808
done
paulson@15082
   809
huffman@20552
   810
lemma Bseq_Suc_imp_Bseq: "Bseq (\<lambda>n. X (Suc n)) \<Longrightarrow> Bseq X"
huffman@20552
   811
apply (unfold Bseq_def, clarify)
huffman@20552
   812
apply (rule_tac x="max K (norm (X 0))" in exI)
huffman@20552
   813
apply (simp add: order_less_le_trans [OF _ le_maxI1])
huffman@20552
   814
apply (clarify, case_tac "n", simp)
huffman@20552
   815
apply (simp add: order_trans [OF _ le_maxI1])
huffman@20552
   816
done
huffman@20552
   817
huffman@20552
   818
lemma Bseq_shift_imp_Bseq: "Bseq (\<lambda>n. X (n + k)) \<Longrightarrow> Bseq X"
huffman@20552
   819
apply (induct k, simp_all)
huffman@20552
   820
apply (subgoal_tac "Bseq (\<lambda>n. X (n + k))", simp)
huffman@20552
   821
apply (rule Bseq_Suc_imp_Bseq, simp)
huffman@20552
   822
done
huffman@20552
   823
paulson@15082
   824
lemma Cauchy_Bseq: "Cauchy X ==> Bseq X"
huffman@20552
   825
apply (simp add: Cauchy_def)
huffman@20552
   826
apply (drule spec, drule mp, rule zero_less_one, safe)
huffman@20552
   827
apply (drule_tac x="M" in spec, simp)
paulson@15082
   828
apply (drule lemmaCauchy)
huffman@20552
   829
apply (rule_tac k="M" in Bseq_shift_imp_Bseq)
huffman@20552
   830
apply (simp add: Bseq_def)
huffman@20552
   831
apply (rule_tac x="1 + norm (X M)" in exI)
huffman@20552
   832
apply (rule conjI, rule order_less_le_trans [OF zero_less_one], simp)
huffman@20552
   833
apply (simp add: order_less_imp_le)
paulson@15082
   834
done
paulson@15082
   835
paulson@15082
   836
text{*A Cauchy sequence is bounded -- nonstandard version*}
paulson@15082
   837
paulson@15082
   838
lemma NSCauchy_NSBseq: "NSCauchy X ==> NSBseq X"
paulson@15082
   839
by (simp add: Cauchy_Bseq Bseq_NSBseq_iff [symmetric] NSCauchy_Cauchy_iff)
paulson@15082
   840
huffman@20696
   841
subsubsection {* Cauchy Sequences are Convergent *}
paulson@15082
   842
huffman@20830
   843
axclass banach \<subseteq> real_normed_vector
huffman@20830
   844
  Cauchy_convergent: "Cauchy X \<Longrightarrow> convergent X"
huffman@20830
   845
paulson@15082
   846
text{*Equivalence of Cauchy criterion and convergence:
paulson@15082
   847
  We will prove this using our NS formulation which provides a
paulson@15082
   848
  much easier proof than using the standard definition. We do not
paulson@15082
   849
  need to use properties of subsequences such as boundedness,
paulson@15082
   850
  monotonicity etc... Compare with Harrison's corresponding proof
paulson@15082
   851
  in HOL which is much longer and more complicated. Of course, we do
paulson@15082
   852
  not have problems which he encountered with guessing the right
paulson@15082
   853
  instantiations for his 'espsilon-delta' proof(s) in this case
paulson@15082
   854
  since the NS formulations do not involve existential quantifiers.*}
paulson@15082
   855
huffman@20691
   856
lemma NSconvergent_NSCauchy: "NSconvergent X \<Longrightarrow> NSCauchy X"
huffman@20691
   857
apply (simp add: NSconvergent_def NSLIMSEQ_def NSCauchy_def, safe)
huffman@20691
   858
apply (auto intro: approx_trans2)
huffman@20691
   859
done
huffman@20691
   860
huffman@20691
   861
lemma convergent_Cauchy: "convergent X \<Longrightarrow> Cauchy X"
huffman@20691
   862
apply (rule NSconvergent_NSCauchy [THEN NSCauchy_Cauchy])
huffman@20691
   863
apply (simp add: convergent_NSconvergent_iff)
huffman@20691
   864
done
huffman@20691
   865
huffman@20830
   866
lemma real_NSCauchy_NSconvergent:
huffman@20830
   867
  fixes X :: "nat \<Rightarrow> real"
huffman@20830
   868
  shows "NSCauchy X \<Longrightarrow> NSconvergent X"
huffman@20830
   869
apply (simp add: NSconvergent_def NSLIMSEQ_def)
paulson@15082
   870
apply (frule NSCauchy_NSBseq)
huffman@20830
   871
apply (simp add: NSBseq_def NSCauchy_def)
paulson@15082
   872
apply (drule HNatInfinite_whn [THEN [2] bspec])
paulson@15082
   873
apply (drule HNatInfinite_whn [THEN [2] bspec])
paulson@15082
   874
apply (auto dest!: st_part_Ex simp add: SReal_iff)
paulson@15082
   875
apply (blast intro: approx_trans3)
paulson@15082
   876
done
paulson@15082
   877
paulson@15082
   878
text{*Standard proof for free*}
huffman@20830
   879
lemma real_Cauchy_convergent:
huffman@20830
   880
  fixes X :: "nat \<Rightarrow> real"
huffman@20830
   881
  shows "Cauchy X \<Longrightarrow> convergent X"
huffman@20830
   882
apply (drule Cauchy_NSCauchy [THEN real_NSCauchy_NSconvergent])
huffman@20830
   883
apply (erule convergent_NSconvergent_iff [THEN iffD2])
huffman@20830
   884
done
huffman@20830
   885
huffman@20830
   886
instance real :: banach
huffman@20830
   887
by intro_classes (rule real_Cauchy_convergent)
huffman@20830
   888
huffman@20830
   889
lemma NSCauchy_NSconvergent:
huffman@20830
   890
  fixes X :: "nat \<Rightarrow> 'a::banach"
huffman@20830
   891
  shows "NSCauchy X \<Longrightarrow> NSconvergent X"
huffman@20830
   892
apply (drule NSCauchy_Cauchy [THEN Cauchy_convergent])
huffman@20830
   893
apply (erule convergent_NSconvergent_iff [THEN iffD1])
huffman@20830
   894
done
huffman@20830
   895
huffman@20830
   896
lemma NSCauchy_NSconvergent_iff:
huffman@20830
   897
  fixes X :: "nat \<Rightarrow> 'a::banach"
huffman@20830
   898
  shows "NSCauchy X = NSconvergent X"
huffman@20830
   899
by (fast intro: NSCauchy_NSconvergent NSconvergent_NSCauchy)
huffman@20830
   900
huffman@20830
   901
lemma Cauchy_convergent_iff:
huffman@20830
   902
  fixes X :: "nat \<Rightarrow> 'a::banach"
huffman@20830
   903
  shows "Cauchy X = convergent X"
huffman@20830
   904
by (fast intro: Cauchy_convergent convergent_Cauchy)
paulson@15082
   905
paulson@15082
   906
huffman@20696
   907
subsection {* More Properties of Sequences *}
huffman@20696
   908
paulson@15082
   909
text{*We can now try and derive a few properties of sequences,
paulson@15082
   910
     starting with the limit comparison property for sequences.*}
paulson@15082
   911
paulson@15082
   912
lemma NSLIMSEQ_le:
paulson@15082
   913
       "[| f ----NS> l; g ----NS> m;
nipkow@15360
   914
           \<exists>N. \<forall>n \<ge> N. f(n) \<le> g(n)
huffman@20552
   915
        |] ==> l \<le> (m::real)"
paulson@15082
   916
apply (simp add: NSLIMSEQ_def, safe)
paulson@15082
   917
apply (drule starfun_le_mono)
paulson@15082
   918
apply (drule HNatInfinite_whn [THEN [2] bspec])+
paulson@15082
   919
apply (drule_tac x = whn in spec)
paulson@15082
   920
apply (drule bex_Infinitesimal_iff2 [THEN iffD2])+
paulson@15082
   921
apply clarify
paulson@15082
   922
apply (auto intro: hypreal_of_real_le_add_Infininitesimal_cancel2)
paulson@15082
   923
done
paulson@15082
   924
paulson@15082
   925
(* standard version *)
paulson@15082
   926
lemma LIMSEQ_le:
nipkow@15360
   927
     "[| f ----> l; g ----> m; \<exists>N. \<forall>n \<ge> N. f(n) \<le> g(n) |]
huffman@20552
   928
      ==> l \<le> (m::real)"
paulson@15082
   929
by (simp add: LIMSEQ_NSLIMSEQ_iff NSLIMSEQ_le)
paulson@15082
   930
huffman@20552
   931
lemma LIMSEQ_le_const: "[| X ----> (r::real); \<forall>n. a \<le> X n |] ==> a \<le> r"
paulson@15082
   932
apply (rule LIMSEQ_le)
paulson@15082
   933
apply (rule LIMSEQ_const, auto)
paulson@15082
   934
done
paulson@15082
   935
huffman@20552
   936
lemma NSLIMSEQ_le_const: "[| X ----NS> (r::real); \<forall>n. a \<le> X n |] ==> a \<le> r"
paulson@15082
   937
by (simp add: LIMSEQ_NSLIMSEQ_iff LIMSEQ_le_const)
paulson@15082
   938
huffman@20552
   939
lemma LIMSEQ_le_const2: "[| X ----> (r::real); \<forall>n. X n \<le> a |] ==> r \<le> a"
paulson@15082
   940
apply (rule LIMSEQ_le)
paulson@15082
   941
apply (rule_tac [2] LIMSEQ_const, auto)
paulson@15082
   942
done
paulson@15082
   943
huffman@20552
   944
lemma NSLIMSEQ_le_const2: "[| X ----NS> (r::real); \<forall>n. X n \<le> a |] ==> r \<le> a"
paulson@15082
   945
by (simp add: LIMSEQ_NSLIMSEQ_iff LIMSEQ_le_const2)
paulson@15082
   946
paulson@15082
   947
text{*Shift a convergent series by 1:
paulson@15082
   948
  By the equivalence between Cauchiness and convergence and because
paulson@15082
   949
  the successor of an infinite hypernatural is also infinite.*}
paulson@15082
   950
paulson@15082
   951
lemma NSLIMSEQ_Suc: "f ----NS> l ==> (%n. f(Suc n)) ----NS> l"
huffman@20552
   952
apply (unfold NSLIMSEQ_def, safe)
huffman@20552
   953
apply (drule_tac x="N + 1" in bspec)
huffman@20740
   954
apply (erule HNatInfinite_add)
huffman@20552
   955
apply (simp add: starfun_shift_one)
paulson@15082
   956
done
paulson@15082
   957
paulson@15082
   958
text{* standard version *}
paulson@15082
   959
lemma LIMSEQ_Suc: "f ----> l ==> (%n. f(Suc n)) ----> l"
paulson@15082
   960
by (simp add: LIMSEQ_NSLIMSEQ_iff NSLIMSEQ_Suc)
paulson@15082
   961
paulson@15082
   962
lemma NSLIMSEQ_imp_Suc: "(%n. f(Suc n)) ----NS> l ==> f ----NS> l"
huffman@20552
   963
apply (unfold NSLIMSEQ_def, safe)
paulson@15082
   964
apply (drule_tac x="N - 1" in bspec) 
huffman@20740
   965
apply (erule Nats_1 [THEN [2] HNatInfinite_diff])
huffman@20740
   966
apply (simp add: starfun_shift_one one_le_HNatInfinite)
paulson@15082
   967
done
paulson@15082
   968
paulson@15082
   969
lemma LIMSEQ_imp_Suc: "(%n. f(Suc n)) ----> l ==> f ----> l"
paulson@15082
   970
apply (simp add: LIMSEQ_NSLIMSEQ_iff)
paulson@15082
   971
apply (erule NSLIMSEQ_imp_Suc)
paulson@15082
   972
done
paulson@15082
   973
paulson@15082
   974
lemma LIMSEQ_Suc_iff: "((%n. f(Suc n)) ----> l) = (f ----> l)"
paulson@15082
   975
by (blast intro: LIMSEQ_imp_Suc LIMSEQ_Suc)
paulson@15082
   976
paulson@15082
   977
lemma NSLIMSEQ_Suc_iff: "((%n. f(Suc n)) ----NS> l) = (f ----NS> l)"
paulson@15082
   978
by (blast intro: NSLIMSEQ_imp_Suc NSLIMSEQ_Suc)
paulson@15082
   979
paulson@15082
   980
text{*A sequence tends to zero iff its abs does*}
huffman@20685
   981
lemma LIMSEQ_norm_zero: "((\<lambda>n. norm (X n)) ----> 0) = (X ----> 0)"
huffman@20685
   982
by (simp add: LIMSEQ_def)
huffman@20685
   983
huffman@20552
   984
lemma LIMSEQ_rabs_zero: "((%n. \<bar>f n\<bar>) ----> 0) = (f ----> (0::real))"
paulson@15082
   985
by (simp add: LIMSEQ_def)
paulson@15082
   986
paulson@15082
   987
text{*We prove the NS version from the standard one, since the NS proof
paulson@15082
   988
   seems more complicated than the standard one above!*}
huffman@20685
   989
lemma NSLIMSEQ_norm_zero: "((\<lambda>n. norm (X n)) ----NS> 0) = (X ----NS> 0)"
huffman@20685
   990
by (simp add: LIMSEQ_NSLIMSEQ_iff [symmetric] LIMSEQ_norm_zero)
huffman@20685
   991
huffman@20552
   992
lemma NSLIMSEQ_rabs_zero: "((%n. \<bar>f n\<bar>) ----NS> 0) = (f ----NS> (0::real))"
paulson@15082
   993
by (simp add: LIMSEQ_NSLIMSEQ_iff [symmetric] LIMSEQ_rabs_zero)
paulson@15082
   994
paulson@15082
   995
text{*Generalization to other limits*}
huffman@20552
   996
lemma NSLIMSEQ_imp_rabs: "f ----NS> (l::real) ==> (%n. \<bar>f n\<bar>) ----NS> \<bar>l\<bar>"
paulson@15082
   997
apply (simp add: NSLIMSEQ_def)
paulson@15082
   998
apply (auto intro: approx_hrabs 
huffman@17318
   999
            simp add: starfun_abs hypreal_of_real_hrabs [symmetric])
paulson@15082
  1000
done
paulson@15082
  1001
paulson@15082
  1002
text{* standard version *}
huffman@20552
  1003
lemma LIMSEQ_imp_rabs: "f ----> (l::real) ==> (%n. \<bar>f n\<bar>) ----> \<bar>l\<bar>"
paulson@15082
  1004
by (simp add: LIMSEQ_NSLIMSEQ_iff NSLIMSEQ_imp_rabs)
paulson@15082
  1005
paulson@15082
  1006
text{*An unbounded sequence's inverse tends to 0*}
paulson@15082
  1007
paulson@15082
  1008
text{* standard proof seems easier *}
paulson@15082
  1009
lemma LIMSEQ_inverse_zero:
huffman@20552
  1010
      "\<forall>y::real. \<exists>N. \<forall>n \<ge> N. y < f(n) ==> (%n. inverse(f n)) ----> 0"
paulson@15082
  1011
apply (simp add: LIMSEQ_def, safe)
paulson@15082
  1012
apply (drule_tac x = "inverse r" in spec, safe)
paulson@15082
  1013
apply (rule_tac x = N in exI, safe)
paulson@15082
  1014
apply (drule spec, auto)
paulson@15082
  1015
apply (frule positive_imp_inverse_positive)
paulson@15082
  1016
apply (frule order_less_trans, assumption)
paulson@15082
  1017
apply (frule_tac a = "f n" in positive_imp_inverse_positive)
paulson@15082
  1018
apply (simp add: abs_if) 
paulson@15082
  1019
apply (rule_tac t = r in inverse_inverse_eq [THEN subst])
paulson@15082
  1020
apply (auto intro: inverse_less_iff_less [THEN iffD2]
paulson@15082
  1021
            simp del: inverse_inverse_eq)
paulson@15082
  1022
done
paulson@15082
  1023
paulson@15082
  1024
lemma NSLIMSEQ_inverse_zero:
huffman@20552
  1025
     "\<forall>y::real. \<exists>N. \<forall>n \<ge> N. y < f(n)
paulson@15082
  1026
      ==> (%n. inverse(f n)) ----NS> 0"
paulson@15082
  1027
by (simp add: LIMSEQ_NSLIMSEQ_iff [symmetric] LIMSEQ_inverse_zero)
paulson@15082
  1028
paulson@15082
  1029
text{*The sequence @{term "1/n"} tends to 0 as @{term n} tends to infinity*}
paulson@15082
  1030
paulson@15082
  1031
lemma LIMSEQ_inverse_real_of_nat: "(%n. inverse(real(Suc n))) ----> 0"
paulson@15082
  1032
apply (rule LIMSEQ_inverse_zero, safe)
paulson@15082
  1033
apply (cut_tac x = y in reals_Archimedean2)
paulson@15082
  1034
apply (safe, rule_tac x = n in exI)
paulson@15082
  1035
apply (auto simp add: real_of_nat_Suc)
paulson@15082
  1036
done
paulson@15082
  1037
paulson@15082
  1038
lemma NSLIMSEQ_inverse_real_of_nat: "(%n. inverse(real(Suc n))) ----NS> 0"
paulson@15082
  1039
by (simp add: LIMSEQ_NSLIMSEQ_iff [symmetric] LIMSEQ_inverse_real_of_nat)
paulson@15082
  1040
paulson@15082
  1041
text{*The sequence @{term "r + 1/n"} tends to @{term r} as @{term n} tends to
paulson@15082
  1042
infinity is now easily proved*}
paulson@15082
  1043
paulson@15082
  1044
lemma LIMSEQ_inverse_real_of_nat_add:
paulson@15082
  1045
     "(%n. r + inverse(real(Suc n))) ----> r"
paulson@15082
  1046
by (cut_tac LIMSEQ_add [OF LIMSEQ_const LIMSEQ_inverse_real_of_nat], auto)
paulson@15082
  1047
paulson@15082
  1048
lemma NSLIMSEQ_inverse_real_of_nat_add:
paulson@15082
  1049
     "(%n. r + inverse(real(Suc n))) ----NS> r"
paulson@15082
  1050
by (simp add: LIMSEQ_NSLIMSEQ_iff [symmetric] LIMSEQ_inverse_real_of_nat_add)
paulson@15082
  1051
paulson@15082
  1052
lemma LIMSEQ_inverse_real_of_nat_add_minus:
paulson@15082
  1053
     "(%n. r + -inverse(real(Suc n))) ----> r"
paulson@15082
  1054
by (cut_tac LIMSEQ_add_minus [OF LIMSEQ_const LIMSEQ_inverse_real_of_nat], auto)
paulson@15082
  1055
paulson@15082
  1056
lemma NSLIMSEQ_inverse_real_of_nat_add_minus:
paulson@15082
  1057
     "(%n. r + -inverse(real(Suc n))) ----NS> r"
paulson@15082
  1058
by (simp add: LIMSEQ_NSLIMSEQ_iff [symmetric] LIMSEQ_inverse_real_of_nat_add_minus)
paulson@15082
  1059
paulson@15082
  1060
lemma LIMSEQ_inverse_real_of_nat_add_minus_mult:
paulson@15082
  1061
     "(%n. r*( 1 + -inverse(real(Suc n)))) ----> r"
paulson@15082
  1062
by (cut_tac b=1 in
paulson@15082
  1063
        LIMSEQ_mult [OF LIMSEQ_const LIMSEQ_inverse_real_of_nat_add_minus], auto)
paulson@15082
  1064
paulson@15082
  1065
lemma NSLIMSEQ_inverse_real_of_nat_add_minus_mult:
paulson@15082
  1066
     "(%n. r*( 1 + -inverse(real(Suc n)))) ----NS> r"
paulson@15082
  1067
by (simp add: LIMSEQ_NSLIMSEQ_iff [symmetric] LIMSEQ_inverse_real_of_nat_add_minus_mult)
paulson@15082
  1068
paulson@15082
  1069
huffman@20696
  1070
subsection {* Power Sequences *}
paulson@15082
  1071
paulson@15082
  1072
text{*The sequence @{term "x^n"} tends to 0 if @{term "0\<le>x"} and @{term
paulson@15082
  1073
"x<1"}.  Proof will use (NS) Cauchy equivalence for convergence and
paulson@15082
  1074
  also fact that bounded and monotonic sequence converges.*}
paulson@15082
  1075
huffman@20552
  1076
lemma Bseq_realpow: "[| 0 \<le> (x::real); x \<le> 1 |] ==> Bseq (%n. x ^ n)"
paulson@15082
  1077
apply (simp add: Bseq_def)
paulson@15082
  1078
apply (rule_tac x = 1 in exI)
paulson@15082
  1079
apply (simp add: power_abs)
paulson@15082
  1080
apply (auto dest: power_mono intro: order_less_imp_le simp add: abs_if)
paulson@15082
  1081
done
paulson@15082
  1082
paulson@15082
  1083
lemma monoseq_realpow: "[| 0 \<le> x; x \<le> 1 |] ==> monoseq (%n. x ^ n)"
paulson@15082
  1084
apply (clarify intro!: mono_SucI2)
paulson@15082
  1085
apply (cut_tac n = n and N = "Suc n" and a = x in power_decreasing, auto)
paulson@15082
  1086
done
paulson@15082
  1087
huffman@20552
  1088
lemma convergent_realpow:
huffman@20552
  1089
  "[| 0 \<le> (x::real); x \<le> 1 |] ==> convergent (%n. x ^ n)"
paulson@15082
  1090
by (blast intro!: Bseq_monoseq_convergent Bseq_realpow monoseq_realpow)
paulson@15082
  1091
paulson@15082
  1092
text{* We now use NS criterion to bring proof of theorem through *}
paulson@15082
  1093
huffman@20552
  1094
lemma NSLIMSEQ_realpow_zero:
huffman@20552
  1095
  "[| 0 \<le> (x::real); x < 1 |] ==> (%n. x ^ n) ----NS> 0"
paulson@15082
  1096
apply (simp add: NSLIMSEQ_def)
paulson@15082
  1097
apply (auto dest!: convergent_realpow simp add: convergent_NSconvergent_iff)
paulson@15082
  1098
apply (frule NSconvergentD)
huffman@17318
  1099
apply (auto simp add: NSLIMSEQ_def NSCauchy_NSconvergent_iff [symmetric] NSCauchy_def starfun_pow)
paulson@15082
  1100
apply (frule HNatInfinite_add_one)
paulson@15082
  1101
apply (drule bspec, assumption)
paulson@15082
  1102
apply (drule bspec, assumption)
paulson@15082
  1103
apply (drule_tac x = "N + (1::hypnat) " in bspec, assumption)
paulson@15082
  1104
apply (simp add: hyperpow_add)
paulson@15082
  1105
apply (drule approx_mult_subst_SReal, assumption)
paulson@15082
  1106
apply (drule approx_trans3, assumption)
huffman@17318
  1107
apply (auto simp del: star_of_mult simp add: star_of_mult [symmetric])
paulson@15082
  1108
done
paulson@15082
  1109
paulson@15082
  1110
text{* standard version *}
huffman@20552
  1111
lemma LIMSEQ_realpow_zero:
huffman@20552
  1112
  "[| 0 \<le> (x::real); x < 1 |] ==> (%n. x ^ n) ----> 0"
paulson@15082
  1113
by (simp add: NSLIMSEQ_realpow_zero LIMSEQ_NSLIMSEQ_iff)
paulson@15082
  1114
huffman@20685
  1115
lemma LIMSEQ_power_zero:
huffman@20685
  1116
  fixes x :: "'a::{real_normed_div_algebra,recpower}"
huffman@20685
  1117
  shows "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) ----> 0"
huffman@20685
  1118
apply (drule LIMSEQ_realpow_zero [OF norm_ge_zero])
huffman@20685
  1119
apply (simp add: norm_power [symmetric] LIMSEQ_norm_zero)
huffman@20685
  1120
done
huffman@20685
  1121
huffman@20552
  1122
lemma LIMSEQ_divide_realpow_zero:
huffman@20552
  1123
  "1 < (x::real) ==> (%n. a / (x ^ n)) ----> 0"
paulson@15082
  1124
apply (cut_tac a = a and x1 = "inverse x" in
paulson@15082
  1125
        LIMSEQ_mult [OF LIMSEQ_const LIMSEQ_realpow_zero])
paulson@15082
  1126
apply (auto simp add: divide_inverse power_inverse)
paulson@15082
  1127
apply (simp add: inverse_eq_divide pos_divide_less_eq)
paulson@15082
  1128
done
paulson@15082
  1129
paulson@15102
  1130
text{*Limit of @{term "c^n"} for @{term"\<bar>c\<bar> < 1"}*}
paulson@15082
  1131
huffman@20552
  1132
lemma LIMSEQ_rabs_realpow_zero: "\<bar>c\<bar> < (1::real) ==> (%n. \<bar>c\<bar> ^ n) ----> 0"
huffman@20685
  1133
by (rule LIMSEQ_realpow_zero [OF abs_ge_zero])
paulson@15082
  1134
huffman@20552
  1135
lemma NSLIMSEQ_rabs_realpow_zero: "\<bar>c\<bar> < (1::real) ==> (%n. \<bar>c\<bar> ^ n) ----NS> 0"
paulson@15082
  1136
by (simp add: LIMSEQ_rabs_realpow_zero LIMSEQ_NSLIMSEQ_iff [symmetric])
paulson@15082
  1137
huffman@20552
  1138
lemma LIMSEQ_rabs_realpow_zero2: "\<bar>c\<bar> < (1::real) ==> (%n. c ^ n) ----> 0"
paulson@15082
  1139
apply (rule LIMSEQ_rabs_zero [THEN iffD1])
paulson@15082
  1140
apply (auto intro: LIMSEQ_rabs_realpow_zero simp add: power_abs)
paulson@15082
  1141
done
paulson@15082
  1142
huffman@20552
  1143
lemma NSLIMSEQ_rabs_realpow_zero2: "\<bar>c\<bar> < (1::real) ==> (%n. c ^ n) ----NS> 0"
paulson@15082
  1144
by (simp add: LIMSEQ_rabs_realpow_zero2 LIMSEQ_NSLIMSEQ_iff [symmetric])
paulson@15082
  1145
paulson@15082
  1146
subsection{*Hyperreals and Sequences*}
paulson@15082
  1147
paulson@15082
  1148
text{*A bounded sequence is a finite hyperreal*}
huffman@17318
  1149
lemma NSBseq_HFinite_hypreal: "NSBseq X ==> star_n X : HFinite"
huffman@17298
  1150
by (auto intro!: bexI lemma_starrel_refl 
paulson@15082
  1151
            intro: FreeUltrafilterNat_all [THEN FreeUltrafilterNat_subset]
paulson@15082
  1152
            simp add: HFinite_FreeUltrafilterNat_iff Bseq_NSBseq_iff [symmetric]
paulson@15082
  1153
                      Bseq_iff1a)
paulson@15082
  1154
paulson@15082
  1155
text{*A sequence converging to zero defines an infinitesimal*}
paulson@15082
  1156
lemma NSLIMSEQ_zero_Infinitesimal_hypreal:
huffman@17318
  1157
      "X ----NS> 0 ==> star_n X : Infinitesimal"
paulson@15082
  1158
apply (simp add: NSLIMSEQ_def)
paulson@15082
  1159
apply (drule_tac x = whn in bspec)
paulson@15082
  1160
apply (simp add: HNatInfinite_whn)
huffman@17318
  1161
apply (auto simp add: hypnat_omega_def mem_infmal_iff [symmetric] starfun)
paulson@15082
  1162
done
paulson@15082
  1163
paulson@15082
  1164
(***---------------------------------------------------------------
paulson@15082
  1165
    Theorems proved by Harrison in HOL that we do not need
paulson@15082
  1166
    in order to prove equivalence between Cauchy criterion
paulson@15082
  1167
    and convergence:
paulson@15082
  1168
 -- Show that every sequence contains a monotonic subsequence
paulson@15082
  1169
Goal "\<exists>f. subseq f & monoseq (%n. s (f n))"
paulson@15082
  1170
 -- Show that a subsequence of a bounded sequence is bounded
paulson@15082
  1171
Goal "Bseq X ==> Bseq (%n. X (f n))";
paulson@15082
  1172
 -- Show we can take subsequential terms arbitrarily far
paulson@15082
  1173
    up a sequence
paulson@15082
  1174
Goal "subseq f ==> n \<le> f(n)";
paulson@15082
  1175
Goal "subseq f ==> \<exists>n. N1 \<le> n & N2 \<le> f(n)";
paulson@15082
  1176
 ---------------------------------------------------------------***)
paulson@15082
  1177
paulson@10751
  1178
end