import Mathlib
import OAI.Probability.SKBarriers.Dynamics.GreedyInvariant
import OAI.Probability.SKBarriers.Dynamics.PredictableGrid
namespace OAI
section
noncomputable section
open scoped BigOperators
open Classical MeasureTheory Set
namespace SK.Analytic
structure GreedyScaleBounds (n B H p : ℕ) (t ρ d b b' q : ℝ) : Prop where
p_pos : 0
linarith only [H.1,H.2,h0,h1,hp]
theorem gridThresholds_spacing {n p : ℕ} (hn : 0 hz ⟨⟨i,hi⟩,H⟩)
obtain ⟨k,hk,Hk⟩ := greedy_marker_windows hn μ pool fallback hf base x (gridThresholds n p t ρ z)
B H p m t ρ d b b' q G.p_pos G.B_pos G.HB G.packingH G.t_pos G.rho_pos G.d_nonneg G.b_pos
G.packing G.cutoff G.total_error G.small_cutoff G.separation G.width G.small_width G.large_width
G.jump G.eta G.high (gridThresholds_range hn G.rho_pos G.grid_range z)
(gridThresholds_spacing hn G.rho_pos z) hm hjump hcoverage hsigned hbank hnarrow hpass
refine ⟨⟨k,by omega⟩,?_⟩
intro i hi
have he : i.val/B*B=i.val := by
have H := Nat.mod_add_div i.val B
rw [hi,zero_add,Nat.mul_comm] at H
exact H
have H := Hk (i.val/B) (by simpa only [he] using i.isLt)
rw [he,gridThresholds,dite_eq_left i.isLt] at H
exact H
have h1 : 1≤P.prob bad+P.prob (fun z => ∃k : Fin (m+1),W k z) := by
have he : P.prob (fun z => bad z ∨ ∃k : Fin (m+1),W k z)=1 := by
unfold FiniteLaw.prob
simp only [hall,ite_true,FiniteLaw.expect_const]
rw [← he]
exact P.prob_or _ _
have hm := gridThresholds_good_mass hn μ p t ρ G.rho_pos
have hw : P.prob (fun z => ∃k : Fin (m+1),W k z)≤(m+1)*(2*(6*p*ρ^20)/ρ+1/(n:ℝ))^s := by
refine (P.prob_exists W).trans ?_
calc
_ ≤ ∑ _k : Fin (m+1),(2*(6*p*ρ^20)/ρ+1/(n:ℝ))^s := by
apply Finset.sum_le_sum
intro k _
exact greedy_grid_windows_bound hn base (bankPick pool fallback B x t q) x B s m G.B_pos t ρ b
(6*p*ρ^20) G.rho_pos (by positivity) k.val
_ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,Nat.cast_add,Nat.cast_one]
change P.prob bad≤_ at hm
simp only [p,Nat.cast_mul] at hm hw h1
linarith only [h1,hm,hw,hcount]
end SK.Analytic
end
end
end OAI