File size: 5,353 Bytes
9dbc64e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
138
139
140
141
142
import OAI.Computability.DepthThree.EntropyBits
import OAI.Computability.DepthThree.EntropyThreshold
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Ring

namespace OAI

universe uDepth1

noncomputable section

namespace DepthThreeLowerBound

open scoped BigOperators

theorem finite_card_le_of_uniform_weight_lower_bound {α : Type uDepth1} [Fintype α]
    (A : Finset α) (w : α → ℝ) {δ : ℝ} (hδ : 0 < δ)
    (hw : ∀ a, 0 ≤ w a) (hsum : ∑ a, w a ≤ 1)
    (hlower : ∀ a ∈ A, δ ≤ w a) : (A.card : ℝ) ≤ 1 / δ := by
  classical
  have hcard : (A.card : ℝ) * δ ≤ 1 := by
    calc
      (A.card : ℝ) * δ = ∑ _a ∈ A, δ := by simp
      _ ≤ ∑ a ∈ A, w a := Finset.sum_le_sum hlower
      _ ≤ ∑ a, w a := Finset.sum_le_sum_of_subset_of_nonneg
        (Finset.subset_univ _) (fun a _ _ => hw a)
      _ ≤ 1 := hsum
  exact (le_div_iff₀ hδ).2 hcard

def bernoulliStringWeight {N : ℕ} (x : ℝ) (z : Fin N → Bool) : ℝ :=
  ∏ i, if z i = true then x else 1 - x

theorem bernoulliStringWeight_pos {N : ℕ} {x : ℝ} (hx : 0 < x)
    (hx1 : x < 1) (z : Fin N → Bool) : 0 < bernoulliStringWeight x z := by
  apply Finset.prod_pos
  intro i _
  split_ifs
  · exact hx
  · exact sub_pos.mpr hx1

theorem sum_bernoulliStringWeight (N : ℕ) (x : ℝ) :
    ∑ z : Fin N → Bool, bernoulliStringWeight x z = 1 := by
  have hbit : (∑ b : Bool, if b = true then x else 1 - x) = 1 := by
    simp [Fintype.univ_bool]
  calc
    (∑ z : Fin N → Bool, bernoulliStringWeight x z) =
        ∏ _i : Fin N, ∑ b : Bool, if b = true then x else 1 - x :=
      (Fintype.prod_sum (fun (_i : Fin N) (b : Bool) =>
        if b = true then x else 1 - x)).symm
    _ = 1 := by simp only [hbit, Finset.prod_const_one]

theorem log_bernoulliStringWeight {N : ℕ} {x : ℝ} (hx : 0 < x)
    (hx1 : x < 1) (z : Fin N → Bool) :
    Real.log (bernoulliStringWeight x z) =
      (N : ℝ) * Real.log (1 - x) +
        (trueCount z : ℝ) * (Real.log x - Real.log (1 - x)) := by
  have hne : ∀ i ∈ (Finset.univ : Finset (Fin N)),
      (if z i = true then x else 1 - x) ≠ 0 := by
    intro i _
    split_ifs
    · exact ne_of_gt hx
    · exact ne_of_gt (sub_pos.mpr hx1)
  rw [bernoulliStringWeight, Real.log_prod hne]
  calc
    (∑ i : Fin N, Real.log (if z i = true then x else 1 - x)) =
        ∑ i : Fin N, (Real.log (1 - x) +
          (if z i = true then (1 : ℝ) else 0) *
            (Real.log x - Real.log (1 - x))) := by
      apply Finset.sum_congr rfl
      intro i _
      split_ifs <;> ring
    _ = (N : ℝ) * Real.log (1 - x) +
        (trueCount z : ℝ) * (Real.log x - Real.log (1 - x)) := by
      rw [Finset.sum_add_distrib, ← Finset.sum_mul, ← trueCount_cast]
      simp

theorem bernoulliStringWeight_lower_bound {N : ℕ} {x : ℝ}
    (hx : 0 < x) (hxhalf : x ≤ 1 / 2) (z : Fin N → Bool)
    (hz : (trueCount z : ℝ) ≤ (N : ℝ) * x) :
    Real.exp (-((N : ℝ) * binaryEntropy x * Real.log 2)) ≤
      bernoulliStringWeight x z := by
  have hx1 : x < 1 := by linarith
  have hc : Real.log x - Real.log (1 - x) ≤ 0 := by
    apply sub_nonpos.mpr
    apply Real.log_le_log hx
    linarith
  have hmul := mul_le_mul_of_nonpos_right hz hc
  have hlog : -((N : ℝ) * binaryEntropy x * Real.log 2) ≤
      Real.log (bernoulliStringWeight x z) := by
    rw [log_bernoulliStringWeight hx hx1]
    calc
      -((N : ℝ) * binaryEntropy x * Real.log 2) =
          (N : ℝ) * Real.log (1 - x) +
            ((N : ℝ) * x) * (Real.log x - Real.log (1 - x)) := by
        rw [mul_assoc, binaryEntropy_mul_log_two]
        ring
      _ ≤ (N : ℝ) * Real.log (1 - x) +
          (trueCount z : ℝ) * (Real.log x - Real.log (1 - x)) :=
        add_le_add_right hmul _
  calc
    Real.exp (-((N : ℝ) * binaryEntropy x * Real.log 2)) ≤
        Real.exp (Real.log (bernoulliStringWeight x z)) :=
      Real.exp_le_exp.mpr hlog
    _ = bernoulliStringWeight x z :=
      Real.exp_log (bernoulliStringWeight_pos hx hx1 z)

def sparseBinaryStrings (N : ℕ) (x : ℝ) : Finset (Fin N → Bool) := by
  classical
  exact Finset.univ.filter fun z => (trueCount z : ℝ) ≤ (N : ℝ) * x

theorem card_sparse_binary_strings_le (N : ℕ) {x : ℝ}
    (hx : 0 < x) (hxhalf : x ≤ 1 / 2) :
    ((sparseBinaryStrings N x).card : ℝ) ≤
      (2 : ℝ) ^ ((N : ℝ) * binaryEntropy x) := by
  classical
  have hx1 : x < 1 := by linarith
  have h := finite_card_le_of_uniform_weight_lower_bound
    (sparseBinaryStrings N x) (bernoulliStringWeight x)
    (Real.exp_pos (-((N : ℝ) * binaryEntropy x * Real.log 2)))
    (fun z => (bernoulliStringWeight_pos hx hx1 z).le)
    (sum_bernoulliStringWeight N x).le
    (fun z hz => bernoulliStringWeight_lower_bound hx hxhalf z
      (Finset.mem_filter.mp hz).2)
  calc
    ((sparseBinaryStrings N x).card : ℝ) ≤
        1 / Real.exp (-((N : ℝ) * binaryEntropy x * Real.log 2)) := h
    _ = Real.exp ((N : ℝ) * binaryEntropy x * Real.log 2) := by
      rw [one_div, Real.exp_neg, inv_inv]
    _ = (2 : ℝ) ^ ((N : ℝ) * binaryEntropy x) := by
      rw [Real.rpow_def_of_pos (show (0 : ℝ) < 2 by norm_num)]
      congr 1
      ring

end DepthThreeLowerBound

end

end OAI