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