src/HOL/SEQ.thy
author paulson
Mon Oct 05 17:27:46 2009 +0100 (2009-10-05)
changeset 32877 6f09346c7c08
parent 32707 836ec9d0a0c8
child 32960 69916a850301
permissions -rw-r--r--
New lemmas connected with the reals and infinite series
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
huffman@22608
     6
    Additional contributions by Jeremy Avigad and Brian Huffman
paulson@15082
     7
*)
paulson@10751
     8
huffman@22631
     9
header {* Sequences and Convergence *}
huffman@17439
    10
nipkow@15131
    11
theory SEQ
huffman@31349
    12
imports Limits
nipkow@15131
    13
begin
paulson@10751
    14
wenzelm@19765
    15
definition
huffman@22608
    16
  Zseq :: "[nat \<Rightarrow> 'a::real_normed_vector] \<Rightarrow> bool" where
huffman@22608
    17
    --{*Standard definition of sequence converging to zero*}
haftmann@28562
    18
  [code del]: "Zseq X = (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. norm (X n) < r)"
huffman@22608
    19
huffman@22608
    20
definition
huffman@31336
    21
  LIMSEQ :: "[nat \<Rightarrow> 'a::metric_space, 'a] \<Rightarrow> bool"
wenzelm@21404
    22
    ("((_)/ ----> (_))" [60, 60] 60) where
paulson@15082
    23
    --{*Standard definition of convergence of sequence*}
huffman@31336
    24
  [code del]: "X ----> L = (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. dist (X n) L < r)"
paulson@10751
    25
wenzelm@21404
    26
definition
huffman@31404
    27
  lim :: "(nat \<Rightarrow> 'a::metric_space) \<Rightarrow> 'a" where
paulson@15082
    28
    --{*Standard definition of limit using choice operator*}
huffman@20682
    29
  "lim X = (THE L. X ----> L)"
paulson@10751
    30
wenzelm@21404
    31
definition
huffman@31336
    32
  convergent :: "(nat \<Rightarrow> 'a::metric_space) \<Rightarrow> bool" where
paulson@15082
    33
    --{*Standard definition of convergence*}
huffman@20682
    34
  "convergent X = (\<exists>L. X ----> L)"
paulson@10751
    35
wenzelm@21404
    36
definition
wenzelm@21404
    37
  Bseq :: "(nat => 'a::real_normed_vector) => bool" where
paulson@15082
    38
    --{*Standard definition for bounded sequence*}
haftmann@28562
    39
  [code del]: "Bseq X = (\<exists>K>0.\<forall>n. norm (X n) \<le> K)"
paulson@10751
    40
wenzelm@21404
    41
definition
wenzelm@21404
    42
  monoseq :: "(nat=>real)=>bool" where
paulson@30730
    43
    --{*Definition of monotonicity. 
paulson@30730
    44
        The use of disjunction here complicates proofs considerably. 
paulson@30730
    45
        One alternative is to add a Boolean argument to indicate the direction. 
paulson@30730
    46
        Another is to develop the notions of increasing and decreasing first.*}
haftmann@28562
    47
  [code del]: "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
    48
wenzelm@21404
    49
definition
paulson@30730
    50
  incseq :: "(nat=>real)=>bool" where
paulson@30730
    51
    --{*Increasing sequence*}
paulson@30730
    52
  [code del]: "incseq X = (\<forall>m. \<forall>n\<ge>m. X m \<le> X n)"
paulson@30730
    53
paulson@30730
    54
definition
paulson@30730
    55
  decseq :: "(nat=>real)=>bool" where
paulson@30730
    56
    --{*Increasing sequence*}
paulson@30730
    57
  [code del]: "decseq X = (\<forall>m. \<forall>n\<ge>m. X n \<le> X m)"
paulson@30730
    58
paulson@30730
    59
definition
wenzelm@21404
    60
  subseq :: "(nat => nat) => bool" where
paulson@15082
    61
    --{*Definition of subsequence*}
haftmann@28562
    62
  [code del]:   "subseq f = (\<forall>m. \<forall>n>m. (f m) < (f n))"
paulson@10751
    63
wenzelm@21404
    64
definition
huffman@31336
    65
  Cauchy :: "(nat \<Rightarrow> 'a::metric_space) \<Rightarrow> bool" where
paulson@15082
    66
    --{*Standard definition of the Cauchy condition*}
huffman@31336
    67
  [code del]: "Cauchy X = (\<forall>e>0. \<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. dist (X m) (X n) < e)"
paulson@10751
    68
paulson@15082
    69
huffman@22608
    70
subsection {* Bounded Sequences *}
huffman@22608
    71
wenzelm@26312
    72
lemma BseqI': assumes K: "\<And>n. norm (X n) \<le> K" shows "Bseq X"
huffman@22608
    73
unfolding Bseq_def
huffman@22608
    74
proof (intro exI conjI allI)
huffman@22608
    75
  show "0 < max K 1" by simp
huffman@22608
    76
next
huffman@22608
    77
  fix n::nat
huffman@22608
    78
  have "norm (X n) \<le> K" by (rule K)
huffman@22608
    79
  thus "norm (X n) \<le> max K 1" by simp
huffman@22608
    80
qed
huffman@22608
    81
huffman@22608
    82
lemma BseqE: "\<lbrakk>Bseq X; \<And>K. \<lbrakk>0 < K; \<forall>n. norm (X n) \<le> K\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@22608
    83
unfolding Bseq_def by auto
huffman@22608
    84
wenzelm@26312
    85
lemma BseqI2': assumes K: "\<forall>n\<ge>N. norm (X n) \<le> K" shows "Bseq X"
wenzelm@26312
    86
proof (rule BseqI')
huffman@22608
    87
  let ?A = "norm ` X ` {..N}"
huffman@22608
    88
  have 1: "finite ?A" by simp
huffman@22608
    89
  fix n::nat
huffman@22608
    90
  show "norm (X n) \<le> max K (Max ?A)"
huffman@22608
    91
  proof (cases rule: linorder_le_cases)
huffman@22608
    92
    assume "n \<ge> N"
huffman@22608
    93
    hence "norm (X n) \<le> K" using K by simp
huffman@22608
    94
    thus "norm (X n) \<le> max K (Max ?A)" by simp
huffman@22608
    95
  next
huffman@22608
    96
    assume "n \<le> N"
huffman@22608
    97
    hence "norm (X n) \<in> ?A" by simp
haftmann@26757
    98
    with 1 have "norm (X n) \<le> Max ?A" by (rule Max_ge)
huffman@22608
    99
    thus "norm (X n) \<le> max K (Max ?A)" by simp
huffman@22608
   100
  qed
huffman@22608
   101
qed
huffman@22608
   102
huffman@22608
   103
lemma Bseq_ignore_initial_segment: "Bseq X \<Longrightarrow> Bseq (\<lambda>n. X (n + k))"
huffman@22608
   104
unfolding Bseq_def by auto
huffman@22608
   105
huffman@22608
   106
lemma Bseq_offset: "Bseq (\<lambda>n. X (n + k)) \<Longrightarrow> Bseq X"
huffman@22608
   107
apply (erule BseqE)
wenzelm@26312
   108
apply (rule_tac N="k" and K="K" in BseqI2')
huffman@22608
   109
apply clarify
huffman@22608
   110
apply (drule_tac x="n - k" in spec, simp)
huffman@22608
   111
done
huffman@22608
   112
huffman@31355
   113
lemma Bseq_conv_Bfun: "Bseq X \<longleftrightarrow> Bfun X sequentially"
huffman@31355
   114
unfolding Bfun_def eventually_sequentially
huffman@31355
   115
apply (rule iffI)
haftmann@32064
   116
apply (simp add: Bseq_def)
haftmann@32064
   117
apply (auto intro: BseqI2')
huffman@31355
   118
done
huffman@31355
   119
huffman@22608
   120
huffman@22608
   121
subsection {* Sequences That Converge to Zero *}
huffman@22608
   122
huffman@22608
   123
lemma ZseqI:
huffman@22608
   124
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n) < r) \<Longrightarrow> Zseq X"
huffman@22608
   125
unfolding Zseq_def by simp
huffman@22608
   126
huffman@22608
   127
lemma ZseqD:
huffman@22608
   128
  "\<lbrakk>Zseq X; 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n) < r"
huffman@22608
   129
unfolding Zseq_def by simp
huffman@22608
   130
huffman@31392
   131
lemma Zseq_conv_Zfun: "Zseq X \<longleftrightarrow> Zfun X sequentially"
huffman@31392
   132
unfolding Zseq_def Zfun_def eventually_sequentially ..
huffman@31392
   133
huffman@22608
   134
lemma Zseq_zero: "Zseq (\<lambda>n. 0)"
huffman@22608
   135
unfolding Zseq_def by simp
huffman@22608
   136
huffman@22608
   137
lemma Zseq_const_iff: "Zseq (\<lambda>n. k) = (k = 0)"
huffman@22608
   138
unfolding Zseq_def by force
huffman@22608
   139
huffman@22608
   140
lemma Zseq_norm_iff: "Zseq (\<lambda>n. norm (X n)) = Zseq (\<lambda>n. X n)"
huffman@22608
   141
unfolding Zseq_def by simp
huffman@22608
   142
huffman@22608
   143
lemma Zseq_imp_Zseq:
huffman@22608
   144
  assumes X: "Zseq X"
huffman@22608
   145
  assumes Y: "\<And>n. norm (Y n) \<le> norm (X n) * K"
huffman@22608
   146
  shows "Zseq (\<lambda>n. Y n)"
huffman@31355
   147
using X Y Zfun_imp_Zfun [of X sequentially Y K]
huffman@31355
   148
unfolding Zseq_conv_Zfun by simp
huffman@22608
   149
huffman@22608
   150
lemma Zseq_le: "\<lbrakk>Zseq Y; \<forall>n. norm (X n) \<le> norm (Y n)\<rbrakk> \<Longrightarrow> Zseq X"
huffman@22608
   151
by (erule_tac K="1" in Zseq_imp_Zseq, simp)
huffman@22608
   152
huffman@22608
   153
lemma Zseq_add:
huffman@31349
   154
  "Zseq X \<Longrightarrow> Zseq Y \<Longrightarrow> Zseq (\<lambda>n. X n + Y n)"
huffman@31349
   155
unfolding Zseq_conv_Zfun by (rule Zfun_add)
huffman@22608
   156
huffman@22608
   157
lemma Zseq_minus: "Zseq X \<Longrightarrow> Zseq (\<lambda>n. - X n)"
huffman@22608
   158
unfolding Zseq_def by simp
huffman@22608
   159
huffman@22608
   160
lemma Zseq_diff: "\<lbrakk>Zseq X; Zseq Y\<rbrakk> \<Longrightarrow> Zseq (\<lambda>n. X n - Y n)"
huffman@22608
   161
by (simp only: diff_minus Zseq_add Zseq_minus)
huffman@22608
   162
huffman@22608
   163
lemma (in bounded_linear) Zseq:
huffman@31349
   164
  "Zseq X \<Longrightarrow> Zseq (\<lambda>n. f (X n))"
huffman@31349
   165
unfolding Zseq_conv_Zfun by (rule Zfun)
huffman@22608
   166
huffman@23127
   167
lemma (in bounded_bilinear) Zseq:
huffman@31349
   168
  "Zseq X \<Longrightarrow> Zseq Y \<Longrightarrow> Zseq (\<lambda>n. X n ** Y n)"
huffman@31349
   169
unfolding Zseq_conv_Zfun by (rule Zfun)
huffman@22608
   170
huffman@22608
   171
lemma (in bounded_bilinear) Zseq_prod_Bseq:
huffman@31355
   172
  "Zseq X \<Longrightarrow> Bseq Y \<Longrightarrow> Zseq (\<lambda>n. X n ** Y n)"
huffman@31355
   173
unfolding Zseq_conv_Zfun Bseq_conv_Bfun
huffman@31355
   174
by (rule Zfun_prod_Bfun)
huffman@22608
   175
huffman@22608
   176
lemma (in bounded_bilinear) Bseq_prod_Zseq:
huffman@31355
   177
  "Bseq X \<Longrightarrow> Zseq Y \<Longrightarrow> Zseq (\<lambda>n. X n ** Y n)"
huffman@31355
   178
unfolding Zseq_conv_Zfun Bseq_conv_Bfun
huffman@31355
   179
by (rule Bfun_prod_Zfun)
huffman@22608
   180
huffman@23127
   181
lemma (in bounded_bilinear) Zseq_left:
huffman@22608
   182
  "Zseq X \<Longrightarrow> Zseq (\<lambda>n. X n ** a)"
huffman@22608
   183
by (rule bounded_linear_left [THEN bounded_linear.Zseq])
huffman@22608
   184
huffman@23127
   185
lemma (in bounded_bilinear) Zseq_right:
huffman@22608
   186
  "Zseq X \<Longrightarrow> Zseq (\<lambda>n. a ** X n)"
huffman@22608
   187
by (rule bounded_linear_right [THEN bounded_linear.Zseq])
huffman@22608
   188
huffman@23127
   189
lemmas Zseq_mult = mult.Zseq
huffman@23127
   190
lemmas Zseq_mult_right = mult.Zseq_right
huffman@23127
   191
lemmas Zseq_mult_left = mult.Zseq_left
huffman@22608
   192
huffman@22608
   193
huffman@20696
   194
subsection {* Limits of Sequences *}
huffman@20696
   195
paulson@32877
   196
lemma [trans]: "X=Y ==> Y ----> z ==> X ----> z"
paulson@32877
   197
  by simp
paulson@32877
   198
huffman@31487
   199
lemma LIMSEQ_conv_tendsto: "(X ----> L) \<longleftrightarrow> (X ---> L) sequentially"
huffman@31488
   200
unfolding LIMSEQ_def tendsto_iff eventually_sequentially ..
huffman@31392
   201
paulson@15082
   202
lemma LIMSEQ_iff:
huffman@31336
   203
  fixes L :: "'a::real_normed_vector"
huffman@31336
   204
  shows "(X ----> L) = (\<forall>r>0. \<exists>no. \<forall>n \<ge> no. norm (X n - L) < r)"
huffman@31336
   205
unfolding LIMSEQ_def dist_norm ..
huffman@22608
   206
huffman@22608
   207
lemma LIMSEQ_Zseq_iff: "((\<lambda>n. X n) ----> L) = Zseq (\<lambda>n. X n - L)"
huffman@31336
   208
by (simp only: LIMSEQ_iff Zseq_def)
huffman@31336
   209
huffman@31336
   210
lemma metric_LIMSEQ_I:
huffman@31336
   211
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r) \<Longrightarrow> X ----> L"
huffman@31336
   212
