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