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