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