src/HOL/Probability/Information.thy
author hoelzl
Wed Oct 10 12:12:36 2012 +0200 (2012-10-10)
changeset 49803 2f076e377703
parent 49802 dd8dffaf84b9
child 49825 bb5db3d1d6dd
permissions -rw-r--r--
add finite entropy
hoelzl@42067
     1
(*  Title:      HOL/Probability/Information.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
    Author:     Armin Heller, TU München
hoelzl@42067
     4
*)
hoelzl@42067
     5
hoelzl@42067
     6
header {*Information theory*}
hoelzl@42067
     7
hoelzl@36080
     8
theory Information
wenzelm@41413
     9
imports
hoelzl@43340
    10
  Independent_Family
hoelzl@43556
    11
  Radon_Nikodym
wenzelm@41413
    12
  "~~/src/HOL/Library/Convex"
hoelzl@36080
    13
begin
hoelzl@36080
    14
hoelzl@39097
    15
lemma log_le: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> x \<le> y \<Longrightarrow> log a x \<le> log a y"
hoelzl@39097
    16
  by (subst log_le_cancel_iff) auto
hoelzl@39097
    17
hoelzl@39097
    18
lemma log_less: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> x < y \<Longrightarrow> log a x < log a y"
hoelzl@39097
    19
  by (subst log_less_cancel_iff) auto
hoelzl@39097
    20
hoelzl@39097
    21
lemma setsum_cartesian_product':
hoelzl@39097
    22
  "(\<Sum>x\<in>A \<times> B. f x) = (\<Sum>x\<in>A. setsum (\<lambda>y. f (x, y)) B)"
hoelzl@39097
    23
  unfolding setsum_cartesian_product by simp
hoelzl@39097
    24
hoelzl@39097
    25
lemma split_pairs:
hoelzl@40859
    26
  "((A, B) = X) \<longleftrightarrow> (fst X = A \<and> snd X = B)" and
hoelzl@40859
    27
  "(X = (A, B)) \<longleftrightarrow> (fst X = A \<and> snd X = B)" by auto
hoelzl@38656
    28
hoelzl@38656
    29
section "Information theory"
hoelzl@38656
    30
hoelzl@40859
    31
locale information_space = prob_space +
hoelzl@38656
    32
  fixes b :: real assumes b_gt_1: "1 < b"
hoelzl@38656
    33
hoelzl@40859
    34
context information_space
hoelzl@38656
    35
begin
hoelzl@38656
    36
hoelzl@40859
    37
text {* Introduce some simplification rules for logarithm of base @{term b}. *}
hoelzl@40859
    38
hoelzl@40859
    39
lemma log_neg_const:
hoelzl@40859
    40
  assumes "x \<le> 0"
hoelzl@40859
    41
  shows "log b x = log b 0"
hoelzl@36624
    42
proof -
hoelzl@40859
    43
  { fix u :: real
hoelzl@40859
    44
    have "x \<le> 0" by fact
hoelzl@40859
    45
    also have "0 < exp u"
hoelzl@40859
    46
      using exp_gt_zero .
hoelzl@40859
    47
    finally have "exp u \<noteq> x"
hoelzl@40859
    48
      by auto }
hoelzl@40859
    49
  then show "log b x = log b 0"
hoelzl@40859
    50
    by (simp add: log_def ln_def)
hoelzl@38656
    51
qed
hoelzl@38656
    52
hoelzl@40859
    53
lemma log_mult_eq:
hoelzl@40859
    54
  "log b (A * B) = (if 0 < A * B then log b \<bar>A\<bar> + log b \<bar>B\<bar> else log b 0)"
hoelzl@40859
    55
  using log_mult[of b "\<bar>A\<bar>" "\<bar>B\<bar>"] b_gt_1 log_neg_const[of "A * B"]
hoelzl@40859
    56
  by (auto simp: zero_less_mult_iff mult_le_0_iff)
hoelzl@38656
    57
hoelzl@40859
    58
lemma log_inverse_eq:
hoelzl@40859
    59
  "log b (inverse B) = (if 0 < B then - log b B else log b 0)"
hoelzl@40859
    60
  using log_inverse[of b B] log_neg_const[of "inverse B"] b_gt_1 by simp
hoelzl@36080
    61
hoelzl@40859
    62
lemma log_divide_eq:
hoelzl@40859
    63
  "log b (A / B) = (if 0 < A * B then log b \<bar>A\<bar> - log b \<bar>B\<bar> else log b 0)"
hoelzl@40859
    64
  unfolding divide_inverse log_mult_eq log_inverse_eq abs_inverse
hoelzl@40859
    65
  by (auto simp: zero_less_mult_iff mult_le_0_iff)
hoelzl@38656
    66
hoelzl@40859
    67
lemmas log_simps = log_mult_eq log_inverse_eq log_divide_eq
hoelzl@38656
    68
hoelzl@38656
    69
end
hoelzl@38656
    70
hoelzl@39097
    71
subsection "Kullback$-$Leibler divergence"
hoelzl@36080
    72
hoelzl@39097
    73
text {* The Kullback$-$Leibler divergence is also known as relative entropy or
hoelzl@39097
    74
Kullback$-$Leibler distance. *}
hoelzl@39097
    75
hoelzl@39097
    76
definition
hoelzl@47694
    77
  "entropy_density b M N = log b \<circ> real \<circ> RN_deriv M N"
hoelzl@43340
    78
hoelzl@43340
    79
definition
hoelzl@47694
    80
  "KL_divergence b M N = integral\<^isup>L N (entropy_density b M N)"
hoelzl@43340
    81
hoelzl@43340
    82
lemma (in information_space) measurable_entropy_density:
hoelzl@47694
    83
  assumes ac: "absolutely_continuous M N" "sets N = events"
hoelzl@47694
    84
  shows "entropy_density b M N \<in> borel_measurable M"
hoelzl@43340
    85
proof -
hoelzl@47694
    86
  from borel_measurable_RN_deriv[OF ac] b_gt_1 show ?thesis
hoelzl@43340
    87
    unfolding entropy_density_def
hoelzl@43340
    88
    by (intro measurable_comp) auto
hoelzl@43340
    89
qed
hoelzl@43340
    90
hoelzl@47694
    91
lemma (in sigma_finite_measure) KL_density:
hoelzl@47694
    92
  fixes f :: "'a \<Rightarrow> real"
hoelzl@47694
    93
  assumes "1 < b"
hoelzl@47694
    94
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
    95
  shows "KL_divergence b M (density M f) = (\<integral>x. f x * log b (f x) \<partial>M)"
hoelzl@47694
    96
  unfolding KL_divergence_def
hoelzl@47694
    97
proof (subst integral_density)
hoelzl@47694
    98
  show "entropy_density b M (density M (\<lambda>x. ereal (f x))) \<in> borel_measurable M"
hoelzl@49776
    99
    using f
hoelzl@47694
   100
    by (auto simp: comp_def entropy_density_def intro!: borel_measurable_log borel_measurable_RN_deriv_density)
hoelzl@47694
   101
  have "density M (RN_deriv M (density M f)) = density M f"
hoelzl@47694
   102
    using f by (intro density_RN_deriv_density) auto
hoelzl@47694
   103
  then have eq: "AE x in M. RN_deriv M (density M f) x = f x"
hoelzl@47694
   104
    using f
hoelzl@47694
   105
    by (intro density_unique)
hoelzl@47694
   106
       (auto intro!: borel_measurable_log borel_measurable_RN_deriv_density simp: RN_deriv_density_nonneg)
hoelzl@47694
   107
  show "(\<integral>x. f x * entropy_density b M (density M (\<lambda>x. ereal (f x))) x \<partial>M) = (\<integral>x. f x * log b (f x) \<partial>M)"
hoelzl@47694
   108
    apply (intro integral_cong_AE)
hoelzl@47694
   109
    using eq
hoelzl@47694
   110
    apply eventually_elim
hoelzl@47694
   111
    apply (auto simp: entropy_density_def)
hoelzl@47694
   112
    done
hoelzl@47694
   113
qed fact+
hoelzl@43340
   114
hoelzl@47694
   115
lemma (in sigma_finite_measure) KL_density_density:
hoelzl@47694
   116
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@47694
   117
  assumes "1 < b"
hoelzl@47694
   118
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
   119
  assumes g: "g \<in> borel_measurable M" "AE x in M. 0 \<le> g x"
hoelzl@47694
   120
  assumes ac: "AE x in M. f x = 0 \<longrightarrow> g x = 0"
hoelzl@47694
   121
  shows "KL_divergence b (density M f) (density M g) = (\<integral>x. g x * log b (g x / f x) \<partial>M)"
hoelzl@47694
   122
proof -
hoelzl@47694
   123
  interpret Mf: sigma_finite_measure "density M f"
hoelzl@47694
   124
    using f by (subst sigma_finite_iff_density_finite) auto
hoelzl@47694
   125
  have "KL_divergence b (density M f) (density M g) =
hoelzl@47694
   126
    KL_divergence b (density M f) (density (density M f) (\<lambda>x. g x / f x))"
hoelzl@47694
   127
    using f g ac by (subst density_density_divide) simp_all
hoelzl@47694
   128
  also have "\<dots> = (\<integral>x. (g x / f x) * log b (g x / f x) \<partial>density M f)"
hoelzl@47694
   129
    using f g `1 < b` by (intro Mf.KL_density) (auto simp: AE_density divide_nonneg_nonneg)
hoelzl@47694
   130
  also have "\<dots> = (\<integral>x. g x * log b (g x / f x) \<partial>M)"
hoelzl@47694
   131
    using ac f g `1 < b` by (subst integral_density) (auto intro!: integral_cong_AE)
hoelzl@47694
   132
  finally show ?thesis .
hoelzl@47694
   133
qed
hoelzl@43340
   134
hoelzl@47694
   135
lemma (in information_space) KL_gt_0:
hoelzl@47694
   136
  fixes D :: "'a \<Rightarrow> real"
hoelzl@47694
   137
  assumes "prob_space (density M D)"
hoelzl@47694
   138
  assumes D: "D \<in> borel_measurable M" "AE x in M. 0 \<le> D x"
hoelzl@47694
   139
  assumes int: "integrable M (\<lambda>x. D x * log b (D x))"
hoelzl@47694
   140
  assumes A: "density M D \<noteq> M"
hoelzl@47694
   141
  shows "0 < KL_divergence b M (density M D)"
hoelzl@47694
   142
proof -
hoelzl@47694
   143
  interpret N: prob_space "density M D" by fact
hoelzl@43340
   144
hoelzl@47694
   145
  obtain A where "A \<in> sets M" "emeasure (density M D) A \<noteq> emeasure M A"
hoelzl@47694
   146
    using measure_eqI[of "density M D" M] `density M D \<noteq> M` by auto
hoelzl@47694
   147
hoelzl@47694
   148
  let ?D_set = "{x\<in>space M. D x \<noteq> 0}"
hoelzl@47694
   149
  have [simp, intro]: "?D_set \<in> sets M"
hoelzl@47694
   150
    using D by auto
hoelzl@43340
   151
hoelzl@43920
   152
  have D_neg: "(\<integral>\<^isup>+ x. ereal (- D x) \<partial>M) = 0"
hoelzl@43340
   153
    using D by (subst positive_integral_0_iff_AE) auto
hoelzl@43340
   154
hoelzl@47694
   155
  have "(\<integral>\<^isup>+ x. ereal (D x) \<partial>M) = emeasure (density M D) (space M)"
hoelzl@47694
   156
    using D by (simp add: emeasure_density cong: positive_integral_cong)
hoelzl@43920
   157
  then have D_pos: "(\<integral>\<^isup>+ x. ereal (D x) \<partial>M) = 1"
hoelzl@47694
   158
    using N.emeasure_space_1 by simp
hoelzl@43340
   159
hoelzl@47694
   160
  have "integrable M D" "integral\<^isup>L M D = 1"
hoelzl@47694
   161
    using D D_pos D_neg unfolding integrable_def lebesgue_integral_def by simp_all
hoelzl@43340
   162
hoelzl@47694
   163
  have "0 \<le> 1 - measure M ?D_set"
hoelzl@43340
   164
    using prob_le_1 by (auto simp: field_simps)
hoelzl@43340
   165
  also have "\<dots> = (\<integral> x. D x - indicator ?D_set x \<partial>M)"
hoelzl@43340
   166
    using `integrable M D` `integral\<^isup>L M D = 1`
hoelzl@47694
   167
    by (simp add: emeasure_eq_measure)
hoelzl@47694
   168
  also have "\<dots> < (\<integral> x. D x * (ln b * log b (D x)) \<partial>M)"
hoelzl@43340
   169
  proof (rule integral_less_AE)
hoelzl@43340
   170
    show "integrable M (\<lambda>x. D x - indicator ?D_set x)"
hoelzl@43340
   171
      using `integrable M D`
hoelzl@43340
   172
      by (intro integral_diff integral_indicator) auto
hoelzl@43340
   173
  next
hoelzl@47694
   174
    from integral_cmult(1)[OF int, of "ln b"]
hoelzl@47694
   175
    show "integrable M (\<lambda>x. D x * (ln b * log b (D x)))" 
hoelzl@47694
   176
      by (simp add: ac_simps)
hoelzl@43340
   177
  next
hoelzl@47694
   178
    show "emeasure M {x\<in>space M. D x \<noteq> 1 \<and> D x \<noteq> 0} \<noteq> 0"
hoelzl@43340
   179
    proof
hoelzl@47694
   180
      assume eq_0: "emeasure M {x\<in>space M. D x \<noteq> 1 \<and> D x \<noteq> 0} = 0"
hoelzl@47694
   181
      then have disj: "AE x in M. D x = 1 \<or> D x = 0"
hoelzl@43340
   182
        using D(1) by (auto intro!: AE_I[OF subset_refl] sets_Collect)
hoelzl@43340
   183
hoelzl@47694
   184
      have "emeasure M {x\<in>space M. D x = 1} = (\<integral>\<^isup>+ x. indicator {x\<in>space M. D x = 1} x \<partial>M)"
hoelzl@43340
   185
        using D(1) by auto
hoelzl@47694
   186
      also have "\<dots> = (\<integral>\<^isup>+ x. ereal (D x) \<partial>M)"
hoelzl@43920
   187
        using disj by (auto intro!: positive_integral_cong_AE simp: indicator_def one_ereal_def)
hoelzl@47694
   188
      finally have "AE x in M. D x = 1"
hoelzl@47694
   189
        using D D_pos by (intro AE_I_eq_1) auto
hoelzl@43920
   190
      then have "(\<integral>\<^isup>+x. indicator A x\<partial>M) = (\<integral>\<^isup>+x. ereal (D x) * indicator A x\<partial>M)"
hoelzl@43920
   191
        by (intro positive_integral_cong_AE) (auto simp: one_ereal_def[symmetric])
hoelzl@47694
   192
      also have "\<dots> = density M D A"
hoelzl@47694
   193
        using `A \<in> sets M` D by (simp add: emeasure_density)
hoelzl@47694
   194
      finally show False using `A \<in> sets M` `emeasure (density M D) A \<noteq> emeasure M A` by simp
hoelzl@43340
   195
    qed
hoelzl@43340
   196
    show "{x\<in>space M. D x \<noteq> 1 \<and> D x \<noteq> 0} \<in> sets M"
hoelzl@47694
   197
      using D(1) by (auto intro: sets_Collect_conj)
hoelzl@43340
   198
hoelzl@47694
   199
    show "AE t in M. t \<in> {x\<in>space M. D x \<noteq> 1 \<and> D x \<noteq> 0} \<longrightarrow>
hoelzl@47694
   200
      D t - indicator ?D_set t \<noteq> D t * (ln b * log b (D t))"
hoelzl@43340
   201
      using D(2)
hoelzl@47694
   202
    proof (eventually_elim, safe)
hoelzl@47694
   203
      fix t assume Dt: "t \<in> space M" "D t \<noteq> 1" "D t \<noteq> 0" "0 \<le> D t"
hoelzl@47694
   204
        and eq: "D t - indicator ?D_set t = D t * (ln b * log b (D t))"
hoelzl@43340
   205
hoelzl@43340
   206
      have "D t - 1 = D t - indicator ?D_set t"
hoelzl@43340
   207
        using Dt by simp
hoelzl@43340
   208
      also note eq
hoelzl@47694
   209
      also have "D t * (ln b * log b (D t)) = - D t * ln (1 / D t)"
hoelzl@47694
   210
        using b_gt_1 `D t \<noteq> 0` `0 \<le> D t`
hoelzl@47694
   211
        by (simp add: log_def ln_div less_le)
hoelzl@43340
   212
      finally have "ln (1 / D t) = 1 / D t - 1"
hoelzl@43340
   213
        using `D t \<noteq> 0` by (auto simp: field_simps)
hoelzl@43340
   214
      from ln_eq_minus_one[OF _ this] `D t \<noteq> 0` `0 \<le> D t` `D t \<noteq> 1`
hoelzl@43340
   215
      show False by auto
hoelzl@43340
   216
    qed
hoelzl@43340
   217
hoelzl@47694
   218
    show "AE t in M. D t - indicator ?D_set t \<le> D t * (ln b * log b (D t))"
hoelzl@47694
   219
      using D(2) AE_space
hoelzl@47694
   220
    proof eventually_elim
hoelzl@47694
   221
      fix t assume "t \<in> space M" "0 \<le> D t"
hoelzl@47694
   222
      show "D t - indicator ?D_set t \<le> D t * (ln b * log b (D t))"
hoelzl@43340
   223
      proof cases
hoelzl@43340
   224
        assume asm: "D t \<noteq> 0"
hoelzl@43340
   225
        then have "0 < D t" using `0 \<le> D t` by auto
hoelzl@43340
   226
        then have "0 < 1 / D t" by auto
hoelzl@43340
   227
        have "D t - indicator ?D_set t \<le> - D t * (1 / D t - 1)"
hoelzl@43340
   228
          using asm `t \<in> space M` by (simp add: field_simps)
hoelzl@43340
   229
        also have "- D t * (1 / D t - 1) \<le> - D t * ln (1 / D t)"
hoelzl@43340
   230
          using ln_le_minus_one `0 < 1 / D t` by (intro mult_left_mono_neg) auto
hoelzl@47694
   231
        also have "\<dots> = D t * (ln b * log b (D t))"
hoelzl@47694
   232
          using `0 < D t` b_gt_1
hoelzl@47694
   233
          by (simp_all add: log_def ln_div)
hoelzl@43340
   234
        finally show ?thesis by simp
hoelzl@43340
   235
      qed simp
hoelzl@43340
   236
    qed
hoelzl@43340
   237
  qed
hoelzl@47694
   238
  also have "\<dots> = (\<integral> x. ln b * (D x * log b (D x)) \<partial>M)"
hoelzl@47694
   239
    by (simp add: ac_simps)
hoelzl@47694
   240
  also have "\<dots> = ln b * (\<integral> x. D x * log b (D x) \<partial>M)"
hoelzl@47694
   241
    using int by (rule integral_cmult)
hoelzl@47694
   242
  finally show ?thesis
hoelzl@47694
   243
    using b_gt_1 D by (subst KL_density) (auto simp: zero_less_mult_iff)
hoelzl@43340
   244
qed
hoelzl@43340
   245
hoelzl@47694
   246
lemma (in sigma_finite_measure) KL_same_eq_0: "KL_divergence b M M = 0"
hoelzl@43340
   247
proof -
hoelzl@47694
   248
  have "AE x in M. 1 = RN_deriv M M x"
hoelzl@43340
   249
  proof (rule RN_deriv_unique)
hoelzl@47694
   250
    show "(\<lambda>x. 1) \<in> borel_measurable M" "AE x in M. 0 \<le> (1 :: ereal)" by auto
hoelzl@47694
   251
    show "density M (\<lambda>x. 1) = M"
hoelzl@47694
   252
      apply (auto intro!: measure_eqI emeasure_density)
hoelzl@47694
   253
      apply (subst emeasure_density)
hoelzl@47694
   254
      apply auto
hoelzl@47694
   255
      done
hoelzl@43340
   256
  qed
hoelzl@47694
   257
  then have "AE x in M. log b (real (RN_deriv M M x)) = 0"
hoelzl@43340
   258
    by (elim AE_mp) simp
hoelzl@43340
   259
  from integral_cong_AE[OF this]
hoelzl@47694
   260
  have "integral\<^isup>L M (entropy_density b M M) = 0"
hoelzl@43340
   261
    by (simp add: entropy_density_def comp_def)
hoelzl@47694
   262
  then show "KL_divergence b M M = 0"
hoelzl@43340
   263
    unfolding KL_divergence_def
hoelzl@47694
   264
    by auto
hoelzl@43340
   265
qed
hoelzl@43340
   266
hoelzl@47694
   267
lemma (in information_space) KL_eq_0_iff_eq:
hoelzl@47694
   268
  fixes D :: "'a \<Rightarrow> real"
hoelzl@47694
   269
  assumes "prob_space (density M D)"
hoelzl@47694
   270
  assumes D: "D \<in> borel_measurable M" "AE x in M. 0 \<le> D x"
hoelzl@47694
   271
  assumes int: "integrable M (\<lambda>x. D x * log b (D x))"
hoelzl@47694
   272
  shows "KL_divergence b M (density M D) = 0 \<longleftrightarrow> density M D = M"
hoelzl@47694
   273
  using KL_same_eq_0[of b] KL_gt_0[OF assms]
hoelzl@47694
   274
  by (auto simp: less_le)
hoelzl@43340
   275
hoelzl@47694
   276
lemma (in information_space) KL_eq_0_iff_eq_ac:
hoelzl@47694
   277
  fixes D :: "'a \<Rightarrow> real"
hoelzl@47694
   278
  assumes "prob_space N"
hoelzl@47694
   279
  assumes ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@47694
   280
  assumes int: "integrable N (entropy_density b M N)"
hoelzl@47694
   281
  shows "KL_divergence b M N = 0 \<longleftrightarrow> N = M"
hoelzl@41833
   282
proof -
hoelzl@47694
   283
  interpret N: prob_space N by fact
hoelzl@47694
   284
  have "finite_measure N" by unfold_locales
hoelzl@47694
   285
  from real_RN_deriv[OF this ac] guess D . note D = this
hoelzl@47694
   286
  
hoelzl@47694
   287
  have "N = density M (RN_deriv M N)"
hoelzl@47694
   288
    using ac by (rule density_RN_deriv[symmetric])
hoelzl@47694
   289
  also have "\<dots> = density M D"
hoelzl@47694
   290
    using borel_measurable_RN_deriv[OF ac] D by (auto intro!: density_cong)
hoelzl@47694
   291
  finally have N: "N = density M D" .
hoelzl@41833
   292
hoelzl@47694
   293
  from absolutely_continuous_AE[OF ac(2,1) D(2)] D b_gt_1 ac measurable_entropy_density
