Gauge measure removed
authorhoelzl
Tue Jan 18 21:37:23 2011 +0100 (2011-01-18)
changeset 4165432fe42892983
parent 41547 4638b1210d26
child 41655 95f851027a59
child 41659 a5d1b2df5e97
Gauge measure removed
src/HOL/IsaMakefile
src/HOL/Multivariate_Analysis/Gauge_Measure.thy
src/HOL/Multivariate_Analysis/Multivariate_Analysis.thy
src/HOL/Probability/Lebesgue_Measure.thy
     1.1 --- a/src/HOL/IsaMakefile	Fri Jan 14 16:00:13 2011 +0100
     1.2 +++ b/src/HOL/IsaMakefile	Tue Jan 18 21:37:23 2011 +0100
     1.3 @@ -1,4 +1,3 @@
     1.4 -
     1.5  #
     1.6  # IsaMakefile for HOL
     1.7  #
     1.8 @@ -1150,7 +1149,6 @@
     1.9    Multivariate_Analysis/Finite_Cartesian_Product.thy			\
    1.10    Multivariate_Analysis/Integration.certs				\
    1.11    Multivariate_Analysis/Integration.thy					\
    1.12 -  Multivariate_Analysis/Gauge_Measure.thy				\
    1.13    Multivariate_Analysis/L2_Norm.thy					\
    1.14    Multivariate_Analysis/Multivariate_Analysis.thy			\
    1.15    Multivariate_Analysis/Operator_Norm.thy				\
     2.1 --- a/src/HOL/Multivariate_Analysis/Gauge_Measure.thy	Fri Jan 14 16:00:13 2011 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,3447 +0,0 @@
     2.4 -
     2.5 -header {* Lebsegue measure (defined via the gauge integral). *}
     2.6 -(*  Author:                     John Harrison
     2.7 -    Translation from HOL light: Robert Himmelmann, TU Muenchen *)
     2.8 -
     2.9 -theory Gauge_Measure
    2.10 -  imports Integration 
    2.11 -begin
    2.12 -
    2.13 -(* ------------------------------------------------------------------------- *)
    2.14 -(* Lebesgue measure (in the case where the measure is finite).               *)
    2.15 -(* For the non-finite version, please see Probability/Lebesgue_Measure.thy   *)
    2.16 -(* ------------------------------------------------------------------------- *)
    2.17 -
    2.18 -definition has_gmeasure (infixr "has'_gmeasure" 80) where
    2.19 -  "s has_gmeasure m \<equiv> ((\<lambda>x. 1::real) has_integral m) s"
    2.20 -
    2.21 -definition gmeasurable :: "('n::ordered_euclidean_space) set \<Rightarrow> bool" where 
    2.22 -  "gmeasurable s \<equiv> (\<exists>m. s has_gmeasure m)"
    2.23 -
    2.24 -lemma gmeasurableI[dest]:"s has_gmeasure m \<Longrightarrow> gmeasurable s"
    2.25 -  unfolding gmeasurable_def by auto
    2.26 -
    2.27 -definition gmeasure where
    2.28 -  "gmeasure s \<equiv> (if gmeasurable s then (SOME m. s has_gmeasure m) else 0)"
    2.29 -
    2.30 -lemma has_gmeasure_measure: "gmeasurable s \<longleftrightarrow> s has_gmeasure (gmeasure s)"
    2.31 -  unfolding gmeasure_def gmeasurable_def
    2.32 -  apply meson apply(subst if_P) defer apply(rule someI) by auto
    2.33 -
    2.34 -lemma has_gmeasure_measureI[intro]:"gmeasurable s \<Longrightarrow> s has_gmeasure (gmeasure s)"
    2.35 -  using has_gmeasure_measure by auto
    2.36 -  
    2.37 -lemma has_gmeasure_unique: "s has_gmeasure m1 \<Longrightarrow> s has_gmeasure m2 \<Longrightarrow> m1 = m2"
    2.38 -  unfolding has_gmeasure_def apply(rule has_integral_unique) by auto
    2.39 -
    2.40 -lemma measure_unique[intro]: assumes "s has_gmeasure m" shows "gmeasure s = m"
    2.41 -  apply(rule has_gmeasure_unique[OF _ assms]) using assms 
    2.42 -  unfolding has_gmeasure_measure[THEN sym] by auto
    2.43 -
    2.44 -lemma has_gmeasure_measurable_measure:
    2.45 - "s has_gmeasure m \<longleftrightarrow> gmeasurable s \<and> gmeasure s = m"
    2.46 -  by(auto intro!:measure_unique simp:has_gmeasure_measure[THEN sym])
    2.47 -
    2.48 -lemmas has_gmeasure_imp_measurable = gmeasurableI
    2.49 -
    2.50 -lemma has_gmeasure:
    2.51 - "s has_gmeasure m \<longleftrightarrow> ((\<lambda>x. if x \<in> s then 1 else 0) has_integral m) UNIV"
    2.52 -  unfolding has_integral_restrict_univ has_gmeasure_def ..
    2.53 -
    2.54 -lemma gmeasurable: "gmeasurable s \<longleftrightarrow> (\<lambda>x. 1::real) integrable_on s"
    2.55 -  unfolding gmeasurable_def integrable_on_def has_gmeasure_def by auto
    2.56 -
    2.57 -lemma gmeasurable_integrable:
    2.58 - "gmeasurable s \<longleftrightarrow> (\<lambda>x. if x \<in> s then 1 else (0::real)) integrable_on UNIV"
    2.59 -  unfolding gmeasurable_def integrable_on_def has_gmeasure ..
    2.60 -
    2.61 -lemma measure_integral:
    2.62 -  assumes "gmeasurable s" shows "gmeasure s = (integral s (\<lambda>x. 1))"
    2.63 -  apply(rule integral_unique[THEN sym])
    2.64 -  unfolding has_gmeasure_def[symmetric] using assms by auto 
    2.65 -
    2.66 -lemma measure_integral_univ: assumes "gmeasurable s"
    2.67 -  shows "gmeasure s = (integral UNIV (\<lambda>x. if x \<in> s then 1 else 0))"
    2.68 -  apply(rule integral_unique[THEN sym])
    2.69 -  using assms by(auto simp:has_gmeasure[THEN sym])
    2.70 -
    2.71 -lemmas integral_measure = measure_integral[THEN sym]
    2.72 -
    2.73 -lemmas integral_measure_univ = measure_integral_univ[THEN sym]
    2.74 -
    2.75 -lemma has_gmeasure_interval[intro]:
    2.76 -  "{a..b} has_gmeasure content{a..b}" (is ?t1)
    2.77 -  "{a<..<b} has_gmeasure content{a..b}" (is ?t2)
    2.78 -proof- show ?t1 unfolding has_gmeasure_def using has_integral_const[where c="1::real"] by auto
    2.79 -  show ?t2 unfolding has_gmeasure apply(rule has_integral_spike[of "{a..b} - {a<..<b}",
    2.80 -    where f="\<lambda>x. (if x \<in> {a..b} then 1 else 0)"]) apply(rule negligible_frontier_interval) 
    2.81 -    using interval_open_subset_closed[of a b]
    2.82 -    using `?t1` unfolding has_gmeasure by auto
    2.83 -qed
    2.84 -
    2.85 -lemma gmeasurable_interval[intro]: "gmeasurable {a..b}" "gmeasurable {a<..<b}"
    2.86 -  by(auto intro:gmeasurableI)
    2.87 -
    2.88 -lemma measure_interval[simp]: "gmeasure{a..b} = content{a..b}"  "gmeasure({a<..<b}) = content{a..b}"
    2.89 -  by(auto intro:measure_unique)
    2.90 -
    2.91 -lemma nonnegative_absolutely_integrable: fixes f::"'n::ordered_euclidean_space \<Rightarrow> 'm::ordered_euclidean_space"
    2.92 -  assumes "\<forall>x\<in>s. \<forall>i<DIM('m). 0 \<le> f(x)$$i" "f integrable_on s"
    2.93 -  shows "f absolutely_integrable_on s"
    2.94 -  unfolding absolutely_integrable_abs_eq apply rule defer
    2.95 -  apply(rule integrable_eq[of _ f]) using assms apply-apply(subst euclidean_eq) by auto
    2.96 -
    2.97 -lemma gmeasurable_inter[dest]: assumes "gmeasurable s" "gmeasurable t" shows "gmeasurable (s \<inter> t)"
    2.98 -proof- have *:"(\<lambda>x. if x \<in> s \<inter> t then 1 else (0::real)) =
    2.99 -    (\<lambda>x. \<chi>\<chi> i. min (((if x \<in> s then 1 else 0)::real)$$i) (((if x \<in> t then 1 else 0)::real)$$i))"
   2.100 -    apply(rule ext) by auto
   2.101 -  show ?thesis unfolding gmeasurable_integrable apply(rule absolutely_integrable_onD)
   2.102 -    unfolding * apply(rule absolutely_integrable_min)
   2.103 -    apply(rule_tac[!] nonnegative_absolutely_integrable)
   2.104 -    using assms unfolding gmeasurable_integrable by auto
   2.105 -qed
   2.106 -
   2.107 -lemma gmeasurable_union: assumes "gmeasurable s" "gmeasurable t"
   2.108 -  shows "gmeasurable (s \<union> t)"
   2.109 -proof- have *:"(\<lambda>x. if x \<in> s \<union> t then 1 else (0::real)) =
   2.110 -    (\<lambda>x. \<chi>\<chi> i. max (((if x \<in> s then 1 else 0)::real)$$i) (((if x \<in> t then 1 else 0)::real)$$i)) "
   2.111 -    by(rule ext,auto)
   2.112 -  show ?thesis unfolding gmeasurable_integrable apply(rule absolutely_integrable_onD)
   2.113 -    unfolding * apply(rule absolutely_integrable_max)
   2.114 -    apply(rule_tac[!]nonnegative_absolutely_integrable)
   2.115 -    using assms unfolding gmeasurable_integrable by auto
   2.116 -qed
   2.117 -
   2.118 -lemma has_gmeasure_disjoint_union: 
   2.119 -  assumes "s1 has_gmeasure m1" "s2 has_gmeasure m2" "s1 \<inter> s2 = {}"
   2.120 -  shows "(s1 \<union> s2) has_gmeasure (m1 + m2)"
   2.121 -proof- have *:"\<And>x. (if x \<in> s1 then 1 else 0) + (if x \<in> s2 then 1 else 0) =
   2.122 -    (if x \<in> s1 \<union> s2 then 1 else (0::real))" using assms(3) by auto
   2.123 -  show ?thesis using has_integral_add[OF assms(1-2)[unfolded has_gmeasure]]
   2.124 -    unfolding has_gmeasure * .
   2.125 -qed
   2.126 -
   2.127 -lemma measure_disjoint_union: assumes "gmeasurable s" "gmeasurable t" "s \<inter> t = {}"
   2.128 -  shows "gmeasure(s \<union> t) = gmeasure s + gmeasure t"
   2.129 -  apply rule apply(rule has_gmeasure_disjoint_union) using assms by auto
   2.130 -
   2.131 -lemma has_gmeasure_pos_le[dest]: assumes "s has_gmeasure m" shows "0 \<le> m"
   2.132 -  apply(rule has_integral_nonneg) using assms unfolding has_gmeasure by auto
   2.133 -
   2.134 -lemma not_measurable_measure:"\<not> gmeasurable s \<Longrightarrow> gmeasure s = 0"
   2.135 -  unfolding gmeasure_def if_not_P ..
   2.136 -
   2.137 -lemma measure_pos_le[intro]: "0 <= gmeasure s"
   2.138 -  apply(cases "gmeasurable s") unfolding not_measurable_measure
   2.139 -  unfolding has_gmeasure_measure by auto
   2.140 -
   2.141 -lemma has_gmeasure_subset[dest]:
   2.142 -  assumes "s1 has_gmeasure m1" "s2 has_gmeasure m2" "s1 \<subseteq> s2"
   2.143 -  shows "m1 <= m2"
   2.144 -  using has_integral_subset_le[OF assms(3,1,2)[unfolded has_gmeasure_def]] by auto
   2.145 -
   2.146 -lemma measure_subset[dest]: assumes "gmeasurable s" "gmeasurable t" "s \<subseteq> t"
   2.147 -  shows "gmeasure s \<le> gmeasure t"
   2.148 -  using assms unfolding has_gmeasure_measure by auto
   2.149 -
   2.150 -lemma has_gmeasure_0:"s has_gmeasure 0 \<longleftrightarrow> negligible s" (is "?l = ?r")
   2.151 -proof assume ?r thus ?l unfolding indicator_def_raw negligible apply(erule_tac x="UNIV" in allE)
   2.152 -    unfolding has_integral_restrict_univ has_gmeasure_def .
   2.153 -next assume ?l note this[unfolded has_gmeasure_def has_integral_alt']
   2.154 -  note * = conjunctD2[OF this,rule_format]
   2.155 -  show ?r unfolding negligible_def 
   2.156 -  proof safe case goal1
   2.157 -    from *(1)[of a b,unfolded integrable_on_def] guess y apply-
   2.158 -      apply(subst (asm) has_integral_restrict_univ[THEN sym]) by (erule exE) note y=this
   2.159 -    have "0 \<le> y" apply(rule has_integral_nonneg[OF y]) by auto
   2.160 -    moreover have "y \<le> 0" apply(rule has_integral_le[OF y]) 
   2.161 -      apply(rule `?l`[unfolded has_gmeasure_def has_integral_restrict_univ[THEN sym,of"\<lambda>x. 1"]]) by auto
   2.162 -    ultimately have "y = 0" by auto
   2.163 -    thus ?case using y unfolding has_integral_restrict_univ indicator_def_raw by auto
   2.164 -  qed
   2.165 -qed
   2.166 -
   2.167 -lemma measure_eq_0: "negligible s ==> gmeasure s = 0"
   2.168 -  apply(rule measure_unique) unfolding has_gmeasure_0 by auto
   2.169 -
   2.170 -lemma has_gmeasure_empty[intro]: "{} has_gmeasure 0"
   2.171 -  unfolding has_gmeasure_0 by auto
   2.172 -
   2.173 -lemma measure_empty[simp]: "gmeasure {} = 0"
   2.174 -  apply(rule measure_eq_0) by auto
   2.175 -
   2.176 -lemma gmeasurable_empty[intro]: "gmeasurable {}" by(auto intro:gmeasurableI)
   2.177 -
   2.178 -lemma gmeasurable_measure_eq_0:
   2.179 -  "gmeasurable s ==> (gmeasure s = 0 \<longleftrightarrow> negligible s)"
   2.180 -  unfolding has_gmeasure_measure has_gmeasure_0[THEN sym] by(auto intro:measure_unique)
   2.181 -
   2.182 -lemma gmeasurable_measure_pos_lt:
   2.183 - "gmeasurable s ==> (0 < gmeasure s \<longleftrightarrow> ~negligible s)"
   2.184 -  unfolding gmeasurable_measure_eq_0[THEN sym]
   2.185 -  using measure_pos_le[of s] unfolding le_less by fastsimp
   2.186 -
   2.187 -lemma negligible_interval:True .. (*
   2.188 - "(!a b. negligible{a..b} \<longleftrightarrow> {a<..<b} = {}) \<and>
   2.189 -   (!a b. negligible({a<..<b}) \<longleftrightarrow> {a<..<b} = {})"
   2.190 -qed   REWRITE_TAC[GSYM HAS_GMEASURE_0] THEN
   2.191 -  MESON_TAC[HAS_GMEASURE_INTERVAL; CONTENT_EQ_0_INTERIOR;
   2.192 -            INTERIOR_CLOSED_INTERVAL; HAS_GMEASURE_UNIQUE]);;*)
   2.193 -
   2.194 -lemma gmeasurable_finite_unions:
   2.195 -  assumes "finite f" "\<And>s. s \<in> f \<Longrightarrow> gmeasurable s"
   2.196 -  shows "gmeasurable (\<Union> f)" using assms(1,2) 
   2.197 -proof induct case (insert s F)
   2.198 -  show ?case unfolding Union_insert apply(rule gmeasurable_union)
   2.199 -    using insert by auto
   2.200 -qed auto  
   2.201 -
   2.202 -lemma has_gmeasure_diff_subset: assumes "s1 has_gmeasure m1" "s2 has_gmeasure m2" "s2 \<subseteq> s1"
   2.203 -  shows "(s1 - s2) has_gmeasure (m1 - m2)"
   2.204 -proof- have *:"(\<lambda>x. (if x \<in> s1 then 1 else 0) - (if x \<in> s2 then 1 else (0::real))) =
   2.205 -    (\<lambda>x. if x \<in> s1 - s2 then 1 else 0)" apply(rule ext) using assms(3) by auto
   2.206 -  show ?thesis using has_integral_sub[OF assms(1-2)[unfolded has_gmeasure]] 
   2.207 -    unfolding has_gmeasure * . 
   2.208 -qed
   2.209 -
   2.210 -lemma gmeasurable_diff: assumes "gmeasurable s" "gmeasurable t" 
   2.211 -  shows "gmeasurable (s - t)"
   2.212 -proof- have *:"\<And>s t. gmeasurable s \<Longrightarrow> gmeasurable t \<Longrightarrow> t \<subseteq> s ==> gmeasurable (s - t)"
   2.213 -    unfolding gmeasurable_def apply(erule exE)+ apply(rule,rule has_gmeasure_diff_subset)
   2.214 -    by assumption+
   2.215 -  have **:"s - t = s - (s \<inter> t)" by auto
   2.216 -  show ?thesis unfolding ** apply(rule *) using assms by auto
   2.217 -qed
   2.218 -
   2.219 -lemma measure_diff_subset: True .. (*
   2.220 - "!s t. gmeasurable s \<and> gmeasurable t \<and> t \<subseteq> s
   2.221 -         ==> measure(s DIFF t) = gmeasure s - gmeasure t"
   2.222 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC MEASURE_UNIQUE THEN
   2.223 -  ASM_SIMP_TAC[HAS_GMEASURE_DIFF_SUBSET; GSYM HAS_GMEASURE_MEASURE]);; *)
   2.224 -
   2.225 -lemma has_gmeasure_union_negligible[dest]:
   2.226 -  assumes "s has_gmeasure m" "negligible t"
   2.227 -  shows "(s \<union> t) has_gmeasure m" unfolding has_gmeasure
   2.228 -  apply(rule has_integral_spike[OF assms(2) _ assms(1)[unfolded has_gmeasure]]) by auto
   2.229 -
   2.230 -lemma has_gmeasure_diff_negligible[dest]:
   2.231 -  assumes "s has_gmeasure m" "negligible t" 
   2.232 -  shows "(s - t) has_gmeasure m" unfolding has_gmeasure
   2.233 -  apply(rule has_integral_spike[OF assms(2) _ assms(1)[unfolded has_gmeasure]]) by auto
   2.234 -
   2.235 -lemma has_gmeasure_union_negligible_eq: True .. (*
   2.236 - "!s t:real^N->bool m.
   2.237 -     negligible t ==> ((s \<union> t) has_gmeasure m \<longleftrightarrow> s has_gmeasure m)"
   2.238 -qed   REPEAT STRIP_TAC THEN EQ_TAC THEN DISCH_TAC THEN
   2.239 -  ASM_SIMP_TAC[HAS_GMEASURE_UNION_NEGLIGIBLE] THEN
   2.240 -  SUBST1_TAC(SET_RULE `s:real^N->bool = (s \<union> t) DIFF (t DIFF s)`) THEN
   2.241 -  MATCH_MP_TAC HAS_GMEASURE_DIFF_NEGLIGIBLE THEN ASM_REWRITE_TAC[] THEN
   2.242 -  MATCH_MP_TAC NEGLIGIBLE_DIFF THEN ASM_REWRITE_TAC[]);; *)
   2.243 -
   2.244 -lemma has_gmeasure_diff_negligible_eq: True .. (*
   2.245 - "!s t:real^N->bool m.
   2.246 -     negligible t ==> ((s DIFF t) has_gmeasure m \<longleftrightarrow> s has_gmeasure m)"
   2.247 -qed   REPEAT STRIP_TAC THEN EQ_TAC THEN DISCH_TAC THEN
   2.248 -  ASM_SIMP_TAC[HAS_GMEASURE_DIFF_NEGLIGIBLE] THEN
   2.249 -  SUBST1_TAC(SET_RULE `s:real^N->bool = (s DIFF t) \<union> (t \<inter> s)`) THEN
   2.250 -  MATCH_MP_TAC HAS_GMEASURE_UNION_NEGLIGIBLE THEN
   2.251 -  ASM_SIMP_TAC[NEGLIGIBLE_INTER]);; *)
   2.252 -
   2.253 -lemma has_gmeasure_almost: assumes "s has_gmeasure m" "negligible t" "s \<union> t = s' \<union> t"
   2.254 -  shows "s' has_gmeasure m"
   2.255 -proof- have *:"s' \<union> t - (t - s') = s'" by blast
   2.256 -  show ?thesis using has_gmeasure_union_negligible[OF assms(1-2)] unfolding assms(3)
   2.257 -    apply-apply(drule has_gmeasure_diff_negligible[where t="t - s'"])
   2.258 -    apply(rule negligible_diff) using assms(2) unfolding * by auto
   2.259 -qed
   2.260 -
   2.261 -lemma has_gmeasure_almost_eq: True .. (*
   2.262 - "!s s' t. negligible t \<and> s \<union> t = s' \<union> t
   2.263 -            ==> (s has_gmeasure m \<longleftrightarrow> s' has_gmeasure m)"
   2.264 -qed   MESON_TAC[HAS_GMEASURE_ALMOST]);; *)
   2.265 -
   2.266 -lemma gmeasurable_almost: True .. (*
   2.267 - "!s s' t. gmeasurable s \<and> negligible t \<and> s \<union> t = s' \<union> t
   2.268 -            ==> gmeasurable s'"
   2.269 -qed   REWRITE_TAC[measurable] THEN MESON_TAC[HAS_GMEASURE_ALMOST]);; *)
   2.270 -
   2.271 -lemma has_gmeasure_negligible_union:
   2.272 -  assumes "s1 has_gmeasure m1" "s2 has_gmeasure m2" "negligible(s1 \<inter> s2)"
   2.273 -  shows "(s1 \<union> s2) has_gmeasure (m1 + m2)" 
   2.274 -  apply(rule has_gmeasure_almost[of "(s1 - (s1 \<inter> s2)) \<union> (s2 - (s1 \<inter> s2))" _ "s1 \<inter> s2"])
   2.275 -  apply(rule has_gmeasure_disjoint_union)
   2.276 -  apply(rule has_gmeasure_almost[of s1,OF _ assms(3)]) prefer 3
   2.277 -  apply(rule has_gmeasure_almost[of s2,OF _ assms(3)])
   2.278 -  using assms by auto
   2.279 -
   2.280 -lemma measure_negligible_union: True .. (*
   2.281 -  "!s t. gmeasurable s \<and> gmeasurable t \<and> negligible(s \<inter> t)
   2.282 -         ==> measure(s \<union> t) = gmeasure s + gmeasure t"
   2.283 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC MEASURE_UNIQUE THEN
   2.284 -  ASM_SIMP_TAC[HAS_GMEASURE_NEGLIGIBLE_UNION; GSYM HAS_GMEASURE_MEASURE]);; *)
   2.285 -
   2.286 -lemma has_gmeasure_negligible_symdiff: True .. (*
   2.287 - "!s t:real^N->bool m.
   2.288 -        s has_gmeasure m \<and>
   2.289 -        negligible((s DIFF t) \<union> (t DIFF s))
   2.290 -        ==> t has_gmeasure m"
   2.291 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC HAS_GMEASURE_ALMOST THEN
   2.292 -  MAP_EVERY EXISTS_TAC
   2.293 -   [`s:real^N->bool`; `(s DIFF t) \<union> (t DIFF s):real^N->bool`] THEN
   2.294 -  ASM_REWRITE_TAC[] THEN SET_TAC[]);; *)
   2.295 -
   2.296 -lemma gmeasurable_negligible_symdiff: True .. (*
   2.297 - "!s t:real^N->bool.
   2.298 -        gmeasurable s \<and> negligible((s DIFF t) \<union> (t DIFF s))
   2.299 -        ==> gmeasurable t"
   2.300 -qed   REWRITE_TAC[measurable] THEN
   2.301 -  MESON_TAC[HAS_GMEASURE_NEGLIGIBLE_SYMDIFF]);; *)
   2.302 -
   2.303 -lemma measure_negligible_symdiff: True .. (*
   2.304 - "!s t:real^N->bool.
   2.305 -        (measurable s \/ gmeasurable t) \<and>
   2.306 -        negligible((s DIFF t) \<union> (t DIFF s))
   2.307 -        ==> gmeasure s = gmeasure t"
   2.308 -qed   MESON_TAC[HAS_GMEASURE_NEGLIGIBLE_SYMDIFF; MEASURE_UNIQUE; UNION_COMM;
   2.309 -                HAS_GMEASURE_MEASURE]);; *)
   2.310 -
   2.311 -lemma has_gmeasure_negligible_unions: assumes "finite f"
   2.312 -  "\<And>s. s \<in> f ==> s has_gmeasure (m s)"
   2.313 -  "\<And>s t. s \<in> f \<Longrightarrow> t \<in> f \<Longrightarrow> ~(s = t) ==> negligible(s \<inter> t)"
   2.314 -  shows "(\<Union> f) has_gmeasure (setsum m f)" using assms
   2.315 -proof induct case (insert x s)
   2.316 -  have *:"(x \<inter> \<Union>s) = \<Union>{x \<inter> y| y. y\<in>s}"by auto
   2.317 -  show ?case unfolding Union_insert setsum.insert [OF insert(1-2)] 
   2.318 -    apply(rule has_gmeasure_negligible_union) unfolding *
   2.319 -    apply(rule insert) defer apply(rule insert) apply(rule insert) defer
   2.320 -    apply(rule insert) prefer 4 apply(rule negligible_unions)
   2.321 -    defer apply safe apply(rule insert) using insert by auto
   2.322 -qed auto
   2.323 -
   2.324 -lemma measure_negligible_unions: 
   2.325 -  assumes "finite f" "\<And>s. s \<in> f ==> s has_gmeasure (m s)"
   2.326 -  "\<And>s t. s \<in> f \<Longrightarrow> t \<in> f \<Longrightarrow> s \<noteq> t ==> negligible(s \<inter> t)"
   2.327 -  shows "gmeasure(\<Union> f) = setsum m f"
   2.328 -  apply rule apply(rule has_gmeasure_negligible_unions)
   2.329 -  using assms by auto
   2.330 -
   2.331 -lemma has_gmeasure_disjoint_unions:
   2.332 -  assumes"finite f" "\<And>s. s \<in> f ==> s has_gmeasure (m s)"
   2.333 -  "\<And>s t. s \<in> f \<Longrightarrow> t \<in> f \<Longrightarrow> s \<noteq> t ==> s \<inter> t = {}"
   2.334 -  shows "(\<Union> f) has_gmeasure (setsum m f)"
   2.335 -  apply(rule has_gmeasure_negligible_unions[OF assms(1-2)]) using assms(3) by auto
   2.336 -
   2.337 -lemma measure_disjoint_unions: 
   2.338 -  assumes "finite f" "\<And>s. s \<in> f ==> s has_gmeasure (m s)" 
   2.339 -  "\<And>s t. s \<in> f \<Longrightarrow> t \<in> f \<Longrightarrow> s \<noteq> t ==> s \<inter> t = {}"
   2.340 -  shows "gmeasure(\<Union> f) = setsum m f"
   2.341 -  apply rule apply(rule has_gmeasure_disjoint_unions[OF assms]) by auto
   2.342 -
   2.343 -lemma has_gmeasure_negligible_unions_image:
   2.344 -  assumes "finite s" "\<And>x. x \<in> s ==> gmeasurable(f x)"
   2.345 -  "\<And>x y. x \<in> s \<Longrightarrow> y \<in> s \<Longrightarrow> x \<noteq> y \<Longrightarrow> negligible((f x) \<inter> (f y))"
   2.346 -  shows "(\<Union> (f ` s)) has_gmeasure (setsum (\<lambda>x. gmeasure(f x)) s)"
   2.347 -proof- have *:"setsum (\<lambda>x. gmeasure(f x)) s = setsum gmeasure (f ` s)"
   2.348 -    apply(subst setsum_reindex_nonzero) defer
   2.349 -    apply(subst gmeasurable_measure_eq_0)
   2.350 -  proof- case goal2 thus ?case using assms(3)[of x y] by auto
   2.351 -  qed(insert assms, auto)
   2.352 -  show ?thesis unfolding * apply(rule has_gmeasure_negligible_unions) using assms by auto
   2.353 -qed
   2.354 -
   2.355 -lemma measure_negligible_unions_image: True .. (*
   2.356 - "!f:A->real^N->bool s.
   2.357 -        FINITE s \<and>
   2.358 -        (!x. x \<in> s ==> gmeasurable(f x)) \<and>
   2.359 -        (!x y. x \<in> s \<and> y \<in> s \<and> ~(x = y) ==> negligible((f x) \<inter> (f y)))
   2.360 -        ==> measure(UNIONS (IMAGE f s)) = sum s (\<lambda>x. measure(f x))"
   2.361 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC MEASURE_UNIQUE THEN
   2.362 -  ASM_SIMP_TAC[HAS_GMEASURE_NEGLIGIBLE_UNIONS_IMAGE]);;*)
   2.363 -
   2.364 -lemma has_gmeasure_disjoint_unions_image: True .. (*
   2.365 - "!f:A->real^N->bool s.
   2.366 -        FINITE s \<and>
   2.367 -        (!x. x \<in> s ==> gmeasurable(f x)) \<and>
   2.368 -        (!x y. x \<in> s \<and> y \<in> s \<and> ~(x = y) ==> DISJOINT (f x) (f y))
   2.369 -        ==> (UNIONS (IMAGE f s)) has_gmeasure (sum s (\<lambda>x. measure(f x)))"
   2.370 -qed   REWRITE_TAC[DISJOINT] THEN REPEAT STRIP_TAC THEN
   2.371 -  MATCH_MP_TAC HAS_GMEASURE_NEGLIGIBLE_UNIONS_IMAGE THEN
   2.372 -  ASM_SIMP_TAC[NEGLIGIBLE_EMPTY]);;*)
   2.373 -
   2.374 -lemma measure_disjoint_unions_image: True .. (*
   2.375 - "!f:A->real^N->bool s.
   2.376 -        FINITE s \<and>
   2.377 -        (!x. x \<in> s ==> gmeasurable(f x)) \<and>
   2.378 -        (!x y. x \<in> s \<and> y \<in> s \<and> ~(x = y) ==> DISJOINT (f x) (f y))
   2.379 -        ==> measure(UNIONS (IMAGE f s)) = sum s (\<lambda>x. measure(f x))"
   2.380 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC MEASURE_UNIQUE THEN
   2.381 -  ASM_SIMP_TAC[HAS_GMEASURE_DISJOINT_UNIONS_IMAGE]);;*)
   2.382 -
   2.383 -lemma has_gmeasure_negligible_unions_image_strong: True .. (*
   2.384 - "!f:A->real^N->bool s.
   2.385 -        FINITE {x | x \<in> s \<and> ~(f x = {})} \<and>
   2.386 -        (!x. x \<in> s ==> gmeasurable(f x)) \<and>
   2.387 -        (!x y. x \<in> s \<and> y \<in> s \<and> ~(x = y) ==> negligible((f x) \<inter> (f y)))
   2.388 -        ==> (UNIONS (IMAGE f s)) has_gmeasure (sum s (\<lambda>x. measure(f x)))"
   2.389 -qed   REPEAT STRIP_TAC THEN
   2.390 -  MP_TAC(ISPECL [`f:A->real^N->bool`;
   2.391 -                 `{x | x \<in> s \<and> ~((f:A->real^N->bool) x = {})}`]
   2.392 -        HAS_GMEASURE_NEGLIGIBLE_UNIONS_IMAGE) THEN
   2.393 -  ASM_SIMP_TAC[IN_ELIM_THM; FINITE_RESTRICT] THEN
   2.394 -  MATCH_MP_TAC EQ_IMP THEN BINOP_TAC THENL
   2.395 -   [GEN_REWRITE_TAC I [EXTENSION] THEN
   2.396 -    REWRITE_TAC[IN_UNIONS; IN_IMAGE; IN_ELIM_THM] THEN
   2.397 -    MESON_TAC[NOT_IN_EMPTY];
   2.398 -    CONV_TAC SYM_CONV THEN MATCH_MP_TAC SUM_SUPERSET THEN
   2.399 -    SIMP_TAC[SUBSET; IN_ELIM_THM; TAUT `a \<and> ~(a \<and> b) \<longleftrightarrow> a \<and> ~b`] THEN
   2.400 -    REWRITE_TAC[MEASURE_EMPTY]]);; *)
   2.401 -
   2.402 -lemma measure_negligible_unions_image_strong: True .. (*
   2.403 - "!f:A->real^N->bool s.
   2.404 -        FINITE {x | x \<in> s \<and> ~(f x = {})} \<and>
   2.405 -        (!x. x \<in> s ==> gmeasurable(f x)) \<and>
   2.406 -        (!x y. x \<in> s \<and> y \<in> s \<and> ~(x = y) ==> negligible((f x) \<inter> (f y)))
   2.407 -        ==> measure(UNIONS (IMAGE f s)) = sum s (\<lambda>x. measure(f x))"
   2.408 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC MEASURE_UNIQUE THEN
   2.409 -  ASM_SIMP_TAC[HAS_GMEASURE_NEGLIGIBLE_UNIONS_IMAGE_STRONG]);; *)
   2.410 -
   2.411 -lemma has_gmeasure_disjoint_unions_image_strong: True .. (*
   2.412 - "!f:A->real^N->bool s.
   2.413 -        FINITE {x | x \<in> s \<and> ~(f x = {})} \<and>
   2.414 -        (!x. x \<in> s ==> gmeasurable(f x)) \<and>
   2.415 -        (!x y. x \<in> s \<and> y \<in> s \<and> ~(x = y) ==> DISJOINT (f x) (f y))
   2.416 -        ==> (UNIONS (IMAGE f s)) has_gmeasure (sum s (\<lambda>x. measure(f x)))"
   2.417 -qed   REWRITE_TAC[DISJOINT] THEN REPEAT STRIP_TAC THEN
   2.418 -  MATCH_MP_TAC HAS_GMEASURE_NEGLIGIBLE_UNIONS_IMAGE_STRONG THEN
   2.419 -  ASM_SIMP_TAC[NEGLIGIBLE_EMPTY]);; *)
   2.420 -
   2.421 -lemma measure_disjoint_unions_image_strong: True .. (*
   2.422 - "!f:A->real^N->bool s.
   2.423 -        FINITE {x | x \<in> s \<and> ~(f x = {})} \<and>
   2.424 -        (!x. x \<in> s ==> gmeasurable(f x)) \<and>
   2.425 -        (!x y. x \<in> s \<and> y \<in> s \<and> ~(x = y) ==> DISJOINT (f x) (f y))
   2.426 -        ==> measure(UNIONS (IMAGE f s)) = sum s (\<lambda>x. measure(f x))"
   2.427 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC MEASURE_UNIQUE THEN
   2.428 -  ASM_SIMP_TAC[HAS_GMEASURE_DISJOINT_UNIONS_IMAGE_STRONG]);; *)
   2.429 -
   2.430 -lemma measure_union: True .. (*
   2.431 - "!s t:real^N->bool.
   2.432 -        gmeasurable s \<and> gmeasurable t
   2.433 -        ==> measure(s \<union> t) = measure(s) + measure(t) - measure(s \<inter> t)"
   2.434 -qed   REPEAT STRIP_TAC THEN
   2.435 -  ONCE_REWRITE_TAC[SET_RULE
   2.436 -   `s \<union> t = (s \<inter> t) \<union> (s DIFF t) \<union> (t DIFF s)`] THEN
   2.437 -  ONCE_REWRITE_TAC[REAL_ARITH `a + b - c = c + (a - c) + (b - c)`] THEN
   2.438 -  MP_TAC(ISPECL [`s DIFF t:real^N->bool`; `t DIFF s:real^N->bool`]
   2.439 -        MEASURE_DISJOINT_UNION) THEN
   2.440 -  ASM_SIMP_TAC[MEASURABLE_DIFF] THEN
   2.441 -  ANTS_TAC THENL [SET_TAC[]; ALL_TAC] THEN
   2.442 -  MP_TAC(ISPECL [`s \<inter> t:real^N->bool`;
   2.443 -                 `(s DIFF t) \<union> (t DIFF s):real^N->bool`]
   2.444 -                MEASURE_DISJOINT_UNION) THEN
   2.445 -  ASM_SIMP_TAC[MEASURABLE_DIFF; GMEASURABLE_UNION; GMEASURABLE_INTER] THEN
   2.446 -  ANTS_TAC THENL [SET_TAC[]; ALL_TAC] THEN
   2.447 -  REPEAT(DISCH_THEN SUBST1_TAC) THEN AP_TERM_TAC THEN BINOP_TAC THEN
   2.448 -  REWRITE_TAC[REAL_EQ_SUB_LADD] THEN MATCH_MP_TAC EQ_TRANS THENL
   2.449 -   [EXISTS_TAC `measure((s DIFF t) \<union> (s \<inter> t):real^N->bool)`;
   2.450 -    EXISTS_TAC `measure((t DIFF s) \<union> (s \<inter> t):real^N->bool)`] THEN
   2.451 -  (CONJ_TAC THENL
   2.452 -    [CONV_TAC SYM_CONV THEN MATCH_MP_TAC MEASURE_DISJOINT_UNION THEN
   2.453 -     ASM_SIMP_TAC[MEASURABLE_DIFF; GMEASURABLE_INTER];
   2.454 -     AP_TERM_TAC] THEN
   2.455 -   SET_TAC[]));; *)
   2.456 -
   2.457 -lemma measure_union_le: True .. (*
   2.458 - "!s t:real^N->bool.
   2.459 -        gmeasurable s \<and> gmeasurable t
   2.460 -        ==> measure(s \<union> t) <= gmeasure s + gmeasure t"
   2.461 -qed   REPEAT STRIP_TAC THEN ASM_SIMP_TAC[MEASURE_UNION] THEN
   2.462 -  REWRITE_TAC[REAL_ARITH `a + b - c <= a + b \<longleftrightarrow> 0 <= c`] THEN
   2.463 -  MATCH_MP_TAC MEASURE_POS_LE THEN ASM_SIMP_TAC[MEASURABLE_INTER]);; *)
   2.464 -
   2.465 -lemma measure_unions_le: True .. (*
   2.466 - "!f:(real^N->bool)->bool.
   2.467 -        FINITE f \<and> (!s. s \<in> f ==> gmeasurable s)
   2.468 -        ==> measure(UNIONS f) <= sum f (\<lambda>s. gmeasure s)"
   2.469 -qed   REWRITE_TAC[IMP_CONJ] THEN
   2.470 -  MATCH_MP_TAC FINITE_INDUCT_STRONG THEN
   2.471 -  SIMP_TAC[UNIONS_0; UNIONS_INSERT; SUM_CLAUSES] THEN
   2.472 -  REWRITE_TAC[MEASURE_EMPTY; REAL_LE_REFL] THEN
   2.473 -  MAP_EVERY X_GEN_TAC [`s:real^N->bool`; `f:(real^N->bool)->bool`] THEN
   2.474 -  REWRITE_TAC[IN_INSERT] THEN REPEAT STRIP_TAC THEN
   2.475 -  MATCH_MP_TAC REAL_LE_TRANS THEN
   2.476 -  EXISTS_TAC `measure(s:real^N->bool) + measure(UNIONS f:real^N->bool)` THEN
   2.477 -  ASM_SIMP_TAC[MEASURE_UNION_LE; GMEASURABLE_UNIONS] THEN
   2.478 -  REWRITE_TAC[REAL_LE_LADD] THEN FIRST_X_ASSUM MATCH_MP_TAC THEN
   2.479 -  ASM_SIMP_TAC[]);; *)
   2.480 -
   2.481 -lemma measure_unions_le_image: True .. (*
   2.482 - "!f:A->bool s:A->(real^N->bool).
   2.483 -        FINITE f \<and> (!a. a \<in> f ==> gmeasurable(s a))
   2.484 -        ==> measure(UNIONS (IMAGE s f)) <= sum f (\<lambda>a. measure(s a))"
   2.485 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC REAL_LE_TRANS THEN
   2.486 -  EXISTS_TAC `sum (IMAGE s (f:A->bool)) (\<lambda>k:real^N->bool. gmeasure k)` THEN
   2.487 -  ASM_SIMP_TAC[MEASURE_UNIONS_LE; FORALL_IN_IMAGE; FINITE_IMAGE] THEN
   2.488 -  GEN_REWRITE_TAC (RAND_CONV o RAND_CONV) [GSYM o_DEF] THEN
   2.489 -  REWRITE_TAC[ETA_AX] THEN MATCH_MP_TAC SUM_IMAGE_LE THEN
   2.490 -  ASM_SIMP_TAC[MEASURE_POS_LE]);; *)
   2.491 -
   2.492 -lemma gmeasurable_inner_outer: True .. (*
   2.493 - "!s:real^N->bool.
   2.494 -        gmeasurable s \<longleftrightarrow>
   2.495 -                !e. 0 < e
   2.496 -                    ==> ?t u. t \<subseteq> s \<and> s \<subseteq> u \<and>
   2.497 -                              gmeasurable t \<and> gmeasurable u \<and>
   2.498 -                              abs(measure t - gmeasure u) < e"
   2.499 -qed   GEN_TAC THEN EQ_TAC THEN DISCH_TAC THENL
   2.500 -   [GEN_TAC THEN DISCH_TAC THEN REPEAT(EXISTS_TAC `s:real^N->bool`) THEN
   2.501 -    ASM_REWRITE_TAC[SUBSET_REFL; REAL_SUB_REFL; REAL_ABS_NUM];
   2.502 -    ALL_TAC] THEN
   2.503 -  REWRITE_TAC[MEASURABLE_INTEGRABLE] THEN MATCH_MP_TAC INTEGRABLE_STRADDLE THEN
   2.504 -  X_GEN_TAC `e:real` THEN DISCH_TAC THEN
   2.505 -  FIRST_X_ASSUM(MP_TAC o SPEC `e:real`) THEN
   2.506 -  ASM_REWRITE_TAC[LEFT_IMP_EXISTS_THM] THEN
   2.507 -  MAP_EVERY X_GEN_TAC [`t:real^N->bool`; `u:real^N->bool`] THEN STRIP_TAC THEN
   2.508 -  MAP_EVERY EXISTS_TAC
   2.509 -   [`(\<lambda>x. if x \<in> t then 1 else 0):real^N->real^1`;
   2.510 -    `(\<lambda>x. if x \<in> u then 1 else 0):real^N->real^1`;
   2.511 -    `lift(measure(t:real^N->bool))`;
   2.512 -    `lift(measure(u:real^N->bool))`] THEN
   2.513 -  ASM_REWRITE_TAC[GSYM HAS_GMEASURE; GSYM HAS_GMEASURE_MEASURE] THEN
   2.514 -  ASM_REWRITE_TAC[GSYM LIFT_SUB; NORM_LIFT] THEN REPEAT STRIP_TAC THEN
   2.515 -  REPEAT(COND_CASES_TAC THEN
   2.516 -         ASM_REWRITE_TAC[_VEC; REAL_POS; REAL_LE_REFL]) THEN
   2.517 -  ASM SET_TAC[]);; *)
   2.518 -
   2.519 -lemma has_gmeasure_inner_outer: True .. (*
   2.520 - "!s:real^N->bool m.
   2.521 -        s has_gmeasure m \<longleftrightarrow>
   2.522 -                (!e. 0 < e ==> ?t. t \<subseteq> s \<and> gmeasurable t \<and>
   2.523 -                                    m - e < gmeasure t) \<and>
   2.524 -                (!e. 0 < e ==> ?u. s \<subseteq> u \<and> gmeasurable u \<and>
   2.525 -                                    gmeasure u < m + e)"
   2.526 -qed   REPEAT GEN_TAC THEN
   2.527 -  GEN_REWRITE_TAC LAND_CONV [HAS_GMEASURE_MEASURABLE_MEASURE] THEN EQ_TAC THENL
   2.528 -   [REPEAT STRIP_TAC THEN EXISTS_TAC `s:real^N->bool` THEN
   2.529 -    ASM_REWRITE_TAC[SUBSET_REFL] THEN ASM_REAL_ARITH_TAC;
   2.530 -    ALL_TAC] THEN
   2.531 -  DISCH_THEN(CONJUNCTS_THEN2 (LABEL_TAC "t") (LABEL_TAC "u")) THEN
   2.532 -  MATCH_MP_TAC(TAUT `a \<and> (a ==> b) ==> a \<and> b`) THEN CONJ_TAC THENL
   2.533 -   [GEN_REWRITE_TAC I [MEASURABLE_INNER_OUTER] THEN
   2.534 -    X_GEN_TAC `e:real` THEN DISCH_TAC THEN
   2.535 -    REMOVE_THEN "u" (MP_TAC o SPEC `e / 2`) THEN
   2.536 -    REMOVE_THEN "t" (MP_TAC o SPEC `e / 2`) THEN
   2.537 -    ASM_SIMP_TAC[REAL_LT_DIV; REAL_OF_NUM_LT; ARITH] THEN
   2.538 -    REWRITE_TAC[IMP_IMP; LEFT_AND_EXISTS_THM] THEN
   2.539 -    REWRITE_TAC[RIGHT_AND_EXISTS_THM] THEN
   2.540 -    REPEAT(MATCH_MP_TAC MONO_EXISTS THEN GEN_TAC) THEN
   2.541 -    STRIP_TAC THEN ASM_REWRITE_TAC[] THEN MATCH_MP_TAC(REAL_ARITH
   2.542 -     `0 < e \<and> t <= u \<and> m - e / 2 < t \<and> u < m + e / 2
   2.543 -                          ==> abs(t - u) < e`) THEN
   2.544 -    ASM_REWRITE_TAC[] THEN MATCH_MP_TAC MEASURE_SUBSET THEN
   2.545 -    ASM_REWRITE_TAC[] THEN ASM SET_TAC[];
   2.546 -    DISCH_TAC THEN MATCH_MP_TAC(REAL_ARITH
   2.547 -     `~(0 < x - y) \<and> ~(0 < y - x) ==> x = y`) THEN
   2.548 -    CONJ_TAC THEN DISCH_TAC THENL
   2.549 -     [REMOVE_THEN "u" (MP_TAC o SPEC `measure(s:real^N->bool) - m`) THEN
   2.550 -      ASM_REWRITE_TAC[REAL_SUB_ADD2; GSYM REAL_NOT_LE];
   2.551 -      REMOVE_THEN "t" (MP_TAC o SPEC `m - measure(s:real^N->bool)`) THEN
   2.552 -      ASM_REWRITE_TAC[REAL_SUB_SUB2; GSYM REAL_NOT_LE]] THEN
   2.553 -    ASM_MESON_TAC[MEASURE_SUBSET]]);; *)
   2.554 -
   2.555 -lemma has_gmeasure_inner_outer_le: True .. (*
   2.556 - "!s:real^N->bool m.
   2.557 -        s has_gmeasure m \<longleftrightarrow>
   2.558 -                (!e. 0 < e ==> ?t. t \<subseteq> s \<and> gmeasurable t \<and>
   2.559 -                                    m - e <= gmeasure t) \<and>
   2.560 -                (!e. 0 < e ==> ?u. s \<subseteq> u \<and> gmeasurable u \<and>
   2.561 -                                    gmeasure u <= m + e)"
   2.562 -qed   REWRITE_TAC[HAS_GMEASURE_INNER_OUTER] THEN
   2.563 -  MESON_TAC[REAL_ARITH `0 < e \<and> m - e / 2 <= t ==> m - e < t`;
   2.564 -            REAL_ARITH `0 < e \<and> u <= m + e / 2 ==> u < m + e`;
   2.565 -            REAL_ARITH `0 < e \<longleftrightarrow> 0 < e / 2`; REAL_LT_IMP_LE]);; *)
   2.566 -
   2.567 -lemma has_gmeasure_limit: True .. (*
   2.568 - "!s. s has_gmeasure m \<longleftrightarrow>
   2.569 -        !e. 0 < e
   2.570 -            ==> ?B. 0 < B \<and>
   2.571 -                    !a b. ball(0,B) \<subseteq> {a..b}
   2.572 -                          ==> ?z. (s \<inter> {a..b}) has_gmeasure z \<and>
   2.573 -                                  abs(z - m) < e"
   2.574 -qed   GEN_TAC THEN REWRITE_TAC[HAS_GMEASURE] THEN
   2.575 -  GEN_REWRITE_TAC LAND_CONV [HAS_INTEGRAL] THEN
   2.576 -  REWRITE_TAC[IN_UNIV] THEN
   2.577 -  GEN_REWRITE_TAC (LAND_CONV o ONCE_DEPTH_CONV)
   2.578 -    [GSYM HAS_INTEGRAL_RESTRICT_UNIV] THEN
   2.579 -  REWRITE_TAC[MESON[IN_INTER]
   2.580 -        `(if x \<in> k \<inter> s then a else b) =
   2.581 -         (if x \<in> s then if x \<in> k then a else b else b)`] THEN
   2.582 -  REWRITE_TAC[EXISTS_LIFT; GSYM LIFT_SUB; NORM_LIFT]);; *)
   2.583 -
   2.584 -(* ------------------------------------------------------------------------- *)
   2.585 -(* properties of gmeasure under simple affine transformations.                *)
   2.586 -(* ------------------------------------------------------------------------- *)
   2.587 -
   2.588 -lemma has_gmeasure_affinity: True .. (*
   2.589 - "!s m c y. s has_gmeasure y
   2.590 -             ==> (IMAGE (\<lambda>x:real^N. m % x + c) s)
   2.591 -                 has_gmeasure abs(m) pow (dimindex(:N)) * y"
   2.592 -qed   REPEAT GEN_TAC THEN ASM_CASES_TAC `m = 0` THENL
   2.593 -   [ASM_REWRITE_TAC[REAL_ABS_NUM; VECTOR_ADD_LID; VECTOR_MUL_LZERO] THEN
   2.594 -    ONCE_REWRITE_TAC[MATCH_MP (ARITH_RULE `~(x = 0) ==> x = SUC(x - 1)`)
   2.595 -     (SPEC_ALL DIMINDEX_NONZERO)] THEN DISCH_TAC THEN
   2.596 -    REWRITE_TAC[real_pow; REAL_MUL_LZERO; HAS_GMEASURE_0] THEN
   2.597 -    MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN EXISTS_TAC `{c:real^N}` THEN
   2.598 -    SIMP_TAC[NEGLIGIBLE_FINITE; FINITE_RULES] THEN SET_TAC[];
   2.599 -    ALL_TAC] THEN
   2.600 -  REWRITE_TAC[HAS_GMEASURE] THEN
   2.601 -  ONCE_REWRITE_TAC[HAS_INTEGRAL] THEN REWRITE_TAC[IN_UNIV] THEN
   2.602 -  DISCH_TAC THEN X_GEN_TAC `e:real` THEN DISCH_TAC THEN
   2.603 -  FIRST_X_ASSUM(MP_TAC o SPEC `e:real / abs(m) pow dimindex(:N)`) THEN
   2.604 -  ASM_SIMP_TAC[REAL_LT_DIV; REAL_POW_LT; GSYM REAL_ABS_NZ; REAL_POW_LT] THEN
   2.605 -  DISCH_THEN(X_CHOOSE_THEN `B:real` STRIP_ASSUME_TAC) THEN
   2.606 -  EXISTS_TAC `abs(m) * B + norm(c:real^N)` THEN
   2.607 -  ASM_SIMP_TAC[REAL_ARITH `0 < B \<and> 0 <= x ==> 0 < B + x`;
   2.608 -               NORM_POS_LE; REAL_LT_MUL; GSYM REAL_ABS_NZ; REAL_POW_LT] THEN
   2.609 -  MAP_EVERY X_GEN_TAC [`u:real^N`; `v:real^N`] THEN DISCH_TAC THEN
   2.610 -  REWRITE_TAC[IN_IMAGE] THEN
   2.611 -  ASM_SIMP_TAC[VECTOR_EQ_AFFINITY; UNWIND_THM1] THEN
   2.612 -  FIRST_X_ASSUM(MP_TAC o SPECL
   2.613 -    [`if 0 <= m then inv m % u + --(inv m % c):real^N
   2.614 -                 else inv m % v + --(inv m % c)`;
   2.615 -     `if 0 <= m then inv m % v + --(inv m % c):real^N
   2.616 -                 else inv m % u + --(inv m % c)`]) THEN
   2.617 -  MATCH_MP_TAC(TAUT `a \<and> (a ==> b ==> c) ==> (a ==> b) ==> c`) THEN
   2.618 -  CONJ_TAC THENL
   2.619 -   [REWRITE_TAC[SUBSET] THEN X_GEN_TAC `x:real^N` THEN
   2.620 -    FIRST_X_ASSUM(MP_TAC o GEN_REWRITE_RULE I [SUBSET]) THEN
   2.621 -    DISCH_THEN(MP_TAC o SPEC `m % x + c:real^N`) THEN
   2.622 -    MATCH_MP_TAC MONO_IMP THEN REWRITE_TAC[IN_BALL; IN_INTERVAL] THEN
   2.623 -    CONJ_TAC THENL
   2.624 -     [REWRITE_TAC[NORM_ARITH `dist(0,x) = norm(x:real^N)`] THEN
   2.625 -      DISCH_TAC THEN MATCH_MP_TAC(NORM_ARITH
   2.626 -       `norm(x:real^N) < a ==> norm(x + y) < a + norm(y)`) THEN
   2.627 -      ASM_SIMP_TAC[NORM_MUL; REAL_LT_LMUL; GSYM REAL_ABS_NZ];
   2.628 -      ALL_TAC] THEN
   2.629 -    SIMP_TAC[VECTOR_ADD_COMPONENT; VECTOR_MUL_COMPONENT; VECTOR_NEG_COMPONENT;
   2.630 -             COND_COMPONENT] THEN
   2.631 -    MATCH_MP_TAC MONO_FORALL THEN GEN_TAC THEN MATCH_MP_TAC MONO_IMP THEN
   2.632 -    REWRITE_TAC[REAL_ARITH `m * u + --(m * c):real = (u - c) * m`] THEN
   2.633 -    SUBST1_TAC(REAL_ARITH
   2.634 -      `inv(m) = if 0 <= inv(m) then abs(inv m) else --(abs(inv m))`) THEN
   2.635 -    SIMP_TAC[REAL_LE_INV_EQ] THEN
   2.636 -    REWRITE_TAC[REAL_ARITH `(x - y:real) * --z = (y - x) * z`] THEN
   2.637 -    REWRITE_TAC[REAL_ABS_INV; GSYM real_div] THEN COND_CASES_TAC THEN
   2.638 -    ASM_SIMP_TAC[REAL_LE_LDIV_EQ; REAL_LE_RDIV_EQ; GSYM REAL_ABS_NZ] THEN
   2.639 -    ASM_REWRITE_TAC[real_abs] THEN REAL_ARITH_TAC;
   2.640 -    ALL_TAC] THEN
   2.641 -  REWRITE_TAC[SUBSET] THEN DISCH_THEN(MP_TAC o SPEC `0:real^N`) THEN
   2.642 -  ASM_REWRITE_TAC[CENTRE_IN_BALL] THEN DISCH_TAC THEN
   2.643 -  DISCH_THEN(X_CHOOSE_THEN `z:real^1`
   2.644 -   (fun th -> EXISTS_TAC `(abs m pow dimindex (:N)) % z:real^1` THEN
   2.645 -              MP_TAC th)) THEN
   2.646 -  DISCH_THEN(CONJUNCTS_THEN2 MP_TAC ASSUME_TAC) THEN
   2.647 -  FIRST_ASSUM(MP_TAC o MATCH_MP(REAL_FIELD `~(x = 0) ==> ~(inv x = 0)`)) THEN
   2.648 -  REWRITE_TAC[TAUT `a ==> b ==> c \<longleftrightarrow> b \<and> a ==> c`] THEN
   2.649 -  DISCH_THEN(MP_TAC o SPEC `--(inv m % c):real^N` o
   2.650 -    MATCH_MP HAS_INTEGRAL_AFFINITY) THEN
   2.651 -  ASM_REWRITE_TAC[IMAGE_AFFINITY_INTERVAL; REAL_INV_INV] THEN
   2.652 -  SIMP_TAC[COND_ID] THEN COND_CASES_TAC THENL [ASM SET_TAC[]; ALL_TAC] THEN
   2.653 -  REWRITE_TAC[VECTOR_ADD_LDISTRIB; VECTOR_MUL_ASSOC;
   2.654 -               VECTOR_MUL_LNEG; VECTOR_MUL_RNEG] THEN
   2.655 -  ASM_SIMP_TAC[REAL_MUL_RINV; VECTOR_MUL_LID; VECTOR_NEG_NEG] THEN
   2.656 -  REWRITE_TAC[VECTOR_ARITH `(u + --c) + c:real^N = u`] THEN
   2.657 -  REWRITE_TAC[REAL_ABS_INV; REAL_INV_INV; GSYM REAL_POW_INV] THEN
   2.658 -  DISCH_THEN(fun th -> REWRITE_TAC[th]) THEN
   2.659 -  REWRITE_TAC[LIFT_CMUL; GSYM VECTOR_SUB_LDISTRIB] THEN
   2.660 -  REWRITE_TAC[NORM_MUL; REAL_ABS_POW; REAL_ABS_ABS] THEN
   2.661 -  ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN
   2.662 -  ASM_SIMP_TAC[GSYM REAL_LT_RDIV_EQ; REAL_POW_LT; GSYM REAL_ABS_NZ]);; *)
   2.663 -
   2.664 -lemma stretch_galois: True .. (*
   2.665 - "!x:real^N y:real^N m.
   2.666 -        (!k. 1 <= k \<and> k <= dimindex(:N) ==>  ~(m k = 0))
   2.667 -        ==> ((y = (lambda k. m k * x$k)) \<longleftrightarrow> (lambda k. inv(m k) * y$k) = x)"
   2.668 -qed   REPEAT GEN_TAC THEN SIMP_TAC[CART_EQ; LAMBDA_BETA] THEN
   2.669 -  MATCH_MP_TAC(MESON[]
   2.670 -   `(!x. p x ==> (q x \<longleftrightarrow> r x))
   2.671 -    ==> (!x. p x) ==> ((!x. q x) \<longleftrightarrow> (!x. r x))`) THEN
   2.672 -  GEN_TAC THEN ASM_CASES_TAC `1 <= k \<and> k <= dimindex(:N)` THEN
   2.673 -  ASM_REWRITE_TAC[] THEN CONV_TAC REAL_FIELD);; *)
   2.674 -
   2.675 -lemma has_gmeasure_stretch: True .. (*
   2.676 - "!s m y. s has_gmeasure y
   2.677 -           ==> (IMAGE (\<lambda>x:real^N. lambda k. m k * x$k) s :real^N->bool)
   2.678 -               has_gmeasure abs(product (1..dimindex(:N)) m) * y"
   2.679 -qed   REPEAT STRIP_TAC THEN ASM_CASES_TAC
   2.680 -   `!k. 1 <= k \<and> k <= dimindex(:N) ==> ~(m k = 0)`
   2.681 -  THENL
   2.682 -   [ALL_TAC;
   2.683 -    FIRST_X_ASSUM(MP_TAC o GEN_REWRITE_RULE I [NOT_FORALL_THM]) THEN
   2.684 -    REWRITE_TAC[NOT_IMP; GSYM CONJ_ASSOC; LEFT_IMP_EXISTS_THM] THEN
   2.685 -    X_GEN_TAC `k:num` THEN STRIP_TAC THEN
   2.686 -    SUBGOAL_THEN `product(1..dimindex (:N)) m = 0` SUBST1_TAC THENL
   2.687 -     [ASM_MESON_TAC[PRODUCT_EQ_0_NUMSEG]; ALL_TAC] THEN
   2.688 -    REWRITE_TAC[REAL_ABS_NUM; REAL_MUL_LZERO; HAS_GMEASURE_0] THEN
   2.689 -    MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
   2.690 -    EXISTS_TAC `{x:real^N | x$k = 0}` THEN
   2.691 -    ASM_SIMP_TAC[NEGLIGIBLE_STANDARD_HYPERPLANE; SUBSET; FORALL_IN_IMAGE] THEN
   2.692 -    ASM_SIMP_TAC[IN_ELIM_THM; LAMBDA_BETA; REAL_MUL_LZERO]] THEN
   2.693 -  UNDISCH_TAC `(s:real^N->bool) has_gmeasure y` THEN
   2.694 -  REWRITE_TAC[HAS_GMEASURE] THEN
   2.695 -  ONCE_REWRITE_TAC[HAS_INTEGRAL] THEN REWRITE_TAC[IN_UNIV] THEN
   2.696 -  DISCH_TAC THEN X_GEN_TAC `e:real` THEN DISCH_TAC THEN
   2.697 -  SUBGOAL_THEN `0 < abs(product(1..dimindex(:N)) m)` ASSUME_TAC THENL
   2.698 -   [ASM_MESON_TAC[REAL_ABS_NZ; REAL_LT_DIV; PRODUCT_EQ_0_NUMSEG];
   2.699 -    ALL_TAC] THEN
   2.700 -  FIRST_X_ASSUM(MP_TAC o SPEC `e:real / abs(product(1..dimindex(:N)) m)`) THEN
   2.701 -  ASM_SIMP_TAC[REAL_LT_DIV] THEN
   2.702 -  DISCH_THEN(X_CHOOSE_THEN `B:real` STRIP_ASSUME_TAC) THEN
   2.703 -  EXISTS_TAC `sup(IMAGE (\<lambda>k. abs(m k) * B) (1..dimindex(:N)))` THEN
   2.704 -  MATCH_MP_TAC(TAUT `a \<and> (a ==> b) ==> a \<and> b`) THEN CONJ_TAC THENL
   2.705 -   [ASM_SIMP_TAC[REAL_LT_SUP_FINITE; FINITE_IMAGE; NUMSEG_EMPTY; FINITE_NUMSEG;
   2.706 -                 IN_NUMSEG; GSYM NOT_LE; DIMINDEX_GE_1; IMAGE_EQ_EMPTY;
   2.707 -                 EXISTS_IN_IMAGE] THEN
   2.708 -    ASM_MESON_TAC[IN_NUMSEG; DIMINDEX_GE_1; LE_REFL; REAL_LT_MUL; REAL_ABS_NZ];
   2.709 -    DISCH_TAC] THEN
   2.710 -  MAP_EVERY X_GEN_TAC [`u:real^N`; `v:real^N`] THEN DISCH_TAC THEN
   2.711 -  ASM_SIMP_TAC[IN_IMAGE; STRETCH_GALOIS; UNWIND_THM1] THEN
   2.712 -  FIRST_X_ASSUM(MP_TAC o SPECL
   2.713 -    [`(lambda k. min (inv(m k) * (u:real^N)$k)
   2.714 -                     (inv(m k) * (v:real^N)$k)):real^N`;
   2.715 -     `(lambda k. max (inv(m k) * (u:real^N)$k)
   2.716 -                 (inv(m k) * (v:real^N)$k)):real^N`]) THEN
   2.717 -  MATCH_MP_TAC(TAUT `a \<and> (b ==> a ==> c) ==> (a ==> b) ==> c`) THEN
   2.718 -  CONJ_TAC THENL
   2.719 -   [ALL_TAC;
   2.720 -    REWRITE_TAC[LEFT_IMP_EXISTS_THM] THEN X_GEN_TAC `z:real^1` THEN
   2.721 -    DISCH_THEN(CONJUNCTS_THEN2 MP_TAC ASSUME_TAC) THEN
   2.722 -    SUBGOAL_THEN `!k. 1 <= k \<and> k <= dimindex (:N) ==> ~(inv(m k) = 0)`
   2.723 -    MP_TAC THENL [ASM_SIMP_TAC[REAL_INV_EQ_0]; ALL_TAC] THEN
   2.724 -    ONCE_REWRITE_TAC[GSYM IMP_CONJ_ALT] THEN
   2.725 -    DISCH_THEN(MP_TAC o MATCH_MP HAS_INTEGRAL_STRETCH)] THEN
   2.726 -  (MP_TAC(ISPECL [`u:real^N`; `v:real^N`; `\i:num. inv(m i)`]
   2.727 -    IMAGE_STRETCH_INTERVAL) THEN
   2.728 -   SUBGOAL_THEN `~(interval[u:real^N,v] = {})` ASSUME_TAC THENL
   2.729 -    [FIRST_ASSUM(MATCH_MP_TAC o MATCH_MP (SET_RULE
   2.730 -      `s \<subseteq> t ==> ~(s = {}) ==> ~(t = {})`)) THEN
   2.731 -     ASM_REWRITE_TAC[BALL_EQ_EMPTY; GSYM REAL_NOT_LT];
   2.732 -     ALL_TAC] THEN
   2.733 -   ASM_REWRITE_TAC[] THEN DISCH_THEN(SUBST1_TAC o SYM))
   2.734 -  THENL
   2.735 -   [FIRST_X_ASSUM(MATCH_MP_TAC o MATCH_MP (SET_RULE
   2.736 -     `b \<subseteq> s ==> b' \<subseteq> IMAGE f b ==> b' \<subseteq> IMAGE f s`)) THEN
   2.737 -    REWRITE_TAC[IN_BALL; SUBSET; NORM_ARITH `dist(0,x) = norm x`;
   2.738 -                IN_IMAGE] THEN
   2.739 -    ASM_SIMP_TAC[STRETCH_GALOIS; REAL_INV_EQ_0; UNWIND_THM1; REAL_INV_INV] THEN
   2.740 -    X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN
   2.741 -    MATCH_MP_TAC REAL_LET_TRANS THEN
   2.742 -    EXISTS_TAC
   2.743 -     `norm(sup(IMAGE(\<lambda>k. abs(m k)) (1..dimindex(:N))) % x:real^N)` THEN
   2.744 -    CONJ_TAC THENL
   2.745 -     [MATCH_MP_TAC NORM_LE_COMPONENTWISE THEN
   2.746 -      SIMP_TAC[LAMBDA_BETA; VECTOR_MUL_COMPONENT; REAL_ABS_MUL] THEN
   2.747 -      REPEAT STRIP_TAC THEN MATCH_MP_TAC REAL_LE_RMUL THEN
   2.748 -      REWRITE_TAC[REAL_ABS_POS] THEN
   2.749 -      MATCH_MP_TAC(REAL_ARITH `x <= y ==> x <= abs y`) THEN
   2.750 -      ASM_SIMP_TAC[REAL_LE_SUP_FINITE; FINITE_IMAGE; IMAGE_EQ_EMPTY;
   2.751 -                  NUMSEG_EMPTY; FINITE_NUMSEG; GSYM NOT_LE; DIMINDEX_GE_1] THEN
   2.752 -      REWRITE_TAC[EXISTS_IN_IMAGE; IN_NUMSEG] THEN ASM_MESON_TAC[REAL_LE_REFL];
   2.753 -      ALL_TAC] THEN
   2.754 -    REWRITE_TAC[NORM_MUL] THEN MATCH_MP_TAC REAL_LTE_TRANS THEN
   2.755 -    EXISTS_TAC `abs(sup(IMAGE(\<lambda>k. abs(m k)) (1..dimindex(:N)))) * B` THEN
   2.756 -    SUBGOAL_THEN `0 < sup(IMAGE(\<lambda>k. abs(m k)) (1..dimindex(:N)))`
   2.757 -    ASSUME_TAC THENL
   2.758 -     [ASM_SIMP_TAC[REAL_LT_SUP_FINITE; FINITE_IMAGE; IMAGE_EQ_EMPTY;
   2.759 -                  NUMSEG_EMPTY; FINITE_NUMSEG; GSYM NOT_LE; DIMINDEX_GE_1] THEN
   2.760 -      REWRITE_TAC[EXISTS_IN_IMAGE; GSYM REAL_ABS_NZ; IN_NUMSEG] THEN
   2.761 -      ASM_MESON_TAC[DIMINDEX_GE_1; LE_REFL];
   2.762 -      ALL_TAC] THEN
   2.763 -    ASM_SIMP_TAC[REAL_LT_LMUL_EQ; REAL_ARITH `0 < x ==> 0 < abs x`] THEN
   2.764 -    MATCH_MP_TAC REAL_LE_TRANS THEN
   2.765 -    EXISTS_TAC `sup(IMAGE(\<lambda>k. abs(m k)) (1..dimindex(:N))) * B` THEN
   2.766 -    ASM_SIMP_TAC[REAL_LE_RMUL_EQ; REAL_ARITH `0 < x ==> abs x <= x`] THEN
   2.767 -    ASM_SIMP_TAC[REAL_LE_SUP_FINITE; FINITE_IMAGE; IMAGE_EQ_EMPTY;
   2.768 -                  NUMSEG_EMPTY; FINITE_NUMSEG; GSYM NOT_LE; DIMINDEX_GE_1] THEN
   2.769 -    ASM_SIMP_TAC[EXISTS_IN_IMAGE; REAL_LE_RMUL_EQ] THEN
   2.770 -    ASM_SIMP_TAC[REAL_SUP_LE_FINITE; FINITE_IMAGE; IMAGE_EQ_EMPTY;
   2.771 -                 NUMSEG_EMPTY; FINITE_NUMSEG; GSYM NOT_LE; DIMINDEX_GE_1] THEN
   2.772 -    MP_TAC(ISPEC `IMAGE (\<lambda>k. abs (m k)) (1..dimindex(:N))` SUP_FINITE) THEN
   2.773 -    REWRITE_TAC[FORALL_IN_IMAGE] THEN
   2.774 -    ASM_SIMP_TAC[FINITE_IMAGE; FINITE_NUMSEG; IMAGE_EQ_EMPTY; NUMSEG_EMPTY;
   2.775 -                 GSYM NOT_LE; DIMINDEX_GE_1] THEN
   2.776 -    REWRITE_TAC[IN_IMAGE] THEN MESON_TAC[];
   2.777 -
   2.778 -    MATCH_MP_TAC(MESON[]
   2.779 -     `s = t \<and> P z ==> (f has_integral z) s ==> Q
   2.780 -                       ==> ?w. (f has_integral w) t \<and> P w`) THEN
   2.781 -    SIMP_TAC[GSYM PRODUCT_INV; FINITE_NUMSEG; GSYM REAL_ABS_INV] THEN
   2.782 -    REWRITE_TAC[REAL_INV_INV] THEN CONJ_TAC THENL
   2.783 -     [REWRITE_TAC[GSYM IMAGE_o] THEN MATCH_MP_TAC(SET_RULE
   2.784 -       `(!x. f x = x) ==> IMAGE f s = s`) THEN
   2.785 -      SIMP_TAC[o_THM; LAMBDA_BETA; CART_EQ] THEN
   2.786 -      ASM_SIMP_TAC[REAL_MUL_ASSOC; REAL_MUL_RINV; REAL_MUL_LID];
   2.787 -      REWRITE_TAC[ABS_; _SUB; LIFT_; _CMUL] THEN
   2.788 -      REWRITE_TAC[GSYM REAL_SUB_LDISTRIB; ETA_AX] THEN
   2.789 -      REWRITE_TAC[REAL_ABS_MUL; REAL_ABS_ABS] THEN
   2.790 -      ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN
   2.791 -      ASM_SIMP_TAC[GSYM REAL_LT_RDIV_EQ] THEN
   2.792 -      ASM_MESON_TAC[ABS_; _SUB; LIFT_]]]);; *)
   2.793 -
   2.794 -lemma has_gmeasure_translation: True .. (*
   2.795 - "!s m a. s has_gmeasure m ==> (IMAGE (\<lambda>x:real^N. a + x) s) has_gmeasure m"
   2.796 -qed   REPEAT GEN_TAC THEN
   2.797 -  MP_TAC(ISPECL [`s:real^N->bool`; `1`; `a:real^N`; `m:real`]
   2.798 -                HAS_GMEASURE_AFFINITY) THEN
   2.799 -  REWRITE_TAC[VECTOR_MUL_LID; REAL_ABS_NUM; REAL_POW_ONE; REAL_MUL_LID] THEN
   2.800 -  REWRITE_TAC[VECTOR_ADD_SYM]);; *)
   2.801 -
   2.802 -lemma negligible_translation: True .. (*
   2.803 - "!s a. negligible s ==> negligible (IMAGE (\<lambda>x:real^N. a + x) s)"
   2.804 -qed   SIMP_TAC[GSYM HAS_GMEASURE_0; HAS_GMEASURE_TRANSLATION]);; *)
   2.805 -
   2.806 -lemma has_gmeasure_translation_eq: True .. (*
   2.807 - "!s m. (IMAGE (\<lambda>x:real^N. a + x) s) has_gmeasure m \<longleftrightarrow> s has_gmeasure m"
   2.808 -qed   REPEAT GEN_TAC THEN EQ_TAC THEN REWRITE_TAC[HAS_GMEASURE_TRANSLATION] THEN
   2.809 -  DISCH_THEN(MP_TAC o SPEC `--a:real^N` o
   2.810 -    MATCH_MP HAS_GMEASURE_TRANSLATION) THEN
   2.811 -  MATCH_MP_TAC EQ_IMP THEN AP_THM_TAC THEN AP_TERM_TAC THEN
   2.812 -  REWRITE_TAC[GSYM IMAGE_o; o_DEF; VECTOR_ARITH `--a + a + b:real^N = b`] THEN
   2.813 -  SET_TAC[]);; *)
   2.814 -
   2.815 -lemma negligible_translation_rev: True .. (*
   2.816 - "!s a. negligible (IMAGE (\<lambda>x:real^N. a + x) s) ==> negligible s"
   2.817 -qed   SIMP_TAC[GSYM HAS_GMEASURE_0; HAS_GMEASURE_TRANSLATION_EQ]);; *)
   2.818 -
   2.819 -lemma negligible_translation_eq: True .. (*
   2.820 - "!s a. negligible (IMAGE (\<lambda>x:real^N. a + x) s) \<longleftrightarrow> negligible s"
   2.821 -qed   SIMP_TAC[GSYM HAS_GMEASURE_0; HAS_GMEASURE_TRANSLATION_EQ]);; *)
   2.822 -
   2.823 -lemma gmeasurable_translation: True .. (*
   2.824 - "!s. gmeasurable (IMAGE (\<lambda>x. a + x) s) \<longleftrightarrow> gmeasurable s"
   2.825 -qed   REWRITE_TAC[measurable; HAS_GMEASURE_TRANSLATION_EQ]);; *)
   2.826 -
   2.827 -lemma measure_translation: True .. (*
   2.828 - "!s. gmeasurable s ==> measure(IMAGE (\<lambda>x. a + x) s) = gmeasure s"
   2.829 -qed   REWRITE_TAC[HAS_GMEASURE_MEASURE] THEN REPEAT STRIP_TAC THEN
   2.830 -  MATCH_MP_TAC MEASURE_UNIQUE THEN
   2.831 -  ASM_REWRITE_TAC[HAS_GMEASURE_TRANSLATION_EQ]);; *)
   2.832 -
   2.833 -lemma has_gmeasure_scaling: True .. (*
   2.834 - "!s m c. s has_gmeasure m
   2.835 -           ==> (IMAGE (\<lambda>x:real^N. c % x) s) has_gmeasure
   2.836 -               (abs(c) pow dimindex(:N)) * m"
   2.837 -qed   REPEAT GEN_TAC THEN
   2.838 -  MP_TAC(ISPECL [`s:real^N->bool`; `c:real`; `0:real^N`; `m:real`]
   2.839 -                HAS_GMEASURE_AFFINITY) THEN
   2.840 -  REWRITE_TAC[VECTOR_ADD_RID]);; *)
   2.841 -
   2.842 -lemma has_gmeasure_scaling_eq: True .. (*
   2.843 - "!s m c. ~(c = 0)
   2.844 -           ==> (IMAGE (\<lambda>x:real^N. c % x) s
   2.845 -                  has_gmeasure (abs(c) pow dimindex(:N)) * m \<longleftrightarrow>
   2.846 -                s has_gmeasure m)"
   2.847 -qed   REPEAT STRIP_TAC THEN EQ_TAC THEN REWRITE_TAC[HAS_GMEASURE_SCALING] THEN
   2.848 -  DISCH_THEN(MP_TAC o SPEC `inv(c)` o MATCH_MP HAS_GMEASURE_SCALING) THEN
   2.849 -  REWRITE_TAC[GSYM IMAGE_o; o_DEF; GSYM REAL_ABS_MUL] THEN
   2.850 -  REWRITE_TAC[GSYM REAL_POW_MUL; VECTOR_MUL_ASSOC; REAL_MUL_ASSOC] THEN
   2.851 -  ASM_SIMP_TAC[GSYM REAL_ABS_MUL; REAL_MUL_LINV] THEN
   2.852 -  REWRITE_TAC[REAL_POW_ONE; REAL_ABS_NUM; REAL_MUL_LID; VECTOR_MUL_LID] THEN
   2.853 -  MATCH_MP_TAC EQ_IMP THEN AP_THM_TAC THEN AP_TERM_TAC THEN SET_TAC[]);; *)
   2.854 -
   2.855 -lemma gmeasurable_scaling: True .. (*
   2.856 - "!s c. gmeasurable s ==> gmeasurable (IMAGE (\<lambda>x. c % x) s)"
   2.857 -qed   REWRITE_TAC[measurable] THEN MESON_TAC[HAS_GMEASURE_SCALING]);; *)
   2.858 -
   2.859 -lemma gmeasurable_scaling_eq: True .. (*
   2.860 - "!s c. ~(c = 0) ==> (measurable (IMAGE (\<lambda>x. c % x) s) \<longleftrightarrow> gmeasurable s)"
   2.861 -qed   REPEAT STRIP_TAC THEN EQ_TAC THEN REWRITE_TAC[MEASURABLE_SCALING] THEN
   2.862 -  DISCH_THEN(MP_TAC o SPEC `inv c` o MATCH_MP GMEASURABLE_SCALING) THEN
   2.863 -  REWRITE_TAC[GSYM IMAGE_o; o_DEF; GSYM REAL_ABS_MUL] THEN
   2.864 -  MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN
   2.865 -  ASM_SIMP_TAC[VECTOR_MUL_ASSOC; REAL_MUL_LINV; VECTOR_MUL_LID] THEN
   2.866 -  SET_TAC[]);; *)
   2.867 -
   2.868 -lemma measure_scaling: True .. (*
   2.869 - "!s. gmeasurable s
   2.870 -       ==> measure(IMAGE (\<lambda>x:real^N. c % x) s) =
   2.871 -              (abs(c) pow dimindex(:N)) * gmeasure s"
   2.872 -qed   REWRITE_TAC[HAS_GMEASURE_MEASURE] THEN REPEAT STRIP_TAC THEN
   2.873 -  MATCH_MP_TAC MEASURE_UNIQUE THEN ASM_SIMP_TAC[HAS_GMEASURE_SCALING]);; *)
   2.874 -
   2.875 -(* ------------------------------------------------------------------------- *)
   2.876 -(* Measurability of countable unions and intersections of various kinds.     *)
   2.877 -(* ------------------------------------------------------------------------- *)
   2.878 -
   2.879 -lemma has_gmeasure_nested_unions:
   2.880 -  assumes "\<And>n. gmeasurable(s n)" "\<And>n. gmeasure(s n) \<le> B" "\<And>n. s(n) \<subseteq> s(Suc n)"
   2.881 -  shows "gmeasurable(\<Union> { s n | n. n \<in> UNIV }) \<and>
   2.882 -  (\<lambda>n. gmeasure(s n)) ----> gmeasure(\<Union> { s(n) | n. n \<in> UNIV })"
   2.883 -proof- let ?g = "\<lambda>x. if x \<in> \<Union>{s n |n. n \<in> UNIV} then 1 else (0::real)"
   2.884 -  have "?g integrable_on UNIV \<and> (\<lambda>k. integral UNIV (\<lambda>x. if x \<in> s k then 1 else 0)) ----> integral UNIV ?g"
   2.885 -  proof(rule monotone_convergence_increasing)
   2.886 -    case goal1 show ?case using assms(1) unfolding gmeasurable_integrable by auto
   2.887 -    case goal2 show ?case using assms(3) by auto
   2.888 -    have "\<forall>m n. m\<le>n \<longrightarrow> s m \<subseteq> s n" apply(subst transitive_stepwise_le_eq)
   2.889 -      using assms(3) by auto note * = this[rule_format]
   2.890 -    have **:"\<And>x e n. \<lbrakk>x \<in> s n; 0 < e\<rbrakk> \<Longrightarrow> \<exists>N. \<forall>n. x \<notin> s n \<longrightarrow> N \<le> n \<longrightarrow> dist 0 1 < e"
   2.891 -      apply(rule_tac x=n in exI) using * by auto 
   2.892 -    case goal3 show ?case unfolding Lim_sequentially by(auto intro!: **) 
   2.893 -    case goal4 show ?case unfolding bounded_def apply(rule_tac x=0 in exI)
   2.894 -      apply(rule_tac x=B in exI) unfolding dist_real_def apply safe
   2.895 -      unfolding measure_integral_univ[OF assms(1),THEN sym]
   2.896 -      apply(subst abs_of_nonpos) using assms(1,2) by auto
   2.897 -  qed note conjunctD2[OF this]
   2.898 -  thus ?thesis unfolding gmeasurable_integrable[THEN sym] measure_integral_univ[OF assms(1)]
   2.899 -    apply- unfolding measure_integral_univ by auto
   2.900 -qed
   2.901 -
   2.902 -lemmas gmeasurable_nested_unions = has_gmeasure_nested_unions(1)
   2.903 -
   2.904 -lemma sums_alt:"f sums s = (\<lambda>n. setsum f {0..n}) ----> s"
   2.905 -proof- have *:"\<And>n. {0..<Suc n} = {0..n}" by auto
   2.906 -  show ?thesis unfolding sums_def apply(subst LIMSEQ_Suc_iff[THEN sym]) unfolding * ..
   2.907 -qed
   2.908 -
   2.909 -lemma has_gmeasure_countable_negligible_unions: 
   2.910 -  assumes "\<And>n. gmeasurable(s n)" "\<And>m n. m \<noteq> n \<Longrightarrow> negligible(s m \<inter> s n)"
   2.911 -  "\<And>n. setsum (\<lambda>k. gmeasure(s k)) {0..n}  <= B"
   2.912 -  shows "gmeasurable(\<Union> { s(n) |n. n \<in> UNIV })" (is ?m)
   2.913 -  "((\<lambda>n. gmeasure(s n)) sums (gmeasure(\<Union> { s(n) |n. n \<in> UNIV })))" (is ?s)
   2.914 -proof- have *:"\<And>n. (\<Union> (s ` {0..n})) has_gmeasure (setsum (\<lambda>k. gmeasure(s k)) {0..n})"
   2.915 -    apply(rule has_gmeasure_negligible_unions_image) using assms by auto
   2.916 -  have **:"(\<Union>{\<Union>s ` {0..n} |n. n \<in> UNIV}) = (\<Union>{s n |n. n \<in> UNIV})" unfolding simple_image by fastsimp
   2.917 -  have "gmeasurable (\<Union>{\<Union>s ` {0..n} |n. n \<in> UNIV}) \<and>
   2.918 -    (\<lambda>n. gmeasure (\<Union>(s ` {0..n}))) ----> gmeasure (\<Union>{\<Union>s ` {0..n} |n. n \<in> UNIV})"
   2.919 -    apply(rule has_gmeasure_nested_unions) apply(rule gmeasurableI,rule *)
   2.920 -    unfolding measure_unique[OF *] defer apply(rule Union_mono,rule image_mono) using assms(3) by auto
   2.921 -  note lem = conjunctD2[OF this,unfolded **]
   2.922 -  show ?m using lem(1) .
   2.923 -  show ?s using lem(2) unfolding sums_alt measure_unique[OF *] .
   2.924 -qed     
   2.925 -
   2.926 -lemma negligible_countable_unions: True .. (*
   2.927 - "!s:num->real^N->bool.
   2.928 -        (!n. negligible(s n)) ==> negligible(UNIONS {s(n) | n \<in> (:num)})"
   2.929 -qed   REPEAT STRIP_TAC THEN
   2.930 -  MP_TAC(ISPECL [`s:num->real^N->bool`; `0`]
   2.931 -    HAS_GMEASURE_COUNTABLE_NEGLIGIBLE_UNIONS) THEN
   2.932 -  ASM_SIMP_TAC[MEASURE_EQ_0; SUM_0; REAL_LE_REFL; LIFT_NUM] THEN ANTS_TAC THENL
   2.933 -   [ASM_MESON_TAC[HAS_GMEASURE_0; gmeasurable; INTER_SUBSET; NEGLIGIBLE_SUBSET];
   2.934 -    ALL_TAC] THEN
   2.935 -  SIMP_TAC[GSYM GMEASURABLE_MEASURE_EQ_0] THEN
   2.936 -  STRIP_TAC THEN REWRITE_TAC[GSYM LIFT_EQ] THEN
   2.937 -  MATCH_MP_TAC SERIES_UNIQUE THEN REWRITE_TAC[LIFT_NUM] THEN
   2.938 -  MAP_EVERY EXISTS_TAC [`(\<lambda>k. 0):num->real^1`; `from 0`] THEN
   2.939 -  ASM_REWRITE_TAC[SERIES_0]);; *)
   2.940 -
   2.941 -lemma gmeasurable_countable_unions_strong:
   2.942 -  assumes "\<And>n. gmeasurable(s n)" "\<And>n::nat. gmeasure(\<Union>{s k |k. k \<le> n}) \<le> B"
   2.943 -  shows "gmeasurable(\<Union>{ s(n) |n. n \<in> UNIV })"
   2.944 -proof- have *:"\<Union>{\<Union>s ` {0..n} |n. n \<in> UNIV} = \<Union>range s" unfolding simple_image by fastsimp
   2.945 -  show ?thesis unfolding simple_image
   2.946 -    apply(rule gmeasurable_nested_unions[of "\<lambda>n. \<Union>(s ` {0..n})", THEN conjunct1,unfolded *])
   2.947 -  proof- fix n::nat show "gmeasurable (\<Union>s ` {0..n})"
   2.948 -      apply(rule gmeasurable_finite_unions) using assms(1) by auto
   2.949 -    show "gmeasure (\<Union>s ` {0..n}) \<le> B"
   2.950 -      using assms(2)[of n] unfolding simple_image[THEN sym] by auto
   2.951 -    show "\<Union>s ` {0..n} \<subseteq> \<Union>s ` {0..Suc n}" apply(rule Union_mono) by auto
   2.952 -  qed
   2.953 -qed
   2.954 -
   2.955 -lemma has_gmeasure_countable_negligible_unions_bounded: True .. (*
   2.956 - "!s:num->real^N->bool.
   2.957 -        (!n. gmeasurable(s n)) \<and>
   2.958 -        (!m n. ~(m = n) ==> negligible(s m \<inter> s n)) \<and>
   2.959 -        bounded(\<Union>{ s(n) | n \<in> (:num) })
   2.960 -        ==> gmeasurable(\<Union>{ s(n) | n \<in> (:num) }) \<and>
   2.961 -            ((\<lambda>n. lift(measure(s n))) sums
   2.962 -             lift(measure(\<Union>{ s(n) | n \<in> (:num) }))) (from 0)"
   2.963 -qed   REPEAT GEN_TAC THEN STRIP_TAC THEN
   2.964 -  FIRST_ASSUM(MP_TAC o MATCH_MP BOUNDED_SUBSET_CLOSED_INTERVAL) THEN
   2.965 -  REWRITE_TAC[LEFT_IMP_EXISTS_THM] THEN
   2.966 -  MAP_EVERY X_GEN_TAC [`a:real^N`; `b:real^N`] THEN DISCH_TAC THEN
   2.967 -  MATCH_MP_TAC HAS_GMEASURE_COUNTABLE_NEGLIGIBLE_UNIONS THEN
   2.968 -  EXISTS_TAC `measure(interval[a:real^N,b])` THEN
   2.969 -  ASM_REWRITE_TAC[] THEN X_GEN_TAC `n:num` THEN MATCH_MP_TAC REAL_LE_TRANS THEN
   2.970 -  EXISTS_TAC `measure(UNIONS (IMAGE (s:num->real^N->bool) (0..n)))` THEN
   2.971 -  CONJ_TAC THENL
   2.972 -   [MATCH_MP_TAC REAL_EQ_IMP_LE THEN CONV_TAC SYM_CONV THEN
   2.973 -    MATCH_MP_TAC MEASURE_NEGLIGIBLE_UNIONS_IMAGE THEN
   2.974 -    ASM_SIMP_TAC[FINITE_NUMSEG];
   2.975 -    MATCH_MP_TAC MEASURE_SUBSET THEN REWRITE_TAC[MEASURABLE_INTERVAL] THEN
   2.976 -    CONJ_TAC THENL
   2.977 -     [MATCH_MP_TAC GMEASURABLE_UNIONS THEN
   2.978 -      ASM_SIMP_TAC[FINITE_IMAGE; FINITE_NUMSEG; FORALL_IN_IMAGE];
   2.979 -      ASM SET_TAC[]]]);; *)
   2.980 -
   2.981 -lemma gmeasurable_countable_negligible_unions_bounded: True .. (*
   2.982 - "!s:num->real^N->bool.
   2.983 -        (!n. gmeasurable(s n)) \<and>
   2.984 -        (!m n. ~(m = n) ==> negligible(s m \<inter> s n)) \<and>
   2.985 -        bounded(\<Union>{ s(n) | n \<in> (:num) })
   2.986 -        ==> gmeasurable(\<Union>{ s(n) | n \<in> (:num) })"
   2.987 -qed   SIMP_TAC[HAS_GMEASURE_COUNTABLE_NEGLIGIBLE_UNIONS_BOUNDED]);; *)
   2.988 -
   2.989 -lemma gmeasurable_countable_unions: True .. (*
   2.990 - "!s:num->real^N->bool B.
   2.991 -        (!n. gmeasurable(s n)) \<and>
   2.992 -        (!n. sum (0..n) (\<lambda>k. measure(s k)) \<le> B)
   2.993 -        ==> gmeasurable(\<Union>{ s(n) | n \<in> (:num) })"
   2.994 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC GMEASURABLE_COUNTABLE_UNIONS_STRONG THEN
   2.995 -  EXISTS_TAC `B:real` THEN ASM_REWRITE_TAC[] THEN
   2.996 -  X_GEN_TAC `n:num` THEN MATCH_MP_TAC REAL_LE_TRANS THEN
   2.997 -  EXISTS_TAC `sum(0..n) (\<lambda>k. measure(s k:real^N->bool))` THEN
   2.998 -  ASM_REWRITE_TAC[] THEN
   2.999 -  W(MP_TAC o PART_MATCH (rand o rand) MEASURE_UNIONS_LE_IMAGE o
  2.1000 -       rand o snd) THEN
  2.1001 -  ASM_REWRITE_TAC[FINITE_NUMSEG] THEN
  2.1002 -  ONCE_REWRITE_TAC[GSYM SIMPLE_IMAGE] THEN
  2.1003 -  REWRITE_TAC[IN_NUMSEG; LE_0]);; *)
  2.1004 -
  2.1005 -lemma gmeasurable_countable_inters: True .. (*
  2.1006 - "!s:num->real^N->bool.
  2.1007 -        (!n. gmeasurable(s n))
  2.1008 -        ==> gmeasurable(INTERS { s(n) | n \<in> (:num) })"
  2.1009 -qed   REPEAT STRIP_TAC THEN
  2.1010 -  SUBGOAL_THEN `INTERS { s(n):real^N->bool | n \<in> (:num) } =
  2.1011 -                s 0 DIFF (\<Union>{s 0 DIFF s n | n \<in> (:num)})`
  2.1012 -  SUBST1_TAC THENL
  2.1013 -   [GEN_REWRITE_TAC I [EXTENSION] THEN
  2.1014 -    REWRITE_TAC[IN_INTERS; IN_DIFF; IN_UNIONS] THEN
  2.1015 -    REWRITE_TAC[SIMPLE_IMAGE; FORALL_IN_IMAGE; EXISTS_IN_IMAGE] THEN
  2.1016 -    ASM SET_TAC[];
  2.1017 -    ALL_TAC] THEN
  2.1018 -  MATCH_MP_TAC GMEASURABLE_DIFF THEN ASM_REWRITE_TAC[] THEN
  2.1019 -  MATCH_MP_TAC GMEASURABLE_COUNTABLE_UNIONS_STRONG THEN
  2.1020 -  EXISTS_TAC `measure(s 0:real^N->bool)` THEN
  2.1021 -  ASM_SIMP_TAC[MEASURABLE_DIFF; LE_0] THEN
  2.1022 -  GEN_TAC THEN MATCH_MP_TAC MEASURE_SUBSET THEN
  2.1023 -  ASM_REWRITE_TAC[] THEN CONJ_TAC THENL
  2.1024 -   [ALL_TAC;
  2.1025 -    REWRITE_TAC[SUBSET; FORALL_IN_UNIONS; IN_ELIM_THM; IN_DIFF] THEN
  2.1026 -    MESON_TAC[IN_DIFF]] THEN
  2.1027 -  ONCE_REWRITE_TAC[GSYM IN_NUMSEG_0] THEN
  2.1028 -  ONCE_REWRITE_TAC[SIMPLE_IMAGE] THEN
  2.1029 -  ASM_SIMP_TAC[FORALL_IN_IMAGE; FINITE_IMAGE; FINITE_NUMSEG;
  2.1030 -               GMEASURABLE_DIFF; GMEASURABLE_UNIONS]);; *)
  2.1031 -
  2.1032 -(* ------------------------------------------------------------------------- *)
  2.1033 -(* measurability of compact and bounded open sets.                           *)
  2.1034 -(* ------------------------------------------------------------------------- *)
  2.1035 -
  2.1036 -lemma gmeasurable_compact: True .. (*
  2.1037 - "!s:real^N->bool. compact s ==> gmeasurable s"
  2.1038 -qed   lemma lemma = prove
  2.1039 -   (`!f s:real^N->bool.
  2.1040 -          (!n. FINITE(f n)) \<and>
  2.1041 -          (!n. s \<subseteq> UNIONS(f n)) \<and>
  2.1042 -          (!x. ~(x \<in> s) ==> ?n. ~(x \<in> UNIONS(f n))) \<and>
  2.1043 -          (!n a. a \<in> f(SUC n) ==> ?b. b \<in> f(n) \<and> a \<subseteq> b) \<and>
  2.1044 -          (!n a. a \<in> f(n) ==> gmeasurable a)
  2.1045 -          ==> gmeasurable s"
  2.1046 -qed     REPEAT STRIP_TAC THEN
  2.1047 -    SUBGOAL_THEN `!n. UNIONS(f(SUC n):(real^N->bool)->bool) \<subseteq> UNIONS(f n)`
  2.1048 -    ASSUME_TAC THENL [ASM SET_TAC[]; ALL_TAC] THEN
  2.1049 -    SUBGOAL_THEN `s = INTERS { UNIONS(f n) | n \<in> (:num) }:real^N->bool`
  2.1050 -    SUBST1_TAC THENL
  2.1051 -     [ONCE_REWRITE_TAC[SIMPLE_IMAGE] THEN
  2.1052 -      MATCH_MP_TAC SUBSET_ANTISYM THEN CONJ_TAC THEN
  2.1053 -      REWRITE_TAC[SUBSET; IN_INTERS; FORALL_IN_IMAGE; IN_UNIV] THEN
  2.1054 -      REWRITE_TAC[IN_IMAGE] THEN ASM SET_TAC[];
  2.1055 -      MATCH_MP_TAC GMEASURABLE_COUNTABLE_INTERS THEN
  2.1056 -      ASM_REWRITE_TAC[] THEN GEN_TAC THEN
  2.1057 -      MATCH_MP_TAC GMEASURABLE_UNIONS THEN
  2.1058 -      ASM_MESON_TAC[]]) in
  2.1059 -  REPEAT STRIP_TAC THEN MATCH_MP_TAC lemma THEN
  2.1060 -  EXISTS_TAC
  2.1061 -   `\n. { k | ?u:real^N. (!i. 1 \<le> i \<and> i \<le> dimindex(:N)
  2.1062 -                              ==> integer(u$i)) \<and>
  2.1063 -                  k = { x:real^N | !i. 1 \<le> i \<and> i \<le> dimindex(:N)
  2.1064 -                                       ==> u$i / 2 pow n \<le> x$i \<and>
  2.1065 -                                           x$i < (u$i + 1) / 2 pow n } \<and>
  2.1066 -                  ~(s \<inter> k = {})}` THEN
  2.1067 -  REWRITE_TAC[IN_ELIM_THM] THEN REPEAT CONJ_TAC THENL
  2.1068 -   [X_GEN_TAC `n:num` THEN
  2.1069 -    SIMP_TAC[REAL_LE_LDIV_EQ; REAL_LT_RDIV_EQ; REAL_LT_POW2] THEN
  2.1070 -    SUBGOAL_THEN
  2.1071 -     `?N. !x:real^N i. x \<in> s \<and> 1 \<le> i \<and> i \<le> dimindex(:N)
  2.1072 -                       ==> abs(x$i * 2 pow n) < N`
  2.1073 -    STRIP_ASSUME_TAC THENL
  2.1074 -     [FIRST_ASSUM(MP_TAC o MATCH_MP COMPACT_IMP_BOUNDED) THEN
  2.1075 -      REWRITE_TAC[BOUNDED_POS; LEFT_IMP_EXISTS_THM] THEN
  2.1076 -      X_GEN_TAC `B:real` THEN STRIP_TAC THEN
  2.1077 -      MP_TAC(SPEC `B * 2 pow n` (MATCH_MP REAL_ARCH REAL_LT_01)) THEN
  2.1078 -      MATCH_MP_TAC MONO_EXISTS THEN REWRITE_TAC[REAL_MUL_RID] THEN
  2.1079 -      X_GEN_TAC `N:num` THEN
  2.1080 -      REWRITE_TAC[REAL_ABS_MUL; REAL_ABS_POW; REAL_ABS_NUM] THEN
  2.1081 -      SIMP_TAC[GSYM REAL_LT_RDIV_EQ; REAL_LT_POW2] THEN
  2.1082 -      ASM_MESON_TAC[COMPONENT_LE_NORM; REAL_LE_TRANS; REAL_LET_TRANS];
  2.1083 -      ALL_TAC] THEN
  2.1084 -    MATCH_MP_TAC FINITE_SUBSET THEN
  2.1085 -    EXISTS_TAC
  2.1086 -     `IMAGE (\<lambda>u. {x | !i. 1 \<le> i \<and> i \<le> dimindex(:N)
  2.1087 -                          ==> (u:real^N)$i \<le> (x:real^N)$i * 2 pow n \<and>
  2.1088 -                              x$i * 2 pow n < u$i + 1})
  2.1089 -            {u | !i. 1 \<le> i \<and> i \<le> dimindex(:N) ==> integer (u$i) \<and>
  2.1090 -                                                     abs(u$i) \<le> N}` THEN
  2.1091 -    CONJ_TAC THENL
  2.1092 -     [MATCH_MP_TAC FINITE_IMAGE THEN MATCH_MP_TAC FINITE_CART THEN
  2.1093 -      REWRITE_TAC[GSYM REAL_BOUNDS_LE; FINITE_INTSEG];
  2.1094 -      REWRITE_TAC[SUBSET; IN_ELIM_THM; IN_IMAGE] THEN
  2.1095 -      X_GEN_TAC `l:real^N->bool` THEN
  2.1096 -      MATCH_MP_TAC MONO_EXISTS THEN X_GEN_TAC `u:real^N` THEN
  2.1097 -      STRIP_TAC THEN FIRST_X_ASSUM SUBST_ALL_TAC THEN ASM_SIMP_TAC[] THEN
  2.1098 -      X_GEN_TAC `k:num` THEN STRIP_TAC THEN
  2.1099 -      MATCH_MP_TAC REAL_LE_REVERSE_INTEGERS THEN
  2.1100 -      ASM_SIMP_TAC[INTEGER_CLOSED] THEN
  2.1101 -      FIRST_X_ASSUM(MP_TAC o GEN_REWRITE_RULE I [GSYM MEMBER_NOT_EMPTY]) THEN
  2.1102 -      DISCH_THEN(X_CHOOSE_THEN `x:real^N` MP_TAC) THEN
  2.1103 -      REWRITE_TAC[IN_INTER; IN_ELIM_THM] THEN
  2.1104 -      DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC (MP_TAC o SPEC `k:num`)) THEN
  2.1105 -      ASM_REWRITE_TAC[] THEN
  2.1106 -      FIRST_X_ASSUM(MP_TAC o SPECL [`x:real^N`; `k:num`]) THEN
  2.1107 -      ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC];
  2.1108 -    X_GEN_TAC `n:num` THEN REWRITE_TAC[SUBSET; IN_UNIONS; IN_ELIM_THM] THEN
  2.1109 -    X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN
  2.1110 -    REWRITE_TAC[LEFT_AND_EXISTS_THM] THEN
  2.1111 -    ONCE_REWRITE_TAC[SWAP_EXISTS_THM] THEN
  2.1112 -    EXISTS_TAC `(lambda i. floor(2 pow n * (x:real^N)$i)):real^N` THEN
  2.1113 -    ONCE_REWRITE_TAC[TAUT `(a \<and> b \<and> c) \<and> d \<longleftrightarrow> b \<and> a \<and> c \<and> d`] THEN
  2.1114 -    REWRITE_TAC[UNWIND_THM2] THEN SIMP_TAC[LAMBDA_BETA; FLOOR] THEN
  2.1115 -    REWRITE_TAC[GSYM MEMBER_NOT_EMPTY; IN_INTER] THEN
  2.1116 -    REWRITE_TAC[LEFT_AND_EXISTS_THM] THEN EXISTS_TAC `x:real^N` THEN
  2.1117 -    ASM_REWRITE_TAC[IN_ELIM_THM] THEN
  2.1118 -    SIMP_TAC[REAL_LE_LDIV_EQ; REAL_LT_RDIV_EQ; REAL_LT_POW2] THEN
  2.1119 -    REWRITE_TAC[REAL_MUL_SYM; FLOOR];
  2.1120 -    X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN
  2.1121 -    FIRST_ASSUM(MP_TAC o MATCH_MP COMPACT_IMP_CLOSED) THEN
  2.1122 -    REWRITE_TAC[closed; open_def] THEN
  2.1123 -    DISCH_THEN(MP_TAC o SPEC `x:real^N`) THEN
  2.1124 -    ASM_REWRITE_TAC[IN_DIFF; IN_UNIV] THEN
  2.1125 -    DISCH_THEN(X_CHOOSE_THEN `e:real` STRIP_ASSUME_TAC) THEN
  2.1126 -    MP_TAC(SPECL [`inv(2)`; `e / (dimindex(:N))`] REAL_ARCH_POW_INV) THEN
  2.1127 -    ASM_SIMP_TAC[REAL_LT_DIV; REAL_LT_RDIV_EQ; REAL_OF_NUM_LT;
  2.1128 -                 DIMINDEX_GE_1; ARITH_RULE `0 < x \<longleftrightarrow> 1 \<le> x`] THEN
  2.1129 -    CONV_TAC REAL_RAT_REDUCE_CONV THEN
  2.1130 -    MATCH_MP_TAC MONO_EXISTS THEN X_GEN_TAC `n:num` THEN DISCH_TAC THEN
  2.1131 -    REWRITE_TAC[IN_UNIONS; IN_ELIM_THM] THEN
  2.1132 -    REWRITE_TAC[LEFT_AND_EXISTS_THM] THEN
  2.1133 -    ONCE_REWRITE_TAC[SWAP_EXISTS_THM] THEN
  2.1134 -    ONCE_REWRITE_TAC[TAUT `(a \<and> b \<and> c) \<and> d \<longleftrightarrow> b \<and> a \<and> c \<and> d`] THEN
  2.1135 -    REWRITE_TAC[UNWIND_THM2] THEN REWRITE_TAC[NOT_EXISTS_THM] THEN
  2.1136 -    X_GEN_TAC `u:real^N` THEN REWRITE_TAC[GSYM MEMBER_NOT_EMPTY] THEN
  2.1137 -    REWRITE_TAC[IN_INTER; IN_ELIM_THM] THEN
  2.1138 -    DISCH_THEN(CONJUNCTS_THEN2 MP_TAC ASSUME_TAC o CONJUNCT2) THEN
  2.1139 -    DISCH_THEN(X_CHOOSE_THEN `y:real^N`
  2.1140 -     (CONJUNCTS_THEN2 MP_TAC ASSUME_TAC)) THEN
  2.1141 -    REWRITE_TAC[] THEN FIRST_X_ASSUM MATCH_MP_TAC THEN
  2.1142 -    FIRST_X_ASSUM(MATCH_MP_TAC o MATCH_MP (REAL_ARITH
  2.1143 -     `d < e ==> x \<le> d ==> x < e`)) THEN
  2.1144 -    REWRITE_TAC[dist] THEN
  2.1145 -    W(MP_TAC o PART_MATCH lhand NORM_LE_L1 o lhand o snd) THEN
  2.1146 -    MATCH_MP_TAC(REAL_ARITH `a \<le> b ==> x \<le> a ==> x \<le> b`) THEN
  2.1147 -    GEN_REWRITE_TAC (funpow 3 RAND_CONV) [GSYM CARD_NUMSEG_1] THEN
  2.1148 -    ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN MATCH_MP_TAC SUM_BOUND THEN
  2.1149 -    SIMP_TAC[FINITE_NUMSEG; IN_NUMSEG; VECTOR_SUB_COMPONENT] THEN
  2.1150 -    X_GEN_TAC `k:num` THEN STRIP_TAC THEN
  2.1151 -    REPEAT(FIRST_X_ASSUM(MP_TAC o SPEC `k:num`)) THEN
  2.1152 -    ASM_REWRITE_TAC[real_div; REAL_ADD_RDISTRIB] THEN
  2.1153 -    REWRITE_TAC[REAL_MUL_LID; GSYM REAL_POW_INV] THEN REAL_ARITH_TAC;
  2.1154 -    MAP_EVERY X_GEN_TAC [`n:num`; `a:real^N->bool`] THEN
  2.1155 -    DISCH_THEN(X_CHOOSE_THEN `u:real^N`
  2.1156 -     (CONJUNCTS_THEN2 ASSUME_TAC MP_TAC)) THEN
  2.1157 -    DISCH_THEN(CONJUNCTS_THEN2 (ASSUME_TAC o SYM) ASSUME_TAC) THEN
  2.1158 -    REWRITE_TAC[LEFT_AND_EXISTS_THM] THEN
  2.1159 -    ONCE_REWRITE_TAC[SWAP_EXISTS_THM] THEN
  2.1160 -    ONCE_REWRITE_TAC[TAUT `(a \<and> b \<and> c) \<and> d \<longleftrightarrow> b \<and> a \<and> c \<and> d`] THEN
  2.1161 -    REWRITE_TAC[UNWIND_THM2] THEN
  2.1162 -    EXISTS_TAC `(lambda i. floor((u:real^N)$i / 2)):real^N` THEN
  2.1163 -    ASM_SIMP_TAC[VECTOR_MUL_COMPONENT; LAMBDA_BETA; FLOOR] THEN
  2.1164 -    MATCH_MP_TAC(SET_RULE `~(s \<inter> a = {}) \<and> a \<subseteq> b
  2.1165 -                           ==> ~(s \<inter> b = {}) \<and> a \<subseteq> b`) THEN
  2.1166 -    ASM_REWRITE_TAC[] THEN EXPAND_TAC "a" THEN REWRITE_TAC[SUBSET] THEN
  2.1167 -    X_GEN_TAC `x:real^N` THEN REWRITE_TAC[IN_ELIM_THM] THEN
  2.1168 -    MATCH_MP_TAC MONO_FORALL THEN X_GEN_TAC `k:num` THEN
  2.1169 -    DISCH_THEN(fun th -> STRIP_TAC THEN MP_TAC th) THEN ASM_REWRITE_TAC[] THEN
  2.1170 -    REWRITE_TAC[real_pow; real_div; REAL_INV_MUL; REAL_MUL_ASSOC] THEN
  2.1171 -    REWRITE_TAC[GSYM real_div] THEN
  2.1172 -    SIMP_TAC[REAL_LE_LDIV_EQ; REAL_LT_RDIV_EQ; REAL_LT_POW2] THEN
  2.1173 -    MP_TAC(SPEC `(u:real^N)$k / 2` FLOOR) THEN
  2.1174 -    REWRITE_TAC[REAL_ARITH `u / 2 < floor(u / 2) + 1 \<longleftrightarrow>
  2.1175 -                            u < 2 * floor(u / 2) + 2`] THEN
  2.1176 -    ASM_SIMP_TAC[REAL_LT_INTEGERS; INTEGER_CLOSED; FLOOR_FRAC] THEN
  2.1177 -    REAL_ARITH_TAC;
  2.1178 -    REWRITE_TAC[LEFT_IMP_EXISTS_THM] THEN
  2.1179 -    MAP_EVERY X_GEN_TAC [`n:num`; `a:real^N->bool`; `u:real^N`] THEN
  2.1180 -    DISCH_THEN(SUBST1_TAC o CONJUNCT1 o CONJUNCT2) THEN
  2.1181 -    ONCE_REWRITE_TAC[MEASURABLE_INNER_OUTER] THEN
  2.1182 -    GEN_TAC THEN DISCH_TAC THEN
  2.1183 -    EXISTS_TAC `interval(inv(2 pow n) % u:real^N,
  2.1184 -                         inv(2 pow n) % (u + 1))` THEN
  2.1185 -    EXISTS_TAC `interval[inv(2 pow n) % u:real^N,
  2.1186 -                         inv(2 pow n) % (u + 1)]` THEN
  2.1187 -    REWRITE_TAC[MEASURABLE_INTERVAL; MEASURE_INTERVAL] THEN
  2.1188 -    ASM_REWRITE_TAC[REAL_SUB_REFL; REAL_ABS_0] THEN
  2.1189 -    REWRITE_TAC[SUBSET; IN_INTERVAL; IN_ELIM_THM] THEN
  2.1190 -    CONJ_TAC THEN X_GEN_TAC `y:real^N` THEN
  2.1191 -    MATCH_MP_TAC MONO_FORALL THEN X_GEN_TAC `k:num` THEN
  2.1192 -    DISCH_THEN(fun th -> STRIP_TAC THEN MP_TAC th) THEN
  2.1193 -    ASM_SIMP_TAC[VECTOR_MUL_COMPONENT; VECTOR_ADD_COMPONENT;
  2.1194 -                 VEC_COMPONENT] THEN
  2.1195 -    REAL_ARITH_TAC]);; *)
  2.1196 -
  2.1197 -lemma gmeasurable_open: True .. (*
  2.1198 - "!s:real^N->bool. bounded s \<and> open s ==> gmeasurable s"
  2.1199 -qed   REPEAT STRIP_TAC THEN
  2.1200 -  FIRST_X_ASSUM(MP_TAC o MATCH_MP BOUNDED_SUBSET_CLOSED_INTERVAL) THEN
  2.1201 -  REWRITE_TAC[LEFT_IMP_EXISTS_THM] THEN
  2.1202 -  MAP_EVERY X_GEN_TAC [`a:real^N`; `b:real^N`] THEN DISCH_TAC THEN
  2.1203 -  FIRST_ASSUM(SUBST1_TAC o MATCH_MP (SET_RULE
  2.1204 -   `s \<subseteq> t ==> s = t DIFF (t DIFF s)`)) THEN
  2.1205 -  MATCH_MP_TAC GMEASURABLE_DIFF THEN
  2.1206 -  REWRITE_TAC[MEASURABLE_INTERVAL] THEN
  2.1207 -  MATCH_MP_TAC GMEASURABLE_COMPACT THEN
  2.1208 -  SIMP_TAC[COMPACT_EQ_BOUNDED_CLOSED; BOUNDED_DIFF; BOUNDED_INTERVAL] THEN
  2.1209 -  MATCH_MP_TAC CLOSED_DIFF THEN ASM_REWRITE_TAC[CLOSED_INTERVAL]);; *)
  2.1210 -
  2.1211 -lemma gmeasurable_closure: True .. (*
  2.1212 - "!s. bounded s ==> gmeasurable(closure s)"
  2.1213 -qed   SIMP_TAC[MEASURABLE_COMPACT; COMPACT_EQ_BOUNDED_CLOSED; CLOSED_CLOSURE;
  2.1214 -           BOUNDED_CLOSURE]);; *)
  2.1215 -
  2.1216 -lemma gmeasurable_interior: True .. (*
  2.1217 - "!s. bounded s ==> gmeasurable(interior s)"
  2.1218 -qed   SIMP_TAC[MEASURABLE_OPEN; OPEN_INTERIOR; BOUNDED_INTERIOR]);; *)
  2.1219 -
  2.1220 -lemma gmeasurable_frontier: True .. (*
  2.1221 - "!s:real^N->bool. bounded s ==> gmeasurable(frontier s)"
  2.1222 -qed   REPEAT STRIP_TAC THEN REWRITE_TAC[frontier] THEN
  2.1223 -  MATCH_MP_TAC GMEASURABLE_DIFF THEN
  2.1224 -  ASM_SIMP_TAC[MEASURABLE_CLOSURE; GMEASURABLE_INTERIOR] THEN
  2.1225 -  MATCH_MP_TAC SUBSET_TRANS THEN EXISTS_TAC `s:real^N->bool` THEN
  2.1226 -  REWRITE_TAC[INTERIOR_SUBSET; CLOSURE_SUBSET]);; *)
  2.1227 -
  2.1228 -lemma measure_frontier: True .. (*
  2.1229 - "!s:real^N->bool.
  2.1230 -        bounded s
  2.1231 -        ==> measure(frontier s) = measure(closure s) - measure(interior s)"
  2.1232 -qed   REPEAT STRIP_TAC THEN REWRITE_TAC[frontier] THEN
  2.1233 -  MATCH_MP_TAC MEASURE_DIFF_SUBSET THEN
  2.1234 -  ASM_SIMP_TAC[MEASURABLE_CLOSURE; GMEASURABLE_INTERIOR] THEN
  2.1235 -  MATCH_MP_TAC SUBSET_TRANS THEN EXISTS_TAC `s:real^N->bool` THEN
  2.1236 -  REWRITE_TAC[INTERIOR_SUBSET; CLOSURE_SUBSET]);; *)
  2.1237 -
  2.1238 -lemma gmeasurable_jordan: True .. (*
  2.1239 - "!s:real^N->bool. bounded s \<and> negligible(frontier s) ==> gmeasurable s"
  2.1240 -qed   REPEAT STRIP_TAC THEN ONCE_REWRITE_TAC[MEASURABLE_INNER_OUTER] THEN
  2.1241 -  GEN_TAC THEN DISCH_TAC THEN
  2.1242 -  EXISTS_TAC `interior(s):real^N->bool` THEN
  2.1243 -  EXISTS_TAC `closure(s):real^N->bool` THEN
  2.1244 -  ASM_SIMP_TAC[MEASURABLE_INTERIOR; GMEASURABLE_CLOSURE] THEN
  2.1245 -  REWRITE_TAC[INTERIOR_SUBSET; CLOSURE_SUBSET] THEN
  2.1246 -  ONCE_REWRITE_TAC[REAL_ABS_SUB] THEN
  2.1247 -  ASM_SIMP_TAC[GSYM MEASURE_FRONTIER; REAL_ABS_NUM; MEASURE_EQ_0]);; *)
  2.1248 -
  2.1249 -lemma has_gmeasure_elementary: True .. (*
  2.1250 - "!d s. d division_of s ==> s has_gmeasure (sum d content)"
  2.1251 -qed   REPEAT STRIP_TAC THEN REWRITE_TAC[has_gmeasure] THEN
  2.1252 -  FIRST_ASSUM(ASSUME_TAC o MATCH_MP DIVISION_OF_FINITE) THEN
  2.1253 -  ASM_SIMP_TAC[LIFT_SUM] THEN
  2.1254 -  MATCH_MP_TAC HAS_INTEGRAL_COMBINE_DIVISION THEN
  2.1255 -  ASM_REWRITE_TAC[o_THM] THEN REWRITE_TAC[GSYM has_gmeasure] THEN
  2.1256 -  ASM_MESON_TAC[HAS_GMEASURE_INTERVAL; division_of]);; *)
  2.1257 -
  2.1258 -lemma gmeasurable_elementary: True .. (*
  2.1259 - "!d s. d division_of s ==> gmeasurable s"
  2.1260 -qed   REWRITE_TAC[measurable] THEN MESON_TAC[HAS_GMEASURE_ELEMENTARY]);; *)
  2.1261 -
  2.1262 -lemma measure_elementary: True .. (*
  2.1263 - "!d s. d division_of s ==> gmeasure s = sum d content"
  2.1264 -qed   MESON_TAC[HAS_GMEASURE_ELEMENTARY; MEASURE_UNIQUE]);; *)
  2.1265 -
  2.1266 -lemma gmeasurable_inter_interval: True .. (*
  2.1267 - "!s a b:real^N. gmeasurable s ==> gmeasurable (s \<inter> {a..b})"
  2.1268 -qed   SIMP_TAC[MEASURABLE_INTER; GMEASURABLE_INTERVAL]);; *)
  2.1269 -
  2.1270 -(* ------------------------------------------------------------------------- *)
  2.1271 -(* A nice lemma for negligibility proofs.                                    *)
  2.1272 -(* ------------------------------------------------------------------------- *)
  2.1273 -
  2.1274 -lemma STARLIKE_NEGLIGIBLE_BOUNDED_MEASURABLE: True .. (*
  2.1275 - "!s. gmeasurable s \<and> bounded s \<and>
  2.1276 -       (!c x:real^N. 0 \<le> c \<and> x \<in> s \<and> (c % x) \<in> s ==> c = 1)
  2.1277 -       ==> negligible s"
  2.1278 -qed   REPEAT STRIP_TAC THEN
  2.1279 -  SUBGOAL_THEN `~(0 < measure(s:real^N->bool))`
  2.1280 -   (fun th -> ASM_MESON_TAC[th; GMEASURABLE_MEASURE_POS_LT]) THEN
  2.1281 -  DISCH_TAC THEN
  2.1282 -  MP_TAC(SPEC `(0:real^N) INSERT s`
  2.1283 -      BOUNDED_SUBSET_CLOSED_INTERVAL_SYMMETRIC) THEN
  2.1284 -  ASM_SIMP_TAC[BOUNDED_INSERT; COMPACT_IMP_BOUNDED; NOT_EXISTS_THM] THEN
  2.1285 -  X_GEN_TAC `a:real^N` THEN REWRITE_TAC[INSERT_SUBSET] THEN STRIP_TAC THEN
  2.1286 -  SUBGOAL_THEN
  2.1287 -   `?N. EVEN N \<and> 0 < N \<and>
  2.1288 -        measure(interval[--a:real^N,a])
  2.1289 -         < (N * measure(s:real^N->bool)) / 4 pow dimindex (:N)`
  2.1290 -  STRIP_ASSUME_TAC THENL
  2.1291 -   [FIRST_ASSUM(MP_TAC o SPEC
  2.1292 -     `measure(interval[--a:real^N,a]) * 4 pow (dimindex(:N))` o
  2.1293 -     MATCH_MP REAL_ARCH) THEN
  2.1294 -    SIMP_TAC[REAL_LT_RDIV_EQ; REAL_POW_LT; REAL_OF_NUM_LT; ARITH] THEN
  2.1295 -    SIMP_TAC[GSYM REAL_LT_LDIV_EQ; ASSUME `0 < measure(s:real^N->bool)`] THEN
  2.1296 -    DISCH_THEN(X_CHOOSE_THEN `N:num` STRIP_ASSUME_TAC) THEN
  2.1297 -    EXISTS_TAC `2 * (N DIV 2 + 1)` THEN REWRITE_TAC[EVEN_MULT; ARITH] THEN
  2.1298 -    CONJ_TAC THENL [ARITH_TAC; ALL_TAC] THEN
  2.1299 -    FIRST_X_ASSUM(MATCH_MP_TAC o MATCH_MP (REAL_ARITH
  2.1300 -     `x < a ==> a \<le> b ==> x < b`)) THEN
  2.1301 -    REWRITE_TAC[REAL_OF_NUM_LE] THEN ARITH_TAC;
  2.1302 -    ALL_TAC] THEN
  2.1303 -  MP_TAC(ISPECL [`\<Union>(IMAGE (\<lambda>m. IMAGE (\<lambda>x:real^N. (m / N) % x) s)
  2.1304 -                                (1..N))`;
  2.1305 -                  `interval[--a:real^N,a]`] MEASURE_SUBSET) THEN
  2.1306 -  MP_TAC(ISPECL [`measure:(real^N->bool)->real`;
  2.1307 -                 `IMAGE (\<lambda>m. IMAGE (\<lambda>x:real^N. (m / N) % x) s) (1..N)`]
  2.1308 -                HAS_GMEASURE_DISJOINT_UNIONS) THEN
  2.1309 -  SIMP_TAC[FINITE_IMAGE; FINITE_NUMSEG; IMP_CONJ] THEN
  2.1310 -  REWRITE_TAC[RIGHT_FORALL_IMP_THM; FORALL_IN_IMAGE] THEN ANTS_TAC THENL
  2.1311 -   [REPEAT STRIP_TAC THEN REWRITE_TAC[GSYM HAS_GMEASURE_MEASURE] THEN
  2.1312 -    MATCH_MP_TAC GMEASURABLE_SCALING THEN ASM_REWRITE_TAC[];
  2.1313 -    ALL_TAC] THEN
  2.1314 -  REWRITE_TAC[RIGHT_IMP_FORALL_THM; IMP_IMP] THEN
  2.1315 -  ONCE_REWRITE_TAC[TAUT `(a \<and> b) \<and> ~c ==> d \<longleftrightarrow> a \<and> b \<and> ~d ==> c`] THEN
  2.1316 -  SUBGOAL_THEN
  2.1317 -   `!m n. m \<in> 1..N \<and> n \<in> 1..N \<and>
  2.1318 -          ~(DISJOINT (IMAGE (\<lambda>x:real^N. m / N % x) s)
  2.1319 -                     (IMAGE (\<lambda>x. n / N % x) s))
  2.1320 -          ==> m = n`
  2.1321 -  ASSUME_TAC THENL
  2.1322 -   [MAP_EVERY X_GEN_TAC [`m:num`; `n:num`] THEN
  2.1323 -    REPEAT(DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC MP_TAC)) THEN
  2.1324 -    REWRITE_TAC[DISJOINT; GSYM MEMBER_NOT_EMPTY] THEN
  2.1325 -    REWRITE_TAC[EXISTS_IN_IMAGE; IN_INTER] THEN
  2.1326 -    DISCH_THEN(X_CHOOSE_THEN `x:real^N`
  2.1327 -     (CONJUNCTS_THEN2 ASSUME_TAC MP_TAC)) THEN
  2.1328 -    REWRITE_TAC[IN_IMAGE] THEN
  2.1329 -    DISCH_THEN(X_CHOOSE_THEN `y:real^N`
  2.1330 -     (CONJUNCTS_THEN2 MP_TAC ASSUME_TAC)) THEN
  2.1331 -    DISCH_THEN(MP_TAC o AP_TERM `(%) (N / m) :real^N->real^N`) THEN
  2.1332 -    SUBGOAL_THEN `~(N = 0) \<and> ~(m = 0)` STRIP_ASSUME_TAC THENL
  2.1333 -     [REWRITE_TAC[REAL_OF_NUM_EQ] THEN
  2.1334 -      REPEAT(FIRST_X_ASSUM(MP_TAC o GEN_REWRITE_RULE I [IN_NUMSEG])) THEN
  2.1335 -      ARITH_TAC;
  2.1336 -      ALL_TAC] THEN
  2.1337 -    FIRST_X_ASSUM(ASSUME_TAC o GEN_REWRITE_RULE (BINDER_CONV o BINDER_CONV)
  2.1338 -     [GSYM CONTRAPOS_THM]) THEN
  2.1339 -    ASM_SIMP_TAC[VECTOR_MUL_ASSOC; REAL_FIELD
  2.1340 -     `~(x = 0) \<and> ~(y = 0) ==> x / y * y / x = 1`] THEN
  2.1341 -    ASM_SIMP_TAC[REAL_FIELD
  2.1342 -     `~(x = 0) \<and> ~(y = 0) ==> x / y * z / x = z / y`] THEN
  2.1343 -    REWRITE_TAC[VECTOR_MUL_LID] THEN DISCH_THEN SUBST_ALL_TAC THEN
  2.1344 -    FIRST_X_ASSUM(MP_TAC o SPECL [`n / m`; `y:real^N`]) THEN
  2.1345 -    ASM_SIMP_TAC[REAL_LE_DIV; REAL_POS; REAL_FIELD
  2.1346 -     `~(y = 0) ==> (x / y = 1 \<longleftrightarrow> x = y)`] THEN
  2.1347 -    REWRITE_TAC[REAL_OF_NUM_EQ; EQ_SYM_EQ];
  2.1348 -    ALL_TAC] THEN
  2.1349 -  ANTS_TAC THENL [ASM_MESON_TAC[]; DISCH_TAC] THEN
  2.1350 -  REWRITE_TAC[NOT_IMP] THEN REPEAT CONJ_TAC THENL
  2.1351 -   [REWRITE_TAC[measurable] THEN ASM_MESON_TAC[];
  2.1352 -    REWRITE_TAC[MEASURABLE_INTERVAL];
  2.1353 -    REWRITE_TAC[UNIONS_SUBSET; FORALL_IN_IMAGE] THEN
  2.1354 -    REWRITE_TAC[SUBSET; FORALL_IN_IMAGE] THEN
  2.1355 -    X_GEN_TAC `n:num` THEN DISCH_TAC THEN X_GEN_TAC `x:real^N` THEN
  2.1356 -    DISCH_TAC THEN
  2.1357 -    MP_TAC(ISPECL [`--a:real^N`; `a:real^N`] CONVEX_INTERVAL) THEN
  2.1358 -    DISCH_THEN(MP_TAC o REWRITE_RULE[CONVEX_ALT] o CONJUNCT1) THEN
  2.1359 -    DISCH_THEN(MP_TAC o SPECL [`0:real^N`; `x:real^N`; `n / N`]) THEN
  2.1360 -    ASM_REWRITE_TAC[VECTOR_MUL_RZERO; VECTOR_ADD_LID] THEN
  2.1361 -    DISCH_THEN MATCH_MP_TAC THEN SIMP_TAC[REAL_LE_DIV; REAL_POS] THEN
  2.1362 -    CONJ_TAC THENL [ASM SET_TAC[]; ALL_TAC] THEN
  2.1363 -    FIRST_X_ASSUM(MP_TAC o GEN_REWRITE_RULE I [IN_NUMSEG]) THEN
  2.1364 -    DISCH_THEN(MP_TAC o MATCH_MP (ARITH_RULE
  2.1365 -     `1 \<le> n \<and> n \<le> N ==> 0 < N \<and> n \<le> N`)) THEN
  2.1366 -    SIMP_TAC[GSYM REAL_OF_NUM_LE; GSYM REAL_OF_NUM_LT; REAL_LE_LDIV_EQ] THEN
  2.1367 -    SIMP_TAC[REAL_MUL_LID];
  2.1368 -    ALL_TAC] THEN
  2.1369 -  FIRST_X_ASSUM(SUBST1_TAC o MATCH_MP MEASURE_UNIQUE) THEN
  2.1370 -  ASM_SIMP_TAC[MEASURE_SCALING; REAL_NOT_LE] THEN
  2.1371 -  FIRST_X_ASSUM(K ALL_TAC o SPEC `0`) THEN
  2.1372 -  MATCH_MP_TAC REAL_LTE_TRANS THEN EXISTS_TAC
  2.1373 -   `sum (1..N) (measure o (\<lambda>m. IMAGE (\<lambda>x:real^N. m / N % x) s))` THEN
  2.1374 -  CONJ_TAC THENL
  2.1375 -   [ALL_TAC;
  2.1376 -    MATCH_MP_TAC REAL_EQ_IMP_LE THEN CONV_TAC SYM_CONV THEN
  2.1377 -    MATCH_MP_TAC SUM_IMAGE THEN REWRITE_TAC[] THEN
  2.1378 -    REPEAT STRIP_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN
  2.1379 -    ASM_REWRITE_TAC[SET_RULE `DISJOINT s s \<longleftrightarrow> s = {}`; IMAGE_EQ_EMPTY] THEN
  2.1380 -    DISCH_THEN SUBST_ALL_TAC THEN
  2.1381 -    ASM_MESON_TAC[REAL_LT_REFL; MEASURE_EMPTY]] THEN
  2.1382 -  FIRST_X_ASSUM(K ALL_TAC o SPEC `0`) THEN
  2.1383 -  ASM_SIMP_TAC[o_DEF; MEASURE_SCALING; SUM_RMUL] THEN
  2.1384 -  FIRST_ASSUM(MATCH_MP_TAC o MATCH_MP (REAL_ARITH
  2.1385 -   `x < a ==> a \<le> b ==> x < b`)) THEN
  2.1386 -  ASM_SIMP_TAC[REAL_LE_LDIV_EQ; REAL_POW_LT; REAL_OF_NUM_LT; ARITH] THEN
  2.1387 -  ONCE_REWRITE_TAC[REAL_ARITH `(a * b) * c:real = (a * c) * b`] THEN
  2.1388 -  ASM_SIMP_TAC[REAL_LE_RMUL_EQ] THEN REWRITE_TAC[GSYM SUM_RMUL] THEN
  2.1389 -  REWRITE_TAC[GSYM REAL_POW_MUL] THEN
  2.1390 -  REWRITE_TAC[REAL_ABS_DIV; REAL_ABS_NUM] THEN
  2.1391 -  FIRST_X_ASSUM(X_CHOOSE_THEN `M:num` SUBST_ALL_TAC o
  2.1392 -        GEN_REWRITE_RULE I [EVEN_EXISTS]) THEN
  2.1393 -  REWRITE_TAC[GSYM REAL_OF_NUM_MUL] THEN
  2.1394 -  RULE_ASSUM_TAC(REWRITE_RULE[GSYM REAL_OF_NUM_MUL]) THEN
  2.1395 -  RULE_ASSUM_TAC(REWRITE_RULE[REAL_ARITH `0 < 2 * x \<longleftrightarrow> 0 < x`]) THEN
  2.1396 -  ASM_SIMP_TAC[REAL_FIELD `0 < y ==> x / (2 * y) * 4 = x * 2 / y`] THEN
  2.1397 -  MATCH_MP_TAC REAL_LE_TRANS THEN
  2.1398 -  EXISTS_TAC `sum(M..(2*M)) (\<lambda>i. (i * 2 / M) pow dimindex (:N))` THEN
  2.1399 -  CONJ_TAC THENL
  2.1400 -   [ALL_TAC;
  2.1401 -    MATCH_MP_TAC SUM_SUBSET_SIMPLE THEN
  2.1402 -    SIMP_TAC[REAL_POW_LE; REAL_LE_MUL; REAL_LE_DIV; REAL_POS] THEN
  2.1403 -    REWRITE_TAC[IN_NUMSEG; FINITE_NUMSEG; SUBSET] THEN
  2.1404 -    FIRST_X_ASSUM(MP_TAC o GEN_REWRITE_RULE I [REAL_OF_NUM_LT]) THEN
  2.1405 -    ARITH_TAC] THEN
  2.1406 -  MATCH_MP_TAC REAL_LE_TRANS THEN
  2.1407 -  EXISTS_TAC `sum(M..(2*M)) (\<lambda>i. 2)` THEN CONJ_TAC THENL
  2.1408 -   [REWRITE_TAC[SUM_CONST_NUMSEG] THEN
  2.1409 -    REWRITE_TAC[ARITH_RULE `(2 * M + 1) - M = M + 1`] THEN
  2.1410 -    REWRITE_TAC[GSYM REAL_OF_NUM_ADD] THEN REAL_ARITH_TAC;
  2.1411 -    ALL_TAC] THEN
  2.1412 -  MATCH_MP_TAC SUM_LE THEN REWRITE_TAC[FINITE_NUMSEG; IN_NUMSEG] THEN
  2.1413 -  X_GEN_TAC `n:num` THEN STRIP_TAC THEN
  2.1414 -  MATCH_MP_TAC REAL_LE_TRANS THEN EXISTS_TAC `2 pow (dimindex(:N))` THEN
  2.1415 -  CONJ_TAC THENL
  2.1416 -   [GEN_REWRITE_TAC LAND_CONV [GSYM REAL_POW_1] THEN
  2.1417 -    MATCH_MP_TAC REAL_POW_MONO THEN REWRITE_TAC[DIMINDEX_GE_1] THEN
  2.1418 -    ARITH_TAC;
  2.1419 -    ALL_TAC] THEN
  2.1420 -  MATCH_MP_TAC REAL_POW_LE2 THEN
  2.1421 -  REWRITE_TAC[REAL_POS; ARITH; real_div; REAL_MUL_ASSOC] THEN
  2.1422 -  ASM_SIMP_TAC[GSYM real_div; REAL_LE_RDIV_EQ] THEN
  2.1423 -  REWRITE_TAC[REAL_OF_NUM_MUL; REAL_OF_NUM_LE] THEN
  2.1424 -  UNDISCH_TAC `M:num \<le> n` THEN ARITH_TAC);; *)
  2.1425 -
  2.1426 -lemma STARLIKE_NEGLIGIBLE_LEMMA: True .. (*
  2.1427 - "!s. compact s \<and>
  2.1428 -       (!c x:real^N. 0 \<le> c \<and> x \<in> s \<and> (c % x) \<in> s ==> c = 1)
  2.1429 -       ==> negligible s"
  2.1430 -qed   REPEAT STRIP_TAC THEN
  2.1431 -  MATCH_MP_TAC STARLIKE_NEGLIGIBLE_BOUNDED_MEASURABLE THEN
  2.1432 -  ASM_MESON_TAC[MEASURABLE_COMPACT; COMPACT_IMP_BOUNDED]);; *)
  2.1433 -
  2.1434 -lemma STARLIKE_NEGLIGIBLE: True .. (*
  2.1435 - "!s a. closed s \<and>
  2.1436 -         (!c x:real^N. 0 \<le> c \<and> (a + x) \<in> s \<and> (a + c % x) \<in> s ==> c = 1)
  2.1437 -         ==> negligible s"
  2.1438 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC NEGLIGIBLE_TRANSLATION_REV THEN
  2.1439 -  EXISTS_TAC `--a:real^N` THEN ONCE_REWRITE_TAC[NEGLIGIBLE_ON_INTERVALS] THEN
  2.1440 -  MAP_EVERY X_GEN_TAC [`u:real^N`; `v:real^N`] THEN
  2.1441 -  MATCH_MP_TAC STARLIKE_NEGLIGIBLE_LEMMA THEN CONJ_TAC THENL
  2.1442 -   [MATCH_MP_TAC CLOSED_INTER_COMPACT THEN REWRITE_TAC[COMPACT_INTERVAL] THEN
  2.1443 -    ASM_SIMP_TAC[CLOSED_TRANSLATION];
  2.1444 -    REWRITE_TAC[IN_IMAGE; IN_INTER] THEN
  2.1445 -    ONCE_REWRITE_TAC[VECTOR_ARITH `x:real^N = --a + y \<longleftrightarrow> y = a + x`] THEN
  2.1446 -    REWRITE_TAC[UNWIND_THM2] THEN ASM MESON_TAC[]]);; *)
  2.1447 -
  2.1448 -lemma STARLIKE_NEGLIGIBLE_STRONG: True .. (*
  2.1449 - "!s a. closed s \<and>
  2.1450 -         (!c x:real^N. 0 \<le> c \<and> c < 1 \<and> (a + x) \<in> s
  2.1451 -                       ==> ~((a + c % x) \<in> s))
  2.1452 -         ==> negligible s"
  2.1453 -qed   REPEAT GEN_TAC THEN STRIP_TAC THEN MATCH_MP_TAC STARLIKE_NEGLIGIBLE THEN
  2.1454 -  EXISTS_TAC `a:real^N` THEN ASM_REWRITE_TAC[] THEN
  2.1455 -  MAP_EVERY X_GEN_TAC [`c:real`; `x:real^N`] THEN STRIP_TAC THEN
  2.1456 -  MATCH_MP_TAC(REAL_ARITH `~(x < y) \<and> ~(y < x) ==> x = y`) THEN
  2.1457 -  STRIP_TAC THENL [ASM_MESON_TAC[]; ALL_TAC] THEN DISCH_TAC THEN
  2.1458 -  FIRST_X_ASSUM(MP_TAC o SPECL [`inv c`; `c % x:real^N`]) THEN
  2.1459 -  ASM_REWRITE_TAC[REAL_LE_INV_EQ; VECTOR_MUL_ASSOC] THEN
  2.1460 -  ASM_SIMP_TAC[REAL_MUL_LINV; REAL_ARITH `1 < c ==> ~(c = 0)`] THEN
  2.1461 -  ASM_REWRITE_TAC[VECTOR_MUL_LID] THEN
  2.1462 -  GEN_REWRITE_TAC RAND_CONV [GSYM REAL_INV_1] THEN
  2.1463 -  MATCH_MP_TAC REAL_LT_INV2 THEN ASM_REWRITE_TAC[REAL_LT_01]);; *)
  2.1464 -
  2.1465 -(* ------------------------------------------------------------------------- *)
  2.1466 -(* In particular.                                                            *)
  2.1467 -(* ------------------------------------------------------------------------- *)
  2.1468 -
  2.1469 -lemma NEGLIGIBLE_HYPERPLANE: True .. (*
  2.1470 - "!a b. ~(a = 0 \<and> b = 0) ==> negligible {x:real^N | a dot x = b}"
  2.1471 -qed   REPEAT GEN_TAC THEN ASM_CASES_TAC `a:real^N = 0` THEN
  2.1472 -  ASM_SIMP_TAC[DOT_LZERO; SET_RULE `{x | F} = {}`; NEGLIGIBLE_EMPTY] THEN
  2.1473 -  MATCH_MP_TAC STARLIKE_NEGLIGIBLE THEN
  2.1474 -  SUBGOAL_THEN `?x:real^N. ~(a dot x = b)` MP_TAC THENL
  2.1475 -   [MATCH_MP_TAC(MESON[] `!a:real^N. P a \/ P(--a) ==> ?x. P x`) THEN
  2.1476 -    EXISTS_TAC `a:real^N` THEN REWRITE_TAC[DOT_RNEG] THEN
  2.1477 -    MATCH_MP_TAC(REAL_ARITH `~(a = 0) ==> ~(a = b) \/ ~(--a = b)`) THEN
  2.1478 -    ASM_REWRITE_TAC[DOT_EQ_0];
  2.1479 -    ALL_TAC] THEN
  2.1480 -  MATCH_MP_TAC MONO_EXISTS THEN X_GEN_TAC `c:real^N` THEN DISCH_TAC THEN
  2.1481 -  REWRITE_TAC[CLOSED_HYPERPLANE; IN_ELIM_THM; DOT_RADD; DOT_RMUL] THEN
  2.1482 -  MAP_EVERY X_GEN_TAC [`t:real`; `y:real^N`] THEN
  2.1483 -  DISCH_THEN(MP_TAC o MATCH_MP (REAL_ARITH
  2.1484 -   `0 \<le> t \<and> ac + ay = b \<and> ac + t * ay = b
  2.1485 -    ==> ((ay = 0 ==> ac = b) \<and> (t - 1) * ay = 0)`)) THEN
  2.1486 -  ASM_SIMP_TAC[REAL_ENTIRE; REAL_SUB_0] THEN CONV_TAC TAUT);; *)
  2.1487 -
  2.1488 -lemma NEGLIGIBLE_LOWDIM: True .. (*
  2.1489 - "!s:real^N->bool. dim(s) < dimindex(:N) ==> negligible s"
  2.1490 -qed   GEN_TAC THEN DISCH_THEN(MP_TAC o MATCH_MP LOWDIM_SUBSET_HYPERPLANE) THEN
  2.1491 -  DISCH_THEN(X_CHOOSE_THEN `a:real^N` STRIP_ASSUME_TAC) THEN
  2.1492 -  MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.1493 -  EXISTS_TAC `span(s):real^N->bool` THEN REWRITE_TAC[SPAN_INC] THEN
  2.1494 -  MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.1495 -  EXISTS_TAC `{x:real^N | a dot x = 0}` THEN
  2.1496 -  ASM_SIMP_TAC[NEGLIGIBLE_HYPERPLANE]);; *)
  2.1497 -
  2.1498 -(* ------------------------------------------------------------------------- *)
  2.1499 -(* Measurability of bounded convex sets.                                     *)
  2.1500 -(* ------------------------------------------------------------------------- *)
  2.1501 -
  2.1502 -lemma NEGLIGIBLE_CONVEX_FRONTIER: True .. (*
  2.1503 - "!s:real^N->bool. convex s ==> negligible(frontier s)"
  2.1504 -qed   SUBGOAL_THEN
  2.1505 -   `!s:real^N->bool. convex s \<and> (0) \<in> s ==> negligible(frontier s)`
  2.1506 -  ASSUME_TAC THENL
  2.1507 -   [ALL_TAC;
  2.1508 -    X_GEN_TAC `s:real^N->bool` THEN DISCH_TAC THEN
  2.1509 -    ASM_CASES_TAC `s:real^N->bool = {}` THEN
  2.1510 -    ASM_REWRITE_TAC[FRONTIER_EMPTY; NEGLIGIBLE_EMPTY] THEN
  2.1511 -    FIRST_X_ASSUM(MP_TAC o GEN_REWRITE_RULE I [GSYM MEMBER_NOT_EMPTY]) THEN
  2.1512 -    DISCH_THEN(X_CHOOSE_TAC `a:real^N`) THEN
  2.1513 -    FIRST_X_ASSUM(MP_TAC o SPEC `IMAGE (\<lambda>x:real^N. --a + x) s`) THEN
  2.1514 -    ASM_SIMP_TAC[CONVEX_TRANSLATION; IN_IMAGE] THEN
  2.1515 -    ASM_REWRITE_TAC[UNWIND_THM2;
  2.1516 -                    VECTOR_ARITH `0:real^N = --a + x \<longleftrightarrow> x = a`] THEN
  2.1517 -    REWRITE_TAC[FRONTIER_TRANSLATION; NEGLIGIBLE_TRANSLATION_EQ]] THEN
  2.1518 -  REPEAT STRIP_TAC THEN MP_TAC(ISPEC `s:real^N->bool` DIM_SUBSET_UNIV) THEN
  2.1519 -  REWRITE_TAC[ARITH_RULE `d:num \<le> e \<longleftrightarrow> d < e \/ d = e`] THEN STRIP_TAC THENL
  2.1520 -   [MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.1521 -    EXISTS_TAC `closure s:real^N->bool` THEN
  2.1522 -    REWRITE_TAC[frontier; SUBSET_DIFF] THEN
  2.1523 -    MATCH_MP_TAC NEGLIGIBLE_LOWDIM THEN ASM_REWRITE_TAC[DIM_CLOSURE];
  2.1524 -    ALL_TAC] THEN
  2.1525 -  SUBGOAL_THEN `?a:real^N. a \<in> interior s` CHOOSE_TAC THENL
  2.1526 -   [X_CHOOSE_THEN `b:real^N->bool` STRIP_ASSUME_TAC
  2.1527 -     (ISPEC `s:real^N->bool` BASIS_EXISTS) THEN
  2.1528 -    FIRST_X_ASSUM SUBST_ALL_TAC THEN
  2.1529 -    MP_TAC(ISPEC `b:real^N->bool` INTERIOR_SIMPLEX_NONEMPTY) THEN
  2.1530 -    ASM_REWRITE_TAC[] THEN
  2.1531 -    MATCH_MP_TAC MONO_EXISTS THEN REWRITE_TAC[GSYM SUBSET] THEN
  2.1532 -    MATCH_MP_TAC SUBSET_INTERIOR THEN MATCH_MP_TAC HULL_MINIMAL THEN
  2.1533 -    ASM_REWRITE_TAC[INSERT_SUBSET];
  2.1534 -    ALL_TAC] THEN
  2.1535 -  MATCH_MP_TAC STARLIKE_NEGLIGIBLE_STRONG THEN
  2.1536 -  EXISTS_TAC `a:real^N` THEN REWRITE_TAC[FRONTIER_CLOSED] THEN
  2.1537 -  REPEAT GEN_TAC THEN STRIP_TAC THEN
  2.1538 -  REWRITE_TAC[frontier; IN_DIFF; DE_MORGAN_THM] THEN DISJ2_TAC THEN
  2.1539 -  SIMP_TAC[VECTOR_ARITH
  2.1540 -   `a + c % x:real^N = (a + x) - (1 - c) % ((a + x) - a)`] THEN
  2.1541 -  MATCH_MP_TAC IN_INTERIOR_CLOSURE_CONVEX_SHRINK THEN
  2.1542 -  RULE_ASSUM_TAC(REWRITE_RULE[frontier; IN_DIFF]) THEN
  2.1543 -  ASM_REWRITE_TAC[] THEN ASM_REAL_ARITH_TAC);; *)
  2.1544 -
  2.1545 -lemma GMEASURABLE_CONVEX: True .. (*
  2.1546 - "!s:real^N->bool. convex s \<and> bounded s ==> gmeasurable s"
  2.1547 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC GMEASURABLE_JORDAN THEN
  2.1548 -  ASM_SIMP_TAC[NEGLIGIBLE_CONVEX_FRONTIER]);; *)
  2.1549 -
  2.1550 -(* ------------------------------------------------------------------------- *)
  2.1551 -(* Various special cases.                                                    *)
  2.1552 -(* ------------------------------------------------------------------------- *)
  2.1553 -
  2.1554 -lemma NEGLIGIBLE_SPHERE: True .. (*
  2.1555 - "!a r. negligible {x:real^N | dist(a,x) = r}"
  2.1556 -qed   REWRITE_TAC[GSYM FRONTIER_CBALL] THEN
  2.1557 -  SIMP_TAC[NEGLIGIBLE_CONVEX_FRONTIER; CONVEX_CBALL]);; *)
  2.1558 -
  2.1559 -lemma GMEASURABLE_BALL: True .. (*
  2.1560 - "!a r. gmeasurable(ball(a,r))"
  2.1561 -qed   SIMP_TAC[MEASURABLE_OPEN; BOUNDED_BALL; OPEN_BALL]);; *)
  2.1562 -
  2.1563 -lemma GMEASURABLE_CBALL: True .. (*
  2.1564 - "!a r. gmeasurable(cball(a,r))"
  2.1565 -qed   SIMP_TAC[MEASURABLE_COMPACT; COMPACT_CBALL]);; *)
  2.1566 -
  2.1567 -(* ------------------------------------------------------------------------- *)
  2.1568 -(* Negligibility of image under non-injective linear map.                    *)
  2.1569 -(* ------------------------------------------------------------------------- *)
  2.1570 -
  2.1571 -lemma NEGLIGIBLE_LINEAR_SINGULAR_IMAGE: True .. (*
  2.1572 - "!f:real^N->real^N s.
  2.1573 -        linear f \<and> ~(!x y. f(x) = f(y) ==> x = y)
  2.1574 -        ==> negligible(IMAGE f s)"
  2.1575 -qed   REPEAT GEN_TAC THEN
  2.1576 -  DISCH_THEN(MP_TAC o MATCH_MP LINEAR_SINGULAR_IMAGE_HYPERPLANE) THEN
  2.1577 -  DISCH_THEN(X_CHOOSE_THEN `a:real^N` STRIP_ASSUME_TAC) THEN
  2.1578 -  MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.1579 -  EXISTS_TAC `{x:real^N | a dot x = 0}` THEN
  2.1580 -  ASM_SIMP_TAC[NEGLIGIBLE_HYPERPLANE]);; *)
  2.1581 -
  2.1582 -(* ------------------------------------------------------------------------- *)
  2.1583 -(* Approximation of gmeasurable set by union of intervals.                    *)
  2.1584 -(* ------------------------------------------------------------------------- *)
  2.1585 -
  2.1586 -lemma COVERING_LEMMA: True .. (*
  2.1587 - "!a b:real^N s g.
  2.1588 -        s \<subseteq> {a..b} \<and> ~({a<..<b} = {}) \<and> gauge g
  2.1589 -        ==> ?d. COUNTABLE d \<and>
  2.1590 -                (!k. k \<in> d ==> k \<subseteq> {a..b} \<and> ~(k = {}) \<and>
  2.1591 -                                (\<exists>c d. k = {c..d})) \<and>
  2.1592 -                (!k1 k2. k1 \<in> d \<and> k2 \<in> d \<and> ~(k1 = k2)
  2.1593 -                         ==> interior k1 \<inter> interior k2 = {}) \<and>
  2.1594 -                (!k. k \<in> d ==> ?x. x \<in> (s \<inter> k) \<and> k \<subseteq> g(x)) \<and>
  2.1595 -                s \<subseteq> \<Union>d"
  2.1596 -qed   REPEAT STRIP_TAC THEN
  2.1597 -  SUBGOAL_THEN
  2.1598 -   `?d. COUNTABLE d \<and>
  2.1599 -        (!k. k \<in> d ==> k \<subseteq> {a..b} \<and> ~(k = {}) \<and>
  2.1600 -                        (\<exists>c d:real^N. k = {c..d})) \<and>
  2.1601 -        (!k1 k2. k1 \<in> d \<and> k2 \<in> d
  2.1602 -                 ==> k1 \<subseteq> k2 \/ k2 \<subseteq> k1 \/
  2.1603 -                     interior k1 \<inter> interior k2 = {}) \<and>
  2.1604 -        (!x. x \<in> s ==> ?k. k \<in> d \<and> x \<in> k \<and> k \<subseteq> g(x)) \<and>
  2.1605 -        (!k. k \<in> d ==> FINITE {l | l \<in> d \<and> k \<subseteq> l})`
  2.1606 -  ASSUME_TAC THENL
  2.1607 -   [EXISTS_TAC
  2.1608 -     `IMAGE (\<lambda>(n,v).
  2.1609 -             interval[(lambda i. a$i + (v$i) / 2 pow n *
  2.1610 -                                       ((b:real^N)$i - (a:real^N)$i)):real^N,
  2.1611 -                      (lambda i. a$i + ((v$i) + 1) / 2 pow n * (b$i - a$i))])
  2.1612 -            {n,v | n \<in> (:num) \<and>
  2.1613 -                   v \<in> {v:num^N | !i. 1 \<le> i \<and> i \<le> dimindex(:N)
  2.1614 -                                       ==> v$i < 2 EXP n}}` THEN
  2.1615 -    CONJ_TAC THENL
  2.1616 -     [MATCH_MP_TAC COUNTABLE_IMAGE THEN
  2.1617 -      MATCH_MP_TAC COUNTABLE_PRODUCT_DEPENDENT THEN
  2.1618 -      REWRITE_TAC[NUM_COUNTABLE; IN_UNIV] THEN
  2.1619 -      GEN_TAC THEN MATCH_MP_TAC FINITE_IMP_COUNTABLE THEN
  2.1620 -      MATCH_MP_TAC FINITE_CART THEN REWRITE_TAC[FINITE_NUMSEG_LT];
  2.1621 -      ALL_TAC] THEN
  2.1622 -    CONJ_TAC THENL
  2.1623 -     [REWRITE_TAC[FORALL_IN_IMAGE; FORALL_PAIR_THM] THEN
  2.1624 -      MAP_EVERY X_GEN_TAC [`n:num`; `v:num^N`] THEN
  2.1625 -      REWRITE_TAC[IN_ELIM_PAIR_THM] THEN
  2.1626 -      REWRITE_TAC[IN_ELIM_THM; IN_UNIV] THEN DISCH_TAC THEN
  2.1627 -      REWRITE_TAC[CONJ_ASSOC] THEN CONJ_TAC THENL [ALL_TAC; MESON_TAC[]] THEN
  2.1628 -      SIMP_TAC[INTERVAL_NE_EMPTY; SUBSET_INTERVAL; LAMBDA_BETA] THEN
  2.1629 -      REWRITE_TAC[REAL_LE_LADD; REAL_LE_ADDR; REAL_ARITH
  2.1630 -        `a + x * (b - a) \<le> b \<longleftrightarrow> 0 \<le> (1 - x) * (b - a)`] THEN
  2.1631 -      RULE_ASSUM_TAC(REWRITE_RULE[INTERVAL_NE_EMPTY]) THEN
  2.1632 -      REPEAT STRIP_TAC THEN
  2.1633 -      (MATCH_MP_TAC REAL_LE_MUL ORELSE MATCH_MP_TAC REAL_LE_RMUL) THEN
  2.1634 -      ASM_SIMP_TAC[REAL_SUB_LE; REAL_LE_DIV2_EQ; REAL_LT_POW2] THEN
  2.1635 -      ASM_SIMP_TAC[REAL_LE_LDIV_EQ; REAL_LE_RDIV_EQ; REAL_LT_POW2] THEN
  2.1636 -      REWRITE_TAC[REAL_MUL_LZERO; REAL_POS; REAL_MUL_LID; REAL_LE_ADDR] THEN
  2.1637 -      SIMP_TAC[REAL_OF_NUM_ADD; REAL_OF_NUM_POW; REAL_OF_NUM_LE] THEN
  2.1638 -      ASM_SIMP_TAC[ARITH_RULE `x + 1 \<le> y \<longleftrightarrow> x < y`; REAL_LT_IMP_LE];
  2.1639 -      ALL_TAC] THEN
  2.1640 -    CONJ_TAC THENL
  2.1641 -     [ONCE_REWRITE_TAC[IMP_CONJ] THEN
  2.1642 -      REWRITE_TAC[FORALL_IN_IMAGE; FORALL_PAIR_THM; RIGHT_FORALL_IMP_THM] THEN
  2.1643 -      REWRITE_TAC[IN_ELIM_PAIR_THM; IN_UNIV] THEN REWRITE_TAC[IN_ELIM_THM] THEN
  2.1644 -      REWRITE_TAC[RIGHT_IMP_FORALL_THM] THEN
  2.1645 -      GEN_REWRITE_TAC BINDER_CONV [SWAP_FORALL_THM] THEN
  2.1646 -      MATCH_MP_TAC WLOG_LE THEN CONJ_TAC THENL
  2.1647 -       [REPEAT GEN_TAC THEN
  2.1648 -        GEN_REWRITE_TAC RAND_CONV [SWAP_FORALL_THM] THEN
  2.1649 -        REPEAT(AP_TERM_TAC THEN ABS_TAC) THEN SET_TAC[];
  2.1650 -        ALL_TAC] THEN
  2.1651 -      MAP_EVERY X_GEN_TAC [`m:num`; `n:num`] THEN DISCH_TAC THEN
  2.1652 -      MAP_EVERY X_GEN_TAC [`v:num^N`; `w:num^N`] THEN REPEAT DISCH_TAC THEN
  2.1653 -      REWRITE_TAC[INTERIOR_CLOSED_INTERVAL; SUBSET_INTERVAL] THEN
  2.1654 -      SIMP_TAC[DISJOINT_INTERVAL; LAMBDA_BETA] THEN
  2.1655 -      MATCH_MP_TAC(TAUT `p \/ q \/ r ==> (a ==> p) \/ (b ==> q) \/ r`) THEN
  2.1656 -      ONCE_REWRITE_TAC[TAUT `a \<and> b \<and> c \<longleftrightarrow> ~(a \<and> b ==> ~c)`] THEN
  2.1657 -      RULE_ASSUM_TAC(REWRITE_RULE[INTERVAL_NE_EMPTY]) THEN
  2.1658 -      ASM_SIMP_TAC[REAL_LE_LADD; REAL_LE_RMUL_EQ; REAL_SUB_LT; LAMBDA_BETA] THEN
  2.1659 -      REWRITE_TAC[NOT_IMP; REAL_LE_LADD] THEN
  2.1660 -      ASM_SIMP_TAC[REAL_LE_DIV2_EQ; REAL_LT_POW2] THEN
  2.1661 -      REWRITE_TAC[REAL_ARITH `~(x + 1 \<le> x)`] THEN DISJ2_TAC THEN
  2.1662 -      MATCH_MP_TAC(MESON[]
  2.1663 -       `(!i. ~P i ==> Q i) ==> (!i. Q i) \/ (\<exists>i. P i)`) THEN
  2.1664 -      X_GEN_TAC `i:num` THEN
  2.1665 -      DISCH_THEN(fun th -> STRIP_TAC THEN MP_TAC th) THEN
  2.1666 -      ASM_REWRITE_TAC[DE_MORGAN_THM; REAL_NOT_LE] THEN
  2.1667 -      UNDISCH_TAC `m:num \<le> n` THEN REWRITE_TAC[LE_EXISTS] THEN
  2.1668 -      DISCH_THEN(X_CHOOSE_THEN `p:num` SUBST1_TAC) THEN
  2.1669 -      ONCE_REWRITE_TAC[ADD_SYM] THEN
  2.1670 -      REWRITE_TAC[REAL_POW_ADD; real_div; REAL_INV_MUL] THEN
  2.1671 -      REWRITE_TAC[REAL_MUL_ASSOC] THEN REWRITE_TAC[GSYM real_div] THEN
  2.1672 -      ASM_SIMP_TAC[REAL_LE_DIV2_EQ; REAL_LT_POW2; REAL_LT_DIV2_EQ] THEN
  2.1673 -      ASM_SIMP_TAC[REAL_LE_LDIV_EQ; REAL_LE_RDIV_EQ; REAL_LT_POW2;
  2.1674 -                   REAL_LT_LDIV_EQ; REAL_LT_RDIV_EQ] THEN
  2.1675 -      SIMP_TAC[REAL_LT_INTEGERS; INTEGER_CLOSED] THEN REAL_ARITH_TAC;
  2.1676 -      ALL_TAC] THEN
  2.1677 -    CONJ_TAC THENL
  2.1678 -     [X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN
  2.1679 -      SUBGOAL_THEN
  2.1680 -        `?e. 0 < e \<and> !y. (!i. 1 \<le> i \<and> i \<le> dimindex(:N)
  2.1681 -                                ==> abs((x:real^N)$i - (y:real^N)$i) \<le> e)
  2.1682 -                           ==> y \<in> g(x)`
  2.1683 -      STRIP_ASSUME_TAC THENL
  2.1684 -       [FIRST_ASSUM(MP_TAC o SPEC `x:real^N` o GEN_REWRITE_RULE I [gauge]) THEN
  2.1685 -        STRIP_TAC THEN
  2.1686 -        FIRST_ASSUM(MP_TAC o GEN_REWRITE_RULE I [OPEN_CONTAINS_BALL]) THEN
  2.1687 -        DISCH_THEN(MP_TAC o SPEC `x:real^N`) THEN ASM_REWRITE_TAC[] THEN
  2.1688 -        DISCH_THEN(X_CHOOSE_THEN `e:real` STRIP_ASSUME_TAC) THEN
  2.1689 -        EXISTS_TAC `e / 2 / (dimindex(:N))` THEN
  2.1690 -        ASM_SIMP_TAC[REAL_LT_DIV; REAL_OF_NUM_LT; LE_1; DIMINDEX_GE_1;
  2.1691 -                     ARITH] THEN
  2.1692 -        X_GEN_TAC `y:real^N` THEN STRIP_TAC THEN
  2.1693 -        MATCH_MP_TAC(SET_RULE `!s. s \<subseteq> t \<and> x \<in> s ==> x \<in> t`) THEN
  2.1694 -        EXISTS_TAC `ball(x:real^N,e)` THEN ASM_REWRITE_TAC[IN_BALL] THEN
  2.1695 -        MATCH_MP_TAC(REAL_ARITH `0 < e \<and> x \<le> e / 2 ==> x < e`) THEN
  2.1696 -        ASM_REWRITE_TAC[dist] THEN MATCH_MP_TAC REAL_LE_TRANS THEN
  2.1697 -        EXISTS_TAC `sum(1..dimindex(:N)) (\<lambda>i. abs((x - y:real^N)$i))` THEN
  2.1698 -        REWRITE_TAC[NORM_LE_L1] THEN MATCH_MP_TAC SUM_BOUND_GEN THEN
  2.1699 -        ASM_SIMP_TAC[IN_NUMSEG; FINITE_NUMSEG; NUMSEG_EMPTY; NOT_LT;
  2.1700 -                     DIMINDEX_GE_1; VECTOR_SUB_COMPONENT; CARD_NUMSEG_1];
  2.1701 -        ALL_TAC] THEN
  2.1702 -      REWRITE_TAC[EXISTS_IN_IMAGE; EXISTS_PAIR_THM; IN_ELIM_PAIR_THM] THEN
  2.1703 -      MP_TAC(SPECL [`1 / 2`; `e / norm(b - a:real^N)`]
  2.1704 -        REAL_ARCH_POW_INV) THEN
  2.1705 -      SUBGOAL_THEN `0 < norm(b - a:real^N)` ASSUME_TAC THENL
  2.1706 -       [ASM_MESON_TAC[VECTOR_SUB_EQ; NORM_POS_LT; INTERVAL_SING]; ALL_TAC] THEN
  2.1707 -      CONV_TAC REAL_RAT_REDUCE_CONV THEN ASM_SIMP_TAC[REAL_LT_DIV] THEN
  2.1708 -      MATCH_MP_TAC MONO_EXISTS THEN X_GEN_TAC `n:num` THEN
  2.1709 -      REWRITE_TAC[real_div; REAL_MUL_LID; REAL_POW_INV] THEN DISCH_TAC THEN
  2.1710 -      SIMP_TAC[IN_ELIM_THM; IN_INTERVAL; SUBSET; LAMBDA_BETA] THEN
  2.1711 -      MATCH_MP_TAC(MESON[]
  2.1712 -       `(!x. Q x ==> R x) \<and> (\<exists>x. P x \<and> Q x) ==> ?x. P x \<and> Q x \<and> R x`) THEN
  2.1713 -      CONJ_TAC THENL
  2.1714 -       [REWRITE_TAC[RIGHT_IMP_FORALL_THM] THEN
  2.1715 -        MAP_EVERY X_GEN_TAC [`w:num^N`; `y:real^N`] THEN
  2.1716 -        REWRITE_TAC[IMP_IMP; AND_FORALL_THM] THEN
  2.1717 -        DISCH_THEN(fun th -> FIRST_X_ASSUM MATCH_MP_TAC THEN MP_TAC th) THEN
  2.1718 -        MATCH_MP_TAC MONO_FORALL THEN X_GEN_TAC `i:num` THEN
  2.1719 -        DISCH_THEN(fun th -> STRIP_TAC THEN MP_TAC th) THEN
  2.1720 -        ASM_REWRITE_TAC[] THEN DISCH_THEN(MP_TAC o MATCH_MP (REAL_ARITH
  2.1721 -         `(a + n \<le> x \<and> x \<le> a + m) \<and>
  2.1722 -          (a + n \<le> y \<and> y \<le> a + m) ==> abs(x - y) \<le> m - n`)) THEN
  2.1723 -        MATCH_MP_TAC(REAL_ARITH
  2.1724 -         `y * z \<le> e
  2.1725 -          ==> a \<le> ((x + 1) * y) * z - ((x * y) * z) ==> a \<le> e`) THEN
  2.1726 -        RULE_ASSUM_TAC(REWRITE_RULE[INTERVAL_NE_EMPTY]) THEN
  2.1727 -        ASM_SIMP_TAC[GSYM REAL_LE_RDIV_EQ; REAL_SUB_LT] THEN
  2.1728 -        FIRST_X_ASSUM(MATCH_MP_TAC o MATCH_MP
  2.1729 -        (REAL_ARITH `n < e * x ==> 0 \<le> e * (inv y - x) ==> n \<le> e / y`)) THEN
  2.1730 -        MATCH_MP_TAC REAL_LE_MUL THEN ASM_SIMP_TAC[REAL_LT_IMP_LE] THEN
  2.1731 -        REWRITE_TAC[REAL_SUB_LE] THEN MATCH_MP_TAC REAL_LE_INV2 THEN
  2.1732 -        ASM_SIMP_TAC[REAL_SUB_LT] THEN
  2.1733 -        MP_TAC(SPECL [`b - a:real^N`; `i:num`] COMPONENT_LE_NORM) THEN
  2.1734 -        ASM_SIMP_TAC[VECTOR_SUB_COMPONENT] THEN REAL_ARITH_TAC;
  2.1735 -        ALL_TAC] THEN
  2.1736 -      REWRITE_TAC[IN_UNIV; AND_FORALL_THM] THEN
  2.1737 -      REWRITE_TAC[TAUT `(a ==> c) \<and> (a ==> b) \<longleftrightarrow> a ==> b \<and> c`] THEN
  2.1738 -      REWRITE_TAC[GSYM LAMBDA_SKOLEM] THEN X_GEN_TAC `i:num` THEN
  2.1739 -      STRIP_TAC THEN
  2.1740 -      SUBGOAL_THEN `(x:real^N) \<in> {a..b}` MP_TAC THENL
  2.1741 -       [ASM SET_TAC[]; ALL_TAC] THEN REWRITE_TAC[IN_INTERVAL] THEN
  2.1742 -      DISCH_THEN(MP_TAC o SPEC `i:num`) THEN ASM_REWRITE_TAC[] THEN
  2.1743 -      RULE_ASSUM_TAC(REWRITE_RULE[INTERVAL_NE_EMPTY]) THEN STRIP_TAC THEN
  2.1744 -      DISJ_CASES_TAC(MATCH_MP (REAL_ARITH `x \<le> y ==> x = y \/ x < y`)
  2.1745 -       (ASSUME `(x:real^N)$i \<le> (b:real^N)$i`))
  2.1746 -      THENL
  2.1747 -       [EXISTS_TAC `2 EXP n - 1` THEN
  2.1748 -        SIMP_TAC[GSYM REAL_OF_NUM_SUB; GSYM REAL_OF_NUM_LT;
  2.1749 -                 EXP_LT_0; LE_1; ARITH] THEN
  2.1750 -        ASM_REWRITE_TAC[REAL_SUB_ADD; REAL_ARITH `a - 1 < a`] THEN
  2.1751 -        MATCH_MP_TAC(REAL_ARITH
  2.1752 -         `1 * (b - a) = x \<and> y \<le> x ==> a + y \<le> b \<and> b \<le> a + x`) THEN
  2.1753 -        ASM_SIMP_TAC[REAL_EQ_MUL_RCANCEL; REAL_LT_IMP_NZ; REAL_LE_RMUL_EQ;
  2.1754 -                     REAL_SUB_LT; REAL_LT_INV_EQ; REAL_LT_POW2] THEN
  2.1755 -        SIMP_TAC[GSYM REAL_OF_NUM_POW; REAL_MUL_RINV; REAL_POW_EQ_0;
  2.1756 -                 REAL_OF_NUM_EQ; ARITH_EQ] THEN REAL_ARITH_TAC;
  2.1757 -        ALL_TAC] THEN
  2.1758 -      MP_TAC(SPEC `2 pow n * ((x:real^N)$i - (a:real^N)$i) /
  2.1759 -                              ((b:real^N)$i - (a:real^N)$i)` FLOOR_POS) THEN
  2.1760 -      ANTS_TAC THENL
  2.1761 -       [ASM_MESON_TAC[REAL_LE_MUL; REAL_LE_MUL; REAL_POW_LE; REAL_POS;
  2.1762 -                      REAL_SUB_LE; REAL_LT_IMP_LE; REAL_LE_DIV];
  2.1763 -        ALL_TAC] THEN
  2.1764 -      MATCH_MP_TAC MONO_EXISTS THEN X_GEN_TAC `m:num` THEN
  2.1765 -      REWRITE_TAC[GSYM REAL_OF_NUM_LT; GSYM REAL_OF_NUM_POW] THEN
  2.1766 -      DISCH_THEN(SUBST_ALL_TAC o SYM) THEN
  2.1767 -      REWRITE_TAC[REAL_ARITH `a + b * c \<le> x \<and> x \<le> a + b' * c \<longleftrightarrow>
  2.1768 -                              b * c \<le> x - a \<and> x - a \<le> b' * c`] THEN
  2.1769 -      ASM_SIMP_TAC[GSYM REAL_LE_LDIV_EQ; GSYM REAL_LE_RDIV_EQ;
  2.1770 -                   REAL_SUB_LT; GSYM real_div] THEN
  2.1771 -      ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN
  2.1772 -      SIMP_TAC[REAL_LE_LDIV_EQ; REAL_LE_RDIV_EQ; REAL_LT_POW2] THEN
  2.1773 -      SIMP_TAC[FLOOR; REAL_LT_IMP_LE] THEN MATCH_MP_TAC REAL_LET_TRANS THEN
  2.1774 -      EXISTS_TAC `((x:real^N)$i - (a:real^N)$i) /
  2.1775 -                  ((b:real^N)$i - (a:real^N)$i) *
  2.1776 -                  2 pow n` THEN
  2.1777 -      REWRITE_TAC[FLOOR] THEN GEN_REWRITE_TAC RAND_CONV [GSYM REAL_MUL_LID] THEN
  2.1778 -      ASM_SIMP_TAC[REAL_LT_RMUL_EQ; REAL_LT_POW2] THEN
  2.1779 -      ASM_SIMP_TAC[REAL_LT_LDIV_EQ; REAL_MUL_LID; REAL_SUB_LT] THEN
  2.1780 -      ASM_REAL_ARITH_TAC;
  2.1781 -      ALL_TAC] THEN
  2.1782 -    REWRITE_TAC[FORALL_IN_IMAGE; FORALL_PAIR_THM; IN_ELIM_PAIR_THM] THEN
  2.1783 -    MAP_EVERY X_GEN_TAC [`n:num`; `v:num^N`] THEN
  2.1784 -    REWRITE_TAC[IN_ELIM_THM; IN_UNIV] THEN DISCH_TAC THEN
  2.1785 -    MATCH_MP_TAC FINITE_SUBSET THEN EXISTS_TAC
  2.1786 -     `IMAGE (\<lambda>(n,v).
  2.1787 -            interval[(lambda i. a$i + (v$i) / 2 pow n *
  2.1788 -                                      ((b:real^N)$i - (a:real^N)$i)):real^N,
  2.1789 -                     (lambda i. a$i + ((v$i) + 1) / 2 pow n * (b$i - a$i))])
  2.1790 -            {m,v | m \<in> 0..n \<and>
  2.1791 -                   v \<in> {v:num^N | !i. 1 \<le> i \<and> i \<le> dimindex(:N)
  2.1792 -                                       ==> v$i < 2 EXP m}}` THEN
  2.1793 -    CONJ_TAC THENL
  2.1794 -     [MATCH_MP_TAC FINITE_IMAGE THEN
  2.1795 -      MATCH_MP_TAC FINITE_PRODUCT_DEPENDENT THEN
  2.1796 -      REWRITE_TAC[FINITE_NUMSEG] THEN REPEAT STRIP_TAC THEN
  2.1797 -      MATCH_MP_TAC FINITE_CART THEN REWRITE_TAC[FINITE_NUMSEG_LT];
  2.1798 -      ALL_TAC] THEN
  2.1799 -    GEN_REWRITE_TAC I [SUBSET] THEN
  2.1800 -    REWRITE_TAC[IN_ELIM_THM] THEN ONCE_REWRITE_TAC[IMP_CONJ] THEN
  2.1801 -    REWRITE_TAC[FORALL_IN_IMAGE; FORALL_PAIR_THM; IN_ELIM_PAIR_THM] THEN
  2.1802 -    MAP_EVERY X_GEN_TAC [`m:num`; `w:num^N`] THEN DISCH_TAC THEN
  2.1803 -    DISCH_TAC THEN SIMP_TAC[IN_IMAGE; EXISTS_PAIR_THM; IN_ELIM_PAIR_THM] THEN
  2.1804 -    MAP_EVERY EXISTS_TAC [`m:num`; `w:num^N`] THEN ASM_REWRITE_TAC[] THEN
  2.1805 -    REWRITE_TAC[IN_NUMSEG; GSYM NOT_LT; LT] THEN DISCH_TAC THEN
  2.1806 -    FIRST_X_ASSUM(MP_TAC o GEN_REWRITE_RULE I [SUBSET_INTERVAL]) THEN
  2.1807 -    SIMP_TAC[NOT_IMP; LAMBDA_BETA] THEN
  2.1808 -    RULE_ASSUM_TAC(REWRITE_RULE[INTERVAL_NE_EMPTY]) THEN
  2.1809 -    ASM_SIMP_TAC[REAL_LE_LADD; REAL_LE_RMUL_EQ; REAL_SUB_LT] THEN
  2.1810 -    ASM_SIMP_TAC[REAL_LE_DIV2_EQ; REAL_LT_POW2] THEN
  2.1811 -    REWRITE_TAC[REAL_ARITH `x \<le> x + 1`] THEN
  2.1812 -    DISCH_THEN(MP_TAC o SPEC `1`) THEN
  2.1813 -    REWRITE_TAC[LE_REFL; DIMINDEX_GE_1] THEN
  2.1814 -    DISCH_THEN(MP_TAC o MATCH_MP (REAL_ARITH
  2.1815 -     `w / m \<le> v / n \<and> (v + 1) / n \<le> (w + 1) / m
  2.1816 -      ==> inv n \<le> inv m`)) THEN
  2.1817 -    REWRITE_TAC[REAL_NOT_LE] THEN MATCH_MP_TAC REAL_LT_INV2 THEN
  2.1818 -    ASM_REWRITE_TAC[REAL_LT_POW2] THEN MATCH_MP_TAC REAL_POW_MONO_LT THEN
  2.1819 -    ASM_REWRITE_TAC[] THEN CONV_TAC REAL_RAT_REDUCE_CONV;
  2.1820 -    ALL_TAC] THEN
  2.1821 -  SUBGOAL_THEN
  2.1822 -   `?d. COUNTABLE d \<and>
  2.1823 -        (!k. k \<in> d ==> k \<subseteq> {a..b} \<and> ~(k = {}) \<and>
  2.1824 -                        (\<exists>c d:real^N. k = {c..d})) \<and>
  2.1825 -        (!k1 k2. k1 \<in> d \<and> k2 \<in> d
  2.1826 -                 ==> k1 \<subseteq> k2 \/ k2 \<subseteq> k1 \/
  2.1827 -                     interior k1 \<inter> interior k2 = {}) \<and>
  2.1828 -        (!k. k \<in> d ==> (\<exists>x. x \<in> s \<inter> k \<and> k \<subseteq> g x)) \<and>
  2.1829 -        (!k. k \<in> d ==> FINITE {l | l \<in> d \<and> k \<subseteq> l}) \<and>
  2.1830 -        s \<subseteq> \<Union>d`
  2.1831 -  MP_TAC THENL
  2.1832 -   [FIRST_X_ASSUM(X_CHOOSE_THEN `d:(real^N->bool)->bool` STRIP_ASSUME_TAC) THEN
  2.1833 -    EXISTS_TAC
  2.1834 -     `{k:real^N->bool | k \<in> d \<and> ?x. x \<in> (s \<inter> k) \<and> k \<subseteq> g x}` THEN
  2.1835 -    ASM_SIMP_TAC[IN_ELIM_THM] THEN REPEAT CONJ_TAC THENL
  2.1836 -     [MATCH_MP_TAC COUNTABLE_SUBSET THEN
  2.1837 -      EXISTS_TAC `d:(real^N->bool)->bool` THEN
  2.1838 -      ASM_REWRITE_TAC[] THEN SET_TAC[];
  2.1839 -      X_GEN_TAC `k:real^N->bool` THEN REPEAT STRIP_TAC THEN
  2.1840 -      MATCH_MP_TAC FINITE_SUBSET THEN
  2.1841 -      EXISTS_TAC `{l:real^N->bool | l \<in> d \<and> k \<subseteq> l}` THEN
  2.1842 -      ASM_REWRITE_TAC[] THEN SET_TAC[];
  2.1843 -      ASM SET_TAC[]];
  2.1844 -    ALL_TAC] THEN
  2.1845 -  DISCH_THEN(X_CHOOSE_THEN `d:(real^N->bool)->bool` STRIP_ASSUME_TAC) THEN
  2.1846 -  EXISTS_TAC
  2.1847 -   `{k:real^N->bool | k \<in> d \<and> !k'. k' \<in> d \<and> ~(k = k')
  2.1848 -                                     ==> ~(k \<subseteq> k')}` THEN
  2.1849 -  ASM_SIMP_TAC[IN_ELIM_THM] THEN REPEAT CONJ_TAC THENL
  2.1850 -   [MATCH_MP_TAC COUNTABLE_SUBSET THEN EXISTS_TAC `d:(real^N->bool)->bool` THEN
  2.1851 -    ASM_REWRITE_TAC[] THEN SET_TAC[];
  2.1852 -    ASM SET_TAC[];
  2.1853 -    ALL_TAC] THEN
  2.1854 -  FIRST_X_ASSUM(MATCH_MP_TAC o MATCH_MP
  2.1855 -   (REWRITE_RULE[IMP_CONJ] SUBSET_TRANS)) THEN
  2.1856 -  GEN_REWRITE_TAC I [SUBSET] THEN REWRITE_TAC[FORALL_IN_UNIONS] THEN
  2.1857 -  MAP_EVERY X_GEN_TAC [`k:real^N->bool`; `x:real^N`] THEN DISCH_TAC THEN
  2.1858 -  REWRITE_TAC[IN_UNIONS; IN_ELIM_THM] THEN
  2.1859 -  MP_TAC(ISPEC `\k l:real^N->bool. k \<in> d \<and> l \<in> d \<and> l \<subseteq> k \<and> ~(k = l)`
  2.1860 -     WF_FINITE) THEN
  2.1861 -  REWRITE_TAC[WF] THEN ANTS_TAC THENL
  2.1862 -   [CONJ_TAC THENL [SET_TAC[]; ALL_TAC] THEN X_GEN_TAC `l:real^N->bool` THEN
  2.1863 -    ASM_CASES_TAC `(l:real^N->bool) \<in> d` THEN
  2.1864 -    ASM_REWRITE_TAC[EMPTY_GSPEC; FINITE_RULES] THEN
  2.1865 -    MATCH_MP_TAC FINITE_SUBSET THEN
  2.1866 -    EXISTS_TAC `{m:real^N->bool | m \<in> d \<and> l \<subseteq> m}` THEN
  2.1867 -    ASM_SIMP_TAC[] THEN SET_TAC[];
  2.1868 -    ALL_TAC] THEN
  2.1869 -  DISCH_THEN(MP_TAC o SPEC `\l:real^N->bool. l \<in> d \<and> x \<in> l`) THEN
  2.1870 -  REWRITE_TAC[] THEN ANTS_TAC THENL [SET_TAC[]; ALL_TAC] THEN
  2.1871 -  MATCH_MP_TAC MONO_EXISTS THEN ASM SET_TAC[]);; *)
  2.1872 -
  2.1873 -lemma GMEASURABLE_OUTER_INTERVALS_BOUNDED: True .. (*
  2.1874 - "!s a b:real^N e.
  2.1875 -        gmeasurable s \<and> s \<subseteq> {a..b} \<and> 0 < e
  2.1876 -        ==> ?d. COUNTABLE d \<and>
  2.1877 -                (!k. k \<in> d ==> k \<subseteq> {a..b} \<and> ~(k = {}) \<and>
  2.1878 -                                (\<exists>c d. k = {c..d})) \<and>
  2.1879 -                (!k1 k2. k1 \<in> d \<and> k2 \<in> d \<and> ~(k1 = k2)
  2.1880 -                         ==> interior k1 \<inter> interior k2 = {}) \<and>
  2.1881 -                s \<subseteq> \<Union>d \<and>
  2.1882 -                gmeasurable (\<Union>d) \<and>
  2.1883 -                gmeasure (\<Union>d) \<le> gmeasure s + e"
  2.1884 -qed   lemma lemma = prove
  2.1885 -   (`(!x y. (x,y) \<in> IMAGE (\<lambda>z. f z,g z) s ==> P x y) \<longleftrightarrow>
  2.1886 -     (!z. z \<in> s ==> P (f z) (g z))"
  2.1887 -qed   REWRITE_TAC[IN_IMAGE; PAIR_EQ] THEN MESON_TAC[]) in
  2.1888 -  REPEAT GEN_TAC THEN
  2.1889 -  ASM_CASES_TAC `interval[a:real^N,b] = {}` THENL
  2.1890 -   [ASM_REWRITE_TAC[SUBSET_EMPTY] THEN STRIP_TAC THEN
  2.1891 -    EXISTS_TAC `{}:(real^N->bool)->bool` THEN
  2.1892 -    ASM_REWRITE_TAC[NOT_IN_EMPTY; UNIONS_0; MEASURE_EMPTY; REAL_ADD_LID;
  2.1893 -                    SUBSET_REFL; COUNTABLE_EMPTY; GMEASURABLE_EMPTY] THEN
  2.1894 -    ASM_SIMP_TAC[REAL_LT_IMP_LE];
  2.1895 -    ALL_TAC] THEN
  2.1896 -  STRIP_TAC THEN ASM_CASES_TAC `interval(a:real^N,b) = {}` THENL
  2.1897 -   [EXISTS_TAC `{interval[a:real^N,b]}` THEN
  2.1898 -    REWRITE_TAC[UNIONS_1; COUNTABLE_SING] THEN
  2.1899 -    ASM_REWRITE_TAC[IMP_CONJ; RIGHT_FORALL_IMP_THM; FORALL_IN_INSERT;
  2.1900 -                    NOT_IN_EMPTY; SUBSET_REFL; GMEASURABLE_INTERVAL] THEN
  2.1901 -    CONJ_TAC THENL [MESON_TAC[]; ALL_TAC] THEN
  2.1902 -    SUBGOAL_THEN
  2.1903 -     `measure(interval[a:real^N,b]) = 0 \<and> measure(s:real^N->bool) = 0`
  2.1904 -     (fun th -> ASM_SIMP_TAC[th; REAL_LT_IMP_LE; REAL_ADD_LID]) THEN
  2.1905 -    SUBGOAL_THEN
  2.1906 -      `interval[a:real^N,b] has_gmeasure 0 \<and> (s:real^N->bool) has_gmeasure 0`
  2.1907 -      (fun th -> MESON_TAC[th; MEASURE_UNIQUE]) THEN
  2.1908 -    REWRITE_TAC[HAS_GMEASURE_0] THEN
  2.1909 -    MATCH_MP_TAC(TAUT `a \<and> (a ==> b) ==> a \<and> b`) THEN CONJ_TAC THENL
  2.1910 -     [ASM_REWRITE_TAC[NEGLIGIBLE_INTERVAL];
  2.1911 -      ASM_MESON_TAC[NEGLIGIBLE_SUBSET]];
  2.1912 -    ALL_TAC] THEN
  2.1913 -  FIRST_ASSUM(MP_TAC o GEN_REWRITE_RULE I [measurable]) THEN
  2.1914 -  DISCH_THEN(X_CHOOSE_TAC `m:real`) THEN
  2.1915 -  FIRST_ASSUM(ASSUME_TAC o MATCH_MP MEASURE_UNIQUE) THEN
  2.1916 -  SUBGOAL_THEN
  2.1917 -   `((\<lambda>x:real^N. if x \<in> s then 1 else 0) has_integral (lift m))
  2.1918 -    {a..b}`
  2.1919 -  ASSUME_TAC THENL
  2.1920 -   [ONCE_REWRITE_TAC[GSYM HAS_INTEGRAL_RESTRICT_UNIV] THEN
  2.1921 -    FIRST_ASSUM(MP_TAC o GEN_REWRITE_RULE I [HAS_GMEASURE]) THEN
  2.1922 -    MATCH_MP_TAC(REWRITE_RULE[IMP_CONJ] HAS_INTEGRAL_EQ) THEN
  2.1923 -    ASM SET_TAC[];
  2.1924 -    ALL_TAC] THEN
  2.1925 -  FIRST_ASSUM(ASSUME_TAC o MATCH_MP HAS_INTEGRAL_INTEGRABLE) THEN
  2.1926 -  FIRST_ASSUM(MP_TAC o GEN_REWRITE_RULE I [has_integral]) THEN
  2.1927 -  DISCH_THEN(MP_TAC o SPEC `e:real`) THEN ASM_REWRITE_TAC[] THEN
  2.1928 -  DISCH_THEN(X_CHOOSE_THEN `g:real^N->real^N->bool` STRIP_ASSUME_TAC) THEN
  2.1929 -  MP_TAC(SPECL [`a:real^N`; `b:real^N`; `s:real^N->bool`;
  2.1930 -                `g:real^N->real^N->bool`] COVERING_LEMMA) THEN
  2.1931 -  ASM_REWRITE_TAC[] THEN MATCH_MP_TAC MONO_EXISTS THEN
  2.1932 -  X_GEN_TAC `d:(real^N->bool)->bool` THEN STRIP_TAC THEN ASM_REWRITE_TAC[] THEN
  2.1933 -  MP_TAC(ISPECL [`(\<lambda>x. if x \<in> s then 1 else 0):real^N->real^1`;
  2.1934 -                 `a:real^N`; `b:real^N`; `g:real^N->real^N->bool`;
  2.1935 -                 `e:real`]
  2.1936 -                HENSTOCK_LEMMA_PART1) THEN
  2.1937 -  ASM_REWRITE_TAC[] THEN
  2.1938 -  FIRST_ASSUM(SUBST1_TAC o MATCH_MP INTEGRAL_UNIQUE) THEN
  2.1939 -  ASM_REWRITE_TAC[] THEN DISCH_THEN(LABEL_TAC "*") THEN
  2.1940 -  SUBGOAL_THEN
  2.1941 -   `!k l:real^N->bool. k \<in> d \<and> l \<in> d \<and> ~(k = l)
  2.1942 -                       ==> negligible(k \<inter> l)`
  2.1943 -  ASSUME_TAC THENL
  2.1944 -   [REPEAT STRIP_TAC THEN
  2.1945 -    FIRST_X_ASSUM(MP_TAC o SPECL [`k:real^N->bool`; `l:real^N->bool`]) THEN
  2.1946 -    ASM_SIMP_TAC[] THEN
  2.1947 -    SUBGOAL_THEN
  2.1948 -     `?x y:real^N u v:real^N. k = {x..y} \<and> l = {u..v}`
  2.1949 -    MP_TAC THENL [ASM_MESON_TAC[SUBSET]; ALL_TAC] THEN
  2.1950 -    DISCH_THEN(REPEAT_TCL CHOOSE_THEN (CONJUNCTS_THEN SUBST_ALL_TAC)) THEN
  2.1951 -    REWRITE_TAC[INTERIOR_CLOSED_INTERVAL] THEN DISCH_TAC THEN
  2.1952 -    MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.1953 -    EXISTS_TAC `(interval[x:real^N,y] DIFF {x<..<y}) UNION
  2.1954 -                (interval[u:real^N,v] DIFF {u<..<v}) UNION
  2.1955 -                (interval (x,y) \<inter> interval (u,v))` THEN
  2.1956 -    CONJ_TAC THENL [ALL_TAC; SET_TAC[]] THEN
  2.1957 -    ASM_REWRITE_TAC[UNION_EMPTY] THEN
  2.1958 -    SIMP_TAC[NEGLIGIBLE_UNION; NEGLIGIBLE_FRONTIER_INTERVAL];
  2.1959 -    ALL_TAC] THEN
  2.1960 -  SUBGOAL_THEN
  2.1961 -   `!D. FINITE D \<and> D \<subseteq> d
  2.1962 -         ==> gmeasurable(\<Union>D :real^N->bool) \<and> measure(\<Union>D) \<le> m + e`
  2.1963 -  ASSUME_TAC THENL
  2.1964 -   [GEN_TAC THEN STRIP_TAC THEN
  2.1965 -    SUBGOAL_THEN
  2.1966 -     `?t:(real^N->bool)->real^N. !k. k \<in> D ==> t(k) \<in> (s \<inter> k) \<and>
  2.1967 -                                                k \<subseteq> (g(t k))`
  2.1968 -    (CHOOSE_THEN (LABEL_TAC "+")) THENL
  2.1969 -     [REWRITE_TAC[GSYM SKOLEM_THM] THEN ASM SET_TAC[]; ALL_TAC] THEN
  2.1970 -    REMOVE_THEN "*" (MP_TAC o SPEC
  2.1971 -     `IMAGE (\<lambda>k. (t:(real^N->bool)->real^N) k,k) D`) THEN
  2.1972 -    ASM_SIMP_TAC[VSUM_IMAGE; PAIR_EQ] THEN REWRITE_TAC[o_DEF] THEN
  2.1973 -    ANTS_TAC THENL
  2.1974 -     [REWRITE_TAC[tagged_partial_division_of; fine] THEN
  2.1975 -      ASM_SIMP_TAC[FINITE_IMAGE; FORALL_IN_IMAGE] THEN
  2.1976 -      REWRITE_TAC[lemma; RIGHT_FORALL_IMP_THM; IMP_CONJ; PAIR_EQ] THEN
  2.1977 -      ASM_SIMP_TAC[] THEN
  2.1978 -      CONJ_TAC THENL [ASM SET_TAC[]; ASM_MESON_TAC[SUBSET]];
  2.1979 -      ALL_TAC] THEN
  2.1980 -    USE_THEN "+" (MP_TAC o REWRITE_RULE[IN_INTER]) THEN
  2.1981 -    SIMP_TAC[] THEN DISCH_THEN(K ALL_TAC) THEN
  2.1982 -    ASM_SIMP_TAC[VSUM_SUB] THEN
  2.1983 -    SUBGOAL_THEN `D division_of (\<Union>D:real^N->bool)` ASSUME_TAC THENL
  2.1984 -     [REWRITE_TAC[division_of] THEN ASM SET_TAC[]; ALL_TAC] THEN
  2.1985 -    FIRST_ASSUM(ASSUME_TAC o MATCH_MP GMEASURABLE_ELEMENTARY) THEN
  2.1986 -    SUBGOAL_THEN `vsum D (\<lambda>k:real^N->bool. content k % 1) =
  2.1987 -                  lift(measure(\<Union>D))`
  2.1988 -    SUBST1_TAC THENL
  2.1989 -     [ONCE_REWRITE_TAC[GSYM _EQ] THEN
  2.1990 -      ASM_SIMP_TAC[LIFT_; _VSUM; o_DEF; _CMUL; _VEC] THEN
  2.1991 -      SIMP_TAC[REAL_MUL_RID; ETA_AX] THEN ASM_MESON_TAC[MEASURE_ELEMENTARY];
  2.1992 -      ALL_TAC] THEN
  2.1993 -    SUBGOAL_THEN
  2.1994 -     `vsum D (\<lambda>k. integral k (\<lambda>x:real^N. if x \<in> s then 1 else 0)) =
  2.1995 -      lift(sum D (\<lambda>k. measure(k \<inter> s)))`
  2.1996 -    SUBST1_TAC THENL
  2.1997 -     [ASM_SIMP_TAC[LIFT_SUM; o_DEF] THEN MATCH_MP_TAC VSUM_EQ THEN
  2.1998 -      X_GEN_TAC `k:real^N->bool` THEN DISCH_TAC THEN REWRITE_TAC[] THEN
  2.1999 -      SUBGOAL_THEN `measurable(k:real^N->bool)` ASSUME_TAC THENL
  2.2000 -       [ASM_MESON_TAC[SUBSET; GMEASURABLE_INTERVAL]; ALL_TAC] THEN
  2.2001 -      ASM_SIMP_TAC[GSYM INTEGRAL_MEASURE_UNIV; GMEASURABLE_INTER] THEN
  2.2002 -      REWRITE_TAC[MESON[IN_INTER]
  2.2003 -        `(if x \<in> k \<inter> s then a else b) =
  2.2004 -         (if x \<in> k then if x \<in> s then a else b else b)`] THEN
  2.2005 -      CONV_TAC SYM_CONV THEN MATCH_MP_TAC INTEGRAL_RESTRICT_UNIV THEN
  2.2006 -      ONCE_REWRITE_TAC[GSYM INTEGRABLE_RESTRICT_UNIV] THEN
  2.2007 -      REWRITE_TAC[MESON[IN_INTER]
  2.2008 -       `(if x \<in> k then if x \<in> s then a else b else b) =
  2.2009 -        (if x \<in> k \<inter> s then a else b)`] THEN
  2.2010 -      ASM_SIMP_TAC[GSYM GMEASURABLE_INTEGRABLE; GMEASURABLE_INTER];
  2.2011 -      ALL_TAC] THEN
  2.2012 -    ASM_REWRITE_TAC[GSYM LIFT_SUB; NORM_LIFT] THEN
  2.2013 -    MATCH_MP_TAC(REAL_ARITH `y \<le> m ==> abs(x - y) \<le> e ==> x \<le> m + e`) THEN
  2.2014 -    MATCH_MP_TAC REAL_LE_TRANS THEN
  2.2015 -    EXISTS_TAC `measure(\<Union>D \<inter> s:real^N->bool)` THEN
  2.2016 -    CONJ_TAC THENL
  2.2017 -     [ALL_TAC;
  2.2018 -      EXPAND_TAC "m" THEN MATCH_MP_TAC MEASURE_SUBSET THEN
  2.2019 -      ASM_REWRITE_TAC[] THEN CONJ_TAC THENL [ALL_TAC; SET_TAC[]] THEN
  2.2020 -      MATCH_MP_TAC GMEASURABLE_INTER THEN ASM_REWRITE_TAC[]] THEN
  2.2021 -    REWRITE_TAC[INTER_UNIONS] THEN MATCH_MP_TAC REAL_EQ_IMP_LE THEN
  2.2022 -    ONCE_REWRITE_TAC[SIMPLE_IMAGE] THEN CONV_TAC SYM_CONV THEN
  2.2023 -    MATCH_MP_TAC MEASURE_NEGLIGIBLE_UNIONS_IMAGE_STRONG THEN
  2.2024 -    ASM_SIMP_TAC[FINITE_RESTRICT] THEN CONJ_TAC THENL
  2.2025 -     [ASM_MESON_TAC[SUBSET; GMEASURABLE_INTERVAL; GMEASURABLE_INTER];
  2.2026 -      ALL_TAC] THEN
  2.2027 -    MAP_EVERY X_GEN_TAC [`k:real^N->bool`; `l:real^N->bool`] THEN
  2.2028 -    STRIP_TAC THEN MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.2029 -    EXISTS_TAC `k \<inter> l:real^N->bool` THEN ASM_SIMP_TAC[] THEN SET_TAC[];
  2.2030 -    ALL_TAC] THEN
  2.2031 -  ASM_CASES_TAC `FINITE(d:(real^N->bool)->bool)` THENL
  2.2032 -   [ASM_MESON_TAC[SUBSET_REFL]; ALL_TAC] THEN
  2.2033 -  MP_TAC(ISPEC `d:(real^N->bool)->bool` COUNTABLE_AS_INJECTIVE_IMAGE) THEN
  2.2034 -  ASM_REWRITE_TAC[INFINITE] THEN
  2.2035 -  DISCH_THEN(X_CHOOSE_THEN `s:num->real^N->bool`
  2.2036 -   (CONJUNCTS_THEN2 SUBST_ALL_TAC ASSUME_TAC)) THEN
  2.2037 -  MP_TAC(ISPECL [`s:num->real^N->bool`; `m + e:real`]
  2.2038 -    HAS_GMEASURE_COUNTABLE_NEGLIGIBLE_UNIONS) THEN
  2.2039 -  MATCH_MP_TAC(TAUT `a \<and> (a \<and> b ==> c) ==> (a ==> b) ==> c`) THEN
  2.2040 -  REWRITE_TAC[GSYM CONJ_ASSOC] THEN
  2.2041 -  RULE_ASSUM_TAC(REWRITE_RULE[IMP_CONJ; RIGHT_FORALL_IMP_THM;
  2.2042 -                              FORALL_IN_IMAGE; IN_UNIV]) THEN
  2.2043 -  RULE_ASSUM_TAC(REWRITE_RULE[IMP_IMP; RIGHT_IMP_FORALL_THM]) THEN
  2.2044 -  REPEAT CONJ_TAC THENL
  2.2045 -   [ASM_MESON_TAC[MEASURABLE_INTERVAL; GMEASURABLE_INTER];
  2.2046 -    ASM_MESON_TAC[];
  2.2047 -    X_GEN_TAC `n:num` THEN
  2.2048 -    FIRST_X_ASSUM(MP_TAC o SPEC `IMAGE (s:num->real^N->bool) (0..n)`) THEN
  2.2049 -    SIMP_TAC[FINITE_IMAGE; FINITE_NUMSEG; IMAGE_SUBSET; SUBSET_UNIV] THEN
  2.2050 -    DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC MP_TAC) THEN
  2.2051 -    MATCH_MP_TAC(REAL_ARITH `x = y ==> x \<le> e ==> y \<le> e`) THEN
  2.2052 -    MATCH_MP_TAC MEASURE_NEGLIGIBLE_UNIONS_IMAGE THEN
  2.2053 -    ASM_MESON_TAC[FINITE_NUMSEG; GMEASURABLE_INTERVAL];
  2.2054 -    ALL_TAC] THEN
  2.2055 -  ONCE_REWRITE_TAC[SIMPLE_IMAGE] THEN STRIP_TAC THEN ASM_REWRITE_TAC[] THEN
  2.2056 -  GEN_REWRITE_TAC LAND_CONV [GSYM(CONJUNCT2 LIFT_)] THEN
  2.2057 -  REWRITE_TAC[] THEN
  2.2058 -  MATCH_MP_TAC(ISPEC `sequentially` LIM_COMPONENT_UBOUND) THEN
  2.2059 -  EXISTS_TAC
  2.2060 -   `\n. vsum(from 0 \<inter> (0..n)) (\<lambda>n. lift(measure(s n:real^N->bool)))` THEN
  2.2061 -  ASM_REWRITE_TAC[GSYM sums; TRIVIAL_LIMIT_SEQUENTIALLY] THEN
  2.2062 -  REWRITE_TAC[DIMINDEX_1; ARITH; EVENTUALLY_SEQUENTIALLY] THEN
  2.2063 -  SIMP_TAC[VSUM_COMPONENT; ARITH; DIMINDEX_1] THEN
  2.2064 -  ASM_REWRITE_TAC[GSYM ; LIFT_; FROM_INTER_NUMSEG]);; *)
  2.2065 -
  2.2066 -(* ------------------------------------------------------------------------- *)
  2.2067 -(* Hence for linear transformation, suffices to check compact intervals.     *)
  2.2068 -(* ------------------------------------------------------------------------- *)
  2.2069 -
  2.2070 -lemma GMEASURABLE_LINEAR_IMAGE_INTERVAL: True .. (*
  2.2071 - "!f a b. linear f ==> gmeasurable(IMAGE f {a..b})"
  2.2072 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC GMEASURABLE_CONVEX THEN CONJ_TAC THENL
  2.2073 -   [MATCH_MP_TAC CONVEX_LINEAR_IMAGE THEN
  2.2074 -    ASM_MESON_TAC[CONVEX_INTERVAL];
  2.2075 -    MATCH_MP_TAC BOUNDED_LINEAR_IMAGE THEN
  2.2076 -    ASM_MESON_TAC[BOUNDED_INTERVAL]]);; *)
  2.2077 -
  2.2078 -lemma HAS_GMEASURE_LINEAR_SUFFICIENT: True .. (*
  2.2079 - "!f:real^N->real^N m.
  2.2080 -        linear f \<and>
  2.2081 -        (!a b. IMAGE f {a..b} has_gmeasure
  2.2082 -               (m * measure{a..b}))
  2.2083 -        ==> !s. gmeasurable s ==> (IMAGE f s) has_gmeasure (m * gmeasure s)"
  2.2084 -qed   REPEAT GEN_TAC THEN STRIP_TAC THEN
  2.2085 -  DISJ_CASES_TAC(REAL_ARITH `m < 0 \/ 0 \<le> m`) THENL
  2.2086 -   [FIRST_X_ASSUM(MP_TAC o SPECL [`0:real^N`; `1:real^N`]) THEN
  2.2087 -    DISCH_THEN(MP_TAC o MATCH_MP HAS_GMEASURE_POS_LE) THEN
  2.2088 -    MATCH_MP_TAC(TAUT `~a ==> a ==> b`) THEN
  2.2089 -    MATCH_MP_TAC(REAL_ARITH `0 < --m * x ==> ~(0 \<le> m * x)`) THEN
  2.2090 -    MATCH_MP_TAC REAL_LT_MUL THEN ASM_REWRITE_TAC[REAL_NEG_GT0] THEN
  2.2091 -    REWRITE_TAC[MEASURE_INTERVAL] THEN MATCH_MP_TAC CONTENT_POS_LT THEN
  2.2092 -    SIMP_TAC[VEC_COMPONENT; REAL_LT_01];
  2.2093 -    ALL_TAC] THEN
  2.2094 -  ASM_CASES_TAC `!x y. (f:real^N->real^N) x = f y ==> x = y` THENL
  2.2095 -   [ALL_TAC;
  2.2096 -    SUBGOAL_THEN `!s. negligible(IMAGE (f:real^N->real^N) s)` ASSUME_TAC THENL
  2.2097 -     [ASM_MESON_TAC[NEGLIGIBLE_LINEAR_SINGULAR_IMAGE]; ALL_TAC] THEN
  2.2098 -    SUBGOAL_THEN `m * measure(interval[0:real^N,1]) = 0` MP_TAC THENL
  2.2099 -     [MATCH_MP_TAC(ISPEC `IMAGE (f:real^N->real^N) {0..1}`
  2.2100 -        HAS_GMEASURE_UNIQUE) THEN
  2.2101 -      ASM_REWRITE_TAC[HAS_GMEASURE_0];
  2.2102 -      REWRITE_TAC[REAL_ENTIRE; MEASURE_INTERVAL] THEN
  2.2103 -      MATCH_MP_TAC(TAUT `~b \<and> (a ==> c) ==> a \/ b ==> c`) THEN CONJ_TAC THENL
  2.2104 -       [SIMP_TAC[CONTENT_EQ_0_INTERIOR; INTERIOR_CLOSED_INTERVAL;
  2.2105 -                 INTERVAL_NE_EMPTY; VEC_COMPONENT; REAL_LT_01];
  2.2106 -        ASM_SIMP_TAC[REAL_MUL_LZERO; HAS_GMEASURE_0]]]] THEN
  2.2107 -  MP_TAC(ISPEC `f:real^N->real^N` LINEAR_INJECTIVE_ISOMORPHISM) THEN
  2.2108 -  ASM_REWRITE_TAC[] THEN
  2.2109 -  DISCH_THEN(X_CHOOSE_THEN `h:real^N->real^N` STRIP_ASSUME_TAC) THEN
  2.2110 -  UNDISCH_THEN `!x y. (f:real^N->real^N) x = f y ==> x = y` (K ALL_TAC) THEN
  2.2111 -  SUBGOAL_THEN
  2.2112 -   `!s. bounded s \<and> gmeasurable s
  2.2113 -        ==> (IMAGE (f:real^N->real^N) s) has_gmeasure (m * gmeasure s)`
  2.2114 -  ASSUME_TAC THENL
  2.2115 -   [REPEAT STRIP_TAC THEN
  2.2116 -    FIRST_ASSUM(MP_TAC o MATCH_MP BOUNDED_SUBSET_CLOSED_INTERVAL) THEN
  2.2117 -    REWRITE_TAC[LEFT_IMP_EXISTS_THM] THEN
  2.2118 -    MAP_EVERY X_GEN_TAC [`a:real^N`; `b:real^N`] THEN DISCH_TAC THEN
  2.2119 -    SUBGOAL_THEN
  2.2120 -     `!d. COUNTABLE d \<and>
  2.2121 -          (!k. k \<in> d ==> k \<subseteq> {a..b} \<and> ~(k = {}) \<and>
  2.2122 -                          (\<exists>c d. k = {c..d})) \<and>
  2.2123 -          (!k1 k2. k1 \<in> d \<and> k2 \<in> d \<and> ~(k1 = k2)
  2.2124 -                   ==> interior k1 \<inter> interior k2 = {})
  2.2125 -          ==> IMAGE (f:real^N->real^N) (\<Union>d) has_gmeasure
  2.2126 -                    (m * measure(\<Union>d))`
  2.2127 -    ASSUME_TAC THENL
  2.2128 -     [REWRITE_TAC[IMAGE_UNIONS] THEN REPEAT STRIP_TAC THEN
  2.2129 -      SUBGOAL_THEN
  2.2130 -       `!g:real^N->real^N.
  2.2131 -          linear g
  2.2132 -          ==> !k l. k \<in> d \<and> l \<in> d \<and> ~(k = l)
  2.2133 -                    ==> negligible((IMAGE g k) \<inter> (IMAGE g l))`
  2.2134 -      MP_TAC THENL
  2.2135 -       [REPEAT STRIP_TAC THEN
  2.2136 -        ASM_CASES_TAC `!x y. (g:real^N->real^N) x = g y ==> x = y` THENL
  2.2137 -         [ALL_TAC;
  2.2138 -          ASM_MESON_TAC[NEGLIGIBLE_LINEAR_SINGULAR_IMAGE;
  2.2139 -                        NEGLIGIBLE_INTER]] THEN
  2.2140 -        MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.2141 -        EXISTS_TAC `frontier(IMAGE (g:real^N->real^N) k \<inter> IMAGE g l) UNION
  2.2142 -                    interior(IMAGE g k \<inter> IMAGE g l)` THEN
  2.2143 -        CONJ_TAC THENL
  2.2144 -         [ALL_TAC;
  2.2145 -          REWRITE_TAC[frontier] THEN MATCH_MP_TAC(SET_RULE
  2.2146 -           `s \<subseteq> t ==> s \<subseteq> (t DIFF u) \<union> u`) THEN
  2.2147 -          REWRITE_TAC[CLOSURE_SUBSET]] THEN
  2.2148 -        MATCH_MP_TAC NEGLIGIBLE_UNION THEN CONJ_TAC THENL
  2.2149 -         [MATCH_MP_TAC NEGLIGIBLE_CONVEX_FRONTIER THEN
  2.2150 -          MATCH_MP_TAC CONVEX_INTER THEN CONJ_TAC THEN
  2.2151 -          MATCH_MP_TAC CONVEX_LINEAR_IMAGE THEN ASM_MESON_TAC[CONVEX_INTERVAL];
  2.2152 -          ALL_TAC] THEN
  2.2153 -        REWRITE_TAC[INTERIOR_INTER] THEN MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.2154 -        EXISTS_TAC `IMAGE (g:real^N->real^N) (interior k) INTER
  2.2155 -                    IMAGE g (interior l)` THEN
  2.2156 -        CONJ_TAC THENL
  2.2157 -         [MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.2158 -          EXISTS_TAC
  2.2159 -           `IMAGE (g:real^N->real^N) (interior k \<inter> interior l)` THEN
  2.2160 -          CONJ_TAC THENL
  2.2161 -           [ASM_SIMP_TAC[IMAGE_CLAUSES; NEGLIGIBLE_EMPTY]; SET_TAC[]];
  2.2162 -          MATCH_MP_TAC(SET_RULE
  2.2163 -           `s \<subseteq> u \<and> t \<subseteq> v ==> (s \<inter> t) \<subseteq> (u \<inter> v)`) THEN
  2.2164 -          CONJ_TAC THEN MATCH_MP_TAC INTERIOR_IMAGE_SUBSET THEN
  2.2165 -          ASM_MESON_TAC[LINEAR_CONTINUOUS_AT]];
  2.2166 -        ALL_TAC] THEN
  2.2167 -      DISCH_THEN(fun th -> MP_TAC(SPEC `f:real^N->real^N` th) THEN
  2.2168 -          MP_TAC(SPEC `\x:real^N. x` th)) THEN
  2.2169 -      ASM_REWRITE_TAC[LINEAR_ID; SET_RULE `IMAGE (\<lambda>x. x) s = s`] THEN
  2.2170 -      REPEAT STRIP_TAC THEN ASM_CASES_TAC `FINITE(d:(real^N->bool)->bool)` THENL
  2.2171 -       [MP_TAC(ISPECL [`IMAGE (f:real^N->real^N)`; `d:(real^N->bool)->bool`]
  2.2172 -                  HAS_GMEASURE_NEGLIGIBLE_UNIONS_IMAGE) THEN
  2.2173 -        ANTS_TAC THENL [ASM_MESON_TAC[measurable]; ALL_TAC] THEN
  2.2174 -        MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN
  2.2175 -        MATCH_MP_TAC EQ_TRANS THEN
  2.2176 -        EXISTS_TAC `sum d (\<lambda>k:real^N->bool. m * gmeasure k)` THEN CONJ_TAC THENL
  2.2177 -         [MATCH_MP_TAC SUM_EQ THEN ASM_MESON_TAC[MEASURE_UNIQUE]; ALL_TAC] THEN
  2.2178 -        REWRITE_TAC[SUM_LMUL] THEN AP_TERM_TAC THEN
  2.2179 -        CONV_TAC SYM_CONV THEN MATCH_MP_TAC MEASURE_NEGLIGIBLE_UNIONS THEN
  2.2180 -        ASM_REWRITE_TAC[GSYM HAS_GMEASURE_MEASURE] THEN
  2.2181 -        ASM_MESON_TAC[MEASURABLE_INTERVAL];
  2.2182 -        ALL_TAC] THEN
  2.2183 -      MP_TAC(ISPEC `d:(real^N->bool)->bool` COUNTABLE_AS_INJECTIVE_IMAGE) THEN
  2.2184 -      ASM_REWRITE_TAC[INFINITE] THEN
  2.2185 -      DISCH_THEN(X_CHOOSE_THEN `s:num->real^N->bool`
  2.2186 -       (CONJUNCTS_THEN2 SUBST_ALL_TAC ASSUME_TAC)) THEN
  2.2187 -      MP_TAC(ISPEC `s:num->real^N->bool`
  2.2188 -        HAS_GMEASURE_COUNTABLE_NEGLIGIBLE_UNIONS_BOUNDED) THEN
  2.2189 -      MP_TAC(ISPEC `\n:num. IMAGE (f:real^N->real^N) (s n)`
  2.2190 -        HAS_GMEASURE_COUNTABLE_NEGLIGIBLE_UNIONS_BOUNDED) THEN
  2.2191 -      RULE_ASSUM_TAC(REWRITE_RULE[IMP_CONJ; RIGHT_FORALL_IMP_THM;
  2.2192 -                                  FORALL_IN_IMAGE; IN_UNIV]) THEN
  2.2193 -      RULE_ASSUM_TAC(REWRITE_RULE[IMP_IMP; RIGHT_IMP_FORALL_THM]) THEN
  2.2194 -      ASM_SIMP_TAC[] THEN ONCE_REWRITE_TAC[SIMPLE_IMAGE] THEN ANTS_TAC THENL
  2.2195 -       [REPEAT CONJ_TAC THENL
  2.2196 -         [ASM_MESON_TAC[MEASURABLE_LINEAR_IMAGE_INTERVAL];
  2.2197 -          ASM_MESON_TAC[];
  2.2198 -          ONCE_REWRITE_TAC[GSYM o_DEF] THEN
  2.2199 -          REWRITE_TAC[GSYM IMAGE_UNIONS; IMAGE_o] THEN
  2.2200 -          MATCH_MP_TAC BOUNDED_LINEAR_IMAGE THEN ASM_REWRITE_TAC[] THEN
  2.2201 -          MATCH_MP_TAC BOUNDED_SUBSET THEN REWRITE_TAC[UNIONS_SUBSET] THEN
  2.2202 -          EXISTS_TAC `interval[a:real^N,b]` THEN
  2.2203 -          REWRITE_TAC[BOUNDED_INTERVAL] THEN ASM SET_TAC[]];
  2.2204 -        ALL_TAC] THEN
  2.2205 -      STRIP_TAC THEN ANTS_TAC THENL
  2.2206 -       [REPEAT CONJ_TAC THENL
  2.2207 -         [ASM_MESON_TAC[MEASURABLE_INTERVAL];
  2.2208 -          ASM_MESON_TAC[];
  2.2209 -          MATCH_MP_TAC BOUNDED_SUBSET THEN REWRITE_TAC[UNIONS_SUBSET] THEN
  2.2210 -          EXISTS_TAC `interval[a:real^N,b]` THEN
  2.2211 -          REWRITE_TAC[BOUNDED_INTERVAL] THEN ASM SET_TAC[]];
  2.2212 -        ALL_TAC] THEN
  2.2213 -      STRIP_TAC THEN REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN
  2.2214 -      SUBGOAL_THEN `m * gmeasure (\<Union>(IMAGE s (:num)):real^N->bool) =
  2.2215 -             measure(\<Union>(IMAGE (\<lambda>x. IMAGE f (s x)) (:num)):real^N->bool)`
  2.2216 -       (fun th -> ASM_REWRITE_TAC[GSYM HAS_GMEASURE_MEASURE; th]) THEN
  2.2217 -      ONCE_REWRITE_TAC[GSYM LIFT_EQ] THEN
  2.2218 -      MATCH_MP_TAC SERIES_UNIQUE THEN
  2.2219 -      EXISTS_TAC `\n:num. lift(measure(IMAGE (f:real^N->real^N) (s n)))` THEN
  2.2220 -      EXISTS_TAC `from 0` THEN ASM_REWRITE_TAC[] THEN MATCH_MP_TAC SUMS_EQ THEN
  2.2221 -      EXISTS_TAC `\n:num. m % lift(measure(s n:real^N->bool))` THEN
  2.2222 -      CONJ_TAC THENL
  2.2223 -       [REWRITE_TAC[GSYM LIFT_CMUL; LIFT_EQ] THEN
  2.2224 -        ASM_MESON_TAC[MEASURE_UNIQUE];
  2.2225 -        REWRITE_TAC[LIFT_CMUL] THEN MATCH_MP_TAC SERIES_CMUL THEN
  2.2226 -        ASM_REWRITE_TAC[]];
  2.2227 -      ALL_TAC] THEN
  2.2228 -    REWRITE_TAC[HAS_GMEASURE_INNER_OUTER_LE] THEN CONJ_TAC THEN
  2.2229 -    X_GEN_TAC `e:real` THEN DISCH_TAC THENL
  2.2230 -     [MP_TAC(ISPECL [`{a..b} DIFF s:real^N->bool`; `a:real^N`;
  2.2231 -       `b:real^N`; `e / (1 + abs m)`] GMEASURABLE_OUTER_INTERVALS_BOUNDED) THEN
  2.2232 -      ANTS_TAC THENL
  2.2233 -       [ASM_SIMP_TAC[MEASURABLE_DIFF; GMEASURABLE_INTERVAL] THEN
  2.2234 -        ASM_SIMP_TAC[REAL_ARITH `0 < 1 + abs x`; REAL_LT_DIV] THEN SET_TAC[];
  2.2235 -        ALL_TAC] THEN
  2.2236 -      DISCH_THEN(X_CHOOSE_THEN `d:(real^N->bool)->bool` STRIP_ASSUME_TAC) THEN
  2.2237 -      EXISTS_TAC `IMAGE f {a..b} DIFF
  2.2238 -                  IMAGE (f:real^N->real^N) (\<Union>d)` THEN
  2.2239 -      FIRST_X_ASSUM(MP_TAC o SPEC `d:(real^N->bool)->bool`) THEN
  2.2240 -      ASM_SIMP_TAC[IMAGE_SUBSET] THEN DISCH_TAC THEN
  2.2241 -      CONJ_TAC THENL [ASM SET_TAC[]; ALL_TAC] THEN CONJ_TAC THENL
  2.2242 -       [ASM_MESON_TAC[MEASURABLE_DIFF; gmeasurable]; ALL_TAC] THEN
  2.2243 -      MATCH_MP_TAC REAL_LE_TRANS THEN
  2.2244 -      EXISTS_TAC `measure(IMAGE f {a..b}) -
  2.2245 -                  measure(IMAGE (f:real^N->real^N) (\<Union>d))` THEN
  2.2246 -      CONJ_TAC THENL
  2.2247 -       [ALL_TAC;
  2.2248 -        MATCH_MP_TAC REAL_EQ_IMP_LE THEN CONV_TAC SYM_CONV THEN
  2.2249 -        MATCH_MP_TAC MEASURE_DIFF_SUBSET THEN
  2.2250 -        REPEAT(CONJ_TAC THENL [ASM_MESON_TAC[measurable]; ALL_TAC]) THEN
  2.2251 -        MATCH_MP_TAC IMAGE_SUBSET THEN ASM_SIMP_TAC[UNIONS_SUBSET]] THEN
  2.2252 -      FIRST_ASSUM(ASSUME_TAC o SPECL [`a:real^N`; `b:real^N`]) THEN
  2.2253 -      REPEAT(FIRST_X_ASSUM(SUBST1_TAC o MATCH_MP MEASURE_UNIQUE)) THEN
  2.2254 -      MATCH_MP_TAC REAL_LE_TRANS THEN
  2.2255 -      EXISTS_TAC `m * measure(s:real^N->bool) - m * e / (1 + abs m)` THEN
  2.2256 -      CONJ_TAC THENL
  2.2257 -       [REWRITE_TAC[REAL_ARITH `a - x \<le> a - y \<longleftrightarrow> y \<le> x`] THEN
  2.2258 -        REWRITE_TAC[real_div; REAL_MUL_ASSOC] THEN
  2.2259 -        REWRITE_TAC[GSYM real_div] THEN
  2.2260 -        ASM_SIMP_TAC[REAL_LE_LDIV_EQ; REAL_ARITH `0 < 1 + abs x`] THEN
  2.2261 -        GEN_REWRITE_TAC RAND_CONV [REAL_MUL_SYM] THEN
  2.2262 -        ASM_SIMP_TAC[REAL_LE_RMUL_EQ] THEN REAL_ARITH_TAC;
  2.2263 -        ALL_TAC] THEN
  2.2264 -      REWRITE_TAC[GSYM REAL_SUB_LDISTRIB] THEN MATCH_MP_TAC REAL_LE_LMUL THEN
  2.2265 -      ASM_REWRITE_TAC[] THEN
  2.2266 -      FIRST_X_ASSUM(MATCH_MP_TAC o MATCH_MP (REAL_ARITH
  2.2267 -        `d \<le> a + e ==> a = i - s ==> s - e \<le> i - d`)) THEN
  2.2268 -      MATCH_MP_TAC MEASURE_DIFF_SUBSET THEN
  2.2269 -      ASM_REWRITE_TAC[MEASURABLE_INTERVAL];
  2.2270 -      MP_TAC(ISPECL [`s:real^N->bool`; `a:real^N`; `b:real^N`;
  2.2271 -                `e / (1 + abs m)`] GMEASURABLE_OUTER_INTERVALS_BOUNDED) THEN
  2.2272 -      ASM_SIMP_TAC[REAL_LT_DIV; REAL_ARITH `0 < 1 + abs x`] THEN
  2.2273 -      DISCH_THEN(X_CHOOSE_THEN `d:(real^N->bool)->bool` STRIP_ASSUME_TAC) THEN
  2.2274 -      EXISTS_TAC `IMAGE (f:real^N->real^N) (\<Union>d)` THEN
  2.2275 -      FIRST_X_ASSUM(MP_TAC o SPEC `d:(real^N->bool)->bool`) THEN
  2.2276 -      ASM_SIMP_TAC[IMAGE_SUBSET] THEN
  2.2277 -      SIMP_TAC[HAS_GMEASURE_MEASURABLE_MEASURE] THEN STRIP_TAC THEN
  2.2278 -      MATCH_MP_TAC REAL_LE_TRANS THEN
  2.2279 -      EXISTS_TAC `m * measure(s:real^N->bool) + m * e / (1 + abs m)` THEN
  2.2280 -      CONJ_TAC THENL
  2.2281 -       [REWRITE_TAC[GSYM REAL_ADD_LDISTRIB] THEN ASM_SIMP_TAC[REAL_LE_LMUL];
  2.2282 -        REWRITE_TAC[REAL_LE_LADD] THEN
  2.2283 -        REWRITE_TAC[real_div; REAL_MUL_ASSOC] THEN
  2.2284 -        REWRITE_TAC[GSYM real_div] THEN
  2.2285 -        ASM_SIMP_TAC[REAL_LE_LDIV_EQ; REAL_ARITH `0 < 1 + abs x`] THEN
  2.2286 -        GEN_REWRITE_TAC RAND_CONV [REAL_MUL_SYM] THEN
  2.2287 -        ASM_SIMP_TAC[REAL_LE_RMUL_EQ] THEN REAL_ARITH_TAC]];
  2.2288 -      ALL_TAC] THEN
  2.2289 -  REPEAT STRIP_TAC THEN ONCE_REWRITE_TAC[HAS_GMEASURE_LIMIT] THEN
  2.2290 -  X_GEN_TAC `e:real` THEN DISCH_TAC THEN
  2.2291 -  FIRST_ASSUM(MP_TAC o GEN_REWRITE_RULE I [HAS_GMEASURE_MEASURE]) THEN
  2.2292 -  GEN_REWRITE_TAC LAND_CONV [HAS_GMEASURE_LIMIT] THEN
  2.2293 -  DISCH_THEN(MP_TAC o SPEC `e / (1 + abs m)`) THEN
  2.2294 -  ASM_SIMP_TAC[REAL_LT_DIV; REAL_ARITH `0 < 1 + abs x`] THEN
  2.2295 -  DISCH_THEN(X_CHOOSE_THEN `B:real`
  2.2296 -   (CONJUNCTS_THEN2 ASSUME_TAC (LABEL_TAC "*"))) THEN
  2.2297 -  MP_TAC(ISPEC `ball(0:real^N,B)` BOUNDED_SUBSET_CLOSED_INTERVAL) THEN
  2.2298 -  REWRITE_TAC[BOUNDED_BALL; LEFT_IMP_EXISTS_THM] THEN
  2.2299 -  REMOVE_THEN "*" MP_TAC THEN
  2.2300 -  MATCH_MP_TAC MONO_FORALL THEN X_GEN_TAC `c:real^N` THEN
  2.2301 -  MATCH_MP_TAC MONO_FORALL THEN X_GEN_TAC `d:real^N` THEN
  2.2302 -  DISCH_THEN(fun th -> DISCH_TAC THEN MP_TAC th) THEN ASM_REWRITE_TAC[] THEN
  2.2303 -  DISCH_THEN(X_CHOOSE_THEN `z:real` STRIP_ASSUME_TAC) THEN
  2.2304 -  MP_TAC(ISPECL [`interval[c:real^N,d]`; `0:real^N`]
  2.2305 -    BOUNDED_SUBSET_BALL) THEN
  2.2306 -  REWRITE_TAC[BOUNDED_INTERVAL] THEN
  2.2307 -  DISCH_THEN(X_CHOOSE_THEN `D:real` STRIP_ASSUME_TAC) THEN
  2.2308 -  MP_TAC(ISPEC `f:real^N->real^N` LINEAR_BOUNDED_POS) THEN
  2.2309 -  ASM_REWRITE_TAC[] THEN
  2.2310 -  DISCH_THEN(X_CHOOSE_THEN `C:real` STRIP_ASSUME_TAC) THEN
  2.2311 -
  2.2312 -  EXISTS_TAC `D * C` THEN ASM_SIMP_TAC[REAL_LT_MUL] THEN
  2.2313 -  MAP_EVERY X_GEN_TAC [`a:real^N`; `b:real^N`] THEN DISCH_TAC THEN
  2.2314 -  FIRST_X_ASSUM(MP_TAC o SPEC
  2.2315 -   `s \<inter> (IMAGE (h:real^N->real^N) {a..b})`) THEN
  2.2316 -  SUBGOAL_THEN
  2.2317 -   `IMAGE (f:real^N->real^N) (s \<inter> IMAGE h (interval [a,b])) =
  2.2318 -    (IMAGE f s) \<inter> {a..b}`
  2.2319 -  SUBST1_TAC THENL [ASM SET_TAC[]; ALL_TAC] THEN ANTS_TAC THENL
  2.2320 -   [ASM_SIMP_TAC[BOUNDED_INTER; BOUNDED_LINEAR_IMAGE; BOUNDED_INTERVAL] THEN
  2.2321 -    ASM_SIMP_TAC[MEASURABLE_INTER; GMEASURABLE_LINEAR_IMAGE_INTERVAL];
  2.2322 -    ALL_TAC] THEN
  2.2323 -  DISCH_TAC THEN EXISTS_TAC
  2.2324 -   `m * measure(s \<inter> (IMAGE (h:real^N->real^N) {a..b}))` THEN
  2.2325 -  ASM_REWRITE_TAC[] THEN
  2.2326 -  MATCH_MP_TAC REAL_LET_TRANS THEN EXISTS_TAC `m * e / (1 + abs m)` THEN
  2.2327 -  CONJ_TAC THENL
  2.2328 -   [ALL_TAC;
  2.2329 -    REWRITE_TAC[real_div; REAL_MUL_ASSOC] THEN REWRITE_TAC[GSYM real_div] THEN
  2.2330 -    ASM_SIMP_TAC[REAL_LT_LDIV_EQ; REAL_ARITH `0 < 1 + abs x`] THEN
  2.2331 -    GEN_REWRITE_TAC RAND_CONV [REAL_MUL_SYM] THEN
  2.2332 -    ASM_SIMP_TAC[REAL_LT_RMUL_EQ] THEN REAL_ARITH_TAC] THEN
  2.2333 -  REWRITE_TAC[GSYM REAL_SUB_LDISTRIB; REAL_ABS_MUL] THEN
  2.2334 -  GEN_REWRITE_TAC (LAND_CONV o LAND_CONV) [real_abs] THEN
  2.2335 -  ASM_REWRITE_TAC[] THEN MATCH_MP_TAC REAL_LE_LMUL THEN ASM_REWRITE_TAC[] THEN
  2.2336 -  FIRST_ASSUM(MATCH_MP_TAC o MATCH_MP (REAL_ARITH
  2.2337 -   `abs(z - m) < e ==> z \<le> w \<and> w \<le> m ==> abs(w - m) \<le> e`)) THEN
  2.2338 -  SUBST1_TAC(SYM(MATCH_MP MEASURE_UNIQUE
  2.2339 -   (ASSUME `s \<inter> interval [c:real^N,d] has_gmeasure z`))) THEN
  2.2340 -  CONJ_TAC THEN MATCH_MP_TAC MEASURE_SUBSET THEN
  2.2341 -  ASM_SIMP_TAC[MEASURABLE_INTER; GMEASURABLE_LINEAR_IMAGE_INTERVAL;
  2.2342 -               GMEASURABLE_INTERVAL; INTER_SUBSET] THEN
  2.2343 -  MATCH_MP_TAC(SET_RULE
  2.2344 -   `!v. t \<subseteq> v \<and> v \<subseteq> u ==> s \<inter> t \<subseteq> s \<inter> u`) THEN
  2.2345 -  EXISTS_TAC `ball(0:real^N,D)` THEN ASM_REWRITE_TAC[] THEN
  2.2346 -  MATCH_MP_TAC(SET_RULE
  2.2347 -   `!f. (!x. h(f x) = x) \<and> IMAGE f s \<subseteq> t ==> s \<subseteq> IMAGE h t`) THEN
  2.2348 -  EXISTS_TAC `f:real^N->real^N` THEN ASM_REWRITE_TAC[] THEN
  2.2349 -  MATCH_MP_TAC SUBSET_TRANS THEN EXISTS_TAC `ball(0:real^N,D * C)` THEN
  2.2350 -  ASM_REWRITE_TAC[SUBSET; FORALL_IN_IMAGE; IN_BALL_0] THEN
  2.2351 -  X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN
  2.2352 -  MATCH_MP_TAC REAL_LET_TRANS THEN EXISTS_TAC `C * norm(x:real^N)` THEN
  2.2353 -  ASM_REWRITE_TAC[] THEN GEN_REWRITE_TAC RAND_CONV [REAL_MUL_SYM] THEN
  2.2354 -  ASM_SIMP_TAC[REAL_LT_LMUL_EQ]);; *)
  2.2355 -
  2.2356 -(* ------------------------------------------------------------------------- *)
  2.2357 -(* Some inductions by expressing mapping in terms of elementary matrices.    *)
  2.2358 -(* ------------------------------------------------------------------------- *)
  2.2359 -
  2.2360 -lemma INDUCT_MATRIX_ROW_OPERATIONS: True .. (*
  2.2361 - "!P:real^N^N->bool.
  2.2362 -        (!A i. 1 \<le> i \<and> i \<le> dimindex(:N) \<and> row i A = 0 ==> P A) \<and>
  2.2363 -        (!A. (!i j. 1 \<le> i \<and> i \<le> dimindex(:N) \<and>
  2.2364 -                    1 \<le> j \<and> j \<le> dimindex(:N) \<and> ~(i = j)
  2.2365 -                    ==> A$i$j = 0) ==> P A) \<and>
  2.2366 -        (!A m n. P A \<and> 1 \<le> m \<and> m \<le> dimindex(:N) \<and>
  2.2367 -                 1 \<le> n \<and> n \<le> dimindex(:N) \<and> ~(m = n)
  2.2368 -                 ==> P(lambda i j. A$i$(swap(m,n) j))) \<and>
  2.2369 -        (!A m n c. P A \<and> 1 \<le> m \<and> m \<le> dimindex(:N) \<and>
  2.2370 -                   1 \<le> n \<and> n \<le> dimindex(:N) \<and> ~(m = n)
  2.2371 -                   ==> P(lambda i. if i = m then row m A + c % row n A
  2.2372 -                                   else row i A))
  2.2373 -        ==> !A. P A"
  2.2374 -qed   GEN_TAC THEN
  2.2375 -  DISCH_THEN(CONJUNCTS_THEN2 (LABEL_TAC "zero_row") MP_TAC) THEN
  2.2376 -  DISCH_THEN(CONJUNCTS_THEN2 (LABEL_TAC "diagonal") MP_TAC) THEN
  2.2377 -  DISCH_THEN(CONJUNCTS_THEN2 (LABEL_TAC "swap_cols") (LABEL_TAC "row_op")) THEN
  2.2378 -  SUBGOAL_THEN
  2.2379 -   `!k A:real^N^N.
  2.2380 -        (!i j. 1 \<le> i \<and> i \<le> dimindex(:N) \<and>
  2.2381 -               k \<le> j \<and> j \<le> dimindex(:N) \<and> ~(i = j)
  2.2382 -               ==> A$i$j = 0)
  2.2383 -        ==> P A`
  2.2384 -   (fun th -> GEN_TAC THEN MATCH_MP_TAC th THEN
  2.2385 -              EXISTS_TAC `dimindex(:N) + 1` THEN ARITH_TAC) THEN
  2.2386 -  MATCH_MP_TAC num_INDUCTION THEN CONJ_TAC THENL
  2.2387 -   [REPEAT STRIP_TAC THEN USE_THEN "diagonal" MATCH_MP_TAC THEN
  2.2388 -    REPEAT STRIP_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN
  2.2389 -    ASM_REWRITE_TAC[LE_0];
  2.2390 -    ALL_TAC] THEN
  2.2391 -  X_GEN_TAC `k:num` THEN DISCH_THEN(LABEL_TAC "ind_hyp") THEN
  2.2392 -  DISJ_CASES_THEN2 SUBST1_TAC ASSUME_TAC (ARITH_RULE `k = 0 \/ 1 \<le> k`) THEN
  2.2393 -  ASM_REWRITE_TAC[ARITH] THEN
  2.2394 -  ASM_CASES_TAC `k \<le> dimindex(:N)` THENL
  2.2395 -   [ALL_TAC;
  2.2396 -    REPEAT STRIP_TAC THEN REMOVE_THEN "ind_hyp" MATCH_MP_TAC THEN
  2.2397 -    ASM_ARITH_TAC] THEN
  2.2398 -  SUBGOAL_THEN
  2.2399 -   `!A:real^N^N.
  2.2400 -        ~(A$k$k = 0) \<and>
  2.2401 -        (!i j. 1 \<le> i \<and> i \<le> dimindex (:N) \<and>
  2.2402 -               SUC k \<le> j \<and> j \<le> dimindex (:N) \<and> ~(i = j)
  2.2403 -               ==> A$i$j = 0)
  2.2404 -        ==> P A`
  2.2405 -  (LABEL_TAC "nonzero_hyp") THENL
  2.2406 -   [ALL_TAC;
  2.2407 -    X_GEN_TAC `A:real^N^N` THEN DISCH_TAC THEN
  2.2408 -    ASM_CASES_TAC `row k (A:real^N^N) = 0` THENL
  2.2409 -     [REMOVE_THEN "zero_row" MATCH_MP_TAC THEN ASM_MESON_TAC[];
  2.2410 -      ALL_TAC] THEN
  2.2411 -    FIRST_ASSUM(MP_TAC o GEN_REWRITE_RULE RAND_CONV [CART_EQ]) THEN
  2.2412 -    SIMP_TAC[VEC_COMPONENT; row; LAMBDA_BETA] THEN
  2.2413 -    REWRITE_TAC[NOT_FORALL_THM; NOT_IMP; LEFT_IMP_EXISTS_THM] THEN
  2.2414 -    X_GEN_TAC `l:num` THEN STRIP_TAC THEN
  2.2415 -    ASM_CASES_TAC `l:num = k` THENL
  2.2416 -     [REMOVE_THEN "nonzero_hyp" MATCH_MP_TAC THEN ASM_MESON_TAC[];
  2.2417 -      ALL_TAC] THEN
  2.2418 -    REMOVE_THEN "swap_cols" (MP_TAC o SPECL
  2.2419 -     [`(lambda i j. (A:real^N^N)$i$swap(k,l) j):real^N^N`;
  2.2420 -      `k:num`; `l:num`]) THEN
  2.2421 -    ASM_SIMP_TAC[LAMBDA_BETA] THEN ANTS_TAC THENL
  2.2422 -     [ALL_TAC;
  2.2423 -      MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN
  2.2424 -      SIMP_TAC[CART_EQ; LAMBDA_BETA] THEN
  2.2425 -      REPEAT STRIP_TAC THEN REWRITE_TAC[swap] THEN
  2.2426 -      REPEAT(COND_CASES_TAC THEN ASM_SIMP_TAC[LAMBDA_BETA])] THEN
  2.2427 -    REMOVE_THEN "nonzero_hyp" MATCH_MP_TAC THEN
  2.2428 -    ONCE_REWRITE_TAC[ARITH_RULE `SUC k \<le> i \<longleftrightarrow> 1 \<le> i \<and> SUC k \<le> i`] THEN
  2.2429 -    ASM_SIMP_TAC[LAMBDA_BETA] THEN
  2.2430 -    ASM_REWRITE_TAC[swap] THEN MAP_EVERY X_GEN_TAC [`i:num`; `j:num`] THEN
  2.2431 -    STRIP_TAC THEN SUBGOAL_THEN `l:num \<le> k` ASSUME_TAC THENL
  2.2432 -     [FIRST_X_ASSUM(MP_TAC o SPECL [`k:num`; `l:num`]) THEN
  2.2433 -      ASM_REWRITE_TAC[] THEN ARITH_TAC;
  2.2434 -      ALL_TAC] THEN
  2.2435 -    REPEAT(COND_CASES_TAC THEN ASM_REWRITE_TAC[]) THEN
  2.2436 -    FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[] THEN
  2.2437 -    ASM_ARITH_TAC] THEN
  2.2438 -   SUBGOAL_THEN
  2.2439 -   `!l A:real^N^N.
  2.2440 -        ~(A$k$k = 0) \<and>
  2.2441 -        (!i j. 1 \<le> i \<and> i \<le> dimindex (:N) \<and>
  2.2442 -               SUC k \<le> j \<and> j \<le> dimindex (:N) \<and> ~(i = j)
  2.2443 -               ==> A$i$j = 0) \<and>
  2.2444 -        (!i. l \<le> i \<and> i \<le> dimindex(:N) \<and> ~(i = k) ==> A$i$k = 0)
  2.2445 -        ==> P A`
  2.2446 -   MP_TAC THENL
  2.2447 -    [ALL_TAC;
  2.2448 -     DISCH_THEN(MP_TAC o SPEC `dimindex(:N) + 1`) THEN
  2.2449 -     REWRITE_TAC[CONJ_ASSOC; ARITH_RULE `~(n + 1 \<le> i \<and> i \<le> n)`]] THEN
  2.2450 -   MATCH_MP_TAC num_INDUCTION THEN CONJ_TAC THENL
  2.2451 -    [GEN_TAC THEN DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC MP_TAC) THEN
  2.2452 -     DISCH_THEN(CONJUNCTS_THEN2 (LABEL_TAC "main") (LABEL_TAC "aux")) THEN
  2.2453 -     USE_THEN "ind_hyp" MATCH_MP_TAC THEN
  2.2454 -     MAP_EVERY X_GEN_TAC [`i:num`; `j:num`] THEN STRIP_TAC THEN
  2.2455 -     ASM_CASES_TAC `j:num = k` THENL
  2.2456 -      [ASM_REWRITE_TAC[] THEN USE_THEN "aux" MATCH_MP_TAC THEN ASM_ARITH_TAC;
  2.2457 -       REMOVE_THEN "main" MATCH_MP_TAC THEN ASM_ARITH_TAC];
  2.2458 -    ALL_TAC] THEN
  2.2459 -  X_GEN_TAC `l:num` THEN DISCH_THEN(LABEL_TAC "inner_hyp") THEN
  2.2460 -  GEN_TAC THEN DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC MP_TAC) THEN
  2.2461 -  DISCH_THEN(CONJUNCTS_THEN2 (LABEL_TAC "main") (LABEL_TAC "aux")) THEN
  2.2462 -  ASM_CASES_TAC `l:num = k` THENL
  2.2463 -   [REMOVE_THEN "inner_hyp" MATCH_MP_TAC THEN ASM_REWRITE_TAC[] THEN
  2.2464 -    REPEAT STRIP_TAC THEN REMOVE_THEN "aux" MATCH_MP_TAC THEN ASM_ARITH_TAC;
  2.2465 -    ALL_TAC] THEN
  2.2466 -  DISJ_CASES_TAC(ARITH_RULE `l = 0 \/ 1 \<le> l`) THENL
  2.2467 -   [REMOVE_THEN "ind_hyp" MATCH_MP_TAC THEN
  2.2468 -    MAP_EVERY X_GEN_TAC [`i:num`; `j:num`] THEN STRIP_TAC THEN
  2.2469 -    ASM_CASES_TAC `j:num = k` THENL
  2.2470 -     [ASM_REWRITE_TAC[] THEN REMOVE_THEN "aux" MATCH_MP_TAC THEN ASM_ARITH_TAC;
  2.2471 -      REMOVE_THEN "main" MATCH_MP_TAC THEN ASM_ARITH_TAC];
  2.2472 -    ALL_TAC] THEN
  2.2473 -  ASM_CASES_TAC `l \<le> dimindex(:N)` THENL
  2.2474 -   [ALL_TAC;
  2.2475 -    REMOVE_THEN "inner_hyp" MATCH_MP_TAC THEN ASM_REWRITE_TAC[] THEN
  2.2476 -    ASM_ARITH_TAC] THEN
  2.2477 -  REMOVE_THEN "inner_hyp" (MP_TAC o SPECL
  2.2478 -   [`(lambda i. if i = l then row l (A:real^N^N) + --(A$l$k/A$k$k) % row k A
  2.2479 -                else row i A):real^N^N`]) THEN
  2.2480 -  ANTS_TAC THENL
  2.2481 -   [SUBGOAL_THEN `!i. l \<le> i ==> 1 \<le> i` ASSUME_TAC THENL
  2.2482 -     [ASM_ARITH_TAC; ALL_TAC] THEN
  2.2483 -    ONCE_REWRITE_TAC[ARITH_RULE `SUC k \<le> j \<longleftrightarrow> 1 \<le> j \<and> SUC k \<le> j`] THEN
  2.2484 -    ASM_SIMP_TAC[LAMBDA_BETA; row; COND_COMPONENT;
  2.2485 -                 VECTOR_ADD_COMPONENT; VECTOR_MUL_COMPONENT] THEN
  2.2486 -    ASM_SIMP_TAC[REAL_FIELD `~(y = 0) ==> x + --(x / y) * y = 0`] THEN
  2.2487 -    REWRITE_TAC[AND_FORALL_THM] THEN X_GEN_TAC `i:num` THEN
  2.2488 -    ASM_CASES_TAC `i:num = l` THEN ASM_REWRITE_TAC[] THENL
  2.2489 -     [REPEAT STRIP_TAC THEN
  2.2490 -      MATCH_MP_TAC(REAL_RING `x = 0 \<and> y = 0 ==> x + z * y = 0`) THEN
  2.2491 -      CONJ_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_ARITH_TAC;
  2.2492 -      REPEAT STRIP_TAC THEN REMOVE_THEN "aux" MATCH_MP_TAC THEN ASM_ARITH_TAC];
  2.2493 -    ALL_TAC] THEN
  2.2494 -  DISCH_TAC THEN REMOVE_THEN "row_op" (MP_TAC o SPECL
  2.2495 -   [`(lambda i. if i = l then row l A + --(A$l$k / A$k$k) % row k A
  2.2496 -                else row i (A:real^N^N)):real^N^N`;
  2.2497 -    `l:num`; `k:num`; `(A:real^N^N)$l$k / A$k$k`]) THEN
  2.2498 -  ASM_REWRITE_TAC[] THEN MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN
  2.2499 -  ASM_SIMP_TAC[CART_EQ; LAMBDA_BETA; VECTOR_ADD_COMPONENT;
  2.2500 -               VECTOR_MUL_COMPONENT; row; COND_COMPONENT] THEN
  2.2501 -  REPEAT STRIP_TAC THEN COND_CASES_TAC THEN ASM_REWRITE_TAC[] THEN
  2.2502 -  REAL_ARITH_TAC);; *)
  2.2503 -
  2.2504 -lemma INDUCT_MATRIX_ELEMENTARY: True .. (*
  2.2505 - "!P:real^N^N->bool.
  2.2506 -        (!A B. P A \<and> P B ==> P(A ** B)) \<and>
  2.2507 -        (!A i. 1 \<le> i \<and> i \<le> dimindex(:N) \<and> row i A = 0 ==> P A) \<and>
  2.2508 -        (!A. (!i j. 1 \<le> i \<and> i \<le> dimindex(:N) \<and>
  2.2509 -                    1 \<le> j \<and> j \<le> dimindex(:N) \<and> ~(i = j)
  2.2510 -                    ==> A$i$j = 0) ==> P A) \<and>
  2.2511 -        (!m n. 1 \<le> m \<and> m \<le> dimindex(:N) \<and>
  2.2512 -               1 \<le> n \<and> n \<le> dimindex(:N) \<and> ~(m = n)
  2.2513 -               ==> P(lambda i j. (mat 1:real^N^N)$i$(swap(m,n) j))) \<and>
  2.2514 -        (!m n c. 1 \<le> m \<and> m \<le> dimindex(:N) \<and>
  2.2515 -                 1 \<le> n \<and> n \<le> dimindex(:N) \<and> ~(m = n)
  2.2516 -                 ==> P(lambda i j. if i = m \<and> j = n then c
  2.2517 -                                   else if i = j then 1 else 0))
  2.2518 -        ==> !A. P A"
  2.2519 -qed   GEN_TAC THEN
  2.2520 -  DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC MP_TAC) THEN
  2.2521 -  DISCH_THEN(fun th ->
  2.2522 -    MATCH_MP_TAC INDUCT_MATRIX_ROW_OPERATIONS THEN MP_TAC th) THEN
  2.2523 -  REPEAT(MATCH_MP_TAC MONO_AND THEN CONJ_TAC) THEN REWRITE_TAC[] THEN
  2.2524 -  DISCH_THEN(fun th -> X_GEN_TAC `A:real^N^N` THEN MP_TAC th) THEN
  2.2525 -  REPEAT(MATCH_MP_TAC MONO_FORALL THEN GEN_TAC) THEN
  2.2526 -  DISCH_THEN(fun th -> STRIP_TAC THEN MP_TAC th) THEN ASM_REWRITE_TAC[] THEN
  2.2527 -  UNDISCH_TAC `(P:real^N^N->bool) A` THENL
  2.2528 -   [REWRITE_TAC[GSYM IMP_CONJ]; REWRITE_TAC[GSYM IMP_CONJ_ALT]] THEN
  2.2529 -  DISCH_THEN(ANTE_RES_THEN MP_TAC) THEN MATCH_MP_TAC EQ_IMP THEN
  2.2530 -  AP_TERM_TAC THEN REWRITE_TAC[CART_EQ] THEN
  2.2531 -  X_GEN_TAC `i:num` THEN STRIP_TAC THEN
  2.2532 -  X_GEN_TAC `j:num` THEN STRIP_TAC THEN
  2.2533 -  ASM_SIMP_TAC[CART_EQ; LAMBDA_BETA; matrix_mul; row] THENL
  2.2534 -   [ASM_SIMP_TAC[mat; IN_DIMINDEX_SWAP; LAMBDA_BETA] THEN
  2.2535 -    ONCE_REWRITE_TAC[COND_RAND] THEN
  2.2536 -    SIMP_TAC[SUM_DELTA; REAL_MUL_RZERO; REAL_MUL_RID] THEN
  2.2537 -    COND_CASES_TAC THEN REWRITE_TAC[] THEN
  2.2538 -    RULE_ASSUM_TAC(REWRITE_RULE[swap; IN_NUMSEG]) THEN ASM_ARITH_TAC;
  2.2539 -    ALL_TAC] THEN
  2.2540 -  ASM_CASES_TAC `i:num = m` THEN ASM_REWRITE_TAC[] THENL
  2.2541 -   [ALL_TAC;
  2.2542 -    ONCE_REWRITE_TAC[COND_RAND] THEN ONCE_REWRITE_TAC[COND_RATOR] THEN
  2.2543 -    REWRITE_TAC[REAL_MUL_LZERO] THEN
  2.2544 -    GEN_REWRITE_TAC (LAND_CONV o ONCE_DEPTH_CONV) [EQ_SYM_EQ] THEN
  2.2545 -    ASM_SIMP_TAC[SUM_DELTA; LAMBDA_BETA; IN_NUMSEG; REAL_MUL_LID]] THEN
  2.2546 -  ASM_SIMP_TAC[VECTOR_ADD_COMPONENT; VECTOR_MUL_COMPONENT; LAMBDA_BETA] THEN
  2.2547 -  MATCH_MP_TAC EQ_TRANS THEN
  2.2548 -  EXISTS_TAC
  2.2549 -    `sum {m,n} (\<lambda>k. (if k = n then c else if m = k then 1 else 0) *
  2.2550 -                    (A:real^N^N)$k$j)` THEN
  2.2551 -  CONJ_TAC THENL
  2.2552 -   [MATCH_MP_TAC SUM_SUPERSET THEN
  2.2553 -    ASM_SIMP_TAC[SUBSET; IN_INSERT; NOT_IN_EMPTY; DE_MORGAN_THM;
  2.2554 -                 IN_NUMSEG; REAL_MUL_LZERO] THEN
  2.2555 -    ASM_ARITH_TAC;
  2.2556 -    ASM_SIMP_TAC[SUM_CLAUSES; FINITE_RULES; IN_INSERT; NOT_IN_EMPTY] THEN
  2.2557 -    REAL_ARITH_TAC]);; *)
  2.2558 -
  2.2559 -lemma INDUCT_MATRIX_ELEMENTARY_ALT: True .. (*
  2.2560 - "!P:real^N^N->bool.
  2.2561 -        (!A B. P A \<and> P B ==> P(A ** B)) \<and>
  2.2562 -        (!A i. 1 \<le> i \<and> i \<le> dimindex(:N) \<and> row i A = 0 ==> P A) \<and>
  2.2563 -        (!A. (!i j. 1 \<le> i \<and> i \<le> dimindex(:N) \<and>
  2.2564 -                    1 \<le> j \<and> j \<le> dimindex(:N) \<and> ~(i = j)
  2.2565 -                    ==> A$i$j = 0) ==> P A) \<and>
  2.2566 -        (!m n. 1 \<le> m \<and> m \<le> dimindex(:N) \<and>
  2.2567 -               1 \<le> n \<and> n \<le> dimindex(:N) \<and> ~(m = n)
  2.2568 -               ==> P(lambda i j. (mat 1:real^N^N)$i$(swap(m,n) j))) \<and>
  2.2569 -        (!m n. 1 \<le> m \<and> m \<le> dimindex(:N) \<and>
  2.2570 -               1 \<le> n \<and> n \<le> dimindex(:N) \<and> ~(m = n)
  2.2571 -               ==> P(lambda i j. if i = m \<and> j = n \/ i = j then 1 else 0))
  2.2572 -        ==> !A. P A"
  2.2573 -qed   GEN_TAC THEN STRIP_TAC THEN MATCH_MP_TAC INDUCT_MATRIX_ELEMENTARY THEN
  2.2574 -  ASM_REWRITE_TAC[] THEN REPEAT STRIP_TAC THEN
  2.2575 -  ASM_CASES_TAC `c = 0` THENL
  2.2576 -   [FIRST_X_ASSUM(fun th -> MATCH_MP_TAC th THEN
  2.2577 -        MAP_EVERY X_GEN_TAC [`i:num`; `j:num`]) THEN
  2.2578 -    ASM_SIMP_TAC[LAMBDA_BETA; COND_ID];
  2.2579 -    ALL_TAC] THEN
  2.2580 -  SUBGOAL_THEN
  2.2581 -   `(lambda i j. if i = m \<and> j = n then c else if i = j then 1 else 0) =
  2.2582 -  ((lambda i j. if i = j then if j = n then inv c else 1 else 0):real^N^N) **
  2.2583 -    ((lambda i j. if i = m \<and> j = n \/ i = j then 1 else 0):real^N^N) **
  2.2584 -    ((lambda i j. if i = j then if j = n then c else 1 else 0):real^N^N)`
  2.2585 -  SUBST1_TAC THENL
  2.2586 -   [ALL_TAC;
  2.2587 -    REPEAT(MATCH_MP_TAC(ASSUME `!A B:real^N^N. P A \<and> P B ==> P(A ** B)`) THEN
  2.2588 -           CONJ_TAC) THEN
  2.2589 -    ASM_SIMP_TAC[] THEN FIRST_X_ASSUM(fun th -> MATCH_MP_TAC th THEN
  2.2590 -        MAP_EVERY X_GEN_TAC [`i:num`; `j:num`]) THEN
  2.2591 -    ASM_SIMP_TAC[LAMBDA_BETA]] THEN
  2.2592 -  SIMP_TAC[CART_EQ; matrix_mul; LAMBDA_BETA] THEN
  2.2593 -  X_GEN_TAC `i:num` THEN STRIP_TAC THEN
  2.2594 -  X_GEN_TAC `j:num` THEN STRIP_TAC THEN
  2.2595 -  ASM_SIMP_TAC[SUM_DELTA; IN_NUMSEG; REAL_ARITH
  2.2596 -       `(if p then 1 else 0) * (if q then c else 0) =
  2.2597 -        if q then if p then c else 0 else 0`] THEN
  2.2598 -  REWRITE_TAC[REAL_ARITH
  2.2599 -   `(if p then x else 0) * y = (if p then x * y else 0)`] THEN
  2.2600 -  GEN_REWRITE_TAC (RAND_CONV o ONCE_DEPTH_CONV) [EQ_SYM_EQ] THEN
  2.2601 -  ASM_SIMP_TAC[SUM_DELTA; IN_NUMSEG] THEN
  2.2602 -  ASM_CASES_TAC `i:num = m` THEN ASM_REWRITE_TAC[] THEN
  2.2603 -  ASM_CASES_TAC `j:num = n` THEN ASM_REWRITE_TAC[REAL_MUL_LID; EQ_SYM_EQ] THEN
  2.2604 -  ASM_CASES_TAC `i:num = n` THEN
  2.2605 -  ASM_SIMP_TAC[REAL_MUL_LINV; REAL_MUL_LID; REAL_MUL_RZERO]);; *)
  2.2606 -
  2.2607 -(* ------------------------------------------------------------------------- *)
  2.2608 -(* The same thing in mapping form (might have been easier all along).        *)
  2.2609 -(* ------------------------------------------------------------------------- *)
  2.2610 -
  2.2611 -lemma INDUCT_LINEAR_ELEMENTARY: True .. (*
  2.2612 - "!P. (!f g. linear f \<and> linear g \<and> P f \<and> P g ==> P(f o g)) \<and>
  2.2613 -       (!f i. linear f \<and> 1 \<le> i \<and> i \<le> dimindex(:N) \<and> (!x. (f x)$i = 0)
  2.2614 -              ==> P f) \<and>
  2.2615 -       (!c. P(\<lambda>x. lambda i. c i * x$i)) \<and>
  2.2616 -       (!m n. 1 \<le> m \<and> m \<le> dimindex(:N) \<and>
  2.2617 -              1 \<le> n \<and> n \<le> dimindex(:N) \<and> ~(m = n)
  2.2618 -              ==> P(\<lambda>x. lambda i. x$swap(m,n) i)) \<and>
  2.2619 -       (!m n. 1 \<le> m \<and> m \<le> dimindex(:N) \<and>
  2.2620 -              1 \<le> n \<and> n \<le> dimindex(:N) \<and> ~(m = n)
  2.2621 -              ==> P(\<lambda>x. lambda i. if i = m then x$m + x$n else x$i))
  2.2622 -       ==> !f:real^N->real^N. linear f ==> P f"
  2.2623 -qed   GEN_TAC THEN
  2.2624 -  MP_TAC(ISPEC `\A:real^N^N. P(\<lambda>x:real^N. A ** x):bool`
  2.2625 -    INDUCT_MATRIX_ELEMENTARY_ALT) THEN
  2.2626 -  REWRITE_TAC[] THEN MATCH_MP_TAC MONO_IMP THEN CONJ_TAC THENL
  2.2627 -   [ALL_TAC;
  2.2628 -    DISCH_TAC THEN X_GEN_TAC `f:real^N->real^N` THEN DISCH_TAC THEN
  2.2629 -    FIRST_X_ASSUM(MP_TAC o SPEC `matrix(f:real^N->real^N)`) THEN
  2.2630 -    ASM_SIMP_TAC[MATRIX_WORKS] THEN REWRITE_TAC[ETA_AX]] THEN
  2.2631 -  MATCH_MP_TAC MONO_AND THEN CONJ_TAC THENL
  2.2632 -   [DISCH_TAC THEN MAP_EVERY X_GEN_TAC [`A:real^N^N`; `B:real^N^N`] THEN
  2.2633 -    STRIP_TAC THEN FIRST_X_ASSUM(MP_TAC o SPECL
  2.2634 -     [`\x:real^N. (A:real^N^N) ** x`; `\x:real^N. (B:real^N^N) ** x`]) THEN
  2.2635 -    ASM_REWRITE_TAC[MATRIX_VECTOR_MUL_LINEAR; o_DEF] THEN
  2.2636 -    REWRITE_TAC[MATRIX_VECTOR_MUL_ASSOC];
  2.2637 -    ALL_TAC] THEN
  2.2638 -  MATCH_MP_TAC MONO_AND THEN CONJ_TAC THENL
  2.2639 -   [DISCH_TAC THEN MAP_EVERY X_GEN_TAC [`A:real^N^N`; `m:num`] THEN
  2.2640 -    STRIP_TAC THEN FIRST_X_ASSUM(MP_TAC o SPECL
  2.2641 -     [`\x:real^N. (A:real^N^N) ** x`; `m:num`]) THEN
  2.2642 -    ASM_REWRITE_TAC[MATRIX_VECTOR_MUL_LINEAR] THEN
  2.2643 -    DISCH_THEN MATCH_MP_TAC THEN
  2.2644 -    UNDISCH_TAC `row m (A:real^N^N) = 0` THEN
  2.2645 -    ASM_SIMP_TAC[CART_EQ; row; LAMBDA_BETA; VEC_COMPONENT; matrix_vector_mul;
  2.2646 -                 REAL_MUL_LZERO; SUM_0];
  2.2647 -    ALL_TAC] THEN
  2.2648 -  MATCH_MP_TAC MONO_AND THEN CONJ_TAC THENL
  2.2649 -   [DISCH_TAC THEN X_GEN_TAC `A:real^N^N` THEN STRIP_TAC THEN
  2.2650 -    FIRST_X_ASSUM(MP_TAC o SPEC `\i. (A:real^N^N)$i$i`) THEN
  2.2651 -    MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN
  2.2652 -    ASM_SIMP_TAC[CART_EQ; matrix_vector_mul; FUN_EQ_THM; LAMBDA_BETA] THEN
  2.2653 -    MAP_EVERY X_GEN_TAC [`x:real^N`; `i:num`] THEN STRIP_TAC THEN
  2.2654 -    MATCH_MP_TAC EQ_TRANS THEN EXISTS_TAC
  2.2655 -     `sum(1..dimindex(:N)) (\<lambda>j. if j = i then (A:real^N^N)$i$j * (x:real^N)$j
  2.2656 -                                else 0)` THEN
  2.2657 -    CONJ_TAC THENL [ASM_SIMP_TAC[SUM_DELTA; IN_NUMSEG]; ALL_TAC] THEN
  2.2658 -    MATCH_MP_TAC SUM_EQ_NUMSEG THEN X_GEN_TAC `j:num` THEN STRIP_TAC THEN
  2.2659 -    ASM_SIMP_TAC[] THEN COND_CASES_TAC THEN ASM_SIMP_TAC[REAL_MUL_LZERO];
  2.2660 -    ALL_TAC] THEN
  2.2661 -  MATCH_MP_TAC MONO_AND THEN CONJ_TAC THEN
  2.2662 -  MATCH_MP_TAC MONO_FORALL THEN X_GEN_TAC `m:num` THEN
  2.2663 -  MATCH_MP_TAC MONO_FORALL THEN X_GEN_TAC `n:num` THEN
  2.2664 -  DISCH_THEN(fun th -> STRIP_TAC THEN MP_TAC th) THEN
  2.2665 -  ASM_REWRITE_TAC[] THEN MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN
  2.2666 -  ASM_SIMP_TAC[CART_EQ; matrix_vector_mul; FUN_EQ_THM; LAMBDA_BETA;
  2.2667 -               mat; IN_DIMINDEX_SWAP]
  2.2668 -  THENL
  2.2669 -   [ONCE_REWRITE_TAC[SWAP_GALOIS] THEN ONCE_REWRITE_TAC[COND_RAND] THEN
  2.2670 -    ONCE_REWRITE_TAC[COND_RATOR] THEN
  2.2671 -    SIMP_TAC[SUM_DELTA; REAL_MUL_LID; REAL_MUL_LZERO; IN_NUMSEG] THEN
  2.2672 -    REPEAT STRIP_TAC THEN REWRITE_TAC[swap] THEN
  2.2673 -    COND_CASES_TAC THEN ASM_REWRITE_TAC[] THEN ASM_ARITH_TAC;
  2.2674 -    MAP_EVERY X_GEN_TAC [`x:real^N`; `i:num`] THEN STRIP_TAC THEN
  2.2675 -    ASM_CASES_TAC `i:num = m` THEN ASM_REWRITE_TAC[] THEN
  2.2676 -    ONCE_REWRITE_TAC[COND_RAND] THEN ONCE_REWRITE_TAC[COND_RATOR] THEN
  2.2677 -    GEN_REWRITE_TAC (RAND_CONV o ONCE_DEPTH_CONV) [EQ_SYM_EQ] THEN
  2.2678 -    ASM_SIMP_TAC[SUM_DELTA; REAL_MUL_LZERO; REAL_MUL_LID; IN_NUMSEG] THEN
  2.2679 -    MATCH_MP_TAC EQ_TRANS THEN EXISTS_TAC
  2.2680 -     `sum {m,n} (\<lambda>j. if n = j \/ j = m then (x:real^N)$j else 0)` THEN
  2.2681 -    CONJ_TAC THENL
  2.2682 -     [SIMP_TAC[SUM_CLAUSES; FINITE_RULES; IN_INSERT; NOT_IN_EMPTY] THEN
  2.2683 -      ASM_REWRITE_TAC[REAL_ADD_RID];
  2.2684 -      CONV_TAC SYM_CONV THEN MATCH_MP_TAC SUM_SUPERSET THEN
  2.2685 -      ASM_SIMP_TAC[SUBSET; IN_INSERT; NOT_IN_EMPTY; DE_MORGAN_THM;
  2.2686 -                   IN_NUMSEG; REAL_MUL_LZERO] THEN
  2.2687 -      ASM_ARITH_TAC]]);; *)
  2.2688 -
  2.2689 -(* ------------------------------------------------------------------------- *)
  2.2690 -(* Hence the effect of an arbitrary linear map on a gmeasurable set.          *)
  2.2691 -(* ------------------------------------------------------------------------- *)
  2.2692 -
  2.2693 -lemma LAMBDA_SWAP_GALOIS: True .. (*
  2.2694 - "!x:real^N y:real^N.
  2.2695 -        1 \<le> m \<and> m \<le> dimindex(:N) \<and> 1 \<le> n \<and> n \<le> dimindex(:N)
  2.2696 -        ==> (x = (lambda i. y$swap(m,n) i) \<longleftrightarrow>
  2.2697 -             (lambda i. x$swap(m,n) i) = y)"
  2.2698 -qed   SIMP_TAC[CART_EQ; LAMBDA_BETA; IN_DIMINDEX_SWAP] THEN
  2.2699 -  REPEAT GEN_TAC THEN STRIP_TAC THEN EQ_TAC THEN
  2.2700 -  DISCH_TAC THEN X_GEN_TAC `i:num` THEN STRIP_TAC THEN
  2.2701 -  FIRST_X_ASSUM(MP_TAC o SPEC `swap(m,n) (i:num)`) THEN
  2.2702 -  ASM_SIMP_TAC[IN_DIMINDEX_SWAP] THEN
  2.2703 -  ASM_MESON_TAC[REWRITE_RULE[FUN_EQ_THM; o_THM; I_THM] SWAP_IDEMPOTENT]);; *)
  2.2704 -
  2.2705 -lemma LAMBDA_ADD_GALOIS: True .. (*
  2.2706 - "!x:real^N y:real^N.
  2.2707 -        1 \<le> m \<and> m \<le> dimindex(:N) \<and> 1 \<le> n \<and> n \<le> dimindex(:N) \<and>
  2.2708 -        ~(m = n)
  2.2709 -        ==> (x = (lambda i. if i = m then y$m + y$n else y$i) \<longleftrightarrow>
  2.2710 -             (lambda i. if i = m then x$m - x$n else x$i) = y)"
  2.2711 -qed   SIMP_TAC[CART_EQ; LAMBDA_BETA] THEN
  2.2712 -  REPEAT GEN_TAC THEN STRIP_TAC THEN EQ_TAC THEN
  2.2713 -  DISCH_TAC THEN X_GEN_TAC `i:num` THEN STRIP_TAC THEN
  2.2714 -  FIRST_ASSUM(MP_TAC o SPEC `n:num`) THEN
  2.2715 -  FIRST_X_ASSUM(MP_TAC o SPEC `i:num`) THEN
  2.2716 -  ASM_REWRITE_TAC[] THEN COND_CASES_TAC THEN ASM_REWRITE_TAC[] THEN
  2.2717 -  REAL_ARITH_TAC);; *)
  2.2718 -
  2.2719 -lemma HAS_GMEASURE_SHEAR_INTERVAL: True .. (*
  2.2720 - "!a b:real^N m n.
  2.2721 -        1 \<le> m \<and> m \<le> dimindex(:N) \<and>
  2.2722 -        1 \<le> n \<and> n \<le> dimindex(:N) \<and>
  2.2723 -        ~(m = n) \<and> ~({a..b} = {}) \<and>
  2.2724 -        0 \<le> a$n
  2.2725 -        ==> (IMAGE (\<lambda>x. (lambda i. if i = m then x$m + x$n else x$i))
  2.2726 -                   {a..b}:real^N->bool)
  2.2727 -            has_gmeasure gmeasure (interval [a,b])"
  2.2728 -qed   lemma lemma = prove
  2.2729 -   (`!s t u v:real^N->bool.
  2.2730 -          gmeasurable s \<and> gmeasurable t \<and> gmeasurable u \<and>
  2.2731 -          negligible(s \<inter> t) \<and> negligible(s \<inter> u) \<and>
  2.2732 -          negligible(t \<inter> u) \<and>
  2.2733 -          s \<union> t \<union> u = v
  2.2734 -          ==> v has_gmeasure (measure s) + (measure t) + (measure u)"
  2.2735 -qed     REPEAT STRIP_TAC THEN
  2.2736 -    ASM_SIMP_TAC[HAS_GMEASURE_MEASURABLE_MEASURE; GMEASURABLE_UNION] THEN
  2.2737 -    FIRST_X_ASSUM(SUBST1_TAC o SYM) THEN
  2.2738 -    ASM_SIMP_TAC[MEASURE_UNION; GMEASURABLE_UNION] THEN
  2.2739 -    ASM_SIMP_TAC[MEASURE_EQ_0; UNION_OVER_INTER; MEASURE_UNION;
  2.2740 -                 GMEASURABLE_UNION; NEGLIGIBLE_INTER; GMEASURABLE_INTER] THEN
  2.2741 -    REAL_ARITH_TAC)
  2.2742 -  and lemma' = prove
  2.2743 -   (`!s t u a.
  2.2744 -          gmeasurable s \<and> gmeasurable t \<and>
  2.2745 -          s \<union> (IMAGE (\<lambda>x. a + x) t) = u \<and>
  2.2746 -          negligible(s \<inter> (IMAGE (\<lambda>x. a + x) t))
  2.2747 -          ==> gmeasure s + gmeasure t = gmeasure u"
  2.2748 -qed     REPEAT STRIP_TAC THEN FIRST_X_ASSUM(SUBST_ALL_TAC o SYM) THEN
  2.2749 -    ASM_SIMP_TAC[MEASURE_NEGLIGIBLE_UNION; GMEASURABLE_TRANSLATION;
  2.2750 -                 MEASURE_TRANSLATION]) in
  2.2751 -  REWRITE_TAC[INTERVAL_NE_EMPTY] THEN REPEAT STRIP_TAC THEN
  2.2752 -  SUBGOAL_THEN
  2.2753 -   `linear((\<lambda>x. lambda i. if i = m then x$m + x$n else x$i):real^N->real^N)`
  2.2754 -  ASSUME_TAC THENL
  2.2755 -   [ASM_SIMP_TAC[linear; LAMBDA_BETA; VECTOR_ADD_COMPONENT;
  2.2756 -                 VECTOR_MUL_COMPONENT; CART_EQ] THEN REAL_ARITH_TAC;
  2.2757 -    ALL_TAC] THEN
  2.2758 -  MP_TAC(ISPECL
  2.2759 -   [`IMAGE (\<lambda>x. lambda i. if i = m then x$m + x$n else x$i)
  2.2760 -            (interval[a:real^N,b]):real^N->bool`;
  2.2761 -    `interval[a,(lambda i. if i = m then (b:real^N)$m + b$n else b$i)] INTER
  2.2762 -       {x:real^N | (basis m - basis n) dot x \<le> a$m}`;
  2.2763 -    `interval[a,(lambda i. if i = m then b$m + b$n else b$i)] INTER
  2.2764 -       {x:real^N | (basis m - basis n) dot x >= (b:real^N)$m}`;
  2.2765 -    `interval[a:real^N,
  2.2766 -              (lambda i. if i = m then (b:real^N)$m + b$n else b$i)]`]
  2.2767 -     lemma) THEN
  2.2768 -  ANTS_TAC THENL
  2.2769 -   [ASM_SIMP_TAC[CONVEX_LINEAR_IMAGE; CONVEX_INTERVAL;
  2.2770 -                 CONVEX_HALFSPACE_LE; CONVEX_HALFSPACE_GE;
  2.2771 -                 CONVEX_INTER; GMEASURABLE_CONVEX; BOUNDED_INTER;
  2.2772 -                 BOUNDED_LINEAR_IMAGE; BOUNDED_INTERVAL] THEN
  2.2773 -    REWRITE_TAC[INTER] THEN
  2.2774 -    REWRITE_TAC[EXTENSION; IN_UNION; IN_INTER; IN_IMAGE] THEN
  2.2775 -    ASM_SIMP_TAC[LAMBDA_ADD_GALOIS; UNWIND_THM1] THEN
  2.2776 -    ASM_SIMP_TAC[IN_INTERVAL; IN_ELIM_THM; LAMBDA_BETA;
  2.2777 -                 DOT_BASIS; DOT_LSUB] THEN
  2.2778 -    ONCE_REWRITE_TAC[MESON[]
  2.2779 -       `(!i:num. P i) \<longleftrightarrow> P m \<and> (!i. ~(i = m) ==> P i)`] THEN
  2.2780 -    ASM_SIMP_TAC[] THEN
  2.2781 -    REWRITE_TAC[TAUT `(p \<and> x) \<and> (q \<and> x) \<and> r \<longleftrightarrow> x \<and> p \<and> q \<and> r`;
  2.2782 -                TAUT `(p \<and> x) \<and> q \<and> (r \<and> x) \<longleftrightarrow> x \<and> p \<and> q \<and> r`;
  2.2783 -                TAUT `((p \<and> x) \<and> q) \<and> (r \<and> x) \<and> s \<longleftrightarrow>
  2.2784 -                            x \<and> p \<and> q \<and> r \<and> s`;
  2.2785 -            TAUT `(a \<and> x \/ (b \<and> x) \<and> c \/ (d \<and> x) \<and> e \<longleftrightarrow> f \<and> x) \<longleftrightarrow>
  2.2786 -                  x ==> (a \/ b \<and> c \/ d \<and> e \<longleftrightarrow> f)`] THEN
  2.2787 -    ONCE_REWRITE_TAC[SET_RULE
  2.2788 -     `{x | P x \<and> Q x} = {x | P x} \<inter> {x | Q x}`] THEN
  2.2789 -    REWRITE_TAC[CONJ_ASSOC] THEN CONJ_TAC THENL
  2.2790 -     [ALL_TAC;
  2.2791 -      GEN_TAC THEN DISCH_THEN(MP_TAC o SPEC `n:num`) THEN
  2.2792 -      ASM_REWRITE_TAC[] THEN ASM_REAL_ARITH_TAC] THEN
  2.2793 -    REWRITE_TAC[GSYM CONJ_ASSOC] THEN REPEAT CONJ_TAC THEN
  2.2794 -    MATCH_MP_TAC NEGLIGIBLE_INTER THEN DISJ2_TAC THEN
  2.2795 -    MATCH_MP_TAC NEGLIGIBLE_SUBSET THENL
  2.2796 -     [EXISTS_TAC `{x:real^N | (basis m - basis n) dot x = (a:real^N)$m}`;
  2.2797 -      EXISTS_TAC `{x:real^N | (basis m - basis n) dot x = (b:real^N)$m}`;
  2.2798 -      EXISTS_TAC `{x:real^N | (basis m - basis n) dot x = (b:real^N)$m}`]
  2.2799 -    THEN (CONJ_TAC THENL
  2.2800 -      [MATCH_MP_TAC NEGLIGIBLE_HYPERPLANE THEN
  2.2801 -       REWRITE_TAC[VECTOR_SUB_EQ] THEN
  2.2802 -       ASM_MESON_TAC[BASIS_INJ];
  2.2803 -       ASM_SIMP_TAC[DOT_LSUB; DOT_BASIS; SUBSET; IN_ELIM_THM;
  2.2804 -                    NOT_IN_EMPTY] THEN
  2.2805 -       FIRST_X_ASSUM(MP_TAC o SPEC `m:num`) THEN ASM_REWRITE_TAC[] THEN
  2.2806 -       ASM_REAL_ARITH_TAC]);
  2.2807 -    ALL_TAC] THEN
  2.2808 -  ASM_SIMP_TAC[HAS_GMEASURE_MEASURABLE_MEASURE;
  2.2809 -               GMEASURABLE_LINEAR_IMAGE_INTERVAL;
  2.2810 -               GMEASURABLE_INTERVAL] THEN
  2.2811 -  MP_TAC(ISPECL
  2.2812 -   [`interval[a,(lambda i. if i = m then (b:real^N)$m + b$n else b$i)] INTER
  2.2813 -       {x:real^N | (basis m - basis n) dot x \<le> a$m}`;
  2.2814 -    `interval[a,(lambda i. if i = m then b$m + b$n else b$i)] INTER
  2.2815 -       {x:real^N | (basis m - basis n) dot x >= (b:real^N)$m}`;
  2.2816 -    `interval[a:real^N,
  2.2817 -              (lambda i. if i = m then (a:real^N)$m + b$n
  2.2818 -                         else (b:real^N)$i)]`;
  2.2819 -    `(lambda i. if i = m then (a:real^N)$m - (b:real^N)$m
  2.2820 -                else 0):real^N`]
  2.2821 -     lemma') THEN
  2.2822 -  ANTS_TAC THENL
  2.2823 -   [ASM_SIMP_TAC[CONVEX_LINEAR_IMAGE; CONVEX_INTERVAL;
  2.2824 -                 CONVEX_HALFSPACE_LE; CONVEX_HALFSPACE_GE;
  2.2825 -                 CONVEX_INTER; GMEASURABLE_CONVEX; BOUNDED_INTER;
  2.2826 -                 BOUNDED_LINEAR_IMAGE; BOUNDED_INTERVAL] THEN
  2.2827 -    REWRITE_TAC[INTER] THEN
  2.2828 -    REWRITE_TAC[EXTENSION; IN_UNION; IN_INTER; IN_IMAGE] THEN
  2.2829 -    ONCE_REWRITE_TAC[VECTOR_ARITH `x:real^N = (lambda i. p i) + y \<longleftrightarrow>
  2.2830 -                                   x - (lambda i. p i) = y`] THEN
  2.2831 -    ASM_SIMP_TAC[IN_INTERVAL; IN_ELIM_THM; LAMBDA_BETA;
  2.2832 -                 DOT_BASIS; DOT_LSUB; UNWIND_THM1;
  2.2833 -                 VECTOR_SUB_COMPONENT] THEN
  2.2834 -    ONCE_REWRITE_TAC[MESON[]
  2.2835 -       `(!i:num. P i) \<longleftrightarrow> P m \<and> (!i. ~(i = m) ==> P i)`] THEN
  2.2836 -    ASM_SIMP_TAC[REAL_SUB_RZERO] THEN CONJ_TAC THENL
  2.2837 -     [X_GEN_TAC `x:real^N` THEN
  2.2838 -      FIRST_ASSUM(MP_TAC o SPEC `n:num`) THEN
  2.2839 -      FIRST_X_ASSUM(MP_TAC o SPEC `m:num`) THEN
  2.2840 -      ASM_REWRITE_TAC[] THEN
  2.2841 -      ASM_CASES_TAC
  2.2842 -       `!i. ~(i = m)
  2.2843 -            ==> 1 \<le> i \<and> i \<le> dimindex (:N)
  2.2844 -                ==> (a:real^N)$i \<le> (x:real^N)$i \<and>
  2.2845 -                    x$i \<le> (b:real^N)$i` THEN
  2.2846 -      ASM_REWRITE_TAC[] THEN
  2.2847 -      FIRST_X_ASSUM(MP_TAC o SPEC `n:num`) THEN
  2.2848 -      ASM_REWRITE_TAC[] THEN ASM_REAL_ARITH_TAC;
  2.2849 -      ONCE_REWRITE_TAC[TAUT `((a \<and> b) \<and> c) \<and> (d \<and> e) \<and> f \<longleftrightarrow>
  2.2850 -                             (b \<and> e) \<and> a \<and> c \<and> d \<and> f`] THEN
  2.2851 -      ONCE_REWRITE_TAC[SET_RULE
  2.2852 -       `{x | P x \<and> Q x} = {x | P x} \<inter> {x | Q x}`] THEN
  2.2853 -      MATCH_MP_TAC NEGLIGIBLE_INTER THEN DISJ2_TAC THEN
  2.2854 -      MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.2855 -      EXISTS_TAC `{x:real^N | (basis m - basis n) dot x = (a:real^N)$m}`
  2.2856 -      THEN CONJ_TAC THENL
  2.2857 -       [MATCH_MP_TAC NEGLIGIBLE_HYPERPLANE THEN
  2.2858 -        REWRITE_TAC[VECTOR_SUB_EQ] THEN
  2.2859 -        ASM_MESON_TAC[BASIS_INJ];
  2.2860 -        ASM_SIMP_TAC[DOT_LSUB; DOT_BASIS; SUBSET; IN_ELIM_THM;
  2.2861 -                     NOT_IN_EMPTY] THEN
  2.2862 -        FIRST_ASSUM(MP_TAC o SPEC `n:num`) THEN
  2.2863 -        FIRST_X_ASSUM(MP_TAC o SPEC `m:num`) THEN
  2.2864 -        ASM_REWRITE_TAC[] THEN ASM_REAL_ARITH_TAC]];
  2.2865 -    ALL_TAC] THEN
  2.2866 -  DISCH_THEN SUBST1_TAC THEN MATCH_MP_TAC(REAL_ARITH
  2.2867 -   `a = b + c ==> a = x + b ==> x = c`) THEN
  2.2868 -  ASM_SIMP_TAC[MEASURE_INTERVAL; CONTENT_CLOSED_INTERVAL_CASES;
  2.2869 -               LAMBDA_BETA] THEN
  2.2870 -  REPEAT(COND_CASES_TAC THENL
  2.2871 -   [ALL_TAC;
  2.2872 -    FIRST_X_ASSUM(MP_TAC o check (is_neg o concl)) THEN
  2.2873 -    MATCH_MP_TAC(TAUT `p ==> ~p ==> q`) THEN
  2.2874 -    X_GEN_TAC `i:num` THEN STRIP_TAC THEN
  2.2875 -    COND_CASES_TAC THEN ASM_SIMP_TAC[] THEN
  2.2876 -    FIRST_ASSUM(MP_TAC o SPEC `n:num`) THEN
  2.2877 -    FIRST_X_ASSUM(MP_TAC o SPEC `m:num`) THEN
  2.2878 -    ASM_REWRITE_TAC[] THEN ASM_REAL_ARITH_TAC]) THEN
  2.2879 -  SUBGOAL_THEN `1..dimindex(:N) = m INSERT ((1..dimindex(:N)) DELETE m)`
  2.2880 -  SUBST1_TAC THENL
  2.2881 -   [REWRITE_TAC[EXTENSION; IN_INSERT; IN_DELETE; IN_NUMSEG] THEN
  2.2882 -    ASM_ARITH_TAC;
  2.2883 -    ALL_TAC] THEN
  2.2884 -  SIMP_TAC[PRODUCT_CLAUSES; FINITE_DELETE; FINITE_NUMSEG] THEN
  2.2885 -  ASM_SIMP_TAC[IN_DELETE] THEN
  2.2886 -  MATCH_MP_TAC(REAL_RING
  2.2887 -   `s1 = s3 \<and> s2 = s3
  2.2888 -    ==> ((bm + bn) - am) * s1 =
  2.2889 -        ((am + bn) - am) * s2 + (bm - am) * s3`) THEN
  2.2890 -  CONJ_TAC THEN MATCH_MP_TAC PRODUCT_EQ THEN
  2.2891 -  SIMP_TAC[IN_DELETE] THEN REAL_ARITH_TAC);; *)
  2.2892 -
  2.2893 -lemma HAS_GMEASURE_LINEAR_IMAGE: True .. (*
  2.2894 - "!f:real^N->real^N s.
  2.2895 -        linear f \<and> gmeasurable s
  2.2896 -        ==> (IMAGE f s) has_gmeasure (abs(det(matrix f)) * gmeasure s)"
  2.2897 -qed   REWRITE_TAC[IMP_CONJ; RIGHT_FORALL_IMP_THM] THEN
  2.2898 -  MATCH_MP_TAC INDUCT_LINEAR_ELEMENTARY THEN REPEAT CONJ_TAC THENL
  2.2899 -   [MAP_EVERY X_GEN_TAC [`f:real^N->real^N`; `g:real^N->real^N`] THEN
  2.2900 -    REPLICATE_TAC 2 (DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC MP_TAC)) THEN
  2.2901 -    DISCH_THEN(fun th -> REPEAT STRIP_TAC THEN MP_TAC th) THEN
  2.2902 -    DISCH_THEN(CONJUNCTS_THEN2
  2.2903 -     (MP_TAC o SPEC `IMAGE (g:real^N->real^N) s`)
  2.2904 -     (MP_TAC o SPEC `s:real^N->bool`)) THEN
  2.2905 -    ASM_REWRITE_TAC[] THEN
  2.2906 -    GEN_REWRITE_TAC LAND_CONV [HAS_GMEASURE_MEASURABLE_MEASURE] THEN
  2.2907 -    STRIP_TAC THEN ASM_SIMP_TAC[MATRIX_COMPOSE; DET_MUL; REAL_ABS_MUL] THEN
  2.2908 -    REWRITE_TAC[IMAGE_o; GSYM REAL_MUL_ASSOC];
  2.2909 -
  2.2910 -    MAP_EVERY X_GEN_TAC [`f:real^N->real^N`; `m:num`] THEN STRIP_TAC THEN
  2.2911 -    SUBGOAL_THEN `~(!x y. (f:real^N->real^N) x = f y ==> x = y)`
  2.2912 -    ASSUME_TAC THENL
  2.2913 -     [ASM_SIMP_TAC[LINEAR_SINGULAR_INTO_HYPERPLANE] THEN
  2.2914 -      EXISTS_TAC `basis m:real^N` THEN
  2.2915 -      ASM_SIMP_TAC[BASIS_NONZERO; DOT_BASIS];
  2.2916 -      ALL_TAC] THEN
  2.2917 -    MP_TAC(ISPEC `matrix f:real^N^N` INVERTIBLE_DET_NZ) THEN
  2.2918 -    ASM_SIMP_TAC[INVERTIBLE_LEFT_INVERSE; MATRIX_LEFT_INVERTIBLE_INJECTIVE;
  2.2919 -                 MATRIX_WORKS; REAL_ABS_NUM; REAL_MUL_LZERO] THEN
  2.2920 -    DISCH_THEN(K ALL_TAC) THEN REWRITE_TAC[HAS_GMEASURE_0] THEN
  2.2921 -    ASM_SIMP_TAC[NEGLIGIBLE_LINEAR_SINGULAR_IMAGE];
  2.2922 -
  2.2923 -    MAP_EVERY X_GEN_TAC [`c:num->real`; `s:real^N->bool`] THEN
  2.2924 -    DISCH_TAC THEN
  2.2925 -    FIRST_ASSUM(ASSUME_TAC o REWRITE_RULE[HAS_GMEASURE_MEASURE]) THEN
  2.2926 -    FIRST_ASSUM(MP_TAC o SPEC `c:num->real` o
  2.2927 -     MATCH_MP HAS_GMEASURE_STRETCH) THEN
  2.2928 -    MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN
  2.2929 -    AP_THM_TAC THEN AP_TERM_TAC THEN AP_TERM_TAC THEN
  2.2930 -    SIMP_TAC[matrix; LAMBDA_BETA] THEN
  2.2931 -    W(MP_TAC o PART_MATCH (lhs o rand) DET_DIAGONAL o rand o snd) THEN
  2.2932 -    SIMP_TAC[LAMBDA_BETA; BASIS_COMPONENT; REAL_MUL_RZERO] THEN
  2.2933 -    DISCH_THEN(K ALL_TAC) THEN MATCH_MP_TAC PRODUCT_EQ_NUMSEG THEN
  2.2934 -    REWRITE_TAC[REAL_MUL_RID];
  2.2935 -
  2.2936 -    MAP_EVERY X_GEN_TAC [`m:num`; `n:num`] THEN STRIP_TAC THEN
  2.2937 -    MATCH_MP_TAC HAS_GMEASURE_LINEAR_SUFFICIENT THEN
  2.2938 -    ASM_SIMP_TAC[linear; LAMBDA_BETA; IN_DIMINDEX_SWAP; VECTOR_ADD_COMPONENT;
  2.2939 -                 VECTOR_MUL_COMPONENT; CART_EQ] THEN
  2.2940 -    MAP_EVERY X_GEN_TAC [`a:real^N`; `b:real^N`] THEN
  2.2941 -    SUBGOAL_THEN `matrix (\<lambda>x:real^N. lambda i. x$swap (m,n) i):real^N^N =
  2.2942 -                  transp(lambda i j. (mat 1:real^N^N)$i$swap (m,n) j)`
  2.2943 -    SUBST1_TAC THENL
  2.2944 -     [ASM_SIMP_TAC[MATRIX_EQ; LAMBDA_BETA; IN_DIMINDEX_SWAP;
  2.2945 -                    matrix_vector_mul; CART_EQ; matrix; mat; basis;
  2.2946 -                    COND_COMPONENT; transp] THEN
  2.2947 -      REWRITE_TAC[EQ_SYM_EQ];
  2.2948 -      ALL_TAC] THEN
  2.2949 -    REWRITE_TAC[DET_TRANSP] THEN
  2.2950 -    W(MP_TAC o PART_MATCH (lhs o rand) DET_PERMUTE_COLUMNS o
  2.2951 -        rand o lhand o rand o snd) THEN
  2.2952 -    ASM_SIMP_TAC[PERMUTES_SWAP; IN_NUMSEG; ETA_AX] THEN
  2.2953 -    DISCH_THEN(K ALL_TAC) THEN
  2.2954 -    REWRITE_TAC[DET_I; REAL_ABS_SIGN; REAL_MUL_RID; REAL_MUL_LID] THEN
  2.2955 -    ASM_CASES_TAC `interval[a:real^N,b] = {}` THENL
  2.2956 -     [ASM_SIMP_TAC[IMAGE_CLAUSES; HAS_GMEASURE_EMPTY; MEASURE_EMPTY];
  2.2957 -      ALL_TAC] THEN
  2.2958 -    SUBGOAL_THEN
  2.2959 -     `~(IMAGE (\<lambda>x:real^N. lambda i. x$swap (m,n) i)
  2.2960 -              {a..b}:real^N->bool = {})`
  2.2961 -    MP_TAC THENL [ASM_REWRITE_TAC[IMAGE_EQ_EMPTY]; ALL_TAC] THEN
  2.2962 -    SUBGOAL_THEN
  2.2963 -     `IMAGE (\<lambda>x:real^N. lambda i. x$swap (m,n) i)
  2.2964 -              {a..b}:real^N->bool =
  2.2965 -      interval[(lambda i. a$swap (m,n) i),
  2.2966 -               (lambda i. b$swap (m,n) i)]`
  2.2967 -    SUBST1_TAC THENL
  2.2968 -     [REWRITE_TAC[EXTENSION; IN_INTERVAL; IN_IMAGE] THEN
  2.2969 -      ASM_SIMP_TAC[LAMBDA_SWAP_GALOIS; UNWIND_THM1] THEN
  2.2970 -      SIMP_TAC[LAMBDA_BETA] THEN GEN_TAC THEN EQ_TAC THEN
  2.2971 -      DISCH_TAC THEN X_GEN_TAC `i:num` THEN STRIP_TAC THEN
  2.2972 -      FIRST_X_ASSUM(MP_TAC o SPEC `swap(m,n) (i:num)`) THEN
  2.2973 -      ASM_SIMP_TAC[IN_DIMINDEX_SWAP] THEN
  2.2974 -      ASM_MESON_TAC[REWRITE_RULE[FUN_EQ_THM; o_THM; I_THM] SWAP_IDEMPOTENT];
  2.2975 -      ALL_TAC] THEN
  2.2976 -    REWRITE_TAC[HAS_GMEASURE_MEASURABLE_MEASURE; GMEASURABLE_INTERVAL] THEN
  2.2977 -    REWRITE_TAC[MEASURE_INTERVAL] THEN
  2.2978 -    ASM_SIMP_TAC[CONTENT_CLOSED_INTERVAL; GSYM INTERVAL_NE_EMPTY] THEN
  2.2979 -    DISCH_THEN(K ALL_TAC) THEN SIMP_TAC[LAMBDA_BETA] THEN
  2.2980 -    ASM_SIMP_TAC[GSYM VECTOR_SUB_COMPONENT; IN_DIMINDEX_SWAP] THEN
  2.2981 -    MP_TAC(ISPECL [`\i. (b - a:real^N)$i`; `swap(m:num,n)`; `1..dimindex(:N)`]
  2.2982 -                (GSYM PRODUCT_PERMUTE)) THEN
  2.2983 -    REWRITE_TAC[o_DEF] THEN DISCH_THEN MATCH_MP_TAC THEN
  2.2984 -    ASM_SIMP_TAC[PERMUTES_SWAP; IN_NUMSEG];
  2.2985 -
  2.2986 -    MAP_EVERY X_GEN_TAC [`m:num`; `n:num`] THEN STRIP_TAC THEN
  2.2987 -    MATCH_MP_TAC HAS_GMEASURE_LINEAR_SUFFICIENT THEN
  2.2988 -    MATCH_MP_TAC(TAUT `a \<and> (a ==> b) ==> a \<and> b`) THEN CONJ_TAC THENL
  2.2989 -     [ASM_SIMP_TAC[linear; LAMBDA_BETA; VECTOR_ADD_COMPONENT;
  2.2990 -                   VECTOR_MUL_COMPONENT; CART_EQ] THEN REAL_ARITH_TAC;
  2.2991 -      DISCH_TAC] THEN
  2.2992 -    MAP_EVERY X_GEN_TAC [`a:real^N`; `b:real^N`] THEN
  2.2993 -    SUBGOAL_THEN
  2.2994 -      `det(matrix(\<lambda>x. lambda i. if i = m then (x:real^N)$m + x$n
  2.2995 -                                else x$i):real^N^N) = 1`
  2.2996 -    SUBST1_TAC THENL
  2.2997 -     [ASM_SIMP_TAC[matrix; basis; COND_COMPONENT; LAMBDA_BETA] THEN
  2.2998 -      FIRST_ASSUM(DISJ_CASES_TAC o MATCH_MP (ARITH_RULE
  2.2999 -       `~(m:num = n) ==> m < n \/ n < m`))
  2.3000 -      THENL
  2.3001 -       [W(MP_TAC o PART_MATCH (lhs o rand) DET_UPPERTRIANGULAR o lhs o snd);
  2.3002 -        W(MP_TAC o PART_MATCH (lhs o rand) DET_LOWERTRIANGULAR o lhs o snd)]
  2.3003 -      THEN ASM_SIMP_TAC[LAMBDA_BETA; BASIS_COMPONENT; COND_COMPONENT;
  2.3004 -                        matrix; REAL_ADD_RID; COND_ID;
  2.3005 -                        PRODUCT_CONST_NUMSEG; REAL_POW_ONE] THEN
  2.3006 -      DISCH_THEN MATCH_MP_TAC THEN
  2.3007 -      REPEAT GEN_TAC THEN REPEAT(COND_CASES_TAC THEN ASM_REWRITE_TAC[]) THEN
  2.3008 -      ASM_ARITH_TAC;
  2.3009 -      ALL_TAC] THEN
  2.3010 -    REWRITE_TAC[REAL_ABS_NUM; REAL_MUL_LID] THEN
  2.3011 -    ASM_CASES_TAC `interval[a:real^N,b] = {}` THENL
  2.3012 -     [ASM_SIMP_TAC[IMAGE_CLAUSES; HAS_GMEASURE_EMPTY; MEASURE_EMPTY];
  2.3013 -      ALL_TAC] THEN
  2.3014 -    SUBGOAL_THEN
  2.3015 -     `IMAGE (\<lambda>x. lambda i. if i = m then x$m + x$n else x$i) (interval [a,b]) =
  2.3016 -      IMAGE (\<lambda>x:real^N. (lambda i. if i = m \/ i = n then a$n else 0) +
  2.3017 -                        x)
  2.3018 -            (IMAGE (\<lambda>x:real^N. lambda i. if i = m then x$m + x$n else x$i)
  2.3019 -                   (IMAGE (\<lambda>x. (lambda i. if i = n then --(a$n) else 0) + x)
  2.3020 -                          {a..b}))`
  2.3021 -    SUBST1_TAC THENL
  2.3022 -     [REWRITE_TAC[GSYM IMAGE_o] THEN AP_THM_TAC THEN AP_TERM_TAC THEN
  2.3023 -      ASM_SIMP_TAC[FUN_EQ_THM; o_THM; VECTOR_ADD_COMPONENT; LAMBDA_BETA;
  2.3024 -                   CART_EQ] THEN
  2.3025 -      MAP_EVERY X_GEN_TAC [`x:real^N`; `i:num`] THEN
  2.3026 -      STRIP_TAC THEN ASM_CASES_TAC `i:num = m` THEN ASM_REWRITE_TAC[] THEN
  2.3027 -      ASM_CASES_TAC `i:num = n` THEN ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC;
  2.3028 -      ALL_TAC] THEN
  2.3029 -    MATCH_MP_TAC HAS_GMEASURE_TRANSLATION THEN
  2.3030 -    SUBGOAL_THEN
  2.3031 -     `measure{a..b} =
  2.3032 -      measure(IMAGE (\<lambda>x:real^N. (lambda i. if i = n then --(a$n) else 0) + x)
  2.3033 -                    {a..b}:real^N->bool)`
  2.3034 -    SUBST1_TAC THENL
  2.3035 -     [CONV_TAC SYM_CONV THEN MATCH_MP_TAC MEASURE_TRANSLATION THEN
  2.3036 -      REWRITE_TAC[MEASURABLE_INTERVAL];
  2.3037 -      ALL_TAC] THEN
  2.3038 -    SUBGOAL_THEN
  2.3039 -     `~(IMAGE (\<lambda>x:real^N. (lambda i. if i = n then --(a$n) else 0) + x)
  2.3040 -                    {a..b}:real^N->bool = {})`
  2.3041 -    MP_TAC THENL [ASM_SIMP_TAC[IMAGE_EQ_EMPTY]; ALL_TAC] THEN
  2.3042 -    ONCE_REWRITE_TAC[VECTOR_ARITH `c + x = 1 % x + c`] THEN
  2.3043 -    ASM_REWRITE_TAC[IMAGE_AFFINITY_INTERVAL; REAL_POS] THEN
  2.3044 -    DISCH_TAC THEN MATCH_MP_TAC HAS_GMEASURE_SHEAR_INTERVAL THEN
  2.3045 -    ASM_SIMP_TAC[LAMBDA_BETA; VECTOR_ADD_COMPONENT; VECTOR_MUL_COMPONENT] THEN
  2.3046 -    REAL_ARITH_TAC]);; *)
  2.3047 -
  2.3048 -lemma GMEASURABLE_LINEAR_IMAGE: True .. (*
  2.3049 - "!f:real^N->real^N s.
  2.3050 -        linear f \<and> gmeasurable s ==> gmeasurable(IMAGE f s)"
  2.3051 -qed   REPEAT GEN_TAC THEN
  2.3052 -  DISCH_THEN(MP_TAC o MATCH_MP HAS_GMEASURE_LINEAR_IMAGE) THEN
  2.3053 -  SIMP_TAC[HAS_GMEASURE_MEASURABLE_MEASURE]);; *)
  2.3054 -
  2.3055 -lemma MEASURE_LINEAR_IMAGE: True .. (*
  2.3056 - "!f:real^N->real^N s.
  2.3057 -        linear f \<and> gmeasurable s
  2.3058 -        ==> measure(IMAGE f s) = abs(det(matrix f)) * gmeasure s"
  2.3059 -qed   REPEAT GEN_TAC THEN
  2.3060 -  DISCH_THEN(MP_TAC o MATCH_MP HAS_GMEASURE_LINEAR_IMAGE) THEN
  2.3061 -  SIMP_TAC[HAS_GMEASURE_MEASURABLE_MEASURE]);; *)
  2.3062 -
  2.3063 -lemma HAS_GMEASURE_LINEAR_IMAGE_SAME: True .. (*
  2.3064 - "!f s. linear f \<and> gmeasurable s \<and> abs(det(matrix f)) = 1
  2.3065 -         ==> (IMAGE f s) has_gmeasure (measure s)"
  2.3066 -qed   MESON_TAC[HAS_GMEASURE_LINEAR_IMAGE; REAL_MUL_LID]);; *)
  2.3067 -
  2.3068 -lemma MEASURE_LINEAR_IMAGE_SAME: True .. (*
  2.3069 - "!f:real^N->real^N s.
  2.3070 -        linear f \<and> gmeasurable s \<and> abs(det(matrix f)) = 1
  2.3071 -        ==> measure(IMAGE f s) = gmeasure s"
  2.3072 -qed   REPEAT GEN_TAC THEN
  2.3073 -  DISCH_THEN(MP_TAC o MATCH_MP HAS_GMEASURE_LINEAR_IMAGE_SAME) THEN
  2.3074 -  SIMP_TAC[HAS_GMEASURE_MEASURABLE_MEASURE]);; *)
  2.3075 -
  2.3076 -(* ------------------------------------------------------------------------- *)
  2.3077 -(* gmeasure of a standard simplex.                                            *)
  2.3078 -(* ------------------------------------------------------------------------- *)
  2.3079 -
  2.3080 -lemma CONGRUENT_IMAGE_STD_SIMPLEX: True .. (*
  2.3081 - "!p. p permutes 1..dimindex(:N)
  2.3082 -       ==> {x:real^N | 0 \<le> x$(p 1) \<and> x$(p(dimindex(:N))) \<le> 1 \<and>
  2.3083 -                       (!i. 1 \<le> i \<and> i < dimindex(:N)
  2.3084 -                            ==> x$(p i) \<le> x$(p(i + 1)))} =
  2.3085 -           IMAGE (\<lambda>x:real^N. lambda i. sum(1..inverse p(i)) (\<lambda>j. x$j))
  2.3086 -                 {x | (!i. 1 \<le> i \<and> i \<le> dimindex (:N) ==> 0 \<le> x$i) \<and>
  2.3087 -                      sum (1..dimindex (:N)) (\<lambda>i. x$i) \<le> 1}"
  2.3088 -qed   REPEAT STRIP_TAC THEN MATCH_MP_TAC SUBSET_ANTISYM THEN CONJ_TAC THENL
  2.3089 -   [ALL_TAC;
  2.3090 -    REWRITE_TAC[SUBSET; FORALL_IN_IMAGE] THEN X_GEN_TAC `x:real^N` THEN
  2.3091 -    ASM_SIMP_TAC[IN_ELIM_THM; LAMBDA_BETA; LAMBDA_BETA_PERM; LE_REFL;
  2.3092 -                 ARITH_RULE `i < n ==> i \<le> n \<and> i + 1 \<le> n`;
  2.3093 -                 ARITH_RULE `1 \<le> n + 1`; DIMINDEX_GE_1] THEN
  2.3094 -    STRIP_TAC THEN
  2.3095 -    FIRST_ASSUM(fun th -> REWRITE_TAC[MATCH_MP PERMUTES_INVERSES th]) THEN
  2.3096 -    ASM_SIMP_TAC[SUM_SING_NUMSEG; DIMINDEX_GE_1; LE_REFL] THEN
  2.3097 -    REWRITE_TAC[GSYM ADD1; SUM_CLAUSES_NUMSEG; ARITH_RULE `1 \<le> SUC n`] THEN
  2.3098 -    ASM_SIMP_TAC[REAL_LE_ADDR] THEN REPEAT STRIP_TAC THEN
  2.3099 -    FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_ARITH_TAC] THEN
  2.3100 -  REWRITE_TAC[SUBSET; IN_IMAGE; IN_ELIM_THM] THEN X_GEN_TAC `x:real^N` THEN
  2.3101 -  STRIP_TAC THEN
  2.3102 -  EXISTS_TAC `(lambda i. if i = 1 then x$(p 1)
  2.3103 -                         else (x:real^N)$p(i) - x$p(i - 1)):real^N` THEN
  2.3104 -  ASM_SIMP_TAC[IN_ELIM_THM; LAMBDA_BETA; LAMBDA_BETA_PERM; LE_REFL;
  2.3105 -               ARITH_RULE `i < n ==> i \<le> n \<and> i + 1 \<le> n`;
  2.3106 -               ARITH_RULE `1 \<le> n + 1`; DIMINDEX_GE_1; CART_EQ] THEN
  2.3107 -  REPEAT CONJ_TAC THENL
  2.3108 -   [X_GEN_TAC `i:num` THEN STRIP_TAC THEN
  2.3109 -    SUBGOAL_THEN `1 \<le> inverse (p:num->num) i \<and>
  2.3110 -                  !x. x \<le> inverse p i ==> x \<le> dimindex(:N)`
  2.3111 -    ASSUME_TAC THENL
  2.3112 -     [ASM_MESON_TAC[PERMUTES_INVERSE; IN_NUMSEG; LE_TRANS; PERMUTES_IN_IMAGE];
  2.3113 -      ASM_SIMP_TAC[LAMBDA_BETA] THEN ASM_SIMP_TAC[SUM_CLAUSES_LEFT; ARITH]] THEN
  2.3114 -    SIMP_TAC[ARITH_RULE `2 \<le> n ==> ~(n = 1)`] THEN
  2.3115 -    GEN_REWRITE_TAC (RAND_CONV o RAND_CONV o BINDER_CONV)
  2.3116 -                [GSYM REAL_MUL_LID] THEN
  2.3117 -    ONCE_REWRITE_TAC[SUM_PARTIAL_PRE] THEN
  2.3118 -    REWRITE_TAC[REAL_SUB_REFL; REAL_MUL_RZERO; SUM_0; COND_ID] THEN
  2.3119 -    REWRITE_TAC[REAL_MUL_LID; ARITH; REAL_SUB_RZERO] THEN
  2.3120 -    FIRST_ASSUM(DISJ_CASES_TAC o MATCH_MP (ARITH_RULE
  2.3121 -     `1 \<le> p ==> p = 1 \/ 2 \<le> p`) o CONJUNCT1) THEN
  2.3122 -    ASM_SIMP_TAC[ARITH] THEN
  2.3123 -    FIRST_ASSUM(fun th -> REWRITE_TAC[MATCH_MP PERMUTES_INVERSES th]) THEN
  2.3124 -    REWRITE_TAC[REAL_ADD_RID] THEN TRY REAL_ARITH_TAC THEN
  2.3125 -    ASM_MESON_TAC[PERMUTES_INVERSE_EQ; PERMUTES_INVERSE];
  2.3126 -
  2.3127 -    X_GEN_TAC `i:num` THEN STRIP_TAC THEN COND_CASES_TAC THEN
  2.3128 -    ASM_REWRITE_TAC[REAL_SUB_LE] THEN
  2.3129 -    FIRST_X_ASSUM(MP_TAC o SPEC `i - 1`) THEN
  2.3130 -    ASM_SIMP_TAC[SUB_ADD] THEN DISCH_THEN MATCH_MP_TAC THEN ASM_ARITH_TAC;
  2.3131 -
  2.3132 -    SIMP_TAC[SUM_CLAUSES_LEFT; DIMINDEX_GE_1; ARITH;
  2.3133 -             ARITH_RULE `2 \<le> n ==> ~(n = 1)`] THEN
  2.3134 -    GEN_REWRITE_TAC (LAND_CONV o RAND_CONV o RAND_CONV o BINDER_CONV)
  2.3135 -                [GSYM REAL_MUL_LID] THEN
  2.3136 -    ONCE_REWRITE_TAC[SUM_PARTIAL_PRE] THEN
  2.3137 -    REWRITE_TAC[REAL_SUB_REFL; REAL_MUL_RZERO; SUM_0; COND_ID] THEN
  2.3138 -    REWRITE_TAC[REAL_MUL_LID; ARITH; REAL_SUB_RZERO] THEN
  2.3139 -    COND_CASES_TAC THEN ASM_SIMP_TAC[REAL_ADD_RID] THEN
  2.3140 -    ASM_REWRITE_TAC[REAL_ARITH `x + y - x:real = y`] THEN
  2.3141 -    ASM_MESON_TAC[DIMINDEX_GE_1;
  2.3142 -                  ARITH_RULE `1 \<le> n \<and> ~(2 \<le> n) ==> n = 1`]]);; *)
  2.3143 -
  2.3144 -lemma HAS_GMEASURE_IMAGE_STD_SIMPLEX: True .. (*
  2.3145 - "!p. p permutes 1..dimindex(:N)
  2.3146 -       ==> {x:real^N | 0 \<le> x$(p 1) \<and> x$(p(dimindex(:N))) \<le> 1 \<and>
  2.3147 -                       (!i. 1 \<le> i \<and> i < dimindex(:N)
  2.3148 -                            ==> x$(p i) \<le> x$(p(i + 1)))}
  2.3149 -           has_gmeasure
  2.3150 -           (measure (convex hull
  2.3151 -             (0 INSERT {basis i:real^N | 1 \<le> i \<and> i \<le> dimindex(:N)})))"
  2.3152 -qed   REPEAT STRIP_TAC THEN ASM_SIMP_TAC[CONGRUENT_IMAGE_STD_SIMPLEX] THEN
  2.3153 -  ASM_SIMP_TAC[GSYM STD_SIMPLEX] THEN
  2.3154 -  MATCH_MP_TAC HAS_GMEASURE_LINEAR_IMAGE_SAME THEN
  2.3155 -  REPEAT CONJ_TAC THENL
  2.3156 -   [REWRITE_TAC[linear; CART_EQ] THEN
  2.3157 -    ASM_SIMP_TAC[LAMBDA_BETA; VECTOR_ADD_COMPONENT; VECTOR_MUL_COMPONENT;
  2.3158 -                 GSYM SUM_ADD_NUMSEG; GSYM SUM_LMUL] THEN
  2.3159 -    REPEAT STRIP_TAC THEN MATCH_MP_TAC SUM_EQ_NUMSEG THEN
  2.3160 -    REPEAT STRIP_TAC THEN REWRITE_TAC[] THENL
  2.3161 -     [MATCH_MP_TAC VECTOR_ADD_COMPONENT;
  2.3162 -      MATCH_MP_TAC VECTOR_MUL_COMPONENT] THEN
  2.3163 -    ASM_MESON_TAC[PERMUTES_INVERSE; IN_NUMSEG; LE_TRANS; PERMUTES_IN_IMAGE];
  2.3164 -    MATCH_MP_TAC GMEASURABLE_CONVEX THEN REWRITE_TAC[CONVEX_CONVEX_HULL] THEN
  2.3165 -    MATCH_MP_TAC BOUNDED_CONVEX_HULL THEN REWRITE_TAC[BOUNDED_INSERT] THEN
  2.3166 -    ONCE_REWRITE_TAC[SIMPLE_IMAGE_GEN] THEN
  2.3167 -    MATCH_MP_TAC FINITE_IMP_BOUNDED THEN MATCH_MP_TAC FINITE_IMAGE THEN
  2.3168 -    REWRITE_TAC[GSYM numseg; FINITE_NUMSEG];
  2.3169 -    MATCH_MP_TAC EQ_TRANS THEN EXISTS_TAC
  2.3170 -     `abs(det
  2.3171 -       ((lambda i. ((lambda i j. if j \<le> i then 1 else 0):real^N^N)
  2.3172 -                   $inverse p i)
  2.3173 -        :real^N^N))` THEN
  2.3174 -    CONJ_TAC THENL
  2.3175 -     [AP_TERM_TAC THEN AP_TERM_TAC THEN REWRITE_TAC[CART_EQ] THEN
  2.3176 -      ASM_SIMP_TAC[matrix; LAMBDA_BETA; BASIS_COMPONENT; COND_COMPONENT;
  2.3177 -                   LAMBDA_BETA_PERM; PERMUTES_INVERSE] THEN
  2.3178 -      X_GEN_TAC `i:num` THEN STRIP_TAC THEN
  2.3179 -      X_GEN_TAC `j:num` THEN STRIP_TAC THEN MATCH_MP_TAC EQ_TRANS THEN
  2.3180 -      EXISTS_TAC `sum (1..inverse (p:num->num) i)
  2.3181 -                      (\<lambda>k. if k = j then 1 else 0)` THEN
  2.3182 -      CONJ_TAC THENL
  2.3183 -       [MATCH_MP_TAC SUM_EQ THEN
  2.3184 -        ASM_SIMP_TAC[IN_NUMSEG; PERMUTES_IN_IMAGE; basis] THEN
  2.3185 -        REPEAT STRIP_TAC THEN MATCH_MP_TAC LAMBDA_BETA THEN
  2.3186 -        ASM_MESON_TAC[PERMUTES_IN_IMAGE; IN_NUMSEG; LE_TRANS;
  2.3187 -                      PERMUTES_INVERSE];
  2.3188 -        ASM_SIMP_TAC[SUM_DELTA; IN_NUMSEG]];
  2.3189 -      ALL_TAC] THEN
  2.3190 -    ASM_SIMP_TAC[PERMUTES_INVERSE; DET_PERMUTE_ROWS; ETA_AX] THEN
  2.3191 -    REWRITE_TAC[REAL_ABS_MUL; REAL_ABS_SIGN; REAL_MUL_LID] THEN
  2.3192 -    MATCH_MP_TAC(REAL_ARITH `x = 1 ==> abs x = 1`) THEN
  2.3193 -    ASM_SIMP_TAC[DET_LOWERTRIANGULAR; GSYM NOT_LT; LAMBDA_BETA] THEN
  2.3194 -    REWRITE_TAC[LT_REFL; PRODUCT_CONST_NUMSEG; REAL_POW_ONE]]);; *)
  2.3195 -
  2.3196 -lemma HAS_GMEASURE_STD_SIMPLEX: True .. (*
  2.3197 - "(convex hull (0:real^N INSERT {basis i | 1 \<le> i \<and> i \<le> dimindex(:N)}))
  2.3198 -   has_gmeasure inv((FACT(dimindex(:N))))"
  2.3199 -qed   lemma lemma = prove
  2.3200 -   (`!f:num->real. (!i. 1 \<le> i \<and> i < n ==> f i \<le> f(i + 1)) \<longleftrightarrow>
  2.3201 -                   (!i j. 1 \<le> i \<and> i \<le> j \<and> j \<le> n ==> f i \<le> f j)"
  2.3202 -qed     GEN_TAC THEN EQ_TAC THEN DISCH_TAC THENL
  2.3203 -     [GEN_TAC THEN INDUCT_TAC THEN
  2.3204 -      SIMP_TAC[LE; REAL_LE_REFL] THEN
  2.3205 -      STRIP_TAC THEN ASM_SIMP_TAC[REAL_LE_REFL] THEN
  2.3206 -      MATCH_MP_TAC REAL_LE_TRANS THEN EXISTS_TAC `(f:num->real) j` THEN
  2.3207 -      ASM_SIMP_TAC[ARITH_RULE `SUC x \<le> y ==> x \<le> y`] THEN
  2.3208 -      REWRITE_TAC[ADD1] THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_ARITH_TAC;
  2.3209 -      REPEAT STRIP_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN ASM_ARITH_TAC]) in
  2.3210 -  MP_TAC(ISPECL
  2.3211 -   [`\p. {x:real^N | 0 \<le> x$(p 1) \<and> x$(p(dimindex(:N))) \<le> 1 \<and>
  2.3212 -                     (!i. 1 \<le> i \<and> i < dimindex(:N)
  2.3213 -                          ==> x$(p i) \<le> x$(p(i + 1)))}`;
  2.3214 -    `{p | p permutes 1..dimindex(:N)}`]
  2.3215 -    HAS_GMEASURE_NEGLIGIBLE_UNIONS_IMAGE) THEN
  2.3216 -  ASM_SIMP_TAC[REWRITE_RULE[HAS_GMEASURE_MEASURABLE_MEASURE]
  2.3217 -                            HAS_GMEASURE_IMAGE_STD_SIMPLEX; IN_ELIM_THM] THEN
  2.3218 -  ASM_SIMP_TAC[SUM_CONST; FINITE_PERMUTATIONS; FINITE_NUMSEG;
  2.3219 -               CARD_PERMUTATIONS; CARD_NUMSEG_1] THEN
  2.3220 -  ANTS_TAC THENL
  2.3221 -   [MAP_EVERY X_GEN_TAC [`p:num->num`; `q:num->num`] THEN STRIP_TAC THEN
  2.3222 -    SUBGOAL_THEN `?i. i \<in> 1..dimindex(:N) \<and> ~(p i:num = q i)` MP_TAC THENL
  2.3223 -     [ASM_MESON_TAC[permutes; FUN_EQ_THM]; ALL_TAC] THEN
  2.3224 -    GEN_REWRITE_TAC LAND_CONV [num_WOP] THEN
  2.3225 -    REWRITE_TAC[TAUT `a ==> ~(b \<and> ~c) \<longleftrightarrow> a \<and> b ==> c`] THEN
  2.3226 -    REWRITE_TAC[IN_NUMSEG] THEN
  2.3227 -    DISCH_THEN(X_CHOOSE_THEN `k:num` STRIP_ASSUME_TAC) THEN
  2.3228 -    MATCH_MP_TAC NEGLIGIBLE_SUBSET THEN
  2.3229 -    EXISTS_TAC `{x:real^N | (basis(p(k:num)) - basis(q k)) dot x = 0}` THEN
  2.3230 -    CONJ_TAC THENL
  2.3231 -     [MATCH_MP_TAC NEGLIGIBLE_HYPERPLANE THEN REWRITE_TAC[VECTOR_SUB_EQ] THEN
  2.3232 -      MATCH_MP_TAC BASIS_NE THEN ASM_MESON_TAC[PERMUTES_IN_IMAGE; IN_NUMSEG];
  2.3233 -      ALL_TAC] THEN
  2.3234 -    REWRITE_TAC[SUBSET; IN_INTER; IN_ELIM_THM; DOT_LSUB; VECTOR_SUB_EQ] THEN
  2.3235 -    ASM_SIMP_TAC[DOT_BASIS; GSYM IN_NUMSEG; PERMUTES_IN_IMAGE] THEN
  2.3236 -    SUBGOAL_THEN `?l. (q:num->num) l = p(k:num)` STRIP_ASSUME_TAC THENL
  2.3237 -     [ASM_MESON_TAC[permutes]; ALL_TAC] THEN
  2.3238 -    SUBGOAL_THEN `1 \<le> l \<and> l \<le> dimindex(:N)` STRIP_ASSUME_TAC THENL
  2.3239 -     [ASM_MESON_TAC[PERMUTES_IN_IMAGE; IN_NUMSEG]; ALL_TAC] THEN
  2.3240 -    SUBGOAL_THEN `k:num < l` ASSUME_TAC THENL
  2.3241 -     [REWRITE_TAC[GSYM NOT_LE] THEN REWRITE_TAC[LE_LT] THEN
  2.3242 -      ASM_MESON_TAC[PERMUTES_INJECTIVE; IN_NUMSEG];
  2.3243 -      ALL_TAC] THEN
  2.3244 -    SUBGOAL_THEN `?m. (p:num->num) m = q(k:num)` STRIP_ASSUME_TAC THENL
  2.3245 -     [ASM_MESON_TAC[permutes]; ALL_TAC] THEN
  2.3246 -    SUBGOAL_THEN `1 \<le> m \<and> m \<le> dimindex(:N)` STRIP_ASSUME_TAC THENL
  2.3247 -     [ASM_MESON_TAC[PERMUTES_IN_IMAGE; IN_NUMSEG]; ALL_TAC] THEN
  2.3248 -    SUBGOAL_THEN `k:num < m` ASSUME_TAC THENL
  2.3249 -     [REWRITE_TAC[GSYM NOT_LE] THEN REWRITE_TAC[LE_LT] THEN
  2.3250 -      ASM_MESON_TAC[PERMUTES_INJECTIVE; IN_NUMSEG];
  2.3251 -      ALL_TAC] THEN
  2.3252 -    X_GEN_TAC `x:real^N` THEN REWRITE_TAC[lemma] THEN STRIP_TAC THEN
  2.3253 -    FIRST_X_ASSUM(MP_TAC o SPECL [`k:num`; `l:num`]) THEN
  2.3254 -    FIRST_X_ASSUM(MP_TAC o SPECL [`k:num`; `m:num`]) THEN
  2.3255 -    ASM_SIMP_TAC[LT_IMP_LE; IMP_IMP; REAL_LE_ANTISYM; REAL_SUB_0] THEN
  2.3256 -    MATCH_MP_TAC EQ_IMP THEN BINOP_TAC THEN
  2.3257 -    ASM_MESON_TAC[PERMUTES_IN_IMAGE; IN_NUMSEG; DOT_BASIS];
  2.3258 -    ALL_TAC] THEN
  2.3259 -  REWRITE_TAC[HAS_GMEASURE_MEASURABLE_MEASURE] THEN
  2.3260 -  DISCH_THEN(ASSUME_TAC o CONJUNCT2) THEN CONJ_TAC THENL
  2.3261 -   [MATCH_MP_TAC GMEASURABLE_CONVEX THEN REWRITE_TAC[CONVEX_CONVEX_HULL] THEN
  2.3262 -    MATCH_MP_TAC BOUNDED_CONVEX_HULL THEN REWRITE_TAC[BOUNDED_INSERT] THEN
  2.3263 -    ONCE_REWRITE_TAC[SIMPLE_IMAGE_GEN] THEN
  2.3264 -    MATCH_MP_TAC FINITE_IMP_BOUNDED THEN MATCH_MP_TAC FINITE_IMAGE THEN
  2.3265 -    REWRITE_TAC[GSYM numseg; FINITE_NUMSEG];
  2.3266 -    ALL_TAC] THEN
  2.3267 -  ASM_SIMP_TAC[REAL_FIELD `~(y = 0) ==> (x = inv y \<longleftrightarrow> y * x = 1)`;
  2.3268 -               REAL_OF_NUM_EQ; FACT_NZ] THEN
  2.3269 -  FIRST_X_ASSUM(SUBST1_TAC o SYM) THEN MATCH_MP_TAC EQ_TRANS THEN
  2.3270 -  EXISTS_TAC `measure(interval[0:real^N,1])` THEN CONJ_TAC THENL
  2.3271 -   [AP_TERM_TAC; REWRITE_TAC[MEASURE_INTERVAL; CONTENT_UNIT]] THEN
  2.3272 -  REWRITE_TAC[lemma] THEN MATCH_MP_TAC SUBSET_ANTISYM THEN CONJ_TAC THENL
  2.3273 -   [REWRITE_TAC[SUBSET; FORALL_IN_UNIONS; FORALL_IN_IMAGE; IMP_CONJ;
  2.3274 -                RIGHT_FORALL_IMP_THM; IN_ELIM_THM] THEN
  2.3275 -    SIMP_TAC[IMP_IMP; IN_INTERVAL; LAMBDA_BETA; VEC_COMPONENT] THEN
  2.3276 -    X_GEN_TAC `p:num->num` THEN STRIP_TAC THEN X_GEN_TAC `x:real^N` THEN
  2.3277 -    STRIP_TAC THEN X_GEN_TAC `i:num` THEN REPEAT STRIP_TAC THEN
  2.3278 -    MATCH_MP_TAC REAL_LE_TRANS THENL
  2.3279 -     [EXISTS_TAC `(x:real^N)$(p 1)`;
  2.3280 -      EXISTS_TAC `(x:real^N)$(p(dimindex(:N)))`] THEN
  2.3281 -    ASM_REWRITE_TAC[] THEN
  2.3282 -    FIRST_ASSUM(MP_TAC o SPEC `i:num` o MATCH_MP PERMUTES_SURJECTIVE) THEN
  2.3283 -    ASM_MESON_TAC[LE_REFL; PERMUTES_IN_IMAGE; IN_NUMSEG];
  2.3284 -    ALL_TAC] THEN
  2.3285 -  REWRITE_TAC[SET_RULE `s \<subseteq> UNIONS(IMAGE f t) \<longleftrightarrow>
  2.3286 -                        !x. x \<in> s ==> ?y. y \<in> t \<and> x \<in> f y`] THEN
  2.3287 -  X_GEN_TAC `x:real^N` THEN REWRITE_TAC[IN_INTERVAL; IN_ELIM_THM] THEN
  2.3288 -  SIMP_TAC[VEC_COMPONENT] THEN DISCH_TAC THEN
  2.3289 -  MP_TAC(ISPEC `\i j. ~((x:real^N)$j \<le> x$i)` TOPOLOGICAL_SORT) THEN
  2.3290 -  REWRITE_TAC[REAL_NOT_LE; REAL_NOT_LT] THEN
  2.3291 -  ANTS_TAC THENL [REAL_ARITH_TAC; ALL_TAC] THEN
  2.3292 -  DISCH_THEN(MP_TAC o SPECL [`dimindex(:N)`; `1..dimindex(:N)`]) THEN
  2.3293 -  REWRITE_TAC[HAS_SIZE_NUMSEG_1; EXTENSION; IN_IMAGE; IN_NUMSEG] THEN
  2.3294 -  DISCH_THEN(X_CHOOSE_THEN `f:num->num` (CONJUNCTS_THEN2
  2.3295 -   (ASSUME_TAC o GSYM) ASSUME_TAC)) THEN
  2.3296 -  EXISTS_TAC `\i. if i \<in> 1..dimindex(:N) then f(i) else i` THEN
  2.3297 -  REWRITE_TAC[] THEN ONCE_REWRITE_TAC[ARITH_RULE
  2.3298 -    `1 \<le> i \<and> i \<le> j \<and> j \<le> n \<longleftrightarrow>
  2.3299 -     1 \<le> i \<and> 1 \<le> j \<and> i \<le> n \<and> j \<le> n \<and> i \<le> j`] THEN
  2.3300 -  ASM_SIMP_TAC[IN_NUMSEG; LE_REFL; DIMINDEX_GE_1] THEN
  2.3301 -  CONJ_TAC THENL
  2.3302 -   [ALL_TAC;
  2.3303 -    ASM_MESON_TAC[LE_REFL; DIMINDEX_GE_1; LE_LT; REAL_LE_LT]] THEN
  2.3304 -  SIMP_TAC[PERMUTES_FINITE_SURJECTIVE; FINITE_NUMSEG] THEN
  2.3305 -  SIMP_TAC[IN_NUMSEG] THEN ASM_MESON_TAC[]);; *)
  2.3306 -
  2.3307 -(* ------------------------------------------------------------------------- *)
  2.3308 -(* Hence the gmeasure of a general simplex.                                   *)
  2.3309 -(* ------------------------------------------------------------------------- *)
  2.3310 -
  2.3311 -lemma HAS_GMEASURE_SIMPLEX_0: True .. (*
  2.3312 - "!l:(real^N)list.
  2.3313 -        LENGTH l = dimindex(:N)
  2.3314 -        ==> (convex hull (0 INSERT set_of_list l)) has_gmeasure
  2.3315 -            abs(det(vector l)) / (FACT(dimindex(:N)))"
  2.3316 -qed   REPEAT STRIP_TAC THEN
  2.3317 -  SUBGOAL_THEN
  2.3318 -   `0 INSERT (set_of_list l) =
  2.3319 -        IMAGE (\<lambda>x:real^N. transp(vector l:real^N^N) ** x)
  2.3320 -              (0 INSERT {basis i:real^N | 1 \<le> i \<and> i \<le> dimindex(:N)})`
  2.3321 -  SUBST1_TAC THENL
  2.3322 -   [ONCE_REWRITE_TAC[SIMPLE_IMAGE_GEN] THEN
  2.3323 -    REWRITE_TAC[IMAGE_CLAUSES; GSYM IMAGE_o; o_DEF] THEN
  2.3324 -    REWRITE_TAC[MATRIX_VECTOR_MUL_RZERO] THEN AP_TERM_TAC THEN
  2.3325 -    SIMP_TAC[matrix_vector_mul; vector; transp; LAMBDA_BETA; basis] THEN
  2.3326 -    ONCE_REWRITE_TAC[COND_RAND] THEN
  2.3327 -    SIMP_TAC[REAL_MUL_RZERO; SUM_DELTA] THEN
  2.3328 -    REWRITE_TAC[EXTENSION; IN_IMAGE; IN_ELIM_THM; IN_NUMSEG] THEN
  2.3329 -    ONCE_REWRITE_TAC[TAUT `a \<and> b \<and> c \<longleftrightarrow> ~(b \<and> c ==> ~a)`] THEN
  2.3330 -    X_GEN_TAC `y:real^N` THEN SIMP_TAC[LAMBDA_BETA; REAL_MUL_RID] THEN
  2.3331 -    SIMP_TAC[CART_EQ; LAMBDA_BETA] THEN
  2.3332 -    REWRITE_TAC[NOT_IMP; REAL_MUL_RID; GSYM CART_EQ] THEN
  2.3333 -    ASM_REWRITE_TAC[IN_SET_OF_LIST; MEM_EXISTS_EL] THEN
  2.3334 -    EQ_TAC THEN DISCH_THEN(X_CHOOSE_THEN `i:num` STRIP_ASSUME_TAC) THENL
  2.3335 -     [EXISTS_TAC `SUC i`; EXISTS_TAC `i - 1`] THEN
  2.3336 -    ASM_REWRITE_TAC[SUC_SUB1] THEN ASM_ARITH_TAC;
  2.3337 -    ALL_TAC] THEN
  2.3338 -  ASM_SIMP_TAC[GSYM CONVEX_HULL_LINEAR_IMAGE; MATRIX_VECTOR_MUL_LINEAR] THEN
  2.3339 -  SUBGOAL_THEN
  2.3340 -   `det(vector l:real^N^N) = det(matrix(\<lambda>x:real^N. transp(vector l) ** x))`
  2.3341 -  SUBST1_TAC THENL
  2.3342 -   [REWRITE_TAC[MATRIX_OF_MATRIX_VECTOR_MUL; DET_TRANSP]; ALL_TAC] THEN
  2.3343 -  REWRITE_TAC[real_div] THEN
  2.3344 -  ASM_SIMP_TAC[GSYM(REWRITE_RULE[HAS_GMEASURE_MEASURABLE_MEASURE]
  2.3345 -                 HAS_GMEASURE_STD_SIMPLEX)] THEN
  2.3346 -  MATCH_MP_TAC HAS_GMEASURE_LINEAR_IMAGE THEN
  2.3347 -  REWRITE_TAC[MATRIX_VECTOR_MUL_LINEAR] THEN
  2.3348 -  MATCH_MP_TAC GMEASURABLE_CONVEX THEN REWRITE_TAC[CONVEX_CONVEX_HULL] THEN
  2.3349 -  MATCH_MP_TAC BOUNDED_CONVEX_HULL THEN REWRITE_TAC[BOUNDED_INSERT] THEN
  2.3350 -  ONCE_REWRITE_TAC[SIMPLE_IMAGE_GEN] THEN
  2.3351 -  MATCH_MP_TAC FINITE_IMP_BOUNDED THEN MATCH_MP_TAC FINITE_IMAGE THEN
  2.3352 -  REWRITE_TAC[GSYM numseg; FINITE_NUMSEG]);; *)
  2.3353 -
  2.3354 -lemma HAS_GMEASURE_SIMPLEX: True .. (*
  2.3355 - "!a l:(real^N)list.
  2.3356 -        LENGTH l = dimindex(:N)
  2.3357 -        ==> (convex hull (set_of_list(CONS a l))) has_gmeasure
  2.3358 -            abs(det(vector(MAP (\<lambda>x. x - a) l))) / (FACT(dimindex(:N)))"
  2.3359 -qed   REPEAT STRIP_TAC THEN
  2.3360 -  MP_TAC(ISPEC `MAP (\<lambda>x:real^N. x - a) l` HAS_GMEASURE_SIMPLEX_0) THEN
  2.3361 -  ASM_REWRITE_TAC[LENGTH_MAP; set_of_list] THEN
  2.3362 -  DISCH_THEN(MP_TAC o SPEC `a:real^N` o MATCH_MP HAS_GMEASURE_TRANSLATION) THEN
  2.3363 -  REWRITE_TAC[GSYM CONVEX_HULL_TRANSLATION] THEN
  2.3364 -  MATCH_MP_TAC EQ_IMP THEN AP_THM_TAC THEN AP_TERM_TAC THEN
  2.3365 -  REWRITE_TAC[IMAGE_CLAUSES; VECTOR_ADD_RID; SET_OF_LIST_MAP] THEN
  2.3366 -  REWRITE_TAC[GSYM IMAGE_o; o_DEF; VECTOR_ARITH `a + x - a:real^N = x`;
  2.3367 -              SET_RULE `IMAGE (\<lambda>x. x) s = s`]);; *)
  2.3368 -
  2.3369 -lemma GMEASURABLE_SIMPLEX: True .. (*
  2.3370 - "!l. gmeasurable(convex hull (set_of_list l))"
  2.3371 -qed   GEN_TAC THEN
  2.3372 -  MATCH_MP_TAC GMEASURABLE_CONVEX THEN REWRITE_TAC[CONVEX_CONVEX_HULL] THEN
  2.3373 -  MATCH_MP_TAC BOUNDED_CONVEX_HULL THEN
  2.3374 -  MATCH_MP_TAC FINITE_IMP_BOUNDED THEN REWRITE_TAC[FINITE_SET_OF_LIST]);; *)
  2.3375 -
  2.3376 -lemma MEASURE_SIMPLEX: True .. (*
  2.3377 - "!a l:(real^N)list.
  2.3378 -        LENGTH l = dimindex(:N)
  2.3379 -        ==> measure(convex hull (set_of_list(CONS a l))) =
  2.3380 -            abs(det(vector(MAP (\<lambda>x. x - a) l))) / (FACT(dimindex(:N)))"
  2.3381 -qed   MESON_TAC[HAS_GMEASURE_SIMPLEX; HAS_GMEASURE_MEASURABLE_MEASURE]);; *)
  2.3382 -
  2.3383 -(* ------------------------------------------------------------------------- *)
  2.3384 -(* Area of a triangle.                                                       *)
  2.3385 -(* ------------------------------------------------------------------------- *)
  2.3386 -
  2.3387 -lemma HAS_GMEASURE_TRIANGLE: True .. (*
  2.3388 - "!a b c:real^2.
  2.3389 -        convex hull {a,b,c} has_gmeasure
  2.3390 -        abs((b$1 - a$1) * (c$2 - a$2) - (b$2 - a$2) * (c$1 - a$1)) / 2"
  2.3391 -qed   REPEAT STRIP_TAC THEN
  2.3392 -  MP_TAC(ISPECL [`a:real^2`; `[b;c]:(real^2)list`] HAS_GMEASURE_SIMPLEX) THEN
  2.3393 -  REWRITE_TAC[LENGTH; DIMINDEX_2; ARITH; set_of_list; MAP] THEN
  2.3394 -  CONV_TAC NUM_REDUCE_CONV THEN SIMP_TAC[DET_2; VECTOR_2] THEN
  2.3395 -  SIMP_TAC[VECTOR_SUB_COMPONENT; DIMINDEX_2; ARITH]);; *)
  2.3396 -
  2.3397 -lemma GMEASURABLE_TRIANGLE: True .. (*
  2.3398 - "!a b c:real^N. gmeasurable(convex hull {a,b,c})"
  2.3399 -qed   REPEAT GEN_TAC THEN
  2.3400 -  MATCH_MP_TAC GMEASURABLE_CONVEX THEN REWRITE_TAC[CONVEX_CONVEX_HULL] THEN
  2.3401 -  MATCH_MP_TAC BOUNDED_CONVEX_HULL THEN MATCH_MP_TAC FINITE_IMP_BOUNDED THEN
  2.3402 -  REWRITE_TAC[FINITE_INSERT; FINITE_RULES]);; *)
  2.3403 -
  2.3404 -lemma MEASURE_TRIANGLE: True .. (*
  2.3405 - "!a b c:real^2.
  2.3406 -        measure(convex hull {a,b,c}) =
  2.3407 -        abs((b$1 - a$1) * (c$2 - a$2) - (b$2 - a$2) * (c$1 - a$1)) / 2"
  2.3408 -qed   REWRITE_TAC[REWRITE_RULE[HAS_GMEASURE_MEASURABLE_MEASURE]
  2.3409 -               HAS_GMEASURE_TRIANGLE]);; *)
  2.3410 -
  2.3411 -(* ------------------------------------------------------------------------- *)
  2.3412 -(* Volume of a tetrahedron.                                                  *)
  2.3413 -(* ------------------------------------------------------------------------- *)
  2.3414 -
  2.3415 -lemma HAS_GMEASURE_TETRAHEDRON: True .. (*
  2.3416 - "!a b c d:real^3.
  2.3417 -        convex hull {a,b,c,d} has_gmeasure
  2.3418 -        abs((b$1 - a$1) * (c$2 - a$2) * (d$3 - a$3) +
  2.3419 -            (b$2 - a$2) * (c$3 - a$3) * (d$1 - a$1) +
  2.3420 -            (b$3 - a$3) * (c$1 - a$1) * (d$2 - a$2) -
  2.3421 -            (b$1 - a$1) * (c$3 - a$3) * (d$2 - a$2) -
  2.3422 -            (b$2 - a$2) * (c$1 - a$1) * (d$3 - a$3) -
  2.3423 -            (b$3 - a$3) * (c$2 - a$2) * (d$1 - a$1)) /
  2.3424 -           6"
  2.3425 -qed   REPEAT STRIP_TAC THEN
  2.3426 -  MP_TAC(ISPECL [`a:real^3`; `[b;c;d]:(real^3)list`] HAS_GMEASURE_SIMPLEX) THEN
  2.3427 -  REWRITE_TAC[LENGTH; DIMINDEX_3; ARITH; set_of_list; MAP] THEN
  2.3428 -  CONV_TAC NUM_REDUCE_CONV THEN SIMP_TAC[DET_3; VECTOR_3] THEN
  2.3429 -  SIMP_TAC[VECTOR_SUB_COMPONENT; DIMINDEX_3; ARITH]);; *)
  2.3430 -
  2.3431 -lemma GMEASURABLE_TETRAHEDRON: True .. (*
  2.3432 - "!a b c d:real^N. gmeasurable(convex hull {a,b,c,d})"
  2.3433 -qed   REPEAT GEN_TAC THEN
  2.3434 -  MATCH_MP_TAC GMEASURABLE_CONVEX THEN REWRITE_TAC[CONVEX_CONVEX_HULL] THEN
  2.3435 -  MATCH_MP_TAC BOUNDED_CONVEX_HULL THEN MATCH_MP_TAC FINITE_IMP_BOUNDED THEN
  2.3436 -  REWRITE_TAC[FINITE_INSERT; FINITE_RULES]);; *)
  2.3437 -
  2.3438 -lemma MEASURE_TETRAHEDRON: True .. (*
  2.3439 - "!a b c d:real^3.
  2.3440 -        measure(convex hull {a,b,c,d}) =
  2.3441 -        abs((b$1 - a$1) * (c$2 - a$2) * (d$3 - a$3) +
  2.3442 -            (b$2 - a$2) * (c$3 - a$3) * (d$1 - a$1) +
  2.3443 -            (b$3 - a$3) * (c$1 - a$1) * (d$2 - a$2) -
  2.3444 -            (b$1 - a$1) * (c$3 - a$3) * (d$2 - a$2) -
  2.3445 -            (b$2 - a$2) * (c$1 - a$1) * (d$3 - a$3) -
  2.3446 -            (b$3 - a$3) * (c$2 - a$2) * (d$1 - a$1)) / 6"
  2.3447 -qed   REWRITE_TAC[REWRITE_RULE[HAS_GMEASURE_MEASURABLE_MEASURE]
  2.3448 -               HAS_GMEASURE_TETRAHEDRON]);; *)
  2.3449 -
  2.3450 -end
     3.1 --- a/src/HOL/Multivariate_Analysis/Multivariate_Analysis.thy	Fri Jan 14 16:00:13 2011 +0100
     3.2 +++ b/src/HOL/Multivariate_Analysis/Multivariate_Analysis.thy	Tue Jan 18 21:37:23 2011 +0100
     3.3 @@ -1,5 +1,5 @@
     3.4  theory Multivariate_Analysis
     3.5 -imports Fashoda Gauge_Measure
     3.6 +imports Fashoda
     3.7  begin
     3.8  
     3.9  end
     4.1 --- a/src/HOL/Probability/Lebesgue_Measure.thy	Fri Jan 14 16:00:13 2011 +0100
     4.2 +++ b/src/HOL/Probability/Lebesgue_Measure.thy	Tue Jan 18 21:37:23 2011 +0100
     4.3 @@ -1,7 +1,7 @@
     4.4  (*  Author: Robert Himmelmann, TU Muenchen *)
     4.5  header {* Lebsegue measure *}
     4.6  theory Lebesgue_Measure
     4.7 -  imports Product_Measure Gauge_Measure Complete_Measure
     4.8 +  imports Product_Measure Complete_Measure
     4.9  begin
    4.10  
    4.11  subsection {* Standard Cubes *}
    4.12 @@ -42,144 +42,165 @@
    4.13      by (auto simp add:dist_norm)
    4.14  qed
    4.15  
    4.16 -lemma Union_inter_cube:"\<Union>{s \<inter> cube n |n. n \<in> UNIV} = s"
    4.17 -proof safe case goal1
    4.18 -  from mem_big_cube[of x] guess n . note n=this
    4.19 -  show ?case unfolding Union_iff apply(rule_tac x="s \<inter> cube n" in bexI)
    4.20 -    using n goal1 by auto
    4.21 -qed
    4.22 +definition lebesgue :: "'a::ordered_euclidean_space algebra" where
    4.23 +  "lebesgue = \<lparr> space = UNIV, sets = {A. \<forall>n. (indicator A :: 'a \<Rightarrow> real) integrable_on cube n} \<rparr>"
    4.24 +
    4.25 +lemma space_lebesgue[simp]: "space lebesgue = UNIV"
    4.26 +  unfolding lebesgue_def by simp
    4.27 +
    4.28 +lemma lebesgueD: "A \<in> sets lebesgue \<Longrightarrow> (indicator A :: _ \<Rightarrow> real) integrable_on cube n"
    4.29 +  unfolding lebesgue_def by simp
    4.30 +
    4.31 +lemma lebesgueI: "(\<And>n. (indicator A :: _ \<Rightarrow> real) integrable_on cube n) \<Longrightarrow> A \<in> sets lebesgue"
    4.32 +  unfolding lebesgue_def by simp
    4.33 +
    4.34 +lemma absolutely_integrable_on_indicator[simp]:
    4.35 +  fixes A :: "'a::ordered_euclidean_space set"
    4.36 +  shows "((indicator A :: _ \<Rightarrow> real) absolutely_integrable_on X) \<longleftrightarrow>
    4.37 +    (indicator A :: _ \<Rightarrow> real) integrable_on X"
    4.38 +  unfolding absolutely_integrable_on_def by simp
    4.39 +
    4.40 +lemma LIMSEQ_indicator_UN:
    4.41 +  "(\<lambda>k. indicator (\<Union> i<k. A i) x) ----> (indicator (\<Union>i. A i) x :: real)"
    4.42 +proof cases
    4.43 +  assume "\<exists>i. x \<in> A i" then guess i .. note i = this
    4.44 +  then have *: "\<And>n. (indicator (\<Union> i<n + Suc i. A i) x :: real) = 1"
    4.45 +    "(indicator (\<Union> i. A i) x :: real) = 1" by (auto simp: indicator_def)
    4.46 +  show ?thesis
    4.47 +    apply (rule LIMSEQ_offset[of _ "Suc i"]) unfolding * by auto
    4.48 +qed (auto simp: indicator_def)
    4.49  
    4.50 -lemma gmeasurable_cube[intro]:"gmeasurable (cube n)"
    4.51 -  unfolding cube_def by auto
    4.52 +lemma indicator_add:
    4.53 +  "A \<inter> B = {} \<Longrightarrow> (indicator A x::_::monoid_add) + indicator B x = indicator (A \<union> B) x"
    4.54 +  unfolding indicator_def by auto
    4.55  
    4.56 -lemma gmeasure_le_inter_cube[intro]: fixes s::"'a::ordered_euclidean_space set"
    4.57 -  assumes "gmeasurable (s \<inter> cube n)" shows "gmeasure (s \<inter> cube n) \<le> gmeasure (cube n::'a set)"
    4.58 -  apply(rule has_gmeasure_subset[of "s\<inter>cube n" _ "cube n"])
    4.59 -  unfolding has_gmeasure_measure[THEN sym] using assms by auto
    4.60 +interpretation lebesgue: sigma_algebra lebesgue
    4.61 +proof (intro sigma_algebra_iff2[THEN iffD2] conjI allI ballI impI lebesgueI)
    4.62 +  fix A n assume A: "A \<in> sets lebesgue"
    4.63 +  have "indicator (space lebesgue - A) = (\<lambda>x. 1 - indicator A x :: real)"
    4.64 +    by (auto simp: fun_eq_iff indicator_def)
    4.65 +  then show "(indicator (space lebesgue - A) :: _ \<Rightarrow> real) integrable_on cube n"
    4.66 +    using A by (auto intro!: integrable_sub dest: lebesgueD simp: cube_def)
    4.67 +next
    4.68 +  fix n show "(indicator {} :: _\<Rightarrow>real) integrable_on cube n"
    4.69 +    by (auto simp: cube_def indicator_def_raw)
    4.70 +next
    4.71 +  fix A :: "nat \<Rightarrow> 'a set" and n ::nat assume "range A \<subseteq> sets lebesgue"
    4.72 +  then have A: "\<And>i. (indicator (A i) :: _ \<Rightarrow> real) integrable_on cube n"
    4.73 +    by (auto dest: lebesgueD)
    4.74 +  show "(indicator (\<Union>i. A i) :: _ \<Rightarrow> real) integrable_on cube n" (is "?g integrable_on _")
    4.75 +  proof (intro dominated_convergence[where g="?g"] ballI)
    4.76 +    fix k show "(indicator (\<Union>i<k. A i) :: _ \<Rightarrow> real) integrable_on cube n"
    4.77 +    proof (induct k)
    4.78 +      case (Suc k)
    4.79 +      have *: "(\<Union> i<Suc k. A i) = (\<Union> i<k. A i) \<union> A k"
    4.80 +        unfolding lessThan_Suc UN_insert by auto
    4.81 +      have *: "(\<lambda>x. max (indicator (\<Union> i<k. A i) x) (indicator (A k) x) :: real) =
    4.82 +          indicator (\<Union> i<Suc k. A i)" (is "(\<lambda>x. max (?f x) (?g x)) = _")
    4.83 +        by (auto simp: fun_eq_iff * indicator_def)
    4.84 +      show ?case
    4.85 +        using absolutely_integrable_max[of ?f "cube n" ?g] A Suc by (simp add: *)
    4.86 +    qed auto
    4.87 +  qed (auto intro: LIMSEQ_indicator_UN simp: cube_def)
    4.88 +qed simp
    4.89  
    4.90 -lemma has_gmeasure_cube[intro]: "(cube n::('a::ordered_euclidean_space) set)
    4.91 -  has_gmeasure ((2 * real n) ^ (DIM('a)))"
    4.92 -proof-
    4.93 -  have "content {\<chi>\<chi> i. - real n..(\<chi>\<chi> i. real n)::'a} = (2 * real n) ^ (DIM('a))"
    4.94 -    apply(subst content_closed_interval) defer
    4.95 -    by (auto simp add:setprod_constant)
    4.96 -  thus ?thesis unfolding cube_def
    4.97 -    using has_gmeasure_interval(1)[of "(\<chi>\<chi> i. - real n)::'a" "(\<chi>\<chi> i. real n)::'a"]
    4.98 -    by auto
    4.99 -qed
   4.100 +definition "lmeasure A = (SUP n. Real (integral (cube n) (indicator A)))"
   4.101  
   4.102 -lemma gmeasure_cube_eq[simp]:
   4.103 -  "gmeasure (cube n::('a::ordered_euclidean_space) set) = (2 * real n) ^ DIM('a)"
   4.104 -  by (intro measure_unique) auto
   4.105 -
   4.106 -lemma gmeasure_cube_ge_n: "gmeasure (cube n::('a::ordered_euclidean_space) set) \<ge> real n"
   4.107 -proof cases
   4.108 -  assume "n = 0" then show ?thesis by simp
   4.109 +interpretation lebesgue: measure_space lebesgue lmeasure
   4.110 +proof
   4.111 +  have *: "indicator {} = (\<lambda>x. 0 :: real)" by (simp add: fun_eq_iff)
   4.112 +  show "lmeasure {} = 0" by (simp add: integral_0 * lmeasure_def)
   4.113  next
   4.114 -  assume "n \<noteq> 0"
   4.115 -  have "real n \<le> (2 * real n)^1" by simp
   4.116 -  also have "\<dots> \<le> (2 * real n)^DIM('a)"
   4.117 -    using DIM_positive[where 'a='a] `n \<noteq> 0`
   4.118 -    by (intro power_increasing) auto
   4.119 -  also have "\<dots> = gmeasure (cube n::'a set)" by simp
   4.120 -  finally show ?thesis .
   4.121 +  show "countably_additive lebesgue lmeasure"
   4.122 +  proof (intro countably_additive_def[THEN iffD2] allI impI)
   4.123 +    fix A :: "nat \<Rightarrow> 'b set" assume rA: "range A \<subseteq> sets lebesgue" "disjoint_family A"
   4.124 +    then have A[simp, intro]: "\<And>i n. (indicator (A i) :: _ \<Rightarrow> real) integrable_on cube n"
   4.125 +      by (auto dest: lebesgueD)
   4.126 +    let "?m n i" = "integral (cube n) (indicator (A i) :: _\<Rightarrow>real)"
   4.127 +    let "?M n I" = "integral (cube n) (indicator (\<Union>i\<in>I. A i) :: _\<Rightarrow>real)"
   4.128 +    have nn[simp, intro]: "\<And>i n. 0 \<le> ?m n i" by (auto intro!: integral_nonneg)
   4.129 +    assume "(\<Union>i. A i) \<in> sets lebesgue"
   4.130 +    then have UN_A[simp, intro]: "\<And>i n. (indicator (\<Union>i. A i) :: _ \<Rightarrow> real) integrable_on cube n"
   4.131 +      by (auto dest: lebesgueD)
   4.132 +    show "(\<Sum>\<^isub>\<infinity>n. lmeasure (A n)) = lmeasure (\<Union>i. A i)" unfolding lmeasure_def
   4.133 +    proof (subst psuminf_SUP_eq)
   4.134 +      fix n i show "Real (?m n i) \<le> Real (?m (Suc n) i)"
   4.135 +        using cube_subset[of n "Suc n"] by (auto intro!: integral_subset_le)
   4.136 +    next
   4.137 +      show "(SUP n. \<Sum>\<^isub>\<infinity>i. Real (?m n i)) = (SUP n. Real (?M n UNIV))"
   4.138 +        unfolding psuminf_def
   4.139 +      proof (subst setsum_Real, (intro arg_cong[where f="SUPR UNIV"] ext ballI nn SUP_eq_LIMSEQ[THEN iffD2])+)
   4.140 +        fix n :: nat show "mono (\<lambda>m. \<Sum>x<m. ?m n x)"
   4.141 +        proof (intro mono_iff_le_Suc[THEN iffD2] allI)
   4.142 +          fix m show "(\<Sum>x<m. ?m n x) \<le> (\<Sum>x<Suc m. ?m n x)"
   4.143 +            using nn[of n m] by auto
   4.144 +        qed
   4.145 +        show "0 \<le> ?M n UNIV"
   4.146 +          using UN_A by (auto intro!: integral_nonneg)
   4.147 +        fix m show "0 \<le> (\<Sum>x<m. ?m n x)" by (auto intro!: setsum_nonneg)
   4.148 +      next
   4.149 +        fix n
   4.150 +        have "\<And>m. (UNION {..<m} A) \<in> sets lebesgue" using rA by auto
   4.151 +        from lebesgueD[OF this]
   4.152 +        have "(\<lambda>m. ?M n {..< m}) ----> ?M n UNIV"
   4.153 +          (is "(\<lambda>m. integral _ (?A m)) ----> ?I")
   4.154 +          by (intro dominated_convergence(2)[where f="?A" and h="\<lambda>x. 1::real"])
   4.155 +             (auto intro: LIMSEQ_indicator_UN simp: cube_def)
   4.156 +        moreover
   4.157 +        { fix m have *: "(\<Sum>x<m. ?m n x) = ?M n {..< m}"
   4.158 +          proof (induct m)
   4.159 +            case (Suc m)
   4.160 +            have "(\<Union>i<m. A i) \<in> sets lebesgue" using rA by auto
   4.161 +            then have "(indicator (\<Union>i<m. A i) :: _\<Rightarrow>real) integrable_on (cube n)"
   4.162 +              by (auto dest!: lebesgueD)
   4.163 +            moreover
   4.164 +            have "(\<Union>i<m. A i) \<inter> A m = {}"
   4.165 +              using rA(2)[unfolded disjoint_family_on_def, THEN bspec, of m]
   4.166 +              by auto
   4.167 +            then have "\<And>x. indicator (\<Union>i<Suc m. A i) x =
   4.168 +              indicator (\<Union>i<m. A i) x + (indicator (A m) x :: real)"
   4.169 +              by (auto simp: indicator_add lessThan_Suc ac_simps)
   4.170 +            ultimately show ?case
   4.171 +              using Suc A by (simp add: integral_add[symmetric])
   4.172 +          qed auto }
   4.173 +        ultimately show "(\<lambda>m. \<Sum>x<m. ?m n x) ----> ?M n UNIV"
   4.174 +          by simp
   4.175 +      qed
   4.176 +    qed
   4.177 +  qed
   4.178  qed
   4.179  
   4.180 -lemma gmeasure_setsum:
   4.181 -  assumes "finite A" and "\<And>s t. s \<in> A \<Longrightarrow> t \<in> A \<Longrightarrow> s \<noteq> t \<Longrightarrow> f s \<inter> f t = {}"
   4.182 -    and "\<And>i. i \<in> A \<Longrightarrow> gmeasurable (f i)"
   4.183 -  shows "gmeasure (\<Union>i\<in>A. f i) = (\<Sum>i\<in>A. gmeasure (f i))"
   4.184 +lemma has_integral_interval_cube:
   4.185 +  fixes a b :: "'a::ordered_euclidean_space"
   4.186 +  shows "(indicator {a .. b} has_integral
   4.187 +    content ({\<chi>\<chi> i. max (- real n) (a $$ i) .. \<chi>\<chi> i. min (real n) (b $$ i)} :: 'a set)) (cube n)"
   4.188 +    (is "(?I has_integral content ?R) (cube n)")
   4.189  proof -
   4.190 -  have "gmeasure (\<Union>i\<in>A. f i) = gmeasure (\<Union>f ` A)" by auto
   4.191 -  also have "\<dots> = setsum gmeasure (f ` A)" using assms
   4.192 -  proof (intro measure_negligible_unions)
   4.193 -    fix X Y assume "X \<in> f`A" "Y \<in> f`A" "X \<noteq> Y"
   4.194 -    then have "X \<inter> Y = {}" using assms by auto
   4.195 -    then show "negligible (X \<inter> Y)" by auto
   4.196 -  qed auto
   4.197 -  also have "\<dots> = setsum gmeasure (f ` A - {{}})"
   4.198 -    using assms by (intro setsum_mono_zero_cong_right) auto
   4.199 -  also have "\<dots> = (\<Sum>i\<in>A - {i. f i = {}}. gmeasure (f i))"
   4.200 -  proof (intro setsum_reindex_cong inj_onI)
   4.201 -    fix s t assume *: "s \<in> A - {i. f i = {}}" "t \<in> A - {i. f i = {}}" "f s = f t"
   4.202 -    show "s = t"
   4.203 -    proof (rule ccontr)
   4.204 -      assume "s \<noteq> t" with assms(2)[of s t] * show False by auto
   4.205 -    qed
   4.206 -  qed auto
   4.207 -  also have "\<dots> = (\<Sum>i\<in>A. gmeasure (f i))"
   4.208 -    using assms by (intro setsum_mono_zero_cong_left) auto
   4.209 -  finally show ?thesis .
   4.210 -qed
   4.211 -
   4.212 -lemma gmeasurable_finite_UNION[intro]:
   4.213 -  assumes "\<And>i. i \<in> S \<Longrightarrow> gmeasurable (A i)" "finite S"
   4.214 -  shows "gmeasurable (\<Union>i\<in>S. A i)"
   4.215 -  unfolding UNION_eq_Union_image using assms
   4.216 -  by (intro gmeasurable_finite_unions) auto
   4.217 -
   4.218 -lemma gmeasurable_countable_UNION[intro]:
   4.219 -  fixes A :: "nat \<Rightarrow> ('a::ordered_euclidean_space) set"
   4.220 -  assumes measurable: "\<And>i. gmeasurable (A i)"
   4.221 -    and finite: "\<And>n. gmeasure (UNION {.. n} A) \<le> B"
   4.222 -  shows "gmeasurable (\<Union>i. A i)"
   4.223 -proof -
   4.224 -  have *: "\<And>n. \<Union>{A k |k. k \<le> n} = (\<Union>i\<le>n. A i)"
   4.225 -    "(\<Union>{A n |n. n \<in> UNIV}) = (\<Union>i. A i)" by auto
   4.226 -  show ?thesis
   4.227 -    by (rule gmeasurable_countable_unions_strong[of A B, unfolded *, OF assms])
   4.228 +  let "{?N .. ?P}" = ?R
   4.229 +  have [simp]: "(\<lambda>x. if x \<in> cube n then ?I x else 0) = indicator ?R"
   4.230 +    by (auto simp: indicator_def cube_def fun_eq_iff eucl_le[where 'a='a])
   4.231 +  have "(?I has_integral content ?R) (cube n) \<longleftrightarrow> (indicator ?R has_integral content ?R) UNIV"
   4.232 +    unfolding has_integral_restrict_univ[where s="cube n", symmetric] by simp
   4.233 +  also have "\<dots> \<longleftrightarrow> ((\<lambda>x. 1) has_integral content ?R) ?R"
   4.234 +    unfolding indicator_def_raw has_integral_restrict_univ ..
   4.235 +  finally show ?thesis
   4.236 +    using has_integral_const[of "1::real" "?N" "?P"] by simp
   4.237  qed
   4.238  
   4.239 -subsection {* Measurability *}
   4.240 -
   4.241 -definition lebesgue :: "'a::ordered_euclidean_space algebra" where
   4.242 -  "lebesgue = \<lparr> space = UNIV, sets = {A. \<forall>n. gmeasurable (A \<inter> cube n)} \<rparr>"
   4.243 -
   4.244 -lemma space_lebesgue[simp]:"space lebesgue = UNIV"
   4.245 -  unfolding lebesgue_def by auto
   4.246 -
   4.247 -lemma lebesgueD[dest]: assumes "S \<in> sets lebesgue"
   4.248 -  shows "\<And>n. gmeasurable (S \<inter> cube n)"
   4.249 -  using assms unfolding lebesgue_def by auto
   4.250 -
   4.251 -lemma lebesgueI[intro]: assumes "gmeasurable S"
   4.252 -  shows "S \<in> sets lebesgue" unfolding lebesgue_def cube_def
   4.253 -  using assms gmeasurable_interval by auto
   4.254 -
   4.255 -lemma lebesgueI2: "(\<And>n. gmeasurable (S \<inter> cube n)) \<Longrightarrow> S \<in> sets lebesgue"
   4.256 -  using assms unfolding lebesgue_def by auto
   4.257 -
   4.258 -interpretation lebesgue: sigma_algebra lebesgue
   4.259 -proof
   4.260 -  show "sets lebesgue \<subseteq> Pow (space lebesgue)"
   4.261 -    unfolding lebesgue_def by auto
   4.262 -  show "{} \<in> sets lebesgue"
   4.263 -    using gmeasurable_empty by auto
   4.264 -  { fix A B :: "'a set" assume "A \<in> sets lebesgue" "B \<in> sets lebesgue"
   4.265 -    then show "A \<union> B \<in> sets lebesgue"
   4.266 -      by (auto intro: gmeasurable_union simp: lebesgue_def Int_Un_distrib2) }
   4.267 -  { fix A :: "nat \<Rightarrow> 'a set" assume A: "range A \<subseteq> sets lebesgue"
   4.268 -    show "(\<Union>i. A i) \<in> sets lebesgue"
   4.269 -    proof (rule lebesgueI2)
   4.270 -      fix n show "gmeasurable ((\<Union>i. A i) \<inter> cube n)" unfolding UN_extend_simps
   4.271 -        using A
   4.272 -        by (intro gmeasurable_countable_UNION[where B="gmeasure (cube n::'a set)"])
   4.273 -           (auto intro!: measure_subset gmeasure_setsum simp: UN_extend_simps simp del: gmeasure_cube_eq UN_simps)
   4.274 -    qed }
   4.275 -  { fix A assume A: "A \<in> sets lebesgue" show "space lebesgue - A \<in> sets lebesgue"
   4.276 -    proof (rule lebesgueI2)
   4.277 -      fix n
   4.278 -      have *: "(space lebesgue - A) \<inter> cube n = cube n - (A \<inter> cube n)"
   4.279 -        unfolding lebesgue_def by auto
   4.280 -      show "gmeasurable ((space lebesgue - A) \<inter> cube n)" unfolding *
   4.281 -        using A by (auto intro!: gmeasurable_diff)
   4.282 -    qed }
   4.283 -qed
   4.284 -
   4.285 -lemma lebesgueI_borel[intro, simp]: fixes s::"'a::ordered_euclidean_space set"
   4.286 +lemma lebesgueI_borel[intro, simp]:
   4.287 +  fixes s::"'a::ordered_euclidean_space set"
   4.288    assumes "s \<in> sets borel" shows "s \<in> sets lebesgue"
   4.289 -proof- let ?S = "range (\<lambda>(a, b). {a .. (b :: 'a\<Colon>ordered_euclidean_space)})"
   4.290 -  have *:"?S \<subseteq> sets lebesgue" by auto
   4.291 +proof -
   4.292 +  let ?S = "range (\<lambda>(a, b). {a .. (b :: 'a\<Colon>ordered_euclidean_space)})"
   4.293 +  have *:"?S \<subseteq> sets lebesgue"
   4.294 +  proof (safe intro!: lebesgueI)
   4.295 +    fix n :: nat and a b :: 'a
   4.296 +    let ?N = "\<chi>\<chi> i. max (- real n) (a $$ i)"
   4.297 +    let ?P = "\<chi>\<chi> i. min (real n) (b $$ i)"
   4.298 +    show "(indicator {a..b} :: 'a\<Rightarrow>real) integrable_on cube n"
   4.299 +      unfolding integrable_on_def
   4.300 +      using has_integral_interval_cube[of a b] by auto
   4.301 +  qed
   4.302    have "s \<in> sigma_sets UNIV ?S" using assms
   4.303      unfolding borel_eq_atLeastAtMost by (simp add: sigma_def)
   4.304    thus ?thesis
   4.305 @@ -189,171 +210,153 @@
   4.306  
   4.307  lemma lebesgueI_negligible[dest]: fixes s::"'a::ordered_euclidean_space set"
   4.308    assumes "negligible s" shows "s \<in> sets lebesgue"
   4.309 -proof (rule lebesgueI2)
   4.310 -  fix n
   4.311 -  have *:"\<And>x. (if x \<in> cube n then indicator s x else 0) = (if x \<in> s \<inter> cube n then 1 else 0)"
   4.312 -    unfolding indicator_def_raw by auto
   4.313 -  note assms[unfolded negligible_def,rule_format,of "(\<chi>\<chi> i. - real n)::'a" "\<chi>\<chi> i. real n"]
   4.314 -  thus "gmeasurable (s \<inter> cube n)" apply-apply(rule gmeasurableI[of _ 0]) unfolding has_gmeasure_def
   4.315 -    apply(subst(asm) has_integral_restrict_univ[THEN sym]) unfolding cube_def[symmetric]
   4.316 -    apply(subst has_integral_restrict_univ[THEN sym]) unfolding * .
   4.317 -qed
   4.318 +  using assms by (force simp: cube_def integrable_on_def negligible_def intro!: lebesgueI)
   4.319  
   4.320 -section {* The Lebesgue Measure *}
   4.321 -
   4.322 -definition "lmeasure A = (SUP n. Real (gmeasure (A \<inter> cube n)))"
   4.323 -
   4.324 -lemma lmeasure_eq_0: assumes "negligible S" shows "lmeasure S = 0"
   4.325 +lemma lmeasure_eq_0:
   4.326 +  fixes S :: "'a::ordered_euclidean_space set" assumes "negligible S" shows "lmeasure S = 0"
   4.327  proof -
   4.328 -  from lebesgueI_negligible[OF assms]
   4.329 -  have "\<And>n. gmeasurable (S \<inter> cube n)" by auto
   4.330 -  from gmeasurable_measure_eq_0[OF this]
   4.331 -  have "\<And>n. gmeasure (S \<inter> cube n) = 0" using assms by auto
   4.332 -  then show ?thesis unfolding lmeasure_def by simp
   4.333 +  have "\<And>n. integral (cube n) (indicator S :: 'a\<Rightarrow>real) = 0"
   4.334 +    unfolding integral_def using assms
   4.335 +    by (intro some1_equality ex_ex1I has_integral_unique)
   4.336 +       (auto simp: cube_def negligible_def intro: )
   4.337 +  then show ?thesis unfolding lmeasure_def by auto
   4.338  qed
   4.339  
   4.340  lemma lmeasure_iff_LIMSEQ:
   4.341    assumes "A \<in> sets lebesgue" "0 \<le> m"
   4.342 -  shows "lmeasure A = Real m \<longleftrightarrow> (\<lambda>n. (gmeasure (A \<inter> cube n))) ----> m"
   4.343 -  unfolding lmeasure_def using assms cube_subset[where 'a='a]
   4.344 -  by (intro SUP_eq_LIMSEQ monoI measure_subset) force+
   4.345 +  shows "lmeasure A = Real m \<longleftrightarrow> (\<lambda>n. integral (cube n) (indicator A :: _ \<Rightarrow> real)) ----> m"
   4.346 +  unfolding lmeasure_def
   4.347 +proof (intro SUP_eq_LIMSEQ)
   4.348 +  show "mono (\<lambda>n. integral (cube n) (indicator A::_=>real))"
   4.349 +    using cube_subset assms by (intro monoI integral_subset_le) (auto dest!: lebesgueD)
   4.350 +  fix n show "0 \<le> integral (cube n) (indicator A::_=>real)"
   4.351 +    using assms by (auto dest!: lebesgueD intro!: integral_nonneg)
   4.352 +qed fact
   4.353  
   4.354 -interpretation lebesgue: measure_space lebesgue lmeasure
   4.355 -proof
   4.356 -  show "lmeasure {} = 0"
   4.357 -    by (auto intro!: lmeasure_eq_0)
   4.358 -  show "countably_additive lebesgue lmeasure"
   4.359 -  proof (unfold countably_additive_def, intro allI impI conjI)
   4.360 -    fix A :: "nat \<Rightarrow> 'b set" assume "range A \<subseteq> sets lebesgue" "disjoint_family A"
   4.361 -    then have A: "\<And>i. A i \<in> sets lebesgue" by auto
   4.362 -    show "(\<Sum>\<^isub>\<infinity>n. lmeasure (A n)) = lmeasure (\<Union>i. A i)" unfolding lmeasure_def
   4.363 -    proof (subst psuminf_SUP_eq)
   4.364 -      { fix i n
   4.365 -        have "gmeasure (A i \<inter> cube n) \<le> gmeasure (A i \<inter> cube (Suc n))"
   4.366 -          using A cube_subset[of n "Suc n"] by (auto intro!: measure_subset)
   4.367 -        then show "Real (gmeasure (A i \<inter> cube n)) \<le> Real (gmeasure (A i \<inter> cube (Suc n)))"
   4.368 -          by auto }
   4.369 -      show "(SUP n. \<Sum>\<^isub>\<infinity>i. Real (gmeasure (A i \<inter> cube n))) = (SUP n. Real (gmeasure ((\<Union>i. A i) \<inter> cube n)))"
   4.370 -      proof (intro arg_cong[where f="SUPR UNIV"] ext)
   4.371 -        fix n
   4.372 -        have sums: "(\<lambda>i. gmeasure (A i \<inter> cube n)) sums gmeasure (\<Union>{A i \<inter> cube n |i. i \<in> UNIV})"
   4.373 -        proof (rule has_gmeasure_countable_negligible_unions(2))
   4.374 -          fix i show "gmeasurable (A i \<inter> cube n)" using A by auto
   4.375 -        next
   4.376 -          fix i m :: nat assume "m \<noteq> i"
   4.377 -          then have "A m \<inter> cube n \<inter> (A i \<inter> cube n) = {}"
   4.378 -            using `disjoint_family A` unfolding disjoint_family_on_def by auto
   4.379 -          then show "negligible (A m \<inter> cube n \<inter> (A i \<inter> cube n))" by auto
   4.380 -        next
   4.381 -          fix i
   4.382 -          have "(\<Sum>k = 0..i. gmeasure (A k \<inter> cube n)) = gmeasure (\<Union>k\<le>i . A k \<inter> cube n)"
   4.383 -            unfolding atLeast0AtMost using A
   4.384 -          proof (intro gmeasure_setsum[symmetric])
   4.385 -            fix s t :: nat assume "s \<noteq> t" then have "A t \<inter> A s = {}"
   4.386 -              using `disjoint_family A` unfolding disjoint_family_on_def by auto
   4.387 -            then show "A s \<inter> cube n \<inter> (A t \<inter> cube n) = {}" by auto
   4.388 -          qed auto
   4.389 -          also have "\<dots> \<le> gmeasure (cube n :: 'b set)" using A
   4.390 -            by (intro measure_subset gmeasurable_finite_UNION) auto
   4.391 -          finally show "(\<Sum>k = 0..i. gmeasure (A k \<inter> cube n)) \<le> gmeasure (cube n :: 'b set)" .
   4.392 -        qed
   4.393 -        show "(\<Sum>\<^isub>\<infinity>i. Real (gmeasure (A i \<inter> cube n))) = Real (gmeasure ((\<Union>i. A i) \<inter> cube n))"
   4.394 -          unfolding psuminf_def
   4.395 -          apply (subst setsum_Real)
   4.396 -          apply (simp add: measure_pos_le)
   4.397 -        proof (rule SUP_eq_LIMSEQ[THEN iffD2])
   4.398 -          have "(\<Union>{A i \<inter> cube n |i. i \<in> UNIV}) = (\<Union>i. A i) \<inter> cube n" by auto
   4.399 -          with sums show "(\<lambda>i. \<Sum>k<i. gmeasure (A k \<inter> cube n)) ----> gmeasure ((\<Union>i. A i) \<inter> cube n)"
   4.400 -            unfolding sums_def atLeast0LessThan by simp
   4.401 -        qed (auto intro!: monoI setsum_nonneg setsum_mono2)
   4.402 -      qed
   4.403 -    qed
   4.404 -  qed
   4.405 +lemma has_integral_indicator_UNIV:
   4.406 +  fixes s A :: "'a::ordered_euclidean_space set" and x :: real
   4.407 +  shows "((indicator (s \<inter> A) :: 'a\<Rightarrow>real) has_integral x) UNIV = ((indicator s :: _\<Rightarrow>real) has_integral x) A"
   4.408 +proof -
   4.409 +  have "(\<lambda>x. if x \<in> A then indicator s x else 0) = (indicator (s \<inter> A) :: _\<Rightarrow>real)"
   4.410 +    by (auto simp: fun_eq_iff indicator_def)
   4.411 +  then show ?thesis
   4.412 +    unfolding has_integral_restrict_univ[where s=A, symmetric] by simp
   4.413  qed
   4.414  
   4.415 -lemma lmeasure_finite_has_gmeasure: assumes "s \<in> sets lebesgue" "lmeasure s = Real m" "0 \<le> m"
   4.416 -  shows "s has_gmeasure m"
   4.417 -proof-
   4.418 -  have *:"(\<lambda>n. (gmeasure (s \<inter> cube n))) ----> m"
   4.419 -    using `lmeasure s = Real m` unfolding lmeasure_iff_LIMSEQ[OF `s \<in> sets lebesgue` `0 \<le> m`] .
   4.420 -  have s: "\<And>n. gmeasurable (s \<inter> cube n)" using assms by auto
   4.421 -  have "(\<lambda>x. if x \<in> s then 1 else (0::real)) integrable_on UNIV \<and>
   4.422 -    (\<lambda>k. integral UNIV (\<lambda>x. if x \<in> s \<inter> cube k then 1 else (0::real)))
   4.423 -    ----> integral UNIV (\<lambda>x. if x \<in> s then 1 else 0)"
   4.424 -  proof(rule monotone_convergence_increasing)
   4.425 -    have "lmeasure s \<le> Real m" using `lmeasure s = Real m` by simp
   4.426 -    then have "\<forall>n. gmeasure (s \<inter> cube n) \<le> m"
   4.427 -      unfolding lmeasure_def complete_lattice_class.SUP_le_iff
   4.428 -      using `0 \<le> m` by (auto simp: measure_pos_le)
   4.429 -    thus *:"bounded {integral UNIV (\<lambda>x. if x \<in> s \<inter> cube k then 1 else (0::real)) |k. True}"
   4.430 -      unfolding integral_measure_univ[OF s] bounded_def apply-
   4.431 -      apply(rule_tac x=0 in exI,rule_tac x=m in exI) unfolding dist_real_def
   4.432 -      by (auto simp: measure_pos_le)
   4.433 -    show "\<forall>k. (\<lambda>x. if x \<in> s \<inter> cube k then (1::real) else 0) integrable_on UNIV"
   4.434 -      unfolding integrable_restrict_univ
   4.435 -      using s unfolding gmeasurable_def has_gmeasure_def by auto
   4.436 -    have *:"\<And>n. n \<le> Suc n" by auto
   4.437 -    show "\<forall>k. \<forall>x\<in>UNIV. (if x \<in> s \<inter> cube k then 1 else 0) \<le> (if x \<in> s \<inter> cube (Suc k) then 1 else (0::real))"
   4.438 -      using cube_subset[OF *] by fastsimp
   4.439 -    show "\<forall>x\<in>UNIV. (\<lambda>k. if x \<in> s \<inter> cube k then 1 else 0) ----> (if x \<in> s then 1 else (0::real))"
   4.440 -      unfolding Lim_sequentially
   4.441 -    proof safe case goal1 from real_arch_lt[of "norm x"] guess N .. note N = this
   4.442 -      show ?case apply(rule_tac x=N in exI)
   4.443 -      proof safe case goal1
   4.444 -        have "x \<in> cube n" using cube_subset[OF goal1] N
   4.445 -          using ball_subset_cube[of N] by(auto simp: dist_norm)
   4.446 -        thus ?case using `e>0` by auto
   4.447 -      qed
   4.448 -    qed
   4.449 -  qed note ** = conjunctD2[OF this]
   4.450 -  hence *:"m = integral UNIV (\<lambda>x. if x \<in> s then 1 else 0)" apply-
   4.451 -    apply(rule LIMSEQ_unique[OF _ **(2)]) unfolding measure_integral_univ[THEN sym,OF s] using * .
   4.452 -  show ?thesis unfolding has_gmeasure * apply(rule integrable_integral) using ** by auto
   4.453 +lemma
   4.454 +  fixes s a :: "'a::ordered_euclidean_space set"
   4.455 +  shows integral_indicator_UNIV:
   4.456 +    "integral UNIV (indicator (s \<inter> A) :: 'a\<Rightarrow>real) = integral A (indicator s :: _\<Rightarrow>real)"
   4.457 +  and integrable_indicator_UNIV:
   4.458 +    "(indicator (s \<inter> A) :: 'a\<Rightarrow>real) integrable_on UNIV \<longleftrightarrow> (indicator s :: 'a\<Rightarrow>real) integrable_on A"
   4.459 +  unfolding integral_def integrable_on_def has_integral_indicator_UNIV by auto
   4.460 +
   4.461 +lemma lmeasure_finite_has_integral:
   4.462 +  fixes s :: "'a::ordered_euclidean_space set"
   4.463 +  assumes "s \<in> sets lebesgue" "lmeasure s = Real m" "0 \<le> m"
   4.464 +  shows "(indicator s has_integral m) UNIV"
   4.465 +proof -
   4.466 +  let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
   4.467 +  have **: "(?I s) integrable_on UNIV \<and> (\<lambda>k. integral UNIV (?I (s \<inter> cube k))) ----> integral UNIV (?I s)"
   4.468 +  proof (intro monotone_convergence_increasing allI ballI)
   4.469 +    have LIMSEQ: "(\<lambda>n. integral (cube n) (?I s)) ----> m"
   4.470 +      using assms(2) unfolding lmeasure_iff_LIMSEQ[OF assms(1, 3)] .
   4.471 +    { fix n have "integral (cube n) (?I s) \<le> m"
   4.472 +        using cube_subset assms
   4.473 +        by (intro incseq_le[where L=m] LIMSEQ incseq_def[THEN iffD2] integral_subset_le allI impI)
   4.474 +           (auto dest!: lebesgueD) }
   4.475 +    moreover
   4.476 +    { fix n have "0 \<le> integral (cube n) (?I s)"
   4.477 +      using assms by (auto dest!: lebesgueD intro!: integral_nonneg) }
   4.478 +    ultimately
   4.479 +    show "bounded {integral UNIV (?I (s \<inter> cube k)) |k. True}"
   4.480 +      unfolding bounded_def
   4.481 +      apply (rule_tac exI[of _ 0])
   4.482 +      apply (rule_tac exI[of _ m])
   4.483 +      by (auto simp: dist_real_def integral_indicator_UNIV)
   4.484 +    fix k show "?I (s \<inter> cube k) integrable_on UNIV"
   4.485 +      unfolding integrable_indicator_UNIV using assms by (auto dest!: lebesgueD)
   4.486 +    fix x show "?I (s \<inter> cube k) x \<le> ?I (s \<inter> cube (Suc k)) x"
   4.487 +      using cube_subset[of k "Suc k"] by (auto simp: indicator_def)
   4.488 +  next
   4.489 +    fix x :: 'a
   4.490 +    from mem_big_cube obtain k where k: "x \<in> cube k" .
   4.491 +    { fix n have "?I (s \<inter> cube (n + k)) x = ?I s x"
   4.492 +      using k cube_subset[of k "n + k"] by (auto simp: indicator_def) }
   4.493 +    note * = this
   4.494 +    show "(\<lambda>k. ?I (s \<inter> cube k) x) ----> ?I s x"
   4.495 +      by (rule LIMSEQ_offset[where k=k]) (auto simp: *)
   4.496 +  qed
   4.497 +  note ** = conjunctD2[OF this]
   4.498 +  have m: "m = integral UNIV (?I s)"
   4.499 +    apply (intro LIMSEQ_unique[OF _ **(2)])
   4.500 +    using assms(2) unfolding lmeasure_iff_LIMSEQ[OF assms(1,3)] integral_indicator_UNIV .
   4.501 +  show ?thesis
   4.502 +    unfolding m by (intro integrable_integral **)
   4.503  qed
   4.504  
   4.505 -lemma lmeasure_finite_gmeasurable: assumes "s \<in> sets lebesgue" "lmeasure s \<noteq> \<omega>"
   4.506 -  shows "gmeasurable s"
   4.507 +lemma lmeasure_finite_integrable: assumes "s \<in> sets lebesgue" "lmeasure s \<noteq> \<omega>"
   4.508 +  shows "(indicator s :: _ \<Rightarrow> real) integrable_on UNIV"
   4.509  proof (cases "lmeasure s")
   4.510 -  case (preal m) from lmeasure_finite_has_gmeasure[OF `s \<in> sets lebesgue` this]
   4.511 -  show ?thesis unfolding gmeasurable_def by auto
   4.512 +  case (preal m) from lmeasure_finite_has_integral[OF `s \<in> sets lebesgue` this]
   4.513 +  show ?thesis unfolding integrable_on_def by auto
   4.514  qed (insert assms, auto)
   4.515  
   4.516 -lemma has_gmeasure_lmeasure: assumes "s has_gmeasure m"
   4.517 -  shows "lmeasure s = Real m"
   4.518 -proof-
   4.519 -  have gmea:"gmeasurable s" using assms by auto
   4.520 -  then have s: "s \<in> sets lebesgue" by auto
   4.521 -  have m:"m \<ge> 0" using assms by auto
   4.522 -  have *:"m = gmeasure (\<Union>{s \<inter> cube n |n. n \<in> UNIV})" unfolding Union_inter_cube
   4.523 -    using assms by(rule measure_unique[THEN sym])
   4.524 -  show ?thesis
   4.525 -    unfolding lmeasure_iff_LIMSEQ[OF s `0 \<le> m`] unfolding *
   4.526 -    apply(rule gmeasurable_nested_unions[THEN conjunct2, where B1="gmeasure s"])
   4.527 -  proof- fix n::nat show *:"gmeasurable (s \<inter> cube n)"
   4.528 -      using gmeasurable_inter[OF gmea gmeasurable_cube] .
   4.529 -    show "gmeasure (s \<inter> cube n) \<le> gmeasure s" apply(rule measure_subset)
   4.530 -      apply(rule * gmea)+ by auto
   4.531 -    show "s \<inter> cube n \<subseteq> s \<inter> cube (Suc n)" using cube_subset[of n "Suc n"] by auto
   4.532 -  qed
   4.533 +lemma has_integral_lebesgue: assumes "((indicator s :: _\<Rightarrow>real) has_integral m) UNIV"
   4.534 +  shows "s \<in> sets lebesgue"
   4.535 +proof (intro lebesgueI)
   4.536 +  let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
   4.537 +  fix n show "(?I s) integrable_on cube n" unfolding cube_def
   4.538 +  proof (intro integrable_on_subinterval)
   4.539 +    show "(?I s) integrable_on UNIV"
   4.540 +      unfolding integrable_on_def using assms by auto
   4.541 +  qed auto
   4.542  qed
   4.543  
   4.544 -lemma has_gmeasure_iff_lmeasure:
   4.545 -  "A has_gmeasure m \<longleftrightarrow> (A \<in> sets lebesgue \<and> 0 \<le> m \<and> lmeasure A = Real m)"
   4.546 +lemma has_integral_lmeasure: assumes "((indicator s :: _\<Rightarrow>real) has_integral m) UNIV"
   4.547 +  shows "lmeasure s = Real m"
   4.548 +proof (intro lmeasure_iff_LIMSEQ[THEN iffD2])
   4.549 +  let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
   4.550 +  show "s \<in> sets lebesgue" using has_integral_lebesgue[OF assms] .
   4.551 +  show "0 \<le> m" using assms by (rule has_integral_nonneg) auto
   4.552 +  have "(\<lambda>n. integral UNIV (?I (s \<inter> cube n))) ----> integral UNIV (?I s)"
   4.553 +  proof (intro dominated_convergence(2) ballI)
   4.554 +    show "(?I s) integrable_on UNIV" unfolding integrable_on_def using assms by auto
   4.555 +    fix n show "?I (s \<inter> cube n) integrable_on UNIV"
   4.556 +      unfolding integrable_indicator_UNIV using `s \<in> sets lebesgue` by (auto dest: lebesgueD)
   4.557 +    fix x show "norm (?I (s \<inter> cube n) x) \<le> ?I s x" by (auto simp: indicator_def)
   4.558 +  next
   4.559 +    fix x :: 'a
   4.560 +    from mem_big_cube obtain k where k: "x \<in> cube k" .
   4.561 +    { fix n have "?I (s \<inter> cube (n + k)) x = ?I s x"
   4.562 +      using k cube_subset[of k "n + k"] by (auto simp: indicator_def) }
   4.563 +    note * = this
   4.564 +    show "(\<lambda>k. ?I (s \<inter> cube k) x) ----> ?I s x"
   4.565 +      by (rule LIMSEQ_offset[where k=k]) (auto simp: *)
   4.566 +  qed
   4.567 +  then show "(\<lambda>n. integral (cube n) (?I s)) ----> m"
   4.568 +    unfolding integral_unique[OF assms] integral_indicator_UNIV by simp
   4.569 +qed
   4.570 +
   4.571 +lemma has_integral_iff_lmeasure:
   4.572 +  "(indicator A has_integral m) UNIV \<longleftrightarrow> (A \<in> sets lebesgue \<and> 0 \<le> m \<and> lmeasure A = Real m)"
   4.573  proof
   4.574 -  assume "A has_gmeasure m"
   4.575 -  with has_gmeasure_lmeasure[OF this]
   4.576 -  have "gmeasurable A" "0 \<le> m" "lmeasure A = Real m" by auto
   4.577 -  then show "A \<in> sets lebesgue \<and> 0 \<le> m \<and> lmeasure A = Real m" by auto
   4.578 +  assume "(indicator A has_integral m) UNIV"
   4.579 +  with has_integral_lmeasure[OF this] has_integral_lebesgue[OF this]
   4.580 +  show "A \<in> sets lebesgue \<and> 0 \<le> m \<and> lmeasure A = Real m"
   4.581 +    by (auto intro: has_integral_nonneg)
   4.582  next
   4.583    assume "A \<in> sets lebesgue \<and> 0 \<le> m \<and> lmeasure A = Real m"
   4.584 -  then show "A has_gmeasure m" by (intro lmeasure_finite_has_gmeasure) auto
   4.585 +  then show "(indicator A has_integral m) UNIV" by (intro lmeasure_finite_has_integral) auto
   4.586  qed
   4.587  
   4.588 -lemma gmeasure_lmeasure: assumes "gmeasurable s" shows "lmeasure s = Real (gmeasure s)"
   4.589 -proof -
   4.590 -  note has_gmeasure_measureI[OF assms]
   4.591 -  note has_gmeasure_lmeasure[OF this]
   4.592 -  thus ?thesis .
   4.593 +lemma lmeasure_eq_integral: assumes "(indicator s::_\<Rightarrow>real) integrable_on UNIV"
   4.594 +  shows "lmeasure s = Real (integral UNIV (indicator s))"
   4.595 +  using assms unfolding integrable_on_def
   4.596 +proof safe
   4.597 +  fix y :: real assume "(indicator s has_integral y) UNIV"
   4.598 +  from this[unfolded has_integral_iff_lmeasure] integral_unique[OF this]
   4.599 +  show "lmeasure s = Real (integral UNIV (indicator s))" by simp
   4.600  qed
   4.601  
   4.602  lemma lebesgue_simple_function_indicator:
   4.603 @@ -362,12 +365,12 @@
   4.604    shows "f = (\<lambda>x. (\<Sum>y \<in> f ` UNIV. y * indicator (f -` {y}) x))"
   4.605    apply(rule,subst lebesgue.simple_function_indicator_representation[OF f]) by auto
   4.606  
   4.607 -lemma lmeasure_gmeasure:
   4.608 -  "gmeasurable s \<Longrightarrow> gmeasure s = real (lmeasure s)"
   4.609 -  by (subst gmeasure_lmeasure) auto
   4.610 +lemma integral_eq_lmeasure:
   4.611 +  "(indicator s::_\<Rightarrow>real) integrable_on UNIV \<Longrightarrow> integral UNIV (indicator s) = real (lmeasure s)"
   4.612 +  by (subst lmeasure_eq_integral) (auto intro!: integral_nonneg)
   4.613  
   4.614 -lemma lmeasure_finite: assumes "gmeasurable s" shows "lmeasure s \<noteq> \<omega>"
   4.615 -  using gmeasure_lmeasure[OF assms] by auto
   4.616 +lemma lmeasure_finite: assumes "(indicator s::_\<Rightarrow>real) integrable_on UNIV" shows "lmeasure s \<noteq> \<omega>"
   4.617 +  using lmeasure_eq_integral[OF assms] by auto
   4.618  
   4.619  lemma negligible_iff_lebesgue_null_sets:
   4.620    "negligible A \<longleftrightarrow> A \<in> lebesgue.null_sets"
   4.621 @@ -377,35 +380,65 @@
   4.622    show "A \<in> lebesgue.null_sets" by auto
   4.623  next
   4.624    assume A: "A \<in> lebesgue.null_sets"
   4.625 -  then have *:"gmeasurable A" using lmeasure_finite_gmeasurable[of A] by auto
   4.626 -  show "negligible A"
   4.627 -    unfolding gmeasurable_measure_eq_0[OF *, symmetric]
   4.628 -    unfolding lmeasure_gmeasure[OF *] using A by auto
   4.629 +  then have *:"((indicator A) has_integral (0::real)) UNIV" using lmeasure_finite_has_integral[of A] by auto
   4.630 +  show "negligible A" unfolding negligible_def
   4.631 +  proof (intro allI)
   4.632 +    fix a b :: 'a
   4.633 +    have integrable: "(indicator A :: _\<Rightarrow>real) integrable_on {a..b}"
   4.634 +      by (intro integrable_on_subinterval has_integral_integrable) (auto intro: *)
   4.635 +    then have "integral {a..b} (indicator A) \<le> (integral UNIV (indicator A) :: real)"
   4.636 +      using * by (auto intro!: integral_subset_le has_integral_integrable)
   4.637 +    moreover have "(0::real) \<le> integral {a..b} (indicator A)"
   4.638 +      using integrable by (auto intro!: integral_nonneg)
   4.639 +    ultimately have "integral {a..b} (indicator A) = (0::real)"
   4.640 +      using integral_unique[OF *] by auto
   4.641 +    then show "(indicator A has_integral (0::real)) {a..b}"
   4.642 +      using integrable_integral[OF integrable] by simp
   4.643 +  qed
   4.644 +qed
   4.645 +
   4.646 +lemma integral_const[simp]:
   4.647 +  fixes a b :: "'a::ordered_euclidean_space"
   4.648 +  shows "integral {a .. b} (\<lambda>x. c) = content {a .. b} *\<^sub>R c"
   4.649 +  by (rule integral_unique) (rule has_integral_const)
   4.650 +
   4.651 +lemma lmeasure_UNIV[intro]: "lmeasure (UNIV::'a::ordered_euclidean_space set) = \<omega>"
   4.652 +  unfolding lmeasure_def SUP_\<omega>
   4.653 +proof (intro allI impI)
   4.654 +  fix x assume "x < \<omega>"
   4.655 +  then obtain r where r: "x = Real r" "0 \<le> r" by (cases x) auto
   4.656 +  then obtain n where n: "r < of_nat n" using ex_less_of_nat by auto
   4.657 +  show "\<exists>i\<in>UNIV. x < Real (integral (cube i) (indicator UNIV::'a\<Rightarrow>real))"
   4.658 +  proof (intro bexI[of _ n])
   4.659 +    have [simp]: "indicator UNIV = (\<lambda>x. 1)" by (auto simp: fun_eq_iff)
   4.660 +    { fix m :: nat assume "0 < m" then have "real n \<le> (\<Prod>x<m. 2 * real n)"
   4.661 +      proof (induct m)
   4.662 +        case (Suc m)
   4.663 +        show ?case
   4.664 +        proof cases
   4.665 +          assume "m = 0" then show ?thesis by (simp add: lessThan_Suc)
   4.666 +        next
   4.667 +          assume "m \<noteq> 0" then have "real n \<le> (\<Prod>x<m. 2 * real n)" using Suc by auto
   4.668 +          then show ?thesis
   4.669 +            by (auto simp: lessThan_Suc field_simps mult_le_cancel_left1)
   4.670 +        qed
   4.671 +      qed auto } note this[OF DIM_positive[where 'a='a], simp]
   4.672 +    then have [simp]: "0 \<le> (\<Prod>x<DIM('a). 2 * real n)" using real_of_nat_ge_zero by arith
   4.673 +    have "x < Real (of_nat n)" using n r by auto
   4.674 +    also have "Real (of_nat n) \<le> Real (integral (cube n) (indicator UNIV::'a\<Rightarrow>real))"
   4.675 +      by (auto simp: real_eq_of_nat[symmetric] cube_def content_closed_interval_cases)
   4.676 +    finally show "x < Real (integral (cube n) (indicator UNIV::'a\<Rightarrow>real))" .
   4.677 +  qed auto
   4.678  qed
   4.679  
   4.680  lemma
   4.681    fixes a b ::"'a::ordered_euclidean_space"
   4.682    shows lmeasure_atLeastAtMost[simp]: "lmeasure {a..b} = Real (content {a..b})"
   4.683 -    and lmeasure_greaterThanLessThan[simp]: "lmeasure {a <..< b} = Real (content {a..b})"
   4.684 -  using has_gmeasure_interval[of a b] by (auto intro!: has_gmeasure_lmeasure)
   4.685 -
   4.686 -lemma lmeasure_cube:
   4.687 -  "lmeasure (cube n::('a::ordered_euclidean_space) set) = (Real ((2 * real n) ^ (DIM('a))))"
   4.688 -  by (intro has_gmeasure_lmeasure) auto
   4.689 -
   4.690 -lemma lmeasure_UNIV[intro]: "lmeasure UNIV = \<omega>"
   4.691 -  unfolding lmeasure_def SUP_\<omega>
   4.692 -proof (intro allI impI)
   4.693 -  fix x assume "x < \<omega>"
   4.694 -  then obtain r where r: "x = Real r" "0 \<le> r" by (cases x) auto
   4.695 -  then obtain n where n: "r < of_nat n" using ex_less_of_nat by auto
   4.696 -  show "\<exists>i\<in>UNIV. x < Real (gmeasure (UNIV \<inter> cube i))"
   4.697 -  proof (intro bexI[of _ n])
   4.698 -    have "x < Real (of_nat n)" using n r by auto
   4.699 -    also have "Real (of_nat n) \<le> Real (gmeasure (UNIV \<inter> cube n))"
   4.700 -      using gmeasure_cube_ge_n[of n] by (auto simp: real_eq_of_nat[symmetric])
   4.701 -    finally show "x < Real (gmeasure (UNIV \<inter> cube n))" .
   4.702 -  qed auto
   4.703 +proof -
   4.704 +  have "(indicator (UNIV \<inter> {a..b})::_\<Rightarrow>real) integrable_on UNIV"
   4.705 +    unfolding integrable_indicator_UNIV by (simp add: integrable_const indicator_def_raw)
   4.706 +  from lmeasure_eq_integral[OF this] show ?thesis unfolding integral_indicator_UNIV
   4.707 +    by (simp add: indicator_def_raw)
   4.708  qed
   4.709  
   4.710  lemma atLeastAtMost_singleton_euclidean[simp]:
   4.711 @@ -421,9 +454,7 @@
   4.712  
   4.713  lemma lmeasure_singleton[simp]:
   4.714    fixes a :: "'a::ordered_euclidean_space" shows "lmeasure {a} = 0"
   4.715 -  using has_gmeasure_interval[of a a] unfolding zero_pextreal_def
   4.716 -  by (intro has_gmeasure_lmeasure)
   4.717 -     (simp add: content_closed_interval DIM_positive)
   4.718 +  using lmeasure_atLeastAtMost[of a a] by simp
   4.719  
   4.720  declare content_real[simp]
   4.721  
   4.722 @@ -433,21 +464,33 @@
   4.723      "lmeasure {a <.. b} = Real (if a \<le> b then b - a else 0)"
   4.724  proof cases
   4.725    assume "a < b"
   4.726 -  then have "lmeasure {a <.. b} = lmeasure {a <..< b} + lmeasure {b}"
   4.727 -    by (subst lebesgue.measure_additive)
   4.728 -       (auto intro!: lebesgueI_borel arg_cong[where f=lmeasure])
   4.729 +  then have "lmeasure {a <.. b} = lmeasure {a .. b} - lmeasure {a}"
   4.730 +    by (subst lebesgue.measure_Diff[symmetric])
   4.731 +       (auto intro!: arg_cong[where f=lmeasure])
   4.732    then show ?thesis by auto
   4.733  qed auto
   4.734  
   4.735  lemma
   4.736    fixes a b :: real
   4.737    shows lmeasure_real_atLeastLessThan[simp]:
   4.738 -    "lmeasure {a ..< b} = Real (if a \<le> b then b - a else 0)" (is ?eqlt)
   4.739 +    "lmeasure {a ..< b} = Real (if a \<le> b then b - a else 0)"
   4.740  proof cases
   4.741    assume "a < b"
   4.742 -  then have "lmeasure {a ..< b} = lmeasure {a} + lmeasure {a <..< b}"
   4.743 -    by (subst lebesgue.measure_additive)
   4.744 -       (auto intro!: lebesgueI_borel arg_cong[where f=lmeasure])
   4.745 +  then have "lmeasure {a ..< b} = lmeasure {a .. b} - lmeasure {b}"
   4.746 +    by (subst lebesgue.measure_Diff[symmetric])
   4.747 +       (auto intro!: arg_cong[where f=lmeasure])
   4.748 +  then show ?thesis by auto
   4.749 +qed auto
   4.750 +
   4.751 +lemma
   4.752 +  fixes a b :: real
   4.753 +  shows lmeasure_real_greaterThanLessThan[simp]:
   4.754 +    "lmeasure {a <..< b} = Real (if a \<le> b then b - a else 0)"
   4.755 +proof cases
   4.756 +  assume "a < b"
   4.757 +  then have "lmeasure {a <..< b} = lmeasure {a <.. b} - lmeasure {b}"
   4.758 +    by (subst lebesgue.measure_Diff[symmetric])
   4.759 +       (auto intro!: arg_cong[where f=lmeasure])
   4.760    then show ?thesis by auto
   4.761  qed auto
   4.762  
   4.763 @@ -463,7 +506,7 @@
   4.764    show "range cube \<subseteq> sets borel" by (auto intro: borel_closed)
   4.765    { fix x have "\<exists>n. x\<in>cube n" using mem_big_cube by auto }
   4.766    thus "(\<Union>i. cube i) = space borel" by auto
   4.767 -  show "\<forall>i. lmeasure (cube i) \<noteq> \<omega>" unfolding lmeasure_cube by auto
   4.768 +  show "\<forall>i. lmeasure (cube i) \<noteq> \<omega>" unfolding cube_def by auto
   4.769  qed
   4.770  
   4.771  interpretation lebesgue: sigma_finite_measure lebesgue lmeasure
   4.772 @@ -482,7 +525,8 @@
   4.773    shows "((\<lambda>x. real (f x)) has_integral (real (lebesgue.simple_integral f))) UNIV"
   4.774    unfolding lebesgue.simple_integral_def
   4.775    apply(subst lebesgue_simple_function_indicator[OF f])
   4.776 -proof- case goal1
   4.777 +proof -
   4.778 +  case goal1
   4.779    have *:"\<And>x. \<forall>y\<in>range f. y * indicator (f -` {y}) x \<noteq> \<omega>"
   4.780      "\<forall>x\<in>range f. x * lmeasure (f -` {x} \<inter> UNIV) \<noteq> \<omega>"
   4.781      using f' om unfolding indicator_def by auto
   4.782 @@ -494,16 +538,19 @@
   4.783      fix y::'a show "((\<lambda>x. real (f y * indicator (f -` {f y}) x)) has_integral
   4.784        real (f y * lmeasure (f -` {f y} \<inter> UNIV))) UNIV"
   4.785      proof(cases "f y = 0") case False
   4.786 -      have mea:"gmeasurable (f -` {f y})" apply(rule lmeasure_finite_gmeasurable)
   4.787 +      have mea:"(indicator (f -` {f y}) ::_\<Rightarrow>real) integrable_on UNIV"
   4.788 +        apply(rule lmeasure_finite_integrable)
   4.789          using assms unfolding lebesgue.simple_function_def using False by auto
   4.790 -      have *:"\<And>x. real (indicator (f -` {f y}) x::pextreal) = (if x \<in> f -` {f y} then 1 else 0)" by auto
   4.791 +      have *:"\<And>x. real (indicator (f -` {f y}) x::pextreal) = (indicator (f -` {f y}) x)"
   4.792 +        by (auto simp: indicator_def)
   4.793        show ?thesis unfolding real_of_pextreal_mult[THEN sym]
   4.794          apply(rule has_integral_cmul[where 'b=real, unfolded real_scaleR_def])
   4.795 -        unfolding Int_UNIV_right lmeasure_gmeasure[OF mea,THEN sym]
   4.796 -        unfolding measure_integral_univ[OF mea] * apply(rule integrable_integral)
   4.797 -        unfolding gmeasurable_integrable[THEN sym] using mea .
   4.798 +        unfolding Int_UNIV_right lmeasure_eq_integral[OF mea,THEN sym]
   4.799 +        unfolding integral_eq_lmeasure[OF mea, symmetric] *
   4.800 +        apply(rule integrable_integral) using mea .
   4.801      qed auto
   4.802 -  qed qed
   4.803 +  qed
   4.804 +qed
   4.805  
   4.806  lemma bounded_realI: assumes "\<forall>x\<in>s. abs (x::real) \<le> B" shows "bounded s"
   4.807    unfolding bounded_def dist_real_def apply(rule_tac x=0 in exI)
   4.808 @@ -826,7 +873,7 @@
   4.809    show "Int_stable \<lparr> space = UNIV :: 'a set, sets = range (\<lambda>(a,b). {a..b}) \<rparr>"
   4.810      (is "Int_stable ?E" ) using Int_stable_cuboids' .
   4.811    show "borel = sigma ?E" using borel_eq_atLeastAtMost .
   4.812 -  show "\<And>i. lmeasure (cube i) \<noteq> \<omega>" unfolding lmeasure_cube by auto
   4.813 +  show "\<And>i. lmeasure (cube i) \<noteq> \<omega>" unfolding cube_def by auto
   4.814    show "\<And>X. X \<in> sets ?E \<Longrightarrow>
   4.815      lmeasure X = borel_product.product_measure {..<DIM('a)} (e2p ` X :: (nat \<Rightarrow> real) set)"
   4.816    proof- case goal1 then obtain a b where X:"X = {a..b}" by auto