src/HOL/Probability/Information.thy
author hoelzl
Mon, 03 May 2010 14:35:10 +0200
changeset 36624 25153c08655e
parent 36623 d26348b667f2
child 36649 bfd8c550faa6
permissions -rw-r--r--
Cleanup information theory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
     1
theory Information
36623
d26348b667f2 Moved Convex theory to library.
hoelzl
parents: 36080
diff changeset
     2
imports Probability_Space Product_Measure "../Multivariate_Analysis/Convex"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
     3
begin
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
     4
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
     5
section "Convex theory"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
     6
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
     7
lemma log_setsum:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
     8
  assumes "finite s" "s \<noteq> {}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
     9
  assumes "b > 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    10
  assumes "(\<Sum> i \<in> s. a i) = 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    11
  assumes "\<And> i. i \<in> s \<Longrightarrow> a i \<ge> 0"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    12
  assumes "\<And> i. i \<in> s \<Longrightarrow> y i \<in> {0 <..}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    13
  shows "log b (\<Sum> i \<in> s. a i * y i) \<ge> (\<Sum> i \<in> s. a i * log b (y i))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    14
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    15
  have "convex_on {0 <..} (\<lambda> x. - log b x)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    16
    by (rule minus_log_convex[OF `b > 1`])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    17
  hence "- log b (\<Sum> i \<in> s. a i * y i) \<le> (\<Sum> i \<in> s. a i * - log b (y i))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    18
    using convex_on_setsum[of _ _ "\<lambda> x. - log b x"] assms pos_is_convex by fastsimp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    19
  thus ?thesis by (auto simp add:setsum_negf le_imp_neg_le)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    20
qed
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
    21
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    22
lemma log_setsum':
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    23
  assumes "finite s" "s \<noteq> {}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    24
  assumes "b > 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    25
  assumes "(\<Sum> i \<in> s. a i) = 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    26
  assumes pos: "\<And> i. i \<in> s \<Longrightarrow> 0 \<le> a i"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    27
          "\<And> i. \<lbrakk> i \<in> s ; 0 < a i \<rbrakk> \<Longrightarrow> 0 < y i"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    28
  shows "log b (\<Sum> i \<in> s. a i * y i) \<ge> (\<Sum> i \<in> s. a i * log b (y i))"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
    29
proof -
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    30
  have "\<And>y. (\<Sum> i \<in> s - {i. a i = 0}. a i * y i) = (\<Sum> i \<in> s. a i * y i)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    31
    using assms by (auto intro!: setsum_mono_zero_cong_left)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    32
  moreover have "log b (\<Sum> i \<in> s - {i. a i = 0}. a i * y i) \<ge> (\<Sum> i \<in> s - {i. a i = 0}. a i * log b (y i))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    33
  proof (rule log_setsum)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    34
    have "setsum a (s - {i. a i = 0}) = setsum a s"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    35
      using assms(1) by (rule setsum_mono_zero_cong_left) auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    36
    thus sum_1: "setsum a (s - {i. a i = 0}) = 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    37
      "finite (s - {i. a i = 0})" using assms by simp_all
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    38
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    39
    show "s - {i. a i = 0} \<noteq> {}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    40
    proof
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    41
      assume *: "s - {i. a i = 0} = {}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    42
      hence "setsum a (s - {i. a i = 0}) = 0" by (simp add: * setsum_empty)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    43
      with sum_1 show False by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    44
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    45
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    46
    fix i assume "i \<in> s - {i. a i = 0}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    47
    hence "i \<in> s" "a i \<noteq> 0" by simp_all
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    48
    thus "0 \<le> a i" "y i \<in> {0<..}" using pos[of i] by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    49
  qed fact+
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    50
  ultimately show ?thesis by simp
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
    51
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
    52
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    53
section "Information theory"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    54
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    55
lemma (in finite_prob_space) sum_over_space_distrib:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    56
  "(\<Sum>x\<in>X`space M. distribution X {x}) = 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    57
  unfolding distribution_def prob_space[symmetric] using finite_space
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    58
  by (subst measure_finitely_additive'')
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    59
     (auto simp add: disjoint_family_on_def sets_eq_Pow intro!: arg_cong[where f=prob])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    60
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    61
locale finite_information_space = finite_prob_space +
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    62
  fixes b :: real assumes b_gt_1: "1 < b"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    63
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    64
definition
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    65
  "KL_divergence b M X Y =
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    66
    measure_space.integral (M\<lparr>measure := X\<rparr>)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    67
                           (\<lambda>x. log b ((measure_space.RN_deriv (M \<lparr>measure := Y\<rparr> ) X) x))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    68
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    69
lemma (in finite_prob_space) distribution_mono:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    70
  assumes "\<And>t. \<lbrakk> t \<in> space M ; X t \<in> x \<rbrakk> \<Longrightarrow> Y t \<in> y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    71
  shows "distribution X x \<le> distribution Y y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    72
  unfolding distribution_def
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    73
  using assms by (auto simp: sets_eq_Pow intro!: measure_mono)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    74
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    75
lemma (in prob_space) distribution_remove_const:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    76
  shows "joint_distribution X (\<lambda>x. ()) {(x, ())} = distribution X {x}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    77
  and "joint_distribution (\<lambda>x. ()) X {((), x)} = distribution X {x}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    78
  and "joint_distribution X (\<lambda>x. (Y x, ())) {(x, y, ())} = joint_distribution X Y {(x, y)}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    79
  and "joint_distribution X (\<lambda>x. ((), Y x)) {(x, (), y)} = joint_distribution X Y {(x, y)}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    80
  and "distribution (\<lambda>x. ()) {()} = 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    81
  unfolding prob_space[symmetric]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    82
  by (auto intro!: arg_cong[where f=prob] simp: distribution_def)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    83
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    84
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    85
context finite_information_space
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    86
begin
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    87
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    88
lemma distribution_mono_gt_0:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    89
  assumes gt_0: "0 < distribution X x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    90
  assumes *: "\<And>t. \<lbrakk> t \<in> space M ; X t \<in> x \<rbrakk> \<Longrightarrow> Y t \<in> y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    91
  shows "0 < distribution Y y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    92
  by (rule less_le_trans[OF gt_0 distribution_mono]) (rule *)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    93
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    94
lemma
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    95
  assumes "0 \<le> A" and pos: "0 < A \<Longrightarrow> 0 < B" "0 < A \<Longrightarrow> 0 < C"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    96
  shows mult_log_mult: "A * log b (B * C) = A * log b B + A * log b C" (is "?mult")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    97
  and mult_log_divide: "A * log b (B / C) = A * log b B - A * log b C" (is "?div")
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
    98
proof -
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
    99
  have "?mult \<and> ?div"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   100
proof (cases "A = 0")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   101
  case False
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   102
  hence "0 < A" using `0 \<le> A` by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   103
    with pos[OF this] show "?mult \<and> ?div" using b_gt_1
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   104
      by (auto simp: log_divide log_mult field_simps)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   105