by (simp add: LIMSEQ_def)
huffman@31336
   213
huffman@31336
   214
lemma metric_LIMSEQ_D:
huffman@31336
   215
  "\<lbrakk>X ----> L; 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r"
huffman@31336
   216
by (simp add: LIMSEQ_def)
paulson@15082
   217
huffman@20751
   218
lemma LIMSEQ_I:
huffman@31336
   219
  fixes L :: "'a::real_normed_vector"
huffman@31336
   220
  shows "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n - L) < r) \<Longrightarrow> X ----> L"
huffman@31336
   221
by (simp add: LIMSEQ_iff)
huffman@20751
   222
huffman@20751
   223
lemma LIMSEQ_D:
huffman@31336
   224
  fixes L :: "'a::real_normed_vector"
huffman@31336
   225
  shows "\<lbrakk>X ----> L; 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n - L) < r"
huffman@31336
   226
by (simp add: LIMSEQ_iff)
huffman@20751
   227
huffman@22608
   228
lemma LIMSEQ_const: "(\<lambda>n. k) ----> k"
huffman@20696
   229
by (simp add: LIMSEQ_def)
huffman@20696
   230
huffman@31336
   231
lemma LIMSEQ_const_iff: "(\<lambda>n. k) ----> l \<longleftrightarrow> k = l"
huffman@31336
   232
apply (safe intro!: LIMSEQ_const)
huffman@31336
   233
apply (rule ccontr)
huffman@31336
   234
apply (drule_tac r="dist k l" in metric_LIMSEQ_D)
huffman@31336
   235
apply (simp add: zero_less_dist_iff)
huffman@31336
   236
apply auto
huffman@31336
   237
done
huffman@22608
   238
huffman@31336
   239
lemma LIMSEQ_norm:
huffman@31336
   240
  fixes a :: "'a::real_normed_vector"
huffman@31336
   241
  shows "X ----> a \<Longrightarrow> (\<lambda>n. norm (X n)) ----> norm a"
huffman@31349
   242
unfolding LIMSEQ_conv_tendsto by (rule tendsto_norm)
huffman@20696
   243
huffman@22615
   244
lemma LIMSEQ_ignore_initial_segment:
huffman@22615
   245
  "f ----> a \<Longrightarrow> (\<lambda>n. f (n + k)) ----> a"
huffman@31336
   246
apply (rule metric_LIMSEQ_I)
huffman@31336
   247
apply (drule (1) metric_LIMSEQ_D)
huffman@22615
   248
apply (erule exE, rename_tac N)
huffman@22615
   249
apply (rule_tac x=N in exI)
huffman@22615
   250
apply simp
huffman@22615
   251
done
huffman@20696
   252
huffman@22615
   253
lemma LIMSEQ_offset:
huffman@22615
   254
  "(\<lambda>n. f (n + k)) ----> a \<Longrightarrow> f ----> a"
huffman@31336
   255
apply (rule metric_LIMSEQ_I)
huffman@31336
   256
apply (drule (1) metric_LIMSEQ_D)
huffman@22615
   257
apply (erule exE, rename_tac N)
huffman@22615
   258
apply (rule_tac x="N + k" in exI)
huffman@22615
   259
apply clarify
huffman@22615
   260
apply (drule_tac x="n - k" in spec)
huffman@22615
   261
apply (simp add: le_diff_conv2)
huffman@20696
   262
done
huffman@20696
   263
huffman@22615
   264
lemma LIMSEQ_Suc: "f ----> l \<Longrightarrow> (\<lambda>n. f (Suc n)) ----> l"
huffman@30082
   265
by (drule_tac k="Suc 0" in LIMSEQ_ignore_initial_segment, simp)
huffman@22615
   266
huffman@22615
   267
lemma LIMSEQ_imp_Suc: "(\<lambda>n. f (Suc n)) ----> l \<Longrightarrow> f ----> l"
huffman@30082
   268
by (rule_tac k="Suc 0" in LIMSEQ_offset, simp)
huffman@22615
   269
huffman@22615
   270
lemma LIMSEQ_Suc_iff: "(\<lambda>n. f (Suc n)) ----> l = f ----> l"
huffman@22615
   271
by (blast intro: LIMSEQ_imp_Suc LIMSEQ_Suc)
huffman@22615
   272
hoelzl@29803
   273
lemma LIMSEQ_linear: "\<lbrakk> X ----> x ; l > 0 \<rbrakk> \<Longrightarrow> (\<lambda> n. X (n * l)) ----> x"
hoelzl@29803
   274
  unfolding LIMSEQ_def
hoelzl@29803
   275
  by (metis div_le_dividend div_mult_self1_is_m le_trans nat_mult_commute)
hoelzl@29803
   276
huffman@31336
   277
lemma LIMSEQ_add:
huffman@31336
   278
  fixes a b :: "'a::real_normed_vector"
huffman@31336
   279
  shows "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) ----> a + b"
huffman@31349
   280
unfolding LIMSEQ_conv_tendsto by (rule tendsto_add)
huffman@22608
   281
huffman@31336
   282
lemma LIMSEQ_minus:
huffman@31336
   283
  fixes a :: "'a::real_normed_vector"
huffman@31336
   284
  shows "X ----> a \<Longrightarrow> (\<lambda>n. - X n) ----> - a"
huffman@31349
   285
unfolding LIMSEQ_conv_tendsto by (rule tendsto_minus)
huffman@22608
   286
huffman@31336
   287
lemma LIMSEQ_minus_cancel:
huffman@31336
   288
  fixes a :: "'a::real_normed_vector"
huffman@31336
   289
  shows "(\<lambda>n. - X n) ----> - a \<Longrightarrow> X ----> a"
huffman@22608
   290
by (drule LIMSEQ_minus, simp)
huffman@22608
   291
huffman@31336
   292
lemma LIMSEQ_diff:
huffman@31336
   293
  fixes a b :: "'a::real_normed_vector"
huffman@31336
   294
  shows "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) ----> a - b"
huffman@31349
   295
unfolding LIMSEQ_conv_tendsto by (rule tendsto_diff)
huffman@22608
   296
huffman@22608
   297
lemma LIMSEQ_unique: "\<lbrakk>X ----> a; X ----> b\<rbrakk> \<Longrightarrow> a = b"
huffman@31336
   298
apply (rule ccontr)
huffman@31336
   299
apply (drule_tac r="dist a b / 2" in metric_LIMSEQ_D, simp add: zero_less_dist_iff)
huffman@31336
   300
apply (drule_tac r="dist a b / 2" in metric_LIMSEQ_D, simp add: zero_less_dist_iff)
huffman@31336
   301
apply (clarify, rename_tac M N)
huffman@31336
   302
apply (subgoal_tac "dist a b < dist a b / 2 + dist a b / 2", simp)
huffman@31336
   303
apply (subgoal_tac "dist a b \<le> dist (X (max M N)) a + dist (X (max M N)) b")
huffman@31336
   304
apply (erule le_less_trans, rule add_strict_mono, simp, simp)
huffman@31336
   305
apply (subst dist_commute, rule dist_triangle)
huffman@31336
   306
done
huffman@22608
   307
huffman@22608
   308
lemma (in bounded_linear) LIMSEQ:
huffman@22608
   309
  "X ----> a \<Longrightarrow> (\<lambda>n. f (X n)) ----> f a"
huffman@31349
   310
unfolding LIMSEQ_conv_tendsto by (rule tendsto)
huffman@22608
   311
huffman@22608
   312
lemma (in bounded_bilinear) LIMSEQ:
huffman@22608
   313
  "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n ** Y n) ----> a ** b"
huffman@31349
   314
unfolding LIMSEQ_conv_tendsto by (rule tendsto)
huffman@22608
   315
huffman@22608
   316
lemma LIMSEQ_mult:
huffman@22608
   317
  fixes a b :: "'a::real_normed_algebra"
huffman@22608
   318
  shows "[| X ----> a; Y ----> b |] ==> (%n. X n * Y n) ----> a * b"
huffman@23127
   319
by (rule mult.LIMSEQ)
huffman@22608
   320
paulson@32877
   321
lemma increasing_LIMSEQ:
paulson@32877
   322
  fixes f :: "nat \<Rightarrow> real"
paulson@32877
   323
  assumes inc: "!!n. f n \<le> f (Suc n)"
paulson@32877
   324
      and bdd: "!!n. f n \<le> l"
paulson@32877
   325
      and en: "!!e. 0 < e \<Longrightarrow> \<exists>n. l \<le> f n + e"
paulson@32877
   326
  shows "f ----> l"
paulson@32877
   327
proof (auto simp add: LIMSEQ_def)
paulson@32877
   328
  fix e :: real
paulson@32877
   329
  assume e: "0 < e"
paulson@32877
   330
  then obtain N where "l \<le> f N + e/2"
paulson@32877
   331
    by (metis half_gt_zero e en that)
paulson@32877
   332
  hence N: "l < f N + e" using e
paulson@32877
   333
    by simp
paulson@32877
   334
  { fix k
paulson@32877
   335
    have [simp]: "!!n. \<bar>f n - l\<bar> = l - f n"
paulson@32877
   336
      by (simp add: bdd) 
paulson@32877
   337
    have "\<bar>f (N+k) - l\<bar> < e"
paulson@32877
   338
    proof (induct k)
paulson@32877
   339
      case 0 show ?case using N
paulson@32877
   340
	by simp   
paulson@32877
   341
    next
paulson@32877
   342
      case (Suc k) thus ?case using N inc [of "N+k"]
paulson@32877
   343
	by simp
paulson@32877
   344
    qed 
paulson@32877
   345
  } note 1 = this
paulson@32877
   346
  { fix n
paulson@32877
   347
    have "N \<le> n \<Longrightarrow> \<bar>f n - l\<bar> < e" using 1 [of "n-N"]
paulson@32877
   348
      by simp 
paulson@32877
   349
  } note [intro] = this
