src/HOL/Analysis/Regularity.thy
author wenzelm
Mon Mar 25 17:21:26 2019 +0100 (4 weeks ago)
changeset 69981 3dced198b9ec
parent 69739 8b47c021666e
permissions -rw-r--r--
more strict AFP properties;
hoelzl@63627
     1
(*  Title:      HOL/Analysis/Regularity.thy
immler@50087
     2
    Author:     Fabian Immler, TU M√ľnchen
immler@50087
     3
*)
immler@50087
     4
wenzelm@61808
     5
section \<open>Regularity of Measures\<close>
immler@50089
     6
ak2110@69730
     7
theory Regularity (* FIX suggestion to rename  e.g. RegularityMeasures and/ or move as
ak2110@69730
     8
this theory consists of 1 result only  *)
immler@50087
     9
imports Measure_Space Borel_Space
immler@50087
    10
begin
immler@50087
    11
nipkow@69739
    12
theorem
hoelzl@50881
    13
  fixes M::"'a::{second_countable_topology, complete_space} measure"
immler@50087
    14
  assumes sb: "sets M = sets borel"
immler@50087
    15
  assumes "emeasure M (space M) \<noteq> \<infinity>"
immler@50087
    16
  assumes "B \<in> sets borel"
immler@50087
    17
  shows inner_regular: "emeasure M B =
haftmann@69260
    18
    (SUP K \<in> {K. K \<subseteq> B \<and> compact K}. emeasure M K)" (is "?inner B")
immler@50087
    19
  and outer_regular: "emeasure M B =
haftmann@69260
    20
    (INF U \<in> {U. B \<subseteq> U \<and> open U}. emeasure M U)" (is "?outer B")
ak2110@69730
    21
proof -
immler@50087
    22
  have Us: "UNIV = space M" by (metis assms(1) sets_eq_imp_space_eq space_borel)
immler@50087
    23
  hence sU: "space M = UNIV" by simp
immler@50087
    24
  interpret finite_measure M by rule fact
immler@50087
    25
  have approx_inner: "\<And>A. A \<in> sets M \<Longrightarrow>
hoelzl@62975
    26
    (\<And>e. e > 0 \<Longrightarrow> \<exists>K. K \<subseteq> A \<and> compact K \<and> emeasure M A \<le> emeasure M K + ennreal e) \<Longrightarrow> ?inner A"
hoelzl@62975
    27
    by (rule ennreal_approx_SUP)
immler@50087
    28
      (force intro!: emeasure_mono simp: compact_imp_closed emeasure_eq_measure)+
immler@50087
    29
  have approx_outer: "\<And>A. A \<in> sets M \<Longrightarrow>
hoelzl@62975
    30
    (\<And>e. e > 0 \<Longrightarrow> \<exists>B. A \<subseteq> B \<and> open B \<and> emeasure M B \<le> emeasure M A + ennreal e) \<Longrightarrow> ?outer A"
hoelzl@62975
    31
    by (rule ennreal_approx_INF)
immler@50087
    32
       (force intro!: emeasure_mono simp: emeasure_eq_measure sb)+
immler@50245
    33
  from countable_dense_setE guess X::"'a set"  . note X = this
immler@50087
    34
  {
immler@50087
    35
    fix r::real assume "r > 0" hence "\<And>y. open (ball y r)" "\<And>y. ball y r \<noteq> {}" by auto
immler@50245
    36
    with X(2)[OF this]
immler@50245
    37
    have x: "space M = (\<Union>x\<in>X. cball x r)"
immler@50087
    38
      by (auto simp add: sU) (metis dist_commute order_less_imp_le)
immler@50245
    39
    let ?U = "\<Union>k. (\<Union>n\<in>{0..k}. cball (from_nat_into X n) r)"
wenzelm@61969
    40
    have "(\<lambda>k. emeasure M (\<Union>n\<in>{0..k}. cball (from_nat_into X n) r)) \<longlonglongrightarrow> M ?U"
hoelzl@62975
    41
      by (rule Lim_emeasure_incseq) (auto intro!: borel_closed bexI simp: incseq_def Us sb)
immler@50245
    42
    also have "?U = space M"
immler@50245
    43
    proof safe
wenzelm@61808
    44
      fix x from X(2)[OF open_ball[of x r]] \<open>r > 0\<close> obtain d where d: "d\<in>X" "d \<in> ball x r" by auto
immler@50245
    45
      show "x \<in> ?U"
haftmann@62343
    46
        using X(1) d
haftmann@62343
    47
        by simp (auto intro!: exI [where x = "to_nat_on X d"] simp: dist_commute Bex_def)
immler@50245
    48
    qed (simp add: sU)
wenzelm@61969
    49
    finally have "(\<lambda>k. M (\<Union>n\<in>{0..k}. cball (from_nat_into X n) r)) \<longlonglongrightarrow> M (space M)" .
immler@50087
    50
  } note M_space = this
