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