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