src/HOL/Multivariate_Analysis/Integration.thy
author wenzelm
Thu Jan 17 15:17:48 2013 +0100 (2013-01-17)
changeset 50945 917e76c53f82
parent 50919 cc03437a1f80
child 51348 011c97ba3b3d
permissions -rw-r--r--
tuned proofs;
hoelzl@37489
     1
header {* Kurzweil-Henstock Gauge Integration in many dimensions. *}
himmelma@35172
     2
(*  Author:                     John Harrison
himmelma@35172
     3
    Translation from HOL light: Robert Himmelmann, TU Muenchen *)
himmelma@35172
     4
hoelzl@35292
     5
theory Integration
wenzelm@41413
     6
imports
wenzelm@41413
     7
  Derivative
wenzelm@41413
     8
  "~~/src/HOL/Library/Indicator_Function"
himmelma@35172
     9
begin
himmelma@35172
    10
hoelzl@37489
    11
(*declare not_less[simp] not_le[simp]*)
hoelzl@37489
    12
hoelzl@37489
    13
lemmas scaleR_simps = scaleR_zero_left scaleR_minus_left scaleR_left_diff_distrib
hoelzl@37489
    14
  scaleR_zero_right scaleR_minus_right scaleR_right_diff_distrib scaleR_eq_0_iff
huffman@44282
    15
  scaleR_cancel_left scaleR_cancel_right scaleR_add_right scaleR_add_left real_vector_class.scaleR_one
hoelzl@37489
    16
hoelzl@37489
    17
lemma real_arch_invD:
hoelzl@37489
    18
  "0 < (e::real) \<Longrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)"
wenzelm@49675
    19
  by (subst(asm) real_arch_inv)
wenzelm@49675
    20
wenzelm@49675
    21
himmelma@36243
    22
subsection {* Sundries *}
himmelma@36243
    23
himmelma@35172
    24
lemma conjunctD2: assumes "a \<and> b" shows a b using assms by auto
himmelma@35172
    25
lemma conjunctD3: assumes "a \<and> b \<and> c" shows a b c using assms by auto
himmelma@35172
    26
lemma conjunctD4: assumes "a \<and> b \<and> c \<and> d" shows a b c d using assms by auto
himmelma@35172
    27
lemma conjunctD5: assumes "a \<and> b \<and> c \<and> d \<and> e" shows a b c d e using assms by auto
himmelma@35172
    28
hoelzl@37489
    29
declare norm_triangle_ineq4[intro] 
himmelma@35172
    30
himmelma@36243
    31
lemma simple_image: "{f x |x . x \<in> s} = f ` s" by blast
himmelma@36243
    32
wenzelm@49970
    33
lemma linear_simps:
wenzelm@49970
    34
  assumes "bounded_linear f"
wenzelm@49970
    35
  shows
wenzelm@49970
    36
    "f (a + b) = f a + f b"
wenzelm@49970
    37
    "f (a - b) = f a - f b"
wenzelm@49970
    38
    "f 0 = 0"
wenzelm@49970
    39
    "f (- a) = - f a"
wenzelm@49970
    40
    "f (s *\<^sub>R v) = s *\<^sub>R (f v)"
wenzelm@49970
    41
  apply (rule_tac[!] additive.add additive.minus additive.diff additive.zero bounded_linear.scaleR)
wenzelm@49675
    42
  using assms unfolding bounded_linear_def additive_def
wenzelm@49675
    43
  apply auto
wenzelm@49675
    44
  done
wenzelm@49675
    45
wenzelm@49675
    46
lemma bounded_linearI:
wenzelm@49675
    47
  assumes "\<And>x y. f (x + y) = f x + f y"
wenzelm@49675
    48
    and "\<And>r x. f (r *\<^sub>R x) = r *\<^sub>R f x" "\<And>x. norm (f x) \<le> norm x * K"
himmelma@36243
    49
  shows "bounded_linear f"
himmelma@36243
    50
  unfolding bounded_linear_def additive_def bounded_linear_axioms_def using assms by auto
himmelma@36243
    51
 
himmelma@36243
    52
lemma real_le_inf_subset:
wenzelm@49675
    53
  assumes "t \<noteq> {}" "t \<subseteq> s" "\<exists>b. b <=* s"
wenzelm@49675
    54
  shows "Inf s <= Inf (t::real set)"
wenzelm@49675
    55
  apply (rule isGlb_le_isLb)
wenzelm@49675
    56
  apply (rule Inf[OF assms(1)])
wenzelm@49970
    57
  apply (insert assms)
wenzelm@49675
    58
  apply (erule exE)
wenzelm@49970
    59
  apply (rule_tac x = b in exI)
wenzelm@49970
    60
  apply (auto simp: isLb_def setge_def)
wenzelm@49675
    61
  done
himmelma@36243
    62
himmelma@36243
    63
lemma real_ge_sup_subset:
wenzelm@49675
    64
  assumes "t \<noteq> {}" "t \<subseteq> s" "\<exists>b. s *<= b"
wenzelm@49675
    65
  shows "Sup s >= Sup (t::real set)"
wenzelm@49675
    66
  apply (rule isLub_le_isUb)
wenzelm@49675
    67
  apply (rule Sup[OF assms(1)])
wenzelm@49970
    68
  apply (insert assms)
wenzelm@49675
    69
  apply (erule exE)
wenzelm@49970
    70
  apply (rule_tac x = b in exI)
wenzelm@49970
    71
  apply (auto simp: isUb_def setle_def)
wenzelm@49675
    72
  done
himmelma@36243
    73
hoelzl@50526
    74
lemma bounded_linear_component [intro]: "bounded_linear (\<lambda>x::'a::euclidean_space. x \<bullet> k)"
hoelzl@50526
    75
  by (rule bounded_linear_inner_left)
himmelma@36243
    76
himmelma@36243
    77
lemma transitive_stepwise_lt_eq:
himmelma@36243
    78
  assumes "(\<And>x y z::nat. R x y \<Longrightarrow> R y z \<Longrightarrow> R x z)"
himmelma@36243
    79
  shows "((\<forall>m. \<forall>n>m. R m n) \<longleftrightarrow> (\<forall>n. R n (Suc n)))" (is "?l = ?r")
wenzelm@49675
    80
proof (safe)
wenzelm@49675
    81
  assume ?r
wenzelm@49675
    82
  fix n m :: nat
wenzelm@49675
    83
  assume "m < n"
wenzelm@49675
    84
  then show "R m n"
wenzelm@49675
    85
  proof (induct n arbitrary: m)
wenzelm@49675
    86
    case (Suc n)
wenzelm@49675
    87
    show ?case 
wenzelm@49675
    88
    proof (cases "m < n")
wenzelm@49675
    89
      case True
wenzelm@49675
    90
      show ?thesis
wenzelm@49675
    91
        apply (rule assms[OF Suc(1)[OF True]])
wenzelm@50945
    92
        using `?r`
wenzelm@50945
    93
        apply auto
wenzelm@49675
    94
        done
wenzelm@49675
    95
    next
wenzelm@49675
    96
      case False
wenzelm@49970
    97
      then have "m = n" using Suc(2) by auto
wenzelm@49970
    98
      then show ?thesis using `?r` by auto
wenzelm@49675
    99
    qed
wenzelm@49675
   100
  qed auto
wenzelm@49675
   101
qed auto
himmelma@36243
   102
himmelma@36243
   103
lemma transitive_stepwise_gt:
himmelma@36243
   104
  assumes "\<And>x y z. R x y \<Longrightarrow> R y z \<Longrightarrow> R x z" "\<And>n. R n (Suc n) "
himmelma@36243
   105
  shows "\<forall>n>m. R m n"
wenzelm@49675
   106
proof -
wenzelm@49675
   107
  have "\<forall>m. \<forall>n>m. R m n"
wenzelm@49675
   108
    apply (subst transitive_stepwise_lt_eq)
wenzelm@49675
   109
    apply (rule assms)
wenzelm@49675
   110
    apply assumption
wenzelm@49675
   111
    apply assumption
wenzelm@49675
   112
    using assms(2) apply auto
wenzelm@49675
   113
    done
wenzelm@49970
   114
  then show ?thesis by auto
wenzelm@49675
   115
qed
himmelma@36243
   116
himmelma@36243
   117
lemma transitive_stepwise_le_eq:
himmelma@36243
   118
  assumes "\<And>x. R x x" "\<And>x y z. R x y \<Longrightarrow> R y z \<Longrightarrow> R x z"
himmelma@36243
   119
  shows "(\<forall>m. \<forall>n\<ge>m. R m n) \<longleftrightarrow> (\<forall>n. R n (Suc n))" (is "?l = ?r")
wenzelm@49675
   120
proof safe
wenzelm@49675
   121
  assume ?r
wenzelm@49675
   122
  fix m n :: nat
wenzelm@49675
   123
  assume "m \<le> n"
wenzelm@49675
   124
  thus "R m n"
wenzelm@49675
   125
  proof (induct n arbitrary: m)
wenzelm@49970
   126
    case 0
wenzelm@49970
   127
    with assms show ?case by auto
wenzelm@49970
   128
  next
wenzelm@49675
   129
    case (Suc n)
wenzelm@49675
   130
    show ?case
wenzelm@49675
   131
    proof (cases "m \<le> n")
wenzelm@49675
   132
      case True
wenzelm@49675
   133
      show ?thesis
wenzelm@49675
   134
        apply (rule assms(2))
wenzelm@49675
   135
        apply (rule Suc(1)[OF True])
wenzelm@49675
   136
        using `?r` apply auto
wenzelm@49675
   137
        done
wenzelm@49675
   138
    next
wenzelm@49675
   139
      case False
wenzelm@49675
   140
      hence "m = Suc n" using Suc(2) by auto
himmelma@36243
   141
      thus ?thesis using assms(1) by auto
wenzelm@49675
   142
    qed
wenzelm@49970
   143
  qed
wenzelm@49675
   144
qed auto
himmelma@36243
   145
himmelma@36243
   146
lemma transitive_stepwise_le:
himmelma@36243
   147
  assumes "\<And>x. R x x" "\<And>x y z. R x y \<Longrightarrow> R y z \<Longrightarrow> R x z" "\<And>n. R n (Suc n) "
himmelma@36243
   148
  shows "\<forall>n\<ge>m. R m n"
wenzelm@49675
   149
proof -
wenzelm@49675
   150
  have "\<forall>m. \<forall>n\<ge>m. R m n"
wenzelm@49675
   151
    apply (subst transitive_stepwise_le_eq)
wenzelm@49675
   152
    apply (rule assms)
wenzelm@49675
   153
    apply (rule assms,assumption,assumption)
wenzelm@49675
   154
    using assms(3) apply auto
wenzelm@49675
   155
    done
wenzelm@49970
   156
  then show ?thesis by auto
wenzelm@49675
   157
qed
wenzelm@49675
   158
himmelma@36243
   159
himmelma@35172
   160
subsection {* Some useful lemmas about intervals. *}
himmelma@35172
   161
hoelzl@50526
   162
abbreviation One where "One \<equiv> ((\<Sum>Basis)::_::euclidean_space)"
hoelzl@50526
   163
hoelzl@50526
   164
lemma empty_as_interval: "{} = {One..(0::'a::ordered_euclidean_space)}"
hoelzl@50526
   165
  by (auto simp: set_eq_iff eucl_le[where 'a='a] intro!: bexI[OF _ SOME_Basis])
himmelma@35172
   166
himmelma@35172
   167
lemma interior_subset_union_intervals: 
wenzelm@49675
   168
  assumes "i = {a..b::'a::ordered_euclidean_space}" "j = {c..d}"
wenzelm@49675
   169
    "interior j \<noteq> {}" "i \<subseteq> j \<union> s" "interior(i) \<inter> interior(j) = {}"
wenzelm@49675
   170
  shows "interior i \<subseteq> interior s"
wenzelm@49675
   171
proof -
wenzelm@49675
   172
  have "{a<..<b} \<inter> {c..d} = {}"
wenzelm@49675
   173
    using inter_interval_mixed_eq_empty[of c d a b] and assms(3,5)
himmelma@35172
   174
    unfolding assms(1,2) interior_closed_interval by auto
wenzelm@49675
   175
  moreover
wenzelm@49970
   176
  have "{a<..<b} \<subseteq> {c..d} \<union> s"
wenzelm@49970
   177
    apply (rule order_trans,rule interval_open_subset_closed)
wenzelm@49970
   178
    using assms(4) unfolding assms(1,2)
wenzelm@49970
   179
    apply auto
wenzelm@49970
   180
    done
wenzelm@49675
   181
  ultimately
wenzelm@49675
   182
  show ?thesis
wenzelm@49675
   183
    apply -
wenzelm@49970
   184
    apply (rule interior_maximal)
wenzelm@49970
   185
    defer
wenzelm@49675
   186
    apply (rule open_interior)
wenzelm@49970
   187
    unfolding assms(1,2) interior_closed_interval
wenzelm@49970
   188
    apply auto
wenzelm@49675
   189
    done
wenzelm@49675
   190
qed
wenzelm@49675
   191
wenzelm@49675
   192
lemma inter_interior_unions_intervals:
wenzelm@49675
   193
  fixes f::"('a::ordered_euclidean_space) set set"
himmelma@35172
   194
  assumes "finite f" "open s" "\<forall>t\<in>f. \<exists>a b. t = {a..b}" "\<forall>t\<in>f. s \<inter> (interior t) = {}"
wenzelm@49675
   195
  shows "s \<inter> interior(\<Union>f) = {}"
wenzelm@49970
   196
proof (rule ccontr, unfold ex_in_conv[THEN sym])
wenzelm@49970
   197
  case goal1
wenzelm@49970
   198
  have lem1: "\<And>x e s U. ball x e \<subseteq> s \<inter> interior U \<longleftrightarrow> ball x e \<subseteq> s \<inter> U"
wenzelm@49970
   199
    apply rule
wenzelm@49970
   200
    defer
wenzelm@49970
   201
    apply (rule_tac Int_greatest)
wenzelm@49970
   202
    unfolding open_subset_interior[OF open_ball]
wenzelm@49970
   203
    using interior_subset
wenzelm@49970
   204
    apply auto
wenzelm@49970
   205
    done
wenzelm@49970
   206
  have lem2: "\<And>x s P. \<exists>x\<in>s. P x \<Longrightarrow> \<exists>x\<in>insert x s. P x" by auto
wenzelm@49970
   207
  have "\<And>f. finite f \<Longrightarrow> (\<forall>t\<in>f. \<exists>a b. t = {a..b}) \<Longrightarrow>
wenzelm@49970
   208
    (\<exists>x. x \<in> s \<inter> interior (\<Union>f)) \<Longrightarrow> (\<exists>t\<in>f. \<exists>x. \<exists>e>0. ball x e \<subseteq> s \<inter> t)"
wenzelm@49970
   209
  proof -
wenzelm@49970
   210
    case goal1
wenzelm@49970
   211
    then show ?case
wenzelm@49970
   212
    proof (induct rule: finite_induct)
wenzelm@49970
   213
      case empty from this(2) guess x ..
wenzelm@49970
   214
      hence False unfolding Union_empty interior_empty by auto
wenzelm@49970
   215
      thus ?case by auto
wenzelm@49970
   216
    next
wenzelm@49970
   217
      case (insert i f) guess x using insert(5) .. note x = this
wenzelm@49970
   218
      then guess e unfolding open_contains_ball_eq[OF open_Int[OF assms(2) open_interior],rule_format] .. note e=this
wenzelm@49970
   219
      guess a using insert(4)[rule_format,OF insertI1] ..
wenzelm@49970
   220
      then guess b .. note ab = this
wenzelm@49970
   221
      show ?case
wenzelm@49970
   222
      proof (cases "x\<in>i")
wenzelm@49970
   223
        case False
wenzelm@49970
   224
        hence "x \<in> UNIV - {a..b}" unfolding ab by auto
wenzelm@49970
   225
        then guess d unfolding open_contains_ball_eq[OF open_Diff[OF open_UNIV closed_interval],rule_format] ..
wenzelm@49970
   226
        hence "0 < d" "ball x (min d e) \<subseteq> UNIV - i" unfolding ab ball_min_Int by auto
wenzelm@49970
   227
        hence "ball x (min d e) \<subseteq> s \<inter> interior (\<Union>f)"
wenzelm@49970
   228
          using e unfolding lem1 unfolding  ball_min_Int by auto
wenzelm@49970
   229
        hence "x \<in> s \<inter> interior (\<Union>f)" using `d>0` e by auto
wenzelm@49970
   230
        hence "\<exists>t\<in>f. \<exists>x e. 0 < e \<and> ball x e \<subseteq> s \<inter> t"
wenzelm@49970
   231
          apply -
wenzelm@49970
   232
          apply (rule insert(3))
wenzelm@49970
   233
          using insert(4)
wenzelm@49970
   234
          apply auto
wenzelm@49970
   235
          done
wenzelm@49970
   236
        thus ?thesis by auto
wenzelm@49970
   237
      next
wenzelm@49970
   238
        case True show ?thesis
wenzelm@49970
   239
        proof (cases "x\<in>{a<..<b}")
wenzelm@49970
   240
          case True
wenzelm@49970
   241
          then guess d unfolding open_contains_ball_eq[OF open_interval,rule_format] ..
wenzelm@49970
   242
          thus ?thesis
wenzelm@49970
   243
            apply (rule_tac x=i in bexI, rule_tac x=x in exI, rule_tac x="min d e" in exI)
wenzelm@49970
   244
            unfolding ab
wenzelm@50945
   245
            using interval_open_subset_closed[of a b] and e
wenzelm@50945
   246
            apply fastforce+
wenzelm@49970
   247
            done
wenzelm@49970
   248
        next
wenzelm@49970
   249
          case False
hoelzl@50526
   250
          then obtain k where "x\<bullet>k \<le> a\<bullet>k \<or> x\<bullet>k \<ge> b\<bullet>k" and k:"k\<in>Basis"
wenzelm@49970
   251
            unfolding mem_interval by (auto simp add: not_less)
hoelzl@50526
   252
          hence "x\<bullet>k = a\<bullet>k \<or> x\<bullet>k = b\<bullet>k"
wenzelm@49970
   253
            using True unfolding ab and mem_interval
hoelzl@50526
   254
              apply (erule_tac x = k in ballE)
wenzelm@49970
   255
              apply auto
wenzelm@49970
   256
              done
wenzelm@49970
   257
          hence "\<exists>x. ball x (e/2) \<subseteq> s \<inter> (\<Union>f)"
wenzelm@49970
   258
          proof (erule_tac disjE)
hoelzl@50526
   259
            let ?z = "x - (e/2) *\<^sub>R k"
hoelzl@50526
   260
            assume as: "x\<bullet>k = a\<bullet>k"
wenzelm@49970
   261
            have "ball ?z (e / 2) \<inter> i = {}"
wenzelm@49970
   262
              apply (rule ccontr)
wenzelm@49970
   263
              unfolding ex_in_conv[THEN sym]
wenzelm@49970
   264
            proof (erule exE)
wenzelm@49970
   265
              fix y
wenzelm@49970
   266
              assume "y \<in> ball ?z (e / 2) \<inter> i"
wenzelm@49970
   267
              hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
hoelzl@50526
   268
              hence "\<bar>(?z - y) \<bullet> k\<bar> < e/2"
hoelzl@50526
   269
                using Basis_le_norm[OF k, of "?z - y"] unfolding dist_norm by auto
hoelzl@50526
   270
              hence "y\<bullet>k < a\<bullet>k"
hoelzl@50526
   271
                using e[THEN conjunct1] k by (auto simp add: field_simps as inner_Basis inner_simps)
wenzelm@49970
   272
              hence "y \<notin> i"
hoelzl@50526
   273
                unfolding ab mem_interval by (auto intro!: bexI[OF _ k])
wenzelm@49970
   274
              thus False using yi by auto
wenzelm@49970
   275
            qed
wenzelm@49970
   276
            moreover
wenzelm@49970
   277
            have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)"
wenzelm@49970
   278
              apply(rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]])
wenzelm@49970
   279
            proof
wenzelm@49970
   280
              fix y
wenzelm@49970
   281
              assume as: "y\<in> ball ?z (e/2)"
hoelzl@50526
   282
              have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y - (e / 2) *\<^sub>R k)"
wenzelm@49970
   283
                apply -
hoelzl@50526
   284
                apply (rule order_trans,rule norm_triangle_sub[of "x - y" "(e/2) *\<^sub>R k"])
hoelzl@50526
   285
                unfolding norm_scaleR norm_Basis[OF k]
wenzelm@49970
   286
                apply auto
wenzelm@49970
   287
                done
wenzelm@49970
   288
              also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2"
wenzelm@49970
   289
                apply (rule add_strict_left_mono)
wenzelm@50945
   290
                using as
wenzelm@50945
   291
                unfolding mem_ball dist_norm
wenzelm@50945
   292
                using e
wenzelm@50945
   293
                apply (auto simp add: field_simps)
wenzelm@49970
   294
                done
wenzelm@49970
   295
              finally show "y\<in>ball x e"
wenzelm@49970
   296
                unfolding mem_ball dist_norm using e by (auto simp add:field_simps)
wenzelm@49970
   297
            qed
wenzelm@49970
   298
            ultimately show ?thesis
wenzelm@49970
   299
              apply (rule_tac x="?z" in exI)
wenzelm@49970
   300
              unfolding Union_insert
wenzelm@49970
   301
              apply auto
wenzelm@49970
   302
              done
wenzelm@49970
   303
          next
hoelzl@50526
   304
            let ?z = "x + (e/2) *\<^sub>R k"
hoelzl@50526
   305
            assume as: "x\<bullet>k = b\<bullet>k"
wenzelm@49970
   306
            have "ball ?z (e / 2) \<inter> i = {}"
wenzelm@49970
   307
              apply (rule ccontr)
wenzelm@49970
   308
              unfolding ex_in_conv[THEN sym]
wenzelm@49970
   309
            proof(erule exE)
wenzelm@49970
   310
              fix y
wenzelm@49970
   311
              assume "y \<in> ball ?z (e / 2) \<inter> i"
wenzelm@49970
   312
              hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
hoelzl@50526
   313
              hence "\<bar>(?z - y) \<bullet> k\<bar> < e/2"
hoelzl@50526
   314
                using Basis_le_norm[OF k, of "?z - y"] unfolding dist_norm by auto
hoelzl@50526
   315
              hence "y\<bullet>k > b\<bullet>k"
hoelzl@50526
   316
                using e[THEN conjunct1] k by(auto simp add:field_simps inner_simps inner_Basis as)
wenzelm@49970
   317
              hence "y \<notin> i"
hoelzl@50526
   318
                unfolding ab mem_interval by (auto intro!: bexI[OF _ k])
wenzelm@49970
   319
              thus False using yi by auto
wenzelm@49970
   320
            qed
wenzelm@49970
   321
            moreover
wenzelm@49970
   322
            have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)"
wenzelm@49970
   323
              apply (rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]])
wenzelm@49970
   324
            proof
wenzelm@49970
   325
              fix y
wenzelm@49970
   326
              assume as: "y\<in> ball ?z (e/2)"
hoelzl@50526
   327
              have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y + (e / 2) *\<^sub>R k)"
wenzelm@49970
   328
                apply -
hoelzl@50526
   329
                apply(rule order_trans,rule norm_triangle_sub[of "x - y" "- (e/2) *\<^sub>R k"])
wenzelm@49970
   330
                unfolding norm_scaleR
hoelzl@50526
   331
                apply (auto simp: k)
wenzelm@49970
   332
                done
wenzelm@49970
   333
              also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2"
wenzelm@49970
   334
                apply (rule add_strict_left_mono)
wenzelm@49970
   335
                using as unfolding mem_ball dist_norm
wenzelm@49970
   336
                using e apply (auto simp add: field_simps)
wenzelm@49970
   337
                done
wenzelm@49970
   338
              finally show "y\<in>ball x e"
wenzelm@49970
   339
                unfolding mem_ball dist_norm using e by(auto simp add:field_simps)
wenzelm@49970
   340
            qed
wenzelm@49970
   341
            ultimately show ?thesis
wenzelm@49970
   342
              apply (rule_tac x="?z" in exI)
wenzelm@49970
   343
              unfolding Union_insert
wenzelm@49970
   344
              apply auto
wenzelm@49970
   345
              done
wenzelm@49970
   346
          qed 
wenzelm@49970
   347
          then guess x ..
wenzelm@49970
   348
          hence "x \<in> s \<inter> interior (\<Union>f)"
wenzelm@49970
   349
            unfolding lem1[where U="\<Union>f",THEN sym]
wenzelm@49970
   350
            using centre_in_ball e[THEN conjunct1] by auto
wenzelm@49970
   351
          thus ?thesis
wenzelm@49970
   352
            apply -
wenzelm@49970
   353
            apply (rule lem2, rule insert(3))
wenzelm@49970
   354
            using insert(4) apply auto
wenzelm@49970
   355
            done
wenzelm@49970
   356
        qed
wenzelm@49970
   357
      qed
wenzelm@49970
   358
    qed
wenzelm@49970
   359
  qed
wenzelm@49970
   360
  note * = this
wenzelm@49970
   361
  guess t using *[OF assms(1,3) goal1] ..
wenzelm@49970
   362
  from this(2) guess x ..
wenzelm@49970
   363
  then guess e ..
wenzelm@49970
   364
  hence "x \<in> s" "x\<in>interior t"
wenzelm@49970
   365
    defer
wenzelm@49970
   366
    using open_subset_interior[OF open_ball, of x e t] apply auto
wenzelm@49970
   367
    done
wenzelm@49970
   368
  thus False using `t\<in>f` assms(4) by auto
wenzelm@49970
   369
qed
wenzelm@49970
   370
hoelzl@37489
   371
himmelma@35172
   372
subsection {* Bounds on intervals where they exist. *}
himmelma@35172
   373
hoelzl@50526
   374
definition interval_upperbound :: "('a::ordered_euclidean_space) set \<Rightarrow> 'a" where
hoelzl@50526
   375
  "interval_upperbound s = (\<Sum>i\<in>Basis. Sup {a. \<exists>x\<in>s. x\<bullet>i = a} *\<^sub>R i)"
hoelzl@50526
   376
hoelzl@50526
   377
definition interval_lowerbound :: "('a::ordered_euclidean_space) set \<Rightarrow> 'a" where
hoelzl@50526
   378
  "interval_lowerbound s = (\<Sum>i\<in>Basis. Inf {a. \<exists>x\<in>s. x\<bullet>i = a} *\<^sub>R i)"
wenzelm@49970
   379
wenzelm@49970
   380
lemma interval_upperbound[simp]:
hoelzl@50526
   381
  "\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i \<Longrightarrow>