hoelzl@47694
   294
  have "integrable N (\<lambda>x. log b (D x))"
hoelzl@47694
   295
    by (intro integrable_cong_AE[THEN iffD2, OF _ _ _ int])
hoelzl@47694
   296
       (auto simp: N entropy_density_def)
hoelzl@47694
   297
  with D b_gt_1 have "integrable M (\<lambda>x. D x * log b (D x))"
hoelzl@47694
   298
    by (subst integral_density(2)[symmetric]) (auto simp: N[symmetric] comp_def)
hoelzl@47694
   299
  with `prob_space N` D show ?thesis
hoelzl@47694
   300
    unfolding N
hoelzl@47694
   301
    by (intro KL_eq_0_iff_eq) auto
hoelzl@41833
   302
qed
hoelzl@41833
   303
hoelzl@47694
   304
lemma (in information_space) KL_nonneg:
hoelzl@47694
   305
  assumes "prob_space (density M D)"
hoelzl@47694
   306
  assumes D: "D \<in> borel_measurable M" "AE x in M. 0 \<le> D x"
hoelzl@47694
   307
  assumes int: "integrable M (\<lambda>x. D x * log b (D x))"
hoelzl@47694
   308
  shows "0 \<le> KL_divergence b M (density M D)"
hoelzl@47694
   309
  using KL_gt_0[OF assms] by (cases "density M D = M") (auto simp: KL_same_eq_0)
hoelzl@40859
   310
hoelzl@47694
   311
lemma (in sigma_finite_measure) KL_density_density_nonneg:
hoelzl@47694
   312
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@47694
   313
  assumes "1 < b"
hoelzl@47694
   314
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x" "prob_space (density M f)"
hoelzl@47694
   315
  assumes g: "g \<in> borel_measurable M" "AE x in M. 0 \<le> g x" "prob_space (density M g)"
hoelzl@47694
   316
  assumes ac: "AE x in M. f x = 0 \<longrightarrow> g x = 0"
hoelzl@47694
   317
  assumes int: "integrable M (\<lambda>x. g x * log b (g x / f x))"
hoelzl@47694
   318
  shows "0 \<le> KL_divergence b (density M f) (density M g)"
hoelzl@47694
   319
proof -
hoelzl@47694
   320
  interpret Mf: prob_space "density M f" by fact
hoelzl@47694
   321
  interpret Mf: information_space "density M f" b by default fact
hoelzl@47694
   322
  have eq: "density (density M f) (\<lambda>x. g x / f x) = density M g" (is "?DD = _")
hoelzl@47694
   323
    using f g ac by (subst density_density_divide) simp_all
hoelzl@36080
   324
hoelzl@47694
   325
  have "0 \<le> KL_divergence b (density M f) (density (density M f) (\<lambda>x. g x / f x))"
hoelzl@47694
   326
  proof (rule Mf.KL_nonneg)
hoelzl@47694
   327
    show "prob_space ?DD" unfolding eq by fact
hoelzl@47694
   328
    from f g show "(\<lambda>x. g x / f x) \<in> borel_measurable (density M f)"
hoelzl@47694
   329
      by auto
hoelzl@47694
   330
    show "AE x in density M f. 0 \<le> g x / f x"
hoelzl@47694
   331
      using f g by (auto simp: AE_density divide_nonneg_nonneg)
hoelzl@47694
   332
    show "integrable (density M f) (\<lambda>x. g x / f x * log b (g x / f x))"
hoelzl@47694
   333
      using `1 < b` f g ac
hoelzl@47694
   334
      by (subst integral_density)
hoelzl@47694
   335
         (auto intro!: integrable_cong_AE[THEN iffD2, OF _ _ _ int] measurable_If)
hoelzl@47694
   336
  qed
hoelzl@47694
   337
  also have "\<dots> = KL_divergence b (density M f) (density M g)"
hoelzl@47694
   338
    using f g ac by (subst density_density_divide) simp_all
hoelzl@47694
   339
  finally show ?thesis .
hoelzl@36080
   340
qed
hoelzl@36080
   341
hoelzl@49803
   342
subsection {* Finite Entropy *}
hoelzl@49803
   343
hoelzl@49803
   344
definition (in information_space) 
hoelzl@49803
   345
  "finite_entropy S X f \<longleftrightarrow> distributed M S X f \<and> integrable S (\<lambda>x. f x * log b (f x))"
hoelzl@49803
   346
hoelzl@49803
   347
lemma (in information_space) finite_entropy_simple_function:
hoelzl@49803
   348
  assumes X: "simple_function M X"
hoelzl@49803
   349
  shows "finite_entropy (count_space (X`space M)) X (\<lambda>a. measure M {x \<in> space M. X x = a})"
hoelzl@49803
   350
  unfolding finite_entropy_def
hoelzl@49803
   351
proof
hoelzl@49803
   352
  have [simp]: "finite (X ` space M)"
hoelzl@49803
   353
    using X by (auto simp: simple_function_def)
hoelzl@49803
   354
  then show "integrable (count_space (X ` space M))
hoelzl@49803
   355
     (\<lambda>x. prob {xa \<in> space M. X xa = x} * log b (prob {xa \<in> space M. X xa = x}))"
hoelzl@49803
   356
    by (rule integrable_count_space)
hoelzl@49803
   357
  have d: "distributed M (count_space (X ` space M)) X (\<lambda>x. ereal (if x \<in> X`space M then prob {xa \<in> space M. X xa = x} else 0))"
hoelzl@49803
   358
    by (rule distributed_simple_function_superset[OF X]) (auto intro!: arg_cong[where f=prob])
hoelzl@49803
   359
  show "distributed M (count_space (X ` space M)) X (\<lambda>x. ereal (prob {xa \<in> space M. X xa = x}))"
hoelzl@49803
   360
    by (rule distributed_cong_density[THEN iffD1, OF _ _ _ d]) auto
hoelzl@49803
   361
qed
hoelzl@49803
   362
hoelzl@49803
   363
lemma distributed_transform_AE:
hoelzl@49803
   364
  assumes T: "T \<in> measurable P Q" "absolutely_continuous Q (distr P Q T)"
hoelzl@49803
   365
  assumes g: "distributed M Q Y g"
hoelzl@49803
   366
  shows "AE x in P. 0 \<le> g (T x)"
hoelzl@49803
   367
  using g
hoelzl@49803
   368
  apply (subst AE_distr_iff[symmetric, OF T(1)])
hoelzl@49803
   369
  apply (simp add: distributed_borel_measurable)
hoelzl@49803
   370
  apply (rule absolutely_continuous_AE[OF _ T(2)])
hoelzl@49803
   371
  apply simp
hoelzl@49803
   372
  apply (simp add: distributed_AE)
hoelzl@49803
   373
  done
hoelzl@49803
   374
hoelzl@49803
   375
lemma ac_fst:
hoelzl@49803
   376
  assumes "sigma_finite_measure T"
hoelzl@49803
   377
  shows "absolutely_continuous S (distr (S \<Otimes>\<^isub>M T) S fst)"
hoelzl@49803
   378
proof -
hoelzl@49803
   379
  interpret sigma_finite_measure T by fact
hoelzl@49803
   380
  { fix A assume "A \<in> sets S" "emeasure S A = 0"
hoelzl@49803
   381
    moreover then have "fst -` A \<inter> space (S \<Otimes>\<^isub>M T) = A \<times> space T"
hoelzl@49803
   382
      by (auto simp: space_pair_measure dest!: sets_into_space)
hoelzl@49803
   383
    ultimately have "emeasure (S \<Otimes>\<^isub>M T) (fst -` A \<inter> space (S \<Otimes>\<^isub>M T)) = 0"
hoelzl@49803
   384
      by (simp add: emeasure_pair_measure_Times) }
hoelzl@49803
   385
  then show ?thesis
hoelzl@49803
   386
    unfolding absolutely_continuous_def
hoelzl@49803
   387
    apply (auto simp: null_sets_distr_iff)
hoelzl@49803
   388
    apply (auto simp: null_sets_def intro!: measurable_sets)
hoelzl@49803
   389
    done
hoelzl@49803
   390
qed
hoelzl@49803
   391
hoelzl@49803
   392
lemma ac_snd:
hoelzl@49803
   393
  assumes "sigma_finite_measure T"
hoelzl@49803
   394
  shows "absolutely_continuous T (distr (S \<Otimes>\<^isub>M T) T snd)"
hoelzl@49803
   395
proof -
hoelzl@49803
   396
  interpret sigma_finite_measure T by fact
hoelzl@49803
   397
  { fix A assume "A \<in> sets T" "emeasure T A = 0"
hoelzl@49803
   398
    moreover then have "snd -` A \<inter> space (S \<Otimes>\<^isub>M T) = space S \<times> A"
hoelzl@49803
   399
      by (auto simp: space_pair_measure dest!: sets_into_space)
hoelzl@49803
   400
    ultimately have "emeasure (S \<Otimes>\<^isub>M T) (snd -` A \<inter> space (S \<Otimes>\<^isub>M T)) = 0"
hoelzl@49803
   401
      by (simp add: emeasure_pair_measure_Times) }
hoelzl@49803
   402
  then show ?thesis
hoelzl@49803
   403
    unfolding absolutely_continuous_def
hoelzl@49803
   404
    apply (auto simp: null_sets_distr_iff)
hoelzl@49803
   405
    apply (auto simp: null_sets_def intro!: measurable_sets)
hoelzl@49803
   406
    done
hoelzl@49803
   407
qed
hoelzl@49803
   408
hoelzl@49803
   409
lemma distributed_integrable:
hoelzl@49803
   410
  "distributed M N X f \<Longrightarrow> g \<in> borel_measurable N \<Longrightarrow>
hoelzl@49803
   411
    integrable N (\<lambda>x. f x * g x) \<longleftrightarrow> integrable M (\<lambda>x. g (X x))"
hoelzl@49803
   412
  by (auto simp: distributed_real_measurable distributed_real_AE distributed_measurable
hoelzl@49803
   413
                    distributed_distr_eq_density[symmetric] integral_density[symmetric] integrable_distr_eq)
hoelzl@49803
   414
  
hoelzl@49803
   415
lemma distributed_transform_integrable:
hoelzl@49803
   416
  assumes Px: "distributed M N X Px"
hoelzl@49803
   417
  assumes "distributed M P Y Py"
hoelzl@49803
   418
  assumes Y: "Y = (\<lambda>x. T (X x))" and T: "T \<in> measurable N P" and f: "f \<in> borel_measurable P"
hoelzl@49803
   419
  shows "integrable P (\<lambda>x. Py x * f x) \<longleftrightarrow> integrable N (\<lambda>x. Px x * f (T x))"
hoelzl@49803
   420
proof -
hoelzl@49803
   421
  have "integrable P (\<lambda>x. Py x * f x) \<longleftrightarrow> integrable M (\<lambda>x. f (Y x))"
hoelzl@49803
   422
    by (rule distributed_integrable) fact+
hoelzl@49803
   423
  also have "\<dots> \<longleftrightarrow> integrable M (\<lambda>x. f (T (X x)))"
hoelzl@49803
   424
    using Y by simp
hoelzl@49803
   425
  also have "\<dots> \<longleftrightarrow> integrable N (\<lambda>x. Px x * f (T x))"
hoelzl@49803
   426
    using measurable_comp[OF T f] Px by (intro distributed_integrable[symmetric]) (auto simp: comp_def)
hoelzl@49803
   427
  finally show ?thesis .
hoelzl@49803
   428
qed
hoelzl@49803
   429
hoelzl@49803
   430
lemma integrable_cong_AE_imp: "integrable M g \<Longrightarrow> f \<in> borel_measurable M \<Longrightarrow> (AE x in M. g x = f x) \<Longrightarrow> integrable M f"
hoelzl@49803
   431
  using integrable_cong_AE by blast
hoelzl@49803
   432
hoelzl@49803
   433
lemma (in information_space) finite_entropy_integrable:
hoelzl@49803
   434
  "finite_entropy S X Px \<Longrightarrow> integrable S (\<lambda>x. Px x * log b (Px x))"
hoelzl@49803
   435
  unfolding finite_entropy_def by auto
hoelzl@49803
   436
hoelzl@49803
   437
lemma (in information_space) finite_entropy_distributed:
hoelzl@49803
   438
  "finite_entropy S X Px \<Longrightarrow> distributed M S X Px"
hoelzl@49803
   439
  unfolding finite_entropy_def by auto
hoelzl@49803
   440
hoelzl@49803
   441
lemma (in information_space) finite_entropy_integrable_transform:
hoelzl@49803
   442
  assumes Fx: "finite_entropy S X Px"
hoelzl@49803
   443
  assumes Fy: "distributed M T Y Py"
hoelzl@49803
   444
    and "X = (\<lambda>x. f (Y x))"
hoelzl@49803
   445
    and "f \<in> measurable T S"
hoelzl@49803
   446
  shows "integrable T (\<lambda>x. Py x * log b (Px (f x)))"
hoelzl@49803
   447
  using assms unfolding finite_entropy_def
hoelzl@49803
   448
  using distributed_transform_integrable[of M T Y Py S X Px f "\<lambda>x. log b (Px x)"]
hoelzl@49803
   449
  by (auto intro: distributed_real_measurable)
hoelzl@49803
   450
hoelzl@39097
   451
subsection {* Mutual Information *}
hoelzl@39097
   452
hoelzl@36080
   453
definition (in prob_space)
hoelzl@38656
   454
  "mutual_information b S T X Y =
hoelzl@47694
   455
    KL_divergence b (distr M S X \<Otimes>\<^isub>M distr M T Y) (distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)))"
hoelzl@36080
   456
hoelzl@47694
   457
lemma (in information_space) mutual_information_indep_vars:
hoelzl@43340
   458
  fixes S T X Y
hoelzl@47694
   459
  defines "P \<equiv> distr M S X \<Otimes>\<^isub>M distr M T Y"
hoelzl@47694
   460
  defines "Q \<equiv> distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@43340
   461
  shows "indep_var S X T Y \<longleftrightarrow>
hoelzl@43340
   462
    (random_variable S X \<and> random_variable T Y \<and>
hoelzl@47694
   463
      absolutely_continuous P Q \<and> integrable Q (entropy_density b P Q) \<and>
hoelzl@47694
   464
      mutual_information b S T X Y = 0)"
hoelzl@47694
   465
  unfolding indep_var_distribution_eq
hoelzl@43340
   466
proof safe
hoelzl@47694
   467
  assume rv: "random_variable S X" "random_variable T Y"
hoelzl@43340
   468
hoelzl@47694
   469
  interpret X: prob_space "distr M S X"
hoelzl@47694
   470
    by (rule prob_space_distr) fact
hoelzl@47694
   471
  interpret Y: prob_space "distr M T Y"
hoelzl@47694
   472
    by (rule prob_space_distr) fact
hoelzl@47694
   473
  interpret XY: pair_prob_space "distr M S X" "distr M T Y" by default
hoelzl@47694
   474
  interpret P: information_space P b unfolding P_def by default (rule b_gt_1)
hoelzl@43340
   475
hoelzl@47694
   476
  interpret Q: prob_space Q unfolding Q_def
hoelzl@47694
   477
    by (rule prob_space_distr) (simp add: comp_def measurable_pair_iff rv)
hoelzl@43340
   478
hoelzl@47694
   479
  { assume "distr M S X \<Otimes>\<^isub>M distr M T Y = distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@47694
   480
    then have [simp]: "Q = P"  unfolding Q_def P_def by simp
hoelzl@43340
   481
hoelzl@47694
   482
    show ac: "absolutely_continuous P Q" by (simp add: absolutely_continuous_def)
hoelzl@47694
   483
    then have ed: "entropy_density b P Q \<in> borel_measurable P"
hoelzl@47694
   484
      by (rule P.measurable_entropy_density) simp
hoelzl@43340
   485
hoelzl@47694
   486
    have "AE x in P. 1 = RN_deriv P Q x"
hoelzl@47694
   487
    proof (rule P.RN_deriv_unique)
hoelzl@47694
   488
      show "density P (\<lambda>x. 1) = Q"
hoelzl@47694
   489
        unfolding `Q = P` by (intro measure_eqI) (auto simp: emeasure_density)
hoelzl@47694
   490
    qed auto
hoelzl@47694
   491
    then have ae_0: "AE x in P. entropy_density b P Q x = 0"
hoelzl@47694
   492
      by eventually_elim (auto simp: entropy_density_def)
hoelzl@47694
   493
    then have "integrable P (entropy_density b P Q) \<longleftrightarrow> integrable Q (\<lambda>x. 0)"
hoelzl@47694
   494
      using ed unfolding `Q = P` by (intro integrable_cong_AE) auto
hoelzl@47694
   495
    then show "integrable Q (entropy_density b P Q)" by simp
hoelzl@43340
   496
hoelzl@47694
   497
    show "mutual_information b S T X Y = 0"
hoelzl@47694
   498
      unfolding mutual_information_def KL_divergence_def P_def[symmetric] Q_def[symmetric] `Q = P`
hoelzl@47694
   499
      using ae_0 by (simp cong: integral_cong_AE) }
hoelzl@43340
   500
hoelzl@47694
   501
  { assume ac: "absolutely_continuous P Q"
hoelzl@47694
   502
    assume int: "integrable Q (entropy_density b P Q)"
hoelzl@47694
   503
    assume I_eq_0: "mutual_information b S T X Y = 0"
hoelzl@43340
   504
hoelzl@47694
   505
    have eq: "Q = P"
hoelzl@47694
   506
    proof (rule P.KL_eq_0_iff_eq_ac[THEN iffD1])
hoelzl@47694
   507
      show "prob_space Q" by unfold_locales
hoelzl@47694
   508
      show "absolutely_continuous P Q" by fact
hoelzl@47694
   509
      show "integrable Q (entropy_density b P Q)" by fact
hoelzl@47694
   510
      show "sets Q = sets P" by (simp add: P_def Q_def sets_pair_measure)
hoelzl@47694
   511
      show "KL_divergence b P Q = 0"
hoelzl@47694
   512
        using I_eq_0 unfolding mutual_information_def by (simp add: P_def Q_def)
hoelzl@47694
   513
    qed
hoelzl@47694
   514
    then show "distr M S X \<Otimes>\<^isub>M distr M T Y = distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@47694
   515
      unfolding P_def Q_def .. }
hoelzl@43340
   516
qed
hoelzl@43340
   517
hoelzl@40859
   518
abbreviation (in information_space)
hoelzl@40859
   519
  mutual_information_Pow ("\<I>'(_ ; _')") where
hoelzl@47694
   520
  "\<I>(X ; Y) \<equiv> mutual_information b (count_space (X`space M)) (count_space (Y`space M)) X Y"
hoelzl@41689
   521
hoelzl@47694
   522
lemma (in information_space)
hoelzl@47694
   523
  fixes Pxy :: "'b \<times> 'c \<Rightarrow> real" and Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@49803
   524
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
hoelzl@49803
   525
  assumes Fx: "finite_entropy S X Px" and Fy: "finite_entropy T Y Py"
hoelzl@49803
   526
  assumes Fxy: "finite_entropy (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@49803
   527
  defines "f \<equiv> \<lambda>x. Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x)))"
hoelzl@49803
   528
  shows mutual_information_distr': "mutual_information b S T X Y = integral\<^isup>L (S \<Otimes>\<^isub>M T) f" (is "?M = ?R")
hoelzl@49803
   529
    and mutual_information_nonneg': "0 \<le> mutual_information b S T X Y"
hoelzl@49803
   530
proof -
hoelzl@49803
   531
  have Px: "distributed M S X Px"
hoelzl@49803
   532
    using Fx by (auto simp: finite_entropy_def)
hoelzl@49803
   533
  have Py: "distributed M T Y Py"
hoelzl@49803
   534
    using Fy by (auto simp: finite_entropy_def)
hoelzl@49803
   535
  have Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@49803
   536
    using Fxy by (auto simp: finite_entropy_def)
hoelzl@49803
   537
hoelzl@49803
   538
  have X: "random_variable S X"
hoelzl@49803
   539
    using Px by (auto simp: distributed_def finite_entropy_def)
hoelzl@49803
   540
  have Y: "random_variable T Y"
hoelzl@49803
   541
    using Py by (auto simp: distributed_def finite_entropy_def)
hoelzl@49803
   542
  interpret S: sigma_finite_measure S by fact
hoelzl@49803
   543
  interpret T: sigma_finite_measure T by fact
hoelzl@49803
   544
  interpret ST: pair_sigma_finite S T ..
hoelzl@49803
   545
  interpret X: prob_space "distr M S X" using X by (rule prob_space_distr)
hoelzl@49803
   546
  interpret Y: prob_space "distr M T Y" using Y by (rule prob_space_distr)
hoelzl@49803
   547
  interpret XY: pair_prob_space "distr M S X" "distr M T Y" ..
hoelzl@49803
   548
  let ?P = "S \<Otimes>\<^isub>M T"
hoelzl@49803
   549
  let ?D = "distr M ?P (\<lambda>x. (X x, Y x))"
hoelzl@49803
   550
hoelzl@49803
   551
  { fix A assume "A \<in> sets S"
hoelzl@49803
   552
    with X Y have "emeasure (distr M S X) A = emeasure ?D (A \<times> space T)"
hoelzl@49803
   553
      by (auto simp: emeasure_distr measurable_Pair measurable_space
hoelzl@49803
   554
               intro!: arg_cong[where f="emeasure M"]) }
hoelzl@49803
   555
  note marginal_eq1 = this
hoelzl@49803
   556
  { fix A assume "A \<in> sets T"
hoelzl@49803
   557
    with X Y have "emeasure (distr M T Y) A = emeasure ?D (space S \<times> A)"
hoelzl@49803
   558
      by (auto simp: emeasure_distr measurable_Pair measurable_space
hoelzl@49803
   559
               intro!: arg_cong[where f="emeasure M"]) }
hoelzl@49803
   560
  note marginal_eq2 = this
hoelzl@49803
   561
hoelzl@49803
   562
  have eq: "(\<lambda>x. ereal (Px (fst x) * Py (snd x))) = (\<lambda>(x, y). ereal (Px x) * ereal (Py y))"
hoelzl@49803
   563
    by auto
hoelzl@49803
   564
hoelzl@49803
   565
  have distr_eq: "distr M S X \<Otimes>\<^isub>M distr M T Y = density ?P (\<lambda>x. ereal (Px (fst x) * Py (snd x)))"
hoelzl@49803
   566
    unfolding Px(1)[THEN distributed_distr_eq_density] Py(1)[THEN distributed_distr_eq_density] eq
hoelzl@49803
   567
  proof (subst pair_measure_density)
hoelzl@49803
   568
    show "(\<lambda>x. ereal (Px x)) \<in> borel_measurable S" "(\<lambda>y. ereal (Py y)) \<in> borel_measurable T"