paulson@32877
   350
  show " \<exists>no. \<forall>n\<ge>no. dist (f n) l < e"
paulson@32877
   351
    by (auto simp add: dist_real_def) 
paulson@32877
   352
  qed
paulson@32877
   353
huffman@22608
   354
lemma Bseq_inverse_lemma:
huffman@22608
   355
  fixes x :: "'a::real_normed_div_algebra"
huffman@22608
   356
  shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
huffman@22608
   357
apply (subst nonzero_norm_inverse, clarsimp)
huffman@22608
   358
apply (erule (1) le_imp_inverse_le)
huffman@22608
   359
done
huffman@22608
   360
huffman@22608
   361
lemma Bseq_inverse:
huffman@22608
   362
  fixes a :: "'a::real_normed_div_algebra"
huffman@31355
   363
  shows "\<lbrakk>X ----> a; a \<noteq> 0\<rbrakk> \<Longrightarrow> Bseq (\<lambda>n. inverse (X n))"
huffman@31355
   364
unfolding LIMSEQ_conv_tendsto Bseq_conv_Bfun
huffman@31355
   365
by (rule Bfun_inverse)
huffman@22608
   366
huffman@22608
   367
lemma LIMSEQ_inverse:
huffman@22608
   368
  fixes a :: "'a::real_normed_div_algebra"
huffman@31355
   369
  shows "\<lbrakk>X ----> a; a \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>n. inverse (X n)) ----> inverse a"
huffman@31355
   370
unfolding LIMSEQ_conv_tendsto
huffman@31355
   371
by (rule tendsto_inverse)
huffman@22608
   372
huffman@22608
   373
lemma LIMSEQ_divide:
huffman@22608
   374
  fixes a b :: "'a::real_normed_field"
huffman@22608
   375
  shows "\<lbrakk>X ----> a; Y ----> b; b \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>n. X n / Y n) ----> a / b"
huffman@22608
   376
by (simp add: LIMSEQ_mult LIMSEQ_inverse divide_inverse)
huffman@22608
   377
huffman@22608
   378
lemma LIMSEQ_pow:
haftmann@31017
   379
  fixes a :: "'a::{power, real_normed_algebra}"
huffman@22608
   380
  shows "X ----> a \<Longrightarrow> (\<lambda>n. (X n) ^ m) ----> a ^ m"
huffman@30273
   381
by (induct m) (simp_all add: LIMSEQ_const LIMSEQ_mult)
huffman@22608
   382
huffman@22608
   383
lemma LIMSEQ_setsum:
huffman@31336
   384
  fixes L :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@22608
   385
  assumes n: "\<And>n. n \<in> S \<Longrightarrow> X n ----> L n"
huffman@22608
   386
  shows "(\<lambda>m. \<Sum>n\<in>S. X n m) ----> (\<Sum>n\<in>S. L n)"
huffman@31588
   387
using n unfolding LIMSEQ_conv_tendsto by (rule tendsto_setsum)
huffman@22608
   388
huffman@22608
   389
lemma LIMSEQ_setprod:
huffman@22608
   390
  fixes L :: "'a \<Rightarrow> 'b::{real_normed_algebra,comm_ring_1}"
huffman@22608
   391
  assumes n: "\<And>n. n \<in> S \<Longrightarrow> X n ----> L n"
huffman@22608
   392
  shows "(\<lambda>m. \<Prod>n\<in>S. X n m) ----> (\<Prod>n\<in>S. L n)"
huffman@22608
   393
proof (cases "finite S")
huffman@22608
   394
  case True
huffman@22608
   395
  thus ?thesis using n
huffman@22608
   396
  proof (induct)
huffman@22608
   397
    case empty
huffman@22608
   398
    show ?case
huffman@22608
   399
      by (simp add: LIMSEQ_const)
huffman@22608
   400
  next
huffman@22608
   401
    case insert
huffman@22608
   402
    thus ?case
huffman@22608
   403
      by (simp add: LIMSEQ_mult)
huffman@22608
   404
  qed
huffman@22608
   405
next
huffman@22608
   406
  case False
huffman@22608
   407
  thus ?thesis
huffman@22608
   408
    by (simp add: setprod_def LIMSEQ_const)
huffman@22608
   409
qed
huffman@22608
   410
huffman@31336
   411
lemma LIMSEQ_add_const:
huffman@31336
   412
  fixes a :: "'a::real_normed_vector"
huffman@31336
   413
  shows "f ----> a ==> (%n.(f n + b)) ----> a + b"
huffman@22614
   414
by (simp add: LIMSEQ_add LIMSEQ_const)
huffman@22614
   415
huffman@22614
   416
(* FIXME: delete *)
huffman@22614
   417
lemma LIMSEQ_add_minus:
huffman@31336
   418
  fixes a b :: "'a::real_normed_vector"
huffman@31336
   419
  shows "[| X ----> a; Y ----> b |] ==> (%n. X n + -Y n) ----> a + -b"
huffman@22614
   420
by (simp only: LIMSEQ_add LIMSEQ_minus)
huffman@22614
   421
huffman@31336
   422
lemma LIMSEQ_diff_const:
huffman@31336
   423
  fixes a b :: "'a::real_normed_vector"
huffman@31336
   424
  shows "f ----> a ==> (%n.(f n  - b)) ----> a - b"
huffman@22614
   425
by (simp add: LIMSEQ_diff LIMSEQ_const)
huffman@22614
   426
huffman@31336
   427
lemma LIMSEQ_diff_approach_zero:
huffman@31336
   428
  fixes L :: "'a::real_normed_vector"
huffman@31336
   429
  shows "g ----> L ==> (%x. f x - g x) ----> 0 ==> f ----> L"
huffman@31336
   430
by (drule (1) LIMSEQ_add, simp)
huffman@22614
   431
huffman@31336
   432
lemma LIMSEQ_diff_approach_zero2:
huffman@31336
   433
  fixes L :: "'a::real_normed_vector"
huffman@31336
   434
  shows "f ----> L ==> (%x. f x - g x) ----> 0 ==> g ----> L";
huffman@31336
   435
by (drule (1) LIMSEQ_diff, simp)
huffman@22614
   436
huffman@22614
   437
text{*A sequence tends to zero iff its abs does*}
huffman@31336
   438
lemma LIMSEQ_norm_zero:
huffman@31336
   439
  fixes X :: "nat \<Rightarrow> 'a::real_normed_vector"
huffman@31336
   440
  shows "((\<lambda>n. norm (X n)) ----> 0) \<longleftrightarrow> (X ----> 0)"
huffman@31336
   441
by (simp add: LIMSEQ_iff)
huffman@22614
   442
huffman@22614
   443
lemma LIMSEQ_rabs_zero: "((%n. \<bar>f n\<bar>) ----> 0) = (f ----> (0::real))"
huffman@31336
   444
by (simp add: LIMSEQ_iff)
huffman@22614
   445
huffman@22614
   446
lemma LIMSEQ_imp_rabs: "f ----> (l::real) ==> (%n. \<bar>f n\<bar>) ----> \<bar>l\<bar>"
huffman@22614
   447
by (drule LIMSEQ_norm, simp)
huffman@22614
   448
huffman@22614
   449