hoelzl@50526
   382
    interval_upperbound {a..b} = (b::'a::ordered_euclidean_space)"
hoelzl@50526
   383
  unfolding interval_upperbound_def euclidean_representation_setsum
hoelzl@50526
   384
  by (auto simp del: ex_simps simp add: Bex_def ex_simps[symmetric] eucl_le[where 'a='a] setle_def
hoelzl@50526
   385
           intro!: Sup_unique)
wenzelm@49970
   386
wenzelm@49970
   387
lemma interval_lowerbound[simp]:
hoelzl@50526
   388
  "\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i \<Longrightarrow>
hoelzl@50526
   389
    interval_lowerbound {a..b} = (a::'a::ordered_euclidean_space)"
hoelzl@50526
   390
  unfolding interval_lowerbound_def euclidean_representation_setsum
hoelzl@50526
   391
  by (auto simp del: ex_simps simp add: Bex_def ex_simps[symmetric] eucl_le[where 'a='a] setge_def
hoelzl@50526
   392
           intro!: Inf_unique)
himmelma@35172
   393
himmelma@35172
   394
lemmas interval_bounds = interval_upperbound interval_lowerbound
himmelma@35172
   395
wenzelm@49970
   396
lemma interval_bounds'[simp]:
wenzelm@49970
   397
  assumes "{a..b}\<noteq>{}"
wenzelm@49970
   398
  shows "interval_upperbound {a..b} = b" "interval_lowerbound {a..b} = a"
himmelma@35172
   399
  using assms unfolding interval_ne_empty by auto
himmelma@35172
   400
himmelma@35172
   401
subsection {* Content (length, area, volume...) of an interval. *}
himmelma@35172
   402
hoelzl@37489
   403
definition "content (s::('a::ordered_euclidean_space) set) =
hoelzl@50526
   404
  (if s = {} then 0 else (\<Prod>i\<in>Basis. (interval_upperbound s)\<bullet>i - (interval_lowerbound s)\<bullet>i))"
hoelzl@50526
   405
hoelzl@50526
   406
lemma interval_not_empty:"\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i \<Longrightarrow> {a..b::'a::ordered_euclidean_space} \<noteq> {}"
hoelzl@37489
   407
  unfolding interval_eq_empty unfolding not_ex not_less by auto
hoelzl@37489
   408
wenzelm@49970
   409
lemma content_closed_interval:
wenzelm@49970
   410
  fixes a::"'a::ordered_euclidean_space"
hoelzl@50526
   411
  assumes "\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i"
hoelzl@50526
   412
  shows "content {a..b} = (\<Prod>i\<in>Basis. b\<bullet>i - a\<bullet>i)"
wenzelm@49970
   413
  using interval_not_empty[OF assms]
wenzelm@49970
   414
  unfolding content_def interval_upperbound[OF assms] interval_lowerbound[OF assms]
wenzelm@49970
   415
  by auto
wenzelm@49970
   416
wenzelm@49970
   417
lemma content_closed_interval':
wenzelm@49970
   418
  fixes a::"'a::ordered_euclidean_space"
wenzelm@49970
   419
  assumes "{a..b}\<noteq>{}"
hoelzl@50526
   420
  shows "content {a..b} = (\<Prod>i\<in>Basis. b\<bullet>i - a\<bullet>i)"
wenzelm@49970
   421
  apply (rule content_closed_interval)
wenzelm@50945
   422
  using assms
wenzelm@50945
   423
  unfolding interval_ne_empty
wenzelm@49970
   424
  apply assumption
wenzelm@49970
   425
  done
wenzelm@49970
   426
wenzelm@49970
   427
lemma content_real:
wenzelm@49970
   428
  assumes "a\<le>b"
wenzelm@49970
   429
  shows "content {a..b} = b-a"
wenzelm@49970
   430
proof -
wenzelm@49970
   431
  have *: "{..<Suc 0} = {0}" by auto
wenzelm@49970
   432
  show ?thesis unfolding content_def using assms by (auto simp: *)
hoelzl@37489
   433
qed
hoelzl@37489
   434
hoelzl@50104
   435
lemma content_singleton[simp]: "content {a} = 0"
hoelzl@50104
   436
proof -
hoelzl@50104
   437
  have "content {a .. a} = 0"
hoelzl@50526
   438
    by (subst content_closed_interval) (auto simp: ex_in_conv)
hoelzl@50104
   439
  then show ?thesis by simp
hoelzl@50104
   440
qed
hoelzl@50104
   441
wenzelm@49970
   442
lemma content_unit[intro]: "content{0..One::'a::ordered_euclidean_space} = 1"
wenzelm@49970
   443
proof -
hoelzl@50526
   444
  have *: "\<forall>i\<in>Basis. (0::'a)\<bullet>i \<le> (One::'a)\<bullet>i" by auto
hoelzl@37489
   445
  have "0 \<in> {0..One::'a}" unfolding mem_interval by auto
wenzelm@49970
   446
  thus ?thesis unfolding content_def interval_bounds[OF *] using setprod_1 by auto
wenzelm@49970
   447
qed
wenzelm@49970
   448
wenzelm@49970
   449
lemma content_pos_le[intro]:
wenzelm@49970
   450
  fixes a::"'a::ordered_euclidean_space"
wenzelm@49970
   451
  shows "0 \<le> content {a..b}"
wenzelm@49970
   452
proof (cases "{a..b} = {}")
wenzelm@49970
   453
  case False
hoelzl@50526
   454
  hence *: "\<forall>i\<in>Basis. a \<bullet> i \<le> b \<bullet> i" unfolding interval_ne_empty .
hoelzl@50526
   455
  have "(\<Prod>i\<in>Basis. interval_upperbound {a..b} \<bullet> i - interval_lowerbound {a..b} \<bullet> i) \<ge> 0"
wenzelm@49970
   456
    apply (rule setprod_nonneg)
wenzelm@49970
   457
    unfolding interval_bounds[OF *]
wenzelm@49970
   458
    using *
hoelzl@50526
   459
    apply (erule_tac x=x in ballE)
wenzelm@49970
   460
    apply auto
wenzelm@49970
   461
    done
wenzelm@49970
   462
  thus ?thesis unfolding content_def by (auto simp del:interval_bounds')
wenzelm@49970
   463
qed (unfold content_def, auto)
wenzelm@49970
   464
wenzelm@49970
   465
lemma content_pos_lt:
wenzelm@49970
   466
  fixes a::"'a::ordered_euclidean_space"
hoelzl@50526
   467
  assumes "\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i"
wenzelm@49970
   468
  shows "0 < content {a..b}"
wenzelm@49970
   469
proof -
hoelzl@50526
   470
  have help_lemma1: "\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i \<Longrightarrow> \<forall>i\<in>Basis. a\<bullet>i \<le> ((b\<bullet>i)::real)"
hoelzl@50526
   471
    apply (rule, erule_tac x=i in ballE)
wenzelm@49970
   472
    apply auto
wenzelm@49970
   473
    done
wenzelm@49970
   474
  show ?thesis unfolding content_closed_interval[OF help_lemma1[OF assms]]
wenzelm@49970
   475
    apply(rule setprod_pos)
hoelzl@50526
   476
    using assms apply (erule_tac x=x in ballE)
wenzelm@49970
   477
    apply auto
wenzelm@49970
   478
    done
wenzelm@49970
   479
qed
wenzelm@49970
   480
hoelzl@50526
   481
lemma content_eq_0: "content{a..b::'a::ordered_euclidean_space} = 0 \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i \<le> a\<bullet>i)"
wenzelm@49970
   482
proof (cases "{a..b} = {}")
wenzelm@49970
   483
  case True
wenzelm@49970
   484
  thus ?thesis
wenzelm@49970
   485
    unfolding content_def if_P[OF True]
wenzelm@49970
   486
    unfolding interval_eq_empty
wenzelm@49970
   487
    apply -
hoelzl@50526
   488
    apply (rule, erule bexE)
hoelzl@50526
   489
    apply (rule_tac x = i in bexI)
wenzelm@49970
   490
    apply auto
wenzelm@49970
   491
    done
wenzelm@49970
   492
next
wenzelm@49970
   493
  case False
wenzelm@49970
   494
  from this[unfolded interval_eq_empty not_ex not_less]
hoelzl@50526
   495
  have as: "\<forall>i\<in>Basis. b \<bullet> i \<ge> a \<bullet> i" by fastforce
wenzelm@49970
   496
  show ?thesis
hoelzl@50526
   497
    unfolding content_def if_not_P[OF False] setprod_zero_iff[OF finite_Basis]
hoelzl@50526
   498
    using as
hoelzl@50526
   499
    by (auto intro!: bexI)
wenzelm@49970
   500
qed
himmelma@35172
   501
himmelma@35172
   502
lemma cond_cases:"(P \<Longrightarrow> Q x) \<Longrightarrow> (\<not> P \<Longrightarrow> Q y) \<Longrightarrow> Q (if P then x else y)" by auto
himmelma@35172
   503
himmelma@35172
   504
lemma content_closed_interval_cases:
wenzelm@49970
   505
  "content {a..b::'a::ordered_euclidean_space} =
hoelzl@50526
   506
    (if \<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i then setprod (\<lambda>i. b\<bullet>i - a\<bullet>i) Basis else 0)"
hoelzl@50526
   507
  by (auto simp: not_le content_eq_0 intro: less_imp_le content_closed_interval)
himmelma@35172
   508
himmelma@35172
   509
lemma content_eq_0_interior: "content {a..b} = 0 \<longleftrightarrow> interior({a..b}) = {}"
himmelma@35172
   510
  unfolding content_eq_0 interior_closed_interval interval_eq_empty by auto
himmelma@35172
   511
hoelzl@50526
   512
lemma content_pos_lt_eq: "0 < content {a..b::'a::ordered_euclidean_space} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i)"
wenzelm@49970
   513
  apply rule
wenzelm@49970
   514
  defer
wenzelm@49970
   515
  apply (rule content_pos_lt, assumption)
wenzelm@49970
   516
proof -
wenzelm@49970
   517
  assume "0 < content {a..b}"
wenzelm@49970
   518
  hence "content {a..b} \<noteq> 0" by auto
hoelzl@50526
   519
  thus "\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i"
wenzelm@49970
   520
    unfolding content_eq_0 not_ex not_le by fastforce
wenzelm@49970
   521
qed
wenzelm@49970
   522
wenzelm@49970
   523
lemma content_empty [simp]: "content {} = 0" unfolding content_def by auto
himmelma@35172
   524
wenzelm@49698
   525
lemma content_subset:
wenzelm@49698
   526
  assumes "{a..b} \<subseteq> {c..d}"
wenzelm@49698
   527
  shows "content {a..b::'a::ordered_euclidean_space} \<le> content {c..d}"
wenzelm@49698
   528
proof (cases "{a..b} = {}")
wenzelm@49698
   529
  case True
wenzelm@49698
   530
  thus ?thesis using content_pos_le[of c d] by auto
wenzelm@49698
   531
next
wenzelm@49698
   532
  case False
hoelzl@50526
   533
  hence ab_ne:"\<forall>i\<in>Basis. a \<bullet> i \<le> b \<bullet> i" unfolding interval_ne_empty by auto
himmelma@35172
   534
  hence ab_ab:"a\<in>{a..b}" "b\<in>{a..b}" unfolding mem_interval by auto
himmelma@35172
   535
  have "{c..d} \<noteq> {}" using assms False by auto
hoelzl@50526
   536
  hence cd_ne:"\<forall>i\<in>Basis. c \<bullet> i \<le> d \<bullet> i" using assms unfolding interval_ne_empty by auto
wenzelm@49698
   537
  show ?thesis
wenzelm@49698
   538
    unfolding content_def
wenzelm@49698
   539
    unfolding interval_bounds[OF ab_ne] interval_bounds[OF cd_ne]
wenzelm@49698
   540
    unfolding if_not_P[OF False] if_not_P[OF `{c..d} \<noteq> {}`]
wenzelm@50945
   541
    apply (rule setprod_mono, rule)
wenzelm@49698
   542
  proof
hoelzl@50526
   543
    fix i :: 'a
wenzelm@50945
   544
    assume i: "i\<in>Basis"
hoelzl@50526
   545
    show "0 \<le> b \<bullet> i - a \<bullet> i" using ab_ne[THEN bspec, OF i] i by auto
hoelzl@50526
   546
    show "b \<bullet> i - a \<bullet> i \<le> d \<bullet> i - c \<bullet> i"
himmelma@35172
   547
      using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(2),of i]
wenzelm@49698
   548
      using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(1),of i]
wenzelm@49698
   549
      using i by auto
wenzelm@49698
   550
  qed
wenzelm@49698
   551
qed
himmelma@35172
   552
himmelma@35172
   553
lemma content_lt_nz: "0 < content {a..b} \<longleftrightarrow> content {a..b} \<noteq> 0"
nipkow@44890
   554
  unfolding content_pos_lt_eq content_eq_0 unfolding not_ex not_le by fastforce
himmelma@35172
   555
wenzelm@49698
   556
himmelma@35172
   557
subsection {* The notion of a gauge --- simply an open set containing the point. *}
himmelma@35172
   558
himmelma@35172
   559
definition gauge where "gauge d \<longleftrightarrow> (\<forall>x. x\<in>(d x) \<and> open(d x))"
himmelma@35172
   560
wenzelm@49698
   561
lemma gaugeI: assumes "\<And>x. x\<in>g x" "\<And>x. open (g x)" shows "gauge g"
himmelma@35172
   562
  using assms unfolding gauge_def by auto
himmelma@35172
   563
wenzelm@49698
   564
lemma gaugeD[dest]: assumes "gauge d" shows "x\<in>d x" "open (d x)"
wenzelm@49698
   565
  using assms unfolding gauge_def by auto
himmelma@35172
   566
himmelma@35172
   567
lemma gauge_ball_dependent: "\<forall>x. 0 < e x \<Longrightarrow> gauge (\<lambda>x. ball x (e x))"
himmelma@35172
   568
  unfolding gauge_def by auto 
himmelma@35172
   569
himmelma@35751
   570
lemma gauge_ball[intro]: "0 < e \<Longrightarrow> gauge (\<lambda>x. ball x e)" unfolding gauge_def by auto 
himmelma@35172
   571
wenzelm@49698
   572
lemma gauge_trivial[intro]: "gauge (\<lambda>x. ball x 1)"
wenzelm@49698
   573
  by (rule gauge_ball) auto
himmelma@35172
   574
himmelma@35751
   575
lemma gauge_inter[intro]: "gauge d1 \<Longrightarrow> gauge d2 \<Longrightarrow> gauge (\<lambda>x. (d1 x) \<inter> (d2 x))"
himmelma@35172
   576
  unfolding gauge_def by auto 
himmelma@35172
   577
wenzelm@49698
   578
lemma gauge_inters:
wenzelm@49698
   579
  assumes "finite s" "\<forall>d\<in>s. gauge (f d)"
wenzelm@49698
   580
  shows "gauge(\<lambda>x. \<Inter> {f d x | d. d \<in> s})"
wenzelm@49698
   581
proof -
wenzelm@49698
   582
  have *:"\<And>x. {f d x |d. d \<in> s} = (\<lambda>d. f d x) ` s" by auto
wenzelm@49698
   583
  show ?thesis
wenzelm@49698
   584
    unfolding gauge_def unfolding * 
wenzelm@49698
   585
    using assms unfolding Ball_def Inter_iff mem_Collect_eq gauge_def by auto
wenzelm@49698
   586
qed
wenzelm@49698
   587
wenzelm@49698
   588
lemma gauge_existence_lemma: "(\<forall>x. \<exists>d::real. p x \<longrightarrow> 0 < d \<and> q d x) \<longleftrightarrow> (\<forall>x. \<exists>d>0. p x \<longrightarrow> q d x)"
wenzelm@49698
   589
  by(meson zero_less_one)
wenzelm@49698
   590
himmelma@35172
   591
himmelma@35172
   592
subsection {* Divisions. *}
himmelma@35172
   593
himmelma@35172
   594
definition division_of (infixl "division'_of" 40) where
himmelma@35172
   595
  "s division_of i \<equiv>
himmelma@35172
   596
        finite s \<and>
himmelma@35172
   597
        (\<forall>k\<in>s. k \<subseteq> i \<and> k \<noteq> {} \<and> (\<exists>a b. k = {a..b})) \<and>
himmelma@35172
   598
        (\<forall>k1\<in>s. \<forall>k2\<in>s. k1 \<noteq> k2 \<longrightarrow> interior(k1) \<inter> interior(k2) = {}) \<and>
himmelma@35172
   599
        (\<Union>s = i)"
himmelma@35172
   600
wenzelm@49698
   601
lemma division_ofD[dest]:
wenzelm@49698
   602
  assumes "s division_of i"
wenzelm@49698
   603
  shows "finite s" "\<And>k. k\<in>s \<Longrightarrow> k \<subseteq> i" "\<And>k. k\<in>s \<Longrightarrow>  k \<noteq> {}" "\<And>k. k\<in>s \<Longrightarrow> (\<exists>a b. k = {a..b})"
wenzelm@49698
   604
    "\<And>k1 k2. \<lbrakk>k1\<in>s; k2\<in>s; k1 \<noteq> k2\<rbrakk> \<Longrightarrow> interior(k1) \<inter> interior(k2) = {}" "\<Union>s = i"
wenzelm@49698
   605
  using assms unfolding division_of_def by auto
himmelma@35172
   606
himmelma@35172
   607
lemma division_ofI:
himmelma@35172
   608
  assumes "finite s" "\<And>k. k\<in>s \<Longrightarrow> k \<subseteq> i" "\<And>k. k\<in>s \<Longrightarrow>  k \<noteq> {}" "\<And>k. k\<in>s \<Longrightarrow> (\<exists>a b. k = {a..b})"
wenzelm@49698
   609
    "\<And>k1 k2. \<lbrakk>k1\<in>s; k2\<in>s; k1 \<noteq> k2\<rbrakk> \<Longrightarrow> interior(k1) \<inter> interior(k2) = {}" "\<Union>s = i"
himmelma@35172
   610
  shows "s division_of i" using assms unfolding division_of_def by auto
himmelma@35172
   611
himmelma@35172
   612
lemma division_of_finite: "s division_of i \<Longrightarrow> finite s"
himmelma@35172
   613
  unfolding division_of_def by auto
himmelma@35172
   614
himmelma@35172
   615
lemma division_of_self[intro]: "{a..b} \<noteq> {} \<Longrightarrow> {{a..b}} division_of {a..b}"
himmelma@35172
   616
  unfolding division_of_def by auto
himmelma@35172
   617
himmelma@35172
   618
lemma division_of_trivial[simp]: "s division_of {} \<longleftrightarrow> s = {}" unfolding division_of_def by auto 
himmelma@35172
   619
wenzelm@49698
   620
lemma division_of_sing[simp]:
wenzelm@49698
   621
  "s division_of {a..a::'a::ordered_euclidean_space} \<longleftrightarrow> s = {{a..a}}" (is "?l = ?r")
wenzelm@49698
   622
proof
wenzelm@49698
   623
  assume ?r
wenzelm@49698
   624
  moreover {
wenzelm@49698
   625
    assume "s = {{a}}"
wenzelm@49698
   626
    moreover fix k assume "k\<in>s" 
wenzelm@49698
   627
    ultimately have"\<exists>x y. k = {x..y}"
wenzelm@50945
   628
      apply (rule_tac x=a in exI)+
wenzelm@50945
   629
      unfolding interval_sing
wenzelm@50945
   630
      apply auto
wenzelm@50945
   631
      done
wenzelm@49698
   632
  }
wenzelm@49698
   633
  ultimately show ?l unfolding division_of_def interval_sing by auto
wenzelm@49698
   634
next
wenzelm@49698
   635
  assume ?l
wenzelm@49698
   636
  note as=conjunctD4[OF this[unfolded division_of_def interval_sing]]
himmelma@35172
   637
  { fix x assume x:"x\<in>s" have "x={a}" using as(2)[rule_format,OF x] by auto }
wenzelm@49698
   638
  moreover have "s \<noteq> {}" using as(4) by auto
wenzelm@49698
   639
  ultimately show ?r unfolding interval_sing by auto
wenzelm@49698
   640
qed
himmelma@35172
   641
himmelma@35172
   642
lemma elementary_empty: obtains p where "p division_of {}"
himmelma@35172
   643
  unfolding division_of_trivial by auto
himmelma@35172
   644
wenzelm@49698
   645
lemma elementary_interval: obtains p where "p division_of {a..b}"
wenzelm@49698
   646
  by (metis division_of_trivial division_of_self)
himmelma@35172
   647
himmelma@35172
   648
lemma division_contains: "s division_of i \<Longrightarrow> \<forall>x\<in>i. \<exists>k\<in>s. x \<in> k"
himmelma@35172
   649
  unfolding division_of_def by auto
himmelma@35172
   650
himmelma@35172
   651
lemma forall_in_division:
himmelma@35172
   652
 "d division_of i \<Longrightarrow> ((\<forall>x\<in>d. P x) \<longleftrightarrow> (\<forall>a b. {a..b} \<in> d \<longrightarrow> P {a..b}))"
nipkow@44890
   653
  unfolding division_of_def by fastforce
himmelma@35172
   654
himmelma@35172
   655
lemma division_of_subset: assumes "p division_of (\<Union>p)" "q \<subseteq> p" shows "q division_of (\<Union>q)"
wenzelm@49698
   656
  apply (rule division_ofI)
wenzelm@49698
   657
proof -
wenzelm@49698
   658
  note as=division_ofD[OF assms(1)]
wenzelm@49698
   659
  show "finite q"
wenzelm@49698
   660
    apply (rule finite_subset)
wenzelm@49698
   661
    using as(1) assms(2) apply auto
wenzelm@49698
   662
    done
wenzelm@49698
   663
  { fix k
wenzelm@49698
   664
    assume "k \<in> q"
wenzelm@49698
   665
    hence kp:"k\<in>p" using assms(2) by auto
wenzelm@49698
   666
    show "k\<subseteq>\<Union>q" using `k \<in> q` by auto
wenzelm@49698
   667
    show "\<exists>a b. k = {a..b}" using as(4)[OF kp]
wenzelm@49698
   668
      by auto show "k \<noteq> {}" using as(3)[OF kp] by auto }
wenzelm@49698
   669
  fix k1 k2
wenzelm@49698
   670
  assume "k1 \<in> q" "k2 \<in> q" "k1 \<noteq> k2"
wenzelm@49698
   671
  hence *: "k1\<in>p" "k2\<in>p" "k1\<noteq>k2" using assms(2) by auto
wenzelm@49698
   672
  show "interior k1 \<inter> interior k2 = {}" using as(5)[OF *] by auto
wenzelm@49698
   673
qed auto
wenzelm@49698
   674
wenzelm@49698
   675
lemma division_of_union_self[intro]: "p division_of s \<Longrightarrow> p division_of (\<Union>p)"
wenzelm@49698
   676
  unfolding division_of_def by auto
himmelma@35172
   677
wenzelm@49970
   678
lemma division_of_content_0:
wenzelm@49970
   679
  assumes "content {a..b} = 0" "d division_of {a..b}"
wenzelm@49970
   680
  shows "\<forall>k\<in>d. content k = 0"
wenzelm@49970
   681
  unfolding forall_in_division[OF assms(2)]
wenzelm@50945
   682
  apply (rule,rule,rule)
wenzelm@50945
   683
  apply (drule division_ofD(2)[OF assms(2)])
wenzelm@50945
   684
  apply (drule content_subset) unfolding assms(1)
wenzelm@49970
   685
proof -
wenzelm@49970
   686
  case goal1
wenzelm@49970
   687
  thus ?case using content_pos_le[of a b] by auto
wenzelm@49970
   688
qed
wenzelm@49970
   689
wenzelm@49970
   690
lemma division_inter:
wenzelm@49970
   691
  assumes "p1 division_of s1" "p2 division_of (s2::('a::ordered_euclidean_space) set)"
wenzelm@49970
   692
  shows "{k1 \<inter> k2 | k1 k2 .k1 \<in> p1 \<and> k2 \<in> p2 \<and> k1 \<inter> k2 \<noteq> {}} division_of (s1 \<inter> s2)"
wenzelm@49970
   693
  (is "?A' division_of _")
wenzelm@49970
   694
proof -
wenzelm@49970
   695
  let ?A = "{s. s \<in>  (\<lambda>(k1,k2). k1 \<inter> k2) ` (p1 \<times> p2) \<and> s \<noteq> {}}"
wenzelm@49970
   696
  have *:"?A' = ?A" by auto
wenzelm@49970
   697
  show ?thesis unfolding *
wenzelm@49970
   698
  proof (rule division_ofI)
wenzelm@49970
   699
    have "?A \<subseteq> (\<lambda>(x, y). x \<inter> y) ` (p1 \<times> p2)" by auto
wenzelm@49970
   700
    moreover have "finite (p1 \<times> p2)" using assms unfolding division_of_def by auto
wenzelm@49970
   701
    ultimately show "finite ?A" by auto
wenzelm@49970
   702
    have *:"\<And>s. \<Union>{x\<in>s. x \<noteq> {}} = \<Union>s" by auto
wenzelm@49970
   703
    show "\<Union>?A = s1 \<inter> s2"
wenzelm@49970
   704
      apply (rule set_eqI)
wenzelm@49970
   705
      unfolding * and Union_image_eq UN_iff
wenzelm@49970
   706
      using division_ofD(6)[OF assms(1)] and division_ofD(6)[OF assms(2)]
wenzelm@49970
   707
      apply auto
wenzelm@49970
   708
      done
wenzelm@49970
   709
    { fix k
wenzelm@49970
   710
      assume "k\<in>?A"
wenzelm@49970
   711
      then obtain k1 k2 where k: "k = k1 \<inter> k2" "k1\<in>p1" "k2\<in>p2" "k\<noteq>{}" by auto
wenzelm@49970
   712
      thus "k \<noteq> {}" by auto
wenzelm@49970
   713
      show "k \<subseteq> s1 \<inter> s2"
wenzelm@49970
   714
        using division_ofD(2)[OF assms(1) k(2)] and division_ofD(2)[OF assms(2) k(3)]
wenzelm@49970
   715
        unfolding k by auto
wenzelm@49970
   716
      guess a1 using division_ofD(4)[OF assms(1) k(2)] ..
wenzelm@49970
   717
      then guess b1 .. note ab1=this
wenzelm@49970
   718
      guess a2 using division_ofD(4)[OF assms(2) k(3)] ..
wenzelm@49970
   719
      then guess b2 .. note ab2=this
wenzelm@49970
   720
      show "\<exists>a b. k = {a..b}"
wenzelm@49970
   721
        unfolding k ab1 ab2 unfolding inter_interval by auto }
wenzelm@49970
   722
    fix k1 k2
wenzelm@49970
   723
    assume "k1\<in>?A"
wenzelm@49970
   724
    then obtain x1 y1 where k1:"k1 = x1 \<inter> y1" "x1\<in>p1" "y1\<in>p2" "k1\<noteq>{}" by auto
wenzelm@49970
   725
    assume "k2\<in>?A"
wenzelm@49970
   726
    then obtain x2 y2 where k2:"k2 = x2 \<inter> y2" "x2\<in>p1" "y2\<in>p2" "k2\<noteq>{}" by auto
wenzelm@49970
   727
    assume "k1 \<noteq> k2"
wenzelm@49970
   728
    hence th:"x1\<noteq>x2 \<or> y1\<noteq>y2" unfolding k1 k2 by auto
wenzelm@49970
   729
    have *:"(interior x1 \<inter> interior x2 = {} \<or> interior y1 \<inter> interior y2 = {}) \<Longrightarrow>
himmelma@35172
   730
      interior(x1 \<inter> y1) \<subseteq> interior(x1) \<Longrightarrow> interior(x1 \<inter> y1) \<subseteq> interior(y1) \<Longrightarrow>
himmelma@35172
   731
      interior(x2 \<inter> y2) \<subseteq> interior(x2) \<Longrightarrow> interior(x2 \<inter> y2) \<subseteq> interior(y2)
himmelma@35172
   732
      \<Longrightarrow> interior(x1 \<inter> y1) \<inter> interior(x2 \<inter> y2) = {}" by auto
wenzelm@49970
   733
    show "interior k1 \<inter> interior k2 = {}"
wenzelm@49970
   734
      unfolding k1 k2
wenzelm@49970
   735
      apply (rule *)
wenzelm@49970
   736
      defer
wenzelm@49970
   737
      apply (rule_tac[1-4] interior_mono)
wenzelm@49970
   738
      using division_ofD(5)[OF assms(1) k1(2) k2(2)]
wenzelm@49970
   739
      using division_ofD(5)[OF assms(2) k1(3) k2(3)]
wenzelm@49970
   740
      using th apply auto done
wenzelm@49970
   741
  qed
wenzelm@49970
   742
qed
wenzelm@49970
   743
wenzelm@49970
   744
lemma division_inter_1:
wenzelm@49970
   745
  assumes "d division_of i" "{a..b::'a::ordered_euclidean_space} \<subseteq> i"
wenzelm@49970
   746
  shows "{ {a..b} \<inter> k |k. k \<in> d \<and> {a..b} \<inter> k \<noteq> {} } division_of {a..b}"
wenzelm@49970
   747
proof (cases "{a..b} = {}")
wenzelm@49970
   748
  case True
wenzelm@49970
   749
  show ?thesis unfolding True and division_of_trivial by auto
wenzelm@49970
   750
next
wenzelm@49970
   751
  case False
wenzelm@49970
   752
  have *: "{a..b} \<inter> i = {a..b}" using assms(2) by auto
wenzelm@49970
   753
  show ?thesis using division_inter[OF division_of_self[OF False] assms(1)] unfolding * by auto
wenzelm@49970
   754
qed
wenzelm@49970
   755
wenzelm@49970
   756
lemma elementary_inter:
wenzelm@49970
   757
  assumes "p1 division_of s" "p2 division_of (t::('a::ordered_euclidean_space) set)"
himmelma@35172
   758
  shows "\<exists>p. p division_of (s \<inter> t)"
wenzelm@50945
   759
  apply rule
wenzelm@50945
   760
  apply (rule division_inter[OF assms])
wenzelm@50945
   761
  done
wenzelm@49970
   762
wenzelm@49970
   763
lemma elementary_inters:
wenzelm@49970
   764
  assumes "finite f" "f\<noteq>{}" "\<forall>s\<in>f. \<exists>p. p division_of (s::('a::ordered_euclidean_space) set)"
wenzelm@49970
   765
  shows "\<exists>p. p division_of (\<Inter> f)"
wenzelm@49970
   766
  using assms
wenzelm@49970
   767
proof (induct f rule: finite_induct)
wenzelm@49970
   768
  case (insert x f)
wenzelm@49970
   769
  show ?case
wenzelm@49970
   770
  proof (cases "f = {}")
wenzelm@49970
   771
    case True
wenzelm@49970
   772
    thus ?thesis unfolding True using insert by auto
wenzelm@49970
   773
  next
wenzelm@49970
   774
    case False
wenzelm@49970
   775
    guess p using insert(3)[OF False insert(5)[unfolded ball_simps,THEN conjunct2]] ..
wenzelm@49970
   776
    moreover guess px using insert(5)[rule_format,OF insertI1] ..
wenzelm@49970
   777
    ultimately show ?thesis
wenzelm@49970
   778
      unfolding Inter_insert
wenzelm@49970
   779
      apply (rule_tac elementary_inter)
wenzelm@49970
   780
      apply assumption
wenzelm@49970
   781
      apply assumption
wenzelm@49970
   782
      done
wenzelm@49970
   783
  qed
wenzelm@49970
   784
qed auto
himmelma@35172
   785
himmelma@35172
   786
lemma division_disjoint_union:
himmelma@35172
   787
  assumes "p1 division_of s1" "p2 division_of s2" "interior s1 \<inter> interior s2 = {}"
wenzelm@50945
   788
  shows "(p1 \<union> p2) division_of (s1 \<union> s2)"
wenzelm@50945
   789
proof (rule division_ofI)
himmelma@35172
   790
  note d1 = division_ofD[OF assms(1)] and d2 = division_ofD[OF assms(2)]
himmelma@35172
   791
  show "finite (p1 \<union> p2)" using d1(1) d2(1) by auto
himmelma@35172
   792
  show "\<Union>(p1 \<union> p2) = s1 \<union> s2" using d1(6) d2(6) by auto
wenzelm@50945
   793
  {
wenzelm@50945
   794
    fix k1 k2
wenzelm@50945
   795
    assume as: "k1 \<in> p1 \<union> p2" "k2 \<in> p1 \<union> p2" "k1 \<noteq> k2"
wenzelm@50945
   796
    moreover
wenzelm@50945
   797
    let ?g="interior k1 \<inter> interior k2 = {}"
wenzelm@50945
   798
    {
wenzelm@50945
   799
      assume as: "k1\<in>p1" "k2\<in>p2"
wenzelm@50945
   800
      have ?g
wenzelm@50945
   801
        using interior_mono[OF d1(2)[OF as(1)]] interior_mono[OF d2(2)[OF as(2)]]
wenzelm@50945
   802
        using assms(3) by blast
wenzelm@50945
   803
    }
wenzelm@50945
   804
    moreover
wenzelm@50945
   805
    {
wenzelm@50945
   806
      assume as: "k1\<in>p2" "k2\<in>p1"
wenzelm@50945
   807
      have ?g
wenzelm@50945
   808
        using interior_mono[OF d1(2)[OF as(2)]] interior_mono[OF d2(2)[OF as(1)]]
wenzelm@50945
   809
        using assms(3) by blast
wenzelm@50945
   810
    }
wenzelm@50945
   811
    ultimately show ?g using d1(5)[OF _ _ as(3)] and d2(5)[OF _ _ as(3)] by auto
wenzelm@50945
   812
  }
wenzelm@50945
   813
  fix k
wenzelm@50945
   814
  assume k: "k \<in> p1 \<union> p2"
wenzelm@50945
   815
  show "k \<subseteq> s1 \<union> s2" using k d1(2) d2(2) by auto
wenzelm@50945
   816
  show "k \<noteq> {}" using k d1(3) d2(3) by auto
wenzelm@50945
   817
  show "\<exists>a b. k = {a..b}" using k d1(4) d2(4) by auto
wenzelm@50945
   818
qed
himmelma@35172
   819
himmelma@35172
   820
lemma partial_division_extend_1:
wenzelm@50945
   821
  assumes incl: "{c..d} \<subseteq> {a..b::'a::ordered_euclidean_space}"
wenzelm@50945
   822
    and nonempty: "{c..d} \<noteq> {}"
himmelma@35172
   823
  obtains p where "p division_of {a..b}" "{c..d} \<in> p"
hoelzl@50526
   824
proof
hoelzl@50526
   825
  let ?B = "\<lambda>f::'a\<Rightarrow>'a \<times> 'a. {(\<Sum>i\<in>Basis. (fst (f i) \<bullet> i) *\<^sub>R i) .. (\<Sum>i\<in>Basis. (snd (f i) \<bullet> i) *\<^sub>R i)}"
hoelzl@50526
   826
  def p \<equiv> "?B ` (Basis \<rightarrow>\<^isub>E {(a, c), (c, d), (d, b)})"
hoelzl@50526
   827
hoelzl@50526
   828
  show "{c .. d} \<in> p"
hoelzl@50526
   829
    unfolding p_def
hoelzl@50526
   830
    by (auto simp add: interval_eq_empty eucl_le[where 'a='a]
hoelzl@50526
   831
             intro!: image_eqI[where x="\<lambda>(i::'a)\<in>Basis. (c, d)"])
hoelzl@50526
   832
wenzelm@50945
   833
  {
wenzelm@50945
   834
    fix i :: 'a
wenzelm@50945
   835
    assume "i \<in> Basis"
hoelzl@50526
   836
    with incl nonempty have "a \<bullet> i \<le> c \<bullet> i" "c \<bullet> i \<le> d \<bullet> i" "d \<bullet> i \<le> b \<bullet> i"
wenzelm@50945
   837
      unfolding interval_eq_empty subset_interval by (auto simp: not_le)
wenzelm@50945
   838
  }
hoelzl@50526
   839
  note ord = this
hoelzl@50526
   840
hoelzl@50526
   841
  show "p division_of {a..b}"
hoelzl@50526
   842
  proof (rule division_ofI)
wenzelm@50945
   843
    show "finite p" unfolding p_def by (auto intro!: finite_PiE)
wenzelm@50945
   844
    {
wenzelm@50945
   845
      fix k
wenzelm@50945
   846
      assume "k \<in> p"
hoelzl@50526
   847
      then obtain f where f: "f \<in> Basis \<rightarrow>\<^isub>E {(a, c), (c, d), (d, b)}" and k: "k = ?B f"
hoelzl@50526
   848
        by (auto simp: p_def)
hoelzl@50526
   849
      then show "\<exists>a b. k = {a..b}" by auto
hoelzl@50526
   850
      have "k \<subseteq> {a..b} \<and> k \<noteq> {}"
hoelzl@50526
   851
      proof (simp add: k interval_eq_empty subset_interval not_less, safe)
hoelzl@50526
   852
        fix i :: 'a assume i: "i \<in> Basis"
wenzelm@50945
   853
        moreover
wenzelm@50945
   854
        with f have "f i = (a, c) \<or> f i = (c, d) \<or> f i = (d, b)"
hoelzl@50526
   855
          by (auto simp: PiE_iff)
hoelzl@50526
   856
        moreover note ord[of i]
wenzelm@50945
   857
        ultimately
wenzelm@50945
   858
        show "a \<bullet> i \<le> fst (f i) \<bullet> i" "snd (f i) \<bullet> i \<le> b \<bullet> i" "fst (f i) \<bullet> i \<le> snd (f i) \<bullet> i"
hoelzl@50526
   859
          by (auto simp: subset_iff eucl_le[where 'a='a])
hoelzl@50526
   860
      qed
hoelzl@50526
   861
      then show "k \<noteq> {}" "k \<subseteq> {a .. b}" by auto
wenzelm@50945
   862
      {
wenzelm@50945
   863
        fix l assume "l \<in> p"
wenzelm@50945
   864
        then obtain g where g: "g \<in> Basis \<rightarrow>\<^isub>E {(a, c), (c, d), (d, b)}" and l: "l = ?B g"
wenzelm@50945
   865
          by (auto simp: p_def)
wenzelm@50945
   866
        assume "l \<noteq> k"
wenzelm@50945
   867
        have "\<exists>i\<in>Basis. f i \<noteq> g i"
wenzelm@50945
   868
        proof (rule ccontr)
wenzelm@50945
   869
          assume "\<not> (\<exists>i\<in>Basis. f i \<noteq> g i)"
wenzelm@50945
   870
          with f g have "f = g"
wenzelm@50945
   871
            by (auto simp: PiE_iff extensional_def intro!: ext)
wenzelm@50945
   872
          with `l \<noteq> k` show False
wenzelm@50945
   873
            by (simp add: l k)
wenzelm@50945
   874
        qed
wenzelm@50945
   875
        then guess i .. note * = this
wenzelm@50945
   876
        moreover from * have "f i = (a, c) \<or> f i = (c, d) \<or> f i = (d, b)"
wenzelm@50945
   877
            "g i = (a, c) \<or> g i = (c, d) \<or> g i = (d, b)"
wenzelm@50945
   878
          using f g by (auto simp: PiE_iff)
wenzelm@50945
   879
        moreover note ord[of i]
wenzelm@50945
   880
        ultimately show "interior l \<inter> interior k = {}"
wenzelm@50945
   881
          by (auto simp add: l k interior_closed_interval disjoint_interval intro!: bexI[of _ i])
wenzelm@50945
   882
      }
wenzelm@50945
   883
      note `k \<subseteq> { a.. b}`
wenzelm@50945
   884
    }
hoelzl@50526
   885
    moreover
wenzelm@50945
   886
    {
wenzelm@50945
   887
      fix x assume x: "x \<in> {a .. b}"
hoelzl@50526
   888
      have "\<forall>i\<in>Basis. \<exists>l. x \<bullet> i \<in> {fst l \<bullet> i .. snd l \<bullet> i} \<and> l \<in> {(a, c), (c, d), (d, b)}"
hoelzl@50526
   889
      proof
hoelzl@50526
   890
        fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
   891
        with x ord[of i] 
hoelzl@50526
   892
        have "(a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> c \<bullet> i) \<or> (c \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> d \<bullet> i) \<or>
hoelzl@50526
   893
            (d \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i)"
hoelzl@50526
   894
          by (auto simp: eucl_le[where 'a='a])
hoelzl@50526
   895
        then show "\<exists>l. x \<bullet> i \<in> {fst l \<bullet> i .. snd l \<bullet> i} \<and> l \<in> {(a, c), (c, d), (d, b)}"
hoelzl@50526
   896
          by auto
hoelzl@50526
   897
      qed
hoelzl@50526
   898
      then guess f unfolding bchoice_iff .. note f = this
hoelzl@50526
   899
      moreover then have "restrict f Basis \<in> Basis \<rightarrow>\<^isub>E {(a, c), (c, d), (d, b)}"
hoelzl@50526
   900
        by auto
hoelzl@50526
   901
      moreover from f have "x \<in> ?B (restrict f Basis)"
hoelzl@50526
   902
        by (auto simp: mem_interval eucl_le[where 'a='a])
hoelzl@50526
   903
      ultimately have "\<exists>k\<in>p. x \<in> k"
hoelzl@50526
   904
        unfolding p_def by blast }
hoelzl@50526
   905
    ultimately show "\<Union>p = {a..b}"
hoelzl@50526
   906
      by auto
hoelzl@50526
   907
  qed
hoelzl@50526
   908
qed
himmelma@35172
   909
wenzelm@50945
   910
lemma partial_division_extend_interval:
wenzelm@50945
   911
  assumes "p division_of (\<Union>p)" "(\<Union>p) \<subseteq> {a..b}"
wenzelm@50945
   912
  obtains q where "p \<subseteq> q" "q division_of {a..b::'a::ordered_euclidean_space}"
wenzelm@50945
   913
proof (cases "p = {}")
wenzelm@50945
   914
  case True
wenzelm@50945
   915
  guess q apply (rule elementary_interval[of a b]) .
wenzelm@50945
   916
  thus ?thesis
wenzelm@50945
   917
    apply -
wenzelm@50945
   918
    apply (rule that[of q])
wenzelm@50945
   919
    unfolding True
wenzelm@50945
   920
    apply auto
wenzelm@50945
   921
    done
wenzelm@50945
   922
next
wenzelm@50945
   923
  case False
wenzelm@50945
   924
  note p = division_ofD[OF assms(1)]
wenzelm@50945
   925
  have *: "\<forall>k\<in>p. \<exists>q. q division_of {a..b} \<and> k\<in>q"
wenzelm@50945
   926
  proof
wenzelm@50945
   927
    case goal1
wenzelm@50945
   928
    guess c using p(4)[OF goal1] ..
wenzelm@50945
   929
    then guess d .. note "cd" = this
wenzelm@50945
   930
    have *: "{c..d} \<subseteq> {a..b}" "{c..d} \<noteq> {}"
wenzelm@50945
   931
      using p(2,3)[OF goal1, unfolded "cd"] using assms(2) by auto
wenzelm@50945
   932
    guess q apply(rule partial_division_extend_1[OF *]) .
wenzelm@50945
   933
    thus ?case unfolding "cd" by auto
wenzelm@50945
   934
  qed
himmelma@35172
   935
  guess q using bchoice[OF *] .. note q = conjunctD2[OF this[rule_format]]
wenzelm@50945
   936
  have "\<And>x. x\<in>p \<Longrightarrow> \<exists>d. d division_of \<Union>(q x - {x})"
wenzelm@50945
   937
    apply (rule, rule_tac p="q x" in division_of_subset)
wenzelm@50945
   938
  proof -
wenzelm@50945
   939
    fix x
wenzelm@50945
   940
    assume x: "x\<in>p"
wenzelm@50945
   941
    show "q x division_of \<Union>q x"
wenzelm@50945
   942
      apply -
wenzelm@50945
   943
      apply (rule division_ofI)
wenzelm@50945
   944
      using division_ofD[OF q(1)[OF x]]
wenzelm@50945
   945
      apply auto
wenzelm@50945
   946
      done
wenzelm@50945
   947
    show "q x - {x} \<subseteq> q x" by auto
wenzelm@50945
   948
  qed
wenzelm@50945
   949
  hence "\<exists>d. d division_of \<Inter> ((\<lambda>i. \<Union>(q i - {i})) ` p)"
wenzelm@50945
   950
    apply -
wenzelm@50945
   951
    apply (rule elementary_inters)
wenzelm@50945
   952
    apply (rule finite_imageI[OF p(1)])
wenzelm@50945
   953
    unfolding image_is_empty
wenzelm@50945
   954
    apply (rule False)
wenzelm@50945
   955
    apply auto
wenzelm@50945
   956
    done
himmelma@35172
   957
  then guess d .. note d = this
wenzelm@50945
   958
  show ?thesis
wenzelm@50945
   959
    apply (rule that[of "d \<union> p"])
wenzelm@50945
   960
  proof -
wenzelm@50945
   961
    have *: "\<And>s f t. s \<noteq> {} \<Longrightarrow> (\<forall>i\<in>s. f i \<union> i = t) \<Longrightarrow> t = \<Inter> (f ` s) \<union> (\<Union>s)" by auto
wenzelm@50945
   962
    have *: "{a..b} = \<Inter> (\<lambda>i. \<Union>(q i - {i})) ` p \<union> \<Union>p"
wenzelm@50945
   963
      apply (rule *[OF False])
wenzelm@50945
   964
    proof
wenzelm@50945
   965
      fix i
wenzelm@50945
   966
      assume i: "i\<in>p"
wenzelm@50945
   967
      show "\<Union>(q i - {i}) \<union> i = {a..b}"
wenzelm@50945
   968
        using division_ofD(6)[OF q(1)[OF i]] using q(2)[OF i] by auto
wenzelm@50945
   969
    qed
wenzelm@50945
   970
    show "d \<union> p division_of {a..b}"
wenzelm@50945
   971
      unfolding *
wenzelm@50945
   972
      apply (rule division_disjoint_union[OF d assms(1)])
wenzelm@50945
   973
      apply (rule inter_interior_unions_intervals)
wenzelm@50945
   974
      apply (rule p open_interior ballI)+
wenzelm@50945
   975
    proof (assumption, rule)
wenzelm@50945
   976
      fix k
wenzelm@50945
   977
      assume k: "k\<in>p"
wenzelm@50945
   978
      have *: "\<And>u t s. u \<subseteq> s \<Longrightarrow> s \<inter> t = {} \<Longrightarrow> u \<inter> t = {}" by auto
wenzelm@50945
   979
      show "interior (\<Inter>(\<lambda>i. \<Union>(q i - {i})) ` p) \<inter> interior k = {}"
wenzelm@50945
   980
        apply (rule *[of _ "interior (\<Union>(q k - {k}))"])
wenzelm@50945
   981
        defer
wenzelm@50945
   982
        apply (subst Int_commute)
wenzelm@50945
   983
        apply (rule inter_interior_unions_intervals)
wenzelm@50945
   984
      proof -
wenzelm@50945
   985
        note qk=division_ofD[OF q(1)[OF k]]
wenzelm@50945
   986
        show "finite (q k - {k})" "open (interior k)"
wenzelm@50945
   987
          "\<forall>t\<in>q k - {k}. \<exists>a b. t = {a..b}" using qk by auto
wenzelm@50945
   988
        show "\<forall>t\<in>q k - {k}. interior k \<inter> interior t = {}"
wenzelm@50945
   989
          using qk(5) using q(2)[OF k] by auto
wenzelm@50945
   990
        have *: "\<And>x s. x \<in> s \<Longrightarrow> \<Inter>s \<subseteq> x" by auto
wenzelm@50945
   991
        show "interior (\<Inter>(\<lambda>i. \<Union>(q i - {i})) ` p) \<subseteq> interior (\<Union>(q k - {k}))"
wenzelm@50945
   992
          apply (rule interior_mono *)+
wenzelm@50945
   993
          using k by auto
wenzelm@50945
   994
      qed
wenzelm@50945
   995
    qed
wenzelm@50945
   996
  qed auto
wenzelm@50945
   997
qed
himmelma@35172
   998
hoelzl@37489
   999
lemma elementary_bounded[dest]: "p division_of s \<Longrightarrow> bounded (s::('a::ordered_euclidean_space) set)"
himmelma@35172
  1000
  unfolding division_of_def by(metis bounded_Union bounded_interval) 
himmelma@35172
  1001
hoelzl@37489
  1002
lemma elementary_subset_interval: "p division_of s \<Longrightarrow> \<exists>a b. s \<subseteq> {a..b::'a::ordered_euclidean_space}"
wenzelm@50945
  1003
  by (meson elementary_bounded bounded_subset_closed_interval)
wenzelm@50945
  1004
wenzelm@50945
  1005
lemma division_union_intervals_exists:
wenzelm@50945
  1006
  assumes "{a..b::'a::ordered_euclidean_space} \<noteq> {}"
wenzelm@50945
  1007
  obtains p where "(insert {a..b} p) division_of ({a..b} \<union> {c..d})"
wenzelm@50945
  1008
proof (cases "{c..d} = {}")
wenzelm@50945
  1009
  case True
wenzelm@50945
  1010
  show ?thesis
wenzelm@50945
  1011
    apply (rule that[of "{}"])
wenzelm@50945
  1012
    unfolding True
wenzelm@50945
  1013
    using assms
wenzelm@50945
  1014
    apply auto
wenzelm@50945
  1015
    done
wenzelm@50945
  1016
next
wenzelm@50945
  1017
  case False
wenzelm@50945
  1018
  note false=this
wenzelm@50945
  1019
  show ?thesis
wenzelm@50945
  1020
  proof (cases "{a..b} \<inter> {c..d} = {}")
wenzelm@50945
  1021
    case True
wenzelm@50945
  1022
    have *:"\<And>a b. {a,b} = {a} \<union> {b}" by auto
wenzelm@50945
  1023
    show ?thesis
wenzelm@50945
  1024
      apply (rule that[of "{{c..d}}"])
wenzelm@50945
  1025
      unfolding *
wenzelm@50945
  1026
      apply (rule division_disjoint_union)
wenzelm@50945
  1027
      using false True assms
wenzelm@50945
  1028
      using interior_subset
wenzelm@50945
  1029
      apply auto
wenzelm@50945
  1030
      done
wenzelm@50945
  1031
  next
wenzelm@50945
  1032
    case False
wenzelm@50945
  1033
    obtain u v where uv: "{a..b} \<inter> {c..d} = {u..v}"
wenzelm@50945
  1034
      unfolding inter_interval by auto
wenzelm@50945
  1035
    have *: "{u..v} \<subseteq> {c..d}" using uv by auto
wenzelm@50945
  1036
    guess p apply (rule partial_division_extend_1[OF * False[unfolded uv]]) .
wenzelm@50945
  1037
    note p=this division_ofD[OF this(1)]
wenzelm@50945
  1038
    have *: "{a..b} \<union> {c..d} = {a..b} \<union> \<Union>(p - {{u..v}})" "\<And>x s. insert x s = {x} \<union> s"
wenzelm@50945
  1039
      using p(8) unfolding uv[THEN sym] by auto
wenzelm@50945
  1040
    show ?thesis
wenzelm@50945
  1041
      apply (rule that[of "p - {{u..v}}"])
wenzelm@50945
  1042
      unfolding *(1)
wenzelm@50945
  1043
      apply (subst *(2))
wenzelm@50945
  1044
      apply (rule division_disjoint_union)
wenzelm@50945
  1045
      apply (rule, rule assms)
wenzelm@50945
  1046
      apply (rule division_of_subset[of p])
wenzelm@50945
  1047
      apply (rule division_of_union_self[OF p(1)])
wenzelm@50945
  1048
      defer
wenzelm@50945
  1049
      unfolding interior_inter[THEN sym]
wenzelm@50945
  1050
    proof -
wenzelm@50945
  1051
      have *: "\<And>cd p uv ab. p \<subseteq> cd \<Longrightarrow> ab \<inter> cd = uv \<Longrightarrow> ab \<inter> p = uv \<inter> p" by auto
wenzelm@50945
  1052
      have "interior ({a..b} \<inter> \<Union>(p - {{u..v}})) = interior({u..v} \<inter> \<Union>(p - {{u..v}}))" 
wenzelm@50945
  1053
        apply (rule arg_cong[of _ _ interior])
wenzelm@50945
  1054
        apply (rule *[OF _ uv])
wenzelm@50945
  1055
        using p(8)
wenzelm@50945
  1056
        apply auto
wenzelm@50945
  1057
        done
wenzelm@50945
  1058
      also have "\<dots> = {}"
wenzelm@50945
  1059
        unfolding interior_inter
wenzelm@50945
  1060
        apply (rule inter_interior_unions_intervals)
wenzelm@50945
  1061
        using p(6) p(7)[OF p(2)] p(3)
wenzelm@50945
  1062
        apply auto
wenzelm@50945
  1063
        done
wenzelm@50945
  1064
      finally show "interior ({a..b} \<inter> \<Union>(p - {{u..v}})) = {}" .
wenzelm@50945
  1065
    qed auto
wenzelm@50945
  1066
  qed
wenzelm@50945
  1067
qed
himmelma@35172
  1068
himmelma@35172
  1069
lemma division_of_unions: assumes "finite f"  "\<And>p. p\<in>f \<Longrightarrow> p division_of (\<Union>p)"
himmelma@35172
  1070
  "\<And>k1 k2. \<lbrakk>k1 \<in> \<Union>f; k2 \<in> \<Union>f; k1 \<noteq> k2\<rbrakk> \<Longrightarrow> interior k1 \<inter> interior k2 = {}"
himmelma@35172
  1071
  shows "\<Union>f division_of \<Union>\<Union>f" apply(rule division_ofI) prefer 5 apply(rule assms(3)|assumption)+
himmelma@35172
  1072
  apply(rule finite_Union assms(1))+ prefer 3 apply(erule UnionE) apply(rule_tac s=X in division_ofD(3)[OF assms(2)])
himmelma@35172
  1073
  using division_ofD[OF assms(2)] by auto
himmelma@35172
  1074
  
himmelma@35172
  1075
lemma elementary_union_interval: assumes "p division_of \<Union>p"
hoelzl@37489
  1076
  obtains q where "q division_of ({a..b::'a::ordered_euclidean_space} \<union> \<Union>p)" proof-
himmelma@35172
  1077
  note assm=division_ofD[OF assms]
himmelma@35172
  1078
  have lem1:"\<And>f s. \<Union>\<Union> (f ` s) = \<Union>(\<lambda>x.\<Union>(f x)) ` s" by auto
himmelma@35172
  1079
  have lem2:"\<And>f s. f \<noteq> {} \<Longrightarrow> \<Union>{s \<union> t |t. t \<in> f} = s \<union> \<Union>f" by auto
himmelma@35172
  1080
{ presume "p={} \<Longrightarrow> thesis" "{a..b} = {} \<Longrightarrow> thesis" "{a..b} \<noteq> {} \<Longrightarrow> interior {a..b} = {} \<Longrightarrow> thesis"
himmelma@35172
  1081
    "p\<noteq>{} \<Longrightarrow> interior {a..b}\<noteq>{} \<Longrightarrow> {a..b} \<noteq> {} \<Longrightarrow> thesis"
himmelma@35172
  1082
  thus thesis by auto
himmelma@35172
  1083
next assume as:"p={}" guess p apply(rule elementary_interval[of a b]) .
himmelma@35172
  1084
  thus thesis apply(rule_tac that[of p]) unfolding as by auto 
himmelma@35172
  1085
next assume as:"{a..b}={}" show thesis apply(rule that) unfolding as using assms by auto
himmelma@35172
  1086
next assume as:"interior {a..b} = {}" "{a..b} \<noteq> {}"
himmelma@35172
  1087
  show thesis apply(rule that[of "insert {a..b} p"],rule division_ofI)
himmelma@35172
  1088
    unfolding finite_insert apply(rule assm(1)) unfolding Union_insert  
nipkow@44890
  1089
    using assm(2-4) as apply- by(fastforce dest: assm(5))+
himmelma@35172
  1090
next assume as:"p \<noteq> {}" "interior {a..b} \<noteq> {}" "{a..b}\<noteq>{}"
himmelma@35172
  1091
  have "\<forall>k\<in>p. \<exists>q. (insert {a..b} q) division_of ({a..b} \<union> k)" proof case goal1
himmelma@35172
  1092
    from assm(4)[OF this] guess c .. then guess d ..
himmelma@35172
  1093
    thus ?case apply-apply(rule division_union_intervals_exists[OF as(3),of c d]) by auto
himmelma@35172
  1094
  qed from bchoice[OF this] guess q .. note q=division_ofD[OF this[rule_format]]
himmelma@35172
  1095
  let ?D = "\<Union>{insert {a..b} (q k) | k. k \<in> p}"
himmelma@35172
  1096
  show thesis apply(rule that[of "?D"]) proof(rule division_ofI)
himmelma@35172
  1097
    have *:"{insert {a..b} (q k) |k. k \<in> p} = (\<lambda>k. insert {a..b} (q k)) ` p" by auto
himmelma@35172
  1098
    show "finite ?D" apply(rule finite_Union) unfolding * apply(rule finite_imageI) using assm(1) q(1) by auto
himmelma@35172
  1099
    show "\<Union>?D = {a..b} \<union> \<Union>p" unfolding * lem1 unfolding lem2[OF as(1), of "{a..b}",THEN sym]
himmelma@35172
  1100
      using q(6) by auto
himmelma@35172
  1101
    fix k assume k:"k\<in>?D" thus " k \<subseteq> {a..b} \<union> \<Union>p" using q(2) by auto
himmelma@35172
  1102
    show "k \<noteq> {}" using q(3) k by auto show "\<exists>a b. k = {a..b}" using q(4) k by auto
himmelma@35172
  1103
    fix k' assume k':"k'\<in>?D" "k\<noteq>k'"
himmelma@35172
  1104
    obtain x  where x: "k \<in>insert {a..b} (q x)"  "x\<in>p"  using k  by auto
himmelma@35172
  1105
    obtain x' where x':"k'\<in>insert {a..b} (q x')" "x'\<in>p" using k' by auto
himmelma@35172
  1106
    show "interior k \<inter> interior k' = {}" proof(cases "x=x'")
himmelma@35172
  1107
      case True show ?thesis apply(rule q(5)) using x x' k' unfolding True by auto
himmelma@35172
  1108
    next case False 
himmelma@35172
  1109
      { presume "k = {a..b} \<Longrightarrow> ?thesis" "k' = {a..b} \<Longrightarrow> ?thesis" 
himmelma@35172
  1110
        "k \<noteq> {a..b} \<Longrightarrow> k' \<noteq> {a..b} \<Longrightarrow> ?thesis"
himmelma@35172
  1111
        thus ?thesis by auto }
himmelma@35172
  1112
      { assume as':"k  = {a..b}" show ?thesis apply(rule q(5)) using x' k'(2) unfolding as' by auto }
himmelma@35172
  1113
      { assume as':"k' = {a..b}" show ?thesis apply(rule q(5)) using x  k'(2) unfolding as' by auto }
himmelma@35172
  1114
      assume as':"k \<noteq> {a..b}" "k' \<noteq> {a..b}"
himmelma@35172
  1115
      guess c using q(4)[OF x(2,1)] .. then guess d .. note c_d=this
himmelma@35172
  1116
      have "interior k  \<inter> interior {a..b} = {}" apply(rule q(5)) using x  k'(2) using as' by auto
himmelma@35172
  1117
      hence "interior k \<subseteq> interior x" apply-
himmelma@35172
  1118
        apply(rule interior_subset_union_intervals[OF c_d _ as(2) q(2)[OF x(2,1)]]) by auto moreover
himmelma@35172
  1119
      guess c using q(4)[OF x'(2,1)] .. then guess d .. note c_d=this
himmelma@35172
  1120
      have "interior k' \<inter> interior {a..b} = {}" apply(rule q(5)) using x' k'(2) using as' by auto
himmelma@35172
  1121
      hence "interior k' \<subseteq> interior x'" apply-
himmelma@35172
  1122
        apply(rule interior_subset_union_intervals[OF c_d _ as(2) q(2)[OF x'(2,1)]]) by auto
himmelma@35172
  1123
      ultimately show ?thesis using assm(5)[OF x(2) x'(2) False] by auto
himmelma@35172
  1124
    qed qed } qed
himmelma@35172
  1125
himmelma@35172
  1126
lemma elementary_unions_intervals:
hoelzl@37489
  1127
  assumes "finite f" "\<And>s. s \<in> f \<Longrightarrow> \<exists>a b. s = {a..b::'a::ordered_euclidean_space}"
himmelma@35172
  1128
  obtains p where "p division_of (\<Union>f)" proof-
himmelma@35172
  1129
  have "\<exists>p. p division_of (\<Union>f)" proof(induct_tac f rule:finite_subset_induct) 
himmelma@35172
  1130
    show "\<exists>p. p division_of \<Union>{}" using elementary_empty by auto
himmelma@35172
  1131
    fix x F assume as:"finite F" "x \<notin> F" "\<exists>p. p division_of \<Union>F" "x\<in>f"
himmelma@35172
  1132
    from this(3) guess p .. note p=this
himmelma@35172
  1133
    from assms(2)[OF as(4)] guess a .. then guess b .. note ab=this
himmelma@35172
  1134
    have *:"\<Union>F = \<Union>p" using division_ofD[OF p] by auto
himmelma@35172
  1135
    show "\<exists>p. p division_of \<Union>insert x F" using elementary_union_interval[OF p[unfolded *], of a b]
himmelma@35172
  1136
      unfolding Union_insert ab * by auto
himmelma@35172
  1137
  qed(insert assms,auto) thus ?thesis apply-apply(erule exE,rule that) by auto qed
himmelma@35172
  1138
hoelzl@37489
  1139
lemma elementary_union: assumes "ps division_of s" "pt division_of (t::('a::ordered_euclidean_space) set)"
himmelma@35172
  1140
  obtains p where "p division_of (s \<union> t)"
himmelma@35172
  1141
proof- have "s \<union> t = \<Union>ps \<union> \<Union>pt" using assms unfolding division_of_def by auto
himmelma@35172
  1142
  hence *:"\<Union>(ps \<union> pt) = s \<union> t" by auto
himmelma@35172
  1143
  show ?thesis apply-apply(rule elementary_unions_intervals[of "ps\<union>pt"])
himmelma@35172
  1144
    unfolding * prefer 3 apply(rule_tac p=p in that)
himmelma@35172
  1145
    using assms[unfolded division_of_def] by auto qed
himmelma@35172
  1146
hoelzl@37489
  1147
lemma partial_division_extend: fixes t::"('a::ordered_euclidean_space) set"
himmelma@35172
  1148
  assumes "p division_of s" "q division_of t" "s \<subseteq> t"
himmelma@35172
  1149
  obtains r where "p \<subseteq> r" "r division_of t" proof-
himmelma@35172
  1150
  note divp = division_ofD[OF assms(1)] and divq = division_ofD[OF assms(2)]
himmelma@35172
  1151
  obtain a b where ab:"t\<subseteq>{a..b}" using elementary_subset_interval[OF assms(2)] by auto
himmelma@35172
  1152
  guess r1 apply(rule partial_division_extend_interval) apply(rule assms(1)[unfolded divp(6)[THEN sym]])
himmelma@35172
  1153
    apply(rule subset_trans) by(rule ab assms[unfolded divp(6)[THEN sym]])+  note r1 = this division_ofD[OF this(2)]
himmelma@35172
  1154
  guess p' apply(rule elementary_unions_intervals[of "r1 - p"]) using r1(3,6) by auto 
himmelma@35172
  1155
  then obtain r2 where r2:"r2 division_of (\<Union>(r1 - p)) \<inter> (\<Union>q)" 
himmelma@35172
  1156
    apply- apply(drule elementary_inter[OF _ assms(2)[unfolded divq(6)[THEN sym]]]) by auto
himmelma@35172
  1157
  { fix x assume x:"x\<in>t" "x\<notin>s"
himmelma@35172
  1158
    hence "x\<in>\<Union>r1" unfolding r1 using ab by auto
himmelma@35172
  1159
    then guess r unfolding Union_iff .. note r=this moreover
himmelma@35172
  1160
    have "r \<notin> p" proof assume "r\<in>p" hence "x\<in>s" using divp(2) r by auto
himmelma@35172
  1161
      thus False using x by auto qed
himmelma@35172
  1162
    ultimately have "x\<in>\<Union>(r1 - p)" by auto }
himmelma@35172
  1163
  hence *:"t = \<Union>p \<union> (\<Union>(r1 - p) \<inter> \<Union>q)" unfolding divp divq using assms(3) by auto
himmelma@35172
  1164
  show ?thesis apply(rule that[of "p \<union> r2"]) unfolding * defer apply(rule division_disjoint_union)
himmelma@35172
  1165
    unfolding divp(6) apply(rule assms r2)+
himmelma@35172
  1166
  proof- have "interior s \<inter> interior (\<Union>(r1-p)) = {}"
himmelma@35172
  1167
    proof(rule inter_interior_unions_intervals)
himmelma@35172
  1168
      show "finite (r1 - p)" "open (interior s)" "\<forall>t\<in>r1-p. \<exists>a b. t = {a..b}" using r1 by auto
himmelma@35172
  1169
      have *:"\<And>s. (\<And>x. x \<in> s \<Longrightarrow> False) \<Longrightarrow> s = {}" by auto
himmelma@35172
  1170
      show "\<forall>t\<in>r1-p. interior s \<inter> interior t = {}" proof(rule)
himmelma@35172
  1171
        fix m x assume as:"m\<in>r1-p"
himmelma@35172
  1172
        have "interior m \<inter> interior (\<Union>p) = {}" proof(rule inter_interior_unions_intervals)
himmelma@35172
  1173
          show "finite p" "open (interior m)" "\<forall>t\<in>p. \<exists>a b. t = {a..b}" using divp by auto
himmelma@35172
  1174
          show "\<forall>t\<in>p. interior m \<inter> interior t = {}" apply(rule, rule r1(7)) using as using r1 by auto
himmelma@35172
  1175
        qed thus "interior s \<inter> interior m = {}" unfolding divp by auto
himmelma@35172
  1176
      qed qed        
himmelma@35172
  1177
    thus "interior s \<inter> interior (\<Union>(r1-p) \<inter> (\<Union>q)) = {}" using interior_subset by auto
himmelma@35172
  1178
  qed auto qed
himmelma@35172
  1179
himmelma@35172
  1180
subsection {* Tagged (partial) divisions. *}
himmelma@35172
  1181
himmelma@35172
  1182
definition tagged_partial_division_of (infixr "tagged'_partial'_division'_of" 40) where
himmelma@35172
  1183
  "(s tagged_partial_division_of i) \<equiv>
himmelma@35172
  1184
        finite s \<and>
himmelma@35172
  1185
        (\<forall>x k. (x,k) \<in> s \<longrightarrow> x \<in> k \<and> k \<subseteq> i \<and> (\<exists>a b. k = {a..b})) \<and>
himmelma@35172
  1186
        (\<forall>x1 k1 x2 k2. (x1,k1) \<in> s \<and> (x2,k2) \<in> s \<and> ((x1,k1) \<noteq> (x2,k2))
himmelma@35172
  1187
                       \<longrightarrow> (interior(k1) \<inter> interior(k2) = {}))"
himmelma@35172
  1188
himmelma@35172
  1189
lemma tagged_partial_division_ofD[dest]: assumes "s tagged_partial_division_of i"
himmelma@35172
  1190
  shows "finite s" "\<And>x k. (x,k) \<in> s \<Longrightarrow> x \<in> k" "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> i"
himmelma@35172
  1191
  "\<And>x k. (x,k) \<in> s \<Longrightarrow> \<exists>a b. k = {a..b}"
himmelma@35172
  1192
  "\<And>x1 k1 x2 k2. (x1,k1) \<in> s \<Longrightarrow> (x2,k2) \<in> s \<Longrightarrow> (x1,k1) \<noteq> (x2,k2) \<Longrightarrow> interior(k1) \<inter> interior(k2) = {}"
himmelma@35172
  1193
  using assms unfolding tagged_partial_division_of_def  apply- by blast+ 
himmelma@35172
  1194
himmelma@35172
  1195
definition tagged_division_of (infixr "tagged'_division'_of" 40) where
himmelma@35172
  1196
  "(s tagged_division_of i) \<equiv>
himmelma@35172
  1197
        (s tagged_partial_division_of i) \<and> (\<Union>{k. \<exists>x. (x,k) \<in> s} = i)"
himmelma@35172
  1198
huffman@44167
  1199
lemma tagged_division_of_finite: "s tagged_division_of i \<Longrightarrow> finite s"
himmelma@35172
  1200
  unfolding tagged_division_of_def tagged_partial_division_of_def by auto
himmelma@35172
  1201
himmelma@35172
  1202
lemma tagged_division_of:
himmelma@35172
  1203
 "(s tagged_division_of i) \<longleftrightarrow>
himmelma@35172
  1204
        finite s \<and>
himmelma@35172
  1205
        (\<forall>x k. (x,k) \<in> s
himmelma@35172
  1206
               \<longrightarrow> x \<in> k \<and> k \<subseteq> i \<and> (\<exists>a b. k = {a..b})) \<and>
himmelma@35172
  1207
        (\<forall>x1 k1 x2 k2. (x1,k1) \<in> s \<and> (x2,k2) \<in> s \<and> ~((x1,k1) = (x2,k2))
himmelma@35172
  1208
                       \<longrightarrow> (interior(k1) \<inter> interior(k2) = {})) \<and>
himmelma@35172
  1209
        (\<Union>{k. \<exists>x. (x,k) \<in> s} = i)"
himmelma@35172
  1210
  unfolding tagged_division_of_def tagged_partial_division_of_def by auto
himmelma@35172
  1211
himmelma@35172
  1212
lemma tagged_division_ofI: assumes
himmelma@35172
  1213
  "finite s" "\<And>x k. (x,k) \<in> s \<Longrightarrow> x \<in> k" "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> i"  "\<And>x k. (x,k) \<in> s \<Longrightarrow> \<exists>a b. k = {a..b}"
himmelma@35172
  1214
  "\<And>x1 k1 x2 k2. (x1,k1) \<in> s \<Longrightarrow> (x2,k2) \<in> s \<Longrightarrow> ~((x1,k1) = (x2,k2)) \<Longrightarrow> (interior(k1) \<inter> interior(k2) = {})"
himmelma@35172
  1215
  "(\<Union>{k. \<exists>x. (x,k) \<in> s} = i)"
himmelma@35172
  1216
  shows "s tagged_division_of i"
himmelma@35172
  1217
  unfolding tagged_division_of apply(rule) defer apply rule
himmelma@35172
  1218
  apply(rule allI impI conjI assms)+ apply assumption
himmelma@35172
  1219
  apply(rule, rule assms, assumption) apply(rule assms, assumption)
himmelma@35172
  1220
  using assms(1,5-) apply- by blast+
himmelma@35172
  1221
himmelma@35172
  1222
lemma tagged_division_ofD[dest]: assumes "s tagged_division_of i"
himmelma@35172
  1223
  shows "finite s" "\<And>x k. (x,k) \<in> s \<Longrightarrow> x \<in> k" "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> i"  "\<And>x k. (x,k) \<in> s \<Longrightarrow> \<exists>a b. k = {a..b}"
himmelma@35172
  1224
  "\<And>x1 k1 x2 k2. (x1,k1) \<in> s \<Longrightarrow> (x2,k2) \<in> s \<Longrightarrow> ~((x1,k1) = (x2,k2)) \<Longrightarrow> (interior(k1) \<inter> interior(k2) = {})"
himmelma@35172
  1225
  "(\<Union>{k. \<exists>x. (x,k) \<in> s} = i)" using assms unfolding tagged_division_of apply- by blast+
himmelma@35172
  1226
himmelma@35172
  1227
lemma division_of_tagged_division: assumes"s tagged_division_of i"  shows "(snd ` s) division_of i"
himmelma@35172
  1228
proof(rule division_ofI) note assm=tagged_division_ofD[OF assms]
himmelma@35172
  1229
  show "\<Union>snd ` s = i" "finite (snd ` s)" using assm by auto
himmelma@35172
  1230
  fix k assume k:"k \<in> snd ` s" then obtain xk where xk:"(xk, k) \<in> s" by auto
nipkow@44890
  1231
  thus  "k \<subseteq> i" "k \<noteq> {}" "\<exists>a b. k = {a..b}" using assm apply- by fastforce+
himmelma@35172
  1232
  fix k' assume k':"k' \<in> snd ` s" "k \<noteq> k'" from this(1) obtain xk' where xk':"(xk', k') \<in> s" by auto
himmelma@35172
  1233
  thus "interior k \<inter> interior k' = {}" apply-apply(rule assm(5)) apply(rule xk xk')+ using k' by auto
himmelma@35172
  1234
qed
himmelma@35172
  1235
himmelma@35172
  1236
lemma partial_division_of_tagged_division: assumes "s tagged_partial_division_of i"
himmelma@35172
  1237
  shows "(snd ` s) division_of \<Union>(snd ` s)"
himmelma@35172
  1238
proof(rule division_ofI) note assm=tagged_partial_division_ofD[OF assms]
himmelma@35172
  1239
  show "finite (snd ` s)" "\<Union>snd ` s = \<Union>snd ` s" using assm by auto
himmelma@35172
  1240
  fix k assume k:"k \<in> snd ` s" then obtain xk where xk:"(xk, k) \<in> s" by auto
himmelma@35172
  1241
  thus "k\<noteq>{}" "\<exists>a b. k = {a..b}" "k \<subseteq> \<Union>snd ` s" using assm by auto
himmelma@35172
  1242
  fix k' assume k':"k' \<in> snd ` s" "k \<noteq> k'" from this(1) obtain xk' where xk':"(xk', k') \<in> s" by auto
himmelma@35172
  1243
  thus "interior k \<inter> interior k' = {}" apply-apply(rule assm(5)) apply(rule xk xk')+ using k' by auto
himmelma@35172
  1244
qed
himmelma@35172
  1245
himmelma@35172
  1246
lemma tagged_partial_division_subset: assumes "s tagged_partial_division_of i" "t \<subseteq> s"
himmelma@35172
  1247
  shows "t tagged_partial_division_of i"
himmelma@35172
  1248
  using assms unfolding tagged_partial_division_of_def using finite_subset[OF assms(2)] by blast
himmelma@35172
  1249
hoelzl@37489
  1250
lemma setsum_over_tagged_division_lemma: fixes d::"('m::ordered_euclidean_space) set \<Rightarrow> 'a::real_normed_vector"
himmelma@35172
  1251
  assumes "p tagged_division_of i" "\<And>u v. {u..v} \<noteq> {} \<Longrightarrow> content {u..v} = 0 \<Longrightarrow> d {u..v} = 0"
himmelma@35172
  1252
  shows "setsum (\<lambda>(x,k). d k) p = setsum d (snd ` p)"
himmelma@35172
  1253
proof- note assm=tagged_division_ofD[OF assms(1)]
himmelma@35172
  1254
  have *:"(\<lambda>(x,k). d k) = d \<circ> snd" unfolding o_def apply(rule ext) by auto
himmelma@35172
  1255
  show ?thesis unfolding * apply(subst eq_commute) proof(rule setsum_reindex_nonzero)
himmelma@35172
  1256
    show "finite p" using assm by auto
himmelma@35172
  1257
    fix x y assume as:"x\<in>p" "y\<in>p" "x\<noteq>y" "snd x = snd y" 
himmelma@35172
  1258
    obtain a b where ab:"snd x = {a..b}" using assm(4)[of "fst x" "snd x"] as(1) by auto
himmelma@35172
  1259
    have "(fst x, snd y) \<in> p" "(fst x, snd y) \<noteq> y" unfolding as(4)[THEN sym] using as(1-3) by auto
himmelma@35172
  1260
    hence "interior (snd x) \<inter> interior (snd y) = {}" apply-apply(rule assm(5)[of "fst x" _ "fst y"]) using as by auto 
himmelma@35172
  1261
    hence "content {a..b} = 0" unfolding as(4)[THEN sym] ab content_eq_0_interior by auto
himmelma@35172
  1262
    hence "d {a..b} = 0" apply-apply(rule assms(2)) using assm(2)[of "fst x" "snd x"] as(1) unfolding ab[THEN sym] by auto
himmelma@35172
  1263
    thus "d (snd x) = 0" unfolding ab by auto qed qed
himmelma@35172
  1264
himmelma@35172
  1265
lemma tag_in_interval: "p tagged_division_of i \<Longrightarrow> (x,k) \<in> p \<Longrightarrow> x \<in> i" by auto
himmelma@35172
  1266
himmelma@35172
  1267
lemma tagged_division_of_empty: "{} tagged_division_of {}"
himmelma@35172
  1268
  unfolding tagged_division_of by auto
himmelma@35172
  1269
himmelma@35172
  1270
lemma tagged_partial_division_of_trivial[simp]:
himmelma@35172
  1271
 "p tagged_partial_division_of {} \<longleftrightarrow> p = {}"
himmelma@35172
  1272
  unfolding tagged_partial_division_of_def by auto
himmelma@35172
  1273
himmelma@35172
  1274
lemma tagged_division_of_trivial[simp]:
himmelma@35172
  1275
 "p tagged_division_of {} \<longleftrightarrow> p = {}"
himmelma@35172
  1276
  unfolding tagged_division_of by auto
himmelma@35172
  1277
himmelma@35172
  1278
lemma tagged_division_of_self:
himmelma@35172
  1279
 "x \<in> {a..b} \<Longrightarrow> {(x,{a..b})} tagged_division_of {a..b}"
himmelma@35172
  1280
  apply(rule tagged_division_ofI) by auto
himmelma@35172
  1281
himmelma@35172
  1282
lemma tagged_division_union:
himmelma@35172
  1283
  assumes "p1 tagged_division_of s1"  "p2 tagged_division_of s2" "interior s1 \<inter> interior s2 = {}"
himmelma@35172
  1284
  shows "(p1 \<union> p2) tagged_division_of (s1 \<union> s2)"
himmelma@35172
  1285
proof(rule tagged_division_ofI) note p1=tagged_division_ofD[OF assms(1)] and p2=tagged_division_ofD[OF assms(2)]
himmelma@35172
  1286
  show "finite (p1 \<union> p2)" using p1(1) p2(1) by auto
himmelma@35172
  1287
  show "\<Union>{k. \<exists>x. (x, k) \<in> p1 \<union> p2} = s1 \<union> s2" using p1(6) p2(6) by blast
himmelma@35172
  1288
  fix x k assume xk:"(x,k)\<in>p1\<union>p2" show "x\<in>k" "\<exists>a b. k = {a..b}" using xk p1(2,4) p2(2,4) by auto
himmelma@35172
  1289
  show "k\<subseteq>s1\<union>s2" using xk p1(3) p2(3) by blast
himmelma@35172
  1290
  fix x' k' assume xk':"(x',k')\<in>p1\<union>p2" "(x,k) \<noteq> (x',k')"
huffman@44522
  1291
  have *:"\<And>a b. a\<subseteq> s1 \<Longrightarrow> b\<subseteq> s2 \<Longrightarrow> interior a \<inter> interior b = {}" using assms(3) interior_mono by blast
himmelma@35172
  1292
  show "interior k \<inter> interior k' = {}" apply(cases "(x,k)\<in>p1", case_tac[!] "(x',k')\<in>p1")
himmelma@35172
  1293
    apply(rule p1(5)) prefer 4 apply(rule *) prefer 6 apply(subst Int_commute,rule *) prefer 8 apply(rule p2(5))
himmelma@35172
  1294
    using p1(3) p2(3) using xk xk' by auto qed 
himmelma@35172
  1295
himmelma@35172
  1296
lemma tagged_division_unions:
himmelma@35172
  1297
  assumes "finite iset" "\<forall>i\<in>iset. (pfn(i) tagged_division_of i)"
himmelma@35172
  1298
  "\<forall>i1 \<in> iset. \<forall>i2 \<in> iset. ~(i1 = i2) \<longrightarrow> (interior(i1) \<inter> interior(i2) = {})"
himmelma@35172
  1299
  shows "\<Union>(pfn ` iset) tagged_division_of (\<Union>iset)"
himmelma@35172
  1300
proof(rule tagged_division_ofI)
himmelma@35172
  1301
  note assm = tagged_division_ofD[OF assms(2)[rule_format]]
himmelma@35172
  1302
  show "finite (\<Union>pfn ` iset)" apply(rule finite_Union) using assms by auto
himmelma@35172
  1303
  have "\<Union>{k. \<exists>x. (x, k) \<in> \<Union>pfn ` iset} = \<Union>(\<lambda>i. \<Union>{k. \<exists>x. (x, k) \<in> pfn i}) ` iset" by blast 
himmelma@35172
  1304
  also have "\<dots> = \<Union>iset" using assm(6) by auto
himmelma@35172
  1305
  finally show "\<Union>{k. \<exists>x. (x, k) \<in> \<Union>pfn ` iset} = \<Union>iset" . 
himmelma@35172
  1306
  fix x k assume xk:"(x,k)\<in>\<Union>pfn ` iset" then obtain i where i:"i \<in> iset" "(x, k) \<in> pfn i" by auto
himmelma@35172
  1307
  show "x\<in>k" "\<exists>a b. k = {a..b}" "k \<subseteq> \<Union>iset" using assm(2-4)[OF i] using i(1) by auto
himmelma@35172
  1308
  fix x' k' assume xk':"(x',k')\<in>\<Union>pfn ` iset" "(x, k) \<noteq> (x', k')" then obtain i' where i':"i' \<in> iset" "(x', k') \<in> pfn i'" by auto
himmelma@35172
  1309
  have *:"\<And>a b. i\<noteq>i' \<Longrightarrow> a\<subseteq> i \<Longrightarrow> b\<subseteq> i' \<Longrightarrow> interior a \<inter> interior b = {}" using i(1) i'(1)
huffman@44522
  1310
    using assms(3)[rule_format] interior_mono by blast
himmelma@35172
  1311
  show "interior k \<inter> interior k' = {}" apply(cases "i=i'")
himmelma@35172
  1312
    using assm(5)[OF i _ xk'(2)]  i'(2) using assm(3)[OF i] assm(3)[OF i'] defer apply-apply(rule *) by auto
himmelma@35172
  1313
qed
himmelma@35172
  1314
himmelma@35172
  1315
lemma tagged_partial_division_of_union_self:
himmelma@35172
  1316
  assumes "p tagged_partial_division_of s" shows "p tagged_division_of (\<Union>(snd ` p))"
himmelma@35172
  1317
  apply(rule tagged_division_ofI) using tagged_partial_division_ofD[OF assms] by auto
himmelma@35172
  1318
himmelma@35172
  1319
lemma tagged_division_of_union_self: assumes "p tagged_division_of s"
himmelma@35172
  1320
  shows "p tagged_division_of (\<Union>(snd ` p))"
himmelma@35172
  1321
  apply(rule tagged_division_ofI) using tagged_division_ofD[OF assms] by auto
himmelma@35172
  1322
himmelma@35172
  1323
subsection {* Fine-ness of a partition w.r.t. a gauge. *}
himmelma@35172
  1324
himmelma@35172
  1325
definition fine (infixr "fine" 46) where
himmelma@35172
  1326
  "d fine s \<longleftrightarrow> (\<forall>(x,k) \<in> s. k \<subseteq> d(x))"
himmelma@35172
  1327
himmelma@35172
  1328
lemma fineI: assumes "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> d x"
himmelma@35172
  1329
  shows "d fine s" using assms unfolding fine_def by auto
himmelma@35172
  1330
himmelma@35172
  1331
lemma fineD[dest]: assumes "d fine s"
himmelma@35172
  1332
  shows "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> d x" using assms unfolding fine_def by auto
himmelma@35172
  1333
himmelma@35172
  1334
lemma fine_inter: "(\<lambda>x. d1 x \<inter> d2 x) fine p \<longleftrightarrow> d1 fine p \<and> d2 fine p"
himmelma@35172
  1335
  unfolding fine_def by auto
himmelma@35172
  1336
himmelma@35172
  1337
lemma fine_inters:
himmelma@35172
  1338
 "(\<lambda>x. \<Inter> {f d x | d.  d \<in> s}) fine p \<longleftrightarrow> (\<forall>d\<in>s. (f d) fine p)"
himmelma@35172
  1339
  unfolding fine_def by blast
himmelma@35172
  1340
himmelma@35172
  1341
lemma fine_union:
himmelma@35172
  1342
  "d fine p1 \<Longrightarrow> d fine p2 \<Longrightarrow> d fine (p1 \<union> p2)"
himmelma@35172
  1343
  unfolding fine_def by blast
himmelma@35172
  1344
himmelma@35172
  1345
lemma fine_unions:"(\<And>p. p \<in> ps \<Longrightarrow> d fine p) \<Longrightarrow> d fine (\<Union>ps)"
himmelma@35172
  1346
  unfolding fine_def by auto
himmelma@35172
  1347
himmelma@35172
  1348
lemma fine_subset:  "p \<subseteq> q \<Longrightarrow> d fine q \<Longrightarrow> d fine p"
himmelma@35172
  1349
  unfolding fine_def by blast
himmelma@35172
  1350
himmelma@35172
  1351
subsection {* Gauge integral. Define on compact intervals first, then use a limit. *}
himmelma@35172
  1352
himmelma@35172
  1353
definition has_integral_compact_interval (infixr "has'_integral'_compact'_interval" 46) where
himmelma@35172
  1354
  "(f has_integral_compact_interval y) i \<equiv>
himmelma@35172
  1355
        (\<forall>e>0. \<exists>d. gauge d \<and>
himmelma@35172
  1356
          (\<forall>p. p tagged_division_of i \<and> d fine p
himmelma@35172
  1357
                        \<longrightarrow> norm(setsum (\<lambda>(x,k). content k *\<^sub>R f x) p - y) < e))"
himmelma@35172
  1358
himmelma@35172
  1359
definition has_integral (infixr "has'_integral" 46) where 
hoelzl@37489
  1360
"((f::('n::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector)) has_integral y) i \<equiv>
himmelma@35172
  1361
        if (\<exists>a b. i = {a..b}) then (f has_integral_compact_interval y) i
himmelma@35172
  1362
        else (\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b}
himmelma@35172
  1363
              \<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> i then f x else 0) has_integral_compact_interval z) {a..b} \<and>
himmelma@35172
  1364
                                       norm(z - y) < e))"
himmelma@35172
  1365
himmelma@35172
  1366
lemma has_integral:
himmelma@35172
  1367
 "(f has_integral y) ({a..b}) \<longleftrightarrow>
himmelma@35172
  1368
        (\<forall>e>0. \<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p
himmelma@35172
  1369
                        \<longrightarrow> norm(setsum (\<lambda>(x,k). content(k) *\<^sub>R f x) p - y) < e))"
himmelma@35172
  1370
  unfolding has_integral_def has_integral_compact_interval_def by auto
himmelma@35172
  1371
himmelma@35172
  1372
lemma has_integralD[dest]: assumes
himmelma@35172
  1373
 "(f has_integral y) ({a..b})" "e>0"
himmelma@35172
  1374
  obtains d where "gauge d" "\<And>p. p tagged_division_of {a..b} \<Longrightarrow> d fine p
himmelma@35172
  1375
                        \<Longrightarrow> norm(setsum (\<lambda>(x,k). content(k) *\<^sub>R f(x)) p - y) < e"
himmelma@35172
  1376
  using assms unfolding has_integral by auto
himmelma@35172
  1377
himmelma@35172
  1378
lemma has_integral_alt:
himmelma@35172
  1379
 "(f has_integral y) i \<longleftrightarrow>
himmelma@35172
  1380
      (if (\<exists>a b. i = {a..b}) then (f has_integral y) i
himmelma@35172
  1381
       else (\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b}
himmelma@35172
  1382
                               \<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> i then f(x) else 0)
himmelma@35172
  1383
                                        has_integral z) ({a..b}) \<and>
himmelma@35172
  1384
                                       norm(z - y) < e)))"
himmelma@35172
  1385
  unfolding has_integral unfolding has_integral_compact_interval_def has_integral_def by auto
himmelma@35172
  1386
himmelma@35172
  1387
lemma has_integral_altD:
himmelma@35172
  1388
  assumes "(f has_integral y) i" "\<not> (\<exists>a b. i = {a..b})" "e>0"
himmelma@35172
  1389
  obtains B where "B>0" "\<forall>a b. ball 0 B \<subseteq> {a..b}\<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> i then f(x) else 0) has_integral z) ({a..b}) \<and> norm(z - y) < e)"
himmelma@35172
  1390
  using assms unfolding has_integral unfolding has_integral_compact_interval_def has_integral_def by auto
himmelma@35172
  1391
himmelma@35172
  1392
definition integrable_on (infixr "integrable'_on" 46) where
himmelma@35172
  1393
  "(f integrable_on i) \<equiv> \<exists>y. (f has_integral y) i"
himmelma@35172
  1394
himmelma@35172
  1395
definition "integral i f \<equiv> SOME y. (f has_integral y) i"
himmelma@35172
  1396
himmelma@35172
  1397
lemma integrable_integral[dest]:
himmelma@35172
  1398
 "f integrable_on i \<Longrightarrow> (f has_integral (integral i f)) i"
himmelma@35172
  1399
  unfolding integrable_on_def integral_def by(rule someI_ex)
himmelma@35172
  1400
himmelma@35172
  1401
lemma has_integral_integrable[intro]: "(f has_integral i) s \<Longrightarrow> f integrable_on s"
himmelma@35172
  1402
  unfolding integrable_on_def by auto
himmelma@35172
  1403
himmelma@35172
  1404
lemma has_integral_integral:"f integrable_on s \<longleftrightarrow> (f has_integral (integral s f)) s"
himmelma@35172
  1405
  by auto
himmelma@35172
  1406
himmelma@35172
  1407
lemma setsum_content_null:
himmelma@35172
  1408
  assumes "content({a..b}) = 0" "p tagged_division_of {a..b}"
himmelma@35172
  1409
  shows "setsum (\<lambda>(x,k). content k *\<^sub>R f x) p = (0::'a::real_normed_vector)"
himmelma@35172
  1410
proof(rule setsum_0',rule) fix y assume y:"y\<in>p"
himmelma@35172
  1411
  obtain x k where xk:"y = (x,k)" using surj_pair[of y] by blast
himmelma@35172
  1412
  note assm = tagged_division_ofD(3-4)[OF assms(2) y[unfolded xk]]
himmelma@35172
  1413
  from this(2) guess c .. then guess d .. note c_d=this
himmelma@35172
  1414
  have "(\<lambda>(x, k). content k *\<^sub>R f x) y = content k *\<^sub>R f x" unfolding xk by auto
himmelma@35172
  1415
  also have "\<dots> = 0" using content_subset[OF assm(1)[unfolded c_d]] content_pos_le[of c d]
himmelma@35172
  1416
    unfolding assms(1) c_d by auto
himmelma@35172
  1417
  finally show "(\<lambda>(x, k). content k *\<^sub>R f x) y = 0" .
himmelma@35172
  1418
qed
himmelma@35172
  1419
himmelma@35172
  1420
subsection {* Some basic combining lemmas. *}
himmelma@35172
  1421
himmelma@35172
  1422
lemma tagged_division_unions_exists:
himmelma@35172
  1423
  assumes "finite iset" "\<forall>i \<in> iset. \<exists>p. p tagged_division_of i \<and> d fine p"
himmelma@35172
  1424
  "\<forall>i1\<in>iset. \<forall>i2\<in>iset. ~(i1 = i2) \<longrightarrow> (interior(i1) \<inter> interior(i2) = {})" "(\<Union>iset = i)"
himmelma@35172
  1425
   obtains p where "p tagged_division_of i" "d fine p"
himmelma@35172
  1426
proof- guess pfn using bchoice[OF assms(2)] .. note pfn = conjunctD2[OF this[rule_format]]
himmelma@35172
  1427
  show thesis apply(rule_tac p="\<Union>(pfn ` iset)" in that) unfolding assms(4)[THEN sym]
himmelma@35172
  1428
    apply(rule tagged_division_unions[OF assms(1) _ assms(3)]) defer 
himmelma@35172
  1429
    apply(rule fine_unions) using pfn by auto
himmelma@35172
  1430
qed
himmelma@35172
  1431
himmelma@35172
  1432
subsection {* The set we're concerned with must be closed. *}
himmelma@35172
  1433
hoelzl@37489
  1434
lemma division_of_closed: "s division_of i \<Longrightarrow> closed (i::('n::ordered_euclidean_space) set)"
nipkow@44890
  1435
  unfolding division_of_def by fastforce
himmelma@35172
  1436
himmelma@35172
  1437
subsection {* General bisection principle for intervals; might be useful elsewhere. *}
himmelma@35172
  1438
hoelzl@37489
  1439
lemma interval_bisection_step:  fixes type::"'a::ordered_euclidean_space"
hoelzl@37489
  1440
  assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "~(P {a..b::'a})"
himmelma@35172
  1441
  obtains c d where "~(P{c..d})"
hoelzl@50526
  1442
  "\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> c\<bullet>i \<le> d\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i \<and> 2 * (d\<bullet>i - c\<bullet>i) \<le> b\<bullet>i - a\<bullet>i"
himmelma@35172
  1443
proof- have "{a..b} \<noteq> {}" using assms(1,3) by auto
hoelzl@50526
  1444
  then have ab: "\<And>i. i\<in>Basis \<Longrightarrow> a \<bullet> i \<le> b \<bullet> i" by (auto simp: interval_eq_empty not_le)
himmelma@35172
  1445
  { fix f have "finite f \<Longrightarrow>
himmelma@35172
  1446
        (\<forall>s\<in>f. P s) \<Longrightarrow>
himmelma@35172
  1447
        (\<forall>s\<in>f. \<exists>a b. s = {a..b}) \<Longrightarrow>
himmelma@35172
  1448
        (\<forall>s\<in>f.\<forall>t\<in>f. ~(s = t) \<longrightarrow> interior(s) \<inter> interior(t) = {}) \<Longrightarrow> P(\<Union>f)"
himmelma@35172
  1449
    proof(induct f rule:finite_induct)
himmelma@35172
  1450
      case empty show ?case using assms(1) by auto
himmelma@35172
  1451
    next case (insert x f) show ?case unfolding Union_insert apply(rule assms(2)[rule_format])
himmelma@35172
  1452
        apply rule defer apply rule defer apply(rule inter_interior_unions_intervals)
himmelma@35172
  1453
        using insert by auto
himmelma@35172
  1454
    qed } note * = this
hoelzl@50526
  1455
  let ?A = "{{c..d} | c d::'a. \<forall>i\<in>Basis. (c\<bullet>i = a\<bullet>i) \<and> (d\<bullet>i = (a\<bullet>i + b\<bullet>i) / 2) \<or> (c\<bullet>i = (a\<bullet>i + b\<bullet>i) / 2) \<and> (d\<bullet>i = b\<bullet>i)}"
hoelzl@50526
  1456
  let ?PP = "\<lambda>c d. \<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> c\<bullet>i \<le> d\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i \<and> 2 * (d\<bullet>i - c\<bullet>i) \<le> b\<bullet>i - a\<bullet>i"
himmelma@35172
  1457
  { presume "\<forall>c d. ?PP c d \<longrightarrow> P {c..d} \<Longrightarrow> False"
himmelma@35172
  1458
    thus thesis unfolding atomize_not not_all apply-apply(erule exE)+ apply(rule_tac c=x and d=xa in that) by auto }
himmelma@35172
  1459
  assume as:"\<forall>c d. ?PP c d \<longrightarrow> P {c..d}"
himmelma@35172
  1460
  have "P (\<Union> ?A)" proof(rule *, rule_tac[2-] ballI, rule_tac[4] ballI, rule_tac[4] impI) 
hoelzl@50526
  1461
    let ?B = "(\<lambda>s.{(\<Sum>i\<in>Basis. (if i \<in> s then a\<bullet>i else (a\<bullet>i + b\<bullet>i) / 2) *\<^sub>R i)::'a ..
hoelzl@50526
  1462
      (\<Sum>i\<in>Basis. (if i \<in> s then (a\<bullet>i + b\<bullet>i) / 2 else b\<bullet>i) *\<^sub>R i)}) ` {s. s \<subseteq> Basis}"
himmelma@35172
  1463
    have "?A \<subseteq> ?B" proof case goal1
himmelma@35172
  1464
      then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+) note c_d=this[rule_format]
himmelma@35172
  1465
      have *:"\<And>a b c d. a = c \<Longrightarrow> b = d \<Longrightarrow> {a..b} = {c..d}" by auto
hoelzl@50526
  1466
      show "x\<in>?B" unfolding image_iff
hoelzl@50526
  1467
        apply(rule_tac x="{i. i\<in>Basis \<and> c\<bullet>i = a\<bullet>i}" in bexI)
hoelzl@50526
  1468
        unfolding c_d
hoelzl@50526
  1469
        apply(rule *)
hoelzl@50526
  1470
        apply (simp_all only: euclidean_eq_iff[where 'a='a] inner_setsum_left_Basis mem_Collect_eq simp_thms
hoelzl@50526
  1471
                        cong: ball_cong)
hoelzl@50526
  1472
        apply safe
hoelzl@50526
  1473
      proof-
hoelzl@50526
  1474
        fix i :: 'a assume i: "i\<in>Basis"
hoelzl@50526
  1475
        thus " c \<bullet> i = (if c \<bullet> i = a \<bullet> i then a \<bullet> i else (a \<bullet> i + b \<bullet> i) / 2)"
hoelzl@50526
  1476
          "d \<bullet> i = (if c \<bullet> i = a \<bullet> i then (a \<bullet> i + b \<bullet> i) / 2 else b \<bullet> i)"
hoelzl@50526
  1477
          using c_d(2)[of i] ab[OF i] by(auto simp add:field_simps)
hoelzl@37489
  1478
      qed qed
hoelzl@37489
  1479
    thus "finite ?A" apply(rule finite_subset) by auto
himmelma@35172
  1480
    fix s assume "s\<in>?A" then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+)
himmelma@35172
  1481
    note c_d=this[rule_format]
hoelzl@37489
  1482
    show "P s" unfolding c_d apply(rule as[rule_format]) proof- case goal1 thus ?case 
hoelzl@50526
  1483
        using c_d(2)[of i] using ab[OF `i \<in> Basis`] by auto qed
himmelma@35172
  1484
    show "\<exists>a b. s = {a..b}" unfolding c_d by auto
himmelma@35172
  1485
    fix t assume "t\<in>?A" then guess e unfolding mem_Collect_eq .. then guess f apply- by(erule exE,(erule conjE)+)
himmelma@35172
  1486
    note e_f=this[rule_format]
himmelma@35172
  1487
    assume "s \<noteq> t" hence "\<not> (c = e \<and> d = f)" unfolding c_d e_f by auto
hoelzl@50526
  1488
    then obtain i where "c\<bullet>i \<noteq> e\<bullet>i \<or> d\<bullet>i \<noteq> f\<bullet>i" and i':"i\<in>Basis"
hoelzl@50526
  1489
      unfolding euclidean_eq_iff[where 'a='a] by auto
hoelzl@50526
  1490
    hence i:"c\<bullet>i \<noteq> e\<bullet>i" "d\<bullet>i \<noteq> f\<bullet>i" apply- apply(erule_tac[!] disjE)
hoelzl@50526
  1491
    proof- assume "c\<bullet>i \<noteq> e\<bullet>i" thus "d\<bullet>i \<noteq> f\<bullet>i" using c_d(2)[OF i'] e_f(2)[OF i'] by fastforce
hoelzl@50526
  1492
    next   assume "d\<bullet>i \<noteq> f\<bullet>i" thus "c\<bullet>i \<noteq> e\<bullet>i" using c_d(2)[OF i'] e_f(2)[OF i'] by fastforce
himmelma@35172
  1493
    qed have *:"\<And>s t. (\<And>a. a\<in>s \<Longrightarrow> a\<in>t \<Longrightarrow> False) \<Longrightarrow> s \<inter> t = {}" by auto
himmelma@35172
  1494
    show "interior s \<inter> interior t = {}" unfolding e_f c_d interior_closed_interval proof(rule *)
himmelma@35172
  1495
      fix x assume "x\<in>{c<..<d}" "x\<in>{e<..<f}"
hoelzl@50526
  1496
      hence x:"c\<bullet>i < d\<bullet>i" "e\<bullet>i < f\<bullet>i" "c\<bullet>i < f\<bullet>i" "e\<bullet>i < d\<bullet>i" unfolding mem_interval using i'
hoelzl@50526
  1497
        apply-apply(erule_tac[!] x=i in ballE)+ by auto
hoelzl@37489
  1498
      show False using c_d(2)[OF i'] apply- apply(erule_tac disjE)
hoelzl@50526
  1499
      proof(erule_tac[!] conjE) assume as:"c \<bullet> i = a \<bullet> i" "d \<bullet> i = (a \<bullet> i + b \<bullet> i) / 2"
hoelzl@50526
  1500
        show False using e_f(2)[OF i'] and i x unfolding as by(fastforce simp add:field_simps)
hoelzl@50526
  1501
      next assume as:"c \<bullet> i = (a \<bullet> i + b \<bullet> i) / 2" "d \<bullet> i = b \<bullet> i"
hoelzl@50526
  1502
        show False using e_f(2)[OF i'] and i x unfolding as by(fastforce simp add:field_simps)
himmelma@35172
  1503
      qed qed qed
nipkow@39302
  1504
  also have "\<Union> ?A = {a..b}" proof(rule set_eqI,rule)
himmelma@35172
  1505
    fix x assume "x\<in>\<Union>?A" then guess Y unfolding Union_iff ..
himmelma@35172
  1506
    from this(1) guess c unfolding mem_Collect_eq .. then guess d ..
himmelma@35172
  1507
    note c_d = this[THEN conjunct2,rule_format] `x\<in>Y`[unfolded this[THEN conjunct1]]
hoelzl@37489
  1508
    show "x\<in>{a..b}" unfolding mem_interval proof safe
hoelzl@50526
  1509
      fix i :: 'a assume i: "i\<in>Basis" thus "a \<bullet> i \<le> x \<bullet> i" "x \<bullet> i \<le> b \<bullet> i"
hoelzl@50526
  1510
        using c_d(1)[OF i] c_d(2)[unfolded mem_interval,THEN bspec, OF i] by auto qed
himmelma@35172
  1511
  next fix x assume x:"x\<in>{a..b}"
hoelzl@50526
  1512
    have "\<forall>i\<in>Basis. \<exists>c d. (c = a\<bullet>i \<and> d = (a\<bullet>i + b\<bullet>i) / 2 \<or> c = (a\<bullet>i + b\<bullet>i) / 2 \<and> d = b\<bullet>i) \<and> c\<le>x\<bullet>i \<and> x\<bullet>i \<le> d"
hoelzl@50526
  1513
      (is "\<forall>i\<in>Basis. \<exists>c d. ?P i c d") unfolding mem_interval
hoelzl@50526
  1514
    proof
hoelzl@50526
  1515
      fix i :: 'a assume i: "i \<in> Basis"
hoelzl@50526
  1516
      have "?P i (a\<bullet>i) ((a \<bullet> i + b \<bullet> i) / 2) \<or> ?P i ((a \<bullet> i + b \<bullet> i) / 2) (b\<bullet>i)"
hoelzl@50526
  1517
        using x[unfolded mem_interval,THEN bspec, OF i] by auto thus "\<exists>c d. ?P i c d" by blast
hoelzl@50526
  1518
    qed
hoelzl@50526
  1519
    thus "x\<in>\<Union>?A"
hoelzl@50526
  1520
      unfolding Union_iff Bex_def mem_Collect_eq choice_Basis_iff
himmelma@35172
  1521
      apply-apply(erule exE)+ apply(rule_tac x="{xa..xaa}" in exI) unfolding mem_interval by auto
himmelma@35172
  1522
  qed finally show False using assms by auto qed
himmelma@35172
  1523
hoelzl@37489
  1524
lemma interval_bisection: fixes type::"'a::ordered_euclidean_space"
hoelzl@37489
  1525
  assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "\<not> P {a..b::'a}"
himmelma@35172
  1526
  obtains x where "x \<in> {a..b}" "\<forall>e>0. \<exists>c d. x \<in> {c..d} \<and> {c..d} \<subseteq> ball x e \<and> {c..d} \<subseteq> {a..b} \<and> ~P({c..d})"
himmelma@35172
  1527
proof-
hoelzl@37489
  1528
  have "\<forall>x. \<exists>y. \<not> P {fst x..snd x} \<longrightarrow> (\<not> P {fst y..snd y} \<and>
hoelzl@50526
  1529
    (\<forall>i\<in>Basis. fst x\<bullet>i \<le> fst y\<bullet>i \<and> fst y\<bullet>i \<le> snd y\<bullet>i \<and> snd y\<bullet>i \<le> snd x\<bullet>i \<and>
hoelzl@50526
  1530
                           2 * (snd y\<bullet>i - fst y\<bullet>i) \<le> snd x\<bullet>i - fst x\<bullet>i))" proof case goal1 thus ?case proof-
himmelma@35172
  1531
      presume "\<not> P {fst x..snd x} \<Longrightarrow> ?thesis"
himmelma@35172
  1532
      thus ?thesis apply(cases "P {fst x..snd x}") by auto
himmelma@35172
  1533
    next assume as:"\<not> P {fst x..snd x}" from interval_bisection_step[of P, OF assms(1-2) as] guess c d . 
himmelma@35172
  1534
      thus ?thesis apply- apply(rule_tac x="(c,d)" in exI) by auto
himmelma@35172
  1535
    qed qed then guess f apply-apply(drule choice) by(erule exE) note f=this
himmelma@35172
  1536
  def AB \<equiv> "\<lambda>n. (f ^^ n) (a,b)" def A \<equiv> "\<lambda>n. fst(AB n)" and B \<equiv> "\<lambda>n. snd(AB n)" note ab_def = this AB_def
himmelma@35172
  1537
  have "A 0 = a" "B 0 = b" "\<And>n. \<not> P {A(Suc n)..B(Suc n)} \<and>
hoelzl@50526
  1538
    (\<forall>i\<in>Basis. A(n)\<bullet>i \<le> A(Suc n)\<bullet>i \<and> A(Suc n)\<bullet>i \<le> B(Suc n)\<bullet>i \<and> B(Suc n)\<bullet>i \<le> B(n)\<bullet>i \<and> 
hoelzl@50526
  1539
    2 * (B(Suc n)\<bullet>i - A(Suc n)\<bullet>i) \<le> B(n)\<bullet>i - A(n)\<bullet>i)" (is "\<And>n. ?P n")
himmelma@35172
  1540
  proof- show "A 0 = a" "B 0 = b" unfolding ab_def by auto
himmelma@35172
  1541
    case goal3 note S = ab_def funpow.simps o_def id_apply show ?case
himmelma@35172
  1542
    proof(induct n) case 0 thus ?case unfolding S apply(rule f[rule_format]) using assms(3) by auto
himmelma@35172
  1543
    next case (Suc n) show ?case unfolding S apply(rule f[rule_format]) using Suc unfolding S by auto
himmelma@35172
  1544
    qed qed note AB = this(1-2) conjunctD2[OF this(3),rule_format]
himmelma@35172
  1545
himmelma@35172
  1546
  have interv:"\<And>e. 0 < e \<Longrightarrow> \<exists>n. \<forall>x\<in>{A n..B n}. \<forall>y\<in>{A n..B n}. dist x y < e"
hoelzl@50526
  1547
  proof- case goal1 guess n using real_arch_pow2[of "(setsum (\<lambda>i. b\<bullet>i - a\<bullet>i) Basis) / e"] .. note n=this
himmelma@35172
  1548
    show ?case apply(rule_tac x=n in exI) proof(rule,rule)
himmelma@35172
  1549
      fix x y assume xy:"x\<in>{A n..B n}" "y\<in>{A n..B n}"
hoelzl@50526
  1550
      have "dist x y \<le> setsum (\<lambda>i. abs((x - y)\<bullet>i)) Basis" unfolding dist_norm by(rule norm_le_l1)
hoelzl@50526
  1551
      also have "\<dots> \<le> setsum (\<lambda>i. B n\<bullet>i - A n\<bullet>i) Basis"
hoelzl@50526
  1552
      proof(rule setsum_mono)
hoelzl@50526
  1553
        fix i :: 'a assume i: "i \<in> Basis" show "\<bar>(x - y) \<bullet> i\<bar> \<le> B n \<bullet> i - A n \<bullet> i"
hoelzl@50526
  1554
          using xy[unfolded mem_interval,THEN bspec, OF i] by (auto simp: inner_diff_left) qed
hoelzl@50526
  1555
      also have "\<dots> \<le> setsum (\<lambda>i. b\<bullet>i - a\<bullet>i) Basis / 2^n" unfolding setsum_divide_distrib
himmelma@35172
  1556
      proof(rule setsum_mono) case goal1 thus ?case
himmelma@35172
  1557
        proof(induct n) case 0 thus ?case unfolding AB by auto
hoelzl@50526
  1558
        next case (Suc n) have "B (Suc n) \<bullet> i - A (Suc n) \<bullet> i \<le> (B n \<bullet> i - A n \<bullet> i) / 2"
hoelzl@37489
  1559
            using AB(4)[of i n] using goal1 by auto
hoelzl@50526
  1560
          also have "\<dots> \<le> (b \<bullet> i - a \<bullet> i) / 2 ^ Suc n" using Suc by(auto simp add:field_simps) finally show ?case .
himmelma@35172
  1561
        qed qed
himmelma@35172
  1562
      also have "\<dots> < e" using n using goal1 by(auto simp add:field_simps) finally show "dist x y < e" .
himmelma@35172
  1563
    qed qed
hoelzl@50526
  1564
  { fix n m :: nat assume "m \<le> n" then have "{A n..B n} \<subseteq> {A m..B m}"
hoelzl@50526
  1565
    proof(induct rule: inc_induct)
hoelzl@50526
  1566
      case (step i) show ?case
hoelzl@50526
  1567
        using AB(4) by (intro order_trans[OF step(2)] subset_interval_imp) auto
hoelzl@50526
  1568
    qed simp } note ABsubset = this 
himmelma@35172
  1569
  have "\<exists>a. \<forall>n. a\<in>{A n..B n}" apply(rule decreasing_closed_nest[rule_format,OF closed_interval _ ABsubset interv])
himmelma@35172
  1570
  proof- fix n show "{A n..B n} \<noteq> {}" apply(cases "0<n") using AB(3)[of "n - 1"] assms(1,3) AB(1-2) by auto qed auto
himmelma@35172
  1571
  then guess x0 .. note x0=this[rule_format]
himmelma@35172
  1572
  show thesis proof(rule that[rule_format,of x0])
himmelma@35172
  1573
    show "x0\<in>{a..b}" using x0[of 0] unfolding AB .
himmelma@35172
  1574
    fix e assume "0 < (e::real)" from interv[OF this] guess n .. note n=this
himmelma@35172
  1575
    show "\<exists>c d. x0 \<in> {c..d} \<and> {c..d} \<subseteq> ball x0 e \<and> {c..d} \<subseteq> {a..b} \<and> \<not> P {c..d}"
himmelma@35172
  1576
      apply(rule_tac x="A n" in exI,rule_tac x="B n" in exI) apply(rule,rule x0) apply rule defer 
himmelma@35172
  1577
    proof show "\<not> P {A n..B n}" apply(cases "0<n") using AB(3)[of "n - 1"] assms(3) AB(1-2) by auto
himmelma@35172
  1578
      show "{A n..B n} \<subseteq> ball x0 e" using n using x0[of n] by auto
himmelma@35172
  1579
      show "{A n..B n} \<subseteq> {a..b}" unfolding AB(1-2)[symmetric] apply(rule ABsubset) by auto
himmelma@35172
  1580
    qed qed qed 
himmelma@35172
  1581
himmelma@35172
  1582
subsection {* Cousin's lemma. *}
himmelma@35172
  1583
himmelma@35172
  1584
lemma fine_division_exists: assumes "gauge g" 
hoelzl@37489
  1585
  obtains p where "p tagged_division_of {a..b::'a::ordered_euclidean_space}" "g fine p"
himmelma@35172
  1586
proof- presume "\<not> (\<exists>p. p tagged_division_of {a..b} \<and> g fine p) \<Longrightarrow> False"
himmelma@35172
  1587
  then guess p unfolding atomize_not not_not .. thus thesis apply-apply(rule that[of p]) by auto
himmelma@35172
  1588
next assume as:"\<not> (\<exists>p. p tagged_division_of {a..b} \<and> g fine p)"
himmelma@35172
  1589
  guess x apply(rule interval_bisection[of "\<lambda>s. \<exists>p. p tagged_division_of s \<and> g fine p",rule_format,OF _ _ as])
himmelma@35172
  1590
    apply(rule_tac x="{}" in exI) defer apply(erule conjE exE)+
himmelma@35172
  1591
  proof- show "{} tagged_division_of {} \<and> g fine {}" unfolding fine_def by auto
himmelma@35172
  1592
    fix s t p p' assume "p tagged_division_of s" "g fine p" "p' tagged_division_of t" "g fine p'" "interior s \<inter> interior t = {}"
himmelma@35172
  1593
    thus "\<exists>p. p tagged_division_of s \<union> t \<and> g fine p" apply-apply(rule_tac x="p \<union> p'" in exI) apply rule
himmelma@35172
  1594
      apply(rule tagged_division_union) prefer 4 apply(rule fine_union) by auto
himmelma@35172
  1595
  qed note x=this
himmelma@35172
  1596
  obtain e where e:"e>0" "ball x e \<subseteq> g x" using gaugeD[OF assms, of x] unfolding open_contains_ball by auto
himmelma@35172
  1597
  from x(2)[OF e(1)] guess c d apply-apply(erule exE conjE)+ . note c_d = this
himmelma@35172
  1598
  have "g fine {(x, {c..d})}" unfolding fine_def using e using c_d(2) by auto
himmelma@35172
  1599
  thus False using tagged_division_of_self[OF c_d(1)] using c_d by auto qed
himmelma@35172
  1600
himmelma@35172
  1601
subsection {* Basic theorems about integrals. *}
himmelma@35172
  1602
hoelzl@37489
  1603
lemma has_integral_unique: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector"
himmelma@35172
  1604
  assumes "(f has_integral k1) i" "(f has_integral k2) i" shows "k1 = k2"
himmelma@35172
  1605
proof(rule ccontr) let ?e = "norm(k1 - k2) / 2" assume as:"k1 \<noteq> k2" hence e:"?e > 0" by auto
hoelzl@37489
  1606
  have lem:"\<And>f::'n \<Rightarrow> 'a.  \<And> a b k1 k2.
himmelma@35172
  1607
    (f has_integral k1) ({a..b}) \<Longrightarrow> (f has_integral k2) ({a..b}) \<Longrightarrow> k1 \<noteq> k2 \<Longrightarrow> False"
himmelma@35172
  1608
  proof- case goal1 let ?e = "norm(k1 - k2) / 2" from goal1(3) have e:"?e > 0" by auto
himmelma@35172
  1609
    guess d1 by(rule has_integralD[OF goal1(1) e]) note d1=this
himmelma@35172
  1610
    guess d2 by(rule has_integralD[OF goal1(2) e]) note d2=this
himmelma@35172
  1611
    guess p by(rule fine_division_exists[OF gauge_inter[OF d1(1) d2(1)],of a b]) note p=this
himmelma@35172
  1612
    let ?c = "(\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)" have "norm (k1 - k2) \<le> norm (?c - k2) + norm (?c - k1)"
haftmann@36350
  1613
      using norm_triangle_ineq4[of "k1 - ?c" "k2 - ?c"] by(auto simp add:algebra_simps norm_minus_commute)
himmelma@35172
  1614
    also have "\<dots> < norm (k1 - k2) / 2 + norm (k1 - k2) / 2"
himmelma@35172
  1615
      apply(rule add_strict_mono) apply(rule_tac[!] d2(2) d1(2)) using p unfolding fine_def by auto
himmelma@35172
  1616
    finally show False by auto
himmelma@35172
  1617
  qed { presume "\<not> (\<exists>a b. i = {a..b}) \<Longrightarrow> False"
himmelma@35172
  1618
    thus False apply-apply(cases "\<exists>a b. i = {a..b}")
himmelma@35172
  1619
      using assms by(auto simp add:has_integral intro:lem[OF _ _ as]) }
himmelma@35172
  1620
  assume as:"\<not> (\<exists>a b. i = {a..b})"
himmelma@35172
  1621
  guess B1 by(rule has_integral_altD[OF assms(1) as,OF e]) note B1=this[rule_format]
himmelma@35172
  1622
  guess B2 by(rule has_integral_altD[OF assms(2) as,OF e]) note B2=this[rule_format]
hoelzl@37489
  1623
  have "\<exists>a b::'n. ball 0 B1 \<union> ball 0 B2 \<subseteq> {a..b}" apply(rule bounded_subset_closed_interval)
himmelma@35172
  1624
    using bounded_Un bounded_ball by auto then guess a b apply-by(erule exE)+
himmelma@35172
  1625
  note ab=conjunctD2[OF this[unfolded Un_subset_iff]]
himmelma@35172
  1626
  guess w using B1(2)[OF ab(1)] .. note w=conjunctD2[OF this]
himmelma@35172
  1627
  guess z using B2(2)[OF ab(2)] .. note z=conjunctD2[OF this]
himmelma@35172
  1628
  have "z = w" using lem[OF w(1) z(1)] by auto
himmelma@35172
  1629
  hence "norm (k1 - k2) \<le> norm (z - k2) + norm (w - k1)"
himmelma@35172
  1630
    using norm_triangle_ineq4[of "k1 - w" "k2 - z"] by(auto simp add: norm_minus_commute) 
himmelma@35172
  1631
  also have "\<dots> < norm (k1 - k2) / 2 + norm (k1 - k2) / 2" apply(rule add_strict_mono) by(rule_tac[!] z(2) w(2))
himmelma@35172
  1632
  finally show False by auto qed
himmelma@35172
  1633
himmelma@35172
  1634
lemma integral_unique[intro]:
himmelma@35172
  1635
  "(f has_integral y) k \<Longrightarrow> integral k f = y"
himmelma@35172
  1636
  unfolding integral_def apply(rule some_equality) by(auto intro: has_integral_unique) 
himmelma@35172
  1637
hoelzl@37489
  1638
lemma has_integral_is_0: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector" 
himmelma@35172
  1639
  assumes "\<forall>x\<in>s. f x = 0" shows "(f has_integral 0) s"
hoelzl@37489
  1640
proof- have lem:"\<And>a b. \<And>f::'n \<Rightarrow> 'a.
himmelma@35172
  1641
    (\<forall>x\<in>{a..b}. f(x) = 0) \<Longrightarrow> (f has_integral 0) ({a..b})" unfolding has_integral
hoelzl@37489
  1642
  proof(rule,rule) fix a b e and f::"'n \<Rightarrow> 'a"
himmelma@35172
  1643
    assume as:"\<forall>x\<in>{a..b}. f x = 0" "0 < (e::real)"
himmelma@35172
  1644
    show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) < e)"
himmelma@35172
  1645
      apply(rule_tac x="\<lambda>x. ball x 1" in exI)  apply(rule,rule gaugeI) unfolding centre_in_ball defer apply(rule open_ball)
himmelma@35172
  1646
    proof(rule,rule,erule conjE) case goal1
himmelma@35172
  1647
      have "(\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) = 0" proof(rule setsum_0',rule)
himmelma@35172
  1648
        fix x assume x:"x\<in>p" have "f (fst x) = 0" using tagged_division_ofD(2-3)[OF goal1(1), of "fst x" "snd x"] using as x by auto
himmelma@35172
  1649
        thus "(\<lambda>(x, k). content k *\<^sub>R f x) x = 0" apply(subst surjective_pairing[of x]) unfolding split_conv by auto
himmelma@35172
  1650
      qed thus ?case using as by auto
himmelma@35172
  1651
    qed auto qed  { presume "\<not> (\<exists>a b. s = {a..b}) \<Longrightarrow> ?thesis"
himmelma@35172
  1652
    thus ?thesis apply-apply(cases "\<exists>a b. s = {a..b}")
himmelma@35172
  1653
      using assms by(auto simp add:has_integral intro:lem) }
himmelma@35172
  1654
  have *:"(\<lambda>x. if x \<in> s then f x else 0) = (\<lambda>x. 0)" apply(rule ext) using assms by auto
himmelma@35172
  1655
  assume "\<not> (\<exists>a b. s = {a..b})" thus ?thesis apply(subst has_integral_alt) unfolding if_not_P *
himmelma@35172
  1656
  apply(rule,rule,rule_tac x=1 in exI,rule) defer apply(rule,rule,rule)
himmelma@35172
  1657
  proof- fix e::real and a b assume "e>0"
hoelzl@37489
  1658
    thus "\<exists>z. ((\<lambda>x::'n. 0::'a) has_integral z) {a..b} \<and> norm (z - 0) < e"
himmelma@35172
  1659
      apply(rule_tac x=0 in exI) apply(rule,rule lem) by auto
himmelma@35172
  1660
  qed auto qed
himmelma@35172
  1661
hoelzl@37489
  1662
lemma has_integral_0[simp]: "((\<lambda>x::'n::ordered_euclidean_space. 0) has_integral 0) s"
himmelma@35172
  1663
  apply(rule has_integral_is_0) by auto 
himmelma@35172
  1664
himmelma@35172
  1665
lemma has_integral_0_eq[simp]: "((\<lambda>x. 0) has_integral i) s \<longleftrightarrow> i = 0"
himmelma@35172
  1666
  using has_integral_unique[OF has_integral_0] by auto
himmelma@35172
  1667
hoelzl@37489
  1668
lemma has_integral_linear: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector"
himmelma@35172
  1669
  assumes "(f has_integral y) s" "bounded_linear h" shows "((h o f) has_integral ((h y))) s"
himmelma@35172
  1670
proof- interpret bounded_linear h using assms(2) . from pos_bounded guess B .. note B=conjunctD2[OF this,rule_format]
hoelzl@37489
  1671
  have lem:"\<And>f::'n \<Rightarrow> 'a. \<And> y a b.
himmelma@35172
  1672
    (f has_integral y) ({a..b}) \<Longrightarrow> ((h o f) has_integral h(y)) ({a..b})"
himmelma@35172
  1673
  proof(subst has_integral,rule,rule) case goal1
himmelma@35172
  1674
    from pos_bounded guess B .. note B=conjunctD2[OF this,rule_format]
himmelma@35172
  1675
    have *:"e / B > 0" apply(rule divide_pos_pos) using goal1(2) B by auto
himmelma@35172
  1676
    guess g using has_integralD[OF goal1(1) *] . note g=this
himmelma@35172
  1677
    show ?case apply(rule_tac x=g in exI) apply(rule,rule g(1))
himmelma@35172
  1678
    proof(rule,rule,erule conjE) fix p assume as:"p tagged_division_of {a..b}" "g fine p" 
himmelma@35172
  1679
      have *:"\<And>x k. h ((\<lambda>(x, k). content k *\<^sub>R f x) x) = (\<lambda>(x, k). h (content k *\<^sub>R f x)) x" by auto
himmelma@35172
  1680
      have "(\<Sum>(x, k)\<in>p. content k *\<^sub>R (h \<circ> f) x) = setsum (h \<circ> (\<lambda>(x, k). content k *\<^sub>R f x)) p"
himmelma@35172
  1681
        unfolding o_def unfolding scaleR[THEN sym] * by simp
himmelma@35172
  1682
      also have "\<dots> = h (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)" using setsum[of "\<lambda>(x,k). content k *\<^sub>R f x" p] using as by auto
himmelma@35172
  1683
      finally have *:"(\<Sum>(x, k)\<in>p. content k *\<^sub>R (h \<circ> f) x) = h (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)" .
himmelma@35172
  1684
      show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R (h \<circ> f) x) - h y) < e" unfolding * diff[THEN sym]
himmelma@35172
  1685
        apply(rule le_less_trans[OF B(2)]) using g(2)[OF as] B(1) by(auto simp add:field_simps)
himmelma@35172
  1686
    qed qed { presume "\<not> (\<exists>a b. s = {a..b}) \<Longrightarrow> ?thesis"
himmelma@35172
  1687
    thus ?thesis apply-apply(cases "\<exists>a b. s = {a..b}") using assms by(auto simp add:has_integral intro!:lem) }
himmelma@35172
  1688
  assume as:"\<not> (\<exists>a b. s = {a..b})" thus ?thesis apply(subst has_integral_alt) unfolding if_not_P
himmelma@35172
  1689
  proof(rule,rule) fix e::real  assume e:"0<e"
himmelma@35172
  1690
    have *:"0 < e/B" by(rule divide_pos_pos,rule e,rule B(1))
himmelma@35172
  1691
    guess M using has_integral_altD[OF assms(1) as *,rule_format] . note M=this
himmelma@35172
  1692
    show "\<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b} \<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> s then (h \<circ> f) x else 0) has_integral z) {a..b} \<and> norm (z - h y) < e)"
himmelma@35172
  1693
      apply(rule_tac x=M in exI) apply(rule,rule M(1))
himmelma@35172
  1694
    proof(rule,rule,rule) case goal1 guess z using M(2)[OF goal1(1)] .. note z=conjunctD2[OF this]
himmelma@35172
  1695
      have *:"(\<lambda>x. if x \<in> s then (h \<circ> f) x else 0) = h \<circ> (\<lambda>x. if x \<in> s then f x else 0)"
himmelma@35172
  1696
        unfolding o_def apply(rule ext) using zero by auto
himmelma@35172
  1697
      show ?case apply(rule_tac x="h z" in exI,rule) unfolding * apply(rule lem[OF z(1)]) unfolding diff[THEN sym]
himmelma@35172
  1698
        apply(rule le_less_trans[OF B(2)]) using B(1) z(2) by(auto simp add:field_simps)
himmelma@35172
  1699
    qed qed qed
himmelma@35172
  1700
himmelma@35172
  1701
lemma has_integral_cmul:
himmelma@35172
  1702
  shows "(f has_integral k) s \<Longrightarrow> ((\<lambda>x. c *\<^sub>R f x) has_integral (c *\<^sub>R k)) s"
himmelma@35172
  1703
  unfolding o_def[THEN sym] apply(rule has_integral_linear,assumption)
huffman@44282
  1704
  by(rule bounded_linear_scaleR_right)
himmelma@35172
  1705
hoelzl@50104
  1706
lemma has_integral_cmult_real:
hoelzl@50104
  1707
  fixes c :: real
hoelzl@50104
  1708
  assumes "c \<noteq> 0 \<Longrightarrow> (f has_integral x) A"
hoelzl@50104
  1709
  shows "((\<lambda>x. c * f x) has_integral c * x) A"
hoelzl@50104
  1710
proof cases
hoelzl@50104
  1711
  assume "c \<noteq> 0"
hoelzl@50104
  1712
  from has_integral_cmul[OF assms[OF this], of c] show ?thesis
hoelzl@50104
  1713
    unfolding real_scaleR_def .
hoelzl@50104
  1714
qed simp
hoelzl@50104
  1715
himmelma@35172
  1716
lemma has_integral_neg:
himmelma@35172
  1717
  shows "(f has_integral k) s \<Longrightarrow> ((\<lambda>x. -(f x)) has_integral (-k)) s"
himmelma@35172
  1718
  apply(drule_tac c="-1" in has_integral_cmul) by auto
himmelma@35172
  1719
hoelzl@37489
  1720
lemma has_integral_add: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector" 
himmelma@35172
  1721
  assumes "(f has_integral k) s" "(g has_integral l) s"
himmelma@35172
  1722
  shows "((\<lambda>x. f x + g x) has_integral (k + l)) s"
hoelzl@37489
  1723
proof- have lem:"\<And>f g::'n \<Rightarrow> 'a. \<And>a b k l.
himmelma@35172
  1724
    (f has_integral k) ({a..b}) \<Longrightarrow> (g has_integral l) ({a..b}) \<Longrightarrow>
himmelma@35172
  1725
     ((\<lambda>x. f(x) + g(x)) has_integral (k + l)) ({a..b})" proof- case goal1
himmelma@35172
  1726
    show ?case unfolding has_integral proof(rule,rule) fix e::real assume e:"e>0" hence *:"e/2>0" by auto
himmelma@35172
  1727
      guess d1 using has_integralD[OF goal1(1) *] . note d1=this
himmelma@35172
  1728
      guess d2 using has_integralD[OF goal1(2) *] . note d2=this
himmelma@35172
  1729
      show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R (f x + g x)) - (k + l)) < e)"
himmelma@35172
  1730
        apply(rule_tac x="\<lambda>x. (d1 x) \<inter> (d2 x)" in exI) apply(rule,rule gauge_inter[OF d1(1) d2(1)])
himmelma@35172
  1731
      proof(rule,rule,erule conjE) fix p assume as:"p tagged_division_of {a..b}" "(\<lambda>x. d1 x \<inter> d2 x) fine p"
himmelma@35172
  1732
        have *:"(\<Sum>(x, k)\<in>p. content k *\<^sub>R (f x + g x)) = (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>p. content k *\<^sub>R g x)"
himmelma@35172
  1733
          unfolding scaleR_right_distrib setsum_addf[of "\<lambda>(x,k). content k *\<^sub>R f x" "\<lambda>(x,k). content k *\<^sub>R g x" p,THEN sym]
himmelma@35172
  1734
          by(rule setsum_cong2,auto)
himmelma@35172
  1735
        have "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R (f x + g x)) - (k + l)) = norm (((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - k) + ((\<Sum>(x, k)\<in>p. content k *\<^sub>R g x) - l))"
haftmann@36350
  1736
          unfolding * by(auto simp add:algebra_simps) also let ?res = "\<dots>"
himmelma@35172
  1737
        from as have *:"d1 fine p" "d2 fine p" unfolding fine_inter by auto
himmelma@35172
  1738
        have "?res < e/2 + e/2" apply(rule le_less_trans[OF norm_triangle_ineq])
himmelma@35172
  1739
          apply(rule add_strict_mono) using d1(2)[OF as(1) *(1)] and d2(2)[OF as(1) *(2)] by auto
himmelma@35172
  1740
        finally show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R (f x + g x)) - (k + l)) < e" by auto
himmelma@35172
  1741
      qed qed qed { presume "\<not> (\<exists>a b. s = {a..b}) \<Longrightarrow> ?thesis"
himmelma@35172
  1742
    thus ?thesis apply-apply(cases "\<exists>a b. s = {a..b}") using assms by(auto simp add:has_integral intro!:lem) }
himmelma@35172
  1743
  assume as:"\<not> (\<exists>a b. s = {a..b})" thus ?thesis apply(subst has_integral_alt) unfolding if_not_P
himmelma@35172
  1744
  proof(rule,rule) case goal1 hence *:"e/2 > 0" by auto
himmelma@35172
  1745
    from has_integral_altD[OF assms(1) as *] guess B1 . note B1=this[rule_format]
himmelma@35172
  1746
    from has_integral_altD[OF assms(2) as *] guess B2 . note B2=this[rule_format]
himmelma@35172
  1747
    show ?case apply(rule_tac x="max B1 B2" in exI) apply(rule,rule min_max.less_supI1,rule B1)
hoelzl@37489
  1748
    proof(rule,rule,rule) fix a b assume "ball 0 (max B1 B2) \<subseteq> {a..b::'n}"
hoelzl@37489
  1749
      hence *:"ball 0 B1 \<subseteq> {a..b::'n}" "ball 0 B2 \<subseteq> {a..b::'n}" by auto
himmelma@35172
  1750
      guess w using B1(2)[OF *(1)] .. note w=conjunctD2[OF this]
himmelma@35172
  1751
      guess z using B2(2)[OF *(2)] .. note z=conjunctD2[OF this]
himmelma@35172
  1752
      have *:"\<And>x. (if x \<in> s then f x + g x else 0) = (if x \<in> s then f x else 0) + (if x \<in> s then g x else 0)" by auto
himmelma@35172
  1753
      show "\<exists>z. ((\<lambda>x. if x \<in> s then f x + g x else 0) has_integral z) {a..b} \<and> norm (z - (k + l)) < e"
himmelma@35172
  1754
        apply(rule_tac x="w + z" in exI) apply(rule,rule lem[OF w(1) z(1), unfolded *[THEN sym]])
himmelma@35172
  1755
        using norm_triangle_ineq[of "w - k" "z - l"] w(2) z(2) by(auto simp add:field_simps)
himmelma@35172
  1756
    qed qed qed
himmelma@35172
  1757
himmelma@35172
  1758
lemma has_integral_sub:
himmelma@35172
  1759
  shows "(f has_integral k) s \<Longrightarrow> (g has_integral l) s \<Longrightarrow> ((\<lambda>x. f(x) - g(x)) has_integral (k - l)) s"
haftmann@36350
  1760
  using has_integral_add[OF _ has_integral_neg,of f k s g l] unfolding algebra_simps by auto
himmelma@35172
  1761
hoelzl@37489
  1762
lemma integral_0: "integral s (\<lambda>x::'n::ordered_euclidean_space. 0::'m::real_normed_vector) = 0"
himmelma@35172
  1763
  by(rule integral_unique has_integral_0)+
himmelma@35172
  1764
himmelma@35172
  1765
lemma integral_add:
himmelma@35172
  1766
  shows "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow>
himmelma@35172
  1767
   integral s (\<lambda>x. f x + g x) = integral s f + integral s g"
himmelma@35172
  1768
  apply(rule integral_unique) apply(drule integrable_integral)+
himmelma@35172
  1769
  apply(rule has_integral_add) by assumption+
himmelma@35172
  1770
himmelma@35172
  1771
lemma integral_cmul:
himmelma@35172
  1772
  shows "f integrable_on s \<Longrightarrow> integral s (\<lambda>x. c *\<^sub>R f x) = c *\<^sub>R integral s f"
himmelma@35172
  1773
  apply(rule integral_unique) apply(drule integrable_integral)+
himmelma@35172
  1774
  apply(rule has_integral_cmul) by assumption+
himmelma@35172
  1775
himmelma@35172
  1776
lemma integral_neg:
himmelma@35172
  1777
  shows "f integrable_on s \<Longrightarrow> integral s (\<lambda>x. - f x) = - integral s f"
himmelma@35172
  1778
  apply(rule integral_unique) apply(drule integrable_integral)+
himmelma@35172
  1779
  apply(rule has_integral_neg) by assumption+
himmelma@35172
  1780
himmelma@35172
  1781
lemma integral_sub:
himmelma@35172
  1782
  shows "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow> integral s (\<lambda>x. f x - g x) = integral s f - integral s g"
himmelma@35172
  1783
  apply(rule integral_unique) apply(drule integrable_integral)+
himmelma@35172
  1784
  apply(rule has_integral_sub) by assumption+
himmelma@35172
  1785
himmelma@35172
  1786
lemma integrable_0: "(\<lambda>x. 0) integrable_on s"
himmelma@35172
  1787
  unfolding integrable_on_def using has_integral_0 by auto
himmelma@35172
  1788
himmelma@35172
  1789
lemma integrable_add:
himmelma@35172
  1790
  shows "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow> (\<lambda>x. f x + g x) integrable_on s"
himmelma@35172
  1791
  unfolding integrable_on_def by(auto intro: has_integral_add)
himmelma@35172
  1792
himmelma@35172
  1793
lemma integrable_cmul:
himmelma@35172
  1794
  shows "f integrable_on s \<Longrightarrow> (\<lambda>x. c *\<^sub>R f(x)) integrable_on s"
himmelma@35172
  1795
  unfolding integrable_on_def by(auto intro: has_integral_cmul)
himmelma@35172
  1796
hoelzl@50104
  1797
lemma integrable_on_cmult_iff:
hoelzl@50104
  1798
  fixes c :: real assumes "c \<noteq> 0"
hoelzl@50104
  1799
  shows "(\<lambda>x. c * f x) integrable_on s \<longleftrightarrow> f integrable_on s"
hoelzl@50104
  1800
  using integrable_cmul[of "\<lambda>x. c * f x" s "1 / c"] integrable_cmul[of f s c] `c \<noteq> 0`
hoelzl@50104
  1801
  by auto
hoelzl@50104
  1802
himmelma@35172
  1803
lemma integrable_neg:
himmelma@35172
  1804
  shows "f integrable_on s \<Longrightarrow> (\<lambda>x. -f(x)) integrable_on s"
himmelma@35172
  1805
  unfolding integrable_on_def by(auto intro: has_integral_neg)
himmelma@35172
  1806
himmelma@35172
  1807
lemma integrable_sub:
himmelma@35172
  1808
  shows "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow> (\<lambda>x. f x - g x) integrable_on s"
himmelma@35172
  1809
  unfolding integrable_on_def by(auto intro: has_integral_sub)
himmelma@35172
  1810
himmelma@35172
  1811
lemma integrable_linear:
himmelma@35172
  1812
  shows "f integrable_on s \<Longrightarrow> bounded_linear h \<Longrightarrow> (h o f) integrable_on s"
himmelma@35172
  1813
  unfolding integrable_on_def by(auto intro: has_integral_linear)
himmelma@35172
  1814
himmelma@35172
  1815
lemma integral_linear:
himmelma@35172
  1816
  shows "f integrable_on s \<Longrightarrow> bounded_linear h \<Longrightarrow> integral s (h o f) = h(integral s f)"
himmelma@35172
  1817
  apply(rule has_integral_unique) defer unfolding has_integral_integral 
himmelma@35172
  1818
  apply(drule has_integral_linear,assumption,assumption) unfolding has_integral_integral[THEN sym]
himmelma@35172
  1819
  apply(rule integrable_linear) by assumption+
himmelma@35172
  1820
hoelzl@37489
  1821
lemma integral_component_eq[simp]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
hoelzl@50526
  1822
  assumes "f integrable_on s" shows "integral s (\<lambda>x. f x \<bullet> k) = integral s f \<bullet> k"
hoelzl@37489
  1823
  unfolding integral_linear[OF assms(1) bounded_linear_component,unfolded o_def] ..
himmelma@36243
  1824
himmelma@35172
  1825
lemma has_integral_setsum:
himmelma@35172
  1826
  assumes "finite t" "\<forall>a\<in>t. ((f a) has_integral (i a)) s"
himmelma@35172
  1827
  shows "((\<lambda>x. setsum (\<lambda>a. f a x) t) has_integral (setsum i t)) s"
himmelma@35172
  1828
proof(insert assms(1) subset_refl[of t],induct rule:finite_subset_induct)
himmelma@35172
  1829
  case (insert x F) show ?case unfolding setsum_insert[OF insert(1,3)]
himmelma@35172
  1830
    apply(rule has_integral_add) using insert assms by auto
himmelma@35172
  1831
qed auto
himmelma@35172
  1832
himmelma@35172
  1833
lemma integral_setsum:
himmelma@35172
  1834
  shows "finite t \<Longrightarrow> \<forall>a\<in>t. (f a) integrable_on s \<Longrightarrow>
himmelma@35172
  1835
  integral s (\<lambda>x. setsum (\<lambda>a. f a x) t) = setsum (\<lambda>a. integral s (f a)) t"
himmelma@35172
  1836
  apply(rule integral_unique) apply(rule has_integral_setsum)
himmelma@35172
  1837
  using integrable_integral by auto
himmelma@35172
  1838
himmelma@35172
  1839
lemma integrable_setsum:
himmelma@35172
  1840
  shows "finite t \<Longrightarrow> \<forall>a \<in> t.(f a) integrable_on s \<Longrightarrow> (\<lambda>x. setsum (\<lambda>a. f a x) t) integrable_on s"
himmelma@35172
  1841
  unfolding integrable_on_def apply(drule bchoice) using has_integral_setsum[of t] by auto
himmelma@35172
  1842
himmelma@35172
  1843
lemma has_integral_eq:
himmelma@35172
  1844
  assumes "\<forall>x\<in>s. f x = g x" "(f has_integral k) s" shows "(g has_integral k) s"
himmelma@35172
  1845
  using has_integral_sub[OF assms(2), of "\<lambda>x. f x - g x" 0]
himmelma@35172
  1846
  using has_integral_is_0[of s "\<lambda>x. f x - g x"] using assms(1) by auto
himmelma@35172
  1847
himmelma@35172
  1848
lemma integrable_eq:
himmelma@35172
  1849
  shows "\<forall>x\<in>s. f x = g x \<Longrightarrow> f integrable_on s \<Longrightarrow> g integrable_on s"
himmelma@35172
  1850
  unfolding integrable_on_def using has_integral_eq[of s f g] by auto
himmelma@35172
  1851
himmelma@35172
  1852
lemma has_integral_eq_eq:
himmelma@35172
  1853
  shows "\<forall>x\<in>s. f x = g x \<Longrightarrow> ((f has_integral k) s \<longleftrightarrow> (g has_integral k) s)"
huffman@36362
  1854
  using has_integral_eq[of s f g] has_integral_eq[of s g f] by rule auto
himmelma@35172
  1855
himmelma@35172
  1856
lemma has_integral_null[dest]:
himmelma@35172
  1857
  assumes "content({a..b}) = 0" shows  "(f has_integral 0) ({a..b})"
himmelma@35172
  1858
  unfolding has_integral apply(rule,rule,rule_tac x="\<lambda>x. ball x 1" in exI,rule) defer
himmelma@35172
  1859
proof(rule,rule,erule conjE) fix e::real assume e:"e>0" thus "gauge (\<lambda>x. ball x 1)" by auto
himmelma@35172
  1860
  fix p assume p:"p tagged_division_of {a..b}" (*"(\<lambda>x. ball x 1) fine p"*)
himmelma@35172
  1861
  have "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) = 0" unfolding norm_eq_zero diff_0_right
himmelma@35172
  1862
    using setsum_content_null[OF assms(1) p, of f] . 
himmelma@35172
  1863
  thus "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) < e" using e by auto qed
himmelma@35172
  1864
himmelma@35172
  1865
lemma has_integral_null_eq[simp]:
himmelma@35172
  1866
  shows "content({a..b}) = 0 \<Longrightarrow> ((f has_integral i) ({a..b}) \<longleftrightarrow> i = 0)"
himmelma@35172
  1867
  apply rule apply(rule has_integral_unique,assumption) 
himmelma@35172
  1868
  apply(drule has_integral_null,assumption)
himmelma@35172
  1869
  apply(drule has_integral_null) by auto
himmelma@35172
  1870
himmelma@35172
  1871
lemma integral_null[dest]: shows "content({a..b}) = 0 \<Longrightarrow> integral({a..b}) f = 0"
himmelma@35172
  1872
  by(rule integral_unique,drule has_integral_null)
himmelma@35172
  1873
himmelma@35172
  1874
lemma integrable_on_null[dest]: shows "content({a..b}) = 0 \<Longrightarrow> f integrable_on {a..b}"
himmelma@35172
  1875
  unfolding integrable_on_def apply(drule has_integral_null) by auto
himmelma@35172
  1876
himmelma@35172
  1877
lemma has_integral_empty[intro]: shows "(f has_integral 0) {}"
himmelma@35172
  1878
  unfolding empty_as_interval apply(rule has_integral_null) 
himmelma@35172
  1879
  using content_empty unfolding empty_as_interval .
himmelma@35172
  1880
himmelma@35172
  1881
lemma has_integral_empty_eq[simp]: shows "(f has_integral i) {} \<longleftrightarrow> i = 0"
himmelma@35172
  1882
  apply(rule,rule has_integral_unique,assumption) by auto
himmelma@35172
  1883
himmelma@35172
  1884
lemma integrable_on_empty[intro]: shows "f integrable_on {}" unfolding integrable_on_def by auto
himmelma@35172
  1885
himmelma@35172
  1886
lemma integral_empty[simp]: shows "integral {} f = 0"
himmelma@35172
  1887
  apply(rule integral_unique) using has_integral_empty .
himmelma@35172
  1888
hoelzl@37489
  1889
lemma has_integral_refl[intro]: shows "(f has_integral 0) {a..a}" "(f has_integral 0) {a::'a::ordered_euclidean_space}"
hoelzl@50526
  1890
proof-
hoelzl@50526
  1891
  have *:"{a} = {a..a}" apply(rule set_eqI) unfolding mem_interval singleton_iff euclidean_eq_iff[where 'a='a]
hoelzl@50526
  1892
    apply safe prefer 3 apply(erule_tac x=b in ballE) by(auto simp add: field_simps)
himmelma@35540
  1893
  show "(f has_integral 0) {a..a}" "(f has_integral 0) {a}" unfolding *
himmelma@35540
  1894
    apply(rule_tac[!] has_integral_null) unfolding content_eq_0_interior
himmelma@35540
  1895
    unfolding interior_closed_interval using interval_sing by auto qed
himmelma@35172
  1896
himmelma@35172
  1897
lemma integrable_on_refl[intro]: shows "f integrable_on {a..a}" unfolding integrable_on_def by auto
himmelma@35172
  1898
himmelma@35172
  1899
lemma integral_refl: shows "integral {a..a} f = 0" apply(rule integral_unique) by auto
himmelma@35172
  1900
himmelma@35172
  1901
subsection {* Cauchy-type criterion for integrability. *}
himmelma@35172
  1902
hoelzl@37489
  1903
(* XXXXXXX *)
hoelzl@37489
  1904
lemma integrable_cauchy: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::{real_normed_vector,complete_space}" 
himmelma@35172
  1905
  shows "f integrable_on {a..b} \<longleftrightarrow>
himmelma@35172
  1906
  (\<forall>e>0.\<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of {a..b} \<and> d fine p1 \<and>
himmelma@35172
  1907
                            p2 tagged_division_of {a..b} \<and> d fine p2
himmelma@35172
  1908
                            \<longrightarrow> norm(setsum (\<lambda>(x,k). content k *\<^sub>R f x) p1 -
himmelma@35172
  1909
                                     setsum (\<lambda>(x,k). content k *\<^sub>R f x) p2) < e))" (is "?l = (\<forall>e>0. \<exists>d. ?P e d)")
himmelma@35172
  1910
proof assume ?l
himmelma@35172
  1911
  then guess y unfolding integrable_on_def has_integral .. note y=this
himmelma@35172
  1912
  show "\<forall>e>0. \<exists>d. ?P e d" proof(rule,rule) case goal1 hence "e/2 > 0" by auto
himmelma@35172
  1913
    then guess d apply- apply(drule y[rule_format]) by(erule exE,erule conjE) note d=this[rule_format]
himmelma@35172
  1914
    show ?case apply(rule_tac x=d in exI,rule,rule d) apply(rule,rule,rule,(erule conjE)+)
himmelma@35172
  1915
    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b}" "d fine p1" "p2 tagged_division_of {a..b}" "d fine p2"
himmelma@35172
  1916
      show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e"
huffman@36587
  1917
        apply(rule dist_triangle_half_l[where y=y,unfolded dist_norm])
himmelma@35172
  1918
        using d(2)[OF conjI[OF as(1-2)]] d(2)[OF conjI[OF as(3-4)]] .
himmelma@35172
  1919
    qed qed
himmelma@35172
  1920
next assume "\<forall>e>0. \<exists>d. ?P e d" hence "\<forall>n::nat. \<exists>d. ?P (inverse(real (n + 1))) d" by auto
himmelma@35172
  1921
  from choice[OF this] guess d .. note d=conjunctD2[OF this[rule_format],rule_format]
himmelma@35172
  1922
  have "\<And>n. gauge (\<lambda>x. \<Inter>{d i x |i. i \<in> {0..n}})" apply(rule gauge_inters) using d(1) by auto
himmelma@35172
  1923
  hence "\<forall>n. \<exists>p. p tagged_division_of {a..b} \<and> (\<lambda>x. \<Inter>{d i x |i. i \<in> {0..n}}) fine p" apply-
himmelma@35172
  1924
  proof case goal1 from this[of n] show ?case apply(drule_tac fine_division_exists) by auto qed
himmelma@35172
  1925
  from choice[OF this] guess p .. note p = conjunctD2[OF this[rule_format]]
himmelma@35172
  1926
  have dp:"\<And>i n. i\<le>n \<Longrightarrow> d i fine p n" using p(2) unfolding fine_inters by auto
himmelma@35172
  1927
  have "Cauchy (\<lambda>n. setsum (\<lambda>(x,k). content k *\<^sub>R (f x)) (p n))"
himmelma@35172
  1928
  proof(rule CauchyI) case goal1 then guess N unfolding real_arch_inv[of e] .. note N=this
himmelma@35172
  1929
    show ?case apply(rule_tac x=N in exI)
himmelma@35172
  1930
    proof(rule,rule,rule,rule) fix m n assume mn:"N \<le> m" "N \<le> n" have *:"N = (N - 1) + 1" using N by auto
himmelma@35172
  1931
      show "norm ((\<Sum>(x, k)\<in>p m. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p n. content k *\<^sub>R f x)) < e"
himmelma@35172
  1932
        apply(rule less_trans[OF _ N[THEN conjunct2,THEN conjunct2]]) apply(subst *) apply(rule d(2))
himmelma@35172
  1933
        using dp p(1) using mn by auto 
himmelma@35172
  1934
    qed qed
huffman@44906
  1935
  then guess y unfolding convergent_eq_cauchy[THEN sym] .. note y=this[THEN LIMSEQ_D]
himmelma@35172
  1936
  show ?l unfolding integrable_on_def has_integral apply(rule_tac x=y in exI)
himmelma@35172
  1937
  proof(rule,rule) fix e::real assume "e>0" hence *:"e/2 > 0" by auto
himmelma@35172
  1938
    then guess N1 unfolding real_arch_inv[of "e/2"] .. note N1=this hence N1':"N1 = N1 - 1 + 1" by auto
himmelma@35172
  1939
    guess N2 using y[OF *] .. note N2=this
himmelma@35172
  1940
    show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - y) < e)"
himmelma@35172
  1941
      apply(rule_tac x="d (N1 + N2)" in exI) apply rule defer 
himmelma@35172
  1942
    proof(rule,rule,erule conjE) show "gauge (d (N1 + N2))" using d by auto
himmelma@35172
  1943
      fix q assume as:"q tagged_division_of {a..b}" "d (N1 + N2) fine q"
himmelma@35172
  1944
      have *:"inverse (real (N1 + N2 + 1)) < e / 2" apply(rule less_trans) using N1 by auto
himmelma@35172
  1945
      show "norm ((\<Sum>(x, k)\<in>q. content k *\<^sub>R f x) - y) < e" apply(rule norm_triangle_half_r)
himmelma@35172
  1946
        apply(rule less_trans[OF _ *]) apply(subst N1', rule d(2)[of "p (N1+N2)"]) defer
huffman@44906
  1947
        using N2[rule_format,of "N1+N2"]
himmelma@35172
  1948
        using as dp[of "N1 - 1 + 1 + N2" "N1 + N2"] using p(1)[of "N1 + N2"] using N1 by auto qed qed qed
himmelma@35172
  1949
himmelma@35172
  1950
subsection {* Additivity of integral on abutting intervals. *}
himmelma@35172
  1951
hoelzl@50526
  1952
lemma interval_split:
hoelzl@50526
  1953
  fixes a::"'a::ordered_euclidean_space" assumes "k \<in> Basis"
hoelzl@50526
  1954
  shows
hoelzl@50526
  1955
    "{a..b} \<inter> {x. x\<bullet>k \<le> c} = {a .. (\<Sum>i\<in>Basis. (if i = k then min (b\<bullet>k) c else b\<bullet>i) *\<^sub>R i)}"
hoelzl@50526
  1956
    "{a..b} \<inter> {x. x\<bullet>k \<ge> c} = {(\<Sum>i\<in>Basis. (if i = k then max (a\<bullet>k) c else a\<bullet>i) *\<^sub>R i) .. b}"
hoelzl@50526
  1957
  apply(rule_tac[!] set_eqI) unfolding Int_iff mem_interval mem_Collect_eq using assms
hoelzl@50526
  1958
  by auto
hoelzl@50526
  1959
hoelzl@50526
  1960
lemma content_split: fixes a::"'a::ordered_euclidean_space" assumes "k\<in>Basis" shows
hoelzl@50526
  1961
  "content {a..b} = content({a..b} \<inter> {x. x\<bullet>k \<le> c}) + content({a..b} \<inter> {x. x\<bullet>k >= c})"
hoelzl@50526
  1962
proof cases
hoelzl@50526
  1963
  note simps = interval_split[OF assms] content_closed_interval_cases eucl_le[where 'a='a]
hoelzl@50526
  1964
  have *:"Basis = insert k (Basis - {k})" "\<And>x. finite (Basis-{x})" "\<And>x. x\<notin>Basis-{x}"
hoelzl@37489
  1965
    using assms by auto
hoelzl@50526
  1966
  have *:"\<And>X Y Z. (\<Prod>i\<in>Basis. Z i (if i = k then X else Y i)) = Z k X * (\<Prod>i\<in>Basis-{k}. Z i (Y i))"
hoelzl@50526
  1967
    "(\<Prod>i\<in>Basis. b\<bullet>i - a\<bullet>i) = (\<Prod>i\<in>Basis-{k}. b\<bullet>i - a\<bullet>i) * (b\<bullet>k - a\<bullet>k)" 
himmelma@35172
  1968
    apply(subst *(1)) defer apply(subst *(1)) unfolding setprod_insert[OF *(2-)] by auto
hoelzl@50526
  1969
  assume as:"a\<le>b" moreover have "\<And>x. min (b \<bullet> k) c = max (a \<bullet> k) c
hoelzl@50526
  1970
    \<Longrightarrow> x* (b\<bullet>k - a\<bullet>k) = x*(max (a \<bullet> k) c - a \<bullet> k) + x*(b \<bullet> k - max (a \<bullet> k) c)"
himmelma@35172
  1971
    by  (auto simp add:field_simps)
hoelzl@50526
  1972
  moreover have **:"(\<Prod>i\<in>Basis. ((\<Sum>i\<in>Basis. (if i = k then min (b \<bullet> k) c else b \<bullet> i) *\<^sub>R i) \<bullet> i - a \<bullet> i)) = 
hoelzl@50526
  1973
      (\<Prod>i\<in>Basis. (if i = k then min (b \<bullet> k) c else b \<bullet> i) - a \<bullet> i)"
hoelzl@50526
  1974
    "(\<Prod>i\<in>Basis. b \<bullet> i - ((\<Sum>i\<in>Basis. (if i = k then max (a \<bullet> k) c else a \<bullet> i) *\<^sub>R i) \<bullet> i)) =
hoelzl@50526
  1975
      (\<Prod>i\<in>Basis. b \<bullet> i - (if i = k then max (a \<bullet> k) c else a \<bullet> i))"
hoelzl@50526
  1976
    by (auto intro!: setprod_cong)
hoelzl@50526
  1977
  have "\<not> a \<bullet> k \<le> c \<Longrightarrow> \<not> c \<le> b \<bullet> k \<Longrightarrow> False"
hoelzl@37489
  1978
    unfolding not_le using as[unfolded eucl_le[where 'a='a],rule_format,of k] assms by auto
hoelzl@37489
  1979
  ultimately show ?thesis using assms unfolding simps **
hoelzl@50526
  1980
    unfolding *(1)[of "\<lambda>i x. b\<bullet>i - x"] *(1)[of "\<lambda>i x. x - a\<bullet>i"] unfolding *(2)
hoelzl@50526
  1981
    by auto
hoelzl@50526
  1982
next
hoelzl@50526
  1983
  assume "\<not> a \<le> b" then have "{a .. b} = {}"
hoelzl@50526
  1984
    unfolding interval_eq_empty by (auto simp: eucl_le[where 'a='a] not_le)
hoelzl@50526
  1985
  then show ?thesis by auto
himmelma@35172
  1986
qed
himmelma@35172
  1987
hoelzl@37489
  1988
lemma division_split_left_inj: fixes type::"'a::ordered_euclidean_space"
hoelzl@37489
  1989
  assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2" 
hoelzl@50526
  1990
  "k1 \<inter> {x::'a. x\<bullet>k \<le> c} = k2 \<inter> {x. x\<bullet>k \<le> c}"and k:"k\<in>Basis"
hoelzl@50526
  1991
  shows "content(k1 \<inter> {x. x\<bullet>k \<le> c}) = 0"
himmelma@35172
  1992
proof- note d=division_ofD[OF assms(1)]
hoelzl@50526
  1993
  have *:"\<And>a b::'a. \<And> c. (content({a..b} \<inter> {x. x\<bullet>k \<le> c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x\<bullet>k \<le> c}) = {})"
hoelzl@37489
  1994
    unfolding  interval_split[OF k] content_eq_0_interior by auto
himmelma@35172
  1995
  guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
himmelma@35172
  1996
  guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
himmelma@35172
  1997
  have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
himmelma@35172
  1998
  show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
himmelma@35172
  1999
    defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
hoelzl@37489
  2000
 
hoelzl@37489
  2001
lemma division_split_right_inj: fixes type::"'a::ordered_euclidean_space"
himmelma@35172
  2002
  assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2"
hoelzl@50526
  2003
  "k1 \<inter> {x::'a. x\<bullet>k \<ge> c} = k2 \<inter> {x. x\<bullet>k \<ge> c}" and k:"k\<in>Basis"
hoelzl@50526
  2004
  shows "content(k1 \<inter> {x. x\<bullet>k \<ge> c}) = 0"
himmelma@35172
  2005
proof- note d=division_ofD[OF assms(1)]
hoelzl@50526
  2006
  have *:"\<And>a b::'a. \<And> c. (content({a..b} \<inter> {x. x\<bullet>k >= c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x\<bullet>k >= c}) = {})"
hoelzl@37489
  2007
    unfolding interval_split[OF k] content_eq_0_interior by auto
himmelma@35172
  2008
  guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
himmelma@35172
  2009
  guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
himmelma@35172
  2010
  have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
himmelma@35172
  2011
  show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
himmelma@35172
  2012
    defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
himmelma@35172
  2013
hoelzl@37489
  2014
lemma tagged_division_split_left_inj: fixes x1::"'a::ordered_euclidean_space"
hoelzl@50526
  2015
  assumes "d tagged_division_of i" "(x1,k1) \<in> d" "(x2,k2) \<in> d" "k1 \<noteq> k2"  "k1 \<inter> {x. x\<bullet>k \<le> c} = k2 \<inter> {x. x\<bullet>k \<le> c}" 
hoelzl@50526
  2016
  and k:"k\<in>Basis"
hoelzl@50526
  2017
  shows "content(k1 \<inter> {x. x\<bullet>k \<le> c}) = 0"
himmelma@35172
  2018
proof- have *:"\<And>a b c. (a,b) \<in> c \<Longrightarrow> b \<in> snd ` c" unfolding image_iff apply(rule_tac x="(a,b)" in bexI) by auto
himmelma@35172
  2019
  show ?thesis apply(rule division_split_left_inj[OF division_of_tagged_division[OF assms(1)]])
himmelma@35172
  2020
    apply(rule_tac[1-2] *) using assms(2-) by auto qed
himmelma@35172
  2021
hoelzl@37489
  2022
lemma tagged_division_split_right_inj: fixes x1::"'a::ordered_euclidean_space"
hoelzl@50526
  2023
  assumes "d tagged_division_of i" "(x1,k1) \<in> d" "(x2,k2) \<in> d" "k1 \<noteq> k2"  "k1 \<inter> {x. x\<bullet>k \<ge> c} = k2 \<inter> {x. x\<bullet>k \<ge> c}" 
hoelzl@50526
  2024
  and k:"k\<in>Basis"
hoelzl@50526
  2025
  shows "content(k1 \<inter> {x. x\<bullet>k \<ge> c}) = 0"
himmelma@35172
  2026
proof- have *:"\<And>a b c. (a,b) \<in> c \<Longrightarrow> b \<in> snd ` c" unfolding image_iff apply(rule_tac x="(a,b)" in bexI) by auto
himmelma@35172
  2027
  show ?thesis apply(rule division_split_right_inj[OF division_of_tagged_division[OF assms(1)]])
himmelma@35172
  2028
    apply(rule_tac[1-2] *) using assms(2-) by auto qed
himmelma@35172
  2029
hoelzl@37489
  2030
lemma division_split: fixes a::"'a::ordered_euclidean_space"
hoelzl@50526
  2031
  assumes "p division_of {a..b}" and k:"k\<in>Basis"
hoelzl@50526
  2032
  shows "{l \<inter> {x. x\<bullet>k \<le> c} | l. l \<in> p \<and> ~(l \<inter> {x. x\<bullet>k \<le> c} = {})} division_of({a..b} \<inter> {x. x\<bullet>k \<le> c})" (is "?p1 division_of ?I1") and 
hoelzl@50526
  2033
        "{l \<inter> {x. x\<bullet>k \<ge> c} | l. l \<in> p \<and> ~(l \<inter> {x. x\<bullet>k \<ge> c} = {})} division_of ({a..b} \<inter> {x. x\<bullet>k \<ge> c})" (is "?p2 division_of ?I2")
hoelzl@37489
  2034
proof(rule_tac[!] division_ofI) note p=division_ofD[OF assms(1)]
himmelma@35172
  2035
  show "finite ?p1" "finite ?p2" using p(1) by auto show "\<Union>?p1 = ?I1" "\<Union>?p2 = ?I2" unfolding p(6)[THEN sym] by auto
himmelma@35172
  2036
  { fix k assume "k\<in>?p1" then guess l unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l=this
himmelma@35172
  2037
    guess u v using p(4)[OF l(2)] apply-by(erule exE)+ note uv=this
himmelma@35172
  2038
    show "k\<subseteq>?I1" "k \<noteq> {}" "\<exists>a b. k = {a..b}" unfolding l
hoelzl@37489
  2039
      using p(2-3)[OF l(2)] l(3) unfolding uv apply- prefer 3 apply(subst interval_split[OF k]) by auto
himmelma@35172
  2040
    fix k' assume "k'\<in>?p1" then guess l' unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l'=this
himmelma@35172
  2041
    assume "k\<noteq>k'" thus "interior k \<inter> interior k' = {}" unfolding l l' using p(5)[OF l(2) l'(2)] by auto }
himmelma@35172
  2042
  { fix k assume "k\<in>?p2" then guess l unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l=this
himmelma@35172
  2043
    guess u v using p(4)[OF l(2)] apply-by(erule exE)+ note uv=this
himmelma@35172
  2044
    show "k\<subseteq>?I2" "k \<noteq> {}" "\<exists>a b. k = {a..b}" unfolding l
hoelzl@37489
  2045
      using p(2-3)[OF l(2)] l(3) unfolding uv apply- prefer 3 apply(subst interval_split[OF k]) by auto
himmelma@35172
  2046
    fix k' assume "k'\<in>?p2" then guess l' unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l'=this
himmelma@35172
  2047
    assume "k\<noteq>k'" thus "interior k \<inter> interior k' = {}" unfolding l l' using p(5)[OF l(2) l'(2)] by auto }
