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