immler@50087
    51
  {
immler@50087
    52
    fix e ::real and n :: nat assume "e > 0" "n > 0"
nipkow@56544
    53
    hence "1/n > 0" "e * 2 powr - n > 0" by (auto)
wenzelm@61808
    54
    from M_space[OF \<open>1/n>0\<close>]
wenzelm@61969
    55
    have "(\<lambda>k. measure M (\<Union>i\<in>{0..k}. cball (from_nat_into X i) (1/real n))) \<longlonglongrightarrow> measure M (space M)"
hoelzl@62975
    56
      unfolding emeasure_eq_measure by (auto simp: measure_nonneg)
wenzelm@61808
    57
    from metric_LIMSEQ_D[OF this \<open>0 < e * 2 powr -n\<close>]
immler@50245
    58
    obtain k where "dist (measure M (\<Union>i\<in>{0..k}. cball (from_nat_into X i) (1/real n))) (measure M (space M)) <
immler@50087
    59
      e * 2 powr -n"
immler@50087
    60
      by auto
immler@50245
    61
    hence "measure M (\<Union>i\<in>{0..k}. cball (from_nat_into X i) (1/real n)) \<ge>
immler@50087
    62
      measure M (space M) - e * 2 powr -real n"
immler@50087
    63
      by (auto simp: dist_real_def)
immler@50245
    64
    hence "\<exists>k. measure M (\<Union>i\<in>{0..k}. cball (from_nat_into X i) (1/real n)) \<ge>
immler@50087
    65
      measure M (space M) - e * 2 powr - real n" ..
immler@50087
    66
  } note k=this
immler@50087
    67
  hence "\<forall>e\<in>{0<..}. \<forall>(n::nat)\<in>{0<..}. \<exists>k.
immler@50245
    68
    measure M (\<Union>i\<in>{0..k}. cball (from_nat_into X i) (1/real n)) \<ge> measure M (space M) - e * 2 powr - real n"
immler@50087
    69
    by blast
immler@50087
    70
  then obtain k where k: "\<forall>e\<in>{0<..}. \<forall>n\<in>{0<..}. measure M (space M) - e * 2 powr - real (n::nat)
immler@50245
    71
    \<le> measure M (\<Union>i\<in>{0..k e n}. cball (from_nat_into X i) (1 / n))"
hoelzl@58184
    72
    by metis
immler@50087
    73
  hence k: "\<And>e n. e > 0 \<Longrightarrow> n > 0 \<Longrightarrow> measure M (space M) - e * 2 powr - n
immler@50245
    74
    \<le> measure M (\<Union>i\<in>{0..k e n}. cball (from_nat_into X i) (1 / n))"
immler@50087
    75
    unfolding Ball_def by blast
immler@50087
    76
  have approx_space:
hoelzl@62975
    77
    "\<exists>K \<in> {K. K \<subseteq> space M \<and> compact K}. emeasure M (space M) \<le> emeasure M K + ennreal e"
hoelzl@62975
    78
    (is "?thesis e") if "0 < e" for e :: real
immler@50087
    79
  proof -
wenzelm@63040
    80
    define B where [abs_def]:
wenzelm@63040
    81
      "B n = (\<Union>i\<in>{0..k e (Suc n)}. cball (from_nat_into X i) (1 / Suc n))" for n
hoelzl@62975
    82
    have "\<And>n. closed (B n)" by (auto simp: B_def)
immler@50087
    83
    hence [simp]: "\<And>n. B n \<in> sets M" by (simp add: sb)
wenzelm@61808
    84
    from k[OF \<open>e > 0\<close> zero_less_Suc]
immler@50087
    85
    have "\<And>n. measure M (space M) - measure M (B n) \<le> e * 2 powr - real (Suc n)"
immler@50087
    86
      by (simp add: algebra_simps B_def finite_measure_compl)
immler@50087
    87
    hence B_compl_le: "\<And>n::nat. measure M (space M - B n) \<le> e * 2 powr - real (Suc n)"
immler@50087
    88
      by (simp add: finite_measure_compl)
wenzelm@63040
    89
    define K where "K = (\<Inter>n. B n)"
wenzelm@61808
    90
    from \<open>closed (B _)\<close> have "closed K" by (auto simp: K_def)
immler@50087
    91
    hence [simp]: "K \<in> sets M" by (simp add: sb)
immler@50087
    92
    have "measure M (space M) - measure M K = measure M (space M - K)"
immler@50087
    93
      by (simp add: finite_measure_compl)
immler@50087
    94
    also have "\<dots> = emeasure M (\<Union>n. space M - B n)" by (auto simp: K_def emeasure_eq_measure)