hoelzl@49803
   569
      "AE x in S. 0 \<le> ereal (Px x)" "AE y in T. 0 \<le> ereal (Py y)"
hoelzl@49803
   570
      using Px Py by (auto simp: distributed_def)
hoelzl@49803
   571
    show "sigma_finite_measure (density S Px)" unfolding Px(1)[THEN distributed_distr_eq_density, symmetric] ..
hoelzl@49803
   572
    show "sigma_finite_measure (density T Py)" unfolding Py(1)[THEN distributed_distr_eq_density, symmetric] ..
hoelzl@49803
   573
  qed (fact | simp)+
hoelzl@49803
   574
  
hoelzl@49803
   575
  have M: "?M = KL_divergence b (density ?P (\<lambda>x. ereal (Px (fst x) * Py (snd x)))) (density ?P (\<lambda>x. ereal (Pxy x)))"
hoelzl@49803
   576
    unfolding mutual_information_def distr_eq Pxy(1)[THEN distributed_distr_eq_density] ..
hoelzl@49803
   577
hoelzl@49803
   578
  from Px Py have f: "(\<lambda>x. Px (fst x) * Py (snd x)) \<in> borel_measurable ?P"
hoelzl@49803
   579
    by (intro borel_measurable_times) (auto intro: distributed_real_measurable measurable_fst'' measurable_snd'')
hoelzl@49803
   580
  have PxPy_nonneg: "AE x in ?P. 0 \<le> Px (fst x) * Py (snd x)"
hoelzl@49803
   581
  proof (rule ST.AE_pair_measure)
hoelzl@49803
   582
    show "{x \<in> space ?P. 0 \<le> Px (fst x) * Py (snd x)} \<in> sets ?P"
hoelzl@49803
   583
      using f by auto
hoelzl@49803
   584
    show "AE x in S. AE y in T. 0 \<le> Px (fst (x, y)) * Py (snd (x, y))"
hoelzl@49803
   585
      using Px Py by (auto simp: zero_le_mult_iff dest!: distributed_real_AE)
hoelzl@49803
   586
  qed
hoelzl@49803
   587
hoelzl@49803
   588
  have "(AE x in ?P. Px (fst x) = 0 \<longrightarrow> Pxy x = 0)"
hoelzl@49803
   589
    by (rule subdensity_real[OF measurable_fst Pxy Px]) auto
hoelzl@49803
   590
  moreover
hoelzl@49803
   591
  have "(AE x in ?P. Py (snd x) = 0 \<longrightarrow> Pxy x = 0)"
hoelzl@49803
   592
    by (rule subdensity_real[OF measurable_snd Pxy Py]) auto
hoelzl@49803
   593
  ultimately have ac: "AE x in ?P. Px (fst x) * Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@49803
   594
    by eventually_elim auto
hoelzl@49803
   595
hoelzl@49803
   596
  show "?M = ?R"
hoelzl@49803
   597
    unfolding M f_def
hoelzl@49803
   598
    using b_gt_1 f PxPy_nonneg Pxy[THEN distributed_real_measurable] Pxy[THEN distributed_real_AE] ac
hoelzl@49803
   599
    by (rule ST.KL_density_density)
hoelzl@49803
   600
hoelzl@49803
   601
  have X: "X = fst \<circ> (\<lambda>x. (X x, Y x))" and Y: "Y = snd \<circ> (\<lambda>x. (X x, Y x))"
hoelzl@49803
   602
    by auto
hoelzl@49803
   603
hoelzl@49803
   604
  have "integrable (S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Pxy x) - Pxy x * log b (Px (fst x)) - Pxy x * log b (Py (snd x)))"
hoelzl@49803
   605
    using finite_entropy_integrable[OF Fxy]
hoelzl@49803
   606
    using finite_entropy_integrable_transform[OF Fx Pxy, of fst]
hoelzl@49803
   607
    using finite_entropy_integrable_transform[OF Fy Pxy, of snd]
hoelzl@49803
   608
    by simp
hoelzl@49803
   609
  moreover have "f \<in> borel_measurable (S \<Otimes>\<^isub>M T)"
hoelzl@49803
   610
    unfolding f_def using Px Py Pxy
hoelzl@49803
   611
    by (auto intro: distributed_real_measurable measurable_fst'' measurable_snd''
hoelzl@49803
   612
      intro!: borel_measurable_times borel_measurable_log borel_measurable_divide)
hoelzl@49803
   613
  ultimately have int: "integrable (S \<Otimes>\<^isub>M T) f"
hoelzl@49803
   614
    apply (rule integrable_cong_AE_imp)
hoelzl@49803
   615
    using
hoelzl@49803
   616
      distributed_transform_AE[OF measurable_fst ac_fst, of T, OF T Px]
hoelzl@49803
   617
      distributed_transform_AE[OF measurable_snd ac_snd, of _ _ _ _ S, OF T Py]
hoelzl@49803
   618
      subdensity_real[OF measurable_fst Pxy Px X]
hoelzl@49803
   619
      subdensity_real[OF measurable_snd Pxy Py Y]
hoelzl@49803
   620
      distributed_real_AE[OF Pxy]
hoelzl@49803
   621
    by eventually_elim
hoelzl@49803
   622
       (auto simp: f_def log_divide_eq log_mult_eq field_simps zero_less_mult_iff mult_nonneg_nonneg)
hoelzl@49803
   623
hoelzl@49803
   624
  show "0 \<le> ?M" unfolding M
hoelzl@49803
   625
  proof (rule ST.KL_density_density_nonneg
hoelzl@49803
   626
    [OF b_gt_1 f PxPy_nonneg _ Pxy[THEN distributed_real_measurable] Pxy[THEN distributed_real_AE] _ ac int[unfolded f_def]])
hoelzl@49803
   627
    show "prob_space (density (S \<Otimes>\<^isub>M T) (\<lambda>x. ereal (Pxy x))) "
hoelzl@49803
   628
      unfolding distributed_distr_eq_density[OF Pxy, symmetric]
hoelzl@49803
   629
      using distributed_measurable[OF Pxy] by (rule prob_space_distr)
hoelzl@49803
   630
    show "prob_space (density (S \<Otimes>\<^isub>M T) (\<lambda>x. ereal (Px (fst x) * Py (snd x))))"
hoelzl@49803
   631
      unfolding distr_eq[symmetric] by unfold_locales
hoelzl@49803
   632
  qed
hoelzl@49803
   633
qed
hoelzl@49803
   634
hoelzl@49803
   635
hoelzl@49803
   636
lemma (in information_space)
hoelzl@49803
   637
  fixes Pxy :: "'b \<times> 'c \<Rightarrow> real" and Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@47694
   638
  assumes "sigma_finite_measure S" "sigma_finite_measure T"
hoelzl@47694
   639
  assumes Px: "distributed M S X Px" and Py: "distributed M T Y Py"
hoelzl@47694
   640
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
   641
  defines "f \<equiv> \<lambda>x. Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x)))"
hoelzl@47694
   642
  shows mutual_information_distr: "mutual_information b S T X Y = integral\<^isup>L (S \<Otimes>\<^isub>M T) f" (is "?M = ?R")
hoelzl@47694
   643
    and mutual_information_nonneg: "integrable (S \<Otimes>\<^isub>M T) f \<Longrightarrow> 0 \<le> mutual_information b S T X Y"
hoelzl@40859
   644
proof -
hoelzl@47694
   645
  have X: "random_variable S X"
hoelzl@47694
   646
    using Px by (auto simp: distributed_def)
hoelzl@47694
   647
  have Y: "random_variable T Y"
hoelzl@47694
   648
    using Py by (auto simp: distributed_def)
hoelzl@47694
   649
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
   650
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
   651
  interpret ST: pair_sigma_finite S T ..
hoelzl@47694
   652
  interpret X: prob_space "distr M S X" using X by (rule prob_space_distr)
hoelzl@47694
   653
  interpret Y: prob_space "distr M T Y" using Y by (rule prob_space_distr)
hoelzl@47694
   654
  interpret XY: pair_prob_space "distr M S X" "distr M T Y" ..
hoelzl@47694
   655
  let ?P = "S \<Otimes>\<^isub>M T"
hoelzl@47694
   656
  let ?D = "distr M ?P (\<lambda>x. (X x, Y x))"
hoelzl@47694
   657
hoelzl@47694
   658
  { fix A assume "A \<in> sets S"
hoelzl@47694
   659
    with X Y have "emeasure (distr M S X) A = emeasure ?D (A \<times> space T)"
hoelzl@47694
   660
      by (auto simp: emeasure_distr measurable_Pair measurable_space
hoelzl@47694
   661
               intro!: arg_cong[where f="emeasure M"]) }
hoelzl@47694
   662
  note marginal_eq1 = this
hoelzl@47694
   663
  { fix A assume "A \<in> sets T"
hoelzl@47694
   664
    with X Y have "emeasure (distr M T Y) A = emeasure ?D (space S \<times> A)"
hoelzl@47694
   665
      by (auto simp: emeasure_distr measurable_Pair measurable_space
hoelzl@47694
   666
               intro!: arg_cong[where f="emeasure M"]) }
hoelzl@47694
   667
  note marginal_eq2 = this
hoelzl@47694
   668
hoelzl@47694
   669
  have eq: "(\<lambda>x. ereal (Px (fst x) * Py (snd x))) = (\<lambda>(x, y). ereal (Px x) * ereal (Py y))"
hoelzl@47694
   670
    by auto
hoelzl@47694
   671
hoelzl@47694
   672
  have distr_eq: "distr M S X \<Otimes>\<^isub>M distr M T Y = density ?P (\<lambda>x. ereal (Px (fst x) * Py (snd x)))"
hoelzl@47694
   673
    unfolding Px(1)[THEN distributed_distr_eq_density] Py(1)[THEN distributed_distr_eq_density] eq
hoelzl@47694
   674
  proof (subst pair_measure_density)
hoelzl@47694
   675
    show "(\<lambda>x. ereal (Px x)) \<in> borel_measurable S" "(\<lambda>y. ereal (Py y)) \<in> borel_measurable T"
hoelzl@47694
   676
      "AE x in S. 0 \<le> ereal (Px x)" "AE y in T. 0 \<le> ereal (Py y)"
hoelzl@47694
   677
      using Px Py by (auto simp: distributed_def)
hoelzl@47694
   678
    show "sigma_finite_measure (density S Px)" unfolding Px(1)[THEN distributed_distr_eq_density, symmetric] ..
hoelzl@47694
   679
    show "sigma_finite_measure (density T Py)" unfolding Py(1)[THEN distributed_distr_eq_density, symmetric] ..
hoelzl@47694
   680
  qed (fact | simp)+
hoelzl@47694
   681
  
hoelzl@47694
   682
  have M: "?M = KL_divergence b (density ?P (\<lambda>x. ereal (Px (fst x) * Py (snd x)))) (density ?P (\<lambda>x. ereal (Pxy x)))"
hoelzl@47694
   683
    unfolding mutual_information_def distr_eq Pxy(1)[THEN distributed_distr_eq_density] ..
hoelzl@47694
   684
hoelzl@47694
   685
  from Px Py have f: "(\<lambda>x. Px (fst x) * Py (snd x)) \<in> borel_measurable ?P"
hoelzl@47694
   686
    by (intro borel_measurable_times) (auto intro: distributed_real_measurable measurable_fst'' measurable_snd'')
hoelzl@47694
   687
  have PxPy_nonneg: "AE x in ?P. 0 \<le> Px (fst x) * Py (snd x)"
hoelzl@47694
   688
  proof (rule ST.AE_pair_measure)
hoelzl@47694
   689
    show "{x \<in> space ?P. 0 \<le> Px (fst x) * Py (snd x)} \<in> sets ?P"
hoelzl@47694
   690
      using f by auto
hoelzl@47694
   691
    show "AE x in S. AE y in T. 0 \<le> Px (fst (x, y)) * Py (snd (x, y))"
hoelzl@47694
   692
      using Px Py by (auto simp: zero_le_mult_iff dest!: distributed_real_AE)
hoelzl@47694
   693
  qed
hoelzl@47694
   694
hoelzl@47694
   695
  have "(AE x in ?P. Px (fst x) = 0 \<longrightarrow> Pxy x = 0)"
hoelzl@47694
   696
    by (rule subdensity_real[OF measurable_fst Pxy Px]) auto
hoelzl@47694
   697
  moreover
hoelzl@47694
   698
  have "(AE x in ?P. Py (snd x) = 0 \<longrightarrow> Pxy x = 0)"
hoelzl@47694
   699
    by (rule subdensity_real[OF measurable_snd Pxy Py]) auto
hoelzl@47694
   700
  ultimately have ac: "AE x in ?P. Px (fst x) * Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
   701
    by eventually_elim auto
hoelzl@47694
   702
hoelzl@47694
   703
  show "?M = ?R"
hoelzl@47694
   704
    unfolding M f_def
hoelzl@47694
   705
    using b_gt_1 f PxPy_nonneg Pxy[THEN distributed_real_measurable] Pxy[THEN distributed_real_AE] ac
hoelzl@47694
   706
    by (rule ST.KL_density_density)
hoelzl@47694
   707
hoelzl@47694
   708
  assume int: "integrable (S \<Otimes>\<^isub>M T) f"
hoelzl@47694
   709
  show "0 \<le> ?M" unfolding M
hoelzl@47694
   710
  proof (rule ST.KL_density_density_nonneg
hoelzl@47694
   711
    [OF b_gt_1 f PxPy_nonneg _ Pxy[THEN distributed_real_measurable] Pxy[THEN distributed_real_AE] _ ac int[unfolded f_def]])
hoelzl@47694
   712
    show "prob_space (density (S \<Otimes>\<^isub>M T) (\<lambda>x. ereal (Pxy x))) "
hoelzl@47694
   713
      unfolding distributed_distr_eq_density[OF Pxy, symmetric]
hoelzl@47694
   714
      using distributed_measurable[OF Pxy] by (rule prob_space_distr)
hoelzl@47694
   715
    show "prob_space (density (S \<Otimes>\<^isub>M T) (\<lambda>x. ereal (Px (fst x) * Py (snd x))))"
hoelzl@47694
   716
      unfolding distr_eq[symmetric] by unfold_locales
hoelzl@40859
   717
  qed
hoelzl@40859
   718
qed
hoelzl@40859
   719
hoelzl@40859
   720
lemma (in information_space)
hoelzl@47694
   721
  fixes Pxy :: "'b \<times> 'c \<Rightarrow> real" and Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@47694
   722
  assumes "sigma_finite_measure S" "sigma_finite_measure T"
hoelzl@47694
   723
  assumes Px: "distributed M S X Px" and Py: "distributed M T Y Py"
hoelzl@47694
   724
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
   725
  assumes ae: "AE x in S. AE y in T. Pxy (x, y) = Px x * Py y"
hoelzl@47694
   726
  shows mutual_information_eq_0: "mutual_information b S T X Y = 0"
hoelzl@36624
   727
proof -
hoelzl@47694
   728
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
   729
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
   730
  interpret ST: pair_sigma_finite S T ..
hoelzl@36080
   731
hoelzl@47694
   732
  have "AE x in S \<Otimes>\<^isub>M T. Px (fst x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
   733
    by (rule subdensity_real[OF measurable_fst Pxy Px]) auto
hoelzl@47694
   734
  moreover
hoelzl@47694
   735
  have "AE x in S \<Otimes>\<^isub>M T. Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
   736
    by (rule subdensity_real[OF measurable_snd Pxy Py]) auto
hoelzl@47694
   737
  moreover 
hoelzl@47694
   738
  have "AE x in S \<Otimes>\<^isub>M T. Pxy x = Px (fst x) * Py (snd x)"
hoelzl@47694
   739
    using distributed_real_measurable[OF Px] distributed_real_measurable[OF Py] distributed_real_measurable[OF Pxy]
hoelzl@47694
   740
    by (intro ST.AE_pair_measure) (auto simp: ae intro!: measurable_snd'' measurable_fst'')
hoelzl@47694
   741
  ultimately have "AE x in S \<Otimes>\<^isub>M T. Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x))) = 0"
hoelzl@47694
   742
    by eventually_elim simp
hoelzl@47694
   743
  then have "(\<integral>x. Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x))) \<partial>(S \<Otimes>\<^isub>M T)) = (\<integral>x. 0 \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@47694
   744
    by (rule integral_cong_AE)
hoelzl@47694
   745
  then show ?thesis
hoelzl@47694
   746
    by (subst mutual_information_distr[OF assms(1-5)]) simp
hoelzl@36080
   747
qed
hoelzl@36080
   748
hoelzl@47694
   749
lemma (in information_space) mutual_information_simple_distributed:
hoelzl@47694
   750
  assumes X: "simple_distributed M X Px" and Y: "simple_distributed M Y Py"
hoelzl@47694
   751
  assumes XY: "simple_distributed M (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
   752
  shows "\<I>(X ; Y) = (\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x))`space M. Pxy (x, y) * log b (Pxy (x, y) / (Px x * Py y)))"
hoelzl@47694
   753
proof (subst mutual_information_distr[OF _ _ simple_distributed[OF X] simple_distributed[OF Y] simple_distributed_joint[OF XY]])
hoelzl@47694
   754
  note fin = simple_distributed_joint_finite[OF XY, simp]
hoelzl@47694
   755
  show "sigma_finite_measure (count_space (X ` space M))"
hoelzl@47694
   756
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
   757
  show "sigma_finite_measure (count_space (Y ` space M))"
hoelzl@47694
   758
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
   759
  let ?Pxy = "\<lambda>x. (if x \<in> (\<lambda>x. (X x, Y x)) ` space M then Pxy x else 0)"
hoelzl@47694
   760
  let ?f = "\<lambda>x. ?Pxy x * log b (?Pxy x / (Px (fst x) * Py (snd x)))"
hoelzl@47694
   761
  have "\<And>x. ?f x = (if x \<in> (\<lambda>x. (X x, Y x)) ` space M then Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x))) else 0)"
hoelzl@47694
   762
    by auto
hoelzl@47694
   763
  with fin show "(\<integral> x. ?f x \<partial>(count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M))) =
hoelzl@47694
   764
    (\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` space M. Pxy (x, y) * log b (Pxy (x, y) / (Px x * Py y)))"
hoelzl@47694
   765
    by (auto simp add: pair_measure_count_space lebesgue_integral_count_space_finite setsum_cases split_beta'
hoelzl@47694
   766
             intro!: setsum_cong)
hoelzl@47694
   767
qed
hoelzl@36080
   768
hoelzl@47694
   769
lemma (in information_space)
hoelzl@47694
   770
  fixes Pxy :: "'b \<times> 'c \<Rightarrow> real" and Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@47694
   771
  assumes Px: "simple_distributed M X Px" and Py: "simple_distributed M Y Py"
hoelzl@47694
   772
  assumes Pxy: "simple_distributed M (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
   773
  assumes ae: "\<forall>x\<in>space M. Pxy (X x, Y x) = Px (X x) * Py (Y x)"
hoelzl@47694
   774
  shows mutual_information_eq_0_simple: "\<I>(X ; Y) = 0"
hoelzl@47694
   775
proof (subst mutual_information_simple_distributed[OF Px Py Pxy])
hoelzl@47694
   776
  have "(\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` space M. Pxy (x, y) * log b (Pxy (x, y) / (Px x * Py y))) =
hoelzl@47694
   777
    (\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` space M. 0)"
hoelzl@47694
   778
    by (intro setsum_cong) (auto simp: ae)
hoelzl@47694
   779
  then show "(\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` space M.
hoelzl@47694
   780
    Pxy (x, y) * log b (Pxy (x, y) / (Px x * Py y))) = 0" by simp
hoelzl@47694
   781
qed
hoelzl@36080
   782
hoelzl@39097
   783
subsection {* Entropy *}
hoelzl@39097
   784
hoelzl@47694
   785
definition (in prob_space) entropy :: "real \<Rightarrow> 'b measure \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> real" where
hoelzl@47694
   786
  "entropy b S X = - KL_divergence b S (distr M S X)"
hoelzl@47694
   787
hoelzl@40859
   788
abbreviation (in information_space)
hoelzl@40859
   789
  entropy_Pow ("\<H>'(_')") where
hoelzl@47694
   790
  "\<H>(X) \<equiv> entropy b (count_space (X`space M)) X"
hoelzl@41981
   791
hoelzl@49791
   792
lemma (in prob_space) distributed_RN_deriv:
hoelzl@49791
   793
  assumes X: "distributed M S X Px"
hoelzl@49791
   794
  shows "AE x in S. RN_deriv S (density S Px) x = Px x"
hoelzl@49791
   795
proof -
hoelzl@49791
   796
  note D = distributed_measurable[OF X] distributed_borel_measurable[OF X] distributed_AE[OF X]
hoelzl@49791
   797
  interpret X: prob_space "distr M S X"
hoelzl@49791
   798
    using D(1) by (rule prob_space_distr)
hoelzl@49791
   799
hoelzl@49791
   800
  have sf: "sigma_finite_measure (distr M S X)" by default
hoelzl@49791
   801
  show ?thesis
hoelzl@49791
   802
    using D
hoelzl@49791
   803
    apply (subst eq_commute)
hoelzl@49791
   804
    apply (intro RN_deriv_unique_sigma_finite)
hoelzl@49791
   805
    apply (auto intro: divide_nonneg_nonneg measure_nonneg
hoelzl@49791
   806
             simp: distributed_distr_eq_density[symmetric, OF X] sf)
hoelzl@49791
   807
    done
hoelzl@49791
   808
qed
hoelzl@49791
   809
hoelzl@49788
   810
lemma (in information_space)
hoelzl@47694
   811
  fixes X :: "'a \<Rightarrow> 'b"
hoelzl@49785
   812
  assumes X: "distributed M MX X f"
hoelzl@49788
   813
  shows entropy_distr: "entropy b MX X = - (\<integral>x. f x * log b (f x) \<partial>MX)" (is ?eq)
hoelzl@49788
   814
proof -
hoelzl@49785
   815
  note D = distributed_measurable[OF X] distributed_borel_measurable[OF X] distributed_AE[OF X]
hoelzl@49791
   816
  note ae = distributed_RN_deriv[OF X]
hoelzl@49788
   817
hoelzl@49788
   818
  have ae_eq: "AE x in distr M MX X. log b (real (RN_deriv MX (distr M MX X) x)) =
hoelzl@49785
   819
    log b (f x)"
hoelzl@49785
   820
    unfolding distributed_distr_eq_density[OF X]
hoelzl@49785
   821
    apply (subst AE_density)
hoelzl@49785
   822
    using D apply simp
hoelzl@49785
   823
    using ae apply eventually_elim
hoelzl@49785
   824
    apply auto
hoelzl@49785
   825
    done
hoelzl@49788
   826
