Replaced Integration by Multivariate-Analysis/Real_Integration
authorhoelzl
Mon Feb 22 20:41:49 2010 +0100 (2010-02-22)
changeset 35292e4a431b6d9b7
parent 35291 ead7bfc30b26
child 35293 06a98796453e
Replaced Integration by Multivariate-Analysis/Real_Integration
src/HOL/Complex_Main.thy
src/HOL/Integration.thy
src/HOL/IsaMakefile
src/HOL/Multivariate_Analysis/Integration.cert
src/HOL/Multivariate_Analysis/Integration.thy
src/HOL/Multivariate_Analysis/Integration_MV.cert
src/HOL/Multivariate_Analysis/Integration_MV.thy
src/HOL/Multivariate_Analysis/Multivariate_Analysis.thy
src/HOL/Multivariate_Analysis/Real_Integration.thy
src/HOL/SEQ.thy
     1.1 --- a/src/HOL/Complex_Main.thy	Mon Feb 22 20:08:10 2010 +0100
     1.2 +++ b/src/HOL/Complex_Main.thy	Mon Feb 22 20:41:49 2010 +0100
     1.3 @@ -9,7 +9,7 @@
     1.4    Log
     1.5    Ln
     1.6    Taylor
     1.7 -  Integration
     1.8 +  Deriv
     1.9  begin
    1.10  
    1.11  end
     2.1 --- a/src/HOL/Integration.thy	Mon Feb 22 20:08:10 2010 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,658 +0,0 @@
     2.4 -(*  Author:     Jacques D. Fleuriot, University of Edinburgh
     2.5 -    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
     2.6 -*)
     2.7 -
     2.8 -header{*Theory of Integration*}
     2.9 -
    2.10 -theory Integration
    2.11 -imports Deriv ATP_Linkup
    2.12 -begin
    2.13 -
    2.14 -text{*We follow John Harrison in formalizing the Gauge integral.*}
    2.15 -
    2.16 -subsection {* Gauges *}
    2.17 -
    2.18 -definition
    2.19 -  gauge :: "[real set, real => real] => bool" where
    2.20 -  [code del]:"gauge E g = (\<forall>x\<in>E. 0 < g(x))"
    2.21 -
    2.22 -
    2.23 -subsection {* Gauge-fine divisions *}
    2.24 -
    2.25 -inductive
    2.26 -  fine :: "[real \<Rightarrow> real, real \<times> real, (real \<times> real \<times> real) list] \<Rightarrow> bool"
    2.27 -for
    2.28 -  \<delta> :: "real \<Rightarrow> real"
    2.29 -where
    2.30 -  fine_Nil:
    2.31 -    "fine \<delta> (a, a) []"
    2.32 -| fine_Cons:
    2.33 -    "\<lbrakk>fine \<delta> (b, c) D; a < b; a \<le> x; x \<le> b; b - a < \<delta> x\<rbrakk>
    2.34 -      \<Longrightarrow> fine \<delta> (a, c) ((a, x, b) # D)"
    2.35 -
    2.36 -lemmas fine_induct [induct set: fine] =
    2.37 -  fine.induct [of "\<delta>" "(a,b)" "D" "split P", unfolded split_conv, standard]
    2.38 -
    2.39 -lemma fine_single:
    2.40 -  "\<lbrakk>a < b; a \<le> x; x \<le> b; b - a < \<delta> x\<rbrakk> \<Longrightarrow> fine \<delta> (a, b) [(a, x, b)]"
    2.41 -by (rule fine_Cons [OF fine_Nil])
    2.42 -
    2.43 -lemma fine_append:
    2.44 -  "\<lbrakk>fine \<delta> (a, b) D; fine \<delta> (b, c) D'\<rbrakk> \<Longrightarrow> fine \<delta> (a, c) (D @ D')"
    2.45 -by (induct set: fine, simp, simp add: fine_Cons)
    2.46 -
    2.47 -lemma fine_imp_le: "fine \<delta> (a, b) D \<Longrightarrow> a \<le> b"
    2.48 -by (induct set: fine, simp_all)
    2.49 -
    2.50 -lemma nonempty_fine_imp_less: "\<lbrakk>fine \<delta> (a, b) D; D \<noteq> []\<rbrakk> \<Longrightarrow> a < b"
    2.51 -apply (induct set: fine, simp)
    2.52 -apply (drule fine_imp_le, simp)
    2.53 -done
    2.54 -
    2.55 -lemma empty_fine_imp_eq: "\<lbrakk>fine \<delta> (a, b) D; D = []\<rbrakk> \<Longrightarrow> a = b"
    2.56 -by (induct set: fine, simp_all)
    2.57 -
    2.58 -lemma fine_eq: "fine \<delta> (a, b) D \<Longrightarrow> a = b \<longleftrightarrow> D = []"
    2.59 -apply (cases "D = []")
    2.60 -apply (drule (1) empty_fine_imp_eq, simp)
    2.61 -apply (drule (1) nonempty_fine_imp_less, simp)
    2.62 -done
    2.63 -
    2.64 -lemma mem_fine:
    2.65 -  "\<lbrakk>fine \<delta> (a, b) D; (u, x, v) \<in> set D\<rbrakk> \<Longrightarrow> u < v \<and> u \<le> x \<and> x \<le> v"
    2.66 -by (induct set: fine, simp, force)
    2.67 -
    2.68 -lemma mem_fine2: "\<lbrakk>fine \<delta> (a, b) D; (u, z, v) \<in> set D\<rbrakk> \<Longrightarrow> a \<le> u \<and> v \<le> b"
    2.69 -apply (induct arbitrary: z u v set: fine, auto)
    2.70 -apply (simp add: fine_imp_le)
    2.71 -apply (erule order_trans [OF less_imp_le], simp)
    2.72 -done
    2.73 -
    2.74 -lemma mem_fine3: "\<lbrakk>fine \<delta> (a, b) D; (u, z, v) \<in> set D\<rbrakk> \<Longrightarrow> v - u < \<delta> z"
    2.75 -by (induct arbitrary: z u v set: fine) auto
    2.76 -
    2.77 -lemma BOLZANO:
    2.78 -  fixes P :: "real \<Rightarrow> real \<Rightarrow> bool"
    2.79 -  assumes 1: "a \<le> b"
    2.80 -  assumes 2: "\<And>a b c. \<lbrakk>P a b; P b c; a \<le> b; b \<le> c\<rbrakk> \<Longrightarrow> P a c"
    2.81 -  assumes 3: "\<And>x. \<exists>d>0. \<forall>a b. a \<le> x & x \<le> b & (b-a) < d \<longrightarrow> P a b"
    2.82 -  shows "P a b"
    2.83 -apply (subgoal_tac "split P (a,b)", simp)
    2.84 -apply (rule lemma_BOLZANO [OF _ _ 1])
    2.85 -apply (clarify, erule (3) 2)
    2.86 -apply (clarify, rule 3)
    2.87 -done
    2.88 -
    2.89 -text{*We can always find a division that is fine wrt any gauge*}
    2.90 -
    2.91 -lemma fine_exists:
    2.92 -  assumes "a \<le> b" and "gauge {a..b} \<delta>" shows "\<exists>D. fine \<delta> (a, b) D"
    2.93 -proof -
    2.94 -  {
    2.95 -    fix u v :: real assume "u \<le> v"
    2.96 -    have "a \<le> u \<Longrightarrow> v \<le> b \<Longrightarrow> \<exists>D. fine \<delta> (u, v) D"
    2.97 -      apply (induct u v rule: BOLZANO, rule `u \<le> v`)
    2.98 -       apply (simp, fast intro: fine_append)
    2.99 -      apply (case_tac "a \<le> x \<and> x \<le> b")
   2.100 -       apply (rule_tac x="\<delta> x" in exI)
   2.101 -       apply (rule conjI)
   2.102 -        apply (simp add: `gauge {a..b} \<delta>` [unfolded gauge_def])
   2.103 -       apply (clarify, rename_tac u v)
   2.104 -       apply (case_tac "u = v")
   2.105 -        apply (fast intro: fine_Nil)
   2.106 -       apply (subgoal_tac "u < v", fast intro: fine_single, simp)
   2.107 -      apply (rule_tac x="1" in exI, clarsimp)
   2.108 -      done
   2.109 -  }
   2.110 -  with `a \<le> b` show ?thesis by auto
   2.111 -qed
   2.112 -
   2.113 -lemma fine_covers_all:
   2.114 -  assumes "fine \<delta> (a, c) D" and "a < x" and "x \<le> c"
   2.115 -  shows "\<exists> N < length D. \<forall> d t e. D ! N = (d,t,e) \<longrightarrow> d < x \<and> x \<le> e"
   2.116 -  using assms
   2.117 -proof (induct set: fine)
   2.118 -  case (2 b c D a t)
   2.119 -  thus ?case
   2.120 -  proof (cases "b < x")
   2.121 -    case True
   2.122 -    with 2 obtain N where *: "N < length D"
   2.123 -      and **: "\<And> d t e. D ! N = (d,t,e) \<Longrightarrow> d < x \<and> x \<le> e" by auto
   2.124 -    hence "Suc N < length ((a,t,b)#D) \<and>
   2.125 -           (\<forall> d t' e. ((a,t,b)#D) ! Suc N = (d,t',e) \<longrightarrow> d < x \<and> x \<le> e)" by auto
   2.126 -    thus ?thesis by auto
   2.127 -  next
   2.128 -    case False with 2
   2.129 -    have "0 < length ((a,t,b)#D) \<and>
   2.130 -           (\<forall> d t' e. ((a,t,b)#D) ! 0 = (d,t',e) \<longrightarrow> d < x \<and> x \<le> e)" by auto
   2.131 -    thus ?thesis by auto
   2.132 -  qed
   2.133 -qed auto
   2.134 -
   2.135 -lemma fine_append_split:
   2.136 -  assumes "fine \<delta> (a,b) D" and "D2 \<noteq> []" and "D = D1 @ D2"
   2.137 -  shows "fine \<delta> (a,fst (hd D2)) D1" (is "?fine1")
   2.138 -  and "fine \<delta> (fst (hd D2), b) D2" (is "?fine2")
   2.139 -proof -
   2.140 -  from assms
   2.141 -  have "?fine1 \<and> ?fine2"
   2.142 -  proof (induct arbitrary: D1 D2)
   2.143 -    case (2 b c D a' x D1 D2)
   2.144 -    note induct = this
   2.145 -
   2.146 -    thus ?case
   2.147 -    proof (cases D1)
   2.148 -      case Nil
   2.149 -      hence "fst (hd D2) = a'" using 2 by auto
   2.150 -      with fine_Cons[OF `fine \<delta> (b,c) D` induct(3,4,5)] Nil induct
   2.151 -      show ?thesis by (auto intro: fine_Nil)
   2.152 -    next
   2.153 -      case (Cons d1 D1')
   2.154 -      with induct(2)[OF `D2 \<noteq> []`, of D1'] induct(8)
   2.155 -      have "fine \<delta> (b, fst (hd D2)) D1'" and "fine \<delta> (fst (hd D2), c) D2" and
   2.156 -        "d1 = (a', x, b)" by auto
   2.157 -      with fine_Cons[OF this(1) induct(3,4,5), OF induct(6)] Cons
   2.158 -      show ?thesis by auto
   2.159 -    qed
   2.160 -  qed auto
   2.161 -  thus ?fine1 and ?fine2 by auto
   2.162 -qed
   2.163 -
   2.164 -lemma fine_\<delta>_expand:
   2.165 -  assumes "fine \<delta> (a,b) D"
   2.166 -  and "\<And> x. \<lbrakk> a \<le> x ; x \<le> b \<rbrakk> \<Longrightarrow> \<delta> x \<le> \<delta>' x"
   2.167 -  shows "fine \<delta>' (a,b) D"
   2.168 -using assms proof induct
   2.169 -  case 1 show ?case by (rule fine_Nil)
   2.170 -next
   2.171 -  case (2 b c D a x)
   2.172 -  show ?case
   2.173 -  proof (rule fine_Cons)
   2.174 -    show "fine \<delta>' (b,c) D" using 2 by auto
   2.175 -    from fine_imp_le[OF 2(1)] 2(6) `x \<le> b`
   2.176 -    show "b - a < \<delta>' x"
   2.177 -      using 2(7)[OF `a \<le> x`] by auto
   2.178 -  qed (auto simp add: 2)
   2.179 -qed
   2.180 -
   2.181 -lemma fine_single_boundaries:
   2.182 -  assumes "fine \<delta> (a,b) D" and "D = [(d, t, e)]"
   2.183 -  shows "a = d \<and> b = e"
   2.184 -using assms proof induct
   2.185 -  case (2 b c  D a x)
   2.186 -  hence "D = []" and "a = d" and "b = e" by auto
   2.187 -  moreover
   2.188 -  from `fine \<delta> (b,c) D` `D = []` have "b = c"
   2.189 -    by (rule empty_fine_imp_eq)
   2.190 -  ultimately show ?case by simp
   2.191 -qed auto
   2.192 -
   2.193 -
   2.194 -subsection {* Riemann sum *}
   2.195 -
   2.196 -definition
   2.197 -  rsum :: "[(real \<times> real \<times> real) list, real \<Rightarrow> real] \<Rightarrow> real" where
   2.198 -  "rsum D f = (\<Sum>(u, x, v)\<leftarrow>D. f x * (v - u))"
   2.199 -
   2.200 -lemma rsum_Nil [simp]: "rsum [] f = 0"
   2.201 -unfolding rsum_def by simp
   2.202 -
   2.203 -lemma rsum_Cons [simp]: "rsum ((u, x, v) # D) f = f x * (v - u) + rsum D f"
   2.204 -unfolding rsum_def by simp
   2.205 -
   2.206 -lemma rsum_zero [simp]: "rsum D (\<lambda>x. 0) = 0"
   2.207 -by (induct D, auto)
   2.208 -
   2.209 -lemma rsum_left_distrib: "rsum D f * c = rsum D (\<lambda>x. f x * c)"
   2.210 -by (induct D, auto simp add: algebra_simps)
   2.211 -
   2.212 -lemma rsum_right_distrib: "c * rsum D f = rsum D (\<lambda>x. c * f x)"
   2.213 -by (induct D, auto simp add: algebra_simps)
   2.214 -
   2.215 -lemma rsum_add: "rsum D (\<lambda>x. f x + g x) =  rsum D f + rsum D g"
   2.216 -by (induct D, auto simp add: algebra_simps)
   2.217 -
   2.218 -lemma rsum_append: "rsum (D1 @ D2) f = rsum D1 f + rsum D2 f"
   2.219 -unfolding rsum_def map_append listsum_append ..
   2.220 -
   2.221 -
   2.222 -subsection {* Gauge integrability (definite) *}
   2.223 -
   2.224 -definition
   2.225 -  Integral :: "[(real*real),real=>real,real] => bool" where
   2.226 -  [code del]: "Integral = (%(a,b) f k. \<forall>e > 0.
   2.227 -                               (\<exists>\<delta>. gauge {a .. b} \<delta> &
   2.228 -                               (\<forall>D. fine \<delta> (a,b) D -->
   2.229 -                                         \<bar>rsum D f - k\<bar> < e)))"
   2.230 -
   2.231 -lemma Integral_def2:
   2.232 -  "Integral = (%(a,b) f k. \<forall>e>0. (\<exists>\<delta>. gauge {a..b} \<delta> &
   2.233 -                               (\<forall>D. fine \<delta> (a,b) D -->
   2.234 -                                         \<bar>rsum D f - k\<bar> \<le> e)))"
   2.235 -unfolding Integral_def
   2.236 -apply (safe intro!: ext)
   2.237 -apply (fast intro: less_imp_le)
   2.238 -apply (drule_tac x="e/2" in spec)
   2.239 -apply force
   2.240 -done
   2.241 -
   2.242 -text{*Lemmas about combining gauges*}
   2.243 -
   2.244 -lemma gauge_min:
   2.245 -     "[| gauge(E) g1; gauge(E) g2 |]
   2.246 -      ==> gauge(E) (%x. min (g1(x)) (g2(x)))"
   2.247 -by (simp add: gauge_def)
   2.248 -
   2.249 -lemma fine_min:
   2.250 -      "fine (%x. min (g1(x)) (g2(x))) (a,b) D
   2.251 -       ==> fine(g1) (a,b) D & fine(g2) (a,b) D"
   2.252 -apply (erule fine.induct)
   2.253 -apply (simp add: fine_Nil)
   2.254 -apply (simp add: fine_Cons)
   2.255 -done
   2.256 -
   2.257 -text{*The integral is unique if it exists*}
   2.258 -
   2.259 -lemma Integral_unique:
   2.260 -    "[| a \<le> b; Integral(a,b) f k1; Integral(a,b) f k2 |] ==> k1 = k2"
   2.261 -apply (simp add: Integral_def)
   2.262 -apply (drule_tac x = "\<bar>k1 - k2\<bar> /2" in spec)+
   2.263 -apply auto
   2.264 -apply (drule gauge_min, assumption)
   2.265 -apply (drule_tac \<delta> = "%x. min (\<delta> x) (\<delta>' x)"
   2.266 -       in fine_exists, assumption, auto)
   2.267 -apply (drule fine_min)
   2.268 -apply (drule spec)+
   2.269 -apply auto
   2.270 -apply (subgoal_tac "\<bar>(rsum D f - k2) - (rsum D f - k1)\<bar> < \<bar>k1 - k2\<bar>")
   2.271 -apply arith
   2.272 -apply (drule add_strict_mono, assumption)
   2.273 -apply (auto simp only: left_distrib [symmetric] mult_2_right [symmetric] 
   2.274 -                mult_less_cancel_right)
   2.275 -done
   2.276 -
   2.277 -lemma Integral_zero [simp]: "Integral(a,a) f 0"
   2.278 -apply (auto simp add: Integral_def)
   2.279 -apply (rule_tac x = "%x. 1" in exI)
   2.280 -apply (auto dest: fine_eq simp add: gauge_def rsum_def)
   2.281 -done
   2.282 -
   2.283 -lemma fine_rsum_const: "fine \<delta> (a,b) D \<Longrightarrow> rsum D (\<lambda>x. c) = (c * (b - a))"
   2.284 -unfolding rsum_def
   2.285 -by (induct set: fine, auto simp add: algebra_simps)
   2.286 -
   2.287 -lemma Integral_eq_diff_bounds: "a \<le> b ==> Integral(a,b) (%x. 1) (b - a)"
   2.288 -apply (cases "a = b", simp)
   2.289 -apply (simp add: Integral_def, clarify)
   2.290 -apply (rule_tac x = "%x. b - a" in exI)
   2.291 -apply (rule conjI, simp add: gauge_def)
   2.292 -apply (clarify)
   2.293 -apply (subst fine_rsum_const, assumption, simp)
   2.294 -done
   2.295 -
   2.296 -lemma Integral_mult_const: "a \<le> b ==> Integral(a,b) (%x. c)  (c*(b - a))"
   2.297 -apply (cases "a = b", simp)
   2.298 -apply (simp add: Integral_def, clarify)
   2.299 -apply (rule_tac x = "%x. b - a" in exI)
   2.300 -apply (rule conjI, simp add: gauge_def)
   2.301 -apply (clarify)
   2.302 -apply (subst fine_rsum_const, assumption, simp)
   2.303 -done
   2.304 -
   2.305 -lemma Integral_mult:
   2.306 -     "[| a \<le> b; Integral(a,b) f k |] ==> Integral(a,b) (%x. c * f x) (c * k)"
   2.307 -apply (auto simp add: order_le_less 
   2.308 -            dest: Integral_unique [OF order_refl Integral_zero])
   2.309 -apply (auto simp add: Integral_def setsum_right_distrib[symmetric] mult_assoc)
   2.310 -apply (case_tac "c = 0", force)
   2.311 -apply (drule_tac x = "e/abs c" in spec)
   2.312 -apply (simp add: divide_pos_pos)
   2.313 -apply clarify
   2.314 -apply (rule_tac x="\<delta>" in exI, clarify)
   2.315 -apply (drule_tac x="D" in spec, clarify)
   2.316 -apply (simp add: pos_less_divide_eq abs_mult [symmetric]
   2.317 -                 algebra_simps rsum_right_distrib)
   2.318 -done
   2.319 -
   2.320 -lemma Integral_add:
   2.321 -  assumes "Integral (a, b) f x1"
   2.322 -  assumes "Integral (b, c) f x2"
   2.323 -  assumes "a \<le> b" and "b \<le> c"
   2.324 -  shows "Integral (a, c) f (x1 + x2)"
   2.325 -proof (cases "a < b \<and> b < c", simp only: Integral_def split_conv, rule allI, rule impI)
   2.326 -  fix \<epsilon> :: real assume "0 < \<epsilon>"
   2.327 -  hence "0 < \<epsilon> / 2" by auto
   2.328 -
   2.329 -  assume "a < b \<and> b < c"
   2.330 -  hence "a < b" and "b < c" by auto
   2.331 -
   2.332 -  from `Integral (a, b) f x1`[simplified Integral_def split_conv,
   2.333 -                              rule_format, OF `0 < \<epsilon>/2`]
   2.334 -  obtain \<delta>1 where \<delta>1_gauge: "gauge {a..b} \<delta>1"
   2.335 -    and I1: "\<And> D. fine \<delta>1 (a,b) D \<Longrightarrow> \<bar> rsum D f - x1 \<bar> < (\<epsilon> / 2)" by auto
   2.336 -
   2.337 -  from `Integral (b, c) f x2`[simplified Integral_def split_conv,
   2.338 -                              rule_format, OF `0 < \<epsilon>/2`]
   2.339 -  obtain \<delta>2 where \<delta>2_gauge: "gauge {b..c} \<delta>2"
   2.340 -    and I2: "\<And> D. fine \<delta>2 (b,c) D \<Longrightarrow> \<bar> rsum D f - x2 \<bar> < (\<epsilon> / 2)" by auto
   2.341 -
   2.342 -  def \<delta> \<equiv> "\<lambda> x. if x < b then min (\<delta>1 x) (b - x)
   2.343 -           else if x = b then min (\<delta>1 b) (\<delta>2 b)
   2.344 -                         else min (\<delta>2 x) (x - b)"
   2.345 -
   2.346 -  have "gauge {a..c} \<delta>"
   2.347 -    using \<delta>1_gauge \<delta>2_gauge unfolding \<delta>_def gauge_def by auto
   2.348 -  moreover {
   2.349 -    fix D :: "(real \<times> real \<times> real) list"
   2.350 -    assume fine: "fine \<delta> (a,c) D"
   2.351 -    from fine_covers_all[OF this `a < b` `b \<le> c`]
   2.352 -    obtain N where "N < length D"
   2.353 -      and *: "\<forall> d t e. D ! N = (d, t, e) \<longrightarrow> d < b \<and> b \<le> e"
   2.354 -      by auto
   2.355 -    obtain d t e where D_eq: "D ! N = (d, t, e)" by (cases "D!N", auto)
   2.356 -    with * have "d < b" and "b \<le> e" by auto
   2.357 -    have in_D: "(d, t, e) \<in> set D"
   2.358 -      using D_eq[symmetric] using `N < length D` by auto
   2.359 -
   2.360 -    from mem_fine[OF fine in_D]
   2.361 -    have "d < e" and "d \<le> t" and "t \<le> e" by auto
   2.362 -
   2.363 -    have "t = b"
   2.364 -    proof (rule ccontr)
   2.365 -      assume "t \<noteq> b"
   2.366 -      with mem_fine3[OF fine in_D] `b \<le> e` `d \<le> t` `t \<le> e` `d < b` \<delta>_def
   2.367 -      show False by (cases "t < b") auto
   2.368 -    qed
   2.369 -
   2.370 -    let ?D1 = "take N D"
   2.371 -    let ?D2 = "drop N D"
   2.372 -    def D1 \<equiv> "take N D @ [(d, t, b)]"
   2.373 -    def D2 \<equiv> "(if b = e then [] else [(b, t, e)]) @ drop (Suc N) D"
   2.374 -
   2.375 -    have "D \<noteq> []" using `N < length D` by auto
   2.376 -    from hd_drop_conv_nth[OF this `N < length D`]
   2.377 -    have "fst (hd ?D2) = d" using `D ! N = (d, t, e)` by auto
   2.378 -    with fine_append_split[OF _ _ append_take_drop_id[symmetric]]
   2.379 -    have fine1: "fine \<delta> (a,d) ?D1" and fine2: "fine \<delta> (d,c) ?D2"
   2.380 -      using `N < length D` fine by auto
   2.381 -
   2.382 -    have "fine \<delta>1 (a,b) D1" unfolding D1_def
   2.383 -    proof (rule fine_append)
   2.384 -      show "fine \<delta>1 (a, d) ?D1"
   2.385 -      proof (rule fine1[THEN fine_\<delta>_expand])
   2.386 -        fix x assume "a \<le> x" "x \<le> d"
   2.387 -        hence "x \<le> b" using `d < b` `x \<le> d` by auto
   2.388 -        thus "\<delta> x \<le> \<delta>1 x" unfolding \<delta>_def by auto
   2.389 -      qed
   2.390 -
   2.391 -      have "b - d < \<delta>1 t"
   2.392 -        using mem_fine3[OF fine in_D] \<delta>_def `b \<le> e` `t = b` by auto
   2.393 -      from `d < b` `d \<le> t` `t = b` this
   2.394 -      show "fine \<delta>1 (d, b) [(d, t, b)]" using fine_single by auto
   2.395 -    qed
   2.396 -    note rsum1 = I1[OF this]
   2.397 -
   2.398 -    have drop_split: "drop N D = [D ! N] @ drop (Suc N) D"
   2.399 -      using nth_drop'[OF `N < length D`] by simp
   2.400 -
   2.401 -    have fine2: "fine \<delta>2 (e,c) (drop (Suc N) D)"
   2.402 -    proof (cases "drop (Suc N) D = []")
   2.403 -      case True
   2.404 -      note * = fine2[simplified drop_split True D_eq append_Nil2]
   2.405 -      have "e = c" using fine_single_boundaries[OF * refl] by auto
   2.406 -      thus ?thesis unfolding True using fine_Nil by auto
   2.407 -    next
   2.408 -      case False
   2.409 -      note * = fine_append_split[OF fine2 False drop_split]
   2.410 -      from fine_single_boundaries[OF *(1)]
   2.411 -      have "fst (hd (drop (Suc N) D)) = e" using D_eq by auto
   2.412 -      with *(2) have "fine \<delta> (e,c) (drop (Suc N) D)" by auto
   2.413 -      thus ?thesis
   2.414 -      proof (rule fine_\<delta>_expand)
   2.415 -        fix x assume "e \<le> x" and "x \<le> c"
   2.416 -        thus "\<delta> x \<le> \<delta>2 x" using `b \<le> e` unfolding \<delta>_def by auto
   2.417 -      qed
   2.418 -    qed
   2.419 -
   2.420 -    have "fine \<delta>2 (b, c) D2"
   2.421 -    proof (cases "e = b")
   2.422 -      case True thus ?thesis using fine2 by (simp add: D1_def D2_def)
   2.423 -    next
   2.424 -      case False
   2.425 -      have "e - b < \<delta>2 b"
   2.426 -        using mem_fine3[OF fine in_D] \<delta>_def `d < b` `t = b` by auto
   2.427 -      with False `t = b` `b \<le> e`
   2.428 -      show ?thesis using D2_def
   2.429 -        by (auto intro!: fine_append[OF _ fine2] fine_single
   2.430 -               simp del: append_Cons)
   2.431 -    qed
   2.432 -    note rsum2 = I2[OF this]
   2.433 -
   2.434 -    have "rsum D f = rsum (take N D) f + rsum [D ! N] f + rsum (drop (Suc N) D) f"
   2.435 -      using rsum_append[symmetric] nth_drop'[OF `N < length D`] by auto
   2.436 -    also have "\<dots> = rsum D1 f + rsum D2 f"
   2.437 -      by (cases "b = e", auto simp add: D1_def D2_def D_eq rsum_append algebra_simps)
   2.438 -    finally have "\<bar>rsum D f - (x1 + x2)\<bar> < \<epsilon>"
   2.439 -      using add_strict_mono[OF rsum1 rsum2] by simp
   2.440 -  }
   2.441 -  ultimately show "\<exists> \<delta>. gauge {a .. c} \<delta> \<and>
   2.442 -    (\<forall>D. fine \<delta> (a,c) D \<longrightarrow> \<bar>rsum D f - (x1 + x2)\<bar> < \<epsilon>)"
   2.443 -    by blast
   2.444 -next
   2.445 -  case False
   2.446 -  hence "a = b \<or> b = c" using `a \<le> b` and `b \<le> c` by auto
   2.447 -  thus ?thesis
   2.448 -  proof (rule disjE)
   2.449 -    assume "a = b" hence "x1 = 0"
   2.450 -      using `Integral (a, b) f x1` Integral_zero Integral_unique[of a b] by auto
   2.451 -    thus ?thesis using `a = b` `Integral (b, c) f x2` by auto
   2.452 -  next
   2.453 -    assume "b = c" hence "x2 = 0"
   2.454 -      using `Integral (b, c) f x2` Integral_zero Integral_unique[of b c] by auto
   2.455 -    thus ?thesis using `b = c` `Integral (a, b) f x1` by auto
   2.456 -  qed
   2.457 -qed
   2.458 -
   2.459 -text{*Fundamental theorem of calculus (Part I)*}
   2.460 -
   2.461 -text{*"Straddle Lemma" : Swartz and Thompson: AMM 95(7) 1988 *}
   2.462 -
   2.463 -lemma strad1:
   2.464 -       "\<lbrakk>\<forall>z::real. z \<noteq> x \<and> \<bar>z - x\<bar> < s \<longrightarrow>
   2.465 -             \<bar>(f z - f x) / (z - x) - f' x\<bar> < e/2;
   2.466 -        0 < s; 0 < e; a \<le> x; x \<le> b\<rbrakk>
   2.467 -       \<Longrightarrow> \<forall>z. \<bar>z - x\<bar> < s -->\<bar>f z - f x - f' x * (z - x)\<bar> \<le> e/2 * \<bar>z - x\<bar>"
   2.468 -apply clarify
   2.469 -apply (case_tac "z = x", simp)
   2.470 -apply (drule_tac x = z in spec)
   2.471 -apply (rule_tac z1 = "\<bar>inverse (z - x)\<bar>" 
   2.472 -       in real_mult_le_cancel_iff2 [THEN iffD1])
   2.473 - apply simp
   2.474 -apply (simp del: abs_inverse abs_mult add: abs_mult [symmetric]
   2.475 -          mult_assoc [symmetric])
   2.476 -apply (subgoal_tac "inverse (z - x) * (f z - f x - f' x * (z - x)) 
   2.477 -                    = (f z - f x) / (z - x) - f' x")
   2.478 - apply (simp add: abs_mult [symmetric] mult_ac diff_minus)
   2.479 -apply (subst mult_commute)
   2.480 -apply (simp add: left_distrib diff_minus)
   2.481 -apply (simp add: mult_assoc divide_inverse)
   2.482 -apply (simp add: left_distrib)
   2.483 -done
   2.484 -
   2.485 -lemma lemma_straddle:
   2.486 -  assumes f': "\<forall>x. a \<le> x & x \<le> b --> DERIV f x :> f'(x)" and "0 < e"
   2.487 -  shows "\<exists>g. gauge {a..b} g &
   2.488 -                (\<forall>x u v. a \<le> u & u \<le> x & x \<le> v & v \<le> b & (v - u) < g(x)
   2.489 -                  --> \<bar>(f(v) - f(u)) - (f'(x) * (v - u))\<bar> \<le> e * (v - u))"
   2.490 -proof -
   2.491 -  have "\<forall>x\<in>{a..b}.
   2.492 -        (\<exists>d > 0. \<forall>u v. u \<le> x & x \<le> v & (v - u) < d --> 
   2.493 -                       \<bar>(f(v) - f(u)) - (f'(x) * (v - u))\<bar> \<le> e * (v - u))"
   2.494 -  proof (clarsimp)
   2.495 -    fix x :: real assume "a \<le> x" and "x \<le> b"
   2.496 -    with f' have "DERIV f x :> f'(x)" by simp
   2.497 -    then have "\<forall>r>0. \<exists>s>0. \<forall>z. z \<noteq> x \<and> \<bar>z - x\<bar> < s \<longrightarrow> \<bar>(f z - f x) / (z - x) - f' x\<bar> < r"
   2.498 -      by (simp add: DERIV_iff2 LIM_eq)
   2.499 -    with `0 < e` obtain s
   2.500 -    where "\<forall>z. z \<noteq> x \<and> \<bar>z - x\<bar> < s \<longrightarrow> \<bar>(f z - f x) / (z - x) - f' x\<bar> < e/2" and "0 < s"
   2.501 -      by (drule_tac x="e/2" in spec, auto)
   2.502 -    then have strad [rule_format]:
   2.503 -        "\<forall>z. \<bar>z - x\<bar> < s --> \<bar>f z - f x - f' x * (z - x)\<bar> \<le> e/2 * \<bar>z - x\<bar>"
   2.504 -      using `0 < e` `a \<le> x` `x \<le> b` by (rule strad1)
   2.505 -    show "\<exists>d>0. \<forall>u v. u \<le> x \<and> x \<le> v \<and> v - u < d \<longrightarrow> \<bar>f v - f u - f' x * (v - u)\<bar> \<le> e * (v - u)"
   2.506 -    proof (safe intro!: exI)
   2.507 -      show "0 < s" by fact
   2.508 -    next
   2.509 -      fix u v :: real assume "u \<le> x" and "x \<le> v" and "v - u < s"
   2.510 -      have "\<bar>f v - f u - f' x * (v - u)\<bar> =
   2.511 -            \<bar>(f v - f x - f' x * (v - x)) + (f x - f u - f' x * (x - u))\<bar>"
   2.512 -        by (simp add: right_diff_distrib)
   2.513 -      also have "\<dots> \<le> \<bar>f v - f x - f' x * (v - x)\<bar> + \<bar>f x - f u - f' x * (x - u)\<bar>"
   2.514 -        by (rule abs_triangle_ineq)
   2.515 -      also have "\<dots> = \<bar>f v - f x - f' x * (v - x)\<bar> + \<bar>f u - f x - f' x * (u - x)\<bar>"
   2.516 -        by (simp add: right_diff_distrib)
   2.517 -      also have "\<dots> \<le> (e/2) * \<bar>v - x\<bar> + (e/2) * \<bar>u - x\<bar>"
   2.518 -        using `u \<le> x` `x \<le> v` `v - u < s` by (intro add_mono strad, simp_all)
   2.519 -      also have "\<dots> \<le> e * (v - u) / 2 + e * (v - u) / 2"
   2.520 -        using `u \<le> x` `x \<le> v` `0 < e` by (intro add_mono, simp_all)
   2.521 -      also have "\<dots> = e * (v - u)"
   2.522 -        by simp
   2.523 -      finally show "\<bar>f v - f u - f' x * (v - u)\<bar> \<le> e * (v - u)" .
   2.524 -    qed
   2.525 -  qed
   2.526 -  thus ?thesis
   2.527 -    by (simp add: gauge_def) (drule bchoice, auto)
   2.528 -qed
   2.529 -
   2.530 -lemma fine_listsum_eq_diff:
   2.531 -  fixes f :: "real \<Rightarrow> real"
   2.532 -  shows "fine \<delta> (a, b) D \<Longrightarrow> (\<Sum>(u, x, v)\<leftarrow>D. f v - f u) = f b - f a"
   2.533 -by (induct set: fine) simp_all
   2.534 -
   2.535 -lemma FTC1: "[|a \<le> b; \<forall>x. a \<le> x & x \<le> b --> DERIV f x :> f'(x) |]
   2.536 -             ==> Integral(a,b) f' (f(b) - f(a))"
   2.537 - apply (drule order_le_imp_less_or_eq, auto)
   2.538 - apply (auto simp add: Integral_def2)
   2.539 - apply (drule_tac e = "e / (b - a)" in lemma_straddle)
   2.540 -  apply (simp add: divide_pos_pos)
   2.541 - apply clarify
   2.542 - apply (rule_tac x="g" in exI, clarify)
   2.543 - apply (clarsimp simp add: rsum_def)
   2.544 - apply (frule fine_listsum_eq_diff [where f=f])
   2.545 - apply (erule subst)
   2.546 - apply (subst listsum_subtractf [symmetric])
   2.547 - apply (rule listsum_abs [THEN order_trans])
   2.548 - apply (subst map_map [unfolded o_def])
   2.549 - apply (subgoal_tac "e = (\<Sum>(u, x, v)\<leftarrow>D. (e / (b - a)) * (v - u))")
   2.550 -  apply (erule ssubst)
   2.551 -  apply (simp add: abs_minus_commute)
   2.552 -  apply (rule listsum_mono)
   2.553 -  apply (clarify, rename_tac u x v)
   2.554 -  apply ((drule spec)+, erule mp)
   2.555 -  apply (simp add: mem_fine mem_fine2 mem_fine3)
   2.556 - apply (frule fine_listsum_eq_diff [where f="\<lambda>x. x"])
   2.557 - apply (simp only: split_def)
   2.558 - apply (subst listsum_const_mult)
   2.559 - apply simp
   2.560 -done
   2.561 -
   2.562 -lemma Integral_subst: "[| Integral(a,b) f k1; k2=k1 |] ==> Integral(a,b) f k2"
   2.563 -by simp
   2.564 -
   2.565 -subsection {* Additivity Theorem of Gauge Integral *}
   2.566 -
   2.567 -text{* Bartle/Sherbert: Theorem 10.1.5 p. 278 *}
   2.568 -lemma Integral_add_fun:
   2.569 -    "[| a \<le> b; Integral(a,b) f k1; Integral(a,b) g k2 |]
   2.570 -     ==> Integral(a,b) (%x. f x + g x) (k1 + k2)"
   2.571 -unfolding Integral_def
   2.572 -apply clarify
   2.573 -apply (drule_tac x = "e/2" in spec)+
   2.574 -apply clarsimp
   2.575 -apply (rule_tac x = "\<lambda>x. min (\<delta> x) (\<delta>' x)" in exI)
   2.576 -apply (rule conjI, erule (1) gauge_min)
   2.577 -apply clarify
   2.578 -apply (drule fine_min)
   2.579 -apply (drule_tac x=D in spec, simp)+
   2.580 -apply (drule_tac a = "\<bar>rsum D f - k1\<bar> * 2" and c = "\<bar>rsum D g - k2\<bar> * 2" in add_strict_mono, assumption)
   2.581 -apply (auto simp only: rsum_add left_distrib [symmetric]
   2.582 -                mult_2_right [symmetric] real_mult_less_iff1)
   2.583 -done
   2.584 -
   2.585 -lemma lemma_Integral_rsum_le:
   2.586 -     "[| \<forall>x. a \<le> x & x \<le> b --> f x \<le> g x;
   2.587 -         fine \<delta> (a,b) D
   2.588 -      |] ==> rsum D f \<le> rsum D g"
   2.589 -unfolding rsum_def
   2.590 -apply (rule listsum_mono)
   2.591 -apply clarify
   2.592 -apply (rule mult_right_mono)
   2.593 -apply (drule spec, erule mp)
   2.594 -apply (frule (1) mem_fine)
   2.595 -apply (frule (1) mem_fine2)
   2.596 -apply simp
   2.597 -apply (frule (1) mem_fine)
   2.598 -apply simp
   2.599 -done
   2.600 -
   2.601 -lemma Integral_le:
   2.602 -    "[| a \<le> b;
   2.603 -        \<forall>x. a \<le> x & x \<le> b --> f(x) \<le> g(x);
   2.604 -        Integral(a,b) f k1; Integral(a,b) g k2
   2.605 -     |] ==> k1 \<le> k2"
   2.606 -apply (simp add: Integral_def)
   2.607 -apply (rotate_tac 2)
   2.608 -apply (drule_tac x = "\<bar>k1 - k2\<bar> /2" in spec)
   2.609 -apply (drule_tac x = "\<bar>k1 - k2\<bar> /2" in spec, auto)
   2.610 -apply (drule gauge_min, assumption)
   2.611 -apply (drule_tac \<delta> = "\<lambda>x. min (\<delta> x) (\<delta>' x)" in fine_exists, assumption, clarify)
   2.612 -apply (drule fine_min)
   2.613 -apply (drule_tac x = D in spec, drule_tac x = D in spec, clarsimp)
   2.614 -apply (frule lemma_Integral_rsum_le, assumption)
   2.615 -apply (subgoal_tac "\<bar>(rsum D f - k1) - (rsum D g - k2)\<bar> < \<bar>k1 - k2\<bar>")
   2.616 -apply arith
   2.617 -apply (drule add_strict_mono, assumption)
   2.618 -apply (auto simp only: left_distrib [symmetric] mult_2_right [symmetric]
   2.619 -                       real_mult_less_iff1)
   2.620 -done
   2.621 -
   2.622 -lemma Integral_imp_Cauchy:
   2.623 -     "(\<exists>k. Integral(a,b) f k) ==>
   2.624 -      (\<forall>e > 0. \<exists>\<delta>. gauge {a..b} \<delta> &
   2.625 -                       (\<forall>D1 D2.
   2.626 -                            fine \<delta> (a,b) D1 &
   2.627 -                            fine \<delta> (a,b) D2 -->
   2.628 -                            \<bar>rsum D1 f - rsum D2 f\<bar> < e))"
   2.629 -apply (simp add: Integral_def, auto)
   2.630 -apply (drule_tac x = "e/2" in spec, auto)
   2.631 -apply (rule exI, auto)
   2.632 -apply (frule_tac x = D1 in spec)
   2.633 -apply (drule_tac x = D2 in spec)
   2.634 -apply simp
   2.635 -apply (thin_tac "0 < e")
   2.636 -apply (drule add_strict_mono, assumption)
   2.637 -apply (auto simp only: left_distrib [symmetric] mult_2_right [symmetric]
   2.638 -                       real_mult_less_iff1)
   2.639 -done
   2.640 -
   2.641 -lemma Cauchy_iff2:
   2.642 -     "Cauchy X =
   2.643 -      (\<forall>j. (\<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. \<bar>X m - X n\<bar> < inverse(real (Suc j))))"
   2.644 -apply (simp add: Cauchy_iff, auto)
   2.645 -apply (drule reals_Archimedean, safe)
   2.646 -apply (drule_tac x = n in spec, auto)
   2.647 -apply (rule_tac x = M in exI, auto)
   2.648 -apply (drule_tac x = m in spec, simp)
   2.649 -apply (drule_tac x = na in spec, auto)
   2.650 -done
   2.651 -
   2.652 -lemma monotonic_anti_derivative:
   2.653 -  fixes f g :: "real => real" shows
   2.654 -     "[| a \<le> b; \<forall>c. a \<le> c & c \<le> b --> f' c \<le> g' c;
   2.655 -         \<forall>x. DERIV f x :> f' x; \<forall>x. DERIV g x :> g' x |]
   2.656 -      ==> f b - f a \<le> g b - g a"
   2.657 -apply (rule Integral_le, assumption)
   2.658 -apply (auto intro: FTC1) 
   2.659 -done
   2.660 -
   2.661 -end
     3.1 --- a/src/HOL/IsaMakefile	Mon Feb 22 20:08:10 2010 +0100
     3.2 +++ b/src/HOL/IsaMakefile	Mon Feb 22 20:41:49 2010 +0100
     3.3 @@ -344,7 +344,6 @@
     3.4    Deriv.thy \
     3.5    Fact.thy \
     3.6    GCD.thy \
     3.7 -  Integration.thy \
     3.8    Lim.thy \
     3.9    Limits.thy \
    3.10    Ln.thy \
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/HOL/Multivariate_Analysis/Integration.cert	Mon Feb 22 20:41:49 2010 +0100
     4.3 @@ -0,0 +1,3296 @@
     4.4 +tB2Atlor9W4pSnrAz5nHpw 907 0
     4.5 +#2 := false
     4.6 +#299 := 0::real
     4.7 +decl uf_1 :: (-> T3 T2 real)
     4.8 +decl uf_10 :: (-> T4 T2)
     4.9 +decl uf_7 :: T4
    4.10 +#15 := uf_7
    4.11 +#22 := (uf_10 uf_7)
    4.12 +decl uf_2 :: (-> T1 T3)
    4.13 +decl uf_4 :: T1
    4.14 +#11 := uf_4
    4.15 +#91 := (uf_2 uf_4)
    4.16 +#902 := (uf_1 #91 #22)
    4.17 +#297 := -1::real
    4.18 +#1084 := (* -1::real #902)
    4.19 +decl uf_16 :: T1
    4.20 +#50 := uf_16
    4.21 +#78 := (uf_2 uf_16)
    4.22 +#799 := (uf_1 #78 #22)
    4.23 +#1267 := (+ #799 #1084)
    4.24 +#1272 := (>= #1267 0::real)
    4.25 +#1266 := (= #799 #902)
    4.26 +decl uf_9 :: T3
    4.27 +#21 := uf_9
    4.28 +#23 := (uf_1 uf_9 #22)
    4.29 +#905 := (= #23 #902)
    4.30 +decl uf_11 :: T3
    4.31 +#24 := uf_11
    4.32 +#850 := (uf_1 uf_11 #22)
    4.33 +#904 := (= #850 #902)
    4.34 +decl uf_6 :: (-> T2 T4)
    4.35 +#74 := (uf_6 #22)
    4.36 +#281 := (= uf_7 #74)
    4.37 +#922 := (ite #281 #905 #904)
    4.38 +decl uf_8 :: T3
    4.39 +#18 := uf_8
    4.40 +#848 := (uf_1 uf_8 #22)
    4.41 +#903 := (= #848 #902)
    4.42 +#60 := 0::int
    4.43 +decl uf_5 :: (-> T4 int)
    4.44 +#803 := (uf_5 #74)
    4.45 +#117 := -1::int
    4.46 +#813 := (* -1::int #803)
    4.47 +#16 := (uf_5 uf_7)
    4.48 +#916 := (+ #16 #813)
    4.49 +#917 := (<= #916 0::int)
    4.50 +#925 := (ite #917 #922 #903)
    4.51 +#6 := (:var 0 T2)
    4.52 +#19 := (uf_1 uf_8 #6)
    4.53 +#544 := (pattern #19)
    4.54 +#25 := (uf_1 uf_11 #6)
    4.55 +#543 := (pattern #25)
    4.56 +#92 := (uf_1 #91 #6)
    4.57 +#542 := (pattern #92)
    4.58 +#13 := (uf_6 #6)
    4.59 +#541 := (pattern #13)
    4.60 +#447 := (= #19 #92)
    4.61 +#445 := (= #25 #92)
    4.62 +#444 := (= #23 #92)
    4.63 +#20 := (= #13 uf_7)
    4.64 +#446 := (ite #20 #444 #445)
    4.65 +#120 := (* -1::int #16)
    4.66 +#14 := (uf_5 #13)
    4.67 +#121 := (+ #14 #120)
    4.68 +#119 := (>= #121 0::int)
    4.69 +#448 := (ite #119 #446 #447)
    4.70 +#545 := (forall (vars (?x3 T2)) (:pat #541 #542 #543 #544) #448)
    4.71 +#451 := (forall (vars (?x3 T2)) #448)
    4.72 +#548 := (iff #451 #545)
    4.73 +#546 := (iff #448 #448)
    4.74 +#547 := [refl]: #546
    4.75 +#549 := [quant-intro #547]: #548
    4.76 +#26 := (ite #20 #23 #25)
    4.77 +#127 := (ite #119 #26 #19)
    4.78 +#368 := (= #92 #127)
    4.79 +#369 := (forall (vars (?x3 T2)) #368)
    4.80 +#452 := (iff #369 #451)
    4.81 +#449 := (iff #368 #448)
    4.82 +#450 := [rewrite]: #449
    4.83 +#453 := [quant-intro #450]: #452
    4.84 +#392 := (~ #369 #369)
    4.85 +#390 := (~ #368 #368)
    4.86 +#391 := [refl]: #390
    4.87 +#366 := [nnf-pos #391]: #392
    4.88 +decl uf_3 :: (-> T1 T2 real)
    4.89 +#12 := (uf_3 uf_4 #6)
    4.90 +#132 := (= #12 #127)
    4.91 +#135 := (forall (vars (?x3 T2)) #132)
    4.92 +#370 := (iff #135 #369)
    4.93 +#4 := (:var 1 T1)
    4.94 +#8 := (uf_3 #4 #6)
    4.95 +#5 := (uf_2 #4)
    4.96 +#7 := (uf_1 #5 #6)
    4.97 +#9 := (= #7 #8)
    4.98 +#10 := (forall (vars (?x1 T1) (?x2 T2)) #9)
    4.99 +#113 := [asserted]: #10
   4.100 +#371 := [rewrite* #113]: #370
   4.101 +#17 := (< #14 #16)
   4.102 +#27 := (ite #17 #19 #26)
   4.103 +#28 := (= #12 #27)
   4.104 +#29 := (forall (vars (?x3 T2)) #28)
   4.105 +#136 := (iff #29 #135)
   4.106 +#133 := (iff #28 #132)
   4.107 +#130 := (= #27 #127)
   4.108 +#118 := (not #119)
   4.109 +#124 := (ite #118 #19 #26)
   4.110 +#128 := (= #124 #127)
   4.111 +#129 := [rewrite]: #128
   4.112 +#125 := (= #27 #124)
   4.113 +#122 := (iff #17 #118)
   4.114 +#123 := [rewrite]: #122
   4.115 +#126 := [monotonicity #123]: #125
   4.116 +#131 := [trans #126 #129]: #130
   4.117 +#134 := [monotonicity #131]: #133
   4.118 +#137 := [quant-intro #134]: #136
   4.119 +#114 := [asserted]: #29
   4.120 +#138 := [mp #114 #137]: #135
   4.121 +#372 := [mp #138 #371]: #369
   4.122 +#367 := [mp~ #372 #366]: #369
   4.123 +#454 := [mp #367 #453]: #451
   4.124 +#550 := [mp #454 #549]: #545
   4.125 +#738 := (not #545)
   4.126 +#928 := (or #738 #925)
   4.127 +#75 := (= #74 uf_7)
   4.128 +#906 := (ite #75 #905 #904)
   4.129 +#907 := (+ #803 #120)
   4.130 +#908 := (>= #907 0::int)
   4.131 +#909 := (ite #908 #906 #903)
   4.132 +#929 := (or #738 #909)
   4.133 +#931 := (iff #929 #928)
   4.134 +#933 := (iff #928 #928)
   4.135 +#934 := [rewrite]: #933
   4.136 +#926 := (iff #909 #925)
   4.137 +#923 := (iff #906 #922)
   4.138 +#283 := (iff #75 #281)
   4.139 +#284 := [rewrite]: #283
   4.140 +#924 := [monotonicity #284]: #923
   4.141 +#920 := (iff #908 #917)
   4.142 +#910 := (+ #120 #803)
   4.143 +#913 := (>= #910 0::int)
   4.144 +#918 := (iff #913 #917)
   4.145 +#919 := [rewrite]: #918
   4.146 +#914 := (iff #908 #913)
   4.147 +#911 := (= #907 #910)
   4.148 +#912 := [rewrite]: #911
   4.149 +#915 := [monotonicity #912]: #914
   4.150 +#921 := [trans #915 #919]: #920
   4.151 +#927 := [monotonicity #921 #924]: #926
   4.152 +#932 := [monotonicity #927]: #931
   4.153 +#935 := [trans #932 #934]: #931
   4.154 +#930 := [quant-inst]: #929
   4.155 +#936 := [mp #930 #935]: #928
   4.156 +#1300 := [unit-resolution #936 #550]: #925
   4.157 +#989 := (= #16 #803)
   4.158 +#1277 := (= #803 #16)
   4.159 +#280 := [asserted]: #75
   4.160 +#287 := [mp #280 #284]: #281
   4.161 +#1276 := [symm #287]: #75
   4.162 +#1278 := [monotonicity #1276]: #1277
   4.163 +#1301 := [symm #1278]: #989
   4.164 +#1302 := (not #989)
   4.165 +#1303 := (or #1302 #917)
   4.166 +#1304 := [th-lemma]: #1303
   4.167 +#1305 := [unit-resolution #1304 #1301]: #917
   4.168 +#950 := (not #917)
   4.169 +#949 := (not #925)
   4.170 +#951 := (or #949 #950 #922)
   4.171 +#952 := [def-axiom]: #951
   4.172 +#1306 := [unit-resolution #952 #1305 #1300]: #922
   4.173 +#937 := (not #922)
   4.174 +#1307 := (or #937 #905)
   4.175 +#938 := (not #281)
   4.176 +#939 := (or #937 #938 #905)
   4.177 +#940 := [def-axiom]: #939
   4.178 +#1308 := [unit-resolution #940 #287]: #1307
   4.179 +#1309 := [unit-resolution #1308 #1306]: #905
   4.180 +#1356 := (= #799 #23)
   4.181 +#800 := (= #23 #799)
   4.182 +decl uf_15 :: T4
   4.183 +#40 := uf_15
   4.184 +#41 := (uf_5 uf_15)
   4.185 +#814 := (+ #41 #813)
   4.186 +#815 := (<= #814 0::int)
   4.187 +#836 := (not #815)
   4.188 +#158 := (* -1::int #41)
   4.189 +#1270 := (+ #16 #158)
   4.190 +#1265 := (>= #1270 0::int)
   4.191 +#1339 := (not #1265)
   4.192 +#1269 := (= #16 #41)
   4.193 +#1298 := (not #1269)
   4.194 +#286 := (= uf_7 uf_15)
   4.195 +#44 := (uf_10 uf_15)
   4.196 +#72 := (uf_6 #44)
   4.197 +#73 := (= #72 uf_15)
   4.198 +#277 := (= uf_15 #72)
   4.199 +#278 := (iff #73 #277)
   4.200 +#279 := [rewrite]: #278
   4.201 +#276 := [asserted]: #73
   4.202 +#282 := [mp #276 #279]: #277
   4.203 +#1274 := [symm #282]: #73
   4.204 +#729 := (= uf_7 #72)
   4.205 +decl uf_17 :: (-> int T4)
   4.206 +#611 := (uf_5 #72)
   4.207 +#991 := (uf_17 #611)
   4.208 +#1289 := (= #991 #72)
   4.209 +#992 := (= #72 #991)
   4.210 +#55 := (:var 0 T4)
   4.211 +#56 := (uf_5 #55)
   4.212 +#574 := (pattern #56)
   4.213 +#57 := (uf_17 #56)
   4.214 +#177 := (= #55 #57)
   4.215 +#575 := (forall (vars (?x7 T4)) (:pat #574) #177)
   4.216 +#195 := (forall (vars (?x7 T4)) #177)
   4.217 +#578 := (iff #195 #575)
   4.218 +#576 := (iff #177 #177)
   4.219 +#577 := [refl]: #576
   4.220 +#579 := [quant-intro #577]: #578
   4.221 +#405 := (~ #195 #195)
   4.222 +#403 := (~ #177 #177)
   4.223 +#404 := [refl]: #403
   4.224 +#406 := [nnf-pos #404]: #405
   4.225 +#58 := (= #57 #55)
   4.226 +#59 := (forall (vars (?x7 T4)) #58)
   4.227 +#196 := (iff #59 #195)
   4.228 +#193 := (iff #58 #177)
   4.229 +#194 := [rewrite]: #193
   4.230 +#197 := [quant-intro #194]: #196
   4.231 +#155 := [asserted]: #59
   4.232 +#200 := [mp #155 #197]: #195
   4.233 +#407 := [mp~ #200 #406]: #195
   4.234 +#580 := [mp #407 #579]: #575
   4.235 +#995 := (not #575)
   4.236 +#996 := (or #995 #992)
   4.237 +#997 := [quant-inst]: #996
   4.238 +#1273 := [unit-resolution #997 #580]: #992
   4.239 +#1290 := [symm #1273]: #1289
   4.240 +#1293 := (= uf_7 #991)
   4.241 +#993 := (uf_17 #803)
   4.242 +#1287 := (= #993 #991)
   4.243 +#1284 := (= #803 #611)
   4.244 +#987 := (= #41 #611)
   4.245 +#1279 := (= #611 #41)
   4.246 +#1280 := [monotonicity #1274]: #1279
   4.247 +#1281 := [symm #1280]: #987
   4.248 +#1282 := (= #803 #41)
   4.249 +#1275 := [hypothesis]: #1269
   4.250 +#1283 := [trans #1278 #1275]: #1282
   4.251 +#1285 := [trans #1283 #1281]: #1284
   4.252 +#1288 := [monotonicity #1285]: #1287
   4.253 +#1291 := (= uf_7 #993)
   4.254 +#994 := (= #74 #993)
   4.255 +#1000 := (or #995 #994)
   4.256 +#1001 := [quant-inst]: #1000
   4.257 +#1286 := [unit-resolution #1001 #580]: #994
   4.258 +#1292 := [trans #287 #1286]: #1291
   4.259 +#1294 := [trans #1292 #1288]: #1293
   4.260 +#1295 := [trans #1294 #1290]: #729
   4.261 +#1296 := [trans #1295 #1274]: #286
   4.262 +#290 := (not #286)
   4.263 +#76 := (= uf_15 uf_7)
   4.264 +#77 := (not #76)
   4.265 +#291 := (iff #77 #290)
   4.266 +#288 := (iff #76 #286)
   4.267 +#289 := [rewrite]: #288
   4.268 +#292 := [monotonicity #289]: #291
   4.269 +#285 := [asserted]: #77
   4.270 +#295 := [mp #285 #292]: #290
   4.271 +#1297 := [unit-resolution #295 #1296]: false
   4.272 +#1299 := [lemma #1297]: #1298
   4.273 +#1342 := (or #1269 #1339)
   4.274 +#1271 := (<= #1270 0::int)
   4.275 +#621 := (* -1::int #611)
   4.276 +#723 := (+ #16 #621)
   4.277 +#724 := (<= #723 0::int)
   4.278 +decl uf_12 :: T1
   4.279 +#30 := uf_12
   4.280 +#88 := (uf_2 uf_12)
   4.281 +#771 := (uf_1 #88 #44)
   4.282 +#45 := (uf_1 uf_9 #44)
   4.283 +#772 := (= #45 #771)
   4.284 +#796 := (not #772)
   4.285 +decl uf_14 :: T1
   4.286 +#38 := uf_14
   4.287 +#83 := (uf_2 uf_14)
   4.288 +#656 := (uf_1 #83 #44)
   4.289 +#1239 := (= #656 #771)
   4.290 +#1252 := (not #1239)
   4.291 +#1324 := (iff #1252 #796)
   4.292 +#1322 := (iff #1239 #772)
   4.293 +#1320 := (= #656 #45)
   4.294 +#661 := (= #45 #656)
   4.295 +#659 := (uf_1 uf_11 #44)
   4.296 +#664 := (= #656 #659)
   4.297 +#667 := (ite #277 #661 #664)
   4.298 +#657 := (uf_1 uf_8 #44)
   4.299 +#670 := (= #656 #657)
   4.300 +#622 := (+ #41 #621)
   4.301 +#623 := (<= #622 0::int)
   4.302 +#673 := (ite #623 #667 #670)
   4.303 +#84 := (uf_1 #83 #6)
   4.304 +#560 := (pattern #84)
   4.305 +#467 := (= #19 #84)
   4.306 +#465 := (= #25 #84)
   4.307 +#464 := (= #45 #84)
   4.308 +#43 := (= #13 uf_15)
   4.309 +#466 := (ite #43 #464 #465)
   4.310 +#159 := (+ #14 #158)
   4.311 +#157 := (>= #159 0::int)
   4.312 +#468 := (ite #157 #466 #467)
   4.313 +#561 := (forall (vars (?x5 T2)) (:pat #541 #560 #543 #544) #468)
   4.314 +#471 := (forall (vars (?x5 T2)) #468)
   4.315 +#564 := (iff #471 #561)
   4.316 +#562 := (iff #468 #468)
   4.317 +#563 := [refl]: #562
   4.318 +#565 := [quant-intro #563]: #564
   4.319 +#46 := (ite #43 #45 #25)
   4.320 +#165 := (ite #157 #46 #19)
   4.321 +#378 := (= #84 #165)
   4.322 +#379 := (forall (vars (?x5 T2)) #378)
   4.323 +#472 := (iff #379 #471)
   4.324 +#469 := (iff #378 #468)
   4.325 +#470 := [rewrite]: #469
   4.326 +#473 := [quant-intro #470]: #472
   4.327 +#359 := (~ #379 #379)
   4.328 +#361 := (~ #378 #378)
   4.329 +#358 := [refl]: #361
   4.330 +#356 := [nnf-pos #358]: #359
   4.331 +#39 := (uf_3 uf_14 #6)
   4.332 +#170 := (= #39 #165)
   4.333 +#173 := (forall (vars (?x5 T2)) #170)
   4.334 +#380 := (iff #173 #379)
   4.335 +#381 := [rewrite* #113]: #380
   4.336 +#42 := (< #14 #41)
   4.337 +#47 := (ite #42 #19 #46)
   4.338 +#48 := (= #39 #47)
   4.339 +#49 := (forall (vars (?x5 T2)) #48)
   4.340 +#174 := (iff #49 #173)
   4.341 +#171 := (iff #48 #170)
   4.342 +#168 := (= #47 #165)
   4.343 +#156 := (not #157)
   4.344 +#162 := (ite #156 #19 #46)
   4.345 +#166 := (= #162 #165)
   4.346 +#167 := [rewrite]: #166
   4.347 +#163 := (= #47 #162)
   4.348 +#160 := (iff #42 #156)
   4.349 +#161 := [rewrite]: #160
   4.350 +#164 := [monotonicity #161]: #163
   4.351 +#169 := [trans #164 #167]: #168
   4.352 +#172 := [monotonicity #169]: #171
   4.353 +#175 := [quant-intro #172]: #174
   4.354 +#116 := [asserted]: #49
   4.355 +#176 := [mp #116 #175]: #173
   4.356 +#382 := [mp #176 #381]: #379
   4.357 +#357 := [mp~ #382 #356]: #379
   4.358 +#474 := [mp #357 #473]: #471
   4.359 +#566 := [mp #474 #565]: #561
   4.360 +#676 := (not #561)
   4.361 +#677 := (or #676 #673)
   4.362 +#658 := (= #657 #656)
   4.363 +#660 := (= #659 #656)
   4.364 +#662 := (ite #73 #661 #660)
   4.365 +#612 := (+ #611 #158)
   4.366 +#613 := (>= #612 0::int)
   4.367 +#663 := (ite #613 #662 #658)
   4.368 +#678 := (or #676 #663)
   4.369 +#680 := (iff #678 #677)
   4.370 +#682 := (iff #677 #677)
   4.371 +#683 := [rewrite]: #682
   4.372 +#674 := (iff #663 #673)
   4.373 +#671 := (iff #658 #670)
   4.374 +#672 := [rewrite]: #671
   4.375 +#668 := (iff #662 #667)
   4.376 +#665 := (iff #660 #664)
   4.377 +#666 := [rewrite]: #665
   4.378 +#669 := [monotonicity #279 #666]: #668
   4.379 +#626 := (iff #613 #623)
   4.380 +#615 := (+ #158 #611)
   4.381 +#618 := (>= #615 0::int)
   4.382 +#624 := (iff #618 #623)
   4.383 +#625 := [rewrite]: #624
   4.384 +#619 := (iff #613 #618)
   4.385 +#616 := (= #612 #615)
   4.386 +#617 := [rewrite]: #616
   4.387 +#620 := [monotonicity #617]: #619
   4.388 +#627 := [trans #620 #625]: #626
   4.389 +#675 := [monotonicity #627 #669 #672]: #674
   4.390 +#681 := [monotonicity #675]: #680
   4.391 +#684 := [trans #681 #683]: #680
   4.392 +#679 := [quant-inst]: #678
   4.393 +#685 := [mp #679 #684]: #677
   4.394 +#1311 := [unit-resolution #685 #566]: #673
   4.395 +#1312 := (not #987)
   4.396 +#1313 := (or #1312 #623)
   4.397 +#1314 := [th-lemma]: #1313
   4.398 +#1315 := [unit-resolution #1314 #1281]: #623
   4.399 +#645 := (not #623)
   4.400 +#698 := (not #673)
   4.401 +#699 := (or #698 #645 #667)
   4.402 +#700 := [def-axiom]: #699
   4.403 +#1316 := [unit-resolution #700 #1315 #1311]: #667
   4.404 +#686 := (not #667)
   4.405 +#1317 := (or #686 #661)
   4.406 +#687 := (not #277)
   4.407 +#688 := (or #686 #687 #661)
   4.408 +#689 := [def-axiom]: #688
   4.409 +#1318 := [unit-resolution #689 #282]: #1317
   4.410 +#1319 := [unit-resolution #1318 #1316]: #661
   4.411 +#1321 := [symm #1319]: #1320
   4.412 +#1323 := [monotonicity #1321]: #1322
   4.413 +#1325 := [monotonicity #1323]: #1324
   4.414 +#1145 := (* -1::real #771)
   4.415 +#1240 := (+ #656 #1145)
   4.416 +#1241 := (<= #1240 0::real)
   4.417 +#1249 := (not #1241)
   4.418 +#1243 := [hypothesis]: #1241
   4.419 +decl uf_18 :: T3
   4.420 +#80 := uf_18
   4.421 +#1040 := (uf_1 uf_18 #44)
   4.422 +#1043 := (* -1::real #1040)
   4.423 +#1156 := (+ #771 #1043)
   4.424 +#1157 := (>= #1156 0::real)
   4.425 +#1189 := (not #1157)
   4.426 +#708 := (uf_1 #91 #44)
   4.427 +#1168 := (+ #708 #1043)
   4.428 +#1169 := (<= #1168 0::real)
   4.429 +#1174 := (or #1157 #1169)
   4.430 +#1177 := (not #1174)
   4.431 +#89 := (uf_1 #88 #6)
   4.432 +#552 := (pattern #89)
   4.433 +#81 := (uf_1 uf_18 #6)
   4.434 +#594 := (pattern #81)
   4.435 +#324 := (* -1::real #92)
   4.436 +#325 := (+ #81 #324)
   4.437 +#323 := (>= #325 0::real)
   4.438 +#317 := (* -1::real #89)
   4.439 +#318 := (+ #81 #317)
   4.440 +#319 := (<= #318 0::real)
   4.441 +#436 := (or #319 #323)
   4.442 +#437 := (not #436)
   4.443 +#601 := (forall (vars (?x11 T2)) (:pat #594 #552 #542) #437)
   4.444 +#440 := (forall (vars (?x11 T2)) #437)
   4.445 +#604 := (iff #440 #601)
   4.446 +#602 := (iff #437 #437)
   4.447 +#603 := [refl]: #602
   4.448 +#605 := [quant-intro #603]: #604
   4.449 +#326 := (not #323)
   4.450 +#320 := (not #319)
   4.451 +#329 := (and #320 #326)
   4.452 +#332 := (forall (vars (?x11 T2)) #329)
   4.453 +#441 := (iff #332 #440)
   4.454 +#438 := (iff #329 #437)
   4.455 +#439 := [rewrite]: #438
   4.456 +#442 := [quant-intro #439]: #441
   4.457 +#425 := (~ #332 #332)
   4.458 +#423 := (~ #329 #329)
   4.459 +#424 := [refl]: #423
   4.460 +#426 := [nnf-pos #424]: #425
   4.461 +#306 := (* -1::real #84)
   4.462 +#307 := (+ #81 #306)
   4.463 +#305 := (>= #307 0::real)
   4.464 +#308 := (not #305)
   4.465 +#301 := (* -1::real #81)
   4.466 +#79 := (uf_1 #78 #6)
   4.467 +#302 := (+ #79 #301)
   4.468 +#300 := (>= #302 0::real)
   4.469 +#298 := (not #300)
   4.470 +#311 := (and #298 #308)
   4.471 +#314 := (forall (vars (?x10 T2)) #311)
   4.472 +#335 := (and #314 #332)
   4.473 +#93 := (< #81 #92)
   4.474 +#90 := (< #89 #81)
   4.475 +#94 := (and #90 #93)
   4.476 +#95 := (forall (vars (?x11 T2)) #94)
   4.477 +#85 := (< #81 #84)
   4.478 +#82 := (< #79 #81)
   4.479 +#86 := (and #82 #85)
   4.480 +#87 := (forall (vars (?x10 T2)) #86)
   4.481 +#96 := (and #87 #95)
   4.482 +#336 := (iff #96 #335)
   4.483 +#333 := (iff #95 #332)
   4.484 +#330 := (iff #94 #329)
   4.485 +#327 := (iff #93 #326)
   4.486 +#328 := [rewrite]: #327
   4.487 +#321 := (iff #90 #320)
   4.488 +#322 := [rewrite]: #321
   4.489 +#331 := [monotonicity #322 #328]: #330
   4.490 +#334 := [quant-intro #331]: #333
   4.491 +#315 := (iff #87 #314)
   4.492 +#312 := (iff #86 #311)
   4.493 +#309 := (iff #85 #308)
   4.494 +#310 := [rewrite]: #309
   4.495 +#303 := (iff #82 #298)
   4.496 +#304 := [rewrite]: #303
   4.497 +#313 := [monotonicity #304 #310]: #312
   4.498 +#316 := [quant-intro #313]: #315
   4.499 +#337 := [monotonicity #316 #334]: #336
   4.500 +#293 := [asserted]: #96
   4.501 +#338 := [mp #293 #337]: #335
   4.502 +#340 := [and-elim #338]: #332
   4.503 +#427 := [mp~ #340 #426]: #332
   4.504 +#443 := [mp #427 #442]: #440
   4.505 +#606 := [mp #443 #605]: #601
   4.506 +#1124 := (not #601)
   4.507 +#1180 := (or #1124 #1177)
   4.508 +#1142 := (* -1::real #708)
   4.509 +#1143 := (+ #1040 #1142)
   4.510 +#1144 := (>= #1143 0::real)
   4.511 +#1146 := (+ #1040 #1145)
   4.512 +#1147 := (<= #1146 0::real)
   4.513 +#1148 := (or #1147 #1144)
   4.514 +#1149 := (not #1148)
   4.515 +#1181 := (or #1124 #1149)
   4.516 +#1183 := (iff #1181 #1180)
   4.517 +#1185 := (iff #1180 #1180)
   4.518 +#1186 := [rewrite]: #1185
   4.519 +#1178 := (iff #1149 #1177)
   4.520 +#1175 := (iff #1148 #1174)
   4.521 +#1172 := (iff #1144 #1169)
   4.522 +#1162 := (+ #1142 #1040)
   4.523 +#1165 := (>= #1162 0::real)
   4.524 +#1170 := (iff #1165 #1169)
   4.525 +#1171 := [rewrite]: #1170
   4.526 +#1166 := (iff #1144 #1165)
   4.527 +#1163 := (= #1143 #1162)
   4.528 +#1164 := [rewrite]: #1163
   4.529 +#1167 := [monotonicity #1164]: #1166
   4.530 +#1173 := [trans #1167 #1171]: #1172
   4.531 +#1160 := (iff #1147 #1157)
   4.532 +#1150 := (+ #1145 #1040)
   4.533 +#1153 := (<= #1150 0::real)
   4.534 +#1158 := (iff #1153 #1157)
   4.535 +#1159 := [rewrite]: #1158
   4.536 +#1154 := (iff #1147 #1153)
   4.537 +#1151 := (= #1146 #1150)
   4.538 +#1152 := [rewrite]: #1151
   4.539 +#1155 := [monotonicity #1152]: #1154
   4.540 +#1161 := [trans #1155 #1159]: #1160
   4.541 +#1176 := [monotonicity #1161 #1173]: #1175
   4.542 +#1179 := [monotonicity #1176]: #1178
   4.543 +#1184 := [monotonicity #1179]: #1183
   4.544 +#1187 := [trans #1184 #1186]: #1183
   4.545 +#1182 := [quant-inst]: #1181
   4.546 +#1188 := [mp #1182 #1187]: #1180
   4.547 +#1244 := [unit-resolution #1188 #606]: #1177
   4.548 +#1190 := (or #1174 #1189)
   4.549 +#1191 := [def-axiom]: #1190
   4.550 +#1245 := [unit-resolution #1191 #1244]: #1189
   4.551 +#1054 := (+ #656 #1043)
   4.552 +#1055 := (<= #1054 0::real)
   4.553 +#1079 := (not #1055)
   4.554 +#607 := (uf_1 #78 #44)
   4.555 +#1044 := (+ #607 #1043)
   4.556 +#1045 := (>= #1044 0::real)
   4.557 +#1060 := (or #1045 #1055)
   4.558 +#1063 := (not #1060)
   4.559 +#567 := (pattern #79)
   4.560 +#428 := (or #300 #305)
   4.561 +#429 := (not #428)
   4.562 +#595 := (forall (vars (?x10 T2)) (:pat #567 #594 #560) #429)
   4.563 +#432 := (forall (vars (?x10 T2)) #429)
   4.564 +#598 := (iff #432 #595)
   4.565 +#596 := (iff #429 #429)
   4.566 +#597 := [refl]: #596
   4.567 +#599 := [quant-intro #597]: #598
   4.568 +#433 := (iff #314 #432)
   4.569 +#430 := (iff #311 #429)
   4.570 +#431 := [rewrite]: #430
   4.571 +#434 := [quant-intro #431]: #433
   4.572 +#420 := (~ #314 #314)
   4.573 +#418 := (~ #311 #311)
   4.574 +#419 := [refl]: #418
   4.575 +#421 := [nnf-pos #419]: #420
   4.576 +#339 := [and-elim #338]: #314
   4.577 +#422 := [mp~ #339 #421]: #314
   4.578 +#435 := [mp #422 #434]: #432
   4.579 +#600 := [mp #435 #599]: #595
   4.580 +#1066 := (not #595)
   4.581 +#1067 := (or #1066 #1063)
   4.582 +#1039 := (* -1::real #656)
   4.583 +#1041 := (+ #1040 #1039)
   4.584 +#1042 := (>= #1041 0::real)
   4.585 +#1046 := (or #1045 #1042)
   4.586 +#1047 := (not #1046)
   4.587 +#1068 := (or #1066 #1047)
   4.588 +#1070 := (iff #1068 #1067)
   4.589 +#1072 := (iff #1067 #1067)
   4.590 +#1073 := [rewrite]: #1072
   4.591 +#1064 := (iff #1047 #1063)
   4.592 +#1061 := (iff #1046 #1060)
   4.593 +#1058 := (iff #1042 #1055)
   4.594 +#1048 := (+ #1039 #1040)
   4.595 +#1051 := (>= #1048 0::real)
   4.596 +#1056 := (iff #1051 #1055)
   4.597 +#1057 := [rewrite]: #1056
   4.598 +#1052 := (iff #1042 #1051)
   4.599 +#1049 := (= #1041 #1048)
   4.600 +#1050 := [rewrite]: #1049
   4.601 +#1053 := [monotonicity #1050]: #1052
   4.602 +#1059 := [trans #1053 #1057]: #1058
   4.603 +#1062 := [monotonicity #1059]: #1061
   4.604 +#1065 := [monotonicity #1062]: #1064
   4.605 +#1071 := [monotonicity #1065]: #1070
   4.606 +#1074 := [trans #1071 #1073]: #1070
   4.607 +#1069 := [quant-inst]: #1068
   4.608 +#1075 := [mp #1069 #1074]: #1067
   4.609 +#1246 := [unit-resolution #1075 #600]: #1063
   4.610 +#1080 := (or #1060 #1079)
   4.611 +#1081 := [def-axiom]: #1080
   4.612 +#1247 := [unit-resolution #1081 #1246]: #1079
   4.613 +#1248 := [th-lemma #1247 #1245 #1243]: false
   4.614 +#1250 := [lemma #1248]: #1249
   4.615 +#1253 := (or #1252 #1241)
   4.616 +#1254 := [th-lemma]: #1253
   4.617 +#1310 := [unit-resolution #1254 #1250]: #1252
   4.618 +#1326 := [mp #1310 #1325]: #796
   4.619 +#1328 := (or #724 #772)
   4.620 +decl uf_13 :: T3
   4.621 +#33 := uf_13
   4.622 +#609 := (uf_1 uf_13 #44)
   4.623 +#773 := (= #609 #771)
   4.624 +#775 := (ite #724 #773 #772)
   4.625 +#32 := (uf_1 uf_9 #6)
   4.626 +#553 := (pattern #32)
   4.627 +#34 := (uf_1 uf_13 #6)
   4.628 +#551 := (pattern #34)
   4.629 +#456 := (= #32 #89)
   4.630 +#455 := (= #34 #89)
   4.631 +#457 := (ite #119 #455 #456)
   4.632 +#554 := (forall (vars (?x4 T2)) (:pat #541 #551 #552 #553) #457)
   4.633 +#460 := (forall (vars (?x4 T2)) #457)
   4.634 +#557 := (iff #460 #554)
   4.635 +#555 := (iff #457 #457)
   4.636 +#556 := [refl]: #555
   4.637 +#558 := [quant-intro #556]: #557
   4.638 +#143 := (ite #119 #34 #32)
   4.639 +#373 := (= #89 #143)
   4.640 +#374 := (forall (vars (?x4 T2)) #373)
   4.641 +#461 := (iff #374 #460)
   4.642 +#458 := (iff #373 #457)
   4.643 +#459 := [rewrite]: #458
   4.644 +#462 := [quant-intro #459]: #461
   4.645 +#362 := (~ #374 #374)
   4.646 +#364 := (~ #373 #373)
   4.647 +#365 := [refl]: #364
   4.648 +#363 := [nnf-pos #365]: #362
   4.649 +#31 := (uf_3 uf_12 #6)
   4.650 +#148 := (= #31 #143)
   4.651 +#151 := (forall (vars (?x4 T2)) #148)
   4.652 +#375 := (iff #151 #374)
   4.653 +#376 := [rewrite* #113]: #375
   4.654 +#35 := (ite #17 #32 #34)
   4.655 +#36 := (= #31 #35)
   4.656 +#37 := (forall (vars (?x4 T2)) #36)
   4.657 +#152 := (iff #37 #151)
   4.658 +#149 := (iff #36 #148)
   4.659 +#146 := (= #35 #143)
   4.660 +#140 := (ite #118 #32 #34)
   4.661 +#144 := (= #140 #143)
   4.662 +#145 := [rewrite]: #144
   4.663 +#141 := (= #35 #140)
   4.664 +#142 := [monotonicity #123]: #141
   4.665 +#147 := [trans #142 #145]: #146
   4.666 +#150 := [monotonicity #147]: #149
   4.667 +#153 := [quant-intro #150]: #152
   4.668 +#115 := [asserted]: #37
   4.669 +#154 := [mp #115 #153]: #151
   4.670 +#377 := [mp #154 #376]: #374
   4.671 +#360 := [mp~ #377 #363]: #374
   4.672 +#463 := [mp #360 #462]: #460
   4.673 +#559 := [mp #463 #558]: #554
   4.674 +#778 := (not #554)
   4.675 +#779 := (or #778 #775)
   4.676 +#714 := (+ #611 #120)
   4.677 +#715 := (>= #714 0::int)
   4.678 +#774 := (ite #715 #773 #772)
   4.679 +#780 := (or #778 #774)
   4.680 +#782 := (iff #780 #779)
   4.681 +#784 := (iff #779 #779)
   4.682 +#785 := [rewrite]: #784
   4.683 +#776 := (iff #774 #775)
   4.684 +#727 := (iff #715 #724)
   4.685 +#717 := (+ #120 #611)
   4.686 +#720 := (>= #717 0::int)
   4.687 +#725 := (iff #720 #724)
   4.688 +#726 := [rewrite]: #725
   4.689 +#721 := (iff #715 #720)
   4.690 +#718 := (= #714 #717)
   4.691 +#719 := [rewrite]: #718
   4.692 +#722 := [monotonicity #719]: #721
   4.693 +#728 := [trans #722 #726]: #727
   4.694 +#777 := [monotonicity #728]: #776
   4.695 +#783 := [monotonicity #777]: #782
   4.696 +#786 := [trans #783 #785]: #782
   4.697 +#781 := [quant-inst]: #780
   4.698 +#787 := [mp #781 #786]: #779
   4.699 +#1327 := [unit-resolution #787 #559]: #775
   4.700 +#788 := (not #775)
   4.701 +#791 := (or #788 #724 #772)
   4.702 +#792 := [def-axiom]: #791
   4.703 +#1329 := [unit-resolution #792 #1327]: #1328
   4.704 +#1330 := [unit-resolution #1329 #1326]: #724
   4.705 +#988 := (>= #622 0::int)
   4.706 +#1331 := (or #1312 #988)
   4.707 +#1332 := [th-lemma]: #1331
   4.708 +#1333 := [unit-resolution #1332 #1281]: #988
   4.709 +#761 := (not #724)
   4.710 +#1334 := (not #988)
   4.711 +#1335 := (or #1271 #1334 #761)
   4.712 +#1336 := [th-lemma]: #1335
   4.713 +#1337 := [unit-resolution #1336 #1333 #1330]: #1271
   4.714 +#1338 := (not #1271)
   4.715 +#1340 := (or #1269 #1338 #1339)
   4.716 +#1341 := [th-lemma]: #1340
   4.717 +#1343 := [unit-resolution #1341 #1337]: #1342
   4.718 +#1344 := [unit-resolution #1343 #1299]: #1339
   4.719 +#990 := (>= #916 0::int)
   4.720 +#1345 := (or #1302 #990)
   4.721 +#1346 := [th-lemma]: #1345
   4.722 +#1347 := [unit-resolution #1346 #1301]: #990
   4.723 +#1348 := (not #990)
   4.724 +#1349 := (or #836 #1348 #1265)
   4.725 +#1350 := [th-lemma]: #1349
   4.726 +#1351 := [unit-resolution #1350 #1347 #1344]: #836
   4.727 +#1353 := (or #815 #800)
   4.728 +#801 := (uf_1 uf_13 #22)
   4.729 +#820 := (= #799 #801)
   4.730 +#823 := (ite #815 #820 #800)
   4.731 +#476 := (= #32 #79)
   4.732 +#475 := (= #34 #79)
   4.733 +#477 := (ite #157 #475 #476)
   4.734 +#568 := (forall (vars (?x6 T2)) (:pat #541 #551 #567 #553) #477)
   4.735 +#480 := (forall (vars (?x6 T2)) #477)
   4.736 +#571 := (iff #480 #568)
   4.737 +#569 := (iff #477 #477)
   4.738 +#570 := [refl]: #569
   4.739 +#572 := [quant-intro #570]: #571
   4.740 +#181 := (ite #157 #34 #32)
   4.741 +#383 := (= #79 #181)
   4.742 +#384 := (forall (vars (?x6 T2)) #383)
   4.743 +#481 := (iff #384 #480)
   4.744 +#478 := (iff #383 #477)
   4.745 +#479 := [rewrite]: #478
   4.746 +#482 := [quant-intro #479]: #481
   4.747 +#352 := (~ #384 #384)
   4.748 +#354 := (~ #383 #383)
   4.749 +#355 := [refl]: #354
   4.750 +#353 := [nnf-pos #355]: #352
   4.751 +#51 := (uf_3 uf_16 #6)
   4.752 +#186 := (= #51 #181)
   4.753 +#189 := (forall (vars (?x6 T2)) #186)
   4.754 +#385 := (iff #189 #384)
   4.755 +#386 := [rewrite* #113]: #385
   4.756 +#52 := (ite #42 #32 #34)
   4.757 +#53 := (= #51 #52)
   4.758 +#54 := (forall (vars (?x6 T2)) #53)
   4.759 +#190 := (iff #54 #189)
   4.760 +#187 := (iff #53 #186)
   4.761 +#184 := (= #52 #181)
   4.762 +#178 := (ite #156 #32 #34)
   4.763 +#182 := (= #178 #181)
   4.764 +#183 := [rewrite]: #182
   4.765 +#179 := (= #52 #178)
   4.766 +#180 := [monotonicity #161]: #179
   4.767 +#185 := [trans #180 #183]: #184
   4.768 +#188 := [monotonicity #185]: #187
   4.769 +#191 := [quant-intro #188]: #190
   4.770 +#139 := [asserted]: #54
   4.771 +#192 := [mp #139 #191]: #189
   4.772 +#387 := [mp #192 #386]: #384
   4.773 +#402 := [mp~ #387 #353]: #384
   4.774 +#483 := [mp #402 #482]: #480
   4.775 +#573 := [mp #483 #572]: #568
   4.776 +#634 := (not #568)
   4.777 +#826 := (or #634 #823)
   4.778 +#802 := (= #801 #799)
   4.779 +#804 := (+ #803 #158)
   4.780 +#805 := (>= #804 0::int)
   4.781 +#806 := (ite #805 #802 #800)
   4.782 +#827 := (or #634 #806)
   4.783 +#829 := (iff #827 #826)
   4.784 +#831 := (iff #826 #826)
   4.785 +#832 := [rewrite]: #831
   4.786 +#824 := (iff #806 #823)
   4.787 +#821 := (iff #802 #820)
   4.788 +#822 := [rewrite]: #821
   4.789 +#818 := (iff #805 #815)
   4.790 +#807 := (+ #158 #803)
   4.791 +#810 := (>= #807 0::int)
   4.792 +#816 := (iff #810 #815)
   4.793 +#817 := [rewrite]: #816
   4.794 +#811 := (iff #805 #810)
   4.795 +#808 := (= #804 #807)
   4.796 +#809 := [rewrite]: #808
   4.797 +#812 := [monotonicity #809]: #811
   4.798 +#819 := [trans #812 #817]: #818
   4.799 +#825 := [monotonicity #819 #822]: #824
   4.800 +#830 := [monotonicity #825]: #829
   4.801 +#833 := [trans #830 #832]: #829
   4.802 +#828 := [quant-inst]: #827
   4.803 +#834 := [mp #828 #833]: #826
   4.804 +#1352 := [unit-resolution #834 #573]: #823
   4.805 +#835 := (not #823)
   4.806 +#839 := (or #835 #815 #800)
   4.807 +#840 := [def-axiom]: #839
   4.808 +#1354 := [unit-resolution #840 #1352]: #1353
   4.809 +#1355 := [unit-resolution #1354 #1351]: #800
   4.810 +#1357 := [symm #1355]: #1356
   4.811 +#1358 := [trans #1357 #1309]: #1266
   4.812 +#1359 := (not #1266)
   4.813 +#1360 := (or #1359 #1272)
   4.814 +#1361 := [th-lemma]: #1360
   4.815 +#1362 := [unit-resolution #1361 #1358]: #1272
   4.816 +#1085 := (uf_1 uf_18 #22)
   4.817 +#1099 := (* -1::real #1085)
   4.818 +#1112 := (+ #902 #1099)
   4.819 +#1113 := (<= #1112 0::real)
   4.820 +#1137 := (not #1113)
   4.821 +#960 := (uf_1 #88 #22)
   4.822 +#1100 := (+ #960 #1099)
   4.823 +#1101 := (>= #1100 0::real)
   4.824 +#1118 := (or #1101 #1113)
   4.825 +#1121 := (not #1118)
   4.826 +#1125 := (or #1124 #1121)
   4.827 +#1086 := (+ #1085 #1084)
   4.828 +#1087 := (>= #1086 0::real)
   4.829 +#1088 := (* -1::real #960)
   4.830 +#1089 := (+ #1085 #1088)
   4.831 +#1090 := (<= #1089 0::real)
   4.832 +#1091 := (or #1090 #1087)
   4.833 +#1092 := (not #1091)
   4.834 +#1126 := (or #1124 #1092)
   4.835 +#1128 := (iff #1126 #1125)
   4.836 +#1130 := (iff #1125 #1125)
   4.837 +#1131 := [rewrite]: #1130
   4.838 +#1122 := (iff #1092 #1121)
   4.839 +#1119 := (iff #1091 #1118)
   4.840 +#1116 := (iff #1087 #1113)
   4.841 +#1106 := (+ #1084 #1085)
   4.842 +#1109 := (>= #1106 0::real)
   4.843 +#1114 := (iff #1109 #1113)
   4.844 +#1115 := [rewrite]: #1114
   4.845 +#1110 := (iff #1087 #1109)
   4.846 +#1107 := (= #1086 #1106)
   4.847 +#1108 := [rewrite]: #1107
   4.848 +#1111 := [monotonicity #1108]: #1110
   4.849 +#1117 := [trans #1111 #1115]: #1116
   4.850 +#1104 := (iff #1090 #1101)
   4.851 +#1093 := (+ #1088 #1085)
   4.852 +#1096 := (<= #1093 0::real)
   4.853 +#1102 := (iff #1096 #1101)
   4.854 +#1103 := [rewrite]: #1102
   4.855 +#1097 := (iff #1090 #1096)
   4.856 +#1094 := (= #1089 #1093)
   4.857 +#1095 := [rewrite]: #1094
   4.858 +#1098 := [monotonicity #1095]: #1097
   4.859 +#1105 := [trans #1098 #1103]: #1104
   4.860 +#1120 := [monotonicity #1105 #1117]: #1119
   4.861 +#1123 := [monotonicity #1120]: #1122
   4.862 +#1129 := [monotonicity #1123]: #1128
   4.863 +#1132 := [trans #1129 #1131]: #1128
   4.864 +#1127 := [quant-inst]: #1126
   4.865 +#1133 := [mp #1127 #1132]: #1125
   4.866 +#1363 := [unit-resolution #1133 #606]: #1121
   4.867 +#1138 := (or #1118 #1137)
   4.868 +#1139 := [def-axiom]: #1138
   4.869 +#1364 := [unit-resolution #1139 #1363]: #1137
   4.870 +#1200 := (+ #799 #1099)
   4.871 +#1201 := (>= #1200 0::real)
   4.872 +#1231 := (not #1201)
   4.873 +#847 := (uf_1 #83 #22)
   4.874 +#1210 := (+ #847 #1099)
   4.875 +#1211 := (<= #1210 0::real)
   4.876 +#1216 := (or #1201 #1211)
   4.877 +#1219 := (not #1216)
   4.878 +#1222 := (or #1066 #1219)
   4.879 +#1197 := (* -1::real #847)
   4.880 +#1198 := (+ #1085 #1197)
   4.881 +#1199 := (>= #1198 0::real)
   4.882 +#1202 := (or #1201 #1199)
   4.883 +#1203 := (not #1202)
   4.884 +#1223 := (or #1066 #1203)
   4.885 +#1225 := (iff #1223 #1222)
   4.886 +#1227 := (iff #1222 #1222)
   4.887 +#1228 := [rewrite]: #1227
   4.888 +#1220 := (iff #1203 #1219)
   4.889 +#1217 := (iff #1202 #1216)
   4.890 +#1214 := (iff #1199 #1211)
   4.891 +#1204 := (+ #1197 #1085)
   4.892 +#1207 := (>= #1204 0::real)
   4.893 +#1212 := (iff #1207 #1211)
   4.894 +#1213 := [rewrite]: #1212
   4.895 +#1208 := (iff #1199 #1207)
   4.896 +#1205 := (= #1198 #1204)
   4.897 +#1206 := [rewrite]: #1205
   4.898 +#1209 := [monotonicity #1206]: #1208
   4.899 +#1215 := [trans #1209 #1213]: #1214
   4.900 +#1218 := [monotonicity #1215]: #1217
   4.901 +#1221 := [monotonicity #1218]: #1220
   4.902 +#1226 := [monotonicity #1221]: #1225
   4.903 +#1229 := [trans #1226 #1228]: #1225
   4.904 +#1224 := [quant-inst]: #1223
   4.905 +#1230 := [mp #1224 #1229]: #1222
   4.906 +#1365 := [unit-resolution #1230 #600]: #1219
   4.907 +#1232 := (or #1216 #1231)
   4.908 +#1233 := [def-axiom]: #1232
   4.909 +#1366 := [unit-resolution #1233 #1365]: #1231
   4.910 +[th-lemma #1366 #1364 #1362]: false
   4.911 +unsat
   4.912 +NQHwTeL311Tq3wf2s5BReA 419 0
   4.913 +#2 := false
   4.914 +#194 := 0::real
   4.915 +decl uf_4 :: (-> T2 T3 real)
   4.916 +decl uf_6 :: (-> T1 T3)
   4.917 +decl uf_3 :: T1
   4.918 +#21 := uf_3
   4.919 +#25 := (uf_6 uf_3)
   4.920 +decl uf_5 :: T2
   4.921 +#24 := uf_5
   4.922 +#26 := (uf_4 uf_5 #25)
   4.923 +decl uf_7 :: T2
   4.924 +#27 := uf_7
   4.925 +#28 := (uf_4 uf_7 #25)
   4.926 +decl uf_10 :: T1
   4.927 +#38 := uf_10
   4.928 +#42 := (uf_6 uf_10)
   4.929 +decl uf_9 :: T2
   4.930 +#33 := uf_9
   4.931 +#43 := (uf_4 uf_9 #42)
   4.932 +#41 := (= uf_3 uf_10)
   4.933 +#44 := (ite #41 #43 #28)
   4.934 +#9 := 0::int
   4.935 +decl uf_2 :: (-> T1 int)
   4.936 +#39 := (uf_2 uf_10)
   4.937 +#226 := -1::int
   4.938 +#229 := (* -1::int #39)
   4.939 +#22 := (uf_2 uf_3)
   4.940 +#230 := (+ #22 #229)
   4.941 +#228 := (>= #230 0::int)
   4.942 +#236 := (ite #228 #44 #26)
   4.943 +#192 := -1::real
   4.944 +#244 := (* -1::real #236)
   4.945 +#642 := (+ #26 #244)
   4.946 +#643 := (<= #642 0::real)
   4.947 +#567 := (= #26 #236)
   4.948 +#227 := (not #228)
   4.949 +decl uf_1 :: (-> int T1)
   4.950 +#593 := (uf_1 #39)
   4.951 +#660 := (= #593 uf_10)
   4.952 +#594 := (= uf_10 #593)
   4.953 +#4 := (:var 0 T1)
   4.954 +#5 := (uf_2 #4)
   4.955 +#546 := (pattern #5)
   4.956 +#6 := (uf_1 #5)
   4.957 +#93 := (= #4 #6)
   4.958 +#547 := (forall (vars (?x1 T1)) (:pat #546) #93)
   4.959 +#96 := (forall (vars (?x1 T1)) #93)
   4.960 +#550 := (iff #96 #547)
   4.961 +#548 := (iff #93 #93)
   4.962 +#549 := [refl]: #548
   4.963 +#551 := [quant-intro #549]: #550
   4.964 +#448 := (~ #96 #96)
   4.965 +#450 := (~ #93 #93)
   4.966 +#451 := [refl]: #450
   4.967 +#449 := [nnf-pos #451]: #448
   4.968 +#7 := (= #6 #4)
   4.969 +#8 := (forall (vars (?x1 T1)) #7)
   4.970 +#97 := (iff #8 #96)
   4.971 +#94 := (iff #7 #93)
   4.972 +#95 := [rewrite]: #94
   4.973 +#98 := [quant-intro #95]: #97
   4.974 +#92 := [asserted]: #8
   4.975 +#101 := [mp #92 #98]: #96
   4.976 +#446 := [mp~ #101 #449]: #96
   4.977 +#552 := [mp #446 #551]: #547
   4.978 +#595 := (not #547)
   4.979 +#600 := (or #595 #594)
   4.980 +#601 := [quant-inst]: #600
   4.981 +#654 := [unit-resolution #601 #552]: #594
   4.982 +#680 := [symm #654]: #660
   4.983 +#681 := (= uf_3 #593)
   4.984 +#591 := (uf_1 #22)
   4.985 +#658 := (= #591 #593)
   4.986 +#656 := (= #593 #591)
   4.987 +#652 := (= #39 #22)
   4.988 +#647 := (= #22 #39)
   4.989 +#290 := (<= #230 0::int)
   4.990 +#70 := (<= #22 #39)
   4.991 +#388 := (iff #70 #290)
   4.992 +#389 := [rewrite]: #388
   4.993 +#341 := [asserted]: #70
   4.994 +#390 := [mp #341 #389]: #290
   4.995 +#646 := [hypothesis]: #228
   4.996 +#648 := [th-lemma #646 #390]: #647
   4.997 +#653 := [symm #648]: #652
   4.998 +#657 := [monotonicity #653]: #656
   4.999 +#659 := [symm #657]: #658
  4.1000 +#592 := (= uf_3 #591)
  4.1001 +#596 := (or #595 #592)
  4.1002 +#597 := [quant-inst]: #596
  4.1003 +#655 := [unit-resolution #597 #552]: #592
  4.1004 +#682 := [trans #655 #659]: #681
  4.1005 +#683 := [trans #682 #680]: #41
  4.1006 +#570 := (not #41)
  4.1007 +decl uf_11 :: T2
  4.1008 +#47 := uf_11
  4.1009 +#59 := (uf_4 uf_11 #42)
  4.1010 +#278 := (ite #41 #26 #59)
  4.1011 +#459 := (* -1::real #278)
  4.1012 +#637 := (+ #26 #459)
  4.1013 +#639 := (>= #637 0::real)
  4.1014 +#585 := (= #26 #278)
  4.1015 +#661 := [hypothesis]: #41
  4.1016 +#587 := (or #570 #585)
  4.1017 +#588 := [def-axiom]: #587
  4.1018 +#662 := [unit-resolution #588 #661]: #585
  4.1019 +#663 := (not #585)
  4.1020 +#664 := (or #663 #639)
  4.1021 +#665 := [th-lemma]: #664
  4.1022 +#666 := [unit-resolution #665 #662]: #639
  4.1023 +decl uf_8 :: T2
  4.1024 +#30 := uf_8
  4.1025 +#56 := (uf_4 uf_8 #42)
  4.1026 +#357 := (* -1::real #56)
  4.1027 +#358 := (+ #43 #357)
  4.1028 +#356 := (>= #358 0::real)
  4.1029 +#355 := (not #356)
  4.1030 +#374 := (* -1::real #59)
  4.1031 +#375 := (+ #56 #374)
  4.1032 +#373 := (>= #375 0::real)
  4.1033 +#376 := (not #373)
  4.1034 +#381 := (and #355 #376)
  4.1035 +#64 := (< #39 #39)
  4.1036 +#67 := (ite #64 #43 #59)
  4.1037 +#68 := (< #56 #67)
  4.1038 +#53 := (uf_4 uf_5 #42)
  4.1039 +#65 := (ite #64 #53 #43)
  4.1040 +#66 := (< #65 #56)
  4.1041 +#69 := (and #66 #68)
  4.1042 +#382 := (iff #69 #381)
  4.1043 +#379 := (iff #68 #376)
  4.1044 +#370 := (< #56 #59)
  4.1045 +#377 := (iff #370 #376)
  4.1046 +#378 := [rewrite]: #377
  4.1047 +#371 := (iff #68 #370)
  4.1048 +#368 := (= #67 #59)
  4.1049 +#363 := (ite false #43 #59)
  4.1050 +#366 := (= #363 #59)
  4.1051 +#367 := [rewrite]: #366
  4.1052 +#364 := (= #67 #363)
  4.1053 +#343 := (iff #64 false)
  4.1054 +#344 := [rewrite]: #343
  4.1055 +#365 := [monotonicity #344]: #364
  4.1056 +#369 := [trans #365 #367]: #368
  4.1057 +#372 := [monotonicity #369]: #371
  4.1058 +#380 := [trans #372 #378]: #379
  4.1059 +#361 := (iff #66 #355)
  4.1060 +#352 := (< #43 #56)
  4.1061 +#359 := (iff #352 #355)
  4.1062 +#360 := [rewrite]: #359
  4.1063 +#353 := (iff #66 #352)
  4.1064 +#350 := (= #65 #43)
  4.1065 +#345 := (ite false #53 #43)
  4.1066 +#348 := (= #345 #43)
  4.1067 +#349 := [rewrite]: #348
  4.1068 +#346 := (= #65 #345)
  4.1069 +#347 := [monotonicity #344]: #346
  4.1070 +#351 := [trans #347 #349]: #350
  4.1071 +#354 := [monotonicity #351]: #353
  4.1072 +#362 := [trans #354 #360]: #361
  4.1073 +#383 := [monotonicity #362 #380]: #382
  4.1074 +#340 := [asserted]: #69
  4.1075 +#384 := [mp #340 #383]: #381
  4.1076 +#385 := [and-elim #384]: #355
  4.1077 +#394 := (* -1::real #53)
  4.1078 +#395 := (+ #43 #394)
  4.1079 +#393 := (>= #395 0::real)
  4.1080 +#54 := (uf_4 uf_7 #42)
  4.1081 +#402 := (* -1::real #54)
  4.1082 +#403 := (+ #53 #402)
  4.1083 +#401 := (>= #403 0::real)
  4.1084 +#397 := (+ #43 #374)
  4.1085 +#398 := (<= #397 0::real)
  4.1086 +#412 := (and #393 #398 #401)
  4.1087 +#73 := (<= #43 #59)
  4.1088 +#72 := (<= #53 #43)
  4.1089 +#74 := (and #72 #73)
  4.1090 +#71 := (<= #54 #53)
  4.1091 +#75 := (and #71 #74)
  4.1092 +#415 := (iff #75 #412)
  4.1093 +#406 := (and #393 #398)
  4.1094 +#409 := (and #401 #406)
  4.1095 +#413 := (iff #409 #412)
  4.1096 +#414 := [rewrite]: #413
  4.1097 +#410 := (iff #75 #409)
  4.1098 +#407 := (iff #74 #406)
  4.1099 +#399 := (iff #73 #398)
  4.1100 +#400 := [rewrite]: #399
  4.1101 +#392 := (iff #72 #393)
  4.1102 +#396 := [rewrite]: #392
  4.1103 +#408 := [monotonicity #396 #400]: #407
  4.1104 +#404 := (iff #71 #401)
  4.1105 +#405 := [rewrite]: #404
  4.1106 +#411 := [monotonicity #405 #408]: #410
  4.1107 +#416 := [trans #411 #414]: #415
  4.1108 +#342 := [asserted]: #75
  4.1109 +#417 := [mp #342 #416]: #412
  4.1110 +#418 := [and-elim #417]: #393
  4.1111 +#650 := (+ #26 #394)
  4.1112 +#651 := (<= #650 0::real)
  4.1113 +#649 := (= #26 #53)
  4.1114 +#671 := (= #53 #26)
  4.1115 +#669 := (= #42 #25)
  4.1116 +#667 := (= #25 #42)
  4.1117 +#668 := [monotonicity #661]: #667
  4.1118 +#670 := [symm #668]: #669
  4.1119 +#672 := [monotonicity #670]: #671
  4.1120 +#673 := [symm #672]: #649
  4.1121 +#674 := (not #649)
  4.1122 +#675 := (or #674 #651)
  4.1123 +#676 := [th-lemma]: #675
  4.1124 +#677 := [unit-resolution #676 #673]: #651
  4.1125 +#462 := (+ #56 #459)
  4.1126 +#465 := (>= #462 0::real)
  4.1127 +#438 := (not #465)
  4.1128 +#316 := (ite #290 #278 #43)
  4.1129 +#326 := (* -1::real #316)
  4.1130 +#327 := (+ #56 #326)
  4.1131 +#325 := (>= #327 0::real)
  4.1132 +#324 := (not #325)
  4.1133 +#439 := (iff #324 #438)
  4.1134 +#466 := (iff #325 #465)
  4.1135 +#463 := (= #327 #462)
  4.1136 +#460 := (= #326 #459)
  4.1137 +#457 := (= #316 #278)
  4.1138 +#1 := true
  4.1139 +#452 := (ite true #278 #43)
  4.1140 +#455 := (= #452 #278)
  4.1141 +#456 := [rewrite]: #455
  4.1142 +#453 := (= #316 #452)
  4.1143 +#444 := (iff #290 true)
  4.1144 +#445 := [iff-true #390]: #444
  4.1145 +#454 := [monotonicity #445]: #453
  4.1146 +#458 := [trans #454 #456]: #457
  4.1147 +#461 := [monotonicity #458]: #460
  4.1148 +#464 := [monotonicity #461]: #463
  4.1149 +#467 := [monotonicity #464]: #466
  4.1150 +#468 := [monotonicity #467]: #439
  4.1151 +#297 := (ite #290 #54 #53)
  4.1152 +#305 := (* -1::real #297)
  4.1153 +#306 := (+ #56 #305)
  4.1154 +#307 := (<= #306 0::real)
  4.1155 +#308 := (not #307)
  4.1156 +#332 := (and #308 #324)
  4.1157 +#58 := (= uf_10 uf_3)
  4.1158 +#60 := (ite #58 #26 #59)
  4.1159 +#52 := (< #39 #22)
  4.1160 +#61 := (ite #52 #43 #60)
  4.1161 +#62 := (< #56 #61)
  4.1162 +#55 := (ite #52 #53 #54)
  4.1163 +#57 := (< #55 #56)
  4.1164 +#63 := (and #57 #62)
  4.1165 +#335 := (iff #63 #332)
  4.1166 +#281 := (ite #52 #43 #278)
  4.1167 +#284 := (< #56 #281)
  4.1168 +#287 := (and #57 #284)
  4.1169 +#333 := (iff #287 #332)
  4.1170 +#330 := (iff #284 #324)
  4.1171 +#321 := (< #56 #316)
  4.1172 +#328 := (iff #321 #324)
  4.1173 +#329 := [rewrite]: #328
  4.1174 +#322 := (iff #284 #321)
  4.1175 +#319 := (= #281 #316)
  4.1176 +#291 := (not #290)
  4.1177 +#313 := (ite #291 #43 #278)
  4.1178 +#317 := (= #313 #316)
  4.1179 +#318 := [rewrite]: #317
  4.1180 +#314 := (= #281 #313)
  4.1181 +#292 := (iff #52 #291)
  4.1182 +#293 := [rewrite]: #292
  4.1183 +#315 := [monotonicity #293]: #314
  4.1184 +#320 := [trans #315 #318]: #319
  4.1185 +#323 := [monotonicity #320]: #322
  4.1186 +#331 := [trans #323 #329]: #330
  4.1187 +#311 := (iff #57 #308)
  4.1188 +#302 := (< #297 #56)
  4.1189 +#309 := (iff #302 #308)
  4.1190 +#310 := [rewrite]: #309
  4.1191 +#303 := (iff #57 #302)
  4.1192 +#300 := (= #55 #297)
  4.1193 +#294 := (ite #291 #53 #54)
  4.1194 +#298 := (= #294 #297)
  4.1195 +#299 := [rewrite]: #298
  4.1196 +#295 := (= #55 #294)
  4.1197 +#296 := [monotonicity #293]: #295
  4.1198 +#301 := [trans #296 #299]: #300
  4.1199 +#304 := [monotonicity #301]: #303
  4.1200 +#312 := [trans #304 #310]: #311
  4.1201 +#334 := [monotonicity #312 #331]: #333
  4.1202 +#288 := (iff #63 #287)
  4.1203 +#285 := (iff #62 #284)
  4.1204 +#282 := (= #61 #281)
  4.1205 +#279 := (= #60 #278)
  4.1206 +#225 := (iff #58 #41)
  4.1207 +#277 := [rewrite]: #225
  4.1208 +#280 := [monotonicity #277]: #279
  4.1209 +#283 := [monotonicity #280]: #282
  4.1210 +#286 := [monotonicity #283]: #285
  4.1211 +#289 := [monotonicity #286]: #288
  4.1212 +#336 := [trans #289 #334]: #335
  4.1213 +#179 := [asserted]: #63
  4.1214 +#337 := [mp #179 #336]: #332
  4.1215 +#339 := [and-elim #337]: #324
  4.1216 +#469 := [mp #339 #468]: #438
  4.1217 +#678 := [th-lemma #469 #677 #418 #385 #666]: false
  4.1218 +#679 := [lemma #678]: #570
  4.1219 +#684 := [unit-resolution #679 #683]: false
  4.1220 +#685 := [lemma #684]: #227
  4.1221 +#577 := (or #228 #567)
  4.1222 +#578 := [def-axiom]: #577
  4.1223 +#645 := [unit-resolution #578 #685]: #567
  4.1224 +#686 := (not #567)
  4.1225 +#687 := (or #686 #643)
  4.1226 +#688 := [th-lemma]: #687
  4.1227 +#689 := [unit-resolution #688 #645]: #643
  4.1228 +#31 := (uf_4 uf_8 #25)
  4.1229 +#245 := (+ #31 #244)
  4.1230 +#246 := (<= #245 0::real)
  4.1231 +#247 := (not #246)
  4.1232 +#34 := (uf_4 uf_9 #25)
  4.1233 +#48 := (uf_4 uf_11 #25)
  4.1234 +#255 := (ite #228 #48 #34)
  4.1235 +#264 := (* -1::real #255)
  4.1236 +#265 := (+ #31 #264)
  4.1237 +#263 := (>= #265 0::real)
  4.1238 +#266 := (not #263)
  4.1239 +#271 := (and #247 #266)
  4.1240 +#40 := (< #22 #39)
  4.1241 +#49 := (ite #40 #34 #48)
  4.1242 +#50 := (< #31 #49)
  4.1243 +#45 := (ite #40 #26 #44)
  4.1244 +#46 := (< #45 #31)
  4.1245 +#51 := (and #46 #50)
  4.1246 +#272 := (iff #51 #271)
  4.1247 +#269 := (iff #50 #266)
  4.1248 +#260 := (< #31 #255)
  4.1249 +#267 := (iff #260 #266)
  4.1250 +#268 := [rewrite]: #267
  4.1251 +#261 := (iff #50 #260)
  4.1252 +#258 := (= #49 #255)
  4.1253 +#252 := (ite #227 #34 #48)
  4.1254 +#256 := (= #252 #255)
  4.1255 +#257 := [rewrite]: #256
  4.1256 +#253 := (= #49 #252)
  4.1257 +#231 := (iff #40 #227)
  4.1258 +#232 := [rewrite]: #231
  4.1259 +#254 := [monotonicity #232]: #253
  4.1260 +#259 := [trans #254 #257]: #258
  4.1261 +#262 := [monotonicity #259]: #261
  4.1262 +#270 := [trans #262 #268]: #269
  4.1263 +#250 := (iff #46 #247)
  4.1264 +#241 := (< #236 #31)
  4.1265 +#248 := (iff #241 #247)
  4.1266 +#249 := [rewrite]: #248
  4.1267 +#242 := (iff #46 #241)
  4.1268 +#239 := (= #45 #236)
  4.1269 +#233 := (ite #227 #26 #44)
  4.1270 +#237 := (= #233 #236)
  4.1271 +#238 := [rewrite]: #237
  4.1272 +#234 := (= #45 #233)
  4.1273 +#235 := [monotonicity #232]: #234
  4.1274 +#240 := [trans #235 #238]: #239
  4.1275 +#243 := [monotonicity #240]: #242
  4.1276 +#251 := [trans #243 #249]: #250
  4.1277 +#273 := [monotonicity #251 #270]: #272
  4.1278 +#178 := [asserted]: #51
  4.1279 +#274 := [mp #178 #273]: #271
  4.1280 +#275 := [and-elim #274]: #247
  4.1281 +#196 := (* -1::real #31)
  4.1282 +#212 := (+ #26 #196)
  4.1283 +#213 := (<= #212 0::real)
  4.1284 +#214 := (not #213)
  4.1285 +#197 := (+ #28 #196)
  4.1286 +#195 := (>= #197 0::real)
  4.1287 +#193 := (not #195)
  4.1288 +#219 := (and #193 #214)
  4.1289 +#23 := (< #22 #22)
  4.1290 +#35 := (ite #23 #34 #26)
  4.1291 +#36 := (< #31 #35)
  4.1292 +#29 := (ite #23 #26 #28)
  4.1293 +#32 := (< #29 #31)
  4.1294 +#37 := (and #32 #36)
  4.1295 +#220 := (iff #37 #219)
  4.1296 +#217 := (iff #36 #214)
  4.1297 +#209 := (< #31 #26)
  4.1298 +#215 := (iff #209 #214)
  4.1299 +#216 := [rewrite]: #215
  4.1300 +#210 := (iff #36 #209)
  4.1301 +#207 := (= #35 #26)
  4.1302 +#202 := (ite false #34 #26)
  4.1303 +#205 := (= #202 #26)
  4.1304 +#206 := [rewrite]: #205
  4.1305 +#203 := (= #35 #202)
  4.1306 +#180 := (iff #23 false)
  4.1307 +#181 := [rewrite]: #180
  4.1308 +#204 := [monotonicity #181]: #203
  4.1309 +#208 := [trans #204 #206]: #207
  4.1310 +#211 := [monotonicity #208]: #210
  4.1311 +#218 := [trans #211 #216]: #217
  4.1312 +#200 := (iff #32 #193)
  4.1313 +#189 := (< #28 #31)
  4.1314 +#198 := (iff #189 #193)
  4.1315 +#199 := [rewrite]: #198
  4.1316 +#190 := (iff #32 #189)
  4.1317 +#187 := (= #29 #28)
  4.1318 +#182 := (ite false #26 #28)
  4.1319 +#185 := (= #182 #28)
  4.1320 +#186 := [rewrite]: #185
  4.1321 +#183 := (= #29 #182)
  4.1322 +#184 := [monotonicity #181]: #183
  4.1323 +#188 := [trans #184 #186]: #187
  4.1324 +#191 := [monotonicity #188]: #190
  4.1325 +#201 := [trans #191 #199]: #200
  4.1326 +#221 := [monotonicity #201 #218]: #220
  4.1327 +#177 := [asserted]: #37
  4.1328 +#222 := [mp #177 #221]: #219
  4.1329 +#224 := [and-elim #222]: #214
  4.1330 +[th-lemma #224 #275 #689]: false
  4.1331 +unsat
  4.1332 +NX/HT1QOfbspC2LtZNKpBA 428 0
  4.1333 +#2 := false
  4.1334 +decl uf_10 :: T1
  4.1335 +#38 := uf_10
  4.1336 +decl uf_3 :: T1
  4.1337 +#21 := uf_3
  4.1338 +#45 := (= uf_3 uf_10)
  4.1339 +decl uf_1 :: (-> int T1)
  4.1340 +decl uf_2 :: (-> T1 int)
  4.1341 +#39 := (uf_2 uf_10)
  4.1342 +#588 := (uf_1 #39)
  4.1343 +#686 := (= #588 uf_10)
  4.1344 +#589 := (= uf_10 #588)
  4.1345 +#4 := (:var 0 T1)
  4.1346 +#5 := (uf_2 #4)
  4.1347 +#541 := (pattern #5)
  4.1348 +#6 := (uf_1 #5)
  4.1349 +#93 := (= #4 #6)
  4.1350 +#542 := (forall (vars (?x1 T1)) (:pat #541) #93)
  4.1351 +#96 := (forall (vars (?x1 T1)) #93)
  4.1352 +#545 := (iff #96 #542)
  4.1353 +#543 := (iff #93 #93)
  4.1354 +#544 := [refl]: #543
  4.1355 +#546 := [quant-intro #544]: #545
  4.1356 +#454 := (~ #96 #96)
  4.1357 +#456 := (~ #93 #93)
  4.1358 +#457 := [refl]: #456
  4.1359 +#455 := [nnf-pos #457]: #454
  4.1360 +#7 := (= #6 #4)
  4.1361 +#8 := (forall (vars (?x1 T1)) #7)
  4.1362 +#97 := (iff #8 #96)
  4.1363 +#94 := (iff #7 #93)
  4.1364 +#95 := [rewrite]: #94
  4.1365 +#98 := [quant-intro #95]: #97
  4.1366 +#92 := [asserted]: #8
  4.1367 +#101 := [mp #92 #98]: #96
  4.1368 +#452 := [mp~ #101 #455]: #96
  4.1369 +#547 := [mp #452 #546]: #542
  4.1370 +#590 := (not #542)
  4.1371 +#595 := (or #590 #589)
  4.1372 +#596 := [quant-inst]: #595
  4.1373 +#680 := [unit-resolution #596 #547]: #589
  4.1374 +#687 := [symm #680]: #686
  4.1375 +#688 := (= uf_3 #588)
  4.1376 +#22 := (uf_2 uf_3)
  4.1377 +#586 := (uf_1 #22)
  4.1378 +#684 := (= #586 #588)
  4.1379 +#682 := (= #588 #586)
  4.1380 +#678 := (= #39 #22)
  4.1381 +#676 := (= #22 #39)
  4.1382 +#9 := 0::int
  4.1383 +#227 := -1::int
  4.1384 +#230 := (* -1::int #39)
  4.1385 +#231 := (+ #22 #230)
  4.1386 +#296 := (<= #231 0::int)
  4.1387 +#70 := (<= #22 #39)
  4.1388 +#393 := (iff #70 #296)
  4.1389 +#394 := [rewrite]: #393
  4.1390 +#347 := [asserted]: #70
  4.1391 +#395 := [mp #347 #394]: #296
  4.1392 +#229 := (>= #231 0::int)
  4.1393 +decl uf_4 :: (-> T2 T3 real)
  4.1394 +decl uf_6 :: (-> T1 T3)
  4.1395 +#25 := (uf_6 uf_3)
  4.1396 +decl uf_7 :: T2
  4.1397 +#27 := uf_7
  4.1398 +#28 := (uf_4 uf_7 #25)
  4.1399 +decl uf_9 :: T2
  4.1400 +#33 := uf_9
  4.1401 +#34 := (uf_4 uf_9 #25)
  4.1402 +#46 := (uf_6 uf_10)
  4.1403 +decl uf_5 :: T2
  4.1404 +#24 := uf_5
  4.1405 +#47 := (uf_4 uf_5 #46)
  4.1406 +#48 := (ite #45 #47 #34)
  4.1407 +#256 := (ite #229 #48 #28)
  4.1408 +#568 := (= #28 #256)
  4.1409 +#648 := (not #568)
  4.1410 +#194 := 0::real
  4.1411 +#192 := -1::real
  4.1412 +#265 := (* -1::real #256)
  4.1413 +#640 := (+ #28 #265)
  4.1414 +#642 := (>= #640 0::real)
  4.1415 +#645 := (not #642)
  4.1416 +#643 := [hypothesis]: #642
  4.1417 +decl uf_8 :: T2
  4.1418 +#30 := uf_8
  4.1419 +#31 := (uf_4 uf_8 #25)
  4.1420 +#266 := (+ #31 #265)
  4.1421 +#264 := (>= #266 0::real)
  4.1422 +#267 := (not #264)
  4.1423 +#26 := (uf_4 uf_5 #25)
  4.1424 +decl uf_11 :: T2
  4.1425 +#41 := uf_11
  4.1426 +#42 := (uf_4 uf_11 #25)
  4.1427 +#237 := (ite #229 #42 #26)
  4.1428 +#245 := (* -1::real #237)
  4.1429 +#246 := (+ #31 #245)
  4.1430 +#247 := (<= #246 0::real)
  4.1431 +#248 := (not #247)
  4.1432 +#272 := (and #248 #267)
  4.1433 +#40 := (< #22 #39)
  4.1434 +#49 := (ite #40 #28 #48)
  4.1435 +#50 := (< #31 #49)
  4.1436 +#43 := (ite #40 #26 #42)
  4.1437 +#44 := (< #43 #31)
  4.1438 +#51 := (and #44 #50)
  4.1439 +#273 := (iff #51 #272)
  4.1440 +#270 := (iff #50 #267)
  4.1441 +#261 := (< #31 #256)
  4.1442 +#268 := (iff #261 #267)
  4.1443 +#269 := [rewrite]: #268
  4.1444 +#262 := (iff #50 #261)
  4.1445 +#259 := (= #49 #256)
  4.1446 +#228 := (not #229)
  4.1447 +#253 := (ite #228 #28 #48)
  4.1448 +#257 := (= #253 #256)
  4.1449 +#258 := [rewrite]: #257
  4.1450 +#254 := (= #49 #253)
  4.1451 +#232 := (iff #40 #228)
  4.1452 +#233 := [rewrite]: #232
  4.1453 +#255 := [monotonicity #233]: #254
  4.1454 +#260 := [trans #255 #258]: #259
  4.1455 +#263 := [monotonicity #260]: #262
  4.1456 +#271 := [trans #263 #269]: #270
  4.1457 +#251 := (iff #44 #248)
  4.1458 +#242 := (< #237 #31)
  4.1459 +#249 := (iff #242 #248)
  4.1460 +#250 := [rewrite]: #249
  4.1461 +#243 := (iff #44 #242)
  4.1462 +#240 := (= #43 #237)
  4.1463 +#234 := (ite #228 #26 #42)
  4.1464 +#238 := (= #234 #237)
  4.1465 +#239 := [rewrite]: #238
  4.1466 +#235 := (= #43 #234)
  4.1467 +#236 := [monotonicity #233]: #235
  4.1468 +#241 := [trans #236 #239]: #240
  4.1469 +#244 := [monotonicity #241]: #243
  4.1470 +#252 := [trans #244 #250]: #251
  4.1471 +#274 := [monotonicity #252 #271]: #273
  4.1472 +#178 := [asserted]: #51
  4.1473 +#275 := [mp #178 #274]: #272
  4.1474 +#277 := [and-elim #275]: #267
  4.1475 +#196 := (* -1::real #31)
  4.1476 +#197 := (+ #28 #196)
  4.1477 +#195 := (>= #197 0::real)
  4.1478 +#193 := (not #195)
  4.1479 +#213 := (* -1::real #34)
  4.1480 +#214 := (+ #31 #213)
  4.1481 +#212 := (>= #214 0::real)
  4.1482 +#215 := (not #212)
  4.1483 +#220 := (and #193 #215)
  4.1484 +#23 := (< #22 #22)
  4.1485 +#35 := (ite #23 #28 #34)
  4.1486 +#36 := (< #31 #35)
  4.1487 +#29 := (ite #23 #26 #28)
  4.1488 +#32 := (< #29 #31)
  4.1489 +#37 := (and #32 #36)
  4.1490 +#221 := (iff #37 #220)
  4.1491 +#218 := (iff #36 #215)
  4.1492 +#209 := (< #31 #34)
  4.1493 +#216 := (iff #209 #215)
  4.1494 +#217 := [rewrite]: #216
  4.1495 +#210 := (iff #36 #209)
  4.1496 +#207 := (= #35 #34)
  4.1497 +#202 := (ite false #28 #34)
  4.1498 +#205 := (= #202 #34)
  4.1499 +#206 := [rewrite]: #205
  4.1500 +#203 := (= #35 #202)
  4.1501 +#180 := (iff #23 false)
  4.1502 +#181 := [rewrite]: #180
  4.1503 +#204 := [monotonicity #181]: #203
  4.1504 +#208 := [trans #204 #206]: #207
  4.1505 +#211 := [monotonicity #208]: #210
  4.1506 +#219 := [trans #211 #217]: #218
  4.1507 +#200 := (iff #32 #193)
  4.1508 +#189 := (< #28 #31)
  4.1509 +#198 := (iff #189 #193)
  4.1510 +#199 := [rewrite]: #198
  4.1511 +#190 := (iff #32 #189)
  4.1512 +#187 := (= #29 #28)
  4.1513 +#182 := (ite false #26 #28)
  4.1514 +#185 := (= #182 #28)
  4.1515 +#186 := [rewrite]: #185
  4.1516 +#183 := (= #29 #182)
  4.1517 +#184 := [monotonicity #181]: #183
  4.1518 +#188 := [trans #184 #186]: #187
  4.1519 +#191 := [monotonicity #188]: #190
  4.1520 +#201 := [trans #191 #199]: #200
  4.1521 +#222 := [monotonicity #201 #219]: #221
  4.1522 +#177 := [asserted]: #37
  4.1523 +#223 := [mp #177 #222]: #220
  4.1524 +#224 := [and-elim #223]: #193
  4.1525 +#644 := [th-lemma #224 #277 #643]: false
  4.1526 +#646 := [lemma #644]: #645
  4.1527 +#647 := [hypothesis]: #568
  4.1528 +#649 := (or #648 #642)
  4.1529 +#650 := [th-lemma]: #649
  4.1530 +#651 := [unit-resolution #650 #647 #646]: false
  4.1531 +#652 := [lemma #651]: #648
  4.1532 +#578 := (or #229 #568)
  4.1533 +#579 := [def-axiom]: #578
  4.1534 +#675 := [unit-resolution #579 #652]: #229
  4.1535 +#677 := [th-lemma #675 #395]: #676
  4.1536 +#679 := [symm #677]: #678
  4.1537 +#683 := [monotonicity #679]: #682
  4.1538 +#685 := [symm #683]: #684
  4.1539 +#587 := (= uf_3 #586)
  4.1540 +#591 := (or #590 #587)
  4.1541 +#592 := [quant-inst]: #591
  4.1542 +#681 := [unit-resolution #592 #547]: #587
  4.1543 +#689 := [trans #681 #685]: #688
  4.1544 +#690 := [trans #689 #687]: #45
  4.1545 +#571 := (not #45)
  4.1546 +#54 := (uf_4 uf_11 #46)
  4.1547 +#279 := (ite #45 #28 #54)
  4.1548 +#465 := (* -1::real #279)
  4.1549 +#632 := (+ #28 #465)
  4.1550 +#633 := (<= #632 0::real)
  4.1551 +#580 := (= #28 #279)
  4.1552 +#656 := [hypothesis]: #45
  4.1553 +#582 := (or #571 #580)
  4.1554 +#583 := [def-axiom]: #582
  4.1555 +#657 := [unit-resolution #583 #656]: #580
  4.1556 +#658 := (not #580)
  4.1557 +#659 := (or #658 #633)
  4.1558 +#660 := [th-lemma]: #659
  4.1559 +#661 := [unit-resolution #660 #657]: #633
  4.1560 +#57 := (uf_4 uf_8 #46)
  4.1561 +#363 := (* -1::real #57)
  4.1562 +#379 := (+ #47 #363)
  4.1563 +#380 := (<= #379 0::real)
  4.1564 +#381 := (not #380)
  4.1565 +#364 := (+ #54 #363)
  4.1566 +#362 := (>= #364 0::real)
  4.1567 +#361 := (not #362)
  4.1568 +#386 := (and #361 #381)
  4.1569 +#59 := (uf_4 uf_7 #46)
  4.1570 +#64 := (< #39 #39)
  4.1571 +#67 := (ite #64 #59 #47)
  4.1572 +#68 := (< #57 #67)
  4.1573 +#65 := (ite #64 #47 #54)
  4.1574 +#66 := (< #65 #57)
  4.1575 +#69 := (and #66 #68)
  4.1576 +#387 := (iff #69 #386)
  4.1577 +#384 := (iff #68 #381)
  4.1578 +#376 := (< #57 #47)
  4.1579 +#382 := (iff #376 #381)
  4.1580 +#383 := [rewrite]: #382
  4.1581 +#377 := (iff #68 #376)
  4.1582 +#374 := (= #67 #47)
  4.1583 +#369 := (ite false #59 #47)
  4.1584 +#372 := (= #369 #47)
  4.1585 +#373 := [rewrite]: #372
  4.1586 +#370 := (= #67 #369)
  4.1587 +#349 := (iff #64 false)
  4.1588 +#350 := [rewrite]: #349
  4.1589 +#371 := [monotonicity #350]: #370
  4.1590 +#375 := [trans #371 #373]: #374
  4.1591 +#378 := [monotonicity #375]: #377
  4.1592 +#385 := [trans #378 #383]: #384
  4.1593 +#367 := (iff #66 #361)
  4.1594 +#358 := (< #54 #57)
  4.1595 +#365 := (iff #358 #361)
  4.1596 +#366 := [rewrite]: #365
  4.1597 +#359 := (iff #66 #358)
  4.1598 +#356 := (= #65 #54)
  4.1599 +#351 := (ite false #47 #54)
  4.1600 +#354 := (= #351 #54)
  4.1601 +#355 := [rewrite]: #354
  4.1602 +#352 := (= #65 #351)
  4.1603 +#353 := [monotonicity #350]: #352
  4.1604 +#357 := [trans #353 #355]: #356
  4.1605 +#360 := [monotonicity #357]: #359
  4.1606 +#368 := [trans #360 #366]: #367
  4.1607 +#388 := [monotonicity #368 #385]: #387
  4.1608 +#346 := [asserted]: #69
  4.1609 +#389 := [mp #346 #388]: #386
  4.1610 +#391 := [and-elim #389]: #381
  4.1611 +#397 := (* -1::real #59)
  4.1612 +#398 := (+ #47 #397)
  4.1613 +#399 := (<= #398 0::real)
  4.1614 +#409 := (* -1::real #54)
  4.1615 +#410 := (+ #47 #409)
  4.1616 +#408 := (>= #410 0::real)
  4.1617 +#60 := (uf_4 uf_9 #46)
  4.1618 +#402 := (* -1::real #60)
  4.1619 +#403 := (+ #59 #402)
  4.1620 +#404 := (<= #403 0::real)
  4.1621 +#418 := (and #399 #404 #408)
  4.1622 +#73 := (<= #59 #60)
  4.1623 +#72 := (<= #47 #59)
  4.1624 +#74 := (and #72 #73)
  4.1625 +#71 := (<= #54 #47)
  4.1626 +#75 := (and #71 #74)
  4.1627 +#421 := (iff #75 #418)
  4.1628 +#412 := (and #399 #404)
  4.1629 +#415 := (and #408 #412)
  4.1630 +#419 := (iff #415 #418)
  4.1631 +#420 := [rewrite]: #419
  4.1632 +#416 := (iff #75 #415)
  4.1633 +#413 := (iff #74 #412)
  4.1634 +#405 := (iff #73 #404)
  4.1635 +#406 := [rewrite]: #405
  4.1636 +#400 := (iff #72 #399)
  4.1637 +#401 := [rewrite]: #400
  4.1638 +#414 := [monotonicity #401 #406]: #413
  4.1639 +#407 := (iff #71 #408)
  4.1640 +#411 := [rewrite]: #407
  4.1641 +#417 := [monotonicity #411 #414]: #416
  4.1642 +#422 := [trans #417 #420]: #421
  4.1643 +#348 := [asserted]: #75
  4.1644 +#423 := [mp #348 #422]: #418
  4.1645 +#424 := [and-elim #423]: #399
  4.1646 +#637 := (+ #28 #397)
  4.1647 +#639 := (>= #637 0::real)
  4.1648 +#636 := (= #28 #59)
  4.1649 +#666 := (= #59 #28)
  4.1650 +#664 := (= #46 #25)
  4.1651 +#662 := (= #25 #46)
  4.1652 +#663 := [monotonicity #656]: #662
  4.1653 +#665 := [symm #663]: #664
  4.1654 +#667 := [monotonicity #665]: #666
  4.1655 +#668 := [symm #667]: #636
  4.1656 +#669 := (not #636)
  4.1657 +#670 := (or #669 #639)
  4.1658 +#671 := [th-lemma]: #670
  4.1659 +#672 := [unit-resolution #671 #668]: #639
  4.1660 +#468 := (+ #57 #465)
  4.1661 +#471 := (<= #468 0::real)
  4.1662 +#444 := (not #471)
  4.1663 +#322 := (ite #296 #279 #47)
  4.1664 +#330 := (* -1::real #322)
  4.1665 +#331 := (+ #57 #330)
  4.1666 +#332 := (<= #331 0::real)
  4.1667 +#333 := (not #332)
  4.1668 +#445 := (iff #333 #444)
  4.1669 +#472 := (iff #332 #471)
  4.1670 +#469 := (= #331 #468)
  4.1671 +#466 := (= #330 #465)
  4.1672 +#463 := (= #322 #279)
  4.1673 +#1 := true
  4.1674 +#458 := (ite true #279 #47)
  4.1675 +#461 := (= #458 #279)
  4.1676 +#462 := [rewrite]: #461
  4.1677 +#459 := (= #322 #458)
  4.1678 +#450 := (iff #296 true)
  4.1679 +#451 := [iff-true #395]: #450
  4.1680 +#460 := [monotonicity #451]: #459
  4.1681 +#464 := [trans #460 #462]: #463
  4.1682 +#467 := [monotonicity #464]: #466
  4.1683 +#470 := [monotonicity #467]: #469
  4.1684 +#473 := [monotonicity #470]: #472
  4.1685 +#474 := [monotonicity #473]: #445
  4.1686 +#303 := (ite #296 #60 #59)
  4.1687 +#313 := (* -1::real #303)
  4.1688 +#314 := (+ #57 #313)
  4.1689 +#312 := (>= #314 0::real)
  4.1690 +#311 := (not #312)
  4.1691 +#338 := (and #311 #333)
  4.1692 +#52 := (< #39 #22)
  4.1693 +#61 := (ite #52 #59 #60)
  4.1694 +#62 := (< #57 #61)
  4.1695 +#53 := (= uf_10 uf_3)
  4.1696 +#55 := (ite #53 #28 #54)
  4.1697 +#56 := (ite #52 #47 #55)
  4.1698 +#58 := (< #56 #57)
  4.1699 +#63 := (and #58 #62)
  4.1700 +#341 := (iff #63 #338)
  4.1701 +#282 := (ite #52 #47 #279)
  4.1702 +#285 := (< #282 #57)
  4.1703 +#291 := (and #62 #285)
  4.1704 +#339 := (iff #291 #338)
  4.1705 +#336 := (iff #285 #333)
  4.1706 +#327 := (< #322 #57)
  4.1707 +#334 := (iff #327 #333)
  4.1708 +#335 := [rewrite]: #334
  4.1709 +#328 := (iff #285 #327)
  4.1710 +#325 := (= #282 #322)
  4.1711 +#297 := (not #296)
  4.1712 +#319 := (ite #297 #47 #279)
  4.1713 +#323 := (= #319 #322)
  4.1714 +#324 := [rewrite]: #323
  4.1715 +#320 := (= #282 #319)
  4.1716 +#298 := (iff #52 #297)
  4.1717 +#299 := [rewrite]: #298
  4.1718 +#321 := [monotonicity #299]: #320
  4.1719 +#326 := [trans #321 #324]: #325
  4.1720 +#329 := [monotonicity #326]: #328
  4.1721 +#337 := [trans #329 #335]: #336
  4.1722 +#317 := (iff #62 #311)
  4.1723 +#308 := (< #57 #303)
  4.1724 +#315 := (iff #308 #311)
  4.1725 +#316 := [rewrite]: #315
  4.1726 +#309 := (iff #62 #308)
  4.1727 +#306 := (= #61 #303)
  4.1728 +#300 := (ite #297 #59 #60)
  4.1729 +#304 := (= #300 #303)
  4.1730 +#305 := [rewrite]: #304
  4.1731 +#301 := (= #61 #300)
  4.1732 +#302 := [monotonicity #299]: #301
  4.1733 +#307 := [trans #302 #305]: #306
  4.1734 +#310 := [monotonicity #307]: #309
  4.1735 +#318 := [trans #310 #316]: #317
  4.1736 +#340 := [monotonicity #318 #337]: #339
  4.1737 +#294 := (iff #63 #291)
  4.1738 +#288 := (and #285 #62)
  4.1739 +#292 := (iff #288 #291)
  4.1740 +#293 := [rewrite]: #292
  4.1741 +#289 := (iff #63 #288)
  4.1742 +#286 := (iff #58 #285)
  4.1743 +#283 := (= #56 #282)
  4.1744 +#280 := (= #55 #279)
  4.1745 +#226 := (iff #53 #45)
  4.1746 +#278 := [rewrite]: #226
  4.1747 +#281 := [monotonicity #278]: #280
  4.1748 +#284 := [monotonicity #281]: #283
  4.1749 +#287 := [monotonicity #284]: #286
  4.1750 +#290 := [monotonicity #287]: #289
  4.1751 +#295 := [trans #290 #293]: #294
  4.1752 +#342 := [trans #295 #340]: #341
  4.1753 +#179 := [asserted]: #63
  4.1754 +#343 := [mp #179 #342]: #338
  4.1755 +#345 := [and-elim #343]: #333
  4.1756 +#475 := [mp #345 #474]: #444
  4.1757 +#673 := [th-lemma #475 #672 #424 #391 #661]: false
  4.1758 +#674 := [lemma #673]: #571
  4.1759 +[unit-resolution #674 #690]: false
  4.1760 +unsat
  4.1761 +IL2powemHjRpCJYwmXFxyw 211 0
  4.1762 +#2 := false
  4.1763 +#33 := 0::real
  4.1764 +decl uf_11 :: (-> T5 T6 real)
  4.1765 +decl uf_15 :: T6
  4.1766 +#28 := uf_15
  4.1767 +decl uf_16 :: T5
  4.1768 +#30 := uf_16
  4.1769 +#31 := (uf_11 uf_16 uf_15)
  4.1770 +decl uf_12 :: (-> T7 T8 T5)
  4.1771 +decl uf_14 :: T8
  4.1772 +#26 := uf_14
  4.1773 +decl uf_13 :: (-> T1 T7)
  4.1774 +decl uf_8 :: T1
  4.1775 +#16 := uf_8
  4.1776 +#25 := (uf_13 uf_8)
  4.1777 +#27 := (uf_12 #25 uf_14)
  4.1778 +#29 := (uf_11 #27 uf_15)
  4.1779 +#73 := -1::real
  4.1780 +#84 := (* -1::real #29)
  4.1781 +#85 := (+ #84 #31)
  4.1782 +#74 := (* -1::real #31)
  4.1783 +#75 := (+ #29 #74)
  4.1784 +#112 := (>= #75 0::real)
  4.1785 +#119 := (ite #112 #75 #85)
  4.1786 +#127 := (* -1::real #119)
  4.1787 +decl uf_17 :: T5
  4.1788 +#37 := uf_17
  4.1789 +#38 := (uf_11 uf_17 uf_15)
  4.1790 +#102 := -1/3::real
  4.1791 +#103 := (* -1/3::real #38)
  4.1792 +#128 := (+ #103 #127)
  4.1793 +#100 := 1/3::real
  4.1794 +#101 := (* 1/3::real #31)
  4.1795 +#129 := (+ #101 #128)
  4.1796 +#130 := (<= #129 0::real)
  4.1797 +#131 := (not #130)
  4.1798 +#40 := 3::real
  4.1799 +#39 := (- #31 #38)
  4.1800 +#41 := (/ #39 3::real)
  4.1801 +#32 := (- #29 #31)
  4.1802 +#35 := (- #32)
  4.1803 +#34 := (< #32 0::real)
  4.1804 +#36 := (ite #34 #35 #32)
  4.1805 +#42 := (< #36 #41)
  4.1806 +#136 := (iff #42 #131)
  4.1807 +#104 := (+ #101 #103)
  4.1808 +#78 := (< #75 0::real)
  4.1809 +#90 := (ite #78 #85 #75)
  4.1810 +#109 := (< #90 #104)
  4.1811 +#134 := (iff #109 #131)
  4.1812 +#124 := (< #119 #104)
  4.1813 +#132 := (iff #124 #131)
  4.1814 +#133 := [rewrite]: #132
  4.1815 +#125 := (iff #109 #124)
  4.1816 +#122 := (= #90 #119)
  4.1817 +#113 := (not #112)
  4.1818 +#116 := (ite #113 #85 #75)
  4.1819 +#120 := (= #116 #119)
  4.1820 +#121 := [rewrite]: #120
  4.1821 +#117 := (= #90 #116)
  4.1822 +#114 := (iff #78 #113)
  4.1823 +#115 := [rewrite]: #114
  4.1824 +#118 := [monotonicity #115]: #117
  4.1825 +#123 := [trans #118 #121]: #122
  4.1826 +#126 := [monotonicity #123]: #125
  4.1827 +#135 := [trans #126 #133]: #134
  4.1828 +#110 := (iff #42 #109)
  4.1829 +#107 := (= #41 #104)
  4.1830 +#93 := (* -1::real #38)
  4.1831 +#94 := (+ #31 #93)
  4.1832 +#97 := (/ #94 3::real)
  4.1833 +#105 := (= #97 #104)
  4.1834 +#106 := [rewrite]: #105
  4.1835 +#98 := (= #41 #97)
  4.1836 +#95 := (= #39 #94)
  4.1837 +#96 := [rewrite]: #95
  4.1838 +#99 := [monotonicity #96]: #98
  4.1839 +#108 := [trans #99 #106]: #107
  4.1840 +#91 := (= #36 #90)
  4.1841 +#76 := (= #32 #75)
  4.1842 +#77 := [rewrite]: #76
  4.1843 +#88 := (= #35 #85)
  4.1844 +#81 := (- #75)
  4.1845 +#86 := (= #81 #85)
  4.1846 +#87 := [rewrite]: #86
  4.1847 +#82 := (= #35 #81)
  4.1848 +#83 := [monotonicity #77]: #82
  4.1849 +#89 := [trans #83 #87]: #88
  4.1850 +#79 := (iff #34 #78)
  4.1851 +#80 := [monotonicity #77]: #79
  4.1852 +#92 := [monotonicity #80 #89 #77]: #91
  4.1853 +#111 := [monotonicity #92 #108]: #110
  4.1854 +#137 := [trans #111 #135]: #136
  4.1855 +#72 := [asserted]: #42
  4.1856 +#138 := [mp #72 #137]: #131
  4.1857 +decl uf_1 :: T1
  4.1858 +#4 := uf_1
  4.1859 +#43 := (uf_13 uf_1)
  4.1860 +#44 := (uf_12 #43 uf_14)
  4.1861 +#45 := (uf_11 #44 uf_15)
  4.1862 +#149 := (* -1::real #45)
  4.1863 +#150 := (+ #38 #149)
  4.1864 +#140 := (+ #93 #45)
  4.1865 +#161 := (<= #150 0::real)
  4.1866 +#168 := (ite #161 #140 #150)
  4.1867 +#176 := (* -1::real #168)
  4.1868 +#177 := (+ #103 #176)
  4.1869 +#178 := (+ #101 #177)
  4.1870 +#179 := (<= #178 0::real)
  4.1871 +#180 := (not #179)
  4.1872 +#46 := (- #45 #38)
  4.1873 +#48 := (- #46)
  4.1874 +#47 := (< #46 0::real)
  4.1875 +#49 := (ite #47 #48 #46)
  4.1876 +#50 := (< #49 #41)
  4.1877 +#185 := (iff #50 #180)
  4.1878 +#143 := (< #140 0::real)
  4.1879 +#155 := (ite #143 #150 #140)
  4.1880 +#158 := (< #155 #104)
  4.1881 +#183 := (iff #158 #180)
  4.1882 +#173 := (< #168 #104)
  4.1883 +#181 := (iff #173 #180)
  4.1884 +#182 := [rewrite]: #181
  4.1885 +#174 := (iff #158 #173)
  4.1886 +#171 := (= #155 #168)
  4.1887 +#162 := (not #161)
  4.1888 +#165 := (ite #162 #150 #140)
  4.1889 +#169 := (= #165 #168)
  4.1890 +#170 := [rewrite]: #169
  4.1891 +#166 := (= #155 #165)
  4.1892 +#163 := (iff #143 #162)
  4.1893 +#164 := [rewrite]: #163
  4.1894 +#167 := [monotonicity #164]: #166
  4.1895 +#172 := [trans #167 #170]: #171
  4.1896 +#175 := [monotonicity #172]: #174
  4.1897 +#184 := [trans #175 #182]: #183
  4.1898 +#159 := (iff #50 #158)
  4.1899 +#156 := (= #49 #155)
  4.1900 +#141 := (= #46 #140)
  4.1901 +#142 := [rewrite]: #141
  4.1902 +#153 := (= #48 #150)
  4.1903 +#146 := (- #140)
  4.1904 +#151 := (= #146 #150)
  4.1905 +#152 := [rewrite]: #151
  4.1906 +#147 := (= #48 #146)
  4.1907 +#148 := [monotonicity #142]: #147
  4.1908 +#154 := [trans #148 #152]: #153
  4.1909 +#144 := (iff #47 #143)
  4.1910 +#145 := [monotonicity #142]: #144
  4.1911 +#157 := [monotonicity #145 #154 #142]: #156
  4.1912 +#160 := [monotonicity #157 #108]: #159
  4.1913 +#186 := [trans #160 #184]: #185
  4.1914 +#139 := [asserted]: #50
  4.1915 +#187 := [mp #139 #186]: #180
  4.1916 +#299 := (+ #140 #176)
  4.1917 +#300 := (<= #299 0::real)
  4.1918 +#290 := (= #140 #168)
  4.1919 +#329 := [hypothesis]: #162
  4.1920 +#191 := (+ #29 #149)
  4.1921 +#192 := (<= #191 0::real)
  4.1922 +#51 := (<= #29 #45)
  4.1923 +#193 := (iff #51 #192)
  4.1924 +#194 := [rewrite]: #193
  4.1925 +#188 := [asserted]: #51
  4.1926 +#195 := [mp #188 #194]: #192
  4.1927 +#298 := (+ #75 #127)
  4.1928 +#301 := (<= #298 0::real)
  4.1929 +#284 := (= #75 #119)
  4.1930 +#302 := [hypothesis]: #113
  4.1931 +#296 := (+ #85 #127)
  4.1932 +#297 := (<= #296 0::real)
  4.1933 +#285 := (= #85 #119)
  4.1934 +#288 := (or #112 #285)
  4.1935 +#289 := [def-axiom]: #288
  4.1936 +#303 := [unit-resolution #289 #302]: #285
  4.1937 +#304 := (not #285)
  4.1938 +#305 := (or #304 #297)
  4.1939 +#306 := [th-lemma]: #305
  4.1940 +#307 := [unit-resolution #306 #303]: #297
  4.1941 +#315 := (not #290)
  4.1942 +#310 := (not #300)
  4.1943 +#311 := (or #310 #112)
  4.1944 +#308 := [hypothesis]: #300
  4.1945 +#309 := [th-lemma #308 #307 #138 #302 #187 #195]: false
  4.1946 +#312 := [lemma #309]: #311
  4.1947 +#322 := [unit-resolution #312 #302]: #310
  4.1948 +#316 := (or #315 #300)
  4.1949 +#313 := [hypothesis]: #310
  4.1950 +#314 := [hypothesis]: #290
  4.1951 +#317 := [th-lemma]: #316
  4.1952 +#318 := [unit-resolution #317 #314 #313]: false
  4.1953 +#319 := [lemma #318]: #316
  4.1954 +#323 := [unit-resolution #319 #322]: #315
  4.1955 +#292 := (or #162 #290)
  4.1956 +#293 := [def-axiom]: #292
  4.1957 +#324 := [unit-resolution #293 #323]: #162
  4.1958 +#325 := [th-lemma #324 #307 #138 #302 #195]: false
  4.1959 +#326 := [lemma #325]: #112
  4.1960 +#286 := (or #113 #284)
  4.1961 +#287 := [def-axiom]: #286
  4.1962 +#330 := [unit-resolution #287 #326]: #284
  4.1963 +#331 := (not #284)
  4.1964 +#332 := (or #331 #301)
  4.1965 +#333 := [th-lemma]: #332
  4.1966 +#334 := [unit-resolution #333 #330]: #301
  4.1967 +#335 := [th-lemma #326 #334 #195 #329 #138]: false
  4.1968 +#336 := [lemma #335]: #161
  4.1969 +#327 := [unit-resolution #293 #336]: #290
  4.1970 +#328 := [unit-resolution #319 #327]: #300
  4.1971 +[th-lemma #326 #334 #195 #328 #187 #138]: false
  4.1972 +unsat
  4.1973 +GX51o3DUO/UBS3eNP2P9kA 285 0
  4.1974 +#2 := false
  4.1975 +#7 := 0::real
  4.1976 +decl uf_4 :: real
  4.1977 +#16 := uf_4
  4.1978 +#40 := -1::real
  4.1979 +#116 := (* -1::real uf_4)
  4.1980 +decl uf_3 :: real
  4.1981 +#11 := uf_3
  4.1982 +#117 := (+ uf_3 #116)
  4.1983 +#128 := (<= #117 0::real)
  4.1984 +#129 := (not #128)
  4.1985 +#220 := 2/3::real
  4.1986 +#221 := (* 2/3::real uf_3)
  4.1987 +#222 := (+ #221 #116)
  4.1988 +decl uf_2 :: real
  4.1989 +#5 := uf_2
  4.1990 +#67 := 1/3::real
  4.1991 +#68 := (* 1/3::real uf_2)
  4.1992 +#233 := (+ #68 #222)
  4.1993 +#243 := (<= #233 0::real)
  4.1994 +#268 := (not #243)
  4.1995 +#287 := [hypothesis]: #268
  4.1996 +#41 := (* -1::real uf_2)
  4.1997 +decl uf_1 :: real
  4.1998 +#4 := uf_1
  4.1999 +#42 := (+ uf_1 #41)
  4.2000 +#79 := (>= #42 0::real)
  4.2001 +#80 := (not #79)
  4.2002 +#297 := (or #80 #243)
  4.2003 +#158 := (+ uf_1 #116)
  4.2004 +#159 := (<= #158 0::real)
  4.2005 +#22 := (<= uf_1 uf_4)
  4.2006 +#160 := (iff #22 #159)
  4.2007 +#161 := [rewrite]: #160
  4.2008 +#155 := [asserted]: #22
  4.2009 +#162 := [mp #155 #161]: #159
  4.2010 +#200 := (* 1/3::real uf_3)
  4.2011 +#198 := -4/3::real
  4.2012 +#199 := (* -4/3::real uf_2)
  4.2013 +#201 := (+ #199 #200)
  4.2014 +#202 := (+ uf_1 #201)
  4.2015 +#203 := (>= #202 0::real)
  4.2016 +#258 := (not #203)
  4.2017 +#292 := [hypothesis]: #79
  4.2018 +#293 := (or #80 #258)
  4.2019 +#69 := -1/3::real
  4.2020 +#70 := (* -1/3::real uf_3)
  4.2021 +#186 := -2/3::real
  4.2022 +#187 := (* -2/3::real uf_2)
  4.2023 +#188 := (+ #187 #70)
  4.2024 +#189 := (+ uf_1 #188)
  4.2025 +#204 := (<= #189 0::real)
  4.2026 +#205 := (ite #79 #203 #204)
  4.2027 +#210 := (not #205)
  4.2028 +#51 := (* -1::real uf_1)
  4.2029 +#52 := (+ #51 uf_2)
  4.2030 +#86 := (ite #79 #42 #52)
  4.2031 +#94 := (* -1::real #86)
  4.2032 +#95 := (+ #70 #94)
  4.2033 +#96 := (+ #68 #95)
  4.2034 +#97 := (<= #96 0::real)
  4.2035 +#98 := (not #97)
  4.2036 +#211 := (iff #98 #210)
  4.2037 +#208 := (iff #97 #205)
  4.2038 +#182 := 4/3::real
  4.2039 +#183 := (* 4/3::real uf_2)
  4.2040 +#184 := (+ #183 #70)
  4.2041 +#185 := (+ #51 #184)
  4.2042 +#190 := (ite #79 #185 #189)
  4.2043 +#195 := (<= #190 0::real)
  4.2044 +#206 := (iff #195 #205)
  4.2045 +#207 := [rewrite]: #206
  4.2046 +#196 := (iff #97 #195)
  4.2047 +#193 := (= #96 #190)
  4.2048 +#172 := (+ #41 #70)
  4.2049 +#173 := (+ uf_1 #172)
  4.2050 +#170 := (+ uf_2 #70)
  4.2051 +#171 := (+ #51 #170)
  4.2052 +#174 := (ite #79 #171 #173)
  4.2053 +#179 := (+ #68 #174)
  4.2054 +#191 := (= #179 #190)
  4.2055 +#192 := [rewrite]: #191
  4.2056 +#180 := (= #96 #179)
  4.2057 +#177 := (= #95 #174)
  4.2058 +#164 := (ite #79 #52 #42)
  4.2059 +#167 := (+ #70 #164)
  4.2060 +#175 := (= #167 #174)
  4.2061 +#176 := [rewrite]: #175
  4.2062 +#168 := (= #95 #167)
  4.2063 +#156 := (= #94 #164)
  4.2064 +#165 := [rewrite]: #156
  4.2065 +#169 := [monotonicity #165]: #168
  4.2066 +#178 := [trans #169 #176]: #177
  4.2067 +#181 := [monotonicity #178]: #180
  4.2068 +#194 := [trans #181 #192]: #193
  4.2069 +#197 := [monotonicity #194]: #196
  4.2070 +#209 := [trans #197 #207]: #208
  4.2071 +#212 := [monotonicity #209]: #211
  4.2072 +#13 := 3::real
  4.2073 +#12 := (- uf_2 uf_3)
  4.2074 +#14 := (/ #12 3::real)
  4.2075 +#6 := (- uf_1 uf_2)
  4.2076 +#9 := (- #6)
  4.2077 +#8 := (< #6 0::real)
  4.2078 +#10 := (ite #8 #9 #6)
  4.2079 +#15 := (< #10 #14)
  4.2080 +#103 := (iff #15 #98)
  4.2081 +#71 := (+ #68 #70)
  4.2082 +#45 := (< #42 0::real)
  4.2083 +#57 := (ite #45 #52 #42)
  4.2084 +#76 := (< #57 #71)
  4.2085 +#101 := (iff #76 #98)
  4.2086 +#91 := (< #86 #71)
  4.2087 +#99 := (iff #91 #98)
  4.2088 +#100 := [rewrite]: #99
  4.2089 +#92 := (iff #76 #91)
  4.2090 +#89 := (= #57 #86)
  4.2091 +#83 := (ite #80 #52 #42)
  4.2092 +#87 := (= #83 #86)
  4.2093 +#88 := [rewrite]: #87
  4.2094 +#84 := (= #57 #83)
  4.2095 +#81 := (iff #45 #80)
  4.2096 +#82 := [rewrite]: #81
  4.2097 +#85 := [monotonicity #82]: #84
  4.2098 +#90 := [trans #85 #88]: #89
  4.2099 +#93 := [monotonicity #90]: #92
  4.2100 +#102 := [trans #93 #100]: #101
  4.2101 +#77 := (iff #15 #76)
  4.2102 +#74 := (= #14 #71)
  4.2103 +#60 := (* -1::real uf_3)
  4.2104 +#61 := (+ uf_2 #60)
  4.2105 +#64 := (/ #61 3::real)
  4.2106 +#72 := (= #64 #71)
  4.2107 +#73 := [rewrite]: #72
  4.2108 +#65 := (= #14 #64)
  4.2109 +#62 := (= #12 #61)
  4.2110 +#63 := [rewrite]: #62
  4.2111 +#66 := [monotonicity #63]: #65
  4.2112 +#75 := [trans #66 #73]: #74
  4.2113 +#58 := (= #10 #57)
  4.2114 +#43 := (= #6 #42)
  4.2115 +#44 := [rewrite]: #43
  4.2116 +#55 := (= #9 #52)
  4.2117 +#48 := (- #42)
  4.2118 +#53 := (= #48 #52)
  4.2119 +#54 := [rewrite]: #53
  4.2120 +#49 := (= #9 #48)
  4.2121 +#50 := [monotonicity #44]: #49
  4.2122 +#56 := [trans #50 #54]: #55
  4.2123 +#46 := (iff #8 #45)
  4.2124 +#47 := [monotonicity #44]: #46
  4.2125 +#59 := [monotonicity #47 #56 #44]: #58
  4.2126 +#78 := [monotonicity #59 #75]: #77
  4.2127 +#104 := [trans #78 #102]: #103
  4.2128 +#39 := [asserted]: #15
  4.2129 +#105 := [mp #39 #104]: #98
  4.2130 +#213 := [mp #105 #212]: #210
  4.2131 +#259 := (or #205 #80 #258)
  4.2132 +#260 := [def-axiom]: #259
  4.2133 +#294 := [unit-resolution #260 #213]: #293
  4.2134 +#295 := [unit-resolution #294 #292]: #258
  4.2135 +#296 := [th-lemma #287 #292 #295 #162]: false
  4.2136 +#298 := [lemma #296]: #297
  4.2137 +#299 := [unit-resolution #298 #287]: #80
  4.2138 +#261 := (not #204)
  4.2139 +#281 := (or #79 #261)
  4.2140 +#262 := (or #205 #79 #261)
  4.2141 +#263 := [def-axiom]: #262
  4.2142 +#282 := [unit-resolution #263 #213]: #281
  4.2143 +#300 := [unit-resolution #282 #299]: #261
  4.2144 +#290 := (or #79 #204 #243)
  4.2145 +#276 := [hypothesis]: #261
  4.2146 +#288 := [hypothesis]: #80
  4.2147 +#289 := [th-lemma #288 #276 #162 #287]: false
  4.2148 +#291 := [lemma #289]: #290
  4.2149 +#301 := [unit-resolution #291 #300 #299 #287]: false
  4.2150 +#302 := [lemma #301]: #243
  4.2151 +#303 := (or #129 #268)
  4.2152 +#223 := (* -4/3::real uf_3)
  4.2153 +#224 := (+ #223 uf_4)
  4.2154 +#234 := (+ #68 #224)
  4.2155 +#244 := (<= #234 0::real)
  4.2156 +#245 := (ite #128 #243 #244)
  4.2157 +#250 := (not #245)
  4.2158 +#107 := (+ #60 uf_4)
  4.2159 +#135 := (ite #128 #107 #117)
  4.2160 +#143 := (* -1::real #135)
  4.2161 +#144 := (+ #70 #143)
  4.2162 +#145 := (+ #68 #144)
  4.2163 +#146 := (<= #145 0::real)
  4.2164 +#147 := (not #146)
  4.2165 +#251 := (iff #147 #250)
  4.2166 +#248 := (iff #146 #245)
  4.2167 +#235 := (ite #128 #233 #234)
  4.2168 +#240 := (<= #235 0::real)
  4.2169 +#246 := (iff #240 #245)
  4.2170 +#247 := [rewrite]: #246
  4.2171 +#241 := (iff #146 #240)
  4.2172 +#238 := (= #145 #235)
  4.2173 +#225 := (ite #128 #222 #224)
  4.2174 +#230 := (+ #68 #225)
  4.2175 +#236 := (= #230 #235)
  4.2176 +#237 := [rewrite]: #236
  4.2177 +#231 := (= #145 #230)
  4.2178 +#228 := (= #144 #225)
  4.2179 +#214 := (ite #128 #117 #107)
  4.2180 +#217 := (+ #70 #214)
  4.2181 +#226 := (= #217 #225)
  4.2182 +#227 := [rewrite]: #226
  4.2183 +#218 := (= #144 #217)
  4.2184 +#215 := (= #143 #214)
  4.2185 +#216 := [rewrite]: #215
  4.2186 +#219 := [monotonicity #216]: #218
  4.2187 +#229 := [trans #219 #227]: #228
  4.2188 +#232 := [monotonicity #229]: #231
  4.2189 +#239 := [trans #232 #237]: #238
  4.2190 +#242 := [monotonicity #239]: #241
  4.2191 +#249 := [trans #242 #247]: #248
  4.2192 +#252 := [monotonicity #249]: #251
  4.2193 +#17 := (- uf_4 uf_3)
  4.2194 +#19 := (- #17)
  4.2195 +#18 := (< #17 0::real)
  4.2196 +#20 := (ite #18 #19 #17)
  4.2197 +#21 := (< #20 #14)
  4.2198 +#152 := (iff #21 #147)
  4.2199 +#110 := (< #107 0::real)
  4.2200 +#122 := (ite #110 #117 #107)
  4.2201 +#125 := (< #122 #71)
  4.2202 +#150 := (iff #125 #147)
  4.2203 +#140 := (< #135 #71)
  4.2204 +#148 := (iff #140 #147)
  4.2205 +#149 := [rewrite]: #148
  4.2206 +#141 := (iff #125 #140)
  4.2207 +#138 := (= #122 #135)
  4.2208 +#132 := (ite #129 #117 #107)
  4.2209 +#136 := (= #132 #135)
  4.2210 +#137 := [rewrite]: #136
  4.2211 +#133 := (= #122 #132)
  4.2212 +#130 := (iff #110 #129)
  4.2213 +#131 := [rewrite]: #130
  4.2214 +#134 := [monotonicity #131]: #133
  4.2215 +#139 := [trans #134 #137]: #138
  4.2216 +#142 := [monotonicity #139]: #141
  4.2217 +#151 := [trans #142 #149]: #150
  4.2218 +#126 := (iff #21 #125)
  4.2219 +#123 := (= #20 #122)
  4.2220 +#108 := (= #17 #107)
  4.2221 +#109 := [rewrite]: #108
  4.2222 +#120 := (= #19 #117)
  4.2223 +#113 := (- #107)
  4.2224 +#118 := (= #113 #117)
  4.2225 +#119 := [rewrite]: #118
  4.2226 +#114 := (= #19 #113)
  4.2227 +#115 := [monotonicity #109]: #114
  4.2228 +#121 := [trans #115 #119]: #120
  4.2229 +#111 := (iff #18 #110)
  4.2230 +#112 := [monotonicity #109]: #111
  4.2231 +#124 := [monotonicity #112 #121 #109]: #123
  4.2232 +#127 := [monotonicity #124 #75]: #126
  4.2233 +#153 := [trans #127 #151]: #152
  4.2234 +#106 := [asserted]: #21
  4.2235 +#154 := [mp #106 #153]: #147
  4.2236 +#253 := [mp #154 #252]: #250
  4.2237 +#269 := (or #245 #129 #268)
  4.2238 +#270 := [def-axiom]: #269
  4.2239 +#304 := [unit-resolution #270 #253]: #303
  4.2240 +#305 := [unit-resolution #304 #302]: #129
  4.2241 +#271 := (not #244)
  4.2242 +#306 := (or #128 #271)
  4.2243 +#272 := (or #245 #128 #271)
  4.2244 +#273 := [def-axiom]: #272
  4.2245 +#307 := [unit-resolution #273 #253]: #306
  4.2246 +#308 := [unit-resolution #307 #305]: #271
  4.2247 +#285 := (or #128 #244)
  4.2248 +#274 := [hypothesis]: #271
  4.2249 +#275 := [hypothesis]: #129
  4.2250 +#278 := (or #204 #128 #244)
  4.2251 +#277 := [th-lemma #276 #275 #274 #162]: false
  4.2252 +#279 := [lemma #277]: #278
  4.2253 +#280 := [unit-resolution #279 #275 #274]: #204
  4.2254 +#283 := [unit-resolution #282 #280]: #79
  4.2255 +#284 := [th-lemma #275 #274 #283 #162]: false
  4.2256 +#286 := [lemma #284]: #285
  4.2257 +[unit-resolution #286 #308 #305]: false
  4.2258 +unsat
  4.2259 +cebG074uorSr8ODzgTmcKg 97 0
  4.2260 +#2 := false
  4.2261 +#18 := 0::real
  4.2262 +decl uf_1 :: (-> T2 T1 real)
  4.2263 +decl uf_5 :: T1
  4.2264 +#11 := uf_5
  4.2265 +decl uf_2 :: T2
  4.2266 +#4 := uf_2
  4.2267 +#20 := (uf_1 uf_2 uf_5)
  4.2268 +#42 := -1::real
  4.2269 +#53 := (* -1::real #20)
  4.2270 +decl uf_3 :: T2
  4.2271 +#7 := uf_3
  4.2272 +#19 := (uf_1 uf_3 uf_5)
  4.2273 +#54 := (+ #19 #53)
  4.2274 +#63 := (<= #54 0::real)
  4.2275 +#21 := (- #19 #20)
  4.2276 +#22 := (< 0::real #21)
  4.2277 +#23 := (not #22)
  4.2278 +#74 := (iff #23 #63)
  4.2279 +#57 := (< 0::real #54)
  4.2280 +#60 := (not #57)
  4.2281 +#72 := (iff #60 #63)
  4.2282 +#64 := (not #63)
  4.2283 +#67 := (not #64)
  4.2284 +#70 := (iff #67 #63)
  4.2285 +#71 := [rewrite]: #70
  4.2286 +#68 := (iff #60 #67)
  4.2287 +#65 := (iff #57 #64)
  4.2288 +#66 := [rewrite]: #65
  4.2289 +#69 := [monotonicity #66]: #68
  4.2290 +#73 := [trans #69 #71]: #72
  4.2291 +#61 := (iff #23 #60)
  4.2292 +#58 := (iff #22 #57)
  4.2293 +#55 := (= #21 #54)
  4.2294 +#56 := [rewrite]: #55
  4.2295 +#59 := [monotonicity #56]: #58
  4.2296 +#62 := [monotonicity #59]: #61
  4.2297 +#75 := [trans #62 #73]: #74
  4.2298 +#41 := [asserted]: #23
  4.2299 +#76 := [mp #41 #75]: #63
  4.2300 +#5 := (:var 0 T1)
  4.2301 +#8 := (uf_1 uf_3 #5)
  4.2302 +#141 := (pattern #8)
  4.2303 +#6 := (uf_1 uf_2 #5)
  4.2304 +#140 := (pattern #6)
  4.2305 +#45 := (* -1::real #8)
  4.2306 +#46 := (+ #6 #45)
  4.2307 +#44 := (>= #46 0::real)
  4.2308 +#43 := (not #44)
  4.2309 +#142 := (forall (vars (?x1 T1)) (:pat #140 #141) #43)
  4.2310 +#49 := (forall (vars (?x1 T1)) #43)
  4.2311 +#145 := (iff #49 #142)
  4.2312 +#143 := (iff #43 #43)
  4.2313 +#144 := [refl]: #143
  4.2314 +#146 := [quant-intro #144]: #145
  4.2315 +#80 := (~ #49 #49)
  4.2316 +#82 := (~ #43 #43)
  4.2317 +#83 := [refl]: #82
  4.2318 +#81 := [nnf-pos #83]: #80
  4.2319 +#9 := (< #6 #8)
  4.2320 +#10 := (forall (vars (?x1 T1)) #9)
  4.2321 +#50 := (iff #10 #49)
  4.2322 +#47 := (iff #9 #43)
  4.2323 +#48 := [rewrite]: #47
  4.2324 +#51 := [quant-intro #48]: #50
  4.2325 +#39 := [asserted]: #10
  4.2326 +#52 := [mp #39 #51]: #49
  4.2327 +#79 := [mp~ #52 #81]: #49
  4.2328 +#147 := [mp #79 #146]: #142
  4.2329 +#164 := (not #142)
  4.2330 +#165 := (or #164 #64)
  4.2331 +#148 := (* -1::real #19)
  4.2332 +#149 := (+ #20 #148)
  4.2333 +#150 := (>= #149 0::real)
  4.2334 +#151 := (not #150)
  4.2335 +#166 := (or #164 #151)
  4.2336 +#168 := (iff #166 #165)
  4.2337 +#170 := (iff #165 #165)
  4.2338 +#171 := [rewrite]: #170
  4.2339 +#162 := (iff #151 #64)
  4.2340 +#160 := (iff #150 #63)
  4.2341 +#152 := (+ #148 #20)
  4.2342 +#155 := (>= #152 0::real)
  4.2343 +#158 := (iff #155 #63)
  4.2344 +#159 := [rewrite]: #158
  4.2345 +#156 := (iff #150 #155)
  4.2346 +#153 := (= #149 #152)
  4.2347 +#154 := [rewrite]: #153
  4.2348 +#157 := [monotonicity #154]: #156
  4.2349 +#161 := [trans #157 #159]: #160
  4.2350 +#163 := [monotonicity #161]: #162
  4.2351 +#169 := [monotonicity #163]: #168
  4.2352 +#172 := [trans #169 #171]: #168
  4.2353 +#167 := [quant-inst]: #166
  4.2354 +#173 := [mp #167 #172]: #165
  4.2355 +[unit-resolution #173 #147 #76]: false
  4.2356 +unsat
  4.2357 +DKRtrJ2XceCkITuNwNViRw 57 0
  4.2358 +#2 := false
  4.2359 +#4 := 0::real
  4.2360 +decl uf_1 :: (-> T2 real)
  4.2361 +decl uf_2 :: (-> T1 T1 T2)
  4.2362 +decl uf_12 :: (-> T4 T1)
  4.2363 +decl uf_4 :: T4
  4.2364 +#11 := uf_4
  4.2365 +#39 := (uf_12 uf_4)
  4.2366 +decl uf_10 :: T4
  4.2367 +#27 := uf_10
  4.2368 +#38 := (uf_12 uf_10)
  4.2369 +#40 := (uf_2 #38 #39)
  4.2370 +#41 := (uf_1 #40)
  4.2371 +#264 := (>= #41 0::real)
  4.2372 +#266 := (not #264)
  4.2373 +#43 := (= #41 0::real)
  4.2374 +#44 := (not #43)
  4.2375 +#131 := [asserted]: #44
  4.2376 +#272 := (or #43 #266)
  4.2377 +#42 := (<= #41 0::real)
  4.2378 +#130 := [asserted]: #42
  4.2379 +#265 := (not #42)
  4.2380 +#270 := (or #43 #265 #266)
  4.2381 +#271 := [th-lemma]: #270
  4.2382 +#273 := [unit-resolution #271 #130]: #272
  4.2383 +#274 := [unit-resolution #273 #131]: #266
  4.2384 +#6 := (:var 0 T1)
  4.2385 +#5 := (:var 1 T1)
  4.2386 +#7 := (uf_2 #5 #6)
  4.2387 +#241 := (pattern #7)
  4.2388 +#8 := (uf_1 #7)
  4.2389 +#65 := (>= #8 0::real)
  4.2390 +#242 := (forall (vars (?x1 T1) (?x2 T1)) (:pat #241) #65)
  4.2391 +#66 := (forall (vars (?x1 T1) (?x2 T1)) #65)
  4.2392 +#245 := (iff #66 #242)
  4.2393 +#243 := (iff #65 #65)
  4.2394 +#244 := [refl]: #243
  4.2395 +#246 := [quant-intro #244]: #245
  4.2396 +#149 := (~ #66 #66)
  4.2397 +#151 := (~ #65 #65)
  4.2398 +#152 := [refl]: #151
  4.2399 +#150 := [nnf-pos #152]: #149
  4.2400 +#9 := (<= 0::real #8)
  4.2401 +#10 := (forall (vars (?x1 T1) (?x2 T1)) #9)
  4.2402 +#67 := (iff #10 #66)
  4.2403 +#63 := (iff #9 #65)
  4.2404 +#64 := [rewrite]: #63
  4.2405 +#68 := [quant-intro #64]: #67
  4.2406 +#60 := [asserted]: #10
  4.2407 +#69 := [mp #60 #68]: #66
  4.2408 +#147 := [mp~ #69 #150]: #66
  4.2409 +#247 := [mp #147 #246]: #242
  4.2410 +#267 := (not #242)
  4.2411 +#268 := (or #267 #264)
  4.2412 +#269 := [quant-inst]: #268
  4.2413 +[unit-resolution #269 #247 #274]: false
  4.2414 +unsat
  4.2415 +97KJAJfUio+nGchEHWvgAw 91 0
  4.2416 +#2 := false
  4.2417 +#38 := 0::real
  4.2418 +decl uf_1 :: (-> T1 T2 real)
  4.2419 +decl uf_3 :: T2
  4.2420 +#5 := uf_3
  4.2421 +decl uf_4 :: T1
  4.2422 +#7 := uf_4
  4.2423 +#8 := (uf_1 uf_4 uf_3)
  4.2424 +#35 := -1::real
  4.2425 +#36 := (* -1::real #8)
  4.2426 +decl uf_2 :: T1
  4.2427 +#4 := uf_2
  4.2428 +#6 := (uf_1 uf_2 uf_3)
  4.2429 +#37 := (+ #6 #36)
  4.2430 +#130 := (>= #37 0::real)
  4.2431 +#155 := (not #130)
  4.2432 +#43 := (= #6 #8)
  4.2433 +#55 := (not #43)
  4.2434 +#15 := (= #8 #6)
  4.2435 +#16 := (not #15)
  4.2436 +#56 := (iff #16 #55)
  4.2437 +#53 := (iff #15 #43)
  4.2438 +#54 := [rewrite]: #53
  4.2439 +#57 := [monotonicity #54]: #56
  4.2440 +#34 := [asserted]: #16
  4.2441 +#60 := [mp #34 #57]: #55
  4.2442 +#158 := (or #43 #155)
  4.2443 +#39 := (<= #37 0::real)
  4.2444 +#9 := (<= #6 #8)
  4.2445 +#40 := (iff #9 #39)
  4.2446 +#41 := [rewrite]: #40
  4.2447 +#32 := [asserted]: #9
  4.2448 +#42 := [mp #32 #41]: #39
  4.2449 +#154 := (not #39)
  4.2450 +#156 := (or #43 #154 #155)
  4.2451 +#157 := [th-lemma]: #156
  4.2452 +#159 := [unit-resolution #157 #42]: #158
  4.2453 +#160 := [unit-resolution #159 #60]: #155
  4.2454 +#10 := (:var 0 T2)
  4.2455 +#12 := (uf_1 uf_2 #10)
  4.2456 +#123 := (pattern #12)
  4.2457 +#11 := (uf_1 uf_4 #10)
  4.2458 +#122 := (pattern #11)
  4.2459 +#44 := (* -1::real #12)
  4.2460 +#45 := (+ #11 #44)
  4.2461 +#46 := (<= #45 0::real)
  4.2462 +#124 := (forall (vars (?x1 T2)) (:pat #122 #123) #46)
  4.2463 +#49 := (forall (vars (?x1 T2)) #46)
  4.2464 +#127 := (iff #49 #124)
  4.2465 +#125 := (iff #46 #46)
  4.2466 +#126 := [refl]: #125
  4.2467 +#128 := [quant-intro #126]: #127
  4.2468 +#62 := (~ #49 #49)
  4.2469 +#64 := (~ #46 #46)
  4.2470 +#65 := [refl]: #64
  4.2471 +#63 := [nnf-pos #65]: #62
  4.2472 +#13 := (<= #11 #12)
  4.2473 +#14 := (forall (vars (?x1 T2)) #13)
  4.2474 +#50 := (iff #14 #49)
  4.2475 +#47 := (iff #13 #46)
  4.2476 +#48 := [rewrite]: #47
  4.2477 +#51 := [quant-intro #48]: #50
  4.2478 +#33 := [asserted]: #14
  4.2479 +#52 := [mp #33 #51]: #49
  4.2480 +#61 := [mp~ #52 #63]: #49
  4.2481 +#129 := [mp #61 #128]: #124
  4.2482 +#144 := (not #124)
  4.2483 +#145 := (or #144 #130)
  4.2484 +#131 := (* -1::real #6)
  4.2485 +#132 := (+ #8 #131)
  4.2486 +#133 := (<= #132 0::real)
  4.2487 +#146 := (or #144 #133)
  4.2488 +#148 := (iff #146 #145)
  4.2489 +#150 := (iff #145 #145)
  4.2490 +#151 := [rewrite]: #150
  4.2491 +#142 := (iff #133 #130)
  4.2492 +#134 := (+ #131 #8)
  4.2493 +#137 := (<= #134 0::real)
  4.2494 +#140 := (iff #137 #130)
  4.2495 +#141 := [rewrite]: #140
  4.2496 +#138 := (iff #133 #137)
  4.2497 +#135 := (= #132 #134)
  4.2498 +#136 := [rewrite]: #135
  4.2499 +#139 := [monotonicity #136]: #138
  4.2500 +#143 := [trans #139 #141]: #142
  4.2501 +#149 := [monotonicity #143]: #148
  4.2502 +#152 := [trans #149 #151]: #148
  4.2503 +#147 := [quant-inst]: #146
  4.2504 +#153 := [mp #147 #152]: #145
  4.2505 +[unit-resolution #153 #129 #160]: false
  4.2506 +unsat
  4.2507 +flJYbeWfe+t2l/zsRqdujA 149 0
  4.2508 +#2 := false
  4.2509 +#19 := 0::real
  4.2510 +decl uf_1 :: (-> T1 T2 real)
  4.2511 +decl uf_3 :: T2
  4.2512 +#5 := uf_3
  4.2513 +decl uf_4 :: T1
  4.2514 +#7 := uf_4
  4.2515 +#8 := (uf_1 uf_4 uf_3)
  4.2516 +#44 := -1::real
  4.2517 +#156 := (* -1::real #8)
  4.2518 +decl uf_2 :: T1
  4.2519 +#4 := uf_2
  4.2520 +#6 := (uf_1 uf_2 uf_3)
  4.2521 +#203 := (+ #6 #156)
  4.2522 +#205 := (>= #203 0::real)
  4.2523 +#9 := (= #6 #8)
  4.2524 +#40 := [asserted]: #9
  4.2525 +#208 := (not #9)
  4.2526 +#209 := (or #208 #205)
  4.2527 +#210 := [th-lemma]: #209
  4.2528 +#211 := [unit-resolution #210 #40]: #205
  4.2529 +decl uf_5 :: T1
  4.2530 +#12 := uf_5
  4.2531 +#22 := (uf_1 uf_5 uf_3)
  4.2532 +#160 := (* -1::real #22)
  4.2533 +#161 := (+ #6 #160)
  4.2534 +#207 := (>= #161 0::real)
  4.2535 +#222 := (not #207)
  4.2536 +#206 := (= #6 #22)
  4.2537 +#216 := (not #206)
  4.2538 +#62 := (= #8 #22)
  4.2539 +#70 := (not #62)
  4.2540 +#217 := (iff #70 #216)
  4.2541 +#214 := (iff #62 #206)
  4.2542 +#212 := (iff #206 #62)
  4.2543 +#213 := [monotonicity #40]: #212
  4.2544 +#215 := [symm #213]: #214
  4.2545 +#218 := [monotonicity #215]: #217
  4.2546 +#23 := (= #22 #8)
  4.2547 +#24 := (not #23)
  4.2548 +#71 := (iff #24 #70)
  4.2549 +#68 := (iff #23 #62)
  4.2550 +#69 := [rewrite]: #68
  4.2551 +#72 := [monotonicity #69]: #71
  4.2552 +#43 := [asserted]: #24
  4.2553 +#75 := [mp #43 #72]: #70
  4.2554 +#219 := [mp #75 #218]: #216
  4.2555 +#225 := (or #206 #222)
  4.2556 +#162 := (<= #161 0::real)
  4.2557 +#172 := (+ #8 #160)
  4.2558 +#173 := (>= #172 0::real)
  4.2559 +#178 := (not #173)
  4.2560 +#163 := (not #162)
  4.2561 +#181 := (or #163 #178)
  4.2562 +#184 := (not #181)
  4.2563 +#10 := (:var 0 T2)
  4.2564 +#15 := (uf_1 uf_4 #10)
  4.2565 +#149 := (pattern #15)
  4.2566 +#13 := (uf_1 uf_5 #10)
  4.2567 +#148 := (pattern #13)
  4.2568 +#11 := (uf_1 uf_2 #10)
  4.2569 +#147 := (pattern #11)
  4.2570 +#50 := (* -1::real #15)
  4.2571 +#51 := (+ #13 #50)
  4.2572 +#52 := (<= #51 0::real)
  4.2573 +#76 := (not #52)
  4.2574 +#45 := (* -1::real #13)
  4.2575 +#46 := (+ #11 #45)
  4.2576 +#47 := (<= #46 0::real)
  4.2577 +#78 := (not #47)
  4.2578 +#73 := (or #78 #76)
  4.2579 +#83 := (not #73)
  4.2580 +#150 := (forall (vars (?x1 T2)) (:pat #147 #148 #149) #83)
  4.2581 +#86 := (forall (vars (?x1 T2)) #83)
  4.2582 +#153 := (iff #86 #150)
  4.2583 +#151 := (iff #83 #83)
  4.2584 +#152 := [refl]: #151
  4.2585 +#154 := [quant-intro #152]: #153
  4.2586 +#55 := (and #47 #52)
  4.2587 +#58 := (forall (vars (?x1 T2)) #55)
  4.2588 +#87 := (iff #58 #86)
  4.2589 +#84 := (iff #55 #83)
  4.2590 +#85 := [rewrite]: #84
  4.2591 +#88 := [quant-intro #85]: #87
  4.2592 +#79 := (~ #58 #58)
  4.2593 +#81 := (~ #55 #55)
  4.2594 +#82 := [refl]: #81
  4.2595 +#80 := [nnf-pos #82]: #79
  4.2596 +#16 := (<= #13 #15)
  4.2597 +#14 := (<= #11 #13)
  4.2598 +#17 := (and #14 #16)
  4.2599 +#18 := (forall (vars (?x1 T2)) #17)
  4.2600 +#59 := (iff #18 #58)
  4.2601 +#56 := (iff #17 #55)
  4.2602 +#53 := (iff #16 #52)
  4.2603 +#54 := [rewrite]: #53
  4.2604 +#48 := (iff #14 #47)
  4.2605 +#49 := [rewrite]: #48
  4.2606 +#57 := [monotonicity #49 #54]: #56
  4.2607 +#60 := [quant-intro #57]: #59
  4.2608 +#41 := [asserted]: #18
  4.2609 +#61 := [mp #41 #60]: #58
  4.2610 +#77 := [mp~ #61 #80]: #58
  4.2611 +#89 := [mp #77 #88]: #86
  4.2612 +#155 := [mp #89 #154]: #150
  4.2613 +#187 := (not #150)
  4.2614 +#188 := (or #187 #184)
  4.2615 +#157 := (+ #22 #156)
  4.2616 +#158 := (<= #157 0::real)
  4.2617 +#159 := (not #158)
  4.2618 +#164 := (or #163 #159)
  4.2619 +#165 := (not #164)
  4.2620 +#189 := (or #187 #165)
  4.2621 +#191 := (iff #189 #188)
  4.2622 +#193 := (iff #188 #188)
  4.2623 +#194 := [rewrite]: #193
  4.2624 +#185 := (iff #165 #184)
  4.2625 +#182 := (iff #164 #181)
  4.2626 +#179 := (iff #159 #178)
  4.2627 +#176 := (iff #158 #173)
  4.2628 +#166 := (+ #156 #22)
  4.2629 +#169 := (<= #166 0::real)
  4.2630 +#174 := (iff #169 #173)
  4.2631 +#175 := [rewrite]: #174
  4.2632 +#170 := (iff #158 #169)
  4.2633 +#167 := (= #157 #166)
  4.2634 +#168 := [rewrite]: #167
  4.2635 +#171 := [monotonicity #168]: #170
  4.2636 +#177 := [trans #171 #175]: #176
  4.2637 +#180 := [monotonicity #177]: #179
  4.2638 +#183 := [monotonicity #180]: #182
  4.2639 +#186 := [monotonicity #183]: #185
  4.2640 +#192 := [monotonicity #186]: #191
  4.2641 +#195 := [trans #192 #194]: #191
  4.2642 +#190 := [quant-inst]: #189
  4.2643 +#196 := [mp #190 #195]: #188
  4.2644 +#220 := [unit-resolution #196 #155]: #184
  4.2645 +#197 := (or #181 #162)
  4.2646 +#198 := [def-axiom]: #197
  4.2647 +#221 := [unit-resolution #198 #220]: #162
  4.2648 +#223 := (or #206 #163 #222)
  4.2649 +#224 := [th-lemma]: #223
  4.2650 +#226 := [unit-resolution #224 #221]: #225
  4.2651 +#227 := [unit-resolution #226 #219]: #222
  4.2652 +#199 := (or #181 #173)
  4.2653 +#200 := [def-axiom]: #199
  4.2654 +#228 := [unit-resolution #200 #220]: #173
  4.2655 +[th-lemma #228 #227 #211]: false
  4.2656 +unsat
  4.2657 +rbrrQuQfaijtLkQizgEXnQ 222 0
  4.2658 +#2 := false
  4.2659 +#4 := 0::real
  4.2660 +decl uf_2 :: (-> T2 T1 real)
  4.2661 +decl uf_5 :: T1
  4.2662 +#15 := uf_5
  4.2663 +decl uf_3 :: T2
  4.2664 +#7 := uf_3
  4.2665 +#20 := (uf_2 uf_3 uf_5)
  4.2666 +decl uf_6 :: T2
  4.2667 +#17 := uf_6
  4.2668 +#18 := (uf_2 uf_6 uf_5)
  4.2669 +#59 := -1::real
  4.2670 +#73 := (* -1::real #18)
  4.2671 +#106 := (+ #73 #20)
  4.2672 +decl uf_1 :: real
  4.2673 +#5 := uf_1
  4.2674 +#78 := (* -1::real #20)
  4.2675 +#79 := (+ #18 #78)
  4.2676 +#144 := (+ uf_1 #79)
  4.2677 +#145 := (<= #144 0::real)
  4.2678 +#148 := (ite #145 uf_1 #106)
  4.2679 +#279 := (* -1::real #148)
  4.2680 +#280 := (+ uf_1 #279)
  4.2681 +#281 := (<= #280 0::real)
  4.2682 +#289 := (not #281)
  4.2683 +#72 := 1/2::real
  4.2684 +#151 := (* 1/2::real #148)
  4.2685 +#248 := (<= #151 0::real)
  4.2686 +#162 := (= #151 0::real)
  4.2687 +#24 := 2::real
  4.2688 +#27 := (- #20 #18)
  4.2689 +#28 := (<= uf_1 #27)
  4.2690 +#29 := (ite #28 uf_1 #27)
  4.2691 +#30 := (/ #29 2::real)
  4.2692 +#31 := (+ #18 #30)
  4.2693 +#32 := (= #31 #18)
  4.2694 +#33 := (not #32)
  4.2695 +#34 := (not #33)
  4.2696 +#165 := (iff #34 #162)
  4.2697 +#109 := (<= uf_1 #106)
  4.2698 +#112 := (ite #109 uf_1 #106)
  4.2699 +#118 := (* 1/2::real #112)
  4.2700 +#123 := (+ #18 #118)
  4.2701 +#129 := (= #18 #123)
  4.2702 +#163 := (iff #129 #162)
  4.2703 +#154 := (+ #18 #151)
  4.2704 +#157 := (= #18 #154)
  4.2705 +#160 := (iff #157 #162)
  4.2706 +#161 := [rewrite]: #160
  4.2707 +#158 := (iff #129 #157)
  4.2708 +#155 := (= #123 #154)
  4.2709 +#152 := (= #118 #151)
  4.2710 +#149 := (= #112 #148)
  4.2711 +#146 := (iff #109 #145)
  4.2712 +#147 := [rewrite]: #146
  4.2713 +#150 := [monotonicity #147]: #149
  4.2714 +#153 := [monotonicity #150]: #152
  4.2715 +#156 := [monotonicity #153]: #155
  4.2716 +#159 := [monotonicity #156]: #158
  4.2717 +#164 := [trans #159 #161]: #163
  4.2718 +#142 := (iff #34 #129)
  4.2719 +#134 := (not #129)
  4.2720 +#137 := (not #134)
  4.2721 +#140 := (iff #137 #129)
  4.2722 +#141 := [rewrite]: #140
  4.2723 +#138 := (iff #34 #137)
  4.2724 +#135 := (iff #33 #134)
  4.2725 +#132 := (iff #32 #129)
  4.2726 +#126 := (= #123 #18)
  4.2727 +#130 := (iff #126 #129)
  4.2728 +#131 := [rewrite]: #130
  4.2729 +#127 := (iff #32 #126)
  4.2730 +#124 := (= #31 #123)
  4.2731 +#121 := (= #30 #118)
  4.2732 +#115 := (/ #112 2::real)
  4.2733 +#119 := (= #115 #118)
  4.2734 +#120 := [rewrite]: #119
  4.2735 +#116 := (= #30 #115)
  4.2736 +#113 := (= #29 #112)
  4.2737 +#107 := (= #27 #106)
  4.2738 +#108 := [rewrite]: #107
  4.2739 +#110 := (iff #28 #109)
  4.2740 +#111 := [monotonicity #108]: #110
  4.2741 +#114 := [monotonicity #111 #108]: #113
  4.2742 +#117 := [monotonicity #114]: #116
  4.2743 +#122 := [trans #117 #120]: #121
  4.2744 +#125 := [monotonicity #122]: #124
  4.2745 +#128 := [monotonicity #125]: #127
  4.2746 +#133 := [trans #128 #131]: #132
  4.2747 +#136 := [monotonicity #133]: #135
  4.2748 +#139 := [monotonicity #136]: #138
  4.2749 +#143 := [trans #139 #141]: #142
  4.2750 +#166 := [trans #143 #164]: #165
  4.2751 +#105 := [asserted]: #34
  4.2752 +#167 := [mp #105 #166]: #162
  4.2753 +#283 := (not #162)
  4.2754 +#284 := (or #283 #248)
  4.2755 +#285 := [th-lemma]: #284
  4.2756 +#286 := [unit-resolution #285 #167]: #248
  4.2757 +#287 := [hypothesis]: #281
  4.2758 +#53 := (<= uf_1 0::real)
  4.2759 +#54 := (not #53)
  4.2760 +#6 := (< 0::real uf_1)
  4.2761 +#55 := (iff #6 #54)
  4.2762 +#56 := [rewrite]: #55
  4.2763 +#50 := [asserted]: #6
  4.2764 +#57 := [mp #50 #56]: #54
  4.2765 +#288 := [th-lemma #57 #287 #286]: false
  4.2766 +#290 := [lemma #288]: #289
  4.2767 +#241 := (= uf_1 #148)
  4.2768 +#242 := (= #106 #148)
  4.2769 +#299 := (not #242)
  4.2770 +#282 := (+ #106 #279)
  4.2771 +#291 := (<= #282 0::real)
  4.2772 +#296 := (not #291)
  4.2773 +decl uf_4 :: T2
  4.2774 +#10 := uf_4
  4.2775 +#16 := (uf_2 uf_4 uf_5)
  4.2776 +#260 := (+ #16 #78)
  4.2777 +#261 := (>= #260 0::real)
  4.2778 +#266 := (not #261)
  4.2779 +#8 := (:var 0 T1)
  4.2780 +#11 := (uf_2 uf_4 #8)
  4.2781 +#234 := (pattern #11)
  4.2782 +#9 := (uf_2 uf_3 #8)
  4.2783 +#233 := (pattern #9)
  4.2784 +#60 := (* -1::real #11)
  4.2785 +#61 := (+ #9 #60)
  4.2786 +#62 := (<= #61 0::real)
  4.2787 +#179 := (not #62)
  4.2788 +#235 := (forall (vars (?x1 T1)) (:pat #233 #234) #179)
  4.2789 +#178 := (forall (vars (?x1 T1)) #179)
  4.2790 +#238 := (iff #178 #235)
  4.2791 +#236 := (iff #179 #179)
  4.2792 +#237 := [refl]: #236
  4.2793 +#239 := [quant-intro #237]: #238
  4.2794 +#65 := (exists (vars (?x1 T1)) #62)
  4.2795 +#68 := (not #65)
  4.2796 +#175 := (~ #68 #178)
  4.2797 +#180 := (~ #179 #179)
  4.2798 +#177 := [refl]: #180
  4.2799 +#176 := [nnf-neg #177]: #175
  4.2800 +#12 := (<= #9 #11)
  4.2801 +#13 := (exists (vars (?x1 T1)) #12)
  4.2802 +#14 := (not #13)
  4.2803 +#69 := (iff #14 #68)
  4.2804 +#66 := (iff #13 #65)
  4.2805 +#63 := (iff #12 #62)
  4.2806 +#64 := [rewrite]: #63
  4.2807 +#67 := [quant-intro #64]: #66
  4.2808 +#70 := [monotonicity #67]: #69
  4.2809 +#51 := [asserted]: #14
  4.2810 +#71 := [mp #51 #70]: #68
  4.2811 +#173 := [mp~ #71 #176]: #178
  4.2812 +#240 := [mp #173 #239]: #235
  4.2813 +#269 := (not #235)
  4.2814 +#270 := (or #269 #266)
  4.2815 +#250 := (* -1::real #16)
  4.2816 +#251 := (+ #20 #250)
  4.2817 +#252 := (<= #251 0::real)
  4.2818 +#253 := (not #252)
  4.2819 +#271 := (or #269 #253)
  4.2820 +#273 := (iff #271 #270)
  4.2821 +#275 := (iff #270 #270)
  4.2822 +#276 := [rewrite]: #275
  4.2823 +#267 := (iff #253 #266)
  4.2824 +#264 := (iff #252 #261)
  4.2825 +#254 := (+ #250 #20)
  4.2826 +#257 := (<= #254 0::real)
  4.2827 +#262 := (iff #257 #261)
  4.2828 +#263 := [rewrite]: #262
  4.2829 +#258 := (iff #252 #257)
  4.2830 +#255 := (= #251 #254)
  4.2831 +#256 := [rewrite]: #255
  4.2832 +#259 := [monotonicity #256]: #258
  4.2833 +#265 := [trans #259 #263]: #264
  4.2834 +#268 := [monotonicity #265]: #267
  4.2835 +#274 := [monotonicity #268]: #273
  4.2836 +#277 := [trans #274 #276]: #273
  4.2837 +#272 := [quant-inst]: #271
  4.2838 +#278 := [mp #272 #277]: #270
  4.2839 +#293 := [unit-resolution #278 #240]: #266
  4.2840 +#90 := (* 1/2::real #20)
  4.2841 +#102 := (+ #73 #90)
  4.2842 +#89 := (* 1/2::real #16)
  4.2843 +#103 := (+ #89 #102)
  4.2844 +#100 := (>= #103 0::real)
  4.2845 +#23 := (+ #16 #20)
  4.2846 +#25 := (/ #23 2::real)
  4.2847 +#26 := (<= #18 #25)
  4.2848 +#98 := (iff #26 #100)
  4.2849 +#91 := (+ #89 #90)
  4.2850 +#94 := (<= #18 #91)
  4.2851 +#97 := (iff #94 #100)
  4.2852 +#99 := [rewrite]: #97
  4.2853 +#95 := (iff #26 #94)
  4.2854 +#92 := (= #25 #91)
  4.2855 +#93 := [rewrite]: #92
  4.2856 +#96 := [monotonicity #93]: #95
  4.2857 +#101 := [trans #96 #99]: #98
  4.2858 +#58 := [asserted]: #26
  4.2859 +#104 := [mp #58 #101]: #100
  4.2860 +#294 := [hypothesis]: #291
  4.2861 +#295 := [th-lemma #294 #104 #293 #286]: false
  4.2862 +#297 := [lemma #295]: #296
  4.2863 +#298 := [hypothesis]: #242
  4.2864 +#300 := (or #299 #291)
  4.2865 +#301 := [th-lemma]: #300
  4.2866 +#302 := [unit-resolution #301 #298 #297]: false
  4.2867 +#303 := [lemma #302]: #299
  4.2868 +#246 := (or #145 #242)
  4.2869 +#247 := [def-axiom]: #246
  4.2870 +#304 := [unit-resolution #247 #303]: #145
  4.2871 +#243 := (not #145)
  4.2872 +#244 := (or #243 #241)
  4.2873 +#245 := [def-axiom]: #244
  4.2874 +#305 := [unit-resolution #245 #304]: #241
  4.2875 +#306 := (not #241)
  4.2876 +#307 := (or #306 #281)
  4.2877 +#308 := [th-lemma]: #307
  4.2878 +[unit-resolution #308 #305 #290]: false
  4.2879 +unsat
  4.2880 +hwh3oeLAWt56hnKIa8Wuow 248 0
  4.2881 +#2 := false
  4.2882 +#4 := 0::real
  4.2883 +decl uf_2 :: (-> T2 T1 real)
  4.2884 +decl uf_5 :: T1
  4.2885 +#15 := uf_5
  4.2886 +decl uf_6 :: T2
  4.2887 +#17 := uf_6
  4.2888 +#18 := (uf_2 uf_6 uf_5)
  4.2889 +decl uf_4 :: T2
  4.2890 +#10 := uf_4
  4.2891 +#16 := (uf_2 uf_4 uf_5)
  4.2892 +#66 := -1::real
  4.2893 +#137 := (* -1::real #16)
  4.2894 +#138 := (+ #137 #18)
  4.2895 +decl uf_1 :: real
  4.2896 +#5 := uf_1
  4.2897 +#80 := (* -1::real #18)
  4.2898 +#81 := (+ #16 #80)
  4.2899 +#201 := (+ uf_1 #81)
  4.2900 +#202 := (<= #201 0::real)
  4.2901 +#205 := (ite #202 uf_1 #138)
  4.2902 +#352 := (* -1::real #205)
  4.2903 +#353 := (+ uf_1 #352)
  4.2904 +#354 := (<= #353 0::real)
  4.2905 +#362 := (not #354)
  4.2906 +#79 := 1/2::real
  4.2907 +#244 := (* 1/2::real #205)
  4.2908 +#322 := (<= #244 0::real)
  4.2909 +#245 := (= #244 0::real)
  4.2910 +#158 := -1/2::real
  4.2911 +#208 := (* -1/2::real #205)
  4.2912 +#211 := (+ #18 #208)
  4.2913 +decl uf_3 :: T2
  4.2914 +#7 := uf_3
  4.2915 +#20 := (uf_2 uf_3 uf_5)
  4.2916 +#117 := (+ #80 #20)
  4.2917 +#85 := (* -1::real #20)
  4.2918 +#86 := (+ #18 #85)
  4.2919 +#188 := (+ uf_1 #86)
  4.2920 +#189 := (<= #188 0::real)
  4.2921 +#192 := (ite #189 uf_1 #117)
  4.2922 +#195 := (* 1/2::real #192)
  4.2923 +#198 := (+ #18 #195)
  4.2924 +#97 := (* 1/2::real #20)
  4.2925 +#109 := (+ #80 #97)
  4.2926 +#96 := (* 1/2::real #16)
  4.2927 +#110 := (+ #96 #109)
  4.2928 +#107 := (>= #110 0::real)
  4.2929 +#214 := (ite #107 #198 #211)
  4.2930 +#217 := (= #18 #214)
  4.2931 +#248 := (iff #217 #245)
  4.2932 +#241 := (= #18 #211)
  4.2933 +#246 := (iff #241 #245)
  4.2934 +#247 := [rewrite]: #246
  4.2935 +#242 := (iff #217 #241)
  4.2936 +#239 := (= #214 #211)
  4.2937 +#234 := (ite false #198 #211)
  4.2938 +#237 := (= #234 #211)
  4.2939 +#238 := [rewrite]: #237
  4.2940 +#235 := (= #214 #234)
  4.2941 +#232 := (iff #107 false)
  4.2942 +#104 := (not #107)
  4.2943 +#24 := 2::real
  4.2944 +#23 := (+ #16 #20)
  4.2945 +#25 := (/ #23 2::real)
  4.2946 +#26 := (< #25 #18)
  4.2947 +#108 := (iff #26 #104)
  4.2948 +#98 := (+ #96 #97)
  4.2949 +#101 := (< #98 #18)
  4.2950 +#106 := (iff #101 #104)
  4.2951 +#105 := [rewrite]: #106
  4.2952 +#102 := (iff #26 #101)
  4.2953 +#99 := (= #25 #98)
  4.2954 +#100 := [rewrite]: #99
  4.2955 +#103 := [monotonicity #100]: #102
  4.2956 +#111 := [trans #103 #105]: #108
  4.2957 +#65 := [asserted]: #26
  4.2958 +#112 := [mp #65 #111]: #104
  4.2959 +#233 := [iff-false #112]: #232
  4.2960 +#236 := [monotonicity #233]: #235
  4.2961 +#240 := [trans #236 #238]: #239
  4.2962 +#243 := [monotonicity #240]: #242
  4.2963 +#249 := [trans #243 #247]: #248
  4.2964 +#33 := (- #18 #16)
  4.2965 +#34 := (<= uf_1 #33)
  4.2966 +#35 := (ite #34 uf_1 #33)
  4.2967 +#36 := (/ #35 2::real)
  4.2968 +#37 := (- #18 #36)
  4.2969 +#28 := (- #20 #18)
  4.2970 +#29 := (<= uf_1 #28)
  4.2971 +#30 := (ite #29 uf_1 #28)
  4.2972 +#31 := (/ #30 2::real)
  4.2973 +#32 := (+ #18 #31)
  4.2974 +#27 := (<= #18 #25)
  4.2975 +#38 := (ite #27 #32 #37)
  4.2976 +#39 := (= #38 #18)
  4.2977 +#40 := (not #39)
  4.2978 +#41 := (not #40)
  4.2979 +#220 := (iff #41 #217)
  4.2980 +#141 := (<= uf_1 #138)
  4.2981 +#144 := (ite #141 uf_1 #138)
  4.2982 +#159 := (* -1/2::real #144)
  4.2983 +#160 := (+ #18 #159)
  4.2984 +#120 := (<= uf_1 #117)
  4.2985 +#123 := (ite #120 uf_1 #117)
  4.2986 +#129 := (* 1/2::real #123)
  4.2987 +#134 := (+ #18 #129)
  4.2988 +#114 := (<= #18 #98)
  4.2989 +#165 := (ite #114 #134 #160)
  4.2990 +#171 := (= #18 #165)
  4.2991 +#218 := (iff #171 #217)
  4.2992 +#215 := (= #165 #214)
  4.2993 +#212 := (= #160 #211)
  4.2994 +#209 := (= #159 #208)
  4.2995 +#206 := (= #144 #205)
  4.2996 +#203 := (iff #141 #202)
  4.2997 +#204 := [rewrite]: #203
  4.2998 +#207 := [monotonicity #204]: #206
  4.2999 +#210 := [monotonicity #207]: #209
  4.3000 +#213 := [monotonicity #210]: #212
  4.3001 +#199 := (= #134 #198)
  4.3002 +#196 := (= #129 #195)
  4.3003 +#193 := (= #123 #192)
  4.3004 +#190 := (iff #120 #189)
  4.3005 +#191 := [rewrite]: #190
  4.3006 +#194 := [monotonicity #191]: #193
  4.3007 +#197 := [monotonicity #194]: #196
  4.3008 +#200 := [monotonicity #197]: #199
  4.3009 +#187 := (iff #114 #107)
  4.3010 +#186 := [rewrite]: #187
  4.3011 +#216 := [monotonicity #186 #200 #213]: #215
  4.3012 +#219 := [monotonicity #216]: #218
  4.3013 +#184 := (iff #41 #171)
  4.3014 +#176 := (not #171)
  4.3015 +#179 := (not #176)
  4.3016 +#182 := (iff #179 #171)
  4.3017 +#183 := [rewrite]: #182
  4.3018 +#180 := (iff #41 #179)
  4.3019 +#177 := (iff #40 #176)
  4.3020 +#174 := (iff #39 #171)
  4.3021 +#168 := (= #165 #18)
  4.3022 +#172 := (iff #168 #171)
  4.3023 +#173 := [rewrite]: #172
  4.3024 +#169 := (iff #39 #168)
  4.3025 +#166 := (= #38 #165)
  4.3026 +#163 := (= #37 #160)
  4.3027 +#150 := (* 1/2::real #144)
  4.3028 +#155 := (- #18 #150)
  4.3029 +#161 := (= #155 #160)
  4.3030 +#162 := [rewrite]: #161
  4.3031 +#156 := (= #37 #155)
  4.3032 +#153 := (= #36 #150)
  4.3033 +#147 := (/ #144 2::real)
  4.3034 +#151 := (= #147 #150)
  4.3035 +#152 := [rewrite]: #151
  4.3036 +#148 := (= #36 #147)
  4.3037 +#145 := (= #35 #144)
  4.3038 +#139 := (= #33 #138)
  4.3039 +#140 := [rewrite]: #139
  4.3040 +#142 := (iff #34 #141)
  4.3041 +#143 := [monotonicity #140]: #142
  4.3042 +#146 := [monotonicity #143 #140]: #145
  4.3043 +#149 := [monotonicity #146]: #148
  4.3044 +#154 := [trans #149 #152]: #153
  4.3045 +#157 := [monotonicity #154]: #156
  4.3046 +#164 := [trans #157 #162]: #163
  4.3047 +#135 := (= #32 #134)
  4.3048 +#132 := (= #31 #129)
  4.3049 +#126 := (/ #123 2::real)
  4.3050 +#130 := (= #126 #129)
  4.3051 +#131 := [rewrite]: #130
  4.3052 +#127 := (= #31 #126)
  4.3053 +#124 := (= #30 #123)
  4.3054 +#118 := (= #28 #117)
  4.3055 +#119 := [rewrite]: #118
  4.3056 +#121 := (iff #29 #120)
  4.3057 +#122 := [monotonicity #119]: #121
  4.3058 +#125 := [monotonicity #122 #119]: #124
  4.3059 +#128 := [monotonicity #125]: #127
  4.3060 +#133 := [trans #128 #131]: #132
  4.3061 +#136 := [monotonicity #133]: #135
  4.3062 +#115 := (iff #27 #114)
  4.3063 +#116 := [monotonicity #100]: #115
  4.3064 +#167 := [monotonicity #116 #136 #164]: #166
  4.3065 +#170 := [monotonicity #167]: #169
  4.3066 +#175 := [trans #170 #173]: #174
  4.3067 +#178 := [monotonicity #175]: #177
  4.3068 +#181 := [monotonicity #178]: #180
  4.3069 +#185 := [trans #181 #183]: #184
  4.3070 +#221 := [trans #185 #219]: #220
  4.3071 +#113 := [asserted]: #41
  4.3072 +#222 := [mp #113 #221]: #217
  4.3073 +#250 := [mp #222 #249]: #245
  4.3074 +#356 := (not #245)
  4.3075 +#357 := (or #356 #322)
  4.3076 +#358 := [th-lemma]: #357
  4.3077 +#359 := [unit-resolution #358 #250]: #322
  4.3078 +#360 := [hypothesis]: #354
  4.3079 +#60 := (<= uf_1 0::real)
  4.3080 +#61 := (not #60)
  4.3081 +#6 := (< 0::real uf_1)
  4.3082 +#62 := (iff #6 #61)
  4.3083 +#63 := [rewrite]: #62
  4.3084 +#57 := [asserted]: #6
  4.3085 +#64 := [mp #57 #63]: #61
  4.3086 +#361 := [th-lemma #64 #360 #359]: false
  4.3087 +#363 := [lemma #361]: #362
  4.3088 +#315 := (= uf_1 #205)
  4.3089 +#316 := (= #138 #205)
  4.3090 +#371 := (not #316)
  4.3091 +#355 := (+ #138 #352)
  4.3092 +#364 := (<= #355 0::real)
  4.3093 +#368 := (not #364)
  4.3094 +#87 := (<= #86 0::real)
  4.3095 +#82 := (<= #81 0::real)
  4.3096 +#90 := (and #82 #87)
  4.3097 +#21 := (<= #18 #20)
  4.3098 +#19 := (<= #16 #18)
  4.3099 +#22 := (and #19 #21)
  4.3100 +#91 := (iff #22 #90)
  4.3101 +#88 := (iff #21 #87)
  4.3102 +#89 := [rewrite]: #88
  4.3103 +#83 := (iff #19 #82)
  4.3104 +#84 := [rewrite]: #83
  4.3105 +#92 := [monotonicity #84 #89]: #91
  4.3106 +#59 := [asserted]: #22
  4.3107 +#93 := [mp #59 #92]: #90
  4.3108 +#95 := [and-elim #93]: #87
  4.3109 +#366 := [hypothesis]: #364
  4.3110 +#367 := [th-lemma #366 #95 #112 #359]: false
  4.3111 +#369 := [lemma #367]: #368
  4.3112 +#370 := [hypothesis]: #316
  4.3113 +#372 := (or #371 #364)
  4.3114 +#373 := [th-lemma]: #372
  4.3115 +#374 := [unit-resolution #373 #370 #369]: false
  4.3116 +#375 := [lemma #374]: #371
  4.3117 +#320 := (or #202 #316)
  4.3118 +#321 := [def-axiom]: #320
  4.3119 +#376 := [unit-resolution #321 #375]: #202
  4.3120 +#317 := (not #202)
  4.3121 +#318 := (or #317 #315)
  4.3122 +#319 := [def-axiom]: #318
  4.3123 +#377 := [unit-resolution #319 #376]: #315
  4.3124 +#378 := (not #315)
  4.3125 +#379 := (or #378 #354)
  4.3126 +#380 := [th-lemma]: #379
  4.3127 +[unit-resolution #380 #377 #363]: false
  4.3128 +unsat
  4.3129 +WdMJH3tkMv/rps8y9Ukq5Q 86 0
  4.3130 +#2 := false
  4.3131 +#37 := 0::real
  4.3132 +decl uf_2 :: (-> T2 T1 real)
  4.3133 +decl uf_4 :: T1
  4.3134 +#12 := uf_4
  4.3135 +decl uf_3 :: T2
  4.3136 +#5 := uf_3
  4.3137 +#13 := (uf_2 uf_3 uf_4)
  4.3138 +#34 := -1::real
  4.3139 +#140 := (* -1::real #13)
  4.3140 +decl uf_1 :: real
  4.3141 +#4 := uf_1
  4.3142 +#141 := (+ uf_1 #140)
  4.3143 +#143 := (>= #141 0::real)
  4.3144 +#6 := (:var 0 T1)
  4.3145 +#7 := (uf_2 uf_3 #6)
  4.3146 +#127 := (pattern #7)
  4.3147 +#35 := (* -1::real #7)
  4.3148 +#36 := (+ uf_1 #35)
  4.3149 +#47 := (>= #36 0::real)
  4.3150 +#134 := (forall (vars (?x2 T1)) (:pat #127) #47)
  4.3151 +#49 := (forall (vars (?x2 T1)) #47)
  4.3152 +#137 := (iff #49 #134)
  4.3153 +#135 := (iff #47 #47)
  4.3154 +#136 := [refl]: #135
  4.3155 +#138 := [quant-intro #136]: #137
  4.3156 +#67 := (~ #49 #49)
  4.3157 +#58 := (~ #47 #47)
  4.3158 +#66 := [refl]: #58
  4.3159 +#68 := [nnf-pos #66]: #67
  4.3160 +#10 := (<= #7 uf_1)
  4.3161 +#11 := (forall (vars (?x2 T1)) #10)
  4.3162 +#50 := (iff #11 #49)
  4.3163 +#46 := (iff #10 #47)
  4.3164 +#48 := [rewrite]: #46
  4.3165 +#51 := [quant-intro #48]: #50
  4.3166 +#32 := [asserted]: #11
  4.3167 +#52 := [mp #32 #51]: #49
  4.3168 +#69 := [mp~ #52 #68]: #49
  4.3169 +#139 := [mp #69 #138]: #134
  4.3170 +#149 := (not #134)
  4.3171 +#150 := (or #149 #143)
  4.3172 +#151 := [quant-inst]: #150
  4.3173 +#144 := [unit-resolution #151 #139]: #143
  4.3174 +#142 := (<= #141 0::real)
  4.3175 +#38 := (<= #36 0::real)
  4.3176 +#128 := (forall (vars (?x1 T1)) (:pat #127) #38)
  4.3177 +#41 := (forall (vars (?x1 T1)) #38)
  4.3178 +#131 := (iff #41 #128)
  4.3179 +#129 := (iff #38 #38)
  4.3180 +#130 := [refl]: #129
  4.3181 +#132 := [quant-intro #130]: #131
  4.3182 +#62 := (~ #41 #41)
  4.3183 +#64 := (~ #38 #38)
  4.3184 +#65 := [refl]: #64
  4.3185 +#63 := [nnf-pos #65]: #62
  4.3186 +#8 := (<= uf_1 #7)
  4.3187 +#9 := (forall (vars (?x1 T1)) #8)
  4.3188 +#42 := (iff #9 #41)
  4.3189 +#39 := (iff #8 #38)
  4.3190 +#40 := [rewrite]: #39
  4.3191 +#43 := [quant-intro #40]: #42
  4.3192 +#31 := [asserted]: #9
  4.3193 +#44 := [mp #31 #43]: #41
  4.3194 +#61 := [mp~ #44 #63]: #41
  4.3195 +#133 := [mp #61 #132]: #128
  4.3196 +#145 := (not #128)
  4.3197 +#146 := (or #145 #142)
  4.3198 +#147 := [quant-inst]: #146
  4.3199 +#148 := [unit-resolution #147 #133]: #142
  4.3200 +#45 := (= uf_1 #13)
  4.3201 +#55 := (not #45)
  4.3202 +#14 := (= #13 uf_1)
  4.3203 +#15 := (not #14)
  4.3204 +#56 := (iff #15 #55)
  4.3205 +#53 := (iff #14 #45)
  4.3206 +#54 := [rewrite]: #53
  4.3207 +#57 := [monotonicity #54]: #56
  4.3208 +#33 := [asserted]: #15
  4.3209 +#60 := [mp #33 #57]: #55
  4.3210 +#153 := (not #143)
  4.3211 +#152 := (not #142)
  4.3212 +#154 := (or #45 #152 #153)
  4.3213 +#155 := [th-lemma]: #154
  4.3214 +[unit-resolution #155 #60 #148 #144]: false
  4.3215 +unsat
  4.3216 +V+IAyBZU/6QjYs6JkXx8LQ 57 0
  4.3217 +#2 := false
  4.3218 +#4 := 0::real
  4.3219 +decl uf_1 :: (-> T2 real)
  4.3220 +decl uf_2 :: (-> T1 T1 T2)
  4.3221 +decl uf_12 :: (-> T4 T1)
  4.3222 +decl uf_4 :: T4
  4.3223 +#11 := uf_4
  4.3224 +#39 := (uf_12 uf_4)
  4.3225 +decl uf_10 :: T4
  4.3226 +#27 := uf_10
  4.3227 +#38 := (uf_12 uf_10)
  4.3228 +#40 := (uf_2 #38 #39)
  4.3229 +#41 := (uf_1 #40)
  4.3230 +#264 := (>= #41 0::real)
  4.3231 +#266 := (not #264)
  4.3232 +#43 := (= #41 0::real)
  4.3233 +#44 := (not #43)
  4.3234 +#131 := [asserted]: #44
  4.3235 +#272 := (or #43 #266)
  4.3236 +#42 := (<= #41 0::real)
  4.3237 +#130 := [asserted]: #42
  4.3238 +#265 := (not #42)
  4.3239 +#270 := (or #43 #265 #266)
  4.3240 +#271 := [th-lemma]: #270
  4.3241 +#273 := [unit-resolution #271 #130]: #272
  4.3242 +#274 := [unit-resolution #273 #131]: #266
  4.3243 +#6 := (:var 0 T1)
  4.3244 +#5 := (:var 1 T1)
  4.3245 +#7 := (uf_2 #5 #6)
  4.3246 +#241 := (pattern #7)
  4.3247 +#8 := (uf_1 #7)
  4.3248 +#65 := (>= #8 0::real)
  4.3249 +#242 := (forall (vars (?x1 T1) (?x2 T1)) (:pat #241) #65)
  4.3250 +#66 := (forall (vars (?x1 T1) (?x2 T1)) #65)
  4.3251 +#245 := (iff #66 #242)
  4.3252 +#243 := (iff #65 #65)
  4.3253 +#244 := [refl]: #243
  4.3254 +#246 := [quant-intro #244]: #245
  4.3255 +#149 := (~ #66 #66)
  4.3256 +#151 := (~ #65 #65)
  4.3257 +#152 := [refl]: #151
  4.3258 +#150 := [nnf-pos #152]: #149
  4.3259 +#9 := (<= 0::real #8)
  4.3260 +#10 := (forall (vars (?x1 T1) (?x2 T1)) #9)
  4.3261 +#67 := (iff #10 #66)
  4.3262 +#63 := (iff #9 #65)
  4.3263 +#64 := [rewrite]: #63
  4.3264 +#68 := [quant-intro #64]: #67
  4.3265 +#60 := [asserted]: #10
  4.3266 +#69 := [mp #60 #68]: #66
  4.3267 +#147 := [mp~ #69 #150]: #66
  4.3268 +#247 := [mp #147 #246]: #242
  4.3269 +#267 := (not #242)
  4.3270 +#268 := (or #267 #264)
  4.3271 +#269 := [quant-inst]: #268
  4.3272 +[unit-resolution #269 #247 #274]: false
  4.3273 +unsat
  4.3274 +vqiyJ/qjGXZ3iOg6xftiug 15 0
  4.3275 +uf_1 -> val!0
  4.3276 +uf_2 -> val!1
  4.3277 +uf_3 -> val!2
  4.3278 +uf_5 -> val!15
  4.3279 +uf_6 -> val!26
  4.3280 +uf_4 -> {
  4.3281 +  val!0 -> val!12
  4.3282 +  val!1 -> val!13
  4.3283 +  else -> val!13
  4.3284 +}
  4.3285 +uf_7 -> {
  4.3286 +  val!6 -> val!31
  4.3287 +  else -> val!31
  4.3288 +}
  4.3289 +sat
  4.3290 +mrZPJZyTokErrN6SYupisw 9 0
  4.3291 +uf_4 -> val!1
  4.3292 +uf_2 -> val!3
  4.3293 +uf_3 -> val!4
  4.3294 +uf_1 -> {
  4.3295 +  val!5 -> val!6
  4.3296 +  val!4 -> val!7
  4.3297 +  else -> val!7
  4.3298 +}
  4.3299 +sat
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/HOL/Multivariate_Analysis/Integration.thy	Mon Feb 22 20:41:49 2010 +0100
     5.3 @@ -0,0 +1,3473 @@
     5.4 +
     5.5 +header {* Kurzweil-Henstock gauge integration in many dimensions. *}
     5.6 +(*  Author:                     John Harrison
     5.7 +    Translation from HOL light: Robert Himmelmann, TU Muenchen *)
     5.8 +
     5.9 +theory Integration
    5.10 +  imports Derivative SMT
    5.11 +begin
    5.12 +
    5.13 +declare [[smt_certificates="~~/src/HOL/Multivariate_Analysis/Integration.cert"]]
    5.14 +declare [[smt_record=true]]
    5.15 +declare [[z3_proofs=true]]
    5.16 +
    5.17 +lemma conjunctD2: assumes "a \<and> b" shows a b using assms by auto
    5.18 +lemma conjunctD3: assumes "a \<and> b \<and> c" shows a b c using assms by auto
    5.19 +lemma conjunctD4: assumes "a \<and> b \<and> c \<and> d" shows a b c d using assms by auto
    5.20 +lemma conjunctD5: assumes "a \<and> b \<and> c \<and> d \<and> e" shows a b c d e using assms by auto
    5.21 +
    5.22 +declare smult_conv_scaleR[simp]
    5.23 +
    5.24 +subsection {* Some useful lemmas about intervals. *}
    5.25 +
    5.26 +lemma empty_as_interval: "{} = {1..0::real^'n}"
    5.27 +  apply(rule set_ext,rule) defer unfolding vector_le_def mem_interval
    5.28 +  using UNIV_witness[where 'a='n] apply(erule_tac exE,rule_tac x=x in allE) by auto
    5.29 +
    5.30 +lemma interior_subset_union_intervals: 
    5.31 +  assumes "i = {a..b::real^'n}" "j = {c..d}" "interior j \<noteq> {}" "i \<subseteq> j \<union> s" "interior(i) \<inter> interior(j) = {}"
    5.32 +  shows "interior i \<subseteq> interior s" proof-
    5.33 +  have "{a<..<b} \<inter> {c..d} = {}" using inter_interval_mixed_eq_empty[of c d a b] and assms(3,5)
    5.34 +    unfolding assms(1,2) interior_closed_interval by auto
    5.35 +  moreover have "{a<..<b} \<subseteq> {c..d} \<union> s" apply(rule order_trans,rule interval_open_subset_closed)
    5.36 +    using assms(4) unfolding assms(1,2) by auto
    5.37 +  ultimately show ?thesis apply-apply(rule interior_maximal) defer apply(rule open_interior)
    5.38 +    unfolding assms(1,2) interior_closed_interval by auto qed
    5.39 +
    5.40 +lemma inter_interior_unions_intervals: fixes f::"(real^'n) set set"
    5.41 +  assumes "finite f" "open s" "\<forall>t\<in>f. \<exists>a b. t = {a..b}" "\<forall>t\<in>f. s \<inter> (interior t) = {}"
    5.42 +  shows "s \<inter> interior(\<Union>f) = {}" proof(rule ccontr,unfold ex_in_conv[THEN sym]) case goal1
    5.43 +  have lem1:"\<And>x e s U. ball x e \<subseteq> s \<inter> interior U \<longleftrightarrow> ball x e \<subseteq> s \<inter> U" apply rule  defer apply(rule_tac Int_greatest)
    5.44 +    unfolding open_subset_interior[OF open_ball]  using interior_subset by auto
    5.45 +  have lem2:"\<And>x s P. \<exists>x\<in>s. P x \<Longrightarrow> \<exists>x\<in>insert x s. P x" by auto
    5.46 +  have "\<And>f. finite f \<Longrightarrow> (\<forall>t\<in>f. \<exists>a b. t = {a..b}) \<Longrightarrow> (\<exists>x. x \<in> s \<inter> interior (\<Union>f)) \<Longrightarrow> (\<exists>t\<in>f. \<exists>x. \<exists>e>0. ball x e \<subseteq> s \<inter> t)" proof- case goal1
    5.47 +  thus ?case proof(induct rule:finite_induct) 
    5.48 +    case empty from this(2) guess x .. hence False unfolding Union_empty interior_empty by auto thus ?case by auto next
    5.49 +    case (insert i f) guess x using insert(5) .. note x = this
    5.50 +    then guess e unfolding open_contains_ball_eq[OF open_Int[OF assms(2) open_interior],rule_format] .. note e=this
    5.51 +    guess a using insert(4)[rule_format,OF insertI1] .. then guess b .. note ab = this
    5.52 +    show ?case proof(cases "x\<in>i") case False hence "x \<in> UNIV - {a..b}" unfolding ab by auto
    5.53 +      then guess d unfolding open_contains_ball_eq[OF open_Diff[OF open_UNIV closed_interval],rule_format] ..
    5.54 +      hence "0 < d" "ball x (min d e) \<subseteq> UNIV - i" using e unfolding ab by auto
    5.55 +      hence "ball x (min d e) \<subseteq> s \<inter> interior (\<Union>f)" using e unfolding lem1 by auto hence "x \<in> s \<inter> interior (\<Union>f)" using `d>0` e by auto
    5.56 +      hence "\<exists>t\<in>f. \<exists>x e. 0 < e \<and> ball x e \<subseteq> s \<inter> t" apply-apply(rule insert(3)) using insert(4) by auto thus ?thesis by auto next
    5.57 +    case True show ?thesis proof(cases "x\<in>{a<..<b}")
    5.58 +      case True then guess d unfolding open_contains_ball_eq[OF open_interval,rule_format] ..
    5.59 +      thus ?thesis apply(rule_tac x=i in bexI,rule_tac x=x in exI,rule_tac x="min d e" in exI)
    5.60 +	unfolding ab using interval_open_subset_closed[of a b] and e by fastsimp+ next
    5.61 +    case False then obtain k where "x$k \<le> a$k \<or> x$k \<ge> b$k" unfolding mem_interval by(auto simp add:not_less) 
    5.62 +    hence "x$k = a$k \<or> x$k = b$k" using True unfolding ab and mem_interval apply(erule_tac x=k in allE) by auto
    5.63 +    hence "\<exists>x. ball x (e/2) \<subseteq> s \<inter> (\<Union>f)" proof(erule_tac disjE)
    5.64 +      let ?z = "x - (e/2) *\<^sub>R basis k" assume as:"x$k = a$k" have "ball ?z (e / 2) \<inter> i = {}" apply(rule ccontr) unfolding ex_in_conv[THEN sym] proof(erule exE)
    5.65 +	fix y assume "y \<in> ball ?z (e / 2) \<inter> i" hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
    5.66 +	hence "\<bar>(?z - y) $ k\<bar> < e/2" using component_le_norm[of "?z - y" k] unfolding vector_dist_norm by auto
    5.67 +	hence "y$k < a$k" unfolding vector_component_simps vector_scaleR_component as using e[THEN conjunct1] by(auto simp add:field_simps)
    5.68 +	hence "y \<notin> i" unfolding ab mem_interval not_all by(rule_tac x=k in exI,auto) thus False using yi by auto qed
    5.69 +      moreover have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)" apply(rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]]) proof
    5.70 +	fix y assume as:"y\<in> ball ?z (e/2)" have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y - (e / 2) *\<^sub>R basis k)"
    5.71 +	   apply-apply(rule order_trans,rule norm_triangle_sub[of "x - y" "(e/2) *\<^sub>R basis k"])
    5.72 +	  unfolding norm_scaleR norm_basis by auto
    5.73 +	also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2" apply(rule add_strict_left_mono) using as unfolding mem_ball vector_dist_norm using e by(auto simp add:field_simps)
    5.74 +	finally show "y\<in>ball x e" unfolding mem_ball vector_dist_norm using e by(auto simp add:field_simps) qed
    5.75 +      ultimately show ?thesis apply(rule_tac x="?z" in exI) unfolding Union_insert by auto
    5.76 +    next let ?z = "x + (e/2) *\<^sub>R basis k" assume as:"x$k = b$k" have "ball ?z (e / 2) \<inter> i = {}" apply(rule ccontr) unfolding ex_in_conv[THEN sym] proof(erule exE)
    5.77 +	fix y assume "y \<in> ball ?z (e / 2) \<inter> i" hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
    5.78 +	hence "\<bar>(?z - y) $ k\<bar> < e/2" using component_le_norm[of "?z - y" k] unfolding vector_dist_norm by auto
    5.79 +	hence "y$k > b$k" unfolding vector_component_simps vector_scaleR_component as using e[THEN conjunct1] by(auto simp add:field_simps)
    5.80 +	hence "y \<notin> i" unfolding ab mem_interval not_all by(rule_tac x=k in exI,auto) thus False using yi by auto qed
    5.81 +      moreover have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)" apply(rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]]) proof
    5.82 +	fix y assume as:"y\<in> ball ?z (e/2)" have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y + (e / 2) *\<^sub>R basis k)"
    5.83 +	   apply-apply(rule order_trans,rule norm_triangle_sub[of "x - y" "- (e/2) *\<^sub>R basis k"])
    5.84 +	  unfolding norm_scaleR norm_basis by auto
    5.85 +	also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2" apply(rule add_strict_left_mono) using as unfolding mem_ball vector_dist_norm using e by(auto simp add:field_simps)
    5.86 +	finally show "y\<in>ball x e" unfolding mem_ball vector_dist_norm using e by(auto simp add:field_simps) qed
    5.87 +      ultimately show ?thesis apply(rule_tac x="?z" in exI) unfolding Union_insert by auto qed 
    5.88 +    then guess x .. hence "x \<in> s \<inter> interior (\<Union>f)" unfolding lem1[where U="\<Union>f",THEN sym] using centre_in_ball e[THEN conjunct1] by auto
    5.89 +    thus ?thesis apply-apply(rule lem2,rule insert(3)) using insert(4) by auto qed qed qed qed note * = this
    5.90 +  guess t using *[OF assms(1,3) goal1]  .. from this(2) guess x .. then guess e ..
    5.91 +  hence "x \<in> s" "x\<in>interior t" defer using open_subset_interior[OF open_ball, of x e t] by auto
    5.92 +  thus False using `t\<in>f` assms(4) by auto qed
    5.93 +subsection {* Bounds on intervals where they exist. *}
    5.94 +
    5.95 +definition "interval_upperbound (s::(real^'n) set) = (\<chi> i. Sup {a. \<exists>x\<in>s. x$i = a})"
    5.96 +
    5.97 +definition "interval_lowerbound (s::(real^'n) set) = (\<chi> i. Inf {a. \<exists>x\<in>s. x$i = a})"
    5.98 +
    5.99 +lemma interval_upperbound[simp]: assumes "\<forall>i. a$i \<le> b$i" shows "interval_upperbound {a..b} = b"
   5.100 +  using assms unfolding interval_upperbound_def Cart_eq Cart_lambda_beta apply-apply(rule,erule_tac x=i in allE)
   5.101 +  apply(rule Sup_unique) unfolding setle_def apply rule unfolding mem_Collect_eq apply(erule bexE) unfolding mem_interval defer
   5.102 +  apply(rule,rule) apply(rule_tac x="b$i" in bexI) defer unfolding mem_Collect_eq apply(rule_tac x=b in bexI)
   5.103 +  unfolding mem_interval using assms by auto
   5.104 +
   5.105 +lemma interval_lowerbound[simp]: assumes "\<forall>i. a$i \<le> b$i" shows "interval_lowerbound {a..b} = a"
   5.106 +  using assms unfolding interval_lowerbound_def Cart_eq Cart_lambda_beta apply-apply(rule,erule_tac x=i in allE)
   5.107 +  apply(rule Inf_unique) unfolding setge_def apply rule unfolding mem_Collect_eq apply(erule bexE) unfolding mem_interval defer
   5.108 +  apply(rule,rule) apply(rule_tac x="a$i" in bexI) defer unfolding mem_Collect_eq apply(rule_tac x=a in bexI)
   5.109 +  unfolding mem_interval using assms by auto
   5.110 +
   5.111 +lemmas interval_bounds = interval_upperbound interval_lowerbound
   5.112 +
   5.113 +lemma interval_bounds'[simp]: assumes "{a..b}\<noteq>{}" shows "interval_upperbound {a..b} = b" "interval_lowerbound {a..b} = a"
   5.114 +  using assms unfolding interval_ne_empty by auto
   5.115 +
   5.116 +lemma interval_upperbound_1[simp]: "dest_vec1 a \<le> dest_vec1 b \<Longrightarrow> interval_upperbound {a..b} = (b::real^1)"
   5.117 +  apply(rule interval_upperbound) by auto
   5.118 +
   5.119 +lemma interval_lowerbound_1[simp]: "dest_vec1 a \<le> dest_vec1 b \<Longrightarrow> interval_lowerbound {a..b} = (a::real^1)"
   5.120 +  apply(rule interval_lowerbound) by auto
   5.121 +
   5.122 +lemmas interval_bound_1 = interval_upperbound_1 interval_lowerbound_1
   5.123 +
   5.124 +subsection {* Content (length, area, volume...) of an interval. *}
   5.125 +
   5.126 +definition "content (s::(real^'n) set) =
   5.127 +       (if s = {} then 0 else (\<Prod>i\<in>UNIV. (interval_upperbound s)$i - (interval_lowerbound s)$i))"
   5.128 +
   5.129 +lemma interval_not_empty:"\<forall>i. a$i \<le> b$i \<Longrightarrow> {a..b::real^'n} \<noteq> {}"
   5.130 +  unfolding interval_eq_empty unfolding not_ex not_less by assumption
   5.131 +
   5.132 +lemma content_closed_interval: assumes "\<forall>i. a$i \<le> b$i"
   5.133 +  shows "content {a..b} = (\<Prod>i\<in>UNIV. b$i - a$i)"
   5.134 +  using interval_not_empty[OF assms] unfolding content_def interval_upperbound[OF assms] interval_lowerbound[OF assms] by auto
   5.135 +
   5.136 +lemma content_closed_interval': assumes "{a..b}\<noteq>{}" shows "content {a..b} = (\<Prod>i\<in>UNIV. b$i - a$i)"
   5.137 +  apply(rule content_closed_interval) using assms unfolding interval_ne_empty .
   5.138 +
   5.139 +lemma content_1:"dest_vec1 a \<le> dest_vec1 b \<Longrightarrow> content {a..b} = dest_vec1 b - dest_vec1 a"
   5.140 +  using content_closed_interval[of a b] by auto
   5.141 +
   5.142 +lemma content_1':"a \<le> b \<Longrightarrow> content {vec1 a..vec1 b} = b - a" using content_1[of "vec a" "vec b"] by auto
   5.143 +
   5.144 +lemma content_unit[intro]: "content{0..1::real^'n} = 1" proof-
   5.145 +  have *:"\<forall>i. 0$i \<le> (1::real^'n::finite)$i" by auto
   5.146 +  have "0 \<in> {0..1::real^'n::finite}" unfolding mem_interval by auto
   5.147 +  thus ?thesis unfolding content_def interval_bounds[OF *] using setprod_1 by auto qed
   5.148 +
   5.149 +lemma content_pos_le[intro]: "0 \<le> content {a..b}" proof(cases "{a..b}={}")
   5.150 +  case False hence *:"\<forall>i. a $ i \<le> b $ i" unfolding interval_ne_empty by assumption
   5.151 +  have "(\<Prod>i\<in>UNIV. interval_upperbound {a..b} $ i - interval_lowerbound {a..b} $ i) \<ge> 0"
   5.152 +    apply(rule setprod_nonneg) unfolding interval_bounds[OF *] using * apply(erule_tac x=x in allE) by auto
   5.153 +  thus ?thesis unfolding content_def by(auto simp del:interval_bounds') qed(unfold content_def, auto)
   5.154 +
   5.155 +lemma content_pos_lt: assumes "\<forall>i. a$i < b$i" shows "0 < content {a..b}"
   5.156 +proof- have help_lemma1: "\<forall>i. a$i < b$i \<Longrightarrow> \<forall>i. a$i \<le> ((b$i)::real)" apply(rule,erule_tac x=i in allE) by auto
   5.157 +  show ?thesis unfolding content_closed_interval[OF help_lemma1[OF assms]] apply(rule setprod_pos)
   5.158 +    using assms apply(erule_tac x=x in allE) by auto qed
   5.159 +
   5.160 +lemma content_pos_lt_1: "dest_vec1 a < dest_vec1 b \<Longrightarrow> 0 < content({a..b})"
   5.161 +  apply(rule content_pos_lt) by auto
   5.162 +
   5.163 +lemma content_eq_0: "content({a..b::real^'n}) = 0 \<longleftrightarrow> (\<exists>i. b$i \<le> a$i)" proof(cases "{a..b} = {}")
   5.164 +  case True thus ?thesis unfolding content_def if_P[OF True] unfolding interval_eq_empty apply-
   5.165 +    apply(rule,erule exE) apply(rule_tac x=i in exI) by auto next
   5.166 +  guess a using UNIV_witness[where 'a='n] .. case False note as=this[unfolded interval_eq_empty not_ex not_less]
   5.167 +  show ?thesis unfolding content_def if_not_P[OF False] setprod_zero_iff[OF finite_UNIV]
   5.168 +    apply(rule) apply(erule_tac[!] exE bexE) unfolding interval_bounds[OF as] apply(rule_tac x=x in exI) defer
   5.169 +    apply(rule_tac x=i in bexI) using as apply(erule_tac x=i in allE) by auto qed
   5.170 +
   5.171 +lemma cond_cases:"(P \<Longrightarrow> Q x) \<Longrightarrow> (\<not> P \<Longrightarrow> Q y) \<Longrightarrow> Q (if P then x else y)" by auto
   5.172 +
   5.173 +lemma content_closed_interval_cases:
   5.174 +  "content {a..b} = (if \<forall>i. a$i \<le> b$i then setprod (\<lambda>i. b$i - a$i) UNIV else 0)" apply(rule cond_cases) 
   5.175 +  apply(rule content_closed_interval) unfolding content_eq_0 not_all not_le defer apply(erule exE,rule_tac x=x in exI) by auto
   5.176 +
   5.177 +lemma content_eq_0_interior: "content {a..b} = 0 \<longleftrightarrow> interior({a..b}) = {}"
   5.178 +  unfolding content_eq_0 interior_closed_interval interval_eq_empty by auto
   5.179 +
   5.180 +lemma content_eq_0_1: "content {a..b::real^1} = 0 \<longleftrightarrow> dest_vec1 b \<le> dest_vec1 a"
   5.181 +  unfolding content_eq_0 by auto
   5.182 +
   5.183 +lemma content_pos_lt_eq: "0 < content {a..b} \<longleftrightarrow> (\<forall>i. a$i < b$i)"
   5.184 +  apply(rule) defer apply(rule content_pos_lt,assumption) proof- assume "0 < content {a..b}"
   5.185 +  hence "content {a..b} \<noteq> 0" by auto thus "\<forall>i. a$i < b$i" unfolding content_eq_0 not_ex not_le by auto qed
   5.186 +
   5.187 +lemma content_empty[simp]: "content {} = 0" unfolding content_def by auto
   5.188 +
   5.189 +lemma content_subset: assumes "{a..b} \<subseteq> {c..d}" shows "content {a..b::real^'n} \<le> content {c..d}" proof(cases "{a..b}={}")
   5.190 +  case True thus ?thesis using content_pos_le[of c d] by auto next
   5.191 +  case False hence ab_ne:"\<forall>i. a $ i \<le> b $ i" unfolding interval_ne_empty by auto
   5.192 +  hence ab_ab:"a\<in>{a..b}" "b\<in>{a..b}" unfolding mem_interval by auto
   5.193 +  have "{c..d} \<noteq> {}" using assms False by auto
   5.194 +  hence cd_ne:"\<forall>i. c $ i \<le> d $ i" using assms unfolding interval_ne_empty by auto
   5.195 +  show ?thesis unfolding content_def unfolding interval_bounds[OF ab_ne] interval_bounds[OF cd_ne]
   5.196 +    unfolding if_not_P[OF False] if_not_P[OF `{c..d} \<noteq> {}`] apply(rule setprod_mono,rule) proof fix i::'n
   5.197 +    show "0 \<le> b $ i - a $ i" using ab_ne[THEN spec[where x=i]] by auto
   5.198 +    show "b $ i - a $ i \<le> d $ i - c $ i"
   5.199 +      using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(2),of i]
   5.200 +      using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(1),of i] by auto qed qed
   5.201 +
   5.202 +lemma content_lt_nz: "0 < content {a..b} \<longleftrightarrow> content {a..b} \<noteq> 0"
   5.203 +  unfolding content_pos_lt_eq content_eq_0 unfolding not_ex not_le by auto
   5.204 +
   5.205 +subsection {* The notion of a gauge --- simply an open set containing the point. *}
   5.206 +
   5.207 +definition gauge where "gauge d \<longleftrightarrow> (\<forall>x. x\<in>(d x) \<and> open(d x))"
   5.208 +
   5.209 +lemma gaugeI:assumes "\<And>x. x\<in>g x" "\<And>x. open (g x)" shows "gauge g"
   5.210 +  using assms unfolding gauge_def by auto
   5.211 +
   5.212 +lemma gaugeD[dest]: assumes "gauge d" shows "x\<in>d x" "open (d x)" using assms unfolding gauge_def by auto
   5.213 +
   5.214 +lemma gauge_ball_dependent: "\<forall>x. 0 < e x \<Longrightarrow> gauge (\<lambda>x. ball x (e x))"
   5.215 +  unfolding gauge_def by auto 
   5.216 +
   5.217 +lemma gauge_ball[intro?]: "0 < e \<Longrightarrow> gauge (\<lambda>x. ball x e)" unfolding gauge_def by auto 
   5.218 +
   5.219 +lemma gauge_trivial[intro]: "gauge (\<lambda>x. ball x 1)" apply(rule gauge_ball) by auto
   5.220 +
   5.221 +lemma gauge_inter: "gauge d1 \<Longrightarrow> gauge d2 \<Longrightarrow> gauge (\<lambda>x. (d1 x) \<inter> (d2 x))"
   5.222 +  unfolding gauge_def by auto 
   5.223 +
   5.224 +lemma gauge_inters: assumes "finite s" "\<forall>d\<in>s. gauge (f d)" shows "gauge(\<lambda>x. \<Inter> {f d x | d. d \<in> s})" proof-
   5.225 +  have *:"\<And>x. {f d x |d. d \<in> s} = (\<lambda>d. f d x) ` s" by auto show ?thesis
   5.226 +  unfolding gauge_def unfolding * 
   5.227 +  using assms unfolding Ball_def Inter_iff mem_Collect_eq gauge_def by auto qed
   5.228 +
   5.229 +lemma gauge_existence_lemma: "(\<forall>x. \<exists>d::real. p x \<longrightarrow> 0 < d \<and> q d x) \<longleftrightarrow> (\<forall>x. \<exists>d>0. p x \<longrightarrow> q d x)" by(meson zero_less_one)
   5.230 +
   5.231 +subsection {* Divisions. *}
   5.232 +
   5.233 +definition division_of (infixl "division'_of" 40) where
   5.234 +  "s division_of i \<equiv>
   5.235 +        finite s \<and>
   5.236 +        (\<forall>k\<in>s. k \<subseteq> i \<and> k \<noteq> {} \<and> (\<exists>a b. k = {a..b})) \<and>
   5.237 +        (\<forall>k1\<in>s. \<forall>k2\<in>s. k1 \<noteq> k2 \<longrightarrow> interior(k1) \<inter> interior(k2) = {}) \<and>
   5.238 +        (\<Union>s = i)"
   5.239 +
   5.240 +lemma division_ofD[dest]: assumes  "s division_of i"
   5.241 +  shows"finite s" "\<And>k. k\<in>s \<Longrightarrow> k \<subseteq> i" "\<And>k. k\<in>s \<Longrightarrow>  k \<noteq> {}" "\<And>k. k\<in>s \<Longrightarrow> (\<exists>a b. k = {a..b})"
   5.242 +  "\<And>k1 k2. \<lbrakk>k1\<in>s; k2\<in>s; k1 \<noteq> k2\<rbrakk> \<Longrightarrow> interior(k1) \<inter> interior(k2) = {}" "\<Union>s = i" using assms unfolding division_of_def by auto
   5.243 +
   5.244 +lemma division_ofI:
   5.245 +  assumes "finite s" "\<And>k. k\<in>s \<Longrightarrow> k \<subseteq> i" "\<And>k. k\<in>s \<Longrightarrow>  k \<noteq> {}" "\<And>k. k\<in>s \<Longrightarrow> (\<exists>a b. k = {a..b})"
   5.246 +  "\<And>k1 k2. \<lbrakk>k1\<in>s; k2\<in>s; k1 \<noteq> k2\<rbrakk> \<Longrightarrow> interior(k1) \<inter> interior(k2) = {}" "\<Union>s = i"
   5.247 +  shows "s division_of i" using assms unfolding division_of_def by auto
   5.248 +
   5.249 +lemma division_of_finite: "s division_of i \<Longrightarrow> finite s"
   5.250 +  unfolding division_of_def by auto
   5.251 +
   5.252 +lemma division_of_self[intro]: "{a..b} \<noteq> {} \<Longrightarrow> {{a..b}} division_of {a..b}"
   5.253 +  unfolding division_of_def by auto
   5.254 +
   5.255 +lemma division_of_trivial[simp]: "s division_of {} \<longleftrightarrow> s = {}" unfolding division_of_def by auto 
   5.256 +
   5.257 +lemma division_of_sing[simp]: "s division_of {a..a::real^'n} \<longleftrightarrow> s = {{a..a}}" (is "?l = ?r") proof
   5.258 +  assume ?r moreover { assume "s = {{a}}" moreover fix k assume "k\<in>s" 
   5.259 +    ultimately have"\<exists>x y. k = {x..y}" apply(rule_tac x=a in exI)+ unfolding interval_sing[THEN conjunct1] by auto }
   5.260 +  ultimately show ?l unfolding division_of_def interval_sing[THEN conjunct1] by auto next
   5.261 +  assume ?l note as=conjunctD4[OF this[unfolded division_of_def interval_sing[THEN conjunct1]]]
   5.262 +  { fix x assume x:"x\<in>s" have "x={a}" using as(2)[rule_format,OF x] by auto }
   5.263 +  moreover have "s \<noteq> {}" using as(4) by auto ultimately show ?r unfolding interval_sing[THEN conjunct1] by auto qed
   5.264 +
   5.265 +lemma elementary_empty: obtains p where "p division_of {}"
   5.266 +  unfolding division_of_trivial by auto
   5.267 +
   5.268 +lemma elementary_interval: obtains p where  "p division_of {a..b}"
   5.269 +  by(metis division_of_trivial division_of_self)
   5.270 +
   5.271 +lemma division_contains: "s division_of i \<Longrightarrow> \<forall>x\<in>i. \<exists>k\<in>s. x \<in> k"
   5.272 +  unfolding division_of_def by auto
   5.273 +
   5.274 +lemma forall_in_division:
   5.275 + "d division_of i \<Longrightarrow> ((\<forall>x\<in>d. P x) \<longleftrightarrow> (\<forall>a b. {a..b} \<in> d \<longrightarrow> P {a..b}))"
   5.276 +  unfolding division_of_def by fastsimp
   5.277 +
   5.278 +lemma division_of_subset: assumes "p division_of (\<Union>p)" "q \<subseteq> p" shows "q division_of (\<Union>q)"
   5.279 +  apply(rule division_ofI) proof- note as=division_ofD[OF assms(1)]
   5.280 +  show "finite q" apply(rule finite_subset) using as(1) assms(2) by auto
   5.281 +  { fix k assume "k \<in> q" hence kp:"k\<in>p" using assms(2) by auto show "k\<subseteq>\<Union>q" using `k \<in> q` by auto
   5.282 +  show "\<exists>a b. k = {a..b}" using as(4)[OF kp] by auto show "k \<noteq> {}" using as(3)[OF kp] by auto }
   5.283 +  fix k1 k2 assume "k1 \<in> q" "k2 \<in> q" "k1 \<noteq> k2" hence *:"k1\<in>p" "k2\<in>p" "k1\<noteq>k2" using assms(2) by auto
   5.284 +  show "interior k1 \<inter> interior k2 = {}" using as(5)[OF *] by auto qed auto
   5.285 +
   5.286 +lemma division_of_union_self[intro]: "p division_of s \<Longrightarrow> p division_of (\<Union>p)" unfolding division_of_def by auto
   5.287 +
   5.288 +lemma division_of_content_0: assumes "content {a..b} = 0" "d division_of {a..b}" shows "\<forall>k\<in>d. content k = 0"
   5.289 +  unfolding forall_in_division[OF assms(2)] apply(rule,rule,rule) apply(drule division_ofD(2)[OF assms(2)])
   5.290 +  apply(drule content_subset) unfolding assms(1) proof- case goal1 thus ?case using content_pos_le[of a b] by auto qed
   5.291 +
   5.292 +lemma division_inter: assumes "p1 division_of s1" "p2 division_of (s2::(real^'a) set)"
   5.293 +  shows "{k1 \<inter> k2 | k1 k2 .k1 \<in> p1 \<and> k2 \<in> p2 \<and> k1 \<inter> k2 \<noteq> {}} division_of (s1 \<inter> s2)" (is "?A' division_of _") proof-
   5.294 +let ?A = "{s. s \<in>  (\<lambda>(k1,k2). k1 \<inter> k2) ` (p1 \<times> p2) \<and> s \<noteq> {}}" have *:"?A' = ?A" by auto
   5.295 +show ?thesis unfolding * proof(rule division_ofI) have "?A \<subseteq> (\<lambda>(x, y). x \<inter> y) ` (p1 \<times> p2)" by auto
   5.296 +  moreover have "finite (p1 \<times> p2)" using assms unfolding division_of_def by auto ultimately show "finite ?A" by auto
   5.297 +  have *:"\<And>s. \<Union>{x\<in>s. x \<noteq> {}} = \<Union>s" by auto show "\<Union>?A = s1 \<inter> s2" apply(rule set_ext) unfolding * and Union_image_eq UN_iff
   5.298 +    using division_ofD(6)[OF assms(1)] and division_ofD(6)[OF assms(2)] by auto
   5.299 +  { fix k assume "k\<in>?A" then obtain k1 k2 where k:"k = k1 \<inter> k2" "k1\<in>p1" "k2\<in>p2" "k\<noteq>{}" by auto thus "k \<noteq> {}" by auto
   5.300 +  show "k \<subseteq> s1 \<inter> s2" using division_ofD(2)[OF assms(1) k(2)] and division_ofD(2)[OF assms(2) k(3)] unfolding k by auto
   5.301 +  guess a1 using division_ofD(4)[OF assms(1) k(2)] .. then guess b1 .. note ab1=this
   5.302 +  guess a2 using division_ofD(4)[OF assms(2) k(3)] .. then guess b2 .. note ab2=this
   5.303 +  show "\<exists>a b. k = {a..b}" unfolding k ab1 ab2 unfolding inter_interval by auto } fix k1 k2
   5.304 +  assume "k1\<in>?A" then obtain x1 y1 where k1:"k1 = x1 \<inter> y1" "x1\<in>p1" "y1\<in>p2" "k1\<noteq>{}" by auto
   5.305 +  assume "k2\<in>?A" then obtain x2 y2 where k2:"k2 = x2 \<inter> y2" "x2\<in>p1" "y2\<in>p2" "k2\<noteq>{}" by auto
   5.306 +  assume "k1 \<noteq> k2" hence th:"x1\<noteq>x2 \<or> y1\<noteq>y2" unfolding k1 k2 by auto
   5.307 +  have *:"(interior x1 \<inter> interior x2 = {} \<or> interior y1 \<inter> interior y2 = {}) \<Longrightarrow>
   5.308 +      interior(x1 \<inter> y1) \<subseteq> interior(x1) \<Longrightarrow> interior(x1 \<inter> y1) \<subseteq> interior(y1) \<Longrightarrow>
   5.309 +      interior(x2 \<inter> y2) \<subseteq> interior(x2) \<Longrightarrow> interior(x2 \<inter> y2) \<subseteq> interior(y2)
   5.310 +      \<Longrightarrow> interior(x1 \<inter> y1) \<inter> interior(x2 \<inter> y2) = {}" by auto
   5.311 +  show "interior k1 \<inter> interior k2 = {}" unfolding k1 k2 apply(rule *) defer apply(rule_tac[1-4] subset_interior)
   5.312 +    using division_ofD(5)[OF assms(1) k1(2) k2(2)]
   5.313 +    using division_ofD(5)[OF assms(2) k1(3) k2(3)] using th by auto qed qed
   5.314 +
   5.315 +lemma division_inter_1: assumes "d division_of i" "{a..b::real^'n} \<subseteq> i"
   5.316 +  shows "{ {a..b} \<inter> k |k. k \<in> d \<and> {a..b} \<inter> k \<noteq> {} } division_of {a..b}" proof(cases "{a..b} = {}")
   5.317 +  case True show ?thesis unfolding True and division_of_trivial by auto next
   5.318 +  have *:"{a..b} \<inter> i = {a..b}" using assms(2) by auto 
   5.319 +  case False show ?thesis using division_inter[OF division_of_self[OF False] assms(1)] unfolding * by auto qed
   5.320 +
   5.321 +lemma elementary_inter: assumes "p1 division_of s" "p2 division_of (t::(real^'n) set)"
   5.322 +  shows "\<exists>p. p division_of (s \<inter> t)"
   5.323 +  by(rule,rule division_inter[OF assms])
   5.324 +
   5.325 +lemma elementary_inters: assumes "finite f" "f\<noteq>{}" "\<forall>s\<in>f. \<exists>p. p division_of (s::(real^'n) set)"
   5.326 +  shows "\<exists>p. p division_of (\<Inter> f)" using assms apply-proof(induct f rule:finite_induct)
   5.327 +case (insert x f) show ?case proof(cases "f={}")
   5.328 +  case True thus ?thesis unfolding True using insert by auto next
   5.329 +  case False guess p using insert(3)[OF False insert(5)[unfolded ball_simps,THEN conjunct2]] ..
   5.330 +  moreover guess px using insert(5)[rule_format,OF insertI1] .. ultimately
   5.331 +  show ?thesis unfolding Inter_insert apply(rule_tac elementary_inter) by assumption+ qed qed auto
   5.332 +
   5.333 +lemma division_disjoint_union:
   5.334 +  assumes "p1 division_of s1" "p2 division_of s2" "interior s1 \<inter> interior s2 = {}"
   5.335 +  shows "(p1 \<union> p2) division_of (s1 \<union> s2)" proof(rule division_ofI) 
   5.336 +  note d1 = division_ofD[OF assms(1)] and d2 = division_ofD[OF assms(2)]
   5.337 +  show "finite (p1 \<union> p2)" using d1(1) d2(1) by auto
   5.338 +  show "\<Union>(p1 \<union> p2) = s1 \<union> s2" using d1(6) d2(6) by auto
   5.339 +  { fix k1 k2 assume as:"k1 \<in> p1 \<union> p2" "k2 \<in> p1 \<union> p2" "k1 \<noteq> k2" moreover let ?g="interior k1 \<inter> interior k2 = {}"
   5.340 +  { assume as:"k1\<in>p1" "k2\<in>p2" have ?g using subset_interior[OF d1(2)[OF as(1)]] subset_interior[OF d2(2)[OF as(2)]]
   5.341 +      using assms(3) by blast } moreover
   5.342 +  { assume as:"k1\<in>p2" "k2\<in>p1" have ?g using subset_interior[OF d1(2)[OF as(2)]] subset_interior[OF d2(2)[OF as(1)]]
   5.343 +      using assms(3) by blast} ultimately
   5.344 +  show ?g using d1(5)[OF _ _ as(3)] and d2(5)[OF _ _ as(3)] by auto }
   5.345 +  fix k assume k:"k \<in> p1 \<union> p2"  show "k \<subseteq> s1 \<union> s2" using k d1(2) d2(2) by auto
   5.346 +  show "k \<noteq> {}" using k d1(3) d2(3) by auto show "\<exists>a b. k = {a..b}" using k d1(4) d2(4) by auto qed
   5.347 +
   5.348 +lemma partial_division_extend_1:
   5.349 +  assumes "{c..d} \<subseteq> {a..b::real^'n}" "{c..d} \<noteq> {}"
   5.350 +  obtains p where "p division_of {a..b}" "{c..d} \<in> p"
   5.351 +proof- def n \<equiv> "CARD('n)" have n:"1 \<le> n" "0 < n" "n \<noteq> 0" unfolding n_def by auto
   5.352 +  guess \<pi> using ex_bij_betw_nat_finite_1[OF finite_UNIV[where 'a='n]] .. note \<pi>=this
   5.353 +  def \<pi>' \<equiv> "inv_into {1..n} \<pi>"
   5.354 +  have \<pi>':"bij_betw \<pi>' UNIV {1..n}" using bij_betw_inv_into[OF \<pi>] unfolding \<pi>'_def n_def by auto
   5.355 +  hence \<pi>'i:"\<And>i. \<pi>' i \<in> {1..n}" unfolding bij_betw_def by auto 
   5.356 +  have \<pi>\<pi>'[simp]:"\<And>i. \<pi> (\<pi>' i) = i" unfolding \<pi>'_def apply(rule f_inv_into_f) unfolding n_def using \<pi> unfolding bij_betw_def by auto
   5.357 +  have \<pi>'\<pi>[simp]:"\<And>i. i\<in>{1..n} \<Longrightarrow> \<pi>' (\<pi> i) = i" unfolding \<pi>'_def apply(rule inv_into_f_eq) using \<pi> unfolding n_def bij_betw_def by auto
   5.358 +  have "{c..d} \<noteq> {}" using assms by auto
   5.359 +  let ?p1 = "\<lambda>l. {(\<chi> i. if \<pi>' i < l then c$i else a$i) .. (\<chi> i. if \<pi>' i < l then d$i else if \<pi>' i = l then c$\<pi> l else b$i)}"
   5.360 +  let ?p2 = "\<lambda>l. {(\<chi> i. if \<pi>' i < l then c$i else if \<pi>' i = l then d$\<pi> l else a$i) .. (\<chi> i. if \<pi>' i < l then d$i else b$i)}"
   5.361 +  let ?p =  "{?p1 l |l. l \<in> {1..n+1}} \<union> {?p2 l |l. l \<in> {1..n+1}}"
   5.362 +  have abcd:"\<And>i. a $ i \<le> c $ i \<and> c$i \<le> d$i \<and> d $ i \<le> b $ i" using assms unfolding subset_interval interval_eq_empty by(auto simp add:not_le not_less)
   5.363 +  show ?thesis apply(rule that[of ?p]) apply(rule division_ofI)
   5.364 +  proof- have "\<And>i. \<pi>' i < Suc n"
   5.365 +    proof(rule ccontr,unfold not_less) fix i assume "Suc n \<le> \<pi>' i"
   5.366 +      hence "\<pi>' i \<notin> {1..n}" by auto thus False using \<pi>' unfolding bij_betw_def by auto
   5.367 +    qed hence "c = (\<chi> i. if \<pi>' i < Suc n then c $ i else a $ i)"
   5.368 +        "d = (\<chi> i. if \<pi>' i < Suc n then d $ i else if \<pi>' i = n + 1 then c $ \<pi> (n + 1) else b $ i)"
   5.369 +      unfolding Cart_eq Cart_lambda_beta using \<pi>' unfolding bij_betw_def by auto
   5.370 +    thus cdp:"{c..d} \<in> ?p" apply-apply(rule UnI1) unfolding mem_Collect_eq apply(rule_tac x="n + 1" in exI) by auto
   5.371 +    have "\<And>l. l\<in>{1..n+1} \<Longrightarrow> ?p1 l \<subseteq> {a..b}"  "\<And>l. l\<in>{1..n+1} \<Longrightarrow> ?p2 l \<subseteq> {a..b}"
   5.372 +      unfolding subset_eq apply(rule_tac[!] ballI,rule_tac[!] ccontr)
   5.373 +    proof- fix l assume l:"l\<in>{1..n+1}" fix x assume "x\<notin>{a..b}"
   5.374 +      then guess i unfolding mem_interval not_all .. note i=this
   5.375 +      show "x \<in> ?p1 l \<Longrightarrow> False" "x \<in> ?p2 l \<Longrightarrow> False" unfolding mem_interval apply(erule_tac[!] x=i in allE)
   5.376 +        apply(case_tac[!] "\<pi>' i < l", case_tac[!] "\<pi>' i = l") using abcd[of i] i by auto 
   5.377 +    qed moreover have "\<And>x. x \<in> {a..b} \<Longrightarrow> x \<in> \<Union>?p"
   5.378 +    proof- fix x assume x:"x\<in>{a..b}"
   5.379 +      { presume "x\<notin>{c..d} \<Longrightarrow> x \<in> \<Union>?p" thus "x \<in> \<Union>?p" using cdp by blast }
   5.380 +      let ?M = "{i. i\<in>{1..n+1} \<and> \<not> (c $ \<pi> i \<le> x $ \<pi> i \<and> x $ \<pi> i \<le> d $ \<pi> i)}"
   5.381 +      assume "x\<notin>{c..d}" then guess i0 unfolding mem_interval not_all ..
   5.382 +      hence "\<pi>' i0 \<in> ?M" using \<pi>' unfolding bij_betw_def by(auto intro!:le_SucI)
   5.383 +      hence M:"finite ?M" "?M \<noteq> {}" by auto
   5.384 +      def l \<equiv> "Min ?M" note l = Min_less_iff[OF M,unfolded l_def[symmetric]] Min_in[OF M,unfolded mem_Collect_eq l_def[symmetric]]
   5.385 +        Min_gr_iff[OF M,unfolded l_def[symmetric]]
   5.386 +      have "x\<in>?p1 l \<or> x\<in>?p2 l" using l(2)[THEN conjunct2] unfolding de_Morgan_conj not_le
   5.387 +        apply- apply(erule disjE) apply(rule disjI1) defer apply(rule disjI2)
   5.388 +      proof- assume as:"x $ \<pi> l < c $ \<pi> l"
   5.389 +        show "x \<in> ?p1 l" unfolding mem_interval Cart_lambda_beta
   5.390 +        proof case goal1 have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le by auto
   5.391 +          thus ?case using as x[unfolded mem_interval,rule_format,of i]
   5.392 +            apply auto using l(3)[of "\<pi>' i"] by(auto elim!:ballE[where x="\<pi>' i"])
   5.393 +        qed
   5.394 +      next assume as:"x $ \<pi> l > d $ \<pi> l"
   5.395 +        show "x \<in> ?p2 l" unfolding mem_interval Cart_lambda_beta
   5.396 +        proof case goal1 have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le by auto
   5.397 +          thus ?case using as x[unfolded mem_interval,rule_format,of i]
   5.398 +            apply auto using l(3)[of "\<pi>' i"] by(auto elim!:ballE[where x="\<pi>' i"])
   5.399 +        qed qed
   5.400 +      thus "x \<in> \<Union>?p" using l(2) by blast 
   5.401 +    qed ultimately show "\<Union>?p = {a..b}" apply-apply(rule) defer apply(rule) by(assumption,blast)
   5.402 +    
   5.403 +    show "finite ?p" by auto
   5.404 +    fix k assume k:"k\<in>?p" then obtain l where l:"k = ?p1 l \<or> k = ?p2 l" "l \<in> {1..n + 1}" by auto
   5.405 +    show "k\<subseteq>{a..b}" apply(rule,unfold mem_interval,rule,rule) 
   5.406 +    proof- fix i::'n and x assume "x \<in> k" moreover have "\<pi>' i < l \<or> \<pi>' i = l \<or> \<pi>' i > l" by auto
   5.407 +      ultimately show "a$i \<le> x$i" "x$i \<le> b$i" using abcd[of i] using l by(auto elim:disjE elim!:allE[where x=i] simp add:vector_le_def)
   5.408 +    qed have "\<And>l. ?p1 l \<noteq> {}" "\<And>l. ?p2 l \<noteq> {}" unfolding interval_eq_empty not_ex apply(rule_tac[!] allI)
   5.409 +    proof- case goal1 thus ?case using abcd[of x] by auto
   5.410 +    next   case goal2 thus ?case using abcd[of x] by auto
   5.411 +    qed thus "k \<noteq> {}" using k by auto
   5.412 +    show "\<exists>a b. k = {a..b}" using k by auto
   5.413 +    fix k' assume k':"k' \<in> ?p" "k \<noteq> k'" then obtain l' where l':"k' = ?p1 l' \<or> k' = ?p2 l'" "l' \<in> {1..n + 1}" by auto
   5.414 +    { fix k k' l l'
   5.415 +      assume k:"k\<in>?p" and l:"k = ?p1 l \<or> k = ?p2 l" "l \<in> {1..n + 1}" 
   5.416 +      assume k':"k' \<in> ?p" "k \<noteq> k'" and  l':"k' = ?p1 l' \<or> k' = ?p2 l'" "l' \<in> {1..n + 1}" 
   5.417 +      assume "l \<le> l'" fix x
   5.418 +      have "x \<notin> interior k \<inter> interior k'" 
   5.419 +      proof(rule,cases "l' = n+1") assume x:"x \<in> interior k \<inter> interior k'"
   5.420 +        case True hence "\<And>i. \<pi>' i < l'" using \<pi>'i by(auto simp add:less_Suc_eq_le)
   5.421 +        hence k':"k' = {c..d}" using l'(1) \<pi>'i by(auto simp add:Cart_nth_inverse)
   5.422 +        have ln:"l < n + 1" 
   5.423 +        proof(rule ccontr) case goal1 hence l2:"l = n+1" using l by auto
   5.424 +          hence "\<And>i. \<pi>' i < l" using \<pi>'i by(auto simp add:less_Suc_eq_le)
   5.425 +          hence "k = {c..d}" using l(1) \<pi>'i by(auto simp add:Cart_nth_inverse)
   5.426 +          thus False using `k\<noteq>k'` k' by auto
   5.427 +        qed have **:"\<pi>' (\<pi> l) = l" using \<pi>'\<pi>[of l] using l ln by auto
   5.428 +        have "x $ \<pi> l < c $ \<pi> l \<or> d $ \<pi> l < x $ \<pi> l" using l(1) apply-
   5.429 +        proof(erule disjE)
   5.430 +          assume as:"k = ?p1 l" note * = conjunct1[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   5.431 +          show ?thesis using *[of "\<pi> l"] using ln unfolding Cart_lambda_beta ** by auto
   5.432 +        next assume as:"k = ?p2 l" note * = conjunct1[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   5.433 +          show ?thesis using *[of "\<pi> l"] using ln unfolding Cart_lambda_beta ** by auto
   5.434 +        qed thus False using x unfolding k' unfolding Int_iff interior_closed_interval mem_interval
   5.435 +          by(auto elim!:allE[where x="\<pi> l"])
   5.436 +      next case False hence "l < n + 1" using l'(2) using `l\<le>l'` by auto
   5.437 +        hence ln:"l \<in> {1..n}" "l' \<in> {1..n}" using l l' False by auto
   5.438 +        note \<pi>l = \<pi>'\<pi>[OF ln(1)] \<pi>'\<pi>[OF ln(2)]
   5.439 +        assume x:"x \<in> interior k \<inter> interior k'"
   5.440 +        show False using l(1) l'(1) apply-
   5.441 +        proof(erule_tac[!] disjE)+
   5.442 +          assume as:"k = ?p1 l" "k' = ?p1 l'"
   5.443 +          note * = x[unfolded as Int_iff interior_closed_interval mem_interval]
   5.444 +          have "l \<noteq> l'" using k'(2)[unfolded as] by auto
   5.445 +          thus False using * by(smt Cart_lambda_beta \<pi>l)
   5.446 +        next assume as:"k = ?p2 l" "k' = ?p2 l'"
   5.447 +          note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   5.448 +          have "l \<noteq> l'" apply(rule) using k'(2)[unfolded as] by auto
   5.449 +          thus False using *[of "\<pi> l"] *[of "\<pi> l'"]
   5.450 +            unfolding Cart_lambda_beta \<pi>l using `l \<le> l'` by auto
   5.451 +        next assume as:"k = ?p1 l" "k' = ?p2 l'"
   5.452 +          note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   5.453 +          show False using *[of "\<pi> l"] *[of "\<pi> l'"]
   5.454 +            unfolding Cart_lambda_beta \<pi>l using `l \<le> l'` using abcd[of "\<pi> l'"] by smt 
   5.455 +        next assume as:"k = ?p2 l" "k' = ?p1 l'"
   5.456 +          note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   5.457 +          show False using *[of "\<pi> l"] *[of "\<pi> l'"]
   5.458 +            unfolding Cart_lambda_beta \<pi>l using `l \<le> l'` using abcd[of "\<pi> l'"] by smt
   5.459 +        qed qed } 
   5.460 +    from this[OF k l k' l'] this[OF k'(1) l' k _ l] have "\<And>x. x \<notin> interior k \<inter> interior k'"
   5.461 +      apply - apply(cases "l' \<le> l") using k'(2) by auto            
   5.462 +    thus "interior k \<inter> interior k' = {}" by auto        
   5.463 +qed qed
   5.464 +
   5.465 +lemma partial_division_extend_interval: assumes "p division_of (\<Union>p)" "(\<Union>p) \<subseteq> {a..b}"
   5.466 +  obtains q where "p \<subseteq> q" "q division_of {a..b::real^'n}" proof(cases "p = {}")
   5.467 +  case True guess q apply(rule elementary_interval[of a b]) .
   5.468 +  thus ?thesis apply- apply(rule that[of q]) unfolding True by auto next
   5.469 +  case False note p = division_ofD[OF assms(1)]
   5.470 +  have *:"\<forall>k\<in>p. \<exists>q. q division_of {a..b} \<and> k\<in>q" proof case goal1
   5.471 +    guess c using p(4)[OF goal1] .. then guess d .. note cd_ = this
   5.472 +    have *:"{c..d} \<subseteq> {a..b}" "{c..d} \<noteq> {}" using p(2,3)[OF goal1, unfolded cd_] using assms(2) by auto
   5.473 +    guess q apply(rule partial_division_extend_1[OF *]) . thus ?case unfolding cd_ by auto qed
   5.474 +  guess q using bchoice[OF *] .. note q = conjunctD2[OF this[rule_format]]
   5.475 +  have "\<And>x. x\<in>p \<Longrightarrow> \<exists>d. d division_of \<Union>(q x - {x})" apply(rule,rule_tac p="q x" in division_of_subset) proof-
   5.476 +    fix x assume x:"x\<in>p" show "q x division_of \<Union>q x" apply-apply(rule division_ofI)
   5.477 +      using division_ofD[OF q(1)[OF x]] by auto show "q x - {x} \<subseteq> q x" by auto qed
   5.478 +  hence "\<exists>d. d division_of \<Inter> ((\<lambda>i. \<Union>(q i - {i})) ` p)" apply- apply(rule elementary_inters)
   5.479 +    apply(rule finite_imageI[OF p(1)]) unfolding image_is_empty apply(rule False) by auto
   5.480 +  then guess d .. note d = this
   5.481 +  show ?thesis apply(rule that[of "d \<union> p"]) proof-
   5.482 +    have *:"\<And>s f t. s \<noteq> {} \<Longrightarrow> (\<forall>i\<in>s. f i \<union> i = t) \<Longrightarrow> t = \<Inter> (f ` s) \<union> (\<Union>s)" by auto
   5.483 +    have *:"{a..b} = \<Inter> (\<lambda>i. \<Union>(q i - {i})) ` p \<union> \<Union>p" apply(rule *[OF False]) proof fix i assume i:"i\<in>p"
   5.484 +      show "\<Union>(q i - {i}) \<union> i = {a..b}" using division_ofD(6)[OF q(1)[OF i]] using q(2)[OF i] by auto qed
   5.485 +    show "d \<union> p division_of {a..b}" unfolding * apply(rule division_disjoint_union[OF d assms(1)])
   5.486 +      apply(rule inter_interior_unions_intervals) apply(rule p open_interior ballI)+ proof(assumption,rule)
   5.487 +      fix k assume k:"k\<in>p" have *:"\<And>u t s. u \<subseteq> s \<Longrightarrow> s \<inter> t = {} \<Longrightarrow> u \<inter> t = {}" by auto
   5.488 +      show "interior (\<Inter>(\<lambda>i. \<Union>(q i - {i})) ` p) \<inter> interior k = {}" apply(rule *[of _ "interior (\<Union>(q k - {k}))"])
   5.489 +	defer apply(subst Int_commute) apply(rule inter_interior_unions_intervals) proof- note qk=division_ofD[OF q(1)[OF k]]
   5.490 +	show "finite (q k - {k})" "open (interior k)"  "\<forall>t\<in>q k - {k}. \<exists>a b. t = {a..b}" using qk by auto
   5.491 +	show "\<forall>t\<in>q k - {k}. interior k \<inter> interior t = {}" using qk(5) using q(2)[OF k] by auto
   5.492 +	have *:"\<And>x s. x \<in> s \<Longrightarrow> \<Inter>s \<subseteq> x" by auto show "interior (\<Inter>(\<lambda>i. \<Union>(q i - {i})) ` p) \<subseteq> interior (\<Union>(q k - {k}))"
   5.493 +	  apply(rule subset_interior *)+ using k by auto qed qed qed auto qed
   5.494 +
   5.495 +lemma elementary_bounded[dest]: "p division_of s \<Longrightarrow> bounded (s::(real^'n) set)"
   5.496 +  unfolding division_of_def by(metis bounded_Union bounded_interval) 
   5.497 +
   5.498 +lemma elementary_subset_interval: "p division_of s \<Longrightarrow> \<exists>a b. s \<subseteq> {a..b::real^'n}"
   5.499 +  by(meson elementary_bounded bounded_subset_closed_interval)
   5.500 +
   5.501 +lemma division_union_intervals_exists: assumes "{a..b::real^'n} \<noteq> {}"
   5.502 +  obtains p where "(insert {a..b} p) division_of ({a..b} \<union> {c..d})" proof(cases "{c..d} = {}")
   5.503 +  case True show ?thesis apply(rule that[of "{}"]) unfolding True using assms by auto next
   5.504 +  case False note false=this show ?thesis proof(cases "{a..b} \<inter> {c..d} = {}")
   5.505 +  have *:"\<And>a b. {a,b} = {a} \<union> {b}" by auto
   5.506 +  case True show ?thesis apply(rule that[of "{{c..d}}"]) unfolding * apply(rule division_disjoint_union)
   5.507 +    using false True assms using interior_subset by auto next
   5.508 +  case False obtain u v where uv:"{a..b} \<inter> {c..d} = {u..v}" unfolding inter_interval by auto
   5.509 +  have *:"{u..v} \<subseteq> {c..d}" using uv by auto
   5.510 +  guess p apply(rule partial_division_extend_1[OF * False[unfolded uv]]) . note p=this division_ofD[OF this(1)]
   5.511 +  have *:"{a..b} \<union> {c..d} = {a..b} \<union> \<Union>(p - {{u..v}})" "\<And>x s. insert x s = {x} \<union> s" using p(8) unfolding uv[THEN sym] by auto
   5.512 +  show thesis apply(rule that[of "p - {{u..v}}"]) unfolding *(1) apply(subst *(2)) apply(rule division_disjoint_union)
   5.513 +    apply(rule,rule assms) apply(rule division_of_subset[of p]) apply(rule division_of_union_self[OF p(1)]) defer
   5.514 +    unfolding interior_inter[THEN sym] proof-
   5.515 +    have *:"\<And>cd p uv ab. p \<subseteq> cd \<Longrightarrow> ab \<inter> cd = uv \<Longrightarrow> ab \<inter> p = uv \<inter> p" by auto
   5.516 +    have "interior ({a..b} \<inter> \<Union>(p - {{u..v}})) = interior({u..v} \<inter> \<Union>(p - {{u..v}}))" 
   5.517 +      apply(rule arg_cong[of _ _ interior]) apply(rule *[OF _ uv]) using p(8) by auto
   5.518 +    also have "\<dots> = {}" unfolding interior_inter apply(rule inter_interior_unions_intervals) using p(6) p(7)[OF p(2)] p(3) by auto
   5.519 +    finally show "interior ({a..b} \<inter> \<Union>(p - {{u..v}})) = {}" by assumption qed auto qed qed
   5.520 +
   5.521 +lemma division_of_unions: assumes "finite f"  "\<And>p. p\<in>f \<Longrightarrow> p division_of (\<Union>p)"
   5.522 +  "\<And>k1 k2. \<lbrakk>k1 \<in> \<Union>f; k2 \<in> \<Union>f; k1 \<noteq> k2\<rbrakk> \<Longrightarrow> interior k1 \<inter> interior k2 = {}"
   5.523 +  shows "\<Union>f division_of \<Union>\<Union>f" apply(rule division_ofI) prefer 5 apply(rule assms(3)|assumption)+
   5.524 +  apply(rule finite_Union assms(1))+ prefer 3 apply(erule UnionE) apply(rule_tac s=X in division_ofD(3)[OF assms(2)])
   5.525 +  using division_ofD[OF assms(2)] by auto
   5.526 +  
   5.527 +lemma elementary_union_interval: assumes "p division_of \<Union>p"
   5.528 +  obtains q where "q division_of ({a..b::real^'n} \<union> \<Union>p)" proof-
   5.529 +  note assm=division_ofD[OF assms]
   5.530 +  have lem1:"\<And>f s. \<Union>\<Union> (f ` s) = \<Union>(\<lambda>x.\<Union>(f x)) ` s" by auto
   5.531 +  have lem2:"\<And>f s. f \<noteq> {} \<Longrightarrow> \<Union>{s \<union> t |t. t \<in> f} = s \<union> \<Union>f" by auto
   5.532 +{ presume "p={} \<Longrightarrow> thesis" "{a..b} = {} \<Longrightarrow> thesis" "{a..b} \<noteq> {} \<Longrightarrow> interior {a..b} = {} \<Longrightarrow> thesis"
   5.533 +    "p\<noteq>{} \<Longrightarrow> interior {a..b}\<noteq>{} \<Longrightarrow> {a..b} \<noteq> {} \<Longrightarrow> thesis"
   5.534 +  thus thesis by auto
   5.535 +next assume as:"p={}" guess p apply(rule elementary_interval[of a b]) .
   5.536 +  thus thesis apply(rule_tac that[of p]) unfolding as by auto 
   5.537 +next assume as:"{a..b}={}" show thesis apply(rule that) unfolding as using assms by auto
   5.538 +next assume as:"interior {a..b} = {}" "{a..b} \<noteq> {}"
   5.539 +  show thesis apply(rule that[of "insert {a..b} p"],rule division_ofI)
   5.540 +    unfolding finite_insert apply(rule assm(1)) unfolding Union_insert  
   5.541 +    using assm(2-4) as apply- by(fastsimp dest: assm(5))+
   5.542 +next assume as:"p \<noteq> {}" "interior {a..b} \<noteq> {}" "{a..b}\<noteq>{}"
   5.543 +  have "\<forall>k\<in>p. \<exists>q. (insert {a..b} q) division_of ({a..b} \<union> k)" proof case goal1
   5.544 +    from assm(4)[OF this] guess c .. then guess d ..
   5.545 +    thus ?case apply-apply(rule division_union_intervals_exists[OF as(3),of c d]) by auto
   5.546 +  qed from bchoice[OF this] guess q .. note q=division_ofD[OF this[rule_format]]
   5.547 +  let ?D = "\<Union>{insert {a..b} (q k) | k. k \<in> p}"
   5.548 +  show thesis apply(rule that[of "?D"]) proof(rule division_ofI)
   5.549 +    have *:"{insert {a..b} (q k) |k. k \<in> p} = (\<lambda>k. insert {a..b} (q k)) ` p" by auto
   5.550 +    show "finite ?D" apply(rule finite_Union) unfolding * apply(rule finite_imageI) using assm(1) q(1) by auto
   5.551 +    show "\<Union>?D = {a..b} \<union> \<Union>p" unfolding * lem1 unfolding lem2[OF as(1), of "{a..b}",THEN sym]
   5.552 +      using q(6) by auto
   5.553 +    fix k assume k:"k\<in>?D" thus " k \<subseteq> {a..b} \<union> \<Union>p" using q(2) by auto
   5.554 +    show "k \<noteq> {}" using q(3) k by auto show "\<exists>a b. k = {a..b}" using q(4) k by auto
   5.555 +    fix k' assume k':"k'\<in>?D" "k\<noteq>k'"
   5.556 +    obtain x  where x: "k \<in>insert {a..b} (q x)"  "x\<in>p"  using k  by auto
   5.557 +    obtain x' where x':"k'\<in>insert {a..b} (q x')" "x'\<in>p" using k' by auto
   5.558 +    show "interior k \<inter> interior k' = {}" proof(cases "x=x'")
   5.559 +      case True show ?thesis apply(rule q(5)) using x x' k' unfolding True by auto
   5.560 +    next case False 
   5.561 +      { presume "k = {a..b} \<Longrightarrow> ?thesis" "k' = {a..b} \<Longrightarrow> ?thesis" 
   5.562 +        "k \<noteq> {a..b} \<Longrightarrow> k' \<noteq> {a..b} \<Longrightarrow> ?thesis"
   5.563 +        thus ?thesis by auto }
   5.564 +      { assume as':"k  = {a..b}" show ?thesis apply(rule q(5)) using x' k'(2) unfolding as' by auto }
   5.565 +      { assume as':"k' = {a..b}" show ?thesis apply(rule q(5)) using x  k'(2) unfolding as' by auto }
   5.566 +      assume as':"k \<noteq> {a..b}" "k' \<noteq> {a..b}"
   5.567 +      guess c using q(4)[OF x(2,1)] .. then guess d .. note c_d=this
   5.568 +      have "interior k  \<inter> interior {a..b} = {}" apply(rule q(5)) using x  k'(2) using as' by auto
   5.569 +      hence "interior k \<subseteq> interior x" apply-
   5.570 +        apply(rule interior_subset_union_intervals[OF c_d _ as(2) q(2)[OF x(2,1)]]) by auto moreover
   5.571 +      guess c using q(4)[OF x'(2,1)] .. then guess d .. note c_d=this
   5.572 +      have "interior k' \<inter> interior {a..b} = {}" apply(rule q(5)) using x' k'(2) using as' by auto
   5.573 +      hence "interior k' \<subseteq> interior x'" apply-
   5.574 +        apply(rule interior_subset_union_intervals[OF c_d _ as(2) q(2)[OF x'(2,1)]]) by auto
   5.575 +      ultimately show ?thesis using assm(5)[OF x(2) x'(2) False] by auto
   5.576 +    qed qed } qed
   5.577 +
   5.578 +lemma elementary_unions_intervals:
   5.579 +  assumes "finite f" "\<And>s. s \<in> f \<Longrightarrow> \<exists>a b. s = {a..b::real^'n}"
   5.580 +  obtains p where "p division_of (\<Union>f)" proof-
   5.581 +  have "\<exists>p. p division_of (\<Union>f)" proof(induct_tac f rule:finite_subset_induct) 
   5.582 +    show "\<exists>p. p division_of \<Union>{}" using elementary_empty by auto
   5.583 +    fix x F assume as:"finite F" "x \<notin> F" "\<exists>p. p division_of \<Union>F" "x\<in>f"
   5.584 +    from this(3) guess p .. note p=this
   5.585 +    from assms(2)[OF as(4)] guess a .. then guess b .. note ab=this
   5.586 +    have *:"\<Union>F = \<Union>p" using division_ofD[OF p] by auto
   5.587 +    show "\<exists>p. p division_of \<Union>insert x F" using elementary_union_interval[OF p[unfolded *], of a b]
   5.588 +      unfolding Union_insert ab * by auto
   5.589 +  qed(insert assms,auto) thus ?thesis apply-apply(erule exE,rule that) by auto qed
   5.590 +
   5.591 +lemma elementary_union: assumes "ps division_of s" "pt division_of (t::(real^'n) set)"
   5.592 +  obtains p where "p division_of (s \<union> t)"
   5.593 +proof- have "s \<union> t = \<Union>ps \<union> \<Union>pt" using assms unfolding division_of_def by auto
   5.594 +  hence *:"\<Union>(ps \<union> pt) = s \<union> t" by auto
   5.595 +  show ?thesis apply-apply(rule elementary_unions_intervals[of "ps\<union>pt"])
   5.596 +    unfolding * prefer 3 apply(rule_tac p=p in that)
   5.597 +    using assms[unfolded division_of_def] by auto qed
   5.598 +
   5.599 +lemma partial_division_extend: fixes t::"(real^'n) set"
   5.600 +  assumes "p division_of s" "q division_of t" "s \<subseteq> t"
   5.601 +  obtains r where "p \<subseteq> r" "r division_of t" proof-
   5.602 +  note divp = division_ofD[OF assms(1)] and divq = division_ofD[OF assms(2)]
   5.603 +  obtain a b where ab:"t\<subseteq>{a..b}" using elementary_subset_interval[OF assms(2)] by auto
   5.604 +  guess r1 apply(rule partial_division_extend_interval) apply(rule assms(1)[unfolded divp(6)[THEN sym]])
   5.605 +    apply(rule subset_trans) by(rule ab assms[unfolded divp(6)[THEN sym]])+  note r1 = this division_ofD[OF this(2)]
   5.606 +  guess p' apply(rule elementary_unions_intervals[of "r1 - p"]) using r1(3,6) by auto 
   5.607 +  then obtain r2 where r2:"r2 division_of (\<Union>(r1 - p)) \<inter> (\<Union>q)" 
   5.608 +    apply- apply(drule elementary_inter[OF _ assms(2)[unfolded divq(6)[THEN sym]]]) by auto
   5.609 +  { fix x assume x:"x\<in>t" "x\<notin>s"
   5.610 +    hence "x\<in>\<Union>r1" unfolding r1 using ab by auto
   5.611 +    then guess r unfolding Union_iff .. note r=this moreover
   5.612 +    have "r \<notin> p" proof assume "r\<in>p" hence "x\<in>s" using divp(2) r by auto
   5.613 +      thus False using x by auto qed
   5.614 +    ultimately have "x\<in>\<Union>(r1 - p)" by auto }
   5.615 +  hence *:"t = \<Union>p \<union> (\<Union>(r1 - p) \<inter> \<Union>q)" unfolding divp divq using assms(3) by auto
   5.616 +  show ?thesis apply(rule that[of "p \<union> r2"]) unfolding * defer apply(rule division_disjoint_union)
   5.617 +    unfolding divp(6) apply(rule assms r2)+
   5.618 +  proof- have "interior s \<inter> interior (\<Union>(r1-p)) = {}"
   5.619 +    proof(rule inter_interior_unions_intervals)
   5.620 +      show "finite (r1 - p)" "open (interior s)" "\<forall>t\<in>r1-p. \<exists>a b. t = {a..b}" using r1 by auto
   5.621 +      have *:"\<And>s. (\<And>x. x \<in> s \<Longrightarrow> False) \<Longrightarrow> s = {}" by auto
   5.622 +      show "\<forall>t\<in>r1-p. interior s \<inter> interior t = {}" proof(rule)
   5.623 +        fix m x assume as:"m\<in>r1-p"
   5.624 +        have "interior m \<inter> interior (\<Union>p) = {}" proof(rule inter_interior_unions_intervals)
   5.625 +          show "finite p" "open (interior m)" "\<forall>t\<in>p. \<exists>a b. t = {a..b}" using divp by auto
   5.626 +          show "\<forall>t\<in>p. interior m \<inter> interior t = {}" apply(rule, rule r1(7)) using as using r1 by auto
   5.627 +        qed thus "interior s \<inter> interior m = {}" unfolding divp by auto
   5.628 +      qed qed        
   5.629 +    thus "interior s \<inter> interior (\<Union>(r1-p) \<inter> (\<Union>q)) = {}" using interior_subset by auto
   5.630 +  qed auto qed
   5.631 +
   5.632 +subsection {* Tagged (partial) divisions. *}
   5.633 +
   5.634 +definition tagged_partial_division_of (infixr "tagged'_partial'_division'_of" 40) where
   5.635 +  "(s tagged_partial_division_of i) \<equiv>
   5.636 +        finite s \<and>
   5.637 +        (\<forall>x k. (x,k) \<in> s \<longrightarrow> x \<in> k \<and> k \<subseteq> i \<and> (\<exists>a b. k = {a..b})) \<and>
   5.638 +        (\<forall>x1 k1 x2 k2. (x1,k1) \<in> s \<and> (x2,k2) \<in> s \<and> ((x1,k1) \<noteq> (x2,k2))
   5.639 +                       \<longrightarrow> (interior(k1) \<inter> interior(k2) = {}))"
   5.640 +
   5.641 +lemma tagged_partial_division_ofD[dest]: assumes "s tagged_partial_division_of i"
   5.642 +  shows "finite s" "\<And>x k. (x,k) \<in> s \<Longrightarrow> x \<in> k" "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> i"
   5.643 +  "\<And>x k. (x,k) \<in> s \<Longrightarrow> \<exists>a b. k = {a..b}"
   5.644 +  "\<And>x1 k1 x2 k2. (x1,k1) \<in> s \<Longrightarrow> (x2,k2) \<in> s \<Longrightarrow> (x1,k1) \<noteq> (x2,k2) \<Longrightarrow> interior(k1) \<inter> interior(k2) = {}"
   5.645 +  using assms unfolding tagged_partial_division_of_def  apply- by blast+ 
   5.646 +
   5.647 +definition tagged_division_of (infixr "tagged'_division'_of" 40) where
   5.648 +  "(s tagged_division_of i) \<equiv>
   5.649 +        (s tagged_partial_division_of i) \<and> (\<Union>{k. \<exists>x. (x,k) \<in> s} = i)"
   5.650 +
   5.651 +lemma tagged_division_of_finite[dest]: "s tagged_division_of i \<Longrightarrow> finite s"
   5.652 +  unfolding tagged_division_of_def tagged_partial_division_of_def by auto
   5.653 +
   5.654 +lemma tagged_division_of:
   5.655 + "(s tagged_division_of i) \<longleftrightarrow>
   5.656 +        finite s \<and>
   5.657 +        (\<forall>x k. (x,k) \<in> s
   5.658 +               \<longrightarrow> x \<in> k \<and> k \<subseteq> i \<and> (\<exists>a b. k = {a..b})) \<and>
   5.659 +        (\<forall>x1 k1 x2 k2. (x1,k1) \<in> s \<and> (x2,k2) \<in> s \<and> ~((x1,k1) = (x2,k2))
   5.660 +                       \<longrightarrow> (interior(k1) \<inter> interior(k2) = {})) \<and>
   5.661 +        (\<Union>{k. \<exists>x. (x,k) \<in> s} = i)"
   5.662 +  unfolding tagged_division_of_def tagged_partial_division_of_def by auto
   5.663 +
   5.664 +lemma tagged_division_ofI: assumes
   5.665 +  "finite s" "\<And>x k. (x,k) \<in> s \<Longrightarrow> x \<in> k" "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> i"  "\<And>x k. (x,k) \<in> s \<Longrightarrow> \<exists>a b. k = {a..b}"
   5.666 +  "\<And>x1 k1 x2 k2. (x1,k1) \<in> s \<Longrightarrow> (x2,k2) \<in> s \<Longrightarrow> ~((x1,k1) = (x2,k2)) \<Longrightarrow> (interior(k1) \<inter> interior(k2) = {})"
   5.667 +  "(\<Union>{k. \<exists>x. (x,k) \<in> s} = i)"
   5.668 +  shows "s tagged_division_of i"
   5.669 +  unfolding tagged_division_of apply(rule) defer apply rule
   5.670 +  apply(rule allI impI conjI assms)+ apply assumption
   5.671 +  apply(rule, rule assms, assumption) apply(rule assms, assumption)
   5.672 +  using assms(1,5-) apply- by blast+
   5.673 +
   5.674 +lemma tagged_division_ofD[dest]: assumes "s tagged_division_of i"
   5.675 +  shows "finite s" "\<And>x k. (x,k) \<in> s \<Longrightarrow> x \<in> k" "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> i"  "\<And>x k. (x,k) \<in> s \<Longrightarrow> \<exists>a b. k = {a..b}"
   5.676 +  "\<And>x1 k1 x2 k2. (x1,k1) \<in> s \<Longrightarrow> (x2,k2) \<in> s \<Longrightarrow> ~((x1,k1) = (x2,k2)) \<Longrightarrow> (interior(k1) \<inter> interior(k2) = {})"
   5.677 +  "(\<Union>{k. \<exists>x. (x,k) \<in> s} = i)" using assms unfolding tagged_division_of apply- by blast+
   5.678 +
   5.679 +lemma division_of_tagged_division: assumes"s tagged_division_of i"  shows "(snd ` s) division_of i"
   5.680 +proof(rule division_ofI) note assm=tagged_division_ofD[OF assms]
   5.681 +  show "\<Union>snd ` s = i" "finite (snd ` s)" using assm by auto
   5.682 +  fix k assume k:"k \<in> snd ` s" then obtain xk where xk:"(xk, k) \<in> s" by auto
   5.683 +  thus  "k \<subseteq> i" "k \<noteq> {}" "\<exists>a b. k = {a..b}" using assm apply- by fastsimp+
   5.684 +  fix k' assume k':"k' \<in> snd ` s" "k \<noteq> k'" from this(1) obtain xk' where xk':"(xk', k') \<in> s" by auto
   5.685 +  thus "interior k \<inter> interior k' = {}" apply-apply(rule assm(5)) apply(rule xk xk')+ using k' by auto
   5.686 +qed
   5.687 +
   5.688 +lemma partial_division_of_tagged_division: assumes "s tagged_partial_division_of i"
   5.689 +  shows "(snd ` s) division_of \<Union>(snd ` s)"
   5.690 +proof(rule division_ofI) note assm=tagged_partial_division_ofD[OF assms]
   5.691 +  show "finite (snd ` s)" "\<Union>snd ` s = \<Union>snd ` s" using assm by auto
   5.692 +  fix k assume k:"k \<in> snd ` s" then obtain xk where xk:"(xk, k) \<in> s" by auto
   5.693 +  thus "k\<noteq>{}" "\<exists>a b. k = {a..b}" "k \<subseteq> \<Union>snd ` s" using assm by auto
   5.694 +  fix k' assume k':"k' \<in> snd ` s" "k \<noteq> k'" from this(1) obtain xk' where xk':"(xk', k') \<in> s" by auto
   5.695 +  thus "interior k \<inter> interior k' = {}" apply-apply(rule assm(5)) apply(rule xk xk')+ using k' by auto
   5.696 +qed
   5.697 +
   5.698 +lemma tagged_partial_division_subset: assumes "s tagged_partial_division_of i" "t \<subseteq> s"
   5.699 +  shows "t tagged_partial_division_of i"
   5.700 +  using assms unfolding tagged_partial_division_of_def using finite_subset[OF assms(2)] by blast
   5.701 +
   5.702 +lemma setsum_over_tagged_division_lemma: fixes d::"(real^'m) set \<Rightarrow> 'a::real_normed_vector"
   5.703 +  assumes "p tagged_division_of i" "\<And>u v. {u..v} \<noteq> {} \<Longrightarrow> content {u..v} = 0 \<Longrightarrow> d {u..v} = 0"
   5.704 +  shows "setsum (\<lambda>(x,k). d k) p = setsum d (snd ` p)"
   5.705 +proof- note assm=tagged_division_ofD[OF assms(1)]
   5.706 +  have *:"(\<lambda>(x,k). d k) = d \<circ> snd" unfolding o_def apply(rule ext) by auto
   5.707 +  show ?thesis unfolding * apply(subst eq_commute) proof(rule setsum_reindex_nonzero)
   5.708 +    show "finite p" using assm by auto
   5.709 +    fix x y assume as:"x\<in>p" "y\<in>p" "x\<noteq>y" "snd x = snd y" 
   5.710 +    obtain a b where ab:"snd x = {a..b}" using assm(4)[of "fst x" "snd x"] as(1) by auto
   5.711 +    have "(fst x, snd y) \<in> p" "(fst x, snd y) \<noteq> y" unfolding as(4)[THEN sym] using as(1-3) by auto
   5.712 +    hence "interior (snd x) \<inter> interior (snd y) = {}" apply-apply(rule assm(5)[of "fst x" _ "fst y"]) using as by auto 
   5.713 +    hence "content {a..b} = 0" unfolding as(4)[THEN sym] ab content_eq_0_interior by auto
   5.714 +    hence "d {a..b} = 0" apply-apply(rule assms(2)) using assm(2)[of "fst x" "snd x"] as(1) unfolding ab[THEN sym] by auto
   5.715 +    thus "d (snd x) = 0" unfolding ab by auto qed qed
   5.716 +
   5.717 +lemma tag_in_interval: "p tagged_division_of i \<Longrightarrow> (x,k) \<in> p \<Longrightarrow> x \<in> i" by auto
   5.718 +
   5.719 +lemma tagged_division_of_empty: "{} tagged_division_of {}"
   5.720 +  unfolding tagged_division_of by auto
   5.721 +
   5.722 +lemma tagged_partial_division_of_trivial[simp]:
   5.723 + "p tagged_partial_division_of {} \<longleftrightarrow> p = {}"
   5.724 +  unfolding tagged_partial_division_of_def by auto
   5.725 +
   5.726 +lemma tagged_division_of_trivial[simp]:
   5.727 + "p tagged_division_of {} \<longleftrightarrow> p = {}"
   5.728 +  unfolding tagged_division_of by auto
   5.729 +
   5.730 +lemma tagged_division_of_self:
   5.731 + "x \<in> {a..b} \<Longrightarrow> {(x,{a..b})} tagged_division_of {a..b}"
   5.732 +  apply(rule tagged_division_ofI) by auto
   5.733 +
   5.734 +lemma tagged_division_union:
   5.735 +  assumes "p1 tagged_division_of s1"  "p2 tagged_division_of s2" "interior s1 \<inter> interior s2 = {}"
   5.736 +  shows "(p1 \<union> p2) tagged_division_of (s1 \<union> s2)"
   5.737 +proof(rule tagged_division_ofI) note p1=tagged_division_ofD[OF assms(1)] and p2=tagged_division_ofD[OF assms(2)]
   5.738 +  show "finite (p1 \<union> p2)" using p1(1) p2(1) by auto
   5.739 +  show "\<Union>{k. \<exists>x. (x, k) \<in> p1 \<union> p2} = s1 \<union> s2" using p1(6) p2(6) by blast
   5.740 +  fix x k assume xk:"(x,k)\<in>p1\<union>p2" show "x\<in>k" "\<exists>a b. k = {a..b}" using xk p1(2,4) p2(2,4) by auto
   5.741 +  show "k\<subseteq>s1\<union>s2" using xk p1(3) p2(3) by blast
   5.742 +  fix x' k' assume xk':"(x',k')\<in>p1\<union>p2" "(x,k) \<noteq> (x',k')"
   5.743 +  have *:"\<And>a b. a\<subseteq> s1 \<Longrightarrow> b\<subseteq> s2 \<Longrightarrow> interior a \<inter> interior b = {}" using assms(3) subset_interior by blast
   5.744 +  show "interior k \<inter> interior k' = {}" apply(cases "(x,k)\<in>p1", case_tac[!] "(x',k')\<in>p1")
   5.745 +    apply(rule p1(5)) prefer 4 apply(rule *) prefer 6 apply(subst Int_commute,rule *) prefer 8 apply(rule p2(5))
   5.746 +    using p1(3) p2(3) using xk xk' by auto qed 
   5.747 +
   5.748 +lemma tagged_division_unions:
   5.749 +  assumes "finite iset" "\<forall>i\<in>iset. (pfn(i) tagged_division_of i)"
   5.750 +  "\<forall>i1 \<in> iset. \<forall>i2 \<in> iset. ~(i1 = i2) \<longrightarrow> (interior(i1) \<inter> interior(i2) = {})"
   5.751 +  shows "\<Union>(pfn ` iset) tagged_division_of (\<Union>iset)"
   5.752 +proof(rule tagged_division_ofI)
   5.753 +  note assm = tagged_division_ofD[OF assms(2)[rule_format]]
   5.754 +  show "finite (\<Union>pfn ` iset)" apply(rule finite_Union) using assms by auto
   5.755 +  have "\<Union>{k. \<exists>x. (x, k) \<in> \<Union>pfn ` iset} = \<Union>(\<lambda>i. \<Union>{k. \<exists>x. (x, k) \<in> pfn i}) ` iset" by blast 
   5.756 +  also have "\<dots> = \<Union>iset" using assm(6) by auto
   5.757 +  finally show "\<Union>{k. \<exists>x. (x, k) \<in> \<Union>pfn ` iset} = \<Union>iset" . 
   5.758 +  fix x k assume xk:"(x,k)\<in>\<Union>pfn ` iset" then obtain i where i:"i \<in> iset" "(x, k) \<in> pfn i" by auto
   5.759 +  show "x\<in>k" "\<exists>a b. k = {a..b}" "k \<subseteq> \<Union>iset" using assm(2-4)[OF i] using i(1) by auto
   5.760 +  fix x' k' assume xk':"(x',k')\<in>\<Union>pfn ` iset" "(x, k) \<noteq> (x', k')" then obtain i' where i':"i' \<in> iset" "(x', k') \<in> pfn i'" by auto
   5.761 +  have *:"\<And>a b. i\<noteq>i' \<Longrightarrow> a\<subseteq> i \<Longrightarrow> b\<subseteq> i' \<Longrightarrow> interior a \<inter> interior b = {}" using i(1) i'(1)
   5.762 +    using assms(3)[rule_format] subset_interior by blast
   5.763 +  show "interior k \<inter> interior k' = {}" apply(cases "i=i'")
   5.764 +    using assm(5)[OF i _ xk'(2)]  i'(2) using assm(3)[OF i] assm(3)[OF i'] defer apply-apply(rule *) by auto
   5.765 +qed
   5.766 +
   5.767 +lemma tagged_partial_division_of_union_self:
   5.768 +  assumes "p tagged_partial_division_of s" shows "p tagged_division_of (\<Union>(snd ` p))"
   5.769 +  apply(rule tagged_division_ofI) using tagged_partial_division_ofD[OF assms] by auto
   5.770 +
   5.771 +lemma tagged_division_of_union_self: assumes "p tagged_division_of s"
   5.772 +  shows "p tagged_division_of (\<Union>(snd ` p))"
   5.773 +  apply(rule tagged_division_ofI) using tagged_division_ofD[OF assms] by auto
   5.774 +
   5.775 +subsection {* Fine-ness of a partition w.r.t. a gauge. *}
   5.776 +
   5.777 +definition fine (infixr "fine" 46) where
   5.778 +  "d fine s \<longleftrightarrow> (\<forall>(x,k) \<in> s. k \<subseteq> d(x))"
   5.779 +
   5.780 +lemma fineI: assumes "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> d x"
   5.781 +  shows "d fine s" using assms unfolding fine_def by auto
   5.782 +
   5.783 +lemma fineD[dest]: assumes "d fine s"
   5.784 +  shows "\<And>x k. (x,k) \<in> s \<Longrightarrow> k \<subseteq> d x" using assms unfolding fine_def by auto
   5.785 +
   5.786 +lemma fine_inter: "(\<lambda>x. d1 x \<inter> d2 x) fine p \<longleftrightarrow> d1 fine p \<and> d2 fine p"
   5.787 +  unfolding fine_def by auto
   5.788 +
   5.789 +lemma fine_inters:
   5.790 + "(\<lambda>x. \<Inter> {f d x | d.  d \<in> s}) fine p \<longleftrightarrow> (\<forall>d\<in>s. (f d) fine p)"
   5.791 +  unfolding fine_def by blast
   5.792 +
   5.793 +lemma fine_union:
   5.794 +  "d fine p1 \<Longrightarrow> d fine p2 \<Longrightarrow> d fine (p1 \<union> p2)"
   5.795 +  unfolding fine_def by blast
   5.796 +
   5.797 +lemma fine_unions:"(\<And>p. p \<in> ps \<Longrightarrow> d fine p) \<Longrightarrow> d fine (\<Union>ps)"
   5.798 +  unfolding fine_def by auto
   5.799 +
   5.800 +lemma fine_subset:  "p \<subseteq> q \<Longrightarrow> d fine q \<Longrightarrow> d fine p"
   5.801 +  unfolding fine_def by blast
   5.802 +
   5.803 +subsection {* Gauge integral. Define on compact intervals first, then use a limit. *}
   5.804 +
   5.805 +definition has_integral_compact_interval (infixr "has'_integral'_compact'_interval" 46) where
   5.806 +  "(f has_integral_compact_interval y) i \<equiv>
   5.807 +        (\<forall>e>0. \<exists>d. gauge d \<and>
   5.808 +          (\<forall>p. p tagged_division_of i \<and> d fine p
   5.809 +                        \<longrightarrow> norm(setsum (\<lambda>(x,k). content k *\<^sub>R f x) p - y) < e))"
   5.810 +
   5.811 +definition has_integral (infixr "has'_integral" 46) where 
   5.812 +"((f::(real^'n \<Rightarrow> 'b::real_normed_vector)) has_integral y) i \<equiv>
   5.813 +        if (\<exists>a b. i = {a..b}) then (f has_integral_compact_interval y) i
   5.814 +        else (\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b}
   5.815 +              \<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> i then f x else 0) has_integral_compact_interval z) {a..b} \<and>
   5.816 +                                       norm(z - y) < e))"
   5.817 +
   5.818 +lemma has_integral:
   5.819 + "(f has_integral y) ({a..b}) \<longleftrightarrow>
   5.820 +        (\<forall>e>0. \<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p
   5.821 +                        \<longrightarrow> norm(setsum (\<lambda>(x,k). content(k) *\<^sub>R f x) p - y) < e))"
   5.822 +  unfolding has_integral_def has_integral_compact_interval_def by auto
   5.823 +
   5.824 +lemma has_integralD[dest]: assumes
   5.825 + "(f has_integral y) ({a..b})" "e>0"
   5.826 +  obtains d where "gauge d" "\<And>p. p tagged_division_of {a..b} \<Longrightarrow> d fine p
   5.827 +                        \<Longrightarrow> norm(setsum (\<lambda>(x,k). content(k) *\<^sub>R f(x)) p - y) < e"
   5.828 +  using assms unfolding has_integral by auto
   5.829 +
   5.830 +lemma has_integral_alt:
   5.831 + "(f has_integral y) i \<longleftrightarrow>
   5.832 +      (if (\<exists>a b. i = {a..b}) then (f has_integral y) i
   5.833 +       else (\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b}
   5.834 +                               \<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> i then f(x) else 0)
   5.835 +                                        has_integral z) ({a..b}) \<and>
   5.836 +                                       norm(z - y) < e)))"
   5.837 +  unfolding has_integral unfolding has_integral_compact_interval_def has_integral_def by auto
   5.838 +
   5.839 +lemma has_integral_altD:
   5.840 +  assumes "(f has_integral y) i" "\<not> (\<exists>a b. i = {a..b})" "e>0"
   5.841 +  obtains B where "B>0" "\<forall>a b. ball 0 B \<subseteq> {a..b}\<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> i then f(x) else 0) has_integral z) ({a..b}) \<and> norm(z - y) < e)"
   5.842 +  using assms unfolding has_integral unfolding has_integral_compact_interval_def has_integral_def by auto
   5.843 +
   5.844 +definition integrable_on (infixr "integrable'_on" 46) where
   5.845 +  "(f integrable_on i) \<equiv> \<exists>y. (f has_integral y) i"
   5.846 +
   5.847 +definition "integral i f \<equiv> SOME y. (f has_integral y) i"
   5.848 +
   5.849 +lemma integrable_integral[dest]:
   5.850 + "f integrable_on i \<Longrightarrow> (f has_integral (integral i f)) i"
   5.851 +  unfolding integrable_on_def integral_def by(rule someI_ex)
   5.852 +
   5.853 +lemma has_integral_integrable[intro]: "(f has_integral i) s \<Longrightarrow> f integrable_on s"
   5.854 +  unfolding integrable_on_def by auto
   5.855 +
   5.856 +lemma has_integral_integral:"f integrable_on s \<longleftrightarrow> (f has_integral (integral s f)) s"
   5.857 +  by auto
   5.858 +
   5.859 +lemma has_integral_vec1: assumes "(f has_integral k) {a..b}"
   5.860 +  shows "((\<lambda>x. vec1 (f x)) has_integral (vec1 k)) {a..b}"
   5.861 +proof- have *:"\<And>p. (\<Sum>(x, k)\<in>p. content k *\<^sub>R vec1 (f x)) - vec1 k = vec1 ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - k)"
   5.862 +    unfolding vec_sub Cart_eq by(auto simp add:vec1_dest_vec1_simps split_beta)
   5.863 +  show ?thesis using assms unfolding has_integral apply safe
   5.864 +    apply(erule_tac x=e in allE,safe) apply(rule_tac x=d in exI,safe)
   5.865 +    apply(erule_tac x=p in allE,safe) unfolding * norm_vector_1 by auto qed
   5.866 +
   5.867 +lemma setsum_content_null:
   5.868 +  assumes "content({a..b}) = 0" "p tagged_division_of {a..b}"
   5.869 +  shows "setsum (\<lambda>(x,k). content k *\<^sub>R f x) p = (0::'a::real_normed_vector)"
   5.870 +proof(rule setsum_0',rule) fix y assume y:"y\<in>p"
   5.871 +  obtain x k where xk:"y = (x,k)" using surj_pair[of y] by blast
   5.872 +  note assm = tagged_division_ofD(3-4)[OF assms(2) y[unfolded xk]]
   5.873 +  from this(2) guess c .. then guess d .. note c_d=this
   5.874 +  have "(\<lambda>(x, k). content k *\<^sub>R f x) y = content k *\<^sub>R f x" unfolding xk by auto
   5.875 +  also have "\<dots> = 0" using content_subset[OF assm(1)[unfolded c_d]] content_pos_le[of c d]
   5.876 +    unfolding assms(1) c_d by auto
   5.877 +  finally show "(\<lambda>(x, k). content k *\<^sub>R f x) y = 0" .
   5.878 +qed
   5.879 +
   5.880 +subsection {* Some basic combining lemmas. *}
   5.881 +
   5.882 +lemma tagged_division_unions_exists:
   5.883 +  assumes "finite iset" "\<forall>i \<in> iset. \<exists>p. p tagged_division_of i \<and> d fine p"
   5.884 +  "\<forall>i1\<in>iset. \<forall>i2\<in>iset. ~(i1 = i2) \<longrightarrow> (interior(i1) \<inter> interior(i2) = {})" "(\<Union>iset = i)"
   5.885 +   obtains p where "p tagged_division_of i" "d fine p"
   5.886 +proof- guess pfn using bchoice[OF assms(2)] .. note pfn = conjunctD2[OF this[rule_format]]
   5.887 +  show thesis apply(rule_tac p="\<Union>(pfn ` iset)" in that) unfolding assms(4)[THEN sym]
   5.888 +    apply(rule tagged_division_unions[OF assms(1) _ assms(3)]) defer 
   5.889 +    apply(rule fine_unions) using pfn by auto
   5.890 +qed
   5.891 +
   5.892 +subsection {* The set we're concerned with must be closed. *}
   5.893 +
   5.894 +lemma division_of_closed: "s division_of i \<Longrightarrow> closed (i::(real^'n) set)"
   5.895 +  unfolding division_of_def by(fastsimp intro!: closed_Union closed_interval)
   5.896 +
   5.897 +subsection {* General bisection principle for intervals; might be useful elsewhere. *}
   5.898 +
   5.899 +lemma interval_bisection_step:
   5.900 +  assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "~(P {a..b::real^'n})"
   5.901 +  obtains c d where "~(P{c..d})"
   5.902 +  "\<forall>i. a$i \<le> c$i \<and> c$i \<le> d$i \<and> d$i \<le> b$i \<and> 2 * (d$i - c$i) \<le> b$i - a$i"
   5.903 +proof- have "{a..b} \<noteq> {}" using assms(1,3) by auto
   5.904 +  note ab=this[unfolded interval_eq_empty not_ex not_less]
   5.905 +  { fix f have "finite f \<Longrightarrow>
   5.906 +        (\<forall>s\<in>f. P s) \<Longrightarrow>
   5.907 +        (\<forall>s\<in>f. \<exists>a b. s = {a..b}) \<Longrightarrow>
   5.908 +        (\<forall>s\<in>f.\<forall>t\<in>f. ~(s = t) \<longrightarrow> interior(s) \<inter> interior(t) = {}) \<Longrightarrow> P(\<Union>f)"
   5.909 +    proof(induct f rule:finite_induct)
   5.910 +      case empty show ?case using assms(1) by auto
   5.911 +    next case (insert x f) show ?case unfolding Union_insert apply(rule assms(2)[rule_format])
   5.912 +        apply rule defer apply rule defer apply(rule inter_interior_unions_intervals)
   5.913 +        using insert by auto
   5.914 +    qed } note * = this
   5.915 +  let ?A = "{{c..d} | c d. \<forall>i. (c$i = a$i) \<and> (d$i = (a$i + b$i) / 2) \<or> (c$i = (a$i + b$i) / 2) \<and> (d$i = b$i)}"
   5.916 +  let ?PP = "\<lambda>c d. \<forall>i. a$i \<le> c$i \<and> c$i \<le> d$i \<and> d$i \<le> b$i \<and> 2 * (d$i - c$i) \<le> b$i - a$i"
   5.917 +  { presume "\<forall>c d. ?PP c d \<longrightarrow> P {c..d} \<Longrightarrow> False"
   5.918 +    thus thesis unfolding atomize_not not_all apply-apply(erule exE)+ apply(rule_tac c=x and d=xa in that) by auto }
   5.919 +  assume as:"\<forall>c d. ?PP c d \<longrightarrow> P {c..d}"
   5.920 +  have "P (\<Union> ?A)" proof(rule *, rule_tac[2-] ballI, rule_tac[4] ballI, rule_tac[4] impI) 
   5.921 +    let ?B = "(\<lambda>s.{(\<chi> i. if i \<in> s then a$i else (a$i + b$i) / 2) ..
   5.922 +      (\<chi> i. if i \<in> s then (a$i + b$i) / 2 else b$i)}) ` {s. s \<subseteq> UNIV}"
   5.923 +    have "?A \<subseteq> ?B" proof case goal1
   5.924 +      then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+) note c_d=this[rule_format]
   5.925 +      have *:"\<And>a b c d. a = c \<Longrightarrow> b = d \<Longrightarrow> {a..b} = {c..d}" by auto
   5.926 +      show "x\<in>?B" unfolding image_iff apply(rule_tac x="{i. c$i = a$i}" in bexI)
   5.927 +        unfolding c_d apply(rule * ) unfolding Cart_eq cond_component Cart_lambda_beta
   5.928 +      proof(rule_tac[1-2] allI) fix i show "c $ i = (if i \<in> {i. c $ i = a $ i} then a $ i else (a $ i + b $ i) / 2)"
   5.929 +          "d $ i = (if i \<in> {i. c $ i = a $ i} then (a $ i + b $ i) / 2 else b $ i)"
   5.930 +          using c_d(2)[of i] ab[THEN spec[where x=i]] by(auto simp add:field_simps)
   5.931 +      qed auto qed
   5.932 +    thus "finite ?A" apply(rule finite_subset[of _ ?B]) by auto
   5.933 +    fix s assume "s\<in>?A" then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+)
   5.934 +    note c_d=this[rule_format]
   5.935 +    show "P s" unfolding c_d apply(rule as[rule_format]) proof- case goal1 show ?case 
   5.936 +        using c_d(2)[of i] using ab[THEN spec[where x=i]] by auto qed
   5.937 +    show "\<exists>a b. s = {a..b}" unfolding c_d by auto
   5.938 +    fix t assume "t\<in>?A" then guess e unfolding mem_Collect_eq .. then guess f apply- by(erule exE,(erule conjE)+)
   5.939 +    note e_f=this[rule_format]
   5.940 +    assume "s \<noteq> t" hence "\<not> (c = e \<and> d = f)" unfolding c_d e_f by auto
   5.941 +    then obtain i where "c$i \<noteq> e$i \<or> d$i \<noteq> f$i" unfolding de_Morgan_conj Cart_eq by auto
   5.942 +    hence i:"c$i \<noteq> e$i" "d$i \<noteq> f$i" apply- apply(erule_tac[!] disjE)
   5.943 +    proof- assume "c$i \<noteq> e$i" thus "d$i \<noteq> f$i" using c_d(2)[of i] e_f(2)[of i] by fastsimp
   5.944 +    next   assume "d$i \<noteq> f$i" thus "c$i \<noteq> e$i" using c_d(2)[of i] e_f(2)[of i] by fastsimp
   5.945 +    qed have *:"\<And>s t. (\<And>a. a\<in>s \<Longrightarrow> a\<in>t \<Longrightarrow> False) \<Longrightarrow> s \<inter> t = {}" by auto
   5.946 +    show "interior s \<inter> interior t = {}" unfolding e_f c_d interior_closed_interval proof(rule *)
   5.947 +      fix x assume "x\<in>{c<..<d}" "x\<in>{e<..<f}"
   5.948 +      hence x:"c$i < d$i" "e$i < f$i" "c$i < f$i" "e$i < d$i" unfolding mem_interval apply-apply(erule_tac[!] x=i in allE)+ by auto
   5.949 +      show False using c_d(2)[of i] apply- apply(erule_tac disjE)
   5.950 +      proof(erule_tac[!] conjE) assume as:"c $ i = a $ i" "d $ i = (a $ i + b $ i) / 2"
   5.951 +        show False using e_f(2)[of i] and i x unfolding as by(fastsimp simp add:field_simps)
   5.952 +      next assume as:"c $ i = (a $ i + b $ i) / 2" "d $ i = b $ i"
   5.953 +        show False using e_f(2)[of i] and i x unfolding as by(fastsimp simp add:field_simps)
   5.954 +      qed qed qed
   5.955 +  also have "\<Union> ?A = {a..b}" proof(rule set_ext,rule)
   5.956 +    fix x assume "x\<in>\<Union>?A" then guess Y unfolding Union_iff ..
   5.957 +    from this(1) guess c unfolding mem_Collect_eq .. then guess d ..
   5.958 +    note c_d = this[THEN conjunct2,rule_format] `x\<in>Y`[unfolded this[THEN conjunct1]]
   5.959 +    show "x\<in>{a..b}" unfolding mem_interval proof 
   5.960 +      fix i show "a $ i \<le> x $ i \<and> x $ i \<le> b $ i"
   5.961 +        using c_d(1)[of i] c_d(2)[unfolded mem_interval,THEN spec[where x=i]] by auto qed
   5.962 +  next fix x assume x:"x\<in>{a..b}"
   5.963 +    have "\<forall>i. \<exists>c d. (c = a$i \<and> d = (a$i + b$i) / 2 \<or> c = (a$i + b$i) / 2 \<and> d = b$i) \<and> c\<le>x$i \<and> x$i \<le> d"
   5.964 +      (is "\<forall>i. \<exists>c d. ?P i c d") unfolding mem_interval proof fix i
   5.965 +      have "?P i (a$i) ((a $ i + b $ i) / 2) \<or> ?P i ((a $ i + b $ i) / 2) (b$i)"
   5.966 +        using x[unfolded mem_interval,THEN spec[where x=i]] by auto thus "\<exists>c d. ?P i c d" by blast
   5.967 +    qed thus "x\<in>\<Union>?A" unfolding Union_iff lambda_skolem unfolding Bex_def mem_Collect_eq
   5.968 +      apply-apply(erule exE)+ apply(rule_tac x="{xa..xaa}" in exI) unfolding mem_interval by auto
   5.969 +  qed finally show False using assms by auto qed
   5.970 +
   5.971 +lemma interval_bisection:
   5.972 +  assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "\<not> P {a..b::real^'n}"
   5.973 +  obtains x where "x \<in> {a..b}" "\<forall>e>0. \<exists>c d. x \<in> {c..d} \<and> {c..d} \<subseteq> ball x e \<and> {c..d} \<subseteq> {a..b} \<and> ~P({c..d})"
   5.974 +proof-
   5.975 +  have "\<forall>x. \<exists>y. \<not> P {fst x..snd x} \<longrightarrow> (\<not> P {fst y..snd y} \<and> (\<forall>i. fst x$i \<le> fst y$i \<and> fst y$i \<le> snd y$i \<and> snd y$i \<le> snd x$i \<and>
   5.976 +                           2 * (snd y$i - fst y$i) \<le> snd x$i - fst x$i))" proof case goal1 thus ?case proof-
   5.977 +      presume "\<not> P {fst x..snd x} \<Longrightarrow> ?thesis"
   5.978 +      thus ?thesis apply(cases "P {fst x..snd x}") by auto
   5.979 +    next assume as:"\<not> P {fst x..snd x}" from interval_bisection_step[of P, OF assms(1-2) as] guess c d . 
   5.980 +      thus ?thesis apply- apply(rule_tac x="(c,d)" in exI) by auto
   5.981 +    qed qed then guess f apply-apply(drule choice) by(erule exE) note f=this
   5.982 +  def AB \<equiv> "\<lambda>n. (f ^^ n) (a,b)" def A \<equiv> "\<lambda>n. fst(AB n)" and B \<equiv> "\<lambda>n. snd(AB n)" note ab_def = this AB_def
   5.983 +  have "A 0 = a" "B 0 = b" "\<And>n. \<not> P {A(Suc n)..B(Suc n)} \<and>
   5.984 +    (\<forall>i. A(n)$i \<le> A(Suc n)$i \<and> A(Suc n)$i \<le> B(Suc n)$i \<and> B(Suc n)$i \<le> B(n)$i \<and> 
   5.985 +    2 * (B(Suc n)$i - A(Suc n)$i) \<le> B(n)$i - A(n)$i)" (is "\<And>n. ?P n")
   5.986 +  proof- show "A 0 = a" "B 0 = b" unfolding ab_def by auto
   5.987 +    case goal3 note S = ab_def funpow.simps o_def id_apply show ?case
   5.988 +    proof(induct n) case 0 thus ?case unfolding S apply(rule f[rule_format]) using assms(3) by auto
   5.989 +    next case (Suc n) show ?case unfolding S apply(rule f[rule_format]) using Suc unfolding S by auto
   5.990 +    qed qed note AB = this(1-2) conjunctD2[OF this(3),rule_format]
   5.991 +
   5.992 +  have interv:"\<And>e. 0 < e \<Longrightarrow> \<exists>n. \<forall>x\<in>{A n..B n}. \<forall>y\<in>{A n..B n}. dist x y < e"
   5.993 +  proof- case goal1 guess n using real_arch_pow2[of "(setsum (\<lambda>i. b$i - a$i) UNIV) / e"] .. note n=this
   5.994 +    show ?case apply(rule_tac x=n in exI) proof(rule,rule)
   5.995 +      fix x y assume xy:"x\<in>{A n..B n}" "y\<in>{A n..B n}"
   5.996 +      have "dist x y \<le> setsum (\<lambda>i. abs((x - y)$i)) UNIV" unfolding vector_dist_norm by(rule norm_le_l1)
   5.997 +      also have "\<dots> \<le> setsum (\<lambda>i. B n$i - A n$i) UNIV"
   5.998 +      proof(rule setsum_mono) fix i show "\<bar>(x - y) $ i\<bar> \<le> B n $ i - A n $ i"
   5.999 +          using xy[unfolded mem_interval,THEN spec[where x=i]]
  5.1000 +          unfolding vector_minus_component by auto qed
  5.1001 +      also have "\<dots> \<le> setsum (\<lambda>i. b$i - a$i) UNIV / 2^n" unfolding setsum_divide_distrib
  5.1002 +      proof(rule setsum_mono) case goal1 thus ?case
  5.1003 +        proof(induct n) case 0 thus ?case unfolding AB by auto
  5.1004 +        next case (Suc n) have "B (Suc n) $ i - A (Suc n) $ i \<le> (B n $ i - A n $ i) / 2" using AB(4)[of n i] by auto
  5.1005 +          also have "\<dots> \<le> (b $ i - a $ i) / 2 ^ Suc n" using Suc by(auto simp add:field_simps) finally show ?case .
  5.1006 +        qed qed
  5.1007 +      also have "\<dots> < e" using n using goal1 by(auto simp add:field_simps) finally show "dist x y < e" .
  5.1008 +    qed qed
  5.1009 +  { fix n m ::nat assume "m \<le> n" then guess d unfolding le_Suc_ex_iff .. note d=this
  5.1010 +    have "{A n..B n} \<subseteq> {A m..B m}" unfolding d 
  5.1011 +    proof(induct d) case 0 thus ?case by auto
  5.1012 +    next case (Suc d) show ?case apply(rule subset_trans[OF _ Suc])
  5.1013 +        apply(rule) unfolding mem_interval apply(rule,erule_tac x=i in allE)
  5.1014 +      proof- case goal1 thus ?case using AB(4)[of "m + d" i] by(auto simp add:field_simps)
  5.1015 +      qed qed } note ABsubset = this 
  5.1016 +  have "\<exists>a. \<forall>n. a\<in>{A n..B n}" apply(rule decreasing_closed_nest[rule_format,OF closed_interval _ ABsubset interv])
  5.1017 +  proof- fix n show "{A n..B n} \<noteq> {}" apply(cases "0<n") using AB(3)[of "n - 1"] assms(1,3) AB(1-2) by auto qed auto
  5.1018 +  then guess x0 .. note x0=this[rule_format]
  5.1019 +  show thesis proof(rule that[rule_format,of x0])
  5.1020 +    show "x0\<in>{a..b}" using x0[of 0] unfolding AB .
  5.1021 +    fix e assume "0 < (e::real)" from interv[OF this] guess n .. note n=this
  5.1022 +    show "\<exists>c d. x0 \<in> {c..d} \<and> {c..d} \<subseteq> ball x0 e \<and> {c..d} \<subseteq> {a..b} \<and> \<not> P {c..d}"
  5.1023 +      apply(rule_tac x="A n" in exI,rule_tac x="B n" in exI) apply(rule,rule x0) apply rule defer 
  5.1024 +    proof show "\<not> P {A n..B n}" apply(cases "0<n") using AB(3)[of "n - 1"] assms(3) AB(1-2) by auto
  5.1025 +      show "{A n..B n} \<subseteq> ball x0 e" using n using x0[of n] by auto
  5.1026 +      show "{A n..B n} \<subseteq> {a..b}" unfolding AB(1-2)[symmetric] apply(rule ABsubset) by auto
  5.1027 +    qed qed qed 
  5.1028 +
  5.1029 +subsection {* Cousin's lemma. *}
  5.1030 +
  5.1031 +lemma fine_division_exists: assumes "gauge g" 
  5.1032 +  obtains p where "p tagged_division_of {a..b::real^'n}" "g fine p"
  5.1033 +proof- presume "\<not> (\<exists>p. p tagged_division_of {a..b} \<and> g fine p) \<Longrightarrow> False"
  5.1034 +  then guess p unfolding atomize_not not_not .. thus thesis apply-apply(rule that[of p]) by auto
  5.1035 +next assume as:"\<not> (\<exists>p. p tagged_division_of {a..b} \<and> g fine p)"
  5.1036 +  guess x apply(rule interval_bisection[of "\<lambda>s. \<exists>p. p tagged_division_of s \<and> g fine p",rule_format,OF _ _ as])
  5.1037 +    apply(rule_tac x="{}" in exI) defer apply(erule conjE exE)+
  5.1038 +  proof- show "{} tagged_division_of {} \<and> g fine {}" unfolding fine_def by auto
  5.1039 +    fix s t p p' assume "p tagged_division_of s" "g fine p" "p' tagged_division_of t" "g fine p'" "interior s \<inter> interior t = {}"
  5.1040 +    thus "\<exists>p. p tagged_division_of s \<union> t \<and> g fine p" apply-apply(rule_tac x="p \<union> p'" in exI) apply rule
  5.1041 +      apply(rule tagged_division_union) prefer 4 apply(rule fine_union) by auto
  5.1042 +  qed note x=this
  5.1043 +  obtain e where e:"e>0" "ball x e \<subseteq> g x" using gaugeD[OF assms, of x] unfolding open_contains_ball by auto
  5.1044 +  from x(2)[OF e(1)] guess c d apply-apply(erule exE conjE)+ . note c_d = this
  5.1045 +  have "g fine {(x, {c..d})}" unfolding fine_def using e using c_d(2) by auto
  5.1046 +  thus False using tagged_division_of_self[OF c_d(1)] using c_d by auto qed
  5.1047 +
  5.1048 +subsection {* Basic theorems about integrals. *}
  5.1049 +
  5.1050 +lemma has_integral_unique: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  5.1051 +  assumes "(f has_integral k1) i" "(f has_integral k2) i" shows "k1 = k2"
  5.1052 +proof(rule ccontr) let ?e = "norm(k1 - k2) / 2" assume as:"k1 \<noteq> k2" hence e:"?e > 0" by auto
  5.1053 +  have lem:"\<And>f::real^'n \<Rightarrow> 'a.  \<And> a b k1 k2.
  5.1054 +    (f has_integral k1) ({a..b}) \<Longrightarrow> (f has_integral k2) ({a..b}) \<Longrightarrow> k1 \<noteq> k2 \<Longrightarrow> False"
  5.1055 +  proof- case goal1 let ?e = "norm(k1 - k2) / 2" from goal1(3) have e:"?e > 0" by auto
  5.1056 +    guess d1 by(rule has_integralD[OF goal1(1) e]) note d1=this
  5.1057 +    guess d2 by(rule has_integralD[OF goal1(2) e]) note d2=this
  5.1058 +    guess p by(rule fine_division_exists[OF gauge_inter[OF d1(1) d2(1)],of a b]) note p=this
  5.1059 +    let ?c = "(\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)" have "norm (k1 - k2) \<le> norm (?c - k2) + norm (?c - k1)"
  5.1060 +      using norm_triangle_ineq4[of "k1 - ?c" "k2 - ?c"] by(auto simp add:group_simps norm_minus_commute)
  5.1061 +    also have "\<dots> < norm (k1 - k2) / 2 + norm (k1 - k2) / 2"
  5.1062 +      apply(rule add_strict_mono) apply(rule_tac[!] d2(2) d1(2)) using p unfolding fine_def by auto
  5.1063 +    finally show False by auto
  5.1064 +  qed { presume "\<not> (\<exists>a b. i = {a..b}) \<Longrightarrow> False"
  5.1065 +    thus False apply-apply(cases "\<exists>a b. i = {a..b}")
  5.1066 +      using assms by(auto simp add:has_integral intro:lem[OF _ _ as]) }
  5.1067 +  assume as:"\<not> (\<exists>a b. i = {a..b})"
  5.1068 +  guess B1 by(rule has_integral_altD[OF assms(1) as,OF e]) note B1=this[rule_format]
  5.1069 +  guess B2 by(rule has_integral_altD[OF assms(2) as,OF e]) note B2=this[rule_format]
  5.1070 +  have "\<exists>a b::real^'n. ball 0 B1 \<union> ball 0 B2 \<subseteq> {a..b}" apply(rule bounded_subset_closed_interval)
  5.1071 +    using bounded_Un bounded_ball by auto then guess a b apply-by(erule exE)+
  5.1072 +  note ab=conjunctD2[OF this[unfolded Un_subset_iff]]
  5.1073 +  guess w using B1(2)[OF ab(1)] .. note w=conjunctD2[OF this]
  5.1074 +  guess z using B2(2)[OF ab(2)] .. note z=conjunctD2[OF this]
  5.1075 +  have "z = w" using lem[OF w(1) z(1)] by auto
  5.1076 +  hence "norm (k1 - k2) \<le> norm (z - k2) + norm (w - k1)"
  5.1077 +    using norm_triangle_ineq4[of "k1 - w" "k2 - z"] by(auto simp add: norm_minus_commute) 
  5.1078 +  also have "\<dots> < norm (k1 - k2) / 2 + norm (k1 - k2) / 2" apply(rule add_strict_mono) by(rule_tac[!] z(2) w(2))
  5.1079 +  finally show False by auto qed
  5.1080 +
  5.1081 +lemma integral_unique[intro]:
  5.1082 +  "(f has_integral y) k \<Longrightarrow> integral k f = y"
  5.1083 +  unfolding integral_def apply(rule some_equality) by(auto intro: has_integral_unique) 
  5.1084 +
  5.1085 +lemma has_integral_is_0: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector" 
  5.1086 +  assumes "\<forall>x\<in>s. f x = 0" shows "(f has_integral 0) s"
  5.1087 +proof- have lem:"\<And>a b. \<And>f::real^'n \<Rightarrow> 'a.
  5.1088 +    (\<forall>x\<in>{a..b}. f(x) = 0) \<Longrightarrow> (f has_integral 0) ({a..b})" unfolding has_integral
  5.1089 +  proof(rule,rule) fix a b e and f::"real^'n \<Rightarrow> 'a"
  5.1090 +    assume as:"\<forall>x\<in>{a..b}. f x = 0" "0 < (e::real)"
  5.1091 +    show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) < e)"
  5.1092 +      apply(rule_tac x="\<lambda>x. ball x 1" in exI)  apply(rule,rule gaugeI) unfolding centre_in_ball defer apply(rule open_ball)
  5.1093 +    proof(rule,rule,erule conjE) case goal1
  5.1094 +      have "(\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) = 0" proof(rule setsum_0',rule)
  5.1095 +        fix x assume x:"x\<in>p" have "f (fst x) = 0" using tagged_division_ofD(2-3)[OF goal1(1), of "fst x" "snd x"] using as x by auto
  5.1096 +        thus "(\<lambda>(x, k). content k *\<^sub>R f x) x = 0" apply(subst surjective_pairing[of x]) unfolding split_conv by auto
  5.1097 +      qed thus ?case using as by auto
  5.1098 +    qed auto qed  { presume "\<not> (\<exists>a b. s = {a..b}) \<Longrightarrow> ?thesis"
  5.1099 +    thus ?thesis apply-apply(cases "\<exists>a b. s = {a..b}")
  5.1100 +      using assms by(auto simp add:has_integral intro:lem) }
  5.1101 +  have *:"(\<lambda>x. if x \<in> s then f x else 0) = (\<lambda>x. 0)" apply(rule ext) using assms by auto
  5.1102 +  assume "\<not> (\<exists>a b. s = {a..b})" thus ?thesis apply(subst has_integral_alt) unfolding if_not_P *
  5.1103 +  apply(rule,rule,rule_tac x=1 in exI,rule) defer apply(rule,rule,rule)
  5.1104 +  proof- fix e::real and a b assume "e>0"
  5.1105 +    thus "\<exists>z. ((\<lambda>x::real^'n. 0::'a) has_integral z) {a..b} \<and> norm (z - 0) < e"
  5.1106 +      apply(rule_tac x=0 in exI) apply(rule,rule lem) by auto
  5.1107 +  qed auto qed
  5.1108 +
  5.1109 +lemma has_integral_0[simp]: "((\<lambda>x::real^'n. 0) has_integral 0) s"
  5.1110 +  apply(rule has_integral_is_0) by auto 
  5.1111 +
  5.1112 +lemma has_integral_0_eq[simp]: "((\<lambda>x. 0) has_integral i) s \<longleftrightarrow> i = 0"
  5.1113 +  using has_integral_unique[OF has_integral_0] by auto
  5.1114 +
  5.1115 +lemma has_integral_linear: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  5.1116 +  assumes "(f has_integral y) s" "bounded_linear h" shows "((h o f) has_integral ((h y))) s"
  5.1117 +proof- interpret bounded_linear h using assms(2) . from pos_bounded guess B .. note B=conjunctD2[OF this,rule_format]
  5.1118 +  have lem:"\<And>f::real^'n \<Rightarrow> 'a. \<And> y a b.
  5.1119 +    (f has_integral y) ({a..b}) \<Longrightarrow> ((h o f) has_integral h(y)) ({a..b})"
  5.1120 +  proof(subst has_integral,rule,rule) case goal1
  5.1121 +    from pos_bounded guess B .. note B=conjunctD2[OF this,rule_format]
  5.1122 +    have *:"e / B > 0" apply(rule divide_pos_pos) using goal1(2) B by auto
  5.1123 +    guess g using has_integralD[OF goal1(1) *] . note g=this
  5.1124 +    show ?case apply(rule_tac x=g in exI) apply(rule,rule g(1))
  5.1125 +    proof(rule,rule,erule conjE) fix p assume as:"p tagged_division_of {a..b}" "g fine p" 
  5.1126 +      have *:"\<And>x k. h ((\<lambda>(x, k). content k *\<^sub>R f x) x) = (\<lambda>(x, k). h (content k *\<^sub>R f x)) x" by auto
  5.1127 +      have "(\<Sum>(x, k)\<in>p. content k *\<^sub>R (h \<circ> f) x) = setsum (h \<circ> (\<lambda>(x, k). content k *\<^sub>R f x)) p"
  5.1128 +        unfolding o_def unfolding scaleR[THEN sym] * by simp
  5.1129 +      also have "\<dots> = h (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)" using setsum[of "\<lambda>(x,k). content k *\<^sub>R f x" p] using as by auto
  5.1130 +      finally have *:"(\<Sum>(x, k)\<in>p. content k *\<^sub>R (h \<circ> f) x) = h (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)" .
  5.1131 +      show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R (h \<circ> f) x) - h y) < e" unfolding * diff[THEN sym]
  5.1132 +        apply(rule le_less_trans[OF B(2)]) using g(2)[OF as] B(1) by(auto simp add:field_simps)
  5.1133 +    qed qed { presume "\<not> (\<exists>a b. s = {a..b}) \<Longrightarrow> ?thesis"
  5.1134 +    thus ?thesis apply-apply(cases "\<exists>a b. s = {a..b}") using assms by(auto simp add:has_integral intro!:lem) }
  5.1135 +  assume as:"\<not> (\<exists>a b. s = {a..b})" thus ?thesis apply(subst has_integral_alt) unfolding if_not_P
  5.1136 +  proof(rule,rule) fix e::real  assume e:"0<e"
  5.1137 +    have *:"0 < e/B" by(rule divide_pos_pos,rule e,rule B(1))
  5.1138 +    guess M using has_integral_altD[OF assms(1) as *,rule_format] . note M=this
  5.1139 +    show "\<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b} \<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> s then (h \<circ> f) x else 0) has_integral z) {a..b} \<and> norm (z - h y) < e)"
  5.1140 +      apply(rule_tac x=M in exI) apply(rule,rule M(1))
  5.1141 +    proof(rule,rule,rule) case goal1 guess z using M(2)[OF goal1(1)] .. note z=conjunctD2[OF this]
  5.1142 +      have *:"(\<lambda>x. if x \<in> s then (h \<circ> f) x else 0) = h \<circ> (\<lambda>x. if x \<in> s then f x else 0)"
  5.1143 +        unfolding o_def apply(rule ext) using zero by auto
  5.1144 +      show ?case apply(rule_tac x="h z" in exI,rule) unfolding * apply(rule lem[OF z(1)]) unfolding diff[THEN sym]
  5.1145 +        apply(rule le_less_trans[OF B(2)]) using B(1) z(2) by(auto simp add:field_simps)
  5.1146 +    qed qed qed
  5.1147 +
  5.1148 +lemma has_integral_cmul:
  5.1149 +  shows "(f has_integral k) s \<Longrightarrow> ((\<lambda>x. c *\<^sub>R f x) has_integral (c *\<^sub>R k)) s"
  5.1150 +  unfolding o_def[THEN sym] apply(rule has_integral_linear,assumption)
  5.1151 +  by(rule scaleR.bounded_linear_right)
  5.1152 +
  5.1153 +lemma has_integral_neg:
  5.1154 +  shows "(f has_integral k) s \<Longrightarrow> ((\<lambda>x. -(f x)) has_integral (-k)) s"
  5.1155 +  apply(drule_tac c="-1" in has_integral_cmul) by auto
  5.1156 +
  5.1157 +lemma has_integral_add: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector" 
  5.1158 +  assumes "(f has_integral k) s" "(g has_integral l) s"
  5.1159 +  shows "((\<lambda>x. f x + g x) has_integral (k + l)) s"
  5.1160 +proof- have lem:"\<And>f g::real^'n \<Rightarrow> 'a. \<And>a b k l.
  5.1161 +    (f has_integral k) ({a..b}) \<Longrightarrow> (g has_integral l) ({a..b}) \<Longrightarrow>
  5.1162 +     ((\<lambda>x. f(x) + g(x)) has_integral (k + l)) ({a..b})" proof- case goal1
  5.1163 +    show ?case unfolding has_integral proof(rule,rule) fix e::real assume e:"e>0" hence *:"e/2>0" by auto
  5.1164 +      guess d1 using has_integralD[OF goal1(1) *] . note d1=this
  5.1165 +      guess d2 using has_integralD[OF goal1(2) *] . note d2=this
  5.1166 +      show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R (f x + g x)) - (k + l)) < e)"
  5.1167 +        apply(rule_tac x="\<lambda>x. (d1 x) \<inter> (d2 x)" in exI) apply(rule,rule gauge_inter[OF d1(1) d2(1)])
  5.1168 +      proof(rule,rule,erule conjE) fix p assume as:"p tagged_division_of {a..b}" "(\<lambda>x. d1 x \<inter> d2 x) fine p"
  5.1169 +        have *:"(\<Sum>(x, k)\<in>p. content k *\<^sub>R (f x + g x)) = (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>p. content k *\<^sub>R g x)"
  5.1170 +          unfolding scaleR_right_distrib setsum_addf[of "\<lambda>(x,k). content k *\<^sub>R f x" "\<lambda>(x,k). content k *\<^sub>R g x" p,THEN sym]
  5.1171 +          by(rule setsum_cong2,auto)
  5.1172 +        have "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R (f x + g x)) - (k + l)) = norm (((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - k) + ((\<Sum>(x, k)\<in>p. content k *\<^sub>R g x) - l))"
  5.1173 +          unfolding * by(auto simp add:group_simps) also let ?res = "\<dots>"
  5.1174 +        from as have *:"d1 fine p" "d2 fine p" unfolding fine_inter by auto
  5.1175 +        have "?res < e/2 + e/2" apply(rule le_less_trans[OF norm_triangle_ineq])
  5.1176 +          apply(rule add_strict_mono) using d1(2)[OF as(1) *(1)] and d2(2)[OF as(1) *(2)] by auto
  5.1177 +        finally show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R (f x + g x)) - (k + l)) < e" by auto
  5.1178 +      qed qed qed { presume "\<not> (\<exists>a b. s = {a..b}) \<Longrightarrow> ?thesis"
  5.1179 +    thus ?thesis apply-apply(cases "\<exists>a b. s = {a..b}") using assms by(auto simp add:has_integral intro!:lem) }
  5.1180 +  assume as:"\<not> (\<exists>a b. s = {a..b})" thus ?thesis apply(subst has_integral_alt) unfolding if_not_P
  5.1181 +  proof(rule,rule) case goal1 hence *:"e/2 > 0" by auto
  5.1182 +    from has_integral_altD[OF assms(1) as *] guess B1 . note B1=this[rule_format]
  5.1183 +    from has_integral_altD[OF assms(2) as *] guess B2 . note B2=this[rule_format]
  5.1184 +    show ?case apply(rule_tac x="max B1 B2" in exI) apply(rule,rule min_max.less_supI1,rule B1)
  5.1185 +    proof(rule,rule,rule) fix a b assume "ball 0 (max B1 B2) \<subseteq> {a..b::real^'n}"
  5.1186 +      hence *:"ball 0 B1 \<subseteq> {a..b::real^'n}" "ball 0 B2 \<subseteq> {a..b::real^'n}" by auto
  5.1187 +      guess w using B1(2)[OF *(1)] .. note w=conjunctD2[OF this]
  5.1188 +      guess z using B2(2)[OF *(2)] .. note z=conjunctD2[OF this]
  5.1189 +      have *:"\<And>x. (if x \<in> s then f x + g x else 0) = (if x \<in> s then f x else 0) + (if x \<in> s then g x else 0)" by auto
  5.1190 +      show "\<exists>z. ((\<lambda>x. if x \<in> s then f x + g x else 0) has_integral z) {a..b} \<and> norm (z - (k + l)) < e"
  5.1191 +        apply(rule_tac x="w + z" in exI) apply(rule,rule lem[OF w(1) z(1), unfolded *[THEN sym]])
  5.1192 +        using norm_triangle_ineq[of "w - k" "z - l"] w(2) z(2) by(auto simp add:field_simps)
  5.1193 +    qed qed qed
  5.1194 +
  5.1195 +lemma has_integral_sub:
  5.1196 +  shows "(f has_integral k) s \<Longrightarrow> (g has_integral l) s \<Longrightarrow> ((\<lambda>x. f(x) - g(x)) has_integral (k - l)) s"
  5.1197 +  using has_integral_add[OF _ has_integral_neg,of f k s g l] unfolding group_simps by auto
  5.1198 +
  5.1199 +lemma integral_0: "integral s (\<lambda>x::real^'n. 0::real^'m) = 0"
  5.1200 +  by(rule integral_unique has_integral_0)+
  5.1201 +
  5.1202 +lemma integral_add:
  5.1203 +  shows "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow>
  5.1204 +   integral s (\<lambda>x. f x + g x) = integral s f + integral s g"
  5.1205 +  apply(rule integral_unique) apply(drule integrable_integral)+
  5.1206 +  apply(rule has_integral_add) by assumption+
  5.1207 +
  5.1208 +lemma integral_cmul:
  5.1209 +  shows "f integrable_on s \<Longrightarrow> integral s (\<lambda>x. c *\<^sub>R f x) = c *\<^sub>R integral s f"
  5.1210 +  apply(rule integral_unique) apply(drule integrable_integral)+
  5.1211 +  apply(rule has_integral_cmul) by assumption+
  5.1212 +
  5.1213 +lemma integral_neg:
  5.1214 +  shows "f integrable_on s \<Longrightarrow> integral s (\<lambda>x. - f x) = - integral s f"
  5.1215 +  apply(rule integral_unique) apply(drule integrable_integral)+
  5.1216 +  apply(rule has_integral_neg) by assumption+
  5.1217 +
  5.1218 +lemma integral_sub:
  5.1219 +  shows "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow> integral s (\<lambda>x. f x - g x) = integral s f - integral s g"
  5.1220 +  apply(rule integral_unique) apply(drule integrable_integral)+
  5.1221 +  apply(rule has_integral_sub) by assumption+
  5.1222 +
  5.1223 +lemma integrable_0: "(\<lambda>x. 0) integrable_on s"
  5.1224 +  unfolding integrable_on_def using has_integral_0 by auto
  5.1225 +
  5.1226 +lemma integrable_add:
  5.1227 +  shows "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow> (\<lambda>x. f x + g x) integrable_on s"
  5.1228 +  unfolding integrable_on_def by(auto intro: has_integral_add)
  5.1229 +
  5.1230 +lemma integrable_cmul:
  5.1231 +  shows "f integrable_on s \<Longrightarrow> (\<lambda>x. c *\<^sub>R f(x)) integrable_on s"
  5.1232 +  unfolding integrable_on_def by(auto intro: has_integral_cmul)
  5.1233 +
  5.1234 +lemma integrable_neg:
  5.1235 +  shows "f integrable_on s \<Longrightarrow> (\<lambda>x. -f(x)) integrable_on s"
  5.1236 +  unfolding integrable_on_def by(auto intro: has_integral_neg)
  5.1237 +
  5.1238 +lemma integrable_sub:
  5.1239 +  shows "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow> (\<lambda>x. f x - g x) integrable_on s"
  5.1240 +  unfolding integrable_on_def by(auto intro: has_integral_sub)
  5.1241 +
  5.1242 +lemma integrable_linear:
  5.1243 +  shows "f integrable_on s \<Longrightarrow> bounded_linear h \<Longrightarrow> (h o f) integrable_on s"
  5.1244 +  unfolding integrable_on_def by(auto intro: has_integral_linear)
  5.1245 +
  5.1246 +lemma integral_linear:
  5.1247 +  shows "f integrable_on s \<Longrightarrow> bounded_linear h \<Longrightarrow> integral s (h o f) = h(integral s f)"
  5.1248 +  apply(rule has_integral_unique) defer unfolding has_integral_integral 
  5.1249 +  apply(drule has_integral_linear,assumption,assumption) unfolding has_integral_integral[THEN sym]
  5.1250 +  apply(rule integrable_linear) by assumption+
  5.1251 +
  5.1252 +lemma has_integral_setsum:
  5.1253 +  assumes "finite t" "\<forall>a\<in>t. ((f a) has_integral (i a)) s"
  5.1254 +  shows "((\<lambda>x. setsum (\<lambda>a. f a x) t) has_integral (setsum i t)) s"
  5.1255 +proof(insert assms(1) subset_refl[of t],induct rule:finite_subset_induct)
  5.1256 +  case (insert x F) show ?case unfolding setsum_insert[OF insert(1,3)]
  5.1257 +    apply(rule has_integral_add) using insert assms by auto
  5.1258 +qed auto
  5.1259 +
  5.1260 +lemma integral_setsum:
  5.1261 +  shows "finite t \<Longrightarrow> \<forall>a\<in>t. (f a) integrable_on s \<Longrightarrow>
  5.1262 +  integral s (\<lambda>x. setsum (\<lambda>a. f a x) t) = setsum (\<lambda>a. integral s (f a)) t"
  5.1263 +  apply(rule integral_unique) apply(rule has_integral_setsum)
  5.1264 +  using integrable_integral by auto
  5.1265 +
  5.1266 +lemma integrable_setsum:
  5.1267 +  shows "finite t \<Longrightarrow> \<forall>a \<in> t.(f a) integrable_on s \<Longrightarrow> (\<lambda>x. setsum (\<lambda>a. f a x) t) integrable_on s"
  5.1268 +  unfolding integrable_on_def apply(drule bchoice) using has_integral_setsum[of t] by auto
  5.1269 +
  5.1270 +lemma has_integral_eq:
  5.1271 +  assumes "\<forall>x\<in>s. f x = g x" "(f has_integral k) s" shows "(g has_integral k) s"
  5.1272 +  using has_integral_sub[OF assms(2), of "\<lambda>x. f x - g x" 0]
  5.1273 +  using has_integral_is_0[of s "\<lambda>x. f x - g x"] using assms(1) by auto
  5.1274 +
  5.1275 +lemma integrable_eq:
  5.1276 +  shows "\<forall>x\<in>s. f x = g x \<Longrightarrow> f integrable_on s \<Longrightarrow> g integrable_on s"
  5.1277 +  unfolding integrable_on_def using has_integral_eq[of s f g] by auto
  5.1278 +
  5.1279 +lemma has_integral_eq_eq:
  5.1280 +  shows "\<forall>x\<in>s. f x = g x \<Longrightarrow> ((f has_integral k) s \<longleftrightarrow> (g has_integral k) s)"
  5.1281 +  using has_integral_eq[of s f g] has_integral_eq[of s g f] by auto 
  5.1282 +
  5.1283 +lemma has_integral_null[dest]:
  5.1284 +  assumes "content({a..b}) = 0" shows  "(f has_integral 0) ({a..b})"
  5.1285 +  unfolding has_integral apply(rule,rule,rule_tac x="\<lambda>x. ball x 1" in exI,rule) defer
  5.1286 +proof(rule,rule,erule conjE) fix e::real assume e:"e>0" thus "gauge (\<lambda>x. ball x 1)" by auto
  5.1287 +  fix p assume p:"p tagged_division_of {a..b}" (*"(\<lambda>x. ball x 1) fine p"*)
  5.1288 +  have "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) = 0" unfolding norm_eq_zero diff_0_right
  5.1289 +    using setsum_content_null[OF assms(1) p, of f] . 
  5.1290 +  thus "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) < e" using e by auto qed
  5.1291 +
  5.1292 +lemma has_integral_null_eq[simp]:
  5.1293 +  shows "content({a..b}) = 0 \<Longrightarrow> ((f has_integral i) ({a..b}) \<longleftrightarrow> i = 0)"
  5.1294 +  apply rule apply(rule has_integral_unique,assumption) 
  5.1295 +  apply(drule has_integral_null,assumption)
  5.1296 +  apply(drule has_integral_null) by auto
  5.1297 +
  5.1298 +lemma integral_null[dest]: shows "content({a..b}) = 0 \<Longrightarrow> integral({a..b}) f = 0"
  5.1299 +  by(rule integral_unique,drule has_integral_null)
  5.1300 +
  5.1301 +lemma integrable_on_null[dest]: shows "content({a..b}) = 0 \<Longrightarrow> f integrable_on {a..b}"
  5.1302 +  unfolding integrable_on_def apply(drule has_integral_null) by auto
  5.1303 +
  5.1304 +lemma has_integral_empty[intro]: shows "(f has_integral 0) {}"
  5.1305 +  unfolding empty_as_interval apply(rule has_integral_null) 
  5.1306 +  using content_empty unfolding empty_as_interval .
  5.1307 +
  5.1308 +lemma has_integral_empty_eq[simp]: shows "(f has_integral i) {} \<longleftrightarrow> i = 0"
  5.1309 +  apply(rule,rule has_integral_unique,assumption) by auto
  5.1310 +
  5.1311 +lemma integrable_on_empty[intro]: shows "f integrable_on {}" unfolding integrable_on_def by auto
  5.1312 +
  5.1313 +lemma integral_empty[simp]: shows "integral {} f = 0"
  5.1314 +  apply(rule integral_unique) using has_integral_empty .
  5.1315 +
  5.1316 +lemma has_integral_refl[intro]: shows "(f has_integral 0) {a..a}"
  5.1317 +  apply(rule has_integral_null) unfolding content_eq_0_interior
  5.1318 +  unfolding interior_closed_interval using interval_sing by auto
  5.1319 +
  5.1320 +lemma integrable_on_refl[intro]: shows "f integrable_on {a..a}" unfolding integrable_on_def by auto
  5.1321 +
  5.1322 +lemma integral_refl: shows "integral {a..a} f = 0" apply(rule integral_unique) by auto
  5.1323 +
  5.1324 +subsection {* Cauchy-type criterion for integrability. *}
  5.1325 +
  5.1326 +lemma integrable_cauchy: fixes f::"real^'n \<Rightarrow> 'a::{real_normed_vector,complete_space}" 
  5.1327 +  shows "f integrable_on {a..b} \<longleftrightarrow>
  5.1328 +  (\<forall>e>0.\<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of {a..b} \<and> d fine p1 \<and>
  5.1329 +                            p2 tagged_division_of {a..b} \<and> d fine p2
  5.1330 +                            \<longrightarrow> norm(setsum (\<lambda>(x,k). content k *\<^sub>R f x) p1 -
  5.1331 +                                     setsum (\<lambda>(x,k). content k *\<^sub>R f x) p2) < e))" (is "?l = (\<forall>e>0. \<exists>d. ?P e d)")
  5.1332 +proof assume ?l
  5.1333 +  then guess y unfolding integrable_on_def has_integral .. note y=this
  5.1334 +  show "\<forall>e>0. \<exists>d. ?P e d" proof(rule,rule) case goal1 hence "e/2 > 0" by auto
  5.1335 +    then guess d apply- apply(drule y[rule_format]) by(erule exE,erule conjE) note d=this[rule_format]
  5.1336 +    show ?case apply(rule_tac x=d in exI,rule,rule d) apply(rule,rule,rule,(erule conjE)+)
  5.1337 +    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b}" "d fine p1" "p2 tagged_division_of {a..b}" "d fine p2"
  5.1338 +      show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e"
  5.1339 +        apply(rule dist_triangle_half_l[where y=y,unfolded vector_dist_norm])
  5.1340 +        using d(2)[OF conjI[OF as(1-2)]] d(2)[OF conjI[OF as(3-4)]] .
  5.1341 +    qed qed
  5.1342 +next assume "\<forall>e>0. \<exists>d. ?P e d" hence "\<forall>n::nat. \<exists>d. ?P (inverse(real (n + 1))) d" by auto
  5.1343 +  from choice[OF this] guess d .. note d=conjunctD2[OF this[rule_format],rule_format]
  5.1344 +  have "\<And>n. gauge (\<lambda>x. \<Inter>{d i x |i. i \<in> {0..n}})" apply(rule gauge_inters) using d(1) by auto
  5.1345 +  hence "\<forall>n. \<exists>p. p tagged_division_of {a..b} \<and> (\<lambda>x. \<Inter>{d i x |i. i \<in> {0..n}}) fine p" apply-
  5.1346 +  proof case goal1 from this[of n] show ?case apply(drule_tac fine_division_exists) by auto qed
  5.1347 +  from choice[OF this] guess p .. note p = conjunctD2[OF this[rule_format]]
  5.1348 +  have dp:"\<And>i n. i\<le>n \<Longrightarrow> d i fine p n" using p(2) unfolding fine_inters by auto
  5.1349 +  have "Cauchy (\<lambda>n. setsum (\<lambda>(x,k). content k *\<^sub>R (f x)) (p n))"
  5.1350 +  proof(rule CauchyI) case goal1 then guess N unfolding real_arch_inv[of e] .. note N=this
  5.1351 +    show ?case apply(rule_tac x=N in exI)
  5.1352 +    proof(rule,rule,rule,rule) fix m n assume mn:"N \<le> m" "N \<le> n" have *:"N = (N - 1) + 1" using N by auto
  5.1353 +      show "norm ((\<Sum>(x, k)\<in>p m. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p n. content k *\<^sub>R f x)) < e"
  5.1354 +        apply(rule less_trans[OF _ N[THEN conjunct2,THEN conjunct2]]) apply(subst *) apply(rule d(2))
  5.1355 +        using dp p(1) using mn by auto 
  5.1356 +    qed qed
  5.1357 +  then guess y unfolding convergent_eq_cauchy[THEN sym] .. note y=this[unfolded Lim_sequentially,rule_format]
  5.1358 +  show ?l unfolding integrable_on_def has_integral apply(rule_tac x=y in exI)
  5.1359 +  proof(rule,rule) fix e::real assume "e>0" hence *:"e/2 > 0" by auto
  5.1360 +    then guess N1 unfolding real_arch_inv[of "e/2"] .. note N1=this hence N1':"N1 = N1 - 1 + 1" by auto
  5.1361 +    guess N2 using y[OF *] .. note N2=this
  5.1362 +    show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - y) < e)"
  5.1363 +      apply(rule_tac x="d (N1 + N2)" in exI) apply rule defer 
  5.1364 +    proof(rule,rule,erule conjE) show "gauge (d (N1 + N2))" using d by auto
  5.1365 +      fix q assume as:"q tagged_division_of {a..b}" "d (N1 + N2) fine q"
  5.1366 +      have *:"inverse (real (N1 + N2 + 1)) < e / 2" apply(rule less_trans) using N1 by auto
  5.1367 +      show "norm ((\<Sum>(x, k)\<in>q. content k *\<^sub>R f x) - y) < e" apply(rule norm_triangle_half_r)
  5.1368 +        apply(rule less_trans[OF _ *]) apply(subst N1', rule d(2)[of "p (N1+N2)"]) defer
  5.1369 +        using N2[rule_format,unfolded vector_dist_norm,of "N1+N2"]
  5.1370 +        using as dp[of "N1 - 1 + 1 + N2" "N1 + N2"] using p(1)[of "N1 + N2"] using N1 by auto qed qed qed
  5.1371 +
  5.1372 +subsection {* Additivity of integral on abutting intervals. *}
  5.1373 +
  5.1374 +lemma interval_split:
  5.1375 +  "{a..b::real^'n} \<inter> {x. x$k \<le> c} = {a .. (\<chi> i. if i = k then min (b$k) c else b$i)}"
  5.1376 +  "{a..b} \<inter> {x. x$k \<ge> c} = {(\<chi> i. if i = k then max (a$k) c else a$i) .. b}"
  5.1377 +  apply(rule_tac[!] set_ext) unfolding Int_iff mem_interval mem_Collect_eq
  5.1378 +  unfolding Cart_lambda_beta by auto
  5.1379 +
  5.1380 +lemma content_split:
  5.1381 +  "content {a..b::real^'n} = content({a..b} \<inter> {x. x$k \<le> c}) + content({a..b} \<inter> {x. x$k >= c})"
  5.1382 +proof- note simps = interval_split content_closed_interval_cases Cart_lambda_beta vector_le_def
  5.1383 +  { presume "a\<le>b \<Longrightarrow> ?thesis" thus ?thesis apply(cases "a\<le>b") unfolding simps by auto }
  5.1384 +  have *:"UNIV = insert k (UNIV - {k})" "\<And>x. finite (UNIV-{x::'n})" "\<And>x. x\<notin>UNIV-{x}" by auto
  5.1385 +  have *:"\<And>X Y Z. (\<Prod>i\<in>UNIV. Z i (if i = k then X else Y i)) = Z k X * (\<Prod>i\<in>UNIV-{k}. Z i (Y i))"
  5.1386 +    "(\<Prod>i\<in>UNIV. b$i - a$i) = (\<Prod>i\<in>UNIV-{k}. b$i - a$i) * (b$k - a$k)" 
  5.1387 +    apply(subst *(1)) defer apply(subst *(1)) unfolding setprod_insert[OF *(2-)] by auto
  5.1388 +  assume as:"a\<le>b" moreover have "\<And>x. min (b $ k) c = max (a $ k) c
  5.1389 +    \<Longrightarrow> x* (b$k - a$k) = x*(max (a $ k) c - a $ k) + x*(b $ k - max (a $ k) c)"
  5.1390 +    by  (auto simp add:field_simps)
  5.1391 +  moreover have "\<not> a $ k \<le> c \<Longrightarrow> \<not> c \<le> b $ k \<Longrightarrow> False"
  5.1392 +    unfolding not_le using as[unfolded vector_le_def,rule_format,of k] by auto
  5.1393 +  ultimately show ?thesis 
  5.1394 +    unfolding simps unfolding *(1)[of "\<lambda>i x. b$i - x"] *(1)[of "\<lambda>i x. x - a$i"] *(2) by(auto)
  5.1395 +qed
  5.1396 +
  5.1397 +lemma division_split_left_inj:
  5.1398 +  assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2"
  5.1399 +  "k1 \<inter> {x::real^'n. x$k \<le> c} = k2 \<inter> {x. x$k \<le> c}"
  5.1400 +  shows "content(k1 \<inter> {x. x$k \<le> c}) = 0"
  5.1401 +proof- note d=division_ofD[OF assms(1)]
  5.1402 +  have *:"\<And>a b::real^'n. \<And> c k. (content({a..b} \<inter> {x. x$k \<le> c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x$k \<le> c}) = {})"
  5.1403 +    unfolding interval_split content_eq_0_interior by auto
  5.1404 +  guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
  5.1405 +  guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
  5.1406 +  have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
  5.1407 +  show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
  5.1408 +    defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
  5.1409 +
  5.1410 +lemma division_split_right_inj:
  5.1411 +  assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2"
  5.1412 +  "k1 \<inter> {x::real^'n. x$k \<ge> c} = k2 \<inter> {x. x$k \<ge> c}"
  5.1413 +  shows "content(k1 \<inter> {x. x$k \<ge> c}) = 0"
  5.1414 +proof- note d=division_ofD[OF assms(1)]
  5.1415 +  have *:"\<And>a b::real^'n. \<And> c k. (content({a..b} \<inter> {x. x$k >= c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x$k >= c}) = {})"
  5.1416 +    unfolding interval_split content_eq_0_interior by auto
  5.1417 +  guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
  5.1418 +  guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
  5.1419 +  have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
  5.1420 +  show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
  5.1421 +    defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
  5.1422 +
  5.1423 +lemma tagged_division_split_left_inj:
  5.1424 +  assumes "d tagged_division_of i" "(x1,k1) \<in> d" "(x2,k2) \<in> d" "k1 \<noteq> k2"  "k1 \<inter> {x. x$k \<le> c} = k2 \<inter> {x. x$k \<le> c}" 
  5.1425 +  shows "content(k1 \<inter> {x. x$k \<le> c}) = 0"
  5.1426 +proof- have *:"\<And>a b c. (a,b) \<in> c \<Longrightarrow> b \<in> snd ` c" unfolding image_iff apply(rule_tac x="(a,b)" in bexI) by auto
  5.1427 +  show ?thesis apply(rule division_split_left_inj[OF division_of_tagged_division[OF assms(1)]])
  5.1428 +    apply(rule_tac[1-2] *) using assms(2-) by auto qed
  5.1429 +
  5.1430 +lemma tagged_division_split_right_inj:
  5.1431 +  assumes "d tagged_division_of i" "(x1,k1) \<in> d" "(x2,k2) \<in> d" "k1 \<noteq> k2"  "k1 \<inter> {x. x$k \<ge> c} = k2 \<inter> {x. x$k \<ge> c}" 
  5.1432 +  shows "content(k1 \<inter> {x. x$k \<ge> c}) = 0"
  5.1433 +proof- have *:"\<And>a b c. (a,b) \<in> c \<Longrightarrow> b \<in> snd ` c" unfolding image_iff apply(rule_tac x="(a,b)" in bexI) by auto
  5.1434 +  show ?thesis apply(rule division_split_right_inj[OF division_of_tagged_division[OF assms(1)]])
  5.1435 +    apply(rule_tac[1-2] *) using assms(2-) by auto qed
  5.1436 +
  5.1437 +lemma division_split:
  5.1438 +  assumes "p division_of {a..b::real^'n}"
  5.1439 +  shows "{l \<inter> {x. x$k \<le> c} | l. l \<in> p \<and> ~(l \<inter> {x. x$k \<le> c} = {})} division_of ({a..b} \<inter> {x. x$k \<le> c})" (is "?p1 division_of ?I1") and 
  5.1440 +        "{l \<inter> {x. x$k \<ge> c} | l. l \<in> p \<and> ~(l \<inter> {x. x$k \<ge> c} = {})} division_of ({a..b} \<inter> {x. x$k \<ge> c})" (is "?p2 division_of ?I2")
  5.1441 +proof(rule_tac[!] division_ofI) note p=division_ofD[OF assms]
  5.1442 +  show "finite ?p1" "finite ?p2" using p(1) by auto show "\<Union>?p1 = ?I1" "\<Union>?p2 = ?I2" unfolding p(6)[THEN sym] by auto
  5.1443 +  { fix k assume "k\<in>?p1" then guess l unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l=this
  5.1444 +    guess u v using p(4)[OF l(2)] apply-by(erule exE)+ note uv=this
  5.1445 +    show "k\<subseteq>?I1" "k \<noteq> {}" "\<exists>a b. k = {a..b}" unfolding l
  5.1446 +      using p(2-3)[OF l(2)] l(3) unfolding uv apply- prefer 3 apply(subst interval_split) by auto
  5.1447 +    fix k' assume "k'\<in>?p1" then guess l' unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l'=this
  5.1448 +    assume "k\<noteq>k'" thus "interior k \<inter> interior k' = {}" unfolding l l' using p(5)[OF l(2) l'(2)] by auto }
  5.1449 +  { fix k assume "k\<in>?p2" then guess l unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l=this
  5.1450 +    guess u v using p(4)[OF l(2)] apply-by(erule exE)+ note uv=this
  5.1451 +    show "k\<subseteq>?I2" "k \<noteq> {}" "\<exists>a b. k = {a..b}" unfolding l
  5.1452 +      using p(2-3)[OF l(2)] l(3) unfolding uv apply- prefer 3 apply(subst interval_split) by auto
  5.1453 +    fix k' assume "k'\<in>?p2" then guess l' unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l'=this
  5.1454 +    assume "k\<noteq>k'" thus "interior k \<inter> interior k' = {}" unfolding l l' using p(5)[OF l(2) l'(2)] by auto }
  5.1455 +qed
  5.1456 +
  5.1457 +lemma has_integral_split: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  5.1458 +  assumes "(f has_integral i) ({a..b} \<inter> {x. x$k \<le> c})"  "(f has_integral j) ({a..b} \<inter> {x. x$k \<ge> c})"
  5.1459 +  shows "(f has_integral (i + j)) ({a..b})"
  5.1460 +proof(unfold has_integral,rule,rule) case goal1 hence e:"e/2>0" by auto
  5.1461 +  guess d1 using has_integralD[OF assms(1)[unfolded interval_split] e] . note d1=this[unfolded interval_split[THEN sym]]
  5.1462 +  guess d2 using has_integralD[OF assms(2)[unfolded interval_split] e] . note d2=this[unfolded interval_split[THEN sym]]
  5.1463 +  let ?d = "\<lambda>x. if x$k = c then (d1 x \<inter> d2 x) else ball x (abs(x$k - c)) \<inter> d1 x \<inter> d2 x"
  5.1464 +  show ?case apply(rule_tac x="?d" in exI,rule) defer apply(rule,rule,(erule conjE)+)
  5.1465 +  proof- show "gauge ?d" using d1(1) d2(1) unfolding gauge_def by auto
  5.1466 +    fix p assume "p tagged_division_of {a..b}" "?d fine p" note p = this tagged_division_ofD[OF this(1)]
  5.1467 +    have lem0:"\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x$k \<le> c} = {}) \<Longrightarrow> x$k \<le> c"
  5.1468 +         "\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x$k \<ge> c} = {}) \<Longrightarrow> x$k \<ge> c"
  5.1469 +    proof- fix x kk assume as:"(x,kk)\<in>p"
  5.1470 +      show "~(kk \<inter> {x. x$k \<le> c} = {}) \<Longrightarrow> x$k \<le> c"
  5.1471 +      proof(rule ccontr) case goal1
  5.1472 +        from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x $ k - c\<bar>"
  5.1473 +          using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
  5.1474 +        hence "\<exists>y. y \<in> ball x \<bar>x $ k - c\<bar> \<inter> {x. x $ k \<le> c}" using goal1(1) by blast 
  5.1475 +        then guess y .. hence "\<bar>x $ k - y $ k\<bar> < \<bar>x $ k - c\<bar>" "y$k \<le> c" apply-apply(rule le_less_trans)
  5.1476 +          using component_le_norm[of "x - y" k,unfolded vector_minus_component] by(auto simp add:vector_dist_norm)
  5.1477 +        thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
  5.1478 +      qed
  5.1479 +      show "~(kk \<inter> {x. x$k \<ge> c} = {}) \<Longrightarrow> x$k \<ge> c"
  5.1480 +      proof(rule ccontr) case goal1
  5.1481 +        from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x $ k - c\<bar>"
  5.1482 +          using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
  5.1483 +        hence "\<exists>y. y \<in> ball x \<bar>x $ k - c\<bar> \<inter> {x. x $ k \<ge> c}" using goal1(1) by blast 
  5.1484 +        then guess y .. hence "\<bar>x $ k - y $ k\<bar> < \<bar>x $ k - c\<bar>" "y$k \<ge> c" apply-apply(rule le_less_trans)
  5.1485 +          using component_le_norm[of "x - y" k,unfolded vector_minus_component] by(auto simp add:vector_dist_norm)
  5.1486 +        thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
  5.1487 +      qed
  5.1488 +    qed
  5.1489 +
  5.1490 +    have lem1: "\<And>f P Q. (\<forall>x k. (x,k) \<in> {(x,f k) | x k. P x k} \<longrightarrow> Q x k) \<longleftrightarrow> (\<forall>x k. P x k \<longrightarrow> Q x (f k))" by auto
  5.1491 +    have lem2: "\<And>f s P f. finite s \<Longrightarrow> finite {(x,f k) | x k. (x,k) \<in> s \<and> P x k}"
  5.1492 +    proof- case goal1 thus ?case apply-apply(rule finite_subset[of _ "(\<lambda>(x,k). (x,f k)) ` s"]) by auto qed
  5.1493 +    have lem3: "\<And>g::(real ^ 'n \<Rightarrow> bool) \<Rightarrow> real ^ 'n \<Rightarrow> bool. finite p \<Longrightarrow>
  5.1494 +      setsum (\<lambda>(x,k). content k *\<^sub>R f x) {(x,g k) |x k. (x,k) \<in> p \<and> ~(g k = {})}
  5.1495 +               = setsum (\<lambda>(x,k). content k *\<^sub>R f x) ((\<lambda>(x,k). (x,g k)) ` p)"
  5.1496 +      apply(rule setsum_mono_zero_left) prefer 3
  5.1497 +    proof fix g::"(real ^ 'n \<Rightarrow> bool) \<Rightarrow> real ^ 'n \<Rightarrow> bool" and i::"(real^'n) \<times> ((real^'n) set)"
  5.1498 +      assume "i \<in> (\<lambda>(x, k). (x, g k)) ` p - {(x, g k) |x k. (x, k) \<in> p \<and> g k \<noteq> {}}"
  5.1499 +      then obtain x k where xk:"i=(x,g k)" "(x,k)\<in>p" "(x,g k) \<notin> {(x, g k) |x k. (x, k) \<in> p \<and> g k \<noteq> {}}" by auto
  5.1500 +      have "content (g k) = 0" using xk using content_empty by auto
  5.1501 +      thus "(\<lambda>(x, k). content k *\<^sub>R f x) i = 0" unfolding xk split_conv by auto
  5.1502 +    qed auto
  5.1503 +    have lem4:"\<And>g. (\<lambda>(x,l). content (g l) *\<^sub>R f x) = (\<lambda>(x,l). content l *\<^sub>R f x) o (\<lambda>(x,l). (x,g l))" apply(rule ext) by auto
  5.1504 +
  5.1505 +    let ?M1 = "{(x,kk \<inter> {x. x$k \<le> c}) |x kk. (x,kk) \<in> p \<and> kk \<inter> {x. x$k \<le> c} \<noteq> {}}"
  5.1506 +    have "norm ((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) < e/2" apply(rule d1(2),rule tagged_division_ofI)
  5.1507 +      apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
  5.1508 +    proof- show "\<Union>{k. \<exists>x. (x, k) \<in> ?M1} = {a..b} \<inter> {x. x$k \<le> c}" unfolding p(8)[THEN sym] by auto
  5.1509 +      fix x l assume xl:"(x,l)\<in>?M1"
  5.1510 +      then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
  5.1511 +      have "l' \<subseteq> d1 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
  5.1512 +      thus "l \<subseteq> d1 x" unfolding xl' by auto
  5.1513 +      show "x\<in>l" "l \<subseteq> {a..b} \<inter> {x. x $ k \<le> c}" unfolding xl' using p(4-6)[OF xl'(3)] using xl'(4)
  5.1514 +        using lem0(1)[OF xl'(3-4)] by auto
  5.1515 +      show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastsimp simp add: interval_split[where c=c and k=k])
  5.1516 +      fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M1"
  5.1517 +      then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
  5.1518 +      assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
  5.1519 +      proof(cases "l' = r' \<longrightarrow> x' = y'")
  5.1520 +        case False thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
  5.1521 +      next case True hence "l' \<noteq> r'" using as unfolding xl' yr' by auto
  5.1522 +        thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
  5.1523 +      qed qed moreover
  5.1524 +
  5.1525 +    let ?M2 = "{(x,kk \<inter> {x. x$k \<ge> c}) |x kk. (x,kk) \<in> p \<and> kk \<inter> {x. x$k \<ge> c} \<noteq> {}}" 
  5.1526 +    have "norm ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j) < e/2" apply(rule d2(2),rule tagged_division_ofI)
  5.1527 +      apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
  5.1528 +    proof- show "\<Union>{k. \<exists>x. (x, k) \<in> ?M2} = {a..b} \<inter> {x. x$k \<ge> c}" unfolding p(8)[THEN sym] by auto
  5.1529 +      fix x l assume xl:"(x,l)\<in>?M2"
  5.1530 +      then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
  5.1531 +      have "l' \<subseteq> d2 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
  5.1532 +      thus "l \<subseteq> d2 x" unfolding xl' by auto
  5.1533 +      show "x\<in>l" "l \<subseteq> {a..b} \<inter> {x. x $ k \<ge> c}" unfolding xl' using p(4-6)[OF xl'(3)] using xl'(4)
  5.1534 +        using lem0(2)[OF xl'(3-4)] by auto
  5.1535 +      show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastsimp simp add: interval_split[where c=c and k=k])
  5.1536 +      fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M2"
  5.1537 +      then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
  5.1538 +      assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
  5.1539 +      proof(cases "l' = r' \<longrightarrow> x' = y'")
  5.1540 +        case False thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
  5.1541 +      next case True hence "l' \<noteq> r'" using as unfolding xl' yr' by auto
  5.1542 +        thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
  5.1543 +      qed qed ultimately
  5.1544 +
  5.1545 +    have "norm (((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) + ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j)) < e/2 + e/2"
  5.1546 +      apply- apply(rule norm_triangle_lt) by auto
  5.1547 +    also { have *:"\<And>x y. x = (0::real) \<Longrightarrow> x *\<^sub>R (y::'a) = 0" using scaleR_zero_left by auto
  5.1548 +      have "((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) + ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j)
  5.1549 +       = (\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - (i + j)" by auto
  5.1550 +      also have "\<dots> = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. x $ k \<le> c}) *\<^sub>R f x) + (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. c \<le> x $ k}) *\<^sub>R f x) - (i + j)"
  5.1551 +        unfolding lem3[OF p(3)] apply(subst setsum_reindex_nonzero[OF p(3)]) defer apply(subst setsum_reindex_nonzero[OF p(3)])
  5.1552 +        defer unfolding lem4[THEN sym] apply(rule refl) unfolding split_paired_all split_conv apply(rule_tac[!] *)
  5.1553 +      proof- case goal1 thus ?case apply- apply(rule tagged_division_split_left_inj [OF p(1), of a b aa ba]) by auto
  5.1554 +      next case   goal2 thus ?case apply- apply(rule tagged_division_split_right_inj[OF p(1), of a b aa ba]) by auto
  5.1555 +      qed also note setsum_addf[THEN sym]
  5.1556 +      also have *:"\<And>x. x\<in>p \<Longrightarrow> (\<lambda>(x, ka). content (ka \<inter> {x. x $ k \<le> c}) *\<^sub>R f x) x + (\<lambda>(x, ka). content (ka \<inter> {x. c \<le> x $ k}) *\<^sub>R f x) x
  5.1557 +        = (\<lambda>(x,ka). content ka *\<^sub>R f x) x" unfolding split_paired_all split_conv
  5.1558 +      proof- fix a b assume "(a,b) \<in> p" from p(6)[OF this] guess u v apply-by(erule exE)+ note uv=this
  5.1559 +        thus "content (b \<inter> {x. x $ k \<le> c}) *\<^sub>R f a + content (b \<inter> {x. c \<le> x $ k}) *\<^sub>R f a = content b *\<^sub>R f a"
  5.1560 +          unfolding scaleR_left_distrib[THEN sym] unfolding uv content_split[of u v k c] by auto
  5.1561 +      qed note setsum_cong2[OF this]
  5.1562 +      finally have "(\<Sum>(x, k)\<in>{(x, kk \<inter> {x. x $ k \<le> c}) |x kk. (x, kk) \<in> p \<and> kk \<inter> {x. x $ k \<le> c} \<noteq> {}}. content k *\<^sub>R f x) - i +
  5.1563 +        ((\<Sum>(x, k)\<in>{(x, kk \<inter> {x. c \<le> x $ k}) |x kk. (x, kk) \<in> p \<and> kk \<inter> {x. c \<le> x $ k} \<noteq> {}}. content k *\<^sub>R f x) - j) =
  5.1564 +        (\<Sum>(x, ka)\<in>p. content ka *\<^sub>R f x) - (i + j)" by auto }
  5.1565 +    finally show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - (i + j)) < e" by auto qed qed
  5.1566 +
  5.1567 +subsection {* A sort of converse, integrability on subintervals. *}
  5.1568 +
  5.1569 +lemma tagged_division_union_interval:
  5.1570 +  assumes "p1 tagged_division_of ({a..b} \<inter> {x::real^'n. x$k \<le> (c::real)})"  "p2 tagged_division_of ({a..b} \<inter> {x. x$k \<ge> c})"
  5.1571 +  shows "(p1 \<union> p2) tagged_division_of ({a..b})"
  5.1572 +proof- have *:"{a..b} = ({a..b} \<inter> {x. x$k \<le> c}) \<union> ({a..b} \<inter> {x. x$k \<ge> c})" by auto
  5.1573 +  show ?thesis apply(subst *) apply(rule tagged_division_union[OF assms])
  5.1574 +    unfolding interval_split interior_closed_interval
  5.1575 +    by(auto simp add: vector_less_def Cart_lambda_beta elim!:allE[where x=k]) qed
  5.1576 +
  5.1577 +lemma has_integral_separate_sides: fixes f::"real^'m \<Rightarrow> 'a::real_normed_vector"
  5.1578 +  assumes "(f has_integral i) ({a..b})" "e>0"
  5.1579 +  obtains d where "gauge d" "(\<forall>p1 p2. p1 tagged_division_of ({a..b} \<inter> {x. x$k \<le> c}) \<and> d fine p1 \<and>
  5.1580 +                                p2 tagged_division_of ({a..b} \<inter> {x. x$k \<ge> c}) \<and> d fine p2
  5.1581 +                                \<longrightarrow> norm((setsum (\<lambda>(x,k). content k *\<^sub>R f x) p1 +
  5.1582 +                                          setsum (\<lambda>(x,k). content k *\<^sub>R f x) p2) - i) < e)"
  5.1583 +proof- guess d using has_integralD[OF assms] . note d=this
  5.1584 +  show ?thesis apply(rule that[of d]) apply(rule d) apply(rule,rule,rule,(erule conjE)+)
  5.1585 +  proof- fix p1 p2 assume "p1 tagged_division_of {a..b} \<inter> {x. x $ k \<le> c}" "d fine p1" note p1=tagged_division_ofD[OF this(1)] this
  5.1586 +                   assume "p2 tagged_division_of {a..b} \<inter> {x. c \<le> x $ k}" "d fine p2" note p2=tagged_division_ofD[OF this(1)] this
  5.1587 +    note tagged_division_union_interval[OF p1(7) p2(7)] note p12 = tagged_division_ofD[OF this] this
  5.1588 +    have "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x) - i) = norm ((\<Sum>(x, k)\<in>p1 \<union> p2. content k *\<^sub>R f x) - i)"
  5.1589 +      apply(subst setsum_Un_zero) apply(rule p1 p2)+ apply(rule) unfolding split_paired_all split_conv
  5.1590 +    proof- fix a b assume ab:"(a,b) \<in> p1 \<inter> p2"
  5.1591 +      have "(a,b) \<in> p1" using ab by auto from p1(4)[OF this] guess u v apply-by(erule exE)+ note uv =this
  5.1592 +      have "b \<subseteq> {x. x$k = c}" using ab p1(3)[of a b] p2(3)[of a b] by fastsimp
  5.1593 +      moreover have "interior {x. x $ k = c} = {}" 
  5.1594 +      proof(rule ccontr) case goal1 then obtain x where x:"x\<in>interior {x. x$k = c}" by auto
  5.1595 +        then guess e unfolding mem_interior .. note e=this
  5.1596 +        have x:"x$k = c" using x interior_subset by fastsimp
  5.1597 +        have *:"\<And>i. \<bar>(x - (x + (\<chi> i. if i = k then e / 2 else 0))) $ i\<bar> = (if i = k then e/2 else 0)" using e by auto
  5.1598 +        have "x + (\<chi> i. if i = k then e/2 else 0) \<in> ball x e" unfolding mem_ball vector_dist_norm 
  5.1599 +          apply(rule le_less_trans[OF norm_le_l1]) unfolding * 
  5.1600 +          unfolding setsum_delta[OF finite_UNIV] using e by auto 
  5.1601 +        hence "x + (\<chi> i. if i = k then e/2 else 0) \<in> {x. x$k = c}" using e by auto
  5.1602 +        thus False unfolding mem_Collect_eq using e x by auto
  5.1603 +      qed ultimately have "content b = 0" unfolding uv content_eq_0_interior apply-apply(drule subset_interior) by auto
  5.1604 +      thus "content b *\<^sub>R f a = 0" by auto
  5.1605 +    qed auto
  5.1606 +    also have "\<dots> < e" by(rule d(2) p12 fine_union p1 p2)+
  5.1607 +    finally show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x) - i) < e" . qed qed
  5.1608 +
  5.1609 +lemma integrable_split[intro]: fixes f::"real^'n \<Rightarrow> 'a::{real_normed_vector,complete_space}" assumes "f integrable_on {a..b}"
  5.1610 +  shows "f integrable_on ({a..b} \<inter> {x. x$k \<le> c})" (is ?t1) and "f integrable_on ({a..b} \<inter> {x. x$k \<ge> c})" (is ?t2) 
  5.1611 +proof- guess y using assms unfolding integrable_on_def .. note y=this
  5.1612 +  def b' \<equiv> "(\<chi> i. if i = k then min (b$k) c else b$i)::real^'n"
  5.1613 +  and a' \<equiv> "(\<chi> i. if i = k then max (a$k) c else a$i)::real^'n"
  5.1614 +  show ?t1 ?t2 unfolding interval_split integrable_cauchy unfolding interval_split[THEN sym]
  5.1615 +  proof(rule_tac[!] allI impI)+ fix e::real assume "e>0" hence "e/2>0" by auto
  5.1616 +    from has_integral_separate_sides[OF y this,of k c] guess d . note d=this[rule_format]
  5.1617 +    let ?P = "\<lambda>A. \<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of {a..b} \<inter> A \<and> d fine p1 \<and> p2 tagged_division_of {a..b} \<inter> A \<and> d fine p2 \<longrightarrow>
  5.1618 +                              norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e)"
  5.1619 +    show "?P {x. x $ k \<le> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  5.1620 +    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x $ k \<le> c} \<and> d fine p1 \<and> p2 tagged_division_of {a..b} \<inter> {x. x $ k \<le> c} \<and> d fine p2"
  5.1621 +      show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e"
  5.1622 +      proof- guess p using fine_division_exists[OF d(1), of a' b] . note p=this
  5.1623 +        show ?thesis using norm_triangle_half_l[OF d(2)[of p1 p] d(2)[of p2 p]]
  5.1624 +          using as unfolding interval_split b'_def[symmetric] a'_def[symmetric]
  5.1625 +          using p using assms by(auto simp add:group_simps)
  5.1626 +      qed qed  
  5.1627 +    show "?P {x. x $ k \<ge> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  5.1628 +    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x $ k \<ge> c} \<and> d fine p1 \<and> p2 tagged_division_of {a..b} \<inter> {x. x $ k \<ge> c} \<and> d fine p2"
  5.1629 +      show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e"
  5.1630 +      proof- guess p using fine_division_exists[OF d(1), of a b'] . note p=this
  5.1631 +        show ?thesis using norm_triangle_half_l[OF d(2)[of p p1] d(2)[of p p2]]
  5.1632 +          using as unfolding interval_split b'_def[symmetric] a'_def[symmetric]
  5.1633 +          using p using assms by(auto simp add:group_simps) qed qed qed qed
  5.1634 +
  5.1635 +subsection {* Generalized notion of additivity. *}
  5.1636 +
  5.1637 +definition "neutral opp = (SOME x. \<forall>y. opp x y = y \<and> opp y x = y)"
  5.1638 +
  5.1639 +definition operative :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> ((real^'n) set \<Rightarrow> 'a) \<Rightarrow> bool" where
  5.1640 +  "operative opp f \<equiv> 
  5.1641 +    (\<forall>a b. content {a..b} = 0 \<longrightarrow> f {a..b} = neutral(opp)) \<and>
  5.1642 +    (\<forall>a b c k. f({a..b}) =
  5.1643 +                   opp (f({a..b} \<inter> {x. x$k \<le> c}))
  5.1644 +                       (f({a..b} \<inter> {x. x$k \<ge> c})))"
  5.1645 +
  5.1646 +lemma operativeD[dest]: assumes "operative opp f"
  5.1647 +  shows "\<And>a b. content {a..b} = 0 \<Longrightarrow> f {a..b} = neutral(opp)"
  5.1648 +  "\<And>a b c k. f({a..b}) = opp (f({a..b} \<inter> {x. x$k \<le> c})) (f({a..b} \<inter> {x. x$k \<ge> c}))"
  5.1649 +  using assms unfolding operative_def by auto
  5.1650 +
  5.1651 +lemma operative_trivial:
  5.1652 + "operative opp f \<Longrightarrow> content({a..b}) = 0 \<Longrightarrow> f({a..b}) = neutral opp"
  5.1653 +  unfolding operative_def by auto
  5.1654 +
  5.1655 +lemma property_empty_interval:
  5.1656 + "(\<forall>a b. content({a..b}) = 0 \<longrightarrow> P({a..b})) \<Longrightarrow> P {}" 
  5.1657 +  using content_empty unfolding empty_as_interval by auto
  5.1658 +
  5.1659 +lemma operative_empty: "operative opp f \<Longrightarrow> f {} = neutral opp"
  5.1660 +  unfolding operative_def apply(rule property_empty_interval) by auto
  5.1661 +
  5.1662 +subsection {* Using additivity of lifted function to encode definedness. *}
  5.1663 +
  5.1664 +lemma forall_option: "(\<forall>x. P x) \<longleftrightarrow> P None \<and> (\<forall>x. P(Some x))"
  5.1665 +  by (metis map_of.simps option.nchotomy)
  5.1666 +
  5.1667 +lemma exists_option:
  5.1668 + "(\<exists>x. P x) \<longleftrightarrow> P None \<or> (\<exists>x. P(Some x))" 
  5.1669 +  by (metis map_of.simps option.nchotomy)
  5.1670 +
  5.1671 +fun lifted where 
  5.1672 +  "lifted (opp::'a\<Rightarrow>'a\<Rightarrow>'b) (Some x) (Some y) = Some(opp x y)" |
  5.1673 +  "lifted opp None _ = (None::'b option)" |
  5.1674 +  "lifted opp _ None = None"
  5.1675 +
  5.1676 +lemma lifted_simp_1[simp]: "lifted opp v None = None"
  5.1677 +  apply(induct v) by auto
  5.1678 +
  5.1679 +definition "monoidal opp \<equiv>  (\<forall>x y. opp x y = opp y x) \<and>
  5.1680 +                   (\<forall>x y z. opp x (opp y z) = opp (opp x y) z) \<and>
  5.1681 +                   (\<forall>x. opp (neutral opp) x = x)"
  5.1682 +
  5.1683 +lemma monoidalI: assumes "\<And>x y. opp x y = opp y x"
  5.1684 +  "\<And>x y z. opp x (opp y z) = opp (opp x y) z"
  5.1685 +  "\<And>x. opp (neutral opp) x = x" shows "monoidal opp"
  5.1686 +  unfolding monoidal_def using assms by fastsimp
  5.1687 +
  5.1688 +lemma monoidal_ac: assumes "monoidal opp"
  5.1689 +  shows "opp (neutral opp) a = a" "opp a (neutral opp) = a" "opp a b = opp b a"
  5.1690 +  "opp (opp a b) c = opp a (opp b c)"  "opp a (opp b c) = opp b (opp a c)"
  5.1691 +  using assms unfolding monoidal_def apply- by metis+
  5.1692 +
  5.1693 +lemma monoidal_simps[simp]: assumes "monoidal opp"
  5.1694 +  shows "opp (neutral opp) a = a" "opp a (neutral opp) = a"
  5.1695 +  using monoidal_ac[OF assms] by auto
  5.1696 +
  5.1697 +lemma neutral_lifted[cong]: assumes "monoidal opp"
  5.1698 +  shows "neutral (lifted opp) = Some(neutral opp)"
  5.1699 +  apply(subst neutral_def) apply(rule some_equality) apply(rule,induct_tac y) prefer 3
  5.1700 +proof- fix x assume "\<forall>y. lifted opp x y = y \<and> lifted opp y x = y"
  5.1701 +  thus "x = Some (neutral opp)" apply(induct x) defer
  5.1702 +    apply rule apply(subst neutral_def) apply(subst eq_commute,rule some_equality)
  5.1703 +    apply(rule,erule_tac x="Some y" in allE) defer apply(erule_tac x="Some x" in allE) by auto
  5.1704 +qed(auto simp add:monoidal_ac[OF assms])
  5.1705 +
  5.1706 +lemma monoidal_lifted[intro]: assumes "monoidal opp" shows "monoidal(lifted opp)"
  5.1707 +  unfolding monoidal_def forall_option neutral_lifted[OF assms] using monoidal_ac[OF assms] by auto
  5.1708 +
  5.1709 +definition "support opp f s = {x. x\<in>s \<and> f x \<noteq> neutral opp}"
  5.1710 +definition "fold' opp e s \<equiv> (if finite s then fold opp e s else e)"
  5.1711 +definition "iterate opp s f \<equiv> fold' (\<lambda>x a. opp (f x) a) (neutral opp) (support opp f s)"
  5.1712 +
  5.1713 +lemma support_subset[intro]:"support opp f s \<subseteq> s" unfolding support_def by auto
  5.1714 +lemma support_empty[simp]:"support opp f {} = {}" using support_subset[of opp f "{}"] by auto
  5.1715 +
  5.1716 +lemma fun_left_comm_monoidal[intro]: assumes "monoidal opp" shows "fun_left_comm opp"
  5.1717 +  unfolding fun_left_comm_def using monoidal_ac[OF assms] by auto
  5.1718 +
  5.1719 +lemma support_clauses:
  5.1720 +  "\<And>f g s. support opp f {} = {}"
  5.1721 +  "\<And>f g s. support opp f (insert x s) = (if f(x) = neutral opp then support opp f s else insert x (support opp f s))"
  5.1722 +  "\<And>f g s. support opp f (s - {x}) = (support opp f s) - {x}"
  5.1723 +  "\<And>f g s. support opp f (s \<union> t) = (support opp f s) \<union> (support opp f t)"
  5.1724 +  "\<And>f g s. support opp f (s \<inter> t) = (support opp f s) \<inter> (support opp f t)"
  5.1725 +  "\<And>f g s. support opp f (s - t) = (support opp f s) - (support opp f t)"
  5.1726 +  "\<And>f g s. support opp g (f ` s) = f ` (support opp (g o f) s)"
  5.1727 +unfolding support_def by auto
  5.1728 +
  5.1729 +lemma finite_support[intro]:"finite s \<Longrightarrow> finite (support opp f s)"
  5.1730 +  unfolding support_def by auto
  5.1731 +
  5.1732 +lemma iterate_empty[simp]:"iterate opp {} f = neutral opp"
  5.1733 +  unfolding iterate_def fold'_def by auto 
  5.1734 +
  5.1735 +lemma iterate_insert[simp]: assumes "monoidal opp" "finite s"
  5.1736 +  shows "iterate opp (insert x s) f = (if x \<in> s then iterate opp s f else opp (f x) (iterate opp s f))" 
  5.1737 +proof(cases "x\<in>s") case True hence *:"insert x s = s" by auto
  5.1738 +  show ?thesis unfolding iterate_def if_P[OF True] * by auto
  5.1739 +next case False note x=this
  5.1740 +  note * = fun_left_comm.fun_left_comm_apply[OF fun_left_comm_monoidal[OF assms(1)]]
  5.1741 +  show ?thesis proof(cases "f x = neutral opp")
  5.1742 +    case True show ?thesis unfolding iterate_def if_not_P[OF x] support_clauses if_P[OF True]
  5.1743 +      unfolding True monoidal_simps[OF assms(1)] by auto
  5.1744 +  next case False show ?thesis unfolding iterate_def fold'_def  if_not_P[OF x] support_clauses if_not_P[OF False]
  5.1745 +      apply(subst fun_left_comm.fold_insert[OF * finite_support])
  5.1746 +      using `finite s` unfolding support_def using False x by auto qed qed 
  5.1747 +
  5.1748 +lemma iterate_some:
  5.1749 +  assumes "monoidal opp"  "finite s"
  5.1750 +  shows "iterate (lifted opp) s (\<lambda>x. Some(f x)) = Some (iterate opp s f)" using assms(2)
  5.1751 +proof(induct s) case empty thus ?case using assms by auto
  5.1752 +next case (insert x F) show ?case apply(subst iterate_insert) prefer 3 apply(subst if_not_P)
  5.1753 +    defer unfolding insert(3) lifted.simps apply rule using assms insert by auto qed
  5.1754 +
  5.1755 +subsection {* Two key instances of additivity. *}
  5.1756 +
  5.1757 +lemma neutral_add[simp]:
  5.1758 +  "neutral op + = (0::_::comm_monoid_add)" unfolding neutral_def 
  5.1759 +  apply(rule some_equality) defer apply(erule_tac x=0 in allE) by auto
  5.1760 +
  5.1761 +lemma operative_content[intro]: "operative (op +) content"
  5.1762 +  unfolding operative_def content_split[THEN sym] neutral_add by auto
  5.1763 +
  5.1764 +lemma neutral_monoid[simp]: "neutral ((op +)::('a::comm_monoid_add) \<Rightarrow> 'a \<Rightarrow> 'a) = 0"
  5.1765 +  unfolding neutral_def apply(rule some_equality) defer
  5.1766 +  apply(erule_tac x=0 in allE) by auto
  5.1767 +
  5.1768 +lemma monoidal_monoid[intro]:
  5.1769 +  shows "monoidal ((op +)::('a::comm_monoid_add) \<Rightarrow> 'a \<Rightarrow> 'a)"
  5.1770 +  unfolding monoidal_def neutral_monoid by(auto simp add: group_simps) 
  5.1771 +
  5.1772 +lemma operative_integral: fixes f::"real^'n \<Rightarrow> 'a::banach"
  5.1773 +  shows "operative (lifted(op +)) (\<lambda>i. if f integrable_on i then Some(integral i f) else None)"
  5.1774 +  unfolding operative_def unfolding neutral_lifted[OF monoidal_monoid] neutral_add
  5.1775 +  apply(rule,rule,rule,rule) defer apply(rule allI)+
  5.1776 +proof- fix a b c k show "(if f integrable_on {a..b} then Some (integral {a..b} f) else None) =
  5.1777 +              lifted op + (if f integrable_on {a..b} \<inter> {x. x $ k \<le> c} then Some (integral ({a..b} \<inter> {x. x $ k \<le> c}) f) else None)
  5.1778 +               (if f integrable_on {a..b} \<inter> {x. c \<le> x $ k} then Some (integral ({a..b} \<inter> {x. c \<le> x $ k}) f) else None)"
  5.1779 +  proof(cases "f integrable_on {a..b}") 
  5.1780 +    case True show ?thesis unfolding if_P[OF True]
  5.1781 +      unfolding if_P[OF integrable_split(1)[OF True]] if_P[OF integrable_split(2)[OF True]]
  5.1782 +      unfolding lifted.simps option.inject apply(rule integral_unique) apply(rule has_integral_split) 
  5.1783 +      apply(rule_tac[!] integrable_integral integrable_split)+ using True by assumption+
  5.1784 +  next case False have "(\<not> (f integrable_on {a..b} \<inter> {x. x $ k \<le> c})) \<or> (\<not> ( f integrable_on {a..b} \<inter> {x. c \<le> x $ k}))"
  5.1785 +    proof(rule ccontr) case goal1 hence "f integrable_on {a..b}" apply- unfolding integrable_on_def
  5.1786 +        apply(rule_tac x="integral ({a..b} \<inter> {x. x $ k \<le> c}) f + integral ({a..b} \<inter> {x. x $ k \<ge> c}) f" in exI)
  5.1787 +        apply(rule has_integral_split) apply(rule_tac[!] integrable_integral) by auto
  5.1788 +      thus False using False by auto
  5.1789 +    qed thus ?thesis using False by auto 
  5.1790 +  qed next 
  5.1791 +  fix a b assume as:"content {a..b::real^'n} = 0"
  5.1792 +  thus "(if f integrable_on {a..b} then Some (integral {a..b} f) else None) = Some 0"
  5.1793 +    unfolding if_P[OF integrable_on_null[OF as]] using has_integral_null_eq[OF as] by auto qed
  5.1794 +
  5.1795 +subsection {* Points of division of a partition. *}
  5.1796 +
  5.1797 +definition "division_points (k::(real^'n) set) d = 
  5.1798 +    {(j,x). (interval_lowerbound k)$j < x \<and> x < (interval_upperbound k)$j \<and>
  5.1799 +           (\<exists>i\<in>d. (interval_lowerbound i)$j = x \<or> (interval_upperbound i)$j = x)}"
  5.1800 +
  5.1801 +lemma division_points_finite: assumes "d division_of i"
  5.1802 +  shows "finite (division_points i d)"
  5.1803 +proof- note assm = division_ofD[OF assms]
  5.1804 +  let ?M = "\<lambda>j. {(j,x)|x. (interval_lowerbound i)$j < x \<and> x < (interval_upperbound i)$j \<and>
  5.1805 +           (\<exists>i\<in>d. (interval_lowerbound i)$j = x \<or> (interval_upperbound i)$j = x)}"
  5.1806 +  have *:"division_points i d = \<Union>(?M ` UNIV)"
  5.1807 +    unfolding division_points_def by auto
  5.1808 +  show ?thesis unfolding * using assm by auto qed
  5.1809 +
  5.1810 +lemma division_points_subset:
  5.1811 +  assumes "d division_of {a..b}" "\<forall>i. a$i < b$i"  "a$k < c" "c < b$k"
  5.1812 +  shows "division_points ({a..b} \<inter> {x. x$k \<le> c}) {l \<inter> {x. x$k \<le> c} | l . l \<in> d \<and> ~(l \<inter> {x. x$k \<le> c} = {})}
  5.1813 +                  \<subseteq> division_points ({a..b}) d" (is ?t1) and
  5.1814 +        "division_points ({a..b} \<inter> {x. x$k \<ge> c}) {l \<inter> {x. x$k \<ge> c} | l . l \<in> d \<and> ~(l \<inter> {x. x$k \<ge> c} = {})}
  5.1815 +                  \<subseteq> division_points ({a..b}) d" (is ?t2)
  5.1816 +proof- note assm = division_ofD[OF assms(1)]
  5.1817 +  have *:"\<forall>i. a$i \<le> b$i"   "\<forall>i. a$i \<le> (\<chi> i. if i = k then min (b $ k) c else b $ i) $ i"
  5.1818 +    "\<forall>i. (\<chi> i. if i = k then max (a $ k) c else a $ i) $ i \<le> b$i"  "min (b $ k) c = c" "max (a $ k) c = c"
  5.1819 +    using assms using less_imp_le by auto
  5.1820 +  show ?t1 unfolding division_points_def interval_split[of a b]
  5.1821 +    unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)] Cart_lambda_beta unfolding *
  5.1822 +    unfolding subset_eq apply(rule) unfolding mem_Collect_eq split_beta apply(erule bexE conjE)+ unfolding mem_Collect_eq apply(erule exE conjE)+
  5.1823 +  proof- fix i l x assume as:"a $ fst x < snd x" "snd x < (if fst x = k then c else b $ fst x)"
  5.1824 +      "interval_lowerbound i $ fst x = snd x \<or> interval_upperbound i $ fst x = snd x"  "i = l \<inter> {x. x $ k \<le> c}" "l \<in> d" "l \<inter> {x. x $ k \<le> c} \<noteq> {}"
  5.1825 +    from assm(4)[OF this(5)] guess u v apply-by(erule exE)+ note l=this
  5.1826 +    have *:"\<forall>i. u $ i \<le> (\<chi> i. if i = k then min (v $ k) c else v $ i) $ i" using as(6) unfolding l interval_split interval_ne_empty as .
  5.1827 +    have **:"\<forall>i. u$i \<le> v$i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
  5.1828 +    show "a $ fst x < snd x \<and> snd x < b $ fst x \<and> (\<exists>i\<in>d. interval_lowerbound i $ fst x = snd x \<or> interval_upperbound i $ fst x = snd x)"
  5.1829 +      using as(1-3,5) unfolding l interval_split interval_ne_empty as interval_bounds[OF *] Cart_lambda_beta apply-
  5.1830 +      apply(rule,assumption,rule) defer apply(rule_tac x="{u..v}" in bexI) unfolding interval_bounds[OF **]
  5.1831 +      apply(case_tac[!] "fst x = k") using assms by auto
  5.1832 +  qed
  5.1833 +  show ?t2 unfolding division_points_def interval_split[of a b]
  5.1834 +    unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)] Cart_lambda_beta unfolding *
  5.1835 +    unfolding subset_eq apply(rule) unfolding mem_Collect_eq split_beta apply(erule bexE conjE)+ unfolding mem_Collect_eq apply(erule exE conjE)+
  5.1836 +  proof- fix i l x assume as:"(if fst x = k then c else a $ fst x) < snd x" "snd x < b $ fst x" "interval_lowerbound i $ fst x = snd x \<or> interval_upperbound i $ fst x = snd x"
  5.1837 +      "i = l \<inter> {x. c \<le> x $ k}" "l \<in> d" "l \<inter> {x. c \<le> x $ k} \<noteq> {}"
  5.1838 +    from assm(4)[OF this(5)] guess u v apply-by(erule exE)+ note l=this
  5.1839 +    have *:"\<forall>i. (\<chi> i. if i = k then max (u $ k) c else u $ i) $ i \<le> v $ i" using as(6) unfolding l interval_split interval_ne_empty as .
  5.1840 +    have **:"\<forall>i. u$i \<le> v$i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
  5.1841 +    show "a $ fst x < snd x \<and> snd x < b $ fst x \<and> (\<exists>i\<in>d. interval_lowerbound i $ fst x = snd x \<or> interval_upperbound i $ fst x = snd x)"
  5.1842 +      using as(1-3,5) unfolding l interval_split interval_ne_empty as interval_bounds[OF *] Cart_lambda_beta apply-
  5.1843 +      apply rule defer apply(rule,assumption) apply(rule_tac x="{u..v}" in bexI) unfolding interval_bounds[OF **]
  5.1844 +      apply(case_tac[!] "fst x = k") using assms by auto qed qed
  5.1845 +
  5.1846 +lemma division_points_psubset:
  5.1847 +  assumes "d division_of {a..b}"  "\<forall>i. a$i < b$i"  "a$k < c" "c < b$k"
  5.1848 +  "l \<in> d" "interval_lowerbound l$k = c \<or> interval_upperbound l$k = c"
  5.1849 +  shows "division_points ({a..b} \<inter> {x. x$k \<le> c}) {l \<inter> {x. x$k \<le> c} | l. l\<in>d \<and> l \<inter> {x. x$k \<le> c} \<noteq> {}} \<subset> division_points ({a..b}) d" (is "?D1 \<subset> ?D") 
  5.1850 +        "division_points ({a..b} \<inter> {x. x$k \<ge> c}) {l \<inter> {x. x$k \<ge> c} | l. l\<in>d \<and> l \<inter> {x. x$k \<ge> c} \<noteq> {}} \<subset> division_points ({a..b}) d" (is "?D2 \<subset> ?D") 
  5.1851 +proof- have ab:"\<forall>i. a$i \<le> b$i" using assms(2) by(auto intro!:less_imp_le)
  5.1852 +  guess u v using division_ofD(4)[OF assms(1,5)] apply-by(erule exE)+ note l=this
  5.1853 +  have uv:"\<forall>i. u$i \<le> v$i" "\<forall>i. a$i \<le> u$i \<and> v$i \<le> b$i" using division_ofD(2,2,3)[OF assms(1,5)] unfolding l interval_ne_empty
  5.1854 +    unfolding subset_eq apply- defer apply(erule_tac x=u in ballE, erule_tac x=v in ballE) unfolding mem_interval by auto
  5.1855 +  have *:"interval_upperbound ({a..b} \<inter> {x. x $ k \<le> interval_upperbound l $ k}) $ k = interval_upperbound l $ k"
  5.1856 +         "interval_upperbound ({a..b} \<inter> {x. x $ k \<le> interval_lowerbound l $ k}) $ k = interval_lowerbound l $ k"
  5.1857 +    unfolding interval_split apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  5.1858 +    unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab by auto
  5.1859 +  have "\<exists>x. x \<in> ?D - ?D1" using assms(2-) apply-apply(erule disjE)
  5.1860 +    apply(rule_tac x="(k,(interval_lowerbound l)$k)" in exI) defer
  5.1861 +    apply(rule_tac x="(k,(interval_upperbound l)$k)" in exI)
  5.1862 +    unfolding division_points_def unfolding interval_bounds[OF ab]
  5.1863 +    apply (auto simp add:interval_bounds) unfolding * by auto
  5.1864 +  thus "?D1 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4)]) by auto
  5.1865 +
  5.1866 +  have *:"interval_lowerbound ({a..b} \<inter> {x. x $ k \<ge> interval_lowerbound l $ k}) $ k = interval_lowerbound l $ k"
  5.1867 +         "interval_lowerbound ({a..b} \<inter> {x. x $ k \<ge> interval_upperbound l $ k}) $ k = interval_upperbound l $ k"
  5.1868 +    unfolding interval_split apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  5.1869 +    unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab by auto
  5.1870 +  have "\<exists>x. x \<in> ?D - ?D2" using assms(2-) apply-apply(erule disjE)
  5.1871 +    apply(rule_tac x="(k,(interval_lowerbound l)$k)" in exI) defer
  5.1872 +    apply(rule_tac x="(k,(interval_upperbound l)$k)" in exI)
  5.1873 +    unfolding division_points_def unfolding interval_bounds[OF ab]
  5.1874 +    apply (auto simp add:interval_bounds) unfolding * by auto
  5.1875 +  thus "?D2 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4)]) by auto qed
  5.1876 +
  5.1877 +subsection {* Preservation by divisions and tagged divisions. *}
  5.1878 +
  5.1879 +lemma support_support[simp]:"support opp f (support opp f s) = support opp f s"
  5.1880 +  unfolding support_def by auto
  5.1881 +
  5.1882 +lemma iterate_support[simp]: "iterate opp (support opp f s) f = iterate opp s f"
  5.1883 +  unfolding iterate_def support_support by auto
  5.1884 +
  5.1885 +lemma iterate_expand_cases:
  5.1886 +  "iterate opp s f = (if finite(support opp f s) then iterate opp (support opp f s) f else neutral opp)"
  5.1887 +  apply(cases) apply(subst if_P,assumption) unfolding iterate_def support_support fold'_def by auto 
  5.1888 +
  5.1889 +lemma iterate_image: assumes "monoidal opp"  "inj_on f s"
  5.1890 +  shows "iterate opp (f ` s) g = iterate opp s (g \<circ> f)"
  5.1891 +proof- have *:"\<And>s. finite s \<Longrightarrow>  \<forall>x\<in>s. \<forall>y\<in>s. f x = f y \<longrightarrow> x = y \<Longrightarrow>
  5.1892 +     iterate opp (f ` s) g = iterate opp s (g \<circ> f)"
  5.1893 +  proof- case goal1 show ?case using goal1
  5.1894 +    proof(induct s) case empty thus ?case using assms(1) by auto
  5.1895 +    next case (insert x s) show ?case unfolding iterate_insert[OF assms(1) insert(1)]
  5.1896 +        unfolding if_not_P[OF insert(2)] apply(subst insert(3)[THEN sym])
  5.1897 +        unfolding image_insert defer apply(subst iterate_insert[OF assms(1)])
  5.1898 +        apply(rule finite_imageI insert)+ apply(subst if_not_P)
  5.1899 +        unfolding image_iff o_def using insert(2,4) by auto
  5.1900 +    qed qed
  5.1901 +  show ?thesis 
  5.1902 +    apply(cases "finite (support opp g (f ` s))")
  5.1903 +    apply(subst (1) iterate_support[THEN sym],subst (2) iterate_support[THEN sym])
  5.1904 +    unfolding support_clauses apply(rule *)apply(rule finite_imageD,assumption) unfolding inj_on_def[symmetric]
  5.1905 +    apply(rule subset_inj_on[OF assms(2) support_subset])+
  5.1906 +    apply(subst iterate_expand_cases) unfolding support_clauses apply(simp only: if_False)
  5.1907 +    apply(subst iterate_expand_cases) apply(subst if_not_P) by auto qed
  5.1908 +
  5.1909 +
  5.1910 +(* This lemma about iterations comes up in a few places.                     *)
  5.1911 +lemma iterate_nonzero_image_lemma:
  5.1912 +  assumes "monoidal opp" "finite s" "g(a) = neutral opp"
  5.1913 +  "\<forall>x\<in>s. \<forall>y\<in>s. f x = f y \<and> x \<noteq> y \<longrightarrow> g(f x) = neutral opp"
  5.1914 +  shows "iterate opp {f x | x. x \<in> s \<and> f x \<noteq> a} g = iterate opp s (g \<circ> f)"
  5.1915 +proof- have *:"{f x |x. x \<in> s \<and> ~(f x = a)} = f ` {x. x \<in> s \<and> ~(f x = a)}" by auto
  5.1916 +  have **:"support opp (g \<circ> f) {x \<in> s. f x \<noteq> a} = support opp (g \<circ> f) s"
  5.1917 +    unfolding support_def using assms(3) by auto
  5.1918 +  show ?thesis unfolding *
  5.1919 +    apply(subst iterate_support[THEN sym]) unfolding support_clauses
  5.1920 +    apply(subst iterate_image[OF assms(1)]) defer
  5.1921 +    apply(subst(2) iterate_support[THEN sym]) apply(subst **)
  5.1922 +    unfolding inj_on_def using assms(3,4) unfolding support_def by auto qed
  5.1923 +
  5.1924 +lemma iterate_eq_neutral:
  5.1925 +  assumes "monoidal opp"  "\<forall>x \<in> s. (f(x) = neutral opp)"
  5.1926 +  shows "(iterate opp s f = neutral opp)"
  5.1927 +proof- have *:"support opp f s = {}" unfolding support_def using assms(2) by auto
  5.1928 +  show ?thesis apply(subst iterate_support[THEN sym]) 
  5.1929 +    unfolding * using assms(1) by auto qed
  5.1930 +
  5.1931 +lemma iterate_op: assumes "monoidal opp" "finite s"
  5.1932 +  shows "iterate opp s (\<lambda>x. opp (f x) (g x)) = opp (iterate opp s f) (iterate opp s g)" using assms(2)
  5.1933 +proof(induct s) case empty thus ?case unfolding iterate_insert[OF assms(1)] using assms(1) by auto
  5.1934 +next case (insert x F) show ?case unfolding iterate_insert[OF assms(1) insert(1)] if_not_P[OF insert(2)] insert(3)
  5.1935 +    unfolding monoidal_ac[OF assms(1)] by(rule refl) qed
  5.1936 +
  5.1937 +lemma iterate_eq: assumes "monoidal opp" "\<And>x. x \<in> s \<Longrightarrow> f x = g x"
  5.1938 +  shows "iterate opp s f = iterate opp s g"
  5.1939 +proof- have *:"support opp g s = support opp f s"
  5.1940 +    unfolding support_def using assms(2) by auto
  5.1941 +  show ?thesis
  5.1942 +  proof(cases "finite (support opp f s)")
  5.1943 +    case False thus ?thesis apply(subst iterate_expand_cases,subst(2) iterate_expand_cases)
  5.1944 +      unfolding * by auto
  5.1945 +  next def su \<equiv> "support opp f s"
  5.1946 +    case True note support_subset[of opp f s] 
  5.1947 +    thus ?thesis apply- apply(subst iterate_support[THEN sym],subst(2) iterate_support[THEN sym]) unfolding * using True
  5.1948 +      unfolding su_def[symmetric]
  5.1949 +    proof(induct su) case empty show ?case by auto
  5.1950 +    next case (insert x s) show ?case unfolding iterate_insert[OF assms(1) insert(1)] 
  5.1951 +        unfolding if_not_P[OF insert(2)] apply(subst insert(3))
  5.1952 +        defer apply(subst assms(2)[of x]) using insert by auto qed qed qed
  5.1953 +
  5.1954 +lemma nonempty_witness: assumes "s \<noteq> {}" obtains x where "x \<in> s" using assms by auto
  5.1955 +
  5.1956 +lemma operative_division: fixes f::"(real^'n) set \<Rightarrow> 'a"
  5.1957 +  assumes "monoidal opp" "operative opp f" "d division_of {a..b}"
  5.1958 +  shows "iterate opp d f = f {a..b}"
  5.1959 +proof- def C \<equiv> "card (division_points {a..b} d)" thus ?thesis using assms
  5.1960 +  proof(induct C arbitrary:a b d rule:full_nat_induct)
  5.1961 +    case goal1
  5.1962 +    { presume *:"content {a..b} \<noteq> 0 \<Longrightarrow> ?case"
  5.1963 +      thus ?case apply-apply(cases) defer apply assumption
  5.1964 +      proof- assume as:"content {a..b} = 0"
  5.1965 +        show ?case unfolding operativeD(1)[OF assms(2) as] apply(rule iterate_eq_neutral[OF goal1(2)])
  5.1966 +        proof fix x assume x:"x\<in>d"
  5.1967 +          then guess u v apply(drule_tac division_ofD(4)[OF goal1(4)]) by(erule exE)+
  5.1968 +          thus "f x = neutral opp" using division_of_content_0[OF as goal1(4)] 
  5.1969 +            using operativeD(1)[OF assms(2)] x by auto
  5.1970 +        qed qed }
  5.1971 +    assume "content {a..b} \<noteq> 0" note ab = this[unfolded content_lt_nz[THEN sym] content_pos_lt_eq]
  5.1972 +    hence ab':"\<forall>i. a$i \<le> b$i" by (auto intro!: less_imp_le) show ?case 
  5.1973 +    proof(cases "division_points {a..b} d = {}")
  5.1974 +      case True have d':"\<forall>i\<in>d. \<exists>u v. i = {u..v} \<and>
  5.1975 +        (\<forall>j. u$j = a$j \<and> v$j = a$j \<or> u$j = b$j \<and> v$j = b$j \<or> u$j = a$j \<and> v$j = b$j)"
  5.1976 +        unfolding forall_in_division[OF goal1(4)] apply(rule,rule,rule)
  5.1977 +        apply(rule_tac x=a in exI,rule_tac x=b in exI) apply(rule,rule refl) apply(rule)
  5.1978 +      proof- fix u v j assume as:"{u..v} \<in> d" note division_ofD(3)[OF goal1(4) this]
  5.1979 +        hence uv:"\<forall>i. u$i \<le> v$i" "u$j \<le> v$j" unfolding interval_ne_empty by auto
  5.1980 +        have *:"\<And>p r Q. p \<or> r \<or> (\<forall>x\<in>d. Q x) \<Longrightarrow> p \<or> r \<or> (Q {u..v})" using as by auto
  5.1981 +        have "(j, u$j) \<notin> division_points {a..b} d"
  5.1982 +          "(j, v$j) \<notin> division_points {a..b} d" using True by auto
  5.1983 +        note this[unfolded de_Morgan_conj division_points_def mem_Collect_eq split_conv interval_bounds[OF ab'] bex_simps]
  5.1984 +        note *[OF this(1)] *[OF this(2)] note this[unfolded interval_bounds[OF uv(1)]]
  5.1985 +        moreover have "a$j \<le> u$j" "v$j \<le> b$j" using division_ofD(2,2,3)[OF goal1(4) as] 
  5.1986 +          unfolding subset_eq apply- apply(erule_tac x=u in ballE,erule_tac[3] x=v in ballE)
  5.1987 +          unfolding interval_ne_empty mem_interval by auto
  5.1988 +        ultimately show "u$j = a$j \<and> v$j = a$j \<or> u$j = b$j \<and> v$j = b$j \<or> u$j = a$j \<and> v$j = b$j"
  5.1989 +          unfolding not_less de_Morgan_disj using ab[rule_format,of j] uv(2) by auto
  5.1990 +      qed have "(1/2) *\<^sub>R (a+b) \<in> {a..b}" unfolding mem_interval using ab by(auto intro!:less_imp_le)
  5.1991 +      note this[unfolded division_ofD(6)[OF goal1(4),THEN sym] Union_iff]
  5.1992 +      then guess i .. note i=this guess u v using d'[rule_format,OF i(1)] apply-by(erule exE conjE)+ note uv=this
  5.1993 +      have "{a..b} \<in> d"
  5.1994 +      proof- { presume "i = {a..b}" thus ?thesis using i by auto }
  5.1995 +        { presume "u = a" "v = b" thus "i = {a..b}" using uv by auto }
  5.1996 +        show "u = a" "v = b" unfolding Cart_eq
  5.1997 +        proof(rule_tac[!] allI) fix j note i(2)[unfolded uv mem_interval,rule_format,of j]
  5.1998 +          thus "u $ j = a $ j" "v $ j = b $ j" using uv(2)[rule_format,of j] by auto
  5.1999 +        qed qed
  5.2000 +      hence *:"d = insert {a..b} (d - {{a..b}})" by auto
  5.2001 +      have "iterate opp (d - {{a..b}}) f = neutral opp" apply(rule iterate_eq_neutral[OF goal1(2)])
  5.2002 +      proof fix x assume x:"x \<in> d - {{a..b}}" hence "x\<in>d" by auto note d'[rule_format,OF this]
  5.2003 +        then guess u v apply-by(erule exE conjE)+ note uv=this
  5.2004 +        have "u\<noteq>a \<or> v\<noteq>b" using x[unfolded uv] by auto  
  5.2005 +        then obtain j where "u$j \<noteq> a$j \<or> v$j \<noteq> b$j" unfolding Cart_eq by auto
  5.2006 +        hence "u$j = v$j" using uv(2)[rule_format,of j] by auto
  5.2007 +        hence "content {u..v} = 0"  unfolding content_eq_0 apply(rule_tac x=j in exI) by auto
  5.2008 +        thus "f x = neutral opp" unfolding uv(1) by(rule operativeD(1)[OF goal1(3)])
  5.2009 +      qed thus "iterate opp d f = f {a..b}" apply-apply(subst *) 
  5.2010 +        apply(subst iterate_insert[OF goal1(2)]) using goal1(2,4) by auto
  5.2011 +    next case False hence "\<exists>x. x\<in>division_points {a..b} d" by auto
  5.2012 +      then guess k c unfolding split_paired_Ex apply- unfolding division_points_def mem_Collect_eq split_conv
  5.2013 +        by(erule exE conjE)+ note kc=this[unfolded interval_bounds[OF ab']]
  5.2014 +      from this(3) guess j .. note j=this
  5.2015 +      def d1 \<equiv> "{l \<inter> {x. x$k \<le> c} | l. l \<in> d \<and> l \<inter> {x. x$k \<le> c} \<noteq> {}}"
  5.2016 +      def d2 \<equiv> "{l \<inter> {x. x$k \<ge> c} | l. l \<in> d \<and> l \<inter> {x. x$k \<ge> c} \<noteq> {}}"
  5.2017 +      def cb \<equiv> "(\<chi> i. if i = k then c else b$i)" and ca \<equiv> "(\<chi> i. if i = k then c else a$i)"
  5.2018 +      note division_points_psubset[OF goal1(4) ab kc(1-2) j]
  5.2019 +      note psubset_card_mono[OF _ this(1)] psubset_card_mono[OF _ this(2)]
  5.2020 +      hence *:"(iterate opp d1 f) = f ({a..b} \<inter> {x. x$k \<le> c})" "(iterate opp d2 f) = f ({a..b} \<inter> {x. x$k \<ge> c})"
  5.2021 +        apply- unfolding interval_split apply(rule_tac[!] goal1(1)[rule_format])
  5.2022 +        using division_split[OF goal1(4), where k=k and c=c]
  5.2023 +        unfolding interval_split d1_def[symmetric] d2_def[symmetric] unfolding goal1(2) Suc_le_mono
  5.2024 +        using goal1(2-3) using division_points_finite[OF goal1(4)] by auto
  5.2025 +      have "f {a..b} = opp (iterate opp d1 f) (iterate opp d2 f)" (is "_ = ?prev")
  5.2026 +        unfolding * apply(rule operativeD(2)) using goal1(3) .
  5.2027 +      also have "iterate opp d1 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x$k \<le> c}))"
  5.2028 +        unfolding d1_def apply(rule iterate_nonzero_image_lemma[unfolded o_def])
  5.2029 +        unfolding empty_as_interval apply(rule goal1 division_of_finite operativeD[OF goal1(3)])+
  5.2030 +        unfolding empty_as_interval[THEN sym] apply(rule content_empty)
  5.2031 +      proof(rule,rule,rule,erule conjE) fix l y assume as:"l \<in> d" "y \<in> d" "l \<inter> {x. x $ k \<le> c} = y \<inter> {x. x $ k \<le> c}" "l \<noteq> y" 
  5.2032 +        from division_ofD(4)[OF goal1(4) this(1)] guess u v apply-by(erule exE)+ note l=this
  5.2033 +        show "f (l \<inter> {x. x $ k \<le> c}) = neutral opp" unfolding l interval_split
  5.2034 +          apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym] apply(rule division_split_left_inj)
  5.2035 +          apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule as)+
  5.2036 +      qed also have "iterate opp d2 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x$k \<ge> c}))"
  5.2037 +        unfolding d2_def apply(rule iterate_nonzero_image_lemma[unfolded o_def])
  5.2038 +        unfolding empty_as_interval apply(rule goal1 division_of_finite operativeD[OF goal1(3)])+
  5.2039 +        unfolding empty_as_interval[THEN sym] apply(rule content_empty)
  5.2040 +      proof(rule,rule,rule,erule conjE) fix l y assume as:"l \<in> d" "y \<in> d" "l \<inter> {x. c \<le> x $ k} = y \<inter> {x. c \<le> x $ k}" "l \<noteq> y" 
  5.2041 +        from division_ofD(4)[OF goal1(4) this(1)] guess u v apply-by(erule exE)+ note l=this
  5.2042 +        show "f (l \<inter> {x. x $ k \<ge> c}) = neutral opp" unfolding l interval_split
  5.2043 +          apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym] apply(rule division_split_right_inj)
  5.2044 +          apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule as)+
  5.2045 +      qed also have *:"\<forall>x\<in>d. f x = opp (f (x \<inter> {x. x $ k \<le> c})) (f (x \<inter> {x. c \<le> x $ k}))"
  5.2046 +        unfolding forall_in_division[OF goal1(4)] apply(rule,rule,rule,rule operativeD(2)) using goal1(3) .
  5.2047 +      have "opp (iterate opp d (\<lambda>l. f (l \<inter> {x. x $ k \<le> c}))) (iterate opp d (\<lambda>l. f (l \<inter> {x. c \<le> x $ k})))
  5.2048 +        = iterate opp d f" apply(subst(3) iterate_eq[OF _ *[rule_format]]) prefer 3
  5.2049 +        apply(rule iterate_op[THEN sym]) using goal1 by auto
  5.2050 +      finally show ?thesis by auto
  5.2051 +    qed qed qed 
  5.2052 +
  5.2053 +lemma iterate_image_nonzero: assumes "monoidal opp"
  5.2054 +  "finite s" "\<forall>x\<in>s. \<forall>y\<in>s. ~(x = y) \<and> f x = f y \<longrightarrow> g(f x) = neutral opp"
  5.2055 +  shows "iterate opp (f ` s) g = iterate opp s (g \<circ> f)" using assms
  5.2056 +proof(induct rule:finite_subset_induct[OF assms(2) subset_refl])
  5.2057 +  case goal1 show ?case using assms(1) by auto
  5.2058 +next case goal2 have *:"\<And>x y. y = neutral opp \<Longrightarrow> x = opp y x" using assms(1) by auto
  5.2059 +  show ?case unfolding image_insert apply(subst iterate_insert[OF assms(1)])
  5.2060 +    apply(rule finite_imageI goal2)+
  5.2061 +    apply(cases "f a \<in> f ` F") unfolding if_P if_not_P apply(subst goal2(4)[OF assms(1) goal2(1)]) defer
  5.2062 +    apply(subst iterate_insert[OF assms(1) goal2(1)]) defer
  5.2063 +    apply(subst iterate_insert[OF assms(1) goal2(1)])
  5.2064 +    unfolding if_not_P[OF goal2(3)] defer unfolding image_iff defer apply(erule bexE)
  5.2065 +    apply(rule *) unfolding o_def apply(rule_tac y=x in goal2(7)[rule_format])
  5.2066 +    using goal2 unfolding o_def by auto qed 
  5.2067 +
  5.2068 +lemma operative_tagged_division: assumes "monoidal opp" "operative opp f" "d tagged_division_of {a..b}"
  5.2069 +  shows "iterate(opp) d (\<lambda>(x,l). f l) = f {a..b}"
  5.2070 +proof- have *:"(\<lambda>(x,l). f l) = (f o snd)" unfolding o_def by(rule,auto) note assm = tagged_division_ofD[OF assms(3)]
  5.2071 +  have "iterate(opp) d (\<lambda>(x,l). f l) = iterate opp (snd ` d) f" unfolding *
  5.2072 +    apply(rule iterate_image_nonzero[THEN sym,OF assms(1)]) apply(rule tagged_division_of_finite assms)+ 
  5.2073 +    unfolding Ball_def split_paired_All snd_conv apply(rule,rule,rule,rule,rule,rule,rule,erule conjE)
  5.2074 +  proof- fix a b aa ba assume as:"(a, b) \<in> d" "(aa, ba) \<in> d" "(a, b) \<noteq> (aa, ba)" "b = ba"
  5.2075 +    guess u v using assm(4)[OF as(1)] apply-by(erule exE)+ note uv=this
  5.2076 +    show "f b = neutral opp" unfolding uv apply(rule operativeD(1)[OF assms(2)])
  5.2077 +      unfolding content_eq_0_interior using tagged_division_ofD(5)[OF assms(3) as(1-3)]
  5.2078 +      unfolding as(4)[THEN sym] uv by auto
  5.2079 +  qed also have "\<dots> = f {a..b}" 
  5.2080 +    using operative_division[OF assms(1-2) division_of_tagged_division[OF assms(3)]] .
  5.2081 +  finally show ?thesis . qed
  5.2082 +
  5.2083 +subsection {* Additivity of content. *}
  5.2084 +
  5.2085 +lemma setsum_iterate:assumes "finite s" shows "setsum f s = iterate op + s f"
  5.2086 +proof- have *:"setsum f s = setsum f (support op + f s)"
  5.2087 +    apply(rule setsum_mono_zero_right)
  5.2088 +    unfolding support_def neutral_monoid using assms by auto
  5.2089 +  thus ?thesis unfolding * setsum_def iterate_def fold_image_def fold'_def
  5.2090 +    unfolding neutral_monoid . qed
  5.2091 +
  5.2092 +lemma additive_content_division: assumes "d division_of {a..b}"
  5.2093 +  shows "setsum content d = content({a..b})"
  5.2094 +  unfolding operative_division[OF monoidal_monoid operative_content assms,THEN sym]
  5.2095 +  apply(subst setsum_iterate) using assms by auto
  5.2096 +
  5.2097 +lemma additive_content_tagged_division:
  5.2098 +  assumes "d tagged_division_of {a..b}"
  5.2099 +  shows "setsum (\<lambda>(x,l). content l) d = content({a..b})"
  5.2100 +  unfolding operative_tagged_division[OF monoidal_monoid operative_content assms,THEN sym]
  5.2101 +  apply(subst setsum_iterate) using assms by auto
  5.2102 +
  5.2103 +subsection {* Finally, the integral of a constant\<forall> *}
  5.2104 +
  5.2105 +lemma has_integral_const[intro]:
  5.2106 +  "((\<lambda>x. c) has_integral (content({a..b::real^'n}) *\<^sub>R c)) ({a..b})"
  5.2107 +  unfolding has_integral apply(rule,rule,rule_tac x="\<lambda>x. ball x 1" in exI)
  5.2108 +  apply(rule,rule gauge_trivial)apply(rule,rule,erule conjE)
  5.2109 +  unfolding split_def apply(subst scaleR_left.setsum[THEN sym, unfolded o_def])
  5.2110 +  defer apply(subst additive_content_tagged_division[unfolded split_def]) apply assumption by auto
  5.2111 +
  5.2112 +subsection {* Bounds on the norm of Riemann sums and the integral itself. *}
  5.2113 +
  5.2114 +lemma dsum_bound: assumes "p division_of {a..b}" "norm(c) \<le> e"
  5.2115 +  shows "norm(setsum (\<lambda>l. content l *\<^sub>R c) p) \<le> e * content({a..b})" (is "?l \<le> ?r")
  5.2116 +  apply(rule order_trans,rule setsum_norm) defer unfolding norm_scaleR setsum_left_distrib[THEN sym]
  5.2117 +  apply(rule order_trans[OF mult_left_mono],rule assms,rule setsum_abs_ge_zero)
  5.2118 +  apply(subst real_mult_commute) apply(rule mult_left_mono)
  5.2119 +  apply(rule order_trans[of _ "setsum content p"]) apply(rule eq_refl,rule setsum_cong2)
  5.2120 +  apply(subst abs_of_nonneg) unfolding additive_content_division[OF assms(1)]
  5.2121 +proof- from order_trans[OF norm_ge_zero[of c] assms(2)] show "0 \<le> e" .
  5.2122 +  fix x assume "x\<in>p" from division_ofD(4)[OF assms(1) this] guess u v apply-by(erule exE)+
  5.2123 +  thus "0 \<le> content x" using content_pos_le by auto
  5.2124 +qed(insert assms,auto)
  5.2125 +
  5.2126 +lemma rsum_bound: assumes "p tagged_division_of {a..b}" "\<forall>x\<in>{a..b}. norm(f x) \<le> e"
  5.2127 +  shows "norm(setsum (\<lambda>(x,k). content k *\<^sub>R f x) p) \<le> e * content({a..b})"
  5.2128 +proof(cases "{a..b} = {}") case True
  5.2129 +  show ?thesis using assms(1) unfolding True tagged_division_of_trivial by auto
  5.2130 +next case False show ?thesis
  5.2131 +    apply(rule order_trans,rule setsum_norm) defer unfolding split_def norm_scaleR
  5.2132 +    apply(rule order_trans[OF setsum_mono]) apply(rule mult_left_mono[OF _ abs_ge_zero, of _ e]) defer
  5.2133 +    unfolding setsum_left_distrib[THEN sym] apply(subst real_mult_commute) apply(rule mult_left_mono)
  5.2134 +    apply(rule order_trans[of _ "setsum (content \<circ> snd) p"]) apply(rule eq_refl,rule setsum_cong2)
  5.2135 +    apply(subst o_def, rule abs_of_nonneg)
  5.2136 +  proof- show "setsum (content \<circ> snd) p \<le> content {a..b}" apply(rule eq_refl)
  5.2137 +      unfolding additive_content_tagged_division[OF assms(1),THEN sym] split_def by auto
  5.2138 +    guess w using nonempty_witness[OF False] .
  5.2139 +    thus "e\<ge>0" apply-apply(rule order_trans) defer apply(rule assms(2)[rule_format],assumption) by auto
  5.2140 +    fix xk assume *:"xk\<in>p" guess x k  using surj_pair[of xk] apply-by(erule exE)+ note xk = this *[unfolded this]
  5.2141 +    from tagged_division_ofD(4)[OF assms(1) xk(2)] guess u v apply-by(erule exE)+ note uv=this
  5.2142 +    show "0\<le> content (snd xk)" unfolding xk snd_conv uv by(rule content_pos_le)
  5.2143 +    show "norm (f (fst xk)) \<le> e" unfolding xk fst_conv using tagged_division_ofD(2,3)[OF assms(1) xk(2)] assms(2) by auto
  5.2144 +  qed(insert assms,auto) qed
  5.2145 +
  5.2146 +lemma rsum_diff_bound:
  5.2147 +  assumes "p tagged_division_of {a..b}"  "\<forall>x\<in>{a..b}. norm(f x - g x) \<le> e"
  5.2148 +  shows "norm(setsum (\<lambda>(x,k). content k *\<^sub>R f x) p - setsum (\<lambda>(x,k). content k *\<^sub>R g x) p) \<le> e * content({a..b})"
  5.2149 +  apply(rule order_trans[OF _ rsum_bound[OF assms]]) apply(rule eq_refl) apply(rule arg_cong[where f=norm])
  5.2150 +  unfolding setsum_subtractf[THEN sym] apply(rule setsum_cong2) unfolding scaleR.diff_right by auto
  5.2151 +
  5.2152 +lemma has_integral_bound: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  5.2153 +  assumes "0 \<le> B" "(f has_integral i) ({a..b})" "\<forall>x\<in>{a..b}. norm(f x) \<le> B"
  5.2154 +  shows "norm i \<le> B * content {a..b}"
  5.2155 +proof- let ?P = "content {a..b} > 0" { presume "?P \<Longrightarrow> ?thesis"
  5.2156 +    thus ?thesis proof(cases ?P) case False
  5.2157 +      hence *:"content {a..b} = 0" using content_lt_nz by auto
  5.2158 +      hence **:"i = 0" using assms(2) apply(subst has_integral_null_eq[THEN sym]) by auto
  5.2159 +      show ?thesis unfolding * ** using assms(1) by auto
  5.2160 +    qed auto } assume ab:?P
  5.2161 +  { presume "\<not> ?thesis \<Longrightarrow> False" thus ?thesis by auto }
  5.2162 +  assume "\<not> ?thesis" hence *:"norm i - B * content {a..b} > 0" by auto
  5.2163 +  from assms(2)[unfolded has_integral,rule_format,OF *] guess d apply-by(erule exE conjE)+ note d=this[rule_format]
  5.2164 +  from fine_division_exists[OF this(1), of a b] guess p . note p=this
  5.2165 +  have *:"\<And>s B. norm s \<le> B \<Longrightarrow> \<not> (norm (s - i) < norm i - B)"
  5.2166 +  proof- case goal1 thus ?case unfolding not_less
  5.2167 +    using norm_triangle_sub[of i s] unfolding norm_minus_commute by auto
  5.2168 +  qed show False using d(2)[OF conjI[OF p]] *[OF rsum_bound[OF p(1) assms(3)]] by auto qed
  5.2169 +
  5.2170 +subsection {* Similar theorems about relationship among components. *}
  5.2171 +
  5.2172 +lemma rsum_component_le: fixes f::"real^'n \<Rightarrow> real^'m"
  5.2173 +  assumes "p tagged_division_of {a..b}"  "\<forall>x\<in>{a..b}. (f x)$i \<le> (g x)$i"
  5.2174 +  shows "(setsum (\<lambda>(x,k). content k *\<^sub>R f x) p)$i \<le> (setsum (\<lambda>(x,k). content k *\<^sub>R g x) p)$i"
  5.2175 +  unfolding setsum_component apply(rule setsum_mono)
  5.2176 +  apply(rule mp) defer apply assumption apply(induct_tac x,rule) unfolding split_conv
  5.2177 +proof- fix a b assume ab:"(a,b) \<in> p" note assm = tagged_division_ofD(2-4)[OF assms(1) ab]
  5.2178 +  from this(3) guess u v apply-by(erule exE)+ note b=this
  5.2179 +  show "(content b *\<^sub>R f a) $ i \<le> (content b *\<^sub>R g a) $ i" unfolding b
  5.2180 +    unfolding Cart_nth.scaleR real_scaleR_def apply(rule mult_left_mono)
  5.2181 +    defer apply(rule content_pos_le,rule assms(2)[rule_format]) using assm by auto qed
  5.2182 +
  5.2183 +lemma has_integral_component_le: fixes f::"real^'n \<Rightarrow> real^'m"
  5.2184 +  assumes "(f has_integral i) s" "(g has_integral j) s"  "\<forall>x\<in>s. (f x)$k \<le> (g x)$k"
  5.2185 +  shows "i$k \<le> j$k"
  5.2186 +proof- have lem:"\<And>a b g i j. \<And>f::real^'n \<Rightarrow> real^'m. (f has_integral i) ({a..b}) \<Longrightarrow> 
  5.2187 +    (g has_integral j) ({a..b}) \<Longrightarrow> \<forall>x\<in>{a..b}. (f x)$k \<le> (g x)$k \<Longrightarrow> i$k \<le> j$k"
  5.2188 +  proof(rule ccontr) case goal1 hence *:"0 < (i$k - j$k) / 3" by auto
  5.2189 +    guess d1 using goal1(1)[unfolded has_integral,rule_format,OF *] apply-by(erule exE conjE)+ note d1=this[rule_format]
  5.2190 +    guess d2 using goal1(2)[unfolded has_integral,rule_format,OF *] apply-by(erule exE conjE)+ note d2=this[rule_format]
  5.2191 +    guess p using fine_division_exists[OF gauge_inter[OF d1(1) d2(1)], of a b] unfolding fine_inter .
  5.2192 +    note p = this(1) conjunctD2[OF this(2)]  note le_less_trans[OF component_le_norm, of _ _ k]
  5.2193 +    note this[OF d1(2)[OF conjI[OF p(1,2)]]] this[OF d2(2)[OF conjI[OF p(1,3)]]]
  5.2194 +    thus False unfolding Cart_nth.diff using rsum_component_le[OF p(1) goal1(3)] by smt
  5.2195 +  qed let ?P = "\<exists>a b. s = {a..b}"
  5.2196 +  { presume "\<not> ?P \<Longrightarrow> ?thesis" thus ?thesis proof(cases ?P)
  5.2197 +      case True then guess a b apply-by(erule exE)+ note s=this
  5.2198 +      show ?thesis apply(rule lem) using assms[unfolded s] by auto
  5.2199 +    qed auto } assume as:"\<not> ?P"
  5.2200 +  { presume "\<not> ?thesis \<Longrightarrow> False" thus ?thesis by auto }
  5.2201 +  assume "\<not> i$k \<le> j$k" hence ij:"(i$k - j$k) / 3 > 0" by auto
  5.2202 +  note has_integral_altD[OF _ as this] from this[OF assms(1)] this[OF assms(2)] guess B1 B2 . note B=this[rule_format]
  5.2203 +  have "bounded (ball 0 B1 \<union> ball (0::real^'n) B2)" unfolding bounded_Un by(rule conjI bounded_ball)+
  5.2204 +  from bounded_subset_closed_interval[OF this] guess a b apply- by(erule exE)+
  5.2205 +  note ab = conjunctD2[OF this[unfolded Un_subset_iff]]
  5.2206 +  guess w1 using B(2)[OF ab(1)] .. note w1=conjunctD2[OF this]
  5.2207 +  guess w2 using B(4)[OF ab(2)] .. note w2=conjunctD2[OF this]
  5.2208 +  have *:"\<And>w1 w2 j i::real .\<bar>w1 - i\<bar> < (i - j) / 3 \<Longrightarrow> \<bar>w2 - j\<bar> < (i - j) / 3 \<Longrightarrow> w1 \<le> w2 \<Longrightarrow> False" by smt(*SMTSMT*)
  5.2209 +  note le_less_trans[OF component_le_norm[of _ k]] note this[OF w1(2)] this[OF w2(2)] moreover
  5.2210 +  have "w1$k \<le> w2$k" apply(rule lem[OF w1(1) w2(1)]) using assms by auto ultimately
  5.2211 +  show False unfolding Cart_nth.diff by(rule *) qed
  5.2212 +
  5.2213 +lemma integral_component_le: fixes f::"real^'n \<Rightarrow> real^'m"
  5.2214 +  assumes "f integrable_on s" "g integrable_on s"  "\<forall>x\<in>s. (f x)$k \<le> (g x)$k"
  5.2215 +  shows "(integral s f)$k \<le> (integral s g)$k"
  5.2216 +  apply(rule has_integral_component_le) using integrable_integral assms by auto
  5.2217 +
  5.2218 +lemma has_integral_dest_vec1_le: fixes f::"real^'n \<Rightarrow> real^1"
  5.2219 +  assumes "(f has_integral i) s"  "(g has_integral j) s" "\<forall>x\<in>s. f x \<le> g x"
  5.2220 +  shows "dest_vec1 i \<le> dest_vec1 j" apply(rule has_integral_component_le[OF assms(1-2)])
  5.2221 +  using assms(3) unfolding vector_le_def by auto
  5.2222 +
  5.2223 +lemma integral_dest_vec1_le: fixes f::"real^'n \<Rightarrow> real^1"
  5.2224 +  assumes "f integrable_on s" "g integrable_on s" "\<forall>x\<in>s. f x \<le> g x"
  5.2225 +  shows "dest_vec1(integral s f) \<le> dest_vec1(integral s g)"
  5.2226 +  apply(rule has_integral_dest_vec1_le) apply(rule_tac[1-2] integrable_integral) using assms by auto
  5.2227 +
  5.2228 +lemma has_integral_component_pos: fixes f::"real^'n \<Rightarrow> real^'m"
  5.2229 +  assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> (f x)$k" shows "0 \<le> i$k"
  5.2230 +  using has_integral_component_le[OF has_integral_0 assms(1)] using assms(2) by auto
  5.2231 +
  5.2232 +lemma integral_component_pos: fixes f::"real^'n \<Rightarrow> real^'m"
  5.2233 +  assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> (f x)$k" shows "0 \<le> (integral s f)$k"
  5.2234 +  apply(rule has_integral_component_pos) using assms by auto
  5.2235 +
  5.2236 +lemma has_integral_dest_vec1_pos: fixes f::"real^'n \<Rightarrow> real^1"
  5.2237 +  assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> i"
  5.2238 +  using has_integral_component_pos[OF assms(1), of 1]
  5.2239 +  using assms(2) unfolding vector_le_def by auto
  5.2240 +
  5.2241 +lemma integral_dest_vec1_pos: fixes f::"real^'n \<Rightarrow> real^1"
  5.2242 +  assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> integral s f"
  5.2243 +  apply(rule has_integral_dest_vec1_pos) using assms by auto
  5.2244 +
  5.2245 +lemma has_integral_component_neg: fixes f::"real^'n \<Rightarrow> real^'m"
  5.2246 +  assumes "(f has_integral i) s" "\<forall>x\<in>s. (f x)$k \<le> 0" shows "i$k \<le> 0"
  5.2247 +  using has_integral_component_le[OF assms(1) has_integral_0] assms(2) by auto
  5.2248 +
  5.2249 +lemma has_integral_dest_vec1_neg: fixes f::"real^'n \<Rightarrow> real^1"
  5.2250 +  assumes "(f has_integral i) s" "\<forall>x\<in>s. f x \<le> 0" shows "i \<le> 0"
  5.2251 +  using has_integral_component_neg[OF assms(1),of 1] using assms(2) by auto
  5.2252 +
  5.2253 +lemma has_integral_component_lbound:
  5.2254 +  assumes "(f has_integral i) {a..b}"  "\<forall>x\<in>{a..b}. B \<le> f(x)$k" shows "B * content {a..b} \<le> i$k"
  5.2255 +  using has_integral_component_le[OF has_integral_const assms(1),of "(\<chi> i. B)" k] assms(2)
  5.2256 +  unfolding Cart_lambda_beta vector_scaleR_component by(auto simp add:field_simps)
  5.2257 +
  5.2258 +lemma has_integral_component_ubound: 
  5.2259 +  assumes "(f has_integral i) {a..b}" "\<forall>x\<in>{a..b}. f x$k \<le> B"
  5.2260 +  shows "i$k \<le> B * content({a..b})"
  5.2261 +  using has_integral_component_le[OF assms(1) has_integral_const, of k "vec B"]
  5.2262 +  unfolding vec_component Cart_nth.scaleR using assms(2) by(auto simp add:field_simps)
  5.2263 +
  5.2264 +lemma integral_component_lbound:
  5.2265 +  assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. B \<le> f(x)$k"
  5.2266 +  shows "B * content({a..b}) \<le> (integral({a..b}) f)$k"
  5.2267 +  apply(rule has_integral_component_lbound) using assms unfolding has_integral_integral by auto
  5.2268 +
  5.2269 +lemma integral_component_ubound:
  5.2270 +  assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. f(x)$k \<le> B"
  5.2271 +  shows "(integral({a..b}) f)$k \<le> B * content({a..b})"
  5.2272 +  apply(rule has_integral_component_ubound) using assms unfolding has_integral_integral by auto
  5.2273 +
  5.2274 +subsection {* Uniform limit of integrable functions is integrable. *}
  5.2275 +
  5.2276 +lemma real_arch_invD:
  5.2277 +  "0 < (e::real) \<Longrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)"
  5.2278 +  by(subst(asm) real_arch_inv)
  5.2279 +
  5.2280 +lemma integrable_uniform_limit: fixes f::"real^'n \<Rightarrow> 'a::banach"
  5.2281 +  assumes "\<forall>e>0. \<exists>g. (\<forall>x\<in>{a..b}. norm(f x - g x) \<le> e) \<and> g integrable_on {a..b}"
  5.2282 +  shows "f integrable_on {a..b}"
  5.2283 +proof- { presume *:"content {a..b} > 0 \<Longrightarrow> ?thesis"
  5.2284 +    show ?thesis apply cases apply(rule *,assumption)
  5.2285 +      unfolding content_lt_nz integrable_on_def using has_integral_null by auto }
  5.2286 +  assume as:"content {a..b} > 0"
  5.2287 +  have *:"\<And>P. \<forall>e>(0::real). P e \<Longrightarrow> \<forall>n::nat. P (inverse (real n+1))" by auto
  5.2288 +  from choice[OF *[OF assms]] guess g .. note g=conjunctD2[OF this[rule_format],rule_format]
  5.2289 +  from choice[OF allI[OF g(2)[unfolded integrable_on_def], of "\<lambda>x. x"]] guess i .. note i=this[rule_format]
  5.2290 +  
  5.2291 +  have "Cauchy i" unfolding Cauchy_def
  5.2292 +  proof(rule,rule) fix e::real assume "e>0"
  5.2293 +    hence "e / 4 / content {a..b} > 0" using as by(auto simp add:field_simps)
  5.2294 +    then guess M apply-apply(subst(asm) real_arch_inv) by(erule exE conjE)+ note M=this
  5.2295 +    show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (i m) (i n) < e" apply(rule_tac x=M in exI,rule,rule,rule,rule)
  5.2296 +    proof- case goal1 have "e/4>0" using `e>0` by auto note * = i[unfolded has_integral,rule_format,OF this]
  5.2297 +      from *[of m] guess gm apply-by(erule conjE exE)+ note gm=this[rule_format]
  5.2298 +      from *[of n] guess gn apply-by(erule conjE exE)+ note gn=this[rule_format]
  5.2299 +      from fine_division_exists[OF gauge_inter[OF gm(1) gn(1)], of a b] guess p . note p=this
  5.2300 +      have lem2:"\<And>s1 s2 i1 i2. norm(s2 - s1) \<le> e/2 \<Longrightarrow> norm(s1 - i1) < e / 4 \<Longrightarrow> norm(s2 - i2) < e / 4 \<Longrightarrow>norm(i1 - i2) < e"
  5.2301 +      proof- case goal1 have "norm (i1 - i2) \<le> norm (i1 - s1) + norm (s1 - s2) + norm (s2 - i2)"
  5.2302 +          using norm_triangle_ineq[of "i1 - s1" "s1 - i2"]
  5.2303 +          using norm_triangle_ineq[of "s1 - s2" "s2 - i2"] by(auto simp add:group_simps)
  5.2304 +        also have "\<dots> < e" using goal1 unfolding norm_minus_commute by(auto simp add:group_simps)
  5.2305 +        finally show ?case .
  5.2306 +      qed
  5.2307 +      show ?case unfolding vector_dist_norm apply(rule lem2) defer
  5.2308 +        apply(rule gm(2)[OF conjI[OF p(1)]],rule_tac[2] gn(2)[OF conjI[OF p(1)]])
  5.2309 +        using conjunctD2[OF p(2)[unfolded fine_inter]] apply- apply assumption+ apply(rule order_trans)
  5.2310 +        apply(rule rsum_diff_bound[OF p(1), where e="2 / real M"])
  5.2311 +      proof show "2 / real M * content {a..b} \<le> e / 2" unfolding divide_inverse 
  5.2312 +          using M as by(auto simp add:field_simps)
  5.2313 +        fix x assume x:"x \<in> {a..b}"
  5.2314 +        have "norm (f x - g n x) + norm (f x - g m x) \<le> inverse (real n + 1) + inverse (real m + 1)" 
  5.2315 +            using g(1)[OF x, of n] g(1)[OF x, of m] by auto
  5.2316 +        also have "\<dots> \<le> inverse (real M) + inverse (real M)" apply(rule add_mono)
  5.2317 +          apply(rule_tac[!] le_imp_inverse_le) using goal1 M by auto
  5.2318 +        also have "\<dots> = 2 / real M" unfolding real_divide_def by auto
  5.2319 +        finally show "norm (g n x - g m x) \<le> 2 / real M"
  5.2320 +          using norm_triangle_le[of "g n x - f x" "f x - g m x" "2 / real M"]
  5.2321 +          by(auto simp add:group_simps simp add:norm_minus_commute)
  5.2322 +      qed qed qed
  5.2323 +  from this[unfolded convergent_eq_cauchy[THEN sym]] guess s .. note s=this
  5.2324 +
  5.2325 +  show ?thesis unfolding integrable_on_def apply(rule_tac x=s in exI) unfolding has_integral
  5.2326 +  proof(rule,rule)  
  5.2327 +    case goal1 hence *:"e/3 > 0" by auto
  5.2328 +    from s[unfolded Lim_sequentially,rule_format,OF this] guess N1 .. note N1=this
  5.2329 +    from goal1 as have "e / 3 / content {a..b} > 0" by(auto simp add:field_simps)
  5.2330 +    from real_arch_invD[OF this] guess N2 apply-by(erule exE conjE)+ note N2=this
  5.2331 +    from i[of "N1 + N2",unfolded has_integral,rule_format,OF *] guess g' .. note g'=conjunctD2[OF this,rule_format]
  5.2332 +    have lem:"\<And>sf sg i. norm(sf - sg) \<le> e / 3 \<Longrightarrow> norm(i - s) < e / 3 \<Longrightarrow> norm(sg - i) < e / 3 \<Longrightarrow> norm(sf - s) < e"
  5.2333 +    proof- case goal1 have "norm (sf - s) \<le> norm (sf - sg) + norm (sg - i) + norm (i - s)"
  5.2334 +        using norm_triangle_ineq[of "sf - sg" "sg - s"]
  5.2335 +        using norm_triangle_ineq[of "sg -  i" " i - s"] by(auto simp add:group_simps)
  5.2336 +      also have "\<dots> < e" using goal1 unfolding norm_minus_commute by(auto simp add:group_simps)
  5.2337 +      finally show ?case .
  5.2338 +    qed
  5.2339 +    show ?case apply(rule_tac x=g' in exI) apply(rule,rule g')
  5.2340 +    proof(rule,rule) fix p assume p:"p tagged_division_of {a..b} \<and> g' fine p" note * = g'(2)[OF this]
  5.2341 +      show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - s) < e" apply-apply(rule lem[OF _ _ *])
  5.2342 +        apply(rule order_trans,rule rsum_diff_bound[OF p[THEN conjunct1]]) apply(rule,rule g,assumption)
  5.2343 +      proof- have "content {a..b} < e / 3 * (real N2)"
  5.2344 +          using N2 unfolding inverse_eq_divide using as by(auto simp add:field_simps)
  5.2345 +        hence "content {a..b} < e / 3 * (real (N1 + N2) + 1)"
  5.2346 +          apply-apply(rule less_le_trans,assumption) using `e>0` by auto 
  5.2347 +        thus "inverse (real (N1 + N2) + 1) * content {a..b} \<le> e / 3"
  5.2348 +          unfolding inverse_eq_divide by(auto simp add:field_simps)
  5.2349 +        show "norm (i (N1 + N2) - s) < e / 3" by(rule N1[rule_format,unfolded vector_dist_norm],auto)
  5.2350 +      qed qed qed qed
  5.2351 +
  5.2352 +subsection {* Negligible sets. *}
  5.2353 +
  5.2354 +definition "indicator s \<equiv> (\<lambda>x. if x \<in> s then 1 else (0::real))"
  5.2355 +
  5.2356 +lemma dest_vec1_indicator:
  5.2357 + "indicator s x = (if x \<in> s then 1 else 0)" unfolding indicator_def by auto
  5.2358 +
  5.2359 +lemma indicator_pos_le[intro]: "0 \<le> (indicator s x)" unfolding indicator_def by auto
  5.2360 +
  5.2361 +lemma indicator_le_1[intro]: "(indicator s x) \<le> 1" unfolding indicator_def by auto
  5.2362 +
  5.2363 +lemma dest_vec1_indicator_abs_le_1: "abs(indicator s x) \<le> 1"
  5.2364 +  unfolding indicator_def by auto
  5.2365 +
  5.2366 +definition "negligible (s::(real^'n) set) \<equiv> (\<forall>a b. ((indicator s) has_integral 0) {a..b})"
  5.2367 +
  5.2368 +lemma indicator_simps[simp]:"x\<in>s \<Longrightarrow> indicator s x = 1" "x\<notin>s \<Longrightarrow> indicator s x = 0"
  5.2369 +  unfolding indicator_def by auto
  5.2370 +
  5.2371 +subsection {* Negligibility of hyperplane. *}
  5.2372 +
  5.2373 +lemma vsum_nonzero_image_lemma: 
  5.2374 +  assumes "finite s" "g(a) = 0"
  5.2375 +  "\<forall>x\<in>s. \<forall>y\<in>s. f x = f y \<and> x \<noteq> y \<longrightarrow> g(f x) = 0"
  5.2376 +  shows "setsum g {f x |x. x \<in> s \<and> f x \<noteq> a} = setsum (g o f) s"
  5.2377 +  unfolding setsum_iterate[OF assms(1)] apply(subst setsum_iterate) defer
  5.2378 +  apply(rule iterate_nonzero_image_lemma) apply(rule assms monoidal_monoid)+
  5.2379 +  unfolding assms using neutral_add unfolding neutral_add using assms by auto 
  5.2380 +
  5.2381 +lemma interval_doublesplit: shows "{a..b} \<inter> {x . abs(x$k - c) \<le> (e::real)} =
  5.2382 +  {(\<chi> i. if i = k then max (a$k) (c - e) else a$i) .. (\<chi> i. if i = k then min (b$k) (c + e) else b$i)}"
  5.2383 +proof- have *:"\<And>x c e::real. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  5.2384 +  have **:"\<And>s P Q. s \<inter> {x. P x \<and> Q x} = (s \<inter> {x. Q x}) \<inter> {x. P x}" by blast
  5.2385 +  show ?thesis unfolding * ** interval_split by(rule refl) qed
  5.2386 +
  5.2387 +lemma division_doublesplit: assumes "p division_of {a..b::real^'n}" 
  5.2388 +  shows "{l \<inter> {x. abs(x$k - c) \<le> e} |l. l \<in> p \<and> l \<inter> {x. abs(x$k - c) \<le> e} \<noteq> {}} division_of ({a..b} \<inter> {x. abs(x$k - c) \<le> e})"
  5.2389 +proof- have *:"\<And>x c. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  5.2390 +  have **:"\<And>p q p' q'. p division_of q \<Longrightarrow> p = p' \<Longrightarrow> q = q' \<Longrightarrow> p' division_of q'" by auto
  5.2391 +  note division_split(1)[OF assms, where c="c+e" and k=k,unfolded interval_split]
  5.2392 +  note division_split(2)[OF this, where c="c-e" and k=k] 
  5.2393 +  thus ?thesis apply(rule **) unfolding interval_doublesplit unfolding * unfolding interval_split interval_doublesplit
  5.2394 +    apply(rule set_ext) unfolding mem_Collect_eq apply rule apply(erule conjE exE)+ apply(rule_tac x=la in exI) defer
  5.2395 +    apply(erule conjE exE)+ apply(rule_tac x="l \<inter> {x. c + e \<ge> x $ k}" in exI) apply rule defer apply rule
  5.2396 +    apply(rule_tac x=l in exI) by blast+ qed
  5.2397 +
  5.2398 +lemma content_doublesplit: assumes "0 < e"
  5.2399 +  obtains d where "0 < d" "content({a..b} \<inter> {x. abs(x$k - c) \<le> d}) < e"
  5.2400 +proof(cases "content {a..b} = 0")
  5.2401 +  case True show ?thesis apply(rule that[of 1]) defer unfolding interval_doublesplit
  5.2402 +    apply(rule le_less_trans[OF content_subset]) defer apply(subst True)
  5.2403 +    unfolding interval_doublesplit[THEN sym] using assms by auto 
  5.2404 +next case False def d \<equiv> "e / 3 / setprod (\<lambda>i. b$i - a$i) (UNIV - {k})"
  5.2405 +  note False[unfolded content_eq_0 not_ex not_le, rule_format]
  5.2406 +  hence prod0:"0 < setprod (\<lambda>i. b$i - a$i) (UNIV - {k})" apply-apply(rule setprod_pos) by smt
  5.2407 +  hence "d > 0" unfolding d_def using assms by(auto simp add:field_simps) thus ?thesis
  5.2408 +  proof(rule that[of d]) have *:"UNIV = insert k (UNIV - {k})" by auto
  5.2409 +    have **:"{a..b} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d} \<noteq> {} \<Longrightarrow> 
  5.2410 +      (\<Prod>i\<in>UNIV - {k}. interval_upperbound ({a..b} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) $ i - interval_lowerbound ({a..b} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) $ i)
  5.2411 +      = (\<Prod>i\<in>UNIV - {k}. b$i - a$i)" apply(rule setprod_cong,rule refl)
  5.2412 +      unfolding interval_doublesplit interval_eq_empty not_ex not_less unfolding interval_bounds by auto
  5.2413 +    show "content ({a..b} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) < e" apply(cases) unfolding content_def apply(subst if_P,assumption,rule assms)
  5.2414 +      unfolding if_not_P apply(subst *) apply(subst setprod_insert) unfolding **
  5.2415 +      unfolding interval_doublesplit interval_eq_empty not_ex not_less unfolding interval_bounds unfolding Cart_lambda_beta if_P[OF refl]
  5.2416 +    proof- have "(min (b $ k) (c + d) - max (a $ k) (c - d)) \<le> 2 * d" by auto
  5.2417 +      also have "... < e / (\<Prod>i\<in>UNIV - {k}. b $ i - a $ i)" unfolding d_def using assms prod0 by(auto simp add:field_simps)
  5.2418 +      finally show "(min (b $ k) (c + d) - max (a $ k) (c - d)) * (\<Prod>i\<in>UNIV - {k}. b $ i - a $ i) < e"
  5.2419 +        unfolding pos_less_divide_eq[OF prod0] . qed auto qed qed
  5.2420 +
  5.2421 +lemma negligible_standard_hyperplane[intro]: "negligible {x. x$k = (c::real)}" 
  5.2422 +  unfolding negligible_def has_integral apply(rule,rule,rule,rule)
  5.2423 +proof- case goal1 from content_doublesplit[OF this,of a b k c] guess d . note d=this let ?i = "indicator {x. x$k = c}"
  5.2424 +  show ?case apply(rule_tac x="\<lambda>x. ball x d" in exI) apply(rule,rule gauge_ball,rule d)
  5.2425 +  proof(rule,rule) fix p assume p:"p tagged_division_of {a..b} \<and> (\<lambda>x. ball x d) fine p"
  5.2426 +    have *:"(\<Sum>(x, ka)\<in>p. content ka *\<^sub>R ?i x) = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. abs(x$k - c) \<le> d}) *\<^sub>R ?i x)"
  5.2427 +      apply(rule setsum_cong2) unfolding split_paired_all real_scaleR_def mult_cancel_right split_conv
  5.2428 +      apply(cases,rule disjI1,assumption,rule disjI2)
  5.2429 +    proof- fix x l assume as:"(x,l)\<in>p" "?i x \<noteq> 0" hence xk:"x$k = c" unfolding indicator_def apply-by(rule ccontr,auto)
  5.2430 +      show "content l = content (l \<inter> {x. \<bar>x $ k - c\<bar> \<le> d})" apply(rule arg_cong[where f=content])
  5.2431 +        apply(rule set_ext,rule,rule) unfolding mem_Collect_eq
  5.2432 +      proof- fix y assume y:"y\<in>l" note p[THEN conjunct2,unfolded fine_def,rule_format,OF as(1),unfolded split_conv]
  5.2433 +        note this[unfolded subset_eq mem_ball vector_dist_norm,rule_format,OF y] note le_less_trans[OF component_le_norm[of _ k] this]
  5.2434 +        thus "\<bar>y $ k - c\<bar> \<le> d" unfolding Cart_nth.diff xk by auto
  5.2435 +      qed auto qed
  5.2436 +    note p'= tagged_division_ofD[OF p[THEN conjunct1]] and p''=division_of_tagged_division[OF p[THEN conjunct1]]
  5.2437 +    show "norm ((\<Sum>(x, ka)\<in>p. content ka *\<^sub>R ?i x) - 0) < e" unfolding diff_0_right * unfolding real_scaleR_def real_norm_def
  5.2438 +      apply(subst abs_of_nonneg) apply(rule setsum_nonneg,rule) unfolding split_paired_all split_conv
  5.2439 +      apply(rule mult_nonneg_nonneg) apply(drule p'(4)) apply(erule exE)+ apply(rule_tac b=b in back_subst)
  5.2440 +      prefer 2 apply(subst(asm) eq_commute) apply assumption
  5.2441 +      apply(subst interval_doublesplit) apply(rule content_pos_le) apply(rule indicator_pos_le)
  5.2442 +    proof- have "(\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) * ?i x) \<le> (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}))"
  5.2443 +        apply(rule setsum_mono) unfolding split_paired_all split_conv 
  5.2444 +        apply(rule mult_right_le_one_le) apply(drule p'(4)) by(auto simp add:interval_doublesplit intro!:content_pos_le)
  5.2445 +      also have "... < e" apply(subst setsum_over_tagged_division_lemma[OF p[THEN conjunct1]])
  5.2446 +      proof- case goal1 have "content ({u..v} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) \<le> content {u..v}"
  5.2447 +          unfolding interval_doublesplit apply(rule content_subset) unfolding interval_doublesplit[THEN sym] by auto
  5.2448 +        thus ?case unfolding goal1 unfolding interval_doublesplit using content_pos_le by smt
  5.2449 +      next have *:"setsum content {l \<inter> {x. \<bar>x $ k - c\<bar> \<le> d} |l. l \<in> snd ` p \<and> l \<inter> {x. \<bar>x $ k - c\<bar> \<le> d} \<noteq> {}} \<ge> 0"
  5.2450 +          apply(rule setsum_nonneg,rule) unfolding mem_Collect_eq image_iff apply(erule exE bexE conjE)+ unfolding split_paired_all 
  5.2451 +        proof- fix x l a b assume as:"x = l \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}" "(a, b) \<in> p" "l = snd (a, b)"
  5.2452 +          guess u v using p'(4)[OF as(2)] apply-by(erule exE)+ note * = this
  5.2453 +          show "content x \<ge> 0" unfolding as snd_conv * interval_doublesplit by(rule content_pos_le)
  5.2454 +        qed have **:"norm (1::real) \<le> 1" by auto note division_doublesplit[OF p'',unfolded interval_doublesplit]
  5.2455 +        note dsum_bound[OF this **,unfolded interval_doublesplit[THEN sym]]
  5.2456 +        note this[unfolded real_scaleR_def real_norm_def class_semiring.semiring_rules, of k c d] note le_less_trans[OF this d(2)]
  5.2457 +        from this[unfolded abs_of_nonneg[OF *]] show "(\<Sum>ka\<in>snd ` p. content (ka \<inter> {x. \<bar>x $ k - c\<bar> \<le> d})) < e"
  5.2458 +          apply(subst vsum_nonzero_image_lemma[of "snd ` p" content "{}", unfolded o_def,THEN sym])
  5.2459 +          apply(rule finite_imageI p' content_empty)+ unfolding forall_in_division[OF p'']
  5.2460 +        proof(rule,rule,rule,rule,rule,rule,rule,erule conjE) fix m n u v
  5.2461 +          assume as:"{m..n} \<in> snd ` p" "{u..v} \<in> snd ` p" "{m..n} \<noteq> {u..v}"  "{m..n} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d} = {u..v} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}"
  5.2462 +          have "({m..n} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) \<inter> ({u..v} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) \<subseteq> {m..n} \<inter> {u..v}" by blast
  5.2463 +          note subset_interior[OF this, unfolded division_ofD(5)[OF p'' as(1-3)] interior_inter[of "{m..n}"]]
  5.2464 +          hence "interior ({m..n} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) = {}" unfolding as Int_absorb by auto
  5.2465 +          thus "content ({m..n} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) = 0" unfolding interval_doublesplit content_eq_0_interior[THEN sym] .
  5.2466 +        qed qed
  5.2467 +      finally show "(\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) * ?i x) < e" .
  5.2468 +    qed qed qed
  5.2469 +
  5.2470 +subsection {* A technical lemma about "refinement" of division. *}
  5.2471 +
  5.2472 +lemma tagged_division_finer: fixes p::"((real^'n) \<times> ((real^'n) set)) set"
  5.2473 +  assumes "p tagged_division_of {a..b}" "gauge d"
  5.2474 +  obtains q where "q tagged_division_of {a..b}" "d fine q" "\<forall>(x,k) \<in> p. k \<subseteq> d(x) \<longrightarrow> (x,k) \<in> q"
  5.2475 +proof-
  5.2476 +  let ?P = "\<lambda>p. p tagged_partial_division_of {a..b} \<longrightarrow> gauge d \<longrightarrow>
  5.2477 +    (\<exists>q. q tagged_division_of (\<Union>{k. \<exists>x. (x,k) \<in> p}) \<and> d fine q \<and>
  5.2478 +                   (\<forall>(x,k) \<in> p. k \<subseteq> d(x) \<longrightarrow> (x,k) \<in> q))"
  5.2479 +  { have *:"finite p" "p tagged_partial_division_of {a..b}" using assms(1) unfolding tagged_division_of_def by auto
  5.2480 +    presume "\<And>p. finite p \<Longrightarrow> ?P p" from this[rule_format,OF * assms(2)] guess q .. note q=this
  5.2481 +    thus ?thesis apply-apply(rule that[of q]) unfolding tagged_division_ofD[OF assms(1)] by auto
  5.2482 +  } fix p::"((real^'n) \<times> ((real^'n) set)) set" assume as:"finite p"
  5.2483 +  show "?P p" apply(rule,rule) using as proof(induct p) 
  5.2484 +    case empty show ?case apply(rule_tac x="{}" in exI) unfolding fine_def by auto
  5.2485 +  next case (insert xk p) guess x k using surj_pair[of xk] apply- by(erule exE)+ note xk=this
  5.2486 +    note tagged_partial_division_subset[OF insert(4) subset_insertI]
  5.2487 +    from insert(3)[OF this insert(5)] guess q1 .. note q1 = conjunctD3[OF this]
  5.2488 +    have *:"\<Union>{l. \<exists>y. (y,l) \<in> insert xk p} = k \<union> \<Union>{l. \<exists>y. (y,l) \<in> p}" unfolding xk by auto
  5.2489 +    note p = tagged_partial_division_ofD[OF insert(4)]
  5.2490 +    from p(4)[unfolded xk, OF insertI1] guess u v apply-by(erule exE)+ note uv=this
  5.2491 +
  5.2492 +    have "finite {k. \<exists>x. (x, k) \<in> p}" 
  5.2493 +      apply(rule finite_subset[of _ "snd ` p"],rule) unfolding subset_eq image_iff mem_Collect_eq
  5.2494 +      apply(erule exE,rule_tac x="(xa,x)" in bexI) using p by auto
  5.2495 +    hence int:"interior {u..v} \<inter> interior (\<Union>{k. \<exists>x. (x, k) \<in> p}) = {}"
  5.2496 +      apply(rule inter_interior_unions_intervals) apply(rule open_interior) apply(rule_tac[!] ballI)
  5.2497 +      unfolding mem_Collect_eq apply(erule_tac[!] exE) apply(drule p(4)[OF insertI2],assumption)      
  5.2498 +      apply(rule p(5))  unfolding uv xk apply(rule insertI1,rule insertI2) apply assumption
  5.2499 +      using insert(2) unfolding uv xk by auto
  5.2500 +
  5.2501 +    show ?case proof(cases "{u..v} \<subseteq> d x")
  5.2502 +      case True thus ?thesis apply(rule_tac x="{(x,{u..v})} \<union> q1" in exI) apply rule
  5.2503 +        unfolding * uv apply(rule tagged_division_union,rule tagged_division_of_self)
  5.2504 +        apply(rule p[unfolded xk uv] insertI1)+  apply(rule q1,rule int) 
  5.2505 +        apply(rule,rule fine_union,subst fine_def) defer apply(rule q1)
  5.2506 +        unfolding Ball_def split_paired_All split_conv apply(rule,rule,rule,rule)
  5.2507 +        apply(erule insertE) defer apply(rule UnI2) apply(drule q1(3)[rule_format]) unfolding xk uv by auto
  5.2508 +    next case False from fine_division_exists[OF assms(2), of u v] guess q2 . note q2=this
  5.2509 +      show ?thesis apply(rule_tac x="q2 \<union> q1" in exI)
  5.2510 +        apply rule unfolding * uv apply(rule tagged_division_union q2 q1 int fine_union)+
  5.2511 +        unfolding Ball_def split_paired_All split_conv apply rule apply(rule fine_union)
  5.2512 +        apply(rule q1 q2)+ apply(rule,rule,rule,rule) apply(erule insertE)
  5.2513 +        apply(rule UnI2) defer apply(drule q1(3)[rule_format])using False unfolding xk uv by auto
  5.2514 +    qed qed qed
  5.2515 +
  5.2516 +subsection {* Hence the main theorem about negligible sets. *}
  5.2517 +
  5.2518 +lemma finite_product_dependent: assumes "finite s" "\<And>x. x\<in>s\<Longrightarrow> finite (t x)"
  5.2519 +  shows "finite {(i, j) |i j. i \<in> s \<and> j \<in> t i}" using assms
  5.2520 +proof(induct) case (insert x s) 
  5.2521 +  have *:"{(i, j) |i j. i \<in> insert x s \<and> j \<in> t i} = (\<lambda>y. (x,y)) ` (t x) \<union> {(i, j) |i j. i \<in> s \<and> j \<in> t i}" by auto
  5.2522 +  show ?case unfolding * apply(rule finite_UnI) using insert by auto qed auto
  5.2523 +
  5.2524 +lemma sum_sum_product: assumes "finite s" "\<forall>i\<in>s. finite (t i)"
  5.2525 +  shows "setsum (\<lambda>i. setsum (x i) (t i)::real) s = setsum (\<lambda>(i,j). x i j) {(i,j) | i j. i \<in> s \<and> j \<in> t i}" using assms
  5.2526 +proof(induct) case (insert a s)
  5.2527 +  have *:"{(i, j) |i j. i \<in> insert a s \<and> j \<in> t i} = (\<lambda>y. (a,y)) ` (t a) \<union> {(i, j) |i j. i \<in> s \<and> j \<in> t i}" by auto
  5.2528 +  show ?case unfolding * apply(subst setsum_Un_disjoint) unfolding setsum_insert[OF insert(1-2)]
  5.2529 +    prefer 4 apply(subst insert(3)) unfolding add_right_cancel
  5.2530 +  proof- show "setsum (x a) (t a) = (\<Sum>(xa, y)\<in>Pair a ` t a. x xa y)" apply(subst setsum_reindex) unfolding inj_on_def by auto
  5.2531 +    show "finite {(i, j) |i j. i \<in> s \<and> j \<in> t i}" apply(rule finite_product_dependent) using insert by auto
  5.2532 +  qed(insert insert, auto) qed auto
  5.2533 +
  5.2534 +lemma has_integral_negligible: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  5.2535 +  assumes "negligible s" "\<forall>x\<in>(t - s). f x = 0"
  5.2536 +  shows "(f has_integral 0) t"
  5.2537 +proof- presume P:"\<And>f::real^'n \<Rightarrow> 'a. \<And>a b. (\<forall>x. ~(x \<in> s) \<longrightarrow> f x = 0) \<Longrightarrow> (f has_integral 0) ({a..b})"
  5.2538 +  let ?f = "(\<lambda>x. if x \<in> t then f x else 0)"
  5.2539 +  show ?thesis apply(rule_tac f="?f" in has_integral_eq) apply(rule) unfolding if_P apply(rule refl)
  5.2540 +    apply(subst has_integral_alt) apply(cases,subst if_P,assumption) unfolding if_not_P
  5.2541 +  proof- assume "\<exists>a b. t = {a..b}" then guess a b apply-by(erule exE)+ note t = this
  5.2542 +    show "(?f has_integral 0) t" unfolding t apply(rule P) using assms(2) unfolding t by auto
  5.2543 +  next show "\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b} \<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> t then ?f x else 0) has_integral z) {a..b} \<and> norm (z - 0) < e)"
  5.2544 +      apply(safe,rule_tac x=1 in exI,rule) apply(rule zero_less_one,safe) apply(rule_tac x=0 in exI)
  5.2545 +      apply(rule,rule P) using assms(2) by auto
  5.2546 +  qed
  5.2547 +next fix f::"real^'n \<Rightarrow> 'a" and a b::"real^'n" assume assm:"\<forall>x. x \<notin> s \<longrightarrow> f x = 0" 
  5.2548 +  show "(f has_integral 0) {a..b}" unfolding has_integral
  5.2549 +  proof(safe) case goal1
  5.2550 +    hence "\<And>n. e / 2 / ((real n+1) * (2 ^ n)) > 0" 
  5.2551 +      apply-apply(rule divide_pos_pos) defer apply(rule mult_pos_pos) by(auto simp add:field_simps)
  5.2552 +    note assms(1)[unfolded negligible_def has_integral,rule_format,OF this,of a b] note allI[OF this,of "\<lambda>x. x"] 
  5.2553 +    from choice[OF this] guess d .. note d=conjunctD2[OF this[rule_format]]
  5.2554 +    show ?case apply(rule_tac x="\<lambda>x. d (nat \<lfloor>norm (f x)\<rfloor>) x" in exI) 
  5.2555 +    proof safe show "gauge (\<lambda>x. d (nat \<lfloor>norm (f x)\<rfloor>) x)" using d(1) unfolding gauge_def by auto
  5.2556 +      fix p assume as:"p tagged_division_of {a..b}" "(\<lambda>x. d (nat \<lfloor>norm (f x)\<rfloor>) x) fine p" 
  5.2557 +      let ?goal = "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) < e"
  5.2558 +      { presume "p\<noteq>{} \<Longrightarrow> ?goal" thus ?goal apply(cases "p={}") using goal1 by auto  }
  5.2559 +      assume as':"p \<noteq> {}" from real_arch_simple[of "Sup((\<lambda>(x,k). norm(f x)) ` p)"] guess N ..
  5.2560 +      hence N:"\<forall>x\<in>(\<lambda>(x, k). norm (f x)) ` p. x \<le> real N" apply(subst(asm) Sup_finite_le_iff) using as as' by auto
  5.2561 +      have "\<forall>i. \<exists>q. q tagged_division_of {a..b} \<and> (d i) fine q \<and> (\<forall>(x, k)\<in>p. k \<subseteq> (d i) x \<longrightarrow> (x, k) \<in> q)"
  5.2562 +        apply(rule,rule tagged_division_finer[OF as(1) d(1)]) by auto
  5.2563 +      from choice[OF this] guess q .. note q=conjunctD3[OF this[rule_format]]
  5.2564 +      have *:"\<And>i. (\<Sum>(x, k)\<in>q i. content k *\<^sub>R indicator s x) \<ge> 0" apply(rule setsum_nonneg,safe) 
  5.2565 +        unfolding real_scaleR_def apply(rule mult_nonneg_nonneg) apply(drule tagged_division_ofD(4)[OF q(1)]) by auto
  5.2566 +      have **:"\<And>f g s t. finite s \<Longrightarrow> finite t \<Longrightarrow> (\<forall>(x,y) \<in> t. (0::real) \<le> g(x,y)) \<Longrightarrow> (\<forall>y\<in>s. \<exists>x. (x,y) \<in> t \<and> f(y) \<le> g(x,y)) \<Longrightarrow> setsum f s \<le> setsum g t"
  5.2567 +      proof- case goal1 thus ?case apply-apply(rule setsum_le_included[of s t g snd f]) prefer 4
  5.2568 +          apply safe apply(erule_tac x=x in ballE) apply(erule exE) apply(rule_tac x="(xa,x)" in bexI) by auto qed
  5.2569 +      have "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) \<le> setsum (\<lambda>i. (real i + 1) *
  5.2570 +                     norm(setsum (\<lambda>(x,k). content k *\<^sub>R indicator s x) (q i))) {0..N+1}"
  5.2571 +        unfolding real_norm_def setsum_right_distrib abs_of_nonneg[OF *] diff_0_right
  5.2572 +        apply(rule order_trans,rule setsum_norm) defer apply(subst sum_sum_product) prefer 3 
  5.2573 +      proof(rule **,safe) show "finite {(i, j) |i j. i \<in> {0..N + 1} \<and> j \<in> q i}" apply(rule finite_product_dependent) using q by auto
  5.2574 +        fix i a b assume as'':"(a,b) \<in> q i" show "0 \<le> (real i + 1) * (content b *\<^sub>R indicator s a)"
  5.2575 +          unfolding real_scaleR_def apply(rule mult_nonneg_nonneg) defer apply(rule mult_nonneg_nonneg)
  5.2576 +          using tagged_division_ofD(4)[OF q(1) as''] by auto
  5.2577 +      next fix i::nat show "finite (q i)" using q by auto
  5.2578 +      next fix x k assume xk:"(x,k) \<in> p" def n \<equiv> "nat \<lfloor>norm (f x)\<rfloor>"
  5.2579 +        have *:"norm (f x) \<in> (\<lambda>(x, k). norm (f x)) ` p" using xk by auto
  5.2580 +        have nfx:"real n \<le> norm(f x)" "norm(f x) \<le> real n + 1" unfolding n_def by auto
  5.2581 +        hence "n \<in> {0..N + 1}" using N[rule_format,OF *] by auto
  5.2582 +        moreover  note as(2)[unfolded fine_def,rule_format,OF xk,unfolded split_conv]
  5.2583 +        note q(3)[rule_format,OF xk,unfolded split_conv,rule_format,OF this] note this[unfolded n_def[symmetric]]
  5.2584 +        moreover have "norm (content k *\<^sub>R f x) \<le> (real n + 1) * (content k * indicator s x)"
  5.2585 +        proof(cases "x\<in>s") case False thus ?thesis using assm by auto
  5.2586 +        next case True have *:"content k \<ge> 0" using tagged_division_ofD(4)[OF as(1) xk] by auto
  5.2587 +          moreover have "content k * norm (f x) \<le> content k * (real n + 1)" apply(rule mult_mono) using nfx * by auto
  5.2588 +          ultimately show ?thesis unfolding abs_mult using nfx True by(auto simp add:field_simps)
  5.2589 +        qed ultimately show "\<exists>y. (y, x, k) \<in> {(i, j) |i j. i \<in> {0..N + 1} \<and> j \<in> q i} \<and> norm (content k *\<^sub>R f x) \<le> (real y + 1) * (content k *\<^sub>R indicator s x)"
  5.2590 +          apply(rule_tac x=n in exI,safe) apply(rule_tac x=n in exI,rule_tac x="(x,k)" in exI,safe) by auto
  5.2591 +      qed(insert as, auto)
  5.2592 +      also have "... \<le> setsum (\<lambda>i. e / 2 / 2 ^ i) {0..N+1}" apply(rule setsum_mono) 
  5.2593 +      proof- case goal1 thus ?case apply(subst mult_commute, subst pos_le_divide_eq[THEN sym])
  5.2594 +          using d(2)[rule_format,of "q i" i] using q[rule_format] by(auto simp add:field_simps)
  5.2595 +      qed also have "... < e * inverse 2 * 2" unfolding real_divide_def setsum_right_distrib[THEN sym]
  5.2596 +        apply(rule mult_strict_left_mono) unfolding power_inverse atLeastLessThanSuc_atLeastAtMost[THEN sym]
  5.2597 +        apply(subst sumr_geometric) using goal1 by auto
  5.2598 +      finally show "?goal" by auto qed qed qed
  5.2599 +
  5.2600 +lemma has_integral_spike: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  5.2601 +  assumes "negligible s" "(\<forall>x\<in>(t - s). g x = f x)" "(f has_integral y) t"
  5.2602 +  shows "(g has_integral y) t"
  5.2603 +proof- { fix a b::"real^'n" and f g ::"real^'n \<Rightarrow> 'a" and y::'a
  5.2604 +    assume as:"\<forall>x \<in> {a..b} - s. g x = f x" "(f has_integral y) {a..b}"
  5.2605 +    have "((\<lambda>x. f x + (g x - f x)) has_integral (y + 0)) {a..b}" apply(rule has_integral_add[OF as(2)])
  5.2606 +      apply(rule has_integral_negligible[OF assms(1)]) using as by auto
  5.2607 +    hence "(g has_integral y) {a..b}" by auto } note * = this
  5.2608 +  show ?thesis apply(subst has_integral_alt) using assms(2-) apply-apply(rule cond_cases,safe)
  5.2609 +    apply(rule *, assumption+) apply(subst(asm) has_integral_alt) unfolding if_not_P
  5.2610 +    apply(erule_tac x=e in allE,safe,rule_tac x=B in exI,safe) apply(erule_tac x=a in allE,erule_tac x=b in allE,safe)
  5.2611 +    apply(rule_tac x=z in exI,safe) apply(rule *[where fa2="\<lambda>x. if x\<in>t then f x else 0"]) by auto qed
  5.2612 +
  5.2613 +lemma has_integral_spike_eq:
  5.2614 +  assumes "negligible s" "\<forall>x\<in>(t - s). g x = f x"
  5.2615 +  shows "((f has_integral y) t \<longleftrightarrow> (g has_integral y) t)"
  5.2616 +  apply rule apply(rule_tac[!] has_integral_spike[OF assms(1)]) using assms(2) by auto
  5.2617 +
  5.2618 +lemma integrable_spike: assumes "negligible s" "\<forall>x\<in>(t - s). g x = f x" "f integrable_on t"
  5.2619 +  shows "g integrable_on  t"
  5.2620 +  using assms unfolding integrable_on_def apply-apply(erule exE)
  5.2621 +  apply(rule,rule has_integral_spike) by fastsimp+
  5.2622 +
  5.2623 +lemma integral_spike: assumes "negligible s" "\<forall>x\<in>(t - s). g x = f x"
  5.2624 +  shows "integral t f = integral t g"
  5.2625 +  unfolding integral_def using has_integral_spike_eq[OF assms] by auto
  5.2626 +
  5.2627 +subsection {* Some other trivialities about negligible sets. *}
  5.2628 +
  5.2629 +lemma negligible_subset[intro]: assumes "negligible s" "t \<subseteq> s" shows "negligible t" unfolding negligible_def 
  5.2630 +proof(safe) case goal1 show ?case using assms(1)[unfolded negligible_def,rule_format,of a b]
  5.2631 +    apply-apply(rule has_integral_spike[OF assms(1)]) defer apply assumption
  5.2632 +    using assms(2) unfolding indicator_def by auto qed
  5.2633 +
  5.2634 +lemma negligible_diff[intro?]: assumes "negligible s" shows "negligible(s - t)" using assms by auto
  5.2635 +
  5.2636 +lemma negligible_inter: assumes "negligible s \<or> negligible t" shows "negligible(s \<inter> t)" using assms by auto
  5.2637 +
  5.2638 +lemma negligible_union: assumes "negligible s" "negligible t" shows "negligible (s \<union> t)" unfolding negligible_def 
  5.2639 +proof safe case goal1 note assm = assms[unfolded negligible_def,rule_format,of a b]
  5.2640 +  thus ?case apply(subst has_integral_spike_eq[OF assms(2)])
  5.2641 +    defer apply assumption unfolding indicator_def by auto qed
  5.2642 +
  5.2643 +lemma negligible_union_eq[simp]: "negligible (s \<union> t) \<longleftrightarrow> (negligible s \<and> negligible t)"
  5.2644 +  using negligible_union by auto
  5.2645 +
  5.2646 +lemma negligible_sing[intro]: "negligible {a::real^'n}" 
  5.2647 +proof- guess x using UNIV_witness[where 'a='n] ..
  5.2648 +  show ?thesis using negligible_standard_hyperplane[of x "a$x"] by auto qed
  5.2649 +
  5.2650 +lemma negligible_insert[simp]: "negligible(insert a s) \<longleftrightarrow> negligible s"
  5.2651 +  apply(subst insert_is_Un) unfolding negligible_union_eq by auto
  5.2652 +
  5.2653 +lemma negligible_empty[intro]: "negligible {}" by auto
  5.2654 +
  5.2655 +lemma negligible_finite[intro]: assumes "finite s" shows "negligible s"
  5.2656 +  using assms apply(induct s) by auto
  5.2657 +
  5.2658 +lemma negligible_unions[intro]: assumes "finite s" "\<forall>t\<in>s. negligible t" shows "negligible(\<Union>s)"
  5.2659 +  using assms by(induct,auto) 
  5.2660 +
  5.2661 +lemma negligible:  "negligible s \<longleftrightarrow> (\<forall>t::(real^'n) set. (indicator s has_integral 0) t)"
  5.2662 +  apply safe defer apply(subst negligible_def)
  5.2663 +proof- fix t::"(real^'n) set" assume as:"negligible s"
  5.2664 +  have *:"(\<lambda>x. if x \<in> s \<inter> t then 1 else 0) = (\<lambda>x. if x\<in>t then if x\<in>s then 1 else 0 else 0)" by(rule ext,auto)  
  5.2665 +  show "(indicator s has_integral 0) t" apply(subst has_integral_alt)
  5.2666 +    apply(cases,subst if_P,assumption) unfolding if_not_P apply(safe,rule as[unfolded negligible_def,rule_format])
  5.2667 +    apply(rule_tac x=1 in exI) apply(safe,rule zero_less_one) apply(rule_tac x=0 in exI)
  5.2668 +    using negligible_subset[OF as,of "s \<inter> t"] unfolding negligible_def indicator_def unfolding * by auto qed auto
  5.2669 +
  5.2670 +subsection {* Finite case of the spike theorem is quite commonly needed. *}
  5.2671 +
  5.2672 +lemma has_integral_spike_finite: assumes "finite s" "\<forall>x\<in>t-s. g x = f x" 
  5.2673 +  "(f has_integral y) t" shows "(g has_integral y) t"
  5.2674 +  apply(rule has_integral_spike) using assms by auto
  5.2675 +
  5.2676 +lemma has_integral_spike_finite_eq: assumes "finite s" "\<forall>x\<in>t-s. g x = f x"
  5.2677 +  shows "((f has_integral y) t \<longleftrightarrow> (g has_integral y) t)"
  5.2678 +  apply rule apply(rule_tac[!] has_integral_spike_finite) using assms by auto
  5.2679 +
  5.2680 +lemma integrable_spike_finite:
  5.2681 +  assumes "finite s" "\<forall>x\<in>t-s. g x = f x" "f integrable_on t" shows "g integrable_on  t"
  5.2682 +  using assms unfolding integrable_on_def apply safe apply(rule_tac x=y in exI)
  5.2683 +  apply(rule has_integral_spike_finite) by auto
  5.2684 +
  5.2685 +subsection {* In particular, the boundary of an interval is negligible. *}
  5.2686 +
  5.2687 +lemma negligible_frontier_interval: "negligible({a..b} - {a<..<b})"
  5.2688 +proof- let ?A = "\<Union>((\<lambda>k. {x. x$k = a$k} \<union> {x. x$k = b$k}) ` UNIV)"
  5.2689 +  have "{a..b} - {a<..<b} \<subseteq> ?A" apply rule unfolding Diff_iff mem_interval not_all
  5.2690 +    apply(erule conjE exE)+ apply(rule_tac X="{x. x $ xa = a $ xa} \<union> {x. x $ xa = b $ xa}" in UnionI)
  5.2691 +    apply(erule_tac[!] x=xa in allE) by auto
  5.2692 +  thus ?thesis apply-apply(rule negligible_subset[of ?A]) apply(rule negligible_unions[OF finite_imageI]) by auto qed
  5.2693 +
  5.2694 +lemma has_integral_spike_interior:
  5.2695 +  assumes "\<forall>x\<in>{a<..<b}. g x = f x" "(f has_integral y) ({a..b})" shows "(g has_integral y) ({a..b})"
  5.2696 +  apply(rule has_integral_spike[OF negligible_frontier_interval _ assms(2)]) using assms(1) by auto
  5.2697 +
  5.2698 +lemma has_integral_spike_interior_eq:
  5.2699 +  assumes "\<forall>x\<in>{a<..<b}. g x = f x" shows "((f has_integral y) ({a..b}) \<longleftrightarrow> (g has_integral y) ({a..b}))"
  5.2700 +  apply rule apply(rule_tac[!] has_integral_spike_interior) using assms by auto
  5.2701 +
  5.2702 +lemma integrable_spike_interior: assumes "\<forall>x\<in>{a<..<b}. g x = f x" "f integrable_on {a..b}" shows "g integrable_on {a..b}"
  5.2703 +  using  assms unfolding integrable_on_def using has_integral_spike_interior[OF assms(1)] by auto
  5.2704 +
  5.2705 +subsection {* Integrability of continuous functions. *}
  5.2706 +
  5.2707 +lemma neutral_and[simp]: "neutral op \<and> = True"
  5.2708 +  unfolding neutral_def apply(rule some_equality) by auto
  5.2709 +
  5.2710 +lemma monoidal_and[intro]: "monoidal op \<and>" unfolding monoidal_def by auto
  5.2711 +
  5.2712 +lemma iterate_and[simp]: assumes "finite s" shows "(iterate op \<and>) s p \<longleftrightarrow> (\<forall>x\<in>s. p x)" using assms
  5.2713 +apply induct unfolding iterate_insert[OF monoidal_and] by auto
  5.2714 +
  5.2715 +lemma operative_division_and: assumes "operative op \<and> P" "d division_of {a..b}"
  5.2716 +  shows "(\<forall>i\<in>d. P i) \<longleftrightarrow> P {a..b}"
  5.2717 +  using operative_division[OF monoidal_and assms] division_of_finite[OF assms(2)] by auto
  5.2718 +
  5.2719 +lemma operative_approximable: assumes "0 \<le> e" fixes f::"real^'n \<Rightarrow> 'a::banach"
  5.2720 +  shows "operative op \<and> (\<lambda>i. \<exists>g. (\<forall>x\<in>i. norm (f x - g (x::real^'n)) \<le> e) \<and> g integrable_on i)" unfolding operative_def neutral_and
  5.2721 +proof safe fix a b::"real^'n" { assume "content {a..b} = 0"
  5.2722 +    thus "\<exists>g. (\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b}" 
  5.2723 +      apply(rule_tac x=f in exI) using assms by(auto intro!:integrable_on_null) }
  5.2724 +  { fix c k g assume as:"\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e" "g integrable_on {a..b}"
  5.2725 +    show "\<exists>g. (\<forall>x\<in>{a..b} \<inter> {x. x $ k \<le> c}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b} \<inter> {x. x $ k \<le> c}"
  5.2726 +      "\<exists>g. (\<forall>x\<in>{a..b} \<inter> {x. c \<le> x $ k}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b} \<inter> {x. c \<le> x $ k}"
  5.2727 +      apply(rule_tac[!] x=g in exI) using as(1) integrable_split[OF as(2)] by auto }
  5.2728 +  fix c k g1 g2 assume as:"\<forall>x\<in>{a..b} \<inter> {x. x $ k \<le> c}. norm (f x - g1 x) \<le> e" "g1 integrable_on {a..b} \<inter> {x. x $ k \<le> c}"
  5.2729 +                          "\<forall>x\<in>{a..b} \<inter> {x. c \<le> x $ k}. norm (f x - g2 x) \<le> e" "g2 integrable_on {a..b} \<inter> {x. c \<le> x $ k}"
  5.2730 +  let ?g = "\<lambda>x. if x$k = c then f x else if x$k \<le> c then g1 x else g2 x"
  5.2731 +  show "\<exists>g. (\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b}" apply(rule_tac x="?g" in exI)
  5.2732 +  proof safe case goal1 thus ?case apply- apply(cases "x$k=c", case_tac "x$k < c") using as assms by auto
  5.2733 +  next case goal2 presume "?g integrable_on {a..b} \<inter> {x. x $ k \<le> c}" "?g integrable_on {a..b} \<inter> {x. x $ k \<ge> c}"
  5.2734 +    then guess h1 h2 unfolding integrable_on_def by auto from has_integral_split[OF this]
  5.2735 +    show ?case unfolding integrable_on_def by auto
  5.2736 +  next show "?g integrable_on {a..b} \<inter> {x. x $ k \<le> c}" "?g integrable_on {a..b} \<inter> {x. x $ k \<ge> c}"
  5.2737 +      apply(rule_tac[!] integrable_spike[OF negligible_standard_hyperplane[of k c]]) using as(2,4) by auto qed qed
  5.2738 +
  5.2739 +lemma approximable_on_division: fixes f::"real^'n \<Rightarrow> 'a::banach"
  5.2740 +  assumes "0 \<le> e" "d division_of {a..b}" "\<forall>i\<in>d. \<exists>g. (\<forall>x\<in>i. norm (f x - g x) \<le> e) \<and> g integrable_on i"
  5.2741 +  obtains g where "\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e" "g integrable_on {a..b}"
  5.2742 +proof- note * = operative_division[OF monoidal_and operative_approximable[OF assms(1)] assms(2)]
  5.2743 +  note this[unfolded iterate_and[OF division_of_finite[OF assms(2)]]] from assms(3)[unfolded this[of f]]
  5.2744 +  guess g .. thus thesis apply-apply(rule that[of g]) by auto qed
  5.2745 +
  5.2746 +lemma integrable_continuous: fixes f::"real^'n \<Rightarrow> 'a::banach"
  5.2747 +  assumes "continuous_on {a..b} f" shows "f integrable_on {a..b}"
  5.2748 +proof(rule integrable_uniform_limit,safe) fix e::real assume e:"0 < e"
  5.2749 +  from compact_uniformly_continuous[OF assms compact_interval,unfolded uniformly_continuous_on_def,rule_format,OF e] guess d ..
  5.2750 +  note d=conjunctD2[OF this,rule_format]
  5.2751 +  from fine_division_exists[OF gauge_ball[OF d(1)], of a b] guess p . note p=this
  5.2752 +  note p' = tagged_division_ofD[OF p(1)]
  5.2753 +  have *:"\<forall>i\<in>snd ` p. \<exists>g. (\<forall>x\<in>i. norm (f x - g x) \<le> e) \<and> g integrable_on i"
  5.2754 +  proof(safe,unfold snd_conv) fix x l assume as:"(x,l) \<in> p" 
  5.2755 +    from p'(4)[OF this] guess a b apply-by(erule exE)+ note l=this
  5.2756 +    show "\<exists>g. (\<forall>x\<in>l. norm (f x - g x) \<le> e) \<and> g integrable_on l" apply(rule_tac x="\<lambda>y. f x" in exI)
  5.2757 +    proof safe show "(\<lambda>y. f x) integrable_on l" unfolding integrable_on_def l by(rule,rule has_integral_const)
  5.2758 +      fix y assume y:"y\<in>l" note fineD[OF p(2) as,unfolded subset_eq,rule_format,OF this]
  5.2759 +      note d(2)[OF _ _ this[unfolded mem_ball]]
  5.2760 +      thus "norm (f y - f x) \<le> e" using y p'(2-3)[OF as] unfolding vector_dist_norm l norm_minus_commute by fastsimp qed qed
  5.2761 +  from e have "0 \<le> e" by auto from approximable_on_division[OF this division_of_tagged_division[OF p(1)] *] guess g .
  5.2762 +  thus "\<exists>g. (\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b}" by auto qed 
  5.2763 +
  5.2764 +subsection {* Specialization of additivity to one dimension. *}
  5.2765 +
  5.2766 +lemma operative_1_lt: assumes "monoidal opp"
  5.2767 +  shows "operative opp f \<longleftrightarrow> ((\<forall>a b. b \<le> a \<longrightarrow> f {a..b::real^1} = neutral opp) \<and>
  5.2768 +                (\<forall>a b c. a < c \<and> c < b \<longrightarrow> opp (f{a..c})(f{c..b}) = f {a..b}))"
  5.2769 +  unfolding operative_def content_eq_0_1 forall_1 vector_le_def vector_less_def
  5.2770 +proof safe fix a b c::"real^1" assume as:"\<forall>a b c. f {a..b} = opp (f ({a..b} \<inter> {x. x $ 1 \<le> c})) (f ({a..b} \<inter> {x. c \<le> x $ 1}))" "a $ 1 < c $ 1" "c $ 1 < b $ 1"
  5.2771 +    from this(2-) have "{a..b} \<inter> {x. x $ 1 \<le> c $ 1} = {a..c}" "{a..b} \<inter> {x. x $ 1 \<ge> c $ 1} = {c..b}" by auto
  5.2772 +    thus "opp (f {a..c}) (f {c..b}) = f {a..b}" unfolding as(1)[rule_format,of a b "c$1"] by auto
  5.2773 +next fix a b::"real^1" and c::real
  5.2774 +  assume as:"\<forall>a b. b $ 1 \<le> a $ 1 \<longrightarrow> f {a..b} = neutral opp" "\<forall>a b c. a $ 1 < c $ 1 \<and> c $ 1 < b $ 1 \<longrightarrow> opp (f {a..c}) (f {c..b}) = f {a..b}"
  5.2775 +  show "f {a..b} = opp (f ({a..b} \<inter> {x. x $ 1 \<le> c})) (f ({a..b} \<inter> {x. c \<le> x $ 1}))"
  5.2776 +  proof(cases "c \<in> {a$1 .. b$1}")
  5.2777 +    case False hence "c<a$1 \<or> c>b$1" by auto
  5.2778 +    thus ?thesis apply-apply(erule disjE)
  5.2779 +    proof- assume "c<a$1" hence *:"{a..b} \<inter> {x. x $ 1 \<le> c} = {1..0}"  "{a..b} \<inter> {x. c \<le> x $ 1} = {a..b}" by auto
  5.2780 +      show ?thesis unfolding * apply(subst as(1)[rule_format,of 0 1]) using assms by auto
  5.2781 +    next   assume "b$1<c" hence *:"{a..b} \<inter> {x. x $ 1 \<le> c} = {a..b}"  "{a..b} \<inter> {x. c \<le> x $ 1} = {1..0}" by auto
  5.2782 +      show ?thesis unfolding * apply(subst as(1)[rule_format,of 0 1]) using assms by auto
  5.2783 +    qed
  5.2784 +  next case True hence *:"min (b $ 1) c = c" "max (a $ 1) c = c" by auto
  5.2785 +    show ?thesis unfolding interval_split num1_eq_iff if_True * vec_def[THEN sym]
  5.2786 +    proof(cases "c = a$1 \<or> c = b$1")
  5.2787 +      case False thus "f {a..b} = opp (f {a..vec1 c}) (f {vec1 c..b})"
  5.2788 +        apply-apply(subst as(2)[rule_format]) using True by auto
  5.2789 +    next case True thus "f {a..b} = opp (f {a..vec1 c}) (f {vec1 c..b})" apply-
  5.2790 +      proof(erule disjE) assume "c=a$1" hence *:"a = vec1 c" unfolding Cart_eq by auto 
  5.2791 +        hence "f {a..vec1 c} = neutral opp" apply-apply(rule as(1)[rule_format]) by auto
  5.2792 +        thus ?thesis using assms unfolding * by auto
  5.2793 +      next assume "c=b$1" hence *:"b = vec1 c" unfolding Cart_eq by auto 
  5.2794 +        hence "f {vec1 c..b} = neutral opp" apply-apply(rule as(1)[rule_format]) by auto
  5.2795 +        thus ?thesis using assms unfolding * by auto qed qed qed qed
  5.2796 +
  5.2797 +lemma operative_1_le: assumes "monoidal opp"
  5.2798 +  shows "operative opp f \<longleftrightarrow> ((\<forall>a b. b \<le> a \<longrightarrow> f {a..b::real^1} = neutral opp) \<and>
  5.2799 +                (\<forall>a b c. a \<le> c \<and> c \<le> b \<longrightarrow> opp (f{a..c})(f{c..b}) = f {a..b}))"
  5.2800 +unfolding operative_1_lt[OF assms]
  5.2801 +proof safe fix a b c::"real^1" assume as:"\<forall>a b c. a \<le> c \<and> c \<le> b \<longrightarrow> opp (f {a..c}) (f {c..b}) = f {a..b}" "a < c" "c < b"
  5.2802 +  show "opp (f {a..c}) (f {c..b}) = f {a..b}" apply(rule as(1)[rule_format]) using as(2-) unfolding vector_le_def vector_less_def by auto
  5.2803 +next fix a b c ::"real^1"
  5.2804 +  assume "\<forall>a b. b \<le> a \<longrightarrow> f {a..b} = neutral opp" "\<forall>a b c. a < c \<and> c < b \<longrightarrow> opp (f {a..c}) (f {c..b}) = f {a..b}" "a \<le> c" "c \<le> b"
  5.2805 +  note as = this[rule_format]
  5.2806 +  show "opp (f {a..c}) (f {c..b}) = f {a..b}"
  5.2807 +  proof(cases "c = a \<or> c = b")
  5.2808 +    case False thus ?thesis apply-apply(subst as(2)) using as(3-) unfolding vector_le_def vector_less_def Cart_eq by(auto simp del:dest_vec1_eq)
  5.2809 +    next case True thus ?thesis apply-
  5.2810 +      proof(erule disjE) assume *:"c=a" hence "f {a..c} = neutral opp" apply-apply(rule as(1)[rule_format]) by auto
  5.2811 +        thus ?thesis using assms unfolding * by auto
  5.2812 +      next               assume *:"c=b" hence "f {c..b} = neutral opp" apply-apply(rule as(1)[rule_format]) by auto
  5.2813 +        thus ?thesis using assms unfolding * by auto qed qed qed 
  5.2814 +
  5.2815 +subsection {* Special case of additivity we need for the FCT. *}
  5.2816 +
  5.2817 +lemma additive_tagged_division_1: fixes f::"real^1 \<Rightarrow> 'a::real_normed_vector"
  5.2818 +  assumes "dest_vec1 a \<le> dest_vec1 b" "p tagged_division_of {a..b}"
  5.2819 +  shows "setsum (\<lambda>(x,k). f(interval_upperbound k) - f(interval_lowerbound k)) p = f b - f a"
  5.2820 +proof- let ?f = "(\<lambda>k::(real^1) set. if k = {} then 0 else f(interval_upperbound k) - f(interval_lowerbound k))"
  5.2821 +  have *:"operative op + ?f" unfolding operative_1_lt[OF monoidal_monoid] interval_eq_empty_1
  5.2822 +    by(auto simp add:not_less interval_bound_1 vector_less_def)
  5.2823 +  have **:"{a..b} \<noteq> {}" using assms(1) by auto note operative_tagged_division[OF monoidal_monoid * assms(2)]
  5.2824 +  note * = this[unfolded if_not_P[OF **] interval_bound_1[OF assms(1)],THEN sym ]
  5.2825 +  show ?thesis unfolding * apply(subst setsum_iterate[THEN sym]) defer
  5.2826 +    apply(rule setsum_cong2) unfolding split_paired_all split_conv using assms(2) by auto qed
  5.2827 +
  5.2828 +subsection {* A useful lemma allowing us to factor out the content size. *}
  5.2829 +
  5.2830 +lemma has_integral_factor_content:
  5.2831 +  "(f has_integral i) {a..b} \<longleftrightarrow> (\<forall>e>0. \<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p
  5.2832 +    \<longrightarrow> norm (setsum (\<lambda>(x,k). content k *\<^sub>R f x) p - i) \<le> e * content {a..b}))"
  5.2833 +proof(cases "content {a..b} = 0")
  5.2834 +  case True show ?thesis unfolding has_integral_null_eq[OF True] apply safe
  5.2835 +    apply(rule,rule,rule gauge_trivial,safe) unfolding setsum_content_null[OF True] True defer 
  5.2836 +    apply(erule_tac x=1 in allE,safe) defer apply(rule fine_division_exists[of _ a b],assumption)
  5.2837 +    apply(erule_tac x=p in allE) unfolding setsum_content_null[OF True] by auto
  5.2838 +next case False note F = this[unfolded content_lt_nz[THEN sym]]
  5.2839 +  let ?P = "\<lambda>e opp. \<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> opp (norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - i)) e)"
  5.2840 +  show ?thesis apply(subst has_integral)
  5.2841 +  proof safe fix e::real assume e:"e>0"
  5.2842 +    { assume "\<forall>e>0. ?P e op <" thus "?P (e * content {a..b}) op \<le>" apply(erule_tac x="e * content {a..b}" in allE)
  5.2843 +        apply(erule impE) defer apply(erule exE,rule_tac x=d in exI)
  5.2844 +        using F e by(auto simp add:field_simps intro:mult_pos_pos) }
  5.2845 +    {  assume "\<forall>e>0. ?P (e * content {a..b}) op \<le>" thus "?P e op <" apply(erule_tac x="e / 2 / content {a..b}" in allE)
  5.2846 +        apply(erule impE) defer apply(erule exE,rule_tac x=d in exI)
  5.2847 +        using F e by(auto simp add:field_simps intro:mult_pos_pos) } qed qed
  5.2848 +
  5.2849 +subsection {* Fundamental theorem of calculus. *}
  5.2850 +
  5.2851 +lemma fundamental_theorem_of_calculus: fixes f::"real^1 \<Rightarrow> 'a::banach"
  5.2852 +  assumes "a \<le> b"  "\<forall>x\<in>{a..b}. ((f o vec1) has_vector_derivative f'(vec1 x)) (at x within {a..b})"
  5.2853 +  shows "(f' has_integral (f(vec1 b) - f(vec1 a))) ({vec1 a..vec1 b})"
  5.2854 +unfolding has_integral_factor_content
  5.2855 +proof safe fix e::real assume e:"e>0" have ab:"dest_vec1 (vec1 a) \<le> dest_vec1 (vec1 b)" using assms(1) by auto
  5.2856 +  note assm = assms(2)[unfolded has_vector_derivative_def has_derivative_within_alt]
  5.2857 +  have *:"\<And>P Q. \<forall>x\<in>{a..b}. P x \<and> (\<forall>e>0. \<exists>d>0. Q x e d) \<Longrightarrow> \<forall>x. \<exists>(d::real)>0. x\<in>{a..b} \<longrightarrow> Q x e d" using e by blast
  5.2858 +  note this[OF assm,unfolded gauge_existence_lemma] from choice[OF this,unfolded Ball_def[symmetric]]
  5.2859 +  guess d .. note d=conjunctD2[OF this[rule_format],rule_format]
  5.2860 +  show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {vec1 a..vec1 b} \<and> d fine p \<longrightarrow>
  5.2861 +                 norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f' x) - (f (vec1 b) - f (vec1 a))) \<le> e * content {vec1 a..vec1 b})"
  5.2862 +    apply(rule_tac x="\<lambda>x. ball x (d (dest_vec1 x))" in exI,safe)
  5.2863 +    apply(rule gauge_ball_dependent,rule,rule d(1))
  5.2864 +  proof- fix p assume as:"p tagged_division_of {vec1 a..vec1 b}" "(\<lambda>x. ball x (d (dest_vec1 x))) fine p"
  5.2865 +    show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f' x) - (f (vec1 b) - f (vec1 a))) \<le> e * content {vec1 a..vec1 b}" 
  5.2866 +      unfolding content_1[OF ab] additive_tagged_division_1[OF ab as(1),of f,THEN sym]
  5.2867 +      unfolding vector_minus_component[THEN sym] additive_tagged_division_1[OF ab as(1),of "\<lambda>x. x",THEN sym]
  5.2868 +      apply(subst dest_vec1_setsum) unfolding setsum_right_distrib defer unfolding setsum_subtractf[THEN sym] 
  5.2869 +    proof(rule setsum_norm_le,safe) fix x k assume "(x,k)\<in>p"
  5.2870 +      note xk = tagged_division_ofD(2-4)[OF as(1) this] from this(3) guess u v apply-by(erule exE)+ note k=this
  5.2871 +      have *:"dest_vec1 u \<le> dest_vec1 v" using xk unfolding k by auto
  5.2872 +      have ball:"\<forall>xa\<in>k. xa \<in> ball x (d (dest_vec1 x))" using as(2)[unfolded fine_def,rule_format,OF `(x,k)\<in>p`,unfolded split_conv subset_eq] .
  5.2873 +      have "norm ((v$1 - u$1) *\<^sub>R f' x - (f v - f u)) \<le> norm (f u - f x - (u$1 - x$1) *\<^sub>R f' x) + norm (f v - f x - (v$1 - x$1) *\<^sub>R f' x)"
  5.2874 +        apply(rule order_trans[OF _ norm_triangle_ineq4]) apply(rule eq_refl) apply(rule arg_cong[where f=norm])
  5.2875 +        unfolding scaleR.diff_left by(auto simp add:group_simps)
  5.2876 +      also have "... \<le> e * norm (dest_vec1 u - dest_vec1 x) + e * norm (dest_vec1 v - dest_vec1 x)"
  5.2877 +        apply(rule add_mono) apply(rule d(2)[of "x$1" "u$1",unfolded o_def vec1_dest_vec1]) prefer 4
  5.2878 +        apply(rule d(2)[of "x$1" "v$1",unfolded o_def vec1_dest_vec1])
  5.2879 +        using ball[rule_format,of u] ball[rule_format,of v] 
  5.2880 +        using xk(1-2) unfolding k subset_eq by(auto simp add:vector_dist_norm norm_real)
  5.2881 +      also have "... \<le> e * dest_vec1 (interval_upperbound k - interval_lowerbound k)"
  5.2882 +        unfolding k interval_bound_1[OF *] using xk(1) unfolding k by(auto simp add:vector_dist_norm norm_real field_simps)
  5.2883 +      finally show "norm (content k *\<^sub>R f' x - (f (interval_upperbound k) - f (interval_lowerbound k))) \<le>
  5.2884 +        e * dest_vec1 (interval_upperbound k - interval_lowerbound k)" unfolding k interval_bound_1[OF *] content_1[OF *] .
  5.2885 +    qed(insert as, auto) qed qed
  5.2886 +
  5.2887 +subsection {* Attempt a systematic general set of "offset" results for components. *}
  5.2888 +
  5.2889 +lemma gauge_modify:
  5.2890 +  assumes "(\<forall>s. open s \<longrightarrow> open {x. f(x) \<in> s})" "gauge d"
  5.2891 +  shows "gauge (\<lambda>x y. d (f x) (f y))"
  5.2892 +  using assms unfolding gauge_def apply safe defer apply(erule_tac x="f x" in allE)
  5.2893 +  apply(erule_tac x="d (f x)" in allE) unfolding mem_def Collect_def by auto
  5.2894 +
  5.2895 +subsection {* Only need trivial subintervals if the interval itself is trivial. *}
  5.2896 +
  5.2897 +lemma division_of_nontrivial: fixes s::"(real^'n) set set"
  5.2898 +  assumes "s division_of {a..b}" "content({a..b}) \<noteq> 0"
  5.2899 +  shows "{k. k \<in> s \<and> content k \<noteq> 0} division_of {a..b}" using assms(1) apply-
  5.2900 +proof(induct "card s" arbitrary:s rule:nat_less_induct)
  5.2901 +  fix s::"(real^'n) set set" assume assm:"s division_of {a..b}"
  5.2902 +    "\<forall>m<card s. \<forall>x. m = card x \<longrightarrow> x division_of {a..b} \<longrightarrow> {k \<in> x. content k \<noteq> 0} division_of {a..b}" 
  5.2903 +  note s = division_ofD[OF assm(1)] let ?thesis = "{k \<in> s. content k \<noteq> 0} division_of {a..b}"
  5.2904 +  { presume *:"{k \<in> s. content k \<noteq> 0} \<noteq> s \<Longrightarrow> ?thesis"
  5.2905 +    show ?thesis apply cases defer apply(rule *,assumption) using assm(1) by auto }
  5.2906 +  assume noteq:"{k \<in> s. content k \<noteq> 0} \<noteq> s"
  5.2907 +  then obtain k where k:"k\<in>s" "content k = 0" by auto
  5.2908 +  from s(4)[OF k(1)] guess c d apply-by(erule exE)+ note k=k this
  5.2909 +  from k have "card s > 0" unfolding card_gt_0_iff using assm(1) by auto
  5.2910 +  hence card:"card (s - {k}) < card s" using assm(1) k(1) apply(subst card_Diff_singleton_if) by auto
  5.2911 +  have *:"closed (\<Union>(s - {k}))" apply(rule closed_Union) defer apply rule apply(drule DiffD1,drule s(4))
  5.2912 +    apply safe apply(rule closed_interval) using assm(1) by auto
  5.2913 +  have "k \<subseteq> \<Union>(s - {k})" apply safe apply(rule *[unfolded closed_limpt,rule_format]) unfolding islimpt_approachable
  5.2914 +  proof safe fix x and e::real assume as:"x\<in>k" "e>0"
  5.2915 +    from k(2)[unfolded k content_eq_0] guess i .. 
  5.2916 +    hence i:"c$i = d$i" using s(3)[OF k(1),unfolded k] unfolding interval_ne_empty by smt
  5.2917 +    hence xi:"x$i = d$i" using as unfolding k mem_interval by smt
  5.2918 +    def y \<equiv> "(\<chi> j. if j = i then if c$i \<le> (a$i + b$i) / 2 then c$i + min e (b$i - c$i) / 2 else c$i - min e (c$i - a$i) / 2 else x$j)"
  5.2919 +    show "\<exists>x'\<in>\<Union>(s - {k}). x' \<noteq> x \<and> dist x' x < e" apply(rule_tac x=y in bexI) 
  5.2920 +    proof have "d \<in> {c..d}" using s(3)[OF k(1)] unfolding k interval_eq_empty mem_interval by(fastsimp simp add: not_less)
  5.2921 +      hence "d \<in> {a..b}" using s(2)[OF k(1)] unfolding k by auto note di = this[unfolded mem_interval,THEN spec[where x=i]]
  5.2922 +      hence xyi:"y$i \<noteq> x$i" unfolding y_def unfolding i xi Cart_lambda_beta if_P[OF refl]
  5.2923 +        apply(cases) apply(subst if_P,assumption) unfolding if_not_P not_le using as(2) using assms(2)[unfolded content_eq_0] by smt+ 
  5.2924 +      thus "y \<noteq> x" unfolding Cart_eq by auto
  5.2925 +      have *:"UNIV = insert i (UNIV - {i})" by auto
  5.2926 +      have "norm (y - x) < e + setsum (\<lambda>i. 0) (UNIV::'n set)" apply(rule le_less_trans[OF norm_le_l1])
  5.2927 +        apply(subst *,subst setsum_insert) prefer 3 apply(rule add_less_le_mono)
  5.2928 +      proof- show "\<bar>(y - x) $ i\<bar> < e" unfolding y_def Cart_lambda_beta vector_minus_component if_P[OF refl]
  5.2929 +          apply(cases) apply(subst if_P,assumption) unfolding if_not_P unfolding i xi using di as(2) by auto
  5.2930 +        show "(\<Sum>i\<in>UNIV - {i}. \<bar>(y - x) $ i\<bar>) \<le> (\<Sum>i\<in>UNIV. 0)" unfolding y_def by auto 
  5.2931 +      qed auto thus "dist y x < e" unfolding vector_dist_norm by auto
  5.2932 +      have "y\<notin>k" unfolding k mem_interval apply rule apply(erule_tac x=i in allE) using xyi unfolding k i xi by auto
  5.2933 +      moreover have "y \<in> \<Union>s" unfolding s mem_interval
  5.2934 +      proof note simps = y_def Cart_lambda_beta if_not_P
  5.2935 +        fix j::'n show "a $ j \<le> y $ j \<and> y $ j \<le> b $ j" 
  5.2936 +        proof(cases "j = i") case False have "x \<in> {a..b}" using s(2)[OF k(1)] as(1) by auto
  5.2937 +          thus ?thesis unfolding simps if_not_P[OF False] unfolding mem_interval by auto
  5.2938 +        next case True note T = this show ?thesis
  5.2939 +          proof(cases "c $ i \<le> (a $ i + b $ i) / 2")
  5.2940 +            case True show ?thesis unfolding simps if_P[OF T] if_P[OF True] unfolding i
  5.2941 +              using True as(2) di apply-apply rule unfolding T by (auto simp add:field_simps) 
  5.2942 +          next case False thus ?thesis unfolding simps if_P[OF T] if_not_P[OF False] unfolding i