src/HOL/Probability/Information.thy
author hoelzl
Wed Oct 10 12:12:25 2012 +0200 (2012-10-10)
changeset 49787 d8de705b48d4
parent 49786 f33d5f009627
child 49788 3c10763f5cb4
permissions -rw-r--r--
rule to show that conditional mutual information is non-negative in the continuous case
hoelzl@42067
     1
(*  Title:      HOL/Probability/Information.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
    Author:     Armin Heller, TU München
hoelzl@42067
     4
*)
hoelzl@42067
     5
hoelzl@42067
     6
header {*Information theory*}
hoelzl@42067
     7
hoelzl@36080
     8
theory Information
wenzelm@41413
     9
imports
hoelzl@43340
    10
  Independent_Family
hoelzl@43556
    11
  Radon_Nikodym
wenzelm@41413
    12
  "~~/src/HOL/Library/Convex"
hoelzl@36080
    13
begin
hoelzl@36080
    14
hoelzl@39097
    15
lemma log_le: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> x \<le> y \<Longrightarrow> log a x \<le> log a y"
hoelzl@39097
    16
  by (subst log_le_cancel_iff) auto
hoelzl@39097
    17
hoelzl@39097
    18
lemma log_less: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> x < y \<Longrightarrow> log a x < log a y"
hoelzl@39097
    19
  by (subst log_less_cancel_iff) auto
hoelzl@39097
    20
hoelzl@39097
    21
lemma setsum_cartesian_product':
hoelzl@39097
    22
  "(\<Sum>x\<in>A \<times> B. f x) = (\<Sum>x\<in>A. setsum (\<lambda>y. f (x, y)) B)"
hoelzl@39097
    23
  unfolding setsum_cartesian_product by simp
hoelzl@39097
    24
hoelzl@39097
    25
lemma split_pairs:
hoelzl@40859
    26
  "((A, B) = X) \<longleftrightarrow> (fst X = A \<and> snd X = B)" and
hoelzl@40859
    27
  "(X = (A, B)) \<longleftrightarrow> (fst X = A \<and> snd X = B)" by auto
hoelzl@38656
    28
hoelzl@38656
    29
section "Information theory"
hoelzl@38656
    30
hoelzl@40859
    31
locale information_space = prob_space +
hoelzl@38656
    32
  fixes b :: real assumes b_gt_1: "1 < b"
hoelzl@38656
    33
hoelzl@40859
    34
context information_space
hoelzl@38656
    35
begin
hoelzl@38656
    36
hoelzl@40859
    37
text {* Introduce some simplification rules for logarithm of base @{term b}. *}
hoelzl@40859
    38
hoelzl@40859
    39
lemma log_neg_const:
hoelzl@40859
    40
  assumes "x \<le> 0"
hoelzl@40859
    41
  shows "log b x = log b 0"
hoelzl@36624
    42
proof -
hoelzl@40859
    43
  { fix u :: real
hoelzl@40859
    44
    have "x \<le> 0" by fact
hoelzl@40859
    45
    also have "0 < exp u"
hoelzl@40859
    46
      using exp_gt_zero .
hoelzl@40859
    47
    finally have "exp u \<noteq> x"
hoelzl@40859
    48
      by auto }
hoelzl@40859
    49
  then show "log b x = log b 0"
hoelzl@40859
    50
    by (simp add: log_def ln_def)
hoelzl@38656
    51
qed
hoelzl@38656
    52
hoelzl@40859
    53
lemma log_mult_eq:
hoelzl@40859
    54
  "log b (A * B) = (if 0 < A * B then log b \<bar>A\<bar> + log b \<bar>B\<bar> else log b 0)"
hoelzl@40859
    55
  using log_mult[of b "\<bar>A\<bar>" "\<bar>B\<bar>"] b_gt_1 log_neg_const[of "A * B"]
hoelzl@40859
    56
  by (auto simp: zero_less_mult_iff mult_le_0_iff)
hoelzl@38656
    57
hoelzl@40859
    58
lemma log_inverse_eq:
hoelzl@40859
    59
  "log b (inverse B) = (if 0 < B then - log b B else log b 0)"
hoelzl@40859
    60
  using log_inverse[of b B] log_neg_const[of "inverse B"] b_gt_1 by simp
hoelzl@36080
    61
hoelzl@40859
    62
lemma log_divide_eq:
hoelzl@40859
    63
  "log b (A / B) = (if 0 < A * B then log b \<bar>A\<bar> - log b \<bar>B\<bar> else log b 0)"
hoelzl@40859
    64
  unfolding divide_inverse log_mult_eq log_inverse_eq abs_inverse
hoelzl@40859
    65
  by (auto simp: zero_less_mult_iff mult_le_0_iff)
hoelzl@38656
    66
hoelzl@40859
    67
lemmas log_simps = log_mult_eq log_inverse_eq log_divide_eq
hoelzl@38656
    68
hoelzl@38656
    69
end
hoelzl@38656
    70
hoelzl@39097
    71
subsection "Kullback$-$Leibler divergence"
hoelzl@36080
    72
hoelzl@39097
    73
text {* The Kullback$-$Leibler divergence is also known as relative entropy or
hoelzl@39097
    74
Kullback$-$Leibler distance. *}
hoelzl@39097
    75
hoelzl@39097
    76
definition
hoelzl@47694
    77
  "entropy_density b M N = log b \<circ> real \<circ> RN_deriv M N"
hoelzl@43340
    78
hoelzl@43340
    79
definition
hoelzl@47694
    80
  "KL_divergence b M N = integral\<^isup>L N (entropy_density b M N)"
hoelzl@43340
    81
hoelzl@43340
    82
lemma (in information_space) measurable_entropy_density:
hoelzl@47694
    83
  assumes ac: "absolutely_continuous M N" "sets N = events"
hoelzl@47694
    84
  shows "entropy_density b M N \<in> borel_measurable M"
hoelzl@43340
    85
proof -
hoelzl@47694
    86
  from borel_measurable_RN_deriv[OF ac] b_gt_1 show ?thesis
hoelzl@43340
    87
    unfolding entropy_density_def
hoelzl@43340
    88
    by (intro measurable_comp) auto
hoelzl@43340
    89
qed
hoelzl@43340
    90
hoelzl@47694
    91
lemma (in sigma_finite_measure) KL_density:
hoelzl@47694
    92
  fixes f :: "'a \<Rightarrow> real"
hoelzl@47694
    93
  assumes "1 < b"
hoelzl@47694
    94
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
    95
  shows "KL_divergence b M (density M f) = (\<integral>x. f x * log b (f x) \<partial>M)"
hoelzl@47694
    96
  unfolding KL_divergence_def
hoelzl@47694
    97
proof (subst integral_density)
hoelzl@47694
    98
  show "entropy_density b M (density M (\<lambda>x. ereal (f x))) \<in> borel_measurable M"
hoelzl@49776
    99
    using f
hoelzl@47694
   100
    by (auto simp: comp_def entropy_density_def intro!: borel_measurable_log borel_measurable_RN_deriv_density)
hoelzl@47694
   101
  have "density M (RN_deriv M (density M f)) = density M f"
hoelzl@47694
   102
    using f by (intro density_RN_deriv_density) auto
hoelzl@47694
   103
  then have eq: "AE x in M. RN_deriv M (density M f) x = f x"
hoelzl@47694
   104
    using f
hoelzl@47694
   105
    by (intro density_unique)
hoelzl@47694
   106
       (auto intro!: borel_measurable_log borel_measurable_RN_deriv_density simp: RN_deriv_density_nonneg)
hoelzl@47694
   107
  show "(\<integral>x. f x * entropy_density b M (density M (\<lambda>x. ereal (f x))) x \<partial>M) = (\<integral>x. f x * log b (f x) \<partial>M)"
hoelzl@47694
   108
    apply (intro integral_cong_AE)
hoelzl@47694
   109
    using eq
hoelzl@47694
   110
    apply eventually_elim
hoelzl@47694
   111
    apply (auto simp: entropy_density_def)
hoelzl@47694
   112
    done
hoelzl@47694
   113
qed fact+
hoelzl@43340
   114
hoelzl@47694
   115
lemma (in sigma_finite_measure) KL_density_density:
hoelzl@47694
   116
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@47694
   117
  assumes "1 < b"
hoelzl@47694
   118
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
   119
  assumes g: "g \<in> borel_measurable M" "AE x in M. 0 \<le> g x"
hoelzl@47694
   120
  assumes ac: "AE x in M. f x = 0 \<longrightarrow> g x = 0"
hoelzl@47694
   121
  shows "KL_divergence b (density M f) (density M g) = (\<integral>x. g x * log b (g x / f x) \<partial>M)"
hoelzl@47694
   122
proof -
hoelzl@47694
   123
  interpret Mf: sigma_finite_measure "density M f"
hoelzl@47694
   124
    using f by (subst sigma_finite_iff_density_finite) auto
hoelzl@47694
   125
  have "KL_divergence b (density M f) (density M g) =
hoelzl@47694
   126
    KL_divergence b (density M f) (density (density M f) (\<lambda>x. g x / f x))"
hoelzl@47694
   127
    using f g ac by (subst density_density_divide) simp_all
hoelzl@47694
   128
  also have "\<dots> = (\<integral>x. (g x / f x) * log b (g x / f x) \<partial>density M f)"
hoelzl@47694
   129
    using f g `1 < b` by (intro Mf.KL_density) (auto simp: AE_density divide_nonneg_nonneg)
hoelzl@47694
   130
  also have "\<dots> = (\<integral>x. g x * log b (g x / f x) \<partial>M)"
hoelzl@47694
   131
    using ac f g `1 < b` by (subst integral_density) (auto intro!: integral_cong_AE)
hoelzl@47694
   132
  finally show ?thesis .
hoelzl@47694
   133
qed
hoelzl@43340
   134
hoelzl@47694
   135
lemma (in information_space) KL_gt_0:
hoelzl@47694
   136
  fixes D :: "'a \<Rightarrow> real"
hoelzl@47694
   137
  assumes "prob_space (density M D)"
hoelzl@47694
   138
  assumes D: "D \<in> borel_measurable M" "AE x in M. 0 \<le> D x"
hoelzl@47694
   139
  assumes int: "integrable M (\<lambda>x. D x * log b (D x))"
hoelzl@47694
   140
  assumes A: "density M D \<noteq> M"
hoelzl@47694
   141
  shows "0 < KL_divergence b M (density M D)"
hoelzl@47694
   142
proof -
hoelzl@47694
   143
  interpret N: prob_space "density M D" by fact
hoelzl@43340
   144
hoelzl@47694
   145
  obtain A where "A \<in> sets M" "emeasure (density M D) A \<noteq> emeasure M A"
hoelzl@47694
   146
    using measure_eqI[of "density M D" M] `density M D \<noteq> M` by auto
hoelzl@47694
   147
hoelzl@47694
   148
  let ?D_set = "{x\<in>space M. D x \<noteq> 0}"
hoelzl@47694
   149
  have [simp, intro]: "?D_set \<in> sets M"
hoelzl@47694
   150
    using D by auto
hoelzl@43340
   151
hoelzl@43920
   152
  have D_neg: "(\<integral>\<^isup>+ x. ereal (- D x) \<partial>M) = 0"
hoelzl@43340
   153
    using D by (subst positive_integral_0_iff_AE) auto
hoelzl@43340
   154
hoelzl@47694
   155
  have "(\<integral>\<^isup>+ x. ereal (D x) \<partial>M) = emeasure (density M D) (space M)"
hoelzl@47694
   156
    using D by (simp add: emeasure_density cong: positive_integral_cong)
hoelzl@43920
   157
  then have D_pos: "(\<integral>\<^isup>+ x. ereal (D x) \<partial>M) = 1"
hoelzl@47694
   158
    using N.emeasure_space_1 by simp
hoelzl@43340
   159
hoelzl@47694
   160
  have "integrable M D" "integral\<^isup>L M D = 1"
hoelzl@47694
   161
    using D D_pos D_neg unfolding integrable_def lebesgue_integral_def by simp_all
hoelzl@43340
   162
hoelzl@47694
   163
  have "0 \<le> 1 - measure M ?D_set"
hoelzl@43340
   164
    using prob_le_1 by (auto simp: field_simps)
hoelzl@43340
   165
  also have "\<dots> = (\<integral> x. D x - indicator ?D_set x \<partial>M)"
hoelzl@43340
   166
    using `integrable M D` `integral\<^isup>L M D = 1`
hoelzl@47694
   167
    by (simp add: emeasure_eq_measure)
hoelzl@47694
   168
  also have "\<dots> < (\<integral> x. D x * (ln b * log b (D x)) \<partial>M)"
hoelzl@43340
   169
  proof (rule integral_less_AE)
hoelzl@43340
   170
    show "integrable M (\<lambda>x. D x - indicator ?D_set x)"
hoelzl@43340
   171
      using `integrable M D`
hoelzl@43340
   172
      by (intro integral_diff integral_indicator) auto
hoelzl@43340
   173
  next
hoelzl@47694
   174
    from integral_cmult(1)[OF int, of "ln b"]
hoelzl@47694
   175
    show "integrable M (\<lambda>x. D x * (ln b * log b (D x)))" 
hoelzl@47694
   176
      by (simp add: ac_simps)
hoelzl@43340
   177
  next
hoelzl@47694
   178
    show "emeasure M {x\<in>space M. D x \<noteq> 1 \<and> D x \<noteq> 0} \<noteq> 0"
hoelzl@43340
   179
    proof
hoelzl@47694
   180
      assume eq_0: "emeasure M {x\<in>space M. D x \<noteq> 1 \<and> D x \<noteq> 0} = 0"
hoelzl@47694
   181
      then have disj: "AE x in M. D x = 1 \<or> D x = 0"
hoelzl@43340
   182
        using D(1) by (auto intro!: AE_I[OF subset_refl] sets_Collect)
hoelzl@43340
   183
hoelzl@47694
   184
      have "emeasure M {x\<in>space M. D x = 1} = (\<integral>\<^isup>+ x. indicator {x\<in>space M. D x = 1} x \<partial>M)"
hoelzl@43340
   185
        using D(1) by auto
hoelzl@47694
   186
      also have "\<dots> = (\<integral>\<^isup>+ x. ereal (D x) \<partial>M)"
hoelzl@43920
   187
        using disj by (auto intro!: positive_integral_cong_AE simp: indicator_def one_ereal_def)
hoelzl@47694
   188
      finally have "AE x in M. D x = 1"
hoelzl@47694
   189
        using D D_pos by (intro AE_I_eq_1) auto
hoelzl@43920
   190
      then have "(\<integral>\<^isup>+x. indicator A x\<partial>M) = (\<integral>\<^isup>+x. ereal (D x) * indicator A x\<partial>M)"
hoelzl@43920
   191
        by (intro positive_integral_cong_AE) (auto simp: one_ereal_def[symmetric])
hoelzl@47694
   192
      also have "\<dots> = density M D A"
hoelzl@47694
   193
        using `A \<in> sets M` D by (simp add: emeasure_density)
hoelzl@47694
   194
      finally show False using `A \<in> sets M` `emeasure (density M D) A \<noteq> emeasure M A` by simp
hoelzl@43340
   195
    qed
hoelzl@43340
   196
    show "{x\<in>space M. D x \<noteq> 1 \<and> D x \<noteq> 0} \<in> sets M"
hoelzl@47694
   197
      using D(1) by (auto intro: sets_Collect_conj)
hoelzl@43340
   198