hoelzl@49788
   827
  have int_eq: "- (\<integral> x. log b (f x) \<partial>distr M MX X) = - (\<integral> x. f x * log b (f x) \<partial>MX)"
hoelzl@49785
   828
    unfolding distributed_distr_eq_density[OF X]
hoelzl@49785
   829
    using D
hoelzl@49785
   830
    by (subst integral_density)
hoelzl@49785
   831
       (auto simp: borel_measurable_ereal_iff)
hoelzl@49788
   832
hoelzl@49788
   833
  show ?eq
hoelzl@49788
   834
    unfolding entropy_def KL_divergence_def entropy_density_def comp_def
hoelzl@49788
   835
    apply (subst integral_cong_AE)
hoelzl@49788
   836
    apply (rule ae_eq)
hoelzl@49788
   837
    apply (rule int_eq)
hoelzl@49788
   838
    done
hoelzl@49788
   839
qed
hoelzl@49785
   840
hoelzl@49786
   841
lemma (in prob_space) distributed_imp_emeasure_nonzero:
hoelzl@49786
   842
  assumes X: "distributed M MX X Px"
hoelzl@49786
   843
  shows "emeasure MX {x \<in> space MX. Px x \<noteq> 0} \<noteq> 0"
hoelzl@49786
   844
proof
hoelzl@49786
   845
  note Px = distributed_borel_measurable[OF X] distributed_AE[OF X]
hoelzl@49786
   846
  interpret X: prob_space "distr M MX X"
hoelzl@49786
   847
    using distributed_measurable[OF X] by (rule prob_space_distr)
hoelzl@49786
   848
hoelzl@49786
   849
  assume "emeasure MX {x \<in> space MX. Px x \<noteq> 0} = 0"
hoelzl@49786
   850
  with Px have "AE x in MX. Px x = 0"
hoelzl@49786
   851
    by (intro AE_I[OF subset_refl]) (auto simp: borel_measurable_ereal_iff)
hoelzl@49786
   852
  moreover
hoelzl@49786
   853
  from X.emeasure_space_1 have "(\<integral>\<^isup>+x. Px x \<partial>MX) = 1"
hoelzl@49786
   854
    unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   855
    by (subst (asm) emeasure_density)
hoelzl@49786
   856
       (auto simp: borel_measurable_ereal_iff intro!: integral_cong cong: positive_integral_cong)
hoelzl@49786
   857
  ultimately show False
hoelzl@49786
   858
    by (simp add: positive_integral_cong_AE)
hoelzl@49786
   859
qed
hoelzl@49786
   860
hoelzl@49786
   861
lemma (in information_space) entropy_le:
hoelzl@49786
   862
  fixes Px :: "'b \<Rightarrow> real" and MX :: "'b measure"
hoelzl@49786
   863
  assumes X: "distributed M MX X Px"
hoelzl@49786
   864
  and fin: "emeasure MX {x \<in> space MX. Px x \<noteq> 0} \<noteq> \<infinity>"
hoelzl@49786
   865
  and int: "integrable MX (\<lambda>x. - Px x * log b (Px x))"
hoelzl@49786
   866
  shows "entropy b MX X \<le> log b (measure MX {x \<in> space MX. Px x \<noteq> 0})"
hoelzl@49786
   867
proof -
hoelzl@49786
   868
  note Px = distributed_borel_measurable[OF X] distributed_AE[OF X]
hoelzl@49786
   869
  interpret X: prob_space "distr M MX X"
hoelzl@49786
   870
    using distributed_measurable[OF X] by (rule prob_space_distr)
hoelzl@49786
   871
hoelzl@49786
   872
  have " - log b (measure MX {x \<in> space MX. Px x \<noteq> 0}) = 
hoelzl@49786
   873
    - log b (\<integral> x. indicator {x \<in> space MX. Px x \<noteq> 0} x \<partial>MX)"
hoelzl@49786
   874
    using Px fin
hoelzl@49786
   875
    by (subst integral_indicator) (auto simp: measure_def borel_measurable_ereal_iff)
hoelzl@49786
   876
  also have "- log b (\<integral> x. indicator {x \<in> space MX. Px x \<noteq> 0} x \<partial>MX) = - log b (\<integral> x. 1 / Px x \<partial>distr M MX X)"
hoelzl@49786
   877
    unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   878
    apply (intro arg_cong[where f="log b"] arg_cong[where f=uminus])
hoelzl@49786
   879
    by (subst integral_density) (auto simp: borel_measurable_ereal_iff intro!: integral_cong)
hoelzl@49786
   880
  also have "\<dots> \<le> (\<integral> x. - log b (1 / Px x) \<partial>distr M MX X)"
hoelzl@49786
   881
  proof (rule X.jensens_inequality[of "\<lambda>x. 1 / Px x" "{0<..}" 0 1 "\<lambda>x. - log b x"])
hoelzl@49786
   882
    show "AE x in distr M MX X. 1 / Px x \<in> {0<..}"
hoelzl@49786
   883
      unfolding distributed_distr_eq_density[OF X]
hoelzl@49786
   884
      using Px by (auto simp: AE_density)
hoelzl@49786
   885
    have [simp]: "\<And>x. x \<in> space MX \<Longrightarrow> ereal (if Px x = 0 then 0 else 1) = indicator {x \<in> space MX. Px x \<noteq> 0} x"
hoelzl@49786
   886
      by (auto simp: one_ereal_def)
hoelzl@49786
   887
    have "(\<integral>\<^isup>+ x. max 0 (ereal (- (if Px x = 0 then 0 else 1))) \<partial>MX) = (\<integral>\<^isup>+ x. 0 \<partial>MX)"
hoelzl@49786
   888
      by (intro positive_integral_cong) (auto split: split_max)
hoelzl@49786
   889
    then show "integrable (distr M MX X) (\<lambda>x. 1 / Px x)"
hoelzl@49786
   890
      unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   891
      by (auto simp: positive_integral_density integrable_def borel_measurable_ereal_iff fin positive_integral_max_0
hoelzl@49786
   892
              cong: positive_integral_cong)
hoelzl@49786
   893
    have "integrable MX (\<lambda>x. Px x * log b (1 / Px x)) =
hoelzl@49786
   894
      integrable MX (\<lambda>x. - Px x * log b (Px x))"
hoelzl@49786
   895
      using Px
hoelzl@49786
   896
      by (intro integrable_cong_AE)
hoelzl@49786
   897
         (auto simp: borel_measurable_ereal_iff log_divide_eq
hoelzl@49786
   898
                  intro!: measurable_If)
hoelzl@49786
   899
    then show "integrable (distr M MX X) (\<lambda>x. - log b (1 / Px x))"
hoelzl@49786
   900
      unfolding distributed_distr_eq_density[OF X]
hoelzl@49786
   901
      using Px int
hoelzl@49786
   902
      by (subst integral_density) (auto simp: borel_measurable_ereal_iff)
hoelzl@49786
   903
  qed (auto simp: minus_log_convex[OF b_gt_1])
hoelzl@49786
   904
  also have "\<dots> = (\<integral> x. log b (Px x) \<partial>distr M MX X)"
hoelzl@49786
   905
    unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   906
    by (intro integral_cong_AE) (auto simp: AE_density log_divide_eq)
hoelzl@49786
   907
  also have "\<dots> = - entropy b MX X"
hoelzl@49786
   908
    unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   909
    by (subst entropy_distr[OF X]) (auto simp: borel_measurable_ereal_iff integral_density)
hoelzl@49786
   910
  finally show ?thesis
hoelzl@49786
   911
    by simp
hoelzl@49786
   912
qed
hoelzl@49786
   913
hoelzl@49786
   914
lemma (in information_space) entropy_le_space:
hoelzl@49786
   915
  fixes Px :: "'b \<Rightarrow> real" and MX :: "'b measure"
hoelzl@49786
   916
  assumes X: "distributed M MX X Px"
hoelzl@49786
   917
  and fin: "finite_measure MX"
hoelzl@49786
   918
  and int: "integrable MX (\<lambda>x. - Px x * log b (Px x))"
hoelzl@49786
   919
  shows "entropy b MX X \<le> log b (measure MX (space MX))"
hoelzl@49786
   920
proof -
hoelzl@49786
   921
  note Px = distributed_borel_measurable[OF X] distributed_AE[OF X]
hoelzl@49786
   922
  interpret finite_measure MX by fact
hoelzl@49786
   923
  have "entropy b MX X \<le> log b (measure MX {x \<in> space MX. Px x \<noteq> 0})"
hoelzl@49786
   924
    using int X by (intro entropy_le) auto
hoelzl@49786
   925
  also have "\<dots> \<le> log b (measure MX (space MX))"
hoelzl@49786
   926
    using Px distributed_imp_emeasure_nonzero[OF X]
hoelzl@49786
   927
    by (intro log_le)
hoelzl@49786
   928
       (auto intro!: borel_measurable_ereal_iff finite_measure_mono b_gt_1
hoelzl@49786
   929
                     less_le[THEN iffD2] measure_nonneg simp: emeasure_eq_measure)
hoelzl@49786
   930
  finally show ?thesis .
hoelzl@49786
   931
qed
hoelzl@49786
   932
hoelzl@49785
   933
lemma (in prob_space) uniform_distributed_params:
hoelzl@49785
   934
  assumes X: "distributed M MX X (\<lambda>x. indicator A x / measure MX A)"
hoelzl@49785
   935
  shows "A \<in> sets MX" "measure MX A \<noteq> 0"
hoelzl@47694
   936
proof -
hoelzl@49785
   937
  interpret X: prob_space "distr M MX X"
hoelzl@49785
   938
    using distributed_measurable[OF X] by (rule prob_space_distr)
hoelzl@49785
   939
hoelzl@49785
   940
  show "measure MX A \<noteq> 0"
hoelzl@49785
   941
  proof
hoelzl@49785
   942
    assume "measure MX A = 0"
hoelzl@49785
   943
    with X.emeasure_space_1 X.prob_space distributed_distr_eq_density[OF X]
hoelzl@49785
   944
    show False
hoelzl@49785
   945
      by (simp add: emeasure_density zero_ereal_def[symmetric])
hoelzl@49785
   946
  qed
hoelzl@49785
   947
  with measure_notin_sets[of A MX] show "A \<in> sets MX"
hoelzl@49785
   948
    by blast
hoelzl@39097
   949
qed
hoelzl@36624
   950
hoelzl@47694
   951
lemma (in information_space) entropy_uniform:
hoelzl@49785
   952
  assumes X: "distributed M MX X (\<lambda>x. indicator A x / measure MX A)" (is "distributed _ _ _ ?f")
hoelzl@47694
   953
  shows "entropy b MX X = log b (measure MX A)"
hoelzl@49785
   954
proof (subst entropy_distr[OF X])
hoelzl@49785
   955
  have [simp]: "emeasure MX A \<noteq> \<infinity>"
hoelzl@49785
   956
    using uniform_distributed_params[OF X] by (auto simp add: measure_def)
hoelzl@49785
   957
  have eq: "(\<integral> x. indicator A x / measure MX A * log b (indicator A x / measure MX A) \<partial>MX) =
hoelzl@49785
   958
    (\<integral> x. (- log b (measure MX A) / measure MX A) * indicator A x \<partial>MX)"
hoelzl@49785
   959
    using measure_nonneg[of MX A] uniform_distributed_params[OF X]
hoelzl@49785
   960
    by (auto intro!: integral_cong split: split_indicator simp: log_divide_eq)
hoelzl@49785
   961
  show "- (\<integral> x. indicator A x / measure MX A * log b (indicator A x / measure MX A) \<partial>MX) =
hoelzl@49785
   962
    log b (measure MX A)"
hoelzl@49785
   963
    unfolding eq using uniform_distributed_params[OF X]
hoelzl@49785
   964
    by (subst lebesgue_integral_cmult) (auto simp: measure_def)
hoelzl@49785
   965
qed
hoelzl@36080
   966
hoelzl@47694
   967
lemma (in information_space) entropy_simple_distributed:
hoelzl@49786
   968
  "simple_distributed M X f \<Longrightarrow> \<H>(X) = - (\<Sum>x\<in>X`space M. f x * log b (f x))"
hoelzl@49786
   969
  by (subst entropy_distr[OF simple_distributed])
hoelzl@49786
   970
     (auto simp add: lebesgue_integral_count_space_finite)
hoelzl@39097
   971
hoelzl@40859
   972
lemma (in information_space) entropy_le_card_not_0:
hoelzl@47694
   973
  assumes X: "simple_distributed M X f"
hoelzl@47694
   974
  shows "\<H>(X) \<le> log b (card (X ` space M \<inter> {x. f x \<noteq> 0}))"
hoelzl@39097
   975
proof -
hoelzl@49787
   976
  let ?X = "count_space (X`space M)"
hoelzl@49787
   977
  have "\<H>(X) \<le> log b (measure ?X {x \<in> space ?X. f x \<noteq> 0})"
hoelzl@49787
   978
    by (rule entropy_le[OF simple_distributed[OF X]])
hoelzl@49787
   979
       (simp_all add: simple_distributed_finite[OF X] subset_eq integrable_count_space emeasure_count_space)
hoelzl@49787
   980
  also have "measure ?X {x \<in> space ?X. f x \<noteq> 0} = card (X ` space M \<inter> {x. f x \<noteq> 0})"
hoelzl@49787
   981
    by (simp_all add: simple_distributed_finite[OF X] subset_eq emeasure_count_space measure_def Int_def)
hoelzl@49787
   982
  finally show ?thesis .
hoelzl@39097
   983
qed
hoelzl@39097
   984
hoelzl@40859
   985
lemma (in information_space) entropy_le_card:
hoelzl@49787
   986
  assumes X: "simple_distributed M X f"
hoelzl@40859
   987
  shows "\<H>(X) \<le> log b (real (card (X ` space M)))"
hoelzl@49787
   988
proof -
hoelzl@49787
   989
  let ?X = "count_space (X`space M)"
hoelzl@49787
   990
  have "\<H>(X) \<le> log b (measure ?X (space ?X))"
hoelzl@49787
   991
    by (rule entropy_le_space[OF simple_distributed[OF X]])
hoelzl@49787
   992
       (simp_all add: simple_distributed_finite[OF X] subset_eq integrable_count_space emeasure_count_space finite_measure_count_space)
hoelzl@49787
   993
  also have "measure ?X (space ?X) = card (X ` space M)"
hoelzl@49787
   994
    by (simp_all add: simple_distributed_finite[OF X] subset_eq emeasure_count_space measure_def)
hoelzl@39097
   995
  finally show ?thesis .
hoelzl@39097
   996
qed
hoelzl@39097
   997
hoelzl@39097
   998
subsection {* Conditional Mutual Information *}
hoelzl@39097
   999
hoelzl@36080
  1000
definition (in prob_space)
hoelzl@41689
  1001
  "conditional_mutual_information b MX MY MZ X Y Z \<equiv>
hoelzl@41689
  1002
    mutual_information b MX (MY \<Otimes>\<^isub>M MZ) X (\<lambda>x. (Y x, Z x)) -
hoelzl@41689
  1003
    mutual_information b MX MZ X Z"
hoelzl@36080
  1004
hoelzl@40859
  1005
abbreviation (in information_space)
hoelzl@40859
  1006
  conditional_mutual_information_Pow ("\<I>'( _ ; _ | _ ')") where
hoelzl@36624
  1007
  "\<I>(X ; Y | Z) \<equiv> conditional_mutual_information b
