File size: 10,737 Bytes
f89a930
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import OAI.NumberTheory.Jacobsthal.Partitions.CommonCellSum
import OAI.NumberTheory.Jacobsthal.Partitions.FiniteLabelBudget
import OAI.NumberTheory.Jacobsthal.Primes.ConditionalPrimeBins

namespace OAI

namespace Erdos970
open scoped _root_.Erdos970

section

namespace NumberTheoryLean.CoupledBoundaryEvents

open _root_.Set _root_.MeasureTheory ProbabilityTheory
open scoped ENNReal
open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain
open ActualSupportIntervals MeshBoundaryGeometry MeshRatioLabels
open PrimeCompletedIntervalUpper ContinuousIntervalUpper ActualCouplingSupport
open RegeneratingInverseBands ContinuousKilledBins

noncomputable def lowerA (Ld Lc : ℝ) : ℝ := max (1/2) (min Ld Lc)
noncomputable def lowerB (mesh Ld Lc : ℝ) : ℝ := max (1/2) (max Ld Lc+mesh)
noncomputable def upperA (mesh Ud Uc : ℝ) : ℝ := max (1/2) (min Ud Uc-mesh)
noncomputable def upperB (Ud Uc : ℝ) : ℝ := max (1/2) (max Ud Uc)

variable {w ell S : ℝ} {start : Node}

def primeBadCells (mesh Ld Lc Ud Uc : ℝ) : Set (ChainState w ell S start) :=
  fun p => match p with
    | none => False
    | some h => ¬fullCell Ld Lc Ud Uc (ratioLabel S mesh h.node.ratio)

def continuousBadCells (S mesh Ld Lc Ud Uc : ℝ) : Set (CemeteryKernel.Space CostState) :=
  fun p => match p with
    | .inr _ => False
    | .inl z => ¬fullCell Ld Lc Ud Uc (ratioLabel S mesh (stateRatio z.1))

theorem packet_widths {mesh : ℝ} (hm : 0 ≤ mesh) (Ld Lc Ud Uc : ℝ) :
    (0 < lowerA Ld Lc ∧ lowerA Ld Lc ≤ lowerB mesh Ld Lc ∧
      lowerB mesh Ld Lc-lowerA Ld Lc ≤ |Ld-Lc|+mesh) ∧
    (0 < upperA mesh Ud Uc ∧ upperA mesh Ud Uc ≤ upperB Ud Uc ∧
      upperB Ud Uc-upperA mesh Ud Uc ≤ |Ud-Uc|+mesh) := by
  have hl : min Ld Lc ≤ max Ld Lc+mesh := by linarith [min_le_max (a:=Ld) (b:=Lc)]
  have hu : min Ud Uc-mesh ≤ max Ud Uc := by linarith [min_le_max (a:=Ud) (b:=Uc)]
  exact ⟨clipped_packet_width hl (le_of_eq (lowerPacket_width mesh Ld Lc)),
    clipped_packet_width hu (le_of_eq (upperPacket_width mesh Ud Uc))⟩

theorem point_in_clipped_packets {mesh t Ld Lc Ud Uc : ℝ} (hm : 0 ≤ mesh) (ht : (1/2:ℝ) ≤ t)
    (h : t ∈ lowerPacket mesh Ld Lc ∪ upperPacket mesh Ud Uc) :
    t ∈ Icc (lowerA Ld Lc) (lowerB mesh Ld Lc) ∪ Icc (upperA mesh Ud Uc) (upperB Ud Uc) := by
  rcases h with h | h
  · exact Or.inl (clipPacket (show min Ld Lc ≤ max Ld Lc+mesh by linarith [min_le_max (a:=Ld) (b:=Lc)]) ht h).1
  · exact Or.inr (clipPacket (show min Ud Uc-mesh ≤ max Ud Uc by linarith [min_le_max (a:=Ud) (b:=Uc)]) ht h).1

theorem prime_bad_cell_packets (h : History w ell S start) (hell : 0 < ell)
    (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S)
    {mesh : ℝ} (hm : 0 < mesh) (Lc Uc : ℝ) :
    let Ld := minRatio h.node.side h.node.ratio
    let Ud := upperSupport S ell h.node.gap
    chain w ell S start (some h) (primeBadCells mesh Ld Lc Ud Uc) ≤
      chain w ell S start (some h) (closedLiveBin (lowerA Ld Lc) (lowerB mesh Ld Lc))+
      chain w ell S start (some h) (closedLiveBin (upperA mesh Ud Uc) (upperB Ud Uc)) := by
  dsimp only
  have hvalid := terminal_valid hs h.admissible
  have hgap := terminal_gap_positive hell.le hr hs h.admissible
  apply le_trans (measure_mono_ae ?_) (measure_union_le _ _)
  filter_upwards [prime_row_interval h hell hgap hvalid] with k hk
  intro hbad
  cases k with
  | none => exact False.elim hbad
  | some k =>
    have hhalf : (1/2:ℝ) ≤ k.node.ratio := PrimeTiltBounds.valid_ge_half (terminal_valid hs k.admissible)
    have hS := terminal_ratio_le hsS k.admissible
    have hp := noninterior_in_packets hm (by linarith : 0 ≤ k.node.ratio) hS (Or.inl hk) hbad
    exact point_in_clipped_packets hm.le hhalf hp

