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