text{*An unbounded sequence's inverse tends to 0*}
huffman@22614
   450
huffman@22614
   451
lemma LIMSEQ_inverse_zero:
huffman@22974
   452
  "\<forall>r::real. \<exists>N. \<forall>n\<ge>N. r < X n \<Longrightarrow> (\<lambda>n. inverse (X n)) ----> 0"
huffman@22974
   453
apply (rule LIMSEQ_I)
huffman@22974
   454
apply (drule_tac x="inverse r" in spec, safe)
huffman@22974
   455
apply (rule_tac x="N" in exI, safe)
huffman@22974
   456
apply (drule_tac x="n" in spec, safe)
huffman@22614
   457
apply (frule positive_imp_inverse_positive)
huffman@22974
   458
apply (frule (1) less_imp_inverse_less)
huffman@22974
   459
apply (subgoal_tac "0 < X n", simp)
huffman@22974
   460
apply (erule (1) order_less_trans)
huffman@22614
   461
done
huffman@22614
   462
huffman@22614
   463
text{*The sequence @{term "1/n"} tends to 0 as @{term n} tends to infinity*}
huffman@22614
   464
huffman@22614
   465
lemma LIMSEQ_inverse_real_of_nat: "(%n. inverse(real(Suc n))) ----> 0"
huffman@22614
   466
apply (rule LIMSEQ_inverse_zero, safe)
huffman@22974
   467
apply (cut_tac x = r in reals_Archimedean2)
huffman@22614
   468
apply (safe, rule_tac x = n in exI)
huffman@22614
   469
apply (auto simp add: real_of_nat_Suc)
huffman@22614
   470
done
huffman@22614
   471
huffman@22614
   472
text{*The sequence @{term "r + 1/n"} tends to @{term r} as @{term n} tends to
huffman@22614
   473
infinity is now easily proved*}
huffman@22614
   474
huffman@22614
   475
lemma LIMSEQ_inverse_real_of_nat_add:
huffman@22614
   476
     "(%n. r + inverse(real(Suc n))) ----> r"
huffman@22614
   477
by (cut_tac LIMSEQ_add [OF LIMSEQ_const LIMSEQ_inverse_real_of_nat], auto)
huffman@22614
   478
huffman@22614
   479
lemma LIMSEQ_inverse_real_of_nat_add_minus:
huffman@22614
   480
     "(%n. r + -inverse(real(Suc n))) ----> r"
huffman@22614
   481
by (cut_tac LIMSEQ_add_minus [OF LIMSEQ_const LIMSEQ_inverse_real_of_nat], auto)
huffman@22614
   482
huffman@22614
   483
lemma LIMSEQ_inverse_real_of_nat_add_minus_mult:
huffman@22614
   484
     "(%n. r*( 1 + -inverse(real(Suc n)))) ----> r"
huffman@22614
   485
by (cut_tac b=1 in
huffman@22614
   486
        LIMSEQ_mult [OF LIMSEQ_const LIMSEQ_inverse_real_of_nat_add_minus], auto)
huffman@22614
   487
huffman@22615
   488
lemma LIMSEQ_le_const:
huffman@22615
   489
  "\<lbrakk>X ----> (x::real); \<exists>N. \<forall>n\<ge>N. a \<le> X n\<rbrakk> \<Longrightarrow> a \<le> x"
huffman@22615
   490
apply (rule ccontr, simp only: linorder_not_le)
huffman@22615
   491
apply (drule_tac r="a - x" in LIMSEQ_D, simp)
huffman@22615
   492
apply clarsimp
huffman@22615
   493
apply (drule_tac x="max N no" in spec, drule mp, rule le_maxI1)
huffman@22615
   494
apply (drule_tac x="max N no" in spec, drule mp, rule le_maxI2)
huffman@22615
   495
apply simp
huffman@22615
   496
done
huffman@22615
   497
huffman@22615
   498
lemma LIMSEQ_le_const2:
huffman@22615
   499
  "\<lbrakk>X ----> (x::real); \<exists>N. \<forall>n\<ge>N. X n \<le> a\<rbrakk> \<Longrightarrow> x \<le> a"
huffman@22615
   500
apply (subgoal_tac "- a \<le> - x", simp)
huffman@22615
   501
apply (rule LIMSEQ_le_const)
huffman@22615
   502
apply (erule LIMSEQ_minus)
huffman@22615
   503
apply simp
huffman@22615
   504
done
huffman@22615
   505
huffman@22615
   506
lemma LIMSEQ_le:
huffman@22615
   507
  "\<lbrakk>X ----> x; Y ----> y; \<exists>N. \<forall>n\<ge>N. X n \<le> Y n\<rbrakk> \<Longrightarrow> x \<le> (y::real)"
huffman@22615
   508
apply (subgoal_tac "0 \<le> y - x", simp)
huffman@22615
   509
apply (rule LIMSEQ_le_const)
huffman@22615
   510
apply (erule (1) LIMSEQ_diff)
huffman@22615
   511
apply (simp add: le_diff_eq)
huffman@22615
   512
done
huffman@22615
   513
paulson@15082
   514
huffman@20696
   515
subsection {* Convergence *}
paulson@15082
   516
paulson@15082
   517
lemma limI: "X ----> L ==> lim X = L"
paulson@15082
   518
apply (simp add: lim_def)
paulson@15082
   519
apply (blast intro: LIMSEQ_unique)
paulson@15082
   520
done
paulson@15082
   521
paulson@15082
   522
lemma convergentD: "convergent X ==> \<exists>L. (X ----> L)"
paulson@15082
   523
by (simp add: convergent_def)
paulson@15082
   524
paulson@15082
   525
lemma convergentI: "(X ----> L) ==> convergent X"
paulson@15082
   526
by (auto simp add: convergent_def)
paulson@15082
   527
paulson@15082
   528
lemma convergent_LIMSEQ_iff: "convergent X = (X ----> lim X)"
huffman@20682
   529
by (auto intro: theI LIMSEQ_unique simp add: convergent_def lim_def)
paulson@15082
   530
huffman@31336
   531
lemma convergent_minus_iff:
huffman@31336
   532
  fixes X :: "nat \<Rightarrow> 'a::real_normed_vector"
huffman@31336
   533
  shows "convergent X \<longleftrightarrow> convergent (\<lambda>n. - X n)"
huffman@20696
   534
apply (simp add: convergent_def)
huffman@20696
   535
apply (auto dest: LIMSEQ_minus)
huffman@20696
   536
apply (drule LIMSEQ_minus, auto)
huffman@20696
   537
done
huffman@20696
   538
paulson@32707
   539
lemma lim_le:
paulson@32707
   540
  fixes x :: real
paulson@32707
   541
  assumes f: "convergent f" and fn_le: "!!n. f n \<le> x"
paulson@32707
   542
  shows "lim f \<le> x"
paulson@32707
   543
proof (rule classical)
paulson@32707
   544
  assume "\<not> lim f \<le> x"
paulson@32707
   545
  hence 0: "0 < lim f - x" by arith
paulson@32707
   546
  have 1: "f----> lim f"
paulson@32707
   547
    by (metis convergent_LIMSEQ_iff f) 
paulson@32707
   548
  thus ?thesis
paulson@32707
   549
    proof (simp add: LIMSEQ_iff)
paulson@32707
   550
      assume "\<forall>r>0. \<exists>no. \<forall>n\<ge>no. \<bar>f n - lim f\<bar> < r"
paulson@32707
   551
      hence "\<exists>no. \<forall>n\<ge>no. \<bar>f n - lim f\<bar> < lim f - x"
paulson@32707
   552
	by (metis 0)
paulson@32707
   553
      from this obtain no where "\<forall>n\<ge>no. \<bar>f n - lim f\<bar> < lim f - x"
paulson@32707
   554
	by blast
paulson@32707
   555
      thus "lim f \<le> x"
paulson@32707
   556
	by (metis add_cancel_end add_minus_cancel diff_def linorder_linear 
paulson@32707
   557
                  linorder_not_le minus_diff_eq abs_diff_less_iff fn_le) 
paulson@32707
   558
    qed
paulson@32707
   559
qed
paulson@32707
   560
chaieb@30196
   561
text{* Given a binary function @{text "f:: nat \<Rightarrow> 'a \<Rightarrow> 'a"}, its values are uniquely determined by a function g *}
huffman@20696
   562
chaieb@30196
   563
lemma nat_function_unique: "EX! g. g 0 = e \<and> (\<forall>n. g (Suc n) = f n (g n))"
chaieb@30196
   564
  unfolding Ex1_def
chaieb@30196
   565
  apply (rule_tac x="nat_rec e f" in exI)
chaieb@30196
   566
  apply (rule conjI)+
chaieb@30196
   567
apply (rule def_nat_rec_0, simp)
chaieb@30196
   568
apply (rule allI, rule def_nat_rec_Suc, simp)
chaieb@30196
   569
apply (rule allI, rule impI, rule ext)
chaieb@30196
   570
apply (erule conjE)
chaieb@30196
   571
apply (induct_tac x)
chaieb@30196
   572
apply (simp add: nat_rec_0)
chaieb@30196
   573
apply (erule_tac x="n" in allE)
chaieb@30196
   574
apply (simp)
chaieb@30196
   575
done
huffman@20696
   576
paulson@15082
   577
text{*Subsequence (alternative definition, (e.g. Hoskins)*}
paulson@15082
   578
paulson@15082
   579
lemma subseq_Suc_iff: "subseq f = (\<forall>n. (f n) < (f (Suc n)))"
paulson@15082
   580
apply (simp add: subseq_def)
paulson@15082
   581
apply (auto dest!: less_imp_Suc_add)
paulson@15082
   582
apply (induct_tac k)
paulson@15082
   583
apply (auto intro: less_trans)
paulson@15082
   584
done
paulson@15082
   585
paulson@15082
   586
lemma monoseq_Suc:
paulson@15082
   587
   "monoseq X = ((\<forall>n. X n \<le> X (Suc n))
paulson@15082
   588
                 | (\<forall>n. X (Suc n) \<le> X n))"
paulson@15082
   589
apply (simp add: monoseq_def)
paulson@15082
   590
apply (auto dest!: le_imp_less_or_eq)
paulson@15082
   591
apply (auto intro!: lessI [THEN less_imp_le] dest!: less_imp_Suc_add)
paulson@15082
   592
apply (induct_tac "ka")
paulson@15082
   593
apply (auto intro: order_trans)
wenzelm@18585
   594
apply (erule contrapos_np)
paulson@15082
   595
apply (induct_tac "k")
paulson@15082
   596
apply (auto intro: order_trans)
paulson@15082
   597
done
paulson@15082
   598
nipkow@15360
   599
lemma monoI1: "\<forall>m. \<forall> n \<ge> m. X m \<le> X n ==> monoseq X"
paulson@15082
   600
by (simp add: monoseq_def)
paulson@15082
   601
nipkow@15360
   602
lemma monoI2: "\<forall>m. \<forall> n \<ge> m. X n \<le> X m ==> monoseq X"
paulson@15082
   603
by (simp add: monoseq_def)
paulson@15082
   604
paulson@15082
   605
lemma mono_SucI1: "\<forall>n. X n \<le> X (Suc n) ==> monoseq X"
paulson@15082
   606
by (simp add: monoseq_Suc)
paulson@15082
   607
paulson@15082
   608
lemma mono_SucI2: "\<forall>n. X (Suc n) \<le> X n ==> monoseq X"
paulson@15082
   609
by (simp add: monoseq_Suc)
paulson@15082
   610
hoelzl@29803
   611
lemma monoseq_minus: assumes "monoseq a"
hoelzl@29803
   612
  shows "monoseq (\<lambda> n. - a n)"
hoelzl@29803
   613
proof (cases "\<forall> m. \<forall> n \<ge> m. a m \<le> a n")
hoelzl@29803
   614
  case True
hoelzl@29803
   615
  hence "\<forall> m. \<forall> n \<ge> m. - a n \<le> - a m" by auto
hoelzl@29803
   616
  thus ?thesis by (rule monoI2)
hoelzl@29803
   617
next
hoelzl@29803
   618
  case False
hoelzl@29803
   619
  hence "\<forall> m. \<forall> n \<ge> m. - a m \<le> - a n" using `monoseq a`[unfolded monoseq_def] by auto
hoelzl@29803
   620
  thus ?thesis by (rule monoI1)
hoelzl@29803
   621
qed
hoelzl@29803
   622
hoelzl@29803
   623
lemma monoseq_le: assumes "monoseq a" and "a ----> x"
hoelzl@29803
   624
  shows "((\<forall> n. a n \<le> x) \<and> (\<forall>m. \<forall>n\<ge>m. a m \<le> a n)) \<or> 
hoelzl@29803
   625
         ((\<forall> n. x \<le> a n) \<and> (\<forall>m. \<forall>n\<ge>m. a n \<le> a m))"
hoelzl@29803
   626
proof -
hoelzl@29803
   627
  { fix x n fix a :: "nat \<Rightarrow> real"
hoelzl@29803
   628
    assume "a ----> x" and "\<forall> m. \<forall> n \<ge> m. a m \<le> a n"
hoelzl@29803
   629
    hence monotone: "\<And> m n. m \<le> n \<Longrightarrow> a m \<le> a n" by auto
hoelzl@29803
   630
    have "a n \<le> x"
hoelzl@29803
   631
    proof (rule ccontr)
hoelzl@29803
   632
      assume "\<not> a n \<le> x" hence "x < a n" by auto
hoelzl@29803
   633
      hence "0 < a n - x" by auto
hoelzl@29803
   634
      from `a ----> x`[THEN LIMSEQ_D, OF this]
hoelzl@29803
   635
      obtain no where "\<And>n'. no \<le> n' \<Longrightarrow> norm (a n' - x) < a n - x" by blast
hoelzl@29803
   636
      hence "norm (a (max no n) - x) < a n - x" by auto
hoelzl@29803
   637
      moreover
hoelzl@29803
   638
      { fix n' have "n \<le> n' \<Longrightarrow> x < a n'" using monotone[where m=n and n=n'] and `x < a n` by auto }
hoelzl@29803
   639
      hence "x < a (max no n)" by auto
hoelzl@29803
   640
      ultimately
hoelzl@29803
   641
      have "a (max no n) < a n" by auto
hoelzl@29803
   642
      with monotone[where m=n and n="max no n"]
nipkow@32436
   643
      show False by (auto simp:max_def split:split_if_asm)
hoelzl@29803
   644
    qed
hoelzl@29803
   645
  } note top_down = this
hoelzl@29803
   646
  { fix x n m fix a :: "nat \<Rightarrow> real"
hoelzl@29803
   647
    assume "a ----> x" and "monoseq a" and "a m < x"
hoelzl@29803
   648
    have "a n \<le> x \<and> (\<forall> m. \<forall> n \<ge> m. a m \<le> a n)"
hoelzl@29803
   649
    proof (cases "\<forall> m. \<forall> n \<ge> m. a m \<le> a n")
hoelzl@29803
   650
      case True with top_down and `a ----> x` show ?thesis by auto
hoelzl@29803
   651
    next
hoelzl@29803
   652
      case False with `monoseq a`[unfolded monoseq_def] have "\<forall> m. \<forall> n \<ge> m. - a m \<le> - a n" by auto
hoelzl@29803
   653
      hence "- a m \<le> - x" using top_down[OF LIMSEQ_minus[OF `a ----> x`]] by blast
hoelzl@29803
   654
      hence False using `a m < x` by auto
hoelzl@29803
   655
      thus ?thesis ..
hoelzl@29803
   656
    qed
hoelzl@29803
   657
  } note when_decided = this
hoelzl@29803
   658
hoelzl@29803
   659
  show ?thesis
hoelzl@29803
   660
  proof (cases "\<exists> m. a m \<noteq> x")
hoelzl@29803
   661
    case True then obtain m where "a m \<noteq> x" by auto
hoelzl@29803
   662
    show ?thesis
hoelzl@29803
   663
    proof (cases "a m < x")
hoelzl@29803
   664
      case True with when_decided[OF `a ----> x` `monoseq a`, where m2=m]
hoelzl@29803
   665
      show ?thesis by blast
hoelzl@29803
   666
    next
hoelzl@29803
   667
      case False hence "- a m < - x" using `a m \<noteq> x` by auto
hoelzl@29803
   668
      with when_decided[OF LIMSEQ_minus[OF `a ----> x`] monoseq_minus[OF `monoseq a`], where m2=m]
hoelzl@29803
   669
      show ?thesis by auto
hoelzl@29803
   670
    qed
hoelzl@29803
   671
  qed auto
hoelzl@29803
   672
qed
hoelzl@29803
   673
chaieb@30196
   674
text{* for any sequence, there is a mootonic subsequence *}
chaieb@30196
   675
lemma seq_monosub: "\<exists>f. subseq f \<and> monoseq (\<lambda> n. (s (f n)))"
chaieb@30196
   676