hoelzl@47694
   199
    show "AE t in M. t \<in> {x\<in>space M. D x \<noteq> 1 \<and> D x \<noteq> 0} \<longrightarrow>
hoelzl@47694
   200
      D t - indicator ?D_set t \<noteq> D t * (ln b * log b (D t))"
hoelzl@43340
   201
      using D(2)
hoelzl@47694
   202
    proof (eventually_elim, safe)
hoelzl@47694
   203
      fix t assume Dt: "t \<in> space M" "D t \<noteq> 1" "D t \<noteq> 0" "0 \<le> D t"
hoelzl@47694
   204
        and eq: "D t - indicator ?D_set t = D t * (ln b * log b (D t))"
hoelzl@43340
   205
hoelzl@43340
   206
      have "D t - 1 = D t - indicator ?D_set t"
hoelzl@43340
   207
        using Dt by simp
hoelzl@43340
   208
      also note eq
hoelzl@47694
   209
      also have "D t * (ln b * log b (D t)) = - D t * ln (1 / D t)"
hoelzl@47694
   210
        using b_gt_1 `D t \<noteq> 0` `0 \<le> D t`
hoelzl@47694
   211
        by (simp add: log_def ln_div less_le)
hoelzl@43340
   212
      finally have "ln (1 / D t) = 1 / D t - 1"
hoelzl@43340
   213
        using `D t \<noteq> 0` by (auto simp: field_simps)
hoelzl@43340
   214
      from ln_eq_minus_one[OF _ this] `D t \<noteq> 0` `0 \<le> D t` `D t \<noteq> 1`
hoelzl@43340
   215
      show False by auto
hoelzl@43340
   216
    qed
hoelzl@43340
   217
hoelzl@47694
   218
    show "AE t in M. D t - indicator ?D_set t \<le> D t * (ln b * log b (D t))"
hoelzl@47694
   219
      using D(2) AE_space
hoelzl@47694
   220
    proof eventually_elim
hoelzl@47694
   221
      fix t assume "t \<in> space M" "0 \<le> D t"
hoelzl@47694
   222
      show "D t - indicator ?D_set t \<le> D t * (ln b * log b (D t))"
hoelzl@43340
   223
      proof cases
hoelzl@43340
   224
        assume asm: "D t \<noteq> 0"
hoelzl@43340
   225
        then have "0 < D t" using `0 \<le> D t` by auto
hoelzl@43340
   226
        then have "0 < 1 / D t" by auto
hoelzl@43340
   227
        have "D t - indicator ?D_set t \<le> - D t * (1 / D t - 1)"
hoelzl@43340
   228
          using asm `t \<in> space M` by (simp add: field_simps)
hoelzl@43340
   229
        also have "- D t * (1 / D t - 1) \<le> - D t * ln (1 / D t)"
hoelzl@43340
   230
          using ln_le_minus_one `0 < 1 / D t` by (intro mult_left_mono_neg) auto
hoelzl@47694
   231
        also have "\<dots> = D t * (ln b * log b (D t))"
hoelzl@47694
   232
          using `0 < D t` b_gt_1
hoelzl@47694
   233
          by (simp_all add: log_def ln_div)
hoelzl@43340
   234
        finally show ?thesis by simp
hoelzl@43340
   235
      qed simp
hoelzl@43340
   236
    qed
hoelzl@43340
   237
  qed
hoelzl@47694
   238
  also have "\<dots> = (\<integral> x. ln b * (D x * log b (D x)) \<partial>M)"
hoelzl@47694
   239
    by (simp add: ac_simps)
hoelzl@47694
   240
  also have "\<dots> = ln b * (\<integral> x. D x * log b (D x) \<partial>M)"
hoelzl@47694
   241
    using int by (rule integral_cmult)
hoelzl@47694
   242
  finally show ?thesis
hoelzl@47694
   243
    using b_gt_1 D by (subst KL_density) (auto simp: zero_less_mult_iff)
hoelzl@43340
   244
qed
hoelzl@43340
   245
hoelzl@47694
   246
lemma (in sigma_finite_measure) KL_same_eq_0: "KL_divergence b M M = 0"
hoelzl@43340
   247
proof -
hoelzl@47694
   248
  have "AE x in M. 1 = RN_deriv M M x"
hoelzl@43340
   249
  proof (rule RN_deriv_unique)
hoelzl@47694
   250
    show "(\<lambda>x. 1) \<in> borel_measurable M" "AE x in M. 0 \<le> (1 :: ereal)" by auto
hoelzl@47694
   251
    show "density M (\<lambda>x. 1) = M"
hoelzl@47694
   252
      apply (auto intro!: measure_eqI emeasure_density)
hoelzl@47694
   253
      apply (subst emeasure_density)
hoelzl@47694
   254
      apply auto
hoelzl@47694
   255
      done
hoelzl@43340
   256
  qed
hoelzl@47694
   257
  then have "AE x in M. log b (real (RN_deriv M M x)) = 0"
hoelzl@43340
   258
    by (elim AE_mp) simp
hoelzl@43340
   259
  from integral_cong_AE[OF this]
hoelzl@47694
   260
  have "integral\<^isup>L M (entropy_density b M M) = 0"
hoelzl@43340
   261
    by (simp add: entropy_density_def comp_def)
hoelzl@47694
   262
  then show "KL_divergence b M M = 0"
hoelzl@43340
   263
    unfolding KL_divergence_def
hoelzl@47694
   264
    by auto
hoelzl@43340
   265
qed
hoelzl@43340
   266
hoelzl@47694
   267
lemma (in information_space) KL_eq_0_iff_eq:
hoelzl@47694
   268
  fixes D :: "'a \<Rightarrow> real"
hoelzl@47694
   269
  assumes "prob_space (density M D)"
hoelzl@47694
   270
  assumes D: "D \<in> borel_measurable M" "AE x in M. 0 \<le> D x"
hoelzl@47694
   271
  assumes int: "integrable M (\<lambda>x. D x * log b (D x))"
hoelzl@47694
   272
  shows "KL_divergence b M (density M D) = 0 \<longleftrightarrow> density M D = M"
hoelzl@47694
   273
  using KL_same_eq_0[of b] KL_gt_0[OF assms]
hoelzl@47694
   274
  by (auto simp: less_le)
hoelzl@43340
   275
hoelzl@47694
   276
lemma (in information_space) KL_eq_0_iff_eq_ac:
hoelzl@47694
   277
  fixes D :: "'a \<Rightarrow> real"
hoelzl@47694
   278
  assumes "prob_space N"
hoelzl@47694
   279
  assumes ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@47694
   280
  assumes int: "integrable N (entropy_density b M N)"
hoelzl@47694
   281
  shows "KL_divergence b M N = 0 \<longleftrightarrow> N = M"
hoelzl@41833
   282
proof -
hoelzl@47694
   283
  interpret N: prob_space N by fact
hoelzl@47694
   284
  have "finite_measure N" by unfold_locales
hoelzl@47694
   285
  from real_RN_deriv[OF this ac] guess D . note D = this
hoelzl@47694
   286
  
hoelzl@47694
   287
  have "N = density M (RN_deriv M N)"
hoelzl@47694
   288
    using ac by (rule density_RN_deriv[symmetric])
hoelzl@47694
   289
  also have "\<dots> = density M D"
hoelzl@47694
   290
    using borel_measurable_RN_deriv[OF ac] D by (auto intro!: density_cong)
hoelzl@47694
   291
  finally have N: "N = density M D" .
hoelzl@41833
   292
hoelzl@47694
   293
  from absolutely_continuous_AE[OF ac(2,1) D(2)] D b_gt_1 ac measurable_entropy_density
hoelzl@47694
   294
  have "integrable N (\<lambda>x. log b (D x))"
hoelzl@47694
   295
    by (intro integrable_cong_AE[THEN iffD2, OF _ _ _ int])
hoelzl@47694
   296
       (auto simp: N entropy_density_def)
hoelzl@47694
   297
  with D b_gt_1 have "integrable M (\<lambda>x. D x * log b (D x))"
hoelzl@47694
   298
    by (subst integral_density(2)[symmetric]) (auto simp: N[symmetric] comp_def)
hoelzl@47694
   299
  with `prob_space N` D show ?thesis
hoelzl@47694
   300
    unfolding N
hoelzl@47694
   301
    by (intro KL_eq_0_iff_eq) auto
hoelzl@41833
   302
qed
hoelzl@41833
   303
hoelzl@47694
   304
lemma (in information_space) KL_nonneg:
hoelzl@47694
   305
  assumes "prob_space (density M D)"
hoelzl@47694
   306
  assumes D: "D \<in> borel_measurable M" "AE x in M. 0 \<le> D x"
hoelzl@47694
   307
  assumes int: "integrable M (\<lambda>x. D x * log b (D x))"
hoelzl@47694
   308
  shows "0 \<le> KL_divergence b M (density M D)"
hoelzl@47694
   309
  using KL_gt_0[OF assms] by (cases "density M D = M") (auto simp: KL_same_eq_0)
hoelzl@40859
   310
hoelzl@47694
   311
lemma (in sigma_finite_measure) KL_density_density_nonneg:
hoelzl@47694
   312
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@47694
   313
  assumes "1 < b"
hoelzl@47694
   314
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x" "prob_space (density M f)"
hoelzl@47694
   315
  assumes g: "g \<in> borel_measurable M" "AE x in M. 0 \<le> g x" "prob_space (density M g)"
hoelzl@47694
   316
  assumes ac: "AE x in M. f x = 0 \<longrightarrow> g x = 0"
hoelzl@47694
   317
  assumes int: "integrable M (\<lambda>x. g x * log b (g x / f x))"
hoelzl@47694
   318
  shows "0 \<le> KL_divergence b (density M f) (density M g)"
hoelzl@47694
   319
proof -
hoelzl@47694
   320
  interpret Mf: prob_space "density M f" by fact
hoelzl@47694
   321
  interpret Mf: information_space "density M f" b by default fact
hoelzl@47694
   322
  have eq: "density (density M f) (\<lambda>x. g x / f x) = density M g" (is "?DD = _")
hoelzl@47694
   323
    using f g ac by (subst density_density_divide) simp_all
hoelzl@36080
   324
hoelzl@47694
   325
  have "0 \<le> KL_divergence b (density M f) (density (density M f) (\<lambda>x. g x / f x))"
hoelzl@47694
   326
  proof (rule Mf.KL_nonneg)
hoelzl@47694
   327
    show "prob_space ?DD" unfolding eq by fact
hoelzl@47694
   328
    from f g show "(\<lambda>x. g x / f x) \<in> borel_measurable (density M f)"
hoelzl@47694
   329
      by auto
hoelzl@47694
   330
    show "AE x in density M f. 0 \<le> g x / f x"
hoelzl@47694
   331
      using f g by (auto simp: AE_density divide_nonneg_nonneg)
hoelzl@47694
   332
    show "integrable (density M f) (\<lambda>x. g x / f x * log b (g x / f x))"
hoelzl@47694
   333
      using `1 < b` f g ac
hoelzl@47694
   334
      by (subst integral_density)
hoelzl@47694
   335
         (auto intro!: integrable_cong_AE[THEN iffD2, OF _ _ _ int] measurable_If)
hoelzl@47694
   336
  qed
hoelzl@47694
   337
  also have "\<dots> = KL_divergence b (density M f) (density M g)"
hoelzl@47694
   338
    using f g ac by (subst density_density_divide) simp_all
hoelzl@47694
   339
  finally show ?thesis .
hoelzl@36080
   340
qed
hoelzl@36080
   341
hoelzl@39097
   342
subsection {* Mutual Information *}
hoelzl@39097
   343
hoelzl@36080
   344
definition (in prob_space)
hoelzl@38656
   345
  "mutual_information b S T X Y =
hoelzl@47694
   346
    KL_divergence b (distr M S X \<Otimes>\<^isub>M distr M T Y) (distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)))"
hoelzl@36080
   347
hoelzl@47694
   348
lemma (in information_space) mutual_information_indep_vars:
hoelzl@43340
   349
  fixes S T X Y
hoelzl@47694
   350
  defines "P \<equiv> distr M S X \<Otimes>\<^isub>M distr M T Y"
hoelzl@47694
   351
  defines "Q \<equiv> distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@43340
   352
  shows "indep_var S X T Y \<longleftrightarrow>
hoelzl@43340
   353
    (random_variable S X \<and> random_variable T Y \<and>
hoelzl@47694
   354
      absolutely_continuous P Q \<and> integrable Q (entropy_density b P Q) \<and>
hoelzl@47694
   355
      mutual_information b S T X Y = 0)"
hoelzl@47694
   356
  unfolding indep_var_distribution_eq
hoelzl@43340
   357
proof safe
hoelzl@47694
   358
  assume rv: "random_variable S X" "random_variable T Y"
hoelzl@43340
   359
hoelzl@47694
   360
  interpret X: prob_space "distr M S X"
hoelzl@47694
   361
    by (rule prob_space_distr) fact
hoelzl@47694
   362
  interpret Y: prob_space "distr M T Y"
hoelzl@47694
   363
    by (rule prob_space_distr) fact
hoelzl@47694
   364
  interpret XY: pair_prob_space "distr M S X" "distr M T Y" by default
hoelzl@47694
   365
  interpret P: information_space P b unfolding P_def by default (rule b_gt_1)
hoelzl@43340
   366
hoelzl@47694
   367
  interpret Q: prob_space Q unfolding Q_def
hoelzl@47694
   368
    by (rule prob_space_distr) (simp add: comp_def measurable_pair_iff rv)
hoelzl@43340
   369
hoelzl@47694
   370
  { assume "distr M S X \<Otimes>\<^isub>M distr M T Y = distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@47694
   371
    then have [simp]: "Q = P"  unfolding Q_def P_def by simp
hoelzl@43340
   372
hoelzl@47694
   373
    show ac: "absolutely_continuous P Q" by (simp add: absolutely_continuous_def)
hoelzl@47694
   374
    then have ed: "entropy_density b P Q \<in> borel_measurable P"
hoelzl@47694
   375
      by (rule P.measurable_entropy_density) simp
hoelzl@43340
   376
hoelzl@47694
   377
    have "AE x in P. 1 = RN_deriv P Q x"
hoelzl@47694
   378
    proof (rule P.RN_deriv_unique)
hoelzl@47694
   379
      show "density P (\<lambda>x. 1) = Q"
hoelzl@47694
   380
        unfolding `Q = P` by (intro measure_eqI) (auto simp: emeasure_density)
hoelzl@47694
   381
    qed auto
hoelzl@47694
   382
    then have ae_0: "AE x in P. entropy_density b P Q x = 0"
hoelzl@47694
   383
      by eventually_elim (auto simp: entropy_density_def)
hoelzl@47694
   384
    then have "integrable P (entropy_density b P Q) \<longleftrightarrow> integrable Q (\<lambda>x. 0)"
hoelzl@47694
   385
      using ed unfolding `Q = P` by (intro integrable_cong_AE) auto
hoelzl@47694
   386
    then show "integrable Q (entropy_density b P Q)" by simp
hoelzl@43340
   387
hoelzl@47694
   388
    show "mutual_information b S T X Y = 0"
hoelzl@47694
   389
      unfolding mutual_information_def KL_divergence_def P_def[symmetric] Q_def[symmetric] `Q = P`
hoelzl@47694
   390
      using ae_0 by (simp cong: integral_cong_AE) }
hoelzl@43340
   391
