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