himmelma@35172
  2048
qed
himmelma@35172
  2049
hoelzl@37489
  2050
lemma has_integral_split: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@50526
  2051
  assumes "(f has_integral i) ({a..b} \<inter> {x. x\<bullet>k \<le> c})"  "(f has_integral j) ({a..b} \<inter> {x. x\<bullet>k \<ge> c})" and k:"k\<in>Basis"
himmelma@35172
  2052
  shows "(f has_integral (i + j)) ({a..b})"
himmelma@35172
  2053
proof(unfold has_integral,rule,rule) case goal1 hence e:"e/2>0" by auto
hoelzl@37489
  2054
  guess d1 using has_integralD[OF assms(1)[unfolded interval_split[OF k]] e] . note d1=this[unfolded interval_split[THEN sym,OF k]]
hoelzl@37489
  2055
  guess d2 using has_integralD[OF assms(2)[unfolded interval_split[OF k]] e] . note d2=this[unfolded interval_split[THEN sym,OF k]]
hoelzl@50526
  2056
  let ?d = "\<lambda>x. if x\<bullet>k = c then (d1 x \<inter> d2 x) else ball x (abs(x\<bullet>k - c)) \<inter> d1 x \<inter> d2 x"
himmelma@35172
  2057
  show ?case apply(rule_tac x="?d" in exI,rule) defer apply(rule,rule,(erule conjE)+)
