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