qed simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   106
  thus ?mult and ?div by auto
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   107
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   108
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   109
lemma split_pairs:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   110
  shows
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   111
    "((A, B) = X) \<longleftrightarrow> (fst X = A \<and> snd X = B)" and
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   112
    "(X = (A, B)) \<longleftrightarrow> (fst X = A \<and> snd X = B)" by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   113
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   114
ML {*
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   115
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   116
  (* tactic to solve equations of the form @{term "W * log b (X / (Y * Z)) = W * log b X - W * log b (Y * Z)"}
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   117
     where @{term W} is a joint distribution of @{term X}, @{term Y}, and @{term Z}. *)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   118
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   119
  val mult_log_intros = [@{thm mult_log_divide}, @{thm mult_log_mult}]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   120
  val intros = [@{thm divide_pos_pos}, @{thm mult_pos_pos}, @{thm positive_distribution}]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   121
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   122
  val distribution_gt_0_tac = (rtac @{thm distribution_mono_gt_0}
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   123
    THEN' assume_tac
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   124
    THEN' clarsimp_tac (clasimpset_of @{context} addsimps2 @{thms split_pairs}))
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   125
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   126
  val distr_mult_log_eq_tac = REPEAT_ALL_NEW (CHANGED o TRY o
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   127
    (resolve_tac (mult_log_intros @ intros)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   128
      ORELSE' distribution_gt_0_tac
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   129
      ORELSE' clarsimp_tac (clasimpset_of @{context})))
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   130
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   131
  fun instanciate_term thy redex intro =
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   132
    let
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   133
      val intro_concl = Thm.concl_of intro
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   134
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   135
      val lhs = intro_concl |> HOLogic.dest_Trueprop |> HOLogic.dest_eq |> fst
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   136
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   137
      val m = SOME (Pattern.match thy (lhs, redex) (Vartab.empty, Vartab.empty))
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   138
        handle Pattern.MATCH => NONE
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   139
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   140
    in
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   141
      Option.map (fn m => Envir.subst_term m intro_concl) m
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   142
    end
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   143
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   144
  fun mult_log_simproc simpset redex =
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   145
  let
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   146
    val ctxt = Simplifier.the_context simpset
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   147
    val thy = ProofContext.theory_of ctxt
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   148
    fun prove (SOME thm) = (SOME
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   149
          (Goal.prove ctxt [] [] thm (K (distr_mult_log_eq_tac 1))
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   150
           |> mk_meta_eq)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   151
            handle THM _ => NONE)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   152
      | prove NONE = NONE
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   153
  in
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   154
    get_first (instanciate_term thy (term_of redex) #> prove) mult_log_intros
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   155
  end
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   156
*}
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   157
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   158
simproc_setup mult_log ("distribution X x * log b (A * B)" |
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   159
                        "distribution X x * log b (A / B)") = {* K mult_log_simproc *}
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   160
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   161
end
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   162
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   163
lemma KL_divergence_eq_finite:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   164
  assumes u: "finite_measure_space (M\<lparr>measure := u\<rparr>)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   165
  assumes v: "finite_measure_space (M\<lparr>measure := v\<rparr>)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   166
  assumes u_0: "\<And>x. \<lbrakk> x \<in> space M ; v {x} = 0 \<rbrakk> \<Longrightarrow> u {x} = 0"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   167
  shows "KL_divergence b M u v = (\<Sum>x\<in>space M. u {x} * log b (u {x} / v {x}))" (is "_ = ?sum")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   168
proof (simp add: KL_divergence_def, subst finite_measure_space.integral_finite_singleton, simp_all add: u)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   169
  have ms_u: "measure_space (M\<lparr>measure := u\<rparr>)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   170
    using u unfolding finite_measure_space_def by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   171
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   172
  show "(\<Sum>x \<in> space M. log b (measure_space.RN_deriv (M\<lparr>measure := v\<rparr>) u x) * u {x}) = ?sum"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   173
    apply (rule setsum_cong[OF refl])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   174
    apply simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   175
    apply (safe intro!: arg_cong[where f="log b"] )
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   176
    apply (subst finite_measure_space.RN_deriv_finite_singleton)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   177
    using assms ms_u by auto
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   178
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   179
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   180
lemma log_setsum_divide:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   181
  assumes "finite S" and "S \<noteq> {}" and "1 < b"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   182
  assumes "(\<Sum>x\<in>S. g x) = 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   183
  assumes pos: "\<And>x. x \<in> S \<Longrightarrow> g x \<ge> 0" "\<And>x. x \<in> S \<Longrightarrow> f x \<ge> 0"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   184
  assumes g_pos: "\<And>x. \<lbrakk> x \<in> S ; 0 < g x \<rbrakk> \<Longrightarrow> 0 < f x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   185
  shows "- (\<Sum>x\<in>S. g x * log b (g x / f x)) \<le> log b (\<Sum>x\<in>S. f x)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   186
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   187
  have log_mono: "\<And>x y. 0 < x \<Longrightarrow> x \<le> y \<Longrightarrow> log b x \<le> log b y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   188
    using `1 < b` by (subst log_le_cancel_iff) auto
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   189
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   190
  have "- (\<Sum>x\<in>S. g x * log b (g x / f x)) = (\<Sum>x\<in>S. g x * log b (f x / g x))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   191
  proof (unfold setsum_negf[symmetric], rule setsum_cong)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   192
    fix x assume x: "x \<in> S"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   193
    show "- (g x * log b (g x / f x)) = g x * log b (f x / g x)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   194
    proof (cases "g x = 0")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   195
      case False
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   196
      with pos[OF x] g_pos[OF x] have "0 < f x" "0 < g x" by simp_all
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   197
      thus ?thesis using `1 < b` by (simp add: log_divide field_simps)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   198
    qed simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   199
  qed rule
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   200
  also have "... \<le> log b (\<Sum>x\<in>S. g x * (f x / g x))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   201
  proof (rule log_setsum')
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   202
    fix x assume x: "x \<in> S" "0 < g x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   203
    with g_pos[OF x] show "0 < f x / g x" by (safe intro!: divide_pos_pos)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   204
  qed fact+
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   205
  also have "... = log b (\<Sum>x\<in>S - {x. g x = 0}. f x)" using `finite S`
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   206
    by (auto intro!: setsum_mono_zero_cong_right arg_cong[where f="log b"]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   207
        split: split_if_asm)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   208
  also have "... \<le> log b (\<Sum>x\<in>S. f x)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   209
  proof (rule log_mono)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   210
    have "0 = (\<Sum>x\<in>S - {x. g x = 0}. 0)" by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   211
    also have "... < (\<Sum>x\<in>S - {x. g x = 0}. f x)" (is "_ < ?sum")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   212
    proof (rule setsum_strict_mono)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   213
      show "finite (S - {x. g x = 0})" using `finite S` by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   214
      show "S - {x. g x = 0} \<noteq> {}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   215
      proof
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   216
        assume "S - {x. g x = 0} = {}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   217
        hence "(\<Sum>x\<in>S. g x) = 0" by (subst setsum_0') auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   218
        with `(\<Sum>x\<in>S. g x) = 1` show False by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   219
      qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   220
      fix x assume "x \<in> S - {x. g x = 0}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   221
      thus "0 < f x" using g_pos[of x] pos(1)[of x] by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   222
    qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   223
    finally show "0 < ?sum" .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   224
    show "(\<Sum>x\<in>S - {x. g x = 0}. f x) \<le> (\<Sum>x\<in>S. f x)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   225
      using `finite S` pos by (auto intro!: setsum_mono2)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   226
  qed
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   227
  finally show ?thesis .
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   228
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   229
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   230
lemma KL_divergence_positive_finite:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   231
  assumes u: "finite_prob_space (M\<lparr>measure := u\<rparr>)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   232
  assumes v: "finite_prob_space (M\<lparr>measure := v\<rparr>)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   233
  assumes u_0: "\<And>x. \<lbrakk> x \<in> space M ; v {x} = 0 \<rbrakk> \<Longrightarrow> u {x} = 0"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   234
  and "1 < b"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   235
  shows "0 \<le> KL_divergence b M u v"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   236
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   237
  interpret u: finite_prob_space "M\<lparr>measure := u\<rparr>" using u .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   238
  interpret v: finite_prob_space "M\<lparr>measure := v\<rparr>" using v .
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   239
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   240
  have *: "space M \<noteq> {}" using u.not_empty by simp
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   241
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   242
  have "- (KL_divergence b M u v) \<le> log b (\<Sum>x\<in>space M. v {x})"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   243
  proof (subst KL_divergence_eq_finite, safe intro!: log_setsum_divide *)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   244
    show "finite_measure_space (M\<lparr>measure := u\<rparr>)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   245
      "finite_measure_space (M\<lparr>measure := v\<rparr>)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   246
       using u v unfolding finite_prob_space_eq by simp_all
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   247
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   248
     show "finite (space M)" using u.finite_space by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   249
     show "1 < b" by fact
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   250
     show "(\<Sum>x\<in>space M. u {x}) = 1" using u.sum_over_space_eq_1 by simp
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   251
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   252
     fix x assume x: "x \<in> space M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   253
     thus pos: "0 \<le> u {x}" "0 \<le> v {x}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   254
       using u.positive u.sets_eq_Pow v.positive v.sets_eq_Pow by simp_all
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   255
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   256
     { assume "v {x} = 0" from u_0[OF x this] show "u {x} = 0" . }
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   257
     { assume "0 < u {x}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   258
       hence "v {x} \<noteq> 0" using u_0[OF x] by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   259
       with pos show "0 < v {x}" by simp }
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   260
  qed
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   261
  thus "0 \<le> KL_divergence b M u v" using v.sum_over_space_eq_1 by simp
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   262
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   263
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   264
definition (in prob_space)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   265
  "mutual_information b s1 s2 X Y \<equiv>
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   266
    let prod_space =
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   267
      prod_measure_space (\<lparr>space = space s1, sets = sets s1, measure = distribution X\<rparr>)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   268
                         (\<lparr>space = space s2, sets = sets s2, measure = distribution Y\<rparr>)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   269
    in
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   270
      KL_divergence b prod_space (joint_distribution X Y) (measure prod_space)"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   271
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   272
abbreviation (in finite_information_space)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   273
  finite_mutual_information ("\<I>'(_ ; _')") where
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   274
  "\<I>(X ; Y) \<equiv> mutual_information b
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   275
    \<lparr> space = X`space M, sets = Pow (X`space M) \<rparr>
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   276
    \<lparr> space = Y`space M, sets = Pow (Y`space M) \<rparr> X Y"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   277
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   278
lemma (in finite_measure_space) measure_spaceI: "measure_space M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   279
  by unfold_locales
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   280
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   281
lemma prod_measure_times_finite:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   282
  assumes fms: "finite_measure_space M" "finite_measure_space M'" and a: "a \<in> space M \<times> space M'"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   283
  shows "prod_measure M M' {a} = measure M {fst a} * measure M' {snd a}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   284
proof (cases a)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   285
  case (Pair b c)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   286
  hence a_eq: "{a} = {b} \<times> {c}" by simp
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   287
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   288
  with fms[THEN finite_measure_space.measure_spaceI]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   289
    fms[THEN finite_measure_space.sets_eq_Pow] a Pair
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   290
  show ?thesis unfolding a_eq
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   291
    by (subst prod_measure_times) simp_all
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   292
qed
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   293
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   294
lemma setsum_cartesian_product':
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   295
  "(\<Sum>x\<in>A \<times> B. f x) = (\<Sum>x\<in>A. setsum (\<lambda>y. f (x, y)) B)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   296
  unfolding setsum_cartesian_product by simp
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   297
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   298
lemma (in finite_information_space)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   299
  assumes MX: "finite_prob_space \<lparr> space = space MX, sets = sets MX, measure = distribution X\<rparr>"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   300
    (is "finite_prob_space ?MX")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   301
  assumes MY: "finite_prob_space \<lparr> space = space MY, sets = sets MY, measure = distribution Y\<rparr>"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   302
    (is "finite_prob_space ?MY")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   303
  and X_space: "X ` space M \<subseteq> space MX" and Y_space: "Y ` space M \<subseteq> space MY"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   304
  shows mutual_information_eq_generic:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   305
    "mutual_information b MX MY X Y = (\<Sum> (x,y) \<in> space MX \<times> space MY.
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   306
      joint_distribution X Y {(x,y)} *
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   307
      log b (joint_distribution X Y {(x,y)} /
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   308
      (distribution X {x} * distribution Y {y})))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   309
    (is "?equality")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   310
  and mutual_information_positive_generic:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   311
    "0 \<le> mutual_information b MX MY X Y" (is "?positive")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   312
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   313
  let ?P = "prod_measure_space ?MX ?MY"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   314
  let ?measure = "joint_distribution X Y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   315
  let ?P' = "measure_update (\<lambda>_. ?measure) ?P"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   316
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   317
  interpret X: finite_prob_space "?MX" using MX .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   318
  moreover interpret Y: finite_prob_space "?MY" using MY .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   319
  ultimately have ms_X: "measure_space ?MX"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   320
    and ms_Y: "measure_space ?MY" by unfold_locales
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   321
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   322
  have fms_P: "finite_measure_space ?P"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   323
      by (rule finite_measure_space_finite_prod_measure) fact+
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   324
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   325
  have fms_P': "finite_measure_space ?P'"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   326
      using finite_product_measure_space[of "space MX" "space MY"]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   327
        X.finite_space Y.finite_space sigma_prod_sets_finite[OF X.finite_space Y.finite_space]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   328
        X.sets_eq_Pow Y.sets_eq_Pow
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   329
      by (simp add: prod_measure_space_def)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   330
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   331
  { fix x assume "x \<in> space ?P"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   332
    hence x_in_MX: "{fst x} \<in> sets MX" using X.sets_eq_Pow
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   333
      by (auto simp: prod_measure_space_def)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   334
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   335
    assume "measure ?P {x} = 0"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   336
    with prod_measure_times[OF ms_X ms_Y, of "{fst x}" "{snd x}"] x_in_MX
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   337
    have "distribution X {fst x} = 0 \<or> distribution Y {snd x} = 0"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   338
      by (simp add: prod_measure_space_def)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   339
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   340
    hence "joint_distribution X Y {x} = 0"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   341
      by (cases x) (auto simp: distribution_order) }
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   342
  note measure_0 = this
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   343
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   344
  show ?equality
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   345
    unfolding Let_def mutual_information_def using fms_P fms_P' measure_0 MX MY
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   346
    by (subst KL_divergence_eq_finite)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   347
       (simp_all add: prod_measure_space_def prod_measure_times_finite
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   348
         finite_prob_space_eq setsum_cartesian_product')
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   349
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   350
  show ?positive
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   351
    unfolding Let_def mutual_information_def using measure_0 b_gt_1
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   352
  proof (safe intro!: KL_divergence_positive_finite, simp_all)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   353
    from ms_X ms_Y X.top Y.top X.prob_space Y.prob_space
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   354
    have "measure ?P (space ?P) = 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   355
      by (simp add: prod_measure_space_def, subst prod_measure_times, simp_all)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   356
    with fms_P show "finite_prob_space ?P"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   357
      by (simp add: finite_prob_space_eq)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   358
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   359
    from ms_X ms_Y X.top Y.top X.prob_space Y.prob_space Y.not_empty X_space Y_space
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   360
    have "measure ?P' (space ?P') = 1" unfolding prob_space[symmetric]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   361
      by (auto simp add: prod_measure_space_def distribution_def vimage_Times comp_def
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   362
        intro!: arg_cong[where f=prob])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   363
    with fms_P' show "finite_prob_space ?P'"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   364
      by (simp add: finite_prob_space_eq)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   365
  qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   366
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   367
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   368
lemma (in finite_information_space) mutual_information_eq:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   369
  "\<I>(X;Y) = (\<Sum> (x,y) \<in> X ` space M \<times> Y ` space M.
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   370
    distribution (\<lambda>x. (X x, Y x)) {(x,y)} * log b (distribution (\<lambda>x. (X x, Y x)) {(x,y)} /
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   371
                                                   (distribution X {x} * distribution Y {y})))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   372
  by (subst mutual_information_eq_generic) (simp_all add: finite_prob_space_of_images)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   373
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   374
lemma (in finite_information_space) mutual_information_positive: "0 \<le> \<I>(X;Y)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   375
  by (subst mutual_information_positive_generic) (simp_all add: finite_prob_space_of_images)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   376
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   377
definition (in prob_space)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   378
  "entropy b s X = mutual_information b s s X X"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   379
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   380
abbreviation (in finite_information_space)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   381
  finite_entropy ("\<H>'(_')") where
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   382
  "\<H>(X) \<equiv> entropy b \<lparr> space = X`space M, sets = Pow (X`space M) \<rparr> X"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   383
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   384
lemma (in finite_information_space) joint_distribution_remove[simp]:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   385
    "joint_distribution X X {(x, x)} = distribution X {x}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   386
  unfolding distribution_def by (auto intro!: arg_cong[where f=prob])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   387
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   388
lemma (in finite_information_space) entropy_eq:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   389
  "\<H>(X) = -(\<Sum> x \<in> X ` space M. distribution X {x} * log b (distribution X {x}))"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   390
proof -
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   391
  { fix f
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   392
  { fix x y
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   393
    have "(\<lambda>x. (X x, X x)) -` {(x, y)} = (if x = y then X -` {x} else {})" by auto
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   394
      hence "distribution (\<lambda>x. (X x, X x))  {(x,y)} * f x y = (if x = y then distribution X {x} * f x y else 0)"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   395
      unfolding distribution_def by auto }
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   396
    hence "(\<Sum>(x, y) \<in> X ` space M \<times> X ` space M. joint_distribution X X {(x, y)} * f x y) =
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   397
      (\<Sum>x \<in> X ` space M. distribution X {x} * f x x)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   398
      unfolding setsum_cartesian_product' by (simp add: setsum_cases finite_space) }
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   399
  note remove_cartesian_product = this
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   400
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   401
  show ?thesis
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   402
    unfolding entropy_def mutual_information_eq setsum_negf[symmetric] remove_cartesian_product
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   403
    by (auto intro!: setsum_cong)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   404
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   405
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   406
lemma (in finite_information_space) entropy_positive: "0 \<le> \<H>(X)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   407
  unfolding entropy_def using mutual_information_positive .
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   408
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   409
definition (in prob_space)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   410
  "conditional_mutual_information b s1 s2 s3 X Y Z \<equiv>
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   411
    let prod_space =
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   412
      prod_measure_space \<lparr>space = space s2, sets = sets s2, measure = distribution Y\<rparr>
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   413
                         \<lparr>space = space s3, sets = sets s3, measure = distribution Z\<rparr>
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   414
    in
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   415
      mutual_information b s1 prod_space X (\<lambda>x. (Y x, Z x)) -
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   416
      mutual_information b s1 s3 X Z"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   417
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   418
abbreviation (in finite_information_space)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   419
  finite_conditional_mutual_information ("\<I>'( _ ; _ | _ ')") where
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   420
  "\<I>(X ; Y | Z) \<equiv> conditional_mutual_information b
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   421
    \<lparr> space = X`space M, sets = Pow (X`space M) \<rparr>
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   422
    \<lparr> space = Y`space M, sets = Pow (Y`space M) \<rparr>
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   423
    \<lparr> space = Z`space M, sets = Pow (Z`space M) \<rparr>
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   424
    X Y Z"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   425
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   426
lemma (in finite_information_space) setsum_distribution_gen:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   427
  assumes "Z -` {c} \<inter> space M = (\<Union>x \<in> X`space M. Y -` {f x}) \<inter> space M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   428
  and "inj_on f (X`space M)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   429
  shows "(\<Sum>x \<in> X`space M. distribution Y {f x}) = distribution Z {c}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   430
  unfolding distribution_def assms
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   431
  using finite_space assms
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   432
  by (subst measure_finitely_additive'')
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   433
     (auto simp add: disjoint_family_on_def sets_eq_Pow inj_on_def
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   434
      intro!: arg_cong[where f=prob])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   435
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   436
lemma (in finite_information_space) setsum_distribution:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   437
  "(\<Sum>x \<in> X`space M. joint_distribution X Y {(x, y)}) = distribution Y {y}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   438
  "(\<Sum>y \<in> Y`space M. joint_distribution X Y {(x, y)}) = distribution X {x}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   439
  "(\<Sum>x \<in> X`space M. joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)}) = joint_distribution Y Z {(y, z)}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   440
  "(\<Sum>y \<in> Y`space M. joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)}) = joint_distribution X Z {(x, z)}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   441
  "(\<Sum>z \<in> Z`space M. joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)}) = joint_distribution X Y {(x, y)}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   442
  by (auto intro!: inj_onI setsum_distribution_gen)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   443
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   444
lemma (in finite_information_space) conditional_mutual_information_eq_sum:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   445
   "\<I>(X ; Y | Z) =
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   446
     (\<Sum>(x, y, z)\<in>X ` space M \<times> (\<lambda>x. (Y x, Z x)) ` space M.
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   447
             distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)} *
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   448
             log b (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}/
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   449
        distribution (\<lambda>x. (Y x, Z x)) {(y, z)})) -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   450
     (\<Sum>(x, z)\<in>X ` space M \<times> Z ` space M.
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   451
        distribution (\<lambda>x. (X x, Z x)) {(x,z)} * log b (distribution (\<lambda>x. (X x, Z x)) {(x,z)} / distribution Z {z}))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   452
  (is "_ = ?rhs")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   453
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   454
  have setsum_product:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   455
    "\<And>f x. (\<Sum>v\<in>(\<lambda>x. (Y x, Z x)) ` space M. joint_distribution X (\<lambda>x. (Y x, Z x)) {(x,v)} * f v)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   456
      = (\<Sum>v\<in>Y ` space M \<times> Z ` space M. joint_distribution X (\<lambda>x. (Y x, Z x)) {(x,v)} * f v)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   457
  proof (safe intro!: setsum_mono_zero_cong_left imageI)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   458
    fix x y z f
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   459
    assume *: "(Y y, Z z) \<notin> (\<lambda>x. (Y x, Z x)) ` space M" and "y \<in> space M" "z \<in> space M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   460
    hence "(\<lambda>x. (X x, Y x, Z x)) -` {(x, Y y, Z z)} \<inter> space M = {}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   461
    proof safe
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   462
      fix x' assume x': "x' \<in> space M" and eq: "Y x' = Y y" "Z x' = Z z"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   463
      have "(Y y, Z z) \<in> (\<lambda>x. (Y x, Z x)) ` space M" using eq[symmetric] x' by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   464
      thus "x' \<in> {}" using * by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   465
    qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   466
    thus "joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, Y y, Z z)} * f (Y y) (Z z) = 0"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   467
      unfolding distribution_def by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   468
  qed (simp add: finite_space)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   469
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   470
  thus ?thesis
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   471
    unfolding conditional_mutual_information_def Let_def mutual_information_eq
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   472
    apply (subst mutual_information_eq_generic)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   473
    by (auto simp add: prod_measure_space_def sigma_prod_sets_finite finite_space
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   474
        finite_prob_space_of_images finite_product_prob_space_of_images
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   475
        setsum_cartesian_product' setsum_product setsum_subtractf setsum_addf
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   476
        setsum_left_distrib[symmetric] setsum_distribution
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   477
      cong: setsum_cong)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   478
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   479
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   480
lemma (in finite_information_space) conditional_mutual_information_eq:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   481
  "\<I>(X ; Y | Z) = (\<Sum>(x, y, z) \<in> X ` space M \<times> Y ` space M \<times> Z ` space M.
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   482
             distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)} *
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   483
             log b (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}/
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   484
    (joint_distribution X Z {(x, z)} * joint_distribution Y Z {(y,z)} / distribution Z {z})))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   485
  unfolding conditional_mutual_information_def Let_def mutual_information_eq
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   486
    apply (subst mutual_information_eq_generic)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   487
  by (auto simp add: prod_measure_space_def sigma_prod_sets_finite finite_space
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   488
      finite_prob_space_of_images finite_product_prob_space_of_images
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   489
      setsum_cartesian_product' setsum_product setsum_subtractf setsum_addf
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   490
      setsum_left_distrib[symmetric] setsum_distribution setsum_commute[where A="Y`space M"]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   491
    cong: setsum_cong)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   492
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   493
lemma (in finite_information_space) conditional_mutual_information_eq_mutual_information:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   494
  "\<I>(X ; Y) = \<I>(X ; Y | (\<lambda>x. ()))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   495
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   496
  have [simp]: "(\<lambda>x. ()) ` space M = {()}" using not_empty by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   497
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   498
  show ?thesis
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   499
    unfolding conditional_mutual_information_eq mutual_information_eq
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   500
    by (simp add: setsum_cartesian_product' distribution_remove_const)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   501
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   502
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   503
lemma (in finite_information_space) conditional_mutual_information_positive:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   504
  "0 \<le> \<I>(X ; Y | Z)"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   505
proof -
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   506
  let ?dXYZ = "distribution (\<lambda>x. (X x, Y x, Z x))"
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   507
  let ?dXZ = "joint_distribution X Z"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   508
  let ?dYZ = "joint_distribution Y Z"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   509
  let ?dX = "distribution X"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   510
  let ?dZ = "distribution Z"
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   511
  let ?M = "X ` space M \<times> Y ` space M \<times> Z ` space M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   512
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   513
  have split_beta: "\<And>f. split f = (\<lambda>x. f (fst x) (snd x))" by (simp add: expand_fun_eq)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   514
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   515
  have "- (\<Sum>(x, y, z) \<in> ?M. ?dXYZ {(x, y, z)} *
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   516
    log b (?dXYZ {(x, y, z)} / (?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z})))
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   517
    \<le> log b (\<Sum>(x, y, z) \<in> ?M. ?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z})"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   518
    unfolding split_beta
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   519
  proof (rule log_setsum_divide)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   520
    show "?M \<noteq> {}" using not_empty by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   521
    show "1 < b" using b_gt_1 .
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   522
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   523
    fix x assume "x \<in> ?M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   524
    show "0 \<le> ?dXYZ {(fst x, fst (snd x), snd (snd x))}" using positive_distribution .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   525
    show "0 \<le> ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   526
      by (auto intro!: mult_nonneg_nonneg positive_distribution simp: zero_le_divide_iff)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   527
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   528
    assume *: "0 < ?dXYZ {(fst x, fst (snd x), snd (snd x))}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   529
    thus "0 < ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   530
      by (auto intro!: divide_pos_pos mult_pos_pos
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   531
           intro: distribution_order(6) distribution_mono_gt_0)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   532
  qed (simp_all add: setsum_cartesian_product' sum_over_space_distrib setsum_distribution finite_space)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   533
  also have "(\<Sum>(x, y, z) \<in> ?M. ?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z}) = (\<Sum>z\<in>Z`space M. ?dZ {z})"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   534
    apply (simp add: setsum_cartesian_product')
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   535
    apply (subst setsum_commute)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   536
    apply (subst (2) setsum_commute)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   537
    by (auto simp: setsum_divide_distrib[symmetric] setsum_product[symmetric] setsum_distribution
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   538
          intro!: setsum_cong)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   539
  finally show ?thesis
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   540
    unfolding conditional_mutual_information_eq sum_over_space_distrib by simp
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   541
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   542
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   543
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   544
definition (in prob_space)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   545
  "conditional_entropy b S T X Y = conditional_mutual_information b S S T X X Y"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   546
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   547
abbreviation (in finite_information_space)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   548
  finite_conditional_entropy ("\<H>'(_ | _')") where
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   549
  "\<H>(X | Y) \<equiv> conditional_entropy b
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   550
    \<lparr> space = X`space M, sets = Pow (X`space M) \<rparr>
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   551
    \<lparr> space = Y`space M, sets = Pow (Y`space M) \<rparr> X Y"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   552
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   553
lemma (in finite_information_space) conditional_entropy_positive:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   554
  "0 \<le> \<H>(X | Y)" unfolding conditional_entropy_def using conditional_mutual_information_positive .
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   555
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   556
lemma (in finite_information_space) conditional_entropy_eq:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   557
  "\<H>(X | Z) =
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   558
     - (\<Sum>(x, z)\<in>X ` space M \<times> Z ` space M.
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   559
         joint_distribution X Z {(x, z)} *
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   560
         log b (joint_distribution X Z {(x, z)} / distribution Z {z}))"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   561