himmelma@35172
  2058
  proof- show "gauge ?d" using d1(1) d2(1) unfolding gauge_def by auto
himmelma@35172
  2059
    fix p assume "p tagged_division_of {a..b}" "?d fine p" note p = this tagged_division_ofD[OF this(1)]
hoelzl@50526
  2060
    have lem0:"\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x\<bullet>k \<le> c} = {}) \<Longrightarrow> x\<bullet>k \<le> c"
hoelzl@50526
  2061
         "\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x\<bullet>k \<ge> c} = {}) \<Longrightarrow> x\<bullet>k \<ge> c"
himmelma@35172
  2062
    proof- fix x kk assume as:"(x,kk)\<in>p"
hoelzl@50526
  2063
      show "~(kk \<inter> {x. x\<bullet>k \<le> c} = {}) \<Longrightarrow> x\<bullet>k \<le> c"
himmelma@35172
  2064
      proof(rule ccontr) case goal1
hoelzl@50526
  2065
        from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x \<bullet> k - c\<bar>"
himmelma@35172
  2066
          using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
hoelzl@50526
  2067
        hence "\<exists>y. y \<in> ball x \<bar>x \<bullet> k - c\<bar> \<inter> {x. x \<bullet> k \<le> c}" using goal1(1) by blast 
