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