theorem continuous_bad_cell_packets (v : ℝ) (z : CostState) (hell : 0 < ell)
    {mesh : ℝ} (hm : 0 < mesh) (Ld Ud : ℝ) :
    let Lc := minRatio (stateSide z.1) (stateRatio z.1)
    let Uc := upperSupport S ell (gapValue v z)
    continuousChain v ell S (.inl z) (continuousBadCells S mesh Ld Lc Ud Uc) ≤
      continuousChain v ell S (.inl z) (Sum.inl '' closedCostBin (lowerA Ld Lc) (lowerB mesh Ld Lc))+
      continuousChain v ell S (.inl z) (Sum.inl '' closedCostBin (upperA mesh Ud Uc) (upperB Ud Uc)) := by
  dsimp only
  apply le_trans (measure_mono_ae ?_) (measure_union_le _ _)
  filter_upwards [continuous_row_interval v S hell z,continuous_supported v ell S (.inl z)] with y hy hS
  intro hbad
  cases y with
  | inr u => exact False.elim hbad
  | inl y =>
    have hhalf := CostPrefixTransport.stateRatio_ge_half y.1
    have hp := noninterior_in_packets hm (by linarith : 0 ≤ stateRatio y.1) hS (Or.inr hy) hbad
    rcases point_in_clipped_packets hm.le hhalf hp with hp | hp
    · exact Or.inl (Set.mem_image_of_mem Sum.inl hp)
    · exact Or.inr (Set.mem_image_of_mem Sum.inl hp)

end NumberTheoryLean.CoupledBoundaryEvents

end

section


namespace NumberTheoryLean.CouplingLabelEvents

open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory
open scoped ENNReal
open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain
open MeshRatioLabels MeshBoundaryGeometry ActualProcessCoupling ActualCouplingSupport
open CoupledBoundaryEvents KernelBinConditioning FiniteLabelBudget ContinuousKilledBins

noncomputable def interiorLabels (S mesh Ld Lc Ud Uc : ℝ) : Finset (Label S mesh) := by
  classical
  exact Finset.univ.filter (fullCell Ld Lc Ud Uc)

noncomputable def boundaryLabels (S mesh Ld Lc Ud Uc : ℝ) : Finset (Label S mesh) := by
  classical
  exact (Finset.univ.erase (cemeteryLabel S mesh)).filter (fun j => ¬fullCell Ld Lc Ud Uc j)

variable {w ell S : ℝ} {start : Node}

theorem prime_boundary_event {mesh : ℝ} (hm : 0 < mesh)
    (hsS : start.ratio ≤ S) (Ld Lc Ud Uc : ℝ) :
    (primeLabel w ell S mesh start) ⁻¹' (boundaryLabels S mesh Ld Lc Ud Uc : Set (Label S mesh)) =
      primeBadCells mesh Ld Lc Ud Uc := by
  classical
  ext p
  cases p with
  | none =>
    change cemeteryLabel S mesh ∈ boundaryLabels S mesh Ld Lc Ud Uc ↔ False
    simp [boundaryLabels]
  | some h =>
    have hne : ratioLabel S mesh h.node.ratio ≠ cemeteryLabel S mesh := ratioLabel_ne_cemetery hm (terminal_ratio_le hsS h.admissible)
    change ratioLabel S mesh h.node.ratio ∈ boundaryLabels S mesh Ld Lc Ud Uc ↔ ¬fullCell Ld Lc Ud Uc (ratioLabel S mesh h.node.ratio)
    simp [boundaryLabels,hne]

