File size: 8,338 Bytes
f0f05de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import OAI.Combinatorics.BalancedRyser.Incidence.AffineInjectionGuards
import OAI.Combinatorics.BalancedRyser.Local.AlignedTokenPointLaw

namespace OAI

namespace Balanced.InjectionExposure

noncomputable section
open scoped Classical

variable {I J Z : Type*} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J]

theorem auxiliaryLaw_fst_mem_completions (K : Finset I) (base : I ↪ J)
    (noise : (I ↪ J) → PMF Z) (x : (I ↪ J) × Z)
    (hx : x ∈ (auxiliaryLaw K base noise).support) : x.1 ∈ completions K base := by
  change x ∈ ((PMF.uniformOfFinset (completions K base)
    (completions_nonempty K base)).bind
      (fun e => (noise e).map (fun z => (e,z)))).support at hx
  rw [PMF.mem_support_bind_iff] at hx
  obtain ⟨e,he,hx⟩ := hx
  rw [PMF.mem_support_map_iff] at hx
  obtain ⟨z,hz,hx⟩ := hx
  have he' : e ∈ completions K base := by simpa using he
  have hf := congrArg Prod.fst hx
  simpa only [← hf] using he'

end
end Balanced.InjectionExposure

namespace Balanced.Local.TokenExposure

open AlignedListProbability PartialAlignment InjectionExposure
noncomputable section
open scoped Classical

variable {F : Type*} [Field F] [Fintype F] [DecidableEq F]
variable {b κ : ℕ} {Z : Type*} [Fintype Z]