hoelzl@50526
  2068
        then guess y .. hence "\<bar>x \<bullet> k - y \<bullet> k\<bar> < \<bar>x \<bullet> k - c\<bar>" "y\<bullet>k \<le> c" apply-apply(rule le_less_trans)
hoelzl@50526
  2069
          using Basis_le_norm[OF k, of "x - y"] by (auto simp add: dist_norm inner_diff_left)
himmelma@35172
  2070
        thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
himmelma@35172
  2071
      qed
hoelzl@50526
  2072
      show "~(kk \<inter> {x. x\<bullet>k \<ge> c} = {}) \<Longrightarrow> x\<bullet>k \<ge> c"
himmelma@35172
  2073
      proof(rule ccontr) case goal1
hoelzl@50526
  2074
        from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x \<bullet> k - c\<bar>"
himmelma@35172
  2075
          using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
hoelzl@50526
  2076
        hence "\<exists>y. y \<in> ball x \<bar>x \<bullet> k - c\<bar> \<inter> {x. x \<bullet> k \<ge> c}" using goal1(1) by blast 
hoelzl@50526
  2077
        then guess y .. hence "\<bar>x \<bullet> k - y \<bullet> k\<bar> < \<bar>x \<bullet> k - c\<bar>" "y\<bullet>k \<ge> c" apply-apply(rule le_less_trans)
