src/HOL/Hyperreal/Integration.thy
 author nipkow Wed Aug 18 11:09:40 2004 +0200 (2004-08-18) changeset 15140 322485b816ac parent 15131 c69542757a4d child 15197 19e735596e51 permissions -rw-r--r--
import -> imports
```     1 (*  Title       : Integration.thy
```
```     2     Author      : Jacques D. Fleuriot
```
```     3     Copyright   : 2000  University of Edinburgh
```
```     4     Conversion to Isar and new proofs by Lawrence C Paulson, 2004
```
```     5 *)
```
```     6
```
```     7 header{*Theory of Integration*}
```
```     8
```
```     9 theory Integration
```
```    10 imports MacLaurin
```
```    11 begin
```
```    12
```
```    13 text{*We follow John Harrison in formalizing the Gauge integral.*}
```
```    14
```
```    15 constdefs
```
```    16
```
```    17   --{*Partitions and tagged partitions etc.*}
```
```    18
```
```    19   partition :: "[(real*real),nat => real] => bool"
```
```    20   "partition == %(a,b) D. ((D 0 = a) &
```
```    21                          (\<exists>N. ((\<forall>n. n < N --> D(n) < D(Suc n)) &
```
```    22                             (\<forall>n. N \<le> n --> (D(n) = b)))))"
```
```    23
```
```    24   psize :: "(nat => real) => nat"
```
```    25   "psize D == @N. (\<forall>n. n < N --> D(n) < D(Suc n)) &
```
```    26                   (\<forall>n. N \<le> n --> (D(n) = D(N)))"
```
```    27
```
```    28   tpart :: "[(real*real),((nat => real)*(nat =>real))] => bool"
```
```    29   "tpart == %(a,b) (D,p). partition(a,b) D &
```
```    30                           (\<forall>n. D(n) \<le> p(n) & p(n) \<le> D(Suc n))"
```
```    31
```
```    32   --{*Gauges and gauge-fine divisions*}
```
```    33
```
```    34   gauge :: "[real => bool, real => real] => bool"
```
```    35   "gauge E g == \<forall>x. E x --> 0 < g(x)"
```
```    36
```
```    37   fine :: "[real => real, ((nat => real)*(nat => real))] => bool"
```
```    38   "fine == % g (D,p). \<forall>n. n < (psize D) --> D(Suc n) - D(n) < g(p n)"
```
```    39
```
```    40   --{*Riemann sum*}
```
```    41
```
```    42   rsum :: "[((nat=>real)*(nat=>real)),real=>real] => real"
```
```    43   "rsum == %(D,p) f. sumr 0 (psize(D)) (%n. f(p n) * (D(Suc n) - D(n)))"
```
```    44
```
```    45   --{*Gauge integrability (definite)*}
```
```    46
```
```    47    Integral :: "[(real*real),real=>real,real] => bool"
```
```    48    "Integral == %(a,b) f k. \<forall>e. 0 < e -->
```
```    49                                (\<exists>g. gauge(%x. a \<le> x & x \<le> b) g &
```
```    50                                (\<forall>D p. tpart(a,b) (D,p) & fine(g)(D,p) -->
```
```    51                                          \<bar>rsum(D,p) f - k\<bar> < e))"
```
```    52
```
```    53
```
```    54 lemma partition_zero [simp]: "a = b ==> psize (%n. if n = 0 then a else b) = 0"
```
```    55 by (auto simp add: psize_def)
```
```    56
```
```    57 lemma partition_one [simp]: "a < b ==> psize (%n. if n = 0 then a else b) = 1"
```
```    58 apply (simp add: psize_def)
```
```    59 apply (rule some_equality, auto)
```
```    60 apply (drule_tac x = 1 in spec, auto)
```
```    61 done
```
```    62
```
```    63 lemma partition_single [simp]:
```
```    64      "a \<le> b ==> partition(a,b)(%n. if n = 0 then a else b)"
```
```    65 by (auto simp add: partition_def order_le_less)
```
```    66
```
```    67 lemma partition_lhs: "partition(a,b) D ==> (D(0) = a)"
```
```    68 by (simp add: partition_def)
```
```    69
```
```    70 lemma partition:
```
```    71        "(partition(a,b) D) =
```
```    72         ((D 0 = a) &
```
```    73          (\<forall>n. n < (psize D) --> D n < D(Suc n)) &
```
```    74          (\<forall>n. (psize D) \<le> n --> (D n = b)))"
```
```    75 apply (simp add: partition_def, auto)
```
```    76 apply (subgoal_tac [!] "psize D = N", auto)
```
```    77 apply (simp_all (no_asm) add: psize_def)
```
```    78 apply (rule_tac [!] some_equality, blast)
```
```    79   prefer 2 apply blast
```
```    80 apply (rule_tac [!] ccontr)
```
```    81 apply (simp_all add: linorder_neq_iff, safe)
```
```    82 apply (drule_tac x = Na in spec)
```
```    83 apply (rotate_tac 3)
```
```    84 apply (drule_tac x = "Suc Na" in spec, simp)
```
```    85 apply (rotate_tac 2)
```
```    86 apply (drule_tac x = N in spec, simp)
```
```    87 apply (drule_tac x = Na in spec)
```
```    88 apply (drule_tac x = "Suc Na" and P = "%n. Na\<le>n \<longrightarrow> D n = D Na" in spec, auto)
```
```    89 done
```
```    90
```
```    91 lemma partition_rhs: "partition(a,b) D ==> (D(psize D) = b)"
```
```    92 by (simp add: partition)
```
```    93
```
```    94 lemma partition_rhs2: "[|partition(a,b) D; psize D \<le> n |] ==> (D n = b)"
```
```    95 by (simp add: partition)
```
```    96
```
```    97 lemma lemma_partition_lt_gen [rule_format]:
```
```    98  "partition(a,b) D & m + Suc d \<le> n & n \<le> (psize D) --> D(m) < D(m + Suc d)"
```
```    99 apply (induct_tac "d", auto simp add: partition)
```
```   100 apply (blast dest: Suc_le_lessD  intro: less_le_trans order_less_trans)
```
```   101 done
```
```   102
```
```   103 lemma less_eq_add_Suc: "m < n ==> \<exists>d. n = m + Suc d"
```
```   104 by (auto simp add: less_iff_Suc_add)
```
```   105
```
```   106 lemma partition_lt_gen:
```
```   107      "[|partition(a,b) D; m < n; n \<le> (psize D)|] ==> D(m) < D(n)"
```
```   108 by (auto dest: less_eq_add_Suc intro: lemma_partition_lt_gen)
```
```   109
```
```   110 lemma partition_lt: "partition(a,b) D ==> n < (psize D) ==> D(0) < D(Suc n)"
```
```   111 apply (induct "n")
```
```   112 apply (auto simp add: partition)
```
```   113 done
```
```   114
```
```   115 lemma partition_le: "partition(a,b) D ==> a \<le> b"
```
```   116 apply (frule partition [THEN iffD1], safe)
```
```   117 apply (rotate_tac 2)
```
```   118 apply (drule_tac x = "psize D" in spec, safe)
```
```   119 apply (rule ccontr)
```
```   120 apply (case_tac "psize D = 0", safe)
```
```   121 apply (drule_tac [2] n = "psize D - 1" in partition_lt, auto)
```
```   122 done
```
```   123
```
```   124 lemma partition_gt: "[|partition(a,b) D; n < (psize D)|] ==> D(n) < D(psize D)"
```
```   125 by (auto intro: partition_lt_gen)
```
```   126
```
```   127 lemma partition_eq: "partition(a,b) D ==> ((a = b) = (psize D = 0))"
```
```   128 apply (frule partition [THEN iffD1], safe)
```
```   129 apply (rotate_tac 2)
```
```   130 apply (drule_tac x = "psize D" in spec)
```
```   131 apply (rule ccontr)
```
```   132 apply (drule_tac n = "psize D - 1" in partition_lt)
```
```   133 prefer 3 apply (blast, auto)
```
```   134 done
```
```   135
```
```   136 lemma partition_lb: "partition(a,b) D ==> a \<le> D(r)"
```
```   137 apply (frule partition [THEN iffD1], safe)
```
```   138 apply (induct_tac "r")
```
```   139 apply (cut_tac [2] y = "Suc n" and x = "psize D" in linorder_le_less_linear, safe)
```
```   140  apply (blast intro: order_trans partition_le)
```
```   141 apply (drule_tac x = n in spec)
```
```   142 apply (best intro: order_less_trans order_trans order_less_imp_le)
```
```   143 done
```
```   144
```
```   145 lemma partition_lb_lt: "[| partition(a,b) D; psize D ~= 0 |] ==> a < D(Suc n)"
```
```   146 apply (rule_tac t = a in partition_lhs [THEN subst], assumption)
```
```   147 apply (cut_tac x = "Suc n" and y = "psize D" in linorder_le_less_linear)
```
```   148 apply (frule partition [THEN iffD1], safe)
```
```   149  apply (blast intro: partition_lt less_le_trans)
```
```   150 apply (rotate_tac 3)
```
```   151 apply (drule_tac x = "Suc n" in spec)
```
```   152 apply (erule impE)
```
```   153 apply (erule less_imp_le)
```
```   154 apply (frule partition_rhs)
```
```   155 apply (drule partition_gt, assumption)
```
```   156 apply (simp (no_asm_simp))
```
```   157 done
```
```   158
```
```   159 lemma partition_ub: "partition(a,b) D ==> D(r) \<le> b"
```
```   160 apply (frule partition [THEN iffD1])
```
```   161 apply (cut_tac x = "psize D" and y = r in linorder_le_less_linear, safe, blast)
```
```   162 apply (subgoal_tac "\<forall>x. D ((psize D) - x) \<le> b")
```
```   163 apply (rotate_tac 4)
```
```   164 apply (drule_tac x = "psize D - r" in spec)
```
```   165 apply (subgoal_tac "psize D - (psize D - r) = r")
```
```   166 apply simp
```
```   167 apply arith
```
```   168 apply safe
```
```   169 apply (induct_tac "x")
```
```   170 apply (simp (no_asm), blast)
```
```   171 apply (case_tac "psize D - Suc n = 0")
```
```   172 apply (erule_tac V = "\<forall>n. psize D \<le> n --> D n = b" in thin_rl)
```
```   173 apply (simp (no_asm_simp) add: partition_le)
```
```   174 apply (rule order_trans)
```
```   175  prefer 2 apply assumption
```
```   176 apply (subgoal_tac "psize D - n = Suc (psize D - Suc n)")
```
```   177  prefer 2 apply arith
```
```   178 apply (drule_tac x = "psize D - Suc n" in spec)
```
```   179 apply (erule_tac V = "\<forall>n. psize D \<le> n --> D n = b" in thin_rl, simp)
```
```   180 done
```
```   181
```
```   182 lemma partition_ub_lt: "[| partition(a,b) D; n < psize D |] ==> D(n) < b"
```
```   183 by (blast intro: partition_rhs [THEN subst] partition_gt)
```
```   184
```
```   185 lemma lemma_partition_append1:
```
```   186      "[| partition (a, b) D1; partition (b, c) D2 |]
```
```   187        ==> (\<forall>n.
```
```   188              n < psize D1 + psize D2 -->
```
```   189              (if n < psize D1 then D1 n else D2 (n - psize D1))
```
```   190              < (if Suc n < psize D1 then D1 (Suc n)
```
```   191                 else D2 (Suc n - psize D1))) &
```
```   192          (\<forall>n.
```
```   193              psize D1 + psize D2 \<le> n -->
```
```   194              (if n < psize D1 then D1 n else D2 (n - psize D1)) =
```
```   195              (if psize D1 + psize D2 < psize D1 then D1 (psize D1 + psize D2)
```
```   196               else D2 (psize D1 + psize D2 - psize D1)))"
```
```   197 apply safe
```
```   198 apply (auto intro: partition_lt_gen)
```
```   199 apply (subgoal_tac "psize D1 = Suc n")
```
```   200 apply (auto intro!: partition_lt_gen simp add: partition_lhs partition_ub_lt)
```
```   201 apply (auto intro!: partition_rhs2 simp add: partition_rhs
```
```   202             split: nat_diff_split)
```
```   203 done
```
```   204
```
```   205 lemma lemma_psize1:
```
```   206      "[| partition (a, b) D1; partition (b, c) D2; N < psize D1 |]
```
```   207       ==> D1(N) < D2 (psize D2)"
```
```   208 apply (rule_tac y = "D1 (psize D1)" in order_less_le_trans)
```
```   209 apply (erule partition_gt, assumption)
```
```   210 apply (auto simp add: partition_rhs partition_le)
```
```   211 done
```
```   212
```
```   213 lemma lemma_partition_append2:
```
```   214      "[| partition (a, b) D1; partition (b, c) D2 |]
```
```   215       ==> psize (%n. if n < psize D1 then D1 n else D2 (n - psize D1)) =
```
```   216           psize D1 + psize D2"
```
```   217 apply (rule_tac D2 = "%n. if n < psize D1 then D1 n else D2 (n - psize D1) "
```
```   218        in psize_def [THEN meta_eq_to_obj_eq, THEN ssubst])
```
```   219 apply (rule some1_equality)
```
```   220 prefer 2 apply (blast intro!: lemma_partition_append1)
```
```   221 apply (rule ex1I, rule lemma_partition_append1, auto)
```
```   222 apply (rule ccontr)
```
```   223 apply (simp add: linorder_neq_iff, safe)
```
```   224 apply (rotate_tac 3)
```
```   225 apply (drule_tac x = "psize D1 + psize D2" in spec, auto)
```
```   226 apply (case_tac "N < psize D1")
```
```   227 apply (auto dest: lemma_psize1)
```
```   228 apply (subgoal_tac "N - psize D1 < psize D2")
```
```   229  prefer 2 apply arith
```
```   230 apply (drule_tac a = b and b = c in partition_gt, auto)
```
```   231 apply (drule_tac x = "psize D1 + psize D2" in spec)
```
```   232 apply (auto simp add: partition_rhs2)
```
```   233 done
```
```   234
```
```   235 lemma tpart_eq_lhs_rhs:
```
```   236 "[|psize D = 0; tpart(a,b) (D,p)|] ==> a = b"
```
```   237 apply (simp add: tpart_def)
```
```   238 apply (auto simp add: partition_eq)
```
```   239 done
```
```   240
```
```   241 lemma tpart_partition: "tpart(a,b) (D,p) ==> partition(a,b) D"
```
```   242 by (simp add: tpart_def)
```
```   243
```
```   244 lemma partition_append:
```
```   245      "[| tpart(a,b) (D1,p1); fine(g) (D1,p1);
```
```   246          tpart(b,c) (D2,p2); fine(g) (D2,p2) |]
```
```   247        ==> \<exists>D p. tpart(a,c) (D,p) & fine(g) (D,p)"
```
```   248 apply (rule_tac x = "%n. if n < psize D1 then D1 n else D2 (n - psize D1)"
```
```   249        in exI)
```
```   250 apply (rule_tac x = "%n. if n < psize D1 then p1 n else p2 (n - psize D1)"
```
```   251        in exI)
```
```   252 apply (case_tac "psize D1 = 0")
```
```   253 apply (auto dest: tpart_eq_lhs_rhs)
```
```   254  prefer 2
```
```   255 apply (simp add: fine_def
```
```   256                  lemma_partition_append2 [OF tpart_partition tpart_partition])
```
```   257   --{*But must not expand @{term fine} in other subgoals*}
```
```   258 apply auto
```
```   259 apply (subgoal_tac "psize D1 = Suc n")
```
```   260  prefer 2 apply arith
```
```   261 apply (drule tpart_partition [THEN partition_rhs])
```
```   262 apply (drule tpart_partition [THEN partition_lhs])
```
```   263 apply (auto split: nat_diff_split)
```
```   264 apply (auto simp add: tpart_def)
```
```   265 defer 1
```
```   266  apply (subgoal_tac "psize D1 = Suc n")
```
```   267   prefer 2 apply arith
```
```   268  apply (drule partition_rhs)
```
```   269  apply (drule partition_lhs, auto)
```
```   270 apply (simp split: nat_diff_split)
```
```   271 apply (subst partition)
```
```   272 apply (subst lemma_partition_append2)
```
```   273 apply (rule_tac [3] conjI)
```
```   274 apply (drule_tac [4] lemma_partition_append1)
```
```   275 apply (auto simp add: partition_lhs partition_rhs)
```
```   276 done
```
```   277
```
```   278 text{*We can always find a division which is fine wrt any gauge*}
```
```   279
```
```   280 lemma partition_exists:
```
```   281      "[| a \<le> b; gauge(%x. a \<le> x & x \<le> b) g |]
```
```   282       ==> \<exists>D p. tpart(a,b) (D,p) & fine g (D,p)"
```
```   283 apply (cut_tac P = "%(u,v). a \<le> u & v \<le> b -->
```
```   284                    (\<exists>D p. tpart (u,v) (D,p) & fine (g) (D,p))"
```
```   285        in lemma_BOLZANO2)
```
```   286 apply safe
```
```   287 apply (blast intro: real_le_trans)+
```
```   288 apply (auto intro: partition_append)
```
```   289 apply (case_tac "a \<le> x & x \<le> b")
```
```   290 apply (rule_tac [2] x = 1 in exI, auto)
```
```   291 apply (rule_tac x = "g x" in exI)
```
```   292 apply (auto simp add: gauge_def)
```
```   293 apply (rule_tac x = "%n. if n = 0 then aa else ba" in exI)
```
```   294 apply (rule_tac x = "%n. if n = 0 then x else ba" in exI)
```
```   295 apply (auto simp add: tpart_def fine_def)
```
```   296 done
```
```   297
```
```   298 text{*Lemmas about combining gauges*}
```
```   299
```
```   300 lemma gauge_min:
```
```   301      "[| gauge(E) g1; gauge(E) g2 |]
```
```   302       ==> gauge(E) (%x. if g1(x) < g2(x) then g1(x) else g2(x))"
```
```   303 by (simp add: gauge_def)
```
```   304
```
```   305 lemma fine_min:
```
```   306       "fine (%x. if g1(x) < g2(x) then g1(x) else g2(x)) (D,p)
```
```   307        ==> fine(g1) (D,p) & fine(g2) (D,p)"
```
```   308 by (auto simp add: fine_def split: split_if_asm)
```
```   309
```
```   310
```
```   311 text{*The integral is unique if it exists*}
```
```   312
```
```   313 lemma Integral_unique:
```
```   314     "[| a \<le> b; Integral(a,b) f k1; Integral(a,b) f k2 |] ==> k1 = k2"
```
```   315 apply (simp add: Integral_def)
```
```   316 apply (drule_tac x = "\<bar>k1 - k2\<bar> /2" in spec)+
```
```   317 apply auto
```
```   318 apply (drule gauge_min, assumption)
```
```   319 apply (drule_tac g = "%x. if g x < ga x then g x else ga x"
```
```   320        in partition_exists, assumption, auto)
```
```   321 apply (drule fine_min)
```
```   322 apply (drule spec)+
```
```   323 apply auto
```
```   324 apply (subgoal_tac "\<bar>(rsum (D,p) f - k2) - (rsum (D,p) f - k1)\<bar> < \<bar>k1 - k2\<bar>")
```
```   325 apply arith
```
```   326 apply (drule add_strict_mono, assumption)
```
```   327 apply (auto simp only: left_distrib [symmetric] mult_2_right [symmetric]
```
```   328                 mult_less_cancel_right, arith)
```
```   329 done
```
```   330
```
```   331 lemma Integral_zero [simp]: "Integral(a,a) f 0"
```
```   332 apply (auto simp add: Integral_def)
```
```   333 apply (rule_tac x = "%x. 1" in exI)
```
```   334 apply (auto dest: partition_eq simp add: gauge_def tpart_def rsum_def)
```
```   335 done
```
```   336
```
```   337 lemma sumr_partition_eq_diff_bounds [simp]:
```
```   338      "sumr 0 m (%n. D (Suc n) - D n) = D(m) - D 0"
```
```   339 by (induct_tac "m", auto)
```
```   340
```
```   341 lemma Integral_eq_diff_bounds: "a \<le> b ==> Integral(a,b) (%x. 1) (b - a)"
```
```   342 apply (drule real_le_imp_less_or_eq, auto)
```
```   343 apply (auto simp add: rsum_def Integral_def)
```
```   344 apply (rule_tac x = "%x. b - a" in exI)
```
```   345 apply (auto simp add: gauge_def abs_interval_iff tpart_def partition)
```
```   346 done
```
```   347
```
```   348 lemma Integral_mult_const: "a \<le> b ==> Integral(a,b) (%x. c)  (c*(b - a))"
```
```   349 apply (drule real_le_imp_less_or_eq, auto)
```
```   350 apply (auto simp add: rsum_def Integral_def)
```
```   351 apply (rule_tac x = "%x. b - a" in exI)
```
```   352 apply (auto simp add: sumr_mult [symmetric] gauge_def abs_interval_iff
```
```   353                right_diff_distrib [symmetric] partition tpart_def)
```
```   354 done
```
```   355
```
```   356 lemma Integral_mult:
```
```   357      "[| a \<le> b; Integral(a,b) f k |] ==> Integral(a,b) (%x. c * f x) (c * k)"
```
```   358 apply (drule real_le_imp_less_or_eq)
```
```   359 apply (auto dest: Integral_unique [OF real_le_refl Integral_zero])
```
```   360 apply (auto simp add: rsum_def Integral_def sumr_mult [symmetric] real_mult_assoc)
```
```   361 apply (rule_tac a2 = c in abs_ge_zero [THEN real_le_imp_less_or_eq, THEN disjE])
```
```   362  prefer 2 apply force
```
```   363 apply (drule_tac x = "e/abs c" in spec, auto)
```
```   364 apply (simp add: zero_less_mult_iff divide_inverse)
```
```   365 apply (rule exI, auto)
```
```   366 apply (drule spec)+
```
```   367 apply auto
```
```   368 apply (rule_tac z1 = "inverse (abs c)" in real_mult_less_iff1 [THEN iffD1])
```
```   369 apply (auto simp add: divide_inverse [symmetric] right_diff_distrib [symmetric])
```
```   370 done
```
```   371
```
```   372 text{*Fundamental theorem of calculus (Part I)*}
```
```   373
```
```   374 text{*"Straddle Lemma" : Swartz and Thompson: AMM 95(7) 1988 *}
```
```   375
```
```   376 lemma choiceP: "\<forall>x. P(x) --> (\<exists>y. Q x y) ==> \<exists>f. (\<forall>x. P(x) --> Q x (f x))"
```
```   377 by meson
```
```   378
```
```   379 lemma choiceP2: "\<forall>x. P(x) --> (\<exists>y. R(y) & (\<exists>z. Q x y z)) ==>
```
```   380       \<exists>f fa. (\<forall>x. P(x) --> R(f x) & Q x (f x) (fa x))"
```
```   381 by meson
```
```   382
```
```   383 (*UNUSED
```
```   384 lemma choice2: "\<forall>x. (\<exists>y. R(y) & (\<exists>z. Q x y z)) ==>
```
```   385       \<exists>f fa. (\<forall>x. R(f x) & Q x (f x) (fa x))"
```
```   386 *)
```
```   387
```
```   388
```
```   389 (* new simplifications e.g. (y < x/n) = (y * n < x) are a real nuisance
```
```   390    they break the original proofs and make new proofs longer!*)
```
```   391 lemma strad1:
```
```   392        "\<lbrakk>\<forall>xa::real. xa \<noteq> x \<and> \<bar>xa + - x\<bar> < s \<longrightarrow>
```
```   393              \<bar>(f xa - f x) / (xa - x) + - f' x\<bar> * 2 < e;
```
```   394         0 < e; a \<le> x; x \<le> b; 0 < s\<rbrakk>
```
```   395        \<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>"
```
```   396 apply auto
```
```   397 apply (case_tac "0 < \<bar>z - x\<bar>")
```
```   398  prefer 2 apply (simp add: zero_less_abs_iff)
```
```   399 apply (drule_tac x = z in spec)
```
```   400 apply (rule_tac z1 = "\<bar>inverse (z - x)\<bar>"
```
```   401        in real_mult_le_cancel_iff2 [THEN iffD1])
```
```   402  apply simp
```
```   403 apply (simp del: abs_inverse abs_mult add: abs_mult [symmetric]
```
```   404           mult_assoc [symmetric])
```
```   405 apply (subgoal_tac "inverse (z - x) * (f z - f x - f' x * (z - x))
```
```   406                     = (f z - f x) / (z - x) - f' x")
```
```   407  apply (simp add: abs_mult [symmetric] mult_ac diff_minus)
```
```   408 apply (subst mult_commute)
```
```   409 apply (simp add: left_distrib diff_minus)
```
```   410 apply (simp add: mult_assoc divide_inverse)
```
```   411 apply (simp add: left_distrib)
```
```   412 done
```
```   413
```
```   414 lemma lemma_straddle:
```
```   415      "[| \<forall>x. a \<le> x & x \<le> b --> DERIV f x :> f'(x); 0 < e |]
```
```   416       ==> \<exists>g. gauge(%x. a \<le> x & x \<le> b) g &
```
```   417                 (\<forall>x u v. a \<le> u & u \<le> x & x \<le> v & v \<le> b & (v - u) < g(x)
```
```   418                   --> \<bar>(f(v) - f(u)) - (f'(x) * (v - u))\<bar> \<le> e * (v - u))"
```
```   419 apply (simp add: gauge_def)
```
```   420 apply (subgoal_tac "\<forall>x. a \<le> x & x \<le> b -->
```
```   421         (\<exists>d. 0 < d &
```
```   422              (\<forall>u v. u \<le> x & x \<le> v & (v - u) < d -->
```
```   423                 \<bar>(f (v) - f (u)) - (f' (x) * (v - u))\<bar> \<le> e * (v - u)))")
```
```   424 apply (drule choiceP, auto)
```
```   425 apply (drule spec, auto)
```
```   426 apply (auto simp add: DERIV_iff2 LIM_def)
```
```   427 apply (drule_tac x = "e/2" in spec, auto)
```
```   428 apply (frule strad1, assumption+)
```
```   429 apply (rule_tac x = s in exI, auto)
```
```   430 apply (rule_tac x = u and y = v in linorder_cases, auto)
```
```   431 apply (rule_tac j = "\<bar>(f (v) - f (x)) - (f' (x) * (v - x))\<bar> +
```
```   432                      \<bar>(f (x) - f (u)) - (f' (x) * (x - u))\<bar>"
```
```   433        in real_le_trans)
```
```   434 apply (rule abs_triangle_ineq [THEN [2] real_le_trans])
```
```   435 apply (simp add: right_diff_distrib, arith)
```
```   436 apply (rule_tac t = "e* (v - u)" in real_sum_of_halves [THEN subst])
```
```   437 apply (rule add_mono)
```
```   438 apply (rule_tac j = " (e / 2) * \<bar>v - x\<bar>" in real_le_trans)
```
```   439  prefer 2 apply simp apply arith
```
```   440 apply (erule_tac [!]
```
```   441        V= "\<forall>xa. xa ~= x & \<bar>xa + - x\<bar> < s --> \<bar>(f xa - f x) / (xa - x) + - f' x\<bar> * 2 < e"
```
```   442         in thin_rl)
```
```   443 apply (drule_tac x = v in spec, auto, arith)
```
```   444 apply (drule_tac x = u in spec, auto, arith)
```
```   445 apply (subgoal_tac "\<bar>f u - f x - f' x * (u - x)\<bar> = \<bar>f x - f u - f' x * (x - u)\<bar>")
```
```   446 apply (rule order_trans)
```
```   447 apply (auto simp add: abs_le_interval_iff)
```
```   448 apply (simp add: right_diff_distrib, arith)
```
```   449 done
```
```   450
```
```   451 lemma FTC1: "[|a \<le> b; \<forall>x. a \<le> x & x \<le> b --> DERIV f x :> f'(x) |]
```
```   452       ==> Integral(a,b) f' (f(b) - f(a))"
```
```   453 apply (drule real_le_imp_less_or_eq, auto)
```
```   454 apply (auto simp add: Integral_def)
```
```   455 apply (rule ccontr)
```
```   456 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))")
```
```   457 apply (rotate_tac 3)
```
```   458 apply (drule_tac x = "e/2" in spec, auto)
```
```   459 apply (drule spec, auto)
```
```   460 apply ((drule spec)+, auto)
```
```   461 apply (drule_tac e = "ea/ (b - a)" in lemma_straddle)
```
```   462 apply (auto simp add: zero_less_divide_iff)
```
```   463 apply (rule exI)
```
```   464 apply (auto simp add: tpart_def rsum_def)
```
```   465 apply (subgoal_tac "sumr 0 (psize D) (%n. f(D(Suc n)) - f(D n)) = f b - f a")
```
```   466  prefer 2
```
```   467  apply (cut_tac D = "%n. f (D n)" and m = "psize D"
```
```   468         in sumr_partition_eq_diff_bounds)
```
```   469  apply (simp add: partition_lhs partition_rhs)
```
```   470 apply (drule sym, simp)
```
```   471 apply (simp (no_asm) add: sumr_diff)
```
```   472 apply (rule sumr_rabs [THEN real_le_trans])
```
```   473 apply (subgoal_tac "ea = sumr 0 (psize D) (%n. (ea / (b - a)) * (D (Suc n) - (D n)))")
```
```   474 apply (simp add: abs_minus_commute)
```
```   475 apply (rule_tac t = ea in ssubst, assumption)
```
```   476 apply (rule sumr_le2)
```
```   477 apply (rule_tac [2] sumr_mult [THEN subst])
```
```   478 apply (auto simp add: partition_rhs partition_lhs partition_lb partition_ub
```
```   479           fine_def)
```
```   480 done
```
```   481
```
```   482
```
```   483 lemma Integral_subst: "[| Integral(a,b) f k1; k2=k1 |] ==> Integral(a,b) f k2"
```
```   484 by simp
```
```   485
```
```   486 lemma Integral_add:
```
```   487      "[| a \<le> b; b \<le> c; Integral(a,b) f' k1; Integral(b,c) f' k2;
```
```   488          \<forall>x. a \<le> x & x \<le> c --> DERIV f x :> f' x |]
```
```   489      ==> Integral(a,c) f' (k1 + k2)"
```
```   490 apply (rule FTC1 [THEN Integral_subst], auto)
```
```   491 apply (frule FTC1, auto)
```
```   492 apply (frule_tac a = b in FTC1, auto)
```
```   493 apply (drule_tac x = x in spec, auto)
```
```   494 apply (drule_tac ?k2.0 = "f b - f a" in Integral_unique)
```
```   495 apply (drule_tac [3] ?k2.0 = "f c - f b" in Integral_unique, auto)
```
```   496 done
```
```   497
```
```   498 lemma partition_psize_Least:
```
```   499      "partition(a,b) D ==> psize D = (LEAST n. D(n) = b)"
```
```   500 apply (auto intro!: Least_equality [symmetric] partition_rhs)
```
```   501 apply (rule ccontr)
```
```   502 apply (drule partition_ub_lt)
```
```   503 apply (auto simp add: linorder_not_less [symmetric])
```
```   504 done
```
```   505
```
```   506 lemma lemma_partition_bounded: "partition (a, c) D ==> ~ (\<exists>n. c < D(n))"
```
```   507 apply safe
```
```   508 apply (drule_tac r = n in partition_ub, auto)
```
```   509 done
```
```   510
```
```   511 lemma lemma_partition_eq:
```
```   512      "partition (a, c) D ==> D = (%n. if D n < c then D n else c)"
```
```   513 apply (rule ext, auto)
```
```   514 apply (auto dest!: lemma_partition_bounded)
```
```   515 apply (drule_tac x = n in spec, auto)
```
```   516 done
```
```   517
```
```   518 lemma lemma_partition_eq2:
```
```   519      "partition (a, c) D ==> D = (%n. if D n \<le> c then D n else c)"
```
```   520 apply (rule ext, auto)
```
```   521 apply (auto dest!: lemma_partition_bounded)
```
```   522 apply (drule_tac x = n in spec, auto)
```
```   523 done
```
```   524
```
```   525 lemma partition_lt_Suc:
```
```   526      "[| partition(a,b) D; n < psize D |] ==> D n < D (Suc n)"
```
```   527 by (auto simp add: partition)
```
```   528
```
```   529 lemma tpart_tag_eq: "tpart(a,c) (D,p) ==> p = (%n. if D n < c then p n else c)"
```
```   530 apply (rule ext)
```
```   531 apply (auto simp add: tpart_def)
```
```   532 apply (drule linorder_not_less [THEN iffD1])
```
```   533 apply (drule_tac r = "Suc n" in partition_ub)
```
```   534 apply (drule_tac x = n in spec, auto)
```
```   535 done
```
```   536
```
```   537 subsection{*Lemmas for Additivity Theorem of Gauge Integral*}
```
```   538
```
```   539 lemma lemma_additivity1:
```
```   540      "[| a \<le> D n; D n < b; partition(a,b) D |] ==> n < psize D"
```
```   541 by (auto simp add: partition linorder_not_less [symmetric])
```
```   542
```
```   543 lemma lemma_additivity2: "[| a \<le> D n; partition(a,D n) D |] ==> psize D \<le> n"
```
```   544 apply (rule ccontr, drule not_leE)
```
```   545 apply (frule partition [THEN iffD1], safe)
```
```   546 apply (frule_tac r = "Suc n" in partition_ub)
```
```   547 apply (auto dest!: spec)
```
```   548 done
```
```   549
```
```   550 lemma partition_eq_bound:
```
```   551      "[| partition(a,b) D; psize D < m |] ==> D(m) = D(psize D)"
```
```   552 by (auto simp add: partition)
```
```   553
```
```   554 lemma partition_ub2: "[| partition(a,b) D; psize D < m |] ==> D(r) \<le> D(m)"
```
```   555 by (simp add: partition partition_ub)
```
```   556
```
```   557 lemma tag_point_eq_partition_point:
```
```   558     "[| tpart(a,b) (D,p); psize D \<le> m |] ==> p(m) = D(m)"
```
```   559 apply (simp add: tpart_def, auto)
```
```   560 apply (drule_tac x = m in spec)
```
```   561 apply (auto simp add: partition_rhs2)
```
```   562 done
```
```   563
```
```   564 lemma partition_lt_cancel: "[| partition(a,b) D; D m < D n |] ==> m < n"
```
```   565 apply (cut_tac m = n and n = "psize D" in less_linear, auto)
```
```   566 apply (rule ccontr, drule leI, drule le_imp_less_or_eq)
```
```   567 apply (cut_tac m = m and n = "psize D" in less_linear)
```
```   568 apply (auto dest: partition_gt)
```
```   569 apply (drule_tac n = m in partition_lt_gen, auto)
```
```   570 apply (frule partition_eq_bound)
```
```   571 apply (drule_tac [2] partition_gt, auto)
```
```   572 apply (rule ccontr, drule leI, drule le_imp_less_or_eq)
```
```   573 apply (auto dest: partition_eq_bound)
```
```   574 apply (rule ccontr, drule leI, drule le_imp_less_or_eq)
```
```   575 apply (frule partition_eq_bound, assumption)
```
```   576 apply (drule_tac m = m in partition_eq_bound, auto)
```
```   577 done
```
```   578
```
```   579 lemma lemma_additivity4_psize_eq:
```
```   580      "[| a \<le> D n; D n < b; partition (a, b) D |]
```
```   581       ==> psize (%x. if D x < D n then D(x) else D n) = n"
```
```   582 apply (unfold psize_def)
```
```   583 apply (frule lemma_additivity1)
```
```   584 apply (assumption, assumption)
```
```   585 apply (rule some_equality)
```
```   586 apply (auto intro: partition_lt_Suc)
```
```   587 apply (drule_tac n = n in partition_lt_gen)
```
```   588 apply (assumption, arith, arith)
```
```   589 apply (cut_tac m = na and n = "psize D" in less_linear)
```
```   590 apply (auto dest: partition_lt_cancel)
```
```   591 apply (rule_tac x=N and y=n in linorder_cases)
```
```   592 apply (drule_tac x = n and P="%m. N \<le> m --> ?f m = ?g m" in spec, auto)
```
```   593 apply (drule_tac n = n in partition_lt_gen, auto, arith)
```
```   594 apply (drule_tac x = n in spec)
```
```   595 apply (simp split: split_if_asm)
```
```   596 done
```
```   597
```
```   598 lemma lemma_psize_left_less_psize:
```
```   599      "partition (a, b) D
```
```   600       ==> psize (%x. if D x < D n then D(x) else D n) \<le> psize D"
```
```   601 apply (frule_tac r = n in partition_ub)
```
```   602 apply (drule_tac x = "D n" in real_le_imp_less_or_eq)
```
```   603 apply (auto simp add: lemma_partition_eq [symmetric])
```
```   604 apply (frule_tac r = n in partition_lb)
```
```   605 apply (drule lemma_additivity4_psize_eq)
```
```   606 apply (rule_tac [3] ccontr, auto)
```
```   607 apply (frule_tac not_leE [THEN [2] partition_eq_bound])
```
```   608 apply (auto simp add: partition_rhs)
```
```   609 done
```
```   610
```
```   611 lemma lemma_psize_left_less_psize2:
```
```   612      "[| partition(a,b) D; na < psize (%x. if D x < D n then D(x) else D n) |]
```
```   613       ==> na < psize D"
```
```   614 apply (erule_tac lemma_psize_left_less_psize [THEN [2] less_le_trans], assumption)
```
```   615 done
```
```   616
```
```   617
```
```   618 lemma lemma_additivity3:
```
```   619      "[| partition(a,b) D; D na < D n; D n < D (Suc na);
```
```   620          n < psize D |]
```
```   621       ==> False"
```
```   622 apply (cut_tac m = n and n = "Suc na" in less_linear, auto)
```
```   623 apply (drule_tac [2] n = n in partition_lt_gen, auto)
```
```   624 apply (cut_tac m = "psize D" and n = na in less_linear)
```
```   625 apply (auto simp add: partition_rhs2 less_Suc_eq)
```
```   626 apply (drule_tac n = na in partition_lt_gen, auto)
```
```   627 done
```
```   628
```
```   629 lemma psize_const [simp]: "psize (%x. k) = 0"
```
```   630 by (simp add: psize_def, auto)
```
```   631
```
```   632 lemma lemma_additivity3a:
```
```   633      "[| partition(a,b) D; D na < D n; D n < D (Suc na);
```
```   634          na < psize D |]
```
```   635       ==> False"
```
```   636 apply (frule_tac m = n in partition_lt_cancel)
```
```   637 apply (auto intro: lemma_additivity3)
```
```   638 done
```
```   639
```
```   640 lemma better_lemma_psize_right_eq1:
```
```   641      "[| partition(a,b) D; D n < b |] ==> psize (%x. D (x + n)) \<le> psize D - n"
```
```   642 apply (simp add: psize_def [of "(%x. D (x + n))"]);
```
```   643 apply (rule_tac a = "psize D - n" in someI2, auto)
```
```   644   apply (simp add: partition less_diff_conv)
```
```   645  apply (simp add: le_diff_conv)
```
```   646  apply (case_tac "psize D \<le> n")
```
```   647   apply (simp add: partition_rhs2)
```
```   648  apply (simp add: partition linorder_not_le)
```
```   649 apply (rule ccontr, drule not_leE)
```
```   650 apply (drule_tac x = "psize D - n" in spec, auto)
```
```   651 apply (frule partition_rhs, safe)
```
```   652 apply (frule partition_lt_cancel, assumption)
```
```   653 apply (drule partition [THEN iffD1], safe)
```
```   654 apply (subgoal_tac "~ D (psize D - n + n) < D (Suc (psize D - n + n))")
```
```   655  apply blast
```
```   656 apply (drule_tac x = "Suc (psize D)" and P="%n. ?P n \<longrightarrow> D n = D (psize D)"
```
```   657        in spec)
```
```   658 apply (simp (no_asm_simp))
```
```   659 done
```
```   660
```
```   661 lemma psize_le_n: "partition (a, D n) D ==> psize D \<le> n"
```
```   662 apply (rule ccontr, drule not_leE)
```
```   663 apply (frule partition_lt_Suc, assumption)
```
```   664 apply (frule_tac r = "Suc n" in partition_ub, auto)
```
```   665 done
```
```   666
```
```   667 lemma better_lemma_psize_right_eq1a:
```
```   668      "partition(a,D n) D ==> psize (%x. D (x + n)) \<le> psize D - n"
```
```   669 apply (simp add: psize_def [of "(%x. D (x + n))"]);
```
```   670 apply (rule_tac a = "psize D - n" in someI2, auto)
```
```   671   apply (simp add: partition less_diff_conv)
```
```   672  apply (simp add: le_diff_conv)
```
```   673 apply (case_tac "psize D \<le> n")
```
```   674   apply (force intro: partition_rhs2)
```
```   675  apply (simp add: partition linorder_not_le)
```
```   676 apply (rule ccontr, drule not_leE)
```
```   677 apply (frule psize_le_n)
```
```   678 apply (drule_tac x = "psize D - n" in spec, simp)
```
```   679 apply (drule partition [THEN iffD1], safe)
```
```   680 apply (drule_tac x = "Suc n" and P="%na. psize D \<le> na \<longrightarrow> D na = D n" in spec, auto)
```
```   681 done
```
```   682
```
```   683 lemma better_lemma_psize_right_eq:
```
```   684      "partition(a,b) D ==> psize (%x. D (x + n)) \<le> psize D - n"
```
```   685 apply (frule_tac r1 = n in partition_ub [THEN real_le_imp_less_or_eq])
```
```   686 apply (blast intro: better_lemma_psize_right_eq1a better_lemma_psize_right_eq1)
```
```   687 done
```
```   688
```
```   689 lemma lemma_psize_right_eq1:
```
```   690      "[| partition(a,b) D; D n < b |] ==> psize (%x. D (x + n)) \<le> psize D"
```
```   691 apply (simp add: psize_def [of "(%x. D (x + n))"]);
```
```   692 apply (rule_tac a = "psize D - n" in someI2, auto)
```
```   693   apply (simp add: partition less_diff_conv)
```
```   694  apply (subgoal_tac "n \<le> psize D")
```
```   695   apply (simp add: partition le_diff_conv)
```
```   696  apply (rule ccontr, drule not_leE)
```
```   697  apply (drule_tac less_imp_le [THEN [2] partition_rhs2], auto)
```
```   698 apply (rule ccontr, drule not_leE)
```
```   699 apply (drule_tac x = "psize D" in spec)
```
```   700 apply (simp add: partition)
```
```   701 done
```
```   702
```
```   703 (* should be combined with previous theorem; also proof has redundancy *)
```
```   704 lemma lemma_psize_right_eq1a:
```
```   705      "partition(a,D n) D ==> psize (%x. D (x + n)) \<le> psize D"
```
```   706 apply (simp add: psize_def [of "(%x. D (x + n))"]);
```
```   707 apply (rule_tac a = "psize D - n" in someI2, auto)
```
```   708   apply (simp add: partition less_diff_conv)
```
```   709  apply (case_tac "psize D \<le> n")
```
```   710   apply (force intro: partition_rhs2 simp add: le_diff_conv)
```
```   711  apply (simp add: partition le_diff_conv)
```
```   712 apply (rule ccontr, drule not_leE)
```
```   713 apply (drule_tac x = "psize D" in spec)
```
```   714 apply (simp add: partition)
```
```   715 done
```
```   716
```
```   717 lemma lemma_psize_right_eq:
```
```   718      "[| partition(a,b) D |] ==> psize (%x. D (x + n)) \<le> psize D"
```
```   719 apply (frule_tac r1 = n in partition_ub [THEN real_le_imp_less_or_eq])
```
```   720 apply (blast intro: lemma_psize_right_eq1a lemma_psize_right_eq1)
```
```   721 done
```
```   722
```
```   723 lemma tpart_left1:
```
```   724      "[| a \<le> D n; tpart (a, b) (D, p) |]
```
```   725       ==> tpart(a, D n) (%x. if D x < D n then D(x) else D n,
```
```   726           %x. if D x < D n then p(x) else D n)"
```
```   727 apply (frule_tac r = n in tpart_partition [THEN partition_ub])
```
```   728 apply (drule_tac x = "D n" in real_le_imp_less_or_eq)
```
```   729 apply (auto simp add: tpart_partition [THEN lemma_partition_eq, symmetric] tpart_tag_eq [symmetric])
```
```   730 apply (frule_tac tpart_partition [THEN [3] lemma_additivity1])
```
```   731 apply (auto simp add: tpart_def)
```
```   732 apply (drule_tac [2] linorder_not_less [THEN iffD1, THEN real_le_imp_less_or_eq], auto)
```
```   733   prefer 3
```
```   734   apply (drule linorder_not_less [THEN iffD1])
```
```   735   apply (drule_tac x=na in spec, arith)
```
```   736  prefer 2 apply (blast dest: lemma_additivity3)
```
```   737 apply (frule lemma_additivity4_psize_eq)
```
```   738 apply (assumption+)
```
```   739 apply (rule partition [THEN iffD2])
```
```   740 apply (frule partition [THEN iffD1])
```
```   741 apply (auto intro: partition_lt_gen)
```
```   742 apply (drule_tac n = n in partition_lt_gen)
```
```   743 apply (assumption, arith, blast)
```
```   744 apply (drule partition_lt_cancel, auto)
```
```   745 done
```
```   746
```
```   747 lemma fine_left1:
```
```   748      "[| a \<le> D n; tpart (a, b) (D, p); gauge (%x. a \<le> x & x \<le> D n) g;
```
```   749          fine (%x. if x < D n then min (g x) ((D n - x)/ 2)
```
```   750                  else if x = D n then min (g (D n)) (ga (D n))
```
```   751                       else min (ga x) ((x - D n)/ 2)) (D, p) |]
```
```   752       ==> fine g
```
```   753            (%x. if D x < D n then D(x) else D n,
```
```   754             %x. if D x < D n then p(x) else D n)"
```
```   755 apply (auto simp add: fine_def tpart_def gauge_def)
```
```   756 apply (frule_tac [!] na=na in lemma_psize_left_less_psize2)
```
```   757 apply (drule_tac [!] x = na in spec, auto)
```
```   758 apply (drule_tac [!] x = na in spec, auto)
```
```   759 apply (auto dest: lemma_additivity3a simp add: split_if_asm)
```
```   760 done
```
```   761
```
```   762 lemma tpart_right1:
```
```   763      "[| a \<le> D n; tpart (a, b) (D, p) |]
```
```   764       ==> tpart(D n, b) (%x. D(x + n),%x. p(x + n))"
```
```   765 apply (simp add: tpart_def partition_def, safe)
```
```   766 apply (rule_tac x = "N - n" in exI, auto)
```
```   767 apply (rotate_tac 2)
```
```   768 apply (drule_tac x = "na + n" in spec)
```
```   769 apply (rotate_tac [2] 3)
```
```   770 apply (drule_tac [2] x = "na + n" in spec, arith+)
```
```   771 done
```
```   772
```
```   773 lemma fine_right1:
```
```   774      "[| a \<le> D n; tpart (a, b) (D, p); gauge (%x. D n \<le> x & x \<le> b) ga;
```
```   775          fine (%x. if x < D n then min (g x) ((D n - x)/ 2)
```
```   776                  else if x = D n then min (g (D n)) (ga (D n))
```
```   777                       else min (ga x) ((x - D n)/ 2)) (D, p) |]
```
```   778       ==> fine ga (%x. D(x + n),%x. p(x + n))"
```
```   779 apply (auto simp add: fine_def gauge_def)
```
```   780 apply (drule_tac x = "na + n" in spec)
```
```   781 apply (frule_tac n = n in tpart_partition [THEN better_lemma_psize_right_eq], auto, arith)
```
```   782 apply (simp add: tpart_def, safe)
```
```   783 apply (subgoal_tac "D n \<le> p (na + n)")
```
```   784 apply (drule_tac y = "p (na + n)" in real_le_imp_less_or_eq)
```
```   785 apply safe
```
```   786 apply (simp split: split_if_asm, simp)
```
```   787 apply (drule less_le_trans, assumption)
```
```   788 apply (rotate_tac 5)
```
```   789 apply (drule_tac x = "na + n" in spec, safe)
```
```   790 apply (rule_tac y="D (na + n)" in order_trans)
```
```   791 apply (case_tac "na = 0", auto)
```
```   792 apply (erule partition_lt_gen [THEN order_less_imp_le], arith+)
```
```   793 done
```
```   794
```
```   795 lemma rsum_add: "rsum (D, p) (%x. f x + g x) =  rsum (D, p) f + rsum(D, p) g"
```
```   796 by (simp add: rsum_def sumr_add left_distrib)
```
```   797
```
```   798 text{* Bartle/Sherbert: Theorem 10.1.5 p. 278 *}
```
```   799 lemma Integral_add_fun:
```
```   800     "[| a \<le> b; Integral(a,b) f k1; Integral(a,b) g k2 |]
```
```   801      ==> Integral(a,b) (%x. f x + g x) (k1 + k2)"
```
```   802 apply (simp add: Integral_def, auto)
```
```   803 apply ((drule_tac x = "e/2" in spec)+)
```
```   804 apply auto
```
```   805 apply (drule gauge_min, assumption)
```
```   806 apply (rule_tac x = " (%x. if ga x < gaa x then ga x else gaa x)" in exI)
```
```   807 apply auto
```
```   808 apply (drule fine_min)
```
```   809 apply ((drule spec)+, auto)
```
```   810 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)
```
```   811 apply (auto simp only: rsum_add left_distrib [symmetric]
```
```   812                 mult_2_right [symmetric] real_mult_less_iff1, arith)
```
```   813 done
```
```   814
```
```   815 lemma partition_lt_gen2:
```
```   816      "[| partition(a,b) D; r < psize D |] ==> 0 < D (Suc r) - D r"
```
```   817 by (auto simp add: partition)
```
```   818
```
```   819 lemma lemma_Integral_le:
```
```   820      "[| \<forall>x. a \<le> x & x \<le> b --> f x \<le> g x;
```
```   821          tpart(a,b) (D,p)
```
```   822       |] ==> \<forall>n. n \<le> psize D --> f (p n) \<le> g (p n)"
```
```   823 apply (simp add: tpart_def)
```
```   824 apply (auto, frule partition [THEN iffD1], auto)
```
```   825 apply (drule_tac x = "p n" in spec, auto)
```
```   826 apply (case_tac "n = 0", simp)
```
```   827 apply (rule partition_lt_gen [THEN order_less_le_trans, THEN order_less_imp_le], auto)
```
```   828 apply (drule le_imp_less_or_eq, auto)
```
```   829 apply (drule_tac [2] x = "psize D" in spec, auto)
```
```   830 apply (drule_tac r = "Suc n" in partition_ub)
```
```   831 apply (drule_tac x = n in spec, auto)
```
```   832 done
```
```   833
```
```   834 lemma lemma_Integral_rsum_le:
```
```   835      "[| \<forall>x. a \<le> x & x \<le> b --> f x \<le> g x;
```
```   836          tpart(a,b) (D,p)
```
```   837       |] ==> rsum(D,p) f \<le> rsum(D,p) g"
```
```   838 apply (simp add: rsum_def)
```
```   839 apply (auto intro!: sumr_le2 dest: tpart_partition [THEN partition_lt_gen2]
```
```   840                dest!: lemma_Integral_le)
```
```   841 done
```
```   842
```
```   843 lemma Integral_le:
```
```   844     "[| a \<le> b;
```
```   845         \<forall>x. a \<le> x & x \<le> b --> f(x) \<le> g(x);
```
```   846         Integral(a,b) f k1; Integral(a,b) g k2
```
```   847      |] ==> k1 \<le> k2"
```
```   848 apply (simp add: Integral_def)
```
```   849 apply (rotate_tac 2)
```
```   850 apply (drule_tac x = "\<bar>k1 - k2\<bar> /2" in spec)
```
```   851 apply (drule_tac x = "\<bar>k1 - k2\<bar> /2" in spec)
```
```   852 apply auto
```
```   853 apply (drule gauge_min, assumption)
```
```   854 apply (drule_tac g = "%x. if ga x < gaa x then ga x else gaa x"
```
```   855        in partition_exists, assumption, auto)
```
```   856 apply (drule fine_min)
```
```   857 apply (drule_tac x = D in spec, drule_tac x = D in spec)
```
```   858 apply (drule_tac x = p in spec, drule_tac x = p in spec, auto)
```
```   859 apply (frule lemma_Integral_rsum_le, assumption)
```
```   860 apply (subgoal_tac "\<bar>(rsum (D,p) f - k1) - (rsum (D,p) g - k2)\<bar> < \<bar>k1 - k2\<bar>")
```
```   861 apply arith
```
```   862 apply (drule add_strict_mono, assumption)
```
```   863 apply (auto simp only: left_distrib [symmetric] mult_2_right [symmetric]
```
```   864                        real_mult_less_iff1, arith)
```
```   865 done
```
```   866
```
```   867 lemma Integral_imp_Cauchy:
```
```   868      "(\<exists>k. Integral(a,b) f k) ==>
```
```   869       (\<forall>e. 0 < e -->
```
```   870                (\<exists>g. gauge (%x. a \<le> x & x \<le> b) g &
```
```   871                        (\<forall>D1 D2 p1 p2.
```
```   872                             tpart(a,b) (D1, p1) & fine g (D1,p1) &
```
```   873                             tpart(a,b) (D2, p2) & fine g (D2,p2) -->
```
```   874                             \<bar>rsum(D1,p1) f - rsum(D2,p2) f\<bar> < e)))"
```
```   875 apply (simp add: Integral_def, auto)
```
```   876 apply (drule_tac x = "e/2" in spec, auto)
```
```   877 apply (rule exI, auto)
```
```   878 apply (frule_tac x = D1 in spec)
```
```   879 apply (frule_tac x = D2 in spec)
```
```   880 apply ((drule spec)+, auto)
```
```   881 apply (erule_tac V = "0 < e" in thin_rl)
```
```   882 apply (drule add_strict_mono, assumption)
```
```   883 apply (auto simp only: left_distrib [symmetric] mult_2_right [symmetric]
```
```   884                        real_mult_less_iff1, arith)
```
```   885 done
```
```   886
```
```   887 lemma Cauchy_iff2:
```
```   888      "Cauchy X =
```
```   889       (\<forall>j. (\<exists>M. \<forall>m n. M \<le> m & M \<le> n -->
```
```   890                \<bar>X m + - X n\<bar> < inverse(real (Suc j))))"
```
```   891 apply (simp add: Cauchy_def, auto)
```
```   892 apply (drule reals_Archimedean, safe)
```
```   893 apply (drule_tac x = n in spec, auto)
```
```   894 apply (rule_tac x = M in exI, auto)
```
```   895 apply (drule_tac x = m in spec)
```
```   896 apply (drule_tac x = na in spec, auto)
```
```   897 done
```
```   898
```
```   899 lemma partition_exists2:
```
```   900      "[| a \<le> b; \<forall>n. gauge (%x. a \<le> x & x \<le> b) (fa n) |]
```
```   901       ==> \<forall>n. \<exists>D p. tpart (a, b) (D, p) & fine (fa n) (D, p)"
```
```   902 apply safe
```
```   903 apply (rule partition_exists, auto)
```
```   904 done
```
```   905
```
```   906 lemma monotonic_anti_derivative:
```
```   907      "[| a \<le> b; \<forall>c. a \<le> c & c \<le> b --> f' c \<le> g' c;
```
```   908          \<forall>x. DERIV f x :> f' x; \<forall>x. DERIV g x :> g' x |]
```
```   909       ==> f b - f a \<le> g b - g a"
```
```   910 apply (rule Integral_le, assumption)
```
```   911 apply (rule_tac [2] FTC1)
```
```   912 apply (rule_tac [4] FTC1, auto)
```
```   913 done
```
```   914
```
```   915 end
```