immler@50087
    95
    also have "\<dots> \<le> (\<Sum>n. emeasure M (space M - B n))"
immler@50087
    96
      by (rule emeasure_subadditive_countably) (auto simp: summable_def)
hoelzl@62975
    97
    also have "\<dots> \<le> (\<Sum>n. ennreal (e*2 powr - real (Suc n)))"
hoelzl@62975
    98
      using B_compl_le by (intro suminf_le) (simp_all add: measure_nonneg emeasure_eq_measure ennreal_leI)
hoelzl@62975
    99
    also have "\<dots> \<le> (\<Sum>n. ennreal (e * (1 / 2) ^ Suc n))"
hoelzl@62975
   100
      by (simp add: powr_minus powr_realpow field_simps del: of_nat_Suc)
hoelzl@62975
   101
    also have "\<dots> = ennreal e * (\<Sum>n. ennreal ((1 / 2) ^ Suc n))"
hoelzl@62975
   102
      unfolding ennreal_power[symmetric]
hoelzl@62975
   103
      using \<open>0 < e\<close>
hoelzl@62975
   104
      by (simp add: ac_simps ennreal_mult' divide_ennreal[symmetric] divide_ennreal_def
hoelzl@62975
   105
                    ennreal_power[symmetric])
hoelzl@62975
   106
    also have "\<dots> = e"
hoelzl@62975
   107
      by (subst suminf_ennreal_eq[OF zero_le_power power_half_series]) auto
hoelzl@62975
   108
    finally have "measure M (space M) \<le> measure M K + e"
hoelzl@62975
   109
      using \<open>0 < e\<close> by simp
hoelzl@62975
   110
    hence "emeasure M (space M) \<le> emeasure M K + e"
nipkow@68403
   111
      using \<open>0 < e\<close> by (simp add: emeasure_eq_measure flip: ennreal_plus)
immler@50087
   112
    moreover have "compact K"
immler@50087
   113
      unfolding compact_eq_totally_bounded
immler@50087
   114
    proof safe
wenzelm@61808
   115
      show "complete K" using \<open>closed K\<close> by (simp add: complete_eq_closed)
immler@50087
   116
      fix e'::real assume "0 < e'"
immler@50087
   117
      from nat_approx_posE[OF this] guess n . note n = this
immler@50245
   118
      let ?k = "from_nat_into X ` {0..k e (Suc n)}"
immler@50087
   119
      have "finite ?k" by simp
hoelzl@58184
   120
      moreover have "K \<subseteq> (\<Union>x\<in>?k. ball x e')" unfolding K_def B_def using n by force
hoelzl@58184
   121
      ultimately show "\<exists>k. finite k \<and> K \<subseteq> (\<Union>x\<in>k. ball x e')" by blast
immler@50087
   122
    qed
immler@50087
   123
    ultimately
hoelzl@62975
   124
    show ?thesis by (auto simp: sU)
immler@50087
   125
  qed
