src/HOL/SEQ.thy
changeset 29197 6d4cb27ed19c
parent 28952 15a4b2cf8c34
child 29667 53103fc8ffa3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/SEQ.thy	Mon Dec 29 14:08:08 2008 +0100
     1.3 @@ -0,0 +1,1136 @@
     1.4 +(*  Title       : SEQ.thy
     1.5 +    Author      : Jacques D. Fleuriot
     1.6 +    Copyright   : 1998  University of Cambridge
     1.7 +    Description : Convergence of sequences and series
     1.8 +    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
     1.9 +    Additional contributions by Jeremy Avigad and Brian Huffman
    1.10 +*)
    1.11 +
    1.12 +header {* Sequences and Convergence *}
    1.13 +
    1.14 +theory SEQ
    1.15 +imports RealVector RComplete
    1.16 +begin
    1.17 +
    1.18 +definition
    1.19 +  Zseq :: "[nat \<Rightarrow> 'a::real_normed_vector] \<Rightarrow> bool" where
    1.20 +    --{*Standard definition of sequence converging to zero*}
    1.21 +  [code del]: "Zseq X = (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. norm (X n) < r)"
    1.22 +
    1.23 +definition
    1.24 +  LIMSEQ :: "[nat => 'a::real_normed_vector, 'a] => bool"
    1.25 +    ("((_)/ ----> (_))" [60, 60] 60) where
    1.26 +    --{*Standard definition of convergence of sequence*}
    1.27 +  [code del]: "X ----> L = (\<forall>r. 0 < r --> (\<exists>no. \<forall>n. no \<le> n --> norm (X n - L) < r))"
    1.28 +
    1.29 +definition
    1.30 +  lim :: "(nat => 'a::real_normed_vector) => 'a" where
    1.31 +    --{*Standard definition of limit using choice operator*}
    1.32 +  "lim X = (THE L. X ----> L)"
    1.33 +
    1.34 +definition
    1.35 +  convergent :: "(nat => 'a::real_normed_vector) => bool" where
    1.36 +    --{*Standard definition of convergence*}
    1.37 +  "convergent X = (\<exists>L. X ----> L)"
    1.38 +
    1.39 +definition
    1.40 +  Bseq :: "(nat => 'a::real_normed_vector) => bool" where
    1.41 +    --{*Standard definition for bounded sequence*}
    1.42 +  [code del]: "Bseq X = (\<exists>K>0.\<forall>n. norm (X n) \<le> K)"
    1.43 +
    1.44 +definition
    1.45 +  monoseq :: "(nat=>real)=>bool" where
    1.46 +    --{*Definition for monotonicity*}
    1.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))"
    1.48 +
    1.49 +definition
    1.50 +  subseq :: "(nat => nat) => bool" where
    1.51 +    --{*Definition of subsequence*}
    1.52 +  [code del]:   "subseq f = (\<forall>m. \<forall>n>m. (f m) < (f n))"
    1.53 +
    1.54 +definition
    1.55 +  Cauchy :: "(nat => 'a::real_normed_vector) => bool" where
    1.56 +    --{*Standard definition of the Cauchy condition*}
    1.57 +  [code del]: "Cauchy X = (\<forall>e>0. \<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. norm (X m - X n) < e)"
    1.58 +
    1.59 +
    1.60 +subsection {* Bounded Sequences *}
    1.61 +
    1.62 +lemma BseqI': assumes K: "\<And>n. norm (X n) \<le> K" shows "Bseq X"
    1.63 +unfolding Bseq_def
    1.64 +proof (intro exI conjI allI)
    1.65 +  show "0 < max K 1" by simp
    1.66 +next
    1.67 +  fix n::nat
    1.68 +  have "norm (X n) \<le> K" by (rule K)
    1.69 +  thus "norm (X n) \<le> max K 1" by simp
    1.70 +qed
    1.71 +
    1.72 +lemma BseqE: "\<lbrakk>Bseq X; \<And>K. \<lbrakk>0 < K; \<forall>n. norm (X n) \<le> K\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
    1.73 +unfolding Bseq_def by auto
    1.74 +
    1.75 +lemma BseqI2': assumes K: "\<forall>n\<ge>N. norm (X n) \<le> K" shows "Bseq X"
    1.76 +proof (rule BseqI')
    1.77 +  let ?A = "norm ` X ` {..N}"
    1.78 +  have 1: "finite ?A" by simp
    1.79 +  fix n::nat
    1.80 +  show "norm (X n) \<le> max K (Max ?A)"
    1.81 +  proof (cases rule: linorder_le_cases)
    1.82 +    assume "n \<ge> N"
    1.83 +    hence "norm (X n) \<le> K" using K by simp
    1.84 +    thus "norm (X n) \<le> max K (Max ?A)" by simp
    1.85 +  next
    1.86 +    assume "n \<le> N"
    1.87 +    hence "norm (X n) \<in> ?A" by simp
    1.88 +    with 1 have "norm (X n) \<le> Max ?A" by (rule Max_ge)
    1.89 +    thus "norm (X n) \<le> max K (Max ?A)" by simp
    1.90 +  qed
    1.91 +qed
    1.92 +
    1.93 +lemma Bseq_ignore_initial_segment: "Bseq X \<Longrightarrow> Bseq (\<lambda>n. X (n + k))"
    1.94 +unfolding Bseq_def by auto
    1.95 +
    1.96 +lemma Bseq_offset: "Bseq (\<lambda>n. X (n + k)) \<Longrightarrow> Bseq X"
    1.97 +apply (erule BseqE)
    1.98 +apply (rule_tac N="k" and K="K" in BseqI2')
    1.99 +apply clarify
   1.100 +apply (drule_tac x="n - k" in spec, simp)
   1.101 +done
   1.102 +
   1.103 +
   1.104 +subsection {* Sequences That Converge to Zero *}
   1.105 +
   1.106 +lemma ZseqI:
   1.107 +  "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n) < r) \<Longrightarrow> Zseq X"
   1.108 +unfolding Zseq_def by simp
   1.109 +
   1.110 +lemma ZseqD:
   1.111 +  "\<lbrakk>Zseq X; 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n) < r"
   1.112 +unfolding Zseq_def by simp
   1.113 +
   1.114 +lemma Zseq_zero: "Zseq (\<lambda>n. 0)"
   1.115 +unfolding Zseq_def by simp
   1.116 +
   1.117 +lemma Zseq_const_iff: "Zseq (\<lambda>n. k) = (k = 0)"
   1.118 +unfolding Zseq_def by force
   1.119 +
   1.120 +lemma Zseq_norm_iff: "Zseq (\<lambda>n. norm (X n)) = Zseq (\<lambda>n. X n)"
   1.121 +unfolding Zseq_def by simp
   1.122 +
   1.123 +lemma Zseq_imp_Zseq:
   1.124 +  assumes X: "Zseq X"
   1.125 +  assumes Y: "\<And>n. norm (Y n) \<le> norm (X n) * K"
   1.126 +  shows "Zseq (\<lambda>n. Y n)"
   1.127 +proof (cases)
   1.128 +  assume K: "0 < K"
   1.129 +  show ?thesis
   1.130 +  proof (rule ZseqI)
   1.131 +    fix r::real assume "0 < r"
   1.132 +    hence "0 < r / K"
   1.133 +      using K by (rule divide_pos_pos)
   1.134 +    then obtain N where "\<forall>n\<ge>N. norm (X n) < r / K"
   1.135 +      using ZseqD [OF X] by fast
   1.136 +    hence "\<forall>n\<ge>N. norm (X n) * K < r"
   1.137 +      by (simp add: pos_less_divide_eq K)
   1.138 +    hence "\<forall>n\<ge>N. norm (Y n) < r"
   1.139 +      by (simp add: order_le_less_trans [OF Y])
   1.140 +    thus "\<exists>N. \<forall>n\<ge>N. norm (Y n) < r" ..
   1.141 +  qed
   1.142 +next
   1.143 +  assume "\<not> 0 < K"
   1.144 +  hence K: "K \<le> 0" by (simp only: linorder_not_less)
   1.145 +  {
   1.146 +    fix n::nat
   1.147 +    have "norm (Y n) \<le> norm (X n) * K" by (rule Y)
   1.148 +    also have "\<dots> \<le> norm (X n) * 0"
   1.149 +      using K norm_ge_zero by (rule mult_left_mono)
   1.150 +    finally have "norm (Y n) = 0" by simp
   1.151 +  }
   1.152 +  thus ?thesis by (simp add: Zseq_zero)
   1.153 +qed
   1.154 +
   1.155 +lemma Zseq_le: "\<lbrakk>Zseq Y; \<forall>n. norm (X n) \<le> norm (Y n)\<rbrakk> \<Longrightarrow> Zseq X"
   1.156 +by (erule_tac K="1" in Zseq_imp_Zseq, simp)
   1.157 +
   1.158 +lemma Zseq_add:
   1.159 +  assumes X: "Zseq X"
   1.160 +  assumes Y: "Zseq Y"
   1.161 +  shows "Zseq (\<lambda>n. X n + Y n)"
   1.162 +proof (rule ZseqI)
   1.163 +  fix r::real assume "0 < r"
   1.164 +  hence r: "0 < r / 2" by simp
   1.165 +  obtain M where M: "\<forall>n\<ge>M. norm (X n) < r/2"
   1.166 +    using ZseqD [OF X r] by fast
   1.167 +  obtain N where N: "\<forall>n\<ge>N. norm (Y n) < r/2"
   1.168 +    using ZseqD [OF Y r] by fast
   1.169 +  show "\<exists>N. \<forall>n\<ge>N. norm (X n + Y n) < r"
   1.170 +  proof (intro exI allI impI)
   1.171 +    fix n assume n: "max M N \<le> n"
   1.172 +    have "norm (X n + Y n) \<le> norm (X n) + norm (Y n)"
   1.173 +      by (rule norm_triangle_ineq)
   1.174 +    also have "\<dots> < r/2 + r/2"
   1.175 +    proof (rule add_strict_mono)
   1.176 +      from M n show "norm (X n) < r/2" by simp
   1.177 +      from N n show "norm (Y n) < r/2" by simp
   1.178 +    qed
   1.179 +    finally show "norm (X n + Y n) < r" by simp
   1.180 +  qed
   1.181 +qed
   1.182 +
   1.183 +lemma Zseq_minus: "Zseq X \<Longrightarrow> Zseq (\<lambda>n. - X n)"
   1.184 +unfolding Zseq_def by simp
   1.185 +
   1.186 +lemma Zseq_diff: "\<lbrakk>Zseq X; Zseq Y\<rbrakk> \<Longrightarrow> Zseq (\<lambda>n. X n - Y n)"
   1.187 +by (simp only: diff_minus Zseq_add Zseq_minus)
   1.188 +
   1.189 +lemma (in bounded_linear) Zseq:
   1.190 +  assumes X: "Zseq X"
   1.191 +  shows "Zseq (\<lambda>n. f (X n))"
   1.192 +proof -
   1.193 +  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
   1.194 +    using bounded by fast
   1.195 +  with X show ?thesis
   1.196 +    by (rule Zseq_imp_Zseq)
   1.197 +qed
   1.198 +
   1.199 +lemma (in bounded_bilinear) Zseq:
   1.200 +  assumes X: "Zseq X"
   1.201 +  assumes Y: "Zseq Y"
   1.202 +  shows "Zseq (\<lambda>n. X n ** Y n)"
   1.203 +proof (rule ZseqI)
   1.204 +  fix r::real assume r: "0 < r"
   1.205 +  obtain K where K: "0 < K"
   1.206 +    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   1.207 +    using pos_bounded by fast
   1.208 +  from K have K': "0 < inverse K"
   1.209 +    by (rule positive_imp_inverse_positive)
   1.210 +  obtain M where M: "\<forall>n\<ge>M. norm (X n) < r"
   1.211 +    using ZseqD [OF X r] by fast
   1.212 +  obtain N where N: "\<forall>n\<ge>N. norm (Y n) < inverse K"
   1.213 +    using ZseqD [OF Y K'] by fast
   1.214 +  show "\<exists>N. \<forall>n\<ge>N. norm (X n ** Y n) < r"
   1.215 +  proof (intro exI allI impI)
   1.216 +    fix n assume n: "max M N \<le> n"
   1.217 +    have "norm (X n ** Y n) \<le> norm (X n) * norm (Y n) * K"
   1.218 +      by (rule norm_le)
   1.219 +    also have "norm (X n) * norm (Y n) * K < r * inverse K * K"
   1.220 +    proof (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero K)
   1.221 +      from M n show Xn: "norm (X n) < r" by simp
   1.222 +      from N n show Yn: "norm (Y n) < inverse K" by simp
   1.223 +    qed
   1.224 +    also from K have "r * inverse K * K = r" by simp
   1.225 +    finally show "norm (X n ** Y n) < r" .
   1.226 +  qed
   1.227 +qed
   1.228 +
   1.229 +lemma (in bounded_bilinear) Zseq_prod_Bseq:
   1.230 +  assumes X: "Zseq X"
   1.231 +  assumes Y: "Bseq Y"
   1.232 +  shows "Zseq (\<lambda>n. X n ** Y n)"
   1.233 +proof -
   1.234 +  obtain K where K: "0 \<le> K"
   1.235 +    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   1.236 +    using nonneg_bounded by fast
   1.237 +  obtain B where B: "0 < B"
   1.238 +    and norm_Y: "\<And>n. norm (Y n) \<le> B"
   1.239 +    using Y [unfolded Bseq_def] by fast
   1.240 +  from X show ?thesis
   1.241 +  proof (rule Zseq_imp_Zseq)
   1.242 +    fix n::nat
   1.243 +    have "norm (X n ** Y n) \<le> norm (X n) * norm (Y n) * K"
   1.244 +      by (rule norm_le)
   1.245 +    also have "\<dots> \<le> norm (X n) * B * K"
   1.246 +      by (intro mult_mono' order_refl norm_Y norm_ge_zero
   1.247 +                mult_nonneg_nonneg K)
   1.248 +    also have "\<dots> = norm (X n) * (B * K)"
   1.249 +      by (rule mult_assoc)
   1.250 +    finally show "norm (X n ** Y n) \<le> norm (X n) * (B * K)" .
   1.251 +  qed
   1.252 +qed
   1.253 +
   1.254 +lemma (in bounded_bilinear) Bseq_prod_Zseq:
   1.255 +  assumes X: "Bseq X"
   1.256 +  assumes Y: "Zseq Y"
   1.257 +  shows "Zseq (\<lambda>n. X n ** Y n)"
   1.258 +proof -
   1.259 +  obtain K where K: "0 \<le> K"
   1.260 +    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   1.261 +    using nonneg_bounded by fast
   1.262 +  obtain B where B: "0 < B"
   1.263 +    and norm_X: "\<And>n. norm (X n) \<le> B"
   1.264 +    using X [unfolded Bseq_def] by fast
   1.265 +  from Y show ?thesis
   1.266 +  proof (rule Zseq_imp_Zseq)
   1.267 +    fix n::nat
   1.268 +    have "norm (X n ** Y n) \<le> norm (X n) * norm (Y n) * K"
   1.269 +      by (rule norm_le)
   1.270 +    also have "\<dots> \<le> B * norm (Y n) * K"
   1.271 +      by (intro mult_mono' order_refl norm_X norm_ge_zero
   1.272 +                mult_nonneg_nonneg K)
   1.273 +    also have "\<dots> = norm (Y n) * (B * K)"
   1.274 +      by (simp only: mult_ac)
   1.275 +    finally show "norm (X n ** Y n) \<le> norm (Y n) * (B * K)" .
   1.276 +  qed
   1.277 +qed
   1.278 +
   1.279 +lemma (in bounded_bilinear) Zseq_left:
   1.280 +  "Zseq X \<Longrightarrow> Zseq (\<lambda>n. X n ** a)"
   1.281 +by (rule bounded_linear_left [THEN bounded_linear.Zseq])
   1.282 +
   1.283 +lemma (in bounded_bilinear) Zseq_right:
   1.284 +  "Zseq X \<Longrightarrow> Zseq (\<lambda>n. a ** X n)"
   1.285 +by (rule bounded_linear_right [THEN bounded_linear.Zseq])
   1.286 +
   1.287 +lemmas Zseq_mult = mult.Zseq
   1.288 +lemmas Zseq_mult_right = mult.Zseq_right
   1.289 +lemmas Zseq_mult_left = mult.Zseq_left
   1.290 +
   1.291 +
   1.292 +subsection {* Limits of Sequences *}
   1.293 +
   1.294 +lemma LIMSEQ_iff:
   1.295 +      "(X ----> L) = (\<forall>r>0. \<exists>no. \<forall>n \<ge> no. norm (X n - L) < r)"
   1.296 +by (rule LIMSEQ_def)
   1.297 +
   1.298 +lemma LIMSEQ_Zseq_iff: "((\<lambda>n. X n) ----> L) = Zseq (\<lambda>n. X n - L)"
   1.299 +by (simp only: LIMSEQ_def Zseq_def)
   1.300 +
   1.301 +lemma LIMSEQ_I:
   1.302 +  "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n - L) < r) \<Longrightarrow> X ----> L"
   1.303 +by (simp add: LIMSEQ_def)
   1.304 +
   1.305 +lemma LIMSEQ_D:
   1.306 +  "\<lbrakk>X ----> L; 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n - L) < r"
   1.307 +by (simp add: LIMSEQ_def)
   1.308 +
   1.309 +lemma LIMSEQ_const: "(\<lambda>n. k) ----> k"
   1.310 +by (simp add: LIMSEQ_def)
   1.311 +
   1.312 +lemma LIMSEQ_const_iff: "(\<lambda>n. k) ----> l = (k = l)"
   1.313 +by (simp add: LIMSEQ_Zseq_iff Zseq_const_iff)
   1.314 +
   1.315 +lemma LIMSEQ_norm: "X ----> a \<Longrightarrow> (\<lambda>n. norm (X n)) ----> norm a"
   1.316 +apply (simp add: LIMSEQ_def, safe)
   1.317 +apply (drule_tac x="r" in spec, safe)
   1.318 +apply (rule_tac x="no" in exI, safe)
   1.319 +apply (drule_tac x="n" in spec, safe)
   1.320 +apply (erule order_le_less_trans [OF norm_triangle_ineq3])
   1.321 +done
   1.322 +
   1.323 +lemma LIMSEQ_ignore_initial_segment:
   1.324 +  "f ----> a \<Longrightarrow> (\<lambda>n. f (n + k)) ----> a"
   1.325 +apply (rule LIMSEQ_I)
   1.326 +apply (drule (1) LIMSEQ_D)
   1.327 +apply (erule exE, rename_tac N)
   1.328 +apply (rule_tac x=N in exI)
   1.329 +apply simp
   1.330 +done
   1.331 +
   1.332 +lemma LIMSEQ_offset:
   1.333 +  "(\<lambda>n. f (n + k)) ----> a \<Longrightarrow> f ----> a"
   1.334 +apply (rule LIMSEQ_I)
   1.335 +apply (drule (1) LIMSEQ_D)
   1.336 +apply (erule exE, rename_tac N)
   1.337 +apply (rule_tac x="N + k" in exI)
   1.338 +apply clarify
   1.339 +apply (drule_tac x="n - k" in spec)
   1.340 +apply (simp add: le_diff_conv2)
   1.341 +done
   1.342 +
   1.343 +lemma LIMSEQ_Suc: "f ----> l \<Longrightarrow> (\<lambda>n. f (Suc n)) ----> l"
   1.344 +by (drule_tac k="1" in LIMSEQ_ignore_initial_segment, simp)
   1.345 +
   1.346 +lemma LIMSEQ_imp_Suc: "(\<lambda>n. f (Suc n)) ----> l \<Longrightarrow> f ----> l"
   1.347 +by (rule_tac k="1" in LIMSEQ_offset, simp)
   1.348 +
   1.349 +lemma LIMSEQ_Suc_iff: "(\<lambda>n. f (Suc n)) ----> l = f ----> l"
   1.350 +by (blast intro: LIMSEQ_imp_Suc LIMSEQ_Suc)
   1.351 +
   1.352 +lemma add_diff_add:
   1.353 +  fixes a b c d :: "'a::ab_group_add"
   1.354 +  shows "(a + c) - (b + d) = (a - b) + (c - d)"
   1.355 +by simp
   1.356 +
   1.357 +lemma minus_diff_minus:
   1.358 +  fixes a b :: "'a::ab_group_add"
   1.359 +  shows "(- a) - (- b) = - (a - b)"
   1.360 +by simp
   1.361 +
   1.362 +lemma LIMSEQ_add: "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) ----> a + b"
   1.363 +by (simp only: LIMSEQ_Zseq_iff add_diff_add Zseq_add)
   1.364 +
   1.365 +lemma LIMSEQ_minus: "X ----> a \<Longrightarrow> (\<lambda>n. - X n) ----> - a"
   1.366 +by (simp only: LIMSEQ_Zseq_iff minus_diff_minus Zseq_minus)
   1.367 +
   1.368 +lemma LIMSEQ_minus_cancel: "(\<lambda>n. - X n) ----> - a \<Longrightarrow> X ----> a"
   1.369 +by (drule LIMSEQ_minus, simp)
   1.370 +
   1.371 +lemma LIMSEQ_diff: "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) ----> a - b"
   1.372 +by (simp add: diff_minus LIMSEQ_add LIMSEQ_minus)
   1.373 +
   1.374 +lemma LIMSEQ_unique: "\<lbrakk>X ----> a; X ----> b\<rbrakk> \<Longrightarrow> a = b"
   1.375 +by (drule (1) LIMSEQ_diff, simp add: LIMSEQ_const_iff)
   1.376 +
   1.377 +lemma (in bounded_linear) LIMSEQ:
   1.378 +  "X ----> a \<Longrightarrow> (\<lambda>n. f (X n)) ----> f a"
   1.379 +by (simp only: LIMSEQ_Zseq_iff diff [symmetric] Zseq)
   1.380 +
   1.381 +lemma (in bounded_bilinear) LIMSEQ:
   1.382 +  "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n ** Y n) ----> a ** b"
   1.383 +by (simp only: LIMSEQ_Zseq_iff prod_diff_prod
   1.384 +               Zseq_add Zseq Zseq_left Zseq_right)
   1.385 +
   1.386 +lemma LIMSEQ_mult:
   1.387 +  fixes a b :: "'a::real_normed_algebra"
   1.388 +  shows "[| X ----> a; Y ----> b |] ==> (%n. X n * Y n) ----> a * b"
   1.389 +by (rule mult.LIMSEQ)
   1.390 +
   1.391 +lemma inverse_diff_inverse:
   1.392 +  "\<lbrakk>(a::'a::division_ring) \<noteq> 0; b \<noteq> 0\<rbrakk>
   1.393 +   \<Longrightarrow> inverse a - inverse b = - (inverse a * (a - b) * inverse b)"
   1.394 +by (simp add: ring_simps)
   1.395 +
   1.396 +lemma Bseq_inverse_lemma:
   1.397 +  fixes x :: "'a::real_normed_div_algebra"
   1.398 +  shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
   1.399 +apply (subst nonzero_norm_inverse, clarsimp)
   1.400 +apply (erule (1) le_imp_inverse_le)
   1.401 +done
   1.402 +
   1.403 +lemma Bseq_inverse:
   1.404 +  fixes a :: "'a::real_normed_div_algebra"
   1.405 +  assumes X: "X ----> a"
   1.406 +  assumes a: "a \<noteq> 0"
   1.407 +  shows "Bseq (\<lambda>n. inverse (X n))"
   1.408 +proof -
   1.409 +  from a have "0 < norm a" by simp
   1.410 +  hence "\<exists>r>0. r < norm a" by (rule dense)
   1.411 +  then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
   1.412 +  obtain N where N: "\<And>n. N \<le> n \<Longrightarrow> norm (X n - a) < r"
   1.413 +    using LIMSEQ_D [OF X r1] by fast
   1.414 +  show ?thesis
   1.415 +  proof (rule BseqI2' [rule_format])
   1.416 +    fix n assume n: "N \<le> n"
   1.417 +    hence 1: "norm (X n - a) < r" by (rule N)
   1.418 +    hence 2: "X n \<noteq> 0" using r2 by auto
   1.419 +    hence "norm (inverse (X n)) = inverse (norm (X n))"
   1.420 +      by (rule nonzero_norm_inverse)
   1.421 +    also have "\<dots> \<le> inverse (norm a - r)"
   1.422 +    proof (rule le_imp_inverse_le)
   1.423 +      show "0 < norm a - r" using r2 by simp
   1.424 +    next
   1.425 +      have "norm a - norm (X n) \<le> norm (a - X n)"
   1.426 +        by (rule norm_triangle_ineq2)
   1.427 +      also have "\<dots> = norm (X n - a)"
   1.428 +        by (rule norm_minus_commute)
   1.429 +      also have "\<dots> < r" using 1 .
   1.430 +      finally show "norm a - r \<le> norm (X n)" by simp
   1.431 +    qed
   1.432 +    finally show "norm (inverse (X n)) \<le> inverse (norm a - r)" .
   1.433 +  qed
   1.434 +qed
   1.435 +
   1.436 +lemma LIMSEQ_inverse_lemma:
   1.437 +  fixes a :: "'a::real_normed_div_algebra"
   1.438 +  shows "\<lbrakk>X ----> a; a \<noteq> 0; \<forall>n. X n \<noteq> 0\<rbrakk>
   1.439 +         \<Longrightarrow> (\<lambda>n. inverse (X n)) ----> inverse a"
   1.440 +apply (subst LIMSEQ_Zseq_iff)
   1.441 +apply (simp add: inverse_diff_inverse nonzero_imp_inverse_nonzero)
   1.442 +apply (rule Zseq_minus)
   1.443 +apply (rule Zseq_mult_left)
   1.444 +apply (rule mult.Bseq_prod_Zseq)
   1.445 +apply (erule (1) Bseq_inverse)
   1.446 +apply (simp add: LIMSEQ_Zseq_iff)
   1.447 +done
   1.448 +
   1.449 +lemma LIMSEQ_inverse:
   1.450 +  fixes a :: "'a::real_normed_div_algebra"
   1.451 +  assumes X: "X ----> a"
   1.452 +  assumes a: "a \<noteq> 0"
   1.453 +  shows "(\<lambda>n. inverse (X n)) ----> inverse a"
   1.454 +proof -
   1.455 +  from a have "0 < norm a" by simp
   1.456 +  then obtain k where "\<forall>n\<ge>k. norm (X n - a) < norm a"
   1.457 +    using LIMSEQ_D [OF X] by fast
   1.458 +  hence "\<forall>n\<ge>k. X n \<noteq> 0" by auto
   1.459 +  hence k: "\<forall>n. X (n + k) \<noteq> 0" by simp
   1.460 +
   1.461 +  from X have "(\<lambda>n. X (n + k)) ----> a"
   1.462 +    by (rule LIMSEQ_ignore_initial_segment)
   1.463 +  hence "(\<lambda>n. inverse (X (n + k))) ----> inverse a"
   1.464 +    using a k by (rule LIMSEQ_inverse_lemma)
   1.465 +  thus "(\<lambda>n. inverse (X n)) ----> inverse a"
   1.466 +    by (rule LIMSEQ_offset)
   1.467 +qed
   1.468 +
   1.469 +lemma LIMSEQ_divide:
   1.470 +  fixes a b :: "'a::real_normed_field"
   1.471 +  shows "\<lbrakk>X ----> a; Y ----> b; b \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>n. X n / Y n) ----> a / b"
   1.472 +by (simp add: LIMSEQ_mult LIMSEQ_inverse divide_inverse)
   1.473 +
   1.474 +lemma LIMSEQ_pow:
   1.475 +  fixes a :: "'a::{real_normed_algebra,recpower}"
   1.476 +  shows "X ----> a \<Longrightarrow> (\<lambda>n. (X n) ^ m) ----> a ^ m"
   1.477 +by (induct m) (simp_all add: power_Suc LIMSEQ_const LIMSEQ_mult)
   1.478 +
   1.479 +lemma LIMSEQ_setsum:
   1.480 +  assumes n: "\<And>n. n \<in> S \<Longrightarrow> X n ----> L n"
   1.481 +  shows "(\<lambda>m. \<Sum>n\<in>S. X n m) ----> (\<Sum>n\<in>S. L n)"
   1.482 +proof (cases "finite S")
   1.483 +  case True
   1.484 +  thus ?thesis using n
   1.485 +  proof (induct)
   1.486 +    case empty
   1.487 +    show ?case
   1.488 +      by (simp add: LIMSEQ_const)
   1.489 +  next
   1.490 +    case insert
   1.491 +    thus ?case
   1.492 +      by (simp add: LIMSEQ_add)
   1.493 +  qed
   1.494 +next
   1.495 +  case False
   1.496 +  thus ?thesis
   1.497 +    by (simp add: LIMSEQ_const)
   1.498 +qed
   1.499 +
   1.500 +lemma LIMSEQ_setprod:
   1.501 +  fixes L :: "'a \<Rightarrow> 'b::{real_normed_algebra,comm_ring_1}"
   1.502 +  assumes n: "\<And>n. n \<in> S \<Longrightarrow> X n ----> L n"
   1.503 +  shows "(\<lambda>m. \<Prod>n\<in>S. X n m) ----> (\<Prod>n\<in>S. L n)"
   1.504 +proof (cases "finite S")
   1.505 +  case True
   1.506 +  thus ?thesis using n
   1.507 +  proof (induct)
   1.508 +    case empty
   1.509 +    show ?case
   1.510 +      by (simp add: LIMSEQ_const)
   1.511 +  next
   1.512 +    case insert
   1.513 +    thus ?case
   1.514 +      by (simp add: LIMSEQ_mult)
   1.515 +  qed
   1.516 +next
   1.517 +  case False
   1.518 +  thus ?thesis
   1.519 +    by (simp add: setprod_def LIMSEQ_const)
   1.520 +qed
   1.521 +
   1.522 +lemma LIMSEQ_add_const: "f ----> a ==> (%n.(f n + b)) ----> a + b"
   1.523 +by (simp add: LIMSEQ_add LIMSEQ_const)
   1.524 +
   1.525 +(* FIXME: delete *)
   1.526 +lemma LIMSEQ_add_minus:
   1.527 +     "[| X ----> a; Y ----> b |] ==> (%n. X n + -Y n) ----> a + -b"
   1.528 +by (simp only: LIMSEQ_add LIMSEQ_minus)
   1.529 +
   1.530 +lemma LIMSEQ_diff_const: "f ----> a ==> (%n.(f n  - b)) ----> a - b"
   1.531 +by (simp add: LIMSEQ_diff LIMSEQ_const)
   1.532 +
   1.533 +lemma LIMSEQ_diff_approach_zero: 
   1.534 +  "g ----> L ==> (%x. f x - g x) ----> 0  ==>
   1.535 +     f ----> L"
   1.536 +  apply (drule LIMSEQ_add)
   1.537 +  apply assumption
   1.538 +  apply simp
   1.539 +done
   1.540 +
   1.541 +lemma LIMSEQ_diff_approach_zero2: 
   1.542 +  "f ----> L ==> (%x. f x - g x) ----> 0  ==>
   1.543 +     g ----> L";
   1.544 +  apply (drule LIMSEQ_diff)
   1.545 +  apply assumption
   1.546 +  apply simp
   1.547 +done
   1.548 +
   1.549 +text{*A sequence tends to zero iff its abs does*}
   1.550 +lemma LIMSEQ_norm_zero: "((\<lambda>n. norm (X n)) ----> 0) = (X ----> 0)"
   1.551 +by (simp add: LIMSEQ_def)
   1.552 +
   1.553 +lemma LIMSEQ_rabs_zero: "((%n. \<bar>f n\<bar>) ----> 0) = (f ----> (0::real))"
   1.554 +by (simp add: LIMSEQ_def)
   1.555 +
   1.556 +lemma LIMSEQ_imp_rabs: "f ----> (l::real) ==> (%n. \<bar>f n\<bar>) ----> \<bar>l\<bar>"
   1.557 +by (drule LIMSEQ_norm, simp)
   1.558 +
   1.559 +text{*An unbounded sequence's inverse tends to 0*}
   1.560 +
   1.561 +lemma LIMSEQ_inverse_zero:
   1.562 +  "\<forall>r::real. \<exists>N. \<forall>n\<ge>N. r < X n \<Longrightarrow> (\<lambda>n. inverse (X n)) ----> 0"
   1.563 +apply (rule LIMSEQ_I)
   1.564 +apply (drule_tac x="inverse r" in spec, safe)
   1.565 +apply (rule_tac x="N" in exI, safe)
   1.566 +apply (drule_tac x="n" in spec, safe)
   1.567 +apply (frule positive_imp_inverse_positive)
   1.568 +apply (frule (1) less_imp_inverse_less)
   1.569 +apply (subgoal_tac "0 < X n", simp)
   1.570 +apply (erule (1) order_less_trans)
   1.571 +done
   1.572 +
   1.573 +text{*The sequence @{term "1/n"} tends to 0 as @{term n} tends to infinity*}
   1.574 +
   1.575 +lemma LIMSEQ_inverse_real_of_nat: "(%n. inverse(real(Suc n))) ----> 0"
   1.576 +apply (rule LIMSEQ_inverse_zero, safe)
   1.577 +apply (cut_tac x = r in reals_Archimedean2)
   1.578 +apply (safe, rule_tac x = n in exI)
   1.579 +apply (auto simp add: real_of_nat_Suc)
   1.580 +done
   1.581 +
   1.582 +text{*The sequence @{term "r + 1/n"} tends to @{term r} as @{term n} tends to
   1.583 +infinity is now easily proved*}
   1.584 +
   1.585 +lemma LIMSEQ_inverse_real_of_nat_add:
   1.586 +     "(%n. r + inverse(real(Suc n))) ----> r"
   1.587 +by (cut_tac LIMSEQ_add [OF LIMSEQ_const LIMSEQ_inverse_real_of_nat], auto)
   1.588 +
   1.589 +lemma LIMSEQ_inverse_real_of_nat_add_minus:
   1.590 +     "(%n. r + -inverse(real(Suc n))) ----> r"
   1.591 +by (cut_tac LIMSEQ_add_minus [OF LIMSEQ_const LIMSEQ_inverse_real_of_nat], auto)
   1.592 +
   1.593 +lemma LIMSEQ_inverse_real_of_nat_add_minus_mult:
   1.594 +     "(%n. r*( 1 + -inverse(real(Suc n)))) ----> r"
   1.595 +by (cut_tac b=1 in
   1.596 +        LIMSEQ_mult [OF LIMSEQ_const LIMSEQ_inverse_real_of_nat_add_minus], auto)
   1.597 +
   1.598 +lemma LIMSEQ_le_const:
   1.599 +  "\<lbrakk>X ----> (x::real); \<exists>N. \<forall>n\<ge>N. a \<le> X n\<rbrakk> \<Longrightarrow> a \<le> x"
   1.600 +apply (rule ccontr, simp only: linorder_not_le)
   1.601 +apply (drule_tac r="a - x" in LIMSEQ_D, simp)
   1.602 +apply clarsimp
   1.603 +apply (drule_tac x="max N no" in spec, drule mp, rule le_maxI1)
   1.604 +apply (drule_tac x="max N no" in spec, drule mp, rule le_maxI2)
   1.605 +apply simp
   1.606 +done
   1.607 +
   1.608 +lemma LIMSEQ_le_const2:
   1.609 +  "\<lbrakk>X ----> (x::real); \<exists>N. \<forall>n\<ge>N. X n \<le> a\<rbrakk> \<Longrightarrow> x \<le> a"
   1.610 +apply (subgoal_tac "- a \<le> - x", simp)
   1.611 +apply (rule LIMSEQ_le_const)
   1.612 +apply (erule LIMSEQ_minus)
   1.613 +apply simp
   1.614 +done
   1.615 +
   1.616 +lemma LIMSEQ_le:
   1.617 +  "\<lbrakk>X ----> x; Y ----> y; \<exists>N. \<forall>n\<ge>N. X n \<le> Y n\<rbrakk> \<Longrightarrow> x \<le> (y::real)"
   1.618 +apply (subgoal_tac "0 \<le> y - x", simp)
   1.619 +apply (rule LIMSEQ_le_const)
   1.620 +apply (erule (1) LIMSEQ_diff)
   1.621 +apply (simp add: le_diff_eq)
   1.622 +done
   1.623 +
   1.624 +
   1.625 +subsection {* Convergence *}
   1.626 +
   1.627 +lemma limI: "X ----> L ==> lim X = L"
   1.628 +apply (simp add: lim_def)
   1.629 +apply (blast intro: LIMSEQ_unique)
   1.630 +done
   1.631 +
   1.632 +lemma convergentD: "convergent X ==> \<exists>L. (X ----> L)"
   1.633 +by (simp add: convergent_def)
   1.634 +
   1.635 +lemma convergentI: "(X ----> L) ==> convergent X"
   1.636 +by (auto simp add: convergent_def)
   1.637 +
   1.638 +lemma convergent_LIMSEQ_iff: "convergent X = (X ----> lim X)"
   1.639 +by (auto intro: theI LIMSEQ_unique simp add: convergent_def lim_def)
   1.640 +
   1.641 +lemma convergent_minus_iff: "(convergent X) = (convergent (%n. -(X n)))"
   1.642 +apply (simp add: convergent_def)
   1.643 +apply (auto dest: LIMSEQ_minus)
   1.644 +apply (drule LIMSEQ_minus, auto)
   1.645 +done
   1.646 +
   1.647 +
   1.648 +subsection {* Bounded Monotonic Sequences *}
   1.649 +
   1.650 +text{*Subsequence (alternative definition, (e.g. Hoskins)*}
   1.651 +
   1.652 +lemma subseq_Suc_iff: "subseq f = (\<forall>n. (f n) < (f (Suc n)))"
   1.653 +apply (simp add: subseq_def)
   1.654 +apply (auto dest!: less_imp_Suc_add)
   1.655 +apply (induct_tac k)
   1.656 +apply (auto intro: less_trans)
   1.657 +done
   1.658 +
   1.659 +lemma monoseq_Suc:
   1.660 +   "monoseq X = ((\<forall>n. X n \<le> X (Suc n))
   1.661 +                 | (\<forall>n. X (Suc n) \<le> X n))"
   1.662 +apply (simp add: monoseq_def)
   1.663 +apply (auto dest!: le_imp_less_or_eq)
   1.664 +apply (auto intro!: lessI [THEN less_imp_le] dest!: less_imp_Suc_add)
   1.665 +apply (induct_tac "ka")
   1.666 +apply (auto intro: order_trans)
   1.667 +apply (erule contrapos_np)
   1.668 +apply (induct_tac "k")
   1.669 +apply (auto intro: order_trans)
   1.670 +done
   1.671 +
   1.672 +lemma monoI1: "\<forall>m. \<forall> n \<ge> m. X m \<le> X n ==> monoseq X"
   1.673 +by (simp add: monoseq_def)
   1.674 +
   1.675 +lemma monoI2: "\<forall>m. \<forall> n \<ge> m. X n \<le> X m ==> monoseq X"
   1.676 +by (simp add: monoseq_def)
   1.677 +
   1.678 +lemma mono_SucI1: "\<forall>n. X n \<le> X (Suc n) ==> monoseq X"
   1.679 +by (simp add: monoseq_Suc)
   1.680 +
   1.681 +lemma mono_SucI2: "\<forall>n. X (Suc n) \<le> X n ==> monoseq X"
   1.682 +by (simp add: monoseq_Suc)
   1.683 +
   1.684 +text{*Bounded Sequence*}
   1.685 +
   1.686 +lemma BseqD: "Bseq X ==> \<exists>K. 0 < K & (\<forall>n. norm (X n) \<le> K)"
   1.687 +by (simp add: Bseq_def)
   1.688 +
   1.689 +lemma BseqI: "[| 0 < K; \<forall>n. norm (X n) \<le> K |] ==> Bseq X"
   1.690 +by (auto simp add: Bseq_def)
   1.691 +
   1.692 +lemma lemma_NBseq_def:
   1.693 +     "(\<exists>K > 0. \<forall>n. norm (X n) \<le> K) =
   1.694 +      (\<exists>N. \<forall>n. norm (X n) \<le> real(Suc N))"
   1.695 +apply auto
   1.696 + prefer 2 apply force
   1.697 +apply (cut_tac x = K in reals_Archimedean2, clarify)
   1.698 +apply (rule_tac x = n in exI, clarify)
   1.699 +apply (drule_tac x = na in spec)
   1.700 +apply (auto simp add: real_of_nat_Suc)
   1.701 +done
   1.702 +
   1.703 +text{* alternative definition for Bseq *}
   1.704 +lemma Bseq_iff: "Bseq X = (\<exists>N. \<forall>n. norm (X n) \<le> real(Suc N))"
   1.705 +apply (simp add: Bseq_def)
   1.706 +apply (simp (no_asm) add: lemma_NBseq_def)
   1.707 +done
   1.708 +
   1.709 +lemma lemma_NBseq_def2:
   1.710 +     "(\<exists>K > 0. \<forall>n. norm (X n) \<le> K) = (\<exists>N. \<forall>n. norm (X n) < real(Suc N))"
   1.711 +apply (subst lemma_NBseq_def, auto)
   1.712 +apply (rule_tac x = "Suc N" in exI)
   1.713 +apply (rule_tac [2] x = N in exI)
   1.714 +apply (auto simp add: real_of_nat_Suc)
   1.715 + prefer 2 apply (blast intro: order_less_imp_le)
   1.716 +apply (drule_tac x = n in spec, simp)
   1.717 +done
   1.718 +
   1.719 +(* yet another definition for Bseq *)
   1.720 +lemma Bseq_iff1a: "Bseq X = (\<exists>N. \<forall>n. norm (X n) < real(Suc N))"
   1.721 +by (simp add: Bseq_def lemma_NBseq_def2)
   1.722 +
   1.723 +subsubsection{*Upper Bounds and Lubs of Bounded Sequences*}
   1.724 +
   1.725 +lemma Bseq_isUb:
   1.726 +  "!!(X::nat=>real). Bseq X ==> \<exists>U. isUb (UNIV::real set) {x. \<exists>n. X n = x} U"
   1.727 +by (auto intro: isUbI setleI simp add: Bseq_def abs_le_iff)
   1.728 +
   1.729 +
   1.730 +text{* Use completeness of reals (supremum property)
   1.731 +   to show that any bounded sequence has a least upper bound*}
   1.732 +
   1.733 +lemma Bseq_isLub:
   1.734 +  "!!(X::nat=>real). Bseq X ==>
   1.735 +   \<exists>U. isLub (UNIV::real set) {x. \<exists>n. X n = x} U"
   1.736 +by (blast intro: reals_complete Bseq_isUb)
   1.737 +
   1.738 +subsubsection{*A Bounded and Monotonic Sequence Converges*}
   1.739 +
   1.740 +lemma lemma_converg1:
   1.741 +     "!!(X::nat=>real). [| \<forall>m. \<forall> n \<ge> m. X m \<le> X n;
   1.742 +                  isLub (UNIV::real set) {x. \<exists>n. X n = x} (X ma)
   1.743 +               |] ==> \<forall>n \<ge> ma. X n = X ma"
   1.744 +apply safe
   1.745 +apply (drule_tac y = "X n" in isLubD2)
   1.746 +apply (blast dest: order_antisym)+
   1.747 +done
   1.748 +
   1.749 +text{* The best of both worlds: Easier to prove this result as a standard
   1.750 +   theorem and then use equivalence to "transfer" it into the
   1.751 +   equivalent nonstandard form if needed!*}
   1.752 +
   1.753 +lemma Bmonoseq_LIMSEQ: "\<forall>n. m \<le> n --> X n = X m ==> \<exists>L. (X ----> L)"
   1.754 +apply (simp add: LIMSEQ_def)
   1.755 +apply (rule_tac x = "X m" in exI, safe)
   1.756 +apply (rule_tac x = m in exI, safe)
   1.757 +apply (drule spec, erule impE, auto)
   1.758 +done
   1.759 +
   1.760 +lemma lemma_converg2:
   1.761 +   "!!(X::nat=>real).
   1.762 +    [| \<forall>m. X m ~= U;  isLub UNIV {x. \<exists>n. X n = x} U |] ==> \<forall>m. X m < U"
   1.763 +apply safe
   1.764 +apply (drule_tac y = "X m" in isLubD2)
   1.765 +apply (auto dest!: order_le_imp_less_or_eq)
   1.766 +done
   1.767 +
   1.768 +lemma lemma_converg3: "!!(X ::nat=>real). \<forall>m. X m \<le> U ==> isUb UNIV {x. \<exists>n. X n = x} U"
   1.769 +by (rule setleI [THEN isUbI], auto)
   1.770 +
   1.771 +text{* FIXME: @{term "U - T < U"} is redundant *}
   1.772 +lemma lemma_converg4: "!!(X::nat=> real).
   1.773 +               [| \<forall>m. X m ~= U;
   1.774 +                  isLub UNIV {x. \<exists>n. X n = x} U;
   1.775 +                  0 < T;
   1.776 +                  U + - T < U
   1.777 +               |] ==> \<exists>m. U + -T < X m & X m < U"
   1.778 +apply (drule lemma_converg2, assumption)
   1.779 +apply (rule ccontr, simp)
   1.780 +apply (simp add: linorder_not_less)
   1.781 +apply (drule lemma_converg3)
   1.782 +apply (drule isLub_le_isUb, assumption)
   1.783 +apply (auto dest: order_less_le_trans)
   1.784 +done
   1.785 +
   1.786 +text{*A standard proof of the theorem for monotone increasing sequence*}
   1.787 +
   1.788 +lemma Bseq_mono_convergent:
   1.789 +     "[| Bseq X; \<forall>m. \<forall>n \<ge> m. X m \<le> X n |] ==> convergent (X::nat=>real)"
   1.790 +apply (simp add: convergent_def)
   1.791 +apply (frule Bseq_isLub, safe)
   1.792 +apply (case_tac "\<exists>m. X m = U", auto)
   1.793 +apply (blast dest: lemma_converg1 Bmonoseq_LIMSEQ)
   1.794 +(* second case *)
   1.795 +apply (rule_tac x = U in exI)
   1.796 +apply (subst LIMSEQ_iff, safe)
   1.797 +apply (frule lemma_converg2, assumption)
   1.798 +apply (drule lemma_converg4, auto)
   1.799 +apply (rule_tac x = m in exI, safe)
   1.800 +apply (subgoal_tac "X m \<le> X n")
   1.801 + prefer 2 apply blast
   1.802 +apply (drule_tac x=n and P="%m. X m < U" in spec, arith)
   1.803 +done
   1.804 +
   1.805 +lemma Bseq_minus_iff: "Bseq (%n. -(X n)) = Bseq X"
   1.806 +by (simp add: Bseq_def)
   1.807 +
   1.808 +text{*Main monotonicity theorem*}
   1.809 +lemma Bseq_monoseq_convergent: "[| Bseq X; monoseq X |] ==> convergent X"
   1.810 +apply (simp add: monoseq_def, safe)
   1.811 +apply (rule_tac [2] convergent_minus_iff [THEN ssubst])
   1.812 +apply (drule_tac [2] Bseq_minus_iff [THEN ssubst])
   1.813 +apply (auto intro!: Bseq_mono_convergent)
   1.814 +done
   1.815 +
   1.816 +subsubsection{*A Few More Equivalence Theorems for Boundedness*}
   1.817 +
   1.818 +text{*alternative formulation for boundedness*}
   1.819 +lemma Bseq_iff2: "Bseq X = (\<exists>k > 0. \<exists>x. \<forall>n. norm (X(n) + -x) \<le> k)"
   1.820 +apply (unfold Bseq_def, safe)
   1.821 +apply (rule_tac [2] x = "k + norm x" in exI)
   1.822 +apply (rule_tac x = K in exI, simp)
   1.823 +apply (rule exI [where x = 0], auto)
   1.824 +apply (erule order_less_le_trans, simp)
   1.825 +apply (drule_tac x=n in spec, fold diff_def)
   1.826 +apply (drule order_trans [OF norm_triangle_ineq2])
   1.827 +apply simp
   1.828 +done
   1.829 +
   1.830 +text{*alternative formulation for boundedness*}
   1.831 +lemma Bseq_iff3: "Bseq X = (\<exists>k > 0. \<exists>N. \<forall>n. norm(X(n) + -X(N)) \<le> k)"
   1.832 +apply safe
   1.833 +apply (simp add: Bseq_def, safe)
   1.834 +apply (rule_tac x = "K + norm (X N)" in exI)
   1.835 +apply auto
   1.836 +apply (erule order_less_le_trans, simp)
   1.837 +apply (rule_tac x = N in exI, safe)
   1.838 +apply (drule_tac x = n in spec)
   1.839 +apply (rule order_trans [OF norm_triangle_ineq], simp)
   1.840 +apply (auto simp add: Bseq_iff2)
   1.841 +done
   1.842 +
   1.843 +lemma BseqI2: "(\<forall>n. k \<le> f n & f n \<le> (K::real)) ==> Bseq f"
   1.844 +apply (simp add: Bseq_def)
   1.845 +apply (rule_tac x = " (\<bar>k\<bar> + \<bar>K\<bar>) + 1" in exI, auto)
   1.846 +apply (drule_tac x = n in spec, arith)
   1.847 +done
   1.848 +
   1.849 +
   1.850 +subsection {* Cauchy Sequences *}
   1.851 +
   1.852 +lemma CauchyI:
   1.853 +  "(\<And>e. 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e) \<Longrightarrow> Cauchy X"
   1.854 +by (simp add: Cauchy_def)
   1.855 +
   1.856 +lemma CauchyD:
   1.857 +  "\<lbrakk>Cauchy X; 0 < e\<rbrakk> \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e"
   1.858 +by (simp add: Cauchy_def)
   1.859 +
   1.860 +subsubsection {* Cauchy Sequences are Bounded *}
   1.861 +
   1.862 +text{*A Cauchy sequence is bounded -- this is the standard
   1.863 +  proof mechanization rather than the nonstandard proof*}
   1.864 +
   1.865 +lemma lemmaCauchy: "\<forall>n \<ge> M. norm (X M - X n) < (1::real)
   1.866 +          ==>  \<forall>n \<ge> M. norm (X n :: 'a::real_normed_vector) < 1 + norm (X M)"
   1.867 +apply (clarify, drule spec, drule (1) mp)
   1.868 +apply (simp only: norm_minus_commute)
   1.869 +apply (drule order_le_less_trans [OF norm_triangle_ineq2])
   1.870 +apply simp
   1.871 +done
   1.872 +
   1.873 +lemma Cauchy_Bseq: "Cauchy X ==> Bseq X"
   1.874 +apply (simp add: Cauchy_def)
   1.875 +apply (drule spec, drule mp, rule zero_less_one, safe)
   1.876 +apply (drule_tac x="M" in spec, simp)
   1.877 +apply (drule lemmaCauchy)
   1.878 +apply (rule_tac k="M" in Bseq_offset)
   1.879 +apply (simp add: Bseq_def)
   1.880 +apply (rule_tac x="1 + norm (X M)" in exI)
   1.881 +apply (rule conjI, rule order_less_le_trans [OF zero_less_one], simp)
   1.882 +apply (simp add: order_less_imp_le)
   1.883 +done
   1.884 +
   1.885 +subsubsection {* Cauchy Sequences are Convergent *}
   1.886 +
   1.887 +axclass banach \<subseteq> real_normed_vector
   1.888 +  Cauchy_convergent: "Cauchy X \<Longrightarrow> convergent X"
   1.889 +
   1.890 +theorem LIMSEQ_imp_Cauchy:
   1.891 +  assumes X: "X ----> a" shows "Cauchy X"
   1.892 +proof (rule CauchyI)
   1.893 +  fix e::real assume "0 < e"
   1.894 +  hence "0 < e/2" by simp
   1.895 +  with X have "\<exists>N. \<forall>n\<ge>N. norm (X n - a) < e/2" by (rule LIMSEQ_D)
   1.896 +  then obtain N where N: "\<forall>n\<ge>N. norm (X n - a) < e/2" ..
   1.897 +  show "\<exists>N. \<forall>m\<ge>N. \<forall>n\<ge>N. norm (X m - X n) < e"
   1.898 +  proof (intro exI allI impI)
   1.899 +    fix m assume "N \<le> m"
   1.900 +    hence m: "norm (X m - a) < e/2" using N by fast
   1.901 +    fix n assume "N \<le> n"
   1.902 +    hence n: "norm (X n - a) < e/2" using N by fast
   1.903 +    have "norm (X m - X n) = norm ((X m - a) - (X n - a))" by simp
   1.904 +    also have "\<dots> \<le> norm (X m - a) + norm (X n - a)"
   1.905 +      by (rule norm_triangle_ineq4)
   1.906 +    also from m n have "\<dots> < e" by(simp add:field_simps)
   1.907 +    finally show "norm (X m - X n) < e" .
   1.908 +  qed
   1.909 +qed
   1.910 +
   1.911 +lemma convergent_Cauchy: "convergent X \<Longrightarrow> Cauchy X"
   1.912 +unfolding convergent_def
   1.913 +by (erule exE, erule LIMSEQ_imp_Cauchy)
   1.914 +
   1.915 +text {*
   1.916 +Proof that Cauchy sequences converge based on the one from
   1.917 +http://pirate.shu.edu/~wachsmut/ira/numseq/proofs/cauconv.html
   1.918 +*}
   1.919 +
   1.920 +text {*
   1.921 +  If sequence @{term "X"} is Cauchy, then its limit is the lub of
   1.922 +  @{term "{r::real. \<exists>N. \<forall>n\<ge>N. r < X n}"}
   1.923 +*}
   1.924 +
   1.925 +lemma isUb_UNIV_I: "(\<And>y. y \<in> S \<Longrightarrow> y \<le> u) \<Longrightarrow> isUb UNIV S u"
   1.926 +by (simp add: isUbI setleI)
   1.927 +
   1.928 +lemma real_abs_diff_less_iff:
   1.929 +  "(\<bar>x - a\<bar> < (r::real)) = (a - r < x \<and> x < a + r)"
   1.930 +by auto
   1.931 +
   1.932 +locale real_Cauchy =
   1.933 +  fixes X :: "nat \<Rightarrow> real"
   1.934 +  assumes X: "Cauchy X"
   1.935 +  fixes S :: "real set"
   1.936 +  defines S_def: "S \<equiv> {x::real. \<exists>N. \<forall>n\<ge>N. x < X n}"
   1.937 +
   1.938 +lemma real_CauchyI:
   1.939 +  assumes "Cauchy X"
   1.940 +  shows "real_Cauchy X"
   1.941 +  proof qed (fact assms)
   1.942 +
   1.943 +lemma (in real_Cauchy) mem_S: "\<forall>n\<ge>N. x < X n \<Longrightarrow> x \<in> S"
   1.944 +by (unfold S_def, auto)
   1.945 +
   1.946 +lemma (in real_Cauchy) bound_isUb:
   1.947 +  assumes N: "\<forall>n\<ge>N. X n < x"
   1.948 +  shows "isUb UNIV S x"
   1.949 +proof (rule isUb_UNIV_I)
   1.950 +  fix y::real assume "y \<in> S"
   1.951 +  hence "\<exists>M. \<forall>n\<ge>M. y < X n"
   1.952 +    by (simp add: S_def)
   1.953 +  then obtain M where "\<forall>n\<ge>M. y < X n" ..
   1.954 +  hence "y < X (max M N)" by simp
   1.955 +  also have "\<dots> < x" using N by simp
   1.956 +  finally show "y \<le> x"
   1.957 +    by (rule order_less_imp_le)
   1.958 +qed
   1.959 +
   1.960 +lemma (in real_Cauchy) isLub_ex: "\<exists>u. isLub UNIV S u"
   1.961 +proof (rule reals_complete)
   1.962 +  obtain N where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (X m - X n) < 1"
   1.963 +    using CauchyD [OF X zero_less_one] by fast
   1.964 +  hence N: "\<forall>n\<ge>N. norm (X n - X N) < 1" by simp
   1.965 +  show "\<exists>x. x \<in> S"
   1.966 +  proof
   1.967 +    from N have "\<forall>n\<ge>N. X N - 1 < X n"
   1.968 +      by (simp add: real_abs_diff_less_iff)
   1.969 +    thus "X N - 1 \<in> S" by (rule mem_S)
   1.970 +  qed
   1.971 +  show "\<exists>u. isUb UNIV S u"
   1.972 +  proof
   1.973 +    from N have "\<forall>n\<ge>N. X n < X N + 1"
   1.974 +      by (simp add: real_abs_diff_less_iff)
   1.975 +    thus "isUb UNIV S (X N + 1)"
   1.976 +      by (rule bound_isUb)
   1.977 +  qed
   1.978 +qed
   1.979 +
   1.980 +lemma (in real_Cauchy) isLub_imp_LIMSEQ:
   1.981 +  assumes x: "isLub UNIV S x"
   1.982 +  shows "X ----> x"
   1.983 +proof (rule LIMSEQ_I)
   1.984 +  fix r::real assume "0 < r"
   1.985 +  hence r: "0 < r/2" by simp
   1.986 +  obtain N where "\<forall>n\<ge>N. \<forall>m\<ge>N. norm (X n - X m) < r/2"
   1.987 +    using CauchyD [OF X r] by fast
   1.988 +  hence "\<forall>n\<ge>N. norm (X n - X N) < r/2" by simp
   1.989 +  hence N: "\<forall>n\<ge>N. X N - r/2 < X n \<and> X n < X N + r/2"
   1.990 +    by (simp only: real_norm_def real_abs_diff_less_iff)
   1.991 +
   1.992 +  from N have "\<forall>n\<ge>N. X N - r/2 < X n" by fast
   1.993 +  hence "X N - r/2 \<in> S" by (rule mem_S)
   1.994 +  hence 1: "X N - r/2 \<le> x" using x isLub_isUb isUbD by fast
   1.995 +
   1.996 +  from N have "\<forall>n\<ge>N. X n < X N + r/2" by fast
   1.997 +  hence "isUb UNIV S (X N + r/2)" by (rule bound_isUb)
   1.998 +  hence 2: "x \<le> X N + r/2" using x isLub_le_isUb by fast
   1.999 +
  1.1000 +  show "\<exists>N. \<forall>n\<ge>N. norm (X n - x) < r"
  1.1001 +  proof (intro exI allI impI)
  1.1002 +    fix n assume n: "N \<le> n"
  1.1003 +    from N n have "X n < X N + r/2" and "X N - r/2 < X n" by simp+
  1.1004 +    thus "norm (X n - x) < r" using 1 2
  1.1005 +      by (simp add: real_abs_diff_less_iff)
  1.1006 +  qed
  1.1007 +qed
  1.1008 +
  1.1009 +lemma (in real_Cauchy) LIMSEQ_ex: "\<exists>x. X ----> x"
  1.1010 +proof -
  1.1011 +  obtain x where "isLub UNIV S x"
  1.1012 +    using isLub_ex by fast
  1.1013 +  hence "X ----> x"
  1.1014 +    by (rule isLub_imp_LIMSEQ)
  1.1015 +  thus ?thesis ..
  1.1016 +qed
  1.1017 +
  1.1018 +lemma real_Cauchy_convergent:
  1.1019 +  fixes X :: "nat \<Rightarrow> real"
  1.1020 +  shows "Cauchy X \<Longrightarrow> convergent X"
  1.1021 +unfolding convergent_def
  1.1022 +by (rule real_Cauchy.LIMSEQ_ex)
  1.1023 + (rule real_CauchyI)
  1.1024 +
  1.1025 +instance real :: banach
  1.1026 +by intro_classes (rule real_Cauchy_convergent)
  1.1027 +
  1.1028 +lemma Cauchy_convergent_iff:
  1.1029 +  fixes X :: "nat \<Rightarrow> 'a::banach"
  1.1030 +  shows "Cauchy X = convergent X"
  1.1031 +by (fast intro: Cauchy_convergent convergent_Cauchy)
  1.1032 +
  1.1033 +
  1.1034 +subsection {* Power Sequences *}
  1.1035 +
  1.1036 +text{*The sequence @{term "x^n"} tends to 0 if @{term "0\<le>x"} and @{term
  1.1037 +"x<1"}.  Proof will use (NS) Cauchy equivalence for convergence and
  1.1038 +  also fact that bounded and monotonic sequence converges.*}
  1.1039 +
  1.1040 +lemma Bseq_realpow: "[| 0 \<le> (x::real); x \<le> 1 |] ==> Bseq (%n. x ^ n)"
  1.1041 +apply (simp add: Bseq_def)
  1.1042 +apply (rule_tac x = 1 in exI)
  1.1043 +apply (simp add: power_abs)
  1.1044 +apply (auto dest: power_mono)
  1.1045 +done
  1.1046 +
  1.1047 +lemma monoseq_realpow: "[| 0 \<le> x; x \<le> 1 |] ==> monoseq (%n. x ^ n)"
  1.1048 +apply (clarify intro!: mono_SucI2)
  1.1049 +apply (cut_tac n = n and N = "Suc n" and a = x in power_decreasing, auto)
  1.1050 +done
  1.1051 +
  1.1052 +lemma convergent_realpow:
  1.1053 +  "[| 0 \<le> (x::real); x \<le> 1 |] ==> convergent (%n. x ^ n)"
  1.1054 +by (blast intro!: Bseq_monoseq_convergent Bseq_realpow monoseq_realpow)
  1.1055 +
  1.1056 +lemma LIMSEQ_inverse_realpow_zero_lemma:
  1.1057 +  fixes x :: real
  1.1058 +  assumes x: "0 \<le> x"
  1.1059 +  shows "real n * x + 1 \<le> (x + 1) ^ n"
  1.1060 +apply (induct n)
  1.1061 +apply simp
  1.1062 +apply simp
  1.1063 +apply (rule order_trans)
  1.1064 +prefer 2
  1.1065 +apply (erule mult_left_mono)
  1.1066 +apply (rule add_increasing [OF x], simp)
  1.1067 +apply (simp add: real_of_nat_Suc)
  1.1068 +apply (simp add: ring_distribs)
  1.1069 +apply (simp add: mult_nonneg_nonneg x)
  1.1070 +done
  1.1071 +
  1.1072 +lemma LIMSEQ_inverse_realpow_zero:
  1.1073 +  "1 < (x::real) \<Longrightarrow> (\<lambda>n. inverse (x ^ n)) ----> 0"
  1.1074 +proof (rule LIMSEQ_inverse_zero [rule_format])
  1.1075 +  fix y :: real
  1.1076 +  assume x: "1 < x"
  1.1077 +  hence "0 < x - 1" by simp
  1.1078 +  hence "\<forall>y. \<exists>N::nat. y < real N * (x - 1)"
  1.1079 +    by (rule reals_Archimedean3)
  1.1080 +  hence "\<exists>N::nat. y < real N * (x - 1)" ..
  1.1081 +  then obtain N::nat where "y < real N * (x - 1)" ..
  1.1082 +  also have "\<dots> \<le> real N * (x - 1) + 1" by simp
  1.1083 +  also have "\<dots> \<le> (x - 1 + 1) ^ N"
  1.1084 +    by (rule LIMSEQ_inverse_realpow_zero_lemma, cut_tac x, simp)
  1.1085 +  also have "\<dots> = x ^ N" by simp
  1.1086 +  finally have "y < x ^ N" .
  1.1087 +  hence "\<forall>n\<ge>N. y < x ^ n"
  1.1088 +    apply clarify
  1.1089 +    apply (erule order_less_le_trans)
  1.1090 +    apply (erule power_increasing)
  1.1091 +    apply (rule order_less_imp_le [OF x])
  1.1092 +    done
  1.1093 +  thus "\<exists>N. \<forall>n\<ge>N. y < x ^ n" ..
  1.1094 +qed
  1.1095 +
  1.1096 +lemma LIMSEQ_realpow_zero:
  1.1097 +  "\<lbrakk>0 \<le> (x::real); x < 1\<rbrakk> \<Longrightarrow> (\<lambda>n. x ^ n) ----> 0"
  1.1098 +proof (cases)
  1.1099 +  assume "x = 0"
  1.1100 +  hence "(\<lambda>n. x ^ Suc n) ----> 0" by (simp add: LIMSEQ_const)
  1.1101 +  thus ?thesis by (rule LIMSEQ_imp_Suc)
  1.1102 +next
  1.1103 +  assume "0 \<le> x" and "x \<noteq> 0"
  1.1104 +  hence x0: "0 < x" by simp
  1.1105 +  assume x1: "x < 1"
  1.1106 +  from x0 x1 have "1 < inverse x"
  1.1107 +    by (rule real_inverse_gt_one)
  1.1108 +  hence "(\<lambda>n. inverse (inverse x ^ n)) ----> 0"
  1.1109 +    by (rule LIMSEQ_inverse_realpow_zero)
  1.1110 +  thus ?thesis by (simp add: power_inverse)
  1.1111 +qed
  1.1112 +
  1.1113 +lemma LIMSEQ_power_zero:
  1.1114 +  fixes x :: "'a::{real_normed_algebra_1,recpower}"
  1.1115 +  shows "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) ----> 0"
  1.1116 +apply (drule LIMSEQ_realpow_zero [OF norm_ge_zero])
  1.1117 +apply (simp only: LIMSEQ_Zseq_iff, erule Zseq_le)
  1.1118 +apply (simp add: power_abs norm_power_ineq)
  1.1119 +done
  1.1120 +
  1.1121 +lemma LIMSEQ_divide_realpow_zero:
  1.1122 +  "1 < (x::real) ==> (%n. a / (x ^ n)) ----> 0"
  1.1123 +apply (cut_tac a = a and x1 = "inverse x" in
  1.1124 +        LIMSEQ_mult [OF LIMSEQ_const LIMSEQ_realpow_zero])
  1.1125 +apply (auto simp add: divide_inverse power_inverse)
  1.1126 +apply (simp add: inverse_eq_divide pos_divide_less_eq)
  1.1127 +done
  1.1128 +
  1.1129 +text{*Limit of @{term "c^n"} for @{term"\<bar>c\<bar> < 1"}*}
  1.1130 +
  1.1131 +lemma LIMSEQ_rabs_realpow_zero: "\<bar>c\<bar> < (1::real) ==> (%n. \<bar>c\<bar> ^ n) ----> 0"
  1.1132 +by (rule LIMSEQ_realpow_zero [OF abs_ge_zero])
  1.1133 +
  1.1134 +lemma LIMSEQ_rabs_realpow_zero2: "\<bar>c\<bar> < (1::real) ==> (%n. c ^ n) ----> 0"
  1.1135 +apply (rule LIMSEQ_rabs_zero [THEN iffD1])
  1.1136 +apply (auto intro: LIMSEQ_rabs_realpow_zero simp add: power_abs)
  1.1137 +done
  1.1138 +
  1.1139 +end