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