import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Mathlib.Probability.Distributions.Bernoulli import OAI.NumberTheory.Jacobsthal.Probability.HarmonicPrefixKernel namespace OAI namespace Erdos970 section namespace ErdosPrimeInputs.HarmonicPrefixTilt open Set Filter MeasureTheory ProbabilityTheory open scoped ENNReal open WeightedKernelMass HarmonicPrefixKernel noncomputable def squareBoundE (ell B : ℝ) : ℝ≥0∞ := ENNReal.ofReal (bound ell B ^ 2) lemma squareBoundE_measurable (ell : ℝ) : Measurable (squareBoundE ell) := by unfold squareBoundE bound fun_prop lemma linear_lintegral {ell B : ℝ} (hell : 0 t/ell^2) (Ioc ell B) := ((continuous_id.div_const (ell^2)).continuousOn.integrableOn_Icc).mono_set Ioc_subset_Icc_self have hn : ∀ᵐ t ∂volume.restrict (Ioc ell B), 0≤t/ell^2 := by apply ae_restrict_of_forall_mem measurableSet_Ioc intro t ht exact div_nonneg (hell.le.trans ht.1.le) (sq_nonneg _) rw [← ofReal_integral_eq_lintegral_ofReal hi hn,← intervalIntegral.integral_of_le hB] simp only [div_eq_mul_inv,intervalIntegral.integral_mul_const,_root_.integral_id] lemma harmonic_square_integral {ell B : ℝ} (hell : 0 (schur_two hell x).le) B simpa only [squareBoundE,bound_on hell hB] using h end ErdosPrimeInputs.HarmonicPrefixTilt end section namespace ErdosPrimeInputs.HarmonicLongPrefixes open scoped ENNReal open WeightedKernelMass HarmonicPrefixKernel HarmonicPrefixTilt noncomputable def tailMass (a : ℕ → ℝ≥0∞) (m : ℕ) : ℝ≥0∞ := ∑' n : ℕ, if m≤n then a n else 0 lemma half_power_antitone {m n : ℕ} (hmn : m≤n) : ((2:ℝ≥0∞)⁻¹)^n ≤ ((2:ℝ≥0∞)⁻¹)^m := by obtain ⟨k,rfl⟩ := Nat.exists_eq_add_of_le hmn have hp : ((2:ℝ≥0∞)⁻¹)^k ≤ 1 := pow_le_one₀ zero_le (by norm_num) calc _ = ((2:ℝ≥0∞)⁻¹)^m * ((2:ℝ≥0∞)⁻¹)^k := pow_add _ _ _ _ ≤ ((2:ℝ≥0∞)⁻¹)^m * 1 := mul_le_mul le_rfl hp zero_le zero_le _ = _ := mul_one _ lemma unweight_two (a : ℝ≥0∞) (n : ℕ) : a = ((2:ℝ≥0∞)⁻¹)^n * ((2:ℝ≥0∞)^n*a) := by have hi : (2:ℝ≥0∞)⁻¹*2=1 := ENNReal.inv_mul_cancel (by norm_num) (by norm_num) calc a = 1*a := (one_mul _).symm _ = ((2:ℝ≥0∞)⁻¹*2)^n*a := by rw [hi,one_pow] _ = _ := by rw [mul_pow,mul_assoc] theorem weighted_tail_bound (a : ℕ → ℝ≥0∞) (m : ℕ) {W : ℝ≥0∞} (hW : (∑' n : ℕ, (2:ℝ≥0∞)^n*a n) ≤ W) : tailMass a m ≤ ((2:ℝ≥0∞)⁻¹)^m*W := by calc _ ≤ ∑' n : ℕ, ((2:ℝ≥0∞)⁻¹)^m*((2:ℝ≥0∞)^n*a n) := by apply ENNReal.tsum_le_tsum intro n by_cases hn : m≤n · rw [ite_eq_left hn] exact (unweight_two (a n) n).trans_le (mul_le_mul (half_power_antitone hn) le_rfl zero_le zero_le) · rw [ite_eq_right hn] exact zero_le _ = ((2:ℝ≥0∞)⁻¹)^m*(∑' n : ℕ, (2:ℝ≥0∞)^n*a n) := ENNReal.tsum_mul_left _ ≤ _ := mul_le_mul le_rfl hW zero_le zero_le noncomputable def longPrefixMass (ell B : ℝ) (m : ℕ) : ℝ≥0∞ := tailMass (fun n => mass (kernel ell) n B) m theorem long_prefix_mass {ell B : ℝ} (hell : 0 x.1.2.2) := by fun_prop have hr : Measurable (fun x : State × ℝ => (x.1.2.1-x.2)/x.2) := by fun_prop have hset : MeasurableSet {x : State × ℝ | x.1.2.2=true ∨ S<(x.1.2.1-x.2)/x.2} := (hf (measurableSet_singleton true)).union (measurableSet_lt measurable_const hr) exact measurable_snd.prodMk ((by fun_prop : Measurable (fun x : State × ℝ => x.1.2.1-x.2)).prodMk (Measurable.ite hset measurable_const measurable_const)) lemma update_flag (S : ℝ) (z : State) (t : ℝ) : (update S z t).2.2=true ↔ z.2.2=true ∨ S<(z.2.1-t)/t := by by_cases h : z.2.2=true ∨ S<(z.2.1-t)/t <;> simp [update,h] def Invariant (ell S : ℝ) (n : ℕ) (z : State) : Prop := ell≤z.1 ∧ (z.2.2=true → (S-(n:ℝ))*z.1 z.2.2) := measurable_snd.comp measurable_snd have hg : Measurable (fun z : State => z.2.1) := measurable_fst.comp measurable_snd have hb : MeasurableSet {z : State | ell≤z.1} := measurableSet_le measurable_const measurable_fst have hh : MeasurableSet {z : State | z.2.2=true} := hf (measurableSet_singleton true) have hr : MeasurableSet {z : State | (S-(n:ℝ))*z.1