section‹Formalization of a Countermeasure by Koepf \& Duermuth 2009›
theory Koepf_Duermuth_Countermeasure imports"HOL-Probability.Information" begin
lemma SIGMA_image_vimage: "snd ` (SIGMA x:f`X. f -` {x} ∩ X) = X" by (auto simp: image_iff)
declare inj_split_Cons[simp]
definition extensionalD :: "'b ==> 'a set ==> ('a ==> 'b) set"where "extensionalD d A = {f. ∀x. x ∉ A ⟶ f x = d}"
lemma extensionalD_empty[simp]: "extensionalD d {} = {λx. d}" unfolding extensionalD_def by (simp add: set_eq_iff fun_eq_iff)
lemma funset_eq_UN_fun_upd_I: assumes *: "∧f. f ∈ F (insert a A) ==> f(a := d) ∈ F A" and **: "∧f. f ∈ F (insert a A) ==> f a ∈ G (f(a:=d))" and ***: "∧f x. [ f ∈ F A ; x ∈ G f ]==> f(a:=x) ∈ F (insert a A)" shows"F (insert a A) = (∪f∈F A. fun_upd f a ` (G f))" proof safe fix f assume f: "f ∈ F (insert a A)" show"f ∈ (∪f∈F A. fun_upd f a ` G f)" proof (rule UN_I[of "f(a := d)"]) show"f(a := d) ∈ F A"using *[OF f] . show"f ∈ fun_upd (f(a:=d)) a ` G (f(a:=d))" proof (rule image_eqI[of _ _ "f a"]) show"f a ∈ G (f(a := d))"using **[OF f] . qed simp qed next fix f x assume"f ∈ F A""x ∈ G f" from ***[OF this] show"f(a := x) ∈ F (insert a A)" . qed
lemma extensionalD_insert[simp]: assumes"a ∉ A" shows"extensionalD d (insert a A) ∩ (insert a A → B) = (∪f ∈ extensionalD d A ∩ (A → B). (λb. f(a := b)) ` B)" apply (rule funset_eq_UN_fun_upd_I) using assms by (auto intro!: inj_onI dest: inj_onD split: if_split_asm simp: extensionalD_def)
lemma finite_extensionalD_funcset[simp, intro]: assumes"finite A""finite B" shows"finite (extensionalD d A ∩ (A → B))" using assms by induct auto
lemma fun_upd_eq_iff: "f(a := b) = g(a := b') ⟷ b = b' ∧ f(a := d) = g(a := d)" by (auto simp: fun_eq_iff)
lemma card_funcset: assumes"finite A""finite B" shows"card (extensionalD d A ∩ (A → B)) = card B ^ card A" using‹finite A›proof induct case (insert a A) thus ?caseunfolding extensionalD_insert[OF ‹a ∉ A›] proof (subst card_UN_disjoint, safe, simp_all) show"finite (extensionalD d A ∩ (A → B))""∧f. finite (fun_upd f a ` B)" using‹finite B›‹finite A›by simp_all next fix f g b b' assume"f ≠ g"and eq: "f(a := b) = g(a := b')"and
ext: "f ∈ extensionalD d A""g ∈ extensionalD d A" have"f a = d""g a = d" using ext ‹a ∉ A›by (auto simp add: extensionalD_def) with‹f ≠ g› eq show False unfolding fun_upd_eq_iff[of _ _ b _ _ d] by (auto simp: fun_upd_idem fun_upd_eq_iff) next have"card (fun_upd f a ` B) = card B" if"f ∈ extensionalD d A ∩ (A → B)"for f proof (auto intro!: card_image inj_onI) fix b b' assume"f(a := b) = f(a := b')" from fun_upd_eq_iff[THEN iffD1, OF this] show"b = b'"by simp qed thenshow"(∑i∈extensionalD d A ∩ (A → B). card (fun_upd i a ` B)) = card B * card B ^ card A" using insert by simp qed qed simp
lemma prod_sum_distrib_lists: fixes P and S :: "'a set"and f :: "'a ==> _::semiring_0"assumes"finite S" shows"(∑ms∈{ms. set ms ⊆ S ∧ length ms = n ∧ (∀i<n. P i (ms!i))}. ∏x<n. f (ms ! x)) = (∏i<n. ∑m∈{m∈S. P i m}. f m)" proof (induct n arbitrary: P) case0thenshow ?caseby (simp cong: conj_cong) next case (Suc n) have *: "{ms. set ms ⊆ S ∧ length ms = Suc n ∧ (∀i<Suc n. P i (ms ! i))} = (λ(xs, x). x#xs) ` ({ms. set ms ⊆ S ∧ length ms = n ∧ (∀i<n. P (Suc i) (ms ! i))} × {m∈S. P 0 m})" apply (auto simp: image_iff length_Suc_conv) apply force+ apply (case_tac i) by force+ show ?caseunfolding * using Suc[of "λi. P (Suc i)"] by (simp add: sum.reindex sum.cartesian_product'
lessThan_Suc_eq_insert_0 prod.reindex sum_distrib_right[symmetric] sum_distrib_left[symmetric]) qed
declare space_point_measure[simp]
declare sets_point_measure[simp]
lemma measure_point_measure: "finite Ω ==> A ⊆ Ω ==> (∧x. x ∈ Ω ==> 0 ≤ p x) ==> measure (point_measure Ω (λx. ennreal (p x))) A = (∑i∈A. p i)" unfolding measure_def by (subst emeasure_point_measure_finite) (auto simp: subset_eq sum_nonneg)
locale finite_information = fixes Ω :: "'a set" and p :: "'a ==> real" and b :: real assumes finite_space[simp, intro]: "finite Ω" and p_sums_1[simp]: "(∑ψ∈Ω. p ψ) = 1" and positive_p[simp, intro]: "∧x. 0 ≤ p x" and b_gt_1[simp, intro]: "1 < b"
lemma (in finite_information) positive_p_sum[simp]: "0 ≤ sum p X" by (auto intro!: sum_nonneg)
sublocale finite_information ⊆ prob_space "point_measure Ω p" by standard (simp add: one_ereal_def emeasure_point_measure_finite)
sublocale finite_information ⊆ information_space "point_measure Ω p" b by standard simp
lemma (in finite_information) μ'_eq: "A ⊆ Ω ==> prob A = sum p A" by (auto simp: measure_point_measure)
locale koepf_duermuth = K: finite_information keys K b + M: finite_information messages M b for b :: real and keys :: "'key set"and K :: "'key ==> real" and messages :: "'message set"and M :: "'message ==> real" + fixes observe :: "'key ==> 'message ==> 'observation" and n :: nat begin
definition msgs :: "('key × 'message list) set"where "msgs = keys × {ms. set ms ⊆ messages ∧ length ms = n}"
definition P :: "('key × 'message list) ==> real"where "P = (λ(k, ms). K k * (∏i<n. M (ms ! i)))"
end
sublocale koepf_duermuth ⊆ finite_information msgs P b proof show"finite msgs"unfolding msgs_def using finite_lists_length_eq[OF M.finite_space, of n] by auto
have [simp]: "∧A. inj_on (λ(xs, n). n # xs) A"by (force intro!: inj_onI)
have"(∑ms | set ms ⊆ messages ∧ length ms = n. ∏x<length ms. M (ms ! x)) = 1" proof (induct n) case0thenshow ?caseby (simp cong: conj_cong) next case (Suc n) thenshow ?case by (simp add: lists_length_Suc_eq lessThan_Suc_eq_insert_0
sum.reindex prod.reindex) qed thenshow"sum P msgs = 1" unfolding msgs_def P_def by simp have"0 ≤ (∏x∈A. M (f x))"for A f by (auto simp: prod_nonneg) thenshow"0 ≤ P x"for x unfolding P_def by (auto split: prod.split simp: zero_le_mult_iff) qed auto
lemma card_T_bound: "card ((t∘OB)`msgs) ≤ (n+1)^card observations" proof - have"(t∘OB)`msgs ⊆ extensionalD 0 observations ∩ (observations → {.. n})" unfolding observations_def extensionalD_def OB_def msgs_def by (auto simp add: t_def comp_def image_iff subset_eq) with finite_extensionalD_funcset have"card ((t∘OB)`msgs) ≤ card (extensionalD 0 observations ∩ (observations → {.. n}))" by (rule card_mono) auto alsohave"… = (n + 1) ^ card observations" by (subst card_funcset) auto finallyshow ?thesis . qed
abbreviation "p A ≡ sum P A"
abbreviation "μ ≡ point_measure msgs P"
abbreviation probability (‹P'(_') _›) where "P(X) x ≡ measure μ (X -` x ∩ msgs)"
abbreviation joint_probability (‹P'(_ ; _') _›) where "P(X ; Y) x ≡P(λx. (X x, Y x)) x"
no_notation disj (infixr‹|›30)
abbreviation conditional_probability (‹P'(_ | _') _›) where "P(X | Y) x ≡ (P(X ; Y) x) / P(Y) (snd`x)"
notation
entropy_Pow (‹H'( _ ')›)
notation
conditional_entropy_Pow (‹H'( _ | _ ')›)
notation
mutual_information_Pow (‹I'( _ ; _ ')›)
lemma t_eq_imp_bij_func: assumes"t xs = t ys" shows"∃f. bij_betw f {..<length xs} {..<length ys} ∧ (∀i<length xs. xs ! i = ys ! (f i))" proof - from assms have‹mset xs = mset ys› using assms by (simp add: fun_eq_iff t_def multiset_eq_iff count_mset count_list_eq_length_filter) thenobtain p where‹p permutes {..<length ys}›‹permute_list p ys = xs› by (rule mset_eq_permutation) thenhave‹bij_betw p {..<length xs} {..<length ys}›‹∀i<length xs. xs ! i = ys ! p i› by (auto dest: permutes_imp_bij simp add: permute_list_nth) thenshow ?thesis by blast qed
lemmaP_k: assumes"k ∈ keys"shows"P(fst) {k} = K k" proof - from assms have *: "fst -` {k} ∩ msgs = {k}×{ms. set ms ⊆ messages ∧ length ms = n}" unfolding msgs_def by auto show"(P(fst) {k}) = K k" apply (simp add: μ'_eq) apply (simp add: * P_def) apply (simp add: sum.cartesian_product') using prod_sum_distrib_lists[OF M.finite_space, of M n "λx x. True"] ‹k ∈ keys› by (auto simp add: sum_distrib_left[symmetric] subset_eq prod.neutral_const) qed
lemma fst_image_msgs[simp]: "fst`msgs = keys" proof - from M.not_empty obtain m where"m ∈ messages"by auto thenhave *: "{m. set m ⊆ messages ∧ length m = n} ≠ {}" by (auto intro!: exI[of _ "replicate n m"]) thenshow ?thesis unfolding msgs_def fst_image_times if_not_P[OF *] by simp qed
have t_eq_imp: "(\<P>(OB ; fst) {(obs, k)}) = (\<P>(OB ; fst) {(obs', k)})"
if "k \<in> keys" "K k \<noteq> 0" and obs': "obs' \<in> OB ` msgs" and obs: "obs \<in> OB ` msgs"
and eq: "t obs = t obs'"
for k obs obs'
proof -
from t_eq_imp_bij_func[OF eq]
obtain t_f where "bij_betw t_f {..<n} {..<n}" and
obs_t_f: "\<And>i. i<n \<Longrightarrow> obs!i = obs' ! t_f i"
using obs obs' unfolding OB_def msgs_def by auto
then have t_f: "inj_on t_f {..<n}" "{..<n} = t_f`{..<n}" unfolding bij_betw_def by auto
have *: "(\<P>(OB ; fst) {(obs, k)}) / K k =
(\<Prod>i<n. \<Sum>m\<in>{m\<in>messages. observe k m = obs ! i}. M m)"
if "obs \<in> OB`msgs" for obs
proof -
from that have **: "length ms = n \<Longrightarrow> OB (k, ms) = obs \<longleftrightarrow> (\<forall>i<n. observe k (ms!i) = obs ! i)"
for ms
unfolding OB_def msgs_def by (simp add: image_iff list_eq_iff_nth_eq)
have "(\<P>(OB ; fst) {(obs, k)}) / K k =
p ({k}\<times>{ms. (k,ms) \<in> msgs \<and> OB (k,ms) = obs}) / K k"
by (simp add: \<mu>'_eq) (auto intro!: arg_cong[where f=p])
also have "\<dots> = (\<Prod>i<n. \<Sum>m\<in>{m\<in>messages. observe k m = obs ! i}. M m)"
unfolding P_def using \<open>K k \<noteq> 0\<close> \<open>k \<in> keys\<close>
apply (simp add: sum.cartesian_product' sum_divide_distrib msgs_def ** cong: conj_cong)
apply (subst prod_sum_distrib_lists[OF M.finite_space]) ..
finally show ?thesis .
qed
have "(\<P>(OB ; fst) {(obs, k)}) / K k = (\<P>(OB ; fst) {(obs', k)}) / K k"
unfolding *[OF obs] *[OF obs']
using t_f(1) obs_t_f by (subst (2) t_f(2)) (simp add: prod.reindex)
then show ?thesis using \<open>K k \<noteq> 0\<close> by auto
qed
let ?S = "\<lambda>obs. t -`{t obs} \<inter> OB`msgs"
have P_t_eq_P_OB: "\<P>(t\<circ>OB ; fst) {(t obs, k)} = real (card (?S obs)) * \<P>(OB ; fst) {(obs, k)}"
if "k \<in> keys" "K k \<noteq> 0" and obs: "obs \<in> OB`msgs"
for k obs
proof -
have *: "((\<lambda>x. (t (OB x), fst x)) -` {(t obs, k)} \<inter> msgs) =
(\<Union>obs'\<in>?S obs. ((\<lambda>x. (OB x, fst x)) -` {(obs', k)} \<inter> msgs))" by auto
have df: "disjoint_family_on (\<lambda>obs'. (\<lambda>x. (OB x, fst x)) -` {(obs', k)} \<inter> msgs) (?S obs)"
unfolding disjoint_family_on_def by auto
have "\<P>(t\<circ>OB ; fst) {(t obs, k)} = (\<Sum>obs'\<in>?S obs. \<P>(OB ; fst) {(obs', k)})"
unfolding comp_def
using finite_measure_finite_Union[OF _ _ df]
by (auto simp add: * intro!: sum_nonneg)
also have "(\<Sum>obs'\<in>?S obs. \<P>(OB ; fst) {(obs', k)}) = real (card (?S obs)) * \<P>(OB ; fst) {(obs, k)}"
by (simp add: t_eq_imp[OF \<open>k \<in> keys\<close> \<open>K k \<noteq> 0\<close> obs])
finally show ?thesis .
qed
have CP_t_K: "\<P>(t\<circ>OB | fst) {(t obs, k)} =
real (card (t -` {t obs} \<inter> OB ` msgs)) * \<P>(OB | fst) {(obs, k)}"
if k: "k \<in> keys" and obs: "obs \<in> OB`msgs" for k obs
using \<P>_k[OF k] P_t_eq_P_OB[OF k _ obs] by auto
have CP_T_eq_CP_O: "\<P>(fst | t\<circ>OB) {(k, t obs)} = \<P>(fst | OB) {(k, obs)}"
if "k \<in> keys" and obs: "obs \<in> OB`msgs" for k obs
proof -
from that have "t -`{t obs} \<inter> OB`msgs \<noteq> {}" (is "?S \<noteq> {}") by auto
then have "real (card ?S) \<noteq> 0" by auto
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}"
using finite_measure_mono[of "{x. fst x = k \<and> t (OB x) = t obs} \<inter> msgs" "{x. fst x = k} \<inter> msgs"]
using measure_nonneg[of \<mu> "{x. fst x = k \<and> t (OB x) = t obs} \<inter> msgs"]
by (auto simp add: vimage_def conj_commute subset_eq simp del: measure_nonneg)
also have "(\<P>(t\<circ>OB) {t obs}) = (\<Sum>k'\<in>keys. (\<P>(t\<circ>OB|fst) {(t obs, k')}) * (\<P>(fst) {k'}))"
using finite_measure_mono[of "{x. t (OB x) = t obs \<and> fst x = k} \<inter> msgs" "{x. fst x = k} \<inter> msgs"]
using measure_nonneg[of \<mu> "{x. fst x = k \<and> t (OB x) = t obs} \<inter> msgs"]
apply (simp add: sum_distribution_cut[of "t\<circ>OB" "t obs" fst])
apply (auto intro!: sum.cong simp: subset_eq vimage_def prob_conj_imp1)
done
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'}) =
\<P>(OB | fst) {(obs, k)} * \<P>(fst) {k} / (\<Sum>k'\<in>keys. \<P>(OB|fst) {(obs, k')} * \<P>(fst) {k'})"
using CP_t_K[OF \<open>k\<in>keys\<close> obs] CP_t_K[OF _ obs] \<open>real (card ?S) \<noteq> 0\<close>
by (simp only: sum_distrib_left[symmetric] ac_simps
mult_divide_mult_cancel_left[OF \<open>real (card ?S) \<noteq> 0\<close>]
cong: sum.cong)
also have "(\<Sum>k'\<in>keys. \<P>(OB|fst) {(obs, k')} * \<P>(fst) {k'}) = \<P>(OB) {obs}"
using sum_distribution_cut[of OB obs fst]
by (auto intro!: sum.cong simp: prob_conj_imp1 vimage_def)
also have "\<P>(OB | fst) {(obs, k)} * \<P>(fst) {k} / \<P>(OB) {obs} = \<P>(fst | OB) {(k, obs)}"
by (auto simp: vimage_def conj_commute prob_conj_imp2)
finally show ?thesis .
qed
let ?H = "\<lambda>obs. (\<Sum>k\<in>keys. \<P>(fst|OB) {(k, obs)} * log b (\<P>(fst|OB) {(k, obs)})) :: real"
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"
have *: "?H obs = ?Ht (t obs)" if obs: "obs \<in> OB`msgs" for obs
proof -
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)}))"
using CP_T_eq_CP_O[OF _ obs]
by simp
then show ?thesis .
qed
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
have P_t_sum_P_O: "\<P>(t\<circ>OB) {t (OB x)} = (\<Sum>obs\<in>?S (OB x). \<P>(OB) {obs})" for x
proof -
have *: "(\<lambda>x. t (OB x)) -` {t (OB x)} \<inter> msgs =
(\<Union>obs\<in>?S (OB x). OB -` {obs} \<inter> msgs)" by auto
have df: "disjoint_family_on (\<lambda>obs. OB -` {obs} \<inter> msgs) (?S (OB x))"
unfolding disjoint_family_on_def by auto
show ?thesis
unfolding comp_def
using finite_measure_finite_Union[OF _ _ df]
by (force simp add: * intro!: sum_nonneg)
qed
txt \<open>Lemma 3\<close>
have "\<H>(fst | OB) = -(\<Sum>obs\<in>OB`msgs. \<P>(OB) {obs} * ?Ht (t obs))"
unfolding conditional_entropy_eq_ce_with_hypothesis using * by simp
also have "\<dots> = -(\<Sum>obs\<in>t`OB`msgs. \<P>(t\<circ>OB) {obs} * ?Ht obs)"
apply (subst SIGMA_image_vimage[symmetric, of "OB`msgs" t])
apply (subst sum.reindex)
apply (fastforce intro!: inj_onI)
apply simp
apply (subst sum.Sigma[symmetric, unfolded split_def])
using finite_space apply fastforce
using finite_space apply fastforce
apply (safe intro!: sum.cong)
using P_t_sum_P_O
by (simp add: sum_divide_distrib[symmetric] field_simps **
sum_distrib_left[symmetric] sum_distrib_right[symmetric])
also have "\<dots> = \<H>(fst | t\<circ>OB)"
unfolding conditional_entropy_eq_ce_with_hypothesis
by (simp add: comp_def image_image[symmetric])
finally show ?thesis
by (subst (12) mutual_information_eq_entropy_conditional_entropy) simp_all
qed
theorem "\<I>(fst ; OB) \<le> real (card observations) * log b (real n + 1)"
proof -
have "\<I>(fst ; OB) = \<H>(fst) - \<H>(fst | t\<circ>OB)"
unfolding ce_OB_eq_ce_t
by (rule mutual_information_eq_entropy_conditional_entropy simple_function_finite)+
also have "\<dots> = \<H>(t\<circ>OB) - \<H>(t\<circ>OB | fst)"
unfolding entropy_chain_rule[symmetric, OF simple_function_finite simple_function_finite] algebra_simps
by (subst entropy_commute) simp
also have "\<dots> \<le> \<H>(t\<circ>OB)"
using conditional_entropy_nonneg[of "t\<circ>OB" fst] by simp
also have "\<dots> \<le> log b (real (card ((t\<circ>OB)`msgs)))"
using entropy_le_card[of "t\<circ>OB", OF simple_distributedI[OF simple_function_finite _ refl]] by simp
also have "\<dots> \<le> log b (real (n + 1)^card observations)"
using card_T_bound not_empty
by (auto intro!: log_mono simp: card_gt_0_iff of_nat_power [symmetric] simp del: of_nat_power of_nat_Suc)
also have "\<dots> = real (card observations) * log b (real n + 1)"
by (simp add: log_nat_power add.commute)
finally show ?thesis .
qed
end
end
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.41Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.