src/HOL/Probability/ex/Koepf_Duermuth_Countermeasure.thy
changeset 49793 dd719cdeca8f
parent 49792 43f49922811d
child 57418 6ab1c7cb0b8d
equal deleted inserted replaced
49792:43f49922811d 49793:dd719cdeca8f
   143 
   143 
   144 definition msgs :: "('key \<times> 'message list) set" where
   144 definition msgs :: "('key \<times> 'message list) set" where
   145   "msgs = keys \<times> {ms. set ms \<subseteq> messages \<and> length ms = n}"
   145   "msgs = keys \<times> {ms. set ms \<subseteq> messages \<and> length ms = n}"
   146 
   146 
   147 definition P :: "('key \<times> 'message list) \<Rightarrow> real" where
   147 definition P :: "('key \<times> 'message list) \<Rightarrow> real" where
   148   "P = (\<lambda>(k, ms). K k * (\<Prod>i<length ms. M (ms ! i)))"
   148   "P = (\<lambda>(k, ms). K k * (\<Prod>i<n. M (ms ! i)))"
   149 
   149 
   150 end
   150 end
   151 
   151 
   152 sublocale koepf_duermuth \<subseteq> finite_information msgs P b
   152 sublocale koepf_duermuth \<subseteq> finite_information msgs P b
   153 proof default
   153 proof default
   189 
   189 
   190 definition OB :: "'key \<times> 'message list \<Rightarrow> 'observation list" where
   190 definition OB :: "'key \<times> 'message list \<Rightarrow> 'observation list" where
   191   "OB = (\<lambda>(k, ms). map (observe k) ms)"
   191   "OB = (\<lambda>(k, ms). map (observe k) ms)"
   192 
   192 
   193 definition t :: "'observation list \<Rightarrow> 'observation \<Rightarrow> nat" where
   193 definition t :: "'observation list \<Rightarrow> 'observation \<Rightarrow> nat" where
   194   "t seq obs = length (filter (op = obs) seq)"
   194   t_def2: "t seq obs = card { i. i < length seq \<and> seq ! i = obs}"
       
   195 
       
   196 lemma t_def: "t seq obs = length (filter (op = obs) seq)"
       
   197   unfolding t_def2 length_filter_conv_card by (subst eq_commute) simp
   195 
   198 
   196 lemma card_T_bound: "card ((t\<circ>OB)`msgs) \<le> (n+1)^card observations"
   199 lemma card_T_bound: "card ((t\<circ>OB)`msgs) \<le> (n+1)^card observations"
   197 proof -
   200 proof -
   198   have "(t\<circ>OB)`msgs \<subseteq> extensionalD 0 observations \<inter> (observations \<rightarrow> {.. n})"
   201   have "(t\<circ>OB)`msgs \<subseteq> extensionalD 0 observations \<inter> (observations \<rightarrow> {.. n})"
   199     unfolding observations_def extensionalD_def OB_def msgs_def
   202     unfolding observations_def extensionalD_def OB_def msgs_def
   322     by (auto simp add: setsum_right_distrib vimage_def intro!: setsum_cong prob_conj_imp1)
   325     by (auto simp add: setsum_right_distrib vimage_def intro!: setsum_cong prob_conj_imp1)
   323   finally show "- (\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` msgs. (\<P>(X ; Y) {(x, y)}) * log b ((\<P>(X ; Y) {(x, y)}) / (\<P>(Y) {y}))) =
   326   finally show "- (\<Sum>(x, y)\<in>(\<lambda>x. (X x, Y x)) ` msgs. (\<P>(X ; Y) {(x, y)}) * log b ((\<P>(X ; Y) {(x, y)}) / (\<P>(Y) {y}))) =
   324     -(\<Sum>y\<in>Y`msgs. (\<P>(Y) {y}) * (\<Sum>x\<in>X`msgs. (\<P>(X ; Y) {(x,y)}) / (\<P>(Y) {y}) * log b ((\<P>(X ; Y) {(x,y)}) / (\<P>(Y) {y}))))" .
   327     -(\<Sum>y\<in>Y`msgs. (\<P>(Y) {y}) * (\<Sum>x\<in>X`msgs. (\<P>(X ; Y) {(x,y)}) / (\<P>(Y) {y}) * log b ((\<P>(X ; Y) {(x,y)}) / (\<P>(Y) {y}))))" .
   325 qed
   328 qed
   326 
   329 
   327 lemma ce_OB_eq_ce_t: "\<H>(fst | OB) = \<H>(fst | t\<circ>OB)"
   330 lemma ce_OB_eq_ce_t: "\<I>(fst ; OB) = \<I>(fst ; t\<circ>OB)"
   328 proof -
   331 proof -
   329   txt {* Lemma 2 *}
   332   txt {* Lemma 2 *}
   330 
   333 
   331   { fix k obs obs'
   334   { fix k obs obs'
   332     assume "k \<in> keys" "K k \<noteq> 0" and obs': "obs' \<in> OB ` msgs" and obs: "obs \<in> OB ` msgs"
   335     assume "k \<in> keys" "K k \<noteq> 0" and obs': "obs' \<in> OB ` msgs" and obs: "obs \<in> OB ` msgs"
   431       using finite_measure_finite_Union[OF _ df]
   434       using finite_measure_finite_Union[OF _ df]
   432       by (force simp add: * intro!: setsum_nonneg) }
   435       by (force simp add: * intro!: setsum_nonneg) }
   433   note P_t_sum_P_O = this
   436   note P_t_sum_P_O = this
   434 
   437 
   435   txt {* Lemma 3 *}
   438   txt {* Lemma 3 *}
   436   txt {* Lemma 3 *}
       
   437   have "\<H>(fst | OB) = -(\<Sum>obs\<in>OB`msgs. \<P>(OB) {obs} * ?Ht (t obs))"
   439   have "\<H>(fst | OB) = -(\<Sum>obs\<in>OB`msgs. \<P>(OB) {obs} * ?Ht (t obs))"
   438     unfolding conditional_entropy_eq_ce_with_hypothesis using * by simp
   440     unfolding conditional_entropy_eq_ce_with_hypothesis using * by simp
   439   also have "\<dots> = -(\<Sum>obs\<in>t`OB`msgs. \<P>(t\<circ>OB) {obs} * ?Ht obs)"
   441   also have "\<dots> = -(\<Sum>obs\<in>t`OB`msgs. \<P>(t\<circ>OB) {obs} * ?Ht obs)"
   440     apply (subst SIGMA_image_vimage[symmetric, of "OB`msgs" t])
   442     apply (subst SIGMA_image_vimage[symmetric, of "OB`msgs" t])
   441     apply (subst setsum_reindex)
   443     apply (subst setsum_reindex)
   449     by (simp add: setsum_divide_distrib[symmetric] field_simps **
   451     by (simp add: setsum_divide_distrib[symmetric] field_simps **
   450                   setsum_right_distrib[symmetric] setsum_left_distrib[symmetric])
   452                   setsum_right_distrib[symmetric] setsum_left_distrib[symmetric])
   451   also have "\<dots> = \<H>(fst | t\<circ>OB)"
   453   also have "\<dots> = \<H>(fst | t\<circ>OB)"
   452     unfolding conditional_entropy_eq_ce_with_hypothesis
   454     unfolding conditional_entropy_eq_ce_with_hypothesis
   453     by (simp add: comp_def image_image[symmetric])
   455     by (simp add: comp_def image_image[symmetric])
   454   finally show ?thesis .
   456   finally show ?thesis
       
   457     by (subst (1 2) mutual_information_eq_entropy_conditional_entropy) simp_all
   455 qed
   458 qed
   456 
   459 
   457 theorem "\<I>(fst ; OB) \<le> real (card observations) * log b (real n + 1)"
   460 theorem "\<I>(fst ; OB) \<le> real (card observations) * log b (real n + 1)"
   458 proof -
   461 proof -
   459   from simple_function_finite simple_function_finite
   462   have "\<I>(fst ; OB) = \<H>(fst) - \<H>(fst | t\<circ>OB)"
   460   have "\<I>(fst ; OB) = \<H>(fst) - \<H>(fst | OB)"
   463     unfolding ce_OB_eq_ce_t
   461     by (rule mutual_information_eq_entropy_conditional_entropy)
   464     by (rule mutual_information_eq_entropy_conditional_entropy simple_function_finite)+
   462   also have "\<dots> = \<H>(fst) - \<H>(fst | t\<circ>OB)"
       
   463     unfolding ce_OB_eq_ce_t ..
       
   464   also have "\<dots> = \<H>(t\<circ>OB) - \<H>(t\<circ>OB | fst)"
   465   also have "\<dots> = \<H>(t\<circ>OB) - \<H>(t\<circ>OB | fst)"
   465     unfolding entropy_chain_rule[symmetric, OF simple_function_finite simple_function_finite] sign_simps
   466     unfolding entropy_chain_rule[symmetric, OF simple_function_finite simple_function_finite] sign_simps
   466     by (subst entropy_commute) simp
   467     by (subst entropy_commute) simp
   467   also have "\<dots> \<le> \<H>(t\<circ>OB)"
   468   also have "\<dots> \<le> \<H>(t\<circ>OB)"
   468     using conditional_entropy_nonneg[of "t\<circ>OB" fst] by simp
   469     using conditional_entropy_nonneg[of "t\<circ>OB" fst] by simp