hoelzl@50125
   126
  { fix A::"'a set" assume "closed A" hence "A \<in> sets borel" by (simp add: compact_imp_closed)
immler@50087
   127
    hence [simp]: "A \<in> sets M" by (simp add: sb)
hoelzl@50125
   128
    have "?inner A"
immler@50087
   129
    proof (rule approx_inner)
immler@50087
   130
      fix e::real assume "e > 0"
immler@50087
   131
      from approx_space[OF this] obtain K where
immler@50087
   132
        K: "K \<subseteq> space M" "compact K" "emeasure M (space M) \<le> emeasure M K + e"
immler@50087
   133
        by (auto simp: emeasure_eq_measure)
immler@50087
   134
      hence [simp]: "K \<in> sets M" by (simp add: sb compact_imp_closed)
hoelzl@62975
   135
      have "measure M A - measure M (A \<inter> K) = measure M (A - A \<inter> K)"
immler@50087
   136
        by (subst finite_measure_Diff) auto
immler@50087
   137
      also have "A - A \<inter> K = A \<union> K - K" by auto
immler@50087
   138
      also have "measure M \<dots> = measure M (A \<union> K) - measure M K"
immler@50087
   139
        by (subst finite_measure_Diff) auto
immler@50087
   140
      also have "\<dots> \<le> measure M (space M) - measure M K"
immler@50087
   141
        by (simp add: emeasure_eq_measure sU sb finite_measure_mono)
hoelzl@62975
   142
      also have "\<dots> \<le> e"
nipkow@68403
   143
        using K \<open>0 < e\<close> by (simp add: emeasure_eq_measure flip: ennreal_plus)
hoelzl@62975
   144
      finally have "emeasure M A \<le> emeasure M (A \<inter> K) + ennreal e"
nipkow@68403
   145
        using \<open>0<e\<close> by (simp add: emeasure_eq_measure algebra_simps flip: ennreal_plus)
wenzelm@61808
   146
      moreover have "A \<inter> K \<subseteq> A" "compact (A \<inter> K)" using \<open>closed A\<close> \<open>compact K\<close> by auto
hoelzl@62975
   147
      ultimately show "\<exists>K \<subseteq> A. compact K \<and> emeasure M A \<le> emeasure M K + ennreal e"
immler@50087
   148
        by blast
immler@50087
   149
    qed simp
hoelzl@50125
   150
    have "?outer A"
immler@50087
   151
    proof cases
immler@50087
   152
      assume "A \<noteq> {}"
immler@50087
   153
      let ?G = "\<lambda>d. {x. infdist x A < d}"
immler@50087
   154
      {
immler@50087
   155
        fix d
immler@50087
   156
        have "?G d = (\<lambda>x. infdist x A) -` {..<d}" by auto
immler@50087
   157
        also have "open \<dots>"
lp15@62533
   158
          by (intro continuous_open_vimage) (auto intro!: continuous_infdist continuous_ident)
immler@50087
   159
        finally have "open (?G d)" .
immler@50087
   160
      } note open_G = this
wenzelm@61808
   161
      from in_closed_iff_infdist_zero[OF \<open>closed A\<close> \<open>A \<noteq> {}\<close>]
immler@50087
   162
      have "A = {x. infdist x A = 0}" by auto
immler@50087
   163
      also have "\<dots> = (\<Inter>i. ?G (1/real (Suc i)))"
lp15@61609
   164
      proof (auto simp del: of_nat_Suc, rule ccontr)
immler@50087
   165
        fix x
immler@50087
   166
        assume "infdist x A \<noteq> 0"
immler@50087
   167
        hence pos: "infdist x A > 0" using infdist_nonneg[of x A] by simp
immler@50087
   168
        from nat_approx_posE[OF this] guess n .
immler@50087
   169
        moreover
immler@50087
   170
        assume "\<forall>i. infdist x A < 1 / real (Suc i)"
immler@50087
   171
        hence "infdist x A < 1 / real (Suc n)" by auto
lp15@61609
   172
        ultimately show False by simp
immler@50087
   173
      qed
immler@50087
   174
      also have "M \<dots> = (INF n. emeasure M (?G (1 / real (Suc n))))"
immler@50087
   175
      proof (rule INF_emeasure_decseq[symmetric], safe)
immler@50087
   176
        fix i::nat
immler@50087
   177
        from open_G[of "1 / real (Suc i)"]
immler@50087
   178
        show "?G (1 / real (Suc i)) \<in> sets M" by (simp add: sb borel_open)
immler@50087
   179
      next
immler@50087
   180
        show "decseq (\<lambda>i. {x. infdist x A < 1 / real (Suc i)})"
nipkow@56544
   181
          by (auto intro: less_trans intro!: divide_strict_left_mono
immler@50087
   182
            simp: decseq_def le_eq_less_or_eq)
immler@50087
   183
      qed simp
immler@50087
   184
      finally
immler@50087
   185
      have "emeasure M A = (INF n. emeasure M {x. infdist x A < 1 / real (Suc n)})" .
immler@50087
   186
      moreover
haftmann@69260
   187
      have "\<dots> \<ge> (INF U\<in>{U. A \<subseteq> U \<and> open U}. emeasure M U)"
immler@50087
   188
      proof (intro INF_mono)
immler@50087
   189
        fix m
immler@50087
   190
        have "?G (1 / real (Suc m)) \<in> {U. A \<subseteq> U \<and> open U}" using open_G by auto
immler@50087
   191
        moreover have "M (?G (1 / real (Suc m))) \<le> M (?G (1 / real (Suc m)))" by simp
immler@50087
   192
        ultimately show "\<exists>U\<in>{U. A \<subseteq> U \<and> open U}.
immler@50087
   193
          emeasure M U \<le> emeasure M {x. infdist x A < 1 / real (Suc m)}"
immler@50087
   194
          by blast
immler@50087
   195
      qed
immler@50087
   196
      moreover
haftmann@69260
   197
      have "emeasure M A \<le> (INF U\<in>{U. A \<subseteq> U \<and> open U}. emeasure M U)"
immler@50087
   198
        by (rule INF_greatest) (auto intro!: emeasure_mono simp: sb)
immler@50087
   199
      ultimately show ?thesis by simp
hoelzl@51000
   200
    qed (auto intro!: INF_eqI)
wenzelm@61808
   201
    note \<open>?inner A\<close> \<open>?outer A\<close> }
hoelzl@50125
   202
  note closed_in_D = this
wenzelm@61808
   203
  from \<open>B \<in> sets borel\<close>
lp15@61609
   204
  have "Int_stable (Collect closed)" "Collect closed \<subseteq> Pow UNIV" "B \<in> sigma_sets UNIV (Collect closed)"