proof -
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   562
  have *: "\<And>x y z. (\<lambda>x. (X x, X x, Z x)) -` {(x, y, z)} = (if x = y then (\<lambda>x. (X x, Z x)) -` {(x, z)} else {})" by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   563
  show ?thesis
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   564
    unfolding conditional_mutual_information_eq_sum
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   565
      conditional_entropy_def distribution_def *
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   566
    by (auto intro!: setsum_0')
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   567
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   568
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   569
lemma (in finite_information_space) mutual_information_eq_entropy_conditional_entropy:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   570
  "\<I>(X ; Z) = \<H>(X) - \<H>(X | Z)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   571
  unfolding mutual_information_eq entropy_eq conditional_entropy_eq
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   572
  using finite_space
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   573
  by (auto simp add: setsum_addf setsum_subtractf setsum_cartesian_product'
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   574
      setsum_left_distrib[symmetric] setsum_addf setsum_distribution)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   575
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   576
lemma (in finite_information_space) conditional_entropy_less_eq_entropy:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   577
  "\<H>(X | Z) \<le> \<H>(X)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   578
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   579
  have "\<I>(X ; Z) = \<H>(X) - \<H>(X | Z)" using mutual_information_eq_entropy_conditional_entropy .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   580
  with mutual_information_positive[of X Z] entropy_positive[of X]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   581
  show ?thesis by auto
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   582
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   583
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   584
(* -------------Entropy of a RV with a certain event is zero---------------- *)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   585
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   586
lemma (in finite_information_space) finite_entropy_certainty_eq_0:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   587
  assumes "x \<in> X ` space M" and "distribution X {x} = 1"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   588
  shows "\<H>(X) = 0"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   589
proof -
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   590
  interpret X: finite_prob_space "\<lparr> space = X ` space M,
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   591
    sets = Pow (X ` space M),
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   592
    measure = distribution X\<rparr>" by (rule finite_prob_space_of_images)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   593
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   594
  have "distribution X (X ` space M - {x}) = distribution X (X ` space M) - distribution X {x}"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   595
    using X.measure_compl[of "{x}"] assms by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   596
  also have "\<dots> = 0" using X.prob_space assms by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   597
  finally have X0: "distribution X (X ` space M - {x}) = 0" by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   598
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   599
  { fix y assume asm: "y \<noteq> x" "y \<in> X ` space M"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   600
    hence "{y} \<subseteq> X ` space M - {x}" by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   601
    from X.measure_mono[OF this] X0 X.positive[of "{y}"] asm
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   602
    have "distribution X {y} = 0" by auto }
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   603
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   604
  hence fi: "\<And> y. y \<in> X ` space M \<Longrightarrow> distribution X {y} = (if x = y then 1 else 0)"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   605
    using assms by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   606
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   607
  have y: "\<And>y. (if x = y then 1 else 0) * log b (if x = y then 1 else 0) = 0" by simp
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   608
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   609
  show ?thesis unfolding entropy_eq by (auto simp: y fi)
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   610
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   611
(* --------------- upper bound on entropy for a rv ------------------------- *)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   612
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   613
lemma (in finite_information_space) finite_entropy_le_card:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   614
  "\<H>(X) \<le> log b (real (card (X ` space M \<inter> {x . distribution X {x} \<noteq> 0})))"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   615
proof -
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   616
  interpret X: finite_prob_space "\<lparr>space = X ` space M,
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   617
                                    sets = Pow (X ` space M),
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   618
                                 measure = distribution X\<rparr>"
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   619
    using finite_prob_space_of_images by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   620
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   621
  have triv: "\<And> x. (if distribution X {x} \<noteq> 0 then distribution X {x} else 0) = distribution X {x}"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   622
    by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   623
  hence sum1: "(\<Sum> x \<in> X ` space M \<inter> {y. distribution X {y} \<noteq> 0}. distribution X {x}) = 1"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   624
    using X.measure_finitely_additive''[of "X ` space M" "\<lambda> x. {x}", simplified]
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   625
      sets_eq_Pow inj_singleton[unfolded inj_on_def, rule_format]
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   626
    unfolding disjoint_family_on_def  X.prob_space[symmetric]
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   627
    using finite_imageI[OF finite_space, of X] by (auto simp add:triv setsum_restrict_set)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   628
  have pos: "\<And> x. x \<in> X ` space M \<inter> {y. distribution X {y} \<noteq> 0} \<Longrightarrow> inverse (distribution X {x}) > 0"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   629
    using X.positive sets_eq_Pow unfolding inverse_positive_iff_positive less_le by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   630
  { assume asm: "X ` space M \<inter> {y. distribution X {y} \<noteq> 0} = {}" 
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   631
    { fix x assume "x \<in> X ` space M"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   632
      hence "distribution X {x} = 0" using asm by blast }
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   633
    hence A: "(\<Sum> x \<in> X ` space M. distribution X {x}) = 0" by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   634
    have B: "(\<Sum> x \<in> X ` space M. distribution X {x})
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   635
      \<ge> (\<Sum> x \<in> X ` space M \<inter> {y. distribution X {y} \<noteq> 0}. distribution X {x})"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   636
      using finite_imageI[OF finite_space, of X]
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   637
      by (subst setsum_mono2) auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   638
    from A B have "False" using sum1 by auto } note not_empty = this
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   639
  { fix x assume asm: "x \<in> X ` space M"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   640
    have "- distribution X {x} * log b (distribution X {x})
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   641
       = - (if distribution X {x} \<noteq> 0 
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   642
            then distribution X {x} * log b (distribution X {x})
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   643
            else 0)"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   644
      by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   645
    also have "\<dots> = (if distribution X {x} \<noteq> 0 
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   646
          then distribution X {x} * - log b (distribution X {x})
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   647
          else 0)"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   648
      by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   649
    also have "\<dots> = (if distribution X {x} \<noteq> 0
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   650
                    then distribution X {x} * log b (inverse (distribution X {x}))
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   651
                    else 0)"
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   652
      using log_inverse b_gt_1 X.positive[of "{x}"] asm by auto
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   653
    finally have "- distribution X {x} * log b (distribution X {x})
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   654
                 = (if distribution X {x} \<noteq> 0 
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   655
                    then distribution X {x} * log b (inverse (distribution X {x}))
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   656
                    else 0)"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   657
      by auto } note log_inv = this
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   658
  have "- (\<Sum> x \<in> X ` space M. distribution X {x} * log b (distribution X {x}))
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   659
       = (\<Sum> x \<in> X ` space M. (if distribution X {x} \<noteq> 0 
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   660
          then distribution X {x} * log b (inverse (distribution X {x}))
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   661
          else 0))"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   662
    unfolding setsum_negf[symmetric] using log_inv by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   663
  also have "\<dots> = (\<Sum> x \<in> X ` space M \<inter> {y. distribution X {y} \<noteq> 0}.
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   664
                          distribution X {x} * log b (inverse (distribution X {x})))"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   665
    unfolding setsum_restrict_set[OF finite_imageI[OF finite_space, of X]] by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   666
  also have "\<dots> \<le> log b (\<Sum> x \<in> X ` space M \<inter> {y. distribution X {y} \<noteq> 0}.
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   667
                          distribution X {x} * (inverse (distribution X {x})))"
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   668
    apply (subst log_setsum[OF _ _ b_gt_1 sum1, 
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   669
     unfolded greaterThan_iff, OF _ _ _]) using pos sets_eq_Pow
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   670
      X.finite_space assms X.positive not_empty by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   671
  also have "\<dots> = log b (\<Sum> x \<in> X ` space M \<inter> {y. distribution X {y} \<noteq> 0}. 1)"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   672
    by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   673
  also have "\<dots> \<le> log b (real_of_nat (card (X ` space M \<inter> {y. distribution X {y} \<noteq> 0})))"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   674
    by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   675
  finally have "- (\<Sum>x\<in>X ` space M. distribution X {x} * log b (distribution X {x}))
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   676
               \<le> log b (real_of_nat (card (X ` space M \<inter> {y. distribution X {y} \<noteq> 0})))" by simp
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   677
  thus ?thesis unfolding entropy_eq real_eq_of_nat by auto
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   678
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   679
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   680
(* --------------- entropy is maximal for a uniform rv --------------------- *)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   681
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   682
lemma (in finite_prob_space) uniform_prob:
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   683
  assumes "x \<in> space M"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   684
  assumes "\<And> x y. \<lbrakk>x \<in> space M ; y \<in> space M\<rbrakk> \<Longrightarrow> prob {x} = prob {y}"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   685
  shows "prob {x} = 1 / real (card (space M))"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   686
proof -
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   687
  have prob_x: "\<And> y. y \<in> space M \<Longrightarrow> prob {y} = prob {x}"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   688
    using assms(2)[OF _ `x \<in> space M`] by blast
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   689
  have "1 = prob (space M)"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   690
    using prob_space by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   691
  also have "\<dots> = (\<Sum> x \<in> space M. prob {x})"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   692
    using measure_finitely_additive''[of "space M" "\<lambda> x. {x}", simplified]
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   693
      sets_eq_Pow inj_singleton[unfolded inj_on_def, rule_format]
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   694
      finite_space unfolding disjoint_family_on_def  prob_space[symmetric]
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   695
    by (auto simp add:setsum_restrict_set)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   696
  also have "\<dots> = (\<Sum> y \<in> space M. prob {x})"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   697
    using prob_x by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   698
  also have "\<dots> = real_of_nat (card (space M)) * prob {x}" by simp
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   699
  finally have one: "1 = real (card (space M)) * prob {x}"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   700
    using real_eq_of_nat by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   701
  hence two: "real (card (space M)) \<noteq> 0" by fastsimp 
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   702
  from one have three: "prob {x} \<noteq> 0" by fastsimp
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   703
  thus ?thesis using one two three divide_cancel_right
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   704
    by (auto simp:field_simps)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   705
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   706
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   707
lemma (in finite_information_space) finite_entropy_uniform_max:
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   708
  assumes "\<And>x y. \<lbrakk> x \<in> X ` space M ; y \<in> X ` space M \<rbrakk> \<Longrightarrow> distribution X {x} = distribution X {y}"
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   709
  shows "\<H>(X) = log b (real (card (X ` space M)))"
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   710
proof -
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   711
  interpret X: finite_prob_space "\<lparr>space = X ` space M,
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   712
                                    sets = Pow (X ` space M),
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   713
                                 measure = distribution X\<rparr>"
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   714
    using finite_prob_space_of_images by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   715
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   716
  { fix x assume xasm: "x \<in> X ` space M"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   717
    hence card_gt0: "real (card (X ` space M)) > 0"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   718
      using card_gt_0_iff X.finite_space by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   719
    from xasm have "\<And> y. y \<in> X ` space M \<Longrightarrow> distribution X {y} = distribution X {x}"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   720
      using assms by blast
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   721
    hence "- (\<Sum>x\<in>X ` space M. distribution X {x} * log b (distribution X {x}))
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   722
         = - real (card (X ` space M)) * distribution X {x} * log b (distribution X {x})"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   723
      unfolding real_eq_of_nat by auto
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   724
    also have "\<dots> = - real (card (X ` space M)) * (1 / real (card (X ` space M))) * log b (1 / real (card (X ` space M)))"
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   725
      by (auto simp: X.uniform_prob[simplified, OF xasm assms])
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   726
    also have "\<dots> = log b (real (card (X ` space M)))"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   727
      unfolding inverse_eq_divide[symmetric]
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   728
      using card_gt0 log_inverse b_gt_1
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   729
      by (auto simp add:field_simps card_gt0)
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   730
    finally have ?thesis
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   731
      unfolding entropy_eq by auto }
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   732
  moreover
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   733
  { assume "X ` space M = {}"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   734
    hence "distribution X (X ` space M) = 0"
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   735
      using X.empty_measure by simp
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   736
    hence "False" using X.prob_space by auto }
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   737
  ultimately show ?thesis by auto
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   738
qed
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   739
36624
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   740
definition "subvimage A f g \<longleftrightarrow> (\<forall>x \<in> A. f -` {f x} \<inter> A \<subseteq> g -` {g x} \<inter> A)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   741
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   742
lemma subvimageI:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   743
  assumes "\<And>x y. \<lbrakk> x \<in> A ; y \<in> A ; f x = f y \<rbrakk> \<Longrightarrow> g x = g y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   744
  shows "subvimage A f g"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   745
  using assms unfolding subvimage_def by blast
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   746
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   747
lemma subvimageE[consumes 1]:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   748
  assumes "subvimage A f g"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   749
  obtains "\<And>x y. \<lbrakk> x \<in> A ; y \<in> A ; f x = f y \<rbrakk> \<Longrightarrow> g x = g y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   750
  using assms unfolding subvimage_def by blast
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   751
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   752
lemma subvimageD:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   753
  "\<lbrakk> subvimage A f g ; x \<in> A ; y \<in> A ; f x = f y \<rbrakk> \<Longrightarrow> g x = g y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   754
  using assms unfolding subvimage_def by blast
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   755
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   756
lemma subvimage_subset:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   757
  "\<lbrakk> subvimage B f g ; A \<subseteq> B \<rbrakk> \<Longrightarrow> subvimage A f g"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   758
  unfolding subvimage_def by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   759
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   760
lemma subvimage_idem[intro]: "subvimage A g g"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   761
  by (safe intro!: subvimageI)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   762
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   763
lemma subvimage_comp_finer[intro]:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   764
  assumes svi: "subvimage A g h"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   765
  shows "subvimage A g (f \<circ> h)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   766