hoelzl@47694
  1008
    (count_space (X ` space M)) (count_space (Y ` space M)) (count_space (Z ` space M)) X Y Z"
hoelzl@36080
  1009
hoelzl@49787
  1010
lemma (in pair_sigma_finite) borel_measurable_positive_integral_fst:
hoelzl@49787
  1011
  "(\<lambda>(x, y). f x y) \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2) \<Longrightarrow> (\<lambda>x. \<integral>\<^isup>+ y. f x y \<partial>M2) \<in> borel_measurable M1"
hoelzl@49787
  1012
  using positive_integral_fst_measurable(1)[of "\<lambda>(x, y). f x y"] by simp
hoelzl@49787
  1013
hoelzl@49787
  1014
lemma (in pair_sigma_finite) borel_measurable_positive_integral_snd:
hoelzl@49787
  1015
  assumes "(\<lambda>(x, y). f x y) \<in> borel_measurable (M2 \<Otimes>\<^isub>M M1)" shows "(\<lambda>x. \<integral>\<^isup>+ y. f x y \<partial>M1) \<in> borel_measurable M2"
hoelzl@49787
  1016
proof -
hoelzl@49787
  1017
  interpret Q: pair_sigma_finite M2 M1 by default
hoelzl@49787
  1018
  from Q.borel_measurable_positive_integral_fst assms show ?thesis by simp
hoelzl@49787
  1019
qed
hoelzl@49787
  1020
hoelzl@49787
  1021
lemma (in information_space)
hoelzl@47694
  1022
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T" and P: "sigma_finite_measure P"
hoelzl@47694
  1023
  assumes Px: "distributed M S X Px"
hoelzl@47694
  1024
  assumes Pz: "distributed M P Z Pz"
hoelzl@47694
  1025
  assumes Pyz: "distributed M (T \<Otimes>\<^isub>M P) (\<lambda>x. (Y x, Z x)) Pyz"
hoelzl@47694
  1026
  assumes Pxz: "distributed M (S \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Z x)) Pxz"
hoelzl@47694
  1027
  assumes Pxyz: "distributed M (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Y x, Z x)) Pxyz"
hoelzl@47694
  1028
  assumes I1: "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Px x * Pyz (y, z))))"
hoelzl@47694
  1029
  assumes I2: "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxz (x, z) / (Px x * Pz z)))"
hoelzl@49787
  1030
  shows conditional_mutual_information_generic_eq: "conditional_mutual_information b S T P X Y Z
hoelzl@49787
  1031
    = (\<integral>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Pxz (x, z) * (Pyz (y,z) / Pz z))) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))" (is "?eq")
hoelzl@49787
  1032
    and conditional_mutual_information_generic_nonneg: "0 \<le> conditional_mutual_information b S T P X Y Z" (is "?nonneg")
hoelzl@40859
  1033
proof -
hoelzl@47694
  1034
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
  1035
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
  1036
  interpret P: sigma_finite_measure P by fact
hoelzl@47694
  1037
  interpret TP: pair_sigma_finite T P ..
hoelzl@47694
  1038
  interpret SP: pair_sigma_finite S P ..
hoelzl@49787
  1039
  interpret ST: pair_sigma_finite S T ..
hoelzl@47694
  1040
  interpret SPT: pair_sigma_finite "S \<Otimes>\<^isub>M P" T ..
hoelzl@47694
  1041
  interpret STP: pair_sigma_finite S "T \<Otimes>\<^isub>M P" ..
hoelzl@49787
  1042
  interpret TPS: pair_sigma_finite "T \<Otimes>\<^isub>M P" S ..
hoelzl@47694
  1043
  have TP: "sigma_finite_measure (T \<Otimes>\<^isub>M P)" ..
hoelzl@47694
  1044
  have SP: "sigma_finite_measure (S \<Otimes>\<^isub>M P)" ..
hoelzl@47694
  1045
  have YZ: "random_variable (T \<Otimes>\<^isub>M P) (\<lambda>x. (Y x, Z x))"
hoelzl@47694
  1046
    using Pyz by (simp add: distributed_measurable)
hoelzl@47694
  1047
hoelzl@47694
  1048
  have Pxyz_f: "\<And>M f. f \<in> measurable M (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) \<Longrightarrow> (\<lambda>x. Pxyz (f x)) \<in> borel_measurable M"
hoelzl@47694
  1049
    using measurable_comp[OF _ Pxyz[THEN distributed_real_measurable]] by (auto simp: comp_def)
hoelzl@47694
  1050
hoelzl@47694
  1051
  { fix f g h M
hoelzl@47694
  1052
    assume f: "f \<in> measurable M S" and g: "g \<in> measurable M P" and h: "h \<in> measurable M (S \<Otimes>\<^isub>M P)"
hoelzl@47694
  1053
    from measurable_comp[OF h Pxz[THEN distributed_real_measurable]]
hoelzl@47694
  1054
         measurable_comp[OF f Px[THEN distributed_real_measurable]]
hoelzl@47694
  1055
         measurable_comp[OF g Pz[THEN distributed_real_measurable]]
hoelzl@47694
  1056
    have "(\<lambda>x. log b (Pxz (h x) / (Px (f x) * Pz (g x)))) \<in> borel_measurable M"
hoelzl@47694
  1057
      by (simp add: comp_def b_gt_1) }
hoelzl@47694
  1058
  note borel_log = this
hoelzl@47694
  1059
hoelzl@47694
  1060
  have measurable_cut: "(\<lambda>(x, y, z). (x, z)) \<in> measurable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (S \<Otimes>\<^isub>M P)"
hoelzl@47694
  1061
    by (auto simp add: split_beta' comp_def intro!: measurable_Pair measurable_snd')
hoelzl@47694
  1062
  
hoelzl@47694
  1063
  from Pxz Pxyz have distr_eq: "distr M (S \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Z x)) =
hoelzl@47694
  1064
    distr (distr M (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Y x, Z x))) (S \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). (x, z))"
hoelzl@47694
  1065
    by (subst distr_distr[OF measurable_cut]) (auto dest: distributed_measurable simp: comp_def)
hoelzl@40859
  1066
hoelzl@47694
  1067
  have "mutual_information b S P X Z =
hoelzl@47694
  1068
    (\<integral>x. Pxz x * log b (Pxz x / (Px (fst x) * Pz (snd x))) \<partial>(S \<Otimes>\<^isub>M P))"
hoelzl@47694
  1069
    by (rule mutual_information_distr[OF S P Px Pz Pxz])
hoelzl@47694
  1070
  also have "\<dots> = (\<integral>(x,y,z). Pxyz (x,y,z) * log b (Pxz (x,z) / (Px x * Pz z)) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))"
hoelzl@47694
  1071
    using b_gt_1 Pxz Px Pz
hoelzl@47694
  1072
    by (subst distributed_transform_integral[OF Pxyz Pxz, where T="\<lambda>(x, y, z). (x, z)"])
hoelzl@47694
  1073
       (auto simp: split_beta' intro!: measurable_Pair measurable_snd' measurable_snd'' measurable_fst'' borel_measurable_times
hoelzl@47694
  1074
             dest!: distributed_real_measurable)
hoelzl@47694
  1075
  finally have mi_eq:
hoelzl@47694
  1076
    "mutual_information b S P X Z = (\<integral>(x,y,z). Pxyz (x,y,z) * log b (Pxz (x,z) / (Px x * Pz z)) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))" .
hoelzl@47694
  1077
  
hoelzl@49787
  1078
  have ae1: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Px (fst x) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@47694
  1079
    by (intro subdensity_real[of fst, OF _ Pxyz Px]) auto
hoelzl@49787
  1080
  moreover have ae2: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pz (snd (snd x)) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@47694
  1081
    by (intro subdensity_real[of "\<lambda>x. snd (snd x)", OF _ Pxyz Pz]) (auto intro: measurable_snd')
hoelzl@49787
  1082
  moreover have ae3: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pxz (fst x, snd (snd x)) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@47694
  1083
    by (intro subdensity_real[of "\<lambda>x. (fst x, snd (snd x))", OF _ Pxyz Pxz]) (auto intro: measurable_Pair measurable_snd')
hoelzl@49787
  1084
  moreover have ae4: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pyz (snd x) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@47694
  1085
    by (intro subdensity_real[of snd, OF _ Pxyz Pyz]) (auto intro: measurable_Pair)
hoelzl@49787
  1086
  moreover have ae5: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Px (fst x)"
hoelzl@47694
  1087
    using Px by (intro STP.AE_pair_measure) (auto simp: comp_def intro!: measurable_fst'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49787
  1088
  moreover have ae6: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Pyz (snd x)"
hoelzl@47694
  1089
    using Pyz by (intro STP.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49787
  1090
  moreover have ae7: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Pz (snd (snd x))"
hoelzl@47694
  1091
    using Pz Pz[THEN distributed_real_measurable] by (auto intro!: measurable_snd'' TP.AE_pair_measure STP.AE_pair_measure AE_I2[of S] dest: distributed_real_AE)
hoelzl@49787
  1092
  moreover have ae8: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Pxz (fst x, snd (snd x))"
hoelzl@47694
  1093
    using Pxz[THEN distributed_real_AE, THEN SP.AE_pair]
hoelzl@47694
  1094
    using measurable_comp[OF measurable_Pair[OF measurable_fst measurable_comp[OF measurable_snd measurable_snd]] Pxz[THEN distributed_real_measurable], of T]
hoelzl@47694
  1095
    using measurable_comp[OF measurable_snd measurable_Pair2[OF Pxz[THEN distributed_real_measurable]], of _ T]
hoelzl@47694
  1096
    by (auto intro!: TP.AE_pair_measure STP.AE_pair_measure simp: comp_def)
hoelzl@47694
  1097
  moreover note Pxyz[THEN distributed_real_AE]
hoelzl@49787
  1098
  ultimately have ae: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P.
hoelzl@47694
  1099
    Pxyz x * log b (Pxyz x / (Px (fst x) * Pyz (snd x))) -
hoelzl@47694
  1100
    Pxyz x * log b (Pxz (fst x, snd (snd x)) / (Px (fst x) * Pz (snd (snd x)))) =
hoelzl@47694
  1101
    Pxyz x * log b (Pxyz x * Pz (snd (snd x)) / (Pxz (fst x, snd (snd x)) * Pyz (snd x))) "
hoelzl@47694
  1102
  proof eventually_elim
hoelzl@47694
  1103
    case (goal1 x)
hoelzl@47694
  1104
    show ?case
hoelzl@40859
  1105
    proof cases
hoelzl@47694
  1106
      assume "Pxyz x \<noteq> 0"
hoelzl@47694
  1107
      with goal1 have "0 < Px (fst x)" "0 < Pz (snd (snd x))" "0 < Pxz (fst x, snd (snd x))" "0 < Pyz (snd x)" "0 < Pxyz x"
hoelzl@47694
  1108
        by auto
hoelzl@47694
  1109
      then show ?thesis
hoelzl@47694
  1110
        using b_gt_1 by (simp add: log_simps mult_pos_pos less_imp_le field_simps)
hoelzl@40859
  1111
    qed simp
hoelzl@40859
  1112
  qed
hoelzl@49787
  1113
  with I1 I2 show ?eq
hoelzl@40859
  1114
    unfolding conditional_mutual_information_def
hoelzl@47694
  1115
    apply (subst mi_eq)
hoelzl@47694
  1116
    apply (subst mutual_information_distr[OF S TP Px Pyz Pxyz])
hoelzl@47694
  1117
    apply (subst integral_diff(2)[symmetric])
hoelzl@47694
  1118
    apply (auto intro!: integral_cong_AE simp: split_beta' simp del: integral_diff)
hoelzl@47694
  1119
    done
hoelzl@49787
  1120
hoelzl@49787
  1121
  let ?P = "density (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) Pxyz"
hoelzl@49787
  1122
  interpret P: prob_space ?P
hoelzl@49787
  1123
    unfolding distributed_distr_eq_density[OF Pxyz, symmetric]
hoelzl@49787
  1124
    using distributed_measurable[OF Pxyz] by (rule prob_space_distr)
hoelzl@49787
  1125
hoelzl@49787
  1126
  let ?Q = "density (T \<Otimes>\<^isub>M P) Pyz"
hoelzl@49787
  1127
  interpret Q: prob_space ?Q
hoelzl@49787
  1128
    unfolding distributed_distr_eq_density[OF Pyz, symmetric]
hoelzl@49787
  1129
    using distributed_measurable[OF Pyz] by (rule prob_space_distr)
hoelzl@49787
  1130
hoelzl@49787
  1131
  let ?f = "\<lambda>(x, y, z). Pxz (x, z) * (Pyz (y, z) / Pz z) / Pxyz (x, y, z)"
hoelzl@49787
  1132
hoelzl@49787
  1133
  from subdensity_real[of snd, OF _ Pyz Pz]
hoelzl@49787
  1134
  have aeX1: "AE x in T \<Otimes>\<^isub>M P. Pz (snd x) = 0 \<longrightarrow> Pyz x = 0" by (auto simp: comp_def)
hoelzl@49787
  1135
  have aeX2: "AE x in T \<Otimes>\<^isub>M P. 0 \<le> Pz (snd x)"
hoelzl@49787
  1136
    using Pz by (intro TP.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49787
  1137
hoelzl@49787
  1138
  have aeX3: "AE y in T \<Otimes>\<^isub>M P. (\<integral>\<^isup>+ x. ereal (Pxz (x, snd y)) \<partial>S) = ereal (Pz (snd y))"
hoelzl@49788
  1139
    using Pz distributed_marginal_eq_joint2[OF P S Pz Pxz]
hoelzl@49787
  1140
    apply (intro TP.AE_pair_measure)
hoelzl@49787
  1141
    apply (auto simp: comp_def measurable_split_conv
hoelzl@49787
  1142
                intro!: measurable_snd'' borel_measurable_ereal_eq borel_measurable_ereal
hoelzl@49787
  1143
                        SP.borel_measurable_positive_integral_snd measurable_compose[OF _ Pxz[THEN distributed_real_measurable]]
hoelzl@49787
  1144
                        measurable_Pair
hoelzl@49787
  1145
                dest: distributed_real_AE distributed_real_measurable)
hoelzl@49787
  1146
    done
hoelzl@49787
  1147
hoelzl@49787
  1148
  note M = borel_measurable_divide borel_measurable_diff borel_measurable_times borel_measurable_ereal
hoelzl@49787
  1149
           measurable_compose[OF _ measurable_snd]
hoelzl@49787
  1150
           measurable_Pair
hoelzl@49787
  1151
           measurable_compose[OF _ Pxyz[THEN distributed_real_measurable]]
hoelzl@49787
  1152
           measurable_compose[OF _ Pxz[THEN distributed_real_measurable]]
hoelzl@49787
  1153
           measurable_compose[OF _ Pyz[THEN distributed_real_measurable]]
hoelzl@49787
  1154
           measurable_compose[OF _ Pz[THEN distributed_real_measurable]]
hoelzl@49787
  1155
           measurable_compose[OF _ Px[THEN distributed_real_measurable]]
hoelzl@49787
  1156
           STP.borel_measurable_positive_integral_snd
hoelzl@49787
  1157
  have "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<le> (\<integral>\<^isup>+ (x, y, z). Pxz (x, z) * (Pyz (y, z) / Pz z) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))"
hoelzl@49787
  1158
    apply (subst positive_integral_density)
hoelzl@49787
  1159
    apply (rule distributed_borel_measurable[OF Pxyz])
hoelzl@49787
  1160
    apply (rule distributed_AE[OF Pxyz])
hoelzl@49787
  1161
    apply (auto simp add: borel_measurable_ereal_iff split_beta' intro!: M) []
hoelzl@49787
  1162
    apply (rule positive_integral_mono_AE)
hoelzl@49787
  1163
    using ae5 ae6 ae7 ae8
hoelzl@49787
  1164
    apply eventually_elim
hoelzl@49787
  1165
    apply (auto intro!: divide_nonneg_nonneg mult_nonneg_nonneg)
hoelzl@49787
  1166
    done
hoelzl@49787
  1167
  also have "\<dots> = (\<integral>\<^isup>+(y, z). \<integral>\<^isup>+ x. ereal (Pxz (x, z)) * ereal (Pyz (y, z) / Pz z) \<partial>S \<partial>T \<Otimes>\<^isub>M P)"
hoelzl@49787
  1168
    by (subst STP.positive_integral_snd_measurable[symmetric])
hoelzl@49787
  1169
       (auto simp add: borel_measurable_ereal_iff split_beta' intro!: M)
hoelzl@49787
  1170
  also have "\<dots> = (\<integral>\<^isup>+x. ereal (Pyz x) * 1 \<partial>T \<Otimes>\<^isub>M P)"
hoelzl@49787
  1171
    apply (rule positive_integral_cong_AE)
hoelzl@49787
  1172
    using aeX1 aeX2 aeX3 distributed_AE[OF Pyz] AE_space
hoelzl@49787
  1173
    apply eventually_elim
hoelzl@49787
  1174
  proof (case_tac x, simp del: times_ereal.simps add: space_pair_measure)
hoelzl@49787
  1175
    fix a b assume "Pz b = 0 \<longrightarrow> Pyz (a, b) = 0" "0 \<le> Pz b" "a \<in> space T \<and> b \<in> space P"
hoelzl@49787
  1176
      "(\<integral>\<^isup>+ x. ereal (Pxz (x, b)) \<partial>S) = ereal (Pz b)" "0 \<le> Pyz (a, b)" 
hoelzl@49787
  1177
    then show "(\<integral>\<^isup>+ x. ereal (Pxz (x, b)) * ereal (Pyz (a, b) / Pz b) \<partial>S) = ereal (Pyz (a, b))"
hoelzl@49787
  1178
      apply (subst positive_integral_multc)
hoelzl@49787
  1179
      apply (auto intro!: borel_measurable_ereal divide_nonneg_nonneg
hoelzl@49787
  1180
                          measurable_compose[OF _ Pxz[THEN distributed_real_measurable]] measurable_Pair
hoelzl@49787
  1181
                  split: prod.split)
hoelzl@49787
  1182
      done
hoelzl@49787
  1183
  qed
hoelzl@49787
  1184
  also have "\<dots> = 1"
hoelzl@49787
  1185
    using Q.emeasure_space_1 distributed_AE[OF Pyz] distributed_distr_eq_density[OF Pyz]
hoelzl@49787
  1186
    by (subst positive_integral_density[symmetric]) (auto intro!: M)
hoelzl@49787
  1187
  finally have le1: "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<le> 1" .
hoelzl@49787
  1188
  also have "\<dots> < \<infinity>" by simp
hoelzl@49787
  1189
  finally have fin: "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<noteq> \<infinity>" by simp
hoelzl@49787
  1190
hoelzl@49787
  1191
  have pos: "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<noteq> 0"
hoelzl@49787
  1192
    apply (subst positive_integral_density)
hoelzl@49787
  1193
    apply (rule distributed_borel_measurable[OF Pxyz])
hoelzl@49787
  1194
    apply (rule distributed_AE[OF Pxyz])
hoelzl@49787
  1195
    apply (auto simp add: borel_measurable_ereal_iff split_beta' intro!: M) []
hoelzl@49787
  1196
    apply (simp add: split_beta')
hoelzl@49787
  1197
  proof
hoelzl@49787
  1198
    let ?g = "\<lambda>x. ereal (if Pxyz x = 0 then 0 else Pxz (fst x, snd (snd x)) * Pyz (snd x) / Pz (snd (snd x)))"
hoelzl@49787
  1199
    assume "(\<integral>\<^isup>+ x. ?g x \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P)) = 0"
hoelzl@49787
  1200
    then have "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. ?g x \<le> 0"
hoelzl@49787
  1201
      by (intro positive_integral_0_iff_AE[THEN iffD1]) (auto intro!: M borel_measurable_ereal measurable_If)
hoelzl@49787
  1202
    then have "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pxyz x = 0"
hoelzl@49787
  1203
      using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49787
  1204
      by eventually_elim (auto split: split_if_asm simp: mult_le_0_iff divide_le_0_iff)
hoelzl@49787
  1205
    then have "(\<integral>\<^isup>+ x. ereal (Pxyz x) \<partial>S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) = 0"
hoelzl@49787
  1206
      by (subst positive_integral_cong_AE[of _ "\<lambda>x. 0"]) auto
hoelzl@49787
  1207
    with P.emeasure_space_1 show False
hoelzl@49787
  1208
      by (subst (asm) emeasure_density) (auto intro!: M cong: positive_integral_cong)
hoelzl@49787
  1209
  qed
hoelzl@49787
  1210
hoelzl@49787
  1211
  have neg: "(\<integral>\<^isup>+ x. - ?f x \<partial>?P) = 0"
hoelzl@49787
  1212
    apply (rule positive_integral_0_iff_AE[THEN iffD2])
hoelzl@49787
  1213
    apply (auto intro!: M simp: split_beta') []
hoelzl@49787
  1214
    apply (subst AE_density)
hoelzl@49787
  1215
    apply (auto intro!: M simp: split_beta') []
hoelzl@49787
  1216
    using ae5 ae6 ae7 ae8
hoelzl@49787
  1217
    apply eventually_elim
hoelzl@49787
  1218
    apply (auto intro!: mult_nonneg_nonneg divide_nonneg_nonneg)
hoelzl@49787
  1219
    done
hoelzl@49787
  1220
hoelzl@49787
  1221
  have I3: "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Pxz (x, z) * (Pyz (y,z) / Pz z))))"
hoelzl@49787
  1222
    apply (rule integrable_cong_AE[THEN iffD1, OF _ _ _ integral_diff(1)[OF I1 I2]])
hoelzl@49787
  1223
    using ae
hoelzl@49787
  1224
    apply (auto intro!: M simp: split_beta')
hoelzl@49787
  1225
    done
hoelzl@49787
  1226
hoelzl@49787
  1227
  have "- log b 1 \<le> - log b (integral\<^isup>L ?P ?f)"
hoelzl@49787
  1228
  proof (intro le_imp_neg_le log_le[OF b_gt_1])
hoelzl@49787
  1229
    show "0 < integral\<^isup>L ?P ?f"
hoelzl@49787
  1230
      using neg pos fin positive_integral_positive[of ?P ?f]
hoelzl@49787
  1231
      by (cases "(\<integral>\<^isup>+ x. ?f x \<partial>?P)") (auto simp add: lebesgue_integral_def less_le split_beta')
hoelzl@49787
  1232
    show "integral\<^isup>L ?P ?f \<le> 1"
hoelzl@49787
  1233
      using neg le1 fin positive_integral_positive[of ?P ?f]
hoelzl@49787
  1234
      by (cases "(\<integral>\<^isup>+ x. ?f x \<partial>?P)") (auto simp add: lebesgue_integral_def split_beta' one_ereal_def)
hoelzl@49787
  1235
  qed
hoelzl@49787
  1236
  also have "- log b (integral\<^isup>L ?P ?f) \<le> (\<integral> x. - log b (?f x) \<partial>?P)"
hoelzl@49787
  1237
  proof (rule P.jensens_inequality[where a=0 and b=1 and I="{0<..}"])
hoelzl@49787
  1238
    show "AE x in ?P. ?f x \<in> {0<..}"
hoelzl@49787
  1239
      unfolding AE_density[OF distributed_borel_measurable[OF Pxyz]]
hoelzl@49787
  1240
      using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49787
  1241
      by eventually_elim (auto simp: divide_pos_pos mult_pos_pos)
hoelzl@49787
  1242
    show "integrable ?P ?f"
hoelzl@49787
  1243
      unfolding integrable_def 
hoelzl@49787
  1244
      using fin neg by (auto intro!: M simp: split_beta')
hoelzl@49787
  1245
    show "integrable ?P (\<lambda>x. - log b (?f x))"
hoelzl@49787
  1246
      apply (subst integral_density)
hoelzl@49787
  1247
      apply (auto intro!: M) []
hoelzl@49787
  1248
      apply (auto intro!: M distributed_real_AE[OF Pxyz]) []
hoelzl@49787
  1249
      apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49787
  1250
      apply (rule integrable_cong_AE[THEN iffD1, OF _ _ _ I3])
hoelzl@49787
  1251
      apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49787
  1252
      apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49787
  1253
      using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49787
  1254
      apply eventually_elim
hoelzl@49787
  1255
      apply (auto simp: log_divide_eq log_mult_eq zero_le_mult_iff zero_less_mult_iff zero_less_divide_iff field_simps)
hoelzl@49787
  1256
      done
hoelzl@49787
  1257
  qed (auto simp: b_gt_1 minus_log_convex)
hoelzl@49787
  1258
  also have "\<dots> = conditional_mutual_information b S T P X Y Z"
hoelzl@49787
  1259
    unfolding `?eq`
hoelzl@49787
  1260
    apply (subst integral_density)
hoelzl@49787
  1261
    apply (auto intro!: M) []
hoelzl@49787
  1262
    apply (auto intro!: M distributed_real_AE[OF Pxyz]) []
hoelzl@49787
  1263
    apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49787
  1264
    apply (intro integral_cong_AE)
hoelzl@49787
  1265
    using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49787
  1266
    apply eventually_elim
hoelzl@49787
  1267
    apply (auto simp: log_divide_eq zero_less_mult_iff zero_less_divide_iff field_simps)
hoelzl@49787
  1268
    done
hoelzl@49787
  1269
  finally show ?nonneg
hoelzl@49787
  1270
    by simp
hoelzl@40859
  1271
qed
hoelzl@40859
  1272
hoelzl@49803
  1273
lemma (in information_space)
hoelzl@49803
  1274
  fixes Px :: "_ \<Rightarrow> real"
hoelzl@49803
  1275
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T" and P: "sigma_finite_measure P"
hoelzl@49803
  1276
  assumes Fx: "finite_entropy S X Px"
hoelzl@49803
  1277
  assumes Fz: "finite_entropy P Z Pz"
hoelzl@49803
  1278
  assumes Fyz: "finite_entropy (T \<Otimes>\<^isub>M P) (\<lambda>x. (Y x, Z x)) Pyz"
hoelzl@49803
  1279
  assumes Fxz: "finite_entropy (S \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Z x)) Pxz"
hoelzl@49803
  1280
  assumes Fxyz: "finite_entropy (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Y x, Z x)) Pxyz"
hoelzl@49803
  1281
  shows conditional_mutual_information_generic_eq': "conditional_mutual_information b S T P X Y Z
hoelzl@49803
  1282
    = (\<integral>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Pxz (x, z) * (Pyz (y,z) / Pz z))) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))" (is "?eq")
hoelzl@49803
  1283
    and conditional_mutual_information_generic_nonneg': "0 \<le> conditional_mutual_information b S T P X Y Z" (is "?nonneg")
hoelzl@49803
  1284
proof -
hoelzl@49803
  1285
  note Px = Fx[THEN finite_entropy_distributed]
hoelzl@49803
  1286
  note Pz = Fz[THEN finite_entropy_distributed]
hoelzl@49803
  1287
  note Pyz = Fyz[THEN finite_entropy_distributed]
hoelzl@49803
  1288
  note Pxz = Fxz[THEN finite_entropy_distributed]
hoelzl@49803
  1289
  note Pxyz = Fxyz[THEN finite_entropy_distributed]
hoelzl@49803
  1290
hoelzl@49803
  1291
  interpret S: sigma_finite_measure S by fact
hoelzl@49803
  1292
  interpret T: sigma_finite_measure T by fact
hoelzl@49803
  1293
  interpret P: sigma_finite_measure P by fact
hoelzl@49803
  1294
  interpret TP: pair_sigma_finite T P ..
hoelzl@49803
  1295
  interpret SP: pair_sigma_finite S P ..
hoelzl@49803
  1296
  interpret ST: pair_sigma_finite S T ..
hoelzl@49803
  1297
  interpret SPT: pair_sigma_finite "S \<Otimes>\<^isub>M P" T ..
hoelzl@49803
  1298
  interpret STP: pair_sigma_finite S "T \<Otimes>\<^isub>M P" ..
hoelzl@49803
  1299
  interpret TPS: pair_sigma_finite "T \<Otimes>\<^isub>M P" S ..
hoelzl@49803
  1300
  have TP: "sigma_finite_measure (T \<Otimes>\<^isub>M P)" ..
hoelzl@49803
  1301
  have SP: "sigma_finite_measure (S \<Otimes>\<^isub>M P)" ..
hoelzl@49803
  1302
  have YZ: "random_variable (T \<Otimes>\<^isub>M P) (\<lambda>x. (Y x, Z x))"
hoelzl@49803
  1303
    using Pyz by (simp add: distributed_measurable)
hoelzl@49803
  1304
hoelzl@49803
  1305
  have Pxyz_f: "\<And>M f. f \<in> measurable M (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) \<Longrightarrow> (\<lambda>x. Pxyz (f x)) \<in> borel_measurable M"
hoelzl@49803
  1306
    using measurable_comp[OF _ Pxyz[THEN distributed_real_measurable]] by (auto simp: comp_def)
hoelzl@49803
  1307
hoelzl@49803
  1308
  { fix f g h M
hoelzl@49803
  1309
    assume f: "f \<in> measurable M S" and g: "g \<in> measurable M P" and h: "h \<in> measurable M (S \<Otimes>\<^isub>M P)"
hoelzl@49803
  1310
    from measurable_comp[OF h Pxz[THEN distributed_real_measurable]]
hoelzl@49803
  1311
         measurable_comp[OF f Px[THEN distributed_real_measurable]]
hoelzl@49803
  1312
         measurable_comp[OF g Pz[THEN distributed_real_measurable]]
hoelzl@49803
  1313
    have "(\<lambda>x. log b (Pxz (h x) / (Px (f x) * Pz (g x)))) \<in> borel_measurable M"
hoelzl@49803
  1314
      by (simp add: comp_def b_gt_1) }
hoelzl@49803
  1315
  note borel_log = this
hoelzl@49803
  1316
hoelzl@49803
  1317
  have measurable_cut: "(\<lambda>(x, y, z). (x, z)) \<in> measurable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (S \<Otimes>\<^isub>M P)"
hoelzl@49803
  1318
    by (auto simp add: split_beta' comp_def intro!: measurable_Pair measurable_snd')
hoelzl@49803
  1319
  
hoelzl@49803
  1320
  from Pxz Pxyz have distr_eq: "distr M (S \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Z x)) =
hoelzl@49803
  1321
    distr (distr M (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Y x, Z x))) (S \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). (x, z))"
hoelzl@49803
  1322
    by (subst distr_distr[OF measurable_cut]) (auto dest: distributed_measurable simp: comp_def)
hoelzl@49803
  1323
hoelzl@49803
  1324
  have "mutual_information b S P X Z =
hoelzl@49803
  1325
    (\<integral>x. Pxz x * log b (Pxz x / (Px (fst x) * Pz (snd x))) \<partial>(S \<Otimes>\<^isub>M P))"
hoelzl@49803
  1326
    by (rule mutual_information_distr[OF S P Px Pz Pxz])
hoelzl@49803
  1327
  also have "\<dots> = (\<integral>(x,y,z). Pxyz (x,y,z) * log b (Pxz (x,z) / (Px x * Pz z)) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))"
hoelzl@49803
  1328
    using b_gt_1 Pxz Px Pz
hoelzl@49803
  1329
    by (subst distributed_transform_integral[OF Pxyz Pxz, where T="\<lambda>(x, y, z). (x, z)"])
hoelzl@49803
  1330
       (auto simp: split_beta' intro!: measurable_Pair measurable_snd' measurable_snd'' measurable_fst'' borel_measurable_times
hoelzl@49803
  1331
             dest!: distributed_real_measurable)
hoelzl@49803
  1332
  finally have mi_eq:
hoelzl@49803
  1333
    "mutual_information b S P X Z = (\<integral>(x,y,z). Pxyz (x,y,z) * log b (Pxz (x,z) / (Px x * Pz z)) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))" .
hoelzl@49803
  1334
  
hoelzl@49803
  1335
  have ae1: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Px (fst x) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@49803
  1336
    by (intro subdensity_real[of fst, OF _ Pxyz Px]) auto
hoelzl@49803
  1337
  moreover have ae2: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pz (snd (snd x)) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@49803
  1338
    by (intro subdensity_real[of "\<lambda>x. snd (snd x)", OF _ Pxyz Pz]) (auto intro: measurable_snd')
hoelzl@49803
  1339
  moreover have ae3: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pxz (fst x, snd (snd x)) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@49803
  1340
    by (intro subdensity_real[of "\<lambda>x. (fst x, snd (snd x))", OF _ Pxyz Pxz]) (auto intro: measurable_Pair measurable_snd')
hoelzl@49803
  1341
  moreover have ae4: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pyz (snd x) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@49803
  1342
    by (intro subdensity_real[of snd, OF _ Pxyz Pyz]) (auto intro: measurable_Pair)
hoelzl@49803
  1343
  moreover have ae5: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Px (fst x)"
hoelzl@49803
  1344
    using Px by (intro STP.AE_pair_measure) (auto simp: comp_def intro!: measurable_fst'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49803
  1345
  moreover have ae6: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Pyz (snd x)"
hoelzl@49803
  1346
    using Pyz by (intro STP.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49803
  1347
  moreover have ae7: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Pz (snd (snd x))"
hoelzl@49803
  1348
    using Pz Pz[THEN distributed_real_measurable] by (auto intro!: measurable_snd'' TP.AE_pair_measure STP.AE_pair_measure AE_I2[of S] dest: distributed_real_AE)
hoelzl@49803
  1349
  moreover have ae8: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Pxz (fst x, snd (snd x))"
hoelzl@49803
  1350
    using Pxz[THEN distributed_real_AE, THEN SP.AE_pair]
hoelzl@49803
  1351
    using measurable_comp[OF measurable_Pair[OF measurable_fst measurable_comp[OF measurable_snd measurable_snd]] Pxz[THEN distributed_real_measurable], of T]
hoelzl@49803
  1352
    using measurable_comp[OF measurable_snd measurable_Pair2[OF Pxz[THEN distributed_real_measurable]], of _ T]
hoelzl@49803
  1353
    by (auto intro!: TP.AE_pair_measure STP.AE_pair_measure simp: comp_def)
hoelzl@49803
  1354
  moreover note ae9 = Pxyz[THEN distributed_real_AE]
hoelzl@49803
  1355
  ultimately have ae: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P.
hoelzl@49803
  1356
    Pxyz x * log b (Pxyz x / (Px (fst x) * Pyz (snd x))) -
hoelzl@49803
  1357
    Pxyz x * log b (Pxz (fst x, snd (snd x)) / (Px (fst x) * Pz (snd (snd x)))) =
hoelzl@49803
  1358
    Pxyz x * log b (Pxyz x * Pz (snd (snd x)) / (Pxz (fst x, snd (snd x)) * Pyz (snd x))) "
hoelzl@49803
  1359
  proof eventually_elim
hoelzl@49803
  1360
    case (goal1 x)
hoelzl@49803
  1361
    show ?case
hoelzl@49803
  1362
    proof cases
hoelzl@49803
  1363
      assume "Pxyz x \<noteq> 0"
hoelzl@49803
  1364
      with goal1 have "0 < Px (fst x)" "0 < Pz (snd (snd x))" "0 < Pxz (fst x, snd (snd x))" "0 < Pyz (snd x)" "0 < Pxyz x"
hoelzl@49803
  1365
        by auto
hoelzl@49803
  1366
      then show ?thesis
hoelzl@49803
  1367
        using b_gt_1 by (simp add: log_simps mult_pos_pos less_imp_le field_simps)
hoelzl@49803
  1368
    qed simp
hoelzl@49803
  1369
  qed
hoelzl@49803
  1370
hoelzl@49803
  1371
  have "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P)
hoelzl@49803
  1372
    (\<lambda>x. Pxyz x * log b (Pxyz x) - Pxyz x * log b (Px (fst x)) - Pxyz x * log b (Pyz (snd x)))"
hoelzl@49803
  1373
    using finite_entropy_integrable[OF Fxyz]
hoelzl@49803
  1374
    using finite_entropy_integrable_transform[OF Fx Pxyz, of fst]
hoelzl@49803
  1375
    using finite_entropy_integrable_transform[OF Fyz Pxyz, of snd]
hoelzl@49803
  1376
    by simp
hoelzl@49803
  1377
  moreover have "(\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Px x * Pyz (y, z)))) \<in> borel_measurable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P)"
hoelzl@49803
  1378
    using Pxyz Px Pyz
hoelzl@49803
  1379
    by (auto intro!: borel_measurable_times measurable_fst'' measurable_snd'' dest!: distributed_real_measurable simp: split_beta')
hoelzl@49803
  1380
  ultimately have I1: "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Px x * Pyz (y, z))))"
hoelzl@49803
  1381
    apply (rule integrable_cong_AE_imp)
hoelzl@49803
  1382
    using ae1 ae4 ae5 ae6 ae9
hoelzl@49803
  1383
    by eventually_elim
hoelzl@49803
  1384
       (auto simp: log_divide_eq log_mult_eq mult_nonneg_nonneg field_simps zero_less_mult_iff)
hoelzl@49803
  1385
hoelzl@49803
  1386
  have "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P)
hoelzl@49803
  1387
    (\<lambda>x. Pxyz x * log b (Pxz (fst x, snd (snd x))) - Pxyz x * log b (Px (fst x)) - Pxyz x * log b (Pz (snd (snd x))))"
hoelzl@49803
  1388
    using finite_entropy_integrable_transform[OF Fxz Pxyz, of "\<lambda>x. (fst x, snd (snd x))"]
hoelzl@49803
  1389
    using finite_entropy_integrable_transform[OF Fx Pxyz, of fst]
hoelzl@49803
  1390
    using finite_entropy_integrable_transform[OF Fz Pxyz, of "snd \<circ> snd"]
hoelzl@49803
  1391
    by (simp add: measurable_Pair measurable_snd'' comp_def)
hoelzl@49803
  1392
  moreover have "(\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxz (x, z) / (Px x * Pz z))) \<in> borel_measurable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P)"
hoelzl@49803
  1393
    using Pxyz Px Pz
hoelzl@49803
  1394
    by (auto intro!: measurable_compose[OF _ distributed_real_measurable[OF Pxz]]
hoelzl@49803
  1395
                     measurable_Pair borel_measurable_times measurable_fst'' measurable_snd''
hoelzl@49803
  1396
             dest!: distributed_real_measurable simp: split_beta')
hoelzl@49803
  1397
  ultimately have I2: "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxz (x, z) / (Px x * Pz z)))"
hoelzl@49803
  1398
    apply (rule integrable_cong_AE_imp)
hoelzl@49803
  1399
    using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 ae9
hoelzl@49803
  1400
    by eventually_elim
hoelzl@49803
  1401
       (auto simp: log_divide_eq log_mult_eq mult_nonneg_nonneg field_simps zero_less_mult_iff)
hoelzl@49803
  1402
hoelzl@49803
  1403
  from ae I1 I2 show ?eq
hoelzl@49803
  1404
    unfolding conditional_mutual_information_def
hoelzl@49803
  1405
    apply (subst mi_eq)
hoelzl@49803
  1406
    apply (subst mutual_information_distr[OF S TP Px Pyz Pxyz])
hoelzl@49803
  1407
    apply (subst integral_diff(2)[symmetric])
hoelzl@49803
  1408
    apply (auto intro!: integral_cong_AE simp: split_beta' simp del: integral_diff)
hoelzl@49803
  1409
    done
hoelzl@49803
  1410
hoelzl@49803
  1411
  let ?P = "density (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) Pxyz"
hoelzl@49803
  1412
  interpret P: prob_space ?P
hoelzl@49803
  1413
    unfolding distributed_distr_eq_density[OF Pxyz, symmetric]
hoelzl@49803
  1414
    using distributed_measurable[OF Pxyz] by (rule prob_space_distr)
hoelzl@49803
  1415
hoelzl@49803
  1416
  let ?Q = "density (T \<Otimes>\<^isub>M P) Pyz"
hoelzl@49803
  1417
  interpret Q: prob_space ?Q
hoelzl@49803
  1418
    unfolding distributed_distr_eq_density[OF Pyz, symmetric]
hoelzl@49803
  1419
    using distributed_measurable[OF Pyz] by (rule prob_space_distr)
hoelzl@49803
  1420
hoelzl@49803
  1421
  let ?f = "\<lambda>(x, y, z). Pxz (x, z) * (Pyz (y, z) / Pz z) / Pxyz (x, y, z)"
hoelzl@49803
  1422
hoelzl@49803
  1423
  from subdensity_real[of snd, OF _ Pyz Pz]
hoelzl@49803
  1424
  have aeX1: "AE x in T \<Otimes>\<^isub>M P. Pz (snd x) = 0 \<longrightarrow> Pyz x = 0" by (auto simp: comp_def)
hoelzl@49803
  1425
  have aeX2: "AE x in T \<Otimes>\<^isub>M P. 0 \<le> Pz (snd x)"
hoelzl@49803
  1426
    using Pz by (intro TP.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49803
  1427
hoelzl@49803
  1428
  have aeX3: "AE y in T \<Otimes>\<^isub>M P. (\<integral>\<^isup>+ x. ereal (Pxz (x, snd y)) \<partial>S) = ereal (Pz (snd y))"
hoelzl@49803
  1429
    using Pz distributed_marginal_eq_joint2[OF P S Pz Pxz]
hoelzl@49803
  1430
    apply (intro TP.AE_pair_measure)
hoelzl@49803
  1431
    apply (auto simp: comp_def measurable_split_conv
hoelzl@49803
  1432
                intro!: measurable_snd'' borel_measurable_ereal_eq borel_measurable_ereal
hoelzl@49803
  1433
                        SP.borel_measurable_positive_integral_snd measurable_compose[OF _ Pxz[THEN distributed_real_measurable]]
hoelzl@49803
  1434
                        measurable_Pair
hoelzl@49803
  1435
                dest: distributed_real_AE distributed_real_measurable)
hoelzl@49803
  1436
    done
hoelzl@49803
  1437
hoelzl@49803
  1438
  note M = borel_measurable_divide borel_measurable_diff borel_measurable_times borel_measurable_ereal
hoelzl@49803
  1439
           measurable_compose[OF _ measurable_snd]
hoelzl@49803
  1440
           measurable_Pair
hoelzl@49803
  1441
           measurable_compose[OF _ Pxyz[THEN distributed_real_measurable]]
hoelzl@49803
  1442
           measurable_compose[OF _ Pxz[THEN distributed_real_measurable]]
hoelzl@49803
  1443
           measurable_compose[OF _ Pyz[THEN distributed_real_measurable]]
hoelzl@49803
  1444
           measurable_compose[OF _ Pz[THEN distributed_real_measurable]]
hoelzl@49803
  1445
           measurable_compose[OF _ Px[THEN distributed_real_measurable]]
hoelzl@49803
  1446
           STP.borel_measurable_positive_integral_snd
hoelzl@49803
  1447
  have "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<le> (\<integral>\<^isup>+ (x, y, z). Pxz (x, z) * (Pyz (y, z) / Pz z) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))"
hoelzl@49803
  1448
    apply (subst positive_integral_density)
hoelzl@49803
  1449
    apply (rule distributed_borel_measurable[OF Pxyz])
hoelzl@49803
  1450
    apply (rule distributed_AE[OF Pxyz])
hoelzl@49803
  1451
    apply (auto simp add: borel_measurable_ereal_iff split_beta' intro!: M) []
hoelzl@49803
  1452
    apply (rule positive_integral_mono_AE)
hoelzl@49803
  1453
    using ae5 ae6 ae7 ae8
hoelzl@49803
  1454
    apply eventually_elim
hoelzl@49803
  1455
    apply (auto intro!: divide_nonneg_nonneg mult_nonneg_nonneg)
hoelzl@49803
  1456
    done
hoelzl@49803
  1457
  also have "\<dots> = (\<integral>\<^isup>+(y, z). \<integral>\<^isup>+ x. ereal (Pxz (x, z)) * ereal (Pyz (y, z) / Pz z) \<partial>S \<partial>T \<Otimes>\<^isub>M P)"
hoelzl@49803
  1458
    by (subst STP.positive_integral_snd_measurable[symmetric])
hoelzl@49803
  1459
       (auto simp add: borel_measurable_ereal_iff split_beta' intro!: M)
hoelzl@49803
  1460
  also have "\<dots> = (\<integral>\<^isup>+x. ereal (Pyz x) * 1 \<partial>T \<Otimes>\<^isub>M P)"
hoelzl@49803
  1461
    apply (rule positive_integral_cong_AE)
hoelzl@49803
  1462
    using aeX1 aeX2 aeX3 distributed_AE[OF Pyz] AE_space
hoelzl@49803
  1463
    apply eventually_elim
hoelzl@49803
  1464
  proof (case_tac x, simp del: times_ereal.simps add: space_pair_measure)
hoelzl@49803
  1465
    fix a b assume "Pz b = 0 \<longrightarrow> Pyz (a, b) = 0" "0 \<le> Pz b" "a \<in> space T \<and> b \<in> space P"
hoelzl@49803
  1466
      "(\<integral>\<^isup>+ x. ereal (Pxz (x, b)) \<partial>S) = ereal (Pz b)" "0 \<le> Pyz (a, b)" 
hoelzl@49803
  1467
    then show "(\<integral>\<^isup>+ x. ereal (Pxz (x, b)) * ereal (Pyz (a, b) / Pz b) \<partial>S) = ereal (Pyz (a, b))"
hoelzl@49803
  1468
      apply (subst positive_integral_multc)
hoelzl@49803
  1469
      apply (auto intro!: borel_measurable_ereal divide_nonneg_nonneg
hoelzl@49803
  1470
                          measurable_compose[OF _ Pxz[THEN distributed_real_measurable]] measurable_Pair
hoelzl@49803
  1471
                  split: prod.split)
hoelzl@49803
  1472
      done
hoelzl@49803
  1473
  qed
hoelzl@49803
  1474
  also have "\<dots> = 1"
hoelzl@49803
  1475
    using Q.emeasure_space_1 distributed_AE[OF Pyz] distributed_distr_eq_density[OF Pyz]
hoelzl@49803
  1476
    by (subst positive_integral_density[symmetric]) (auto intro!: M)
hoelzl@49803
  1477
  finally have le1: "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<le> 1" .
hoelzl@49803
  1478
  also have "\<dots> < \<infinity>" by simp
hoelzl@49803
  1479
  finally have fin: "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<noteq> \<infinity>" by simp
hoelzl@49803
  1480
hoelzl@49803
  1481
  have pos: "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<noteq> 0"
hoelzl@49803
  1482
    apply (subst positive_integral_density)
hoelzl@49803
  1483
    apply (rule distributed_borel_measurable[OF Pxyz])
hoelzl@49803
  1484
    apply (rule distributed_AE[OF Pxyz])
hoelzl@49803
  1485
    apply (auto simp add: borel_measurable_ereal_iff split_beta' intro!: M) []
hoelzl@49803
  1486
    apply (simp add: split_beta')
hoelzl@49803
  1487
  proof
hoelzl@49803
  1488
    let ?g = "\<lambda>x. ereal (if Pxyz x = 0 then 0 else Pxz (fst x, snd (snd x)) * Pyz (snd x) / Pz (snd (snd x)))"
hoelzl@49803
  1489
    assume "(\<integral>\<^isup>+ x. ?g x \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P)) = 0"
hoelzl@49803
  1490
    then have "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. ?g x \<le> 0"
hoelzl@49803
  1491
      by (intro positive_integral_0_iff_AE[THEN iffD1]) (auto intro!: M borel_measurable_ereal measurable_If)
hoelzl@49803
  1492
    then have "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pxyz x = 0"
hoelzl@49803
  1493
      using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49803
  1494
      by eventually_elim (auto split: split_if_asm simp: mult_le_0_iff divide_le_0_iff)
hoelzl@49803
  1495
    then have "(\<integral>\<^isup>+ x. ereal (Pxyz x) \<partial>S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) = 0"
hoelzl@49803
  1496
      by (subst positive_integral_cong_AE[of _ "\<lambda>x. 0"]) auto
hoelzl@49803
  1497
    with P.emeasure_space_1 show False
hoelzl@49803
  1498
      by (subst (asm) emeasure_density) (auto intro!: M cong: positive_integral_cong)
hoelzl@49803
  1499
  qed
hoelzl@49803
  1500
hoelzl@49803
  1501
  have neg: "(\<integral>\<^isup>+ x. - ?f x \<partial>?P) = 0"
hoelzl@49803
  1502
    apply (rule positive_integral_0_iff_AE[THEN iffD2])
hoelzl@49803
  1503
    apply (auto intro!: M simp: split_beta') []
hoelzl@49803
  1504
    apply (subst AE_density)
hoelzl@49803
  1505
    apply (auto intro!: M simp: split_beta') []
hoelzl@49803
  1506
    using ae5 ae6 ae7 ae8
hoelzl@49803
  1507
    apply eventually_elim
hoelzl@49803
  1508
    apply (auto intro!: mult_nonneg_nonneg divide_nonneg_nonneg)
hoelzl@49803
  1509
    done
hoelzl@49803
  1510
hoelzl@49803
  1511
  have I3: "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Pxz (x, z) * (Pyz (y,z) / Pz z))))"
hoelzl@49803
  1512
    apply (rule integrable_cong_AE[THEN iffD1, OF _ _ _ integral_diff(1)[OF I1 I2]])
hoelzl@49803
  1513
    using ae
hoelzl@49803
  1514
    apply (auto intro!: M simp: split_beta')
hoelzl@49803
  1515
    done
hoelzl@49803
  1516
hoelzl@49803
  1517
  have "- log b 1 \<le> - log b (integral\<^isup>L ?P ?f)"
hoelzl@49803
  1518
  proof (intro le_imp_neg_le log_le[OF b_gt_1])
hoelzl@49803
  1519
    show "0 < integral\<^isup>L ?P ?f"
hoelzl@49803
  1520
      using neg pos fin positive_integral_positive[of ?P ?f]
hoelzl@49803
  1521
      by (cases "(\<integral>\<^isup>+ x. ?f x \<partial>?P)") (auto simp add: lebesgue_integral_def less_le split_beta')
hoelzl@49803
  1522
    show "integral\<^isup>L ?P ?f \<le> 1"
hoelzl@49803
  1523
      using neg le1 fin positive_integral_positive[of ?P ?f]
hoelzl@49803
  1524
      by (cases "(\<integral>\<^isup>+ x. ?f x \<partial>?P)") (auto simp add: lebesgue_integral_def split_beta' one_ereal_def)
hoelzl@49803
  1525
  qed
hoelzl@49803
  1526
  also have "- log b (integral\<^isup>L ?P ?f) \<le> (\<integral> x. - log b (?f x) \<partial>?P)"
hoelzl@49803
  1527
  proof (rule P.jensens_inequality[where a=0 and b=1 and I="{0<..}"])
hoelzl@49803
  1528
    show "AE x in ?P. ?f x \<in> {0<..}"
hoelzl@49803
  1529
      unfolding AE_density[OF distributed_borel_measurable[OF Pxyz]]
hoelzl@49803
  1530
      using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49803
  1531
      by eventually_elim (auto simp: divide_pos_pos mult_pos_pos)
hoelzl@49803
  1532
    show "integrable ?P ?f"
hoelzl@49803
  1533
      unfolding integrable_def 
hoelzl@49803
  1534
      using fin neg by (auto intro!: M simp: split_beta')
hoelzl@49803
  1535
    show "integrable ?P (\<lambda>x. - log b (?f x))"
hoelzl@49803
  1536
      apply (subst integral_density)
hoelzl@49803
  1537
      apply (auto intro!: M) []
hoelzl@49803
  1538
      apply (auto intro!: M distributed_real_AE[OF Pxyz]) []
hoelzl@49803
  1539
      apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49803
  1540
      apply (rule integrable_cong_AE[THEN iffD1, OF _ _ _ I3])
hoelzl@49803
  1541
      apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49803
  1542
      apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49803
  1543
      using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49803
  1544
      apply eventually_elim
hoelzl@49803
  1545
      apply (auto simp: log_divide_eq log_mult_eq zero_le_mult_iff zero_less_mult_iff zero_less_divide_iff field_simps)
hoelzl@49803
  1546
      done
hoelzl@49803
  1547
  qed (auto simp: b_gt_1 minus_log_convex)
hoelzl@49803
  1548
  also have "\<dots> = conditional_mutual_information b S T P X Y Z"
hoelzl@49803
  1549
    unfolding `?eq`
hoelzl@49803
  1550
    apply (subst integral_density)
hoelzl@49803
  1551
    apply (auto intro!: M) []
hoelzl@49803
  1552
    apply (auto intro!: M distributed_real_AE[OF Pxyz]) []
hoelzl@49803
  1553
    apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49803
  1554
    apply (intro integral_cong_AE)
hoelzl@49803
  1555
    using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49803
  1556
    apply eventually_elim
hoelzl@49803
  1557
    apply (auto simp: log_divide_eq zero_less_mult_iff zero_less_divide_iff field_simps)
hoelzl@49803
  1558
    done
hoelzl@49803
  1559
  finally show ?nonneg
hoelzl@49803
  1560
    by simp
hoelzl@49803
  1561
qed
hoelzl@49803
  1562
hoelzl@40859
  1563
lemma (in information_space) conditional_mutual_information_eq:
hoelzl@47694
  1564
  assumes Pz: "simple_distributed M Z Pz"
hoelzl@47694
  1565
  assumes Pyz: "simple_distributed M (\<lambda>x. (Y x, Z x)) Pyz"
hoelzl@47694
  1566
  assumes Pxz: "simple_distributed M (\<lambda>x. (X x, Z x)) Pxz"
hoelzl@47694
  1567
  assumes Pxyz: "simple_distributed M (\<lambda>x. (X x, Y x, Z x)) Pxyz"
hoelzl@47694
  1568
  shows "\<I>(X ; Y | Z) =
hoelzl@47694
  1569
   (\<Sum>(x, y, z)\<in>(\<lambda>x. (X x, Y x, Z x))`space M. Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Pxz (x, z) * (Pyz (y,z) / Pz z))))"