hoelzl@50125
   205
    by (auto simp: Int_stable_def borel_eq_closed)
hoelzl@50125
   206
  then show "?inner B" "?outer B"
hoelzl@50125
   207
  proof (induct B rule: sigma_sets_induct_disjoint)
hoelzl@50125
   208
    case empty
hoelzl@51000
   209
    { case 1 show ?case by (intro SUP_eqI[symmetric]) auto }
hoelzl@51000
   210
    { case 2 show ?case by (intro INF_eqI[symmetric]) (auto elim!: meta_allE[of _ "{}"]) }
immler@50087
   211
  next
hoelzl@50125
   212
    case (basic B)
hoelzl@50125
   213
    { case 1 from basic closed_in_D show ?case by auto }
hoelzl@50125
   214
    { case 2 from basic closed_in_D show ?case by auto }
hoelzl@50125
   215
  next
hoelzl@50125
   216
    case (compl B)
hoelzl@50125
   217
    note inner = compl(2) and outer = compl(3)
hoelzl@50125
   218
    from compl have [simp]: "B \<in> sets M" by (auto simp: sb borel_eq_closed)
hoelzl@50125
   219
    case 2
immler@50087
   220
    have "M (space M - B) = M (space M) - emeasure M B" by (auto simp: emeasure_compl)
haftmann@69260
   221
    also have "\<dots> = (INF K\<in>{K. K \<subseteq> B \<and> compact K}. M (space M) -  M K)"
hoelzl@62975
   222
      by (subst ennreal_SUP_const_minus) (auto simp: less_top[symmetric] inner)
haftmann@69260
   223
    also have "\<dots> = (INF U\<in>{U. U \<subseteq> B \<and> compact U}. M (space M - U))"
haftmann@69661
   224
      by (auto simp add: emeasure_compl sb compact_imp_closed)
haftmann@69260
   225
    also have "\<dots> \<ge> (INF U\<in>{U. U \<subseteq> B \<and> closed U}. M (space M - U))"
immler@50087
   226
      by (rule INF_superset_mono) (auto simp add: compact_imp_closed)
haftmann@69260
   227
    also have "(INF U\<in>{U. U \<subseteq> B \<and> closed U}. M (space M - U)) =
haftmann@69260
   228
        (INF U\<in>{U. space M - B \<subseteq> U \<and> open U}. emeasure M U)"
haftmann@69661
   229
      apply (rule arg_cong [of _ _ Inf])
haftmann@69661
   230
      using sU
haftmann@69661
   231
      apply (auto simp add: image_iff)
haftmann@69661
   232
      apply (rule exI [of _ "UNIV - y" for y])
haftmann@69661
   233
      apply safe
haftmann@69661
   234
        apply (auto simp add: double_diff)
haftmann@69661
   235
      done
immler@50087
   236
    finally have
haftmann@69260
   237
      "(INF U\<in>{U. space M - B \<subseteq> U \<and> open U}. emeasure M U) \<le> emeasure M (space M - B)" .
immler@50087
   238
    moreover have
haftmann@69260
   239
      "(INF U\<in>{U. space M - B \<subseteq> U \<and> open U}. emeasure M U) \<ge> emeasure M (space M - B)"
immler@50087
   240
      by (auto simp: sb sU intro!: INF_greatest emeasure_mono)
hoelzl@50125
   241
    ultimately show ?case by (auto intro!: antisym simp: sets_eq_imp_space_eq[OF sb])
hoelzl@50125
   242
hoelzl@50125
   243
    case 1
hoelzl@50125
   244
    have "M (space M - B) = M (space M) - emeasure M B" by (auto simp: emeasure_compl)
haftmann@69260
   245
    also have "\<dots> = (SUP U\<in> {U. B \<subseteq> U \<and> open U}. M (space M) -  M U)"
hoelzl@62975
   246
      unfolding outer by (subst ennreal_INF_const_minus) auto
haftmann@69260
   247
    also have "\<dots> = (SUP U\<in>{U. B \<subseteq> U \<and> open U}. M (space M - U))"
haftmann@69661
   248
      by (auto simp add: emeasure_compl sb compact_imp_closed)
haftmann@69260
   249
    also have "\<dots> = (SUP K\<in>{K. K \<subseteq> space M - B \<and> closed K}. emeasure M K)"
haftmann@62343
   250
      unfolding SUP_image [of _ "\<lambda>u. space M - u" _, symmetric, unfolded comp_def]
haftmann@69661
   251
      apply (rule arg_cong [of _ _ Sup])
haftmann@69661
   252
      using sU apply (auto intro!: imageI)
haftmann@69661
   253
      done
haftmann@69260
   254
    also have "\<dots> = (SUP K\<in>{K. K \<subseteq> space M - B \<and> compact K}. emeasure M K)"