proof-
chaieb@30196
   677
  {assume H: "\<forall>n. \<exists>p >n. \<forall> m\<ge>p. s m \<le> s p"
chaieb@30196
   678
    let ?P = "\<lambda> p n. p > n \<and> (\<forall>m \<ge> p. s m \<le> s p)"
chaieb@30196
   679
    from nat_function_unique[of "SOME p. ?P p 0" "\<lambda>p n. SOME p. ?P p n"]
chaieb@30196
   680
    obtain f where f: "f 0 = (SOME p. ?P p 0)" "\<forall>n. f (Suc n) = (SOME p. ?P p (f n))" by blast
chaieb@30196
   681
    have "?P (f 0) 0"  unfolding f(1) some_eq_ex[of "\<lambda>p. ?P p 0"]
chaieb@30196
   682
      using H apply - 
chaieb@30196
   683
      apply (erule allE[where x=0], erule exE, rule_tac x="p" in exI) 
chaieb@30196
   684
      unfolding order_le_less by blast 
chaieb@30196
   685
    hence f0: "f 0 > 0" "\<forall>m \<ge> f 0. s m \<le> s (f 0)" by blast+
chaieb@30196
   686
    {fix n
chaieb@30196
   687
      have "?P (f (Suc n)) (f n)" 
chaieb@30196
   688
	unfolding f(2)[rule_format, of n] some_eq_ex[of "\<lambda>p. ?P p (f n)"]
chaieb@30196
   689
	using H apply - 
chaieb@30196
   690
      apply (erule allE[where x="f n"], erule exE, rule_tac x="p" in exI) 
chaieb@30196
   691
      unfolding order_le_less by blast 
chaieb@30196
   692
    hence "f (Suc n) > f n" "\<forall>m \<ge> f (Suc n). s m \<le> s (f (Suc n))" by blast+}
chaieb@30196
   693
  note fSuc = this
chaieb@30196
   694
    {fix p q assume pq: "p \<ge> f q"
chaieb@30196
   695
      have "s p \<le> s(f(q))"  using f0(2)[rule_format, of p] pq fSuc
chaieb@30196
   696
	by (cases q, simp_all) }
chaieb@30196
   697
    note pqth = this
chaieb@30196
   698
    {fix q
chaieb@30196
   699
      have "f (Suc q) > f q" apply (induct q) 
chaieb@30196
   700
	using f0(1) fSuc(1)[of 0] apply simp by (rule fSuc(1))}
chaieb@30196
   701
    note fss = this
chaieb@30196
   702
    from fss have th1: "subseq f" unfolding subseq_Suc_iff ..
chaieb@30196
   703
    {fix a b 
chaieb@30196
   704
      have "f a \<le> f (a + b)"
chaieb@30196
   705
      proof(induct b)
chaieb@30196
   706
	case 0 thus ?case by simp
chaieb@30196
   707
      next
chaieb@30196
   708
	case (Suc b)
chaieb@30196
   709
	from fSuc(1)[of "a + b"] Suc.hyps show ?case by simp
chaieb@30196
   710
      qed}
chaieb@30196
   711
    note fmon0 = this
chaieb@30196
   712
    have "monoseq (\<lambda>n. s (f n))" 
chaieb@30196
   713
    proof-
chaieb@30196
   714
      {fix n
chaieb@30196
   715
	have "s (f n) \<ge> s (f (Suc n))" 
chaieb@30196
   716
	proof(cases n)
chaieb@30196
   717
	  case 0
chaieb@30196
   718
	  assume n0: "n = 0"
chaieb@30196
   719
	  from fSuc(1)[of 0] have th0: "f 0 \<le> f (Suc 0)" by simp
chaieb@30196
   720
	  from f0(2)[rule_format, OF th0] show ?thesis  using n0 by simp
chaieb@30196
   721
	next
chaieb@30196
   722
	  case (Suc m)
chaieb@30196
   723
	  assume m: "n = Suc m"
chaieb@30196
   724
	  from fSuc(1)[of n] m have th0: "f (Suc m) \<le> f (Suc (Suc m))" by simp
chaieb@30196
   725
	  from m fSuc(2)[rule_format, OF th0] show ?thesis by simp 
chaieb@30196
   726
	qed}
chaieb@30196
   727
      thus "monoseq (\<lambda>n. s (f n))" unfolding monoseq_Suc by blast 
chaieb@30196
   728
    qed
chaieb@30196
   729
    with th1 have ?thesis by blast}
chaieb@30196
   730
  moreover
chaieb@30196
   731
  {fix N assume N: "\<forall>p >N. \<exists> m\<ge>p. s m > s p"
chaieb@30196
   732
    {fix p assume p: "p \<ge> Suc N" 
chaieb@30196
   733
      hence pN: "p > N" by arith with N obtain m where m: "m \<ge> p" "s m > s p" by blast
chaieb@30196
   734
      have "m \<noteq> p" using m(2) by auto 
chaieb@30196
   735
      with m have "\<exists>m>p. s p < s m" by - (rule exI[where x=m], auto)}
chaieb@30196
   736
    note th0 = this
chaieb@30196
   737
    let ?P = "\<lambda>m x. m > x \<and> s x < s m"
chaieb@30196
   738
    from nat_function_unique[of "SOME x. ?P x (Suc N)" "\<lambda>m x. SOME y. ?P y x"]
chaieb@30196
   739
    obtain f where f: "f 0 = (SOME x. ?P x (Suc N))" 
chaieb@30196
   740
      "\<forall>n. f (Suc n) = (SOME m. ?P m (f n))" by blast
chaieb@30196
   741
    have "?P (f 0) (Suc N)"  unfolding f(1) some_eq_ex[of "\<lambda>p. ?P p (Suc N)"]
chaieb@30196
   742
      using N apply - 
chaieb@30196
   743
      apply (erule allE[where x="Suc N"], clarsimp)
chaieb@30196
   744
      apply (rule_tac x="m" in exI)
chaieb@30196
   745
      apply auto
chaieb@30196
   746
      apply (subgoal_tac "Suc N \<noteq> m")
chaieb@30196
   747
      apply simp
chaieb@30196
   748
      apply (rule ccontr, simp)
chaieb@30196
   749
      done
chaieb@30196
   750
    hence f0: "f 0 > Suc N" "s (Suc N) < s (f 0)" by blast+
chaieb@30196
   751
    {fix n
chaieb@30196
   752
      have "f n > N \<and> ?P (f (Suc n)) (f n)"
chaieb@30196
   753
	unfolding f(2)[rule_format, of n] some_eq_ex[of "\<lambda>p. ?P p (f n)"]
chaieb@30196
   754
      proof (induct n)
chaieb@30196
   755
	case 0 thus ?case
chaieb@30196
   756
	  using f0 N apply auto 
chaieb@30196
   757
	  apply (erule allE[where x="f 0"], clarsimp) 
chaieb@30196
   758
	  apply (rule_tac x="m" in exI, simp)
chaieb@30196
   759
	  by (subgoal_tac "f 0 \<noteq> m", auto)
chaieb@30196
   760
      next
chaieb@30196
   761
	case (Suc n)
chaieb@30196
   762
	from Suc.hyps have Nfn: "N < f n" by blast
chaieb@30196
   763
	from Suc.hyps obtain m where m: "m > f n" "s (f n) < s m" by blast
chaieb@30196
   764
	with Nfn have mN: "m > N" by arith
chaieb@30196
   765
	note key = Suc.hyps[unfolded some_eq_ex[of "\<lambda>p. ?P p (f n)", symmetric] f(2)[rule_format, of n, symmetric]]
chaieb@30196
   766
	
chaieb@30196
   767
	from key have th0: "f (Suc n) > N" by simp
chaieb@30196
   768
	from N[rule_format, OF th0]
chaieb@30196
   769
	obtain m' where m': "m' \<ge> f (Suc n)" "s (f (Suc n)) < s m'" by blast
chaieb@30196
   770
	have "m' \<noteq> f (Suc (n))" apply (rule ccontr) using m'(2) by auto
chaieb@30196
   771
	hence "m' > f (Suc n)" using m'(1) by simp
chaieb@30196
   772
	with key m'(2) show ?case by auto
chaieb@30196
   773
      qed}
chaieb@30196
   774
    note fSuc = this
chaieb@30196
   775
    {fix n
chaieb@30196
   776
      have "f n \<ge> Suc N \<and> f(Suc n) > f n \<and> s(f n) < s(f(Suc n))" using fSuc[of n] by auto 
chaieb@30196
   777
      hence "f n \<ge> Suc N" "f(Suc n) > f n" "s(f n) < s(f(Suc n))" by blast+}
chaieb@30196
   778
    note thf = this
chaieb@30196
   779
    have sqf: "subseq f" unfolding subseq_Suc_iff using thf by simp
chaieb@30196
   780
    have "monoseq (\<lambda>n. s (f n))"  unfolding monoseq_Suc using thf
chaieb@30196
   781
      apply -
chaieb@30196
   782
      apply (rule disjI1)
chaieb@30196
   783
      apply auto
chaieb@30196
   784
      apply (rule order_less_imp_le)
chaieb@30196
   785
      apply blast
chaieb@30196
   786
      done
chaieb@30196
   787
    then have ?thesis  using sqf by blast}
chaieb@30196
   788
  ultimately show ?thesis unfolding linorder_not_less[symmetric] by blast
chaieb@30196
   789
qed
chaieb@30196
   790
chaieb@30196
   791
lemma seq_suble: assumes sf: "subseq f" shows "n \<le> f n"
chaieb@30196
   792
proof(induct n)
chaieb@30196
   793
  case 0 thus ?case by simp
chaieb@30196
   794
next
chaieb@30196
   795
  case (Suc n)
chaieb@30196
   796
  from sf[unfolded subseq_Suc_iff, rule_format, of n] Suc.hyps
chaieb@30196
   797
  have "n < f (Suc n)" by arith 
chaieb@30196
   798
  thus ?case by arith
chaieb@30196
   799
qed
chaieb@30196
   800
paulson@30730
   801
lemma LIMSEQ_subseq_LIMSEQ:
paulson@30730
   802
  "\<lbrakk> X ----> L; subseq f \<rbrakk> \<Longrightarrow> (X o f) ----> L"
paulson@30730
   803
apply (auto simp add: LIMSEQ_def) 
paulson@30730
   804
apply (drule_tac x=r in spec, clarify)  
paulson@30730
   805
apply (rule_tac x=no in exI, clarify) 
paulson@30730
   806
apply (blast intro: seq_suble le_trans dest!: spec) 
paulson@30730
   807
done
paulson@30730
   808
chaieb@30196
   809
subsection {* Bounded Monotonic Sequences *}
chaieb@30196
   810
chaieb@30196
   811
huffman@20696
   812
text{*Bounded Sequence*}
paulson@15082
   813
huffman@20552
   814
lemma BseqD: "Bseq X ==> \<exists>K. 0 < K & (\<forall>n. norm (X n) \<le> K)"
paulson@15082
   815
by (simp add: Bseq_def)
paulson@15082
   816
huffman@20552
   817
lemma BseqI: "[| 0 < K; \<forall>n. norm (X n) \<le> K |] ==> Bseq X"
paulson@15082
   818
by (auto simp add: Bseq_def)
paulson@15082
   819
paulson@15082
   820
lemma lemma_NBseq_def:
huffman@20552
   821
     "(\<exists>K > 0. \<forall>n. norm (X n) \<le> K) =
huffman@20552
   822
      (\<exists>N. \<forall>n. norm (X n) \<le> real(Suc N))"
haftmann@32064
   823
proof auto
haftmann@32064
   824
  fix K :: real
haftmann@32064
   825
  from reals_Archimedean2 obtain n :: nat where "K < real n" ..
haftmann@32064
   826
  then have "K \<le> real (Suc n)" by auto
haftmann@32064
   827
  assume "\<forall>m. norm (X m) \<le> K"
haftmann@32064
   828
  have "\<forall>m. norm (X m) \<le> real (Suc n)"
haftmann@32064
   829
  proof
haftmann@32064
   830
    fix m :: 'a
haftmann@32064
   831
    from `\<forall>m. norm (X m) \<le> K` have "norm (X m) \<le> K" ..
haftmann@32064
   832
    with `K \<le> real (Suc n)` show "norm (X m) \<le> real (Suc n)" by auto
haftmann@32064
   833
  qed
haftmann@32064
   834
  then show "\<exists>N. \<forall>n. norm (X n) \<le> real (Suc N)" ..
