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