hoelzl@50125
   255
    proof (safe intro!: antisym SUP_least)
hoelzl@50125
   256
      fix K assume "closed K" "K \<subseteq> space M - B"
wenzelm@61808
   257
      from closed_in_D[OF \<open>closed K\<close>]
haftmann@69260
   258
      have K_inner: "emeasure M K = (SUP K\<in>{Ka. Ka \<subseteq> K \<and> compact Ka}. emeasure M K)" by simp
haftmann@69260
   259
      show "emeasure M K \<le> (SUP K\<in>{K. K \<subseteq> space M - B \<and> compact K}. emeasure M K)"
wenzelm@61808
   260
        unfolding K_inner using \<open>K \<subseteq> space M - B\<close>
hoelzl@50125
   261
        by (auto intro!: SUP_upper SUP_least)
hoelzl@50125
   262
    qed (fastforce intro!: SUP_least SUP_upper simp: compact_imp_closed)
hoelzl@50125
   263
    finally show ?case by (auto intro!: antisym simp: sets_eq_imp_space_eq[OF sb])
immler@50087
   264
  next
hoelzl@50125
   265
    case (union D)
hoelzl@50125
   266
    then have "range D \<subseteq> sets M" by (auto simp: sb borel_eq_closed)
hoelzl@50125
   267
    with union have M[symmetric]: "(\<Sum>i. M (D i)) = M (\<Union>i. D i)" by (intro suminf_emeasure)
wenzelm@61969
   268
    also have "(\<lambda>n. \<Sum>i<n. M (D i)) \<longlonglongrightarrow> (\<Sum>i. M (D i))"
hoelzl@62975
   269
      by (intro summable_LIMSEQ) auto
wenzelm@61969
   270
    finally have measure_LIMSEQ: "(\<lambda>n. \<Sum>i<n. measure M (D i)) \<longlonglongrightarrow> measure M (\<Union>i. D i)"
nipkow@64267
   271
      by (simp add: emeasure_eq_measure measure_nonneg sum_nonneg)
wenzelm@61808
   272
    have "(\<Union>i. D i) \<in> sets M" using \<open>range D \<subseteq> sets M\<close> by auto
lp15@61609
   273
hoelzl@50125
   274
    case 1
hoelzl@50125
   275
    show ?case
immler@50087
   276
    proof (rule approx_inner)
immler@50087
   277
      fix e::real assume "e > 0"
immler@50087
   278
      with measure_LIMSEQ
hoelzl@56193
   279
      have "\<exists>no. \<forall>n\<ge>no. \<bar>(\<Sum>i<n. measure M (D i)) -measure M (\<Union>x. D x)\<bar> < e/2"
lp15@60017
   280
        by (auto simp: lim_sequentially dist_real_def simp del: less_divide_eq_numeral1)
hoelzl@56193
   281
      hence "\<exists>n0. \<bar>(\<Sum>i<n0. measure M (D i)) - measure M (\<Union>x. D x)\<bar> < e/2" by auto
hoelzl@56193
   282
      then obtain n0 where n0: "\<bar>(\<Sum>i<n0. measure M (D i)) - measure M (\<Union>i. D i)\<bar> < e/2"
immler@50087
   283
        unfolding choice_iff by blast
hoelzl@62975
   284
      have "ennreal (\<Sum>i<n0. measure M (D i)) = (\<Sum>i<n0. M (D i))"
nipkow@64267
   285
        by (auto simp add: emeasure_eq_measure sum_nonneg measure_nonneg)
nipkow@64267
   286
      also have "\<dots> \<le> (\<Sum>i. M (D i))" by (rule sum_le_suminf) auto
immler@50087
   287
      also have "\<dots> = M (\<Union>i. D i)" by (simp add: M)
immler@50087
   288
      also have "\<dots> = measure M (\<Union>i. D i)" by (simp add: emeasure_eq_measure)
hoelzl@56193
   289
      finally have n0: "measure M (\<Union>i. D i) - (\<Sum>i<n0. measure M (D i)) < e/2"
nipkow@64267
   290
        using n0 by (auto simp: measure_nonneg sum_nonneg)
immler@50087
   291
      have "\<forall>i. \<exists>K. K \<subseteq> D i \<and> compact K \<and> emeasure M (D i) \<le> emeasure M K + e/(2*Suc n0)"
immler@50087
   292
      proof
immler@50087
   293
        fix i
wenzelm@61808
   294
        from \<open>0 < e\<close> have "0 < e/(2*Suc n0)" by simp
haftmann@69260
   295
        have "emeasure M (D i) = (SUP K\<in>{K. K \<subseteq> (D i) \<and> compact K}. emeasure M K)"
hoelzl@50125
   296
          using union by blast
