cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
authorhoelzl
Tue Mar 18 15:53:48 2014 +0100 (2014-03-18)
changeset 56193c726ecfb22b6
parent 56192 d666cb0e4cf9
child 56194 9ffbb4004c81
cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
src/HOL/MacLaurin.thy
src/HOL/Multivariate_Analysis/Cartesian_Euclidean_Space.thy
src/HOL/Multivariate_Analysis/Derivative.thy
src/HOL/Multivariate_Analysis/Integration.thy
src/HOL/Probability/Lebesgue_Integration.thy
src/HOL/Probability/Lebesgue_Measure.thy
src/HOL/Probability/Measure_Space.thy
src/HOL/Probability/Projective_Limit.thy
src/HOL/Probability/Regularity.thy
src/HOL/Series.thy
src/HOL/Set_Interval.thy
src/HOL/Taylor.thy
src/HOL/Transcendental.thy
     1.1 --- a/src/HOL/MacLaurin.thy	Tue Mar 18 14:32:23 2014 +0100
     1.2 +++ b/src/HOL/MacLaurin.thy	Tue Mar 18 15:53:48 2014 +0100
     1.3 @@ -17,10 +17,9 @@
     1.4  
     1.5  lemma Maclaurin_lemma:
     1.6      "0 < h ==>
     1.7 -     \<exists>B. f h = (\<Sum>m=0..<n. (j m / real (fact m)) * (h^m)) +
     1.8 +     \<exists>B. f h = (\<Sum>m<n. (j m / real (fact m)) * (h^m)) +
     1.9                 (B * ((h^n) / real(fact n)))"
    1.10 -by (rule exI[where x = "(f h - (\<Sum>m=0..<n. (j m / real (fact m)) * h^m)) *
    1.11 -                 real(fact n) / (h^n)"]) simp
    1.12 +by (rule exI[where x = "(f h - (\<Sum>m<n. (j m / real (fact m)) * h^m)) * real(fact n) / (h^n)"]) simp
    1.13  
    1.14  lemma eq_diff_eq': "(x = y - z) = (y = x + (z::real))"
    1.15  by arith
    1.16 @@ -33,20 +32,20 @@
    1.17    fixes B
    1.18    assumes DERIV : "\<forall>m t. m < n \<and> 0\<le>t \<and> t\<le>h \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t"
    1.19      and INIT : "n = Suc k"
    1.20 -  defines "difg \<equiv> (\<lambda>m t. diff m t - ((\<Sum>p = 0..<n - m. diff (m + p) 0 / real (fact p) * t ^ p) +
    1.21 +  defines "difg \<equiv> (\<lambda>m t. diff m t - ((\<Sum>p<n - m. diff (m + p) 0 / real (fact p) * t ^ p) +
    1.22      B * (t ^ (n - m) / real (fact (n - m)))))" (is "difg \<equiv> (\<lambda>m t. diff m t - ?difg m t)")
    1.23    shows "\<forall>m t. m < n & 0 \<le> t & t \<le> h --> DERIV (difg m) t :> difg (Suc m) t"
    1.24  proof (rule allI impI)+
    1.25    fix m t assume INIT2: "m < n & 0 \<le> t & t \<le> h"
    1.26    have "DERIV (difg m) t :> diff (Suc m) t -
    1.27 -    ((\<Sum>x = 0..<n - m. real x * t ^ (x - Suc 0) * diff (m + x) 0 / real (fact x)) +
    1.28 +    ((\<Sum>x<n - m. real x * t ^ (x - Suc 0) * diff (m + x) 0 / real (fact x)) +
    1.29       real (n - m) * t ^ (n - Suc m) * B / real (fact (n - m)))" unfolding difg_def
    1.30      by (auto intro!: DERIV_intros DERIV[rule_format, OF INIT2])
    1.31 -      moreover
    1.32 +  moreover
    1.33    from INIT2 have intvl: "{..<n - m} = insert 0 (Suc ` {..<n - Suc m})" and "0 < n - m"
    1.34      unfolding atLeast0LessThan[symmetric] by auto
    1.35 -  have "(\<Sum>x = 0..<n - m. real x * t ^ (x - Suc 0) * diff (m + x) 0 / real (fact x)) =
    1.36 -      (\<Sum>x = 0..<n - Suc m. real (Suc x) * t ^ x * diff (Suc m + x) 0 / real (fact (Suc x)))"
    1.37 +  have "(\<Sum>x<n - m. real x * t ^ (x - Suc 0) * diff (m + x) 0 / real (fact x)) =
    1.38 +      (\<Sum>x<n - Suc m. real (Suc x) * t ^ x * diff (Suc m + x) 0 / real (fact (Suc x)))"
    1.39      unfolding intvl atLeast0LessThan by (subst setsum.insert) (auto simp: setsum.reindex)
    1.40    moreover
    1.41    have fact_neq_0: "\<And>x::nat. real (fact x) + real x * real (fact x) \<noteq> 0"
    1.42 @@ -71,29 +70,26 @@
    1.43    shows
    1.44      "\<exists>t. 0 < t & t < h &
    1.45                f h =
    1.46 -              setsum (%m. (diff m 0 / real (fact m)) * h ^ m) {0..<n} +
    1.47 +              setsum (%m. (diff m 0 / real (fact m)) * h ^ m) {..<n} +
    1.48                (diff n t / real (fact n)) * h ^ n"
    1.49  proof -
    1.50    from n obtain m where m: "n = Suc m"
    1.51      by (cases n) (simp add: n)
    1.52  
    1.53    obtain B where f_h: "f h =
    1.54 -        (\<Sum>m = 0..<n. diff m (0\<Colon>real) / real (fact m) * h ^ m) +
    1.55 +        (\<Sum>m<n. diff m (0\<Colon>real) / real (fact m) * h ^ m) +
    1.56          B * (h ^ n / real (fact n))"
    1.57      using Maclaurin_lemma [OF h] ..
    1.58  
    1.59    def g \<equiv> "(\<lambda>t. f t -
    1.60 -    (setsum (\<lambda>m. (diff m 0 / real(fact m)) * t^m) {0..<n}
    1.61 +    (setsum (\<lambda>m. (diff m 0 / real(fact m)) * t^m) {..<n}
    1.62        + (B * (t^n / real(fact n)))))"
    1.63  
    1.64    have g2: "g 0 = 0 & g h = 0"
    1.65 -    apply (simp add: m f_h g_def del: setsum_op_ivl_Suc)
    1.66 -    apply (cut_tac n = m and k = "Suc 0" in sumr_offset2)
    1.67 -    apply (simp add: eq_diff_eq' diff_0 del: setsum_op_ivl_Suc)
    1.68 -    done
    1.69 +    by (simp add: m f_h g_def lessThan_Suc_eq_insert_0 image_iff diff_0 setsum_reindex)
    1.70  
    1.71    def difg \<equiv> "(%m t. diff m t -
    1.72 -    (setsum (%p. (diff (m + p) 0 / real (fact p)) * (t ^ p)) {0..<n-m}
    1.73 +    (setsum (%p. (diff (m + p) 0 / real (fact p)) * (t ^ p)) {..<n-m}
    1.74        + (B * ((t ^ (n - m)) / real (fact (n - m))))))"
    1.75  
    1.76    have difg_0: "difg 0 = g"
    1.77 @@ -103,14 +99,8 @@
    1.78          m < n \<and> (0\<Colon>real) \<le> t \<and> t \<le> h \<longrightarrow> DERIV (difg m) t :> difg (Suc m) t"
    1.79      using diff_Suc m unfolding difg_def by (rule Maclaurin_lemma2)
    1.80  
    1.81 -  have difg_eq_0: "\<forall>m. m < n --> difg m 0 = 0"
    1.82 -    apply clarify
    1.83 -    apply (simp add: m difg_def)
    1.84 -    apply (frule less_iff_Suc_add [THEN iffD1], clarify)
    1.85 -    apply (simp del: setsum_op_ivl_Suc)
    1.86 -    apply (insert sumr_offset4 [of "Suc 0"])
    1.87 -    apply (simp del: setsum_op_ivl_Suc fact_Suc)
    1.88 -    done
    1.89 +  have difg_eq_0: "\<forall>m<n. difg m 0 = 0"
    1.90 +    by (auto simp: difg_def m Suc_diff_le lessThan_Suc_eq_insert_0 image_iff setsum_reindex)
    1.91  
    1.92    have isCont_difg: "\<And>m x. \<lbrakk>m < n; 0 \<le> x; x \<le> h\<rbrakk> \<Longrightarrow> isCont (difg m) x"
    1.93      by (rule DERIV_isCont [OF difg_Suc [rule_format]]) simp
    1.94 @@ -166,7 +156,7 @@
    1.95      show "0 < t" by fact
    1.96      show "t < h" by fact
    1.97      show "f h =
    1.98 -      (\<Sum>m = 0..<n. diff m 0 / real (fact m) * h ^ m) +
    1.99 +      (\<Sum>m<n. diff m 0 / real (fact m) * h ^ m) +
   1.100        diff n t / real (fact n) * h ^ n"
   1.101        using `difg (Suc m) t = 0`
   1.102        by (simp add: m f_h difg_def del: fact_Suc)
   1.103 @@ -177,7 +167,7 @@
   1.104    "0 < h & n>0 & diff 0 = f &
   1.105    (\<forall>m t. m < n & 0 \<le> t & t \<le> h --> DERIV (diff m) t :> diff (Suc m) t)
   1.106     --> (\<exists>t. 0 < t & t < h &
   1.107 -            f h = (\<Sum>m=0..<n. diff m 0 / real (fact m) * h ^ m) +
   1.108 +            f h = (\<Sum>m<n. diff m 0 / real (fact m) * h ^ m) +
   1.109                    diff n t / real (fact n) * h ^ n)"
   1.110  by (blast intro: Maclaurin)
   1.111  
   1.112 @@ -187,7 +177,7 @@
   1.113    and DERIV: "\<forall>m t.
   1.114    m < n & 0 \<le> t & t \<le> h --> DERIV (diff m) t :> diff (Suc m) t"
   1.115    shows "\<exists>t. 0 < t \<and> t \<le> h \<and> f h =
   1.116 -  (\<Sum>m=0..<n. diff m 0 / real (fact m) * h ^ m) +
   1.117 +  (\<Sum>m<n. diff m 0 / real (fact m) * h ^ m) +
   1.118    diff n t / real (fact n) * h ^ n"
   1.119  proof (cases "n")
   1.120    case 0 with INIT1 INIT2 show ?thesis by fastforce
   1.121 @@ -196,7 +186,7 @@
   1.122    hence "n > 0" by simp
   1.123    from INIT1 this INIT2 DERIV have "\<exists>t>0. t < h \<and>
   1.124      f h =
   1.125 -    (\<Sum>m = 0..<n. diff m 0 / real (fact m) * h ^ m) + diff n t / real (fact n) * h ^ n"
   1.126 +    (\<Sum>m<n. diff m 0 / real (fact m) * h ^ m) + diff n t / real (fact n) * h ^ n"
   1.127      by (rule Maclaurin)
   1.128    thus ?thesis by fastforce
   1.129  qed
   1.130 @@ -208,7 +198,7 @@
   1.131      --> (\<exists>t. 0 < t &
   1.132                t \<le> h &
   1.133                f h =
   1.134 -              (\<Sum>m=0..<n. diff m 0 / real (fact m) * h ^ m) +
   1.135 +              (\<Sum>m<n. diff m 0 / real (fact m) * h ^ m) +
   1.136                diff n t / real (fact n) * h ^ n)"
   1.137  by (blast intro: Maclaurin2)
   1.138  
   1.139 @@ -216,7 +206,7 @@
   1.140    assumes "h < 0" "0 < n" "diff 0 = f"
   1.141    and DERIV: "\<forall>m t. m < n & h \<le> t & t \<le> 0 --> DERIV (diff m) t :> diff (Suc m) t"
   1.142    shows "\<exists>t. h < t & t < 0 &
   1.143 -         f h = (\<Sum>m=0..<n. diff m 0 / real (fact m) * h ^ m) +
   1.144 +         f h = (\<Sum>m<n. diff m 0 / real (fact m) * h ^ m) +
   1.145           diff n t / real (fact n) * h ^ n"
   1.146  proof -
   1.147    txt "Transform @{text ABL'} into @{text DERIV_intros} format."
   1.148 @@ -224,7 +214,7 @@
   1.149    from assms
   1.150    have "\<exists>t>0. t < - h \<and>
   1.151      f (- (- h)) =
   1.152 -    (\<Sum>m = 0..<n.
   1.153 +    (\<Sum>m<n.
   1.154      (- 1) ^ m * diff m (- 0) / real (fact m) * (- h) ^ m) +
   1.155      (- 1) ^ n * diff n (- t) / real (fact n) * (- h) ^ n"
   1.156      by (intro Maclaurin) (auto intro!: DERIV_intros DERIV')
   1.157 @@ -233,12 +223,12 @@
   1.158    have "-1 ^ n * diff n (- t) * (- h) ^ n / real (fact n) = diff n (- t) * h ^ n / real (fact n)"
   1.159      by (auto simp add: power_mult_distrib[symmetric])
   1.160    moreover
   1.161 -  have "(SUM m = 0..<n. -1 ^ m * diff m 0 * (- h) ^ m / real (fact m)) = (SUM m = 0..<n. diff m 0 * h ^ m / real (fact m))"
   1.162 +  have "(SUM m<n. -1 ^ m * diff m 0 * (- h) ^ m / real (fact m)) = (SUM m<n. diff m 0 * h ^ m / real (fact m))"
   1.163      by (auto intro: setsum_cong simp add: power_mult_distrib[symmetric])
   1.164    ultimately have " h < - t \<and>
   1.165      - t < 0 \<and>
   1.166      f h =
   1.167 -    (\<Sum>m = 0..<n. diff m 0 / real (fact m) * h ^ m) + diff n (- t) / real (fact n) * h ^ n"
   1.168 +    (\<Sum>m<n. diff m 0 / real (fact m) * h ^ m) + diff n (- t) / real (fact n) * h ^ n"
   1.169      by auto
   1.170    thus ?thesis ..
   1.171  qed
   1.172 @@ -250,7 +240,7 @@
   1.173      --> (\<exists>t. h < t &
   1.174                t < 0 &
   1.175                f h =
   1.176 -              (\<Sum>m=0..<n. diff m 0 / real (fact m) * h ^ m) +
   1.177 +              (\<Sum>m<n. diff m 0 / real (fact m) * h ^ m) +
   1.178                diff n t / real (fact n) * h ^ n)"
   1.179  by (blast intro: Maclaurin_minus)
   1.180  
   1.181 @@ -262,7 +252,7 @@
   1.182  lemma Maclaurin_bi_le_lemma [rule_format]:
   1.183    "n>0 \<longrightarrow>
   1.184     diff 0 0 =
   1.185 -   (\<Sum>m = 0..<n. diff m 0 * 0 ^ m / real (fact m)) +
   1.186 +   (\<Sum>m<n. diff m 0 * 0 ^ m / real (fact m)) +
   1.187     diff n 0 * 0 ^ n / real (fact n)"
   1.188  by (induct "n") auto
   1.189  
   1.190 @@ -271,7 +261,7 @@
   1.191     and DERIV : "\<forall>m t. m < n & abs t \<le> abs x --> DERIV (diff m) t :> diff (Suc m) t"
   1.192     shows "\<exists>t. abs t \<le> abs x &
   1.193                f x =
   1.194 -              (\<Sum>m=0..<n. diff m 0 / real (fact m) * x ^ m) +
   1.195 +              (\<Sum>m<n. diff m 0 / real (fact m) * x ^ m) +
   1.196       diff n t / real (fact n) * x ^ n" (is "\<exists>t. _ \<and> f x = ?f x t")
   1.197  proof cases
   1.198    assume "n = 0" with `diff 0 = f` show ?thesis by force
   1.199 @@ -303,7 +293,7 @@
   1.200    assumes INIT1: "diff 0 = f" and INIT2: "0 < n" and INIT3: "x \<noteq> 0"
   1.201    and DERIV: "\<forall>m x. DERIV (diff m) x :> diff(Suc m) x"
   1.202    shows "\<exists>t. 0 < abs t & abs t < abs x & f x =
   1.203 -    (\<Sum>m=0..<n. (diff m 0 / real (fact m)) * x ^ m) +
   1.204 +    (\<Sum>m<n. (diff m 0 / real (fact m)) * x ^ m) +
   1.205                  (diff n t / real (fact n)) * x ^ n" (is "\<exists>t. _ \<and> _ \<and> f x = ?f x t")
   1.206  proof (cases rule: linorder_cases)
   1.207    assume "x = 0" with INIT3 show "?thesis"..
   1.208 @@ -327,14 +317,14 @@
   1.209        (\<forall>m x. DERIV (diff m) x :> diff(Suc m) x) &
   1.210        x ~= 0 & n > 0
   1.211        --> (\<exists>t. 0 < abs t & abs t < abs x &
   1.212 -               f x = (\<Sum>m=0..<n. (diff m 0 / real (fact m)) * x ^ m) +
   1.213 +               f x = (\<Sum>m<n. (diff m 0 / real (fact m)) * x ^ m) +
   1.214                       (diff n t / real (fact n)) * x ^ n)"
   1.215  by (blast intro: Maclaurin_all_lt)
   1.216  
   1.217  lemma Maclaurin_zero [rule_format]:
   1.218       "x = (0::real)
   1.219        ==> n \<noteq> 0 -->
   1.220 -          (\<Sum>m=0..<n. (diff m (0::real) / real (fact m)) * x ^ m) =
   1.221 +          (\<Sum>m<n. (diff m (0::real) / real (fact m)) * x ^ m) =
   1.222            diff 0 0"
   1.223  by (induct n, auto)
   1.224  
   1.225 @@ -343,7 +333,7 @@
   1.226    assumes INIT: "diff 0 = f"
   1.227    and DERIV: "\<forall>m x. DERIV (diff m) x :> diff (Suc m) x"
   1.228    shows "\<exists>t. abs t \<le> abs x & f x =
   1.229 -    (\<Sum>m=0..<n. (diff m 0 / real (fact m)) * x ^ m) +
   1.230 +    (\<Sum>m<n. (diff m 0 / real (fact m)) * x ^ m) +
   1.231      (diff n t / real (fact n)) * x ^ n" (is "\<exists>t. _ \<and> f x = ?f x t")
   1.232  proof cases
   1.233    assume "n = 0" with INIT show ?thesis by force
   1.234 @@ -352,7 +342,7 @@
   1.235    show ?thesis
   1.236    proof cases
   1.237      assume "x = 0"
   1.238 -    with `n \<noteq> 0` have "(\<Sum>m = 0..<n. diff m 0 / real (fact m) * x ^ m) = diff 0 0"
   1.239 +    with `n \<noteq> 0` have "(\<Sum>m<n. diff m 0 / real (fact m) * x ^ m) = diff 0 0"
   1.240        by (intro Maclaurin_zero) auto
   1.241      with INIT `x = 0` `n \<noteq> 0` have " \<bar>0\<bar> \<le> \<bar>x\<bar> \<and> f x = ?f x 0" by force
   1.242      thus ?thesis ..
   1.243 @@ -369,7 +359,7 @@
   1.244  lemma Maclaurin_all_le_objl: "diff 0 = f &
   1.245        (\<forall>m x. DERIV (diff m) x :> diff (Suc m) x)
   1.246        --> (\<exists>t. abs t \<le> abs x &
   1.247 -              f x = (\<Sum>m=0..<n. (diff m 0 / real (fact m)) * x ^ m) +
   1.248 +              f x = (\<Sum>m<n. (diff m 0 / real (fact m)) * x ^ m) +
   1.249                      (diff n t / real (fact n)) * x ^ n)"
   1.250  by (blast intro: Maclaurin_all_le)
   1.251  
   1.252 @@ -379,14 +369,14 @@
   1.253  lemma Maclaurin_exp_lt: "[| x ~= 0; n > 0 |]
   1.254        ==> (\<exists>t. 0 < abs t &
   1.255                  abs t < abs x &
   1.256 -                exp x = (\<Sum>m=0..<n. (x ^ m) / real (fact m)) +
   1.257 +                exp x = (\<Sum>m<n. (x ^ m) / real (fact m)) +
   1.258                          (exp t / real (fact n)) * x ^ n)"
   1.259  by (cut_tac diff = "%n. exp" and f = exp and x = x and n = n in Maclaurin_all_lt_objl, auto)
   1.260  
   1.261  
   1.262  lemma Maclaurin_exp_le:
   1.263       "\<exists>t. abs t \<le> abs x &
   1.264 -            exp x = (\<Sum>m=0..<n. (x ^ m) / real (fact m)) +
   1.265 +            exp x = (\<Sum>m<n. (x ^ m) / real (fact m)) +
   1.266                         (exp t / real (fact n)) * x ^ n"
   1.267  by (cut_tac diff = "%n. exp" and f = exp and x = x and n = n in Maclaurin_all_le_objl, auto)
   1.268  
   1.269 @@ -420,7 +410,7 @@
   1.270  lemma Maclaurin_sin_expansion2:
   1.271       "\<exists>t. abs t \<le> abs x &
   1.272         sin x =
   1.273 -       (\<Sum>m=0..<n. sin_coeff m * x ^ m)
   1.274 +       (\<Sum>m<n. sin_coeff m * x ^ m)
   1.275        + ((sin(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.276  apply (cut_tac f = sin and n = n and x = x
   1.277          and diff = "%n x. sin (x + 1/2*real n * pi)" in Maclaurin_all_lt_objl)
   1.278 @@ -440,7 +430,7 @@
   1.279  
   1.280  lemma Maclaurin_sin_expansion:
   1.281       "\<exists>t. sin x =
   1.282 -       (\<Sum>m=0..<n. sin_coeff m * x ^ m)
   1.283 +       (\<Sum>m<n. sin_coeff m * x ^ m)
   1.284        + ((sin(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.285  apply (insert Maclaurin_sin_expansion2 [of x n])
   1.286  apply (blast intro: elim:)
   1.287 @@ -450,7 +440,7 @@
   1.288       "[| n > 0; 0 < x |] ==>
   1.289         \<exists>t. 0 < t & t < x &
   1.290         sin x =
   1.291 -       (\<Sum>m=0..<n. sin_coeff m * x ^ m)
   1.292 +       (\<Sum>m<n. sin_coeff m * x ^ m)
   1.293        + ((sin(t + 1/2 * real(n) *pi) / real (fact n)) * x ^ n)"
   1.294  apply (cut_tac f = sin and n = n and h = x and diff = "%n x. sin (x + 1/2*real (n) *pi)" in Maclaurin_objl)
   1.295  apply safe
   1.296 @@ -467,7 +457,7 @@
   1.297       "0 < x ==>
   1.298         \<exists>t. 0 < t & t \<le> x &
   1.299         sin x =
   1.300 -       (\<Sum>m=0..<n. sin_coeff m * x ^ m)
   1.301 +       (\<Sum>m<n. sin_coeff m * x ^ m)
   1.302        + ((sin(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.303  apply (cut_tac f = sin and n = n and h = x and diff = "%n x. sin (x + 1/2*real (n) *pi)" in Maclaurin2_objl)
   1.304  apply safe
   1.305 @@ -484,7 +474,7 @@
   1.306  subsection{*Maclaurin Expansion for Cosine Function*}
   1.307  
   1.308  lemma sumr_cos_zero_one [simp]:
   1.309 -  "(\<Sum>m=0..<(Suc n). cos_coeff m * 0 ^ m) = 1"
   1.310 +  "(\<Sum>m<(Suc n). cos_coeff m * 0 ^ m) = 1"
   1.311  by (induct "n", auto)
   1.312  
   1.313  lemma cos_expansion_lemma:
   1.314 @@ -494,14 +484,14 @@
   1.315  lemma Maclaurin_cos_expansion:
   1.316       "\<exists>t. abs t \<le> abs x &
   1.317         cos x =
   1.318 -       (\<Sum>m=0..<n. cos_coeff m * x ^ m)
   1.319 +       (\<Sum>m<n. cos_coeff m * x ^ m)
   1.320        + ((cos(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.321  apply (cut_tac f = cos and n = n and x = x and diff = "%n x. cos (x + 1/2*real (n) *pi)" in Maclaurin_all_lt_objl)
   1.322  apply safe
   1.323  apply (simp (no_asm))
   1.324  apply (simp (no_asm) add: cos_expansion_lemma)
   1.325  apply (case_tac "n", simp)
   1.326 -apply (simp del: setsum_op_ivl_Suc)
   1.327 +apply (simp del: setsum_lessThan_Suc)
   1.328  apply (rule ccontr, simp)
   1.329  apply (drule_tac x = x in spec, simp)
   1.330  apply (erule ssubst)
   1.331 @@ -514,7 +504,7 @@
   1.332       "[| 0 < x; n > 0 |] ==>
   1.333         \<exists>t. 0 < t & t < x &
   1.334         cos x =
   1.335 -       (\<Sum>m=0..<n. cos_coeff m * x ^ m)
   1.336 +       (\<Sum>m<n. cos_coeff m * x ^ m)
   1.337        + ((cos(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.338  apply (cut_tac f = cos and n = n and h = x and diff = "%n x. cos (x + 1/2*real (n) *pi)" in Maclaurin_objl)
   1.339  apply safe
   1.340 @@ -530,7 +520,7 @@
   1.341       "[| x < 0; n > 0 |] ==>
   1.342         \<exists>t. x < t & t < 0 &
   1.343         cos x =
   1.344 -       (\<Sum>m=0..<n. cos_coeff m * x ^ m)
   1.345 +       (\<Sum>m<n. cos_coeff m * x ^ m)
   1.346        + ((cos(t + 1/2 * real (n) *pi) / real (fact n)) * x ^ n)"
   1.347  apply (cut_tac f = cos and n = n and h = x and diff = "%n x. cos (x + 1/2*real (n) *pi)" in Maclaurin_minus_objl)
   1.348  apply safe
   1.349 @@ -551,7 +541,7 @@
   1.350  by auto
   1.351  
   1.352  lemma Maclaurin_sin_bound:
   1.353 -  "abs(sin x - (\<Sum>m=0..<n. sin_coeff m * x ^ m))
   1.354 +  "abs(sin x - (\<Sum>m<n. sin_coeff m * x ^ m))
   1.355    \<le> inverse(real (fact n)) * \<bar>x\<bar> ^ n"
   1.356  proof -
   1.357    have "!! x (y::real). x \<le> 1 \<Longrightarrow> 0 \<le> y \<Longrightarrow> x * y \<le> 1 * y"
   1.358 @@ -567,7 +557,7 @@
   1.359      done
   1.360    from Maclaurin_all_le [OF diff_0 DERIV_diff]
   1.361    obtain t where t1: "\<bar>t\<bar> \<le> \<bar>x\<bar>" and
   1.362 -    t2: "sin x = (\<Sum>m = 0..<n. ?diff m 0 / real (fact m) * x ^ m) +
   1.363 +    t2: "sin x = (\<Sum>m<n. ?diff m 0 / real (fact m) * x ^ m) +
   1.364        ?diff n t / real (fact n) * x ^ n" by fast
   1.365    have diff_m_0:
   1.366      "\<And>m. ?diff m 0 = (if even m then 0
     2.1 --- a/src/HOL/Multivariate_Analysis/Cartesian_Euclidean_Space.thy	Tue Mar 18 14:32:23 2014 +0100
     2.2 +++ b/src/HOL/Multivariate_Analysis/Cartesian_Euclidean_Space.thy	Tue Mar 18 15:53:48 2014 +0100
     2.3 @@ -23,7 +23,7 @@
     2.4  
     2.5  lemma setsum_mult_product:
     2.6    "setsum h {..<A * B :: nat} = (\<Sum>i\<in>{..<A}. \<Sum>j\<in>{..<B}. h (j + i * B))"
     2.7 -  unfolding sumr_group[of h B A, unfolded atLeast0LessThan, symmetric]
     2.8 +  unfolding setsum_nat_group[of h B A, unfolded atLeast0LessThan, symmetric]
     2.9  proof (rule setsum_cong, simp, rule setsum_reindex_cong)
    2.10    fix i
    2.11    show "inj_on (\<lambda>j. j + i * B) {..<B}" by (auto intro!: inj_onI)
     3.1 --- a/src/HOL/Multivariate_Analysis/Derivative.thy	Tue Mar 18 14:32:23 2014 +0100
     3.2 +++ b/src/HOL/Multivariate_Analysis/Derivative.thy	Tue Mar 18 15:53:48 2014 +0100
     3.3 @@ -1990,7 +1990,7 @@
     3.4    fixes f :: "nat \<Rightarrow> 'm::euclidean_space \<Rightarrow> 'n::euclidean_space"
     3.5    assumes "convex s"
     3.6      and "\<And>n x. x \<in> s \<Longrightarrow> ((f n) has_derivative (f' n x)) (at x within s)"
     3.7 -    and "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. \<forall>x\<in>s. \<forall>h. norm (setsum (\<lambda>i. f' i x h) {0..<n} - g' x h) \<le> e * norm h"
     3.8 +    and "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. \<forall>x\<in>s. \<forall>h. norm (setsum (\<lambda>i. f' i x h) {..<n} - g' x h) \<le> e * norm h"
     3.9      and "x \<in> s"
    3.10      and "(\<lambda>n. f n x) sums l"
    3.11    shows "\<exists>g. \<forall>x\<in>s. (\<lambda>n. f n x) sums (g x) \<and> (g has_derivative g' x) (at x within s)"
     4.1 --- a/src/HOL/Multivariate_Analysis/Integration.thy	Tue Mar 18 14:32:23 2014 +0100
     4.2 +++ b/src/HOL/Multivariate_Analysis/Integration.thy	Tue Mar 18 15:53:48 2014 +0100
     4.3 @@ -6006,14 +6006,14 @@
     4.4            done
     4.5        qed
     4.6        have "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) \<le> setsum (\<lambda>i. (real i + 1) *
     4.7 -        norm (setsum (\<lambda>(x,k). content k *\<^sub>R indicator s x :: real) (q i))) {0..N+1}"
     4.8 +        norm (setsum (\<lambda>(x,k). content k *\<^sub>R indicator s x :: real) (q i))) {..N+1}"
     4.9          unfolding real_norm_def setsum_right_distrib abs_of_nonneg[OF *] diff_0_right
    4.10          apply (rule order_trans)
    4.11          apply (rule norm_setsum)
    4.12          apply (subst sum_sum_product)
    4.13          prefer 3
    4.14        proof (rule **, safe)
    4.15 -        show "finite {(i, j) |i j. i \<in> {0..N + 1} \<and> j \<in> q i}"
    4.16 +        show "finite {(i, j) |i j. i \<in> {..N + 1} \<and> j \<in> q i}"
    4.17            apply (rule finite_product_dependent)
    4.18            using q
    4.19            apply auto
    4.20 @@ -6068,7 +6068,7 @@
    4.21              using nfx True
    4.22              by (auto simp add: field_simps)
    4.23          qed
    4.24 -        ultimately show "\<exists>y. (y, x, k) \<in> {(i, j) |i j. i \<in> {0..N + 1} \<and> j \<in> q i} \<and> norm (content k *\<^sub>R f x) \<le>
    4.25 +        ultimately show "\<exists>y. (y, x, k) \<in> {(i, j) |i j. i \<in> {..N + 1} \<and> j \<in> q i} \<and> norm (content k *\<^sub>R f x) \<le>
    4.26            (real y + 1) * (content k *\<^sub>R indicator s x)"
    4.27            apply (rule_tac x=n in exI)
    4.28            apply safe
    4.29 @@ -6078,7 +6078,7 @@
    4.30            apply auto
    4.31            done
    4.32        qed (insert as, auto)
    4.33 -      also have "\<dots> \<le> setsum (\<lambda>i. e / 2 / 2 ^ i) {0..N+1}"
    4.34 +      also have "\<dots> \<le> setsum (\<lambda>i. e / 2 / 2 ^ i) {..N+1}"
    4.35          apply (rule setsum_mono)
    4.36        proof -
    4.37          case goal1
    4.38 @@ -6092,8 +6092,8 @@
    4.39        also have "\<dots> < e * inverse 2 * 2"
    4.40          unfolding divide_inverse setsum_right_distrib[symmetric]
    4.41          apply (rule mult_strict_left_mono)
    4.42 -        unfolding power_inverse atLeastLessThanSuc_atLeastAtMost[symmetric]
    4.43 -        apply (subst sumr_geometric)
    4.44 +        unfolding power_inverse lessThan_Suc_atMost[symmetric]
    4.45 +        apply (subst geometric_sum)
    4.46          using goal1
    4.47          apply auto
    4.48          done
     5.1 --- a/src/HOL/Probability/Lebesgue_Integration.thy	Tue Mar 18 14:32:23 2014 +0100
     5.2 +++ b/src/HOL/Probability/Lebesgue_Integration.thy	Tue Mar 18 15:53:48 2014 +0100
     5.3 @@ -2231,21 +2231,21 @@
     5.4    obtain x where abs_sum: "(\<lambda>i. (\<integral>x. \<bar>f i x\<bar> \<partial>M)) sums x"
     5.5      using sums unfolding summable_def ..
     5.6  
     5.7 -  have 1: "\<And>n. integrable M (\<lambda>x. \<Sum>i = 0..<n. f i x)"
     5.8 +  have 1: "\<And>n. integrable M (\<lambda>x. \<Sum>i<n. f i x)"
     5.9      using integrable by auto
    5.10  
    5.11 -  have 2: "\<And>j. AE x in M. \<bar>\<Sum>i = 0..<j. f i x\<bar> \<le> ?w x"
    5.12 +  have 2: "\<And>j. AE x in M. \<bar>\<Sum>i<j. f i x\<bar> \<le> ?w x"
    5.13      using AE_space
    5.14    proof eventually_elim
    5.15      fix j x assume [simp]: "x \<in> space M"
    5.16 -    have "\<bar>\<Sum>i = 0..< j. f i x\<bar> \<le> (\<Sum>i = 0..< j. \<bar>f i x\<bar>)" by (rule setsum_abs)
    5.17 +    have "\<bar>\<Sum>i<j. f i x\<bar> \<le> (\<Sum>i<j. \<bar>f i x\<bar>)" by (rule setsum_abs)
    5.18      also have "\<dots> \<le> w x" using w[of x] series_pos_le[of "\<lambda>i. \<bar>f i x\<bar>"] unfolding sums_iff by auto
    5.19 -    finally show "\<bar>\<Sum>i = 0..<j. f i x\<bar> \<le> ?w x" by simp
    5.20 +    finally show "\<bar>\<Sum>i<j. f i x\<bar> \<le> ?w x" by simp
    5.21    qed
    5.22  
    5.23    have 3: "integrable M ?w"
    5.24    proof (rule integral_monotone_convergence(1))
    5.25 -    let ?F = "\<lambda>n y. (\<Sum>i = 0..<n. \<bar>f i y\<bar>)"
    5.26 +    let ?F = "\<lambda>n y. (\<Sum>i<n. \<bar>f i y\<bar>)"
    5.27      let ?w' = "\<lambda>n y. if y \<in> space M then ?F n y else 0"
    5.28      have "\<And>n. integrable M (?F n)"
    5.29        using integrable by (auto intro!: integrable_abs)
    5.30 @@ -2254,15 +2254,15 @@
    5.31        by (auto simp: mono_def le_fun_def intro!: setsum_mono2)
    5.32      show "AE x in M. (\<lambda>n. ?w' n x) ----> ?w x"
    5.33          using w by (simp_all add: tendsto_const sums_def)
    5.34 -    have *: "\<And>n. integral\<^sup>L M (?w' n) = (\<Sum>i = 0..< n. (\<integral>x. \<bar>f i x\<bar> \<partial>M))"
    5.35 +    have *: "\<And>n. integral\<^sup>L M (?w' n) = (\<Sum>i< n. (\<integral>x. \<bar>f i x\<bar> \<partial>M))"
    5.36        using integrable by (simp add: integrable_abs cong: integral_cong)
    5.37      from abs_sum
    5.38      show "(\<lambda>i. integral\<^sup>L M (?w' i)) ----> x" unfolding * sums_def .
    5.39    qed (simp add: w_borel measurable_If_set)
    5.40  
    5.41    from summable[THEN summable_rabs_cancel]
    5.42 -  have 4: "AE x in M. (\<lambda>n. \<Sum>i = 0..<n. f i x) ----> (\<Sum>i. f i x)"
    5.43 -    by (auto intro: summable_sumr_LIMSEQ_suminf)
    5.44 +  have 4: "AE x in M. (\<lambda>n. \<Sum>i<n. f i x) ----> (\<Sum>i. f i x)"
    5.45 +    by (auto intro: summable_LIMSEQ)
    5.46  
    5.47    note int = integral_dominated_convergence(1,3)[OF 1 2 3 4
    5.48      borel_measurable_suminf[OF integrableD(1)[OF integrable]]]
     6.1 --- a/src/HOL/Probability/Lebesgue_Measure.thy	Tue Mar 18 14:32:23 2014 +0100
     6.2 +++ b/src/HOL/Probability/Lebesgue_Measure.thy	Tue Mar 18 15:53:48 2014 +0100
     6.3 @@ -194,7 +194,7 @@
     6.4              ultimately show ?case
     6.5                using Suc A by (simp add: Integration.integral_add[symmetric])
     6.6            qed auto }
     6.7 -        ultimately show "(\<lambda>m. \<Sum>x = 0..<m. ?m n x) ----> ?M n UNIV"
     6.8 +        ultimately show "(\<lambda>m. \<Sum>x<m. ?m n x) ----> ?M n UNIV"
     6.9            by (simp add: atLeast0LessThan)
    6.10        qed
    6.11      qed
     7.1 --- a/src/HOL/Probability/Measure_Space.thy	Tue Mar 18 14:32:23 2014 +0100
     7.2 +++ b/src/HOL/Probability/Measure_Space.thy	Tue Mar 18 15:53:48 2014 +0100
     7.3 @@ -16,7 +16,7 @@
     7.4    "f sums x \<longleftrightarrow> (\<lambda>n. (\<Sum>i\<le>n. f i)) ----> x"
     7.5    unfolding sums_def
     7.6    apply (subst LIMSEQ_Suc_iff[symmetric])
     7.7 -  unfolding atLeastLessThanSuc_atLeastAtMost atLeast0AtMost ..
     7.8 +  unfolding lessThan_Suc_atMost ..
     7.9  
    7.10  subsection "Relate extended reals and the indicator function"
    7.11  
    7.12 @@ -304,12 +304,12 @@
    7.13    with count_sum[THEN spec, of "disjointed A"] A(3)
    7.14    have f_UN: "(\<Sum>i. f (disjointed A i)) = f (\<Union>i. A i)"
    7.15      by (auto simp: UN_disjointed_eq disjoint_family_disjointed)
    7.16 -  moreover have "(\<lambda>n. (\<Sum>i=0..<n. f (disjointed A i))) ----> (\<Sum>i. f (disjointed A i))"
    7.17 +  moreover have "(\<lambda>n. (\<Sum>i<n. f (disjointed A i))) ----> (\<Sum>i. f (disjointed A i))"
    7.18      using f(1)[unfolded positive_def] dA
    7.19 -    by (auto intro!: summable_sumr_LIMSEQ_suminf summable_ereal_pos)
    7.20 +    by (auto intro!: summable_LIMSEQ summable_ereal_pos)
    7.21    from LIMSEQ_Suc[OF this]
    7.22    have "(\<lambda>n. (\<Sum>i\<le>n. f (disjointed A i))) ----> (\<Sum>i. f (disjointed A i))"
    7.23 -    unfolding atLeastLessThanSuc_atLeastAtMost atLeast0AtMost .
    7.24 +    unfolding lessThan_Suc_atMost .
    7.25    moreover have "\<And>n. (\<Sum>i\<le>n. f (disjointed A i)) = f (A n)"
    7.26      using disjointed_additive[OF f A(1,2)] .
    7.27    ultimately show "(\<lambda>i. f (A i)) ----> f (\<Union>i. A i)" by simp
     8.1 --- a/src/HOL/Probability/Projective_Limit.thy	Tue Mar 18 14:32:23 2014 +0100
     8.2 +++ b/src/HOL/Probability/Projective_Limit.thy	Tue Mar 18 15:53:48 2014 +0100
     8.3 @@ -355,10 +355,10 @@
     8.4            have "(\<Sum>i\<in>{1..n}. 2 powr - real i) = (\<Sum>i\<in>{1..<Suc n}. (1/2) ^ i)"
     8.5              by (rule setsum_cong)
     8.6                 (auto simp: powr_realpow[symmetric] powr_minus powr_divide inverse_eq_divide)
     8.7 -          also have "{1..<Suc n} = {0..<Suc n} - {0}" by auto
     8.8 -          also have "setsum (op ^ (1 / 2::real)) ({0..<Suc n} - {0}) =
     8.9 -            setsum (op ^ (1 / 2)) ({0..<Suc n}) - 1" by (auto simp: setsum_diff1)
    8.10 -          also have "\<dots> < 1" by (subst sumr_geometric) auto
    8.11 +          also have "{1..<Suc n} = {..<Suc n} - {0}" by auto
    8.12 +          also have "setsum (op ^ (1 / 2::real)) ({..<Suc n} - {0}) =
    8.13 +            setsum (op ^ (1 / 2)) ({..<Suc n}) - 1" by (auto simp: setsum_diff1)
    8.14 +          also have "\<dots> < 1" by (subst geometric_sum) auto
    8.15            finally show "(\<Sum>i = 1..n. 2 powr - real i) < 1" .
    8.16          qed (auto simp:
    8.17            `0 < ?a` `?a \<noteq> \<infinity>` `?a \<noteq> - \<infinity>` ereal_less_real_iff zero_ereal_def[symmetric])
     9.1 --- a/src/HOL/Probability/Regularity.thy	Tue Mar 18 14:32:23 2014 +0100
     9.2 +++ b/src/HOL/Probability/Regularity.thy	Tue Mar 18 15:53:48 2014 +0100
     9.3 @@ -351,9 +351,9 @@
     9.4      case (union D)
     9.5      then have "range D \<subseteq> sets M" by (auto simp: sb borel_eq_closed)
     9.6      with union have M[symmetric]: "(\<Sum>i. M (D i)) = M (\<Union>i. D i)" by (intro suminf_emeasure)
     9.7 -    also have "(\<lambda>n. \<Sum>i\<in>{0..<n}. M (D i)) ----> (\<Sum>i. M (D i))"
     9.8 -      by (intro summable_sumr_LIMSEQ_suminf summable_ereal_pos emeasure_nonneg)
     9.9 -    finally have measure_LIMSEQ: "(\<lambda>n. \<Sum>i = 0..<n. measure M (D i)) ----> measure M (\<Union>i. D i)"
    9.10 +    also have "(\<lambda>n. \<Sum>i<n. M (D i)) ----> (\<Sum>i. M (D i))"
    9.11 +      by (intro summable_LIMSEQ summable_ereal_pos emeasure_nonneg)
    9.12 +    finally have measure_LIMSEQ: "(\<lambda>n. \<Sum>i<n. measure M (D i)) ----> measure M (\<Union>i. D i)"
    9.13        by (simp add: emeasure_eq_measure)
    9.14      have "(\<Union>i. D i) \<in> sets M" using `range D \<subseteq> sets M` by auto
    9.15      
    9.16 @@ -362,18 +362,17 @@
    9.17      proof (rule approx_inner)
    9.18        fix e::real assume "e > 0"
    9.19        with measure_LIMSEQ
    9.20 -      have "\<exists>no. \<forall>n\<ge>no. \<bar>(\<Sum>i = 0..<n. measure M (D i)) -measure M (\<Union>x. D x)\<bar> < e/2"
    9.21 +      have "\<exists>no. \<forall>n\<ge>no. \<bar>(\<Sum>i<n. measure M (D i)) -measure M (\<Union>x. D x)\<bar> < e/2"
    9.22          by (auto simp: LIMSEQ_def dist_real_def simp del: less_divide_eq_numeral1)
    9.23 -      hence "\<exists>n0. \<bar>(\<Sum>i = 0..<n0. measure M (D i)) - measure M (\<Union>x. D x)\<bar> < e/2" by auto
    9.24 -      then obtain n0 where n0: "\<bar>(\<Sum>i = 0..<n0. measure M (D i)) - measure M (\<Union>i. D i)\<bar> < e/2"
    9.25 +      hence "\<exists>n0. \<bar>(\<Sum>i<n0. measure M (D i)) - measure M (\<Union>x. D x)\<bar> < e/2" by auto
    9.26 +      then obtain n0 where n0: "\<bar>(\<Sum>i<n0. measure M (D i)) - measure M (\<Union>i. D i)\<bar> < e/2"
    9.27          unfolding choice_iff by blast
    9.28 -      have "ereal (\<Sum>i = 0..<n0. measure M (D i)) = (\<Sum>i = 0..<n0. M (D i))"
    9.29 +      have "ereal (\<Sum>i<n0. measure M (D i)) = (\<Sum>i<n0. M (D i))"
    9.30          by (auto simp add: emeasure_eq_measure)
    9.31 -      also have "\<dots> = (\<Sum>i<n0. M (D i))" by (rule setsum_cong) auto
    9.32        also have "\<dots> \<le> (\<Sum>i. M (D i))" by (rule suminf_upper) (auto simp: emeasure_nonneg)
    9.33        also have "\<dots> = M (\<Union>i. D i)" by (simp add: M)
    9.34        also have "\<dots> = measure M (\<Union>i. D i)" by (simp add: emeasure_eq_measure)
    9.35 -      finally have n0: "measure M (\<Union>i. D i) - (\<Sum>i = 0..<n0. measure M (D i)) < e/2"
    9.36 +      finally have n0: "measure M (\<Union>i. D i) - (\<Sum>i<n0. measure M (D i)) < e/2"
    9.37          using n0 by auto
    9.38        have "\<forall>i. \<exists>K. K \<subseteq> D i \<and> compact K \<and> emeasure M (D i) \<le> emeasure M K + e/(2*Suc n0)"
    9.39        proof
    9.40 @@ -388,20 +387,20 @@
    9.41        then obtain K where K: "\<And>i. K i \<subseteq> D i" "\<And>i. compact (K i)"
    9.42          "\<And>i. emeasure M (D i) \<le> emeasure M (K i) + e/(2*Suc n0)"
    9.43          unfolding choice_iff by blast
    9.44 -      let ?K = "\<Union>i\<in>{0..<n0}. K i"
    9.45 -      have "disjoint_family_on K {0..<n0}" using K `disjoint_family D`
    9.46 +      let ?K = "\<Union>i\<in>{..<n0}. K i"
    9.47 +      have "disjoint_family_on K {..<n0}" using K `disjoint_family D`
    9.48          unfolding disjoint_family_on_def by blast
    9.49 -      hence mK: "measure M ?K = (\<Sum>i = 0..<n0. measure M (K i))" using K
    9.50 +      hence mK: "measure M ?K = (\<Sum>i<n0. measure M (K i))" using K
    9.51          by (intro finite_measure_finite_Union) (auto simp: sb compact_imp_closed)
    9.52 -      have "measure M (\<Union>i. D i) < (\<Sum>i = 0..<n0. measure M (D i)) + e/2" using n0 by simp
    9.53 -      also have "(\<Sum>i = 0..<n0. measure M (D i)) \<le> (\<Sum>i = 0..<n0. measure M (K i) + e/(2*Suc n0))"
    9.54 +      have "measure M (\<Union>i. D i) < (\<Sum>i<n0. measure M (D i)) + e/2" using n0 by simp
    9.55 +      also have "(\<Sum>i<n0. measure M (D i)) \<le> (\<Sum>i<n0. measure M (K i) + e/(2*Suc n0))"
    9.56          using K by (auto intro: setsum_mono simp: emeasure_eq_measure)
    9.57 -      also have "\<dots> = (\<Sum>i = 0..<n0. measure M (K i)) + (\<Sum>i = 0..<n0. e/(2*Suc n0))"
    9.58 +      also have "\<dots> = (\<Sum>i<n0. measure M (K i)) + (\<Sum>i<n0. e/(2*Suc n0))"
    9.59          by (simp add: setsum.distrib)
    9.60 -      also have "\<dots> \<le> (\<Sum>i = 0..<n0. measure M (K i)) +  e / 2" using `0 < e`
    9.61 +      also have "\<dots> \<le> (\<Sum>i<n0. measure M (K i)) +  e / 2" using `0 < e`
    9.62          by (auto simp: real_of_nat_def[symmetric] field_simps intro!: mult_left_mono)
    9.63        finally
    9.64 -      have "measure M (\<Union>i. D i) < (\<Sum>i = 0..<n0. measure M (K i)) + e / 2 + e / 2"
    9.65 +      have "measure M (\<Union>i. D i) < (\<Sum>i<n0. measure M (K i)) + e / 2 + e / 2"
    9.66          by auto
    9.67        hence "M (\<Union>i. D i) < M ?K + e" by (auto simp: mK emeasure_eq_measure)
    9.68        moreover
    10.1 --- a/src/HOL/Series.thy	Tue Mar 18 14:32:23 2014 +0100
    10.2 +++ b/src/HOL/Series.thy	Tue Mar 18 15:53:48 2014 +0100
    10.3 @@ -7,122 +7,109 @@
    10.4  Additional contributions by Jeremy Avigad
    10.5  *)
    10.6  
    10.7 -header{*Finite Summation and Infinite Series*}
    10.8 +header {* Finite Summation and Infinite Series *}
    10.9  
   10.10  theory Series
   10.11  imports Limits
   10.12  begin
   10.13  
   10.14 -definition
   10.15 -   sums  :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a \<Rightarrow> bool"
   10.16 -     (infixr "sums" 80) where
   10.17 -   "f sums s = (%n. setsum f {0..<n}) ----> s"
   10.18 -
   10.19 -definition
   10.20 -   summable :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> bool" where
   10.21 -   "summable f = (\<exists>s. f sums s)"
   10.22 -
   10.23 -definition
   10.24 -   suminf   :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a" where
   10.25 -   "suminf f = (THE s. f sums s)"
   10.26 -
   10.27 -notation suminf (binder "\<Sum>" 10)
   10.28 -
   10.29 -
   10.30 -lemma [trans]: "f=g ==> g sums z ==> f sums z"
   10.31 -  by simp
   10.32 +(* TODO: MOVE *)
   10.33 +lemma Suc_less_iff: "Suc n < m \<longleftrightarrow> (\<exists>m'. m = Suc m' \<and> n < m')"
   10.34 +  by (cases m) auto
   10.35  
   10.36 -lemma sumr_diff_mult_const:
   10.37 - "setsum f {0..<n} - (real n*r) = setsum (%i. f i - r) {0..<n::nat}"
   10.38 -  by (simp add: setsum_subtractf real_of_nat_def)
   10.39 -
   10.40 -lemma real_setsum_nat_ivl_bounded:
   10.41 -     "(!!p. p < n \<Longrightarrow> f(p) \<le> K)
   10.42 -      \<Longrightarrow> setsum f {0..<n::nat} \<le> real n * K"
   10.43 -using setsum_bounded[where A = "{0..<n}"]
   10.44 -by (auto simp:real_of_nat_def)
   10.45 -
   10.46 -(* Generalize from real to some algebraic structure? *)
   10.47 -lemma sumr_minus_one_realpow_zero [simp]:
   10.48 -  "(\<Sum>i=0..<2*n. (-1) ^ Suc i) = (0::real)"
   10.49 -by (induct "n", auto)
   10.50 -
   10.51 -(* FIXME this is an awful lemma! *)
   10.52 -lemma sumr_one_lb_realpow_zero [simp]:
   10.53 -  "(\<Sum>n=Suc 0..<n. f(n) * (0::real) ^ n) = 0"
   10.54 -by (rule setsum_0', simp)
   10.55 -
   10.56 -lemma sumr_group:
   10.57 -     "(\<Sum>m=0..<n::nat. setsum f {m * k ..< m*k + k}) = setsum f {0 ..< n * k}"
   10.58 -apply (subgoal_tac "k = 0 | 0 < k", auto)
   10.59 -apply (induct "n")
   10.60 -apply (simp_all add: setsum_add_nat_ivl add_commute)
   10.61 +(* TODO: MOVE *)
   10.62 +lemma norm_ratiotest_lemma:
   10.63 +  fixes x y :: "'a::real_normed_vector"
   10.64 +  shows "\<lbrakk>c \<le> 0; norm x \<le> c * norm y\<rbrakk> \<Longrightarrow> x = 0"
   10.65 +apply (subgoal_tac "norm x \<le> 0", simp)
   10.66 +apply (erule order_trans)
   10.67 +apply (simp add: mult_le_0_iff)
   10.68  done
   10.69  
   10.70 -lemma sumr_offset3:
   10.71 -  "setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)) + setsum f {0..<k}"
   10.72 -apply (subst setsum_shift_bounds_nat_ivl [symmetric])
   10.73 -apply (simp add: setsum_add_nat_ivl add_commute)
   10.74 +(* TODO: MOVE *)
   10.75 +lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
   10.76 +by (erule norm_ratiotest_lemma, simp)
   10.77 +
   10.78 +(* TODO: MOVE *)
   10.79 +lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
   10.80 +apply (drule le_imp_less_or_eq)
   10.81 +apply (auto dest: less_imp_Suc_add)
   10.82  done
   10.83  
   10.84 -lemma sumr_offset:
   10.85 -  fixes f :: "nat \<Rightarrow> 'a::ab_group_add"
   10.86 -  shows "(\<Sum>m=0..<n. f(m+k)) = setsum f {0..<n+k} - setsum f {0..<k}"
   10.87 -by (simp add: sumr_offset3)
   10.88 +(* MOVE *)
   10.89 +lemma setsum_even_minus_one [simp]: "(\<Sum>i<2 * n. (-1) ^ Suc i) = (0::'a::ring_1)"
   10.90 +  by (induct "n") auto
   10.91 +
   10.92 +(* MOVE *)
   10.93 +lemma setsum_nat_group: "(\<Sum>m<n::nat. setsum f {m * k ..< m*k + k}) = setsum f {..< n * k}"
   10.94 +  apply (subgoal_tac "k = 0 | 0 < k", auto)
   10.95 +  apply (induct "n")
   10.96 +  apply (simp_all add: setsum_add_nat_ivl add_commute atLeast0LessThan[symmetric])
   10.97 +  done
   10.98  
   10.99 -lemma sumr_offset2:
  10.100 - "\<forall>f. (\<Sum>m=0..<n::nat. f(m+k)::real) = setsum f {0..<n+k} - setsum f {0..<k}"
  10.101 -by (simp add: sumr_offset)
  10.102 +(* MOVE *)
  10.103 +lemma norm_setsum:
  10.104 +  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  10.105 +  shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
  10.106 +  apply (case_tac "finite A")
  10.107 +  apply (erule finite_induct)
  10.108 +  apply simp
  10.109 +  apply simp
  10.110 +  apply (erule order_trans [OF norm_triangle_ineq add_left_mono])
  10.111 +  apply simp
  10.112 +  done
  10.113  
  10.114 -lemma sumr_offset4:
  10.115 -  "\<forall>n f. setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)::real) + setsum f {0..<k}"
  10.116 -by (clarify, rule sumr_offset3)
  10.117 +(* MOVE *)
  10.118 +lemma norm_bound_subset:
  10.119 +  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  10.120 +  assumes "finite s" "t \<subseteq> s"
  10.121 +  assumes le: "(\<And>x. x \<in> s \<Longrightarrow> norm(f x) \<le> g x)"
  10.122 +  shows "norm (setsum f t) \<le> setsum g s"
  10.123 +proof -
  10.124 +  have "norm (setsum f t) \<le> (\<Sum>i\<in>t. norm (f i))"
  10.125 +    by (rule norm_setsum)
  10.126 +  also have "\<dots> \<le> (\<Sum>i\<in>t. g i)"
  10.127 +    using assms by (auto intro!: setsum_mono)
  10.128 +  also have "\<dots> \<le> setsum g s"
  10.129 +    using assms order.trans[OF norm_ge_zero le]
  10.130 +    by (auto intro!: setsum_mono3)
  10.131 +  finally show ?thesis .
  10.132 +qed
  10.133  
  10.134 -subsection{* Infinite Sums, by the Properties of Limits*}
  10.135 +(* MOVE *)
  10.136 +lemma (in linorder) lessThan_minus_lessThan [simp]:
  10.137 +  "{..< n} - {..< m} = {m ..< n}"
  10.138 +  by auto
  10.139 +
  10.140 +definition
  10.141 +  sums :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a \<Rightarrow> bool"
  10.142 +  (infixr "sums" 80)
  10.143 +where
  10.144 +  "f sums s \<longleftrightarrow> (\<lambda>n. \<Sum>i<n. f i) ----> s"
  10.145  
  10.146 -(*----------------------
  10.147 -   suminf is the sum
  10.148 - ---------------------*)
  10.149 -lemma sums_summable: "f sums l ==> summable f"
  10.150 +definition summable :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> bool" where
  10.151 +   "summable f \<longleftrightarrow> (\<exists>s. f sums s)"
  10.152 +
  10.153 +definition
  10.154 +  suminf :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a"
  10.155 +  (binder "\<Sum>" 10)
  10.156 +where
  10.157 +  "suminf f = (THE s. f sums s)"
  10.158 +
  10.159 +lemma sums_subst[trans]: "f = g \<Longrightarrow> g sums z \<Longrightarrow> f sums z"
  10.160 +  by simp
  10.161 +
  10.162 +lemma sums_summable: "f sums l \<Longrightarrow> summable f"
  10.163    by (simp add: sums_def summable_def, blast)
  10.164  
  10.165 -lemma summable_sums:
  10.166 -  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
  10.167 -  assumes "summable f"
  10.168 -  shows "f sums (suminf f)"
  10.169 -proof -
  10.170 -  from assms obtain s where s: "(\<lambda>n. setsum f {0..<n}) ----> s"
  10.171 -    unfolding summable_def sums_def [abs_def] ..
  10.172 -  then show ?thesis unfolding sums_def [abs_def] suminf_def
  10.173 -    by (rule theI, auto intro!: tendsto_unique[OF trivial_limit_sequentially])
  10.174 -qed
  10.175 +lemma summable_iff_convergent: "summable f \<longleftrightarrow> convergent (\<lambda>n. \<Sum>i<n. f i)"
  10.176 +  by (simp add: summable_def sums_def convergent_def)
  10.177  
  10.178 -lemma summable_sumr_LIMSEQ_suminf:
  10.179 -  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
  10.180 -  shows "summable f \<Longrightarrow> (\<lambda>n. setsum f {0..<n}) ----> suminf f"
  10.181 -by (rule summable_sums [unfolded sums_def])
  10.182 -
  10.183 -lemma suminf_eq_lim: "suminf f = lim (%n. setsum f {0..<n})"
  10.184 +lemma suminf_eq_lim: "suminf f = lim (\<lambda>n. \<Sum>i<n. f i)"
  10.185    by (simp add: suminf_def sums_def lim_def)
  10.186  
  10.187 -(*-------------------
  10.188 -    sum is unique
  10.189 - ------------------*)
  10.190 -lemma sums_unique:
  10.191 -  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
  10.192 -  shows "f sums s \<Longrightarrow> (s = suminf f)"
  10.193 -apply (frule sums_summable[THEN summable_sums])
  10.194 -apply (auto intro!: tendsto_unique[OF trivial_limit_sequentially] simp add: sums_def)
  10.195 -done
  10.196 -
  10.197 -lemma sums_iff:
  10.198 -  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
  10.199 -  shows "f sums x \<longleftrightarrow> summable f \<and> (suminf f = x)"
  10.200 -  by (metis summable_sums sums_summable sums_unique)
  10.201 -
  10.202  lemma sums_finite:
  10.203 -  assumes [simp]: "finite N"
  10.204 -  assumes f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
  10.205 +  assumes [simp]: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
  10.206    shows "f sums (\<Sum>n\<in>N. f n)"
  10.207  proof -
  10.208    { fix n
  10.209 @@ -146,266 +133,76 @@
  10.210         (simp add: eq atLeast0LessThan tendsto_const del: add_Suc_right)
  10.211  qed
  10.212  
  10.213 -lemma suminf_finite:
  10.214 -  fixes f :: "nat \<Rightarrow> 'a::{comm_monoid_add,t2_space}"
  10.215 -  assumes N: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
  10.216 -  shows "suminf f = (\<Sum>n\<in>N. f n)"
  10.217 -  using sums_finite[OF assms, THEN sums_unique] by simp
  10.218 -
  10.219 -lemma sums_If_finite_set:
  10.220 -  "finite A \<Longrightarrow> (\<lambda>r. if r \<in> A then f r else 0 :: 'a::{comm_monoid_add,t2_space}) sums (\<Sum>r\<in>A. f r)"
  10.221 +lemma sums_If_finite_set: "finite A \<Longrightarrow> (\<lambda>r. if r \<in> A then f r else 0) sums (\<Sum>r\<in>A. f r)"
  10.222    using sums_finite[of A "(\<lambda>r. if r \<in> A then f r else 0)"] by simp
  10.223  
  10.224 -lemma sums_If_finite:
  10.225 -  "finite {r. P r} \<Longrightarrow> (\<lambda>r. if P r then f r else 0 :: 'a::{comm_monoid_add,t2_space}) sums (\<Sum>r | P r. f r)"
  10.226 -  using sums_If_finite_set[of "{r. P r}" f] by simp
  10.227 -
  10.228 -lemma sums_single:
  10.229 -  "(\<lambda>r. if r = i then f r else 0::'a::{comm_monoid_add,t2_space}) sums f i"
  10.230 -  using sums_If_finite[of "\<lambda>r. r = i" f] by simp
  10.231 -
  10.232 -lemma sums_split_initial_segment:
  10.233 -  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
  10.234 -  shows "f sums s ==> (\<lambda>n. f(n + k)) sums (s - (SUM i = 0..< k. f i))"
  10.235 -  apply (unfold sums_def)
  10.236 -  apply (simp add: sumr_offset)
  10.237 -  apply (rule tendsto_diff [OF _ tendsto_const])
  10.238 -  apply (rule LIMSEQ_ignore_initial_segment)
  10.239 -  apply assumption
  10.240 -done
  10.241 -
  10.242 -lemma summable_ignore_initial_segment:
  10.243 -  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
  10.244 -  shows "summable f ==> summable (%n. f(n + k))"
  10.245 -  apply (unfold summable_def)
  10.246 -  apply (auto intro: sums_split_initial_segment)
  10.247 -done
  10.248 -
  10.249 -lemma suminf_minus_initial_segment:
  10.250 -  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
  10.251 -  shows "summable f ==>
  10.252 -    suminf f = s ==> suminf (%n. f(n + k)) = s - (SUM i = 0..< k. f i)"
  10.253 -  apply (frule summable_ignore_initial_segment)
  10.254 -  apply (rule sums_unique [THEN sym])
  10.255 -  apply (frule summable_sums)
  10.256 -  apply (rule sums_split_initial_segment)
  10.257 -  apply auto
  10.258 -done
  10.259 +lemma sums_If_finite: "finite {r. P r} \<Longrightarrow> (\<lambda>r. if P r then f r else 0) sums (\<Sum>r | P r. f r)"
  10.260 +  using sums_If_finite_set[of "{r. P r}"] by simp
  10.261  
  10.262 -lemma suminf_split_initial_segment:
  10.263 -  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
  10.264 -  shows "summable f ==>
  10.265 -    suminf f = (SUM i = 0..< k. f i) + (\<Sum>n. f(n + k))"
  10.266 -by (auto simp add: suminf_minus_initial_segment)
  10.267 -
  10.268 -lemma suminf_exist_split: fixes r :: real assumes "0 < r" and "summable a"
  10.269 -  shows "\<exists> N. \<forall> n \<ge> N. \<bar> \<Sum> i. a (i + n) \<bar> < r"
  10.270 -proof -
  10.271 -  from LIMSEQ_D[OF summable_sumr_LIMSEQ_suminf[OF `summable a`] `0 < r`]
  10.272 -  obtain N :: nat where "\<forall> n \<ge> N. norm (setsum a {0..<n} - suminf a) < r" by auto
  10.273 -  thus ?thesis unfolding suminf_minus_initial_segment[OF `summable a` refl] abs_minus_commute real_norm_def
  10.274 -    by auto
  10.275 -qed
  10.276 +lemma sums_single: "(\<lambda>r. if r = i then f r else 0) sums f i"
  10.277 +  using sums_If_finite[of "\<lambda>r. r = i"] by simp
  10.278  
  10.279 -lemma sums_Suc:
  10.280 -  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
  10.281 -  assumes sumSuc: "(\<lambda> n. f (Suc n)) sums l" shows "f sums (l + f 0)"
  10.282 -proof -
  10.283 -  from sumSuc[unfolded sums_def]
  10.284 -  have "(\<lambda>i. \<Sum>n = Suc 0..<Suc i. f n) ----> l" unfolding setsum_reindex[OF inj_Suc] image_Suc_atLeastLessThan[symmetric] comp_def .
  10.285 -  from tendsto_add[OF this tendsto_const, where b="f 0"]
  10.286 -  have "(\<lambda>i. \<Sum>n = 0..<Suc i. f n) ----> l + f 0" unfolding add_commute setsum_head_upt_Suc[OF zero_less_Suc] .
  10.287 -  thus ?thesis unfolding sums_def by (rule LIMSEQ_imp_Suc)
  10.288 -qed
  10.289 -
  10.290 -lemma series_zero:
  10.291 -  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
  10.292 -  assumes "\<forall>m. n \<le> m \<longrightarrow> f m = 0"
  10.293 -  shows "f sums (setsum f {0..<n})"
  10.294 -proof -
  10.295 -  { fix k :: nat have "setsum f {0..<k + n} = setsum f {0..<n}"
  10.296 -      using assms by (induct k) auto }
  10.297 -  note setsum_const = this
  10.298 -  show ?thesis
  10.299 -    unfolding sums_def
  10.300 -    apply (rule LIMSEQ_offset[of _ n])
  10.301 -    unfolding setsum_const
  10.302 -    apply (rule tendsto_const)
  10.303 -    done
  10.304 -qed
  10.305 +lemma series_zero: (* REMOVE *)
  10.306 +  "(\<And>m. n \<le> m \<Longrightarrow> f m = 0) \<Longrightarrow> f sums (\<Sum>i<n. f i)"
  10.307 +  by (rule sums_finite) auto
  10.308  
  10.309  lemma sums_zero[simp, intro]: "(\<lambda>n. 0) sums 0"
  10.310    unfolding sums_def by (simp add: tendsto_const)
  10.311  
  10.312  lemma summable_zero[simp, intro]: "summable (\<lambda>n. 0)"
  10.313 -by (rule sums_zero [THEN sums_summable])
  10.314 +  by (rule sums_zero [THEN sums_summable])
  10.315 +
  10.316 +lemma sums_group: "f sums s \<Longrightarrow> 0 < k \<Longrightarrow> (\<lambda>n. setsum f {n * k ..< n * k + k}) sums s"
  10.317 +  apply (simp only: sums_def setsum_nat_group tendsto_def eventually_sequentially)
  10.318 +  apply safe
  10.319 +  apply (erule_tac x=S in allE)
  10.320 +  apply safe
  10.321 +  apply (rule_tac x="N" in exI, safe)
  10.322 +  apply (drule_tac x="n*k" in spec)
  10.323 +  apply (erule mp)
  10.324 +  apply (erule order_trans)
  10.325 +  apply simp
  10.326 +  done
  10.327 +
  10.328 +context
  10.329 +  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
  10.330 +begin
  10.331 +
  10.332 +lemma summable_sums[intro]: "summable f \<Longrightarrow> f sums (suminf f)"
  10.333 +  by (simp add: summable_def sums_def suminf_def)
  10.334 +     (metis convergent_LIMSEQ_iff convergent_def lim_def)
  10.335 +
  10.336 +lemma summable_LIMSEQ: "summable f \<Longrightarrow> (\<lambda>n. \<Sum>i<n. f i) ----> suminf f"
  10.337 +  by (rule summable_sums [unfolded sums_def])
  10.338 +
  10.339 +lemma sums_unique: "f sums s \<Longrightarrow> s = suminf f"
  10.340 +  by (metis limI suminf_eq_lim sums_def)
  10.341 +
  10.342 +lemma sums_iff: "f sums x \<longleftrightarrow> summable f \<and> (suminf f = x)"
  10.343 +  by (metis summable_sums sums_summable sums_unique)
  10.344 +
  10.345 +lemma suminf_finite:
  10.346 +  assumes N: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
  10.347 +  shows "suminf f = (\<Sum>n\<in>N. f n)"
  10.348 +  using sums_finite[OF assms, THEN sums_unique] by simp
  10.349 +
  10.350 +end
  10.351  
  10.352  lemma suminf_zero[simp]: "suminf (\<lambda>n. 0::'a::{t2_space, comm_monoid_add}) = 0"
  10.353 -by (rule sums_zero [THEN sums_unique, symmetric])
  10.354 -
  10.355 -lemma (in bounded_linear) sums:
  10.356 -  "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
  10.357 -  unfolding sums_def by (drule tendsto, simp only: setsum)
  10.358 -
  10.359 -lemma (in bounded_linear) summable:
  10.360 -  "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
  10.361 -unfolding summable_def by (auto intro: sums)
  10.362 -
  10.363 -lemma (in bounded_linear) suminf:
  10.364 -  "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
  10.365 -by (intro sums_unique sums summable_sums)
  10.366 -
  10.367 -lemmas sums_of_real = bounded_linear.sums [OF bounded_linear_of_real]
  10.368 -lemmas summable_of_real = bounded_linear.summable [OF bounded_linear_of_real]
  10.369 -lemmas suminf_of_real = bounded_linear.suminf [OF bounded_linear_of_real]
  10.370 -
  10.371 -lemma sums_mult:
  10.372 -  fixes c :: "'a::real_normed_algebra"
  10.373 -  shows "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
  10.374 -  by (rule bounded_linear.sums [OF bounded_linear_mult_right])
  10.375 -
  10.376 -lemma summable_mult:
  10.377 -  fixes c :: "'a::real_normed_algebra"
  10.378 -  shows "summable f \<Longrightarrow> summable (%n. c * f n)"
  10.379 -  by (rule bounded_linear.summable [OF bounded_linear_mult_right])
  10.380 -
  10.381 -lemma suminf_mult:
  10.382 -  fixes c :: "'a::real_normed_algebra"
  10.383 -  shows "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f"
  10.384 -  by (rule bounded_linear.suminf [OF bounded_linear_mult_right, symmetric])
  10.385 -
  10.386 -lemma sums_mult2:
  10.387 -  fixes c :: "'a::real_normed_algebra"
  10.388 -  shows "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
  10.389 -  by (rule bounded_linear.sums [OF bounded_linear_mult_left])
  10.390 -
  10.391 -lemma summable_mult2:
  10.392 -  fixes c :: "'a::real_normed_algebra"
  10.393 -  shows "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
  10.394 -  by (rule bounded_linear.summable [OF bounded_linear_mult_left])
  10.395 -
  10.396 -lemma suminf_mult2:
  10.397 -  fixes c :: "'a::real_normed_algebra"
  10.398 -  shows "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
  10.399 -  by (rule bounded_linear.suminf [OF bounded_linear_mult_left])
  10.400 -
  10.401 -lemma sums_divide:
  10.402 -  fixes c :: "'a::real_normed_field"
  10.403 -  shows "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
  10.404 -  by (rule bounded_linear.sums [OF bounded_linear_divide])
  10.405 -
  10.406 -lemma summable_divide:
  10.407 -  fixes c :: "'a::real_normed_field"
  10.408 -  shows "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
  10.409 -  by (rule bounded_linear.summable [OF bounded_linear_divide])
  10.410 -
  10.411 -lemma suminf_divide:
  10.412 -  fixes c :: "'a::real_normed_field"
  10.413 -  shows "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
  10.414 -  by (rule bounded_linear.suminf [OF bounded_linear_divide, symmetric])
  10.415 -
  10.416 -lemma sums_add:
  10.417 -  fixes a b :: "'a::real_normed_field"
  10.418 -  shows "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) sums (a + b)"
  10.419 -  unfolding sums_def by (simp add: setsum_addf tendsto_add)
  10.420 -
  10.421 -lemma summable_add:
  10.422 -  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
  10.423 -  shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n + Y n)"
  10.424 -unfolding summable_def by (auto intro: sums_add)
  10.425 +  by (rule sums_zero [THEN sums_unique, symmetric])
  10.426  
  10.427 -lemma suminf_add:
  10.428 -  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
  10.429 -  shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X + suminf Y = (\<Sum>n. X n + Y n)"
  10.430 -by (intro sums_unique sums_add summable_sums)
  10.431 -
  10.432 -lemma sums_diff:
  10.433 -  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
  10.434 -  shows "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) sums (a - b)"
  10.435 -  unfolding sums_def by (simp add: setsum_subtractf tendsto_diff)
  10.436 -
  10.437 -lemma summable_diff:
  10.438 -  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
  10.439 -  shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n - Y n)"
  10.440 -unfolding summable_def by (auto intro: sums_diff)
  10.441 -
  10.442 -lemma suminf_diff:
  10.443 -  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
  10.444 -  shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X - suminf Y = (\<Sum>n. X n - Y n)"
  10.445 -by (intro sums_unique sums_diff summable_sums)
  10.446 -
  10.447 -lemma sums_minus:
  10.448 -  fixes X :: "nat \<Rightarrow> 'a::real_normed_field"
  10.449 -  shows "X sums a ==> (\<lambda>n. - X n) sums (- a)"
  10.450 -  unfolding sums_def by (simp add: setsum_negf tendsto_minus)
  10.451 -
  10.452 -lemma summable_minus:
  10.453 -  fixes X :: "nat \<Rightarrow> 'a::real_normed_field"
  10.454 -  shows "summable X \<Longrightarrow> summable (\<lambda>n. - X n)"
  10.455 -unfolding summable_def by (auto intro: sums_minus)
  10.456 -
  10.457 -lemma suminf_minus:
  10.458 -  fixes X :: "nat \<Rightarrow> 'a::real_normed_field"
  10.459 -  shows "summable X \<Longrightarrow> (\<Sum>n. - X n) = - (\<Sum>n. X n)"
  10.460 -by (intro sums_unique [symmetric] sums_minus summable_sums)
  10.461 +context
  10.462 +  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
  10.463 +begin
  10.464  
  10.465 -lemma sums_group:
  10.466 -  fixes f :: "nat \<Rightarrow> 'a::real_normed_field"
  10.467 -  shows "\<lbrakk>f sums s; 0 < k\<rbrakk> \<Longrightarrow> (\<lambda>n. setsum f {n*k..<n*k+k}) sums s"
  10.468 -apply (simp only: sums_def sumr_group)
  10.469 -apply (unfold LIMSEQ_iff, safe)
  10.470 -apply (drule_tac x="r" in spec, safe)
  10.471 -apply (rule_tac x="no" in exI, safe)
  10.472 -apply (drule_tac x="n*k" in spec)
  10.473 -apply (erule mp)
  10.474 -apply (erule order_trans)
  10.475 -apply simp
  10.476 -done
  10.477 -
  10.478 -text{*A summable series of positive terms has limit that is at least as
  10.479 -great as any partial sum.*}
  10.480 -
  10.481 -lemma pos_summable:
  10.482 -  fixes f:: "nat \<Rightarrow> real"
  10.483 -  assumes pos: "\<And>n. 0 \<le> f n" and le: "\<And>n. setsum f {0..<n} \<le> x"
  10.484 -  shows "summable f"
  10.485 -proof -
  10.486 -  have "convergent (\<lambda>n. setsum f {0..<n})"
  10.487 -    proof (rule Bseq_mono_convergent)
  10.488 -      show "Bseq (\<lambda>n. setsum f {0..<n})"
  10.489 -        by (intro BseqI'[of _ x]) (auto simp add: setsum_nonneg pos intro: le)
  10.490 -    next
  10.491 -      show "\<forall>m n. m \<le> n \<longrightarrow> setsum f {0..<m} \<le> setsum f {0..<n}"
  10.492 -        by (auto intro: setsum_mono2 pos)
  10.493 -    qed
  10.494 -  thus ?thesis
  10.495 -    by (force simp add: summable_def sums_def convergent_def)
  10.496 -qed
  10.497 -
  10.498 -lemma series_pos_le:
  10.499 -  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
  10.500 -  shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 \<le> f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} \<le> suminf f"
  10.501 -  apply (drule summable_sums)
  10.502 -  apply (simp add: sums_def)
  10.503 -  apply (rule LIMSEQ_le_const)
  10.504 +lemma series_pos_le: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 \<le> f m \<Longrightarrow> setsum f {..<n} \<le> suminf f"
  10.505 +  apply (rule LIMSEQ_le_const[OF summable_LIMSEQ])
  10.506    apply assumption
  10.507    apply (intro exI[of _ n])
  10.508 -  apply (auto intro!: setsum_mono2)
  10.509 +  apply (auto intro!: setsum_mono2 simp: not_le[symmetric])
  10.510    done
  10.511  
  10.512 -lemma series_pos_less:
  10.513 -  fixes f :: "nat \<Rightarrow> 'a::{ordered_ab_semigroup_add_imp_le, ordered_comm_monoid_add, linorder_topology}"
  10.514 -  shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 < f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} < suminf f"
  10.515 -  apply (rule_tac y="setsum f {0..<Suc n}" in order_less_le_trans)
  10.516 -  using add_less_cancel_left [of "setsum f {0..<n}" 0 "f n"]
  10.517 -  apply simp
  10.518 -  apply (erule series_pos_le)
  10.519 -  apply (simp add: order_less_imp_le)
  10.520 -  done
  10.521 -
  10.522 -lemma suminf_eq_zero_iff:
  10.523 -  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
  10.524 -  shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> suminf f = 0 \<longleftrightarrow> (\<forall>n. f n = 0)"
  10.525 +lemma suminf_eq_zero_iff: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> suminf f = 0 \<longleftrightarrow> (\<forall>n. f n = 0)"
  10.526  proof
  10.527    assume "summable f" "suminf f = 0" and pos: "\<forall>n. 0 \<le> f n"
  10.528    then have "f sums 0"
  10.529 @@ -419,77 +216,208 @@
  10.530    qed
  10.531    with pos show "\<forall>n. f n = 0"
  10.532      by (auto intro!: antisym)
  10.533 -next
  10.534 -  assume "\<forall>n. f n = 0"
  10.535 -  then have "f = (\<lambda>n. 0)"
  10.536 -    by auto
  10.537 -  then show "suminf f = 0"
  10.538 -    by simp
  10.539 +qed (metis suminf_zero fun_eq_iff)
  10.540 +
  10.541 +lemma suminf_gt_zero_iff: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 < suminf f \<longleftrightarrow> (\<exists>i. 0 < f i)"
  10.542 +  using series_pos_le[of 0] suminf_eq_zero_iff by (simp add: less_le)
  10.543 +
  10.544 +lemma suminf_gt_zero: "summable f \<Longrightarrow> \<forall>n. 0 < f n \<Longrightarrow> 0 < suminf f"
  10.545 +  using suminf_gt_zero_iff by (simp add: less_imp_le)
  10.546 +
  10.547 +lemma suminf_ge_zero: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 \<le> suminf f"
  10.548 +  by (drule_tac n="0" in series_pos_le) simp_all
  10.549 +
  10.550 +lemma suminf_le: "summable f \<Longrightarrow> (\<And>n. setsum f {..<n} \<le> x) \<Longrightarrow> suminf f \<le> x"
  10.551 +  by (metis LIMSEQ_le_const2 summable_LIMSEQ)
  10.552 +
  10.553 +lemma summable_le: "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
  10.554 +  by (rule LIMSEQ_le) (auto intro: setsum_mono summable_LIMSEQ)
  10.555 +
  10.556 +end
  10.557 +
  10.558 +lemma series_pos_less:
  10.559 +  fixes f :: "nat \<Rightarrow> 'a::{ordered_ab_semigroup_add_imp_le, ordered_comm_monoid_add, linorder_topology}"
  10.560 +  shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 < f m\<rbrakk> \<Longrightarrow> setsum f {..<n} < suminf f"
  10.561 +  apply simp
  10.562 +  apply (rule_tac y="setsum f {..<Suc n}" in order_less_le_trans)
  10.563 +  using add_less_cancel_left [of "setsum f {..<n}" 0 "f n"]
  10.564 +  apply simp
  10.565 +  apply (erule series_pos_le)
  10.566 +  apply (simp add: order_less_imp_le)
  10.567 +  done
  10.568 +
  10.569 +lemma sums_Suc_iff:
  10.570 +  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
  10.571 +  shows "(\<lambda>n. f (Suc n)) sums s \<longleftrightarrow> f sums (s + f 0)"
  10.572 +proof -
  10.573 +  have "f sums (s + f 0) \<longleftrightarrow> (\<lambda>i. \<Sum>j<Suc i. f j) ----> s + f 0"
  10.574 +    by (subst LIMSEQ_Suc_iff) (simp add: sums_def)
  10.575 +  also have "\<dots> \<longleftrightarrow> (\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) ----> s + f 0"
  10.576 +    by (simp add: ac_simps setsum_reindex image_iff lessThan_Suc_eq_insert_0)
  10.577 +  also have "\<dots> \<longleftrightarrow> (\<lambda>n. f (Suc n)) sums s"
  10.578 +  proof
  10.579 +    assume "(\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) ----> s + f 0"
  10.580 +    with tendsto_add[OF this tendsto_const, of "- f 0"]
  10.581 +    show "(\<lambda>i. f (Suc i)) sums s"
  10.582 +      by (simp add: sums_def)
  10.583 +  qed (auto intro: tendsto_add tendsto_const simp: sums_def)
  10.584 +  finally show ?thesis ..
  10.585  qed
  10.586  
  10.587 -lemma suminf_gt_zero_iff:
  10.588 -  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
  10.589 -  shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 < suminf f \<longleftrightarrow> (\<exists>i. 0 < f i)"
  10.590 -  using series_pos_le[of f 0] suminf_eq_zero_iff[of f]
  10.591 -  by (simp add: less_le)
  10.592 +context
  10.593 +  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
  10.594 +begin
  10.595 +
  10.596 +lemma sums_add: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n + g n) sums (a + b)"
  10.597 +  unfolding sums_def by (simp add: setsum_addf tendsto_add)
  10.598 +
  10.599 +lemma summable_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n + g n)"
  10.600 +  unfolding summable_def by (auto intro: sums_add)
  10.601 +
  10.602 +lemma suminf_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f + suminf g = (\<Sum>n. f n + g n)"
  10.603 +  by (intro sums_unique sums_add summable_sums)
  10.604 +
  10.605 +lemma sums_diff: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n - g n) sums (a - b)"
  10.606 +  unfolding sums_def by (simp add: setsum_subtractf tendsto_diff)
  10.607 +
  10.608 +lemma summable_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n - g n)"
  10.609 +  unfolding summable_def by (auto intro: sums_diff)
  10.610 +
  10.611 +lemma suminf_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f - suminf g = (\<Sum>n. f n - g n)"
  10.612 +  by (intro sums_unique sums_diff summable_sums)
  10.613 +
  10.614 +lemma sums_minus: "f sums a \<Longrightarrow> (\<lambda>n. - f n) sums (- a)"
  10.615 +  unfolding sums_def by (simp add: setsum_negf tendsto_minus)
  10.616 +
  10.617 +lemma summable_minus: "summable f \<Longrightarrow> summable (\<lambda>n. - f n)"
  10.618 +  unfolding summable_def by (auto intro: sums_minus)
  10.619  
  10.620 -lemma suminf_gt_zero:
  10.621 -  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
  10.622 -  shows "\<lbrakk>summable f; \<forall>n. 0 < f n\<rbrakk> \<Longrightarrow> 0 < suminf f"
  10.623 -  using suminf_gt_zero_iff[of f] by (simp add: less_imp_le)
  10.624 +lemma suminf_minus: "summable f \<Longrightarrow> (\<Sum>n. - f n) = - (\<Sum>n. f n)"
  10.625 +  by (intro sums_unique [symmetric] sums_minus summable_sums)
  10.626 +
  10.627 +lemma sums_Suc: "(\<lambda> n. f (Suc n)) sums l \<Longrightarrow> f sums (l + f 0)"
  10.628 +  by (simp add: sums_Suc_iff)
  10.629 +
  10.630 +lemma sums_iff_shift: "(\<lambda>i. f (i + n)) sums s \<longleftrightarrow> f sums (s + (\<Sum>i<n. f i))"
  10.631 +proof (induct n arbitrary: s)
  10.632 +  case (Suc n)
  10.633 +  moreover have "(\<lambda>i. f (Suc i + n)) sums s \<longleftrightarrow> (\<lambda>i. f (i + n)) sums (s + f n)"
  10.634 +    by (subst sums_Suc_iff) simp
  10.635 +  ultimately show ?case
  10.636 +    by (simp add: ac_simps)
  10.637 +qed simp
  10.638  
  10.639 -lemma suminf_ge_zero:
  10.640 -  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
  10.641 -  shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 \<le> suminf f"
  10.642 -  by (drule_tac n="0" in series_pos_le, simp_all)
  10.643 +lemma summable_iff_shift: "summable (\<lambda>n. f (n + k)) \<longleftrightarrow> summable f"
  10.644 +  by (metis diff_add_cancel summable_def sums_iff_shift[abs_def])
  10.645 +
  10.646 +lemma sums_split_initial_segment: "f sums s \<Longrightarrow> (\<lambda>i. f (i + n)) sums (s - (\<Sum>i<n. f i))"
  10.647 +  by (simp add: sums_iff_shift)
  10.648 +
  10.649 +lemma summable_ignore_initial_segment: "summable f \<Longrightarrow> summable (\<lambda>n. f(n + k))"
  10.650 +  by (simp add: summable_iff_shift)
  10.651 +
  10.652 +lemma suminf_minus_initial_segment: "summable f \<Longrightarrow> (\<Sum>n. f (n + k)) = (\<Sum>n. f n) - (\<Sum>i<k. f i)"
  10.653 +  by (rule sums_unique[symmetric]) (auto simp: sums_iff_shift)
  10.654 +
  10.655 +lemma suminf_split_initial_segment: "summable f \<Longrightarrow> suminf f = (\<Sum>n. f(n + k)) + (\<Sum>i<k. f i)"
  10.656 +  by (auto simp add: suminf_minus_initial_segment)
  10.657  
  10.658 -lemma sumr_pos_lt_pair:
  10.659 -  fixes f :: "nat \<Rightarrow> real"
  10.660 -  shows "\<lbrakk>summable f;
  10.661 -        \<And>d. 0 < f (k + (Suc(Suc 0) * d)) + f (k + ((Suc(Suc 0) * d) + 1))\<rbrakk>
  10.662 -      \<Longrightarrow> setsum f {0..<k} < suminf f"
  10.663 -unfolding One_nat_def
  10.664 -apply (subst suminf_split_initial_segment [where k="k"])
  10.665 -apply assumption
  10.666 -apply simp
  10.667 -apply (drule_tac k="k" in summable_ignore_initial_segment)
  10.668 -apply (drule_tac k="Suc (Suc 0)" in sums_group [OF summable_sums], simp)
  10.669 -apply simp
  10.670 -apply (frule sums_unique)
  10.671 -apply (drule sums_summable)
  10.672 -apply simp
  10.673 -apply (erule suminf_gt_zero)
  10.674 -apply (simp add: add_ac)
  10.675 -done
  10.676 +lemma suminf_exist_split: 
  10.677 +  fixes r :: real assumes "0 < r" and "summable f"
  10.678 +  shows "\<exists>N. \<forall>n\<ge>N. norm (\<Sum>i. f (i + n)) < r"
  10.679 +proof -
  10.680 +  from LIMSEQ_D[OF summable_LIMSEQ[OF `summable f`] `0 < r`]
  10.681 +  obtain N :: nat where "\<forall> n \<ge> N. norm (setsum f {..<n} - suminf f) < r" by auto
  10.682 +  thus ?thesis
  10.683 +    by (auto simp: norm_minus_commute suminf_minus_initial_segment[OF `summable f`])
  10.684 +qed
  10.685 +
  10.686 +lemma summable_LIMSEQ_zero: "summable f \<Longrightarrow> f ----> 0"
  10.687 +  apply (drule summable_iff_convergent [THEN iffD1])
  10.688 +  apply (drule convergent_Cauchy)
  10.689 +  apply (simp only: Cauchy_iff LIMSEQ_iff, safe)
  10.690 +  apply (drule_tac x="r" in spec, safe)
  10.691 +  apply (rule_tac x="M" in exI, safe)
  10.692 +  apply (drule_tac x="Suc n" in spec, simp)
  10.693 +  apply (drule_tac x="n" in spec, simp)
  10.694 +  done
  10.695 +
  10.696 +end
  10.697 +
  10.698 +lemma (in bounded_linear) sums: "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
  10.699 +  unfolding sums_def by (drule tendsto, simp only: setsum)
  10.700 +
  10.701 +lemma (in bounded_linear) summable: "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
  10.702 +  unfolding summable_def by (auto intro: sums)
  10.703 +
  10.704 +lemma (in bounded_linear) suminf: "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
  10.705 +  by (intro sums_unique sums summable_sums)
  10.706 +
  10.707 +lemmas sums_of_real = bounded_linear.sums [OF bounded_linear_of_real]
  10.708 +lemmas summable_of_real = bounded_linear.summable [OF bounded_linear_of_real]
  10.709 +lemmas suminf_of_real = bounded_linear.suminf [OF bounded_linear_of_real]
  10.710 +
  10.711 +context
  10.712 +  fixes f :: "nat \<Rightarrow> 'a::real_normed_algebra"
  10.713 +begin
  10.714 +
  10.715 +lemma sums_mult: "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
  10.716 +  by (rule bounded_linear.sums [OF bounded_linear_mult_right])
  10.717 +
  10.718 +lemma summable_mult: "summable f \<Longrightarrow> summable (\<lambda>n. c * f n)"
  10.719 +  by (rule bounded_linear.summable [OF bounded_linear_mult_right])
  10.720 +
  10.721 +lemma suminf_mult: "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f"
  10.722 +  by (rule bounded_linear.suminf [OF bounded_linear_mult_right, symmetric])
  10.723 +
  10.724 +lemma sums_mult2: "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
  10.725 +  by (rule bounded_linear.sums [OF bounded_linear_mult_left])
  10.726 +
  10.727 +lemma summable_mult2: "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
  10.728 +  by (rule bounded_linear.summable [OF bounded_linear_mult_left])
  10.729 +
  10.730 +lemma suminf_mult2: "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
  10.731 +  by (rule bounded_linear.suminf [OF bounded_linear_mult_left])
  10.732 +
  10.733 +end
  10.734 +
  10.735 +context
  10.736 +  fixes c :: "'a::real_normed_field"
  10.737 +begin
  10.738 +
  10.739 +lemma sums_divide: "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
  10.740 +  by (rule bounded_linear.sums [OF bounded_linear_divide])
  10.741 +
  10.742 +lemma summable_divide: "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
  10.743 +  by (rule bounded_linear.summable [OF bounded_linear_divide])
  10.744 +
  10.745 +lemma suminf_divide: "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
  10.746 +  by (rule bounded_linear.suminf [OF bounded_linear_divide, symmetric])
  10.747  
  10.748  text{*Sum of a geometric progression.*}
  10.749  
  10.750 -lemmas sumr_geometric = geometric_sum [where 'a = real]
  10.751 -
  10.752 -lemma geometric_sums:
  10.753 -  fixes x :: "'a::{real_normed_field}"
  10.754 -  shows "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) sums (1 / (1 - x))"
  10.755 +lemma geometric_sums: "norm c < 1 \<Longrightarrow> (\<lambda>n. c^n) sums (1 / (1 - c))"
  10.756  proof -
  10.757 -  assume less_1: "norm x < 1"
  10.758 -  hence neq_1: "x \<noteq> 1" by auto
  10.759 -  hence neq_0: "x - 1 \<noteq> 0" by simp
  10.760 -  from less_1 have lim_0: "(\<lambda>n. x ^ n) ----> 0"
  10.761 +  assume less_1: "norm c < 1"
  10.762 +  hence neq_1: "c \<noteq> 1" by auto
  10.763 +  hence neq_0: "c - 1 \<noteq> 0" by simp
  10.764 +  from less_1 have lim_0: "(\<lambda>n. c^n) ----> 0"
  10.765      by (rule LIMSEQ_power_zero)
  10.766 -  hence "(\<lambda>n. x ^ n / (x - 1) - 1 / (x - 1)) ----> 0 / (x - 1) - 1 / (x - 1)"
  10.767 +  hence "(\<lambda>n. c ^ n / (c - 1) - 1 / (c - 1)) ----> 0 / (c - 1) - 1 / (c - 1)"
  10.768      using neq_0 by (intro tendsto_intros)
  10.769 -  hence "(\<lambda>n. (x ^ n - 1) / (x - 1)) ----> 1 / (1 - x)"
  10.770 +  hence "(\<lambda>n. (c ^ n - 1) / (c - 1)) ----> 1 / (1 - c)"
  10.771      by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
  10.772 -  thus "(\<lambda>n. x ^ n) sums (1 / (1 - x))"
  10.773 +  thus "(\<lambda>n. c ^ n) sums (1 / (1 - c))"
  10.774      by (simp add: sums_def geometric_sum neq_1)
  10.775  qed
  10.776  
  10.777 -lemma summable_geometric:
  10.778 -  fixes x :: "'a::{real_normed_field}"
  10.779 -  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
  10.780 -by (rule geometric_sums [THEN sums_summable])
  10.781 +lemma summable_geometric: "norm c < 1 \<Longrightarrow> summable (\<lambda>n. c^n)"
  10.782 +  by (rule geometric_sums [THEN sums_summable])
  10.783  
  10.784 -lemma half: "0 < 1 / (2::'a::linordered_field)"
  10.785 -  by simp
  10.786 +lemma suminf_geometric: "norm c < 1 \<Longrightarrow> suminf (\<lambda>n. c^n) = 1 / (1 - c)"
  10.787 +  by (rule sums_unique[symmetric]) (rule geometric_sums)
  10.788 +
  10.789 +end
  10.790  
  10.791  lemma power_half_series: "(\<lambda>n. (1/2::real)^Suc n) sums 1"
  10.792  proof -
  10.793 @@ -503,110 +431,104 @@
  10.794  
  10.795  text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
  10.796  
  10.797 -lemma summable_convergent_sumr_iff:
  10.798 - "summable f = convergent (%n. setsum f {0..<n})"
  10.799 -by (simp add: summable_def sums_def convergent_def)
  10.800 +lemma summable_Cauchy:
  10.801 +  fixes f :: "nat \<Rightarrow> 'a::banach"
  10.802 +  shows "summable f \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m\<ge>N. \<forall>n. norm (setsum f {m..<n}) < e)"
  10.803 +  apply (simp only: summable_iff_convergent Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
  10.804 +  apply (drule spec, drule (1) mp)
  10.805 +  apply (erule exE, rule_tac x="M" in exI, clarify)
  10.806 +  apply (rule_tac x="m" and y="n" in linorder_le_cases)
  10.807 +  apply (frule (1) order_trans)
  10.808 +  apply (drule_tac x="n" in spec, drule (1) mp)
  10.809 +  apply (drule_tac x="m" in spec, drule (1) mp)
  10.810 +  apply (simp_all add: setsum_diff [symmetric])
  10.811 +  apply (drule spec, drule (1) mp)
  10.812 +  apply (erule exE, rule_tac x="N" in exI, clarify)
  10.813 +  apply (rule_tac x="m" and y="n" in linorder_le_cases)
  10.814 +  apply (subst norm_minus_commute)
  10.815 +  apply (simp_all add: setsum_diff [symmetric])
  10.816 +  done
  10.817  
  10.818 -lemma summable_LIMSEQ_zero:
  10.819 -  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
  10.820 -  shows "summable f \<Longrightarrow> f ----> 0"
  10.821 -apply (drule summable_convergent_sumr_iff [THEN iffD1])
  10.822 -apply (drule convergent_Cauchy)
  10.823 -apply (simp only: Cauchy_iff LIMSEQ_iff, safe)
  10.824 -apply (drule_tac x="r" in spec, safe)
  10.825 -apply (rule_tac x="M" in exI, safe)
  10.826 -apply (drule_tac x="Suc n" in spec, simp)
  10.827 -apply (drule_tac x="n" in spec, simp)
  10.828 -done
  10.829 +context
  10.830 +  fixes f :: "nat \<Rightarrow> 'a::banach"
  10.831 +begin  
  10.832 +
  10.833 +text{*Absolute convergence imples normal convergence*}
  10.834  
  10.835 -lemma suminf_le:
  10.836 -  fixes x :: "'a :: {ordered_comm_monoid_add, linorder_topology}"
  10.837 -  shows "summable f \<Longrightarrow> (!!n. setsum f {0..<n} \<le> x) \<Longrightarrow> suminf f \<le> x"
  10.838 -  apply (drule summable_sums)
  10.839 -  apply (simp add: sums_def)
  10.840 -  apply (rule LIMSEQ_le_const2)
  10.841 -  apply assumption
  10.842 -  apply auto
  10.843 +lemma summable_norm_cancel:
  10.844 +  "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
  10.845 +  apply (simp only: summable_Cauchy, safe)
  10.846 +  apply (drule_tac x="e" in spec, safe)
  10.847 +  apply (rule_tac x="N" in exI, safe)
  10.848 +  apply (drule_tac x="m" in spec, safe)
  10.849 +  apply (rule order_le_less_trans [OF norm_setsum])
  10.850 +  apply (rule order_le_less_trans [OF abs_ge_self])
  10.851 +  apply simp
  10.852    done
  10.853  
  10.854 -lemma summable_Cauchy:
  10.855 -     "summable (f::nat \<Rightarrow> 'a::banach) =
  10.856 -      (\<forall>e > 0. \<exists>N. \<forall>m \<ge> N. \<forall>n. norm (setsum f {m..<n}) < e)"
  10.857 -apply (simp only: summable_convergent_sumr_iff Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
  10.858 -apply (drule spec, drule (1) mp)
  10.859 -apply (erule exE, rule_tac x="M" in exI, clarify)
  10.860 -apply (rule_tac x="m" and y="n" in linorder_le_cases)
  10.861 -apply (frule (1) order_trans)
  10.862 -apply (drule_tac x="n" in spec, drule (1) mp)
  10.863 -apply (drule_tac x="m" in spec, drule (1) mp)
  10.864 -apply (simp add: setsum_diff [symmetric])
  10.865 -apply simp
  10.866 -apply (drule spec, drule (1) mp)
  10.867 -apply (erule exE, rule_tac x="N" in exI, clarify)
  10.868 -apply (rule_tac x="m" and y="n" in linorder_le_cases)
  10.869 -apply (subst norm_minus_commute)
  10.870 -apply (simp add: setsum_diff [symmetric])
  10.871 -apply (simp add: setsum_diff [symmetric])
  10.872 -done
  10.873 +lemma summable_norm: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
  10.874 +  by (auto intro: LIMSEQ_le tendsto_norm summable_norm_cancel summable_LIMSEQ norm_setsum)
  10.875 +
  10.876 +text {* Comparison tests *}
  10.877  
  10.878 -text{*Comparison test*}
  10.879 +lemma summable_comparison_test: "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f"
  10.880 +  apply (simp add: summable_Cauchy, safe)
  10.881 +  apply (drule_tac x="e" in spec, safe)
  10.882 +  apply (rule_tac x = "N + Na" in exI, safe)
  10.883 +  apply (rotate_tac 2)
  10.884 +  apply (drule_tac x = m in spec)
  10.885 +  apply (auto, rotate_tac 2, drule_tac x = n in spec)
  10.886 +  apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
  10.887 +  apply (rule norm_setsum)
  10.888 +  apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
  10.889 +  apply (auto intro: setsum_mono simp add: abs_less_iff)
  10.890 +  done
  10.891 +
  10.892 +subsection {* The Ratio Test*}
  10.893  
  10.894 -lemma norm_setsum:
  10.895 -  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  10.896 -  shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
  10.897 -apply (case_tac "finite A")
  10.898 -apply (erule finite_induct)
  10.899 -apply simp
  10.900 -apply simp
  10.901 -apply (erule order_trans [OF norm_triangle_ineq add_left_mono])
  10.902 -apply simp
  10.903 -done
  10.904 -
  10.905 -lemma norm_bound_subset:
  10.906 -  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  10.907 -  assumes "finite s" "t \<subseteq> s"
  10.908 -  assumes le: "(\<And>x. x \<in> s \<Longrightarrow> norm(f x) \<le> g x)"
  10.909 -  shows "norm (setsum f t) \<le> setsum g s"
  10.910 -proof -
  10.911 -  have "norm (setsum f t) \<le> (\<Sum>i\<in>t. norm (f i))"
  10.912 -    by (rule norm_setsum)
  10.913 -  also have "\<dots> \<le> (\<Sum>i\<in>t. g i)"
  10.914 -    using assms by (auto intro!: setsum_mono)
  10.915 -  also have "\<dots> \<le> setsum g s"
  10.916 -    using assms order.trans[OF norm_ge_zero le]
  10.917 -    by (auto intro!: setsum_mono3)
  10.918 -  finally show ?thesis .
  10.919 +lemma summable_ratio_test: 
  10.920 +  assumes "c < 1" "\<And>n. n \<ge> N \<Longrightarrow> norm (f (Suc n)) \<le> c * norm (f n)"
  10.921 +  shows "summable f"
  10.922 +proof cases
  10.923 +  assume "0 < c"
  10.924 +  show "summable f"
  10.925 +  proof (rule summable_comparison_test)
  10.926 +    show "\<exists>N'. \<forall>n\<ge>N'. norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
  10.927 +    proof (intro exI allI impI)
  10.928 +      fix n assume "N \<le> n" then show "norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
  10.929 +      proof (induct rule: inc_induct)
  10.930 +        case (step m)
  10.931 +        moreover have "norm (f (Suc m)) / c ^ Suc m * c ^ n \<le> norm (f m) / c ^ m * c ^ n"
  10.932 +          using `0 < c` `c < 1` assms(2)[OF `N \<le> m`] by (simp add: field_simps)
  10.933 +        ultimately show ?case by simp
  10.934 +      qed (insert `0 < c`, simp)
  10.935 +    qed
  10.936 +    show "summable (\<lambda>n. norm (f N) / c ^ N * c ^ n)"
  10.937 +      using `0 < c` `c < 1` by (intro summable_mult summable_geometric) simp
  10.938 +  qed
  10.939 +next
  10.940 +  assume c: "\<not> 0 < c"
  10.941 +  { fix n assume "n \<ge> N"
  10.942 +    then have "norm (f (Suc n)) \<le> c * norm (f n)"
  10.943 +      by fact
  10.944 +    also have "\<dots> \<le> 0"
  10.945 +      using c by (simp add: not_less mult_nonpos_nonneg)
  10.946 +    finally have "f (Suc n) = 0"
  10.947 +      by auto }
  10.948 +  then show "summable f"
  10.949 +    by (intro sums_summable[OF sums_finite, of "{.. Suc N}"]) (auto simp: not_le Suc_less_iff)
  10.950  qed
  10.951  
  10.952 -lemma summable_comparison_test:
  10.953 -  fixes f :: "nat \<Rightarrow> 'a::banach"
  10.954 -  shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f"
  10.955 -apply (simp add: summable_Cauchy, safe)
  10.956 -apply (drule_tac x="e" in spec, safe)
  10.957 -apply (rule_tac x = "N + Na" in exI, safe)
  10.958 -apply (rotate_tac 2)
  10.959 -apply (drule_tac x = m in spec)
  10.960 -apply (auto, rotate_tac 2, drule_tac x = n in spec)
  10.961 -apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
  10.962 -apply (rule norm_setsum)
  10.963 -apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
  10.964 -apply (auto intro: setsum_mono simp add: abs_less_iff)
  10.965 -done
  10.966 +end
  10.967  
  10.968  lemma summable_norm_comparison_test:
  10.969 -  fixes f :: "nat \<Rightarrow> 'a::banach"
  10.970 -  shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk>
  10.971 -         \<Longrightarrow> summable (\<lambda>n. norm (f n))"
  10.972 -apply (rule summable_comparison_test)
  10.973 -apply (auto)
  10.974 -done
  10.975 +  "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable (\<lambda>n. norm (f n))"
  10.976 +  by (rule summable_comparison_test) auto
  10.977  
  10.978 -lemma summable_rabs_comparison_test:
  10.979 +lemma summable_rabs_cancel:
  10.980    fixes f :: "nat \<Rightarrow> real"
  10.981 -  shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable (\<lambda>n. \<bar>f n\<bar>)"
  10.982 -apply (rule summable_comparison_test)
  10.983 -apply (auto)
  10.984 -done
  10.985 +  shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> summable f"
  10.986 +  by (rule summable_norm_cancel) simp
  10.987  
  10.988  text{*Summability of geometric series for real algebras*}
  10.989  
  10.990 @@ -620,119 +542,34 @@
  10.991      by (simp add: summable_geometric)
  10.992  qed
  10.993  
  10.994 -text{*Limit comparison property for series (c.f. jrh)*}
  10.995  
  10.996 -lemma summable_le:
  10.997 -  fixes f g :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
  10.998 -  shows "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
  10.999 -apply (drule summable_sums)+
 10.1000 -apply (simp only: sums_def, erule (1) LIMSEQ_le)
 10.1001 -apply (rule exI)
 10.1002 -apply (auto intro!: setsum_mono)
 10.1003 -done
 10.1004 -
 10.1005 -lemma summable_le2:
 10.1006 -  fixes f g :: "nat \<Rightarrow> real"
 10.1007 -  shows "\<lbrakk>\<forall>n. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f \<and> suminf f \<le> suminf g"
 10.1008 -apply (subgoal_tac "summable f")
 10.1009 -apply (auto intro!: summable_le)
 10.1010 -apply (simp add: abs_le_iff)
 10.1011 -apply (rule_tac g="g" in summable_comparison_test, simp_all)
 10.1012 -done
 10.1013 +text{*A summable series of positive terms has limit that is at least as
 10.1014 +great as any partial sum.*}
 10.1015  
 10.1016 -(* specialisation for the common 0 case *)
 10.1017 -lemma suminf_0_le:
 10.1018 -  fixes f::"nat\<Rightarrow>real"
 10.1019 -  assumes gt0: "\<forall>n. 0 \<le> f n" and sm: "summable f"
 10.1020 -  shows "0 \<le> suminf f"
 10.1021 -  using suminf_ge_zero[OF sm gt0] by simp
 10.1022 +lemma pos_summable:
 10.1023 +  fixes f:: "nat \<Rightarrow> real"
 10.1024 +  assumes pos: "\<And>n. 0 \<le> f n" and le: "\<And>n. setsum f {..<n} \<le> x"
 10.1025 +  shows "summable f"
 10.1026 +proof -
 10.1027 +  have "convergent (\<lambda>n. setsum f {..<n})"
 10.1028 +  proof (rule Bseq_mono_convergent)
 10.1029 +    show "Bseq (\<lambda>n. setsum f {..<n})"
 10.1030 +      by (intro BseqI'[of _ x]) (auto simp add: setsum_nonneg pos intro: le)
 10.1031 +  qed (auto intro: setsum_mono2 pos)
 10.1032 +  thus ?thesis
 10.1033 +    by (force simp add: summable_def sums_def convergent_def)
 10.1034 +qed
 10.1035  
 10.1036 -text{*Absolute convergence imples normal convergence*}
 10.1037 -lemma summable_norm_cancel:
 10.1038 -  fixes f :: "nat \<Rightarrow> 'a::banach"
 10.1039 -  shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
 10.1040 -apply (simp only: summable_Cauchy, safe)
 10.1041 -apply (drule_tac x="e" in spec, safe)
 10.1042 -apply (rule_tac x="N" in exI, safe)
 10.1043 -apply (drule_tac x="m" in spec, safe)
 10.1044 -apply (rule order_le_less_trans [OF norm_setsum])
 10.1045 -apply (rule order_le_less_trans [OF abs_ge_self])
 10.1046 -apply simp
 10.1047 -done
 10.1048 -
 10.1049 -lemma summable_rabs_cancel:
 10.1050 +lemma summable_rabs_comparison_test:
 10.1051    fixes f :: "nat \<Rightarrow> real"
 10.1052 -  shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> summable f"
 10.1053 -by (rule summable_norm_cancel, simp)
 10.1054 -
 10.1055 -text{*Absolute convergence of series*}
 10.1056 -lemma summable_norm:
 10.1057 -  fixes f :: "nat \<Rightarrow> 'a::banach"
 10.1058 -  shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
 10.1059 -  by (auto intro: LIMSEQ_le tendsto_norm summable_norm_cancel
 10.1060 -                summable_sumr_LIMSEQ_suminf norm_setsum)
 10.1061 +  shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable (\<lambda>n. \<bar>f n\<bar>)"
 10.1062 +  by (rule summable_comparison_test) auto
 10.1063  
 10.1064  lemma summable_rabs:
 10.1065    fixes f :: "nat \<Rightarrow> real"
 10.1066    shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> \<bar>suminf f\<bar> \<le> (\<Sum>n. \<bar>f n\<bar>)"
 10.1067  by (fold real_norm_def, rule summable_norm)
 10.1068  
 10.1069 -subsection{* The Ratio Test*}
 10.1070 -
 10.1071 -lemma norm_ratiotest_lemma:
 10.1072 -  fixes x y :: "'a::real_normed_vector"
 10.1073 -  shows "\<lbrakk>c \<le> 0; norm x \<le> c * norm y\<rbrakk> \<Longrightarrow> x = 0"
 10.1074 -apply (subgoal_tac "norm x \<le> 0", simp)
 10.1075 -apply (erule order_trans)
 10.1076 -apply (simp add: mult_le_0_iff)
 10.1077 -done
 10.1078 -
 10.1079 -lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
 10.1080 -by (erule norm_ratiotest_lemma, simp)
 10.1081 -
 10.1082 -(* TODO: MOVE *)
 10.1083 -lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
 10.1084 -apply (drule le_imp_less_or_eq)
 10.1085 -apply (auto dest: less_imp_Suc_add)
 10.1086 -done
 10.1087 -
 10.1088 -lemma le_Suc_ex_iff: "((k::nat) \<le> l) = (\<exists>n. l = k + n)"
 10.1089 -by (auto simp add: le_Suc_ex)
 10.1090 -
 10.1091 -(*All this trouble just to get 0<c *)
 10.1092 -lemma ratio_test_lemma2:
 10.1093 -  fixes f :: "nat \<Rightarrow> 'a::banach"
 10.1094 -  shows "\<lbrakk>\<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> 0 < c \<or> summable f"
 10.1095 -apply (simp (no_asm) add: linorder_not_le [symmetric])
 10.1096 -apply (simp add: summable_Cauchy)
 10.1097 -apply (safe, subgoal_tac "\<forall>n. N < n --> f (n) = 0")
 10.1098 - prefer 2
 10.1099 - apply clarify
 10.1100 - apply(erule_tac x = "n - Suc 0" in allE)
 10.1101 - apply (simp add:diff_Suc split:nat.splits)
 10.1102 - apply (blast intro: norm_ratiotest_lemma)
 10.1103 -apply (rule_tac x = "Suc N" in exI, clarify)
 10.1104 -apply(simp cong del: setsum_cong cong: setsum_ivl_cong)
 10.1105 -done
 10.1106 -
 10.1107 -lemma ratio_test:
 10.1108 -  fixes f :: "nat \<Rightarrow> 'a::banach"
 10.1109 -  shows "\<lbrakk>c < 1; \<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> summable f"
 10.1110 -apply (frule ratio_test_lemma2, auto)
 10.1111 -apply (rule_tac g = "%n. (norm (f N) / (c ^ N))*c ^ n"
 10.1112 -       in summable_comparison_test)
 10.1113 -apply (rule_tac x = N in exI, safe)
 10.1114 -apply (drule le_Suc_ex_iff [THEN iffD1])
 10.1115 -apply (auto simp add: power_add field_power_not_zero)
 10.1116 -apply (induct_tac "na", auto)
 10.1117 -apply (rule_tac y = "c * norm (f (N + n))" in order_trans)
 10.1118 -apply (auto intro: mult_right_mono simp add: summable_def)
 10.1119 -apply (rule_tac x = "norm (f N) * (1/ (1 - c)) / (c ^ N)" in exI)
 10.1120 -apply (rule sums_divide)
 10.1121 -apply (rule sums_mult)
 10.1122 -apply (auto intro!: geometric_sums)
 10.1123 -done
 10.1124 -
 10.1125  subsection {* Cauchy Product Formula *}
 10.1126  
 10.1127  text {*
 10.1128 @@ -742,14 +579,14 @@
 10.1129  
 10.1130  lemma setsum_triangle_reindex:
 10.1131    fixes n :: nat
 10.1132 -  shows "(\<Sum>(i,j)\<in>{(i,j). i+j < n}. f i j) = (\<Sum>k=0..<n. \<Sum>i=0..k. f i (k - i))"
 10.1133 +  shows "(\<Sum>(i,j)\<in>{(i,j). i+j < n}. f i j) = (\<Sum>k<n. \<Sum>i=0..k. f i (k - i))"
 10.1134  proof -
 10.1135    have "(\<Sum>(i, j)\<in>{(i, j). i + j < n}. f i j) =
 10.1136 -    (\<Sum>(k, i)\<in>(SIGMA k:{0..<n}. {0..k}). f i (k - i))"
 10.1137 +    (\<Sum>(k, i)\<in>(SIGMA k:{..<n}. {0..k}). f i (k - i))"
 10.1138    proof (rule setsum_reindex_cong)
 10.1139 -    show "inj_on (\<lambda>(k,i). (i, k - i)) (SIGMA k:{0..<n}. {0..k})"
 10.1140 +    show "inj_on (\<lambda>(k,i). (i, k - i)) (SIGMA k:{..<n}. {0..k})"
 10.1141        by (rule inj_on_inverseI [where g="\<lambda>(i,j). (i+j, i)"], auto)
 10.1142 -    show "{(i,j). i + j < n} = (\<lambda>(k,i). (i, k - i)) ` (SIGMA k:{0..<n}. {0..k})"
 10.1143 +    show "{(i,j). i + j < n} = (\<lambda>(k,i). (i, k - i)) ` (SIGMA k:{..<n}. {0..k})"
 10.1144        by (safe, rule_tac x="(a+b,a)" in image_eqI, auto)
 10.1145      show "\<And>a. (\<lambda>(k, i). f i (k - i)) a = split f ((\<lambda>(k, i). (i, k - i)) a)"
 10.1146        by clarify
 10.1147 @@ -763,7 +600,7 @@
 10.1148    assumes b: "summable (\<lambda>k. norm (b k))"
 10.1149    shows "(\<lambda>k. \<Sum>i=0..k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
 10.1150  proof -
 10.1151 -  let ?S1 = "\<lambda>n::nat. {0..<n} \<times> {0..<n}"
 10.1152 +  let ?S1 = "\<lambda>n::nat. {..<n} \<times> {..<n}"
 10.1153    let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
 10.1154    have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
 10.1155    have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
 10.1156 @@ -779,20 +616,15 @@
 10.1157      unfolding real_norm_def
 10.1158      by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
 10.1159  
 10.1160 -  have "(\<lambda>n. (\<Sum>k=0..<n. a k) * (\<Sum>k=0..<n. b k))
 10.1161 -           ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
 10.1162 -    by (intro tendsto_mult summable_sumr_LIMSEQ_suminf
 10.1163 -        summable_norm_cancel [OF a] summable_norm_cancel [OF b])
 10.1164 +  have "(\<lambda>n. (\<Sum>k<n. a k) * (\<Sum>k<n. b k)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
 10.1165 +    by (intro tendsto_mult summable_LIMSEQ summable_norm_cancel [OF a] summable_norm_cancel [OF b])
 10.1166    hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
 10.1167 -    by (simp only: setsum_product setsum_Sigma [rule_format]
 10.1168 -                   finite_atLeastLessThan)
 10.1169 +    by (simp only: setsum_product setsum_Sigma [rule_format] finite_lessThan)
 10.1170  
 10.1171 -  have "(\<lambda>n. (\<Sum>k=0..<n. norm (a k)) * (\<Sum>k=0..<n. norm (b k)))
 10.1172 -       ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
 10.1173 -    using a b by (intro tendsto_mult summable_sumr_LIMSEQ_suminf)
 10.1174 +  have "(\<lambda>n. (\<Sum>k<n. norm (a k)) * (\<Sum>k<n. norm (b k))) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
 10.1175 +    using a b by (intro tendsto_mult summable_LIMSEQ)
 10.1176    hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
 10.1177 -    by (simp only: setsum_product setsum_Sigma [rule_format]
 10.1178 -                   finite_atLeastLessThan)
 10.1179 +    by (simp only: setsum_product setsum_Sigma [rule_format] finite_lessThan)
 10.1180    hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
 10.1181      by (rule convergentI)
 10.1182    hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
    11.1 --- a/src/HOL/Set_Interval.thy	Tue Mar 18 14:32:23 2014 +0100
    11.2 +++ b/src/HOL/Set_Interval.thy	Tue Mar 18 15:53:48 2014 +0100
    11.3 @@ -1472,10 +1472,10 @@
    11.4  
    11.5  lemma geometric_sum:
    11.6    assumes "x \<noteq> 1"
    11.7 -  shows "(\<Sum>i=0..<n. x ^ i) = (x ^ n - 1) / (x - 1::'a::field)"
    11.8 +  shows "(\<Sum>i<n. x ^ i) = (x ^ n - 1) / (x - 1::'a::field)"
    11.9  proof -
   11.10    from assms obtain y where "y = x - 1" and "y \<noteq> 0" by simp_all
   11.11 -  moreover have "(\<Sum>i=0..<n. (y + 1) ^ i) = ((y + 1) ^ n - 1) / y"
   11.12 +  moreover have "(\<Sum>i<n. (y + 1) ^ i) = ((y + 1) ^ n - 1) / y"
   11.13    proof (induct n)
   11.14      case 0 then show ?case by simp
   11.15    next
   11.16 @@ -1490,8 +1490,7 @@
   11.17  subsection {* The formula for arithmetic sums *}
   11.18  
   11.19  lemma gauss_sum:
   11.20 -  "(2::'a::comm_semiring_1)*(\<Sum>i\<in>{1..n}. of_nat i) =
   11.21 -   of_nat n*((of_nat n)+1)"
   11.22 +  "(2::'a::comm_semiring_1)*(\<Sum>i\<in>{1..n}. of_nat i) = of_nat n*((of_nat n)+1)"
   11.23  proof (induct n)
   11.24    case 0
   11.25    show ?case by simp
   11.26 @@ -1575,8 +1574,8 @@
   11.27  
   11.28  lemma nat_diff_setsum_reindex:
   11.29    fixes x :: "'a::{comm_ring,monoid_mult}"
   11.30 -  shows "(\<Sum>i=0..<n. f (n - Suc i)) = (\<Sum>i=0..<n. f i)"
   11.31 -apply (subst setsum_reindex_cong [of "%i. n - Suc i" "{0..< n}"])
   11.32 +  shows "(\<Sum>i<n. f (n - Suc i)) = (\<Sum>i<n. f i)"
   11.33 +apply (subst setsum_reindex_cong [of "%i. n - Suc i" "{..< n}"])
   11.34  apply (auto simp: inj_on_def)
   11.35  apply (rule_tac x="n - Suc x" in image_eqI, auto)
   11.36  done
    12.1 --- a/src/HOL/Taylor.thy	Tue Mar 18 14:32:23 2014 +0100
    12.2 +++ b/src/HOL/Taylor.thy	Tue Mar 18 15:53:48 2014 +0100
    12.3 @@ -18,8 +18,7 @@
    12.4    and DERIV: "(\<forall> m t. m < n & a \<le> t & t \<le> b \<longrightarrow> DERIV (diff m) t :> (diff (Suc m) t))"
    12.5    and INTERV: "a \<le> c" "c < b" 
    12.6    shows "\<exists> t. c < t & t < b & 
    12.7 -    f b = setsum (%m. (diff m c / real (fact m)) * (b - c)^m) {0..<n} +
    12.8 -      (diff n t / real (fact n)) * (b - c)^n"
    12.9 +    f b = (\<Sum>m<n. (diff m c / real (fact m)) * (b - c)^m) + (diff n t / real (fact n)) * (b - c)^n"
   12.10  proof -
   12.11    from INTERV have "0 < b-c" by arith
   12.12    moreover 
   12.13 @@ -38,17 +37,17 @@
   12.14    qed
   12.15    ultimately 
   12.16    have EX:"EX t>0. t < b - c & 
   12.17 -    f (b - c + c) = (SUM m = 0..<n. diff m (0 + c) / real (fact m) * (b - c) ^ m) +
   12.18 +    f (b - c + c) = (SUM m<n. diff m (0 + c) / real (fact m) * (b - c) ^ m) +
   12.19        diff n (t + c) / real (fact n) * (b - c) ^ n" 
   12.20      by (rule Maclaurin)
   12.21    show ?thesis
   12.22    proof -
   12.23      from EX obtain x where 
   12.24        X: "0 < x & x < b - c & 
   12.25 -        f (b - c + c) = (\<Sum>m = 0..<n. diff m (0 + c) / real (fact m) * (b - c) ^ m) +
   12.26 +        f (b - c + c) = (\<Sum>m<n. diff m (0 + c) / real (fact m) * (b - c) ^ m) +
   12.27            diff n (x + c) / real (fact n) * (b - c) ^ n" ..
   12.28      let ?H = "x + c"
   12.29 -    from X have "c<?H & ?H<b \<and> f b = (\<Sum>m = 0..<n. diff m c / real (fact m) * (b - c) ^ m) +
   12.30 +    from X have "c<?H & ?H<b \<and> f b = (\<Sum>m<n. diff m c / real (fact m) * (b - c) ^ m) +
   12.31        diff n ?H / real (fact n) * (b - c) ^ n"
   12.32        by fastforce
   12.33      thus ?thesis by fastforce
   12.34 @@ -60,8 +59,7 @@
   12.35    and DERIV: "(\<forall> m t. m < n & a \<le> t & t \<le> b \<longrightarrow> DERIV (diff m) t :> (diff (Suc m) t))"
   12.36    and INTERV: "a < c" "c \<le> b"
   12.37    shows "\<exists> t. a < t & t < c & 
   12.38 -    f a = setsum (% m. (diff m c / real (fact m)) * (a - c)^m) {0..<n} +
   12.39 -      (diff n t / real (fact n)) * (a - c)^n" 
   12.40 +    f a = (\<Sum>m<n. (diff m c / real (fact m)) * (a - c)^m) + (diff n t / real (fact n)) * (a - c)^n" 
   12.41  proof -
   12.42    from INTERV have "a-c < 0" by arith
   12.43    moreover 
   12.44 @@ -79,16 +77,16 @@
   12.45    qed
   12.46    ultimately 
   12.47    have EX: "EX t>a - c. t < 0 &
   12.48 -    f (a - c + c) = (SUM m = 0..<n. diff m (0 + c) / real (fact m) * (a - c) ^ m) +
   12.49 +    f (a - c + c) = (SUM m<n. diff m (0 + c) / real (fact m) * (a - c) ^ m) +
   12.50        diff n (t + c) / real (fact n) * (a - c) ^ n" 
   12.51      by (rule Maclaurin_minus)
   12.52    show ?thesis
   12.53    proof -
   12.54      from EX obtain x where X: "a - c < x & x < 0 &
   12.55 -      f (a - c + c) = (SUM m = 0..<n. diff m (0 + c) / real (fact m) * (a - c) ^ m) +
   12.56 +      f (a - c + c) = (SUM m<n. diff m (0 + c) / real (fact m) * (a - c) ^ m) +
   12.57          diff n (x + c) / real (fact n) * (a - c) ^ n" ..
   12.58      let ?H = "x + c"
   12.59 -    from X have "a<?H & ?H<c \<and> f a = (\<Sum>m = 0..<n. diff m c / real (fact m) * (a - c) ^ m) +
   12.60 +    from X have "a<?H & ?H<c \<and> f a = (\<Sum>m<n. diff m c / real (fact m) * (a - c) ^ m) +
   12.61        diff n ?H / real (fact n) * (a - c) ^ n"
   12.62        by fastforce
   12.63      thus ?thesis by fastforce
   12.64 @@ -100,8 +98,7 @@
   12.65    and DERIV: "(\<forall> m t. m < n & a \<le> t & t \<le> b \<longrightarrow> DERIV (diff m) t :> (diff (Suc m) t))"
   12.66    and INTERV: "a \<le> c " "c \<le> b" "a \<le> x" "x \<le> b" "x \<noteq> c" 
   12.67    shows "\<exists> t. (if x<c then (x < t & t < c) else (c < t & t < x)) &
   12.68 -    f x = setsum (% m. (diff m c / real (fact m)) * (x - c)^m) {0..<n} +
   12.69 -      (diff n t / real (fact n)) * (x - c)^n" 
   12.70 +    f x = (\<Sum>m<n. (diff m c / real (fact m)) * (x - c)^m) + (diff n t / real (fact n)) * (x - c)^n" 
   12.71  proof (cases "x<c")
   12.72    case True
   12.73    note INIT
   12.74 @@ -111,8 +108,7 @@
   12.75    moreover note True
   12.76    moreover from INTERV have "c \<le> b" by simp
   12.77    ultimately have EX: "\<exists>t>x. t < c \<and> f x =
   12.78 -    (\<Sum>m = 0..<n. diff m c / real (fact m) * (x - c) ^ m) +
   12.79 -      diff n t / real (fact n) * (x - c) ^ n"
   12.80 +    (\<Sum>m<n. diff m c / real (fact m) * (x - c) ^ m) + diff n t / real (fact n) * (x - c) ^ n"
   12.81      by (rule taylor_down)
   12.82    with True show ?thesis by simp
   12.83  next
   12.84 @@ -124,8 +120,7 @@
   12.85    moreover from INTERV have "a \<le> c" by arith
   12.86    moreover from False and INTERV have "c < x" by arith
   12.87    ultimately have EX: "\<exists>t>c. t < x \<and> f x =
   12.88 -    (\<Sum>m = 0..<n. diff m c / real (fact m) * (x - c) ^ m) +
   12.89 -      diff n t / real (fact n) * (x - c) ^ n" 
   12.90 +    (\<Sum>m<n. diff m c / real (fact m) * (x - c) ^ m) + diff n t / real (fact n) * (x - c) ^ n" 
   12.91      by (rule taylor_up)
   12.92    with False show ?thesis by simp
   12.93  qed
    13.1 --- a/src/HOL/Transcendental.thy	Tue Mar 18 14:32:23 2014 +0100
    13.2 +++ b/src/HOL/Transcendental.thy	Tue Mar 18 15:53:48 2014 +0100
    13.3 @@ -21,66 +21,55 @@
    13.4    thus ?thesis by (simp add: power_commutes)
    13.5  qed
    13.6  
    13.7 -lemma lemma_realpow_diff_sumr:
    13.8 -  fixes y :: "'a::{comm_semiring_0,monoid_mult}"
    13.9 -  shows
   13.10 -    "(\<Sum>p=0..<Suc n. (x ^ p) * y ^ (Suc n - p)) =
   13.11 -      y * (\<Sum>p=0..<Suc n. (x ^ p) * y ^ (n - p))"
   13.12 -  by (simp add: setsum_right_distrib lemma_realpow_diff mult_ac del: setsum_op_ivl_Suc)
   13.13 -
   13.14  lemma lemma_realpow_diff_sumr2:
   13.15    fixes y :: "'a::{comm_ring,monoid_mult}"
   13.16    shows
   13.17      "x ^ (Suc n) - y ^ (Suc n) =
   13.18 -      (x - y) * (\<Sum>p=0..<Suc n. (x ^ p) * y ^ (n - p))"
   13.19 +      (x - y) * (\<Sum>p<Suc n. (x ^ p) * y ^ (n - p))"
   13.20  proof (induct n)
   13.21 -  case 0 show ?case
   13.22 -    by simp
   13.23 -next
   13.24    case (Suc n)
   13.25    have "x ^ Suc (Suc n) - y ^ Suc (Suc n) = x * (x * x ^ n) - y * (y * y ^ n)"
   13.26      by simp
   13.27    also have "... = y * (x ^ (Suc n) - y ^ (Suc n)) + (x - y) * (x * x ^ n)"
   13.28      by (simp add: algebra_simps)
   13.29 -  also have "... = y * ((x - y) * (\<Sum>p=0..<Suc n. (x ^ p) * y ^ (n - p))) + (x - y) * (x * x ^ n)"
   13.30 +  also have "... = y * ((x - y) * (\<Sum>p<Suc n. (x ^ p) * y ^ (n - p))) + (x - y) * (x * x ^ n)"
   13.31      by (simp only: Suc)
   13.32 -  also have "... = (x - y) * (y * (\<Sum>p=0..<Suc n. (x ^ p) * y ^ (n - p))) + (x - y) * (x * x ^ n)"
   13.33 +  also have "... = (x - y) * (y * (\<Sum>p<Suc n. (x ^ p) * y ^ (n - p))) + (x - y) * (x * x ^ n)"
   13.34      by (simp only: mult_left_commute)
   13.35 -  also have "... = (x - y) * (\<Sum>p = 0..<Suc (Suc n). x ^ p * y ^ (Suc n - p))"
   13.36 -    by (simp add: setsum_op_ivl_Suc [where n = "Suc n"] distrib_left lemma_realpow_diff_sumr
   13.37 -             del: setsum_op_ivl_Suc)
   13.38 +  also have "... = (x - y) * (\<Sum>p<Suc (Suc n). x ^ p * y ^ (Suc n - p))"
   13.39 +    by (simp add: field_simps Suc_diff_le setsum_left_distrib setsum_right_distrib)
   13.40    finally show ?case .
   13.41 -qed
   13.42 +qed simp
   13.43  
   13.44  corollary power_diff_sumr2: --{* @{text COMPLEX_POLYFUN} in HOL Light *}
   13.45    fixes x :: "'a::{comm_ring,monoid_mult}"
   13.46 -  shows   "x^n - y^n = (x - y) * (\<Sum>i=0..<n. y^(n - Suc i) * x^i)"
   13.47 +  shows   "x^n - y^n = (x - y) * (\<Sum>i<n. y^(n - Suc i) * x^i)"
   13.48  using lemma_realpow_diff_sumr2[of x "n - 1" y]
   13.49  by (cases "n = 0") (simp_all add: field_simps)
   13.50  
   13.51  lemma lemma_realpow_rev_sumr:
   13.52 -   "(\<Sum>p=0..<Suc n. (x ^ p) * (y ^ (n - p))) =
   13.53 -    (\<Sum>p=0..<Suc n. (x ^ (n - p)) * (y ^ p))"
   13.54 +   "(\<Sum>p<Suc n. (x ^ p) * (y ^ (n - p))) =
   13.55 +    (\<Sum>p<Suc n. (x ^ (n - p)) * (y ^ p))"
   13.56    apply (rule setsum_reindex_cong [where f="\<lambda>i. n - i"])
   13.57 -  apply (rule inj_onI, auto)
   13.58 -  apply (metis atLeastLessThan_iff diff_diff_cancel diff_less_Suc imageI le0 less_Suc_eq_le)
   13.59 +  apply (auto simp: image_iff Bex_def intro!: inj_onI)
   13.60 +  apply arith
   13.61    done
   13.62  
   13.63  lemma power_diff_1_eq:
   13.64    fixes x :: "'a::{comm_ring,monoid_mult}"
   13.65 -  shows "n \<noteq> 0 \<Longrightarrow> x^n - 1 = (x - 1) * (\<Sum>i=0..<n. (x^i))"
   13.66 +  shows "n \<noteq> 0 \<Longrightarrow> x^n - 1 = (x - 1) * (\<Sum>i<n. (x^i))"
   13.67  using lemma_realpow_diff_sumr2 [of x _ 1] 
   13.68    by (cases n) auto
   13.69  
   13.70  lemma one_diff_power_eq':
   13.71    fixes x :: "'a::{comm_ring,monoid_mult}"
   13.72 -  shows "n \<noteq> 0 \<Longrightarrow> 1 - x^n = (1 - x) * (\<Sum>i=0..<n. x^(n - Suc i))"
   13.73 +  shows "n \<noteq> 0 \<Longrightarrow> 1 - x^n = (1 - x) * (\<Sum>i<n. x^(n - Suc i))"
   13.74  using lemma_realpow_diff_sumr2 [of 1 _ x] 
   13.75    by (cases n) auto
   13.76  
   13.77  lemma one_diff_power_eq:
   13.78    fixes x :: "'a::{comm_ring,monoid_mult}"
   13.79 -  shows "n \<noteq> 0 \<Longrightarrow> 1 - x^n = (1 - x) * (\<Sum>i=0..<n. x^i)"
   13.80 +  shows "n \<noteq> 0 \<Longrightarrow> 1 - x^n = (1 - x) * (\<Sum>i<n. x^i)"
   13.81  by (metis one_diff_power_eq' [of n x] nat_diff_setsum_reindex)
   13.82  
   13.83  text{*Power series has a `circle` of convergence, i.e. if it sums for @{term
   13.84 @@ -149,17 +138,17 @@
   13.85  lemma sum_split_even_odd:
   13.86    fixes f :: "nat \<Rightarrow> real"
   13.87    shows
   13.88 -    "(\<Sum> i = 0 ..< 2 * n. if even i then f i else g i) =
   13.89 -     (\<Sum> i = 0 ..< n. f (2 * i)) + (\<Sum> i = 0 ..< n. g (2 * i + 1))"
   13.90 +    "(\<Sum>i<2 * n. if even i then f i else g i) =
   13.91 +     (\<Sum>i<n. f (2 * i)) + (\<Sum>i<n. g (2 * i + 1))"
   13.92  proof (induct n)
   13.93    case 0
   13.94    then show ?case by simp
   13.95  next
   13.96    case (Suc n)
   13.97 -  have "(\<Sum> i = 0 ..< 2 * Suc n. if even i then f i else g i) =
   13.98 -    (\<Sum> i = 0 ..< n. f (2 * i)) + (\<Sum> i = 0 ..< n. g (2 * i + 1)) + (f (2 * n) + g (2 * n + 1))"
   13.99 +  have "(\<Sum>i<2 * Suc n. if even i then f i else g i) =
  13.100 +    (\<Sum>i<n. f (2 * i)) + (\<Sum>i<n. g (2 * i + 1)) + (f (2 * n) + g (2 * n + 1))"
  13.101      using Suc.hyps unfolding One_nat_def by auto
  13.102 -  also have "\<dots> = (\<Sum> i = 0 ..< Suc n. f (2 * i)) + (\<Sum> i = 0 ..< Suc n. g (2 * i + 1))"
  13.103 +  also have "\<dots> = (\<Sum>i<Suc n. f (2 * i)) + (\<Sum>i<Suc n. g (2 * i + 1))"
  13.104      by auto
  13.105    finally show ?case .
  13.106  qed
  13.107 @@ -173,14 +162,14 @@
  13.108    fix r :: real
  13.109    assume "0 < r"
  13.110    from `g sums x`[unfolded sums_def, THEN LIMSEQ_D, OF this]
  13.111 -  obtain no where no_eq: "\<And> n. n \<ge> no \<Longrightarrow> (norm (setsum g { 0..<n } - x) < r)" by blast
  13.112 -
  13.113 -  let ?SUM = "\<lambda> m. \<Sum> i = 0 ..< m. if even i then 0 else g ((i - 1) div 2)"
  13.114 +  obtain no where no_eq: "\<And> n. n \<ge> no \<Longrightarrow> (norm (setsum g {..<n} - x) < r)" by blast
  13.115 +
  13.116 +  let ?SUM = "\<lambda> m. \<Sum>i<m. if even i then 0 else g ((i - 1) div 2)"
  13.117    {
  13.118      fix m
  13.119      assume "m \<ge> 2 * no"
  13.120      hence "m div 2 \<ge> no" by auto
  13.121 -    have sum_eq: "?SUM (2 * (m div 2)) = setsum g { 0 ..< m div 2 }"
  13.122 +    have sum_eq: "?SUM (2 * (m div 2)) = setsum g {..< m div 2}"
  13.123        using sum_split_even_odd by auto
  13.124      hence "(norm (?SUM (2 * (m div 2)) - x) < r)"
  13.125        using no_eq unfolding sum_eq using `m div 2 \<ge> no` by auto
  13.126 @@ -220,16 +209,12 @@
  13.127    have g_sums: "(\<lambda> n. if even n then 0 else g ((n - 1) div 2)) sums x"
  13.128      using sums_if'[OF `g sums x`] .
  13.129    {
  13.130 -    have "?s 0 = 0" by auto
  13.131 -    have Suc_m1: "\<And> n. Suc n - 1 = n" by auto
  13.132      have if_eq: "\<And>B T E. (if \<not> B then T else E) = (if B then E else T)" by auto
  13.133  
  13.134      have "?s sums y" using sums_if'[OF `f sums y`] .
  13.135      from this[unfolded sums_def, THEN LIMSEQ_Suc]
  13.136      have "(\<lambda> n. if even n then f (n div 2) else 0) sums y"
  13.137 -      unfolding sums_def setsum_shift_lb_Suc0_0_upt[where f="?s", OF `?s 0 = 0`, symmetric]
  13.138 -                image_Suc_atLeastLessThan[symmetric] setsum_reindex[OF inj_Suc, unfolded comp_def]
  13.139 -                even_Suc Suc_m1 if_eq .
  13.140 +      by (simp add: lessThan_Suc_eq_insert_0 image_iff setsum_reindex if_eq sums_def cong del: if_cong)
  13.141    }
  13.142    from sums_add[OF g_sums this] show ?thesis unfolding if_sum .
  13.143  qed
  13.144 @@ -239,8 +224,8 @@
  13.145  lemma sums_alternating_upper_lower:
  13.146    fixes a :: "nat \<Rightarrow> real"
  13.147    assumes mono: "\<And>n. a (Suc n) \<le> a n" and a_pos: "\<And>n. 0 \<le> a n" and "a ----> 0"
  13.148 -  shows "\<exists>l. ((\<forall>n. (\<Sum>i=0..<2*n. -1^i*a i) \<le> l) \<and> (\<lambda> n. \<Sum>i=0..<2*n. -1^i*a i) ----> l) \<and>
  13.149 -             ((\<forall>n. l \<le> (\<Sum>i=0..<2*n + 1. -1^i*a i)) \<and> (\<lambda> n. \<Sum>i=0..<2*n + 1. -1^i*a i) ----> l)"
  13.150 +  shows "\<exists>l. ((\<forall>n. (\<Sum>i<2*n. -1^i*a i) \<le> l) \<and> (\<lambda> n. \<Sum>i<2*n. -1^i*a i) ----> l) \<and>
  13.151 +             ((\<forall>n. l \<le> (\<Sum>i<2*n + 1. -1^i*a i)) \<and> (\<lambda> n. \<Sum>i<2*n + 1. -1^i*a i) ----> l)"
  13.152    (is "\<exists>l. ((\<forall>n. ?f n \<le> l) \<and> _) \<and> ((\<forall>n. l \<le> ?g n) \<and> _)")
  13.153  proof (rule nested_sequence_unique)
  13.154    have fg_diff: "\<And>n. ?f n - ?g n = - a (2 * n)" unfolding One_nat_def by auto
  13.155 @@ -279,13 +264,13 @@
  13.156      and a_pos: "\<And> n. 0 \<le> a n"
  13.157      and a_monotone: "\<And> n. a (Suc n) \<le> a n"
  13.158    shows summable: "summable (\<lambda> n. (-1)^n * a n)"
  13.159 -    and "\<And>n. (\<Sum>i=0..<2*n. (-1)^i*a i) \<le> (\<Sum>i. (-1)^i*a i)"
  13.160 -    and "(\<lambda>n. \<Sum>i=0..<2*n. (-1)^i*a i) ----> (\<Sum>i. (-1)^i*a i)"
  13.161 -    and "\<And>n. (\<Sum>i. (-1)^i*a i) \<le> (\<Sum>i=0..<2*n+1. (-1)^i*a i)"
  13.162 -    and "(\<lambda>n. \<Sum>i=0..<2*n+1. (-1)^i*a i) ----> (\<Sum>i. (-1)^i*a i)"
  13.163 +    and "\<And>n. (\<Sum>i<2*n. (-1)^i*a i) \<le> (\<Sum>i. (-1)^i*a i)"
  13.164 +    and "(\<lambda>n. \<Sum>i<2*n. (-1)^i*a i) ----> (\<Sum>i. (-1)^i*a i)"
  13.165 +    and "\<And>n. (\<Sum>i. (-1)^i*a i) \<le> (\<Sum>i<2*n+1. (-1)^i*a i)"
  13.166 +    and "(\<lambda>n. \<Sum>i<2*n+1. (-1)^i*a i) ----> (\<Sum>i. (-1)^i*a i)"
  13.167  proof -
  13.168    let ?S = "\<lambda>n. (-1)^n * a n"
  13.169 -  let ?P = "\<lambda>n. \<Sum>i=0..<n. ?S i"
  13.170 +  let ?P = "\<lambda>n. \<Sum>i<n. ?S i"
  13.171    let ?f = "\<lambda>n. ?P (2 * n)"
  13.172    let ?g = "\<lambda>n. ?P (2 * n + 1)"
  13.173    obtain l :: real
  13.174 @@ -295,7 +280,7 @@
  13.175        and "?g ----> l"
  13.176      using sums_alternating_upper_lower[OF a_monotone a_pos a_zero] by blast
  13.177  
  13.178 -  let ?Sa = "\<lambda>m. \<Sum> n = 0..<m. ?S n"
  13.179 +  let ?Sa = "\<lambda>m. \<Sum>n<m. ?S n"
  13.180    have "?Sa ----> l"
  13.181    proof (rule LIMSEQ_I)
  13.182      fix r :: real
  13.183 @@ -332,13 +317,13 @@
  13.184          from n_eq `n \<ge> 2 * g_no` have "(n - 1) div 2 \<ge> g_no"
  13.185            by auto
  13.186          from g[OF this] show ?thesis
  13.187 -          unfolding n_eq atLeastLessThanSuc_atLeastAtMost range_eq .
  13.188 +          unfolding n_eq range_eq .
  13.189        qed
  13.190      }
  13.191      thus "\<exists>no. \<forall>n \<ge> no. norm (?Sa n - l) < r" by blast
  13.192    qed
  13.193    hence sums_l: "(\<lambda>i. (-1)^i * a i) sums l"
  13.194 -    unfolding sums_def atLeastLessThanSuc_atLeastAtMost[symmetric] .
  13.195 +    unfolding sums_def .
  13.196    thus "summable ?S" using summable_def by auto
  13.197  
  13.198    have "l = suminf ?S" using sums_unique[OF sums_l] .
  13.199 @@ -359,11 +344,11 @@
  13.200    assumes a_zero: "a ----> 0" and "monoseq a"
  13.201    shows "summable (\<lambda> n. (-1)^n * a n)" (is "?summable")
  13.202      and "0 < a 0 \<longrightarrow>
  13.203 -      (\<forall>n. (\<Sum>i. -1^i*a i) \<in> { \<Sum>i=0..<2*n. -1^i * a i .. \<Sum>i=0..<2*n+1. -1^i * a i})" (is "?pos")
  13.204 +      (\<forall>n. (\<Sum>i. -1^i*a i) \<in> { \<Sum>i<2*n. -1^i * a i .. \<Sum>i<2*n+1. -1^i * a i})" (is "?pos")
  13.205      and "a 0 < 0 \<longrightarrow>
  13.206 -      (\<forall>n. (\<Sum>i. -1^i*a i) \<in> { \<Sum>i=0..<2*n+1. -1^i * a i .. \<Sum>i=0..<2*n. -1^i * a i})" (is "?neg")
  13.207 -    and "(\<lambda>n. \<Sum>i=0..<2*n. -1^i*a i) ----> (\<Sum>i. -1^i*a i)" (is "?f")
  13.208 -    and "(\<lambda>n. \<Sum>i=0..<2*n+1. -1^i*a i) ----> (\<Sum>i. -1^i*a i)" (is "?g")
  13.209 +      (\<forall>n. (\<Sum>i. -1^i*a i) \<in> { \<Sum>i<2*n+1. -1^i * a i .. \<Sum>i<2*n. -1^i * a i})" (is "?neg")
  13.210 +    and "(\<lambda>n. \<Sum>i<2*n. -1^i*a i) ----> (\<Sum>i. -1^i*a i)" (is "?f")
  13.211 +    and "(\<lambda>n. \<Sum>i<2*n+1. -1^i*a i) ----> (\<Sum>i. -1^i*a i)" (is "?g")
  13.212  proof -
  13.213    have "?summable \<and> ?pos \<and> ?neg \<and> ?f \<and> ?g"
  13.214    proof (cases "(\<forall> n. 0 \<le> a n) \<and> (\<forall>m. \<forall>n\<ge>m. a n \<le> a m)")
  13.215 @@ -424,38 +409,32 @@
  13.216  
  13.217  subsection {* Term-by-Term Differentiability of Power Series *}
  13.218  
  13.219 -definition diffs :: "(nat => 'a::ring_1) => nat => 'a"
  13.220 -  where "diffs c = (\<lambda>n. of_nat (Suc n) * c(Suc n))"
  13.221 +definition diffs :: "(nat \<Rightarrow> 'a::ring_1) \<Rightarrow> nat \<Rightarrow> 'a"
  13.222 +  where "diffs c = (\<lambda>n. of_nat (Suc n) * c (Suc n))"
  13.223  
  13.224  text{*Lemma about distributing negation over it*}
  13.225  lemma diffs_minus: "diffs (\<lambda>n. - c n) = (\<lambda>n. - diffs c n)"
  13.226    by (simp add: diffs_def)
  13.227  
  13.228  lemma sums_Suc_imp:
  13.229 -  assumes f: "f 0 = 0"
  13.230 -  shows "(\<lambda>n. f (Suc n)) sums s \<Longrightarrow> (\<lambda>n. f n) sums s"
  13.231 -  unfolding sums_def
  13.232 -  apply (rule LIMSEQ_imp_Suc)
  13.233 -  apply (subst setsum_shift_lb_Suc0_0_upt [where f=f, OF f, symmetric])
  13.234 -  apply (simp only: setsum_shift_bounds_Suc_ivl)
  13.235 -  done
  13.236 +  "(f::nat \<Rightarrow> 'a::real_normed_vector) 0 = 0 \<Longrightarrow> (\<lambda>n. f (Suc n)) sums s \<Longrightarrow> (\<lambda>n. f n) sums s"
  13.237 +  using sums_Suc_iff[of f] by simp
  13.238  
  13.239  lemma diffs_equiv:
  13.240    fixes x :: "'a::{real_normed_vector, ring_1}"
  13.241 -  shows "summable (\<lambda>n. (diffs c)(n) * (x ^ n)) \<Longrightarrow>
  13.242 -      (\<lambda>n. of_nat n * c(n) * (x ^ (n - Suc 0))) sums
  13.243 -         (\<Sum>n. (diffs c)(n) * (x ^ n))"
  13.244 +  shows "summable (\<lambda>n. diffs c n * x^n) \<Longrightarrow>
  13.245 +      (\<lambda>n. of_nat n * c n * x^(n - Suc 0)) sums (\<Sum>n. diffs c n * x^n)"
  13.246    unfolding diffs_def
  13.247    by (simp add: summable_sums sums_Suc_imp)
  13.248  
  13.249  lemma lemma_termdiff1:
  13.250    fixes z :: "'a :: {monoid_mult,comm_ring}" shows
  13.251 -  "(\<Sum>p=0..<m. (((z + h) ^ (m - p)) * (z ^ p)) - (z ^ m)) =
  13.252 -   (\<Sum>p=0..<m. (z ^ p) * (((z + h) ^ (m - p)) - (z ^ (m - p))))"
  13.253 +  "(\<Sum>p<m. (((z + h) ^ (m - p)) * (z ^ p)) - (z ^ m)) =
  13.254 +   (\<Sum>p<m. (z ^ p) * (((z + h) ^ (m - p)) - (z ^ (m - p))))"
  13.255    by (auto simp add: algebra_simps power_add [symmetric])
  13.256  
  13.257  lemma sumr_diff_mult_const2:
  13.258 -  "setsum f {0..<n} - of_nat n * (r::'a::ring_1) = (\<Sum>i = 0..<n. f i - r)"
  13.259 +  "setsum f {..<n} - of_nat n * (r::'a::ring_1) = (\<Sum>i<n. f i - r)"
  13.260    by (simp add: setsum_subtractf)
  13.261  
  13.262  lemma lemma_termdiff2:
  13.263 @@ -463,7 +442,7 @@
  13.264    assumes h: "h \<noteq> 0"
  13.265    shows
  13.266      "((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0) =
  13.267 -     h * (\<Sum>p=0..< n - Suc 0. \<Sum>q=0..< n - Suc 0 - p.
  13.268 +     h * (\<Sum>p< n - Suc 0. \<Sum>q< n - Suc 0 - p.
  13.269            (z + h) ^ q * z ^ (n - 2 - q))" (is "?lhs = ?rhs")
  13.270    apply (subgoal_tac "h * ?lhs = h * ?rhs", simp add: h)
  13.271    apply (simp add: right_diff_distrib diff_divide_distrib h)
  13.272 @@ -471,7 +450,7 @@
  13.273    apply (cases "n", simp)
  13.274    apply (simp add: lemma_realpow_diff_sumr2 h
  13.275                     right_diff_distrib [symmetric] mult_assoc
  13.276 -              del: power_Suc setsum_op_ivl_Suc of_nat_Suc)
  13.277 +              del: power_Suc setsum_lessThan_Suc of_nat_Suc)
  13.278    apply (subst lemma_realpow_rev_sumr)
  13.279    apply (subst sumr_diff_mult_const2)
  13.280    apply simp
  13.281 @@ -480,7 +459,7 @@
  13.282    apply (simp add: less_iff_Suc_add)
  13.283    apply (clarify)
  13.284    apply (simp add: setsum_right_distrib lemma_realpow_diff_sumr2 mult_ac
  13.285 -              del: setsum_op_ivl_Suc power_Suc)
  13.286 +              del: setsum_lessThan_Suc power_Suc)
  13.287    apply (subst mult_assoc [symmetric], subst power_add [symmetric])
  13.288    apply (simp add: mult_ac)
  13.289    done
  13.290 @@ -489,7 +468,7 @@
  13.291    fixes K :: "'a::linordered_semidom"
  13.292    assumes f: "\<And>p::nat. p < n \<Longrightarrow> f p \<le> K"
  13.293      and K: "0 \<le> K"
  13.294 -  shows "setsum f {0..<n-k} \<le> of_nat n * K"
  13.295 +  shows "setsum f {..<n-k} \<le> of_nat n * K"
  13.296    apply (rule order_trans [OF setsum_mono])
  13.297    apply (rule f, simp)
  13.298    apply (simp add: mult_right_mono K)
  13.299 @@ -504,7 +483,7 @@
  13.300            \<le> of_nat n * of_nat (n - Suc 0) * K ^ (n - 2) * norm h"
  13.301  proof -
  13.302    have "norm (((z + h) ^ n - z ^ n) / h - of_nat n * z ^ (n - Suc 0)) =
  13.303 -        norm (\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p.
  13.304 +        norm (\<Sum>p<n - Suc 0. \<Sum>q<n - Suc 0 - p.
  13.305            (z + h) ^ q * z ^ (n - 2 - q)) * norm h"
  13.306      by (metis (lifting, no_types) lemma_termdiff2 [OF 1] mult_commute norm_mult)
  13.307    also have "\<dots> \<le> of_nat n * (of_nat (n - Suc 0) * K ^ (n - 2)) * norm h"
  13.308 @@ -516,7 +495,7 @@
  13.309        apply (simp only: norm_mult norm_power power_add)
  13.310        apply (intro mult_mono power_mono 2 3 norm_ge_zero zero_le_power K)
  13.311        done
  13.312 -    show "norm (\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p. (z + h) ^ q * z ^ (n - 2 - q))
  13.313 +    show "norm (\<Sum>p<n - Suc 0. \<Sum>q<n - Suc 0 - p. (z + h) ^ q * z ^ (n - 2 - q))
  13.314            \<le> of_nat n * (of_nat (n - Suc 0) * K ^ (n - 2))"
  13.315        apply (intro
  13.316           order_trans [OF norm_setsum]
  13.317 @@ -712,16 +691,16 @@
  13.318    from divide_pos_pos[OF `0 < r` this]
  13.319    have "0 < ?r" .
  13.320  
  13.321 -  let "?s n" = "SOME s. 0 < s \<and> (\<forall> x. x \<noteq> 0 \<and> \<bar> x \<bar> < s \<longrightarrow> \<bar> ?diff n x - f' x0 n \<bar> < ?r)"
  13.322 -  def S' \<equiv> "Min (?s ` { 0 ..< ?N })"
  13.323 +  let ?s = "\<lambda>n. SOME s. 0 < s \<and> (\<forall> x. x \<noteq> 0 \<and> \<bar> x \<bar> < s \<longrightarrow> \<bar> ?diff n x - f' x0 n \<bar> < ?r)"
  13.324 +  def S' \<equiv> "Min (?s ` {..< ?N })"
  13.325  
  13.326    have "0 < S'" unfolding S'_def
  13.327    proof (rule iffD2[OF Min_gr_iff])
  13.328 -    show "\<forall>x \<in> (?s ` { 0 ..< ?N }). 0 < x"
  13.329 +    show "\<forall>x \<in> (?s ` {..< ?N }). 0 < x"
  13.330      proof
  13.331        fix x
  13.332 -      assume "x \<in> ?s ` {0..<?N}"
  13.333 -      then obtain n where "x = ?s n" and "n \<in> {0..<?N}"
  13.334 +      assume "x \<in> ?s ` {..<?N}"
  13.335 +      then obtain n where "x = ?s n" and "n \<in> {..<?N}"
  13.336          using image_iff[THEN iffD1] by blast
  13.337        from DERIV_D[OF DERIV_f[where n=n], THEN LIM_D, OF `0 < ?r`, unfolded real_norm_def]
  13.338        obtain s where s_bound: "0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> \<bar>x\<bar> < s \<longrightarrow> \<bar>?diff n x - f' x0 n\<bar> < ?r)"
  13.339 @@ -750,32 +729,30 @@
  13.340      note div_shft_smbl = summable_divide[OF diff_shft_smbl]
  13.341      note all_shft_smbl = summable_diff[OF div_smbl ign[OF `summable (f' x0)`]]
  13.342  
  13.343 -    {
  13.344 -      fix n
  13.345 +    { fix n
  13.346        have "\<bar> ?diff (n + ?N) x \<bar> \<le> L (n + ?N) * \<bar> (x0 + x) - x0 \<bar> / \<bar> x \<bar>"
  13.347          using divide_right_mono[OF L_def[OF x_in_I x0_in_I] abs_ge_zero]
  13.348          unfolding abs_divide .
  13.349        hence "\<bar> (\<bar>?diff (n + ?N) x \<bar>) \<bar> \<le> L (n + ?N)"
  13.350 -        using `x \<noteq> 0` by auto
  13.351 -    } note L_ge = summable_le2[OF allI[OF this] ign[OF `summable L`]]
  13.352 -    from order_trans[OF summable_rabs[OF conjunct1[OF L_ge]] L_ge[THEN conjunct2]]
  13.353 -    have "\<bar> \<Sum> i. ?diff (i + ?N) x \<bar> \<le> (\<Sum> i. L (i + ?N))" .
  13.354 -    hence "\<bar> \<Sum> i. ?diff (i + ?N) x \<bar> \<le> r / 3" (is "?L_part \<le> r/3")
  13.355 +        using `x \<noteq> 0` by auto }
  13.356 +    note 1 = this and 2 = summable_rabs_comparison_test[OF _ ign[OF `summable L`]]
  13.357 +    then have "\<bar> \<Sum> i. ?diff (i + ?N) x \<bar> \<le> (\<Sum> i. L (i + ?N))"
  13.358 +      by (metis (lifting) abs_idempotent order_trans[OF summable_rabs[OF 2] summable_le[OF _ 2 ign[OF `summable L`]]])
  13.359 +    then have "\<bar> \<Sum> i. ?diff (i + ?N) x \<bar> \<le> r / 3" (is "?L_part \<le> r/3")
  13.360        using L_estimate by auto
  13.361  
  13.362 -    have "\<bar>\<Sum>n \<in> { 0 ..< ?N}. ?diff n x - f' x0 n \<bar> \<le>
  13.363 -      (\<Sum>n \<in> { 0 ..< ?N}. \<bar>?diff n x - f' x0 n \<bar>)" ..
  13.364 -    also have "\<dots> < (\<Sum>n \<in> { 0 ..< ?N}. ?r)"
  13.365 +    have "\<bar>\<Sum>n<?N. ?diff n x - f' x0 n \<bar> \<le> (\<Sum>n<?N. \<bar>?diff n x - f' x0 n \<bar>)" ..
  13.366 +    also have "\<dots> < (\<Sum>n<?N. ?r)"
  13.367      proof (rule setsum_strict_mono)
  13.368        fix n
  13.369 -      assume "n \<in> { 0 ..< ?N}"
  13.370 +      assume "n \<in> {..< ?N}"
  13.371        have "\<bar>x\<bar> < S" using `\<bar>x\<bar> < S` .
  13.372        also have "S \<le> S'" using `S \<le> S'` .
  13.373        also have "S' \<le> ?s n" unfolding S'_def
  13.374        proof (rule Min_le_iff[THEN iffD2])
  13.375 -        have "?s n \<in> (?s ` {0..<?N}) \<and> ?s n \<le> ?s n"
  13.376 -          using `n \<in> { 0 ..< ?N}` by auto
  13.377 -        thus "\<exists> a \<in> (?s ` {0..<?N}). a \<le> ?s n" by blast
  13.378 +        have "?s n \<in> (?s ` {..<?N}) \<and> ?s n \<le> ?s n"
  13.379 +          using `n \<in> {..< ?N}` by auto
  13.380 +        thus "\<exists> a \<in> (?s ` {..<?N}). a \<le> ?s n" by blast
  13.381        qed auto
  13.382        finally have "\<bar>x\<bar> < ?s n" .
  13.383  
  13.384 @@ -784,12 +761,12 @@
  13.385        with `x \<noteq> 0` and `\<bar>x\<bar> < ?s n` show "\<bar>?diff n x - f' x0 n\<bar> < ?r"
  13.386          by blast
  13.387      qed auto
  13.388 -    also have "\<dots> = of_nat (card {0 ..< ?N}) * ?r"
  13.389 +    also have "\<dots> = of_nat (card {..<?N}) * ?r"
  13.390        by (rule setsum_constant)
  13.391      also have "\<dots> = real ?N * ?r"
  13.392        unfolding real_eq_of_nat by auto
  13.393      also have "\<dots> = r/3" by auto
  13.394 -    finally have "\<bar>\<Sum>n \<in> { 0 ..< ?N}. ?diff n x - f' x0 n \<bar> < r / 3" (is "?diff_part < r / 3") .
  13.395 +    finally have "\<bar>\<Sum>n<?N. ?diff n x - f' x0 n \<bar> < r / 3" (is "?diff_part < r / 3") .
  13.396  
  13.397      from suminf_diff[OF allf_summable[OF x_in_I] allf_summable[OF x0_in_I]]
  13.398      have "\<bar>(suminf (f (x0 + x)) - (suminf (f x0))) / x - suminf (f' x0)\<bar> =
  13.399 @@ -799,6 +776,7 @@
  13.400      also have "\<dots> \<le> ?diff_part + \<bar> (\<Sum>n. ?diff (n + ?N) x) - (\<Sum> n. f' x0 (n + ?N)) \<bar>"
  13.401        unfolding suminf_split_initial_segment[OF all_smbl, where k="?N"]
  13.402        unfolding suminf_diff[OF div_shft_smbl ign[OF `summable (f' x0)`]]
  13.403 +      apply (subst (5) add_commute)
  13.404        by (rule abs_triangle_ineq)
  13.405      also have "\<dots> \<le> ?diff_part + ?L_part + ?f'_part"
  13.406        using abs_triangle_ineq4 by auto
  13.407 @@ -844,17 +822,17 @@
  13.408          show "\<bar>?f x n - ?f y n\<bar> \<le> \<bar>f n * real (Suc n) * R'^n\<bar> * \<bar>x-y\<bar>"
  13.409          proof -
  13.410            have "\<bar>f n * x ^ (Suc n) - f n * y ^ (Suc n)\<bar> =
  13.411 -            (\<bar>f n\<bar> * \<bar>x-y\<bar>) * \<bar>\<Sum>p = 0..<Suc n. x ^ p * y ^ (n - p)\<bar>"
  13.412 +            (\<bar>f n\<bar> * \<bar>x-y\<bar>) * \<bar>\<Sum>p<Suc n. x ^ p * y ^ (n - p)\<bar>"
  13.413              unfolding right_diff_distrib[symmetric] lemma_realpow_diff_sumr2 abs_mult
  13.414              by auto
  13.415            also have "\<dots> \<le> (\<bar>f n\<bar> * \<bar>x-y\<bar>) * (\<bar>real (Suc n)\<bar> * \<bar>R' ^ n\<bar>)"
  13.416            proof (rule mult_left_mono)
  13.417 -            have "\<bar>\<Sum>p = 0..<Suc n. x ^ p * y ^ (n - p)\<bar> \<le> (\<Sum>p = 0..<Suc n. \<bar>x ^ p * y ^ (n - p)\<bar>)"
  13.418 +            have "\<bar>\<Sum>p<Suc n. x ^ p * y ^ (n - p)\<bar> \<le> (\<Sum>p<Suc n. \<bar>x ^ p * y ^ (n - p)\<bar>)"
  13.419                by (rule setsum_abs)
  13.420 -            also have "\<dots> \<le> (\<Sum>p = 0..<Suc n. R' ^ n)"
  13.421 +            also have "\<dots> \<le> (\<Sum>p<Suc n. R' ^ n)"
  13.422              proof (rule setsum_mono)
  13.423                fix p
  13.424 -              assume "p \<in> {0..<Suc n}"
  13.425 +              assume "p \<in> {..<Suc n}"
  13.426                hence "p \<le> n" by auto
  13.427                {
  13.428                  fix n
  13.429 @@ -872,7 +850,7 @@
  13.430              qed
  13.431              also have "\<dots> = real (Suc n) * R' ^ n"
  13.432                unfolding setsum_constant card_atLeastLessThan real_of_nat_def by auto
  13.433 -            finally show "\<bar>\<Sum>p = 0..<Suc n. x ^ p * y ^ (n - p)\<bar> \<le> \<bar>real (Suc n)\<bar> * \<bar>R' ^ n\<bar>"
  13.434 +            finally show "\<bar>\<Sum>p<Suc n. x ^ p * y ^ (n - p)\<bar> \<le> \<bar>real (Suc n)\<bar> * \<bar>R' ^ n\<bar>"
  13.435                unfolding abs_real_of_nat_cancel abs_of_nonneg[OF zero_le_power[OF less_imp_le[OF `0 < R'`]]] .
  13.436              show "0 \<le> \<bar>f n\<bar> * \<bar>x - y\<bar>"
  13.437                unfolding abs_mult[symmetric] by auto
  13.438 @@ -893,14 +871,14 @@
  13.439          hence "R' \<in> {-R <..< R}" and "norm x < norm R'"
  13.440            using assms `R' < R` by auto
  13.441          have "summable (\<lambda> n. f n * x^n)"
  13.442 -        proof (rule summable_le2[THEN conjunct1, OF _ powser_insidea[OF converges[OF `R' \<in> {-R <..< R}`] `norm x < norm R'`]], rule allI)
  13.443 +        proof (rule summable_comparison_test, intro exI allI impI)
  13.444            fix n
  13.445            have le: "\<bar>f n\<bar> * 1 \<le> \<bar>f n\<bar> * real (Suc n)"
  13.446              by (rule mult_left_mono) auto
  13.447 -          show "\<bar>f n * x ^ n\<bar> \<le> norm (f n * real (Suc n) * x ^ n)"
  13.448 +          show "norm (f n * x ^ n) \<le> norm (f n * real (Suc n) * x ^ n)"
  13.449              unfolding real_norm_def abs_mult
  13.450              by (rule mult_right_mono) (auto simp add: le[unfolded mult_1_right])
  13.451 -        qed
  13.452 +        qed (rule powser_insidea[OF converges[OF `R' \<in> {-R <..< R}`] `norm x < norm R'`])
  13.453          from this[THEN summable_mult2[where c=x], unfolded mult_assoc, unfolded mult_commute]
  13.454          show "summable (?f x)" by auto
  13.455        }
  13.456 @@ -947,7 +925,7 @@
  13.457    obtain N :: nat where N: "norm x < real N * r"
  13.458      using reals_Archimedean3 [OF r0] by fast
  13.459    from r1 show ?thesis
  13.460 -  proof (rule ratio_test [rule_format])
  13.461 +  proof (rule summable_ratio_test [rule_format])
  13.462      fix n :: nat
  13.463      assume n: "N \<le> n"
  13.464      have "norm x \<le> real N * r"
  13.465 @@ -1027,7 +1005,7 @@
  13.466    fixes f :: "nat \<Rightarrow> 'a::{real_normed_algebra_1}"
  13.467    shows "(\<Sum>n. f n * 0 ^ n) = f 0"
  13.468  proof -
  13.469 -  have "(\<Sum>n = 0..<1. f n * 0 ^ n) = (\<Sum>n. f n * 0 ^ n)"
  13.470 +  have "(\<Sum>n<1. f n * 0 ^ n) = (\<Sum>n. f n * 0 ^ n)"
  13.471      by (rule sums_unique [OF series_zero], simp add: power_0_left)
  13.472    thus ?thesis unfolding One_nat_def by simp
  13.473  qed
  13.474 @@ -1147,7 +1125,7 @@
  13.475  using order_le_imp_less_or_eq [OF assms]
  13.476  proof 
  13.477    assume "0 < x"
  13.478 -  have "1+x \<le> (\<Sum>n = 0..<2. inverse (real (fact n)) * x ^ n)"
  13.479 +  have "1+x \<le> (\<Sum>n<2. inverse (real (fact n)) * x ^ n)"
  13.480      by (auto simp add: numeral_2_eq_2)
  13.481    also have "... \<le> (\<Sum>n. inverse (real (fact n)) * x ^ n)"
  13.482      apply (rule series_pos_le [OF summable_exp])
  13.483 @@ -1395,12 +1373,13 @@
  13.484  proof -
  13.485    have "exp x = suminf (\<lambda>n. inverse(fact n) * (x ^ n))"
  13.486      by (simp add: exp_def)
  13.487 -  also from summable_exp have "... = (\<Sum> n::nat = 0 ..< 2. inverse(fact n) * (x ^ n)) +
  13.488 -      (\<Sum> n. inverse(fact(n+2)) * (x ^ (n+2)))" (is "_ = ?a + _")
  13.489 +  also from summable_exp have "... = (\<Sum> n. inverse(fact(n+2)) * (x ^ (n+2))) + 
  13.490 +    (\<Sum> n::nat<2. inverse(fact n) * (x ^ n))" (is "_ = _ + ?a")
  13.491      by (rule suminf_split_initial_segment)
  13.492    also have "?a = 1 + x"
  13.493      by (simp add: numeral_2_eq_2)
  13.494 -  finally show ?thesis .
  13.495 +  finally show ?thesis
  13.496 +    by simp
  13.497  qed
  13.498  
  13.499  lemma exp_bound: "0 <= (x::real) \<Longrightarrow> x <= 1 \<Longrightarrow> exp x <= 1 + x + x\<^sup>2"
  13.500 @@ -2433,6 +2412,25 @@
  13.501  
  13.502  lemmas realpow_num_eq_if = power_eq_if
  13.503  
  13.504 +lemma sumr_pos_lt_pair:
  13.505 +  fixes f :: "nat \<Rightarrow> real"
  13.506 +  shows "\<lbrakk>summable f;
  13.507 +        \<And>d. 0 < f (k + (Suc(Suc 0) * d)) + f (k + ((Suc(Suc 0) * d) + 1))\<rbrakk>
  13.508 +      \<Longrightarrow> setsum f {..<k} < suminf f"
  13.509 +unfolding One_nat_def
  13.510 +apply (subst suminf_split_initial_segment [where k="k"])
  13.511 +apply assumption
  13.512 +apply simp
  13.513 +apply (drule_tac k="k" in summable_ignore_initial_segment)
  13.514 +apply (drule_tac k="Suc (Suc 0)" in sums_group [OF summable_sums], simp)
  13.515 +apply simp
  13.516 +apply (frule sums_unique)
  13.517 +apply (drule sums_summable)
  13.518 +apply simp
  13.519 +apply (erule suminf_gt_zero)
  13.520 +apply (simp add: add_ac)
  13.521 +done
  13.522 +
  13.523  lemma cos_two_less_zero [simp]:
  13.524    "cos 2 < 0"
  13.525  proof -
  13.526 @@ -2444,9 +2442,9 @@
  13.527      by simp
  13.528    then have **: "summable (\<lambda>n. - (-1 ^ n * 2 ^ (2 * n) / real (fact (2 * n))))"
  13.529      by (rule sums_summable)
  13.530 -  have "0 < (\<Sum>n = 0..<Suc (Suc (Suc 0)). - (-1 ^ n * 2 ^ (2 * n) / real (fact (2 * n))))"
  13.531 +  have "0 < (\<Sum>n<Suc (Suc (Suc 0)). - (-1 ^ n * 2 ^ (2 * n) / real (fact (2 * n))))"
  13.532      by (simp add: fact_num_eq_if_nat realpow_num_eq_if)
  13.533 -  moreover have "(\<Sum>n = 0..<Suc (Suc (Suc 0)). - (-1 ^ n  * 2 ^ (2 * n) / real (fact (2 * n))))
  13.534 +  moreover have "(\<Sum>n<Suc (Suc (Suc 0)). - (-1 ^ n  * 2 ^ (2 * n) / real (fact (2 * n))))
  13.535      < (\<Sum>n. - (-1 ^ n * 2 ^ (2 * n) / real (fact (2 * n))))"
  13.536    proof -
  13.537      { fix d
  13.538 @@ -3807,7 +3805,7 @@
  13.539      case False
  13.540      hence "\<bar>x\<bar> = 1" using `\<bar>x\<bar> \<le> 1` by auto
  13.541      let ?a = "\<lambda>x n. \<bar>1 / real (n*2+1) * x^(n*2+1)\<bar>"
  13.542 -    let ?diff = "\<lambda> x n. \<bar> arctan x - (\<Sum> i = 0..<n. ?c x i)\<bar>"
  13.543 +    let ?diff = "\<lambda> x n. \<bar> arctan x - (\<Sum> i<n. ?c x i)\<bar>"
  13.544      {
  13.545        fix n :: nat
  13.546        have "0 < (1 :: real)" by auto
  13.547 @@ -3830,7 +3828,7 @@
  13.548            from `even n` obtain m where "2 * m = n"
  13.549              unfolding even_mult_two_ex by auto
  13.550            from bounds[of m, unfolded this atLeastAtMost_iff]
  13.551 -          have "\<bar>arctan x - (\<Sum>i = 0..<n. (?c x i))\<bar> \<le> (\<Sum>i = 0..<n + 1. (?c x i)) - (\<Sum>i = 0..<n. (?c x i))"
  13.552 +          have "\<bar>arctan x - (\<Sum>i<n. (?c x i))\<bar> \<le> (\<Sum>i<n + 1. (?c x i)) - (\<Sum>i<n. (?c x i))"
  13.553              by auto
  13.554            also have "\<dots> = ?c x n" unfolding One_nat_def by auto
  13.555            also have "\<dots> = ?a x n" unfolding sgn_pos a_pos by auto
  13.556 @@ -3842,7 +3840,7 @@
  13.557              unfolding odd_Suc_mult_two_ex by auto
  13.558            hence m_plus: "2 * (m + 1) = n + 1" by auto
  13.559            from bounds[of "m + 1", unfolded this atLeastAtMost_iff, THEN conjunct1] bounds[of m, unfolded m_def atLeastAtMost_iff, THEN conjunct2]
  13.560 -          have "\<bar>arctan x - (\<Sum>i = 0..<n. (?c x i))\<bar> \<le> (\<Sum>i = 0..<n. (?c x i)) - (\<Sum>i = 0..<n+1. (?c x i))"
  13.561 +          have "\<bar>arctan x - (\<Sum>i<n. (?c x i))\<bar> \<le> (\<Sum>i<n. (?c x i)) - (\<Sum>i<n+1. (?c x i))"
  13.562              by auto
  13.563            also have "\<dots> = - ?c x n" unfolding One_nat_def by auto
  13.564            also have "\<dots> = ?a x n" unfolding sgn_neg a_pos by auto