proof (rule subvimageI, simp)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   767
  fix x y assume "x \<in> A" "y \<in> A" "g x = g y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   768
  from svi[THEN subvimageD, OF this]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   769
  show "f (h x) = f (h y)" by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   770
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   771
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   772
lemma subvimage_comp_gran:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   773
  assumes svi: "subvimage A g h"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   774
  assumes inj: "inj_on f (g ` A)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   775
  shows "subvimage A (f \<circ> g) h"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   776
  by (rule subvimageI) (auto intro!: subvimageD[OF svi] simp: inj_on_iff[OF inj])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   777
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   778
lemma subvimage_comp:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   779
  assumes svi: "subvimage (f ` A) g h"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   780
  shows "subvimage A (g \<circ> f) (h \<circ> f)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   781
  by (rule subvimageI) (auto intro!: svi[THEN subvimageD])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   782
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   783
lemma subvimage_trans:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   784
  assumes fg: "subvimage A f g"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   785
  assumes gh: "subvimage A g h"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   786
  shows "subvimage A f h"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   787
  by (rule subvimageI) (auto intro!: fg[THEN subvimageD] gh[THEN subvimageD])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   788
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   789
lemma subvimage_translator:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   790
  assumes svi: "subvimage A f g"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   791
  shows "\<exists>h. \<forall>x \<in> A. h (f x)  = g x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   792
