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