hoelzl@47694
  1570
proof (subst conditional_mutual_information_generic_eq[OF _ _ _ _
hoelzl@47694
  1571
    simple_distributed[OF Pz] simple_distributed_joint[OF Pyz] simple_distributed_joint[OF Pxz]
hoelzl@47694
  1572
    simple_distributed_joint2[OF Pxyz]])
hoelzl@47694
  1573
  note simple_distributed_joint2_finite[OF Pxyz, simp]
hoelzl@47694
  1574
  show "sigma_finite_measure (count_space (X ` space M))"
hoelzl@47694
  1575
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1576
  show "sigma_finite_measure (count_space (Y ` space M))"
hoelzl@47694
  1577
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1578
  show "sigma_finite_measure (count_space (Z ` space M))"
hoelzl@47694
  1579
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1580
  have "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) \<Otimes>\<^isub>M count_space (Z ` space M) =
hoelzl@47694
  1581
      count_space (X`space M \<times> Y`space M \<times> Z`space M)"
hoelzl@47694
  1582
    (is "?P = ?C")
hoelzl@47694
  1583
    by (simp add: pair_measure_count_space)
hoelzl@40859
  1584
hoelzl@47694
  1585
  let ?Px = "\<lambda>x. measure M (X -` {x} \<inter> space M)"