proof (safe intro!: exI[of _ "\<lambda>x. (THE z. z \<in> (g ` (f -` {x} \<inter> A)))"])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   793
  fix x assume "x \<in> A"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   794
  show "(THE x'. x' \<in> (g ` (f -` {f x} \<inter> A))) = g x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   795
    by (rule theI2[of _ "g x"])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   796
      (insert `x \<in> A`, auto intro!: svi[THEN subvimageD])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   797
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   798
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   799
lemma subvimage_translator_image:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   800
  assumes svi: "subvimage A f g"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   801
  shows "\<exists>h. h ` f ` A = g ` A"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   802
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   803
  from subvimage_translator[OF svi]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   804
  obtain h where "\<And>x. x \<in> A \<Longrightarrow> h (f x) = g x" by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   805
  thus ?thesis
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   806
    by (auto intro!: exI[of _ h]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   807
      simp: image_compose[symmetric] comp_def cong: image_cong)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   808
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   809
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   810
lemma subvimage_finite:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   811
  assumes svi: "subvimage A f g" and fin: "finite (f`A)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   812
  shows "finite (g`A)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   813
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   814
  from subvimage_translator_image[OF svi]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   815
  obtain h where "g`A = h`f`A" by fastsimp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   816
  with fin show "finite (g`A)" by simp
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   817
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   818
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   819
lemma subvimage_disj:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   820
  assumes svi: "subvimage A f g"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   821
  shows "f -` {x} \<inter> A \<subseteq> g -` {y} \<inter> A \<or>
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   822
      f -` {x} \<inter> g -` {y} \<inter> A = {}" (is "?sub \<or> ?dist")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   823
