src/HOL/Probability/Information.thy
 changeset 41981 cdf7693bbe08 parent 41833 563bea92b2c0 child 42067 66c8281349ec
```     1.1 --- a/src/HOL/Probability/Information.thy	Mon Mar 14 14:37:47 2011 +0100
1.2 +++ b/src/HOL/Probability/Information.thy	Mon Mar 14 14:37:49 2011 +0100
1.3 @@ -2,9 +2,12 @@
1.4  imports
1.5    Probability_Space
1.6    "~~/src/HOL/Library/Convex"
1.7 -  Lebesgue_Measure
1.8  begin
1.9
1.10 +lemma (in prob_space) not_zero_less_distribution[simp]:
1.11 +  "(\<not> 0 < distribution X A) \<longleftrightarrow> distribution X A = 0"
1.12 +  using distribution_positive[of X A] by arith
1.13 +
1.14  lemma log_le: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> x \<le> y \<Longrightarrow> log a x \<le> log a y"
1.15    by (subst log_le_cancel_iff) auto
1.16
1.17 @@ -238,7 +241,7 @@
1.18    have ms: "measure_space (M\<lparr>measure := \<nu>\<rparr>)" by default
1.19    show "(\<Sum>x \<in> space M. log b (real (RN_deriv M \<nu> x)) * real (\<nu> {x})) = ?sum"
1.20      using RN_deriv_finite_measure[OF ms ac]
1.21 -    by (auto intro!: setsum_cong simp: field_simps real_of_pextreal_mult[symmetric])
1.22 +    by (auto intro!: setsum_cong simp: field_simps)
1.23  qed
1.24
1.25  lemma (in finite_prob_space) KL_divergence_positive_finite:
1.26 @@ -254,7 +257,8 @@
1.27    proof (subst KL_divergence_eq_finite[OF ms ac], safe intro!: log_setsum_divide not_empty)
1.28      show "finite (space M)" using finite_space by simp
1.29      show "1 < b" by fact
1.30 -    show "(\<Sum>x\<in>space M. real (\<nu> {x})) = 1" using v.finite_sum_over_space_eq_1 by simp
1.31 +    show "(\<Sum>x\<in>space M. real (\<nu> {x})) = 1"
1.32 +      using v.finite_sum_over_space_eq_1 by (simp add: v.\<mu>'_def)
1.33
1.34      fix x assume "x \<in> space M"
1.35      then have x: "{x} \<in> sets M" unfolding sets_eq_Pow by auto
1.36 @@ -262,17 +266,19 @@
1.37        then have "\<nu> {x} \<noteq> 0" by auto
1.38        then have "\<mu> {x} \<noteq> 0"
1.39          using ac[unfolded absolutely_continuous_def, THEN bspec, of "{x}"] x by auto
1.40 -      thus "0 < prob {x}" using finite_measure[of "{x}"] x by auto }
1.41 -  qed auto
1.42 -  thus "0 \<le> KL_divergence b M \<nu>" using finite_sum_over_space_eq_1 by simp
1.43 +      thus "0 < real (\<mu> {x})" using real_measure[OF x] by auto }
1.44 +    show "0 \<le> real (\<mu> {x})" "0 \<le> real (\<nu> {x})"
1.45 +      using real_measure[OF x] v.real_measure[of "{x}"] x by auto
1.46 +  qed
1.47 +  thus "0 \<le> KL_divergence b M \<nu>" using finite_sum_over_space_eq_1 by (simp add: \<mu>'_def)
1.48  qed
1.49
1.50  subsection {* Mutual Information *}
1.51
1.52  definition (in prob_space)
1.53    "mutual_information b S T X Y =
1.54 -    KL_divergence b (S\<lparr>measure := distribution X\<rparr> \<Otimes>\<^isub>M T\<lparr>measure := distribution Y\<rparr>)
1.55 -      (joint_distribution X Y)"
1.56 +    KL_divergence b (S\<lparr>measure := extreal\<circ>distribution X\<rparr> \<Otimes>\<^isub>M T\<lparr>measure := extreal\<circ>distribution Y\<rparr>)
1.57 +      (extreal\<circ>joint_distribution X Y)"
1.58
1.59  definition (in prob_space)
1.60    "entropy b s X = mutual_information b s s X X"
1.61 @@ -280,38 +286,33 @@
1.62  abbreviation (in information_space)
1.63    mutual_information_Pow ("\<I>'(_ ; _')") where
1.64    "\<I>(X ; Y) \<equiv> mutual_information b
1.65 -    \<lparr> space = X`space M, sets = Pow (X`space M), measure = distribution X \<rparr>
1.66 -    \<lparr> space = Y`space M, sets = Pow (Y`space M), measure = distribution Y \<rparr> X Y"
1.67 +    \<lparr> space = X`space M, sets = Pow (X`space M), measure = extreal\<circ>distribution X \<rparr>
1.68 +    \<lparr> space = Y`space M, sets = Pow (Y`space M), measure = extreal\<circ>distribution Y \<rparr> X Y"
1.69
1.70  lemma (in prob_space) finite_variables_absolutely_continuous:
1.71    assumes X: "finite_random_variable S X" and Y: "finite_random_variable T Y"
1.72    shows "measure_space.absolutely_continuous
1.73 -    (S\<lparr>measure := distribution X\<rparr> \<Otimes>\<^isub>M T\<lparr>measure := distribution Y\<rparr>)
1.74 -    (joint_distribution X Y)"
1.75 +    (S\<lparr>measure := extreal\<circ>distribution X\<rparr> \<Otimes>\<^isub>M T\<lparr>measure := extreal\<circ>distribution Y\<rparr>)
1.76 +    (extreal\<circ>joint_distribution X Y)"
1.77  proof -
1.78 -  interpret X: finite_prob_space "S\<lparr>measure := distribution X\<rparr>"
1.79 +  interpret X: finite_prob_space "S\<lparr>measure := extreal\<circ>distribution X\<rparr>"
1.80      using X by (rule distribution_finite_prob_space)
1.81 -  interpret Y: finite_prob_space "T\<lparr>measure := distribution Y\<rparr>"
1.82 +  interpret Y: finite_prob_space "T\<lparr>measure := extreal\<circ>distribution Y\<rparr>"
1.83      using Y by (rule distribution_finite_prob_space)
1.84    interpret XY: pair_finite_prob_space
1.85 -    "S\<lparr>measure := distribution X\<rparr>" "T\<lparr> measure := distribution Y\<rparr>" by default
1.86 -  interpret P: finite_prob_space "XY.P\<lparr> measure := joint_distribution X Y\<rparr>"
1.87 +    "S\<lparr>measure := extreal\<circ>distribution X\<rparr>" "T\<lparr> measure := extreal\<circ>distribution Y\<rparr>" by default
1.88 +  interpret P: finite_prob_space "XY.P\<lparr> measure := extreal\<circ>joint_distribution X Y\<rparr>"
1.89      using assms by (auto intro!: joint_distribution_finite_prob_space)
1.90    note rv = assms[THEN finite_random_variableD]
1.91 -  show "XY.absolutely_continuous (joint_distribution X Y)"
1.92 +  show "XY.absolutely_continuous (extreal\<circ>joint_distribution X Y)"
1.93    proof (rule XY.absolutely_continuousI)
1.94 -    show "finite_measure_space (XY.P\<lparr> measure := joint_distribution X Y\<rparr>)" by default
1.95 +    show "finite_measure_space (XY.P\<lparr> measure := extreal\<circ>joint_distribution X Y\<rparr>)" by default
1.96      fix x assume "x \<in> space XY.P" and "XY.\<mu> {x} = 0"
1.97 -    then obtain a b where "(a, b) = x" and "a \<in> space S" "b \<in> space T"
1.98 -      and distr: "distribution X {a} * distribution Y {b} = 0"
1.99 +    then obtain a b where "x = (a, b)"
1.100 +      and "distribution X {a} = 0 \<or> distribution Y {b} = 0"
1.101        by (cases x) (auto simp: space_pair_measure)
1.102 -    with X.sets_eq_Pow Y.sets_eq_Pow
1.103 -      joint_distribution_Times_le_fst[OF rv, of "{a}" "{b}"]
1.104 -      joint_distribution_Times_le_snd[OF rv, of "{a}" "{b}"]
1.105 -    have "joint_distribution X Y {x} \<le> distribution Y {b}"
1.106 -         "joint_distribution X Y {x} \<le> distribution X {a}"
1.107 -      by (auto simp del: X.sets_eq_Pow Y.sets_eq_Pow)
1.108 -    with distr show "joint_distribution X Y {x} = 0" by auto
1.109 +    with finite_distribution_order(5,6)[OF X Y]
1.110 +    show "(extreal \<circ> joint_distribution X Y) {x} = 0" by auto
1.111    qed
1.112  qed
1.113
1.114 @@ -320,28 +321,28 @@
1.115    assumes MY: "finite_random_variable MY Y"
1.116    shows mutual_information_generic_eq:
1.117      "mutual_information b MX MY X Y = (\<Sum> (x,y) \<in> space MX \<times> space MY.
1.118 -      real (joint_distribution X Y {(x,y)}) *
1.119 -      log b (real (joint_distribution X Y {(x,y)}) /
1.120 -      (real (distribution X {x}) * real (distribution Y {y}))))"
1.121 +      joint_distribution X Y {(x,y)} *
1.122 +      log b (joint_distribution X Y {(x,y)} /
1.123 +      (distribution X {x} * distribution Y {y})))"
1.124      (is ?sum)
1.125    and mutual_information_positive_generic:
1.126       "0 \<le> mutual_information b MX MY X Y" (is ?positive)
1.127  proof -
1.128 -  interpret X: finite_prob_space "MX\<lparr>measure := distribution X\<rparr>"
1.129 +  interpret X: finite_prob_space "MX\<lparr>measure := extreal\<circ>distribution X\<rparr>"
1.130      using MX by (rule distribution_finite_prob_space)
1.131 -  interpret Y: finite_prob_space "MY\<lparr>measure := distribution Y\<rparr>"
1.132 +  interpret Y: finite_prob_space "MY\<lparr>measure := extreal\<circ>distribution Y\<rparr>"
1.133      using MY by (rule distribution_finite_prob_space)
1.134 -  interpret XY: pair_finite_prob_space "MX\<lparr>measure := distribution X\<rparr>" "MY\<lparr>measure := distribution Y\<rparr>" by default
1.135 -  interpret P: finite_prob_space "XY.P\<lparr>measure := joint_distribution X Y\<rparr>"
1.136 +  interpret XY: pair_finite_prob_space "MX\<lparr>measure := extreal\<circ>distribution X\<rparr>" "MY\<lparr>measure := extreal\<circ>distribution Y\<rparr>" by default
1.137 +  interpret P: finite_prob_space "XY.P\<lparr>measure := extreal\<circ>joint_distribution X Y\<rparr>"
1.138      using assms by (auto intro!: joint_distribution_finite_prob_space)
1.139
1.140 -  have P_ms: "finite_measure_space (XY.P\<lparr>measure :=joint_distribution X Y\<rparr>)" by default
1.141 -  have P_ps: "finite_prob_space (XY.P\<lparr>measure := joint_distribution X Y\<rparr>)" by default
1.142 +  have P_ms: "finite_measure_space (XY.P\<lparr>measure := extreal\<circ>joint_distribution X Y\<rparr>)" by default
1.143 +  have P_ps: "finite_prob_space (XY.P\<lparr>measure := extreal\<circ>joint_distribution X Y\<rparr>)" by default
1.144
1.145    show ?sum
1.146      unfolding Let_def mutual_information_def
1.147      by (subst XY.KL_divergence_eq_finite[OF P_ms finite_variables_absolutely_continuous[OF MX MY]])
1.148 -       (auto simp add: space_pair_measure setsum_cartesian_product' real_of_pextreal_mult[symmetric])
1.149 +       (auto simp add: space_pair_measure setsum_cartesian_product')
1.150
1.151    show ?positive
1.152      using XY.KL_divergence_positive_finite[OF P_ps finite_variables_absolutely_continuous[OF MX MY] b_gt_1]
1.153 @@ -351,10 +352,10 @@
1.154  lemma (in information_space) mutual_information_commute_generic:
1.155    assumes X: "random_variable S X" and Y: "random_variable T Y"
1.156    assumes ac: "measure_space.absolutely_continuous
1.157 -    (S\<lparr>measure := distribution X\<rparr> \<Otimes>\<^isub>M T\<lparr>measure := distribution Y\<rparr>) (joint_distribution X Y)"
1.158 +    (S\<lparr>measure := extreal\<circ>distribution X\<rparr> \<Otimes>\<^isub>M T\<lparr>measure := extreal\<circ>distribution Y\<rparr>) (extreal\<circ>joint_distribution X Y)"
1.159    shows "mutual_information b S T X Y = mutual_information b T S Y X"
1.160  proof -
1.161 -  let ?S = "S\<lparr>measure := distribution X\<rparr>" and ?T = "T\<lparr>measure := distribution Y\<rparr>"
1.162 +  let ?S = "S\<lparr>measure := extreal\<circ>distribution X\<rparr>" and ?T = "T\<lparr>measure := extreal\<circ>distribution Y\<rparr>"
1.163    interpret S: prob_space ?S using X by (rule distribution_prob_space)
1.164    interpret T: prob_space ?T using Y by (rule distribution_prob_space)
1.165    interpret P: pair_prob_space ?S ?T ..
1.166 @@ -363,13 +364,13 @@
1.167      unfolding mutual_information_def
1.168    proof (intro Q.KL_divergence_vimage[OF Q.measure_preserving_swap _ _ _ _ ac b_gt_1])
1.169      show "(\<lambda>(x,y). (y,x)) \<in> measure_preserving
1.170 -      (P.P \<lparr> measure := joint_distribution X Y\<rparr>) (Q.P \<lparr> measure := joint_distribution Y X\<rparr>)"
1.171 +      (P.P \<lparr> measure := extreal\<circ>joint_distribution X Y\<rparr>) (Q.P \<lparr> measure := extreal\<circ>joint_distribution Y X\<rparr>)"
1.172        using X Y unfolding measurable_def
1.173        unfolding measure_preserving_def using P.pair_sigma_algebra_swap_measurable
1.174 -      by (auto simp add: space_pair_measure distribution_def intro!: arg_cong[where f=\<mu>])
1.175 -    have "prob_space (P.P\<lparr> measure := joint_distribution X Y\<rparr>)"
1.176 +      by (auto simp add: space_pair_measure distribution_def intro!: arg_cong[where f=\<mu>'])
1.177 +    have "prob_space (P.P\<lparr> measure := extreal\<circ>joint_distribution X Y\<rparr>)"
1.178        using X Y by (auto intro!: distribution_prob_space random_variable_pairI)
1.179 -    then show "measure_space (P.P\<lparr> measure := joint_distribution X Y\<rparr>)"
1.180 +    then show "measure_space (P.P\<lparr> measure := extreal\<circ>joint_distribution X Y\<rparr>)"
1.181        unfolding prob_space_def by simp
1.182    qed auto
1.183  qed
1.184 @@ -389,8 +390,8 @@
1.185  lemma (in information_space) mutual_information_eq:
1.186    assumes "simple_function M X" "simple_function M Y"
1.187    shows "\<I>(X;Y) = (\<Sum> (x,y) \<in> X ` space M \<times> Y ` space M.
1.188 -    real (distribution (\<lambda>x. (X x, Y x)) {(x,y)}) * log b (real (distribution (\<lambda>x. (X x, Y x)) {(x,y)}) /
1.189 -                                                   (real (distribution X {x}) * real (distribution Y {y}))))"
1.190 +    distribution (\<lambda>x. (X x, Y x)) {(x,y)} * log b (distribution (\<lambda>x. (X x, Y x)) {(x,y)} /
1.191 +                                                   (distribution X {x} * distribution Y {y})))"
1.192    using assms by (simp add: mutual_information_generic_eq)
1.193
1.194  lemma (in information_space) mutual_information_generic_cong:
1.195 @@ -416,22 +417,27 @@
1.196
1.197  abbreviation (in information_space)
1.198    entropy_Pow ("\<H>'(_')") where
1.199 -  "\<H>(X) \<equiv> entropy b \<lparr> space = X`space M, sets = Pow (X`space M), measure = distribution X \<rparr> X"
1.200 +  "\<H>(X) \<equiv> entropy b \<lparr> space = X`space M, sets = Pow (X`space M), measure = extreal\<circ>distribution X \<rparr> X"
1.201
1.202  lemma (in information_space) entropy_generic_eq:
1.203 +  fixes X :: "'a \<Rightarrow> 'c"
1.204    assumes MX: "finite_random_variable MX X"
1.205 -  shows "entropy b MX X = -(\<Sum> x \<in> space MX. real (distribution X {x}) * log b (real (distribution X {x})))"
1.206 +  shows "entropy b MX X = -(\<Sum> x \<in> space MX. distribution X {x} * log b (distribution X {x}))"
1.207  proof -
1.208 -  interpret MX: finite_prob_space "MX\<lparr>measure := distribution X\<rparr>"
1.209 +  interpret MX: finite_prob_space "MX\<lparr>measure := extreal\<circ>distribution X\<rparr>"
1.210      using MX by (rule distribution_finite_prob_space)
1.211 -  let "?X x" = "real (distribution X {x})"
1.212 -  let "?XX x y" = "real (joint_distribution X X {(x, y)})"
1.213 -  { fix x y
1.214 -    have "(\<lambda>x. (X x, X x)) -` {(x, y)} = (if x = y then X -` {x} else {})" by auto
1.215 +  let "?X x" = "distribution X {x}"
1.216 +  let "?XX x y" = "joint_distribution X X {(x, y)}"
1.217 +
1.218 +  { fix x y :: 'c
1.219 +    { assume "x \<noteq> y"
1.220 +      then have "(\<lambda>x. (X x, X x)) -` {(x,y)} \<inter> space M = {}" by auto
1.221 +      then have "joint_distribution X X {(x, y)} = 0" by (simp add: distribution_def) }
1.222      then have "?XX x y * log b (?XX x y / (?X x * ?X y)) =
1.223          (if x = y then - ?X y * log b (?X y) else 0)"
1.224 -      unfolding distribution_def by (auto simp: log_simps zero_less_mult_iff) }
1.225 +      by (auto simp: log_simps zero_less_mult_iff) }
1.226    note remove_XX = this
1.227 +
1.228    show ?thesis
1.229      unfolding entropy_def mutual_information_generic_eq[OF MX MX]
1.230      unfolding setsum_cartesian_product[symmetric] setsum_negf[symmetric] remove_XX
1.231 @@ -440,7 +446,7 @@
1.232
1.233  lemma (in information_space) entropy_eq:
1.234    assumes "simple_function M X"
1.235 -  shows "\<H>(X) = -(\<Sum> x \<in> X ` space M. real (distribution X {x}) * log b (real (distribution X {x})))"
1.236 +  shows "\<H>(X) = -(\<Sum> x \<in> X ` space M. distribution X {x} * log b (distribution X {x}))"
1.237    using assms by (simp add: entropy_generic_eq)
1.238
1.239  lemma (in information_space) entropy_positive:
1.240 @@ -448,63 +454,77 @@
1.241    unfolding entropy_def by (simp add: mutual_information_positive)
1.242
1.243  lemma (in information_space) entropy_certainty_eq_0:
1.244 -  assumes "simple_function M X" and "x \<in> X ` space M" and "distribution X {x} = 1"
1.245 +  assumes X: "simple_function M X" and "x \<in> X ` space M" and "distribution X {x} = 1"
1.246    shows "\<H>(X) = 0"
1.247  proof -
1.248 -  let ?X = "\<lparr> space = X ` space M, sets = Pow (X ` space M), measure = distribution X\<rparr>"
1.249 +  let ?X = "\<lparr> space = X ` space M, sets = Pow (X ` space M), measure = extreal\<circ>distribution X\<rparr>"
1.250    note simple_function_imp_finite_random_variable[OF `simple_function M X`]
1.251 -  from distribution_finite_prob_space[OF this, of "\<lparr> measure = distribution X \<rparr>"]
1.252 +  from distribution_finite_prob_space[OF this, of "\<lparr> measure = extreal\<circ>distribution X \<rparr>"]
1.253    interpret X: finite_prob_space ?X by simp
1.254    have "distribution X (X ` space M - {x}) = distribution X (X ` space M) - distribution X {x}"
1.255      using X.measure_compl[of "{x}"] assms by auto
1.256    also have "\<dots> = 0" using X.prob_space assms by auto
1.257    finally have X0: "distribution X (X ` space M - {x}) = 0" by auto
1.258 -  { fix y assume asm: "y \<noteq> x" "y \<in> X ` space M"
1.259 -    hence "{y} \<subseteq> X ` space M - {x}" by auto
1.260 -    from X.measure_mono[OF this] X0 asm
1.261 -    have "distribution X {y} = 0" by auto }
1.262 -  hence fi: "\<And> y. y \<in> X ` space M \<Longrightarrow> real (distribution X {y}) = (if x = y then 1 else 0)"
1.263 -    using assms by auto
1.264 +  { fix y assume *: "y \<in> X ` space M"
1.265 +    { assume asm: "y \<noteq> x"
1.266 +      with * have "{y} \<subseteq> X ` space M - {x}" by auto
1.267 +      from X.measure_mono[OF this] X0 asm *
1.268 +      have "distribution X {y} = 0"  by (auto intro: antisym) }
1.269 +    then have "distribution X {y} = (if x = y then 1 else 0)"
1.270 +      using assms by auto }
1.271 +  note fi = this
1.272    have y: "\<And>y. (if x = y then 1 else 0) * log b (if x = y then 1 else 0) = 0" by simp
1.273    show ?thesis unfolding entropy_eq[OF `simple_function M X`] by (auto simp: y fi)
1.274  qed
1.275
1.276  lemma (in information_space) entropy_le_card_not_0:
1.277 -  assumes "simple_function M X"
1.278 -  shows "\<H>(X) \<le> log b (real (card (X ` space M \<inter> {x . distribution X {x} \<noteq> 0})))"
1.279 +  assumes X: "simple_function M X"
1.280 +  shows "\<H>(X) \<le> log b (card (X ` space M \<inter> {x. distribution X {x} \<noteq> 0}))"
1.281  proof -
1.282 -  let "?d x" = "distribution X {x}"
1.283 -  let "?p x" = "real (?d x)"
1.284 +  let "?p x" = "distribution X {x}"
1.285    have "\<H>(X) = (\<Sum>x\<in>X`space M. ?p x * log b (1 / ?p x))"
1.286 -    by (auto intro!: setsum_cong simp: entropy_eq[OF `simple_function M X`] setsum_negf[symmetric] log_simps not_less)
1.287 +    unfolding entropy_eq[OF X] setsum_negf[symmetric]
1.288 +    by (auto intro!: setsum_cong simp: log_simps)
1.289    also have "\<dots> \<le> log b (\<Sum>x\<in>X`space M. ?p x * (1 / ?p x))"
1.290 -    apply (rule log_setsum')
1.291 -    using not_empty b_gt_1 `simple_function M X` sum_over_space_real_distribution
1.292 -    by (auto simp: simple_function_def)
1.293 -  also have "\<dots> = log b (\<Sum>x\<in>X`space M. if ?d x \<noteq> 0 then 1 else 0)"
1.294 -    using distribution_finite[OF `simple_function M X`[THEN simple_function_imp_random_variable], simplified]
1.295 -    by (intro arg_cong[where f="\<lambda>X. log b X"] setsum_cong) (auto simp: real_of_pextreal_eq_0)
1.296 +    using not_empty b_gt_1 `simple_function M X` sum_over_space_real_distribution[OF X]
1.297 +    by (intro log_setsum') (auto simp: simple_function_def)
1.298 +  also have "\<dots> = log b (\<Sum>x\<in>X`space M. if ?p x \<noteq> 0 then 1 else 0)"
1.299 +    by (intro arg_cong[where f="\<lambda>X. log b X"] setsum_cong) auto
1.300    finally show ?thesis
1.301      using `simple_function M X` by (auto simp: setsum_cases real_eq_of_nat simple_function_def)
1.302  qed
1.303
1.304 +lemma (in prob_space) measure'_translate:
1.305 +  assumes X: "random_variable S X" and A: "A \<in> sets S"
1.306 +  shows "finite_measure.\<mu>' (S\<lparr> measure := extreal\<circ>distribution X \<rparr>) A = distribution X A"
1.307 +proof -
1.308 +  interpret S: prob_space "S\<lparr> measure := extreal\<circ>distribution X \<rparr>"
1.309 +    using distribution_prob_space[OF X] .
1.310 +  from A show "S.\<mu>' A = distribution X A"
1.311 +    unfolding S.\<mu>'_def by (simp add: distribution_def_raw \<mu>'_def)
1.312 +qed
1.313 +
1.314  lemma (in information_space) entropy_uniform_max:
1.315 -  assumes "simple_function M X"
1.316 +  assumes X: "simple_function M X"
1.317    assumes "\<And>x y. \<lbrakk> x \<in> X ` space M ; y \<in> X ` space M \<rbrakk> \<Longrightarrow> distribution X {x} = distribution X {y}"
1.318    shows "\<H>(X) = log b (real (card (X ` space M)))"
1.319  proof -
1.320 -  let ?X = "\<lparr> space = X ` space M, sets = Pow (X ` space M), measure = distribution X\<rparr>"
1.321 -  note simple_function_imp_finite_random_variable[OF `simple_function M X`]
1.322 -  from distribution_finite_prob_space[OF this, of "\<lparr> measure = distribution X \<rparr>"]
1.323 +  let ?X = "\<lparr> space = X ` space M, sets = Pow (X ` space M), measure = undefined\<rparr>\<lparr> measure := extreal\<circ>distribution X\<rparr>"
1.324 +  note frv = simple_function_imp_finite_random_variable[OF X]
1.325 +  from distribution_finite_prob_space[OF this, of "\<lparr> measure = extreal\<circ>distribution X \<rparr>"]
1.326    interpret X: finite_prob_space ?X by simp
1.327 +  note rv = finite_random_variableD[OF frv]
1.328    have card_gt0: "0 < card (X ` space M)" unfolding card_gt_0_iff
1.329      using `simple_function M X` not_empty by (auto simp: simple_function_def)
1.330 -  { fix x assume "x \<in> X ` space M"
1.331 -    hence "real (distribution X {x}) = 1 / real (card (X ` space M))"
1.332 -    proof (rule X.uniform_prob[simplified])
1.333 -      fix x y assume "x \<in> X`space M" "y \<in> X`space M"
1.334 -      from assms(2)[OF this] show "real (distribution X {x}) = real (distribution X {y})" by simp
1.335 -    qed }
1.336 +  { fix x assume "x \<in> space ?X"
1.337 +    moreover then have "X.\<mu>' {x} = 1 / card (space ?X)"
1.338 +    proof (rule X.uniform_prob)
1.339 +      fix x y assume "x \<in> space ?X" "y \<in> space ?X"
1.340 +      with assms(2)[of x y] show "X.\<mu>' {x} = X.\<mu>' {y}"
1.341 +        by (subst (1 2) measure'_translate[OF rv]) auto
1.342 +    qed
1.343 +    ultimately have "distribution X {x} = 1 / card (space ?X)"
1.344 +      by (subst (asm) measure'_translate[OF rv]) auto }
1.345    thus ?thesis
1.346      using not_empty X.finite_space b_gt_1 card_gt0
1.347      by (simp add: entropy_eq[OF `simple_function M X`] real_eq_of_nat[symmetric] log_simps)
1.348 @@ -552,8 +572,7 @@
1.349  lemma (in information_space) entropy_eq_cartesian_product:
1.350    assumes "simple_function M X" "simple_function M Y"
1.351    shows "\<H>(\<lambda>x. (X x, Y x)) = -(\<Sum>x\<in>X`space M. \<Sum>y\<in>Y`space M.
1.352 -    real (joint_distribution X Y {(x,y)}) *
1.353 -    log b (real (joint_distribution X Y {(x,y)})))"
1.354 +    joint_distribution X Y {(x,y)} * log b (joint_distribution X Y {(x,y)}))"
1.355  proof -
1.356    have sf: "simple_function M (\<lambda>x. (X x, Y x))"
1.357      using assms by (auto intro: simple_function_Pair)
1.358 @@ -576,9 +595,9 @@
1.359  abbreviation (in information_space)
1.360    conditional_mutual_information_Pow ("\<I>'( _ ; _ | _ ')") where
1.361    "\<I>(X ; Y | Z) \<equiv> conditional_mutual_information b
1.362 -    \<lparr> space = X`space M, sets = Pow (X`space M), measure = distribution X \<rparr>
1.363 -    \<lparr> space = Y`space M, sets = Pow (Y`space M), measure = distribution Y \<rparr>
1.364 -    \<lparr> space = Z`space M, sets = Pow (Z`space M), measure = distribution Z \<rparr>
1.365 +    \<lparr> space = X`space M, sets = Pow (X`space M), measure = extreal\<circ>distribution X \<rparr>
1.366 +    \<lparr> space = Y`space M, sets = Pow (Y`space M), measure = extreal\<circ>distribution Y \<rparr>
1.367 +    \<lparr> space = Z`space M, sets = Pow (Z`space M), measure = extreal\<circ>distribution Z \<rparr>
1.368      X Y Z"
1.369
1.370  lemma (in information_space) conditional_mutual_information_generic_eq:
1.371 @@ -586,58 +605,44 @@
1.372      and MY: "finite_random_variable MY Y"
1.373      and MZ: "finite_random_variable MZ Z"
1.374    shows "conditional_mutual_information b MX MY MZ X Y Z = (\<Sum>(x, y, z) \<in> space MX \<times> space MY \<times> space MZ.
1.375 -             real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) *
1.376 -             log b (real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) /
1.377 -    (real (joint_distribution X Z {(x, z)}) * real (joint_distribution Y Z {(y,z)} / distribution Z {z}))))"
1.378 -  (is "_ = (\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?XZ x z * ?YZdZ y z)))")
1.379 +             distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)} *
1.380 +             log b (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)} /
1.381 +    (joint_distribution X Z {(x, z)} * (joint_distribution Y Z {(y,z)} / distribution Z {z}))))"
1.382 +  (is "_ = (\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?XZ x z * (?YZ y z / ?Z z))))")
1.383  proof -
1.384 -  let ?YZ = "\<lambda>y z. real (joint_distribution Y Z {(y, z)})"
1.385 -  let ?X = "\<lambda>x. real (distribution X {x})"
1.386 -  let ?Z = "\<lambda>z. real (distribution Z {z})"
1.387 -
1.388 -  txt {* This proof is actually quiet easy, however we need to show that the
1.389 -    distributions are finite and the joint distributions are zero when one of
1.390 -    the variables distribution is also zero. *}
1.391 -
1.392 +  let ?X = "\<lambda>x. distribution X {x}"
1.393    note finite_var = MX MY MZ
1.394 -  note random_var = finite_var[THEN finite_random_variableD]
1.395 -
1.396 -  note space_simps = space_pair_measure space_sigma algebra.simps
1.397 -
1.398    note YZ = finite_random_variable_pairI[OF finite_var(2,3)]
1.399 +  note XYZ = finite_random_variable_pairI[OF MX YZ]
1.400    note XZ = finite_random_variable_pairI[OF finite_var(1,3)]
1.401    note ZX = finite_random_variable_pairI[OF finite_var(3,1)]
1.402    note YZX = finite_random_variable_pairI[OF finite_var(2) ZX]
1.403    note order1 =
1.404 -    finite_distribution_order(5,6)[OF finite_var(1) YZ, simplified space_simps]
1.405 -    finite_distribution_order(5,6)[OF finite_var(1,3), simplified space_simps]
1.406 +    finite_distribution_order(5,6)[OF finite_var(1) YZ]
1.407 +    finite_distribution_order(5,6)[OF finite_var(1,3)]
1.408
1.409 +  note random_var = finite_var[THEN finite_random_variableD]
1.410    note finite = finite_var(1) YZ finite_var(3) XZ YZX
1.411 -  note finite[THEN finite_distribution_finite, simplified space_simps, simp]
1.412
1.413    have order2: "\<And>x y z. \<lbrakk>x \<in> space MX; y \<in> space MY; z \<in> space MZ; joint_distribution X Z {(x, z)} = 0\<rbrakk>
1.414            \<Longrightarrow> joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)} = 0"
1.415      unfolding joint_distribution_commute_singleton[of X]
1.416      unfolding joint_distribution_assoc_singleton[symmetric]
1.417      using finite_distribution_order(6)[OF finite_var(2) ZX]
1.418 -    by (auto simp: space_simps)
1.419 +    by auto
1.420
1.421 -  have "(\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?XZ x z * ?YZdZ y z))) =
1.422 +  have "(\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?XZ x z * (?YZ y z / ?Z z)))) =
1.423      (\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * (log b (?XYZ x y z / (?X x * ?YZ y z)) - log b (?XZ x z / (?X x * ?Z z))))"
1.424      (is "(\<Sum>(x, y, z)\<in>?S. ?L x y z) = (\<Sum>(x, y, z)\<in>?S. ?R x y z)")
1.425    proof (safe intro!: setsum_cong)
1.426      fix x y z assume space: "x \<in> space MX" "y \<in> space MY" "z \<in> space MZ"
1.427 -    then have *: "?XYZ x y z / (?XZ x z * ?YZdZ y z) =
1.428 -      (?XYZ x y z / (?X x * ?YZ y z)) / (?XZ x z / (?X x * ?Z z))"
1.429 -      using order1(3)
1.430 -      by (auto simp: real_of_pextreal_mult[symmetric] real_of_pextreal_eq_0)
1.431      show "?L x y z = ?R x y z"
1.432      proof cases
1.433        assume "?XYZ x y z \<noteq> 0"
1.434 -      with space b_gt_1 order1 order2 show ?thesis unfolding *
1.435 -        by (subst log_divide)
1.436 -           (auto simp: zero_less_divide_iff zero_less_real_of_pextreal
1.437 -                       real_of_pextreal_eq_0 zero_less_mult_iff)
1.438 +      with space have "0 < ?X x" "0 < ?Z z" "0 < ?XZ x z" "0 < ?YZ y z" "0 < ?XYZ x y z"
1.439 +        using order1 order2 by (auto simp: less_le)
1.440 +      with b_gt_1 show ?thesis
1.441 +        by (simp add: log_mult log_divide zero_less_mult_iff zero_less_divide_iff)
1.442      qed simp
1.443    qed
1.444    also have "\<dots> = (\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?X x * ?YZ y z))) -
1.445 @@ -649,8 +654,8 @@
1.446                setsum_left_distrib[symmetric]
1.447      unfolding joint_distribution_commute_singleton[of X]
1.448      unfolding joint_distribution_assoc_singleton[symmetric]
1.449 -    using setsum_real_joint_distribution_singleton[OF finite_var(2) ZX, unfolded space_simps]
1.450 -    by (intro setsum_cong refl) simp
1.451 +    using setsum_joint_distribution_singleton[OF finite_var(2) ZX]
1.452 +    by (intro setsum_cong refl) (simp add: space_pair_measure)
1.453    also have "(\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?X x * ?YZ y z))) -
1.454               (\<Sum>(x, z)\<in>space MX \<times> space MZ. ?XZ x z * log b (?XZ x z / (?X x * ?Z z))) =
1.455               conditional_mutual_information b MX MY MZ X Y Z"
1.456 @@ -664,11 +669,11 @@
1.457  lemma (in information_space) conditional_mutual_information_eq:
1.458    assumes "simple_function M X" "simple_function M Y" "simple_function M Z"
1.459    shows "\<I>(X;Y|Z) = (\<Sum>(x, y, z) \<in> X`space M \<times> Y`space M \<times> Z`space M.
1.460 -             real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) *
1.461 -             log b (real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) /
1.462 -    (real (joint_distribution X Z {(x, z)}) * real (joint_distribution Y Z {(y,z)} / distribution Z {z}))))"
1.463 -  using conditional_mutual_information_generic_eq[OF assms[THEN simple_function_imp_finite_random_variable]]
1.464 -  by simp
1.465 +             distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)} *
1.466 +             log b (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)} /
1.467 +    (joint_distribution X Z {(x, z)} * joint_distribution Y Z {(y,z)} / distribution Z {z})))"
1.468 +  by (subst conditional_mutual_information_generic_eq[OF assms[THEN simple_function_imp_finite_random_variable]])
1.469 +     simp
1.470
1.471  lemma (in information_space) conditional_mutual_information_eq_mutual_information:
1.472    assumes X: "simple_function M X" and Y: "simple_function M Y"
1.473 @@ -683,10 +688,10 @@
1.474  qed
1.475
1.476  lemma (in prob_space) distribution_unit[simp]: "distribution (\<lambda>x. ()) {()} = 1"
1.477 -  unfolding distribution_def using measure_space_1 by auto
1.478 +  unfolding distribution_def using prob_space by auto
1.479
1.480  lemma (in prob_space) joint_distribution_unit[simp]: "distribution (\<lambda>x. (X x, ())) {(a, ())} = distribution X {a}"
1.481 -  unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>])
1.482 +  unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>'])
1.483
1.484  lemma (in prob_space) setsum_distribution:
1.485    assumes X: "finite_random_variable MX X" shows "(\<Sum>a\<in>space MX. distribution X {a}) = 1"
1.486 @@ -695,12 +700,13 @@
1.487
1.488  lemma (in prob_space) setsum_real_distribution:
1.489    fixes MX :: "('c, 'd) measure_space_scheme"
1.490 -  assumes X: "finite_random_variable MX X" shows "(\<Sum>a\<in>space MX. real (distribution X {a})) = 1"
1.491 -  using setsum_real_joint_distribution[OF assms, of "\<lparr> space = UNIV, sets = Pow UNIV, measure = undefined \<rparr>" "\<lambda>x. ()" "{()}"]
1.492 -  using sigma_algebra_Pow[of "UNIV::unit set" "\<lparr> measure = undefined \<rparr>"] by simp
1.493 +  assumes X: "finite_random_variable MX X" shows "(\<Sum>a\<in>space MX. distribution X {a}) = 1"
1.494 +  using setsum_joint_distribution[OF assms, of "\<lparr> space = UNIV, sets = Pow UNIV, measure = undefined \<rparr>" "\<lambda>x. ()" "{()}"]
1.495 +  using sigma_algebra_Pow[of "UNIV::unit set" "\<lparr> measure = undefined \<rparr>"]
1.496 +  by auto
1.497
1.498  lemma (in information_space) conditional_mutual_information_generic_positive:
1.499 -  assumes "finite_random_variable MX X" and "finite_random_variable MY Y" and "finite_random_variable MZ Z"
1.500 +  assumes X: "finite_random_variable MX X" and Y: "finite_random_variable MY Y" and Z: "finite_random_variable MZ Z"
1.501    shows "0 \<le> conditional_mutual_information b MX MY MZ X Y Z"
1.502  proof (cases "space MX \<times> space MY \<times> space MZ = {}")
1.503    case True show ?thesis
1.504 @@ -708,43 +714,35 @@
1.505      by simp
1.506  next
1.507    case False
1.508 -  let "?dXYZ A" = "real (distribution (\<lambda>x. (X x, Y x, Z x)) A)"
1.509 -  let "?dXZ A" = "real (joint_distribution X Z A)"
1.510 -  let "?dYZ A" = "real (joint_distribution Y Z A)"
1.511 -  let "?dX A" = "real (distribution X A)"
1.512 -  let "?dZ A" = "real (distribution Z A)"
1.513 +  let ?dXYZ = "distribution (\<lambda>x. (X x, Y x, Z x))"
1.514 +  let ?dXZ = "joint_distribution X Z"
1.515 +  let ?dYZ = "joint_distribution Y Z"
1.516 +  let ?dX = "distribution X"
1.517 +  let ?dZ = "distribution Z"
1.518    let ?M = "space MX \<times> space MY \<times> space MZ"
1.519
1.520 -  have split_beta: "\<And>f. split f = (\<lambda>x. f (fst x) (snd x))" by (simp add: fun_eq_iff)
1.521 -
1.522 -  note space_simps = space_pair_measure space_sigma algebra.simps
1.523 -
1.524 -  note finite_var = assms
1.525 -  note YZ = finite_random_variable_pairI[OF finite_var(2,3)]
1.526 -  note XZ = finite_random_variable_pairI[OF finite_var(1,3)]
1.527 -  note ZX = finite_random_variable_pairI[OF finite_var(3,1)]
1.528 -  note YZ = finite_random_variable_pairI[OF finite_var(2,3)]
1.529 -  note XYZ = finite_random_variable_pairI[OF finite_var(1) YZ]
1.530 -  note finite = finite_var(3) YZ XZ XYZ
1.531 -  note finite = finite[THEN finite_distribution_finite, simplified space_simps]
1.532 -
1.533 +  note YZ = finite_random_variable_pairI[OF Y Z]
1.534 +  note XZ = finite_random_variable_pairI[OF X Z]
1.535 +  note ZX = finite_random_variable_pairI[OF Z X]
1.536 +  note YZ = finite_random_variable_pairI[OF Y Z]
1.537 +  note XYZ = finite_random_variable_pairI[OF X YZ]
1.538 +  note finite = Z YZ XZ XYZ
1.539    have order: "\<And>x y z. \<lbrakk>x \<in> space MX; y \<in> space MY; z \<in> space MZ; joint_distribution X Z {(x, z)} = 0\<rbrakk>
1.540            \<Longrightarrow> joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)} = 0"
1.541      unfolding joint_distribution_commute_singleton[of X]
1.542      unfolding joint_distribution_assoc_singleton[symmetric]
1.543 -    using finite_distribution_order(6)[OF finite_var(2) ZX]
1.544 -    by (auto simp: space_simps)
1.545 +    using finite_distribution_order(6)[OF Y ZX]
1.546 +    by auto
1.547
1.548    note order = order
1.549 -    finite_distribution_order(5,6)[OF finite_var(1) YZ, simplified space_simps]
1.550 -    finite_distribution_order(5,6)[OF finite_var(2,3), simplified space_simps]
1.551 +    finite_distribution_order(5,6)[OF X YZ]
1.552 +    finite_distribution_order(5,6)[OF Y Z]
1.553
1.554    have "- conditional_mutual_information b MX MY MZ X Y Z = - (\<Sum>(x, y, z) \<in> ?M. ?dXYZ {(x, y, z)} *
1.555      log b (?dXYZ {(x, y, z)} / (?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z})))"
1.556 -    unfolding conditional_mutual_information_generic_eq[OF assms] neg_equal_iff_equal
1.557 -    by (intro setsum_cong) (auto intro!: arg_cong[where f="log b"] simp: real_of_pextreal_mult[symmetric])
1.558 +    unfolding conditional_mutual_information_generic_eq[OF assms] neg_equal_iff_equal by auto
1.559    also have "\<dots> \<le> log b (\<Sum>(x, y, z) \<in> ?M. ?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z})"
1.560 -    unfolding split_beta
1.561 +    unfolding split_beta'
1.562    proof (rule log_setsum_divide)
1.563      show "?M \<noteq> {}" using False by simp
1.564      show "1 < b" using b_gt_1 .
1.565 @@ -757,33 +755,31 @@
1.566        unfolding setsum_commute[of _ "space MY"]
1.567        unfolding setsum_commute[of _ "space MZ"]
1.569 -        setsum_real_joint_distribution_singleton[OF `finite_random_variable MX X` YZ]
1.570 -        setsum_real_joint_distribution_singleton[OF `finite_random_variable MY Y` finite_var(3)]
1.571 -        setsum_real_distribution[OF `finite_random_variable MZ Z`])
1.572 +                        setsum_joint_distribution_singleton[OF X YZ]
1.573 +                        setsum_joint_distribution_singleton[OF Y Z]
1.574 +                        setsum_distribution[OF Z])
1.575
1.576      fix x assume "x \<in> ?M"
1.577      let ?x = "(fst x, fst (snd x), snd (snd x))"
1.578
1.579 -    show "0 \<le> ?dXYZ {?x}" using real_pextreal_nonneg .
1.580 -    show "0 \<le> ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}"
1.581 -     by (simp add: real_pextreal_nonneg mult_nonneg_nonneg divide_nonneg_nonneg)
1.582 +    show "0 \<le> ?dXYZ {?x}"
1.583 +      "0 \<le> ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}"
1.584 +     by (simp_all add: mult_nonneg_nonneg divide_nonneg_nonneg)
1.585
1.586      assume *: "0 < ?dXYZ {?x}"
1.587 -    with `x \<in> ?M` show "0 < ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}"
1.588 -      using finite order
1.589 -      by (cases x)
1.590 -         (auto simp add: zero_less_real_of_pextreal zero_less_mult_iff zero_less_divide_iff)
1.591 +    with `x \<in> ?M` finite order show "0 < ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}"
1.592 +      by (cases x) (auto simp add: zero_le_mult_iff zero_le_divide_iff less_le)
1.593    qed
1.594    also have "(\<Sum>(x, y, z) \<in> ?M. ?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z}) = (\<Sum>z\<in>space MZ. ?dZ {z})"
1.596      apply (subst setsum_commute)
1.597      apply (subst (2) setsum_commute)
1.598      by (auto simp: setsum_divide_distrib[symmetric] setsum_product[symmetric]
1.599 -                   setsum_real_joint_distribution_singleton[OF finite_var(1,3)]
1.600 -                   setsum_real_joint_distribution_singleton[OF finite_var(2,3)]
1.601 +                   setsum_joint_distribution_singleton[OF X Z]
1.602 +                   setsum_joint_distribution_singleton[OF Y Z]
1.603            intro!: setsum_cong)
1.604    also have "log b (\<Sum>z\<in>space MZ. ?dZ {z}) = 0"
1.605 -    unfolding setsum_real_distribution[OF finite_var(3)] by simp
1.606 +    unfolding setsum_real_distribution[OF Z] by simp
1.607    finally show ?thesis by simp
1.608  qed
1.609
1.610 @@ -800,57 +796,52 @@
1.611  abbreviation (in information_space)
1.612    conditional_entropy_Pow ("\<H>'(_ | _')") where
1.613    "\<H>(X | Y) \<equiv> conditional_entropy b
1.614 -    \<lparr> space = X`space M, sets = Pow (X`space M), measure = distribution X \<rparr>
1.615 -    \<lparr> space = Y`space M, sets = Pow (Y`space M), measure = distribution Y \<rparr> X Y"
1.616 +    \<lparr> space = X`space M, sets = Pow (X`space M), measure = extreal\<circ>distribution X \<rparr>
1.617 +    \<lparr> space = Y`space M, sets = Pow (Y`space M), measure = extreal\<circ>distribution Y \<rparr> X Y"
1.618
1.619  lemma (in information_space) conditional_entropy_positive:
1.620    "simple_function M X \<Longrightarrow> simple_function M Y \<Longrightarrow> 0 \<le> \<H>(X | Y)"
1.621    unfolding conditional_entropy_def by (auto intro!: conditional_mutual_information_positive)
1.622
1.623 -lemma (in measure_space) empty_measureI: "A = {} \<Longrightarrow> \<mu> A = 0" by simp
1.624 -
1.625  lemma (in information_space) conditional_entropy_generic_eq:
1.626    fixes MX :: "('c, 'd) measure_space_scheme" and MY :: "('e, 'f) measure_space_scheme"
1.627    assumes MX: "finite_random_variable MX X"
1.628    assumes MZ: "finite_random_variable MZ Z"
1.629    shows "conditional_entropy b MX MZ X Z =
1.630       - (\<Sum>(x, z)\<in>space MX \<times> space MZ.
1.631 -         real (joint_distribution X Z {(x, z)}) *
1.632 -         log b (real (joint_distribution X Z {(x, z)}) / real (distribution Z {z})))"
1.633 +         joint_distribution X Z {(x, z)} * log b (joint_distribution X Z {(x, z)} / distribution Z {z}))"
1.634  proof -
1.635    interpret MX: finite_sigma_algebra MX using MX by simp
1.636    interpret MZ: finite_sigma_algebra MZ using MZ by simp
1.637    let "?XXZ x y z" = "joint_distribution X (\<lambda>x. (X x, Z x)) {(x, y, z)}"
1.638    let "?XZ x z" = "joint_distribution X Z {(x, z)}"
1.639    let "?Z z" = "distribution Z {z}"
1.640 -  let "?f x y z" = "log b (real (?XXZ x y z) / (real (?XZ x z) * real (?XZ y z / ?Z z)))"
1.641 +  let "?f x y z" = "log b (?XXZ x y z * ?Z z / (?XZ x z * ?XZ y z))"
1.642    { fix x z have "?XXZ x x z = ?XZ x z"
1.643 -      unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>]) }
1.644 +      unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>']) }
1.645    note this[simp]
1.646    { fix x x' :: 'c and z assume "x' \<noteq> x"
1.647      then have "?XXZ x x' z = 0"
1.648 -      by (auto simp: distribution_def intro!: arg_cong[where f=\<mu>] empty_measureI) }
1.649 +      by (auto simp: distribution_def empty_measure'[symmetric]
1.650 +               simp del: empty_measure' intro!: arg_cong[where f=\<mu>']) }
1.651    note this[simp]
1.652    { fix x x' z assume *: "x \<in> space MX" "z \<in> space MZ"
1.653 -    then have "(\<Sum>x'\<in>space MX. real (?XXZ x x' z) * ?f x x' z)
1.654 -      = (\<Sum>x'\<in>space MX. if x = x' then real (?XZ x z) * ?f x x z else 0)"
1.655 +    then have "(\<Sum>x'\<in>space MX. ?XXZ x x' z * ?f x x' z)
1.656 +      = (\<Sum>x'\<in>space MX. if x = x' then ?XZ x z * ?f x x z else 0)"
1.657        by (auto intro!: setsum_cong)
1.658 -    also have "\<dots> = real (?XZ x z) * ?f x x z"
1.659 +    also have "\<dots> = ?XZ x z * ?f x x z"
1.660        using `x \<in> space MX` by (simp add: setsum_cases[OF MX.finite_space])
1.661 -    also have "\<dots> = real (?XZ x z) * log b (real (?Z z) / real (?XZ x z))"
1.662 -      by (auto simp: real_of_pextreal_mult[symmetric])
1.663 -    also have "\<dots> = - real (?XZ x z) * log b (real (?XZ x z) / real (?Z z))"
1.664 -      using assms[THEN finite_distribution_finite]
1.665 +    also have "\<dots> = ?XZ x z * log b (?Z z / ?XZ x z)" by auto
1.666 +    also have "\<dots> = - ?XZ x z * log b (?XZ x z / ?Z z)"
1.667        using finite_distribution_order(6)[OF MX MZ]
1.668 -      by (auto simp: log_simps field_simps zero_less_mult_iff zero_less_real_of_pextreal real_of_pextreal_eq_0)
1.669 -    finally have "(\<Sum>x'\<in>space MX. real (?XXZ x x' z) * ?f x x' z) =
1.670 -      - real (?XZ x z) * log b (real (?XZ x z) / real (?Z z))" . }
1.671 +      by (auto simp: log_simps field_simps zero_less_mult_iff)
1.672 +    finally have "(\<Sum>x'\<in>space MX. ?XXZ x x' z * ?f x x' z) = - ?XZ x z * log b (?XZ x z / ?Z z)" . }
1.673    note * = this
1.674    show ?thesis
1.675      unfolding conditional_entropy_def
1.676      unfolding conditional_mutual_information_generic_eq[OF MX MX MZ]
1.677      by (auto simp: setsum_cartesian_product' setsum_negf[symmetric]
1.678 -                   setsum_commute[of _ "space MZ"] *   simp del: divide_pextreal_def
1.679 +                   setsum_commute[of _ "space MZ"] *
1.680               intro!: setsum_cong)
1.681  qed
1.682
1.683 @@ -858,29 +849,27 @@
1.684    assumes "simple_function M X" "simple_function M Z"
1.685    shows "\<H>(X | Z) =
1.686       - (\<Sum>(x, z)\<in>X ` space M \<times> Z ` space M.
1.687 -         real (joint_distribution X Z {(x, z)}) *
1.688 -         log b (real (joint_distribution X Z {(x, z)}) / real (distribution Z {z})))"
1.689 -  using conditional_entropy_generic_eq[OF assms[THEN simple_function_imp_finite_random_variable]]
1.690 -  by simp
1.691 +         joint_distribution X Z {(x, z)} *
1.692 +         log b (joint_distribution X Z {(x, z)} / distribution Z {z}))"
1.693 +  by (subst conditional_entropy_generic_eq[OF assms[THEN simple_function_imp_finite_random_variable]])
1.694 +     simp
1.695
1.696  lemma (in information_space) conditional_entropy_eq_ce_with_hypothesis:
1.697    assumes X: "simple_function M X" and Y: "simple_function M Y"
1.698    shows "\<H>(X | Y) =
1.699 -    -(\<Sum>y\<in>Y`space M. real (distribution Y {y}) *
1.700 -      (\<Sum>x\<in>X`space M. real (joint_distribution X Y {(x,y)}) / real (distribution Y {(y)}) *
1.701 -              log b (real (joint_distribution X Y {(x,y)}) / real (distribution Y {(y)}))))"
1.702 +    -(\<Sum>y\<in>Y`space M. distribution Y {y} *
1.703 +      (\<Sum>x\<in>X`space M. joint_distribution X Y {(x,y)} / distribution Y {(y)} *
1.704 +              log b (joint_distribution X Y {(x,y)} / distribution Y {(y)})))"
1.705    unfolding conditional_entropy_eq[OF assms]
1.706 -  using finite_distribution_finite[OF finite_random_variable_pairI[OF assms[THEN simple_function_imp_finite_random_variable]]]
1.707    using finite_distribution_order(5,6)[OF assms[THEN simple_function_imp_finite_random_variable]]
1.708 -  using finite_distribution_finite[OF Y[THEN simple_function_imp_finite_random_variable]]
1.709 -  by (auto simp: setsum_cartesian_product'  setsum_commute[of _ "Y`space M"] setsum_right_distrib real_of_pextreal_eq_0
1.710 +  by (auto simp: setsum_cartesian_product'  setsum_commute[of _ "Y`space M"] setsum_right_distrib
1.711             intro!: setsum_cong)
1.712
1.713  lemma (in information_space) conditional_entropy_eq_cartesian_product:
1.714    assumes "simple_function M X" "simple_function M Y"
1.715    shows "\<H>(X | Y) = -(\<Sum>x\<in>X`space M. \<Sum>y\<in>Y`space M.
1.716 -    real (joint_distribution X Y {(x,y)}) *
1.717 -    log b (real (joint_distribution X Y {(x,y)}) / real (distribution Y {y})))"
1.718 +    joint_distribution X Y {(x,y)} *
1.719 +    log b (joint_distribution X Y {(x,y)} / distribution Y {y}))"
1.720    unfolding conditional_entropy_eq[OF assms]
1.721    by (auto intro!: setsum_cong simp: setsum_cartesian_product')
1.722
1.723 @@ -890,24 +879,22 @@
1.724    assumes X: "simple_function M X" and Z: "simple_function M Z"
1.725    shows  "\<I>(X ; Z) = \<H>(X) - \<H>(X | Z)"
1.726  proof -
1.727 -  let "?XZ x z" = "real (joint_distribution X Z {(x, z)})"
1.728 -  let "?Z z" = "real (distribution Z {z})"
1.729 -  let "?X x" = "real (distribution X {x})"
1.730 +  let "?XZ x z" = "joint_distribution X Z {(x, z)}"
1.731 +  let "?Z z" = "distribution Z {z}"
1.732 +  let "?X x" = "distribution X {x}"
1.733    note fX = X[THEN simple_function_imp_finite_random_variable]
1.734    note fZ = Z[THEN simple_function_imp_finite_random_variable]
1.735 -  note fX[THEN finite_distribution_finite, simp] and fZ[THEN finite_distribution_finite, simp]
1.736    note finite_distribution_order[OF fX fZ, simp]
1.737    { fix x z assume "x \<in> X`space M" "z \<in> Z`space M"
1.738      have "?XZ x z * log b (?XZ x z / (?X x * ?Z z)) =
1.739            ?XZ x z * log b (?XZ x z / ?Z z) - ?XZ x z * log b (?X x)"
1.740 -      by (auto simp: log_simps real_of_pextreal_mult[symmetric] zero_less_mult_iff
1.741 -                     zero_less_real_of_pextreal field_simps real_of_pextreal_eq_0 abs_mult) }
1.742 +      by (auto simp: log_simps zero_le_mult_iff field_simps less_le) }
1.743    note * = this
1.744    show ?thesis
1.745      unfolding entropy_eq[OF X] conditional_entropy_eq[OF X Z] mutual_information_eq[OF X Z]
1.746 -    using setsum_real_joint_distribution_singleton[OF fZ fX, unfolded joint_distribution_commute_singleton[of Z X]]
1.747 +    using setsum_joint_distribution_singleton[OF fZ fX, unfolded joint_distribution_commute_singleton[of Z X]]
1.748      by (simp add: * setsum_cartesian_product' setsum_subtractf setsum_left_distrib[symmetric]
1.749 -                     setsum_real_distribution)
1.750 +                     setsum_distribution)
1.751  qed
1.752
1.753  lemma (in information_space) conditional_entropy_less_eq_entropy:
1.754 @@ -923,21 +910,19 @@
1.755    assumes X: "simple_function M X" and Y: "simple_function M Y"
1.756    shows  "\<H>(\<lambda>x. (X x, Y x)) = \<H>(X) + \<H>(Y|X)"
1.757  proof -
1.758 -  let "?XY x y" = "real (joint_distribution X Y {(x, y)})"
1.759 -  let "?Y y" = "real (distribution Y {y})"
1.760 -  let "?X x" = "real (distribution X {x})"
1.761 +  let "?XY x y" = "joint_distribution X Y {(x, y)}"
1.762 +  let "?Y y" = "distribution Y {y}"
1.763 +  let "?X x" = "distribution X {x}"
1.764    note fX = X[THEN simple_function_imp_finite_random_variable]
1.765    note fY = Y[THEN simple_function_imp_finite_random_variable]
1.766 -  note fX[THEN finite_distribution_finite, simp] and fY[THEN finite_distribution_finite, simp]
1.767    note finite_distribution_order[OF fX fY, simp]
1.768    { fix x y assume "x \<in> X`space M" "y \<in> Y`space M"
1.769      have "?XY x y * log b (?XY x y / ?X x) =
1.770            ?XY x y * log b (?XY x y) - ?XY x y * log b (?X x)"
1.771 -      by (auto simp: log_simps real_of_pextreal_mult[symmetric] zero_less_mult_iff
1.772 -                     zero_less_real_of_pextreal field_simps real_of_pextreal_eq_0 abs_mult) }
1.773 +      by (auto simp: log_simps zero_le_mult_iff field_simps less_le) }
1.774    note * = this
1.775    show ?thesis
1.776 -    using setsum_real_joint_distribution_singleton[OF fY fX]
1.777 +    using setsum_joint_distribution_singleton[OF fY fX]
1.778      unfolding entropy_eq[OF X] conditional_entropy_eq_cartesian_product[OF Y X] entropy_eq_cartesian_product[OF X Y]
1.779      unfolding joint_distribution_commute_singleton[of Y X] setsum_commute[of _ "X`space M"]
1.780      by (simp add: * setsum_subtractf setsum_left_distrib[symmetric])
1.781 @@ -1063,23 +1048,21 @@
1.782    assumes svi: "subvimage (space M) X P"
1.783    shows "\<H>(X) = \<H>(P) + \<H>(X|P)"
1.784  proof -
1.785 -  let "?XP x p" = "real (joint_distribution X P {(x, p)})"
1.786 -  let "?X x" = "real (distribution X {x})"
1.787 -  let "?P p" = "real (distribution P {p})"
1.788 +  let "?XP x p" = "joint_distribution X P {(x, p)}"
1.789 +  let "?X x" = "distribution X {x}"
1.790 +  let "?P p" = "distribution P {p}"
1.791    note fX = sf(1)[THEN simple_function_imp_finite_random_variable]
1.792    note fP = sf(2)[THEN simple_function_imp_finite_random_variable]
1.793 -  note fX[THEN finite_distribution_finite, simp] and fP[THEN finite_distribution_finite, simp]
1.794    note finite_distribution_order[OF fX fP, simp]
1.795 -  have "(\<Sum>x\<in>X ` space M. real (distribution X {x}) * log b (real (distribution X {x}))) =
1.796 -    (\<Sum>y\<in>P `space M. \<Sum>x\<in>X ` space M.
1.797 -    real (joint_distribution X P {(x, y)}) * log b (real (joint_distribution X P {(x, y)})))"
1.798 +  have "(\<Sum>x\<in>X ` space M. ?X x * log b (?X x)) =
1.799 +    (\<Sum>y\<in>P `space M. \<Sum>x\<in>X ` space M. ?XP x y * log b (?XP x y))"
1.800    proof (subst setsum_image_split[OF svi],
1.801        safe intro!: setsum_mono_zero_cong_left imageI)
1.802      show "finite (X ` space M)" "finite (X ` space M)" "finite (P ` space M)"
1.803        using sf unfolding simple_function_def by auto
1.804    next
1.805      fix p x assume in_space: "p \<in> space M" "x \<in> space M"
1.806 -    assume "real (joint_distribution X P {(X x, P p)}) * log b (real (joint_distribution X P {(X x, P p)})) \<noteq> 0"
1.807 +    assume "?XP (X x) (P p) * log b (?XP (X x) (P p)) \<noteq> 0"
1.808      hence "(\<lambda>x. (X x, P x)) -` {(X x, P p)} \<inter> space M \<noteq> {}" by (auto simp: distribution_def)
1.809      with svi[unfolded subvimage_def, rule_format, OF `x \<in> space M`]
1.810      show "x \<in> P -` {P p}" by auto
1.811 @@ -1091,20 +1074,16 @@
1.812        by auto
1.813      hence "(\<lambda>x. (X x, P x)) -` {(X x, P p)} \<inter> space M = X -` {X x} \<inter> space M"
1.814        by auto
1.815 -    thus "real (distribution X {X x}) * log b (real (distribution X {X x})) =
1.816 -          real (joint_distribution X P {(X x, P p)}) *
1.817 -          log b (real (joint_distribution X P {(X x, P p)}))"
1.818 +    thus "?X (X x) * log b (?X (X x)) = ?XP (X x) (P p) * log b (?XP (X x) (P p))"
1.819        by (auto simp: distribution_def)
1.820    qed
1.821 -  moreover have "\<And>x y. real (joint_distribution X P {(x, y)}) *
1.822 -      log b (real (joint_distribution X P {(x, y)}) / real (distribution P {y})) =
1.823 -      real (joint_distribution X P {(x, y)}) * log b (real (joint_distribution X P {(x, y)})) -
1.824 -      real (joint_distribution X P {(x, y)}) * log b (real (distribution P {y}))"
1.825 +  moreover have "\<And>x y. ?XP x y * log b (?XP x y / ?P y) =
1.826 +      ?XP x y * log b (?XP x y) - ?XP x y * log b (?P y)"
1.827      by (auto simp add: log_simps zero_less_mult_iff field_simps)
1.828    ultimately show ?thesis
1.829      unfolding sf[THEN entropy_eq] conditional_entropy_eq[OF sf]
1.830 -    using setsum_real_joint_distribution_singleton[OF fX fP]
1.831 -    by (simp add: setsum_cartesian_product' setsum_subtractf setsum_real_distribution
1.832 +    using setsum_joint_distribution_singleton[OF fX fP]
1.833 +    by (simp add: setsum_cartesian_product' setsum_subtractf setsum_distribution
1.834        setsum_left_distrib[symmetric] setsum_commute[where B="P`space M"])
1.835  qed
1.836
```