hoelzl@47694
  1586
  have "(\<lambda>x. (X x, Z x)) \<in> measurable M (count_space (X ` space M) \<Otimes>\<^isub>M count_space (Z ` space M))"
hoelzl@47694
  1587
    using simple_distributed_joint[OF Pxz] by (rule distributed_measurable)
hoelzl@47694
  1588
  from measurable_comp[OF this measurable_fst]
hoelzl@47694
  1589
  have "random_variable (count_space (X ` space M)) X"
hoelzl@47694
  1590
    by (simp add: comp_def)
hoelzl@47694
  1591
  then have "simple_function M X"    
hoelzl@47694
  1592
    unfolding simple_function_def by auto
hoelzl@47694
  1593
  then have "simple_distributed M X ?Px"
hoelzl@47694
  1594
    by (rule simple_distributedI) auto
hoelzl@47694
  1595
  then show "distributed M (count_space (X ` space M)) X ?Px"
hoelzl@47694
  1596
    by (rule simple_distributed)
hoelzl@47694
  1597
hoelzl@47694
  1598
  let ?f = "(\<lambda>x. if x \<in> (\<lambda>x. (X x, Y x, Z x)) ` space M then Pxyz x else 0)"
hoelzl@47694
  1599
  let ?g = "(\<lambda>x. if x \<in> (\<lambda>x. (Y x, Z x)) ` space M then Pyz x else 0)"
hoelzl@47694
  1600
  let ?h = "(\<lambda>x. if x \<in> (\<lambda>x. (X x, Z x)) ` space M then Pxz x else 0)"
hoelzl@47694
  1601
  show
hoelzl@47694
  1602
      "integrable ?P (\<lambda>(x, y, z). ?f (x, y, z) * log b (?f (x, y, z) / (?Px x * ?g (y, z))))"
hoelzl@47694
  1603
      "integrable ?P (\<lambda>(x, y, z). ?f (x, y, z) * log b (?h (x, z) / (?Px x * Pz z)))"
hoelzl@47694
  1604
    by (auto intro!: integrable_count_space simp: pair_measure_count_space)
hoelzl@47694
  1605
  let ?i = "\<lambda>x y z. ?f (x, y, z) * log b (?f (x, y, z) / (?h (x, z) * (?g (y, z) / Pz z)))"
hoelzl@47694
  1606
  let ?j = "\<lambda>x y z. Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Pxz (x, z) * (Pyz (y,z) / Pz z)))"
hoelzl@47694
  1607
  have "(\<lambda>(x, y, z). ?i x y z) = (\<lambda>x. if x \<in> (\<lambda>x. (X x, Y x, Z x)) ` space M then ?j (fst x) (fst (snd x)) (snd (snd x)) else 0)"
hoelzl@47694
  1608
    by (auto intro!: ext)
hoelzl@47694
  1609
  then show "(\<integral> (x, y, z). ?i x y z \<partial>?P) = (\<Sum>(x, y, z)\<in>(\<lambda>x. (X x, Y x, Z x)) ` space M. ?j x y z)"
