author | hoelzl |
Thu, 01 Dec 2011 14:03:57 +0100 | |
changeset 45712 | 852597248663 |
parent 45711 | a2c32e196d49 |
child 45715 | efd2b952f425 |
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 |
definition (in prob_space) |
|
79 |
"order_distribution X i = real (distribution X {ordered_variable_partition X i})" |
|
80 |
||
81 |
definition (in prob_space) |
|
82 |
"guessing_entropy b X = (\<Sum>i<card(X`space M). real i * log b (order_distribution X i))" |
|
83 |
||
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
|
84 |
abbreviation (in information_space) |
40859 | 85 |
finite_guessing_entropy ("\<G>'(_')") where |
86 |
"\<G>(X) \<equiv> guessing_entropy b X" |
|
87 |
||
88 |
lemma zero_notin_Suc_image[simp]: "0 \<notin> Suc ` A" |
|
89 |
by auto |
|
90 |
||
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
91 |
definition extensionalD :: "'b \<Rightarrow> 'a set \<Rightarrow> ('a \<Rightarrow> 'b) set" where |
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
92 |
"extensionalD d A = {f. \<forall>x. x \<notin> A \<longrightarrow> f x = d}" |
40859 | 93 |
|
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
94 |
lemma extensionalD_empty[simp]: "extensionalD d {} = {\<lambda>x. d}" |
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
95 |
unfolding extensionalD_def by (simp add: set_eq_iff fun_eq_iff) |
40859 | 96 |
|
97 |
lemma funset_eq_UN_fun_upd_I: |
|
98 |
assumes *: "\<And>f. f \<in> F (insert a A) \<Longrightarrow> f(a := d) \<in> F A" |
|
99 |
and **: "\<And>f. f \<in> F (insert a A) \<Longrightarrow> f a \<in> G (f(a:=d))" |
|
100 |
and ***: "\<And>f x. \<lbrakk> f \<in> F A ; x \<in> G f \<rbrakk> \<Longrightarrow> f(a:=x) \<in> F (insert a A)" |
|
101 |
shows "F (insert a A) = (\<Union>f\<in>F A. fun_upd f a ` (G f))" |
|
102 |
proof safe |
|
103 |
fix f assume f: "f \<in> F (insert a A)" |
|
104 |
show "f \<in> (\<Union>f\<in>F A. fun_upd f a ` G f)" |
|
105 |
proof (rule UN_I[of "f(a := d)"]) |
|
106 |
show "f(a := d) \<in> F A" using *[OF f] . |
|
107 |
show "f \<in> fun_upd (f(a:=d)) a ` G (f(a:=d))" |
|
108 |
proof (rule image_eqI[of _ _ "f a"]) |
|
109 |
show "f a \<in> G (f(a := d))" using **[OF f] . |
|
110 |
qed simp |
|
111 |
qed |
|
112 |
next |
|
113 |
fix f x assume "f \<in> F A" "x \<in> G f" |
|
114 |
from ***[OF this] show "f(a := x) \<in> F (insert a A)" . |
|
115 |
qed |
|
116 |
||
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
117 |
lemma extensionalD_insert[simp]: |
40859 | 118 |
assumes "a \<notin> A" |
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
119 |
shows "extensionalD d (insert a A) \<inter> (insert a A \<rightarrow> B) = (\<Union>f \<in> extensionalD d A \<inter> (A \<rightarrow> B). (\<lambda>b. f(a := b)) ` B)" |
40859 | 120 |
apply (rule funset_eq_UN_fun_upd_I) |
121 |
using assms |
|
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
122 |
by (auto intro!: inj_onI dest: inj_onD split: split_if_asm simp: extensionalD_def) |
40859 | 123 |
|
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
124 |
lemma finite_extensionalD_funcset[simp, intro]: |
40859 | 125 |
assumes "finite A" "finite B" |
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
126 |
shows "finite (extensionalD d A \<inter> (A \<rightarrow> B))" |
40859 | 127 |
using assms by induct auto |
128 |
||
129 |
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
|
130 |
by (auto simp: fun_eq_iff) |
40859 | 131 |
|
132 |
lemma card_funcset: |
|
133 |
assumes "finite A" "finite B" |
|
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
134 |
shows "card (extensionalD d A \<inter> (A \<rightarrow> B)) = card B ^ card A" |
40859 | 135 |
using `finite A` proof induct |
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
136 |
case (insert a A) thus ?case unfolding extensionalD_insert[OF `a \<notin> A`] |
40859 | 137 |
proof (subst card_UN_disjoint, safe, simp_all) |
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
138 |
show "finite (extensionalD d A \<inter> (A \<rightarrow> B))" "\<And>f. finite (fun_upd f a ` B)" |
40859 | 139 |
using `finite B` `finite A` by simp_all |
140 |
next |
|
141 |
fix f g b b' assume "f \<noteq> g" and eq: "f(a := b) = g(a := b')" and |
|
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
142 |
ext: "f \<in> extensionalD d A" "g \<in> extensionalD d A" |
40859 | 143 |
have "f a = d" "g a = d" |
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
144 |
using ext `a \<notin> A` by (auto simp add: extensionalD_def) |
40859 | 145 |
with `f \<noteq> g` eq show False unfolding fun_upd_eq_iff[of _ _ b _ _ d] |
146 |
by (auto simp: fun_upd_idem fun_upd_eq_iff) |
|
147 |
next |
|
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
148 |
{ fix f assume "f \<in> extensionalD d A \<inter> (A \<rightarrow> B)" |
40859 | 149 |
have "card (fun_upd f a ` B) = card B" |
150 |
proof (auto intro!: card_image inj_onI) |
|
151 |
fix b b' assume "f(a := b) = f(a := b')" |
|
152 |
from fun_upd_eq_iff[THEN iffD1, OF this] show "b = b'" by simp |
|
153 |
qed } |
|
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
154 |
then show "(\<Sum>i\<in>extensionalD d A \<inter> (A \<rightarrow> B). card (fun_upd i a ` B)) = card B * card B ^ card A" |
40859 | 155 |
using insert by simp |
156 |
qed |
|
157 |
qed simp |
|
158 |
||
159 |
lemma set_of_list_extend: |
|
160 |
"{xs. length xs = Suc n \<and> (\<forall>x\<in>set xs. x \<in> A)} = |
|
161 |
(\<lambda>(xs, n). n#xs) ` ({xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)} \<times> A)" |
|
162 |
by (auto simp: length_Suc_conv) |
|
163 |
||
164 |
lemma |
|
165 |
assumes "finite A" |
|
166 |
shows finite_lists: |
|
167 |
"finite {xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)}" (is "finite (?lists n)") |
|
168 |
and card_list_length: |
|
169 |
"card {xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)} = (card A)^n" |
|
170 |
proof - |
|
171 |
from `finite A` |
|
172 |
have "(card {xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)} = (card A)^n) \<and> |
|
173 |
finite {xs. length xs = n \<and> (\<forall>x\<in>set xs. x \<in> A)}" |
|
174 |
proof (induct n) |
|
175 |
case (Suc n) |
|
176 |
moreover note set_of_list_extend[of n A] |
|
177 |
moreover have "inj_on (\<lambda>(xs, n). n#xs) (?lists n \<times> A)" |
|
178 |
by (auto intro!: inj_onI) |
|
179 |
ultimately show ?case using assms by (auto simp: card_image) |
|
180 |
qed (simp cong: conj_cong) |
|
181 |
then show "finite (?lists n)" "card (?lists n) = card A ^ n" |
|
182 |
by auto |
|
183 |
qed |
|
184 |
||
185 |
locale finite_information = |
|
186 |
fixes \<Omega> :: "'a set" |
|
187 |
and p :: "'a \<Rightarrow> real" |
|
188 |
and b :: real |
|
189 |
assumes finite_space[simp, intro]: "finite \<Omega>" |
|
190 |
and p_sums_1[simp]: "(\<Sum>\<omega>\<in>\<Omega>. p \<omega>) = 1" |
|
191 |
and positive_p[simp, intro]: "\<And>x. 0 \<le> p x" |
|
192 |
and b_gt_1[simp, intro]: "1 < b" |
|
193 |
||
194 |
lemma (in finite_information) positive_p_sum[simp]: "0 \<le> setsum p X" |
|
195 |
by (auto intro!: setsum_nonneg) |
|
196 |
||
43920 | 197 |
sublocale finite_information \<subseteq> finite_measure_space "\<lparr> space = \<Omega>, sets = Pow \<Omega>, measure = \<lambda>S. ereal (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
|
198 |
by (rule finite_measure_spaceI) (simp_all add: setsum_Un_disjoint finite_subset) |
40859 | 199 |
|
43920 | 200 |
sublocale finite_information \<subseteq> finite_prob_space "\<lparr> space = \<Omega>, sets = Pow \<Omega>, measure = \<lambda>S. ereal (setsum p S)\<rparr>" |
201 |
by default (simp add: one_ereal_def) |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
202 |
|
43920 | 203 |
sublocale finite_information \<subseteq> information_space "\<lparr> space = \<Omega>, sets = Pow \<Omega>, measure = \<lambda>S. ereal (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
|
204 |
by default simp |
40859 | 205 |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
206 |
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
|
207 |
unfolding \<mu>'_def by auto |
40859 | 208 |
|
209 |
locale koepf_duermuth = K: finite_information keys K b + M: finite_information messages M b |
|
210 |
for b :: real |
|
211 |
and keys :: "'key set" and K :: "'key \<Rightarrow> real" |
|
212 |
and messages :: "'message set" and M :: "'message \<Rightarrow> real" + |
|
213 |
fixes observe :: "'key \<Rightarrow> 'message \<Rightarrow> 'observation" |
|
214 |
and n :: nat |
|
215 |
begin |
|
216 |
||
217 |
definition msgs :: "('key \<times> 'message list) set" where |
|
218 |
"msgs = keys \<times> {ms. length ms = n \<and> (\<forall>M\<in>set ms. M \<in> messages)}" |
|
219 |
||
220 |
definition P :: "('key \<times> 'message list) \<Rightarrow> real" where |
|
221 |
"P = (\<lambda>(k, ms). K k * (\<Prod>i<length ms. M (ms ! i)))" |
|
222 |
||
223 |
end |
|
224 |
||
225 |
sublocale koepf_duermuth \<subseteq> finite_information msgs P b |
|
226 |
proof default |
|
227 |
show "finite msgs" unfolding msgs_def |
|
228 |
using finite_lists[OF M.finite_space, of n] |
|
229 |
by auto |
|
230 |
||
231 |
have [simp]: "\<And>A. inj_on (\<lambda>(xs, n). n # xs) A" by (force intro!: inj_onI) |
|
232 |
||
233 |
note setsum_right_distrib[symmetric, simp] |
|
234 |
note setsum_left_distrib[symmetric, simp] |
|
235 |
note setsum_cartesian_product'[simp] |
|
236 |
||
237 |
have "(\<Sum>ms | length ms = n \<and> (\<forall>M\<in>set ms. M \<in> messages). \<Prod>x<length ms. M (ms ! x)) = 1" |
|
238 |
proof (induct n) |
|
239 |
case 0 then show ?case by (simp cong: conj_cong) |
|
240 |
next |
|
241 |
case (Suc n) |
|
242 |
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
|
243 |
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
|
244 |
setsum_reindex setprod_reindex) |
40859 | 245 |
qed |
246 |
then show "setsum P msgs = 1" |
|
247 |
unfolding msgs_def P_def by simp |
|
248 |
fix x |
|
249 |
have "\<And> A f. 0 \<le> (\<Prod>x\<in>A. M (f x))" by (auto simp: setprod_nonneg) |
|
250 |
then show "0 \<le> P x" |
|
251 |
unfolding P_def by (auto split: prod.split simp: zero_le_mult_iff) |
|
252 |
qed auto |
|
253 |
||
254 |
lemma SIGMA_image_vimage: |
|
255 |
"snd ` (SIGMA x:f`X. f -` {x} \<inter> X) = X" |
|
256 |
by (auto simp: image_iff) |
|
257 |
||
258 |
lemma inj_Cons[simp]: "\<And>X. inj_on (\<lambda>(xs, x). x#xs) X" by (auto intro!: inj_onI) |
|
259 |
||
260 |
lemma setprod_setsum_distrib_lists: |
|
261 |
fixes P and S :: "'a set" and f :: "'a \<Rightarrow> _::semiring_0" assumes "finite S" |
|
262 |
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)) = |
|
263 |
(\<Prod>i<n. \<Sum>m\<in>{m\<in>S. P i m}. f m)" |
|
264 |
proof (induct n arbitrary: P) |
|
265 |
case 0 then show ?case by (simp cong: conj_cong) |
|
266 |
next |
|
267 |
case (Suc n) |
|
268 |
have *: "{ms. length ms = Suc n \<and> set ms \<subseteq> S \<and> (\<forall>i<Suc n. P i (ms ! i))} = |
|
269 |
(\<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})" |
|
270 |
apply (auto simp: image_iff length_Suc_conv) |
|
271 |
apply force+ |
|
272 |
apply (case_tac i) |
|
273 |
by force+ |
|
274 |
show ?case unfolding * |
|
275 |
using Suc[of "\<lambda>i. P (Suc i)"] |
|
276 |
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
|
277 |
lessThan_Suc_eq_insert_0 setprod_reindex setsum_left_distrib[symmetric] setsum_right_distrib[symmetric]) |
40859 | 278 |
qed |
279 |
||
280 |
context koepf_duermuth |
|
281 |
begin |
|
282 |
||
283 |
definition observations :: "'observation set" where |
|
284 |
"observations = (\<Union>f\<in>observe ` keys. f ` messages)" |
|
285 |
||
286 |
lemma finite_observations[simp, intro]: "finite observations" |
|
287 |
unfolding observations_def by auto |
|
288 |
||
289 |
definition OB :: "'key \<times> 'message list \<Rightarrow> 'observation list" where |
|
290 |
"OB = (\<lambda>(k, ms). map (observe k) ms)" |
|
291 |
||
292 |
definition t :: "'observation list \<Rightarrow> 'observation \<Rightarrow> nat" where |
|
293 |
"t seq obs = length (filter (op = obs) seq)" |
|
294 |
||
295 |
lemma card_T_bound: "card ((t\<circ>OB)`msgs) \<le> (n+1)^card observations" |
|
296 |
proof - |
|
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
297 |
have "(t\<circ>OB)`msgs \<subseteq> extensionalD 0 observations \<inter> (observations \<rightarrow> {.. n})" |
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
298 |
unfolding observations_def extensionalD_def OB_def msgs_def |
40859 | 299 |
by (auto simp add: t_def comp_def image_iff) |
42256
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
300 |
with finite_extensionalD_funcset |
461624ffd382
Rename extensional to extensionalD (extensional is also defined in FuncSet)
hoelzl
parents:
41981
diff
changeset
|
301 |
have "card ((t\<circ>OB)`msgs) \<le> card (extensionalD 0 observations \<inter> (observations \<rightarrow> {.. n}))" |
40859 | 302 |
by (rule card_mono) auto |
303 |
also have "\<dots> = (n + 1) ^ card observations" |
|
304 |
by (subst card_funcset) auto |
|
305 |
finally show ?thesis . |
|
306 |
qed |
|
307 |
||
308 |
abbreviation |
|
309 |
"p A \<equiv> setsum P A" |
|
310 |
||
311 |
abbreviation probability ("\<P>'(_') _") where |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
312 |
"\<P>(X) x \<equiv> distribution X x" |
40859 | 313 |
|
314 |
abbreviation joint_probability ("\<P>'(_, _') _") where |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
315 |
"\<P>(X, Y) x \<equiv> joint_distribution X Y x" |
40859 | 316 |
|
317 |
abbreviation conditional_probability ("\<P>'(_|_') _") where |
|
318 |
"\<P>(X|Y) x \<equiv> \<P>(X, Y) x / \<P>(Y) (snd`x)" |
|
319 |
||
320 |
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
|
321 |
entropy_Pow ("\<H>'( _ ')") |
40859 | 322 |
|
323 |
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
|
324 |
conditional_entropy_Pow ("\<H>'( _ | _ ')") |
40859 | 325 |
|
326 |
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
|
327 |
mutual_information_Pow ("\<I>'( _ ; _ ')") |
40859 | 328 |
|
329 |
lemma t_eq_imp_bij_func: |
|
330 |
assumes "t xs = t ys" |
|
331 |
shows "\<exists>f. bij_betw f {..<length xs} {..<length ys} \<and> (\<forall>i<length xs. xs ! i = ys ! (f i))" |
|
332 |
proof - |
|
333 |
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
|
334 |
using assms by (simp add: fun_eq_iff count_multiset_of t_def) |
40859 | 335 |
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
|
336 |
then show ?thesis by (rule permutation_Ex_bij) |
40859 | 337 |
qed |
338 |
||
339 |
lemma \<P>_k: assumes "k \<in> keys" shows "\<P>(fst) {k} = K k" |
|
340 |
proof - |
|
341 |
from assms have *: |
|
342 |
"fst -` {k} \<inter> msgs = {k}\<times>{ms. length ms = n \<and> (\<forall>M\<in>set ms. M \<in> messages)}" |
|
343 |
unfolding msgs_def by auto |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
344 |
show "\<P>(fst) {k} = K k" |
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
345 |
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
|
346 |
apply (simp add: * P_def) |
40859 | 347 |
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
|
348 |
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
|
349 |
by (auto simp add: setsum_right_distrib[symmetric] subset_eq setprod_1) |
40859 | 350 |
qed |
351 |
||
352 |
lemma fst_image_msgs[simp]: "fst`msgs = keys" |
|
353 |
proof - |
|
354 |
from M.not_empty obtain m where "m \<in> messages" by auto |
|
355 |
then have *: "{m. length m = n \<and> (\<forall>x\<in>set m. x\<in>messages)} \<noteq> {}" |
|
356 |
by (auto intro!: exI[of _ "replicate n m"]) |
|
357 |
then show ?thesis |
|
358 |
unfolding msgs_def fst_image_times if_not_P[OF *] by simp |
|
359 |
qed |
|
360 |
||
361 |
lemma ce_OB_eq_ce_t: "\<H>(fst | OB) = \<H>(fst | t\<circ>OB)" |
|
362 |
proof - |
|
363 |
txt {* Lemma 2 *} |
|
364 |
||
365 |
{ fix k obs obs' |
|
366 |
assume "k \<in> keys" "K k \<noteq> 0" and obs': "obs' \<in> OB ` msgs" and obs: "obs \<in> OB ` msgs" |
|
367 |
assume "t obs = t obs'" |
|
368 |
from t_eq_imp_bij_func[OF this] |
|
369 |
obtain t_f where "bij_betw t_f {..<n} {..<n}" and |
|
370 |
obs_t_f: "\<And>i. i<n \<Longrightarrow> obs!i = obs' ! t_f i" |
|
371 |
using obs obs' unfolding OB_def msgs_def by auto |
|
372 |
then have t_f: "inj_on t_f {..<n}" "{..<n} = t_f`{..<n}" unfolding bij_betw_def by auto |
|
373 |
||
374 |
{ fix obs assume "obs \<in> OB`msgs" |
|
375 |
then have **: "\<And>ms. length ms = n \<Longrightarrow> OB (k, ms) = obs \<longleftrightarrow> (\<forall>i<n. observe k (ms!i) = obs ! i)" |
|
376 |
unfolding OB_def msgs_def by (simp add: image_iff list_eq_iff_nth_eq) |
|
377 |
||
378 |
have "\<P>(OB, fst) {(obs, k)} / K k = |
|
379 |
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
|
380 |
apply (simp add: distribution_def \<mu>'_eq) by (auto intro!: arg_cong[where f=p]) |
40859 | 381 |
also have "\<dots> = |
382 |
(\<Prod>i<n. \<Sum>m\<in>{m\<in>messages. observe k m = obs ! i}. M m)" |
|
383 |
unfolding P_def using `K k \<noteq> 0` `k \<in> keys` |
|
384 |
apply (simp add: setsum_cartesian_product' setsum_divide_distrib msgs_def ** cong: conj_cong) |
|
385 |
apply (subst setprod_setsum_distrib_lists[OF M.finite_space, unfolded subset_eq]) .. |
|
386 |
finally have "\<P>(OB, fst) {(obs, k)} / K k = |
|
387 |
(\<Prod>i<n. \<Sum>m\<in>{m\<in>messages. observe k m = obs ! i}. M m)" . } |
|
388 |
note * = this |
|
389 |
||
390 |
have "\<P>(OB, fst) {(obs, k)} / K k = \<P>(OB, fst) {(obs', k)} / K k" |
|
391 |
unfolding *[OF obs] *[OF obs'] |
|
392 |
using t_f(1) obs_t_f by (subst (2) t_f(2)) (simp add: setprod_reindex) |
|
393 |
then have "\<P>(OB, fst) {(obs, k)} = \<P>(OB, fst) {(obs', k)}" |
|
394 |
using `K k \<noteq> 0` by auto } |
|
395 |
note t_eq_imp = this |
|
396 |
||
397 |
let "?S obs" = "t -`{t obs} \<inter> OB`msgs" |
|
398 |
{ fix k obs assume "k \<in> keys" "K k \<noteq> 0" and obs: "obs \<in> OB`msgs" |
|
399 |
have *: "((\<lambda>x. (t (OB x), fst x)) -` {(t obs, k)} \<inter> msgs) = |
|
400 |
(\<Union>obs'\<in>?S obs. ((\<lambda>x. (OB x, fst x)) -` {(obs', k)} \<inter> msgs))" by auto |
|
401 |
have df: "disjoint_family_on (\<lambda>obs'. (\<lambda>x. (OB x, fst x)) -` {(obs', k)} \<inter> msgs) (?S obs)" |
|
402 |
unfolding disjoint_family_on_def by auto |
|
403 |
have "\<P>(t\<circ>OB, fst) {(t obs, k)} = (\<Sum>obs'\<in>?S obs. \<P>(OB, fst) {(obs', k)})" |
|
404 |
unfolding distribution_def comp_def |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
405 |
using finite_measure_finite_Union[OF _ _ df] |
40859 | 406 |
by (force simp add: * intro!: setsum_nonneg) |
407 |
also have "(\<Sum>obs'\<in>?S obs. \<P>(OB, fst) {(obs', k)}) = real (card (?S obs)) * \<P>(OB, fst) {(obs, k)}" |
|
408 |
by (simp add: t_eq_imp[OF `k \<in> keys` `K k \<noteq> 0` obs] real_eq_of_nat) |
|
409 |
finally have "\<P>(t\<circ>OB, fst) {(t obs, k)} = real (card (?S obs)) * \<P>(OB, fst) {(obs, k)}" .} |
|
410 |
note P_t_eq_P_OB = this |
|
411 |
||
412 |
{ fix k obs assume "k \<in> keys" and obs: "obs \<in> OB`msgs" |
|
413 |
have "\<P>(t\<circ>OB | fst) {(t obs, k)} = |
|
414 |
real (card (t -` {t obs} \<inter> OB ` msgs)) * \<P>(OB | fst) {(obs, k)}" |
|
415 |
using \<P>_k[OF `k \<in> keys`] P_t_eq_P_OB[OF `k \<in> keys` _ obs] by auto } |
|
416 |
note CP_t_K = this |
|
417 |
||
418 |
{ fix k obs assume "k \<in> keys" and obs: "obs \<in> OB`msgs" |
|
419 |
then have "t -`{t obs} \<inter> OB`msgs \<noteq> {}" (is "?S \<noteq> {}") by auto |
|
420 |
then have "real (card ?S) \<noteq> 0" by auto |
|
421 |
||
422 |
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
|
423 |
using distribution_order(7,8)[where X=fst and x=k and Y="t\<circ>OB" and y="t obs"] |
40859 | 424 |
by (subst joint_distribution_commute) auto |
425 |
also have "\<P>(t\<circ>OB) {t obs} = (\<Sum>k'\<in>keys. \<P>(t\<circ>OB|fst) {(t obs, k')} * \<P>(fst) {k'})" |
|
45711
a2c32e196d49
rename finite_prob_space.setsum_distribution, it collides with prob_space.setsum_distribution
hoelzl
parents:
44890
diff
changeset
|
426 |
using setsum_distribution_cut(2)[of "t\<circ>OB" fst "t obs", symmetric] |
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
427 |
by (auto intro!: setsum_cong distribution_order(8)) |
40859 | 428 |
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'}) = |
429 |
\<P>(OB | fst) {(obs, k)} * \<P>(fst) {k} / (\<Sum>k'\<in>keys. \<P>(OB|fst) {(obs, k')} * \<P>(fst) {k'})" |
|
430 |
using CP_t_K[OF `k\<in>keys` obs] CP_t_K[OF _ obs] `real (card ?S) \<noteq> 0` |
|
431 |
by (simp only: setsum_right_distrib[symmetric] ac_simps |
|
432 |
mult_divide_mult_cancel_left[OF `real (card ?S) \<noteq> 0`] |
|
433 |
cong: setsum_cong) |
|
434 |
also have "(\<Sum>k'\<in>keys. \<P>(OB|fst) {(obs, k')} * \<P>(fst) {k'}) = \<P>(OB) {obs}" |
|
45711
a2c32e196d49
rename finite_prob_space.setsum_distribution, it collides with prob_space.setsum_distribution
hoelzl
parents:
44890
diff
changeset
|
435 |
using setsum_distribution_cut(2)[of OB fst obs, symmetric] |
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
436 |
by (auto intro!: setsum_cong distribution_order(8)) |
40859 | 437 |
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
|
438 |
by (subst joint_distribution_commute) (auto intro!: distribution_order(8)) |
40859 | 439 |
finally have "\<P>(fst | t\<circ>OB) {(k, t obs)} = \<P>(fst | OB) {(k, obs)}" . } |
440 |
note CP_T_eq_CP_O = this |
|
441 |
||
442 |
let "?H obs" = "(\<Sum>k\<in>keys. \<P>(fst|OB) {(k, obs)} * log b (\<P>(fst|OB) {(k, obs)})) :: real" |
|
443 |
let "?Ht obs" = "(\<Sum>k\<in>keys. \<P>(fst|t\<circ>OB) {(k, obs)} * log b (\<P>(fst|t\<circ>OB) {(k, obs)})) :: real" |
|
444 |
||
445 |
{ fix obs assume obs: "obs \<in> OB`msgs" |
|
446 |
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)}))" |
|
447 |
using CP_T_eq_CP_O[OF _ obs] |
|
448 |
by simp |
|
449 |
then have "?H obs = ?Ht (t obs)" . } |
|
450 |
note * = this |
|
451 |
||
452 |
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 |
|
453 |
||
454 |
{ fix x |
|
455 |
have *: "(\<lambda>x. t (OB x)) -` {t (OB x)} \<inter> msgs = |
|
456 |
(\<Union>obs\<in>?S (OB x). OB -` {obs} \<inter> msgs)" by auto |
|
457 |
have df: "disjoint_family_on (\<lambda>obs. OB -` {obs} \<inter> msgs) (?S (OB x))" |
|
458 |
unfolding disjoint_family_on_def by auto |
|
459 |
have "\<P>(t\<circ>OB) {t (OB x)} = (\<Sum>obs\<in>?S (OB x). \<P>(OB) {obs})" |
|
460 |
unfolding distribution_def comp_def |
|
41981
cdf7693bbe08
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl
parents:
41689
diff
changeset
|
461 |
using finite_measure_finite_Union[OF _ _ df] |
40859 | 462 |
by (force simp add: * intro!: setsum_nonneg) } |
463 |
note P_t_sum_P_O = this |
|
464 |
||
465 |
txt {* Lemma 3 *} |
|
466 |
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
|
467 |
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
|
468 |
simple_function_finite simple_function_finite] using * by simp |
40859 | 469 |
also have "\<dots> = -(\<Sum>obs\<in>t`OB`msgs. \<P>(t\<circ>OB) {obs} * ?Ht obs)" |
470 |
apply (subst SIGMA_image_vimage[symmetric, of "OB`msgs" t]) |
|
471 |
apply (subst setsum_reindex) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
43920
diff
changeset
|
472 |
apply (fastforce intro!: inj_onI) |
40859 | 473 |
apply simp |
474 |
apply (subst setsum_Sigma[symmetric, unfolded split_def]) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
43920
diff
changeset
|
475 |
using finite_space apply fastforce |
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
43920
diff
changeset
|
476 |
using finite_space apply fastforce |
40859 | 477 |
apply (safe intro!: setsum_cong) |
478 |
using P_t_sum_P_O |
|
479 |
by (simp add: setsum_divide_distrib[symmetric] field_simps ** |
|
480 |
setsum_right_distrib[symmetric] setsum_left_distrib[symmetric]) |
|
481 |
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
|
482 |
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
|
483 |
simple_function_finite simple_function_finite] |
40859 | 484 |
by (simp add: comp_def image_image[symmetric]) |
485 |
finally show ?thesis . |
|
486 |
qed |
|
487 |
||
488 |
theorem "\<I>(fst ; OB) \<le> real (card observations) * log b (real n + 1)" |
|
489 |
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
|
490 |
from simple_function_finite simple_function_finite |
40859 | 491 |
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
|
492 |
by (rule mutual_information_eq_entropy_conditional_entropy) |
40859 | 493 |
also have "\<dots> = \<H>(fst) - \<H>(fst | t\<circ>OB)" |
494 |
unfolding ce_OB_eq_ce_t .. |
|
495 |
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
|
496 |
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
|
497 |
by (subst entropy_commute[OF simple_function_finite simple_function_finite]) simp |
40859 | 498 |
also have "\<dots> \<le> \<H>(t\<circ>OB)" |
499 |
using conditional_entropy_positive[of "t\<circ>OB" fst] by simp |
|
500 |
also have "\<dots> \<le> log b (real (card ((t\<circ>OB)`msgs)))" |
|
501 |
using entropy_le_card[of "t\<circ>OB"] by simp |
|
502 |
also have "\<dots> \<le> log b (real (n + 1)^card observations)" |
|
503 |
using card_T_bound not_empty |
|
504 |
by (auto intro!: log_le simp: card_gt_0_iff power_real_of_nat simp del: real_of_nat_power) |
|
505 |
also have "\<dots> = real (card observations) * log b (real n + 1)" |
|
506 |
by (simp add: log_nat_power real_of_nat_Suc) |
|
507 |
finally show ?thesis . |
|
508 |
qed |
|
509 |
||
510 |
end |
|
511 |
||
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
|
512 |
end |