src/HOL/Multivariate_Analysis/Integration.thy
changeset 37489 44e42d392c6e
parent 36899 bcd6fce5bf06
child 37665 579258a77fec
     1.1 --- a/src/HOL/Multivariate_Analysis/Integration.thy	Mon Jun 21 14:07:00 2010 +0200
     1.2 +++ b/src/HOL/Multivariate_Analysis/Integration.thy	Mon Jun 21 19:33:51 2010 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  
     1.5 -header {* Kurzweil-Henstock gauge integration in many dimensions. *}
     1.6 +header {* Kurzweil-Henstock Gauge Integration in many dimensions. *}
     1.7  (*  Author:                     John Harrison
     1.8      Translation from HOL light: Robert Himmelmann, TU Muenchen *)
     1.9  
    1.10 @@ -8,20 +8,30 @@
    1.11  begin
    1.12  
    1.13  declare [[smt_certificates="~~/src/HOL/Multivariate_Analysis/Integration.certs"]]
    1.14 -declare [[smt_fixed=true]]
    1.15 +declare [[smt_fixed=false]]
    1.16  declare [[z3_proofs=true]]
    1.17  
    1.18  setup {* Arith_Data.add_tactic "Ferrante-Rackoff" (K FerranteRackoff.dlo_tac) *}
    1.19  
    1.20 -
    1.21 +(*declare not_less[simp] not_le[simp]*)
    1.22 +
    1.23 +lemmas scaleR_simps = scaleR_zero_left scaleR_minus_left scaleR_left_diff_distrib
    1.24 +  scaleR_zero_right scaleR_minus_right scaleR_right_diff_distrib scaleR_eq_0_iff
    1.25 +  scaleR_cancel_left scaleR_cancel_right scaleR.add_right scaleR.add_left real_vector_class.scaleR_one
    1.26 +
    1.27 +lemma real_arch_invD:
    1.28 +  "0 < (e::real) \<Longrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)"
    1.29 +  by(subst(asm) real_arch_inv)
    1.30  subsection {* Sundries *}
    1.31  
    1.32 +(*declare basis_component[simp]*)
    1.33 +
    1.34  lemma conjunctD2: assumes "a \<and> b" shows a b using assms by auto
    1.35  lemma conjunctD3: assumes "a \<and> b \<and> c" shows a b c using assms by auto
    1.36  lemma conjunctD4: assumes "a \<and> b \<and> c \<and> d" shows a b c d using assms by auto
    1.37  lemma conjunctD5: assumes "a \<and> b \<and> c \<and> d \<and> e" shows a b c d e using assms by auto
    1.38  
    1.39 -declare smult_conv_scaleR[simp]
    1.40 +declare norm_triangle_ineq4[intro] 
    1.41  
    1.42  lemma simple_image: "{f x |x . x \<in> s} = f ` s" by blast
    1.43  
    1.44 @@ -47,20 +57,10 @@
    1.45    using assms apply-apply(erule exE) apply(rule_tac x=b in exI)
    1.46    unfolding isUb_def setle_def by auto
    1.47  
    1.48 -lemma dist_trans[simp]:"dist (vec1 x) (vec1 y) = dist x (y::real)"
    1.49 -  unfolding dist_real_def dist_vec1 ..
    1.50 -
    1.51 -lemma Lim_trans[simp]: fixes f::"'a \<Rightarrow> real"
    1.52 -  shows "((\<lambda>x. vec1 (f x)) ---> vec1 l) net \<longleftrightarrow> (f ---> l) net"
    1.53 -  using assms unfolding Lim dist_trans ..
    1.54 -
    1.55 -lemma bounded_linear_component[intro]: "bounded_linear (\<lambda>x::real^'n. x $ k)"
    1.56 +lemma bounded_linear_component[intro]: "bounded_linear (\<lambda>x::'a::euclidean_space. x $$ k)"
    1.57    apply(rule bounded_linearI[where K=1]) 
    1.58    using component_le_norm[of _ k] unfolding real_norm_def by auto
    1.59  
    1.60 -lemma bounded_vec1[intro]:  "bounded s \<Longrightarrow> bounded (vec1 ` (s::real set))"
    1.61 -  unfolding bounded_def apply safe apply(rule_tac x="vec1 x" in exI,rule_tac x=e in exI) by auto
    1.62 -
    1.63  lemma transitive_stepwise_lt_eq:
    1.64    assumes "(\<And>x y z::nat. R x y \<Longrightarrow> R y z \<Longrightarrow> R x z)"
    1.65    shows "((\<forall>m. \<forall>n>m. R m n) \<longleftrightarrow> (\<forall>n. R n (Suc n)))" (is "?l = ?r")
    1.66 @@ -97,15 +97,16 @@
    1.67      apply(rule assms) apply(rule assms,assumption,assumption) using assms(3) by auto
    1.68    thus ?thesis by auto qed
    1.69  
    1.70 -
    1.71  subsection {* Some useful lemmas about intervals. *}
    1.72  
    1.73 -lemma empty_as_interval: "{} = {1..0::real^'n}"
    1.74 -  apply(rule set_ext,rule) defer unfolding vector_le_def mem_interval
    1.75 +abbreviation One  where "One \<equiv> ((\<chi>\<chi> i. 1)::_::ordered_euclidean_space)"
    1.76 +
    1.77 +lemma empty_as_interval: "{} = {One..0}"
    1.78 +  apply(rule set_ext,rule) defer unfolding mem_interval
    1.79    using UNIV_witness[where 'a='n] apply(erule_tac exE,rule_tac x=x in allE) by auto
    1.80  
    1.81  lemma interior_subset_union_intervals: 
    1.82 -  assumes "i = {a..b::real^'n}" "j = {c..d}" "interior j \<noteq> {}" "i \<subseteq> j \<union> s" "interior(i) \<inter> interior(j) = {}"
    1.83 +  assumes "i = {a..b::'a::ordered_euclidean_space}" "j = {c..d}" "interior j \<noteq> {}" "i \<subseteq> j \<union> s" "interior(i) \<inter> interior(j) = {}"
    1.84    shows "interior i \<subseteq> interior s" proof-
    1.85    have "{a<..<b} \<inter> {c..d} = {}" using inter_interval_mixed_eq_empty[of c d a b] and assms(3,5)
    1.86      unfolding assms(1,2) interior_closed_interval by auto
    1.87 @@ -114,7 +115,7 @@
    1.88    ultimately show ?thesis apply-apply(rule interior_maximal) defer apply(rule open_interior)
    1.89      unfolding assms(1,2) interior_closed_interval by auto qed
    1.90  
    1.91 -lemma inter_interior_unions_intervals: fixes f::"(real^'n) set set"
    1.92 +lemma inter_interior_unions_intervals: fixes f::"('a::ordered_euclidean_space) set set"
    1.93    assumes "finite f" "open s" "\<forall>t\<in>f. \<exists>a b. t = {a..b}" "\<forall>t\<in>f. s \<inter> (interior t) = {}"
    1.94    shows "s \<inter> interior(\<Union>f) = {}" proof(rule ccontr,unfold ex_in_conv[THEN sym]) case goal1
    1.95    have lem1:"\<And>x e s U. ball x e \<subseteq> s \<inter> interior U \<longleftrightarrow> ball x e \<subseteq> s \<inter> U" apply rule  defer apply(rule_tac Int_greatest)
    1.96 @@ -128,21 +129,22 @@
    1.97      guess a using insert(4)[rule_format,OF insertI1] .. then guess b .. note ab = this
    1.98      show ?case proof(cases "x\<in>i") case False hence "x \<in> UNIV - {a..b}" unfolding ab by auto
    1.99        then guess d unfolding open_contains_ball_eq[OF open_Diff[OF open_UNIV closed_interval],rule_format] ..
   1.100 -      hence "0 < d" "ball x (min d e) \<subseteq> UNIV - i" using e unfolding ab by auto
   1.101 -      hence "ball x (min d e) \<subseteq> s \<inter> interior (\<Union>f)" using e unfolding lem1 by auto hence "x \<in> s \<inter> interior (\<Union>f)" using `d>0` e by auto
   1.102 +      hence "0 < d" "ball x (min d e) \<subseteq> UNIV - i" unfolding ab ball_min_Int by auto
   1.103 +      hence "ball x (min d e) \<subseteq> s \<inter> interior (\<Union>f)" using e unfolding lem1 unfolding  ball_min_Int by auto
   1.104 +      hence "x \<in> s \<inter> interior (\<Union>f)" using `d>0` e by auto
   1.105        hence "\<exists>t\<in>f. \<exists>x e. 0 < e \<and> ball x e \<subseteq> s \<inter> t" apply-apply(rule insert(3)) using insert(4) by auto thus ?thesis by auto next
   1.106      case True show ?thesis proof(cases "x\<in>{a<..<b}")
   1.107        case True then guess d unfolding open_contains_ball_eq[OF open_interval,rule_format] ..
   1.108        thus ?thesis apply(rule_tac x=i in bexI,rule_tac x=x in exI,rule_tac x="min d e" in exI)
   1.109  	unfolding ab using interval_open_subset_closed[of a b] and e by fastsimp+ next
   1.110 -    case False then obtain k where "x$k \<le> a$k \<or> x$k \<ge> b$k" unfolding mem_interval by(auto simp add:not_less) 
   1.111 -    hence "x$k = a$k \<or> x$k = b$k" using True unfolding ab and mem_interval apply(erule_tac x=k in allE) by auto
   1.112 +    case False then obtain k where "x$$k \<le> a$$k \<or> x$$k \<ge> b$$k" and k:"k<DIM('a)" unfolding mem_interval by(auto simp add:not_less) 
   1.113 +    hence "x$$k = a$$k \<or> x$$k = b$$k" using True unfolding ab and mem_interval apply(erule_tac x=k in allE) by auto
   1.114      hence "\<exists>x. ball x (e/2) \<subseteq> s \<inter> (\<Union>f)" proof(erule_tac disjE)
   1.115 -      let ?z = "x - (e/2) *\<^sub>R basis k" assume as:"x$k = a$k" have "ball ?z (e / 2) \<inter> i = {}" apply(rule ccontr) unfolding ex_in_conv[THEN sym] proof(erule exE)
   1.116 +      let ?z = "x - (e/2) *\<^sub>R basis k" assume as:"x$$k = a$$k" have "ball ?z (e / 2) \<inter> i = {}" apply(rule ccontr) unfolding ex_in_conv[THEN sym] proof(erule exE)
   1.117  	fix y assume "y \<in> ball ?z (e / 2) \<inter> i" hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
   1.118 -	hence "\<bar>(?z - y) $ k\<bar> < e/2" using component_le_norm[of "?z - y" k] unfolding dist_norm by auto
   1.119 -	hence "y$k < a$k" unfolding vector_component_simps vector_scaleR_component as using e[THEN conjunct1] by(auto simp add:field_simps)
   1.120 -	hence "y \<notin> i" unfolding ab mem_interval not_all by(rule_tac x=k in exI,auto) thus False using yi by auto qed
   1.121 +	hence "\<bar>(?z - y) $$ k\<bar> < e/2" using component_le_norm[of "?z - y" k] unfolding dist_norm by auto
   1.122 +	hence "y$$k < a$$k" using e[THEN conjunct1] k by(auto simp add:field_simps basis_component as)
   1.123 +	hence "y \<notin> i" unfolding ab mem_interval not_all apply(rule_tac x=k in exI) using k by auto thus False using yi by auto qed
   1.124        moreover have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)" apply(rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]]) proof
   1.125  	fix y assume as:"y\<in> ball ?z (e/2)" have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y - (e / 2) *\<^sub>R basis k)"
   1.126  	   apply-apply(rule order_trans,rule norm_triangle_sub[of "x - y" "(e/2) *\<^sub>R basis k"])
   1.127 @@ -150,15 +152,15 @@
   1.128  	also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2" apply(rule add_strict_left_mono) using as unfolding mem_ball dist_norm using e by(auto simp add:field_simps)
   1.129  	finally show "y\<in>ball x e" unfolding mem_ball dist_norm using e by(auto simp add:field_simps) qed
   1.130        ultimately show ?thesis apply(rule_tac x="?z" in exI) unfolding Union_insert by auto
   1.131 -    next let ?z = "x + (e/2) *\<^sub>R basis k" assume as:"x$k = b$k" have "ball ?z (e / 2) \<inter> i = {}" apply(rule ccontr) unfolding ex_in_conv[THEN sym] proof(erule exE)
   1.132 +    next let ?z = "x + (e/2) *\<^sub>R basis k" assume as:"x$$k = b$$k" have "ball ?z (e / 2) \<inter> i = {}" apply(rule ccontr) unfolding ex_in_conv[THEN sym] proof(erule exE)
   1.133  	fix y assume "y \<in> ball ?z (e / 2) \<inter> i" hence "dist ?z y < e/2" and yi:"y\<in>i" by auto
   1.134 -	hence "\<bar>(?z - y) $ k\<bar> < e/2" using component_le_norm[of "?z - y" k] unfolding dist_norm by auto
   1.135 -	hence "y$k > b$k" unfolding vector_component_simps vector_scaleR_component as using e[THEN conjunct1] by(auto simp add:field_simps)
   1.136 -	hence "y \<notin> i" unfolding ab mem_interval not_all by(rule_tac x=k in exI,auto) thus False using yi by auto qed
   1.137 +	hence "\<bar>(?z - y) $$ k\<bar> < e/2" using component_le_norm[of "?z - y" k] unfolding dist_norm by auto
   1.138 +	hence "y$$k > b$$k" using e[THEN conjunct1] k by(auto simp add:field_simps as)
   1.139 +	hence "y \<notin> i" unfolding ab mem_interval not_all using k by(rule_tac x=k in exI,auto) thus False using yi by auto qed
   1.140        moreover have "ball ?z (e/2) \<subseteq> s \<inter> (\<Union>insert i f)" apply(rule order_trans[OF _ e[THEN conjunct2, unfolded lem1]]) proof
   1.141  	fix y assume as:"y\<in> ball ?z (e/2)" have "norm (x - y) \<le> \<bar>e\<bar> / 2 + norm (x - y + (e / 2) *\<^sub>R basis k)"
   1.142  	   apply-apply(rule order_trans,rule norm_triangle_sub[of "x - y" "- (e/2) *\<^sub>R basis k"])
   1.143 -	  unfolding norm_scaleR norm_basis by auto
   1.144 +	  unfolding norm_scaleR by auto
   1.145  	also have "\<dots> < \<bar>e\<bar> / 2 + \<bar>e\<bar> / 2" apply(rule add_strict_left_mono) using as unfolding mem_ball dist_norm using e by(auto simp add:field_simps)
   1.146  	finally show "y\<in>ball x e" unfolding mem_ball dist_norm using e by(auto simp add:field_simps) qed
   1.147        ultimately show ?thesis apply(rule_tac x="?z" in exI) unfolding Union_insert by auto qed 
   1.148 @@ -167,117 +169,111 @@
   1.149    guess t using *[OF assms(1,3) goal1]  .. from this(2) guess x .. then guess e ..
   1.150    hence "x \<in> s" "x\<in>interior t" defer using open_subset_interior[OF open_ball, of x e t] by auto
   1.151    thus False using `t\<in>f` assms(4) by auto qed
   1.152 +
   1.153  subsection {* Bounds on intervals where they exist. *}
   1.154  
   1.155 -definition "interval_upperbound (s::(real^'n) set) = (\<chi> i. Sup {a. \<exists>x\<in>s. x$i = a})"
   1.156 -
   1.157 -definition "interval_lowerbound (s::(real^'n) set) = (\<chi> i. Inf {a. \<exists>x\<in>s. x$i = a})"
   1.158 -
   1.159 -lemma interval_upperbound[simp]: assumes "\<forall>i. a$i \<le> b$i" shows "interval_upperbound {a..b} = b"
   1.160 -  using assms unfolding interval_upperbound_def Cart_eq Cart_lambda_beta apply-apply(rule,erule_tac x=i in allE)
   1.161 +definition "interval_upperbound (s::('a::ordered_euclidean_space) set) = ((\<chi>\<chi> i. Sup {a. \<exists>x\<in>s. x$$i = a})::'a)"
   1.162 +
   1.163 +definition "interval_lowerbound (s::('a::ordered_euclidean_space) set) = ((\<chi>\<chi> i. Inf {a. \<exists>x\<in>s. x$$i = a})::'a)"
   1.164 +
   1.165 +lemma interval_upperbound[simp]: assumes "\<forall>i<DIM('a::ordered_euclidean_space). a$$i \<le> (b::'a)$$i" shows "interval_upperbound {a..b} = b"
   1.166 +  using assms unfolding interval_upperbound_def apply(subst euclidean_eq[where 'a='a]) apply safe
   1.167 +  unfolding euclidean_lambda_beta' apply(erule_tac x=i in allE)
   1.168    apply(rule Sup_unique) unfolding setle_def apply rule unfolding mem_Collect_eq apply(erule bexE) unfolding mem_interval defer
   1.169 -  apply(rule,rule) apply(rule_tac x="b$i" in bexI) defer unfolding mem_Collect_eq apply(rule_tac x=b in bexI)
   1.170 +  apply(rule,rule) apply(rule_tac x="b$$i" in bexI) defer unfolding mem_Collect_eq apply(rule_tac x=b in bexI)
   1.171    unfolding mem_interval using assms by auto
   1.172  
   1.173 -lemma interval_lowerbound[simp]: assumes "\<forall>i. a$i \<le> b$i" shows "interval_lowerbound {a..b} = a"
   1.174 -  using assms unfolding interval_lowerbound_def Cart_eq Cart_lambda_beta apply-apply(rule,erule_tac x=i in allE)
   1.175 +lemma interval_lowerbound[simp]: assumes "\<forall>i<DIM('a::ordered_euclidean_space). a$$i \<le> (b::'a)$$i" shows "interval_lowerbound {a..b} = a"
   1.176 +  using assms unfolding interval_lowerbound_def apply(subst euclidean_eq[where 'a='a]) apply safe
   1.177 +  unfolding euclidean_lambda_beta' apply(erule_tac x=i in allE)
   1.178    apply(rule Inf_unique) unfolding setge_def apply rule unfolding mem_Collect_eq apply(erule bexE) unfolding mem_interval defer
   1.179 -  apply(rule,rule) apply(rule_tac x="a$i" in bexI) defer unfolding mem_Collect_eq apply(rule_tac x=a in bexI)
   1.180 -  unfolding mem_interval using assms by auto
   1.181 +  apply(rule,rule) apply(rule_tac x="a$$i" in bexI) defer unfolding mem_Collect_eq apply(rule_tac x=a in bexI)
   1.182 +  unfolding mem_interval using assms by auto 
   1.183  
   1.184  lemmas interval_bounds = interval_upperbound interval_lowerbound
   1.185  
   1.186  lemma interval_bounds'[simp]: assumes "{a..b}\<noteq>{}" shows "interval_upperbound {a..b} = b" "interval_lowerbound {a..b} = a"
   1.187    using assms unfolding interval_ne_empty by auto
   1.188  
   1.189 -lemma interval_upperbound_1[simp]: "dest_vec1 a \<le> dest_vec1 b \<Longrightarrow> interval_upperbound {a..b} = (b::real^1)"
   1.190 -  apply(rule interval_upperbound) by auto
   1.191 -
   1.192 -lemma interval_lowerbound_1[simp]: "dest_vec1 a \<le> dest_vec1 b \<Longrightarrow> interval_lowerbound {a..b} = (a::real^1)"
   1.193 -  apply(rule interval_lowerbound) by auto
   1.194 -
   1.195 -lemmas interval_bound_1 = interval_upperbound_1 interval_lowerbound_1
   1.196 -
   1.197  subsection {* Content (length, area, volume...) of an interval. *}
   1.198  
   1.199 -definition "content (s::(real^'n) set) =
   1.200 -       (if s = {} then 0 else (\<Prod>i\<in>UNIV. (interval_upperbound s)$i - (interval_lowerbound s)$i))"
   1.201 -
   1.202 -lemma interval_not_empty:"\<forall>i. a$i \<le> b$i \<Longrightarrow> {a..b::real^'n} \<noteq> {}"
   1.203 -  unfolding interval_eq_empty unfolding not_ex not_less by assumption
   1.204 -
   1.205 -lemma content_closed_interval: assumes "\<forall>i. a$i \<le> b$i"
   1.206 -  shows "content {a..b} = (\<Prod>i\<in>UNIV. b$i - a$i)"
   1.207 +definition "content (s::('a::ordered_euclidean_space) set) =
   1.208 +       (if s = {} then 0 else (\<Prod>i<DIM('a). (interval_upperbound s)$$i - (interval_lowerbound s)$$i))"
   1.209 +
   1.210 +lemma interval_not_empty:"\<forall>i<DIM('a). a$$i \<le> b$$i \<Longrightarrow> {a..b::'a::ordered_euclidean_space} \<noteq> {}"
   1.211 +  unfolding interval_eq_empty unfolding not_ex not_less by auto
   1.212 +
   1.213 +lemma content_closed_interval: fixes a::"'a::ordered_euclidean_space" assumes "\<forall>i<DIM('a). a$$i \<le> b$$i"
   1.214 +  shows "content {a..b} = (\<Prod>i<DIM('a). b$$i - a$$i)"
   1.215    using interval_not_empty[OF assms] unfolding content_def interval_upperbound[OF assms] interval_lowerbound[OF assms] by auto
   1.216  
   1.217 -lemma content_closed_interval': assumes "{a..b}\<noteq>{}" shows "content {a..b} = (\<Prod>i\<in>UNIV. b$i - a$i)"
   1.218 +lemma content_closed_interval': fixes a::"'a::ordered_euclidean_space" assumes "{a..b}\<noteq>{}" shows "content {a..b} = (\<Prod>i<DIM('a). b$$i - a$$i)"
   1.219    apply(rule content_closed_interval) using assms unfolding interval_ne_empty .
   1.220  
   1.221 -lemma content_1:"dest_vec1 a \<le> dest_vec1 b \<Longrightarrow> content {a..b} = dest_vec1 b - dest_vec1 a"
   1.222 -  using content_closed_interval[of a b] by auto
   1.223 -
   1.224 -lemma content_1':"a \<le> b \<Longrightarrow> content {vec1 a..vec1 b} = b - a" using content_1[of "vec a" "vec b"] by auto
   1.225 -
   1.226 -lemma content_unit[intro]: "content{0..1::real^'n} = 1" proof-
   1.227 -  have *:"\<forall>i. 0$i \<le> (1::real^'n::finite)$i" by auto
   1.228 -  have "0 \<in> {0..1::real^'n::finite}" unfolding mem_interval by auto
   1.229 +lemma content_real:assumes "a\<le>b" shows "content {a..b} = b-a"
   1.230 +proof- have *:"{..<Suc 0} = {0}" by auto
   1.231 +  show ?thesis unfolding content_def using assms by(auto simp: *)
   1.232 +qed
   1.233 +
   1.234 +lemma content_unit[intro]: "content{0..One::'a::ordered_euclidean_space} = 1" proof-
   1.235 +  have *:"\<forall>i<DIM('a). (0::'a)$$i \<le> (One::'a)$$i" by auto
   1.236 +  have "0 \<in> {0..One::'a}" unfolding mem_interval by auto
   1.237    thus ?thesis unfolding content_def interval_bounds[OF *] using setprod_1 by auto qed
   1.238  
   1.239 -lemma content_pos_le[intro]: "0 \<le> content {a..b}" proof(cases "{a..b}={}")
   1.240 -  case False hence *:"\<forall>i. a $ i \<le> b $ i" unfolding interval_ne_empty by assumption
   1.241 -  have "(\<Prod>i\<in>UNIV. interval_upperbound {a..b} $ i - interval_lowerbound {a..b} $ i) \<ge> 0"
   1.242 +lemma content_pos_le[intro]: fixes a::"'a::ordered_euclidean_space" shows "0 \<le> content {a..b}" proof(cases "{a..b}={}")
   1.243 +  case False hence *:"\<forall>i<DIM('a). a $$ i \<le> b $$ i" unfolding interval_ne_empty by assumption
   1.244 +  have "(\<Prod>i<DIM('a). interval_upperbound {a..b} $$ i - interval_lowerbound {a..b} $$ i) \<ge> 0"
   1.245      apply(rule setprod_nonneg) unfolding interval_bounds[OF *] using * apply(erule_tac x=x in allE) by auto
   1.246    thus ?thesis unfolding content_def by(auto simp del:interval_bounds') qed(unfold content_def, auto)
   1.247  
   1.248 -lemma content_pos_lt: assumes "\<forall>i. a$i < b$i" shows "0 < content {a..b}"
   1.249 -proof- have help_lemma1: "\<forall>i. a$i < b$i \<Longrightarrow> \<forall>i. a$i \<le> ((b$i)::real)" apply(rule,erule_tac x=i in allE) by auto
   1.250 +lemma content_pos_lt: fixes a::"'a::ordered_euclidean_space" assumes "\<forall>i<DIM('a). a$$i < b$$i" shows "0 < content {a..b}"
   1.251 +proof- have help_lemma1: "\<forall>i<DIM('a). a$$i < b$$i \<Longrightarrow> \<forall>i<DIM('a). a$$i \<le> ((b$$i)::real)" apply(rule,erule_tac x=i in allE) by auto
   1.252    show ?thesis unfolding content_closed_interval[OF help_lemma1[OF assms]] apply(rule setprod_pos)
   1.253      using assms apply(erule_tac x=x in allE) by auto qed
   1.254  
   1.255 -lemma content_pos_lt_1: "dest_vec1 a < dest_vec1 b \<Longrightarrow> 0 < content({a..b})"
   1.256 -  apply(rule content_pos_lt) by auto
   1.257 -
   1.258 -lemma content_eq_0: "content({a..b::real^'n}) = 0 \<longleftrightarrow> (\<exists>i. b$i \<le> a$i)" proof(cases "{a..b} = {}")
   1.259 +lemma content_eq_0: "content{a..b::'a::ordered_euclidean_space} = 0 \<longleftrightarrow> (\<exists>i<DIM('a). b$$i \<le> a$$i)" proof(cases "{a..b} = {}")
   1.260    case True thus ?thesis unfolding content_def if_P[OF True] unfolding interval_eq_empty apply-
   1.261      apply(rule,erule exE) apply(rule_tac x=i in exI) by auto next
   1.262 -  guess a using UNIV_witness[where 'a='n] .. case False note as=this[unfolded interval_eq_empty not_ex not_less]
   1.263 -  show ?thesis unfolding content_def if_not_P[OF False] setprod_zero_iff[OF finite_UNIV]
   1.264 +  case False note this[unfolded interval_eq_empty not_ex not_less]
   1.265 +  hence as:"\<forall>i<DIM('a). b $$ i \<ge> a $$ i" by fastsimp
   1.266 +  show ?thesis unfolding content_def if_not_P[OF False] setprod_zero_iff[OF finite_lessThan]
   1.267      apply(rule) apply(erule_tac[!] exE bexE) unfolding interval_bounds[OF as] apply(rule_tac x=x in exI) defer
   1.268      apply(rule_tac x=i in bexI) using as apply(erule_tac x=i in allE) by auto qed
   1.269  
   1.270  lemma cond_cases:"(P \<Longrightarrow> Q x) \<Longrightarrow> (\<not> P \<Longrightarrow> Q y) \<Longrightarrow> Q (if P then x else y)" by auto
   1.271  
   1.272  lemma content_closed_interval_cases:
   1.273 -  "content {a..b} = (if \<forall>i. a$i \<le> b$i then setprod (\<lambda>i. b$i - a$i) UNIV else 0)" apply(rule cond_cases) 
   1.274 +  "content {a..b::'a::ordered_euclidean_space} = (if \<forall>i<DIM('a). a$$i \<le> b$$i then setprod (\<lambda>i. b$$i - a$$i) {..<DIM('a)} else 0)" apply(rule cond_cases) 
   1.275    apply(rule content_closed_interval) unfolding content_eq_0 not_all not_le defer apply(erule exE,rule_tac x=x in exI) by auto
   1.276  
   1.277  lemma content_eq_0_interior: "content {a..b} = 0 \<longleftrightarrow> interior({a..b}) = {}"
   1.278    unfolding content_eq_0 interior_closed_interval interval_eq_empty by auto
   1.279  
   1.280 -lemma content_eq_0_1: "content {a..b::real^1} = 0 \<longleftrightarrow> dest_vec1 b \<le> dest_vec1 a"
   1.281 -  unfolding content_eq_0 by auto
   1.282 -
   1.283 -lemma content_pos_lt_eq: "0 < content {a..b} \<longleftrightarrow> (\<forall>i. a$i < b$i)"
   1.284 +(*lemma content_eq_0_1: "content {a..b::real^1} = 0 \<longleftrightarrow> dest_vec1 b \<le> dest_vec1 a"
   1.285 +  unfolding content_eq_0 by auto*)
   1.286 +
   1.287 +lemma content_pos_lt_eq: "0 < content {a..b::'a::ordered_euclidean_space} \<longleftrightarrow> (\<forall>i<DIM('a). a$$i < b$$i)"
   1.288    apply(rule) defer apply(rule content_pos_lt,assumption) proof- assume "0 < content {a..b}"
   1.289 -  hence "content {a..b} \<noteq> 0" by auto thus "\<forall>i. a$i < b$i" unfolding content_eq_0 not_ex not_le by auto qed
   1.290 +  hence "content {a..b} \<noteq> 0" by auto thus "\<forall>i<DIM('a). a$$i < b$$i" unfolding content_eq_0 not_ex not_le by fastsimp qed
   1.291  
   1.292  lemma content_empty[simp]: "content {} = 0" unfolding content_def by auto
   1.293  
   1.294 -lemma content_subset: assumes "{a..b} \<subseteq> {c..d}" shows "content {a..b::real^'n} \<le> content {c..d}" proof(cases "{a..b}={}")
   1.295 +lemma content_subset: assumes "{a..b} \<subseteq> {c..d}" shows "content {a..b::'a::ordered_euclidean_space} \<le> content {c..d}" proof(cases "{a..b}={}")
   1.296    case True thus ?thesis using content_pos_le[of c d] by auto next
   1.297 -  case False hence ab_ne:"\<forall>i. a $ i \<le> b $ i" unfolding interval_ne_empty by auto
   1.298 +  case False hence ab_ne:"\<forall>i<DIM('a). a $$ i \<le> b $$ i" unfolding interval_ne_empty by auto
   1.299    hence ab_ab:"a\<in>{a..b}" "b\<in>{a..b}" unfolding mem_interval by auto
   1.300    have "{c..d} \<noteq> {}" using assms False by auto
   1.301 -  hence cd_ne:"\<forall>i. c $ i \<le> d $ i" using assms unfolding interval_ne_empty by auto
   1.302 +  hence cd_ne:"\<forall>i<DIM('a). c $$ i \<le> d $$ i" using assms unfolding interval_ne_empty by auto
   1.303    show ?thesis unfolding content_def unfolding interval_bounds[OF ab_ne] interval_bounds[OF cd_ne]
   1.304 -    unfolding if_not_P[OF False] if_not_P[OF `{c..d} \<noteq> {}`] apply(rule setprod_mono,rule) proof fix i::'n
   1.305 -    show "0 \<le> b $ i - a $ i" using ab_ne[THEN spec[where x=i]] by auto
   1.306 -    show "b $ i - a $ i \<le> d $ i - c $ i"
   1.307 +    unfolding if_not_P[OF False] if_not_P[OF `{c..d} \<noteq> {}`] apply(rule setprod_mono,rule) proof
   1.308 +    fix i assume i:"i\<in>{..<DIM('a)}"
   1.309 +    show "0 \<le> b $$ i - a $$ i" using ab_ne[THEN spec[where x=i]] i by auto
   1.310 +    show "b $$ i - a $$ i \<le> d $$ i - c $$ i"
   1.311        using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(2),of i]
   1.312 -      using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(1),of i] by auto qed qed
   1.313 +      using assms[unfolded subset_eq mem_interval,rule_format,OF ab_ab(1),of i] using i by auto qed qed
   1.314  
   1.315  lemma content_lt_nz: "0 < content {a..b} \<longleftrightarrow> content {a..b} \<noteq> 0"
   1.316 -  unfolding content_pos_lt_eq content_eq_0 unfolding not_ex not_le by auto
   1.317 +  unfolding content_pos_lt_eq content_eq_0 unfolding not_ex not_le by fastsimp
   1.318  
   1.319  subsection {* The notion of a gauge --- simply an open set containing the point. *}
   1.320  
   1.321 @@ -331,13 +327,13 @@
   1.322  
   1.323  lemma division_of_trivial[simp]: "s division_of {} \<longleftrightarrow> s = {}" unfolding division_of_def by auto 
   1.324  
   1.325 -lemma division_of_sing[simp]: "s division_of {a..a::real^'n} \<longleftrightarrow> s = {{a..a}}" (is "?l = ?r") proof
   1.326 +lemma division_of_sing[simp]: "s division_of {a..a::'a::ordered_euclidean_space} \<longleftrightarrow> s = {{a..a}}" (is "?l = ?r") proof
   1.327    assume ?r moreover { assume "s = {{a}}" moreover fix k assume "k\<in>s" 
   1.328 -    ultimately have"\<exists>x y. k = {x..y}" apply(rule_tac x=a in exI)+ unfolding interval_sing[THEN conjunct1] by auto }
   1.329 -  ultimately show ?l unfolding division_of_def interval_sing[THEN conjunct1] by auto next
   1.330 -  assume ?l note as=conjunctD4[OF this[unfolded division_of_def interval_sing[THEN conjunct1]]]
   1.331 +    ultimately have"\<exists>x y. k = {x..y}" apply(rule_tac x=a in exI)+ unfolding interval_sing by auto }
   1.332 +  ultimately show ?l unfolding division_of_def interval_sing by auto next
   1.333 +  assume ?l note as=conjunctD4[OF this[unfolded division_of_def interval_sing]]
   1.334    { fix x assume x:"x\<in>s" have "x={a}" using as(2)[rule_format,OF x] by auto }
   1.335 -  moreover have "s \<noteq> {}" using as(4) by auto ultimately show ?r unfolding interval_sing[THEN conjunct1] by auto qed
   1.336 +  moreover have "s \<noteq> {}" using as(4) by auto ultimately show ?r unfolding interval_sing by auto qed
   1.337  
   1.338  lemma elementary_empty: obtains p where "p division_of {}"
   1.339    unfolding division_of_trivial by auto
   1.340 @@ -366,7 +362,7 @@
   1.341    unfolding forall_in_division[OF assms(2)] apply(rule,rule,rule) apply(drule division_ofD(2)[OF assms(2)])
   1.342    apply(drule content_subset) unfolding assms(1) proof- case goal1 thus ?case using content_pos_le[of a b] by auto qed
   1.343  
   1.344 -lemma division_inter: assumes "p1 division_of s1" "p2 division_of (s2::(real^'a) set)"
   1.345 +lemma division_inter: assumes "p1 division_of s1" "p2 division_of (s2::('a::ordered_euclidean_space) set)"
   1.346    shows "{k1 \<inter> k2 | k1 k2 .k1 \<in> p1 \<and> k2 \<in> p2 \<and> k1 \<inter> k2 \<noteq> {}} division_of (s1 \<inter> s2)" (is "?A' division_of _") proof-
   1.347  let ?A = "{s. s \<in>  (\<lambda>(k1,k2). k1 \<inter> k2) ` (p1 \<times> p2) \<and> s \<noteq> {}}" have *:"?A' = ?A" by auto
   1.348  show ?thesis unfolding * proof(rule division_ofI) have "?A \<subseteq> (\<lambda>(x, y). x \<inter> y) ` (p1 \<times> p2)" by auto
   1.349 @@ -389,17 +385,17 @@
   1.350      using division_ofD(5)[OF assms(1) k1(2) k2(2)]
   1.351      using division_ofD(5)[OF assms(2) k1(3) k2(3)] using th by auto qed qed
   1.352  
   1.353 -lemma division_inter_1: assumes "d division_of i" "{a..b::real^'n} \<subseteq> i"
   1.354 +lemma division_inter_1: assumes "d division_of i" "{a..b::'a::ordered_euclidean_space} \<subseteq> i"
   1.355    shows "{ {a..b} \<inter> k |k. k \<in> d \<and> {a..b} \<inter> k \<noteq> {} } division_of {a..b}" proof(cases "{a..b} = {}")
   1.356    case True show ?thesis unfolding True and division_of_trivial by auto next
   1.357    have *:"{a..b} \<inter> i = {a..b}" using assms(2) by auto 
   1.358    case False show ?thesis using division_inter[OF division_of_self[OF False] assms(1)] unfolding * by auto qed
   1.359  
   1.360 -lemma elementary_inter: assumes "p1 division_of s" "p2 division_of (t::(real^'n) set)"
   1.361 +lemma elementary_inter: assumes "p1 division_of s" "p2 division_of (t::('a::ordered_euclidean_space) set)"
   1.362    shows "\<exists>p. p division_of (s \<inter> t)"
   1.363    by(rule,rule division_inter[OF assms])
   1.364  
   1.365 -lemma elementary_inters: assumes "finite f" "f\<noteq>{}" "\<forall>s\<in>f. \<exists>p. p division_of (s::(real^'n) set)"
   1.366 +lemma elementary_inters: assumes "finite f" "f\<noteq>{}" "\<forall>s\<in>f. \<exists>p. p division_of (s::('a::ordered_euclidean_space) set)"
   1.367    shows "\<exists>p. p division_of (\<Inter> f)" using assms apply-proof(induct f rule:finite_induct)
   1.368  case (insert x f) show ?case proof(cases "f={}")
   1.369    case True thus ?thesis unfolding True using insert by auto next
   1.370 @@ -422,57 +418,71 @@
   1.371    fix k assume k:"k \<in> p1 \<union> p2"  show "k \<subseteq> s1 \<union> s2" using k d1(2) d2(2) by auto
   1.372    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
   1.373  
   1.374 +(* move *)
   1.375 +lemma Eucl_nth_inverse[simp]: fixes x::"'a::euclidean_space" shows "(\<chi>\<chi> i. x $$ i) = x"
   1.376 +  apply(subst euclidean_eq) by auto
   1.377 +
   1.378  lemma partial_division_extend_1:
   1.379 -  assumes "{c..d} \<subseteq> {a..b::real^'n}" "{c..d} \<noteq> {}"
   1.380 +  assumes "{c..d} \<subseteq> {a..b::'a::ordered_euclidean_space}" "{c..d} \<noteq> {}"
   1.381    obtains p where "p division_of {a..b}" "{c..d} \<in> p"
   1.382 -proof- def n \<equiv> "CARD('n)" have n:"1 \<le> n" "0 < n" "n \<noteq> 0" unfolding n_def by auto
   1.383 -  guess \<pi> using ex_bij_betw_nat_finite_1[OF finite_UNIV[where 'a='n]] .. note \<pi>=this
   1.384 +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
   1.385 +  guess \<pi> using ex_bij_betw_nat_finite_1[OF finite_lessThan[of "DIM('a)"]] .. note \<pi>=this
   1.386    def \<pi>' \<equiv> "inv_into {1..n} \<pi>"
   1.387 -  have \<pi>':"bij_betw \<pi>' UNIV {1..n}" using bij_betw_inv_into[OF \<pi>] unfolding \<pi>'_def n_def by auto
   1.388 -  hence \<pi>'i:"\<And>i. \<pi>' i \<in> {1..n}" unfolding bij_betw_def by auto 
   1.389 -  have \<pi>\<pi>'[simp]:"\<And>i. \<pi> (\<pi>' i) = i" unfolding \<pi>'_def apply(rule f_inv_into_f) unfolding n_def using \<pi> unfolding bij_betw_def by auto
   1.390 -  have \<pi>'\<pi>[simp]:"\<And>i. i\<in>{1..n} \<Longrightarrow> \<pi>' (\<pi> i) = i" unfolding \<pi>'_def apply(rule inv_into_f_eq) using \<pi> unfolding n_def bij_betw_def by auto
   1.391 +  have \<pi>':"bij_betw \<pi>' {..<DIM('a)} {1..n}" using bij_betw_inv_into[OF \<pi>] unfolding \<pi>'_def n_def by auto
   1.392 +  hence \<pi>'i:"\<And>i. i<DIM('a) \<Longrightarrow> \<pi>' i \<in> {1..n}" unfolding bij_betw_def by auto 
   1.393 +  have \<pi>i:"\<And>i. i\<in>{1..n} \<Longrightarrow> \<pi> i <DIM('a)" using \<pi> unfolding bij_betw_def n_def by auto 
   1.394 +  have \<pi>\<pi>'[simp]:"\<And>i. i<DIM('a) \<Longrightarrow> \<pi> (\<pi>' i) = i" unfolding \<pi>'_def
   1.395 +    apply(rule f_inv_into_f) unfolding n_def using \<pi> unfolding bij_betw_def by auto
   1.396 +  have \<pi>'\<pi>[simp]:"\<And>i. i\<in>{1..n} \<Longrightarrow> \<pi>' (\<pi> i) = i" unfolding \<pi>'_def apply(rule inv_into_f_eq)
   1.397 +    using \<pi> unfolding n_def bij_betw_def by auto
   1.398    have "{c..d} \<noteq> {}" using assms by auto
   1.399 -  let ?p1 = "\<lambda>l. {(\<chi> i. if \<pi>' i < l then c$i else a$i) .. (\<chi> i. if \<pi>' i < l then d$i else if \<pi>' i = l then c$\<pi> l else b$i)}"
   1.400 -  let ?p2 = "\<lambda>l. {(\<chi> i. if \<pi>' i < l then c$i else if \<pi>' i = l then d$\<pi> l else a$i) .. (\<chi> i. if \<pi>' i < l then d$i else b$i)}"
   1.401 +  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)}"
   1.402 +  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)}"
   1.403    let ?p =  "{?p1 l |l. l \<in> {1..n+1}} \<union> {?p2 l |l. l \<in> {1..n+1}}"
   1.404 -  have abcd:"\<And>i. a $ i \<le> c $ i \<and> c$i \<le> d$i \<and> d $ i \<le> b $ i" using assms unfolding subset_interval interval_eq_empty by(auto simp add:not_le not_less)
   1.405 +  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
   1.406 +    unfolding subset_interval interval_eq_empty by auto
   1.407    show ?thesis apply(rule that[of ?p]) apply(rule division_ofI)
   1.408 -  proof- have "\<And>i. \<pi>' i < Suc n"
   1.409 -    proof(rule ccontr,unfold not_less) fix i assume "Suc n \<le> \<pi>' i"
   1.410 -      hence "\<pi>' i \<notin> {1..n}" by auto thus False using \<pi>' unfolding bij_betw_def by auto
   1.411 -    qed hence "c = (\<chi> i. if \<pi>' i < Suc n then c $ i else a $ i)"
   1.412 -        "d = (\<chi> i. if \<pi>' i < Suc n then d $ i else if \<pi>' i = n + 1 then c $ \<pi> (n + 1) else b $ i)"
   1.413 -      unfolding Cart_eq Cart_lambda_beta using \<pi>' unfolding bij_betw_def by auto
   1.414 +  proof- have "\<And>i. i<DIM('a) \<Longrightarrow> \<pi>' i < Suc n"
   1.415 +    proof(rule ccontr,unfold not_less) fix i assume i:"i<DIM('a)" and "Suc n \<le> \<pi>' i"
   1.416 +      hence "\<pi>' i \<notin> {1..n}" by auto thus False using \<pi>' i unfolding bij_betw_def by auto
   1.417 +    qed hence "c = (\<chi>\<chi> i. if \<pi>' i < Suc n then c $$ i else a $$ i)"
   1.418 +        "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)"
   1.419 +      unfolding euclidean_eq[where 'a='a] using \<pi>' unfolding bij_betw_def by auto
   1.420      thus cdp:"{c..d} \<in> ?p" apply-apply(rule UnI1) unfolding mem_Collect_eq apply(rule_tac x="n + 1" in exI) by auto
   1.421      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}"
   1.422        unfolding subset_eq apply(rule_tac[!] ballI,rule_tac[!] ccontr)
   1.423      proof- fix l assume l:"l\<in>{1..n+1}" fix x assume "x\<notin>{a..b}"
   1.424 -      then guess i unfolding mem_interval not_all .. note i=this
   1.425 +      then guess i unfolding mem_interval not_all not_imp .. note i=conjunctD2[OF this]
   1.426        show "x \<in> ?p1 l \<Longrightarrow> False" "x \<in> ?p2 l \<Longrightarrow> False" unfolding mem_interval apply(erule_tac[!] x=i in allE)
   1.427          apply(case_tac[!] "\<pi>' i < l", case_tac[!] "\<pi>' i = l") using abcd[of i] i by auto 
   1.428      qed moreover have "\<And>x. x \<in> {a..b} \<Longrightarrow> x \<in> \<Union>?p"
   1.429      proof- fix x assume x:"x\<in>{a..b}"
   1.430        { presume "x\<notin>{c..d} \<Longrightarrow> x \<in> \<Union>?p" thus "x \<in> \<Union>?p" using cdp by blast }
   1.431 -      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)}"
   1.432 -      assume "x\<notin>{c..d}" then guess i0 unfolding mem_interval not_all ..
   1.433 +      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)}"
   1.434 +      assume "x\<notin>{c..d}" then guess i0 unfolding mem_interval not_all not_imp ..
   1.435        hence "\<pi>' i0 \<in> ?M" using \<pi>' unfolding bij_betw_def by(auto intro!:le_SucI)
   1.436        hence M:"finite ?M" "?M \<noteq> {}" by auto
   1.437        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]]
   1.438          Min_gr_iff[OF M,unfolded l_def[symmetric]]
   1.439        have "x\<in>?p1 l \<or> x\<in>?p2 l" using l(2)[THEN conjunct2] unfolding de_Morgan_conj not_le
   1.440          apply- apply(erule disjE) apply(rule disjI1) defer apply(rule disjI2)
   1.441 -      proof- assume as:"x $ \<pi> l < c $ \<pi> l"
   1.442 -        show "x \<in> ?p1 l" unfolding mem_interval Cart_lambda_beta
   1.443 -        proof case goal1 have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le by auto
   1.444 +      proof- assume as:"x $$ \<pi> l < c $$ \<pi> l"
   1.445 +        show "x \<in> ?p1 l" unfolding mem_interval apply safe unfolding euclidean_lambda_beta'
   1.446 +        proof- case goal1 have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le using goal1 by auto
   1.447            thus ?case using as x[unfolded mem_interval,rule_format,of i]
   1.448 -            apply auto using l(3)[of "\<pi>' i"] by(auto elim!:ballE[where x="\<pi>' i"])
   1.449 +            apply auto using l(3)[of "\<pi>' i"] using goal1 by(auto elim!:ballE[where x="\<pi>' i"])
   1.450 +        next case goal2 have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le using goal2 by auto
   1.451 +          thus ?case using as x[unfolded mem_interval,rule_format,of i]
   1.452 +            apply auto using l(3)[of "\<pi>' i"] using goal2 by(auto elim!:ballE[where x="\<pi>' i"])
   1.453          qed
   1.454 -      next assume as:"x $ \<pi> l > d $ \<pi> l"
   1.455 -        show "x \<in> ?p2 l" unfolding mem_interval Cart_lambda_beta
   1.456 -        proof case goal1 have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le by auto
   1.457 -          thus ?case using as x[unfolded mem_interval,rule_format,of i]
   1.458 -            apply auto using l(3)[of "\<pi>' i"] by(auto elim!:ballE[where x="\<pi>' i"])
   1.459 +      next assume as:"x $$ \<pi> l > d $$ \<pi> l"
   1.460 +        show "x \<in> ?p2 l" unfolding mem_interval apply safe unfolding euclidean_lambda_beta'
   1.461 +        proof- fix i assume i:"i<DIM('a)"
   1.462 +          have "\<pi>' i \<in> {1..n}" using \<pi>' unfolding bij_betw_def not_le using i by auto
   1.463 +          thus "(if \<pi>' i < l then c $$ i else if \<pi>' i = l then d $$ \<pi> l else a $$ i) \<le> x $$ i"
   1.464 +            "x $$ i \<le> (if \<pi>' i < l then d $$ i else b $$ i)"
   1.465 +            using as x[unfolded mem_interval,rule_format,of i]
   1.466 +            apply auto using l(3)[of "\<pi>' i"] i by(auto elim!:ballE[where x="\<pi>' i"])
   1.467          qed qed
   1.468        thus "x \<in> \<Union>?p" using l(2) by blast 
   1.469      qed ultimately show "\<Union>?p = {a..b}" apply-apply(rule) defer apply(rule) by(assumption,blast)
   1.470 @@ -480,8 +490,9 @@
   1.471      show "finite ?p" by auto
   1.472      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
   1.473      show "k\<subseteq>{a..b}" apply(rule,unfold mem_interval,rule,rule) 
   1.474 -    proof- fix i::'n and x assume "x \<in> k" moreover have "\<pi>' i < l \<or> \<pi>' i = l \<or> \<pi>' i > l" by auto
   1.475 -      ultimately show "a$i \<le> x$i" "x$i \<le> b$i" using abcd[of i] using l by(auto elim:disjE elim!:allE[where x=i] simp add:vector_le_def)
   1.476 +    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
   1.477 +      ultimately show "a$$i \<le> x$$i" "x$$i \<le> b$$i" using abcd[of i] using l using i
   1.478 +        by(auto elim:disjE elim!:allE[where x=i] simp add:eucl_le[where 'a='a])
   1.479      qed have "\<And>l. ?p1 l \<noteq> {}" "\<And>l. ?p2 l \<noteq> {}" unfolding interval_eq_empty not_ex apply(rule_tac[!] allI)
   1.480      proof- case goal1 thus ?case using abcd[of x] by auto
   1.481      next   case goal2 thus ?case using abcd[of x] by auto
   1.482 @@ -494,20 +505,22 @@
   1.483        assume "l \<le> l'" fix x
   1.484        have "x \<notin> interior k \<inter> interior k'" 
   1.485        proof(rule,cases "l' = n+1") assume x:"x \<in> interior k \<inter> interior k'"
   1.486 -        case True hence "\<And>i. \<pi>' i < l'" using \<pi>'i by(auto simp add:less_Suc_eq_le)
   1.487 -        hence k':"k' = {c..d}" using l'(1) \<pi>'i by(auto simp add:Cart_nth_inverse)
   1.488 +        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)
   1.489 +        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
   1.490 +        hence k':"k' = {c..d}" using l'(1) unfolding * by auto
   1.491          have ln:"l < n + 1" 
   1.492          proof(rule ccontr) case goal1 hence l2:"l = n+1" using l by auto
   1.493 -          hence "\<And>i. \<pi>' i < l" using \<pi>'i by(auto simp add:less_Suc_eq_le)
   1.494 -          hence "k = {c..d}" using l(1) \<pi>'i by(auto simp add:Cart_nth_inverse)
   1.495 +          hence "\<And>i. i<DIM('a) \<Longrightarrow> \<pi>' i < l" using \<pi>'i by(auto simp add:less_Suc_eq_le)
   1.496 +          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
   1.497 +          hence "k = {c..d}" using l(1) \<pi>'i unfolding * by(auto)
   1.498            thus False using `k\<noteq>k'` k' by auto
   1.499          qed have **:"\<pi>' (\<pi> l) = l" using \<pi>'\<pi>[of l] using l ln by auto
   1.500 -        have "x $ \<pi> l < c $ \<pi> l \<or> d $ \<pi> l < x $ \<pi> l" using l(1) apply-
   1.501 +        have "x $$ \<pi> l < c $$ \<pi> l \<or> d $$ \<pi> l < x $$ \<pi> l" using l(1) apply-
   1.502          proof(erule disjE)
   1.503            assume as:"k = ?p1 l" note * = conjunct1[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   1.504 -          show ?thesis using *[of "\<pi> l"] using ln unfolding Cart_lambda_beta ** by auto
   1.505 +          show ?thesis using *[of "\<pi> l"] using ln l(2) using \<pi>i[of l] by(auto simp add:** not_less)
   1.506          next assume as:"k = ?p2 l" note * = conjunct1[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   1.507 -          show ?thesis using *[of "\<pi> l"] using ln unfolding Cart_lambda_beta ** by auto
   1.508 +          show ?thesis using *[of "\<pi> l"] using ln l(2) using \<pi>i[of l] unfolding ** by auto
   1.509          qed thus False using x unfolding k' unfolding Int_iff interior_closed_interval mem_interval
   1.510            by(auto elim!:allE[where x="\<pi> l"])
   1.511        next case False hence "l < n + 1" using l'(2) using `l\<le>l'` by auto
   1.512 @@ -517,22 +530,22 @@
   1.513          show False using l(1) l'(1) apply-
   1.514          proof(erule_tac[!] disjE)+
   1.515            assume as:"k = ?p1 l" "k' = ?p1 l'"
   1.516 -          note * = x[unfolded as Int_iff interior_closed_interval mem_interval]
   1.517 +          note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   1.518            have "l \<noteq> l'" using k'(2)[unfolded as] by auto
   1.519 -          thus False using * by(smt Cart_lambda_beta \<pi>l)
   1.520 +          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'")
   1.521 +            by(auto simp add:euclidean_lambda_beta' \<pi>l \<pi>i n_def)
   1.522          next assume as:"k = ?p2 l" "k' = ?p2 l'"
   1.523            note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   1.524            have "l \<noteq> l'" apply(rule) using k'(2)[unfolded as] by auto
   1.525 -          thus False using *[of "\<pi> l"] *[of "\<pi> l'"]
   1.526 -            unfolding Cart_lambda_beta \<pi>l using `l \<le> l'` by auto
   1.527 +          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)
   1.528          next assume as:"k = ?p1 l" "k' = ?p2 l'"
   1.529            note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   1.530 -          show False using *[of "\<pi> l"] *[of "\<pi> l'"]
   1.531 -            unfolding Cart_lambda_beta \<pi>l using `l \<le> l'` using abcd[of "\<pi> l'"] by smt 
   1.532 +          show False using abcd[of "\<pi> l'"] using *[of "\<pi> l"] *[of "\<pi> l'"]  `l \<le> l'` ln apply(cases "l=l'")
   1.533 +            by(auto simp add:euclidean_lambda_beta' \<pi>l \<pi>i n_def)
   1.534          next assume as:"k = ?p2 l" "k' = ?p1 l'"
   1.535            note * = conjunctD2[OF x[unfolded as Int_iff interior_closed_interval mem_interval],rule_format]
   1.536 -          show False using *[of "\<pi> l"] *[of "\<pi> l'"]
   1.537 -            unfolding Cart_lambda_beta \<pi>l using `l \<le> l'` using abcd[of "\<pi> l'"] by smt
   1.538 +          show False using *[of "\<pi> l"] *[of "\<pi> l'"] ln `l \<le> l'` apply(cases "l=l'") using abcd[of "\<pi> l'"] 
   1.539 +            by(auto simp add:euclidean_lambda_beta' \<pi>l \<pi>i n_def)
   1.540          qed qed } 
   1.541      from this[OF k l k' l'] this[OF k'(1) l' k _ l] have "\<And>x. x \<notin> interior k \<inter> interior k'"
   1.542        apply - apply(cases "l' \<le> l") using k'(2) by auto            
   1.543 @@ -540,7 +553,7 @@
   1.544  qed qed
   1.545  
   1.546  lemma partial_division_extend_interval: assumes "p division_of (\<Union>p)" "(\<Union>p) \<subseteq> {a..b}"
   1.547 -  obtains q where "p \<subseteq> q" "q division_of {a..b::real^'n}" proof(cases "p = {}")
   1.548 +  obtains q where "p \<subseteq> q" "q division_of {a..b::'a::ordered_euclidean_space}" proof(cases "p = {}")
   1.549    case True guess q apply(rule elementary_interval[of a b]) .
   1.550    thus ?thesis apply- apply(rule that[of q]) unfolding True by auto next
   1.551    case False note p = division_ofD[OF assms(1)]
   1.552 @@ -569,13 +582,13 @@
   1.553  	have *:"\<And>x s. x \<in> s \<Longrightarrow> \<Inter>s \<subseteq> x" by auto show "interior (\<Inter>(\<lambda>i. \<Union>(q i - {i})) ` p) \<subseteq> interior (\<Union>(q k - {k}))"
   1.554  	  apply(rule subset_interior *)+ using k by auto qed qed qed auto qed
   1.555  
   1.556 -lemma elementary_bounded[dest]: "p division_of s \<Longrightarrow> bounded (s::(real^'n) set)"
   1.557 +lemma elementary_bounded[dest]: "p division_of s \<Longrightarrow> bounded (s::('a::ordered_euclidean_space) set)"
   1.558    unfolding division_of_def by(metis bounded_Union bounded_interval) 
   1.559  
   1.560 -lemma elementary_subset_interval: "p division_of s \<Longrightarrow> \<exists>a b. s \<subseteq> {a..b::real^'n}"
   1.561 +lemma elementary_subset_interval: "p division_of s \<Longrightarrow> \<exists>a b. s \<subseteq> {a..b::'a::ordered_euclidean_space}"
   1.562    by(meson elementary_bounded bounded_subset_closed_interval)
   1.563  
   1.564 -lemma division_union_intervals_exists: assumes "{a..b::real^'n} \<noteq> {}"
   1.565 +lemma division_union_intervals_exists: assumes "{a..b::'a::ordered_euclidean_space} \<noteq> {}"
   1.566    obtains p where "(insert {a..b} p) division_of ({a..b} \<union> {c..d})" proof(cases "{c..d} = {}")
   1.567    case True show ?thesis apply(rule that[of "{}"]) unfolding True using assms by auto next
   1.568    case False note false=this show ?thesis proof(cases "{a..b} \<inter> {c..d} = {}")
   1.569 @@ -602,7 +615,7 @@
   1.570    using division_ofD[OF assms(2)] by auto
   1.571    
   1.572  lemma elementary_union_interval: assumes "p division_of \<Union>p"
   1.573 -  obtains q where "q division_of ({a..b::real^'n} \<union> \<Union>p)" proof-
   1.574 +  obtains q where "q division_of ({a..b::'a::ordered_euclidean_space} \<union> \<Union>p)" proof-
   1.575    note assm=division_ofD[OF assms]
   1.576    have lem1:"\<And>f s. \<Union>\<Union> (f ` s) = \<Union>(\<lambda>x.\<Union>(f x)) ` s" by auto
   1.577    have lem2:"\<And>f s. f \<noteq> {} \<Longrightarrow> \<Union>{s \<union> t |t. t \<in> f} = s \<union> \<Union>f" by auto
   1.578 @@ -653,7 +666,7 @@
   1.579      qed qed } qed
   1.580  
   1.581  lemma elementary_unions_intervals:
   1.582 -  assumes "finite f" "\<And>s. s \<in> f \<Longrightarrow> \<exists>a b. s = {a..b::real^'n}"
   1.583 +  assumes "finite f" "\<And>s. s \<in> f \<Longrightarrow> \<exists>a b. s = {a..b::'a::ordered_euclidean_space}"
   1.584    obtains p where "p division_of (\<Union>f)" proof-
   1.585    have "\<exists>p. p division_of (\<Union>f)" proof(induct_tac f rule:finite_subset_induct) 
   1.586      show "\<exists>p. p division_of \<Union>{}" using elementary_empty by auto
   1.587 @@ -665,7 +678,7 @@
   1.588        unfolding Union_insert ab * by auto
   1.589    qed(insert assms,auto) thus ?thesis apply-apply(erule exE,rule that) by auto qed
   1.590  
   1.591 -lemma elementary_union: assumes "ps division_of s" "pt division_of (t::(real^'n) set)"
   1.592 +lemma elementary_union: assumes "ps division_of s" "pt division_of (t::('a::ordered_euclidean_space) set)"
   1.593    obtains p where "p division_of (s \<union> t)"
   1.594  proof- have "s \<union> t = \<Union>ps \<union> \<Union>pt" using assms unfolding division_of_def by auto
   1.595    hence *:"\<Union>(ps \<union> pt) = s \<union> t" by auto
   1.596 @@ -673,7 +686,7 @@
   1.597      unfolding * prefer 3 apply(rule_tac p=p in that)
   1.598      using assms[unfolded division_of_def] by auto qed
   1.599  
   1.600 -lemma partial_division_extend: fixes t::"(real^'n) set"
   1.601 +lemma partial_division_extend: fixes t::"('a::ordered_euclidean_space) set"
   1.602    assumes "p division_of s" "q division_of t" "s \<subseteq> t"
   1.603    obtains r where "p \<subseteq> r" "r division_of t" proof-
   1.604    note divp = division_ofD[OF assms(1)] and divq = division_ofD[OF assms(2)]
   1.605 @@ -776,7 +789,7 @@
   1.606    shows "t tagged_partial_division_of i"
   1.607    using assms unfolding tagged_partial_division_of_def using finite_subset[OF assms(2)] by blast
   1.608  
   1.609 -lemma setsum_over_tagged_division_lemma: fixes d::"(real^'m) set \<Rightarrow> 'a::real_normed_vector"
   1.610 +lemma setsum_over_tagged_division_lemma: fixes d::"('m::ordered_euclidean_space) set \<Rightarrow> 'a::real_normed_vector"
   1.611    assumes "p tagged_division_of i" "\<And>u v. {u..v} \<noteq> {} \<Longrightarrow> content {u..v} = 0 \<Longrightarrow> d {u..v} = 0"
   1.612    shows "setsum (\<lambda>(x,k). d k) p = setsum d (snd ` p)"
   1.613  proof- note assm=tagged_division_ofD[OF assms(1)]
   1.614 @@ -886,7 +899,7 @@
   1.615                          \<longrightarrow> norm(setsum (\<lambda>(x,k). content k *\<^sub>R f x) p - y) < e))"
   1.616  
   1.617  definition has_integral (infixr "has'_integral" 46) where 
   1.618 -"((f::(real^'n \<Rightarrow> 'b::real_normed_vector)) has_integral y) i \<equiv>
   1.619 +"((f::('n::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector)) has_integral y) i \<equiv>
   1.620          if (\<exists>a b. i = {a..b}) then (f has_integral_compact_interval y) i
   1.621          else (\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b}
   1.622                \<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> i then f x else 0) has_integral_compact_interval z) {a..b} \<and>
   1.623 @@ -933,14 +946,6 @@
   1.624  lemma has_integral_integral:"f integrable_on s \<longleftrightarrow> (f has_integral (integral s f)) s"
   1.625    by auto
   1.626  
   1.627 -lemma has_integral_vec1: assumes "(f has_integral k) {a..b}"
   1.628 -  shows "((\<lambda>x. vec1 (f x)) has_integral (vec1 k)) {a..b}"
   1.629 -proof- have *:"\<And>p. (\<Sum>(x, k)\<in>p. content k *\<^sub>R vec1 (f x)) - vec1 k = vec1 ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - k)"
   1.630 -    unfolding vec_sub Cart_eq by(auto simp add: split_beta)
   1.631 -  show ?thesis using assms unfolding has_integral apply safe
   1.632 -    apply(erule_tac x=e in allE,safe) apply(rule_tac x=d in exI,safe)
   1.633 -    apply(erule_tac x=p in allE,safe) unfolding * norm_vector_1 by auto qed
   1.634 -
   1.635  lemma setsum_content_null:
   1.636    assumes "content({a..b}) = 0" "p tagged_division_of {a..b}"
   1.637    shows "setsum (\<lambda>(x,k). content k *\<^sub>R f x) p = (0::'a::real_normed_vector)"
   1.638 @@ -968,15 +973,15 @@
   1.639  
   1.640  subsection {* The set we're concerned with must be closed. *}
   1.641  
   1.642 -lemma division_of_closed: "s division_of i \<Longrightarrow> closed (i::(real^'n) set)"
   1.643 +lemma division_of_closed: "s division_of i \<Longrightarrow> closed (i::('n::ordered_euclidean_space) set)"
   1.644    unfolding division_of_def by(fastsimp intro!: closed_Union closed_interval)
   1.645  
   1.646  subsection {* General bisection principle for intervals; might be useful elsewhere. *}
   1.647  
   1.648 -lemma interval_bisection_step:
   1.649 -  assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "~(P {a..b::real^'n})"
   1.650 +lemma interval_bisection_step:  fixes type::"'a::ordered_euclidean_space"
   1.651 +  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})"
   1.652    obtains c d where "~(P{c..d})"
   1.653 -  "\<forall>i. a$i \<le> c$i \<and> c$i \<le> d$i \<and> d$i \<le> b$i \<and> 2 * (d$i - c$i) \<le> b$i - a$i"
   1.654 +  "\<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"
   1.655  proof- have "{a..b} \<noteq> {}" using assms(1,3) by auto
   1.656    note ab=this[unfolded interval_eq_empty not_ex not_less]
   1.657    { fix f have "finite f \<Longrightarrow>
   1.658 @@ -989,68 +994,70 @@
   1.659          apply rule defer apply rule defer apply(rule inter_interior_unions_intervals)
   1.660          using insert by auto
   1.661      qed } note * = this
   1.662 -  let ?A = "{{c..d} | c d. \<forall>i. (c$i = a$i) \<and> (d$i = (a$i + b$i) / 2) \<or> (c$i = (a$i + b$i) / 2) \<and> (d$i = b$i)}"
   1.663 -  let ?PP = "\<lambda>c d. \<forall>i. a$i \<le> c$i \<and> c$i \<le> d$i \<and> d$i \<le> b$i \<and> 2 * (d$i - c$i) \<le> b$i - a$i"
   1.664 +  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)}"
   1.665 +  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"
   1.666    { presume "\<forall>c d. ?PP c d \<longrightarrow> P {c..d} \<Longrightarrow> False"
   1.667      thus thesis unfolding atomize_not not_all apply-apply(erule exE)+ apply(rule_tac c=x and d=xa in that) by auto }
   1.668    assume as:"\<forall>c d. ?PP c d \<longrightarrow> P {c..d}"
   1.669    have "P (\<Union> ?A)" proof(rule *, rule_tac[2-] ballI, rule_tac[4] ballI, rule_tac[4] impI) 
   1.670 -    let ?B = "(\<lambda>s.{(\<chi> i. if i \<in> s then a$i else (a$i + b$i) / 2) ..
   1.671 -      (\<chi> i. if i \<in> s then (a$i + b$i) / 2 else b$i)}) ` {s. s \<subseteq> UNIV}"
   1.672 +    let ?B = "(\<lambda>s.{(\<chi>\<chi> i. if i \<in> s then a$$i else (a$$i + b$$i) / 2)::'a ..
   1.673 +      (\<chi>\<chi> i. if i \<in> s then (a$$i + b$$i) / 2 else b$$i)}) ` {s. s \<subseteq> {..<DIM('a)}}"
   1.674      have "?A \<subseteq> ?B" proof case goal1
   1.675        then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+) note c_d=this[rule_format]
   1.676        have *:"\<And>a b c d. a = c \<Longrightarrow> b = d \<Longrightarrow> {a..b} = {c..d}" by auto
   1.677 -      show "x\<in>?B" unfolding image_iff apply(rule_tac x="{i. c$i = a$i}" in bexI)
   1.678 -        unfolding c_d apply(rule * ) unfolding Cart_eq cond_component Cart_lambda_beta
   1.679 -      proof(rule_tac[1-2] allI) fix i show "c $ i = (if i \<in> {i. c $ i = a $ i} then a $ i else (a $ i + b $ i) / 2)"
   1.680 -          "d $ i = (if i \<in> {i. c $ i = a $ i} then (a $ i + b $ i) / 2 else b $ i)"
   1.681 +      show "x\<in>?B" unfolding image_iff apply(rule_tac x="{i. i<DIM('a) \<and> c$$i = a$$i}" in bexI)
   1.682 +        unfolding c_d apply(rule * ) unfolding euclidean_eq[where 'a='a] apply safe unfolding euclidean_lambda_beta' mem_Collect_eq
   1.683 +      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)"
   1.684 +          "d $$ i = (if i < DIM('a) \<and> c $$ i = a $$ i then (a $$ i + b $$ i) / 2 else b $$ i)"
   1.685            using c_d(2)[of i] ab[THEN spec[where x=i]] by(auto simp add:field_simps)
   1.686 -      qed auto qed
   1.687 -    thus "finite ?A" apply(rule finite_subset[of _ ?B]) by auto
   1.688 +      qed qed
   1.689 +    thus "finite ?A" apply(rule finite_subset) by auto
   1.690      fix s assume "s\<in>?A" then guess c unfolding mem_Collect_eq .. then guess d apply- by(erule exE,(erule conjE)+)
   1.691      note c_d=this[rule_format]
   1.692 -    show "P s" unfolding c_d apply(rule as[rule_format]) proof- case goal1 show ?case 
   1.693 +    show "P s" unfolding c_d apply(rule as[rule_format]) proof- case goal1 thus ?case 
   1.694          using c_d(2)[of i] using ab[THEN spec[where x=i]] by auto qed
   1.695      show "\<exists>a b. s = {a..b}" unfolding c_d by auto
   1.696      fix t assume "t\<in>?A" then guess e unfolding mem_Collect_eq .. then guess f apply- by(erule exE,(erule conjE)+)
   1.697      note e_f=this[rule_format]
   1.698      assume "s \<noteq> t" hence "\<not> (c = e \<and> d = f)" unfolding c_d e_f by auto
   1.699 -    then obtain i where "c$i \<noteq> e$i \<or> d$i \<noteq> f$i" unfolding de_Morgan_conj Cart_eq by auto
   1.700 -    hence i:"c$i \<noteq> e$i" "d$i \<noteq> f$i" apply- apply(erule_tac[!] disjE)
   1.701 -    proof- assume "c$i \<noteq> e$i" thus "d$i \<noteq> f$i" using c_d(2)[of i] e_f(2)[of i] by fastsimp
   1.702 -    next   assume "d$i \<noteq> f$i" thus "c$i \<noteq> e$i" using c_d(2)[of i] e_f(2)[of i] by fastsimp
   1.703 +    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
   1.704 +    hence i:"c$$i \<noteq> e$$i" "d$$i \<noteq> f$$i" apply- apply(erule_tac[!] disjE)
   1.705 +    proof- assume "c$$i \<noteq> e$$i" thus "d$$i \<noteq> f$$i" using c_d(2)[of i] e_f(2)[of i] by fastsimp
   1.706 +    next   assume "d$$i \<noteq> f$$i" thus "c$$i \<noteq> e$$i" using c_d(2)[of i] e_f(2)[of i] by fastsimp
   1.707      qed have *:"\<And>s t. (\<And>a. a\<in>s \<Longrightarrow> a\<in>t \<Longrightarrow> False) \<Longrightarrow> s \<inter> t = {}" by auto
   1.708      show "interior s \<inter> interior t = {}" unfolding e_f c_d interior_closed_interval proof(rule *)
   1.709        fix x assume "x\<in>{c<..<d}" "x\<in>{e<..<f}"
   1.710 -      hence x:"c$i < d$i" "e$i < f$i" "c$i < f$i" "e$i < d$i" unfolding mem_interval apply-apply(erule_tac[!] x=i in allE)+ by auto
   1.711 -      show False using c_d(2)[of i] apply- apply(erule_tac disjE)
   1.712 -      proof(erule_tac[!] conjE) assume as:"c $ i = a $ i" "d $ i = (a $ i + b $ i) / 2"
   1.713 +      hence x:"c$$i < d$$i" "e$$i < f$$i" "c$$i < f$$i" "e$$i < d$$i" unfolding mem_interval using i'
   1.714 +        apply-apply(erule_tac[!] x=i in allE)+ by auto
   1.715 +      show False using c_d(2)[OF i'] apply- apply(erule_tac disjE)
   1.716 +      proof(erule_tac[!] conjE) assume as:"c $$ i = a $$ i" "d $$ i = (a $$ i + b $$ i) / 2"
   1.717          show False using e_f(2)[of i] and i x unfolding as by(fastsimp simp add:field_simps)
   1.718 -      next assume as:"c $ i = (a $ i + b $ i) / 2" "d $ i = b $ i"
   1.719 +      next assume as:"c $$ i = (a $$ i + b $$ i) / 2" "d $$ i = b $$ i"
   1.720          show False using e_f(2)[of i] and i x unfolding as by(fastsimp simp add:field_simps)
   1.721        qed qed qed
   1.722    also have "\<Union> ?A = {a..b}" proof(rule set_ext,rule)
   1.723      fix x assume "x\<in>\<Union>?A" then guess Y unfolding Union_iff ..
   1.724      from this(1) guess c unfolding mem_Collect_eq .. then guess d ..
   1.725      note c_d = this[THEN conjunct2,rule_format] `x\<in>Y`[unfolded this[THEN conjunct1]]
   1.726 -    show "x\<in>{a..b}" unfolding mem_interval proof 
   1.727 -      fix i show "a $ i \<le> x $ i \<and> x $ i \<le> b $ i"
   1.728 +    show "x\<in>{a..b}" unfolding mem_interval proof safe
   1.729 +      fix i assume "i<DIM('a)" thus "a $$ i \<le> x $$ i" "x $$ i \<le> b $$ i"
   1.730          using c_d(1)[of i] c_d(2)[unfolded mem_interval,THEN spec[where x=i]] by auto qed
   1.731    next fix x assume x:"x\<in>{a..b}"
   1.732 -    have "\<forall>i. \<exists>c d. (c = a$i \<and> d = (a$i + b$i) / 2 \<or> c = (a$i + b$i) / 2 \<and> d = b$i) \<and> c\<le>x$i \<and> x$i \<le> d"
   1.733 -      (is "\<forall>i. \<exists>c d. ?P i c d") unfolding mem_interval proof fix i
   1.734 -      have "?P i (a$i) ((a $ i + b $ i) / 2) \<or> ?P i ((a $ i + b $ i) / 2) (b$i)"
   1.735 +    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"
   1.736 +      (is "\<forall>i<DIM('a). \<exists>c d. ?P i c d") unfolding mem_interval proof(rule,rule) fix i
   1.737 +      have "?P i (a$$i) ((a $$ i + b $$ i) / 2) \<or> ?P i ((a $$ i + b $$ i) / 2) (b$$i)"
   1.738          using x[unfolded mem_interval,THEN spec[where x=i]] by auto thus "\<exists>c d. ?P i c d" by blast
   1.739 -    qed thus "x\<in>\<Union>?A" unfolding Union_iff lambda_skolem unfolding Bex_def mem_Collect_eq
   1.740 +    qed thus "x\<in>\<Union>?A" unfolding Union_iff unfolding lambda_skolem' unfolding Bex_def mem_Collect_eq
   1.741        apply-apply(erule exE)+ apply(rule_tac x="{xa..xaa}" in exI) unfolding mem_interval by auto
   1.742    qed finally show False using assms by auto qed
   1.743  
   1.744 -lemma interval_bisection:
   1.745 -  assumes "P {}" "(\<forall>s t. P s \<and> P t \<and> interior(s) \<inter> interior(t) = {} \<longrightarrow> P(s \<union> t))" "\<not> P {a..b::real^'n}"
   1.746 +lemma interval_bisection: fixes type::"'a::ordered_euclidean_space"
   1.747 +  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}"
   1.748    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})"
   1.749  proof-
   1.750 -  have "\<forall>x. \<exists>y. \<not> P {fst x..snd x} \<longrightarrow> (\<not> P {fst y..snd y} \<and> (\<forall>i. fst x$i \<le> fst y$i \<and> fst y$i \<le> snd y$i \<and> snd y$i \<le> snd x$i \<and>
   1.751 -                           2 * (snd y$i - fst y$i) \<le> snd x$i - fst x$i))" proof case goal1 thus ?case proof-
   1.752 +  have "\<forall>x. \<exists>y. \<not> P {fst x..snd x} \<longrightarrow> (\<not> P {fst y..snd y} \<and>
   1.753 +    (\<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>
   1.754 +                           2 * (snd y$$i - fst y$$i) \<le> snd x$$i - fst x$$i))" proof case goal1 thus ?case proof-
   1.755        presume "\<not> P {fst x..snd x} \<Longrightarrow> ?thesis"
   1.756        thus ?thesis apply(cases "P {fst x..snd x}") by auto
   1.757      next assume as:"\<not> P {fst x..snd x}" from interval_bisection_step[of P, OF assms(1-2) as] guess c d . 
   1.758 @@ -1058,8 +1065,8 @@
   1.759      qed qed then guess f apply-apply(drule choice) by(erule exE) note f=this
   1.760    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
   1.761    have "A 0 = a" "B 0 = b" "\<And>n. \<not> P {A(Suc n)..B(Suc n)} \<and>
   1.762 -    (\<forall>i. A(n)$i \<le> A(Suc n)$i \<and> A(Suc n)$i \<le> B(Suc n)$i \<and> B(Suc n)$i \<le> B(n)$i \<and> 
   1.763 -    2 * (B(Suc n)$i - A(Suc n)$i) \<le> B(n)$i - A(n)$i)" (is "\<And>n. ?P n")
   1.764 +    (\<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> 
   1.765 +    2 * (B(Suc n)$$i - A(Suc n)$$i) \<le> B(n)$$i - A(n)$$i)" (is "\<And>n. ?P n")
   1.766    proof- show "A 0 = a" "B 0 = b" unfolding ab_def by auto
   1.767      case goal3 note S = ab_def funpow.simps o_def id_apply show ?case
   1.768      proof(induct n) case 0 thus ?case unfolding S apply(rule f[rule_format]) using assms(3) by auto
   1.769 @@ -1067,19 +1074,19 @@
   1.770      qed qed note AB = this(1-2) conjunctD2[OF this(3),rule_format]
   1.771  
   1.772    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"
   1.773 -  proof- case goal1 guess n using real_arch_pow2[of "(setsum (\<lambda>i. b$i - a$i) UNIV) / e"] .. note n=this
   1.774 +  proof- case goal1 guess n using real_arch_pow2[of "(setsum (\<lambda>i. b$$i - a$$i) {..<DIM('a)}) / e"] .. note n=this
   1.775      show ?case apply(rule_tac x=n in exI) proof(rule,rule)
   1.776        fix x y assume xy:"x\<in>{A n..B n}" "y\<in>{A n..B n}"
   1.777 -      have "dist x y \<le> setsum (\<lambda>i. abs((x - y)$i)) UNIV" unfolding dist_norm by(rule norm_le_l1)
   1.778 -      also have "\<dots> \<le> setsum (\<lambda>i. B n$i - A n$i) UNIV"
   1.779 -      proof(rule setsum_mono) fix i show "\<bar>(x - y) $ i\<bar> \<le> B n $ i - A n $ i"
   1.780 -          using xy[unfolded mem_interval,THEN spec[where x=i]]
   1.781 -          unfolding vector_minus_component by auto qed
   1.782 -      also have "\<dots> \<le> setsum (\<lambda>i. b$i - a$i) UNIV / 2^n" unfolding setsum_divide_distrib
   1.783 +      have "dist x y \<le> setsum (\<lambda>i. abs((x - y)$$i)) {..<DIM('a)}" unfolding dist_norm by(rule norm_le_l1)
   1.784 +      also have "\<dots> \<le> setsum (\<lambda>i. B n$$i - A n$$i) {..<DIM('a)}"
   1.785 +      proof(rule setsum_mono) fix i show "\<bar>(x - y) $$ i\<bar> \<le> B n $$ i - A n $$ i"
   1.786 +          using xy[unfolded mem_interval,THEN spec[where x=i]] by auto qed
   1.787 +      also have "\<dots> \<le> setsum (\<lambda>i. b$$i - a$$i) {..<DIM('a)} / 2^n" unfolding setsum_divide_distrib
   1.788        proof(rule setsum_mono) case goal1 thus ?case
   1.789          proof(induct n) case 0 thus ?case unfolding AB by auto
   1.790 -        next case (Suc n) have "B (Suc n) $ i - A (Suc n) $ i \<le> (B n $ i - A n $ i) / 2" using AB(4)[of n i] by auto
   1.791 -          also have "\<dots> \<le> (b $ i - a $ i) / 2 ^ Suc n" using Suc by(auto simp add:field_simps) finally show ?case .
   1.792 +        next case (Suc n) have "B (Suc n) $$ i - A (Suc n) $$ i \<le> (B n $$ i - A n $$ i) / 2"
   1.793 +            using AB(4)[of i n] using goal1 by auto
   1.794 +          also have "\<dots> \<le> (b $$ i - a $$ i) / 2 ^ Suc n" using Suc by(auto simp add:field_simps) finally show ?case .
   1.795          qed qed
   1.796        also have "\<dots> < e" using n using goal1 by(auto simp add:field_simps) finally show "dist x y < e" .
   1.797      qed qed
   1.798 @@ -1088,7 +1095,7 @@
   1.799      proof(induct d) case 0 thus ?case by auto
   1.800      next case (Suc d) show ?case apply(rule subset_trans[OF _ Suc])
   1.801          apply(rule) unfolding mem_interval apply(rule,erule_tac x=i in allE)
   1.802 -      proof- case goal1 thus ?case using AB(4)[of "m + d" i] by(auto simp add:field_simps)
   1.803 +      proof- case goal1 thus ?case using AB(4)[of i "m + d"] by(auto simp add:field_simps)
   1.804        qed qed } note ABsubset = this 
   1.805    have "\<exists>a. \<forall>n. a\<in>{A n..B n}" apply(rule decreasing_closed_nest[rule_format,OF closed_interval _ ABsubset interv])
   1.806    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
   1.807 @@ -1106,7 +1113,7 @@
   1.808  subsection {* Cousin's lemma. *}
   1.809  
   1.810  lemma fine_division_exists: assumes "gauge g" 
   1.811 -  obtains p where "p tagged_division_of {a..b::real^'n}" "g fine p"
   1.812 +  obtains p where "p tagged_division_of {a..b::'a::ordered_euclidean_space}" "g fine p"
   1.813  proof- presume "\<not> (\<exists>p. p tagged_division_of {a..b} \<and> g fine p) \<Longrightarrow> False"
   1.814    then guess p unfolding atomize_not not_not .. thus thesis apply-apply(rule that[of p]) by auto
   1.815  next assume as:"\<not> (\<exists>p. p tagged_division_of {a..b} \<and> g fine p)"
   1.816 @@ -1124,10 +1131,10 @@
   1.817  
   1.818  subsection {* Basic theorems about integrals. *}
   1.819  
   1.820 -lemma has_integral_unique: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
   1.821 +lemma has_integral_unique: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector"
   1.822    assumes "(f has_integral k1) i" "(f has_integral k2) i" shows "k1 = k2"
   1.823  proof(rule ccontr) let ?e = "norm(k1 - k2) / 2" assume as:"k1 \<noteq> k2" hence e:"?e > 0" by auto
   1.824 -  have lem:"\<And>f::real^'n \<Rightarrow> 'a.  \<And> a b k1 k2.
   1.825 +  have lem:"\<And>f::'n \<Rightarrow> 'a.  \<And> a b k1 k2.
   1.826      (f has_integral k1) ({a..b}) \<Longrightarrow> (f has_integral k2) ({a..b}) \<Longrightarrow> k1 \<noteq> k2 \<Longrightarrow> False"
   1.827    proof- case goal1 let ?e = "norm(k1 - k2) / 2" from goal1(3) have e:"?e > 0" by auto
   1.828      guess d1 by(rule has_integralD[OF goal1(1) e]) note d1=this
   1.829 @@ -1144,7 +1151,7 @@
   1.830    assume as:"\<not> (\<exists>a b. i = {a..b})"
   1.831    guess B1 by(rule has_integral_altD[OF assms(1) as,OF e]) note B1=this[rule_format]
   1.832    guess B2 by(rule has_integral_altD[OF assms(2) as,OF e]) note B2=this[rule_format]
   1.833 -  have "\<exists>a b::real^'n. ball 0 B1 \<union> ball 0 B2 \<subseteq> {a..b}" apply(rule bounded_subset_closed_interval)
   1.834 +  have "\<exists>a b::'n. ball 0 B1 \<union> ball 0 B2 \<subseteq> {a..b}" apply(rule bounded_subset_closed_interval)
   1.835      using bounded_Un bounded_ball by auto then guess a b apply-by(erule exE)+
   1.836    note ab=conjunctD2[OF this[unfolded Un_subset_iff]]
   1.837    guess w using B1(2)[OF ab(1)] .. note w=conjunctD2[OF this]
   1.838 @@ -1159,11 +1166,11 @@
   1.839    "(f has_integral y) k \<Longrightarrow> integral k f = y"
   1.840    unfolding integral_def apply(rule some_equality) by(auto intro: has_integral_unique) 
   1.841  
   1.842 -lemma has_integral_is_0: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector" 
   1.843 +lemma has_integral_is_0: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector" 
   1.844    assumes "\<forall>x\<in>s. f x = 0" shows "(f has_integral 0) s"
   1.845 -proof- have lem:"\<And>a b. \<And>f::real^'n \<Rightarrow> 'a.
   1.846 +proof- have lem:"\<And>a b. \<And>f::'n \<Rightarrow> 'a.
   1.847      (\<forall>x\<in>{a..b}. f(x) = 0) \<Longrightarrow> (f has_integral 0) ({a..b})" unfolding has_integral
   1.848 -  proof(rule,rule) fix a b e and f::"real^'n \<Rightarrow> 'a"
   1.849 +  proof(rule,rule) fix a b e and f::"'n \<Rightarrow> 'a"
   1.850      assume as:"\<forall>x\<in>{a..b}. f x = 0" "0 < (e::real)"
   1.851      show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) < e)"
   1.852        apply(rule_tac x="\<lambda>x. ball x 1" in exI)  apply(rule,rule gaugeI) unfolding centre_in_ball defer apply(rule open_ball)
   1.853 @@ -1179,20 +1186,20 @@
   1.854    assume "\<not> (\<exists>a b. s = {a..b})" thus ?thesis apply(subst has_integral_alt) unfolding if_not_P *
   1.855    apply(rule,rule,rule_tac x=1 in exI,rule) defer apply(rule,rule,rule)
   1.856    proof- fix e::real and a b assume "e>0"
   1.857 -    thus "\<exists>z. ((\<lambda>x::real^'n. 0::'a) has_integral z) {a..b} \<and> norm (z - 0) < e"
   1.858 +    thus "\<exists>z. ((\<lambda>x::'n. 0::'a) has_integral z) {a..b} \<and> norm (z - 0) < e"
   1.859        apply(rule_tac x=0 in exI) apply(rule,rule lem) by auto
   1.860    qed auto qed
   1.861  
   1.862 -lemma has_integral_0[simp]: "((\<lambda>x::real^'n. 0) has_integral 0) s"
   1.863 +lemma has_integral_0[simp]: "((\<lambda>x::'n::ordered_euclidean_space. 0) has_integral 0) s"
   1.864    apply(rule has_integral_is_0) by auto 
   1.865  
   1.866  lemma has_integral_0_eq[simp]: "((\<lambda>x. 0) has_integral i) s \<longleftrightarrow> i = 0"
   1.867    using has_integral_unique[OF has_integral_0] by auto
   1.868  
   1.869 -lemma has_integral_linear: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
   1.870 +lemma has_integral_linear: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector"
   1.871    assumes "(f has_integral y) s" "bounded_linear h" shows "((h o f) has_integral ((h y))) s"
   1.872  proof- interpret bounded_linear h using assms(2) . from pos_bounded guess B .. note B=conjunctD2[OF this,rule_format]
   1.873 -  have lem:"\<And>f::real^'n \<Rightarrow> 'a. \<And> y a b.
   1.874 +  have lem:"\<And>f::'n \<Rightarrow> 'a. \<And> y a b.
   1.875      (f has_integral y) ({a..b}) \<Longrightarrow> ((h o f) has_integral h(y)) ({a..b})"
   1.876    proof(subst has_integral,rule,rule) case goal1
   1.877      from pos_bounded guess B .. note B=conjunctD2[OF this,rule_format]
   1.878 @@ -1231,10 +1238,10 @@
   1.879    shows "(f has_integral k) s \<Longrightarrow> ((\<lambda>x. -(f x)) has_integral (-k)) s"
   1.880    apply(drule_tac c="-1" in has_integral_cmul) by auto
   1.881  
   1.882 -lemma has_integral_add: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector" 
   1.883 +lemma has_integral_add: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector" 
   1.884    assumes "(f has_integral k) s" "(g has_integral l) s"
   1.885    shows "((\<lambda>x. f x + g x) has_integral (k + l)) s"
   1.886 -proof- have lem:"\<And>f g::real^'n \<Rightarrow> 'a. \<And>a b k l.
   1.887 +proof- have lem:"\<And>f g::'n \<Rightarrow> 'a. \<And>a b k l.
   1.888      (f has_integral k) ({a..b}) \<Longrightarrow> (g has_integral l) ({a..b}) \<Longrightarrow>
   1.889       ((\<lambda>x. f(x) + g(x)) has_integral (k + l)) ({a..b})" proof- case goal1
   1.890      show ?case unfolding has_integral proof(rule,rule) fix e::real assume e:"e>0" hence *:"e/2>0" by auto
   1.891 @@ -1259,8 +1266,8 @@
   1.892      from has_integral_altD[OF assms(1) as *] guess B1 . note B1=this[rule_format]
   1.893      from has_integral_altD[OF assms(2) as *] guess B2 . note B2=this[rule_format]
   1.894      show ?case apply(rule_tac x="max B1 B2" in exI) apply(rule,rule min_max.less_supI1,rule B1)
   1.895 -    proof(rule,rule,rule) fix a b assume "ball 0 (max B1 B2) \<subseteq> {a..b::real^'n}"
   1.896 -      hence *:"ball 0 B1 \<subseteq> {a..b::real^'n}" "ball 0 B2 \<subseteq> {a..b::real^'n}" by auto
   1.897 +    proof(rule,rule,rule) fix a b assume "ball 0 (max B1 B2) \<subseteq> {a..b::'n}"
   1.898 +      hence *:"ball 0 B1 \<subseteq> {a..b::'n}" "ball 0 B2 \<subseteq> {a..b::'n}" by auto
   1.899        guess w using B1(2)[OF *(1)] .. note w=conjunctD2[OF this]
   1.900        guess z using B2(2)[OF *(2)] .. note z=conjunctD2[OF this]
   1.901        have *:"\<And>x. (if x \<in> s then f x + g x else 0) = (if x \<in> s then f x else 0) + (if x \<in> s then g x else 0)" by auto
   1.902 @@ -1273,7 +1280,7 @@
   1.903    shows "(f has_integral k) s \<Longrightarrow> (g has_integral l) s \<Longrightarrow> ((\<lambda>x. f(x) - g(x)) has_integral (k - l)) s"
   1.904    using has_integral_add[OF _ has_integral_neg,of f k s g l] unfolding algebra_simps by auto
   1.905  
   1.906 -lemma integral_0: "integral s (\<lambda>x::real^'n. 0::real^'m) = 0"
   1.907 +lemma integral_0: "integral s (\<lambda>x::'n::ordered_euclidean_space. 0::'m::real_normed_vector) = 0"
   1.908    by(rule integral_unique has_integral_0)+
   1.909  
   1.910  lemma integral_add:
   1.911 @@ -1326,9 +1333,9 @@
   1.912    apply(drule has_integral_linear,assumption,assumption) unfolding has_integral_integral[THEN sym]
   1.913    apply(rule integrable_linear) by assumption+
   1.914  
   1.915 -lemma integral_component_eq[simp]: fixes f::"real^'n \<Rightarrow> real^'m"
   1.916 -  assumes "f integrable_on s" shows "integral s (\<lambda>x. f x $ k) = integral s f $ k"
   1.917 -  using integral_linear[OF assms(1) bounded_linear_component,unfolded o_def] .
   1.918 +lemma integral_component_eq[simp]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
   1.919 +  assumes "f integrable_on s" shows "integral s (\<lambda>x. f x $$ k) = integral s f $$ k"
   1.920 +  unfolding integral_linear[OF assms(1) bounded_linear_component,unfolded o_def] ..
   1.921  
   1.922  lemma has_integral_setsum:
   1.923    assumes "finite t" "\<forall>a\<in>t. ((f a) has_integral (i a)) s"
   1.924 @@ -1394,8 +1401,8 @@
   1.925  lemma integral_empty[simp]: shows "integral {} f = 0"
   1.926    apply(rule integral_unique) using has_integral_empty .
   1.927  
   1.928 -lemma has_integral_refl[intro]: shows "(f has_integral 0) {a..a}" "(f has_integral 0) {a}"
   1.929 -proof- have *:"{a} = {a..a}" apply(rule set_ext) unfolding mem_interval singleton_iff Cart_eq
   1.930 +lemma has_integral_refl[intro]: shows "(f has_integral 0) {a..a}" "(f has_integral 0) {a::'a::ordered_euclidean_space}"
   1.931 +proof- have *:"{a} = {a..a}" apply(rule set_ext) unfolding mem_interval singleton_iff euclidean_eq[where 'a='a]
   1.932      apply safe prefer 3 apply(erule_tac x=i in allE) by(auto simp add: field_simps)
   1.933    show "(f has_integral 0) {a..a}" "(f has_integral 0) {a}" unfolding *
   1.934      apply(rule_tac[!] has_integral_null) unfolding content_eq_0_interior
   1.935 @@ -1407,7 +1414,8 @@
   1.936  
   1.937  subsection {* Cauchy-type criterion for integrability. *}
   1.938  
   1.939 -lemma integrable_cauchy: fixes f::"real^'n \<Rightarrow> 'a::{real_normed_vector,complete_space}" 
   1.940 +(* XXXXXXX *)
   1.941 +lemma integrable_cauchy: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::{real_normed_vector,complete_space}" 
   1.942    shows "f integrable_on {a..b} \<longleftrightarrow>
   1.943    (\<forall>e>0.\<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of {a..b} \<and> d fine p1 \<and>
   1.944                              p2 tagged_division_of {a..b} \<and> d fine p2
   1.945 @@ -1455,118 +1463,127 @@
   1.946  
   1.947  subsection {* Additivity of integral on abutting intervals. *}
   1.948  
   1.949 -lemma interval_split:
   1.950 -  "{a..b::real^'n} \<inter> {x. x$k \<le> c} = {a .. (\<chi> i. if i = k then min (b$k) c else b$i)}"
   1.951 -  "{a..b} \<inter> {x. x$k \<ge> c} = {(\<chi> i. if i = k then max (a$k) c else a$i) .. b}"
   1.952 -  apply(rule_tac[!] set_ext) unfolding Int_iff mem_interval mem_Collect_eq
   1.953 -  unfolding Cart_lambda_beta by auto
   1.954 -
   1.955 -lemma content_split:
   1.956 -  "content {a..b::real^'n} = content({a..b} \<inter> {x. x$k \<le> c}) + content({a..b} \<inter> {x. x$k >= c})"
   1.957 -proof- note simps = interval_split content_closed_interval_cases Cart_lambda_beta vector_le_def
   1.958 -  { presume "a\<le>b \<Longrightarrow> ?thesis" thus ?thesis apply(cases "a\<le>b") unfolding simps by auto }
   1.959 -  have *:"UNIV = insert k (UNIV - {k})" "\<And>x. finite (UNIV-{x::'n})" "\<And>x. x\<notin>UNIV-{x}" by auto
   1.960 -  have *:"\<And>X Y Z. (\<Prod>i\<in>UNIV. Z i (if i = k then X else Y i)) = Z k X * (\<Prod>i\<in>UNIV-{k}. Z i (Y i))"
   1.961 -    "(\<Prod>i\<in>UNIV. b$i - a$i) = (\<Prod>i\<in>UNIV-{k}. b$i - a$i) * (b$k - a$k)" 
   1.962 +lemma interval_split: fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)" shows
   1.963 +  "{a..b} \<inter> {x. x$$k \<le> c} = {a .. (\<chi>\<chi> i. if i = k then min (b$$k) c else b$$i)}"
   1.964 +  "{a..b} \<inter> {x. x$$k \<ge> c} = {(\<chi>\<chi> i. if i = k then max (a$$k) c else a$$i) .. b}"
   1.965 +  apply(rule_tac[!] set_ext) unfolding Int_iff mem_interval mem_Collect_eq using assms by auto
   1.966 +
   1.967 +lemma content_split: fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)" shows
   1.968 +  "content {a..b} = content({a..b} \<inter> {x. x$$k \<le> c}) + content({a..b} \<inter> {x. x$$k >= c})"
   1.969 +proof- note simps = interval_split[OF assms] content_closed_interval_cases eucl_le[where 'a='a]
   1.970 +  { presume "a\<le>b \<Longrightarrow> ?thesis" thus ?thesis apply(cases "a\<le>b") unfolding simps using assms by auto }
   1.971 +  have *:"{..<DIM('a)} = insert k ({..<DIM('a)} - {k})" "\<And>x. finite ({..<DIM('a)}-{x})" "\<And>x. x\<notin>{..<DIM('a)}-{x}"
   1.972 +    using assms by auto
   1.973 +  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))"
   1.974 +    "(\<Prod>i\<in>{..<DIM('a)}. b$$i - a$$i) = (\<Prod>i\<in>{..<DIM('a)}-{k}. b$$i - a$$i) * (b$$k - a$$k)" 
   1.975      apply(subst *(1)) defer apply(subst *(1)) unfolding setprod_insert[OF *(2-)] by auto
   1.976 -  assume as:"a\<le>b" moreover have "\<And>x. min (b $ k) c = max (a $ k) c
   1.977 -    \<Longrightarrow> x* (b$k - a$k) = x*(max (a $ k) c - a $ k) + x*(b $ k - max (a $ k) c)"
   1.978 +  assume as:"a\<le>b" moreover have "\<And>x. min (b $$ k) c = max (a $$ k) c
   1.979 +    \<Longrightarrow> x* (b$$k - a$$k) = x*(max (a $$ k) c - a $$ k) + x*(b $$ k - max (a $$ k) c)"
   1.980      by  (auto simp add:field_simps)
   1.981 -  moreover have "\<not> a $ k \<le> c \<Longrightarrow> \<not> c \<le> b $ k \<Longrightarrow> False"
   1.982 -    unfolding not_le using as[unfolded vector_le_def,rule_format,of k] by auto
   1.983 -  ultimately show ?thesis 
   1.984 -    unfolding simps unfolding *(1)[of "\<lambda>i x. b$i - x"] *(1)[of "\<lambda>i x. x - a$i"] *(2) by(auto)
   1.985 +  moreover have **:"(\<Prod>i<DIM('a). ((\<chi>\<chi> i. if i = k then min (b $$ k) c else b $$ i)::'a) $$ i - a $$ i) = 
   1.986 +    (\<Prod>i<DIM('a). (if i = k then min (b $$ k) c else b $$ i) - a $$ i)"
   1.987 +    "(\<Prod>i<DIM('a). b $$ i - ((\<chi>\<chi> i. if i = k then max (a $$ k) c else a $$ i)::'a) $$ i) =
   1.988 +    (\<Prod>i<DIM('a). b $$ i - (if i = k then max (a $$ k) c else a $$ i))"
   1.989 +    apply(rule_tac[!] setprod.cong) by auto
   1.990 +  have "\<not> a $$ k \<le> c \<Longrightarrow> \<not> c \<le> b $$ k \<Longrightarrow> False"
   1.991 +    unfolding not_le using as[unfolded eucl_le[where 'a='a],rule_format,of k] assms by auto
   1.992 +  ultimately show ?thesis using assms unfolding simps **
   1.993 +    unfolding *(1)[of "\<lambda>i x. b$$i - x"] *(1)[of "\<lambda>i x. x - a$$i"] unfolding  *(2) 
   1.994 +    apply(subst(2) euclidean_lambda_beta''[where 'a='a])
   1.995 +    apply(subst(3) euclidean_lambda_beta''[where 'a='a]) by auto
   1.996  qed
   1.997  
   1.998 -lemma division_split_left_inj:
   1.999 -  assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2"
  1.1000 -  "k1 \<inter> {x::real^'n. x$k \<le> c} = k2 \<inter> {x. x$k \<le> c}"
  1.1001 -  shows "content(k1 \<inter> {x. x$k \<le> c}) = 0"
  1.1002 +lemma division_split_left_inj: fixes type::"'a::ordered_euclidean_space"
  1.1003 +  assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2" 
  1.1004 +  "k1 \<inter> {x::'a. x$$k \<le> c} = k2 \<inter> {x. x$$k \<le> c}"and k:"k<DIM('a)"
  1.1005 +  shows "content(k1 \<inter> {x. x$$k \<le> c}) = 0"
  1.1006  proof- note d=division_ofD[OF assms(1)]
  1.1007 -  have *:"\<And>a b::real^'n. \<And> c k. (content({a..b} \<inter> {x. x$k \<le> c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x$k \<le> c}) = {})"
  1.1008 -    unfolding interval_split content_eq_0_interior by auto
  1.1009 +  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}) = {})"
  1.1010 +    unfolding  interval_split[OF k] content_eq_0_interior by auto
  1.1011    guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
  1.1012    guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
  1.1013    have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
  1.1014    show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
  1.1015      defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
  1.1016 -
  1.1017 -lemma division_split_right_inj:
  1.1018 + 
  1.1019 +lemma division_split_right_inj: fixes type::"'a::ordered_euclidean_space"
  1.1020    assumes "d division_of i" "k1 \<in> d" "k2 \<in> d"  "k1 \<noteq> k2"
  1.1021 -  "k1 \<inter> {x::real^'n. x$k \<ge> c} = k2 \<inter> {x. x$k \<ge> c}"
  1.1022 -  shows "content(k1 \<inter> {x. x$k \<ge> c}) = 0"
  1.1023 +  "k1 \<inter> {x::'a. x$$k \<ge> c} = k2 \<inter> {x. x$$k \<ge> c}" and k:"k<DIM('a)"
  1.1024 +  shows "content(k1 \<inter> {x. x$$k \<ge> c}) = 0"
  1.1025  proof- note d=division_ofD[OF assms(1)]
  1.1026 -  have *:"\<And>a b::real^'n. \<And> c k. (content({a..b} \<inter> {x. x$k >= c}) = 0 \<longleftrightarrow> interior({a..b} \<inter> {x. x$k >= c}) = {})"
  1.1027 -    unfolding interval_split content_eq_0_interior by auto
  1.1028 +  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}) = {})"
  1.1029 +    unfolding interval_split[OF k] content_eq_0_interior by auto
  1.1030    guess u1 v1 using d(4)[OF assms(2)] apply-by(erule exE)+ note uv1=this
  1.1031    guess u2 v2 using d(4)[OF assms(3)] apply-by(erule exE)+ note uv2=this
  1.1032    have **:"\<And>s t u. s \<inter> t = {} \<Longrightarrow> u \<subseteq> s \<Longrightarrow> u \<subseteq> t \<Longrightarrow> u = {}" by auto
  1.1033    show ?thesis unfolding uv1 uv2 * apply(rule **[OF d(5)[OF assms(2-4)]])
  1.1034      defer apply(subst assms(5)[unfolded uv1 uv2]) unfolding uv1 uv2 by auto qed
  1.1035  
  1.1036 -lemma tagged_division_split_left_inj:
  1.1037 -  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}" 
  1.1038 -  shows "content(k1 \<inter> {x. x$k \<le> c}) = 0"
  1.1039 +lemma tagged_division_split_left_inj: fixes x1::"'a::ordered_euclidean_space"
  1.1040 +  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}" 
  1.1041 +  and k:"k<DIM('a)"
  1.1042 +  shows "content(k1 \<inter> {x. x$$k \<le> c}) = 0"
  1.1043  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
  1.1044    show ?thesis apply(rule division_split_left_inj[OF division_of_tagged_division[OF assms(1)]])
  1.1045      apply(rule_tac[1-2] *) using assms(2-) by auto qed
  1.1046  
  1.1047 -lemma tagged_division_split_right_inj:
  1.1048 -  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}" 
  1.1049 -  shows "content(k1 \<inter> {x. x$k \<ge> c}) = 0"
  1.1050 +lemma tagged_division_split_right_inj: fixes x1::"'a::ordered_euclidean_space"
  1.1051 +  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}" 
  1.1052 +  and k:"k<DIM('a)"
  1.1053 +  shows "content(k1 \<inter> {x. x$$k \<ge> c}) = 0"
  1.1054  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
  1.1055    show ?thesis apply(rule division_split_right_inj[OF division_of_tagged_division[OF assms(1)]])
  1.1056      apply(rule_tac[1-2] *) using assms(2-) by auto qed
  1.1057  
  1.1058 -lemma division_split:
  1.1059 -  assumes "p division_of {a..b::real^'n}"
  1.1060 -  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 
  1.1061 -        "{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")
  1.1062 -proof(rule_tac[!] division_ofI) note p=division_ofD[OF assms]
  1.1063 +lemma division_split: fixes a::"'a::ordered_euclidean_space"
  1.1064 +  assumes "p division_of {a..b}" and k:"k<DIM('a)"
  1.1065 +  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 
  1.1066 +        "{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")
  1.1067 +proof(rule_tac[!] division_ofI) note p=division_ofD[OF assms(1)]
  1.1068    show "finite ?p1" "finite ?p2" using p(1) by auto show "\<Union>?p1 = ?I1" "\<Union>?p2 = ?I2" unfolding p(6)[THEN sym] by auto
  1.1069    { fix k assume "k\<in>?p1" then guess l unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l=this
  1.1070      guess u v using p(4)[OF l(2)] apply-by(erule exE)+ note uv=this
  1.1071      show "k\<subseteq>?I1" "k \<noteq> {}" "\<exists>a b. k = {a..b}" unfolding l
  1.1072 -      using p(2-3)[OF l(2)] l(3) unfolding uv apply- prefer 3 apply(subst interval_split) by auto
  1.1073 +      using p(2-3)[OF l(2)] l(3) unfolding uv apply- prefer 3 apply(subst interval_split[OF k]) by auto
  1.1074      fix k' assume "k'\<in>?p1" then guess l' unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l'=this
  1.1075      assume "k\<noteq>k'" thus "interior k \<inter> interior k' = {}" unfolding l l' using p(5)[OF l(2) l'(2)] by auto }
  1.1076    { fix k assume "k\<in>?p2" then guess l unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l=this
  1.1077      guess u v using p(4)[OF l(2)] apply-by(erule exE)+ note uv=this
  1.1078      show "k\<subseteq>?I2" "k \<noteq> {}" "\<exists>a b. k = {a..b}" unfolding l
  1.1079 -      using p(2-3)[OF l(2)] l(3) unfolding uv apply- prefer 3 apply(subst interval_split) by auto
  1.1080 +      using p(2-3)[OF l(2)] l(3) unfolding uv apply- prefer 3 apply(subst interval_split[OF k]) by auto
  1.1081      fix k' assume "k'\<in>?p2" then guess l' unfolding mem_Collect_eq apply-by(erule exE,(erule conjE)+) note l'=this
  1.1082      assume "k\<noteq>k'" thus "interior k \<inter> interior k' = {}" unfolding l l' using p(5)[OF l(2) l'(2)] by auto }
  1.1083  qed
  1.1084  
  1.1085 -lemma has_integral_split: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  1.1086 -  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})"
  1.1087 +lemma has_integral_split: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector"
  1.1088 +  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)"
  1.1089    shows "(f has_integral (i + j)) ({a..b})"
  1.1090  proof(unfold has_integral,rule,rule) case goal1 hence e:"e/2>0" by auto
  1.1091 -  guess d1 using has_integralD[OF assms(1)[unfolded interval_split] e] . note d1=this[unfolded interval_split[THEN sym]]
  1.1092 -  guess d2 using has_integralD[OF assms(2)[unfolded interval_split] e] . note d2=this[unfolded interval_split[THEN sym]]
  1.1093 -  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"
  1.1094 +  guess d1 using has_integralD[OF assms(1)[unfolded interval_split[OF k]] e] . note d1=this[unfolded interval_split[THEN sym,OF k]]
  1.1095 +  guess d2 using has_integralD[OF assms(2)[unfolded interval_split[OF k]] e] . note d2=this[unfolded interval_split[THEN sym,OF k]]
  1.1096 +  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"
  1.1097    show ?case apply(rule_tac x="?d" in exI,rule) defer apply(rule,rule,(erule conjE)+)
  1.1098    proof- show "gauge ?d" using d1(1) d2(1) unfolding gauge_def by auto
  1.1099      fix p assume "p tagged_division_of {a..b}" "?d fine p" note p = this tagged_division_ofD[OF this(1)]
  1.1100 -    have lem0:"\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x$k \<le> c} = {}) \<Longrightarrow> x$k \<le> c"
  1.1101 -         "\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x$k \<ge> c} = {}) \<Longrightarrow> x$k \<ge> c"
  1.1102 +    have lem0:"\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x$$k \<le> c} = {}) \<Longrightarrow> x$$k \<le> c"
  1.1103 +         "\<And>x kk. (x,kk) \<in> p \<Longrightarrow> ~(kk \<inter> {x. x$$k \<ge> c} = {}) \<Longrightarrow> x$$k \<ge> c"
  1.1104      proof- fix x kk assume as:"(x,kk)\<in>p"
  1.1105 -      show "~(kk \<inter> {x. x$k \<le> c} = {}) \<Longrightarrow> x$k \<le> c"
  1.1106 +      show "~(kk \<inter> {x. x$$k \<le> c} = {}) \<Longrightarrow> x$$k \<le> c"
  1.1107        proof(rule ccontr) case goal1
  1.1108 -        from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x $ k - c\<bar>"
  1.1109 +        from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x $$ k - c\<bar>"
  1.1110            using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
  1.1111 -        hence "\<exists>y. y \<in> ball x \<bar>x $ k - c\<bar> \<inter> {x. x $ k \<le> c}" using goal1(1) by blast 
  1.1112 -        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)
  1.1113 -          using component_le_norm[of "x - y" k,unfolded vector_minus_component] by(auto simp add:dist_norm)
  1.1114 +        hence "\<exists>y. y \<in> ball x \<bar>x $$ k - c\<bar> \<inter> {x. x $$ k \<le> c}" using goal1(1) by blast 
  1.1115 +        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)
  1.1116 +          using component_le_norm[of "x - y" k] by(auto simp add:dist_norm)
  1.1117          thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
  1.1118        qed
  1.1119 -      show "~(kk \<inter> {x. x$k \<ge> c} = {}) \<Longrightarrow> x$k \<ge> c"
  1.1120 +      show "~(kk \<inter> {x. x$$k \<ge> c} = {}) \<Longrightarrow> x$$k \<ge> c"
  1.1121        proof(rule ccontr) case goal1
  1.1122 -        from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x $ k - c\<bar>"
  1.1123 +        from this(2)[unfolded not_le] have "kk \<subseteq> ball x \<bar>x $$ k - c\<bar>"
  1.1124            using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
  1.1125 -        hence "\<exists>y. y \<in> ball x \<bar>x $ k - c\<bar> \<inter> {x. x $ k \<ge> c}" using goal1(1) by blast 
  1.1126 -        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)
  1.1127 -          using component_le_norm[of "x - y" k,unfolded vector_minus_component] by(auto simp add:dist_norm)
  1.1128 +        hence "\<exists>y. y \<in> ball x \<bar>x $$ k - c\<bar> \<inter> {x. x $$ k \<ge> c}" using goal1(1) by blast 
  1.1129 +        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)
  1.1130 +          using component_le_norm[of "x - y" k] by(auto simp add:dist_norm)
  1.1131          thus False using goal1(2)[unfolded not_le] by(auto simp add:field_simps)
  1.1132        qed
  1.1133      qed
  1.1134 @@ -1574,11 +1591,11 @@
  1.1135      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
  1.1136      have lem2: "\<And>f s P f. finite s \<Longrightarrow> finite {(x,f k) | x k. (x,k) \<in> s \<and> P x k}"
  1.1137      proof- case goal1 thus ?case apply-apply(rule finite_subset[of _ "(\<lambda>(x,k). (x,f k)) ` s"]) by auto qed
  1.1138 -    have lem3: "\<And>g::(real ^ 'n \<Rightarrow> bool) \<Rightarrow> real ^ 'n \<Rightarrow> bool. finite p \<Longrightarrow>
  1.1139 +    have lem3: "\<And>g::('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool. finite p \<Longrightarrow>
  1.1140        setsum (\<lambda>(x,k). content k *\<^sub>R f x) {(x,g k) |x k. (x,k) \<in> p \<and> ~(g k = {})}
  1.1141                 = setsum (\<lambda>(x,k). content k *\<^sub>R f x) ((\<lambda>(x,k). (x,g k)) ` p)"
  1.1142        apply(rule setsum_mono_zero_left) prefer 3
  1.1143 -    proof fix g::"(real ^ 'n \<Rightarrow> bool) \<Rightarrow> real ^ 'n \<Rightarrow> bool" and i::"(real^'n) \<times> ((real^'n) set)"
  1.1144 +    proof fix g::"('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool" and i::"('a) \<times> (('a) set)"
  1.1145        assume "i \<in> (\<lambda>(x, k). (x, g k)) ` p - {(x, g k) |x k. (x, k) \<in> p \<and> g k \<noteq> {}}"
  1.1146        then obtain x k where xk:"i=(x,g k)" "(x,k)\<in>p" "(x,g k) \<notin> {(x, g k) |x k. (x, k) \<in> p \<and> g k \<noteq> {}}" by auto
  1.1147        have "content (g k) = 0" using xk using content_empty by auto
  1.1148 @@ -1586,17 +1603,17 @@
  1.1149      qed auto
  1.1150      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
  1.1151  
  1.1152 -    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> {}}"
  1.1153 +    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> {}}"
  1.1154      have "norm ((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) < e/2" apply(rule d1(2),rule tagged_division_ofI)
  1.1155        apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
  1.1156 -    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
  1.1157 +    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
  1.1158        fix x l assume xl:"(x,l)\<in>?M1"
  1.1159        then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
  1.1160        have "l' \<subseteq> d1 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
  1.1161        thus "l \<subseteq> d1 x" unfolding xl' by auto
  1.1162 -      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)
  1.1163 +      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)
  1.1164          using lem0(1)[OF xl'(3-4)] by auto
  1.1165 -      show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastsimp simp add: interval_split[where c=c and k=k])
  1.1166 +      show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastsimp simp add: interval_split[OF k,where c=c])
  1.1167        fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M1"
  1.1168        then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
  1.1169        assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
  1.1170 @@ -1606,17 +1623,17 @@
  1.1171          thus ?thesis using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
  1.1172        qed qed moreover
  1.1173  
  1.1174 -    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> {}}" 
  1.1175 +    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> {}}" 
  1.1176      have "norm ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j) < e/2" apply(rule d2(2),rule tagged_division_ofI)
  1.1177        apply(rule lem2 p(3))+ prefer 6 apply(rule fineI)
  1.1178 -    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
  1.1179 +    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
  1.1180        fix x l assume xl:"(x,l)\<in>?M2"
  1.1181        then guess x' l' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note xl'=this
  1.1182        have "l' \<subseteq> d2 x'" apply(rule order_trans[OF fineD[OF p(2) xl'(3)]]) by auto
  1.1183        thus "l \<subseteq> d2 x" unfolding xl' by auto
  1.1184 -      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)
  1.1185 +      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)
  1.1186          using lem0(2)[OF xl'(3-4)] by auto
  1.1187 -      show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastsimp simp add: interval_split[where c=c and k=k])
  1.1188 +      show  "\<exists>a b. l = {a..b}" unfolding xl' using p(6)[OF xl'(3)] by(fastsimp simp add: interval_split[OF k, where c=c])
  1.1189        fix y r let ?goal = "interior l \<inter> interior r = {}" assume yr:"(y,r)\<in>?M2"
  1.1190        then guess y' r' unfolding mem_Collect_eq apply- unfolding Pair_eq apply((erule exE)+,(erule conjE)+) .  note yr'=this
  1.1191        assume as:"(x,l) \<noteq> (y,r)" show "interior l \<inter> interior r = {}"
  1.1192 @@ -1628,108 +1645,121 @@
  1.1193  
  1.1194      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"
  1.1195        apply- apply(rule norm_triangle_lt) by auto
  1.1196 -    also { have *:"\<And>x y. x = (0::real) \<Longrightarrow> x *\<^sub>R (y::'a) = 0" using scaleR_zero_left by auto
  1.1197 +    also { have *:"\<And>x y. x = (0::real) \<Longrightarrow> x *\<^sub>R (y::'b) = 0" using scaleR_zero_left by auto
  1.1198        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)
  1.1199         = (\<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
  1.1200 -      also have "\<dots> = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. x $ k \<le> c}) *\<^sub>R f x) + (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. c \<le> x $ k}) *\<^sub>R f x) - (i + j)"
  1.1201 +      also have "\<dots> = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. x $$ k \<le> c}) *\<^sub>R f x) +
  1.1202 +        (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. c \<le> x $$ k}) *\<^sub>R f x) - (i + j)"
  1.1203          unfolding lem3[OF p(3)] apply(subst setsum_reindex_nonzero[OF p(3)]) defer apply(subst setsum_reindex_nonzero[OF p(3)])
  1.1204          defer unfolding lem4[THEN sym] apply(rule refl) unfolding split_paired_all split_conv apply(rule_tac[!] *)
  1.1205 -      proof- case goal1 thus ?case apply- apply(rule tagged_division_split_left_inj [OF p(1), of a b aa ba]) by auto
  1.1206 -      next case   goal2 thus ?case apply- apply(rule tagged_division_split_right_inj[OF p(1), of a b aa ba]) by auto
  1.1207 +      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
  1.1208 +      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
  1.1209        qed also note setsum_addf[THEN sym]
  1.1210 -      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
  1.1211 +      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
  1.1212          = (\<lambda>(x,ka). content ka *\<^sub>R f x) x" unfolding split_paired_all split_conv
  1.1213        proof- fix a b assume "(a,b) \<in> p" from p(6)[OF this] guess u v apply-by(erule exE)+ note uv=this
  1.1214 -        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"
  1.1215 -          unfolding scaleR_left_distrib[THEN sym] unfolding uv content_split[of u v k c] by auto
  1.1216 +        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"
  1.1217 +          unfolding scaleR_left_distrib[THEN sym] unfolding uv content_split[OF k,of u v c] by auto
  1.1218        qed note setsum_cong2[OF this]
  1.1219 -      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 +
  1.1220 -        ((\<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) =
  1.1221 +      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 +
  1.1222 +        ((\<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) =
  1.1223          (\<Sum>(x, ka)\<in>p. content ka *\<^sub>R f x) - (i + j)" by auto }
  1.1224      finally show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - (i + j)) < e" by auto qed qed
  1.1225  
  1.1226 +(*lemma has_integral_split_cart: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  1.1227 +  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})"
  1.1228 +  shows "(f has_integral (i + j)) ({a..b})" *)
  1.1229 +
  1.1230  subsection {* A sort of converse, integrability on subintervals. *}
  1.1231  
  1.1232 -lemma tagged_division_union_interval:
  1.1233 -  assumes "p1 tagged_division_of ({a..b} \<inter> {x::real^'n. x$k \<le> (c::real)})"  "p2 tagged_division_of ({a..b} \<inter> {x. x$k \<ge> c})"
  1.1234 +lemma tagged_division_union_interval: fixes a::"'a::ordered_euclidean_space"
  1.1235 +  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})"
  1.1236 +  and k:"k<DIM('a)"
  1.1237    shows "(p1 \<union> p2) tagged_division_of ({a..b})"
  1.1238 -proof- have *:"{a..b} = ({a..b} \<inter> {x. x$k \<le> c}) \<union> ({a..b} \<inter> {x. x$k \<ge> c})" by auto
  1.1239 -  show ?thesis apply(subst *) apply(rule tagged_division_union[OF assms])
  1.1240 -    unfolding interval_split interior_closed_interval
  1.1241 -    by(auto simp add: vector_less_def elim!:allE[where x=k]) qed
  1.1242 -
  1.1243 -lemma has_integral_separate_sides: fixes f::"real^'m \<Rightarrow> 'a::real_normed_vector"
  1.1244 -  assumes "(f has_integral i) ({a..b})" "e>0"
  1.1245 -  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>
  1.1246 -                                p2 tagged_division_of ({a..b} \<inter> {x. x$k \<ge> c}) \<and> d fine p2
  1.1247 +proof- have *:"{a..b} = ({a..b} \<inter> {x. x$$k \<le> c}) \<union> ({a..b} \<inter> {x. x$$k \<ge> c})" by auto
  1.1248 +  show ?thesis apply(subst *) apply(rule tagged_division_union[OF assms(1-2)])
  1.1249 +    unfolding interval_split[OF k] interior_closed_interval using k
  1.1250 +    by(auto simp add: eucl_less[where 'a='a] elim!:allE[where x=k]) qed
  1.1251 +
  1.1252 +lemma has_integral_separate_sides: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector"
  1.1253 +  assumes "(f has_integral i) ({a..b})" "e>0" and k:"k<DIM('a)"
  1.1254 +  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>
  1.1255 +                                p2 tagged_division_of ({a..b} \<inter> {x. x$$k \<ge> c}) \<and> d fine p2
  1.1256                                  \<longrightarrow> norm((setsum (\<lambda>(x,k). content k *\<^sub>R f x) p1 +
  1.1257                                            setsum (\<lambda>(x,k). content k *\<^sub>R f x) p2) - i) < e)"
  1.1258 -proof- guess d using has_integralD[OF assms] . note d=this
  1.1259 +proof- guess d using has_integralD[OF assms(1-2)] . note d=this
  1.1260    show ?thesis apply(rule that[of d]) apply(rule d) apply(rule,rule,rule,(erule conjE)+)
  1.1261 -  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
  1.1262 -                   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
  1.1263 +  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
  1.1264 +                   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
  1.1265      note tagged_division_union_interval[OF p1(7) p2(7)] note p12 = tagged_division_ofD[OF this] this
  1.1266      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)"
  1.1267        apply(subst setsum_Un_zero) apply(rule p1 p2)+ apply(rule) unfolding split_paired_all split_conv
  1.1268      proof- fix a b assume ab:"(a,b) \<in> p1 \<inter> p2"
  1.1269        have "(a,b) \<in> p1" using ab by auto from p1(4)[OF this] guess u v apply-by(erule exE)+ note uv =this
  1.1270 -      have "b \<subseteq> {x. x$k = c}" using ab p1(3)[of a b] p2(3)[of a b] by fastsimp
  1.1271 -      moreover have "interior {x. x $ k = c} = {}" 
  1.1272 -      proof(rule ccontr) case goal1 then obtain x where x:"x\<in>interior {x. x$k = c}" by auto
  1.1273 +      have "b \<subseteq> {x. x$$k = c}" using ab p1(3)[of a b] p2(3)[of a b] by fastsimp
  1.1274 +      moreover have "interior {x::'a. x $$ k = c} = {}" 
  1.1275 +      proof(rule ccontr) case goal1 then obtain x where x:"x\<in>interior {x::'a. x$$k = c}" by auto
  1.1276          then guess e unfolding mem_interior .. note e=this
  1.1277 -        have x:"x$k = c" using x interior_subset by fastsimp
  1.1278 -        have *:"\<And>i. \<bar>(x - (x + (\<chi> i. if i = k then e / 2 else 0))) $ i\<bar> = (if i = k then e/2 else 0)" using e by auto
  1.1279 -        have "x + (\<chi> i. if i = k then e/2 else 0) \<in> ball x e" unfolding mem_ball dist_norm 
  1.1280 -          apply(rule le_less_trans[OF norm_le_l1]) unfolding * 
  1.1281 -          unfolding setsum_delta[OF finite_UNIV] using e by auto 
  1.1282 -        hence "x + (\<chi> i. if i = k then e/2 else 0) \<in> {x. x$k = c}" using e by auto
  1.1283 -        thus False unfolding mem_Collect_eq using e x by auto
  1.1284 +        have x:"x$$k = c" using x interior_subset by fastsimp
  1.1285 +        have *:"\<And>i. i<DIM('a) \<Longrightarrow> \<bar>(x - (x + (\<chi>\<chi> i. if i = k then e / 2 else 0))) $$ i\<bar>
  1.1286 +          = (if i = k then e/2 else 0)" using e by auto
  1.1287 +        have "(\<Sum>i<DIM('a). \<bar>(x - (x + (\<chi>\<chi> i. if i = k then e / 2 else 0))) $$ i\<bar>) =
  1.1288 +          (\<Sum>i<DIM('a). (if i = k then e / 2 else 0))" apply(rule setsum_cong2) apply(subst *) by auto
  1.1289 +        also have "... < e" apply(subst setsum_delta) using e by auto 
  1.1290 +        finally have "x + (\<chi>\<chi> i. if i = k then e/2 else 0) \<in> ball x e" unfolding mem_ball dist_norm
  1.1291 +          by(rule le_less_trans[OF norm_le_l1])
  1.1292 +        hence "x + (\<chi>\<chi> i. if i = k then e/2 else 0) \<in> {x. x$$k = c}" using e by auto
  1.1293 +        thus False unfolding mem_Collect_eq using e x k by auto
  1.1294        qed ultimately have "content b = 0" unfolding uv content_eq_0_interior apply-apply(drule subset_interior) by auto
  1.1295        thus "content b *\<^sub>R f a = 0" by auto
  1.1296      qed auto
  1.1297 -    also have "\<dots> < e" by(rule d(2) p12 fine_union p1 p2)+
  1.1298 +    also have "\<dots> < e" by(rule k d(2) p12 fine_union p1 p2)+
  1.1299      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
  1.1300  
  1.1301 -lemma integrable_split[intro]: fixes f::"real^'n \<Rightarrow> 'a::{real_normed_vector,complete_space}" assumes "f integrable_on {a..b}"
  1.1302 -  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) 
  1.1303 -proof- guess y using assms unfolding integrable_on_def .. note y=this
  1.1304 -  def b' \<equiv> "(\<chi> i. if i = k then min (b$k) c else b$i)::real^'n"
  1.1305 -  and a' \<equiv> "(\<chi> i. if i = k then max (a$k) c else a$i)::real^'n"
  1.1306 -  show ?t1 ?t2 unfolding interval_split integrable_cauchy unfolding interval_split[THEN sym]
  1.1307 +lemma integrable_split[intro]: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::{real_normed_vector,complete_space}"
  1.1308 +  assumes "f integrable_on {a..b}" and k:"k<DIM('a)"
  1.1309 +  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) 
  1.1310 +proof- guess y using assms(1) unfolding integrable_on_def .. note y=this
  1.1311 +  def b' \<equiv> "(\<chi>\<chi> i. if i = k then min (b$$k) c else b$$i)::'a"
  1.1312 +  and a' \<equiv> "(\<chi>\<chi> i. if i = k then max (a$$k) c else a$$i)::'a"
  1.1313 +  show ?t1 ?t2 unfolding interval_split[OF k] integrable_cauchy unfolding interval_split[THEN sym,OF k]
  1.1314    proof(rule_tac[!] allI impI)+ fix e::real assume "e>0" hence "e/2>0" by auto
  1.1315 -    from has_integral_separate_sides[OF y this,of k c] guess d . note d=this[rule_format]
  1.1316 -    let ?P = "\<lambda>A. \<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of {a..b} \<inter> A \<and> d fine p1 \<and> p2 tagged_division_of {a..b} \<inter> A \<and> d fine p2 \<longrightarrow>
  1.1317 -                              norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e)"
  1.1318 -    show "?P {x. x $ k \<le> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  1.1319 -    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x $ k \<le> c} \<and> d fine p1 \<and> p2 tagged_division_of {a..b} \<inter> {x. x $ k \<le> c} \<and> d fine p2"
  1.1320 +    from has_integral_separate_sides[OF y this k,of c] guess d . note d=this[rule_format]
  1.1321 +    let ?P = "\<lambda>A. \<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of {a..b} \<inter> A \<and> d fine p1
  1.1322 +      \<and> p2 tagged_division_of {a..b} \<inter> A \<and> d fine p2 \<longrightarrow>
  1.1323 +      norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e)"
  1.1324 +    show "?P {x. x $$ k \<le> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  1.1325 +    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x $$ k \<le> c} \<and> d fine p1
  1.1326 +        \<and> p2 tagged_division_of {a..b} \<inter> {x. x $$ k \<le> c} \<and> d fine p2"
  1.1327        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"
  1.1328        proof- guess p using fine_division_exists[OF d(1), of a' b] . note p=this
  1.1329          show ?thesis using norm_triangle_half_l[OF d(2)[of p1 p] d(2)[of p2 p]]
  1.1330 -          using as unfolding interval_split b'_def[symmetric] a'_def[symmetric]
  1.1331 +          using as unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
  1.1332            using p using assms by(auto simp add:algebra_simps)
  1.1333        qed qed  
  1.1334 -    show "?P {x. x $ k \<ge> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  1.1335 -    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x $ k \<ge> c} \<and> d fine p1 \<and> p2 tagged_division_of {a..b} \<inter> {x. x $ k \<ge> c} \<and> d fine p2"
  1.1336 +    show "?P {x. x $$ k \<ge> c}" apply(rule_tac x=d in exI) apply(rule,rule d) apply(rule,rule,rule)
  1.1337 +    proof- fix p1 p2 assume as:"p1 tagged_division_of {a..b} \<inter> {x. x $$ k \<ge> c} \<and> d fine p1
  1.1338 +        \<and> p2 tagged_division_of {a..b} \<inter> {x. x $$ k \<ge> c} \<and> d fine p2"
  1.1339        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"
  1.1340        proof- guess p using fine_division_exists[OF d(1), of a b'] . note p=this
  1.1341          show ?thesis using norm_triangle_half_l[OF d(2)[of p p1] d(2)[of p p2]]
  1.1342 -          using as unfolding interval_split b'_def[symmetric] a'_def[symmetric]
  1.1343 +          using as unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
  1.1344            using p using assms by(auto simp add:algebra_simps) qed qed qed qed
  1.1345  
  1.1346  subsection {* Generalized notion of additivity. *}
  1.1347  
  1.1348  definition "neutral opp = (SOME x. \<forall>y. opp x y = y \<and> opp y x = y)"
  1.1349  
  1.1350 -definition operative :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> ((real^'n) set \<Rightarrow> 'a) \<Rightarrow> bool" where
  1.1351 +definition operative :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> (('b::ordered_euclidean_space) set \<Rightarrow> 'a) \<Rightarrow> bool" where
  1.1352    "operative opp f \<equiv> 
  1.1353      (\<forall>a b. content {a..b} = 0 \<longrightarrow> f {a..b} = neutral(opp)) \<and>
  1.1354 -    (\<forall>a b c k. f({a..b}) =
  1.1355 -                   opp (f({a..b} \<inter> {x. x$k \<le> c}))
  1.1356 -                       (f({a..b} \<inter> {x. x$k \<ge> c})))"
  1.1357 -
  1.1358 -lemma operativeD[dest]: assumes "operative opp f"
  1.1359 -  shows "\<And>a b. content {a..b} = 0 \<Longrightarrow> f {a..b} = neutral(opp)"
  1.1360 -  "\<And>a b c k. f({a..b}) = opp (f({a..b} \<inter> {x. x$k \<le> c})) (f({a..b} \<inter> {x. x$k \<ge> c}))"
  1.1361 +    (\<forall>a b c. \<forall>k<DIM('b). f({a..b}) =
  1.1362 +                   opp (f({a..b} \<inter> {x. x$$k \<le> c}))
  1.1363 +                       (f({a..b} \<inter> {x. x$$k \<ge> c})))"
  1.1364 +
  1.1365 +lemma operativeD[dest]: fixes type::"'a::ordered_euclidean_space"  assumes "operative opp f"
  1.1366 +  shows "\<And>a b. content {a..b} = 0 \<Longrightarrow> f {a..b::'a} = neutral(opp)"
  1.1367 +  "\<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}))"
  1.1368    using assms unfolding operative_def by auto
  1.1369  
  1.1370  lemma operative_trivial:
  1.1371 @@ -1835,15 +1865,15 @@
  1.1372  proof(induct s) case empty thus ?case using assms by auto
  1.1373  next case (insert x F) show ?case apply(subst iterate_insert) prefer 3 apply(subst if_not_P)
  1.1374      defer unfolding insert(3) lifted.simps apply rule using assms insert by auto qed
  1.1375 -
  1.1376  subsection {* Two key instances of additivity. *}
  1.1377  
  1.1378  lemma neutral_add[simp]:
  1.1379    "neutral op + = (0::_::comm_monoid_add)" unfolding neutral_def 
  1.1380    apply(rule some_equality) defer apply(erule_tac x=0 in allE) by auto
  1.1381  
  1.1382 -lemma operative_content[intro]: "operative (op +) content"
  1.1383 -  unfolding operative_def content_split[THEN sym] neutral_add by auto
  1.1384 +lemma operative_content[intro]: "operative (op +) content" 
  1.1385 +  unfolding operative_def neutral_add apply safe 
  1.1386 +  unfolding content_split[THEN sym] ..
  1.1387  
  1.1388  lemma neutral_monoid: "neutral ((op +)::('a::comm_monoid_add) \<Rightarrow> 'a \<Rightarrow> 'a) = 0"
  1.1389    by (rule neutral_add) (* FIXME: duplicate *)
  1.1390 @@ -1852,110 +1882,119 @@
  1.1391    shows "monoidal ((op +)::('a::comm_monoid_add) \<Rightarrow> 'a \<Rightarrow> 'a)"
  1.1392    unfolding monoidal_def neutral_monoid by(auto simp add: algebra_simps) 
  1.1393  
  1.1394 -lemma operative_integral: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.1395 +lemma operative_integral: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  1.1396    shows "operative (lifted(op +)) (\<lambda>i. if f integrable_on i then Some(integral i f) else None)"
  1.1397    unfolding operative_def unfolding neutral_lifted[OF monoidal_monoid] neutral_add
  1.1398 -  apply(rule,rule,rule,rule) defer apply(rule allI)+
  1.1399 -proof- fix a b c k show "(if f integrable_on {a..b} then Some (integral {a..b} f) else None) =
  1.1400 -              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)
  1.1401 -               (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)"
  1.1402 +  apply(rule,rule,rule,rule) defer apply(rule allI impI)+
  1.1403 +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) =
  1.1404 +    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)
  1.1405 +    (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)"
  1.1406    proof(cases "f integrable_on {a..b}") 
  1.1407 -    case True show ?thesis unfolding if_P[OF True]
  1.1408 -      unfolding if_P[OF integrable_split(1)[OF True]] if_P[OF integrable_split(2)[OF True]]
  1.1409 -      unfolding lifted.simps option.inject apply(rule integral_unique) apply(rule has_integral_split) 
  1.1410 -      apply(rule_tac[!] integrable_integral integrable_split)+ using True by assumption+
  1.1411 -  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}))"
  1.1412 +    case True show ?thesis unfolding if_P[OF True] using k apply-
  1.1413 +      unfolding if_P[OF integrable_split(1)[OF True]] unfolding if_P[OF integrable_split(2)[OF True]]
  1.1414 +      unfolding lifted.simps option.inject apply(rule integral_unique) apply(rule has_integral_split[OF _ _ k]) 
  1.1415 +      apply(rule_tac[!] integrable_integral integrable_split)+ using True k by auto
  1.1416 +  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}))"
  1.1417      proof(rule ccontr) case goal1 hence "f integrable_on {a..b}" apply- unfolding integrable_on_def
  1.1418 -        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)
  1.1419 -        apply(rule has_integral_split) apply(rule_tac[!] integrable_integral) by auto
  1.1420 +        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)
  1.1421 +        apply(rule has_integral_split[OF _ _ k]) apply(rule_tac[!] integrable_integral) by auto
  1.1422        thus False using False by auto
  1.1423      qed thus ?thesis using False by auto 
  1.1424    qed next 
  1.1425 -  fix a b assume as:"content {a..b::real^'n} = 0"
  1.1426 +  fix a b assume as:"content {a..b::'a} = 0"
  1.1427    thus "(if f integrable_on {a..b} then Some (integral {a..b} f) else None) = Some 0"
  1.1428      unfolding if_P[OF integrable_on_null[OF as]] using has_integral_null_eq[OF as] by auto qed
  1.1429  
  1.1430  subsection {* Points of division of a partition. *}
  1.1431  
  1.1432 -definition "division_points (k::(real^'n) set) d = 
  1.1433 -    {(j,x). (interval_lowerbound k)$j < x \<and> x < (interval_upperbound k)$j \<and>
  1.1434 -           (\<exists>i\<in>d. (interval_lowerbound i)$j = x \<or> (interval_upperbound i)$j = x)}"
  1.1435 -
  1.1436 -lemma division_points_finite: assumes "d division_of i"
  1.1437 -  shows "finite (division_points i d)"
  1.1438 +definition "division_points (k::('a::ordered_euclidean_space) set) d = 
  1.1439 +    {(j,x). j<DIM('a) \<and> (interval_lowerbound k)$$j < x \<and> x < (interval_upperbound k)$$j \<and>
  1.1440 +           (\<exists>i\<in>d. (interval_lowerbound i)$$j = x \<or> (interval_upperbound i)$$j = x)}"
  1.1441 +
  1.1442 +lemma division_points_finite: fixes i::"('a::ordered_euclidean_space) set"
  1.1443 +  assumes "d division_of i" shows "finite (division_points i d)"
  1.1444  proof- note assm = division_ofD[OF assms]
  1.1445 -  let ?M = "\<lambda>j. {(j,x)|x. (interval_lowerbound i)$j < x \<and> x < (interval_upperbound i)$j \<and>
  1.1446 -           (\<exists>i\<in>d. (interval_lowerbound i)$j = x \<or> (interval_upperbound i)$j = x)}"
  1.1447 -  have *:"division_points i d = \<Union>(?M ` UNIV)"
  1.1448 +  let ?M = "\<lambda>j. {(j,x)|x. (interval_lowerbound i)$$j < x \<and> x < (interval_upperbound i)$$j \<and>
  1.1449 +           (\<exists>i\<in>d. (interval_lowerbound i)$$j = x \<or> (interval_upperbound i)$$j = x)}"
  1.1450 +  have *:"division_points i d = \<Union>(?M ` {..<DIM('a)})"
  1.1451      unfolding division_points_def by auto
  1.1452    show ?thesis unfolding * using assm by auto qed
  1.1453  
  1.1454 -lemma division_points_subset:
  1.1455 -  assumes "d division_of {a..b}" "\<forall>i. a$i < b$i"  "a$k < c" "c < b$k"
  1.1456 -  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} = {})}
  1.1457 +lemma division_points_subset: fixes a::"'a::ordered_euclidean_space"
  1.1458 +  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)"
  1.1459 +  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} = {})}
  1.1460                    \<subseteq> division_points ({a..b}) d" (is ?t1) and
  1.1461 -        "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} = {})}
  1.1462 +        "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} = {})}
  1.1463                    \<subseteq> division_points ({a..b}) d" (is ?t2)
  1.1464  proof- note assm = division_ofD[OF assms(1)]
  1.1465 -  have *:"\<forall>i. a$i \<le> b$i"   "\<forall>i. a$i \<le> (\<chi> i. if i = k then min (b $ k) c else b $ i) $ i"
  1.1466 -    "\<forall>i. (\<chi> i. if i = k then max (a $ k) c else a $ i) $ i \<le> b$i"  "min (b $ k) c = c" "max (a $ k) c = c"
  1.1467 +  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"
  1.1468 +    "\<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"
  1.1469      using assms using less_imp_le by auto
  1.1470 -  show ?t1 unfolding division_points_def interval_split[of a b]
  1.1471 -    unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)] Cart_lambda_beta unfolding *
  1.1472 -    unfolding subset_eq apply(rule) unfolding mem_Collect_eq split_beta apply(erule bexE conjE)+ unfolding mem_Collect_eq apply(erule exE conjE)+
  1.1473 -  proof- fix i l x assume as:"a $ fst x < snd x" "snd x < (if fst x = k then c else b $ fst x)"
  1.1474 -      "interval_lowerbound i $ fst x = snd x \<or> interval_upperbound i $ fst x = snd x"  "i = l \<inter> {x. x $ k \<le> c}" "l \<in> d" "l \<inter> {x. x $ k \<le> c} \<noteq> {}"
  1.1475 +  show ?t1 unfolding division_points_def interval_split[OF k, of a b]
  1.1476 +    unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)] unfolding *
  1.1477 +    unfolding subset_eq apply(rule) unfolding mem_Collect_eq split_beta apply(erule bexE conjE)+
  1.1478 +    unfolding mem_Collect_eq apply(erule exE conjE)+ unfolding euclidean_lambda_beta'
  1.1479 +  proof- fix i l x assume as:"a $$ fst x < snd x" "snd x < (if fst x = k then c else b $$ fst x)"
  1.1480 +      "interval_lowerbound i $$ fst x = snd x \<or> interval_upperbound i $$ fst x = snd x"
  1.1481 +      "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)"
  1.1482      from assm(4)[OF this(5)] guess u v apply-by(erule exE)+ note l=this
  1.1483 -    have *:"\<forall>i. u $ i \<le> (\<chi> i. if i = k then min (v $ k) c else v $ i) $ i" using as(6) unfolding l interval_split interval_ne_empty as .
  1.1484 -    have **:"\<forall>i. u$i \<le> v$i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
  1.1485 -    show "a $ fst x < snd x \<and> snd x < b $ fst x \<and> (\<exists>i\<in>d. interval_lowerbound i $ fst x = snd x \<or> interval_upperbound i $ fst x = snd x)"
  1.1486 -      using as(1-3,5) unfolding l interval_split interval_ne_empty as interval_bounds[OF *] Cart_lambda_beta apply-
  1.1487 +    have *:"\<forall>i<DIM('a). u $$ i \<le> ((\<chi>\<chi> i. if i = k then min (v $$ k) c else v $$ i)::'a) $$ i"
  1.1488 +      using as(6) unfolding l interval_split[OF k] interval_ne_empty as .
  1.1489 +    have **:"\<forall>i<DIM('a). u$$i \<le> v$$i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
  1.1490 +    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
  1.1491 +      \<or> interval_upperbound i $$ fst x = snd x)" apply(rule,rule fstx)
  1.1492 +      using as(1-3,5) unfolding l interval_split[OF k] interval_ne_empty as interval_bounds[OF *] apply-
  1.1493        apply(rule,assumption,rule) defer apply(rule_tac x="{u..v}" in bexI) unfolding interval_bounds[OF **]
  1.1494 -      apply(case_tac[!] "fst x = k") using assms by auto
  1.1495 +      apply(case_tac[!] "fst x = k") using assms fstx apply- unfolding euclidean_lambda_beta by auto
  1.1496    qed
  1.1497 -  show ?t2 unfolding division_points_def interval_split[of a b]
  1.1498 -    unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)] Cart_lambda_beta unfolding *
  1.1499 -    unfolding subset_eq apply(rule) unfolding mem_Collect_eq split_beta apply(erule bexE conjE)+ unfolding mem_Collect_eq apply(erule exE conjE)+
  1.1500 -  proof- fix i l x assume as:"(if fst x = k then c else a $ fst x) < snd x" "snd x < b $ fst x" "interval_lowerbound i $ fst x = snd x \<or> interval_upperbound i $ fst x = snd x"
  1.1501 -      "i = l \<inter> {x. c \<le> x $ k}" "l \<in> d" "l \<inter> {x. c \<le> x $ k} \<noteq> {}"
  1.1502 +  show ?t2 unfolding division_points_def interval_split[OF k, of a b]
  1.1503 +    unfolding interval_bounds[OF *(1)] interval_bounds[OF *(2)] interval_bounds[OF *(3)] unfolding *
  1.1504 +    unfolding subset_eq apply(rule) unfolding mem_Collect_eq split_beta apply(erule bexE conjE)+
  1.1505 +    unfolding mem_Collect_eq apply(erule exE conjE)+ unfolding euclidean_lambda_beta' apply(rule,assumption)
  1.1506 +  proof- fix i l x assume as:"(if fst x = k then c else a $$ fst x) < snd x" "snd x < b $$ fst x"
  1.1507 +      "interval_lowerbound i $$ fst x = snd x \<or> interval_upperbound i $$ fst x = snd x" 
  1.1508 +      "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)"
  1.1509      from assm(4)[OF this(5)] guess u v apply-by(erule exE)+ note l=this
  1.1510 -    have *:"\<forall>i. (\<chi> i. if i = k then max (u $ k) c else u $ i) $ i \<le> v $ i" using as(6) unfolding l interval_split interval_ne_empty as .
  1.1511 -    have **:"\<forall>i. u$i \<le> v$i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
  1.1512 -    show "a $ fst x < snd x \<and> snd x < b $ fst x \<and> (\<exists>i\<in>d. interval_lowerbound i $ fst x = snd x \<or> interval_upperbound i $ fst x = snd x)"
  1.1513 -      using as(1-3,5) unfolding l interval_split interval_ne_empty as interval_bounds[OF *] Cart_lambda_beta apply-
  1.1514 +    have *:"\<forall>i<DIM('a). ((\<chi>\<chi> i. if i = k then max (u $$ k) c else u $$ i)::'a) $$ i \<le> v $$ i"
  1.1515 +      using as(6) unfolding l interval_split[OF k] interval_ne_empty as .
  1.1516 +    have **:"\<forall>i<DIM('a). u$$i \<le> v$$i" using l using as(6) unfolding interval_ne_empty[THEN sym] by auto
  1.1517 +    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>
  1.1518 +      interval_upperbound i $$ fst x = snd x)"
  1.1519 +      using as(1-3,5) unfolding l interval_split[OF k] interval_ne_empty as interval_bounds[OF *] apply-
  1.1520        apply rule defer apply(rule,assumption) apply(rule_tac x="{u..v}" in bexI) unfolding interval_bounds[OF **]
  1.1521 -      apply(case_tac[!] "fst x = k") using assms by auto qed qed
  1.1522 -
  1.1523 -lemma division_points_psubset:
  1.1524 -  assumes "d division_of {a..b}"  "\<forall>i. a$i < b$i"  "a$k < c" "c < b$k"
  1.1525 -  "l \<in> d" "interval_lowerbound l$k = c \<or> interval_upperbound l$k = c"
  1.1526 -  shows "division_points ({a..b} \<inter> {x. x$k \<le> c}) {l \<inter> {x. x$k \<le> c} | l. l\<in>d \<and> l \<inter> {x. x$k \<le> c} \<noteq> {}} \<subset> division_points ({a..b}) d" (is "?D1 \<subset> ?D") 
  1.1527 -        "division_points ({a..b} \<inter> {x. x$k \<ge> c}) {l \<inter> {x. x$k \<ge> c} | l. l\<in>d \<and> l \<inter> {x. x$k \<ge> c} \<noteq> {}} \<subset> division_points ({a..b}) d" (is "?D2 \<subset> ?D") 
  1.1528 -proof- have ab:"\<forall>i. a$i \<le> b$i" using assms(2) by(auto intro!:less_imp_le)
  1.1529 +      apply(case_tac[!] "fst x = k") using assms fstx apply-  by(auto simp add:euclidean_lambda_beta'[OF k]) qed qed
  1.1530 +
  1.1531 +lemma division_points_psubset: fixes a::"'a::ordered_euclidean_space"
  1.1532 +  assumes "d division_of {a..b}"  "\<forall>i<DIM('a). a$$i < b$$i"  "a$$k < c" "c < b$$k"
  1.1533 +  "l \<in> d" "interval_lowerbound l$$k = c \<or> interval_upperbound l$$k = c" and k:"k<DIM('a)"
  1.1534 +  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> {}}
  1.1535 +              \<subset> division_points ({a..b}) d" (is "?D1 \<subset> ?D") 
  1.1536 +        "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> {}}
  1.1537 +              \<subset> division_points ({a..b}) d" (is "?D2 \<subset> ?D") 
  1.1538 +proof- have ab:"\<forall>i<DIM('a). a$$i \<le> b$$i" using assms(2) by(auto intro!:less_imp_le)
  1.1539    guess u v using division_ofD(4)[OF assms(1,5)] apply-by(erule exE)+ note l=this
  1.1540 -  have uv:"\<forall>i. u$i \<le> v$i" "\<forall>i. a$i \<le> u$i \<and> v$i \<le> b$i" using division_ofD(2,2,3)[OF assms(1,5)] unfolding l interval_ne_empty
  1.1541 +  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"
  1.1542 +    using division_ofD(2,2,3)[OF assms(1,5)] unfolding l interval_ne_empty
  1.1543      unfolding subset_eq apply- defer apply(erule_tac x=u in ballE, erule_tac x=v in ballE) unfolding mem_interval by auto
  1.1544 -  have *:"interval_upperbound ({a..b} \<inter> {x. x $ k \<le> interval_upperbound l $ k}) $ k = interval_upperbound l $ k"
  1.1545 -         "interval_upperbound ({a..b} \<inter> {x. x $ k \<le> interval_lowerbound l $ k}) $ k = interval_lowerbound l $ k"
  1.1546 -    unfolding interval_split apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  1.1547 -    unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab by auto
  1.1548 +  have *:"interval_upperbound ({a..b} \<inter> {x. x $$ k \<le> interval_upperbound l $$ k}) $$ k = interval_upperbound l $$ k"
  1.1549 +         "interval_upperbound ({a..b} \<inter> {x. x $$ k \<le> interval_lowerbound l $$ k}) $$ k = interval_lowerbound l $$ k"
  1.1550 +    unfolding interval_split[OF k] apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  1.1551 +    unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab k by auto
  1.1552    have "\<exists>x. x \<in> ?D - ?D1" using assms(2-) apply-apply(erule disjE)
  1.1553 -    apply(rule_tac x="(k,(interval_lowerbound l)$k)" in exI) defer
  1.1554 -    apply(rule_tac x="(k,(interval_upperbound l)$k)" in exI)
  1.1555 -    unfolding division_points_def unfolding interval_bounds[OF ab]
  1.1556 -    apply auto unfolding * by auto
  1.1557 -  thus "?D1 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4)]) by auto
  1.1558 -
  1.1559 -  have *:"interval_lowerbound ({a..b} \<inter> {x. x $ k \<ge> interval_lowerbound l $ k}) $ k = interval_lowerbound l $ k"
  1.1560 -         "interval_lowerbound ({a..b} \<inter> {x. x $ k \<ge> interval_upperbound l $ k}) $ k = interval_upperbound l $ k"
  1.1561 -    unfolding interval_split apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  1.1562 -    unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab by auto
  1.1563 +    apply(rule_tac x="(k,(interval_lowerbound l)$$k)" in exI) defer
  1.1564 +    apply(rule_tac x="(k,(interval_upperbound l)$$k)" in exI)
  1.1565 +    unfolding division_points_def unfolding interval_bounds[OF ab] by(auto simp add:*) 
  1.1566 +  thus "?D1 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4)]) using k by auto
  1.1567 +
  1.1568 +  have *:"interval_lowerbound ({a..b} \<inter> {x. x $$ k \<ge> interval_lowerbound l $$ k}) $$ k = interval_lowerbound l $$ k"
  1.1569 +         "interval_lowerbound ({a..b} \<inter> {x. x $$ k \<ge> interval_upperbound l $$ k}) $$ k = interval_upperbound l $$ k"
  1.1570 +    unfolding interval_split[OF k] apply(subst interval_bounds) prefer 3 apply(subst interval_bounds)
  1.1571 +    unfolding l interval_bounds[OF uv(1)] using uv[rule_format,of k] ab k by auto
  1.1572    have "\<exists>x. x \<in> ?D - ?D2" using assms(2-) apply-apply(erule disjE)
  1.1573 -    apply(rule_tac x="(k,(interval_lowerbound l)$k)" in exI) defer
  1.1574 -    apply(rule_tac x="(k,(interval_upperbound l)$k)" in exI)
  1.1575 -    unfolding division_points_def unfolding interval_bounds[OF ab]
  1.1576 -    apply auto unfolding * by auto
  1.1577 -  thus "?D2 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4)]) by auto qed
  1.1578 +    apply(rule_tac x="(k,(interval_lowerbound l)$$k)" in exI) defer
  1.1579 +    apply(rule_tac x="(k,(interval_upperbound l)$$k)" in exI)
  1.1580 +    unfolding division_points_def unfolding interval_bounds[OF ab] by(auto simp add:*) 
  1.1581 +  thus "?D2 \<subset> ?D" apply-apply(rule,rule division_points_subset[OF assms(1-4) k]) by auto qed
  1.1582  
  1.1583  subsection {* Preservation by divisions and tagged divisions. *}
  1.1584  
  1.1585 @@ -2036,7 +2075,7 @@
  1.1586  
  1.1587  lemma nonempty_witness: assumes "s \<noteq> {}" obtains x where "x \<in> s" using assms by auto
  1.1588  
  1.1589 -lemma operative_division: fixes f::"(real^'n) set \<Rightarrow> 'a"
  1.1590 +lemma operative_division: fixes f::"('a::ordered_euclidean_space) set \<Rightarrow> 'b"
  1.1591    assumes "monoidal opp" "operative opp f" "d division_of {a..b}"
  1.1592    shows "iterate opp d f = f {a..b}"
  1.1593  proof- def C \<equiv> "card (division_points {a..b} d)" thus ?thesis using assms
  1.1594 @@ -2052,82 +2091,82 @@
  1.1595              using operativeD(1)[OF assms(2)] x by auto
  1.1596          qed qed }
  1.1597      assume "content {a..b} \<noteq> 0" note ab = this[unfolded content_lt_nz[THEN sym] content_pos_lt_eq]
  1.1598 -    hence ab':"\<forall>i. a$i \<le> b$i" by (auto intro!: less_imp_le) show ?case 
  1.1599 +    hence ab':"\<forall>i<DIM('a). a$$i \<le> b$$i" by (auto intro!: less_imp_le) show ?case 
  1.1600      proof(cases "division_points {a..b} d = {}")
  1.1601        case True have d':"\<forall>i\<in>d. \<exists>u v. i = {u..v} \<and>
  1.1602 -        (\<forall>j. u$j = a$j \<and> v$j = a$j \<or> u$j = b$j \<and> v$j = b$j \<or> u$j = a$j \<and> v$j = b$j)"
  1.1603 +        (\<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)"
  1.1604          unfolding forall_in_division[OF goal1(4)] apply(rule,rule,rule)
  1.1605 -        apply(rule_tac x=a in exI,rule_tac x=b in exI) apply(rule,rule refl) apply(rule)
  1.1606 -      proof- fix u v j assume as:"{u..v} \<in> d" note division_ofD(3)[OF goal1(4) this]
  1.1607 -        hence uv:"\<forall>i. u$i \<le> v$i" "u$j \<le> v$j" unfolding interval_ne_empty by auto
  1.1608 -        have *:"\<And>p r Q. p \<or> r \<or> (\<forall>x\<in>d. Q x) \<Longrightarrow> p \<or> r \<or> (Q {u..v})" using as by auto
  1.1609 -        have "(j, u$j) \<notin> division_points {a..b} d"
  1.1610 -          "(j, v$j) \<notin> division_points {a..b} d" using True by auto
  1.1611 +        apply(rule_tac x=a in exI,rule_tac x=b in exI) apply(rule,rule refl) apply(rule,rule)
  1.1612 +      proof- fix u v j assume j:"j<DIM('a)" assume as:"{u..v} \<in> d" note division_ofD(3)[OF goal1(4) this]
  1.1613 +        hence uv:"\<forall>i<DIM('a). u$$i \<le> v$$i" "u$$j \<le> v$$j" using j unfolding interval_ne_empty by auto
  1.1614 +        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
  1.1615 +        have "(j, u$$j) \<notin> division_points {a..b} d"
  1.1616 +          "(j, v$$j) \<notin> division_points {a..b} d" using True by auto
  1.1617          note this[unfolded de_Morgan_conj division_points_def mem_Collect_eq split_conv interval_bounds[OF ab'] bex_simps]
  1.1618          note *[OF this(1)] *[OF this(2)] note this[unfolded interval_bounds[OF uv(1)]]
  1.1619 -        moreover have "a$j \<le> u$j" "v$j \<le> b$j" using division_ofD(2,2,3)[OF goal1(4) as] 
  1.1620 +        moreover have "a$$j \<le> u$$j" "v$$j \<le> b$$j" using division_ofD(2,2,3)[OF goal1(4) as] 
  1.1621            unfolding subset_eq apply- apply(erule_tac x=u in ballE,erule_tac[3] x=v in ballE)
  1.1622 -          unfolding interval_ne_empty mem_interval by auto
  1.1623 -        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"
  1.1624 -          unfolding not_less de_Morgan_disj using ab[rule_format,of j] uv(2) by auto
  1.1625 +          unfolding interval_ne_empty mem_interval using j by auto
  1.1626 +        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"
  1.1627 +          unfolding not_less de_Morgan_disj using ab[rule_format,of j] uv(2) j by auto
  1.1628        qed have "(1/2) *\<^sub>R (a+b) \<in> {a..b}" unfolding mem_interval using ab by(auto intro!:less_imp_le)
  1.1629        note this[unfolded division_ofD(6)[OF goal1(4),THEN sym] Union_iff]
  1.1630        then guess i .. note i=this guess u v using d'[rule_format,OF i(1)] apply-by(erule exE conjE)+ note uv=this
  1.1631        have "{a..b} \<in> d"
  1.1632        proof- { presume "i = {a..b}" thus ?thesis using i by auto }
  1.1633          { presume "u = a" "v = b" thus "i = {a..b}" using uv by auto }
  1.1634 -        show "u = a" "v = b" unfolding Cart_eq
  1.1635 -        proof(rule_tac[!] allI) fix j note i(2)[unfolded uv mem_interval,rule_format,of j]
  1.1636 -          thus "u $ j = a $ j" "v $ j = b $ j" using uv(2)[rule_format,of j] by auto
  1.1637 +        show "u = a" "v = b" unfolding euclidean_eq[where 'a='a]
  1.1638 +        proof(safe) fix j assume j:"j<DIM('a)" note i(2)[unfolded uv mem_interval,rule_format,of j]
  1.1639 +          thus "u $$ j = a $$ j" "v $$ j = b $$ j" using uv(2)[rule_format,of j] j by auto
  1.1640          qed qed
  1.1641        hence *:"d = insert {a..b} (d - {{a..b}})" by auto
  1.1642        have "iterate opp (d - {{a..b}}) f = neutral opp" apply(rule iterate_eq_neutral[OF goal1(2)])
  1.1643        proof fix x assume x:"x \<in> d - {{a..b}}" hence "x\<in>d" by auto note d'[rule_format,OF this]
  1.1644          then guess u v apply-by(erule exE conjE)+ note uv=this
  1.1645          have "u\<noteq>a \<or> v\<noteq>b" using x[unfolded uv] by auto  
  1.1646 -        then obtain j where "u$j \<noteq> a$j \<or> v$j \<noteq> b$j" unfolding Cart_eq by auto
  1.1647 -        hence "u$j = v$j" using uv(2)[rule_format,of j] by auto
  1.1648 -        hence "content {u..v} = 0"  unfolding content_eq_0 apply(rule_tac x=j in exI) by auto
  1.1649 +        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
  1.1650 +        hence "u$$j = v$$j" using uv(2)[rule_format,OF j] by auto
  1.1651 +        hence "content {u..v} = 0"  unfolding content_eq_0 apply(rule_tac x=j in exI) using j by auto
  1.1652          thus "f x = neutral opp" unfolding uv(1) by(rule operativeD(1)[OF goal1(3)])
  1.1653        qed thus "iterate opp d f = f {a..b}" apply-apply(subst *) 
  1.1654          apply(subst iterate_insert[OF goal1(2)]) using goal1(2,4) by auto
  1.1655      next case False hence "\<exists>x. x\<in>division_points {a..b} d" by auto
  1.1656        then guess k c unfolding split_paired_Ex apply- unfolding division_points_def mem_Collect_eq split_conv
  1.1657 -        by(erule exE conjE)+ note kc=this[unfolded interval_bounds[OF ab']]
  1.1658 +        by(erule exE conjE)+ note this(2-4,1) note kc=this[unfolded interval_bounds[OF ab']]
  1.1659        from this(3) guess j .. note j=this
  1.1660 -      def d1 \<equiv> "{l \<inter> {x. x$k \<le> c} | l. l \<in> d \<and> l \<inter> {x. x$k \<le> c} \<noteq> {}}"
  1.1661 -      def d2 \<equiv> "{l \<inter> {x. x$k \<ge> c} | l. l \<in> d \<and> l \<inter> {x. x$k \<ge> c} \<noteq> {}}"
  1.1662 -      def cb \<equiv> "(\<chi> i. if i = k then c else b$i)" and ca \<equiv> "(\<chi> i. if i = k then c else a$i)"
  1.1663 +      def d1 \<equiv> "{l \<inter> {x. x$$k \<le> c} | l. l \<in> d \<and> l \<inter> {x. x$$k \<le> c} \<noteq> {}}"
  1.1664 +      def d2 \<equiv> "{l \<inter> {x. x$$k \<ge> c} | l. l \<in> d \<and> l \<inter> {x. x$$k \<ge> c} \<noteq> {}}"
  1.1665 +      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"
  1.1666        note division_points_psubset[OF goal1(4) ab kc(1-2) j]
  1.1667        note psubset_card_mono[OF _ this(1)] psubset_card_mono[OF _ this(2)]
  1.1668 -      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})"
  1.1669 -        apply- unfolding interval_split apply(rule_tac[!] goal1(1)[rule_format])
  1.1670 +      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})"
  1.1671 +        apply- unfolding interval_split[OF kc(4)] apply(rule_tac[!] goal1(1)[rule_format])
  1.1672          using division_split[OF goal1(4), where k=k and c=c]
  1.1673 -        unfolding interval_split d1_def[symmetric] d2_def[symmetric] unfolding goal1(2) Suc_le_mono
  1.1674 -        using goal1(2-3) using division_points_finite[OF goal1(4)] by auto
  1.1675 +        unfolding interval_split[OF kc(4)] d1_def[symmetric] d2_def[symmetric] unfolding goal1(2) Suc_le_mono
  1.1676 +        using goal1(2-3) using division_points_finite[OF goal1(4)] using kc(4) by auto
  1.1677        have "f {a..b} = opp (iterate opp d1 f) (iterate opp d2 f)" (is "_ = ?prev")
  1.1678 -        unfolding * apply(rule operativeD(2)) using goal1(3) .
  1.1679 -      also have "iterate opp d1 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x$k \<le> c}))"
  1.1680 +        unfolding * apply(rule operativeD(2)) using goal1(3) using kc(4) by auto 
  1.1681 +      also have "iterate opp d1 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x$$k \<le> c}))"
  1.1682          unfolding d1_def apply(rule iterate_nonzero_image_lemma[unfolded o_def])
  1.1683          unfolding empty_as_interval apply(rule goal1 division_of_finite operativeD[OF goal1(3)])+
  1.1684          unfolding empty_as_interval[THEN sym] apply(rule content_empty)
  1.1685 -      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" 
  1.1686 +      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" 
  1.1687          from division_ofD(4)[OF goal1(4) this(1)] guess u v apply-by(erule exE)+ note l=this
  1.1688 -        show "f (l \<inter> {x. x $ k \<le> c}) = neutral opp" unfolding l interval_split
  1.1689 -          apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym] apply(rule division_split_left_inj)
  1.1690 -          apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule as)+
  1.1691 -      qed also have "iterate opp d2 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x$k \<ge> c}))"
  1.1692 +        show "f (l \<inter> {x. x $$ k \<le> c}) = neutral opp" unfolding l interval_split[OF kc(4)] 
  1.1693 +          apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym,OF kc(4)] apply(rule division_split_left_inj)
  1.1694 +          apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule kc(4) as)+
  1.1695 +      qed also have "iterate opp d2 f = iterate opp d (\<lambda>l. f(l \<inter> {x. x$$k \<ge> c}))"
  1.1696          unfolding d2_def apply(rule iterate_nonzero_image_lemma[unfolded o_def])
  1.1697          unfolding empty_as_interval apply(rule goal1 division_of_finite operativeD[OF goal1(3)])+
  1.1698          unfolding empty_as_interval[THEN sym] apply(rule content_empty)
  1.1699 -      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" 
  1.1700 +      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" 
  1.1701          from division_ofD(4)[OF goal1(4) this(1)] guess u v apply-by(erule exE)+ note l=this
  1.1702 -        show "f (l \<inter> {x. x $ k \<ge> c}) = neutral opp" unfolding l interval_split
  1.1703 -          apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym] apply(rule division_split_right_inj)
  1.1704 -          apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule as)+
  1.1705 -      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}))"
  1.1706 -        unfolding forall_in_division[OF goal1(4)] apply(rule,rule,rule,rule operativeD(2)) using goal1(3) .
  1.1707 -      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})))
  1.1708 +        show "f (l \<inter> {x. x $$ k \<ge> c}) = neutral opp" unfolding l interval_split[OF kc(4)] 
  1.1709 +          apply(rule operativeD(1) goal1)+ unfolding interval_split[THEN sym,OF kc(4)] apply(rule division_split_right_inj)
  1.1710 +          apply(rule goal1) unfolding l[THEN sym] apply(rule as(1),rule as(2)) by(rule as kc(4))+
  1.1711 +      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}))"
  1.1712 +        unfolding forall_in_division[OF goal1(4)] apply(rule,rule,rule,rule operativeD(2)) using goal1(3) kc by auto 
  1.1713 +      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})))
  1.1714          = iterate opp d f" apply(subst(3) iterate_eq[OF _ *[rule_format]]) prefer 3
  1.1715          apply(rule iterate_op[THEN sym]) using goal1 by auto
  1.1716        finally show ?thesis by auto
  1.1717 @@ -2186,7 +2225,7 @@
  1.1718  subsection {* Finally, the integral of a constant *}
  1.1719  
  1.1720  lemma has_integral_const[intro]:
  1.1721 -  "((\<lambda>x. c) has_integral (content({a..b::real^'n}) *\<^sub>R c)) ({a..b})"
  1.1722 +  "((\<lambda>x. c) has_integral (content({a..b::'a::ordered_euclidean_space}) *\<^sub>R c)) ({a..b})"
  1.1723    unfolding has_integral apply(rule,rule,rule_tac x="\<lambda>x. ball x 1" in exI)
  1.1724    apply(rule,rule gauge_trivial)apply(rule,rule,erule conjE)
  1.1725    unfolding split_def apply(subst scaleR_left.setsum[THEN sym, unfolded o_def])
  1.1726 @@ -2232,7 +2271,7 @@
  1.1727    apply(rule order_trans[OF _ rsum_bound[OF assms]]) apply(rule eq_refl) apply(rule arg_cong[where f=norm])
  1.1728    unfolding setsum_subtractf[THEN sym] apply(rule setsum_cong2) unfolding scaleR.diff_right by auto
  1.1729  
  1.1730 -lemma has_integral_bound: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  1.1731 +lemma has_integral_bound: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::real_normed_vector"
  1.1732    assumes "0 \<le> B" "(f has_integral i) ({a..b})" "\<forall>x\<in>{a..b}. norm(f x) \<le> B"
  1.1733    shows "norm i \<le> B * content {a..b}"
  1.1734  proof- let ?P = "content {a..b} > 0" { presume "?P \<Longrightarrow> ?thesis"
  1.1735 @@ -2252,53 +2291,52 @@
  1.1736  
  1.1737  subsection {* Similar theorems about relationship among components. *}
  1.1738  
  1.1739 -lemma rsum_component_le: fixes f::"real^'n \<Rightarrow> real^'m"
  1.1740 -  assumes "p tagged_division_of {a..b}"  "\<forall>x\<in>{a..b}. (f x)$i \<le> (g x)$i"
  1.1741 -  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"
  1.1742 -  unfolding setsum_component apply(rule setsum_mono)
  1.1743 -  apply(rule mp) defer apply assumption unfolding split_paired_all apply rule unfolding split_conv
  1.1744 +lemma rsum_component_le: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  1.1745 +  assumes "p tagged_division_of {a..b}"  "\<forall>x\<in>{a..b}. (f x)$$i \<le> (g x)$$i"
  1.1746 +  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"
  1.1747 +  unfolding  euclidean_component.setsum apply(rule setsum_mono) apply safe
  1.1748  proof- fix a b assume ab:"(a,b) \<in> p" note assm = tagged_division_ofD(2-4)[OF assms(1) ab]
  1.1749    from this(3) guess u v apply-by(erule exE)+ note b=this
  1.1750 -  show "(content b *\<^sub>R f a) $ i \<le> (content b *\<^sub>R g a) $ i" unfolding b
  1.1751 -    unfolding Cart_nth.scaleR real_scaleR_def apply(rule mult_left_mono)
  1.1752 +  show "(content b *\<^sub>R f a) $$ i \<le> (content b *\<^sub>R g a) $$ i" unfolding b
  1.1753 +    unfolding euclidean_simps real_scaleR_def apply(rule mult_left_mono)
  1.1754      defer apply(rule content_pos_le,rule assms(2)[rule_format]) using assm by auto qed
  1.1755  
  1.1756 -lemma has_integral_component_le: fixes f::"real^'n \<Rightarrow> real^'m"
  1.1757 -  assumes "(f has_integral i) s" "(g has_integral j) s"  "\<forall>x\<in>s. (f x)$k \<le> (g x)$k"
  1.1758 -  shows "i$k \<le> j$k"
  1.1759 -proof- have lem:"\<And>a b g i j. \<And>f::real^'n \<Rightarrow> real^'m. (f has_integral i) ({a..b}) \<Longrightarrow> 
  1.1760 -    (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"
  1.1761 -  proof(rule ccontr) case goal1 hence *:"0 < (i$k - j$k) / 3" by auto
  1.1762 +lemma has_integral_component_le: fixes f g::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  1.1763 +  assumes "(f has_integral i) s" "(g has_integral j) s"  "\<forall>x\<in>s. (f x)$$k \<le> (g x)$$k"
  1.1764 +  shows "i$$k \<le> j$$k"
  1.1765 +proof- have lem:"\<And>a b i (j::'b). \<And>g f::'a \<Rightarrow> 'b. (f has_integral i) ({a..b}) \<Longrightarrow> 
  1.1766 +    (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"
  1.1767 +  proof(rule ccontr) case goal1 hence *:"0 < (i$$k - j$$k) / 3" by auto
  1.1768      guess d1 using goal1(1)[unfolded has_integral,rule_format,OF *] apply-by(erule exE conjE)+ note d1=this[rule_format]
  1.1769      guess d2 using goal1(2)[unfolded has_integral,rule_format,OF *] apply-by(erule exE conjE)+ note d2=this[rule_format]
  1.1770      guess p using fine_division_exists[OF gauge_inter[OF d1(1) d2(1)], of a b] unfolding fine_inter .
  1.1771 -    note p = this(1) conjunctD2[OF this(2)]  note le_less_trans[OF component_le_norm, of _ _ k]
  1.1772 +    note p = this(1) conjunctD2[OF this(2)]  note le_less_trans[OF component_le_norm, of _ _ k] term g
  1.1773      note this[OF d1(2)[OF conjI[OF p(1,2)]]] this[OF d2(2)[OF conjI[OF p(1,3)]]]
  1.1774 -    thus False unfolding Cart_nth.diff using rsum_component_le[OF p(1) goal1(3)] by smt
  1.1775 +    thus False unfolding euclidean_simps using rsum_component_le[OF p(1) goal1(3)] apply simp by smt
  1.1776    qed let ?P = "\<exists>a b. s = {a..b}"
  1.1777    { presume "\<not> ?P \<Longrightarrow> ?thesis" thus ?thesis proof(cases ?P)
  1.1778        case True then guess a b apply-by(erule exE)+ note s=this
  1.1779        show ?thesis apply(rule lem) using assms[unfolded s] by auto
  1.1780      qed auto } assume as:"\<not> ?P"
  1.1781    { presume "\<not> ?thesis \<Longrightarrow> False" thus ?thesis by auto }
  1.1782 -  assume "\<not> i$k \<le> j$k" hence ij:"(i$k - j$k) / 3 > 0" by auto
  1.1783 +  assume "\<not> i$$k \<le> j$$k" hence ij:"(i$$k - j$$k) / 3 > 0" by auto
  1.1784    note has_integral_altD[OF _ as this] from this[OF assms(1)] this[OF assms(2)] guess B1 B2 . note B=this[rule_format]
  1.1785 -  have "bounded (ball 0 B1 \<union> ball (0::real^'n) B2)" unfolding bounded_Un by(rule conjI bounded_ball)+
  1.1786 +  have "bounded (ball 0 B1 \<union> ball (0::'a) B2)" unfolding bounded_Un by(rule conjI bounded_ball)+
  1.1787    from bounded_subset_closed_interval[OF this] guess a b apply- by(erule exE)+
  1.1788    note ab = conjunctD2[OF this[unfolded Un_subset_iff]]
  1.1789    guess w1 using B(2)[OF ab(1)] .. note w1=conjunctD2[OF this]
  1.1790    guess w2 using B(4)[OF ab(2)] .. note w2=conjunctD2[OF this]
  1.1791 -  have *:"\<And>w1 w2 j i::real .\<bar>w1 - i\<bar> < (i - j) / 3 \<Longrightarrow> \<bar>w2 - j\<bar> < (i - j) / 3 \<Longrightarrow> w1 \<le> w2 \<Longrightarrow> False" by smt(*SMTSMT*)
  1.1792 +  have *:"\<And>w1 w2 j i::real .\<bar>w1 - i\<bar> < (i - j) / 3 \<Longrightarrow> \<bar>w2 - j\<bar> < (i - j) / 3 \<Longrightarrow> w1 \<le> w2 \<Longrightarrow> False" by smt
  1.1793    note le_less_trans[OF component_le_norm[of _ k]] note this[OF w1(2)] this[OF w2(2)] moreover
  1.1794 -  have "w1$k \<le> w2$k" apply(rule lem[OF w1(1) w2(1)]) using assms by auto ultimately
  1.1795 -  show False unfolding Cart_nth.diff by(rule *) qed
  1.1796 -
  1.1797 -lemma integral_component_le: fixes f::"real^'n \<Rightarrow> real^'m"
  1.1798 -  assumes "f integrable_on s" "g integrable_on s"  "\<forall>x\<in>s. (f x)$k \<le> (g x)$k"
  1.1799 -  shows "(integral s f)$k \<le> (integral s g)$k"
  1.1800 +  have "w1$$k \<le> w2$$k" apply(rule lem[OF w1(1) w2(1)]) using assms by auto ultimately
  1.1801 +  show False unfolding euclidean_simps by(rule *) qed
  1.1802 +
  1.1803 +lemma integral_component_le: fixes g f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  1.1804 +  assumes "f integrable_on s" "g integrable_on s"  "\<forall>x\<in>s. (f x)$$k \<le> (g x)$$k"
  1.1805 +  shows "(integral s f)$$k \<le> (integral s g)$$k"
  1.1806    apply(rule has_integral_component_le) using integrable_integral assms by auto
  1.1807  
  1.1808 -lemma has_integral_dest_vec1_le: fixes f::"real^'n \<Rightarrow> real^1"
  1.1809 +(*lemma has_integral_dest_vec1_le: fixes f::"'a::ordered_euclidean_space \<Rightarrow> real^1"
  1.1810    assumes "(f has_integral i) s"  "(g has_integral j) s" "\<forall>x\<in>s. f x \<le> g x"
  1.1811    shows "dest_vec1 i \<le> dest_vec1 j" apply(rule has_integral_component_le[OF assms(1-2)])
  1.1812    using assms(3) unfolding vector_le_def by auto
  1.1813 @@ -2306,61 +2344,57 @@
  1.1814  lemma integral_dest_vec1_le: fixes f::"real^'n \<Rightarrow> real^1"
  1.1815    assumes "f integrable_on s" "g integrable_on s" "\<forall>x\<in>s. f x \<le> g x"
  1.1816    shows "dest_vec1(integral s f) \<le> dest_vec1(integral s g)"
  1.1817 -  apply(rule has_integral_dest_vec1_le) apply(rule_tac[1-2] integrable_integral) using assms by auto
  1.1818 -
  1.1819 -lemma has_integral_component_nonneg: fixes f::"real^'n \<Rightarrow> real^'m"
  1.1820 -  assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> (f x)$k" shows "0 \<le> i$k"
  1.1821 -  using has_integral_component_le[OF has_integral_0 assms(1)] using assms(2) by auto
  1.1822 -
  1.1823 -lemma integral_component_nonneg: fixes f::"real^'n \<Rightarrow> real^'m"
  1.1824 -  assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> (f x)$k" shows "0 \<le> (integral s f)$k"
  1.1825 +  apply(rule has_integral_dest_vec1_le) apply(rule_tac[1-2] integrable_integral) using assms by auto*)
  1.1826 +
  1.1827 +lemma has_integral_component_nonneg: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  1.1828 +  assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> (f x)$$k" shows "0 \<le> i$$k" 
  1.1829 +  using has_integral_component_le[OF has_integral_0 assms(1)] using assms(2-) by auto
  1.1830 +
  1.1831 +lemma integral_component_nonneg: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::euclidean_space"
  1.1832 +  assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> (f x)$$k" shows "0 \<le> (integral s f)$$k"
  1.1833    apply(rule has_integral_component_nonneg) using assms by auto
  1.1834  
  1.1835 -lemma has_integral_dest_vec1_nonneg: fixes f::"real^'n \<Rightarrow> real^1"
  1.1836 +(*lemma has_integral_dest_vec1_nonneg: fixes f::"real^'n \<Rightarrow> real^1"
  1.1837    assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> i"
  1.1838    using has_integral_component_nonneg[OF assms(1), of 1]
  1.1839    using assms(2) unfolding vector_le_def by auto
  1.1840  
  1.1841  lemma integral_dest_vec1_nonneg: fixes f::"real^'n \<Rightarrow> real^1"
  1.1842    assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> integral s f"
  1.1843 -  apply(rule has_integral_dest_vec1_nonneg) using assms by auto
  1.1844 -
  1.1845 -lemma has_integral_component_neg: fixes f::"real^'n \<Rightarrow> real^'m"
  1.1846 -  assumes "(f has_integral i) s" "\<forall>x\<in>s. (f x)$k \<le> 0" shows "i$k \<le> 0"
  1.1847 -  using has_integral_component_le[OF assms(1) has_integral_0] assms(2) by auto
  1.1848 -
  1.1849 -lemma has_integral_dest_vec1_neg: fixes f::"real^'n \<Rightarrow> real^1"
  1.1850 +  apply(rule has_integral_dest_vec1_nonneg) using assms by auto*)
  1.1851 +
  1.1852 +lemma has_integral_component_neg: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::ordered_euclidean_space"
  1.1853 +  assumes "(f has_integral i) s" "\<forall>x\<in>s. (f x)$$k \<le> 0"shows "i$$k \<le> 0" 
  1.1854 +  using has_integral_component_le[OF assms(1) has_integral_0] assms(2-) by auto
  1.1855 +
  1.1856 +(*lemma has_integral_dest_vec1_neg: fixes f::"real^'n \<Rightarrow> real^1"
  1.1857    assumes "(f has_integral i) s" "\<forall>x\<in>s. f x \<le> 0" shows "i \<le> 0"
  1.1858 -  using has_integral_component_neg[OF assms(1),of 1] using assms(2) by auto
  1.1859 -
  1.1860 -lemma has_integral_component_lbound:
  1.1861 -  assumes "(f has_integral i) {a..b}"  "\<forall>x\<in>{a..b}. B \<le> f(x)$k" shows "B * content {a..b} \<le> i$k"
  1.1862 -  using has_integral_component_le[OF has_integral_const assms(1),of "(\<chi> i. B)" k] assms(2)
  1.1863 -  unfolding Cart_lambda_beta vector_scaleR_component by(auto simp add:field_simps)
  1.1864 -
  1.1865 -lemma has_integral_component_ubound: 
  1.1866 -  assumes "(f has_integral i) {a..b}" "\<forall>x\<in>{a..b}. f x$k \<le> B"
  1.1867 -  shows "i$k \<le> B * content({a..b})"
  1.1868 -  using has_integral_component_le[OF assms(1) has_integral_const, of k "vec B"]
  1.1869 -  unfolding vec_component Cart_nth.scaleR using assms(2) by(auto simp add:field_simps)
  1.1870 -
  1.1871 -lemma integral_component_lbound:
  1.1872 -  assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. B \<le> f(x)$k"
  1.1873 -  shows "B * content({a..b}) \<le> (integral({a..b}) f)$k"
  1.1874 +  using has_integral_component_neg[OF assms(1),of 1] using assms(2) by auto*)
  1.1875 +
  1.1876 +lemma has_integral_component_lbound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  1.1877 +  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"
  1.1878 +  using has_integral_component_le[OF has_integral_const assms(1),of "(\<chi>\<chi> i. B)::'b" k] assms(2-)
  1.1879 +  unfolding euclidean_simps euclidean_lambda_beta'[OF assms(3)] by(auto simp add:field_simps)
  1.1880 +
  1.1881 +lemma has_integral_component_ubound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  1.1882 +  assumes "(f has_integral i) {a..b}" "\<forall>x\<in>{a..b}. f x$$k \<le> B" "k<DIM('b)"
  1.1883 +  shows "i$$k \<le> B * content({a..b})"
  1.1884 +  using has_integral_component_le[OF assms(1) has_integral_const, of k "\<chi>\<chi> i. B"]
  1.1885 +  unfolding euclidean_simps euclidean_lambda_beta'[OF assms(3)] using assms(2) by(auto simp add:field_simps)
  1.1886 +
  1.1887 +lemma integral_component_lbound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  1.1888 +  assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. B \<le> f(x)$$k" "k<DIM('b)"
  1.1889 +  shows "B * content({a..b}) \<le> (integral({a..b}) f)$$k"
  1.1890    apply(rule has_integral_component_lbound) using assms unfolding has_integral_integral by auto
  1.1891  
  1.1892 -lemma integral_component_ubound:
  1.1893 -  assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. f(x)$k \<le> B"
  1.1894 -  shows "(integral({a..b}) f)$k \<le> B * content({a..b})"
  1.1895 +lemma integral_component_ubound: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  1.1896 +  assumes "f integrable_on {a..b}" "\<forall>x\<in>{a..b}. f(x)$$k \<le> B" "k<DIM('b)" 
  1.1897 +  shows "(integral({a..b}) f)$$k \<le> B * content({a..b})"
  1.1898    apply(rule has_integral_component_ubound) using assms unfolding has_integral_integral by auto
  1.1899  
  1.1900  subsection {* Uniform limit of integrable functions is integrable. *}
  1.1901  
  1.1902 -lemma real_arch_invD:
  1.1903 -  "0 < (e::real) \<Longrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)"
  1.1904 -  by(subst(asm) real_arch_inv)
  1.1905 -
  1.1906 -lemma integrable_uniform_limit: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.1907 +lemma integrable_uniform_limit: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  1.1908    assumes "\<forall>e>0. \<exists>g. (\<forall>x\<in>{a..b}. norm(f x - g x) \<le> e) \<and> g integrable_on {a..b}"
  1.1909    shows "f integrable_on {a..b}"
  1.1910  proof- { presume *:"content {a..b} > 0 \<Longrightarrow> ?thesis"
  1.1911 @@ -2446,7 +2480,7 @@
  1.1912  lemma dest_vec1_indicator_abs_le_1: "abs(indicator s x) \<le> 1"
  1.1913    unfolding indicator_def by auto
  1.1914  
  1.1915 -definition "negligible (s::(real^'n) set) \<equiv> (\<forall>a b. ((indicator s) has_integral 0) {a..b})"
  1.1916 +definition "negligible (s::(_::ordered_euclidean_space) set) \<equiv> (\<forall>a b. ((indicator s) has_integral 0) {a..b})"
  1.1917  
  1.1918  lemma indicator_simps[simp]:"x\<in>s \<Longrightarrow> indicator s x = 1" "x\<notin>s \<Longrightarrow> indicator s x = 0"
  1.1919    unfolding indicator_def by auto
  1.1920 @@ -2461,98 +2495,104 @@
  1.1921    apply(rule iterate_nonzero_image_lemma) apply(rule assms monoidal_monoid)+
  1.1922    unfolding assms using neutral_add unfolding neutral_add using assms by auto 
  1.1923  
  1.1924 -lemma interval_doublesplit: shows "{a..b} \<inter> {x . abs(x$k - c) \<le> (e::real)} =
  1.1925 -  {(\<chi> i. if i = k then max (a$k) (c - e) else a$i) .. (\<chi> i. if i = k then min (b$k) (c + e) else b$i)}"
  1.1926 +lemma interval_doublesplit:  fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)"
  1.1927 +  shows "{a..b} \<inter> {x . abs(x$$k - c) \<le> (e::real)} = 
  1.1928 +  {(\<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)}"
  1.1929  proof- have *:"\<And>x c e::real. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  1.1930    have **:"\<And>s P Q. s \<inter> {x. P x \<and> Q x} = (s \<inter> {x. Q x}) \<inter> {x. P x}" by blast
  1.1931 -  show ?thesis unfolding * ** interval_split by(rule refl) qed
  1.1932 -
  1.1933 -lemma division_doublesplit: assumes "p division_of {a..b::real^'n}" 
  1.1934 -  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})"
  1.1935 +  show ?thesis unfolding * ** interval_split[OF assms] by(rule refl) qed
  1.1936 +
  1.1937 +lemma division_doublesplit: fixes a::"'a::ordered_euclidean_space" assumes "p division_of {a..b}" and k:"k<DIM('a)"
  1.1938 +  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})"
  1.1939  proof- have *:"\<And>x c. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  1.1940    have **:"\<And>p q p' q'. p division_of q \<Longrightarrow> p = p' \<Longrightarrow> q = q' \<Longrightarrow> p' division_of q'" by auto
  1.1941 -  note division_split(1)[OF assms, where c="c+e" and k=k,unfolded interval_split]
  1.1942 -  note division_split(2)[OF this, where c="c-e" and k=k] 
  1.1943 -  thus ?thesis apply(rule **) unfolding interval_doublesplit unfolding * unfolding interval_split interval_doublesplit
  1.1944 +  note division_split(1)[OF assms, where c="c+e",unfolded interval_split[OF k]]
  1.1945 +  note division_split(2)[OF this, where c="c-e" and k=k,OF k] 
  1.1946 +  thus ?thesis apply(rule **) using k apply- unfolding interval_doublesplit unfolding * unfolding interval_split interval_doublesplit
  1.1947      apply(rule set_ext) unfolding mem_Collect_eq apply rule apply(erule conjE exE)+ apply(rule_tac x=la in exI) defer
  1.1948 -    apply(erule conjE exE)+ apply(rule_tac x="l \<inter> {x. c + e \<ge> x $ k}" in exI) apply rule defer apply rule
  1.1949 +    apply(erule conjE exE)+ apply(rule_tac x="l \<inter> {x. c + e \<ge> x $$ k}" in exI) apply rule defer apply rule
  1.1950      apply(rule_tac x=l in exI) by blast+ qed
  1.1951  
  1.1952 -lemma content_doublesplit: assumes "0 < e"
  1.1953 -  obtains d where "0 < d" "content({a..b} \<inter> {x. abs(x$k - c) \<le> d}) < e"
  1.1954 +lemma content_doublesplit: fixes a::"'a::ordered_euclidean_space" assumes "0 < e" and k:"k<DIM('a)"
  1.1955 +  obtains d where "0 < d" "content({a..b} \<inter> {x. abs(x$$k - c) \<le> d}) < e"
  1.1956  proof(cases "content {a..b} = 0")
  1.1957 -  case True show ?thesis apply(rule that[of 1]) defer unfolding interval_doublesplit
  1.1958 +  case True show ?thesis apply(rule that[of 1]) defer unfolding interval_doublesplit[OF k]
  1.1959      apply(rule le_less_trans[OF content_subset]) defer apply(subst True)
  1.1960 -    unfolding interval_doublesplit[THEN sym] using assms by auto 
  1.1961 -next case False def d \<equiv> "e / 3 / setprod (\<lambda>i. b$i - a$i) (UNIV - {k})"
  1.1962 +    unfolding interval_doublesplit[THEN sym,OF k] using assms by auto 
  1.1963 +next case False def d \<equiv> "e / 3 / setprod (\<lambda>i. b$$i - a$$i) ({..<DIM('a)} - {k})"
  1.1964    note False[unfolded content_eq_0 not_ex not_le, rule_format]
  1.1965 -  hence prod0:"0 < setprod (\<lambda>i. b$i - a$i) (UNIV - {k})" apply-apply(rule setprod_pos) by smt
  1.1966 +  hence "\<And>x. x<DIM('a) \<Longrightarrow> b$$x > a$$x" by(auto simp add:not_le)
  1.1967 +  hence prod0:"0 < setprod (\<lambda>i. b$$i - a$$i) ({..<DIM('a)} - {k})" apply-apply(rule setprod_pos) by(auto simp add:field_simps)
  1.1968    hence "d > 0" unfolding d_def using assms by(auto simp add:field_simps) thus ?thesis
  1.1969 -  proof(rule that[of d]) have *:"UNIV = insert k (UNIV - {k})" by auto
  1.1970 -    have **:"{a..b} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d} \<noteq> {} \<Longrightarrow> 
  1.1971 -      (\<Prod>i\<in>UNIV - {k}. interval_upperbound ({a..b} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) $ i - interval_lowerbound ({a..b} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) $ i)
  1.1972 -      = (\<Prod>i\<in>UNIV - {k}. b$i - a$i)" apply(rule setprod_cong,rule refl)
  1.1973 -      unfolding interval_doublesplit interval_eq_empty not_ex not_less unfolding interval_bounds by auto
  1.1974 -    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)
  1.1975 +  proof(rule that[of d]) have *:"{..<DIM('a)} = insert k ({..<DIM('a)} - {k})" using k by auto
  1.1976 +    have **:"{a..b} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d} \<noteq> {} \<Longrightarrow> 
  1.1977 +      (\<Prod>i\<in>{..<DIM('a)} - {k}. interval_upperbound ({a..b} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) $$ i
  1.1978 +      - interval_lowerbound ({a..b} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) $$ i)
  1.1979 +      = (\<Prod>i\<in>{..<DIM('a)} - {k}. b$$i - a$$i)" apply(rule setprod_cong,rule refl) 
  1.1980 +      unfolding interval_doublesplit[OF k] apply(subst interval_bounds) defer apply(subst interval_bounds)
  1.1981 +      unfolding interval_eq_empty not_ex not_less by auto
  1.1982 +    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)
  1.1983        unfolding if_not_P apply(subst *) apply(subst setprod_insert) unfolding **
  1.1984 -      unfolding interval_doublesplit interval_eq_empty not_ex not_less unfolding interval_bounds unfolding Cart_lambda_beta if_P[OF refl]
  1.1985 -    proof- have "(min (b $ k) (c + d) - max (a $ k) (c - d)) \<le> 2 * d" by auto
  1.1986 -      also have "... < e / (\<Prod>i\<in>UNIV - {k}. b $ i - a $ i)" unfolding d_def using assms prod0 by(auto simp add:field_simps)
  1.1987 -      finally show "(min (b $ k) (c + d) - max (a $ k) (c - d)) * (\<Prod>i\<in>UNIV - {k}. b $ i - a $ i) < e"
  1.1988 +      unfolding interval_doublesplit[OF k] interval_eq_empty not_ex not_less prefer 3
  1.1989 +      apply(subst interval_bounds) defer apply(subst interval_bounds) unfolding euclidean_lambda_beta'[OF k] if_P[OF refl]
  1.1990 +    proof- have "(min (b $$ k) (c + d) - max (a $$ k) (c - d)) \<le> 2 * d" by auto
  1.1991 +      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)
  1.1992 +      finally show "(min (b $$ k) (c + d) - max (a $$ k) (c - d)) * (\<Prod>i\<in>{..<DIM('a)} - {k}. b $$ i - a $$ i) < e"
  1.1993          unfolding pos_less_divide_eq[OF prod0] . qed auto qed qed
  1.1994  
  1.1995 -lemma negligible_standard_hyperplane[intro]: "negligible {x. x$k = (c::real)}" 
  1.1996 +lemma negligible_standard_hyperplane[intro]: fixes type::"'a::ordered_euclidean_space" assumes k:"k<DIM('a)"
  1.1997 +  shows "negligible {x::'a. x$$k = (c::real)}" 
  1.1998    unfolding negligible_def has_integral apply(rule,rule,rule,rule)
  1.1999 -proof- case goal1 from content_doublesplit[OF this,of a b k c] guess d . note d=this let ?i = "indicator {x. x$k = c}"
  1.2000 +proof- case goal1 from content_doublesplit[OF this k,of a b c] guess d . note d=this let ?i = "indicator {x::'a. x$$k = c}"
  1.2001    show ?case apply(rule_tac x="\<lambda>x. ball x d" in exI) apply(rule,rule gauge_ball,rule d)
  1.2002    proof(rule,rule) fix p assume p:"p tagged_division_of {a..b} \<and> (\<lambda>x. ball x d) fine p"
  1.2003 -    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)"
  1.2004 +    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)"
  1.2005        apply(rule setsum_cong2) unfolding split_paired_all real_scaleR_def mult_cancel_right split_conv
  1.2006        apply(cases,rule disjI1,assumption,rule disjI2)
  1.2007 -    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)
  1.2008 -      show "content l = content (l \<inter> {x. \<bar>x $ k - c\<bar> \<le> d})" apply(rule arg_cong[where f=content])
  1.2009 +    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)
  1.2010 +      show "content l = content (l \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d})" apply(rule arg_cong[where f=content])
  1.2011          apply(rule set_ext,rule,rule) unfolding mem_Collect_eq
  1.2012        proof- fix y assume y:"y\<in>l" note p[THEN conjunct2,unfolded fine_def,rule_format,OF as(1),unfolded split_conv]
  1.2013          note this[unfolded subset_eq mem_ball dist_norm,rule_format,OF y] note le_less_trans[OF component_le_norm[of _ k] this]
  1.2014 -        thus "\<bar>y $ k - c\<bar> \<le> d" unfolding Cart_nth.diff xk by auto
  1.2015 +        thus "\<bar>y $$ k - c\<bar> \<le> d" unfolding euclidean_simps xk by auto
  1.2016        qed auto qed
  1.2017      note p'= tagged_division_ofD[OF p[THEN conjunct1]] and p''=division_of_tagged_division[OF p[THEN conjunct1]]
  1.2018      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
  1.2019        apply(subst abs_of_nonneg) apply(rule setsum_nonneg,rule) unfolding split_paired_all split_conv
  1.2020        apply(rule mult_nonneg_nonneg) apply(drule p'(4)) apply(erule exE)+ apply(rule_tac b=b in back_subst)
  1.2021        prefer 2 apply(subst(asm) eq_commute) apply assumption
  1.2022 -      apply(subst interval_doublesplit) apply(rule content_pos_le) apply(rule indicator_pos_le)
  1.2023 -    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}))"
  1.2024 +      apply(subst interval_doublesplit[OF k]) apply(rule content_pos_le) apply(rule indicator_pos_le)
  1.2025 +    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}))"
  1.2026          apply(rule setsum_mono) unfolding split_paired_all split_conv 
  1.2027 -        apply(rule mult_right_le_one_le) apply(drule p'(4)) by(auto simp add:interval_doublesplit intro!:content_pos_le)
  1.2028 +        apply(rule mult_right_le_one_le) apply(drule p'(4)) by(auto simp add:interval_doublesplit[OF k] intro!:content_pos_le)
  1.2029        also have "... < e" apply(subst setsum_over_tagged_division_lemma[OF p[THEN conjunct1]])
  1.2030 -      proof- case goal1 have "content ({u..v} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) \<le> content {u..v}"
  1.2031 -          unfolding interval_doublesplit apply(rule content_subset) unfolding interval_doublesplit[THEN sym] by auto
  1.2032 -        thus ?case unfolding goal1 unfolding interval_doublesplit using content_pos_le by smt
  1.2033 -      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"
  1.2034 +      proof- case goal1 have "content ({u..v} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) \<le> content {u..v}"
  1.2035 +          unfolding interval_doublesplit[OF k] apply(rule content_subset) unfolding interval_doublesplit[THEN sym,OF k] by auto
  1.2036 +        thus ?case unfolding goal1 unfolding interval_doublesplit[OF k] using content_pos_le by smt
  1.2037 +      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"
  1.2038            apply(rule setsum_nonneg,rule) unfolding mem_Collect_eq image_iff apply(erule exE bexE conjE)+ unfolding split_paired_all 
  1.2039 -        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)"
  1.2040 +        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)"
  1.2041            guess u v using p'(4)[OF as(2)] apply-by(erule exE)+ note * = this
  1.2042 -          show "content x \<ge> 0" unfolding as snd_conv * interval_doublesplit by(rule content_pos_le)
  1.2043 -        qed have **:"norm (1::real) \<le> 1" by auto note division_doublesplit[OF p'',unfolded interval_doublesplit]
  1.2044 -        note dsum_bound[OF this **,unfolded interval_doublesplit[THEN sym]]
  1.2045 -        note this[unfolded real_scaleR_def real_norm_def mult_1_right mult_1, of k c d] note le_less_trans[OF this d(2)]
  1.2046 -        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"
  1.2047 +          show "content x \<ge> 0" unfolding as snd_conv * interval_doublesplit[OF k] by(rule content_pos_le)
  1.2048 +        qed have **:"norm (1::real) \<le> 1" by auto note division_doublesplit[OF p'' k,unfolded interval_doublesplit[OF k]]
  1.2049 +        note dsum_bound[OF this **,unfolded interval_doublesplit[THEN sym,OF k]]
  1.2050 +        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)]
  1.2051 +        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"
  1.2052            apply(subst vsum_nonzero_image_lemma[of "snd ` p" content "{}", unfolded o_def,THEN sym])
  1.2053            apply(rule finite_imageI p' content_empty)+ unfolding forall_in_division[OF p'']
  1.2054          proof(rule,rule,rule,rule,rule,rule,rule,erule conjE) fix m n u v
  1.2055 -          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}"
  1.2056 -          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
  1.2057 +          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}"
  1.2058 +          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
  1.2059            note subset_interior[OF this, unfolded division_ofD(5)[OF p'' as(1-3)] interior_inter[of "{m..n}"]]
  1.2060 -          hence "interior ({m..n} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) = {}" unfolding as Int_absorb by auto
  1.2061 -          thus "content ({m..n} \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) = 0" unfolding interval_doublesplit content_eq_0_interior[THEN sym] .
  1.2062 +          hence "interior ({m..n} \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) = {}" unfolding as Int_absorb by auto
  1.2063 +          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] .
  1.2064          qed qed
  1.2065 -      finally show "(\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x $ k - c\<bar> \<le> d}) * ?i x) < e" .
  1.2066 +      finally show "(\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d}) * ?i x) < e" .
  1.2067      qed qed qed
  1.2068  
  1.2069  subsection {* A technical lemma about "refinement" of division. *}
  1.2070  
  1.2071 -lemma tagged_division_finer: fixes p::"((real^'n) \<times> ((real^'n) set)) set"
  1.2072 +lemma tagged_division_finer: fixes p::"(('a::ordered_euclidean_space) \<times> (('a::ordered_euclidean_space) set)) set"
  1.2073    assumes "p tagged_division_of {a..b}" "gauge d"
  1.2074    obtains q where "q tagged_division_of {a..b}" "d fine q" "\<forall>(x,k) \<in> p. k \<subseteq> d(x) \<longrightarrow> (x,k) \<in> q"
  1.2075  proof-
  1.2076 @@ -2562,7 +2602,7 @@
  1.2077    { have *:"finite p" "p tagged_partial_division_of {a..b}" using assms(1) unfolding tagged_division_of_def by auto
  1.2078      presume "\<And>p. finite p \<Longrightarrow> ?P p" from this[rule_format,OF * assms(2)] guess q .. note q=this
  1.2079      thus ?thesis apply-apply(rule that[of q]) unfolding tagged_division_ofD[OF assms(1)] by auto
  1.2080 -  } fix p::"((real^'n) \<times> ((real^'n) set)) set" assume as:"finite p"
  1.2081 +  } fix p::"(('a::ordered_euclidean_space) \<times> (('a::ordered_euclidean_space) set)) set" assume as:"finite p"
  1.2082    show "?P p" apply(rule,rule) using as proof(induct p) 
  1.2083      case empty show ?case apply(rule_tac x="{}" in exI) unfolding fine_def by auto
  1.2084    next case (insert xk p) guess x k using surj_pair[of xk] apply- by(erule exE)+ note xk=this
  1.2085 @@ -2614,10 +2654,10 @@
  1.2086      show "finite {(i, j) |i j. i \<in> s \<and> j \<in> t i}" apply(rule finite_product_dependent) using insert by auto
  1.2087    qed(insert insert, auto) qed auto
  1.2088  
  1.2089 -lemma has_integral_negligible: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  1.2090 +lemma has_integral_negligible: fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector"
  1.2091    assumes "negligible s" "\<forall>x\<in>(t - s). f x = 0"
  1.2092    shows "(f has_integral 0) t"
  1.2093 -proof- presume P:"\<And>f::real^'n \<Rightarrow> 'a. \<And>a b. (\<forall>x. ~(x \<in> s) \<longrightarrow> f x = 0) \<Longrightarrow> (f has_integral 0) ({a..b})"
  1.2094 +proof- presume P:"\<And>f::'b::ordered_euclidean_space \<Rightarrow> 'a. \<And>a b. (\<forall>x. ~(x \<in> s) \<longrightarrow> f x = 0) \<Longrightarrow> (f has_integral 0) ({a..b})"
  1.2095    let ?f = "(\<lambda>x. if x \<in> t then f x else 0)"
  1.2096    show ?thesis apply(rule_tac f="?f" in has_integral_eq) apply(rule) unfolding if_P apply(rule refl)
  1.2097      apply(subst has_integral_alt) apply(cases,subst if_P,assumption) unfolding if_not_P
  1.2098 @@ -2627,7 +2667,7 @@
  1.2099        apply(safe,rule_tac x=1 in exI,rule) apply(rule zero_less_one,safe) apply(rule_tac x=0 in exI)
  1.2100        apply(rule,rule P) using assms(2) by auto
  1.2101    qed
  1.2102 -next fix f::"real^'n \<Rightarrow> 'a" and a b::"real^'n" assume assm:"\<forall>x. x \<notin> s \<longrightarrow> f x = 0" 
  1.2103 +next fix f::"'b \<Rightarrow> 'a" and a b::"'b" assume assm:"\<forall>x. x \<notin> s \<longrightarrow> f x = 0" 
  1.2104    show "(f has_integral 0) {a..b}" unfolding has_integral
  1.2105    proof(safe) case goal1
  1.2106      hence "\<And>n. e / 2 / ((real n+1) * (2 ^ n)) > 0" 
  1.2107 @@ -2680,10 +2720,10 @@
  1.2108          apply(subst sumr_geometric) using goal1 by auto
  1.2109        finally show "?goal" by auto qed qed qed
  1.2110  
  1.2111 -lemma has_integral_spike: fixes f::"real^'n \<Rightarrow> 'a::real_normed_vector"
  1.2112 +lemma has_integral_spike: fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::real_normed_vector"
  1.2113    assumes "negligible s" "(\<forall>x\<in>(t - s). g x = f x)" "(f has_integral y) t"
  1.2114    shows "(g has_integral y) t"
  1.2115 -proof- { fix a b::"real^'n" and f g ::"real^'n \<Rightarrow> 'a" and y::'a
  1.2116 +proof- { fix a b::"'b" and f g ::"'b \<Rightarrow> 'a" and y::'a
  1.2117      assume as:"\<forall>x \<in> {a..b} - s. g x = f x" "(f has_integral y) {a..b}"
  1.2118      have "((\<lambda>x. f x + (g x - f x)) has_integral (y + 0)) {a..b}" apply(rule has_integral_add[OF as(2)])
  1.2119        apply(rule has_integral_negligible[OF assms(1)]) using as by auto
  1.2120 @@ -2726,9 +2766,8 @@
  1.2121  lemma negligible_union_eq[simp]: "negligible (s \<union> t) \<longleftrightarrow> (negligible s \<and> negligible t)"
  1.2122    using negligible_union by auto
  1.2123  
  1.2124 -lemma negligible_sing[intro]: "negligible {a::real^'n}" 
  1.2125 -proof- guess x using UNIV_witness[where 'a='n] ..
  1.2126 -  show ?thesis using negligible_standard_hyperplane[of x "a$x"] by auto qed
  1.2127 +lemma negligible_sing[intro]: "negligible {a::_::ordered_euclidean_space}" 
  1.2128 +  using negligible_standard_hyperplane[of 0 "a$$0"] by auto 
  1.2129  
  1.2130  lemma negligible_insert[simp]: "negligible(insert a s) \<longleftrightarrow> negligible s"
  1.2131    apply(subst insert_is_Un) unfolding negligible_union_eq by auto
  1.2132 @@ -2741,9 +2780,9 @@
  1.2133  lemma negligible_unions[intro]: assumes "finite s" "\<forall>t\<in>s. negligible t" shows "negligible(\<Union>s)"
  1.2134    using assms by(induct,auto) 
  1.2135  
  1.2136 -lemma negligible:  "negligible s \<longleftrightarrow> (\<forall>t::(real^'n) set. (indicator s has_integral 0) t)"
  1.2137 +lemma negligible:  "negligible s \<longleftrightarrow> (\<forall>t::('a::ordered_euclidean_space) set. (indicator s has_integral 0) t)"
  1.2138    apply safe defer apply(subst negligible_def)
  1.2139 -proof- fix t::"(real^'n) set" assume as:"negligible s"
  1.2140 +proof- fix t::"'a set" assume as:"negligible s"
  1.2141    have *:"(\<lambda>x. if x \<in> s \<inter> t then 1 else 0) = (\<lambda>x. if x\<in>t then if x\<in>s then 1 else 0 else 0)" by(rule ext,auto)  
  1.2142    show "(indicator s has_integral 0) t" apply(subst has_integral_alt)
  1.2143      apply(cases,subst if_P,assumption) unfolding if_not_P apply(safe,rule as[unfolded negligible_def,rule_format])
  1.2144 @@ -2767,10 +2806,10 @@
  1.2145  
  1.2146  subsection {* In particular, the boundary of an interval is negligible. *}
  1.2147  
  1.2148 -lemma negligible_frontier_interval: "negligible({a..b} - {a<..<b})"
  1.2149 -proof- let ?A = "\<Union>((\<lambda>k. {x. x$k = a$k} \<union> {x. x$k = b$k}) ` UNIV)"
  1.2150 +lemma negligible_frontier_interval: "negligible({a::'a::ordered_euclidean_space..b} - {a<..<b})"
  1.2151 +proof- let ?A = "\<Union>((\<lambda>k. {x. x$$k = a$$k} \<union> {x::'a. x$$k = b$$k}) ` {..<DIM('a)})"
  1.2152    have "{a..b} - {a<..<b} \<subseteq> ?A" apply rule unfolding Diff_iff mem_interval not_all
  1.2153 -    apply(erule conjE exE)+ apply(rule_tac X="{x. x $ xa = a $ xa} \<union> {x. x $ xa = b $ xa}" in UnionI)
  1.2154 +    apply(erule conjE exE)+ apply(rule_tac X="{x. x $$ xa = a $$ xa} \<union> {x. x $$ xa = b $$ xa}" in UnionI)
  1.2155      apply(erule_tac[!] x=xa in allE) by auto
  1.2156    thus ?thesis apply-apply(rule negligible_subset[of ?A]) apply(rule negligible_unions[OF finite_imageI]) by auto qed
  1.2157  
  1.2158 @@ -2799,34 +2838,35 @@
  1.2159    shows "(\<forall>i\<in>d. P i) \<longleftrightarrow> P {a..b}"
  1.2160    using operative_division[OF monoidal_and assms] division_of_finite[OF assms(2)] by auto
  1.2161  
  1.2162 -lemma operative_approximable: assumes "0 \<le> e" fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.2163 -  shows "operative op \<and> (\<lambda>i. \<exists>g. (\<forall>x\<in>i. norm (f x - g (x::real^'n)) \<le> e) \<and> g integrable_on i)" unfolding operative_def neutral_and
  1.2164 -proof safe fix a b::"real^'n" { assume "content {a..b} = 0"
  1.2165 +lemma operative_approximable: assumes "0 \<le> e" fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.2166 +  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
  1.2167 +proof safe fix a b::"'b" { assume "content {a..b} = 0"
  1.2168      thus "\<exists>g. (\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e) \<and> g integrable_on {a..b}" 
  1.2169        apply(rule_tac x=f in exI) using assms by(auto intro!:integrable_on_null) }
  1.2170 -  { fix c k g assume as:"\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e" "g integrable_on {a..b}"
  1.2171 -    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}"
  1.2172 -      "\<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}"
  1.2173 -      apply(rule_tac[!] x=g in exI) using as(1) integrable_split[OF as(2)] by auto }
  1.2174 -  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}"
  1.2175 -                          "\<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}"
  1.2176 -  let ?g = "\<lambda>x. if x$k = c then f x else if x$k \<le> c then g1 x else g2 x"
  1.2177 +  { 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)"
  1.2178 +    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}"
  1.2179 +      "\<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}"
  1.2180 +      apply(rule_tac[!] x=g in exI) using as(1) integrable_split[OF as(2) k] by auto }
  1.2181 +  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}"
  1.2182 +                          "\<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}"
  1.2183 +  assume k:"k<DIM('b)"
  1.2184 +  let ?g = "\<lambda>x. if x$$k = c then f x else if x$$k \<le> c then g1 x else g2 x"
  1.2185    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)
  1.2186 -  proof safe case goal1 thus ?case apply- apply(cases "x$k=c", case_tac "x$k < c") using as assms by auto
  1.2187 -  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}"
  1.2188 -    then guess h1 h2 unfolding integrable_on_def by auto from has_integral_split[OF this]
  1.2189 +  proof safe case goal1 thus ?case apply- apply(cases "x$$k=c", case_tac "x$$k < c") using as assms by auto
  1.2190 +  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}"
  1.2191 +    then guess h1 h2 unfolding integrable_on_def by auto from has_integral_split[OF this k] 
  1.2192      show ?case unfolding integrable_on_def by auto
  1.2193 -  next show "?g integrable_on {a..b} \<inter> {x. x $ k \<le> c}" "?g integrable_on {a..b} \<inter> {x. x $ k \<ge> c}"
  1.2194 -      apply(rule_tac[!] integrable_spike[OF negligible_standard_hyperplane[of k c]]) using as(2,4) by auto qed qed
  1.2195 -
  1.2196 -lemma approximable_on_division: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.2197 +  next show "?g integrable_on {a..b} \<inter> {x. x $$ k \<le> c}" "?g integrable_on {a..b} \<inter> {x. x $$ k \<ge> c}"
  1.2198 +      apply(rule_tac[!] integrable_spike[OF negligible_standard_hyperplane[of k c]]) using k as(2,4) by auto qed qed
  1.2199 +
  1.2200 +lemma approximable_on_division: fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.2201    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"
  1.2202    obtains g where "\<forall>x\<in>{a..b}. norm (f x - g x) \<le> e" "g integrable_on {a..b}"
  1.2203  proof- note * = operative_division[OF monoidal_and operative_approximable[OF assms(1)] assms(2)]
  1.2204    note this[unfolded iterate_and[OF division_of_finite[OF assms(2)]]] from assms(3)[unfolded this[of f]]
  1.2205    guess g .. thus thesis apply-apply(rule that[of g]) by auto qed
  1.2206  
  1.2207 -lemma integrable_continuous: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.2208 +lemma integrable_continuous: fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.2209    assumes "continuous_on {a..b} f" shows "f integrable_on {a..b}"
  1.2210  proof(rule integrable_uniform_limit,safe) fix e::real assume e:"0 < e"
  1.2211    from compact_uniformly_continuous[OF assms compact_interval,unfolded uniformly_continuous_on_def,rule_format,OF e] guess d ..
  1.2212 @@ -2847,48 +2887,52 @@
  1.2213  subsection {* Specialization of additivity to one dimension. *}
  1.2214  
  1.2215  lemma operative_1_lt: assumes "monoidal opp"
  1.2216 -  shows "operative opp f \<longleftrightarrow> ((\<forall>a b. b \<le> a \<longrightarrow> f {a..b::real^1} = neutral opp) \<and>
  1.2217 +  shows "operative opp f \<longleftrightarrow> ((\<forall>a b. b \<le> a \<longrightarrow> f {a..b::real} = neutral opp) \<and>
  1.2218                  (\<forall>a b c. a < c \<and> c < b \<longrightarrow> opp (f{a..c})(f{c..b}) = f {a..b}))"
  1.2219 -  unfolding operative_def content_eq_0_1 forall_1 vector_le_def vector_less_def
  1.2220 -proof safe fix a b c::"real^1" assume as:"\<forall>a b c. f {a..b} = opp (f ({a..b} \<inter> {x. x $ 1 \<le> c})) (f ({a..b} \<inter> {x. c \<le> x $ 1}))" "a $ 1 < c $ 1" "c $ 1 < b $ 1"
  1.2221 -    from this(2-) have "{a..b} \<inter> {x. x $ 1 \<le> c $ 1} = {a..c}" "{a..b} \<inter> {x. x $ 1 \<ge> c $ 1} = {c..b}" by auto
  1.2222 -    thus "opp (f {a..c}) (f {c..b}) = f {a..b}" unfolding as(1)[rule_format,of a b "c$1"] by auto
  1.2223 -next fix a b::"real^1" and c::real
  1.2224 -  assume as:"\<forall>a b. b $ 1 \<le> a $ 1 \<longrightarrow> f {a..b} = neutral opp" "\<forall>a b c. a $ 1 < c $ 1 \<and> c $ 1 < b $ 1 \<longrightarrow> opp (f {a..c}) (f {c..b}) = f {a..b}"
  1.2225 -  show "f {a..b} = opp (f ({a..b} \<inter> {x. x $ 1 \<le> c})) (f ({a..b} \<inter> {x. c \<le> x $ 1}))"
  1.2226 -  proof(cases "c \<in> {a$1 .. b$1}")
  1.2227 -    case False hence "c<a$1 \<or> c>b$1" by auto
  1.2228 +  unfolding operative_def content_eq_0 DIM_real less_one dnf_simps(39,41) Eucl_real_simps
  1.2229 +    (* The dnf_simps simplify "\<exists> x. x= _ \<and> _" and "\<forall>k. k = _ \<longrightarrow> _" *)
  1.2230 +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}))
  1.2231 +    (f ({a..b} \<inter> {x. c \<le> x}))" "a < c" "c < b"
  1.2232 +    from this(2-) have "{a..b} \<inter> {x. x \<le> c} = {a..c}" "{a..b} \<inter> {x. x \<ge> c} = {c..b}" by auto
  1.2233 +    thus "opp (f {a..c}) (f {c..b}) = f {a..b}" unfolding as(1)[rule_format,of a b "c"] by auto
  1.2234 +next fix a b c::real
  1.2235 +  assume as:"\<forall>a b. b \<le> a \<longrightarrow> f {a..b} = neutral opp" "\<forall>a b c. a < c \<and> c < b \<longrightarrow> opp (f {a..c}) (f {c..b}) = f {a..b}"
  1.2236 +  show "f {a..b} = opp (f ({a..b} \<inter> {x. x \<le> c})) (f ({a..b} \<inter> {x. c \<le> x}))"
  1.2237 +  proof(cases "c \<in> {a .. b}")
  1.2238 +    case False hence "c<a \<or> c>b" by auto
  1.2239      thus ?thesis apply-apply(erule disjE)
  1.2240 -    proof- assume "c<a$1" hence *:"{a..b} \<inter> {x. x $ 1 \<le> c} = {1..0}"  "{a..b} \<inter> {x. c \<le> x $ 1} = {a..b}" by auto
  1.2241 +    proof- assume "c<a" hence *:"{a..b} \<inter> {x. x \<le> c} = {1..0}"  "{a..b} \<inter> {x. c \<le> x} = {a..b}" by auto
  1.2242        show ?thesis unfolding * apply(subst as(1)[rule_format,of 0 1]) using assms by auto
  1.2243 -    next   assume "b$1<c" hence *:"{a..b} \<inter> {x. x $ 1 \<le> c} = {a..b}"  "{a..b} \<inter> {x. c \<le> x $ 1} = {1..0}" by auto
  1.2244 +    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
  1.2245        show ?thesis unfolding * apply(subst as(1)[rule_format,of 0 1]) using assms by auto
  1.2246      qed
  1.2247 -  next case True hence *:"min (b $ 1) c = c" "max (a $ 1) c = c" by auto
  1.2248 -    show ?thesis unfolding interval_split num1_eq_iff if_True * vec_def[THEN sym]
  1.2249 -    proof(cases "c = a$1 \<or> c = b$1")
  1.2250 -      case False thus "f {a..b} = opp (f {a..vec1 c}) (f {vec1 c..b})"
  1.2251 +  next case True hence *:"min (b) c = c" "max a c = c" by auto
  1.2252 +    have **:"0 < DIM(real)" by auto
  1.2253 +    have ***:"\<And>P Q. (\<chi>\<chi> i. if i = 0 then P i else Q i) = (P 0::real)" apply(subst euclidean_eq)
  1.2254 +      apply safe unfolding euclidean_lambda_beta' by auto
  1.2255 +    show ?thesis unfolding interval_split[OF **,unfolded Eucl_real_simps(1,3)] unfolding *** *
  1.2256 +    proof(cases "c = a \<or> c = b")
  1.2257 +      case False thus "f {a..b} = opp (f {a..c}) (f {c..b})"
  1.2258          apply-apply(subst as(2)[rule_format]) using True by auto
  1.2259 -    next case True thus "f {a..b} = opp (f {a..vec1 c}) (f {vec1 c..b})" apply-
  1.2260 -      proof(erule disjE) assume "c=a$1" hence *:"a = vec1 c" unfolding Cart_eq by auto 
  1.2261 -        hence "f {a..vec1 c} = neutral opp" apply-apply(rule as(1)[rule_format]) by auto
  1.2262 +    next case True thus "f {a..b} = opp (f {a..c}) (f {c..b})" apply-
  1.2263 +      proof(erule disjE) assume *:"c=a"
  1.2264 +        hence "f {a..c} = neutral opp" apply-apply(rule as(1)[rule_format]) by auto
  1.2265          thus ?thesis using assms unfolding * by auto
  1.2266 -      next assume "c=b$1" hence *:"b = vec1 c" unfolding Cart_eq by auto 
  1.2267 -        hence "f {vec1 c..b} = neutral opp" apply-apply(rule as(1)[rule_format]) by auto
  1.2268 +      next assume *:"c=b" hence "f {c..b} = neutral opp" apply-apply(rule as(1)[rule_format]) by auto
  1.2269          thus ?thesis using assms unfolding * by auto qed qed qed qed
  1.2270  
  1.2271  lemma operative_1_le: assumes "monoidal opp"
  1.2272 -  shows "operative opp f \<longleftrightarrow> ((\<forall>a b. b \<le> a \<longrightarrow> f {a..b::real^1} = neutral opp) \<and>
  1.2273 +  shows "operative opp f \<longleftrightarrow> ((\<forall>a b. b \<le> a \<longrightarrow> f {a..b::real} = neutral opp) \<and>
  1.2274                  (\<forall>a b c. a \<le> c \<and> c \<le> b \<longrightarrow> opp (f{a..c})(f{c..b}) = f {a..b}))"
  1.2275  unfolding operative_1_lt[OF assms]
  1.2276 -proof safe fix a b c::"real^1" assume as:"\<forall>a b c. a \<le> c \<and> c \<le> b \<longrightarrow> opp (f {a..c}) (f {c..b}) = f {a..b}" "a < c" "c < b"
  1.2277 -  show "opp (f {a..c}) (f {c..b}) = f {a..b}" apply(rule as(1)[rule_format]) using as(2-) unfolding vector_le_def vector_less_def by auto
  1.2278 -next fix a b c ::"real^1"
  1.2279 -  assume "\<forall>a b. b \<le> a \<longrightarrow> f {a..b} = neutral opp" "\<forall>a b c. a < c \<and> c < b \<longrightarrow> opp (f {a..c}) (f {c..b}) = f {a..b}" "a \<le> c" "c \<le> b"
  1.2280 +proof safe fix a b c::"real" assume as:"\<forall>a b c. a \<le> c \<and> c \<le> b \<longrightarrow> opp (f {a..c}) (f {c..b}) = f {a..b}" "a < c" "c < b"
  1.2281 +  show "opp (f {a..c}) (f {c..b}) = f {a..b}" apply(rule as(1)[rule_format]) using as(2-) by auto
  1.2282 +next fix a b c ::"real" assume "\<forall>a b. b \<le> a \<longrightarrow> f {a..b} = neutral opp"
  1.2283 +    "\<forall>a b c. a < c \<and> c < b \<longrightarrow> opp (f {a..c}) (f {c..b}) = f {a..b}" "a \<le> c" "c \<le> b"
  1.2284    note as = this[rule_format]
  1.2285    show "opp (f {a..c}) (f {c..b}) = f {a..b}"
  1.2286    proof(cases "c = a \<or> c = b")
  1.2287 -    case False thus ?thesis apply-apply(subst as(2)) using as(3-) unfolding vector_le_def vector_less_def Cart_eq by(auto simp del:dest_vec1_eq)
  1.2288 +    case False thus ?thesis apply-apply(subst as(2)) using as(3-) by(auto)
  1.2289      next case True thus ?thesis apply-
  1.2290        proof(erule disjE) assume *:"c=a" hence "f {a..c} = neutral opp" apply-apply(rule as(1)[rule_format]) by auto
  1.2291          thus ?thesis using assms unfolding * by auto
  1.2292 @@ -2898,16 +2942,16 @@
  1.2293  subsection {* Special case of additivity we need for the FCT. *}
  1.2294  
  1.2295  lemma interval_bound_sing[simp]: "interval_upperbound {a} = a"  "interval_lowerbound {a} = a"
  1.2296 -  unfolding interval_upperbound_def interval_lowerbound_def unfolding Cart_eq by auto
  1.2297 -
  1.2298 -lemma additive_tagged_division_1: fixes f::"real^1 \<Rightarrow> 'a::real_normed_vector"
  1.2299 -  assumes "dest_vec1 a \<le> dest_vec1 b" "p tagged_division_of {a..b}"
  1.2300 +  unfolding interval_upperbound_def interval_lowerbound_def  by auto
  1.2301 +
  1.2302 +lemma additive_tagged_division_1: fixes f::"real \<Rightarrow> 'a::real_normed_vector"
  1.2303 +  assumes "a \<le> b" "p tagged_division_of {a..b}"
  1.2304    shows "setsum (\<lambda>(x,k). f(interval_upperbound k) - f(interval_lowerbound k)) p = f b - f a"
  1.2305 -proof- let ?f = "(\<lambda>k::(real^1) set. if k = {} then 0 else f(interval_upperbound k) - f(interval_lowerbound k))"
  1.2306 -  have *:"operative op + ?f" unfolding operative_1_lt[OF monoidal_monoid] interval_eq_empty_1
  1.2307 -    by(auto simp add:not_less vector_less_def)
  1.2308 +proof- let ?f = "(\<lambda>k::(real) set. if k = {} then 0 else f(interval_upperbound k) - f(interval_lowerbound k))"
  1.2309 +  have ***:"\<forall>i<DIM(real). a $$ i \<le> b $$ i" using assms by auto 
  1.2310 +  have *:"operative op + ?f" unfolding operative_1_lt[OF monoidal_monoid] interval_eq_empty by auto
  1.2311    have **:"{a..b} \<noteq> {}" using assms(1) by auto note operative_tagged_division[OF monoidal_monoid * assms(2)]
  1.2312 -  note * = this[unfolded if_not_P[OF **] interval_bound_1[OF assms(1)],THEN sym ]
  1.2313 +  note * = this[unfolded if_not_P[OF **] interval_bounds[OF ***],THEN sym]
  1.2314    show ?thesis unfolding * apply(subst setsum_iterate[THEN sym]) defer
  1.2315      apply(rule setsum_cong2) unfolding split_paired_all split_conv using assms(2) by auto qed
  1.2316  
  1.2317 @@ -2934,40 +2978,46 @@
  1.2318  
  1.2319  subsection {* Fundamental theorem of calculus. *}
  1.2320  
  1.2321 -lemma fundamental_theorem_of_calculus: fixes f::"real^1 \<Rightarrow> 'a::banach"
  1.2322 -  assumes "a \<le> b"  "\<forall>x\<in>{a..b}. ((f o vec1) has_vector_derivative f'(vec1 x)) (at x within {a..b})"
  1.2323 -  shows "(f' has_integral (f(vec1 b) - f(vec1 a))) ({vec1 a..vec1 b})"
  1.2324 +lemma interval_bounds_real: assumes "a\<le>(b::real)"
  1.2325 +  shows "interval_upperbound {a..b} = b" "interval_lowerbound {a..b} = a"
  1.2326 +  apply(rule_tac[!] interval_bounds) using assms by auto
  1.2327 +
  1.2328 +lemma fundamental_theorem_of_calculus: fixes f::"real \<Rightarrow> 'a::banach"
  1.2329 +  assumes "a \<le> b"  "\<forall>x\<in>{a..b}. (f has_vector_derivative f' x) (at x within {a..b})"
  1.2330 +  shows "(f' has_integral (f b - f a)) ({a..b})"
  1.2331  unfolding has_integral_factor_content
  1.2332 -proof safe fix e::real assume e:"e>0" have ab:"dest_vec1 (vec1 a) \<le> dest_vec1 (vec1 b)" using assms(1) by auto
  1.2333 +proof safe fix e::real assume e:"e>0"
  1.2334    note assm = assms(2)[unfolded has_vector_derivative_def has_derivative_within_alt]
  1.2335    have *:"\<And>P Q. \<forall>x\<in>{a..b}. P x \<and> (\<forall>e>0. \<exists>d>0. Q x e d) \<Longrightarrow> \<forall>x. \<exists>(d::real)>0. x\<in>{a..b} \<longrightarrow> Q x e d" using e by blast
  1.2336    note this[OF assm,unfolded gauge_existence_lemma] from choice[OF this,unfolded Ball_def[symmetric]]
  1.2337    guess d .. note d=conjunctD2[OF this[rule_format],rule_format]
  1.2338 -  show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {vec1 a..vec1 b} \<and> d fine p \<longrightarrow>
  1.2339 -                 norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f' x) - (f (vec1 b) - f (vec1 a))) \<le> e * content {vec1 a..vec1 b})"
  1.2340 -    apply(rule_tac x="\<lambda>x. ball x (d (dest_vec1 x))" in exI,safe)
  1.2341 +  show "\<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow>
  1.2342 +                 norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f' x) - (f b - f a)) \<le> e * content {a..b})"
  1.2343 +    apply(rule_tac x="\<lambda>x. ball x (d x)" in exI,safe)
  1.2344      apply(rule gauge_ball_dependent,rule,rule d(1))
  1.2345 -  proof- fix p assume as:"p tagged_division_of {vec1 a..vec1 b}" "(\<lambda>x. ball x (d (dest_vec1 x))) fine p"
  1.2346 -    show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f' x) - (f (vec1 b) - f (vec1 a))) \<le> e * content {vec1 a..vec1 b}" 
  1.2347 -      unfolding content_1[OF ab] additive_tagged_division_1[OF ab as(1),of f,THEN sym]
  1.2348 -      unfolding vector_minus_component[THEN sym] additive_tagged_division_1[OF ab as(1),of "\<lambda>x. x",THEN sym]
  1.2349 -      apply(subst dest_vec1_setsum) unfolding setsum_right_distrib defer unfolding setsum_subtractf[THEN sym] 
  1.2350 +  proof- fix p assume as:"p tagged_division_of {a..b}" "(\<lambda>x. ball x (d x)) fine p"
  1.2351 +    show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f' x) - (f b - f a)) \<le> e * content {a..b}" 
  1.2352 +      unfolding content_real[OF assms(1)] additive_tagged_division_1[OF assms(1) as(1),of f,THEN sym]
  1.2353 +      unfolding additive_tagged_division_1[OF assms(1) as(1),of "\<lambda>x. x",THEN sym]
  1.2354 +      unfolding setsum_right_distrib defer unfolding setsum_subtractf[THEN sym] 
  1.2355      proof(rule setsum_norm_le,safe) fix x k assume "(x,k)\<in>p"
  1.2356        note xk = tagged_division_ofD(2-4)[OF as(1) this] from this(3) guess u v apply-by(erule exE)+ note k=this
  1.2357 -      have *:"dest_vec1 u \<le> dest_vec1 v" using xk unfolding k by auto
  1.2358 -      have ball:"\<forall>xa\<in>k. xa \<in> ball x (d (dest_vec1 x))" using as(2)[unfolded fine_def,rule_format,OF `(x,k)\<in>p`,unfolded split_conv subset_eq] .
  1.2359 -      have "norm ((v$1 - u$1) *\<^sub>R f' x - (f v - f u)) \<le> norm (f u - f x - (u$1 - x$1) *\<^sub>R f' x) + norm (f v - f x - (v$1 - x$1) *\<^sub>R f' x)"
  1.2360 +      have *:"u \<le> v" using xk unfolding k by auto
  1.2361 +      have ball:"\<forall>xa\<in>k. xa \<in> ball x (d x)" using as(2)[unfolded fine_def,rule_format,OF `(x,k)\<in>p`,
  1.2362 +        unfolded split_conv subset_eq] .
  1.2363 +      have "norm ((v - u) *\<^sub>R f' x - (f v - f u)) \<le>
  1.2364 +        norm (f u - f x - (u - x) *\<^sub>R f' x) + norm (f v - f x - (v - x) *\<^sub>R f' x)"
  1.2365          apply(rule order_trans[OF _ norm_triangle_ineq4]) apply(rule eq_refl) apply(rule arg_cong[where f=norm])
  1.2366          unfolding scaleR.diff_left by(auto simp add:algebra_simps)
  1.2367 -      also have "... \<le> e * norm (dest_vec1 u - dest_vec1 x) + e * norm (dest_vec1 v - dest_vec1 x)"
  1.2368 -        apply(rule add_mono) apply(rule d(2)[of "x$1" "u$1",unfolded o_def vec1_dest_vec1]) prefer 4
  1.2369 -        apply(rule d(2)[of "x$1" "v$1",unfolded o_def vec1_dest_vec1])
  1.2370 +      also have "... \<le> e * norm (u - x) + e * norm (v - x)"
  1.2371 +        apply(rule add_mono) apply(rule d(2)[of "x" "u",unfolded o_def]) prefer 4
  1.2372 +        apply(rule d(2)[of "x" "v",unfolded o_def])
  1.2373          using ball[rule_format,of u] ball[rule_format,of v] 
  1.2374 -        using xk(1-2) unfolding k subset_eq by(auto simp add:dist_norm norm_real)
  1.2375 -      also have "... \<le> e * dest_vec1 (interval_upperbound k - interval_lowerbound k)"
  1.2376 -        unfolding k interval_bound_1[OF *] using xk(1) unfolding k by(auto simp add:dist_norm norm_real field_simps)
  1.2377 +        using xk(1-2) unfolding k subset_eq by(auto simp add:dist_real_def) 
  1.2378 +      also have "... \<le> e * (interval_upperbound k - interval_lowerbound k)"
  1.2379 +        unfolding k interval_bounds_real[OF *] using xk(1) unfolding k by(auto simp add:dist_real_def field_simps)
  1.2380        finally show "norm (content k *\<^sub>R f' x - (f (interval_upperbound k) - f (interval_lowerbound k))) \<le>
  1.2381 -        e * dest_vec1 (interval_upperbound k - interval_lowerbound k)" unfolding k interval_bound_1[OF *] content_1[OF *] .
  1.2382 +        e * (interval_upperbound k - interval_lowerbound k)" unfolding k interval_bounds_real[OF *] content_real[OF *] .
  1.2383      qed(insert as, auto) qed qed
  1.2384  
  1.2385  subsection {* Attempt a systematic general set of "offset" results for components. *}
  1.2386 @@ -2980,11 +3030,11 @@
  1.2387  
  1.2388  subsection {* Only need trivial subintervals if the interval itself is trivial. *}
  1.2389  
  1.2390 -lemma division_of_nontrivial: fixes s::"(real^'n) set set"
  1.2391 +lemma division_of_nontrivial: fixes s::"('a::ordered_euclidean_space) set set"
  1.2392    assumes "s division_of {a..b}" "content({a..b}) \<noteq> 0"
  1.2393    shows "{k. k \<in> s \<and> content k \<noteq> 0} division_of {a..b}" using assms(1) apply-
  1.2394  proof(induct "card s" arbitrary:s rule:nat_less_induct)
  1.2395 -  fix s::"(real^'n) set set" assume assm:"s division_of {a..b}"
  1.2396 +  fix s::"'a set set" assume assm:"s division_of {a..b}"
  1.2397      "\<forall>m<card s. \<forall>x. m = card x \<longrightarrow> x division_of {a..b} \<longrightarrow> {k \<in> x. content k \<noteq> 0} division_of {a..b}" 
  1.2398    note s = division_ofD[OF assm(1)] let ?thesis = "{k \<in> s. content k \<noteq> 0} division_of {a..b}"
  1.2399    { presume *:"{k \<in> s. content k \<noteq> 0} \<noteq> s \<Longrightarrow> ?thesis"
  1.2400 @@ -2999,30 +3049,32 @@
  1.2401    have "k \<subseteq> \<Union>(s - {k})" apply safe apply(rule *[unfolded closed_limpt,rule_format]) unfolding islimpt_approachable
  1.2402    proof safe fix x and e::real assume as:"x\<in>k" "e>0"
  1.2403      from k(2)[unfolded k content_eq_0] guess i .. 
  1.2404 -    hence i:"c$i = d$i" using s(3)[OF k(1),unfolded k] unfolding interval_ne_empty by smt
  1.2405 -    hence xi:"x$i = d$i" using as unfolding k mem_interval by smt
  1.2406 -    def y \<equiv> "(\<chi> j. if j = i then if c$i \<le> (a$i + b$i) / 2 then c$i + min e (b$i - c$i) / 2 else c$i - min e (c$i - a$i) / 2 else x$j)"
  1.2407 +    hence i:"c$$i = d$$i" "i<DIM('a)" using s(3)[OF k(1),unfolded k] unfolding interval_ne_empty by auto
  1.2408 +    hence xi:"x$$i = d$$i" using as unfolding k mem_interval by smt
  1.2409 +    def y \<equiv> "(\<chi>\<chi> j. if j = i then if c$$i \<le> (a$$i + b$$i) / 2 then c$$i +
  1.2410 +      min e (b$$i - c$$i) / 2 else c$$i - min e (c$$i - a$$i) / 2 else x$$j)::'a"
  1.2411      show "\<exists>x'\<in>\<Union>(s - {k}). x' \<noteq> x \<and> dist x' x < e" apply(rule_tac x=y in bexI) 
  1.2412      proof have "d \<in> {c..d}" using s(3)[OF k(1)] unfolding k interval_eq_empty mem_interval by(fastsimp simp add: not_less)
  1.2413        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]]
  1.2414 -      hence xyi:"y$i \<noteq> x$i" unfolding y_def unfolding i xi Cart_lambda_beta if_P[OF refl]
  1.2415 -        apply(cases) apply(subst if_P,assumption) unfolding if_not_P not_le using as(2) using assms(2)[unfolded content_eq_0] by smt+ 
  1.2416 -      thus "y \<noteq> x" unfolding Cart_eq by auto
  1.2417 -      have *:"UNIV = insert i (UNIV - {i})" by auto
  1.2418 -      have "norm (y - x) < e + setsum (\<lambda>i. 0) (UNIV::'n set)" apply(rule le_less_trans[OF norm_le_l1])
  1.2419 +      hence xyi:"y$$i \<noteq> x$$i" unfolding y_def unfolding i xi euclidean_lambda_beta'[OF i(2)] if_P[OF refl]
  1.2420 +        apply(cases) apply(subst if_P,assumption) unfolding if_not_P not_le using as(2)
  1.2421 +        using assms(2)[unfolded content_eq_0] using i(2) by smt+ 
  1.2422 +      thus "y \<noteq> x" unfolding euclidean_eq[where 'a='a] using i by auto
  1.2423 +      have *:"{..<DIM('a)} = insert i ({..<DIM('a)} - {i})" using i by auto
  1.2424 +      have "norm (y - x) < e + setsum (\<lambda>i. 0) {..<DIM('a)}" apply(rule le_less_trans[OF norm_le_l1])
  1.2425          apply(subst *,subst setsum_insert) prefer 3 apply(rule add_less_le_mono)
  1.2426 -      proof- show "\<bar>(y - x) $ i\<bar> < e" unfolding y_def Cart_lambda_beta vector_minus_component if_P[OF refl]
  1.2427 +      proof- show "\<bar>(y - x) $$ i\<bar> < e" unfolding y_def euclidean_simps euclidean_lambda_beta'[OF i(2)] if_P[OF refl]
  1.2428            apply(cases) apply(subst if_P,assumption) unfolding if_not_P unfolding i xi using di as(2) by auto
  1.2429 -        show "(\<Sum>i\<in>UNIV - {i}. \<bar>(y - x) $ i\<bar>) \<le> (\<Sum>i\<in>UNIV. 0)" unfolding y_def by auto 
  1.2430 +        show "(\<Sum>i\<in>{..<DIM('a)} - {i}. \<bar>(y - x) $$ i\<bar>) \<le> (\<Sum>i\<in>{..<DIM('a)}. 0)" unfolding y_def by auto 
  1.2431        qed auto thus "dist y x < e" unfolding dist_norm by auto
  1.2432        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
  1.2433        moreover have "y \<in> \<Union>s" unfolding s mem_interval
  1.2434 -      proof note simps = y_def Cart_lambda_beta if_not_P
  1.2435 -        fix j::'n show "a $ j \<le> y $ j \<and> y $ j \<le> b $ j" 
  1.2436 +      proof(rule,rule) note simps = y_def euclidean_lambda_beta' if_not_P
  1.2437 +        fix j assume j:"j<DIM('a)" show "a $$ j \<le> y $$ j \<and> y $$ j \<le> b $$ j" 
  1.2438          proof(cases "j = i") case False have "x \<in> {a..b}" using s(2)[OF k(1)] as(1) by auto
  1.2439 -          thus ?thesis unfolding simps if_not_P[OF False] unfolding mem_interval by auto
  1.2440 +          thus ?thesis using j apply- unfolding simps if_not_P[OF False] unfolding mem_interval by auto
  1.2441          next case True note T = this show ?thesis
  1.2442 -          proof(cases "c $ i \<le> (a $ i + b $ i) / 2")
  1.2443 +          proof(cases "c $$ i \<le> (a $$ i + b $$ i) / 2")
  1.2444              case True show ?thesis unfolding simps if_P[OF T] if_P[OF True] unfolding i
  1.2445                using True as(2) di apply-apply rule unfolding T by (auto simp add:field_simps) 
  1.2446            next case False thus ?thesis unfolding simps if_P[OF T] if_not_P[OF False] unfolding i
  1.2447 @@ -3036,20 +3088,20 @@
  1.2448  
  1.2449  subsection {* Integrabibility on subintervals. *}
  1.2450  
  1.2451 -lemma operative_integrable: fixes f::"real^'n \<Rightarrow> 'a::banach" shows
  1.2452 +lemma operative_integrable: fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach" shows
  1.2453    "operative op \<and> (\<lambda>i. f integrable_on i)"
  1.2454    unfolding operative_def neutral_and apply safe apply(subst integrable_on_def)
  1.2455 -  unfolding has_integral_null_eq apply(rule,rule refl) apply(rule,assumption)+
  1.2456 -  unfolding integrable_on_def by(auto intro: has_integral_split)
  1.2457 -
  1.2458 -lemma integrable_subinterval: fixes f::"real^'n \<Rightarrow> 'a::banach" 
  1.2459 +  unfolding has_integral_null_eq apply(rule,rule refl) apply(rule,assumption,assumption)+
  1.2460 +  unfolding integrable_on_def by(auto intro!: has_integral_split)
  1.2461 +
  1.2462 +lemma integrable_subinterval: fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach" 
  1.2463    assumes "f integrable_on {a..b}" "{c..d} \<subseteq> {a..b}" shows "f integrable_on {c..d}" 
  1.2464    apply(cases "{c..d} = {}") defer apply(rule partial_division_extend_1[OF assms(2)],assumption)
  1.2465    using operative_division_and[OF operative_integrable,THEN sym,of _ _ _ f] assms(1) by auto
  1.2466  
  1.2467  subsection {* Combining adjacent intervals in 1 dimension. *}
  1.2468  
  1.2469 -lemma has_integral_combine: assumes "(a::real^1) \<le> c" "c \<le> b"
  1.2470 +lemma has_integral_combine: assumes "(a::real) \<le> c" "c \<le> b"
  1.2471    "(f has_integral i) {a..c}" "(f has_integral (j::'a::banach)) {c..b}"
  1.2472    shows "(f has_integral (i + j)) {a..b}"
  1.2473  proof- note operative_integral[of f, unfolded operative_1_le[OF monoidal_lifted[OF monoidal_monoid]]]
  1.2474 @@ -3059,19 +3111,19 @@
  1.2475    with * show ?thesis apply-apply(subst(asm) if_P) defer apply(subst(asm) if_P) defer apply(subst(asm) if_P)
  1.2476      unfolding lifted.simps using assms(3-) by(auto simp add: integrable_on_def integral_unique) qed
  1.2477  
  1.2478 -lemma integral_combine: fixes f::"real^1 \<Rightarrow> 'a::banach"
  1.2479 +lemma integral_combine: fixes f::"real \<Rightarrow> 'a::banach"
  1.2480    assumes "a \<le> c" "c \<le> b" "f integrable_on ({a..b})"
  1.2481    shows "integral {a..c} f + integral {c..b} f = integral({a..b}) f"
  1.2482    apply(rule integral_unique[THEN sym]) apply(rule has_integral_combine[OF assms(1-2)])
  1.2483    apply(rule_tac[!] integrable_integral integrable_subinterval[OF assms(3)])+ using assms(1-2) by auto
  1.2484  
  1.2485 -lemma integrable_combine: fixes f::"real^1 \<Rightarrow> 'a::banach"
  1.2486 +lemma integrable_combine: fixes f::"real \<Rightarrow> 'a::banach"
  1.2487    assumes "a \<le> c" "c \<le> b" "f integrable_on {a..c}" "f integrable_on {c..b}"
  1.2488    shows "f integrable_on {a..b}" using assms unfolding integrable_on_def by(fastsimp intro!:has_integral_combine)
  1.2489  
  1.2490  subsection {* Reduce integrability to "local" integrability. *}
  1.2491  
  1.2492 -lemma integrable_on_little_subintervals: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.2493 +lemma integrable_on_little_subintervals: fixes f::"'b::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.2494    assumes "\<forall>x\<in>{a..b}. \<exists>d>0. \<forall>u v. x \<in> {u..v} \<and> {u..v} \<subseteq> ball x d \<and> {u..v} \<subseteq> {a..b} \<longrightarrow> f integrable_on {u..v}"
  1.2495    shows "f integrable_on {a..b}"
  1.2496  proof- have "\<forall>x. \<exists>d. x\<in>{a..b} \<longrightarrow> d>0 \<and> (\<forall>u v. x \<in> {u..v} \<and> {u..v} \<subseteq> ball x d \<and> {u..v} \<subseteq> {a..b} \<longrightarrow> f integrable_on {u..v})"
  1.2497 @@ -3089,53 +3141,46 @@
  1.2498  
  1.2499  lemma integral_has_vector_derivative: fixes f::"real \<Rightarrow> 'a::banach"
  1.2500    assumes "continuous_on {a..b} f" "x \<in> {a..b}"
  1.2501 -  shows "((\<lambda>u. integral {vec a..vec u} (f o dest_vec1)) has_vector_derivative f(x)) (at x within {a..b})"
  1.2502 +  shows "((\<lambda>u. integral {a..u} f) has_vector_derivative f(x)) (at x within {a..b})"
  1.2503    unfolding has_vector_derivative_def has_derivative_within_alt
  1.2504  apply safe apply(rule scaleR.bounded_linear_left)
  1.2505  proof- fix e::real assume e:"e>0"
  1.2506 -  note compact_uniformly_continuous[OF assms(1) compact_real_interval,unfolded uniformly_continuous_on_def]
  1.2507 +  note compact_uniformly_continuous[OF assms(1) compact_interval,unfolded uniformly_continuous_on_def]
  1.2508    from this[rule_format,OF e] guess d apply-by(erule conjE exE)+ note d=this[rule_format]
  1.2509 -  let ?I = "\<lambda>a b. integral {vec1 a..vec1 b} (f \<circ> dest_vec1)"
  1.2510 +  let ?I = "\<lambda>a b. integral {a..b} f"
  1.2511    show "\<exists>d>0. \<forall>y\<in>{a..b}. norm (y - x) < d \<longrightarrow> norm (?I a y - ?I a x - (y - x) *\<^sub>R f x) \<le> e * norm (y - x)"
  1.2512    proof(rule,rule,rule d,safe) case goal1 show ?case proof(cases "y < x")
  1.2513 -      case False have "f \<circ> dest_vec1 integrable_on {vec1 a..vec1 y}" apply(rule integrable_subinterval,rule integrable_continuous)
  1.2514 -        apply(rule continuous_on_o_dest_vec1 assms)+  unfolding not_less using assms(2) goal1 by auto
  1.2515 +      case False have "f integrable_on {a..y}" apply(rule integrable_subinterval,rule integrable_continuous)
  1.2516 +        apply(rule assms)  unfolding not_less using assms(2) goal1 by auto
  1.2517        hence *:"?I a y - ?I a x = ?I x y" unfolding algebra_simps apply(subst eq_commute) apply(rule integral_combine)
  1.2518          using False unfolding not_less using assms(2) goal1 by auto
  1.2519 -      have **:"norm (y - x) = content {vec1 x..vec1 y}" apply(subst content_1) using False unfolding not_less by auto
  1.2520 -      show ?thesis unfolding ** apply(rule has_integral_bound[where f="(\<lambda>u. f u - f x) o dest_vec1"]) unfolding * unfolding o_def
  1.2521 +      have **:"norm (y - x) = content {x..y}" apply(subst content_real) using False unfolding not_less by auto
  1.2522 +      show ?thesis unfolding ** apply(rule has_integral_bound[where f="(\<lambda>u. f u - f x)"]) unfolding * unfolding o_def
  1.2523          defer apply(rule has_integral_sub) apply(rule integrable_integral)
  1.2524 -        apply(rule integrable_subinterval,rule integrable_continuous) apply(rule continuous_on_o_dest_vec1[unfolded o_def] assms)+
  1.2525 -      proof- show "{vec1 x..vec1 y} \<subseteq> {vec1 a..vec1 b}" using goal1 assms(2) by auto
  1.2526 +        apply(rule integrable_subinterval,rule integrable_continuous) apply(rule assms)+
  1.2527 +      proof- show "{x..y} \<subseteq> {a..b}" using goal1 assms(2) by auto
  1.2528          have *:"y - x = norm(y - x)" using False by auto
  1.2529 -        show "((\<lambda>xa. f x) has_integral (y - x) *\<^sub>R f x) {vec1 x..vec1 y}" apply(subst *) unfolding ** by auto
  1.2530 -        show "\<forall>xa\<in>{vec1 x..vec1 y}. norm (f (dest_vec1 xa) - f x) \<le> e" apply safe apply(rule less_imp_le)
  1.2531 +        show "((\<lambda>xa. f x) has_integral (y - x) *\<^sub>R f x) {x.. y}" apply(subst *) unfolding ** by auto
  1.2532 +        show "\<forall>xa\<in>{x..y}. norm (f xa - f x) \<le> e" apply safe apply(rule less_imp_le)
  1.2533            apply(rule d(2)[unfolded dist_norm]) using assms(2) using goal1 by auto
  1.2534        qed(insert e,auto)
  1.2535 -    next case True have "f \<circ> dest_vec1 integrable_on {vec1 a..vec1 x}" apply(rule integrable_subinterval,rule integrable_continuous)
  1.2536 -        apply(rule continuous_on_o_dest_vec1 assms)+  unfolding not_less using assms(2) goal1 by auto
  1.2537 +    next case True have "f integrable_on {a..x}" apply(rule integrable_subinterval,rule integrable_continuous)
  1.2538 +        apply(rule assms)+  unfolding not_less using assms(2) goal1 by auto
  1.2539        hence *:"?I a x - ?I a y = ?I y x" unfolding algebra_simps apply(subst eq_commute) apply(rule integral_combine)
  1.2540          using True using assms(2) goal1 by auto
  1.2541 -      have **:"norm (y - x) = content {vec1 y..vec1 x}" apply(subst content_1) using True unfolding not_less by auto
  1.2542 +      have **:"norm (y - x) = content {y..x}" apply(subst content_real) using True unfolding not_less by auto
  1.2543        have ***:"\<And>fy fx c::'a. fx - fy - (y - x) *\<^sub>R c = -(fy - fx - (x - y) *\<^sub>R c)" unfolding scaleR_left.diff by auto 
  1.2544        show ?thesis apply(subst ***) unfolding norm_minus_cancel **
  1.2545 -        apply(rule has_integral_bound[where f="(\<lambda>u. f u - f x) o dest_vec1"]) unfolding * unfolding o_def
  1.2546 +        apply(rule has_integral_bound[where f="(\<lambda>u. f u - f x)"]) unfolding * unfolding o_def
  1.2547          defer apply(rule has_integral_sub) apply(subst minus_minus[THEN sym]) unfolding minus_minus
  1.2548 -        apply(rule integrable_integral) apply(rule integrable_subinterval,rule integrable_continuous)
  1.2549 -        apply(rule continuous_on_o_dest_vec1[unfolded o_def] assms)+
  1.2550 -      proof- show "{vec1 y..vec1 x} \<subseteq> {vec1 a..vec1 b}" using goal1 assms(2) by auto
  1.2551 +        apply(rule integrable_integral) apply(rule integrable_subinterval,rule integrable_continuous) apply(rule assms)+
  1.2552 +      proof- show "{y..x} \<subseteq> {a..b}" using goal1 assms(2) by auto
  1.2553          have *:"x - y = norm(y - x)" using True by auto
  1.2554 -        show "((\<lambda>xa. f x) has_integral (x - y) *\<^sub>R f x) {vec1 y..vec1 x}" apply(subst *) unfolding ** by auto
  1.2555 -        show "\<forall>xa\<in>{vec1 y..vec1 x}. norm (f (dest_vec1 xa) - f x) \<le> e" apply safe apply(rule less_imp_le)
  1.2556 +        show "((\<lambda>xa. f x) has_integral (x - y) *\<^sub>R f x) {y..x}" apply(subst *) unfolding ** by auto
  1.2557 +        show "\<forall>xa\<in>{y..x}. norm (f xa - f x) \<le> e" apply safe apply(rule less_imp_le)
  1.2558            apply(rule d(2)[unfolded dist_norm]) using assms(2) using goal1 by auto
  1.2559        qed(insert e,auto) qed qed qed
  1.2560  
  1.2561 -lemma integral_has_vector_derivative': fixes f::"real^1 \<Rightarrow> 'a::banach"
  1.2562 -  assumes "continuous_on {a..b} f" "x \<in> {a..b}"
  1.2563 -  shows "((\<lambda>u. (integral {a..vec u} f)) has_vector_derivative f x) (at (x$1) within {a$1..b$1})"
  1.2564 -  using integral_has_vector_derivative[OF continuous_on_o_vec1[OF assms(1)], of "x$1"]
  1.2565 -  unfolding o_def vec1_dest_vec1 using assms(2) by auto
  1.2566 -
  1.2567  lemma antiderivative_continuous: assumes "continuous_on {a..b::real} f"
  1.2568    obtains g where "\<forall>x\<in> {a..b}. (g has_vector_derivative (f(x)::_::banach)) (at x within {a..b})"
  1.2569    apply(rule that,rule) using integral_has_vector_derivative[OF assms] by auto
  1.2570 @@ -3143,13 +3188,12 @@
  1.2571  subsection {* Combined fundamental theorem of calculus. *}
  1.2572  
  1.2573  lemma antiderivative_integral_continuous: fixes f::"real \<Rightarrow> 'a::banach" assumes "continuous_on {a..b} f"
  1.2574 -  obtains g where "\<forall>u\<in>{a..b}. \<forall>v \<in> {a..b}. u \<le> v \<longrightarrow> ((f o dest_vec1) has_integral (g v - g u)) {vec u..vec v}"
  1.2575 +  obtains g where "\<forall>u\<in>{a..b}. \<forall>v \<in> {a..b}. u \<le> v \<longrightarrow> (f has_integral (g v - g u)) {u..v}"
  1.2576  proof- from antiderivative_continuous[OF assms] guess g . note g=this
  1.2577    show ?thesis apply(rule that[of g])
  1.2578    proof safe case goal1 have "\<forall>x\<in>{u..v}. (g has_vector_derivative f x) (at x within {u..v})"
  1.2579        apply(rule,rule has_vector_derivative_within_subset) apply(rule g[rule_format]) using goal1(1-2) by auto
  1.2580 -    thus ?case using fundamental_theorem_of_calculus[OF goal1(3),of "g o dest_vec1" "f o dest_vec1"]
  1.2581 -      unfolding o_def vec1_dest_vec1 by auto qed qed
  1.2582 +    thus ?case using fundamental_theorem_of_calculus[OF goal1(3),of "g" "f"] by auto qed qed
  1.2583  
  1.2584  subsection {* General "twiddling" for interval-to-interval function image. *}
  1.2585  
  1.2586 @@ -3206,34 +3250,33 @@
  1.2587  
  1.2588  subsection {* Special case of a basic affine transformation. *}
  1.2589  
  1.2590 -lemma interval_image_affinity_interval: shows "\<exists>u v. (\<lambda>x. m *\<^sub>R (x::real^'n) + c) ` {a..b} = {u..v}"
  1.2591 +lemma interval_image_affinity_interval: shows "\<exists>u v. (\<lambda>x. m *\<^sub>R (x::'a::ordered_euclidean_space) + c) ` {a..b} = {u..v}"
  1.2592    unfolding image_affinity_interval by auto
  1.2593  
  1.2594 -lemmas Cart_simps = Cart_nth.add Cart_nth.minus Cart_nth.zero Cart_nth.diff Cart_nth.scaleR real_scaleR_def Cart_lambda_beta
  1.2595 -   Cart_eq vector_le_def vector_less_def
  1.2596 -
  1.2597  lemma setprod_cong2: assumes "\<And>x. x \<in> A \<Longrightarrow> f x = g x" shows "setprod f A = setprod g A"
  1.2598    apply(rule setprod_cong) using assms by auto
  1.2599  
  1.2600  lemma content_image_affinity_interval: 
  1.2601 - "content((\<lambda>x::real^'n. m *\<^sub>R x + c) ` {a..b}) = (abs m) ^ CARD('n) * content {a..b}" (is "?l = ?r")
  1.2602 + "content((\<lambda>x::'a::ordered_euclidean_space. m *\<^sub>R x + c) ` {a..b}) = (abs m) ^ DIM('a) * content {a..b}" (is "?l = ?r")
  1.2603  proof- { presume *:"{a..b}\<noteq>{} \<Longrightarrow> ?thesis" show ?thesis apply(cases,rule *,assumption)
  1.2604        unfolding not_not using content_empty by auto }
  1.2605 +  have *:"DIM('a) = card {..<DIM('a)}" by auto
  1.2606    assume as:"{a..b}\<noteq>{}" show ?thesis proof(cases "m \<ge> 0")
  1.2607      case True show ?thesis unfolding image_affinity_interval if_not_P[OF as] if_P[OF True]
  1.2608 -      unfolding content_closed_interval'[OF as] apply(subst content_closed_interval') 
  1.2609 -      defer apply(subst setprod_constant[THEN sym]) apply(rule finite_UNIV) unfolding setprod_timesf[THEN sym]
  1.2610 -      apply(rule setprod_cong2) using True as unfolding interval_ne_empty Cart_simps not_le  
  1.2611 +      unfolding content_closed_interval'[OF as] apply(subst content_closed_interval') defer apply(subst(2) *)
  1.2612 +      apply(subst setprod_constant[THEN sym]) apply(rule finite_lessThan) unfolding setprod_timesf[THEN sym]
  1.2613 +      apply(rule setprod_cong2) using True as unfolding interval_ne_empty euclidean_simps not_le  
  1.2614        by(auto simp add:field_simps intro:mult_left_mono)
  1.2615    next case False show ?thesis unfolding image_affinity_interval if_not_P[OF as] if_not_P[OF False]
  1.2616 -      unfolding content_closed_interval'[OF as] apply(subst content_closed_interval') 
  1.2617 -      defer apply(subst setprod_constant[THEN sym]) apply(rule finite_UNIV) unfolding setprod_timesf[THEN sym]
  1.2618 -      apply(rule setprod_cong2) using False as unfolding interval_ne_empty Cart_simps not_le 
  1.2619 +      unfolding content_closed_interval'[OF as] apply(subst content_closed_interval') defer apply(subst(2) *)
  1.2620 +      apply(subst setprod_constant[THEN sym]) apply(rule finite_lessThan) unfolding setprod_timesf[THEN sym]
  1.2621 +      apply(rule setprod_cong2) using False as unfolding interval_ne_empty euclidean_simps not_le 
  1.2622        by(auto simp add:field_simps mult_le_cancel_left_neg) qed qed
  1.2623  
  1.2624 -lemma has_integral_affinity: assumes "(f has_integral i) {a..b::real^'n}" "m \<noteq> 0"
  1.2625 -  shows "((\<lambda>x. f(m *\<^sub>R x + c)) has_integral ((1 / (abs(m) ^ CARD('n::finite))) *\<^sub>R i)) ((\<lambda>x. (1 / m) *\<^sub>R x + -((1 / m) *\<^sub>R c)) ` {a..b})"
  1.2626 -  apply(rule has_integral_twiddle,safe) unfolding Cart_eq Cart_simps apply(rule zero_less_power)
  1.2627 +lemma has_integral_affinity: fixes a::"'a::ordered_euclidean_space" assumes "(f has_integral i) {a..b}" "m \<noteq> 0"
  1.2628 +  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})"
  1.2629 +  apply(rule has_integral_twiddle,safe) apply(rule zero_less_power) unfolding euclidean_eq[where 'a='a]
  1.2630 +  unfolding scaleR_right_distrib euclidean_simps scaleR.scaleR_left[THEN sym]
  1.2631    defer apply(insert assms(2), simp add:field_simps) apply(insert assms(2), simp add:field_simps)
  1.2632    apply(rule continuous_intros)+ apply(rule interval_image_affinity_interval)+ apply(rule content_image_affinity_interval) using assms by auto
  1.2633  
  1.2634 @@ -3244,64 +3287,68 @@
  1.2635  subsection {* Special case of stretching coordinate axes separately. *}
  1.2636  
  1.2637  lemma image_stretch_interval:
  1.2638 -  "(\<lambda>x. \<chi> k. m k * x$k) ` {a..b::real^'n} =
  1.2639 -  (if {a..b} = {} then {} else {(\<chi> k. min (m(k) * a$k) (m(k) * b$k)) ..  (\<chi> k. max (m(k) * a$k) (m(k) * b$k))})" (is "?l = ?r")
  1.2640 +  "(\<lambda>x. \<chi>\<chi> k. m k * x$$k) ` {a..b::'a::ordered_euclidean_space} =
  1.2641 +  (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))})"
  1.2642 +  (is "?l = ?r")
  1.2643  proof(cases "{a..b}={}") case True thus ?thesis unfolding True by auto
  1.2644 -next have *:"\<And>P Q. (\<forall>i. P i) \<and> (\<forall>i. Q i) \<longleftrightarrow> (\<forall>i. P i \<and> Q i)" by auto
  1.2645 +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
  1.2646    case False note ab = this[unfolded interval_ne_empty]
  1.2647    show ?thesis apply-apply(rule set_ext)
  1.2648 -  proof- fix x::"real^'n" have **:"\<And>P Q. (\<forall>i. P i = Q i) \<Longrightarrow> (\<forall>i. P i) = (\<forall>i. Q i)" by auto
  1.2649 +  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
  1.2650      show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" unfolding if_not_P[OF False] 
  1.2651 -      unfolding image_iff mem_interval Bex_def Cart_simps Cart_eq *
  1.2652 -      unfolding lambda_skolem[THEN sym,of "\<lambda> i xa. (a $ i \<le> xa \<and> xa \<le> b $ i) \<and> x $ i = m i * xa"]
  1.2653 -    proof(rule **,rule) fix i::'n show "(\<exists>xa. (a $ i \<le> xa \<and> xa \<le> b $ i) \<and> x $ i = m i * xa) =
  1.2654 -        (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))"
  1.2655 -      proof(cases "m i = 0") case True thus ?thesis using ab by auto
  1.2656 +      unfolding image_iff mem_interval Bex_def euclidean_simps euclidean_eq[where 'a='a] *
  1.2657 +      unfolding imp_conjR[THEN sym] apply(subst euclidean_lambda_beta'') apply(subst lambda_skolem'[THEN sym])
  1.2658 +      apply(rule **,rule,rule) unfolding euclidean_lambda_beta'
  1.2659 +    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) =
  1.2660 +        (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))"
  1.2661 +      proof(cases "m i = 0") case True thus ?thesis using ab i by auto
  1.2662        next case False hence "0 < m i \<or> 0 > m i" by auto thus ?thesis apply-
  1.2663 -        proof(erule disjE) assume as:"0 < m i" hence *:"min (m i * a $ i) (m i * b $ i) = m i * a $ i"
  1.2664 -            "max (m i * a $ i) (m i * b $ i) = m i * b $ i" using ab unfolding min_def max_def by auto
  1.2665 -          show ?thesis unfolding * apply rule defer apply(rule_tac x="1 / m i * x$i" in exI)
  1.2666 +        proof(erule disjE) assume as:"0 < m i" hence *:"min (m i * a $$ i) (m i * b $$ i) = m i * a $$ i"
  1.2667 +            "max (m i * a $$ i) (m i * b $$ i) = m i * b $$ i" using ab i unfolding min_def max_def by auto
  1.2668 +          show ?thesis unfolding * apply rule defer apply(rule_tac x="1 / m i * x$$i" in exI)
  1.2669              using as by(auto simp add:field_simps)
  1.2670 -        next assume as:"0 > m i" hence *:"max (m i * a $ i) (m i * b $ i) = m i * a $ i"
  1.2671 -            "min (m i * a $ i) (m i * b $ i) = m i * b $ i" using ab as unfolding min_def max_def 
  1.2672 +        next assume as:"0 > m i" hence *:"max (m i * a $$ i) (m i * b $$ i) = m i * a $$ i"
  1.2673 +            "min (m i * a $$ i) (m i * b $$ i) = m i * b $$ i" using ab as i unfolding min_def max_def 
  1.2674              by(auto simp add:field_simps mult_le_cancel_left_neg intro: order_antisym)
  1.2675 -          show ?thesis unfolding * apply rule defer apply(rule_tac x="1 / m i * x$i" in exI)
  1.2676 +          show ?thesis unfolding * apply rule defer apply(rule_tac x="1 / m i * x$$i" in exI)
  1.2677              using as by(auto simp add:field_simps) qed qed qed qed qed 
  1.2678  
  1.2679 -lemma interval_image_stretch_interval: "\<exists>u v. (\<lambda>x. \<chi> k. m k * x$k) ` {a..b::real^'n} = {u..v}"
  1.2680 +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}"
  1.2681    unfolding image_stretch_interval by auto 
  1.2682  
  1.2683  lemma content_image_stretch_interval:
  1.2684 -  "content((\<lambda>x::real^'n. \<chi> k. m k * x$k) ` {a..b}) = abs(setprod m UNIV) * content({a..b})"
  1.2685 +  "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})"
  1.2686  proof(cases "{a..b} = {}") case True thus ?thesis
  1.2687      unfolding content_def image_is_empty image_stretch_interval if_P[OF True] by auto
  1.2688 -next case False hence "(\<lambda>x. \<chi> k. m k * x $ k) ` {a..b} \<noteq> {}" by auto
  1.2689 +next case False hence "(\<lambda>x. (\<chi>\<chi> k. m k * x $$ k)::'a) ` {a..b} \<noteq> {}" by auto
  1.2690    thus ?thesis using False unfolding content_def image_stretch_interval apply- unfolding interval_bounds' if_not_P
  1.2691 -    unfolding abs_setprod setprod_timesf[THEN sym] apply(rule setprod_cong2) unfolding Cart_lambda_beta
  1.2692 -  proof- fix i::'n have "(m i < 0 \<or> m i > 0) \<or> m i = 0" by auto
  1.2693 -    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)"
  1.2694 -      apply-apply(erule disjE)+ unfolding min_def max_def using False[unfolded interval_ne_empty,rule_format,of i] 
  1.2695 +    unfolding abs_setprod setprod_timesf[THEN sym] apply(rule setprod_cong2) unfolding lessThan_iff euclidean_lambda_beta'
  1.2696 +  proof- fix i assume i:"i<DIM('a)" have "(m i < 0 \<or> m i > 0) \<or> m i = 0" by auto
  1.2697 +    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)"
  1.2698 +      apply-apply(erule disjE)+ unfolding min_def max_def using False[unfolded interval_ne_empty,rule_format,of i] i 
  1.2699        by(auto simp add:field_simps not_le mult_le_cancel_left_neg mult_le_cancel_left_pos) qed qed
  1.2700  
  1.2701 -lemma has_integral_stretch: assumes "(f has_integral i) {a..b}" "\<forall>k. ~(m k = 0)"
  1.2702 -  shows "((\<lambda>x. f(\<chi> k. m k * x$k)) has_integral
  1.2703 -             ((1/(abs(setprod m UNIV))) *\<^sub>R i)) ((\<lambda>x. \<chi> k. 1/(m k) * x$k) ` {a..b})"
  1.2704 -  apply(rule has_integral_twiddle) unfolding zero_less_abs_iff content_image_stretch_interval
  1.2705 -  unfolding image_stretch_interval empty_as_interval Cart_eq using assms
  1.2706 -proof- show "\<forall>x. continuous (at x) (\<lambda>x. \<chi> k. m k * x $ k)"
  1.2707 +lemma has_integral_stretch: fixes f::"'a::ordered_euclidean_space => 'b::real_normed_vector"
  1.2708 +  assumes "(f has_integral i) {a..b}" "\<forall>k<DIM('a). ~(m k = 0)"
  1.2709 +  shows "((\<lambda>x. f(\<chi>\<chi> k. m k * x$$k)) has_integral
  1.2710 +             ((1/(abs(setprod m {..<DIM('a)}))) *\<^sub>R i)) ((\<lambda>x. (\<chi>\<chi> k. 1/(m k) * x$$k)::'a) ` {a..b})"
  1.2711 +  apply(rule has_integral_twiddle[where f=f]) unfolding zero_less_abs_iff content_image_stretch_interval
  1.2712 +  unfolding image_stretch_interval empty_as_interval euclidean_eq[where 'a='a] using assms
  1.2713 +proof- show "\<forall>y::'a. continuous (at y) (\<lambda>x. (\<chi>\<chi> k. m k * x $$ k)::'a)"
  1.2714     apply(rule,rule linear_continuous_at) unfolding linear_linear
  1.2715 -   unfolding linear_def Cart_simps Cart_eq by(auto simp add:field_simps) qed auto
  1.2716 -
  1.2717 -lemma integrable_stretch: 
  1.2718 -  assumes "f integrable_on {a..b}" "\<forall>k. ~(m k = 0)"
  1.2719 -  shows "(\<lambda>x. f(\<chi> k. m k * x$k)) integrable_on ((\<lambda>x. \<chi> k. 1/(m k) * x$k) ` {a..b})"
  1.2720 -  using assms unfolding integrable_on_def apply-apply(erule exE) apply(drule has_integral_stretch) by auto
  1.2721 +   unfolding linear_def euclidean_simps euclidean_eq[where 'a='a] by(auto simp add:field_simps) qed auto
  1.2722 +
  1.2723 +lemma integrable_stretch:  fixes f::"'a::ordered_euclidean_space => 'b::real_normed_vector"
  1.2724 +  assumes "f integrable_on {a..b}" "\<forall>k<DIM('a). ~(m k = 0)"
  1.2725 +  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})"
  1.2726 +  using assms unfolding integrable_on_def apply-apply(erule exE) 
  1.2727 +  apply(drule has_integral_stretch,assumption) by auto
  1.2728  
  1.2729  subsection {* even more special cases. *}
  1.2730  
  1.2731 -lemma uminus_interval_vector[simp]:"uminus ` {a..b} = {-b .. -a::real^'n}"
  1.2732 +lemma uminus_interval_vector[simp]:"uminus ` {a..b} = {-b .. -a::'a::ordered_euclidean_space}"
  1.2733    apply(rule set_ext,rule) defer unfolding image_iff
  1.2734 -  apply(rule_tac x="-x" in bexI) by(auto simp add:vector_le_def minus_le_iff le_minus_iff)
  1.2735 +  apply(rule_tac x="-x" in bexI) by(auto simp add:minus_le_iff le_minus_iff eucl_le[where 'a='a])
  1.2736  
  1.2737  lemma has_integral_reflect_lemma[intro]: assumes "(f has_integral i) {a..b}"
  1.2738    shows "((\<lambda>x. f(-x)) has_integral i) {-b .. -a}"
  1.2739 @@ -3318,16 +3365,12 @@
  1.2740  
  1.2741  subsection {* Stronger form of FCT; quite a tedious proof. *}
  1.2742  
  1.2743 -(** move this **)
  1.2744 -declare norm_triangle_ineq4[intro] 
  1.2745 -
  1.2746  lemma bgauge_existence_lemma: "(\<forall>x\<in>s. \<exists>d::real. 0 < d \<and> q d x) \<longleftrightarrow> (\<forall>x. \<exists>d>0. x\<in>s \<longrightarrow> q d x)" by(meson zero_less_one)
  1.2747  
  1.2748  lemma additive_tagged_division_1': fixes f::"real \<Rightarrow> 'a::real_normed_vector"
  1.2749 -  assumes "a \<le> b" "p tagged_division_of {vec1 a..vec1 b}"
  1.2750 -  shows "setsum (\<lambda>(x,k). f (dest_vec1 (interval_upperbound k)) - f(dest_vec1 (interval_lowerbound k))) p = f b - f a"
  1.2751 -  using additive_tagged_division_1[OF _ assms(2), of "f o dest_vec1"]
  1.2752 -  unfolding o_def vec1_dest_vec1 using assms(1) by auto
  1.2753 +  assumes "a \<le> b" "p tagged_division_of {a..b}"
  1.2754 +  shows "setsum (\<lambda>(x,k). f (interval_upperbound k) - f(interval_lowerbound k)) p = f b - f a"
  1.2755 +  using additive_tagged_division_1[OF _ assms(2), of f] using assms(1) by auto
  1.2756  
  1.2757  lemma split_minus[simp]:"(\<lambda>(x, k). f x k) x - (\<lambda>(x, k). g x k) x = (\<lambda>(x, k). f x k - g x k) x"
  1.2758    unfolding split_def by(rule refl)
  1.2759 @@ -3336,17 +3379,17 @@
  1.2760    apply(subst(asm)(2) norm_minus_cancel[THEN sym])
  1.2761    apply(drule norm_triangle_le) by(auto simp add:algebra_simps)
  1.2762  
  1.2763 -lemma fundamental_theorem_of_calculus_interior:
  1.2764 +lemma fundamental_theorem_of_calculus_interior: fixes f::"real => 'a::real_normed_vector"
  1.2765    assumes"a \<le> b" "continuous_on {a..b} f" "\<forall>x\<in>{a<..<b}. (f has_vector_derivative f'(x)) (at x)"
  1.2766 -  shows "((f' o dest_vec1) has_integral (f b - f a)) {vec a..vec b}"
  1.2767 +  shows "(f' has_integral (f b - f a)) {a..b}"
  1.2768  proof- { presume *:"a < b \<Longrightarrow> ?thesis" 
  1.2769      show ?thesis proof(cases,rule *,assumption)
  1.2770        assume "\<not> a < b" hence "a = b" using assms(1) by auto
  1.2771 -      hence *:"{vec a .. vec b} = {vec b}" "f b - f a = 0" by(auto simp add: Cart_eq vector_le_def order_antisym)
  1.2772 -      show ?thesis unfolding *(2) apply(rule has_integral_null) unfolding content_eq_0_1 using * `a=b` by auto
  1.2773 +      hence *:"{a .. b} = {b}" "f b - f a = 0" by(auto simp add:  order_antisym)
  1.2774 +      show ?thesis unfolding *(2) apply(rule has_integral_null) unfolding content_eq_0 using * `a=b` by auto
  1.2775      qed } assume ab:"a < b"
  1.2776 -  let ?P = "\<lambda>e. \<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {vec1 a..vec1 b} \<and> d fine p \<longrightarrow>
  1.2777 -                   norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R (f' \<circ> dest_vec1) x) - (f b - f a)) \<le> e * content {vec1 a..vec1 b})"
  1.2778 +  let ?P = "\<lambda>e. \<exists>d. gauge d \<and> (\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow>
  1.2779 +                   norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f' x) - (f b - f a)) \<le> e * content {a..b})"
  1.2780    { presume "\<And>e. e>0 \<Longrightarrow> ?P e" thus ?thesis unfolding has_integral_factor_content by auto }
  1.2781    fix e::real assume e:"e>0"
  1.2782    note assms(3)[unfolded has_vector_derivative_def has_derivative_at_alt ball_conj_distrib]
  1.2783 @@ -3354,11 +3397,11 @@
  1.2784    from this(2) have "\<forall>x\<in>{a<..<b}. \<exists>d>0. \<forall>y. norm (y - x) < d \<longrightarrow> norm (f y - f x - (y - x) *\<^sub>R f' x) \<le> e/2 * norm (y - x)"
  1.2785      apply-apply safe apply(erule_tac x=x in ballE,erule_tac x="e/2" in allE) using e by auto note this[unfolded bgauge_existence_lemma]
  1.2786    from choice[OF this] guess d .. note conjunctD2[OF this[rule_format]] note d = this[rule_format]
  1.2787 -  have "bounded (f ` {a..b})" apply(rule compact_imp_bounded compact_continuous_image)+ using compact_real_interval assms by auto
  1.2788 +  have "bounded (f ` {a..b})" apply(rule compact_imp_bounded compact_continuous_image)+ using compact_interval assms by auto
  1.2789    from this[unfolded bounded_pos] guess B .. note B = this[rule_format]
  1.2790  
  1.2791    have "\<exists>da. 0 < da \<and> (\<forall>c. a \<le> c \<and> {a..c} \<subseteq> {a..b} \<and> {a..c} \<subseteq> ball a da
  1.2792 -    \<longrightarrow> norm(content {vec1 a..vec1 c} *\<^sub>R f' a - (f c - f a)) \<le> (e * (b - a)) / 4)"
  1.2793 +    \<longrightarrow> norm(content {a..c} *\<^sub>R f' a - (f c - f a)) \<le> (e * (b - a)) / 4)"
  1.2794    proof- have "a\<in>{a..b}" using ab by auto
  1.2795      note assms(2)[unfolded continuous_on_eq_continuous_within,rule_format,OF this]
  1.2796      note * = this[unfolded continuous_within Lim_within,rule_format] have "(e * (b - a)) / 8 > 0" using e ab by(auto simp add:field_simps)
  1.2797 @@ -3366,9 +3409,8 @@
  1.2798      have "\<exists>l. 0 < l \<and> norm(l *\<^sub>R f' a) \<le> (e * (b - a)) / 8"
  1.2799      proof(cases "f' a = 0") case True
  1.2800        thus ?thesis apply(rule_tac x=1 in exI) using ab e by(auto intro!:mult_nonneg_nonneg) 
  1.2801 -    next case False thus ?thesis 
  1.2802 -        apply(rule_tac x="(e * (b - a)) / 8 / norm (f' a)" in exI)
  1.2803 -        using ab e by(auto simp add:field_simps)
  1.2804 +    next case False thus ?thesis
  1.2805 +        apply(rule_tac x="(e * (b - a)) / 8 / norm (f' a)" in exI) using ab e by(auto simp add:field_simps) 
  1.2806      qed then guess l .. note l = conjunctD2[OF this]
  1.2807      show ?thesis apply(rule_tac x="min k l" in exI) apply safe unfolding min_less_iff_conj apply(rule,(rule l k)+)
  1.2808      proof- fix c assume as:"a \<le> c" "{a..c} \<subseteq> {a..b}" "{a..c} \<subseteq> ball a (min k l)" 
  1.2809 @@ -3379,13 +3421,16 @@
  1.2810          thus ?case apply-apply(rule order_trans[OF _ l(2)]) unfolding norm_scaleR apply(rule mult_right_mono) by auto
  1.2811        next case goal2 show ?case apply(rule less_imp_le) apply(cases "a = c") defer
  1.2812            apply(rule k(2)[unfolded dist_norm]) using as' e ab by(auto simp add:field_simps)
  1.2813 -      qed finally show "norm (content {vec1 a..vec1 c} *\<^sub>R f' a - (f c - f a)) \<le> e * (b - a) / 4" unfolding content_1'[OF as(1)] by auto
  1.2814 +      qed finally show "norm (content {a..c} *\<^sub>R f' a - (f c - f a)) \<le> e * (b - a) / 4"
  1.2815 +        unfolding content_real[OF as(1)] by auto
  1.2816      qed qed then guess da .. note da=conjunctD2[OF this,rule_format]
  1.2817  
  1.2818 -  have "\<exists>db>0. \<forall>c\<le>b. {c..b} \<subseteq> {a..b} \<and> {c..b} \<subseteq> ball b db \<longrightarrow> norm(content {vec1 c..vec1 b} *\<^sub>R f' b - (f b - f c)) \<le> (e * (b - a)) / 4"
  1.2819 +  have "\<exists>db>0. \<forall>c\<le>b. {c..b} \<subseteq> {a..b} \<and> {c..b} \<subseteq> ball b db \<longrightarrow>
  1.2820 +    norm(content {c..b} *\<^sub>R f' b - (f b - f c)) \<le> (e * (b - a)) / 4"
  1.2821    proof- have "b\<in>{a..b}" using ab by auto
  1.2822      note assms(2)[unfolded continuous_on_eq_continuous_within,rule_format,OF this]
  1.2823 -    note * = this[unfolded continuous_within Lim_within,rule_format] have "(e * (b - a)) / 8 > 0" using e ab by(auto simp add:field_simps)
  1.2824 +    note * = this[unfolded continuous_within Lim_within,rule_format] have "(e * (b - a)) / 8 > 0"
  1.2825 +      using e ab by(auto simp add:field_simps)
  1.2826      from *[OF this] guess k .. note k = conjunctD2[OF this,rule_format]
  1.2827      have "\<exists>l. 0 < l \<and> norm(l *\<^sub>R f' b) \<le> (e * (b - a)) / 8"
  1.2828      proof(cases "f' b = 0") case True
  1.2829 @@ -3403,129 +3448,137 @@
  1.2830          thus ?case apply-apply(rule order_trans[OF _ l(2)]) unfolding norm_scaleR apply(rule mult_right_mono) by auto
  1.2831        next case goal2 show ?case apply(rule less_imp_le) apply(cases "b = c") defer apply(subst norm_minus_commute)
  1.2832            apply(rule k(2)[unfolded dist_norm]) using as' e ab by(auto simp add:field_simps)
  1.2833 -      qed finally show "norm (content {vec1 c..vec1 b} *\<^sub>R f' b - (f b - f c)) \<le> e * (b - a) / 4" unfolding content_1'[OF as(1)] by auto
  1.2834 +      qed finally show "norm (content {c..b} *\<^sub>R f' b - (f b - f c)) \<le> e * (b - a) / 4"
  1.2835 +        unfolding content_real[OF as(1)] by auto
  1.2836      qed qed then guess db .. note db=conjunctD2[OF this,rule_format]
  1.2837  
  1.2838 -  let ?d = "(\<lambda>x. ball x (if x=vec1 a then da else if x=vec b then db else d (dest_vec1 x)))"
  1.2839 +  let ?d = "(\<lambda>x. ball x (if x=a then da else if x=b then db else d x))"
  1.2840    show "?P e" apply(rule_tac x="?d" in exI)
  1.2841    proof safe case goal1 show ?case apply(rule gauge_ball_dependent) using ab db(1) da(1) d(1) by auto
  1.2842 -  next case goal2 note as=this let ?A = "{t. fst t \<in> {vec1 a, vec1 b}}" note p = tagged_division_ofD[OF goal2(1)]
  1.2843 +  next case goal2 note as=this let ?A = "{t. fst t \<in> {a, b}}" note p = tagged_division_ofD[OF goal2(1)]
  1.2844      have pA:"p = (p \<inter> ?A) \<union> (p - ?A)" "finite (p \<inter> ?A)" "finite (p - ?A)" "(p \<inter> ?A) \<inter> (p - ?A) = {}"  using goal2 by auto
  1.2845      note * = additive_tagged_division_1'[OF assms(1) goal2(1), THEN sym]
  1.2846      have **:"\<And>n1 s1 n2 s2::real. n2 \<le> s2 / 2 \<Longrightarrow> n1 - s1 \<le> s2 / 2 \<Longrightarrow> n1 + n2 \<le> s1 + s2" by arith
  1.2847 -    show ?case unfolding content_1'[OF assms(1)] and *[of "\<lambda>x. x"] *[of f] setsum_subtractf[THEN sym] split_minus
  1.2848 +    show ?case unfolding content_real[OF assms(1)] and *[of "\<lambda>x. x"] *[of f] setsum_subtractf[THEN sym] split_minus
  1.2849        unfolding setsum_right_distrib apply(subst(2) pA,subst pA) unfolding setsum_Un_disjoint[OF pA(2-)]
  1.2850      proof(rule norm_triangle_le,rule **) 
  1.2851        case goal1 show ?case apply(rule order_trans,rule setsum_norm_le) apply(rule pA) defer apply(subst divide.setsum)
  1.2852        proof(rule order_refl,safe,unfold not_le o_def split_conv fst_conv,rule ccontr) fix x k assume as:"(x,k) \<in> p"
  1.2853 -          "e * (dest_vec1 (interval_upperbound k) - dest_vec1 (interval_lowerbound k)) / 2
  1.2854 -          < norm (content k *\<^sub>R f' (dest_vec1 x) - (f (dest_vec1 (interval_upperbound k)) - f (dest_vec1 (interval_lowerbound k))))"
  1.2855 +          "e * (interval_upperbound k -  interval_lowerbound k) / 2
  1.2856 +          < norm (content k *\<^sub>R f' x - (f (interval_upperbound k) - f (interval_lowerbound k)))"
  1.2857          from p(4)[OF this(1)] guess u v apply-by(erule exE)+ note k=this
  1.2858 -        hence "\<forall>i. u$i \<le> v$i" and uv:"{u,v}\<subseteq>{u..v}" using p(2)[OF as(1)] by auto note this(1) this(1)[unfolded forall_1]
  1.2859 -        note result = as(2)[unfolded k interval_bounds[OF this(1)] content_1[OF this(2)]]
  1.2860 -
  1.2861 -        assume as':"x \<noteq> vec1 a" "x \<noteq> vec1 b" hence "x$1 \<in> {a<..<b}" using p(2-3)[OF as(1)] by(auto simp add: Cart_eq) note  * = d(2)[OF this]
  1.2862 -        have "norm ((v$1 - u$1) *\<^sub>R f' (x$1) - (f (v$1) - f (u$1))) =
  1.2863 -          norm ((f (u$1) - f (x$1) - (u$1 - x$1) *\<^sub>R f' (x$1)) - (f (v$1) - f (x$1) - (v$1 - x$1) *\<^sub>R f' (x$1)))" 
  1.2864 +        hence "u \<le> v" and uv:"{u,v}\<subseteq>{u..v}" using p(2)[OF as(1)] by auto
  1.2865 +        note result = as(2)[unfolded k interval_bounds_real[OF this(1)] content_real[OF this(1)]]
  1.2866 +
  1.2867 +        assume as':"x \<noteq> a" "x \<noteq> b" hence "x \<in> {a<..<b}" using p(2-3)[OF as(1)] by auto
  1.2868 +        note  * = d(2)[OF this]
  1.2869 +        have "norm ((v - u) *\<^sub>R f' (x) - (f (v) - f (u))) =
  1.2870 +          norm ((f (u) - f (x) - (u - x) *\<^sub>R f' (x)) - (f (v) - f (x) - (v - x) *\<^sub>R f' (x)))" 
  1.2871            apply(rule arg_cong[of _ _ norm]) unfolding scaleR_left.diff by auto 
  1.2872 -        also have "... \<le> e / 2 * norm (u$1 - x$1) + e / 2 * norm (v$1 - x$1)" apply(rule norm_triangle_le_sub)
  1.2873 +        also have "... \<le> e / 2 * norm (u - x) + e / 2 * norm (v - x)" apply(rule norm_triangle_le_sub)
  1.2874            apply(rule add_mono) apply(rule_tac[!] *) using fineD[OF goal2(2) as(1)] as' unfolding k subset_eq
  1.2875 -          apply- apply(erule_tac x=u in ballE,erule_tac[3] x=v in ballE) using uv by(auto simp add:dist_real)
  1.2876 -        also have "... \<le> e / 2 * norm (v$1 - u$1)" using p(2)[OF as(1)] unfolding k by(auto simp add:field_simps)
  1.2877 -        finally have "e * (dest_vec1 v - dest_vec1 u) / 2 < e * (dest_vec1 v - dest_vec1 u) / 2"
  1.2878 +          apply- apply(erule_tac x=u in ballE,erule_tac[3] x=v in ballE) using uv by(auto simp:dist_real_def)
  1.2879 +        also have "... \<le> e / 2 * norm (v - u)" using p(2)[OF as(1)] unfolding k by(auto simp add:field_simps)
  1.2880 +        finally have "e * (v - u) / 2 < e * (v - u) / 2"
  1.2881            apply- apply(rule less_le_trans[OF result]) using uv by auto thus False by auto qed
  1.2882  
  1.2883      next have *:"\<And>x s1 s2::real. 0 \<le> s1 \<Longrightarrow> x \<le> (s1 + s2) / 2 \<Longrightarrow> x - s1 \<le> s2 / 2" by auto
  1.2884        case goal2 show ?case apply(rule *) apply(rule setsum_nonneg) apply(rule,unfold split_paired_all split_conv)
  1.2885          defer unfolding setsum_Un_disjoint[OF pA(2-),THEN sym] pA(1)[THEN sym] unfolding setsum_right_distrib[THEN sym] 
  1.2886 -        apply(subst additive_tagged_division_1[OF _ as(1)]) unfolding vec1_dest_vec1 apply(rule assms)
  1.2887 -      proof- fix x k assume "(x,k) \<in> p \<inter> {t. fst t \<in> {vec1 a, vec1 b}}" note xk=IntD1[OF this]
  1.2888 +        apply(subst additive_tagged_division_1[OF _ as(1)]) apply(rule assms)
  1.2889 +      proof- fix x k assume "(x,k) \<in> p \<inter> {t. fst t \<in> {a, b}}" note xk=IntD1[OF this]
  1.2890          from p(4)[OF this] guess u v apply-by(erule exE)+ note uv=this
  1.2891          with p(2)[OF xk] have "{u..v} \<noteq> {}" by auto
  1.2892 -        thus "0 \<le> e * ((interval_upperbound k)$1 - (interval_lowerbound k)$1)"
  1.2893 +        thus "0 \<le> e * ((interval_upperbound k) - (interval_lowerbound k))"
  1.2894            unfolding uv using e by(auto simp add:field_simps)
  1.2895        next have *:"\<And>s f t e. setsum f s = setsum f t \<Longrightarrow> norm(setsum f t) \<le> e \<Longrightarrow> norm(setsum f s) \<le> e" by auto
  1.2896 -        show "norm (\<Sum>(x, k)\<in>p \<inter> ?A. content k *\<^sub>R (f' \<circ> dest_vec1) x -
  1.2897 -          (f ((interval_upperbound k)$1) - f ((interval_lowerbound k)$1))) \<le> e * (b - a) / 2" 
  1.2898 -          apply(rule *[where t="p \<inter> {t. fst t \<in> {vec1 a, vec1 b} \<and> content(snd t) \<noteq> 0}"])
  1.2899 +        show "norm (\<Sum>(x, k)\<in>p \<inter> ?A. content k *\<^sub>R f' x -
  1.2900 +          (f ((interval_upperbound k)) - f ((interval_lowerbound k)))) \<le> e * (b - a) / 2" 
  1.2901 +          apply(rule *[where t="p \<inter> {t. fst t \<in> {a, b} \<and> content(snd t) \<noteq> 0}"])
  1.2902            apply(rule setsum_mono_zero_right[OF pA(2)]) defer apply(rule) unfolding split_paired_all split_conv o_def
  1.2903 -        proof- fix x k assume "(x,k) \<in> p \<inter> {t. fst t \<in> {vec1 a, vec1 b}} - p \<inter> {t. fst t \<in> {vec1 a, vec1 b} \<and> content (snd t) \<noteq> 0}"
  1.2904 +        proof- fix x k assume "(x,k) \<in> p \<inter> {t. fst t \<in> {a, b}} - p \<inter> {t. fst t \<in> {a, b} \<and> content (snd t) \<noteq> 0}"
  1.2905            hence xk:"(x,k)\<in>p" "content k = 0" by auto from p(4)[OF xk(1)] guess u v apply-by(erule exE)+ note uv=this
  1.2906 -          have "k\<noteq>{}" using p(2)[OF xk(1)] by auto hence *:"u = v" using xk unfolding uv content_eq_0_1 interval_eq_empty by auto
  1.2907 -          thus "content k *\<^sub>R (f' (x$1)) - (f ((interval_upperbound k)$1) - f ((interval_lowerbound k)$1)) = 0" using xk unfolding uv by auto
  1.2908 -        next have *:"p \<inter> {t. fst t \<in> {vec1 a, vec1 b} \<and> content(snd t) \<noteq> 0} = 
  1.2909 -            {t. t\<in>p \<and> fst t = vec1 a \<and> content(snd t) \<noteq> 0} \<union> {t. t\<in>p \<and> fst t = vec1 b \<and> content(snd t) \<noteq> 0}" by blast
  1.2910 -          have **:"\<And>s f. \<And>e::real. (\<forall>x y. x \<in> s \<and> y \<in> s \<longrightarrow> x = y) \<Longrightarrow> (\<forall>x. x \<in> s \<longrightarrow> norm(f x) \<le> e) \<Longrightarrow> e>0 \<Longrightarrow> norm(setsum f s) \<le> e"
  1.2911 +          have "k\<noteq>{}" using p(2)[OF xk(1)] by auto hence *:"u = v" using xk
  1.2912 +            unfolding uv content_eq_0 interval_eq_empty by auto
  1.2913 +          thus "content k *\<^sub>R (f' (x)) - (f ((interval_upperbound k)) - f ((interval_lowerbound k))) = 0" using xk unfolding uv by auto
  1.2914 +        next have *:"p \<inter> {t. fst t \<in> {a, b} \<and> content(snd t) \<noteq> 0} = 
  1.2915 +            {t. t\<in>p \<and> fst t = a \<and> content(snd t) \<noteq> 0} \<union> {t. t\<in>p \<and> fst t = b \<and> content(snd t) \<noteq> 0}" by blast
  1.2916 +          have **:"\<And>s f. \<And>e::real. (\<forall>x y. x \<in> s \<and> y \<in> s \<longrightarrow> x = y) \<Longrightarrow> (\<forall>x. x \<in> s \<longrightarrow> norm(f x) \<le> e)
  1.2917 +            \<Longrightarrow> e>0 \<Longrightarrow> norm(setsum f s) \<le> e"
  1.2918            proof(case_tac "s={}") case goal2 then obtain x where "x\<in>s" by auto hence *:"s = {x}" using goal2(1) by auto
  1.2919              thus ?case using `x\<in>s` goal2(2) by auto
  1.2920            qed auto
  1.2921 -          case goal2 show ?case apply(subst *, subst setsum_Un_disjoint) prefer 4 apply(rule order_trans[of _ "e * (b - a)/4 + e * (b - a)/4"]) 
  1.2922 +          case goal2 show ?case apply(subst *, subst setsum_Un_disjoint) prefer 4
  1.2923 +            apply(rule order_trans[of _ "e * (b - a)/4 + e * (b - a)/4"]) 
  1.2924              apply(rule norm_triangle_le,rule add_mono) apply(rule_tac[1-2] **)
  1.2925 -          proof- let ?B = "\<lambda>x. {t \<in> p. fst t = vec1 x \<and> content (snd t) \<noteq> 0}"
  1.2926 -            have pa:"\<And>k. (vec1 a, k) \<in> p \<Longrightarrow> \<exists>v. k = {vec1 a .. v} \<and> vec1 a \<le> v" 
  1.2927 +          proof- let ?B = "\<lambda>x. {t \<in> p. fst t = x \<and> content (snd t) \<noteq> 0}"
  1.2928 +            have pa:"\<And>k. (a, k) \<in> p \<Longrightarrow> \<exists>v. k = {a .. v} \<and> a \<le> v" 
  1.2929              proof- case goal1 guess u v using p(4)[OF goal1] apply-by(erule exE)+ note uv=this
  1.2930                have *:"u \<le> v" using p(2)[OF goal1] unfolding uv by auto
  1.2931 -              have u:"u = vec1 a" proof(rule ccontr)  have "u \<in> {u..v}" using p(2-3)[OF goal1(1)] unfolding uv by auto 
  1.2932 -                have "u \<ge> vec1 a" using p(2-3)[OF goal1(1)] unfolding uv subset_eq by auto moreover assume "u\<noteq>vec1 a" ultimately
  1.2933 -                have "u > vec1 a" unfolding Cart_simps by auto
  1.2934 -                thus False using p(2)[OF goal1(1)] unfolding uv by(auto simp add:Cart_simps)
  1.2935 +              have u:"u = a" proof(rule ccontr)  have "u \<in> {u..v}" using p(2-3)[OF goal1(1)] unfolding uv by auto 
  1.2936 +                have "u \<ge> a" using p(2-3)[OF goal1(1)] unfolding uv subset_eq by auto moreover assume "u\<noteq>a" ultimately
  1.2937 +                have "u > a" by auto
  1.2938 +                thus False using p(2)[OF goal1(1)] unfolding uv by(auto simp add:)
  1.2939                qed thus ?case apply(rule_tac x=v in exI) unfolding uv using * by auto
  1.2940              qed
  1.2941 -            have pb:"\<And>k. (vec1 b, k) \<in> p \<Longrightarrow> \<exists>v. k = {v .. vec1 b} \<and> vec1 b \<ge> v" 
  1.2942 +            have pb:"\<And>k. (b, k) \<in> p \<Longrightarrow> \<exists>v. k = {v .. b} \<and> b \<ge> v" 
  1.2943              proof- case goal1 guess u v using p(4)[OF goal1] apply-by(erule exE)+ note uv=this
  1.2944                have *:"u \<le> v" using p(2)[OF goal1] unfolding uv by auto
  1.2945 -              have u:"v = vec1 b" proof(rule ccontr)  have "u \<in> {u..v}" using p(2-3)[OF goal1(1)] unfolding uv by auto 
  1.2946 -                have "v \<le> vec1 b" using p(2-3)[OF goal1(1)] unfolding uv subset_eq by auto moreover assume "v\<noteq>vec1 b" ultimately
  1.2947 -                have "v < vec1 b" unfolding Cart_simps by auto
  1.2948 -                thus False using p(2)[OF goal1(1)] unfolding uv by(auto simp add:Cart_simps)
  1.2949 +              have u:"v =  b" proof(rule ccontr)  have "u \<in> {u..v}" using p(2-3)[OF goal1(1)] unfolding uv by auto 
  1.2950 +                have "v \<le>  b" using p(2-3)[OF goal1(1)] unfolding uv subset_eq by auto moreover assume "v\<noteq> b" ultimately
  1.2951 +                have "v <  b" by auto
  1.2952 +                thus False using p(2)[OF goal1(1)] unfolding uv by(auto simp add:)
  1.2953                qed thus ?case apply(rule_tac x=u in exI) unfolding uv using * by auto
  1.2954              qed
  1.2955  
  1.2956              show "\<forall>x y. x \<in> ?B a \<and> y \<in> ?B a \<longrightarrow> x = y" apply(rule,rule,rule,unfold split_paired_all)
  1.2957                unfolding mem_Collect_eq fst_conv snd_conv apply safe
  1.2958 -            proof- fix x k k' assume k:"(vec1 a, k) \<in> p" "(vec1 a, k') \<in> p" "content k \<noteq> 0" "content k' \<noteq> 0"
  1.2959 +            proof- fix x k k' assume k:"( a, k) \<in> p" "( a, k') \<in> p" "content k \<noteq> 0" "content k' \<noteq> 0"
  1.2960                guess v using pa[OF k(1)] .. note v = conjunctD2[OF this]
  1.2961 -              guess v' using pa[OF k(2)] .. note v' = conjunctD2[OF this] let ?v = "vec1 (min (v$1) (v'$1))"
  1.2962 -              have "{vec1 a <..< ?v} \<subseteq> k \<inter> k'" unfolding v v' by(auto simp add:Cart_simps) note subset_interior[OF this,unfolded interior_inter]
  1.2963 -              moreover have "vec1 ((a + ?v$1)/2) \<in> {vec1 a <..< ?v}" using k(3-) unfolding v v' content_eq_0_1 not_le by(auto simp add:Cart_simps)
  1.2964 -              ultimately have "vec1 ((a + ?v$1)/2) \<in> interior k \<inter> interior k'" unfolding interior_open[OF open_interval] by auto
  1.2965 +              guess v' using pa[OF k(2)] .. note v' = conjunctD2[OF this] let ?v = " (min (v) (v'))"
  1.2966 +              have "{ a <..< ?v} \<subseteq> k \<inter> k'" unfolding v v' by(auto simp add:) note subset_interior[OF this,unfolded interior_inter]
  1.2967 +              moreover have " ((a + ?v)/2) \<in> { a <..< ?v}" using k(3-)
  1.2968 +                unfolding v v' content_eq_0 not_le by(auto simp add:not_le)
  1.2969 +              ultimately have " ((a + ?v)/2) \<in> interior k \<inter> interior k'" unfolding interior_open[OF open_interval] by auto
  1.2970                hence *:"k = k'" apply- apply(rule ccontr) using p(5)[OF k(1-2)] by auto
  1.2971                { assume "x\<in>k" thus "x\<in>k'" unfolding * . } { assume "x\<in>k'" thus "x\<in>k" unfolding * . }
  1.2972              qed 
  1.2973              show "\<forall>x y. x \<in> ?B b \<and> y \<in> ?B b \<longrightarrow> x = y" apply(rule,rule,rule,unfold split_paired_all)
  1.2974                unfolding mem_Collect_eq fst_conv snd_conv apply safe
  1.2975 -            proof- fix x k k' assume k:"(vec1 b, k) \<in> p" "(vec1 b, k') \<in> p" "content k \<noteq> 0" "content k' \<noteq> 0"
  1.2976 +            proof- fix x k k' assume k:"( b, k) \<in> p" "( b, k') \<in> p" "content k \<noteq> 0" "content k' \<noteq> 0"
  1.2977                guess v using pb[OF k(1)] .. note v = conjunctD2[OF this]
  1.2978 -              guess v' using pb[OF k(2)] .. note v' = conjunctD2[OF this] let ?v = "vec1 (max (v$1) (v'$1))"
  1.2979 -              have "{?v <..< vec1 b} \<subseteq> k \<inter> k'" unfolding v v' by(auto simp add:Cart_simps) note subset_interior[OF this,unfolded interior_inter]
  1.2980 -              moreover have "vec1 ((b + ?v$1)/2) \<in> {?v <..< vec1 b}" using k(3-) unfolding v v' content_eq_0_1 not_le by(auto simp add:Cart_simps)
  1.2981 -              ultimately have "vec1 ((b + ?v$1)/2) \<in> interior k \<inter> interior k'" unfolding interior_open[OF open_interval] by auto
  1.2982 +              guess v' using pb[OF k(2)] .. note v' = conjunctD2[OF this] let ?v = " (max (v) (v'))"
  1.2983 +              have "{?v <..<  b} \<subseteq> k \<inter> k'" unfolding v v' by(auto simp add:) note subset_interior[OF this,unfolded interior_inter]
  1.2984 +              moreover have " ((b + ?v)/2) \<in> {?v <..<  b}" using k(3-) unfolding v v' content_eq_0 not_le by auto
  1.2985 +              ultimately have " ((b + ?v)/2) \<in> interior k \<inter> interior k'" unfolding interior_open[OF open_interval] by auto
  1.2986                hence *:"k = k'" apply- apply(rule ccontr) using p(5)[OF k(1-2)] by auto
  1.2987                { assume "x\<in>k" thus "x\<in>k'" unfolding * . } { assume "x\<in>k'" thus "x\<in>k" unfolding * . }
  1.2988              qed
  1.2989  
  1.2990              let ?a = a and ?b = b (* a is something else while proofing the next theorem. *)
  1.2991 -            show "\<forall>x. x \<in> ?B a \<longrightarrow> norm ((\<lambda>(x, k). content k *\<^sub>R f' (x$1) - (f ((interval_upperbound k)$1) - f ((interval_lowerbound k)$1))) x)
  1.2992 -              \<le> e * (b - a) / 4" apply safe unfolding fst_conv snd_conv apply safe unfolding vec1_dest_vec1
  1.2993 -            proof- case goal1 guess v using pa[OF goal1(1)] .. note v = conjunctD2[OF this]
  1.2994 -              have "vec1 ?a\<in>{vec1 ?a..v}" using v(2) by auto hence "dest_vec1 v \<le> ?b" using p(3)[OF goal1(1)] unfolding subset_eq v by auto
  1.2995 -              moreover have "{?a..dest_vec1 v} \<subseteq> ball ?a da" using fineD[OF as(2) goal1(1)]
  1.2996 -                apply-apply(subst(asm) if_P,rule refl) unfolding subset_eq apply safe apply(erule_tac x="vec1 x" in ballE)
  1.2997 -                by(auto simp add:Cart_simps subset_eq dist_real v dist_real_def) ultimately
  1.2998 -              show ?case unfolding v unfolding interval_bounds[OF v(2)[unfolded v vector_le_def]] vec1_dest_vec1 apply-
  1.2999 -                apply(rule da(2)[of "v$1",unfolded vec1_dest_vec1])
  1.3000 -                using goal1 fineD[OF as(2) goal1(1)] unfolding v content_eq_0_1 by auto
  1.3001 +            show "\<forall>x. x \<in> ?B a \<longrightarrow> norm ((\<lambda>(x, k). content k *\<^sub>R f' (x) - (f ((interval_upperbound k)) -
  1.3002 +              f ((interval_lowerbound k)))) x) \<le> e * (b - a) / 4" apply(rule,rule) unfolding mem_Collect_eq
  1.3003 +              unfolding split_paired_all fst_conv snd_conv 
  1.3004 +            proof safe case goal1 guess v using pa[OF goal1(1)] .. note v = conjunctD2[OF this]
  1.3005 +              have " ?a\<in>{ ?a..v}" using v(2) by auto hence "v \<le> ?b" using p(3)[OF goal1(1)] unfolding subset_eq v by auto
  1.3006 +              moreover have "{?a..v} \<subseteq> ball ?a da" using fineD[OF as(2) goal1(1)]
  1.3007 +                apply-apply(subst(asm) if_P,rule refl) unfolding subset_eq apply safe apply(erule_tac x=" x" in ballE)
  1.3008 +                by(auto simp add:subset_eq dist_real_def v) ultimately
  1.3009 +              show ?case unfolding v interval_bounds_real[OF v(2)] apply- apply(rule da(2)[of "v"])
  1.3010 +                using goal1 fineD[OF as(2) goal1(1)] unfolding v content_eq_0 by auto
  1.3011              qed
  1.3012 -            show "\<forall>x. x \<in> ?B b \<longrightarrow> norm ((\<lambda>(x, k). content k *\<^sub>R f' (x$1) - (f ((interval_upperbound k)$1) - f ((interval_lowerbound k)$1))) x)
  1.3013 -              \<le> e * (b - a) / 4" apply safe unfolding fst_conv snd_conv apply safe unfolding vec1_dest_vec1
  1.3014 -            proof- case goal1 guess v using pb[OF goal1(1)] .. note v = conjunctD2[OF this]
  1.3015 -              have "vec1 ?b\<in>{v..vec1 ?b}" using v(2) by auto hence "dest_vec1 v \<ge> ?a" using p(3)[OF goal1(1)] unfolding subset_eq v by auto
  1.3016 -              moreover have "{dest_vec1 v..?b} \<subseteq> ball ?b db" using fineD[OF as(2) goal1(1)]
  1.3017 -                apply-apply(subst(asm) if_P,rule refl) unfolding subset_eq apply safe apply(erule_tac x="vec1 x" in ballE) using ab
  1.3018 -                by(auto simp add:Cart_simps subset_eq dist_real v dist_real_def) ultimately
  1.3019 -              show ?case unfolding v unfolding interval_bounds[OF v(2)[unfolded v vector_le_def]] vec1_dest_vec1 apply-
  1.3020 -                apply(rule db(2)[of "v$1",unfolded vec1_dest_vec1])
  1.3021 -                using goal1 fineD[OF as(2) goal1(1)] unfolding v content_eq_0_1 by auto
  1.3022 +            show "\<forall>x. x \<in> ?B b \<longrightarrow> norm ((\<lambda>(x, k). content k *\<^sub>R f' (x) -
  1.3023 +              (f ((interval_upperbound k)) - f ((interval_lowerbound k)))) x) \<le> e * (b - a) / 4"
  1.3024 +              apply(rule,rule) unfolding mem_Collect_eq unfolding split_paired_all fst_conv snd_conv 
  1.3025 +            proof safe case goal1 guess v using pb[OF goal1(1)] .. note v = conjunctD2[OF this]
  1.3026 +              have " ?b\<in>{v.. ?b}" using v(2) by auto hence "v \<ge> ?a" using p(3)[OF goal1(1)]
  1.3027 +                unfolding subset_eq v by auto
  1.3028 +              moreover have "{v..?b} \<subseteq> ball ?b db" using fineD[OF as(2) goal1(1)]
  1.3029 +                apply-apply(subst(asm) if_P,rule refl) unfolding subset_eq apply safe
  1.3030 +                apply(erule_tac x=" x" in ballE) using ab
  1.3031 +                by(auto simp add:subset_eq v dist_real_def) ultimately
  1.3032 +              show ?case unfolding v unfolding interval_bounds_real[OF v(2)] apply- apply(rule db(2)[of "v"])
  1.3033 +                using goal1 fineD[OF as(2) goal1(1)] unfolding v content_eq_0 by auto
  1.3034              qed
  1.3035            qed(insert p(1) ab e, auto simp add:field_simps) qed auto qed qed qed qed
  1.3036  
  1.3037 @@ -3534,7 +3587,7 @@
  1.3038  lemma fundamental_theorem_of_calculus_interior_strong: fixes f::"real \<Rightarrow> 'a::banach"
  1.3039    assumes"finite s" "a \<le> b" "continuous_on {a..b} f"
  1.3040    "\<forall>x\<in>{a<..<b} - s. (f has_vector_derivative f'(x)) (at x)"
  1.3041 -  shows "((f' o dest_vec1) has_integral (f b - f a)) {vec a..vec b}" using assms apply- 
  1.3042 +  shows "(f' has_integral (f b - f a)) {a..b}" using assms apply- 
  1.3043  proof(induct "card s" arbitrary:s a b)
  1.3044    case 0 show ?case apply(rule fundamental_theorem_of_calculus_interior) using 0 by auto
  1.3045  next case (Suc n) from this(2) guess c s' apply-apply(subst(asm) eq_commute) unfolding card_Suc_eq
  1.3046 @@ -3543,7 +3596,7 @@
  1.3047      case False thus ?thesis apply- apply(rule Suc(1)[OF cs(3) _ Suc(4,5)]) apply safe defer
  1.3048        apply(rule Suc(6)[rule_format]) using Suc(3) unfolding cs by auto
  1.3049    next have *:"f b - f a = (f c - f a) + (f b - f c)" by auto
  1.3050 -    case True hence "vec1 a \<le> vec1 c" "vec1 c \<le> vec1 b" by auto
  1.3051 +    case True hence "a \<le> c" "c \<le> b" by auto
  1.3052      thus ?thesis apply(subst *) apply(rule has_integral_combine) apply assumption+
  1.3053        apply(rule_tac[!] Suc(1)[OF cs(3)]) using Suc(3) unfolding cs
  1.3054      proof- show "continuous_on {a..c} f" "continuous_on {c..b} f"
  1.3055 @@ -3555,20 +3608,20 @@
  1.3056  lemma fundamental_theorem_of_calculus_strong: fixes f::"real \<Rightarrow> 'a::banach"
  1.3057    assumes "finite s" "a \<le> b" "continuous_on {a..b} f"
  1.3058    "\<forall>x\<in>{a..b} - s. (f has_vector_derivative f'(x)) (at x)"
  1.3059 -  shows "((f' o dest_vec1) has_integral (f(b) - f(a))) {vec1 a..vec1 b}"
  1.3060 +  shows "(f' has_integral (f(b) - f(a))) {a..b}"
  1.3061    apply(rule fundamental_theorem_of_calculus_interior_strong[OF assms(1-3), of f'])
  1.3062    using assms(4) by auto
  1.3063  
  1.3064 -lemma indefinite_integral_continuous_left: fixes f::"real^1 \<Rightarrow> 'a::banach"
  1.3065 +lemma indefinite_integral_continuous_left: fixes f::"real \<Rightarrow> 'a::banach"
  1.3066    assumes "f integrable_on {a..b}" "a < c" "c \<le> b" "0 < e"
  1.3067 -  obtains d where "0 < d" "\<forall>t. c$1 - d < t$1 \<and> t \<le> c \<longrightarrow> norm(integral {a..c} f - integral {a..t} f) < e"
  1.3068 -proof- have "\<exists>w>0. \<forall>t. c$1 - w < t$1 \<and> t < c \<longrightarrow> norm(f c) * norm(c - t) < e / 3"
  1.3069 +  obtains d where "0 < d" "\<forall>t. c - d < t \<and> t \<le> c \<longrightarrow> norm(integral {a..c} f - integral {a..t} f) < e"
  1.3070 +proof- have "\<exists>w>0. \<forall>t. c - w < t \<and> t < c \<longrightarrow> norm(f c) * norm(c - t) < e / 3"
  1.3071    proof(cases "f c = 0") case False hence "0 < e / 3 / norm (f c)"
  1.3072        apply-apply(rule divide_pos_pos) using `e>0` by auto
  1.3073      thus ?thesis apply-apply(rule,rule,assumption,safe)
  1.3074 -    proof- fix t assume as:"t < c" and "c$1 - e / 3 / norm (f c) < t$(1::1)"
  1.3075 -      hence "c$1 - t$1 < e / 3 / norm (f c)" by auto
  1.3076 -      hence "norm (c - t) < e / 3 / norm (f c)" using as unfolding norm_vector_1 vector_less_def by auto
  1.3077 +    proof- fix t assume as:"t < c" and "c - e / 3 / norm (f c) < t"
  1.3078 +      hence "c - t < e / 3 / norm (f c)" by auto
  1.3079 +      hence "norm (c - t) < e / 3 / norm (f c)" using as by auto
  1.3080        thus "norm (f c) * norm (c - t) < e / 3" using False apply-
  1.3081          apply(subst mult_commute) apply(subst pos_less_divide_eq[THEN sym]) by auto
  1.3082      qed next case True show ?thesis apply(rule_tac x=1 in exI) unfolding True using `e>0` by auto
  1.3083 @@ -3582,12 +3635,12 @@
  1.3084    note this[unfolded gauge_def,rule_format,of c] note conjunctD2[OF this]
  1.3085    from this(2)[unfolded open_contains_ball,rule_format,OF this(1)] guess k .. note k=conjunctD2[OF this]
  1.3086  
  1.3087 -  let ?d = "min k (c$1 - a$1)/2" show ?thesis apply(rule that[of ?d])
  1.3088 -  proof safe show "?d > 0" using k(1) using assms(2) unfolding vector_less_def by auto
  1.3089 -    fix t assume as:"c$1 - ?d < t$1" "t \<le> c" let ?thesis = "norm (integral {a..c} f - integral {a..t} f) < e"
  1.3090 +  let ?d = "min k (c - a)/2" show ?thesis apply(rule that[of ?d])
  1.3091 +  proof safe show "?d > 0" using k(1) using assms(2) by auto
  1.3092 +    fix t assume as:"c - ?d < t" "t \<le> c" let ?thesis = "norm (integral {a..c} f - integral {a..t} f) < e"
  1.3093      { presume *:"t < c \<Longrightarrow> ?thesis"
  1.3094        show ?thesis apply(cases "t = c") defer apply(rule *)
  1.3095 -        unfolding vector_less_def apply(subst less_le) using `e>0` as(2) by auto } assume "t < c"
  1.3096 +        apply(subst less_le) using `e>0` as(2) by auto } assume "t < c"
  1.3097  
  1.3098      have "f integrable_on {a..t}" apply(rule integrable_subinterval[OF assms(1)]) using assms(2-3) as(2) by auto
  1.3099      from integrable_integral[OF this,unfolded has_integral,rule_format,OF *] guess d2 ..
  1.3100 @@ -3596,82 +3649,79 @@
  1.3101      have "gauge d3" using d2(1) d1(1) unfolding d3_def gauge_def by auto
  1.3102      from fine_division_exists[OF this, of a t] guess p . note p=this
  1.3103      note p'=tagged_division_ofD[OF this(1)]
  1.3104 -    have pt:"\<forall>(x,k)\<in>p. x$1 \<le> t$1" proof safe case goal1 from p'(2,3)[OF this] show ?case by auto qed
  1.3105 +    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
  1.3106      with p(2) have "d2 fine p" unfolding fine_def d3_def apply safe apply(erule_tac x="(a,b)" in ballE)+ by auto
  1.3107      note d2_fin = d2(2)[OF conjI[OF p(1) this]]
  1.3108      
  1.3109 -    have *:"{a..c} \<inter> {x. x$1 \<le> t$1} = {a..t}" "{a..c} \<inter> {x. x$1 \<ge> t$1} = {t..c}"
  1.3110 +    have *:"{a..c} \<inter> {x. x $$0 \<le> t} = {a..t}" "{a..c} \<inter> {x. x$$0 \<ge> t} = {t..c}"
  1.3111        using assms(2-3) as by(auto simp add:field_simps)
  1.3112      have "p \<union> {(c, {t..c})} tagged_division_of {a..c} \<and> d1 fine p \<union> {(c, {t..c})}" apply rule
  1.3113 -      apply(rule tagged_division_union_interval[of _ _ _ 1 "t$1"]) unfolding * apply(rule p)
  1.3114 +      apply(rule tagged_division_union_interval[of _ _ _ 0 "t"]) unfolding * apply(rule p)
  1.3115        apply(rule tagged_division_of_self) unfolding fine_def
  1.3116      proof safe fix x k y assume "(x,k)\<in>p" "y\<in>k" thus "y\<in>d1 x"
  1.3117          using p(2) pt unfolding fine_def d3_def apply- apply(erule_tac x="(x,k)" in ballE)+ by auto
  1.3118 -    next fix x assume "x\<in>{t..c}" hence "dist c x < k" unfolding dist_real
  1.3119 +    next fix x assume "x\<in>{t..c}" hence "dist c x < k" unfolding dist_real_def
  1.3120          using as(1) by(auto simp add:field_simps) 
  1.3121        thus "x \<in> d1 c" using k(2) unfolding d_def by auto
  1.3122      qed(insert as(2), auto) note d1_fin = d1(2)[OF this]
  1.3123  
  1.3124 -    have *:"integral{a..c} f - integral {a..t} f = -(((c$1 - t$1) *\<^sub>R f c + (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)) -
  1.3125 -        integral {a..c} f) + ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - integral {a..t} f) + (c$1 - t$1) *\<^sub>R f c" 
  1.3126 +    have *:"integral{a..c} f - integral {a..t} f = -(((c - t) *\<^sub>R f c + (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)) -
  1.3127 +        integral {a..c} f) + ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - integral {a..t} f) + (c - t) *\<^sub>R f c" 
  1.3128        "e = (e/3 + e/3) + e/3" by auto
  1.3129 -    have **:"(\<Sum>(x, k)\<in>p \<union> {(c, {t..c})}. content k *\<^sub>R f x) = (c$1 - t$1) *\<^sub>R f c + (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)"
  1.3130 +    have **:"(\<Sum>(x, k)\<in>p \<union> {(c, {t..c})}. content k *\<^sub>R f x) = (c - t) *\<^sub>R f c + (\<Sum>(x, k)\<in>p. content k *\<^sub>R f x)"
  1.3131      proof- have **:"\<And>x F. F \<union> {x} = insert x F" by auto
  1.3132        have "(c, {t..c}) \<notin> p" proof safe case goal1 from p'(2-3)[OF this]
  1.3133 -        have "c \<in> {a..t}" by auto thus False using `t<c` unfolding vector_less_def by auto
  1.3134 +        have "c \<in> {a..t}" by auto thus False using `t<c` by auto
  1.3135        qed thus ?thesis unfolding ** apply- apply(subst setsum_insert) apply(rule p')
  1.3136 -        unfolding split_conv defer apply(subst content_1) using as(2) by auto qed 
  1.3137 -
  1.3138 -    have ***:"c$1 - w < t$1 \<and> t < c"
  1.3139 -    proof- have "c$1 - k < t$1" using `k>0` as(1) by(auto simp add:field_simps)
  1.3140 +        unfolding split_conv defer apply(subst content_real) using as(2) by auto qed 
  1.3141 +
  1.3142 +    have ***:"c - w < t \<and> t < c"
  1.3143 +    proof- have "c - k < t" using `k>0` as(1) by(auto simp add:field_simps)
  1.3144        moreover have "k \<le> w" apply(rule ccontr) using k(2) 
  1.3145 -        unfolding subset_eq apply(erule_tac x="c + vec ((k + w)/2)" in ballE)
  1.3146 -        unfolding d_def using `k>0` `w>0` by(auto simp add:field_simps not_le not_less dist_real)
  1.3147 +        unfolding subset_eq apply(erule_tac x="c + ((k + w)/2)" in ballE)
  1.3148 +        unfolding d_def using `k>0` `w>0` by(auto simp add:field_simps not_le not_less dist_real_def)
  1.3149        ultimately show  ?thesis using `t<c` by(auto simp add:field_simps) qed
  1.3150  
  1.3151      show ?thesis unfolding *(1) apply(subst *(2)) apply(rule norm_triangle_lt add_strict_mono)+
  1.3152        unfolding norm_minus_cancel apply(rule d1_fin[unfolded **]) apply(rule d2_fin)
  1.3153 -      using w(2)[OF ***] unfolding norm_scaleR norm_real by(auto simp add:field_simps) qed qed 
  1.3154 -
  1.3155 -lemma indefinite_integral_continuous_right: fixes f::"real^1 \<Rightarrow> 'a::banach"
  1.3156 +      using w(2)[OF ***] unfolding norm_scaleR by(auto simp add:field_simps) qed qed 
  1.3157 +
  1.3158 +lemma indefinite_integral_continuous_right: fixes f::"real \<Rightarrow> 'a::banach"
  1.3159    assumes "f integrable_on {a..b}" "a \<le> c" "c < b" "0 < e"
  1.3160 -  obtains d where "0 < d" "\<forall>t. c \<le> t \<and> t$1 < c$1 + d \<longrightarrow> norm(integral{a..c} f - integral{a..t} f) < e"
  1.3161 -proof- have *:"(\<lambda>x. f (- x)) integrable_on {- b..- a}" "- b < - c" "- c \<le> - a"
  1.3162 -    using assms unfolding Cart_simps by auto
  1.3163 -  from indefinite_integral_continuous_left[OF * `e>0`] guess d . note d = this let ?d = "min d (b$1 - c$1)"
  1.3164 +  obtains d where "0 < d" "\<forall>t. c \<le> t \<and> t < c + d \<longrightarrow> norm(integral{a..c} f - integral{a..t} f) < e"
  1.3165 +proof- have *:"(\<lambda>x. f (- x)) integrable_on {- b..- a}" "- b < - c" "- c \<le> - a" using assms by auto
  1.3166 +  from indefinite_integral_continuous_left[OF * `e>0`] guess d . note d = this let ?d = "min d (b - c)"
  1.3167    show ?thesis apply(rule that[of "?d"])
  1.3168 -  proof safe show "0 < ?d" using d(1) assms(3) unfolding Cart_simps by auto
  1.3169 -    fix t::"_^1" assume as:"c \<le> t" "t$1 < c$1 + ?d"
  1.3170 +  proof safe show "0 < ?d" using d(1) assms(3) by auto
  1.3171 +    fix t::"real" assume as:"c \<le> t" "t < c + ?d"
  1.3172      have *:"integral{a..c} f = integral{a..b} f - integral{c..b} f"
  1.3173        "integral{a..t} f = integral{a..b} f - integral{t..b} f" unfolding algebra_simps
  1.3174 -      apply(rule_tac[!] integral_combine) using assms as unfolding Cart_simps by auto
  1.3175 -    have "(- c)$1 - d < (- t)$1 \<and> - t \<le> - c" using as by auto note d(2)[rule_format,OF this]
  1.3176 +      apply(rule_tac[!] integral_combine) using assms as by auto
  1.3177 +    have "(- c) - d < (- t) \<and> - t \<le> - c" using as by auto note d(2)[rule_format,OF this]
  1.3178      thus "norm (integral {a..c} f - integral {a..t} f) < e" unfolding * 
  1.3179        unfolding integral_reflect apply-apply(subst norm_minus_commute) by(auto simp add:algebra_simps) qed qed
  1.3180 -
  1.3181 -declare dest_vec1_eq[simp del] not_less[simp] not_le[simp]
  1.3182 -
  1.3183 -lemma indefinite_integral_continuous: fixes f::"real^1 \<Rightarrow> 'a::banach"
  1.3184 +   
  1.3185 +lemma indefinite_integral_continuous: fixes f::"real \<Rightarrow> 'a::banach"
  1.3186    assumes "f integrable_on {a..b}" shows  "continuous_on {a..b} (\<lambda>x. integral {a..x} f)"
  1.3187  proof(unfold continuous_on_iff, safe)  fix x e assume as:"x\<in>{a..b}" "0<(e::real)"
  1.3188    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"
  1.3189    { presume *:"a<b \<Longrightarrow> ?thesis"
  1.3190      show ?thesis apply(cases,rule *,assumption)
  1.3191 -    proof- case goal1 hence "{a..b} = {x}" using as(1) unfolding Cart_simps  
  1.3192 -        by(auto simp only:field_simps not_less Cart_eq forall_1 mem_interval) 
  1.3193 +    proof- case goal1 hence "{a..b} = {x}" using as(1) apply-apply(rule set_ext)
  1.3194 +        unfolding atLeastAtMost_iff by(auto simp only:field_simps not_less DIM_real)
  1.3195        thus ?case using `e>0` by auto
  1.3196      qed } assume "a<b"
  1.3197 -  have "(x=a \<or> x=b) \<or> (a<x \<and> x<b)" using as(1) by (auto simp add: Cart_simps)
  1.3198 +  have "(x=a \<or> x=b) \<or> (a<x \<and> x<b)" using as(1) by (auto simp add:)
  1.3199    thus ?thesis apply-apply(erule disjE)+
  1.3200    proof- assume "x=a" have "a \<le> a" by auto
  1.3201      from indefinite_integral_continuous_right[OF assms(1) this `a<b` `e>0`] guess d . note d=this
  1.3202      show ?thesis apply(rule,rule,rule d,safe) apply(subst dist_commute)
  1.3203 -      unfolding `x=a` dist_norm apply(rule d(2)[rule_format]) unfolding norm_real by auto
  1.3204 +      unfolding `x=a` dist_norm apply(rule d(2)[rule_format]) by auto
  1.3205    next   assume "x=b" have "b \<le> b" by auto
  1.3206      from indefinite_integral_continuous_left[OF assms(1) `a<b` this `e>0`] guess d . note d=this
  1.3207      show ?thesis apply(rule,rule,rule d,safe) apply(subst dist_commute)
  1.3208 -      unfolding `x=b` dist_norm apply(rule d(2)[rule_format]) unfolding norm_real by auto
  1.3209 -  next assume "a<x \<and> x<b" hence xl:"a<x" "x\<le>b" and xr:"a\<le>x" "x<b" by(auto simp add: vector_less_def)
  1.3210 +      unfolding `x=b` dist_norm apply(rule d(2)[rule_format])  by auto
  1.3211 +  next assume "a<x \<and> x<b" hence xl:"a<x" "x\<le>b" and xr:"a\<le>x" "x<b" by(auto simp add: )
  1.3212      from indefinite_integral_continuous_left [OF assms(1) xl `e>0`] guess d1 . note d1=this
  1.3213      from indefinite_integral_continuous_right[OF assms(1) xr `e>0`] guess d2 . note d2=this
  1.3214      show ?thesis apply(rule_tac x="min d1 d2" in exI)
  1.3215 @@ -3679,7 +3729,7 @@
  1.3216        fix y assume "y\<in>{a..b}" "dist y x < min d1 d2"
  1.3217        thus "dist (integral {a..y} f) (integral {a..x} f) < e" apply-apply(subst dist_commute)
  1.3218          apply(cases "y < x") unfolding dist_norm apply(rule d1(2)[rule_format]) defer
  1.3219 -        apply(rule d2(2)[rule_format]) unfolding Cart_simps not_less norm_real by(auto simp add:field_simps)
  1.3220 +        apply(rule d2(2)[rule_format]) unfolding not_less by(auto simp add:field_simps)
  1.3221      qed qed qed 
  1.3222  
  1.3223  subsection {* This doesn't directly involve integration, but that gives an easy proof. *}
  1.3224 @@ -3689,23 +3739,19 @@
  1.3225    "\<forall>x\<in>({a..b} - k). (f has_derivative (\<lambda>h. 0)) (at x within {a..b})" "x \<in> {a..b}"
  1.3226    shows "f x = y"
  1.3227  proof- have ab:"a\<le>b" using assms by auto
  1.3228 -  have *:"(\<lambda>x. 0\<Colon>'a) \<circ> dest_vec1 = (\<lambda>x. 0)" unfolding o_def by auto have **:"a \<le> x" using assms by auto
  1.3229 -  have "((\<lambda>x. 0\<Colon>'a) \<circ> dest_vec1 has_integral f x - f a) {vec1 a..vec1 x}"
  1.3230 -    apply(rule fundamental_theorem_of_calculus_interior_strong[OF assms(1) ** ])
  1.3231 +  have *:"a\<le>x" using assms(5) by auto
  1.3232 +  have "((\<lambda>x. 0\<Colon>'a) has_integral f x - f a) {a..x}"
  1.3233 +    apply(rule fundamental_theorem_of_calculus_interior_strong[OF assms(1) *])
  1.3234      apply(rule continuous_on_subset[OF assms(2)]) defer
  1.3235      apply safe unfolding has_vector_derivative_def apply(subst has_derivative_within_open[THEN sym])
  1.3236 -    apply assumption apply(rule open_interval_real) apply(rule has_derivative_within_subset[where s="{a..b}"])
  1.3237 +    apply assumption apply(rule open_interval) apply(rule has_derivative_within_subset[where s="{a..b}"])
  1.3238      using assms(4) assms(5) by auto note this[unfolded *]
  1.3239    note has_integral_unique[OF has_integral_0 this]
  1.3240    thus ?thesis unfolding assms by auto qed
  1.3241  
  1.3242  subsection {* Generalize a bit to any convex set. *}
  1.3243  
  1.3244 -lemmas scaleR_simps = scaleR_zero_left scaleR_minus_left scaleR_left_diff_distrib
  1.3245 -  scaleR_zero_right scaleR_minus_right scaleR_right_diff_distrib scaleR_eq_0_iff
  1.3246 -  scaleR_cancel_left scaleR_cancel_right scaleR.add_right scaleR.add_left real_vector_class.scaleR_one
  1.3247 -
  1.3248 -lemma has_derivative_zero_unique_strong_convex: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3249 +lemma has_derivative_zero_unique_strong_convex: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  1.3250    assumes "convex s" "finite k" "continuous_on s f" "c \<in> s" "f c = y"
  1.3251    "\<forall>x\<in>(s - k). (f has_derivative (\<lambda>h. 0)) (at x within s)" "x \<in> s"
  1.3252    shows "f x = y"
  1.3253 @@ -3741,7 +3787,7 @@
  1.3254  subsection {* Also to any open connected set with finite set of exceptions. Could 
  1.3255   generalize to locally convex set with limpt-free set of exceptions. *}
  1.3256  
  1.3257 -lemma has_derivative_zero_unique_strong_connected: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3258 +lemma has_derivative_zero_unique_strong_connected: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  1.3259    assumes "connected s" "open s" "finite k" "continuous_on s f" "c \<in> s" "f c = y"
  1.3260    "\<forall>x\<in>(s - k). (f has_derivative (\<lambda>h. 0)) (at x within s)" "x\<in>s"
  1.3261    shows "f x = y"
  1.3262 @@ -3762,7 +3808,7 @@
  1.3263  
  1.3264  subsection {* Integrating characteristic function of an interval. *}
  1.3265  
  1.3266 -lemma has_integral_restrict_open_subinterval: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3267 +lemma has_integral_restrict_open_subinterval: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  1.3268    assumes "(f has_integral i) {c..d}" "{c..d} \<subseteq> {a..b}"
  1.3269    shows "((\<lambda>x. if x \<in> {c<..<d} then f x else 0) has_integral i) {a..b}"
  1.3270  proof- def g \<equiv> "\<lambda>x. if x \<in>{c<..<d} then f x else 0"
  1.3271 @@ -3799,14 +3845,14 @@
  1.3272    ultimately show ?P unfolding operat apply- apply(subst *) apply(subst iterate_insert) apply rule+
  1.3273      unfolding iterate defer apply(subst if_not_P) defer using p by auto qed
  1.3274  
  1.3275 -lemma has_integral_restrict_closed_subinterval: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3276 +lemma has_integral_restrict_closed_subinterval: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach"
  1.3277    assumes "(f has_integral i) ({c..d})" "{c..d} \<subseteq> {a..b}" 
  1.3278    shows "((\<lambda>x. if x \<in> {c..d} then f x else 0) has_integral i) {a..b}"
  1.3279  proof- note has_integral_restrict_open_subinterval[OF assms]
  1.3280    note * = has_integral_spike[OF negligible_frontier_interval _ this]
  1.3281    show ?thesis apply(rule *[of c d]) using interval_open_subset_closed[of c d] by auto qed
  1.3282  
  1.3283 -lemma has_integral_restrict_closed_subintervals_eq: fixes f::"real^'n \<Rightarrow> 'a::banach" assumes "{c..d} \<subseteq> {a..b}" 
  1.3284 +lemma has_integral_restrict_closed_subintervals_eq: fixes f::"'a::ordered_euclidean_space \<Rightarrow> 'b::banach" assumes "{c..d} \<subseteq> {a..b}" 
  1.3285    shows "((\<lambda>x. if x \<in> {c..d} then f x else 0) has_integral i) {a..b} \<longleftrightarrow> (f has_integral i) {c..d}" (is "?l = ?r")
  1.3286  proof(cases "{c..d} = {}") case False let ?g = "\<lambda>x. if x \<in> {c..d} then f x else 0"
  1.3287    show ?thesis apply rule defer apply(rule has_integral_restrict_closed_subinterval[OF _ assms])
  1.3288 @@ -3819,7 +3865,7 @@
  1.3289  
  1.3290  subsection {* Hence we can apply the limit process uniformly to all integrals. *}
  1.3291  
  1.3292 -lemma has_integral': fixes f::"real^'n \<Rightarrow> 'a::banach" shows
  1.3293 +lemma has_integral': fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach" shows
  1.3294   "(f has_integral i) s \<longleftrightarrow> (\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b}
  1.3295    \<longrightarrow> (\<exists>z. ((\<lambda>x. if x \<in> s then f(x) else 0) has_integral z) {a..b} \<and> norm(z - i) < e))" (is "?l \<longleftrightarrow> (\<forall>e>0. ?r e)")
  1.3296  proof- { presume *:"\<exists>a b. s = {a..b} \<Longrightarrow> ?thesis"
  1.3297 @@ -3830,7 +3876,7 @@
  1.3298    note B = conjunctD2[OF this,rule_format] show ?thesis apply safe
  1.3299    proof- fix e assume ?l "e>(0::real)"
  1.3300      show "?r e" apply(rule_tac x="B+1" in exI) apply safe defer apply(rule_tac x=i in exI)
  1.3301 -    proof fix c d assume as:"ball 0 (B+1) \<subseteq> {c..d::real^'n}"
  1.3302 +    proof fix c d assume as:"ball 0 (B+1) \<subseteq> {c..d::'n::ordered_euclidean_space}"
  1.3303        thus "((\<lambda>x. if x \<in> s then f x else 0) has_integral i) {c..d}" unfolding s
  1.3304          apply-apply(rule has_integral_restrict_closed_subinterval) apply(rule `?l`[unfolded s])
  1.3305          apply safe apply(drule B(2)[rule_format]) unfolding subset_eq apply(erule_tac x=x in ballE)
  1.3306 @@ -3838,7 +3884,7 @@
  1.3307      qed(insert B `e>0`, auto)
  1.3308    next assume as:"\<forall>e>0. ?r e" 
  1.3309      from this[rule_format,OF zero_less_one] guess C .. note C=conjunctD2[OF this,rule_format]
  1.3310 -    def c \<equiv> "(\<chi> i. - max B C)::real^'n" and d \<equiv> "(\<chi> i. max B C)::real^'n"
  1.3311 +    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"
  1.3312      have c_d:"{a..b} \<subseteq> {c..d}" apply safe apply(drule B(2)) unfolding mem_interval
  1.3313      proof case goal1 thus ?case using component_le_norm[of x i] unfolding c_def d_def
  1.3314          by(auto simp add:field_simps) qed
  1.3315 @@ -3850,7 +3896,7 @@
  1.3316  
  1.3317      have "y = i" proof(rule ccontr) assume "y\<noteq>i" hence "0 < norm (y - i)" by auto
  1.3318        from as[rule_format,OF this] guess C ..  note C=conjunctD2[OF this,rule_format]
  1.3319 -      def c \<equiv> "(\<chi> i. - max B C)::real^'n" and d \<equiv> "(\<chi> i. max B C)::real^'n"
  1.3320 +      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"
  1.3321        have c_d:"{a..b} \<subseteq> {c..d}" apply safe apply(drule B(2)) unfolding mem_interval
  1.3322        proof case goal1 thus ?case using component_le_norm[of x i] unfolding c_def d_def
  1.3323            by(auto simp add:field_simps) qed
  1.3324 @@ -3862,7 +3908,7 @@
  1.3325        thus False by auto qed
  1.3326      thus ?l using y unfolding s by auto qed qed 
  1.3327  
  1.3328 -lemma has_integral_trans[simp]: fixes f::"real^'n \<Rightarrow> real" shows
  1.3329 +(*lemma has_integral_trans[simp]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real" shows
  1.3330    "((\<lambda>x. vec1 (f x)) has_integral vec1 i) s \<longleftrightarrow> (f has_integral i) s"
  1.3331    unfolding has_integral'[unfolded has_integral] 
  1.3332  proof case goal1 thus ?case apply safe
  1.3333 @@ -3884,32 +3930,31 @@
  1.3334      Cart_nth.scaleR vec1_dest_vec1 zero_index apply assumption
  1.3335    apply(subst norm_vector_1) by auto qed
  1.3336  
  1.3337 -lemma integral_trans[simp]: assumes "(f::real^'n \<Rightarrow> real) integrable_on s"
  1.3338 +lemma integral_trans[simp]: assumes "(f::'n::ordered_euclidean_space \<Rightarrow> real) integrable_on s"
  1.3339    shows "integral s (\<lambda>x. vec1 (f x)) = vec1 (integral s f)"
  1.3340    apply(rule integral_unique) using assms by auto
  1.3341  
  1.3342 -lemma integrable_on_trans[simp]: fixes f::"real^'n \<Rightarrow> real" shows
  1.3343 +lemma integrable_on_trans[simp]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real" shows
  1.3344    "(\<lambda>x. vec1 (f x)) integrable_on s \<longleftrightarrow> (f integrable_on s)"
  1.3345    unfolding integrable_on_def
  1.3346    apply(subst(2) vec1_dest_vec1(1)[THEN sym]) unfolding has_integral_trans
  1.3347 -  apply safe defer apply(rule_tac x="vec1 y" in exI) by auto
  1.3348 -
  1.3349 -lemma has_integral_le: fixes f::"real^'n \<Rightarrow> real"
  1.3350 +  apply safe defer apply(rule_tac x="vec1 y" in exI) by auto *)
  1.3351 +
  1.3352 +lemma has_integral_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  1.3353    assumes "(f has_integral i) s" "(g has_integral j) s"  "\<forall>x\<in>s. (f x) \<le> (g x)"
  1.3354 -  shows "i \<le> j" using has_integral_component_le[of "vec1 o f" "vec1 i" s "vec1 o g" "vec1 j" 1]
  1.3355 -  unfolding o_def using assms by auto 
  1.3356 -
  1.3357 -lemma integral_le: fixes f::"real^'n \<Rightarrow> real"
  1.3358 +  shows "i \<le> j" using has_integral_component_le[OF assms(1-2), of 0] using assms(3) by auto
  1.3359 +
  1.3360 +lemma integral_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  1.3361    assumes "f integrable_on s" "g integrable_on s" "\<forall>x\<in>s. f x \<le> g x"
  1.3362    shows "integral s f \<le> integral s g"
  1.3363    using has_integral_le[OF assms(1,2)[unfolded has_integral_integral] assms(3)] .
  1.3364  
  1.3365 -lemma has_integral_nonneg: fixes f::"real^'n \<Rightarrow> real"
  1.3366 +lemma has_integral_nonneg: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  1.3367    assumes "(f has_integral i) s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> i" 
  1.3368 -  using has_integral_component_nonneg[of "vec1 o f" "vec1 i" s 1]
  1.3369 +  using has_integral_component_nonneg[of "f" "i" s 0]
  1.3370    unfolding o_def using assms by auto
  1.3371  
  1.3372 -lemma integral_nonneg: fixes f::"real^'n \<Rightarrow> real"
  1.3373 +lemma integral_nonneg: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  1.3374    assumes "f integrable_on s" "\<forall>x\<in>s. 0 \<le> f x" shows "0 \<le> integral s f" 
  1.3375    using has_integral_nonneg[OF assms(1)[unfolded has_integral_integral] assms(2)] .
  1.3376  
  1.3377 @@ -3920,10 +3965,10 @@
  1.3378  proof- have *:"\<And>x. (if x \<in> t then if x \<in> s then f x else 0 else 0) =  (if x\<in>s then f x else 0)" using assms by auto
  1.3379    show ?thesis apply(subst(2) has_integral') apply(subst has_integral') unfolding * by rule qed
  1.3380  
  1.3381 -lemma has_integral_restrict_univ: fixes f::"real^'n \<Rightarrow> 'a::banach" shows
  1.3382 +lemma has_integral_restrict_univ: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach" shows
  1.3383    "((\<lambda>x. if x \<in> s then f x else 0) has_integral i) UNIV \<longleftrightarrow> (f has_integral i) s" by auto
  1.3384  
  1.3385 -lemma has_integral_on_superset: fixes f::"real^'n \<Rightarrow> 'a::banach" 
  1.3386 +lemma has_integral_on_superset: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach" 
  1.3387    assumes "\<forall>x. ~(x \<in> s) \<longrightarrow> f x = 0" "s \<subseteq> t" "(f has_integral i) s"
  1.3388    shows "(f has_integral i) t"
  1.3389  proof- have "(\<lambda>x. if x \<in> s then f x else 0) = (\<lambda>x. if x \<in> t then f x else 0)"
  1.3390 @@ -3931,16 +3976,16 @@
  1.3391    thus ?thesis apply- using assms(3) apply(subst has_integral_restrict_univ[THEN sym])
  1.3392    apply- apply(subst(asm) has_integral_restrict_univ[THEN sym]) by auto qed
  1.3393  
  1.3394 -lemma integrable_on_superset: fixes f::"real^'n \<Rightarrow> 'a::banach" 
  1.3395 +lemma integrable_on_superset: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach" 
  1.3396    assumes "\<forall>x. ~(x \<in> s) \<longrightarrow> f x = 0" "s \<subseteq> t" "f integrable_on s"
  1.3397    shows "f integrable_on t"
  1.3398    using assms unfolding integrable_on_def by(auto intro:has_integral_on_superset)
  1.3399  
  1.3400 -lemma integral_restrict_univ[intro]: fixes f::"real^'n \<Rightarrow> 'a::banach" 
  1.3401 +lemma integral_restrict_univ[intro]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach" 
  1.3402    shows "f integrable_on s \<Longrightarrow> integral UNIV (\<lambda>x. if x \<in> s then f x else 0) = integral s f"
  1.3403    apply(rule integral_unique) unfolding has_integral_restrict_univ by auto
  1.3404  
  1.3405 -lemma integrable_restrict_univ: fixes f::"real^'n \<Rightarrow> 'a::banach" shows
  1.3406 +lemma integrable_restrict_univ: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach" shows
  1.3407   "(\<lambda>x. if x \<in> s then f x else 0) integrable_on UNIV \<longleftrightarrow> f integrable_on s"
  1.3408    unfolding integrable_on_def by auto
  1.3409  
  1.3410 @@ -3949,21 +3994,21 @@
  1.3411    proof safe case goal1 show ?case apply(rule has_integral_negligible[OF `?r`[rule_format,of a b]])
  1.3412        unfolding indicator_def by auto qed qed auto
  1.3413  
  1.3414 -lemma has_integral_spike_set_eq: fixes f::"real^'n \<Rightarrow> 'a::banach" 
  1.3415 +lemma has_integral_spike_set_eq: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach" 
  1.3416    assumes "negligible((s - t) \<union> (t - s))" shows "((f has_integral y) s \<longleftrightarrow> (f has_integral y) t)"
  1.3417    unfolding has_integral_restrict_univ[THEN sym,of f] apply(rule has_integral_spike_eq[OF assms]) by (safe, auto split: split_if_asm)
  1.3418  
  1.3419 -lemma has_integral_spike_set[dest]: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3420 +lemma has_integral_spike_set[dest]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3421    assumes "negligible((s - t) \<union> (t - s))" "(f has_integral y) s"
  1.3422    shows "(f has_integral y) t"
  1.3423    using assms has_integral_spike_set_eq by auto
  1.3424  
  1.3425 -lemma integrable_spike_set[dest]: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3426 +lemma integrable_spike_set[dest]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3427    assumes "negligible((s - t) \<union> (t - s))" "f integrable_on s"
  1.3428    shows "f integrable_on t" using assms(2) unfolding integrable_on_def 
  1.3429    unfolding has_integral_spike_set_eq[OF assms(1)] .
  1.3430  
  1.3431 -lemma integrable_spike_set_eq: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3432 +lemma integrable_spike_set_eq: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3433    assumes "negligible((s - t) \<union> (t - s))"
  1.3434    shows "(f integrable_on s \<longleftrightarrow> f integrable_on t)"
  1.3435    apply(rule,rule_tac[!] integrable_spike_set) using assms by auto
  1.3436 @@ -4002,29 +4047,28 @@
  1.3437  
  1.3438  subsection {* More lemmas that are useful later. *}
  1.3439  
  1.3440 -lemma has_integral_subset_component_le: fixes f::"real^'n \<Rightarrow> real^'m"
  1.3441 -  assumes "s \<subseteq> t" "(f has_integral i) s" "(f has_integral j) t" "\<forall>x\<in>t. 0 \<le> f(x)$k"
  1.3442 -  shows "i$k \<le> j$k"
  1.3443 +lemma has_integral_subset_component_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.3444 +  assumes "s \<subseteq> t" "(f has_integral i) s" "(f has_integral j) t" "\<forall>x\<in>t. 0 \<le> f(x)$$k"
  1.3445 +  shows "i$$k \<le> j$$k"
  1.3446  proof- note has_integral_restrict_univ[THEN sym, of f]
  1.3447    note assms(2-3)[unfolded this] note * = has_integral_component_le[OF this]
  1.3448    show ?thesis apply(rule *) using assms(1,4) by auto qed
  1.3449  
  1.3450 -lemma has_integral_subset_le: fixes f::"real^'n \<Rightarrow> real"
  1.3451 +lemma has_integral_subset_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  1.3452    assumes "s \<subseteq> t" "(f has_integral i) s" "(f has_integral j) t" "\<forall>x\<in>t. 0 \<le> f(x)"
  1.3453 -  shows "i \<le> j" using has_integral_subset_component_le[OF assms(1), of "vec1 o f" "vec1 i" "vec1 j" 1]
  1.3454 -  unfolding o_def using assms by auto
  1.3455 -
  1.3456 -lemma integral_subset_component_le: fixes f::"real^'n \<Rightarrow> real^'m"
  1.3457 -  assumes "s \<subseteq> t" "f integrable_on s" "f integrable_on t" "\<forall>x \<in> t. 0 \<le> f(x)$k"
  1.3458 -  shows "(integral s f)$k \<le> (integral t f)$k"
  1.3459 +  shows "i \<le> j" using has_integral_subset_component_le[OF assms(1), of "f" "i" "j" 0] using assms by auto
  1.3460 +
  1.3461 +lemma integral_subset_component_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.3462 +  assumes "s \<subseteq> t" "f integrable_on s" "f integrable_on t" "\<forall>x \<in> t. 0 \<le> f(x)$$k"
  1.3463 +  shows "(integral s f)$$k \<le> (integral t f)$$k"
  1.3464    apply(rule has_integral_subset_component_le) using assms by auto
  1.3465  
  1.3466 -lemma integral_subset_le: fixes f::"real^'n \<Rightarrow> real"
  1.3467 +lemma integral_subset_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  1.3468    assumes "s \<subseteq> t" "f integrable_on s" "f integrable_on t" "\<forall>x \<in> t. 0 \<le> f(x)"
  1.3469    shows "(integral s f) \<le> (integral t f)"
  1.3470    apply(rule has_integral_subset_le) using assms by auto
  1.3471  
  1.3472 -lemma has_integral_alt': fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3473 +lemma has_integral_alt': fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3474    shows "(f has_integral i) s \<longleftrightarrow> (\<forall>a b. (\<lambda>x. if x \<in> s then f x else 0) integrable_on {a..b}) \<and>
  1.3475    (\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> {a..b} \<longrightarrow> norm(integral {a..b} (\<lambda>x. if x \<in> s then f x else 0) - i) < e)" (is "?l = ?r")
  1.3476  proof assume ?r
  1.3477 @@ -4036,9 +4080,9 @@
  1.3478    qed next
  1.3479    assume ?l note as = this[unfolded has_integral'[of f],rule_format]
  1.3480    let ?f = "\<lambda>x. if x \<in> s then f x else 0"
  1.3481 -  show ?r proof safe fix a b::"real^'n"
  1.3482 +  show ?r proof safe fix a b::"'n::ordered_euclidean_space"
  1.3483      from as[OF zero_less_one] guess B .. note B=conjunctD2[OF this,rule_format]
  1.3484 -    let ?a = "(\<chi> i. min (a$i) (-B))::real^'n" and ?b = "(\<chi> i. max (b$i) B)::real^'n"
  1.3485 +    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"
  1.3486      show "?f integrable_on {a..b}" apply(rule integrable_subinterval[of _ ?a ?b])
  1.3487      proof- have "ball 0 B \<subseteq> {?a..?b}" apply safe unfolding mem_ball mem_interval dist_norm
  1.3488        proof case goal1 thus ?case using component_le_norm[of x i] by(auto simp add:field_simps) qed
  1.3489 @@ -4055,7 +4099,7 @@
  1.3490  
  1.3491  subsection {* Continuity of the integral (for a 1-dimensional interval). *}
  1.3492  
  1.3493 -lemma integrable_alt: fixes f::"real^'n \<Rightarrow> 'a::banach" shows 
  1.3494 +lemma integrable_alt: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach" shows 
  1.3495    "f integrable_on s \<longleftrightarrow>
  1.3496            (\<forall>a b. (\<lambda>x. if x \<in> s then f x else 0) integrable_on {a..b}) \<and>
  1.3497            (\<forall>e>0. \<exists>B>0. \<forall>a b c d. ball 0 B \<subseteq> {a..b} \<and> ball 0 B \<subseteq> {c..d}
  1.3498 @@ -4069,11 +4113,11 @@
  1.3499          using B(2)[OF goal1(1)] B(2)[OF goal1(2)] by auto qed qed
  1.3500          
  1.3501  next assume ?r note as = conjunctD2[OF this,rule_format]
  1.3502 -  have "Cauchy (\<lambda>n. integral ({(\<chi> i. - real n) .. (\<chi> i. real n)}) (\<lambda>x. if x \<in> s then f x else 0))"
  1.3503 +  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))"
  1.3504    proof(unfold Cauchy_def,safe) case goal1
  1.3505      from as(2)[OF this] guess B .. note B = conjunctD2[OF this,rule_format]
  1.3506      from real_arch_simple[of B] guess N .. note N = this
  1.3507 -    { fix n assume n:"n \<ge> N" have "ball 0 B \<subseteq> {\<chi> i. - real n..\<chi> i. real n}" apply safe
  1.3508 +    { 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
  1.3509          unfolding mem_ball mem_interval dist_norm
  1.3510        proof case goal1 thus ?case using component_le_norm[of x i]
  1.3511            using n N by(auto simp add:field_simps) qed }
  1.3512 @@ -4088,33 +4132,33 @@
  1.3513      from as(2)[OF *] guess B .. note B=conjunctD2[OF this,rule_format] let ?B = "max (real N) B"
  1.3514      show ?case apply(rule_tac x="?B" in exI)
  1.3515      proof safe show "0 < ?B" using B(1) by auto
  1.3516 -      fix a b assume ab:"ball 0 ?B \<subseteq> {a..b::real^'n}"
  1.3517 +      fix a b assume ab:"ball 0 ?B \<subseteq> {a..b::'n::ordered_euclidean_space}"
  1.3518        from real_arch_simple[of ?B] guess n .. note n=this
  1.3519        show "norm (integral {a..b} (\<lambda>x. if x \<in> s then f x else 0) - i) < e"
  1.3520          apply(rule norm_triangle_half_l) apply(rule B(2)) defer apply(subst norm_minus_commute)
  1.3521          apply(rule N[unfolded dist_norm, of n])
  1.3522        proof safe show "N \<le> n" using n by auto
  1.3523 -        fix x::"real^'n" assume x:"x \<in> ball 0 B" hence "x\<in> ball 0 ?B" by auto
  1.3524 +        fix x::"'n::ordered_euclidean_space" assume x:"x \<in> ball 0 B" hence "x\<in> ball 0 ?B" by auto
  1.3525          thus "x\<in>{a..b}" using ab by blast 
  1.3526 -        show "x\<in>{\<chi> i. - real n..\<chi> i. real n}" using x unfolding mem_interval mem_ball dist_norm apply-
  1.3527 +        show "x\<in>{\<chi>\<chi> i. - real n..\<chi>\<chi> i. real n}" using x unfolding mem_interval mem_ball dist_norm apply-
  1.3528          proof case goal1 thus ?case using component_le_norm[of x i]
  1.3529              using n by(auto simp add:field_simps) qed qed qed qed qed
  1.3530  
  1.3531 -lemma integrable_altD: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3532 +lemma integrable_altD: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3533    assumes "f integrable_on s"
  1.3534    shows "\<And>a b. (\<lambda>x. if x \<in> s then f x else 0) integrable_on {a..b}"
  1.3535    "\<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}
  1.3536    \<longrightarrow> norm(integral {a..b} (\<lambda>x. if x \<in> s then f x else 0) - integral {c..d}  (\<lambda>x. if x \<in> s then f x else 0)) < e"
  1.3537    using assms[unfolded integrable_alt[of f]] by auto
  1.3538  
  1.3539 -lemma integrable_on_subinterval: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3540 +lemma integrable_on_subinterval: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3541    assumes "f integrable_on s" "{a..b} \<subseteq> s" shows "f integrable_on {a..b}"
  1.3542    apply(rule integrable_eq) defer apply(rule integrable_altD(1)[OF assms(1)])
  1.3543    using assms(2) by auto
  1.3544  
  1.3545  subsection {* A straddling criterion for integrability. *}
  1.3546  
  1.3547 -lemma integrable_straddle_interval: fixes f::"real^'n \<Rightarrow> real"
  1.3548 +lemma integrable_straddle_interval: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  1.3549    assumes "\<forall>e>0. \<exists>g  h i j. (g has_integral i) ({a..b}) \<and> (h has_integral j) ({a..b}) \<and>
  1.3550    norm(i - j) < e \<and> (\<forall>x\<in>{a..b}. (g x) \<le> (f x) \<and> (f x) \<le>(h x))"
  1.3551    shows "f integrable_on {a..b}"
  1.3552 @@ -4150,7 +4194,7 @@
  1.3553        apply(rule d2(2)[OF conjI[OF goal1(4,6)]])
  1.3554        apply(rule d2(2)[OF conjI[OF goal1(1,3)]]) by auto qed qed 
  1.3555       
  1.3556 -lemma integrable_straddle: fixes f::"real^'n \<Rightarrow> real"
  1.3557 +lemma integrable_straddle: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  1.3558    assumes "\<forall>e>0. \<exists>g h i j. (g has_integral i) s \<and> (h has_integral j) s \<and>
  1.3559    norm(i - j) < e \<and> (\<forall>x\<in>s. (g x) \<le>(f x) \<and>(f x) \<le>(h x))"
  1.3560    shows "f integrable_on s"
  1.3561 @@ -4161,7 +4205,7 @@
  1.3562      note g = this(1) and this(2)[OF *] from this(2) guess B1 .. note B1 = conjunctD2[OF this,rule_format]
  1.3563      note obt(2)[unfolded has_integral_alt'[of h]] note conjunctD2[OF this, rule_format]
  1.3564      note h = this(1) and this(2)[OF *] from this(2) guess B2 .. note B2 = conjunctD2[OF this,rule_format]
  1.3565 -    def c \<equiv> "\<chi> i. min (a$i) (- (max B1 B2))" and d \<equiv> "\<chi> i. max (b$i) (max B1 B2)"
  1.3566 +    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"
  1.3567      have *:"ball 0 B1 \<subseteq> {c..d}" "ball 0 B2 \<subseteq> {c..d}" apply safe unfolding mem_ball mem_interval dist_norm
  1.3568      proof(rule_tac[!] allI)
  1.3569        case goal1 thus ?case using component_le_norm[of x i] unfolding c_def d_def by auto next
  1.3570 @@ -4196,8 +4240,8 @@
  1.3571      note obt(2)[unfolded has_integral_alt'[of h]] note conjunctD2[OF this, rule_format]
  1.3572      note h = this(1) and this(2)[OF *] from this(2) guess B2 .. note B2 = conjunctD2[OF this,rule_format]
  1.3573      show ?case apply(rule_tac x="max B1 B2" in exI) apply safe apply(rule min_max.less_supI1,rule B1)
  1.3574 -    proof- fix a b c d::"real^'n" assume as:"ball 0 (max B1 B2) \<subseteq> {a..b}" "ball 0 (max B1 B2) \<subseteq> {c..d}"
  1.3575 -      have **:"ball 0 B1 \<subseteq> ball (0::real^'n) (max B1 B2)" "ball 0 B2 \<subseteq> ball (0::real^'n) (max B1 B2)" by auto
  1.3576 +    proof- fix a b c d::"'n::ordered_euclidean_space" assume as:"ball 0 (max B1 B2) \<subseteq> {a..b}" "ball 0 (max B1 B2) \<subseteq> {c..d}"
  1.3577 +      have **:"ball 0 B1 \<subseteq> ball (0::'n::ordered_euclidean_space) (max B1 B2)" "ball 0 B2 \<subseteq> ball (0::'n::ordered_euclidean_space) (max B1 B2)" by auto
  1.3578        have *:"\<And>ga gc ha hc fa fc::real. abs(ga - i) < e / 3 \<and> abs(gc - i) < e / 3 \<and> abs(ha - j) < e / 3 \<and>
  1.3579          abs(hc - j) < e / 3 \<and> abs(i - j) < e / 3 \<and> ga \<le> fa \<and> fa \<le> ha \<and> gc \<le> fc \<and> fc \<le> hc\<Longrightarrow> abs(fa - fc) < e" by smt
  1.3580        show "norm (integral {a..b} (\<lambda>x. if x \<in> s then f x else 0) - integral {c..d} (\<lambda>x. if x \<in> s then f x else 0)) < e"
  1.3581 @@ -4211,14 +4255,14 @@
  1.3582  
  1.3583  subsection {* Adding integrals over several sets. *}
  1.3584  
  1.3585 -lemma has_integral_union: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3586 +lemma has_integral_union: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3587    assumes "(f has_integral i) s" "(f has_integral j) t" "negligible(s \<inter> t)"
  1.3588    shows "(f has_integral (i + j)) (s \<union> t)"
  1.3589  proof- note * = has_integral_restrict_univ[THEN sym, of f]
  1.3590    show ?thesis unfolding * apply(rule has_integral_spike[OF assms(3)])
  1.3591      defer apply(rule has_integral_add[OF assms(1-2)[unfolded *]]) by auto qed
  1.3592  
  1.3593 -lemma has_integral_unions: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3594 +lemma has_integral_unions: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3595    assumes "finite t" "\<forall>s\<in>t. (f has_integral (i s)) s"  "\<forall>s\<in>t. \<forall>s'\<in>t. ~(s = s') \<longrightarrow> negligible(s \<inter> s')"
  1.3596    shows "(f has_integral (setsum i t)) (\<Union>t)"
  1.3597  proof- note * = has_integral_restrict_univ[THEN sym, of f]
  1.3598 @@ -4236,7 +4280,7 @@
  1.3599  
  1.3600  subsection {* In particular adding integrals over a division, maybe not of an interval. *}
  1.3601  
  1.3602 -lemma has_integral_combine_division: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3603 +lemma has_integral_combine_division: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3604    assumes "d division_of s" "\<forall>k\<in>d. (f has_integral (i k)) k"
  1.3605    shows "(f has_integral (setsum i d)) s"
  1.3606  proof- note d = division_ofD[OF assms(1)]
  1.3607 @@ -4248,13 +4292,13 @@
  1.3608        apply-apply(rule negligible_subset[of "({a..b}-{a<..<b}) \<union> ({c..d}-{c<..<d})"])
  1.3609        apply(rule negligible_union negligible_frontier_interval)+ by auto qed qed
  1.3610  
  1.3611 -lemma integral_combine_division_bottomup: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3612 +lemma integral_combine_division_bottomup: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3613    assumes "d division_of s" "\<forall>k\<in>d. f integrable_on k"
  1.3614    shows "integral s f = setsum (\<lambda>i. integral i f) d"
  1.3615    apply(rule integral_unique) apply(rule has_integral_combine_division[OF assms(1)])
  1.3616    using assms(2) unfolding has_integral_integral .
  1.3617  
  1.3618 -lemma has_integral_combine_division_topdown: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3619 +lemma has_integral_combine_division_topdown: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3620    assumes "f integrable_on s" "d division_of k" "k \<subseteq> s"
  1.3621    shows "(f has_integral (setsum (\<lambda>i. integral i f) d)) k"
  1.3622    apply(rule has_integral_combine_division[OF assms(2)])
  1.3623 @@ -4263,18 +4307,18 @@
  1.3624    show ?case apply safe apply(rule integrable_on_subinterval)
  1.3625      apply(rule assms) using assms(3) by auto qed
  1.3626  
  1.3627 -lemma integral_combine_division_topdown: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3628 +lemma integral_combine_division_topdown: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3629    assumes "f integrable_on s" "d division_of s"
  1.3630    shows "integral s f = setsum (\<lambda>i. integral i f) d"
  1.3631    apply(rule integral_unique,rule has_integral_combine_division_topdown) using assms by auto
  1.3632  
  1.3633 -lemma integrable_combine_division: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3634 +lemma integrable_combine_division: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3635    assumes "d division_of s" "\<forall>i\<in>d. f integrable_on i"
  1.3636    shows "f integrable_on s"
  1.3637    using assms(2) unfolding integrable_on_def
  1.3638    by(metis has_integral_combine_division[OF assms(1)])
  1.3639  
  1.3640 -lemma integrable_on_subdivision: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3641 +lemma integrable_on_subdivision: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3642    assumes "d division_of i" "f integrable_on s" "i \<subseteq> s"
  1.3643    shows "f integrable_on i"
  1.3644    apply(rule integrable_combine_division assms)+
  1.3645 @@ -4284,7 +4328,7 @@
  1.3646  
  1.3647  subsection {* Also tagged divisions. *}
  1.3648  
  1.3649 -lemma has_integral_combine_tagged_division: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3650 +lemma has_integral_combine_tagged_division: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3651    assumes "p tagged_division_of s" "\<forall>(x,k) \<in> p. (f has_integral (i k)) k"
  1.3652    shows "(f has_integral (setsum (\<lambda>(x,k). i k) p)) s"
  1.3653  proof- have *:"(f has_integral (setsum (\<lambda>k. integral k f) (snd ` p))) s"
  1.3654 @@ -4295,27 +4339,27 @@
  1.3655      apply(rule setsum_over_tagged_division_lemma[OF assms(1)]) apply(rule integral_null,assumption)
  1.3656      apply(rule setsum_cong2) using assms(2) by auto qed
  1.3657  
  1.3658 -lemma integral_combine_tagged_division_bottomup: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3659 +lemma integral_combine_tagged_division_bottomup: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3660    assumes "p tagged_division_of {a..b}" "\<forall>(x,k)\<in>p. f integrable_on k"
  1.3661    shows "integral {a..b} f = setsum (\<lambda>(x,k). integral k f) p"
  1.3662    apply(rule integral_unique) apply(rule has_integral_combine_tagged_division[OF assms(1)])
  1.3663    using assms(2) by auto
  1.3664  
  1.3665 -lemma has_integral_combine_tagged_division_topdown: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3666 +lemma has_integral_combine_tagged_division_topdown: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3667    assumes "f integrable_on {a..b}" "p tagged_division_of {a..b}"
  1.3668    shows "(f has_integral (setsum (\<lambda>(x,k). integral k f) p)) {a..b}"
  1.3669    apply(rule has_integral_combine_tagged_division[OF assms(2)])
  1.3670  proof safe case goal1 note tagged_division_ofD(3-4)[OF assms(2) this]
  1.3671    thus ?case using integrable_subinterval[OF assms(1)] by auto qed
  1.3672  
  1.3673 -lemma integral_combine_tagged_division_topdown: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3674 +lemma integral_combine_tagged_division_topdown: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3675    assumes "f integrable_on {a..b}" "p tagged_division_of {a..b}"
  1.3676    shows "integral {a..b} f = setsum (\<lambda>(x,k). integral k f) p"
  1.3677    apply(rule integral_unique,rule has_integral_combine_tagged_division_topdown) using assms by auto
  1.3678  
  1.3679  subsection {* Henstock's lemma. *}
  1.3680  
  1.3681 -lemma henstock_lemma_part1: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3682 +lemma henstock_lemma_part1: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3683    assumes "f integrable_on {a..b}" "0 < e" "gauge d"
  1.3684    "(\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> norm (setsum (\<lambda>(x,k). content k *\<^sub>R f x) p - integral({a..b}) f) < e)"
  1.3685    and p:"p tagged_partial_division_of {a..b}" "d fine p"
  1.3686 @@ -4415,23 +4459,23 @@
  1.3687        unfolding divide_inverse[THEN sym] using * by(auto simp add:field_simps real_eq_of_nat)
  1.3688    qed finally show "?x \<le> e + k" . qed
  1.3689  
  1.3690 -lemma henstock_lemma_part2: fixes f::"real^'m \<Rightarrow> real^'n"
  1.3691 +lemma henstock_lemma_part2: fixes f::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space"
  1.3692    assumes "f integrable_on {a..b}" "0 < e" "gauge d"
  1.3693    "\<forall>p. p tagged_division_of {a..b} \<and> d fine p \<longrightarrow> norm (setsum (\<lambda>(x,k). content k *\<^sub>R f x) p -
  1.3694            integral({a..b}) f) < e"    "p tagged_partial_division_of {a..b}" "d fine p"
  1.3695 -  shows "setsum (\<lambda>(x,k). norm(content k *\<^sub>R f x - integral k f)) p \<le> 2 * real (CARD('n)) * e"
  1.3696 -  unfolding split_def apply(rule vsum_norm_allsubsets_bound) defer 
  1.3697 +  shows "setsum (\<lambda>(x,k). norm(content k *\<^sub>R f x - integral k f)) p \<le> 2 * real (DIM('n)) * e"
  1.3698 +  unfolding split_def apply(rule setsum_norm_allsubsets_bound) defer 
  1.3699    apply(rule henstock_lemma_part1[unfolded split_def,OF assms(1-3)])
  1.3700    apply safe apply(rule assms[rule_format,unfolded split_def]) defer
  1.3701    apply(rule tagged_partial_division_subset,rule assms,assumption)
  1.3702    apply(rule fine_subset,assumption,rule assms) using assms(5) by auto
  1.3703    
  1.3704 -lemma henstock_lemma: fixes f::"real^'m \<Rightarrow> real^'n"
  1.3705 +lemma henstock_lemma: fixes f::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space"
  1.3706    assumes "f integrable_on {a..b}" "e>0"
  1.3707    obtains d where "gauge d"
  1.3708    "\<forall>p. p tagged_partial_division_of {a..b} \<and> d fine p
  1.3709    \<longrightarrow> setsum (\<lambda>(x,k). norm(content k *\<^sub>R f x - integral k f)) p < e"
  1.3710 -proof- have *:"e / (2 * (real CARD('n) + 1)) > 0" apply(rule divide_pos_pos) using assms(2) by auto
  1.3711 +proof- have *:"e / (2 * (real DIM('n) + 1)) > 0" apply(rule divide_pos_pos) using assms(2) by auto
  1.3712    from integrable_integral[OF assms(1),unfolded has_integral[of f],rule_format,OF this]
  1.3713    guess d .. note d = conjunctD2[OF this] show thesis apply(rule that,rule d)
  1.3714    proof safe case goal1 note * = henstock_lemma_part2[OF assms(1) * d this]
  1.3715 @@ -4439,16 +4483,16 @@
  1.3716  
  1.3717  subsection {* monotone convergence (bounded interval first). *}
  1.3718  
  1.3719 -lemma monotone_convergence_interval: fixes f::"nat \<Rightarrow> real^'n \<Rightarrow> real^1"
  1.3720 +lemma monotone_convergence_interval: fixes f::"nat \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> real"
  1.3721    assumes "\<forall>k. (f k) integrable_on {a..b}"
  1.3722 -  "\<forall>k. \<forall>x\<in>{a..b}. dest_vec1(f k x) \<le> dest_vec1(f (Suc k) x)"
  1.3723 +  "\<forall>k. \<forall>x\<in>{a..b}.(f k x) \<le> (f (Suc k) x)"
  1.3724    "\<forall>x\<in>{a..b}. ((\<lambda>k. f k x) ---> g x) sequentially"
  1.3725    "bounded {integral {a..b} (f k) | k . k \<in> UNIV}"
  1.3726    shows "g integrable_on {a..b} \<and> ((\<lambda>k. integral ({a..b}) (f k)) ---> integral ({a..b}) g) sequentially"
  1.3727  proof(case_tac[!] "content {a..b} = 0") assume as:"content {a..b} = 0"
  1.3728    show ?thesis using integrable_on_null[OF as] unfolding integral_null[OF as] using Lim_const by auto
  1.3729  next assume ab:"content {a..b} \<noteq> 0"
  1.3730 -  have fg:"\<forall>x\<in>{a..b}. \<forall> k. (f k x)$1 \<le> (g x)$1"
  1.3731 +  have fg:"\<forall>x\<in>{a..b}. \<forall> k. (f k x) $$ 0 \<le> (g x) $$ 0"
  1.3732    proof safe case goal1 note assms(3)[rule_format,OF this]
  1.3733      note * = Lim_component_ge[OF this trivial_limit_sequentially]
  1.3734      show ?case apply(rule *) unfolding eventually_sequentially
  1.3735 @@ -4456,13 +4500,13 @@
  1.3736        using assms(2)[rule_format,OF goal1] by auto qed
  1.3737    have "\<exists>i. ((\<lambda>k. integral ({a..b}) (f k)) ---> i) sequentially"
  1.3738      apply(rule bounded_increasing_convergent) defer
  1.3739 -    apply rule apply(rule integral_component_le) apply safe
  1.3740 +    apply rule apply(rule integral_le) apply safe
  1.3741      apply(rule assms(1-2)[rule_format])+ using assms(4) by auto
  1.3742    then guess i .. note i=this
  1.3743 -  have i':"\<And>k. dest_vec1(integral({a..b}) (f k)) \<le> dest_vec1 i"
  1.3744 +  have i':"\<And>k. (integral({a..b}) (f k)) \<le> i$$0"
  1.3745      apply(rule Lim_component_ge,rule i) apply(rule trivial_limit_sequentially)
  1.3746      unfolding eventually_sequentially apply(rule_tac x=k in exI)
  1.3747 -    apply(rule transitive_stepwise_le) prefer 3 apply(rule integral_dest_vec1_le)
  1.3748 +    apply(rule transitive_stepwise_le) prefer 3 unfolding Eucl_real_simps apply(rule integral_le)
  1.3749      apply(rule assms(1-2)[rule_format])+ using assms(2) by auto
  1.3750  
  1.3751    have "(g has_integral i) {a..b}" unfolding has_integral
  1.3752 @@ -4473,23 +4517,22 @@
  1.3753        apply(rule divide_pos_pos) by auto
  1.3754      from choice[OF this] guess c .. note c=conjunctD2[OF this[rule_format],rule_format]
  1.3755  
  1.3756 -    have "\<exists>r. \<forall>k\<ge>r. 0 \<le> i$1 - dest_vec1(integral {a..b} (f k)) \<and>
  1.3757 -                   i$1 - dest_vec1(integral {a..b} (f k)) < e / 4"
  1.3758 +    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"
  1.3759      proof- case goal1 have "e/4 > 0" using e by auto
  1.3760        from i[unfolded Lim_sequentially,rule_format,OF this] guess r ..
  1.3761        thus ?case apply(rule_tac x=r in exI) apply rule
  1.3762          apply(erule_tac x=k in allE)
  1.3763 -      proof- case goal1 thus ?case using i'[of k] unfolding dist_real by auto qed qed
  1.3764 +      proof- case goal1 thus ?case using i'[of k] unfolding dist_real_def by auto qed qed
  1.3765      then guess r .. note r=conjunctD2[OF this[rule_format]]
  1.3766  
  1.3767 -    have "\<forall>x\<in>{a..b}. \<exists>n\<ge>r. \<forall>k\<ge>n. 0 \<le> (g x)$1 - (f k x)$1 \<and>
  1.3768 -           (g x)$1 - (f k x)$1 < e / (4 * content({a..b}))"
  1.3769 +    have "\<forall>x\<in>{a..b}. \<exists>n\<ge>r. \<forall>k\<ge>n. 0 \<le> (g x)$$0 - (f k x)$$0 \<and>
  1.3770 +           (g x)$$0 - (f k x)$$0 < e / (4 * content({a..b}))"
  1.3771      proof case goal1 have "e / (4 * content {a..b}) > 0" apply(rule divide_pos_pos,fact)
  1.3772          using ab content_pos_le[of a b] by auto
  1.3773        from assms(3)[rule_format,OF goal1,unfolded Lim_sequentially,rule_format,OF this]
  1.3774        guess n .. note n=this
  1.3775        thus ?case apply(rule_tac x="n + r" in exI) apply safe apply(erule_tac[2-3] x=k in allE)
  1.3776 -        unfolding dist_real using fg[rule_format,OF goal1] by(auto simp add:field_simps) qed
  1.3777 +        unfolding dist_real_def using fg[rule_format,OF goal1] by(auto simp add:field_simps) qed
  1.3778      from bchoice[OF this] guess m .. note m=conjunctD2[OF this[rule_format],rule_format]
  1.3779      def d \<equiv> "\<lambda>x. c (m x) x" 
  1.3780  
  1.3781 @@ -4516,7 +4559,7 @@
  1.3782             from p'(4)[OF xk] guess u v apply-by(erule exE)+ note uv=this
  1.3783             show " norm (content k *\<^sub>R (g x - f (m x) x)) \<le> content k * (e / (4 * content {a..b}))"
  1.3784               unfolding norm_scaleR uv unfolding abs_of_nonneg[OF content_pos_le] 
  1.3785 -             apply(rule mult_left_mono) unfolding norm_real using m(2)[OF x,of "m x"] by auto
  1.3786 +             apply(rule mult_left_mono) using m(2)[OF x,of "m x"] by auto
  1.3787           qed(insert ab,auto)
  1.3788           
  1.3789         next case goal2 show ?case apply(rule le_less_trans[of _ "norm (\<Sum>j = 0..s.
  1.3790 @@ -4547,47 +4590,47 @@
  1.3791  
  1.3792         next case goal3
  1.3793           note comb = integral_combine_tagged_division_topdown[OF assms(1)[rule_format] p(1)]
  1.3794 -         have *:"\<And>sr sx ss ks kr::real^1. kr = sr \<longrightarrow> ks = ss \<longrightarrow> ks \<le> i \<and> sr \<le> sx \<and> sx \<le> ss \<and> 0 \<le> i$1 - kr$1
  1.3795 -           \<and> i$1 - kr$1 < e/4 \<longrightarrow> abs(sx$1 - i$1) < e/4" unfolding Cart_eq forall_1 vector_le_def by arith
  1.3796 -         show ?case unfolding norm_real Cart_nth.diff apply(rule *[rule_format],safe)
  1.3797 -           apply(rule comb[of r],rule comb[of s]) unfolding vector_le_def forall_1 setsum_component
  1.3798 -           apply(rule i') apply(rule_tac[1-2] setsum_mono) unfolding split_paired_all split_conv
  1.3799 -           apply(rule_tac[1-2] integral_component_le[OF ])
  1.3800 -         proof safe show "0 \<le> i$1 - (integral {a..b} (f r))$1" using r(1) by auto
  1.3801 -           show "i$1 - (integral {a..b} (f r))$1 < e / 4" using r(2) by auto
  1.3802 +         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
  1.3803 +           \<and> i$$0 - kr$$0 < e/4 \<longrightarrow> abs(sx - i) < e/4" by auto 
  1.3804 +         show ?case unfolding real_norm_def apply(rule *[rule_format],safe)
  1.3805 +           apply(rule comb[of r],rule comb[of s]) apply(rule i'[unfolded Eucl_real_simps]) 
  1.3806 +           apply(rule_tac[1-2] setsum_mono) unfolding split_paired_all split_conv
  1.3807 +           apply(rule_tac[1-2] integral_le[OF ])
  1.3808 +         proof safe show "0 \<le> i$$0 - (integral {a..b} (f r))$$0" using r(1) by auto
  1.3809 +           show "i$$0 - (integral {a..b} (f r))$$0 < e / 4" using r(2) by auto
  1.3810             fix x k assume xk:"(x,k)\<in>p" from p'(4)[OF this] guess u v apply-by(erule exE)+ note uv=this
  1.3811             show "f r integrable_on k" "f s integrable_on k" "f (m x) integrable_on k" "f (m x) integrable_on k" 
  1.3812               unfolding uv apply(rule_tac[!] integrable_on_subinterval[OF assms(1)[rule_format]])
  1.3813               using p'(3)[OF xk] unfolding uv by auto 
  1.3814             fix y assume "y\<in>k" hence "y\<in>{a..b}" using p'(3)[OF xk] by auto
  1.3815 -           hence *:"\<And>m. \<forall>n\<ge>m. (f m y)$1 \<le> (f n y)$1" apply-apply(rule transitive_stepwise_le) using assms(2) by auto
  1.3816 -           show "(f r y)$1 \<le> (f (m x) y)$1" "(f (m x) y)$1 \<le> (f s y)$1"
  1.3817 +           hence *:"\<And>m. \<forall>n\<ge>m. (f m y) \<le> (f n y)" apply-apply(rule transitive_stepwise_le) using assms(2) by auto
  1.3818 +           show "(f r y) \<le> (f (m x) y)" "(f (m x) y) \<le> (f s y)"
  1.3819               apply(rule_tac[!] *[rule_format]) using s[rule_format,OF xk] m(1)[of x] p'(2-3)[OF xk] by auto
  1.3820           qed qed qed qed note * = this 
  1.3821  
  1.3822     have "integral {a..b} g = i" apply(rule integral_unique) using * .
  1.3823     thus ?thesis using i * by auto qed
  1.3824  
  1.3825 -lemma monotone_convergence_increasing: fixes f::"nat \<Rightarrow> real^'n \<Rightarrow> real^1"
  1.3826 -  assumes "\<forall>k. (f k) integrable_on s"  "\<forall>k. \<forall>x\<in>s. (f k x)$1 \<le> (f (Suc k) x)$1"
  1.3827 +lemma monotone_convergence_increasing: fixes f::"nat \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> real"
  1.3828 +  assumes "\<forall>k. (f k) integrable_on s"  "\<forall>k. \<forall>x\<in>s. (f k x) \<le> (f (Suc k) x)"
  1.3829    "\<forall>x\<in>s. ((\<lambda>k. f k x) ---> g x) sequentially" "bounded {integral s (f k)| k. True}"
  1.3830    shows "g integrable_on s \<and> ((\<lambda>k. integral s (f k)) ---> integral s g) sequentially"
  1.3831 -proof- have lem:"\<And>f::nat \<Rightarrow> real^'n \<Rightarrow> real^1. \<And> g s. \<forall>k.\<forall>x\<in>s. 0\<le>dest_vec1 (f k x) \<Longrightarrow> \<forall>k. (f k) integrable_on s \<Longrightarrow>
  1.3832 -    \<forall>k. \<forall>x\<in>s. (f k x)$1 \<le> (f (Suc k) x)$1 \<Longrightarrow> \<forall>x\<in>s. ((\<lambda>k. f k x) ---> g x) sequentially  \<Longrightarrow>
  1.3833 +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>
  1.3834 +    \<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>
  1.3835      bounded {integral s (f k)| k. True} \<Longrightarrow> g integrable_on s \<and> ((\<lambda>k. integral s (f k)) ---> integral s g) sequentially"
  1.3836    proof- case goal1 note assms=this[rule_format]
  1.3837 -    have "\<forall>x\<in>s. \<forall>k. dest_vec1(f k x) \<le> dest_vec1(g x)" apply safe apply(rule Lim_component_ge)
  1.3838 +    have "\<forall>x\<in>s. \<forall>k. (f k x)$$0 \<le> (g x)$$0" apply safe apply(rule Lim_component_ge)
  1.3839        apply(rule goal1(4)[rule_format],assumption) apply(rule trivial_limit_sequentially)
  1.3840        unfolding eventually_sequentially apply(rule_tac x=k in exI)
  1.3841        apply(rule transitive_stepwise_le) using goal1(3) by auto note fg=this[rule_format]
  1.3842  
  1.3843      have "\<exists>i. ((\<lambda>k. integral s (f k)) ---> i) sequentially" apply(rule bounded_increasing_convergent)
  1.3844 -      apply(rule goal1(5)) apply(rule,rule integral_component_le) apply(rule goal1(2)[rule_format])+
  1.3845 +      apply(rule goal1(5)) apply(rule,rule integral_le) apply(rule goal1(2)[rule_format])+
  1.3846        using goal1(3) by auto then guess i .. note i=this
  1.3847      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
  1.3848 -    hence i':"\<forall>k. (integral s (f k))$1 \<le> i$1" apply-apply(rule,rule Lim_component_ge)
  1.3849 +    hence i':"\<forall>k. (integral s (f k))$$0 \<le> i$$0" apply-apply(rule,rule Lim_component_ge)
  1.3850        apply(rule i,rule trivial_limit_sequentially) unfolding eventually_sequentially
  1.3851 -      apply(rule_tac x=k in exI,safe) apply(rule integral_dest_vec1_le)
  1.3852 +      apply(rule_tac x=k in exI,safe) apply(rule integral_component_le)
  1.3853        apply(rule goal1(2)[rule_format])+ by auto 
  1.3854  
  1.3855      note int = assms(2)[unfolded integrable_alt[of _ s],THEN conjunct1,rule_format]
  1.3856 @@ -4602,14 +4645,14 @@
  1.3857        case goal1 show ?case using int .
  1.3858      next case goal2 thus ?case apply-apply(cases "x\<in>s") using assms(3) by auto
  1.3859      next case goal3 thus ?case apply-apply(cases "x\<in>s") using assms(4) by auto
  1.3860 -    next case goal4 note * = integral_dest_vec1_nonneg[unfolded vector_le_def forall_1 zero_index]
  1.3861 +    next case goal4 note * = integral_nonneg
  1.3862        have "\<And>k. norm (integral {a..b} (\<lambda>x. if x \<in> s then f k x else 0)) \<le> norm (integral s (f k))"
  1.3863 -        unfolding norm_real apply(subst abs_of_nonneg) apply(rule *[OF int])
  1.3864 +        unfolding real_norm_def apply(subst abs_of_nonneg) apply(rule *[OF int])
  1.3865          apply(safe,case_tac "x\<in>s") apply(drule assms(1)) prefer 3
  1.3866          apply(subst abs_of_nonneg) apply(rule *[OF assms(2) goal1(1)[THEN spec]])
  1.3867          apply(subst integral_restrict_univ[THEN sym,OF int]) 
  1.3868          unfolding ifif unfolding integral_restrict_univ[OF int']
  1.3869 -        apply(rule integral_subset_component_le[OF _ int' assms(2)]) using assms(1) by auto
  1.3870 +        apply(rule integral_subset_le[OF _ int' assms(2)]) using assms(1) by auto
  1.3871        thus ?case using assms(5) unfolding bounded_iff apply safe
  1.3872          apply(rule_tac x=aa in exI,safe) apply(erule_tac x="integral s (f k)" in ballE)
  1.3873          apply(rule order_trans) apply assumption by auto qed note g = conjunctD2[OF this]
  1.3874 @@ -4620,31 +4663,31 @@
  1.3875        note assms(2)[of N,unfolded has_integral_integral has_integral_alt'[of "f N"]]
  1.3876        from this[THEN conjunct2,rule_format,OF `e/4>0`] guess B .. note B=conjunctD2[OF this]
  1.3877        show ?case apply(rule,rule,rule B,safe)
  1.3878 -      proof- fix a b::"real^'n" assume ab:"ball 0 B \<subseteq> {a..b}"
  1.3879 +      proof- fix a b::"'n::ordered_euclidean_space" assume ab:"ball 0 B \<subseteq> {a..b}"
  1.3880          from `e>0` have "e/2>0" by auto
  1.3881          from g(2)[unfolded Lim_sequentially,of a b,rule_format,OF this] guess M .. note M=this
  1.3882          have **:"norm (integral {a..b} (\<lambda>x. if x \<in> s then f N x else 0) - i) < e/2"
  1.3883            apply(rule norm_triangle_half_l) using B(2)[rule_format,OF ab] N[rule_format,of N]
  1.3884            unfolding dist_norm apply-defer apply(subst norm_minus_commute) by auto
  1.3885 -        have *:"\<And>f1 f2 g. abs(f1 - i$1) < e / 2 \<longrightarrow> abs(f2 - g) < e / 2 \<longrightarrow> f1 \<le> f2 \<longrightarrow> f2 \<le> i$1
  1.3886 -          \<longrightarrow> abs(g - i$1) < e" by arith
  1.3887 +        have *:"\<And>f1 f2 g. abs(f1 - i) < e / 2 \<longrightarrow> abs(f2 - g) < e / 2 \<longrightarrow> f1 \<le> f2 \<longrightarrow> f2 \<le> i
  1.3888 +          \<longrightarrow> abs(g - i) < e" unfolding Eucl_real_simps by arith
  1.3889          show "norm (integral {a..b} (\<lambda>x. if x \<in> s then g x else 0) - i) < e" 
  1.3890 -          unfolding norm_real Cart_simps apply(rule *[rule_format])
  1.3891 -          apply(rule **[unfolded norm_real Cart_simps])
  1.3892 -          apply(rule M[rule_format,of "M + N",unfolded dist_real]) apply(rule le_add1)
  1.3893 -          apply(rule integral_component_le[OF int int]) defer
  1.3894 -          apply(rule order_trans[OF _ i'[rule_format,of "M + N"]])
  1.3895 -        proof safe case goal2 have "\<And>m. x\<in>s \<Longrightarrow> \<forall>n\<ge>m. (f m x)$1 \<le> (f n x)$1"
  1.3896 +          unfolding real_norm_def apply(rule *[rule_format])
  1.3897 +          apply(rule **[unfolded real_norm_def])
  1.3898 +          apply(rule M[rule_format,of "M + N",unfolded dist_real_def]) apply(rule le_add1)
  1.3899 +          apply(rule integral_le[OF int int]) defer
  1.3900 +          apply(rule order_trans[OF _ i'[rule_format,of "M + N",unfolded Eucl_real_simps]])
  1.3901 +        proof safe case goal2 have "\<And>m. x\<in>s \<Longrightarrow> \<forall>n\<ge>m. (f m x)$$0 \<le> (f n x)$$0"
  1.3902              apply(rule transitive_stepwise_le) using assms(3) by auto thus ?case by auto
  1.3903          next case goal1 show ?case apply(subst integral_restrict_univ[THEN sym,OF int]) 
  1.3904              unfolding ifif integral_restrict_univ[OF int']
  1.3905 -            apply(rule integral_subset_component_le[OF _ int']) using assms by auto
  1.3906 +            apply(rule integral_subset_le[OF _ int']) using assms by auto
  1.3907          qed qed qed 
  1.3908      thus ?case apply safe defer apply(drule integral_unique) using i by auto qed
  1.3909  
  1.3910    have sub:"\<And>k. integral s (\<lambda>x. f k x - f 0 x) = integral s (f k) - integral s (f 0)"
  1.3911      apply(subst integral_sub) apply(rule assms(1)[rule_format])+ by rule
  1.3912 -  have "\<And>x m. x\<in>s \<Longrightarrow> \<forall>n\<ge>m. dest_vec1 (f m x) \<le> dest_vec1 (f n x)" apply(rule transitive_stepwise_le)
  1.3913 +  have "\<And>x m. x\<in>s \<Longrightarrow> \<forall>n\<ge>m. (f m x) \<le> (f n x)" apply(rule transitive_stepwise_le)
  1.3914      using assms(2) by auto note * = this[rule_format]
  1.3915    have "(\<lambda>x. g x - f 0 x) integrable_on s \<and>((\<lambda>k. integral s (\<lambda>x. f (Suc k) x - f 0 x)) --->
  1.3916        integral s (\<lambda>x. g x - f 0 x)) sequentially" apply(rule lem,safe)
  1.3917 @@ -4662,8 +4705,8 @@
  1.3918    thus ?thesis unfolding sub apply-apply rule defer apply(subst(asm) integral_sub)
  1.3919      using assms(1) apply auto apply(rule seq_offset_rev[where k=1]) by auto qed
  1.3920  
  1.3921 -lemma monotone_convergence_decreasing: fixes f::"nat \<Rightarrow> real^'n \<Rightarrow> real^1"
  1.3922 -  assumes "\<forall>k. (f k) integrable_on s"  "\<forall>k. \<forall>x\<in>s. (f (Suc k) x)$1 \<le> (f k x)$1"
  1.3923 +lemma monotone_convergence_decreasing: fixes f::"nat \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> real"
  1.3924 +  assumes "\<forall>k. (f k) integrable_on s"  "\<forall>k. \<forall>x\<in>s. (f (Suc k) x) \<le> (f k x)"
  1.3925    "\<forall>x\<in>s. ((\<lambda>k. f k x) ---> g x) sequentially" "bounded {integral s (f k)| k. True}"
  1.3926    shows "g integrable_on s \<and> ((\<lambda>k. integral s (f k)) ---> integral s g) sequentially"
  1.3927  proof- note assm = assms[rule_format]
  1.3928 @@ -4679,28 +4722,6 @@
  1.3929      using Lim_neg[OF *(2)] apply- unfolding integral_neg[OF assm(1)]
  1.3930      unfolding integral_neg[OF *(1),THEN sym] by auto qed
  1.3931  
  1.3932 -lemma monotone_convergence_increasing_real: fixes f::"nat \<Rightarrow> real^'n \<Rightarrow> real"
  1.3933 -  assumes "\<forall>k. (f k) integrable_on s"  "\<forall>k. \<forall>x\<in>s. (f (Suc k) x) \<ge> (f k x)"
  1.3934 -  "\<forall>x\<in>s. ((\<lambda>k. f k x) ---> g x) sequentially" "bounded {integral s (f k)| k. True}"
  1.3935 -  shows "g integrable_on s \<and> ((\<lambda>k. integral s (f k)) ---> integral s g) sequentially"
  1.3936 -proof- have *:"{integral s (\<lambda>x. vec1 (f k x)) |k. True} =  vec1 ` {integral s (f k) |k. True}"
  1.3937 -    unfolding integral_trans[OF assms(1)[rule_format]] by auto
  1.3938 -  have "vec1 \<circ> g integrable_on s \<and> ((\<lambda>k. integral s (vec1 \<circ> f k)) ---> integral s (vec1 \<circ> g)) sequentially"
  1.3939 -    apply(rule monotone_convergence_increasing) unfolding o_def integrable_on_trans
  1.3940 -    unfolding vec1_dest_vec1 apply(rule assms)+ unfolding Lim_trans unfolding * using assms(3,4) by auto
  1.3941 -  thus ?thesis unfolding o_def unfolding integral_trans[OF assms(1)[rule_format]] by auto qed
  1.3942 -
  1.3943 -lemma monotone_convergence_decreasing_real: fixes f::"nat \<Rightarrow> real^'n \<Rightarrow> real"
  1.3944 -  assumes "\<forall>k. (f k) integrable_on s"  "\<forall>k. \<forall>x\<in>s. (f (Suc k) x) \<le> (f k x)"
  1.3945 -  "\<forall>x\<in>s. ((\<lambda>k. f k x) ---> g x) sequentially" "bounded {integral s (f k)| k. True}"
  1.3946 -  shows "g integrable_on s \<and> ((\<lambda>k. integral s (f k)) ---> integral s g) sequentially"
  1.3947 -proof- have *:"{integral s (\<lambda>x. vec1 (f k x)) |k. True} =  vec1 ` {integral s (f k) |k. True}"
  1.3948 -    unfolding integral_trans[OF assms(1)[rule_format]] by auto
  1.3949 -  have "vec1 \<circ> g integrable_on s \<and> ((\<lambda>k. integral s (vec1 \<circ> f k)) ---> integral s (vec1 \<circ> g)) sequentially"
  1.3950 -    apply(rule monotone_convergence_decreasing) unfolding o_def integrable_on_trans
  1.3951 -    unfolding vec1_dest_vec1 apply(rule assms)+ unfolding Lim_trans unfolding * using assms(3,4) by auto
  1.3952 -  thus ?thesis unfolding o_def unfolding integral_trans[OF assms(1)[rule_format]] by auto qed
  1.3953 -
  1.3954  subsection {* absolute integrability (this is the same as Lebesgue integrability). *}
  1.3955  
  1.3956  definition absolutely_integrable_on (infixr "absolutely'_integrable'_on" 46) where
  1.3957 @@ -4714,11 +4735,11 @@
  1.3958    shows "f integrable_on s" "(\<lambda>x. (norm(f x))) integrable_on s"
  1.3959    using assms unfolding absolutely_integrable_on_def by auto
  1.3960  
  1.3961 -lemma absolutely_integrable_on_trans[simp]: fixes f::"real^'n \<Rightarrow> real" shows
  1.3962 +(*lemma absolutely_integrable_on_trans[simp]: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real" shows
  1.3963    "(vec1 o f) absolutely_integrable_on s \<longleftrightarrow> f absolutely_integrable_on s"
  1.3964 -  unfolding absolutely_integrable_on_def o_def by auto
  1.3965 -
  1.3966 -lemma integral_norm_bound_integral: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3967 +  unfolding absolutely_integrable_on_def o_def by auto*)
  1.3968 +
  1.3969 +lemma integral_norm_bound_integral: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.3970    assumes "f integrable_on s" "g integrable_on s" "\<forall>x\<in>s. norm(f x) \<le> g x"
  1.3971    shows "norm(integral s f) \<le> (integral s g)"
  1.3972  proof- have *:"\<And>x y. (\<forall>e::real. 0 < e \<longrightarrow> x < y + e) \<longrightarrow> x \<le> y" apply(safe,rule ccontr)
  1.3973 @@ -4730,7 +4751,7 @@
  1.3974        apply(rule add_le_less_mono) defer apply(subst norm_minus_commute,rule goal1)
  1.3975        apply(rule order_trans[OF goal1(1)]) using goal1(2) by arith
  1.3976    qed note norm=this[rule_format]
  1.3977 -  have lem:"\<And>f::real^'n \<Rightarrow> 'a. \<And> g a b. f integrable_on {a..b} \<Longrightarrow> g integrable_on {a..b} \<Longrightarrow>
  1.3978 +  have lem:"\<And>f::'n::ordered_euclidean_space \<Rightarrow> 'a. \<And> g a b. f integrable_on {a..b} \<Longrightarrow> g integrable_on {a..b} \<Longrightarrow>
  1.3979      \<forall>x\<in>{a..b}. norm(f x) \<le> (g x) \<Longrightarrow> norm(integral({a..b}) f) \<le> (integral({a..b}) g)"
  1.3980    proof(rule *[rule_format]) case goal1 hence *:"e/2>0" by auto
  1.3981      from integrable_integral[OF goal1(1),unfolded has_integral[of f],rule_format,OF *]
  1.3982 @@ -4758,7 +4779,7 @@
  1.3983    guess B1 .. note B1=conjunctD2[OF this[rule_format],rule_format]
  1.3984    from integrable_integral[OF assms(2),unfolded has_integral'[of g],rule_format,OF e]
  1.3985    guess B2 .. note B2=conjunctD2[OF this[rule_format],rule_format]
  1.3986 -  from bounded_subset_closed_interval[OF bounded_ball, of "0::real^'n" "max B1 B2"]
  1.3987 +  from bounded_subset_closed_interval[OF bounded_ball, of "0::'n::ordered_euclidean_space" "max B1 B2"]
  1.3988    guess a b apply-by(erule exE)+ note ab=this[unfolded ball_max_Un]
  1.3989  
  1.3990    have "ball 0 B1 \<subseteq> {a..b}" using ab by auto
  1.3991 @@ -4771,22 +4792,24 @@
  1.3992      defer apply(rule w(2)[unfolded real_norm_def],rule z(2))
  1.3993      apply safe apply(case_tac "x\<in>s") unfolding if_P apply(rule assms(3)[rule_format]) by auto qed
  1.3994  
  1.3995 -lemma integral_norm_bound_integral_component: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.3996 -  assumes "f integrable_on s" "g integrable_on s"  "\<forall>x\<in>s. norm(f x) \<le> (g x)$k"
  1.3997 -  shows "norm(integral s f) \<le> (integral s g)$k"
  1.3998 -proof- have "norm (integral s f) \<le> integral s ((\<lambda>x. x $ k) o g)"
  1.3999 +lemma integral_norm_bound_integral_component: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.4000 +  fixes g::"'n => 'b::ordered_euclidean_space"
  1.4001 +  assumes "f integrable_on s" "g integrable_on s"  "\<forall>x\<in>s. norm(f x) \<le> (g x)$$k"
  1.4002 +  shows "norm(integral s f) \<le> (integral s g)$$k"
  1.4003 +proof- have "norm (integral s f) \<le> integral s ((\<lambda>x. x $$ k) o g)"
  1.4004      apply(rule integral_norm_bound_integral[OF assms(1)])
  1.4005      apply(rule integrable_linear[OF assms(2)],rule)
  1.4006      unfolding o_def by(rule assms)
  1.4007    thus ?thesis unfolding o_def integral_component_eq[OF assms(2)] . qed
  1.4008  
  1.4009 -lemma has_integral_norm_bound_integral_component: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.4010 -  assumes "(f has_integral i) s" "(g has_integral j) s" "\<forall>x\<in>s. norm(f x) \<le> (g x)$k"
  1.4011 -  shows "norm(i) \<le> j$k" using integral_norm_bound_integral_component[of f s g k]
  1.4012 +lemma has_integral_norm_bound_integral_component: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.4013 +  fixes g::"'n => 'b::ordered_euclidean_space"
  1.4014 +  assumes "(f has_integral i) s" "(g has_integral j) s" "\<forall>x\<in>s. norm(f x) \<le> (g x)$$k"
  1.4015 +  shows "norm(i) \<le> j$$k" using integral_norm_bound_integral_component[of f s g k]
  1.4016    unfolding integral_unique[OF assms(1)] integral_unique[OF assms(2)]
  1.4017    using assms by auto
  1.4018  
  1.4019 -lemma absolutely_integrable_le: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.4020 +lemma absolutely_integrable_le: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.4021    assumes "f absolutely_integrable_on s"
  1.4022    shows "norm(integral s f) \<le> integral s (\<lambda>x. norm(f x))"
  1.4023    apply(rule integral_norm_bound_integral) using assms by auto
  1.4024 @@ -4811,11 +4834,11 @@
  1.4025   "f absolutely_integrable_on s \<Longrightarrow> (\<lambda>x. abs(f x::real)) absolutely_integrable_on s"
  1.4026    apply(drule absolutely_integrable_norm) unfolding real_norm_def .
  1.4027  
  1.4028 -lemma absolutely_integrable_on_subinterval: fixes f::"real^'n \<Rightarrow> 'a::banach" shows
  1.4029 +lemma absolutely_integrable_on_subinterval: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach" shows
  1.4030    "f absolutely_integrable_on s \<Longrightarrow> {a..b} \<subseteq> s \<Longrightarrow> f absolutely_integrable_on {a..b}" 
  1.4031    unfolding absolutely_integrable_on_def by(meson integrable_on_subinterval)
  1.4032  
  1.4033 -lemma absolutely_integrable_bounded_variation: fixes f::"real^'n \<Rightarrow> 'a::banach"
  1.4034 +lemma absolutely_integrable_bounded_variation: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'a::banach"
  1.4035    assumes "f absolutely_integrable_on UNIV"
  1.4036    obtains B where "\<forall>d. d division_of (\<Union>d) \<longrightarrow> setsum (\<lambda>k. norm(integral k f)) d \<le> B"
  1.4037    apply(rule that[of "integral UNIV (\<lambda>x. norm (f x))"])
  1.4038 @@ -4839,7 +4862,7 @@
  1.4039    using norm_triangle_ineq3 .
  1.4040  
  1.4041  lemma bounded_variation_absolutely_integrable_interval:
  1.4042 -  fixes f::"real^'n \<Rightarrow> real^'m" assumes "f integrable_on {a..b}"
  1.4043 +  fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space" assumes "f integrable_on {a..b}"
  1.4044    "\<forall>d. d division_of {a..b} \<longrightarrow> setsum (\<lambda>k. norm(integral k f)) d \<le> B"
  1.4045    shows "f absolutely_integrable_on {a..b}"
  1.4046  proof- let ?S = "(\<lambda>d. setsum (\<lambda>k. norm(integral k f)) d) ` {d. d division_of {a..b} }" def i \<equiv> "Sup ?S"
  1.4047 @@ -4851,7 +4874,7 @@
  1.4048          {d. d division_of {a..b}}))" using isLub_ubs[OF i,rule_format]
  1.4049        unfolding setge_def ubs_def by auto 
  1.4050      hence " \<exists>y. y division_of {a..b} \<and> i - e / 2 < (\<Sum>k\<in>y. norm (integral k f))"
  1.4051 -      unfolding mem_Collect_eq isUb_def setle_def by simp then guess d .. note d=conjunctD2[OF this]
  1.4052 +      unfolding mem_Collect_eq isUb_def setle_def by(simp add:not_le) then guess d .. note d=conjunctD2[OF this]
  1.4053      note d' = division_ofD[OF this(1)]
  1.4054  
  1.4055      have "\<forall>x. \<exists>e>0. \<forall>i\<in>d. x \<notin> i \<longrightarrow> ball x e \<inter> i = {}"
  1.4056 @@ -5051,7 +5074,7 @@
  1.4057          qed finally show ?case . 
  1.4058        qed qed qed qed 
  1.4059  
  1.4060 -lemma bounded_variation_absolutely_integrable:  fixes f::"real^'n \<Rightarrow> real^'m"
  1.4061 +lemma bounded_variation_absolutely_integrable:  fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.4062    assumes "f integrable_on UNIV" "\<forall>d. d division_of (\<Union>d) \<longrightarrow> setsum (\<lambda>k. norm(integral k f)) d \<le> B"
  1.4063    shows "f absolutely_integrable_on UNIV"
  1.4064  proof(rule absolutely_integrable_onI,fact,rule)
  1.4065 @@ -5075,7 +5098,7 @@
  1.4066      have "bounded (\<Union>d)" by(rule elementary_bounded,fact)
  1.4067      from this[unfolded bounded_pos] guess K .. note K=conjunctD2[OF this]
  1.4068      show ?case apply(rule_tac x="K + 1" in exI,safe)
  1.4069 -    proof- fix a b assume ab:"ball 0 (K + 1) \<subseteq> {a..b::real^'n}"
  1.4070 +    proof- fix a b assume ab:"ball 0 (K + 1) \<subseteq> {a..b::'n::ordered_euclidean_space}"
  1.4071        have *:"\<forall>s s1. i - e < s1 \<and> s1 \<le> s \<and> s < i + e \<longrightarrow> abs(s - i) < (e::real)" by arith
  1.4072        show "norm (integral {a..b} (\<lambda>x. if x \<in> UNIV then norm (f x) else 0) - i) < e"
  1.4073          unfolding real_norm_def apply(rule *[rule_format],safe) apply(rule d(2))
  1.4074 @@ -5123,16 +5146,16 @@
  1.4075   "(\<lambda>x. if x \<in> s then f x else (0::'a::banach)) absolutely_integrable_on UNIV \<longleftrightarrow> f absolutely_integrable_on s"
  1.4076    unfolding absolutely_integrable_on_def if_distrib norm_zero integrable_restrict_univ ..
  1.4077  
  1.4078 -lemma absolutely_integrable_add[intro]: fixes f g::"real^'n \<Rightarrow> real^'m"
  1.4079 +lemma absolutely_integrable_add[intro]: fixes f g::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.4080    assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  1.4081    shows "(\<lambda>x. f(x) + g(x)) absolutely_integrable_on s"
  1.4082 -proof- let ?P = "\<And>f g::real^'n \<Rightarrow> real^'m. f absolutely_integrable_on UNIV \<Longrightarrow>
  1.4083 +proof- let ?P = "\<And>f g::'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space. f absolutely_integrable_on UNIV \<Longrightarrow>
  1.4084      g absolutely_integrable_on UNIV \<Longrightarrow> (\<lambda>x. f(x) + g(x)) absolutely_integrable_on UNIV"
  1.4085    { presume as:"PROP ?P" note a = absolutely_integrable_restrict_univ[THEN sym]
  1.4086      have *:"\<And>x. (if x \<in> s then f x else 0) + (if x \<in> s then g x else 0)
  1.4087        = (if x \<in> s then f x + g x else 0)" by auto
  1.4088      show ?thesis apply(subst a) using as[OF assms[unfolded a[of f] a[of g]]] unfolding * . }
  1.4089 -  fix f g::"real^'n \<Rightarrow> real^'m" assume assms:"f absolutely_integrable_on UNIV"
  1.4090 +  fix f g::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space" assume assms:"f absolutely_integrable_on UNIV"
  1.4091      "g absolutely_integrable_on UNIV" 
  1.4092    note absolutely_integrable_bounded_variation
  1.4093    from this[OF assms(1)] this[OF assms(2)] guess B1 B2 . note B=this[rule_format]
  1.4094 @@ -5150,21 +5173,21 @@
  1.4095      finally show ?case .
  1.4096    qed(insert assms,auto) qed
  1.4097  
  1.4098 -lemma absolutely_integrable_sub[intro]: fixes f g::"real^'n \<Rightarrow> real^'m"
  1.4099 +lemma absolutely_integrable_sub[intro]: fixes f g::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.4100    assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  1.4101    shows "(\<lambda>x. f(x) - g(x)) absolutely_integrable_on s"
  1.4102    using absolutely_integrable_add[OF assms(1) absolutely_integrable_neg[OF assms(2)]]
  1.4103    unfolding algebra_simps .
  1.4104  
  1.4105 -lemma absolutely_integrable_linear: fixes f::"real^'m \<Rightarrow> real^'n" and h::"real^'n \<Rightarrow> real^'p"
  1.4106 +lemma absolutely_integrable_linear: fixes f::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space" and h::"'n::ordered_euclidean_space \<Rightarrow> 'p::ordered_euclidean_space"
  1.4107    assumes "f absolutely_integrable_on s" "bounded_linear h"
  1.4108    shows "(h o f) absolutely_integrable_on s"
  1.4109 -proof- { presume as:"\<And>f::real^'m \<Rightarrow> real^'n. \<And>h::real^'n \<Rightarrow> real^'p. 
  1.4110 +proof- { presume as:"\<And>f::'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space. \<And>h::'n::ordered_euclidean_space \<Rightarrow> 'p::ordered_euclidean_space. 
  1.4111      f absolutely_integrable_on UNIV \<Longrightarrow> bounded_linear h \<Longrightarrow>
  1.4112      (h o f) absolutely_integrable_on UNIV" note a = absolutely_integrable_restrict_univ[THEN sym]
  1.4113      show ?thesis apply(subst a) using as[OF assms[unfolded a[of f] a[of g]]]
  1.4114        unfolding o_def if_distrib linear_simps[OF assms(2)] . }
  1.4115 -  fix f::"real^'m \<Rightarrow> real^'n" and h::"real^'n \<Rightarrow> real^'p"
  1.4116 +  fix f::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space" and h::"'n::ordered_euclidean_space \<Rightarrow> 'p::ordered_euclidean_space"
  1.4117    assume assms:"f absolutely_integrable_on UNIV" "bounded_linear h" 
  1.4118    from absolutely_integrable_bounded_variation[OF assms(1)] guess B . note B=this
  1.4119    from bounded_linear.pos_bounded[OF assms(2)] guess b .. note b=conjunctD2[OF this]
  1.4120 @@ -5185,125 +5208,112 @@
  1.4121      finally show ?case .
  1.4122    qed(insert assms,auto) qed
  1.4123  
  1.4124 -lemma absolutely_integrable_setsum: fixes f::"'a \<Rightarrow> real^'n \<Rightarrow> real^'m"
  1.4125 +lemma absolutely_integrable_setsum: fixes f::"'a \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.4126    assumes "finite t" "\<And>a. a \<in> t \<Longrightarrow> (f a) absolutely_integrable_on s"
  1.4127    shows "(\<lambda>x. setsum (\<lambda>a. f a x) t) absolutely_integrable_on s"
  1.4128    using assms(1,2) apply induct defer apply(subst setsum.insert) apply assumption+ by(rule,auto)
  1.4129  
  1.4130 -lemma absolutely_integrable_vector_abs:
  1.4131 +lemma absolutely_integrable_vector_abs: fixes f::"'a::ordered_euclidean_space => 'b::ordered_euclidean_space"
  1.4132    assumes "f absolutely_integrable_on s"
  1.4133 -  shows "(\<lambda>x. (\<chi> i. abs(f x$i))::real^'n) absolutely_integrable_on s"
  1.4134 -proof- have *:"\<And>x. ((\<chi> i. abs(f x$i))::real^'n) = (setsum (\<lambda>i.
  1.4135 -    (((\<lambda>y. (\<chi> j. if j = i then y$1 else 0)) o
  1.4136 -    (vec1 o ((\<lambda>x. (norm((\<chi> j. if j = i then x$i else 0)::real^'n))) o f))) x)) UNIV)"
  1.4137 -    unfolding Cart_eq setsum_component Cart_lambda_beta
  1.4138 -  proof case goal1 have *:"\<And>i xa. ((if i = xa then f x $ xa else 0) \<bullet> (if i = xa then f x $ xa else 0)) =
  1.4139 -      (if i = xa then (f x $ xa) * (f x $ xa) else 0)" by auto
  1.4140 -    have "\<bar>f x $ i\<bar> = (setsum (\<lambda>k. if k = i then abs ((f x)$i) else 0) UNIV)"
  1.4141 -      unfolding setsum_delta[OF finite_UNIV] by auto
  1.4142 -    also have "... = (\<Sum>xa\<in>UNIV. ((\<lambda>y. \<chi> j. if j = xa then dest_vec1 y else 0) \<circ>
  1.4143 -                      (\<lambda>x. vec1 (norm (\<chi> j. if j = xa then x $ xa else 0))) \<circ> f) x $ i)"
  1.4144 -      unfolding norm_eq_sqrt_inner inner_vector_def Cart_lambda_beta o_def *
  1.4145 -      apply(rule setsum_cong2) unfolding setsum_delta[OF finite_UNIV] by auto 
  1.4146 +  shows "(\<lambda>x. (\<chi>\<chi> i. abs(f x$$i))::'c::ordered_euclidean_space) absolutely_integrable_on s"
  1.4147 +proof- have *:"\<And>x. ((\<chi>\<chi> i. abs(f x$$i))::'c::ordered_euclidean_space) = (setsum (\<lambda>i.
  1.4148 +    (((\<lambda>y. (\<chi>\<chi> j. if j = i then y else 0)) o
  1.4149 +    (((\<lambda>x. (norm((\<chi>\<chi> j. if j = i then x$$i else 0)::'c::ordered_euclidean_space))) o f))) x)) {..<DIM('c)})"
  1.4150 +    unfolding euclidean_eq[where 'a='c] euclidean_component.setsum apply safe
  1.4151 +    unfolding euclidean_lambda_beta'
  1.4152 +  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)) =
  1.4153 +      (if i = xa then (f x $$ xa) * (f x $$ xa) else 0)" by auto
  1.4154 +    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)"
  1.4155 +      unfolding norm_eq_sqrt_inner euclidean_inner[where 'a='c]
  1.4156 +      by(auto simp add:setsum_delta[OF finite_lessThan] *)
  1.4157 +    have "\<bar>f x $$ i\<bar> = (setsum (\<lambda>k. if k = i then abs ((f x)$$i) else 0) {..<DIM('c)})"
  1.4158 +      unfolding setsum_delta[OF finite_lessThan] using goal1 by auto
  1.4159 +    also have "... = (\<Sum>xa<DIM('c). ((\<lambda>y. (\<chi>\<chi> j. if j = xa then y else 0)::'c) \<circ>
  1.4160 +                      (\<lambda>x. (norm ((\<chi>\<chi> j. if j = xa then x $$ xa else 0)::'c))) \<circ> f) x $$ i)"
  1.4161 +      unfolding o_def * apply(rule setsum_cong2)
  1.4162 +      unfolding euclidean_lambda_beta'[OF goal1 ] by auto
  1.4163      finally show ?case unfolding o_def . qed
  1.4164 -  show ?thesis unfolding * apply(rule absolutely_integrable_setsum) apply(rule finite_UNIV)
  1.4165 -    apply(rule absolutely_integrable_linear) 
  1.4166 -    unfolding absolutely_integrable_on_trans unfolding o_def apply(rule absolutely_integrable_norm)
  1.4167 +  show ?thesis unfolding * apply(rule absolutely_integrable_setsum) apply(rule finite_lessThan)
  1.4168 +    apply(rule absolutely_integrable_linear) unfolding o_def apply(rule absolutely_integrable_norm)
  1.4169      apply(rule absolutely_integrable_linear[OF assms,unfolded o_def]) unfolding linear_linear
  1.4170 -    apply(rule_tac[!] linearI) unfolding Cart_eq by auto
  1.4171 +    apply(rule_tac[!] linearI) unfolding euclidean_eq[where 'a='c]
  1.4172 +    by(auto simp:euclidean_scaleR[where 'a=real,unfolded real_scaleR_def])
  1.4173  qed
  1.4174  
  1.4175 -lemma absolutely_integrable_max: fixes f::"real^'m \<Rightarrow> real^'n"
  1.4176 +lemma absolutely_integrable_max: fixes f g::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space"
  1.4177    assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  1.4178 -  shows "(\<lambda>x. (\<chi> i. max (f(x)$i) (g(x)$i))::real^'n) absolutely_integrable_on s"
  1.4179 -proof- have *:"\<And>x. (1 / 2) *\<^sub>R ((\<chi> i. \<bar>(f x - g x) $ i\<bar>) + (f x + g x)) = (\<chi> i. max (f(x)$i) (g(x)$i))"
  1.4180 -    unfolding Cart_eq by auto
  1.4181 +  shows "(\<lambda>x. (\<chi>\<chi> i. max (f(x)$$i) (g(x)$$i))::'n::ordered_euclidean_space) absolutely_integrable_on s"
  1.4182 +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))"
  1.4183 +    unfolding euclidean_eq[where 'a='n] by auto
  1.4184    note absolutely_integrable_sub[OF assms] absolutely_integrable_add[OF assms]
  1.4185    note absolutely_integrable_vector_abs[OF this(1)] this(2)
  1.4186    note absolutely_integrable_add[OF this] note absolutely_integrable_cmul[OF this,of "1/2"]
  1.4187    thus ?thesis unfolding * . qed
  1.4188  
  1.4189 -lemma absolutely_integrable_max_real: fixes f::"real^'m \<Rightarrow> real"
  1.4190 +lemma absolutely_integrable_min: fixes f g::"'m::ordered_euclidean_space \<Rightarrow> 'n::ordered_euclidean_space"
  1.4191    assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  1.4192 -  shows "(\<lambda>x. max (f x) (g x)) absolutely_integrable_on s"
  1.4193 -proof- have *:"(\<lambda>x. \<chi> i. max ((vec1 \<circ> f) x $ i) ((vec1 \<circ> g) x $ i)) = vec1 o (\<lambda>x. max (f x) (g x))"
  1.4194 -    apply rule unfolding Cart_eq by auto note absolutely_integrable_max[of "vec1 o f" s "vec1 o g"]
  1.4195 -  note this[unfolded absolutely_integrable_on_trans,OF assms]
  1.4196 -  thus ?thesis unfolding * by auto qed
  1.4197 -
  1.4198 -lemma absolutely_integrable_min: fixes f::"real^'m \<Rightarrow> real^'n"
  1.4199 -  assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  1.4200 -  shows "(\<lambda>x. (\<chi> i. min (f(x)$i) (g(x)$i))::real^'n) absolutely_integrable_on s"
  1.4201 -proof- have *:"\<And>x. (1 / 2) *\<^sub>R ((f x + g x) - (\<chi> i. \<bar>(f x - g x) $ i\<bar>)) = (\<chi> i. min (f(x)$i) (g(x)$i))"
  1.4202 -    unfolding Cart_eq by auto
  1.4203 +  shows "(\<lambda>x. (\<chi>\<chi> i. min (f(x)$$i) (g(x)$$i))::'n::ordered_euclidean_space) absolutely_integrable_on s"
  1.4204 +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))"
  1.4205 +    unfolding euclidean_eq[where 'a='n] by auto
  1.4206    note absolutely_integrable_add[OF assms] absolutely_integrable_sub[OF assms]
  1.4207    note this(1) absolutely_integrable_vector_abs[OF this(2)]
  1.4208    note absolutely_integrable_sub[OF this] note absolutely_integrable_cmul[OF this,of "1/2"]
  1.4209    thus ?thesis unfolding * . qed
  1.4210  
  1.4211 -lemma absolutely_integrable_min_real: fixes f::"real^'m \<Rightarrow> real"
  1.4212 -  assumes "f absolutely_integrable_on s" "g absolutely_integrable_on s"
  1.4213 -  shows "(\<lambda>x. min (f x) (g x)) absolutely_integrable_on s"
  1.4214 -proof- have *:"(\<lambda>x. \<chi> i. min ((vec1 \<circ> f) x $ i) ((vec1 \<circ> g) x $ i)) = vec1 o (\<lambda>x. min (f x) (g x))"
  1.4215 -    apply rule unfolding Cart_eq by auto note absolutely_integrable_min[of "vec1 o f" s "vec1 o g"]
  1.4216 -  note this[unfolded absolutely_integrable_on_trans,OF assms]
  1.4217 -  thus ?thesis unfolding * by auto qed
  1.4218 -
  1.4219 -lemma absolutely_integrable_abs_eq: fixes f::"real^'n \<Rightarrow> real^'m"
  1.4220 +lemma absolutely_integrable_abs_eq: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.4221    shows "f absolutely_integrable_on s \<longleftrightarrow> f integrable_on s \<and>
  1.4222 -          (\<lambda>x. (\<chi> i. abs(f x$i))::real^'m) integrable_on s" (is "?l = ?r")
  1.4223 +          (\<lambda>x. (\<chi>\<chi> i. abs(f x$$i))::'m) integrable_on s" (is "?l = ?r")
  1.4224  proof assume ?l thus ?r apply-apply rule defer
  1.4225      apply(drule absolutely_integrable_vector_abs) by auto
  1.4226 -next assume ?r { presume lem:"\<And>f::real^'n \<Rightarrow> real^'m. f integrable_on UNIV \<Longrightarrow>
  1.4227 -    (\<lambda>x. (\<chi> i. abs(f(x)$i))::real^'m) integrable_on UNIV \<Longrightarrow> f absolutely_integrable_on UNIV"
  1.4228 -    have *:"\<And>x. (\<chi> i. \<bar>(if x \<in> s then f x else 0) $ i\<bar>) = (if x\<in>s then (\<chi> i. \<bar>f x $ i\<bar>) else 0)"
  1.4229 -      unfolding Cart_eq by auto
  1.4230 +next assume ?r { presume lem:"\<And>f::'n \<Rightarrow> 'm. f integrable_on UNIV \<Longrightarrow>
  1.4231 +    (\<lambda>x. (\<chi>\<chi> i. abs(f(x)$$i))::'m) integrable_on UNIV \<Longrightarrow> f absolutely_integrable_on UNIV"
  1.4232 +    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))"
  1.4233 +      unfolding euclidean_eq[where 'a='m] by auto
  1.4234      show ?l apply(subst absolutely_integrable_restrict_univ[THEN sym]) apply(rule lem)
  1.4235        unfolding integrable_restrict_univ * using `?r` by auto }
  1.4236 -  fix f::"real^'n \<Rightarrow> real^'m" assume assms:"f integrable_on UNIV"
  1.4237 -    "(\<lambda>x. (\<chi> i. abs(f(x)$i))::real^'m) integrable_on UNIV"
  1.4238 -  let ?B = "setsum (\<lambda>i. integral UNIV (\<lambda>x. (\<chi> j. abs(f x$j)) ::real^'m) $ i) UNIV"
  1.4239 +  fix f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space" assume assms:"f integrable_on UNIV"
  1.4240 +    "(\<lambda>x. (\<chi>\<chi> i. abs(f(x)$$i))::'m::ordered_euclidean_space) integrable_on UNIV"
  1.4241 +  let ?B = "setsum (\<lambda>i. integral UNIV (\<lambda>x. (\<chi>\<chi> j. abs(f x$$j)) ::'m::ordered_euclidean_space) $$ i) {..<DIM('m)}"
  1.4242    show "f absolutely_integrable_on UNIV"
  1.4243      apply(rule bounded_variation_absolutely_integrable[OF assms(1), where B="?B"],safe)
  1.4244    proof- case goal1 note d=this and d'=division_ofD[OF this]
  1.4245      have "(\<Sum>k\<in>d. norm (integral k f)) \<le>
  1.4246 -      (\<Sum>k\<in>d. setsum (op $ (integral k (\<lambda>x. \<chi> j. \<bar>f x $ j\<bar>))) UNIV)" apply(rule setsum_mono)
  1.4247 -      apply(rule order_trans[OF norm_le_l1],rule setsum_mono)
  1.4248 -    proof- fix k and i::'m assume "k\<in>d"
  1.4249 -      from d'(4)[OF this] guess a b apply-by(erule exE)+ note ab=this
  1.4250 -      show "\<bar>integral k f $ i\<bar> \<le> integral k (\<lambda>x. \<chi> j. \<bar>f x $ j\<bar>) $ i" apply(rule abs_leI)
  1.4251 -        unfolding vector_uminus_component[THEN sym] defer apply(subst integral_neg[THEN sym])
  1.4252 +      (\<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)
  1.4253 +      apply(rule order_trans[OF norm_le_l1]) apply(rule setsum_mono) unfolding lessThan_iff
  1.4254 +    proof- fix k and i assume "k\<in>d" and i:"i<DIM('m)"
  1.4255 +      from d'(4)[OF this(1)] guess a b apply-by(erule exE)+ note ab=this
  1.4256 +      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)
  1.4257 +        unfolding euclidean_component.minus[THEN sym] defer apply(subst integral_neg[THEN sym])
  1.4258          defer apply(rule_tac[1-2] integral_component_le) apply(rule integrable_neg)
  1.4259          using integrable_on_subinterval[OF assms(1),of a b]
  1.4260            integrable_on_subinterval[OF assms(2),of a b] unfolding ab by auto
  1.4261 -    qed also have "... \<le> setsum (op $ (integral UNIV (\<lambda>x. \<chi> j. \<bar>f x $ j\<bar>))) UNIV"
  1.4262 +    qed also have "... \<le> setsum (op $$ (integral UNIV (\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>))::'m)) {..<DIM('m)}"
  1.4263        apply(subst setsum_commute,rule setsum_mono)
  1.4264 -    proof- case goal1 have *:"(\<lambda>x. \<chi> j. \<bar>f x $ j\<bar>) integrable_on \<Union>d"
  1.4265 +    proof- case goal1 have *:"(\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>)::'m) integrable_on \<Union>d"
  1.4266          using integrable_on_subdivision[OF d assms(2)] by auto
  1.4267 -      have "(\<Sum>i\<in>d. integral i (\<lambda>x. \<chi> j. \<bar>f x $ j\<bar>) $ j)
  1.4268 -        = integral (\<Union>d) (\<lambda>x. (\<chi> j. abs(f x$j)) ::real^'m) $ j"
  1.4269 -        unfolding setsum_component[THEN sym]
  1.4270 -        apply(subst integral_combine_division_topdown[THEN sym,OF * d]) by auto
  1.4271 -      also have "... \<le> integral UNIV (\<lambda>x. \<chi> j. \<bar>f x $ j\<bar>) $ j"
  1.4272 +      have "(\<Sum>i\<in>d. integral i (\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>)::'m) $$ j)
  1.4273 +        = integral (\<Union>d) (\<lambda>x. (\<chi>\<chi> j. abs(f x$$j)) ::'m::ordered_euclidean_space) $$ j"
  1.4274 +        unfolding euclidean_component.setsum[THEN sym] integral_combine_division_topdown[OF * d] ..
  1.4275 +      also have "... \<le> integral UNIV (\<lambda>x. (\<chi>\<chi> j. \<bar>f x $$ j\<bar>)::'m) $$ j"
  1.4276          apply(rule integral_subset_component_le) using assms * by auto
  1.4277        finally show ?case .
  1.4278      qed finally show ?case . qed qed
  1.4279  
  1.4280 -lemma nonnegative_absolutely_integrable: fixes f::"real^'n \<Rightarrow> real^'m"
  1.4281 -  assumes "\<forall>x\<in>s. \<forall>i. 0 \<le> f(x)$i" "f integrable_on s"
  1.4282 +lemma nonnegative_absolutely_integrable: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.4283 +  assumes "\<forall>x\<in>s. \<forall>i. 0 \<le> f(x)$$i" "f integrable_on s"
  1.4284    shows "f absolutely_integrable_on s"
  1.4285    unfolding absolutely_integrable_abs_eq apply rule defer
  1.4286 -  apply(rule integrable_eq[of _ f]) unfolding Cart_eq using assms by auto
  1.4287 -
  1.4288 -lemma absolutely_integrable_integrable_bound: fixes f::"real^'n \<Rightarrow> real^'m"
  1.4289 +  apply(rule integrable_eq[of _ f]) using assms by auto
  1.4290 +
  1.4291 +lemma absolutely_integrable_integrable_bound: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.4292    assumes "\<forall>x\<in>s. norm(f x) \<le> g x" "f integrable_on s" "g integrable_on s"
  1.4293    shows "f absolutely_integrable_on s"
  1.4294 -proof- { presume *:"\<And>f::real^'n \<Rightarrow> real^'m. \<And> g. \<forall>x. norm(f x) \<le> g x \<Longrightarrow> f integrable_on UNIV
  1.4295 +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
  1.4296      \<Longrightarrow> g integrable_on UNIV \<Longrightarrow> f absolutely_integrable_on UNIV"
  1.4297      show ?thesis apply(subst absolutely_integrable_restrict_univ[THEN sym])
  1.4298        apply(rule *[of _ "\<lambda>x. if x\<in>s then g x else 0"])
  1.4299        using assms unfolding integrable_restrict_univ by auto }
  1.4300 -  fix g and f :: "real^'n \<Rightarrow> real^'m"
  1.4301 +  fix g and f :: "'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
  1.4302    assume assms:"\<forall>x. norm(f x) \<le> g x" "f integrable_on UNIV" "g integrable_on UNIV"
  1.4303    show "f absolutely_integrable_on UNIV"
  1.4304      apply(rule bounded_variation_absolutely_integrable[OF assms(2),where B="integral UNIV g"])
  1.4305 @@ -5319,15 +5329,14 @@
  1.4306        apply(rule,rule_tac y="norm (f x)" in order_trans) using assms by auto
  1.4307      finally show ?case . qed qed
  1.4308  
  1.4309 -lemma absolutely_integrable_integrable_bound_real: fixes f::"real^'n \<Rightarrow> real"
  1.4310 +lemma absolutely_integrable_integrable_bound_real: fixes f::"'n::ordered_euclidean_space \<Rightarrow> real"
  1.4311    assumes "\<forall>x\<in>s. norm(f x) \<le> g x" "f integrable_on s" "g integrable_on s"
  1.4312    shows "f absolutely_integrable_on s"
  1.4313 -  apply(subst absolutely_integrable_on_trans[THEN sym])
  1.4314    apply(rule absolutely_integrable_integrable_bound[where g=g])
  1.4315    using assms unfolding o_def by auto
  1.4316  
  1.4317  lemma absolutely_integrable_absolutely_integrable_bound:
  1.4318 -  fixes f::"real^'n \<Rightarrow> real^'m" and g::"real^'n \<Rightarrow> real^'p"
  1.4319 +  fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space" and g::"'n::ordered_euclidean_space \<Rightarrow> 'p::ordered_euclidean_space"
  1.4320    assumes "\<forall>x\<in>s. norm(f x) \<le> norm(g x)" "f integrable_on s" "g absolutely_integrable_on s"
  1.4321    shows "f absolutely_integrable_on s"
  1.4322    apply(rule absolutely_integrable_integrable_bound[of s f "\<lambda>x. norm (g x)"])
  1.4323 @@ -5343,8 +5352,8 @@
  1.4324      apply(subst Inf_insert_finite) apply(rule finite_imageI[OF insert(1)])
  1.4325    proof(cases "k={}") case True
  1.4326      thus ?P apply(subst if_P) defer apply(rule insert(5)[rule_format]) by auto
  1.4327 -  next case False thus ?P apply(subst if_not_P) defer
  1.4328 -      apply(rule absolutely_integrable_min_real) 
  1.4329 +  next case False thus ?P apply(subst if_not_P) defer      
  1.4330 +      apply(rule absolutely_integrable_min[where 'n=real,unfolded Eucl_real_simps])
  1.4331        defer apply(rule insert(3)[OF False]) using insert(5) by auto
  1.4332    qed qed auto
  1.4333  
  1.4334 @@ -5359,13 +5368,13 @@
  1.4335    proof(cases "k={}") case True
  1.4336      thus ?P apply(subst if_P) defer apply(rule insert(5)[rule_format]) by auto
  1.4337    next case False thus ?P apply(subst if_not_P) defer
  1.4338 -      apply(rule absolutely_integrable_max_real) 
  1.4339 +      apply(rule absolutely_integrable_max[where 'n=real,unfolded Eucl_real_simps]) 
  1.4340        defer apply(rule insert(3)[OF False]) using insert(5) by auto
  1.4341    qed qed auto
  1.4342  
  1.4343  subsection {* Dominated convergence. *}
  1.4344  
  1.4345 -lemma dominated_convergence: fixes f::"nat \<Rightarrow> real^'n \<Rightarrow> real"
  1.4346 +lemma dominated_convergence: fixes f::"nat \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> real"
  1.4347    assumes "\<And>k. (f k) integrable_on s" "h integrable_on s"
  1.4348    "\<And>k. \<forall>x \<in> s. norm(f k x) \<le> (h x)"
  1.4349    "\<forall>x \<in> s. ((\<lambda>k. f k x) ---> g x) sequentially"
  1.4350 @@ -5373,7 +5382,7 @@
  1.4351  proof- have "\<And>m. (\<lambda>x. Inf {f j x |j. m \<le> j}) integrable_on s \<and>
  1.4352      ((\<lambda>k. integral s (\<lambda>x. Inf {f j x |j. j \<in> {m..m + k}})) --->
  1.4353      integral s (\<lambda>x. Inf {f j x |j. m \<le> j}))sequentially"
  1.4354 -  proof(rule monotone_convergence_decreasing_real,safe) fix m::nat
  1.4355 +  proof(rule monotone_convergence_decreasing,safe) fix m::nat
  1.4356      show "bounded {integral s (\<lambda>x. Inf {f j x |j. j \<in> {m..m + k}}) |k. True}"
  1.4357        unfolding bounded_iff apply(rule_tac x="integral s h" in exI)
  1.4358      proof safe fix k::nat
  1.4359 @@ -5418,7 +5427,7 @@
  1.4360    have "\<And>m. (\<lambda>x. Sup {f j x |j. m \<le> j}) integrable_on s \<and>
  1.4361      ((\<lambda>k. integral s (\<lambda>x. Sup {f j x |j. j \<in> {m..m + k}})) --->
  1.4362      integral s (\<lambda>x. Sup {f j x |j. m \<le> j})) sequentially"
  1.4363 -  proof(rule monotone_convergence_increasing_real,safe) fix m::nat
  1.4364 +  proof(rule monotone_convergence_increasing,safe) fix m::nat
  1.4365      show "bounded {integral s (\<lambda>x. Sup {f j x |j. j \<in> {m..m + k}}) |k. True}"
  1.4366        unfolding bounded_iff apply(rule_tac x="integral s h" in exI)
  1.4367      proof safe fix k::nat
  1.4368 @@ -5460,7 +5469,7 @@
  1.4369        qed qed qed note inc1 = conjunctD2[OF this]
  1.4370  
  1.4371    have "g integrable_on s \<and> ((\<lambda>k. integral s (\<lambda>x. Inf {f j x |j. k \<le> j})) ---> integral s g) sequentially"
  1.4372 -  apply(rule monotone_convergence_increasing_real,safe) apply fact 
  1.4373 +  apply(rule monotone_convergence_increasing,safe) apply fact 
  1.4374    proof- show "bounded {integral s (\<lambda>x. Inf {f j x |j. k \<le> j}) |k. True}"
  1.4375        unfolding bounded_iff apply(rule_tac x="integral s h" in exI)
  1.4376      proof safe fix k::nat
  1.4377 @@ -5483,7 +5492,7 @@
  1.4378      qed qed note inc2 = conjunctD2[OF this]
  1.4379  
  1.4380    have "g integrable_on s \<and> ((\<lambda>k. integral s (\<lambda>x. Sup {f j x |j. k \<le> j})) ---> integral s g) sequentially"
  1.4381 -  apply(rule monotone_convergence_decreasing_real,safe) apply fact 
  1.4382 +  apply(rule monotone_convergence_decreasing,safe) apply fact 
  1.4383    proof- show "bounded {integral s (\<lambda>x. Sup {f j x |j. k \<le> j}) |k. True}"
  1.4384        unfolding bounded_iff apply(rule_tac x="integral s h" in exI)
  1.4385      proof safe fix k::nat