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