hoelzl@62975
   297
        from SUP_approx_ennreal[OF \<open>0 < e/(2*Suc n0)\<close> _ this]
immler@50087
   298
        show "\<exists>K. K \<subseteq> D i \<and> compact K \<and> emeasure M (D i) \<le> emeasure M K + e/(2*Suc n0)"
hoelzl@62975
   299
          by (auto simp: emeasure_eq_measure intro: less_imp_le compact_empty)
immler@50087
   300
      qed
immler@50087
   301
      then obtain K where K: "\<And>i. K i \<subseteq> D i" "\<And>i. compact (K i)"
immler@50087
   302
        "\<And>i. emeasure M (D i) \<le> emeasure M (K i) + e/(2*Suc n0)"
immler@50087
   303
        unfolding choice_iff by blast
hoelzl@56193
   304
      let ?K = "\<Union>i\<in>{..<n0}. K i"
wenzelm@61808
   305
      have "disjoint_family_on K {..<n0}" using K \<open>disjoint_family D\<close>
immler@50087
   306
        unfolding disjoint_family_on_def by blast
hoelzl@56193
   307
      hence mK: "measure M ?K = (\<Sum>i<n0. measure M (K i))" using K
immler@50087
   308
        by (intro finite_measure_finite_Union) (auto simp: sb compact_imp_closed)
hoelzl@56193
   309
      have "measure M (\<Union>i. D i) < (\<Sum>i<n0. measure M (D i)) + e/2" using n0 by simp
hoelzl@56193
   310
      also have "(\<Sum>i<n0. measure M (D i)) \<le> (\<Sum>i<n0. measure M (K i) + e/(2*Suc n0))"
hoelzl@62975
   311
        using K \<open>0 < e\<close>
nipkow@68403
   312
        by (auto intro: sum_mono simp: emeasure_eq_measure simp flip: ennreal_plus)
hoelzl@56193
   313
      also have "\<dots> = (\<Sum>i<n0. measure M (K i)) + (\<Sum>i<n0. e/(2*Suc n0))"
nipkow@64267
   314
        by (simp add: sum.distrib)
wenzelm@61808
   315
      also have "\<dots> \<le> (\<Sum>i<n0. measure M (K i)) +  e / 2" using \<open>0 < e\<close>
lp15@61609
   316
        by (auto simp: field_simps intro!: mult_left_mono)
immler@50087
   317
      finally
hoelzl@56193
   318
      have "measure M (\<Union>i. D i) < (\<Sum>i<n0. measure M (K i)) + e / 2 + e / 2"
immler@50087
   319
        by auto
hoelzl@62975
   320
      hence "M (\<Union>i. D i) < M ?K + e"
nipkow@68403
   321
        using \<open>0<e\<close> by (auto simp: mK emeasure_eq_measure sum_nonneg ennreal_less_iff simp flip: ennreal_plus)
immler@50087
   322
      moreover
immler@50087
   323
      have "?K \<subseteq> (\<Union>i. D i)" using K by auto
immler@50087
   324
      moreover
immler@50087
   325
      have "compact ?K" using K by auto
immler@50087
   326
      ultimately
hoelzl@62975
   327
      have "?K\<subseteq>(\<Union>i. D i) \<and> compact ?K \<and> emeasure M (\<Union>i. D i) \<le> emeasure M ?K + ennreal e" by simp
hoelzl@62975
   328
      thus "\<exists>K\<subseteq>\<Union>i. D i. compact K \<and> emeasure M (\<Union>i. D i) \<le> emeasure M K + ennreal e" ..
hoelzl@50125
   329
    qed fact
hoelzl@50125
   330
    case 2
hoelzl@50125
   331
    show ?case
wenzelm@61808
   332
    proof (rule approx_outer[OF \<open>(\<Union>i. D i) \<in> sets M\<close>])
immler@50087
   333
      fix e::real assume "e > 0"
immler@50087
   334
      have "\<forall>i::nat. \<exists>U. D i \<subseteq> U \<and> open U \<and> e/(2 powr Suc i) > emeasure M U - emeasure M (D i)"
immler@50087
   335
      proof
immler@50087
   336
        fix i::nat
wenzelm@61808
   337
        from \<open>0 < e\<close> have "0 < e/(2 powr Suc i)" by simp
haftmann@69260
   338
        have "emeasure M (D i) = (INF U\<in>{U. (D i) \<subseteq> U \<and> open U}. emeasure M U)"
hoelzl@50125
   339
          using union by blast
hoelzl@62975
   340
        from INF_approx_ennreal[OF \<open>0 < e/(2 powr Suc i)\<close> this]
immler@50087
   341
        show "\<exists>U. D i \<subseteq> U \<and> open U \<and> e/(2 powr Suc i) > emeasure M U - emeasure M (D i)"
