src/HOL/Multivariate_Analysis/Integration.thy
changeset 50526 899c9c4e4a4c
parent 50348 4b4fe0d5ee22
child 50919 cc03437a1f80
equal deleted inserted replaced
50525:46be26e02456 50526:899c9c4e4a4c
    69   apply (erule exE)
    69   apply (erule exE)
    70   apply (rule_tac x = b in exI)
    70   apply (rule_tac x = b in exI)
    71   apply (auto simp: isUb_def setle_def)
    71   apply (auto simp: isUb_def setle_def)
    72   done
    72   done
    73 
    73 
    74 lemma bounded_linear_component [intro]: "bounded_linear (\<lambda>x::'a::euclidean_space. x $$ k)"
    74 lemma bounded_linear_component [intro]: "bounded_linear (\<lambda>x::'a::euclidean_space. x \<bullet> k)"
    75   apply (rule bounded_linearI[where K=1])
    75   by (rule bounded_linear_inner_left)
    76   using component_le_norm[of _ k]
       
    77   unfolding real_norm_def
       
    78   apply auto
       
    79   done
       
    80 
    76 
    81 lemma transitive_stepwise_lt_eq:
    77 lemma transitive_stepwise_lt_eq:
    82   assumes "(\<And>x y z::nat. R x y \<Longrightarrow> R y z \<Longrightarrow> R x z)"
    78   assumes "(\<And>x y z::nat. R x y \<Longrightarrow> R y z \<Longrightarrow> R x z)"
    83   shows "((\<forall>m. \<forall>n>m. R m n) \<longleftrightarrow> (\<forall>n. R n (Suc n)))" (is "?l = ?r")
    79   shows "((\<forall>m. \<forall>n>m. R m n) \<longleftrightarrow> (\<forall>n. R n (Suc n)))" (is "?l = ?r")
    84 proof (safe)
    80 proof (safe)
   160 qed
   156 qed
   161 
   157 
   162 
   158 
   163 subsection {* Some useful lemmas about intervals. *}
   159 subsection {* Some useful lemmas about intervals. *}
   164 
   160 
   165 abbreviation One  where "One \<equiv> ((\<chi>\<chi> i. 1)::_::ordered_euclidean_space)"
   161 abbreviation One where "One \<equiv> ((\<Sum>Basis)::_::euclidean_space)"
   166 
   162 
   167 lemma empty_as_interval: "{} = {One..0}"
   163 lemma empty_as_interval: "{} = {One..(0::'a::ordered_euclidean_space)}"
   168   apply (rule set_eqI, rule)
   164   by (auto simp: set_eq_iff eucl_le[where 'a='a] intro!: bexI[OF _ SOME_Basis])
   169   defer
       
   170   unfolding mem_interval
       
   171   using UNIV_witness[where 'a='n]
       
   172   apply (erule_tac exE, rule_tac x = x in allE)
       
   173   apply auto
       
   174   done
       
   175 
   165 
   176 lemma interior_subset_union_intervals: 
   166 lemma interior_subset_union_intervals: 
   177   assumes "i = {a..b::'a::ordered_euclidean_space}" "j = {c..d}"
   167   assumes "i = {a..b::'a::ordered_euclidean_space}" "j = {c..d}"
   178     "interior j \<noteq> {}" "i \<subseteq> j \<union> s" "interior(i) \<inter> interior(j) = {}"
   168     "interior j \<noteq> {}" "i \<subseteq> j \<union> s" "interior(i) \<inter> interior(j) = {}"
   179   shows "interior i \<subseteq> interior s"
   169   shows "interior i \<subseteq> interior s"
   253             unfolding ab
   243             unfolding ab
   254             using interval_open_subset_closed[of a b] and e apply fastforce+
   244             using interval_open_subset_closed[of a b] and e apply fastforce+
   255             done
   245             done
   256         next
   246         next
   257           case False
   247           case False
   258           then obtain k where "x$$k \<le> a$$k \<or> x$$k \<ge> b$$k" and k:"k<DIM('a)"
   248           then obtain k where "x\<bullet>k \<le> a\<bullet>k \<or> x\<bullet>k \<ge> b\<bullet>k" and k:"k\<in>Basis"
   259             unfolding mem_interval by (auto simp add: not_less)
   249             unfolding mem_interval by (auto simp add: not_less)
   260           hence "x$$k = a$$k \<or> x$$k = b$$k"
   250           hence "x\<bullet>k = a\<bullet>k \<or> x\<bullet>k = b\<bullet>k"
   261             using True unfolding ab and mem_interval
   251             using True unfolding ab and mem_interval
   262               apply (erule_tac x = k in allE)
   252               apply (erule_tac x = k in ballE)
   263               apply auto
   253               apply auto
   264               done
   254               done
   265           hence "\<exists>x. ball x (e/2) \<subseteq> s \<inter> (\<Union>f)"
   255           hence "\<exists>x. ball x (e/2) \<subseteq> s \<inter> (\<Union>f)"
   266           proof (erule_tac disjE)
   256           proof (erule_tac disjE)
   267             let ?z = "x - (e/2) *\<^sub>R basis k"
   257             let ?z = "x - (e/2) *\<^sub>R k"
   268             assume as: "x$$k = a$$k"
   258             assume as: "x\<bullet>k = a\<bullet>k"
   269             have "ball ?z (e / 2) \<inter> i = {}"
   259             have "ball ?z (e / 2) \<inter> i = {}"
   270               apply (rule ccontr)
   260               apply (rule ccontr)
   271               unfolding ex_in_conv[THEN sym]
   261               unfolding ex_in_conv[THEN sym]
   272             proof (erule exE)
   262             proof (erule exE)
   273               fix y
   263               fix y
   274               assume "y \<in> ball ?z (e / 2) \<inter> i"
   264               assume "y \<in> ball ?z (e / 2) \<inter> i"
   275               hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
   265               hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
   276               hence "\<bar>(?z - y) $$ k\<bar> < e/2"
   266               hence "\<bar>(?z - y) \<bullet> k\<bar> < e/2"
   277                 using component_le_norm[of "?z - y" k] unfolding dist_norm by auto
   267                 using Basis_le_norm[OF k, of "?z - y"] unfolding dist_norm by auto
   278               hence "y$$k < a$$k"
   268               hence "y\<bullet>k < a\<bullet>k"
   279                 using e[THEN conjunct1] k by (auto simp add: field_simps as)
   269                 using e[THEN conjunct1] k by (auto simp add: field_simps as inner_Basis inner_simps)
   280               hence "y \<notin> i"
   270               hence "y \<notin> i"
   281                 unfolding ab mem_interval not_all
   271                 unfolding ab mem_interval by (auto intro!: bexI[OF _ k])
   282                 apply (rule_tac x=k in exI)
       
   283                 using k apply auto
       
   284                 done
       
   285               thus False using yi by auto
   272               thus False using yi by auto
   286             qed
   273             qed
   287             moreover
   274             moreover
   288             have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)"
   275             have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)"
   289               apply(rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]])
   276               apply(rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]])
   290             proof
   277             proof
   291               fix y
   278               fix y
   292               assume as: "y\<in> ball ?z (e/2)"
   279               assume as: "y\<in> ball ?z (e/2)"
   293               have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y - (e / 2) *\<^sub>R basis k)"
   280               have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y - (e / 2) *\<^sub>R k)"
   294                 apply -
   281                 apply -
   295                 apply (rule order_trans,rule norm_triangle_sub[of "x - y" "(e/2) *\<^sub>R basis k"])
   282                 apply (rule order_trans,rule norm_triangle_sub[of "x - y" "(e/2) *\<^sub>R k"])
   296                 unfolding norm_scaleR norm_basis
   283                 unfolding norm_scaleR norm_Basis[OF k]
   297                 apply auto
   284                 apply auto
   298                 done
   285                 done
   299               also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2"
   286               also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2"
   300                 apply (rule add_strict_left_mono)
   287                 apply (rule add_strict_left_mono)
   301                 using as unfolding mem_ball dist_norm
   288                 using as unfolding mem_ball dist_norm
   308               apply (rule_tac x="?z" in exI)
   295               apply (rule_tac x="?z" in exI)
   309               unfolding Union_insert
   296               unfolding Union_insert
   310               apply auto
   297               apply auto
   311               done
   298               done
   312           next
   299           next
   313             let ?z = "x + (e/2) *\<^sub>R basis k"
   300             let ?z = "x + (e/2) *\<^sub>R k"
   314             assume as: "x$$k = b$$k"
   301             assume as: "x\<bullet>k = b\<bullet>k"
   315             have "ball ?z (e / 2) \<inter> i = {}"
   302             have "ball ?z (e / 2) \<inter> i = {}"
   316               apply (rule ccontr)
   303               apply (rule ccontr)
   317               unfolding ex_in_conv[THEN sym]
   304               unfolding ex_in_conv[THEN sym]
   318             proof(erule exE)
   305             proof(erule exE)
   319               fix y
   306               fix y
   320               assume "y \<in> ball ?z (e / 2) \<inter> i"
   307               assume "y \<in> ball ?z (e / 2) \<inter> i"
   321               hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
   308               hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
   322               hence "\<bar>(?z - y) $$ k\<bar> < e/2"
   309               hence "\<bar>(?z - y) \<bullet> k\<bar> < e/2"
   323                 using component_le_norm[of "?z - y" k] unfolding dist_norm by auto
   310                 using Basis_le_norm[OF k, of "?z - y"] unfolding dist_norm by auto
   324               hence "y$$k > b$$k"
   311               hence "y\<bullet>k > b\<bullet>k"
   325                 using e[THEN conjunct1] k by(auto simp add:field_simps as)
   312                 using e[THEN conjunct1] k by(auto simp add:field_simps inner_simps inner_Basis as)
   326               hence "y \<notin> i"
   313               hence "y \<notin> i"
   327                 unfolding ab mem_interval not_all
   314                 unfolding ab mem_interval by (auto intro!: bexI[OF _ k])
   328                 using k apply (rule_tac x=k in exI)
       
   329                 apply auto
       
   330                 done
       
   331               thus False using yi by auto
   315               thus False using yi by auto
   332             qed
   316             qed
   333             moreover
   317             moreover
   334             have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)"
   318             have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)"
   335               apply (rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]])
   319               apply (rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]])
   336             proof
   320             proof
   337               fix y
   321               fix y
   338               assume as: "y\<in> ball ?z (e/2)"
   322               assume as: "y\<in> ball ?z (e/2)"
   339               have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y + (e / 2) *\<^sub>R basis k)"
   323               have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y + (e / 2) *\<^sub>R k)"
   340                 apply -
   324                 apply -
   341                 apply(rule order_trans,rule norm_triangle_sub[of "x - y" "- (e/2) *\<^sub>R basis k"])
   325                 apply(rule order_trans,rule norm_triangle_sub[of "x - y" "- (e/2) *\<^sub>R k"])
   342                 unfolding norm_scaleR
   326                 unfolding norm_scaleR
   343                 apply auto
   327                 apply (auto simp: k)
   344                 done
   328                 done
   345               also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2"
   329               also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2"
   346                 apply (rule add_strict_left_mono)
   330                 apply (rule add_strict_left_mono)
   347                 using as unfolding mem_ball dist_norm
   331                 using as unfolding mem_ball dist_norm
   348                 using e apply (auto simp add: field_simps)
   332                 using e apply (auto simp add: field_simps)
   381 qed
   365 qed
   382 
   366 
   383 
   367 
   384 subsection {* Bounds on intervals where they exist. *}
   368 subsection {* Bounds on intervals where they exist. *}
   385 
   369 
   386 definition "interval_upperbound (s::('a::ordered_euclidean_space) set) =
   370 definition interval_upperbound :: "('a::ordered_euclidean_space) set \<Rightarrow> 'a" where
   387   ((\<chi>\<chi> i. Sup {a. \<exists>x\<in>s. x$$i = a})::'a)"
   371   "interval_upperbound s = (\<Sum>i\<in>Basis. Sup {a. \<exists>x\<in>s. x\<bullet>i = a} *\<^sub>R i)"
   388 
   372 
   389 definition "interval_lowerbound (s::('a::ordered_euclidean_space) set) =
   373 definition interval_lowerbound :: "('a::ordered_euclidean_space) set \<Rightarrow> 'a" where
   390   ((\<chi>\<chi> i. Inf {a. \<exists>x\<in>s. x$$i = a})::'a)"
   374   "interval_lowerbound s = (\<Sum>i\<in>Basis. Inf {a. \<exists>x\<in>s. x\<bullet>i = a} *\<^sub>R i)"
   391 
   375 
   392 lemma interval_upperbound[simp]:
   376 lemma interval_upperbound[simp]:
   393   assumes "\<forall>i<DIM('a::ordered_euclidean_space). a$$i \<le> (b::'a)$$i"
   377   "\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i \<Longrightarrow>
   394   shows "interval_upperbound {a..b} = b"
   378     interval_upperbound {a..b} = (b::'a::ordered_euclidean_space)"
   395   using assms
   379   unfolding interval_upperbound_def euclidean_representation_setsum
   396   unfolding interval_upperbound_def
   380   by (auto simp del: ex_simps simp add: Bex_def ex_simps[symmetric] eucl_le[where 'a='a] setle_def
   397   apply (subst euclidean_eq[where 'a='a])
   381            intro!: Sup_unique)
   398   apply safe
       
   399   unfolding euclidean_lambda_beta'
       
   400   apply (erule_tac x=i in allE)
       
   401   apply (rule Sup_unique)
       
   402   unfolding setle_def
       
   403   apply rule
       
   404   unfolding mem_Collect_eq
       
   405   apply (erule bexE)
       
   406   unfolding mem_interval
       
   407   defer
       
   408   apply (rule, rule)
       
   409   apply (rule_tac x="b$$i" in bexI)
       
   410   defer
       
   411   unfolding mem_Collect_eq
       
   412   apply (rule_tac x=b in bexI)
       
   413   unfolding mem_interval
       
   414   using assms apply auto
       
   415   done
       
   416 
   382 
   417 lemma interval_lowerbound[simp]:
   383 lemma interval_lowerbound[simp]:
   418   assumes "\<forall>i<DIM('a::ordered_euclidean_space). a$$i \<le> (b::'a)$$i"
   384   "\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i \<Longrightarrow>
   419   shows "interval_lowerbound {a..b} = a"
   385     interval_lowerbound {a..b} = (a::'a::ordered_euclidean_space)"
   420   using assms
   386   unfolding interval_lowerbound_def euclidean_representation_setsum
   421   unfolding interval_lowerbound_def
   387   by (auto simp del: ex_simps simp add: Bex_def ex_simps[symmetric] eucl_le[where 'a='a] setge_def
   422   apply (subst euclidean_eq[where 'a='a])
   388            intro!: Inf_unique)
   423   apply safe
       
   424   unfolding euclidean_lambda_beta'
       
   425   apply (erule_tac x=i in allE)
       
   426   apply (rule Inf_unique)
       
   427   unfolding setge_def
       
   428   apply rule
       
   429   unfolding mem_Collect_eq
       
   430   apply (erule bexE)
       
   431   unfolding mem_interval
       
   432   defer
       
   433   apply (rule, rule)
       
   434   apply (rule_tac x = "a$$i" in bexI)
       
   435   defer
       
   436   unfolding mem_Collect_eq
       
   437   apply (rule_tac x=a in bexI)
       
   438   unfolding mem_interval
       
   439   using assms apply auto
       
   440   done
       
   441 
   389 
   442 lemmas interval_bounds = interval_upperbound interval_lowerbound
   390 lemmas interval_bounds = interval_upperbound interval_lowerbound
   443 
   391 
   444 lemma interval_bounds'[simp]:
   392 lemma interval_bounds'[simp]:
   445   assumes "{a..b}\<noteq>{}"
   393   assumes "{a..b}\<noteq>{}"
   447   using assms unfolding interval_ne_empty by auto
   395   using assms unfolding interval_ne_empty by auto
   448 
   396 
   449 subsection {* Content (length, area, volume...) of an interval. *}
   397 subsection {* Content (length, area, volume...) of an interval. *}
   450 
   398 
   451 definition "content (s::('a::ordered_euclidean_space) set) =
   399 definition "content (s::('a::ordered_euclidean_space) set) =
   452   (if s = {} then 0 else (\<Prod>i<DIM('a). (interval_upperbound s)$$i - (interval_lowerbound s)$$i))"
   400   (if s = {} then 0 else (\<Prod>i\<in>Basis. (interval_upperbound s)\<bullet>i - (interval_lowerbound s)\<bullet>i))"
   453 
   401 
   454 lemma interval_not_empty:"\<forall>i<DIM('a). a$$i \<le> b$$i \<Longrightarrow> {a..b::'a::ordered_euclidean_space} \<noteq> {}"
   402 lemma interval_not_empty:"\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i \<Longrightarrow> {a..b::'a::ordered_euclidean_space} \<noteq> {}"
   455   unfolding interval_eq_empty unfolding not_ex not_less by auto
   403   unfolding interval_eq_empty unfolding not_ex not_less by auto
   456 
   404 
   457 lemma content_closed_interval:
   405 lemma content_closed_interval:
   458   fixes a::"'a::ordered_euclidean_space"
   406   fixes a::"'a::ordered_euclidean_space"
   459   assumes "\<forall>i<DIM('a). a$$i \<le> b$$i"
   407   assumes "\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i"
   460   shows "content {a..b} = (\<Prod>i<DIM('a). b$$i - a$$i)"
   408   shows "content {a..b} = (\<Prod>i\<in>Basis. b\<bullet>i - a\<bullet>i)"
   461   using interval_not_empty[OF assms]
   409   using interval_not_empty[OF assms]
   462   unfolding content_def interval_upperbound[OF assms] interval_lowerbound[OF assms]
   410   unfolding content_def interval_upperbound[OF assms] interval_lowerbound[OF assms]
   463   by auto
   411   by auto
   464 
   412 
   465 lemma content_closed_interval':
   413 lemma content_closed_interval':
   466   fixes a::"'a::ordered_euclidean_space"
   414   fixes a::"'a::ordered_euclidean_space"
   467   assumes "{a..b}\<noteq>{}"
   415   assumes "{a..b}\<noteq>{}"
   468   shows "content {a..b} = (\<Prod>i<DIM('a). b$$i - a$$i)"
   416   shows "content {a..b} = (\<Prod>i\<in>Basis. b\<bullet>i - a\<bullet>i)"
   469   apply (rule content_closed_interval)
   417   apply (rule content_closed_interval)
   470   using assms unfolding interval_ne_empty
   418   using assms unfolding interval_ne_empty
   471   apply assumption
   419   apply assumption
   472   done
   420   done
   473 
   421 
   480 qed
   428 qed
   481 
   429 
   482 lemma content_singleton[simp]: "content {a} = 0"
   430 lemma content_singleton[simp]: "content {a} = 0"
   483 proof -
   431 proof -
   484   have "content {a .. a} = 0"
   432   have "content {a .. a} = 0"
   485     by (subst content_closed_interval) auto
   433     by (subst content_closed_interval) (auto simp: ex_in_conv)
   486   then show ?thesis by simp
   434   then show ?thesis by simp
   487 qed
   435 qed
   488 
   436 
   489 lemma content_unit[intro]: "content{0..One::'a::ordered_euclidean_space} = 1"
   437 lemma content_unit[intro]: "content{0..One::'a::ordered_euclidean_space} = 1"
   490 proof -
   438 proof -
   491   have *: "\<forall>i<DIM('a). (0::'a)$$i \<le> (One::'a)$$i" by auto
   439   have *: "\<forall>i\<in>Basis. (0::'a)\<bullet>i \<le> (One::'a)\<bullet>i" by auto
   492   have "0 \<in> {0..One::'a}" unfolding mem_interval by auto
   440   have "0 \<in> {0..One::'a}" unfolding mem_interval by auto
   493   thus ?thesis unfolding content_def interval_bounds[OF *] using setprod_1 by auto
   441   thus ?thesis unfolding content_def interval_bounds[OF *] using setprod_1 by auto
   494 qed
   442 qed
   495 
   443 
   496 lemma content_pos_le[intro]:
   444 lemma content_pos_le[intro]:
   497   fixes a::"'a::ordered_euclidean_space"
   445   fixes a::"'a::ordered_euclidean_space"
   498   shows "0 \<le> content {a..b}"
   446   shows "0 \<le> content {a..b}"
   499 proof (cases "{a..b} = {}")
   447 proof (cases "{a..b} = {}")
   500   case False
   448   case False
   501   hence *: "\<forall>i<DIM('a). a $$ i \<le> b $$ i" unfolding interval_ne_empty .
   449   hence *: "\<forall>i\<in>Basis. a \<bullet> i \<le> b \<bullet> i" unfolding interval_ne_empty .
   502   have "(\<Prod>i<DIM('a). interval_upperbound {a..b} $$ i - interval_lowerbound {a..b} $$ i) \<ge> 0"
   450   have "(\<Prod>i\<in>Basis. interval_upperbound {a..b} \<bullet> i - interval_lowerbound {a..b} \<bullet> i) \<ge> 0"
   503     apply (rule setprod_nonneg)
   451     apply (rule setprod_nonneg)
   504     unfolding interval_bounds[OF *]
   452     unfolding interval_bounds[OF *]
   505     using *
   453     using *
   506     apply (erule_tac x=x in allE)
   454     apply (erule_tac x=x in ballE)
   507     apply auto
   455     apply auto
   508     done
   456     done
   509   thus ?thesis unfolding content_def by (auto simp del:interval_bounds')
   457   thus ?thesis unfolding content_def by (auto simp del:interval_bounds')
   510 qed (unfold content_def, auto)
   458 qed (unfold content_def, auto)
   511 
   459 
   512 lemma content_pos_lt:
   460 lemma content_pos_lt:
   513   fixes a::"'a::ordered_euclidean_space"
   461   fixes a::"'a::ordered_euclidean_space"
   514   assumes "\<forall>i<DIM('a). a$$i < b$$i"
   462   assumes "\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i"
   515   shows "0 < content {a..b}"
   463   shows "0 < content {a..b}"
   516 proof -
   464 proof -
   517   have help_lemma1: "\<forall>i<DIM('a). a$$i < b$$i \<Longrightarrow> \<forall>i<DIM('a). a$$i \<le> ((b$$i)::real)"
   465   have help_lemma1: "\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i \<Longrightarrow> \<forall>i\<in>Basis. a\<bullet>i \<le> ((b\<bullet>i)::real)"
   518     apply (rule, erule_tac x=i in allE)
   466     apply (rule, erule_tac x=i in ballE)
   519     apply auto
   467     apply auto
   520     done
   468     done
   521   show ?thesis unfolding content_closed_interval[OF help_lemma1[OF assms]]
   469   show ?thesis unfolding content_closed_interval[OF help_lemma1[OF assms]]
   522     apply(rule setprod_pos)
   470     apply(rule setprod_pos)
   523     using assms apply (erule_tac x=x in allE)
   471     using assms apply (erule_tac x=x in ballE)
   524     apply auto
   472     apply auto
   525     done
   473     done
   526 qed
   474 qed
   527 
   475 
   528 lemma content_eq_0: "content{a..b::'a::ordered_euclidean_space} = 0 \<longleftrightarrow> (\<exists>i<DIM('a). b$$i \<le> a$$i)"
   476 lemma content_eq_0: "content{a..b::'a::ordered_euclidean_space} = 0 \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i \<le> a\<bullet>i)"
   529 proof (cases "{a..b} = {}")
   477 proof (cases "{a..b} = {}")
   530   case True
   478   case True
   531   thus ?thesis
   479   thus ?thesis
   532     unfolding content_def if_P[OF True]
   480     unfolding content_def if_P[OF True]
   533     unfolding interval_eq_empty
   481     unfolding interval_eq_empty
   534     apply -
   482     apply -
   535     apply (rule, erule exE)
   483     apply (rule, erule bexE)
   536     apply (rule_tac x = i in exI)
   484     apply (rule_tac x = i in bexI)
   537     apply auto
   485     apply auto
   538     done
   486     done
   539 next
   487 next
   540   case False
   488   case False
   541   from this[unfolded interval_eq_empty not_ex not_less]
   489   from this[unfolded interval_eq_empty not_ex not_less]
   542   have as: "\<forall>i<DIM('a). b $$ i \<ge> a $$ i" by fastforce
   490   have as: "\<forall>i\<in>Basis. b \<bullet> i \<ge> a \<bullet> i" by fastforce
   543   show ?thesis
   491   show ?thesis
   544     unfolding content_def if_not_P[OF False] setprod_zero_iff[OF finite_lessThan]
   492     unfolding content_def if_not_P[OF False] setprod_zero_iff[OF finite_Basis]
   545     apply rule
   493     using as
   546     apply (erule_tac[!] exE bexE)
   494     by (auto intro!: bexI)
   547     unfolding interval_bounds[OF as]
       
   548     apply (rule_tac x=x in exI)
       
   549     defer
       
   550     apply (rule_tac x=i in bexI)
       
   551     using as apply (erule_tac x=i in allE)
       
   552     apply auto
       
   553     done
       
   554 qed
   495 qed
   555 
   496 
   556 lemma cond_cases:"(P \<Longrightarrow> Q x) \<Longrightarrow> (\<not> P \<Longrightarrow> Q y) \<Longrightarrow> Q (if P then x else y)" by auto
   497 lemma cond_cases:"(P \<Longrightarrow> Q x) \<Longrightarrow> (\<not> P \<Longrightarrow> Q y) \<Longrightarrow> Q (if P then x else y)" by auto
   557 
   498 
   558 lemma content_closed_interval_cases:
   499 lemma content_closed_interval_cases:
   559   "content {a..b::'a::ordered_euclidean_space} =
   500   "content {a..b::'a::ordered_euclidean_space} =
   560     (if \<forall>i<DIM('a). a$$i \<le> b$$i then setprod (\<lambda>i. b$$i - a$$i) {..<DIM('a)} else 0)"
   501     (if \<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i then setprod (\<lambda>i. b\<bullet>i - a\<bullet>i) Basis else 0)"
   561   apply (rule cond_cases) 
   502   by (auto simp: not_le content_eq_0 intro: less_imp_le content_closed_interval)
   562   apply (rule content_closed_interval)
       
   563   unfolding content_eq_0 not_all not_le
       
   564   defer
       
   565   apply (erule exE,rule_tac x=x in exI)
       
   566   apply auto
       
   567   done
       
   568 
   503 
   569 lemma content_eq_0_interior: "content {a..b} = 0 \<longleftrightarrow> interior({a..b}) = {}"
   504 lemma content_eq_0_interior: "content {a..b} = 0 \<longleftrightarrow> interior({a..b}) = {}"
   570   unfolding content_eq_0 interior_closed_interval interval_eq_empty by auto
   505   unfolding content_eq_0 interior_closed_interval interval_eq_empty by auto
   571 
   506 
   572 (*lemma content_eq_0_1: "content {a..b::real^1} = 0 \<longleftrightarrow> dest_vec1 b \<le> dest_vec1 a"
   507 lemma content_pos_lt_eq: "0 < content {a..b::'a::ordered_euclidean_space} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i)"
   573   unfolding content_eq_0 by auto*)
       
   574 
       
   575 lemma content_pos_lt_eq: "0 < content {a..b::'a::ordered_euclidean_space} \<longleftrightarrow> (\<forall>i<DIM('a). a$$i < b$$i)"
       
   576   apply rule
   508   apply rule
   577   defer
   509   defer
   578   apply (rule content_pos_lt, assumption)
   510   apply (rule content_pos_lt, assumption)
   579 proof -
   511 proof -
   580   assume "0 < content {a..b}"
   512   assume "0 < content {a..b}"
   581   hence "content {a..b} \<noteq> 0" by auto
   513   hence "content {a..b} \<noteq> 0" by auto
   582   thus "\<forall>i<DIM('a). a$$i < b$$i"
   514   thus "\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i"
   583     unfolding content_eq_0 not_ex not_le by fastforce
   515     unfolding content_eq_0 not_ex not_le by fastforce
   584 qed
   516 qed
   585 
   517 
   586 lemma content_empty [simp]: "content {} = 0" unfolding content_def by auto
   518 lemma content_empty [simp]: "content {} = 0" unfolding content_def by auto
   587 
   519 
   591 proof (cases "{a..b} = {}")
   523 proof (cases "{a..b} = {}")
   592   case True
   524   case True
   593   thus ?thesis using content_pos_le[of c d] by auto
   525   thus ?thesis using content_pos_le[of c d] by auto
   594 next
   526 next
   595   case False
   527   case False
   596   hence ab_ne:"\<forall>i<DIM('a). a $$ i \<le> b $$ i" unfolding interval_ne_empty by auto
   528   hence ab_ne:"\<forall>i\<in>Basis. a \<bullet> i \<le> b \<bullet> i" unfolding interval_ne_empty by auto
   597   hence ab_ab:"a\<in>{a..b}" "b\<in>{a..b}" unfolding mem_interval by auto
   529   hence ab_ab:"a\<in>{a..b}" "b\<in>{a..b}" unfolding mem_interval by auto
   598   have "{c..d} \<noteq> {}" using assms False by auto
   530   have "{c..d} \<noteq> {}" using assms False by auto
   599   hence cd_ne:"\<forall>i<DIM('a). c $$ i \<le> d $$ i" using assms unfolding interval_ne_empty by auto
   531   hence cd_ne:"\<forall>i\<in>Basis. c \<bullet> i \<le> d \<bullet> i" using assms unfolding interval_ne_empty by auto
   600   show ?thesis
   532   show ?thesis
   601     unfolding content_def
   533     unfolding content_def
   602     unfolding interval_bounds[OF ab_ne] interval_bounds[OF cd_ne]
   534     unfolding interval_bounds[OF ab_ne] interval_bounds[OF cd_ne]
   603     unfolding if_not_P[OF False] if_not_P[OF `{c..d} \<noteq> {}`]
   535     unfolding if_not_P[OF False] if_not_P[OF `{c..d} \<noteq> {}`]
   604     apply(rule setprod_mono,rule)
   536     apply(rule setprod_mono,rule)
   605   proof
   537   proof
   606     fix i
   538     fix i :: 'a
   607     assume i:"i\<in>{..<DIM('a)}"
   539     assume i:"i\<in>Basis"
   608     show "0 \<le> b $$ i - a $$ i" using ab_ne[THEN spec[where x=i]] i by auto
   540     show "0 \<le> b \<bullet> i - a \<bullet> i" using ab_ne[THEN bspec, OF i] i by auto
   609     show "b $$ i - a $$ i \<le> d $$ i - c $$ i"
   541     show "b \<bullet> i - a \<bullet> i \<le> d \<bullet> i - c \<bullet> i"
   610       using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(2),of i]
   542       using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(2),of i]
   611       using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(1),of i]
   543       using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(1),of i]
   612       using i by auto
   544       using i by auto
   613   qed
   545   qed
   614 qed
   546 qed
   855   show ?g using d1(5)[OF _ _ as(3)] and d2(5)[OF _ _ as(3)] by auto }
   787   show ?g using d1(5)[OF _ _ as(3)] and d2(5)[OF _ _ as(3)] by auto }
   856   fix k assume k:"k \<in> p1 \<union> p2"  show "k \<subseteq> s1 \<union> s2" using k d1(2) d2(2) by auto
   788   fix k assume k:"k \<in> p1 \<union> p2"  show "k \<subseteq> s1 \<union> s2" using k d1(2) d2(2) by auto
   857   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
   789   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
   858 
   790 
   859 lemma partial_division_extend_1:
   791 lemma partial_division_extend_1:
   860   assumes "{c..d} \<subseteq> {a..b::'a::ordered_euclidean_space}" "{c..d} \<noteq> {}"
   792   assumes incl: "{c..d} \<subseteq> {a..b::'a::ordered_euclidean_space}" and nonempty: "{c..d} \<noteq> {}"
   861   obtains p where "p division_of {a..b}" "{c..d} \<in> p"
   793   obtains p where "p division_of {a..b}" "{c..d} \<in> p"
   862 proof- def n \<equiv> "DIM('a)" have n:"1 \<le> n" "0 < n" "n \<noteq> 0" unfolding n_def using DIM_positive[where 'a='a] by auto
   794 proof
   863   guess \<pi> using ex_bij_betw_nat_finite_1[OF finite_lessThan[of "DIM('a)"]] .. note \<pi>=this
   795   let ?B = "\<lambda>f::'a\<Rightarrow>'a \<times> 'a. {(\<Sum>i\<in>Basis. (fst (f i) \<bullet> i) *\<^sub>R i) .. (\<Sum>i\<in>Basis. (snd (f i) \<bullet> i) *\<^sub>R i)}"
   864   def \<pi>' \<equiv> "inv_into {1..n} \<pi>"
   796   def p \<equiv> "?B ` (Basis \<rightarrow>\<^isub>E {(a, c), (c, d), (d, b)})"
   865   have \<pi>':"bij_betw \<pi>' {..<DIM('a)} {1..n}" using bij_betw_inv_into[OF \<pi>] unfolding \<pi>'_def n_def by auto
   797 
   866   hence \<pi>'_i:"\<And>i. i<DIM('a) \<Longrightarrow> \<pi>' i \<in> {1..n}" unfolding bij_betw_def by auto 
   798   show "{c .. d} \<in> p"
   867   have \<pi>_i:"\<And>i. i\<in>{1..n} \<Longrightarrow> \<pi> i <DIM('a)" using \<pi> unfolding bij_betw_def n_def by auto 
   799     unfolding p_def
   868   have \<pi>_\<pi>'[simp]:"\<And>i. i<DIM('a) \<Longrightarrow> \<pi> (\<pi>' i) = i" unfolding \<pi>'_def
   800     by (auto simp add: interval_eq_empty eucl_le[where 'a='a]
   869     apply(rule f_inv_into_f) unfolding n_def using \<pi> unfolding bij_betw_def by auto
   801              intro!: image_eqI[where x="\<lambda>(i::'a)\<in>Basis. (c, d)"])
   870   have \<pi>'_\<pi>[simp]:"\<And>i. i\<in>{1..n} \<Longrightarrow> \<pi>' (\<pi> i) = i" unfolding \<pi>'_def apply(rule inv_into_f_eq)
   802 
   871     using \<pi> unfolding n_def bij_betw_def by auto
   803   {  fix i :: 'a assume "i \<in> Basis"
   872   have "{c..d} \<noteq> {}" using assms by auto
   804     with incl nonempty have "a \<bullet> i \<le> c \<bullet> i" "c \<bullet> i \<le> d \<bullet> i" "d \<bullet> i \<le> b \<bullet> i"
   873   let ?p1 = "\<lambda>l. {(\<chi>\<chi> i. if \<pi>' i < l then c$$i else a$$i)::'a .. (\<chi>\<chi> i. if \<pi>' i < l then d$$i else if \<pi>' i = l then c$$\<pi> l else b$$i)}"
   805       unfolding interval_eq_empty subset_interval by (auto simp: not_le) }
   874   let ?p2 = "\<lambda>l. {(\<chi>\<chi> i. if \<pi>' i < l then c$$i else if \<pi>' i = l then d$$\<pi> l else a$$i)::'a .. (\<chi>\<chi> i. if \<pi>' i < l then d$$i else b$$i)}"
   806   note ord = this
   875   let ?p =  "{?p1 l |l. l \<in> {1..n+1}} \<union> {?p2 l |l. l \<in> {1..n+1}}"
   807 
   876   have abcd:"\<And>i. i<DIM('a) \<Longrightarrow> a $$ i \<le> c $$ i \<and> c$$i \<le> d$$i \<and> d $$ i \<le> b $$ i" using assms
   808   show "p division_of {a..b}"
   877     unfolding subset_interval interval_eq_empty by auto
   809   proof (rule division_ofI)
   878   show ?thesis apply(rule that[of ?p]) apply(rule division_ofI)
   810     show "finite p"
   879   proof- have "\<And>i. i<DIM('a) \<Longrightarrow> \<pi>' i < Suc n"
   811       unfolding p_def by (auto intro!: finite_PiE)
   880     proof(rule ccontr,unfold not_less) fix i assume i:"i<DIM('a)" and "Suc n \<le> \<pi>' i"
   812     { fix k assume "k \<in> p"
   881       hence "\<pi>' i \<notin> {1..n}" by auto thus False using \<pi>' i unfolding bij_betw_def by auto
   813       then obtain f where f: "f \<in> Basis \<rightarrow>\<^isub>E {(a, c), (c, d), (d, b)}" and k: "k = ?B f"
   882     qed hence "c = (\<chi>\<chi> i. if \<pi>' i < Suc n then c $$ i else a $$ i)"
   814         by (auto simp: p_def)
   883         "d = (\<chi>\<chi> i. if \<pi>' i < Suc n then d $$ i else if \<pi>' i = n + 1 then c $$ \<pi> (n + 1) else b $$ i)"
   815       then show "\<exists>a b. k = {a..b}" by auto
   884       unfolding euclidean_eq[where 'a='a] using \<pi>' unfolding bij_betw_def by auto
   816       have "k \<subseteq> {a..b} \<and> k \<noteq> {}"
   885     thus cdp:"{c..d} \<in> ?p" apply-apply(rule UnI1) unfolding mem_Collect_eq apply(rule_tac x="n + 1" in exI) by auto
   817       proof (simp add: k interval_eq_empty subset_interval not_less, safe)
   886     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}"
   818         fix i :: 'a assume i: "i \<in> Basis"
   887       unfolding subset_eq apply(rule_tac[!] ballI,rule_tac[!] ccontr)
   819         moreover with f have "f i = (a, c) \<or> f i = (c, d) \<or> f i = (d, b)"
   888     proof- fix l assume l:"l\<in>{1..n+1}" fix x assume "x\<notin>{a..b}"
   820           by (auto simp: PiE_iff)
   889       then guess i unfolding mem_interval not_all not_imp .. note i=conjunctD2[OF this]
   821         moreover note ord[of i]
   890       show "x \<in> ?p1 l \<Longrightarrow> False" "x \<in> ?p2 l \<Longrightarrow> False" unfolding mem_interval apply(erule_tac[!] x=i in allE)
   822         ultimately show "a \<bullet> i \<le> fst (f i) \<bullet> i" "snd (f i) \<bullet> i \<le> b \<bullet> i" "fst (f i) \<bullet> i \<le> snd (f i) \<bullet> i"
   891         apply(case_tac[!] "\<pi>' i < l", case_tac[!] "\<pi>' i = l") using abcd[of i] i by auto 
   823           by (auto simp: subset_iff eucl_le[where 'a='a])
   892     qed moreover have "\<And>x. x \<in> {a..b} \<Longrightarrow> x \<in> \<Union>?p"
   824       qed
   893     proof- fix x assume x:"x\<in>{a..b}"
   825       then show "k \<noteq> {}" "k \<subseteq> {a .. b}" by auto
   894       { presume "x\<notin>{c..d} \<Longrightarrow> x \<in> \<Union>?p" thus "x \<in> \<Union>?p" using cdp by blast }
   826       { 
   895       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)}"
   827       fix l assume "l \<in> p"
   896       assume "x\<notin>{c..d}" then guess i0 unfolding mem_interval not_all not_imp ..
   828       then obtain g where g: "g \<in> Basis \<rightarrow>\<^isub>E {(a, c), (c, d), (d, b)}" and l: "l = ?B g"
   897       hence "\<pi>' i0 \<in> ?M" using \<pi>' unfolding bij_betw_def by(auto intro!:le_SucI)
   829         by (auto simp: p_def)
   898       hence M:"finite ?M" "?M \<noteq> {}" by auto
   830       assume "l \<noteq> k"
   899       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]]
   831       have "\<exists>i\<in>Basis. f i \<noteq> g i"
   900         Min_gr_iff[OF M,unfolded l_def[symmetric]]
   832       proof (rule ccontr)
   901       have "x\<in>?p1 l \<or> x\<in>?p2 l" using l(2)[THEN conjunct2] unfolding de_Morgan_conj not_le
   833         assume "\<not> (\<exists>i\<in>Basis. f i \<noteq> g i)"
   902         apply- apply(erule disjE) apply(rule disjI1) defer apply(rule disjI2)
   834         with f g have "f = g"
   903       proof- assume as:"x $$ \<pi> l < c $$ \<pi> l"
   835           by (auto simp: PiE_iff extensional_def intro!: ext)
   904         show "x \<in> ?p1 l" unfolding mem_interval apply safe unfolding euclidean_lambda_beta'
   836         with `l \<noteq> k` show False
   905         proof- case goal1 have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le using goal1 by auto
   837           by (simp add: l k)
   906           thus ?case using as x[unfolded mem_interval,rule_format,of i]
   838       qed
   907             apply auto using l(3)[of "\<pi>' i"] using goal1 by(auto elim!:ballE[where x="\<pi>' i"])
   839       then guess i ..
   908         next case goal2 have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le using goal2 by auto
   840       moreover then have "f i = (a, c) \<or> f i = (c, d) \<or> f i = (d, b)"
   909           thus ?case using as x[unfolded mem_interval,rule_format,of i]
   841           "g i = (a, c) \<or> g i = (c, d) \<or> g i = (d, b)"
   910             apply auto using l(3)[of "\<pi>' i"] using goal2 by(auto elim!:ballE[where x="\<pi>' i"])
   842         using f g by (auto simp: PiE_iff)
   911         qed
   843       moreover note ord[of i]
   912       next assume as:"x $$ \<pi> l > d $$ \<pi> l"
   844       ultimately show "interior l \<inter> interior k = {}"
   913         show "x \<in> ?p2 l" unfolding mem_interval apply safe unfolding euclidean_lambda_beta'
   845         by (auto simp add: l k interior_closed_interval disjoint_interval intro!: bexI[of _ i]) }
   914         proof- fix i assume i:"i<DIM('a)"
   846       note `k \<subseteq> { a.. b}` }
   915           have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le using i by auto
   847     moreover
   916           thus "(if \<pi>' i < l then c $$ i else if \<pi>' i = l then d $$ \<pi> l else a $$ i) \<le> x $$ i"
   848     { fix x assume x: "x \<in> {a .. b}"
   917             "x $$ i \<le> (if \<pi>' i < l then d $$ i else b $$ i)"
   849       have "\<forall>i\<in>Basis. \<exists>l. x \<bullet> i \<in> {fst l \<bullet> i .. snd l \<bullet> i} \<and> l \<in> {(a, c), (c, d), (d, b)}"
   918             using as x[unfolded mem_interval,rule_format,of i]
   850       proof
   919             apply auto using l(3)[of "\<pi>' i"] i by(auto elim!:ballE[where x="\<pi>' i"])
   851         fix i :: 'a assume "i \<in> Basis"
   920         qed qed
   852         with x ord[of i] 
   921       thus "x \<in> \<Union>?p" using l(2) by blast 
   853         have "(a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> c \<bullet> i) \<or> (c \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> d \<bullet> i) \<or>
   922     qed ultimately show "\<Union>?p = {a..b}" apply-apply(rule) defer apply(rule) by(assumption,blast)
   854             (d \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i)"
   923     
   855           by (auto simp: eucl_le[where 'a='a])
   924     show "finite ?p" by auto
   856         then show "\<exists>l. x \<bullet> i \<in> {fst l \<bullet> i .. snd l \<bullet> i} \<and> l \<in> {(a, c), (c, d), (d, b)}"
   925     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
   857           by auto
   926     show "k\<subseteq>{a..b}" apply(rule,unfold mem_interval,rule,rule) 
   858       qed
   927     proof fix i x assume i:"i<DIM('a)" assume "x \<in> k" moreover have "\<pi>' i < l \<or> \<pi>' i = l \<or> \<pi>' i > l" by auto
   859       then guess f unfolding bchoice_iff .. note f = this
   928       ultimately show "a$$i \<le> x$$i" "x$$i \<le> b$$i" using abcd[of i] using l using i
   860       moreover then have "restrict f Basis \<in> Basis \<rightarrow>\<^isub>E {(a, c), (c, d), (d, b)}"
   929         by(auto elim!:allE[where x=i] simp add:eucl_le[where 'a='a]) (* FIXME: SLOW *)
   861         by auto
   930     qed have "\<And>l. ?p1 l \<noteq> {}" "\<And>l. ?p2 l \<noteq> {}" unfolding interval_eq_empty not_ex apply(rule_tac[!] allI)
   862       moreover from f have "x \<in> ?B (restrict f Basis)"
   931     proof- case goal1 thus ?case using abcd[of x] by auto
   863         by (auto simp: mem_interval eucl_le[where 'a='a])
   932     next   case goal2 thus ?case using abcd[of x] by auto
   864       ultimately have "\<exists>k\<in>p. x \<in> k"
   933     qed thus "k \<noteq> {}" using k by auto
   865         unfolding p_def by blast }
   934     show "\<exists>a b. k = {a..b}" using k by auto
   866     ultimately show "\<Union>p = {a..b}"
   935     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
   867       by auto
   936     { fix k k' l l'
   868   qed
   937       assume k:"k\<in>?p" and l:"k = ?p1 l \<or> k = ?p2 l" "l \<in> {1..n + 1}" 
   869 qed
   938       assume k':"k' \<in> ?p" "k \<noteq> k'" and  l':"k' = ?p1 l' \<or> k' = ?p2 l'" "l' \<in> {1..n + 1}" 
       
   939       assume "l \<le> l'" fix x
       
   940       have "x \<notin> interior k \<inter> interior k'" 
       
   941       proof(rule,cases "l' = n+1") assume x:"x \<in> interior k \<inter> interior k'"
       
   942         case True hence "\<And>i. i<DIM('a) \<Longrightarrow> \<pi>' i < l'" using \<pi>'_i using l' by(auto simp add:less_Suc_eq_le)
       
   943         hence *:"\<And> P Q. (\<chi>\<chi> i. if \<pi>' i < l' then P i else Q i) = ((\<chi>\<chi> i. P i)::'a)" apply-apply(subst euclidean_eq) by auto
       
   944         hence k':"k' = {c..d}" using l'(1) unfolding * by auto
       
   945         have ln:"l < n + 1" 
       
   946         proof(rule ccontr) case goal1 hence l2:"l = n+1" using l by auto
       
   947           hence "\<And>i. i<DIM('a) \<Longrightarrow> \<pi>' i < l" using \<pi>'_i by(auto simp add:less_Suc_eq_le)
       
   948           hence *:"\<And> P Q. (\<chi>\<chi> i. if \<pi>' i < l then P i else Q i) = ((\<chi>\<chi> i. P i)::'a)" apply-apply(subst euclidean_eq) by auto
       
   949           hence "k = {c..d}" using l(1) \<pi>'_i unfolding * by(auto)
       
   950           thus False using `k\<noteq>k'` k' by auto
       
   951         qed have **:"\<pi>' (\<pi> l) = l" using \<pi>'_\<pi>[of l] using l ln by auto
       
   952         have "x $$ \<pi> l < c $$ \<pi> l \<or> d $$ \<pi> l < x $$ \<pi> l" using l(1) apply-
       
   953         proof(erule disjE)
       
   954           assume as:"k = ?p1 l" note * = conjunct1[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
       
   955           show ?thesis using *[of "\<pi> l"] using ln l(2) using \<pi>_i[of l] by(auto simp add:** not_less)
       
   956         next assume as:"k = ?p2 l" note * = conjunct1[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
       
   957           show ?thesis using *[of "\<pi> l"] using ln l(2) using \<pi>_i[of l] unfolding ** by auto
       
   958         qed thus False using x unfolding k' unfolding Int_iff interior_closed_interval mem_interval
       
   959           by(auto elim!:allE[where x="\<pi> l"])
       
   960       next case False hence "l < n + 1" using l'(2) using `l\<le>l'` by auto
       
   961         hence ln:"l \<in> {1..n}" "l' \<in> {1..n}" using l l' False by auto
       
   962         note \<pi>_l = \<pi>'_\<pi>[OF ln(1)] \<pi>'_\<pi>[OF ln(2)]
       
   963         assume x:"x \<in> interior k \<inter> interior k'"
       
   964         show False using l(1) l'(1) apply-
       
   965         proof(erule_tac[!] disjE)+
       
   966           assume as:"k = ?p1 l" "k' = ?p1 l'"
       
   967           note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
       
   968           have "l \<noteq> l'" using k'(2)[unfolded as] by auto
       
   969           thus False using *[of "\<pi> l'"] *[of "\<pi> l"] ln using \<pi>_i[OF ln(1)] \<pi>_i[OF ln(2)] apply(cases "l<l'")
       
   970             by(auto simp add:euclidean_lambda_beta' \<pi>_l \<pi>_i n_def)
       
   971         next assume as:"k = ?p2 l" "k' = ?p2 l'"
       
   972           note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
       
   973           have "l \<noteq> l'" apply(rule) using k'(2)[unfolded as] by auto
       
   974           thus False using *[of "\<pi> l"] *[of "\<pi> l'"]  `l \<le> l'` ln by(auto simp add:euclidean_lambda_beta' \<pi>_l \<pi>_i n_def)
       
   975         next assume as:"k = ?p1 l" "k' = ?p2 l'"
       
   976           note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
       
   977           show False using abcd[of "\<pi> l'"] using *[of "\<pi> l"] *[of "\<pi> l'"]  `l \<le> l'` ln apply(cases "l=l'")
       
   978             by(auto simp add:euclidean_lambda_beta' \<pi>_l \<pi>_i n_def)
       
   979         next assume as:"k = ?p2 l" "k' = ?p1 l'"
       
   980           note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
       
   981           show False using *[of "\<pi> l"] *[of "\<pi> l'"] ln `l \<le> l'` apply(cases "l=l'") using abcd[of "\<pi> l'"] 
       
   982             by(auto simp add:euclidean_lambda_beta' \<pi>_l \<pi>_i n_def)
       
   983         qed qed } 
       
   984     from this[OF k l k' l'] this[OF k'(1) l' k _ l] have "\<And>x. x \<notin> interior k \<inter> interior k'"
       
   985       apply - apply(cases "l' \<le> l") using k'(2) by auto            
       
   986     thus "interior k \<inter> interior k' = {}" by auto        
       
   987 qed qed
       
   988 
   870 
   989 lemma partial_division_extend_interval: assumes "p division_of (\<Union>p)" "(\<Union>p) \<subseteq> {a..b}"
   871 lemma partial_division_extend_interval: assumes "p division_of (\<Union>p)" "(\<Union>p) \<subseteq> {a..b}"
   990   obtains q where "p \<subseteq> q" "q division_of {a..b::'a::ordered_euclidean_space}" proof(cases "p = {}")
   872   obtains q where "p \<subseteq> q" "q division_of {a..b::'a::ordered_euclidean_space}" proof(cases "p = {}")
   991   case True guess q apply(rule elementary_interval[of a b]) .
   873   case True guess q apply(rule elementary_interval[of a b]) .
   992   thus ?thesis apply- apply(rule that[of q]) unfolding True by auto next
   874   thus ?thesis apply- apply(rule that[of q]) unfolding True by auto next
  1413 subsection {* General bisection principle for intervals; might be useful elsewhere. *}
  1295 subsection {* General bisection principle for intervals; might be useful elsewhere. *}
  1414 
  1296 
  1415 lemma interval_bisection_step:  fixes type::"'a::ordered_euclidean_space"
  1297 lemma interval_bisection_step:  fixes type::"'a::ordered_euclidean_space"
  1416   assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "~(P {a..b::'a})"
  1298   assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "~(P {a..b::'a})"
  1417   obtains c d where "~(P{c..d})"
  1299   obtains c d where "~(P{c..d})"
  1418   "\<forall>i<DIM('a). 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"
  1300   "\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> c\<bullet>i \<le> d\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i \<and> 2 * (d\<bullet>i - c\<bullet>i) \<le> b\<bullet>i - a\<bullet>i"
  1419 proof- have "{a..b} \<noteq> {}" using assms(1,3) by auto
  1301 proof- have "{a..b} \<noteq> {}" using assms(1,3) by auto
  1420   note ab=this[unfolded interval_eq_empty not_ex not_less]
  1302   then have ab: "\<And>i. i\<in>Basis \<Longrightarrow> a \<bullet> i \<le> b \<bullet> i" by (auto simp: interval_eq_empty not_le)
  1421   { fix f have "finite f \<Longrightarrow>
  1303   { fix f have "finite f \<Longrightarrow>
  1422         (\<forall>s\<in>f. P s) \<Longrightarrow>
  1304         (\<forall>s\<in>f. P s) \<Longrightarrow>
  1423         (\<forall>s\<in>f. \<exists>a b. s = {a..b}) \<Longrightarrow>
  1305         (\<forall>s\<in>f. \<exists>a b. s = {a..b}) \<Longrightarrow>
  1424         (\<forall>s\<in>f.\<forall>t\<in>f. ~(s = t) \<longrightarrow> interior(s) \<inter> interior(t) = {}) \<Longrightarrow> P(\<Union>f)"
  1306         (\<forall>s\<in>f.\<forall>t\<in>f. ~(s = t) \<longrightarrow> interior(s) \<inter> interior(t) = {}) \<Longrightarrow> P(\<Union>f)"
  1425     proof(induct f rule:finite_induct)
  1307     proof(induct f rule:finite_induct)
  1426       case empty show ?case using assms(1) by auto
  1308       case empty show ?case using assms(1) by auto
  1427     next case (insert x f) show ?case unfolding Union_insert apply(rule assms(2)[rule_format])
  1309     next case (insert x f) show ?case unfolding Union_insert apply(rule assms(2)[rule_format])
  1428         apply rule defer apply rule defer apply(rule inter_interior_unions_intervals)
  1310         apply rule defer apply rule defer apply(rule inter_interior_unions_intervals)
  1429         using insert by auto
  1311         using insert by auto
  1430     qed } note * = this
  1312     qed } note * = this
  1431   let ?A = "{{c..d} | c d::'a. \<forall>i<DIM('a). (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)}"
  1313   let ?A = "{{c..d} | c d::'a. \<forall>i\<in>Basis. (c\<bullet>i = a\<bullet>i) \<and> (d\<bullet>i = (a\<bullet>i + b\<bullet>i) / 2) \<or> (c\<bullet>i = (a\<bullet>i + b\<bullet>i) / 2) \<and> (d\<bullet>i = b\<bullet>i)}"
  1432   let ?PP = "\<lambda>c d. \<forall>i<DIM('a). 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"
  1314   let ?PP = "\<lambda>c d. \<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> c\<bullet>i \<le> d\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i \<and> 2 * (d\<bullet>i - c\<bullet>i) \<le> b\<bullet>i - a\<bullet>i"
  1433   { presume "\<forall>c d. ?PP c d \<longrightarrow> P {c..d} \<Longrightarrow> False"
  1315   { presume "\<forall>c d. ?PP c d \<longrightarrow> P {c..d} \<Longrightarrow> False"
  1434     thus thesis unfolding atomize_not not_all apply-apply(erule exE)+ apply(rule_tac c=x and d=xa in that) by auto }
  1316     thus thesis unfolding atomize_not not_all apply-apply(erule exE)+ apply(rule_tac c=x and d=xa in that) by auto }
  1435   assume as:"\<forall>c d. ?PP c d \<longrightarrow> P {c..d}"
  1317   assume as:"\<forall>c d. ?PP c d \<longrightarrow> P {c..d}"
  1436   have "P (\<Union> ?A)" proof(rule *, rule_tac[2-] ballI, rule_tac[4] ballI, rule_tac[4] impI) 
  1318   have "P (\<Union> ?A)" proof(rule *, rule_tac[2-] ballI, rule_tac[4] ballI, rule_tac[4] impI) 
  1437     let ?B = "(\<lambda>s.{(\<chi>\<chi> i. if i \<in> s then a$$i else (a$$i + b$$i) / 2)::'a ..
  1319     let ?B = "(\<lambda>s.{(\<Sum>i\<in>Basis. (if i \<in> s then a\<bullet>i else (a\<bullet>i + b\<bullet>i) / 2) *\<^sub>R i)::'a ..
  1438       (\<chi>\<chi> i. if i \<in> s then (a$$i + b$$i) / 2 else b$$i)}) ` {s. s \<subseteq> {..<DIM('a)}}"
  1320       (\<Sum>i\<in>Basis. (if i \<in> s then (a\<bullet>i + b\<bullet>i) / 2 else b\<bullet>i) *\<^sub>R i)}) ` {s. s \<subseteq> Basis}"
  1439     have "?A \<subseteq> ?B" proof case goal1
  1321     have "?A \<subseteq> ?B" proof case goal1
  1440       then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+) note c_d=this[rule_format]
  1322       then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+) note c_d=this[rule_format]
  1441       have *:"\<And>a b c d. a = c \<Longrightarrow> b = d \<Longrightarrow> {a..b} = {c..d}" by auto
  1323       have *:"\<And>a b c d. a = c \<Longrightarrow> b = d \<Longrightarrow> {a..b} = {c..d}" by auto
  1442       show "x\<in>?B" unfolding image_iff apply(rule_tac x="{i. i<DIM('a) \<and> c$$i = a$$i}" in bexI)
  1324       show "x\<in>?B" unfolding image_iff
  1443         unfolding c_d apply(rule * ) unfolding euclidean_eq[where 'a='a] apply safe unfolding euclidean_lambda_beta' mem_Collect_eq
  1325         apply(rule_tac x="{i. i\<in>Basis \<and> c\<bullet>i = a\<bullet>i}" in bexI)
  1444       proof- fix i assume "i<DIM('a)" thus " c $$ i = (if i < DIM('a) \<and> c $$ i = a $$ i then a $$ i else (a $$ i + b $$ i) / 2)"
  1326         unfolding c_d
  1445           "d $$ i = (if i < DIM('a) \<and> c $$ i = a $$ i then (a $$ i + b $$ i) / 2 else b $$ i)"
  1327         apply(rule *)
  1446           using c_d(2)[of i] ab[THEN spec[where x=i]] by(auto simp add:field_simps)
  1328         apply (simp_all only: euclidean_eq_iff[where 'a='a] inner_setsum_left_Basis mem_Collect_eq simp_thms
       
  1329                         cong: ball_cong)
       
  1330         apply safe
       
  1331       proof-
       
  1332         fix i :: 'a assume i: "i\<in>Basis"
       
  1333         thus " c \<bullet> i = (if c \<bullet> i = a \<bullet> i then a \<bullet> i else (a \<bullet> i + b \<bullet> i) / 2)"
       
  1334           "d \<bullet> i = (if c \<bullet> i = a \<bullet> i then (a \<bullet> i + b \<bullet> i) / 2 else b \<bullet> i)"
       
  1335           using c_d(2)[of i] ab[OF i] by(auto simp add:field_simps)
  1447       qed qed
  1336       qed qed
  1448     thus "finite ?A" apply(rule finite_subset) by auto
  1337     thus "finite ?A" apply(rule finite_subset) by auto
  1449     fix s assume "s\<in>?A" then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+)
  1338     fix s assume "s\<in>?A" then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+)
  1450     note c_d=this[rule_format]
  1339     note c_d=this[rule_format]
  1451     show "P s" unfolding c_d apply(rule as[rule_format]) proof- case goal1 thus ?case 
  1340     show "P s" unfolding c_d apply(rule as[rule_format]) proof- case goal1 thus ?case 
  1452         using c_d(2)[of i] using ab[THEN spec[where x=i]] by auto qed
  1341         using c_d(2)[of i] using ab[OF `i \<in> Basis`] by auto qed
  1453     show "\<exists>a b. s = {a..b}" unfolding c_d by auto
  1342     show "\<exists>a b. s = {a..b}" unfolding c_d by auto
  1454     fix t assume "t\<in>?A" then guess e unfolding mem_Collect_eq .. then guess f apply- by(erule exE,(erule conjE)+)
  1343     fix t assume "t\<in>?A" then guess e unfolding mem_Collect_eq .. then guess f apply- by(erule exE,(erule conjE)+)
  1455     note e_f=this[rule_format]
  1344     note e_f=this[rule_format]
  1456     assume "s \<noteq> t" hence "\<not> (c = e \<and> d = f)" unfolding c_d e_f by auto
  1345     assume "s \<noteq> t" hence "\<not> (c = e \<and> d = f)" unfolding c_d e_f by auto
  1457     then obtain i where "c$$i \<noteq> e$$i \<or> d$$i \<noteq> f$$i" and i':"i<DIM('a)" unfolding de_Morgan_conj euclidean_eq[where 'a='a] by auto
  1346     then obtain i where "c\<bullet>i \<noteq> e\<bullet>i \<or> d\<bullet>i \<noteq> f\<bullet>i" and i':"i\<in>Basis"
  1458     hence i:"c$$i \<noteq> e$$i" "d$$i \<noteq> f$$i" apply- apply(erule_tac[!] disjE)
  1347       unfolding euclidean_eq_iff[where 'a='a] by auto
  1459     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 fastforce
  1348     hence i:"c\<bullet>i \<noteq> e\<bullet>i" "d\<bullet>i \<noteq> f\<bullet>i" apply- apply(erule_tac[!] disjE)
  1460     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 fastforce
  1349     proof- assume "c\<bullet>i \<noteq> e\<bullet>i" thus "d\<bullet>i \<noteq> f\<bullet>i" using c_d(2)[OF i'] e_f(2)[OF i'] by fastforce
       
  1350     next   assume "d\<bullet>i \<noteq> f\<bullet>i" thus "c\<bullet>i \<noteq> e\<bullet>i" using c_d(2)[OF i'] e_f(2)[OF i'] by fastforce
  1461     qed have *:"\<And>s t. (\<And>a. a\<in>s \<Longrightarrow> a\<in>t \<Longrightarrow> False) \<Longrightarrow> s \<inter> t = {}" by auto
  1351     qed have *:"\<And>s t. (\<And>a. a\<in>s \<Longrightarrow> a\<in>t \<Longrightarrow> False) \<Longrightarrow> s \<inter> t = {}" by auto
  1462     show "interior s \<inter> interior t = {}" unfolding e_f c_d interior_closed_interval proof(rule *)
  1352     show "interior s \<inter> interior t = {}" unfolding e_f c_d interior_closed_interval proof(rule *)
  1463       fix x assume "x\<in>{c<..<d}" "x\<in>{e<..<f}"
  1353       fix x assume "x\<in>{c<..<d}" "x\<in>{e<..<f}"
  1464       hence x:"c$$i < d$$i" "e$$i < f$$i" "c$$i < f$$i" "e$$i < d$$i" unfolding mem_interval using i'
  1354       hence x:"c\<bullet>i < d\<bullet>i" "e\<bullet>i < f\<bullet>i" "c\<bullet>i < f\<bullet>i" "e\<bullet>i < d\<bullet>i" unfolding mem_interval using i'
  1465         apply-apply(erule_tac[!] x=i in allE)+ by auto
  1355         apply-apply(erule_tac[!] x=i in ballE)+ by auto
  1466       show False using c_d(2)[OF i'] apply- apply(erule_tac disjE)
  1356       show False using c_d(2)[OF i'] apply- apply(erule_tac disjE)
  1467       proof(erule_tac[!] conjE) assume as:"c $$ i = a $$ i" "d $$ i = (a $$ i + b $$ i) / 2"
  1357       proof(erule_tac[!] conjE) assume as:"c \<bullet> i = a \<bullet> i" "d \<bullet> i = (a \<bullet> i + b \<bullet> i) / 2"
  1468         show False using e_f(2)[of i] and i x unfolding as by(fastforce simp add:field_simps)
  1358         show False using e_f(2)[OF i'] and i x unfolding as by(fastforce simp add:field_simps)
  1469       next assume as:"c $$ i = (a $$ i + b $$ i) / 2" "d $$ i = b $$ i"
  1359       next assume as:"c \<bullet> i = (a \<bullet> i + b \<bullet> i) / 2" "d \<bullet> i = b \<bullet> i"
  1470         show False using e_f(2)[of i] and i x unfolding as by(fastforce simp add:field_simps)
  1360         show False using e_f(2)[OF i'] and i x unfolding as by(fastforce simp add:field_simps)
  1471       qed qed qed
  1361       qed qed qed
  1472   also have "\<Union> ?A = {a..b}" proof(rule set_eqI,rule)
  1362   also have "\<Union> ?A = {a..b}" proof(rule set_eqI,rule)
  1473     fix x assume "x\<in>\<Union>?A" then guess Y unfolding Union_iff ..
  1363     fix x assume "x\<in>\<Union>?A" then guess Y unfolding Union_iff ..
  1474     from this(1) guess c unfolding mem_Collect_eq .. then guess d ..
  1364     from this(1) guess c unfolding mem_Collect_eq .. then guess d ..
  1475     note c_d = this[THEN conjunct2,rule_format] `x\<in>Y`[unfolded this[THEN conjunct1]]
  1365     note c_d = this[THEN conjunct2,rule_format] `x\<in>Y`[unfolded this[THEN conjunct1]]
  1476     show "x\<in>{a..b}" unfolding mem_interval proof safe
  1366     show "x\<in>{a..b}" unfolding mem_interval proof safe
  1477       fix i assume "i<DIM('a)" thus "a $$ i \<le> x $$ i" "x $$ i \<le> b $$ i"
  1367       fix i :: 'a assume i: "i\<in>Basis" thus "a \<bullet> i \<le> x \<bullet> i" "x \<bullet> i \<le> b \<bullet> i"
  1478         using c_d(1)[of i] c_d(2)[unfolded mem_interval,THEN spec[where x=i]] by auto qed
  1368         using c_d(1)[OF i] c_d(2)[unfolded mem_interval,THEN bspec, OF i] by auto qed
  1479   next fix x assume x:"x\<in>{a..b}"
  1369   next fix x assume x:"x\<in>{a..b}"
  1480     have "\<forall>i<DIM('a). \<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"
  1370     have "\<forall>i\<in>Basis. \<exists>c d. (c = a\<bullet>i \<and> d = (a\<bullet>i + b\<bullet>i) / 2 \<or> c = (a\<bullet>i + b\<bullet>i) / 2 \<and> d = b\<bullet>i) \<and> c\<le>x\<bullet>i \<and> x\<bullet>i \<le> d"
  1481       (is "\<forall>i<DIM('a). \<exists>c d. ?P i c d") unfolding mem_interval proof(rule,rule) fix i
  1371       (is "\<forall>i\<in>Basis. \<exists>c d. ?P i c d") unfolding mem_interval
  1482       have "?P i (a$$i) ((a $$ i + b $$ i) / 2) \<or> ?P i ((a $$ i + b $$ i) / 2) (b$$i)"
  1372     proof
  1483         using x[unfolded mem_interval,THEN spec[where x=i]] by auto thus "\<exists>c d. ?P i c d" by blast
  1373       fix i :: 'a assume i: "i \<in> Basis"
  1484     qed thus "x\<in>\<Union>?A" unfolding Union_iff unfolding lambda_skolem' unfolding Bex_def mem_Collect_eq
  1374       have "?P i (a\<bullet>i) ((a \<bullet> i + b \<bullet> i) / 2) \<or> ?P i ((a \<bullet> i + b \<bullet> i) / 2) (b\<bullet>i)"
       
  1375         using x[unfolded mem_interval,THEN bspec, OF i] by auto thus "\<exists>c d. ?P i c d" by blast
       
  1376     qed
       
  1377     thus "x\<in>\<Union>?A"
       
  1378       unfolding Union_iff Bex_def mem_Collect_eq choice_Basis_iff
  1485       apply-apply(erule exE)+ apply(rule_tac x="{xa..xaa}" in exI) unfolding mem_interval by auto
  1379       apply-apply(erule exE)+ apply(rule_tac x="{xa..xaa}" in exI) unfolding mem_interval by auto
  1486   qed finally show False using assms by auto qed
  1380   qed finally show False using assms by auto qed
  1487 
  1381 
  1488 lemma interval_bisection: fixes type::"'a::ordered_euclidean_space"
  1382 lemma interval_bisection: fixes type::"'a::ordered_euclidean_space"
  1489   assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "\<not> P {a..b::'a}"
  1383   assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "\<not> P {a..b::'a}"
  1490   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})"
  1384   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})"
  1491 proof-
  1385 proof-
  1492   have "\<forall>x. \<exists>y. \<not> P {fst x..snd x} \<longrightarrow> (\<not> P {fst y..snd y} \<and>
  1386   have "\<forall>x. \<exists>y. \<not> P {fst x..snd x} \<longrightarrow> (\<not> P {fst y..snd y} \<and>
  1493     (\<forall>i<DIM('a). fst x$$i \<le> fst y$$i \<and> fst y$$i \<le> snd y$$i \<and> snd y$$i \<le> snd x$$i \<and>
  1387     (\<forall>i\<in>Basis. fst x\<bullet>i \<le> fst y\<bullet>i \<and> fst y\<bullet>i \<le> snd y\<bullet>i \<and> snd y\<bullet>i \<le> snd x\<bullet>i \<and>
  1494                            2 * (snd y$$i - fst y$$i) \<le> snd x$$i - fst x$$i))" proof case goal1 thus ?case proof-
  1388                            2 * (snd y\<bullet>i - fst y\<bullet>i) \<le> snd x\<bullet>i - fst x\<bullet>i))" proof case goal1 thus ?case proof-
  1495       presume "\<not> P {fst x..snd x} \<Longrightarrow> ?thesis"
  1389       presume "\<not> P {fst x..snd x} \<Longrightarrow> ?thesis"
  1496       thus ?thesis apply(cases "P {fst x..snd x}") by auto
  1390       thus ?thesis apply(cases "P {fst x..snd x}") by auto
  1497     next assume as:"\<not> P {fst x..snd x}" from interval_bisection_step[of P, OF assms(1-2) as] guess c d . 
  1391     next assume as:"\<not> P {fst x..snd x}" from interval_bisection_step[of P, OF assms(1-2) as] guess c d . 
  1498       thus ?thesis apply- apply(rule_tac x="(c,d)" in exI) by auto
  1392       thus ?thesis apply- apply(rule_tac x="(c,d)" in exI) by auto
  1499     qed qed then guess f apply-apply(drule choice) by(erule exE) note f=this
  1393     qed qed then guess f apply-apply(drule choice) by(erule exE) note f=this
  1500   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
  1394   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
  1501   have "A 0 = a" "B 0 = b" "\<And>n. \<not> P {A(Suc n)..B(Suc n)} \<and>
  1395   have "A 0 = a" "B 0 = b" "\<And>n. \<not> P {A(Suc n)..B(Suc n)} \<and>
  1502     (\<forall>i<DIM('a). 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> 
  1396     (\<forall>i\<in>Basis. A(n)\<bullet>i \<le> A(Suc n)\<bullet>i \<and> A(Suc n)\<bullet>i \<le> B(Suc n)\<bullet>i \<and> B(Suc n)\<bullet>i \<le> B(n)\<bullet>i \<and> 
  1503     2 * (B(Suc n)$$i - A(Suc n)$$i) \<le> B(n)$$i - A(n)$$i)" (is "\<And>n. ?P n")
  1397     2 * (B(Suc n)\<bullet>i - A(Suc n)\<bullet>i) \<le> B(n)\<bullet>i - A(n)\<bullet>i)" (is "\<And>n. ?P n")
  1504   proof- show "A 0 = a" "B 0 = b" unfolding ab_def by auto
  1398   proof- show "A 0 = a" "B 0 = b" unfolding ab_def by auto
  1505     case goal3 note S = ab_def funpow.simps o_def id_apply show ?case
  1399     case goal3 note S = ab_def funpow.simps o_def id_apply show ?case
  1506     proof(induct n) case 0 thus ?case unfolding S apply(rule f[rule_format]) using assms(3) by auto
  1400     proof(induct n) case 0 thus ?case unfolding S apply(rule f[rule_format]) using assms(3) by auto
  1507     next case (Suc n) show ?case unfolding S apply(rule f[rule_format]) using Suc unfolding S by auto
  1401     next case (Suc n) show ?case unfolding S apply(rule f[rule_format]) using Suc unfolding S by auto
  1508     qed qed note AB = this(1-2) conjunctD2[OF this(3),rule_format]
  1402     qed qed note AB = this(1-2) conjunctD2[OF this(3),rule_format]
  1509 
  1403 
  1510   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"
  1404   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"
  1511   proof- case goal1 guess n using real_arch_pow2[of "(setsum (\<lambda>i. b$$i - a$$i) {..<DIM('a)}) / e"] .. note n=this
  1405   proof- case goal1 guess n using real_arch_pow2[of "(setsum (\<lambda>i. b\<bullet>i - a\<bullet>i) Basis) / e"] .. note n=this
  1512     show ?case apply(rule_tac x=n in exI) proof(rule,rule)
  1406     show ?case apply(rule_tac x=n in exI) proof(rule,rule)
  1513       fix x y assume xy:"x\<in>{A n..B n}" "y\<in>{A n..B n}"
  1407       fix x y assume xy:"x\<in>{A n..B n}" "y\<in>{A n..B n}"
  1514       have "dist x y \<le> setsum (\<lambda>i. abs((x - y)$$i)) {..<DIM('a)}" unfolding dist_norm by(rule norm_le_l1)
  1408       have "dist x y \<le> setsum (\<lambda>i. abs((x - y)\<bullet>i)) Basis" unfolding dist_norm by(rule norm_le_l1)
  1515       also have "\<dots> \<le> setsum (\<lambda>i. B n$$i - A n$$i) {..<DIM('a)}"
  1409       also have "\<dots> \<le> setsum (\<lambda>i. B n\<bullet>i - A n\<bullet>i) Basis"
  1516       proof(rule setsum_mono) fix i show "\<bar>(x - y) $$ i\<bar> \<le> B n $$ i - A n $$ i"
  1410       proof(rule setsum_mono)
  1517           using xy[unfolded mem_interval,THEN spec[where x=i]] by auto qed
  1411         fix i :: 'a assume i: "i \<in> Basis" show "\<bar>(x - y) \<bullet> i\<bar> \<le> B n \<bullet> i - A n \<bullet> i"
  1518       also have "\<dots> \<le> setsum (\<lambda>i. b$$i - a$$i) {..<DIM('a)} / 2^n" unfolding setsum_divide_distrib
  1412           using xy[unfolded mem_interval,THEN bspec, OF i] by (auto simp: inner_diff_left) qed
       
  1413       also have "\<dots> \<le> setsum (\<lambda>i. b\<bullet>i - a\<bullet>i) Basis / 2^n" unfolding setsum_divide_distrib
  1519       proof(rule setsum_mono) case goal1 thus ?case
  1414       proof(rule setsum_mono) case goal1 thus ?case
  1520         proof(induct n) case 0 thus ?case unfolding AB by auto
  1415         proof(induct n) case 0 thus ?case unfolding AB by auto
  1521         next case (Suc n) have "B (Suc n) $$ i - A (Suc n) $$ i \<le> (B n $$ i - A n $$ i) / 2"
  1416         next case (Suc n) have "B (Suc n) \<bullet> i - A (Suc n) \<bullet> i \<le> (B n \<bullet> i - A n \<bullet> i) / 2"
  1522             using AB(4)[of i n] using goal1 by auto
  1417             using AB(4)[of i n] using goal1 by auto
  1523           also have "\<dots> \<le> (b $$ i - a $$ i) / 2 ^ Suc n" using Suc by(auto simp add:field_simps) finally show ?case .
  1418           also have "\<dots> \<le> (b \<bullet> i - a \<bullet> i) / 2 ^ Suc n" using Suc by(auto simp add:field_simps) finally show ?case .
  1524         qed qed
  1419         qed qed
  1525       also have "\<dots> < e" using n using goal1 by(auto simp add:field_simps) finally show "dist x y < e" .
  1420       also have "\<dots> < e" using n using goal1 by(auto simp add:field_simps) finally show "dist x y < e" .
  1526     qed qed
  1421     qed qed
  1527   { fix n m ::nat assume "m \<le> n" then guess d unfolding le_Suc_ex_iff .. note d=this
  1422   { fix n m :: nat assume "m \<le> n" then have "{A n..B n} \<subseteq> {A m..B m}"
  1528     have "{A n..B n} \<subseteq> {A m..B m}" unfolding d 
  1423     proof(induct rule: inc_induct)
  1529     proof(induct d) case 0 thus ?case by auto
  1424       case (step i) show ?case
  1530     next case (Suc d) show ?case apply(rule subset_trans[OF _ Suc])
  1425         using AB(4) by (intro order_trans[OF step(2)] subset_interval_imp) auto
  1531         apply(rule) unfolding mem_interval apply(rule,erule_tac x=i in allE)
  1426     qed simp } note ABsubset = this 
  1532       proof- case goal1 thus ?case using AB(4)[of i "m + d"] by(auto simp add:field_simps)
       
  1533       qed qed } note ABsubset = this 
       
  1534   have "\<exists>a. \<forall>n. a\<in>{A n..B n}" apply(rule decreasing_closed_nest[rule_format,OF closed_interval _ ABsubset interv])
  1427   have "\<exists>a. \<forall>n. a\<in>{A n..B n}" apply(rule decreasing_closed_nest[rule_format,OF closed_interval _ ABsubset interv])
  1535   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
  1428   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
  1536   then guess x0 .. note x0=this[rule_format]
  1429   then guess x0 .. note x0=this[rule_format]
  1537   show thesis proof(rule that[rule_format,of x0])
  1430   show thesis proof(rule that[rule_format,of x0])
  1538     show "x0\<in>{a..b}" using x0[of 0] unfolding AB .
  1431     show "x0\<in>{a..b}" using x0[of 0] unfolding AB .
  1782   apply(rule has_integral_unique) defer unfolding has_integral_integral 
  1675   apply(rule has_integral_unique) defer unfolding has_integral_integral 
  1783   apply(drule has_integral_linear,assumption,assumption) unfolding has_integral_integral[THEN sym]
  1676   apply(drule has_integral_linear,assumption,assumption) unfolding has_integral_integral[THEN sym]
  1784   apply(rule integrable_linear) by assumption+
  1677   apply(rule integrable_linear) by assumption+
  1785 
  1678 
  1786 lemma integral_component_eq[simp]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1679 lemma integral_component_eq[simp]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1787   assumes "f integrable_on s" shows "integral s (\<lambda>x. f x $$ k) = integral s f $$ k"
  1680   assumes "f integrable_on s" shows "integral s (\<lambda>x. f x \<bullet> k) = integral s f \<bullet> k"
  1788   unfolding integral_linear[OF assms(1) bounded_linear_component,unfolded o_def] ..
  1681   unfolding integral_linear[OF assms(1) bounded_linear_component,unfolded o_def] ..
  1789 
  1682 
  1790 lemma has_integral_setsum:
  1683 lemma has_integral_setsum:
  1791   assumes "finite t" "\<forall>a\<in>t. ((f a) has_integral (i a)) s"
  1684   assumes "finite t" "\<forall>a\<in>t. ((f a) has_integral (i a)) s"
  1792   shows "((\<lambda>x. setsum (\<lambda>a. f a x) t) has_integral (setsum i t)) s"
  1685   shows "((\<lambda>x. setsum (\<lambda>a. f a x) t) has_integral (setsum i t)) s"
  1850 
  1743 
  1851 lemma integral_empty[simp]: shows "integral {} f = 0"
  1744 lemma integral_empty[simp]: shows "integral {} f = 0"
  1852   apply(rule integral_unique) using has_integral_empty .
  1745   apply(rule integral_unique) using has_integral_empty .
  1853 
  1746 
  1854 lemma has_integral_refl[intro]: shows "(f has_integral 0) {a..a}" "(f has_integral 0) {a::'a::ordered_euclidean_space}"
  1747 lemma has_integral_refl[intro]: shows "(f has_integral 0) {a..a}" "(f has_integral 0) {a::'a::ordered_euclidean_space}"
  1855 proof- have *:"{a} = {a..a}" apply(rule set_eqI) unfolding mem_interval singleton_iff euclidean_eq[where 'a='a]
  1748 proof-
  1856     apply safe prefer 3 apply(erule_tac x=i in allE) by(auto simp add: field_simps)
  1749   have *:"{a} = {a..a}" apply(rule set_eqI) unfolding mem_interval singleton_iff euclidean_eq_iff[where 'a='a]
       
  1750     apply safe prefer 3 apply(erule_tac x=b in ballE) by(auto simp add: field_simps)
  1857   show "(f has_integral 0) {a..a}" "(f has_integral 0) {a}" unfolding *
  1751   show "(f has_integral 0) {a..a}" "(f has_integral 0) {a}" unfolding *
  1858     apply(rule_tac[!] has_integral_null) unfolding content_eq_0_interior
  1752     apply(rule_tac[!] has_integral_null) unfolding content_eq_0_interior
  1859     unfolding interior_closed_interval using interval_sing by auto qed
  1753     unfolding interior_closed_interval using interval_sing by auto qed
  1860 
  1754 
  1861 lemma integrable_on_refl[intro]: shows "f integrable_on {a..a}" unfolding integrable_on_def by auto
  1755 lemma integrable_on_refl[intro]: shows "f integrable_on {a..a}" unfolding integrable_on_def by auto
  1911         using N2[rule_format,of "N1+N2"]
  1805         using N2[rule_format,of "N1+N2"]
  1912         using as dp[of "N1 - 1 + 1 + N2" "N1 + N2"] using p(1)[of "N1 + N2"] using N1 by auto qed qed qed
  1806         using as dp[of "N1 - 1 + 1 + N2" "N1 + N2"] using p(1)[of "N1 + N2"] using N1 by auto qed qed qed
  1913 
  1807 
  1914 subsection {* Additivity of integral on abutting intervals. *}
  1808 subsection {* Additivity of integral on abutting intervals. *}
  1915 
  1809 
  1916 lemma interval_split: fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)" shows
  1810 lemma interval_split:
  1917   "{a..b} \<inter> {x. x$$k \<le> c} = {a .. (\<chi>\<chi> i. if i = k then min (b$$k) c else b$$i)}"
  1811   fixes a::"'a::ordered_euclidean_space" assumes "k \<in> Basis"
  1918   "{a..b} \<inter> {x. x$$k \<ge> c} = {(\<chi>\<chi> i. if i = k then max (a$$k) c else a$$i) .. b}"
  1812   shows
  1919   apply(rule_tac[!] set_eqI) unfolding Int_iff mem_interval mem_Collect_eq using assms by auto
  1813     "{a..b} \<inter> {x. x\<bullet>k \<le> c} = {a .. (\<Sum>i\<in>Basis. (if i = k then min (b\<bullet>k) c else b\<bullet>i) *\<^sub>R i)}"
  1920 
  1814     "{a..b} \<inter> {x. x\<bullet>k \<ge> c} = {(\<Sum>i\<in>Basis. (if i = k then max (a\<bullet>k) c else a\<bullet>i) *\<^sub>R i) .. b}"
  1921 lemma content_split: fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)" shows
  1815   apply(rule_tac[!] set_eqI) unfolding Int_iff mem_interval mem_Collect_eq using assms
  1922   "content {a..b} = content({a..b} \<inter> {x. x$$k \<le> c}) + content({a..b} \<inter> {x. x$$k >= c})"
  1816   by auto
  1923 proof- note simps = interval_split[OF assms] content_closed_interval_cases eucl_le[where 'a='a]
  1817 
  1924   { presume "a\<le>b \<Longrightarrow> ?thesis" thus ?thesis apply(cases "a\<le>b") unfolding simps using assms by auto }
  1818 lemma content_split: fixes a::"'a::ordered_euclidean_space" assumes "k\<in>Basis" shows
  1925   have *:"{..<DIM('a)} = insert k ({..<DIM('a)} - {k})" "\<And>x. finite ({..<DIM('a)}-{x})" "\<And>x. x\<notin>{..<DIM('a)}-{x}"
  1819   "content {a..b} = content({a..b} \<inter> {x. x\<bullet>k \<le> c}) + content({a..b} \<inter> {x. x\<bullet>k >= c})"
       
  1820 proof cases
       
  1821   note simps = interval_split[OF assms] content_closed_interval_cases eucl_le[where 'a='a]
       
  1822   have *:"Basis = insert k (Basis - {k})" "\<And>x. finite (Basis-{x})" "\<And>x. x\<notin>Basis-{x}"
  1926     using assms by auto
  1823     using assms by auto
  1927   have *:"\<And>X Y Z. (\<Prod>i\<in>{..<DIM('a)}. Z i (if i = k then X else Y i)) = Z k X * (\<Prod>i\<in>{..<DIM('a)}-{k}. Z i (Y i))"
  1824   have *:"\<And>X Y Z. (\<Prod>i\<in>Basis. Z i (if i = k then X else Y i)) = Z k X * (\<Prod>i\<in>Basis-{k}. Z i (Y i))"
  1928     "(\<Prod>i\<in>{..<DIM('a)}. b$$i - a$$i) = (\<Prod>i\<in>{..<DIM('a)}-{k}. b$$i - a$$i) * (b$$k - a$$k)" 
  1825     "(\<Prod>i\<in>Basis. b\<bullet>i - a\<bullet>i) = (\<Prod>i\<in>Basis-{k}. b\<bullet>i - a\<bullet>i) * (b\<bullet>k - a\<bullet>k)" 
  1929     apply(subst *(1)) defer apply(subst *(1)) unfolding setprod_insert[OF *(2-)] by auto
  1826     apply(subst *(1)) defer apply(subst *(1)) unfolding setprod_insert[OF *(2-)] by auto
  1930   assume as:"a\<le>b" moreover have "\<And>x. min (b $$ k) c = max (a $$ k) c
  1827   assume as:"a\<le>b" moreover have "\<And>x. min (b \<bullet> k) c = max (a \<bullet> k) c
  1931     \<Longrightarrow> x* (b$$k - a$$k) = x*(max (a $$ k) c - a $$ k) + x*(b $$ k - max (a $$ k) c)"
  1828     \<Longrightarrow> x* (b\<bullet>k - a\<bullet>k) = x*(max (a \<bullet> k) c - a \<bullet> k) + x*(b \<bullet> k - max (a \<bullet> k) c)"
  1932     by  (auto simp add:field_simps)
  1829     by  (auto simp add:field_simps)
  1933   moreover have **:"(\<Prod>i<DIM('a). ((\<chi>\<chi> i. if i = k then min (b $$ k) c else b $$ i)::'a) $$ i - a $$ i) = 
  1830   moreover have **:"(\<Prod>i\<in>Basis. ((\<Sum>i\<in>Basis. (if i = k then min (b \<bullet> k) c else b \<bullet> i) *\<^sub>R i) \<bullet> i - a \<bullet> i)) = 
  1934     (\<Prod>i<DIM('a). (if i = k then min (b $$ k) c else b $$ i) - a $$ i)"
  1831       (\<Prod>i\<in>Basis. (if i = k then min (b \<bullet> k) c else b \<bullet> i) - a \<bullet> i)"
  1935     "(\<Prod>i<DIM('a). b $$ i - ((\<chi>\<chi> i. if i = k then max (a $$ k) c else a $$ i)::'a) $$ i) =
  1832     "(\<Prod>i\<in>Basis. b \<bullet> i - ((\<Sum>i\<in>Basis. (if i = k then max (a \<bullet> k) c else a \<bullet> i) *\<^sub>R i) \<bullet> i)) =
  1936     (\<Prod>i<DIM('a). b $$ i - (if i = k then max (a $$ k) c else a $$ i))"
  1833       (\<Prod>i\<in>Basis. b \<bullet> i - (if i = k then max (a \<bullet> k) c else a \<bullet> i))"
  1937     apply(rule_tac[!] setprod.cong) by auto
  1834     by (auto intro!: setprod_cong)
  1938   have "\<not> a $$ k \<le> c \<Longrightarrow> \<not> c \<le> b $$ k \<Longrightarrow> False"
  1835   have "\<not> a \<bullet> k \<le> c \<Longrightarrow> \<not> c \<le> b \<bullet> k \<Longrightarrow> False"
  1939     unfolding not_le using as[unfolded eucl_le[where 'a='a],rule_format,of k] assms by auto
  1836     unfolding not_le using as[unfolded eucl_le[where 'a='a],rule_format,of k] assms by auto
  1940   ultimately show ?thesis using assms unfolding simps **
  1837   ultimately show ?thesis using assms unfolding simps **
  1941     unfolding *(1)[of "\<lambda>i x. b$$i - x"] *(1)[of "\<lambda>i x. x - a$$i"] unfolding  *(2) 
  1838     unfolding *(1)[of "\<lambda>i x. b\<bullet>i - x"] *(1)[of "\<lambda>i x. x - a\<bullet>i"] unfolding *(2)
  1942     apply(subst(2) euclidean_lambda_beta''[where 'a='a])
  1839     by auto
  1943     apply(subst(3) euclidean_lambda_beta''[where 'a='a]) by auto
  1840 next
       
  1841   assume "\<not> a \<le> b" then have "{a .. b} = {}"
       
  1842     unfolding interval_eq_empty by (auto simp: eucl_le[where 'a='a] not_le)
       
  1843   then show ?thesis by auto
  1944 qed
  1844 qed
  1945 
  1845 
  1946 lemma division_split_left_inj: fixes type::"'a::ordered_euclidean_space"
  1846 lemma division_split_left_inj: fixes type::"'a::ordered_euclidean_space"
  1947   assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2" 
  1847   assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2" 
  1948   "k1 \<inter> {x::'a. x$$k \<le> c} = k2 \<inter> {x. x$$k \<le> c}"and k:"k<DIM('a)"
  1848   "k1 \<inter> {x::'a. x\<bullet>k \<le> c} = k2 \<inter> {x. x\<bullet>k \<le> c}"and k:"k\<in>Basis"
  1949   shows "content(k1 \<inter> {x. x$$k \<le> c}) = 0"
  1849   shows "content(k1 \<inter> {x. x\<bullet>k \<le> c}) = 0"
  1950 proof- note d=division_ofD[OF assms(1)]
  1850 proof- note d=division_ofD[OF assms(1)]
  1951   have *:"\<And>a b::'a. \<And> c. (content({a..b} \<inter> {x. x$$k \<le> c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x$$k \<le> c}) = {})"
  1851   have *:"\<And>a b::'a. \<And> c. (content({a..b} \<inter> {x. x\<bullet>k \<le> c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x\<bullet>k \<le> c}) = {})"
  1952     unfolding  interval_split[OF k] content_eq_0_interior by auto
  1852     unfolding  interval_split[OF k] content_eq_0_interior by auto
  1953   guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
  1853   guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
  1954   guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
  1854   guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
  1955   have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
  1855   have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
  1956   show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
  1856   show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
  1957     defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
  1857     defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
  1958  
  1858  
  1959 lemma division_split_right_inj: fixes type::"'a::ordered_euclidean_space"
  1859 lemma division_split_right_inj: fixes type::"'a::ordered_euclidean_space"
  1960   assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2"
  1860   assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2"
  1961   "k1 \<inter> {x::'a. x$$k \<ge> c} = k2 \<inter> {x. x$$k \<ge> c}" and k:"k<DIM('a)"
  1861   "k1 \<inter> {x::'a. x\<bullet>k \<ge> c} = k2 \<inter> {x. x\<bullet>k \<ge> c}" and k:"k\<in>Basis"
  1962   shows "content(k1 \<inter> {x. x$$k \<ge> c}) = 0"
  1862   shows "content(k1 \<inter> {x. x\<bullet>k \<ge> c}) = 0"
  1963 proof- note d=division_ofD[OF assms(1)]
  1863 proof- note d=division_ofD[OF assms(1)]
  1964   have *:"\<And>a b::'a. \<And> c. (content({a..b} \<inter> {x. x$$k >= c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x$$k >= c}) = {})"
  1864   have *:"\<And>a b::'a. \<And> c. (content({a..b} \<inter> {x. x\<bullet>k >= c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x\<bullet>k >= c}) = {})"
  1965     unfolding interval_split[OF k] content_eq_0_interior by auto
  1865     unfolding interval_split[OF k] content_eq_0_interior by auto
  1966   guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
  1866   guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
  1967   guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
  1867   guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
  1968   have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
  1868   have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
  1969   show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
  1869   show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
  1970     defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
  1870     defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
  1971 
  1871 
  1972 lemma tagged_division_split_left_inj: fixes x1::"'a::ordered_euclidean_space"
  1872 lemma tagged_division_split_left_inj: fixes x1::"'a::ordered_euclidean_space"
  1973   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}" 
  1873   assumes "d tagged_division_of i" "(x1,k1) \<in> d" "(x2,k2) \<in> d" "k1 \<noteq> k2"  "k1 \<inter> {x. x\<bullet>k \<le> c} = k2 \<inter> {x. x\<bullet>k \<le> c}" 
  1974   and k:"k<DIM('a)"
  1874   and k:"k\<in>Basis"
  1975   shows "content(k1 \<inter> {x. x$$k \<le> c}) = 0"
  1875   shows "content(k1 \<inter> {x. x\<bullet>k \<le> c}) = 0"
  1976 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
  1876 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
  1977   show ?thesis apply(rule division_split_left_inj[OF division_of_tagged_division[OF assms(1)]])
  1877   show ?thesis apply(rule division_split_left_inj[OF division_of_tagged_division[OF assms(1)]])
  1978     apply(rule_tac[1-2] *) using assms(2-) by auto qed
  1878     apply(rule_tac[1-2] *) using assms(2-) by auto qed
  1979 
  1879 
  1980 lemma tagged_division_split_right_inj: fixes x1::"'a::ordered_euclidean_space"
  1880 lemma tagged_division_split_right_inj: fixes x1::"'a::ordered_euclidean_space"
  1981   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}" 
  1881   assumes "d tagged_division_of i" "(x1,k1) \<in> d" "(x2,k2) \<in> d" "k1 \<noteq> k2"  "k1 \<inter> {x. x\<bullet>k \<ge> c} = k2 \<inter> {x. x\<bullet>k \<ge> c}" 
  1982   and k:"k<DIM('a)"
  1882   and k:"k\<in>Basis"
  1983   shows "content(k1 \<inter> {x. x$$k \<ge> c}) = 0"
  1883   shows "content(k1 \<inter> {x. x\<bullet>k \<ge> c}) = 0"
  1984 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
  1884 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
  1985   show ?thesis apply(rule division_split_right_inj[OF division_of_tagged_division[OF assms(1)]])
  1885   show ?thesis apply(rule division_split_right_inj[OF division_of_tagged_division[OF assms(1)]])
  1986     apply(rule_tac[1-2] *) using assms(2-) by auto qed
  1886     apply(rule_tac[1-2] *) using assms(2-) by auto qed
  1987 
  1887 
  1988 lemma division_split: fixes a::"'a::ordered_euclidean_space"
  1888 lemma division_split: fixes a::"'a::ordered_euclidean_space"
  1989   assumes "p division_of {a..b}" and k:"k<DIM('a)"
  1889   assumes "p division_of {a..b}" and k:"k\<in>Basis"
  1990   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 
  1890   shows "{l \<inter> {x. x\<bullet>k \<le> c} | l. l \<in> p \<and> ~(l \<inter> {x. x\<bullet>k \<le> c} = {})} division_of({a..b} \<inter> {x. x\<bullet>k \<le> c})" (is "?p1 division_of ?I1") and 
  1991         "{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")
  1891         "{l \<inter> {x. x\<bullet>k \<ge> c} | l. l \<in> p \<and> ~(l \<inter> {x. x\<bullet>k \<ge> c} = {})} division_of ({a..b} \<inter> {x. x\<bullet>k \<ge> c})" (is "?p2 division_of ?I2")
  1992 proof(rule_tac[!] division_ofI) note p=division_ofD[OF assms(1)]
  1892 proof(rule_tac[!] division_ofI) note p=division_ofD[OF assms(1)]
  1993   show "finite ?p1" "finite ?p2" using p(1) by auto show "\<Union>?p1 = ?I1" "\<Union>?p2 = ?I2" unfolding p(6)[THEN sym] by auto
  1893   show "finite ?p1" "finite ?p2" using p(1) by auto show "\<Union>?p1 = ?I1" "\<Union>?p2 = ?I2" unfolding p(6)[THEN sym] by auto
  1994   { fix k assume "k\<in>?p1" then guess l unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l=this
  1894   { fix k assume "k\<in>?p1" then guess l unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l=this
  1995     guess u v using p(4)[OF l(2)] apply-by(erule exE)+ note uv=this
  1895     guess u v using p(4)[OF l(2)] apply-by(erule exE)+ note uv=this
  1996     show "k\<subseteq>?I1" "k \<noteq> {}" "\<exists>a b. k = {a..b}" unfolding l
  1896     show "k\<subseteq>?I1" "k \<noteq> {}" "\<exists>a b. k = {a..b}" unfolding l
  2004     fix k' assume "k'\<in>?p2" then guess l' unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l'=this
  1904     fix k' assume "k'\<in>?p2" then guess l' unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l'=this
  2005     assume "k\<noteq>k'" thus "interior k \<inter> interior k' = {}" unfolding l l' using p(5)[OF l(2) l'(2)] by auto }
  1905     assume "k\<noteq>k'" thus "interior k \<inter> interior k' = {}" unfolding l l' using p(5)[OF l(2) l'(2)] by auto }
  2006 qed
  1906 qed
  2007 
  1907 
  2008 lemma has_integral_split: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector"
  1908 lemma has_integral_split: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector"
  2009   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})" and k:"k<DIM('a)"
  1909   assumes "(f has_integral i) ({a..b} \<inter> {x. x\<bullet>k \<le> c})"  "(f has_integral j) ({a..b} \<inter> {x. x\<bullet>k \<ge> c})" and k:"k\<in>Basis"
  2010   shows "(f has_integral (i + j)) ({a..b})"
  1910   shows "(f has_integral (i + j)) ({a..b})"
  2011 proof(unfold has_integral,rule,rule) case goal1 hence e:"e/2>0" by auto
  1911 proof(unfold has_integral,rule,rule) case goal1 hence e:"e/2>0" by auto
  2012   guess d1 using has_integralD[OF assms(1)[unfolded interval_split[OF k]] e] . note d1=this[unfolded interval_split[THEN sym,OF k]]
  1912   guess d1 using has_integralD[OF assms(1)[unfolded interval_split[OF k]] e] . note d1=this[unfolded interval_split[THEN sym,OF k]]
  2013   guess d2 using has_integralD[OF assms(2)[unfolded interval_split[OF k]] e] . note d2=this[unfolded interval_split[THEN sym,OF k]]
  1913   guess d2 using has_integralD[OF assms(2)[unfolded interval_split[OF k]] e] . note d2=this[unfolded interval_split[THEN sym,OF k]]
  2014   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"
  1914   let ?d = "\<lambda>x. if x\<bullet>k = c then (d1 x \<inter> d2 x) else ball x (abs(x\<bullet>k - c)) \<inter> d1 x \<inter> d2 x"
  2015   show ?case apply(rule_tac x="?d" in exI,rule) defer apply(rule,rule,(erule conjE)+)
  1915   show ?case apply(rule_tac x="?d" in exI,rule) defer apply(rule,rule,(erule conjE)+)
  2016   proof- show "gauge ?d" using d1(1) d2(1) unfolding gauge_def by auto
  1916   proof- show "gauge ?d" using d1(1) d2(1) unfolding gauge_def by auto
  2017     fix p assume "p tagged_division_of {a..b}" "?d fine p" note p = this tagged_division_ofD[OF this(1)]
  1917     fix p assume "p tagged_division_of {a..b}" "?d fine p" note p = this tagged_division_ofD[OF this(1)]
  2018     have lem0:"\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x$$k \<le> c} = {}) \<Longrightarrow> x$$k \<le> c"
  1918     have lem0:"\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x\<bullet>k \<le> c} = {}) \<Longrightarrow> x\<bullet>k \<le> c"
  2019          "\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x$$k \<ge> c} = {}) \<Longrightarrow> x$$k \<ge> c"
  1919          "\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x\<bullet>k \<ge> c} = {}) \<Longrightarrow> x\<bullet>k \<ge> c"
  2020     proof- fix x kk assume as:"(x,kk)\<in>p"
  1920     proof- fix x kk assume as:"(x,kk)\<in>p"
  2021       show "~(kk \<inter> {x. x$$k \<le> c} = {}) \<Longrightarrow> x$$k \<le> c"
  1921       show "~(kk \<inter> {x. x\<bullet>k \<le> c} = {}) \<Longrightarrow> x\<bullet>k \<le> c"
  2022       proof(rule ccontr) case goal1
  1922       proof(rule ccontr) case goal1
  2023         from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x $$ k - c\<bar>"
  1923         from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x \<bullet> k - c\<bar>"
  2024           using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
  1924           using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
  2025         hence "\<exists>y. y \<in> ball x \<bar>x $$ k - c\<bar> \<inter> {x. x $$ k \<le> c}" using goal1(1) by blast 
  1925         hence "\<exists>y. y \<in> ball x \<bar>x \<bullet> k - c\<bar> \<inter> {x. x \<bullet> k \<le> c}" using goal1(1) by blast 
  2026         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)
  1926         then guess y .. hence "\<bar>x \<bullet> k - y \<bullet> k\<bar> < \<bar>x \<bullet> k - c\<bar>" "y\<bullet>k \<le> c" apply-apply(rule le_less_trans)
  2027           using component_le_norm[of "x - y" k] by(auto simp add:dist_norm)
  1927           using Basis_le_norm[OF k, of "x - y"] by (auto simp add: dist_norm inner_diff_left)
  2028         thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
  1928         thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
  2029       qed
  1929       qed
  2030       show "~(kk \<inter> {x. x$$k \<ge> c} = {}) \<Longrightarrow> x$$k \<ge> c"
  1930       show "~(kk \<inter> {x. x\<bullet>k \<ge> c} = {}) \<Longrightarrow> x\<bullet>k \<ge> c"
  2031       proof(rule ccontr) case goal1
  1931       proof(rule ccontr) case goal1
  2032         from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x $$ k - c\<bar>"
  1932         from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x \<bullet> k - c\<bar>"
  2033           using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
  1933           using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
  2034         hence "\<exists>y. y \<in> ball x \<bar>x $$ k - c\<bar> \<inter> {x. x $$ k \<ge> c}" using goal1(1) by blast 
  1934         hence "\<exists>y. y \<in> ball x \<bar>x \<bullet> k - c\<bar> \<inter> {x. x \<bullet> k \<ge> c}" using goal1(1) by blast 
  2035         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)
  1935         then guess y .. hence "\<bar>x \<bullet> k - y \<bullet> k\<bar> < \<bar>x \<bullet> k - c\<bar>" "y\<bullet>k \<ge> c" apply-apply(rule le_less_trans)
  2036           using component_le_norm[of "x - y" k] by(auto simp add:dist_norm)
  1936           using Basis_le_norm[OF k, of "x - y"] by (auto simp add: dist_norm inner_diff_left)
  2037         thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
  1937         thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
  2038       qed
  1938       qed
  2039     qed
  1939     qed
  2040 
  1940 
  2041     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
  1941     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
  2051       have "content (g k) = 0" using xk using content_empty by auto
  1951       have "content (g k) = 0" using xk using content_empty by auto
  2052       thus "(\<lambda>(x, k). content k *\<^sub>R f x) i = 0" unfolding xk split_conv by auto
  1952       thus "(\<lambda>(x, k). content k *\<^sub>R f x) i = 0" unfolding xk split_conv by auto
  2053     qed auto
  1953     qed auto
  2054     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
  1954     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
  2055 
  1955 
  2056     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> {}}"
  1956     let ?M1 = "{(x,kk \<inter> {x. x\<bullet>k \<le> c}) |x kk. (x,kk) \<in> p \<and> kk \<inter> {x. x\<bullet>k \<le> c} \<noteq> {}}"
  2057     have "norm ((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) < e/2" apply(rule d1(2),rule tagged_division_ofI)
  1957     have "norm ((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) < e/2" apply(rule d1(2),rule tagged_division_ofI)
  2058       apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
  1958       apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
  2059     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
  1959     proof- show "\<Union>{k. \<exists>x. (x, k) \<in> ?M1} = {a..b} \<inter> {x. x\<bullet>k \<le> c}" unfolding p(8)[THEN sym] by auto
  2060       fix x l assume xl:"(x,l)\<in>?M1"
  1960       fix x l assume xl:"(x,l)\<in>?M1"
  2061       then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
  1961       then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
  2062       have "l' \<subseteq> d1 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
  1962       have "l' \<subseteq> d1 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
  2063       thus "l \<subseteq> d1 x" unfolding xl' by auto
  1963       thus "l \<subseteq> d1 x" unfolding xl' by auto
  2064       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)
  1964       show "x\<in>l" "l \<subseteq> {a..b} \<inter> {x. x \<bullet> k \<le> c}" unfolding xl' using p(4-6)[OF xl'(3)] using xl'(4)
  2065         using lem0(1)[OF xl'(3-4)] by auto
  1965         using lem0(1)[OF xl'(3-4)] by auto
  2066       show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastforce simp add: interval_split[OF k,where c=c])
  1966       show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastforce simp add: interval_split[OF k,where c=c])
  2067       fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M1"
  1967       fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M1"
  2068       then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
  1968       then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
  2069       assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
  1969       assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
  2071         case False thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
  1971         case False thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
  2072       next case True hence "l' \<noteq> r'" using as unfolding xl' yr' by auto
  1972       next case True hence "l' \<noteq> r'" using as unfolding xl' yr' by auto
  2073         thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
  1973         thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
  2074       qed qed moreover
  1974       qed qed moreover
  2075 
  1975 
  2076     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> {}}" 
  1976     let ?M2 = "{(x,kk \<inter> {x. x\<bullet>k \<ge> c}) |x kk. (x,kk) \<in> p \<and> kk \<inter> {x. x\<bullet>k \<ge> c} \<noteq> {}}" 
  2077     have "norm ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j) < e/2" apply(rule d2(2),rule tagged_division_ofI)
  1977     have "norm ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j) < e/2" apply(rule d2(2),rule tagged_division_ofI)
  2078       apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
  1978       apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
  2079     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
  1979     proof- show "\<Union>{k. \<exists>x. (x, k) \<in> ?M2} = {a..b} \<inter> {x. x\<bullet>k \<ge> c}" unfolding p(8)[THEN sym] by auto
  2080       fix x l assume xl:"(x,l)\<in>?M2"
  1980       fix x l assume xl:"(x,l)\<in>?M2"
  2081       then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
  1981       then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
  2082       have "l' \<subseteq> d2 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
  1982       have "l' \<subseteq> d2 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
  2083       thus "l \<subseteq> d2 x" unfolding xl' by auto
  1983       thus "l \<subseteq> d2 x" unfolding xl' by auto
  2084       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)
  1984       show "x\<in>l" "l \<subseteq> {a..b} \<inter> {x. x \<bullet> k \<ge> c}" unfolding xl' using p(4-6)[OF xl'(3)] using xl'(4)
  2085         using lem0(2)[OF xl'(3-4)] by auto
  1985         using lem0(2)[OF xl'(3-4)] by auto
  2086       show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastforce simp add: interval_split[OF k, where c=c])
  1986       show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastforce simp add: interval_split[OF k, where c=c])
  2087       fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M2"
  1987       fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M2"
  2088       then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
  1988       then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
  2089       assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
  1989       assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
  2096     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"
  1996     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"
  2097       apply- apply(rule norm_triangle_lt) by auto
  1997       apply- apply(rule norm_triangle_lt) by auto
  2098     also { have *:"\<And>x y. x = (0::real) \<Longrightarrow> x *\<^sub>R (y::'b) = 0" using scaleR_zero_left by auto
  1998     also { have *:"\<And>x y. x = (0::real) \<Longrightarrow> x *\<^sub>R (y::'b) = 0" using scaleR_zero_left by auto
  2099       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)
  1999       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)
  2100        = (\<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
  2000        = (\<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
  2101       also have "\<dots> = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. x $$ k \<le> c}) *\<^sub>R f x) +
  2001       also have "\<dots> = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f x) +
  2102         (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. c \<le> x $$ k}) *\<^sub>R f x) - (i + j)"
  2002         (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f x) - (i + j)"
  2103         unfolding lem3[OF p(3)] apply(subst setsum_reindex_nonzero[OF p(3)]) defer apply(subst setsum_reindex_nonzero[OF p(3)])
  2003         unfolding lem3[OF p(3)] apply(subst setsum_reindex_nonzero[OF p(3)]) defer apply(subst setsum_reindex_nonzero[OF p(3)])
  2104         defer unfolding lem4[THEN sym] apply(rule refl) unfolding split_paired_all split_conv apply(rule_tac[!] *)
  2004         defer unfolding lem4[THEN sym] apply(rule refl) unfolding split_paired_all split_conv apply(rule_tac[!] *)
  2105       proof- case goal1 thus ?case apply- apply(rule tagged_division_split_left_inj [OF p(1), of a b aa ba]) using k by auto
  2005       proof- case goal1 thus ?case apply- apply(rule tagged_division_split_left_inj [OF p(1), of a b aa ba]) using k by auto
  2106       next case   goal2 thus ?case apply- apply(rule tagged_division_split_right_inj[OF p(1), of a b aa ba]) using k by auto
  2006       next case   goal2 thus ?case apply- apply(rule tagged_division_split_right_inj[OF p(1), of a b aa ba]) using k by auto
  2107       qed also note setsum_addf[THEN sym]
  2007       qed also note setsum_addf[THEN sym]
  2108       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
  2008       also have *:"\<And>x. x\<in>p \<Longrightarrow> (\<lambda>(x, ka). content (ka \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f x) x + (\<lambda>(x, ka). content (ka \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f x) x
  2109         = (\<lambda>(x,ka). content ka *\<^sub>R f x) x" unfolding split_paired_all split_conv
  2009         = (\<lambda>(x,ka). content ka *\<^sub>R f x) x" unfolding split_paired_all split_conv
  2110       proof- fix a b assume "(a,b) \<in> p" from p(6)[OF this] guess u v apply-by(erule exE)+ note uv=this
  2010       proof- fix a b assume "(a,b) \<in> p" from p(6)[OF this] guess u v apply-by(erule exE)+ note uv=this
  2111         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"
  2011         thus "content (b \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f a + content (b \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f a = content b *\<^sub>R f a"
  2112           unfolding scaleR_left_distrib[THEN sym] unfolding uv content_split[OF k,of u v c] by auto
  2012           unfolding scaleR_left_distrib[THEN sym] unfolding uv content_split[OF k,of u v c] by auto
  2113       qed note setsum_cong2[OF this]
  2013       qed note setsum_cong2[OF this]
  2114       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 +
  2014       finally have "(\<Sum>(x, k)\<in>{(x, kk \<inter> {x. x \<bullet> k \<le> c}) |x kk. (x, kk) \<in> p \<and> kk \<inter> {x. x \<bullet> k \<le> c} \<noteq> {}}. content k *\<^sub>R f x) - i +
  2115         ((\<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) =
  2015         ((\<Sum>(x, k)\<in>{(x, kk \<inter> {x. c \<le> x \<bullet> k}) |x kk. (x, kk) \<in> p \<and> kk \<inter> {x. c \<le> x \<bullet> k} \<noteq> {}}. content k *\<^sub>R f x) - j) =
  2116         (\<Sum>(x, ka)\<in>p. content ka *\<^sub>R f x) - (i + j)" by auto }
  2016         (\<Sum>(x, ka)\<in>p. content ka *\<^sub>R f x) - (i + j)" by auto }
  2117     finally show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - (i + j)) < e" by auto qed qed
  2017     finally show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - (i + j)) < e" by auto qed qed
  2118 
  2018 
  2119 (*lemma has_integral_split_cart: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
       
  2120   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})"
       
  2121   shows "(f has_integral (i + j)) ({a..b})" *)
       
  2122 
       
  2123 subsection {* A sort of converse, integrability on subintervals. *}
  2019 subsection {* A sort of converse, integrability on subintervals. *}
  2124 
  2020 
  2125 lemma tagged_division_union_interval: fixes a::"'a::ordered_euclidean_space"
  2021 lemma tagged_division_union_interval: fixes a::"'a::ordered_euclidean_space"
  2126   assumes "p1 tagged_division_of ({a..b} \<inter> {x. x$$k \<le> (c::real)})"  "p2 tagged_division_of ({a..b} \<inter> {x. x$$k \<ge> c})"
  2022   assumes "p1 tagged_division_of ({a..b} \<inter> {x. x\<bullet>k \<le> (c::real)})"  "p2 tagged_division_of ({a..b} \<inter> {x. x\<bullet>k \<ge> c})"
  2127   and k:"k<DIM('a)"
  2023   and k:"k\<in>Basis"
  2128   shows "(p1 \<union> p2) tagged_division_of ({a..b})"
  2024   shows "(p1 \<union> p2) tagged_division_of ({a..b})"
  2129 proof- have *:"{a..b} = ({a..b} \<inter> {x. x$$k \<le> c}) \<union> ({a..b} \<inter> {x. x$$k \<ge> c})" by auto
  2025 proof- have *:"{a..b} = ({a..b} \<inter> {x. x\<bullet>k \<le> c}) \<union> ({a..b} \<inter> {x. x\<bullet>k \<ge> c})" by auto
  2130   show ?thesis apply(subst *) apply(rule tagged_division_union[OF assms(1-2)])
  2026   show ?thesis apply(subst *) apply(rule tagged_division_union[OF assms(1-2)])
  2131     unfolding interval_split[OF k] interior_closed_interval using k
  2027     unfolding interval_split[OF k] interior_closed_interval using k
  2132     by(auto simp add: eucl_less[where 'a='a] elim!:allE[where x=k]) qed
  2028     by(auto simp add: eucl_less[where 'a='a] elim!: ballE[where x=k]) qed
  2133 
  2029 
  2134 lemma has_integral_separate_sides: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector"
  2030 lemma has_integral_separate_sides: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector"
  2135   assumes "(f has_integral i) ({a..b})" "e>0" and k:"k<DIM('a)"
  2031   assumes "(f has_integral i) ({a..b})" "e>0" and k:"k\<in>Basis"
  2136   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>
  2032   obtains d where "gauge d" "(\<forall>p1 p2. p1 tagged_division_of ({a..b} \<inter> {x. x\<bullet>k \<le> c}) \<and> d fine p1 \<and>
  2137                                 p2 tagged_division_of ({a..b} \<inter> {x. x$$k \<ge> c}) \<and> d fine p2
  2033                                 p2 tagged_division_of ({a..b} \<inter> {x. x\<bullet>k \<ge> c}) \<and> d fine p2
  2138                                 \<longrightarrow> norm((setsum (\<lambda>(x,k). content k *\<^sub>R f x) p1 +
  2034                                 \<longrightarrow> norm((setsum (\<lambda>(x,k). content k *\<^sub>R f x) p1 +
  2139                                           setsum (\<lambda>(x,k). content k *\<^sub>R f x) p2) - i) < e)"
  2035                                           setsum (\<lambda>(x,k). content k *\<^sub>R f x) p2) - i) < e)"
  2140 proof- guess d using has_integralD[OF assms(1-2)] . note d=this
  2036 proof- guess d using has_integralD[OF assms(1-2)] . note d=this
  2141   show ?thesis apply(rule that[of d]) apply(rule d) apply(rule,rule,rule,(erule conjE)+)
  2037   show ?thesis apply(rule that[of d]) apply(rule d) apply(rule,rule,rule,(erule conjE)+)
  2142   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
  2038   proof- fix p1 p2 assume "p1 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<le> c}" "d fine p1" note p1=tagged_division_ofD[OF this(1)] this
  2143                    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
  2039                    assume "p2 tagged_division_of {a..b} \<inter> {x. c \<le> x \<bullet> k}" "d fine p2" note p2=tagged_division_ofD[OF this(1)] this
  2144     note tagged_division_union_interval[OF p1(7) p2(7)] note p12 = tagged_division_ofD[OF this] this
  2040     note tagged_division_union_interval[OF p1(7) p2(7)] note p12 = tagged_division_ofD[OF this] this
  2145     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)"
  2041     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)"
  2146       apply(subst setsum_Un_zero) apply(rule p1 p2)+ apply(rule) unfolding split_paired_all split_conv
  2042       apply(subst setsum_Un_zero) apply(rule p1 p2)+ apply(rule) unfolding split_paired_all split_conv
  2147     proof- fix a b assume ab:"(a,b) \<in> p1 \<inter> p2"
  2043     proof- fix a b assume ab:"(a,b) \<in> p1 \<inter> p2"
  2148       have "(a,b) \<in> p1" using ab by auto from p1(4)[OF this] guess u v apply-by(erule exE)+ note uv =this
  2044       have "(a,b) \<in> p1" using ab by auto from p1(4)[OF this] guess u v apply-by(erule exE)+ note uv =this
  2149       have "b \<subseteq> {x. x$$k = c}" using ab p1(3)[of a b] p2(3)[of a b] by fastforce
  2045       have "b \<subseteq> {x. x\<bullet>k = c}" using ab p1(3)[of a b] p2(3)[of a b] by fastforce
  2150       moreover have "interior {x::'a. x $$ k = c} = {}" 
  2046       moreover have "interior {x::'a. x \<bullet> k = c} = {}" 
  2151       proof(rule ccontr) case goal1 then obtain x where x:"x\<in>interior {x::'a. x$$k = c}" by auto
  2047       proof(rule ccontr) case goal1 then obtain x where x:"x\<in>interior {x::'a. x\<bullet>k = c}" by auto
  2152         then guess e unfolding mem_interior .. note e=this
  2048         then guess e unfolding mem_interior .. note e=this
  2153         have x:"x$$k = c" using x interior_subset by fastforce
  2049         have x:"x\<bullet>k = c" using x interior_subset by fastforce
  2154         have *:"\<And>i. i<DIM('a) \<Longrightarrow> \<bar>(x - (x + (\<chi>\<chi> i. if i = k then e / 2 else 0))) $$ i\<bar>
  2050         have *:"\<And>i. i\<in>Basis \<Longrightarrow> \<bar>(x - (x + (e / 2) *\<^sub>R k)) \<bullet> i\<bar>
  2155           = (if i = k then e/2 else 0)" using e by auto
  2051           = (if i = k then e/2 else 0)" using e k by (auto simp: inner_simps inner_not_same_Basis)
  2156         have "(\<Sum>i<DIM('a). \<bar>(x - (x + (\<chi>\<chi> i. if i = k then e / 2 else 0))) $$ i\<bar>) =
  2052         have "(\<Sum>i\<in>Basis. \<bar>(x - (x + (e / 2 ) *\<^sub>R k)) \<bullet> i\<bar>) =
  2157           (\<Sum>i<DIM('a). (if i = k then e / 2 else 0))" apply(rule setsum_cong2) apply(subst *) by auto
  2053           (\<Sum>i\<in>Basis. (if i = k then e / 2 else 0))" apply(rule setsum_cong2) apply(subst *) by auto
  2158         also have "... < e" apply(subst setsum_delta) using e by auto 
  2054         also have "... < e" apply(subst setsum_delta) using e by auto 
  2159         finally have "x + (\<chi>\<chi> i. if i = k then e/2 else 0) \<in> ball x e" unfolding mem_ball dist_norm
  2055         finally have "x + (e/2) *\<^sub>R k \<in> ball x e"
  2160           by(rule le_less_trans[OF norm_le_l1])
  2056           unfolding mem_ball dist_norm by(rule le_less_trans[OF norm_le_l1])
  2161         hence "x + (\<chi>\<chi> i. if i = k then e/2 else 0) \<in> {x. x$$k = c}" using e by auto
  2057         hence "x + (e/2) *\<^sub>R k \<in> {x. x\<bullet>k = c}" using e by auto
  2162         thus False unfolding mem_Collect_eq using e x k by auto
  2058         thus False unfolding mem_Collect_eq using e x k by (auto simp: inner_simps)
  2163       qed ultimately have "content b = 0" unfolding uv content_eq_0_interior apply-apply(drule interior_mono) by auto
  2059       qed ultimately have "content b = 0" unfolding uv content_eq_0_interior apply-apply(drule interior_mono) by auto
  2164       thus "content b *\<^sub>R f a = 0" by auto
  2060       thus "content b *\<^sub>R f a = 0" by auto
  2165     qed auto
  2061     qed auto
  2166     also have "\<dots> < e" by(rule k d(2) p12 fine_union p1 p2)+
  2062     also have "\<dots> < e" by(rule k d(2) p12 fine_union p1 p2)+
  2167     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
  2063     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
  2168 
  2064 
  2169 lemma integrable_split[intro]: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::{real_normed_vector,complete_space}"
  2065 lemma integrable_split[intro]:
  2170   assumes "f integrable_on {a..b}" and k:"k<DIM('a)"
  2066   fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::{real_normed_vector,complete_space}"
  2171   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) 
  2067   assumes "f integrable_on {a..b}" and k:"k\<in>Basis"
       
  2068   shows "f integrable_on ({a..b} \<inter> {x. x\<bullet>k \<le> c})" (is ?t1) and "f integrable_on ({a..b} \<inter> {x. x\<bullet>k \<ge> c})" (is ?t2) 
  2172 proof- guess y using assms(1) unfolding integrable_on_def .. note y=this
  2069 proof- guess y using assms(1) unfolding integrable_on_def .. note y=this
  2173   def b' \<equiv> "(\<chi>\<chi> i. if i = k then min (b$$k) c else b$$i)::'a"
  2070   def b' \<equiv> "\<Sum>i\<in>Basis. (if i = k then min (b\<bullet>k) c else b\<bullet>i)*\<^sub>R i::'a"
  2174   and a' \<equiv> "(\<chi>\<chi> i. if i = k then max (a$$k) c else a$$i)::'a"
  2071   def a' \<equiv> "\<Sum>i\<in>Basis. (if i = k then max (a\<bullet>k) c else a\<bullet>i)*\<^sub>R i::'a"
  2175   show ?t1 ?t2 unfolding interval_split[OF k] integrable_cauchy unfolding interval_split[THEN sym,OF k]
  2072   show ?t1 ?t2 unfolding interval_split[OF k] integrable_cauchy unfolding interval_split[THEN sym,OF k]
  2176   proof(rule_tac[!] allI impI)+ fix e::real assume "e>0" hence "e/2>0" by auto
  2073   proof(rule_tac[!] allI impI)+ fix e::real assume "e>0" hence "e/2>0" by auto
  2177     from has_integral_separate_sides[OF y this k,of c] guess d . note d=this[rule_format]
  2074     from has_integral_separate_sides[OF y this k,of c] guess d . note d=this[rule_format]
  2178     let ?P = "\<lambda>A. \<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of {a..b} \<inter> A \<and> d fine p1
  2075     let ?P = "\<lambda>A. \<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of {a..b} \<inter> A \<and> d fine p1
  2179       \<and> p2 tagged_division_of {a..b} \<inter> A \<and> d fine p2 \<longrightarrow>
  2076       \<and> p2 tagged_division_of {a..b} \<inter> A \<and> d fine p2 \<longrightarrow>
  2180       norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e)"
  2077       norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e)"
  2181     show "?P {x. x $$ k \<le> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  2078     show "?P {x. x \<bullet> k \<le> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  2182     proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x $$ k \<le> c} \<and> d fine p1
  2079     proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<le> c} \<and> d fine p1
  2183         \<and> p2 tagged_division_of {a..b} \<inter> {x. x $$ k \<le> c} \<and> d fine p2"
  2080         \<and> p2 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<le> c} \<and> d fine p2"
  2184       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"
  2081       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"
  2185       proof- guess p using fine_division_exists[OF d(1), of a' b] . note p=this
  2082       proof- guess p using fine_division_exists[OF d(1), of a' b] . note p=this
  2186         show ?thesis using norm_triangle_half_l[OF d(2)[of p1 p] d(2)[of p2 p]]
  2083         show ?thesis using norm_triangle_half_l[OF d(2)[of p1 p] d(2)[of p2 p]]
  2187           using as unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
  2084           using as unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
  2188           using p using assms by(auto simp add:algebra_simps)
  2085           using p using assms by(auto simp add:algebra_simps)
  2189       qed qed  
  2086       qed qed  
  2190     show "?P {x. x $$ k \<ge> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  2087     show "?P {x. x \<bullet> k \<ge> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  2191     proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x $$ k \<ge> c} \<and> d fine p1
  2088     proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<ge> c} \<and> d fine p1
  2192         \<and> p2 tagged_division_of {a..b} \<inter> {x. x $$ k \<ge> c} \<and> d fine p2"
  2089         \<and> p2 tagged_division_of {a..b} \<inter> {x. x \<bullet> k \<ge> c} \<and> d fine p2"
  2193       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"
  2090       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"
  2194       proof- guess p using fine_division_exists[OF d(1), of a b'] . note p=this
  2091       proof- guess p using fine_division_exists[OF d(1), of a b'] . note p=this
  2195         show ?thesis using norm_triangle_half_l[OF d(2)[of p p1] d(2)[of p p2]]
  2092         show ?thesis using norm_triangle_half_l[OF d(2)[of p p1] d(2)[of p p2]]
  2196           using as unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
  2093           using as unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
  2197           using p using assms by(auto simp add:algebra_simps) qed qed qed qed
  2094           using p using assms by(auto simp add:algebra_simps) qed qed qed qed
  2201 definition "neutral opp = (SOME x. \<forall>y. opp x y = y \<and> opp y x = y)"
  2098 definition "neutral opp = (SOME x. \<forall>y. opp x y = y \<and> opp y x = y)"
  2202 
  2099 
  2203 definition operative :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> (('b::ordered_euclidean_space) set \<Rightarrow> 'a) \<Rightarrow> bool" where
  2100 definition operative :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> (('b::ordered_euclidean_space) set \<Rightarrow> 'a) \<Rightarrow> bool" where
  2204   "operative opp f \<equiv> 
  2101   "operative opp f \<equiv> 
  2205     (\<forall>a b. content {a..b} = 0 \<longrightarrow> f {a..b} = neutral(opp)) \<and>
  2102     (\<forall>a b. content {a..b} = 0 \<longrightarrow> f {a..b} = neutral(opp)) \<and>
  2206     (\<forall>a b c. \<forall>k<DIM('b). f({a..b}) =
  2103     (\<forall>a b c. \<forall>k\<in>Basis. f({a..b}) =
  2207                    opp (f({a..b} \<inter> {x. x$$k \<le> c}))
  2104                    opp (f({a..b} \<inter> {x. x\<bullet>k \<le> c}))
  2208                        (f({a..b} \<inter> {x. x$$k \<ge> c})))"
  2105                        (f({a..b} \<inter> {x. x\<bullet>k \<ge> c})))"
  2209 
  2106 
  2210 lemma operativeD[dest]: fixes type::"'a::ordered_euclidean_space"  assumes "operative opp f"
  2107 lemma operativeD[dest]: fixes type::"'a::ordered_euclidean_space"  assumes "operative opp f"
  2211   shows "\<And>a b. content {a..b} = 0 \<Longrightarrow> f {a..b::'a} = neutral(opp)"
  2108   shows "\<And>a b. content {a..b} = 0 \<Longrightarrow> f {a..b::'a} = neutral(opp)"
  2212   "\<And>a b c k. k<DIM('a) \<Longrightarrow> f({a..b}) = opp (f({a..b} \<inter> {x. x$$k \<le> c})) (f({a..b} \<inter> {x. x$$k \<ge> c}))"
  2109   "\<And>a b c k. k\<in>Basis \<Longrightarrow> f({a..b}) = opp (f({a..b} \<inter> {x. x\<bullet>k \<le> c})) (f({a..b} \<inter> {x. x\<bullet>k \<ge> c}))"
  2213   using assms unfolding operative_def by auto
  2110   using assms unfolding operative_def by auto
  2214 
  2111 
  2215 lemma operative_trivial:
  2112 lemma operative_trivial:
  2216  "operative opp f \<Longrightarrow> content({a..b}) = 0 \<Longrightarrow> f({a..b}) = neutral opp"
  2113  "operative opp f \<Longrightarrow> content({a..b}) = 0 \<Longrightarrow> f({a..b}) = neutral opp"
  2217   unfolding operative_def by auto
  2114   unfolding operative_def by auto
  2340   unfolding monoidal_def neutral_monoid by(auto simp add: algebra_simps) 
  2237   unfolding monoidal_def neutral_monoid by(auto simp add: algebra_simps) 
  2341 
  2238 
  2342 lemma operative_integral: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  2239 lemma operative_integral: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  2343   shows "operative (lifted(op +)) (\<lambda>i. if f integrable_on i then Some(integral i f) else None)"
  2240   shows "operative (lifted(op +)) (\<lambda>i. if f integrable_on i then Some(integral i f) else None)"
  2344   unfolding operative_def unfolding neutral_lifted[OF monoidal_monoid] neutral_add
  2241   unfolding operative_def unfolding neutral_lifted[OF monoidal_monoid] neutral_add
  2345   apply(rule,rule,rule,rule) defer apply(rule allI impI)+
  2242   apply(rule,rule,rule,rule) defer apply(rule allI ballI)+
  2346 proof- fix a b c k assume k:"k<DIM('a)" show "(if f integrable_on {a..b} then Some (integral {a..b} f) else None) =
  2243 proof-
  2347     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)
  2244   fix a b c and k :: 'a assume k:"k\<in>Basis"
  2348     (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)"
  2245   show "(if f integrable_on {a..b} then Some (integral {a..b} f) else None) =
       
  2246     lifted op + (if f integrable_on {a..b} \<inter> {x. x \<bullet> k \<le> c} then Some (integral ({a..b} \<inter> {x. x \<bullet> k \<le> c}) f) else None)
       
  2247     (if f integrable_on {a..b} \<inter> {x. c \<le> x \<bullet> k} then Some (integral ({a..b} \<inter> {x. c \<le> x \<bullet> k}) f) else None)"
  2349   proof(cases "f integrable_on {a..b}") 
  2248   proof(cases "f integrable_on {a..b}") 
  2350     case True show ?thesis unfolding if_P[OF True] using k apply-
  2249     case True show ?thesis unfolding if_P[OF True] using k apply-
  2351       unfolding if_P[OF integrable_split(1)[OF True]] unfolding if_P[OF integrable_split(2)[OF True]]
  2250       unfolding if_P[OF integrable_split(1)[OF True]] unfolding if_P[OF integrable_split(2)[OF True]]
  2352       unfolding lifted.simps option.inject apply(rule integral_unique) apply(rule has_integral_split[OF _ _ k]) 
  2251       unfolding lifted.simps option.inject apply(rule integral_unique) apply(rule has_integral_split[OF _ _ k]) 
  2353       apply(rule_tac[!] integrable_integral integrable_split)+ using True k by auto
  2252       apply(rule_tac[!] integrable_integral integrable_split)+ using True k by auto
  2354   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}))"
  2253   next case False have "(\<not> (f integrable_on {a..b} \<inter> {x. x \<bullet> k \<le> c})) \<or> (\<not> ( f integrable_on {a..b} \<inter> {x. c \<le> x \<bullet> k}))"
  2355     proof(rule ccontr) case goal1 hence "f integrable_on {a..b}" apply- unfolding integrable_on_def
  2254     proof(rule ccontr) case goal1 hence "f integrable_on {a..b}" apply- unfolding integrable_on_def
  2356         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)
  2255         apply(rule_tac x="integral ({a..b} \<inter> {x. x \<bullet> k \<le> c}) f + integral ({a..b} \<inter> {x. x \<bullet> k \<ge> c}) f" in exI)
  2357         apply(rule has_integral_split[OF _ _ k]) apply(rule_tac[!] integrable_integral) by auto
  2256         apply(rule has_integral_split[OF _ _ k]) apply(rule_tac[!] integrable_integral) by auto
  2358       thus False using False by auto
  2257       thus False using False by auto
  2359     qed thus ?thesis using False by auto 
  2258     qed thus ?thesis using False by auto 
  2360   qed next 
  2259   qed next 
  2361   fix a b assume as:"content {a..b::'a} = 0"
  2260   fix a b assume as:"content {a..b::'a} = 0"
  2363     unfolding if_P[OF integrable_on_null[OF as]] using has_integral_null_eq[OF as] by auto qed
  2262     unfolding if_P[OF integrable_on_null[OF as]] using has_integral_null_eq[OF as] by auto qed
  2364 
  2263 
  2365 subsection {* Points of division of a partition. *}
  2264 subsection {* Points of division of a partition. *}
  2366 
  2265 
  2367 definition "division_points (k::('a::ordered_euclidean_space) set) d = 
  2266 definition "division_points (k::('a::ordered_euclidean_space) set) d = 
  2368     {(j,x). j<DIM('a) \<and> (interval_lowerbound k)$$j < x \<and> x < (interval_upperbound k)$$j \<and>
  2267     {(j,x). j\<in>Basis \<and> (interval_lowerbound k)\<bullet>j < x \<and> x < (interval_upperbound k)\<bullet>j \<and>
  2369            (\<exists>i\<in>d. (interval_lowerbound i)$$j = x \<or> (interval_upperbound i)$$j = x)}"
  2268            (\<exists>i\<in>d. (interval_lowerbound i)\<bullet>j = x \<or> (interval_upperbound i)\<bullet>j = x)}"
  2370 
  2269 
  2371 lemma division_points_finite: fixes i::"('a::ordered_euclidean_space) set"
  2270 lemma division_points_finite: fixes i::"('a::ordered_euclidean_space) set"
  2372   assumes "d division_of i" shows "finite (division_points i d)"
  2271   assumes "d division_of i" shows "finite (division_points i d)"
  2373 proof- note assm = division_ofD[OF assms]
  2272 proof- note assm = division_ofD[OF assms]
  2374   let ?M = "\<lambda>j. {(j,x)|x. (interval_lowerbound i)$$j < x \<and> x < (interval_upperbound i)$$j \<and>
  2273   let ?M = "\<lambda>j. {(j,x)|x. (interval_lowerbound i)\<bullet>j < x \<and> x < (interval_upperbound i)\<bullet>j \<and>
  2375            (\<exists>i\<in>d. (interval_lowerbound i)$$j = x \<or> (interval_upperbound i)$$j = x)}"
  2274            (\<exists>i\<in>d. (interval_lowerbound i)\<bullet>j = x \<or> (interval_upperbound i)\<bullet>j = x)}"
  2376   have *:"division_points i d = \<Union>(?M ` {..<DIM('a)})"
  2275   have *:"division_points i d = \<Union>(?M ` Basis)"
  2377     unfolding division_points_def by auto
  2276     unfolding division_points_def by auto
  2378   show ?thesis unfolding * using assm by auto qed
  2277   show ?thesis unfolding * using assm by auto qed
  2379 
  2278 
  2380 lemma division_points_subset: fixes a::"'a::ordered_euclidean_space"
  2279 lemma division_points_subset: fixes a::"'a::ordered_euclidean_space"
  2381   assumes "d division_of {a..b}" "\<forall>i<DIM('a). a$$i < b$$i"  "a$$k < c" "c < b$$k" and k:"k<DIM('a)"
  2280   assumes "d division_of {a..b}" "\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i"  "a\<bullet>k < c" "c < b\<bullet>k" and k:"k\<in>Basis"
  2382   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} = {})}
  2281   shows "division_points ({a..b} \<inter> {x. x\<bullet>k \<le> c}) {l \<inter> {x. x\<bullet>k \<le> c} | l . l \<in> d \<and> ~(l \<inter> {x. x\<bullet>k \<le> c} = {})}
  2383                   \<subseteq> division_points ({a..b}) d" (is ?t1) and
  2282                   \<subseteq> division_points ({a..b}) d" (is ?t1) and
  2384         "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} = {})}
  2283         "division_points ({a..b} \<inter> {x. x\<bullet>k \<ge> c}) {l \<inter> {x. x\<bullet>k \<ge> c} | l . l \<in> d \<and> ~(l \<inter> {x. x\<bullet>k \<ge> c} = {})}
  2385                   \<subseteq> division_points ({a..b}) d" (is ?t2)
  2284                   \<subseteq> division_points ({a..b}) d" (is ?t2)
  2386 proof- note assm = division_ofD[OF assms(1)]
  2285 proof- note assm = division_ofD[OF assms(1)]
  2387   have *:"\<forall>i<DIM('a). a$$i \<le> b$$i"   "\<forall>i<DIM('a). a$$i \<le> ((\<chi>\<chi> i. if i = k then min (b $$ k) c else b $$ i)::'a) $$ i"
  2286   have *:"\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i"
  2388     "\<forall>i<DIM('a). ((\<chi>\<chi> i. if i = k then max (a $$ k) c else a $$ i)::'a) $$ i \<le> b$$i"  "min (b $$ k) c = c" "max (a $$ k) c = c"
  2287     "\<forall>i\<in>Basis. a\<bullet>i \<le> (\<Sum>i\<in>Basis. (if i = k then min (b \<bullet> k) c else b \<bullet> i) *\<^sub>R i) \<bullet> i"
       
  2288     "\<forall>i\<in>Basis. (\<Sum>i\<in>Basis. (if i = k then max (a \<bullet> k) c else a \<bullet> i) *\<^sub>R i) \<bullet> i \<le> b\<bullet>i"
       
  2289     "min (b \<bullet> k) c = c" "max (a \<bullet> k) c = c"
  2389     using assms using less_imp_le by auto
  2290     using assms using less_imp_le by auto
  2390   show ?t1 unfolding division_points_def interval_split[OF k, of a b]
  2291   show ?t1
       
  2292     unfolding division_points_def interval_split[OF k, of a b]
       
  2293     unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)]
       
  2294     unfolding *
       
  2295     unfolding subset_eq
       
  2296     apply(rule)
       
  2297     unfolding mem_Collect_eq split_beta
       
  2298     apply(erule bexE conjE)+
       
  2299     apply(simp only: mem_Collect_eq inner_setsum_left_Basis simp_thms)
       
  2300     apply(erule exE conjE)+
       
  2301   proof
       
  2302     fix i l x assume as:"a \<bullet> fst x < snd x" "snd x < (if fst x = k then c else b \<bullet> fst x)"
       
  2303       "interval_lowerbound i \<bullet> fst x = snd x \<or> interval_upperbound i \<bullet> fst x = snd x"
       
  2304       "i = l \<inter> {x. x \<bullet> k \<le> c}" "l \<in> d" "l \<inter> {x. x \<bullet> k \<le> c} \<noteq> {}" and fstx:"fst x \<in>Basis"
       
  2305     from assm(4)[OF this(5)] guess u v apply-by(erule exE)+ note l=this
       
  2306     have *:"\<forall>i\<in>Basis. u \<bullet> i \<le> (\<Sum>i\<in>Basis. (if i = k then min (v \<bullet> k) c else v \<bullet> i) *\<^sub>R i) \<bullet> i"
       
  2307       using as(6) unfolding l interval_split[OF k] interval_ne_empty as .
       
  2308     have **:"\<forall>i\<in>Basis. u\<bullet>i \<le> v\<bullet>i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
       
  2309     show "\<exists>i\<in>d. interval_lowerbound i \<bullet> fst x = snd x \<or> interval_upperbound i \<bullet> fst x = snd x"
       
  2310       apply (rule bexI[OF _ `l \<in> d`])
       
  2311       using as(1-3,5) fstx
       
  2312       unfolding l interval_bounds[OF **] interval_bounds[OF *] interval_split[OF k] as
       
  2313       by (auto split: split_if_asm)
       
  2314     show "snd x < b \<bullet> fst x"
       
  2315       using as(2) `c < b\<bullet>k` by (auto split: split_if_asm)
       
  2316   qed
       
  2317   show ?t2
       
  2318     unfolding division_points_def interval_split[OF k, of a b]
  2391     unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)] unfolding *
  2319     unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)] unfolding *
  2392     unfolding subset_eq apply(rule) unfolding mem_Collect_eq split_beta apply(erule bexE conjE)+
  2320     unfolding subset_eq apply(rule) unfolding mem_Collect_eq split_beta
  2393     unfolding mem_Collect_eq apply(erule exE conjE)+ unfolding euclidean_lambda_beta'
  2321     apply(erule bexE conjE)+
  2394   proof- fix i l x assume as:"a $$ fst x < snd x" "snd x < (if fst x = k then c else b $$ fst x)"
  2322     apply(simp only: mem_Collect_eq inner_setsum_left_Basis simp_thms)
  2395       "interval_lowerbound i $$ fst x = snd x \<or> interval_upperbound i $$ fst x = snd x"
  2323     apply(erule exE conjE)+
  2396       "i = l \<inter> {x. x $$ k \<le> c}" "l \<in> d" "l \<inter> {x. x $$ k \<le> c} \<noteq> {}" and fstx:"fst x <DIM('a)"
  2324   proof
       
  2325     fix i l x assume as:"(if fst x = k then c else a \<bullet> fst x) < snd x" "snd x < b \<bullet> fst x"
       
  2326       "interval_lowerbound i \<bullet> fst x = snd x \<or> interval_upperbound i \<bullet> fst x = snd x" 
       
  2327       "i = l \<inter> {x. c \<le> x \<bullet> k}" "l \<in> d" "l \<inter> {x. c \<le> x \<bullet> k} \<noteq> {}" and fstx:"fst x \<in> Basis"
  2397     from assm(4)[OF this(5)] guess u v apply-by(erule exE)+ note l=this
  2328     from assm(4)[OF this(5)] guess u v apply-by(erule exE)+ note l=this
  2398     have *:"\<forall>i<DIM('a). u $$ i \<le> ((\<chi>\<chi> i. if i = k then min (v $$ k) c else v $$ i)::'a) $$ i"
  2329     have *:"\<forall>i\<in>Basis. (\<Sum>i\<in>Basis. (if i = k then max (u \<bullet> k) c else u \<bullet> i) *\<^sub>R i) \<bullet> i \<le> v \<bullet> i"
  2399       using as(6) unfolding l interval_split[OF k] interval_ne_empty as .
  2330       using as(6) unfolding l interval_split[OF k] interval_ne_empty as .
  2400     have **:"\<forall>i<DIM('a). u$$i \<le> v$$i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
  2331     have **:"\<forall>i\<in>Basis. u\<bullet>i \<le> v\<bullet>i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
  2401     show "fst x <DIM('a) \<and> a $$ fst x < snd x \<and> snd x < b $$ fst x \<and> (\<exists>i\<in>d. interval_lowerbound i $$ fst x = snd x
  2332     show "\<exists>i\<in>d. interval_lowerbound i \<bullet> fst x = snd x \<or> interval_upperbound i \<bullet> fst x = snd x"
  2402       \<or> interval_upperbound i $$ fst x = snd x)" apply(rule,rule fstx)
  2333       apply (rule bexI[OF _ `l \<in> d`])
  2403       using as(1-3,5) unfolding l interval_split[OF k] interval_ne_empty as interval_bounds[OF *] apply-
  2334       using as(1-3,5) fstx
  2404       apply(rule,assumption,rule) defer apply(rule_tac x="{u..v}" in bexI) unfolding interval_bounds[OF **]
  2335       unfolding l interval_bounds[OF **] interval_bounds[OF *] interval_split[OF k] as
  2405       apply(case_tac[!] "fst x = k") using assms fstx apply- unfolding euclidean_lambda_beta by auto
  2336       by (auto split: split_if_asm)
  2406   qed
  2337     show "a \<bullet> fst x < snd x"
  2407   show ?t2 unfolding division_points_def interval_split[OF k, of a b]
  2338       using as(1) `a\<bullet>k < c` by (auto split: split_if_asm)
  2408     unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)] unfolding *
  2339    qed
  2409     unfolding subset_eq apply(rule) unfolding mem_Collect_eq split_beta apply(erule bexE conjE)+
  2340 qed
  2410     unfolding mem_Collect_eq apply(erule exE conjE)+ unfolding euclidean_lambda_beta' apply(rule,assumption)
       
  2411   proof- fix i l x assume as:"(if fst x = k then c else a $$ fst x) < snd x" "snd x < b $$ fst x"
       
  2412       "interval_lowerbound i $$ fst x = snd x \<or> interval_upperbound i $$ fst x = snd x" 
       
  2413       "i = l \<inter> {x. c \<le> x $$ k}" "l \<in> d" "l \<inter> {x. c \<le> x $$ k} \<noteq> {}" and fstx:"fst x < DIM('a)"
       
  2414     from assm(4)[OF this(5)] guess u v apply-by(erule exE)+ note l=this
       
  2415     have *:"\<forall>i<DIM('a). ((\<chi>\<chi> i. if i = k then max (u $$ k) c else u $$ i)::'a) $$ i \<le> v $$ i"
       
  2416       using as(6) unfolding l interval_split[OF k] interval_ne_empty as .
       
  2417     have **:"\<forall>i<DIM('a). u$$i \<le> v$$i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
       
  2418     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>
       
  2419       interval_upperbound i $$ fst x = snd x)"
       
  2420       using as(1-3,5) unfolding l interval_split[OF k] interval_ne_empty as interval_bounds[OF *] apply-
       
  2421       apply rule defer apply(rule,assumption) apply(rule_tac x="{u..v}" in bexI) unfolding interval_bounds[OF **]
       
  2422       apply(case_tac[!] "fst x = k") using assms fstx apply-  by(auto simp add:euclidean_lambda_beta'[OF k]) qed qed
       
  2423 
  2341 
  2424 lemma division_points_psubset: fixes a::"'a::ordered_euclidean_space"
  2342 lemma division_points_psubset: fixes a::"'a::ordered_euclidean_space"
  2425   assumes "d division_of {a..b}"  "\<forall>i<DIM('a). a$$i < b$$i"  "a$$k < c" "c < b$$k"
  2343   assumes "d division_of {a..b}"  "\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i"  "a\<bullet>k < c" "c < b\<bullet>k"
  2426   "l \<in> d" "interval_lowerbound l$$k = c \<or> interval_upperbound l$$k = c" and k:"k<DIM('a)"
  2344   "l \<in> d" "interval_lowerbound l\<bullet>k = c \<or> interval_upperbound l\<bullet>k = c" and k:"k\<in>Basis"
  2427   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> {}}
  2345   shows "division_points ({a..b} \<inter> {x. x\<bullet>k \<le> c}) {l \<inter> {x. x\<bullet>k \<le> c} | l. l\<in>d \<and> l \<inter> {x. x\<bullet>k \<le> c} \<noteq> {}}
  2428               \<subset> division_points ({a..b}) d" (is "?D1 \<subset> ?D") 
  2346               \<subset> division_points ({a..b}) d" (is "?D1 \<subset> ?D") 
  2429         "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> {}}
  2347         "division_points ({a..b} \<inter> {x. x\<bullet>k \<ge> c}) {l \<inter> {x. x\<bullet>k \<ge> c} | l. l\<in>d \<and> l \<inter> {x. x\<bullet>k \<ge> c} \<noteq> {}}
  2430               \<subset> division_points ({a..b}) d" (is "?D2 \<subset> ?D") 
  2348               \<subset> division_points ({a..b}) d" (is "?D2 \<subset> ?D") 
  2431 proof- have ab:"\<forall>i<DIM('a). a$$i \<le> b$$i" using assms(2) by(auto intro!:less_imp_le)
  2349 proof- have ab:"\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i" using assms(2) by(auto intro!:less_imp_le)
  2432   guess u v using division_ofD(4)[OF assms(1,5)] apply-by(erule exE)+ note l=this
  2350   guess u v using division_ofD(4)[OF assms(1,5)] apply-by(erule exE)+ note l=this
  2433   have uv:"\<forall>i<DIM('a). u$$i \<le> v$$i" "\<forall>i<DIM('a). a$$i \<le> u$$i \<and> v$$i \<le> b$$i"
  2351   have uv:"\<forall>i\<in>Basis. u\<bullet>i \<le> v\<bullet>i" "\<forall>i\<in>Basis. a\<bullet>i \<le> u\<bullet>i \<and> v\<bullet>i \<le> b\<bullet>i"
  2434     using division_ofD(2,2,3)[OF assms(1,5)] unfolding l interval_ne_empty
  2352     using division_ofD(2,2,3)[OF assms(1,5)] unfolding l interval_ne_empty
  2435     unfolding subset_eq apply- defer apply(erule_tac x=u in ballE, erule_tac x=v in ballE) unfolding mem_interval by auto
  2353     unfolding subset_eq apply- defer apply(erule_tac x=u in ballE, erule_tac x=v in ballE) unfolding mem_interval by auto
  2436   have *:"interval_upperbound ({a..b} \<inter> {x. x $$ k \<le> interval_upperbound l $$ k}) $$ k = interval_upperbound l $$ k"
  2354   have *:"interval_upperbound ({a..b} \<inter> {x. x \<bullet> k \<le> interval_upperbound l \<bullet> k}) \<bullet> k = interval_upperbound l \<bullet> k"
  2437          "interval_upperbound ({a..b} \<inter> {x. x $$ k \<le> interval_lowerbound l $$ k}) $$ k = interval_lowerbound l $$ k"
  2355          "interval_upperbound ({a..b} \<inter> {x. x \<bullet> k \<le> interval_lowerbound l \<bullet> k}) \<bullet> k = interval_lowerbound l \<bullet> k"
  2438     unfolding interval_split[OF k] apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  2356     unfolding interval_split[OF k] apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  2439     unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab k by auto
  2357     unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab k by auto
  2440   have "\<exists>x. x \<in> ?D - ?D1" using assms(2-) apply-apply(erule disjE)
  2358   have "\<exists>x. x \<in> ?D - ?D1" using assms(2-) apply-apply(erule disjE)
  2441     apply(rule_tac x="(k,(interval_lowerbound l)$$k)" in exI) defer
  2359     apply(rule_tac x="(k,(interval_lowerbound l)\<bullet>k)" in exI) defer
  2442     apply(rule_tac x="(k,(interval_upperbound l)$$k)" in exI)
  2360     apply(rule_tac x="(k,(interval_upperbound l)\<bullet>k)" in exI)
  2443     unfolding division_points_def unfolding interval_bounds[OF ab] by(auto simp add:*) 
  2361     unfolding division_points_def unfolding interval_bounds[OF ab] by(auto simp add:*) 
  2444   thus "?D1 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4)]) using k by auto
  2362   thus "?D1 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4)]) using k by auto
  2445 
  2363 
  2446   have *:"interval_lowerbound ({a..b} \<inter> {x. x $$ k \<ge> interval_lowerbound l $$ k}) $$ k = interval_lowerbound l $$ k"
  2364   have *:"interval_lowerbound ({a..b} \<inter> {x. x \<bullet> k \<ge> interval_lowerbound l \<bullet> k}) \<bullet> k = interval_lowerbound l \<bullet> k"
  2447          "interval_lowerbound ({a..b} \<inter> {x. x $$ k \<ge> interval_upperbound l $$ k}) $$ k = interval_upperbound l $$ k"
  2365          "interval_lowerbound ({a..b} \<inter> {x. x \<bullet> k \<ge> interval_upperbound l \<bullet> k}) \<bullet> k = interval_upperbound l \<bullet> k"
  2448     unfolding interval_split[OF k] apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  2366     unfolding interval_split[OF k] apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  2449     unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab k by auto
  2367     unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab k by auto
  2450   have "\<exists>x. x \<in> ?D - ?D2" using assms(2-) apply-apply(erule disjE)
  2368   have "\<exists>x. x \<in> ?D - ?D2" using assms(2-) apply-apply(erule disjE)
  2451     apply(rule_tac x="(k,(interval_lowerbound l)$$k)" in exI) defer
  2369     apply(rule_tac x="(k,(interval_lowerbound l)\<bullet>k)" in exI) defer
  2452     apply(rule_tac x="(k,(interval_upperbound l)$$k)" in exI)
  2370     apply(rule_tac x="(k,(interval_upperbound l)\<bullet>k)" in exI)
  2453     unfolding division_points_def unfolding interval_bounds[OF ab] by(auto simp add:*) 
  2371     unfolding division_points_def unfolding interval_bounds[OF ab] by(auto simp add:*) 
  2454   thus "?D2 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4) k]) by auto qed
  2372   thus "?D2 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4) k]) by auto qed
  2455 
  2373 
  2456 subsection {* Preservation by divisions and tagged divisions. *}
  2374 subsection {* Preservation by divisions and tagged divisions. *}
  2457 
  2375 
  2546           then guess u v apply(drule_tac division_ofD(4)[OF goal1(4)]) by(erule exE)+
  2464           then guess u v apply(drule_tac division_ofD(4)[OF goal1(4)]) by(erule exE)+
  2547           thus "f x = neutral opp" using division_of_content_0[OF as goal1(4)] 
  2465           thus "f x = neutral opp" using division_of_content_0[OF as goal1(4)] 
  2548             using operativeD(1)[OF assms(2)] x by auto
  2466             using operativeD(1)[OF assms(2)] x by auto
  2549         qed qed }
  2467         qed qed }
  2550     assume "content {a..b} \<noteq> 0" note ab = this[unfolded content_lt_nz[THEN sym] content_pos_lt_eq]
  2468     assume "content {a..b} \<noteq> 0" note ab = this[unfolded content_lt_nz[THEN sym] content_pos_lt_eq]
  2551     hence ab':"\<forall>i<DIM('a). a$$i \<le> b$$i" by (auto intro!: less_imp_le) show ?case 
  2469     hence ab':"\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i" by (auto intro!: less_imp_le) show ?case 
  2552     proof(cases "division_points {a..b} d = {}")
  2470     proof(cases "division_points {a..b} d = {}")
  2553       case True have d':"\<forall>i\<in>d. \<exists>u v. i = {u..v} \<and>
  2471       case True have d':"\<forall>i\<in>d. \<exists>u v. i = {u..v} \<and>
  2554         (\<forall>j<DIM('a). 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)"
  2472         (\<forall>j\<in>Basis. u\<bullet>j = a\<bullet>j \<and> v\<bullet>j = a\<bullet>j \<or> u\<bullet>j = b\<bullet>j \<and> v\<bullet>j = b\<bullet>j \<or> u\<bullet>j = a\<bullet>j \<and> v\<bullet>j = b\<bullet>j)"
  2555         unfolding forall_in_division[OF goal1(4)] apply(rule,rule,rule)
  2473         unfolding forall_in_division[OF goal1(4)] apply(rule,rule,rule)
  2556         apply(rule_tac x=a in exI,rule_tac x=b in exI) apply(rule,rule refl) apply(rule,rule)
  2474         apply(rule_tac x=a in exI,rule_tac x=b in exI) apply(rule,rule refl)
  2557       proof- fix u v j assume j:"j<DIM('a)" assume as:"{u..v} \<in> d" note division_ofD(3)[OF goal1(4) this]
  2475       proof
  2558         hence uv:"\<forall>i<DIM('a). u$$i \<le> v$$i" "u$$j \<le> v$$j" using j unfolding interval_ne_empty by auto
  2476         fix u v and j :: 'a assume j:"j\<in>Basis" assume as:"{u..v} \<in> d" note division_ofD(3)[OF goal1(4) this]
  2559         have *:"\<And>p r Q. \<not> j<DIM('a) \<or> p \<or> r \<or> (\<forall>x\<in>d. Q x) \<Longrightarrow> p \<or> r \<or> (Q {u..v})" using as j by auto
  2477         hence uv:"\<forall>i\<in>Basis. u\<bullet>i \<le> v\<bullet>i" "u\<bullet>j \<le> v\<bullet>j" using j unfolding interval_ne_empty by auto
  2560         have "(j, u$$j) \<notin> division_points {a..b} d"
  2478         have *:"\<And>p r Q. \<not> j\<in>Basis \<or> p \<or> r \<or> (\<forall>x\<in>d. Q x) \<Longrightarrow> p \<or> r \<or> (Q {u..v})" using as j by auto
  2561           "(j, v$$j) \<notin> division_points {a..b} d" using True by auto
  2479         have "(j, u\<bullet>j) \<notin> division_points {a..b} d"
       
  2480           "(j, v\<bullet>j) \<notin> division_points {a..b} d" using True by auto
  2562         note this[unfolded de_Morgan_conj division_points_def mem_Collect_eq split_conv interval_bounds[OF ab'] bex_simps]
  2481         note this[unfolded de_Morgan_conj division_points_def mem_Collect_eq split_conv interval_bounds[OF ab'] bex_simps]
  2563         note *[OF this(1)] *[OF this(2)] note this[unfolded interval_bounds[OF uv(1)]]
  2482         note *[OF this(1)] *[OF this(2)] note this[unfolded interval_bounds[OF uv(1)]]
  2564         moreover have "a$$j \<le> u$$j" "v$$j \<le> b$$j" using division_ofD(2,2,3)[OF goal1(4) as] 
  2483         moreover have "a\<bullet>j \<le> u\<bullet>j" "v\<bullet>j \<le> b\<bullet>j" using division_ofD(2,2,3)[OF goal1(4) as] 
  2565           unfolding subset_eq apply- apply(erule_tac x=u in ballE,erule_tac[3] x=v in ballE)
  2484           unfolding subset_eq apply- apply(erule_tac x=u in ballE,erule_tac[3] x=v in ballE)
  2566           unfolding interval_ne_empty mem_interval using j by auto
  2485           unfolding interval_ne_empty mem_interval using j by auto
  2567         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"
  2486         ultimately show "u\<bullet>j = a\<bullet>j \<and> v\<bullet>j = a\<bullet>j \<or> u\<bullet>j = b\<bullet>j \<and> v\<bullet>j = b\<bullet>j \<or> u\<bullet>j = a\<bullet>j \<and> v\<bullet>j = b\<bullet>j"
  2568           unfolding not_less de_Morgan_disj using ab[rule_format,of j] uv(2) j by auto
  2487           unfolding not_less de_Morgan_disj using ab[rule_format,of j] uv(2) j by auto
  2569       qed have "(1/2) *\<^sub>R (a+b) \<in> {a..b}" unfolding mem_interval using ab by(auto intro!:less_imp_le)
  2488       qed
       
  2489       have "(1/2) *\<^sub>R (a+b) \<in> {a..b}"
       
  2490         unfolding mem_interval using ab by(auto intro!: less_imp_le simp: inner_simps)
  2570       note this[unfolded division_ofD(6)[OF goal1(4),THEN sym] Union_iff]
  2491       note this[unfolded division_ofD(6)[OF goal1(4),THEN sym] Union_iff]
  2571       then guess i .. note i=this guess u v using d'[rule_format,OF i(1)] apply-by(erule exE conjE)+ note uv=this
  2492       then guess i .. note i=this guess u v using d'[rule_format,OF i(1)] apply-by(erule exE conjE)+ note uv=this
  2572       have "{a..b} \<in> d"
  2493       have "{a..b} \<in> d"
  2573       proof- { presume "i = {a..b}" thus ?thesis using i by auto }
  2494       proof- { presume "i = {a..b}" thus ?thesis using i by auto }
  2574         { presume "u = a" "v = b" thus "i = {a..b}" using uv by auto }
  2495         { presume "u = a" "v = b" thus "i = {a..b}" using uv by auto }
  2575         show "u = a" "v = b" unfolding euclidean_eq[where 'a='a]
  2496         show "u = a" "v = b" unfolding euclidean_eq_iff[where 'a='a]
  2576         proof(safe) fix j assume j:"j<DIM('a)" note i(2)[unfolded uv mem_interval,rule_format,of j]
  2497         proof(safe)
  2577           thus "u $$ j = a $$ j" "v $$ j = b $$ j" using uv(2)[rule_format,of j] j by auto
  2498           fix j :: 'a assume j:"j\<in>Basis"
       
  2499           note i(2)[unfolded uv mem_interval,rule_format,of j]
       
  2500           thus "u \<bullet> j = a \<bullet> j" "v \<bullet> j = b \<bullet> j" using uv(2)[rule_format,of j] j by (auto simp: inner_simps)
  2578         qed qed
  2501         qed qed
  2579       hence *:"d = insert {a..b} (d - {{a..b}})" by auto
  2502       hence *:"d = insert {a..b} (d - {{a..b}})" by auto
  2580       have "iterate opp (d - {{a..b}}) f = neutral opp" apply(rule iterate_eq_neutral[OF goal1(2)])
  2503       have "iterate opp (d - {{a..b}}) f = neutral opp" apply(rule iterate_eq_neutral[OF goal1(2)])
  2581       proof fix x assume x:"x \<in> d - {{a..b}}" hence "x\<in>d" by auto note d'[rule_format,OF this]
  2504       proof fix x assume x:"x \<in> d - {{a..b}}" hence "x\<in>d" by auto note d'[rule_format,OF this]
  2582         then guess u v apply-by(erule exE conjE)+ note uv=this
  2505         then guess u v apply-by(erule exE conjE)+ note uv=this
  2583         have "u\<noteq>a \<or> v\<noteq>b" using x[unfolded uv] by auto  
  2506         have "u\<noteq>a \<or> v\<noteq>b" using x[unfolded uv] by auto  
  2584         then obtain j where "u$$j \<noteq> a$$j \<or> v$$j \<noteq> b$$j" and j:"j<DIM('a)" unfolding euclidean_eq[where 'a='a] by auto
  2507         then obtain j where "u\<bullet>j \<noteq> a\<bullet>j \<or> v\<bullet>j \<noteq> b\<bullet>j" and j:"j\<in>Basis" unfolding euclidean_eq_iff[where 'a='a] by auto
  2585         hence "u$$j = v$$j" using uv(2)[rule_format,OF j] by auto
  2508         hence "u\<bullet>j = v\<bullet>j" using uv(2)[rule_format,OF j] by auto
  2586         hence "content {u..v} = 0"  unfolding content_eq_0 apply(rule_tac x=j in exI) using j by auto
  2509         hence "content {u..v} = 0"  unfolding content_eq_0 apply(rule_tac x=j in bexI) using j by auto
  2587         thus "f x = neutral opp" unfolding uv(1) by(rule operativeD(1)[OF goal1(3)])
  2510         thus "f x = neutral opp" unfolding uv(1) by(rule operativeD(1)[OF goal1(3)])
  2588       qed thus "iterate opp d f = f {a..b}" apply-apply(subst *) 
  2511       qed thus "iterate opp d f = f {a..b}" apply-apply(subst *) 
  2589         apply(subst iterate_insert[OF goal1(2)]) using goal1(2,4) by auto
  2512         apply(subst iterate_insert[OF goal1(2)]) using goal1(2,4) by auto
  2590     next case False hence "\<exists>x. x\<in>division_points {a..b} d" by auto
  2513     next case False hence "\<exists>x. x\<in>division_points {a..b} d" by auto
  2591       then guess k c unfolding split_paired_Ex apply- unfolding division_points_def mem_Collect_eq split_conv
  2514       then guess k c unfolding split_paired_Ex apply- unfolding division_points_def mem_Collect_eq split_conv
  2592         by(erule exE conjE)+ note this(2-4,1) note kc=this[unfolded interval_bounds[OF ab']]
  2515         by(erule exE conjE)+ note this(2-4,1) note kc=this[unfolded interval_bounds[OF ab']]
  2593       from this(3) guess j .. note j=this
  2516       from this(3) guess j .. note j=this
  2594       def d1 \<equiv> "{l \<inter> {x. x$$k \<le> c} | l. l \<in> d \<and> l \<inter> {x. x$$k \<le> c} \<noteq> {}}"
  2517       def d1 \<equiv> "{l \<inter> {x. x\<bullet>k \<le> c} | l. l \<in> d \<and> l \<inter> {x. x\<bullet>k \<le> c} \<noteq> {}}"
  2595       def d2 \<equiv> "{l \<inter> {x. x$$k \<ge> c} | l. l \<in> d \<and> l \<inter> {x. x$$k \<ge> c} \<noteq> {}}"
  2518       def d2 \<equiv> "{l \<inter> {x. x\<bullet>k \<ge> c} | l. l \<in> d \<and> l \<inter> {x. x\<bullet>k \<ge> c} \<noteq> {}}"
  2596       def cb \<equiv> "(\<chi>\<chi> i. if i = k then c else b$$i)::'a" and ca \<equiv> "(\<chi>\<chi> i. if i = k then c else a$$i)::'a"
  2519       def cb \<equiv> "(\<Sum>i\<in>Basis. (if i = k then c else b\<bullet>i) *\<^sub>R i)::'a"
       
  2520       def ca \<equiv> "(\<Sum>i\<in>Basis. (if i = k then c else a\<bullet>i) *\<^sub>R i)::'a"
  2597       note division_points_psubset[OF goal1(4) ab kc(1-2) j]
  2521       note division_points_psubset[OF goal1(4) ab kc(1-2) j]
  2598       note psubset_card_mono[OF _ this(1)] psubset_card_mono[OF _ this(2)]
  2522       note psubset_card_mono[OF _ this(1)] psubset_card_mono[OF _ this(2)]
  2599       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})"
  2523       hence *:"(iterate opp d1 f) = f ({a..b} \<inter> {x. x\<bullet>k \<le> c})" "(iterate opp d2 f) = f ({a..b} \<inter> {x. x\<bullet>k \<ge> c})"
  2600         apply- unfolding interval_split[OF kc(4)] apply(rule_tac[!] goal1(1)[rule_format])
  2524         apply- unfolding interval_split[OF kc(4)] apply(rule_tac[!] goal1(1)[rule_format])
  2601         using division_split[OF goal1(4), where k=k and c=c]
  2525         using division_split[OF goal1(4), where k=k and c=c]
  2602         unfolding interval_split[OF kc(4)] d1_def[symmetric] d2_def[symmetric] unfolding goal1(2) Suc_le_mono
  2526         unfolding interval_split[OF kc(4)] d1_def[symmetric] d2_def[symmetric] unfolding goal1(2) Suc_le_mono
  2603         using goal1(2-3) using division_points_finite[OF goal1(4)] using kc(4) by auto
  2527         using goal1(2-3) using division_points_finite[OF goal1(4)] using kc(4) by auto
  2604       have "f {a..b} = opp (iterate opp d1 f) (iterate opp d2 f)" (is "_ = ?prev")
  2528       have "f {a..b} = opp (iterate opp d1 f) (iterate opp d2 f)" (is "_ = ?prev")
  2605         unfolding * apply(rule operativeD(2)) using goal1(3) using kc(4) by auto 
  2529         unfolding * apply(rule operativeD(2)) using goal1(3) using kc(4) by auto 
  2606       also have "iterate opp d1 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x$$k \<le> c}))"
  2530       also have "iterate opp d1 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x\<bullet>k \<le> c}))"
  2607         unfolding d1_def apply(rule iterate_nonzero_image_lemma[unfolded o_def])
  2531         unfolding d1_def apply(rule iterate_nonzero_image_lemma[unfolded o_def])
  2608         unfolding empty_as_interval apply(rule goal1 division_of_finite operativeD[OF goal1(3)])+
  2532         unfolding empty_as_interval apply(rule goal1 division_of_finite operativeD[OF goal1(3)])+
  2609         unfolding empty_as_interval[THEN sym] apply(rule content_empty)
  2533         unfolding empty_as_interval[THEN sym] apply(rule content_empty)
  2610       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" 
  2534       proof(rule,rule,rule,erule conjE) fix l y assume as:"l \<in> d" "y \<in> d" "l \<inter> {x. x \<bullet> k \<le> c} = y \<inter> {x. x \<bullet> k \<le> c}" "l \<noteq> y" 
  2611         from division_ofD(4)[OF goal1(4) this(1)] guess u v apply-by(erule exE)+ note l=this
  2535         from division_ofD(4)[OF goal1(4) this(1)] guess u v apply-by(erule exE)+ note l=this
  2612         show "f (l \<inter> {x. x $$ k \<le> c}) = neutral opp" unfolding l interval_split[OF kc(4)] 
  2536         show "f (l \<inter> {x. x \<bullet> k \<le> c}) = neutral opp" unfolding l interval_split[OF kc(4)] 
  2613           apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym,OF kc(4)] apply(rule division_split_left_inj)
  2537           apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym,OF kc(4)] apply(rule division_split_left_inj)
  2614           apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule kc(4) as)+
  2538           apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule kc(4) as)+
  2615       qed also have "iterate opp d2 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x$$k \<ge> c}))"
  2539       qed also have "iterate opp d2 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x\<bullet>k \<ge> c}))"
  2616         unfolding d2_def apply(rule iterate_nonzero_image_lemma[unfolded o_def])
  2540         unfolding d2_def apply(rule iterate_nonzero_image_lemma[unfolded o_def])
  2617         unfolding empty_as_interval apply(rule goal1 division_of_finite operativeD[OF goal1(3)])+
  2541         unfolding empty_as_interval apply(rule goal1 division_of_finite operativeD[OF goal1(3)])+
  2618         unfolding empty_as_interval[THEN sym] apply(rule content_empty)
  2542         unfolding empty_as_interval[THEN sym] apply(rule content_empty)
  2619       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" 
  2543       proof(rule,rule,rule,erule conjE) fix l y assume as:"l \<in> d" "y \<in> d" "l \<inter> {x. c \<le> x \<bullet> k} = y \<inter> {x. c \<le> x \<bullet> k}" "l \<noteq> y" 
  2620         from division_ofD(4)[OF goal1(4) this(1)] guess u v apply-by(erule exE)+ note l=this
  2544         from division_ofD(4)[OF goal1(4) this(1)] guess u v apply-by(erule exE)+ note l=this
  2621         show "f (l \<inter> {x. x $$ k \<ge> c}) = neutral opp" unfolding l interval_split[OF kc(4)] 
  2545         show "f (l \<inter> {x. x \<bullet> k \<ge> c}) = neutral opp" unfolding l interval_split[OF kc(4)] 
  2622           apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym,OF kc(4)] apply(rule division_split_right_inj)
  2546           apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym,OF kc(4)] apply(rule division_split_right_inj)
  2623           apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule as kc(4))+
  2547           apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule as kc(4))+
  2624       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}))"
  2548       qed also have *:"\<forall>x\<in>d. f x = opp (f (x \<inter> {x. x \<bullet> k \<le> c})) (f (x \<inter> {x. c \<le> x \<bullet> k}))"
  2625         unfolding forall_in_division[OF goal1(4)] apply(rule,rule,rule,rule operativeD(2)) using goal1(3) kc by auto 
  2549         unfolding forall_in_division[OF goal1(4)] apply(rule,rule,rule,rule operativeD(2)) using goal1(3) kc by auto 
  2626       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})))
  2550       have "opp (iterate opp d (\<lambda>l. f (l \<inter> {x. x \<bullet> k \<le> c}))) (iterate opp d (\<lambda>l. f (l \<inter> {x. c \<le> x \<bullet> k})))
  2627         = iterate opp d f" apply(subst(3) iterate_eq[OF _ *[rule_format]]) prefer 3
  2551         = iterate opp d f" apply(subst(3) iterate_eq[OF _ *[rule_format]]) prefer 3
  2628         apply(rule iterate_op[THEN sym]) using goal1 by auto
  2552         apply(rule iterate_op[THEN sym]) using goal1 by auto
  2629       finally show ?thesis by auto
  2553       finally show ?thesis by auto
  2630     qed qed qed 
  2554     qed qed qed 
  2631 
  2555 
  2752   qed show False using d(2)[OF conjI[OF p]] *[OF rsum_bound[OF p(1) assms(3)]] by auto qed
  2676   qed show False using d(2)[OF conjI[OF p]] *[OF rsum_bound[OF p(1) assms(3)]] by auto qed
  2753 
  2677 
  2754 subsection {* Similar theorems about relationship among components. *}
  2678 subsection {* Similar theorems about relationship among components. *}
  2755 
  2679 
  2756 lemma rsum_component_le: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2680 lemma rsum_component_le: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2757   assumes "p tagged_division_of {a..b}"  "\<forall>x\<in>{a..b}. (f x)$$i \<le> (g x)$$i"
  2681   assumes "p tagged_division_of {a..b}"  "\<forall>x\<in>{a..b}. (f x)\<bullet>i \<le> (g x)\<bullet>i"
  2758   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"
  2682   shows "(setsum (\<lambda>(x,k). content k *\<^sub>R f x) p)\<bullet>i \<le> (setsum (\<lambda>(x,k). content k *\<^sub>R g x) p)\<bullet>i"
  2759   unfolding  euclidean_component_setsum apply(rule setsum_mono) apply safe
  2683   unfolding inner_setsum_left apply(rule setsum_mono) apply safe
  2760 proof- fix a b assume ab:"(a,b) \<in> p" note assm = tagged_division_ofD(2-4)[OF assms(1) ab]
  2684 proof- fix a b assume ab:"(a,b) \<in> p" note assm = tagged_division_ofD(2-4)[OF assms(1) ab]
  2761   from this(3) guess u v apply-by(erule exE)+ note b=this
  2685   from this(3) guess u v apply-by(erule exE)+ note b=this
  2762   show "(content b *\<^sub>R f a) $$ i \<le> (content b *\<^sub>R g a) $$ i" unfolding b
  2686   show "(content b *\<^sub>R f a) \<bullet> i \<le> (content b *\<^sub>R g a) \<bullet> i" unfolding b
  2763     unfolding euclidean_simps real_scaleR_def apply(rule mult_left_mono)
  2687     unfolding inner_simps real_scaleR_def apply(rule mult_left_mono)
  2764     defer apply(rule content_pos_le,rule assms(2)[rule_format]) using assm by auto qed
  2688     defer apply(rule content_pos_le,rule assms(2)[rule_format]) using assm by auto qed
  2765 
  2689 
  2766 lemma has_integral_component_le: fixes f g::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2690 lemma has_integral_component_le:
  2767   assumes "(f has_integral i) s" "(g has_integral j) s"  "\<forall>x\<in>s. (f x)$$k \<le> (g x)$$k"
  2691   fixes f g::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2768   shows "i$$k \<le> j$$k"
  2692   assumes k: "k \<in> Basis"
       
  2693   assumes "(f has_integral i) s" "(g has_integral j) s"  "\<forall>x\<in>s. (f x)\<bullet>k \<le> (g x)\<bullet>k"
       
  2694   shows "i\<bullet>k \<le> j\<bullet>k"
  2769 proof -
  2695 proof -
  2770   have lem:"\<And>a b i (j::'b). \<And>g f::'a \<Rightarrow> 'b. (f has_integral i) ({a..b}) \<Longrightarrow> 
  2696   have lem:"\<And>a b i (j::'b). \<And>g f::'a \<Rightarrow> 'b. (f has_integral i) ({a..b}) \<Longrightarrow> 
  2771     (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"
  2697     (g has_integral j) ({a..b}) \<Longrightarrow> \<forall>x\<in>{a..b}. (f x)\<bullet>k \<le> (g x)\<bullet>k \<Longrightarrow> i\<bullet>k \<le> j\<bullet>k"
  2772   proof (rule ccontr)
  2698   proof (rule ccontr)
  2773     case goal1
  2699     case goal1
  2774     then have *: "0 < (i$$k - j$$k) / 3" by auto
  2700     then have *: "0 < (i\<bullet>k - j\<bullet>k) / 3" by auto
  2775     guess d1 using goal1(1)[unfolded has_integral,rule_format,OF *] apply-by(erule exE conjE)+ note d1=this[rule_format]
  2701     guess d1 using goal1(1)[unfolded has_integral,rule_format,OF *] apply-by(erule exE conjE)+ note d1=this[rule_format]
  2776     guess d2 using goal1(2)[unfolded has_integral,rule_format,OF *] apply-by(erule exE conjE)+ note d2=this[rule_format]
  2702     guess d2 using goal1(2)[unfolded has_integral,rule_format,OF *] apply-by(erule exE conjE)+ note d2=this[rule_format]
  2777     guess p using fine_division_exists[OF gauge_inter[OF d1(1) d2(1)], of a b] unfolding fine_inter .
  2703     guess p using fine_division_exists[OF gauge_inter[OF d1(1) d2(1)], of a b] unfolding fine_inter .
  2778     note p = this(1) conjunctD2[OF this(2)]  note le_less_trans[OF component_le_norm, of _ _ k] term g
  2704     note p = this(1) conjunctD2[OF this(2)]
       
  2705     note le_less_trans[OF Basis_le_norm[OF k]]
  2779     note this[OF d1(2)[OF conjI[OF p(1,2)]]] this[OF d2(2)[OF conjI[OF p(1,3)]]]
  2706     note this[OF d1(2)[OF conjI[OF p(1,2)]]] this[OF d2(2)[OF conjI[OF p(1,3)]]]
  2780     thus False
  2707     thus False
  2781       unfolding euclidean_simps
  2708       unfolding inner_simps
  2782       using rsum_component_le[OF p(1) goal1(3)]
  2709       using rsum_component_le[OF p(1) goal1(3)]
  2783       by (simp add: abs_real_def split: split_if_asm)
  2710       by (simp add: abs_real_def split: split_if_asm)
  2784   qed let ?P = "\<exists>a b. s = {a..b}"
  2711   qed let ?P = "\<exists>a b. s = {a..b}"
  2785   { presume "\<not> ?P \<Longrightarrow> ?thesis" thus ?thesis proof(cases ?P)
  2712   { presume "\<not> ?P \<Longrightarrow> ?thesis" thus ?thesis proof(cases ?P)
  2786       case True then guess a b apply-by(erule exE)+ note s=this
  2713       case True then guess a b apply-by(erule exE)+ note s=this
  2787       show ?thesis apply(rule lem) using assms[unfolded s] by auto
  2714       show ?thesis apply(rule lem) using assms[unfolded s] by auto
  2788     qed auto } assume as:"\<not> ?P"
  2715     qed auto } assume as:"\<not> ?P"
  2789   { presume "\<not> ?thesis \<Longrightarrow> False" thus ?thesis by auto }
  2716   { presume "\<not> ?thesis \<Longrightarrow> False" thus ?thesis by auto }
  2790   assume "\<not> i$$k \<le> j$$k" hence ij:"(i$$k - j$$k) / 3 > 0" by auto
  2717   assume "\<not> i\<bullet>k \<le> j\<bullet>k" hence ij:"(i\<bullet>k - j\<bullet>k) / 3 > 0" by auto
  2791   note has_integral_altD[OF _ as this] from this[OF assms(1)] this[OF assms(2)] guess B1 B2 . note B=this[rule_format]
  2718   note has_integral_altD[OF _ as this]
       
  2719   from this[OF assms(2)] this[OF assms(3)] guess B1 B2 . note B=this[rule_format]
  2792   have "bounded (ball 0 B1 \<union> ball (0::'a) B2)" unfolding bounded_Un by(rule conjI bounded_ball)+
  2720   have "bounded (ball 0 B1 \<union> ball (0::'a) B2)" unfolding bounded_Un by(rule conjI bounded_ball)+
  2793   from bounded_subset_closed_interval[OF this] guess a b apply- by(erule exE)+
  2721   from bounded_subset_closed_interval[OF this] guess a b apply- by(erule exE)+
  2794   note ab = conjunctD2[OF this[unfolded Un_subset_iff]]
  2722   note ab = conjunctD2[OF this[unfolded Un_subset_iff]]
  2795   guess w1 using B(2)[OF ab(1)] .. note w1=conjunctD2[OF this]
  2723   guess w1 using B(2)[OF ab(1)] .. note w1=conjunctD2[OF this]
  2796   guess w2 using B(4)[OF ab(2)] .. note w2=conjunctD2[OF this]
  2724   guess w2 using B(4)[OF ab(2)] .. note w2=conjunctD2[OF this]
  2797   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"
  2725   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"
  2798     by (simp add: abs_real_def split: split_if_asm)
  2726     by (simp add: abs_real_def split: split_if_asm)
  2799   note le_less_trans[OF component_le_norm[of _ k]] note this[OF w1(2)] this[OF w2(2)] moreover
  2727   note le_less_trans[OF Basis_le_norm[OF k]] note this[OF w1(2)] this[OF w2(2)] moreover
  2800   have "w1$$k \<le> w2$$k" apply(rule lem[OF w1(1) w2(1)]) using assms by auto ultimately
  2728   have "w1\<bullet>k \<le> w2\<bullet>k" apply(rule lem[OF w1(1) w2(1)]) using assms by auto ultimately
  2801   show False unfolding euclidean_simps by(rule *) qed
  2729   show False unfolding inner_simps by(rule *)
       
  2730 qed
  2802 
  2731 
  2803 lemma integral_component_le: fixes g f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2732 lemma integral_component_le: fixes g f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2804   assumes "f integrable_on s" "g integrable_on s"  "\<forall>x\<in>s. (f x)$$k \<le> (g x)$$k"
  2733   assumes "k\<in>Basis" "f integrable_on s" "g integrable_on s"  "\<forall>x\<in>s. (f x)\<bullet>k \<le> (g x)\<bullet>k"
  2805   shows "(integral s f)$$k \<le> (integral s g)$$k"
  2734   shows "(integral s f)\<bullet>k \<le> (integral s g)\<bullet>k"
  2806   apply(rule has_integral_component_le) using integrable_integral assms by auto
  2735   apply(rule has_integral_component_le) using integrable_integral assms by auto
  2807 
  2736 
  2808 (*lemma has_integral_dest_vec1_le: fixes f::"'a::ordered_euclidean_space \<Rightarrow> real^1"
       
  2809   assumes "(f has_integral i) s"  "(g has_integral j) s" "\<forall>x\<in>s. f x \<le> g x"
       
  2810   shows "dest_vec1 i \<le> dest_vec1 j" apply(rule has_integral_component_le[OF assms(1-2)])
       
  2811   using assms(3) unfolding vector_le_def by auto
       
  2812 
       
  2813 lemma integral_dest_vec1_le: fixes f::"real^'n \<Rightarrow> real^1"
       
  2814   assumes "f integrable_on s" "g integrable_on s" "\<forall>x\<in>s. f x \<le> g x"
       
  2815   shows "dest_vec1(integral s f) \<le> dest_vec1(integral s g)"
       
  2816   apply(rule has_integral_dest_vec1_le) apply(rule_tac[1-2] integrable_integral) using assms by auto*)
       
  2817 
       
  2818 lemma has_integral_component_nonneg: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2737 lemma has_integral_component_nonneg: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2819   assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> (f x)$$k" shows "0 \<le> i$$k" 
  2738   assumes "k\<in>Basis" "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> (f x)\<bullet>k" shows "0 \<le> i\<bullet>k" 
  2820   using has_integral_component_le[OF has_integral_0 assms(1)] using assms(2-) by auto
  2739   using has_integral_component_le[OF assms(1) has_integral_0 assms(2)] using assms(3-) by auto
  2821 
  2740 
  2822 lemma integral_component_nonneg: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2741 lemma integral_component_nonneg: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  2823   assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> (f x)$$k" shows "0 \<le> (integral s f)$$k"
  2742   assumes "k\<in>Basis" "f integrable_on s" "\<forall>x\<in>s. 0 \<le> (f x)\<bullet>k" shows "0 \<le> (integral s f)\<bullet>k"
  2824   apply(rule has_integral_component_nonneg) using assms by auto
  2743   apply(rule has_integral_component_nonneg) using assms by auto
  2825 
  2744 
  2826 (*lemma has_integral_dest_vec1_nonneg: fixes f::"real^'n \<Rightarrow> real^1"
       
  2827   assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> i"
       
  2828   using has_integral_component_nonneg[OF assms(1), of 1]
       
  2829   using assms(2) unfolding vector_le_def by auto
       
  2830 
       
  2831 lemma integral_dest_vec1_nonneg: fixes f::"real^'n \<Rightarrow> real^1"
       
  2832   assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> integral s f"
       
  2833   apply(rule has_integral_dest_vec1_nonneg) using assms by auto*)
       
  2834 
       
  2835 lemma has_integral_component_neg: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::ordered_euclidean_space"
  2745 lemma has_integral_component_neg: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::ordered_euclidean_space"
  2836   assumes "(f has_integral i) s" "\<forall>x\<in>s. (f x)$$k \<le> 0"shows "i$$k \<le> 0" 
  2746   assumes "k\<in>Basis" "(f has_integral i) s" "\<forall>x\<in>s. (f x)\<bullet>k \<le> 0"shows "i\<bullet>k \<le> 0" 
  2837   using has_integral_component_le[OF assms(1) has_integral_0] assms(2-) by auto
  2747   using has_integral_component_le[OF assms(1,2) has_integral_0] assms(2-) by auto
  2838 
  2748 
  2839 (*lemma has_integral_dest_vec1_neg: fixes f::"real^'n \<Rightarrow> real^1"
  2749 lemma has_integral_component_lbound:
  2840   assumes "(f has_integral i) s" "\<forall>x\<in>s. f x \<le> 0" shows "i \<le> 0"
  2750   fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  2841   using has_integral_component_neg[OF assms(1),of 1] using assms(2) by auto*)
  2751   assumes "(f has_integral i) {a..b}"  "\<forall>x\<in>{a..b}. B \<le> f(x)\<bullet>k" "k\<in>Basis"
  2842 
  2752   shows "B * content {a..b} \<le> i\<bullet>k"
  2843 lemma has_integral_component_lbound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  2753   using has_integral_component_le[OF assms(3) has_integral_const assms(1),of "(\<Sum>i\<in>Basis. B *\<^sub>R i)::'b"] assms(2-)
  2844   assumes "(f has_integral i) {a..b}"  "\<forall>x\<in>{a..b}. B \<le> f(x)$$k" "k<DIM('b)" shows "B * content {a..b} \<le> i$$k"
  2754   by (auto simp add:field_simps)
  2845   using has_integral_component_le[OF has_integral_const assms(1),of "(\<chi>\<chi> i. B)::'b" k] assms(2-)
  2755 
  2846   unfolding euclidean_simps euclidean_lambda_beta'[OF assms(3)] by(auto simp add:field_simps)
  2756 lemma has_integral_component_ubound:
  2847 
  2757   fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  2848 lemma has_integral_component_ubound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  2758   assumes "(f has_integral i) {a..b}" "\<forall>x\<in>{a..b}. f x\<bullet>k \<le> B" "k\<in>Basis"
  2849   assumes "(f has_integral i) {a..b}" "\<forall>x\<in>{a..b}. f x$$k \<le> B" "k<DIM('b)"
  2759   shows "i\<bullet>k \<le> B * content({a..b})"
  2850   shows "i$$k \<le> B * content({a..b})"
  2760   using has_integral_component_le[OF assms(3,1) has_integral_const, of "\<Sum>i\<in>Basis. B *\<^sub>R i"]  assms(2-)
  2851   using has_integral_component_le[OF assms(1) has_integral_const, of k "\<chi>\<chi> i. B"]
  2761   by(auto simp add:field_simps)
  2852   unfolding euclidean_simps euclidean_lambda_beta'[OF assms(3)] using assms(2) by(auto simp add:field_simps)
       
  2853 
  2762 
  2854 lemma integral_component_lbound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  2763 lemma integral_component_lbound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  2855   assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. B \<le> f(x)$$k" "k<DIM('b)"
  2764   assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. B \<le> f(x)\<bullet>k" "k\<in>Basis"
  2856   shows "B * content({a..b}) \<le> (integral({a..b}) f)$$k"
  2765   shows "B * content({a..b}) \<le> (integral({a..b}) f)\<bullet>k"
  2857   apply(rule has_integral_component_lbound) using assms unfolding has_integral_integral by auto
  2766   apply(rule has_integral_component_lbound) using assms unfolding has_integral_integral by auto
  2858 
  2767 
  2859 lemma integral_component_ubound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  2768 lemma integral_component_ubound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  2860   assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. f(x)$$k \<le> B" "k<DIM('b)" 
  2769   assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. f(x)\<bullet>k \<le> B" "k\<in>Basis" 
  2861   shows "(integral({a..b}) f)$$k \<le> B * content({a..b})"
  2770   shows "(integral({a..b}) f)\<bullet>k \<le> B * content({a..b})"
  2862   apply(rule has_integral_component_ubound) using assms unfolding has_integral_integral by auto
  2771   apply(rule has_integral_component_ubound) using assms unfolding has_integral_integral by auto
  2863 
  2772 
  2864 subsection {* Uniform limit of integrable functions is integrable. *}
  2773 subsection {* Uniform limit of integrable functions is integrable. *}
  2865 
  2774 
  2866 lemma integrable_uniform_limit: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  2775 lemma integrable_uniform_limit: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  2947   shows "setsum g {f x |x. x \<in> s \<and> f x \<noteq> a} = setsum (g o f) s"
  2856   shows "setsum g {f x |x. x \<in> s \<and> f x \<noteq> a} = setsum (g o f) s"
  2948   unfolding setsum_iterate[OF assms(1)] apply(subst setsum_iterate) defer
  2857   unfolding setsum_iterate[OF assms(1)] apply(subst setsum_iterate) defer
  2949   apply(rule iterate_nonzero_image_lemma) apply(rule assms monoidal_monoid)+
  2858   apply(rule iterate_nonzero_image_lemma) apply(rule assms monoidal_monoid)+
  2950   unfolding assms using neutral_add unfolding neutral_add using assms by auto 
  2859   unfolding assms using neutral_add unfolding neutral_add using assms by auto 
  2951 
  2860 
  2952 lemma interval_doublesplit:  fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)"
  2861 lemma interval_doublesplit:  fixes a::"'a::ordered_euclidean_space" assumes "k\<in>Basis"
  2953   shows "{a..b} \<inter> {x . abs(x$$k - c) \<le> (e::real)} = 
  2862   shows "{a..b} \<inter> {x . abs(x\<bullet>k - c) \<le> (e::real)} = 
  2954   {(\<chi>\<chi> i. if i = k then max (a$$k) (c - e) else a$$i) .. (\<chi>\<chi> i. if i = k then min (b$$k) (c + e) else b$$i)}"
  2863   {(\<Sum>i\<in>Basis. (if i = k then max (a\<bullet>k) (c - e) else a\<bullet>i) *\<^sub>R i) .. 
       
  2864    (\<Sum>i\<in>Basis. (if i = k then min (b\<bullet>k) (c + e) else b\<bullet>i) *\<^sub>R i)}"
  2955 proof- have *:"\<And>x c e::real. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  2865 proof- have *:"\<And>x c e::real. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  2956   have **:"\<And>s P Q. s \<inter> {x. P x \<and> Q x} = (s \<inter> {x. Q x}) \<inter> {x. P x}" by blast
  2866   have **:"\<And>s P Q. s \<inter> {x. P x \<and> Q x} = (s \<inter> {x. Q x}) \<inter> {x. P x}" by blast
  2957   show ?thesis unfolding * ** interval_split[OF assms] by(rule refl) qed
  2867   show ?thesis unfolding * ** interval_split[OF assms] by(rule refl) qed
  2958 
  2868 
  2959 lemma division_doublesplit: fixes a::"'a::ordered_euclidean_space" assumes "p division_of {a..b}" and k:"k<DIM('a)"
  2869 lemma division_doublesplit: fixes a::"'a::ordered_euclidean_space" assumes "p division_of {a..b}" and k:"k\<in>Basis"
  2960   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})"
  2870   shows "{l \<inter> {x. abs(x\<bullet>k - c) \<le> e} |l. l \<in> p \<and> l \<inter> {x. abs(x\<bullet>k - c) \<le> e} \<noteq> {}} division_of ({a..b} \<inter> {x. abs(x\<bullet>k - c) \<le> e})"
  2961 proof- have *:"\<And>x c. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  2871 proof- have *:"\<And>x c. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  2962   have **:"\<And>p q p' q'. p division_of q \<Longrightarrow> p = p' \<Longrightarrow> q = q' \<Longrightarrow> p' division_of q'" by auto
  2872   have **:"\<And>p q p' q'. p division_of q \<Longrightarrow> p = p' \<Longrightarrow> q = q' \<Longrightarrow> p' division_of q'" by auto
  2963   note division_split(1)[OF assms, where c="c+e",unfolded interval_split[OF k]]
  2873   note division_split(1)[OF assms, where c="c+e",unfolded interval_split[OF k]]
  2964   note division_split(2)[OF this, where c="c-e" and k=k,OF k] 
  2874   note division_split(2)[OF this, where c="c-e" and k=k,OF k] 
  2965   thus ?thesis apply(rule **) using k apply- unfolding interval_doublesplit unfolding * unfolding interval_split interval_doublesplit
  2875   thus ?thesis apply(rule **) using k apply- unfolding interval_doublesplit unfolding * unfolding interval_split interval_doublesplit
  2966     apply(rule set_eqI) unfolding mem_Collect_eq apply rule apply(erule conjE exE)+ apply(rule_tac x=la in exI) defer
  2876     apply(rule set_eqI) unfolding mem_Collect_eq apply rule apply(erule conjE exE)+ apply(rule_tac x=la in exI) defer
  2967     apply(erule conjE exE)+ apply(rule_tac x="l \<inter> {x. c + e \<ge> x $$ k}" in exI) apply rule defer apply rule
  2877     apply(erule conjE exE)+ apply(rule_tac x="l \<inter> {x. c + e \<ge> x \<bullet> k}" in exI) apply rule defer apply rule
  2968     apply(rule_tac x=l in exI) by blast+ qed
  2878     apply(rule_tac x=l in exI) by blast+ qed
  2969 
  2879 
  2970 lemma content_doublesplit: fixes a::"'a::ordered_euclidean_space" assumes "0 < e" and k:"k<DIM('a)"
  2880 lemma content_doublesplit: fixes a::"'a::ordered_euclidean_space" assumes "0 < e" and k:"k\<in>Basis"
  2971   obtains d where "0 < d" "content({a..b} \<inter> {x. abs(x$$k - c) \<le> d}) < e"
  2881   obtains d where "0 < d" "content({a..b} \<inter> {x. abs(x\<bullet>k - c) \<le> d}) < e"
  2972 proof(cases "content {a..b} = 0")
  2882 proof(cases "content {a..b} = 0")
  2973   case True show ?thesis apply(rule that[of 1]) defer unfolding interval_doublesplit[OF k]
  2883   case True show ?thesis apply(rule that[of 1]) defer unfolding interval_doublesplit[OF k]
  2974     apply(rule le_less_trans[OF content_subset]) defer apply(subst True)
  2884     apply(rule le_less_trans[OF content_subset]) defer apply(subst True)
  2975     unfolding interval_doublesplit[THEN sym,OF k] using assms by auto 
  2885     unfolding interval_doublesplit[THEN sym,OF k] using assms by auto 
  2976 next case False def d \<equiv> "e / 3 / setprod (\<lambda>i. b$$i - a$$i) ({..<DIM('a)} - {k})"
  2886 next case False def d \<equiv> "e / 3 / setprod (\<lambda>i. b\<bullet>i - a\<bullet>i) (Basis - {k})"
  2977   note False[unfolded content_eq_0 not_ex not_le, rule_format]
  2887   note False[unfolded content_eq_0 not_ex not_le, rule_format]
  2978   hence "\<And>x. x<DIM('a) \<Longrightarrow> b$$x > a$$x" by(auto simp add:not_le)
  2888   hence "\<And>x. x\<in>Basis \<Longrightarrow> b\<bullet>x > a\<bullet>x" by(auto simp add:not_le)
  2979   hence prod0:"0 < setprod (\<lambda>i. b$$i - a$$i) ({..<DIM('a)} - {k})" apply-apply(rule setprod_pos) by(auto simp add:field_simps)
  2889   hence prod0:"0 < setprod (\<lambda>i. b\<bullet>i - a\<bullet>i) (Basis - {k})" apply-apply(rule setprod_pos) by(auto simp add:field_simps)
  2980   hence "d > 0" unfolding d_def using assms by(auto simp add:field_simps) thus ?thesis
  2890   hence "d > 0" unfolding d_def using assms by(auto simp add:field_simps) thus ?thesis
  2981   proof(rule that[of d]) have *:"{..<DIM('a)} = insert k ({..<DIM('a)} - {k})" using k by auto
  2891   proof(rule that[of d]) have *:"Basis = insert k (Basis - {k})" using k by auto
  2982     have **:"{a..b} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d} \<noteq> {} \<Longrightarrow> 
  2892     have **:"{a..b} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} \<noteq> {} \<Longrightarrow> 
  2983       (\<Prod>i\<in>{..<DIM('a)} - {k}. interval_upperbound ({a..b} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) $$ i
  2893       (\<Prod>i\<in>Basis - {k}. interval_upperbound ({a..b} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) \<bullet> i
  2984       - interval_lowerbound ({a..b} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) $$ i)
  2894       - interval_lowerbound ({a..b} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) \<bullet> i)
  2985       = (\<Prod>i\<in>{..<DIM('a)} - {k}. b$$i - a$$i)" apply(rule setprod_cong,rule refl) 
  2895       = (\<Prod>i\<in>Basis - {k}. b\<bullet>i - a\<bullet>i)" apply(rule setprod_cong,rule refl) 
  2986       unfolding interval_doublesplit[OF k] apply(subst interval_bounds) defer apply(subst interval_bounds)
  2896       unfolding interval_doublesplit[OF k] apply(subst interval_bounds) defer apply(subst interval_bounds)
  2987       unfolding interval_eq_empty not_ex not_less by auto
  2897       unfolding interval_eq_empty not_ex not_less by auto
  2988     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)
  2898     show "content ({a..b} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) < e" apply(cases) unfolding content_def apply(subst if_P,assumption,rule assms)
  2989       unfolding if_not_P apply(subst *) apply(subst setprod_insert) unfolding **
  2899       unfolding if_not_P apply(subst *) apply(subst setprod_insert) unfolding **
  2990       unfolding interval_doublesplit[OF k] interval_eq_empty not_ex not_less prefer 3
  2900       unfolding interval_doublesplit[OF k] interval_eq_empty not_ex not_less prefer 3
  2991       apply(subst interval_bounds) defer apply(subst interval_bounds) unfolding euclidean_lambda_beta'[OF k] if_P[OF refl]
  2901       apply(subst interval_bounds) defer apply(subst interval_bounds)
  2992     proof- have "(min (b $$ k) (c + d) - max (a $$ k) (c - d)) \<le> 2 * d" by auto
  2902       apply (simp_all only: k inner_setsum_left_Basis simp_thms if_P cong: bex_cong ball_cong)
  2993       also have "... < e / (\<Prod>i\<in>{..<DIM('a)} - {k}. b $$ i - a $$ i)" unfolding d_def using assms prod0 by(auto simp add:field_simps)
  2903     proof -
  2994       finally show "(min (b $$ k) (c + d) - max (a $$ k) (c - d)) * (\<Prod>i\<in>{..<DIM('a)} - {k}. b $$ i - a $$ i) < e"
  2904       have "(min (b \<bullet> k) (c + d) - max (a \<bullet> k) (c - d)) \<le> 2 * d" by auto
  2995         unfolding pos_less_divide_eq[OF prod0] . qed auto qed qed
  2905       also have "... < e / (\<Prod>i\<in>Basis - {k}. b \<bullet> i - a \<bullet> i)" unfolding d_def using assms prod0 by(auto simp add:field_simps)
  2996 
  2906       finally show "(min (b \<bullet> k) (c + d) - max (a \<bullet> k) (c - d)) * (\<Prod>i\<in>Basis - {k}. b \<bullet> i - a \<bullet> i) < e"
  2997 lemma negligible_standard_hyperplane[intro]: fixes type::"'a::ordered_euclidean_space" assumes k:"k<DIM('a)"
  2907         unfolding pos_less_divide_eq[OF prod0] .
  2998   shows "negligible {x::'a. x$$k = (c::real)}" 
  2908     qed auto
       
  2909   qed
       
  2910 qed
       
  2911 
       
  2912 lemma negligible_standard_hyperplane[intro]: 
       
  2913   fixes k :: "'a::ordered_euclidean_space"
       
  2914   assumes k: "k \<in> Basis"
       
  2915   shows "negligible {x. x\<bullet>k = c}" 
  2999   unfolding negligible_def has_integral apply(rule,rule,rule,rule)
  2916   unfolding negligible_def has_integral apply(rule,rule,rule,rule)
  3000 proof-
  2917 proof-
  3001   case goal1 from content_doublesplit[OF this k,of a b c] guess d . note d=this
  2918   case goal1 from content_doublesplit[OF this k,of a b c] guess d . note d=this
  3002   let ?i = "indicator {x::'a. x$$k = c} :: 'a\<Rightarrow>real"
  2919   let ?i = "indicator {x::'a. x\<bullet>k = c} :: 'a\<Rightarrow>real"
  3003   show ?case apply(rule_tac x="\<lambda>x. ball x d" in exI) apply(rule,rule gauge_ball,rule d)
  2920   show ?case apply(rule_tac x="\<lambda>x. ball x d" in exI) apply(rule,rule gauge_ball,rule d)
  3004   proof(rule,rule) fix p assume p:"p tagged_division_of {a..b} \<and> (\<lambda>x. ball x d) fine p"
  2921   proof(rule,rule) fix p assume p:"p tagged_division_of {a..b} \<and> (\<lambda>x. ball x d) fine p"
  3005     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)"
  2922     have *:"(\<Sum>(x, ka)\<in>p. content ka *\<^sub>R ?i x) = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. abs(x\<bullet>k - c) \<le> d}) *\<^sub>R ?i x)"
  3006       apply(rule setsum_cong2) unfolding split_paired_all real_scaleR_def mult_cancel_right split_conv
  2923       apply(rule setsum_cong2) unfolding split_paired_all real_scaleR_def mult_cancel_right split_conv
  3007       apply(cases,rule disjI1,assumption,rule disjI2)
  2924       apply(cases,rule disjI1,assumption,rule disjI2)
  3008     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)
  2925     proof- fix x l assume as:"(x,l)\<in>p" "?i x \<noteq> 0" hence xk:"x\<bullet>k = c" unfolding indicator_def apply-by(rule ccontr,auto)
  3009       show "content l = content (l \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d})" apply(rule arg_cong[where f=content])
  2926       show "content l = content (l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})" apply(rule arg_cong[where f=content])
  3010         apply(rule set_eqI,rule,rule) unfolding mem_Collect_eq
  2927         apply(rule set_eqI,rule,rule) unfolding mem_Collect_eq
  3011       proof- fix y assume y:"y\<in>l" note p[THEN conjunct2,unfolded fine_def,rule_format,OF as(1),unfolded split_conv]
  2928       proof- fix y assume y:"y\<in>l" note p[THEN conjunct2,unfolded fine_def,rule_format,OF as(1),unfolded split_conv]
  3012         note this[unfolded subset_eq mem_ball dist_norm,rule_format,OF y] note le_less_trans[OF component_le_norm[of _ k] this]
  2929         note this[unfolded subset_eq mem_ball dist_norm,rule_format,OF y] note le_less_trans[OF Basis_le_norm[OF k] this]
  3013         thus "\<bar>y $$ k - c\<bar> \<le> d" unfolding euclidean_simps xk by auto
  2930         thus "\<bar>y \<bullet> k - c\<bar> \<le> d" unfolding inner_simps xk by auto
  3014       qed auto qed
  2931       qed auto qed
  3015     note p'= tagged_division_ofD[OF p[THEN conjunct1]] and p''=division_of_tagged_division[OF p[THEN conjunct1]]
  2932     note p'= tagged_division_ofD[OF p[THEN conjunct1]] and p''=division_of_tagged_division[OF p[THEN conjunct1]]
  3016     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
  2933     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
  3017       apply(subst abs_of_nonneg) apply(rule setsum_nonneg,rule) unfolding split_paired_all split_conv
  2934       apply(subst abs_of_nonneg) apply(rule setsum_nonneg,rule) unfolding split_paired_all split_conv
  3018       apply(rule mult_nonneg_nonneg) apply(drule p'(4)) apply(erule exE)+ apply(rule_tac b=b in back_subst)
  2935       apply(rule mult_nonneg_nonneg) apply(drule p'(4)) apply(erule exE)+ apply(rule_tac b=b in back_subst)
  3019       prefer 2 apply(subst(asm) eq_commute) apply assumption
  2936       prefer 2 apply(subst(asm) eq_commute) apply assumption
  3020       apply(subst interval_doublesplit[OF k]) apply(rule content_pos_le) apply(rule indicator_pos_le)
  2937       apply(subst interval_doublesplit[OF k]) apply(rule content_pos_le) apply(rule indicator_pos_le)
  3021     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}))"
  2938     proof- have "(\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) * ?i x) \<le> (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}))"
  3022         apply(rule setsum_mono) unfolding split_paired_all split_conv 
  2939         apply(rule setsum_mono) unfolding split_paired_all split_conv 
  3023         apply(rule mult_right_le_one_le) apply(drule p'(4)) by(auto simp add:interval_doublesplit[OF k])
  2940         apply(rule mult_right_le_one_le) apply(drule p'(4)) by(auto simp add:interval_doublesplit[OF k])
  3024       also have "... < e" apply(subst setsum_over_tagged_division_lemma[OF p[THEN conjunct1]])
  2941       also have "... < e" apply(subst setsum_over_tagged_division_lemma[OF p[THEN conjunct1]])
  3025       proof- case goal1 have "content ({u..v} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) \<le> content {u..v}"
  2942       proof- case goal1 have "content ({u..v} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) \<le> content {u..v}"
  3026           unfolding interval_doublesplit[OF k] apply(rule content_subset) unfolding interval_doublesplit[THEN sym,OF k] by auto
  2943           unfolding interval_doublesplit[OF k] apply(rule content_subset) unfolding interval_doublesplit[THEN sym,OF k] by auto
  3027         thus ?case unfolding goal1 unfolding interval_doublesplit[OF k]
  2944         thus ?case unfolding goal1 unfolding interval_doublesplit[OF k]
  3028           by (blast intro: antisym)
  2945           by (blast intro: antisym)
  3029       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"
  2946       next have *:"setsum content {l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} |l. l \<in> snd ` p \<and> l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} \<noteq> {}} \<ge> 0"
  3030           apply(rule setsum_nonneg,rule) unfolding mem_Collect_eq image_iff apply(erule exE bexE conjE)+ unfolding split_paired_all 
  2947           apply(rule setsum_nonneg,rule) unfolding mem_Collect_eq image_iff apply(erule exE bexE conjE)+ unfolding split_paired_all 
  3031         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)"
  2948         proof- fix x l a b assume as:"x = l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}" "(a, b) \<in> p" "l = snd (a, b)"
  3032           guess u v using p'(4)[OF as(2)] apply-by(erule exE)+ note * = this
  2949           guess u v using p'(4)[OF as(2)] apply-by(erule exE)+ note * = this
  3033           show "content x \<ge> 0" unfolding as snd_conv * interval_doublesplit[OF k] by(rule content_pos_le)
  2950           show "content x \<ge> 0" unfolding as snd_conv * interval_doublesplit[OF k] by(rule content_pos_le)
  3034         qed have **:"norm (1::real) \<le> 1" by auto note division_doublesplit[OF p'' k,unfolded interval_doublesplit[OF k]]
  2951         qed have **:"norm (1::real) \<le> 1" by auto note division_doublesplit[OF p'' k,unfolded interval_doublesplit[OF k]]
  3035         note dsum_bound[OF this **,unfolded interval_doublesplit[THEN sym,OF k]]
  2952         note dsum_bound[OF this **,unfolded interval_doublesplit[THEN sym,OF k]]
  3036         note this[unfolded real_scaleR_def real_norm_def mult_1_right mult_1, of c d] note le_less_trans[OF this d(2)]
  2953         note this[unfolded real_scaleR_def real_norm_def mult_1_right mult_1, of c d] note le_less_trans[OF this d(2)]
  3037         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"
  2954         from this[unfolded abs_of_nonneg[OF *]] show "(\<Sum>ka\<in>snd ` p. content (ka \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})) < e"
  3038           apply(subst vsum_nonzero_image_lemma[of "snd ` p" content "{}", unfolded o_def,THEN sym])
  2955           apply(subst vsum_nonzero_image_lemma[of "snd ` p" content "{}", unfolded o_def,THEN sym])
  3039           apply(rule finite_imageI p' content_empty)+ unfolding forall_in_division[OF p'']
  2956           apply(rule finite_imageI p' content_empty)+ unfolding forall_in_division[OF p'']
  3040         proof(rule,rule,rule,rule,rule,rule,rule,erule conjE) fix m n u v
  2957         proof(rule,rule,rule,rule,rule,rule,rule,erule conjE) fix m n u v
  3041           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}"
  2958           assume as:"{m..n} \<in> snd ` p" "{u..v} \<in> snd ` p" "{m..n} \<noteq> {u..v}"  "{m..n} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} = {u..v} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}"
  3042           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
  2959           have "({m..n} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) \<inter> ({u..v} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) \<subseteq> {m..n} \<inter> {u..v}" by blast
  3043           note interior_mono[OF this, unfolded division_ofD(5)[OF p'' as(1-3)] interior_inter[of "{m..n}"]]
  2960           note interior_mono[OF this, unfolded division_ofD(5)[OF p'' as(1-3)] interior_inter[of "{m..n}"]]
  3044           hence "interior ({m..n} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) = {}" unfolding as Int_absorb by auto
  2961           hence "interior ({m..n} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) = {}" unfolding as Int_absorb by auto
  3045           thus "content ({m..n} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) = 0" unfolding interval_doublesplit[OF k] content_eq_0_interior[THEN sym] .
  2962           thus "content ({m..n} \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) = 0" unfolding interval_doublesplit[OF k] content_eq_0_interior[THEN sym] .
  3046         qed qed
  2963         qed qed
  3047       finally show "(\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) * ?i x) < e" .
  2964       finally show "(\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) * ?i x) < e" .
  3048     qed qed qed
  2965     qed qed qed
  3049 
  2966 
  3050 subsection {* A technical lemma about "refinement" of division. *}
  2967 subsection {* A technical lemma about "refinement" of division. *}
  3051 
  2968 
  3052 lemma tagged_division_finer: fixes p::"(('a::ordered_euclidean_space) \<times> (('a::ordered_euclidean_space) set)) set"
  2969 lemma tagged_division_finer: fixes p::"(('a::ordered_euclidean_space) \<times> (('a::ordered_euclidean_space) set)) set"
  3222 
  3139 
  3223 lemma negligible_union_eq[simp]: "negligible (s \<union> t) \<longleftrightarrow> (negligible s \<and> negligible t)"
  3140 lemma negligible_union_eq[simp]: "negligible (s \<union> t) \<longleftrightarrow> (negligible s \<and> negligible t)"
  3224   using negligible_union by auto
  3141   using negligible_union by auto
  3225 
  3142 
  3226 lemma negligible_sing[intro]: "negligible {a::_::ordered_euclidean_space}" 
  3143 lemma negligible_sing[intro]: "negligible {a::_::ordered_euclidean_space}" 
  3227   using negligible_standard_hyperplane[of 0 "a$$0"] by auto 
  3144   using negligible_standard_hyperplane[OF SOME_Basis, of "a \<bullet> (SOME i. i \<in> Basis)"] by auto 
  3228 
  3145 
  3229 lemma negligible_insert[simp]: "negligible(insert a s) \<longleftrightarrow> negligible s"
  3146 lemma negligible_insert[simp]: "negligible(insert a s) \<longleftrightarrow> negligible s"
  3230   apply(subst insert_is_Un) unfolding negligible_union_eq by auto
  3147   apply(subst insert_is_Un) unfolding negligible_union_eq by auto
  3231 
  3148 
  3232 lemma negligible_empty[intro]: "negligible {}" by auto
  3149 lemma negligible_empty[intro]: "negligible {}" by auto
  3274   apply(rule has_integral_spike_finite) by auto
  3191   apply(rule has_integral_spike_finite) by auto
  3275 
  3192 
  3276 subsection {* In particular, the boundary of an interval is negligible. *}
  3193 subsection {* In particular, the boundary of an interval is negligible. *}
  3277 
  3194 
  3278 lemma negligible_frontier_interval: "negligible({a::'a::ordered_euclidean_space..b} - {a<..<b})"
  3195 lemma negligible_frontier_interval: "negligible({a::'a::ordered_euclidean_space..b} - {a<..<b})"
  3279 proof- let ?A = "\<Union>((\<lambda>k. {x. x$$k = a$$k} \<union> {x::'a. x$$k = b$$k}) ` {..<DIM('a)})"
  3196 proof-
  3280   have "{a..b} - {a<..<b} \<subseteq> ?A" apply rule unfolding Diff_iff mem_interval not_all
  3197   let ?A = "\<Union>((\<lambda>k. {x. x\<bullet>k = a\<bullet>k} \<union> {x::'a. x\<bullet>k = b\<bullet>k}) ` Basis)"
  3281     apply(erule conjE exE)+ apply(rule_tac X="{x. x $$ xa = a $$ xa} \<union> {x. x $$ xa = b $$ xa}" in UnionI)
  3198   have "{a..b} - {a<..<b} \<subseteq> ?A"
  3282     apply(erule_tac[!] x=xa in allE) by auto
  3199     apply rule unfolding Diff_iff mem_interval
  3283   thus ?thesis apply-apply(rule negligible_subset[of ?A]) apply(rule negligible_unions[OF finite_imageI]) by auto qed
  3200     apply simp
       
  3201     apply(erule conjE bexE)+
       
  3202     apply(rule_tac x=i in bexI)
       
  3203     by auto
       
  3204   thus ?thesis
       
  3205     apply-
       
  3206     apply(rule negligible_subset[of ?A])
       
  3207     apply(rule negligible_unions[OF finite_imageI])
       
  3208     by auto
       
  3209 qed
  3284 
  3210 
  3285 lemma has_integral_spike_interior:
  3211 lemma has_integral_spike_interior:
  3286   assumes "\<forall>x\<in>{a<..<b}. g x = f x" "(f has_integral y) ({a..b})" shows "(g has_integral y) ({a..b})"
  3212   assumes "\<forall>x\<in>{a<..<b}. g x = f x" "(f has_integral y) ({a..b})" shows "(g has_integral y) ({a..b})"
  3287   apply(rule has_integral_spike[OF negligible_frontier_interval _ assms(2)]) using assms(1) by auto
  3213   apply(rule has_integral_spike[OF negligible_frontier_interval _ assms(2)]) using assms(1) by auto
  3288 
  3214 
  3307   shows "(\<forall>i\<in>d. P i) \<longleftrightarrow> P {a..b}"
  3233   shows "(\<forall>i\<in>d. P i) \<longleftrightarrow> P {a..b}"
  3308   using operative_division[OF monoidal_and assms] division_of_finite[OF assms(2)] by auto
  3234   using operative_division[OF monoidal_and assms] division_of_finite[OF assms(2)] by auto
  3309 
  3235 
  3310 lemma operative_approximable: assumes "0 \<le> e" fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach"
  3236 lemma operative_approximable: assumes "0 \<le> e" fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach"
  3311   shows "operative op \<and> (\<lambda>i. \<exists>g. (\<forall>x\<in>i. norm (f x - g (x::'b)) \<le> e) \<and> g integrable_on i)" unfolding operative_def neutral_and
  3237   shows "operative op \<and> (\<lambda>i. \<exists>g. (\<forall>x\<in>i. norm (f x - g (x::'b)) \<le> e) \<and> g integrable_on i)" unfolding operative_def neutral_and
  3312 proof safe fix a b::"'b" { assume "content {a..b} = 0"
  3238 proof safe
       
  3239   fix a b::"'b"
       
  3240   { assume "content {a..b} = 0"
  3313     thus "\<exists>g. (\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b}" 
  3241     thus "\<exists>g. (\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b}" 
  3314       apply(rule_tac x=f in exI) using assms by(auto intro!:integrable_on_null) }
  3242       apply(rule_tac x=f in exI) using assms by(auto intro!:integrable_on_null) }
  3315   { fix c k g assume as:"\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e" "g integrable_on {a..b}" and k:"k<DIM('b)"
  3243   { fix c g and k :: 'b
  3316     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}"
  3244     assume as:"\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e" "g integrable_on {a..b}" and k:"k\<in>Basis"
  3317       "\<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}"
  3245     show "\<exists>g. (\<forall>x\<in>{a..b} \<inter> {x. x \<bullet> k \<le> c}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b} \<inter> {x. x \<bullet> k \<le> c}"
       
  3246       "\<exists>g. (\<forall>x\<in>{a..b} \<inter> {x. c \<le> x \<bullet> k}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b} \<inter> {x. c \<le> x \<bullet> k}"
  3318       apply(rule_tac[!] x=g in exI) using as(1) integrable_split[OF as(2) k] by auto }
  3247       apply(rule_tac[!] x=g in exI) using as(1) integrable_split[OF as(2) k] by auto }
  3319   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}"
  3248   fix c k g1 g2 assume as:"\<forall>x\<in>{a..b} \<inter> {x. x \<bullet> k \<le> c}. norm (f x - g1 x) \<le> e" "g1 integrable_on {a..b} \<inter> {x. x \<bullet> k \<le> c}"
  3320                           "\<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}"
  3249                           "\<forall>x\<in>{a..b} \<inter> {x. c \<le> x \<bullet> k}. norm (f x - g2 x) \<le> e" "g2 integrable_on {a..b} \<inter> {x. c \<le> x \<bullet> k}"
  3321   assume k:"k<DIM('b)"
  3250   assume k:"k\<in>Basis"
  3322   let ?g = "\<lambda>x. if x$$k = c then f x else if x$$k \<le> c then g1 x else g2 x"
  3251   let ?g = "\<lambda>x. if x\<bullet>k = c then f x else if x\<bullet>k \<le> c then g1 x else g2 x"
  3323   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)
  3252   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)
  3324   proof safe case goal1 thus ?case apply- apply(cases "x$$k=c", case_tac "x$$k < c") using as assms by auto
  3253   proof safe case goal1 thus ?case apply- apply(cases "x\<bullet>k=c", case_tac "x\<bullet>k < c") using as assms by auto
  3325   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}"
  3254   next case goal2 presume "?g integrable_on {a..b} \<inter> {x. x \<bullet> k \<le> c}" "?g integrable_on {a..b} \<inter> {x. x \<bullet> k \<ge> c}"
  3326     then guess h1 h2 unfolding integrable_on_def by auto from has_integral_split[OF this k] 
  3255     then guess h1 h2 unfolding integrable_on_def by auto from has_integral_split[OF this k] 
  3327     show ?case unfolding integrable_on_def by auto
  3256     show ?case unfolding integrable_on_def by auto
  3328   next show "?g integrable_on {a..b} \<inter> {x. x $$ k \<le> c}" "?g integrable_on {a..b} \<inter> {x. x $$ k \<ge> c}"
  3257   next show "?g integrable_on {a..b} \<inter> {x. x \<bullet> k \<le> c}" "?g integrable_on {a..b} \<inter> {x. x \<bullet> k \<ge> c}"
  3329       apply(rule_tac[!] integrable_spike[OF negligible_standard_hyperplane[of k c]]) using k as(2,4) by auto qed qed
  3258       apply(rule_tac[!] integrable_spike[OF negligible_standard_hyperplane[of k c]]) using k as(2,4) by auto qed qed
  3330 
  3259 
  3331 lemma approximable_on_division: fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach"
  3260 lemma approximable_on_division: fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach"
  3332   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"
  3261   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"
  3333   obtains g where "\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e" "g integrable_on {a..b}"
  3262   obtains g where "\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e" "g integrable_on {a..b}"
  3353   from e have "0 \<le> e" by auto from approximable_on_division[OF this division_of_tagged_division[OF p(1)] *] guess g .
  3282   from e have "0 \<le> e" by auto from approximable_on_division[OF this division_of_tagged_division[OF p(1)] *] guess g .
  3354   thus "\<exists>g. (\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b}" by auto qed 
  3283   thus "\<exists>g. (\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b}" by auto qed 
  3355 
  3284 
  3356 subsection {* Specialization of additivity to one dimension. *}
  3285 subsection {* Specialization of additivity to one dimension. *}
  3357 
  3286 
       
  3287 lemma 
       
  3288   shows real_inner_1_left: "inner 1 x = x"
       
  3289   and real_inner_1_right: "inner x 1 = x"
       
  3290   by simp_all
       
  3291 
  3358 lemma operative_1_lt: assumes "monoidal opp"
  3292 lemma operative_1_lt: assumes "monoidal opp"
  3359   shows "operative opp f \<longleftrightarrow> ((\<forall>a b. b \<le> a \<longrightarrow> f {a..b::real} = neutral opp) \<and>
  3293   shows "operative opp f \<longleftrightarrow> ((\<forall>a b. b \<le> a \<longrightarrow> f {a..b::real} = neutral opp) \<and>
  3360                 (\<forall>a b c. a < c \<and> c < b \<longrightarrow> opp (f{a..c})(f{c..b}) = f {a..b}))"
  3294                 (\<forall>a b c. a < c \<and> c < b \<longrightarrow> opp (f{a..c})(f{c..b}) = f {a..b}))"
  3361   unfolding operative_def content_eq_0 DIM_real less_one simp_thms(39,41) Eucl_real_simps
  3295   apply (simp add: operative_def content_eq_0 less_one)
  3362     (* The dnf_simps simplify "\<exists> x. x= _ \<and> _" and "\<forall>k. k = _ \<longrightarrow> _" *)
       
  3363 proof safe fix a b c::"real" assume as:"\<forall>a b c. f {a..b} = opp (f ({a..b} \<inter> {x. x \<le> c}))
  3296 proof safe fix a b c::"real" assume as:"\<forall>a b c. f {a..b} = opp (f ({a..b} \<inter> {x. x \<le> c}))
  3364     (f ({a..b} \<inter> {x. c \<le> x}))" "a < c" "c < b"
  3297     (f ({a..b} \<inter> {x. c \<le> x}))" "a < c" "c < b"
  3365     from this(2-) have "{a..b} \<inter> {x. x \<le> c} = {a..c}" "{a..b} \<inter> {x. x \<ge> c} = {c..b}" by auto
  3298     from this(2-) have "{a..b} \<inter> {x. x \<le> c} = {a..c}" "{a..b} \<inter> {x. x \<ge> c} = {c..b}" by auto
  3366     thus "opp (f {a..c}) (f {c..b}) = f {a..b}" unfolding as(1)[rule_format,of a b "c"] by auto
  3299     thus "opp (f {a..c}) (f {c..b}) = f {a..b}" unfolding as(1)[rule_format,of a b "c"] by auto
  3367 next fix a b c::real
  3300 next fix a b c::real
  3374       show ?thesis unfolding * apply(subst as(1)[rule_format,of 0 1]) using assms by auto
  3307       show ?thesis unfolding * apply(subst as(1)[rule_format,of 0 1]) using assms by auto
  3375     next   assume "b<c" hence *:"{a..b} \<inter> {x. x \<le> c} = {a..b}"  "{a..b} \<inter> {x. c \<le> x} = {1..0}" by auto
  3308     next   assume "b<c" hence *:"{a..b} \<inter> {x. x \<le> c} = {a..b}"  "{a..b} \<inter> {x. c \<le> x} = {1..0}" by auto
  3376       show ?thesis unfolding * apply(subst as(1)[rule_format,of 0 1]) using assms by auto
  3309       show ?thesis unfolding * apply(subst as(1)[rule_format,of 0 1]) using assms by auto
  3377     qed
  3310     qed
  3378   next case True hence *:"min (b) c = c" "max a c = c" by auto
  3311   next case True hence *:"min (b) c = c" "max a c = c" by auto
  3379     have **:"0 < DIM(real)" by auto
  3312     have **: "(1::real) \<in> Basis" by simp
  3380     have ***:"\<And>P Q. (\<chi>\<chi> i. if i = 0 then P i else Q i) = (P 0::real)" apply(subst euclidean_eq)
  3313     have ***:"\<And>P Q. (\<Sum>i\<in>Basis. (if i = 1 then P i else Q i) *\<^sub>R i) = (P 1::real)" 
  3381       apply safe unfolding euclidean_lambda_beta' by auto
  3314       by simp
  3382     show ?thesis unfolding interval_split[OF **,unfolded Eucl_real_simps(1,3)] unfolding *** *
  3315     show ?thesis 
       
  3316       unfolding interval_split[OF **, unfolded real_inner_1_right] unfolding *** *
  3383     proof(cases "c = a \<or> c = b")
  3317     proof(cases "c = a \<or> c = b")
  3384       case False thus "f {a..b} = opp (f {a..c}) (f {c..b})"
  3318       case False thus "f {a..b} = opp (f {a..c}) (f {c..b})"
  3385         apply-apply(subst as(2)[rule_format]) using True by auto
  3319         apply-apply(subst as(2)[rule_format]) using True by auto
  3386     next case True thus "f {a..b} = opp (f {a..c}) (f {c..b})" apply-
  3320     next case True thus "f {a..b} = opp (f {a..c}) (f {c..b})" apply-
  3387       proof(erule disjE) assume *:"c=a"
  3321       proof(erule disjE) assume *:"c=a"
  3409         thus ?thesis using assms unfolding * by auto qed qed qed 
  3343         thus ?thesis using assms unfolding * by auto qed qed qed 
  3410 
  3344 
  3411 subsection {* Special case of additivity we need for the FCT. *}
  3345 subsection {* Special case of additivity we need for the FCT. *}
  3412 
  3346 
  3413 lemma interval_bound_sing[simp]: "interval_upperbound {a} = a"  "interval_lowerbound {a} = a"
  3347 lemma interval_bound_sing[simp]: "interval_upperbound {a} = a"  "interval_lowerbound {a} = a"
  3414   unfolding interval_upperbound_def interval_lowerbound_def  by auto
  3348   unfolding interval_upperbound_def interval_lowerbound_def by (auto simp: euclidean_representation)
  3415 
  3349 
  3416 lemma additive_tagged_division_1: fixes f::"real \<Rightarrow> 'a::real_normed_vector"
  3350 lemma additive_tagged_division_1: fixes f::"real \<Rightarrow> 'a::real_normed_vector"
  3417   assumes "a \<le> b" "p tagged_division_of {a..b}"
  3351   assumes "a \<le> b" "p tagged_division_of {a..b}"
  3418   shows "setsum (\<lambda>(x,k). f(interval_upperbound k) - f(interval_lowerbound k)) p = f b - f a"
  3352   shows "setsum (\<lambda>(x,k). f(interval_upperbound k) - f(interval_lowerbound k)) p = f b - f a"
  3419 proof- let ?f = "(\<lambda>k::(real) set. if k = {} then 0 else f(interval_upperbound k) - f(interval_lowerbound k))"
  3353 proof- let ?f = "(\<lambda>k::(real) set. if k = {} then 0 else f(interval_upperbound k) - f(interval_lowerbound k))"
  3420   have ***:"\<forall>i<DIM(real). a $$ i \<le> b $$ i" using assms by auto 
  3354   have ***:"\<forall>i\<in>Basis. a \<bullet> i \<le> b \<bullet> i" using assms by auto
  3421   have *:"operative op + ?f" unfolding operative_1_lt[OF monoidal_monoid] interval_eq_empty by auto
  3355   have *:"operative op + ?f" unfolding operative_1_lt[OF monoidal_monoid] interval_eq_empty by auto
  3422   have **:"{a..b} \<noteq> {}" using assms(1) by auto note operative_tagged_division[OF monoidal_monoid * assms(2)]
  3356   have **:"{a..b} \<noteq> {}" using assms(1) by auto note operative_tagged_division[OF monoidal_monoid * assms(2)]
  3423   note * = this[unfolded if_not_P[OF **] interval_bounds[OF ***],THEN sym]
  3357   note * = this[unfolded if_not_P[OF **] interval_bounds[OF ***],THEN sym]
  3424   show ?thesis unfolding * apply(subst setsum_iterate[THEN sym]) defer
  3358   show ?thesis unfolding * apply(subst setsum_iterate[THEN sym]) defer
  3425     apply(rule setsum_cong2) unfolding split_paired_all split_conv using assms(2) by auto qed
  3359     apply(rule setsum_cong2) unfolding split_paired_all split_conv using assms(2) by auto qed
  3516   have *:"closed (\<Union>(s - {k}))" apply(rule closed_Union) defer apply rule apply(drule DiffD1,drule s(4))
  3450   have *:"closed (\<Union>(s - {k}))" apply(rule closed_Union) defer apply rule apply(drule DiffD1,drule s(4))
  3517     apply safe apply(rule closed_interval) using assm(1) by auto
  3451     apply safe apply(rule closed_interval) using assm(1) by auto
  3518   have "k \<subseteq> \<Union>(s - {k})" apply safe apply(rule *[unfolded closed_limpt,rule_format]) unfolding islimpt_approachable
  3452   have "k \<subseteq> \<Union>(s - {k})" apply safe apply(rule *[unfolded closed_limpt,rule_format]) unfolding islimpt_approachable
  3519   proof safe fix x and e::real assume as:"x\<in>k" "e>0"
  3453   proof safe fix x and e::real assume as:"x\<in>k" "e>0"
  3520     from k(2)[unfolded k content_eq_0] guess i .. 
  3454     from k(2)[unfolded k content_eq_0] guess i .. 
  3521     hence i:"c$$i = d$$i" "i<DIM('a)" using s(3)[OF k(1),unfolded k] unfolding interval_ne_empty by auto
  3455     hence i:"c\<bullet>i = d\<bullet>i" "i\<in>Basis" using s(3)[OF k(1),unfolded k] unfolding interval_ne_empty by auto
  3522     hence xi:"x$$i = d$$i" using as unfolding k mem_interval by (metis antisym)
  3456     hence xi:"x\<bullet>i = d\<bullet>i" using as unfolding k mem_interval by (metis antisym)
  3523     def y \<equiv> "(\<chi>\<chi> j. if j = i then if c$$i \<le> (a$$i + b$$i) / 2 then c$$i +
  3457     def y \<equiv> "(\<Sum>j\<in>Basis. (if j = i then if c\<bullet>i \<le> (a\<bullet>i + b\<bullet>i) / 2 then c\<bullet>i +
  3524       min e (b$$i - c$$i) / 2 else c$$i - min e (c$$i - a$$i) / 2 else x$$j)::'a"
  3458       min e (b\<bullet>i - c\<bullet>i) / 2 else c\<bullet>i - min e (c\<bullet>i - a\<bullet>i) / 2 else x\<bullet>j) *\<^sub>R j)::'a"
  3525     show "\<exists>x'\<in>\<Union>(s - {k}). x' \<noteq> x \<and> dist x' x < e" apply(rule_tac x=y in bexI) 
  3459     show "\<exists>x'\<in>\<Union>(s - {k}). x' \<noteq> x \<and> dist x' x < e" apply(rule_tac x=y in bexI) 
  3526     proof have "d \<in> {c..d}" using s(3)[OF k(1)] unfolding k interval_eq_empty mem_interval by(fastforce simp add: not_less)
  3460     proof have "d \<in> {c..d}" using s(3)[OF k(1)] unfolding k interval_eq_empty mem_interval by(fastforce simp add: not_less)
  3527       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]]
  3461       hence "d \<in> {a..b}" using s(2)[OF k(1)] unfolding k by auto note di = this[unfolded mem_interval,THEN bspec[where x=i]]
  3528       hence xyi:"y$$i \<noteq> x$$i" unfolding y_def unfolding i xi euclidean_lambda_beta'[OF i(2)] if_P[OF refl]
  3462       hence xyi:"y\<bullet>i \<noteq> x\<bullet>i"
  3529         apply(cases) apply(subst if_P,assumption) unfolding if_not_P not_le using as(2)
  3463         unfolding y_def i xi using as(2) assms(2)[unfolded content_eq_0] i(2)
  3530         using assms(2)[unfolded content_eq_0] using i(2)
  3464         by (auto elim!: ballE[of _ _ i])
  3531         by (auto simp add: not_le min_def)
  3465       thus "y \<noteq> x" unfolding euclidean_eq_iff[where 'a='a] using i by auto
  3532       thus "y \<noteq> x" unfolding euclidean_eq[where 'a='a] using i by auto
  3466       have *:"Basis = insert i (Basis - {i})" using i by auto
  3533       have *:"{..<DIM('a)} = insert i ({..<DIM('a)} - {i})" using i by auto
  3467       have "norm (y - x) < e + setsum (\<lambda>i. 0) Basis" apply(rule le_less_trans[OF norm_le_l1])
  3534       have "norm (y - x) < e + setsum (\<lambda>i. 0) {..<DIM('a)}" apply(rule le_less_trans[OF norm_le_l1])
       
  3535         apply(subst *,subst setsum_insert) prefer 3 apply(rule add_less_le_mono)
  3468         apply(subst *,subst setsum_insert) prefer 3 apply(rule add_less_le_mono)
  3536       proof- show "\<bar>(y - x) $$ i\<bar> < e" unfolding y_def euclidean_simps euclidean_lambda_beta'[OF i(2)] if_P[OF refl]
  3469       proof-
  3537           apply(cases) apply(subst if_P,assumption) unfolding if_not_P unfolding i xi using di as(2) by auto
  3470         show "\<bar>(y - x) \<bullet> i\<bar> < e"
  3538         show "(\<Sum>i\<in>{..<DIM('a)} - {i}. \<bar>(y - x) $$ i\<bar>) \<le> (\<Sum>i\<in>{..<DIM('a)}. 0)" unfolding y_def by auto 
  3471           using di as(2) y_def i xi by (auto simp: inner_simps)
       
  3472         show "(\<Sum>i\<in>Basis - {i}. \<bar>(y - x) \<bullet> i\<bar>) \<le> (\<Sum>i\<in>Basis. 0)"
       
  3473           unfolding y_def by (auto simp: inner_simps)
  3539       qed auto thus "dist y x < e" unfolding dist_norm by auto
  3474       qed auto thus "dist y x < e" unfolding dist_norm by auto
  3540       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
  3475       have "y\<notin>k" unfolding k mem_interval apply rule apply(erule_tac x=i in ballE) using xyi k i xi by auto
  3541       moreover have "y \<in> \<Union>s" unfolding s mem_interval
  3476       moreover have "y \<in> \<Union>s"
  3542       proof(rule,rule) note simps = y_def euclidean_lambda_beta' if_not_P
  3477         using set_rev_mp[OF as(1) s(2)[OF k(1)]] as(2) di i unfolding s mem_interval y_def
  3543         fix j assume j:"j<DIM('a)" show "a $$ j \<le> y $$ j \<and> y $$ j \<le> b $$ j" 
  3478         by (auto simp: field_simps elim!: ballE[of _ _ i])
  3544         proof(cases "j = i") case False have "x \<in> {a..b}" using s(2)[OF k(1)] as(1) by auto
       
  3545           thus ?thesis using j apply- unfolding simps if_not_P[OF False] unfolding mem_interval by auto
       
  3546         next case True note T = this show ?thesis
       
  3547           proof(cases "c $$ i \<le> (a $$ i + b $$ i) / 2")
       
  3548             case True show ?thesis unfolding simps if_P[OF T] if_P[OF True] unfolding i
       
  3549               using True as(2) di apply-apply rule unfolding T by (auto simp add:field_simps) 
       
  3550           next case False thus ?thesis unfolding simps if_P[OF T] if_not_P[OF False] unfolding i
       
  3551               using True as(2) di apply-apply rule unfolding T by (auto simp add:field_simps)
       
  3552           qed qed qed
       
  3553       ultimately show "y \<in> \<Union>(s - {k})" by auto
  3479       ultimately show "y \<in> \<Union>(s - {k})" by auto
  3554     qed qed hence "\<Union>(s - {k}) = {a..b}" unfolding s(6)[THEN sym] by auto
  3480     qed qed hence "\<Union>(s - {k}) = {a..b}" unfolding s(6)[THEN sym] by auto
  3555   hence  "{ka \<in> s - {k}. content ka \<noteq> 0} division_of {a..b}" apply-apply(rule assm(2)[rule_format,OF card refl])
  3481   hence  "{ka \<in> s - {k}. content ka \<noteq> 0} division_of {a..b}" apply-apply(rule assm(2)[rule_format,OF card refl])
  3556     apply(rule division_ofI) defer apply(rule_tac[1-4] s) using assm(1) by auto
  3482     apply(rule division_ofI) defer apply(rule_tac[1-4] s) using assm(1) by auto
  3557   moreover have "{ka \<in> s - {k}. content ka \<noteq> 0} = {k \<in> s. content k \<noteq> 0}" using k by auto ultimately show ?thesis by auto qed
  3483   moreover have "{ka \<in> s - {k}. content ka \<noteq> 0} = {k \<in> s. content k \<noteq> 0}" using k by auto ultimately show ?thesis by auto qed
  3728 
  3654 
  3729 lemma content_image_affinity_interval: 
  3655 lemma content_image_affinity_interval: 
  3730  "content((\<lambda>x::'a::ordered_euclidean_space. m *\<^sub>R x + c) ` {a..b}) = (abs m) ^ DIM('a) * content {a..b}" (is "?l = ?r")
  3656  "content((\<lambda>x::'a::ordered_euclidean_space. m *\<^sub>R x + c) ` {a..b}) = (abs m) ^ DIM('a) * content {a..b}" (is "?l = ?r")
  3731 proof- { presume *:"{a..b}\<noteq>{} \<Longrightarrow> ?thesis" show ?thesis apply(cases,rule *,assumption)
  3657 proof- { presume *:"{a..b}\<noteq>{} \<Longrightarrow> ?thesis" show ?thesis apply(cases,rule *,assumption)
  3732       unfolding not_not using content_empty by auto }
  3658       unfolding not_not using content_empty by auto }
  3733   have *:"DIM('a) = card {..<DIM('a)}" by auto
  3659   assume as: "{a..b}\<noteq>{}" 
  3734   assume as:"{a..b}\<noteq>{}" show ?thesis proof(cases "m \<ge> 0")
  3660   show ?thesis 
  3735     case True show ?thesis unfolding image_affinity_interval if_not_P[OF as] if_P[OF True]
  3661   proof (cases "m \<ge> 0")
  3736       unfolding content_closed_interval'[OF as] apply(subst content_closed_interval') defer apply(subst(2) *)
  3662     case True
  3737       apply(subst setprod_constant[THEN sym]) apply(rule finite_lessThan) unfolding setprod_timesf[THEN sym]
  3663     with as have "{m *\<^sub>R a + c..m *\<^sub>R b + c} \<noteq> {}"
  3738       apply(rule setprod_cong2) using True as unfolding interval_ne_empty euclidean_simps not_le  
  3664       unfolding interval_ne_empty
  3739       by(auto simp add:field_simps intro:mult_left_mono)
  3665       apply (intro ballI)
  3740   next case False show ?thesis unfolding image_affinity_interval if_not_P[OF as] if_not_P[OF False]
  3666       apply (erule_tac x=i in ballE)
  3741       unfolding content_closed_interval'[OF as] apply(subst content_closed_interval') defer apply(subst(2) *)
  3667       apply (auto simp: inner_simps intro!: mult_left_mono)
  3742       apply(subst setprod_constant[THEN sym]) apply(rule finite_lessThan) unfolding setprod_timesf[THEN sym]
  3668       done
  3743       apply(rule setprod_cong2) using False as unfolding interval_ne_empty euclidean_simps not_le 
  3669     moreover from True have *: "\<And>i. (m *\<^sub>R b + c) \<bullet> i - (m *\<^sub>R a + c) \<bullet> i = m *\<^sub>R (b - a) \<bullet> i"
  3744       by(auto simp add:field_simps mult_le_cancel_left_neg) qed qed
  3670       by (simp add: inner_simps field_simps)
       
  3671     ultimately show ?thesis
       
  3672       by (simp add: image_affinity_interval True content_closed_interval'
       
  3673                     setprod_timesf setprod_constant inner_diff_left)
       
  3674   next
       
  3675     case False
       
  3676     moreover with as have "{m *\<^sub>R b + c..m *\<^sub>R a + c} \<noteq> {}"
       
  3677       unfolding interval_ne_empty
       
  3678       apply (intro ballI)
       
  3679       apply (erule_tac x=i in ballE)
       
  3680       apply (auto simp: inner_simps intro!: mult_left_mono)
       
  3681       done
       
  3682     moreover from False have *: "\<And>i. (m *\<^sub>R a + c) \<bullet> i - (m *\<^sub>R b + c) \<bullet> i = (-m) *\<^sub>R (b - a) \<bullet> i"
       
  3683       by (simp add: inner_simps field_simps)
       
  3684     ultimately show ?thesis
       
  3685       by (simp add: image_affinity_interval content_closed_interval'
       
  3686                     setprod_timesf[symmetric] setprod_constant[symmetric] inner_diff_left)
       
  3687   qed
       
  3688 qed
  3745 
  3689 
  3746 lemma has_integral_affinity: fixes a::"'a::ordered_euclidean_space" assumes "(f has_integral i) {a..b}" "m \<noteq> 0"
  3690 lemma has_integral_affinity: fixes a::"'a::ordered_euclidean_space" assumes "(f has_integral i) {a..b}" "m \<noteq> 0"
  3747   shows "((\<lambda>x. f(m *\<^sub>R x + c)) has_integral ((1 / (abs(m) ^ DIM('a))) *\<^sub>R i)) ((\<lambda>x. (1 / m) *\<^sub>R x + -((1 / m) *\<^sub>R c)) ` {a..b})"
  3691   shows "((\<lambda>x. f(m *\<^sub>R x + c)) has_integral ((1 / (abs(m) ^ DIM('a))) *\<^sub>R i)) ((\<lambda>x. (1 / m) *\<^sub>R x + -((1 / m) *\<^sub>R c)) ` {a..b})"
  3748   apply(rule has_integral_twiddle,safe) apply(rule zero_less_power) unfolding euclidean_eq[where 'a='a]
  3692   apply(rule has_integral_twiddle,safe) apply(rule zero_less_power) unfolding euclidean_eq_iff[where 'a='a]
  3749   unfolding scaleR_right_distrib euclidean_simps scaleR_scaleR
  3693   unfolding scaleR_right_distrib inner_simps scaleR_scaleR
  3750   defer apply(insert assms(2), simp add:field_simps) apply(insert assms(2), simp add:field_simps)
  3694   defer apply(insert assms(2), simp add:field_simps) apply(insert assms(2), simp add:field_simps)
  3751   apply(rule continuous_intros)+ apply(rule interval_image_affinity_interval)+ apply(rule content_image_affinity_interval) using assms by auto
  3695   apply(rule continuous_intros)+ apply(rule interval_image_affinity_interval)+ apply(rule content_image_affinity_interval) using assms by auto
  3752 
  3696 
  3753 lemma integrable_affinity: assumes "f integrable_on {a..b}" "m \<noteq> 0"
  3697 lemma integrable_affinity: assumes "f integrable_on {a..b}" "m \<noteq> 0"
  3754   shows "(\<lambda>x. f(m *\<^sub>R x + c)) integrable_on ((\<lambda>x. (1 / m) *\<^sub>R x + -((1/m) *\<^sub>R c)) ` {a..b})"
  3698   shows "(\<lambda>x. f(m *\<^sub>R x + c)) integrable_on ((\<lambda>x. (1 / m) *\<^sub>R x + -((1/m) *\<^sub>R c)) ` {a..b})"
  3755   using assms unfolding integrable_on_def apply safe apply(drule has_integral_affinity) by auto
  3699   using assms unfolding integrable_on_def apply safe apply(drule has_integral_affinity) by auto
  3756 
  3700 
  3757 subsection {* Special case of stretching coordinate axes separately. *}
  3701 subsection {* Special case of stretching coordinate axes separately. *}
  3758 
  3702 
  3759 lemma image_stretch_interval:
  3703 lemma image_stretch_interval:
  3760   "(\<lambda>x. \<chi>\<chi> k. m k * x$$k) ` {a..b::'a::ordered_euclidean_space} =
  3704   "(\<lambda>x. \<Sum>k\<in>Basis. (m k * (x\<bullet>k)) *\<^sub>R k) ` {a..b::'a::ordered_euclidean_space} =
  3761   (if {a..b} = {} then {} else {(\<chi>\<chi> k. min (m(k) * a$$k) (m(k) * b$$k))::'a ..  (\<chi>\<chi> k. max (m(k) * a$$k) (m(k) * b$$k))})"
  3705   (if {a..b} = {} then {} else
  3762   (is "?l = ?r")
  3706     {(\<Sum>k\<in>Basis. (min (m k * (a\<bullet>k)) (m k * (b\<bullet>k))) *\<^sub>R k)::'a .. 
  3763 proof(cases "{a..b}={}") case True thus ?thesis unfolding True by auto
  3707      (\<Sum>k\<in>Basis. (max (m k * (a\<bullet>k)) (m k * (b\<bullet>k))) *\<^sub>R k)})"
  3764 next have *:"\<And>P Q. (\<forall>i<DIM('a). P i) \<and> (\<forall>i<DIM('a). Q i) \<longleftrightarrow> (\<forall>i<DIM('a). P i \<and> Q i)" by auto
  3708 proof cases
  3765   case False note ab = this[unfolded interval_ne_empty]
  3709   assume *: "{a..b} \<noteq> {}" 
  3766   show ?thesis apply-apply(rule set_eqI)
  3710   show ?thesis
  3767   proof- fix x::"'a" have **:"\<And>P Q. (\<forall>i<DIM('a). P i = Q i) \<Longrightarrow> (\<forall>i<DIM('a). P i) = (\<forall>i<DIM('a). Q i)" by auto
  3711     unfolding interval_ne_empty if_not_P[OF *]
  3768     show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" unfolding if_not_P[OF False] 
  3712     apply (simp add: interval image_Collect set_eq_iff euclidean_eq_iff[where 'a='a] ball_conj_distrib[symmetric])
  3769       unfolding image_iff mem_interval Bex_def euclidean_simps euclidean_eq[where 'a='a] *
  3713     apply (subst choice_Basis_iff[symmetric])
  3770       unfolding imp_conjR[THEN sym] apply(subst euclidean_lambda_beta'') apply(subst lambda_skolem'[THEN sym])
  3714   proof (intro allI ball_cong refl)
  3771       apply(rule **,rule,rule) unfolding euclidean_lambda_beta'
  3715     fix x i :: 'a assume "i \<in> Basis"
  3772     proof- fix i assume i:"i<DIM('a)" show "(\<exists>xa. (a $$ i \<le> xa \<and> xa \<le> b $$ i) \<and> x $$ i = m i * xa) =
  3716     with * have a_le_b: "a \<bullet> i \<le> b \<bullet> i"
  3773         (min (m i * a $$ i) (m i * b $$ i) \<le> x $$ i \<and> x $$ i \<le> max (m i * a $$ i) (m i * b $$ i))"
  3717       unfolding interval_ne_empty by auto
  3774       proof(cases "m i = 0") case True thus ?thesis using ab i by auto
  3718     show "(\<exists>xa. x \<bullet> i = m i * xa \<and> a \<bullet> i \<le> xa \<and> xa \<le> b \<bullet> i) \<longleftrightarrow>
  3775       next case False hence "0 < m i \<or> 0 > m i" by auto thus ?thesis apply-
  3719         min (m i * (a \<bullet> i)) (m i * (b \<bullet> i)) \<le> x \<bullet> i \<and> x \<bullet> i \<le> max (m i * (a \<bullet> i)) (m i * (b \<bullet> i))"
  3776         proof(erule disjE) assume as:"0 < m i" hence *:"min (m i * a $$ i) (m i * b $$ i) = m i * a $$ i"
  3720     proof cases
  3777             "max (m i * a $$ i) (m i * b $$ i) = m i * b $$ i" using ab i unfolding min_def max_def by auto
  3721       assume "m i \<noteq> 0"
  3778           show ?thesis unfolding * apply rule defer apply(rule_tac x="1 / m i * x$$i" in exI)
  3722       moreover then have *: "\<And>a b. a = m i * b \<longleftrightarrow> b = a / m i"
  3779             using as by(auto simp add:field_simps)
  3723         by (auto simp add: field_simps)
  3780         next assume as:"0 > m i" hence *:"max (m i * a $$ i) (m i * b $$ i) = m i * a $$ i"
  3724       moreover have
  3781             "min (m i * a $$ i) (m i * b $$ i) = m i * b $$ i" using ab as i unfolding min_def max_def 
  3725           "min (m i * (a \<bullet> i)) (m i * (b \<bullet> i)) = (if 0 < m i then m i * (a \<bullet> i) else m i * (b \<bullet> i))"
  3782             by(auto simp add:field_simps mult_le_cancel_left_neg intro: order_antisym)
  3726           "max (m i * (a \<bullet> i)) (m i * (b \<bullet> i)) = (if 0 < m i then m i * (b \<bullet> i) else m i * (a \<bullet> i))"
  3783           show ?thesis unfolding * apply rule defer apply(rule_tac x="1 / m i * x$$i" in exI)
  3727         using a_le_b by (auto simp: min_def max_def mult_le_cancel_left)
  3784             using as by(auto simp add:field_simps) qed qed qed qed qed 
  3728       ultimately show ?thesis using a_le_b
  3785 
  3729         unfolding * by (auto simp add: le_divide_eq divide_le_eq ac_simps) 
  3786 lemma interval_image_stretch_interval: "\<exists>u v. (\<lambda>x. \<chi>\<chi> k. m k * x$$k) ` {a..b::'a::ordered_euclidean_space} = {u..v::'a}"
  3730     qed (insert a_le_b, auto)
       
  3731   qed
       
  3732 qed simp
       
  3733 
       
  3734 lemma interval_image_stretch_interval: 
       
  3735     "\<exists>u v. (\<lambda>x. \<Sum>k\<in>Basis. (m k * (x\<bullet>k))*\<^sub>R k) ` {a..b::'a::ordered_euclidean_space} = {u..v::'a}"
  3787   unfolding image_stretch_interval by auto 
  3736   unfolding image_stretch_interval by auto 
  3788 
  3737 
  3789 lemma content_image_stretch_interval:
  3738 lemma content_image_stretch_interval:
  3790   "content((\<lambda>x::'a::ordered_euclidean_space. (\<chi>\<chi> k. m k * x$$k)::'a) ` {a..b}) = abs(setprod m {..<DIM('a)}) * content({a..b})"
  3739   "content((\<lambda>x::'a::ordered_euclidean_space. (\<Sum>k\<in>Basis. (m k * (x\<bullet>k))*\<^sub>R k)::'a) ` {a..b}) = abs(setprod m Basis) * content({a..b})"
  3791 proof(cases "{a..b} = {}") case True thus ?thesis
  3740 proof(cases "{a..b} = {}") case True thus ?thesis
  3792     unfolding content_def image_is_empty image_stretch_interval if_P[OF True] by auto
  3741     unfolding content_def image_is_empty image_stretch_interval if_P[OF True] by auto
  3793 next case False hence "(\<lambda>x. (\<chi>\<chi> k. m k * x $$ k)::'a) ` {a..b} \<noteq> {}" by auto
  3742 next case False hence "(\<lambda>x. (\<Sum>k\<in>Basis. (m k * (x\<bullet>k))*\<^sub>R k)::'a) ` {a..b} \<noteq> {}" by auto
  3794   thus ?thesis using False unfolding content_def image_stretch_interval apply- unfolding interval_bounds' if_not_P
  3743   thus ?thesis using False unfolding content_def image_stretch_interval apply- unfolding interval_bounds' if_not_P
  3795     unfolding abs_setprod setprod_timesf[THEN sym] apply(rule setprod_cong2) unfolding lessThan_iff euclidean_lambda_beta'
  3744     unfolding abs_setprod setprod_timesf[THEN sym] apply(rule setprod_cong2) unfolding lessThan_iff
  3796   proof- fix i assume i:"i<DIM('a)" have "(m i < 0 \<or> m i > 0) \<or> m i = 0" by auto
  3745   proof (simp only: inner_setsum_left_Basis)
  3797     thus "max (m i * a $$ i) (m i * b $$ i) - min (m i * a $$ i) (m i * b $$ i) = \<bar>m i\<bar> * (b $$ i - a $$ i)"
  3746     fix i :: 'a assume i:"i\<in>Basis" have "(m i < 0 \<or> m i > 0) \<or> m i = 0" by auto
       
  3747     thus "max (m i * (a \<bullet> i)) (m i * (b \<bullet> i)) - min (m i * (a \<bullet> i)) (m i * (b \<bullet> i)) = 
       
  3748         \<bar>m i\<bar> * (b \<bullet> i - a \<bullet> i)"
  3798       apply-apply(erule disjE)+ unfolding min_def max_def using False[unfolded interval_ne_empty,rule_format,of i] i 
  3749       apply-apply(erule disjE)+ unfolding min_def max_def using False[unfolded interval_ne_empty,rule_format,of i] i 
  3799       by(auto simp add:field_simps not_le mult_le_cancel_left_neg mult_le_cancel_left_pos) qed qed
  3750       by(auto simp add:field_simps not_le mult_le_cancel_left_neg mult_le_cancel_left_pos) qed qed
  3800 
  3751 
  3801 lemma has_integral_stretch: fixes f::"'a::ordered_euclidean_space => 'b::real_normed_vector"
  3752 lemma has_integral_stretch: fixes f::"'a::ordered_euclidean_space => 'b::real_normed_vector"
  3802   assumes "(f has_integral i) {a..b}" "\<forall>k<DIM('a). ~(m k = 0)"
  3753   assumes "(f has_integral i) {a..b}" "\<forall>k\<in>Basis. ~(m k = 0)"
  3803   shows "((\<lambda>x. f(\<chi>\<chi> k. m k * x$$k)) has_integral
  3754   shows "((\<lambda>x. f (\<Sum>k\<in>Basis. (m k * (x\<bullet>k))*\<^sub>R k)) has_integral
  3804              ((1/(abs(setprod m {..<DIM('a)}))) *\<^sub>R i)) ((\<lambda>x. (\<chi>\<chi> k. 1/(m k) * x$$k)::'a) ` {a..b})"
  3755              ((1/(abs(setprod m Basis))) *\<^sub>R i)) ((\<lambda>x. (\<Sum>k\<in>Basis. (1 / m k * (x\<bullet>k))*\<^sub>R k)) ` {a..b})"
  3805   apply(rule has_integral_twiddle[where f=f]) unfolding zero_less_abs_iff content_image_stretch_interval
  3756   apply(rule has_integral_twiddle[where f=f]) unfolding zero_less_abs_iff content_image_stretch_interval
  3806   unfolding image_stretch_interval empty_as_interval euclidean_eq[where 'a='a] using assms
  3757   unfolding image_stretch_interval empty_as_interval euclidean_eq_iff[where 'a='a] using assms
  3807 proof- show "\<forall>y::'a. continuous (at y) (\<lambda>x. (\<chi>\<chi> k. m k * x $$ k)::'a)"
  3758 proof- show "\<forall>y::'a. continuous (at y) (\<lambda>x. (\<Sum>k\<in>Basis. (m k * (x\<bullet>k))*\<^sub>R k))"
  3808    apply(rule,rule linear_continuous_at) unfolding linear_linear
  3759    apply(rule,rule linear_continuous_at) unfolding linear_linear
  3809    unfolding linear_def euclidean_simps euclidean_eq[where 'a='a] by(auto simp add:field_simps) qed auto
  3760    unfolding linear_def inner_simps euclidean_eq_iff[where 'a='a] by(auto simp add:field_simps)
       
  3761 qed auto
  3810 
  3762 
  3811 lemma integrable_stretch:  fixes f::"'a::ordered_euclidean_space => 'b::real_normed_vector"
  3763 lemma integrable_stretch:  fixes f::"'a::ordered_euclidean_space => 'b::real_normed_vector"
  3812   assumes "f integrable_on {a..b}" "\<forall>k<DIM('a). ~(m k = 0)"
  3764   assumes "f integrable_on {a..b}" "\<forall>k\<in>Basis. ~(m k = 0)"
  3813   shows "(\<lambda>x::'a. f(\<chi>\<chi> k. m k * x$$k)) integrable_on ((\<lambda>x. \<chi>\<chi> k. 1/(m k) * x$$k) ` {a..b})"
  3765   shows "(\<lambda>x::'a. f (\<Sum>k\<in>Basis. (m k * (x\<bullet>k))*\<^sub>R k)) integrable_on ((\<lambda>x. \<Sum>k\<in>Basis. (1 / m k * (x\<bullet>k))*\<^sub>R k) ` {a..b})"
  3814   using assms unfolding integrable_on_def apply-apply(erule exE) 
  3766   using assms unfolding integrable_on_def apply-apply(erule exE) 
  3815   apply(drule has_integral_stretch,assumption) by auto
  3767   apply(drule has_integral_stretch,assumption) by auto
  3816 
  3768 
  3817 subsection {* even more special cases. *}
  3769 subsection {* even more special cases. *}
  3818 
  3770 
  3854   shows "(f' has_integral (f b - f a)) {a..b}"
  3806   shows "(f' has_integral (f b - f a)) {a..b}"
  3855 proof- { presume *:"a < b \<Longrightarrow> ?thesis" 
  3807 proof- { presume *:"a < b \<Longrightarrow> ?thesis" 
  3856     show ?thesis proof(cases,rule *,assumption)
  3808     show ?thesis proof(cases,rule *,assumption)
  3857       assume "\<not> a < b" hence "a = b" using assms(1) by auto
  3809       assume "\<not> a < b" hence "a = b" using assms(1) by auto
  3858       hence *:"{a .. b} = {b}" "f b - f a = 0" by(auto simp add:  order_antisym)
  3810       hence *:"{a .. b} = {b}" "f b - f a = 0" by(auto simp add:  order_antisym)
  3859       show ?thesis unfolding *(2) apply(rule has_integral_null) unfolding content_eq_0 using * `a=b` by auto
  3811       show ?thesis unfolding *(2) apply(rule has_integral_null) unfolding content_eq_0 using * `a=b`
       
  3812         by (auto simp: ex_in_conv)
  3860     qed } assume ab:"a < b"
  3813     qed } assume ab:"a < b"
  3861   let ?P = "\<lambda>e. \<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow>
  3814   let ?P = "\<lambda>e. \<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow>
  3862                    norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f' x) - (f b - f a)) \<le> e * content {a..b})"
  3815                    norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f' x) - (f b - f a)) \<le> e * content {a..b})"
  3863   { presume "\<And>e. e>0 \<Longrightarrow> ?P e" thus ?thesis unfolding has_integral_factor_content by auto }
  3816   { presume "\<And>e. e>0 \<Longrightarrow> ?P e" thus ?thesis unfolding has_integral_factor_content by auto }
  3864   fix e::real assume e:"e>0"
  3817   fix e::real assume e:"e>0"
  4104   have "gauge d" unfolding d_def using w(1) d1 by auto
  4057   have "gauge d" unfolding d_def using w(1) d1 by auto
  4105   note this[unfolded gauge_def,rule_format,of c] note conjunctD2[OF this]
  4058   note this[unfolded gauge_def,rule_format,of c] note conjunctD2[OF this]
  4106   from this(2)[unfolded open_contains_ball,rule_format,OF this(1)] guess k .. note k=conjunctD2[OF this]
  4059   from this(2)[unfolded open_contains_ball,rule_format,OF this(1)] guess k .. note k=conjunctD2[OF this]
  4107 
  4060 
  4108   let ?d = "min k (c - a)/2" show ?thesis apply(rule that[of ?d])
  4061   let ?d = "min k (c - a)/2" show ?thesis apply(rule that[of ?d])
  4109   proof safe show "?d > 0" using k(1) using assms(2) by auto
  4062   proof safe
  4110     fix t assume as:"c - ?d < t" "t \<le> c" let ?thesis = "norm (integral {a..c} f - integral {a..t} f) < e"
  4063     show "?d > 0" using k(1) using assms(2) by auto
       
  4064     fix t assume as:"c - ?d < t" "t \<le> c"
       
  4065     let ?thesis = "norm (integral {a..c} f - integral {a..t} f) < e"
  4111     { presume *:"t < c \<Longrightarrow> ?thesis"
  4066     { presume *:"t < c \<Longrightarrow> ?thesis"
  4112       show ?thesis apply(cases "t = c") defer apply(rule *)
  4067       show ?thesis apply(cases "t = c") defer apply(rule *)
  4113         apply(subst less_le) using `e>0` as(2) by auto } assume "t < c"
  4068         apply(subst less_le) using `e>0` as(2) by auto }
       
  4069     assume "t < c"
  4114 
  4070 
  4115     have "f integrable_on {a..t}" apply(rule integrable_subinterval[OF assms(1)]) using assms(2-3) as(2) by auto
  4071     have "f integrable_on {a..t}" apply(rule integrable_subinterval[OF assms(1)]) using assms(2-3) as(2) by auto
  4116     from integrable_integral[OF this,unfolded has_integral,rule_format,OF *] guess d2 ..
  4072     from integrable_integral[OF this,unfolded has_integral,rule_format,OF *] guess d2 ..
  4117     note d2 = conjunctD2[OF this,rule_format]
  4073     note d2 = conjunctD2[OF this,rule_format]
  4118     def d3 \<equiv> "\<lambda>x. if x \<le> t then d1 x \<inter> d2 x else d1 x"
  4074     def d3 \<equiv> "\<lambda>x. if x \<le> t then d1 x \<inter> d2 x else d1 x"
  4121     note p'=tagged_division_ofD[OF this(1)]
  4077     note p'=tagged_division_ofD[OF this(1)]
  4122     have pt:"\<forall>(x,k)\<in>p. x \<le> t" proof safe case goal1 from p'(2,3)[OF this] show ?case by auto qed
  4078     have pt:"\<forall>(x,k)\<in>p. x \<le> t" proof safe case goal1 from p'(2,3)[OF this] show ?case by auto qed
  4123     with p(2) have "d2 fine p" unfolding fine_def d3_def apply safe apply(erule_tac x="(a,b)" in ballE)+ by auto
  4079     with p(2) have "d2 fine p" unfolding fine_def d3_def apply safe apply(erule_tac x="(a,b)" in ballE)+ by auto
  4124     note d2_fin = d2(2)[OF conjI[OF p(1) this]]
  4080     note d2_fin = d2(2)[OF conjI[OF p(1) this]]
  4125     
  4081     
  4126     have *:"{a..c} \<inter> {x. x $$0 \<le> t} = {a..t}" "{a..c} \<inter> {x. x$$0 \<ge> t} = {t..c}"
  4082     have *:"{a..c} \<inter> {x. x \<bullet> 1 \<le> t} = {a..t}" "{a..c} \<inter> {x. x \<bullet> 1 \<ge> t} = {t..c}"
  4127       using assms(2-3) as by(auto simp add:field_simps)
  4083       using assms(2-3) as by(auto simp add:field_simps)
  4128     have "p \<union> {(c, {t..c})} tagged_division_of {a..c} \<and> d1 fine p \<union> {(c, {t..c})}" apply rule
  4084     have "p \<union> {(c, {t..c})} tagged_division_of {a..c} \<and> d1 fine p \<union> {(c, {t..c})}" apply rule
  4129       apply(rule tagged_division_union_interval[of _ _ _ 0 "t"]) unfolding * apply(rule p)
  4085       apply(rule tagged_division_union_interval[of _ _ _ 1 "t"]) unfolding * apply(rule p)
  4130       apply(rule tagged_division_of_self) unfolding fine_def
  4086       apply(rule tagged_division_of_self) unfolding fine_def
  4131     proof safe fix x k y assume "(x,k)\<in>p" "y\<in>k" thus "y\<in>d1 x"
  4087     proof safe fix x k y assume "(x,k)\<in>p" "y\<in>k" thus "y\<in>d1 x"
  4132         using p(2) pt unfolding fine_def d3_def apply- apply(erule_tac x="(x,k)" in ballE)+ by auto
  4088         using p(2) pt unfolding fine_def d3_def apply- apply(erule_tac x="(x,k)" in ballE)+ by auto
  4133     next fix x assume "x\<in>{t..c}" hence "dist c x < k" unfolding dist_real_def
  4089     next fix x assume "x\<in>{t..c}" hence "dist c x < k" unfolding dist_real_def
  4134         using as(1) by(auto simp add:field_simps) 
  4090         using as(1) by(auto simp add:field_simps) 
  4176 proof(unfold continuous_on_iff, safe)  fix x e assume as:"x\<in>{a..b}" "0<(e::real)"
  4132 proof(unfold continuous_on_iff, safe)  fix x e assume as:"x\<in>{a..b}" "0<(e::real)"
  4177   let ?thesis = "\<exists>d>0. \<forall>x'\<in>{a..b}. dist x' x < d \<longrightarrow> dist (integral {a..x'} f) (integral {a..x} f) < e"
  4133   let ?thesis = "\<exists>d>0. \<forall>x'\<in>{a..b}. dist x' x < d \<longrightarrow> dist (integral {a..x'} f) (integral {a..x} f) < e"
  4178   { presume *:"a<b \<Longrightarrow> ?thesis"
  4134   { presume *:"a<b \<Longrightarrow> ?thesis"
  4179     show ?thesis apply(cases,rule *,assumption)
  4135     show ?thesis apply(cases,rule *,assumption)
  4180     proof- case goal1 hence "{a..b} = {x}" using as(1) apply-apply(rule set_eqI)
  4136     proof- case goal1 hence "{a..b} = {x}" using as(1) apply-apply(rule set_eqI)
  4181         unfolding atLeastAtMost_iff by(auto simp only:field_simps not_less DIM_real)
  4137         unfolding atLeastAtMost_iff by(auto simp only:field_simps not_less)
  4182       thus ?case using `e>0` by auto
  4138       thus ?case using `e>0` by auto
  4183     qed } assume "a<b"
  4139     qed } assume "a<b"
  4184   have "(x=a \<or> x=b) \<or> (a<x \<and> x<b)" using as(1) by (auto simp add:)
  4140   have "(x=a \<or> x=b) \<or> (a<x \<and> x<b)" using as(1) by (auto simp add:)
  4185   thus ?thesis apply-apply(erule disjE)+
  4141   thus ?thesis apply-apply(erule disjE)+
  4186   proof- assume "x=a" have "a \<le> a" by auto
  4142   proof- assume "x=a" have "a \<le> a" by auto
  4353         apply safe apply(drule B(2)[rule_format]) unfolding subset_eq apply(erule_tac x=x in ballE)
  4309         apply safe apply(drule B(2)[rule_format]) unfolding subset_eq apply(erule_tac x=x in ballE)
  4354         by(auto simp add:dist_norm)
  4310         by(auto simp add:dist_norm)
  4355     qed(insert B `e>0`, auto)
  4311     qed(insert B `e>0`, auto)
  4356   next assume as:"\<forall>e>0. ?r e" 
  4312   next assume as:"\<forall>e>0. ?r e" 
  4357     from this[rule_format,OF zero_less_one] guess C .. note C=conjunctD2[OF this,rule_format]
  4313     from this[rule_format,OF zero_less_one] guess C .. note C=conjunctD2[OF this,rule_format]
  4358     def c \<equiv> "(\<chi>\<chi> i. - max B C)::'n::ordered_euclidean_space" and d \<equiv> "(\<chi>\<chi> i. max B C)::'n::ordered_euclidean_space"
  4314     def c \<equiv> "(\<Sum>i\<in>Basis. (- max B C) *\<^sub>R i)::'n::ordered_euclidean_space" 
       
  4315     def d \<equiv> "(\<Sum>i\<in>Basis. max B C *\<^sub>R i)::'n::ordered_euclidean_space"
  4359     have c_d:"{a..b} \<subseteq> {c..d}" apply safe apply(drule B(2)) unfolding mem_interval
  4316     have c_d:"{a..b} \<subseteq> {c..d}" apply safe apply(drule B(2)) unfolding mem_interval
  4360     proof case goal1 thus ?case using component_le_norm[of x i] unfolding c_def d_def
  4317     proof
  4361         by(auto simp add:field_simps) qed
  4318       case goal1 thus ?case using Basis_le_norm[OF `i\<in>Basis`, of x] unfolding c_def d_def
       
  4319         by(auto simp add:field_simps setsum_negf)
       
  4320     qed
  4362     have "ball 0 C \<subseteq> {c..d}" apply safe unfolding mem_interval mem_ball dist_norm 
  4321     have "ball 0 C \<subseteq> {c..d}" apply safe unfolding mem_interval mem_ball dist_norm 
  4363     proof case goal1 thus ?case using component_le_norm[of x i] unfolding c_def d_def by auto qed
  4322     proof
       
  4323       case goal1 thus ?case
       
  4324         using Basis_le_norm[OF `i\<in>Basis`, of x] unfolding c_def d_def by (auto simp: setsum_negf)
       
  4325     qed
  4364     from C(2)[OF this] have "\<exists>y. (f has_integral y) {a..b}"
  4326     from C(2)[OF this] have "\<exists>y. (f has_integral y) {a..b}"
  4365       unfolding has_integral_restrict_closed_subintervals_eq[OF c_d,THEN sym] unfolding s by auto
  4327       unfolding has_integral_restrict_closed_subintervals_eq[OF c_d,THEN sym] unfolding s by auto
  4366     then guess y .. note y=this
  4328     then guess y .. note y=this
  4367 
  4329 
  4368     have "y = i" proof(rule ccontr) assume "y\<noteq>i" hence "0 < norm (y - i)" by auto
  4330     have "y = i" proof(rule ccontr) assume "y\<noteq>i" hence "0 < norm (y - i)" by auto
  4369       from as[rule_format,OF this] guess C ..  note C=conjunctD2[OF this,rule_format]
  4331       from as[rule_format,OF this] guess C ..  note C=conjunctD2[OF this,rule_format]
  4370       def c \<equiv> "(\<chi>\<chi> i. - max B C)::'n::ordered_euclidean_space" and d \<equiv> "(\<chi>\<chi> i. max B C)::'n::ordered_euclidean_space"
  4332       def c \<equiv> "(\<Sum>i\<in>Basis. (- max B C) *\<^sub>R i)::'n::ordered_euclidean_space" 
       
  4333       def d \<equiv> "(\<Sum>i\<in>Basis. max B C *\<^sub>R i)::'n::ordered_euclidean_space"
  4371       have c_d:"{a..b} \<subseteq> {c..d}" apply safe apply(drule B(2)) unfolding mem_interval
  4334       have c_d:"{a..b} \<subseteq> {c..d}" apply safe apply(drule B(2)) unfolding mem_interval
  4372       proof case goal1 thus ?case using component_le_norm[of x i] unfolding c_def d_def
  4335       proof case goal1 thus ?case using Basis_le_norm[of i x] unfolding c_def d_def
  4373           by(auto simp add:field_simps) qed
  4336           by(auto simp add:field_simps setsum_negf) qed
  4374       have "ball 0 C \<subseteq> {c..d}" apply safe unfolding mem_interval mem_ball dist_norm 
  4337       have "ball 0 C \<subseteq> {c..d}" apply safe unfolding mem_interval mem_ball dist_norm 
  4375       proof case goal1 thus ?case using component_le_norm[of x i] unfolding c_def d_def by auto qed
  4338       proof case goal1 thus ?case using Basis_le_norm[of i x] unfolding c_def d_def by (auto simp: setsum_negf) qed
  4376       note C(2)[OF this] then guess z .. note z = conjunctD2[OF this, unfolded s]
  4339       note C(2)[OF this] then guess z .. note z = conjunctD2[OF this, unfolded s]
  4377       note this[unfolded has_integral_restrict_closed_subintervals_eq[OF c_d]]
  4340       note this[unfolded has_integral_restrict_closed_subintervals_eq[OF c_d]]
  4378       hence "z = y" "norm (z - i) < norm (y - i)" apply- apply(rule has_integral_unique[OF _ y(1)]) .
  4341       hence "z = y" "norm (z - i) < norm (y - i)" apply- apply(rule has_integral_unique[OF _ y(1)]) .
  4379       thus False by auto qed
  4342       thus False by auto qed
  4380     thus ?l using y unfolding s by auto qed qed 
  4343     thus ?l using y unfolding s by auto qed qed 
  4381 
  4344 
  4382 (*lemma has_integral_trans[simp]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real" shows
       
  4383   "((\<lambda>x. vec1 (f x)) has_integral vec1 i) s \<longleftrightarrow> (f has_integral i) s"
       
  4384   unfolding has_integral'[unfolded has_integral] 
       
  4385 proof case goal1 thus ?case apply safe
       
  4386   apply(erule_tac x=e in allE,safe) apply(rule_tac x=B in exI,safe)
       
  4387   apply(erule_tac x=a in allE, erule_tac x=b in allE,safe) 
       
  4388   apply(rule_tac x="dest_vec1 z" in exI,safe) apply(erule_tac x=ea in allE,safe) 
       
  4389   apply(rule_tac x=d in exI,safe) apply(erule_tac x=p in allE,safe)
       
  4390   apply(subst(asm)(2) norm_vector_1) unfolding split_def
       
  4391   unfolding setsum_component Cart_nth.diff cond_value_iff[of dest_vec1]
       
  4392     Cart_nth.scaleR vec1_dest_vec1 zero_index apply assumption
       
  4393   apply(subst(asm)(2) norm_vector_1) by auto
       
  4394 next case goal2 thus ?case apply safe
       
  4395   apply(erule_tac x=e in allE,safe) apply(rule_tac x=B in exI,safe)
       
  4396   apply(erule_tac x=a in allE, erule_tac x=b in allE,safe) 
       
  4397   apply(rule_tac x="vec1 z" in exI,safe) apply(erule_tac x=ea in allE,safe) 
       
  4398   apply(rule_tac x=d in exI,safe) apply(erule_tac x=p in allE,safe)
       
  4399   apply(subst norm_vector_1) unfolding split_def
       
  4400   unfolding setsum_component Cart_nth.diff cond_value_iff[of dest_vec1]
       
  4401     Cart_nth.scaleR vec1_dest_vec1 zero_index apply assumption
       
  4402   apply(subst norm_vector_1) by auto qed
       
  4403 
       
  4404 lemma integral_trans[simp]: assumes "(f::'n::ordered_euclidean_space \<Rightarrow> real) integrable_on s"
       
  4405   shows "integral s (\<lambda>x. vec1 (f x)) = vec1 (integral s f)"
       
  4406   apply(rule integral_unique) using assms by auto
       
  4407 
       
  4408 lemma integrable_on_trans[simp]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real" shows
       
  4409   "(\<lambda>x. vec1 (f x)) integrable_on s \<longleftrightarrow> (f integrable_on s)"
       
  4410   unfolding integrable_on_def
       
  4411   apply(subst(2) vec1_dest_vec1(1)[THEN sym]) unfolding has_integral_trans
       
  4412   apply safe defer apply(rule_tac x="vec1 y" in exI) by auto *)
       
  4413 
       
  4414 lemma has_integral_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4345 lemma has_integral_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4415   assumes "(f has_integral i) s" "(g has_integral j) s"  "\<forall>x\<in>s. (f x) \<le> (g x)"
  4346   assumes "(f has_integral i) s" "(g has_integral j) s"  "\<forall>x\<in>s. (f x) \<le> (g x)"
  4416   shows "i \<le> j" using has_integral_component_le[OF assms(1-2), of 0] using assms(3) by auto
  4347   shows "i \<le> j"
       
  4348   using has_integral_component_le[OF _ assms(1-2), of 1] using assms(3) by auto
  4417 
  4349 
  4418 lemma integral_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4350 lemma integral_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4419   assumes "f integrable_on s" "g integrable_on s" "\<forall>x\<in>s. f x \<le> g x"
  4351   assumes "f integrable_on s" "g integrable_on s" "\<forall>x\<in>s. f x \<le> g x"
  4420   shows "integral s f \<le> integral s g"
  4352   shows "integral s f \<le> integral s g"
  4421   using has_integral_le[OF assms(1,2)[unfolded has_integral_integral] assms(3)] .
  4353   using has_integral_le[OF assms(1,2)[unfolded has_integral_integral] assms(3)] .
  4422 
  4354 
  4423 lemma has_integral_nonneg: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4355 lemma has_integral_nonneg: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4424   assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> i" 
  4356   assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> i" 
  4425   using has_integral_component_nonneg[of "f" "i" s 0]
  4357   using has_integral_component_nonneg[of 1 f i s]
  4426   unfolding o_def using assms by auto
  4358   unfolding o_def using assms by auto
  4427 
  4359 
  4428 lemma integral_nonneg: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4360 lemma integral_nonneg: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4429   assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> integral s f" 
  4361   assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> integral s f" 
  4430   using has_integral_nonneg[OF assms(1)[unfolded has_integral_integral] assms(2)] .
  4362   using has_integral_nonneg[OF assms(1)[unfolded has_integral_integral] assms(2)] .
  4517   SET_TAC[]);;*)
  4449   SET_TAC[]);;*)
  4518 
  4450 
  4519 subsection {* More lemmas that are useful later. *}
  4451 subsection {* More lemmas that are useful later. *}
  4520 
  4452 
  4521 lemma has_integral_subset_component_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  4453 lemma has_integral_subset_component_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  4522   assumes "s \<subseteq> t" "(f has_integral i) s" "(f has_integral j) t" "\<forall>x\<in>t. 0 \<le> f(x)$$k"
  4454   assumes k: "k\<in>Basis" and as: "s \<subseteq> t" "(f has_integral i) s" "(f has_integral j) t" "\<forall>x\<in>t. 0 \<le> f(x)\<bullet>k"
  4523   shows "i$$k \<le> j$$k"
  4455   shows "i\<bullet>k \<le> j\<bullet>k"
  4524 proof- note has_integral_restrict_univ[THEN sym, of f]
  4456 proof- note has_integral_restrict_univ[THEN sym, of f]
  4525   note assms(2-3)[unfolded this] note * = has_integral_component_le[OF this]
  4457   note as(2-3)[unfolded this] note * = has_integral_component_le[OF k this]
  4526   show ?thesis apply(rule *) using assms(1,4) by auto qed
  4458   show ?thesis apply(rule *) using as(1,4) by auto qed
  4527 
  4459 
  4528 lemma has_integral_subset_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4460 lemma has_integral_subset_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4529   assumes "s \<subseteq> t" "(f has_integral i) s" "(f has_integral j) t" "\<forall>x\<in>t. 0 \<le> f(x)"
  4461   assumes as: "s \<subseteq> t" "(f has_integral i) s" "(f has_integral j) t" "\<forall>x\<in>t. 0 \<le> f(x)"
  4530   shows "i \<le> j" using has_integral_subset_component_le[OF assms(1), of "f" "i" "j" 0] using assms by auto
  4462   shows "i \<le> j"
       
  4463   using has_integral_subset_component_le[OF _ assms(1), of 1 f i j] using assms by auto
  4531 
  4464 
  4532 lemma integral_subset_component_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  4465 lemma integral_subset_component_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  4533   assumes "s \<subseteq> t" "f integrable_on s" "f integrable_on t" "\<forall>x \<in> t. 0 \<le> f(x)$$k"
  4466   assumes "k\<in>Basis" "s \<subseteq> t" "f integrable_on s" "f integrable_on t" "\<forall>x \<in> t. 0 \<le> f(x)\<bullet>k"
  4534   shows "(integral s f)$$k \<le> (integral t f)$$k"
  4467   shows "(integral s f)\<bullet>k \<le> (integral t f)\<bullet>k"
  4535   apply(rule has_integral_subset_component_le) using assms by auto
  4468   apply(rule has_integral_subset_component_le) using assms by auto
  4536 
  4469 
  4537 lemma integral_subset_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4470 lemma integral_subset_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  4538   assumes "s \<subseteq> t" "f integrable_on s" "f integrable_on t" "\<forall>x \<in> t. 0 \<le> f(x)"
  4471   assumes "s \<subseteq> t" "f integrable_on s" "f integrable_on t" "\<forall>x \<in> t. 0 \<le> f(x)"
  4539   shows "(integral s f) \<le> (integral t f)"
  4472   shows "(integral s f) \<le> (integral t f)"
  4551   qed next
  4484   qed next
  4552   assume ?l note as = this[unfolded has_integral'[of f],rule_format]
  4485   assume ?l note as = this[unfolded has_integral'[of f],rule_format]
  4553   let ?f = "\<lambda>x. if x \<in> s then f x else 0"
  4486   let ?f = "\<lambda>x. if x \<in> s then f x else 0"
  4554   show ?r proof safe fix a b::"'n::ordered_euclidean_space"
  4487   show ?r proof safe fix a b::"'n::ordered_euclidean_space"
  4555     from as[OF zero_less_one] guess B .. note B=conjunctD2[OF this,rule_format]
  4488     from as[OF zero_less_one] guess B .. note B=conjunctD2[OF this,rule_format]
  4556     let ?a = "(\<chi>\<chi> i. min (a$$i) (-B))::'n::ordered_euclidean_space" and ?b = "(\<chi>\<chi> i. max (b$$i) B)::'n::ordered_euclidean_space"
  4489     let ?a = "\<Sum>i\<in>Basis. min (a\<bullet>i) (-B) *\<^sub>R i::'n" and ?b = "\<Sum>i\<in>Basis. max (b\<bullet>i) B *\<^sub>R i::'n"
  4557     show "?f integrable_on {a..b}" apply(rule integrable_subinterval[of _ ?a ?b])
  4490     show "?f integrable_on {a..b}" apply(rule integrable_subinterval[of _ ?a ?b])
  4558     proof- have "ball 0 B \<subseteq> {?a..?b}" apply safe unfolding mem_ball mem_interval dist_norm
  4491     proof- have "ball 0 B \<subseteq> {?a..?b}" apply safe unfolding mem_ball mem_interval dist_norm
  4559       proof case goal1 thus ?case using component_le_norm[of x i] by(auto simp add:field_simps) qed
  4492       proof case goal1 thus ?case using Basis_le_norm[of i x] by(auto simp add:field_simps) qed
  4560       from B(2)[OF this] guess z .. note conjunct1[OF this]
  4493       from B(2)[OF this] guess z .. note conjunct1[OF this]
  4561       thus "?f integrable_on {?a..?b}" unfolding integrable_on_def by auto
  4494       thus "?f integrable_on {?a..?b}" unfolding integrable_on_def by auto
  4562       show "{a..b} \<subseteq> {?a..?b}" apply safe unfolding mem_interval apply(rule,erule_tac x=i in allE) by auto qed
  4495       show "{a..b} \<subseteq> {?a..?b}" apply safe unfolding mem_interval apply(rule,erule_tac x=i in ballE) by auto qed
  4563 
  4496 
  4564     fix e::real assume "e>0" from as[OF this] guess B .. note B=conjunctD2[OF this,rule_format]
  4497     fix e::real assume "e>0" from as[OF this] guess B .. note B=conjunctD2[OF this,rule_format]
  4565     show "\<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b} \<longrightarrow>
  4498     show "\<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b} \<longrightarrow>
  4566                     norm (integral {a..b} (\<lambda>x. if x \<in> s then f x else 0) - i) < e"
  4499                     norm (integral {a..b} (\<lambda>x. if x \<in> s then f x else 0) - i) < e"
  4567     proof(rule,rule,rule B,safe) case goal1 from B(2)[OF this] guess z .. note z=conjunctD2[OF this]
  4500     proof(rule,rule,rule B,safe) case goal1 from B(2)[OF this] guess z .. note z=conjunctD2[OF this]
  4582     show ?case apply(rule,rule,rule B)
  4515     show ?case apply(rule,rule,rule B)
  4583     proof safe case goal1 show ?case apply(rule norm_triangle_half_l)
  4516     proof safe case goal1 show ?case apply(rule norm_triangle_half_l)
  4584         using B(2)[OF goal1(1)] B(2)[OF goal1(2)] by auto qed qed
  4517         using B(2)[OF goal1(1)] B(2)[OF goal1(2)] by auto qed qed
  4585         
  4518         
  4586 next assume ?r note as = conjunctD2[OF this,rule_format]
  4519 next assume ?r note as = conjunctD2[OF this,rule_format]
  4587   have "Cauchy (\<lambda>n. integral ({(\<chi>\<chi> i. - real n)::'n .. (\<chi>\<chi> i. real n)}) (\<lambda>x. if x \<in> s then f x else 0))"
  4520   let ?cube = "\<lambda>n. {(\<Sum>i\<in>Basis. - real n *\<^sub>R i)::'n .. (\<Sum>i\<in>Basis. real n *\<^sub>R i)} :: 'n set"
       
  4521   have "Cauchy (\<lambda>n. integral (?cube n) (\<lambda>x. if x \<in> s then f x else 0))"
  4588   proof(unfold Cauchy_def,safe) case goal1
  4522   proof(unfold Cauchy_def,safe) case goal1
  4589     from as(2)[OF this] guess B .. note B = conjunctD2[OF this,rule_format]
  4523     from as(2)[OF this] guess B .. note B = conjunctD2[OF this,rule_format]
  4590     from real_arch_simple[of B] guess N .. note N = this
  4524     from real_arch_simple[of B] guess N .. note N = this
  4591     { fix n assume n:"n \<ge> N" have "ball 0 B \<subseteq> {(\<chi>\<chi> i. - real n)::'n..\<chi>\<chi> i. real n}" apply safe
  4525     { fix n assume n:"n \<ge> N" have "ball 0 B \<subseteq> ?cube n" apply safe
  4592         unfolding mem_ball mem_interval dist_norm
  4526         unfolding mem_ball mem_interval dist_norm
  4593       proof case goal1 thus ?case using component_le_norm[of x i]
  4527       proof case goal1 thus ?case using Basis_le_norm[of i x] `i\<in>Basis`
  4594           using n N by(auto simp add:field_simps) qed }
  4528           using n N by(auto simp add:field_simps setsum_negf) qed }
  4595     thus ?case apply-apply(rule_tac x=N in exI) apply safe unfolding dist_norm apply(rule B(2)) by auto
  4529     thus ?case apply-apply(rule_tac x=N in exI) apply safe unfolding dist_norm apply(rule B(2)) by auto
  4596   qed from this[unfolded convergent_eq_cauchy[THEN sym]] guess i ..
  4530   qed from this[unfolded convergent_eq_cauchy[THEN sym]] guess i ..
  4597   note i = this[THEN LIMSEQ_D]
  4531   note i = this[THEN LIMSEQ_D]
  4598 
  4532 
  4599   show ?l unfolding integrable_on_def has_integral_alt'[of f] apply(rule_tac x=i in exI)
  4533   show ?l unfolding integrable_on_def has_integral_alt'[of f] apply(rule_tac x=i in exI)
  4609         apply(rule norm_triangle_half_l) apply(rule B(2)) defer apply(subst norm_minus_commute)
  4543         apply(rule norm_triangle_half_l) apply(rule B(2)) defer apply(subst norm_minus_commute)
  4610         apply(rule N[of n])
  4544         apply(rule N[of n])
  4611       proof safe show "N \<le> n" using n by auto
  4545       proof safe show "N \<le> n" using n by auto
  4612         fix x::"'n::ordered_euclidean_space" assume x:"x \<in> ball 0 B" hence "x\<in> ball 0 ?B" by auto
  4546         fix x::"'n::ordered_euclidean_space" assume x:"x \<in> ball 0 B" hence "x\<in> ball 0 ?B" by auto
  4613         thus "x\<in>{a..b}" using ab by blast 
  4547         thus "x\<in>{a..b}" using ab by blast 
  4614         show "x\<in>{\<chi>\<chi> i. - real n..\<chi>\<chi> i. real n}" using x unfolding mem_interval mem_ball dist_norm apply-
  4548         show "x\<in>?cube n" using x unfolding mem_interval mem_ball dist_norm apply-
  4615         proof case goal1 thus ?case using component_le_norm[of x i]
  4549         proof case goal1 thus ?case using Basis_le_norm[of i x] `i\<in>Basis`
  4616             using n by(auto simp add:field_simps) qed qed qed qed qed
  4550             using n by(auto simp add:field_simps setsum_negf) qed qed qed qed qed
  4617 
  4551 
  4618 lemma integrable_altD: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  4552 lemma integrable_altD: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  4619   assumes "f integrable_on s"
  4553   assumes "f integrable_on s"
  4620   shows "\<And>a b. (\<lambda>x. if x \<in> s then f x else 0) integrable_on {a..b}"
  4554   shows "\<And>a b. (\<lambda>x. if x \<in> s then f x else 0) integrable_on {a..b}"
  4621   "\<And>e. e>0 \<Longrightarrow> \<exists>B>0. \<forall>a b c d. ball 0 B \<subseteq> {a..b} \<and> ball 0 B \<subseteq> {c..d}
  4555   "\<And>e. e>0 \<Longrightarrow> \<exists>B>0. \<forall>a b c d. ball 0 B \<subseteq> {a..b} \<and> ball 0 B \<subseteq> {c..d}
  4674     from assms[rule_format,OF this] guess g h i j apply-by(erule exE conjE)+ note obt=this
  4608     from assms[rule_format,OF this] guess g h i j apply-by(erule exE conjE)+ note obt=this
  4675     note obt(1)[unfolded has_integral_alt'[of g]] note conjunctD2[OF this, rule_format]
  4609     note obt(1)[unfolded has_integral_alt'[of g]] note conjunctD2[OF this, rule_format]
  4676     note g = this(1) and this(2)[OF *] from this(2) guess B1 .. note B1 = conjunctD2[OF this,rule_format]
  4610     note g = this(1) and this(2)[OF *] from this(2) guess B1 .. note B1 = conjunctD2[OF this,rule_format]
  4677     note obt(2)[unfolded has_integral_alt'[of h]] note conjunctD2[OF this, rule_format]
  4611     note obt(2)[unfolded has_integral_alt'[of h]] note conjunctD2[OF this, rule_format]
  4678     note h = this(1) and this(2)[OF *] from this(2) guess B2 .. note B2 = conjunctD2[OF this,rule_format]
  4612     note h = this(1) and this(2)[OF *] from this(2) guess B2 .. note B2 = conjunctD2[OF this,rule_format]
  4679     def c \<equiv> "(\<chi>\<chi> i. min (a$$i) (- (max B1 B2)))::'n" and d \<equiv> "(\<chi>\<chi> i. max (b$$i) (max B1 B2))::'n"
  4613     def c \<equiv> "\<Sum>i\<in>Basis. min (a\<bullet>i) (- (max B1 B2)) *\<^sub>R i::'n"
  4680     have *:"ball 0 B1 \<subseteq> {c..d}" "ball 0 B2 \<subseteq> {c..d}" apply safe unfolding mem_ball mem_interval dist_norm
  4614     def d \<equiv> "\<Sum>i\<in>Basis. max (b\<bullet>i) (max B1 B2) *\<^sub>R i::'n"
  4681     proof(rule_tac[!] allI)
  4615     have *:"ball 0 B1 \<subseteq> {c..d}" "ball 0 B2 \<subseteq> {c..d}"
  4682       case goal1 thus ?case using component_le_norm[of x i] unfolding c_def d_def by auto next
  4616       apply safe unfolding mem_ball mem_interval dist_norm
  4683       case goal2 thus ?case using component_le_norm[of x i] unfolding c_def d_def by auto qed
  4617     proof(rule_tac[!] ballI)
       
  4618       case goal1 thus ?case using Basis_le_norm[of i x] unfolding c_def d_def by auto next
       
  4619       case goal2 thus ?case using Basis_le_norm[of i x] unfolding c_def d_def by auto qed
  4684     have **:"\<And>ch cg ag ah::real. norm(ah - ag) \<le> norm(ch - cg) \<Longrightarrow> norm(cg - i) < e / 4 \<Longrightarrow>
  4620     have **:"\<And>ch cg ag ah::real. norm(ah - ag) \<le> norm(ch - cg) \<Longrightarrow> norm(cg - i) < e / 4 \<Longrightarrow>
  4685       norm(ch - j) < e / 4 \<Longrightarrow> norm(ag - ah) < e"
  4621       norm(ch - j) < e / 4 \<Longrightarrow> norm(ag - ah) < e"
  4686       using obt(3) unfolding real_norm_def by arith 
  4622       using obt(3) unfolding real_norm_def by arith 
  4687     show ?case apply(rule_tac x="\<lambda>x. if x \<in> s then g x else 0" in exI)
  4623     show ?case apply(rule_tac x="\<lambda>x. if x \<in> s then g x else 0" in exI)
  4688                apply(rule_tac x="\<lambda>x. if x \<in> s then h x else 0" in exI)
  4624                apply(rule_tac x="\<lambda>x. if x \<in> s then h x else 0" in exI)
  4698            \<le> norm (integral {c..d} (\<lambda>x. if x \<in> s then h x else 0) -
  4634            \<le> norm (integral {c..d} (\<lambda>x. if x \<in> s then h x else 0) -
  4699                    integral {c..d} (\<lambda>x. if x \<in> s then g x else 0))"
  4635                    integral {c..d} (\<lambda>x. if x \<in> s then g x else 0))"
  4700         unfolding integral_sub[OF h g,THEN sym] real_norm_def apply(subst **) defer apply(subst **) defer
  4636         unfolding integral_sub[OF h g,THEN sym] real_norm_def apply(subst **) defer apply(subst **) defer
  4701         apply(rule has_integral_subset_le) defer apply(rule integrable_integral integrable_sub h g)+
  4637         apply(rule has_integral_subset_le) defer apply(rule integrable_integral integrable_sub h g)+
  4702       proof safe fix x assume "x\<in>{a..b}" thus "x\<in>{c..d}" unfolding mem_interval c_def d_def
  4638       proof safe fix x assume "x\<in>{a..b}" thus "x\<in>{c..d}" unfolding mem_interval c_def d_def
  4703           apply - apply rule apply(erule_tac x=i in allE) by auto
  4639           apply - apply rule apply(erule_tac x=i in ballE) by auto
  4704       qed(insert obt(4), auto) qed(insert obt(4), auto) qed note interv = this
  4640       qed(insert obt(4), auto) qed(insert obt(4), auto) qed note interv = this
  4705 
  4641 
  4706   show ?thesis unfolding integrable_alt[of f] apply safe apply(rule interv)
  4642   show ?thesis unfolding integrable_alt[of f] apply safe apply(rule interv)
  4707   proof- case goal1 hence *:"e/3 > 0" by auto
  4643   proof- case goal1 hence *:"e/3 > 0" by auto
  4708     from assms[rule_format,OF this] guess g h i j apply-by(erule exE conjE)+ note obt=this
  4644     from assms[rule_format,OF this] guess g h i j apply-by(erule exE conjE)+ note obt=this
  5017   "bounded {integral {a..b} (f k) | k . k \<in> UNIV}"
  4953   "bounded {integral {a..b} (f k) | k . k \<in> UNIV}"
  5018   shows "g integrable_on {a..b} \<and> ((\<lambda>k. integral ({a..b}) (f k)) ---> integral ({a..b}) g) sequentially"
  4954   shows "g integrable_on {a..b} \<and> ((\<lambda>k. integral ({a..b}) (f k)) ---> integral ({a..b}) g) sequentially"
  5019 proof(case_tac[!] "content {a..b} = 0") assume as:"content {a..b} = 0"
  4955 proof(case_tac[!] "content {a..b} = 0") assume as:"content {a..b} = 0"
  5020   show ?thesis using integrable_on_null[OF as] unfolding integral_null[OF as] using tendsto_const by auto
  4956   show ?thesis using integrable_on_null[OF as] unfolding integral_null[OF as] using tendsto_const by auto
  5021 next assume ab:"content {a..b} \<noteq> 0"
  4957 next assume ab:"content {a..b} \<noteq> 0"
  5022   have fg:"\<forall>x\<in>{a..b}. \<forall> k. (f k x) $$ 0 \<le> (g x) $$ 0"
  4958   have fg:"\<forall>x\<in>{a..b}. \<forall> k. (f k x) \<bullet> 1 \<le> (g x) \<bullet> 1"
  5023   proof safe case goal1 note assms(3)[rule_format,OF this]
  4959   proof safe case goal1 note assms(3)[rule_format,OF this]
  5024     note * = Lim_component_ge[OF this trivial_limit_sequentially]
  4960     note * = Lim_component_ge[OF this trivial_limit_sequentially]
  5025     show ?case apply(rule *) unfolding eventually_sequentially
  4961     show ?case apply(rule *) unfolding eventually_sequentially
  5026       apply(rule_tac x=k in exI) apply- apply(rule transitive_stepwise_le)
  4962       apply(rule_tac x=k in exI) apply- apply(rule transitive_stepwise_le)
  5027       using assms(2)[rule_format,OF goal1] by auto qed
  4963       using assms(2)[rule_format,OF goal1] by auto qed
  5028   have "\<exists>i. ((\<lambda>k. integral ({a..b}) (f k)) ---> i) sequentially"
  4964   have "\<exists>i. ((\<lambda>k. integral ({a..b}) (f k)) ---> i) sequentially"
  5029     apply(rule bounded_increasing_convergent) defer
  4965     apply(rule bounded_increasing_convergent) defer
  5030     apply rule apply(rule integral_le) apply safe
  4966     apply rule apply(rule integral_le) apply safe
  5031     apply(rule assms(1-2)[rule_format])+ using assms(4) by auto
  4967     apply(rule assms(1-2)[rule_format])+ using assms(4) by auto
  5032   then guess i .. note i=this
  4968   then guess i .. note i=this
  5033   have i':"\<And>k. (integral({a..b}) (f k)) \<le> i$$0"
  4969   have i':"\<And>k. (integral({a..b}) (f k)) \<le> i\<bullet>1"
  5034     apply(rule Lim_component_ge,rule i) apply(rule trivial_limit_sequentially)
  4970     apply(rule Lim_component_ge,rule i) apply(rule trivial_limit_sequentially)
  5035     unfolding eventually_sequentially apply(rule_tac x=k in exI)
  4971     unfolding eventually_sequentially apply(rule_tac x=k in exI)
  5036     apply(rule transitive_stepwise_le) prefer 3 unfolding Eucl_real_simps apply(rule integral_le)
  4972     apply(rule transitive_stepwise_le) prefer 3 unfolding inner_simps real_inner_1_right apply(rule integral_le)
  5037     apply(rule assms(1-2)[rule_format])+ using assms(2) by auto
  4973     apply(rule assms(1-2)[rule_format])+ using assms(2) by auto
  5038 
  4974 
  5039   have "(g has_integral i) {a..b}" unfolding has_integral
  4975   have "(g has_integral i) {a..b}" unfolding has_integral
  5040   proof safe case goal1 note e=this
  4976   proof safe case goal1 note e=this
  5041     hence "\<forall>k. (\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow>
  4977     hence "\<forall>k. (\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow>
  5042              norm ((\<Sum>(x, ka)\<in>p. content ka *\<^sub>R f k x) - integral {a..b} (f k)) < e / 2 ^ (k + 2)))"
  4978              norm ((\<Sum>(x, ka)\<in>p. content ka *\<^sub>R f k x) - integral {a..b} (f k)) < e / 2 ^ (k + 2)))"
  5043       apply-apply(rule,rule assms(1)[unfolded has_integral_integral has_integral,rule_format])
  4979       apply-apply(rule,rule assms(1)[unfolded has_integral_integral has_integral,rule_format])
  5044       apply(rule divide_pos_pos) by auto
  4980       apply(rule divide_pos_pos) by auto
  5045     from choice[OF this] guess c .. note c=conjunctD2[OF this[rule_format],rule_format]
  4981     from choice[OF this] guess c .. note c=conjunctD2[OF this[rule_format],rule_format]
  5046 
  4982 
  5047     have "\<exists>r. \<forall>k\<ge>r. 0 \<le> i$$0 - (integral {a..b} (f k)) \<and> i$$0 - (integral {a..b} (f k)) < e / 4"
  4983     have "\<exists>r. \<forall>k\<ge>r. 0 \<le> i\<bullet>1 - (integral {a..b} (f k)) \<and> i\<bullet>1 - (integral {a..b} (f k)) < e / 4"
  5048     proof- case goal1 have "e/4 > 0" using e by auto
  4984     proof- case goal1 have "e/4 > 0" using e by auto
  5049       from LIMSEQ_D [OF i this] guess r ..
  4985       from LIMSEQ_D [OF i this] guess r ..
  5050       thus ?case apply(rule_tac x=r in exI) apply rule
  4986       thus ?case apply(rule_tac x=r in exI) apply rule
  5051         apply(erule_tac x=k in allE)
  4987         apply(erule_tac x=k in allE)
  5052       proof- case goal1 thus ?case using i'[of k] by auto qed qed
  4988       proof- case goal1 thus ?case using i'[of k] by auto qed qed
  5053     then guess r .. note r=conjunctD2[OF this[rule_format]]
  4989     then guess r .. note r=conjunctD2[OF this[rule_format]]
  5054 
  4990 
  5055     have "\<forall>x\<in>{a..b}. \<exists>n\<ge>r. \<forall>k\<ge>n. 0 \<le> (g x)$$0 - (f k x)$$0 \<and>
  4991     have "\<forall>x\<in>{a..b}. \<exists>n\<ge>r. \<forall>k\<ge>n. 0 \<le> (g x)\<bullet>1 - (f k x)\<bullet>1 \<and>
  5056            (g x)$$0 - (f k x)$$0 < e / (4 * content({a..b}))"
  4992            (g x)\<bullet>1 - (f k x)\<bullet>1 < e / (4 * content({a..b}))"
  5057     proof case goal1 have "e / (4 * content {a..b}) > 0" apply(rule divide_pos_pos,fact)
  4993     proof case goal1 have "e / (4 * content {a..b}) > 0" apply(rule divide_pos_pos,fact)
  5058         using ab content_pos_le[of a b] by auto
  4994         using ab content_pos_le[of a b] by auto
  5059       from assms(3)[rule_format, OF goal1, THEN LIMSEQ_D, OF this]
  4995       from assms(3)[rule_format, OF goal1, THEN LIMSEQ_D, OF this]
  5060       guess n .. note n=this
  4996       guess n .. note n=this
  5061       thus ?case apply(rule_tac x="n + r" in exI) apply safe apply(erule_tac[2-3] x=k in allE)
  4997       thus ?case apply(rule_tac x="n + r" in exI) apply safe apply(erule_tac[2-3] x=k in allE)
  5062         unfolding dist_real_def using fg[rule_format,OF goal1] by(auto simp add:field_simps) qed
  4998         unfolding dist_real_def using fg[rule_format,OF goal1]
       
  4999         by (auto simp add:field_simps) qed
  5063     from bchoice[OF this] guess m .. note m=conjunctD2[OF this[rule_format],rule_format]
  5000     from bchoice[OF this] guess m .. note m=conjunctD2[OF this[rule_format],rule_format]
  5064     def d \<equiv> "\<lambda>x. c (m x) x" 
  5001     def d \<equiv> "\<lambda>x. c (m x) x" 
  5065 
  5002 
  5066     show ?case apply(rule_tac x=d in exI)
  5003     show ?case apply(rule_tac x=d in exI)
  5067     proof safe show "gauge d" using c(1) unfolding gauge_def d_def by auto
  5004     proof safe show "gauge d" using c(1) unfolding gauge_def d_def by auto
  5116                unfolding d_def by auto qed
  5053                unfolding d_def by auto qed
  5117          qed(insert s, auto)
  5054          qed(insert s, auto)
  5118 
  5055 
  5119        next case goal3
  5056        next case goal3
  5120          note comb = integral_combine_tagged_division_topdown[OF assms(1)[rule_format] p(1)]
  5057          note comb = integral_combine_tagged_division_topdown[OF assms(1)[rule_format] p(1)]
  5121          have *:"\<And>sr sx ss ks kr::real. kr = sr \<longrightarrow> ks = ss \<longrightarrow> ks \<le> i \<and> sr \<le> sx \<and> sx \<le> ss \<and> 0 \<le> i$$0 - kr$$0
  5058          have *:"\<And>sr sx ss ks kr::real. kr = sr \<longrightarrow> ks = ss \<longrightarrow> ks \<le> i \<and> sr \<le> sx \<and> sx \<le> ss \<and> 0 \<le> i\<bullet>1 - kr\<bullet>1
  5122            \<and> i$$0 - kr$$0 < e/4 \<longrightarrow> abs(sx - i) < e/4" by auto 
  5059            \<and> i\<bullet>1 - kr\<bullet>1 < e/4 \<longrightarrow> abs(sx - i) < e/4" by auto 
  5123          show ?case unfolding real_norm_def apply(rule *[rule_format],safe)
  5060          show ?case unfolding real_norm_def apply(rule *[rule_format],safe)
  5124            apply(rule comb[of r],rule comb[of s]) apply(rule i'[unfolded Eucl_real_simps]) 
  5061            apply(rule comb[of r],rule comb[of s]) apply(rule i'[unfolded real_inner_1_right]) 
  5125            apply(rule_tac[1-2] setsum_mono) unfolding split_paired_all split_conv
  5062            apply(rule_tac[1-2] setsum_mono) unfolding split_paired_all split_conv
  5126            apply(rule_tac[1-2] integral_le[OF ])
  5063            apply(rule_tac[1-2] integral_le[OF ])
  5127          proof safe show "0 \<le> i$$0 - (integral {a..b} (f r))$$0" using r(1) by auto
  5064          proof safe show "0 \<le> i\<bullet>1 - (integral {a..b} (f r))\<bullet>1" using r(1) by auto
  5128            show "i$$0 - (integral {a..b} (f r))$$0 < e / 4" using r(2) by auto
  5065            show "i\<bullet>1 - (integral {a..b} (f r))\<bullet>1 < e / 4" using r(2) by auto
  5129            fix x k assume xk:"(x,k)\<in>p" from p'(4)[OF this] guess u v apply-by(erule exE)+ note uv=this
  5066            fix x k assume xk:"(x,k)\<in>p" from p'(4)[OF this] guess u v apply-by(erule exE)+ note uv=this
  5130            show "f r integrable_on k" "f s integrable_on k" "f (m x) integrable_on k" "f (m x) integrable_on k" 
  5067            show "f r integrable_on k" "f s integrable_on k" "f (m x) integrable_on k" "f (m x) integrable_on k" 
  5131              unfolding uv apply(rule_tac[!] integrable_on_subinterval[OF assms(1)[rule_format]])
  5068              unfolding uv apply(rule_tac[!] integrable_on_subinterval[OF assms(1)[rule_format]])
  5132              using p'(3)[OF xk] unfolding uv by auto 
  5069              using p'(3)[OF xk] unfolding uv by auto 
  5133            fix y assume "y\<in>k" hence "y\<in>{a..b}" using p'(3)[OF xk] by auto
  5070            fix y assume "y\<in>k" hence "y\<in>{a..b}" using p'(3)[OF xk] by auto
  5145   shows "g integrable_on s \<and> ((\<lambda>k. integral s (f k)) ---> integral s g) sequentially"
  5082   shows "g integrable_on s \<and> ((\<lambda>k. integral s (f k)) ---> integral s g) sequentially"
  5146 proof- have lem:"\<And>f::nat \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> real. \<And> g s. \<forall>k.\<forall>x\<in>s. 0 \<le> (f k x) \<Longrightarrow> \<forall>k. (f k) integrable_on s \<Longrightarrow>
  5083 proof- have lem:"\<And>f::nat \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> real. \<And> g s. \<forall>k.\<forall>x\<in>s. 0 \<le> (f k x) \<Longrightarrow> \<forall>k. (f k) integrable_on s \<Longrightarrow>
  5147     \<forall>k. \<forall>x\<in>s. (f k x) \<le> (f (Suc k) x) \<Longrightarrow> \<forall>x\<in>s. ((\<lambda>k. f k x) ---> g x) sequentially  \<Longrightarrow>
  5084     \<forall>k. \<forall>x\<in>s. (f k x) \<le> (f (Suc k) x) \<Longrightarrow> \<forall>x\<in>s. ((\<lambda>k. f k x) ---> g x) sequentially  \<Longrightarrow>
  5148     bounded {integral s (f k)| k. True} \<Longrightarrow> g integrable_on s \<and> ((\<lambda>k. integral s (f k)) ---> integral s g) sequentially"
  5085     bounded {integral s (f k)| k. True} \<Longrightarrow> g integrable_on s \<and> ((\<lambda>k. integral s (f k)) ---> integral s g) sequentially"
  5149   proof- case goal1 note assms=this[rule_format]
  5086   proof- case goal1 note assms=this[rule_format]
  5150     have "\<forall>x\<in>s. \<forall>k. (f k x)$$0 \<le> (g x)$$0" apply safe apply(rule Lim_component_ge)
  5087     have "\<forall>x\<in>s. \<forall>k. (f k x)\<bullet>1 \<le> (g x)\<bullet>1" apply safe apply(rule Lim_component_ge)
  5151       apply(rule goal1(4)[rule_format],assumption) apply(rule trivial_limit_sequentially)
  5088       apply(rule goal1(4)[rule_format],assumption) apply(rule trivial_limit_sequentially)
  5152       unfolding eventually_sequentially apply(rule_tac x=k in exI)
  5089       unfolding eventually_sequentially apply(rule_tac x=k in exI)
  5153       apply(rule transitive_stepwise_le) using goal1(3) by auto note fg=this[rule_format]
  5090       apply(rule transitive_stepwise_le) using goal1(3) by auto note fg=this[rule_format]
  5154 
  5091 
  5155     have "\<exists>i. ((\<lambda>k. integral s (f k)) ---> i) sequentially" apply(rule bounded_increasing_convergent)
  5092     have "\<exists>i. ((\<lambda>k. integral s (f k)) ---> i) sequentially" apply(rule bounded_increasing_convergent)
  5156       apply(rule goal1(5)) apply(rule,rule integral_le) apply(rule goal1(2)[rule_format])+
  5093       apply(rule goal1(5)) apply(rule,rule integral_le) apply(rule goal1(2)[rule_format])+
  5157       using goal1(3) by auto then guess i .. note i=this
  5094       using goal1(3) by auto then guess i .. note i=this
  5158     have "\<And>k. \<forall>x\<in>s. \<forall>n\<ge>k. f k x \<le> f n x" apply(rule,rule transitive_stepwise_le) using goal1(3) by auto
  5095     have "\<And>k. \<forall>x\<in>s. \<forall>n\<ge>k. f k x \<le> f n x" apply(rule,rule transitive_stepwise_le) using goal1(3) by auto
  5159     hence i':"\<forall>k. (integral s (f k))$$0 \<le> i$$0" apply-apply(rule,rule Lim_component_ge)
  5096     hence i':"\<forall>k. (integral s (f k))\<bullet>1 \<le> i\<bullet>1" apply-apply(rule,rule Lim_component_ge)
  5160       apply(rule i,rule trivial_limit_sequentially) unfolding eventually_sequentially
  5097       apply(rule i,rule trivial_limit_sequentially) unfolding eventually_sequentially
  5161       apply(rule_tac x=k in exI,safe) apply(rule integral_component_le)
  5098       apply(rule_tac x=k in exI,safe) apply(rule integral_component_le)
       
  5099       apply simp
  5162       apply(rule goal1(2)[rule_format])+ by auto 
  5100       apply(rule goal1(2)[rule_format])+ by auto 
  5163 
  5101 
  5164     note int = assms(2)[unfolded integrable_alt[of _ s],THEN conjunct1,rule_format]
  5102     note int = assms(2)[unfolded integrable_alt[of _ s],THEN conjunct1,rule_format]
  5165     have ifif:"\<And>k t. (\<lambda>x. if x \<in> t then if x \<in> s then f k x else 0 else 0) =
  5103     have ifif:"\<And>k t. (\<lambda>x. if x \<in> t then if x \<in> s then f k x else 0 else 0) =
  5166       (\<lambda>x. if x \<in> t\<inter>s then f k x else 0)" apply(rule ext) by auto
  5104       (\<lambda>x. if x \<in> t\<inter>s then f k x else 0)" apply(rule ext) by auto
  5197         from LIMSEQ_D [OF g(2)[of a b] this] guess M .. note M=this
  5135         from LIMSEQ_D [OF g(2)[of a b] this] guess M .. note M=this
  5198         have **:"norm (integral {a..b} (\<lambda>x. if x \<in> s then f N x else 0) - i) < e/2"
  5136         have **:"norm (integral {a..b} (\<lambda>x. if x \<in> s then f N x else 0) - i) < e/2"
  5199           apply(rule norm_triangle_half_l) using B(2)[rule_format,OF ab] N[rule_format,of N]
  5137           apply(rule norm_triangle_half_l) using B(2)[rule_format,OF ab] N[rule_format,of N]
  5200           apply-defer apply(subst norm_minus_commute) by auto
  5138           apply-defer apply(subst norm_minus_commute) by auto
  5201         have *:"\<And>f1 f2 g. abs(f1 - i) < e / 2 \<longrightarrow> abs(f2 - g) < e / 2 \<longrightarrow> f1 \<le> f2 \<longrightarrow> f2 \<le> i
  5139         have *:"\<And>f1 f2 g. abs(f1 - i) < e / 2 \<longrightarrow> abs(f2 - g) < e / 2 \<longrightarrow> f1 \<le> f2 \<longrightarrow> f2 \<le> i
  5202           \<longrightarrow> abs(g - i) < e" unfolding Eucl_real_simps by arith
  5140           \<longrightarrow> abs(g - i) < e" unfolding real_inner_1_right by arith
  5203         show "norm (integral {a..b} (\<lambda>x. if x \<in> s then g x else 0) - i) < e" 
  5141         show "norm (integral {a..b} (\<lambda>x. if x \<in> s then g x else 0) - i) < e" 
  5204           unfolding real_norm_def apply(rule *[rule_format])
  5142           unfolding real_norm_def apply(rule *[rule_format])
  5205           apply(rule **[unfolded real_norm_def])
  5143           apply(rule **[unfolded real_norm_def])
  5206           apply(rule M[rule_format,of "M + N",unfolded real_norm_def]) apply(rule le_add1)
  5144           apply(rule M[rule_format,of "M + N",unfolded real_norm_def]) apply(rule le_add1)
  5207           apply(rule integral_le[OF int int]) defer
  5145           apply(rule integral_le[OF int int]) defer
  5208           apply(rule order_trans[OF _ i'[rule_format,of "M + N",unfolded Eucl_real_simps]])
  5146           apply(rule order_trans[OF _ i'[rule_format,of "M + N",unfolded real_inner_1_right]])
  5209         proof safe case goal2 have "\<And>m. x\<in>s \<Longrightarrow> \<forall>n\<ge>m. (f m x)$$0 \<le> (f n x)$$0"
  5147         proof safe case goal2 have "\<And>m. x\<in>s \<Longrightarrow> \<forall>n\<ge>m. (f m x)\<bullet>1 \<le> (f n x)\<bullet>1"
  5210             apply(rule transitive_stepwise_le) using assms(3) by auto thus ?case by auto
  5148             apply(rule transitive_stepwise_le) using assms(3) by auto thus ?case by auto
  5211         next case goal1 show ?case apply(subst integral_restrict_univ[THEN sym,OF int]) 
  5149         next case goal1 show ?case apply(subst integral_restrict_univ[THEN sym,OF int]) 
  5212             unfolding ifif integral_restrict_univ[OF int']
  5150             unfolding ifif integral_restrict_univ[OF int']
  5213             apply(rule integral_subset_le[OF _ int']) using assms by auto
  5151             apply(rule integral_subset_le[OF _ int']) using assms by auto
  5214         qed qed qed 
  5152         qed qed qed 
  5321     defer apply(rule w(2)[unfolded real_norm_def],rule z(2))
  5259     defer apply(rule w(2)[unfolded real_norm_def],rule z(2))
  5322     apply safe apply(case_tac "x\<in>s") unfolding if_P apply(rule assms(3)[rule_format]) by auto qed
  5260     apply safe apply(case_tac "x\<in>s") unfolding if_P apply(rule assms(3)[rule_format]) by auto qed
  5323 
  5261 
  5324 lemma integral_norm_bound_integral_component: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  5262 lemma integral_norm_bound_integral_component: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  5325   fixes g::"'n => 'b::ordered_euclidean_space"
  5263   fixes g::"'n => 'b::ordered_euclidean_space"
  5326   assumes "f integrable_on s" "g integrable_on s"  "\<forall>x\<in>s. norm(f x) \<le> (g x)$$k"
  5264   assumes "f integrable_on s" "g integrable_on s"  "\<forall>x\<in>s. norm(f x) \<le> (g x)\<bullet>k"
  5327   shows "norm(integral s f) \<le> (integral s g)$$k"
  5265   shows "norm(integral s f) \<le> (integral s g)\<bullet>k"
  5328 proof- have "norm (integral s f) \<le> integral s ((\<lambda>x. x $$ k) o g)"
  5266 proof- have "norm (integral s f) \<le> integral s ((\<lambda>x. x \<bullet> k) o g)"
  5329     apply(rule integral_norm_bound_integral[OF assms(1)])
  5267     apply(rule integral_norm_bound_integral[OF assms(1)])
  5330     apply(rule integrable_linear[OF assms(2)],rule)
  5268     apply(rule integrable_linear[OF assms(2)],rule)
  5331     unfolding o_def by(rule assms)
  5269     unfolding o_def by(rule assms)
  5332   thus ?thesis unfolding o_def integral_component_eq[OF assms(2)] . qed
  5270   thus ?thesis unfolding o_def integral_component_eq[OF assms(2)] . qed
  5333 
  5271 
  5334 lemma has_integral_norm_bound_integral_component: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  5272 lemma has_integral_norm_bound_integral_component: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  5335   fixes g::"'n => 'b::ordered_euclidean_space"
  5273   fixes g::"'n => 'b::ordered_euclidean_space"
  5336   assumes "(f has_integral i) s" "(g has_integral j) s" "\<forall>x\<in>s. norm(f x) \<le> (g x)$$k"
  5274   assumes "(f has_integral i) s" "(g has_integral j) s" "\<forall>x\<in>s. norm(f x) \<le> (g x)\<bullet>k"
  5337   shows "norm(i) \<le> j$$k" using integral_norm_bound_integral_component[of f s g k]
  5275   shows "norm(i) \<le> j\<bullet>k" using integral_norm_bound_integral_component[of f s g k]
  5338   unfolding integral_unique[OF assms(1)] integral_unique[OF assms(2)]
  5276   unfolding integral_unique[OF assms(1)] integral_unique[OF assms(2)]
  5339   using assms by auto
  5277   using assms by auto
  5340 
  5278 
  5341 lemma absolutely_integrable_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  5279 lemma absolutely_integrable_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  5342   assumes "f absolutely_integrable_on s"
  5280   assumes "f absolutely_integrable_on s"
  5740 lemma absolutely_integrable_setsum: fixes f::"'a \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  5678 lemma absolutely_integrable_setsum: fixes f::"'a \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  5741   assumes "finite t" "\<And>a. a \<in> t \<Longrightarrow> (f a) absolutely_integrable_on s"
  5679   assumes "finite t" "\<And>a. a \<in> t \<Longrightarrow> (f a) absolutely_integrable_on s"
  5742   shows "(\<lambda>x. setsum (\<lambda>a. f a x) t) absolutely_integrable_on s"
  5680   shows "(\<lambda>x. setsum (\<lambda>a. f a x) t) absolutely_integrable_on s"
  5743   using assms(1,2) apply induct defer apply(subst setsum.insert) apply assumption+ by(rule,auto)
  5681   using assms(1,2) apply induct defer apply(subst setsum.insert) apply assumption+ by(rule,auto)
  5744 
  5682 
  5745 lemma absolutely_integrable_vector_abs: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  5683 lemma bounded_linear_setsum:
  5746   assumes "f absolutely_integrable_on s"
  5684   fixes f :: "'i \<Rightarrow> 'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
  5747   shows "(\<lambda>x. (\<chi>\<chi> i. abs(f x$$i))::'c::ordered_euclidean_space) absolutely_integrable_on s"
  5685   assumes f: "\<And>i. i\<in>I \<Longrightarrow> bounded_linear (f i)"
  5748 proof- have *:"\<And>x. ((\<chi>\<chi> i. abs(f x$$i))::'c::ordered_euclidean_space) = (setsum (\<lambda>i.
  5686   shows "bounded_linear (\<lambda>x. \<Sum>i\<in>I. f i x)"
  5749     (((\<lambda>y. (\<chi>\<chi> j. if j = i then y else 0)) o
  5687 proof cases
  5750     (((\<lambda>x. (norm((\<chi>\<chi> j. if j = i then x$$i else 0)::'c::ordered_euclidean_space))) o f))) x)) {..<DIM('c)})"
  5688   assume "finite I" from this f show ?thesis
  5751     unfolding euclidean_eq[where 'a='c] euclidean_component_setsum apply safe
  5689     by (induct I) (auto intro!: bounded_linear_add bounded_linear_zero)
  5752     unfolding euclidean_lambda_beta'
  5690 qed (simp add: bounded_linear_zero)
  5753   proof- case goal1 have *:"\<And>i xa. ((if i = xa then f x $$ xa else 0) * (if i = xa then f x $$ xa else 0)) =
  5691 
  5754       (if i = xa then (f x $$ xa) * (f x $$ xa) else 0)" by auto
  5692 lemma absolutely_integrable_vector_abs:
  5755     have *:"\<And>xa. norm ((\<chi>\<chi> j. if j = xa then f x $$ xa else 0)::'c) = (if xa<DIM('c) then abs (f x $$ xa) else 0)"
  5693   fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  5756       unfolding norm_eq_sqrt_inner euclidean_inner[where 'a='c]
  5694   fixes T :: "'c::ordered_euclidean_space \<Rightarrow> 'b"
  5757       by(auto simp add:setsum_delta[OF finite_lessThan] *)
  5695   assumes f: "f absolutely_integrable_on s"
  5758     have "\<bar>f x $$ i\<bar> = (setsum (\<lambda>k. if k = i then abs ((f x)$$i) else 0) {..<DIM('c)})"
  5696   shows "(\<lambda>x. (\<Sum>i\<in>Basis. abs(f x\<bullet>T i) *\<^sub>R i)) absolutely_integrable_on s"
  5759       unfolding setsum_delta[OF finite_lessThan] using goal1 by auto
  5697     (is "?Tf absolutely_integrable_on s")
  5760     also have "... = (\<Sum>xa<DIM('c). ((\<lambda>y. (\<chi>\<chi> j. if j = xa then y else 0)::'c) \<circ>
  5698 proof -
  5761                       (\<lambda>x. (norm ((\<chi>\<chi> j. if j = xa then x $$ xa else 0)::'c))) \<circ> f) x $$ i)"
  5699   have if_distrib: "\<And>P A B x. (if P then A else B) *\<^sub>R x = (if P then A *\<^sub>R x else B *\<^sub>R x)"
  5762       unfolding o_def * apply(rule setsum_cong2)
  5700     by simp
  5763       unfolding euclidean_lambda_beta'[OF goal1 ] by auto
  5701   have *: "\<And>x. ?Tf x = (\<Sum>i\<in>Basis.
  5764     finally show ?case unfolding o_def . qed
  5702     ((\<lambda>y. (\<Sum>j\<in>Basis. (if j = i then y else 0) *\<^sub>R j)) o
  5765   show ?thesis unfolding * apply(rule absolutely_integrable_setsum) apply(rule finite_lessThan)
  5703      (\<lambda>x. (norm (\<Sum>j\<in>Basis. (if j = i then f x\<bullet>T i else 0) *\<^sub>R j)))) x)"
  5766     apply(rule absolutely_integrable_linear) unfolding o_def apply(rule absolutely_integrable_norm)
  5704     by (simp add: comp_def if_distrib setsum_cases)
  5767     apply(rule absolutely_integrable_linear[OF assms,unfolded o_def]) unfolding linear_linear
  5705   show ?thesis
  5768     apply(rule_tac[!] linearI) unfolding euclidean_eq[where 'a='c]
  5706     unfolding *
  5769     by(auto simp:euclidean_component_scaleR[where 'a=real,unfolded real_scaleR_def])
  5707     apply (rule absolutely_integrable_setsum[OF finite_Basis])
       
  5708     apply (rule absolutely_integrable_linear)
       
  5709     apply (rule absolutely_integrable_norm)
       
  5710     apply (rule absolutely_integrable_linear[OF f, unfolded o_def])
       
  5711     apply (auto simp: linear_linear euclidean_eq_iff[where 'a='c] inner_simps intro!: linearI)
       
  5712     done
  5770 qed
  5713 qed
  5771 
  5714 
  5772 lemma absolutely_integrable_max: fixes f g::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space"
  5715 lemma absolutely_integrable_max:
       
  5716   fixes f g::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space"
  5773   assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  5717   assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  5774   shows "(\<lambda>x. (\<chi>\<chi> i. max (f(x)$$i) (g(x)$$i))::'n::ordered_euclidean_space) absolutely_integrable_on s"
  5718   shows "(\<lambda>x. (\<Sum>i\<in>Basis. max (f(x)\<bullet>i) (g(x)\<bullet>i) *\<^sub>R i)::'n) absolutely_integrable_on s"
  5775 proof- have *:"\<And>x. (1 / 2) *\<^sub>R (((\<chi>\<chi> i. \<bar>(f x - g x) $$ i\<bar>)::'n) + (f x + g x)) = (\<chi>\<chi> i. max (f(x)$$i) (g(x)$$i))"
  5719 proof -
  5776     unfolding euclidean_eq[where 'a='n] by auto
  5720   have *:"\<And>x. (1 / 2) *\<^sub>R (((\<Sum>i\<in>Basis. \<bar>(f x - g x) \<bullet> i\<bar> *\<^sub>R i)::'n) + (f x + g x)) =
       
  5721       (\<Sum>i\<in>Basis. max (f(x)\<bullet>i) (g(x)\<bullet>i) *\<^sub>R i)"
       
  5722     unfolding euclidean_eq_iff[where 'a='n] by (auto simp: inner_simps)
  5777   note absolutely_integrable_sub[OF assms] absolutely_integrable_add[OF assms]
  5723   note absolutely_integrable_sub[OF assms] absolutely_integrable_add[OF assms]
  5778   note absolutely_integrable_vector_abs[OF this(1)] this(2)
  5724   note absolutely_integrable_vector_abs[OF this(1), where T="\<lambda>x. x"] this(2)
  5779   note absolutely_integrable_add[OF this] note absolutely_integrable_cmul[OF this,of "1/2"]
  5725   note absolutely_integrable_add[OF this]
  5780   thus ?thesis unfolding * . qed
  5726   note absolutely_integrable_cmul[OF this, of "1/2"]
  5781 
  5727   thus ?thesis unfolding * .
  5782 lemma absolutely_integrable_min: fixes f g::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space"
  5728 qed
       
  5729 
       
  5730 lemma absolutely_integrable_min:
       
  5731   fixes f g::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space"
  5783   assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  5732   assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  5784   shows "(\<lambda>x. (\<chi>\<chi> i. min (f(x)$$i) (g(x)$$i))::'n::ordered_euclidean_space) absolutely_integrable_on s"
  5733   shows "(\<lambda>x. (\<Sum>i\<in>Basis. min (f(x)\<bullet>i) (g(x)\<bullet>i) *\<^sub>R i)::'n) absolutely_integrable_on s"
  5785 proof- have *:"\<And>x. (1 / 2) *\<^sub>R ((f x + g x) - ((\<chi>\<chi> i. \<bar>(f x - g x) $$ i\<bar>)::'n)) = (\<chi>\<chi> i. min (f(x)$$i) (g(x)$$i))"
  5734 proof -
  5786     unfolding euclidean_eq[where 'a='n] by auto
  5735   have *:"\<And>x. (1 / 2) *\<^sub>R ((f x + g x) - (\<Sum>i\<in>Basis. \<bar>(f x - g x) \<bullet> i\<bar> *\<^sub>R i::'n)) =
       
  5736       (\<Sum>i\<in>Basis. min (f(x)\<bullet>i) (g(x)\<bullet>i) *\<^sub>R i)"
       
  5737     unfolding euclidean_eq_iff[where 'a='n] by (auto simp: inner_simps)
       
  5738 
  5787   note absolutely_integrable_add[OF assms] absolutely_integrable_sub[OF assms]
  5739   note absolutely_integrable_add[OF assms] absolutely_integrable_sub[OF assms]
  5788   note this(1) absolutely_integrable_vector_abs[OF this(2)]
  5740   note this(1) absolutely_integrable_vector_abs[OF this(2), where T="\<lambda>x. x"]
  5789   note absolutely_integrable_sub[OF this] note absolutely_integrable_cmul[OF this,of "1/2"]
  5741   note absolutely_integrable_sub[OF this]
  5790   thus ?thesis unfolding * . qed
  5742   note absolutely_integrable_cmul[OF this,of "1/2"]
  5791 
  5743   thus ?thesis unfolding * .
  5792 lemma absolutely_integrable_abs_eq: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  5744 qed
       
  5745 
       
  5746 lemma absolutely_integrable_abs_eq:
       
  5747   fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  5793   shows "f absolutely_integrable_on s \<longleftrightarrow> f integrable_on s \<and>
  5748   shows "f absolutely_integrable_on s \<longleftrightarrow> f integrable_on s \<and>
  5794           (\<lambda>x. (\<chi>\<chi> i. abs(f x$$i))::'m) integrable_on s" (is "?l = ?r")
  5749           (\<lambda>x. (\<Sum>i\<in>Basis. abs(f x\<bullet>i) *\<^sub>R i)::'m) integrable_on s" (is "?l = ?r")
  5795 proof assume ?l thus ?r apply-apply rule defer
  5750 proof
       
  5751   assume ?l thus ?r apply-apply rule defer
  5796     apply(drule absolutely_integrable_vector_abs) by auto
  5752     apply(drule absolutely_integrable_vector_abs) by auto
  5797 next assume ?r { presume lem:"\<And>f::'n \<Rightarrow> 'm. f integrable_on UNIV \<Longrightarrow>
  5753 next 
  5798     (\<lambda>x. (\<chi>\<chi> i. abs(f(x)$$i))::'m) integrable_on UNIV \<Longrightarrow> f absolutely_integrable_on UNIV"
  5754   assume ?r
  5799     have *:"\<And>x. (\<chi>\<chi> i. \<bar>(if x \<in> s then f x else 0) $$ i\<bar>) = (if x\<in>s then (\<chi>\<chi> i. \<bar>f x $$ i\<bar>) else (0::'m))"
  5755   { presume lem:"\<And>f::'n \<Rightarrow> 'm. f integrable_on UNIV \<Longrightarrow>
  5800       unfolding euclidean_eq[where 'a='m] by auto
  5756       (\<lambda>x. (\<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i)::'m) integrable_on UNIV \<Longrightarrow> f absolutely_integrable_on UNIV"
       
  5757     have *:"\<And>x. (\<Sum>i\<in>Basis. \<bar>(if x \<in> s then f x else 0) \<bullet> i\<bar> *\<^sub>R i) =
       
  5758         (if x\<in>s then (\<Sum>i\<in>Basis. \<bar>f x \<bullet> i\<bar> *\<^sub>R i) else (0::'m))"
       
  5759       unfolding euclidean_eq_iff[where 'a='m] by auto
  5801     show ?l apply(subst absolutely_integrable_restrict_univ[THEN sym]) apply(rule lem)
  5760     show ?l apply(subst absolutely_integrable_restrict_univ[THEN sym]) apply(rule lem)
  5802       unfolding integrable_restrict_univ * using `?r` by auto }
  5761       unfolding integrable_restrict_univ * using `?r` by auto }
  5803   fix f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space" assume assms:"f integrable_on UNIV"
  5762   fix f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  5804     "(\<lambda>x. (\<chi>\<chi> i. abs(f(x)$$i))::'m::ordered_euclidean_space) integrable_on UNIV"
  5763   assume assms:"f integrable_on UNIV" "(\<lambda>x. (\<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i)::'m) integrable_on UNIV"
  5805   let ?B = "setsum (\<lambda>i. integral UNIV (\<lambda>x. (\<chi>\<chi> j. abs(f x$$j)) ::'m::ordered_euclidean_space) $$ i) {..<DIM('m)}"
  5764   let ?B = "\<Sum>i\<in>Basis. integral UNIV (\<lambda>x. (\<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i)::'m) \<bullet> i"
  5806   show "f absolutely_integrable_on UNIV"
  5765   show "f absolutely_integrable_on UNIV"
  5807     apply(rule bounded_variation_absolutely_integrable[OF assms(1), where B="?B"],safe)
  5766     apply(rule bounded_variation_absolutely_integrable[OF assms(1), where B="?B"],safe)
  5808   proof- case goal1 note d=this and d'=division_ofD[OF this]
  5767   proof- case goal1 note d=this and d'=division_ofD[OF this]
  5809     have "(\<Sum>k\<in>d. norm (integral k f)) \<le>
  5768     have "(\<Sum>k\<in>d. norm (integral k f)) \<le>
  5810       (\<Sum>k\<in>d. setsum (op $$ (integral k (\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>)::'m))) {..<DIM('m)})" apply(rule setsum_mono)
  5769       (\<Sum>k\<in>d. setsum (op \<bullet> (integral k (\<lambda>x. (\<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i)::'m))) Basis)"
       
  5770       apply(rule setsum_mono)
  5811       apply(rule order_trans[OF norm_le_l1]) apply(rule setsum_mono) unfolding lessThan_iff
  5771       apply(rule order_trans[OF norm_le_l1]) apply(rule setsum_mono) unfolding lessThan_iff
  5812     proof- fix k and i assume "k\<in>d" and i:"i<DIM('m)"
  5772     proof- fix k and i :: 'm assume "k\<in>d" and i:"i\<in>Basis"
  5813       from d'(4)[OF this(1)] guess a b apply-by(erule exE)+ note ab=this
  5773       from d'(4)[OF this(1)] guess a b apply-by(erule exE)+ note ab=this
  5814       show "\<bar>integral k f $$ i\<bar> \<le> integral k (\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>)::'m) $$ i" apply(rule abs_leI)
  5774       show "\<bar>integral k f \<bullet> i\<bar> \<le> integral k (\<lambda>x. (\<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i)::'m) \<bullet> i"
  5815         unfolding euclidean_component_minus[THEN sym] defer apply(subst integral_neg[THEN sym])
  5775         apply (rule abs_leI)
  5816         defer apply(rule_tac[1-2] integral_component_le) apply(rule integrable_neg)
  5776         unfolding inner_minus_left[THEN sym] defer apply(subst integral_neg[THEN sym])
       
  5777         defer apply(rule_tac[1-2] integral_component_le[OF i]) apply(rule integrable_neg)
  5817         using integrable_on_subinterval[OF assms(1),of a b]
  5778         using integrable_on_subinterval[OF assms(1),of a b]
  5818           integrable_on_subinterval[OF assms(2),of a b] unfolding ab by auto
  5779           integrable_on_subinterval[OF assms(2),of a b] i unfolding ab by auto
  5819     qed also have "... \<le> setsum (op $$ (integral UNIV (\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>))::'m)) {..<DIM('m)}"
  5780     qed also have "... \<le> setsum (op \<bullet> (integral UNIV (\<lambda>x. (\<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i)::'m))) Basis"
  5820       apply(subst setsum_commute,rule setsum_mono)
  5781       apply(subst setsum_commute,rule setsum_mono)
  5821     proof- case goal1 have *:"(\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>)::'m) integrable_on \<Union>d"
  5782     proof- case goal1 have *:"(\<lambda>x. \<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i::'m) integrable_on \<Union>d"
  5822         using integrable_on_subdivision[OF d assms(2)] by auto
  5783         using integrable_on_subdivision[OF d assms(2)] by auto
  5823       have "(\<Sum>i\<in>d. integral i (\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>)::'m) $$ j)
  5784       have "(\<Sum>i\<in>d. integral i (\<lambda>x. \<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i::'m) \<bullet> j)
  5824         = integral (\<Union>d) (\<lambda>x. (\<chi>\<chi> j. abs(f x$$j)) ::'m::ordered_euclidean_space) $$ j"
  5785         = integral (\<Union>d) (\<lambda>x. \<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i::'m) \<bullet> j"
  5825         unfolding euclidean_component_setsum[THEN sym] integral_combine_division_topdown[OF * d] ..
  5786         unfolding inner_setsum_left[symmetric] integral_combine_division_topdown[OF * d] ..
  5826       also have "... \<le> integral UNIV (\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>)::'m) $$ j"
  5787       also have "... \<le> integral UNIV (\<lambda>x. \<Sum>i\<in>Basis. \<bar>f x\<bullet>i\<bar> *\<^sub>R i::'m) \<bullet> j"
  5827         apply(rule integral_subset_component_le) using assms * by auto
  5788         apply(rule integral_subset_component_le) using assms * `j\<in>Basis` by auto
  5828       finally show ?case .
  5789       finally show ?case .
  5829     qed finally show ?case . qed qed
  5790     qed finally show ?case . qed qed
  5830 
  5791 
  5831 lemma nonnegative_absolutely_integrable: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  5792 lemma nonnegative_absolutely_integrable:
  5832   assumes "\<forall>x\<in>s. \<forall>i<DIM('m). 0 \<le> f(x)$$i" "f integrable_on s"
  5793   fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
       
  5794   assumes "\<forall>x\<in>s. \<forall>i\<in>Basis. 0 \<le> f(x)\<bullet>i" "f integrable_on s"
  5833   shows "f absolutely_integrable_on s"
  5795   shows "f absolutely_integrable_on s"
  5834   unfolding absolutely_integrable_abs_eq apply rule defer
  5796   unfolding absolutely_integrable_abs_eq
  5835   apply(rule integrable_eq[of _ f]) using assms apply-apply(subst euclidean_eq) by auto
  5797   apply rule
       
  5798   apply (rule assms)
       
  5799   apply (rule integrable_eq[of _ f])
       
  5800   using assms
       
  5801   apply (auto simp: euclidean_eq_iff[where 'a='m])
       
  5802   done
  5836 
  5803 
  5837 lemma absolutely_integrable_integrable_bound: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  5804 lemma absolutely_integrable_integrable_bound: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  5838   assumes "\<forall>x\<in>s. norm(f x) \<le> g x" "f integrable_on s" "g integrable_on s"
  5805   assumes "\<forall>x\<in>s. norm(f x) \<le> g x" "f integrable_on s" "g integrable_on s"
  5839   shows "f absolutely_integrable_on s"
  5806   shows "f absolutely_integrable_on s"
  5840 proof- { presume *:"\<And>f::'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space. \<And> g. \<forall>x. norm(f x) \<le> g x \<Longrightarrow> f integrable_on UNIV
  5807 proof- { presume *:"\<And>f::'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space. \<And> g. \<forall>x. norm(f x) \<le> g x \<Longrightarrow> f integrable_on UNIV
  5879          else min (fs x a) (Inf (fs x ` k))) absolutely_integrable_on s"
  5846          else min (fs x a) (Inf (fs x ` k))) absolutely_integrable_on s"
  5880   show ?case unfolding image_insert
  5847   show ?case unfolding image_insert
  5881     apply(subst Inf_insert_finite) apply(rule finite_imageI[OF insert(1)])
  5848     apply(subst Inf_insert_finite) apply(rule finite_imageI[OF insert(1)])
  5882   proof(cases "k={}") case True
  5849   proof(cases "k={}") case True
  5883     thus ?P apply(subst if_P) defer apply(rule insert(5)[rule_format]) by auto
  5850     thus ?P apply(subst if_P) defer apply(rule insert(5)[rule_format]) by auto
  5884   next case False thus ?P apply(subst if_not_P) defer      
  5851   next case False thus ?P apply(subst if_not_P) defer
  5885       apply(rule absolutely_integrable_min[where 'n=real,unfolded Eucl_real_simps])
  5852       apply (rule absolutely_integrable_min[where 'n=real, unfolded Basis_real_def, simplified])
  5886       defer apply(rule insert(3)[OF False]) using insert(5) by auto
  5853       defer apply(rule insert(3)[OF False]) using insert(5) by auto
  5887   qed qed auto
  5854   qed qed auto
  5888 
  5855 
  5889 lemma absolutely_integrable_sup_real:
  5856 lemma absolutely_integrable_sup_real:
  5890   assumes "finite k" "k \<noteq> {}"
  5857   assumes "finite k" "k \<noteq> {}"
  5895   show ?case unfolding image_insert
  5862   show ?case unfolding image_insert
  5896     apply(subst Sup_insert_finite) apply(rule finite_imageI[OF insert(1)])
  5863     apply(subst Sup_insert_finite) apply(rule finite_imageI[OF insert(1)])
  5897   proof(cases "k={}") case True
  5864   proof(cases "k={}") case True
  5898     thus ?P apply(subst if_P) defer apply(rule insert(5)[rule_format]) by auto
  5865     thus ?P apply(subst if_P) defer apply(rule insert(5)[rule_format]) by auto
  5899   next case False thus ?P apply(subst if_not_P) defer
  5866   next case False thus ?P apply(subst if_not_P) defer
  5900       apply(rule absolutely_integrable_max[where 'n=real,unfolded Eucl_real_simps]) 
  5867       apply (rule absolutely_integrable_max[where 'n=real, unfolded Basis_real_def, simplified])
  5901       defer apply(rule insert(3)[OF False]) using insert(5) by auto
  5868       defer apply(rule insert(3)[OF False]) using insert(5) by auto
  5902   qed qed auto
  5869   qed qed auto
  5903 
  5870 
  5904 subsection {* Dominated convergence. *}
  5871 subsection {* Dominated convergence. *}
  5905 
  5872