File size: 4,737 Bytes
f205175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.Probability.CriticalPercolation.ProductMeasure.Delta
import OAI.Probability.CriticalPercolation.Exploration.QueryTree
import OAI.Probability.CriticalPercolation.Modular.PushMass

namespace OAI

section
section
open Set MeasureTheory ProbabilityTheory
open scoped Classical
open Real
open Set Real
open scoped Topology
open scoped BigOperators
open Set

namespace CriticalPercolation.QueryTree
open FiniteProduct FiniteEntropy

variable {E : Type*} [Fintype E]

noncomputable def bitWeight (p : ℝ) (_ : E) (b : Bool) : ℝ := if b then p else 1-p

omit [Fintype E] in
lemma bitWeight_sum (p : ℝ) (e : E) : ∑ b, bitWeight p e b = 1 := by
  simp [bitWeight]

omit [Fintype E] in
lemma bitWeight_nonneg {p : ℝ} (hp : p ∈ Set.Icc 0 1) (e : E) (b : Bool) :
    0 ≤ bitWeight p e b := by cases b <;> simp [bitWeight, hp.1, hp.2]

lemma expect_indicator (p : ℝ) {Y : Type*} (f : (E → Bool) → Y) (y : Y) :
    expect (bitWeight p) (fun ω => if f ω = y then 1 else 0) =
      pushMass f (density (bitWeight p)) y := by
  classical
  simp only [expect, pushMass, mul_ite, mul_one, mul_zero]

lemma reference_eq_product_push (p : ℝ) (t : QueryTree E)
    (used : Finset E) (hv : t.Valid used) :
    pushMass t.run (density (bitWeight p)) = t.reference p := by
  classical
  induction t generalizing used with
  | stop =>
    funext x
    have : x = PUnit.unit := Subsingleton.elim _ _
    subst x
    simp only [pushMass, run, reference]
    exact sum_density _ (bitWeight_sum p)
  | ask e left right hl hr =>
    have hi (b : Bool) : DependsOn (fun ω : E → Bool => if ω e = b then (1:ℝ) else 0)
        ({e} : Set E) := by
      intro ω ω' hω
      dsimp only
      rw [hω e (Set.mem_singleton e)]
    have hc (u : QueryTree E) (hu : u.Valid (insert e used)) (x : u.Leaf) :
        DependsOn (fun ω => if u.run ω = x then (1:ℝ) else 0) ({e} : Set E)ᶜ := by
      intro ω ω' hω
      have heq : u.run ω = u.run ω' := run_dependsOn u _ hu (fun j hj =>
        hω j (by intro hje; have hje : j = e := hje; subst j
                 exact hj (Finset.mem_insert_self _ _)))
      dsimp only
      rw [heq]
    funext x
    cases x with
    | inl x =>
      have heq : (fun ω => if (ask e left right).run ω = Sum.inl x then (1:ℝ) else 0) =
          (fun ω => (if ω e = false then (1:ℝ) else 0) *
            (if left.run ω = x then 1 else 0)) := by
        funext ω
        cases he : ω e <;> simp [run, he]
      have hm : pushMass (ask e left right).run (density (bitWeight p)) (Sum.inl x) =
          expect (bitWeight p) (fun ω => if (ask e left right).run ω = Sum.inl x then 1 else 0) := by
        simp only [pushMass, expect, mul_ite, mul_one, mul_zero]
        apply Finset.sum_congr rfl
        intro ω _
        split_ifs <;> simp_all
      rw [hm, heq, expect_indep _ (bitWeight_sum p) _ (hi false)
        (hc left hv.2.1 x)]
      have hev : expect (bitWeight p) (fun ω => if ω e = false then 1 else 0) =
          bitWeight p e false := by
        convert expect_eval_indicator (bitWeight p) (bitWeight_sum p) e false using 1
        congr 1
        funext ω
        split_ifs <;> simp_all
      rw [hev]
      have hm' : expect (bitWeight p) (fun ω => if left.run ω = x then 1 else 0) =
          pushMass left.run (density (bitWeight p)) x := by
        simp only [pushMass, expect, mul_ite, mul_one, mul_zero]
      rw [hm', hl _ hv.2.1]
      rfl
    | inr x =>
      have heq : (fun ω => if (ask e left right).run ω = Sum.inr x then (1:ℝ) else 0) =
          (fun ω => (if ω e = true then (1:ℝ) else 0) *
            (if right.run ω = x then 1 else 0)) := by
        funext ω
        cases he : ω e <;> simp [run, he]
      have hm : pushMass (ask e left right).run (density (bitWeight p)) (Sum.inr x) =
          expect (bitWeight p) (fun ω => if (ask e left right).run ω = Sum.inr x then 1 else 0) := by
        simp only [pushMass, expect, mul_ite, mul_one, mul_zero]
        apply Finset.sum_congr rfl
        intro ω _
        split_ifs <;> simp_all
      rw [hm, heq, expect_indep _ (bitWeight_sum p) _ (hi true)
        (hc right hv.2.2 x)]
      have hev : expect (bitWeight p) (fun ω => if ω e = true then 1 else 0) =
          bitWeight p e true := by
        convert expect_eval_indicator (bitWeight p) (bitWeight_sum p) e true using 1
        congr 1
        funext ω
        split_ifs <;> simp_all
      rw [hev]
      have hm' : expect (bitWeight p) (fun ω => if right.run ω = x then 1 else 0) =
          pushMass right.run (density (bitWeight p)) x := by
        simp only [pushMass, expect, mul_ite, mul_one, mul_zero]
      rw [hm', hr _ hv.2.2]
      rfl

end CriticalPercolation.QueryTree

end
end

end OAI