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