proof (rule disjCI)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   824
  assume "\<not> ?dist"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   825
  then obtain z where "z \<in> A" and "x = f z" and "y = g z" by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   826
  thus "?sub" using svi unfolding subvimage_def by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   827
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   828
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   829
lemma setsum_image_split:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   830
  assumes svi: "subvimage A f g" and fin: "finite (f ` A)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   831
  shows "(\<Sum>x\<in>f`A. h x) = (\<Sum>y\<in>g`A. \<Sum>x\<in>f`(g -` {y} \<inter> A). h x)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   832
    (is "?lhs = ?rhs")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   833
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   834
  have "f ` A =
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   835
      snd ` (SIGMA x : g ` A. f ` (g -` {x} \<inter> A))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   836
      (is "_ = snd ` ?SIGMA")
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   837
    unfolding image_split_eq_Sigma[symmetric]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   838
    by (simp add: image_compose[symmetric] comp_def)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   839
  moreover
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   840
  have snd_inj: "inj_on snd ?SIGMA"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   841
    unfolding image_split_eq_Sigma[symmetric]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   842
    by (auto intro!: inj_onI subvimageD[OF svi])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   843
  ultimately
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   844
  have "(\<Sum>x\<in>f`A. h x) = (\<Sum>(x,y)\<in>?SIGMA. h y)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   845
    by (auto simp: setsum_reindex intro: setsum_cong)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   846
  also have "... = ?rhs"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   847
    using subvimage_finite[OF svi fin] fin
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   848
    apply (subst setsum_Sigma[symmetric])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   849
    by (auto intro!: finite_subset[of _ "f`A"])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   850
  finally show ?thesis .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   851
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   852
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   853
lemma (in finite_information_space) entropy_partition:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   854
  assumes svi: "subvimage (space M) X P"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   855
  shows "\<H>(X) = \<H>(P) + \<H>(X|P)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   856
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   857
  have "(\<Sum>x\<in>X ` space M. distribution X {x} * log b (distribution X {x})) =
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   858
    (\<Sum>y\<in>P `space M. \<Sum>x\<in>X ` space M.
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   859
    joint_distribution X P {(x, y)} * log b (joint_distribution X P {(x, y)}))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   860
  proof (subst setsum_image_split[OF svi],
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   861
      safe intro!: finite_imageI finite_space setsum_mono_zero_cong_left imageI)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   862
    fix p x assume in_space: "p \<in> space M" "x \<in> space M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   863
    assume "joint_distribution X P {(X x, P p)} * log b (joint_distribution X P {(X x, P p)}) \<noteq> 0"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   864
    hence "(\<lambda>x. (X x, P x)) -` {(X x, P p)} \<inter> space M \<noteq> {}" by (auto simp: distribution_def)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   865
    with svi[unfolded subvimage_def, rule_format, OF `x \<in> space M`]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   866
    show "x \<in> P -` {P p}" by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   867
  next
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   868
    fix p x assume in_space: "p \<in> space M" "x \<in> space M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   869
    assume "P x = P p"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   870
    from this[symmetric] svi[unfolded subvimage_def, rule_format, OF `x \<in> space M`]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   871
    have "X -` {X x} \<inter> space M \<subseteq> P -` {P p} \<inter> space M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   872
      by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   873
    hence "(\<lambda>x. (X x, P x)) -` {(X x, P p)} \<inter> space M = X -` {X x} \<inter> space M"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   874
      by auto
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   875
    thus "distribution X {X x} * log b (distribution X {X x}) =
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   876
          joint_distribution X P {(X x, P p)} *
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   877
          log b (joint_distribution X P {(X x, P p)})"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   878
      by (auto simp: distribution_def)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   879
  qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   880
  thus ?thesis
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   881
  unfolding entropy_eq conditional_entropy_eq
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   882
    by (simp add: setsum_cartesian_product' setsum_subtractf setsum_distribution
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   883
      setsum_left_distrib[symmetric] setsum_commute[where B="P`space M"])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   884
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   885
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   886
corollary (in finite_information_space) entropy_data_processing:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   887
  "\<H>(f \<circ> X) \<le> \<H>(X)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   888
  by (subst (2) entropy_partition[of _ "f \<circ> X"]) (auto intro: conditional_entropy_positive)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   889
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   890
lemma (in prob_space) distribution_cong:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   891
  assumes "\<And>x. x \<in> space M \<Longrightarrow> X x = Y x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   892
  shows "distribution X = distribution Y"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   893
  unfolding distribution_def expand_fun_eq
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   894
  using assms by (auto intro!: arg_cong[where f=prob])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   895
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   896
lemma (in prob_space) joint_distribution_cong:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   897
  assumes "\<And>x. x \<in> space M \<Longrightarrow> X x = X' x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   898
  assumes "\<And>x. x \<in> space M \<Longrightarrow> Y x = Y' x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   899
  shows "joint_distribution X Y = joint_distribution X' Y'"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   900
  unfolding distribution_def expand_fun_eq
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   901
  using assms by (auto intro!: arg_cong[where f=prob])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   902
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   903
lemma image_cong:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   904
  "\<lbrakk> \<And>x. x \<in> S \<Longrightarrow> X x = X' x \<rbrakk> \<Longrightarrow> X ` S = X' ` S"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   905
  by (auto intro!: image_eqI)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   906
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   907
lemma (in finite_information_space) mutual_information_cong:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   908
  assumes X: "\<And>x. x \<in> space M \<Longrightarrow> X x = X' x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   909
  assumes Y: "\<And>x. x \<in> space M \<Longrightarrow> Y x = Y' x"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   910
  shows "\<I>(X ; Y) = \<I>(X' ; Y')"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   911
