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