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