Datasets:

ArXiv:
License:
File size: 6,390 Bytes
bf6216d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
module

public import Mathlib.Algebra.BigOperators.Field
public import Mathlib.Analysis.Convex.Jensen
public import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog

/-!
# Entropy function

The purpose of this file is to record basic analytic properties of the function
$$h(x) = - x * \log x$$ on the unit interval, for use in the theory of Shannon entropy.

## Main results

* `sum_negMulLog_le`: a Jensen inequality for `negMulLog`
* `sum_negMulLog_eq`: the equality case of this inequality

-/

public section

open scoped ENNReal NNReal Topology

namespace Real
variable {ι : Type*} {s : Finset ι} {w : ι → ℝ} {p : ι → ℝ}

/-- If $S$ is a finite set, and $a_s$, $b_s$ are non-negative for $s\in S$, then
  $$\sum_{s\in S} a_s \log\frac{a_s}{b_s}\ge
    \left(\sum_{s\in S}a_s\right)\log\frac{\sum_{s\in S} a_s}{\sum_{s\in S} b_s}$$.
  We require additionally that, if $b_s=0$, then $s_s=0$ as otherwise the right hand side should
  morally be infinite, which it can't be in the formalization using real numbers. -/
lemma sum_mul_log_div_leq {a b : ι → ℝ} (ha : ∀ i ∈ s, 0 ≤ a i) (hb : ∀ i ∈ s, 0 ≤ b i)
    (habs : ∀ i ∈ s, b i = 0 → a i = 0) :
    (∑ i ∈ s, a i) * log ((∑ i ∈ s, a i) / (∑ i ∈ s, b i)) ≤ ∑ i ∈ s, a i * log (a i / b i) := by
  by_cases h : ∀ i ∈ s, b i = 0
  · have A : ∑ i ∈ s, b i = ∑ i ∈ s, 0 := Finset.sum_congr rfl (fun i hi ↦ h i hi)
    have B : ∑ i ∈ s, a i * log (a i / b i) = ∑ i ∈ s, a i * log (a i / 0) := by
      apply Finset.sum_congr rfl (fun i hi ↦ by simp [h i hi])
    simp [A, B]
  let B := ∑ i ∈ s, b i
  have B_pos : 0 < B := by
    apply Finset.sum_pos' hb
    simp only [not_forall] at h
    rcases h with ⟨i, hi, h'i⟩
    exact ⟨i, hi, lt_of_le_of_ne (hb i hi) (Ne.symm h'i)⟩
  suffices - (∑ i ∈ s, a i * log (a i / b i)) / B ≤
        - ((∑ i ∈ s, a i) * log ((∑ i ∈ s, a i) / (∑ i ∈ s, b i))) / B by
    rwa [div_le_div_iff_of_pos_right B_pos, neg_le_neg_iff] at this
  have A : ∑ i ∈ s, b i / B = 1 := by simp [← Finset.sum_div, B, div_self B_pos.ne']
  have A' : ∀ i ∈ s, 0 ≤ b i / B := fun i hi ↦ div_nonneg (hb i hi) B_pos.le
  have A'' : ∀ i ∈ s, 0 ≤ a i / b i := fun i hi ↦ div_nonneg (ha i hi) (hb i hi)
  convert! ConcaveOn.le_map_sum Real.concaveOn_negMulLog A' A (p := fun i ↦ a i / b i) A'' using 1
  · simp only [negMulLog, neg_mul, smul_eq_mul, mul_neg, Finset.sum_neg_distrib]
    rw [neg_div, Finset.sum_div]
    congr 1
    apply Finset.sum_congr rfl (fun i hi ↦ ?_)
    rcases eq_or_lt_of_le (hb i hi) with h'i | h'i
    · simp [← h'i, habs i hi h'i.symm]
    · field_simp
  · have : ∑ x ∈ s, b x / B * (a x / b x) = (∑ x ∈ s, a x) / B := by
      rw [Finset.sum_div]
      apply Finset.sum_congr rfl (fun i hi ↦ ?_)
      rcases eq_or_lt_of_le (hb i hi) with h'i | h'i
      · simp [← h'i, habs i hi h'i.symm]
      · field_simp
    simp only [negMulLog, smul_eq_mul, neg_mul, this]
    ring

/-- If equality holds in the previous bound, then $a_s=r\cdot b_s$ for every $s\in S$, for some
constant $r\in \mathbb{R}$. Auxiliary version assuming the `b i` are positive. -/
lemma sum_mul_log_div_eq_iff_aux {a b : ι → ℝ} (ha : ∀ i ∈ s, 0 ≤ a i) (hb : ∀ i ∈ s, 0 < b i)
    (heq : ∑ i ∈ s, a i * log (a i / b i) = (∑ i ∈ s, a i) * log ((∑ i ∈ s, a i) / ∑ i ∈ s, b i)) :
    ∃ r, ∀ i ∈ s, a i = r * (b i) := by
  rcases Finset.eq_empty_or_nonempty s with rfl | h's
  · simp
  let B := ∑ i ∈ s, b i
  have B_pos : 0 < B := Finset.sum_pos hb h's
  suffices ∀ j ∈ s, a j / b j = ∑ i ∈ s, (b i / B) * (a i / b i) by
    refine ⟨∑ i ∈ s, (b i / B) * (a i / b i), fun j hj ↦ ?_⟩
    specialize this j hj
    rwa [div_eq_iff (hb j hj).ne'] at this
  have A : ∑ i ∈ s, b i / B = 1 := by simp [← Finset.sum_div, B, div_self B_pos.ne']
  have A' : ∀ i ∈ s, 0 < b i / B := fun i hi ↦ div_pos (hb i hi) B_pos
  have A'' : ∀ i ∈ s, 0 ≤ a i / b i := fun i hi ↦ div_nonneg (ha i hi) (hb i hi).le
  apply (StrictConcaveOn.map_sum_eq_iff Real.strictConcaveOn_negMulLog A' A A'').1
  have : ∑ x ∈ s, b x / B * (a x / b x) = (∑ x ∈ s, a x) / B := by
    rw [Finset.sum_div]
    apply Finset.sum_congr rfl (fun i hi ↦ ?_)
    have : 0 < b i := hb i hi
    field_simp
  simp only [negMulLog, smul_eq_mul, this, neg_mul, mul_neg, Finset.sum_neg_distrib, neg_inj]
  rw [← mul_div_right_comm, ← heq, Finset.sum_div]
  apply Finset.sum_congr rfl (fun i hi ↦ ?_)
  have : 0 < b i := hb i hi
  field_simp

/-- If equality holds in the previous bound, then $a_s=r\cdot b_s$ for every $s\in S$, for some
constant $r\in \mathbb{R}$. -/
lemma sum_mul_log_div_eq_iff {a b : ι → ℝ} (ha : ∀ i ∈ s, 0 ≤ a i) (hb : ∀ i ∈ s, 0 ≤ b i)
    (habs : ∀ i ∈ s, b i = 0 → a i = 0)
    (heq : ∑ i ∈ s, a i * log (a i / b i)
      = (∑ i ∈ s, a i) * log ((∑ i ∈ s, a i) / (∑ i ∈ s, b i))) :
    ∃ r, ∀ i ∈ s, a i = r * (b i) := by
  let s' : Finset ι := s.filter (fun i ↦ 0 < b i)
  have A : ∑ i ∈ s', a i = ∑ i ∈ s, a i := by
    apply Finset.sum_subset (Finset.filter_subset _ _)
    intro i hi h'i
    simp only [Finset.mem_filter, hi, true_and, not_lt] at h'i
    exact habs i hi (le_antisymm h'i (hb i hi))
  have B : ∑ i ∈ s', b i = ∑ i ∈ s, b i := by
    apply Finset.sum_subset (Finset.filter_subset _ _)
    intro i hi h'i
    simp only [Finset.mem_filter, hi, true_and, not_lt] at h'i
    exact le_antisymm h'i (hb i hi)
  have C : ∑ i ∈ s', a i * log (a i / b i) =
      (∑ i ∈ s', a i) * log ((∑ i ∈ s', a i) / (∑ i ∈ s', b i)) := by
    convert heq using 1
    · apply Finset.sum_subset (Finset.filter_subset _ _)
      intro i hi h'i
      simp only [Finset.mem_filter, hi, true_and, not_lt] at h'i
      have : b i = 0 := le_antisymm h'i (hb i hi)
      simp [this]
    · simp [A, B]
  obtain ⟨r, hr⟩ : ∃ r, ∀ i ∈ s', a i = r * (b i) := by
    apply sum_mul_log_div_eq_iff_aux (fun i hi ↦ ha i ?_) (fun i hi ↦ ?_) C
    · simp only [Finset.mem_filter, s'] at hi
      exact hi.1
    · simp only [Finset.mem_filter, s'] at hi
      exact hi.2
  refine ⟨r, fun i hi ↦ ?_⟩
  rcases eq_or_lt_of_le (hb i hi) with h'i | h'i
  · simp [← h'i, habs i hi h'i.symm]
  · apply hr
    simp [s', hi, h'i]

end Real