author | hoelzl |
Mon, 24 Jan 2011 22:29:50 +0100 | |
changeset 41661 | baf1964bc468 |
parent 41413 | 64cd30d6b0b8 |
child 41689 | 3e39b0e730d6 |
permissions | -rw-r--r-- |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
1 |
theory Information |
41413
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
wenzelm
parents:
41095
diff
changeset
|
2 |
imports |
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
wenzelm
parents:
41095
diff
changeset
|
3 |
Probability_Space |
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
wenzelm
parents:
41095
diff
changeset
|
4 |
"~~/src/HOL/Library/Convex" |
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
wenzelm
parents:
41095
diff
changeset
|
5 |
Lebesgue_Measure |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
6 |
begin |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
7 |
|
39097 | 8 |
lemma log_le: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> x \<le> y \<Longrightarrow> log a x \<le> log a y" |
9 |
by (subst log_le_cancel_iff) auto |
|
10 |
||
11 |
lemma log_less: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> x < y \<Longrightarrow> log a x < log a y" |
|
12 |
by (subst log_less_cancel_iff) auto |
|
13 |
||
14 |
lemma setsum_cartesian_product': |
|
15 |
"(\<Sum>x\<in>A \<times> B. f x) = (\<Sum>x\<in>A. setsum (\<lambda>y. f (x, y)) B)" |
|
16 |
unfolding setsum_cartesian_product by simp |
|
17 |
||
36624 | 18 |
section "Convex theory" |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
19 |
|
36624 | 20 |
lemma log_setsum: |
21 |
assumes "finite s" "s \<noteq> {}" |
|
22 |
assumes "b > 1" |
|
23 |
assumes "(\<Sum> i \<in> s. a i) = 1" |
|
24 |
assumes "\<And> i. i \<in> s \<Longrightarrow> a i \<ge> 0" |
|
25 |
assumes "\<And> i. i \<in> s \<Longrightarrow> y i \<in> {0 <..}" |
|
26 |
shows "log b (\<Sum> i \<in> s. a i * y i) \<ge> (\<Sum> i \<in> s. a i * log b (y i))" |
|
27 |
proof - |
|
28 |
have "convex_on {0 <..} (\<lambda> x. - log b x)" |
|
29 |
by (rule minus_log_convex[OF `b > 1`]) |
|
30 |
hence "- log b (\<Sum> i \<in> s. a i * y i) \<le> (\<Sum> i \<in> s. a i * - log b (y i))" |
|
31 |
using convex_on_setsum[of _ _ "\<lambda> x. - log b x"] assms pos_is_convex by fastsimp |
|
32 |
thus ?thesis by (auto simp add:setsum_negf le_imp_neg_le) |
|
33 |
qed |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
34 |
|
36624 | 35 |
lemma log_setsum': |
36 |
assumes "finite s" "s \<noteq> {}" |
|
37 |
assumes "b > 1" |
|
38 |
assumes "(\<Sum> i \<in> s. a i) = 1" |
|
39 |
assumes pos: "\<And> i. i \<in> s \<Longrightarrow> 0 \<le> a i" |
|
40 |
"\<And> i. \<lbrakk> i \<in> s ; 0 < a i \<rbrakk> \<Longrightarrow> 0 < y i" |
|
41 |
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
|
42 |
proof - |
36624 | 43 |
have "\<And>y. (\<Sum> i \<in> s - {i. a i = 0}. a i * y i) = (\<Sum> i \<in> s. a i * y i)" |
44 |
using assms by (auto intro!: setsum_mono_zero_cong_left) |
|
45 |
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))" |
|
46 |
proof (rule log_setsum) |
|
47 |
have "setsum a (s - {i. a i = 0}) = setsum a s" |
|
48 |
using assms(1) by (rule setsum_mono_zero_cong_left) auto |
|
49 |
thus sum_1: "setsum a (s - {i. a i = 0}) = 1" |
|
50 |
"finite (s - {i. a i = 0})" using assms by simp_all |
|
51 |
||
52 |
show "s - {i. a i = 0} \<noteq> {}" |
|
53 |
proof |
|
54 |
assume *: "s - {i. a i = 0} = {}" |
|
55 |
hence "setsum a (s - {i. a i = 0}) = 0" by (simp add: * setsum_empty) |
|
56 |
with sum_1 show False by simp |
|
38656 | 57 |
qed |
36624 | 58 |
|
59 |
fix i assume "i \<in> s - {i. a i = 0}" |
|
60 |
hence "i \<in> s" "a i \<noteq> 0" by simp_all |
|
61 |
thus "0 \<le> a i" "y i \<in> {0<..}" using pos[of i] by auto |
|
62 |
qed fact+ |
|
63 |
ultimately show ?thesis by simp |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
64 |
qed |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
65 |
|
36624 | 66 |
lemma log_setsum_divide: |
67 |
assumes "finite S" and "S \<noteq> {}" and "1 < b" |
|
68 |
assumes "(\<Sum>x\<in>S. g x) = 1" |
|
69 |
assumes pos: "\<And>x. x \<in> S \<Longrightarrow> g x \<ge> 0" "\<And>x. x \<in> S \<Longrightarrow> f x \<ge> 0" |
|
70 |
assumes g_pos: "\<And>x. \<lbrakk> x \<in> S ; 0 < g x \<rbrakk> \<Longrightarrow> 0 < f x" |
|
71 |
shows "- (\<Sum>x\<in>S. g x * log b (g x / f x)) \<le> log b (\<Sum>x\<in>S. f x)" |
|
72 |
proof - |
|
73 |
have log_mono: "\<And>x y. 0 < x \<Longrightarrow> x \<le> y \<Longrightarrow> log b x \<le> log b y" |
|
74 |
using `1 < b` by (subst log_le_cancel_iff) auto |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
75 |
|
36624 | 76 |
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))" |
77 |
proof (unfold setsum_negf[symmetric], rule setsum_cong) |
|
78 |
fix x assume x: "x \<in> S" |
|
79 |
show "- (g x * log b (g x / f x)) = g x * log b (f x / g x)" |
|
80 |
proof (cases "g x = 0") |
|
81 |
case False |
|
82 |
with pos[OF x] g_pos[OF x] have "0 < f x" "0 < g x" by simp_all |
|
83 |
thus ?thesis using `1 < b` by (simp add: log_divide field_simps) |
|
84 |
qed simp |
|
85 |
qed rule |
|
86 |
also have "... \<le> log b (\<Sum>x\<in>S. g x * (f x / g x))" |
|
87 |
proof (rule log_setsum') |
|
88 |
fix x assume x: "x \<in> S" "0 < g x" |
|
89 |
with g_pos[OF x] show "0 < f x / g x" by (safe intro!: divide_pos_pos) |
|
90 |
qed fact+ |
|
91 |
also have "... = log b (\<Sum>x\<in>S - {x. g x = 0}. f x)" using `finite S` |
|
92 |
by (auto intro!: setsum_mono_zero_cong_right arg_cong[where f="log b"] |
|
93 |
split: split_if_asm) |
|
94 |
also have "... \<le> log b (\<Sum>x\<in>S. f x)" |
|
95 |
proof (rule log_mono) |
|
96 |
have "0 = (\<Sum>x\<in>S - {x. g x = 0}. 0)" by simp |
|
97 |
also have "... < (\<Sum>x\<in>S - {x. g x = 0}. f x)" (is "_ < ?sum") |
|
98 |
proof (rule setsum_strict_mono) |
|
99 |
show "finite (S - {x. g x = 0})" using `finite S` by simp |
|
100 |
show "S - {x. g x = 0} \<noteq> {}" |
|
101 |
proof |
|
102 |
assume "S - {x. g x = 0} = {}" |
|
103 |
hence "(\<Sum>x\<in>S. g x) = 0" by (subst setsum_0') auto |
|
104 |
with `(\<Sum>x\<in>S. g x) = 1` show False by simp |
|
105 |
qed |
|
106 |
fix x assume "x \<in> S - {x. g x = 0}" |
|
107 |
thus "0 < f x" using g_pos[of x] pos(1)[of x] by auto |
|
108 |
qed |
|
109 |
finally show "0 < ?sum" . |
|
110 |
show "(\<Sum>x\<in>S - {x. g x = 0}. f x) \<le> (\<Sum>x\<in>S. f x)" |
|
111 |
using `finite S` pos by (auto intro!: setsum_mono2) |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
112 |
qed |
36624 | 113 |
finally show ?thesis . |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
114 |
qed |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
115 |
|
39097 | 116 |
lemma split_pairs: |
40859 | 117 |
"((A, B) = X) \<longleftrightarrow> (fst X = A \<and> snd X = B)" and |
118 |
"(X = (A, B)) \<longleftrightarrow> (fst X = A \<and> snd X = B)" by auto |
|
38656 | 119 |
|
120 |
section "Information theory" |
|
121 |
||
40859 | 122 |
locale information_space = prob_space + |
38656 | 123 |
fixes b :: real assumes b_gt_1: "1 < b" |
124 |
||
40859 | 125 |
context information_space |
38656 | 126 |
begin |
127 |
||
40859 | 128 |
text {* Introduce some simplification rules for logarithm of base @{term b}. *} |
129 |
||
130 |
lemma log_neg_const: |
|
131 |
assumes "x \<le> 0" |
|
132 |
shows "log b x = log b 0" |
|
36624 | 133 |
proof - |
40859 | 134 |
{ fix u :: real |
135 |
have "x \<le> 0" by fact |
|
136 |
also have "0 < exp u" |
|
137 |
using exp_gt_zero . |
|
138 |
finally have "exp u \<noteq> x" |
|
139 |
by auto } |
|
140 |
then show "log b x = log b 0" |
|
141 |
by (simp add: log_def ln_def) |
|
38656 | 142 |
qed |
143 |
||
40859 | 144 |
lemma log_mult_eq: |
145 |
"log b (A * B) = (if 0 < A * B then log b \<bar>A\<bar> + log b \<bar>B\<bar> else log b 0)" |
|
146 |
using log_mult[of b "\<bar>A\<bar>" "\<bar>B\<bar>"] b_gt_1 log_neg_const[of "A * B"] |
|
147 |
by (auto simp: zero_less_mult_iff mult_le_0_iff) |
|
38656 | 148 |
|
40859 | 149 |
lemma log_inverse_eq: |
150 |
"log b (inverse B) = (if 0 < B then - log b B else log b 0)" |
|
151 |
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
|
152 |
|
40859 | 153 |
lemma log_divide_eq: |
154 |
"log b (A / B) = (if 0 < A * B then log b \<bar>A\<bar> - log b \<bar>B\<bar> else log b 0)" |
|
155 |
unfolding divide_inverse log_mult_eq log_inverse_eq abs_inverse |
|
156 |
by (auto simp: zero_less_mult_iff mult_le_0_iff) |
|
38656 | 157 |
|
40859 | 158 |
lemmas log_simps = log_mult_eq log_inverse_eq log_divide_eq |
38656 | 159 |
|
160 |
end |
|
161 |
||
39097 | 162 |
subsection "Kullback$-$Leibler divergence" |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
163 |
|
39097 | 164 |
text {* The Kullback$-$Leibler divergence is also known as relative entropy or |
165 |
Kullback$-$Leibler distance. *} |
|
166 |
||
167 |
definition |
|
168 |
"KL_divergence b M \<mu> \<nu> = |
|
169 |
measure_space.integral M \<mu> (\<lambda>x. log b (real (sigma_finite_measure.RN_deriv M \<nu> \<mu> x)))" |
|
38656 | 170 |
|
40859 | 171 |
lemma (in sigma_finite_measure) KL_divergence_cong: |
172 |
assumes "measure_space M \<nu>" |
|
173 |
and cong: "\<And>A. A \<in> sets M \<Longrightarrow> \<mu>' A = \<mu> A" "\<And>A. A \<in> sets M \<Longrightarrow> \<nu>' A = \<nu> A" |
|
174 |
shows "KL_divergence b M \<nu>' \<mu>' = KL_divergence b M \<nu> \<mu>" |
|
175 |
proof - |
|
176 |
interpret \<nu>: measure_space M \<nu> by fact |
|
177 |
show ?thesis |
|
178 |
unfolding KL_divergence_def |
|
179 |
using RN_deriv_cong[OF cong, of "\<lambda>A. A"] |
|
180 |
by (simp add: cong \<nu>.integral_cong_measure[OF cong(2)]) |
|
181 |
qed |
|
182 |
||
38656 | 183 |
lemma (in finite_measure_space) KL_divergence_eq_finite: |
184 |
assumes v: "finite_measure_space M \<nu>" |
|
40859 | 185 |
assumes ac: "absolutely_continuous \<nu>" |
38656 | 186 |
shows "KL_divergence b M \<nu> \<mu> = (\<Sum>x\<in>space M. real (\<nu> {x}) * log b (real (\<nu> {x}) / real (\<mu> {x})))" (is "_ = ?sum") |
187 |
proof (simp add: KL_divergence_def finite_measure_space.integral_finite_singleton[OF v]) |
|
188 |
interpret v: finite_measure_space M \<nu> by fact |
|
189 |
have ms: "measure_space M \<nu>" by fact |
|
190 |
show "(\<Sum>x \<in> space M. log b (real (RN_deriv \<nu> x)) * real (\<nu> {x})) = ?sum" |
|
191 |
using RN_deriv_finite_measure[OF ms ac] |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
192 |
by (auto intro!: setsum_cong simp: field_simps real_of_pextreal_mult[symmetric]) |
38656 | 193 |
qed |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
194 |
|
38656 | 195 |
lemma (in finite_prob_space) KL_divergence_positive_finite: |
196 |
assumes v: "finite_prob_space M \<nu>" |
|
40859 | 197 |
assumes ac: "absolutely_continuous \<nu>" |
38656 | 198 |
and "1 < b" |
199 |
shows "0 \<le> KL_divergence b M \<nu> \<mu>" |
|
200 |
proof - |
|
201 |
interpret v: finite_prob_space M \<nu> using v . |
|
40859 | 202 |
have ms: "finite_measure_space M \<nu>" by default |
38656 | 203 |
|
40859 | 204 |
have "- (KL_divergence b M \<nu> \<mu>) \<le> log b (\<Sum>x\<in>space M. real (\<mu> {x}))" |
205 |
proof (subst KL_divergence_eq_finite[OF ms ac], safe intro!: log_setsum_divide not_empty) |
|
206 |
show "finite (space M)" using finite_space by simp |
|
207 |
show "1 < b" by fact |
|
208 |
show "(\<Sum>x\<in>space M. real (\<nu> {x})) = 1" using v.finite_sum_over_space_eq_1 by simp |
|
38656 | 209 |
|
40859 | 210 |
fix x assume "x \<in> space M" |
211 |
then have x: "{x} \<in> sets M" unfolding sets_eq_Pow by auto |
|
212 |
{ assume "0 < real (\<nu> {x})" |
|
213 |
then have "\<nu> {x} \<noteq> 0" by auto |
|
214 |
then have "\<mu> {x} \<noteq> 0" |
|
215 |
using ac[unfolded absolutely_continuous_def, THEN bspec, of "{x}"] x by auto |
|
216 |
thus "0 < prob {x}" using finite_measure[of "{x}"] x by auto } |
|
217 |
qed auto |
|
38656 | 218 |
thus "0 \<le> KL_divergence b M \<nu> \<mu>" using finite_sum_over_space_eq_1 by simp |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
219 |
qed |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
220 |
|
39097 | 221 |
subsection {* Mutual Information *} |
222 |
||
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
223 |
definition (in prob_space) |
38656 | 224 |
"mutual_information b S T X Y = |
40859 | 225 |
KL_divergence b (sigma (pair_algebra S T)) |
38656 | 226 |
(joint_distribution X Y) |
40859 | 227 |
(pair_sigma_finite.pair_measure S (distribution X) T (distribution Y))" |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
228 |
|
40859 | 229 |
definition (in prob_space) |
230 |
"entropy b s X = mutual_information b s s X X" |
|
231 |
||
232 |
abbreviation (in information_space) |
|
233 |
mutual_information_Pow ("\<I>'(_ ; _')") where |
|
36624 | 234 |
"\<I>(X ; Y) \<equiv> mutual_information b |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
235 |
\<lparr> space = X`space M, sets = Pow (X`space M) \<rparr> |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
236 |
\<lparr> space = Y`space M, sets = Pow (Y`space M) \<rparr> X Y" |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
237 |
|
40859 | 238 |
lemma (in prob_space) finite_variables_absolutely_continuous: |
239 |
assumes X: "finite_random_variable S X" and Y: "finite_random_variable T Y" |
|
240 |
shows "measure_space.absolutely_continuous (sigma (pair_algebra S T)) |
|
241 |
(pair_sigma_finite.pair_measure S (distribution X) T (distribution Y)) (joint_distribution X Y)" |
|
242 |
proof - |
|
243 |
interpret X: finite_prob_space S "distribution X" using X by (rule distribution_finite_prob_space) |
|
244 |
interpret Y: finite_prob_space T "distribution Y" using Y by (rule distribution_finite_prob_space) |
|
245 |
interpret XY: pair_finite_prob_space S "distribution X" T "distribution Y" by default |
|
246 |
interpret P: finite_prob_space XY.P "joint_distribution X Y" |
|
247 |
using assms by (intro joint_distribution_finite_prob_space) |
|
248 |
show "XY.absolutely_continuous (joint_distribution X Y)" |
|
249 |
proof (rule XY.absolutely_continuousI) |
|
250 |
show "finite_measure_space XY.P (joint_distribution X Y)" by default |
|
251 |
fix x assume "x \<in> space XY.P" and "XY.pair_measure {x} = 0" |
|
252 |
then obtain a b where "(a, b) = x" and "a \<in> space S" "b \<in> space T" |
|
253 |
and distr: "distribution X {a} * distribution Y {b} = 0" |
|
254 |
by (cases x) (auto simp: pair_algebra_def) |
|
255 |
with assms[THEN finite_random_variableD] |
|
256 |
joint_distribution_Times_le_fst[of S X T Y "{a}" "{b}"] |
|
257 |
joint_distribution_Times_le_snd[of S X T Y "{a}" "{b}"] |
|
258 |
have "joint_distribution X Y {x} \<le> distribution Y {b}" |
|
259 |
"joint_distribution X Y {x} \<le> distribution X {a}" |
|
260 |
by auto |
|
261 |
with distr show "joint_distribution X Y {x} = 0" by auto |
|
262 |
qed |
|
263 |
qed |
|
264 |
||
265 |
lemma (in information_space) |
|
266 |
assumes MX: "finite_random_variable MX X" |
|
267 |
assumes MY: "finite_random_variable MY Y" |
|
268 |
shows mutual_information_generic_eq: |
|
36624 | 269 |
"mutual_information b MX MY X Y = (\<Sum> (x,y) \<in> space MX \<times> space MY. |
38656 | 270 |
real (joint_distribution X Y {(x,y)}) * |
271 |
log b (real (joint_distribution X Y {(x,y)}) / |
|
272 |
(real (distribution X {x}) * real (distribution Y {y}))))" |
|
40859 | 273 |
(is ?sum) |
36624 | 274 |
and mutual_information_positive_generic: |
40859 | 275 |
"0 \<le> mutual_information b MX MY X Y" (is ?positive) |
36624 | 276 |
proof - |
40859 | 277 |
interpret X: finite_prob_space MX "distribution X" using MX by (rule distribution_finite_prob_space) |
278 |
interpret Y: finite_prob_space MY "distribution Y" using MY by (rule distribution_finite_prob_space) |
|
279 |
interpret XY: pair_finite_prob_space MX "distribution X" MY "distribution Y" by default |
|
280 |
interpret P: finite_prob_space XY.P "joint_distribution X Y" |
|
281 |
using assms by (intro joint_distribution_finite_prob_space) |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
282 |
|
40859 | 283 |
have P_ms: "finite_measure_space XY.P (joint_distribution X Y)" by default |
284 |
have P_ps: "finite_prob_space XY.P (joint_distribution X Y)" by default |
|
36624 | 285 |
|
40859 | 286 |
show ?sum |
38656 | 287 |
unfolding Let_def mutual_information_def |
40859 | 288 |
by (subst XY.KL_divergence_eq_finite[OF P_ms finite_variables_absolutely_continuous[OF MX MY]]) |
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
289 |
(auto simp add: pair_algebra_def setsum_cartesian_product' real_of_pextreal_mult[symmetric]) |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
290 |
|
36624 | 291 |
show ?positive |
40859 | 292 |
using XY.KL_divergence_positive_finite[OF P_ps finite_variables_absolutely_continuous[OF MX MY] b_gt_1] |
293 |
unfolding mutual_information_def . |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
294 |
qed |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
295 |
|
41661 | 296 |
lemma (in information_space) mutual_information_commute: |
297 |
assumes X: "finite_random_variable S X" and Y: "finite_random_variable T Y" |
|
298 |
shows "mutual_information b S T X Y = mutual_information b T S Y X" |
|
299 |
unfolding mutual_information_generic_eq[OF X Y] mutual_information_generic_eq[OF Y X] |
|
300 |
unfolding joint_distribution_commute_singleton[of X Y] |
|
301 |
by (auto simp add: ac_simps intro!: setsum_reindex_cong[OF swap_inj_on]) |
|
302 |
||
303 |
lemma (in information_space) mutual_information_commute_simple: |
|
304 |
assumes X: "simple_function X" and Y: "simple_function Y" |
|
305 |
shows "\<I>(X;Y) = \<I>(Y;X)" |
|
306 |
by (intro X Y simple_function_imp_finite_random_variable mutual_information_commute) |
|
307 |
||
40859 | 308 |
lemma (in information_space) mutual_information_eq: |
309 |
assumes "simple_function X" "simple_function Y" |
|
310 |
shows "\<I>(X;Y) = (\<Sum> (x,y) \<in> X ` space M \<times> Y ` space M. |
|
38656 | 311 |
real (distribution (\<lambda>x. (X x, Y x)) {(x,y)}) * log b (real (distribution (\<lambda>x. (X x, Y x)) {(x,y)}) / |
312 |
(real (distribution X {x}) * real (distribution Y {y}))))" |
|
40859 | 313 |
using assms by (simp add: mutual_information_generic_eq) |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
314 |
|
40859 | 315 |
lemma (in information_space) mutual_information_generic_cong: |
39097 | 316 |
assumes X: "\<And>x. x \<in> space M \<Longrightarrow> X x = X' x" |
317 |
assumes Y: "\<And>x. x \<in> space M \<Longrightarrow> Y x = Y' x" |
|
40859 | 318 |
shows "mutual_information b MX MY X Y = mutual_information b MX MY X' Y'" |
319 |
unfolding mutual_information_def using X Y |
|
320 |
by (simp cong: distribution_cong) |
|
39097 | 321 |
|
40859 | 322 |
lemma (in information_space) mutual_information_cong: |
323 |
assumes X: "\<And>x. x \<in> space M \<Longrightarrow> X x = X' x" |
|
324 |
assumes Y: "\<And>x. x \<in> space M \<Longrightarrow> Y x = Y' x" |
|
325 |
shows "\<I>(X; Y) = \<I>(X'; Y')" |
|
326 |
unfolding mutual_information_def using X Y |
|
327 |
by (simp cong: distribution_cong image_cong) |
|
328 |
||
329 |
lemma (in information_space) mutual_information_positive: |
|
330 |
assumes "simple_function X" "simple_function Y" |
|
331 |
shows "0 \<le> \<I>(X;Y)" |
|
332 |
using assms by (simp add: mutual_information_positive_generic) |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
333 |
|
39097 | 334 |
subsection {* Entropy *} |
335 |
||
40859 | 336 |
abbreviation (in information_space) |
337 |
entropy_Pow ("\<H>'(_')") where |
|
36624 | 338 |
"\<H>(X) \<equiv> entropy b \<lparr> space = X`space M, sets = Pow (X`space M) \<rparr> X" |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
339 |
|
40859 | 340 |
lemma (in information_space) entropy_generic_eq: |
341 |
assumes MX: "finite_random_variable MX X" |
|
39097 | 342 |
shows "entropy b MX X = -(\<Sum> x \<in> space MX. real (distribution X {x}) * log b (real (distribution X {x})))" |
343 |
proof - |
|
40859 | 344 |
interpret MX: finite_prob_space MX "distribution X" using MX by (rule distribution_finite_prob_space) |
39097 | 345 |
let "?X x" = "real (distribution X {x})" |
346 |
let "?XX x y" = "real (joint_distribution X X {(x, y)})" |
|
347 |
{ fix x y |
|
348 |
have "(\<lambda>x. (X x, X x)) -` {(x, y)} = (if x = y then X -` {x} else {})" by auto |
|
349 |
then have "?XX x y * log b (?XX x y / (?X x * ?X y)) = |
|
350 |
(if x = y then - ?X y * log b (?X y) else 0)" |
|
40859 | 351 |
unfolding distribution_def by (auto simp: log_simps zero_less_mult_iff) } |
39097 | 352 |
note remove_XX = this |
353 |
show ?thesis |
|
354 |
unfolding entropy_def mutual_information_generic_eq[OF MX MX] |
|
355 |
unfolding setsum_cartesian_product[symmetric] setsum_negf[symmetric] remove_XX |
|
356 |
by (auto simp: setsum_cases MX.finite_space) |
|
357 |
qed |
|
36624 | 358 |
|
40859 | 359 |
lemma (in information_space) entropy_eq: |
360 |
assumes "simple_function X" |
|
361 |
shows "\<H>(X) = -(\<Sum> x \<in> X ` space M. real (distribution X {x}) * log b (real (distribution X {x})))" |
|
362 |
using assms by (simp add: entropy_generic_eq) |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
363 |
|
40859 | 364 |
lemma (in information_space) entropy_positive: |
365 |
"simple_function X \<Longrightarrow> 0 \<le> \<H>(X)" |
|
366 |
unfolding entropy_def by (simp add: mutual_information_positive) |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
367 |
|
40859 | 368 |
lemma (in information_space) entropy_certainty_eq_0: |
369 |
assumes "simple_function X" and "x \<in> X ` space M" and "distribution X {x} = 1" |
|
39097 | 370 |
shows "\<H>(X) = 0" |
371 |
proof - |
|
372 |
interpret X: finite_prob_space "\<lparr> space = X ` space M, sets = Pow (X ` space M) \<rparr>" "distribution X" |
|
40859 | 373 |
using simple_function_imp_finite_random_variable[OF `simple_function X`] |
374 |
by (rule distribution_finite_prob_space) |
|
39097 | 375 |
have "distribution X (X ` space M - {x}) = distribution X (X ` space M) - distribution X {x}" |
376 |
using X.measure_compl[of "{x}"] assms by auto |
|
377 |
also have "\<dots> = 0" using X.prob_space assms by auto |
|
378 |
finally have X0: "distribution X (X ` space M - {x}) = 0" by auto |
|
379 |
{ fix y assume asm: "y \<noteq> x" "y \<in> X ` space M" |
|
380 |
hence "{y} \<subseteq> X ` space M - {x}" by auto |
|
381 |
from X.measure_mono[OF this] X0 asm |
|
382 |
have "distribution X {y} = 0" by auto } |
|
383 |
hence fi: "\<And> y. y \<in> X ` space M \<Longrightarrow> real (distribution X {y}) = (if x = y then 1 else 0)" |
|
384 |
using assms by auto |
|
385 |
have y: "\<And>y. (if x = y then 1 else 0) * log b (if x = y then 1 else 0) = 0" by simp |
|
40859 | 386 |
show ?thesis unfolding entropy_eq[OF `simple_function X`] by (auto simp: y fi) |
39097 | 387 |
qed |
388 |
||
40859 | 389 |
lemma (in information_space) entropy_le_card_not_0: |
390 |
assumes "simple_function X" |
|
391 |
shows "\<H>(X) \<le> log b (real (card (X ` space M \<inter> {x . distribution X {x} \<noteq> 0})))" |
|
39097 | 392 |
proof - |
393 |
let "?d x" = "distribution X {x}" |
|
394 |
let "?p x" = "real (?d x)" |
|
395 |
have "\<H>(X) = (\<Sum>x\<in>X`space M. ?p x * log b (1 / ?p x))" |
|
40859 | 396 |
by (auto intro!: setsum_cong simp: entropy_eq[OF `simple_function X`] setsum_negf[symmetric] log_simps not_less) |
39097 | 397 |
also have "\<dots> \<le> log b (\<Sum>x\<in>X`space M. ?p x * (1 / ?p x))" |
398 |
apply (rule log_setsum') |
|
40859 | 399 |
using not_empty b_gt_1 `simple_function X` sum_over_space_real_distribution |
400 |
by (auto simp: simple_function_def) |
|
39097 | 401 |
also have "\<dots> = log b (\<Sum>x\<in>X`space M. if ?d x \<noteq> 0 then 1 else 0)" |
40859 | 402 |
using distribution_finite[OF `simple_function X`[THEN simple_function_imp_random_variable], simplified] |
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
403 |
by (intro arg_cong[where f="\<lambda>X. log b X"] setsum_cong) (auto simp: real_of_pextreal_eq_0) |
39097 | 404 |
finally show ?thesis |
40859 | 405 |
using `simple_function X` by (auto simp: setsum_cases real_eq_of_nat simple_function_def) |
39097 | 406 |
qed |
407 |
||
40859 | 408 |
lemma (in information_space) entropy_uniform_max: |
409 |
assumes "simple_function X" |
|
39097 | 410 |
assumes "\<And>x y. \<lbrakk> x \<in> X ` space M ; y \<in> X ` space M \<rbrakk> \<Longrightarrow> distribution X {x} = distribution X {y}" |
411 |
shows "\<H>(X) = log b (real (card (X ` space M)))" |
|
412 |
proof - |
|
40859 | 413 |
interpret X: finite_prob_space "\<lparr> space = X ` space M, sets = Pow (X ` space M) \<rparr>" "distribution X" |
414 |
using simple_function_imp_finite_random_variable[OF `simple_function X`] |
|
415 |
by (rule distribution_finite_prob_space) |
|
39097 | 416 |
have card_gt0: "0 < card (X ` space M)" unfolding card_gt_0_iff |
40859 | 417 |
using `simple_function X` not_empty by (auto simp: simple_function_def) |
39097 | 418 |
{ fix x assume "x \<in> X ` space M" |
419 |
hence "real (distribution X {x}) = 1 / real (card (X ` space M))" |
|
40859 | 420 |
proof (rule X.uniform_prob[simplified]) |
39097 | 421 |
fix x y assume "x \<in> X`space M" "y \<in> X`space M" |
40859 | 422 |
from assms(2)[OF this] show "real (distribution X {x}) = real (distribution X {y})" by simp |
39097 | 423 |
qed } |
424 |
thus ?thesis |
|
40859 | 425 |
using not_empty X.finite_space b_gt_1 card_gt0 |
426 |
by (simp add: entropy_eq[OF `simple_function X`] real_eq_of_nat[symmetric] log_simps) |
|
39097 | 427 |
qed |
428 |
||
40859 | 429 |
lemma (in information_space) entropy_le_card: |
430 |
assumes "simple_function X" |
|
431 |
shows "\<H>(X) \<le> log b (real (card (X ` space M)))" |
|
39097 | 432 |
proof cases |
433 |
assume "X ` space M \<inter> {x. distribution X {x} \<noteq> 0} = {}" |
|
434 |
then have "\<And>x. x\<in>X`space M \<Longrightarrow> distribution X {x} = 0" by auto |
|
435 |
moreover |
|
436 |
have "0 < card (X`space M)" |
|
40859 | 437 |
using `simple_function X` not_empty |
438 |
by (auto simp: card_gt_0_iff simple_function_def) |
|
39097 | 439 |
then have "log b 1 \<le> log b (real (card (X`space M)))" |
440 |
using b_gt_1 by (intro log_le) auto |
|
40859 | 441 |
ultimately show ?thesis using assms by (simp add: entropy_eq) |
39097 | 442 |
next |
443 |
assume False: "X ` space M \<inter> {x. distribution X {x} \<noteq> 0} \<noteq> {}" |
|
444 |
have "card (X ` space M \<inter> {x. distribution X {x} \<noteq> 0}) \<le> card (X ` space M)" |
|
40859 | 445 |
(is "?A \<le> ?B") using assms not_empty by (auto intro!: card_mono simp: simple_function_def) |
446 |
note entropy_le_card_not_0[OF assms] |
|
39097 | 447 |
also have "log b (real ?A) \<le> log b (real ?B)" |
40859 | 448 |
using b_gt_1 False not_empty `?A \<le> ?B` assms |
449 |
by (auto intro!: log_le simp: card_gt_0_iff simp: simple_function_def) |
|
39097 | 450 |
finally show ?thesis . |
451 |
qed |
|
452 |
||
40859 | 453 |
lemma (in information_space) entropy_commute: |
454 |
assumes "simple_function X" "simple_function Y" |
|
455 |
shows "\<H>(\<lambda>x. (X x, Y x)) = \<H>(\<lambda>x. (Y x, X x))" |
|
39097 | 456 |
proof - |
40859 | 457 |
have sf: "simple_function (\<lambda>x. (X x, Y x))" "simple_function (\<lambda>x. (Y x, X x))" |
458 |
using assms by (auto intro: simple_function_Pair) |
|
39097 | 459 |
have *: "(\<lambda>x. (Y x, X x))`space M = (\<lambda>(a,b). (b,a))`(\<lambda>x. (X x, Y x))`space M" |
460 |
by auto |
|
461 |
have inj: "\<And>X. inj_on (\<lambda>(a,b). (b,a)) X" |
|
462 |
by (auto intro!: inj_onI) |
|
463 |
show ?thesis |
|
40859 | 464 |
unfolding sf[THEN entropy_eq] unfolding * setsum_reindex[OF inj] |
39097 | 465 |
by (simp add: joint_distribution_commute[of Y X] split_beta) |
466 |
qed |
|
467 |
||
40859 | 468 |
lemma (in information_space) entropy_eq_cartesian_product: |
469 |
assumes "simple_function X" "simple_function Y" |
|
470 |
shows "\<H>(\<lambda>x. (X x, Y x)) = -(\<Sum>x\<in>X`space M. \<Sum>y\<in>Y`space M. |
|
39097 | 471 |
real (joint_distribution X Y {(x,y)}) * |
472 |
log b (real (joint_distribution X Y {(x,y)})))" |
|
473 |
proof - |
|
40859 | 474 |
have sf: "simple_function (\<lambda>x. (X x, Y x))" |
475 |
using assms by (auto intro: simple_function_Pair) |
|
39097 | 476 |
{ fix x assume "x\<notin>(\<lambda>x. (X x, Y x))`space M" |
477 |
then have "(\<lambda>x. (X x, Y x)) -` {x} \<inter> space M = {}" by auto |
|
478 |
then have "joint_distribution X Y {x} = 0" |
|
479 |
unfolding distribution_def by auto } |
|
40859 | 480 |
then show ?thesis using sf assms |
481 |
unfolding entropy_eq[OF sf] neg_equal_iff_equal setsum_cartesian_product |
|
482 |
by (auto intro!: setsum_mono_zero_cong_left simp: simple_function_def) |
|
39097 | 483 |
qed |
484 |
||
485 |
subsection {* Conditional Mutual Information *} |
|
486 |
||
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
487 |
definition (in prob_space) |
38656 | 488 |
"conditional_mutual_information b M1 M2 M3 X Y Z \<equiv> |
40859 | 489 |
mutual_information b M1 (sigma (pair_algebra M2 M3)) X (\<lambda>x. (Y x, Z x)) - |
38656 | 490 |
mutual_information b M1 M3 X Z" |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
491 |
|
40859 | 492 |
abbreviation (in information_space) |
493 |
conditional_mutual_information_Pow ("\<I>'( _ ; _ | _ ')") where |
|
36624 | 494 |
"\<I>(X ; Y | Z) \<equiv> conditional_mutual_information b |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
495 |
\<lparr> space = X`space M, sets = Pow (X`space M) \<rparr> |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
496 |
\<lparr> space = Y`space M, sets = Pow (Y`space M) \<rparr> |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
497 |
\<lparr> space = Z`space M, sets = Pow (Z`space M) \<rparr> |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
498 |
X Y Z" |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
499 |
|
38656 | 500 |
|
40859 | 501 |
lemma (in information_space) conditional_mutual_information_generic_eq: |
502 |
assumes MX: "finite_random_variable MX X" |
|
503 |
and MY: "finite_random_variable MY Y" |
|
504 |
and MZ: "finite_random_variable MZ Z" |
|
505 |
shows "conditional_mutual_information b MX MY MZ X Y Z = (\<Sum>(x, y, z) \<in> space MX \<times> space MY \<times> space MZ. |
|
38656 | 506 |
real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) * |
507 |
log b (real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) / |
|
508 |
(real (joint_distribution X Z {(x, z)}) * real (joint_distribution Y Z {(y,z)} / distribution Z {z}))))" |
|
40859 | 509 |
(is "_ = (\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?XZ x z * ?YZdZ y z)))") |
510 |
proof - |
|
511 |
let ?YZ = "\<lambda>y z. real (joint_distribution Y Z {(y, z)})" |
|
512 |
let ?X = "\<lambda>x. real (distribution X {x})" |
|
513 |
let ?Z = "\<lambda>z. real (distribution Z {z})" |
|
514 |
||
515 |
txt {* This proof is actually quiet easy, however we need to show that the |
|
516 |
distributions are finite and the joint distributions are zero when one of |
|
517 |
the variables distribution is also zero. *} |
|
518 |
||
519 |
note finite_var = MX MY MZ |
|
520 |
note random_var = finite_var[THEN finite_random_variableD] |
|
521 |
||
522 |
note space_simps = space_pair_algebra space_sigma algebra.simps |
|
523 |
||
524 |
note YZ = finite_random_variable_pairI[OF finite_var(2,3)] |
|
525 |
note XZ = finite_random_variable_pairI[OF finite_var(1,3)] |
|
526 |
note ZX = finite_random_variable_pairI[OF finite_var(3,1)] |
|
527 |
note YZX = finite_random_variable_pairI[OF finite_var(2) ZX] |
|
528 |
note order1 = |
|
529 |
finite_distribution_order(5,6)[OF finite_var(1) YZ, simplified space_simps] |
|
530 |
finite_distribution_order(5,6)[OF finite_var(1,3), simplified space_simps] |
|
531 |
||
532 |
note finite = finite_var(1) YZ finite_var(3) XZ YZX |
|
533 |
note finite[THEN finite_distribution_finite, simplified space_simps, simp] |
|
534 |
||
535 |
have order2: "\<And>x y z. \<lbrakk>x \<in> space MX; y \<in> space MY; z \<in> space MZ; joint_distribution X Z {(x, z)} = 0\<rbrakk> |
|
536 |
\<Longrightarrow> joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)} = 0" |
|
537 |
unfolding joint_distribution_commute_singleton[of X] |
|
538 |
unfolding joint_distribution_assoc_singleton[symmetric] |
|
539 |
using finite_distribution_order(6)[OF finite_var(2) ZX] |
|
540 |
by (auto simp: space_simps) |
|
36624 | 541 |
|
40859 | 542 |
have "(\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?XZ x z * ?YZdZ y z))) = |
543 |
(\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * (log b (?XYZ x y z / (?X x * ?YZ y z)) - log b (?XZ x z / (?X x * ?Z z))))" |
|
544 |
(is "(\<Sum>(x, y, z)\<in>?S. ?L x y z) = (\<Sum>(x, y, z)\<in>?S. ?R x y z)") |
|
545 |
proof (safe intro!: setsum_cong) |
|
546 |
fix x y z assume space: "x \<in> space MX" "y \<in> space MY" "z \<in> space MZ" |
|
547 |
then have *: "?XYZ x y z / (?XZ x z * ?YZdZ y z) = |
|
548 |
(?XYZ x y z / (?X x * ?YZ y z)) / (?XZ x z / (?X x * ?Z z))" |
|
549 |
using order1(3) |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
550 |
by (auto simp: real_of_pextreal_mult[symmetric] real_of_pextreal_eq_0) |
40859 | 551 |
show "?L x y z = ?R x y z" |
552 |
proof cases |
|
553 |
assume "?XYZ x y z \<noteq> 0" |
|
554 |
with space b_gt_1 order1 order2 show ?thesis unfolding * |
|
555 |
by (subst log_divide) |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
556 |
(auto simp: zero_less_divide_iff zero_less_real_of_pextreal |
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
557 |
real_of_pextreal_eq_0 zero_less_mult_iff) |
40859 | 558 |
qed simp |
559 |
qed |
|
560 |
also have "\<dots> = (\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?X x * ?YZ y z))) - |
|
561 |
(\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XZ x z / (?X x * ?Z z)))" |
|
562 |
by (auto simp add: setsum_subtractf[symmetric] field_simps intro!: setsum_cong) |
|
563 |
also have "(\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XZ x z / (?X x * ?Z z))) = |
|
564 |
(\<Sum>(x, z)\<in>space MX \<times> space MZ. ?XZ x z * log b (?XZ x z / (?X x * ?Z z)))" |
|
565 |
unfolding setsum_cartesian_product[symmetric] setsum_commute[of _ _ "space MY"] |
|
566 |
setsum_left_distrib[symmetric] |
|
567 |
unfolding joint_distribution_commute_singleton[of X] |
|
568 |
unfolding joint_distribution_assoc_singleton[symmetric] |
|
569 |
using setsum_real_joint_distribution_singleton[OF finite_var(2) ZX, unfolded space_simps] |
|
570 |
by (intro setsum_cong refl) simp |
|
571 |
also have "(\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?X x * ?YZ y z))) - |
|
572 |
(\<Sum>(x, z)\<in>space MX \<times> space MZ. ?XZ x z * log b (?XZ x z / (?X x * ?Z z))) = |
|
573 |
conditional_mutual_information b MX MY MZ X Y Z" |
|
574 |
unfolding conditional_mutual_information_def |
|
575 |
unfolding mutual_information_generic_eq[OF finite_var(1,3)] |
|
576 |
unfolding mutual_information_generic_eq[OF finite_var(1) YZ] |
|
577 |
by (simp add: space_sigma space_pair_algebra setsum_cartesian_product') |
|
578 |
finally show ?thesis by simp |
|
579 |
qed |
|
580 |
||
581 |
lemma (in information_space) conditional_mutual_information_eq: |
|
582 |
assumes "simple_function X" "simple_function Y" "simple_function Z" |
|
583 |
shows "\<I>(X;Y|Z) = (\<Sum>(x, y, z) \<in> X`space M \<times> Y`space M \<times> Z`space M. |
|
584 |
real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) * |
|
585 |
log b (real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) / |
|
586 |
(real (joint_distribution X Z {(x, z)}) * real (joint_distribution Y Z {(y,z)} / distribution Z {z}))))" |
|
587 |
using conditional_mutual_information_generic_eq[OF assms[THEN simple_function_imp_finite_random_variable]] |
|
588 |
by simp |
|
589 |
||
590 |
lemma (in information_space) conditional_mutual_information_eq_mutual_information: |
|
591 |
assumes X: "simple_function X" and Y: "simple_function Y" |
|
592 |
shows "\<I>(X ; Y) = \<I>(X ; Y | (\<lambda>x. ()))" |
|
36624 | 593 |
proof - |
594 |
have [simp]: "(\<lambda>x. ()) ` space M = {()}" using not_empty by auto |
|
40859 | 595 |
have C: "simple_function (\<lambda>x. ())" by auto |
36624 | 596 |
show ?thesis |
40859 | 597 |
unfolding conditional_mutual_information_eq[OF X Y C] |
598 |
unfolding mutual_information_eq[OF X Y] |
|
36624 | 599 |
by (simp add: setsum_cartesian_product' distribution_remove_const) |
600 |
qed |
|
601 |
||
40859 | 602 |
lemma (in prob_space) distribution_unit[simp]: "distribution (\<lambda>x. ()) {()} = 1" |
603 |
unfolding distribution_def using measure_space_1 by auto |
|
604 |
||
605 |
lemma (in prob_space) joint_distribution_unit[simp]: "distribution (\<lambda>x. (X x, ())) {(a, ())} = distribution X {a}" |
|
606 |
unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>]) |
|
607 |
||
608 |
lemma (in prob_space) setsum_distribution: |
|
609 |
assumes X: "finite_random_variable MX X" shows "(\<Sum>a\<in>space MX. distribution X {a}) = 1" |
|
610 |
using setsum_joint_distribution[OF assms, of "\<lparr> space = UNIV, sets = Pow UNIV \<rparr>" "\<lambda>x. ()" "{()}"] |
|
611 |
using sigma_algebra_Pow[of "UNIV::unit set"] by simp |
|
612 |
||
613 |
lemma (in prob_space) setsum_real_distribution: |
|
614 |
assumes X: "finite_random_variable MX X" shows "(\<Sum>a\<in>space MX. real (distribution X {a})) = 1" |
|
615 |
using setsum_real_joint_distribution[OF assms, of "\<lparr> space = UNIV, sets = Pow UNIV \<rparr>" "\<lambda>x. ()" "{()}"] |
|
616 |
using sigma_algebra_Pow[of "UNIV::unit set"] by simp |
|
617 |
||
618 |
lemma (in information_space) conditional_mutual_information_generic_positive: |
|
619 |
assumes "finite_random_variable MX X" and "finite_random_variable MY Y" and "finite_random_variable MZ Z" |
|
620 |
shows "0 \<le> conditional_mutual_information b MX MY MZ X Y Z" |
|
621 |
proof (cases "space MX \<times> space MY \<times> space MZ = {}") |
|
622 |
case True show ?thesis |
|
623 |
unfolding conditional_mutual_information_generic_eq[OF assms] True |
|
624 |
by simp |
|
625 |
next |
|
626 |
case False |
|
38656 | 627 |
let "?dXYZ A" = "real (distribution (\<lambda>x. (X x, Y x, Z x)) A)" |
628 |
let "?dXZ A" = "real (joint_distribution X Z A)" |
|
629 |
let "?dYZ A" = "real (joint_distribution Y Z A)" |
|
630 |
let "?dX A" = "real (distribution X A)" |
|
631 |
let "?dZ A" = "real (distribution Z A)" |
|
40859 | 632 |
let ?M = "space MX \<times> space MY \<times> space MZ" |
36624 | 633 |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
634 |
have split_beta: "\<And>f. split f = (\<lambda>x. f (fst x) (snd x))" by (simp add: fun_eq_iff) |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
635 |
|
40859 | 636 |
note space_simps = space_pair_algebra space_sigma algebra.simps |
637 |
||
638 |
note finite_var = assms |
|
639 |
note YZ = finite_random_variable_pairI[OF finite_var(2,3)] |
|
640 |
note XZ = finite_random_variable_pairI[OF finite_var(1,3)] |
|
641 |
note ZX = finite_random_variable_pairI[OF finite_var(3,1)] |
|
642 |
note YZ = finite_random_variable_pairI[OF finite_var(2,3)] |
|
643 |
note XYZ = finite_random_variable_pairI[OF finite_var(1) YZ] |
|
644 |
note finite = finite_var(3) YZ XZ XYZ |
|
645 |
note finite = finite[THEN finite_distribution_finite, simplified space_simps] |
|
646 |
||
647 |
have order: "\<And>x y z. \<lbrakk>x \<in> space MX; y \<in> space MY; z \<in> space MZ; joint_distribution X Z {(x, z)} = 0\<rbrakk> |
|
648 |
\<Longrightarrow> joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)} = 0" |
|
649 |
unfolding joint_distribution_commute_singleton[of X] |
|
650 |
unfolding joint_distribution_assoc_singleton[symmetric] |
|
651 |
using finite_distribution_order(6)[OF finite_var(2) ZX] |
|
652 |
by (auto simp: space_simps) |
|
653 |
||
654 |
note order = order |
|
655 |
finite_distribution_order(5,6)[OF finite_var(1) YZ, simplified space_simps] |
|
656 |
finite_distribution_order(5,6)[OF finite_var(2,3), simplified space_simps] |
|
657 |
||
658 |
have "- conditional_mutual_information b MX MY MZ X Y Z = - (\<Sum>(x, y, z) \<in> ?M. ?dXYZ {(x, y, z)} * |
|
659 |
log b (?dXYZ {(x, y, z)} / (?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z})))" |
|
660 |
unfolding conditional_mutual_information_generic_eq[OF assms] neg_equal_iff_equal |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
661 |
by (intro setsum_cong) (auto intro!: arg_cong[where f="log b"] simp: real_of_pextreal_mult[symmetric]) |
40859 | 662 |
also have "\<dots> \<le> log b (\<Sum>(x, y, z) \<in> ?M. ?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z})" |
36624 | 663 |
unfolding split_beta |
664 |
proof (rule log_setsum_divide) |
|
40859 | 665 |
show "?M \<noteq> {}" using False by simp |
36624 | 666 |
show "1 < b" using b_gt_1 . |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
667 |
|
40859 | 668 |
show "finite ?M" using assms |
669 |
unfolding finite_sigma_algebra_def finite_sigma_algebra_axioms_def by auto |
|
670 |
||
671 |
show "(\<Sum>x\<in>?M. ?dXYZ {(fst x, fst (snd x), snd (snd x))}) = 1" |
|
672 |
unfolding setsum_cartesian_product' |
|
673 |
unfolding setsum_commute[of _ "space MY"] |
|
674 |
unfolding setsum_commute[of _ "space MZ"] |
|
675 |
by (simp_all add: space_pair_algebra |
|
676 |
setsum_real_joint_distribution_singleton[OF `finite_random_variable MX X` YZ] |
|
677 |
setsum_real_joint_distribution_singleton[OF `finite_random_variable MY Y` finite_var(3)] |
|
678 |
setsum_real_distribution[OF `finite_random_variable MZ Z`]) |
|
679 |
||
36624 | 680 |
fix x assume "x \<in> ?M" |
38656 | 681 |
let ?x = "(fst x, fst (snd x), snd (snd x))" |
682 |
||
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
683 |
show "0 \<le> ?dXYZ {?x}" using real_pextreal_nonneg . |
36624 | 684 |
show "0 \<le> ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}" |
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
685 |
by (simp add: real_pextreal_nonneg mult_nonneg_nonneg divide_nonneg_nonneg) |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
686 |
|
38656 | 687 |
assume *: "0 < ?dXYZ {?x}" |
40859 | 688 |
with `x \<in> ?M` show "0 < ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}" |
689 |
using finite order |
|
690 |
by (cases x) |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
691 |
(auto simp add: zero_less_real_of_pextreal zero_less_mult_iff zero_less_divide_iff) |
40859 | 692 |
qed |
693 |
also have "(\<Sum>(x, y, z) \<in> ?M. ?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z}) = (\<Sum>z\<in>space MZ. ?dZ {z})" |
|
36624 | 694 |
apply (simp add: setsum_cartesian_product') |
695 |
apply (subst setsum_commute) |
|
696 |
apply (subst (2) setsum_commute) |
|
40859 | 697 |
by (auto simp: setsum_divide_distrib[symmetric] setsum_product[symmetric] |
698 |
setsum_real_joint_distribution_singleton[OF finite_var(1,3)] |
|
699 |
setsum_real_joint_distribution_singleton[OF finite_var(2,3)] |
|
36624 | 700 |
intro!: setsum_cong) |
40859 | 701 |
also have "log b (\<Sum>z\<in>space MZ. ?dZ {z}) = 0" |
702 |
unfolding setsum_real_distribution[OF finite_var(3)] by simp |
|
703 |
finally show ?thesis by simp |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
704 |
qed |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
705 |
|
40859 | 706 |
lemma (in information_space) conditional_mutual_information_positive: |
707 |
assumes "simple_function X" and "simple_function Y" and "simple_function Z" |
|
708 |
shows "0 \<le> \<I>(X;Y|Z)" |
|
709 |
using conditional_mutual_information_generic_positive[OF assms[THEN simple_function_imp_finite_random_variable]] |
|
710 |
by simp |
|
711 |
||
39097 | 712 |
subsection {* Conditional Entropy *} |
713 |
||
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
714 |
definition (in prob_space) |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
715 |
"conditional_entropy b S T X Y = conditional_mutual_information b S S T X X Y" |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
716 |
|
40859 | 717 |
abbreviation (in information_space) |
718 |
conditional_entropy_Pow ("\<H>'(_ | _')") where |
|
36624 | 719 |
"\<H>(X | Y) \<equiv> conditional_entropy b |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
720 |
\<lparr> space = X`space M, sets = Pow (X`space M) \<rparr> |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
721 |
\<lparr> space = Y`space M, sets = Pow (Y`space M) \<rparr> X Y" |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
722 |
|
40859 | 723 |
lemma (in information_space) conditional_entropy_positive: |
724 |
"simple_function X \<Longrightarrow> simple_function Y \<Longrightarrow> 0 \<le> \<H>(X | Y)" |
|
725 |
unfolding conditional_entropy_def by (auto intro!: conditional_mutual_information_positive) |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
726 |
|
40859 | 727 |
lemma (in measure_space) empty_measureI: "A = {} \<Longrightarrow> \<mu> A = 0" by simp |
728 |
||
729 |
lemma (in information_space) conditional_entropy_generic_eq: |
|
730 |
assumes MX: "finite_random_variable MX X" |
|
731 |
assumes MZ: "finite_random_variable MZ Z" |
|
39097 | 732 |
shows "conditional_entropy b MX MZ X Z = |
733 |
- (\<Sum>(x, z)\<in>space MX \<times> space MZ. |
|
734 |
real (joint_distribution X Z {(x, z)}) * |
|
735 |
log b (real (joint_distribution X Z {(x, z)}) / real (distribution Z {z})))" |
|
40859 | 736 |
proof - |
737 |
interpret MX: finite_sigma_algebra MX using MX by simp |
|
738 |
interpret MZ: finite_sigma_algebra MZ using MZ by simp |
|
739 |
let "?XXZ x y z" = "joint_distribution X (\<lambda>x. (X x, Z x)) {(x, y, z)}" |
|
740 |
let "?XZ x z" = "joint_distribution X Z {(x, z)}" |
|
741 |
let "?Z z" = "distribution Z {z}" |
|
742 |
let "?f x y z" = "log b (real (?XXZ x y z) / (real (?XZ x z) * real (?XZ y z / ?Z z)))" |
|
743 |
{ fix x z have "?XXZ x x z = ?XZ x z" |
|
744 |
unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>]) } |
|
745 |
note this[simp] |
|
746 |
{ fix x x' :: 'b and z assume "x' \<noteq> x" |
|
747 |
then have "?XXZ x x' z = 0" |
|
748 |
by (auto simp: distribution_def intro!: arg_cong[where f=\<mu>] empty_measureI) } |
|
749 |
note this[simp] |
|
750 |
{ fix x x' z assume *: "x \<in> space MX" "z \<in> space MZ" |
|
751 |
then have "(\<Sum>x'\<in>space MX. real (?XXZ x x' z) * ?f x x' z) |
|
752 |
= (\<Sum>x'\<in>space MX. if x = x' then real (?XZ x z) * ?f x x z else 0)" |
|
753 |
by (auto intro!: setsum_cong) |
|
754 |
also have "\<dots> = real (?XZ x z) * ?f x x z" |
|
755 |
using `x \<in> space MX` by (simp add: setsum_cases[OF MX.finite_space]) |
|
756 |
also have "\<dots> = real (?XZ x z) * log b (real (?Z z) / real (?XZ x z))" |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
757 |
by (auto simp: real_of_pextreal_mult[symmetric]) |
40859 | 758 |
also have "\<dots> = - real (?XZ x z) * log b (real (?XZ x z) / real (?Z z))" |
759 |
using assms[THEN finite_distribution_finite] |
|
760 |
using finite_distribution_order(6)[OF MX MZ] |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
761 |
by (auto simp: log_simps field_simps zero_less_mult_iff zero_less_real_of_pextreal real_of_pextreal_eq_0) |
40859 | 762 |
finally have "(\<Sum>x'\<in>space MX. real (?XXZ x x' z) * ?f x x' z) = |
763 |
- real (?XZ x z) * log b (real (?XZ x z) / real (?Z z))" . } |
|
764 |
note * = this |
|
765 |
||
766 |
show ?thesis |
|
767 |
unfolding conditional_entropy_def |
|
768 |
unfolding conditional_mutual_information_generic_eq[OF MX MX MZ] |
|
769 |
by (auto simp: setsum_cartesian_product' setsum_negf[symmetric] |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
770 |
setsum_commute[of _ "space MZ"] * simp del: divide_pextreal_def |
40859 | 771 |
intro!: setsum_cong) |
39097 | 772 |
qed |
773 |
||
40859 | 774 |
lemma (in information_space) conditional_entropy_eq: |
775 |
assumes "simple_function X" "simple_function Z" |
|
776 |
shows "\<H>(X | Z) = |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
777 |
- (\<Sum>(x, z)\<in>X ` space M \<times> Z ` space M. |
38656 | 778 |
real (joint_distribution X Z {(x, z)}) * |
779 |
log b (real (joint_distribution X Z {(x, z)}) / real (distribution Z {z})))" |
|
40859 | 780 |
using conditional_entropy_generic_eq[OF assms[THEN simple_function_imp_finite_random_variable]] |
781 |
by simp |
|
39097 | 782 |
|
40859 | 783 |
lemma (in information_space) conditional_entropy_eq_ce_with_hypothesis: |
784 |
assumes X: "simple_function X" and Y: "simple_function Y" |
|
785 |
shows "\<H>(X | Y) = |
|
39097 | 786 |
-(\<Sum>y\<in>Y`space M. real (distribution Y {y}) * |
787 |
(\<Sum>x\<in>X`space M. real (joint_distribution X Y {(x,y)}) / real (distribution Y {(y)}) * |
|
788 |
log b (real (joint_distribution X Y {(x,y)}) / real (distribution Y {(y)}))))" |
|
40859 | 789 |
unfolding conditional_entropy_eq[OF assms] |
790 |
using finite_distribution_finite[OF finite_random_variable_pairI[OF assms[THEN simple_function_imp_finite_random_variable]]] |
|
791 |
using finite_distribution_order(5,6)[OF assms[THEN simple_function_imp_finite_random_variable]] |
|
792 |
using finite_distribution_finite[OF Y[THEN simple_function_imp_finite_random_variable]] |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
793 |
by (auto simp: setsum_cartesian_product' setsum_commute[of _ "Y`space M"] setsum_right_distrib real_of_pextreal_eq_0 |
40859 | 794 |
intro!: setsum_cong) |
39097 | 795 |
|
40859 | 796 |
lemma (in information_space) conditional_entropy_eq_cartesian_product: |
797 |
assumes "simple_function X" "simple_function Y" |
|
798 |
shows "\<H>(X | Y) = -(\<Sum>x\<in>X`space M. \<Sum>y\<in>Y`space M. |
|
39097 | 799 |
real (joint_distribution X Y {(x,y)}) * |
800 |
log b (real (joint_distribution X Y {(x,y)}) / real (distribution Y {y})))" |
|
40859 | 801 |
unfolding conditional_entropy_eq[OF assms] |
802 |
by (auto intro!: setsum_cong simp: setsum_cartesian_product') |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
803 |
|
39097 | 804 |
subsection {* Equalities *} |
805 |
||
40859 | 806 |
lemma (in information_space) mutual_information_eq_entropy_conditional_entropy: |
807 |
assumes X: "simple_function X" and Z: "simple_function Z" |
|
808 |
shows "\<I>(X ; Z) = \<H>(X) - \<H>(X | Z)" |
|
809 |
proof - |
|
810 |
let "?XZ x z" = "real (joint_distribution X Z {(x, z)})" |
|
811 |
let "?Z z" = "real (distribution Z {z})" |
|
812 |
let "?X x" = "real (distribution X {x})" |
|
813 |
note fX = X[THEN simple_function_imp_finite_random_variable] |
|
814 |
note fZ = Z[THEN simple_function_imp_finite_random_variable] |
|
815 |
note fX[THEN finite_distribution_finite, simp] and fZ[THEN finite_distribution_finite, simp] |
|
816 |
note finite_distribution_order[OF fX fZ, simp] |
|
817 |
{ fix x z assume "x \<in> X`space M" "z \<in> Z`space M" |
|
818 |
have "?XZ x z * log b (?XZ x z / (?X x * ?Z z)) = |
|
819 |
?XZ x z * log b (?XZ x z / ?Z z) - ?XZ x z * log b (?X x)" |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
820 |
by (auto simp: log_simps real_of_pextreal_mult[symmetric] zero_less_mult_iff |
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
821 |
zero_less_real_of_pextreal field_simps real_of_pextreal_eq_0 abs_mult) } |
40859 | 822 |
note * = this |
823 |
show ?thesis |
|
824 |
unfolding entropy_eq[OF X] conditional_entropy_eq[OF X Z] mutual_information_eq[OF X Z] |
|
825 |
using setsum_real_joint_distribution_singleton[OF fZ fX, unfolded joint_distribution_commute_singleton[of Z X]] |
|
826 |
by (simp add: * setsum_cartesian_product' setsum_subtractf setsum_left_distrib[symmetric] |
|
827 |
setsum_real_distribution) |
|
828 |
qed |
|
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
829 |
|
40859 | 830 |
lemma (in information_space) conditional_entropy_less_eq_entropy: |
831 |
assumes X: "simple_function X" and Z: "simple_function Z" |
|
832 |
shows "\<H>(X | Z) \<le> \<H>(X)" |
|
36624 | 833 |
proof - |
40859 | 834 |
have "\<I>(X ; Z) = \<H>(X) - \<H>(X | Z)" using mutual_information_eq_entropy_conditional_entropy[OF assms] . |
835 |
with mutual_information_positive[OF X Z] entropy_positive[OF X] |
|
36624 | 836 |
show ?thesis by auto |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
837 |
qed |
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
838 |
|
40859 | 839 |
lemma (in information_space) entropy_chain_rule: |
840 |
assumes X: "simple_function X" and Y: "simple_function Y" |
|
841 |
shows "\<H>(\<lambda>x. (X x, Y x)) = \<H>(X) + \<H>(Y|X)" |
|
842 |
proof - |
|
843 |
let "?XY x y" = "real (joint_distribution X Y {(x, y)})" |
|
844 |
let "?Y y" = "real (distribution Y {y})" |
|
845 |
let "?X x" = "real (distribution X {x})" |
|
846 |
note fX = X[THEN simple_function_imp_finite_random_variable] |
|
847 |
note fY = Y[THEN simple_function_imp_finite_random_variable] |
|
848 |
note fX[THEN finite_distribution_finite, simp] and fY[THEN finite_distribution_finite, simp] |
|
849 |
note finite_distribution_order[OF fX fY, simp] |
|
850 |
{ fix x y assume "x \<in> X`space M" "y \<in> Y`space M" |
|
851 |
have "?XY x y * log b (?XY x y / ?X x) = |
|
852 |
?XY x y * log b (?XY x y) - ?XY x y * log b (?X x)" |
|
41023
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
853 |
by (auto simp: log_simps real_of_pextreal_mult[symmetric] zero_less_mult_iff |
9118eb4eb8dc
it is known as the extended reals, not the infinite reals
hoelzl
parents:
40859
diff
changeset
|
854 |
zero_less_real_of_pextreal field_simps real_of_pextreal_eq_0 abs_mult) } |
40859 | 855 |
note * = this |
856 |
show ?thesis |
|
857 |
using setsum_real_joint_distribution_singleton[OF fY fX] |
|
858 |
unfolding entropy_eq[OF X] conditional_entropy_eq_cartesian_product[OF Y X] entropy_eq_cartesian_product[OF X Y] |
|
859 |
unfolding joint_distribution_commute_singleton[of Y X] setsum_commute[of _ "X`space M"] |
|
860 |
by (simp add: * setsum_subtractf setsum_left_distrib[symmetric]) |
|
861 |
qed |
|
38656 | 862 |
|
39097 | 863 |
section {* Partitioning *} |
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
864 |
|
36624 | 865 |
definition "subvimage A f g \<longleftrightarrow> (\<forall>x \<in> A. f -` {f x} \<inter> A \<subseteq> g -` {g x} \<inter> A)" |
866 |
||
867 |
lemma subvimageI: |
|
868 |
assumes "\<And>x y. \<lbrakk> x \<in> A ; y \<in> A ; f x = f y \<rbrakk> \<Longrightarrow> g x = g y" |
|
869 |
shows "subvimage A f g" |
|
870 |
using assms unfolding subvimage_def by blast |
|
871 |
||
872 |
lemma subvimageE[consumes 1]: |
|
873 |
assumes "subvimage A f g" |
|
874 |
obtains "\<And>x y. \<lbrakk> x \<in> A ; y \<in> A ; f x = f y \<rbrakk> \<Longrightarrow> g x = g y" |
|
875 |
using assms unfolding subvimage_def by blast |
|
876 |
||
877 |
lemma subvimageD: |
|
878 |
"\<lbrakk> subvimage A f g ; x \<in> A ; y \<in> A ; f x = f y \<rbrakk> \<Longrightarrow> g x = g y" |
|
879 |
using assms unfolding subvimage_def by blast |
|
880 |
||
881 |
lemma subvimage_subset: |
|
882 |
"\<lbrakk> subvimage B f g ; A \<subseteq> B \<rbrakk> \<Longrightarrow> subvimage A f g" |
|
883 |
unfolding subvimage_def by auto |
|
884 |
||
885 |
lemma subvimage_idem[intro]: "subvimage A g g" |
|
886 |
by (safe intro!: subvimageI) |
|
887 |
||
888 |
lemma subvimage_comp_finer[intro]: |
|
889 |
assumes svi: "subvimage A g h" |
|
890 |
shows "subvimage A g (f \<circ> h)" |
|
891 |
proof (rule subvimageI, simp) |
|
892 |
fix x y assume "x \<in> A" "y \<in> A" "g x = g y" |
|
893 |
from svi[THEN subvimageD, OF this] |
|
894 |
show "f (h x) = f (h y)" by simp |
|
895 |
qed |
|
896 |
||
897 |
lemma subvimage_comp_gran: |
|
898 |
assumes svi: "subvimage A g h" |
|
899 |
assumes inj: "inj_on f (g ` A)" |
|
900 |
shows "subvimage A (f \<circ> g) h" |
|
901 |
by (rule subvimageI) (auto intro!: subvimageD[OF svi] simp: inj_on_iff[OF inj]) |
|
902 |
||
903 |
lemma subvimage_comp: |
|
904 |
assumes svi: "subvimage (f ` A) g h" |
|
905 |
shows "subvimage A (g \<circ> f) (h \<circ> f)" |
|
906 |
by (rule subvimageI) (auto intro!: svi[THEN subvimageD]) |
|
907 |
||
908 |
lemma subvimage_trans: |
|
909 |
assumes fg: "subvimage A f g" |
|
910 |
assumes gh: "subvimage A g h" |
|
911 |
shows "subvimage A f h" |
|
912 |
by (rule subvimageI) (auto intro!: fg[THEN subvimageD] gh[THEN subvimageD]) |
|
913 |
||
914 |
lemma subvimage_translator: |
|
915 |
assumes svi: "subvimage A f g" |
|
916 |
shows "\<exists>h. \<forall>x \<in> A. h (f x) = g x" |
|
917 |
proof (safe intro!: exI[of _ "\<lambda>x. (THE z. z \<in> (g ` (f -` {x} \<inter> A)))"]) |
|
918 |
fix x assume "x \<in> A" |
|
919 |
show "(THE x'. x' \<in> (g ` (f -` {f x} \<inter> A))) = g x" |
|
920 |
by (rule theI2[of _ "g x"]) |
|
921 |
(insert `x \<in> A`, auto intro!: svi[THEN subvimageD]) |
|
922 |
qed |
|
923 |
||
924 |
lemma subvimage_translator_image: |
|
925 |
assumes svi: "subvimage A f g" |
|
926 |
shows "\<exists>h. h ` f ` A = g ` A" |
|
927 |
proof - |
|
928 |
from subvimage_translator[OF svi] |
|
929 |
obtain h where "\<And>x. x \<in> A \<Longrightarrow> h (f x) = g x" by auto |
|
930 |
thus ?thesis |
|
931 |
by (auto intro!: exI[of _ h] |
|
932 |
simp: image_compose[symmetric] comp_def cong: image_cong) |
|
933 |
qed |
|
934 |
||
935 |
lemma subvimage_finite: |
|
936 |
assumes svi: "subvimage A f g" and fin: "finite (f`A)" |
|
937 |
shows "finite (g`A)" |
|
938 |
proof - |
|
939 |
from subvimage_translator_image[OF svi] |
|
940 |
obtain h where "g`A = h`f`A" by fastsimp |
|
941 |
with fin show "finite (g`A)" by simp |
|
942 |
qed |
|
943 |
||
944 |
lemma subvimage_disj: |
|
945 |
assumes svi: "subvimage A f g" |
|
946 |
shows "f -` {x} \<inter> A \<subseteq> g -` {y} \<inter> A \<or> |
|
947 |
f -` {x} \<inter> g -` {y} \<inter> A = {}" (is "?sub \<or> ?dist") |
|
948 |
proof (rule disjCI) |
|
949 |
assume "\<not> ?dist" |
|
950 |
then obtain z where "z \<in> A" and "x = f z" and "y = g z" by auto |
|
951 |
thus "?sub" using svi unfolding subvimage_def by auto |
|
952 |
qed |
|
953 |
||
954 |
lemma setsum_image_split: |
|
955 |
assumes svi: "subvimage A f g" and fin: "finite (f ` A)" |
|
956 |
shows "(\<Sum>x\<in>f`A. h x) = (\<Sum>y\<in>g`A. \<Sum>x\<in>f`(g -` {y} \<inter> A). h x)" |
|
957 |
(is "?lhs = ?rhs") |
|
958 |
proof - |
|
959 |
have "f ` A = |
|
960 |
snd ` (SIGMA x : g ` A. f ` (g -` {x} \<inter> A))" |
|
961 |
(is "_ = snd ` ?SIGMA") |
|
962 |
unfolding image_split_eq_Sigma[symmetric] |
|
963 |
by (simp add: image_compose[symmetric] comp_def) |
|
964 |
moreover |
|
965 |
have snd_inj: "inj_on snd ?SIGMA" |
|
966 |
unfolding image_split_eq_Sigma[symmetric] |
|
967 |
by (auto intro!: inj_onI subvimageD[OF svi]) |
|
968 |
ultimately |
|
969 |
have "(\<Sum>x\<in>f`A. h x) = (\<Sum>(x,y)\<in>?SIGMA. h y)" |
|
970 |
by (auto simp: setsum_reindex intro: setsum_cong) |
|
971 |
also have "... = ?rhs" |
|
972 |
using subvimage_finite[OF svi fin] fin |
|
973 |
apply (subst setsum_Sigma[symmetric]) |
|
974 |
by (auto intro!: finite_subset[of _ "f`A"]) |
|
975 |
finally show ?thesis . |
|
976 |
qed |
|
977 |
||
40859 | 978 |
lemma (in information_space) entropy_partition: |
979 |
assumes sf: "simple_function X" "simple_function P" |
|
36624 | 980 |
assumes svi: "subvimage (space M) X P" |
981 |
shows "\<H>(X) = \<H>(P) + \<H>(X|P)" |
|
982 |
proof - |
|
40859 | 983 |
let "?XP x p" = "real (joint_distribution X P {(x, p)})" |
984 |
let "?X x" = "real (distribution X {x})" |
|
985 |
let "?P p" = "real (distribution P {p})" |
|
986 |
note fX = sf(1)[THEN simple_function_imp_finite_random_variable] |
|
987 |
note fP = sf(2)[THEN simple_function_imp_finite_random_variable] |
|
988 |
note fX[THEN finite_distribution_finite, simp] and fP[THEN finite_distribution_finite, simp] |
|
989 |
note finite_distribution_order[OF fX fP, simp] |
|
38656 | 990 |
have "(\<Sum>x\<in>X ` space M. real (distribution X {x}) * log b (real (distribution X {x}))) = |
36624 | 991 |
(\<Sum>y\<in>P `space M. \<Sum>x\<in>X ` space M. |
38656 | 992 |
real (joint_distribution X P {(x, y)}) * log b (real (joint_distribution X P {(x, y)})))" |
36624 | 993 |
proof (subst setsum_image_split[OF svi], |
40859 | 994 |
safe intro!: setsum_mono_zero_cong_left imageI) |
995 |
show "finite (X ` space M)" "finite (X ` space M)" "finite (P ` space M)" |
|
996 |
using sf unfolding simple_function_def by auto |
|
997 |
next |
|
36624 | 998 |
fix p x assume in_space: "p \<in> space M" "x \<in> space M" |
38656 | 999 |
assume "real (joint_distribution X P {(X x, P p)}) * log b (real (joint_distribution X P {(X x, P p)})) \<noteq> 0" |
36624 | 1000 |
hence "(\<lambda>x. (X x, P x)) -` {(X x, P p)} \<inter> space M \<noteq> {}" by (auto simp: distribution_def) |
1001 |
with svi[unfolded subvimage_def, rule_format, OF `x \<in> space M`] |
|
1002 |
show "x \<in> P -` {P p}" by auto |
|
1003 |
next |
|
1004 |
fix p x assume in_space: "p \<in> space M" "x \<in> space M" |
|
1005 |
assume "P x = P p" |
|
1006 |
from this[symmetric] svi[unfolded subvimage_def, rule_format, OF `x \<in> space M`] |
|
1007 |
have "X -` {X x} \<inter> space M \<subseteq> P -` {P p} \<inter> space M" |
|
1008 |
by auto |
|
1009 |
hence "(\<lambda>x. (X x, P x)) -` {(X x, P p)} \<inter> space M = X -` {X x} \<inter> space M" |
|
1010 |
by auto |
|
38656 | 1011 |
thus "real (distribution X {X x}) * log b (real (distribution X {X x})) = |
1012 |
real (joint_distribution X P {(X x, P p)}) * |
|
1013 |
log b (real (joint_distribution X P {(X x, P p)}))" |
|
36624 | 1014 |
by (auto simp: distribution_def) |
1015 |
qed |
|
40859 | 1016 |
moreover have "\<And>x y. real (joint_distribution X P {(x, y)}) * |
1017 |
log b (real (joint_distribution X P {(x, y)}) / real (distribution P {y})) = |
|
1018 |
real (joint_distribution X P {(x, y)}) * log b (real (joint_distribution X P {(x, y)})) - |
|
1019 |
real (joint_distribution X P {(x, y)}) * log b (real (distribution P {y}))" |
|
1020 |
by (auto simp add: log_simps zero_less_mult_iff field_simps) |
|
1021 |
ultimately show ?thesis |
|
1022 |
unfolding sf[THEN entropy_eq] conditional_entropy_eq[OF sf] |
|
1023 |
using setsum_real_joint_distribution_singleton[OF fX fP] |
|
38656 | 1024 |
by (simp add: setsum_cartesian_product' setsum_subtractf setsum_real_distribution |
36624 | 1025 |
setsum_left_distrib[symmetric] setsum_commute[where B="P`space M"]) |
1026 |
qed |
|
1027 |
||
40859 | 1028 |
corollary (in information_space) entropy_data_processing: |
1029 |
assumes X: "simple_function X" shows "\<H>(f \<circ> X) \<le> \<H>(X)" |
|
1030 |
proof - |
|
1031 |
note X |
|
1032 |
moreover have fX: "simple_function (f \<circ> X)" using X by auto |
|
1033 |
moreover have "subvimage (space M) X (f \<circ> X)" by auto |
|
1034 |
ultimately have "\<H>(X) = \<H>(f\<circ>X) + \<H>(X|f\<circ>X)" by (rule entropy_partition) |
|
1035 |
then show "\<H>(f \<circ> X) \<le> \<H>(X)" |
|
1036 |
by (auto intro: conditional_entropy_positive[OF X fX]) |
|
1037 |
qed |
|
36624 | 1038 |
|
40859 | 1039 |
corollary (in information_space) entropy_of_inj: |
1040 |
assumes X: "simple_function X" and inj: "inj_on f (X`space M)" |
|
36624 | 1041 |
shows "\<H>(f \<circ> X) = \<H>(X)" |
1042 |
proof (rule antisym) |
|
40859 | 1043 |
show "\<H>(f \<circ> X) \<le> \<H>(X)" using entropy_data_processing[OF X] . |
36624 | 1044 |
next |
40859 | 1045 |
have sf: "simple_function (f \<circ> X)" |
1046 |
using X by auto |
|
36624 | 1047 |
have "\<H>(X) = \<H>(the_inv_into (X`space M) f \<circ> (f \<circ> X))" |
40859 | 1048 |
by (auto intro!: mutual_information_cong simp: entropy_def the_inv_into_f_f[OF inj]) |
36624 | 1049 |
also have "... \<le> \<H>(f \<circ> X)" |
40859 | 1050 |
using entropy_data_processing[OF sf] . |
36624 | 1051 |
finally show "\<H>(X) \<le> \<H>(f \<circ> X)" . |
1052 |
qed |
|
1053 |
||
36080
0d9affa4e73c
Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff
changeset
|
1054 |
end |