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