hoelzl@62975
   342
          using \<open>0<e\<close>
nipkow@68046
   343
          by (auto simp: emeasure_eq_measure sum_nonneg ennreal_less_iff ennreal_minus
hoelzl@62975
   344
                         finite_measure_mono sb
nipkow@68403
   345
                   simp flip: ennreal_plus)
immler@50087
   346
      qed
immler@50087
   347
      then obtain U where U: "\<And>i. D i \<subseteq> U i" "\<And>i. open (U i)"
immler@50087
   348
        "\<And>i. e/(2 powr Suc i) > emeasure M (U i) - emeasure M (D i)"
immler@50087
   349
        unfolding choice_iff by blast
immler@50087
   350
      let ?U = "\<Union>i. U i"
hoelzl@62975
   351
      have "ennreal (measure M ?U - measure M (\<Union>i. D i)) = M ?U - M (\<Union>i. D i)"
hoelzl@62975
   352
        using U(1,2)
hoelzl@62975
   353
        by (subst ennreal_minus[symmetric])
hoelzl@62975
   354
           (auto intro!: finite_measure_mono simp: sb measure_nonneg emeasure_eq_measure)
hoelzl@62975
   355
      also have "\<dots> = M (?U - (\<Union>i. D i))" using U  \<open>(\<Union>i. D i) \<in> sets M\<close>
immler@50087
   356
        by (subst emeasure_Diff) (auto simp: sb)
wenzelm@61808
   357
      also have "\<dots> \<le> M (\<Union>i. U i - D i)" using U  \<open>range D \<subseteq> sets M\<close>
immler@50244
   358
        by (intro emeasure_mono) (auto simp: sb intro!: sets.countable_nat_UN sets.Diff)
wenzelm@61808
   359
      also have "\<dots> \<le> (\<Sum>i. M (U i - D i))" using U  \<open>range D \<subseteq> sets M\<close>
immler@50244
   360
        by (intro emeasure_subadditive_countably) (auto intro!: sets.Diff simp: sb)
hoelzl@62975
   361
      also have "\<dots> \<le> (\<Sum>i. ennreal e/(2 powr Suc i))" using U \<open>range D \<subseteq> sets M\<close>
hoelzl@62975
   362
        using \<open>0<e\<close>
hoelzl@62975
   363
        by (intro suminf_le, subst emeasure_Diff)
hoelzl@62975
   364
           (auto simp: emeasure_Diff emeasure_eq_measure sb measure_nonneg ennreal_minus
hoelzl@62975
   365
                       finite_measure_mono divide_ennreal ennreal_less_iff
hoelzl@62975
   366
                 intro: less_imp_le)
hoelzl@62975
   367
      also have "\<dots> \<le> (\<Sum>n. ennreal (e * (1 / 2) ^ Suc n))"
hoelzl@62975
   368
        using \<open>0<e\<close>
hoelzl@62975
   369
        by (simp add: powr_minus powr_realpow field_simps divide_ennreal del: of_nat_Suc)
hoelzl@62975
   370
      also have "\<dots> = ennreal e * (\<Sum>n. ennreal ((1 / 2) ^  Suc n))"
hoelzl@62975
   371
        unfolding ennreal_power[symmetric]
hoelzl@62975
   372
        using \<open>0 < e\<close>
hoelzl@62975
   373
        by (simp add: ac_simps ennreal_mult' divide_ennreal[symmetric] divide_ennreal_def
hoelzl@62975
   374
                      ennreal_power[symmetric])
hoelzl@62975
   375
      also have "\<dots> = ennreal e"
hoelzl@62975
   376
        by (subst suminf_ennreal_eq[OF zero_le_power power_half_series]) auto
hoelzl@62975
   377
      finally have "emeasure M ?U \<le> emeasure M (\<Union>i. D i) + ennreal e"
nipkow@68403
   378
        using \<open>0<e\<close> by (simp add: emeasure_eq_measure flip: ennreal_plus)
immler@50087
   379
      moreover
immler@50087
   380
      have "(\<Union>i. D i) \<subseteq> ?U" using U by auto
immler@50087
   381
      moreover
immler@50087
   382
      have "open ?U" using U by auto
immler@50087
   383
      ultimately
hoelzl@62975
   384
      have "(\<Union>i. D i) \<subseteq> ?U \<and> open ?U \<and> emeasure M ?U \<le> emeasure M (\<Union>i. D i) + ennreal e" by simp
hoelzl@62975
   385
      thus "\<exists>B. (\<Union>i. D i) \<subseteq> B \<and> open B \<and> emeasure M B \<le> emeasure M (\<Union>i. D i) + ennreal e" ..
immler@50087
   386
    qed
immler@50087
   387
  qed
immler@50087
   388
qed
immler@50087
   389
immler@50087
   390
end
immler@50087
   391