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