hoelzl@47694
   392
  { assume ac: "absolutely_continuous P Q"
hoelzl@47694
   393
    assume int: "integrable Q (entropy_density b P Q)"
hoelzl@47694
   394
    assume I_eq_0: "mutual_information b S T X Y = 0"
hoelzl@43340
   395
hoelzl@47694
   396
    have eq: "Q = P"
hoelzl@47694
   397
    proof (rule P.KL_eq_0_iff_eq_ac[THEN iffD1])
hoelzl@47694
   398
      show "prob_space Q" by unfold_locales
hoelzl@47694
   399
      show "absolutely_continuous P Q" by fact
hoelzl@47694
   400
      show "integrable Q (entropy_density b P Q)" by fact
hoelzl@47694
   401
      show "sets Q = sets P" by (simp add: P_def Q_def sets_pair_measure)
hoelzl@47694
   402
      show "KL_divergence b P Q = 0"
hoelzl@47694
   403
        using I_eq_0 unfolding mutual_information_def by (simp add: P_def Q_def)
hoelzl@47694
   404
    qed
hoelzl@47694
   405
    then show "distr M S X \<Otimes>\<^isub>M distr M T Y = distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@47694
   406
      unfolding P_def Q_def .. }
hoelzl@43340
   407
qed
hoelzl@43340
   408
hoelzl@40859
   409
abbreviation (in information_space)
hoelzl@40859
   410
  mutual_information_Pow ("\<I>'(_ ; _')") where
hoelzl@47694
   411
  "\<I>(X ; Y) \<equiv> mutual_information b (count_space (X`space M)) (count_space (Y`space M)) X Y"
hoelzl@41689
   412
hoelzl@47694
   413
lemma (in information_space)
hoelzl@47694
   414
  fixes Pxy :: "'b \<times> 'c \<Rightarrow> real" and Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@47694
   415
  assumes "sigma_finite_measure S" "sigma_finite_measure T"
hoelzl@47694
   416
  assumes Px: "distributed M S X Px" and Py: "distributed M T Y Py"
hoelzl@47694
   417
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
   418
  defines "f \<equiv> \<lambda>x. Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x)))"
hoelzl@47694
   419
  shows mutual_information_distr: "mutual_information b S T X Y = integral\<^isup>L (S \<Otimes>\<^isub>M T) f" (is "?M = ?R")
hoelzl@47694
   420
    and mutual_information_nonneg: "integrable (S \<Otimes>\<^isub>M T) f \<Longrightarrow> 0 \<le> mutual_information b S T X Y"
hoelzl@40859
   421
proof -
hoelzl@47694
   422
  have X: "random_variable S X"
hoelzl@47694
   423
    using Px by (auto simp: distributed_def)
hoelzl@47694
   424
  have Y: "random_variable T Y"
hoelzl@47694
   425
    using Py by (auto simp: distributed_def)
hoelzl@47694
   426
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
   427
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
   428
  interpret ST: pair_sigma_finite S T ..
hoelzl@47694
   429
  interpret X: prob_space "distr M S X" using X by (rule prob_space_distr)
hoelzl@47694
   430
  interpret Y: prob_space "distr M T Y" using Y by (rule prob_space_distr)
hoelzl@47694
   431
  interpret XY: pair_prob_space "distr M S X" "distr M T Y" ..
hoelzl@47694
   432
  let ?P = "S \<Otimes>\<^isub>M T"
hoelzl@47694
   433
  let ?D = "distr M ?P (\<lambda>x. (X x, Y x))"
hoelzl@47694
   434
hoelzl@47694
   435
  { fix A assume "A \<in> sets S"
hoelzl@47694
   436
    with X Y have "emeasure (distr M S X) A = emeasure ?D (A \<times> space T)"
hoelzl@47694
   437
      by (auto simp: emeasure_distr measurable_Pair measurable_space
hoelzl@47694
   438
               intro!: arg_cong[where f="emeasure M"]) }
hoelzl@47694
   439
  note marginal_eq1 = this
hoelzl@47694
   440
  { fix A assume "A \<in> sets T"
hoelzl@47694
   441
    with X Y have "emeasure (distr M T Y) A = emeasure ?D (space S \<times> A)"
hoelzl@47694
   442
      by (auto simp: emeasure_distr measurable_Pair measurable_space
hoelzl@47694
   443
               intro!: arg_cong[where f="emeasure M"]) }
hoelzl@47694
   444
  note marginal_eq2 = this
hoelzl@47694
   445
hoelzl@47694
   446
  have eq: "(\<lambda>x. ereal (Px (fst x) * Py (snd x))) = (\<lambda>(x, y). ereal (Px x) * ereal (Py y))"
hoelzl@47694
   447
    by auto
hoelzl@47694
   448
hoelzl@47694
   449
  have distr_eq: "distr M S X \<Otimes>\<^isub>M distr M T Y = density ?P (\<lambda>x. ereal (Px (fst x) * Py (snd x)))"
hoelzl@47694
   450
    unfolding Px(1)[THEN distributed_distr_eq_density] Py(1)[THEN distributed_distr_eq_density] eq
hoelzl@47694
   451
  proof (subst pair_measure_density)
hoelzl@47694
   452
    show "(\<lambda>x. ereal (Px x)) \<in> borel_measurable S" "(\<lambda>y. ereal (Py y)) \<in> borel_measurable T"
hoelzl@47694
   453
      "AE x in S. 0 \<le> ereal (Px x)" "AE y in T. 0 \<le> ereal (Py y)"
hoelzl@47694
   454
      using Px Py by (auto simp: distributed_def)
hoelzl@47694
   455
    show "sigma_finite_measure (density S Px)" unfolding Px(1)[THEN distributed_distr_eq_density, symmetric] ..
hoelzl@47694
   456
    show "sigma_finite_measure (density T Py)" unfolding Py(1)[THEN distributed_distr_eq_density, symmetric] ..
hoelzl@47694
   457
  qed (fact | simp)+
hoelzl@47694
   458
  
hoelzl@47694
   459
  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
   460
    unfolding mutual_information_def distr_eq Pxy(1)[THEN distributed_distr_eq_density] ..
hoelzl@47694
   461
hoelzl@47694
   462
  from Px Py have f: "(\<lambda>x. Px (fst x) * Py (snd x)) \<in> borel_measurable ?P"
hoelzl@47694
   463
    by (intro borel_measurable_times) (auto intro: distributed_real_measurable measurable_fst'' measurable_snd'')
hoelzl@47694
   464
  have PxPy_nonneg: "AE x in ?P. 0 \<le> Px (fst x) * Py (snd x)"
hoelzl@47694
   465
  proof (rule ST.AE_pair_measure)
hoelzl@47694
   466
    show "{x \<in> space ?P. 0 \<le> Px (fst x) * Py (snd x)} \<in> sets ?P"
hoelzl@47694
   467
      using f by auto
hoelzl@47694
   468
    show "AE x in S. AE y in T. 0 \<le> Px (fst (x, y)) * Py (snd (x, y))"
hoelzl@47694
   469
      using Px Py by (auto simp: zero_le_mult_iff dest!: distributed_real_AE)
hoelzl@47694
   470
  qed
hoelzl@47694
   471
hoelzl@47694
   472
  have "(AE x in ?P. Px (fst x) = 0 \<longrightarrow> Pxy x = 0)"
hoelzl@47694
   473
    by (rule subdensity_real[OF measurable_fst Pxy Px]) auto
hoelzl@47694
   474
  moreover
hoelzl@47694
   475
  have "(AE x in ?P. Py (snd x) = 0 \<longrightarrow> Pxy x = 0)"
hoelzl@47694
   476
    by (rule subdensity_real[OF measurable_snd Pxy Py]) auto
hoelzl@47694
   477
  ultimately have ac: "AE x in ?P. Px (fst x) * Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
   478
    by eventually_elim auto
hoelzl@47694
   479
hoelzl@47694
   480
  show "?M = ?R"
hoelzl@47694
   481
    unfolding M f_def
hoelzl@47694
   482
    using b_gt_1 f PxPy_nonneg Pxy[THEN distributed_real_measurable] Pxy[THEN distributed_real_AE] ac
hoelzl@47694
   483
    by (rule ST.KL_density_density)
hoelzl@47694
   484
hoelzl@47694
   485
  assume int: "integrable (S \<Otimes>\<^isub>M T) f"
hoelzl@47694
   486
  show "0 \<le> ?M" unfolding M
hoelzl@47694
   487
  proof (rule ST.KL_density_density_nonneg
hoelzl@47694
   488
    [OF b_gt_1 f PxPy_nonneg _ Pxy[THEN distributed_real_measurable] Pxy[THEN distributed_real_AE] _ ac int[unfolded f_def]])
hoelzl@47694
   489
    show "prob_space (density (S \<Otimes>\<^isub>M T) (\<lambda>x. ereal (Pxy x))) "
hoelzl@47694
   490
      unfolding distributed_distr_eq_density[OF Pxy, symmetric]
hoelzl@47694
   491
      using distributed_measurable[OF Pxy] by (rule prob_space_distr)
hoelzl@47694
   492
    show "prob_space (density (S \<Otimes>\<^isub>M T) (\<lambda>x. ereal (Px (fst x) * Py (snd x))))"
hoelzl@47694
   493
      unfolding distr_eq[symmetric] by unfold_locales
hoelzl@40859
   494
  qed
hoelzl@40859
   495
qed
hoelzl@40859
   496
hoelzl@40859
   497
lemma (in information_space)
hoelzl@47694
   498
  fixes Pxy :: "'b \<times> 'c \<Rightarrow> real" and Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@47694
   499
  assumes "sigma_finite_measure S" "sigma_finite_measure T"
hoelzl@47694
   500
  assumes Px: "distributed M S X Px" and Py: "distributed M T Y Py"
hoelzl@47694
   501
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
   502
  assumes ae: "AE x in S. AE y in T. Pxy (x, y) = Px x * Py y"
hoelzl@47694
   503
  shows mutual_information_eq_0: "mutual_information b S T X Y = 0"
hoelzl@36624
   504
proof -
hoelzl@47694
   505
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
   506
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
   507
  interpret ST: pair_sigma_finite S T ..
hoelzl@36080
   508
hoelzl@47694
   509
  have "AE x in S \<Otimes>\<^isub>M T. Px (fst x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
   510
    by (rule subdensity_real[OF measurable_fst Pxy Px]) auto
hoelzl@47694
   511
  moreover
hoelzl@47694
   512
  have "AE x in S \<Otimes>\<^isub>M T. Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
   513
    by (rule subdensity_real[OF measurable_snd Pxy Py]) auto
hoelzl@47694
   514
  moreover 
hoelzl@47694
   515
  have "AE x in S \<Otimes>\<^isub>M T. Pxy x = Px (fst x) * Py (snd x)"
hoelzl@47694
   516
    using distributed_real_measurable[OF Px] distributed_real_measurable[OF Py] distributed_real_measurable[OF Pxy]
hoelzl@47694
   517
    by (intro ST.AE_pair_measure) (auto simp: ae intro!: measurable_snd'' measurable_fst'')
hoelzl@47694
   518
  ultimately have "AE x in S \<Otimes>\<^isub>M T. Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x))) = 0"
hoelzl@47694
   519
    by eventually_elim simp
hoelzl@47694
   520
  then have "(\<integral>x. Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x))) \<partial>(S \<Otimes>\<^isub>M T)) = (\<integral>x. 0 \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@47694
   521
    by (rule integral_cong_AE)
hoelzl@47694
   522
  then show ?thesis
hoelzl@47694
   523
    by (subst mutual_information_distr[OF assms(1-5)]) simp
hoelzl@36080
   524
qed
hoelzl@36080
   525
hoelzl@47694
   526
lemma (in information_space) mutual_information_simple_distributed:
hoelzl@47694
   527
  assumes X: "simple_distributed M X Px" and Y: "simple_distributed M Y Py"
hoelzl@47694
   528
  assumes XY: "simple_distributed M (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
   529
  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
   530
proof (subst mutual_information_distr[OF _ _ simple_distributed[OF X] simple_distributed[OF Y] simple_distributed_joint[OF XY]])
hoelzl@47694
   531
  note fin = simple_distributed_joint_finite[OF XY, simp]
hoelzl@47694
   532
  show "sigma_finite_measure (count_space (X ` space M))"
hoelzl@47694
   533
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
   534
  show "sigma_finite_measure (count_space (Y ` space M))"
hoelzl@47694
   535
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
   536
  let ?Pxy = "\<lambda>x. (if x \<in> (\<lambda>x. (X x, Y x)) ` space M then Pxy x else 0)"
hoelzl@47694
   537
  let ?f = "\<lambda>x. ?Pxy x * log b (?Pxy x / (Px (fst x) * Py (snd x)))"
hoelzl@47694
   538
  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
   539
    by auto
hoelzl@47694
   540
  with fin show "(\<integral> x. ?f x \<partial>(count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M))) =
