src/HOL/Multivariate_Analysis/Integration.thy
changeset 39302 d7728f65b353
parent 38656 d5d342611edb
child 40163 a462d5207aa6
equal deleted inserted replaced
39301:e1bd8a54c40f 39302:d7728f65b353
   100 subsection {* Some useful lemmas about intervals. *}
   100 subsection {* Some useful lemmas about intervals. *}
   101 
   101 
   102 abbreviation One  where "One \<equiv> ((\<chi>\<chi> i. 1)::_::ordered_euclidean_space)"
   102 abbreviation One  where "One \<equiv> ((\<chi>\<chi> i. 1)::_::ordered_euclidean_space)"
   103 
   103 
   104 lemma empty_as_interval: "{} = {One..0}"
   104 lemma empty_as_interval: "{} = {One..0}"
   105   apply(rule set_ext,rule) defer unfolding mem_interval
   105   apply(rule set_eqI,rule) defer unfolding mem_interval
   106   using UNIV_witness[where 'a='n] apply(erule_tac exE,rule_tac x=x in allE) by auto
   106   using UNIV_witness[where 'a='n] apply(erule_tac exE,rule_tac x=x in allE) by auto
   107 
   107 
   108 lemma interior_subset_union_intervals: 
   108 lemma interior_subset_union_intervals: 
   109   assumes "i = {a..b::'a::ordered_euclidean_space}" "j = {c..d}" "interior j \<noteq> {}" "i \<subseteq> j \<union> s" "interior(i) \<inter> interior(j) = {}"
   109   assumes "i = {a..b::'a::ordered_euclidean_space}" "j = {c..d}" "interior j \<noteq> {}" "i \<subseteq> j \<union> s" "interior(i) \<inter> interior(j) = {}"
   110   shows "interior i \<subseteq> interior s" proof-
   110   shows "interior i \<subseteq> interior s" proof-
   365 lemma division_inter: assumes "p1 division_of s1" "p2 division_of (s2::('a::ordered_euclidean_space) set)"
   365 lemma division_inter: assumes "p1 division_of s1" "p2 division_of (s2::('a::ordered_euclidean_space) set)"
   366   shows "{k1 \<inter> k2 | k1 k2 .k1 \<in> p1 \<and> k2 \<in> p2 \<and> k1 \<inter> k2 \<noteq> {}} division_of (s1 \<inter> s2)" (is "?A' division_of _") proof-
   366   shows "{k1 \<inter> k2 | k1 k2 .k1 \<in> p1 \<and> k2 \<in> p2 \<and> k1 \<inter> k2 \<noteq> {}} division_of (s1 \<inter> s2)" (is "?A' division_of _") proof-
   367 let ?A = "{s. s \<in>  (\<lambda>(k1,k2). k1 \<inter> k2) ` (p1 \<times> p2) \<and> s \<noteq> {}}" have *:"?A' = ?A" by auto
   367 let ?A = "{s. s \<in>  (\<lambda>(k1,k2). k1 \<inter> k2) ` (p1 \<times> p2) \<and> s \<noteq> {}}" have *:"?A' = ?A" by auto
   368 show ?thesis unfolding * proof(rule division_ofI) have "?A \<subseteq> (\<lambda>(x, y). x \<inter> y) ` (p1 \<times> p2)" by auto
   368 show ?thesis unfolding * proof(rule division_ofI) have "?A \<subseteq> (\<lambda>(x, y). x \<inter> y) ` (p1 \<times> p2)" by auto
   369   moreover have "finite (p1 \<times> p2)" using assms unfolding division_of_def by auto ultimately show "finite ?A" by auto
   369   moreover have "finite (p1 \<times> p2)" using assms unfolding division_of_def by auto ultimately show "finite ?A" by auto
   370   have *:"\<And>s. \<Union>{x\<in>s. x \<noteq> {}} = \<Union>s" by auto show "\<Union>?A = s1 \<inter> s2" apply(rule set_ext) unfolding * and Union_image_eq UN_iff
   370   have *:"\<And>s. \<Union>{x\<in>s. x \<noteq> {}} = \<Union>s" by auto show "\<Union>?A = s1 \<inter> s2" apply(rule set_eqI) unfolding * and Union_image_eq UN_iff
   371     using division_ofD(6)[OF assms(1)] and division_ofD(6)[OF assms(2)] by auto
   371     using division_ofD(6)[OF assms(1)] and division_ofD(6)[OF assms(2)] by auto
   372   { fix k assume "k\<in>?A" then obtain k1 k2 where k:"k = k1 \<inter> k2" "k1\<in>p1" "k2\<in>p2" "k\<noteq>{}" by auto thus "k \<noteq> {}" by auto
   372   { fix k assume "k\<in>?A" then obtain k1 k2 where k:"k = k1 \<inter> k2" "k1\<in>p1" "k2\<in>p2" "k\<noteq>{}" by auto thus "k \<noteq> {}" by auto
   373   show "k \<subseteq> s1 \<inter> s2" using division_ofD(2)[OF assms(1) k(2)] and division_ofD(2)[OF assms(2) k(3)] unfolding k by auto
   373   show "k \<subseteq> s1 \<inter> s2" using division_ofD(2)[OF assms(1) k(2)] and division_ofD(2)[OF assms(2) k(3)] unfolding k by auto
   374   guess a1 using division_ofD(4)[OF assms(1) k(2)] .. then guess b1 .. note ab1=this
   374   guess a1 using division_ofD(4)[OF assms(1) k(2)] .. then guess b1 .. note ab1=this
   375   guess a2 using division_ofD(4)[OF assms(2) k(3)] .. then guess b2 .. note ab2=this
   375   guess a2 using division_ofD(4)[OF assms(2) k(3)] .. then guess b2 .. note ab2=this
  1033       proof(erule_tac[!] conjE) assume as:"c $$ i = a $$ i" "d $$ i = (a $$ i + b $$ i) / 2"
  1033       proof(erule_tac[!] conjE) assume as:"c $$ i = a $$ i" "d $$ i = (a $$ i + b $$ i) / 2"
  1034         show False using e_f(2)[of i] and i x unfolding as by(fastsimp simp add:field_simps)
  1034         show False using e_f(2)[of i] and i x unfolding as by(fastsimp simp add:field_simps)
  1035       next assume as:"c $$ i = (a $$ i + b $$ i) / 2" "d $$ i = b $$ i"
  1035       next assume as:"c $$ i = (a $$ i + b $$ i) / 2" "d $$ i = b $$ i"
  1036         show False using e_f(2)[of i] and i x unfolding as by(fastsimp simp add:field_simps)
  1036         show False using e_f(2)[of i] and i x unfolding as by(fastsimp simp add:field_simps)
  1037       qed qed qed
  1037       qed qed qed
  1038   also have "\<Union> ?A = {a..b}" proof(rule set_ext,rule)
  1038   also have "\<Union> ?A = {a..b}" proof(rule set_eqI,rule)
  1039     fix x assume "x\<in>\<Union>?A" then guess Y unfolding Union_iff ..
  1039     fix x assume "x\<in>\<Union>?A" then guess Y unfolding Union_iff ..
  1040     from this(1) guess c unfolding mem_Collect_eq .. then guess d ..
  1040     from this(1) guess c unfolding mem_Collect_eq .. then guess d ..
  1041     note c_d = this[THEN conjunct2,rule_format] `x\<in>Y`[unfolded this[THEN conjunct1]]
  1041     note c_d = this[THEN conjunct2,rule_format] `x\<in>Y`[unfolded this[THEN conjunct1]]
  1042     show "x\<in>{a..b}" unfolding mem_interval proof safe
  1042     show "x\<in>{a..b}" unfolding mem_interval proof safe
  1043       fix i assume "i<DIM('a)" thus "a $$ i \<le> x $$ i" "x $$ i \<le> b $$ i"
  1043       fix i assume "i<DIM('a)" thus "a $$ i \<le> x $$ i" "x $$ i \<le> b $$ i"
  1400 
  1400 
  1401 lemma integral_empty[simp]: shows "integral {} f = 0"
  1401 lemma integral_empty[simp]: shows "integral {} f = 0"
  1402   apply(rule integral_unique) using has_integral_empty .
  1402   apply(rule integral_unique) using has_integral_empty .
  1403 
  1403 
  1404 lemma has_integral_refl[intro]: shows "(f has_integral 0) {a..a}" "(f has_integral 0) {a::'a::ordered_euclidean_space}"
  1404 lemma has_integral_refl[intro]: shows "(f has_integral 0) {a..a}" "(f has_integral 0) {a::'a::ordered_euclidean_space}"
  1405 proof- have *:"{a} = {a..a}" apply(rule set_ext) unfolding mem_interval singleton_iff euclidean_eq[where 'a='a]
  1405 proof- have *:"{a} = {a..a}" apply(rule set_eqI) unfolding mem_interval singleton_iff euclidean_eq[where 'a='a]
  1406     apply safe prefer 3 apply(erule_tac x=i in allE) by(auto simp add: field_simps)
  1406     apply safe prefer 3 apply(erule_tac x=i in allE) by(auto simp add: field_simps)
  1407   show "(f has_integral 0) {a..a}" "(f has_integral 0) {a}" unfolding *
  1407   show "(f has_integral 0) {a..a}" "(f has_integral 0) {a}" unfolding *
  1408     apply(rule_tac[!] has_integral_null) unfolding content_eq_0_interior
  1408     apply(rule_tac[!] has_integral_null) unfolding content_eq_0_interior
  1409     unfolding interior_closed_interval using interval_sing by auto qed
  1409     unfolding interior_closed_interval using interval_sing by auto qed
  1410 
  1410 
  1464 subsection {* Additivity of integral on abutting intervals. *}
  1464 subsection {* Additivity of integral on abutting intervals. *}
  1465 
  1465 
  1466 lemma interval_split: fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)" shows
  1466 lemma interval_split: fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)" shows
  1467   "{a..b} \<inter> {x. x$$k \<le> c} = {a .. (\<chi>\<chi> i. if i = k then min (b$$k) c else b$$i)}"
  1467   "{a..b} \<inter> {x. x$$k \<le> c} = {a .. (\<chi>\<chi> i. if i = k then min (b$$k) c else b$$i)}"
  1468   "{a..b} \<inter> {x. x$$k \<ge> c} = {(\<chi>\<chi> i. if i = k then max (a$$k) c else a$$i) .. b}"
  1468   "{a..b} \<inter> {x. x$$k \<ge> c} = {(\<chi>\<chi> i. if i = k then max (a$$k) c else a$$i) .. b}"
  1469   apply(rule_tac[!] set_ext) unfolding Int_iff mem_interval mem_Collect_eq using assms by auto
  1469   apply(rule_tac[!] set_eqI) unfolding Int_iff mem_interval mem_Collect_eq using assms by auto
  1470 
  1470 
  1471 lemma content_split: fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)" shows
  1471 lemma content_split: fixes a::"'a::ordered_euclidean_space" assumes "k<DIM('a)" shows
  1472   "content {a..b} = content({a..b} \<inter> {x. x$$k \<le> c}) + content({a..b} \<inter> {x. x$$k >= c})"
  1472   "content {a..b} = content({a..b} \<inter> {x. x$$k \<le> c}) + content({a..b} \<inter> {x. x$$k >= c})"
  1473 proof- note simps = interval_split[OF assms] content_closed_interval_cases eucl_le[where 'a='a]
  1473 proof- note simps = interval_split[OF assms] content_closed_interval_cases eucl_le[where 'a='a]
  1474   { presume "a\<le>b \<Longrightarrow> ?thesis" thus ?thesis apply(cases "a\<le>b") unfolding simps using assms by auto }
  1474   { presume "a\<le>b \<Longrightarrow> ?thesis" thus ?thesis apply(cases "a\<le>b") unfolding simps using assms by auto }
  2492 proof- have *:"\<And>x c. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  2492 proof- have *:"\<And>x c. abs(x - c) \<le> e \<longleftrightarrow> x \<ge> c - e \<and> x \<le> c + e" by auto
  2493   have **:"\<And>p q p' q'. p division_of q \<Longrightarrow> p = p' \<Longrightarrow> q = q' \<Longrightarrow> p' division_of q'" by auto
  2493   have **:"\<And>p q p' q'. p division_of q \<Longrightarrow> p = p' \<Longrightarrow> q = q' \<Longrightarrow> p' division_of q'" by auto
  2494   note division_split(1)[OF assms, where c="c+e",unfolded interval_split[OF k]]
  2494   note division_split(1)[OF assms, where c="c+e",unfolded interval_split[OF k]]
  2495   note division_split(2)[OF this, where c="c-e" and k=k,OF k] 
  2495   note division_split(2)[OF this, where c="c-e" and k=k,OF k] 
  2496   thus ?thesis apply(rule **) using k apply- unfolding interval_doublesplit unfolding * unfolding interval_split interval_doublesplit
  2496   thus ?thesis apply(rule **) using k apply- unfolding interval_doublesplit unfolding * unfolding interval_split interval_doublesplit
  2497     apply(rule set_ext) unfolding mem_Collect_eq apply rule apply(erule conjE exE)+ apply(rule_tac x=la in exI) defer
  2497     apply(rule set_eqI) unfolding mem_Collect_eq apply rule apply(erule conjE exE)+ apply(rule_tac x=la in exI) defer
  2498     apply(erule conjE exE)+ apply(rule_tac x="l \<inter> {x. c + e \<ge> x $$ k}" in exI) apply rule defer apply rule
  2498     apply(erule conjE exE)+ apply(rule_tac x="l \<inter> {x. c + e \<ge> x $$ k}" in exI) apply rule defer apply rule
  2499     apply(rule_tac x=l in exI) by blast+ qed
  2499     apply(rule_tac x=l in exI) by blast+ qed
  2500 
  2500 
  2501 lemma content_doublesplit: fixes a::"'a::ordered_euclidean_space" assumes "0 < e" and k:"k<DIM('a)"
  2501 lemma content_doublesplit: fixes a::"'a::ordered_euclidean_space" assumes "0 < e" and k:"k<DIM('a)"
  2502   obtains d where "0 < d" "content({a..b} \<inter> {x. abs(x$$k - c) \<le> d}) < e"
  2502   obtains d where "0 < d" "content({a..b} \<inter> {x. abs(x$$k - c) \<le> d}) < e"
  2536     have *:"(\<Sum>(x, ka)\<in>p. content ka *\<^sub>R ?i x) = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. abs(x$$k - c) \<le> d}) *\<^sub>R ?i x)"
  2536     have *:"(\<Sum>(x, ka)\<in>p. content ka *\<^sub>R ?i x) = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. abs(x$$k - c) \<le> d}) *\<^sub>R ?i x)"
  2537       apply(rule setsum_cong2) unfolding split_paired_all real_scaleR_def mult_cancel_right split_conv
  2537       apply(rule setsum_cong2) unfolding split_paired_all real_scaleR_def mult_cancel_right split_conv
  2538       apply(cases,rule disjI1,assumption,rule disjI2)
  2538       apply(cases,rule disjI1,assumption,rule disjI2)
  2539     proof- fix x l assume as:"(x,l)\<in>p" "?i x \<noteq> 0" hence xk:"x$$k = c" unfolding indicator_def apply-by(rule ccontr,auto)
  2539     proof- fix x l assume as:"(x,l)\<in>p" "?i x \<noteq> 0" hence xk:"x$$k = c" unfolding indicator_def apply-by(rule ccontr,auto)
  2540       show "content l = content (l \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d})" apply(rule arg_cong[where f=content])
  2540       show "content l = content (l \<inter> {x. \<bar>x $$ k - c\<bar> \<le> d})" apply(rule arg_cong[where f=content])
  2541         apply(rule set_ext,rule,rule) unfolding mem_Collect_eq
  2541         apply(rule set_eqI,rule,rule) unfolding mem_Collect_eq
  2542       proof- fix y assume y:"y\<in>l" note p[THEN conjunct2,unfolded fine_def,rule_format,OF as(1),unfolded split_conv]
  2542       proof- fix y assume y:"y\<in>l" note p[THEN conjunct2,unfolded fine_def,rule_format,OF as(1),unfolded split_conv]
  2543         note this[unfolded subset_eq mem_ball dist_norm,rule_format,OF y] note le_less_trans[OF component_le_norm[of _ k] this]
  2543         note this[unfolded subset_eq mem_ball dist_norm,rule_format,OF y] note le_less_trans[OF component_le_norm[of _ k] this]
  2544         thus "\<bar>y $$ k - c\<bar> \<le> d" unfolding euclidean_simps xk by auto
  2544         thus "\<bar>y $$ k - c\<bar> \<le> d" unfolding euclidean_simps xk by auto
  2545       qed auto qed
  2545       qed auto qed
  2546     note p'= tagged_division_ofD[OF p[THEN conjunct1]] and p''=division_of_tagged_division[OF p[THEN conjunct1]]
  2546     note p'= tagged_division_ofD[OF p[THEN conjunct1]] and p''=division_of_tagged_division[OF p[THEN conjunct1]]
  3278   (if {a..b} = {} then {} else {(\<chi>\<chi> k. min (m(k) * a$$k) (m(k) * b$$k))::'a ..  (\<chi>\<chi> k. max (m(k) * a$$k) (m(k) * b$$k))})"
  3278   (if {a..b} = {} then {} else {(\<chi>\<chi> k. min (m(k) * a$$k) (m(k) * b$$k))::'a ..  (\<chi>\<chi> k. max (m(k) * a$$k) (m(k) * b$$k))})"
  3279   (is "?l = ?r")
  3279   (is "?l = ?r")
  3280 proof(cases "{a..b}={}") case True thus ?thesis unfolding True by auto
  3280 proof(cases "{a..b}={}") case True thus ?thesis unfolding True by auto
  3281 next have *:"\<And>P Q. (\<forall>i<DIM('a). P i) \<and> (\<forall>i<DIM('a). Q i) \<longleftrightarrow> (\<forall>i<DIM('a). P i \<and> Q i)" by auto
  3281 next have *:"\<And>P Q. (\<forall>i<DIM('a). P i) \<and> (\<forall>i<DIM('a). Q i) \<longleftrightarrow> (\<forall>i<DIM('a). P i \<and> Q i)" by auto
  3282   case False note ab = this[unfolded interval_ne_empty]
  3282   case False note ab = this[unfolded interval_ne_empty]
  3283   show ?thesis apply-apply(rule set_ext)
  3283   show ?thesis apply-apply(rule set_eqI)
  3284   proof- fix x::"'a" have **:"\<And>P Q. (\<forall>i<DIM('a). P i = Q i) \<Longrightarrow> (\<forall>i<DIM('a). P i) = (\<forall>i<DIM('a). Q i)" by auto
  3284   proof- fix x::"'a" have **:"\<And>P Q. (\<forall>i<DIM('a). P i = Q i) \<Longrightarrow> (\<forall>i<DIM('a). P i) = (\<forall>i<DIM('a). Q i)" by auto
  3285     show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" unfolding if_not_P[OF False] 
  3285     show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" unfolding if_not_P[OF False] 
  3286       unfolding image_iff mem_interval Bex_def euclidean_simps euclidean_eq[where 'a='a] *
  3286       unfolding image_iff mem_interval Bex_def euclidean_simps euclidean_eq[where 'a='a] *
  3287       unfolding imp_conjR[THEN sym] apply(subst euclidean_lambda_beta'') apply(subst lambda_skolem'[THEN sym])
  3287       unfolding imp_conjR[THEN sym] apply(subst euclidean_lambda_beta'') apply(subst lambda_skolem'[THEN sym])
  3288       apply(rule **,rule,rule) unfolding euclidean_lambda_beta'
  3288       apply(rule **,rule,rule) unfolding euclidean_lambda_beta'
  3332   apply(drule has_integral_stretch,assumption) by auto
  3332   apply(drule has_integral_stretch,assumption) by auto
  3333 
  3333 
  3334 subsection {* even more special cases. *}
  3334 subsection {* even more special cases. *}
  3335 
  3335 
  3336 lemma uminus_interval_vector[simp]:"uminus ` {a..b} = {-b .. -a::'a::ordered_euclidean_space}"
  3336 lemma uminus_interval_vector[simp]:"uminus ` {a..b} = {-b .. -a::'a::ordered_euclidean_space}"
  3337   apply(rule set_ext,rule) defer unfolding image_iff
  3337   apply(rule set_eqI,rule) defer unfolding image_iff
  3338   apply(rule_tac x="-x" in bexI) by(auto simp add:minus_le_iff le_minus_iff eucl_le[where 'a='a])
  3338   apply(rule_tac x="-x" in bexI) by(auto simp add:minus_le_iff le_minus_iff eucl_le[where 'a='a])
  3339 
  3339 
  3340 lemma has_integral_reflect_lemma[intro]: assumes "(f has_integral i) {a..b}"
  3340 lemma has_integral_reflect_lemma[intro]: assumes "(f has_integral i) {a..b}"
  3341   shows "((\<lambda>x. f(-x)) has_integral i) {-b .. -a}"
  3341   shows "((\<lambda>x. f(-x)) has_integral i) {-b .. -a}"
  3342   using has_integral_affinity[OF assms, of "-1" 0] by auto
  3342   using has_integral_affinity[OF assms, of "-1" 0] by auto
  3692   assumes "f integrable_on {a..b}" shows  "continuous_on {a..b} (\<lambda>x. integral {a..x} f)"
  3692   assumes "f integrable_on {a..b}" shows  "continuous_on {a..b} (\<lambda>x. integral {a..x} f)"
  3693 proof(unfold continuous_on_iff, safe)  fix x e assume as:"x\<in>{a..b}" "0<(e::real)"
  3693 proof(unfold continuous_on_iff, safe)  fix x e assume as:"x\<in>{a..b}" "0<(e::real)"
  3694   let ?thesis = "\<exists>d>0. \<forall>x'\<in>{a..b}. dist x' x < d \<longrightarrow> dist (integral {a..x'} f) (integral {a..x} f) < e"
  3694   let ?thesis = "\<exists>d>0. \<forall>x'\<in>{a..b}. dist x' x < d \<longrightarrow> dist (integral {a..x'} f) (integral {a..x} f) < e"
  3695   { presume *:"a<b \<Longrightarrow> ?thesis"
  3695   { presume *:"a<b \<Longrightarrow> ?thesis"
  3696     show ?thesis apply(cases,rule *,assumption)
  3696     show ?thesis apply(cases,rule *,assumption)
  3697     proof- case goal1 hence "{a..b} = {x}" using as(1) apply-apply(rule set_ext)
  3697     proof- case goal1 hence "{a..b} = {x}" using as(1) apply-apply(rule set_eqI)
  3698         unfolding atLeastAtMost_iff by(auto simp only:field_simps not_less DIM_real)
  3698         unfolding atLeastAtMost_iff by(auto simp only:field_simps not_less DIM_real)
  3699       thus ?case using `e>0` by auto
  3699       thus ?case using `e>0` by auto
  3700     qed } assume "a<b"
  3700     qed } assume "a<b"
  3701   have "(x=a \<or> x=b) \<or> (a<x \<and> x<b)" using as(1) by (auto simp add:)
  3701   have "(x=a \<or> x=b) \<or> (a<x \<and> x<b)" using as(1) by (auto simp add:)
  3702   thus ?thesis apply-apply(erule disjE)+
  3702   thus ?thesis apply-apply(erule disjE)+