hoelzl@47694
  1610
    by (auto intro!: setsum_cong simp add: `?P = ?C` lebesgue_integral_count_space_finite simple_distributed_finite setsum_cases split_beta')
hoelzl@36624
  1611
qed
hoelzl@36624
  1612
hoelzl@47694
  1613
lemma (in information_space) conditional_mutual_information_nonneg:
hoelzl@47694
  1614
  assumes X: "simple_function M X" and Y: "simple_function M Y" and Z: "simple_function M Z"
hoelzl@47694
  1615
  shows "0 \<le> \<I>(X ; Y | Z)"
hoelzl@47694
  1616
proof -
hoelzl@49787
  1617
  have [simp]: "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) \<Otimes>\<^isub>M count_space (Z ` space M) =
hoelzl@49787
  1618
      count_space (X`space M \<times> Y`space M \<times> Z`space M)"
hoelzl@49787
  1619
    by (simp add: pair_measure_count_space X Y Z simple_functionD)
hoelzl@49787
  1620
  note sf = sigma_finite_measure_count_space_finite[OF simple_functionD(1)]
hoelzl@49787
  1621
  note sd = simple_distributedI[OF _ refl]
hoelzl@49787
  1622
  note sp = simple_function_Pair
hoelzl@49787
  1623
  show ?thesis
hoelzl@49787
  1624
   apply (rule conditional_mutual_information_generic_nonneg[OF sf[OF X] sf[OF Y] sf[OF Z]])
hoelzl@49787
  1625
   apply (rule simple_distributed[OF sd[OF X]])
hoelzl@49787
  1626
   apply (rule simple_distributed[OF sd[OF Z]])
hoelzl@49787
  1627
   apply (rule simple_distributed_joint[OF sd[OF sp[OF Y Z]]])
hoelzl@49787
  1628
   apply (rule simple_distributed_joint[OF sd[OF sp[OF X Z]]])
hoelzl@49787
  1629
   apply (rule simple_distributed_joint2[OF sd[OF sp[OF X sp[OF Y Z]]]])
hoelzl@49787
  1630
   apply (auto intro!: integrable_count_space simp: X Y Z simple_functionD)
hoelzl@49787
  1631
   done
hoelzl@36080
  1632
qed
hoelzl@36080
  1633
hoelzl@39097
  1634
subsection {* Conditional Entropy *}
hoelzl@39097
  1635
hoelzl@36080
  1636
definition (in prob_space)
hoelzl@49791
  1637
  "conditional_entropy b S T X Y = - (\<integral>(x, y). log b (real (RN_deriv (S \<Otimes>\<^isub>M T) (distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))) (x, y)) / 
hoelzl@49791
  1638
    real (RN_deriv T (distr M T Y) y)) \<partial>distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)))"
hoelzl@36080
  1639
hoelzl@40859
  1640
abbreviation (in information_space)
hoelzl@40859
  1641
  conditional_entropy_Pow ("\<H>'(_ | _')") where
hoelzl@47694
  1642
  "\<H>(X | Y) \<equiv> conditional_entropy b (count_space (X`space M)) (count_space (Y`space M)) X Y"
hoelzl@36080
  1643
hoelzl@49791
  1644
lemma (in information_space) conditional_entropy_generic_eq:
hoelzl@49791
  1645
  fixes Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@49791
  1646
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
hoelzl@49791
  1647
  assumes Py: "distributed M T Y Py"
hoelzl@49791
  1648
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@49791
  1649
  shows "conditional_entropy b S T X Y = - (\<integral>(x, y). Pxy (x, y) * log b (Pxy (x, y) / Py y) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@49791
  1650
proof -
hoelzl@49791
  1651
  interpret S: sigma_finite_measure S by fact
hoelzl@49791
  1652
  interpret T: sigma_finite_measure T by fact
hoelzl@49791
  1653
  interpret ST: pair_sigma_finite S T ..
hoelzl@49791
  1654
hoelzl@49791
  1655
  have "AE x in density (S \<Otimes>\<^isub>M T) (\<lambda>x. ereal (Pxy x)). Pxy x = real (RN_deriv (S \<Otimes>\<^isub>M T) (distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))) x)"
hoelzl@49791
  1656
    unfolding AE_density[OF distributed_borel_measurable, OF Pxy]
hoelzl@49791
  1657
    unfolding distributed_distr_eq_density[OF Pxy]
hoelzl@49791
  1658
    using distributed_RN_deriv[OF Pxy]
hoelzl@49791
  1659
    by auto
hoelzl@49791
  1660
  moreover
hoelzl@49791
  1661
  have "AE x in density (S \<Otimes>\<^isub>M T) (\<lambda>x. ereal (Pxy x)). Py (snd x) = real (RN_deriv T (distr M T Y) (snd x))"
hoelzl@49791
  1662
    unfolding AE_density[OF distributed_borel_measurable, OF Pxy]
hoelzl@49791
  1663
    unfolding distributed_distr_eq_density[OF Py]
hoelzl@49791
  1664
    apply (rule ST.AE_pair_measure)
hoelzl@49791
  1665
    apply (auto intro!: sets_Collect borel_measurable_eq measurable_compose[OF _ distributed_real_measurable[OF Py]]
hoelzl@49791
  1666
                        distributed_real_measurable[OF Pxy] distributed_real_AE[OF Py]
hoelzl@49791
  1667
                        borel_measurable_real_of_ereal measurable_compose[OF _ borel_measurable_RN_deriv_density])
hoelzl@49791
  1668
    using distributed_RN_deriv[OF Py]
hoelzl@49791
  1669
    apply auto
hoelzl@49791
  1670
    done    
hoelzl@49791
  1671
  ultimately
hoelzl@49791
  1672
  have "conditional_entropy b S T X Y = - (\<integral>x. Pxy x * log b (Pxy x / Py (snd x)) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@49791
  1673
    unfolding conditional_entropy_def neg_equal_iff_equal
hoelzl@49791
  1674
    apply (subst integral_density(1)[symmetric])
hoelzl@49791
  1675
    apply (auto simp: distributed_real_measurable[OF Pxy] distributed_real_AE[OF Pxy]
hoelzl@49791
  1676
                      measurable_compose[OF _ distributed_real_measurable[OF Py]]
hoelzl@49791
  1677
                      distributed_distr_eq_density[OF Pxy]
hoelzl@49791
  1678
                intro!: integral_cong_AE)
hoelzl@49791
  1679
    done
hoelzl@49791
  1680
  then show ?thesis by (simp add: split_beta')
hoelzl@49791
  1681
qed
hoelzl@49791
  1682
hoelzl@49791
  1683
lemma (in information_space) conditional_entropy_eq_entropy:
hoelzl@47694
  1684
  fixes Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@47694
  1685
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
hoelzl@47694
  1686
  assumes Py: "distributed M T Y Py"
hoelzl@47694
  1687
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
  1688
  assumes I1: "integrable (S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Pxy x))"
hoelzl@47694
  1689
  assumes I2: "integrable (S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Py (snd x)))"
hoelzl@49791
  1690
  shows "conditional_entropy b S T X Y = entropy b (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) - entropy b T Y"
hoelzl@40859
  1691
proof -
hoelzl@47694
  1692
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
  1693
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
  1694
  interpret ST: pair_sigma_finite S T ..
hoelzl@47694
  1695
hoelzl@47694
  1696
  have "entropy b T Y = - (\<integral>y. Py y * log b (Py y) \<partial>T)"
hoelzl@49786
  1697
    by (rule entropy_distr[OF Py])
hoelzl@47694
  1698
  also have "\<dots> = - (\<integral>(x,y). Pxy (x,y) * log b (Py y) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@47694
  1699
    using b_gt_1 Py[THEN distributed_real_measurable]
hoelzl@47694
  1700
    by (subst distributed_transform_integral[OF Pxy Py, where T=snd]) (auto intro!: integral_cong)
hoelzl@47694
  1701
  finally have e_eq: "entropy b T Y = - (\<integral>(x,y). Pxy (x,y) * log b (Py y) \<partial>(S \<Otimes>\<^isub>M T))" .
hoelzl@49791
  1702
hoelzl@49790
  1703
  have ae2: "AE x in S \<Otimes>\<^isub>M T. Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
  1704
    by (intro subdensity_real[of snd, OF _ Pxy Py]) (auto intro: measurable_Pair)
hoelzl@49788
  1705
  moreover have ae4: "AE x in S \<Otimes>\<^isub>M T. 0 \<le> Py (snd x)"
hoelzl@47694
  1706
    using Py by (intro ST.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49788
  1707
  moreover note ae5 = Pxy[THEN distributed_real_AE]
hoelzl@49791
  1708
  ultimately have "AE x in S \<Otimes>\<^isub>M T. 0 \<le> Pxy x \<and> 0 \<le> Py (snd x) \<and>
hoelzl@49790
  1709
    (Pxy x = 0 \<or> (Pxy x \<noteq> 0 \<longrightarrow> 0 < Pxy x \<and> 0 < Py (snd x)))"
hoelzl@47694
  1710
    by eventually_elim auto
hoelzl@49791
  1711
  then have ae: "AE x in S \<Otimes>\<^isub>M T.
hoelzl@47694
  1712
     Pxy x * log b (Pxy x) - Pxy x * log b (Py (snd x)) = Pxy x * log b (Pxy x / Py (snd x))"
hoelzl@47694
  1713
    by eventually_elim (auto simp: log_simps mult_pos_pos field_simps b_gt_1)
hoelzl@49791
  1714
  have "conditional_entropy b S T X Y = 
hoelzl@49791
  1715
    - (\<integral>x. Pxy x * log b (Pxy x) - Pxy x * log b (Py (snd x)) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@49791
  1716
    unfolding conditional_entropy_generic_eq[OF S T Py Pxy] neg_equal_iff_equal
hoelzl@49791
  1717
    apply (intro integral_cong_AE)
hoelzl@49791
  1718
    using ae
hoelzl@49791
  1719
    apply eventually_elim
hoelzl@49791
  1720
    apply auto
hoelzl@47694
  1721
    done
hoelzl@49791
  1722
  also have "\<dots> = - (\<integral>x. Pxy x * log b (Pxy x) \<partial>(S \<Otimes>\<^isub>M T)) - - (\<integral>x.  Pxy x * log b (Py (snd x)) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@49791
  1723
    by (simp add: integral_diff[OF I1 I2])
hoelzl@49791
  1724
  finally show ?thesis 
hoelzl@49791
  1725
    unfolding conditional_entropy_generic_eq[OF S T Py Pxy] entropy_distr[OF Pxy] e_eq
hoelzl@49791
  1726
    by (simp add: split_beta')
hoelzl@49791
  1727
qed
hoelzl@49791
  1728
hoelzl@49791
  1729
lemma (in information_space) conditional_entropy_eq_entropy_simple:
hoelzl@49791
  1730
  assumes X: "simple_function M X" and Y: "simple_function M Y"
hoelzl@49791
  1731
  shows "\<H>(X | Y) = entropy b (count_space (X`space M) \<Otimes>\<^isub>M count_space (Y`space M)) (\<lambda>x. (X x, Y x)) - \<H>(Y)"
hoelzl@49791
  1732
proof -
hoelzl@49791
  1733
  have "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) = count_space (X`space M \<times> Y`space M)"
hoelzl@49791
  1734
    (is "?P = ?C") using X Y by (simp add: simple_functionD pair_measure_count_space)
hoelzl@49791
  1735
  show ?thesis
hoelzl@49791
  1736
    by (rule conditional_entropy_eq_entropy sigma_finite_measure_count_space_finite
hoelzl@49791
  1737
                 simple_functionD  X Y simple_distributed simple_distributedI[OF _ refl]
hoelzl@49791
  1738
                 simple_distributed_joint simple_function_Pair integrable_count_space)+
hoelzl@49791
  1739
       (auto simp: `?P = ?C` intro!: integrable_count_space simple_functionD  X Y)
hoelzl@39097
  1740
qed
hoelzl@39097
  1741
hoelzl@40859
  1742
lemma (in information_space) conditional_entropy_eq:
hoelzl@49792
  1743
  assumes Y: "simple_distributed M Y Py"
hoelzl@47694
  1744
  assumes XY: "simple_distributed M (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
  1745
    shows "\<H>(X | Y) = - (\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` space M. Pxy (x, y) * log b (Pxy (x, y) / Py y))"
hoelzl@47694
  1746
proof (subst conditional_entropy_generic_eq[OF _ _
hoelzl@49790
  1747
  simple_distributed[OF Y] simple_distributed_joint[OF XY]])
hoelzl@49792
  1748
  have "finite ((\<lambda>x. (X x, Y x))`space M)"
hoelzl@49792
  1749
    using XY unfolding simple_distributed_def by auto
hoelzl@49792
  1750
  from finite_imageI[OF this, of fst]
hoelzl@49792
  1751
  have [simp]: "finite (X`space M)"
hoelzl@49792
  1752
    by (simp add: image_compose[symmetric] comp_def)
hoelzl@47694
  1753
  note Y[THEN simple_distributed_finite, simp]
hoelzl@47694
  1754
  show "sigma_finite_measure (count_space (X ` space M))"
hoelzl@47694
  1755
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1756
  show "sigma_finite_measure (count_space (Y ` space M))"
hoelzl@47694
  1757
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1758
  let ?f = "(\<lambda>x. if x \<in> (\<lambda>x. (X x, Y x)) ` space M then Pxy x else 0)"
hoelzl@47694
  1759
  have "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) = count_space (X`space M \<times> Y`space M)"
hoelzl@47694
  1760
    (is "?P = ?C")
hoelzl@49792
  1761
    using Y by (simp add: simple_distributed_finite pair_measure_count_space)
hoelzl@47694
  1762
  have eq: "(\<lambda>(x, y). ?f (x, y) * log b (?f (x, y) / Py y)) =
hoelzl@47694
  1763
    (\<lambda>x. if x \<in> (\<lambda>x. (X x, Y x)) ` space M then Pxy x * log b (Pxy x / Py (snd x)) else 0)"
hoelzl@47694
  1764
    by auto
hoelzl@49792
  1765
  from Y show "- (\<integral> (x, y). ?f (x, y) * log b (?f (x, y) / Py y) \<partial>?P) =
hoelzl@47694
  1766
    - (\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` space M. Pxy (x, y) * log b (Pxy (x, y) / Py y))"
hoelzl@47694
  1767
    by (auto intro!: setsum_cong simp add: `?P = ?C` lebesgue_integral_count_space_finite simple_distributed_finite eq setsum_cases split_beta')
hoelzl@47694
  1768
qed
hoelzl@39097
  1769
hoelzl@47694
  1770
lemma (in information_space) conditional_mutual_information_eq_conditional_entropy:
hoelzl@41689
  1771
  assumes X: "simple_function M X" and Y: "simple_function M Y"
hoelzl@47694
  1772
  shows "\<I>(X ; X | Y) = \<H>(X | Y)"
hoelzl@47694
  1773
proof -
hoelzl@47694
  1774
  def Py \<equiv> "\<lambda>x. if x \<in> Y`space M then measure M (Y -` {x} \<inter> space M) else 0"
hoelzl@47694
  1775
  def Pxy \<equiv> "\<lambda>x. if x \<in> (\<lambda>x. (X x, Y x))`space M then measure M ((\<lambda>x. (X x, Y x)) -` {x} \<inter> space M) else 0"
hoelzl@47694
  1776
  def Pxxy \<equiv> "\<lambda>x. if x \<in> (\<lambda>x. (X x, X x, Y x))`space M then measure M ((\<lambda>x. (X x, X x, Y x)) -` {x} \<inter> space M) else 0"
hoelzl@47694
  1777
  let ?M = "X`space M \<times> X`space M \<times> Y`space M"
hoelzl@39097
  1778
hoelzl@47694
  1779
  note XY = simple_function_Pair[OF X Y]
hoelzl@47694
  1780
  note XXY = simple_function_Pair[OF X XY]
hoelzl@47694
  1781
  have Py: "simple_distributed M Y Py"
hoelzl@47694
  1782
    using Y by (rule simple_distributedI) (auto simp: Py_def)
hoelzl@47694
  1783
  have Pxy: "simple_distributed M (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
  1784
    using XY by (rule simple_distributedI) (auto simp: Pxy_def)
hoelzl@47694
  1785
  have Pxxy: "simple_distributed M (\<lambda>x. (X x, X x, Y x)) Pxxy"
hoelzl@47694
  1786
    using XXY by (rule simple_distributedI) (auto simp: Pxxy_def)
hoelzl@47694
  1787
  have eq: "(\<lambda>x. (X x, X x, Y x)) ` space M = (\<lambda>(x, y). (x, x, y)) ` (\<lambda>x. (X x, Y x)) ` space M"
hoelzl@47694
  1788
    by auto
hoelzl@47694
  1789
  have inj: "\<And>A. inj_on (\<lambda>(x, y). (x, x, y)) A"
hoelzl@47694
  1790
    by (auto simp: inj_on_def)
hoelzl@47694
  1791
  have Pxxy_eq: "\<And>x y. Pxxy (x, x, y) = Pxy (x, y)"
hoelzl@47694
  1792
    by (auto simp: Pxxy_def Pxy_def intro!: arg_cong[where f=prob])
hoelzl@47694
  1793
  have "AE x in count_space ((\<lambda>x. (X x, Y x))`space M). Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
  1794
    by (intro subdensity_real[of snd, OF _ Pxy[THEN simple_distributed] Py[THEN simple_distributed]]) (auto intro: measurable_Pair)
hoelzl@47694
  1795
  then show ?thesis
hoelzl@47694
  1796
    apply (subst conditional_mutual_information_eq[OF Py Pxy Pxy Pxxy])
hoelzl@49792
  1797
    apply (subst conditional_entropy_eq[OF Py Pxy])
hoelzl@47694
  1798
    apply (auto intro!: setsum_cong simp: Pxxy_eq setsum_negf[symmetric] eq setsum_reindex[OF inj]
hoelzl@47694
  1799
                log_simps zero_less_mult_iff zero_le_mult_iff field_simps mult_less_0_iff AE_count_space)
hoelzl@47694
  1800
    using Py[THEN simple_distributed, THEN distributed_real_AE] Pxy[THEN simple_distributed, THEN distributed_real_AE]
hoelzl@49790
  1801
  apply (auto simp add: not_le[symmetric] AE_count_space)
hoelzl@47694
  1802
    done
hoelzl@47694
  1803
qed
hoelzl@47694
  1804
hoelzl@47694
  1805
lemma (in information_space) conditional_entropy_nonneg:
hoelzl@47694
  1806
  assumes X: "simple_function M X" and Y: "simple_function M Y" shows "0 \<le> \<H>(X | Y)"
hoelzl@47694
  1807
  using conditional_mutual_information_eq_conditional_entropy[OF X Y] conditional_mutual_information_nonneg[OF X X Y]
hoelzl@47694
  1808
  by simp
hoelzl@36080
  1809
hoelzl@39097
  1810
subsection {* Equalities *}
hoelzl@39097
  1811
hoelzl@47694
  1812
lemma (in information_space) mutual_information_eq_entropy_conditional_entropy_distr:
hoelzl@47694
  1813
  fixes Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real" and Pxy :: "('b \<times> 'c) \<Rightarrow> real"
hoelzl@47694
  1814
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
hoelzl@47694
  1815
  assumes Px: "distributed M S X Px" and Py: "distributed M T Y Py"
hoelzl@47694
  1816
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
  1817
  assumes Ix: "integrable(S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Px (fst x)))"
hoelzl@47694
  1818
  assumes Iy: "integrable(S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Py (snd x)))"
hoelzl@47694
  1819
  assumes Ixy: "integrable(S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Pxy x))"
hoelzl@47694
  1820
  shows  "mutual_information b S T X Y = entropy b S X + entropy b T Y - entropy b (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@40859
  1821
proof -
hoelzl@47694
  1822
  have X: "entropy b S X = - (\<integral>x. Pxy x * log b (Px (fst x)) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@47694
  1823
    using b_gt_1 Px[THEN distributed_real_measurable]
hoelzl@49786
  1824
    apply (subst entropy_distr[OF Px])
hoelzl@47694
  1825
    apply (subst distributed_transform_integral[OF Pxy Px, where T=fst])
hoelzl@47694
  1826
    apply (auto intro!: integral_cong)
hoelzl@47694
  1827
    done
hoelzl@47694
  1828
hoelzl@47694
  1829
  have Y: "entropy b T Y = - (\<integral>x. Pxy x * log b (Py (snd x)) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@47694
  1830
    using b_gt_1 Py[THEN distributed_real_measurable]
hoelzl@49786
  1831
    apply (subst entropy_distr[OF Py])
hoelzl@47694
  1832
    apply (subst distributed_transform_integral[OF Pxy Py, where T=snd])
hoelzl@47694
  1833
    apply (auto intro!: integral_cong)
hoelzl@47694
  1834
    done
hoelzl@47694
  1835
hoelzl@47694
  1836
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
  1837
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
  1838
  interpret ST: pair_sigma_finite S T ..
hoelzl@47694
  1839
  have ST: "sigma_finite_measure (S \<Otimes>\<^isub>M T)" ..
hoelzl@47694
  1840
hoelzl@47694
  1841
  have XY: "entropy b (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) = - (\<integral>x. Pxy x * log b (Pxy x) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@49786
  1842
    by (subst entropy_distr[OF Pxy]) (auto intro!: integral_cong)
hoelzl@47694
  1843
  
hoelzl@47694
  1844
  have "AE x in S \<Otimes>\<^isub>M T. Px (fst x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
  1845
    by (intro subdensity_real[of fst, OF _ Pxy Px]) (auto intro: measurable_Pair)
hoelzl@47694
  1846
  moreover have "AE x in S \<Otimes>\<^isub>M T. Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
  1847
    by (intro subdensity_real[of snd, OF _ Pxy Py]) (auto intro: measurable_Pair)
hoelzl@47694
  1848
  moreover have "AE x in S \<Otimes>\<^isub>M T. 0 \<le> Px (fst x)"
hoelzl@47694
  1849
    using Px by (intro ST.AE_pair_measure) (auto simp: comp_def intro!: measurable_fst'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@47694
  1850
  moreover have "AE x in S \<Otimes>\<^isub>M T. 0 \<le> Py (snd x)"
hoelzl@47694
  1851
    using Py by (intro ST.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@47694
  1852
  moreover note Pxy[THEN distributed_real_AE]
hoelzl@47694
  1853
  ultimately have "AE x in S \<Otimes>\<^isub>M T. Pxy x * log b (Pxy x) - Pxy x * log b (Px (fst x)) - Pxy x * log b (Py (snd x)) = 
hoelzl@47694
  1854
    Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x)))"
hoelzl@47694
  1855
    (is "AE x in _. ?f x = ?g x")
hoelzl@47694
  1856
  proof eventually_elim
hoelzl@47694
  1857
    case (goal1 x)
hoelzl@47694
  1858
    show ?case
hoelzl@47694
  1859
    proof cases
hoelzl@47694
  1860
      assume "Pxy x \<noteq> 0"
hoelzl@47694
  1861
      with goal1 have "0 < Px (fst x)" "0 < Py (snd x)" "0 < Pxy x"
hoelzl@47694
  1862
        by auto
hoelzl@47694
  1863
      then show ?thesis
hoelzl@47694
  1864
        using b_gt_1 by (simp add: log_simps mult_pos_pos less_imp_le field_simps)
hoelzl@47694
  1865
    qed simp
hoelzl@47694
  1866
  qed
hoelzl@47694
  1867
hoelzl@47694
  1868
  have "entropy b S X + entropy b T Y - entropy b (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) = integral\<^isup>L (S \<Otimes>\<^isub>M T) ?f"
hoelzl@47694
  1869
    unfolding X Y XY
hoelzl@47694
  1870
    apply (subst integral_diff)
hoelzl@47694
  1871
    apply (intro integral_diff Ixy Ix Iy)+
hoelzl@47694
  1872
    apply (subst integral_diff)
hoelzl@47694
  1873
    apply (intro integral_diff Ixy Ix Iy)+
hoelzl@47694
  1874
    apply (simp add: field_simps)
hoelzl@47694
  1875
    done
hoelzl@47694
  1876
  also have "\<dots> = integral\<^isup>L (S \<Otimes>\<^isub>M T) ?g"
hoelzl@47694
  1877
    using `AE x in _. ?f x = ?g x` by (rule integral_cong_AE)
hoelzl@47694
  1878
  also have "\<dots> = mutual_information b S T X Y"
hoelzl@47694
  1879
    by (rule mutual_information_distr[OF S T Px Py Pxy, symmetric])
hoelzl@47694
  1880
  finally show ?thesis ..
hoelzl@47694
  1881
qed
hoelzl@47694
  1882
hoelzl@49802
  1883
lemma (in information_space) mutual_information_eq_entropy_conditional_entropy':
hoelzl@49802
  1884
  fixes Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real" and Pxy :: "('b \<times> 'c) \<Rightarrow> real"
hoelzl@49802
  1885
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
hoelzl@49802
  1886
  assumes Px: "distributed M S X Px" and Py: "distributed M T Y Py"
hoelzl@49802
  1887
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@49802
  1888
  assumes Ix: "integrable(S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Px (fst x)))"
hoelzl@49802
  1889
  assumes Iy: "integrable(S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Py (snd x)))"
hoelzl@49802
  1890
  assumes Ixy: "integrable(S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Pxy x))"
hoelzl@49802
  1891
  shows  "mutual_information b S T X Y = entropy b S X - conditional_entropy b S T X Y"
hoelzl@49802
  1892
  using
hoelzl@49802
  1893
    mutual_information_eq_entropy_conditional_entropy_distr[OF S T Px Py Pxy Ix Iy Ixy]
hoelzl@49802
  1894
    conditional_entropy_eq_entropy[OF S T Py Pxy Ixy Iy]
hoelzl@49802
  1895
  by simp
hoelzl@49802
  1896
hoelzl@47694
  1897
lemma (in information_space) mutual_information_eq_entropy_conditional_entropy:
hoelzl@47694
  1898
  assumes sf_X: "simple_function M X" and sf_Y: "simple_function M Y"
hoelzl@47694
  1899
  shows  "\<I>(X ; Y) = \<H>(X) - \<H>(X | Y)"
hoelzl@47694
  1900
proof -
hoelzl@47694
  1901
  have X: "simple_distributed M X (\<lambda>x. measure M (X -` {x} \<inter> space M))"
hoelzl@47694
  1902
    using sf_X by (rule simple_distributedI) auto
hoelzl@47694
  1903
  have Y: "simple_distributed M Y (\<lambda>x. measure M (Y -` {x} \<inter> space M))"
hoelzl@47694
  1904
    using sf_Y by (rule simple_distributedI) auto
hoelzl@47694
  1905
  have sf_XY: "simple_function M (\<lambda>x. (X x, Y x))"
hoelzl@47694
  1906
    using sf_X sf_Y by (rule simple_function_Pair)
hoelzl@47694
  1907
  then have XY: "simple_distributed M (\<lambda>x. (X x, Y x)) (\<lambda>x. measure M ((\<lambda>x. (X x, Y x)) -` {x} \<inter> space M))"
hoelzl@47694
  1908
    by (rule simple_distributedI) auto
hoelzl@47694
  1909
  from simple_distributed_joint_finite[OF this, simp]
hoelzl@47694
  1910
  have eq: "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) = count_space (X ` space M \<times> Y ` space M)"
hoelzl@47694
  1911
    by (simp add: pair_measure_count_space)
hoelzl@47694
  1912
hoelzl@47694
  1913
  have "\<I>(X ; Y) = \<H>(X) + \<H>(Y) - entropy b (count_space (X`space M) \<Otimes>\<^isub>M count_space (Y`space M)) (\<lambda>x. (X x, Y x))"
hoelzl@47694
  1914
    using sigma_finite_measure_count_space_finite sigma_finite_measure_count_space_finite simple_distributed[OF X] simple_distributed[OF Y] simple_distributed_joint[OF XY]
hoelzl@47694
  1915
    by (rule mutual_information_eq_entropy_conditional_entropy_distr) (auto simp: eq integrable_count_space)
hoelzl@47694
  1916
  then show ?thesis
hoelzl@49791
  1917
    unfolding conditional_entropy_eq_entropy_simple[OF sf_X sf_Y] by simp
hoelzl@47694
  1918
qed
hoelzl@47694
  1919
hoelzl@47694
  1920
lemma (in information_space) mutual_information_nonneg_simple:
hoelzl@47694
  1921
  assumes sf_X: "simple_function M X" and sf_Y: "simple_function M Y"
hoelzl@47694
  1922
  shows  "0 \<le> \<I>(X ; Y)"
hoelzl@47694
  1923
proof -
hoelzl@47694
  1924
  have X: "simple_distributed M X (\<lambda>x. measure M (X -` {x} \<inter> space M))"
hoelzl@47694
  1925
    using sf_X by (rule simple_distributedI) auto
hoelzl@47694
  1926
  have Y: "simple_distributed M Y (\<lambda>x. measure M (Y -` {x} \<inter> space M))"
hoelzl@47694
  1927
    using sf_Y by (rule simple_distributedI) auto
hoelzl@47694
  1928
hoelzl@47694
  1929
  have sf_XY: "simple_function M (\<lambda>x. (X x, Y x))"
hoelzl@47694
  1930
    using sf_X sf_Y by (rule simple_function_Pair)
hoelzl@47694
  1931
  then have XY: "simple_distributed M (\<lambda>x. (X x, Y x)) (\<lambda>x. measure M ((\<lambda>x. (X x, Y x)) -` {x} \<inter> space M))"
hoelzl@47694
  1932
    by (rule simple_distributedI) auto
hoelzl@47694
  1933
hoelzl@47694
  1934
  from simple_distributed_joint_finite[OF this, simp]
hoelzl@47694
  1935
  have eq: "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) = count_space (X ` space M \<times> Y ` space M)"
hoelzl@47694
  1936
    by (simp add: pair_measure_count_space)
hoelzl@47694
  1937
hoelzl@40859
  1938
  show ?thesis
hoelzl@47694
  1939
    by (rule mutual_information_nonneg[OF _ _ simple_distributed[OF X] simple_distributed[OF Y] simple_distributed_joint[OF XY]])
hoelzl@47694
  1940
       (simp_all add: eq integrable_count_space sigma_finite_measure_count_space_finite)
hoelzl@40859
  1941
qed
hoelzl@36080
  1942
hoelzl@40859
  1943
lemma (in information_space) conditional_entropy_less_eq_entropy:
hoelzl@41689
  1944
  assumes X: "simple_function M X" and Z: "simple_function M Z"
hoelzl@40859
  1945
  shows "\<H>(X | Z) \<le> \<H>(X)"
hoelzl@36624
  1946
proof -
hoelzl@47694
  1947
  have "0 \<le> \<I>(X ; Z)" using X Z by (rule mutual_information_nonneg_simple)
hoelzl@47694
  1948
  also have "\<I>(X ; Z) = \<H>(X) - \<H>(X | Z)" using mutual_information_eq_entropy_conditional_entropy[OF assms] .
hoelzl@47694
  1949
  finally show ?thesis by auto
hoelzl@36080
  1950
qed
hoelzl@36080
  1951
hoelzl@49803
  1952
lemma (in information_space) 
hoelzl@49803
  1953
  fixes Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real" and Pxy :: "('b \<times> 'c) \<Rightarrow> real"
hoelzl@49803
  1954
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
hoelzl@49803
  1955
  assumes Px: "finite_entropy S X Px" and Py: "finite_entropy T Y Py"
hoelzl@49803
  1956
  assumes Pxy: "finite_entropy (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@49803
  1957
  shows "conditional_entropy b S T X Y \<le> entropy b S X"
hoelzl@49803
  1958
proof -
hoelzl@49803
  1959
hoelzl@49803
  1960
  have "0 \<le> mutual_information b S T X Y" 
hoelzl@49803
  1961
    by (rule mutual_information_nonneg') fact+
hoelzl@49803
  1962
  also have "\<dots> = entropy b S X - conditional_entropy b S T X Y"
hoelzl@49803
  1963
    apply (rule mutual_information_eq_entropy_conditional_entropy')
hoelzl@49803
  1964
    using assms
hoelzl@49803
  1965
    by (auto intro!: finite_entropy_integrable finite_entropy_distributed
hoelzl@49803
  1966
      finite_entropy_integrable_transform[OF Px]
hoelzl@49803
  1967
      finite_entropy_integrable_transform[OF Py])
hoelzl@49803
  1968
  finally show ?thesis by auto
hoelzl@49803
  1969
qed
hoelzl@49803
  1970
hoelzl@40859
  1971
lemma (in information_space) entropy_chain_rule:
hoelzl@41689
  1972
  assumes X: "simple_function M X" and Y: "simple_function M Y"
hoelzl@40859
  1973
  shows  "\<H>(\<lambda>x. (X x, Y x)) = \<H>(X) + \<H>(Y|X)"
hoelzl@40859
  1974
proof -
hoelzl@47694
  1975
  note XY = simple_distributedI[OF simple_function_Pair[OF X Y] refl]
hoelzl@47694
  1976
  note YX = simple_distributedI[OF simple_function_Pair[OF Y X] refl]
hoelzl@47694
  1977
  note simple_distributed_joint_finite[OF this, simp]
hoelzl@47694
  1978
  let ?f = "\<lambda>x. prob ((\<lambda>x. (X x, Y x)) -` {x} \<inter> space M)"
hoelzl@47694
  1979
  let ?g = "\<lambda>x. prob ((\<lambda>x. (Y x, X x)) -` {x} \<inter> space M)"
hoelzl@47694
  1980
  let ?h = "\<lambda>x. if x \<in> (\<lambda>x. (Y x, X x)) ` space M then prob ((\<lambda>x. (Y x, X x)) -` {x} \<inter> space M) else 0"
hoelzl@47694
  1981
  have "\<H>(\<lambda>x. (X x, Y x)) = - (\<Sum>x\<in>(\<lambda>x. (X x, Y x)) ` space M. ?f x * log b (?f x))"
hoelzl@47694
  1982
    using XY by (rule entropy_simple_distributed)
hoelzl@47694
  1983
  also have "\<dots> = - (\<Sum>x\<in>(\<lambda>(x, y). (y, x)) ` (\<lambda>x. (X x, Y x)) ` space M. ?g x * log b (?g x))"
hoelzl@47694
  1984
    by (subst (2) setsum_reindex) (auto simp: inj_on_def intro!: setsum_cong arg_cong[where f="\<lambda>A. prob A * log b (prob A)"])
hoelzl@47694
  1985
  also have "\<dots> = - (\<Sum>x\<in>(\<lambda>x. (Y x, X x)) ` space M. ?h x * log b (?h x))"
hoelzl@47694
  1986
    by (auto intro!: setsum_cong)
hoelzl@47694
  1987
  also have "\<dots> = entropy b (count_space (Y ` space M) \<Otimes>\<^isub>M count_space (X ` space M)) (\<lambda>x. (Y x, X x))"
hoelzl@49786
  1988
    by (subst entropy_distr[OF simple_distributed_joint[OF YX]])
hoelzl@47694
  1989
       (auto simp: pair_measure_count_space sigma_finite_measure_count_space_finite lebesgue_integral_count_space_finite
hoelzl@47694
  1990
             cong del: setsum_cong  intro!: setsum_mono_zero_left)
hoelzl@47694
  1991
  finally have "\<H>(\<lambda>x. (X x, Y x)) = entropy b (count_space (Y ` space M) \<Otimes>\<^isub>M count_space (X ` space M)) (\<lambda>x. (Y x, X x))" .
hoelzl@47694
  1992
  then show ?thesis
hoelzl@49791
  1993
    unfolding conditional_entropy_eq_entropy_simple[OF Y X] by simp
hoelzl@36624
  1994
qed
hoelzl@36624
  1995
hoelzl@40859
  1996
lemma (in information_space) entropy_partition:
hoelzl@47694
  1997
  assumes X: "simple_function M X"
hoelzl@47694
  1998
  shows "\<H>(X) = \<H>(f \<circ> X) + \<H>(X|f \<circ> X)"
hoelzl@36624
  1999
proof -
hoelzl@47694
  2000
  note fX = simple_function_compose[OF X, of f]  
hoelzl@47694
  2001
  have eq: "(\<lambda>x. ((f \<circ> X) x, X x)) ` space M = (\<lambda>x. (f x, x)) ` X ` space M" by auto
hoelzl@47694
  2002
  have inj: "\<And>A. inj_on (\<lambda>x. (f x, x)) A"
hoelzl@47694
  2003
    by (auto simp: inj_on_def)
hoelzl@47694
  2004
  show ?thesis
hoelzl@47694
  2005
    apply (subst entropy_chain_rule[symmetric, OF fX X])
hoelzl@47694
  2006
    apply (subst entropy_simple_distributed[OF simple_distributedI[OF simple_function_Pair[OF fX X] refl]])
hoelzl@47694
  2007
    apply (subst entropy_simple_distributed[OF simple_distributedI[OF X refl]])
hoelzl@47694
  2008
    unfolding eq
hoelzl@47694
  2009
    apply (subst setsum_reindex[OF inj])
hoelzl@47694
  2010
    apply (auto intro!: setsum_cong arg_cong[where f="\<lambda>A. prob A * log b (prob A)"])
hoelzl@47694
  2011
    done
hoelzl@36624
  2012
qed
hoelzl@36624
  2013
hoelzl@40859
  2014
corollary (in information_space) entropy_data_processing:
hoelzl@41689
  2015
  assumes X: "simple_function M X" shows "\<H>(f \<circ> X) \<le> \<H>(X)"
hoelzl@40859
  2016
proof -
hoelzl@47694
  2017
  note fX = simple_function_compose[OF X, of f]
hoelzl@47694
  2018
  from X have "\<H>(X) = \<H>(f\<circ>X) + \<H>(X|f\<circ>X)" by (rule entropy_partition)
hoelzl@40859
  2019
  then show "\<H>(f \<circ> X) \<le> \<H>(X)"
hoelzl@47694
  2020
    by (auto intro: conditional_entropy_nonneg[OF X fX])
hoelzl@40859
  2021
qed
hoelzl@36624
  2022
hoelzl@40859
  2023
corollary (in information_space) entropy_of_inj:
hoelzl@41689
  2024
  assumes X: "simple_function M X" and inj: "inj_on f (X`space M)"
hoelzl@36624
  2025
  shows "\<H>(f \<circ> X) = \<H>(X)"
hoelzl@36624
  2026
proof (rule antisym)
hoelzl@40859
  2027
  show "\<H>(f \<circ> X) \<le> \<H>(X)" using entropy_data_processing[OF X] .
hoelzl@36624
  2028
next
hoelzl@41689
  2029
  have sf: "simple_function M (f \<circ> X)"
hoelzl@40859
  2030
    using X by auto
hoelzl@36624
  2031
  have "\<H>(X) = \<H>(the_inv_into (X`space M) f \<circ> (f \<circ> X))"
hoelzl@47694
  2032
    unfolding o_assoc
hoelzl@47694
  2033
    apply (subst entropy_simple_distributed[OF simple_distributedI[OF X refl]])
hoelzl@47694
  2034
    apply (subst entropy_simple_distributed[OF simple_distributedI[OF simple_function_compose[OF X]], where f="\<lambda>x. prob (X -` {x} \<inter> space M)"])
hoelzl@47694
  2035
    apply (auto intro!: setsum_cong arg_cong[where f=prob] image_eqI simp: the_inv_into_f_f[OF inj] comp_def)
hoelzl@47694
  2036
    done
hoelzl@36624
  2037
  also have "... \<le> \<H>(f \<circ> X)"
hoelzl@40859
  2038
    using entropy_data_processing[OF sf] .
hoelzl@36624
  2039
  finally show "\<H>(X) \<le> \<H>(f \<circ> X)" .
hoelzl@36624
  2040
qed
hoelzl@36624
  2041
hoelzl@36080
  2042
end