author | hoelzl |
Mon, 14 Mar 2011 14:37:49 +0100 | |
changeset 41981 | cdf7693bbe08 |
parent 41689 | 3e39b0e730d6 |
child 42256 | 461624ffd382 |
permissions | -rw-r--r-- |
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
1 |
(* Author: Johannes Hölzl, TU München *) |
40859 | 2 |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
3 |
header {* Formalization of a Countermeasure by Koepf \& Duermuth 2009 *} |
40859 | 4 |
|
5 |
theory Koepf_Duermuth_Countermeasure |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
6 |
imports "~~/src/HOL/Probability/Information" "~~/src/HOL/Library/Permutation" |
40859 | 7 |
begin |
8 |
||
9 |
lemma |
|
10 |
fixes p u :: "'a \<Rightarrow> real" |
|
11 |
assumes "1 < b" |
|
12 |
assumes sum: "(\<Sum>i\<in>S. p i) = (\<Sum>i\<in>S. u i)" |
|
13 |
and pos: "\<And>i. i \<in> S \<Longrightarrow> 0 \<le> p i" "\<And>i. i \<in> S \<Longrightarrow> 0 \<le> u i" |
|
14 |
and cont: "\<And>i. i \<in> S \<Longrightarrow> 0 < p i \<Longrightarrow> 0 < u i" |
|
15 |
shows "(\<Sum>i\<in>S. p i * log b (u i)) \<le> (\<Sum>i\<in>S. p i * log b (p i))" |
|
16 |
proof - |
|
17 |
have "(\<Sum>i\<in>S. p i * ln (u i) - p i * ln (p i)) \<le> (\<Sum>i\<in>S. u i - p i)" |
|
18 |
proof (intro setsum_mono) |
|
19 |
fix i assume [intro, simp]: "i \<in> S" |
|
20 |
show "p i * ln (u i) - p i * ln (p i) \<le> u i - p i" |
|
21 |
proof cases |
|
22 |
assume "p i = 0" with pos[of i] show ?thesis by simp |
|
23 |
next |
|
24 |
assume "p i \<noteq> 0" |
|
25 |
then have "0 < p i" "0 < u i" using pos[of i] cont[of i] by auto |
|
26 |
then have *: "0 < u i / p i" by (blast intro: divide_pos_pos cont) |
|
27 |
from `0 < p i` `0 < u i` |
|
28 |
have "p i * ln (u i) - p i * ln (p i) = p i * ln (u i / p i)" |
|
29 |
by (simp add: ln_div field_simps) |
|
30 |
also have "\<dots> \<le> p i * (u i / p i - 1)" |
|
31 |
using exp_ge_add_one_self[of "ln (u i / p i)"] pos[of i] exp_ln[OF *] |
|
32 |
by (auto intro!: mult_left_mono) |
|
33 |
also have "\<dots> = u i - p i" |
|
34 |
using `p i \<noteq> 0` by (simp add: field_simps) |
|
35 |
finally show ?thesis by simp |
|
36 |
qed |
|
37 |
qed |
|
38 |
also have "\<dots> = 0" using sum by (simp add: setsum_subtractf) |
|
39 |
finally show ?thesis using `1 < b` unfolding log_def setsum_subtractf |
|
40 |
by (auto intro!: divide_right_mono |
|
41 |
simp: times_divide_eq_right setsum_divide_distrib[symmetric]) |
|
42 |
qed |
|
43 |
||
44 |
definition (in prob_space) |
|
45 |
"ordered_variable_partition X = (SOME f. bij_betw f {0..<card (X`space M)} (X`space M) \<and> |
|
46 |
(\<forall>i<card (X`space M). \<forall>j<card (X`space M). i \<le> j \<longrightarrow> distribution X {f i} \<le> distribution X {f j}))" |
|
47 |
||
48 |
lemma ex_ordered_bij_betw_nat_finite: |
|
49 |
fixes order :: "nat \<Rightarrow> 'a\<Colon>linorder" |
|
50 |
assumes "finite S" |
|
51 |
shows "\<exists>f. bij_betw f {0..<card S} S \<and> (\<forall>i<card S. \<forall>j<card S. i \<le> j \<longrightarrow> order (f i) \<le> order (f j))" |
|
52 |
proof - |
|
53 |
from ex_bij_betw_nat_finite [OF `finite S`] guess f .. note f = this |
|
54 |
let ?xs = "sort_key order (map f [0 ..< card S])" |
|
55 |
||
56 |
have "?xs <~~> map f [0 ..< card S]" |
|
57 |
unfolding multiset_of_eq_perm[symmetric] by (rule multiset_of_sort) |
|
58 |
from permutation_Ex_bij [OF this] |
|
59 |
obtain g where g: "bij_betw g {0..<card S} {0..<card S}" and |
|
60 |
map: "\<And>i. i<card S \<Longrightarrow> ?xs ! i = map f [0 ..< card S] ! g i" |
|
61 |
by (auto simp: atLeast0LessThan) |
|
62 |
||
63 |
{ fix i assume "i < card S" |
|
64 |
then have "g i < card S" using g by (auto simp: bij_betw_def) |
|
65 |
with map [OF `i < card S`] have "f (g i) = ?xs ! i" by simp } |
|
66 |
note this[simp] |
|
67 |
||
68 |
show ?thesis |
|
69 |
proof (intro exI allI conjI impI) |
|
70 |
show "bij_betw (f\<circ>g) {0..<card S} S" |
|
71 |
using g f by (rule bij_betw_trans) |
|
72 |
fix i j assume [simp]: "i < card S" "j < card S" "i \<le> j" |
|
73 |
from sorted_nth_mono[of "map order ?xs" i j] |
|
74 |
show "order ((f\<circ>g) i) \<le> order ((f\<circ>g) j)" by simp |
|
75 |
qed |
|
76 |
qed |
|
77 |
||
78 |
lemma (in prob_space) |
|
79 |
assumes "finite (X`space M)" |
|
80 |
shows "bij_betw (ordered_variable_partition X) {0..<card (X`space M)} (X`space M)" |
|
81 |
and "\<And>i j. \<lbrakk> i < card (X`space M) ; j < card (X`space M) ; i \<le> j \<rbrakk> \<Longrightarrow> |
|
82 |
distribution X {ordered_variable_partition X i} \<le> distribution X {ordered_variable_partition X j}" |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
83 |
oops |
40859 | 84 |
|
85 |
definition (in prob_space) |
|
86 |
"order_distribution X i = real (distribution X {ordered_variable_partition X i})" |
|
87 |
||
88 |
definition (in prob_space) |
|
89 |
"guessing_entropy b X = (\<Sum>i<card(X`space M). real i * log b (order_distribution X i))" |
|
90 |
||
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
91 |
abbreviation (in information_space) |
40859 | 92 |
finite_guessing_entropy ("\<G>'(_')") where |
93 |
"\<G>(X) \<equiv> guessing_entropy b X" |
|
94 |
||
95 |
lemma zero_notin_Suc_image[simp]: "0 \<notin> Suc ` A" |
|
96 |
by auto |
|
97 |
||
98 |
definition extensional :: "'b \<Rightarrow> 'a set \<Rightarrow> ('a \<Rightarrow> 'b) set" where |
|
99 |
"extensional d A = {f. \<forall>x. x \<notin> A \<longrightarrow> f x = d}" |
|
100 |
||
101 |
lemma extensional_empty[simp]: "extensional d {} = {\<lambda>x. d}" |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
102 |
unfolding extensional_def by (simp add: set_eq_iff fun_eq_iff) |
40859 | 103 |
|
104 |
lemma funset_eq_UN_fun_upd_I: |
|
105 |
assumes *: "\<And>f. f \<in> F (insert a A) \<Longrightarrow> f(a := d) \<in> F A" |
|
106 |
and **: "\<And>f. f \<in> F (insert a A) \<Longrightarrow> f a \<in> G (f(a:=d))" |
|
107 |
and ***: "\<And>f x. \<lbrakk> f \<in> F A ; x \<in> G f \<rbrakk> \<Longrightarrow> f(a:=x) \<in> F (insert a A)" |
|
108 |
shows "F (insert a A) = (\<Union>f\<in>F A. fun_upd f a ` (G f))" |
|
109 |
proof safe |
|
110 |
fix f assume f: "f \<in> F (insert a A)" |
|
111 |
show "f \<in> (\<Union>f\<in>F A. fun_upd f a ` G f)" |
|
112 |
proof (rule UN_I[of "f(a := d)"]) |
|
113 |
show "f(a := d) \<in> F A" using *[OF f] . |
|
114 |
show "f \<in> fun_upd (f(a:=d)) a ` G (f(a:=d))" |
|
115 |
proof (rule image_eqI[of _ _ "f a"]) |
|
116 |
show "f a \<in> G (f(a := d))" using **[OF f] . |
|
117 |
qed simp |
|
118 |
qed |
|
119 |
next |
|
120 |
fix f x assume "f \<in> F A" "x \<in> G f" |
|
121 |
from ***[OF this] show "f(a := x) \<in> F (insert a A)" . |
|
122 |
qed |
|
123 |
||
124 |
lemma extensional_insert[simp]: |
|
125 |
assumes "a \<notin> A" |
|
126 |
shows "extensional d (insert a A) \<inter> (insert a A \<rightarrow> B) = (\<Union>f \<in> extensional d A \<inter> (A \<rightarrow> B). (\<lambda>b. f(a := b)) ` B)" |
|
127 |
apply (rule funset_eq_UN_fun_upd_I) |
|
128 |
using assms |
|
129 |
by (auto intro!: inj_onI dest: inj_onD split: split_if_asm simp: extensional_def) |
|
130 |
||
131 |
lemma finite_extensional_funcset[simp, intro]: |
|
132 |
assumes "finite A" "finite B" |
|
133 |
shows "finite (extensional d A \<inter> (A \<rightarrow> B))" |
|
134 |
using assms by induct auto |
|
135 |
||
136 |
lemma fun_upd_eq_iff: "f(a := b) = g(a := b') \<longleftrightarrow> b = b' \<and> f(a := d) = g(a := d)" |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
137 |
by (auto simp: fun_eq_iff) |
40859 | 138 |
|
139 |
lemma card_funcset: |
|
140 |
assumes "finite A" "finite B" |
|
141 |
shows "card (extensional d A \<inter> (A \<rightarrow> B)) = card B ^ card A" |
|
142 |
using `finite A` proof induct |
|
143 |
case (insert a A) thus ?case unfolding extensional_insert[OF `a \<notin> A`] |
|
144 |
proof (subst card_UN_disjoint, safe, simp_all) |
|
145 |
show "finite (extensional d A \<inter> (A \<rightarrow> B))" "\<And>f. finite (fun_upd f a ` B)" |
|
146 |
using `finite B` `finite A` by simp_all |
|
147 |
next |
|
148 |
fix f g b b' assume "f \<noteq> g" and eq: "f(a := b) = g(a := b')" and |
|
149 |
ext: "f \<in> extensional d A" "g \<in> extensional d A" |
|
150 |
have "f a = d" "g a = d" |
|
151 |
using ext `a \<notin> A` by (auto simp add: extensional_def) |
|
152 |
with `f \<noteq> g` eq show False unfolding fun_upd_eq_iff[of _ _ b _ _ d] |
|
153 |
by (auto simp: fun_upd_idem fun_upd_eq_iff) |
|
154 |
next |
|
155 |
{ fix f assume "f \<in> extensional d A \<inter> (A \<rightarrow> B)" |
|
156 |
have "card (fun_upd f a ` B) = card B" |
|
157 |
proof (auto intro!: card_image inj_onI) |
|
158 |
fix b b' assume "f(a := b) = f(a := b')" |
|
159 |
from fun_upd_eq_iff[THEN iffD1, OF this] show "b = b'" by simp |
|
160 |
qed } |
|
161 |
then show "(\<Sum>i\<in>extensional d A \<inter> (A \<rightarrow> B). card (fun_upd i a ` B)) = card B * card B ^ card A" |
|
162 |
using insert by simp |
|
163 |
qed |
|
164 |
qed simp |
|
165 |
||
166 |
lemma set_of_list_extend: |
|
167 |
"{xs. length xs = Suc n \<and> (\<forall>x\<in>set xs. x \<in> A)} = |
|
168 |
(\<lambda>(xs, n). n#xs) ` ({xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)} \<times> A)" |
|
169 |
by (auto simp: length_Suc_conv) |
|
170 |
||
171 |
lemma |
|
172 |
assumes "finite A" |
|
173 |
shows finite_lists: |
|
174 |
"finite {xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)}" (is "finite (?lists n)") |
|
175 |
and card_list_length: |
|
176 |
"card {xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)} = (card A)^n" |
|
177 |
proof - |
|
178 |
from `finite A` |
|
179 |
have "(card {xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)} = (card A)^n) \<and> |
|
180 |
finite {xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)}" |
|
181 |
proof (induct n) |
|
182 |
case (Suc n) |
|
183 |
moreover note set_of_list_extend[of n A] |
|
184 |
moreover have "inj_on (\<lambda>(xs, n). n#xs) (?lists n \<times> A)" |
|
185 |
by (auto intro!: inj_onI) |
|
186 |
ultimately show ?case using assms by (auto simp: card_image) |
|
187 |
qed (simp cong: conj_cong) |
|
188 |
then show "finite (?lists n)" "card (?lists n) = card A ^ n" |
|
189 |
by auto |
|
190 |
qed |
|
191 |
||
192 |
locale finite_information = |
|
193 |
fixes \<Omega> :: "'a set" |
|
194 |
and p :: "'a \<Rightarrow> real" |
|
195 |
and b :: real |
|
196 |
assumes finite_space[simp, intro]: "finite \<Omega>" |
|
197 |
and p_sums_1[simp]: "(\<Sum>\<omega>\<in>\<Omega>. p \<omega>) = 1" |
|
198 |
and positive_p[simp, intro]: "\<And>x. 0 \<le> p x" |
|
199 |
and b_gt_1[simp, intro]: "1 < b" |
|
200 |
||
201 |
lemma (in finite_information) positive_p_sum[simp]: "0 \<le> setsum p X" |
|
202 |
by (auto intro!: setsum_nonneg) |
|
203 |
||
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
204 |
sublocale finite_information \<subseteq> finite_measure_space "\<lparr> space = \<Omega>, sets = Pow \<Omega>, measure = \<lambda>S. extreal (setsum p S)\<rparr>" |
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
205 |
by (rule finite_measure_spaceI) (simp_all add: setsum_Un_disjoint finite_subset) |
40859 | 206 |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
207 |
sublocale finite_information \<subseteq> finite_prob_space "\<lparr> space = \<Omega>, sets = Pow \<Omega>, measure = \<lambda>S. extreal (setsum p S)\<rparr>" |
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
208 |
by default (simp add: one_extreal_def) |
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
209 |
|
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
210 |
sublocale finite_information \<subseteq> information_space "\<lparr> space = \<Omega>, sets = Pow \<Omega>, measure = \<lambda>S. extreal (setsum p S)\<rparr>" b |
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
211 |
by default simp |
40859 | 212 |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
213 |
lemma (in finite_information) \<mu>'_eq: "A \<subseteq> \<Omega> \<Longrightarrow> \<mu>' A = setsum p A" |
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
214 |
unfolding \<mu>'_def by auto |
40859 | 215 |
|
216 |
locale koepf_duermuth = K: finite_information keys K b + M: finite_information messages M b |
|
217 |
for b :: real |
|
218 |
and keys :: "'key set" and K :: "'key \<Rightarrow> real" |
|
219 |
and messages :: "'message set" and M :: "'message \<Rightarrow> real" + |
|
220 |
fixes observe :: "'key \<Rightarrow> 'message \<Rightarrow> 'observation" |
|
221 |
and n :: nat |
|
222 |
begin |
|
223 |
||
224 |
definition msgs :: "('key \<times> 'message list) set" where |
|
225 |
"msgs = keys \<times> {ms. length ms = n \<and> (\<forall>M\<in>set ms. M \<in> messages)}" |
|
226 |
||
227 |
definition P :: "('key \<times> 'message list) \<Rightarrow> real" where |
|
228 |
"P = (\<lambda>(k, ms). K k * (\<Prod>i<length ms. M (ms ! i)))" |
|
229 |
||
230 |
end |
|
231 |
||
232 |
sublocale koepf_duermuth \<subseteq> finite_information msgs P b |
|
233 |
proof default |
|
234 |
show "finite msgs" unfolding msgs_def |
|
235 |
using finite_lists[OF M.finite_space, of n] |
|
236 |
by auto |
|
237 |
||
238 |
have [simp]: "\<And>A. inj_on (\<lambda>(xs, n). n # xs) A" by (force intro!: inj_onI) |
|
239 |
||
240 |
note setsum_right_distrib[symmetric, simp] |
|
241 |
note setsum_left_distrib[symmetric, simp] |
|
242 |
note setsum_cartesian_product'[simp] |
|
243 |
||
244 |
have "(\<Sum>ms | length ms = n \<and> (\<forall>M\<in>set ms. M \<in> messages). \<Prod>x<length ms. M (ms ! x)) = 1" |
|
245 |
proof (induct n) |
|
246 |
case 0 then show ?case by (simp cong: conj_cong) |
|
247 |
next |
|
248 |
case (Suc n) |
|
249 |
then show ?case |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
250 |
by (simp add: comp_def set_of_list_extend lessThan_Suc_eq_insert_0 |
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
251 |
setsum_reindex setprod_reindex) |
40859 | 252 |
qed |
253 |
then show "setsum P msgs = 1" |
|
254 |
unfolding msgs_def P_def by simp |
|
255 |
fix x |
|
256 |
have "\<And> A f. 0 \<le> (\<Prod>x\<in>A. M (f x))" by (auto simp: setprod_nonneg) |
|
257 |
then show "0 \<le> P x" |
|
258 |
unfolding P_def by (auto split: prod.split simp: zero_le_mult_iff) |
|
259 |
qed auto |
|
260 |
||
261 |
lemma SIGMA_image_vimage: |
|
262 |
"snd ` (SIGMA x:f`X. f -` {x} \<inter> X) = X" |
|
263 |
by (auto simp: image_iff) |
|
264 |
||
265 |
lemma inj_Cons[simp]: "\<And>X. inj_on (\<lambda>(xs, x). x#xs) X" by (auto intro!: inj_onI) |
|
266 |
||
267 |
lemma setprod_setsum_distrib_lists: |
|
268 |
fixes P and S :: "'a set" and f :: "'a \<Rightarrow> _::semiring_0" assumes "finite S" |
|
269 |
shows "(\<Sum>ms\<in>{ms. length ms = n \<and> set ms \<subseteq> S \<and> (\<forall>i<n. P i (ms!i))}. \<Prod>x<n. f (ms ! x)) = |
|
270 |
(\<Prod>i<n. \<Sum>m\<in>{m\<in>S. P i m}. f m)" |
|
271 |
proof (induct n arbitrary: P) |
|
272 |
case 0 then show ?case by (simp cong: conj_cong) |
|
273 |
next |
|
274 |
case (Suc n) |
|
275 |
have *: "{ms. length ms = Suc n \<and> set ms \<subseteq> S \<and> (\<forall>i<Suc n. P i (ms ! i))} = |
|
276 |
(\<lambda>(xs, x). x#xs) ` ({ms. length ms = n \<and> set ms \<subseteq> S \<and> (\<forall>i<n. P (Suc i) (ms ! i))} \<times> {m\<in>S. P 0 m})" |
|
277 |
apply (auto simp: image_iff length_Suc_conv) |
|
278 |
apply force+ |
|
279 |
apply (case_tac i) |
|
280 |
by force+ |
|
281 |
show ?case unfolding * |
|
282 |
using Suc[of "\<lambda>i. P (Suc i)"] |
|
283 |
by (simp add: setsum_reindex split_conv setsum_cartesian_product' |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
284 |
lessThan_Suc_eq_insert_0 setprod_reindex setsum_left_distrib[symmetric] setsum_right_distrib[symmetric]) |
40859 | 285 |
qed |
286 |
||
287 |
context koepf_duermuth |
|
288 |
begin |
|
289 |
||
290 |
definition observations :: "'observation set" where |
|
291 |
"observations = (\<Union>f\<in>observe ` keys. f ` messages)" |
|
292 |
||
293 |
lemma finite_observations[simp, intro]: "finite observations" |
|
294 |
unfolding observations_def by auto |
|
295 |
||
296 |
definition OB :: "'key \<times> 'message list \<Rightarrow> 'observation list" where |
|
297 |
"OB = (\<lambda>(k, ms). map (observe k) ms)" |
|
298 |
||
299 |
definition t :: "'observation list \<Rightarrow> 'observation \<Rightarrow> nat" where |
|
300 |
"t seq obs = length (filter (op = obs) seq)" |
|
301 |
||
302 |
lemma card_T_bound: "card ((t\<circ>OB)`msgs) \<le> (n+1)^card observations" |
|
303 |
proof - |
|
304 |
have "(t\<circ>OB)`msgs \<subseteq> extensional 0 observations \<inter> (observations \<rightarrow> {.. n})" |
|
305 |
unfolding observations_def extensional_def OB_def msgs_def |
|
306 |
by (auto simp add: t_def comp_def image_iff) |
|
307 |
with finite_extensional_funcset |
|
308 |
have "card ((t\<circ>OB)`msgs) \<le> card (extensional 0 observations \<inter> (observations \<rightarrow> {.. n}))" |
|
309 |
by (rule card_mono) auto |
|
310 |
also have "\<dots> = (n + 1) ^ card observations" |
|
311 |
by (subst card_funcset) auto |
|
312 |
finally show ?thesis . |
|
313 |
qed |
|
314 |
||
315 |
abbreviation |
|
316 |
"p A \<equiv> setsum P A" |
|
317 |
||
318 |
abbreviation probability ("\<P>'(_') _") where |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
319 |
"\<P>(X) x \<equiv> distribution X x" |
40859 | 320 |
|
321 |
abbreviation joint_probability ("\<P>'(_, _') _") where |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
322 |
"\<P>(X, Y) x \<equiv> joint_distribution X Y x" |
40859 | 323 |
|
324 |
abbreviation conditional_probability ("\<P>'(_|_') _") where |
|
325 |
"\<P>(X|Y) x \<equiv> \<P>(X, Y) x / \<P>(Y) (snd`x)" |
|
326 |
||
327 |
notation |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
328 |
entropy_Pow ("\<H>'( _ ')") |
40859 | 329 |
|
330 |
notation |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
331 |
conditional_entropy_Pow ("\<H>'( _ | _ ')") |
40859 | 332 |
|
333 |
notation |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
334 |
mutual_information_Pow ("\<I>'( _ ; _ ')") |
40859 | 335 |
|
336 |
lemma t_eq_imp_bij_func: |
|
337 |
assumes "t xs = t ys" |
|
338 |
shows "\<exists>f. bij_betw f {..<length xs} {..<length ys} \<and> (\<forall>i<length xs. xs ! i = ys ! (f i))" |
|
339 |
proof - |
|
340 |
have "count (multiset_of xs) = count (multiset_of ys)" |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
341 |
using assms by (simp add: fun_eq_iff count_multiset_of t_def) |
40859 | 342 |
then have "xs <~~> ys" unfolding multiset_of_eq_perm count_inject . |
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
343 |
then show ?thesis by (rule permutation_Ex_bij) |
40859 | 344 |
qed |
345 |
||
346 |
lemma \<P>_k: assumes "k \<in> keys" shows "\<P>(fst) {k} = K k" |
|
347 |
proof - |
|
348 |
from assms have *: |
|
349 |
"fst -` {k} \<inter> msgs = {k}\<times>{ms. length ms = n \<and> (\<forall>M\<in>set ms. M \<in> messages)}" |
|
350 |
unfolding msgs_def by auto |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
351 |
show "\<P>(fst) {k} = K k" |
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
352 |
apply (simp add: \<mu>'_eq distribution_def) |
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
353 |
apply (simp add: * P_def) |
40859 | 354 |
apply (simp add: setsum_cartesian_product') |
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
355 |
using setprod_setsum_distrib_lists[OF M.finite_space, of M n "\<lambda>x x. True"] `k \<in> keys` |
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
356 |
by (auto simp add: setsum_right_distrib[symmetric] subset_eq setprod_1) |
40859 | 357 |
qed |
358 |
||
359 |
lemma fst_image_msgs[simp]: "fst`msgs = keys" |
|
360 |
proof - |
|
361 |
from M.not_empty obtain m where "m \<in> messages" by auto |
|
362 |
then have *: "{m. length m = n \<and> (\<forall>x\<in>set m. x\<in>messages)} \<noteq> {}" |
|
363 |
by (auto intro!: exI[of _ "replicate n m"]) |
|
364 |
then show ?thesis |
|
365 |
unfolding msgs_def fst_image_times if_not_P[OF *] by simp |
|
366 |
qed |
|
367 |
||
368 |
lemma ce_OB_eq_ce_t: "\<H>(fst | OB) = \<H>(fst | t\<circ>OB)" |
|
369 |
proof - |
|
370 |
txt {* Lemma 2 *} |
|
371 |
||
372 |
{ fix k obs obs' |
|
373 |
assume "k \<in> keys" "K k \<noteq> 0" and obs': "obs' \<in> OB ` msgs" and obs: "obs \<in> OB ` msgs" |
|
374 |
assume "t obs = t obs'" |
|
375 |
from t_eq_imp_bij_func[OF this] |
|
376 |
obtain t_f where "bij_betw t_f {..<n} {..<n}" and |
|
377 |
obs_t_f: "\<And>i. i<n \<Longrightarrow> obs!i = obs' ! t_f i" |
|
378 |
using obs obs' unfolding OB_def msgs_def by auto |
|
379 |
then have t_f: "inj_on t_f {..<n}" "{..<n} = t_f`{..<n}" unfolding bij_betw_def by auto |
|
380 |
||
381 |
{ fix obs assume "obs \<in> OB`msgs" |
|
382 |
then have **: "\<And>ms. length ms = n \<Longrightarrow> OB (k, ms) = obs \<longleftrightarrow> (\<forall>i<n. observe k (ms!i) = obs ! i)" |
|
383 |
unfolding OB_def msgs_def by (simp add: image_iff list_eq_iff_nth_eq) |
|
384 |
||
385 |
have "\<P>(OB, fst) {(obs, k)} / K k = |
|
386 |
p ({k}\<times>{ms. (k,ms) \<in> msgs \<and> OB (k,ms) = obs}) / K k" |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
387 |
apply (simp add: distribution_def \<mu>'_eq) by (auto intro!: arg_cong[where f=p]) |
40859 | 388 |
also have "\<dots> = |
389 |
(\<Prod>i<n. \<Sum>m\<in>{m\<in>messages. observe k m = obs ! i}. M m)" |
|
390 |
unfolding P_def using `K k \<noteq> 0` `k \<in> keys` |
|
391 |
apply (simp add: setsum_cartesian_product' setsum_divide_distrib msgs_def ** cong: conj_cong) |
|
392 |
apply (subst setprod_setsum_distrib_lists[OF M.finite_space, unfolded subset_eq]) .. |
|
393 |
finally have "\<P>(OB, fst) {(obs, k)} / K k = |
|
394 |
(\<Prod>i<n. \<Sum>m\<in>{m\<in>messages. observe k m = obs ! i}. M m)" . } |
|
395 |
note * = this |
|
396 |
||
397 |
have "\<P>(OB, fst) {(obs, k)} / K k = \<P>(OB, fst) {(obs', k)} / K k" |
|
398 |
unfolding *[OF obs] *[OF obs'] |
|
399 |
using t_f(1) obs_t_f by (subst (2) t_f(2)) (simp add: setprod_reindex) |
|
400 |
then have "\<P>(OB, fst) {(obs, k)} = \<P>(OB, fst) {(obs', k)}" |
|
401 |
using `K k \<noteq> 0` by auto } |
|
402 |
note t_eq_imp = this |
|
403 |
||
404 |
let "?S obs" = "t -`{t obs} \<inter> OB`msgs" |
|
405 |
{ fix k obs assume "k \<in> keys" "K k \<noteq> 0" and obs: "obs \<in> OB`msgs" |
|
406 |
have *: "((\<lambda>x. (t (OB x), fst x)) -` {(t obs, k)} \<inter> msgs) = |
|
407 |
(\<Union>obs'\<in>?S obs. ((\<lambda>x. (OB x, fst x)) -` {(obs', k)} \<inter> msgs))" by auto |
|
408 |
have df: "disjoint_family_on (\<lambda>obs'. (\<lambda>x. (OB x, fst x)) -` {(obs', k)} \<inter> msgs) (?S obs)" |
|
409 |
unfolding disjoint_family_on_def by auto |
|
410 |
have "\<P>(t\<circ>OB, fst) {(t obs, k)} = (\<Sum>obs'\<in>?S obs. \<P>(OB, fst) {(obs', k)})" |
|
411 |
unfolding distribution_def comp_def |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
412 |
using finite_measure_finite_Union[OF _ _ df] |
40859 | 413 |
by (force simp add: * intro!: setsum_nonneg) |
414 |
also have "(\<Sum>obs'\<in>?S obs. \<P>(OB, fst) {(obs', k)}) = real (card (?S obs)) * \<P>(OB, fst) {(obs, k)}" |
|
415 |
by (simp add: t_eq_imp[OF `k \<in> keys` `K k \<noteq> 0` obs] real_eq_of_nat) |
|
416 |
finally have "\<P>(t\<circ>OB, fst) {(t obs, k)} = real (card (?S obs)) * \<P>(OB, fst) {(obs, k)}" .} |
|
417 |
note P_t_eq_P_OB = this |
|
418 |
||
419 |
{ fix k obs assume "k \<in> keys" and obs: "obs \<in> OB`msgs" |
|
420 |
have "\<P>(t\<circ>OB | fst) {(t obs, k)} = |
|
421 |
real (card (t -` {t obs} \<inter> OB ` msgs)) * \<P>(OB | fst) {(obs, k)}" |
|
422 |
using \<P>_k[OF `k \<in> keys`] P_t_eq_P_OB[OF `k \<in> keys` _ obs] by auto } |
|
423 |
note CP_t_K = this |
|
424 |
||
425 |
{ fix k obs assume "k \<in> keys" and obs: "obs \<in> OB`msgs" |
|
426 |
then have "t -`{t obs} \<inter> OB`msgs \<noteq> {}" (is "?S \<noteq> {}") by auto |
|
427 |
then have "real (card ?S) \<noteq> 0" by auto |
|
428 |
||
429 |
have "\<P>(fst | t\<circ>OB) {(k, t obs)} = \<P>(t\<circ>OB | fst) {(t obs, k)} * \<P>(fst) {k} / \<P>(t\<circ>OB) {t obs}" |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
430 |
using distribution_order(7,8)[where X=fst and x=k and Y="t\<circ>OB" and y="t obs"] |
40859 | 431 |
by (subst joint_distribution_commute) auto |
432 |
also have "\<P>(t\<circ>OB) {t obs} = (\<Sum>k'\<in>keys. \<P>(t\<circ>OB|fst) {(t obs, k')} * \<P>(fst) {k'})" |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
433 |
using setsum_distribution(2)[of "t\<circ>OB" fst "t obs", symmetric] |
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
434 |
by (auto intro!: setsum_cong distribution_order(8)) |
40859 | 435 |
also have "\<P>(t\<circ>OB | fst) {(t obs, k)} * \<P>(fst) {k} / (\<Sum>k'\<in>keys. \<P>(t\<circ>OB|fst) {(t obs, k')} * \<P>(fst) {k'}) = |
436 |
\<P>(OB | fst) {(obs, k)} * \<P>(fst) {k} / (\<Sum>k'\<in>keys. \<P>(OB|fst) {(obs, k')} * \<P>(fst) {k'})" |
|
437 |
using CP_t_K[OF `k\<in>keys` obs] CP_t_K[OF _ obs] `real (card ?S) \<noteq> 0` |
|
438 |
by (simp only: setsum_right_distrib[symmetric] ac_simps |
|
439 |
mult_divide_mult_cancel_left[OF `real (card ?S) \<noteq> 0`] |
|
440 |
cong: setsum_cong) |
|
441 |
also have "(\<Sum>k'\<in>keys. \<P>(OB|fst) {(obs, k')} * \<P>(fst) {k'}) = \<P>(OB) {obs}" |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
442 |
using setsum_distribution(2)[of OB fst obs, symmetric] |
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
443 |
by (auto intro!: setsum_cong distribution_order(8)) |
40859 | 444 |
also have "\<P>(OB | fst) {(obs, k)} * \<P>(fst) {k} / \<P>(OB) {obs} = \<P>(fst | OB) {(k, obs)}" |
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
445 |
by (subst joint_distribution_commute) (auto intro!: distribution_order(8)) |
40859 | 446 |
finally have "\<P>(fst | t\<circ>OB) {(k, t obs)} = \<P>(fst | OB) {(k, obs)}" . } |
447 |
note CP_T_eq_CP_O = this |
|
448 |
||
449 |
let "?H obs" = "(\<Sum>k\<in>keys. \<P>(fst|OB) {(k, obs)} * log b (\<P>(fst|OB) {(k, obs)})) :: real" |
|
450 |
let "?Ht obs" = "(\<Sum>k\<in>keys. \<P>(fst|t\<circ>OB) {(k, obs)} * log b (\<P>(fst|t\<circ>OB) {(k, obs)})) :: real" |
|
451 |
||
452 |
{ fix obs assume obs: "obs \<in> OB`msgs" |
|
453 |
have "?H obs = (\<Sum>k\<in>keys. \<P>(fst|t\<circ>OB) {(k, t obs)} * log b (\<P>(fst|t\<circ>OB) {(k, t obs)}))" |
|
454 |
using CP_T_eq_CP_O[OF _ obs] |
|
455 |
by simp |
|
456 |
then have "?H obs = ?Ht (t obs)" . } |
|
457 |
note * = this |
|
458 |
||
459 |
have **: "\<And>x f A. (\<Sum>y\<in>t-`{x}\<inter>A. f y (t y)) = (\<Sum>y\<in>t-`{x}\<inter>A. f y x)" by auto |
|
460 |
||
461 |
{ fix x |
|
462 |
have *: "(\<lambda>x. t (OB x)) -` {t (OB x)} \<inter> msgs = |
|
463 |
(\<Union>obs\<in>?S (OB x). OB -` {obs} \<inter> msgs)" by auto |
|
464 |
have df: "disjoint_family_on (\<lambda>obs. OB -` {obs} \<inter> msgs) (?S (OB x))" |
|
465 |
unfolding disjoint_family_on_def by auto |
|
466 |
have "\<P>(t\<circ>OB) {t (OB x)} = (\<Sum>obs\<in>?S (OB x). \<P>(OB) {obs})" |
|
467 |
unfolding distribution_def comp_def |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
468 |
using finite_measure_finite_Union[OF _ _ df] |
40859 | 469 |
by (force simp add: * intro!: setsum_nonneg) } |
470 |
note P_t_sum_P_O = this |
|
471 |
||
472 |
txt {* Lemma 3 *} |
|
473 |
have "\<H>(fst | OB) = -(\<Sum>obs\<in>OB`msgs. \<P>(OB) {obs} * ?Ht (t obs))" |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
474 |
unfolding conditional_entropy_eq_ce_with_hypothesis[OF |
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
475 |
simple_function_finite simple_function_finite] using * by simp |
40859 | 476 |
also have "\<dots> = -(\<Sum>obs\<in>t`OB`msgs. \<P>(t\<circ>OB) {obs} * ?Ht obs)" |
477 |
apply (subst SIGMA_image_vimage[symmetric, of "OB`msgs" t]) |
|
478 |
apply (subst setsum_reindex) |
|
479 |
apply (fastsimp intro!: inj_onI) |
|
480 |
apply simp |
|
481 |
apply (subst setsum_Sigma[symmetric, unfolded split_def]) |
|
482 |
using finite_space apply fastsimp |
|
483 |
using finite_space apply fastsimp |
|
484 |
apply (safe intro!: setsum_cong) |
|
485 |
using P_t_sum_P_O |
|
486 |
by (simp add: setsum_divide_distrib[symmetric] field_simps ** |
|
487 |
setsum_right_distrib[symmetric] setsum_left_distrib[symmetric]) |
|
488 |
also have "\<dots> = \<H>(fst | t\<circ>OB)" |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
489 |
unfolding conditional_entropy_eq_ce_with_hypothesis[OF |
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
490 |
simple_function_finite simple_function_finite] |
40859 | 491 |
by (simp add: comp_def image_image[symmetric]) |
492 |
finally show ?thesis . |
|
493 |
qed |
|
494 |
||
495 |
theorem "\<I>(fst ; OB) \<le> real (card observations) * log b (real n + 1)" |
|
496 |
proof - |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
497 |
from simple_function_finite simple_function_finite |
40859 | 498 |
have "\<I>(fst ; OB) = \<H>(fst) - \<H>(fst | OB)" |
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
499 |
by (rule mutual_information_eq_entropy_conditional_entropy) |
40859 | 500 |
also have "\<dots> = \<H>(fst) - \<H>(fst | t\<circ>OB)" |
501 |
unfolding ce_OB_eq_ce_t .. |
|
502 |
also have "\<dots> = \<H>(t\<circ>OB) - \<H>(t\<circ>OB | fst)" |
|
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
503 |
unfolding entropy_chain_rule[symmetric, OF simple_function_finite simple_function_finite] sign_simps |
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
504 |
by (subst entropy_commute[OF simple_function_finite simple_function_finite]) simp |
40859 | 505 |
also have "\<dots> \<le> \<H>(t\<circ>OB)" |
506 |
using conditional_entropy_positive[of "t\<circ>OB" fst] by simp |
|
507 |
also have "\<dots> \<le> log b (real (card ((t\<circ>OB)`msgs)))" |
|
508 |
using entropy_le_card[of "t\<circ>OB"] by simp |
|
509 |
also have "\<dots> \<le> log b (real (n + 1)^card observations)" |
|
510 |
using card_T_bound not_empty |
|
511 |
by (auto intro!: log_le simp: card_gt_0_iff power_real_of_nat simp del: real_of_nat_power) |
|
512 |
also have "\<dots> = real (card observations) * log b (real n + 1)" |
|
513 |
by (simp add: log_nat_power real_of_nat_Suc) |
|
514 |
finally show ?thesis . |
|
515 |
qed |
|
516 |
||
517 |
end |
|
518 |
||
41689
3e39b0e730d6
the measure valuation is again part of the measure_space type, instead of an explicit parameter to the locale;
hoelzl
parents:
41413
diff
changeset
|
519 |
end |