proof -
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   912
  have "X ` space M = X' ` space M" using X by (rule image_cong)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   913
  moreover have "Y ` space M = Y' ` space M" using Y by (rule image_cong)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   914
  ultimately show ?thesis
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   915
  unfolding mutual_information_eq
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   916
    using
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   917
      assms[THEN distribution_cong]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   918
      joint_distribution_cong[OF assms]
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   919
    by (auto intro!: setsum_cong)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   920
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   921
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   922
corollary (in finite_information_space) entropy_of_inj:
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   923
  assumes "inj_on f (X`space M)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   924
  shows "\<H>(f \<circ> X) = \<H>(X)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   925
proof (rule antisym)
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   926
  show "\<H>(f \<circ> X) \<le> \<H>(X)" using entropy_data_processing .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   927
next
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   928
  have "\<H>(X) = \<H>(the_inv_into (X`space M) f \<circ> (f \<circ> X))"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   929
    by (auto intro!: mutual_information_cong simp: entropy_def the_inv_into_f_f[OF assms])
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   930
  also have "... \<le> \<H>(f \<circ> X)"
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   931
    using entropy_data_processing .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   932
  finally show "\<H>(X) \<le> \<H>(f \<circ> X)" .
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   933
qed
25153c08655e Cleanup information theory
hoelzl
parents: 36623
diff changeset
   934
36080
0d9affa4e73c Added Information theory and Example: dining cryptographers
hoelzl
parents:
diff changeset
   935
end