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