src/HOL/Probability/Information.thy
 changeset 41689 3e39b0e730d6 parent 41661 baf1964bc468 child 41833 563bea92b2c0
```     1.1 --- a/src/HOL/Probability/Information.thy	Wed Feb 02 10:35:41 2011 +0100
1.2 +++ b/src/HOL/Probability/Information.thy	Wed Feb 02 12:34:45 2011 +0100
1.3 @@ -165,43 +165,45 @@
1.4  Kullback\$-\$Leibler distance. *}
1.5
1.6  definition
1.7 -  "KL_divergence b M \<mu> \<nu> =
1.8 -    measure_space.integral M \<mu> (\<lambda>x. log b (real (sigma_finite_measure.RN_deriv M \<nu> \<mu> x)))"
1.9 +  "KL_divergence b M \<nu> = \<integral>x. log b (real (RN_deriv M \<nu> x)) \<partial>M\<lparr>measure := \<nu>\<rparr>"
1.10
1.11  lemma (in sigma_finite_measure) KL_divergence_cong:
1.12 -  assumes "measure_space M \<nu>"
1.13 -  and cong: "\<And>A. A \<in> sets M \<Longrightarrow> \<mu>' A = \<mu> A" "\<And>A. A \<in> sets M \<Longrightarrow> \<nu>' A = \<nu> A"
1.14 -  shows "KL_divergence b M \<nu>' \<mu>' = KL_divergence b M \<nu> \<mu>"
1.15 +  assumes "measure_space (M\<lparr>measure := \<nu>\<rparr>)" (is "measure_space ?\<nu>")
1.16 +  assumes [simp]: "sets N = sets M" "space N = space M"
1.17 +    "\<And>A. A \<in> sets M \<Longrightarrow> measure N A = \<mu> A"
1.18 +    "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = \<nu>' A"
1.19 +  shows "KL_divergence b M \<nu> = KL_divergence b N \<nu>'"
1.20  proof -
1.21 -  interpret \<nu>: measure_space M \<nu> by fact
1.22 -  show ?thesis
1.23 -    unfolding KL_divergence_def
1.24 -    using RN_deriv_cong[OF cong, of "\<lambda>A. A"]
1.25 -    by (simp add: cong \<nu>.integral_cong_measure[OF cong(2)])
1.26 +  interpret \<nu>: measure_space ?\<nu> by fact
1.27 +  have "KL_divergence b M \<nu> = \<integral>x. log b (real (RN_deriv N \<nu>' x)) \<partial>?\<nu>"
1.28 +    by (simp cong: RN_deriv_cong \<nu>.integral_cong add: KL_divergence_def)
1.29 +  also have "\<dots> = KL_divergence b N \<nu>'"
1.30 +    by (auto intro!: \<nu>.integral_cong_measure[symmetric] simp: KL_divergence_def)
1.31 +  finally show ?thesis .
1.32  qed
1.33
1.34  lemma (in finite_measure_space) KL_divergence_eq_finite:
1.35 -  assumes v: "finite_measure_space M \<nu>"
1.36 +  assumes v: "finite_measure_space (M\<lparr>measure := \<nu>\<rparr>)"
1.37    assumes ac: "absolutely_continuous \<nu>"
1.38 -  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")
1.39 +  shows "KL_divergence b M \<nu> = (\<Sum>x\<in>space M. real (\<nu> {x}) * log b (real (\<nu> {x}) / real (\<mu> {x})))" (is "_ = ?sum")
1.40  proof (simp add: KL_divergence_def finite_measure_space.integral_finite_singleton[OF v])
1.41 -  interpret v: finite_measure_space M \<nu> by fact
1.42 -  have ms: "measure_space M \<nu>" by fact
1.43 -  show "(\<Sum>x \<in> space M. log b (real (RN_deriv \<nu> x)) * real (\<nu> {x})) = ?sum"
1.44 +  interpret v: finite_measure_space "M\<lparr>measure := \<nu>\<rparr>" by fact
1.45 +  have ms: "measure_space (M\<lparr>measure := \<nu>\<rparr>)" by default
1.46 +  show "(\<Sum>x \<in> space M. log b (real (RN_deriv M \<nu> x)) * real (\<nu> {x})) = ?sum"
1.47      using RN_deriv_finite_measure[OF ms ac]
1.48      by (auto intro!: setsum_cong simp: field_simps real_of_pextreal_mult[symmetric])
1.49  qed
1.50
1.51  lemma (in finite_prob_space) KL_divergence_positive_finite:
1.52 -  assumes v: "finite_prob_space M \<nu>"
1.53 +  assumes v: "finite_prob_space (M\<lparr>measure := \<nu>\<rparr>)"
1.54    assumes ac: "absolutely_continuous \<nu>"
1.55    and "1 < b"
1.56 -  shows "0 \<le> KL_divergence b M \<nu> \<mu>"
1.57 +  shows "0 \<le> KL_divergence b M \<nu>"
1.58  proof -
1.59 -  interpret v: finite_prob_space M \<nu> using v .
1.60 -  have ms: "finite_measure_space M \<nu>" by default
1.61 +  interpret v: finite_prob_space "M\<lparr>measure := \<nu>\<rparr>" by fact
1.62 +  have ms: "finite_measure_space (M\<lparr>measure := \<nu>\<rparr>)" by default
1.63
1.64 -  have "- (KL_divergence b M \<nu> \<mu>) \<le> log b (\<Sum>x\<in>space M. real (\<mu> {x}))"
1.65 +  have "- (KL_divergence b M \<nu>) \<le> log b (\<Sum>x\<in>space M. real (\<mu> {x}))"
1.66    proof (subst KL_divergence_eq_finite[OF ms ac], safe intro!: log_setsum_divide not_empty)
1.67      show "finite (space M)" using finite_space by simp
1.68      show "1 < b" by fact
1.69 @@ -215,16 +217,15 @@
1.70          using ac[unfolded absolutely_continuous_def, THEN bspec, of "{x}"] x by auto
1.71        thus "0 < prob {x}" using finite_measure[of "{x}"] x by auto }
1.72    qed auto
1.73 -  thus "0 \<le> KL_divergence b M \<nu> \<mu>" using finite_sum_over_space_eq_1 by simp
1.74 +  thus "0 \<le> KL_divergence b M \<nu>" using finite_sum_over_space_eq_1 by simp
1.75  qed
1.76
1.77  subsection {* Mutual Information *}
1.78
1.79  definition (in prob_space)
1.80    "mutual_information b S T X Y =
1.81 -    KL_divergence b (sigma (pair_algebra S T))
1.82 -      (joint_distribution X Y)
1.83 -      (pair_sigma_finite.pair_measure S (distribution X) T (distribution Y))"
1.84 +    KL_divergence b (S\<lparr>measure := distribution X\<rparr> \<Otimes>\<^isub>M T\<lparr>measure := distribution Y\<rparr>)
1.85 +      (joint_distribution X Y)"
1.86
1.87  definition (in prob_space)
1.88    "entropy b s X = mutual_information b s s X X"
1.89 @@ -232,32 +233,49 @@
1.90  abbreviation (in information_space)
1.91    mutual_information_Pow ("\<I>'(_ ; _')") where
1.92    "\<I>(X ; Y) \<equiv> mutual_information b
1.93 -    \<lparr> space = X`space M, sets = Pow (X`space M) \<rparr>
1.94 -    \<lparr> space = Y`space M, sets = Pow (Y`space M) \<rparr> X Y"
1.95 +    \<lparr> space = X`space M, sets = Pow (X`space M), measure = distribution X \<rparr>
1.96 +    \<lparr> space = Y`space M, sets = Pow (Y`space M), measure = distribution Y \<rparr> X Y"
1.97 +
1.98 +lemma algebra_measure_update[simp]:
1.99 +  "algebra (M'\<lparr>measure := m\<rparr>) \<longleftrightarrow> algebra M'"
1.100 +  unfolding algebra_def by simp
1.101 +
1.102 +lemma sigma_algebra_measure_update[simp]:
1.103 +  "sigma_algebra (M'\<lparr>measure := m\<rparr>) \<longleftrightarrow> sigma_algebra M'"
1.104 +  unfolding sigma_algebra_def sigma_algebra_axioms_def by simp
1.105 +
1.106 +lemma finite_sigma_algebra_measure_update[simp]:
1.107 +  "finite_sigma_algebra (M'\<lparr>measure := m\<rparr>) \<longleftrightarrow> finite_sigma_algebra M'"
1.108 +  unfolding finite_sigma_algebra_def finite_sigma_algebra_axioms_def by simp
1.109
1.110  lemma (in prob_space) finite_variables_absolutely_continuous:
1.111    assumes X: "finite_random_variable S X" and Y: "finite_random_variable T Y"
1.112 -  shows "measure_space.absolutely_continuous (sigma (pair_algebra S T))
1.113 -   (pair_sigma_finite.pair_measure S (distribution X) T (distribution Y)) (joint_distribution X Y)"
1.114 +  shows "measure_space.absolutely_continuous
1.115 +    (S\<lparr>measure := distribution X\<rparr> \<Otimes>\<^isub>M T\<lparr>measure := distribution Y\<rparr>)
1.116 +    (joint_distribution X Y)"
1.117  proof -
1.118 -  interpret X: finite_prob_space S "distribution X" using X by (rule distribution_finite_prob_space)
1.119 -  interpret Y: finite_prob_space T "distribution Y" using Y by (rule distribution_finite_prob_space)
1.120 -  interpret XY: pair_finite_prob_space S "distribution X" T "distribution Y" by default
1.121 -  interpret P: finite_prob_space XY.P "joint_distribution X Y"
1.122 -    using assms by (intro joint_distribution_finite_prob_space)
1.123 +  interpret X: finite_prob_space "S\<lparr>measure := distribution X\<rparr>"
1.124 +    using X by (rule distribution_finite_prob_space)
1.125 +  interpret Y: finite_prob_space "T\<lparr>measure := distribution Y\<rparr>"
1.126 +    using Y by (rule distribution_finite_prob_space)
1.127 +  interpret XY: pair_finite_prob_space
1.128 +    "S\<lparr>measure := distribution X\<rparr>" "T\<lparr> measure := distribution Y\<rparr>" by default
1.129 +  interpret P: finite_prob_space "XY.P\<lparr> measure := joint_distribution X Y\<rparr>"
1.130 +    using assms by (auto intro!: joint_distribution_finite_prob_space)
1.131 +  note rv = assms[THEN finite_random_variableD]
1.132    show "XY.absolutely_continuous (joint_distribution X Y)"
1.133    proof (rule XY.absolutely_continuousI)
1.134 -    show "finite_measure_space XY.P (joint_distribution X Y)" by default
1.135 -    fix x assume "x \<in> space XY.P" and "XY.pair_measure {x} = 0"
1.136 +    show "finite_measure_space (XY.P\<lparr> measure := joint_distribution X Y\<rparr>)" by default
1.137 +    fix x assume "x \<in> space XY.P" and "XY.\<mu> {x} = 0"
1.138      then obtain a b where "(a, b) = x" and "a \<in> space S" "b \<in> space T"
1.139        and distr: "distribution X {a} * distribution Y {b} = 0"
1.140 -      by (cases x) (auto simp: pair_algebra_def)
1.141 -    with assms[THEN finite_random_variableD]
1.142 -      joint_distribution_Times_le_fst[of S X T Y "{a}" "{b}"]
1.143 -      joint_distribution_Times_le_snd[of S X T Y "{a}" "{b}"]
1.144 +      by (cases x) (auto simp: space_pair_measure)
1.145 +    with X.sets_eq_Pow Y.sets_eq_Pow
1.146 +      joint_distribution_Times_le_fst[OF rv, of "{a}" "{b}"]
1.147 +      joint_distribution_Times_le_snd[OF rv, of "{a}" "{b}"]
1.148      have "joint_distribution X Y {x} \<le> distribution Y {b}"
1.149           "joint_distribution X Y {x} \<le> distribution X {a}"
1.150 -      by auto
1.151 +      by (auto simp del: X.sets_eq_Pow Y.sets_eq_Pow)
1.152      with distr show "joint_distribution X Y {x} = 0" by auto
1.153    qed
1.154  qed
1.155 @@ -274,19 +292,21 @@
1.156    and mutual_information_positive_generic:
1.157       "0 \<le> mutual_information b MX MY X Y" (is ?positive)
1.158  proof -
1.159 -  interpret X: finite_prob_space MX "distribution X" using MX by (rule distribution_finite_prob_space)
1.160 -  interpret Y: finite_prob_space MY "distribution Y" using MY by (rule distribution_finite_prob_space)
1.161 -  interpret XY: pair_finite_prob_space MX "distribution X" MY "distribution Y" by default
1.162 -  interpret P: finite_prob_space XY.P "joint_distribution X Y"
1.163 -    using assms by (intro joint_distribution_finite_prob_space)
1.164 +  interpret X: finite_prob_space "MX\<lparr>measure := distribution X\<rparr>"
1.165 +    using MX by (rule distribution_finite_prob_space)
1.166 +  interpret Y: finite_prob_space "MY\<lparr>measure := distribution Y\<rparr>"
1.167 +    using MY by (rule distribution_finite_prob_space)
1.168 +  interpret XY: pair_finite_prob_space "MX\<lparr>measure := distribution X\<rparr>" "MY\<lparr>measure := distribution Y\<rparr>" by default
1.169 +  interpret P: finite_prob_space "XY.P\<lparr>measure := joint_distribution X Y\<rparr>"
1.170 +    using assms by (auto intro!: joint_distribution_finite_prob_space)
1.171
1.172 -  have P_ms: "finite_measure_space XY.P (joint_distribution X Y)" by default
1.173 -  have P_ps: "finite_prob_space XY.P (joint_distribution X Y)" by default
1.174 +  have P_ms: "finite_measure_space (XY.P\<lparr>measure :=joint_distribution X Y\<rparr>)" by default
1.175 +  have P_ps: "finite_prob_space (XY.P\<lparr>measure := joint_distribution X Y\<rparr>)" by default
1.176
1.177    show ?sum
1.178      unfolding Let_def mutual_information_def
1.179      by (subst XY.KL_divergence_eq_finite[OF P_ms finite_variables_absolutely_continuous[OF MX MY]])
1.180 -       (auto simp add: pair_algebra_def setsum_cartesian_product' real_of_pextreal_mult[symmetric])
1.181 +       (auto simp add: space_pair_measure setsum_cartesian_product' real_of_pextreal_mult[symmetric])
1.182
1.183    show ?positive
1.184      using XY.KL_divergence_positive_finite[OF P_ps finite_variables_absolutely_continuous[OF MX MY] b_gt_1]
1.185 @@ -301,12 +321,12 @@
1.186    by (auto simp add: ac_simps intro!: setsum_reindex_cong[OF swap_inj_on])
1.187
1.188  lemma (in information_space) mutual_information_commute_simple:
1.189 -  assumes X: "simple_function X" and Y: "simple_function Y"
1.190 +  assumes X: "simple_function M X" and Y: "simple_function M Y"
1.191    shows "\<I>(X;Y) = \<I>(Y;X)"
1.192    by (intro X Y simple_function_imp_finite_random_variable mutual_information_commute)
1.193
1.194  lemma (in information_space) mutual_information_eq:
1.195 -  assumes "simple_function X" "simple_function Y"
1.196 +  assumes "simple_function M X" "simple_function M Y"
1.197    shows "\<I>(X;Y) = (\<Sum> (x,y) \<in> X ` space M \<times> Y ` space M.
1.198      real (distribution (\<lambda>x. (X x, Y x)) {(x,y)}) * log b (real (distribution (\<lambda>x. (X x, Y x)) {(x,y)}) /
1.199                                                     (real (distribution X {x}) * real (distribution Y {y}))))"
1.200 @@ -327,7 +347,7 @@
1.201    by (simp cong: distribution_cong image_cong)
1.202
1.203  lemma (in information_space) mutual_information_positive:
1.204 -  assumes "simple_function X" "simple_function Y"
1.205 +  assumes "simple_function M X" "simple_function M Y"
1.206    shows "0 \<le> \<I>(X;Y)"
1.207    using assms by (simp add: mutual_information_positive_generic)
1.208
1.209 @@ -335,13 +355,14 @@
1.210
1.211  abbreviation (in information_space)
1.212    entropy_Pow ("\<H>'(_')") where
1.213 -  "\<H>(X) \<equiv> entropy b \<lparr> space = X`space M, sets = Pow (X`space M) \<rparr> X"
1.214 +  "\<H>(X) \<equiv> entropy b \<lparr> space = X`space M, sets = Pow (X`space M), measure = distribution X \<rparr> X"
1.215
1.216  lemma (in information_space) entropy_generic_eq:
1.217    assumes MX: "finite_random_variable MX X"
1.218    shows "entropy b MX X = -(\<Sum> x \<in> space MX. real (distribution X {x}) * log b (real (distribution X {x})))"
1.219  proof -
1.220 -  interpret MX: finite_prob_space MX "distribution X" using MX by (rule distribution_finite_prob_space)
1.221 +  interpret MX: finite_prob_space "MX\<lparr>measure := distribution X\<rparr>"
1.222 +    using MX by (rule distribution_finite_prob_space)
1.223    let "?X x" = "real (distribution X {x})"
1.224    let "?XX x y" = "real (joint_distribution X X {(x, y)})"
1.225    { fix x y
1.226 @@ -353,25 +374,26 @@
1.227    show ?thesis
1.228      unfolding entropy_def mutual_information_generic_eq[OF MX MX]
1.229      unfolding setsum_cartesian_product[symmetric] setsum_negf[symmetric] remove_XX
1.230 -    by (auto simp: setsum_cases MX.finite_space)
1.231 +    using MX.finite_space by (auto simp: setsum_cases)
1.232  qed
1.233
1.234  lemma (in information_space) entropy_eq:
1.235 -  assumes "simple_function X"
1.236 +  assumes "simple_function M X"
1.237    shows "\<H>(X) = -(\<Sum> x \<in> X ` space M. real (distribution X {x}) * log b (real (distribution X {x})))"
1.238    using assms by (simp add: entropy_generic_eq)
1.239
1.240  lemma (in information_space) entropy_positive:
1.241 -  "simple_function X \<Longrightarrow> 0 \<le> \<H>(X)"
1.242 +  "simple_function M X \<Longrightarrow> 0 \<le> \<H>(X)"
1.243    unfolding entropy_def by (simp add: mutual_information_positive)
1.244
1.245  lemma (in information_space) entropy_certainty_eq_0:
1.246 -  assumes "simple_function X" and "x \<in> X ` space M" and "distribution X {x} = 1"
1.247 +  assumes "simple_function M X" and "x \<in> X ` space M" and "distribution X {x} = 1"
1.248    shows "\<H>(X) = 0"
1.249  proof -
1.250 -  interpret X: finite_prob_space "\<lparr> space = X ` space M, sets = Pow (X ` space M) \<rparr>" "distribution X"
1.251 -    using simple_function_imp_finite_random_variable[OF `simple_function X`]
1.252 -    by (rule distribution_finite_prob_space)
1.253 +  let ?X = "\<lparr> space = X ` space M, sets = Pow (X ` space M), measure = distribution X\<rparr>"
1.254 +  note simple_function_imp_finite_random_variable[OF `simple_function M X`]
1.255 +  from distribution_finite_prob_space[OF this, of "\<lparr> measure = distribution X \<rparr>"]
1.256 +  interpret X: finite_prob_space ?X by simp
1.257    have "distribution X (X ` space M - {x}) = distribution X (X ` space M) - distribution X {x}"
1.258      using X.measure_compl[of "{x}"] assms by auto
1.259    also have "\<dots> = 0" using X.prob_space assms by auto
1.260 @@ -383,38 +405,39 @@
1.261    hence fi: "\<And> y. y \<in> X ` space M \<Longrightarrow> real (distribution X {y}) = (if x = y then 1 else 0)"
1.262      using assms by auto
1.263    have y: "\<And>y. (if x = y then 1 else 0) * log b (if x = y then 1 else 0) = 0" by simp
1.264 -  show ?thesis unfolding entropy_eq[OF `simple_function X`] by (auto simp: y fi)
1.265 +  show ?thesis unfolding entropy_eq[OF `simple_function M X`] by (auto simp: y fi)
1.266  qed
1.267
1.268  lemma (in information_space) entropy_le_card_not_0:
1.269 -  assumes "simple_function X"
1.270 +  assumes "simple_function M X"
1.271    shows "\<H>(X) \<le> log b (real (card (X ` space M \<inter> {x . distribution X {x} \<noteq> 0})))"
1.272  proof -
1.273    let "?d x" = "distribution X {x}"
1.274    let "?p x" = "real (?d x)"
1.275    have "\<H>(X) = (\<Sum>x\<in>X`space M. ?p x * log b (1 / ?p x))"
1.276 -    by (auto intro!: setsum_cong simp: entropy_eq[OF `simple_function X`] setsum_negf[symmetric] log_simps not_less)
1.277 +    by (auto intro!: setsum_cong simp: entropy_eq[OF `simple_function M X`] setsum_negf[symmetric] log_simps not_less)
1.278    also have "\<dots> \<le> log b (\<Sum>x\<in>X`space M. ?p x * (1 / ?p x))"
1.279      apply (rule log_setsum')
1.280 -    using not_empty b_gt_1 `simple_function X` sum_over_space_real_distribution
1.281 +    using not_empty b_gt_1 `simple_function M X` sum_over_space_real_distribution
1.282      by (auto simp: simple_function_def)
1.283    also have "\<dots> = log b (\<Sum>x\<in>X`space M. if ?d x \<noteq> 0 then 1 else 0)"
1.284 -    using distribution_finite[OF `simple_function X`[THEN simple_function_imp_random_variable], simplified]
1.285 +    using distribution_finite[OF `simple_function M X`[THEN simple_function_imp_random_variable], simplified]
1.286      by (intro arg_cong[where f="\<lambda>X. log b X"] setsum_cong) (auto simp: real_of_pextreal_eq_0)
1.287    finally show ?thesis
1.288 -    using `simple_function X` by (auto simp: setsum_cases real_eq_of_nat simple_function_def)
1.289 +    using `simple_function M X` by (auto simp: setsum_cases real_eq_of_nat simple_function_def)
1.290  qed
1.291
1.292  lemma (in information_space) entropy_uniform_max:
1.293 -  assumes "simple_function X"
1.294 +  assumes "simple_function M X"
1.295    assumes "\<And>x y. \<lbrakk> x \<in> X ` space M ; y \<in> X ` space M \<rbrakk> \<Longrightarrow> distribution X {x} = distribution X {y}"
1.296    shows "\<H>(X) = log b (real (card (X ` space M)))"
1.297  proof -
1.298 -  interpret X: finite_prob_space "\<lparr> space = X ` space M, sets = Pow (X ` space M) \<rparr>" "distribution X"
1.299 -    using simple_function_imp_finite_random_variable[OF `simple_function X`]
1.300 -    by (rule distribution_finite_prob_space)
1.301 +  let ?X = "\<lparr> space = X ` space M, sets = Pow (X ` space M), measure = distribution X\<rparr>"
1.302 +  note simple_function_imp_finite_random_variable[OF `simple_function M X`]
1.303 +  from distribution_finite_prob_space[OF this, of "\<lparr> measure = distribution X \<rparr>"]
1.304 +  interpret X: finite_prob_space ?X by simp
1.305    have card_gt0: "0 < card (X ` space M)" unfolding card_gt_0_iff
1.306 -    using `simple_function X` not_empty by (auto simp: simple_function_def)
1.307 +    using `simple_function M X` not_empty by (auto simp: simple_function_def)
1.308    { fix x assume "x \<in> X ` space M"
1.309      hence "real (distribution X {x}) = 1 / real (card (X ` space M))"
1.310      proof (rule X.uniform_prob[simplified])
1.311 @@ -423,18 +446,18 @@
1.312      qed }
1.313    thus ?thesis
1.314      using not_empty X.finite_space b_gt_1 card_gt0
1.315 -    by (simp add: entropy_eq[OF `simple_function X`] real_eq_of_nat[symmetric] log_simps)
1.316 +    by (simp add: entropy_eq[OF `simple_function M X`] real_eq_of_nat[symmetric] log_simps)
1.317  qed
1.318
1.319  lemma (in information_space) entropy_le_card:
1.320 -  assumes "simple_function X"
1.321 +  assumes "simple_function M X"
1.322    shows "\<H>(X) \<le> log b (real (card (X ` space M)))"
1.323  proof cases
1.324    assume "X ` space M \<inter> {x. distribution X {x} \<noteq> 0} = {}"
1.325    then have "\<And>x. x\<in>X`space M \<Longrightarrow> distribution X {x} = 0" by auto
1.326    moreover
1.327    have "0 < card (X`space M)"
1.328 -    using `simple_function X` not_empty
1.329 +    using `simple_function M X` not_empty
1.330      by (auto simp: card_gt_0_iff simple_function_def)
1.331    then have "log b 1 \<le> log b (real (card (X`space M)))"
1.332      using b_gt_1 by (intro log_le) auto
1.333 @@ -451,10 +474,10 @@
1.334  qed
1.335
1.336  lemma (in information_space) entropy_commute:
1.337 -  assumes "simple_function X" "simple_function Y"
1.338 +  assumes "simple_function M X" "simple_function M Y"
1.339    shows "\<H>(\<lambda>x. (X x, Y x)) = \<H>(\<lambda>x. (Y x, X x))"
1.340  proof -
1.341 -  have sf: "simple_function (\<lambda>x. (X x, Y x))" "simple_function (\<lambda>x. (Y x, X x))"
1.342 +  have sf: "simple_function M (\<lambda>x. (X x, Y x))" "simple_function M (\<lambda>x. (Y x, X x))"
1.343      using assms by (auto intro: simple_function_Pair)
1.344    have *: "(\<lambda>x. (Y x, X x))`space M = (\<lambda>(a,b). (b,a))`(\<lambda>x. (X x, Y x))`space M"
1.345      by auto
1.346 @@ -466,12 +489,12 @@
1.347  qed
1.348
1.349  lemma (in information_space) entropy_eq_cartesian_product:
1.350 -  assumes "simple_function X" "simple_function Y"
1.351 +  assumes "simple_function M X" "simple_function M Y"
1.352    shows "\<H>(\<lambda>x. (X x, Y x)) = -(\<Sum>x\<in>X`space M. \<Sum>y\<in>Y`space M.
1.353      real (joint_distribution X Y {(x,y)}) *
1.354      log b (real (joint_distribution X Y {(x,y)})))"
1.355  proof -
1.356 -  have sf: "simple_function (\<lambda>x. (X x, Y x))"
1.357 +  have sf: "simple_function M (\<lambda>x. (X x, Y x))"
1.358      using assms by (auto intro: simple_function_Pair)
1.359    { fix x assume "x\<notin>(\<lambda>x. (X x, Y x))`space M"
1.360      then have "(\<lambda>x. (X x, Y x)) -` {x} \<inter> space M = {}" by auto
1.361 @@ -485,19 +508,18 @@
1.362  subsection {* Conditional Mutual Information *}
1.363
1.364  definition (in prob_space)
1.365 -  "conditional_mutual_information b M1 M2 M3 X Y Z \<equiv>
1.366 -    mutual_information b M1 (sigma (pair_algebra M2 M3)) X (\<lambda>x. (Y x, Z x)) -
1.367 -    mutual_information b M1 M3 X Z"
1.368 +  "conditional_mutual_information b MX MY MZ X Y Z \<equiv>
1.369 +    mutual_information b MX (MY \<Otimes>\<^isub>M MZ) X (\<lambda>x. (Y x, Z x)) -
1.370 +    mutual_information b MX MZ X Z"
1.371
1.372  abbreviation (in information_space)
1.373    conditional_mutual_information_Pow ("\<I>'( _ ; _ | _ ')") where
1.374    "\<I>(X ; Y | Z) \<equiv> conditional_mutual_information b
1.375 -    \<lparr> space = X`space M, sets = Pow (X`space M) \<rparr>
1.376 -    \<lparr> space = Y`space M, sets = Pow (Y`space M) \<rparr>
1.377 -    \<lparr> space = Z`space M, sets = Pow (Z`space M) \<rparr>
1.378 +    \<lparr> space = X`space M, sets = Pow (X`space M), measure = distribution X \<rparr>
1.379 +    \<lparr> space = Y`space M, sets = Pow (Y`space M), measure = distribution Y \<rparr>
1.380 +    \<lparr> space = Z`space M, sets = Pow (Z`space M), measure = distribution Z \<rparr>
1.381      X Y Z"
1.382
1.383 -
1.384  lemma (in information_space) conditional_mutual_information_generic_eq:
1.385    assumes MX: "finite_random_variable MX X"
1.386      and MY: "finite_random_variable MY Y"
1.387 @@ -519,7 +541,7 @@
1.388    note finite_var = MX MY MZ
1.389    note random_var = finite_var[THEN finite_random_variableD]
1.390
1.391 -  note space_simps = space_pair_algebra space_sigma algebra.simps
1.392 +  note space_simps = space_pair_measure space_sigma algebra.simps
1.393
1.394    note YZ = finite_random_variable_pairI[OF finite_var(2,3)]
1.395    note XZ = finite_random_variable_pairI[OF finite_var(1,3)]
1.396 @@ -574,12 +596,12 @@
1.397      unfolding conditional_mutual_information_def
1.398      unfolding mutual_information_generic_eq[OF finite_var(1,3)]
1.399      unfolding mutual_information_generic_eq[OF finite_var(1) YZ]
1.400 -    by (simp add: space_sigma space_pair_algebra setsum_cartesian_product')
1.401 +    by (simp add: space_sigma space_pair_measure setsum_cartesian_product')
1.402    finally show ?thesis by simp
1.403  qed
1.404
1.405  lemma (in information_space) conditional_mutual_information_eq:
1.406 -  assumes "simple_function X" "simple_function Y" "simple_function Z"
1.407 +  assumes "simple_function M X" "simple_function M Y" "simple_function M Z"
1.408    shows "\<I>(X;Y|Z) = (\<Sum>(x, y, z) \<in> X`space M \<times> Y`space M \<times> Z`space M.
1.409               real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) *
1.410               log b (real (distribution (\<lambda>x. (X x, Y x, Z x)) {(x, y, z)}) /
1.411 @@ -588,11 +610,11 @@
1.412    by simp
1.413
1.414  lemma (in information_space) conditional_mutual_information_eq_mutual_information:
1.415 -  assumes X: "simple_function X" and Y: "simple_function Y"
1.416 +  assumes X: "simple_function M X" and Y: "simple_function M Y"
1.417    shows "\<I>(X ; Y) = \<I>(X ; Y | (\<lambda>x. ()))"
1.418  proof -
1.419    have [simp]: "(\<lambda>x. ()) ` space M = {()}" using not_empty by auto
1.420 -  have C: "simple_function (\<lambda>x. ())" by auto
1.421 +  have C: "simple_function M (\<lambda>x. ())" by auto
1.422    show ?thesis
1.423      unfolding conditional_mutual_information_eq[OF X Y C]
1.424      unfolding mutual_information_eq[OF X Y]
1.425 @@ -608,12 +630,13 @@
1.426  lemma (in prob_space) setsum_distribution:
1.427    assumes X: "finite_random_variable MX X" shows "(\<Sum>a\<in>space MX. distribution X {a}) = 1"
1.428    using setsum_joint_distribution[OF assms, of "\<lparr> space = UNIV, sets = Pow UNIV \<rparr>" "\<lambda>x. ()" "{()}"]
1.429 -  using sigma_algebra_Pow[of "UNIV::unit set"] by simp
1.430 +  using sigma_algebra_Pow[of "UNIV::unit set" "()"] by simp
1.431
1.432  lemma (in prob_space) setsum_real_distribution:
1.433 +  fixes MX :: "('c, 'd) measure_space_scheme"
1.434    assumes X: "finite_random_variable MX X" shows "(\<Sum>a\<in>space MX. real (distribution X {a})) = 1"
1.435 -  using setsum_real_joint_distribution[OF assms, of "\<lparr> space = UNIV, sets = Pow UNIV \<rparr>" "\<lambda>x. ()" "{()}"]
1.436 -  using sigma_algebra_Pow[of "UNIV::unit set"] by simp
1.437 +  using setsum_real_joint_distribution[OF assms, of "\<lparr> space = UNIV, sets = Pow UNIV, measure = undefined \<rparr>" "\<lambda>x. ()" "{()}"]
1.438 +  using sigma_algebra_Pow[of "UNIV::unit set" "\<lparr> measure = undefined \<rparr>"] by simp
1.439
1.440  lemma (in information_space) conditional_mutual_information_generic_positive:
1.441    assumes "finite_random_variable MX X" and "finite_random_variable MY Y" and "finite_random_variable MZ Z"
1.442 @@ -633,7 +656,7 @@
1.443
1.444    have split_beta: "\<And>f. split f = (\<lambda>x. f (fst x) (snd x))" by (simp add: fun_eq_iff)
1.445
1.446 -  note space_simps = space_pair_algebra space_sigma algebra.simps
1.447 +  note space_simps = space_pair_measure space_sigma algebra.simps
1.448
1.449    note finite_var = assms
1.450    note YZ = finite_random_variable_pairI[OF finite_var(2,3)]
1.451 @@ -672,7 +695,7 @@
1.452        unfolding setsum_cartesian_product'
1.453        unfolding setsum_commute[of _ "space MY"]
1.454        unfolding setsum_commute[of _ "space MZ"]
1.455 -      by (simp_all add: space_pair_algebra
1.456 +      by (simp_all add: space_pair_measure
1.457          setsum_real_joint_distribution_singleton[OF `finite_random_variable MX X` YZ]
1.458          setsum_real_joint_distribution_singleton[OF `finite_random_variable MY Y` finite_var(3)]
1.459          setsum_real_distribution[OF `finite_random_variable MZ Z`])
1.460 @@ -704,10 +727,9 @@
1.461  qed
1.462
1.463  lemma (in information_space) conditional_mutual_information_positive:
1.464 -  assumes "simple_function X" and "simple_function Y" and "simple_function Z"
1.465 +  assumes "simple_function M X" and "simple_function M Y" and "simple_function M Z"
1.466    shows "0 \<le> \<I>(X;Y|Z)"
1.467 -  using conditional_mutual_information_generic_positive[OF assms[THEN simple_function_imp_finite_random_variable]]
1.468 -  by simp
1.469 +  by (rule conditional_mutual_information_generic_positive[OF assms[THEN simple_function_imp_finite_random_variable]])
1.470
1.471  subsection {* Conditional Entropy *}
1.472
1.473 @@ -717,16 +739,17 @@
1.474  abbreviation (in information_space)
1.475    conditional_entropy_Pow ("\<H>'(_ | _')") where
1.476    "\<H>(X | Y) \<equiv> conditional_entropy b
1.477 -    \<lparr> space = X`space M, sets = Pow (X`space M) \<rparr>
1.478 -    \<lparr> space = Y`space M, sets = Pow (Y`space M) \<rparr> X Y"
1.479 +    \<lparr> space = X`space M, sets = Pow (X`space M), measure = distribution X \<rparr>
1.480 +    \<lparr> space = Y`space M, sets = Pow (Y`space M), measure = distribution Y \<rparr> X Y"
1.481
1.482  lemma (in information_space) conditional_entropy_positive:
1.483 -  "simple_function X \<Longrightarrow> simple_function Y \<Longrightarrow> 0 \<le> \<H>(X | Y)"
1.484 +  "simple_function M X \<Longrightarrow> simple_function M Y \<Longrightarrow> 0 \<le> \<H>(X | Y)"
1.485    unfolding conditional_entropy_def by (auto intro!: conditional_mutual_information_positive)
1.486
1.487  lemma (in measure_space) empty_measureI: "A = {} \<Longrightarrow> \<mu> A = 0" by simp
1.488
1.489  lemma (in information_space) conditional_entropy_generic_eq:
1.490 +  fixes MX :: "('c, 'd) measure_space_scheme" and MY :: "('e, 'f) measure_space_scheme"
1.491    assumes MX: "finite_random_variable MX X"
1.492    assumes MZ: "finite_random_variable MZ Z"
1.493    shows "conditional_entropy b MX MZ X Z =
1.494 @@ -743,7 +766,7 @@
1.495    { fix x z have "?XXZ x x z = ?XZ x z"
1.496        unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>]) }
1.497    note this[simp]
1.498 -  { fix x x' :: 'b and z assume "x' \<noteq> x"
1.499 +  { fix x x' :: 'c and z assume "x' \<noteq> x"
1.500      then have "?XXZ x x' z = 0"
1.501        by (auto simp: distribution_def intro!: arg_cong[where f=\<mu>] empty_measureI) }
1.502    note this[simp]
1.503 @@ -762,7 +785,6 @@
1.504      finally have "(\<Sum>x'\<in>space MX. real (?XXZ x x' z) * ?f x x' z) =
1.505        - real (?XZ x z) * log b (real (?XZ x z) / real (?Z z))" . }
1.506    note * = this
1.507 -
1.508    show ?thesis
1.509      unfolding conditional_entropy_def
1.510      unfolding conditional_mutual_information_generic_eq[OF MX MX MZ]
1.511 @@ -772,7 +794,7 @@
1.512  qed
1.513
1.514  lemma (in information_space) conditional_entropy_eq:
1.515 -  assumes "simple_function X" "simple_function Z"
1.516 +  assumes "simple_function M X" "simple_function M Z"
1.517    shows "\<H>(X | Z) =
1.518       - (\<Sum>(x, z)\<in>X ` space M \<times> Z ` space M.
1.519           real (joint_distribution X Z {(x, z)}) *
1.520 @@ -781,7 +803,7 @@
1.521    by simp
1.522
1.523  lemma (in information_space) conditional_entropy_eq_ce_with_hypothesis:
1.524 -  assumes X: "simple_function X" and Y: "simple_function Y"
1.525 +  assumes X: "simple_function M X" and Y: "simple_function M Y"
1.526    shows "\<H>(X | Y) =
1.527      -(\<Sum>y\<in>Y`space M. real (distribution Y {y}) *
1.528        (\<Sum>x\<in>X`space M. real (joint_distribution X Y {(x,y)}) / real (distribution Y {(y)}) *
1.529 @@ -794,7 +816,7 @@
1.530             intro!: setsum_cong)
1.531
1.532  lemma (in information_space) conditional_entropy_eq_cartesian_product:
1.533 -  assumes "simple_function X" "simple_function Y"
1.534 +  assumes "simple_function M X" "simple_function M Y"
1.535    shows "\<H>(X | Y) = -(\<Sum>x\<in>X`space M. \<Sum>y\<in>Y`space M.
1.536      real (joint_distribution X Y {(x,y)}) *
1.537      log b (real (joint_distribution X Y {(x,y)}) / real (distribution Y {y})))"
1.538 @@ -804,7 +826,7 @@
1.539  subsection {* Equalities *}
1.540
1.541  lemma (in information_space) mutual_information_eq_entropy_conditional_entropy:
1.542 -  assumes X: "simple_function X" and Z: "simple_function Z"
1.543 +  assumes X: "simple_function M X" and Z: "simple_function M Z"
1.544    shows  "\<I>(X ; Z) = \<H>(X) - \<H>(X | Z)"
1.545  proof -
1.546    let "?XZ x z" = "real (joint_distribution X Z {(x, z)})"
1.547 @@ -828,7 +850,7 @@
1.548  qed
1.549
1.550  lemma (in information_space) conditional_entropy_less_eq_entropy:
1.551 -  assumes X: "simple_function X" and Z: "simple_function Z"
1.552 +  assumes X: "simple_function M X" and Z: "simple_function M Z"
1.553    shows "\<H>(X | Z) \<le> \<H>(X)"
1.554  proof -
1.555    have "\<I>(X ; Z) = \<H>(X) - \<H>(X | Z)" using mutual_information_eq_entropy_conditional_entropy[OF assms] .
1.556 @@ -837,7 +859,7 @@
1.557  qed
1.558
1.559  lemma (in information_space) entropy_chain_rule:
1.560 -  assumes X: "simple_function X" and Y: "simple_function Y"
1.561 +  assumes X: "simple_function M X" and Y: "simple_function M Y"
1.562    shows  "\<H>(\<lambda>x. (X x, Y x)) = \<H>(X) + \<H>(Y|X)"
1.563  proof -
1.564    let "?XY x y" = "real (joint_distribution X Y {(x, y)})"
1.565 @@ -976,7 +998,7 @@
1.566  qed
1.567
1.568  lemma (in information_space) entropy_partition:
1.569 -  assumes sf: "simple_function X" "simple_function P"
1.570 +  assumes sf: "simple_function M X" "simple_function M P"
1.571    assumes svi: "subvimage (space M) X P"
1.572    shows "\<H>(X) = \<H>(P) + \<H>(X|P)"
1.573  proof -
1.574 @@ -1026,10 +1048,10 @@
1.575  qed
1.576
1.577  corollary (in information_space) entropy_data_processing:
1.578 -  assumes X: "simple_function X" shows "\<H>(f \<circ> X) \<le> \<H>(X)"
1.579 +  assumes X: "simple_function M X" shows "\<H>(f \<circ> X) \<le> \<H>(X)"
1.580  proof -
1.581    note X
1.582 -  moreover have fX: "simple_function (f \<circ> X)" using X by auto
1.583 +  moreover have fX: "simple_function M (f \<circ> X)" using X by auto
1.584    moreover have "subvimage (space M) X (f \<circ> X)" by auto
1.585    ultimately have "\<H>(X) = \<H>(f\<circ>X) + \<H>(X|f\<circ>X)" by (rule entropy_partition)
1.586    then show "\<H>(f \<circ> X) \<le> \<H>(X)"
1.587 @@ -1037,12 +1059,12 @@
1.588  qed
1.589
1.590  corollary (in information_space) entropy_of_inj:
1.591 -  assumes X: "simple_function X" and inj: "inj_on f (X`space M)"
1.592 +  assumes X: "simple_function M X" and inj: "inj_on f (X`space M)"
1.593    shows "\<H>(f \<circ> X) = \<H>(X)"
1.594  proof (rule antisym)
1.595    show "\<H>(f \<circ> X) \<le> \<H>(X)" using entropy_data_processing[OF X] .
1.596  next
1.597 -  have sf: "simple_function (f \<circ> X)"
1.598 +  have sf: "simple_function M (f \<circ> X)"
1.599      using X by auto
1.600    have "\<H>(X) = \<H>(the_inv_into (X`space M) f \<circ> (f \<circ> X))"
1.601      by (auto intro!: mutual_information_cong simp: entropy_def the_inv_into_f_f[OF inj])
```