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