def pointOutput (P : EqualityPattern b κ) (bits : Bits b) (p : Point F)
    (i : Fin b) (J : Finset (Fin 4)) (hJ : J.card ≤ 1)
    (a : Z → Fin 4 → Bool → F)
    (x : Z → {j : Fin 4 // j ∈ freePositions J} → F)
    (e : DirectionToken b κ ↪ Direction F) (z : Z) (j : Fin 4) : Point F :=
  generatedPositions (tupleDirections P e i) (tupleDirections_adjacent P e i)
    (bits i) (e (Sum.inl i)) (tupleDirections_ne_target P e i)
    (lineEval (e (Sum.inl i)) p) J hJ (a z) (x z) j

theorem projected_left_probability_le
    (P : EqualityPattern b κ) (bits : Bits b) (p : Point F) (i : Fin b)
    (J : Finset (Fin 4)) (hJ : J.card ≤ 1) (j : Fin 4) (hj : j ∈ J)
    (K : Finset (DirectionToken b κ)) (base : DirectionToken b κ ↪ Direction F)
    (htarget : Sum.inl i ∉ K) (hold : Sum.inr (P.classOf i j) ∈ K)
    (noise : (DirectionToken b κ ↪ Direction F) → PMF Z)
    (hnoise : DependsOnExposed K noise)
    (a : Z → Fin 4 → Bool → F)
    (x : Z → {j : Fin 4 // j ∈ freePositions J} → F)
    (m : Z → Line F) :
    ((auxiliaryLaw K base noise).toOuterMeasure
      {ez | (tupleDirections P ez.1 i j, a ez.2 j (bits i j)) ≠ m ez.2 ∧
        pointOutput P bits p i J hJ a x ez.1 ez.2 j ≠ p ∧
        OnLine (pointOutput P bits p i J hJ a x ez.1 ez.2 j) (m ez.2)}).toReal ≤
      1 / ((Fintype.card F + 1 - K.card : ℕ) : ℝ) := by
  let l : Z → Line F := fun z => (base (Sum.inr (P.classOf i j)), a z j (bits i j))
  have h := auxiliary_guarded_projection_probability_le K base (Sum.inl i) htarget
    noise hnoise (fun _ => p) l m
  apply le_trans _ h
  apply ENNReal.toReal_mono
  · rw [PMF.toOuterMeasure_apply]
    exact PMF.tsum_coe_indicator_ne_top _ _
  · apply PMF.toOuterMeasure_mono
    intro ez hez
    have he := (mem_completions K base ez.1).mp
      (auxiliaryLaw_fst_mem_completions K base noise ez hez.2)
    have hd : tupleDirections P ez.1 i j = base (Sum.inr (P.classOf i j)) :=
      he _ hold
    have hp : pointOutput P bits p i J hJ a x ez.1 ez.2 j =
        lineIntersection (l ez.2) (lineThrough (ez.1 (Sum.inl i)) p) := by
      change generatedPositions _ _ _ _ _ _ _ _ _ _ j = _
      rw [generatedPositions_old_left _ _ _ _ _ _ J hJ _ _ j hj]
      rw [hd]
      rfl
    have hne : ez.1 (Sum.inl i) ≠ (l ez.2).1 := by
      change ez.1 (Sum.inl i) ≠ base (Sum.inr (P.classOf i j))
      rw [← hd]
      exact (tupleDirections_ne_target P ez.1 i j).symm
    exact ⟨by simpa only [l, hd] using hez.1.1, hne,
      by simpa only [hp] using hez.1.2.1,
      by simpa only [hp] using hez.1.2.2⟩

theorem projected_right_probability_le
    (P : EqualityPattern b κ) (bits : Bits b) (p : Point F) (i : Fin b)
    (J : Finset (Fin 4)) (hJ : J.card ≤ 1) (j : Fin 4) (hj : j+1 ∈ J)
    (K : Finset (DirectionToken b κ)) (base : DirectionToken b κ ↪ Direction F)
    (htarget : Sum.inl i ∉ K) (hold : Sum.inr (P.classOf i (j+1)) ∈ K)
    (noise : (DirectionToken b κ ↪ Direction F) → PMF Z)
    (hnoise : DependsOnExposed K noise)
    (a : Z → Fin 4 → Bool → F)
    (x : Z → {j : Fin 4 // j ∈ freePositions J} → F)
    (m : Z → Line F) :
    ((auxiliaryLaw K base noise).toOuterMeasure
      {ez | (tupleDirections P ez.1 i (j+1), a ez.2 (j+1) (!(bits i (j+1)))) ≠ m ez.2 ∧
        pointOutput P bits p i J hJ a x ez.1 ez.2 j ≠ p ∧
        OnLine (pointOutput P bits p i J hJ a x ez.1 ez.2 j) (m ez.2)}).toReal ≤
      1 / ((Fintype.card F + 1 - K.card : ℕ) : ℝ) := by
  let l : Z → Line F := fun z =>
    (base (Sum.inr (P.classOf i (j+1))), a z (j+1) (!(bits i (j+1))))
  have h := auxiliary_guarded_projection_probability_le K base (Sum.inl i) htarget
    noise hnoise (fun _ => p) l m
  apply le_trans _ h
  apply ENNReal.toReal_mono
  · rw [PMF.toOuterMeasure_apply]
    exact PMF.tsum_coe_indicator_ne_top _ _
  · apply PMF.toOuterMeasure_mono
    intro ez hez
    have he := (mem_completions K base ez.1).mp
      (auxiliaryLaw_fst_mem_completions K base noise ez hez.2)
    have hd : tupleDirections P ez.1 i (j+1) = base (Sum.inr (P.classOf i (j+1))) :=
      he _ hold
    have hp : pointOutput P bits p i J hJ a x ez.1 ez.2 j =
        lineIntersection (l ez.2) (lineThrough (ez.1 (Sum.inl i)) p) := by
      change generatedPositions _ _ _ _ _ _ _ _ _ _ j = _
      rw [generatedPositions_old_right _ _ _ _ _ _ J hJ _ _ j hj]
      rw [hd]
      rfl
    have hne : ez.1 (Sum.inl i) ≠ (l ez.2).1 := by
      change ez.1 (Sum.inl i) ≠ base (Sum.inr (P.classOf i (j+1)))
      rw [← hd]
      exact (tupleDirections_ne_target P ez.1 i (j+1)).symm
    exact ⟨by simpa only [l, hd] using hez.1.1, hne,
      by simpa only [hp] using hez.1.2.1,
      by simpa only [hp] using hez.1.2.2⟩

theorem projected_left_probability_le_two_div
    (P : EqualityPattern b κ) (bits : Bits b) (p : Point F) (i : Fin b)
    (J : Finset (Fin 4)) (hJ : J.card ≤ 1) (j : Fin 4) (hj : j ∈ J)
    (K : Finset (DirectionToken b κ)) (base : DirectionToken b κ ↪ Direction F)
    (htarget : Sum.inl i ∉ K) (hold : Sum.inr (P.classOf i j) ∈ K)
    (noise : (DirectionToken b κ ↪ Direction F) → PMF Z)
    (hnoise : DependsOnExposed K noise)
    (a : Z → Fin 4 → Bool → F)
    (x : Z → {j : Fin 4 // j ∈ freePositions J} → F)
    (m : Z → Line F) (hK : K.card ≤ 5 * b)
    (hb : 10 * b ≤ Fintype.card F) :
    ((auxiliaryLaw K base noise).toOuterMeasure
      {ez | (tupleDirections P ez.1 i j, a ez.2 j (bits i j)) ≠ m ez.2 ∧
        pointOutput P bits p i J hJ a x ez.1 ez.2 j ≠ p ∧
        OnLine (pointOutput P bits p i J hJ a x ez.1 ez.2 j) (m ez.2)}).toReal ≤
      2 / (Fintype.card F : ℝ) := by
  exact (projected_left_probability_le P bits p i J hJ j hj K base
    htarget hold noise hnoise a x m).trans
    (inverse_remaining_le_two_div (Fintype.card F) K.card b
      Fintype.card_pos hK hb)

theorem projected_right_probability_le_two_div
    (P : EqualityPattern b κ) (bits : Bits b) (p : Point F) (i : Fin b)
    (J : Finset (Fin 4)) (hJ : J.card ≤ 1) (j : Fin 4) (hj : j+1 ∈ J)
    (K : Finset (DirectionToken b κ)) (base : DirectionToken b κ ↪ Direction F)
    (htarget : Sum.inl i ∉ K) (hold : Sum.inr (P.classOf i (j+1)) ∈ K)
    (noise : (DirectionToken b κ ↪ Direction F) → PMF Z)
    (hnoise : DependsOnExposed K noise)
    (a : Z → Fin 4 → Bool → F)
    (x : Z → {j : Fin 4 // j ∈ freePositions J} → F)
    (m : Z → Line F) (hK : K.card ≤ 5 * b)
    (hb : 10 * b ≤ Fintype.card F) :
    ((auxiliaryLaw K base noise).toOuterMeasure
      {ez | (tupleDirections P ez.1 i (j+1), a ez.2 (j+1) (!(bits i (j+1)))) ≠ m ez.2 ∧
        pointOutput P bits p i J hJ a x ez.1 ez.2 j ≠ p ∧
        OnLine (pointOutput P bits p i J hJ a x ez.1 ez.2 j) (m ez.2)}).toReal ≤
      2 / (Fintype.card F : ℝ) := by
  exact (projected_right_probability_le P bits p i J hJ j hj K base
    htarget hold noise hnoise a x m).trans
    (inverse_remaining_le_two_div (Fintype.card F) K.card b
      Fintype.card_pos hK hb)

end
end Balanced.Local.TokenExposure

end OAI