hoelzl@50526
  2078
          using Basis_le_norm[OF k, of "x - y"] by (auto simp add: dist_norm inner_diff_left)
himmelma@35172
  2079
        thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
himmelma@35172
  2080
      qed
himmelma@35172
  2081
    qed
himmelma@35172
  2082
himmelma@35172
  2083
    have lem1: "\<And>f P Q. (\<forall>x k. (x,k) \<in> {(x,f k) | x k. P x k} \<longrightarrow> Q x k) \<longleftrightarrow> (\<forall>x k. P x k \<longrightarrow> Q x (f k))" by auto
himmelma@35172
  2084
    have lem2: "\<And>f s P f. finite s \<Longrightarrow> finite {(x,f k) | x k. (x,k) \<in> s \<and> P x k}"
himmelma@35172
  2085
    proof- case goal1 thus ?case apply-apply(rule finite_subset[of _ "(\<lambda>(x,k). (x,f k)) ` s"]) by auto qed
huffman@44170
  2086
    have lem3: "\<And>g::'a set \<Rightarrow> 'a set. finite p \<Longrightarrow>
himmelma@35172
  2087
      setsum (\<lambda>(x,k). content k *\<^sub>R f x) {(x,g k) |x k. (x,k) \<in> p \<and> ~(g k = {})}