theorem continuous_boundary_event_mass (v ell S : ℝ) {mesh : ℝ} (hm : 0 < mesh)
    (z : CostState) (Ld Lc Ud Uc : ℝ) :
    continuousChain v ell S (.inl z)
      ((continuousLabel S mesh) ⁻¹' (boundaryLabels S mesh Ld Lc Ud Uc : Set (Label S mesh))) =
      continuousChain v ell S (.inl z) (continuousBadCells S mesh Ld Lc Ud Uc) := by
  classical
  apply measure_congr
  filter_upwards [continuous_supported v ell S (.inl z)] with y hy
  apply propext
  cases y with
  | inr u =>
    change cemeteryLabel S mesh ∈ boundaryLabels S mesh Ld Lc Ud Uc ↔ False
    simp [boundaryLabels]
  | inl y =>
    have hne := ratioLabel_ne_cemetery hm hy
    change ratioLabel S mesh (stateRatio y.1) ∈ boundaryLabels S mesh Ld Lc Ud Uc ↔ ¬fullCell Ld Lc Ud Uc (ratioLabel S mesh (stateRatio y.1))
    simp [boundaryLabels,hne]

theorem prime_boundary_mass [IsMarkovKernel (chain w ell S start)] {mesh : ℝ} (hm : 0 < mesh)
    (hsS : start.ratio ≤ S)
    (h : History w ell S start) (Ld Lc Ud Uc : ℝ) :
    (∑ j ∈ boundaryLabels S mesh Ld Lc Ud Uc,labelMass (chain w ell S start) (primeLabel w ell S mesh start) (some h) j) =
      (chain w ell S start (some h) (primeBadCells mesh Ld Lc Ud Uc)).toReal := by
  rw [selected_label_mass _ (primeLabel_measurable w ell S mesh start),prime_boundary_event hm hsS]

theorem continuous_boundary_mass (v ell S : ℝ) {mesh : ℝ} (hm : 0 < mesh)
    (z : CostState) (Ld Lc Ud Uc : ℝ) :
    (∑ j ∈ boundaryLabels S mesh Ld Lc Ud Uc,labelMass (continuousChain v ell S) (continuousLabel S mesh) (.inl z) j) =
      (continuousChain v ell S (.inl z) (continuousBadCells S mesh Ld Lc Ud Uc)).toReal := by
  rw [selected_label_mass _ (continuousLabel_measurable S mesh),continuous_boundary_event_mass v ell S hm z]

theorem actual_label_budget (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell)
    (hS0 : 0 ≤ S) (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap)
    (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S)
    (h : History w ell S start) (v : ℝ) (z : CostState) {mesh : ℝ} (hm : 0 < mesh)
    (Ld Lc Ud Uc : ℝ) :
    (∑ j : Label S mesh, |labelMass (chain w ell S start) (primeLabel w ell S mesh start) (some h) j-
      labelMass (continuousChain v ell S) (continuousLabel S mesh) (.inl z) j|) ≤
      2*((∑ j ∈ interiorLabels S mesh Ld Lc Ud Uc,
        |labelMass (chain w ell S start) (primeLabel w ell S mesh start) (some h) j-
          labelMass (continuousChain v ell S) (continuousLabel S mesh) (.inl z) j|)+
        (chain w ell S start (some h) (primeBadCells mesh Ld Lc Ud Uc)).toReal+
        (continuousChain v ell S (.inl z) (continuousBadCells S mesh Ld Lc Ud Uc)).toReal) := by
  classical
  let := chain_isMarkov hw hell hS0 hS hr hs hsS
  let a := labelMass (chain w ell S start) (primeLabel w ell S mesh start) (some h)
  let b := labelMass (continuousChain v ell S) (continuousLabel S mesh) (.inl z)
  let good := fullCell (S:=S) (mesh:=mesh) Ld Lc Ud Uc
  have hbudget := interior_boundary_budget a b (cemeteryLabel S mesh) good
    (labelMass_nonneg (chain w ell S start) (primeLabel w ell S mesh start) (some h))
    (labelMass_nonneg (continuousChain v ell S) (continuousLabel S mesh) (.inl z))
    (labelMass_sum (chain w ell S start) (primeLabel_measurable w ell S mesh start) (some h))
    (labelMass_sum (continuousChain v ell S) (continuousLabel_measurable S mesh) (.inl z))
  have hsub : (Finset.univ.erase (cemeteryLabel S mesh)).filter good ⊆ interiorLabels S mesh Ld Lc Ud Uc := by
    intro j hj
    exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,(Finset.mem_filter.mp hj).2⟩
  have hsum := Finset.sum_le_sum_of_subset_of_nonneg hsub (fun j _ _ => abs_nonneg (a j-b j))
  change (∑ j,|a j-b j|) ≤ _
  have hbad : (∑ j ∈ (Finset.univ.erase (cemeteryLabel S mesh)).filter (fun j => ¬good j),(a j+b j)) =
      (chain w ell S start (some h) (primeBadCells mesh Ld Lc Ud Uc)).toReal+
      (continuousChain v ell S (.inl z) (continuousBadCells S mesh Ld Lc Ud Uc)).toReal := by
    rw [Finset.sum_add_distrib]
    exact congrArg₂ (·+·) (prime_boundary_mass hm hsS h Ld Lc Ud Uc)
      (continuous_boundary_mass v ell S hm z Ld Lc Ud Uc)
  rw [hbad] at hbudget
  linarith

end NumberTheoryLean.CouplingLabelEvents

end

end Erdos970

end OAI