haftmann@32064
   835
next
haftmann@32064
   836
  fix N :: nat
haftmann@32064
   837
  have "real (Suc N) > 0" by (simp add: real_of_nat_Suc)
haftmann@32064
   838
  moreover assume "\<forall>n. norm (X n) \<le> real (Suc N)"
haftmann@32064
   839
  ultimately show "\<exists>K>0. \<forall>n. norm (X n) \<le> K" by blast
haftmann@32064
   840
qed
haftmann@32064
   841
paulson@15082
   842
paulson@15082
   843
text{* alternative definition for Bseq *}
huffman@20552
   844
lemma Bseq_iff: "Bseq X = (\<exists>N. \<forall>n. norm (X n) \<le> real(Suc N))"
paulson@15082
   845
apply (simp add: Bseq_def)
paulson@15082
   846
apply (simp (no_asm) add: lemma_NBseq_def)
paulson@15082
   847
done
paulson@15082
   848
paulson@15082
   849
lemma lemma_NBseq_def2:
huffman@20552
   850
     "(\<exists>K > 0. \<forall>n. norm (X n) \<le> K) = (\<exists>N. \<forall>n. norm (X n) < real(Suc N))"
paulson@15082
   851
apply (subst lemma_NBseq_def, auto)
paulson@15082
   852
apply (rule_tac x = "Suc N" in exI)
paulson@15082
   853
apply (rule_tac [2] x = N in exI)
paulson@15082
   854
apply (auto simp add: real_of_nat_Suc)
paulson@15082
   855
 prefer 2 apply (blast intro: order_less_imp_le)
paulson@15082
   856
apply (drule_tac x = n in spec, simp)
paulson@15082
   857
done
paulson@15082
   858
paulson@15082
   859
(* yet another definition for Bseq *)
huffman@20552
   860
lemma Bseq_iff1a: "Bseq X = (\<exists>N. \<forall>n. norm (X n) < real(Suc N))"
paulson@15082
   861
by (simp add: Bseq_def lemma_NBseq_def2)
paulson@15082
   862
huffman@20696
   863
subsubsection{*Upper Bounds and Lubs of Bounded Sequences*}
paulson@15082
   864
paulson@15082
   865
lemma Bseq_isUb:
paulson@15082
   866
  "!!(X::nat=>real). Bseq X ==> \<exists>U. isUb (UNIV::real set) {x. \<exists>n. X n = x} U"
huffman@22998
   867
by (auto intro: isUbI setleI simp add: Bseq_def abs_le_iff)
paulson@15082
   868
paulson@15082
   869
paulson@15082
   870
text{* Use completeness of reals (supremum property)
paulson@15082
   871
   to show that any bounded sequence has a least upper bound*}
paulson@15082
   872
paulson@15082
   873
lemma Bseq_isLub:
paulson@15082
   874
  "!!(X::nat=>real). Bseq X ==>
paulson@15082
   875
   \<exists>U. isLub (UNIV::real set) {x. \<exists>n. X n = x} U"
paulson@15082
   876
by (blast intro: reals_complete Bseq_isUb)
paulson@15082
   877
huffman@20696
   878
subsubsection{*A Bounded and Monotonic Sequence Converges*}
paulson@15082
   879
paulson@15082
   880
lemma lemma_converg1:
nipkow@15360
   881
     "!!(X::nat=>real). [| \<forall>m. \<forall> n \<ge> m. X m \<le> X n;
paulson@15082
   882
                  isLub (UNIV::real set) {x. \<exists>n. X n = x} (X ma)
nipkow@15360
   883
               |] ==> \<forall>n \<ge> ma. X n = X ma"
paulson@15082
   884
apply safe
paulson@15082
   885
apply (drule_tac y = "X n" in isLubD2)
paulson@15082
   886
apply (blast dest: order_antisym)+
paulson@15082
   887
done
paulson@15082
   888
paulson@15082
   889
text{* The best of both worlds: Easier to prove this result as a standard
paulson@15082
   890
   theorem and then use equivalence to "transfer" it into the
paulson@15082
   891
   equivalent nonstandard form if needed!*}
paulson@15082
   892
paulson@15082
   893
lemma Bmonoseq_LIMSEQ: "\<forall>n. m \<le> n --> X n = X m ==> \<exists>L. (X ----> L)"
paulson@15082
   894
apply (simp add: LIMSEQ_def)
paulson@15082
   895
apply (rule_tac x = "X m" in exI, safe)
paulson@15082
   896
apply (rule_tac x = m in exI, safe)
paulson@15082
   897
apply (drule spec, erule impE, auto)
paulson@15082
   898
done
paulson@15082
   899
paulson@15082
   900
lemma lemma_converg2:
paulson@15082
   901
   "!!(X::nat=>real).
paulson@15082
   902
    [| \<forall>m. X m ~= U;  isLub UNIV {x. \<exists>n. X n = x} U |] ==> \<forall>m. X m < U"
paulson@15082
   903
apply safe
paulson@15082
   904
apply (drule_tac y = "X m" in isLubD2)
paulson@15082
   905
apply (auto dest!: order_le_imp_less_or_eq)
paulson@15082
   906
done
paulson@15082
   907
paulson@15082
   908
lemma lemma_converg3: "!!(X ::nat=>real). \<forall>m. X m \<le> U ==> isUb UNIV {x. \<exists>n. X n = x} U"
paulson@15082
   909
by (rule setleI [THEN isUbI], auto)
paulson@15082
   910
paulson@15082
   911
text{* FIXME: @{term "U - T < U"} is redundant *}
paulson@15082
   912
lemma lemma_converg4: "!!(X::nat=> real).
paulson@15082
   913
               [| \<forall>m. X m ~= U;
paulson@15082
   914
                  isLub UNIV {x. \<exists>n. X n = x} U;
paulson@15082
   915
                  0 < T;
paulson@15082
   916
                  U + - T < U
paulson@15082
   917
               |] ==> \<exists>m. U + -T < X m & X m < U"
paulson@15082
   918
apply (drule lemma_converg2, assumption)
paulson@15082
   919
apply (rule ccontr, simp)
paulson@15082
   920
apply (simp add: linorder_not_less)
paulson@15082
   921
apply (drule lemma_converg3)
paulson@15082
   922
apply (drule isLub_le_isUb, assumption)
paulson@15082
   923
apply (auto dest: order_less_le_trans)
paulson@15082
   924
done
paulson@15082
   925
paulson@15082
   926
text{*A standard proof of the theorem for monotone increasing sequence*}
paulson@15082
   927
paulson@15082
   928
lemma Bseq_mono_convergent:
huffman@20552
   929
     "[| Bseq X; \<forall>m. \<forall>n \<ge> m. X m \<le> X n |] ==> convergent (X::nat=>real)"
paulson@15082
   930
apply (simp add: convergent_def)
paulson@15082
   931
apply (frule Bseq_isLub, safe)
paulson@15082
   932
apply (case_tac "\<exists>m. X m = U", auto)
paulson@15082
   933
apply (blast dest: lemma_converg1 Bmonoseq_LIMSEQ)
paulson@15082
   934
(* second case *)
paulson@15082
   935
apply (rule_tac x = U in exI)
paulson@15082
   936
apply (subst LIMSEQ_iff, safe)
paulson@15082
   937
apply (frule lemma_converg2, assumption)
paulson@15082
   938
apply (drule lemma_converg4, auto)
paulson@15082
   939
apply (rule_tac x = m in exI, safe)
paulson@15082
   940
apply (subgoal_tac "X m \<le> X n")
paulson@15082
   941
 prefer 2 apply blast
paulson@15082
   942
apply (drule_tac x=n and P="%m. X m < U" in spec, arith)
paulson@15082
   943
done
paulson@15082
   944
paulson@15082
   945
lemma Bseq_minus_iff: "Bseq (%n. -(X n)) = Bseq X"
paulson@15082
   946
by (simp add: Bseq_def)
paulson@15082
   947
paulson@15082
   948
text{*Main monotonicity theorem*}
paulson@15082
   949
lemma Bseq_monoseq_convergent: "[| Bseq X; monoseq X |] ==> convergent X"
paulson@15082
   950
apply (simp add: monoseq_def, safe)
paulson@15082
   951
apply (rule_tac [2] convergent_minus_iff [THEN ssubst])
paulson@15082
   952
apply (drule_tac [2] Bseq_minus_iff [THEN ssubst])
paulson@15082
   953
apply (auto intro!: Bseq_mono_convergent)
paulson@15082
   954
done
paulson@15082
   955
paulson@30730
   956
subsubsection{*Increasing and Decreasing Series*}
paulson@30730
   957
paulson@30730
   958
lemma incseq_imp_monoseq:  "incseq X \<Longrightarrow> monoseq X"
paulson@30730
   959
  by (simp add: incseq_def monoseq_def) 
paulson@30730
   960
paulson@30730
   961
lemma incseq_le: assumes inc: "incseq X" and lim: "X ----> L" shows "X n \<le> L"
paulson@30730
   962
  using monoseq_le [OF incseq_imp_monoseq [OF inc] lim]
paulson@30730
   963
proof
paulson@30730
   964
  assume "(\<forall>n. X n \<le> L) \<and> (\<forall>m n. m \<le> n \<longrightarrow> X m \<le> X n)"
paulson@30730
   965
  thus ?thesis by simp
paulson@30730
   966
next
paulson@30730
   967
  assume "(\<forall>n. L \<le> X n) \<and> (\<forall>m n. m \<le> n \<longrightarrow> X n \<le> X m)"
paulson@30730
   968
  hence const: "(!!m n. m \<le> n \<Longrightarrow> X n = X m)" using inc
paulson@30730
   969
    by (auto simp add: incseq_def intro: order_antisym)
paulson@30730
   970
  have X: "!!n. X n = X 0"
paulson@30730
   971
    by (blast intro: const [of 0]) 
paulson@30730
   972
  have "X = (\<lambda>n. X 0)"
paulson@30730
   973
    by (blast intro: ext X)
paulson@30730
   974
  hence "L = X 0" using LIMSEQ_const [of "X 0"]
paulson@30730
   975
    by (auto intro: LIMSEQ_unique lim) 
paulson@30730
   976
  thus ?thesis
paulson@30730
   977
    by (blast intro: eq_refl X)
paulson@30730
   978
qed
paulson@30730
   979
paulson@30730
   980
lemma decseq_imp_monoseq:  "decseq X \<Longrightarrow> monoseq X"
paulson@30730
   981
  by (simp add: decseq_def monoseq_def)
paulson@30730
   982
paulson@30730
   983
lemma decseq_eq_incseq: "decseq X = incseq (\<lambda>n. - X n)" 
paulson@30730
   984
  by (simp add: decseq_def incseq_def)
paulson@30730
   985
paulson@30730
   986
paulson@30730
   987
lemma decseq_le: assumes dec: "decseq X" and lim: "X ----> L" shows "L \<le> X n"
paulson@30730
   988
proof -
paulson@30730
   989
  have inc: "incseq (\<lambda>n. - X n)" using dec
paulson@30730
   990
    by (simp add: decseq_eq_incseq)
paulson@30730
   991
  have "- X n \<le> - L" 
paulson@30730
   992
    by (blast intro: incseq_le [OF inc] LIMSEQ_minus lim) 
paulson@30730
   993
  thus ?thesis
paulson@30730
   994
    by simp
paulson@30730
   995
qed
paulson@30730
   996
huffman@20696
   997
subsubsection{*A Few More Equivalence Theorems for Boundedness*}
paulson@15082
   998
paulson@15082
   999
text{*alternative formulation for boundedness*}
huffman@20552
  1000
lemma Bseq_iff2: "Bseq X = (\<exists>k > 0. \<exists>x. \<forall>n. norm (X(n) + -x) \<le> k)"
paulson@15082
  1001
apply (unfold Bseq_def, safe)
huffman@20552
  1002
apply (rule_tac [2] x = "k + norm x" in exI)
nipkow@15360
  1003
apply (rule_tac x = K in exI, simp)
paulson@15221
  1004
apply (rule exI [where x = 0], auto)
huffman@20552
  1005
apply (erule order_less_le_trans, simp)
huffman@20552
  1006
apply (drule_tac x=n in spec, fold diff_def)
huffman@20552
  1007