himmelma@35172
  2088
               = setsum (\<lambda>(x,k). content k *\<^sub>R f x) ((\<lambda>(x,k). (x,g k)) ` p)"
himmelma@35172
  2089
      apply(rule setsum_mono_zero_left) prefer 3
huffman@44170
  2090
    proof fix g::"'a set \<Rightarrow> 'a set" and i::"('a) \<times> (('a) set)"
himmelma@35172
  2091
      assume "i \<in> (\<lambda>(x, k). (x, g k)) ` p - {(x, g k) |x k. (x, k) \<in> p \<and> g k \<noteq> {}}"
himmelma@35172
  2092
      then obtain x k where xk:"i=(x,g k)" "(x,k)\<in>p" "(x,g k) \<notin> {(x, g k) |x k. (x, k) \<in> p \<and> g k \<noteq> {}}" by auto
himmelma@35172
  2093
      have "content (g k) = 0" using xk using content_empty by auto
himmelma@35172
  2094
      thus "(\<lambda>(x, k). content k *\<^sub>R f x) i = 0" unfolding xk split_conv by auto
himmelma@35172
  2095
    qed auto
himmelma@35172
  2096
    have lem4:"\<And>g. (\<lambda>(x,l). content (g l) *\<^sub>R f x) = (\<lambda>(x,l). content l *\<^sub>R f x) o (\<lambda>(x,l). (x,g l))" apply(rule ext) by auto
himmelma@35172
  2097
hoelzl@50526
  2098
    let ?M1 = "{(x,kk \<inter> {x. x\<bullet>k \<le> c}) |x kk. (x,kk) \<in> p \<and> kk \<inter> {x. x\<bullet>k \<le> c} \<noteq> {}}"
himmelma@35172
  2099
    have "norm ((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) < e/2" apply(rule d1(2),rule tagged_division_ofI)
himmelma@35172
  2100
      apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
hoelzl@50526
  2101
    proof- show "\<Union>{k. \<exists>x. (x, k) \<in> ?M1} = {a..b} \<inter> {x. x\<bullet>k \<le> c}" unfolding p(8)[THEN sym] by auto
himmelma@35172
  2102
      fix x l assume xl:"(x,l)\<in>?M1"
himmelma@35172
  2103
      then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
himmelma@35172
  2104
      have "l' \<subseteq> d1 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
himmelma@35172
  2105
      thus "l \<subseteq> d1 x" unfolding xl' by auto
hoelzl@50526
  2106
      show "x\<in>l" "l \<subseteq> {a..b} \<inter> {x. x \<bullet> k \<le> c}" unfolding xl' using p(4-6)[OF xl'(3)] using xl'(4)
