
paulson@13958: (*  Title       : Integration.thy
paulson@13958:     Author      : Jacques D. Fleuriot
paulson@13958:     Copyright   : 2000  University of Edinburgh
paulson@15093:     Conversion to Isar and new proofs by Lawrence C Paulson, 2004
paulson@13958: *)
paulson@13958: 
paulson@15093: header{*Theory of Integration*}
paulson@13958: 
nipkow@15131: theory Integration
nipkow@15131: import MacLaurin
nipkow@15131: begin
paulson@15093: 
paulson@15093: text{*We follow John Harrison in formalizing the Gauge integral.*}
paulson@13958: 
paulson@13958: constdefs
paulson@13958: 
paulson@15093:   --{*Partitions and tagged partitions etc.*}
paulson@13958: 
paulson@13958:   partition :: "[(real*real),nat => real] => bool"
paulson@15093:   "partition == %(a,b) D. ((D 0 = a) &
paulson@15093:                          (\<exists>N. ((\<forall>n. n < N --> D(n) < D(Suc n)) &
paulson@15093:                             (\<forall>n. N \<le> n --> (D(n) = b)))))"
paulson@15093: 
paulson@15093:   psize :: "(nat => real) => nat"
paulson@15093:   "psize D == @N. (\<forall>n. n < N --> D(n) < D(Suc n)) &
paulson@15093:                   (\<forall>n. N \<le> n --> (D(n) = D(N)))"
paulson@15093: 
paulson@13958:   tpart :: "[(real*real),((nat => real)*(nat =>real))] => bool"
paulson@13958:   "tpart == %(a,b) (D,p). partition(a,b) D &
paulson@15093:                           (\<forall>n. D(n) \<le> p(n) & p(n) \<le> D(Suc n))"
paulson@13958: 
paulson@15093:   --{*Gauges and gauge-fine divisions*}
paulson@15093: 
paulson@15093:   gauge :: "[real => bool, real => real] => bool"
paulson@15093:   "gauge E g == \<forall>x. E x --> 0 < g(x)"
paulson@13958: 
paulson@13958:   fine :: "[real => real, ((nat => real)*(nat => real))] => bool"
paulson@15093:   "fine == % g (D,p). \<forall>n. n < (psize D) --> D(Suc n) - D(n) < g(p n)"
paulson@13958: 
paulson@15093:   --{*Riemann sum*}
paulson@13958: 
paulson@13958:   rsum :: "[((nat=>real)*(nat=>real)),real=>real] => real"
paulson@13958:   "rsum == %(D,p) f. sumr 0 (psize(D)) (%n. f(p n) * (D(Suc n) - D(n)))"
paulson@13958: 
paulson@15093:   --{*Gauge integrability (definite)*}
paulson@13958: 
paulson@13958:    Integral :: "[(real*real),real=>real,real] => bool"
paulson@15093:    "Integral == %(a,b) f k. \<forall>e. 0 < e -->
paulson@15093:                                (\<exists>g. gauge(%x. a \<le> x & x \<le> b) g &
paulson@15093:                                (\<forall>D p. tpart(a,b) (D,p) & fine(g)(D,p) -->
paulson@15093:                                          \<bar>rsum(D,p) f - k\<bar> < e))"
paulson@15093: 
paulson@15093: 
paulson@15093: lemma partition_zero [simp]: "a = b ==> psize (%n. if n = 0 then a else b) = 0"
paulson@15093: by (auto simp add: psize_def)
paulson@15093: 
paulson@15093: lemma partition_one [simp]: "a < b ==> psize (%n. if n = 0 then a else b) = 1"
paulson@15093: apply (simp add: psize_def)
paulson@15093: apply (rule some_equality, auto)
paulson@15093: apply (drule_tac x = 1 in spec, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_single [simp]:
paulson@15093:      "a \<le> b ==> partition(a,b)(%n. if n = 0 then a else b)"
paulson@15093: by (auto simp add: partition_def order_le_less)
paulson@15093: 
paulson@15093: lemma partition_lhs: "partition(a,b) D ==> (D(0) = a)"
paulson@15093: by (simp add: partition_def)
paulson@15093: 
paulson@15093: lemma partition:
paulson@15093:        "(partition(a,b) D) =
paulson@15093:         ((D 0 = a) &
paulson@15093:          (\<forall>n. n < (psize D) --> D n < D(Suc n)) &
paulson@15093:          (\<forall>n. (psize D) \<le> n --> (D n = b)))"
paulson@15093: apply (simp add: partition_def, auto)
paulson@15093: apply (subgoal_tac [!] "psize D = N", auto)
paulson@15093: apply (simp_all (no_asm) add: psize_def)
paulson@15093: apply (rule_tac [!] some_equality, blast)
paulson@15093:   prefer 2 apply blast
paulson@15093: apply (rule_tac [!] ccontr)
paulson@15093: apply (simp_all add: linorder_neq_iff, safe)
paulson@15093: apply (drule_tac x = Na in spec)
paulson@15093: apply (rotate_tac 3)
paulson@15093: apply (drule_tac x = "Suc Na" in spec, simp)
paulson@15093: apply (rotate_tac 2)
paulson@15093: apply (drule_tac x = N in spec, simp)
paulson@15093: apply (drule_tac x = Na in spec)
paulson@15094: apply (drule_tac x = "Suc Na" and P = "%n. Na\<le>n \<longrightarrow> D n = D Na" in spec, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_rhs: "partition(a,b) D ==> (D(psize D) = b)"
paulson@15093: by (simp add: partition)
paulson@15093: 
paulson@15093: lemma partition_rhs2: "[|partition(a,b) D; psize D \<le> n |] ==> (D n = b)"
paulson@15093: by (simp add: partition)
paulson@15093: 
paulson@15093: lemma lemma_partition_lt_gen [rule_format]:
paulson@15093:  "partition(a,b) D & m + Suc d \<le> n & n \<le> (psize D) --> D(m) < D(m + Suc d)"
paulson@15093: apply (induct_tac "d", auto simp add: partition)
paulson@15093: apply (blast dest: Suc_le_lessD  intro: less_le_trans order_less_trans)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma less_eq_add_Suc: "m < n ==> \<exists>d. n = m + Suc d"
paulson@15093: by (auto simp add: less_iff_Suc_add)
paulson@15093: 
paulson@15093: lemma partition_lt_gen:
paulson@15093:      "[|partition(a,b) D; m < n; n \<le> (psize D)|] ==> D(m) < D(n)"
paulson@15093: by (auto dest: less_eq_add_Suc intro: lemma_partition_lt_gen)
paulson@15093: 
paulson@15093: lemma partition_lt: "partition(a,b) D ==> n < (psize D) ==> D(0) < D(Suc n)"
paulson@15093: apply (induct "n")
paulson@15093: apply (auto simp add: partition)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_le: "partition(a,b) D ==> a \<le> b"
paulson@15093: apply (frule partition [THEN iffD1], safe)
paulson@15093: apply (rotate_tac 2)
paulson@15093: apply (drule_tac x = "psize D" in spec, safe)
paulson@15093: apply (rule ccontr)
paulson@15093: apply (case_tac "psize D = 0", safe)
paulson@15093: apply (drule_tac [2] n = "psize D - 1" in partition_lt, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_gt: "[|partition(a,b) D; n < (psize D)|] ==> D(n) < D(psize D)"
paulson@15093: by (auto intro: partition_lt_gen)
paulson@15093: 
paulson@15093: lemma partition_eq: "partition(a,b) D ==> ((a = b) = (psize D = 0))"
paulson@15093: apply (frule partition [THEN iffD1], safe)
paulson@15093: apply (rotate_tac 2)
paulson@15093: apply (drule_tac x = "psize D" in spec)
paulson@15093: apply (rule ccontr)
paulson@15093: apply (drule_tac n = "psize D - 1" in partition_lt)
paulson@15093: prefer 3 apply (blast, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_lb: "partition(a,b) D ==> a \<le> D(r)"
paulson@15093: apply (frule partition [THEN iffD1], safe)
paulson@15093: apply (induct_tac "r")
paulson@15093: apply (cut_tac [2] y = "Suc n" and x = "psize D" in linorder_le_less_linear, safe)
paulson@15093:  apply (blast intro: order_trans partition_le)
paulson@15093: apply (drule_tac x = n in spec)
paulson@15093: apply (best intro: order_less_trans order_trans order_less_imp_le)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_lb_lt: "[| partition(a,b) D; psize D ~= 0 |] ==> a < D(Suc n)"
paulson@15093: apply (rule_tac t = a in partition_lhs [THEN subst], assumption)
paulson@15093: apply (cut_tac x = "Suc n" and y = "psize D" in linorder_le_less_linear)
paulson@15093: apply (frule partition [THEN iffD1], safe)
paulson@15093:  apply (blast intro: partition_lt less_le_trans)
paulson@15093: apply (rotate_tac 3)
paulson@15093: apply (drule_tac x = "Suc n" in spec)
paulson@15093: apply (erule impE)
paulson@15093: apply (erule less_imp_le)
paulson@15093: apply (frule partition_rhs)
paulson@15093: apply (drule partition_gt, assumption)
paulson@15093: apply (simp (no_asm_simp))
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_ub: "partition(a,b) D ==> D(r) \<le> b"
paulson@15093: apply (frule partition [THEN iffD1])
paulson@15093: apply (cut_tac x = "psize D" and y = r in linorder_le_less_linear, safe, blast)
paulson@15093: apply (subgoal_tac "\<forall>x. D ((psize D) - x) \<le> b")
paulson@15093: apply (rotate_tac 4)
paulson@15093: apply (drule_tac x = "psize D - r" in spec)
paulson@15093: apply (subgoal_tac "psize D - (psize D - r) = r")
paulson@15093: apply simp
paulson@15093: apply arith
paulson@15093: apply safe
paulson@15093: apply (induct_tac "x")
paulson@15093: apply (simp (no_asm), blast)
paulson@15093: apply (case_tac "psize D - Suc n = 0")
paulson@15093: apply (erule_tac V = "\<forall>n. psize D \<le> n --> D n = b" in thin_rl)
paulson@15093: apply (simp (no_asm_simp) add: partition_le)
paulson@15093: apply (rule order_trans)
paulson@15093:  prefer 2 apply assumption
paulson@15093: apply (subgoal_tac "psize D - n = Suc (psize D - Suc n)")
paulson@15093:  prefer 2 apply arith
paulson@15093: apply (drule_tac x = "psize D - Suc n" in spec)
paulson@15093: apply (erule_tac V = "\<forall>n. psize D \<le> n --> D n = b" in thin_rl, simp)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_ub_lt: "[| partition(a,b) D; n < psize D |] ==> D(n) < b"
paulson@15093: by (blast intro: partition_rhs [THEN subst] partition_gt)
paulson@15093: 
paulson@15093: lemma lemma_partition_append1:
paulson@15093:      "[| partition (a, b) D1; partition (b, c) D2 |]
paulson@15093:        ==> (\<forall>n.
paulson@15093:              n < psize D1 + psize D2 -->
paulson@15093:              (if n < psize D1 then D1 n else D2 (n - psize D1))
paulson@15093:              < (if Suc n < psize D1 then D1 (Suc n)
paulson@15093:                 else D2 (Suc n - psize D1))) &
paulson@15093:          (\<forall>n.
paulson@15093:              psize D1 + psize D2 \<le> n -->
paulson@15093:              (if n < psize D1 then D1 n else D2 (n - psize D1)) =
paulson@15093:              (if psize D1 + psize D2 < psize D1 then D1 (psize D1 + psize D2)
paulson@15093:               else D2 (psize D1 + psize D2 - psize D1)))"
paulson@15093: apply safe
paulson@15093: apply (auto intro: partition_lt_gen)
paulson@15093: apply (subgoal_tac "psize D1 = Suc n")
paulson@15093: apply (auto intro!: partition_lt_gen simp add: partition_lhs partition_ub_lt)
paulson@15093: apply (auto intro!: partition_rhs2 simp add: partition_rhs
paulson@15093:             split: nat_diff_split)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_psize1:
paulson@15093:      "[| partition (a, b) D1; partition (b, c) D2; N < psize D1 |]
paulson@15093:       ==> D1(N) < D2 (psize D2)"
paulson@15094: apply (rule_tac y = "D1 (psize D1)" in order_less_le_trans)
paulson@15093: apply (erule partition_gt, assumption)
paulson@15093: apply (auto simp add: partition_rhs partition_le)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_partition_append2:
paulson@15093:      "[| partition (a, b) D1; partition (b, c) D2 |]
paulson@15093:       ==> psize (%n. if n < psize D1 then D1 n else D2 (n - psize D1)) =
paulson@15093:           psize D1 + psize D2"
paulson@15093: apply (rule_tac D2 = "%n. if n < psize D1 then D1 n else D2 (n - psize D1) "
paulson@15093:        in psize_def [THEN meta_eq_to_obj_eq, THEN ssubst])
paulson@15093: apply (rule some1_equality)
paulson@15093: prefer 2 apply (blast intro!: lemma_partition_append1)
paulson@15093: apply (rule ex1I, rule lemma_partition_append1, auto)
paulson@15093: apply (rule ccontr)
paulson@15093: apply (simp add: linorder_neq_iff, safe)
paulson@15093: apply (rotate_tac 3)
paulson@15093: apply (drule_tac x = "psize D1 + psize D2" in spec, auto)
paulson@15093: apply (case_tac "N < psize D1")
paulson@15093: apply (auto dest: lemma_psize1)
paulson@15093: apply (subgoal_tac "N - psize D1 < psize D2")
paulson@15093:  prefer 2 apply arith
paulson@15093: apply (drule_tac a = b and b = c in partition_gt, auto)
paulson@15093: apply (drule_tac x = "psize D1 + psize D2" in spec)
paulson@15093: apply (auto simp add: partition_rhs2)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma tpart_eq_lhs_rhs:
paulson@15093: "[|psize D = 0; tpart(a,b) (D,p)|] ==> a = b"
paulson@15093: apply (simp add: tpart_def)
paulson@15093: apply (auto simp add: partition_eq)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma tpart_partition: "tpart(a,b) (D,p) ==> partition(a,b) D"
paulson@15093: by (simp add: tpart_def)
paulson@15093: 
paulson@15093: lemma partition_append:
paulson@15093:      "[| tpart(a,b) (D1,p1); fine(g) (D1,p1);
paulson@15093:          tpart(b,c) (D2,p2); fine(g) (D2,p2) |]
paulson@15093:        ==> \<exists>D p. tpart(a,c) (D,p) & fine(g) (D,p)"
paulson@15093: apply (rule_tac x = "%n. if n < psize D1 then D1 n else D2 (n - psize D1)"
paulson@15093:        in exI)
paulson@15093: apply (rule_tac x = "%n. if n < psize D1 then p1 n else p2 (n - psize D1)"
paulson@15093:        in exI)
paulson@15093: apply (case_tac "psize D1 = 0")
paulson@15093: apply (auto dest: tpart_eq_lhs_rhs)
paulson@15093:  prefer 2
paulson@15093: apply (simp add: fine_def
paulson@15093:                  lemma_partition_append2 [OF tpart_partition tpart_partition])
paulson@15093:   --{*But must not expand @{term fine} in other subgoals*}
paulson@15093: apply auto
paulson@15093: apply (subgoal_tac "psize D1 = Suc n")
paulson@15093:  prefer 2 apply arith
paulson@15093: apply (drule tpart_partition [THEN partition_rhs])
paulson@15093: apply (drule tpart_partition [THEN partition_lhs])
paulson@15093: apply (auto split: nat_diff_split)
paulson@15093: apply (auto simp add: tpart_def)
paulson@15093: defer 1
paulson@15093:  apply (subgoal_tac "psize D1 = Suc n")
paulson@15093:   prefer 2 apply arith
paulson@15093:  apply (drule partition_rhs)
paulson@15093:  apply (drule partition_lhs, auto)
paulson@15093: apply (simp split: nat_diff_split)
paulson@15093: apply (subst partition)
paulson@15093: apply (subst lemma_partition_append2)
paulson@15093: apply (rule_tac [3] conjI)
paulson@15093: apply (drule_tac [4] lemma_partition_append1)
paulson@15093: apply (auto simp add: partition_lhs partition_rhs)
paulson@15093: done
paulson@15093: 
paulson@15093: text{*We can always find a division which is fine wrt any gauge*}
paulson@15093: 
paulson@15093: lemma partition_exists:
paulson@15093:      "[| a \<le> b; gauge(%x. a \<le> x & x \<le> b) g |]
paulson@15093:       ==> \<exists>D p. tpart(a,b) (D,p) & fine g (D,p)"
paulson@15093: apply (cut_tac P = "%(u,v). a \<le> u & v \<le> b --> 
paulson@15093:                    (\<exists>D p. tpart (u,v) (D,p) & fine (g) (D,p))" 
paulson@15093:        in lemma_BOLZANO2)
paulson@15093: apply safe
paulson@15093: apply (blast intro: real_le_trans)+
paulson@15093: apply (auto intro: partition_append)
paulson@15093: apply (case_tac "a \<le> x & x \<le> b")
paulson@15093: apply (rule_tac [2] x = 1 in exI, auto)
paulson@15093: apply (rule_tac x = "g x" in exI)
paulson@15093: apply (auto simp add: gauge_def)
paulson@15093: apply (rule_tac x = "%n. if n = 0 then aa else ba" in exI)
paulson@15093: apply (rule_tac x = "%n. if n = 0 then x else ba" in exI)
paulson@15093: apply (auto simp add: tpart_def fine_def)
paulson@15093: done
paulson@15093: 
paulson@15093: text{*Lemmas about combining gauges*}
paulson@15093: 
paulson@15093: lemma gauge_min:
paulson@15093:      "[| gauge(E) g1; gauge(E) g2 |]
paulson@15093:       ==> gauge(E) (%x. if g1(x) < g2(x) then g1(x) else g2(x))"
paulson@15093: by (simp add: gauge_def)
paulson@15093: 
paulson@15093: lemma fine_min:
paulson@15093:       "fine (%x. if g1(x) < g2(x) then g1(x) else g2(x)) (D,p)
paulson@15093:        ==> fine(g1) (D,p) & fine(g2) (D,p)"
paulson@15093: by (auto simp add: fine_def split: split_if_asm)
paulson@15093: 
paulson@15093: 
paulson@15093: text{*The integral is unique if it exists*}
paulson@15093: 
paulson@15093: lemma Integral_unique:
paulson@15093:     "[| a \<le> b; Integral(a,b) f k1; Integral(a,b) f k2 |] ==> k1 = k2"
paulson@15093: apply (simp add: Integral_def)
paulson@15093: apply (drule_tac x = "\<bar>k1 - k2\<bar> /2" in spec)+
paulson@15093: apply auto
paulson@15093: apply (drule gauge_min, assumption)
paulson@15093: apply (drule_tac g = "%x. if g x < ga x then g x else ga x" 
paulson@15093:        in partition_exists, assumption, auto)
paulson@15093: apply (drule fine_min)
paulson@15093: apply (drule spec)+
paulson@15093: apply auto
paulson@15094: apply (subgoal_tac "\<bar>(rsum (D,p) f - k2) - (rsum (D,p) f - k1)\<bar> < \<bar>k1 - k2\<bar>")
paulson@15093: apply arith
paulson@15093: apply (drule add_strict_mono, assumption)
paulson@15093: apply (auto simp only: left_distrib [symmetric] mult_2_right [symmetric] 
paulson@15093:                 mult_less_cancel_right, arith)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma Integral_zero [simp]: "Integral(a,a) f 0"
paulson@15093: apply (auto simp add: Integral_def)
paulson@15093: apply (rule_tac x = "%x. 1" in exI)
paulson@15093: apply (auto dest: partition_eq simp add: gauge_def tpart_def rsum_def)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma sumr_partition_eq_diff_bounds [simp]:
paulson@15093:      "sumr 0 m (%n. D (Suc n) - D n) = D(m) - D 0"
paulson@15093: by (induct_tac "m", auto)
paulson@15093: 
paulson@15093: lemma Integral_eq_diff_bounds: "a \<le> b ==> Integral(a,b) (%x. 1) (b - a)"
paulson@15093: apply (drule real_le_imp_less_or_eq, auto)
paulson@15093: apply (auto simp add: rsum_def Integral_def)
paulson@15093: apply (rule_tac x = "%x. b - a" in exI)
paulson@15093: apply (auto simp add: gauge_def abs_interval_iff tpart_def partition)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma Integral_mult_const: "a \<le> b ==> Integral(a,b) (%x. c)  (c*(b - a))"
paulson@15093: apply (drule real_le_imp_less_or_eq, auto)
paulson@15093: apply (auto simp add: rsum_def Integral_def)
paulson@15093: apply (rule_tac x = "%x. b - a" in exI)
paulson@15093: apply (auto simp add: sumr_mult [symmetric] gauge_def abs_interval_iff 
paulson@15093:                right_diff_distrib [symmetric] partition tpart_def)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma Integral_mult:
paulson@15093:      "[| a \<le> b; Integral(a,b) f k |] ==> Integral(a,b) (%x. c * f x) (c * k)"
paulson@15093: apply (drule real_le_imp_less_or_eq)
paulson@15093: apply (auto dest: Integral_unique [OF real_le_refl Integral_zero])
paulson@15093: apply (auto simp add: rsum_def Integral_def sumr_mult [symmetric] real_mult_assoc)
paulson@15093: apply (rule_tac a2 = c in abs_ge_zero [THEN real_le_imp_less_or_eq, THEN disjE])
paulson@15093:  prefer 2 apply force
paulson@15093: apply (drule_tac x = "e/abs c" in spec, auto)
paulson@15093: apply (simp add: zero_less_mult_iff divide_inverse)
paulson@15093: apply (rule exI, auto)
paulson@15093: apply (drule spec)+
paulson@15093: apply auto
paulson@15094: apply (rule_tac z1 = "inverse (abs c)" in real_mult_less_iff1 [THEN iffD1])
paulson@15093: apply (auto simp add: divide_inverse [symmetric] right_diff_distrib [symmetric])
paulson@15093: done
paulson@15093: 
paulson@15093: text{*Fundamental theorem of calculus (Part I)*}
paulson@15093: 
nipkow@15105: text{*"Straddle Lemma" : Swartz and Thompson: AMM 95(7) 1988 *}
paulson@15093: 
paulson@15093: lemma choiceP: "\<forall>x. P(x) --> (\<exists>y. Q x y) ==> \<exists>f. (\<forall>x. P(x) --> Q x (f x))"
paulson@15093: by meson
paulson@15093: 
paulson@15093: lemma choiceP2: "\<forall>x. P(x) --> (\<exists>y. R(y) & (\<exists>z. Q x y z)) ==>
paulson@15093:       \<exists>f fa. (\<forall>x. P(x) --> R(f x) & Q x (f x) (fa x))"
paulson@15093: by meson
paulson@15093: 
paulson@15093: (*UNUSED
paulson@15093: lemma choice2: "\<forall>x. (\<exists>y. R(y) & (\<exists>z. Q x y z)) ==>
paulson@15093:       \<exists>f fa. (\<forall>x. R(f x) & Q x (f x) (fa x))"
paulson@15093: *)
paulson@15093: 
paulson@15093: 
paulson@15093: (* new simplifications e.g. (y < x/n) = (y * n < x) are a real nuisance
paulson@15094:    they break the original proofs and make new proofs longer!*)
paulson@15093: lemma strad1:
paulson@15093:        "\<lbrakk>\<forall>xa::real. xa \<noteq> x \<and> \<bar>xa + - x\<bar> < s \<longrightarrow>
paulson@15093:              \<bar>(f xa - f x) / (xa - x) + - f' x\<bar> * 2 < e;
paulson@15093:         0 < e; a \<le> x; x \<le> b; 0 < s\<rbrakk>
paulson@15093:        \<Longrightarrow> \<forall>z. \<bar>z - x\<bar> < s -->\<bar>f z - f x - f' x * (z - x)\<bar> * 2 \<le> e * \<bar>z - x\<bar>"
paulson@15093: apply auto
paulson@15094: apply (case_tac "0 < \<bar>z - x\<bar>")
paulson@15093:  prefer 2 apply (simp add: zero_less_abs_iff)
paulson@15093: apply (drule_tac x = z in spec)
paulson@15093: apply (rule_tac z1 = "\<bar>inverse (z - x)\<bar>" 
paulson@15093:        in real_mult_le_cancel_iff2 [THEN iffD1])
paulson@15093:  apply simp
paulson@15093: apply (simp del: abs_inverse abs_mult add: abs_mult [symmetric]
paulson@15093:           mult_assoc [symmetric])
paulson@15093: apply (subgoal_tac "inverse (z - x) * (f z - f x - f' x * (z - x)) 
paulson@15093:                     = (f z - f x) / (z - x) - f' x")
paulson@15093:  apply (simp add: abs_mult [symmetric] mult_ac diff_minus)
paulson@15093: apply (subst mult_commute)
paulson@15093: apply (simp add: left_distrib diff_minus)
paulson@15093: apply (simp add: mult_assoc divide_inverse)
paulson@15093: apply (simp add: left_distrib)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_straddle:
paulson@15093:      "[| \<forall>x. a \<le> x & x \<le> b --> DERIV f x :> f'(x); 0 < e |]
paulson@15093:       ==> \<exists>g. gauge(%x. a \<le> x & x \<le> b) g &
paulson@15093:                 (\<forall>x u v. a \<le> u & u \<le> x & x \<le> v & v \<le> b & (v - u) < g(x)
paulson@15094:                   --> \<bar>(f(v) - f(u)) - (f'(x) * (v - u))\<bar> \<le> e * (v - u))"
paulson@15093: apply (simp add: gauge_def)
paulson@15093: apply (subgoal_tac "\<forall>x. a \<le> x & x \<le> b --> 
paulson@15094:         (\<exists>d. 0 < d & 
paulson@15094:              (\<forall>u v. u \<le> x & x \<le> v & (v - u) < d --> 
paulson@15094:                 \<bar>(f (v) - f (u)) - (f' (x) * (v - u))\<bar> \<le> e * (v - u)))")
paulson@15093: apply (drule choiceP, auto)
paulson@15093: apply (drule spec, auto)
paulson@15093: apply (auto simp add: DERIV_iff2 LIM_def)
paulson@15093: apply (drule_tac x = "e/2" in spec, auto)
paulson@15093: apply (frule strad1, assumption+)
paulson@15093: apply (rule_tac x = s in exI, auto)
paulson@15093: apply (rule_tac x = u and y = v in linorder_cases, auto)
paulson@15094: apply (rule_tac j = "\<bar>(f (v) - f (x)) - (f' (x) * (v - x))\<bar> + 
paulson@15094:                      \<bar>(f (x) - f (u)) - (f' (x) * (x - u))\<bar>"
paulson@15093:        in real_le_trans)
paulson@15093: apply (rule abs_triangle_ineq [THEN [2] real_le_trans])
paulson@15093: apply (simp add: right_diff_distrib, arith)
paulson@15094: apply (rule_tac t = "e* (v - u)" in real_sum_of_halves [THEN subst])
paulson@15093: apply (rule add_mono)
paulson@15094: apply (rule_tac j = " (e / 2) * \<bar>v - x\<bar>" in real_le_trans)
paulson@15093:  prefer 2 apply simp apply arith
paulson@15093: apply (erule_tac [!]
paulson@15093:        V= "\<forall>xa. xa ~= x & \<bar>xa + - x\<bar> < s --> \<bar>(f xa - f x) / (xa - x) + - f' x\<bar> * 2 < e"
paulson@15093:         in thin_rl)
paulson@15093: apply (drule_tac x = v in spec, auto, arith)
paulson@15093: apply (drule_tac x = u in spec, auto, arith)
paulson@15093: apply (subgoal_tac "\<bar>f u - f x - f' x * (u - x)\<bar> = \<bar>f x - f u - f' x * (x - u)\<bar>")
paulson@15093: apply (rule order_trans)
paulson@15093: apply (auto simp add: abs_le_interval_iff)
paulson@15093: apply (simp add: right_diff_distrib, arith)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma FTC1: "[|a \<le> b; \<forall>x. a \<le> x & x \<le> b --> DERIV f x :> f'(x) |]
paulson@15093:       ==> Integral(a,b) f' (f(b) - f(a))"
paulson@15093: apply (drule real_le_imp_less_or_eq, auto)
paulson@15093: apply (auto simp add: Integral_def)
paulson@15093: apply (rule ccontr)
paulson@15093: apply (subgoal_tac "\<forall>e. 0 < e --> (\<exists>g. gauge (%x. a \<le> x & x \<le> b) g & (\<forall>D p. tpart (a, b) (D, p) & fine g (D, p) --> \<bar>rsum (D, p) f' - (f b - f a)\<bar> \<le> e))")
paulson@15093: apply (rotate_tac 3)
paulson@15093: apply (drule_tac x = "e/2" in spec, auto)
paulson@15093: apply (drule spec, auto)
paulson@15093: apply ((drule spec)+, auto)
paulson@15094: apply (drule_tac e = "ea/ (b - a)" in lemma_straddle)
paulson@15093: apply (auto simp add: zero_less_divide_iff)
paulson@15093: apply (rule exI)
paulson@15093: apply (auto simp add: tpart_def rsum_def)
paulson@15094: apply (subgoal_tac "sumr 0 (psize D) (%n. f(D(Suc n)) - f(D n)) = f b - f a")
paulson@15093:  prefer 2
paulson@15094:  apply (cut_tac D = "%n. f (D n)" and m = "psize D"
paulson@15093:         in sumr_partition_eq_diff_bounds)
paulson@15093:  apply (simp add: partition_lhs partition_rhs)
paulson@15093: apply (drule sym, simp)
paulson@15093: apply (simp (no_asm) add: sumr_diff)
paulson@15093: apply (rule sumr_rabs [THEN real_le_trans])
paulson@15094: apply (subgoal_tac "ea = sumr 0 (psize D) (%n. (ea / (b - a)) * (D (Suc n) - (D n)))")
paulson@15093: apply (simp add: abs_minus_commute)
paulson@15093: apply (rule_tac t = ea in ssubst, assumption)
paulson@15093: apply (rule sumr_le2)
paulson@15093: apply (rule_tac [2] sumr_mult [THEN subst])
paulson@15093: apply (auto simp add: partition_rhs partition_lhs partition_lb partition_ub
paulson@15093:           fine_def)
paulson@15093: done
paulson@13958: 
paulson@13958: 
paulson@15093: lemma Integral_subst: "[| Integral(a,b) f k1; k2=k1 |] ==> Integral(a,b) f k2"
paulson@15093: by simp
paulson@15093: 
paulson@15093: lemma Integral_add:
paulson@15093:      "[| a \<le> b; b \<le> c; Integral(a,b) f' k1; Integral(b,c) f' k2;
paulson@15093:          \<forall>x. a \<le> x & x \<le> c --> DERIV f x :> f' x |]
paulson@15093:      ==> Integral(a,c) f' (k1 + k2)"
paulson@15093: apply (rule FTC1 [THEN Integral_subst], auto)
paulson@15093: apply (frule FTC1, auto)
paulson@15093: apply (frule_tac a = b in FTC1, auto)
paulson@15093: apply (drule_tac x = x in spec, auto)
paulson@15093: apply (drule_tac ?k2.0 = "f b - f a" in Integral_unique)
paulson@15093: apply (drule_tac [3] ?k2.0 = "f c - f b" in Integral_unique, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_psize_Least:
paulson@15093:      "partition(a,b) D ==> psize D = (LEAST n. D(n) = b)"
paulson@15093: apply (auto intro!: Least_equality [symmetric] partition_rhs)
paulson@15093: apply (rule ccontr)
paulson@15093: apply (drule partition_ub_lt)
paulson@15093: apply (auto simp add: linorder_not_less [symmetric])
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_partition_bounded: "partition (a, c) D ==> ~ (\<exists>n. c < D(n))"
paulson@15093: apply safe
paulson@15093: apply (drule_tac r = n in partition_ub, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_partition_eq:
paulson@15093:      "partition (a, c) D ==> D = (%n. if D n < c then D n else c)"
paulson@15093: apply (rule ext, auto)
paulson@15093: apply (auto dest!: lemma_partition_bounded)
paulson@15093: apply (drule_tac x = n in spec, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_partition_eq2:
paulson@15093:      "partition (a, c) D ==> D = (%n. if D n \<le> c then D n else c)"
paulson@15093: apply (rule ext, auto)
paulson@15093: apply (auto dest!: lemma_partition_bounded)
paulson@15093: apply (drule_tac x = n in spec, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_lt_Suc:
paulson@15093:      "[| partition(a,b) D; n < psize D |] ==> D n < D (Suc n)"
paulson@15093: by (auto simp add: partition)
paulson@15093: 
paulson@15093: lemma tpart_tag_eq: "tpart(a,c) (D,p) ==> p = (%n. if D n < c then p n else c)"
paulson@15093: apply (rule ext)
paulson@15093: apply (auto simp add: tpart_def)
paulson@15093: apply (drule linorder_not_less [THEN iffD1])
paulson@15093: apply (drule_tac r = "Suc n" in partition_ub)
paulson@15093: apply (drule_tac x = n in spec, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: subsection{*Lemmas for Additivity Theorem of Gauge Integral*}
paulson@15093: 
paulson@15093: lemma lemma_additivity1:
paulson@15093:      "[| a \<le> D n; D n < b; partition(a,b) D |] ==> n < psize D"
paulson@15093: by (auto simp add: partition linorder_not_less [symmetric])
paulson@15093: 
paulson@15093: lemma lemma_additivity2: "[| a \<le> D n; partition(a,D n) D |] ==> psize D \<le> n"
paulson@15093: apply (rule ccontr, drule not_leE)
paulson@15093: apply (frule partition [THEN iffD1], safe)
paulson@15093: apply (frule_tac r = "Suc n" in partition_ub)
paulson@15093: apply (auto dest!: spec)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_eq_bound:
paulson@15093:      "[| partition(a,b) D; psize D < m |] ==> D(m) = D(psize D)"
paulson@15093: by (auto simp add: partition)
paulson@15093: 
paulson@15093: lemma partition_ub2: "[| partition(a,b) D; psize D < m |] ==> D(r) \<le> D(m)"
paulson@15093: by (simp add: partition partition_ub)
paulson@15093: 
paulson@15093: lemma tag_point_eq_partition_point:
paulson@15093:     "[| tpart(a,b) (D,p); psize D \<le> m |] ==> p(m) = D(m)"
paulson@15093: apply (simp add: tpart_def, auto)
paulson@15093: apply (drule_tac x = m in spec)
paulson@15093: apply (auto simp add: partition_rhs2)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_lt_cancel: "[| partition(a,b) D; D m < D n |] ==> m < n"
paulson@15093: apply (cut_tac m = n and n = "psize D" in less_linear, auto)
paulson@15093: apply (rule ccontr, drule leI, drule le_imp_less_or_eq)
paulson@15093: apply (cut_tac m = m and n = "psize D" in less_linear)
paulson@15093: apply (auto dest: partition_gt)
paulson@15093: apply (drule_tac n = m in partition_lt_gen, auto)
paulson@15093: apply (frule partition_eq_bound)
paulson@15093: apply (drule_tac [2] partition_gt, auto)
paulson@15093: apply (rule ccontr, drule leI, drule le_imp_less_or_eq)
paulson@15093: apply (auto dest: partition_eq_bound)
paulson@15093: apply (rule ccontr, drule leI, drule le_imp_less_or_eq)
paulson@15093: apply (frule partition_eq_bound, assumption)
paulson@15093: apply (drule_tac m = m in partition_eq_bound, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_additivity4_psize_eq:
paulson@15093:      "[| a \<le> D n; D n < b; partition (a, b) D |]
paulson@15093:       ==> psize (%x. if D x < D n then D(x) else D n) = n"
paulson@15093: apply (unfold psize_def)
paulson@15093: apply (frule lemma_additivity1)
paulson@15093: apply (assumption, assumption)
paulson@15093: apply (rule some_equality)
paulson@15093: apply (auto intro: partition_lt_Suc)
paulson@15093: apply (drule_tac n = n in partition_lt_gen)
paulson@15093: apply (assumption, arith, arith)
paulson@15093: apply (cut_tac m = na and n = "psize D" in less_linear)
paulson@15093: apply (auto dest: partition_lt_cancel)
paulson@15093: apply (rule_tac x=N and y=n in linorder_cases)
paulson@15093: apply (drule_tac x = n and P="%m. N \<le> m --> ?f m = ?g m" in spec, auto)
paulson@15093: apply (drule_tac n = n in partition_lt_gen, auto, arith)
paulson@15093: apply (drule_tac x = n in spec)
paulson@15093: apply (simp split: split_if_asm)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_psize_left_less_psize:
paulson@15093:      "partition (a, b) D
paulson@15093:       ==> psize (%x. if D x < D n then D(x) else D n) \<le> psize D"
paulson@15093: apply (frule_tac r = n in partition_ub)
paulson@15093: apply (drule_tac x = "D n" in real_le_imp_less_or_eq)
paulson@15093: apply (auto simp add: lemma_partition_eq [symmetric])
paulson@15093: apply (frule_tac r = n in partition_lb)
paulson@15093: apply (drule lemma_additivity4_psize_eq)
paulson@15093: apply (rule_tac [3] ccontr, auto)
paulson@15093: apply (frule_tac not_leE [THEN [2] partition_eq_bound])
paulson@15093: apply (auto simp add: partition_rhs)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_psize_left_less_psize2:
paulson@15093:      "[| partition(a,b) D; na < psize (%x. if D x < D n then D(x) else D n) |]
paulson@15093:       ==> na < psize D"
paulson@15093: apply (erule_tac lemma_psize_left_less_psize [THEN [2] less_le_trans], assumption)
paulson@15093: done
paulson@15093: 
paulson@15093: 
paulson@15093: lemma lemma_additivity3:
paulson@15093:      "[| partition(a,b) D; D na < D n; D n < D (Suc na);
paulson@15093:          n < psize D |]
paulson@15093:       ==> False"
paulson@15093: apply (cut_tac m = n and n = "Suc na" in less_linear, auto)
paulson@15093: apply (drule_tac [2] n = n in partition_lt_gen, auto)
paulson@15093: apply (cut_tac m = "psize D" and n = na in less_linear)
paulson@15093: apply (auto simp add: partition_rhs2 less_Suc_eq)
paulson@15093: apply (drule_tac n = na in partition_lt_gen, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma psize_const [simp]: "psize (%x. k) = 0"
paulson@15093: by (simp add: psize_def, auto)
paulson@15093: 
paulson@15093: lemma lemma_additivity3a:
paulson@15093:      "[| partition(a,b) D; D na < D n; D n < D (Suc na);
paulson@15093:          na < psize D |]
paulson@15093:       ==> False"
paulson@15093: apply (frule_tac m = n in partition_lt_cancel)
paulson@15093: apply (auto intro: lemma_additivity3)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma better_lemma_psize_right_eq1:
paulson@15093:      "[| partition(a,b) D; D n < b |] ==> psize (%x. D (x + n)) \<le> psize D - n"
paulson@15093: apply (simp add: psize_def [of "(%x. D (x + n))"]);
paulson@15093: apply (rule_tac a = "psize D - n" in someI2, auto)
paulson@15093:   apply (simp add: partition less_diff_conv)
paulson@15093:  apply (simp add: le_diff_conv)
paulson@15093:  apply (case_tac "psize D \<le> n")
paulson@15093:   apply (simp add: partition_rhs2)
paulson@15093:  apply (simp add: partition linorder_not_le)
paulson@15093: apply (rule ccontr, drule not_leE)
paulson@15093: apply (drule_tac x = "psize D - n" in spec, auto)
paulson@15093: apply (frule partition_rhs, safe)
paulson@15093: apply (frule partition_lt_cancel, assumption)
paulson@15093: apply (drule partition [THEN iffD1], safe)
paulson@15093: apply (subgoal_tac "~ D (psize D - n + n) < D (Suc (psize D - n + n))")
paulson@15093:  apply blast
paulson@15093: apply (drule_tac x = "Suc (psize D)" and P="%n. ?P n \<longrightarrow> D n = D (psize D)"
paulson@15093:        in spec)
paulson@15093: apply (simp (no_asm_simp))
paulson@15093: done
paulson@15093: 
paulson@15093: lemma psize_le_n: "partition (a, D n) D ==> psize D \<le> n"
paulson@15093: apply (rule ccontr, drule not_leE)
paulson@15093: apply (frule partition_lt_Suc, assumption)
paulson@15093: apply (frule_tac r = "Suc n" in partition_ub, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma better_lemma_psize_right_eq1a:
paulson@15093:      "partition(a,D n) D ==> psize (%x. D (x + n)) \<le> psize D - n"
paulson@15093: apply (simp add: psize_def [of "(%x. D (x + n))"]);
paulson@15093: apply (rule_tac a = "psize D - n" in someI2, auto)
paulson@15093:   apply (simp add: partition less_diff_conv)
paulson@15093:  apply (simp add: le_diff_conv)
paulson@15093: apply (case_tac "psize D \<le> n")
paulson@15093:   apply (force intro: partition_rhs2)
paulson@15093:  apply (simp add: partition linorder_not_le)
paulson@15093: apply (rule ccontr, drule not_leE)
paulson@15093: apply (frule psize_le_n)
paulson@15093: apply (drule_tac x = "psize D - n" in spec, simp)
paulson@15093: apply (drule partition [THEN iffD1], safe)
paulson@15093: apply (drule_tac x = "Suc n" and P="%na. psize D \<le> na \<longrightarrow> D na = D n" in spec, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma better_lemma_psize_right_eq:
paulson@15093:      "partition(a,b) D ==> psize (%x. D (x + n)) \<le> psize D - n"
paulson@15093: apply (frule_tac r1 = n in partition_ub [THEN real_le_imp_less_or_eq])
paulson@15093: apply (blast intro: better_lemma_psize_right_eq1a better_lemma_psize_right_eq1)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_psize_right_eq1:
paulson@15093:      "[| partition(a,b) D; D n < b |] ==> psize (%x. D (x + n)) \<le> psize D"
paulson@15093: apply (simp add: psize_def [of "(%x. D (x + n))"]);
paulson@15093: apply (rule_tac a = "psize D - n" in someI2, auto)
paulson@15093:   apply (simp add: partition less_diff_conv)
paulson@15093:  apply (subgoal_tac "n \<le> psize D")
paulson@15093:   apply (simp add: partition le_diff_conv)
paulson@15093:  apply (rule ccontr, drule not_leE)
paulson@15093:  apply (drule_tac less_imp_le [THEN [2] partition_rhs2], auto)
paulson@15093: apply (rule ccontr, drule not_leE)
paulson@15093: apply (drule_tac x = "psize D" in spec)
paulson@15093: apply (simp add: partition)
paulson@15093: done
paulson@15093: 
paulson@15093: (* should be combined with previous theorem; also proof has redundancy *)
paulson@15093: lemma lemma_psize_right_eq1a:
paulson@15093:      "partition(a,D n) D ==> psize (%x. D (x + n)) \<le> psize D"
paulson@15093: apply (simp add: psize_def [of "(%x. D (x + n))"]);
paulson@15093: apply (rule_tac a = "psize D - n" in someI2, auto)
paulson@15093:   apply (simp add: partition less_diff_conv)
paulson@15093:  apply (case_tac "psize D \<le> n")
paulson@15093:   apply (force intro: partition_rhs2 simp add: le_diff_conv)
paulson@15093:  apply (simp add: partition le_diff_conv)
paulson@15093: apply (rule ccontr, drule not_leE)
paulson@15093: apply (drule_tac x = "psize D" in spec)
paulson@15093: apply (simp add: partition)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_psize_right_eq:
paulson@15093:      "[| partition(a,b) D |] ==> psize (%x. D (x + n)) \<le> psize D"
paulson@15093: apply (frule_tac r1 = n in partition_ub [THEN real_le_imp_less_or_eq])
paulson@15093: apply (blast intro: lemma_psize_right_eq1a lemma_psize_right_eq1)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma tpart_left1:
paulson@15093:      "[| a \<le> D n; tpart (a, b) (D, p) |]
paulson@15093:       ==> tpart(a, D n) (%x. if D x < D n then D(x) else D n,
paulson@15093:           %x. if D x < D n then p(x) else D n)"
paulson@15093: apply (frule_tac r = n in tpart_partition [THEN partition_ub])
paulson@15093: apply (drule_tac x = "D n" in real_le_imp_less_or_eq)
paulson@15093: apply (auto simp add: tpart_partition [THEN lemma_partition_eq, symmetric] tpart_tag_eq [symmetric])
paulson@15093: apply (frule_tac tpart_partition [THEN [3] lemma_additivity1])
paulson@15093: apply (auto simp add: tpart_def)
paulson@15093: apply (drule_tac [2] linorder_not_less [THEN iffD1, THEN real_le_imp_less_or_eq], auto)
paulson@15093:   prefer 3
paulson@15093:   apply (drule linorder_not_less [THEN iffD1])
paulson@15093:   apply (drule_tac x=na in spec, arith)
paulson@15093:  prefer 2 apply (blast dest: lemma_additivity3)
paulson@15093: apply (frule lemma_additivity4_psize_eq)
paulson@15093: apply (assumption+)
paulson@15093: apply (rule partition [THEN iffD2])
paulson@15093: apply (frule partition [THEN iffD1])
paulson@15093: apply (auto intro: partition_lt_gen)
paulson@15093: apply (drule_tac n = n in partition_lt_gen)
paulson@15093: apply (assumption, arith, blast)
paulson@15093: apply (drule partition_lt_cancel, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma fine_left1:
paulson@15093:      "[| a \<le> D n; tpart (a, b) (D, p); gauge (%x. a \<le> x & x \<le> D n) g;
paulson@15093:          fine (%x. if x < D n then min (g x) ((D n - x)/ 2)
paulson@15093:                  else if x = D n then min (g (D n)) (ga (D n))
paulson@15093:                       else min (ga x) ((x - D n)/ 2)) (D, p) |]
paulson@15093:       ==> fine g
paulson@15093:            (%x. if D x < D n then D(x) else D n,
paulson@15093:             %x. if D x < D n then p(x) else D n)"
paulson@15093: apply (auto simp add: fine_def tpart_def gauge_def)
paulson@15093: apply (frule_tac [!] na=na in lemma_psize_left_less_psize2)
paulson@15093: apply (drule_tac [!] x = na in spec, auto)
paulson@15093: apply (drule_tac [!] x = na in spec, auto)
paulson@15093: apply (auto dest: lemma_additivity3a simp add: split_if_asm)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma tpart_right1:
paulson@15093:      "[| a \<le> D n; tpart (a, b) (D, p) |]
paulson@15093:       ==> tpart(D n, b) (%x. D(x + n),%x. p(x + n))"
paulson@15093: apply (simp add: tpart_def partition_def, safe)
paulson@15093: apply (rule_tac x = "N - n" in exI, auto)
paulson@15093: apply (rotate_tac 2)
paulson@15093: apply (drule_tac x = "na + n" in spec)
paulson@15093: apply (rotate_tac [2] 3)
paulson@15093: apply (drule_tac [2] x = "na + n" in spec, arith+)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma fine_right1:
paulson@15093:      "[| a \<le> D n; tpart (a, b) (D, p); gauge (%x. D n \<le> x & x \<le> b) ga;
paulson@15093:          fine (%x. if x < D n then min (g x) ((D n - x)/ 2)
paulson@15093:                  else if x = D n then min (g (D n)) (ga (D n))
paulson@15093:                       else min (ga x) ((x - D n)/ 2)) (D, p) |]
paulson@15093:       ==> fine ga (%x. D(x + n),%x. p(x + n))"
paulson@15093: apply (auto simp add: fine_def gauge_def)
paulson@15093: apply (drule_tac x = "na + n" in spec)
paulson@15093: apply (frule_tac n = n in tpart_partition [THEN better_lemma_psize_right_eq], auto, arith)
paulson@15093: apply (simp add: tpart_def, safe)
paulson@15094: apply (subgoal_tac "D n \<le> p (na + n)")
paulson@15094: apply (drule_tac y = "p (na + n)" in real_le_imp_less_or_eq)
paulson@15093: apply safe
paulson@15093: apply (simp split: split_if_asm, simp)
paulson@15093: apply (drule less_le_trans, assumption)
paulson@15093: apply (rotate_tac 5)
paulson@15093: apply (drule_tac x = "na + n" in spec, safe)
paulson@15093: apply (rule_tac y="D (na + n)" in order_trans)
paulson@15093: apply (case_tac "na = 0", auto)
paulson@15093: apply (erule partition_lt_gen [THEN order_less_imp_le], arith+)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma rsum_add: "rsum (D, p) (%x. f x + g x) =  rsum (D, p) f + rsum(D, p) g"
paulson@15093: by (simp add: rsum_def sumr_add left_distrib)
paulson@15093: 
paulson@15094: text{* Bartle/Sherbert: Theorem 10.1.5 p. 278 *}
paulson@15093: lemma Integral_add_fun:
paulson@15093:     "[| a \<le> b; Integral(a,b) f k1; Integral(a,b) g k2 |]
paulson@15093:      ==> Integral(a,b) (%x. f x + g x) (k1 + k2)"
paulson@15093: apply (simp add: Integral_def, auto)
paulson@15093: apply ((drule_tac x = "e/2" in spec)+)
paulson@15093: apply auto
paulson@15093: apply (drule gauge_min, assumption)
paulson@15094: apply (rule_tac x = " (%x. if ga x < gaa x then ga x else gaa x)" in exI)
paulson@15093: apply auto
paulson@15093: apply (drule fine_min)
paulson@15093: apply ((drule spec)+, auto)
paulson@15093: apply (drule_tac a = "\<bar>rsum (D, p) f - k1\<bar> * 2" and c = "\<bar>rsum (D, p) g - k2\<bar> * 2" in add_strict_mono, assumption)
paulson@15093: apply (auto simp only: rsum_add left_distrib [symmetric]
paulson@15093:                 mult_2_right [symmetric] real_mult_less_iff1, arith)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_lt_gen2:
paulson@15093:      "[| partition(a,b) D; r < psize D |] ==> 0 < D (Suc r) - D r"
paulson@15093: by (auto simp add: partition)
paulson@15093: 
paulson@15093: lemma lemma_Integral_le:
paulson@15093:      "[| \<forall>x. a \<le> x & x \<le> b --> f x \<le> g x;
paulson@15093:          tpart(a,b) (D,p)
paulson@15093:       |] ==> \<forall>n. n \<le> psize D --> f (p n) \<le> g (p n)"
paulson@15093: apply (simp add: tpart_def)
paulson@15093: apply (auto, frule partition [THEN iffD1], auto)
paulson@15093: apply (drule_tac x = "p n" in spec, auto)
paulson@15093: apply (case_tac "n = 0", simp)
paulson@15093: apply (rule partition_lt_gen [THEN order_less_le_trans, THEN order_less_imp_le], auto)
paulson@15093: apply (drule le_imp_less_or_eq, auto)
paulson@15093: apply (drule_tac [2] x = "psize D" in spec, auto)
paulson@15093: apply (drule_tac r = "Suc n" in partition_ub)
paulson@15093: apply (drule_tac x = n in spec, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma lemma_Integral_rsum_le:
paulson@15093:      "[| \<forall>x. a \<le> x & x \<le> b --> f x \<le> g x;
paulson@15093:          tpart(a,b) (D,p)
paulson@15093:       |] ==> rsum(D,p) f \<le> rsum(D,p) g"
paulson@15093: apply (simp add: rsum_def)
paulson@15093: apply (auto intro!: sumr_le2 dest: tpart_partition [THEN partition_lt_gen2]
paulson@15093:                dest!: lemma_Integral_le)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma Integral_le:
paulson@15093:     "[| a \<le> b;
paulson@15093:         \<forall>x. a \<le> x & x \<le> b --> f(x) \<le> g(x);
paulson@15093:         Integral(a,b) f k1; Integral(a,b) g k2
paulson@15093:      |] ==> k1 \<le> k2"
paulson@15093: apply (simp add: Integral_def)
paulson@15093: apply (rotate_tac 2)
paulson@15093: apply (drule_tac x = "\<bar>k1 - k2\<bar> /2" in spec)
paulson@15093: apply (drule_tac x = "\<bar>k1 - k2\<bar> /2" in spec)
paulson@15093: apply auto
paulson@15093: apply (drule gauge_min, assumption)
paulson@15093: apply (drule_tac g = "%x. if ga x < gaa x then ga x else gaa x" 
paulson@15093:        in partition_exists, assumption, auto)
paulson@15093: apply (drule fine_min)
paulson@15093: apply (drule_tac x = D in spec, drule_tac x = D in spec)
paulson@15093: apply (drule_tac x = p in spec, drule_tac x = p in spec, auto)
paulson@15093: apply (frule lemma_Integral_rsum_le, assumption)
paulson@15094: apply (subgoal_tac "\<bar>(rsum (D,p) f - k1) - (rsum (D,p) g - k2)\<bar> < \<bar>k1 - k2\<bar>")
paulson@15093: apply arith
paulson@15093: apply (drule add_strict_mono, assumption)
paulson@15093: apply (auto simp only: left_distrib [symmetric] mult_2_right [symmetric]
paulson@15093:                        real_mult_less_iff1, arith)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma Integral_imp_Cauchy:
paulson@15093:      "(\<exists>k. Integral(a,b) f k) ==>
paulson@15093:       (\<forall>e. 0 < e -->
paulson@15093:                (\<exists>g. gauge (%x. a \<le> x & x \<le> b) g &
paulson@15093:                        (\<forall>D1 D2 p1 p2.
paulson@15093:                             tpart(a,b) (D1, p1) & fine g (D1,p1) &
paulson@15093:                             tpart(a,b) (D2, p2) & fine g (D2,p2) -->
paulson@15093:                             \<bar>rsum(D1,p1) f - rsum(D2,p2) f\<bar> < e)))"
paulson@15093: apply (simp add: Integral_def, auto)
paulson@15093: apply (drule_tac x = "e/2" in spec, auto)
paulson@15093: apply (rule exI, auto)
paulson@15093: apply (frule_tac x = D1 in spec)
paulson@15093: apply (frule_tac x = D2 in spec)
paulson@15093: apply ((drule spec)+, auto)
paulson@15093: apply (erule_tac V = "0 < e" in thin_rl)
paulson@15093: apply (drule add_strict_mono, assumption)
paulson@15093: apply (auto simp only: left_distrib [symmetric] mult_2_right [symmetric]
paulson@15093:                        real_mult_less_iff1, arith)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma Cauchy_iff2:
paulson@15093:      "Cauchy X =
paulson@15093:       (\<forall>j. (\<exists>M. \<forall>m n. M \<le> m & M \<le> n -->
paulson@15093:                \<bar>X m + - X n\<bar> < inverse(real (Suc j))))"
paulson@15093: apply (simp add: Cauchy_def, auto)
paulson@15093: apply (drule reals_Archimedean, safe)
paulson@15093: apply (drule_tac x = n in spec, auto)
paulson@15093: apply (rule_tac x = M in exI, auto)
paulson@15093: apply (drule_tac x = m in spec)
paulson@15093: apply (drule_tac x = na in spec, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma partition_exists2:
paulson@15093:      "[| a \<le> b; \<forall>n. gauge (%x. a \<le> x & x \<le> b) (fa n) |]
paulson@15093:       ==> \<forall>n. \<exists>D p. tpart (a, b) (D, p) & fine (fa n) (D, p)"
paulson@15093: apply safe
paulson@15093: apply (rule partition_exists, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: lemma monotonic_anti_derivative:
paulson@15093:      "[| a \<le> b; \<forall>c. a \<le> c & c \<le> b --> f' c \<le> g' c;
paulson@15093:          \<forall>x. DERIV f x :> f' x; \<forall>x. DERIV g x :> g' x |]
paulson@15093:       ==> f b - f a \<le> g b - g a"
paulson@15093: apply (rule Integral_le, assumption)
paulson@15093: apply (rule_tac [2] FTC1)
paulson@15093: apply (rule_tac [4] FTC1, auto)
paulson@15093: done
paulson@15093: 
paulson@15093: end