apply (drule order_trans [OF norm_triangle_ineq2])
huffman@20552
  1008
apply simp
paulson@15082
  1009
done
paulson@15082
  1010
paulson@15082
  1011
text{*alternative formulation for boundedness*}
huffman@20552
  1012
lemma Bseq_iff3: "Bseq X = (\<exists>k > 0. \<exists>N. \<forall>n. norm(X(n) + -X(N)) \<le> k)"
paulson@15082
  1013
apply safe
paulson@15082
  1014
apply (simp add: Bseq_def, safe)
huffman@20552
  1015
apply (rule_tac x = "K + norm (X N)" in exI)
paulson@15082
  1016
apply auto
huffman@20552
  1017
apply (erule order_less_le_trans, simp)
paulson@15082
  1018
apply (rule_tac x = N in exI, safe)
huffman@20552
  1019
apply (drule_tac x = n in spec)
huffman@20552
  1020
apply (rule order_trans [OF norm_triangle_ineq], simp)
paulson@15082
  1021
apply (auto simp add: Bseq_iff2)
paulson@15082
  1022
done
paulson@15082
  1023
huffman@20552
  1024
lemma BseqI2: "(\<forall>n. k \<le> f n & f n \<le> (K::real)) ==> Bseq f"
paulson@15082
  1025
apply (simp add: Bseq_def)
paulson@15221
  1026
apply (rule_tac x = " (\<bar>k\<bar> + \<bar>K\<bar>) + 1" in exI, auto)
webertj@20217
  1027
apply (drule_tac x = n in spec, arith)
paulson@15082
  1028
done
paulson@15082
  1029
paulson@15082
  1030
huffman@20696
  1031
subsection {* Cauchy Sequences *}
paulson@15082
  1032
huffman@31336
  1033
lemma metric_CauchyI:
huffman@31336
  1034
  "(\<And>e. 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < e) \<Longrightarrow> Cauchy X"
huffman@31336
  1035
by (simp add: Cauchy_def)
huffman@31336
  1036
huffman@31336
  1037
lemma metric_CauchyD:
huffman@31336
  1038
  "\<lbrakk>Cauchy X; 0 < e\<rbrakk> \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < e"
huffman@20751
  1039
by (simp add: Cauchy_def)
huffman@20751
  1040
huffman@31336
  1041
lemma Cauchy_iff:
huffman@31336
  1042
  fixes X :: "nat \<Rightarrow> 'a::real_normed_vector"
huffman@31336
  1043
  shows "Cauchy X \<longleftrightarrow> (\<forall>e>0. \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e)"
huffman@31336
  1044
unfolding Cauchy_def dist_norm ..
huffman@31336
  1045
huffman@31336
  1046
lemma CauchyI:
huffman@31336
  1047
  fixes X :: "nat \<Rightarrow> 'a::real_normed_vector"
huffman@31336
  1048
  shows "(\<And>e. 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e) \<Longrightarrow> Cauchy X"
huffman@31336
  1049
by (simp add: Cauchy_iff)
huffman@31336
  1050
huffman@20751
  1051
lemma CauchyD:
huffman@31336
  1052
  fixes X :: "nat \<Rightarrow> 'a::real_normed_vector"
huffman@31336
  1053
  shows "\<lbrakk>Cauchy X; 0 < e\<rbrakk> \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e"
huffman@31336
  1054
by (simp add: Cauchy_iff)
huffman@20751
  1055
paulson@30730
  1056
lemma Cauchy_subseq_Cauchy:
paulson@30730
  1057
  "\<lbrakk> Cauchy X; subseq f \<rbrakk> \<Longrightarrow> Cauchy (X o f)"
huffman@31336
  1058
apply (auto simp add: Cauchy_def)
huffman@31336
  1059
apply (drule_tac x=e in spec, clarify)
huffman@31336
  1060
apply (rule_tac x=M in exI, clarify)
huffman@31336
  1061
apply (blast intro: le_trans [OF _ seq_suble] dest!: spec)
paulson@30730
  1062
done
paulson@30730
  1063
huffman@20696
  1064
subsubsection {* Cauchy Sequences are Bounded *}
huffman@20696
  1065
paulson@15082
  1066
text{*A Cauchy sequence is bounded -- this is the standard
paulson@15082
  1067
  proof mechanization rather than the nonstandard proof*}
paulson@15082
  1068
huffman@20563
  1069