hoelzl@47694
   541
    (\<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
   542
    by (auto simp add: pair_measure_count_space lebesgue_integral_count_space_finite setsum_cases split_beta'
hoelzl@47694
   543
             intro!: setsum_cong)
hoelzl@47694
   544
qed
hoelzl@36080
   545
hoelzl@47694
   546
lemma (in information_space)
hoelzl@47694
   547
  fixes Pxy :: "'b \<times> 'c \<Rightarrow> real" and Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@47694
   548
  assumes Px: "simple_distributed M X Px" and Py: "simple_distributed M Y Py"
hoelzl@47694
   549
  assumes Pxy: "simple_distributed M (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
   550
  assumes ae: "\<forall>x\<in>space M. Pxy (X x, Y x) = Px (X x) * Py (Y x)"
hoelzl@47694
   551
  shows mutual_information_eq_0_simple: "\<I>(X ; Y) = 0"
hoelzl@47694
   552
proof (subst mutual_information_simple_distributed[OF Px Py Pxy])
hoelzl@47694
   553
  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
   554
    (\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` space M. 0)"
hoelzl@47694
   555
    by (intro setsum_cong) (auto simp: ae)
hoelzl@47694
   556
  then show "(\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` space M.
hoelzl@47694
   557
    Pxy (x, y) * log b (Pxy (x, y) / (Px x * Py y))) = 0" by simp
hoelzl@47694
   558
qed
hoelzl@36080
   559
hoelzl@39097
   560
subsection {* Entropy *}
hoelzl@39097
   561
hoelzl@47694
   562
definition (in prob_space) entropy :: "real \<Rightarrow> 'b measure \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> real" where
hoelzl@47694
   563
  "entropy b S X = - KL_divergence b S (distr M S X)"
hoelzl@47694
   564
hoelzl@40859
   565
abbreviation (in information_space)
hoelzl@40859
   566
  entropy_Pow ("\<H>'(_')") where
hoelzl@47694
   567
  "\<H>(X) \<equiv> entropy b (count_space (X`space M)) X"
hoelzl@41981
   568
hoelzl@47694
   569
lemma (in information_space) entropy_distr:
hoelzl@47694
   570
  fixes X :: "'a \<Rightarrow> 'b"
hoelzl@49785
   571
  assumes X: "distributed M MX X f"
hoelzl@47694
   572
  shows "entropy b MX X = - (\<integral>x. f x * log b (f x) \<partial>MX)"
hoelzl@49785
   573
  unfolding entropy_def KL_divergence_def entropy_density_def comp_def
hoelzl@49785
   574
proof (subst integral_cong_AE)
hoelzl@49785
   575
  note D = distributed_measurable[OF X] distributed_borel_measurable[OF X] distributed_AE[OF X]
hoelzl@49785
   576
  interpret X: prob_space "distr M MX X"
hoelzl@49785
   577
    using D(1) by (rule prob_space_distr)
hoelzl@49785
   578
hoelzl@49785
   579
  have sf: "sigma_finite_measure (distr M MX X)" by default
hoelzl@49785
   580
  have ae: "AE x in MX. f x = RN_deriv MX (density MX f) x"
hoelzl@49785
   581
    using D
hoelzl@49785
   582
    by (intro RN_deriv_unique_sigma_finite)
hoelzl@49785
   583
       (auto intro: divide_nonneg_nonneg measure_nonneg
hoelzl@49785
   584
             simp: distributed_distr_eq_density[symmetric, OF X] sf)
hoelzl@49785
   585
  show "AE x in distr M MX X. log b (real (RN_deriv MX (distr M MX X) x)) =
hoelzl@49785
   586
    log b (f x)"
hoelzl@49785
   587
    unfolding distributed_distr_eq_density[OF X]
hoelzl@49785
   588
    apply (subst AE_density)
hoelzl@49785
   589
    using D apply simp
hoelzl@49785
   590
    using ae apply eventually_elim
hoelzl@49785
   591
    apply (subst (asm) eq_commute)
hoelzl@49785
   592
    apply auto
hoelzl@49785
   593
    done
hoelzl@49785
   594
  show "- (\<integral> x. log b (f x) \<partial>distr M MX X) = - (\<integral> x. f x * log b (f x) \<partial>MX)"
hoelzl@49785
   595
    unfolding distributed_distr_eq_density[OF X]
hoelzl@49785
   596
    using D
hoelzl@49785
   597
    by (subst integral_density)
hoelzl@49785
   598
       (auto simp: borel_measurable_ereal_iff)
hoelzl@49785
   599
qed 
hoelzl@49785
   600
hoelzl@49786
   601
lemma (in prob_space) distributed_imp_emeasure_nonzero:
hoelzl@49786
   602
  assumes X: "distributed M MX X Px"
hoelzl@49786
   603
  shows "emeasure MX {x \<in> space MX. Px x \<noteq> 0} \<noteq> 0"
hoelzl@49786
   604
proof
hoelzl@49786
   605
  note Px = distributed_borel_measurable[OF X] distributed_AE[OF X]
hoelzl@49786
   606
  interpret X: prob_space "distr M MX X"
hoelzl@49786
   607
    using distributed_measurable[OF X] by (rule prob_space_distr)
hoelzl@49786
   608
hoelzl@49786
   609
  assume "emeasure MX {x \<in> space MX. Px x \<noteq> 0} = 0"
hoelzl@49786
   610
  with Px have "AE x in MX. Px x = 0"
hoelzl@49786
   611
    by (intro AE_I[OF subset_refl]) (auto simp: borel_measurable_ereal_iff)
hoelzl@49786
   612
  moreover
hoelzl@49786
   613
  from X.emeasure_space_1 have "(\<integral>\<^isup>+x. Px x \<partial>MX) = 1"
hoelzl@49786
   614
    unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   615
    by (subst (asm) emeasure_density)
hoelzl@49786
   616
       (auto simp: borel_measurable_ereal_iff intro!: integral_cong cong: positive_integral_cong)
hoelzl@49786
   617
  ultimately show False
hoelzl@49786
   618
    by (simp add: positive_integral_cong_AE)
hoelzl@49786
   619
qed
hoelzl@49786
   620
hoelzl@49786
   621
lemma (in information_space) entropy_le:
hoelzl@49786
   622
  fixes Px :: "'b \<Rightarrow> real" and MX :: "'b measure"
hoelzl@49786
   623
  assumes X: "distributed M MX X Px"
hoelzl@49786
   624
  and fin: "emeasure MX {x \<in> space MX. Px x \<noteq> 0} \<noteq> \<infinity>"
hoelzl@49786
   625
  and int: "integrable MX (\<lambda>x. - Px x * log b (Px x))"
hoelzl@49786
   626
  shows "entropy b MX X \<le> log b (measure MX {x \<in> space MX. Px x \<noteq> 0})"
hoelzl@49786
   627
proof -
hoelzl@49786
   628
  note Px = distributed_borel_measurable[OF X] distributed_AE[OF X]
hoelzl@49786
   629
  interpret X: prob_space "distr M MX X"
hoelzl@49786
   630
    using distributed_measurable[OF X] by (rule prob_space_distr)
hoelzl@49786
   631
hoelzl@49786
   632
  have " - log b (measure MX {x \<in> space MX. Px x \<noteq> 0}) = 
hoelzl@49786
   633
    - log b (\<integral> x. indicator {x \<in> space MX. Px x \<noteq> 0} x \<partial>MX)"
hoelzl@49786
   634
    using Px fin
hoelzl@49786
   635
    by (subst integral_indicator) (auto simp: measure_def borel_measurable_ereal_iff)
hoelzl@49786
   636
  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
   637
    unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   638
    apply (intro arg_cong[where f="log b"] arg_cong[where f=uminus])
hoelzl@49786
   639
    by (subst integral_density) (auto simp: borel_measurable_ereal_iff intro!: integral_cong)
hoelzl@49786
   640
  also have "\<dots> \<le> (\<integral> x. - log b (1 / Px x) \<partial>distr M MX X)"
hoelzl@49786
   641
  proof (rule X.jensens_inequality[of "\<lambda>x. 1 / Px x" "{0<..}" 0 1 "\<lambda>x. - log b x"])
hoelzl@49786
   642
    show "AE x in distr M MX X. 1 / Px x \<in> {0<..}"
hoelzl@49786
   643
      unfolding distributed_distr_eq_density[OF X]
hoelzl@49786
   644
      using Px by (auto simp: AE_density)
hoelzl@49786
   645
    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
   646
      by (auto simp: one_ereal_def)
hoelzl@49786
   647
    have "(\<integral>\<^isup>+ x. max 0 (ereal (- (if Px x = 0 then 0 else 1))) \<partial>MX) = (\<integral>\<^isup>+ x. 0 \<partial>MX)"
hoelzl@49786
   648
      by (intro positive_integral_cong) (auto split: split_max)
hoelzl@49786
   649
    then show "integrable (distr M MX X) (\<lambda>x. 1 / Px x)"
hoelzl@49786
   650
      unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   651
      by (auto simp: positive_integral_density integrable_def borel_measurable_ereal_iff fin positive_integral_max_0
hoelzl@49786
   652
              cong: positive_integral_cong)
hoelzl@49786
   653
    have "integrable MX (\<lambda>x. Px x * log b (1 / Px x)) =
hoelzl@49786
   654
      integrable MX (\<lambda>x. - Px x * log b (Px x))"
hoelzl@49786
   655
      using Px
hoelzl@49786
   656
      by (intro integrable_cong_AE)
hoelzl@49786
   657
         (auto simp: borel_measurable_ereal_iff log_divide_eq
hoelzl@49786
   658
                  intro!: measurable_If)
hoelzl@49786
   659
    then show "integrable (distr M MX X) (\<lambda>x. - log b (1 / Px x))"
hoelzl@49786
   660
      unfolding distributed_distr_eq_density[OF X]
hoelzl@49786
   661
      using Px int
hoelzl@49786
   662
      by (subst integral_density) (auto simp: borel_measurable_ereal_iff)
hoelzl@49786
   663
  qed (auto simp: minus_log_convex[OF b_gt_1])
hoelzl@49786
   664
  also have "\<dots> = (\<integral> x. log b (Px x) \<partial>distr M MX X)"
hoelzl@49786
   665
    unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   666
    by (intro integral_cong_AE) (auto simp: AE_density log_divide_eq)
hoelzl@49786
   667
  also have "\<dots> = - entropy b MX X"
hoelzl@49786
   668
    unfolding distributed_distr_eq_density[OF X] using Px
hoelzl@49786
   669
    by (subst entropy_distr[OF X]) (auto simp: borel_measurable_ereal_iff integral_density)
hoelzl@49786
   670
  finally show ?thesis
hoelzl@49786
   671
    by simp
hoelzl@49786
   672
qed
hoelzl@49786
   673
hoelzl@49786
   674
lemma (in information_space) entropy_le_space:
hoelzl@49786
   675
  fixes Px :: "'b \<Rightarrow> real" and MX :: "'b measure"
hoelzl@49786
   676
  assumes X: "distributed M MX X Px"
hoelzl@49786
   677
  and fin: "finite_measure MX"
hoelzl@49786
   678
  and int: "integrable MX (\<lambda>x. - Px x * log b (Px x))"
hoelzl@49786
   679
  shows "entropy b MX X \<le> log b (measure MX (space MX))"
hoelzl@49786
   680
proof -
hoelzl@49786
   681
  note Px = distributed_borel_measurable[OF X] distributed_AE[OF X]
hoelzl@49786
   682
  interpret finite_measure MX by fact
hoelzl@49786
   683
  have "entropy b MX X \<le> log b (measure MX {x \<in> space MX. Px x \<noteq> 0})"
hoelzl@49786
   684
    using int X by (intro entropy_le) auto
hoelzl@49786
   685
  also have "\<dots> \<le> log b (measure MX (space MX))"
hoelzl@49786
   686
    using Px distributed_imp_emeasure_nonzero[OF X]
hoelzl@49786
   687
    by (intro log_le)
hoelzl@49786
   688
       (auto intro!: borel_measurable_ereal_iff finite_measure_mono b_gt_1
hoelzl@49786
   689
                     less_le[THEN iffD2] measure_nonneg simp: emeasure_eq_measure)
hoelzl@49786
   690
  finally show ?thesis .
hoelzl@49786
   691
qed
hoelzl@49786
   692
hoelzl@49785
   693
lemma (in prob_space) uniform_distributed_params:
hoelzl@49785
   694
  assumes X: "distributed M MX X (\<lambda>x. indicator A x / measure MX A)"
hoelzl@49785
   695
  shows "A \<in> sets MX" "measure MX A \<noteq> 0"
hoelzl@47694
   696
proof -
hoelzl@49785
   697
  interpret X: prob_space "distr M MX X"
hoelzl@49785
   698
    using distributed_measurable[OF X] by (rule prob_space_distr)
hoelzl@49785
   699
hoelzl@49785
   700
  show "measure MX A \<noteq> 0"
hoelzl@49785
   701
  proof
hoelzl@49785
   702
    assume "measure MX A = 0"
hoelzl@49785
   703
    with X.emeasure_space_1 X.prob_space distributed_distr_eq_density[OF X]
hoelzl@49785
   704
    show False
hoelzl@49785
   705
      by (simp add: emeasure_density zero_ereal_def[symmetric])
hoelzl@49785
   706
  qed
hoelzl@49785
   707
  with measure_notin_sets[of A MX] show "A \<in> sets MX"
hoelzl@49785
   708
    by blast
hoelzl@39097
   709
qed
hoelzl@36624
   710
hoelzl@47694
   711
lemma (in information_space) entropy_uniform:
hoelzl@49785
   712
  assumes X: "distributed M MX X (\<lambda>x. indicator A x / measure MX A)" (is "distributed _ _ _ ?f")
hoelzl@47694
   713
  shows "entropy b MX X = log b (measure MX A)"
hoelzl@49785
   714
proof (subst entropy_distr[OF X])
hoelzl@49785
   715
  have [simp]: "emeasure MX A \<noteq> \<infinity>"
hoelzl@49785
   716
    using uniform_distributed_params[OF X] by (auto simp add: measure_def)
hoelzl@49785
   717
  have eq: "(\<integral> x. indicator A x / measure MX A * log b (indicator A x / measure MX A) \<partial>MX) =
hoelzl@49785
   718
    (\<integral> x. (- log b (measure MX A) / measure MX A) * indicator A x \<partial>MX)"
hoelzl@49785
   719
    using measure_nonneg[of MX A] uniform_distributed_params[OF X]
hoelzl@49785
   720
    by (auto intro!: integral_cong split: split_indicator simp: log_divide_eq)
hoelzl@49785
   721
  show "- (\<integral> x. indicator A x / measure MX A * log b (indicator A x / measure MX A) \<partial>MX) =
hoelzl@49785
   722
    log b (measure MX A)"
hoelzl@49785
   723
    unfolding eq using uniform_distributed_params[OF X]
hoelzl@49785
   724
    by (subst lebesgue_integral_cmult) (auto simp: measure_def)
hoelzl@49785
   725
qed
hoelzl@36080
   726
hoelzl@47694
   727
lemma (in information_space) entropy_simple_distributed:
hoelzl@49786
   728
  "simple_distributed M X f \<Longrightarrow> \<H>(X) = - (\<Sum>x\<in>X`space M. f x * log b (f x))"
hoelzl@49786
   729
  by (subst entropy_distr[OF simple_distributed])
hoelzl@49786
   730
     (auto simp add: lebesgue_integral_count_space_finite)
hoelzl@39097
   731
hoelzl@40859
   732
lemma (in information_space) entropy_le_card_not_0:
hoelzl@47694
   733
  assumes X: "simple_distributed M X f"
hoelzl@47694
   734
  shows "\<H>(X) \<le> log b (card (X ` space M \<inter> {x. f x \<noteq> 0}))"
hoelzl@39097
   735
proof -
hoelzl@49787
   736
  let ?X = "count_space (X`space M)"
hoelzl@49787
   737
  have "\<H>(X) \<le> log b (measure ?X {x \<in> space ?X. f x \<noteq> 0})"
hoelzl@49787
   738
    by (rule entropy_le[OF simple_distributed[OF X]])
hoelzl@49787
   739
       (simp_all add: simple_distributed_finite[OF X] subset_eq integrable_count_space emeasure_count_space)
hoelzl@49787
   740
  also have "measure ?X {x \<in> space ?X. f x \<noteq> 0} = card (X ` space M \<inter> {x. f x \<noteq> 0})"
hoelzl@49787
   741
    by (simp_all add: simple_distributed_finite[OF X] subset_eq emeasure_count_space measure_def Int_def)
hoelzl@49787
   742
  finally show ?thesis .
hoelzl@39097
   743
qed
hoelzl@39097
   744
hoelzl@40859
   745
lemma (in information_space) entropy_le_card:
hoelzl@49787
   746
  assumes X: "simple_distributed M X f"
hoelzl@40859
   747
  shows "\<H>(X) \<le> log b (real (card (X ` space M)))"
hoelzl@49787
   748
proof -
hoelzl@49787
   749
  let ?X = "count_space (X`space M)"
hoelzl@49787
   750
  have "\<H>(X) \<le> log b (measure ?X (space ?X))"
hoelzl@49787
   751
    by (rule entropy_le_space[OF simple_distributed[OF X]])
hoelzl@49787
   752
       (simp_all add: simple_distributed_finite[OF X] subset_eq integrable_count_space emeasure_count_space finite_measure_count_space)
hoelzl@49787
   753
  also have "measure ?X (space ?X) = card (X ` space M)"
hoelzl@49787
   754
    by (simp_all add: simple_distributed_finite[OF X] subset_eq emeasure_count_space measure_def)
hoelzl@39097
   755
  finally show ?thesis .
hoelzl@39097
   756
qed
hoelzl@39097
   757
hoelzl@39097
   758
subsection {* Conditional Mutual Information *}
hoelzl@39097
   759
hoelzl@36080
   760
definition (in prob_space)
hoelzl@41689
   761
  "conditional_mutual_information b MX MY MZ X Y Z \<equiv>
hoelzl@41689
   762
    mutual_information b MX (MY \<Otimes>\<^isub>M MZ) X (\<lambda>x. (Y x, Z x)) -
hoelzl@41689
   763
    mutual_information b MX MZ X Z"
hoelzl@36080
   764
hoelzl@40859
   765
abbreviation (in information_space)
hoelzl@40859
   766
  conditional_mutual_information_Pow ("\<I>'( _ ; _ | _ ')") where
hoelzl@36624
   767
  "\<I>(X ; Y | Z) \<equiv> conditional_mutual_information b
hoelzl@47694
   768
    (count_space (X ` space M)) (count_space (Y ` space M)) (count_space (Z ` space M)) X Y Z"
hoelzl@36080
   769
hoelzl@49787
   770
lemma (in pair_sigma_finite) borel_measurable_positive_integral_fst:
hoelzl@49787
   771
  "(\<lambda>(x, y). f x y) \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2) \<Longrightarrow> (\<lambda>x. \<integral>\<^isup>+ y. f x y \<partial>M2) \<in> borel_measurable M1"
hoelzl@49787
   772
  using positive_integral_fst_measurable(1)[of "\<lambda>(x, y). f x y"] by simp
hoelzl@49787
   773
hoelzl@49787
   774
lemma (in pair_sigma_finite) borel_measurable_positive_integral_snd:
hoelzl@49787
   775
  assumes "(\<lambda>(x, y). f x y) \<in> borel_measurable (M2 \<Otimes>\<^isub>M M1)" shows "(\<lambda>x. \<integral>\<^isup>+ y. f x y \<partial>M1) \<in> borel_measurable M2"
hoelzl@49787
   776
proof -
hoelzl@49787
   777
  interpret Q: pair_sigma_finite M2 M1 by default
hoelzl@49787
   778
  from Q.borel_measurable_positive_integral_fst assms show ?thesis by simp
hoelzl@49787
   779
qed
hoelzl@49787
   780
hoelzl@49787
   781
lemma (in information_space)
hoelzl@47694
   782
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T" and P: "sigma_finite_measure P"
hoelzl@47694
   783
  assumes Px: "distributed M S X Px"
hoelzl@47694
   784
  assumes Pz: "distributed M P Z Pz"
hoelzl@47694
   785
  assumes Pyz: "distributed M (T \<Otimes>\<^isub>M P) (\<lambda>x. (Y x, Z x)) Pyz"
hoelzl@47694
   786
  assumes Pxz: "distributed M (S \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Z x)) Pxz"
hoelzl@47694
   787
  assumes Pxyz: "distributed M (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Y x, Z x)) Pxyz"
hoelzl@47694
   788
  assumes I1: "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Px x * Pyz (y, z))))"
hoelzl@47694
   789
  assumes I2: "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxz (x, z) / (Px x * Pz z)))"
hoelzl@49787
   790
  shows conditional_mutual_information_generic_eq: "conditional_mutual_information b S T P X Y Z
hoelzl@49787
   791
    = (\<integral>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Pxz (x, z) * (Pyz (y,z) / Pz z))) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))" (is "?eq")
hoelzl@49787
   792
    and conditional_mutual_information_generic_nonneg: "0 \<le> conditional_mutual_information b S T P X Y Z" (is "?nonneg")
hoelzl@40859
   793
proof -
hoelzl@47694
   794
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
   795
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
   796
  interpret P: sigma_finite_measure P by fact
hoelzl@47694
   797
  interpret TP: pair_sigma_finite T P ..
hoelzl@47694
   798
  interpret SP: pair_sigma_finite S P ..
hoelzl@49787
   799
  interpret ST: pair_sigma_finite S T ..
hoelzl@47694
   800
  interpret SPT: pair_sigma_finite "S \<Otimes>\<^isub>M P" T ..
hoelzl@47694
   801
  interpret STP: pair_sigma_finite S "T \<Otimes>\<^isub>M P" ..
hoelzl@49787
   802
  interpret TPS: pair_sigma_finite "T \<Otimes>\<^isub>M P" S ..
hoelzl@47694
   803
  have TP: "sigma_finite_measure (T \<Otimes>\<^isub>M P)" ..
hoelzl@47694
   804
  have SP: "sigma_finite_measure (S \<Otimes>\<^isub>M P)" ..
hoelzl@47694
   805
  have YZ: "random_variable (T \<Otimes>\<^isub>M P) (\<lambda>x. (Y x, Z x))"
hoelzl@47694
   806
    using Pyz by (simp add: distributed_measurable)
hoelzl@47694
   807
hoelzl@47694
   808
  have Pxyz_f: "\<And>M f. f \<in> measurable M (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) \<Longrightarrow> (\<lambda>x. Pxyz (f x)) \<in> borel_measurable M"
hoelzl@47694
   809
    using measurable_comp[OF _ Pxyz[THEN distributed_real_measurable]] by (auto simp: comp_def)
hoelzl@47694
   810
hoelzl@47694
   811
  { fix f g h M
hoelzl@47694
   812
    assume f: "f \<in> measurable M S" and g: "g \<in> measurable M P" and h: "h \<in> measurable M (S \<Otimes>\<^isub>M P)"
hoelzl@47694
   813
    from measurable_comp[OF h Pxz[THEN distributed_real_measurable]]
hoelzl@47694
   814
         measurable_comp[OF f Px[THEN distributed_real_measurable]]
hoelzl@47694
   815
         measurable_comp[OF g Pz[THEN distributed_real_measurable]]
hoelzl@47694
   816
    have "(\<lambda>x. log b (Pxz (h x) / (Px (f x) * Pz (g x)))) \<in> borel_measurable M"
hoelzl@47694
   817
      by (simp add: comp_def b_gt_1) }
hoelzl@47694
   818
  note borel_log = this
hoelzl@47694
   819
hoelzl@47694
   820
  have measurable_cut: "(\<lambda>(x, y, z). (x, z)) \<in> measurable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (S \<Otimes>\<^isub>M P)"
hoelzl@47694
   821
    by (auto simp add: split_beta' comp_def intro!: measurable_Pair measurable_snd')
hoelzl@47694
   822
  
hoelzl@47694
   823
  from Pxz Pxyz have distr_eq: "distr M (S \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Z x)) =
hoelzl@47694
   824
    distr (distr M (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>x. (X x, Y x, Z x))) (S \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). (x, z))"
hoelzl@47694
   825
    by (subst distr_distr[OF measurable_cut]) (auto dest: distributed_measurable simp: comp_def)
hoelzl@40859
   826
hoelzl@47694
   827
  have "mutual_information b S P X Z =
hoelzl@47694
   828
    (\<integral>x. Pxz x * log b (Pxz x / (Px (fst x) * Pz (snd x))) \<partial>(S \<Otimes>\<^isub>M P))"
hoelzl@47694
   829
    by (rule mutual_information_distr[OF S P Px Pz Pxz])
hoelzl@47694
   830
  also have "\<dots> = (\<integral>(x,y,z). Pxyz (x,y,z) * log b (Pxz (x,z) / (Px x * Pz z)) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))"
hoelzl@47694
   831
    using b_gt_1 Pxz Px Pz
hoelzl@47694
   832
    by (subst distributed_transform_integral[OF Pxyz Pxz, where T="\<lambda>(x, y, z). (x, z)"])
hoelzl@47694
   833
       (auto simp: split_beta' intro!: measurable_Pair measurable_snd' measurable_snd'' measurable_fst'' borel_measurable_times
hoelzl@47694
   834
             dest!: distributed_real_measurable)
hoelzl@47694
   835
  finally have mi_eq:
hoelzl@47694
   836
    "mutual_information b S P X Z = (\<integral>(x,y,z). Pxyz (x,y,z) * log b (Pxz (x,z) / (Px x * Pz z)) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))" .
hoelzl@47694
   837
  
hoelzl@49787
   838
  have ae1: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Px (fst x) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@47694
   839
    by (intro subdensity_real[of fst, OF _ Pxyz Px]) auto
hoelzl@49787
   840
  moreover have ae2: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pz (snd (snd x)) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@47694
   841
    by (intro subdensity_real[of "\<lambda>x. snd (snd x)", OF _ Pxyz Pz]) (auto intro: measurable_snd')
hoelzl@49787
   842
  moreover have ae3: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pxz (fst x, snd (snd x)) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@47694
   843
    by (intro subdensity_real[of "\<lambda>x. (fst x, snd (snd x))", OF _ Pxyz Pxz]) (auto intro: measurable_Pair measurable_snd')
hoelzl@49787
   844
  moreover have ae4: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pyz (snd x) = 0 \<longrightarrow> Pxyz x = 0"
hoelzl@47694
   845
    by (intro subdensity_real[of snd, OF _ Pxyz Pyz]) (auto intro: measurable_Pair)
hoelzl@49787
   846
  moreover have ae5: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Px (fst x)"
hoelzl@47694
   847
    using Px by (intro STP.AE_pair_measure) (auto simp: comp_def intro!: measurable_fst'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49787
   848
  moreover have ae6: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Pyz (snd x)"
hoelzl@47694
   849
    using Pyz by (intro STP.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49787
   850
  moreover have ae7: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Pz (snd (snd x))"
hoelzl@47694
   851
    using Pz Pz[THEN distributed_real_measurable] by (auto intro!: measurable_snd'' TP.AE_pair_measure STP.AE_pair_measure AE_I2[of S] dest: distributed_real_AE)
hoelzl@49787
   852
  moreover have ae8: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. 0 \<le> Pxz (fst x, snd (snd x))"
hoelzl@47694
   853
    using Pxz[THEN distributed_real_AE, THEN SP.AE_pair]
hoelzl@47694
   854
    using measurable_comp[OF measurable_Pair[OF measurable_fst measurable_comp[OF measurable_snd measurable_snd]] Pxz[THEN distributed_real_measurable], of T]
hoelzl@47694
   855
    using measurable_comp[OF measurable_snd measurable_Pair2[OF Pxz[THEN distributed_real_measurable]], of _ T]
hoelzl@47694
   856
    by (auto intro!: TP.AE_pair_measure STP.AE_pair_measure simp: comp_def)
hoelzl@47694
   857
  moreover note Pxyz[THEN distributed_real_AE]
hoelzl@49787
   858
  ultimately have ae: "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P.
hoelzl@47694
   859
    Pxyz x * log b (Pxyz x / (Px (fst x) * Pyz (snd x))) -
hoelzl@47694
   860
    Pxyz x * log b (Pxz (fst x, snd (snd x)) / (Px (fst x) * Pz (snd (snd x)))) =
hoelzl@47694
   861
    Pxyz x * log b (Pxyz x * Pz (snd (snd x)) / (Pxz (fst x, snd (snd x)) * Pyz (snd x))) "
hoelzl@47694
   862
  proof eventually_elim
hoelzl@47694
   863
    case (goal1 x)
hoelzl@47694
   864
    show ?case
hoelzl@40859
   865
    proof cases
hoelzl@47694
   866
      assume "Pxyz x \<noteq> 0"
hoelzl@47694
   867
      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
   868
        by auto
hoelzl@47694
   869
      then show ?thesis
hoelzl@47694
   870
        using b_gt_1 by (simp add: log_simps mult_pos_pos less_imp_le field_simps)
hoelzl@40859
   871
    qed simp
hoelzl@40859
   872
  qed
hoelzl@49787
   873
  with I1 I2 show ?eq
hoelzl@40859
   874
    unfolding conditional_mutual_information_def
hoelzl@47694
   875
    apply (subst mi_eq)
hoelzl@47694
   876
    apply (subst mutual_information_distr[OF S TP Px Pyz Pxyz])
hoelzl@47694
   877
    apply (subst integral_diff(2)[symmetric])
hoelzl@47694
   878
    apply (auto intro!: integral_cong_AE simp: split_beta' simp del: integral_diff)
hoelzl@47694
   879
    done
hoelzl@49787
   880
hoelzl@49787
   881
  let ?P = "density (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) Pxyz"
hoelzl@49787
   882
  interpret P: prob_space ?P
hoelzl@49787
   883
    unfolding distributed_distr_eq_density[OF Pxyz, symmetric]
hoelzl@49787
   884
    using distributed_measurable[OF Pxyz] by (rule prob_space_distr)
hoelzl@49787
   885
hoelzl@49787
   886
  let ?Q = "density (T \<Otimes>\<^isub>M P) Pyz"
hoelzl@49787
   887
  interpret Q: prob_space ?Q
hoelzl@49787
   888
    unfolding distributed_distr_eq_density[OF Pyz, symmetric]
hoelzl@49787
   889
    using distributed_measurable[OF Pyz] by (rule prob_space_distr)
hoelzl@49787
   890
hoelzl@49787
   891
  let ?f = "\<lambda>(x, y, z). Pxz (x, z) * (Pyz (y, z) / Pz z) / Pxyz (x, y, z)"
hoelzl@49787
   892
hoelzl@49787
   893
  from subdensity_real[of snd, OF _ Pyz Pz]
hoelzl@49787
   894
  have aeX1: "AE x in T \<Otimes>\<^isub>M P. Pz (snd x) = 0 \<longrightarrow> Pyz x = 0" by (auto simp: comp_def)
hoelzl@49787
   895
  have aeX2: "AE x in T \<Otimes>\<^isub>M P. 0 \<le> Pz (snd x)"
hoelzl@49787
   896
    using Pz by (intro TP.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@49787
   897
hoelzl@49787
   898
  have aeX3: "AE y in T \<Otimes>\<^isub>M P. (\<integral>\<^isup>+ x. ereal (Pxz (x, snd y)) \<partial>S) = ereal (Pz (snd y))"
hoelzl@49787
   899
    using Pz distributed_marginal_eq_joint[OF P S Px Pz Pxz]
hoelzl@49787
   900
    apply (intro TP.AE_pair_measure)
hoelzl@49787
   901
    apply (auto simp: comp_def measurable_split_conv
hoelzl@49787
   902
                intro!: measurable_snd'' borel_measurable_ereal_eq borel_measurable_ereal
hoelzl@49787
   903
                        SP.borel_measurable_positive_integral_snd measurable_compose[OF _ Pxz[THEN distributed_real_measurable]]
hoelzl@49787
   904
                        measurable_Pair
hoelzl@49787
   905
                dest: distributed_real_AE distributed_real_measurable)
hoelzl@49787
   906
    done
hoelzl@49787
   907
hoelzl@49787
   908
  note M = borel_measurable_divide borel_measurable_diff borel_measurable_times borel_measurable_ereal
hoelzl@49787
   909
           measurable_compose[OF _ measurable_snd]
hoelzl@49787
   910
           measurable_Pair
hoelzl@49787
   911
           measurable_compose[OF _ Pxyz[THEN distributed_real_measurable]]
hoelzl@49787
   912
           measurable_compose[OF _ Pxz[THEN distributed_real_measurable]]
hoelzl@49787
   913
           measurable_compose[OF _ Pyz[THEN distributed_real_measurable]]
hoelzl@49787
   914
           measurable_compose[OF _ Pz[THEN distributed_real_measurable]]
hoelzl@49787
   915
           measurable_compose[OF _ Px[THEN distributed_real_measurable]]
hoelzl@49787
   916
           STP.borel_measurable_positive_integral_snd
hoelzl@49787
   917
  have "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<le> (\<integral>\<^isup>+ (x, y, z). Pxz (x, z) * (Pyz (y, z) / Pz z) \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P))"
hoelzl@49787
   918
    apply (subst positive_integral_density)
hoelzl@49787
   919
    apply (rule distributed_borel_measurable[OF Pxyz])
hoelzl@49787
   920
    apply (rule distributed_AE[OF Pxyz])
hoelzl@49787
   921
    apply (auto simp add: borel_measurable_ereal_iff split_beta' intro!: M) []
hoelzl@49787
   922
    apply (rule positive_integral_mono_AE)
hoelzl@49787
   923
    using ae5 ae6 ae7 ae8
hoelzl@49787
   924
    apply eventually_elim
hoelzl@49787
   925
    apply (auto intro!: divide_nonneg_nonneg mult_nonneg_nonneg)
hoelzl@49787
   926
    done
hoelzl@49787
   927
  also have "\<dots> = (\<integral>\<^isup>+(y, z). \<integral>\<^isup>+ x. ereal (Pxz (x, z)) * ereal (Pyz (y, z) / Pz z) \<partial>S \<partial>T \<Otimes>\<^isub>M P)"
hoelzl@49787
   928
    by (subst STP.positive_integral_snd_measurable[symmetric])
hoelzl@49787
   929
       (auto simp add: borel_measurable_ereal_iff split_beta' intro!: M)
hoelzl@49787
   930
  also have "\<dots> = (\<integral>\<^isup>+x. ereal (Pyz x) * 1 \<partial>T \<Otimes>\<^isub>M P)"
hoelzl@49787
   931
    apply (rule positive_integral_cong_AE)
hoelzl@49787
   932
    using aeX1 aeX2 aeX3 distributed_AE[OF Pyz] AE_space
hoelzl@49787
   933
    apply eventually_elim
hoelzl@49787
   934
  proof (case_tac x, simp del: times_ereal.simps add: space_pair_measure)
hoelzl@49787
   935
    fix a b assume "Pz b = 0 \<longrightarrow> Pyz (a, b) = 0" "0 \<le> Pz b" "a \<in> space T \<and> b \<in> space P"
hoelzl@49787
   936
      "(\<integral>\<^isup>+ x. ereal (Pxz (x, b)) \<partial>S) = ereal (Pz b)" "0 \<le> Pyz (a, b)" 
hoelzl@49787
   937
    then show "(\<integral>\<^isup>+ x. ereal (Pxz (x, b)) * ereal (Pyz (a, b) / Pz b) \<partial>S) = ereal (Pyz (a, b))"
hoelzl@49787
   938
      apply (subst positive_integral_multc)
hoelzl@49787
   939
      apply (auto intro!: borel_measurable_ereal divide_nonneg_nonneg
hoelzl@49787
   940
                          measurable_compose[OF _ Pxz[THEN distributed_real_measurable]] measurable_Pair
hoelzl@49787
   941
                  split: prod.split)
hoelzl@49787
   942
      done
hoelzl@49787
   943
  qed
hoelzl@49787
   944
  also have "\<dots> = 1"
hoelzl@49787
   945
    using Q.emeasure_space_1 distributed_AE[OF Pyz] distributed_distr_eq_density[OF Pyz]
hoelzl@49787
   946
    by (subst positive_integral_density[symmetric]) (auto intro!: M)
hoelzl@49787
   947
  finally have le1: "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<le> 1" .
hoelzl@49787
   948
  also have "\<dots> < \<infinity>" by simp
hoelzl@49787
   949
  finally have fin: "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<noteq> \<infinity>" by simp
hoelzl@49787
   950
hoelzl@49787
   951
  have pos: "(\<integral>\<^isup>+ x. ?f x \<partial>?P) \<noteq> 0"
hoelzl@49787
   952
    apply (subst positive_integral_density)
hoelzl@49787
   953
    apply (rule distributed_borel_measurable[OF Pxyz])
hoelzl@49787
   954
    apply (rule distributed_AE[OF Pxyz])
hoelzl@49787
   955
    apply (auto simp add: borel_measurable_ereal_iff split_beta' intro!: M) []
hoelzl@49787
   956
    apply (simp add: split_beta')
hoelzl@49787
   957
  proof
hoelzl@49787
   958
    let ?g = "\<lambda>x. ereal (if Pxyz x = 0 then 0 else Pxz (fst x, snd (snd x)) * Pyz (snd x) / Pz (snd (snd x)))"
hoelzl@49787
   959
    assume "(\<integral>\<^isup>+ x. ?g x \<partial>(S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P)) = 0"
hoelzl@49787
   960
    then have "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. ?g x \<le> 0"
hoelzl@49787
   961
      by (intro positive_integral_0_iff_AE[THEN iffD1]) (auto intro!: M borel_measurable_ereal measurable_If)
hoelzl@49787
   962
    then have "AE x in S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P. Pxyz x = 0"
hoelzl@49787
   963
      using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49787
   964
      by eventually_elim (auto split: split_if_asm simp: mult_le_0_iff divide_le_0_iff)
hoelzl@49787
   965
    then have "(\<integral>\<^isup>+ x. ereal (Pxyz x) \<partial>S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) = 0"
hoelzl@49787
   966
      by (subst positive_integral_cong_AE[of _ "\<lambda>x. 0"]) auto
hoelzl@49787
   967
    with P.emeasure_space_1 show False
hoelzl@49787
   968
      by (subst (asm) emeasure_density) (auto intro!: M cong: positive_integral_cong)
hoelzl@49787
   969
  qed
hoelzl@49787
   970
hoelzl@49787
   971
  have neg: "(\<integral>\<^isup>+ x. - ?f x \<partial>?P) = 0"
hoelzl@49787
   972
    apply (rule positive_integral_0_iff_AE[THEN iffD2])
hoelzl@49787
   973
    apply (auto intro!: M simp: split_beta') []
hoelzl@49787
   974
    apply (subst AE_density)
hoelzl@49787
   975
    apply (auto intro!: M simp: split_beta') []
hoelzl@49787
   976
    using ae5 ae6 ae7 ae8
hoelzl@49787
   977
    apply eventually_elim
hoelzl@49787
   978
    apply (auto intro!: mult_nonneg_nonneg divide_nonneg_nonneg)
hoelzl@49787
   979
    done
hoelzl@49787
   980
hoelzl@49787
   981
  have I3: "integrable (S \<Otimes>\<^isub>M T \<Otimes>\<^isub>M P) (\<lambda>(x, y, z). Pxyz (x, y, z) * log b (Pxyz (x, y, z) / (Pxz (x, z) * (Pyz (y,z) / Pz z))))"
hoelzl@49787
   982
    apply (rule integrable_cong_AE[THEN iffD1, OF _ _ _ integral_diff(1)[OF I1 I2]])
hoelzl@49787
   983
    using ae
hoelzl@49787
   984
    apply (auto intro!: M simp: split_beta')
hoelzl@49787
   985
    done
hoelzl@49787
   986
hoelzl@49787
   987
  have "- log b 1 \<le> - log b (integral\<^isup>L ?P ?f)"
hoelzl@49787
   988
  proof (intro le_imp_neg_le log_le[OF b_gt_1])
hoelzl@49787
   989
    show "0 < integral\<^isup>L ?P ?f"
hoelzl@49787
   990
      using neg pos fin positive_integral_positive[of ?P ?f]
hoelzl@49787
   991
      by (cases "(\<integral>\<^isup>+ x. ?f x \<partial>?P)") (auto simp add: lebesgue_integral_def less_le split_beta')
hoelzl@49787
   992
    show "integral\<^isup>L ?P ?f \<le> 1"
hoelzl@49787
   993
      using neg le1 fin positive_integral_positive[of ?P ?f]
hoelzl@49787
   994
      by (cases "(\<integral>\<^isup>+ x. ?f x \<partial>?P)") (auto simp add: lebesgue_integral_def split_beta' one_ereal_def)
hoelzl@49787
   995
  qed
hoelzl@49787
   996
  also have "- log b (integral\<^isup>L ?P ?f) \<le> (\<integral> x. - log b (?f x) \<partial>?P)"
hoelzl@49787
   997
  proof (rule P.jensens_inequality[where a=0 and b=1 and I="{0<..}"])
hoelzl@49787
   998
    show "AE x in ?P. ?f x \<in> {0<..}"
hoelzl@49787
   999
      unfolding AE_density[OF distributed_borel_measurable[OF Pxyz]]
hoelzl@49787
  1000
      using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49787
  1001
      by eventually_elim (auto simp: divide_pos_pos mult_pos_pos)
hoelzl@49787
  1002
    show "integrable ?P ?f"
hoelzl@49787
  1003
      unfolding integrable_def 
hoelzl@49787
  1004
      using fin neg by (auto intro!: M simp: split_beta')
hoelzl@49787
  1005
    show "integrable ?P (\<lambda>x. - log b (?f x))"
hoelzl@49787
  1006
      apply (subst integral_density)
hoelzl@49787
  1007
      apply (auto intro!: M) []
hoelzl@49787
  1008
      apply (auto intro!: M distributed_real_AE[OF Pxyz]) []
hoelzl@49787
  1009
      apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49787
  1010
      apply (rule integrable_cong_AE[THEN iffD1, OF _ _ _ I3])
hoelzl@49787
  1011
      apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49787
  1012
      apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49787
  1013
      using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49787
  1014
      apply eventually_elim
hoelzl@49787
  1015
      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
  1016
      done
hoelzl@49787
  1017
  qed (auto simp: b_gt_1 minus_log_convex)
hoelzl@49787
  1018
  also have "\<dots> = conditional_mutual_information b S T P X Y Z"
hoelzl@49787
  1019
    unfolding `?eq`
hoelzl@49787
  1020
    apply (subst integral_density)
hoelzl@49787
  1021
    apply (auto intro!: M) []
hoelzl@49787
  1022
    apply (auto intro!: M distributed_real_AE[OF Pxyz]) []
hoelzl@49787
  1023
    apply (auto intro!: M borel_measurable_uminus borel_measurable_log simp: split_beta') []
hoelzl@49787
  1024
    apply (intro integral_cong_AE)
hoelzl@49787
  1025
    using ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae8 Pxyz[THEN distributed_real_AE]
hoelzl@49787
  1026
    apply eventually_elim
hoelzl@49787
  1027
    apply (auto simp: log_divide_eq zero_less_mult_iff zero_less_divide_iff field_simps)
hoelzl@49787
  1028
    done
hoelzl@49787
  1029
  finally show ?nonneg
hoelzl@49787
  1030
    by simp
hoelzl@40859
  1031
qed
hoelzl@40859
  1032
hoelzl@40859
  1033
lemma (in information_space) conditional_mutual_information_eq:
hoelzl@47694
  1034
  assumes Pz: "simple_distributed M Z Pz"
hoelzl@47694
  1035
  assumes Pyz: "simple_distributed M (\<lambda>x. (Y x, Z x)) Pyz"
hoelzl@47694
  1036
  assumes Pxz: "simple_distributed M (\<lambda>x. (X x, Z x)) Pxz"
hoelzl@47694
  1037
  assumes Pxyz: "simple_distributed M (\<lambda>x. (X x, Y x, Z x)) Pxyz"
hoelzl@47694
  1038
  shows "\<I>(X ; Y | Z) =
hoelzl@47694
  1039
   (\<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
  1040
proof (subst conditional_mutual_information_generic_eq[OF _ _ _ _
hoelzl@47694
  1041
    simple_distributed[OF Pz] simple_distributed_joint[OF Pyz] simple_distributed_joint[OF Pxz]
hoelzl@47694
  1042
    simple_distributed_joint2[OF Pxyz]])
hoelzl@47694
  1043
  note simple_distributed_joint2_finite[OF Pxyz, simp]
hoelzl@47694
  1044
  show "sigma_finite_measure (count_space (X ` space M))"
hoelzl@47694
  1045
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1046
  show "sigma_finite_measure (count_space (Y ` space M))"
hoelzl@47694
  1047
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1048
  show "sigma_finite_measure (count_space (Z ` space M))"
hoelzl@47694
  1049
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1050
  have "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) \<Otimes>\<^isub>M count_space (Z ` space M) =
hoelzl@47694
  1051
      count_space (X`space M \<times> Y`space M \<times> Z`space M)"
hoelzl@47694
  1052
    (is "?P = ?C")
hoelzl@47694
  1053
    by (simp add: pair_measure_count_space)
hoelzl@40859
  1054
hoelzl@47694
  1055
  let ?Px = "\<lambda>x. measure M (X -` {x} \<inter> space M)"
hoelzl@47694
  1056
  have "(\<lambda>x. (X x, Z x)) \<in> measurable M (count_space (X ` space M) \<Otimes>\<^isub>M count_space (Z ` space M))"
hoelzl@47694
  1057
    using simple_distributed_joint[OF Pxz] by (rule distributed_measurable)
hoelzl@47694
  1058
  from measurable_comp[OF this measurable_fst]
hoelzl@47694
  1059
  have "random_variable (count_space (X ` space M)) X"
hoelzl@47694
  1060
    by (simp add: comp_def)
hoelzl@47694
  1061
  then have "simple_function M X"    
hoelzl@47694
  1062
    unfolding simple_function_def by auto
hoelzl@47694
  1063
  then have "simple_distributed M X ?Px"
hoelzl@47694
  1064
    by (rule simple_distributedI) auto
hoelzl@47694
  1065
  then show "distributed M (count_space (X ` space M)) X ?Px"
hoelzl@47694
  1066
    by (rule simple_distributed)
hoelzl@47694
  1067
hoelzl@47694
  1068
  let ?f = "(\<lambda>x. if x \<in> (\<lambda>x. (X x, Y x, Z x)) ` space M then Pxyz x else 0)"
hoelzl@47694
  1069
  let ?g = "(\<lambda>x. if x \<in> (\<lambda>x. (Y x, Z x)) ` space M then Pyz x else 0)"
hoelzl@47694
  1070
  let ?h = "(\<lambda>x. if x \<in> (\<lambda>x. (X x, Z x)) ` space M then Pxz x else 0)"
hoelzl@47694
  1071
  show
hoelzl@47694
  1072
      "integrable ?P (\<lambda>(x, y, z). ?f (x, y, z) * log b (?f (x, y, z) / (?Px x * ?g (y, z))))"
hoelzl@47694
  1073
      "integrable ?P (\<lambda>(x, y, z). ?f (x, y, z) * log b (?h (x, z) / (?Px x * Pz z)))"
hoelzl@47694
  1074
    by (auto intro!: integrable_count_space simp: pair_measure_count_space)
hoelzl@47694
  1075
  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
  1076
  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
  1077
  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
  1078
    by (auto intro!: ext)
hoelzl@47694
  1079
  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
  1080
    by (auto intro!: setsum_cong simp add: `?P = ?C` lebesgue_integral_count_space_finite simple_distributed_finite setsum_cases split_beta')
hoelzl@36624
  1081
qed
hoelzl@36624
  1082
hoelzl@47694
  1083
lemma (in information_space) conditional_mutual_information_nonneg:
hoelzl@47694
  1084
  assumes X: "simple_function M X" and Y: "simple_function M Y" and Z: "simple_function M Z"
hoelzl@47694
  1085
  shows "0 \<le> \<I>(X ; Y | Z)"
hoelzl@47694
  1086
proof -
hoelzl@49787
  1087
  have [simp]: "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) \<Otimes>\<^isub>M count_space (Z ` space M) =
hoelzl@49787
  1088
      count_space (X`space M \<times> Y`space M \<times> Z`space M)"
hoelzl@49787
  1089
    by (simp add: pair_measure_count_space X Y Z simple_functionD)
hoelzl@49787
  1090
  note sf = sigma_finite_measure_count_space_finite[OF simple_functionD(1)]
hoelzl@49787
  1091
  note sd = simple_distributedI[OF _ refl]
hoelzl@49787
  1092
  note sp = simple_function_Pair
hoelzl@49787
  1093
  show ?thesis
hoelzl@49787
  1094
   apply (rule conditional_mutual_information_generic_nonneg[OF sf[OF X] sf[OF Y] sf[OF Z]])
hoelzl@49787
  1095
   apply (rule simple_distributed[OF sd[OF X]])
hoelzl@49787
  1096
   apply (rule simple_distributed[OF sd[OF Z]])
hoelzl@49787
  1097
   apply (rule simple_distributed_joint[OF sd[OF sp[OF Y Z]]])
hoelzl@49787
  1098
   apply (rule simple_distributed_joint[OF sd[OF sp[OF X Z]]])
hoelzl@49787
  1099
   apply (rule simple_distributed_joint2[OF sd[OF sp[OF X sp[OF Y Z]]]])
hoelzl@49787
  1100
   apply (auto intro!: integrable_count_space simp: X Y Z simple_functionD)
hoelzl@49787
  1101
   done
hoelzl@36080
  1102
qed
hoelzl@36080
  1103
hoelzl@39097
  1104
subsection {* Conditional Entropy *}
hoelzl@39097
  1105
hoelzl@36080
  1106
definition (in prob_space)
hoelzl@47694
  1107
  "conditional_entropy b S T X Y = entropy b (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) - entropy b T Y"
hoelzl@36080
  1108
hoelzl@40859
  1109
abbreviation (in information_space)
hoelzl@40859
  1110
  conditional_entropy_Pow ("\<H>'(_ | _')") where
hoelzl@47694
  1111
  "\<H>(X | Y) \<equiv> conditional_entropy b (count_space (X`space M)) (count_space (Y`space M)) X Y"
hoelzl@36080
  1112
hoelzl@40859
  1113
lemma (in information_space) conditional_entropy_generic_eq:
hoelzl@47694
  1114
  fixes Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real"
hoelzl@47694
  1115
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
hoelzl@47694
  1116
  assumes Px: "distributed M S X Px"
hoelzl@47694
  1117
  assumes Py: "distributed M T Y Py"
hoelzl@47694
  1118
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
  1119
  assumes I1: "integrable (S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Pxy x))"
hoelzl@47694
  1120
  assumes I2: "integrable (S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Py (snd x)))"
hoelzl@47694
  1121
  shows "conditional_entropy b S T X Y = - (\<integral>(x, y). Pxy (x, y) * log b (Pxy (x, y) / Py y) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@40859
  1122
proof -
hoelzl@47694
  1123
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
  1124
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
  1125
  interpret ST: pair_sigma_finite S T ..
hoelzl@47694
  1126
  have ST: "sigma_finite_measure (S \<Otimes>\<^isub>M T)" ..
hoelzl@47694
  1127
hoelzl@47694
  1128
  interpret Pxy: prob_space "density (S \<Otimes>\<^isub>M T) Pxy"
hoelzl@47694
  1129
    unfolding Pxy[THEN distributed_distr_eq_density, symmetric]
hoelzl@47694
  1130
    using Pxy[THEN distributed_measurable] by (rule prob_space_distr)
hoelzl@47694
  1131
hoelzl@47694
  1132
  from Py Pxy have distr_eq: "distr M T Y =
hoelzl@47694
  1133
    distr (distr M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))) T snd"
hoelzl@47694
  1134
    by (subst distr_distr[OF measurable_snd]) (auto dest: distributed_measurable simp: comp_def)
hoelzl@47694
  1135
hoelzl@47694
  1136
  have "entropy b T Y = - (\<integral>y. Py y * log b (Py y) \<partial>T)"
hoelzl@49786
  1137
    by (rule entropy_distr[OF Py])
hoelzl@47694
  1138
  also have "\<dots> = - (\<integral>(x,y). Pxy (x,y) * log b (Py y) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@47694
  1139
    using b_gt_1 Py[THEN distributed_real_measurable]
hoelzl@47694
  1140
    by (subst distributed_transform_integral[OF Pxy Py, where T=snd]) (auto intro!: integral_cong)
hoelzl@47694
  1141
  finally have e_eq: "entropy b T Y = - (\<integral>(x,y). Pxy (x,y) * log b (Py y) \<partial>(S \<Otimes>\<^isub>M T))" .
hoelzl@47694
  1142
  
hoelzl@47694
  1143
  have "AE x in S \<Otimes>\<^isub>M T. Px (fst x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
  1144
    by (intro subdensity_real[of fst, OF _ Pxy Px]) (auto intro: measurable_Pair)
hoelzl@47694
  1145
  moreover have "AE x in S \<Otimes>\<^isub>M T. Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
  1146
    by (intro subdensity_real[of snd, OF _ Pxy Py]) (auto intro: measurable_Pair)
hoelzl@47694
  1147
  moreover have "AE x in S \<Otimes>\<^isub>M T. 0 \<le> Px (fst x)"
hoelzl@47694
  1148
    using Px by (intro ST.AE_pair_measure) (auto simp: comp_def intro!: measurable_fst'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@47694
  1149
  moreover have "AE x in S \<Otimes>\<^isub>M T. 0 \<le> Py (snd x)"
hoelzl@47694
  1150
    using Py by (intro ST.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@47694
  1151
  moreover note Pxy[THEN distributed_real_AE]
hoelzl@47694
  1152
  ultimately have pos: "AE x in S \<Otimes>\<^isub>M T. 0 \<le> Pxy x \<and> 0 \<le> Px (fst x) \<and> 0 \<le> Py (snd x) \<and>
hoelzl@47694
  1153
    (Pxy x = 0 \<or> (Pxy x \<noteq> 0 \<longrightarrow> 0 < Pxy x \<and> 0 < Px (fst x) \<and> 0 < Py (snd x)))"
hoelzl@47694
  1154
    by eventually_elim auto
hoelzl@47694
  1155
hoelzl@47694
  1156
  from pos have "AE x in S \<Otimes>\<^isub>M T.
hoelzl@47694
  1157
     Pxy x * log b (Pxy x) - Pxy x * log b (Py (snd x)) = Pxy x * log b (Pxy x / Py (snd x))"
hoelzl@47694
  1158
    by eventually_elim (auto simp: log_simps mult_pos_pos field_simps b_gt_1)
hoelzl@47694
  1159
  with I1 I2 show ?thesis
hoelzl@40859
  1160
    unfolding conditional_entropy_def
hoelzl@47694
  1161
    apply (subst e_eq)
hoelzl@49786
  1162
    apply (subst entropy_distr[OF Pxy])
hoelzl@47694
  1163
    unfolding minus_diff_minus
hoelzl@47694
  1164
    apply (subst integral_diff(2)[symmetric])
hoelzl@47694
  1165
    apply (auto intro!: integral_cong_AE simp: split_beta' simp del: integral_diff)
hoelzl@47694
  1166
    done
hoelzl@39097
  1167
qed
hoelzl@39097
  1168
hoelzl@40859
  1169
lemma (in information_space) conditional_entropy_eq:
hoelzl@47694
  1170
  assumes Y: "simple_distributed M Y Py" and X: "simple_function M X"
hoelzl@47694
  1171
  assumes XY: "simple_distributed M (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
  1172
    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
  1173
proof (subst conditional_entropy_generic_eq[OF _ _
hoelzl@47694
  1174
  simple_distributed[OF simple_distributedI[OF X refl]] simple_distributed[OF Y] simple_distributed_joint[OF XY]])
hoelzl@47694
  1175
  have [simp]: "finite (X`space M)" using X by (simp add: simple_function_def)
hoelzl@47694
  1176
  note Y[THEN simple_distributed_finite, simp]
hoelzl@47694
  1177
  show "sigma_finite_measure (count_space (X ` space M))"
hoelzl@47694
  1178
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1179
  show "sigma_finite_measure (count_space (Y ` space M))"
hoelzl@47694
  1180
    by (simp add: sigma_finite_measure_count_space_finite)
hoelzl@47694
  1181
  let ?f = "(\<lambda>x. if x \<in> (\<lambda>x. (X x, Y x)) ` space M then Pxy x else 0)"
hoelzl@47694
  1182
  have "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) = count_space (X`space M \<times> Y`space M)"
hoelzl@47694
  1183
    (is "?P = ?C")
hoelzl@47694
  1184
    using X Y by (simp add: simple_distributed_finite pair_measure_count_space)
hoelzl@47694
  1185
  with X Y show
hoelzl@47694
  1186
      "integrable ?P (\<lambda>x. ?f x * log b (?f x))"
hoelzl@47694
  1187
      "integrable ?P (\<lambda>x. ?f x * log b (Py (snd x)))"
hoelzl@47694
  1188
    by (auto intro!: integrable_count_space simp: simple_distributed_finite)
hoelzl@47694
  1189
  have eq: "(\<lambda>(x, y). ?f (x, y) * log b (?f (x, y) / Py y)) =
hoelzl@47694
  1190
    (\<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
  1191
    by auto
hoelzl@47694
  1192
  from X Y show "- (\<integral> (x, y). ?f (x, y) * log b (?f (x, y) / Py y) \<partial>?P) =
hoelzl@47694
  1193
    - (\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` space M. Pxy (x, y) * log b (Pxy (x, y) / Py y))"
hoelzl@47694
  1194
    by (auto intro!: setsum_cong simp add: `?P = ?C` lebesgue_integral_count_space_finite simple_distributed_finite eq setsum_cases split_beta')
hoelzl@47694
  1195
qed
hoelzl@39097
  1196
hoelzl@47694
  1197
lemma (in information_space) conditional_mutual_information_eq_conditional_entropy:
hoelzl@41689
  1198
  assumes X: "simple_function M X" and Y: "simple_function M Y"
hoelzl@47694
  1199
  shows "\<I>(X ; X | Y) = \<H>(X | Y)"
hoelzl@47694
  1200
proof -
hoelzl@47694
  1201
  def Py \<equiv> "\<lambda>x. if x \<in> Y`space M then measure M (Y -` {x} \<inter> space M) else 0"
hoelzl@47694
  1202
  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
  1203
  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
  1204
  let ?M = "X`space M \<times> X`space M \<times> Y`space M"
hoelzl@39097
  1205
hoelzl@47694
  1206
  note XY = simple_function_Pair[OF X Y]
hoelzl@47694
  1207
  note XXY = simple_function_Pair[OF X XY]
hoelzl@47694
  1208
  have Py: "simple_distributed M Y Py"
hoelzl@47694
  1209
    using Y by (rule simple_distributedI) (auto simp: Py_def)
hoelzl@47694
  1210
  have Pxy: "simple_distributed M (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
  1211
    using XY by (rule simple_distributedI) (auto simp: Pxy_def)
hoelzl@47694
  1212
  have Pxxy: "simple_distributed M (\<lambda>x. (X x, X x, Y x)) Pxxy"
hoelzl@47694
  1213
    using XXY by (rule simple_distributedI) (auto simp: Pxxy_def)
hoelzl@47694
  1214
  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
  1215
    by auto
hoelzl@47694
  1216
  have inj: "\<And>A. inj_on (\<lambda>(x, y). (x, x, y)) A"
hoelzl@47694
  1217
    by (auto simp: inj_on_def)
hoelzl@47694
  1218
  have Pxxy_eq: "\<And>x y. Pxxy (x, x, y) = Pxy (x, y)"
hoelzl@47694
  1219
    by (auto simp: Pxxy_def Pxy_def intro!: arg_cong[where f=prob])
hoelzl@47694
  1220
  have "AE x in count_space ((\<lambda>x. (X x, Y x))`space M). Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
  1221
    by (intro subdensity_real[of snd, OF _ Pxy[THEN simple_distributed] Py[THEN simple_distributed]]) (auto intro: measurable_Pair)
hoelzl@47694
  1222
  then show ?thesis
hoelzl@47694
  1223
    apply (subst conditional_mutual_information_eq[OF Py Pxy Pxy Pxxy])
hoelzl@47694
  1224
    apply (subst conditional_entropy_eq[OF Py X Pxy])
hoelzl@47694
  1225
    apply (auto intro!: setsum_cong simp: Pxxy_eq setsum_negf[symmetric] eq setsum_reindex[OF inj]
hoelzl@47694
  1226
                log_simps zero_less_mult_iff zero_le_mult_iff field_simps mult_less_0_iff AE_count_space)
hoelzl@47694
  1227
    using Py[THEN simple_distributed, THEN distributed_real_AE] Pxy[THEN simple_distributed, THEN distributed_real_AE]
hoelzl@47694
  1228
    apply (auto simp add: not_le[symmetric] AE_count_space)
hoelzl@47694
  1229
    done
hoelzl@47694
  1230
qed
hoelzl@47694
  1231
hoelzl@47694
  1232
lemma (in information_space) conditional_entropy_nonneg:
hoelzl@47694
  1233
  assumes X: "simple_function M X" and Y: "simple_function M Y" shows "0 \<le> \<H>(X | Y)"
hoelzl@47694
  1234
  using conditional_mutual_information_eq_conditional_entropy[OF X Y] conditional_mutual_information_nonneg[OF X X Y]
hoelzl@47694
  1235
  by simp
hoelzl@36080
  1236
hoelzl@39097
  1237
subsection {* Equalities *}
hoelzl@39097
  1238
hoelzl@47694
  1239
lemma (in information_space) mutual_information_eq_entropy_conditional_entropy_distr:
hoelzl@47694
  1240
  fixes Px :: "'b \<Rightarrow> real" and Py :: "'c \<Rightarrow> real" and Pxy :: "('b \<times> 'c) \<Rightarrow> real"
hoelzl@47694
  1241
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
hoelzl@47694
  1242
  assumes Px: "distributed M S X Px" and Py: "distributed M T Y Py"
hoelzl@47694
  1243
  assumes Pxy: "distributed M (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) Pxy"
hoelzl@47694
  1244
  assumes Ix: "integrable(S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Px (fst x)))"
hoelzl@47694
  1245
  assumes Iy: "integrable(S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Py (snd x)))"
hoelzl@47694
  1246
  assumes Ixy: "integrable(S \<Otimes>\<^isub>M T) (\<lambda>x. Pxy x * log b (Pxy x))"
hoelzl@47694
  1247
  shows  "mutual_information b S T X Y = entropy b S X + entropy b T Y - entropy b (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@40859
  1248
proof -
hoelzl@47694
  1249
  have X: "entropy b S X = - (\<integral>x. Pxy x * log b (Px (fst x)) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@47694
  1250
    using b_gt_1 Px[THEN distributed_real_measurable]
hoelzl@49786
  1251
    apply (subst entropy_distr[OF Px])
hoelzl@47694
  1252
    apply (subst distributed_transform_integral[OF Pxy Px, where T=fst])
hoelzl@47694
  1253
    apply (auto intro!: integral_cong)
hoelzl@47694
  1254
    done
hoelzl@47694
  1255
hoelzl@47694
  1256
  have Y: "entropy b T Y = - (\<integral>x. Pxy x * log b (Py (snd x)) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@47694
  1257
    using b_gt_1 Py[THEN distributed_real_measurable]
hoelzl@49786
  1258
    apply (subst entropy_distr[OF Py])
hoelzl@47694
  1259
    apply (subst distributed_transform_integral[OF Pxy Py, where T=snd])
hoelzl@47694
  1260
    apply (auto intro!: integral_cong)
hoelzl@47694
  1261
    done
hoelzl@47694
  1262
hoelzl@47694
  1263
  interpret S: sigma_finite_measure S by fact
hoelzl@47694
  1264
  interpret T: sigma_finite_measure T by fact
hoelzl@47694
  1265
  interpret ST: pair_sigma_finite S T ..
hoelzl@47694
  1266
  have ST: "sigma_finite_measure (S \<Otimes>\<^isub>M T)" ..
hoelzl@47694
  1267
hoelzl@47694
  1268
  have XY: "entropy b (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) = - (\<integral>x. Pxy x * log b (Pxy x) \<partial>(S \<Otimes>\<^isub>M T))"
hoelzl@49786
  1269
    by (subst entropy_distr[OF Pxy]) (auto intro!: integral_cong)
hoelzl@47694
  1270
  
hoelzl@47694
  1271
  have "AE x in S \<Otimes>\<^isub>M T. Px (fst x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
  1272
    by (intro subdensity_real[of fst, OF _ Pxy Px]) (auto intro: measurable_Pair)
hoelzl@47694
  1273
  moreover have "AE x in S \<Otimes>\<^isub>M T. Py (snd x) = 0 \<longrightarrow> Pxy x = 0"
hoelzl@47694
  1274
    by (intro subdensity_real[of snd, OF _ Pxy Py]) (auto intro: measurable_Pair)
hoelzl@47694
  1275
  moreover have "AE x in S \<Otimes>\<^isub>M T. 0 \<le> Px (fst x)"
hoelzl@47694
  1276
    using Px by (intro ST.AE_pair_measure) (auto simp: comp_def intro!: measurable_fst'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@47694
  1277
  moreover have "AE x in S \<Otimes>\<^isub>M T. 0 \<le> Py (snd x)"
hoelzl@47694
  1278
    using Py by (intro ST.AE_pair_measure) (auto simp: comp_def intro!: measurable_snd'' dest: distributed_real_AE distributed_real_measurable)
hoelzl@47694
  1279
  moreover note Pxy[THEN distributed_real_AE]
hoelzl@47694
  1280
  ultimately have "AE x in S \<Otimes>\<^isub>M T. Pxy x * log b (Pxy x) - Pxy x * log b (Px (fst x)) - Pxy x * log b (Py (snd x)) = 
hoelzl@47694
  1281
    Pxy x * log b (Pxy x / (Px (fst x) * Py (snd x)))"
hoelzl@47694
  1282
    (is "AE x in _. ?f x = ?g x")
hoelzl@47694
  1283
  proof eventually_elim
hoelzl@47694
  1284
    case (goal1 x)
hoelzl@47694
  1285
    show ?case
hoelzl@47694
  1286
    proof cases
hoelzl@47694
  1287
      assume "Pxy x \<noteq> 0"
hoelzl@47694
  1288
      with goal1 have "0 < Px (fst x)" "0 < Py (snd x)" "0 < Pxy x"
hoelzl@47694
  1289
        by auto
hoelzl@47694
  1290
      then show ?thesis
hoelzl@47694
  1291
        using b_gt_1 by (simp add: log_simps mult_pos_pos less_imp_le field_simps)
hoelzl@47694
  1292
    qed simp
hoelzl@47694
  1293
  qed
hoelzl@47694
  1294
hoelzl@47694
  1295
  have "entropy b S X + entropy b T Y - entropy b (S \<Otimes>\<^isub>M T) (\<lambda>x. (X x, Y x)) = integral\<^isup>L (S \<Otimes>\<^isub>M T) ?f"
hoelzl@47694
  1296
    unfolding X Y XY
hoelzl@47694
  1297
    apply (subst integral_diff)
hoelzl@47694
  1298
    apply (intro integral_diff Ixy Ix Iy)+
hoelzl@47694
  1299
    apply (subst integral_diff)
hoelzl@47694
  1300
    apply (intro integral_diff Ixy Ix Iy)+
hoelzl@47694
  1301
    apply (simp add: field_simps)
hoelzl@47694
  1302
    done
hoelzl@47694
  1303
  also have "\<dots> = integral\<^isup>L (S \<Otimes>\<^isub>M T) ?g"
hoelzl@47694
  1304
    using `AE x in _. ?f x = ?g x` by (rule integral_cong_AE)
hoelzl@47694
  1305
  also have "\<dots> = mutual_information b S T X Y"
hoelzl@47694
  1306
    by (rule mutual_information_distr[OF S T Px Py Pxy, symmetric])
hoelzl@47694
  1307
  finally show ?thesis ..
hoelzl@47694
  1308
qed
hoelzl@47694
  1309
hoelzl@47694
  1310
lemma (in information_space) mutual_information_eq_entropy_conditional_entropy:
hoelzl@47694
  1311
  assumes sf_X: "simple_function M X" and sf_Y: "simple_function M Y"
hoelzl@47694
  1312
  shows  "\<I>(X ; Y) = \<H>(X) - \<H>(X | Y)"
hoelzl@47694
  1313
proof -
hoelzl@47694
  1314
  have X: "simple_distributed M X (\<lambda>x. measure M (X -` {x} \<inter> space M))"
hoelzl@47694
  1315
    using sf_X by (rule simple_distributedI) auto
hoelzl@47694
  1316
  have Y: "simple_distributed M Y (\<lambda>x. measure M (Y -` {x} \<inter> space M))"
hoelzl@47694
  1317
    using sf_Y by (rule simple_distributedI) auto
hoelzl@47694
  1318
  have sf_XY: "simple_function M (\<lambda>x. (X x, Y x))"
hoelzl@47694
  1319
    using sf_X sf_Y by (rule simple_function_Pair)
hoelzl@47694
  1320
  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
  1321
    by (rule simple_distributedI) auto
hoelzl@47694
  1322
  from simple_distributed_joint_finite[OF this, simp]
hoelzl@47694
  1323
  have eq: "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) = count_space (X ` space M \<times> Y ` space M)"
hoelzl@47694
  1324
    by (simp add: pair_measure_count_space)
hoelzl@47694
  1325
hoelzl@47694
  1326
  have "\<I>(X ; Y) = \<H>(X) + \<H>(Y) - entropy b (count_space (X`space M) \<Otimes>\<^isub>M count_space (Y`space M)) (\<lambda>x. (X x, Y x))"
hoelzl@47694
  1327
    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
  1328
    by (rule mutual_information_eq_entropy_conditional_entropy_distr) (auto simp: eq integrable_count_space)
hoelzl@47694
  1329
  then show ?thesis
hoelzl@47694
  1330
    unfolding conditional_entropy_def by simp
hoelzl@47694
  1331
qed
hoelzl@47694
  1332
hoelzl@47694
  1333
lemma (in information_space) mutual_information_nonneg_simple:
hoelzl@47694
  1334
  assumes sf_X: "simple_function M X" and sf_Y: "simple_function M Y"
hoelzl@47694
  1335
  shows  "0 \<le> \<I>(X ; Y)"
hoelzl@47694
  1336
proof -
hoelzl@47694
  1337
  have X: "simple_distributed M X (\<lambda>x. measure M (X -` {x} \<inter> space M))"
hoelzl@47694
  1338
    using sf_X by (rule simple_distributedI) auto
hoelzl@47694
  1339
  have Y: "simple_distributed M Y (\<lambda>x. measure M (Y -` {x} \<inter> space M))"
hoelzl@47694
  1340
    using sf_Y by (rule simple_distributedI) auto
hoelzl@47694
  1341
hoelzl@47694
  1342
  have sf_XY: "simple_function M (\<lambda>x. (X x, Y x))"
hoelzl@47694
  1343
    using sf_X sf_Y by (rule simple_function_Pair)
hoelzl@47694
  1344
  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
  1345
    by (rule simple_distributedI) auto
hoelzl@47694
  1346
hoelzl@47694
  1347
  from simple_distributed_joint_finite[OF this, simp]
hoelzl@47694
  1348
  have eq: "count_space (X ` space M) \<Otimes>\<^isub>M count_space (Y ` space M) = count_space (X ` space M \<times> Y ` space M)"
hoelzl@47694
  1349
    by (simp add: pair_measure_count_space)
hoelzl@47694
  1350
hoelzl@40859
  1351
  show ?thesis
hoelzl@47694
  1352
    by (rule mutual_information_nonneg[OF _ _ simple_distributed[OF X] simple_distributed[OF Y] simple_distributed_joint[OF XY]])
hoelzl@47694
  1353
       (simp_all add: eq integrable_count_space sigma_finite_measure_count_space_finite)
hoelzl@40859
  1354
qed
hoelzl@36080
  1355
hoelzl@40859
  1356
lemma (in information_space) conditional_entropy_less_eq_entropy:
hoelzl@41689
  1357
  assumes X: "simple_function M X" and Z: "simple_function M Z"
hoelzl@40859
  1358
  shows "\<H>(X | Z) \<le> \<H>(X)"
hoelzl@36624
  1359
proof -
hoelzl@47694
  1360
  have "0 \<le> \<I>(X ; Z)" using X Z by (rule mutual_information_nonneg_simple)
hoelzl@47694
  1361
  also have "\<I>(X ; Z) = \<H>(X) - \<H>(X | Z)" using mutual_information_eq_entropy_conditional_entropy[OF assms] .
hoelzl@47694
  1362
  finally show ?thesis by auto
hoelzl@36080
  1363
qed
hoelzl@36080
  1364
hoelzl@40859
  1365
lemma (in information_space) entropy_chain_rule:
hoelzl@41689
  1366
  assumes X: "simple_function M X" and Y: "simple_function M Y"
hoelzl@40859
  1367
  shows  "\<H>(\<lambda>x. (X x, Y x)) = \<H>(X) + \<H>(Y|X)"
hoelzl@40859
  1368
proof -
hoelzl@47694
  1369
  note XY = simple_distributedI[OF simple_function_Pair[OF X Y] refl]
hoelzl@47694
  1370
  note YX = simple_distributedI[OF simple_function_Pair[OF Y X] refl]
hoelzl@47694
  1371
  note simple_distributed_joint_finite[OF this, simp]
hoelzl@47694
  1372
  let ?f = "\<lambda>x. prob ((\<lambda>x. (X x, Y x)) -` {x} \<inter> space M)"
hoelzl@47694
  1373
  let ?g = "\<lambda>x. prob ((\<lambda>x. (Y x, X x)) -` {x} \<inter> space M)"
hoelzl@47694
  1374
  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
  1375
  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
  1376
    using XY by (rule entropy_simple_distributed)
hoelzl@47694
  1377
  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
  1378
    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
  1379
  also have "\<dots> = - (\<Sum>x\<in>(\<lambda>x. (Y x, X x)) ` space M. ?h x * log b (?h x))"
hoelzl@47694
  1380
    by (auto intro!: setsum_cong)
hoelzl@47694
  1381
  also have "\<dots> = entropy b (count_space (Y ` space M) \<Otimes>\<^isub>M count_space (X ` space M)) (\<lambda>x. (Y x, X x))"
hoelzl@49786
  1382
    by (subst entropy_distr[OF simple_distributed_joint[OF YX]])
hoelzl@47694
  1383
       (auto simp: pair_measure_count_space sigma_finite_measure_count_space_finite lebesgue_integral_count_space_finite
hoelzl@47694
  1384
             cong del: setsum_cong  intro!: setsum_mono_zero_left)
hoelzl@47694
  1385
  finally have "\<H>(\<lambda>x. (X x, Y x)) = entropy b (count_space (Y ` space M) \<Otimes>\<^isub>M count_space (X ` space M)) (\<lambda>x. (Y x, X x))" .
hoelzl@47694
  1386
  then show ?thesis
hoelzl@47694
  1387
    unfolding conditional_entropy_def by simp
hoelzl@36624
  1388
qed
hoelzl@36624
  1389
hoelzl@40859
  1390
lemma (in information_space) entropy_partition:
hoelzl@47694
  1391
  assumes X: "simple_function M X"
hoelzl@47694
  1392
  shows "\<H>(X) = \<H>(f \<circ> X) + \<H>(X|f \<circ> X)"
hoelzl@36624
  1393
proof -
hoelzl@47694
  1394
  note fX = simple_function_compose[OF X, of f]  
hoelzl@47694
  1395
  have eq: "(\<lambda>x. ((f \<circ> X) x, X x)) ` space M = (\<lambda>x. (f x, x)) ` X ` space M" by auto
hoelzl@47694
  1396
  have inj: "\<And>A. inj_on (\<lambda>x. (f x, x)) A"
hoelzl@47694
  1397
    by (auto simp: inj_on_def)
hoelzl@47694
  1398
  show ?thesis
hoelzl@47694
  1399
    apply (subst entropy_chain_rule[symmetric, OF fX X])
hoelzl@47694
  1400
    apply (subst entropy_simple_distributed[OF simple_distributedI[OF simple_function_Pair[OF fX X] refl]])
hoelzl@47694
  1401
    apply (subst entropy_simple_distributed[OF simple_distributedI[OF X refl]])
hoelzl@47694
  1402
    unfolding eq
hoelzl@47694
  1403
    apply (subst setsum_reindex[OF inj])
hoelzl@47694
  1404
    apply (auto intro!: setsum_cong arg_cong[where f="\<lambda>A. prob A * log b (prob A)"])
hoelzl@47694
  1405
    done
hoelzl@36624
  1406
qed
hoelzl@36624
  1407
hoelzl@40859
  1408
corollary (in information_space) entropy_data_processing:
hoelzl@41689
  1409
  assumes X: "simple_function M X" shows "\<H>(f \<circ> X) \<le> \<H>(X)"
hoelzl@40859
  1410
proof -
hoelzl@47694
  1411
  note fX = simple_function_compose[OF X, of f]
hoelzl@47694
  1412
  from X have "\<H>(X) = \<H>(f\<circ>X) + \<H>(X|f\<circ>X)" by (rule entropy_partition)
hoelzl@40859
  1413
  then show "\<H>(f \<circ> X) \<le> \<H>(X)"
hoelzl@47694
  1414
    by (auto intro: conditional_entropy_nonneg[OF X fX])
hoelzl@40859
  1415
qed
hoelzl@36624
  1416
hoelzl@40859
  1417
corollary (in information_space) entropy_of_inj:
hoelzl@41689
  1418
  assumes X: "simple_function M X" and inj: "inj_on f (X`space M)"
hoelzl@36624
  1419
  shows "\<H>(f \<circ> X) = \<H>(X)"
hoelzl@36624
  1420
proof (rule antisym)
hoelzl@40859
  1421
  show "\<H>(f \<circ> X) \<le> \<H>(X)" using entropy_data_processing[OF X] .
hoelzl@36624
  1422
next
hoelzl@41689
  1423
  have sf: "simple_function M (f \<circ> X)"
hoelzl@40859
  1424
    using X by auto
hoelzl@36624
  1425
  have "\<H>(X) = \<H>(the_inv_into (X`space M) f \<circ> (f \<circ> X))"
hoelzl@47694
  1426
    unfolding o_assoc
hoelzl@47694
  1427
    apply (subst entropy_simple_distributed[OF simple_distributedI[OF X refl]])
hoelzl@47694
  1428
    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
  1429
    apply (auto intro!: setsum_cong arg_cong[where f=prob] image_eqI simp: the_inv_into_f_f[OF inj] comp_def)
hoelzl@47694
  1430
    done
hoelzl@36624
  1431
  also have "... \<le> \<H>(f \<circ> X)"
hoelzl@40859
  1432
    using entropy_data_processing[OF sf] .
hoelzl@36624
  1433
  finally show "\<H>(X) \<le> \<H>(f \<circ> X)" .
hoelzl@36624
  1434
qed
hoelzl@36624
  1435
hoelzl@36080
  1436
end