himmelma@35172
  2107
        using lem0(1)[OF xl'(3-4)] by auto
nipkow@44890
  2108
      show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastforce simp add: interval_split[OF k,where c=c])
himmelma@35172
  2109
      fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M1"
himmelma@35172
  2110
      then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
himmelma@35172
  2111
      assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
himmelma@35172
  2112
      proof(cases "l' = r' \<longrightarrow> x' = y'")
himmelma@35172
  2113
        case False thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
himmelma@35172
  2114
      next case True hence "l' \<noteq> r'" using as unfolding xl' yr' by auto
himmelma@35172
  2115
        thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
himmelma@35172
  2116
      qed qed moreover
himmelma@35172
  2117
hoelzl@50526
  2118
    let ?M2 = "{(x,kk \<inter> {x. x\<bullet>k \<ge> c}) |x kk. (x,kk) \<in> p \<and> kk \<inter> {x. x\<bullet>k \<ge> c} \<noteq> {}}" 
himmelma@35172
  2119
    have "norm ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j) < e/2" apply(rule d2(2),rule tagged_division_ofI)
himmelma@35172
  2120
      apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
hoelzl@50526
  2121
    proof- show "\<Union>{k. \<exists>x. (x, k) \<in> ?M2} = {a..b} \<inter> {x. x\<bullet>k \<ge> c}" unfolding p(8)[THEN sym] by auto
himmelma@35172
  2122
      fix x l assume xl:"(x,l)\<in>?M2"
himmelma@35172
  2123
      then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
himmelma@35172
  2124
      have "l' \<subseteq> d2 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
himmelma@35172
  2125
      thus "l \<subseteq> d2 x" unfolding xl' by auto
hoelzl@50526
  2126
      show "x\<in>l" "l \<subseteq> {a..b} \<inter> {x. x \<bullet> k \<ge> c}" unfolding xl' using p(4-6)[OF xl'(3)] using xl'(4)
himmelma@35172
  2127
        using lem0(2)[OF xl'(3-4)] by auto
nipkow@44890
  2128
      show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastforce simp add: interval_split[OF k, where c=c])
himmelma@35172
  2129
      fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M2"
himmelma@35172
  2130
      then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
himmelma@35172
  2131
      assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
himmelma@35172
  2132
      proof(cases "l' = r' \<longrightarrow> x' = y'")
himmelma@35172
  2133
        case False thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
himmelma@35172
  2134
      next case True hence "l' \<noteq> r'" using as unfolding xl' yr' by auto
himmelma@35172
  2135
        thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
himmelma@35172
  2136
      qed qed ultimately
himmelma@35172
  2137
himmelma@35172
  2138
    have "norm (((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) + ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j)) < e/2 + e/2"
himmelma@35172
  2139
      apply- apply(rule norm_triangle_lt) by auto
hoelzl@37489
  2140
    also { have *:"\<And>x y. x = (0::real) \<Longrightarrow> x *\<^sub>R (y::'b) = 0" using scaleR_zero_left by auto
himmelma@35172
  2141
      have "((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) + ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j)
himmelma@35172
  2142
       = (\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - (i + j)" by auto
hoelzl@50526
  2143
      also have "\<dots> = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f x) +
hoelzl@50526
  2144
        (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f x) - (i + j)"
himmelma@35172
  2145
        unfolding lem3[OF p(3)] apply(subst setsum_reindex_nonzero[OF p(3)]) defer apply(subst setsum_reindex_nonzero[OF p(3)])
himmelma@35172
  2146
        defer unfolding lem4[THEN sym] apply(rule refl) unfolding split_paired_all split_conv apply(rule_tac[!] *)
hoelzl@37489
  2147
      proof- case goal1 thus ?case apply- apply(rule tagged_division_split_left_inj [OF p(1), of a b aa ba]) using k by auto
hoelzl@37489
  2148
      next case   goal2 thus ?case apply- apply(rule tagged_division_split_right_inj[OF p(1), of a b aa ba]) using k by auto
himmelma@35172
  2149
      qed also note setsum_addf[THEN sym]
hoelzl@50526
  2150
      also have *:"\<And>x. x\<in>p \<Longrightarrow> (\<lambda>(x, ka). content (ka \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f x) x + (\<lambda>(x, ka). content (ka \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f x) x
himmelma@35172
  2151
        = (\<lambda>(x,ka). content ka *\<^sub>R f x) x" unfolding split_paired_all split_conv
himmelma@35172
  2152
      proof- fix a b assume "(a,b) \<in> p" from p(6)[OF this] guess u v apply-by(erule exE)+ note uv=this
hoelzl@50526
  2153
        thus "content (b \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f a + content (b \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f a = content b *\<^sub>R f a"
hoelzl@37489
  2154
          unfolding scaleR_left_distrib[THEN sym] unfolding uv content_split[OF k,of u v c] by auto
himmelma@35172
  2155
      qed note setsum_cong2[OF this]
hoelzl@50526
  2156
      finally have "(\<Sum>(x, k)\<in>{(x, kk \<inter> {x. x \<bullet> k \<le> c}) |x kk. (x, kk) \<in> p \<and> kk \<inter> {x. x \<bullet> k \<le> c} \<noteq> {}}. content k *\<^sub>R f x) - i +
hoelzl@50526
  2157
        ((\<Sum>(x, k)\<in>{(x, kk \<inter> {x. c \<le> x \<bullet> k}) |x kk. (x, kk) \<in> p \<and> kk \<inter> {x. c \<le> x \<bullet> k} \<noteq> {}}. content k *\<^sub>R f x) - j) =
himmelma@35172
  2158
        (\<Sum>(x, ka)\<in>p. content ka *\<^sub>R f x) - (i + j)" by auto }
himmelma@35172
  2159
    finally show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - (i + j)) < e" by auto qed qed
himmelma@35172
  2160
himmelma@35172
  2161
subsection {* A sort of converse, integrability on subintervals. *}
himmelma@35172
  2162
hoelzl@37489
  2163
lemma tagged_division_union_interval: fixes a::"'a::ordered_euclidean_space"
hoelzl@50526
  2164
  assumes "p1 tagged_division_of ({a..b} \<inter> {x. x\<bullet>k \<le> (c::real)})"  "p2 tagged_division_of ({a..b} \<inter> {x. x\<bullet>k \<ge> c})"
hoelzl@50526
  2165
  and k:"k\<in>Basis"
himmelma@35172
  2166
  shows "(p1 \<union> p2) tagged_division_of ({a..b})"
hoelzl@50526
  2167
proof- have *:"{a..b} = ({a..b} \<inter> {x. x\<bullet>k \<le> c}) \<union> ({a..b} \<inter> {x. x\<bullet>k \<ge> c})" by auto
hoelzl@37489
  2168
  show ?thesis apply(subst *) apply(rule tagged_division_union[OF assms(1-2)])
hoelzl@37489
  2169
    unfolding interval_split[OF k] interior_closed_interval using k
hoelzl@50526
  2170
    by(auto simp add: eucl_less[where 'a='a] elim!: ballE[where x=k]) qed
hoelzl@37489
  2171
hoelzl@37489
  2172
lemma has_integral_separate_sides: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@50526
  2173
  assumes "(f has_integral i) ({a..b})" "e>0" and k:"k\<in>Basis"
hoelzl@50526
  2174
  obtains d where "gauge d" "(\<forall>p1 p2. p1 tagged_division_of ({a..b} \<inter> {x. x\<bullet>k \<le> c}) \<and> d fine p1 \<and>
hoelzl@50526
  2175
                                p2 tagged_division_of ({a..b} \<inter> {x. x\<bullet>k \<ge> c}) \<and> d fine p2
himmelma@35172
  2176
                                \<longrightarrow> norm((setsum (\<lambda>(x,k). content k *\<^sub>R f x) p1 +
himmelma@35172
  2177
                                          setsum (\<lambda>(x,k). content k *\<^sub>R f x) p2) - i) < e)"
hoelzl@37489
  2178
proof- guess d using has_integralD[OF assms(1-2)] . note d=this
himmelma@35172
  2179
  show ?thesis apply(rule that[of d]) apply(rule d) apply(rule,rule,rule,(erule conjE)+)
hoelzl@50526
  2180
  proof- fix p1 p2 assume "p1 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<le> c}" "d fine p1" note p1=tagged_division_ofD[OF this(1)] this
hoelzl@50526
  2181
                   assume "p2 tagged_division_of {a..b} \<inter> {x. c \<le> x \<bullet> k}" "d fine p2" note p2=tagged_division_ofD[OF this(1)] this
himmelma@35172
  2182
    note tagged_division_union_interval[OF p1(7) p2(7)] note p12 = tagged_division_ofD[OF this] this
himmelma@35172
  2183
    have "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x) - i) = norm ((\<Sum>(x, k)\<in>p1 \<union> p2. content k *\<^sub>R f x) - i)"
himmelma@35172
  2184
      apply(subst setsum_Un_zero) apply(rule p1 p2)+ apply(rule) unfolding split_paired_all split_conv
himmelma@35172
  2185
    proof- fix a b assume ab:"(a,b) \<in> p1 \<inter> p2"
himmelma@35172
  2186
      have "(a,b) \<in> p1" using ab by auto from p1(4)[OF this] guess u v apply-by(erule exE)+ note uv =this
hoelzl@50526
  2187
      have "b \<subseteq> {x. x\<bullet>k = c}" using ab p1(3)[of a b] p2(3)[of a b] by fastforce
hoelzl@50526
  2188
      moreover have "interior {x::'a. x \<bullet> k = c} = {}" 
hoelzl@50526
  2189
      proof(rule ccontr) case goal1 then obtain x where x:"x\<in>interior {x::'a. x\<bullet>k = c}" by auto
himmelma@35172
  2190
        then guess e unfolding mem_interior .. note e=this
hoelzl@50526
  2191
        have x:"x\<bullet>k = c" using x interior_subset by fastforce
hoelzl@50526
  2192
        have *:"\<And>i. i\<in>Basis \<Longrightarrow> \<bar>(x - (x + (e / 2) *\<^sub>R k)) \<bullet> i\<bar>
hoelzl@50526
  2193
          = (if i = k then e/2 else 0)" using e k by (auto simp: inner_simps inner_not_same_Basis)
hoelzl@50526
  2194
        have "(\<Sum>i\<in>Basis. \<bar>(x - (x + (e / 2 ) *\<^sub>R k)) \<bullet> i\<bar>) =
hoelzl@50526
  2195
          (\<Sum>i\<in>Basis. (if i = k then e / 2 else 0))" apply(rule setsum_cong2) apply(subst *) by auto
hoelzl@37489
  2196
        also have "... < e" apply(subst setsum_delta) using e by auto 
hoelzl@50526
  2197
        finally have "x + (e/2) *\<^sub>R k \<in> ball x e"
hoelzl@50526
  2198
          unfolding mem_ball dist_norm by(rule le_less_trans[OF norm_le_l1])
hoelzl@50526
  2199
        hence "x + (e/2) *\<^sub>R k \<in> {x. x\<bullet>k = c}" using e by auto
hoelzl@50526
  2200
        thus False unfolding mem_Collect_eq using e x k by (auto simp: inner_simps)
huffman@44522
  2201
      qed ultimately have "content b = 0" unfolding uv content_eq_0_interior apply-apply(drule interior_mono) by auto
himmelma@35172
  2202
      thus "content b *\<^sub>R f a = 0" by auto
himmelma@35172
  2203
    qed auto
hoelzl@37489
  2204
    also have "\<dots> < e" by(rule k d(2) p12 fine_union p1 p2)+
himmelma@35172
  2205
    finally show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x) - i) < e" . qed qed
himmelma@35172
  2206
hoelzl@50526
  2207
lemma integrable_split[intro]:
hoelzl@50526
  2208
  fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::{real_normed_vector,complete_space}"
hoelzl@50526
  2209
  assumes "f integrable_on {a..b}" and k:"k\<in>Basis"
hoelzl@50526
  2210
  shows "f integrable_on ({a..b} \<inter> {x. x\<bullet>k \<le> c})" (is ?t1) and "f integrable_on ({a..b} \<inter> {x. x\<bullet>k \<ge> c})" (is ?t2) 
hoelzl@37489
  2211
proof- guess y using assms(1) unfolding integrable_on_def .. note y=this
hoelzl@50526
  2212
  def b' \<equiv> "\<Sum>i\<in>Basis. (if i = k then min (b\<bullet>k) c else b\<bullet>i)*\<^sub>R i::'a"
hoelzl@50526
  2213
  def a' \<equiv> "\<Sum>i\<in>Basis. (if i = k then max (a\<bullet>k) c else a\<bullet>i)*\<^sub>R i::'a"
hoelzl@37489
  2214
  show ?t1 ?t2 unfolding interval_split[OF k] integrable_cauchy unfolding interval_split[THEN sym,OF k]
himmelma@35172
  2215
  proof(rule_tac[!] allI impI)+ fix e::real assume "e>0" hence "e/2>0" by auto
hoelzl@37489
  2216
    from has_integral_separate_sides[OF y this k,of c] guess d . note d=this[rule_format]
hoelzl@37489
  2217
    let ?P = "\<lambda>A. \<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of {a..b} \<inter> A \<and> d fine p1
hoelzl@37489
  2218
      \<and> p2 tagged_division_of {a..b} \<inter> A \<and> d fine p2 \<longrightarrow>
hoelzl@37489
  2219
      norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e)"
hoelzl@50526
  2220
    show "?P {x. x \<bullet> k \<le> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
hoelzl@50526
  2221
    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<le> c} \<and> d fine p1
hoelzl@50526
  2222
        \<and> p2 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<le> c} \<and> d fine p2"
himmelma@35172
  2223
      show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e"
himmelma@35172
  2224
      proof- guess p using fine_division_exists[OF d(1), of a' b] . note p=this
himmelma@35172
  2225
        show ?thesis using norm_triangle_half_l[OF d(2)[of p1 p] d(2)[of p2 p]]
hoelzl@37489
  2226
          using as unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
haftmann@36350
  2227
          using p using assms by(auto simp add:algebra_simps)
himmelma@35172
  2228
      qed qed  
hoelzl@50526
  2229
    show "?P {x. x \<bullet> k \<ge> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
hoelzl@50526
  2230
    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<ge> c} \<and> d fine p1
hoelzl@50526
  2231
        \<and> p2 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<ge> c} \<and> d fine p2"
himmelma@35172
  2232
      show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e"
himmelma@35172
  2233
      proof- guess p using fine_division_exists[OF d(1), of a b'] . note p=this
himmelma@35172
  2234
        show ?thesis using norm_triangle_half_l[OF d(2)[of p p1] d(2)[of p p2]]
hoelzl@37489
  2235
          using as unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
haftmann@36350
  2236
          using p using assms by(auto simp add:algebra_simps) qed qed qed qed
himmelma@35172
  2237
himmelma@35172
  2238
subsection {* Generalized notion of additivity. *}
himmelma@35172
  2239
himmelma@35172
  2240
definition "neutral opp = (SOME x. \<forall>y. opp x y = y \<and> opp y x = y)"
himmelma@35172
  2241
hoelzl@37489
  2242
definition operative :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> (('b::ordered_euclidean_space) set \<Rightarrow> 'a) \<Rightarrow> bool" where
himmelma@35172
  2243
  "operative opp f \<equiv> 
himmelma@35172
  2244
    (\<forall>a b. content {a..b} = 0 \<longrightarrow> f {a..b} = neutral(opp)) \<and>
hoelzl@50526
  2245
    (\<forall>a b c. \<forall>k\<in>Basis. f({a..b}) =
hoelzl@50526
  2246
                   opp (f({a..b} \<inter> {x. x\<bullet>k \<le> c}))
hoelzl@50526
  2247
                       (f({a..b} \<inter> {x. x\<bullet>k \<ge> c})))"
hoelzl@37489
  2248
hoelzl@37489
  2249
lemma operativeD[dest]: fixes type::"'a::ordered_euclidean_space"  assumes "operative opp f"
hoelzl@37489
  2250
  shows "\<And>a b. content {a..b} = 0 \<Longrightarrow> f {a..b::'a} = neutral(opp)"
hoelzl@50526
  2251
  "\<And>a b c k. k\<in>Basis \<Longrightarrow> f({a..b}) = opp (f({a..b} \<inter> {x. x\<bullet>k \<le> c})) (f({a..b} \<inter> {x. x\<bullet>k \<ge> c}))"
himmelma@35172
  2252
  using assms unfolding operative_def by auto
himmelma@35172
  2253
himmelma@35172
  2254
lemma operative_trivial:
himmelma@35172
  2255
 "operative opp f \<Longrightarrow> content({a..b}) = 0 \<Longrightarrow> f({a..b}) = neutral opp"
himmelma@35172
  2256
  unfolding operative_def by auto
himmelma@35172
  2257
himmelma@35172
  2258
lemma property_empty_interval:
himmelma@35172
  2259
 "(\<forall>a b. content({a..b}) = 0 \<longrightarrow> P({a..b})) \<Longrightarrow> P {}" 
himmelma@35172
  2260
  using content_empty unfolding empty_as_interval by auto