lemma lemmaCauchy: "\<forall>n \<ge> M. norm (X M - X n) < (1::real)
huffman@20552
  1070
          ==>  \<forall>n \<ge> M. norm (X n :: 'a::real_normed_vector) < 1 + norm (X M)"
huffman@20552
  1071
apply (clarify, drule spec, drule (1) mp)
huffman@20563
  1072
apply (simp only: norm_minus_commute)
huffman@20552
  1073
apply (drule order_le_less_trans [OF norm_triangle_ineq2])
huffman@20552
  1074
apply simp
huffman@20552
  1075
done
paulson@15082
  1076
paulson@15082
  1077
lemma Cauchy_Bseq: "Cauchy X ==> Bseq X"
huffman@31336
  1078
apply (simp add: Cauchy_iff)
huffman@20552
  1079
apply (drule spec, drule mp, rule zero_less_one, safe)
huffman@20552
  1080
apply (drule_tac x="M" in spec, simp)
paulson@15082
  1081
apply (drule lemmaCauchy)
huffman@22608
  1082
apply (rule_tac k="M" in Bseq_offset)
huffman@20552
  1083
apply (simp add: Bseq_def)
huffman@20552
  1084
apply (rule_tac x="1 + norm (X M)" in exI)
huffman@20552
  1085
apply (rule conjI, rule order_less_le_trans [OF zero_less_one], simp)
huffman@20552
  1086
apply (simp add: order_less_imp_le)
paulson@15082
  1087
done
paulson@15082
  1088
huffman@20696
  1089
subsubsection {* Cauchy Sequences are Convergent *}
paulson@15082
  1090
huffman@31403
  1091
axclass complete_space \<subseteq> metric_space
huffman@20830
  1092
  Cauchy_convergent: "Cauchy X \<Longrightarrow> convergent X"
huffman@20830
  1093
huffman@31403
  1094
axclass banach \<subseteq> real_normed_vector, complete_space
huffman@31403
  1095
huffman@22629
  1096
theorem LIMSEQ_imp_Cauchy:
huffman@22629
  1097
  assumes X: "X ----> a" shows "Cauchy X"
huffman@31336
  1098
proof (rule metric_CauchyI)
huffman@22629
  1099
  fix e::real assume "0 < e"
huffman@22629
  1100
  hence "0 < e/2" by simp
huffman@31336
  1101
  with X have "\<exists>N. \<forall>n\<ge>N. dist (X n) a < e/2" by (rule metric_LIMSEQ_D)
huffman@31336
  1102
  then obtain N where N: "\<forall>n\<ge>N. dist (X n) a < e/2" ..
huffman@31336
  1103
  show "\<exists>N. \<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m) (X n) < e"
huffman@22629
  1104
  proof (intro exI allI impI)
huffman@22629
  1105
    fix m assume "N \<le> m"
huffman@31336
  1106
    hence m: "dist (X m) a < e/2" using N by fast
huffman@22629
  1107
    fix n assume "N \<le> n"
huffman@31336
  1108
    hence n: "dist (X n) a < e/2" using N by fast
huffman@31336
  1109
    have "dist (X m) (X n) \<le> dist (X m) a + dist (X n) a"
huffman@31336
  1110
      by (rule dist_triangle2)
huffman@31336
  1111
    also from m n have "\<dots> < e" by simp
huffman@31336
  1112
    finally show "dist (X m) (X n) < e" .
huffman@22629
  1113
  qed
huffman@22629
  1114
qed
huffman@22629
  1115
huffman@20691
  1116
lemma convergent_Cauchy: "convergent X \<Longrightarrow> Cauchy X"
huffman@22629
  1117
unfolding convergent_def
huffman@22629
  1118
by (erule exE, erule LIMSEQ_imp_Cauchy)
huffman@20691
  1119
huffman@31403
  1120
lemma Cauchy_convergent_iff:
huffman@31403
  1121
  fixes X :: "nat \<Rightarrow> 'a::complete_space"
huffman@31403
  1122
  shows "Cauchy X = convergent X"
huffman@31403
  1123
by (fast intro: Cauchy_convergent convergent_Cauchy)
huffman@31403
  1124
huffman@31403
  1125
lemma convergent_subseq_convergent:
huffman@31403
  1126
  fixes X :: "nat \<Rightarrow> 'a::complete_space"
huffman@31403
  1127
  shows "\<lbrakk> convergent X; subseq f \<rbrakk> \<Longrightarrow> convergent (X o f)"
huffman@31403
  1128
  by (simp add: Cauchy_subseq_Cauchy Cauchy_convergent_iff [symmetric])
huffman@31403
  1129
huffman@22629
  1130
text {*
huffman@22629
  1131
Proof that Cauchy sequences converge based on the one from
huffman@22629
  1132
http://pirate.shu.edu/~wachsmut/ira/numseq/proofs/cauconv.html
huffman@22629
  1133
*}
huffman@22629
  1134
huffman@22629
  1135
text {*
huffman@22629
  1136
  If sequence @{term "X"} is Cauchy, then its limit is the lub of
huffman@22629
  1137
  @{term "{r::real. \<exists>N. \<forall>n\<ge>N. r < X n}"}
huffman@22629
  1138
*}
huffman@22629
  1139
huffman@22629
  1140
lemma isUb_UNIV_I: "(\<And>y. y \<in> S \<Longrightarrow> y \<le> u) \<Longrightarrow> isUb UNIV S u"
huffman@22629
  1141
by (simp add: isUbI setleI)
huffman@22629
  1142
haftmann@27681
  1143
locale real_Cauchy =
huffman@22629
  1144
  fixes X :: "nat \<Rightarrow> real"
huffman@22629
  1145
  assumes X: "Cauchy X"
huffman@22629
  1146
  fixes S :: "real set"
huffman@22629
  1147
  defines S_def: "S \<equiv> {x::real. \<exists>N. \<forall>n\<ge>N. x < X n}"
huffman@22629
  1148
haftmann@27681
  1149
lemma real_CauchyI:
haftmann@27681
  1150
  assumes "Cauchy X"
haftmann@27681
  1151
  shows "real_Cauchy X"
haftmann@28823
  1152
  proof qed (fact assms)
haftmann@27681
  1153
huffman@22629
  1154
lemma (in real_Cauchy) mem_S: "\<forall>n\<ge>N. x < X n \<Longrightarrow> x \<in> S"
huffman@22629
  1155
by (unfold S_def, auto)
huffman@22629
  1156
huffman@22629
  1157
lemma (in real_Cauchy) bound_isUb:
huffman@22629
  1158
  assumes N: "\<forall>n\<ge>N. X n < x"
huffman@22629
  1159
  shows "isUb UNIV S x"
huffman@22629
  1160
proof (rule isUb_UNIV_I)
huffman@22629
  1161
  fix y::real assume "y \<in> S"
huffman@22629
  1162
  hence "\<exists>M. \<forall>n\<ge>M. y < X n"
huffman@22629
  1163
    by (simp add: S_def)
huffman@22629
  1164
  then obtain M where "\<forall>n\<ge>M. y < X n" ..
huffman@22629
  1165
  hence "y < X (max M N)" by simp
huffman@22629
  1166
  also have "\<dots> < x" using N by simp
huffman@22629
  1167
  finally show "y \<le> x"
huffman@22629
  1168
    by (rule order_less_imp_le)
huffman@22629
  1169
qed
huffman@22629
  1170
huffman@22629
  1171
lemma (in real_Cauchy) isLub_ex: "\<exists>u. isLub UNIV S u"
huffman@22629
  1172
proof (rule reals_complete)
huffman@22629
  1173
  obtain N where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (X m - X n) < 1"
haftmann@32064
  1174
    using CauchyD [OF X zero_less_one] by auto
huffman@22629
  1175
  hence N: "\<forall>n\<ge>N. norm (X n - X N) < 1" by simp
huffman@22629
  1176
  show "\<exists>x. x \<in> S"
huffman@22629
  1177
  proof
huffman@22629
  1178
    from N have "\<forall>n\<ge>N. X N - 1 < X n"
paulson@32707
  1179
      by (simp add: abs_diff_less_iff)
huffman@22629
  1180
    thus "X N - 1 \<in> S" by (rule mem_S)
huffman@22629
  1181
  qed
huffman@22629
  1182
  show "\<exists>u. isUb UNIV S u"
huffman@22629
  1183
  proof
huffman@22629
  1184
    from N have "\<forall>n\<ge>N. X n < X N + 1"
paulson@32707
  1185
      by (simp add: abs_diff_less_iff)
huffman@22629
  1186
    thus "isUb UNIV S (X N + 1)"
huffman@22629
  1187
      by (rule bound_isUb)
huffman@22629
  1188
  qed
huffman@22629
  1189
qed
huffman@22629
  1190
huffman@22629
  1191
lemma (in real_Cauchy) isLub_imp_LIMSEQ:
huffman@22629
  1192
  assumes x: "isLub UNIV S x"
huffman@22629
  1193
  shows "X ----> x"
huffman@22629
  1194
proof (rule LIMSEQ_I)
huffman@22629
  1195
  fix r::real assume "0 < r"
huffman@22629
  1196
  hence r: "0 < r/2" by simp
huffman@22629
  1197
  obtain N where "\<forall>n\<ge>N. \<forall>m\<ge>N. norm (X n - X m) < r/2"
haftmann@32064
  1198
    using CauchyD [OF X r] by auto
huffman@22629
  1199
  hence "\<forall>n\<ge>N. norm (X n - X N) < r/2" by simp
huffman@22629
  1200
  hence N: "\<forall>n\<ge>N. X N - r/2 < X n \<and> X n < X N + r/2"
paulson@32707
  1201
    by (simp only: real_norm_def abs_diff_less_iff)
huffman@22629
  1202
huffman@22629
  1203
  from N have "\<forall>n\<ge>N. X N - r/2 < X n" by fast
huffman@22629
  1204
  hence "X N - r/2 \<in> S" by (rule mem_S)
nipkow@23482
  1205
  hence 1: "X N - r/2 \<le> x" using x isLub_isUb isUbD by fast
huffman@22629
  1206
huffman@22629
  1207
  from N have "\<forall>n\<ge>N. X n < X N + r/2" by fast
huffman@22629
  1208
  hence "isUb UNIV S (X N + r/2)" by (rule bound_isUb)
nipkow@23482
  1209
  hence 2: "x \<le> X N + r/2" using x isLub_le_isUb by fast
huffman@22629
  1210
huffman@22629
  1211
  show "\<exists>N. \<forall>n\<ge>N. norm (X n - x) < r"
huffman@22629
  1212
  proof (intro exI allI impI)
huffman@22629
  1213
    fix n assume n: "N \<le> n"
nipkow@23482
  1214
    from N n have "X n < X N + r/2" and "X N - r/2 < X n" by simp+
nipkow@23482
  1215
    thus "norm (X n - x) < r" using 1 2
paulson@32707
  1216
      by (simp add: abs_diff_less_iff)
huffman@22629
  1217
  qed
huffman@22629
  1218
qed
huffman@22629
  1219
huffman@22629
  1220
lemma (in real_Cauchy) LIMSEQ_ex: "\<exists>x. X ----> x"
huffman@22629
  1221
proof -
huffman@22629
  1222
  obtain x where "isLub UNIV S x"
huffman@22629
  1223
    using isLub_ex by fast
huffman@22629
  1224
  hence "X ----> x"
huffman@22629
  1225
    by (rule isLub_imp_LIMSEQ)
huffman@22629
  1226
  thus ?thesis ..
huffman@22629
  1227
qed
huffman@22629
  1228
huffman@20830
  1229
lemma real_Cauchy_convergent:
huffman@20830
  1230
  fixes X :: "nat \<Rightarrow> real"
huffman@20830
  1231
  shows "Cauchy X \<Longrightarrow> convergent X"
haftmann@27681
  1232
unfolding convergent_def
haftmann@27681
  1233
by (rule real_Cauchy.LIMSEQ_ex)
haftmann@27681
  1234
 (rule real_CauchyI)
huffman@20830
  1235
huffman@20830
  1236
instance real :: banach
huffman@20830
  1237
by intro_classes (rule real_Cauchy_convergent)
huffman@20830
  1238
paulson@15082
  1239
huffman@20696
  1240
subsection {* Power Sequences *}
paulson@15082
  1241
paulson@15082
  1242
text{*The sequence @{term "x^n"} tends to 0 if @{term "0\<le>x"} and @{term
paulson@15082
  1243
"x<1"}.  Proof will use (NS) Cauchy equivalence for convergence and
paulson@15082
  1244
  also fact that bounded and monotonic sequence converges.*}
paulson@15082
  1245
huffman@20552
  1246
lemma Bseq_realpow: "[| 0 \<le> (x::real); x \<le> 1 |] ==> Bseq (%n. x ^ n)"
paulson@15082
  1247
apply (simp add: Bseq_def)
paulson@15082
  1248
apply (rule_tac x = 1 in exI)
paulson@15082
  1249
apply (simp add: power_abs)
huffman@22974
  1250
apply (auto dest: power_mono)
paulson@15082
  1251
done
paulson@15082
  1252
paulson@15082
  1253
lemma monoseq_realpow: "[| 0 \<le> x; x \<le> 1 |] ==> monoseq (%n. x ^ n)"
paulson@15082
  1254
apply (clarify intro!: mono_SucI2)
paulson@15082
  1255
apply (cut_tac n = n and N = "Suc n" and a = x in power_decreasing, auto)
paulson@15082
  1256
done
paulson@15082
  1257
huffman@20552
  1258
lemma convergent_realpow:
huffman@20552
  1259
  "[| 0 \<le> (x::real); x \<le> 1 |] ==> convergent (%n. x ^ n)"
paulson@15082
  1260
by (blast intro!: Bseq_monoseq_convergent Bseq_realpow monoseq_realpow)
paulson@15082
  1261
huffman@22628
  1262
lemma LIMSEQ_inverse_realpow_zero_lemma:
huffman@22628
  1263
  fixes x :: real
huffman@22628
  1264
  assumes x: "0 \<le> x"
huffman@22628
  1265
  shows "real n * x + 1 \<le> (x + 1) ^ n"
huffman@22628
  1266
apply (induct n)
huffman@22628
  1267
apply simp
huffman@22628
  1268
apply simp
huffman@22628
  1269
apply (rule order_trans)
huffman@22628
  1270
prefer 2
huffman@22628
  1271
apply (erule mult_left_mono)
huffman@22628
  1272
apply (rule add_increasing [OF x], simp)
huffman@22628
  1273
apply (simp add: real_of_nat_Suc)
nipkow@23477
  1274
apply (simp add: ring_distribs)
huffman@22628
  1275
apply (simp add: mult_nonneg_nonneg x)
huffman@22628
  1276
done
huffman@22628
  1277
huffman@22628
  1278
lemma LIMSEQ_inverse_realpow_zero:
huffman@22628
  1279
  "1 < (x::real) \<Longrightarrow> (\<lambda>n. inverse (x ^ n)) ----> 0"
huffman@22628
  1280
proof (rule LIMSEQ_inverse_zero [rule_format])
huffman@22628
  1281
  fix y :: real
huffman@22628
  1282
  assume x: "1 < x"
huffman@22628
  1283
  hence "0 < x - 1" by simp
huffman@22628
  1284
  hence "\<forall>y. \<exists>N::nat. y < real N * (x - 1)"
huffman@22628
  1285
    by (rule reals_Archimedean3)
huffman@22628
  1286
  hence "\<exists>N::nat. y < real N * (x - 1)" ..
huffman@22628
  1287
  then obtain N::nat where "y < real N * (x - 1)" ..
huffman@22628
  1288
  also have "\<dots> \<le> real N * (x - 1) + 1" by simp
huffman@22628
  1289
  also have "\<dots> \<le> (x - 1 + 1) ^ N"
huffman@22628
  1290
    by (rule LIMSEQ_inverse_realpow_zero_lemma, cut_tac x, simp)
huffman@22628
  1291
  also have "\<dots> = x ^ N" by simp
huffman@22628
  1292
  finally have "y < x ^ N" .
huffman@22628
  1293
  hence "\<forall>n\<ge>N. y < x ^ n"
huffman@22628
  1294
    apply clarify
huffman@22628
  1295
    apply (erule order_less_le_trans)
huffman@22628
  1296
    apply (erule power_increasing)
huffman@22628
  1297
    apply (rule order_less_imp_le [OF x])
huffman@22628
  1298
    done
huffman@22628
  1299
  thus "\<exists>N. \<forall>n\<ge>N. y < x ^ n" ..
huffman@22628
  1300
qed
huffman@22628
  1301
huffman@20552
  1302
lemma LIMSEQ_realpow_zero:
huffman@22628
  1303
  "\<lbrakk>0 \<le> (x::real); x < 1\<rbrakk> \<Longrightarrow> (\<lambda>n. x ^ n) ----> 0"
huffman@22628
  1304
proof (cases)
huffman@22628
  1305
  assume "x = 0"
huffman@22628
  1306
  hence "(\<lambda>n. x ^ Suc n) ----> 0" by (simp add: LIMSEQ_const)
huffman@22628
  1307
  thus ?thesis by (rule LIMSEQ_imp_Suc)
huffman@22628
  1308
next
huffman@22628
  1309
  assume "0 \<le> x" and "x \<noteq> 0"
huffman@22628
  1310
  hence x0: "0 < x" by simp
huffman@22628
  1311
  assume x1: "x < 1"
huffman@22628
  1312
  from x0 x1 have "1 < inverse x"
huffman@22628
  1313
    by (rule real_inverse_gt_one)
huffman@22628
  1314
  hence "(\<lambda>n. inverse (inverse x ^ n)) ----> 0"
huffman@22628
  1315
    by (rule LIMSEQ_inverse_realpow_zero)
huffman@22628
  1316
  thus ?thesis by (simp add: power_inverse)
huffman@22628
  1317
qed
paulson@15082
  1318
huffman@20685
  1319
lemma LIMSEQ_power_zero:
haftmann@31017
  1320
  fixes x :: "'a::{real_normed_algebra_1}"
huffman@20685
  1321
  shows "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) ----> 0"
huffman@20685
  1322
apply (drule LIMSEQ_realpow_zero [OF norm_ge_zero])
huffman@22974
  1323
apply (simp only: LIMSEQ_Zseq_iff, erule Zseq_le)
huffman@22974
  1324
apply (simp add: power_abs norm_power_ineq)
huffman@20685
  1325
done
huffman@20685
  1326
huffman@20552
  1327
lemma LIMSEQ_divide_realpow_zero:
huffman@20552
  1328
  "1 < (x::real) ==> (%n. a / (x ^ n)) ----> 0"
paulson@15082
  1329
apply (cut_tac a = a and x1 = "inverse x" in
paulson@15082
  1330
        LIMSEQ_mult [OF LIMSEQ_const LIMSEQ_realpow_zero])
paulson@15082
  1331
apply (auto simp add: divide_inverse power_inverse)
paulson@15082
  1332
apply (simp add: inverse_eq_divide pos_divide_less_eq)
paulson@15082
  1333
done
paulson@15082
  1334
paulson@15102
  1335
text{*Limit of @{term "c^n"} for @{term"\<bar>c\<bar> < 1"}*}
paulson@15082
  1336
huffman@20552
  1337
lemma LIMSEQ_rabs_realpow_zero: "\<bar>c\<bar> < (1::real) ==> (%n. \<bar>c\<bar> ^ n) ----> 0"
huffman@20685
  1338
by (rule LIMSEQ_realpow_zero [OF abs_ge_zero])
paulson@15082
  1339
huffman@20552
  1340
lemma LIMSEQ_rabs_realpow_zero2: "\<bar>c\<bar> < (1::real) ==> (%n. c ^ n) ----> 0"
paulson@15082
  1341
apply (rule LIMSEQ_rabs_zero [THEN iffD1])
paulson@15082
  1342
apply (auto intro: LIMSEQ_rabs_realpow_zero simp add: power_abs)
paulson@15082
  1343
done
paulson@15082
  1344
paulson@10751
  1345
end